]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: cli for SRv6 SID alloc to redirect to vrf (step4)
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
4ab46701 25#include "lib/sockopt.h"
5cb5f4d0 26#include "lib_errors.h"
ec0ab544 27#include "lib/zclient.h"
6f4eacf3 28#include "lib/printfrr.h"
718e3744 29#include "prefix.h"
30#include "plist.h"
31#include "buffer.h"
32#include "linklist.h"
33#include "stream.h"
34#include "thread.h"
35#include "log.h"
3b8b1855 36#include "memory.h"
1c0d8808 37#include "lib_vty.h"
4bf6a362 38#include "hash.h"
3f9c7369 39#include "queue.h"
039f3a34 40#include "filter.h"
5d5ba018 41#include "frrstr.h"
718e3744 42
43#include "bgpd/bgpd.h"
48ecf8f5 44#include "bgpd/bgp_attr_evpn.h"
4bf6a362 45#include "bgpd/bgp_advertise.h"
718e3744 46#include "bgpd/bgp_attr.h"
47#include "bgpd/bgp_aspath.h"
48#include "bgpd/bgp_community.h"
ed0e57e3 49#include "bgpd/bgp_community_alias.h"
4bf6a362 50#include "bgpd/bgp_ecommunity.h"
57d187bc 51#include "bgpd/bgp_lcommunity.h"
4bf6a362 52#include "bgpd/bgp_damp.h"
718e3744 53#include "bgpd/bgp_debug.h"
14454c9f 54#include "bgpd/bgp_errors.h"
e0701b79 55#include "bgpd/bgp_fsm.h"
4bf6a362 56#include "bgpd/bgp_nexthop.h"
718e3744 57#include "bgpd/bgp_open.h"
4bf6a362 58#include "bgpd/bgp_regex.h"
718e3744 59#include "bgpd/bgp_route.h"
c016b6c7 60#include "bgpd/bgp_mplsvpn.h"
718e3744 61#include "bgpd/bgp_zebra.h"
fee0f4c6 62#include "bgpd/bgp_table.h"
94f2b392 63#include "bgpd/bgp_vty.h"
165b5fff 64#include "bgpd/bgp_mpath.h"
cb1faec9 65#include "bgpd/bgp_packet.h"
3f9c7369 66#include "bgpd/bgp_updgrp.h"
c43ed2e4 67#include "bgpd/bgp_bfd.h"
555e09d4 68#include "bgpd/bgp_io.h"
94c2f693 69#include "bgpd/bgp_evpn.h"
dd65f45e 70#include "bgpd/bgp_evpn_vty.h"
b5e140c8 71#include "bgpd/bgp_evpn_mh.h"
dcc68b5e 72#include "bgpd/bgp_addpath.h"
48ecf8f5 73#include "bgpd/bgp_mac.h"
dd65f45e 74#include "bgpd/bgp_flowspec.h"
49e5a4a0 75#ifdef ENABLE_BGP_VNC
dd65f45e
DL
76#include "bgpd/rfapi/bgp_rfapi_cfg.h"
77#endif
78
ff8a8a7a
CS
79#include "northbound.h"
80#include "northbound_cli.h"
81#include "bgpd/bgp_nb.h"
82
83
5d5393b9 84FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
62282e83
DS
85 {
86 .val_bool = false,
87 .match_profile = "traditional",
88 .match_version = "< 7.4",
89 },
90 { .val_bool = true },
67b0f40c 91);
5d5393b9 92FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
4c1458b5
DL
93 { .val_bool = true, .match_profile = "datacenter", },
94 { .val_bool = false },
67b0f40c 95);
aef999a2
DA
96FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
97 { .val_bool = true, .match_profile = "datacenter", },
98 { .val_bool = false },
67b0f40c 99);
5d5393b9 100FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
4c1458b5
DL
101 { .val_bool = true, .match_profile = "datacenter", },
102 { .val_bool = false },
67b0f40c 103);
5d5393b9 104FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
4c1458b5
DL
105 { .val_bool = true, .match_profile = "datacenter", },
106 { .val_bool = false },
67b0f40c 107);
5d5393b9
DL
108FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
109 { .val_ulong = 10, .match_profile = "datacenter", },
110 { .val_ulong = 120 },
67b0f40c 111);
5d5393b9
DL
112FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
113 { .val_ulong = 9, .match_profile = "datacenter", },
114 { .val_ulong = 180 },
67b0f40c 115);
5d5393b9
DL
116FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
117 { .val_ulong = 3, .match_profile = "datacenter", },
118 { .val_ulong = 60 },
67b0f40c 119);
1d3fdccf
DA
120FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
121 { .val_bool = false, .match_profile = "datacenter", },
122 { .val_bool = false, .match_version = "< 7.4", },
123 { .val_bool = true },
67b0f40c 124);
2adac256
DA
125FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
126 { .val_bool = false, .match_version = "< 7.6", },
127 { .val_bool = true },
67b0f40c 128);
5d5393b9 129
dd65f45e
DL
130DEFINE_HOOK(bgp_inst_config_write,
131 (struct bgp *bgp, struct vty *vty),
8451921b
DL
132 (bgp, vty));
133DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
718e3744 134
d62a17ae 135static struct peer_group *listen_range_exists(struct bgp *bgp,
136 struct prefix *range, int exact);
137
055679e9 138/* Show BGP peer's information. */
139enum show_type {
140 show_all,
141 show_peer,
142 show_ipv4_all,
143 show_ipv6_all,
144 show_ipv4_peer,
145 show_ipv6_peer
146};
147
36235319
QY
148static struct peer_group *listen_range_exists(struct bgp *bgp,
149 struct prefix *range, int exact);
2986cac2 150
36235319
QY
151static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
152 struct bgp *bgp,
153 bool use_json,
154 json_object *json);
2986cac2 155
36235319
QY
156static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
157 enum show_type type,
158 const char *ip_str,
159 afi_t afi, bool use_json);
2986cac2 160
f4b8ec07
CS
161static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
162 char *base_xpath, int xpath_len,
163 char *abs_xpath);
164
d62a17ae 165static enum node_type bgp_node_type(afi_t afi, safi_t safi)
166{
167 switch (afi) {
168 case AFI_IP:
169 switch (safi) {
170 case SAFI_UNICAST:
171 return BGP_IPV4_NODE;
d62a17ae 172 case SAFI_MULTICAST:
173 return BGP_IPV4M_NODE;
d62a17ae 174 case SAFI_LABELED_UNICAST:
175 return BGP_IPV4L_NODE;
d62a17ae 176 case SAFI_MPLS_VPN:
177 return BGP_VPNV4_NODE;
7c40bf39 178 case SAFI_FLOWSPEC:
179 return BGP_FLOWSPECV4_NODE;
5c525538
RW
180 default:
181 /* not expected */
182 return BGP_IPV4_NODE;
d62a17ae 183 }
184 break;
185 case AFI_IP6:
186 switch (safi) {
187 case SAFI_UNICAST:
188 return BGP_IPV6_NODE;
d62a17ae 189 case SAFI_MULTICAST:
190 return BGP_IPV6M_NODE;
d62a17ae 191 case SAFI_LABELED_UNICAST:
192 return BGP_IPV6L_NODE;
d62a17ae 193 case SAFI_MPLS_VPN:
194 return BGP_VPNV6_NODE;
7c40bf39 195 case SAFI_FLOWSPEC:
196 return BGP_FLOWSPECV6_NODE;
5c525538
RW
197 default:
198 /* not expected */
199 return BGP_IPV4_NODE;
d62a17ae 200 }
201 break;
202 case AFI_L2VPN:
203 return BGP_EVPN_NODE;
b26f891d 204 case AFI_UNSPEC:
d62a17ae 205 case AFI_MAX:
206 // We should never be here but to clarify the switch statement..
207 return BGP_IPV4_NODE;
d62a17ae 208 }
209
210 // Impossible to happen
211 return BGP_IPV4_NODE;
f51bae9c 212}
20eb8864 213
5cb5f4d0
DD
214static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
215{
7d0d37de
DS
216 if (afi == AFI_IP) {
217 if (safi == SAFI_UNICAST)
218 return "IPv4 Unicast";
219 if (safi == SAFI_MULTICAST)
220 return "IPv4 Multicast";
221 if (safi == SAFI_LABELED_UNICAST)
222 return "IPv4 Labeled Unicast";
223 if (safi == SAFI_MPLS_VPN)
224 return "IPv4 VPN";
225 if (safi == SAFI_ENCAP)
226 return "IPv4 Encap";
227 if (safi == SAFI_FLOWSPEC)
228 return "IPv4 Flowspec";
229 } else if (afi == AFI_IP6) {
230 if (safi == SAFI_UNICAST)
231 return "IPv6 Unicast";
232 if (safi == SAFI_MULTICAST)
233 return "IPv6 Multicast";
234 if (safi == SAFI_LABELED_UNICAST)
235 return "IPv6 Labeled Unicast";
236 if (safi == SAFI_MPLS_VPN)
237 return "IPv6 VPN";
238 if (safi == SAFI_ENCAP)
239 return "IPv6 Encap";
240 if (safi == SAFI_FLOWSPEC)
241 return "IPv6 Flowspec";
242 } else if (afi == AFI_L2VPN) {
243 if (safi == SAFI_EVPN)
244 return "L2VPN EVPN";
245 }
246
247 return "Unknown";
5cb5f4d0
DD
248}
249
250/*
251 * Please note that we have intentionally camelCased
252 * the return strings here. So if you want
253 * to use this function, please ensure you
254 * are doing this within json output
255 */
256static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
257{
7d0d37de
DS
258 if (afi == AFI_IP) {
259 if (safi == SAFI_UNICAST)
260 return "ipv4Unicast";
261 if (safi == SAFI_MULTICAST)
262 return "ipv4Multicast";
263 if (safi == SAFI_LABELED_UNICAST)
264 return "ipv4LabeledUnicast";
265 if (safi == SAFI_MPLS_VPN)
266 return "ipv4Vpn";
267 if (safi == SAFI_ENCAP)
268 return "ipv4Encap";
269 if (safi == SAFI_FLOWSPEC)
270 return "ipv4Flowspec";
271 } else if (afi == AFI_IP6) {
272 if (safi == SAFI_UNICAST)
273 return "ipv6Unicast";
274 if (safi == SAFI_MULTICAST)
275 return "ipv6Multicast";
276 if (safi == SAFI_LABELED_UNICAST)
277 return "ipv6LabeledUnicast";
278 if (safi == SAFI_MPLS_VPN)
279 return "ipv6Vpn";
280 if (safi == SAFI_ENCAP)
281 return "ipv6Encap";
282 if (safi == SAFI_FLOWSPEC)
283 return "ipv6Flowspec";
284 } else if (afi == AFI_L2VPN) {
285 if (safi == SAFI_EVPN)
286 return "l2VpnEvpn";
287 }
288
289 return "Unknown";
5cb5f4d0
DD
290}
291
37a87b8f
CS
292/* return string maps to afi-safi specific container names
293 * defined in bgp yang file.
294 */
295const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
296{
7d0d37de
DS
297 if (afi == AFI_IP) {
298 if (safi == SAFI_UNICAST)
299 return "ipv4-unicast";
300 if (safi == SAFI_MULTICAST)
301 return "ipv4-multicast";
302 if (safi == SAFI_LABELED_UNICAST)
303 return "ipv4-labeled-unicast";
304 if (safi == SAFI_MPLS_VPN)
305 return "l3vpn-ipv4-unicast";
306 if (safi == SAFI_FLOWSPEC)
307 return "ipv4-flowspec";
308 } else if (afi == AFI_IP6) {
309 if (safi == SAFI_UNICAST)
310 return "ipv6-unicast";
311 if (safi == SAFI_MULTICAST)
312 return "ipv6-multicast";
313 if (safi == SAFI_LABELED_UNICAST)
314 return "ipv6-labeled-unicast";
315 if (safi == SAFI_MPLS_VPN)
316 return "l3vpn-ipv6-unicast";
317 if (safi == SAFI_FLOWSPEC)
318 return "ipv6-flowspec";
319 } else if (afi == AFI_L2VPN) {
320 if (safi == SAFI_EVPN)
321 return "l2vpn-evpn";
322 }
323
324 return "Unknown";
37a87b8f
CS
325}
326
718e3744 327/* Utility function to get address family from current node. */
d62a17ae 328afi_t bgp_node_afi(struct vty *vty)
329{
330 afi_t afi;
331 switch (vty->node) {
332 case BGP_IPV6_NODE:
333 case BGP_IPV6M_NODE:
334 case BGP_IPV6L_NODE:
335 case BGP_VPNV6_NODE:
7c40bf39 336 case BGP_FLOWSPECV6_NODE:
d62a17ae 337 afi = AFI_IP6;
338 break;
339 case BGP_EVPN_NODE:
340 afi = AFI_L2VPN;
341 break;
342 default:
343 afi = AFI_IP;
344 break;
345 }
346 return afi;
718e3744 347}
348
349/* Utility function to get subsequent address family from current
350 node. */
d62a17ae 351safi_t bgp_node_safi(struct vty *vty)
352{
353 safi_t safi;
354 switch (vty->node) {
355 case BGP_VPNV4_NODE:
356 case BGP_VPNV6_NODE:
357 safi = SAFI_MPLS_VPN;
358 break;
359 case BGP_IPV4M_NODE:
360 case BGP_IPV6M_NODE:
361 safi = SAFI_MULTICAST;
362 break;
363 case BGP_EVPN_NODE:
364 safi = SAFI_EVPN;
365 break;
366 case BGP_IPV4L_NODE:
367 case BGP_IPV6L_NODE:
368 safi = SAFI_LABELED_UNICAST;
369 break;
7c40bf39 370 case BGP_FLOWSPECV4_NODE:
371 case BGP_FLOWSPECV6_NODE:
372 safi = SAFI_FLOWSPEC;
373 break;
d62a17ae 374 default:
375 safi = SAFI_UNICAST;
376 break;
377 }
378 return safi;
718e3744 379}
380
55f91488
QY
381/**
382 * Converts an AFI in string form to afi_t
383 *
384 * @param afi string, one of
385 * - "ipv4"
386 * - "ipv6"
81cf0de5 387 * - "l2vpn"
55f91488
QY
388 * @return the corresponding afi_t
389 */
d62a17ae 390afi_t bgp_vty_afi_from_str(const char *afi_str)
391{
392 afi_t afi = AFI_MAX; /* unknown */
393 if (strmatch(afi_str, "ipv4"))
394 afi = AFI_IP;
395 else if (strmatch(afi_str, "ipv6"))
396 afi = AFI_IP6;
81cf0de5
CS
397 else if (strmatch(afi_str, "l2vpn"))
398 afi = AFI_L2VPN;
d62a17ae 399 return afi;
400}
401
402int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
403 afi_t *afi)
404{
405 int ret = 0;
406 if (argv_find(argv, argc, "ipv4", index)) {
407 ret = 1;
408 if (afi)
409 *afi = AFI_IP;
410 } else if (argv_find(argv, argc, "ipv6", index)) {
411 ret = 1;
412 if (afi)
413 *afi = AFI_IP6;
8688b3e7
DS
414 } else if (argv_find(argv, argc, "l2vpn", index)) {
415 ret = 1;
416 if (afi)
417 *afi = AFI_L2VPN;
d62a17ae 418 }
419 return ret;
46f296b4
LB
420}
421
375a2e67 422/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 423safi_t bgp_vty_safi_from_str(const char *safi_str)
424{
425 safi_t safi = SAFI_MAX; /* unknown */
426 if (strmatch(safi_str, "multicast"))
427 safi = SAFI_MULTICAST;
428 else if (strmatch(safi_str, "unicast"))
429 safi = SAFI_UNICAST;
430 else if (strmatch(safi_str, "vpn"))
431 safi = SAFI_MPLS_VPN;
81cf0de5
CS
432 else if (strmatch(safi_str, "evpn"))
433 safi = SAFI_EVPN;
d62a17ae 434 else if (strmatch(safi_str, "labeled-unicast"))
435 safi = SAFI_LABELED_UNICAST;
7c40bf39 436 else if (strmatch(safi_str, "flowspec"))
437 safi = SAFI_FLOWSPEC;
d62a17ae 438 return safi;
439}
440
441int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
442 safi_t *safi)
443{
444 int ret = 0;
445 if (argv_find(argv, argc, "unicast", index)) {
446 ret = 1;
447 if (safi)
448 *safi = SAFI_UNICAST;
449 } else if (argv_find(argv, argc, "multicast", index)) {
450 ret = 1;
451 if (safi)
452 *safi = SAFI_MULTICAST;
453 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
454 ret = 1;
455 if (safi)
456 *safi = SAFI_LABELED_UNICAST;
457 } else if (argv_find(argv, argc, "vpn", index)) {
458 ret = 1;
459 if (safi)
460 *safi = SAFI_MPLS_VPN;
8688b3e7
DS
461 } else if (argv_find(argv, argc, "evpn", index)) {
462 ret = 1;
463 if (safi)
464 *safi = SAFI_EVPN;
7c40bf39 465 } else if (argv_find(argv, argc, "flowspec", index)) {
466 ret = 1;
467 if (safi)
468 *safi = SAFI_FLOWSPEC;
d62a17ae 469 }
470 return ret;
46f296b4
LB
471}
472
5d5393b9
DL
473int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
474 enum bgp_instance_type inst_type)
475{
476 int ret = bgp_get(bgp, as, name, inst_type);
477
478 if (ret == BGP_CREATED) {
479 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
d43114f3 480 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
5d5393b9
DL
481
482 if (DFLT_BGP_IMPORT_CHECK)
892fedb6 483 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
5d5393b9 484 if (DFLT_BGP_SHOW_HOSTNAME)
892fedb6 485 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
aef999a2
DA
486 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
487 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
5d5393b9 488 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
892fedb6 489 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
5d5393b9 490 if (DFLT_BGP_DETERMINISTIC_MED)
892fedb6 491 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
1d3fdccf
DA
492 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
493 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
2adac256
DA
494 if (DFLT_BGP_SUPPRESS_DUPLICATES)
495 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
5d5393b9
DL
496
497 ret = BGP_SUCCESS;
498 }
499 return ret;
500}
501
7eeee51e 502/*
f212a857 503 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 504 *
f212a857
DS
505 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
506 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
507 * to appropriate values for the calling function. This is to allow the
508 * calling function to make decisions appropriate for the show command
509 * that is being parsed.
510 *
511 * The show commands are generally of the form:
d62a17ae 512 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
513 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
514 *
515 * Since we use argv_find if the show command in particular doesn't have:
516 * [ip]
18c57037 517 * [<view|vrf> VIEWVRFNAME]
375a2e67 518 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
519 * The command parsing should still be ok.
520 *
521 * vty -> The vty for the command so we can output some useful data in
522 * the event of a parse error in the vrf.
523 * argv -> The command tokens
524 * argc -> How many command tokens we have
d62a17ae 525 * idx -> The current place in the command, generally should be 0 for this
526 * function
7eeee51e
DS
527 * afi -> The parsed afi if it was included in the show command, returned here
528 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 529 * bgp -> Pointer to the bgp data structure we need to fill in.
52e5b8c4 530 * use_json -> json is configured or not
7eeee51e
DS
531 *
532 * The function returns the correct location in the parse tree for the
533 * last token found.
0e37c258
DS
534 *
535 * Returns 0 for failure to parse correctly, else the idx position of where
536 * it found the last token.
7eeee51e 537 */
d62a17ae 538int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
539 struct cmd_token **argv, int argc,
540 int *idx, afi_t *afi, safi_t *safi,
9f049418 541 struct bgp **bgp, bool use_json)
d62a17ae 542{
543 char *vrf_name = NULL;
544
545 assert(afi);
546 assert(safi);
547 assert(bgp);
548
549 if (argv_find(argv, argc, "ip", idx))
550 *afi = AFI_IP;
551
9a8bdf1c 552 if (argv_find(argv, argc, "view", idx))
d62a17ae 553 vrf_name = argv[*idx + 1]->arg;
9a8bdf1c
PG
554 else if (argv_find(argv, argc, "vrf", idx)) {
555 vrf_name = argv[*idx + 1]->arg;
556 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
557 vrf_name = NULL;
558 }
559 if (vrf_name) {
d62a17ae 560 if (strmatch(vrf_name, "all"))
561 *bgp = NULL;
562 else {
563 *bgp = bgp_lookup_by_name(vrf_name);
564 if (!*bgp) {
52e5b8c4
SP
565 if (use_json) {
566 json_object *json = NULL;
567 json = json_object_new_object();
568 json_object_string_add(
569 json, "warning",
570 "View/Vrf is unknown");
571 vty_out(vty, "%s\n",
572 json_object_to_json_string_ext(json,
573 JSON_C_TO_STRING_PRETTY));
574 json_object_free(json);
575 }
ca61fd25
DS
576 else
577 vty_out(vty, "View/Vrf %s is unknown\n",
578 vrf_name);
d62a17ae 579 *idx = 0;
580 return 0;
581 }
582 }
583 } else {
584 *bgp = bgp_get_default();
585 if (!*bgp) {
52e5b8c4
SP
586 if (use_json) {
587 json_object *json = NULL;
588 json = json_object_new_object();
589 json_object_string_add(
590 json, "warning",
591 "Default BGP instance not found");
592 vty_out(vty, "%s\n",
593 json_object_to_json_string_ext(json,
594 JSON_C_TO_STRING_PRETTY));
595 json_object_free(json);
596 }
ca61fd25
DS
597 else
598 vty_out(vty,
599 "Default BGP instance not found\n");
d62a17ae 600 *idx = 0;
601 return 0;
602 }
603 }
604
605 if (argv_find_and_parse_afi(argv, argc, idx, afi))
606 argv_find_and_parse_safi(argv, argc, idx, safi);
607
608 *idx += 1;
609 return *idx;
610}
611
f4b8ec07 612bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
d62a17ae 613{
614 struct interface *ifp = NULL;
615
616 if (su->sa.sa_family == AF_INET)
617 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
618 else if (su->sa.sa_family == AF_INET6)
619 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
620 su->sin6.sin6_scope_id,
621 bgp->vrf_id);
622
623 if (ifp)
3dc339cd 624 return true;
d62a17ae 625
3dc339cd 626 return false;
718e3744 627}
628
718e3744 629/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
630/* This is used only for configuration, so disallow if attempted on
631 * a dynamic neighbor.
632 */
d62a17ae 633struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
634{
635 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
636 int ret;
637 union sockunion su;
638 struct peer *peer = NULL;
639 struct peer_group *group = NULL;
640
641 if (!bgp) {
642 return NULL;
643 }
644
645 ret = str2sockunion(peer_str, &su);
646 if (ret == 0) {
647 /* IP address, locate peer. */
648 peer = peer_lookup(bgp, &su);
649 } else {
650 /* Not IP, could match either peer configured on interface or a
651 * group. */
652 peer = peer_lookup_by_conf_if(bgp, peer_str);
653 if (!peer)
654 group = peer_group_lookup(bgp, peer_str);
655 }
656
657 if (peer) {
658 if (peer_dynamic_neighbor(peer)) {
659 vty_out(vty,
660 "%% Operation not allowed on a dynamic neighbor\n");
661 return NULL;
662 }
663
664 return peer;
665 }
666
667 if (group)
668 return group->conf;
669
670 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
671
672 return NULL;
673}
674
f4b8ec07
CS
675int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
676{
677 const char *str = NULL;
678
679 switch (ret) {
680 case BGP_ERR_INVALID_VALUE:
681 str = "Invalid value";
682 break;
683 case BGP_ERR_INVALID_FLAG:
684 str = "Invalid flag";
685 break;
686 case BGP_ERR_PEER_GROUP_SHUTDOWN:
687 str = "Peer-group has been shutdown. Activate the peer-group first";
688 break;
689 case BGP_ERR_PEER_FLAG_CONFLICT:
690 str = "Can't set override-capability and strict-capability-match at the same time";
691 break;
692 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
693 str = "Specify remote-as or peer-group remote AS first";
694 break;
695 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
696 str = "Cannot change the peer-group. Deconfigure first";
697 break;
698 case BGP_ERR_PEER_GROUP_MISMATCH:
699 str = "Peer is not a member of this peer-group";
700 break;
701 case BGP_ERR_PEER_FILTER_CONFLICT:
702 str = "Prefix/distribute list can not co-exist";
703 break;
704 case BGP_ERR_NOT_INTERNAL_PEER:
705 str = "Invalid command. Not an internal neighbor";
706 break;
707 case BGP_ERR_REMOVE_PRIVATE_AS:
708 str = "remove-private-AS cannot be configured for IBGP peers";
709 break;
710 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
711 str = "Local-AS allowed only for EBGP peers";
712 break;
713 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
714 str = "Cannot have local-as same as BGP AS number";
715 break;
716 case BGP_ERR_TCPSIG_FAILED:
717 str = "Error while applying TCP-Sig to session(s)";
718 break;
719 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
720 str = "ebgp-multihop and ttl-security cannot be configured together";
721 break;
722 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
723 str = "ttl-security only allowed for EBGP peers";
724 break;
725 case BGP_ERR_AS_OVERRIDE:
726 str = "as-override cannot be configured for IBGP peers";
727 break;
728 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
729 str = "Invalid limit for number of dynamic neighbors";
730 break;
731 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
732 str = "Dynamic neighbor listen range already exists";
733 break;
734 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
735 str = "Operation not allowed on a dynamic neighbor";
736 break;
737 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
738 str = "Operation not allowed on a directly connected neighbor";
739 break;
740 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 741 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
f4b8ec07
CS
742 break;
743 case BGP_ERR_GR_INVALID_CMD:
744 str = "The Graceful Restart command used is not valid at this moment.";
745 break;
746 case BGP_ERR_GR_OPERATION_FAILED:
747 str = "The Graceful Restart Operation failed due to an err.";
748 break;
f4b8ec07
CS
749 case BGP_ERR_PEER_GROUP_MEMBER:
750 str = "Peer-group member cannot override remote-as of peer-group";
751 break;
752 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
753 str = "Peer-group members must be all internal or all external";
754 break;
755 }
756 if (str) {
757 snprintf(errmsg, errmsg_len, "%s", str);
758 return -1;
759 }
760
761 return 0;
762}
763
d62a17ae 764int bgp_vty_return(struct vty *vty, int ret)
765{
766 const char *str = NULL;
767
768 switch (ret) {
769 case BGP_ERR_INVALID_VALUE:
770 str = "Invalid value";
771 break;
772 case BGP_ERR_INVALID_FLAG:
773 str = "Invalid flag";
774 break;
775 case BGP_ERR_PEER_GROUP_SHUTDOWN:
776 str = "Peer-group has been shutdown. Activate the peer-group first";
777 break;
778 case BGP_ERR_PEER_FLAG_CONFLICT:
779 str = "Can't set override-capability and strict-capability-match at the same time";
780 break;
781 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
782 str = "Specify remote-as or peer-group remote AS first";
783 break;
784 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
785 str = "Cannot change the peer-group. Deconfigure first";
786 break;
787 case BGP_ERR_PEER_GROUP_MISMATCH:
788 str = "Peer is not a member of this peer-group";
789 break;
790 case BGP_ERR_PEER_FILTER_CONFLICT:
791 str = "Prefix/distribute list can not co-exist";
792 break;
793 case BGP_ERR_NOT_INTERNAL_PEER:
794 str = "Invalid command. Not an internal neighbor";
795 break;
796 case BGP_ERR_REMOVE_PRIVATE_AS:
797 str = "remove-private-AS cannot be configured for IBGP peers";
798 break;
799 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
800 str = "Local-AS allowed only for EBGP peers";
801 break;
802 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
803 str = "Cannot have local-as same as BGP AS number";
804 break;
805 case BGP_ERR_TCPSIG_FAILED:
806 str = "Error while applying TCP-Sig to session(s)";
807 break;
808 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
809 str = "ebgp-multihop and ttl-security cannot be configured together";
810 break;
811 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
812 str = "ttl-security only allowed for EBGP peers";
813 break;
814 case BGP_ERR_AS_OVERRIDE:
815 str = "as-override cannot be configured for IBGP peers";
816 break;
817 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
818 str = "Invalid limit for number of dynamic neighbors";
819 break;
820 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
821 str = "Dynamic neighbor listen range already exists";
822 break;
823 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
824 str = "Operation not allowed on a dynamic neighbor";
825 break;
826 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
827 str = "Operation not allowed on a directly connected neighbor";
828 break;
829 case BGP_ERR_PEER_SAFI_CONFLICT:
a59803d0 830 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
055679e9 831 break;
832 case BGP_ERR_GR_INVALID_CMD:
833 str = "The Graceful Restart command used is not valid at this moment.";
834 break;
835 case BGP_ERR_GR_OPERATION_FAILED:
836 str = "The Graceful Restart Operation failed due to an err.";
837 break;
d62a17ae 838 }
839 if (str) {
840 vty_out(vty, "%% %s\n", str);
841 return CMD_WARNING_CONFIG_FAILED;
842 }
843 return CMD_SUCCESS;
718e3744 844}
845
7aafcaca 846/* BGP clear sort. */
d62a17ae 847enum clear_sort {
848 clear_all,
849 clear_peer,
850 clear_group,
851 clear_external,
852 clear_as
7aafcaca
DS
853};
854
ff8a8a7a
CS
855static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
856 int error, char *errmsg, size_t errmsg_len)
d62a17ae 857{
858 switch (error) {
859 case BGP_ERR_AF_UNCONFIGURED:
ff8a8a7a
CS
860 snprintf(errmsg, errmsg_len,
861 "%%BGP: Enable %s address family for the neighbor %s",
862 get_afi_safi_str(afi, safi, false), peer->host);
d62a17ae 863 break;
864 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
ff8a8a7a
CS
865 snprintf(
866 errmsg, errmsg_len,
867 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
d62a17ae 868 peer->host);
869 break;
870 default:
871 break;
872 }
7aafcaca
DS
873}
874
dc912615 875static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
c368171c 876 struct listnode **nnode, enum bgp_clear_type stype)
dc912615
DS
877{
878 int ret = 0;
2adac256 879 struct peer_af *paf;
dc912615
DS
880
881 /* if afi/.safi not specified, spin thru all of them */
882 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
883 afi_t tmp_afi;
884 safi_t tmp_safi;
885
886 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
2adac256
DA
887 paf = peer_af_find(peer, tmp_afi, tmp_safi);
888 if (paf && paf->subgroup)
889 SET_FLAG(paf->subgroup->sflags,
890 SUBGRP_STATUS_FORCE_UPDATES);
891
dc912615
DS
892 if (!peer->afc[tmp_afi][tmp_safi])
893 continue;
894
895 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 896 ret = peer_clear(peer, nnode);
dc912615
DS
897 else
898 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
899 stype);
900 }
901 /* if afi specified and safi not, spin thru safis on this afi */
902 } else if (safi == SAFI_UNSPEC) {
903 safi_t tmp_safi;
904
905 for (tmp_safi = SAFI_UNICAST;
906 tmp_safi < SAFI_MAX; tmp_safi++) {
907 if (!peer->afc[afi][tmp_safi])
908 continue;
909
2adac256
DA
910 paf = peer_af_find(peer, afi, tmp_safi);
911 if (paf && paf->subgroup)
912 SET_FLAG(paf->subgroup->sflags,
913 SUBGRP_STATUS_FORCE_UPDATES);
914
dc912615 915 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 916 ret = peer_clear(peer, nnode);
dc912615
DS
917 else
918 ret = peer_clear_soft(peer, afi,
919 tmp_safi, stype);
920 }
921 /* both afi/safi specified, let the caller know if not defined */
922 } else {
923 if (!peer->afc[afi][safi])
924 return 1;
925
2adac256
DA
926 paf = peer_af_find(peer, afi, safi);
927 if (paf && paf->subgroup)
928 SET_FLAG(paf->subgroup->sflags,
929 SUBGRP_STATUS_FORCE_UPDATES);
930
dc912615 931 if (stype == BGP_CLEAR_SOFT_NONE)
c368171c 932 ret = peer_clear(peer, nnode);
dc912615
DS
933 else
934 ret = peer_clear_soft(peer, afi, safi, stype);
935 }
936
937 return ret;
938}
939
7aafcaca 940/* `clear ip bgp' functions. */
ff8a8a7a 941static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
d62a17ae 942 enum clear_sort sort, enum bgp_clear_type stype,
ff8a8a7a 943 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 944{
dc912615 945 int ret = 0;
3ae8bfa5 946 bool found = false;
d62a17ae 947 struct peer *peer;
dc95985f 948
949 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
d62a17ae 950
951 /* Clear all neighbors. */
952 /*
953 * Pass along pointer to next node to peer_clear() when walking all
3ae8bfa5
PM
954 * nodes on the BGP instance as that may get freed if it is a
955 * doppelganger
d62a17ae 956 */
957 if (sort == clear_all) {
958 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dc95985f 959
960 bgp_peer_gr_flags_update(peer);
961
36235319 962 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
dc95985f 963 gr_router_detected = true;
964
c368171c 965 ret = bgp_peer_clear(peer, afi, safi, &nnode,
dc912615 966 stype);
d62a17ae 967
968 if (ret < 0)
ff8a8a7a
CS
969 bgp_clear_vty_error(peer, afi, safi, ret,
970 errmsg, errmsg_len);
dc95985f 971 }
972
36235319
QY
973 if (gr_router_detected
974 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 975 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
976 } else if (!gr_router_detected
977 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 978 bgp_zebra_send_capabilities(bgp, true);
04b6bdc0 979 }
d62a17ae 980
981 /* This is to apply read-only mode on this clear. */
982 if (stype == BGP_CLEAR_SOFT_NONE)
983 bgp->update_delay_over = 0;
984
985 return CMD_SUCCESS;
7aafcaca
DS
986 }
987
3ae8bfa5 988 /* Clear specified neighbor. */
d62a17ae 989 if (sort == clear_peer) {
990 union sockunion su;
d62a17ae 991
992 /* Make sockunion for lookup. */
993 ret = str2sockunion(arg, &su);
994 if (ret < 0) {
995 peer = peer_lookup_by_conf_if(bgp, arg);
996 if (!peer) {
997 peer = peer_lookup_by_hostname(bgp, arg);
998 if (!peer) {
ff8a8a7a
CS
999 snprintf(
1000 errmsg, errmsg_len,
1001 "Malformed address or name: %s",
d62a17ae 1002 arg);
1003 return CMD_WARNING;
1004 }
1005 }
1006 } else {
1007 peer = peer_lookup(bgp, &su);
1008 if (!peer) {
ff8a8a7a
CS
1009 snprintf(errmsg, errmsg_len,
1010 "%%BGP: Unknown neighbor - \"%s\"",
1011 arg);
d62a17ae 1012 return CMD_WARNING;
1013 }
1014 }
7aafcaca 1015
dc95985f 1016 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1017 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1018
dc912615
DS
1019 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1020
1021 /* if afi/safi not defined for this peer, let caller know */
1022 if (ret == 1)
3ae8bfa5 1023 ret = BGP_ERR_AF_UNCONFIGURED;
7aafcaca 1024
d62a17ae 1025 if (ret < 0)
ff8a8a7a
CS
1026 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1027 errmsg_len);
7aafcaca 1028
d62a17ae 1029 return CMD_SUCCESS;
7aafcaca 1030 }
7aafcaca 1031
3ae8bfa5 1032 /* Clear all neighbors belonging to a specific peer-group. */
d62a17ae 1033 if (sort == clear_group) {
1034 struct peer_group *group;
7aafcaca 1035
d62a17ae 1036 group = peer_group_lookup(bgp, arg);
1037 if (!group) {
ff8a8a7a
CS
1038 snprintf(errmsg, errmsg_len,
1039 "%%BGP: No such peer-group %s", arg);
d62a17ae 1040 return CMD_WARNING;
1041 }
1042
1043 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
c368171c 1044 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1045
d62a17ae 1046 if (ret < 0)
ff8a8a7a
CS
1047 bgp_clear_vty_error(peer, afi, safi, ret,
1048 errmsg, errmsg_len);
3ae8bfa5
PM
1049 else
1050 found = true;
d62a17ae 1051 }
3ae8bfa5
PM
1052
1053 if (!found)
ff8a8a7a
CS
1054 snprintf(
1055 errmsg, errmsg_len,
1056 "%%BGP: No %s peer belonging to peer-group %s is configured",
5cb5f4d0 1057 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1058
d62a17ae 1059 return CMD_SUCCESS;
7aafcaca 1060 }
7aafcaca 1061
3ae8bfa5 1062 /* Clear all external (eBGP) neighbors. */
d62a17ae 1063 if (sort == clear_external) {
1064 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1065 if (peer->sort == BGP_PEER_IBGP)
1066 continue;
7aafcaca 1067
dc95985f 1068 bgp_peer_gr_flags_update(peer);
1069
36235319 1070 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1071 gr_router_detected = true;
dc95985f 1072
c368171c 1073 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
7aafcaca 1074
d62a17ae 1075 if (ret < 0)
ff8a8a7a
CS
1076 bgp_clear_vty_error(peer, afi, safi, ret,
1077 errmsg, errmsg_len);
3ae8bfa5
PM
1078 else
1079 found = true;
d62a17ae 1080 }
3ae8bfa5 1081
36235319
QY
1082 if (gr_router_detected
1083 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1084 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1085 } else if (!gr_router_detected
1086 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1087 bgp_zebra_send_capabilities(bgp, true);
1088 }
1089
3ae8bfa5 1090 if (!found)
ff8a8a7a
CS
1091 snprintf(errmsg, errmsg_len,
1092 "%%BGP: No external %s peer is configured",
1093 get_afi_safi_str(afi, safi, false));
3ae8bfa5 1094
d62a17ae 1095 return CMD_SUCCESS;
1096 }
1097
3ae8bfa5 1098 /* Clear all neighbors belonging to a specific AS. */
d62a17ae 1099 if (sort == clear_as) {
3ae8bfa5 1100 as_t as = strtoul(arg, NULL, 10);
d62a17ae 1101
1102 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1103 if (peer->as != as)
1104 continue;
1105
dc95985f 1106 bgp_peer_gr_flags_update(peer);
1107
36235319 1108 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
2ba1fe69 1109 gr_router_detected = true;
dc95985f 1110
c368171c 1111 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
d62a17ae 1112
1113 if (ret < 0)
ff8a8a7a
CS
1114 bgp_clear_vty_error(peer, afi, safi, ret,
1115 errmsg, errmsg_len);
3ae8bfa5
PM
1116 else
1117 found = true;
d62a17ae 1118 }
3ae8bfa5 1119
36235319
QY
1120 if (gr_router_detected
1121 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
dc95985f 1122 bgp_zebra_send_capabilities(bgp, false);
36235319
QY
1123 } else if (!gr_router_detected
1124 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
dc95985f 1125 bgp_zebra_send_capabilities(bgp, true);
1126 }
1127
3ae8bfa5 1128 if (!found)
ff8a8a7a
CS
1129 snprintf(errmsg, errmsg_len,
1130 "%%BGP: No %s peer is configured with AS %s",
1131 get_afi_safi_str(afi, safi, false), arg);
3ae8bfa5 1132
d62a17ae 1133 return CMD_SUCCESS;
1134 }
1135
1136 return CMD_SUCCESS;
1137}
1138
ff8a8a7a
CS
1139static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1140 enum clear_sort sort, enum bgp_clear_type stype,
1141 const char *arg, char *errmsg, size_t errmsg_len)
d62a17ae 1142{
1143 struct bgp *bgp;
1144
1145 /* BGP structure lookup. */
1146 if (name) {
1147 bgp = bgp_lookup_by_name(name);
1148 if (bgp == NULL) {
ff8a8a7a
CS
1149 snprintf(errmsg, errmsg_len,
1150 "Can't find BGP instance %s", name);
d62a17ae 1151 return CMD_WARNING;
1152 }
1153 } else {
1154 bgp = bgp_get_default();
1155 if (bgp == NULL) {
ff8a8a7a
CS
1156 snprintf(errmsg, errmsg_len,
1157 "No BGP process is configured");
d62a17ae 1158 return CMD_WARNING;
1159 }
1160 }
1161
ff8a8a7a 1162 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
7aafcaca
DS
1163}
1164
1165/* clear soft inbound */
ff8a8a7a 1166int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1167{
99b3ebd3
NS
1168 afi_t afi;
1169 safi_t safi;
ff8a8a7a
CS
1170 int ret;
1171
1172 FOREACH_AFI_SAFI (afi, safi) {
1173 ret = bgp_clear_vty(name, afi, safi, clear_all,
1174 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1175 errmsg_len);
1176 if (ret != CMD_SUCCESS)
1177 return -1;
1178 }
99b3ebd3 1179
ff8a8a7a 1180 return 0;
7aafcaca
DS
1181}
1182
1183/* clear soft outbound */
ff8a8a7a 1184int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
7aafcaca 1185{
99b3ebd3
NS
1186 afi_t afi;
1187 safi_t safi;
ff8a8a7a 1188 int ret;
99b3ebd3 1189
ff8a8a7a
CS
1190 FOREACH_AFI_SAFI (afi, safi) {
1191 ret = bgp_clear_vty(name, afi, safi, clear_all,
1192 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1193 errmsg_len);
1194 if (ret != CMD_SUCCESS)
1195 return -1;
1196 }
1197
1198 return 0;
7aafcaca
DS
1199}
1200
1201
f787d7a0 1202#ifndef VTYSH_EXTRACT_PL
2e4c2296 1203#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
1204#endif
1205
8029b216
AK
1206DEFUN_HIDDEN (bgp_local_mac,
1207 bgp_local_mac_cmd,
093e3f23 1208 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
8029b216
AK
1209 BGP_STR
1210 "Local MAC config\n"
1211 "VxLAN Network Identifier\n"
1212 "VNI number\n"
1213 "local mac\n"
1214 "mac address\n"
1215 "mac-mobility sequence\n"
1216 "seq number\n")
1217{
1218 int rv;
1219 vni_t vni;
1220 struct ethaddr mac;
1221 struct ipaddr ip;
1222 uint32_t seq;
1223 struct bgp *bgp;
1224
1225 vni = strtoul(argv[3]->arg, NULL, 10);
1226 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1227 vty_out(vty, "%% Malformed MAC address\n");
1228 return CMD_WARNING;
1229 }
1230 memset(&ip, 0, sizeof(ip));
1231 seq = strtoul(argv[7]->arg, NULL, 10);
1232
1233 bgp = bgp_get_default();
1234 if (!bgp) {
1235 vty_out(vty, "Default BGP instance is not there\n");
1236 return CMD_WARNING;
1237 }
1238
b5e140c8
AK
1239 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1240 zero_esi);
8029b216
AK
1241 if (rv < 0) {
1242 vty_out(vty, "Internal error\n");
1243 return CMD_WARNING;
1244 }
1245
1246 return CMD_SUCCESS;
1247}
1248
1249DEFUN_HIDDEN (no_bgp_local_mac,
1250 no_bgp_local_mac_cmd,
093e3f23 1251 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
8029b216
AK
1252 NO_STR
1253 BGP_STR
1254 "Local MAC config\n"
1255 "VxLAN Network Identifier\n"
1256 "VNI number\n"
1257 "local mac\n"
1258 "mac address\n")
1259{
1260 int rv;
1261 vni_t vni;
1262 struct ethaddr mac;
1263 struct ipaddr ip;
1264 struct bgp *bgp;
1265
1266 vni = strtoul(argv[4]->arg, NULL, 10);
1267 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1268 vty_out(vty, "%% Malformed MAC address\n");
1269 return CMD_WARNING;
1270 }
1271 memset(&ip, 0, sizeof(ip));
1272
1273 bgp = bgp_get_default();
1274 if (!bgp) {
1275 vty_out(vty, "Default BGP instance is not there\n");
1276 return CMD_WARNING;
1277 }
1278
ec0ab544 1279 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
8029b216
AK
1280 if (rv < 0) {
1281 vty_out(vty, "Internal error\n");
1282 return CMD_WARNING;
1283 }
1284
1285 return CMD_SUCCESS;
1286}
1287
718e3744 1288DEFUN (no_synchronization,
1289 no_synchronization_cmd,
1290 "no synchronization",
1291 NO_STR
1292 "Perform IGP synchronization\n")
1293{
d62a17ae 1294 return CMD_SUCCESS;
718e3744 1295}
1296
1297DEFUN (no_auto_summary,
1298 no_auto_summary_cmd,
1299 "no auto-summary",
1300 NO_STR
1301 "Enable automatic network number summarization\n")
1302{
d62a17ae 1303 return CMD_SUCCESS;
718e3744 1304}
3d515fd9 1305
718e3744 1306/* "router bgp" commands. */
ff8a8a7a
CS
1307DEFUN_YANG_NOSH(router_bgp,
1308 router_bgp_cmd,
1309 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1310 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1311{
d62a17ae 1312 int idx_asn = 2;
1313 int idx_view_vrf = 3;
1314 int idx_vrf = 4;
ff8a8a7a 1315 int ret = CMD_SUCCESS;
d62a17ae 1316 as_t as;
1317 struct bgp *bgp;
1318 const char *name = NULL;
1319 enum bgp_instance_type inst_type;
ff8a8a7a 1320 char base_xpath[XPATH_MAXLEN];
4062b455 1321 const struct lyd_node *bgp_glb_dnode;
d62a17ae 1322
1323 // "router bgp" without an ASN
1324 if (argc == 2) {
1325 // Pending: Make VRF option available for ASN less config
4062b455
IR
1326 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1327 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
d62a17ae 1328
4062b455
IR
1329 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1330 base_xpath);
1331 if (!bgp_glb_dnode) {
d62a17ae 1332 vty_out(vty, "%% No BGP process is configured\n");
1333 return CMD_WARNING_CONFIG_FAILED;
1334 }
1335
1336 if (listcount(bm->bgp) > 1) {
996c9314 1337 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1338 return CMD_WARNING_CONFIG_FAILED;
1339 }
ff8a8a7a 1340
4062b455 1341 as = yang_dnode_get_uint32(bgp_glb_dnode, "./global/local-as");
ff8a8a7a 1342
4062b455 1343 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
ff8a8a7a 1344
4062b455
IR
1345 /*
1346 * For backward compatibility with old commands we still
1347 * need to use the qobj infrastructure.
1348 */
1349 bgp = bgp_lookup(as, NULL);
1350 if (bgp)
ff8a8a7a 1351 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
4062b455
IR
1352
1353 return CMD_SUCCESS;
d62a17ae 1354 }
1355
1356 // "router bgp X"
1357 else {
d62a17ae 1358
ff8a8a7a 1359 as = strtoul(argv[idx_asn]->arg, NULL, 10);
d62a17ae 1360 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1361 if (argc > 3) {
1362 name = argv[idx_vrf]->arg;
1363
9a8bdf1c
PG
1364 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1365 if (strmatch(name, VRF_DEFAULT_NAME))
1366 name = NULL;
1367 else
1368 inst_type = BGP_INSTANCE_TYPE_VRF;
ff8a8a7a 1369 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
d62a17ae 1370 inst_type = BGP_INSTANCE_TYPE_VIEW;
ff8a8a7a 1371 }
d62a17ae 1372 }
ff8a8a7a
CS
1373 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1374 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1375
1376 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
87ce2564 1377 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
ff8a8a7a
CS
1378 argv[idx_asn]->arg);
1379 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
87ce2564
CS
1380 nb_cli_enqueue_change(vty,
1381 "./global/instance-type-view",
ff8a8a7a 1382 NB_OP_MODIFY, "true");
d3e36770
IR
1383 } else {
1384 nb_cli_enqueue_change(vty,
1385 "./global/instance-type-view",
1386 NB_OP_MODIFY, "false");
d62a17ae 1387 }
1388
ff8a8a7a
CS
1389 ret = nb_cli_apply_changes(vty, base_xpath);
1390 if (ret == CMD_SUCCESS) {
1391 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
3bd70bf8 1392
ff8a8a7a
CS
1393 /*
1394 * For backward compatibility with old commands we still
1395 * need to use the qobj infrastructure.
1396 */
ea1a5c00 1397 nb_cli_pending_commit_check(vty);
ff8a8a7a
CS
1398 bgp = bgp_lookup(as, name);
1399 if (bgp)
1400 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1401 }
d62a17ae 1402 }
1403
ff8a8a7a 1404 return ret;
718e3744 1405}
1406
718e3744 1407/* "no router bgp" commands. */
ff8a8a7a
CS
1408DEFUN_YANG(no_router_bgp,
1409 no_router_bgp_cmd,
1410 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1411 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
718e3744 1412{
d62a17ae 1413 int idx_vrf = 5;
d62a17ae 1414 const char *name = NULL;
ff8a8a7a 1415 char base_xpath[XPATH_MAXLEN];
4b63e358 1416 const struct lyd_node *bgp_glb_dnode;
718e3744 1417
d62a17ae 1418 // "no router bgp" without an ASN
1419 if (argc == 3) {
1420 // Pending: Make VRF option available for ASN less config
4b63e358
CS
1421 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1422 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
718e3744 1423
4b63e358
CS
1424 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1425 base_xpath);
1426 if (!bgp_glb_dnode) {
d62a17ae 1427 vty_out(vty, "%% No BGP process is configured\n");
1428 return CMD_WARNING_CONFIG_FAILED;
1429 }
7fb21a9f 1430
d62a17ae 1431 if (listcount(bm->bgp) > 1) {
996c9314 1432 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 1433 return CMD_WARNING_CONFIG_FAILED;
1434 }
1435 } else {
d62a17ae 1436 if (argc > 4)
1437 name = argv[idx_vrf]->arg;
45d1d7c9
IR
1438 else
1439 name = VRF_DEFAULT_NAME;
7fb21a9f 1440
45d1d7c9
IR
1441 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1442 "frr-bgp:bgp", "bgp", name);
d62a17ae 1443 }
718e3744 1444
ff8a8a7a 1445 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
718e3744 1446
ff8a8a7a 1447 return nb_cli_apply_changes(vty, base_xpath);
718e3744 1448}
1449
ff8a8a7a
CS
1450void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1451 bool show_defaults)
1452{
1453 const struct lyd_node *vrf_dnode;
1454 const char *vrf_name;
1455 as_t as;
6b0655a2 1456
ff8a8a7a
CS
1457 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1458 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
5e42cb2f 1459 as = yang_dnode_get_uint32(dnode, "./global/local-as");
718e3744 1460
ff8a8a7a
CS
1461 vty_out(vty, "!\n");
1462 vty_out(vty, "router bgp %u", as);
1463 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1464 vty_out(vty, " vrf %s", vrf_name);
1465 vty_out(vty, "\n");
718e3744 1466}
1467
ff8a8a7a
CS
1468/* BGP router-id. */
1469
1470DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1471 BGP_STR
1472 "Override configured router identifier\n"
1473 "Manually configured router identifier\n")
718e3744 1474{
87ce2564
CS
1475 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1476 router_id_str);
718e3744 1477
ff8a8a7a
CS
1478 return nb_cli_apply_changes(vty, NULL);
1479}
718e3744 1480
ff8a8a7a
CS
1481DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1482 NO_STR BGP_STR
1483 "Override configured router identifier\n"
1484 "Manually configured router identifier\n")
1485{
87ce2564 1486 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
ff8a8a7a 1487 router_id_str ? router_id_str : NULL);
718e3744 1488
ff8a8a7a 1489 return nb_cli_apply_changes(vty, NULL);
718e3744 1490}
1491
ff8a8a7a
CS
1492void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1493 bool show_defaults)
1494{
1495 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1496}
6b0655a2 1497
ed0e57e3
DA
1498DEFPY(bgp_community_alias, bgp_community_alias_cmd,
1499 "[no$no] bgp community alias WORD$community WORD$alias",
1500 NO_STR BGP_STR
1501 "Add community specific parameters\n"
1502 "Create an alias for a community\n"
1503 "Community (AA:BB or AA:BB:CC)\n"
1504 "Alias name\n")
1505{
1506 struct community_alias ca1;
1507 struct community_alias ca2;
1508 struct community_alias *lookup_community;
1509 struct community_alias *lookup_alias;
1510
1511 if (!community_str2com(community) && !lcommunity_str2com(community)) {
1512 vty_out(vty, "Invalid community format\n");
1513 return CMD_WARNING;
1514 }
1515
1516 memset(&ca1, 0, sizeof(ca1));
1517 memset(&ca2, 0, sizeof(ca2));
1518 strlcpy(ca1.community, community, sizeof(ca1.community));
1519 strlcpy(ca1.alias, alias, sizeof(ca1.alias));
1520
1521 lookup_community = bgp_ca_community_lookup(&ca1);
1522 lookup_alias = bgp_ca_alias_lookup(&ca1);
1523
1524 if (no) {
1525 bgp_ca_alias_delete(&ca1);
1526 bgp_ca_community_delete(&ca1);
1527 } else {
1528 if (lookup_alias) {
1529 /* Lookup if community hash table has an item
1530 * with the same alias name.
1531 */
1532 strlcpy(ca2.community, lookup_alias->community,
1533 sizeof(ca2.community));
1534 if (bgp_ca_community_lookup(&ca2)) {
1535 vty_out(vty,
1536 "community (%s) already has this alias (%s)\n",
1537 lookup_alias->community,
1538 lookup_alias->alias);
1539 return CMD_WARNING;
1540 }
1541 bgp_ca_alias_delete(&ca1);
1542 }
1543
1544 if (lookup_community)
1545 bgp_ca_community_delete(&ca1);
1546
1547 bgp_ca_alias_insert(&ca1);
1548 bgp_ca_community_insert(&ca1);
1549 }
1550
1551 return CMD_SUCCESS;
1552}
1553
9acb67cb
DS
1554DEFPY (bgp_global_suppress_fib_pending,
1555 bgp_global_suppress_fib_pending_cmd,
1556 "[no] bgp suppress-fib-pending",
1557 NO_STR
1558 BGP_STR
1559 "Advertise only routes that are programmed in kernel to peers globally\n")
1560{
1561 bm_wait_for_fib_set(!no);
1562
1563 return CMD_SUCCESS;
1564}
1565
c208c586
S
1566DEFPY (bgp_suppress_fib_pending,
1567 bgp_suppress_fib_pending_cmd,
1568 "[no] bgp suppress-fib-pending",
1569 NO_STR
1570 BGP_STR
1571 "Advertise only routes that are programmed in kernel to peers\n")
1572{
1573 VTY_DECLVAR_CONTEXT(bgp, bgp);
1574
1575 bgp_suppress_fib_pending_set(bgp, !no);
1576 return CMD_SUCCESS;
1577}
1578
1579
718e3744 1580/* BGP Cluster ID. */
ff8a8a7a
CS
1581DEFUN_YANG(bgp_cluster_id,
1582 bgp_cluster_id_cmd,
1583 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1584 BGP_STR
1585 "Configure Route-Reflector Cluster-id\n"
1586 "Route-Reflector Cluster-id in IP address format\n"
1587 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1588{
d62a17ae 1589 int idx_ipv4 = 2;
718e3744 1590
87ce2564
CS
1591 nb_cli_enqueue_change(
1592 vty, "./global/route-reflector/route-reflector-cluster-id",
1593 NB_OP_MODIFY, argv[idx_ipv4]->arg);
718e3744 1594
ff8a8a7a 1595 return nb_cli_apply_changes(vty, NULL);
718e3744 1596}
1597
ff8a8a7a
CS
1598DEFUN_YANG(no_bgp_cluster_id,
1599 no_bgp_cluster_id_cmd,
1600 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1601 NO_STR BGP_STR
1602 "Configure Route-Reflector Cluster-id\n"
1603 "Route-Reflector Cluster-id in IP address format\n"
1604 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1605{
87ce2564
CS
1606 nb_cli_enqueue_change(
1607 vty, "./global/route-reflector/route-reflector-cluster-id",
1608 NB_OP_DESTROY, NULL);
718e3744 1609
ff8a8a7a 1610 return nb_cli_apply_changes(vty, NULL);
718e3744 1611}
1612
c163f297
DS
1613DEFPY (bgp_norib,
1614 bgp_norib_cmd,
1615 "bgp no-rib",
1616 BGP_STR
1617 "Disable BGP route installation to RIB (Zebra)\n")
1618{
1619 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1620 vty_out(vty,
1621 "%% No-RIB option is already set, nothing to do here.\n");
1622 return CMD_SUCCESS;
1623 }
1624
1625 bgp_option_norib_set_runtime();
1626
1627 return CMD_SUCCESS;
1628}
1629
1630DEFPY (no_bgp_norib,
1631 no_bgp_norib_cmd,
1632 "no bgp no-rib",
1633 NO_STR
1634 BGP_STR
1635 "Disable BGP route installation to RIB (Zebra)\n")
1636{
1637 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1638 vty_out(vty,
1639 "%% No-RIB option is not set, nothing to do here.\n");
1640 return CMD_SUCCESS;
1641 }
1642
1643 bgp_option_norib_unset_runtime();
1644
1645 return CMD_SUCCESS;
1646}
1647
e46723a5
DS
1648DEFPY (no_bgp_send_extra_data,
1649 no_bgp_send_extra_data_cmd,
1650 "[no] bgp send-extra-data zebra",
1651 NO_STR
1652 BGP_STR
1653 "Extra data to Zebra for display/use\n"
1654 "To zebra\n")
1655{
ec0acb80
DA
1656 if (no)
1657 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1658 else
1659 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
e46723a5
DS
1660
1661 return CMD_SUCCESS;
1662}
1663
ff8a8a7a
CS
1664DEFUN_YANG(bgp_confederation_identifier,
1665 bgp_confederation_identifier_cmd,
1666 "bgp confederation identifier (1-4294967295)",
1667 "BGP specific commands\n"
1668 "AS confederation parameters\n"
1669 "AS number\n"
1670 "Set routing domain confederation AS\n")
718e3744 1671{
d62a17ae 1672 int idx_number = 3;
718e3744 1673
87ce2564
CS
1674 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1675 NB_OP_MODIFY, argv[idx_number]->arg);
718e3744 1676
ff8a8a7a 1677 return nb_cli_apply_changes(vty, NULL);
718e3744 1678}
1679
ff8a8a7a
CS
1680DEFUN_YANG(no_bgp_confederation_identifier,
1681 no_bgp_confederation_identifier_cmd,
1682 "no bgp confederation identifier [(1-4294967295)]",
1683 NO_STR
1684 "BGP specific commands\n"
1685 "AS confederation parameters\n"
1686 "AS number\n"
1687 "Set routing domain confederation AS\n")
718e3744 1688{
87ce2564
CS
1689 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1690 NB_OP_DESTROY, NULL);
718e3744 1691
ff8a8a7a 1692 return nb_cli_apply_changes(vty, NULL);
718e3744 1693}
1694
ff8a8a7a
CS
1695void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1696 struct lyd_node *dnode,
1697 bool show_defaults)
1698{
1699 vty_out(vty, " bgp confederation identifier %u\n",
1700 yang_dnode_get_uint32(dnode, NULL));
1701}
1702
1703DEFUN_YANG(bgp_confederation_peers,
1704 bgp_confederation_peers_cmd,
1705 "bgp confederation peers (1-4294967295)...",
1706 "BGP specific commands\n"
1707 "AS confederation parameters\n"
1708 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1709{
d62a17ae 1710 int idx_asn = 3;
d62a17ae 1711 int i;
718e3744 1712
ff8a8a7a 1713 for (i = idx_asn; i < argc; i++)
87ce2564 1714 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1715 NB_OP_CREATE, argv[i]->arg);
718e3744 1716
ff8a8a7a 1717 return nb_cli_apply_changes(vty, NULL);
718e3744 1718}
1719
ff8a8a7a
CS
1720DEFUN_YANG(no_bgp_confederation_peers,
1721 no_bgp_confederation_peers_cmd,
1722 "no bgp confederation peers (1-4294967295)...",
1723 NO_STR
1724 "BGP specific commands\n"
1725 "AS confederation parameters\n"
1726 "Peer ASs in BGP confederation\n" AS_STR)
718e3744 1727{
d62a17ae 1728 int idx_asn = 4;
d62a17ae 1729 int i;
718e3744 1730
ff8a8a7a 1731 for (i = idx_asn; i < argc; i++)
87ce2564 1732 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
ff8a8a7a 1733 NB_OP_DESTROY, argv[i]->arg);
0b2aa3a0 1734
ff8a8a7a
CS
1735 return nb_cli_apply_changes(vty, NULL);
1736}
1737
1738void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1739 struct lyd_node *dnode,
1740 bool show_defaults)
1741{
1742 vty_out(vty, " bgp confederation peers %u \n",
1743 yang_dnode_get_uint32(dnode, NULL));
718e3744 1744}
6b0655a2 1745
5e242b0d
DS
1746/**
1747 * Central routine for maximum-paths configuration.
1748 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1749 * @set: 1 for setting values, 0 for removing the max-paths config.
1750 */
37a87b8f
CS
1751int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1752 int peer_type, uint16_t maxpaths, uint16_t options,
1753 int set, char *errmsg, size_t errmsg_len)
d62a17ae 1754{
d62a17ae 1755 int ret;
d62a17ae 1756
1757 if (set) {
d62a17ae 1758 if (maxpaths > multipath_num) {
37a87b8f
CS
1759 snprintf(
1760 errmsg, errmsg_len,
d62a17ae 1761 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1762 maxpaths, multipath_num);
1763 return CMD_WARNING_CONFIG_FAILED;
1764 }
1765 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1766 options);
1767 } else
1768 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1769
1770 if (ret < 0) {
37a87b8f
CS
1771 snprintf(
1772 errmsg, errmsg_len,
d62a17ae 1773 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1774 (set == 1) ? "" : "un",
1775 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1776 maxpaths, afi, safi);
1777 return CMD_WARNING_CONFIG_FAILED;
1778 }
1779
1780 bgp_recalculate_all_bestpaths(bgp);
1781
1782 return CMD_SUCCESS;
165b5fff
JB
1783}
1784
ff8a8a7a
CS
1785void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1786 bool show_defaults)
abc920f8 1787{
ff8a8a7a
CS
1788 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1789 uint32_t med_admin_val;
abc920f8 1790
ff8a8a7a
CS
1791 vty_out(vty, " bgp max-med administrative");
1792 if ((med_admin_val =
1793 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1794 != BGP_MAXMED_VALUE_DEFAULT)
1795 vty_out(vty, " %u", med_admin_val);
1796 vty_out(vty, "\n");
1797 }
abc920f8 1798
ff8a8a7a
CS
1799 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1800 uint32_t onstartup_val;
abc920f8 1801
ff8a8a7a
CS
1802 vty_out(vty, " bgp max-med on-startup %u",
1803 yang_dnode_get_uint32(dnode,
1804 "./max-med-onstart-up-time"));
1805 onstartup_val = yang_dnode_get_uint32(
1806 dnode, "./max-med-onstart-up-value");
1807 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1808 vty_out(vty, " %u", onstartup_val);
1809
1810 vty_out(vty, "\n");
1811 }
abc920f8
DS
1812}
1813
ff8a8a7a
CS
1814DEFUN_YANG(bgp_maxmed_admin,
1815 bgp_maxmed_admin_cmd,
1816 "bgp max-med administrative ",
1817 BGP_STR
1818 "Advertise routes with max-med\n"
1819 "Administratively applied, for an indefinite period\n")
1820{
87ce2564 1821 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a
CS
1822 NB_OP_MODIFY, "true");
1823
1824 return nb_cli_apply_changes(vty, NULL);
1825}
1826
1827DEFUN_YANG(bgp_maxmed_admin_medv,
1828 bgp_maxmed_admin_medv_cmd,
1829 "bgp max-med administrative (0-4294967295)",
1830 BGP_STR
1831 "Advertise routes with max-med\n"
1832 "Administratively applied, for an indefinite period\n"
1833 "Max MED value to be used\n")
abc920f8 1834{
d62a17ae 1835 int idx_number = 3;
abc920f8 1836
87ce2564 1837 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1838 NB_OP_MODIFY, "true");
abc920f8 1839
87ce2564
CS
1840 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1841 NB_OP_MODIFY, argv[idx_number]->arg);
abc920f8 1842
ff8a8a7a 1843 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1844}
1845
ff8a8a7a
CS
1846DEFUN_YANG(no_bgp_maxmed_admin,
1847 no_bgp_maxmed_admin_cmd,
1848 "no bgp max-med administrative [(0-4294967295)]",
1849 NO_STR BGP_STR
1850 "Advertise routes with max-med\n"
1851 "Administratively applied, for an indefinite period\n"
1852 "Max MED value to be used\n")
abc920f8 1853{
87ce2564 1854 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
ff8a8a7a 1855 NB_OP_MODIFY, "false");
abc920f8 1856
87ce2564
CS
1857 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1858 NB_OP_MODIFY, NULL);
ff8a8a7a
CS
1859
1860 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1861}
1862
37a87b8f
CS
1863DEFUN_YANG (bgp_maxmed_onstartup,
1864 bgp_maxmed_onstartup_cmd,
1865 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1866 BGP_STR
1867 "Advertise routes with max-med\n"
1868 "Effective on a startup\n"
1869 "Time (seconds) period for max-med\n"
1870 "Max MED value to be used\n")
abc920f8 1871{
d62a17ae 1872 int idx = 0;
4668a151 1873
d62a17ae 1874 argv_find(argv, argc, "(5-86400)", &idx);
87ce2564
CS
1875 nb_cli_enqueue_change(vty,
1876 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a
CS
1877 NB_OP_MODIFY, argv[idx]->arg);
1878
d62a17ae 1879 if (argv_find(argv, argc, "(0-4294967295)", &idx))
87ce2564
CS
1880 nb_cli_enqueue_change(
1881 vty, "./global/med-config/max-med-onstart-up-value",
1882 NB_OP_MODIFY, argv[idx]->arg);
d62a17ae 1883 else
87ce2564
CS
1884 nb_cli_enqueue_change(
1885 vty, "./global/med-config/max-med-onstart-up-value",
1886 NB_OP_MODIFY, NULL);
abc920f8 1887
ff8a8a7a 1888 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1889}
1890
37a87b8f
CS
1891DEFUN_YANG (no_bgp_maxmed_onstartup,
1892 no_bgp_maxmed_onstartup_cmd,
1893 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1894 NO_STR BGP_STR
1895 "Advertise routes with max-med\n"
1896 "Effective on a startup\n"
1897 "Time (seconds) period for max-med\n"
1898 "Max MED value to be used\n")
abc920f8 1899{
87ce2564
CS
1900 nb_cli_enqueue_change(vty,
1901 "./global/med-config/max-med-onstart-up-time",
ff8a8a7a 1902 NB_OP_DESTROY, NULL);
abc920f8 1903
87ce2564
CS
1904 nb_cli_enqueue_change(vty,
1905 "./global/med-config/max-med-onstart-up-value",
ff8a8a7a 1906 NB_OP_MODIFY, NULL);
abc920f8 1907
ff8a8a7a 1908 return nb_cli_apply_changes(vty, NULL);
abc920f8
DS
1909}
1910
d70583f7
D
1911static int bgp_global_update_delay_config_vty(struct vty *vty,
1912 uint16_t update_delay,
1913 uint16_t establish_wait)
1914{
1915 struct listnode *node, *nnode;
1916 struct bgp *bgp;
1917 bool vrf_cfg = false;
1918
1919 /*
1920 * See if update-delay is set per-vrf and warn user to delete it
1921 * Note that we only need to check this if this is the first time
1922 * setting the global config.
1923 */
1924 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1925 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1926 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1927 vty_out(vty,
1928 "%% update-delay configuration found in vrf %s\n",
1929 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1930 ? VRF_DEFAULT_NAME
1931 : bgp->name);
1932 vrf_cfg = true;
1933 }
1934 }
1935 }
1936
1937 if (vrf_cfg) {
1938 vty_out(vty,
1939 "%%Failed: global update-delay config not permitted\n");
1940 return CMD_WARNING;
1941 }
1942
1943 if (!establish_wait) { /* update-delay <delay> */
1944 bm->v_update_delay = update_delay;
1945 bm->v_establish_wait = bm->v_update_delay;
1946 } else {
1947 /* update-delay <delay> <establish-wait> */
1948 if (update_delay < establish_wait) {
1949 vty_out(vty,
1950 "%%Failed: update-delay less than the establish-wait!\n");
1951 return CMD_WARNING_CONFIG_FAILED;
1952 }
1953
1954 bm->v_update_delay = update_delay;
1955 bm->v_establish_wait = establish_wait;
1956 }
1957
1958 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1959 bgp->v_update_delay = bm->v_update_delay;
1960 bgp->v_establish_wait = bm->v_establish_wait;
1961 }
1962
1963 return CMD_SUCCESS;
1964}
1965
1966static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1967{
1968 struct listnode *node, *nnode;
1969 struct bgp *bgp;
1970
1971 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1972 bm->v_establish_wait = bm->v_update_delay;
1973
1974 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1975 bgp->v_update_delay = bm->v_update_delay;
1976 bgp->v_establish_wait = bm->v_establish_wait;
1977 }
1978
1979 return CMD_SUCCESS;
1980}
1981
1982static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1983 uint16_t establish_wait)
f188f2c4 1984{
d62a17ae 1985 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1986
d70583f7
D
1987 /* if configured globally, per-instance config is not allowed */
1988 if (bm->v_update_delay) {
1989 vty_out(vty,
1990 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1991 return CMD_WARNING_CONFIG_FAILED;
1992 }
1993
f188f2c4 1994
d70583f7 1995 if (!establish_wait) /* update-delay <delay> */
d62a17ae 1996 {
1997 bgp->v_update_delay = update_delay;
1998 bgp->v_establish_wait = bgp->v_update_delay;
1999 return CMD_SUCCESS;
2000 }
f188f2c4 2001
d62a17ae 2002 /* update-delay <delay> <establish-wait> */
d62a17ae 2003 if (update_delay < establish_wait) {
2004 vty_out(vty,
2005 "%%Failed: update-delay less than the establish-wait!\n");
2006 return CMD_WARNING_CONFIG_FAILED;
2007 }
f188f2c4 2008
d62a17ae 2009 bgp->v_update_delay = update_delay;
2010 bgp->v_establish_wait = establish_wait;
f188f2c4 2011
d62a17ae 2012 return CMD_SUCCESS;
f188f2c4
DS
2013}
2014
d62a17ae 2015static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 2016{
d62a17ae 2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 2018
d70583f7
D
2019 /* If configured globally, cannot remove from one bgp instance */
2020 if (bm->v_update_delay) {
2021 vty_out(vty,
2022 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2023 return CMD_WARNING_CONFIG_FAILED;
2024 }
d62a17ae 2025 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2026 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 2027
d62a17ae 2028 return CMD_SUCCESS;
f188f2c4
DS
2029}
2030
2b791107 2031void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 2032{
d70583f7
D
2033 /* If configured globally, no need to display per-instance value */
2034 if (bgp->v_update_delay != bm->v_update_delay) {
d62a17ae 2035 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2036 if (bgp->v_update_delay != bgp->v_establish_wait)
2037 vty_out(vty, " %d", bgp->v_establish_wait);
2038 vty_out(vty, "\n");
2039 }
f188f2c4
DS
2040}
2041
d70583f7
D
2042/* Global update-delay configuration */
2043DEFPY (bgp_global_update_delay,
2044 bgp_global_update_delay_cmd,
2045 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2046 BGP_STR
2047 "Force initial delay for best-path and updates for all bgp instances\n"
2048 "Max delay in seconds\n"
2049 "Establish wait in seconds\n")
2050{
2051 return bgp_global_update_delay_config_vty(vty, delay, wait);
2052}
f188f2c4 2053
d70583f7
D
2054/* Global update-delay deconfiguration */
2055DEFPY (no_bgp_global_update_delay,
2056 no_bgp_global_update_delay_cmd,
2057 "no bgp update-delay [(0-3600) [(1-3600)]]",
2058 NO_STR
2059 BGP_STR
f188f2c4 2060 "Force initial delay for best-path and updates\n"
d70583f7
D
2061 "Max delay in seconds\n"
2062 "Establish wait in seconds\n")
f188f2c4 2063{
d70583f7 2064 return bgp_global_update_delay_deconfig_vty(vty);
f188f2c4
DS
2065}
2066
d70583f7
D
2067/* Update-delay configuration */
2068
2069DEFPY (bgp_update_delay,
2070 bgp_update_delay_cmd,
2071 "update-delay (0-3600)$delay [(1-3600)$wait]",
f188f2c4 2072 "Force initial delay for best-path and updates\n"
d70583f7
D
2073 "Max delay in seconds\n"
2074 "Establish wait in seconds\n")
f188f2c4 2075{
d70583f7 2076 return bgp_update_delay_config_vty(vty, delay, wait);
f188f2c4
DS
2077}
2078
2079/* Update-delay deconfiguration */
d70583f7 2080DEFPY (no_bgp_update_delay,
f188f2c4 2081 no_bgp_update_delay_cmd,
838758ac
DW
2082 "no update-delay [(0-3600) [(1-3600)]]",
2083 NO_STR
f188f2c4 2084 "Force initial delay for best-path and updates\n"
d70583f7
D
2085 "Max delay in seconds\n"
2086 "Establish wait in seconds\n")
f188f2c4 2087{
d62a17ae 2088 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
2089}
2090
5e242b0d 2091
ff8a8a7a 2092int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
cb1faec9 2093{
8fa7732f
QY
2094 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2095 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
555e09d4
QY
2096
2097 return CMD_SUCCESS;
2098}
2099
ff8a8a7a 2100int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
555e09d4 2101{
8fa7732f
QY
2102 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2103 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
cb1faec9 2104
d62a17ae 2105 return CMD_SUCCESS;
cb1faec9
DS
2106}
2107
2b791107 2108void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 2109{
555e09d4
QY
2110 uint32_t quanta =
2111 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2112 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 2113 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
2114}
2115
555e09d4
QY
2116void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2117{
2118 uint32_t quanta =
2119 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2120 if (quanta != BGP_READ_PACKET_MAX)
152456fe 2121 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 2122}
cb1faec9 2123
8fa7732f
QY
2124/* Packet quanta configuration
2125 *
2126 * XXX: The value set here controls the size of a stack buffer in the IO
2127 * thread. When changing these limits be careful to prevent stack overflow.
2128 *
2129 * Furthermore, the maximums used here should correspond to
2130 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2131 */
37a87b8f
CS
2132DEFPY_YANG (bgp_wpkt_quanta,
2133 bgp_wpkt_quanta_cmd,
2134 "[no] write-quanta (1-64)$quanta",
2135 NO_STR
2136 "How many packets to write to peer socket per run\n"
2137 "Number of packets\n")
ff8a8a7a
CS
2138{
2139 if (!no)
2140 nb_cli_enqueue_change(
2141 vty,
87ce2564 2142 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2143 NB_OP_MODIFY, quanta_str);
2144 else
2145 nb_cli_enqueue_change(
2146 vty,
87ce2564 2147 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
ff8a8a7a
CS
2148 NB_OP_MODIFY, NULL);
2149
2150 return nb_cli_apply_changes(vty, NULL);
2151}
2152
37a87b8f
CS
2153DEFPY_YANG (bgp_rpkt_quanta,
2154 bgp_rpkt_quanta_cmd,
2155 "[no] read-quanta (1-10)$quanta",
2156 NO_STR
2157 "How many packets to read from peer socket per I/O cycle\n"
2158 "Number of packets\n")
ff8a8a7a
CS
2159{
2160 if (!no)
2161 nb_cli_enqueue_change(
2162 vty,
87ce2564 2163 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a
CS
2164 NB_OP_MODIFY, quanta_str);
2165 else
2166 nb_cli_enqueue_change(
2167 vty,
87ce2564 2168 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
ff8a8a7a 2169 NB_OP_MODIFY, NULL);
cb1faec9 2170
ff8a8a7a 2171 return nb_cli_apply_changes(vty, NULL);
555e09d4
QY
2172}
2173
2b791107 2174void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 2175{
37a333fe 2176 if (!bgp->heuristic_coalesce)
d62a17ae 2177 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
2178}
2179
ff8a8a7a
CS
2180void cli_show_router_global_update_group_config_coalesce_time(
2181 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3f9c7369 2182{
ff8a8a7a
CS
2183 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2184}
2185
4668a151 2186
37a87b8f
CS
2187DEFUN_YANG (bgp_coalesce_time,
2188 bgp_coalesce_time_cmd,
2189 "coalesce-time (0-4294967295)",
2190 "Subgroup coalesce timer\n"
2191 "Subgroup coalesce timer value (in ms)\n")
ff8a8a7a 2192{
d62a17ae 2193 int idx = 0;
ff8a8a7a 2194
d62a17ae 2195 argv_find(argv, argc, "(0-4294967295)", &idx);
87ce2564
CS
2196 nb_cli_enqueue_change(
2197 vty, "./global/global-update-group-config/coalesce-time",
2198 NB_OP_MODIFY, argv[idx]->arg);
ff8a8a7a
CS
2199
2200 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2201}
2202
ff8a8a7a
CS
2203DEFUN_YANG(no_bgp_coalesce_time,
2204 no_bgp_coalesce_time_cmd,
2205 "no coalesce-time (0-4294967295)",
2206 NO_STR
2207 "Subgroup coalesce timer\n"
2208 "Subgroup coalesce timer value (in ms)\n")
3f9c7369 2209{
87ce2564
CS
2210 nb_cli_enqueue_change(
2211 vty, "./global/global-update-group-config/coalesce-time",
2212 NB_OP_MODIFY, NULL);
4668a151 2213
ff8a8a7a 2214 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
2215}
2216
5e242b0d 2217/* Maximum-paths configuration */
37a87b8f
CS
2218DEFUN_YANG (bgp_maxpaths,
2219 bgp_maxpaths_cmd,
2220 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2221 "Forward packets over multiple paths\n"
2222 "Number of paths\n")
5e242b0d 2223{
d62a17ae 2224 int idx_number = 1;
37a87b8f
CS
2225 char base_xpath[XPATH_MAXLEN];
2226 afi_t afi;
2227 safi_t safi;
2228
2229 afi = bgp_node_afi(vty);
2230 safi = bgp_node_safi(vty);
2231
2232 snprintf(
2233 base_xpath, sizeof(base_xpath),
2234 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2235 yang_afi_safi_value2identity(afi, safi),
2236 bgp_afi_safi_get_container_str(afi, safi));
2237
2238 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2239 argv[idx_number]->arg);
2240
2241 return nb_cli_apply_changes(vty, NULL);
2242}
2243
2244void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2245 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2246{
2247 vty_out(vty, " maximum-paths %d\n",
2248 yang_dnode_get_uint16(dnode, NULL));
5e242b0d
DS
2249}
2250
d62a17ae 2251ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2252 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2253 "Forward packets over multiple paths\n"
2254 "Number of paths\n")
596c17ba 2255
37a87b8f
CS
2256DEFUN_YANG (bgp_maxpaths_ibgp,
2257 bgp_maxpaths_ibgp_cmd,
2258 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2259 "Forward packets over multiple paths\n"
2260 "iBGP-multipath\n"
2261 "Number of paths\n")
165b5fff 2262{
d62a17ae 2263 int idx_number = 2;
37a87b8f
CS
2264 char base_xpath[XPATH_MAXLEN];
2265 afi_t afi;
2266 safi_t safi;
2267
2268 afi = bgp_node_afi(vty);
2269 safi = bgp_node_safi(vty);
2270
2271 snprintf(
2272 base_xpath, sizeof(base_xpath),
2273 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
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,
2278 argv[idx_number]->arg);
2279
2280 return nb_cli_apply_changes(vty, NULL);
5e242b0d 2281}
165b5fff 2282
d62a17ae 2283ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2284 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2285 "Forward packets over multiple paths\n"
2286 "iBGP-multipath\n"
2287 "Number of paths\n")
596c17ba 2288
37a87b8f
CS
2289DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2290 bgp_maxpaths_ibgp_cluster_cmd,
2291 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2292 "Forward packets over multiple paths\n"
2293 "iBGP-multipath\n"
2294 "Number of paths\n"
2295 "Match the cluster length\n")
5e242b0d 2296{
d62a17ae 2297 int idx_number = 2;
37a87b8f
CS
2298 char base_xpath[XPATH_MAXLEN];
2299 afi_t afi;
2300 safi_t safi;
2301
2302 afi = bgp_node_afi(vty);
2303 safi = bgp_node_safi(vty);
2304
2305 snprintf(
2306 base_xpath, sizeof(base_xpath),
2307 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2308 yang_afi_safi_value2identity(afi, safi),
2309 bgp_afi_safi_get_container_str(afi, safi));
2310
2311 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2312 argv[idx_number]->arg);
2313
2314 snprintf(
2315 base_xpath, sizeof(base_xpath),
2316 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
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, "true");
2321
2322 return nb_cli_apply_changes(vty, NULL);
2323}
2324
2325void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2326 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2327{
2328 vty_out(vty, " maximum-paths ibgp %d",
2329 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2330 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2331 vty_out(vty, " equal-cluster-length");
2332 vty_out(vty, "\n");
165b5fff
JB
2333}
2334
d62a17ae 2335ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2336 "maximum-paths ibgp " CMD_RANGE_STR(
2337 1, MULTIPATH_NUM) " equal-cluster-length",
2338 "Forward packets over multiple paths\n"
2339 "iBGP-multipath\n"
2340 "Number of paths\n"
2341 "Match the cluster length\n")
596c17ba 2342
37a87b8f
CS
2343DEFUN_YANG (no_bgp_maxpaths,
2344 no_bgp_maxpaths_cmd,
2345 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2346 NO_STR
2347 "Forward packets over multiple paths\n"
2348 "Number of paths\n")
165b5fff 2349{
37a87b8f
CS
2350 char base_xpath[XPATH_MAXLEN];
2351 afi_t afi;
2352 safi_t safi;
2353
2354 afi = bgp_node_afi(vty);
2355 safi = bgp_node_safi(vty);
2356
2357 snprintf(
2358 base_xpath, sizeof(base_xpath),
2359 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2360 yang_afi_safi_value2identity(afi, safi),
2361 bgp_afi_safi_get_container_str(afi, safi));
2362
2363 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2364
2365 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2366}
2367
d62a17ae 2368ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 2369 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 2370 "Forward packets over multiple paths\n"
2371 "Number of paths\n")
596c17ba 2372
37a87b8f
CS
2373DEFUN_YANG (no_bgp_maxpaths_ibgp,
2374 no_bgp_maxpaths_ibgp_cmd,
2375 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2376 NO_STR
2377 "Forward packets over multiple paths\n"
2378 "iBGP-multipath\n"
2379 "Number of paths\n"
2380 "Match the cluster length\n")
165b5fff 2381{
37a87b8f
CS
2382 char base_xpath[XPATH_MAXLEN];
2383 afi_t afi;
2384 safi_t safi;
2385
2386 afi = bgp_node_afi(vty);
2387 safi = bgp_node_safi(vty);
2388
2389 snprintf(
2390 base_xpath, sizeof(base_xpath),
2391 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2392 yang_afi_safi_value2identity(afi, safi),
2393 bgp_afi_safi_get_container_str(afi, safi));
2394
2395 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2396
2397 snprintf(
2398 base_xpath, sizeof(base_xpath),
2399 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2400 yang_afi_safi_value2identity(afi, safi),
2401 bgp_afi_safi_get_container_str(afi, safi));
2402
2403 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2404
2405 return nb_cli_apply_changes(vty, NULL);
165b5fff
JB
2406}
2407
d62a17ae 2408ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2409 "no maximum-paths ibgp [" CMD_RANGE_STR(
2410 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2411 NO_STR
2412 "Forward packets over multiple paths\n"
2413 "iBGP-multipath\n"
2414 "Number of paths\n"
2415 "Match the cluster length\n")
596c17ba 2416
dd65f45e
DL
2417static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2418 afi_t afi, safi_t safi)
165b5fff 2419{
00908b7a 2420 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
d62a17ae 2421 vty_out(vty, " maximum-paths %d\n",
2422 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2423 }
165b5fff 2424
00908b7a 2425 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
d62a17ae 2426 vty_out(vty, " maximum-paths ibgp %d",
2427 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2428 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2429 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2430 vty_out(vty, " equal-cluster-length");
2431 vty_out(vty, "\n");
2432 }
165b5fff 2433}
6b0655a2 2434
718e3744 2435/* BGP timers. */
2436
37a87b8f
CS
2437DEFUN_YANG (bgp_timers,
2438 bgp_timers_cmd,
2439 "timers bgp (0-65535) (0-65535)",
2440 "Adjust routing timers\n"
2441 "BGP timers\n"
2442 "Keepalive interval\n"
2443 "Holdtime\n")
718e3744 2444{
d62a17ae 2445 int idx_number = 2;
2446 int idx_number_2 = 3;
718e3744 2447
87ce2564 2448 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2449 NB_OP_MODIFY, argv[idx_number]->arg);
87ce2564 2450 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2451 NB_OP_MODIFY, argv[idx_number_2]->arg);
718e3744 2452
ff8a8a7a
CS
2453 return nb_cli_apply_changes(vty, NULL);
2454}
718e3744 2455
37a87b8f
CS
2456DEFUN_YANG (no_bgp_timers,
2457 no_bgp_timers_cmd,
2458 "no timers bgp [(0-65535) (0-65535)]",
2459 NO_STR
2460 "Adjust routing timers\n"
2461 "BGP timers\n"
2462 "Keepalive interval\n"
2463 "Holdtime\n")
ff8a8a7a 2464{
87ce2564 2465 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
ff8a8a7a 2466 NB_OP_DESTROY, NULL);
87ce2564 2467 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
ff8a8a7a 2468 NB_OP_DESTROY, NULL);
718e3744 2469
ff8a8a7a 2470 return nb_cli_apply_changes(vty, NULL);
718e3744 2471}
2472
ff8a8a7a
CS
2473void cli_show_router_bgp_route_reflector(struct vty *vty,
2474 struct lyd_node *dnode,
2475 bool show_defaults)
718e3744 2476{
ff8a8a7a
CS
2477 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2478 vty_out(vty, " no bgp client-to-client reflection\n");
718e3744 2479
ff8a8a7a
CS
2480 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2481 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2482
2483 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2484 vty_out(vty, " bgp cluster-id %s\n",
2485 yang_dnode_get_string(dnode,
2486 "./route-reflector-cluster-id"));
718e3744 2487}
2488
ff8a8a7a
CS
2489DEFUN_YANG(bgp_client_to_client_reflection,
2490 bgp_client_to_client_reflection_cmd,
2491 "bgp client-to-client reflection",
2492 "BGP specific commands\n"
2493 "Configure client to client route reflection\n"
2494 "reflection of routes allowed\n")
2495{
87ce2564 2496 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2497 NB_OP_MODIFY, "false");
6b0655a2 2498
ff8a8a7a
CS
2499 return nb_cli_apply_changes(vty, NULL);
2500}
2501
2502DEFUN_YANG(no_bgp_client_to_client_reflection,
2503 no_bgp_client_to_client_reflection_cmd,
2504 "no bgp client-to-client reflection",
2505 NO_STR
2506 "BGP specific commands\n"
2507 "Configure client to client route reflection\n"
2508 "reflection of routes allowed\n")
718e3744 2509{
87ce2564 2510 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
ff8a8a7a 2511 NB_OP_MODIFY, "true");
7aafcaca 2512
ff8a8a7a 2513 return nb_cli_apply_changes(vty, NULL);
718e3744 2514}
2515
ff8a8a7a
CS
2516void cli_show_router_bgp_route_selection(struct vty *vty,
2517 struct lyd_node *dnode,
2518 bool show_defaults)
718e3744 2519{
7aafcaca 2520
ff8a8a7a
CS
2521 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2522 vty_out(vty, " bgp always-compare-med\n");
2523
2524 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2525 vty_out(vty, " bgp bestpath as-path ignore\n");
2526
2527 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2528 vty_out(vty, " bgp bestpath as-path confed\n");
2529
2530 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2531 vty_out(vty, " bgp bestpath compare-routerid\n");
2532
2533 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2534 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2535 vty_out(vty,
2536 " bgp bestpath as-path multipath-relax as-set\n");
2537 else
2538 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2539 }
2540
2541 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2542 vty_out(vty, " bgp deterministic-med\n");
2543
2544 if (yang_dnode_get_bool(dnode, "./confed-med")
2545 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2546 vty_out(vty, " bgp bestpath med");
2547 if (yang_dnode_get_bool(dnode, "./confed-med"))
2548 vty_out(vty, " confed");
2549 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2550 vty_out(vty, " missing-as-worst");
2551 vty_out(vty, "\n");
2552 }
718e3744 2553}
2554
2555/* "bgp always-compare-med" configuration. */
ff8a8a7a
CS
2556DEFUN_YANG(bgp_always_compare_med,
2557 bgp_always_compare_med_cmd,
2558 "bgp always-compare-med",
2559 "BGP specific commands\n"
2560 "Allow comparing MED from different neighbors\n")
718e3744 2561{
87ce2564
CS
2562 nb_cli_enqueue_change(
2563 vty, "./global/route-selection-options/always-compare-med",
2564 NB_OP_MODIFY, "true");
7aafcaca 2565
ff8a8a7a 2566 return nb_cli_apply_changes(vty, NULL);
718e3744 2567}
2568
ff8a8a7a
CS
2569DEFUN_YANG(no_bgp_always_compare_med,
2570 no_bgp_always_compare_med_cmd,
2571 "no bgp always-compare-med",
2572 NO_STR
2573 "BGP specific commands\n"
2574 "Allow comparing MED from different neighbors\n")
718e3744 2575{
87ce2564
CS
2576 nb_cli_enqueue_change(
2577 vty, "./global/route-selection-options/always-compare-med",
2578 NB_OP_MODIFY, "false");
7aafcaca 2579
ff8a8a7a 2580 return nb_cli_apply_changes(vty, NULL);
718e3744 2581}
6b0655a2 2582
2adac256
DA
2583DEFUN_YANG(bgp_suppress_duplicates,
2584 bgp_suppress_duplicates_cmd,
2585 "bgp suppress-duplicates",
2586 "BGP specific commands\n"
2587 "Suppress duplicate updates if the route actually not changed\n")
2588{
2589 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2590 NB_OP_MODIFY, "true");
2591 return nb_cli_apply_changes(vty, NULL);
2592}
2593
2594DEFUN_YANG(no_bgp_suppress_duplicates,
2595 no_bgp_suppress_duplicates_cmd,
2596 "no bgp suppress-duplicates",
2597 NO_STR
2598 "BGP specific commands\n"
2599 "Suppress duplicate updates if the route actually not changed\n")
2600{
2601 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2602 NB_OP_MODIFY, "false");
2603 return nb_cli_apply_changes(vty, NULL);
2604}
2605
2606void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2607 struct lyd_node *dnode,
2608 bool show_defaults)
2609{
2610 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2611 vty_out(vty, " bgp suppress-duplicates\n");
2612}
2613
ff8a8a7a
CS
2614DEFUN_YANG(bgp_ebgp_requires_policy,
2615 bgp_ebgp_requires_policy_cmd,
2616 "bgp ebgp-requires-policy",
2617 "BGP specific commands\n"
2618 "Require in and out policy for eBGP peers (RFC8212)\n")
2619{
87ce2564
CS
2620 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2621 NB_OP_MODIFY, "true");
ff8a8a7a
CS
2622 return nb_cli_apply_changes(vty, NULL);
2623}
9dac9fc8 2624
ff8a8a7a
CS
2625DEFUN_YANG(no_bgp_ebgp_requires_policy,
2626 no_bgp_ebgp_requires_policy_cmd,
2627 "no bgp ebgp-requires-policy",
2628 NO_STR
2629 "BGP specific commands\n"
2630 "Require in and out policy for eBGP peers (RFC8212)\n")
9dac9fc8 2631{
87ce2564
CS
2632 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2633 NB_OP_MODIFY, "false");
ff8a8a7a 2634 return nb_cli_apply_changes(vty, NULL);
9dac9fc8
DA
2635}
2636
ff8a8a7a
CS
2637void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2638 struct lyd_node *dnode,
2639 bool show_defaults)
9dac9fc8 2640{
ff8a8a7a
CS
2641 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2642 vty_out(vty, " bgp ebgp-requires-policy\n");
9dac9fc8
DA
2643}
2644
fb29348a
DA
2645DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2646 "bgp reject-as-sets",
2647 "BGP specific commands\n"
2648 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2649{
2650 VTY_DECLVAR_CONTEXT(bgp, bgp);
2651 struct listnode *node, *nnode;
2652 struct peer *peer;
2653
7f972cd8 2654 bgp->reject_as_sets = true;
fb29348a
DA
2655
2656 /* Reset existing BGP sessions to reject routes
2657 * with aspath containing AS_SET or AS_CONFED_SET.
2658 */
2659 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2660 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2661 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2662 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2663 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2664 }
2665 }
2666
2667 return CMD_SUCCESS;
2668}
2669
2670DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2671 "no bgp reject-as-sets",
2672 NO_STR
2673 "BGP specific commands\n"
2674 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2675{
2676 VTY_DECLVAR_CONTEXT(bgp, bgp);
2677 struct listnode *node, *nnode;
2678 struct peer *peer;
2679
7f972cd8 2680 bgp->reject_as_sets = false;
fb29348a
DA
2681
2682 /* Reset existing BGP sessions to reject routes
2683 * with aspath containing AS_SET or AS_CONFED_SET.
2684 */
2685 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2686 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2687 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2688 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2689 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2690 }
2691 }
2692
2693 return CMD_SUCCESS;
2694}
9dac9fc8 2695
718e3744 2696/* "bgp deterministic-med" configuration. */
ff8a8a7a 2697DEFUN_YANG (bgp_deterministic_med,
718e3744 2698 bgp_deterministic_med_cmd,
2699 "bgp deterministic-med",
2700 "BGP specific commands\n"
2701 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2702{
87ce2564
CS
2703 nb_cli_enqueue_change(
2704 vty, "./global/route-selection-options/deterministic-med",
2705 NB_OP_MODIFY, "true");
7aafcaca 2706
ff8a8a7a 2707 return nb_cli_apply_changes(vty, NULL);
718e3744 2708}
2709
ff8a8a7a 2710DEFUN_YANG (no_bgp_deterministic_med,
718e3744 2711 no_bgp_deterministic_med_cmd,
2712 "no bgp deterministic-med",
2713 NO_STR
2714 "BGP specific commands\n"
2715 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2716{
87ce2564
CS
2717 nb_cli_enqueue_change(
2718 vty, "./global/route-selection-options/deterministic-med",
2719 NB_OP_MODIFY, "false");
d62a17ae 2720
ff8a8a7a 2721 return nb_cli_apply_changes(vty, NULL);
718e3744 2722}
538621f2 2723
055679e9 2724/* "bgp graceful-restart mode" configuration. */
538621f2 2725DEFUN (bgp_graceful_restart,
2ba1fe69 2726 bgp_graceful_restart_cmd,
2727 "bgp graceful-restart",
2728 "BGP specific commands\n"
2729 GR_CMD
055679e9 2730 )
538621f2 2731{
055679e9 2732 int ret = BGP_GR_FAILURE;
2733
2734 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2735 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
dc95985f 2736
d62a17ae 2737 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2738
2739 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2740
36235319
QY
2741 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2742 ret);
5cce3f05 2743
055679e9 2744 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2745 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
dc95985f 2746 vty_out(vty,
2747 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2748 return bgp_vty_return(vty, ret);
538621f2 2749}
2750
2751DEFUN (no_bgp_graceful_restart,
2ba1fe69 2752 no_bgp_graceful_restart_cmd,
2753 "no bgp graceful-restart",
2754 NO_STR
2755 "BGP specific commands\n"
2756 NO_GR_CMD
055679e9 2757 )
538621f2 2758{
d62a17ae 2759 VTY_DECLVAR_CONTEXT(bgp, bgp);
055679e9 2760
2761 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2762 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
055679e9 2763
2764 int ret = BGP_GR_FAILURE;
2765
2766 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2767
36235319
QY
2768 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2769 ret);
5cce3f05 2770
055679e9 2771 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2ba1fe69 2772 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
dc95985f 2773 vty_out(vty,
2774 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2775
2776 return bgp_vty_return(vty, ret);
538621f2 2777}
2778
93406d87 2779DEFUN (bgp_graceful_restart_stalepath_time,
2ba1fe69 2780 bgp_graceful_restart_stalepath_time_cmd,
2781 "bgp graceful-restart stalepath-time (1-4095)",
2782 "BGP specific commands\n"
2783 "Graceful restart capability parameters\n"
2784 "Set the max time to hold onto restarting peer's stale paths\n"
2785 "Delay value (seconds)\n")
93406d87 2786{
d62a17ae 2787 VTY_DECLVAR_CONTEXT(bgp, bgp);
2788 int idx_number = 3;
d7c0a89a 2789 uint32_t stalepath;
93406d87 2790
d62a17ae 2791 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2792 bgp->stalepath_time = stalepath;
2793 return CMD_SUCCESS;
93406d87 2794}
2795
eb6f1b41 2796DEFUN (bgp_graceful_restart_restart_time,
2ba1fe69 2797 bgp_graceful_restart_restart_time_cmd,
2798 "bgp graceful-restart restart-time (1-4095)",
2799 "BGP specific commands\n"
2800 "Graceful restart capability parameters\n"
2801 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2802 "Delay value (seconds)\n")
eb6f1b41 2803{
d62a17ae 2804 VTY_DECLVAR_CONTEXT(bgp, bgp);
2805 int idx_number = 3;
d7c0a89a 2806 uint32_t restart;
eb6f1b41 2807
d62a17ae 2808 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2809 bgp->restart_time = restart;
2810 return CMD_SUCCESS;
eb6f1b41
PG
2811}
2812
cfd47646 2813DEFUN (bgp_graceful_restart_select_defer_time,
2814 bgp_graceful_restart_select_defer_time_cmd,
2815 "bgp graceful-restart select-defer-time (0-3600)",
2816 "BGP specific commands\n"
2817 "Graceful restart capability parameters\n"
2818 "Set the time to defer the BGP route selection after restart\n"
2819 "Delay value (seconds, 0 - disable)\n")
2820{
2821 VTY_DECLVAR_CONTEXT(bgp, bgp);
2822 int idx_number = 3;
2823 uint32_t defer_time;
2824
2825 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2826 bgp->select_defer_time = defer_time;
2827 if (defer_time == 0)
892fedb6 2828 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2829 else
892fedb6 2830 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2831
2832 return CMD_SUCCESS;
2833}
2834
93406d87 2835DEFUN (no_bgp_graceful_restart_stalepath_time,
2ba1fe69 2836 no_bgp_graceful_restart_stalepath_time_cmd,
2837 "no bgp graceful-restart stalepath-time [(1-4095)]",
2838 NO_STR
2839 "BGP specific commands\n"
2840 "Graceful restart capability parameters\n"
2841 "Set the max time to hold onto restarting peer's stale paths\n"
2842 "Delay value (seconds)\n")
93406d87 2843{
d62a17ae 2844 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 2845
d62a17ae 2846 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2847 return CMD_SUCCESS;
93406d87 2848}
2849
eb6f1b41 2850DEFUN (no_bgp_graceful_restart_restart_time,
2ba1fe69 2851 no_bgp_graceful_restart_restart_time_cmd,
2852 "no bgp graceful-restart restart-time [(1-4095)]",
2853 NO_STR
2854 "BGP specific commands\n"
2855 "Graceful restart capability parameters\n"
2856 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2857 "Delay value (seconds)\n")
eb6f1b41 2858{
d62a17ae 2859 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 2860
d62a17ae 2861 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2862 return CMD_SUCCESS;
eb6f1b41
PG
2863}
2864
cfd47646 2865DEFUN (no_bgp_graceful_restart_select_defer_time,
2866 no_bgp_graceful_restart_select_defer_time_cmd,
2867 "no bgp graceful-restart select-defer-time [(0-3600)]",
2868 NO_STR
2869 "BGP specific commands\n"
2870 "Graceful restart capability parameters\n"
2871 "Set the time to defer the BGP route selection after restart\n"
2872 "Delay value (seconds)\n")
2873{
2874 VTY_DECLVAR_CONTEXT(bgp, bgp);
2875
2876 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
892fedb6 2877 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
cfd47646 2878
2879 return CMD_SUCCESS;
2880}
2881
43fc21b3 2882DEFUN (bgp_graceful_restart_preserve_fw,
2ba1fe69 2883 bgp_graceful_restart_preserve_fw_cmd,
2884 "bgp graceful-restart preserve-fw-state",
2885 "BGP specific commands\n"
2886 "Graceful restart capability parameters\n"
2887 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2888{
d62a17ae 2889 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2890 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2891 return CMD_SUCCESS;
43fc21b3
JC
2892}
2893
2894DEFUN (no_bgp_graceful_restart_preserve_fw,
2ba1fe69 2895 no_bgp_graceful_restart_preserve_fw_cmd,
2896 "no bgp graceful-restart preserve-fw-state",
2897 NO_STR
2898 "BGP specific commands\n"
2899 "Graceful restart capability parameters\n"
2900 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
43fc21b3 2901{
d62a17ae 2902 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 2903 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
d62a17ae 2904 return CMD_SUCCESS;
43fc21b3
JC
2905}
2906
055679e9 2907DEFUN (bgp_graceful_restart_disable,
2ba1fe69 2908 bgp_graceful_restart_disable_cmd,
2909 "bgp graceful-restart-disable",
2910 "BGP specific commands\n"
2911 GR_DISABLE)
055679e9 2912{
2913 int ret = BGP_GR_FAILURE;
2914
2915 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2916 zlog_debug(
2ba1fe69 2917 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
dc95985f 2918
055679e9 2919 VTY_DECLVAR_CONTEXT(bgp, bgp);
2920
2921 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2922
dc95985f 2923 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2924 bgp->peer, ret);
5cce3f05 2925
055679e9 2926 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2927 zlog_debug(
2ba1fe69 2928 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
dc95985f 2929 vty_out(vty,
2930 "Graceful restart configuration changed, reset all peers to take effect\n");
2931
055679e9 2932 return bgp_vty_return(vty, ret);
2933}
2934
2935DEFUN (no_bgp_graceful_restart_disable,
2ba1fe69 2936 no_bgp_graceful_restart_disable_cmd,
2937 "no bgp graceful-restart-disable",
2938 NO_STR
2939 "BGP specific commands\n"
2940 NO_GR_DISABLE
055679e9 2941 )
2942{
2943 VTY_DECLVAR_CONTEXT(bgp, bgp);
2944
2945 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2946 zlog_debug(
2ba1fe69 2947 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
055679e9 2948
2949 int ret = BGP_GR_FAILURE;
2950
2951 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2952
36235319
QY
2953 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2954 ret);
5cce3f05 2955
055679e9 2956 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2957 zlog_debug(
2ba1fe69 2958 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
dc95985f 2959 vty_out(vty,
2960 "Graceful restart configuration changed, reset all peers to take effect\n");
055679e9 2961
2962 return bgp_vty_return(vty, ret);
2963}
2964
2965DEFUN (bgp_neighbor_graceful_restart_set,
2ba1fe69 2966 bgp_neighbor_graceful_restart_set_cmd,
2967 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2968 NEIGHBOR_STR
2969 NEIGHBOR_ADDR_STR2
2970 GR_NEIGHBOR_CMD
055679e9 2971 )
2972{
2973 int idx_peer = 1;
2974 struct peer *peer;
2975 int ret = BGP_GR_FAILURE;
2976
dc95985f 2977 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2978
055679e9 2979 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2980 zlog_debug(
2ba1fe69 2981 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
dc95985f 2982
055679e9 2983 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2984 if (!peer)
2985 return CMD_WARNING_CONFIG_FAILED;
2986
2987 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2988
dc95985f 2989 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2990 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 2991
2992 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2993 zlog_debug(
2ba1fe69 2994 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 2995 vty_out(vty,
2996 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 2997
2998 return bgp_vty_return(vty, ret);
2999}
3000
3001DEFUN (no_bgp_neighbor_graceful_restart,
2ba1fe69 3002 no_bgp_neighbor_graceful_restart_set_cmd,
3003 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3004 NO_STR
3005 NEIGHBOR_STR
3006 NEIGHBOR_ADDR_STR2
3007 NO_GR_NEIGHBOR_CMD
055679e9 3008 )
3009{
3010 int idx_peer = 2;
3011 int ret = BGP_GR_FAILURE;
3012 struct peer *peer;
3013
dc95985f 3014 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3015
055679e9 3016 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3017 if (!peer)
3018 return CMD_WARNING_CONFIG_FAILED;
3019
3020 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3021 zlog_debug(
2ba1fe69 3022 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
055679e9 3023
3024 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3025
dc95985f 3026 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3027 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3028
3029 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3030 zlog_debug(
2ba1fe69 3031 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
dc95985f 3032 vty_out(vty,
3033 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3034
3035 return bgp_vty_return(vty, ret);
3036}
3037
3038DEFUN (bgp_neighbor_graceful_restart_helper_set,
2ba1fe69 3039 bgp_neighbor_graceful_restart_helper_set_cmd,
3040 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3041 NEIGHBOR_STR
3042 NEIGHBOR_ADDR_STR2
3043 GR_NEIGHBOR_HELPER_CMD
055679e9 3044 )
3045{
3046 int idx_peer = 1;
3047 struct peer *peer;
3048 int ret = BGP_GR_FAILURE;
3049
dc95985f 3050 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3051
055679e9 3052 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3053 zlog_debug(
2ba1fe69 3054 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
dc95985f 3055
055679e9 3056 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3057
055679e9 3058 if (!peer)
3059 return CMD_WARNING_CONFIG_FAILED;
3060
3061
3062 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
5cce3f05 3063
dc95985f 3064 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3065 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
5cce3f05 3066
055679e9 3067 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3068 zlog_debug(
2ba1fe69 3069 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3070 vty_out(vty,
3071 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3072
3073 return bgp_vty_return(vty, ret);
3074}
3075
3076DEFUN (no_bgp_neighbor_graceful_restart_helper,
2ba1fe69 3077 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3078 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3079 NO_STR
3080 NEIGHBOR_STR
3081 NEIGHBOR_ADDR_STR2
3082 NO_GR_NEIGHBOR_HELPER_CMD
055679e9 3083 )
3084{
3085 int idx_peer = 2;
3086 int ret = BGP_GR_FAILURE;
3087 struct peer *peer;
3088
dc95985f 3089 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3090
055679e9 3091 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3092 if (!peer)
3093 return CMD_WARNING_CONFIG_FAILED;
3094
3095 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3096 zlog_debug(
2ba1fe69 3097 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
055679e9 3098
36235319 3099 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
055679e9 3100
dc95985f 3101 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3102 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3103
3104 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3105 zlog_debug(
2ba1fe69 3106 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
dc95985f 3107 vty_out(vty,
3108 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3109
3110 return bgp_vty_return(vty, ret);
3111}
3112
3113DEFUN (bgp_neighbor_graceful_restart_disable_set,
2ba1fe69 3114 bgp_neighbor_graceful_restart_disable_set_cmd,
3115 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3116 NEIGHBOR_STR
3117 NEIGHBOR_ADDR_STR2
3118 GR_NEIGHBOR_DISABLE_CMD
055679e9 3119 )
3120{
3121 int idx_peer = 1;
3122 struct peer *peer;
3123 int ret = BGP_GR_FAILURE;
3124
dc95985f 3125 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3126
055679e9 3127 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3128 zlog_debug(
2ba1fe69 3129 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3130
3131 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3132 if (!peer)
3133 return CMD_WARNING_CONFIG_FAILED;
3134
36235319 3135 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
055679e9 3136
3137 if (peer->bgp->t_startup)
3138 bgp_peer_gr_flags_update(peer);
3139
dc95985f 3140 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3141 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3142
055679e9 3143 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3144 zlog_debug(
2ba1fe69 3145 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3146 vty_out(vty,
3147 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3148
3149 return bgp_vty_return(vty, ret);
3150}
3151
3152DEFUN (no_bgp_neighbor_graceful_restart_disable,
2ba1fe69 3153 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3154 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3155 NO_STR
3156 NEIGHBOR_STR
3157 NEIGHBOR_ADDR_STR2
3158 NO_GR_NEIGHBOR_DISABLE_CMD
055679e9 3159 )
3160{
3161 int idx_peer = 2;
3162 int ret = BGP_GR_FAILURE;
3163 struct peer *peer;
3164
dc95985f 3165 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3166
055679e9 3167 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3168 if (!peer)
3169 return CMD_WARNING_CONFIG_FAILED;
3170
3171 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3172 zlog_debug(
2ba1fe69 3173 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
055679e9 3174
3175 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3176
dc95985f 3177 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3178 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
055679e9 3179
3180 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3181 zlog_debug(
2ba1fe69 3182 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
dc95985f 3183 vty_out(vty,
3184 "Graceful restart configuration changed, reset this peer to take effect\n");
055679e9 3185
3186 return bgp_vty_return(vty, ret);
3187}
3188
d6e3c15b 3189DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3190 bgp_graceful_restart_disable_eor_cmd,
3191 "bgp graceful-restart disable-eor",
3192 "BGP specific commands\n"
3193 "Graceful restart configuration parameters\n"
3194 "Disable EOR Check\n")
3195{
3196 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3197 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3198
d6e3c15b 3199 return CMD_SUCCESS;
3200}
3201
3202DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3203 no_bgp_graceful_restart_disable_eor_cmd,
3204 "no bgp graceful-restart disable-eor",
3205 NO_STR
3206 "BGP specific commands\n"
3207 "Graceful restart configuration parameters\n"
3208 "Disable EOR Check\n")
3209{
3210 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3211 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
dc95985f 3212
3213 return CMD_SUCCESS;
3214}
3215
3216DEFUN (bgp_graceful_restart_rib_stale_time,
3217 bgp_graceful_restart_rib_stale_time_cmd,
3218 "bgp graceful-restart rib-stale-time (1-3600)",
3219 "BGP specific commands\n"
3220 "Graceful restart configuration parameters\n"
3221 "Specify the stale route removal timer in rib\n"
3222 "Delay value (seconds)\n")
3223{
3224 VTY_DECLVAR_CONTEXT(bgp, bgp);
3225 int idx_number = 3;
3226 uint32_t stale_time;
3227
3228 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3229 bgp->rib_stale_time = stale_time;
3230 /* Send the stale timer update message to RIB */
3231 if (bgp_zebra_stale_timer_update(bgp))
3232 return CMD_WARNING;
3233
3234 return CMD_SUCCESS;
3235}
3236
3237DEFUN (no_bgp_graceful_restart_rib_stale_time,
3238 no_bgp_graceful_restart_rib_stale_time_cmd,
3239 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3240 NO_STR
3241 "BGP specific commands\n"
3242 "Graceful restart configuration parameters\n"
3243 "Specify the stale route removal timer in rib\n"
3244 "Delay value (seconds)\n")
3245{
3246 VTY_DECLVAR_CONTEXT(bgp, bgp);
3247
3248 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3249 /* Send the stale timer update message to RIB */
3250 if (bgp_zebra_stale_timer_update(bgp))
3251 return CMD_WARNING;
3252
d6e3c15b 3253 return CMD_SUCCESS;
3254}
3255
ff8a8a7a
CS
3256static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3257 char *errmsg,
3258 size_t errmsg_len)
05bd726c 3259{
3260 bgp_static_redo_import_check(bgp);
3261 bgp_redistribute_redo(bgp);
ff8a8a7a
CS
3262 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3263 return -1;
3264 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3265 return -1;
3266
3267 return 0;
05bd726c 3268}
3269
3270static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3271{
3272 struct listnode *node, *nnode;
3273 struct bgp *bgp;
3274 bool vrf_cfg = false;
ff8a8a7a 3275 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3276
3277 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3278 return CMD_SUCCESS;
3279
3280 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3281 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3282 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3283 vty_out(vty,
3284 "%% graceful-shutdown configuration found in vrf %s\n",
3285 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3286 VRF_DEFAULT_NAME : bgp->name);
3287 vrf_cfg = true;
3288 }
3289 }
3290
3291 if (vrf_cfg) {
3292 vty_out(vty,
3293 "%%Failed: global graceful-shutdown not permitted\n");
3294 return CMD_WARNING;
3295 }
3296
3297 /* Set flag globally */
3298 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3299
3300 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3301 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3302 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3303 sizeof(errmsg))
3304 < 0)
3305 if (strlen(errmsg))
3306 vty_out(vty, "%s\n", errmsg);
3307 }
05bd726c 3308
3309 return CMD_SUCCESS;
3310}
3311
3312static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3313{
3314 struct listnode *node, *nnode;
3315 struct bgp *bgp;
ff8a8a7a 3316 char errmsg[BUFSIZ] = {'\0'};
05bd726c 3317
3318 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3319 return CMD_SUCCESS;
3320
3321 /* Unset flag globally */
3322 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3323
3324 /* Initiate processing for all BGP instances. */
ff8a8a7a
CS
3325 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3326 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3327 sizeof(errmsg))
3328 < 0)
3329 if (strlen(errmsg))
3330 vty_out(vty, "%s\n", errmsg);
3331 }
05bd726c 3332
3333 return CMD_SUCCESS;
3334}
3335
7f323236
DW
3336/* "bgp graceful-shutdown" configuration */
3337DEFUN (bgp_graceful_shutdown,
3338 bgp_graceful_shutdown_cmd,
3339 "bgp graceful-shutdown",
3340 BGP_STR
3341 "Graceful shutdown parameters\n")
3342{
05bd726c 3343 if (vty->node == CONFIG_NODE)
3344 return bgp_global_graceful_shutdown_config_vty(vty);
3345
87ce2564
CS
3346 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3347 NB_OP_MODIFY, "true");
7f323236 3348
ff8a8a7a 3349 return nb_cli_apply_changes(vty, NULL);
7f323236
DW
3350}
3351
ff8a8a7a 3352DEFUN_YANG (no_bgp_graceful_shutdown,
7f323236
DW
3353 no_bgp_graceful_shutdown_cmd,
3354 "no bgp graceful-shutdown",
3355 NO_STR
3356 BGP_STR
3357 "Graceful shutdown parameters\n")
3358{
05bd726c 3359 if (vty->node == CONFIG_NODE)
3360 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3361
87ce2564
CS
3362 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3363 NB_OP_MODIFY, "false");
05bd726c 3364
ff8a8a7a
CS
3365 return nb_cli_apply_changes(vty, NULL);
3366}
7f323236 3367
ff8a8a7a
CS
3368void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3369 struct lyd_node *dnode,
3370 bool show_defaults)
3371{
3372 if (yang_dnode_get_bool(dnode, NULL))
3373 vty_out(vty, " bgp graceful-shutdown\n");
7f323236
DW
3374}
3375
718e3744 3376/* "bgp fast-external-failover" configuration. */
ff8a8a7a 3377DEFUN_YANG (bgp_fast_external_failover,
718e3744 3378 bgp_fast_external_failover_cmd,
3379 "bgp fast-external-failover",
3380 BGP_STR
3381 "Immediately reset session if a link to a directly connected external peer goes down\n")
3382{
87ce2564
CS
3383 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3384 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3385
3386 return nb_cli_apply_changes(vty, NULL);
718e3744 3387}
3388
ff8a8a7a 3389DEFUN_YANG (no_bgp_fast_external_failover,
718e3744 3390 no_bgp_fast_external_failover_cmd,
3391 "no bgp fast-external-failover",
3392 NO_STR
3393 BGP_STR
3394 "Immediately reset session if a link to a directly connected external peer goes down\n")
3395{
87ce2564
CS
3396 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3397 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3398
3399 return nb_cli_apply_changes(vty, NULL);
3400}
3401
3402void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3403 struct lyd_node *dnode,
3404 bool show_defaults)
3405{
3406 if (!yang_dnode_get_bool(dnode, NULL))
3407 vty_out(vty, " no bgp fast-external-failover\n");
718e3744 3408}
6b0655a2 3409
718e3744 3410/* "bgp bestpath compare-routerid" configuration. */
ff8a8a7a
CS
3411DEFUN_YANG(bgp_bestpath_compare_router_id,
3412 bgp_bestpath_compare_router_id_cmd,
3413 "bgp bestpath compare-routerid",
3414 "BGP specific commands\n"
3415 "Change the default bestpath selection\n"
3416 "Compare router-id for identical EBGP paths\n")
718e3744 3417{
ff8a8a7a 3418 nb_cli_enqueue_change(
87ce2564
CS
3419 vty,
3420 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3421 NB_OP_MODIFY, "true");
7aafcaca 3422
ff8a8a7a 3423 return nb_cli_apply_changes(vty, NULL);
718e3744 3424}
3425
ff8a8a7a
CS
3426DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3427 no_bgp_bestpath_compare_router_id_cmd,
3428 "no bgp bestpath compare-routerid",
3429 NO_STR
3430 "BGP specific commands\n"
3431 "Change the default bestpath selection\n"
3432 "Compare router-id for identical EBGP paths\n")
718e3744 3433{
ff8a8a7a 3434 nb_cli_enqueue_change(
87ce2564
CS
3435 vty,
3436 "./global/route-selection-options/external-compare-router-id",
ff8a8a7a 3437 NB_OP_MODIFY, "false");
7aafcaca 3438
ff8a8a7a 3439 return nb_cli_apply_changes(vty, NULL);
718e3744 3440}
6b0655a2 3441
718e3744 3442/* "bgp bestpath as-path ignore" configuration. */
ff8a8a7a
CS
3443DEFUN_YANG(bgp_bestpath_aspath_ignore,
3444 bgp_bestpath_aspath_ignore_cmd,
3445 "bgp bestpath as-path ignore",
3446 "BGP specific commands\n"
3447 "Change the default bestpath selection\n"
3448 "AS-path attribute\n"
3449 "Ignore as-path length in selecting a route\n")
718e3744 3450{
87ce2564
CS
3451 nb_cli_enqueue_change(
3452 vty, "./global/route-selection-options/ignore-as-path-length",
3453 NB_OP_MODIFY, "true");
7aafcaca 3454
ff8a8a7a 3455 return nb_cli_apply_changes(vty, NULL);
718e3744 3456}
3457
ff8a8a7a
CS
3458DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3459 no_bgp_bestpath_aspath_ignore_cmd,
3460 "no bgp bestpath as-path ignore",
3461 NO_STR
3462 "BGP specific commands\n"
3463 "Change the default bestpath selection\n"
3464 "AS-path attribute\n"
3465 "Ignore as-path length in selecting a route\n")
718e3744 3466{
87ce2564
CS
3467 nb_cli_enqueue_change(
3468 vty, "./global/route-selection-options/ignore-as-path-length",
3469 NB_OP_MODIFY, "false");
7aafcaca 3470
ff8a8a7a 3471 return nb_cli_apply_changes(vty, NULL);
718e3744 3472}
6b0655a2 3473
6811845b 3474/* "bgp bestpath as-path confed" configuration. */
ff8a8a7a 3475DEFUN_YANG (bgp_bestpath_aspath_confed,
6811845b 3476 bgp_bestpath_aspath_confed_cmd,
3477 "bgp bestpath as-path confed",
3478 "BGP specific commands\n"
3479 "Change the default bestpath selection\n"
3480 "AS-path attribute\n"
3481 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3482{
87ce2564
CS
3483 nb_cli_enqueue_change(vty,
3484 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3485 NB_OP_MODIFY, "true");
7aafcaca 3486
ff8a8a7a 3487 return nb_cli_apply_changes(vty, NULL);
6811845b 3488}
3489
ff8a8a7a 3490DEFUN_YANG (no_bgp_bestpath_aspath_confed,
6811845b 3491 no_bgp_bestpath_aspath_confed_cmd,
3492 "no bgp bestpath as-path confed",
3493 NO_STR
3494 "BGP specific commands\n"
3495 "Change the default bestpath selection\n"
3496 "AS-path attribute\n"
3497 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3498{
87ce2564
CS
3499 nb_cli_enqueue_change(vty,
3500 "./global/route-selection-options/aspath-confed",
ff8a8a7a 3501 NB_OP_MODIFY, "false");
7aafcaca 3502
ff8a8a7a 3503 return nb_cli_apply_changes(vty, NULL);
6811845b 3504}
6b0655a2 3505
2fdd455c 3506/* "bgp bestpath as-path multipath-relax" configuration. */
ff8a8a7a 3507DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
2fdd455c 3508 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3509 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3510 "BGP specific commands\n"
3511 "Change the default bestpath selection\n"
3512 "AS-path attribute\n"
3513 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3514 "Generate an AS_SET\n"
16fc1eec
DS
3515 "Do not generate an AS_SET\n")
3516{
d62a17ae 3517 int idx = 0;
219178b6 3518
87ce2564
CS
3519 nb_cli_enqueue_change(
3520 vty, "./global/route-selection-options/allow-multiple-as",
3521 NB_OP_MODIFY, "true");
d62a17ae 3522 if (argv_find(argv, argc, "as-set", &idx))
ff8a8a7a 3523 nb_cli_enqueue_change(
87ce2564
CS
3524 vty,
3525 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3526 NB_OP_MODIFY, "true");
d62a17ae 3527 else
ff8a8a7a 3528 nb_cli_enqueue_change(
87ce2564
CS
3529 vty,
3530 "./global/route-selection-options/multi-path-as-set",
ff8a8a7a 3531 NB_OP_MODIFY, "false");
7aafcaca 3532
ff8a8a7a 3533 return nb_cli_apply_changes(vty, NULL);
16fc1eec
DS
3534}
3535
ff8a8a7a 3536DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
219178b6 3537 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 3538 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
3539 NO_STR
3540 "BGP specific commands\n"
3541 "Change the default bestpath selection\n"
3542 "AS-path attribute\n"
3543 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 3544 "Generate an AS_SET\n"
16fc1eec
DS
3545 "Do not generate an AS_SET\n")
3546{
87ce2564
CS
3547 nb_cli_enqueue_change(
3548 vty, "./global/route-selection-options/allow-multiple-as",
3549 NB_OP_MODIFY, "false");
3550 nb_cli_enqueue_change(
3551 vty, "./global/route-selection-options/multi-path-as-set",
3552 NB_OP_MODIFY, "false");
7aafcaca 3553
ff8a8a7a 3554 return nb_cli_apply_changes(vty, NULL);
2fdd455c 3555}
6b0655a2 3556
ee88563a
JM
3557/* "bgp bestpath peer-type multipath-relax" configuration. */
3558DEFUN(bgp_bestpath_peer_type_multipath_relax,
3559 bgp_bestpath_peer_type_multipath_relax_cmd,
3560 "bgp bestpath peer-type multipath-relax",
3561 BGP_STR
3562 "Change the default bestpath selection\n"
3563 "Peer type\n"
3564 "Allow load sharing across routes learned from different peer types\n")
3565{
3566 VTY_DECLVAR_CONTEXT(bgp, bgp);
3567 SET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3568 bgp_recalculate_all_bestpaths(bgp);
3569
3570 return CMD_SUCCESS;
3571}
3572
3573DEFUN(no_bgp_bestpath_peer_type_multipath_relax,
3574 no_bgp_bestpath_peer_type_multipath_relax_cmd,
3575 "no bgp bestpath peer-type multipath-relax",
3576 NO_STR BGP_STR
3577 "Change the default bestpath selection\n"
3578 "Peer type\n"
3579 "Allow load sharing across routes learned from different peer types\n")
3580{
3581 VTY_DECLVAR_CONTEXT(bgp, bgp);
3582 UNSET_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX);
3583 bgp_recalculate_all_bestpaths(bgp);
3584
3585 return CMD_SUCCESS;
3586}
3587
848973c7 3588/* "bgp log-neighbor-changes" configuration. */
ff8a8a7a
CS
3589DEFUN_YANG(bgp_log_neighbor_changes,
3590 bgp_log_neighbor_changes_cmd,
3591 "bgp log-neighbor-changes",
3592 "BGP specific commands\n"
3593 "Log neighbor up/down and reset reason\n")
848973c7 3594{
87ce2564
CS
3595 nb_cli_enqueue_change(
3596 vty, "./global/global-neighbor-config/log-neighbor-changes",
3597 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3598
3599 return nb_cli_apply_changes(vty, NULL);
848973c7 3600}
3601
ff8a8a7a
CS
3602DEFUN_YANG(no_bgp_log_neighbor_changes,
3603 no_bgp_log_neighbor_changes_cmd,
3604 "no bgp log-neighbor-changes",
3605 NO_STR
3606 "BGP specific commands\n"
3607 "Log neighbor up/down and reset reason\n")
848973c7 3608{
87ce2564
CS
3609 nb_cli_enqueue_change(
3610 vty, "./global/global-neighbor-config/log-neighbor-changes",
3611 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3612
3613 return nb_cli_apply_changes(vty, NULL);
848973c7 3614}
6b0655a2 3615
718e3744 3616/* "bgp bestpath med" configuration. */
ff8a8a7a 3617DEFUN_YANG (bgp_bestpath_med,
718e3744 3618 bgp_bestpath_med_cmd,
2d8c1a4d 3619 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3620 "BGP specific commands\n"
3621 "Change the default bestpath selection\n"
3622 "MED attribute\n"
3623 "Compare MED among confederation paths\n"
838758ac
DW
3624 "Treat missing MED as the least preferred one\n"
3625 "Treat missing MED as the least preferred one\n"
3626 "Compare MED among confederation paths\n")
718e3744 3627{
d62a17ae 3628 int idx = 0;
ff8a8a7a
CS
3629 bool confed = false;
3630 bool worst_med = false;
3631
3632
d62a17ae 3633 if (argv_find(argv, argc, "confed", &idx))
ff8a8a7a
CS
3634 confed = true;
3635
87ce2564
CS
3636 nb_cli_enqueue_change(vty,
3637 "./global/route-selection-options/confed-med",
ff8a8a7a
CS
3638 NB_OP_MODIFY, confed ? "true" : "false");
3639
d62a17ae 3640 idx = 0;
3641 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3642 worst_med = true;
e52702f2 3643
87ce2564
CS
3644 nb_cli_enqueue_change(
3645 vty, "./global/route-selection-options/missing-as-worst-med",
3646 NB_OP_MODIFY, worst_med ? "true" : "false");
7aafcaca 3647
ff8a8a7a 3648 return nb_cli_apply_changes(vty, NULL);
718e3744 3649}
3650
ff8a8a7a 3651DEFUN_YANG (no_bgp_bestpath_med,
718e3744 3652 no_bgp_bestpath_med_cmd,
2d8c1a4d 3653 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 3654 NO_STR
3655 "BGP specific commands\n"
3656 "Change the default bestpath selection\n"
3657 "MED attribute\n"
3658 "Compare MED among confederation paths\n"
3a2d747c
QY
3659 "Treat missing MED as the least preferred one\n"
3660 "Treat missing MED as the least preferred one\n"
3661 "Compare MED among confederation paths\n")
718e3744 3662{
d62a17ae 3663 int idx = 0;
ff8a8a7a 3664
d62a17ae 3665 if (argv_find(argv, argc, "confed", &idx))
87ce2564
CS
3666 nb_cli_enqueue_change(
3667 vty, "./global/route-selection-options/confed-med",
3668 NB_OP_MODIFY, "false");
ff8a8a7a 3669
d62a17ae 3670 idx = 0;
3671 if (argv_find(argv, argc, "missing-as-worst", &idx))
ff8a8a7a 3672 nb_cli_enqueue_change(
87ce2564
CS
3673 vty,
3674 "./global/route-selection-options/missing-as-worst-med",
ff8a8a7a 3675 NB_OP_MODIFY, "false");
718e3744 3676
ff8a8a7a 3677 return nb_cli_apply_changes(vty, NULL);
718e3744 3678}
3679
f7e1c681 3680/* "bgp bestpath bandwidth" configuration. */
3681DEFPY (bgp_bestpath_bw,
3682 bgp_bestpath_bw_cmd,
ad36d216 3683 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
f7e1c681 3684 "BGP specific commands\n"
3685 "Change the default bestpath selection\n"
3686 "Link Bandwidth attribute\n"
3687 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3688 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3689 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3690{
3691 VTY_DECLVAR_CONTEXT(bgp, bgp);
3692 afi_t afi;
3693 safi_t safi;
3694
ad36d216
DS
3695 if (!bw_cfg) {
3696 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3697 return CMD_ERR_INCOMPLETE;
f7e1c681 3698 }
ad36d216
DS
3699 if (!strcmp(bw_cfg, "ignore"))
3700 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3701 else if (!strcmp(bw_cfg, "skip-missing"))
3702 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3703 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3704 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3705 else
3706 return CMD_ERR_NO_MATCH;
f7e1c681 3707
3708 /* This config is used in route install, so redo that. */
3709 FOREACH_AFI_SAFI (afi, safi) {
3710 if (!bgp_fibupd_safi(safi))
3711 continue;
3712 bgp_zebra_announce_table(bgp, afi, safi);
3713 }
3714
3715 return CMD_SUCCESS;
3716}
3717
ad36d216
DS
3718DEFPY (no_bgp_bestpath_bw,
3719 no_bgp_bestpath_bw_cmd,
3720 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3721 NO_STR
3722 "BGP specific commands\n"
3723 "Change the default bestpath selection\n"
3724 "Link Bandwidth attribute\n"
3725 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3726 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3727 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3728{
3729 VTY_DECLVAR_CONTEXT(bgp, bgp);
3730 afi_t afi;
3731 safi_t safi;
3732
3733 bgp->lb_handling = BGP_LINK_BW_ECMP;
3734
3735 /* This config is used in route install, so redo that. */
3736 FOREACH_AFI_SAFI (afi, safi) {
3737 if (!bgp_fibupd_safi(safi))
3738 continue;
3739 bgp_zebra_announce_table(bgp, afi, safi);
3740 }
3741 return CMD_SUCCESS;
3742}
3743
e84c59af
DA
3744/* "no bgp default ipv6-unicast". */
3745DEFUN(no_bgp_default_ipv6_unicast, no_bgp_default_ipv6_unicast_cmd,
3746 "no bgp default ipv6-unicast", NO_STR
3747 "BGP specific commands\n"
3748 "Configure BGP defaults\n"
3749 "Activate ipv6-unicast for a peer by default\n")
3750{
3751 VTY_DECLVAR_CONTEXT(bgp, bgp);
3752 UNSET_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6);
3753 return CMD_SUCCESS;
3754}
3755
3756DEFUN(bgp_default_ipv6_unicast, bgp_default_ipv6_unicast_cmd,
3757 "bgp default ipv6-unicast",
3758 "BGP specific commands\n"
3759 "Configure BGP defaults\n"
3760 "Activate ipv6-unicast for a peer by default\n")
3761{
3762 VTY_DECLVAR_CONTEXT(bgp, bgp);
3763 SET_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6);
3764 return CMD_SUCCESS;
3765}
3766
718e3744 3767/* "no bgp default ipv4-unicast". */
3768DEFUN (no_bgp_default_ipv4_unicast,
3769 no_bgp_default_ipv4_unicast_cmd,
3770 "no bgp default ipv4-unicast",
3771 NO_STR
3772 "BGP specific commands\n"
3773 "Configure BGP defaults\n"
3774 "Activate ipv4-unicast for a peer by default\n")
3775{
d62a17ae 3776 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3777 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3778 return CMD_SUCCESS;
718e3744 3779}
3780
3781DEFUN (bgp_default_ipv4_unicast,
3782 bgp_default_ipv4_unicast_cmd,
3783 "bgp default ipv4-unicast",
3784 "BGP specific commands\n"
3785 "Configure BGP defaults\n"
3786 "Activate ipv4-unicast for a peer by default\n")
3787{
d62a17ae 3788 VTY_DECLVAR_CONTEXT(bgp, bgp);
892fedb6 3789 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
d62a17ae 3790 return CMD_SUCCESS;
718e3744 3791}
6b0655a2 3792
04b6bdc0 3793/* Display hostname in certain command outputs */
ff8a8a7a 3794DEFUN_YANG (bgp_default_show_hostname,
04b6bdc0
DW
3795 bgp_default_show_hostname_cmd,
3796 "bgp default show-hostname",
3797 "BGP specific commands\n"
3798 "Configure BGP defaults\n"
0437e105 3799 "Show hostname in certain command outputs\n")
04b6bdc0 3800{
87ce2564
CS
3801 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3802 "true");
ff8a8a7a
CS
3803
3804 return nb_cli_apply_changes(vty, NULL);
04b6bdc0
DW
3805}
3806
ff8a8a7a
CS
3807DEFUN_YANG(no_bgp_default_show_hostname,
3808 no_bgp_default_show_hostname_cmd,
3809 "no bgp default show-hostname",
3810 NO_STR
3811 "BGP specific commands\n"
3812 "Configure BGP defaults\n"
3813 "Show hostname in certain command outputs\n")
04b6bdc0 3814{
87ce2564
CS
3815 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3816 "false");
ff8a8a7a
CS
3817
3818 return nb_cli_apply_changes(vty, NULL);
3819}
3820
3821void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3822 bool show_defaults)
3823{
3824 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3825 vty_out(vty, " bgp default show-hostname\n");
04b6bdc0
DW
3826}
3827
aef999a2 3828/* Display hostname in certain command outputs */
232c75cd
CS
3829DEFUN_YANG(bgp_default_show_nexthop_hostname,
3830 bgp_default_show_nexthop_hostname_cmd,
3831 "bgp default show-nexthop-hostname",
3832 "BGP specific commands\n"
3833 "Configure BGP defaults\n"
3834 "Show hostname for nexthop in certain command outputs\n")
aef999a2 3835{
87ce2564
CS
3836 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3837 NB_OP_MODIFY, "true");
ff8a8a7a
CS
3838
3839 return nb_cli_apply_changes(vty, NULL);
aef999a2
DA
3840}
3841
3842DEFUN (no_bgp_default_show_nexthop_hostname,
3843 no_bgp_default_show_nexthop_hostname_cmd,
3844 "no bgp default show-nexthop-hostname",
3845 NO_STR
3846 "BGP specific commands\n"
3847 "Configure BGP defaults\n"
3848 "Show hostname for nexthop in certain command outputs\n")
3849{
87ce2564
CS
3850 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3851 NB_OP_MODIFY, "false");
ff8a8a7a
CS
3852
3853 return nb_cli_apply_changes(vty, NULL);
3854}
3855
3856void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3857 struct lyd_node *dnode,
3858 bool show_defaults)
3859{
3860 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3861 vty_out(vty, " bgp default show-nexthop-hostname\n");
aef999a2
DA
3862}
3863
8233ef81 3864/* "bgp network import-check" configuration. */
ff8a8a7a
CS
3865DEFUN_YANG(bgp_network_import_check,
3866 bgp_network_import_check_cmd,
3867 "bgp network import-check",
3868 "BGP specific commands\n"
3869 "BGP network command\n"
3870 "Check BGP network route exists in IGP\n")
718e3744 3871{
87ce2564
CS
3872 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3873 "true");
078430f6 3874
ff8a8a7a 3875 return nb_cli_apply_changes(vty, NULL);
718e3744 3876}
3877
d62a17ae 3878ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3879 "bgp network import-check exact",
3880 "BGP specific commands\n"
3881 "BGP network command\n"
3882 "Check BGP network route exists in IGP\n"
3883 "Match route precisely\n")
8233ef81 3884
ff8a8a7a
CS
3885DEFUN_YANG(no_bgp_network_import_check,
3886 no_bgp_network_import_check_cmd,
3887 "no bgp network import-check",
3888 NO_STR
3889 "BGP specific commands\n"
3890 "BGP network command\n"
3891 "Check BGP network route exists in IGP\n")
718e3744 3892{
87ce2564
CS
3893 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3894 "false");
5623e905 3895
ff8a8a7a 3896 return nb_cli_apply_changes(vty, NULL);
718e3744 3897}
6b0655a2 3898
ff8a8a7a
CS
3899void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3900 bool show_defaults)
718e3744 3901{
ff8a8a7a
CS
3902 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3903 vty_out(vty, " bgp network import-check\n");
3904}
718e3744 3905
ff8a8a7a
CS
3906DEFUN_YANG(bgp_default_local_preference,
3907 bgp_default_local_preference_cmd,
3908 "bgp default local-preference (0-4294967295)",
3909 "BGP specific commands\n"
3910 "Configure BGP defaults\n"
3911 "local preference (higher=more preferred)\n"
3912 "Configure default local preference value\n")
3913{
3914 int idx_number = 3;
718e3744 3915
87ce2564 3916 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
ff8a8a7a 3917 argv[idx_number]->arg);
718e3744 3918
ff8a8a7a 3919 return nb_cli_apply_changes(vty, NULL);
718e3744 3920}
3921
ff8a8a7a
CS
3922DEFUN_YANG(no_bgp_default_local_preference,
3923 no_bgp_default_local_preference_cmd,
3924 "no bgp default local-preference [(0-4294967295)]",
3925 NO_STR
3926 "BGP specific commands\n"
3927 "Configure BGP defaults\n"
3928 "local preference (higher=more preferred)\n"
3929 "Configure default local preference value\n")
718e3744 3930{
87ce2564 3931 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
7aafcaca 3932
ff8a8a7a 3933 return nb_cli_apply_changes(vty, NULL);
718e3744 3934}
3935
ff8a8a7a
CS
3936void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3937 bool show_defaults)
3938{
3939 vty_out(vty, " bgp default local-preference %u\n",
3940 yang_dnode_get_uint32(dnode, NULL));
3941}
6b0655a2 3942
ff8a8a7a
CS
3943
3944DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3945 bgp_default_subgroup_pkt_queue_max_cmd,
3946 "bgp default subgroup-pkt-queue-max (20-100)",
3947 "BGP specific commands\n"
3948 "Configure BGP defaults\n"
3949 "subgroup-pkt-queue-max\n"
3950 "Configure subgroup packet queue max\n")
8bd9d948 3951{
d62a17ae 3952 int idx_number = 3;
3f9c7369 3953
ff8a8a7a 3954 nb_cli_enqueue_change(
87ce2564
CS
3955 vty,
3956 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a 3957 NB_OP_MODIFY, argv[idx_number]->arg);
3f9c7369 3958
ff8a8a7a 3959 return nb_cli_apply_changes(vty, NULL);
3f9c7369
DS
3960}
3961
ff8a8a7a
CS
3962DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3963 no_bgp_default_subgroup_pkt_queue_max_cmd,
3964 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3965 NO_STR
3966 "BGP specific commands\n"
3967 "Configure BGP defaults\n"
3968 "subgroup-pkt-queue-max\n"
3969 "Configure subgroup packet queue max\n")
3f9c7369 3970{
ff8a8a7a 3971 nb_cli_enqueue_change(
87ce2564
CS
3972 vty,
3973 "./global/global-update-group-config/subgroup-pkt-queue-size",
ff8a8a7a
CS
3974 NB_OP_MODIFY, NULL);
3975
3976 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
3977}
3978
ff8a8a7a
CS
3979void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3980 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3981{
3982 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3983 yang_dnode_get_uint32(dnode, NULL));
3984}
813d4307 3985
ff8a8a7a
CS
3986DEFUN_YANG(bgp_rr_allow_outbound_policy,
3987 bgp_rr_allow_outbound_policy_cmd,
3988 "bgp route-reflector allow-outbound-policy",
3989 "BGP specific commands\n"
3990 "Allow modifications made by out route-map\n"
3991 "on ibgp neighbors\n")
8bd9d948 3992{
87ce2564
CS
3993 nb_cli_enqueue_change(vty,
3994 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a 3995 NB_OP_MODIFY, "true");
8bd9d948 3996
ff8a8a7a
CS
3997 return nb_cli_apply_changes(vty, NULL);
3998}
8bd9d948 3999
ff8a8a7a
CS
4000DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
4001 no_bgp_rr_allow_outbound_policy_cmd,
4002 "no bgp route-reflector allow-outbound-policy",
4003 NO_STR
4004 "BGP specific commands\n"
4005 "Allow modifications made by out route-map\n"
4006 "on ibgp neighbors\n")
4007{
87ce2564
CS
4008 nb_cli_enqueue_change(vty,
4009 "./global/route-reflector/allow-outbound-policy",
ff8a8a7a
CS
4010 NB_OP_MODIFY, "false");
4011
4012 return nb_cli_apply_changes(vty, NULL);
8bd9d948
DS
4013}
4014
ff8a8a7a
CS
4015
4016void cli_show_router_global_neighbor_config(struct vty *vty,
4017 struct lyd_node *dnode,
4018 bool show_defaults)
8bd9d948 4019{
ff8a8a7a
CS
4020 uint32_t write_quanta, read_quanta;
4021
4022 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
4023 vty_out(vty, " bgp log-neighbor-changes\n");
8bd9d948 4024
ff8a8a7a
CS
4025 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
4026 uint32_t listen_limit = yang_dnode_get_uint32(
4027 dnode, "./dynamic-neighbors-limit");
4028 vty_out(vty, " bgp listen limit %u\n", listen_limit);
d62a17ae 4029 }
8bd9d948 4030
ff8a8a7a
CS
4031 write_quanta = yang_dnode_get_uint32(
4032 dnode, "./packet-quanta-config/wpkt-quanta");
4033 if (write_quanta != BGP_WRITE_PACKET_MAX)
4034 vty_out(vty, " write-quanta %d\n", write_quanta);
4035
4036 read_quanta = yang_dnode_get_uint32(
4037 dnode, "./packet-quanta-config/rpkt-quanta");
4038
4039 if (read_quanta != BGP_READ_PACKET_MAX)
4040 vty_out(vty, " read-quanta %d\n", read_quanta);
8bd9d948
DS
4041}
4042
ff8a8a7a
CS
4043DEFUN_YANG(bgp_listen_limit,
4044 bgp_listen_limit_cmd,
5b1b6b8b 4045 "bgp listen limit (1-65535)",
ff8a8a7a
CS
4046 "BGP specific commands\n"
4047 "BGP Dynamic Neighbors listen commands\n"
4048 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4049 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4050{
d62a17ae 4051 int idx_number = 3;
f14e6fdb 4052
ff8a8a7a 4053 nb_cli_enqueue_change(
87ce2564 4054 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a 4055 NB_OP_MODIFY, argv[idx_number]->arg);
f14e6fdb 4056
ff8a8a7a 4057 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4058}
4059
ff8a8a7a
CS
4060DEFUN_YANG(no_bgp_listen_limit,
4061 no_bgp_listen_limit_cmd,
5b1b6b8b 4062 "no bgp listen limit [(1-65535)]",
ff8a8a7a
CS
4063 NO_STR
4064 "BGP specific commands\n"
4065 "BGP Dynamic Neighbors listen commands\n"
4066 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4067 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 4068{
ff8a8a7a 4069 nb_cli_enqueue_change(
87ce2564 4070 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
ff8a8a7a
CS
4071 NB_OP_DESTROY, NULL);
4072
4073 return nb_cli_apply_changes(vty, NULL);
f14e6fdb
DS
4074}
4075
4076
20eb8864 4077/*
4078 * Check if this listen range is already configured. Check for exact
4079 * match or overlap based on input.
4080 */
d62a17ae 4081static struct peer_group *listen_range_exists(struct bgp *bgp,
4082 struct prefix *range, int exact)
4083{
4084 struct listnode *node, *nnode;
4085 struct listnode *node1, *nnode1;
4086 struct peer_group *group;
4087 struct prefix *lr;
4088 afi_t afi;
4089 int match;
4090
4091 afi = family2afi(range->family);
4092 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4093 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4094 lr)) {
4095 if (exact)
4096 match = prefix_same(range, lr);
4097 else
4098 match = (prefix_match(range, lr)
4099 || prefix_match(lr, range));
4100 if (match)
4101 return group;
4102 }
4103 }
4104
4105 return NULL;
20eb8864 4106}
4107
f14e6fdb
DS
4108DEFUN (bgp_listen_range,
4109 bgp_listen_range_cmd,
d7b9898c 4110 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
f14e6fdb 4111 "BGP specific commands\n"
d7fa34c1
QY
4112 "Configure BGP dynamic neighbors listen range\n"
4113 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
4114 NEIGHBOR_ADDR_STR
4115 "Member of the peer-group\n"
4116 "Peer-group name\n")
f14e6fdb 4117{
d62a17ae 4118 VTY_DECLVAR_CONTEXT(bgp, bgp);
4119 struct prefix range;
4120 struct peer_group *group, *existing_group;
4121 afi_t afi;
4122 int ret;
4123 int idx = 0;
4124
4125 argv_find(argv, argc, "A.B.C.D/M", &idx);
4126 argv_find(argv, argc, "X:X::X:X/M", &idx);
4127 char *prefix = argv[idx]->arg;
d7b9898c 4128 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4129 char *peergroup = argv[idx]->arg;
4130
4131 /* Convert IP prefix string to struct prefix. */
4132 ret = str2prefix(prefix, &range);
4133 if (!ret) {
4134 vty_out(vty, "%% Malformed listen range\n");
4135 return CMD_WARNING_CONFIG_FAILED;
4136 }
4137
4138 afi = family2afi(range.family);
4139
4140 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4141 vty_out(vty,
4142 "%% Malformed listen range (link-local address)\n");
4143 return CMD_WARNING_CONFIG_FAILED;
4144 }
4145
4146 apply_mask(&range);
4147
4148 /* Check if same listen range is already configured. */
4149 existing_group = listen_range_exists(bgp, &range, 1);
4150 if (existing_group) {
4151 if (strcmp(existing_group->name, peergroup) == 0)
4152 return CMD_SUCCESS;
4153 else {
4154 vty_out(vty,
4155 "%% Same listen range is attached to peer-group %s\n",
4156 existing_group->name);
4157 return CMD_WARNING_CONFIG_FAILED;
4158 }
4159 }
4160
4161 /* Check if an overlapping listen range exists. */
4162 if (listen_range_exists(bgp, &range, 0)) {
4163 vty_out(vty,
4164 "%% Listen range overlaps with existing listen range\n");
4165 return CMD_WARNING_CONFIG_FAILED;
4166 }
4167
4168 group = peer_group_lookup(bgp, peergroup);
4169 if (!group) {
4170 vty_out(vty, "%% Configure the peer-group first\n");
4171 return CMD_WARNING_CONFIG_FAILED;
4172 }
4173
4174 ret = peer_group_listen_range_add(group, &range);
4175 return bgp_vty_return(vty, ret);
f14e6fdb
DS
4176}
4177
4178DEFUN (no_bgp_listen_range,
4179 no_bgp_listen_range_cmd,
d7b9898c 4180 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
d7fa34c1 4181 NO_STR
f14e6fdb 4182 "BGP specific commands\n"
d7fa34c1
QY
4183 "Unconfigure BGP dynamic neighbors listen range\n"
4184 "Unconfigure BGP dynamic neighbors listen range\n"
4185 NEIGHBOR_ADDR_STR
4186 "Member of the peer-group\n"
4187 "Peer-group name\n")
f14e6fdb 4188{
d62a17ae 4189 VTY_DECLVAR_CONTEXT(bgp, bgp);
4190 struct prefix range;
4191 struct peer_group *group;
4192 afi_t afi;
4193 int ret;
4194 int idx = 0;
4195
4196 argv_find(argv, argc, "A.B.C.D/M", &idx);
4197 argv_find(argv, argc, "X:X::X:X/M", &idx);
4198 char *prefix = argv[idx]->arg;
21d88a71 4199 argv_find(argv, argc, "PGNAME", &idx);
d62a17ae 4200 char *peergroup = argv[idx]->arg;
4201
4202 /* Convert IP prefix string to struct prefix. */
4203 ret = str2prefix(prefix, &range);
4204 if (!ret) {
4205 vty_out(vty, "%% Malformed listen range\n");
4206 return CMD_WARNING_CONFIG_FAILED;
4207 }
4208
4209 afi = family2afi(range.family);
4210
4211 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4212 vty_out(vty,
4213 "%% Malformed listen range (link-local address)\n");
4214 return CMD_WARNING_CONFIG_FAILED;
4215 }
4216
4217 apply_mask(&range);
4218
4219 group = peer_group_lookup(bgp, peergroup);
4220 if (!group) {
4221 vty_out(vty, "%% Peer-group does not exist\n");
4222 return CMD_WARNING_CONFIG_FAILED;
4223 }
4224
4225 ret = peer_group_listen_range_del(group, &range);
4226 return bgp_vty_return(vty, ret);
4227}
4228
2b791107 4229void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 4230{
4231 struct peer_group *group;
4232 struct listnode *node, *nnode, *rnode, *nrnode;
4233 struct prefix *range;
4234 afi_t afi;
d62a17ae 4235
4236 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4237 vty_out(vty, " bgp listen limit %d\n",
4238 bgp->dynamic_neighbors_limit);
4239
4240 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4241 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4242 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4243 nrnode, range)) {
d62a17ae 4244 vty_out(vty,
2dbe669b
DA
4245 " bgp listen range %pFX peer-group %s\n",
4246 range, group->name);
d62a17ae 4247 }
4248 }
4249 }
f14e6fdb
DS
4250}
4251
4252
ff8a8a7a
CS
4253DEFUN_YANG(bgp_disable_connected_route_check,
4254 bgp_disable_connected_route_check_cmd,
4255 "bgp disable-ebgp-connected-route-check",
4256 "BGP specific commands\n"
4257 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4258{
87ce2564
CS
4259 nb_cli_enqueue_change(vty,
4260 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4261 NB_OP_MODIFY, "true");
7aafcaca 4262
ff8a8a7a 4263 return nb_cli_apply_changes(vty, NULL);
907f92c8
DS
4264}
4265
ff8a8a7a
CS
4266DEFUN_YANG(no_bgp_disable_connected_route_check,
4267 no_bgp_disable_connected_route_check_cmd,
4268 "no bgp disable-ebgp-connected-route-check",
4269 NO_STR
4270 "BGP specific commands\n"
4271 "Disable checking if nexthop is connected on ebgp sessions\n")
907f92c8 4272{
87ce2564
CS
4273 nb_cli_enqueue_change(vty,
4274 "./global/ebgp-multihop-connected-route-check",
ff8a8a7a 4275 NB_OP_MODIFY, "false");
d62a17ae 4276
ff8a8a7a 4277 return nb_cli_apply_changes(vty, NULL);
d62a17ae 4278}
4279
ff8a8a7a
CS
4280void cli_show_router_global_ebgp_multihop_connected_route_check(
4281 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4282{
4283 if (yang_dnode_get_bool(dnode, NULL))
4284 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4285}
d62a17ae 4286
ff8a8a7a
CS
4287DEFUN_YANG(bgp_default_shutdown,
4288 bgp_default_shutdown_cmd,
4289 "[no] bgp default shutdown",
4290 NO_STR BGP_STR
4291 "Configure BGP defaults\n"
4292 "Apply administrative shutdown to newly configured peers\n")
f26845f9 4293{
87ce2564 4294 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
ff8a8a7a
CS
4295 strmatch(argv[0]->text, "no") ? "false" : "true");
4296
4297 return nb_cli_apply_changes(vty, NULL);
4298}
4299
4300void cli_show_router_bgp_default_shutdown(struct vty *vty,
4301 struct lyd_node *dnode,
4302 bool show_defaults)
4303{
4304 if (yang_dnode_get_bool(dnode, NULL))
4305 vty_out(vty, " bgp default shutdown\n");
f26845f9
QY
4306}
4307
736b68f3
DS
4308DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4309 BGP_STR
9ddf4b81 4310 "Administrative shutdown of the BGP instance\n"
736b68f3
DS
4311 "Add a shutdown message (RFC 8203)\n"
4312 "Shutdown message\n")
9cf59432 4313{
736b68f3 4314 char *msgstr = NULL;
8389c83a 4315
9cf59432
DS
4316 VTY_DECLVAR_CONTEXT(bgp, bgp);
4317
8389c83a 4318 if (argc > 3)
f80e35b6 4319 msgstr = argv_concat(argv, argc, 3);
8389c83a
DS
4320
4321 bgp_shutdown_enable(bgp, msgstr);
4322 XFREE(MTYPE_TMP, msgstr);
9cf59432
DS
4323
4324 return CMD_SUCCESS;
4325}
4326
736b68f3 4327DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
9ddf4b81 4328 BGP_STR "Administrative shutdown of the BGP instance\n")
1e12ebbc
DS
4329{
4330 VTY_DECLVAR_CONTEXT(bgp, bgp);
4331
4332 bgp_shutdown_enable(bgp, NULL);
4333
4334 return CMD_SUCCESS;
4335}
8389c83a 4336
736b68f3 4337DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
9ddf4b81 4338 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
9cf59432
DS
4339{
4340 VTY_DECLVAR_CONTEXT(bgp, bgp);
4341
4342 bgp_shutdown_disable(bgp);
4343
4344 return CMD_SUCCESS;
4345}
4346
9ddf4b81 4347ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
1b6e7a88 4348 "no bgp shutdown message MSG...", NO_STR BGP_STR
9ddf4b81 4349 "Administrative shutdown of the BGP instance\n"
1b6e7a88 4350 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
1b6e7a88 4351
f4b8ec07
CS
4352DEFUN_YANG(neighbor_remote_as,
4353 neighbor_remote_as_cmd,
4354 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4355 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4356 "Specify a BGP neighbor\n" AS_STR
4357 "Internal BGP peer\n"
4358 "External BGP peer\n")
718e3744 4359{
d62a17ae 4360 int idx_peer = 1;
4361 int idx_remote_as = 3;
f4b8ec07
CS
4362 char base_xpath[XPATH_MAXLEN];
4363 char unnbr_xpath[XPATH_MAXLEN];
4364 char prgrp_xpath[XPATH_MAXLEN];
4365 union sockunion su;
4366 const char *as_type_str = "as-specified";
4367
4368 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4369 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4370 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4371
4372 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4373 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4374
3bb513c3
CH
4375 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4376 VTY_CURR_XPATH, unnbr_xpath + 1)) {
f4b8ec07 4377 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
3bb513c3
CH
4378 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4379 "%s%s", VTY_CURR_XPATH,
4380 prgrp_xpath + 1)) {
f4b8ec07
CS
4381 snprintf(base_xpath, sizeof(base_xpath),
4382 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4383 "");
4384 } else {
4385 vty_out(vty,
4386 "%% Create the peer-group or interface first\n");
4387 return CMD_WARNING_CONFIG_FAILED;
4388 }
4389 } else {
4390 snprintf(base_xpath, sizeof(base_xpath),
4391 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4392 }
4393
4394 if (argv[idx_remote_as]->arg[0] == 'i') {
4395 as_type_str = "internal";
4396 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4397 as_type_str = "external";
4398 } else {
4399 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4400 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4401 }
4402 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4403 NB_OP_MODIFY, as_type_str);
4404
4405 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 4406}
4407
e84c59af
DA
4408int peer_conf_interface_create(struct bgp *bgp, const char *conf_if,
4409 bool v6only, const char *peer_group_name,
4410 int as_type, as_t as, char *errmsg,
4411 size_t errmsg_len)
d62a17ae 4412{
d62a17ae 4413 struct peer *peer;
4414 struct peer_group *group;
4415 int ret = 0;
d62a17ae 4416
4417 group = peer_group_lookup(bgp, conf_if);
4418
4419 if (group) {
f4b8ec07
CS
4420 snprintf(errmsg, errmsg_len,
4421 "Name conflict with peer-group \n");
4422 return -1;
d62a17ae 4423 }
4424
4425 peer = peer_lookup_by_conf_if(bgp, conf_if);
4426 if (peer) {
f4b8ec07 4427 if (as_type != AS_UNSPECIFIED)
e84c59af 4428 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
d62a17ae 4429 } else {
e84c59af
DA
4430 peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
4431 NULL);
d62a17ae 4432
4433 if (!peer) {
f4b8ec07
CS
4434 snprintf(errmsg, errmsg_len,
4435 "BGP failed to create peer\n");
4436 return -1;
d62a17ae 4437 }
4438
4439 if (v6only)
527de3dc 4440 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4441
4442 /* Request zebra to initiate IPv6 RAs on this interface. We do
4443 * this
4444 * any unnumbered peer in order to not worry about run-time
4445 * transitions
4446 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4447 * address
4448 * gets deleted later etc.)
4449 */
4450 if (peer->ifp)
4451 bgp_zebra_initiate_radv(bgp, peer);
4452 }
4453
4454 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4455 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4456 if (v6only)
527de3dc 4457 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4458 else
527de3dc 4459 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
d62a17ae 4460
4461 /* v6only flag changed. Reset bgp seesion */
4462 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4463 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4464 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4465 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4466 } else
4467 bgp_session_reset(peer);
4468 }
4469
9fb964de
PM
4470 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4471 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4472 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
dc2f50f3 4473 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
9fb964de 4474 }
d62a17ae 4475
4476 if (peer_group_name) {
4477 group = peer_group_lookup(bgp, peer_group_name);
4478 if (!group) {
f4b8ec07
CS
4479 snprintf(errmsg, errmsg_len,
4480 "Configure the peer-group first\n");
4481 return -1;
d62a17ae 4482 }
4483
8395c1f8 4484 ret = peer_group_bind(bgp, NULL, peer, group, &as);
d62a17ae 4485 }
4486
f4b8ec07 4487 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
a80beece
DS
4488}
4489
232c75cd
CS
4490DEFUN_YANG(neighbor_interface_config,
4491 neighbor_interface_config_cmd,
f4b8ec07
CS
4492 "neighbor WORD interface [peer-group PGNAME]",
4493 NEIGHBOR_STR
4494 "Interface name or neighbor tag\n"
4495 "Enable BGP on interface\n"
4496 "Member of the peer-group\n"
4497 "Peer-group name\n")
4c48cf63 4498{
d62a17ae 4499 int idx_word = 1;
4500 int idx_peer_group_word = 4;
f4b8ec07
CS
4501 char base_xpath[XPATH_MAXLEN];
4502
4503 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4504 argv[idx_word]->arg, "");
31500417 4505
f4b8ec07 4506 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4507 if (argc > idx_peer_group_word)
f4b8ec07
CS
4508 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4509 argv[idx_peer_group_word]->arg);
4510
4511 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4512}
4513
f4b8ec07
CS
4514DEFUN_YANG(neighbor_interface_config_v6only,
4515 neighbor_interface_config_v6only_cmd,
4516 "neighbor WORD interface v6only [peer-group PGNAME]",
4517 NEIGHBOR_STR
4518 "Interface name or neighbor tag\n"
4519 "Enable BGP on interface\n"
4520 "Enable BGP with v6 link-local only\n"
4521 "Member of the peer-group\n"
4522 "Peer-group name\n")
4c48cf63 4523{
d62a17ae 4524 int idx_word = 1;
4525 int idx_peer_group_word = 5;
f4b8ec07
CS
4526 char base_xpath[XPATH_MAXLEN];
4527
4528 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4529 argv[idx_word]->arg, "");
31500417 4530
f4b8ec07 4531 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 4532 if (argc > idx_peer_group_word)
f4b8ec07
CS
4533 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4534 argv[idx_peer_group_word]->arg);
31500417 4535
f4b8ec07
CS
4536 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4537
4538 return nb_cli_apply_changes(vty, base_xpath);
4c48cf63
DW
4539}
4540
a80beece 4541
f4b8ec07
CS
4542DEFUN_YANG(
4543 neighbor_interface_config_remote_as,
4544 neighbor_interface_config_remote_as_cmd,
4545 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4546 NEIGHBOR_STR
4547 "Interface name or neighbor tag\n"
4548 "Enable BGP on interface\n"
4549 "Specify a BGP neighbor\n" AS_STR
4550 "Internal BGP peer\n"
4551 "External BGP peer\n")
b3a39dc5 4552{
d62a17ae 4553 int idx_word = 1;
4554 int idx_remote_as = 4;
f4b8ec07
CS
4555 char base_xpath[XPATH_MAXLEN];
4556 const char *as_type_str = "as-specified";
4557
4558 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4559 argv[idx_word]->arg, "");
4560
4561 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4562
4563 if (argv[idx_remote_as]->arg[0] == 'i') {
4564 as_type_str = "internal";
4565 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4566 as_type_str = "external";
4567 } else {
4568 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4569 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4570 }
4571 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4572 NB_OP_MODIFY, as_type_str);
4573
4574 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4575}
4576
f4b8ec07
CS
4577DEFUN_YANG(
4578 neighbor_interface_v6only_config_remote_as,
4579 neighbor_interface_v6only_config_remote_as_cmd,
4580 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4581 NEIGHBOR_STR
4582 "Interface name or neighbor tag\n"
4583 "Enable BGP with v6 link-local only\n"
4584 "Enable BGP on interface\n"
4585 "Specify a BGP neighbor\n" AS_STR
4586 "Internal BGP peer\n"
4587 "External BGP peer\n")
b3a39dc5 4588{
d62a17ae 4589 int idx_word = 1;
4590 int idx_remote_as = 5;
f4b8ec07
CS
4591 char base_xpath[XPATH_MAXLEN];
4592 const char *as_type_str = "as-specified";
4593
4594 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4595 argv[idx_word]->arg, "");
4596
4597 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4598
4599 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4600
4601 if (argv[idx_remote_as]->arg[0] == 'i') {
4602 as_type_str = "internal";
4603 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4604 as_type_str = "external";
4605 } else {
4606 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4607 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4608 }
4609 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4610 NB_OP_MODIFY, as_type_str);
4611
4612 return nb_cli_apply_changes(vty, base_xpath);
b3a39dc5
DD
4613}
4614
f4b8ec07
CS
4615DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4616 "neighbor WORD peer-group",
4617 NEIGHBOR_STR
4618 "Interface name or neighbor tag\n"
4619 "Configure peer-group\n")
718e3744 4620{
f4b8ec07 4621 char base_xpath[XPATH_MAXLEN];
d62a17ae 4622 int idx_word = 1;
718e3744 4623
f4b8ec07
CS
4624 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4625 argv[idx_word]->arg, "");
718e3744 4626
f4b8ec07 4627 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 4628
f4b8ec07 4629 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4630}
4631
232c75cd
CS
4632DEFUN_YANG(no_neighbor,
4633 no_neighbor_cmd,
4634 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4635 NO_STR NEIGHBOR_STR
4636 NEIGHBOR_ADDR_STR2
4637 "Specify a BGP neighbor\n" AS_STR
4638 "Internal BGP peer\n"
4639 "External BGP peer\n")
718e3744 4640{
d62a17ae 4641 int idx_peer = 2;
f4b8ec07
CS
4642 char base_xpath[XPATH_MAXLEN];
4643 char num_xpath[XPATH_MAXLEN];
4644 char unnbr_xpath[XPATH_MAXLEN];
4645 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4646 union sockunion su;
d62a17ae 4647
f4b8ec07
CS
4648 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4649 snprintf(num_xpath, sizeof(num_xpath),
4650 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
3bb513c3
CH
4651 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4652 VTY_CURR_XPATH, num_xpath + 1)) {
f4b8ec07 4653 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
d62a17ae 4654 }
f4b8ec07
CS
4655 } else {
4656 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4657 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4658
4659 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4660 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4661
3bb513c3
CH
4662 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4663 VTY_CURR_XPATH, unnbr_xpath + 1)) {
f4b8ec07 4664 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
3bb513c3
CH
4665 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
4666 "%s%s", VTY_CURR_XPATH,
4667 prgrp_xpath + 1)) {
f4b8ec07 4668 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4e2786df 4669 } else {
f4b8ec07
CS
4670 vty_out(vty,
4671 "%% Create the peer-group or interface first\n");
d62a17ae 4672 return CMD_WARNING_CONFIG_FAILED;
4673 }
1ff9a340 4674 }
718e3744 4675
f4b8ec07
CS
4676 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4677
4678 return nb_cli_apply_changes(vty, NULL);
718e3744 4679}
4680
f4b8ec07
CS
4681DEFUN_YANG(no_neighbor_interface_config,
4682 no_neighbor_interface_config_cmd,
4683 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4684 NO_STR NEIGHBOR_STR
4685 "Interface name\n"
4686 "Configure BGP on interface\n"
4687 "Enable BGP with v6 link-local only\n"
4688 "Member of the peer-group\n"
4689 "Peer-group name\n"
4690 "Specify a BGP neighbor\n" AS_STR
4691 "Internal BGP peer\n"
4692 "External BGP peer\n")
a80beece 4693{
d62a17ae 4694 int idx_word = 2;
f4b8ec07 4695 char base_xpath[XPATH_MAXLEN];
d62a17ae 4696
f4b8ec07
CS
4697 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4698 argv[idx_word]->arg, "");
4699
4700 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4701
4702 return nb_cli_apply_changes(vty, base_xpath);
a80beece
DS
4703}
4704
f4b8ec07
CS
4705DEFUN_YANG(no_neighbor_peer_group,
4706 no_neighbor_peer_group_cmd,
4707 "no neighbor WORD peer-group",
4708 NO_STR NEIGHBOR_STR
4709 "Neighbor tag\n"
4710 "Configure peer-group\n")
718e3744 4711{
f4b8ec07 4712 char base_xpath[XPATH_MAXLEN];
d62a17ae 4713 int idx_word = 2;
718e3744 4714
f4b8ec07
CS
4715 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4716 argv[idx_word]->arg, "");
4717
4718 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4719
4720 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4721}
4722
f4b8ec07
CS
4723DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4724 no_neighbor_interface_peer_group_remote_as_cmd,
4725 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4726 NO_STR NEIGHBOR_STR
4727 "Interface name or neighbor tag\n"
4728 "Specify a BGP neighbor\n" AS_STR
4729 "Internal BGP peer\n"
4730 "External BGP peer\n")
718e3744 4731{
f4b8ec07
CS
4732 int idx_peer = 2;
4733 char base_xpath[XPATH_MAXLEN];
4734 char unnbr_xpath[XPATH_MAXLEN];
4735 char prgrp_xpath[XPATH_MAXLEN];
d62a17ae 4736
f4b8ec07
CS
4737 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4738 argv[idx_peer]->arg, "");
d62a17ae 4739
f4b8ec07
CS
4740 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4741 argv[idx_peer]->arg, "");
4742
3bb513c3
CH
4743 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4744 VTY_CURR_XPATH, unnbr_xpath + 1)) {
f4b8ec07 4745 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
3bb513c3
CH
4746 } else if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
4747 VTY_CURR_XPATH, prgrp_xpath + 1)) {
f4b8ec07
CS
4748 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4749 } else {
d62a17ae 4750 vty_out(vty, "%% Create the peer-group or interface first\n");
4751 return CMD_WARNING_CONFIG_FAILED;
4752 }
f4b8ec07
CS
4753
4754 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4755 sizeof(base_xpath));
4756
4757 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4758
4759 return nb_cli_apply_changes(vty, NULL);
718e3744 4760}
6b0655a2 4761
f4b8ec07
CS
4762DEFUN_YANG(neighbor_local_as,
4763 neighbor_local_as_cmd,
4764 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4765 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4766 "Specify a local-as number\n"
4767 "AS number used as local AS\n")
718e3744 4768{
d62a17ae 4769 int idx_peer = 1;
4770 int idx_number = 3;
f4b8ec07 4771 char base_xpath[XPATH_MAXLEN];
718e3744 4772
f4b8ec07
CS
4773 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4774 sizeof(base_xpath), NULL)
4775 < 0)
d62a17ae 4776 return CMD_WARNING_CONFIG_FAILED;
718e3744 4777
f4b8ec07
CS
4778 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4779 argv[idx_number]->arg);
4780
4781 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4782}
4783
f4b8ec07
CS
4784DEFUN_YANG(
4785 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4786 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4787 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4788 "Specify a local-as number\n"
4789 "AS number used as local AS\n"
4790 "Do not prepend local-as to updates from ebgp peers\n")
718e3744 4791{
d62a17ae 4792 int idx_peer = 1;
4793 int idx_number = 3;
f4b8ec07 4794 char base_xpath[XPATH_MAXLEN];
718e3744 4795
f4b8ec07
CS
4796 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4797 sizeof(base_xpath), NULL)
4798 < 0)
d62a17ae 4799 return CMD_WARNING_CONFIG_FAILED;
718e3744 4800
f4b8ec07
CS
4801 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4802 argv[idx_number]->arg);
4803 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4804 "true");
4805
4806 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4807}
4808
f4b8ec07
CS
4809DEFUN_YANG(
4810 neighbor_local_as_no_prepend_replace_as,
4811 neighbor_local_as_no_prepend_replace_as_cmd,
4812 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4813 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4814 "Specify a local-as number\n"
4815 "AS number used as local AS\n"
4816 "Do not prepend local-as to updates from ebgp peers\n"
4817 "Do not prepend local-as to updates from ibgp peers\n")
9d3f9705 4818{
d62a17ae 4819 int idx_peer = 1;
4820 int idx_number = 3;
f4b8ec07 4821 char base_xpath[XPATH_MAXLEN];
9d3f9705 4822
f4b8ec07
CS
4823 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4824 sizeof(base_xpath), NULL)
4825 < 0)
d62a17ae 4826 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 4827
f4b8ec07
CS
4828 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4829 argv[idx_number]->arg);
4830 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4831 "true");
ba51dd26 4832 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
f4b8ec07
CS
4833 "true");
4834
4835 return nb_cli_apply_changes(vty, base_xpath);
9d3f9705
AC
4836}
4837
f4b8ec07
CS
4838DEFUN_YANG(no_neighbor_local_as,
4839 no_neighbor_local_as_cmd,
4840 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4841 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4842 "Specify a local-as number\n"
4843 "AS number used as local AS\n"
4844 "Do not prepend local-as to updates from ebgp peers\n"
4845 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 4846{
d62a17ae 4847 int idx_peer = 2;
f4b8ec07 4848 char base_xpath[XPATH_MAXLEN];
718e3744 4849
f4b8ec07
CS
4850 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4851 sizeof(base_xpath), NULL)
4852 < 0)
d62a17ae 4853 return CMD_WARNING_CONFIG_FAILED;
718e3744 4854
f4b8ec07
CS
4855 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4856 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4857 "false");
ba51dd26 4858 nb_cli_enqueue_change(vty, "./local-as/replace-as", NB_OP_MODIFY,
f4b8ec07
CS
4859 "false");
4860
4861 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4862}
4863
718e3744 4864
3f9c7369
DS
4865DEFUN (neighbor_solo,
4866 neighbor_solo_cmd,
9ccf14f7 4867 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4868 NEIGHBOR_STR
4869 NEIGHBOR_ADDR_STR2
4870 "Solo peer - part of its own update group\n")
4871{
d62a17ae 4872 int idx_peer = 1;
4873 struct peer *peer;
4874 int ret;
3f9c7369 4875
d62a17ae 4876 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4877 if (!peer)
4878 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4879
d62a17ae 4880 ret = update_group_adjust_soloness(peer, 1);
4881 return bgp_vty_return(vty, ret);
3f9c7369
DS
4882}
4883
4884DEFUN (no_neighbor_solo,
4885 no_neighbor_solo_cmd,
9ccf14f7 4886 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
4887 NO_STR
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
4890 "Solo peer - part of its own update group\n")
4891{
d62a17ae 4892 int idx_peer = 2;
4893 struct peer *peer;
4894 int ret;
3f9c7369 4895
d62a17ae 4896 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4897 if (!peer)
4898 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 4899
d62a17ae 4900 ret = update_group_adjust_soloness(peer, 0);
4901 return bgp_vty_return(vty, ret);
3f9c7369
DS
4902}
4903
f4b8ec07
CS
4904DEFUN_YANG(neighbor_password,
4905 neighbor_password_cmd,
4906 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4908 "Set a password\n"
4909 "The password\n")
0df7c91f 4910{
d62a17ae 4911 int idx_peer = 1;
4912 int idx_line = 3;
f4b8ec07 4913 char base_xpath[XPATH_MAXLEN];
0df7c91f 4914
f4b8ec07
CS
4915 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4916 sizeof(base_xpath), NULL)
4917 < 0)
d62a17ae 4918 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4919
f4b8ec07
CS
4920 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4921 argv[idx_line]->arg);
4922
4923 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f
PJ
4924}
4925
f4b8ec07
CS
4926DEFUN_YANG(no_neighbor_password,
4927 no_neighbor_password_cmd,
4928 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4929 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4930 "Set a password\n"
4931 "The password\n")
0df7c91f 4932{
d62a17ae 4933 int idx_peer = 2;
f4b8ec07 4934 char base_xpath[XPATH_MAXLEN];
0df7c91f 4935
f4b8ec07
CS
4936 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4937 sizeof(base_xpath), NULL)
4938 < 0)
d62a17ae 4939 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 4940
f4b8ec07
CS
4941 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4942
4943 return nb_cli_apply_changes(vty, base_xpath);
0df7c91f 4944}
6b0655a2 4945
f4b8ec07
CS
4946DEFUN_YANG(neighbor_activate,
4947 neighbor_activate_cmd,
4948 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4949 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4950 "Enable the Address Family for this Neighbor\n")
718e3744 4951{
d62a17ae 4952 int idx_peer = 1;
f4b8ec07 4953 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
4954 char af_xpath[XPATH_MAXLEN];
4955 afi_t afi = bgp_node_afi(vty);
4956 safi_t safi = bgp_node_safi(vty);
718e3744 4957
f4b8ec07
CS
4958 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4959 yang_afi_safi_value2identity(afi, safi));
555c8ab7
CS
4960 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4961 sizeof(base_xpath), af_xpath)
f4b8ec07 4962 < 0)
d62a17ae 4963 return CMD_WARNING_CONFIG_FAILED;
718e3744 4964
555c8ab7 4965 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
f4b8ec07
CS
4966
4967 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4968}
4969
d62a17ae 4970ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4971 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4972 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4973 "Enable the Address Family for this Neighbor\n")
596c17ba 4974
f4b8ec07
CS
4975DEFUN_YANG(no_neighbor_activate,
4976 no_neighbor_activate_cmd,
4977 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4978 NO_STR NEIGHBOR_STR
4979 NEIGHBOR_ADDR_STR2
4980 "Enable the Address Family for this Neighbor\n")
718e3744 4981{
d62a17ae 4982 int idx_peer = 2;
f4b8ec07
CS
4983 char base_xpath[XPATH_MAXLEN];
4984 char af_xpath[XPATH_MAXLEN];
4985 afi_t afi = bgp_node_afi(vty);
4986 safi_t safi = bgp_node_safi(vty);
718e3744 4987
f4b8ec07
CS
4988 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4989 yang_afi_safi_value2identity(afi, safi));
4990
4991 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4992 sizeof(base_xpath), af_xpath)
4993 < 0)
d62a17ae 4994 return CMD_WARNING_CONFIG_FAILED;
718e3744 4995
f4b8ec07
CS
4996 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4997
4998 return nb_cli_apply_changes(vty, base_xpath);
718e3744 4999}
6b0655a2 5000
d62a17ae 5001ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
5002 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
5003 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5004 "Enable the Address Family for this Neighbor\n")
596c17ba 5005
2a059a54
DS
5006DEFUN (neighbor_set_peer_group,
5007 neighbor_set_peer_group_cmd,
5008 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5009 NEIGHBOR_STR
5010 NEIGHBOR_ADDR_STR2
5011 "Member of the peer-group\n"
5012 "Peer-group name\n")
718e3744 5013{
2a059a54 5014 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 5015 int idx_peer = 1;
5016 int idx_word = 3;
2a059a54
DS
5017 int ret;
5018 as_t as;
5019 union sockunion su;
5020 struct peer *peer;
5021 struct peer_group *group;
d62a17ae 5022
2a059a54
DS
5023 ret = str2sockunion(argv[idx_peer]->arg, &su);
5024 if (ret < 0) {
5025 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
5026 if (!peer) {
5027 vty_out(vty, "%% Malformed address or name: %s\n",
5028 argv[idx_peer]->arg);
5029 return CMD_WARNING_CONFIG_FAILED;
5030 }
5031 } else {
5032 if (peer_address_self_check(bgp, &su)) {
5033 vty_out(vty,
5034 "%% Can not configure the local system as neighbor\n");
5035 return CMD_WARNING_CONFIG_FAILED;
5036 }
5037
5038 /* Disallow for dynamic neighbor. */
5039 peer = peer_lookup(bgp, &su);
5040 if (peer && peer_dynamic_neighbor(peer)) {
5041 vty_out(vty,
5042 "%% Operation not allowed on a dynamic neighbor\n");
5043 return CMD_WARNING_CONFIG_FAILED;
5044 }
5045 }
5046
5047 group = peer_group_lookup(bgp, argv[idx_word]->arg);
5048 if (!group) {
5049 vty_out(vty, "%% Configure the peer-group first\n");
d62a17ae 5050 return CMD_WARNING_CONFIG_FAILED;
2a059a54 5051 }
d62a17ae 5052
2a059a54 5053 ret = peer_group_bind(bgp, &su, peer, group, &as);
d62a17ae 5054
2a059a54
DS
5055 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5056 vty_out(vty,
5057 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5058 as);
5059 return CMD_WARNING_CONFIG_FAILED;
5060 }
5061
5062 return bgp_vty_return(vty, ret);
d62a17ae 5063}
5064
5065ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
d7b9898c 5066 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5067 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5068 "Member of the peer-group\n"
5069 "Peer-group name\n")
596c17ba 5070
f4b8ec07
CS
5071DEFUN_YANG (no_neighbor_set_peer_group,
5072 no_neighbor_set_peer_group_cmd,
71cc0c88 5073 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
f4b8ec07
CS
5074 NO_STR
5075 NEIGHBOR_STR
5076 NEIGHBOR_ADDR_STR2
5077 "Member of the peer-group\n"
5078 "Peer-group name\n")
718e3744 5079{
d62a17ae 5080 int idx_peer = 2;
f4b8ec07 5081 char base_xpath[XPATH_MAXLEN];
d62a17ae 5082
f4b8ec07
CS
5083 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5084 sizeof(base_xpath), NULL)
5085 < 0)
d62a17ae 5086 return CMD_WARNING_CONFIG_FAILED;
b3a3290e 5087
f4b8ec07 5088 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
718e3744 5089
f4b8ec07 5090 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5091}
6b0655a2 5092
d62a17ae 5093ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
71cc0c88 5094 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
d62a17ae 5095 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5096 "Member of the peer-group\n"
5097 "Peer-group name\n")
596c17ba 5098
d62a17ae 5099static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
47cbc09b 5100 uint32_t flag, int set)
718e3744 5101{
d62a17ae 5102 int ret;
5103 struct peer *peer;
718e3744 5104
d62a17ae 5105 peer = peer_and_group_lookup_vty(vty, ip_str);
5106 if (!peer)
5107 return CMD_WARNING_CONFIG_FAILED;
718e3744 5108
7ebe625c
QY
5109 /*
5110 * If 'neighbor <interface>', then this is for directly connected peers,
5111 * we should not accept disable-connected-check.
5112 */
5113 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5114 vty_out(vty,
3efd0893 5115 "%s is directly connected peer, cannot accept disable-connected-check\n",
7ebe625c
QY
5116 ip_str);
5117 return CMD_WARNING_CONFIG_FAILED;
5118 }
5119
d62a17ae 5120 if (!set && flag == PEER_FLAG_SHUTDOWN)
5121 peer_tx_shutdown_message_unset(peer);
ae9b0e11 5122
d62a17ae 5123 if (set)
5124 ret = peer_flag_set(peer, flag);
5125 else
5126 ret = peer_flag_unset(peer, flag);
718e3744 5127
d62a17ae 5128 return bgp_vty_return(vty, ret);
718e3744 5129}
5130
47cbc09b 5131static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
718e3744 5132{
d62a17ae 5133 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 5134}
5135
d62a17ae 5136static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
47cbc09b 5137 uint32_t flag)
718e3744 5138{
d62a17ae 5139 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 5140}
5141
f4b8ec07
CS
5142int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5143 uint32_t flag, bool set, char *errmsg,
5144 size_t errmsg_len)
5145{
5146 int ret;
5147
5148 /*
5149 * If 'neighbor <interface>', then this is for directly connected peers,
5150 * we should not accept disable-connected-check.
5151 */
5152 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5153 snprintf(
5154 errmsg, errmsg_len,
5155 "%s is directly connected peer, cannot accept disable-connected-check\n",
5156 ip_str);
5157 return -1;
5158 }
5159
5160 if (!set && flag == PEER_FLAG_SHUTDOWN)
5161 peer_tx_shutdown_message_unset(peer);
5162
5163 if (set)
5164 ret = peer_flag_set(peer, flag);
5165 else
5166 ret = peer_flag_unset(peer, flag);
5167
5168 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5169}
5170
718e3744 5171/* neighbor passive. */
f4b8ec07
CS
5172DEFUN_YANG(neighbor_passive,
5173 neighbor_passive_cmd,
5174 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5175 NEIGHBOR_STR
5176 NEIGHBOR_ADDR_STR2
5177 "Don't send open messages to this neighbor\n")
718e3744 5178{
d62a17ae 5179 int idx_peer = 1;
f4b8ec07
CS
5180 char base_xpath[XPATH_MAXLEN];
5181
5182 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5183 sizeof(base_xpath), NULL)
5184 < 0)
5185 return CMD_WARNING_CONFIG_FAILED;
5186
5187 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5188
5189 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5190}
5191
f4b8ec07
CS
5192DEFUN_YANG(no_neighbor_passive,
5193 no_neighbor_passive_cmd,
5194 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5195 NO_STR NEIGHBOR_STR
5196 NEIGHBOR_ADDR_STR2
5197 "Don't send open messages to this neighbor\n")
718e3744 5198{
d62a17ae 5199 int idx_peer = 2;
f4b8ec07
CS
5200 char base_xpath[XPATH_MAXLEN];
5201
5202 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5203 sizeof(base_xpath), NULL)
5204 < 0)
5205 return CMD_WARNING_CONFIG_FAILED;
5206
5207 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5208
5209 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5210}
6b0655a2 5211
718e3744 5212/* neighbor shutdown. */
f4b8ec07
CS
5213DEFUN_YANG(neighbor_shutdown_msg,
5214 neighbor_shutdown_msg_cmd,
5215 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5216 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5217 "Administratively shut down this neighbor\n"
5218 "Add a shutdown message (RFC 8203)\n"
5219 "Shutdown message\n")
718e3744 5220{
d62a17ae 5221 int idx_peer = 1;
f4b8ec07
CS
5222 char base_xpath[XPATH_MAXLEN];
5223
5224 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5225 sizeof(base_xpath), NULL)
5226 < 0)
5227 return CMD_WARNING_CONFIG_FAILED;
73d70fa6 5228
d62a17ae 5229 if (argc >= 5) {
d62a17ae 5230 char *message;
73d70fa6 5231
d62a17ae 5232 message = argv_concat(argv, argc, 4);
f4b8ec07
CS
5233 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5234 NB_OP_MODIFY, message);
d62a17ae 5235 }
73d70fa6 5236
f4b8ec07
CS
5237 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5238 "true");
5239
5240 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5241}
5242
232c75cd 5243ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
d62a17ae 5244 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5246 "Administratively shut down this neighbor\n")
73d70fa6 5247
f4b8ec07
CS
5248DEFUN_YANG(no_neighbor_shutdown_msg,
5249 no_neighbor_shutdown_msg_cmd,
5250 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5251 NO_STR NEIGHBOR_STR
5252 NEIGHBOR_ADDR_STR2
5253 "Administratively shut down this neighbor\n"
5254 "Remove a shutdown message (RFC 8203)\n"
5255 "Shutdown message\n")
718e3744 5256{
d62a17ae 5257 int idx_peer = 2;
f4b8ec07 5258 char base_xpath[XPATH_MAXLEN];
73d70fa6 5259
f4b8ec07
CS
5260 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5261 sizeof(base_xpath), NULL)
5262 < 0)
5263 return CMD_WARNING_CONFIG_FAILED;
5264
5265 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5266 "false");
5267
5268 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5269}
6b0655a2 5270
232c75cd 5271ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
d62a17ae 5272 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5273 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5274 "Administratively shut down this neighbor\n")
73d70fa6 5275
8336c896
DA
5276DEFUN(neighbor_shutdown_rtt,
5277 neighbor_shutdown_rtt_cmd,
5278 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5279 NEIGHBOR_STR
5280 NEIGHBOR_ADDR_STR2
5281 "Administratively shut down this neighbor\n"
5282 "Shutdown if round-trip-time is higher than expected\n"
5283 "Round-trip-time in milliseconds\n"
5284 "Specify the number of keepalives before shutdown\n"
5285 "The number of keepalives with higher RTT to shutdown\n")
5286{
5287 int idx_peer = 1;
5288 int idx_rtt = 4;
5289 int idx_count = 0;
5290 struct peer *peer;
5291
5292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5293
5294 if (!peer)
5295 return CMD_WARNING_CONFIG_FAILED;
5296
5297 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5298
5299 if (argv_find(argv, argc, "count", &idx_count))
5300 peer->rtt_keepalive_conf =
5301 strtol(argv[idx_count + 1]->arg, NULL, 10);
5302
5303 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5304 PEER_FLAG_RTT_SHUTDOWN);
5305}
5306
5307DEFUN(no_neighbor_shutdown_rtt,
5308 no_neighbor_shutdown_rtt_cmd,
5309 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5310 NO_STR
5311 NEIGHBOR_STR
5312 NEIGHBOR_ADDR_STR2
5313 "Administratively shut down this neighbor\n"
5314 "Shutdown if round-trip-time is higher than expected\n"
5315 "Round-trip-time in milliseconds\n"
5316 "Specify the number of keepalives before shutdown\n"
5317 "The number of keepalives with higher RTT to shutdown\n")
5318{
5319 int idx_peer = 2;
5320 struct peer *peer;
5321
5322 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5323
5324 if (!peer)
5325 return CMD_WARNING_CONFIG_FAILED;
5326
5327 peer->rtt_expected = 0;
5328 peer->rtt_keepalive_conf = 1;
5329
5330 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5331 PEER_FLAG_RTT_SHUTDOWN);
5332}
5333
718e3744 5334/* neighbor capability dynamic. */
f4b8ec07
CS
5335DEFUN_YANG (neighbor_capability_dynamic,
5336 neighbor_capability_dynamic_cmd,
5337 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5338 NEIGHBOR_STR
5339 NEIGHBOR_ADDR_STR2
5340 "Advertise capability to the peer\n"
5341 "Advertise dynamic capability to this neighbor\n")
718e3744 5342{
d62a17ae 5343 int idx_peer = 1;
f4b8ec07
CS
5344 char base_xpath[XPATH_MAXLEN];
5345
5346 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5347 sizeof(base_xpath), NULL)
5348 < 0)
5349 return CMD_WARNING_CONFIG_FAILED;
5350
5351 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5352 NB_OP_MODIFY, "true");
5353
5354 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5355}
5356
f4b8ec07
CS
5357DEFUN_YANG (no_neighbor_capability_dynamic,
5358 no_neighbor_capability_dynamic_cmd,
5359 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5360 NO_STR
5361 NEIGHBOR_STR
5362 NEIGHBOR_ADDR_STR2
5363 "Advertise capability to the peer\n"
5364 "Advertise dynamic capability to this neighbor\n")
718e3744 5365{
d62a17ae 5366 int idx_peer = 2;
f4b8ec07
CS
5367 char base_xpath[XPATH_MAXLEN];
5368
5369 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5370 sizeof(base_xpath), NULL)
5371 < 0)
5372 return CMD_WARNING_CONFIG_FAILED;
5373
5374 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5375 NB_OP_MODIFY, "false");
5376
5377 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5378}
6b0655a2 5379
718e3744 5380/* neighbor dont-capability-negotiate */
5381DEFUN (neighbor_dont_capability_negotiate,
5382 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5383 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5384 NEIGHBOR_STR
5385 NEIGHBOR_ADDR_STR2
5386 "Do not perform capability negotiation\n")
5387{
d62a17ae 5388 int idx_peer = 1;
5389 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5390 PEER_FLAG_DONT_CAPABILITY);
718e3744 5391}
5392
5393DEFUN (no_neighbor_dont_capability_negotiate,
5394 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 5395 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 5396 NO_STR
5397 NEIGHBOR_STR
5398 NEIGHBOR_ADDR_STR2
5399 "Do not perform capability negotiation\n")
5400{
d62a17ae 5401 int idx_peer = 2;
5402 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5403 PEER_FLAG_DONT_CAPABILITY);
718e3744 5404}
6b0655a2 5405
8a92a8a0 5406/* neighbor capability extended next hop encoding */
f4b8ec07
CS
5407DEFUN_YANG (neighbor_capability_enhe,
5408 neighbor_capability_enhe_cmd,
5409 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5410 NEIGHBOR_STR
5411 NEIGHBOR_ADDR_STR2
5412 "Advertise capability to the peer\n"
5413 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5414{
d62a17ae 5415 int idx_peer = 1;
f4b8ec07
CS
5416 char base_xpath[XPATH_MAXLEN];
5417
5418 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5419 sizeof(base_xpath), NULL)
5420 < 0)
5421 return CMD_WARNING_CONFIG_FAILED;
5422
5423 nb_cli_enqueue_change(
5424 vty, "./capability-options/extended-nexthop-capability",
5425 NB_OP_MODIFY, "true");
5426
5427 return nb_cli_apply_changes(vty, base_xpath);
8a92a8a0
DS
5428}
5429
f4b8ec07
CS
5430DEFUN_YANG (no_neighbor_capability_enhe,
5431 no_neighbor_capability_enhe_cmd,
5432 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5433 NO_STR
5434 NEIGHBOR_STR
5435 NEIGHBOR_ADDR_STR2
5436 "Advertise capability to the peer\n"
5437 "Advertise extended next-hop capability to the peer\n")
8a92a8a0 5438{
d62a17ae 5439 int idx_peer = 2;
f4b8ec07
CS
5440 char base_xpath[XPATH_MAXLEN];
5441
5442 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5443 sizeof(base_xpath), NULL)
5444 < 0)
5445 return CMD_WARNING_CONFIG_FAILED;
5446
5447 nb_cli_enqueue_change(
5448 vty, "./capability-options/extended-nexthop-capability",
5449 NB_OP_MODIFY, "false");
5450
5451 return nb_cli_apply_changes(vty, base_xpath);
5452}
5453
5454int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5455 uint32_t flag, int set, char *errmsg,
5456 size_t errmsg_len)
5457{
5458 int ret;
5459
5460 if (set)
5461 ret = peer_af_flag_set(peer, afi, safi, flag);
5462 else
5463 ret = peer_af_flag_unset(peer, afi, safi, flag);
5464
5465 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
8a92a8a0
DS
5466}
5467
d62a17ae 5468static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5469 afi_t afi, safi_t safi, uint32_t flag,
d62a17ae 5470 int set)
718e3744 5471{
d62a17ae 5472 int ret;
5473 struct peer *peer;
718e3744 5474
d62a17ae 5475 peer = peer_and_group_lookup_vty(vty, peer_str);
5476 if (!peer)
5477 return CMD_WARNING_CONFIG_FAILED;
718e3744 5478
d62a17ae 5479 if (set)
5480 ret = peer_af_flag_set(peer, afi, safi, flag);
5481 else
5482 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 5483
d62a17ae 5484 return bgp_vty_return(vty, ret);
718e3744 5485}
5486
d62a17ae 5487static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5488 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5489{
d62a17ae 5490 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 5491}
5492
d62a17ae 5493static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
d7c0a89a 5494 afi_t afi, safi_t safi, uint32_t flag)
718e3744 5495{
d62a17ae 5496 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 5497}
6b0655a2 5498
718e3744 5499/* neighbor capability orf prefix-list. */
5500DEFUN (neighbor_capability_orf_prefix,
5501 neighbor_capability_orf_prefix_cmd,
9ccf14f7 5502 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5503 NEIGHBOR_STR
5504 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")
5511{
d62a17ae 5512 int idx_send_recv = 5;
db45f64d
DS
5513 char *peer_str = argv[1]->arg;
5514 struct peer *peer;
5515 afi_t afi = bgp_node_afi(vty);
5516 safi_t safi = bgp_node_safi(vty);
d62a17ae 5517
db45f64d
DS
5518 peer = peer_and_group_lookup_vty(vty, peer_str);
5519 if (!peer)
d62a17ae 5520 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5521
db45f64d
DS
5522 if (strmatch(argv[idx_send_recv]->text, "send"))
5523 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5524 PEER_FLAG_ORF_PREFIX_SM);
5525
5526 if (strmatch(argv[idx_send_recv]->text, "receive"))
5527 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5528 PEER_FLAG_ORF_PREFIX_RM);
5529
5530 if (strmatch(argv[idx_send_recv]->text, "both"))
5531 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5532 PEER_FLAG_ORF_PREFIX_SM)
5533 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5534 PEER_FLAG_ORF_PREFIX_RM);
5535
5536 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5537}
5538
5539ALIAS_HIDDEN(
5540 neighbor_capability_orf_prefix,
5541 neighbor_capability_orf_prefix_hidden_cmd,
5542 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5543 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5544 "Advertise capability to the peer\n"
5545 "Advertise ORF capability to the peer\n"
5546 "Advertise prefixlist ORF capability to this neighbor\n"
5547 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5548 "Capability to RECEIVE the ORF from this neighbor\n"
5549 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5550
718e3744 5551DEFUN (no_neighbor_capability_orf_prefix,
5552 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 5553 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 5554 NO_STR
5555 NEIGHBOR_STR
5556 NEIGHBOR_ADDR_STR2
5557 "Advertise capability to the peer\n"
5558 "Advertise ORF capability to the peer\n"
5559 "Advertise prefixlist ORF capability to this neighbor\n"
5560 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5561 "Capability to RECEIVE the ORF from this neighbor\n"
5562 "Capability to SEND the ORF to this neighbor\n")
5563{
d62a17ae 5564 int idx_send_recv = 6;
db45f64d
DS
5565 char *peer_str = argv[2]->arg;
5566 struct peer *peer;
5567 afi_t afi = bgp_node_afi(vty);
5568 safi_t safi = bgp_node_safi(vty);
d62a17ae 5569
db45f64d
DS
5570 peer = peer_and_group_lookup_vty(vty, peer_str);
5571 if (!peer)
d62a17ae 5572 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5573
db45f64d
DS
5574 if (strmatch(argv[idx_send_recv]->text, "send"))
5575 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5576 PEER_FLAG_ORF_PREFIX_SM);
5577
5578 if (strmatch(argv[idx_send_recv]->text, "receive"))
5579 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5580 PEER_FLAG_ORF_PREFIX_RM);
5581
5582 if (strmatch(argv[idx_send_recv]->text, "both"))
5583 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5584 PEER_FLAG_ORF_PREFIX_SM)
5585 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5586 PEER_FLAG_ORF_PREFIX_RM);
5587
5588 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 5589}
5590
5591ALIAS_HIDDEN(
5592 no_neighbor_capability_orf_prefix,
5593 no_neighbor_capability_orf_prefix_hidden_cmd,
5594 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5595 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5596 "Advertise capability to the peer\n"
5597 "Advertise ORF capability to the peer\n"
5598 "Advertise prefixlist ORF capability to this neighbor\n"
5599 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5600 "Capability to RECEIVE the ORF from this neighbor\n"
5601 "Capability to SEND the ORF to this neighbor\n")
596c17ba 5602
718e3744 5603/* neighbor next-hop-self. */
f4b8ec07
CS
5604DEFUN_YANG (neighbor_nexthop_self,
5605 neighbor_nexthop_self_cmd,
5606 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5607 NEIGHBOR_STR
5608 NEIGHBOR_ADDR_STR2
5609 "Disable the next hop calculation for this neighbor\n")
718e3744 5610{
d62a17ae 5611 int idx_peer = 1;
f4b8ec07
CS
5612 char base_xpath[XPATH_MAXLEN];
5613 char af_xpath[XPATH_MAXLEN];
5614 char attr_xpath[XPATH_MAXLEN];
5615 afi_t afi = bgp_node_afi(vty);
5616 safi_t safi = bgp_node_safi(vty);
5617
f4b8ec07
CS
5618 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5619 yang_afi_safi_value2identity(afi, safi));
5620
5621 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5622 sizeof(base_xpath), af_xpath)
5623 < 0)
5624 return CMD_WARNING_CONFIG_FAILED;
5625
5626 snprintf(attr_xpath, sizeof(attr_xpath),
5627 "./%s/nexthop-self/next-hop-self",
5628 bgp_afi_safi_get_container_str(afi, safi));
5629
5630 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5631
5632 return nb_cli_apply_changes(vty, base_xpath);
a538debe 5633}
9e7a53c1 5634
d62a17ae 5635ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5636 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5637 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5638 "Disable the next hop calculation for this neighbor\n")
596c17ba 5639
f4b8ec07
CS
5640/* neighbor next-hop-self. */
5641DEFUN_YANG(neighbor_nexthop_self_force,
5642 neighbor_nexthop_self_force_cmd,
5643 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5644 NEIGHBOR_STR
5645 NEIGHBOR_ADDR_STR2
5646 "Disable the next hop calculation for this neighbor\n"
5647 "Set the next hop to self for reflected routes\n")
5648{
5649 int idx_peer = 1;
5650 char base_xpath[XPATH_MAXLEN];
5651 char af_xpath[XPATH_MAXLEN];
5652 char attr_xpath[XPATH_MAXLEN];
5653 afi_t afi = bgp_node_afi(vty);
5654 safi_t safi = bgp_node_safi(vty);
5655
f4b8ec07
CS
5656 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5657 yang_afi_safi_value2identity(afi, safi));
5658
5659 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5660 sizeof(base_xpath), af_xpath)
5661 < 0)
5662 return CMD_WARNING_CONFIG_FAILED;
5663
5664 snprintf(attr_xpath, sizeof(attr_xpath),
5665 "./%s/nexthop-self/next-hop-self-force",
5666 bgp_afi_safi_get_container_str(afi, safi));
5667
5668 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5669
5670 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5671}
5672
d62a17ae 5673ALIAS_HIDDEN(neighbor_nexthop_self_force,
5674 neighbor_nexthop_self_force_hidden_cmd,
5675 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5676 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")
596c17ba 5679
1bc4e531
DA
5680ALIAS_HIDDEN(neighbor_nexthop_self_force,
5681 neighbor_nexthop_self_all_hidden_cmd,
5682 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5683 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5684 "Disable the next hop calculation for this neighbor\n"
5685 "Set the next hop to self for reflected routes\n")
5686
f4b8ec07
CS
5687DEFUN_YANG (no_neighbor_nexthop_self,
5688 no_neighbor_nexthop_self_cmd,
5689 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5690 NO_STR
5691 NEIGHBOR_STR
5692 NEIGHBOR_ADDR_STR2
5693 "Disable the next hop calculation for this neighbor\n")
718e3744 5694{
d62a17ae 5695 int idx_peer = 2;
f4b8ec07
CS
5696 char base_xpath[XPATH_MAXLEN];
5697 char af_xpath[XPATH_MAXLEN];
5698 char attr_xpath[XPATH_MAXLEN];
5699 afi_t afi = bgp_node_afi(vty);
5700 safi_t safi = bgp_node_safi(vty);
5701
5702 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5703 yang_afi_safi_value2identity(afi, safi));
5704
5705 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5706 sizeof(base_xpath), af_xpath)
5707 < 0)
5708 return CMD_WARNING_CONFIG_FAILED;
5709
5710 snprintf(attr_xpath, sizeof(attr_xpath),
5711 "./%s/nexthop-self/next-hop-self",
5712 bgp_afi_safi_get_container_str(afi, safi));
5713
5714 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5715
5716 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5717}
6b0655a2 5718
d62a17ae 5719ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5720 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5721 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5722 "Disable the next hop calculation for this neighbor\n")
596c17ba 5723
f4b8ec07
CS
5724DEFUN_YANG (no_neighbor_nexthop_self_force,
5725 no_neighbor_nexthop_self_force_cmd,
5726 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5727 NO_STR
5728 NEIGHBOR_STR
5729 NEIGHBOR_ADDR_STR2
5730 "Disable the next hop calculation for this neighbor\n"
5731 "Set the next hop to self for reflected routes\n")
88b8ed8d 5732{
d62a17ae 5733 int idx_peer = 2;
f4b8ec07
CS
5734 char base_xpath[XPATH_MAXLEN];
5735 char af_xpath[XPATH_MAXLEN];
5736 char attr_xpath[XPATH_MAXLEN];
5737 afi_t afi = bgp_node_afi(vty);
5738 safi_t safi = bgp_node_safi(vty);
5739
f4b8ec07
CS
5740 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5741 yang_afi_safi_value2identity(afi, safi));
5742
5743 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5744 sizeof(base_xpath), af_xpath)
5745 < 0)
5746 return CMD_WARNING_CONFIG_FAILED;
5747
5748 snprintf(attr_xpath, sizeof(attr_xpath),
5749 "./%s/nexthop-self/next-hop-self-force",
5750 bgp_afi_safi_get_container_str(afi, safi));
5751
5752 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5753
5754 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 5755}
a538debe 5756
d62a17ae 5757ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5758 no_neighbor_nexthop_self_force_hidden_cmd,
5759 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5760 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5761 "Disable the next hop calculation for this neighbor\n"
5762 "Set the next hop to self for reflected routes\n")
596c17ba 5763
1bc4e531
DA
5764ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5765 no_neighbor_nexthop_self_all_hidden_cmd,
5766 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5767 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5768 "Disable the next hop calculation for this neighbor\n"
5769 "Set the next hop to self for reflected routes\n")
5770
c7122e14 5771/* neighbor as-override */
f4b8ec07
CS
5772DEFUN_YANG (neighbor_as_override,
5773 neighbor_as_override_cmd,
5774 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5775 NEIGHBOR_STR
5776 NEIGHBOR_ADDR_STR2
5777 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5778{
d62a17ae 5779 int idx_peer = 1;
f4b8ec07
CS
5780 char base_xpath[XPATH_MAXLEN];
5781 char af_xpath[XPATH_MAXLEN];
5782 char attr_xpath[XPATH_MAXLEN];
5783 afi_t afi = bgp_node_afi(vty);
5784 safi_t safi = bgp_node_safi(vty);
5785
5786 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5787 yang_afi_safi_value2identity(afi, safi));
5788
5789 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5790 sizeof(base_xpath), af_xpath)
5791 < 0)
5792 return CMD_WARNING_CONFIG_FAILED;
5793
5794 snprintf(attr_xpath, sizeof(attr_xpath),
5795 "./%s/as-path-options/replace-peer-as",
5796 bgp_afi_safi_get_container_str(afi, safi));
5797
5798 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5799
5800 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5801}
5802
d62a17ae 5803ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5804 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5806 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5807
f4b8ec07
CS
5808DEFUN_YANG (no_neighbor_as_override,
5809 no_neighbor_as_override_cmd,
5810 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5811 NO_STR
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Override ASNs in outbound updates if aspath equals remote-as\n")
c7122e14 5815{
d62a17ae 5816 int idx_peer = 2;
f4b8ec07
CS
5817 char base_xpath[XPATH_MAXLEN];
5818 char af_xpath[XPATH_MAXLEN];
5819 char attr_xpath[XPATH_MAXLEN];
5820 afi_t afi = bgp_node_afi(vty);
5821 safi_t safi = bgp_node_safi(vty);
5822
5823 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5824 yang_afi_safi_value2identity(afi, safi));
5825
5826 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5827 sizeof(base_xpath), af_xpath)
5828 < 0)
5829 return CMD_WARNING_CONFIG_FAILED;
5830
5831 snprintf(attr_xpath, sizeof(attr_xpath),
5832 "./%s/as-path-options/replace-peer-as",
5833 bgp_afi_safi_get_container_str(afi, safi));
5834
5835 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5836
5837 return nb_cli_apply_changes(vty, base_xpath);
c7122e14
DS
5838}
5839
d62a17ae 5840ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5841 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5842 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 5844
718e3744 5845/* neighbor remove-private-AS. */
f4b8ec07
CS
5846DEFUN_YANG (neighbor_remove_private_as,
5847 neighbor_remove_private_as_cmd,
5848 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5849 NEIGHBOR_STR
5850 NEIGHBOR_ADDR_STR2
5851 "Remove private ASNs in outbound updates\n")
718e3744 5852{
d62a17ae 5853 int idx_peer = 1;
f4b8ec07
CS
5854 char base_xpath[XPATH_MAXLEN];
5855 char af_xpath[XPATH_MAXLEN];
5856 char attr_xpath[XPATH_MAXLEN];
5857 afi_t afi = bgp_node_afi(vty);
5858 safi_t safi = bgp_node_safi(vty);
5859
5860 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5861 yang_afi_safi_value2identity(afi, safi));
5862
5863 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5864 sizeof(base_xpath), af_xpath)
5865 < 0)
5866 return CMD_WARNING_CONFIG_FAILED;
5867
5868 snprintf(attr_xpath, sizeof(attr_xpath),
5869 "./%s/private-as/remove-private-as",
5870 bgp_afi_safi_get_container_str(afi, safi));
5871
5872 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5873
5874 return nb_cli_apply_changes(vty, base_xpath);
718e3744 5875}
5876
d62a17ae 5877ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5878 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5880 "Remove private ASNs in outbound updates\n")
596c17ba 5881
f4b8ec07
CS
5882DEFUN_YANG (neighbor_remove_private_as_all,
5883 neighbor_remove_private_as_all_cmd,
5884 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5885 NEIGHBOR_STR
5886 NEIGHBOR_ADDR_STR2
5887 "Remove private ASNs in outbound updates\n"
5888 "Apply to all AS numbers\n")
5000f21c 5889{
d62a17ae 5890 int idx_peer = 1;
f4b8ec07
CS
5891 char base_xpath[XPATH_MAXLEN];
5892 char af_xpath[XPATH_MAXLEN];
5893 char attr_xpath[XPATH_MAXLEN];
5894 afi_t afi = bgp_node_afi(vty);
5895 safi_t safi = bgp_node_safi(vty);
5896
f4b8ec07
CS
5897 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5898 yang_afi_safi_value2identity(afi, safi));
5899
5900 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5901 sizeof(base_xpath), af_xpath)
5902 < 0)
5903 return CMD_WARNING_CONFIG_FAILED;
5904
5905 snprintf(attr_xpath, sizeof(attr_xpath),
5906 "./%s/private-as/remove-private-as-all",
5907 bgp_afi_safi_get_container_str(afi, safi));
5908
5909 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5910
5911 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5912}
5913
d62a17ae 5914ALIAS_HIDDEN(neighbor_remove_private_as_all,
5915 neighbor_remove_private_as_all_hidden_cmd,
5916 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5918 "Remove private ASNs in outbound updates\n"
5919 "Apply to all AS numbers")
596c17ba 5920
f4b8ec07
CS
5921DEFUN_YANG (neighbor_remove_private_as_replace_as,
5922 neighbor_remove_private_as_replace_as_cmd,
5923 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5924 NEIGHBOR_STR
5925 NEIGHBOR_ADDR_STR2
5926 "Remove private ASNs in outbound updates\n"
5927 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5928{
d62a17ae 5929 int idx_peer = 1;
f4b8ec07
CS
5930 char base_xpath[XPATH_MAXLEN];
5931 char af_xpath[XPATH_MAXLEN];
5932 char attr_xpath[XPATH_MAXLEN];
5933 afi_t afi = bgp_node_afi(vty);
5934 safi_t safi = bgp_node_safi(vty);
5935
f4b8ec07
CS
5936 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5937 yang_afi_safi_value2identity(afi, safi));
5938
5939 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5940 sizeof(base_xpath), af_xpath)
5941 < 0)
5942 return CMD_WARNING_CONFIG_FAILED;
5943
5944 snprintf(attr_xpath, sizeof(attr_xpath),
5945 "./%s/private-as/remove-private-as-replace",
5946 bgp_afi_safi_get_container_str(afi, safi));
5947
5948 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5949
5950 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5951}
5952
d62a17ae 5953ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5954 neighbor_remove_private_as_replace_as_hidden_cmd,
5955 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5957 "Remove private ASNs in outbound updates\n"
5958 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 5959
f4b8ec07
CS
5960DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5961 neighbor_remove_private_as_all_replace_as_cmd,
5962 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5963 NEIGHBOR_STR
5964 NEIGHBOR_ADDR_STR2
5965 "Remove private ASNs in outbound updates\n"
5966 "Apply to all AS numbers\n"
5967 "Replace private ASNs with our ASN in outbound updates\n")
5000f21c 5968{
d62a17ae 5969 int idx_peer = 1;
f4b8ec07
CS
5970 char base_xpath[XPATH_MAXLEN];
5971 char af_xpath[XPATH_MAXLEN];
5972 char attr_xpath[XPATH_MAXLEN];
5973 afi_t afi = bgp_node_afi(vty);
5974 safi_t safi = bgp_node_safi(vty);
5975
f4b8ec07
CS
5976 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5977 yang_afi_safi_value2identity(afi, safi));
5978
5979 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5980 sizeof(base_xpath), af_xpath)
5981 < 0)
5982 return CMD_WARNING_CONFIG_FAILED;
5983
5984 snprintf(attr_xpath, sizeof(attr_xpath),
5985 "./%s/private-as/remove-private-as-all-replace",
5986 bgp_afi_safi_get_container_str(afi, safi));
5987
5988 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5989
5990 return nb_cli_apply_changes(vty, base_xpath);
5000f21c
DS
5991}
5992
d62a17ae 5993ALIAS_HIDDEN(
5994 neighbor_remove_private_as_all_replace_as,
5995 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5996 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5998 "Remove private ASNs in outbound updates\n"
5999 "Apply to all AS numbers\n"
6000 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6001
f4b8ec07
CS
6002DEFUN_YANG (no_neighbor_remove_private_as,
6003 no_neighbor_remove_private_as_cmd,
6004 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6005 NO_STR
6006 NEIGHBOR_STR
6007 NEIGHBOR_ADDR_STR2
6008 "Remove private ASNs in outbound updates\n")
718e3744 6009{
d62a17ae 6010 int idx_peer = 2;
f4b8ec07
CS
6011 char base_xpath[XPATH_MAXLEN];
6012 char af_xpath[XPATH_MAXLEN];
6013 char attr_xpath[XPATH_MAXLEN];
6014 afi_t afi = bgp_node_afi(vty);
6015 safi_t safi = bgp_node_safi(vty);
6016
6017 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6018 yang_afi_safi_value2identity(afi, safi));
6019
6020 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6021 sizeof(base_xpath), af_xpath)
6022 < 0)
6023 return CMD_WARNING_CONFIG_FAILED;
6024
6025 snprintf(attr_xpath, sizeof(attr_xpath),
6026 "./%s/private-as/remove-private-as",
6027 bgp_afi_safi_get_container_str(afi, safi));
6028
6029 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6030
6031 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6032}
6b0655a2 6033
d62a17ae 6034ALIAS_HIDDEN(no_neighbor_remove_private_as,
6035 no_neighbor_remove_private_as_hidden_cmd,
6036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
6037 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6038 "Remove private ASNs in outbound updates\n")
596c17ba 6039
f4b8ec07
CS
6040DEFUN_YANG (no_neighbor_remove_private_as_all,
6041 no_neighbor_remove_private_as_all_cmd,
6042 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6043 NO_STR
6044 NEIGHBOR_STR
6045 NEIGHBOR_ADDR_STR2
6046 "Remove private ASNs in outbound updates\n"
6047 "Apply to all AS numbers\n")
88b8ed8d 6048{
d62a17ae 6049 int idx_peer = 2;
f4b8ec07
CS
6050 char base_xpath[XPATH_MAXLEN];
6051 char af_xpath[XPATH_MAXLEN];
6052 char attr_xpath[XPATH_MAXLEN];
6053 afi_t afi = bgp_node_afi(vty);
6054 safi_t safi = bgp_node_safi(vty);
6055
f4b8ec07
CS
6056 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6057 yang_afi_safi_value2identity(afi, safi));
6058
6059 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6060 sizeof(base_xpath), af_xpath)
6061 < 0)
6062 return CMD_WARNING_CONFIG_FAILED;
6063
6064 snprintf(attr_xpath, sizeof(attr_xpath),
6065 "./%s/private-as/remove-private-as-all",
6066 bgp_afi_safi_get_container_str(afi, safi));
6067
6068 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6069
6070 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6071}
5000f21c 6072
d62a17ae 6073ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6074 no_neighbor_remove_private_as_all_hidden_cmd,
6075 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6076 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6077 "Remove private ASNs in outbound updates\n"
6078 "Apply to all AS numbers\n")
596c17ba 6079
f4b8ec07
CS
6080DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6081 no_neighbor_remove_private_as_replace_as_cmd,
6082 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6083 NO_STR
6084 NEIGHBOR_STR
6085 NEIGHBOR_ADDR_STR2
6086 "Remove private ASNs in outbound updates\n"
6087 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6088{
d62a17ae 6089 int idx_peer = 2;
f4b8ec07
CS
6090 char base_xpath[XPATH_MAXLEN];
6091 char af_xpath[XPATH_MAXLEN];
6092 char attr_xpath[XPATH_MAXLEN];
6093 afi_t afi = bgp_node_afi(vty);
6094 safi_t safi = bgp_node_safi(vty);
6095
f4b8ec07
CS
6096 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6097 yang_afi_safi_value2identity(afi, safi));
6098
6099 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6100 sizeof(base_xpath), af_xpath)
6101 < 0)
6102 return CMD_WARNING_CONFIG_FAILED;
6103
6104 snprintf(attr_xpath, sizeof(attr_xpath),
6105 "./%s/private-as/remove-private-as-replace",
6106 bgp_afi_safi_get_container_str(afi, safi));
6107
6108 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6109
6110 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6111}
5000f21c 6112
d62a17ae 6113ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6114 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6115 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6116 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6117 "Remove private ASNs in outbound updates\n"
6118 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6119
f4b8ec07
CS
6120DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6121 no_neighbor_remove_private_as_all_replace_as_cmd,
6122 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6123 NO_STR
6124 NEIGHBOR_STR
6125 NEIGHBOR_ADDR_STR2
6126 "Remove private ASNs in outbound updates\n"
6127 "Apply to all AS numbers\n"
6128 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 6129{
d62a17ae 6130 int idx_peer = 2;
f4b8ec07
CS
6131 char base_xpath[XPATH_MAXLEN];
6132 char af_xpath[XPATH_MAXLEN];
6133 char attr_xpath[XPATH_MAXLEN];
6134 afi_t afi = bgp_node_afi(vty);
6135 safi_t safi = bgp_node_safi(vty);
6136
f4b8ec07
CS
6137 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6138 yang_afi_safi_value2identity(afi, safi));
6139
6140 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6141 sizeof(base_xpath), af_xpath)
6142 < 0)
6143 return CMD_WARNING_CONFIG_FAILED;
6144
6145 snprintf(attr_xpath, sizeof(attr_xpath),
6146 "./%s/private-as/remove-private-as-all-replace",
6147 bgp_afi_safi_get_container_str(afi, safi));
6148
6149 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6150
6151 return nb_cli_apply_changes(vty, base_xpath);
88b8ed8d 6152}
5000f21c 6153
d62a17ae 6154ALIAS_HIDDEN(
6155 no_neighbor_remove_private_as_all_replace_as,
6156 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6157 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6158 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6159 "Remove private ASNs in outbound updates\n"
6160 "Apply to all AS numbers\n"
6161 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 6162
5000f21c 6163
718e3744 6164/* neighbor send-community. */
f4b8ec07
CS
6165DEFUN_YANG (neighbor_send_community,
6166 neighbor_send_community_cmd,
6167 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6168 NEIGHBOR_STR
6169 NEIGHBOR_ADDR_STR2
6170 "Send Community attribute to this neighbor\n")
718e3744 6171{
d62a17ae 6172 int idx_peer = 1;
e48a9a90
CS
6173 char *peer_str = argv[idx_peer]->arg;
6174 char base_xpath[XPATH_MAXLEN];
6175 char af_xpath[XPATH_MAXLEN];
6176 char std_xpath[XPATH_MAXLEN];
6177 afi_t afi = bgp_node_afi(vty);
6178 safi_t safi = bgp_node_safi(vty);
27c05d4d 6179
e48a9a90
CS
6180 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6181 yang_afi_safi_value2identity(afi, safi));
6182
6183 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6184 sizeof(base_xpath), af_xpath)
6185 < 0)
6186 return CMD_WARNING_CONFIG_FAILED;
6187
6188 snprintf(std_xpath, sizeof(std_xpath),
6189 "./%s/send-community/send-community",
6190 bgp_afi_safi_get_container_str(afi, safi));
6191
6192 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6193
6194 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6195}
6196
d62a17ae 6197ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6198 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6199 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6200 "Send Community attribute to this neighbor\n")
596c17ba 6201
f4b8ec07
CS
6202DEFUN_YANG (no_neighbor_send_community,
6203 no_neighbor_send_community_cmd,
6204 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6205 NO_STR
6206 NEIGHBOR_STR
6207 NEIGHBOR_ADDR_STR2
6208 "Send Community attribute to this neighbor\n")
718e3744 6209{
d62a17ae 6210 int idx_peer = 2;
e48a9a90
CS
6211 char *peer_str = argv[idx_peer]->arg;
6212 char base_xpath[XPATH_MAXLEN];
6213 char af_xpath[XPATH_MAXLEN];
6214 char std_xpath[XPATH_MAXLEN];
6215 afi_t afi = bgp_node_afi(vty);
6216 safi_t safi = bgp_node_safi(vty);
27c05d4d 6217
e48a9a90
CS
6218 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6219 yang_afi_safi_value2identity(afi, safi));
6220
6221 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6222 sizeof(base_xpath), af_xpath)
6223 < 0)
6224 return CMD_WARNING_CONFIG_FAILED;
6225
6226 snprintf(std_xpath, sizeof(std_xpath),
6227 "./%s/send-community/send-community",
6228 bgp_afi_safi_get_container_str(afi, safi));
6229
6230 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6231
6232 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6233}
6b0655a2 6234
d62a17ae 6235ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6236 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6237 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6238 "Send Community attribute to this neighbor\n")
596c17ba 6239
718e3744 6240/* neighbor send-community extended. */
f4b8ec07
CS
6241DEFUN_YANG (neighbor_send_community_type,
6242 neighbor_send_community_type_cmd,
6243 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6244 NEIGHBOR_STR
6245 NEIGHBOR_ADDR_STR2
6246 "Send Community attribute to this neighbor\n"
6247 "Send Standard and Extended Community attributes\n"
6248 "Send Standard, Large and Extended Community attributes\n"
6249 "Send Extended Community attributes\n"
6250 "Send Standard Community attributes\n"
6251 "Send Large Community attributes\n")
718e3744 6252{
27c05d4d 6253 const char *type = argv[argc - 1]->text;
db45f64d 6254 char *peer_str = argv[1]->arg;
f4b8ec07
CS
6255 char base_xpath[XPATH_MAXLEN];
6256 char af_xpath[XPATH_MAXLEN];
6257 char std_xpath[XPATH_MAXLEN];
6258 char ext_xpath[XPATH_MAXLEN];
6259 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6260 afi_t afi = bgp_node_afi(vty);
6261 safi_t safi = bgp_node_safi(vty);
d62a17ae 6262
f4b8ec07
CS
6263 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6264 yang_afi_safi_value2identity(afi, safi));
6265
6266 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6267 sizeof(base_xpath), af_xpath)
6268 < 0)
db45f64d 6269 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6270
f4b8ec07
CS
6271 if (strmatch(type, "standard")) {
6272 snprintf(std_xpath, sizeof(std_xpath),
6273 "./%s/send-community/send-community",
6274 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6275
f4b8ec07
CS
6276 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6277 }
db45f64d 6278
f4b8ec07
CS
6279 if (strmatch(type, "extended")) {
6280 snprintf(ext_xpath, sizeof(ext_xpath),
6281 "./%s/send-community/send-ext-community",
6282 bgp_afi_safi_get_container_str(afi, safi));
6283
6284 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6285 }
6286
6287 if (strmatch(type, "large")) {
6288 snprintf(lrg_xpath, sizeof(lrg_xpath),
6289 "./%s/send-community/send-large-community",
6290 bgp_afi_safi_get_container_str(afi, safi));
6291
6292 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6293 }
db45f64d
DS
6294
6295 if (strmatch(type, "both")) {
f4b8ec07
CS
6296 snprintf(std_xpath, sizeof(std_xpath),
6297 "./%s/send-community/send-community",
6298 bgp_afi_safi_get_container_str(afi, safi));
6299
6300 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6301
6302 snprintf(ext_xpath, sizeof(ext_xpath),
6303 "./%s/send-community/send-ext-community",
6304 bgp_afi_safi_get_container_str(afi, safi));
6305
6306 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
db45f64d 6307 }
f4b8ec07
CS
6308
6309 if (strmatch(type, "all")) {
6310 snprintf(std_xpath, sizeof(std_xpath),
6311 "./%s/send-community/send-community",
6312 bgp_afi_safi_get_container_str(afi, safi));
6313
6314 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6315
6316 snprintf(ext_xpath, sizeof(ext_xpath),
6317 "./%s/send-community/send-ext-community",
6318 bgp_afi_safi_get_container_str(afi, safi));
6319
6320 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6321
6322 snprintf(lrg_xpath, sizeof(lrg_xpath),
6323 "./%s/send-community/send-large-community",
6324 bgp_afi_safi_get_container_str(afi, safi));
6325
6326 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6327 }
6328
6329 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6330}
6331
6332ALIAS_HIDDEN(
6333 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6334 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6335 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6336 "Send Community attribute to this neighbor\n"
6337 "Send Standard and Extended Community attributes\n"
6338 "Send Standard, Large and Extended Community attributes\n"
6339 "Send Extended Community attributes\n"
6340 "Send Standard Community attributes\n"
6341 "Send Large Community attributes\n")
596c17ba 6342
f4b8ec07
CS
6343DEFUN_YANG (no_neighbor_send_community_type,
6344 no_neighbor_send_community_type_cmd,
6345 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6346 NO_STR
6347 NEIGHBOR_STR
6348 NEIGHBOR_ADDR_STR2
6349 "Send Community attribute to this neighbor\n"
6350 "Send Standard and Extended Community attributes\n"
6351 "Send Standard, Large and Extended Community attributes\n"
6352 "Send Extended Community attributes\n"
6353 "Send Standard Community attributes\n"
6354 "Send Large Community attributes\n")
718e3744 6355{
d62a17ae 6356 const char *type = argv[argc - 1]->text;
db45f64d 6357 char *peer_str = argv[2]->arg;
f4b8ec07
CS
6358 char base_xpath[XPATH_MAXLEN];
6359 char af_xpath[XPATH_MAXLEN];
6360 char std_xpath[XPATH_MAXLEN];
6361 char ext_xpath[XPATH_MAXLEN];
6362 char lrg_xpath[XPATH_MAXLEN];
db45f64d
DS
6363 afi_t afi = bgp_node_afi(vty);
6364 safi_t safi = bgp_node_safi(vty);
6365
f4b8ec07
CS
6366 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6367 yang_afi_safi_value2identity(afi, safi));
6368
6369 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6370 sizeof(base_xpath), af_xpath)
6371 < 0)
6372 return CMD_WARNING_CONFIG_FAILED;
6373
6374 if (strmatch(type, "standard")) {
6375 snprintf(std_xpath, sizeof(std_xpath),
6376 "./%s/send-community/send-community",
6377 bgp_afi_safi_get_container_str(afi, safi));
6378
6379 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6380 }
6381
6382 if (strmatch(type, "extended")) {
6383 snprintf(ext_xpath, sizeof(ext_xpath),
6384 "./%s/send-community/send-ext-community",
6385 bgp_afi_safi_get_container_str(afi, safi));
6386
6387 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6388 }
6389
6390 if (strmatch(type, "large")) {
6391 snprintf(lrg_xpath, sizeof(lrg_xpath),
6392 "./%s/send-community/send-large-community",
6393 bgp_afi_safi_get_container_str(afi, safi));
6394
6395 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6396 }
6397
6398 if (strmatch(type, "both")) {
6399 snprintf(std_xpath, sizeof(std_xpath),
6400 "./%s/send-community/send-community",
6401 bgp_afi_safi_get_container_str(afi, safi));
6402
6403 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6404
6405 snprintf(ext_xpath, sizeof(ext_xpath),
6406 "./%s/send-community/send-ext-community",
6407 bgp_afi_safi_get_container_str(afi, safi));
6408
6409 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6410 }
6411
6412 if (strmatch(type, "all")) {
6413 snprintf(std_xpath, sizeof(std_xpath),
6414 "./%s/send-community/send-community",
6415 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6416
f4b8ec07 6417 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
db45f64d 6418
f4b8ec07
CS
6419 snprintf(ext_xpath, sizeof(ext_xpath),
6420 "./%s/send-community/send-ext-community",
6421 bgp_afi_safi_get_container_str(afi, safi));
db45f64d 6422
f4b8ec07 6423 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
db45f64d 6424
f4b8ec07
CS
6425 snprintf(lrg_xpath, sizeof(lrg_xpath),
6426 "./%s/send-community/send-large-community",
6427 bgp_afi_safi_get_container_str(afi, safi));
d62a17ae 6428
f4b8ec07 6429 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
27c05d4d
PM
6430 }
6431
f4b8ec07 6432 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6433}
6434
6435ALIAS_HIDDEN(
6436 no_neighbor_send_community_type,
6437 no_neighbor_send_community_type_hidden_cmd,
6438 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6439 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6440 "Send Community attribute to this neighbor\n"
6441 "Send Standard and Extended Community attributes\n"
6442 "Send Standard, Large and Extended Community attributes\n"
6443 "Send Extended Community attributes\n"
6444 "Send Standard Community attributes\n"
6445 "Send Large Community attributes\n")
596c17ba 6446
718e3744 6447/* neighbor soft-reconfig. */
f4b8ec07
CS
6448DEFUN_YANG (neighbor_soft_reconfiguration,
6449 neighbor_soft_reconfiguration_cmd,
6450 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6451 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6452 "Per neighbor soft reconfiguration\n"
6453 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6454{
d62a17ae 6455 int idx_peer = 1;
f4b8ec07
CS
6456 char base_xpath[XPATH_MAXLEN];
6457 char af_xpath[XPATH_MAXLEN];
6458 char soft_xpath[XPATH_MAXLEN];
6459 afi_t afi = bgp_node_afi(vty);
6460 safi_t safi = bgp_node_safi(vty);
6461
f4b8ec07
CS
6462 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6463 yang_afi_safi_value2identity(afi, safi));
6464
6465 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6466 sizeof(base_xpath), af_xpath)
6467 < 0)
6468 return CMD_WARNING_CONFIG_FAILED;
6469
6470 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6471 bgp_afi_safi_get_container_str(afi, safi));
6472
6473 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6474
6475 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6476}
6477
d62a17ae 6478ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6479 neighbor_soft_reconfiguration_hidden_cmd,
6480 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6481 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6482 "Per neighbor soft reconfiguration\n"
6483 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6484
f4b8ec07
CS
6485DEFUN_YANG (no_neighbor_soft_reconfiguration,
6486 no_neighbor_soft_reconfiguration_cmd,
6487 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6488 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6489 "Per neighbor soft reconfiguration\n"
6490 "Allow inbound soft reconfiguration for this neighbor\n")
718e3744 6491{
d62a17ae 6492 int idx_peer = 2;
f4b8ec07
CS
6493 char base_xpath[XPATH_MAXLEN];
6494 char af_xpath[XPATH_MAXLEN];
6495 char soft_xpath[XPATH_MAXLEN];
6496 afi_t afi = bgp_node_afi(vty);
6497 safi_t safi = bgp_node_safi(vty);
6498
6499 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6500 yang_afi_safi_value2identity(afi, safi));
6501
6502 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6503 bgp_afi_safi_get_container_str(afi, safi));
6504
6505 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6506 sizeof(base_xpath), af_xpath)
6507 < 0)
6508 return CMD_WARNING_CONFIG_FAILED;
6509
6510 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6511
6512 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6513}
6b0655a2 6514
d62a17ae 6515ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6516 no_neighbor_soft_reconfiguration_hidden_cmd,
6517 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6518 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6519 "Per neighbor soft reconfiguration\n"
6520 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 6521
f4b8ec07
CS
6522DEFUN_YANG (neighbor_route_reflector_client,
6523 neighbor_route_reflector_client_cmd,
6524 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6525 NEIGHBOR_STR
6526 NEIGHBOR_ADDR_STR2
6527 "Configure a neighbor as Route Reflector client\n")
718e3744 6528{
d62a17ae 6529 int idx_peer = 1;
f4b8ec07
CS
6530 char base_xpath[XPATH_MAXLEN];
6531 char af_xpath[XPATH_MAXLEN];
6532 char attr_xpath[XPATH_MAXLEN];
6533 afi_t afi = bgp_node_afi(vty);
6534 safi_t safi = bgp_node_safi(vty);
718e3744 6535
f4b8ec07
CS
6536 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6537 yang_afi_safi_value2identity(afi, safi));
718e3744 6538
f4b8ec07
CS
6539 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6540 sizeof(base_xpath), af_xpath)
6541 < 0)
d62a17ae 6542 return CMD_WARNING_CONFIG_FAILED;
718e3744 6543
f4b8ec07
CS
6544 snprintf(attr_xpath, sizeof(attr_xpath),
6545 "./%s/route-reflector/route-reflector-client",
6546 bgp_afi_safi_get_container_str(afi, safi));
6547
6548 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6549
6550 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6551}
6552
d62a17ae 6553ALIAS_HIDDEN(neighbor_route_reflector_client,
6554 neighbor_route_reflector_client_hidden_cmd,
6555 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6556 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6557 "Configure a neighbor as Route Reflector client\n")
596c17ba 6558
f4b8ec07
CS
6559DEFUN_YANG (no_neighbor_route_reflector_client,
6560 no_neighbor_route_reflector_client_cmd,
6561 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6562 NO_STR
6563 NEIGHBOR_STR
6564 NEIGHBOR_ADDR_STR2
6565 "Configure a neighbor as Route Reflector client\n")
718e3744 6566{
d62a17ae 6567 int idx_peer = 2;
f4b8ec07
CS
6568 char base_xpath[XPATH_MAXLEN];
6569 char af_xpath[XPATH_MAXLEN];
6570 char attr_xpath[XPATH_MAXLEN];
6571 afi_t afi = bgp_node_afi(vty);
6572 safi_t safi = bgp_node_safi(vty);
6573
6574 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6575 yang_afi_safi_value2identity(afi, safi));
6576
6577 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6578 sizeof(base_xpath), af_xpath)
6579 < 0)
6580 return CMD_WARNING_CONFIG_FAILED;
6581
6582 snprintf(attr_xpath, sizeof(attr_xpath),
6583 "./%s/route-reflector/route-reflector-client",
6584 bgp_afi_safi_get_container_str(afi, safi));
6585
6586 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6587
6588 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6589}
6b0655a2 6590
d62a17ae 6591ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6592 no_neighbor_route_reflector_client_hidden_cmd,
6593 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6594 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6595 "Configure a neighbor as Route Reflector client\n")
596c17ba 6596
718e3744 6597/* neighbor route-server-client. */
f4b8ec07
CS
6598DEFUN_YANG (neighbor_route_server_client,
6599 neighbor_route_server_client_cmd,
6600 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6601 NEIGHBOR_STR
6602 NEIGHBOR_ADDR_STR2
6603 "Configure a neighbor as Route Server client\n")
718e3744 6604{
d62a17ae 6605 int idx_peer = 1;
f4b8ec07
CS
6606 char base_xpath[XPATH_MAXLEN];
6607 char af_xpath[XPATH_MAXLEN];
6608 char attr_xpath[XPATH_MAXLEN];
6609 afi_t afi = bgp_node_afi(vty);
6610 safi_t safi = bgp_node_safi(vty);
2a3d5731 6611
f4b8ec07
CS
6612 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6613 yang_afi_safi_value2identity(afi, safi));
6614
6615 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6616 sizeof(base_xpath), af_xpath)
6617 < 0)
d62a17ae 6618 return CMD_WARNING_CONFIG_FAILED;
f4b8ec07
CS
6619
6620 snprintf(attr_xpath, sizeof(attr_xpath),
6621 "./%s/route-server/route-server-client",
6622 bgp_afi_safi_get_container_str(afi, safi));
6623
6624 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6625
6626 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6627}
6628
d62a17ae 6629ALIAS_HIDDEN(neighbor_route_server_client,
6630 neighbor_route_server_client_hidden_cmd,
6631 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6632 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6633 "Configure a neighbor as Route Server client\n")
596c17ba 6634
f4b8ec07
CS
6635DEFUN_YANG (no_neighbor_route_server_client,
6636 no_neighbor_route_server_client_cmd,
6637 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6638 NO_STR
6639 NEIGHBOR_STR
6640 NEIGHBOR_ADDR_STR2
6641 "Configure a neighbor as Route Server client\n")
fee0f4c6 6642{
d62a17ae 6643 int idx_peer = 2;
f4b8ec07
CS
6644 char base_xpath[XPATH_MAXLEN];
6645 char af_xpath[XPATH_MAXLEN];
6646 char attr_xpath[XPATH_MAXLEN];
6647 afi_t afi = bgp_node_afi(vty);
6648 safi_t safi = bgp_node_safi(vty);
6649
6650 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6651 yang_afi_safi_value2identity(afi, safi));
6652
6653 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6654 sizeof(base_xpath), af_xpath)
6655 < 0)
6656 return CMD_WARNING_CONFIG_FAILED;
6657
6658 snprintf(attr_xpath, sizeof(attr_xpath),
6659 "./%s/route-server/route-server-client",
6660 bgp_afi_safi_get_container_str(afi, safi));
6661
6662 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6663
6664 return nb_cli_apply_changes(vty, base_xpath);
fee0f4c6 6665}
6b0655a2 6666
d62a17ae 6667ALIAS_HIDDEN(no_neighbor_route_server_client,
6668 no_neighbor_route_server_client_hidden_cmd,
6669 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6670 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6671 "Configure a neighbor as Route Server client\n")
596c17ba 6672
fee0f4c6 6673DEFUN (neighbor_nexthop_local_unchanged,
6674 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6675 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6676 NEIGHBOR_STR
6677 NEIGHBOR_ADDR_STR2
6678 "Configure treatment of outgoing link-local nexthop attribute\n"
6679 "Leave link-local nexthop unchanged for this peer\n")
6680{
d62a17ae 6681 int idx_peer = 1;
6682 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6683 bgp_node_safi(vty),
6684 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 6685}
6b0655a2 6686
fee0f4c6 6687DEFUN (no_neighbor_nexthop_local_unchanged,
6688 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 6689 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 6690 NO_STR
6691 NEIGHBOR_STR
6692 NEIGHBOR_ADDR_STR2
6693 "Configure treatment of outgoing link-local-nexthop attribute\n"
6694 "Leave link-local nexthop unchanged for this peer\n")
718e3744 6695{
d62a17ae 6696 int idx_peer = 2;
6697 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6698 bgp_node_afi(vty), bgp_node_safi(vty),
6699 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 6700}
6b0655a2 6701
f4b8ec07
CS
6702DEFUN_YANG (neighbor_attr_unchanged,
6703 neighbor_attr_unchanged_cmd,
6704 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6705 NEIGHBOR_STR
6706 NEIGHBOR_ADDR_STR2
6707 "BGP attribute is propagated unchanged to this neighbor\n"
6708 "As-path attribute\n"
6709 "Nexthop attribute\n"
6710 "Med attribute\n")
718e3744 6711{
d62a17ae 6712 int idx = 0;
8eeb0335 6713 char *peer_str = argv[1]->arg;
db45f64d
DS
6714 bool aspath = false;
6715 bool nexthop = false;
6716 bool med = false;
8eeb0335
DW
6717 afi_t afi = bgp_node_afi(vty);
6718 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6719 char base_xpath[XPATH_MAXLEN];
6720 char af_xpath[XPATH_MAXLEN];
6721 char as_xpath[XPATH_MAXLEN];
6722 char nxthop_xpath[XPATH_MAXLEN];
6723 char med_xpath[XPATH_MAXLEN];
8eeb0335 6724
f4b8ec07
CS
6725 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6726 yang_afi_safi_value2identity(afi, safi));
6727
6728 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6729 sizeof(base_xpath), af_xpath)
6730 < 0)
8eeb0335 6731 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6732
6733 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6734 aspath = true;
6735
d62a17ae 6736 idx = 0;
6737 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6738 nexthop = true;
6739
d62a17ae 6740 idx = 0;
6741 if (argv_find(argv, argc, "med", &idx))
db45f64d 6742 med = true;
d62a17ae 6743
f4b8ec07
CS
6744 snprintf(as_xpath, sizeof(as_xpath),
6745 "./%s/attr-unchanged/as-path-unchanged",
6746 bgp_afi_safi_get_container_str(afi, safi));
6747 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6748 "./%s/attr-unchanged/next-hop-unchanged",
6749 bgp_afi_safi_get_container_str(afi, safi));
6750 snprintf(med_xpath, sizeof(med_xpath),
6751 "./%s/attr-unchanged/med-unchanged",
6752 bgp_afi_safi_get_container_str(afi, safi));
6753
8eeb0335 6754 /* no flags means all of them! */
db45f64d 6755 if (!aspath && !nexthop && !med) {
f4b8ec07
CS
6756 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6757 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6758 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
8eeb0335 6759 } else {
f4b8ec07
CS
6760 if (!aspath)
6761 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6762 "false");
6763 else
6764 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6765 "true");
6766
6767 if (!nexthop)
6768 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6769 "false");
6770 else
6771 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6772 "true");
6773
6774 if (!med)
6775 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6776 "false");
6777 else
6778 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6779 "true");
d62a17ae 6780 }
6781
f4b8ec07 6782 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6783}
6784
6785ALIAS_HIDDEN(
6786 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6787 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6788 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6789 "BGP attribute is propagated unchanged to this neighbor\n"
6790 "As-path attribute\n"
6791 "Nexthop attribute\n"
6792 "Med attribute\n")
596c17ba 6793
f4b8ec07
CS
6794DEFUN_YANG (no_neighbor_attr_unchanged,
6795 no_neighbor_attr_unchanged_cmd,
6796 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6797 NO_STR
6798 NEIGHBOR_STR
6799 NEIGHBOR_ADDR_STR2
6800 "BGP attribute is propagated unchanged to this neighbor\n"
6801 "As-path attribute\n"
6802 "Nexthop attribute\n"
6803 "Med attribute\n")
718e3744 6804{
d62a17ae 6805 int idx = 0;
db45f64d 6806 char *peer_str = argv[2]->arg;
db45f64d
DS
6807 bool aspath = false;
6808 bool nexthop = false;
6809 bool med = false;
6810 afi_t afi = bgp_node_afi(vty);
6811 safi_t safi = bgp_node_safi(vty);
f4b8ec07
CS
6812 char base_xpath[XPATH_MAXLEN];
6813 char af_xpath[XPATH_MAXLEN];
6814 char as_xpath[XPATH_MAXLEN];
6815 char nxthop_xpath[XPATH_MAXLEN];
6816 char med_xpath[XPATH_MAXLEN];
db45f64d 6817
f4b8ec07
CS
6818 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6819 yang_afi_safi_value2identity(afi, safi));
6820
6821 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6822 sizeof(base_xpath), af_xpath)
6823 < 0)
db45f64d 6824 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 6825
6826 if (argv_find(argv, argc, "as-path", &idx))
db45f64d
DS
6827 aspath = true;
6828
d62a17ae 6829 idx = 0;
6830 if (argv_find(argv, argc, "next-hop", &idx))
db45f64d
DS
6831 nexthop = true;
6832
d62a17ae 6833 idx = 0;
6834 if (argv_find(argv, argc, "med", &idx))
db45f64d 6835 med = true;
d62a17ae 6836
f4b8ec07
CS
6837 snprintf(as_xpath, sizeof(as_xpath),
6838 "./%s/attr-unchanged/as-path-unchanged",
6839 bgp_afi_safi_get_container_str(afi, safi));
6840 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6841 "./%s/attr-unchanged/next-hop-unchanged",
6842 bgp_afi_safi_get_container_str(afi, safi));
6843 snprintf(med_xpath, sizeof(med_xpath),
6844 "./%s/attr-unchanged/med-unchanged",
6845 bgp_afi_safi_get_container_str(afi, safi));
6846
6847 /* no flags means all of them! */
6848 if (!aspath && !nexthop && !med) {
6849 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6850 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6851 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6852 }
db45f64d
DS
6853
6854 if (aspath)
f4b8ec07 6855 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
db45f64d
DS
6856
6857 if (nexthop)
f4b8ec07 6858 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
d62a17ae 6859
db45f64d 6860 if (med)
f4b8ec07 6861 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
db45f64d 6862
f4b8ec07 6863 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 6864}
6865
6866ALIAS_HIDDEN(
6867 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6868 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6869 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6870 "BGP attribute is propagated unchanged to this neighbor\n"
6871 "As-path attribute\n"
6872 "Nexthop attribute\n"
6873 "Med attribute\n")
718e3744 6874
f4b8ec07
CS
6875/* neighbor ebgp-multihop. */
6876DEFUN_YANG (neighbor_ebgp_multihop,
6877 neighbor_ebgp_multihop_cmd,
6878 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6879 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6880 "Allow EBGP neighbors not on directly connected networks\n")
718e3744 6881{
f4b8ec07
CS
6882 int idx_peer = 1;
6883 char base_xpath[XPATH_MAXLEN];
718e3744 6884
f4b8ec07
CS
6885 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6886 sizeof(base_xpath), NULL)
6887 < 0)
d62a17ae 6888 return CMD_WARNING_CONFIG_FAILED;
718e3744 6889
f4b8ec07
CS
6890 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6891 "true");
718e3744 6892
f4b8ec07 6893 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6894}
6895
f4b8ec07
CS
6896DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6897 neighbor_ebgp_multihop_ttl_cmd,
6898 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6899 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6900 "Allow EBGP neighbors not on directly connected networks\n"
6901 "maximum hop count\n")
718e3744 6902{
f4b8ec07
CS
6903 int idx_peer = 1;
6904 int idx_number = 3;
6905 char base_xpath[XPATH_MAXLEN];
718e3744 6906
f4b8ec07
CS
6907 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6908 sizeof(base_xpath), NULL)
6909 < 0)
d62a17ae 6910 return CMD_WARNING_CONFIG_FAILED;
718e3744 6911
f4b8ec07
CS
6912 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6913 argv[idx_number]->arg);
718e3744 6914
f4b8ec07 6915 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6916}
6917
f4b8ec07
CS
6918DEFUN_YANG (no_neighbor_ebgp_multihop,
6919 no_neighbor_ebgp_multihop_cmd,
6920 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6921 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6922 "Allow EBGP neighbors not on directly connected networks\n"
6923 "maximum hop count\n")
718e3744 6924{
d62a17ae 6925 int idx_peer = 2;
f4b8ec07
CS
6926 char base_xpath[XPATH_MAXLEN];
6927
6928 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6929 sizeof(base_xpath), NULL)
6930 < 0)
6931 return CMD_WARNING_CONFIG_FAILED;
6932
6933 if (argc > 4)
6934 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6935 NB_OP_DESTROY, NULL);
6936 else
6937 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6938 NB_OP_MODIFY, "false");
6939
6940 return nb_cli_apply_changes(vty, base_xpath);
718e3744 6941}
6942
6b0655a2 6943
6ffd2079 6944/* disable-connected-check */
f4b8ec07
CS
6945DEFUN_YANG (neighbor_disable_connected_check,
6946 neighbor_disable_connected_check_cmd,
6947 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6948 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6949 "one-hop away EBGP peer using loopback address\n"
6950 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6951{
d62a17ae 6952 int idx_peer = 1;
f4b8ec07
CS
6953 char base_xpath[XPATH_MAXLEN];
6954
6955 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6956 sizeof(base_xpath), NULL)
6957 < 0)
6958 return CMD_WARNING_CONFIG_FAILED;
6959
6960 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6961 NB_OP_MODIFY, "true");
6962
6963 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6964}
6965
f4b8ec07
CS
6966DEFUN_YANG (no_neighbor_disable_connected_check,
6967 no_neighbor_disable_connected_check_cmd,
6968 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6969 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6970 "one-hop away EBGP peer using loopback address\n"
6971 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 6972{
d62a17ae 6973 int idx_peer = 2;
f4b8ec07
CS
6974 char base_xpath[XPATH_MAXLEN];
6975
6976 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6977 sizeof(base_xpath), NULL)
6978 < 0)
6979 return CMD_WARNING_CONFIG_FAILED;
6980
6981 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6982 NB_OP_MODIFY, "false");
6983
6984 return nb_cli_apply_changes(vty, base_xpath);
6ffd2079 6985}
6986
47cbc09b
PM
6987
6988/* enforce-first-as */
f4b8ec07
CS
6989DEFUN_YANG (neighbor_enforce_first_as,
6990 neighbor_enforce_first_as_cmd,
6991 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6993 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
6994{
6995 int idx_peer = 1;
f4b8ec07 6996 char base_xpath[XPATH_MAXLEN];
47cbc09b 6997
f4b8ec07
CS
6998 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6999 sizeof(base_xpath), NULL)
7000 < 0)
7001 return CMD_WARNING_CONFIG_FAILED;
7002
7003 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
7004
7005 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
7006}
7007
f4b8ec07
CS
7008DEFUN_YANG (no_neighbor_enforce_first_as,
7009 no_neighbor_enforce_first_as_cmd,
7010 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
7011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7012 "Enforce the first AS for EBGP routes\n")
47cbc09b
PM
7013{
7014 int idx_peer = 2;
f4b8ec07 7015 char base_xpath[XPATH_MAXLEN];
47cbc09b 7016
f4b8ec07
CS
7017 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7018 sizeof(base_xpath), NULL)
7019 < 0)
7020 return CMD_WARNING_CONFIG_FAILED;
7021
7022 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
7023
7024 return nb_cli_apply_changes(vty, base_xpath);
47cbc09b
PM
7025}
7026
f4b8ec07
CS
7027static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
7028 char *base_xpath, int xpath_len,
7029 char *xpath)
7030{
7031 union sockunion su;
7032 char num_xpath[XPATH_MAXLEN];
7033 char unnbr_xpath[XPATH_MAXLEN];
7034 char prgrp_xpath[XPATH_MAXLEN];
7035
7036 if (str2sockunion(peer_str, &su) == 0) {
7037 snprintf(num_xpath, sizeof(num_xpath),
7038 "/neighbors/neighbor[remote-address='%s']", peer_str);
3bb513c3
CH
7039 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7040 VTY_CURR_XPATH, num_xpath)) {
f4b8ec07
CS
7041 snprintf(base_xpath, xpath_len,
7042 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
7043 xpath ? xpath : "");
7044 } else {
7045 vty_out(vty,
7046 "%% Specify remote-as or peer-group commands first\n");
7047 return -1;
7048 }
7049
7050 } else {
7051 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
7052 "/neighbors/unnumbered-neighbor[interface='%s']",
7053 peer_str);
7054
7055 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
7056 "/peer-groups/peer-group[peer-group-name='%s']",
7057 peer_str);
7058
3bb513c3
CH
7059 if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
7060 VTY_CURR_XPATH, unnbr_xpath)) {
f4b8ec07
CS
7061 snprintf(base_xpath, xpath_len,
7062 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
7063 xpath ? xpath : "");
3bb513c3
CH
7064 } else if (yang_dnode_existsf(vty->candidate_config->dnode,
7065 "%s%s", VTY_CURR_XPATH,
7066 prgrp_xpath)) {
f4b8ec07
CS
7067 snprintf(base_xpath, xpath_len,
7068 FRR_BGP_PEER_GROUP_XPATH, peer_str,
7069 xpath ? xpath : "");
7070 } else {
7071 vty_out(vty,
7072 "%% Create the peer-group or interface first\n");
7073 return -1;
7074 }
7075 }
7076
7077 return 0;
7078}
47cbc09b 7079
f4b8ec07
CS
7080DEFUN_YANG (neighbor_description,
7081 neighbor_description_cmd,
7082 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7083 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7084 "Neighbor specific description\n"
7085 "Up to 80 characters describing this neighbor\n")
718e3744 7086{
d62a17ae 7087 int idx_peer = 1;
7088 int idx_line = 3;
f4b8ec07
CS
7089 int ret;
7090 char base_xpath[XPATH_MAXLEN];
d62a17ae 7091 char *str;
718e3744 7092
f4b8ec07
CS
7093 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7094 sizeof(base_xpath), NULL)
7095 < 0)
d62a17ae 7096 return CMD_WARNING_CONFIG_FAILED;
718e3744 7097
d62a17ae 7098 str = argv_concat(argv, argc, idx_line);
718e3744 7099
f4b8ec07
CS
7100 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7101
7102 ret = nb_cli_apply_changes(vty, base_xpath);
718e3744 7103
d62a17ae 7104 XFREE(MTYPE_TMP, str);
718e3744 7105
f4b8ec07 7106 return ret;
718e3744 7107}
7108
f4b8ec07
CS
7109DEFUN_YANG (no_neighbor_description,
7110 no_neighbor_description_cmd,
7111 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7112 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7113 "Neighbor specific description\n")
718e3744 7114{
d62a17ae 7115 int idx_peer = 2;
f4b8ec07
CS
7116 char base_xpath[XPATH_MAXLEN];
7117
7118 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7119 sizeof(base_xpath), NULL)
7120 < 0)
d62a17ae 7121 return CMD_WARNING_CONFIG_FAILED;
718e3744 7122
f4b8ec07 7123 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
718e3744 7124
f4b8ec07 7125 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7126}
7127
232c75cd 7128ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
a14810f4
PM
7129 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7130 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7131 "Neighbor specific description\n"
7132 "Up to 80 characters describing this neighbor\n")
6b0655a2 7133
d62a17ae 7134#define BGP_UPDATE_SOURCE_HELP_STR \
7135 "IPv4 address\n" \
7136 "IPv6 address\n" \
7137 "Interface name (requires zebra to be running)\n"
369688c0 7138
f4b8ec07
CS
7139DEFUN_YANG (neighbor_update_source,
7140 neighbor_update_source_cmd,
7141 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7142 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7143 "Source of routing updates\n"
7144 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7145{
d62a17ae 7146 int idx_peer = 1;
7147 int idx_peer_2 = 3;
f4b8ec07
CS
7148 union sockunion su;
7149 char base_xpath[XPATH_MAXLEN];
7150
7151 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7152 sizeof(base_xpath), NULL)
7153 < 0)
7154 return CMD_WARNING_CONFIG_FAILED;
7155
f4b8ec07
CS
7156 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7157 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
d62a17ae 7158 argv[idx_peer_2]->arg);
f4b8ec07
CS
7159 else
7160 nb_cli_enqueue_change(vty, "./update-source/interface",
7161 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7162
7163 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7164}
7165
f4b8ec07
CS
7166DEFUN_YANG (no_neighbor_update_source,
7167 no_neighbor_update_source_cmd,
7168 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7169 NO_STR NEIGHBOR_STR
7170 NEIGHBOR_ADDR_STR2
7171 "Source of routing updates\n"
7172 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 7173{
d62a17ae 7174 int idx_peer = 2;
f4b8ec07 7175 char base_xpath[XPATH_MAXLEN];
f4b8ec07
CS
7176
7177 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7178 sizeof(base_xpath), NULL)
7179 < 0)
7180 return CMD_WARNING_CONFIG_FAILED;
7181
555c8ab7
CS
7182 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7183 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7184 NULL);
f4b8ec07
CS
7185
7186 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7187}
6b0655a2 7188
d62a17ae 7189static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7190 afi_t afi, safi_t safi,
7191 const char *rmap, int set)
718e3744 7192{
d62a17ae 7193 int ret;
7194 struct peer *peer;
80912664 7195 struct route_map *route_map = NULL;
718e3744 7196
d62a17ae 7197 peer = peer_and_group_lookup_vty(vty, peer_str);
7198 if (!peer)
7199 return CMD_WARNING_CONFIG_FAILED;
718e3744 7200
1de27621 7201 if (set) {
80912664
DS
7202 if (rmap)
7203 route_map = route_map_lookup_warn_noexist(vty, rmap);
1de27621
DA
7204 ret = peer_default_originate_set(peer, afi, safi,
7205 rmap, route_map);
7206 } else
d62a17ae 7207 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 7208
d62a17ae 7209 return bgp_vty_return(vty, ret);
718e3744 7210}
7211
7212/* neighbor default-originate. */
7213DEFUN (neighbor_default_originate,
7214 neighbor_default_originate_cmd,
9ccf14f7 7215 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 7216 NEIGHBOR_STR
7217 NEIGHBOR_ADDR_STR2
7218 "Originate default route to this neighbor\n")
7219{
d62a17ae 7220 int idx_peer = 1;
7221 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7222 bgp_node_afi(vty),
7223 bgp_node_safi(vty), NULL, 1);
718e3744 7224}
7225
d62a17ae 7226ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7227 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7228 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7229 "Originate default route to this neighbor\n")
596c17ba 7230
718e3744 7231DEFUN (neighbor_default_originate_rmap,
7232 neighbor_default_originate_rmap_cmd,
9ccf14f7 7233 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 7234 NEIGHBOR_STR
7235 NEIGHBOR_ADDR_STR2
7236 "Originate default route to this neighbor\n"
7237 "Route-map to specify criteria to originate default\n"
7238 "route-map name\n")
7239{
d62a17ae 7240 int idx_peer = 1;
7241 int idx_word = 4;
7242 return peer_default_originate_set_vty(
7243 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7244 argv[idx_word]->arg, 1);
718e3744 7245}
7246
d62a17ae 7247ALIAS_HIDDEN(
7248 neighbor_default_originate_rmap,
7249 neighbor_default_originate_rmap_hidden_cmd,
7250 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7251 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7252 "Originate default route to this neighbor\n"
7253 "Route-map to specify criteria to originate default\n"
7254 "route-map name\n")
596c17ba 7255
718e3744 7256DEFUN (no_neighbor_default_originate,
7257 no_neighbor_default_originate_cmd,
a636c635 7258 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 7259 NO_STR
7260 NEIGHBOR_STR
7261 NEIGHBOR_ADDR_STR2
a636c635
DW
7262 "Originate default route to this neighbor\n"
7263 "Route-map to specify criteria to originate default\n"
7264 "route-map name\n")
718e3744 7265{
d62a17ae 7266 int idx_peer = 2;
7267 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7268 bgp_node_afi(vty),
7269 bgp_node_safi(vty), NULL, 0);
718e3744 7270}
7271
d62a17ae 7272ALIAS_HIDDEN(
7273 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7274 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7275 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7276 "Originate default route to this neighbor\n"
7277 "Route-map to specify criteria to originate default\n"
7278 "route-map name\n")
596c17ba 7279
6b0655a2 7280
f418446b 7281/* Set specified peer's BGP port. */
f4b8ec07
CS
7282DEFUN_YANG (neighbor_port,
7283 neighbor_port_cmd,
7284 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7285 NEIGHBOR_STR
7286 NEIGHBOR_ADDR_STR
7287 "Neighbor's BGP port\n"
7288 "TCP port number\n")
718e3744 7289{
d62a17ae 7290 int idx_ip = 1;
7291 int idx_number = 3;
f4b8ec07 7292 char base_xpath[XPATH_MAXLEN];
718e3744 7293
f4b8ec07
CS
7294 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7295 argv[idx_ip]->arg, "");
718e3744 7296
f4b8ec07
CS
7297 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7298 argv[idx_number]->arg);
7299
7300 return nb_cli_apply_changes(vty, base_xpath);
7301}
6b0655a2 7302
f4b8ec07
CS
7303DEFUN_YANG (no_neighbor_port,
7304 no_neighbor_port_cmd,
7305 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7306 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7307 "Neighbor's BGP port\n"
7308 "TCP port number\n")
718e3744 7309{
f4b8ec07
CS
7310 int idx_ip = 2;
7311 char base_xpath[XPATH_MAXLEN];
718e3744 7312
f4b8ec07
CS
7313 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7314 argv[idx_ip]->arg, "");
718e3744 7315
f4b8ec07 7316 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
718e3744 7317
f4b8ec07 7318 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7319}
7320
f4b8ec07
CS
7321DEFUN_YANG (neighbor_weight,
7322 neighbor_weight_cmd,
7323 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7324 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7325 "Set default weight for routes from this neighbor\n"
7326 "default weight\n")
718e3744 7327{
f4b8ec07
CS
7328 int idx_peer = 1;
7329 int idx_number = 3;
7330 char base_xpath[XPATH_MAXLEN];
7331 char af_xpath[XPATH_MAXLEN];
7332 char attr_xpath[XPATH_MAXLEN];
7333 afi_t afi = bgp_node_afi(vty);
7334 safi_t safi = bgp_node_safi(vty);
718e3744 7335
f4b8ec07
CS
7336 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7337 yang_afi_safi_value2identity(afi, safi));
7338
7339 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7340 sizeof(base_xpath), af_xpath)
7341 < 0)
d62a17ae 7342 return CMD_WARNING_CONFIG_FAILED;
718e3744 7343
f4b8ec07
CS
7344 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7345 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7346
f4b8ec07
CS
7347 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7348 argv[idx_number]->arg);
7349
7350 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7351}
7352
d62a17ae 7353ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7354 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7355 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7356 "Set default weight for routes from this neighbor\n"
7357 "default weight\n")
596c17ba 7358
f4b8ec07
CS
7359DEFUN_YANG (no_neighbor_weight,
7360 no_neighbor_weight_cmd,
7361 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7362 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7363 "Set default weight for routes from this neighbor\n"
7364 "default weight\n")
718e3744 7365{
d62a17ae 7366 int idx_peer = 2;
f4b8ec07
CS
7367 char base_xpath[XPATH_MAXLEN];
7368 char af_xpath[XPATH_MAXLEN];
7369 char attr_xpath[XPATH_MAXLEN];
7370 afi_t afi = bgp_node_afi(vty);
7371 safi_t safi = bgp_node_safi(vty);
7372
7373 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7374 yang_afi_safi_value2identity(afi, safi));
7375
7376 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7377 sizeof(base_xpath), af_xpath)
7378 < 0)
7379 return CMD_WARNING_CONFIG_FAILED;
7380
7381 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7382 bgp_afi_safi_get_container_str(afi, safi));
7383
7384 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7385
7386 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7387}
7388
d62a17ae 7389ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7390 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7391 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7392 "Set default weight for routes from this neighbor\n"
7393 "default weight\n")
596c17ba 7394
6b0655a2 7395
718e3744 7396/* Override capability negotiation. */
8611c7f3
CS
7397DEFUN_YANG (neighbor_override_capability,
7398 neighbor_override_capability_cmd,
7399 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7400 NEIGHBOR_STR
7401 NEIGHBOR_ADDR_STR2
7402 "Override capability negotiation result\n")
718e3744 7403{
d62a17ae 7404 int idx_peer = 1;
8611c7f3
CS
7405 char base_xpath[XPATH_MAXLEN];
7406
7407 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7408 sizeof(base_xpath), NULL)
7409 < 0)
7410 return CMD_WARNING_CONFIG_FAILED;
7411
7412 nb_cli_enqueue_change(
7413 vty, "./capability-options/override-capability",
7414 NB_OP_MODIFY, "true");
7415
7416 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7417}
7418
8611c7f3
CS
7419DEFUN_YANG (no_neighbor_override_capability,
7420 no_neighbor_override_capability_cmd,
7421 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7422 NO_STR
7423 NEIGHBOR_STR
7424 NEIGHBOR_ADDR_STR2
7425 "Override capability negotiation result\n")
718e3744 7426{
d62a17ae 7427 int idx_peer = 2;
8611c7f3
CS
7428 char base_xpath[XPATH_MAXLEN];
7429
7430 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7431 sizeof(base_xpath), NULL)
7432 < 0)
7433 return CMD_WARNING_CONFIG_FAILED;
7434
7435 nb_cli_enqueue_change(
7436 vty, "./capability-options/override-capability",
7437 NB_OP_MODIFY, "false");
7438
7439 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7440}
6b0655a2 7441
8611c7f3
CS
7442DEFUN_YANG (neighbor_strict_capability,
7443 neighbor_strict_capability_cmd,
7444 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7445 NEIGHBOR_STR
7446 NEIGHBOR_ADDR_STR2
7447 "Strict capability negotiation match\n")
718e3744 7448{
9fb964de 7449 int idx_peer = 1;
8611c7f3 7450 char base_xpath[XPATH_MAXLEN];
9fb964de 7451
8611c7f3
CS
7452 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7453 sizeof(base_xpath), NULL)
7454 < 0)
7455 return CMD_WARNING_CONFIG_FAILED;
7456
7457 nb_cli_enqueue_change(
7458 vty, "./capability-options/strict-capability",
7459 NB_OP_MODIFY, "true");
7460
7461 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7462}
7463
8611c7f3
CS
7464DEFUN_YANG (no_neighbor_strict_capability,
7465 no_neighbor_strict_capability_cmd,
7466 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7467 NO_STR
7468 NEIGHBOR_STR
7469 NEIGHBOR_ADDR_STR2
7470 "Strict capability negotiation match\n")
718e3744 7471{
9fb964de 7472 int idx_peer = 2;
8611c7f3 7473 char base_xpath[XPATH_MAXLEN];
9fb964de 7474
8611c7f3
CS
7475 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7476 sizeof(base_xpath), NULL)
7477 < 0)
7478 return CMD_WARNING_CONFIG_FAILED;
7479
7480 nb_cli_enqueue_change(
7481 vty, "./capability-options/strict-capability",
7482 NB_OP_MODIFY, "false");
7483
7484 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7485}
6b0655a2 7486
f4b8ec07
CS
7487DEFUN_YANG (neighbor_timers,
7488 neighbor_timers_cmd,
7489 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7490 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7491 "BGP per neighbor timers\n"
7492 "Keepalive interval\n"
7493 "Holdtime\n")
718e3744 7494{
f4b8ec07
CS
7495 int idx_peer = 1;
7496 int idx_number = 3;
7497 int idx_number_2 = 4;
7498 char base_xpath[XPATH_MAXLEN];
718e3744 7499
f4b8ec07
CS
7500 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7501 sizeof(base_xpath), NULL)
7502 < 0)
d62a17ae 7503 return CMD_WARNING_CONFIG_FAILED;
718e3744 7504
f4b8ec07
CS
7505 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7506 argv[idx_number]->arg);
718e3744 7507
f4b8ec07
CS
7508 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7509 argv[idx_number_2]->arg);
718e3744 7510
f4b8ec07 7511 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7512}
6b0655a2 7513
f4b8ec07
CS
7514DEFUN_YANG (no_neighbor_timers,
7515 no_neighbor_timers_cmd,
7516 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7517 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7518 "BGP per neighbor timers\n"
7519 "Keepalive interval\n"
7520 "Holdtime\n")
718e3744 7521{
f4b8ec07
CS
7522 int idx_peer = 2;
7523 char base_xpath[XPATH_MAXLEN];
718e3744 7524
f4b8ec07
CS
7525 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7526 sizeof(base_xpath), NULL)
7527 < 0)
d62a17ae 7528 return CMD_WARNING_CONFIG_FAILED;
718e3744 7529
f4b8ec07 7530 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
718e3744 7531
f4b8ec07 7532 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
718e3744 7533
f4b8ec07 7534 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7535}
6b0655a2 7536
f4b8ec07
CS
7537DEFUN_YANG (neighbor_timers_connect,
7538 neighbor_timers_connect_cmd,
7539 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7540 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7541 "BGP per neighbor timers\n"
7542 "BGP connect timer\n"
7543 "Connect timer\n")
718e3744 7544{
f4b8ec07
CS
7545 int idx_peer = 1;
7546 int idx_number = 4;
7547 char base_xpath[XPATH_MAXLEN];
718e3744 7548
f4b8ec07
CS
7549 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7550 sizeof(base_xpath), NULL)
7551 < 0)
d62a17ae 7552 return CMD_WARNING_CONFIG_FAILED;
718e3744 7553
f4b8ec07
CS
7554 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7555 argv[idx_number]->arg);
718e3744 7556
f4b8ec07 7557 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7558}
7559
f4b8ec07
CS
7560DEFUN_YANG (no_neighbor_timers_connect,
7561 no_neighbor_timers_connect_cmd,
7562 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7563 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7564 "BGP per neighbor timers\n"
7565 "BGP connect timer\n"
7566 "Connect timer\n")
718e3744 7567{
f4b8ec07
CS
7568 int idx_peer = 2;
7569 char base_xpath[XPATH_MAXLEN];
718e3744 7570
f4b8ec07
CS
7571 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7572 sizeof(base_xpath), NULL)
7573 < 0)
d62a17ae 7574 return CMD_WARNING_CONFIG_FAILED;
718e3744 7575
f4b8ec07
CS
7576 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7577 NULL);
718e3744 7578
f4b8ec07 7579 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7580}
7581
d43114f3
DS
7582DEFPY (neighbor_timers_delayopen,
7583 neighbor_timers_delayopen_cmd,
7584 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7585 NEIGHBOR_STR
7586 NEIGHBOR_ADDR_STR2
7587 "BGP per neighbor timers\n"
7588 "RFC 4271 DelayOpenTimer\n"
7589 "DelayOpenTime timer interval\n")
7590{
7591 struct peer *peer;
7592
7593 peer = peer_and_group_lookup_vty(vty, neighbor);
7594 if (!peer)
7595 return CMD_WARNING_CONFIG_FAILED;
7596
7597 if (!interval) {
7598 if (peer_timers_delayopen_unset(peer))
7599 return CMD_WARNING_CONFIG_FAILED;
7600 } else {
7601 if (peer_timers_delayopen_set(peer, interval))
7602 return CMD_WARNING_CONFIG_FAILED;
7603 }
7604
7605 return CMD_SUCCESS;
7606}
7607
7608DEFPY (no_neighbor_timers_delayopen,
7609 no_neighbor_timers_delayopen_cmd,
7610 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7611 NO_STR
7612 NEIGHBOR_STR
7613 NEIGHBOR_ADDR_STR2
7614 "BGP per neighbor timers\n"
7615 "RFC 4271 DelayOpenTimer\n"
7616 "DelayOpenTime timer interval\n")
7617{
7618 struct peer *peer;
7619
7620 peer = peer_and_group_lookup_vty(vty, neighbor);
7621 if (!peer)
7622 return CMD_WARNING_CONFIG_FAILED;
7623
7624 if (peer_timers_delayopen_unset(peer))
7625 return CMD_WARNING_CONFIG_FAILED;
7626
7627 return CMD_SUCCESS;
7628}
7629
f4b8ec07
CS
7630DEFUN_YANG (neighbor_advertise_interval,
7631 neighbor_advertise_interval_cmd,
7632 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7633 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7634 "Minimum interval between sending BGP routing updates\n"
7635 "time in seconds\n")
718e3744 7636{
d62a17ae 7637 int idx_peer = 1;
f4b8ec07
CS
7638 int idx_number = 3;
7639 char base_xpath[XPATH_MAXLEN];
718e3744 7640
f4b8ec07
CS
7641 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7642 sizeof(base_xpath), NULL)
7643 < 0)
d62a17ae 7644 return CMD_WARNING_CONFIG_FAILED;
718e3744 7645
f4b8ec07
CS
7646 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7647 argv[idx_number]->arg);
718e3744 7648
f4b8ec07 7649 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7650}
7651
f4b8ec07
CS
7652DEFUN_YANG (no_neighbor_advertise_interval,
7653 no_neighbor_advertise_interval_cmd,
7654 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7655 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7656 "Minimum interval between sending BGP routing updates\n"
7657 "time in seconds\n")
718e3744 7658{
d62a17ae 7659 int idx_peer = 2;
f4b8ec07
CS
7660 char base_xpath[XPATH_MAXLEN];
7661
7662 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7663 sizeof(base_xpath), NULL)
7664 < 0)
7665 return CMD_WARNING_CONFIG_FAILED;
7666
7667 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7668 NULL);
7669
7670 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7671}
7672
6b0655a2 7673
518f0eb1
DS
7674/* Time to wait before processing route-map updates */
7675DEFUN (bgp_set_route_map_delay_timer,
7676 bgp_set_route_map_delay_timer_cmd,
6147e2c6 7677 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
7678 SET_STR
7679 "BGP route-map delay timer\n"
7680 "Time in secs to wait before processing route-map changes\n"
f414725f 7681 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7682{
d62a17ae 7683 int idx_number = 3;
d7c0a89a 7684 uint32_t rmap_delay_timer;
d62a17ae 7685
7686 if (argv[idx_number]->arg) {
7687 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7688 bm->rmap_update_timer = rmap_delay_timer;
7689
7690 /* if the dynamic update handling is being disabled, and a timer
7691 * is
7692 * running, stop the timer and act as if the timer has already
7693 * fired.
7694 */
7695 if (!rmap_delay_timer && bm->t_rmap_update) {
7696 BGP_TIMER_OFF(bm->t_rmap_update);
7697 thread_execute(bm->master, bgp_route_map_update_timer,
7698 NULL, 0);
7699 }
7700 return CMD_SUCCESS;
7701 } else {
7702 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7703 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 7704 }
518f0eb1
DS
7705}
7706
7707DEFUN (no_bgp_set_route_map_delay_timer,
7708 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 7709 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 7710 NO_STR
3a2d747c 7711 BGP_STR
518f0eb1 7712 "Default BGP route-map delay timer\n"
8334fd5a
DW
7713 "Reset to default time to wait for processing route-map changes\n"
7714 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 7715{
518f0eb1 7716
d62a17ae 7717 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 7718
d62a17ae 7719 return CMD_SUCCESS;
518f0eb1
DS
7720}
7721
f4b8ec07
CS
7722DEFUN_YANG (neighbor_interface,
7723 neighbor_interface_cmd,
7724 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7725 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7726 "Interface\n"
7727 "Interface name\n")
718e3744 7728{
f4b8ec07
CS
7729 int idx_ip = 1;
7730 int idx_word = 3;
7731 char base_xpath[XPATH_MAXLEN];
718e3744 7732
f4b8ec07
CS
7733 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7734 argv[idx_ip]->arg, "");
718e3744 7735
f4b8ec07
CS
7736 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7737 argv[idx_word]->arg);
718e3744 7738
f4b8ec07 7739 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7740}
7741
f4b8ec07
CS
7742DEFUN_YANG (no_neighbor_interface,
7743 no_neighbor_interface_cmd,
7744 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7746 "Interface\n"
7747 "Interface name\n")
718e3744 7748{
d62a17ae 7749 int idx_peer = 2;
f4b8ec07
CS
7750 char base_xpath[XPATH_MAXLEN];
7751
7752 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7753 argv[idx_peer]->arg, "");
7754
7755 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7756
7757 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7758}
6b0655a2 7759
718e3744 7760DEFUN (neighbor_distribute_list,
7761 neighbor_distribute_list_cmd,
9ccf14f7 7762 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7763 NEIGHBOR_STR
7764 NEIGHBOR_ADDR_STR2
7765 "Filter updates to/from this neighbor\n"
7766 "IP access-list number\n"
7767 "IP access-list number (expanded range)\n"
7768 "IP Access-list name\n"
7769 "Filter incoming updates\n"
7770 "Filter outgoing updates\n")
7771{
d62a17ae 7772 int idx_peer = 1;
7773 int idx_acl = 3;
7774 int direct, ret;
7775 struct peer *peer;
a8206004 7776
d62a17ae 7777 const char *pstr = argv[idx_peer]->arg;
7778 const char *acl = argv[idx_acl]->arg;
7779 const char *inout = argv[argc - 1]->text;
a8206004 7780
d62a17ae 7781 peer = peer_and_group_lookup_vty(vty, pstr);
7782 if (!peer)
7783 return CMD_WARNING_CONFIG_FAILED;
a8206004 7784
d62a17ae 7785 /* Check filter direction. */
7786 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7787 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7788 direct, acl);
a8206004 7789
d62a17ae 7790 return bgp_vty_return(vty, ret);
718e3744 7791}
7792
d62a17ae 7793ALIAS_HIDDEN(
7794 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7795 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7796 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7797 "Filter updates to/from this neighbor\n"
7798 "IP access-list number\n"
7799 "IP access-list number (expanded range)\n"
7800 "IP Access-list name\n"
7801 "Filter incoming updates\n"
7802 "Filter outgoing updates\n")
596c17ba 7803
718e3744 7804DEFUN (no_neighbor_distribute_list,
7805 no_neighbor_distribute_list_cmd,
9ccf14f7 7806 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 7807 NO_STR
7808 NEIGHBOR_STR
7809 NEIGHBOR_ADDR_STR2
7810 "Filter updates to/from this neighbor\n"
7811 "IP access-list number\n"
7812 "IP access-list number (expanded range)\n"
7813 "IP Access-list name\n"
7814 "Filter incoming updates\n"
7815 "Filter outgoing updates\n")
7816{
d62a17ae 7817 int idx_peer = 2;
7818 int direct, ret;
7819 struct peer *peer;
a8206004 7820
d62a17ae 7821 const char *pstr = argv[idx_peer]->arg;
7822 const char *inout = argv[argc - 1]->text;
a8206004 7823
d62a17ae 7824 peer = peer_and_group_lookup_vty(vty, pstr);
7825 if (!peer)
7826 return CMD_WARNING_CONFIG_FAILED;
a8206004 7827
d62a17ae 7828 /* Check filter direction. */
7829 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7830 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7831 direct);
a8206004 7832
d62a17ae 7833 return bgp_vty_return(vty, ret);
718e3744 7834}
6b0655a2 7835
d62a17ae 7836ALIAS_HIDDEN(
7837 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7838 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7839 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7840 "Filter updates to/from this neighbor\n"
7841 "IP access-list number\n"
7842 "IP access-list number (expanded range)\n"
7843 "IP Access-list name\n"
7844 "Filter incoming updates\n"
7845 "Filter outgoing updates\n")
596c17ba 7846
718e3744 7847/* Set prefix list to the peer. */
d9986d26
CS
7848DEFPY_YANG(
7849 neighbor_prefix_list, neighbor_prefix_list_cmd,
7850 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7851 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7852 "Filter updates to/from this neighbor\n"
7853 "Name of a prefix list\n"
7854 "Filter incoming updates\n"
7855 "Filter outgoing updates\n")
718e3744 7856{
d9986d26
CS
7857 char base_xpath[XPATH_MAXLEN];
7858 char af_xpath[XPATH_MAXLEN];
c6685575 7859 char plist_xpath[XPATH_MAXLEN];
d9986d26
CS
7860 afi_t afi = bgp_node_afi(vty);
7861 safi_t safi = bgp_node_safi(vty);
718e3744 7862
d9986d26
CS
7863 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7864 yang_afi_safi_value2identity(afi, safi));
7865 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7866 sizeof(base_xpath), af_xpath)
7867 < 0)
d62a17ae 7868 return CMD_WARNING_CONFIG_FAILED;
e52702f2 7869
d9986d26
CS
7870 if (strmatch(direction, "in"))
7871 snprintf(plist_xpath, sizeof(plist_xpath),
7872 "./%s/filter-config/plist-import",
7873 bgp_afi_safi_get_container_str(afi, safi));
7874 else if (strmatch(direction, "out"))
7875 snprintf(plist_xpath, sizeof(plist_xpath),
7876 "./%s/filter-config/plist-export",
7877 bgp_afi_safi_get_container_str(afi, safi));
718e3744 7878
d9986d26
CS
7879 if (!no)
7880 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7881 prefix_str);
7882 else
7883 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
718e3744 7884
d9986d26 7885 return nb_cli_apply_changes(vty, base_xpath);
718e3744 7886}
7887
d62a17ae 7888ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7889 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7891 "Filter updates to/from this neighbor\n"
7892 "Name of a prefix list\n"
7893 "Filter incoming updates\n"
7894 "Filter outgoing updates\n")
596c17ba 7895
d62a17ae 7896static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7897 safi_t safi, const char *name_str,
7898 const char *direct_str)
718e3744 7899{
d62a17ae 7900 int ret;
7901 struct peer *peer;
7902 int direct = FILTER_IN;
718e3744 7903
d62a17ae 7904 peer = peer_and_group_lookup_vty(vty, ip_str);
7905 if (!peer)
7906 return CMD_WARNING_CONFIG_FAILED;
718e3744 7907
d62a17ae 7908 /* Check filter direction. */
7909 if (strncmp(direct_str, "i", 1) == 0)
7910 direct = FILTER_IN;
7911 else if (strncmp(direct_str, "o", 1) == 0)
7912 direct = FILTER_OUT;
718e3744 7913
d62a17ae 7914 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 7915
d62a17ae 7916 return bgp_vty_return(vty, ret);
718e3744 7917}
7918
d62a17ae 7919static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7920 safi_t safi, const char *direct_str)
718e3744 7921{
d62a17ae 7922 int ret;
7923 struct peer *peer;
7924 int direct = FILTER_IN;
718e3744 7925
d62a17ae 7926 peer = peer_and_group_lookup_vty(vty, ip_str);
7927 if (!peer)
7928 return CMD_WARNING_CONFIG_FAILED;
718e3744 7929
d62a17ae 7930 /* Check filter direction. */
7931 if (strncmp(direct_str, "i", 1) == 0)
7932 direct = FILTER_IN;
7933 else if (strncmp(direct_str, "o", 1) == 0)
7934 direct = FILTER_OUT;
718e3744 7935
d62a17ae 7936 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 7937
d62a17ae 7938 return bgp_vty_return(vty, ret);
718e3744 7939}
7940
7941DEFUN (neighbor_filter_list,
7942 neighbor_filter_list_cmd,
9ccf14f7 7943 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7944 NEIGHBOR_STR
7945 NEIGHBOR_ADDR_STR2
7946 "Establish BGP filters\n"
7947 "AS path access-list name\n"
7948 "Filter incoming routes\n"
7949 "Filter outgoing routes\n")
7950{
d62a17ae 7951 int idx_peer = 1;
7952 int idx_word = 3;
7953 int idx_in_out = 4;
7954 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7955 bgp_node_safi(vty), argv[idx_word]->arg,
7956 argv[idx_in_out]->arg);
718e3744 7957}
7958
d62a17ae 7959ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7960 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7962 "Establish BGP filters\n"
7963 "AS path access-list name\n"
7964 "Filter incoming routes\n"
7965 "Filter outgoing routes\n")
596c17ba 7966
718e3744 7967DEFUN (no_neighbor_filter_list,
7968 no_neighbor_filter_list_cmd,
9ccf14f7 7969 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 7970 NO_STR
7971 NEIGHBOR_STR
7972 NEIGHBOR_ADDR_STR2
7973 "Establish BGP filters\n"
7974 "AS path access-list name\n"
7975 "Filter incoming routes\n"
7976 "Filter outgoing routes\n")
7977{
d62a17ae 7978 int idx_peer = 2;
7979 int idx_in_out = 5;
7980 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7981 bgp_node_afi(vty), bgp_node_safi(vty),
7982 argv[idx_in_out]->arg);
718e3744 7983}
6b0655a2 7984
d62a17ae 7985ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7986 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7987 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7988 "Establish BGP filters\n"
7989 "AS path access-list name\n"
7990 "Filter incoming routes\n"
7991 "Filter outgoing routes\n")
596c17ba 7992
7f7940e6
MK
7993/* Set advertise-map to the peer. */
7994static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7995 afi_t afi, safi_t safi,
cf2ad4d8
MK
7996 const char *advertise_str,
7997 const char *condition_str, bool condition,
7998 bool set)
7f7940e6
MK
7999{
8000 int ret = CMD_WARNING_CONFIG_FAILED;
8001 struct peer *peer;
8002 struct route_map *advertise_map;
8003 struct route_map *condition_map;
8004
8005 peer = peer_and_group_lookup_vty(vty, ip_str);
8006 if (!peer)
8007 return ret;
8008
8009 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
8010 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
8011
cf2ad4d8
MK
8012 if (set)
8013 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
8014 advertise_map, condition_str,
8015 condition_map, condition);
8016 else
8017 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
8018 advertise_map, condition_str,
8019 condition_map, condition);
7f7940e6
MK
8020
8021 return bgp_vty_return(vty, ret);
8022}
8023
cf2ad4d8 8024DEFPY (neighbor_advertise_map,
7f7940e6 8025 neighbor_advertise_map_cmd,
52b84062 8026 "[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 8027 NO_STR
7f7940e6
MK
8028 NEIGHBOR_STR
8029 NEIGHBOR_ADDR_STR2
8030 "Route-map to conditionally advertise routes\n"
8031 "Name of advertise map\n"
8032 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 8033 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 8034 "Name of the exist or non exist map\n")
7f7940e6 8035{
7f7940e6
MK
8036 bool condition = CONDITION_EXIST;
8037
52b84062 8038 if (!strcmp(exist, "non-exist-map"))
7f7940e6
MK
8039 condition = CONDITION_NON_EXIST;
8040
52b84062
MK
8041 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
8042 bgp_node_safi(vty), advertise_str,
8043 condition_str, condition, !no);
7f7940e6
MK
8044}
8045
8046ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
52b84062 8047 "[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
8048 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8049 "Route-map to conditionally advertise routes\n"
8050 "Name of advertise map\n"
8051 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7f7940e6 8052 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
52b84062 8053 "Name of the exist or non exist map\n")
7f7940e6 8054
718e3744 8055/* Set route-map to the peer. */
c6685575
CS
8056DEFPY_YANG(
8057 neighbor_route_map, neighbor_route_map_cmd,
8058 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
8059 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8060 "Apply route map to neighbor\n"
8061 "Name of route map\n"
8062 "Apply map to incoming routes\n"
8063 "Apply map to outbound routes\n")
718e3744 8064{
c6685575
CS
8065 char base_xpath[XPATH_MAXLEN];
8066 char af_xpath[XPATH_MAXLEN];
8067 char rmap_xpath[XPATH_MAXLEN];
8068 afi_t afi = bgp_node_afi(vty);
8069 safi_t safi = bgp_node_safi(vty);
718e3744 8070
c6685575
CS
8071 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8072 yang_afi_safi_value2identity(afi, safi));
8073 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
8074 sizeof(base_xpath), af_xpath)
8075 < 0)
d62a17ae 8076 return CMD_WARNING_CONFIG_FAILED;
718e3744 8077
c6685575
CS
8078 if (strmatch(direction, "in"))
8079 snprintf(rmap_xpath, sizeof(rmap_xpath),
8080 "./%s/filter-config/rmap-import",
8081 bgp_afi_safi_get_container_str(afi, safi));
8082 else if (strmatch(direction, "out"))
8083 snprintf(rmap_xpath, sizeof(rmap_xpath),
8084 "./%s/filter-config/rmap-export",
8085 bgp_afi_safi_get_container_str(afi, safi));
718e3744 8086
c6685575 8087 if (!no) {
3bb513c3 8088 if (!yang_dnode_existsf(
c6685575
CS
8089 vty->candidate_config->dnode,
8090 "/frr-route-map:lib/route-map[name='%s']",
8091 rmap_str)) {
8092 if (vty_shell_serv(vty))
8093 vty_out(vty,
8094 "The route-map '%s' does not exist.\n",
8095 rmap_str);
8096 }
8097 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8098 } else
8099 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
718e3744 8100
c6685575 8101 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8102}
8103
718e3744 8104/* Set unsuppress-map to the peer. */
d62a17ae 8105static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8106 afi_t afi, safi_t safi,
8107 const char *name_str)
718e3744 8108{
d62a17ae 8109 int ret;
8110 struct peer *peer;
1de27621 8111 struct route_map *route_map;
718e3744 8112
d62a17ae 8113 peer = peer_and_group_lookup_vty(vty, ip_str);
8114 if (!peer)
8115 return CMD_WARNING_CONFIG_FAILED;
718e3744 8116
1de27621
DA
8117 route_map = route_map_lookup_warn_noexist(vty, name_str);
8118 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
718e3744 8119
d62a17ae 8120 return bgp_vty_return(vty, ret);
718e3744 8121}
8122
8123/* Unset route-map from the peer. */
d62a17ae 8124static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8125 afi_t afi, safi_t safi)
718e3744 8126{
d62a17ae 8127 int ret;
8128 struct peer *peer;
718e3744 8129
d62a17ae 8130 peer = peer_and_group_lookup_vty(vty, ip_str);
8131 if (!peer)
8132 return CMD_WARNING_CONFIG_FAILED;
718e3744 8133
d62a17ae 8134 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 8135
d62a17ae 8136 return bgp_vty_return(vty, ret);
718e3744 8137}
8138
8139DEFUN (neighbor_unsuppress_map,
8140 neighbor_unsuppress_map_cmd,
9ccf14f7 8141 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8142 NEIGHBOR_STR
8143 NEIGHBOR_ADDR_STR2
8144 "Route-map to selectively unsuppress suppressed routes\n"
8145 "Name of route map\n")
8146{
d62a17ae 8147 int idx_peer = 1;
8148 int idx_word = 3;
8149 return peer_unsuppress_map_set_vty(
8150 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8151 argv[idx_word]->arg);
718e3744 8152}
8153
d62a17ae 8154ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8155 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8156 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8157 "Route-map to selectively unsuppress suppressed routes\n"
8158 "Name of route map\n")
596c17ba 8159
718e3744 8160DEFUN (no_neighbor_unsuppress_map,
8161 no_neighbor_unsuppress_map_cmd,
9ccf14f7 8162 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 8163 NO_STR
8164 NEIGHBOR_STR
8165 NEIGHBOR_ADDR_STR2
8166 "Route-map to selectively unsuppress suppressed routes\n"
8167 "Name of route map\n")
8168{
d62a17ae 8169 int idx_peer = 2;
8170 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8171 bgp_node_afi(vty),
8172 bgp_node_safi(vty));
718e3744 8173}
6b0655a2 8174
d62a17ae 8175ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8176 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8177 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8178 "Route-map to selectively unsuppress suppressed routes\n"
8179 "Name of route map\n")
596c17ba 8180
fde246e8 8181/* Maximum number of prefix to be sent to the neighbor. */
232c75cd
CS
8182DEFUN_YANG(neighbor_maximum_prefix_out,
8183 neighbor_maximum_prefix_out_cmd,
8184 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8186 "Maximum number of prefixes to be sent to this peer\n"
8187 "Maximum no. of prefix limit\n")
fde246e8 8188{
04261dec
CS
8189 char base_xpath[XPATH_MAXLEN];
8190 char af_xpath[XPATH_MAXLEN];
8191 char attr_xpath[XPATH_MAXLEN];
fde246e8
DA
8192 int idx_peer = 1;
8193 int idx_number = 3;
fde246e8
DA
8194 afi_t afi = bgp_node_afi(vty);
8195 safi_t safi = bgp_node_safi(vty);
8196
04261dec
CS
8197 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8198 yang_afi_safi_value2identity(afi, safi));
8199 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8200 sizeof(base_xpath), af_xpath)
8201 < 0)
fde246e8
DA
8202 return CMD_WARNING_CONFIG_FAILED;
8203
04261dec
CS
8204 snprintf(attr_xpath, sizeof(attr_xpath),
8205 "/%s/prefix-limit/direction-list[direction='out']",
8206 bgp_afi_safi_get_container_str(afi, safi));
8207 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
fde246e8 8208
04261dec 8209 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
fde246e8 8210
04261dec
CS
8211 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8212 argv[idx_number]->arg);
8213
8214 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8215}
8216
232c75cd
CS
8217DEFUN_YANG(no_neighbor_maximum_prefix_out,
8218 no_neighbor_maximum_prefix_out_cmd,
8219 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8220 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8221 "Maximum number of prefixes to be sent to this peer\n")
fde246e8 8222{
04261dec
CS
8223 char base_xpath[XPATH_MAXLEN];
8224 char af_xpath[XPATH_MAXLEN];
8225 char attr_xpath[XPATH_MAXLEN];
fde246e8 8226 int idx_peer = 2;
fde246e8
DA
8227 afi_t afi = bgp_node_afi(vty);
8228 safi_t safi = bgp_node_safi(vty);
8229
04261dec
CS
8230 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8231 yang_afi_safi_value2identity(afi, safi));
8232 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8233 sizeof(base_xpath), af_xpath)
8234 < 0)
fde246e8
DA
8235 return CMD_WARNING_CONFIG_FAILED;
8236
04261dec
CS
8237 snprintf(attr_xpath, sizeof(attr_xpath),
8238 "/%s/prefix-limit/direction-list[direction='out']",
8239 bgp_afi_safi_get_container_str(afi, safi));
8240 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8241
8242 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
fde246e8 8243
04261dec 8244 return nb_cli_apply_changes(vty, base_xpath);
fde246e8
DA
8245}
8246
9cbd06e0
DA
8247/* Maximum number of prefix configuration. Prefix count is different
8248 for each peer configuration. So this configuration can be set for
718e3744 8249 each peer configuration. */
232c75cd
CS
8250DEFUN_YANG(neighbor_maximum_prefix,
8251 neighbor_maximum_prefix_cmd,
8252 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8253 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8254 "Maximum number of prefix accept from this peer\n"
8255 "maximum no. of prefix limit\n"
8256 "Force checking all received routes not only accepted\n")
718e3744 8257{
d62a17ae 8258 int idx_peer = 1;
8259 int idx_number = 3;
9cbd06e0 8260 int idx_force = 0;
04261dec
CS
8261 char base_xpath[XPATH_MAXLEN];
8262 char af_xpath[XPATH_MAXLEN];
8263 char attr_xpath[XPATH_MAXLEN];
8264 afi_t afi = bgp_node_afi(vty);
8265 safi_t safi = bgp_node_safi(vty);
8266
8267 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8268 yang_afi_safi_value2identity(afi, safi));
8269 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8270 sizeof(base_xpath), af_xpath)
8271 < 0)
8272 return CMD_WARNING_CONFIG_FAILED;
8273
8274 snprintf(attr_xpath, sizeof(attr_xpath),
8275 "/%s/prefix-limit/direction-list[direction='in']",
8276 bgp_afi_safi_get_container_str(afi, safi));
8277 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8278
8279 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9cbd06e0 8280
04261dec
CS
8281 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8282 argv[idx_number]->arg);
9cbd06e0 8283 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8284 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8285 "true");
9cbd06e0 8286
04261dec 8287 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8288}
8289
d62a17ae 8290ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8291 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
d62a17ae 8292 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8293 "Maximum number of prefix accept from this peer\n"
9cbd06e0
DA
8294 "maximum no. of prefix limit\n"
8295 "Force checking all received routes not only accepted\n")
596c17ba 8296
232c75cd
CS
8297DEFUN_YANG(neighbor_maximum_prefix_threshold,
8298 neighbor_maximum_prefix_threshold_cmd,
8299 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8300 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8301 "Maximum number of prefix accept from this peer\n"
8302 "maximum no. of prefix limit\n"
8303 "Threshold value (%) at which to generate a warning msg\n"
8304 "Force checking all received routes not only accepted\n")
e0701b79 8305{
d62a17ae 8306 int idx_peer = 1;
8307 int idx_number = 3;
8308 int idx_number_2 = 4;
9cbd06e0 8309 int idx_force = 0;
04261dec
CS
8310 char base_xpath[XPATH_MAXLEN];
8311 char af_xpath[XPATH_MAXLEN];
8312 char attr_xpath[XPATH_MAXLEN];
8313 afi_t afi = bgp_node_afi(vty);
8314 safi_t safi = bgp_node_safi(vty);
8315
8316 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8317 yang_afi_safi_value2identity(afi, safi));
8318 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8319 sizeof(base_xpath), af_xpath)
8320 < 0)
8321 return CMD_WARNING_CONFIG_FAILED;
8322
8323 snprintf(attr_xpath, sizeof(attr_xpath),
8324 "/%s/prefix-limit/direction-list[direction='in']",
8325 bgp_afi_safi_get_container_str(afi, safi));
8326 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8327
8328 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8329
8330 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8331 argv[idx_number]->arg);
8332
8333 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8334 NB_OP_MODIFY, argv[idx_number_2]->arg);
9cbd06e0
DA
8335
8336 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8337 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8338 "true");
9cbd06e0 8339
04261dec 8340 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8341}
e0701b79 8342
d62a17ae 8343ALIAS_HIDDEN(
8344 neighbor_maximum_prefix_threshold,
8345 neighbor_maximum_prefix_threshold_hidden_cmd,
9cbd06e0 8346 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
d62a17ae 8347 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8348 "Maximum number of prefix accept from this peer\n"
8349 "maximum no. of prefix limit\n"
9cbd06e0
DA
8350 "Threshold value (%) at which to generate a warning msg\n"
8351 "Force checking all received routes not only accepted\n")
596c17ba 8352
232c75cd
CS
8353DEFUN_YANG(neighbor_maximum_prefix_warning,
8354 neighbor_maximum_prefix_warning_cmd,
8355 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8356 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8357 "Maximum number of prefix accept from this peer\n"
8358 "maximum no. of prefix limit\n"
8359 "Only give warning message when limit is exceeded\n"
8360 "Force checking all received routes not only accepted\n")
718e3744 8361{
d62a17ae 8362 int idx_peer = 1;
8363 int idx_number = 3;
9cbd06e0 8364 int idx_force = 0;
04261dec
CS
8365 char base_xpath[XPATH_MAXLEN];
8366 char af_xpath[XPATH_MAXLEN];
8367 char attr_xpath[XPATH_MAXLEN];
8368 afi_t afi = bgp_node_afi(vty);
8369 safi_t safi = bgp_node_safi(vty);
8370
8371 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8372 yang_afi_safi_value2identity(afi, safi));
8373 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8374 sizeof(base_xpath), af_xpath)
8375 < 0)
8376 return CMD_WARNING_CONFIG_FAILED;
9cbd06e0 8377
04261dec
CS
8378 snprintf(attr_xpath, sizeof(attr_xpath),
8379 "/%s/prefix-limit/direction-list[direction='in']",
8380 bgp_afi_safi_get_container_str(afi, safi));
8381 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8382
8383 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8384
8385 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8386 argv[idx_number]->arg);
8387
8388 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8389 "true");
9cbd06e0 8390 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8391 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8392 "true");
9cbd06e0 8393
04261dec 8394 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8395}
8396
d62a17ae 8397ALIAS_HIDDEN(
8398 neighbor_maximum_prefix_warning,
8399 neighbor_maximum_prefix_warning_hidden_cmd,
9cbd06e0 8400 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
d62a17ae 8401 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8402 "Maximum number of prefix accept from this peer\n"
8403 "maximum no. of prefix limit\n"
9cbd06e0
DA
8404 "Only give warning message when limit is exceeded\n"
8405 "Force checking all received routes not only accepted\n")
596c17ba 8406
232c75cd
CS
8407DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8408 neighbor_maximum_prefix_threshold_warning_cmd,
8409 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8410 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8411 "Maximum number of prefix accept from this peer\n"
8412 "maximum no. of prefix limit\n"
8413 "Threshold value (%) at which to generate a warning msg\n"
8414 "Only give warning message when limit is exceeded\n"
8415 "Force checking all received routes not only accepted\n")
e0701b79 8416{
d62a17ae 8417 int idx_peer = 1;
8418 int idx_number = 3;
8419 int idx_number_2 = 4;
9cbd06e0 8420 int idx_force = 0;
04261dec
CS
8421 char base_xpath[XPATH_MAXLEN];
8422 char af_xpath[XPATH_MAXLEN];
8423 char attr_xpath[XPATH_MAXLEN];
8424 afi_t afi = bgp_node_afi(vty);
8425 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8426
04261dec
CS
8427 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8428 yang_afi_safi_value2identity(afi, safi));
8429 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8430 sizeof(base_xpath), af_xpath)
8431 < 0)
8432 return CMD_WARNING_CONFIG_FAILED;
8433
8434 snprintf(attr_xpath, sizeof(attr_xpath),
8435 "/%s/prefix-limit/direction-list[direction='in']",
8436 bgp_afi_safi_get_container_str(afi, safi));
8437 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8438
8439 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8440
8441 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8442 argv[idx_number]->arg);
8443 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8444 NB_OP_MODIFY, argv[idx_number_2]->arg);
8445 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8446 "true");
9cbd06e0 8447 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8448 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8449 "true");
9cbd06e0 8450
04261dec 8451 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8452}
8453
d62a17ae 8454ALIAS_HIDDEN(
8455 neighbor_maximum_prefix_threshold_warning,
8456 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
9cbd06e0 8457 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
d62a17ae 8458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8459 "Maximum number of prefix accept from this peer\n"
8460 "maximum no. of prefix limit\n"
8461 "Threshold value (%) at which to generate a warning msg\n"
9cbd06e0
DA
8462 "Only give warning message when limit is exceeded\n"
8463 "Force checking all received routes not only accepted\n")
596c17ba 8464
232c75cd
CS
8465DEFUN_YANG(neighbor_maximum_prefix_restart,
8466 neighbor_maximum_prefix_restart_cmd,
8467 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8468 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8469 "Maximum number of prefix accept from this peer\n"
8470 "maximum no. of prefix limit\n"
8471 "Restart bgp connection after limit is exceeded\n"
8472 "Restart interval in minutes\n"
8473 "Force checking all received routes not only accepted\n")
0a486e5f 8474{
d62a17ae 8475 int idx_peer = 1;
8476 int idx_number = 3;
8477 int idx_number_2 = 5;
9cbd06e0 8478 int idx_force = 0;
04261dec
CS
8479 char base_xpath[XPATH_MAXLEN];
8480 char af_xpath[XPATH_MAXLEN];
8481 char attr_xpath[XPATH_MAXLEN];
8482 afi_t afi = bgp_node_afi(vty);
8483 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8484
04261dec
CS
8485 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8486 yang_afi_safi_value2identity(afi, safi));
8487 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8488 sizeof(base_xpath), af_xpath)
8489 < 0)
8490 return CMD_WARNING_CONFIG_FAILED;
8491
8492 snprintf(attr_xpath, sizeof(attr_xpath),
8493 "/%s/prefix-limit/direction-list[direction='in']",
8494 bgp_afi_safi_get_container_str(afi, safi));
8495 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8496
8497 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8498
8499 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8500 argv[idx_number]->arg);
8501 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8502 argv[idx_number_2]->arg);
9cbd06e0 8503 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8504 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8505 "true");
9cbd06e0 8506
04261dec 8507 return nb_cli_apply_changes(vty, base_xpath);
0a486e5f 8508}
8509
d62a17ae 8510ALIAS_HIDDEN(
8511 neighbor_maximum_prefix_restart,
8512 neighbor_maximum_prefix_restart_hidden_cmd,
9cbd06e0 8513 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
d62a17ae 8514 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8515 "Maximum number of prefix accept from this peer\n"
8516 "maximum no. of prefix limit\n"
8517 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8518 "Restart interval in minutes\n"
8519 "Force checking all received routes not only accepted\n")
596c17ba 8520
232c75cd
CS
8521DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8522 neighbor_maximum_prefix_threshold_restart_cmd,
8523 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8524 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8525 "Maximum number of prefixes to accept from this peer\n"
8526 "maximum no. of prefix limit\n"
8527 "Threshold value (%) at which to generate a warning msg\n"
8528 "Restart bgp connection after limit is exceeded\n"
8529 "Restart interval in minutes\n"
8530 "Force checking all received routes not only accepted\n")
0a486e5f 8531{
d62a17ae 8532 int idx_peer = 1;
8533 int idx_number = 3;
8534 int idx_number_2 = 4;
8535 int idx_number_3 = 6;
9cbd06e0 8536 int idx_force = 0;
04261dec
CS
8537 char base_xpath[XPATH_MAXLEN];
8538 char af_xpath[XPATH_MAXLEN];
8539 char attr_xpath[XPATH_MAXLEN];
8540 afi_t afi = bgp_node_afi(vty);
8541 safi_t safi = bgp_node_safi(vty);
9cbd06e0 8542
04261dec
CS
8543 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8544 yang_afi_safi_value2identity(afi, safi));
8545 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8546 sizeof(base_xpath), af_xpath)
8547 < 0)
8548 return CMD_WARNING_CONFIG_FAILED;
8549
8550 snprintf(attr_xpath, sizeof(attr_xpath),
8551 "/%s/prefix-limit/direction-list[direction='in']",
8552 bgp_afi_safi_get_container_str(afi, safi));
8553 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8554
8555 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8556
8557 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8558 argv[idx_number]->arg);
8559 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8560 NB_OP_MODIFY, argv[idx_number_2]->arg);
8561 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8562 argv[idx_number_3]->arg);
9cbd06e0 8563 if (argv_find(argv, argc, "force", &idx_force))
04261dec
CS
8564 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8565 "true");
9cbd06e0 8566
04261dec 8567 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 8568}
8569
8570ALIAS_HIDDEN(
8571 neighbor_maximum_prefix_threshold_restart,
8572 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
9cbd06e0 8573 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
d62a17ae 8574 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8575 "Maximum number of prefixes to accept from this peer\n"
8576 "maximum no. of prefix limit\n"
8577 "Threshold value (%) at which to generate a warning msg\n"
8578 "Restart bgp connection after limit is exceeded\n"
9cbd06e0
DA
8579 "Restart interval in minutes\n"
8580 "Force checking all received routes not only accepted\n")
596c17ba 8581
232c75cd
CS
8582DEFUN_YANG(no_neighbor_maximum_prefix,
8583 no_neighbor_maximum_prefix_cmd,
8584 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8585 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8586 "Maximum number of prefixes to accept from this peer\n"
8587 "maximum no. of prefix limit\n"
8588 "Threshold value (%) at which to generate a warning msg\n"
8589 "Restart bgp connection after limit is exceeded\n"
8590 "Restart interval in minutes\n"
8591 "Only give warning message when limit is exceeded\n"
8592 "Force checking all received routes not only accepted\n")
718e3744 8593{
d62a17ae 8594 int idx_peer = 2;
04261dec
CS
8595 char base_xpath[XPATH_MAXLEN];
8596 char af_xpath[XPATH_MAXLEN];
8597 char attr_xpath[XPATH_MAXLEN];
8598 afi_t afi = bgp_node_afi(vty);
8599 safi_t safi = bgp_node_safi(vty);
8600
8601 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8602 yang_afi_safi_value2identity(afi, safi));
8603 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8604 sizeof(base_xpath), af_xpath)
8605 < 0)
8606 return CMD_WARNING_CONFIG_FAILED;
8607
8608 snprintf(attr_xpath, sizeof(attr_xpath),
8609 "/%s/prefix-limit/direction-list[direction='in']",
8610 bgp_afi_safi_get_container_str(afi, safi));
8611 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8612
8613 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8614
8615 return nb_cli_apply_changes(vty, base_xpath);
718e3744 8616}
e52702f2 8617
d62a17ae 8618ALIAS_HIDDEN(
8619 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
9cbd06e0 8620 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
d62a17ae 8621 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8622 "Maximum number of prefixes to accept from this peer\n"
8623 "maximum no. of prefix limit\n"
8624 "Threshold value (%) at which to generate a warning msg\n"
8625 "Restart bgp connection after limit is exceeded\n"
8626 "Restart interval in minutes\n"
9cbd06e0
DA
8627 "Only give warning message when limit is exceeded\n"
8628 "Force checking all received routes not only accepted\n")
596c17ba 8629
718e3744 8630
718e3744 8631/* "neighbor allowas-in" */
8632DEFUN (neighbor_allowas_in,
8633 neighbor_allowas_in_cmd,
fd8503f5 8634 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8635 NEIGHBOR_STR
8636 NEIGHBOR_ADDR_STR2
31500417 8637 "Accept as-path with my AS present in it\n"
f79f7a7b 8638 "Number of occurrences of AS number\n"
fd8503f5 8639 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8640{
d62a17ae 8641 int idx_peer = 1;
8642 int idx_number_origin = 3;
8643 int ret;
8644 int origin = 0;
8645 struct peer *peer;
8646 int allow_num = 0;
8647
8648 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8649 if (!peer)
8650 return CMD_WARNING_CONFIG_FAILED;
8651
8652 if (argc <= idx_number_origin)
8653 allow_num = 3;
8654 else {
8655 if (argv[idx_number_origin]->type == WORD_TKN)
8656 origin = 1;
8657 else
8658 allow_num = atoi(argv[idx_number_origin]->arg);
8659 }
8660
8661 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8662 allow_num, origin);
8663
8664 return bgp_vty_return(vty, ret);
8665}
8666
8667ALIAS_HIDDEN(
8668 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8669 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8671 "Accept as-path with my AS present in it\n"
f79f7a7b 8672 "Number of occurrences of AS number\n"
d62a17ae 8673 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8674
718e3744 8675DEFUN (no_neighbor_allowas_in,
8676 no_neighbor_allowas_in_cmd,
fd8503f5 8677 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 8678 NO_STR
8679 NEIGHBOR_STR
8680 NEIGHBOR_ADDR_STR2
8334fd5a 8681 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8682 "Number of occurrences of AS number\n"
fd8503f5 8683 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 8684{
d62a17ae 8685 int idx_peer = 2;
8686 int ret;
8687 struct peer *peer;
718e3744 8688
d62a17ae 8689 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8690 if (!peer)
8691 return CMD_WARNING_CONFIG_FAILED;
718e3744 8692
d62a17ae 8693 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8694 bgp_node_safi(vty));
718e3744 8695
d62a17ae 8696 return bgp_vty_return(vty, ret);
718e3744 8697}
6b0655a2 8698
d62a17ae 8699ALIAS_HIDDEN(
8700 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8701 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8702 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8703 "allow local ASN appears in aspath attribute\n"
f79f7a7b 8704 "Number of occurrences of AS number\n"
d62a17ae 8705 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 8706
f4b8ec07
CS
8707DEFUN_YANG (neighbor_ttl_security,
8708 neighbor_ttl_security_cmd,
8709 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8710 NEIGHBOR_STR
8711 NEIGHBOR_ADDR_STR2
8712 "BGP ttl-security parameters\n"
8713 "Specify the maximum number of hops to the BGP peer\n"
8714 "Number of hops to BGP peer\n")
fa411a21 8715{
d62a17ae 8716 int idx_peer = 1;
8717 int idx_number = 4;
f4b8ec07 8718 char base_xpath[XPATH_MAXLEN];
d62a17ae 8719
f4b8ec07
CS
8720 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8721 sizeof(base_xpath), NULL)
8722 < 0)
d62a17ae 8723 return CMD_WARNING_CONFIG_FAILED;
8724
f4b8ec07
CS
8725 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8726 argv[idx_number]->arg);
7ebe625c 8727
f4b8ec07 8728 return nb_cli_apply_changes(vty, base_xpath);
fa411a21
NH
8729}
8730
232c75cd
CS
8731DEFUN_YANG(no_neighbor_ttl_security,
8732 no_neighbor_ttl_security_cmd,
8733 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8734 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8735 "BGP ttl-security parameters\n"
8736 "Specify the maximum number of hops to the BGP peer\n"
8737 "Number of hops to BGP peer\n")
fa411a21 8738{
d62a17ae 8739 int idx_peer = 2;
f4b8ec07 8740 char base_xpath[XPATH_MAXLEN];
fa411a21 8741
f4b8ec07
CS
8742 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8743 sizeof(base_xpath), NULL)
8744 < 0)
d62a17ae 8745 return CMD_WARNING_CONFIG_FAILED;
fa411a21 8746
f4b8ec07
CS
8747 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8748
8749 return nb_cli_apply_changes(vty, base_xpath);
fa411a21 8750}
6b0655a2 8751
adbac85e
DW
8752DEFUN (neighbor_addpath_tx_all_paths,
8753 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8754 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8755 NEIGHBOR_STR
8756 NEIGHBOR_ADDR_STR2
8757 "Use addpath to advertise all paths to a neighbor\n")
8758{
d62a17ae 8759 int idx_peer = 1;
8760 struct peer *peer;
adbac85e 8761
d62a17ae 8762 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8763 if (!peer)
8764 return CMD_WARNING_CONFIG_FAILED;
adbac85e 8765
dcc68b5e
MS
8766 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8767 BGP_ADDPATH_ALL);
8768 return CMD_SUCCESS;
adbac85e
DW
8769}
8770
d62a17ae 8771ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8772 neighbor_addpath_tx_all_paths_hidden_cmd,
8773 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8774 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8775 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8776
adbac85e
DW
8777DEFUN (no_neighbor_addpath_tx_all_paths,
8778 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 8779 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
8780 NO_STR
8781 NEIGHBOR_STR
8782 NEIGHBOR_ADDR_STR2
8783 "Use addpath to advertise all paths to a neighbor\n")
8784{
d62a17ae 8785 int idx_peer = 2;
dcc68b5e
MS
8786 struct peer *peer;
8787
8788 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8789 if (!peer)
8790 return CMD_WARNING_CONFIG_FAILED;
8791
8792 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8793 != BGP_ADDPATH_ALL) {
8794 vty_out(vty,
8795 "%% Peer not currently configured to transmit all paths.");
8796 return CMD_WARNING_CONFIG_FAILED;
8797 }
8798
8799 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8800 BGP_ADDPATH_NONE);
8801
8802 return CMD_SUCCESS;
adbac85e
DW
8803}
8804
d62a17ae 8805ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8806 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8807 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8808 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8809 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 8810
06370dac
DW
8811DEFUN (neighbor_addpath_tx_bestpath_per_as,
8812 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8813 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8814 NEIGHBOR_STR
8815 NEIGHBOR_ADDR_STR2
8816 "Use addpath to advertise the bestpath per each neighboring AS\n")
8817{
d62a17ae 8818 int idx_peer = 1;
8819 struct peer *peer;
06370dac 8820
d62a17ae 8821 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8822 if (!peer)
8823 return CMD_WARNING_CONFIG_FAILED;
06370dac 8824
dcc68b5e
MS
8825 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8826 BGP_ADDPATH_BEST_PER_AS);
8827
8828 return CMD_SUCCESS;
06370dac
DW
8829}
8830
d62a17ae 8831ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8832 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8833 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8834 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8835 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8836
06370dac
DW
8837DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8838 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 8839 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
8840 NO_STR
8841 NEIGHBOR_STR
8842 NEIGHBOR_ADDR_STR2
8843 "Use addpath to advertise the bestpath per each neighboring AS\n")
8844{
d62a17ae 8845 int idx_peer = 2;
dcc68b5e
MS
8846 struct peer *peer;
8847
8848 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8849 if (!peer)
8850 return CMD_WARNING_CONFIG_FAILED;
8851
8852 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8853 != BGP_ADDPATH_BEST_PER_AS) {
8854 vty_out(vty,
8855 "%% Peer not currently configured to transmit all best path per as.");
8856 return CMD_WARNING_CONFIG_FAILED;
8857 }
8858
8859 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8860 BGP_ADDPATH_NONE);
8861
8862 return CMD_SUCCESS;
06370dac
DW
8863}
8864
d62a17ae 8865ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8866 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8867 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8868 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8869 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 8870
2b31007c
RZ
8871DEFPY(
8872 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8873 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8874 NEIGHBOR_STR
8875 NEIGHBOR_ADDR_STR2
8876 "Detect AS loops before sending to neighbor\n")
8877{
8878 struct peer *peer;
8879
8880 peer = peer_and_group_lookup_vty(vty, neighbor);
8881 if (!peer)
8882 return CMD_WARNING_CONFIG_FAILED;
8883
8884 peer->as_path_loop_detection = true;
8885
8886 return CMD_SUCCESS;
8887}
8888
8889DEFPY(
8890 no_neighbor_aspath_loop_detection,
8891 no_neighbor_aspath_loop_detection_cmd,
8892 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8893 NO_STR
8894 NEIGHBOR_STR
8895 NEIGHBOR_ADDR_STR2
8896 "Detect AS loops before sending to neighbor\n")
8897{
8898 struct peer *peer;
8899
8900 peer = peer_and_group_lookup_vty(vty, neighbor);
8901 if (!peer)
8902 return CMD_WARNING_CONFIG_FAILED;
8903
8904 peer->as_path_loop_detection = false;
8905
8906 return CMD_SUCCESS;
8907}
8908
0221327c
DS
8909DEFPY(neighbor_damp,
8910 neighbor_damp_cmd,
8911 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8912 NEIGHBOR_STR
8913 NEIGHBOR_ADDR_STR2
8914 "Enable neighbor route-flap dampening\n"
8915 "Half-life time for the penalty\n"
8916 "Value to start reusing a route\n"
8917 "Value to start suppressing a route\n"
8918 "Maximum duration to suppress a stable route\n")
8919{
8920 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8921
8922 if (!peer)
8923 return CMD_WARNING_CONFIG_FAILED;
8924 if (!half)
8925 half = DEFAULT_HALF_LIFE;
8926 if (!reuse) {
8927 reuse = DEFAULT_REUSE;
8928 suppress = DEFAULT_SUPPRESS;
8929 max = half * 4;
8930 }
8931 if (suppress < reuse) {
8932 vty_out(vty,
8933 "Suppress value cannot be less than reuse value\n");
8934 return CMD_WARNING_CONFIG_FAILED;
8935 }
8936 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8937 half * 60, reuse, suppress, max * 60);
8938 return CMD_SUCCESS;
8939}
8940
8941DEFPY(no_neighbor_damp,
8942 no_neighbor_damp_cmd,
8943 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8944 NO_STR
8945 NEIGHBOR_STR
8946 NEIGHBOR_ADDR_STR2
8947 "Enable neighbor route-flap dampening\n"
8948 "Half-life time for the penalty\n"
8949 "Value to start reusing a route\n"
8950 "Value to start suppressing a route\n"
8951 "Maximum duration to suppress a stable route\n")
8952{
8953 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8954
8955 if (!peer)
8956 return CMD_WARNING_CONFIG_FAILED;
8957 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8958 return CMD_SUCCESS;
8959}
8960
8961DEFPY (show_ip_bgp_neighbor_damp_param,
8962 show_ip_bgp_neighbor_damp_param_cmd,
8963 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8964 SHOW_STR
8965 IP_STR
8966 BGP_STR
8967 BGP_AFI_HELP_STR
8968 "Address Family modifier\n"
8969 NEIGHBOR_STR
8970 NEIGHBOR_ADDR_STR2
8971 "Neighbor route-flap dampening information\n"
8972 "Display detail of configured dampening parameters\n"
8973 JSON_STR)
8974{
8975 bool use_json = false;
8976 int idx = 0;
8977 afi_t afi = AFI_IP;
8978 safi_t safi = SAFI_UNICAST;
8979 struct peer *peer;
8980
8981 if (argv_find(argv, argc, "ip", &idx))
8982 afi = AFI_IP;
8983 if (argv_find(argv, argc, "ipv4", &idx))
8984 afi = AFI_IP;
8985 if (argv_find(argv, argc, "ipv6", &idx))
8986 afi = AFI_IP6;
8987 peer = peer_and_group_lookup_vty(vty, neighbor);
8988 if (!peer)
8989 return CMD_WARNING;
8990 if (json)
8991 use_json = true;
8992 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
8993 return CMD_SUCCESS;
8994}
8995
b9c7bc5a 8996static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
c6423c31 8997 struct ecommunity **list, bool is_rt6)
ddb5b488 8998{
b9c7bc5a
PZ
8999 struct ecommunity *ecom = NULL;
9000 struct ecommunity *ecomadd;
ddb5b488 9001
b9c7bc5a 9002 for (; argc; --argc, ++argv) {
9a659715
PG
9003 if (is_rt6)
9004 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
9005 ECOMMUNITY_ROUTE_TARGET,
9006 0);
9007 else
9008 ecomadd = ecommunity_str2com(argv[0]->arg,
9009 ECOMMUNITY_ROUTE_TARGET,
9010 0);
b9c7bc5a
PZ
9011 if (!ecomadd) {
9012 vty_out(vty, "Malformed community-list value\n");
9013 if (ecom)
9014 ecommunity_free(&ecom);
9015 return CMD_WARNING_CONFIG_FAILED;
9016 }
ddb5b488 9017
b9c7bc5a
PZ
9018 if (ecom) {
9019 ecommunity_merge(ecom, ecomadd);
9020 ecommunity_free(&ecomadd);
9021 } else {
9022 ecom = ecomadd;
9023 }
9024 }
9025
9026 if (*list) {
9027 ecommunity_free(&*list);
ddb5b488 9028 }
b9c7bc5a
PZ
9029 *list = ecom;
9030
9031 return CMD_SUCCESS;
ddb5b488
PZ
9032}
9033
37a87b8f
CS
9034bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
9035 bool v2vimport, char *errmsg, size_t errmsg_len)
9036{
9037 if (!v2vimport) {
9038 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9039 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9040 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9041 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9042 snprintf(
9043 errmsg, errmsg_len, "%s",
9044 "%% error: Please unconfigure import vrf commands before using vpn commands");
9045 return false;
9046 }
9047 } else {
9048 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9049 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9050 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9051 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9052 snprintf(
9053 errmsg, errmsg_len, "%s",
9054 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
9055 return false;
9056 }
9057 }
9058 return true;
9059}
9060
0ca70ba5
DS
9061/*
9062 * v2vimport is true if we are handling a `import vrf ...` command
9063 */
9064static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
ddb5b488 9065{
0ca70ba5
DS
9066 afi_t afi;
9067
ddb5b488 9068 switch (vty->node) {
b9c7bc5a 9069 case BGP_IPV4_NODE:
0ca70ba5
DS
9070 afi = AFI_IP;
9071 break;
b9c7bc5a 9072 case BGP_IPV6_NODE:
0ca70ba5
DS
9073 afi = AFI_IP6;
9074 break;
ddb5b488
PZ
9075 default:
9076 vty_out(vty,
b9c7bc5a 9077 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
69b07479 9078 return AFI_MAX;
ddb5b488 9079 }
69b07479 9080
0ca70ba5
DS
9081 if (!v2vimport) {
9082 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9083 BGP_CONFIG_VRF_TO_VRF_IMPORT)
9084 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9085 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9086 vty_out(vty,
9087 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9088 return AFI_MAX;
9089 }
9090 } else {
9091 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9092 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9093 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9094 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9095 vty_out(vty,
9096 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9097 return AFI_MAX;
9098 }
9099 }
9100 return afi;
ddb5b488
PZ
9101}
9102
37a87b8f
CS
9103DEFPY_YANG(
9104 af_rd_vpn_export,
9105 af_rd_vpn_export_cmd,
9106 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9107 NO_STR
9108 "Specify route distinguisher\n"
9109 "Between current address-family and vpn\n"
9110 "For routes leaked from current address-family to vpn\n"
9111 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
ddb5b488 9112{
37a87b8f 9113 char base_xpath[XPATH_MAXLEN];
ddb5b488 9114 afi_t afi;
37a87b8f 9115 safi_t safi;
b9c7bc5a 9116 int idx = 0;
b9c7bc5a 9117
37a87b8f
CS
9118 afi = bgp_node_afi(vty);
9119 safi = bgp_node_safi(vty);
ddb5b488 9120
37a87b8f
CS
9121 snprintf(
9122 base_xpath, sizeof(base_xpath),
9123 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9124 yang_afi_safi_value2identity(afi, safi),
9125 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9126
37a87b8f
CS
9127 if (argv_find(argv, argc, "no", &idx))
9128 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9129 else
9130 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
ddb5b488 9131
37a87b8f
CS
9132 return nb_cli_apply_changes(vty, base_xpath);
9133}
ddb5b488 9134
37a87b8f
CS
9135void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9136 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9137{
9138 int indent = 2;
69b07479 9139
37a87b8f
CS
9140 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9141 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9142}
9143
b9c7bc5a
PZ
9144ALIAS (af_rd_vpn_export,
9145 af_no_rd_vpn_export_cmd,
9146 "no rd vpn export",
ddb5b488 9147 NO_STR
b9c7bc5a
PZ
9148 "Specify route distinguisher\n"
9149 "Between current address-family and vpn\n"
9150 "For routes leaked from current address-family to vpn\n")
ddb5b488 9151
b9c7bc5a
PZ
9152DEFPY (af_label_vpn_export,
9153 af_label_vpn_export_cmd,
e70e9f8e 9154 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
b9c7bc5a 9155 NO_STR
ddb5b488 9156 "label value for VRF\n"
b9c7bc5a
PZ
9157 "Between current address-family and vpn\n"
9158 "For routes leaked from current address-family to vpn\n"
e70e9f8e
PZ
9159 "Label Value <0-1048575>\n"
9160 "Automatically assign a label\n")
ddb5b488
PZ
9161{
9162 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 9163 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488 9164 afi_t afi;
b9c7bc5a 9165 int idx = 0;
c6423c31 9166 bool yes = true;
b9c7bc5a
PZ
9167
9168 if (argv_find(argv, argc, "no", &idx))
c6423c31 9169 yes = false;
ddb5b488 9170
21a16cc2
PZ
9171 /* If "no ...", squash trailing parameter */
9172 if (!yes)
9173 label_auto = NULL;
9174
e70e9f8e
PZ
9175 if (yes) {
9176 if (!label_auto)
9177 label = label_val; /* parser should force unsigned */
9178 }
ddb5b488 9179
0ca70ba5 9180 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9181 if (afi == AFI_MAX)
9182 return CMD_WARNING_CONFIG_FAILED;
e70e9f8e 9183
e70e9f8e 9184
69b07479
DS
9185 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9186 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9187 /* no change */
9188 return CMD_SUCCESS;
e70e9f8e 9189
69b07479
DS
9190 /*
9191 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9192 */
9193 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9194 bgp_get_default(), bgp);
9195
9196 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9197 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9198
9199 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9200
9201 /*
9202 * label has previously been automatically
9203 * assigned by labelpool: release it
9204 *
9205 * NB if tovpn_label == MPLS_LABEL_NONE it
9206 * means the automatic assignment is in flight
9207 * and therefore the labelpool callback must
9208 * detect that the auto label is not needed.
9209 */
9210
9211 bgp_lp_release(LP_TYPE_VRF,
9212 &bgp->vpn_policy[afi],
9213 bgp->vpn_policy[afi].tovpn_label);
e70e9f8e 9214 }
69b07479
DS
9215 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9216 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9217 }
ddb5b488 9218
69b07479
DS
9219 bgp->vpn_policy[afi].tovpn_label = label;
9220 if (label_auto) {
9221 SET_FLAG(bgp->vpn_policy[afi].flags,
9222 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9223 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9224 vpn_leak_label_callback);
ddb5b488
PZ
9225 }
9226
69b07479
DS
9227 /* post-change: re-export vpn routes */
9228 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9229 bgp_get_default(), bgp);
9230
0d020cd6 9231 hook_call(bgp_snmp_update_last_changed, bgp);
ddb5b488
PZ
9232 return CMD_SUCCESS;
9233}
9234
b72c9e14
HS
9235DEFPY (af_sid_vpn_export,
9236 af_sid_vpn_export_cmd,
9237 "[no] sid vpn export <(1-255)$sid_idx|auto$sid_auto>",
9238 NO_STR
9239 "sid value for VRF\n"
9240 "Between current address-family and vpn\n"
9241 "For routes leaked from current address-family to vpn\n"
9242 "Sid allocation index\n"
9243 "Automatically assign a label\n")
9244{
9245 VTY_DECLVAR_CONTEXT(bgp, bgp);
9246 afi_t afi;
9247 int debug = 0;
9248 int idx = 0;
9249 bool yes = true;
9250
9251 if (argv_find(argv, argc, "no", &idx))
9252 yes = false;
9253 debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
9254 BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
9255
9256 afi = vpn_policy_getafi(vty, bgp, false);
9257 if (afi == AFI_MAX)
9258 return CMD_WARNING_CONFIG_FAILED;
9259
9260 if (!yes) {
9261 /* implement me */
9262 vty_out(vty, "It's not implemented");
9263 return CMD_WARNING_CONFIG_FAILED;
9264 }
9265
9266 /* skip when it's already configured */
9267 if ((sid_idx != 0 && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9268 || (sid_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9269 BGP_VPN_POLICY_TOVPN_SID_AUTO)))
9270 return CMD_SUCCESS;
9271
9272 /* mode change between sid_idx and sid_auto isn't supported.
9273 * user must negate sid vpn export when they want to change
9274 * the mode */
9275 if ((sid_auto && bgp->vpn_policy[afi].tovpn_sid_index != 0)
9276 || (sid_idx != 0 && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9277 BGP_VPN_POLICY_TOVPN_SID_AUTO))) {
9278 vty_out(vty, "it's already configured as %s.\n",
9279 sid_auto ? "auto-mode" : "idx-mode");
9280 return CMD_WARNING_CONFIG_FAILED;
9281 }
9282
9283 /* pre-change */
9284 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9285 bgp_get_default(), bgp);
9286
9287 if (sid_auto) {
9288 /* SID allocation auto-mode */
9289 if (debug)
9290 zlog_debug("%s: auto sid alloc.", __func__);
9291 SET_FLAG(bgp->vpn_policy[afi].flags,
9292 BGP_VPN_POLICY_TOVPN_SID_AUTO);
9293 } else {
9294 /* SID allocation index-mode */
9295 if (debug)
9296 zlog_debug("%s: idx %ld sid alloc.", __func__, sid_idx);
9297 bgp->vpn_policy[afi].tovpn_sid_index = sid_idx;
9298 }
9299
9300 /* post-change */
9301 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9302 bgp_get_default(), bgp);
9303 return CMD_SUCCESS;
9304}
9305
b9c7bc5a
PZ
9306ALIAS (af_label_vpn_export,
9307 af_no_label_vpn_export_cmd,
9308 "no label vpn export",
9309 NO_STR
9310 "label value for VRF\n"
9311 "Between current address-family and vpn\n"
9312 "For routes leaked from current address-family to vpn\n")
ddb5b488 9313
37a87b8f 9314DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 9315 af_nexthop_vpn_export_cmd,
8c85ca28 9316 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9317 NO_STR
ddb5b488 9318 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9319 "Between current address-family and vpn\n"
9320 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9321 "IPv4 prefix\n"
9322 "IPv6 prefix\n")
9323{
37a87b8f 9324 char base_xpath[XPATH_MAXLEN];
ddb5b488 9325 afi_t afi;
37a87b8f
CS
9326 safi_t safi;
9327 int idx = 0;
ddb5b488
PZ
9328 struct prefix p;
9329
8c85ca28
QY
9330 if (!no) {
9331 if (!nexthop_su) {
9332 vty_out(vty, "%% Nexthop required\n");
9333 return CMD_WARNING_CONFIG_FAILED;
9334 }
8c85ca28 9335 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9336 return CMD_WARNING_CONFIG_FAILED;
9337 }
ddb5b488 9338
37a87b8f
CS
9339 afi = bgp_node_afi(vty);
9340 safi = bgp_node_safi(vty);
ddb5b488 9341
37a87b8f
CS
9342 snprintf(
9343 base_xpath, sizeof(base_xpath),
9344 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9345 yang_afi_safi_value2identity(afi, safi),
9346 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9347
37a87b8f
CS
9348 if (argv_find(argv, argc, "no", &idx))
9349 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9350 else
9351 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9352 nexthop_su_str);
ddb5b488 9353
37a87b8f
CS
9354 return nb_cli_apply_changes(vty, base_xpath);
9355}
69b07479 9356
37a87b8f
CS
9357void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9358 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9359{
9360 int indent = 2;
9361
9362 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9363 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9364}
9365
b9c7bc5a 9366static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9367{
b9c7bc5a
PZ
9368 if (!strcmp(dstr, "import")) {
9369 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9370 } else if (!strcmp(dstr, "export")) {
9371 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9372 } else if (!strcmp(dstr, "both")) {
9373 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9374 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9375 } else {
9376 vty_out(vty, "%% direction parse error\n");
9377 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9378 }
ddb5b488
PZ
9379 return CMD_SUCCESS;
9380}
9381
b9c7bc5a
PZ
9382DEFPY (af_rt_vpn_imexport,
9383 af_rt_vpn_imexport_cmd,
9384 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9385 NO_STR
9386 "Specify route target list\n"
ddb5b488 9387 "Specify route target list\n"
b9c7bc5a
PZ
9388 "Between current address-family and vpn\n"
9389 "For routes leaked from vpn to current address-family: match any\n"
9390 "For routes leaked from current address-family to vpn: set\n"
9391 "both import: match any and export: set\n"
ddb5b488
PZ
9392 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9393{
9394 VTY_DECLVAR_CONTEXT(bgp, bgp);
9395 int ret;
9396 struct ecommunity *ecom = NULL;
9397 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
9398 vpn_policy_direction_t dir;
9399 afi_t afi;
9400 int idx = 0;
c6423c31 9401 bool yes = true;
ddb5b488 9402
b9c7bc5a 9403 if (argv_find(argv, argc, "no", &idx))
c6423c31 9404 yes = false;
b9c7bc5a 9405
0ca70ba5 9406 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9407 if (afi == AFI_MAX)
9408 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9409
b9c7bc5a 9410 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9411 if (ret != CMD_SUCCESS)
9412 return ret;
9413
b9c7bc5a
PZ
9414 if (yes) {
9415 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9416 vty_out(vty, "%% Missing RTLIST\n");
9417 return CMD_WARNING_CONFIG_FAILED;
9418 }
c6423c31 9419 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9420 if (ret != CMD_SUCCESS) {
9421 return ret;
9422 }
ddb5b488
PZ
9423 }
9424
69b07479
DS
9425 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9426 if (!dodir[dir])
ddb5b488 9427 continue;
ddb5b488 9428
69b07479 9429 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9430
69b07479
DS
9431 if (yes) {
9432 if (bgp->vpn_policy[afi].rtlist[dir])
9433 ecommunity_free(
9434 &bgp->vpn_policy[afi].rtlist[dir]);
9435 bgp->vpn_policy[afi].rtlist[dir] =
9436 ecommunity_dup(ecom);
9437 } else {
9438 if (bgp->vpn_policy[afi].rtlist[dir])
9439 ecommunity_free(
9440 &bgp->vpn_policy[afi].rtlist[dir]);
9441 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9442 }
69b07479
DS
9443
9444 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9445 }
69b07479 9446
d555f3e9
PZ
9447 if (ecom)
9448 ecommunity_free(&ecom);
ddb5b488
PZ
9449
9450 return CMD_SUCCESS;
9451}
9452
b9c7bc5a
PZ
9453ALIAS (af_rt_vpn_imexport,
9454 af_no_rt_vpn_imexport_cmd,
9455 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9456 NO_STR
9457 "Specify route target list\n"
b9c7bc5a
PZ
9458 "Specify route target list\n"
9459 "Between current address-family and vpn\n"
9460 "For routes leaked from vpn to current address-family\n"
9461 "For routes leaked from current address-family to vpn\n"
9462 "both import and export\n")
9463
37a87b8f 9464DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9465 af_route_map_vpn_imexport_cmd,
9466/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9467 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9468 NO_STR
ddb5b488 9469 "Specify route map\n"
b9c7bc5a
PZ
9470 "Between current address-family and vpn\n"
9471 "For routes leaked from vpn to current address-family\n"
9472 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9473 "name of route-map\n")
9474{
37a87b8f 9475 char base_xpath[XPATH_MAXLEN];
ddb5b488 9476 afi_t afi;
37a87b8f 9477 safi_t safi;
ddb5b488 9478 int idx = 0;
ddb5b488 9479
37a87b8f
CS
9480 afi = bgp_node_afi(vty);
9481 safi = bgp_node_safi(vty);
ddb5b488 9482
37a87b8f
CS
9483 snprintf(
9484 base_xpath, sizeof(base_xpath),
9485 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9486 yang_afi_safi_value2identity(afi, safi),
9487 bgp_afi_safi_get_container_str(afi, safi));
9488
9489 if (argv_find(argv, argc, "no", &idx)) {
9490 if (!strcmp(direction_str, "import"))
9491 nb_cli_enqueue_change(vty, "./rmap-import",
9492 NB_OP_DESTROY, NULL);
9493 else if (!strcmp(direction_str, "export"))
9494 nb_cli_enqueue_change(vty, "./rmap-export",
9495 NB_OP_DESTROY, NULL);
9496 } else {
9497 if (!strcmp(direction_str, "import"))
9498 nb_cli_enqueue_change(vty, "./rmap-import",
9499 NB_OP_MODIFY, rmap_str);
9500 if (!strcmp(direction_str, "export"))
9501 nb_cli_enqueue_change(vty, "./rmap-export",
9502 NB_OP_MODIFY, rmap_str);
9503 }
9504 return nb_cli_apply_changes(vty, base_xpath);
9505}
ddb5b488 9506
37a87b8f
CS
9507void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9508 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9509{
9510 int indent = 2;
ddb5b488 9511
37a87b8f
CS
9512 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9513 yang_dnode_get_string(dnode, NULL));
9514}
69b07479 9515
37a87b8f
CS
9516void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9517 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9518{
9519 int indent = 2;
ddb5b488 9520
37a87b8f
CS
9521 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9522 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9523}
9524
b9c7bc5a
PZ
9525ALIAS (af_route_map_vpn_imexport,
9526 af_no_route_map_vpn_imexport_cmd,
9527 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9528 NO_STR
9529 "Specify route map\n"
b9c7bc5a
PZ
9530 "Between current address-family and vpn\n"
9531 "For routes leaked from vpn to current address-family\n"
9532 "For routes leaked from current address-family to vpn\n")
9533
bb4f6190 9534DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9535 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9536 "Import routes from another VRF\n"
9537 "Vrf routes being filtered\n"
9538 "Specify route map\n"
9539 "name of route-map\n")
9540{
9541 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
9542 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9543 afi_t afi;
bb4f6190
DS
9544 struct bgp *bgp_default;
9545
0ca70ba5 9546 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9547 if (afi == AFI_MAX)
9548 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9549
9550 bgp_default = bgp_get_default();
9551 if (!bgp_default) {
9552 int32_t ret;
9553 as_t as = bgp->as;
9554
9555 /* Auto-create assuming the same AS */
5d5393b9
DL
9556 ret = bgp_get_vty(&bgp_default, &as, NULL,
9557 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9558
9559 if (ret) {
9560 vty_out(vty,
9561 "VRF default is not configured as a bgp instance\n");
9562 return CMD_WARNING;
9563 }
9564 }
9565
69b07479 9566 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9567
ae6a6fb4
DS
9568 if (bgp->vpn_policy[afi].rmap_name[dir])
9569 XFREE(MTYPE_ROUTE_MAP_NAME,
9570 bgp->vpn_policy[afi].rmap_name[dir]);
9571 bgp->vpn_policy[afi].rmap_name[dir] =
9572 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9573 bgp->vpn_policy[afi].rmap[dir] =
9574 route_map_lookup_warn_noexist(vty, rmap_str);
9575 if (!bgp->vpn_policy[afi].rmap[dir])
9576 return CMD_SUCCESS;
9577
9578 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9579 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9580
69b07479
DS
9581 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9582
bb4f6190
DS
9583 return CMD_SUCCESS;
9584}
9585
ae6a6fb4
DS
9586DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9587 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9588 NO_STR
9589 "Import routes from another VRF\n"
9590 "Vrf routes being filtered\n"
ae6a6fb4
DS
9591 "Specify route map\n"
9592 "name of route-map\n")
9593{
9594 VTY_DECLVAR_CONTEXT(bgp, bgp);
9595 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9596 afi_t afi;
9597
9598 afi = vpn_policy_getafi(vty, bgp, true);
9599 if (afi == AFI_MAX)
9600 return CMD_WARNING_CONFIG_FAILED;
9601
9602 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9603
9604 if (bgp->vpn_policy[afi].rmap_name[dir])
9605 XFREE(MTYPE_ROUTE_MAP_NAME,
9606 bgp->vpn_policy[afi].rmap_name[dir]);
9607 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9608 bgp->vpn_policy[afi].rmap[dir] = NULL;
9609
9610 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9611 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9612 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9613
9614 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9615
9616 return CMD_SUCCESS;
9617}
bb4f6190 9618
37a87b8f
CS
9619DEFPY_YANG(bgp_imexport_vrf,
9620 bgp_imexport_vrf_cmd,
9621 "[no] import vrf VIEWVRFNAME$import_name",
9622 NO_STR
9623 "Import routes from another VRF\n"
9624 "VRF to import from\n"
9625 "The name of the VRF\n")
12a844a5 9626{
37a87b8f 9627 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
9628 safi_t safi;
9629 afi_t afi;
37a87b8f 9630 int32_t idx = 0;
12a844a5 9631
867f0cca 9632 if (import_name == NULL) {
9633 vty_out(vty, "%% Missing import name\n");
9634 return CMD_WARNING;
9635 }
9636
ae6a6fb4
DS
9637 if (strcmp(import_name, "route-map") == 0) {
9638 vty_out(vty, "%% Must include route-map name\n");
9639 return CMD_WARNING;
9640 }
9641
37a87b8f 9642 afi = bgp_node_afi(vty);
12a844a5
DS
9643 safi = bgp_node_safi(vty);
9644
37a87b8f
CS
9645 snprintf(
9646 base_xpath, sizeof(base_xpath),
9647 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9648 yang_afi_safi_value2identity(afi, safi),
9649 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 9650
37a87b8f
CS
9651 if (argv_find(argv, argc, "no", &idx))
9652 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9653 else
9654 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 9655
37a87b8f
CS
9656 return nb_cli_apply_changes(vty, base_xpath);
9657}
12a844a5 9658
37a87b8f
CS
9659void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9660 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9661{
9662 vty_out(vty, " import vrf %s\n",
9663 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
9664}
9665
b9c7bc5a 9666/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 9667DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
9668 bgp_imexport_vpn_cmd,
9669 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9670 NO_STR
9671 "Import routes to this address-family\n"
9672 "Export routes from this address-family\n"
9673 "to/from default instance VPN RIB\n")
ddb5b488 9674{
37a87b8f 9675 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 9676 safi_t safi;
37a87b8f
CS
9677 afi_t afi;
9678 int32_t idx = 0;
ddb5b488 9679
b9c7bc5a
PZ
9680 afi = bgp_node_afi(vty);
9681 safi = bgp_node_safi(vty);
ddb5b488 9682
b9c7bc5a 9683 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
9684 snprintf(
9685 base_xpath, sizeof(base_xpath),
9686 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9687 yang_afi_safi_value2identity(afi, safi),
9688 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 9689 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
9690 snprintf(
9691 base_xpath, sizeof(base_xpath),
9692 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9693 yang_afi_safi_value2identity(afi, safi),
9694 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
9695 } else {
9696 vty_out(vty, "%% unknown direction %s\n", direction_str);
9697 return CMD_WARNING_CONFIG_FAILED;
9698 }
9699
37a87b8f
CS
9700 if (argv_find(argv, argc, "no", &idx))
9701 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9702 else
9703 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 9704
37a87b8f
CS
9705 return nb_cli_apply_changes(vty, base_xpath);
9706}
ddb5b488 9707
37a87b8f
CS
9708void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9709 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9710{
9711 if (yang_dnode_get_bool(dnode, NULL))
9712 vty_out(vty, " import vpn\n");
9713}
9714
9715void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9716 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9717{
9718 if (yang_dnode_get_bool(dnode, NULL))
9719 vty_out(vty, " export vpn\n");
ddb5b488
PZ
9720}
9721
301ad80a
PG
9722DEFPY (af_routetarget_import,
9723 af_routetarget_import_cmd,
9a659715 9724 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9725 NO_STR
9726 "Specify route target list\n"
9727 "Specify route target list\n"
9a659715
PG
9728 "Specify route target list\n"
9729 "Specify route target list\n"
301ad80a
PG
9730 "Flow-spec redirect type route target\n"
9731 "Import routes to this address-family\n"
9a659715 9732 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9733{
9734 VTY_DECLVAR_CONTEXT(bgp, bgp);
9735 int ret;
9736 struct ecommunity *ecom = NULL;
301ad80a 9737 afi_t afi;
9a659715 9738 int idx = 0, idx_unused = 0;
c6423c31
PG
9739 bool yes = true;
9740 bool rt6 = false;
301ad80a
PG
9741
9742 if (argv_find(argv, argc, "no", &idx))
c6423c31 9743 yes = false;
301ad80a 9744
9a659715
PG
9745 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9746 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9747 rt6 = true;
301ad80a 9748
0ca70ba5 9749 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9750 if (afi == AFI_MAX)
9751 return CMD_WARNING_CONFIG_FAILED;
9752
9a659715
PG
9753 if (rt6 && afi != AFI_IP6)
9754 return CMD_WARNING_CONFIG_FAILED;
9755
301ad80a
PG
9756 if (yes) {
9757 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9758 vty_out(vty, "%% Missing RTLIST\n");
9759 return CMD_WARNING_CONFIG_FAILED;
9760 }
9a659715 9761 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9762 if (ret != CMD_SUCCESS)
9763 return ret;
9764 }
69b07479
DS
9765
9766 if (yes) {
9767 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9768 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9769 .import_redirect_rtlist);
69b07479
DS
9770 bgp->vpn_policy[afi].import_redirect_rtlist =
9771 ecommunity_dup(ecom);
9772 } else {
9773 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9774 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9775 .import_redirect_rtlist);
69b07479 9776 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9777 }
69b07479 9778
301ad80a
PG
9779 if (ecom)
9780 ecommunity_free(&ecom);
9781
9782 return CMD_SUCCESS;
9783}
9784
37a87b8f
CS
9785void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9786 struct lyd_node *dnode,
9787 bool show_defaults)
9788{
9789 const char *af_name;
9790 afi_t afi;
9791 safi_t safi;
9792
9793 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9794 yang_afi_safi_identity2value(af_name, &afi, &safi);
9795
9796 vty_out(vty, " !\n address-family ");
9797 if (afi == AFI_IP) {
9798 if (safi == SAFI_UNICAST)
9799 vty_out(vty, "ipv4 unicast");
9800 else if (safi == SAFI_LABELED_UNICAST)
9801 vty_out(vty, "ipv4 labeled-unicast");
9802 else if (safi == SAFI_MULTICAST)
9803 vty_out(vty, "ipv4 multicast");
9804 else if (safi == SAFI_MPLS_VPN)
9805 vty_out(vty, "ipv4 vpn");
9806 else if (safi == SAFI_ENCAP)
9807 vty_out(vty, "ipv4 encap");
9808 else if (safi == SAFI_FLOWSPEC)
9809 vty_out(vty, "ipv4 flowspec");
9810 } else if (afi == AFI_IP6) {
9811 if (safi == SAFI_UNICAST)
9812 vty_out(vty, "ipv6 unicast");
9813 else if (safi == SAFI_LABELED_UNICAST)
9814 vty_out(vty, "ipv6 labeled-unicast");
9815 else if (safi == SAFI_MULTICAST)
9816 vty_out(vty, "ipv6 multicast");
9817 else if (safi == SAFI_MPLS_VPN)
9818 vty_out(vty, "ipv6 vpn");
9819 else if (safi == SAFI_ENCAP)
9820 vty_out(vty, "ipv6 encap");
9821 else if (safi == SAFI_FLOWSPEC)
9822 vty_out(vty, "ipv6 flowspec");
9823 } else if (afi == AFI_L2VPN) {
9824 if (safi == SAFI_EVPN)
9825 vty_out(vty, "l2vpn evpn");
9826 }
9827 vty_out(vty, "\n");
9828}
9829
505e5056 9830DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9831 address_family_ipv4_safi_cmd,
9832 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9833 "Enter Address Family command mode\n"
9834 "Address Family\n"
9835 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9836{
f51bae9c 9837
37a87b8f
CS
9838 safi_t safi = SAFI_UNICAST;
9839 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9840 const char *vrf_name = NULL;
9841
d62a17ae 9842 if (argc == 3) {
37a87b8f
CS
9843 safi = bgp_vty_safi_from_str(argv[2]->text);
9844
9845 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9846 VTY_CURR_XPATH);
9847 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9848 "control-plane-protocol");
9849 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9850
9851 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9852 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9853 && safi != SAFI_EVPN) {
31947174
MK
9854 vty_out(vty,
9855 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9856 return CMD_WARNING_CONFIG_FAILED;
9857 }
37a87b8f
CS
9858 }
9859 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 9860
d62a17ae 9861 return CMD_SUCCESS;
718e3744 9862}
9863
505e5056 9864DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9865 address_family_ipv6_safi_cmd,
9866 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9867 "Enter Address Family command mode\n"
9868 "Address Family\n"
9869 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9870{
37a87b8f
CS
9871 safi_t safi = SAFI_UNICAST;
9872 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9873 const char *vrf_name = NULL;
9874
d62a17ae 9875 if (argc == 3) {
37a87b8f
CS
9876 safi = bgp_vty_safi_from_str(argv[2]->text);
9877 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9878 VTY_CURR_XPATH);
9879 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9880 "control-plane-protocol");
9881 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9882
9883 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9884 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9885 && safi != SAFI_EVPN) {
31947174
MK
9886 vty_out(vty,
9887 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9888 return CMD_WARNING_CONFIG_FAILED;
9889 }
37a87b8f
CS
9890 }
9891 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 9892
d62a17ae 9893 return CMD_SUCCESS;
25ffbdc1 9894}
718e3744 9895
d6902373 9896#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9897DEFUN_NOSH (address_family_vpnv4,
718e3744 9898 address_family_vpnv4_cmd,
8334fd5a 9899 "address-family vpnv4 [unicast]",
718e3744 9900 "Enter Address Family command mode\n"
8c3deaae 9901 "Address Family\n"
3a2d747c 9902 "Address Family modifier\n")
718e3744 9903{
d62a17ae 9904 vty->node = BGP_VPNV4_NODE;
9905 return CMD_SUCCESS;
718e3744 9906}
9907
505e5056 9908DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9909 address_family_vpnv6_cmd,
8334fd5a 9910 "address-family vpnv6 [unicast]",
8ecd3266 9911 "Enter Address Family command mode\n"
8c3deaae 9912 "Address Family\n"
3a2d747c 9913 "Address Family modifier\n")
8ecd3266 9914{
d62a17ae 9915 vty->node = BGP_VPNV6_NODE;
9916 return CMD_SUCCESS;
8ecd3266 9917}
64e4a6c5 9918#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9919
505e5056 9920DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9921 address_family_evpn_cmd,
7111c1a0 9922 "address-family l2vpn evpn",
4e0b7b6d 9923 "Enter Address Family command mode\n"
7111c1a0
QY
9924 "Address Family\n"
9925 "Address Family modifier\n")
4e0b7b6d 9926{
2131d5cf 9927 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9928 vty->node = BGP_EVPN_NODE;
9929 return CMD_SUCCESS;
4e0b7b6d
PG
9930}
9931
bfaab44d
HS
9932DEFUN_NOSH (bgp_segment_routing_srv6,
9933 bgp_segment_routing_srv6_cmd,
9934 "segment-routing srv6",
9935 "Segment-Routing configuration\n"
9936 "Segment-Routing SRv6 configuration\n")
9937{
9938 VTY_DECLVAR_CONTEXT(bgp, bgp);
92a9e6f2 9939 bgp->srv6_enabled = true;
bfaab44d
HS
9940 vty->node = BGP_SRV6_NODE;
9941 return CMD_SUCCESS;
9942}
9943
a0281b2e
HS
9944DEFPY (bgp_srv6_locator,
9945 bgp_srv6_locator_cmd,
9946 "locator NAME$name",
9947 "Specify SRv6 locator\n"
9948 "Specify SRv6 locator\n")
9949{
9950 VTY_DECLVAR_CONTEXT(bgp, bgp);
9951
9952 if (strlen(bgp->srv6_locator_name) > 0
9953 && strcmp(name, bgp->srv6_locator_name) != 0) {
9954 vty_out(vty, "srv6 locator is already configured\n");
9955 return CMD_WARNING_CONFIG_FAILED;
9956 } else
9957 snprintf(bgp->srv6_locator_name,
9958 sizeof(bgp->srv6_locator_name), "%s", name);
9959
9960 int ret = bgp_zebra_srv6_manager_get_locator_chunk(name);
9961 if (ret < 0)
9962 return CMD_WARNING_CONFIG_FAILED;
9963
9964 return CMD_SUCCESS;
9965}
9966
505e5056 9967DEFUN_NOSH (exit_address_family,
718e3744 9968 exit_address_family_cmd,
9969 "exit-address-family",
9970 "Exit from Address Family configuration mode\n")
9971{
d62a17ae 9972 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9973 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9974 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9975 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9976 || vty->node == BGP_EVPN_NODE
9977 || vty->node == BGP_FLOWSPECV4_NODE
9978 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9979 vty->node = BGP_NODE;
9980 return CMD_SUCCESS;
718e3744 9981}
6b0655a2 9982
37a87b8f
CS
9983void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9984 struct lyd_node *dnode
9985 __attribute__((__unused__)))
9986{
9987 vty_out(vty, " exit-address-family\n");
9988}
9989
8ad7271d 9990/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9991static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9992 const char *ip_str, afi_t afi, safi_t safi,
9993 struct prefix_rd *prd)
9994{
9995 int ret;
9996 struct prefix match;
9bcb3eef
DS
9997 struct bgp_dest *dest;
9998 struct bgp_dest *rm;
d62a17ae 9999 struct bgp *bgp;
10000 struct bgp_table *table;
10001 struct bgp_table *rib;
10002
10003 /* BGP structure lookup. */
10004 if (view_name) {
10005 bgp = bgp_lookup_by_name(view_name);
10006 if (bgp == NULL) {
10007 vty_out(vty, "%% Can't find BGP instance %s\n",
10008 view_name);
10009 return CMD_WARNING;
10010 }
10011 } else {
10012 bgp = bgp_get_default();
10013 if (bgp == NULL) {
10014 vty_out(vty, "%% No BGP process is configured\n");
10015 return CMD_WARNING;
10016 }
10017 }
10018
10019 /* Check IP address argument. */
10020 ret = str2prefix(ip_str, &match);
10021 if (!ret) {
10022 vty_out(vty, "%% address is malformed\n");
10023 return CMD_WARNING;
10024 }
10025
10026 match.family = afi2family(afi);
10027 rib = bgp->rib[afi][safi];
10028
10029 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
10030 for (dest = bgp_table_top(rib); dest;
10031 dest = bgp_route_next(dest)) {
10032 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10033
9bcb3eef 10034 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 10035 continue;
10036
9bcb3eef 10037 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
10038 if (table == NULL)
10039 continue;
10040
10041 if ((rm = bgp_node_match(table, &match)) != NULL) {
10042 const struct prefix *rm_p =
9bcb3eef 10043 bgp_dest_get_prefix(rm);
b54892e0
DS
10044
10045 if (rm_p->prefixlen == match.prefixlen) {
10046 SET_FLAG(rm->flags,
10047 BGP_NODE_USER_CLEAR);
10048 bgp_process(bgp, rm, afi, safi);
d62a17ae 10049 }
9bcb3eef 10050 bgp_dest_unlock_node(rm);
d62a17ae 10051 }
10052 }
10053 } else {
9bcb3eef
DS
10054 if ((dest = bgp_node_match(rib, &match)) != NULL) {
10055 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 10056
9bcb3eef
DS
10057 if (dest_p->prefixlen == match.prefixlen) {
10058 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
10059 bgp_process(bgp, dest, afi, safi);
d62a17ae 10060 }
9bcb3eef 10061 bgp_dest_unlock_node(dest);
d62a17ae 10062 }
10063 }
10064
10065 return CMD_SUCCESS;
8ad7271d
DS
10066}
10067
b09b5ae0 10068/* one clear bgp command to rule them all */
718e3744 10069DEFUN (clear_ip_bgp_all,
10070 clear_ip_bgp_all_cmd,
453c92f6 10071 "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 10072 CLEAR_STR
10073 IP_STR
10074 BGP_STR
838758ac 10075 BGP_INSTANCE_HELP_STR
510afcd6 10076 BGP_AFI_HELP_STR
fd5e7b70 10077 "Address Family\n"
510afcd6 10078 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 10079 "Address Family modifier\n"
b09b5ae0 10080 "Clear all peers\n"
453c92f6 10081 "BGP IPv4 neighbor to clear\n"
a80beece 10082 "BGP IPv6 neighbor to clear\n"
838758ac 10083 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
10084 "Clear peers with the AS number\n"
10085 "Clear all external peers\n"
718e3744 10086 "Clear all members of peer-group\n"
b09b5ae0 10087 "BGP peer-group name\n"
b09b5ae0
DW
10088 BGP_SOFT_STR
10089 BGP_SOFT_IN_STR
b09b5ae0
DW
10090 BGP_SOFT_OUT_STR
10091 BGP_SOFT_IN_STR
10092 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 10093 BGP_SOFT_OUT_STR)
718e3744 10094{
d62a17ae 10095 char *vrf = NULL;
10096
dc912615
DS
10097 afi_t afi = AFI_UNSPEC;
10098 safi_t safi = SAFI_UNSPEC;
d62a17ae 10099 enum clear_sort clr_sort = clear_peer;
10100 enum bgp_clear_type clr_type;
10101 char *clr_arg = NULL;
10102
10103 int idx = 0;
ff8a8a7a
CS
10104 char errmsg[BUFSIZ] = {'\0'};
10105 int ret;
d62a17ae 10106
10107 /* clear [ip] bgp */
10108 if (argv_find(argv, argc, "ip", &idx))
10109 afi = AFI_IP;
10110
9a8bdf1c
PG
10111 /* [<vrf> VIEWVRFNAME] */
10112 if (argv_find(argv, argc, "vrf", &idx)) {
10113 vrf = argv[idx + 1]->arg;
10114 idx += 2;
10115 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10116 vrf = NULL;
10117 } else if (argv_find(argv, argc, "view", &idx)) {
10118 /* [<view> VIEWVRFNAME] */
d62a17ae 10119 vrf = argv[idx + 1]->arg;
10120 idx += 2;
10121 }
d62a17ae 10122 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10123 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10124 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10125
d7b9898c 10126 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 10127 if (argv_find(argv, argc, "*", &idx)) {
10128 clr_sort = clear_all;
10129 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10130 clr_sort = clear_peer;
10131 clr_arg = argv[idx]->arg;
10132 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10133 clr_sort = clear_peer;
10134 clr_arg = argv[idx]->arg;
10135 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10136 clr_sort = clear_group;
10137 idx++;
10138 clr_arg = argv[idx]->arg;
d7b9898c 10139 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10140 clr_sort = clear_peer;
10141 clr_arg = argv[idx]->arg;
8fa7d444
DS
10142 } else if (argv_find(argv, argc, "WORD", &idx)) {
10143 clr_sort = clear_peer;
10144 clr_arg = argv[idx]->arg;
d62a17ae 10145 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10146 clr_sort = clear_as;
10147 clr_arg = argv[idx]->arg;
10148 } else if (argv_find(argv, argc, "external", &idx)) {
10149 clr_sort = clear_external;
10150 }
10151
10152 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
10153 if (argv_find(argv, argc, "soft", &idx)) {
10154 if (argv_find(argv, argc, "in", &idx)
10155 || argv_find(argv, argc, "out", &idx))
10156 clr_type = strmatch(argv[idx]->text, "in")
10157 ? BGP_CLEAR_SOFT_IN
10158 : BGP_CLEAR_SOFT_OUT;
10159 else
10160 clr_type = BGP_CLEAR_SOFT_BOTH;
10161 } else if (argv_find(argv, argc, "in", &idx)) {
10162 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10163 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10164 : BGP_CLEAR_SOFT_IN;
10165 } else if (argv_find(argv, argc, "out", &idx)) {
10166 clr_type = BGP_CLEAR_SOFT_OUT;
10167 } else
10168 clr_type = BGP_CLEAR_SOFT_NONE;
10169
ff8a8a7a
CS
10170 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
10171 sizeof(errmsg));
10172 if (ret != NB_OK)
10173 vty_out(vty, "Error description: %s\n", errmsg);
10174
10175 return ret;
838758ac 10176}
01080f7c 10177
8ad7271d
DS
10178DEFUN (clear_ip_bgp_prefix,
10179 clear_ip_bgp_prefix_cmd,
18c57037 10180 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10181 CLEAR_STR
10182 IP_STR
10183 BGP_STR
838758ac 10184 BGP_INSTANCE_HELP_STR
8ad7271d 10185 "Clear bestpath and re-advertise\n"
0c7b1b01 10186 "IPv4 prefix\n")
8ad7271d 10187{
d62a17ae 10188 char *vrf = NULL;
10189 char *prefix = NULL;
8ad7271d 10190
d62a17ae 10191 int idx = 0;
01080f7c 10192
d62a17ae 10193 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10194 if (argv_find(argv, argc, "vrf", &idx)) {
10195 vrf = argv[idx + 1]->arg;
10196 idx += 2;
10197 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10198 vrf = NULL;
10199 } else if (argv_find(argv, argc, "view", &idx)) {
10200 /* [<view> VIEWVRFNAME] */
10201 vrf = argv[idx + 1]->arg;
10202 idx += 2;
10203 }
0c7b1b01 10204
d62a17ae 10205 prefix = argv[argc - 1]->arg;
8ad7271d 10206
d62a17ae 10207 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10208}
8ad7271d 10209
b09b5ae0
DW
10210DEFUN (clear_bgp_ipv6_safi_prefix,
10211 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10212 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10213 CLEAR_STR
3a2d747c 10214 IP_STR
718e3744 10215 BGP_STR
8c3deaae 10216 "Address Family\n"
46f296b4 10217 BGP_SAFI_HELP_STR
b09b5ae0 10218 "Clear bestpath and re-advertise\n"
0c7b1b01 10219 "IPv6 prefix\n")
718e3744 10220{
9b475e76
PG
10221 int idx_safi = 0;
10222 int idx_ipv6_prefix = 0;
10223 safi_t safi = SAFI_UNICAST;
10224 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10225 argv[idx_ipv6_prefix]->arg : NULL;
10226
10227 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10228 return bgp_clear_prefix(
9b475e76
PG
10229 vty, NULL, prefix, AFI_IP6,
10230 safi, NULL);
838758ac 10231}
01080f7c 10232
b09b5ae0
DW
10233DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10234 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10235 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10236 CLEAR_STR
3a2d747c 10237 IP_STR
718e3744 10238 BGP_STR
838758ac 10239 BGP_INSTANCE_HELP_STR
8c3deaae 10240 "Address Family\n"
46f296b4 10241 BGP_SAFI_HELP_STR
b09b5ae0 10242 "Clear bestpath and re-advertise\n"
0c7b1b01 10243 "IPv6 prefix\n")
718e3744 10244{
9b475e76 10245 int idx_safi = 0;
9a8bdf1c 10246 int idx_vrfview = 0;
9b475e76
PG
10247 int idx_ipv6_prefix = 0;
10248 safi_t safi = SAFI_UNICAST;
10249 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10250 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10251 char *vrfview = NULL;
9b475e76 10252
9a8bdf1c
PG
10253 /* [<view|vrf> VIEWVRFNAME] */
10254 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10255 vrfview = argv[idx_vrfview + 1]->arg;
10256 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10257 vrfview = NULL;
10258 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10259 /* [<view> VIEWVRFNAME] */
10260 vrfview = argv[idx_vrfview + 1]->arg;
10261 }
9b475e76
PG
10262 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10263
d62a17ae 10264 return bgp_clear_prefix(
9b475e76
PG
10265 vty, vrfview, prefix,
10266 AFI_IP6, safi, NULL);
718e3744 10267}
10268
b09b5ae0
DW
10269DEFUN (show_bgp_views,
10270 show_bgp_views_cmd,
d6e3c605 10271 "show [ip] bgp views",
b09b5ae0 10272 SHOW_STR
d6e3c605 10273 IP_STR
01080f7c 10274 BGP_STR
b09b5ae0 10275 "Show the defined BGP views\n")
01080f7c 10276{
d62a17ae 10277 struct list *inst = bm->bgp;
10278 struct listnode *node;
10279 struct bgp *bgp;
01080f7c 10280
d62a17ae 10281 vty_out(vty, "Defined BGP views:\n");
10282 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10283 /* Skip VRFs. */
10284 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10285 continue;
10286 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10287 bgp->as);
10288 }
e52702f2 10289
d62a17ae 10290 return CMD_SUCCESS;
e0081f70
ML
10291}
10292
8386ac43 10293DEFUN (show_bgp_vrfs,
10294 show_bgp_vrfs_cmd,
d6e3c605 10295 "show [ip] bgp vrfs [json]",
8386ac43 10296 SHOW_STR
d6e3c605 10297 IP_STR
8386ac43 10298 BGP_STR
10299 "Show BGP VRFs\n"
9973d184 10300 JSON_STR)
8386ac43 10301{
fe1dc5a3 10302 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10303 struct list *inst = bm->bgp;
10304 struct listnode *node;
10305 struct bgp *bgp;
9f049418 10306 bool uj = use_json(argc, argv);
d62a17ae 10307 json_object *json = NULL;
10308 json_object *json_vrfs = NULL;
10309 int count = 0;
d62a17ae 10310
d62a17ae 10311 if (uj) {
10312 json = json_object_new_object();
10313 json_vrfs = json_object_new_object();
10314 }
10315
10316 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10317 const char *name, *type;
10318 struct peer *peer;
7fe96307 10319 struct listnode *node2, *nnode2;
d62a17ae 10320 int peers_cfg, peers_estb;
10321 json_object *json_vrf = NULL;
d62a17ae 10322
10323 /* Skip Views. */
10324 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10325 continue;
10326
10327 count++;
efb4077a 10328 if (!uj && count == 1) {
fe1dc5a3 10329 vty_out(vty,
efb4077a 10330 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10331 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10332 "#PeersEstb", "Name");
10333 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10334 "L3-VNI", "RouterMAC", "Interface");
10335 }
d62a17ae 10336
10337 peers_cfg = peers_estb = 0;
10338 if (uj)
10339 json_vrf = json_object_new_object();
10340
10341
7fe96307 10342 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10343 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10344 continue;
10345 peers_cfg++;
10346 if (peer->status == Established)
10347 peers_estb++;
10348 }
10349
10350 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10351 name = VRF_DEFAULT_NAME;
d62a17ae 10352 type = "DFLT";
10353 } else {
10354 name = bgp->name;
10355 type = "VRF";
10356 }
10357
a8bf7d9c 10358
d62a17ae 10359 if (uj) {
a4d82a8a
PZ
10360 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10361 ? -1
10362 : (int64_t)bgp->vrf_id;
23d0a753
DA
10363 char buf[BUFSIZ] = {0};
10364
d62a17ae 10365 json_object_string_add(json_vrf, "type", type);
10366 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10367 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
10368 inet_ntop(AF_INET,
10369 &bgp->router_id, buf,
10370 sizeof(buf)));
d62a17ae 10371 json_object_int_add(json_vrf, "numConfiguredPeers",
10372 peers_cfg);
10373 json_object_int_add(json_vrf, "numEstablishedPeers",
10374 peers_estb);
10375
fe1dc5a3 10376 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10377 json_object_string_add(
10378 json_vrf, "rmac",
10379 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10380 json_object_string_add(json_vrf, "interface",
10381 ifindex2ifname(bgp->l3vni_svi_ifindex,
10382 bgp->vrf_id));
d62a17ae 10383 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10384 } else {
23d0a753 10385 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10386 type,
10387 bgp->vrf_id == VRF_UNKNOWN ? -1
10388 : (int)bgp->vrf_id,
23d0a753 10389 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10390 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10391 bgp->l3vni,
10392 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10393 ifindex2ifname(bgp->l3vni_svi_ifindex,
10394 bgp->vrf_id));
10395 }
d62a17ae 10396 }
10397
10398 if (uj) {
10399 json_object_object_add(json, "vrfs", json_vrfs);
10400
10401 json_object_int_add(json, "totalVrfs", count);
10402
996c9314
LB
10403 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10404 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10405 json_object_free(json);
10406 } else {
10407 if (count)
10408 vty_out(vty,
10409 "\nTotal number of VRFs (including default): %d\n",
10410 count);
10411 }
10412
10413 return CMD_SUCCESS;
8386ac43 10414}
10415
48ecf8f5
DS
10416DEFUN (show_bgp_mac_hash,
10417 show_bgp_mac_hash_cmd,
10418 "show bgp mac hash",
10419 SHOW_STR
10420 BGP_STR
10421 "Mac Address\n"
10422 "Mac Address database\n")
10423{
10424 bgp_mac_dump_table(vty);
10425
10426 return CMD_SUCCESS;
10427}
acf71666 10428
e3b78da8 10429static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10430{
0291c246 10431 struct vty *vty = (struct vty *)args;
e3b78da8 10432 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10433
23d0a753 10434 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10435}
10436
10437static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10438{
10439 vty_out(vty, "self nexthop database:\n");
af97a18b 10440 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10441
10442 vty_out(vty, "Tunnel-ip database:\n");
10443 hash_iterate(bgp->tip_hash,
e3b78da8 10444 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10445 vty);
10446}
10447
15c81ca4
DS
10448DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10449 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10450 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10451 "martian next-hops\n"
10452 "martian next-hop database\n")
acf71666 10453{
0291c246 10454 struct bgp *bgp = NULL;
15c81ca4 10455 int idx = 0;
9a8bdf1c
PG
10456 char *name = NULL;
10457
10458 /* [<vrf> VIEWVRFNAME] */
10459 if (argv_find(argv, argc, "vrf", &idx)) {
10460 name = argv[idx + 1]->arg;
10461 if (name && strmatch(name, VRF_DEFAULT_NAME))
10462 name = NULL;
10463 } else if (argv_find(argv, argc, "view", &idx))
10464 /* [<view> VIEWVRFNAME] */
10465 name = argv[idx + 1]->arg;
10466 if (name)
10467 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10468 else
10469 bgp = bgp_get_default();
acf71666 10470
acf71666
MK
10471 if (!bgp) {
10472 vty_out(vty, "%% No BGP process is configured\n");
10473 return CMD_WARNING;
10474 }
10475 bgp_show_martian_nexthops(vty, bgp);
10476
10477 return CMD_SUCCESS;
10478}
10479
f412b39a 10480DEFUN (show_bgp_memory,
4bf6a362 10481 show_bgp_memory_cmd,
7fa12b13 10482 "show [ip] bgp memory",
4bf6a362 10483 SHOW_STR
3a2d747c 10484 IP_STR
4bf6a362
PJ
10485 BGP_STR
10486 "Global BGP memory statistics\n")
10487{
d62a17ae 10488 char memstrbuf[MTYPE_MEMSTR_LEN];
10489 unsigned long count;
10490
10491 /* RIB related usage stats */
10492 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10493 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10494 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10495 count * sizeof(struct bgp_dest)));
d62a17ae 10496
10497 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10498 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10499 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10500 count * sizeof(struct bgp_path_info)));
d62a17ae 10501 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10502 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10503 count,
4b7e6066
DS
10504 mtype_memstr(
10505 memstrbuf, sizeof(memstrbuf),
10506 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10507
10508 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10509 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10510 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10511 count * sizeof(struct bgp_static)));
10512
10513 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10514 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10515 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10516 count * sizeof(struct bpacket)));
10517
10518 /* Adj-In/Out */
10519 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10520 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10521 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10522 count * sizeof(struct bgp_adj_in)));
10523 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10524 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10525 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10526 count * sizeof(struct bgp_adj_out)));
10527
10528 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10529 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10530 count,
10531 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10532 count * sizeof(struct bgp_nexthop_cache)));
10533
10534 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10535 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10536 count,
10537 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10538 count * sizeof(struct bgp_damp_info)));
10539
10540 /* Attributes */
10541 count = attr_count();
10542 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10543 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10544 count * sizeof(struct attr)));
10545
10546 if ((count = attr_unknown_count()))
10547 vty_out(vty, "%ld unknown attributes\n", count);
10548
10549 /* AS_PATH attributes */
10550 count = aspath_count();
10551 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10552 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10553 count * sizeof(struct aspath)));
10554
10555 count = mtype_stats_alloc(MTYPE_AS_SEG);
10556 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10557 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10558 count * sizeof(struct assegment)));
10559
10560 /* Other attributes */
10561 if ((count = community_count()))
10562 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10563 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10564 count * sizeof(struct community)));
d62a17ae 10565 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10566 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10567 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10568 count * sizeof(struct ecommunity)));
d62a17ae 10569 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10570 vty_out(vty,
10571 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10572 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10573 count * sizeof(struct lcommunity)));
d62a17ae 10574
10575 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10576 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10577 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10578 count * sizeof(struct cluster_list)));
10579
10580 /* Peer related usage */
10581 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10582 vty_out(vty, "%ld peers, using %s of memory\n", count,
10583 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10584 count * sizeof(struct peer)));
10585
10586 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10587 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10588 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10589 count * sizeof(struct peer_group)));
10590
10591 /* Other */
d62a17ae 10592 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10593 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10594 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10595 count * sizeof(regex_t)));
d62a17ae 10596 return CMD_SUCCESS;
4bf6a362 10597}
fee0f4c6 10598
57a9c8a8
DS
10599static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10600{
10601 json_object *bestpath = json_object_new_object();
10602
892fedb6 10603 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10604 json_object_string_add(bestpath, "asPath", "ignore");
10605
892fedb6 10606 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10607 json_object_string_add(bestpath, "asPath", "confed");
10608
892fedb6
DA
10609 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10610 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10611 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10612 "as-set");
10613 else
a4d82a8a 10614 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10615 "true");
10616 } else
a4d82a8a 10617 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10618
ee88563a
JM
10619 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10620 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10621
892fedb6 10622 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10623 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10624 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10625 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10626 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10627 json_object_string_add(bestpath, "med", "confed");
892fedb6 10628 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10629 json_object_string_add(bestpath, "med",
10630 "missing-as-worst");
10631 else
10632 json_object_string_add(bestpath, "med", "true");
10633 }
10634
10635 json_object_object_add(json, "bestPath", bestpath);
10636}
10637
3577f1c5
DD
10638/* Print the error code/subcode for why the peer is down */
10639static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10640 json_object *json_peer, bool use_json)
10641{
10642 const char *code_str;
10643 const char *subcode_str;
10644
10645 if (use_json) {
10646 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10647 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10648 char errorcodesubcode_hexstr[5];
10649 char errorcodesubcode_str[256];
10650
10651 code_str = bgp_notify_code_str(peer->notify.code);
10652 subcode_str = bgp_notify_subcode_str(
10653 peer->notify.code,
10654 peer->notify.subcode);
10655
772270f3
QY
10656 snprintf(errorcodesubcode_hexstr,
10657 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10658 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10659 json_object_string_add(json_peer,
10660 "lastErrorCodeSubcode",
10661 errorcodesubcode_hexstr);
10662 snprintf(errorcodesubcode_str, 255, "%s%s",
10663 code_str, subcode_str);
10664 json_object_string_add(json_peer,
10665 "lastNotificationReason",
10666 errorcodesubcode_str);
10667 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10668 && peer->notify.code == BGP_NOTIFY_CEASE
10669 && (peer->notify.subcode
10670 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10671 || peer->notify.subcode
10672 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10673 && peer->notify.length) {
10674 char msgbuf[1024];
10675 const char *msg_str;
10676
10677 msg_str = bgp_notify_admin_message(
10678 msgbuf, sizeof(msgbuf),
10679 (uint8_t *)peer->notify.data,
10680 peer->notify.length);
10681 if (msg_str)
10682 json_object_string_add(
10683 json_peer,
10684 "lastShutdownDescription",
10685 msg_str);
10686 }
10687
c258527b 10688 }
3577f1c5
DD
10689 json_object_string_add(json_peer, "lastResetDueTo",
10690 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10691 json_object_int_add(json_peer, "lastResetCode",
10692 peer->last_reset);
3577f1c5
DD
10693 } else {
10694 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10695 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10696 code_str = bgp_notify_code_str(peer->notify.code);
10697 subcode_str =
10698 bgp_notify_subcode_str(peer->notify.code,
10699 peer->notify.subcode);
10700 vty_out(vty, " Notification %s (%s%s)\n",
10701 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10702 ? "sent"
10703 : "received",
10704 code_str, subcode_str);
10705 } else {
e91c24c8 10706 vty_out(vty, " %s\n",
3577f1c5
DD
10707 peer_down_str[(int)peer->last_reset]);
10708 }
10709 }
10710}
10711
10712static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10713 safi_t safi)
10714{
10715 return ((peer->status != Established) ||
10716 !peer->afc_recv[afi][safi]);
10717}
10718
10719static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10720 struct peer *peer, json_object *json_peer,
10721 int max_neighbor_width, bool use_json)
10722{
10723 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10724 int len;
10725
10726 if (use_json) {
10727 if (peer_dynamic_neighbor(peer))
10728 json_object_boolean_true_add(json_peer,
10729 "dynamicPeer");
10730 if (peer->hostname)
10731 json_object_string_add(json_peer, "hostname",
10732 peer->hostname);
10733
10734 if (peer->domainname)
10735 json_object_string_add(json_peer, "domainname",
10736 peer->domainname);
10737 json_object_int_add(json_peer, "connectionsEstablished",
10738 peer->established);
10739 json_object_int_add(json_peer, "connectionsDropped",
10740 peer->dropped);
10741 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10742 use_json, json_peer);
10743 if (peer->status == Established)
10744 json_object_string_add(json_peer, "lastResetDueTo",
10745 "AFI/SAFI Not Negotiated");
10746 else
10747 bgp_show_peer_reset(NULL, peer, json_peer, true);
10748 } else {
10749 dn_flag[1] = '\0';
10750 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10751 if (peer->hostname
892fedb6 10752 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10753 len = vty_out(vty, "%s%s(%s)", dn_flag,
10754 peer->hostname, peer->host);
10755 else
10756 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10757
10758 /* pad the neighbor column with spaces */
10759 if (len < max_neighbor_width)
10760 vty_out(vty, "%*s", max_neighbor_width - len,
10761 " ");
e91c24c8 10762 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10763 peer->dropped,
10764 peer_uptime(peer->uptime, timebuf,
10765 BGP_UPTIME_LEN, 0, NULL));
10766 if (peer->status == Established)
10767 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10768 else
10769 bgp_show_peer_reset(vty, peer, NULL,
10770 false);
10771 }
10772}
c258527b 10773
cb75bb31
DA
10774/* If the peer's description includes whitespaces
10775 * then return the first occurrence. Also strip description
10776 * to the given size if needed.
10777 */
10778static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10779{
10780 static char stripped[BUFSIZ];
10781 char *pnt;
10782 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10783
10784 pnt = strchr(desc, ' ');
10785 if (pnt)
10786 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10787 : size;
10788
10789 strlcpy(stripped, desc, len + 1);
10790
10791 return stripped;
10792}
3577f1c5 10793
8c1d4cd5
LS
10794/* Determine whether var peer should be filtered out of the summary. */
10795static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10796 struct peer *fpeer, int as_type,
10797 as_t as)
10798{
10799
10800 /* filter neighbor XXXX */
10801 if (fpeer && fpeer != peer)
10802 return true;
10803
10804 /* filter remote-as (internal|external) */
10805 if (as_type != AS_UNSPECIFIED) {
10806 if (peer->as_type == AS_SPECIFIED) {
10807 if (as_type == AS_INTERNAL) {
10808 if (peer->as != peer->local_as)
10809 return true;
10810 } else if (peer->as == peer->local_as)
10811 return true;
10812 } else if (as_type != peer->as_type)
10813 return true;
10814 } else if (as && as != peer->as) /* filter remote-as XXX */
10815 return true;
10816
10817 return false;
10818}
10819
718e3744 10820/* Show BGP peer's summary information. */
d62a17ae 10821static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10822 struct peer *fpeer, int as_type, as_t as,
85eeb029 10823 uint8_t show_flags)
d62a17ae 10824{
10825 struct peer *peer;
10826 struct listnode *node, *nnode;
10827 unsigned int count = 0, dn_count = 0;
10828 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10829 char neighbor_buf[VTY_BUFSIZ];
10830 int neighbor_col_default_width = 16;
3577f1c5 10831 int len, failed_count = 0;
d62a17ae 10832 int max_neighbor_width = 0;
10833 int pfx_rcd_safi;
3c13337d 10834 json_object *json = NULL;
d62a17ae 10835 json_object *json_peer = NULL;
10836 json_object *json_peers = NULL;
50e05855 10837 struct peer_af *paf;
d3ada366 10838 struct bgp_filter *filter;
85eeb029
DA
10839 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10840 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10841 bool show_established =
10842 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10843 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
d62a17ae 10844
10845 /* labeled-unicast routes are installed in the unicast table so in order
10846 * to
10847 * display the correct PfxRcd value we must look at SAFI_UNICAST
10848 */
3577f1c5 10849
d62a17ae 10850 if (safi == SAFI_LABELED_UNICAST)
10851 pfx_rcd_safi = SAFI_UNICAST;
10852 else
10853 pfx_rcd_safi = safi;
10854
10855 if (use_json) {
3c13337d 10856 json = json_object_new_object();
d62a17ae 10857 json_peers = json_object_new_object();
3577f1c5 10858 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10859 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10860 as_type, as)) {
10861 count++;
10862 continue;
10863 }
10864
3577f1c5
DD
10865 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10866 continue;
10867
10868 if (peer->afc[afi][safi]) {
10869 /* See if we have at least a single failed peer */
10870 if (bgp_has_peer_failed(peer, afi, safi))
10871 failed_count++;
10872 count++;
10873 }
10874 if (peer_dynamic_neighbor(peer))
10875 dn_count++;
10876 }
c258527b 10877
d62a17ae 10878 } else {
10879 /* Loop over all neighbors that will be displayed to determine
10880 * how many
10881 * characters are needed for the Neighbor column
10882 */
10883 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10884 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10885 as_type, as)) {
10886 count++;
10887 continue;
10888 }
10889
d62a17ae 10890 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10891 continue;
10892
10893 if (peer->afc[afi][safi]) {
10894 memset(dn_flag, '\0', sizeof(dn_flag));
10895 if (peer_dynamic_neighbor(peer))
10896 dn_flag[0] = '*';
10897
10898 if (peer->hostname
892fedb6
DA
10899 && CHECK_FLAG(bgp->flags,
10900 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10901 snprintf(neighbor_buf,
10902 sizeof(neighbor_buf),
10903 "%s%s(%s) ", dn_flag,
10904 peer->hostname, peer->host);
d62a17ae 10905 else
772270f3
QY
10906 snprintf(neighbor_buf,
10907 sizeof(neighbor_buf), "%s%s ",
10908 dn_flag, peer->host);
d62a17ae 10909
10910 len = strlen(neighbor_buf);
10911
10912 if (len > max_neighbor_width)
10913 max_neighbor_width = len;
c258527b 10914
3577f1c5
DD
10915 /* See if we have at least a single failed peer */
10916 if (bgp_has_peer_failed(peer, afi, safi))
10917 failed_count++;
10918 count++;
d62a17ae 10919 }
10920 }
f933309e 10921
d62a17ae 10922 /* Originally we displayed the Neighbor column as 16
10923 * characters wide so make that the default
10924 */
10925 if (max_neighbor_width < neighbor_col_default_width)
10926 max_neighbor_width = neighbor_col_default_width;
10927 }
f933309e 10928
3577f1c5
DD
10929 if (show_failed && !failed_count) {
10930 if (use_json) {
10931 json_object_int_add(json, "failedPeersCount", 0);
10932 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10933 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
10934
10935 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10936 json, JSON_C_TO_STRING_PRETTY));
10937 json_object_free(json);
10938 } else {
10939 vty_out(vty, "%% No failed BGP neighbors found\n");
10940 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10941 }
10942 return CMD_SUCCESS;
10943 }
c258527b 10944
3577f1c5 10945 count = 0; /* Reset the value as its used again */
d62a17ae 10946 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10947 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10948 continue;
10949
ea47320b
DL
10950 if (!peer->afc[afi][safi])
10951 continue;
d62a17ae 10952
ea47320b
DL
10953 if (!count) {
10954 unsigned long ents;
10955 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10956 int64_t vrf_id_ui;
d62a17ae 10957
a4d82a8a
PZ
10958 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10959 ? -1
10960 : (int64_t)bgp->vrf_id;
ea47320b
DL
10961
10962 /* Usage summary and header */
10963 if (use_json) {
23d0a753
DA
10964 char buf[BUFSIZ] = {0};
10965
ea47320b
DL
10966 json_object_string_add(
10967 json, "routerId",
23d0a753
DA
10968 inet_ntop(AF_INET, &bgp->router_id, buf,
10969 sizeof(buf)));
60466a63
QY
10970 json_object_int_add(json, "as", bgp->as);
10971 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10972 json_object_string_add(
10973 json, "vrfName",
10974 (bgp->inst_type
10975 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10976 ? VRF_DEFAULT_NAME
ea47320b
DL
10977 : bgp->name);
10978 } else {
10979 vty_out(vty,
23d0a753
DA
10980 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10981 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10982 bgp->vrf_id == VRF_UNKNOWN
10983 ? -1
10984 : (int)bgp->vrf_id);
ea47320b
DL
10985 vty_out(vty, "\n");
10986 }
d62a17ae 10987
ea47320b 10988 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10989 if (use_json) {
ea47320b 10990 json_object_int_add(
60466a63 10991 json, "updateDelayLimit",
ea47320b 10992 bgp->v_update_delay);
d62a17ae 10993
ea47320b
DL
10994 if (bgp->v_update_delay
10995 != bgp->v_establish_wait)
d62a17ae 10996 json_object_int_add(
10997 json,
ea47320b
DL
10998 "updateDelayEstablishWait",
10999 bgp->v_establish_wait);
d62a17ae 11000
60466a63 11001 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11002 json_object_string_add(
11003 json,
11004 "updateDelayFirstNeighbor",
11005 bgp->update_delay_begin_time);
11006 json_object_boolean_true_add(
11007 json,
11008 "updateDelayInProgress");
11009 } else {
11010 if (bgp->update_delay_over) {
d62a17ae 11011 json_object_string_add(
11012 json,
11013 "updateDelayFirstNeighbor",
11014 bgp->update_delay_begin_time);
ea47320b 11015 json_object_string_add(
d62a17ae 11016 json,
ea47320b
DL
11017 "updateDelayBestpathResumed",
11018 bgp->update_delay_end_time);
11019 json_object_string_add(
d62a17ae 11020 json,
ea47320b
DL
11021 "updateDelayZebraUpdateResume",
11022 bgp->update_delay_zebra_resume_time);
11023 json_object_string_add(
11024 json,
11025 "updateDelayPeerUpdateResume",
11026 bgp->update_delay_peers_resume_time);
d62a17ae 11027 }
ea47320b
DL
11028 }
11029 } else {
11030 vty_out(vty,
11031 "Read-only mode update-delay limit: %d seconds\n",
11032 bgp->v_update_delay);
11033 if (bgp->v_update_delay
11034 != bgp->v_establish_wait)
d62a17ae 11035 vty_out(vty,
ea47320b
DL
11036 " Establish wait: %d seconds\n",
11037 bgp->v_establish_wait);
d62a17ae 11038
60466a63 11039 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
11040 vty_out(vty,
11041 " First neighbor established: %s\n",
11042 bgp->update_delay_begin_time);
11043 vty_out(vty,
11044 " Delay in progress\n");
11045 } else {
11046 if (bgp->update_delay_over) {
d62a17ae 11047 vty_out(vty,
11048 " First neighbor established: %s\n",
11049 bgp->update_delay_begin_time);
11050 vty_out(vty,
ea47320b
DL
11051 " Best-paths resumed: %s\n",
11052 bgp->update_delay_end_time);
11053 vty_out(vty,
11054 " zebra update resumed: %s\n",
11055 bgp->update_delay_zebra_resume_time);
11056 vty_out(vty,
11057 " peers update resumed: %s\n",
11058 bgp->update_delay_peers_resume_time);
d62a17ae 11059 }
11060 }
11061 }
ea47320b 11062 }
d62a17ae 11063
ea47320b
DL
11064 if (use_json) {
11065 if (bgp_maxmed_onstartup_configured(bgp)
11066 && bgp->maxmed_active)
11067 json_object_boolean_true_add(
60466a63 11068 json, "maxMedOnStartup");
ea47320b
DL
11069 if (bgp->v_maxmed_admin)
11070 json_object_boolean_true_add(
60466a63 11071 json, "maxMedAdministrative");
d62a17ae 11072
ea47320b
DL
11073 json_object_int_add(
11074 json, "tableVersion",
60466a63 11075 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 11076
60466a63
QY
11077 ents = bgp_table_count(bgp->rib[afi][safi]);
11078 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
11079 json_object_int_add(
11080 json, "ribMemory",
9bcb3eef 11081 ents * sizeof(struct bgp_dest));
d62a17ae 11082
210ec2a0 11083 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
11084 json_object_int_add(json, "peerCount", ents);
11085 json_object_int_add(json, "peerMemory",
11086 ents * sizeof(struct peer));
d62a17ae 11087
ea47320b
DL
11088 if ((ents = listcount(bgp->group))) {
11089 json_object_int_add(
60466a63 11090 json, "peerGroupCount", ents);
ea47320b
DL
11091 json_object_int_add(
11092 json, "peerGroupMemory",
996c9314
LB
11093 ents * sizeof(struct
11094 peer_group));
ea47320b 11095 }
d62a17ae 11096
ea47320b
DL
11097 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11098 BGP_CONFIG_DAMPENING))
11099 json_object_boolean_true_add(
60466a63 11100 json, "dampeningEnabled");
ea47320b
DL
11101 } else {
11102 if (bgp_maxmed_onstartup_configured(bgp)
11103 && bgp->maxmed_active)
d62a17ae 11104 vty_out(vty,
ea47320b
DL
11105 "Max-med on-startup active\n");
11106 if (bgp->v_maxmed_admin)
d62a17ae 11107 vty_out(vty,
ea47320b 11108 "Max-med administrative active\n");
d62a17ae 11109
60466a63
QY
11110 vty_out(vty, "BGP table version %" PRIu64 "\n",
11111 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 11112
60466a63 11113 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
11114 vty_out(vty,
11115 "RIB entries %ld, using %s of memory\n",
11116 ents,
9bcb3eef
DS
11117 mtype_memstr(
11118 memstrbuf, sizeof(memstrbuf),
11119 ents
11120 * sizeof(struct
11121 bgp_dest)));
ea47320b
DL
11122
11123 /* Peer related usage */
210ec2a0 11124 ents = bgp->af_peer_count[afi][safi];
60466a63 11125 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
11126 ents,
11127 mtype_memstr(
60466a63
QY
11128 memstrbuf, sizeof(memstrbuf),
11129 ents * sizeof(struct peer)));
ea47320b
DL
11130
11131 if ((ents = listcount(bgp->group)))
d62a17ae 11132 vty_out(vty,
ea47320b 11133 "Peer groups %ld, using %s of memory\n",
d62a17ae 11134 ents,
11135 mtype_memstr(
11136 memstrbuf,
11137 sizeof(memstrbuf),
996c9314
LB
11138 ents * sizeof(struct
11139 peer_group)));
d62a17ae 11140
ea47320b
DL
11141 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11142 BGP_CONFIG_DAMPENING))
60466a63 11143 vty_out(vty, "Dampening enabled.\n");
ea47320b 11144 vty_out(vty, "\n");
d62a17ae 11145
ea47320b
DL
11146 /* Subtract 8 here because 'Neighbor' is
11147 * 8 characters */
11148 vty_out(vty, "Neighbor");
60466a63
QY
11149 vty_out(vty, "%*s", max_neighbor_width - 8,
11150 " ");
3577f1c5 11151 if (show_failed)
85eeb029
DA
11152 vty_out(vty,
11153 BGP_SHOW_SUMMARY_HEADER_FAILED);
3577f1c5
DD
11154 else
11155 vty_out(vty,
85eeb029
DA
11156 show_wide
11157 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11158 : BGP_SHOW_SUMMARY_HEADER_ALL);
d62a17ae 11159 }
ea47320b 11160 }
d62a17ae 11161
d55811cc 11162 paf = peer_af_find(peer, afi, safi);
d3ada366 11163 filter = &peer->filter[afi][safi];
db92d226 11164
ea47320b 11165 count++;
3577f1c5
DD
11166 /* Works for both failed & successful cases */
11167 if (peer_dynamic_neighbor(peer))
11168 dn_count++;
d62a17ae 11169
ea47320b 11170 if (use_json) {
3577f1c5
DD
11171 json_peer = NULL;
11172
8c1d4cd5
LS
11173 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11174 as_type, as))
11175 continue;
11176
3577f1c5
DD
11177 if (show_failed &&
11178 bgp_has_peer_failed(peer, afi, safi)) {
11179 json_peer = json_object_new_object();
11180 bgp_show_failed_summary(vty, bgp, peer,
11181 json_peer, 0, use_json);
11182 } else if (!show_failed) {
10b49f14
DA
11183 if (show_established
11184 && bgp_has_peer_failed(peer, afi, safi))
11185 continue;
11186
3577f1c5
DD
11187 json_peer = json_object_new_object();
11188 if (peer_dynamic_neighbor(peer)) {
11189 json_object_boolean_true_add(json_peer,
11190 "dynamicPeer");
11191 }
d62a17ae 11192
3577f1c5
DD
11193 if (peer->hostname)
11194 json_object_string_add(json_peer, "hostname",
11195 peer->hostname);
11196
11197 if (peer->domainname)
11198 json_object_string_add(json_peer, "domainname",
11199 peer->domainname);
11200
11201 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
11202 json_object_int_add(
11203 json_peer, "localAs",
11204 peer->change_local_as
11205 ? peer->change_local_as
11206 : peer->local_as);
3577f1c5
DD
11207 json_object_int_add(json_peer, "version", 4);
11208 json_object_int_add(json_peer, "msgRcvd",
11209 PEER_TOTAL_RX(peer));
11210 json_object_int_add(json_peer, "msgSent",
11211 PEER_TOTAL_TX(peer));
11212
43aa5965
QY
11213 atomic_size_t outq_count, inq_count;
11214 outq_count = atomic_load_explicit(
11215 &peer->obuf->count,
11216 memory_order_relaxed);
11217 inq_count = atomic_load_explicit(
11218 &peer->ibuf->count,
11219 memory_order_relaxed);
11220
3577f1c5
DD
11221 json_object_int_add(json_peer, "tableVersion",
11222 peer->version[afi][safi]);
11223 json_object_int_add(json_peer, "outq",
43aa5965
QY
11224 outq_count);
11225 json_object_int_add(json_peer, "inq",
11226 inq_count);
3577f1c5
DD
11227 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11228 use_json, json_peer);
11229
3577f1c5
DD
11230 json_object_int_add(json_peer, "pfxRcd",
11231 peer->pcount[afi][pfx_rcd_safi]);
11232
3577f1c5 11233 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11234 json_object_int_add(
11235 json_peer, "pfxSnt",
11236 (PAF_SUBGRP(paf))->scount);
11237 else
11238 json_object_int_add(json_peer, "pfxSnt",
11239 0);
0e1f8ab5
DA
11240
11241 /* BGP FSM state */
cb9196e7 11242 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11243 || CHECK_FLAG(peer->bgp->flags,
11244 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11245 json_object_string_add(json_peer,
11246 "state",
3577f1c5
DD
11247 "Idle (Admin)");
11248 else if (peer->afc_recv[afi][safi])
11249 json_object_string_add(
0e1f8ab5
DA
11250 json_peer, "state",
11251 lookup_msg(bgp_status_msg,
11252 peer->status, NULL));
11253 else if (CHECK_FLAG(
11254 peer->sflags,
11255 PEER_STATUS_PREFIX_OVERFLOW))
11256 json_object_string_add(json_peer,
11257 "state",
3577f1c5
DD
11258 "Idle (PfxCt)");
11259 else
11260 json_object_string_add(
0e1f8ab5
DA
11261 json_peer, "state",
11262 lookup_msg(bgp_status_msg,
11263 peer->status, NULL));
11264
11265 /* BGP peer state */
11266 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11267 || CHECK_FLAG(peer->bgp->flags,
11268 BGP_FLAG_SHUTDOWN))
11269 json_object_string_add(json_peer,
11270 "peerState",
11271 "Admin");
11272 else if (CHECK_FLAG(
11273 peer->sflags,
11274 PEER_STATUS_PREFIX_OVERFLOW))
11275 json_object_string_add(json_peer,
11276 "peerState",
11277 "PfxCt");
11278 else if (CHECK_FLAG(peer->flags,
11279 PEER_FLAG_PASSIVE))
11280 json_object_string_add(json_peer,
11281 "peerState",
11282 "Passive");
11283 else if (CHECK_FLAG(peer->sflags,
11284 PEER_STATUS_NSF_WAIT))
11285 json_object_string_add(json_peer,
11286 "peerState",
11287 "NSF passive");
11288 else if (CHECK_FLAG(
11289 peer->bgp->flags,
11290 BGP_FLAG_EBGP_REQUIRES_POLICY)
11291 && (!bgp_inbound_policy_exists(peer,
11292 filter)
11293 || !bgp_outbound_policy_exists(
11294 peer, filter)))
11295 json_object_string_add(json_peer,
11296 "peerState",
11297 "Policy");
11298 else
11299 json_object_string_add(
11300 json_peer, "peerState", "OK");
11301
200116db
DD
11302 json_object_int_add(json_peer, "connectionsEstablished",
11303 peer->established);
11304 json_object_int_add(json_peer, "connectionsDropped",
11305 peer->dropped);
aa72bd7e
PG
11306 if (peer->desc)
11307 json_object_string_add(
11308 json_peer, "desc", peer->desc);
b4e9dcba 11309 }
3577f1c5
DD
11310 /* Avoid creating empty peer dicts in JSON */
11311 if (json_peer == NULL)
11312 continue;
ea47320b
DL
11313
11314 if (peer->conf_if)
60466a63 11315 json_object_string_add(json_peer, "idType",
ea47320b
DL
11316 "interface");
11317 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11318 json_object_string_add(json_peer, "idType",
11319 "ipv4");
ea47320b 11320 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11321 json_object_string_add(json_peer, "idType",
11322 "ipv6");
ea47320b
DL
11323 json_object_object_add(json_peers, peer->host,
11324 json_peer);
11325 } else {
8c1d4cd5
LS
11326 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11327 as_type, as))
11328 continue;
3577f1c5
DD
11329 if (show_failed &&
11330 bgp_has_peer_failed(peer, afi, safi)) {
11331 bgp_show_failed_summary(vty, bgp, peer, NULL,
11332 max_neighbor_width,
11333 use_json);
11334 } else if (!show_failed) {
10b49f14
DA
11335 if (show_established
11336 && bgp_has_peer_failed(peer, afi, safi))
11337 continue;
3577f1c5
DD
11338 memset(dn_flag, '\0', sizeof(dn_flag));
11339 if (peer_dynamic_neighbor(peer)) {
11340 dn_flag[0] = '*';
11341 }
d62a17ae 11342
3577f1c5 11343 if (peer->hostname
892fedb6
DA
11344 && CHECK_FLAG(bgp->flags,
11345 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11346 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11347 peer->hostname,
11348 peer->host);
d62a17ae 11349 else
3577f1c5
DD
11350 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11351
11352 /* pad the neighbor column with spaces */
11353 if (len < max_neighbor_width)
11354 vty_out(vty, "%*s", max_neighbor_width - len,
11355 " ");
11356
43aa5965
QY
11357 atomic_size_t outq_count, inq_count;
11358 outq_count = atomic_load_explicit(
11359 &peer->obuf->count,
11360 memory_order_relaxed);
11361 inq_count = atomic_load_explicit(
11362 &peer->ibuf->count,
11363 memory_order_relaxed);
11364
85eeb029
DA
11365 if (show_wide)
11366 vty_out(vty,
11367 "4 %10u %10u %9u %9u %8" PRIu64
11368 " %4zu %4zu %8s",
11369 peer->as,
11370 peer->change_local_as
11371 ? peer->change_local_as
11372 : peer->local_as,
11373 PEER_TOTAL_RX(peer),
11374 PEER_TOTAL_TX(peer),
11375 peer->version[afi][safi],
11376 inq_count, outq_count,
11377 peer_uptime(peer->uptime,
11378 timebuf,
11379 BGP_UPTIME_LEN, 0,
11380 NULL));
11381 else
11382 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11383 " %4zu %4zu %8s",
11384 peer->as, PEER_TOTAL_RX(peer),
11385 PEER_TOTAL_TX(peer),
11386 peer->version[afi][safi],
11387 inq_count, outq_count,
11388 peer_uptime(peer->uptime,
11389 timebuf,
11390 BGP_UPTIME_LEN, 0,
11391 NULL));
3577f1c5 11392
db92d226 11393 if (peer->status == Established) {
d3ada366
DA
11394 if (peer->afc_recv[afi][safi]) {
11395 if (CHECK_FLAG(
11396 bgp->flags,
11397 BGP_FLAG_EBGP_REQUIRES_POLICY)
11398 && !bgp_inbound_policy_exists(
11399 peer, filter))
11400 vty_out(vty, " %12s",
11401 "(Policy)");
11402 else
11403 vty_out(vty,
6cde4b45 11404 " %12u",
d3ada366
DA
11405 peer->pcount
11406 [afi]
11407 [pfx_rcd_safi]);
11408 } else {
749d0f27 11409 vty_out(vty, " NoNeg");
d3ada366 11410 }
db92d226 11411
d3ada366
DA
11412 if (paf && PAF_SUBGRP(paf)) {
11413 if (CHECK_FLAG(
11414 bgp->flags,
11415 BGP_FLAG_EBGP_REQUIRES_POLICY)
11416 && !bgp_outbound_policy_exists(
11417 peer, filter))
11418 vty_out(vty, " %8s",
11419 "(Policy)");
11420 else
11421 vty_out(vty,
6cde4b45 11422 " %8u",
d3ada366
DA
11423 (PAF_SUBGRP(
11424 paf))
11425 ->scount);
749d0f27
DA
11426 } else {
11427 vty_out(vty, " NoNeg");
d3ada366 11428 }
db92d226 11429 } else {
736b68f3
DS
11430 if (CHECK_FLAG(peer->flags,
11431 PEER_FLAG_SHUTDOWN)
11432 || CHECK_FLAG(peer->bgp->flags,
11433 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11434 vty_out(vty, " Idle (Admin)");
11435 else if (CHECK_FLAG(
11436 peer->sflags,
11437 PEER_STATUS_PREFIX_OVERFLOW))
11438 vty_out(vty, " Idle (PfxCt)");
11439 else
11440 vty_out(vty, " %12s",
11441 lookup_msg(bgp_status_msg,
11442 peer->status, NULL));
db92d226 11443
6cde4b45 11444 vty_out(vty, " %8u", 0);
3577f1c5 11445 }
aa72bd7e 11446 if (peer->desc)
cb75bb31
DA
11447 vty_out(vty, " %s",
11448 bgp_peer_description_stripped(
85eeb029
DA
11449 peer->desc,
11450 show_wide ? 64 : 20));
aa72bd7e
PG
11451 else
11452 vty_out(vty, " N/A");
3577f1c5 11453 vty_out(vty, "\n");
d62a17ae 11454 }
3577f1c5 11455
d62a17ae 11456 }
11457 }
f933309e 11458
d62a17ae 11459 if (use_json) {
11460 json_object_object_add(json, "peers", json_peers);
3577f1c5 11461 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 11462 json_object_int_add(json, "totalPeers", count);
11463 json_object_int_add(json, "dynamicPeers", dn_count);
11464
3577f1c5
DD
11465 if (!show_failed)
11466 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11467
996c9314
LB
11468 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11469 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11470 json_object_free(json);
11471 } else {
11472 if (count)
11473 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11474 else {
d6ceaca3 11475 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11476 get_afi_safi_str(afi, safi, false));
d62a17ae 11477 }
b05a1c8b 11478
d6ceaca3 11479 if (dn_count) {
d62a17ae 11480 vty_out(vty, "* - dynamic neighbor\n");
11481 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11482 dn_count, bgp->dynamic_neighbors_limit);
11483 }
11484 }
1ff9a340 11485
d62a17ae 11486 return CMD_SUCCESS;
718e3744 11487}
11488
d62a17ae 11489static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5
LS
11490 int safi, struct peer *fpeer, int as_type,
11491 as_t as, uint8_t show_flags)
d62a17ae 11492{
11493 int is_first = 1;
11494 int afi_wildcard = (afi == AFI_MAX);
11495 int safi_wildcard = (safi == SAFI_MAX);
11496 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11497 bool nbr_output = false;
85eeb029 11498 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11499
11500 if (use_json && is_wildcard)
11501 vty_out(vty, "{\n");
11502 if (afi_wildcard)
11503 afi = 1; /* AFI_IP */
11504 while (afi < AFI_MAX) {
11505 if (safi_wildcard)
11506 safi = 1; /* SAFI_UNICAST */
11507 while (safi < SAFI_MAX) {
318cac96 11508 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11509 nbr_output = true;
f86897b9 11510
d62a17ae 11511 if (is_wildcard) {
11512 /*
11513 * So limit output to those afi/safi
11514 * pairs that
11515 * actualy have something interesting in
11516 * them
11517 */
11518 if (use_json) {
d62a17ae 11519 if (!is_first)
11520 vty_out(vty, ",\n");
11521 else
11522 is_first = 0;
11523
11524 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11525 get_afi_safi_str(afi,
11526 safi,
11527 true));
d62a17ae 11528 } else {
11529 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
11530 get_afi_safi_str(afi,
11531 safi,
11532 false));
d62a17ae 11533 }
11534 }
8c1d4cd5
LS
11535 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11536 as_type, as, show_flags);
d62a17ae 11537 }
11538 safi++;
d62a17ae 11539 if (!safi_wildcard)
11540 safi = SAFI_MAX;
11541 }
11542 afi++;
ee851c8c 11543 if (!afi_wildcard)
d62a17ae 11544 afi = AFI_MAX;
11545 }
11546
11547 if (use_json && is_wildcard)
11548 vty_out(vty, "}\n");
ca61fd25
DS
11549 else if (!nbr_output) {
11550 if (use_json)
11551 vty_out(vty, "{}\n");
11552 else
11553 vty_out(vty, "%% No BGP neighbors found\n");
11554 }
d62a17ae 11555}
11556
11557static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11558 safi_t safi,
11559 const char *neighbor,
11560 int as_type, as_t as,
11561 uint8_t show_flags)
d62a17ae 11562{
11563 struct listnode *node, *nnode;
11564 struct bgp *bgp;
8c1d4cd5 11565 struct peer *fpeer = NULL;
d62a17ae 11566 int is_first = 1;
9f049418 11567 bool nbr_output = false;
85eeb029 11568 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11569
11570 if (use_json)
11571 vty_out(vty, "{\n");
11572
11573 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11574 nbr_output = true;
d62a17ae 11575 if (use_json) {
d62a17ae 11576 if (!is_first)
11577 vty_out(vty, ",\n");
11578 else
11579 is_first = 0;
11580
11581 vty_out(vty, "\"%s\":",
11582 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11583 ? VRF_DEFAULT_NAME
d62a17ae 11584 : bgp->name);
11585 } else {
11586 vty_out(vty, "\nInstance %s:\n",
11587 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11588 ? VRF_DEFAULT_NAME
d62a17ae 11589 : bgp->name);
11590 }
8c1d4cd5
LS
11591 if (neighbor) {
11592 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11593 use_json);
11594 if (!fpeer)
11595 continue;
11596 }
11597 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11598 as, show_flags);
d62a17ae 11599 }
11600
11601 if (use_json)
11602 vty_out(vty, "}\n");
9f049418
DS
11603 else if (!nbr_output)
11604 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11605}
11606
11607int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5
LS
11608 safi_t safi, const char *neighbor, int as_type,
11609 as_t as, uint8_t show_flags)
d62a17ae 11610{
11611 struct bgp *bgp;
85eeb029 11612 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11613 struct peer *fpeer = NULL;
d62a17ae 11614
11615 if (name) {
11616 if (strmatch(name, "all")) {
85eeb029 11617 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11618 neighbor, as_type,
11619 as, show_flags);
d62a17ae 11620 return CMD_SUCCESS;
11621 } else {
11622 bgp = bgp_lookup_by_name(name);
11623
11624 if (!bgp) {
11625 if (use_json)
11626 vty_out(vty, "{}\n");
11627 else
11628 vty_out(vty,
ca61fd25 11629 "%% BGP instance not found\n");
d62a17ae 11630 return CMD_WARNING;
11631 }
11632
8c1d4cd5
LS
11633 if (neighbor) {
11634 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11635 use_json);
11636 if (!fpeer)
11637 return CMD_WARNING;
11638 }
11639 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11640 as_type, as, show_flags);
d62a17ae 11641 return CMD_SUCCESS;
11642 }
11643 }
11644
11645 bgp = bgp_get_default();
11646
8c1d4cd5
LS
11647 if (bgp) {
11648 if (neighbor) {
11649 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11650 use_json);
11651 if (!fpeer)
11652 return CMD_WARNING;
11653 }
11654 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11655 as, show_flags);
11656 } else {
ca61fd25
DS
11657 if (use_json)
11658 vty_out(vty, "{}\n");
11659 else
11660 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11661 return CMD_WARNING;
11662 }
d62a17ae 11663
11664 return CMD_SUCCESS;
4fb25c53
DW
11665}
11666
716b2d8a 11667/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11668DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11669 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11670 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11671 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [wide] [json$uj]",
11672 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11673 BGP_SAFI_WITH_LABEL_HELP_STR
11674 "Display the entries for all address families\n"
11675 "Summary of BGP neighbor status\n"
11676 "Show only sessions in Established state\n"
11677 "Show only sessions not in Established state\n"
11678 "Show only the specified neighbor session\n"
11679 "Neighbor to display information about\n"
11680 "Neighbor to display information about\n"
11681 "Neighbor on BGP configured interface\n"
11682 "Show only the specified remote AS sessions\n"
11683 "AS number\n"
11684 "Internal (iBGP) AS sessions\n"
11685 "External (eBGP) AS sessions\n"
11686 "Increase table width for longer output\n" JSON_STR)
718e3744 11687{
d62a17ae 11688 char *vrf = NULL;
11689 afi_t afi = AFI_MAX;
11690 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11691 as_t as = 0; /* 0 means AS filter not set */
11692 int as_type = AS_UNSPECIFIED;
85eeb029 11693 uint8_t show_flags = 0;
d62a17ae 11694
11695 int idx = 0;
11696
11697 /* show [ip] bgp */
96f3485c 11698 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11699 afi = AFI_IP;
9a8bdf1c
PG
11700 /* [<vrf> VIEWVRFNAME] */
11701 if (argv_find(argv, argc, "vrf", &idx)) {
11702 vrf = argv[idx + 1]->arg;
11703 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11704 vrf = NULL;
11705 } else if (argv_find(argv, argc, "view", &idx))
11706 /* [<view> VIEWVRFNAME] */
11707 vrf = argv[idx + 1]->arg;
d62a17ae 11708 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11709 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11710 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11711 }
11712
3577f1c5 11713 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11714 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11715
10b49f14 11716 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11717 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11718
8c1d4cd5
LS
11719 if (argv_find(argv, argc, "remote-as", &idx)) {
11720 if (argv[idx + 1]->arg[0] == 'i')
11721 as_type = AS_INTERNAL;
11722 else if (argv[idx + 1]->arg[0] == 'e')
11723 as_type = AS_EXTERNAL;
11724 else
11725 as = (as_t)atoi(argv[idx + 1]->arg);
11726 }
11727
85eeb029
DA
11728 if (argv_find(argv, argc, "wide", &idx))
11729 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11730
11731 if (argv_find(argv, argc, "json", &idx))
11732 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11733
8c1d4cd5
LS
11734 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11735 show_flags);
d62a17ae 11736}
11737
5cb5f4d0 11738const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11739{
5cb5f4d0
DD
11740 if (for_json)
11741 return get_afi_safi_json_str(afi, safi);
d62a17ae 11742 else
5cb5f4d0 11743 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11744}
11745
d62a17ae 11746
11747static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11748 afi_t afi, safi_t safi,
d7c0a89a
QY
11749 uint16_t adv_smcap, uint16_t adv_rmcap,
11750 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11751 bool use_json, json_object *json_pref)
d62a17ae 11752{
11753 /* Send-Mode */
11754 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11755 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11756 if (use_json) {
11757 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11758 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11759 json_object_string_add(json_pref, "sendMode",
11760 "advertisedAndReceived");
11761 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11762 json_object_string_add(json_pref, "sendMode",
11763 "advertised");
11764 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11765 json_object_string_add(json_pref, "sendMode",
11766 "received");
11767 } else {
11768 vty_out(vty, " Send-mode: ");
11769 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11770 vty_out(vty, "advertised");
11771 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11772 vty_out(vty, "%sreceived",
11773 CHECK_FLAG(p->af_cap[afi][safi],
11774 adv_smcap)
11775 ? ", "
11776 : "");
11777 vty_out(vty, "\n");
11778 }
11779 }
11780
11781 /* Receive-Mode */
11782 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11783 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11784 if (use_json) {
11785 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11786 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11787 json_object_string_add(json_pref, "recvMode",
11788 "advertisedAndReceived");
11789 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11790 json_object_string_add(json_pref, "recvMode",
11791 "advertised");
11792 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11793 json_object_string_add(json_pref, "recvMode",
11794 "received");
11795 } else {
11796 vty_out(vty, " Receive-mode: ");
11797 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11798 vty_out(vty, "advertised");
11799 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11800 vty_out(vty, "%sreceived",
11801 CHECK_FLAG(p->af_cap[afi][safi],
11802 adv_rmcap)
11803 ? ", "
11804 : "");
11805 vty_out(vty, "\n");
11806 }
11807 }
11808}
11809
13909c4f
DS
11810static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11811 struct peer *p,
11812 bool use_json,
11813 json_object *json)
2986cac2 11814{
08c2d52a 11815 bool rbit_status = false;
2986cac2 11816
11817 if (!use_json)
a53ca37b 11818 vty_out(vty, "\n R bit: ");
2986cac2 11819
13909c4f
DS
11820 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11821 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11822 && (p->status == Established)) {
2986cac2 11823
11824 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11825 rbit_status = true;
2986cac2 11826 else
08c2d52a 11827 rbit_status = false;
2986cac2 11828 }
11829
11830 if (rbit_status) {
11831 if (use_json)
13909c4f 11832 json_object_boolean_true_add(json, "rBit");
2986cac2 11833 else
11834 vty_out(vty, "True\n");
11835 } else {
11836 if (use_json)
13909c4f 11837 json_object_boolean_false_add(json, "rBit");
2986cac2 11838 else
11839 vty_out(vty, "False\n");
11840 }
11841}
11842
13909c4f
DS
11843static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11844 struct peer *peer,
11845 bool use_json,
11846 json_object *json)
2986cac2 11847{
2bb5d39b 11848 const char *mode = "NotApplicable";
2986cac2 11849
11850 if (!use_json)
a53ca37b 11851 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11852
13909c4f
DS
11853 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11854 && (peer->status == Established)) {
2986cac2 11855
13909c4f
DS
11856 if ((peer->nsf_af_count == 0)
11857 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11858
2986cac2 11859 mode = "Disable";
11860
13909c4f
DS
11861 } else if (peer->nsf_af_count == 0
11862 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11863
2986cac2 11864 mode = "Helper";
11865
13909c4f
DS
11866 } else if (peer->nsf_af_count != 0
11867 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11868
2986cac2 11869 mode = "Restart";
2986cac2 11870 }
11871 }
11872
11873 if (use_json) {
13909c4f 11874 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11875 } else
11876 vty_out(vty, mode, "\n");
11877}
11878
13909c4f
DS
11879static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11880 struct peer *p,
11881 bool use_json,
11882 json_object *json)
2986cac2 11883{
11884 const char *mode = "Invalid";
11885
11886 if (!use_json)
a53ca37b 11887 vty_out(vty, " Local GR Mode: ");
2986cac2 11888
11889 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11890 mode = "Helper";
11891 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11892 mode = "Restart";
11893 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11894 mode = "Disable";
2ba1fe69 11895 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11896 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11897 mode = "Helper*";
11898 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11899 mode = "Restart*";
11900 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11901 mode = "Disable*";
11902 else
11903 mode = "Invalid*";
2ba1fe69 11904 }
2986cac2 11905
11906 if (use_json) {
13909c4f 11907 json_object_string_add(json, "localGrMode", mode);
2986cac2 11908 } else {
11909 vty_out(vty, mode, "\n");
11910 }
11911}
11912
13909c4f
DS
11913static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11914 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11915{
2ba1fe69 11916 afi_t afi;
11917 safi_t safi;
2986cac2 11918 json_object *json_afi_safi = NULL;
11919 json_object *json_timer = NULL;
11920 json_object *json_endofrib_status = NULL;
9e3b51a7 11921 bool eor_flag = false;
2986cac2 11922
11923 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11924 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
11925 if (!peer->afc[afi][safi])
11926 continue;
2986cac2 11927
13909c4f
DS
11928 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11929 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11930 continue;
9e3b51a7 11931
13909c4f
DS
11932 if (use_json) {
11933 json_afi_safi = json_object_new_object();
11934 json_endofrib_status = json_object_new_object();
11935 json_timer = json_object_new_object();
11936 }
2986cac2 11937
13909c4f
DS
11938 if (peer->eor_stime[afi][safi]
11939 >= peer->pkt_stime[afi][safi])
11940 eor_flag = true;
11941 else
11942 eor_flag = false;
2986cac2 11943
13909c4f 11944 if (!use_json) {
a53ca37b 11945 vty_out(vty, " %s:\n",
13909c4f 11946 get_afi_safi_str(afi, safi, false));
2986cac2 11947
a53ca37b 11948 vty_out(vty, " F bit: ");
698ba8d0 11949 }
2986cac2 11950
13909c4f
DS
11951 if (peer->nsf[afi][safi]
11952 && CHECK_FLAG(peer->af_cap[afi][safi],
11953 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11954
13909c4f
DS
11955 if (use_json) {
11956 json_object_boolean_true_add(
2986cac2 11957 json_afi_safi, "fBit");
13909c4f
DS
11958 } else
11959 vty_out(vty, "True\n");
11960 } else {
11961 if (use_json)
11962 json_object_boolean_false_add(
11963 json_afi_safi, "fBit");
11964 else
11965 vty_out(vty, "False\n");
11966 }
2986cac2 11967
13909c4f 11968 if (!use_json)
a53ca37b 11969 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11970
13909c4f
DS
11971 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11972 PEER_STATUS_EOR_SEND)) {
11973 if (use_json) {
11974 json_object_boolean_true_add(
2986cac2 11975 json_endofrib_status,
13909c4f 11976 "endOfRibSend");
9e3b51a7 11977
13909c4f
DS
11978 PRINT_EOR_JSON(eor_flag);
11979 } else {
11980 vty_out(vty, "Yes\n");
11981 vty_out(vty,
a53ca37b 11982 " End-of-RIB sent after update: ");
2986cac2 11983
13909c4f
DS
11984 PRINT_EOR(eor_flag);
11985 }
11986 } else {
11987 if (use_json) {
11988 json_object_boolean_false_add(
2986cac2 11989 json_endofrib_status,
13909c4f
DS
11990 "endOfRibSend");
11991 json_object_boolean_false_add(
9e3b51a7 11992 json_endofrib_status,
13909c4f
DS
11993 "endOfRibSentAfterUpdate");
11994 } else {
11995 vty_out(vty, "No\n");
11996 vty_out(vty,
a53ca37b 11997 " End-of-RIB sent after update: ");
13909c4f 11998 vty_out(vty, "No\n");
2986cac2 11999 }
13909c4f 12000 }
2986cac2 12001
a53ca37b
DA
12002 if (!use_json)
12003 vty_out(vty, " End-of-RIB received: ");
12004
12005 if (CHECK_FLAG(peer->af_sflags[afi][safi],
12006 PEER_STATUS_EOR_RECEIVED)) {
12007 if (use_json)
12008 json_object_boolean_true_add(
12009 json_endofrib_status,
12010 "endOfRibRecv");
12011 else
12012 vty_out(vty, "Yes\n");
12013 } else {
12014 if (use_json)
12015 json_object_boolean_false_add(
12016 json_endofrib_status,
12017 "endOfRibRecv");
12018 else
12019 vty_out(vty, "No\n");
12020 }
12021
13909c4f
DS
12022 if (use_json) {
12023 json_object_int_add(json_timer,
12024 "stalePathTimer",
12025 peer->bgp->stalepath_time);
2986cac2 12026
13909c4f
DS
12027 if (peer->t_gr_stale != NULL) {
12028 json_object_int_add(
2986cac2 12029 json_timer,
12030 "stalePathTimerRemaining",
12031 thread_timer_remain_second(
13909c4f
DS
12032 peer->t_gr_stale));
12033 }
3a75afa4 12034
13909c4f
DS
12035 /* Display Configured Selection
12036 * Deferral only when when
12037 * Gr mode is enabled.
12038 */
12039 if (CHECK_FLAG(peer->flags,
12040 PEER_FLAG_GRACEFUL_RESTART)) {
12041 json_object_int_add(
3a75afa4 12042 json_timer,
2986cac2 12043 "selectionDeferralTimer",
12044 peer->bgp->stalepath_time);
13909c4f 12045 }
2986cac2 12046
13909c4f
DS
12047 if (peer->bgp->gr_info[afi][safi]
12048 .t_select_deferral
12049 != NULL) {
2986cac2 12050
13909c4f 12051 json_object_int_add(
2986cac2 12052 json_timer,
12053 "selectionDeferralTimerRemaining",
12054 thread_timer_remain_second(
13909c4f
DS
12055 peer->bgp
12056 ->gr_info[afi]
12057 [safi]
12058 .t_select_deferral));
12059 }
12060 } else {
a53ca37b 12061 vty_out(vty, " Timers:\n");
13909c4f 12062 vty_out(vty,
a53ca37b
DA
12063 " Configured Stale Path Time(sec): %u\n",
12064 peer->bgp->stalepath_time);
2986cac2 12065
a53ca37b 12066 if (peer->t_gr_stale != NULL)
2986cac2 12067 vty_out(vty,
a53ca37b 12068 " Stale Path Remaining(sec): %ld\n",
2986cac2 12069 thread_timer_remain_second(
13909c4f 12070 peer->t_gr_stale));
13909c4f
DS
12071 /* Display Configured Selection
12072 * Deferral only when when
12073 * Gr mode is enabled.
12074 */
12075 if (CHECK_FLAG(peer->flags,
a53ca37b 12076 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 12077 vty_out(vty,
a53ca37b 12078 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 12079 peer->bgp->select_defer_time);
2986cac2 12080
13909c4f
DS
12081 if (peer->bgp->gr_info[afi][safi]
12082 .t_select_deferral
a53ca37b 12083 != NULL)
13909c4f 12084 vty_out(vty,
a53ca37b 12085 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 12086 thread_timer_remain_second(
13909c4f
DS
12087 peer->bgp
12088 ->gr_info[afi]
12089 [safi]
12090 .t_select_deferral));
2986cac2 12091 }
13909c4f
DS
12092 if (use_json) {
12093 json_object_object_add(json_afi_safi,
12094 "endOfRibStatus",
12095 json_endofrib_status);
12096 json_object_object_add(json_afi_safi, "timers",
12097 json_timer);
12098 json_object_object_add(
12099 json, get_afi_safi_str(afi, safi, true),
12100 json_afi_safi);
12101 }
2986cac2 12102 }
12103 }
12104}
12105
36235319
QY
12106static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12107 struct peer *p,
12108 bool use_json,
12109 json_object *json)
2986cac2 12110{
12111 if (use_json) {
12112 json_object *json_timer = NULL;
12113
12114 json_timer = json_object_new_object();
12115
13909c4f
DS
12116 json_object_int_add(json_timer, "configuredRestartTimer",
12117 p->bgp->restart_time);
2986cac2 12118
13909c4f
DS
12119 json_object_int_add(json_timer, "receivedRestartTimer",
12120 p->v_gr_restart);
2986cac2 12121
13909c4f
DS
12122 if (p->t_gr_restart != NULL)
12123 json_object_int_add(
12124 json_timer, "restartTimerRemaining",
12125 thread_timer_remain_second(p->t_gr_restart));
2986cac2 12126
12127 json_object_object_add(json, "timers", json_timer);
12128 } else {
12129
a53ca37b
DA
12130 vty_out(vty, " Timers:\n");
12131 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12132 p->bgp->restart_time);
2986cac2 12133
a53ca37b 12134 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12135 p->v_gr_restart);
12136 if (p->t_gr_restart != NULL)
a53ca37b 12137 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 12138 thread_timer_remain_second(p->t_gr_restart));
36235319 12139 if (p->t_gr_restart != NULL) {
a53ca37b 12140 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
12141 thread_timer_remain_second(p->t_gr_restart));
12142 }
2986cac2 12143 }
12144}
12145
12146static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 12147 bool use_json, json_object *json)
2986cac2 12148{
12149 char buf[SU_ADDRSTRLEN] = {0};
12150 char dn_flag[2] = {0};
2b7165e7
QY
12151 /* '*' + v6 address of neighbor */
12152 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12153
2986cac2 12154 if (!p->conf_if && peer_dynamic_neighbor(p))
12155 dn_flag[0] = '*';
12156
12157 if (p->conf_if) {
12158 if (use_json)
13909c4f
DS
12159 json_object_string_add(
12160 json, "neighborAddr",
2986cac2 12161 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
12162 ? "none"
12163 : sockunion2str(&p->su, buf,
12164 SU_ADDRSTRLEN));
2986cac2 12165 else
13909c4f 12166 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 12167 BGP_PEER_SU_UNSPEC(p)
12168 ? "none"
12169 : sockunion2str(&p->su, buf,
12170 SU_ADDRSTRLEN));
12171 } else {
772270f3
QY
12172 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12173 p->host);
2986cac2 12174
12175 if (use_json)
36235319
QY
12176 json_object_string_add(json, "neighborAddr",
12177 neighborAddr);
2986cac2 12178 else
36235319 12179 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12180 }
12181
12182 /* more gr info in new format */
12183 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12184}
12185
d62a17ae 12186static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12187 safi_t safi, bool use_json,
d62a17ae 12188 json_object *json_neigh)
12189{
0291c246
MK
12190 struct bgp_filter *filter;
12191 struct peer_af *paf;
12192 char orf_pfx_name[BUFSIZ];
12193 int orf_pfx_count;
12194 json_object *json_af = NULL;
12195 json_object *json_prefA = NULL;
12196 json_object *json_prefB = NULL;
12197 json_object *json_addr = NULL;
fa36596c 12198 json_object *json_advmap = NULL;
d62a17ae 12199
12200 if (use_json) {
12201 json_addr = json_object_new_object();
12202 json_af = json_object_new_object();
12203 filter = &p->filter[afi][safi];
12204
12205 if (peer_group_active(p))
12206 json_object_string_add(json_addr, "peerGroupMember",
12207 p->group->name);
12208
12209 paf = peer_af_find(p, afi, safi);
12210 if (paf && PAF_SUBGRP(paf)) {
12211 json_object_int_add(json_addr, "updateGroupId",
12212 PAF_UPDGRP(paf)->id);
12213 json_object_int_add(json_addr, "subGroupId",
12214 PAF_SUBGRP(paf)->id);
12215 json_object_int_add(json_addr, "packetQueueLength",
12216 bpacket_queue_virtual_length(paf));
12217 }
12218
12219 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12220 || CHECK_FLAG(p->af_cap[afi][safi],
12221 PEER_CAP_ORF_PREFIX_SM_RCV)
12222 || CHECK_FLAG(p->af_cap[afi][safi],
12223 PEER_CAP_ORF_PREFIX_RM_ADV)
12224 || CHECK_FLAG(p->af_cap[afi][safi],
12225 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12226 json_object_int_add(json_af, "orfType",
12227 ORF_TYPE_PREFIX);
12228 json_prefA = json_object_new_object();
12229 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12230 PEER_CAP_ORF_PREFIX_SM_ADV,
12231 PEER_CAP_ORF_PREFIX_RM_ADV,
12232 PEER_CAP_ORF_PREFIX_SM_RCV,
12233 PEER_CAP_ORF_PREFIX_RM_RCV,
12234 use_json, json_prefA);
12235 json_object_object_add(json_af, "orfPrefixList",
12236 json_prefA);
12237 }
12238
12239 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12240 || CHECK_FLAG(p->af_cap[afi][safi],
12241 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12242 || CHECK_FLAG(p->af_cap[afi][safi],
12243 PEER_CAP_ORF_PREFIX_RM_ADV)
12244 || CHECK_FLAG(p->af_cap[afi][safi],
12245 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12246 json_object_int_add(json_af, "orfOldType",
12247 ORF_TYPE_PREFIX_OLD);
12248 json_prefB = json_object_new_object();
12249 bgp_show_peer_afi_orf_cap(
12250 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12251 PEER_CAP_ORF_PREFIX_RM_ADV,
12252 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12253 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12254 json_prefB);
12255 json_object_object_add(json_af, "orfOldPrefixList",
12256 json_prefB);
12257 }
12258
12259 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12260 || CHECK_FLAG(p->af_cap[afi][safi],
12261 PEER_CAP_ORF_PREFIX_SM_RCV)
12262 || CHECK_FLAG(p->af_cap[afi][safi],
12263 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12264 || CHECK_FLAG(p->af_cap[afi][safi],
12265 PEER_CAP_ORF_PREFIX_RM_ADV)
12266 || CHECK_FLAG(p->af_cap[afi][safi],
12267 PEER_CAP_ORF_PREFIX_RM_RCV)
12268 || CHECK_FLAG(p->af_cap[afi][safi],
12269 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12270 json_object_object_add(json_addr, "afDependentCap",
12271 json_af);
12272 else
12273 json_object_free(json_af);
12274
772270f3
QY
12275 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12276 p->host, afi, safi);
d62a17ae 12277 orf_pfx_count = prefix_bgp_show_prefix_list(
12278 NULL, afi, orf_pfx_name, use_json);
12279
12280 if (CHECK_FLAG(p->af_sflags[afi][safi],
12281 PEER_STATUS_ORF_PREFIX_SEND)
12282 || orf_pfx_count) {
12283 if (CHECK_FLAG(p->af_sflags[afi][safi],
12284 PEER_STATUS_ORF_PREFIX_SEND))
12285 json_object_boolean_true_add(json_neigh,
12286 "orfSent");
12287 if (orf_pfx_count)
12288 json_object_int_add(json_addr, "orfRecvCounter",
12289 orf_pfx_count);
12290 }
12291 if (CHECK_FLAG(p->af_sflags[afi][safi],
12292 PEER_STATUS_ORF_WAIT_REFRESH))
12293 json_object_string_add(
12294 json_addr, "orfFirstUpdate",
12295 "deferredUntilORFOrRouteRefreshRecvd");
12296
12297 if (CHECK_FLAG(p->af_flags[afi][safi],
12298 PEER_FLAG_REFLECTOR_CLIENT))
12299 json_object_boolean_true_add(json_addr,
12300 "routeReflectorClient");
12301 if (CHECK_FLAG(p->af_flags[afi][safi],
12302 PEER_FLAG_RSERVER_CLIENT))
12303 json_object_boolean_true_add(json_addr,
12304 "routeServerClient");
12305 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12306 json_object_boolean_true_add(json_addr,
12307 "inboundSoftConfigPermit");
12308
12309 if (CHECK_FLAG(p->af_flags[afi][safi],
12310 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12311 json_object_boolean_true_add(
12312 json_addr,
12313 "privateAsNumsAllReplacedInUpdatesToNbr");
12314 else if (CHECK_FLAG(p->af_flags[afi][safi],
12315 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12316 json_object_boolean_true_add(
12317 json_addr,
12318 "privateAsNumsReplacedInUpdatesToNbr");
12319 else if (CHECK_FLAG(p->af_flags[afi][safi],
12320 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12321 json_object_boolean_true_add(
12322 json_addr,
12323 "privateAsNumsAllRemovedInUpdatesToNbr");
12324 else if (CHECK_FLAG(p->af_flags[afi][safi],
12325 PEER_FLAG_REMOVE_PRIVATE_AS))
12326 json_object_boolean_true_add(
12327 json_addr,
12328 "privateAsNumsRemovedInUpdatesToNbr");
12329
dcc68b5e
MS
12330 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12331 json_object_boolean_true_add(
12332 json_addr,
12333 bgp_addpath_names(p->addpath_type[afi][safi])
12334 ->type_json_name);
d62a17ae 12335
12336 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12337 json_object_string_add(json_addr,
12338 "overrideASNsInOutboundUpdates",
12339 "ifAspathEqualRemoteAs");
12340
12341 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12342 || CHECK_FLAG(p->af_flags[afi][safi],
12343 PEER_FLAG_FORCE_NEXTHOP_SELF))
12344 json_object_boolean_true_add(json_addr,
12345 "routerAlwaysNextHop");
12346 if (CHECK_FLAG(p->af_flags[afi][safi],
12347 PEER_FLAG_AS_PATH_UNCHANGED))
12348 json_object_boolean_true_add(
12349 json_addr, "unchangedAsPathPropogatedToNbr");
12350 if (CHECK_FLAG(p->af_flags[afi][safi],
12351 PEER_FLAG_NEXTHOP_UNCHANGED))
12352 json_object_boolean_true_add(
12353 json_addr, "unchangedNextHopPropogatedToNbr");
12354 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12355 json_object_boolean_true_add(
12356 json_addr, "unchangedMedPropogatedToNbr");
12357 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12358 || CHECK_FLAG(p->af_flags[afi][safi],
12359 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12360 if (CHECK_FLAG(p->af_flags[afi][safi],
12361 PEER_FLAG_SEND_COMMUNITY)
12362 && CHECK_FLAG(p->af_flags[afi][safi],
12363 PEER_FLAG_SEND_EXT_COMMUNITY))
12364 json_object_string_add(json_addr,
12365 "commAttriSentToNbr",
12366 "extendedAndStandard");
12367 else if (CHECK_FLAG(p->af_flags[afi][safi],
12368 PEER_FLAG_SEND_EXT_COMMUNITY))
12369 json_object_string_add(json_addr,
12370 "commAttriSentToNbr",
12371 "extended");
12372 else
12373 json_object_string_add(json_addr,
12374 "commAttriSentToNbr",
12375 "standard");
12376 }
12377 if (CHECK_FLAG(p->af_flags[afi][safi],
12378 PEER_FLAG_DEFAULT_ORIGINATE)) {
12379 if (p->default_rmap[afi][safi].name)
12380 json_object_string_add(
12381 json_addr, "defaultRouteMap",
12382 p->default_rmap[afi][safi].name);
12383
12384 if (paf && PAF_SUBGRP(paf)
12385 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12386 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12387 json_object_boolean_true_add(json_addr,
12388 "defaultSent");
12389 else
12390 json_object_boolean_true_add(json_addr,
12391 "defaultNotSent");
12392 }
12393
dff8f48d 12394 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12395 if (is_evpn_enabled())
60466a63
QY
12396 json_object_boolean_true_add(
12397 json_addr, "advertiseAllVnis");
dff8f48d
MK
12398 }
12399
d62a17ae 12400 if (filter->plist[FILTER_IN].name
12401 || filter->dlist[FILTER_IN].name
12402 || filter->aslist[FILTER_IN].name
12403 || filter->map[RMAP_IN].name)
12404 json_object_boolean_true_add(json_addr,
12405 "inboundPathPolicyConfig");
12406 if (filter->plist[FILTER_OUT].name
12407 || filter->dlist[FILTER_OUT].name
12408 || filter->aslist[FILTER_OUT].name
12409 || filter->map[RMAP_OUT].name || filter->usmap.name)
12410 json_object_boolean_true_add(
12411 json_addr, "outboundPathPolicyConfig");
12412
12413 /* prefix-list */
12414 if (filter->plist[FILTER_IN].name)
12415 json_object_string_add(json_addr,
12416 "incomingUpdatePrefixFilterList",
12417 filter->plist[FILTER_IN].name);
12418 if (filter->plist[FILTER_OUT].name)
12419 json_object_string_add(json_addr,
12420 "outgoingUpdatePrefixFilterList",
12421 filter->plist[FILTER_OUT].name);
12422
12423 /* distribute-list */
12424 if (filter->dlist[FILTER_IN].name)
12425 json_object_string_add(
12426 json_addr, "incomingUpdateNetworkFilterList",
12427 filter->dlist[FILTER_IN].name);
12428 if (filter->dlist[FILTER_OUT].name)
12429 json_object_string_add(
12430 json_addr, "outgoingUpdateNetworkFilterList",
12431 filter->dlist[FILTER_OUT].name);
12432
12433 /* filter-list. */
12434 if (filter->aslist[FILTER_IN].name)
12435 json_object_string_add(json_addr,
12436 "incomingUpdateAsPathFilterList",
12437 filter->aslist[FILTER_IN].name);
12438 if (filter->aslist[FILTER_OUT].name)
12439 json_object_string_add(json_addr,
12440 "outgoingUpdateAsPathFilterList",
12441 filter->aslist[FILTER_OUT].name);
12442
12443 /* route-map. */
12444 if (filter->map[RMAP_IN].name)
12445 json_object_string_add(
12446 json_addr, "routeMapForIncomingAdvertisements",
12447 filter->map[RMAP_IN].name);
12448 if (filter->map[RMAP_OUT].name)
12449 json_object_string_add(
12450 json_addr, "routeMapForOutgoingAdvertisements",
12451 filter->map[RMAP_OUT].name);
12452
9dac9fc8 12453 /* ebgp-requires-policy (inbound) */
1d3fdccf 12454 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12455 && !bgp_inbound_policy_exists(p, filter))
12456 json_object_string_add(
12457 json_addr, "inboundEbgpRequiresPolicy",
12458 "Inbound updates discarded due to missing policy");
12459
12460 /* ebgp-requires-policy (outbound) */
1d3fdccf 12461 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12462 && (!bgp_outbound_policy_exists(p, filter)))
12463 json_object_string_add(
12464 json_addr, "outboundEbgpRequiresPolicy",
12465 "Outbound updates discarded due to missing policy");
12466
d62a17ae 12467 /* unsuppress-map */
12468 if (filter->usmap.name)
12469 json_object_string_add(json_addr,
12470 "selectiveUnsuppressRouteMap",
12471 filter->usmap.name);
12472
fa36596c
MK
12473 /* advertise-map */
12474 if (filter->advmap.aname) {
12475 json_advmap = json_object_new_object();
12476 json_object_string_add(json_advmap, "condition",
12477 filter->advmap.condition
12478 ? "EXIST"
12479 : "NON_EXIST");
12480 json_object_string_add(json_advmap, "conditionMap",
12481 filter->advmap.cname);
12482 json_object_string_add(json_advmap, "advertiseMap",
12483 filter->advmap.aname);
12484 json_object_string_add(json_advmap, "advertiseStatus",
12485 filter->advmap.update_type
12486 == ADVERTISE
12487 ? "Advertise"
12488 : "Withdraw");
12489 json_object_object_add(json_addr, "advertiseMap",
12490 json_advmap);
12491 }
12492
d62a17ae 12493 /* Receive prefix count */
12494 json_object_int_add(json_addr, "acceptedPrefixCounter",
12495 p->pcount[afi][safi]);
50e05855
AD
12496 if (paf && PAF_SUBGRP(paf))
12497 json_object_int_add(json_addr, "sentPrefixCounter",
12498 (PAF_SUBGRP(paf))->scount);
d62a17ae 12499
fde246e8
DA
12500 /* Maximum prefix */
12501 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12502 json_object_int_add(json_addr, "prefixOutAllowedMax",
12503 p->pmax_out[afi][safi]);
12504
d62a17ae 12505 /* Maximum prefix */
12506 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12507 json_object_int_add(json_addr, "prefixAllowedMax",
12508 p->pmax[afi][safi]);
12509 if (CHECK_FLAG(p->af_flags[afi][safi],
12510 PEER_FLAG_MAX_PREFIX_WARNING))
12511 json_object_boolean_true_add(
12512 json_addr, "prefixAllowedMaxWarning");
12513 json_object_int_add(json_addr,
12514 "prefixAllowedWarningThresh",
12515 p->pmax_threshold[afi][safi]);
12516 if (p->pmax_restart[afi][safi])
12517 json_object_int_add(
12518 json_addr,
12519 "prefixAllowedRestartIntervalMsecs",
12520 p->pmax_restart[afi][safi] * 60000);
12521 }
2986cac2 12522 json_object_object_add(json_neigh,
36235319 12523 get_afi_safi_str(afi, safi, true),
d62a17ae 12524 json_addr);
12525
12526 } else {
12527 filter = &p->filter[afi][safi];
12528
12529 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12530 get_afi_safi_str(afi, safi, false));
d62a17ae 12531
12532 if (peer_group_active(p))
12533 vty_out(vty, " %s peer-group member\n",
12534 p->group->name);
12535
12536 paf = peer_af_find(p, afi, safi);
12537 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12538 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12539 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12540 vty_out(vty, " Packet Queue length %d\n",
12541 bpacket_queue_virtual_length(paf));
12542 } else {
12543 vty_out(vty, " Not part of any update group\n");
12544 }
12545 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12546 || CHECK_FLAG(p->af_cap[afi][safi],
12547 PEER_CAP_ORF_PREFIX_SM_RCV)
12548 || CHECK_FLAG(p->af_cap[afi][safi],
12549 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12550 || CHECK_FLAG(p->af_cap[afi][safi],
12551 PEER_CAP_ORF_PREFIX_RM_ADV)
12552 || CHECK_FLAG(p->af_cap[afi][safi],
12553 PEER_CAP_ORF_PREFIX_RM_RCV)
12554 || CHECK_FLAG(p->af_cap[afi][safi],
12555 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12556 vty_out(vty, " AF-dependant capabilities:\n");
12557
12558 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12559 || CHECK_FLAG(p->af_cap[afi][safi],
12560 PEER_CAP_ORF_PREFIX_SM_RCV)
12561 || CHECK_FLAG(p->af_cap[afi][safi],
12562 PEER_CAP_ORF_PREFIX_RM_ADV)
12563 || CHECK_FLAG(p->af_cap[afi][safi],
12564 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12565 vty_out(vty,
12566 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12567 ORF_TYPE_PREFIX);
12568 bgp_show_peer_afi_orf_cap(
12569 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12570 PEER_CAP_ORF_PREFIX_RM_ADV,
12571 PEER_CAP_ORF_PREFIX_SM_RCV,
12572 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12573 }
12574 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12575 || CHECK_FLAG(p->af_cap[afi][safi],
12576 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12577 || CHECK_FLAG(p->af_cap[afi][safi],
12578 PEER_CAP_ORF_PREFIX_RM_ADV)
12579 || CHECK_FLAG(p->af_cap[afi][safi],
12580 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12581 vty_out(vty,
12582 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12583 ORF_TYPE_PREFIX_OLD);
12584 bgp_show_peer_afi_orf_cap(
12585 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12586 PEER_CAP_ORF_PREFIX_RM_ADV,
12587 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12588 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12589 }
12590
772270f3
QY
12591 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12592 p->host, afi, safi);
d62a17ae 12593 orf_pfx_count = prefix_bgp_show_prefix_list(
12594 NULL, afi, orf_pfx_name, use_json);
12595
12596 if (CHECK_FLAG(p->af_sflags[afi][safi],
12597 PEER_STATUS_ORF_PREFIX_SEND)
12598 || orf_pfx_count) {
12599 vty_out(vty, " Outbound Route Filter (ORF):");
12600 if (CHECK_FLAG(p->af_sflags[afi][safi],
12601 PEER_STATUS_ORF_PREFIX_SEND))
12602 vty_out(vty, " sent;");
12603 if (orf_pfx_count)
12604 vty_out(vty, " received (%d entries)",
12605 orf_pfx_count);
12606 vty_out(vty, "\n");
12607 }
12608 if (CHECK_FLAG(p->af_sflags[afi][safi],
12609 PEER_STATUS_ORF_WAIT_REFRESH))
12610 vty_out(vty,
12611 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12612
12613 if (CHECK_FLAG(p->af_flags[afi][safi],
12614 PEER_FLAG_REFLECTOR_CLIENT))
12615 vty_out(vty, " Route-Reflector Client\n");
12616 if (CHECK_FLAG(p->af_flags[afi][safi],
12617 PEER_FLAG_RSERVER_CLIENT))
12618 vty_out(vty, " Route-Server Client\n");
12619 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12620 vty_out(vty,
12621 " Inbound soft reconfiguration allowed\n");
12622
12623 if (CHECK_FLAG(p->af_flags[afi][safi],
12624 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12625 vty_out(vty,
12626 " Private AS numbers (all) replaced in updates to this neighbor\n");
12627 else if (CHECK_FLAG(p->af_flags[afi][safi],
12628 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12629 vty_out(vty,
12630 " Private AS numbers replaced in updates to this neighbor\n");
12631 else if (CHECK_FLAG(p->af_flags[afi][safi],
12632 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12633 vty_out(vty,
12634 " Private AS numbers (all) removed in updates to this neighbor\n");
12635 else if (CHECK_FLAG(p->af_flags[afi][safi],
12636 PEER_FLAG_REMOVE_PRIVATE_AS))
12637 vty_out(vty,
12638 " Private AS numbers removed in updates to this neighbor\n");
12639
dcc68b5e
MS
12640 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12641 vty_out(vty, " %s\n",
12642 bgp_addpath_names(p->addpath_type[afi][safi])
12643 ->human_description);
d62a17ae 12644
12645 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12646 vty_out(vty,
12647 " Override ASNs in outbound updates if aspath equals remote-as\n");
12648
12649 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12650 || CHECK_FLAG(p->af_flags[afi][safi],
12651 PEER_FLAG_FORCE_NEXTHOP_SELF))
12652 vty_out(vty, " NEXT_HOP is always this router\n");
12653 if (CHECK_FLAG(p->af_flags[afi][safi],
12654 PEER_FLAG_AS_PATH_UNCHANGED))
12655 vty_out(vty,
12656 " AS_PATH is propagated unchanged to this neighbor\n");
12657 if (CHECK_FLAG(p->af_flags[afi][safi],
12658 PEER_FLAG_NEXTHOP_UNCHANGED))
12659 vty_out(vty,
12660 " NEXT_HOP is propagated unchanged to this neighbor\n");
12661 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12662 vty_out(vty,
12663 " MED is propagated unchanged to this neighbor\n");
12664 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12665 || CHECK_FLAG(p->af_flags[afi][safi],
12666 PEER_FLAG_SEND_EXT_COMMUNITY)
12667 || CHECK_FLAG(p->af_flags[afi][safi],
12668 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12669 vty_out(vty,
12670 " Community attribute sent to this neighbor");
12671 if (CHECK_FLAG(p->af_flags[afi][safi],
12672 PEER_FLAG_SEND_COMMUNITY)
12673 && CHECK_FLAG(p->af_flags[afi][safi],
12674 PEER_FLAG_SEND_EXT_COMMUNITY)
12675 && CHECK_FLAG(p->af_flags[afi][safi],
12676 PEER_FLAG_SEND_LARGE_COMMUNITY))
12677 vty_out(vty, "(all)\n");
12678 else if (CHECK_FLAG(p->af_flags[afi][safi],
12679 PEER_FLAG_SEND_LARGE_COMMUNITY))
12680 vty_out(vty, "(large)\n");
12681 else if (CHECK_FLAG(p->af_flags[afi][safi],
12682 PEER_FLAG_SEND_EXT_COMMUNITY))
12683 vty_out(vty, "(extended)\n");
12684 else
12685 vty_out(vty, "(standard)\n");
12686 }
12687 if (CHECK_FLAG(p->af_flags[afi][safi],
12688 PEER_FLAG_DEFAULT_ORIGINATE)) {
12689 vty_out(vty, " Default information originate,");
12690
12691 if (p->default_rmap[afi][safi].name)
12692 vty_out(vty, " default route-map %s%s,",
12693 p->default_rmap[afi][safi].map ? "*"
12694 : "",
12695 p->default_rmap[afi][safi].name);
12696 if (paf && PAF_SUBGRP(paf)
12697 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12698 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12699 vty_out(vty, " default sent\n");
12700 else
12701 vty_out(vty, " default not sent\n");
12702 }
12703
dff8f48d
MK
12704 /* advertise-vni-all */
12705 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12706 if (is_evpn_enabled())
dff8f48d
MK
12707 vty_out(vty, " advertise-all-vni\n");
12708 }
12709
d62a17ae 12710 if (filter->plist[FILTER_IN].name
12711 || filter->dlist[FILTER_IN].name
12712 || filter->aslist[FILTER_IN].name
12713 || filter->map[RMAP_IN].name)
12714 vty_out(vty, " Inbound path policy configured\n");
12715 if (filter->plist[FILTER_OUT].name
12716 || filter->dlist[FILTER_OUT].name
12717 || filter->aslist[FILTER_OUT].name
12718 || filter->map[RMAP_OUT].name || filter->usmap.name)
12719 vty_out(vty, " Outbound path policy configured\n");
12720
12721 /* prefix-list */
12722 if (filter->plist[FILTER_IN].name)
12723 vty_out(vty,
12724 " Incoming update prefix filter list is %s%s\n",
12725 filter->plist[FILTER_IN].plist ? "*" : "",
12726 filter->plist[FILTER_IN].name);
12727 if (filter->plist[FILTER_OUT].name)
12728 vty_out(vty,
12729 " Outgoing update prefix filter list is %s%s\n",
12730 filter->plist[FILTER_OUT].plist ? "*" : "",
12731 filter->plist[FILTER_OUT].name);
12732
12733 /* distribute-list */
12734 if (filter->dlist[FILTER_IN].name)
12735 vty_out(vty,
12736 " Incoming update network filter list is %s%s\n",
12737 filter->dlist[FILTER_IN].alist ? "*" : "",
12738 filter->dlist[FILTER_IN].name);
12739 if (filter->dlist[FILTER_OUT].name)
12740 vty_out(vty,
12741 " Outgoing update network filter list is %s%s\n",
12742 filter->dlist[FILTER_OUT].alist ? "*" : "",
12743 filter->dlist[FILTER_OUT].name);
12744
12745 /* filter-list. */
12746 if (filter->aslist[FILTER_IN].name)
12747 vty_out(vty,
12748 " Incoming update AS path filter list is %s%s\n",
12749 filter->aslist[FILTER_IN].aslist ? "*" : "",
12750 filter->aslist[FILTER_IN].name);
12751 if (filter->aslist[FILTER_OUT].name)
12752 vty_out(vty,
12753 " Outgoing update AS path filter list is %s%s\n",
12754 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12755 filter->aslist[FILTER_OUT].name);
12756
12757 /* route-map. */
12758 if (filter->map[RMAP_IN].name)
12759 vty_out(vty,
12760 " Route map for incoming advertisements is %s%s\n",
12761 filter->map[RMAP_IN].map ? "*" : "",
12762 filter->map[RMAP_IN].name);
12763 if (filter->map[RMAP_OUT].name)
12764 vty_out(vty,
12765 " Route map for outgoing advertisements is %s%s\n",
12766 filter->map[RMAP_OUT].map ? "*" : "",
12767 filter->map[RMAP_OUT].name);
12768
9dac9fc8 12769 /* ebgp-requires-policy (inbound) */
1d3fdccf 12770 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12771 && !bgp_inbound_policy_exists(p, filter))
12772 vty_out(vty,
12773 " Inbound updates discarded due to missing policy\n");
12774
12775 /* ebgp-requires-policy (outbound) */
1d3fdccf 12776 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12777 && !bgp_outbound_policy_exists(p, filter))
12778 vty_out(vty,
12779 " Outbound updates discarded due to missing policy\n");
12780
d62a17ae 12781 /* unsuppress-map */
12782 if (filter->usmap.name)
12783 vty_out(vty,
12784 " Route map for selective unsuppress is %s%s\n",
12785 filter->usmap.map ? "*" : "",
12786 filter->usmap.name);
12787
7f7940e6
MK
12788 /* advertise-map */
12789 if (filter->advmap.aname && filter->advmap.cname)
12790 vty_out(vty,
12791 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12792 filter->advmap.condition ? "EXIST"
12793 : "NON_EXIST",
12794 filter->advmap.cmap ? "*" : "",
12795 filter->advmap.cname,
12796 filter->advmap.amap ? "*" : "",
12797 filter->advmap.aname,
fa36596c 12798 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12799 ? "Advertise"
12800 : "Withdraw");
7f7940e6 12801
d62a17ae 12802 /* Receive prefix count */
6cde4b45 12803 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12804 p->pcount[afi][safi]);
d62a17ae 12805
fde246e8
DA
12806 /* maximum-prefix-out */
12807 if (CHECK_FLAG(p->af_flags[afi][safi],
12808 PEER_FLAG_MAX_PREFIX_OUT))
12809 vty_out(vty,
6cde4b45 12810 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12811 p->pmax_out[afi][safi]);
12812
d62a17ae 12813 /* Maximum prefix */
12814 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12815 vty_out(vty,
6cde4b45 12816 " Maximum prefixes allowed %u%s\n",
d62a17ae 12817 p->pmax[afi][safi],
12818 CHECK_FLAG(p->af_flags[afi][safi],
12819 PEER_FLAG_MAX_PREFIX_WARNING)
12820 ? " (warning-only)"
12821 : "");
12822 vty_out(vty, " Threshold for warning message %d%%",
12823 p->pmax_threshold[afi][safi]);
12824 if (p->pmax_restart[afi][safi])
12825 vty_out(vty, ", restart interval %d min",
12826 p->pmax_restart[afi][safi]);
12827 vty_out(vty, "\n");
12828 }
12829
12830 vty_out(vty, "\n");
12831 }
12832}
12833
9f049418 12834static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12835 json_object *json)
718e3744 12836{
d62a17ae 12837 struct bgp *bgp;
12838 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12839 char timebuf[BGP_UPTIME_LEN];
12840 char dn_flag[2];
d62a17ae 12841 afi_t afi;
12842 safi_t safi;
d7c0a89a
QY
12843 uint16_t i;
12844 uint8_t *msg;
d62a17ae 12845 json_object *json_neigh = NULL;
12846 time_t epoch_tbuf;
4ab46701 12847 uint32_t sync_tcp_mss;
718e3744 12848
d62a17ae 12849 bgp = p->bgp;
12850
12851 if (use_json)
12852 json_neigh = json_object_new_object();
12853
12854 memset(dn_flag, '\0', sizeof(dn_flag));
12855 if (!p->conf_if && peer_dynamic_neighbor(p))
12856 dn_flag[0] = '*';
12857
12858 if (!use_json) {
12859 if (p->conf_if) /* Configured interface name. */
12860 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12861 BGP_PEER_SU_UNSPEC(p)
12862 ? "None"
12863 : sockunion2str(&p->su, buf,
12864 SU_ADDRSTRLEN));
12865 else /* Configured IP address. */
12866 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12867 p->host);
12868 }
12869
12870 if (use_json) {
12871 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12872 json_object_string_add(json_neigh, "bgpNeighborAddr",
12873 "none");
12874 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12875 json_object_string_add(
12876 json_neigh, "bgpNeighborAddr",
12877 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12878
12879 json_object_int_add(json_neigh, "remoteAs", p->as);
12880
12881 if (p->change_local_as)
12882 json_object_int_add(json_neigh, "localAs",
12883 p->change_local_as);
12884 else
12885 json_object_int_add(json_neigh, "localAs", p->local_as);
12886
12887 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12888 json_object_boolean_true_add(json_neigh,
12889 "localAsNoPrepend");
12890
12891 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12892 json_object_boolean_true_add(json_neigh,
12893 "localAsReplaceAs");
12894 } else {
12895 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12896 || (p->as_type == AS_INTERNAL))
12897 vty_out(vty, "remote AS %u, ", p->as);
12898 else
12899 vty_out(vty, "remote AS Unspecified, ");
12900 vty_out(vty, "local AS %u%s%s, ",
12901 p->change_local_as ? p->change_local_as : p->local_as,
12902 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12903 ? " no-prepend"
12904 : "",
12905 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12906 ? " replace-as"
12907 : "");
12908 }
faa16034
DS
12909 /* peer type internal or confed-internal */
12910 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12911 if (use_json) {
12912 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12913 json_object_boolean_true_add(
12914 json_neigh, "nbrConfedInternalLink");
12915 else
12916 json_object_boolean_true_add(json_neigh,
12917 "nbrInternalLink");
12918 } else {
12919 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12920 vty_out(vty, "confed-internal link\n");
12921 else
12922 vty_out(vty, "internal link\n");
12923 }
faa16034
DS
12924 /* peer type external or confed-external */
12925 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12926 if (use_json) {
12927 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12928 json_object_boolean_true_add(
12929 json_neigh, "nbrConfedExternalLink");
12930 else
12931 json_object_boolean_true_add(json_neigh,
12932 "nbrExternalLink");
12933 } else {
12934 if (bgp_confederation_peers_check(bgp, p->as))
12935 vty_out(vty, "confed-external link\n");
12936 else
12937 vty_out(vty, "external link\n");
12938 }
faa16034
DS
12939 } else {
12940 if (use_json)
12941 json_object_boolean_true_add(json_neigh,
12942 "nbrUnspecifiedLink");
12943 else
12944 vty_out(vty, "unspecified link\n");
d62a17ae 12945 }
12946
12947 /* Description. */
12948 if (p->desc) {
12949 if (use_json)
12950 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12951 else
12952 vty_out(vty, " Description: %s\n", p->desc);
12953 }
12954
12955 if (p->hostname) {
12956 if (use_json) {
12957 if (p->hostname)
12958 json_object_string_add(json_neigh, "hostname",
12959 p->hostname);
12960
12961 if (p->domainname)
12962 json_object_string_add(json_neigh, "domainname",
12963 p->domainname);
12964 } else {
12965 if (p->domainname && (p->domainname[0] != '\0'))
12966 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12967 p->domainname);
12968 else
12969 vty_out(vty, "Hostname: %s\n", p->hostname);
12970 }
12971 }
12972
12973 /* Peer-group */
12974 if (p->group) {
12975 if (use_json) {
12976 json_object_string_add(json_neigh, "peerGroup",
12977 p->group->name);
12978
12979 if (dn_flag[0]) {
12980 struct prefix prefix, *range = NULL;
12981
0154d8ce
DS
12982 if (sockunion2hostprefix(&(p->su), &prefix))
12983 range = peer_group_lookup_dynamic_neighbor_range(
12984 p->group, &prefix);
d62a17ae 12985
12986 if (range) {
12987 prefix2str(range, buf1, sizeof(buf1));
12988 json_object_string_add(
12989 json_neigh,
12990 "peerSubnetRangeGroup", buf1);
12991 }
12992 }
12993 } else {
12994 vty_out(vty,
12995 " Member of peer-group %s for session parameters\n",
12996 p->group->name);
12997
12998 if (dn_flag[0]) {
12999 struct prefix prefix, *range = NULL;
13000
0154d8ce
DS
13001 if (sockunion2hostprefix(&(p->su), &prefix))
13002 range = peer_group_lookup_dynamic_neighbor_range(
13003 p->group, &prefix);
d62a17ae 13004
13005 if (range) {
d62a17ae 13006 vty_out(vty,
1b78780b
DL
13007 " Belongs to the subnet range group: %pFX\n",
13008 range);
d62a17ae 13009 }
13010 }
13011 }
13012 }
13013
13014 if (use_json) {
13015 /* Administrative shutdown. */
cb9196e7
DS
13016 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13017 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13018 json_object_boolean_true_add(json_neigh,
13019 "adminShutDown");
13020
13021 /* BGP Version. */
13022 json_object_int_add(json_neigh, "bgpVersion", 4);
13023 json_object_string_add(
13024 json_neigh, "remoteRouterId",
13025 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
13026 json_object_string_add(
13027 json_neigh, "localRouterId",
13028 inet_ntop(AF_INET, &bgp->router_id, buf1,
13029 sizeof(buf1)));
d62a17ae 13030
13031 /* Confederation */
13032 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13033 && bgp_confederation_peers_check(bgp, p->as))
13034 json_object_boolean_true_add(json_neigh,
13035 "nbrCommonAdmin");
13036
13037 /* Status. */
13038 json_object_string_add(
13039 json_neigh, "bgpState",
13040 lookup_msg(bgp_status_msg, p->status, NULL));
13041
13042 if (p->status == Established) {
13043 time_t uptime;
d62a17ae 13044
13045 uptime = bgp_clock();
13046 uptime -= p->uptime;
d62a17ae 13047 epoch_tbuf = time(NULL) - uptime;
13048
d3c7efed
DS
13049 json_object_int_add(json_neigh, "bgpTimerUpMsec",
13050 uptime * 1000);
d62a17ae 13051 json_object_string_add(json_neigh, "bgpTimerUpString",
13052 peer_uptime(p->uptime, timebuf,
13053 BGP_UPTIME_LEN, 0,
13054 NULL));
13055 json_object_int_add(json_neigh,
13056 "bgpTimerUpEstablishedEpoch",
13057 epoch_tbuf);
13058 }
13059
13060 else if (p->status == Active) {
13061 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13062 json_object_string_add(json_neigh, "bgpStateIs",
13063 "passive");
13064 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13065 json_object_string_add(json_neigh, "bgpStateIs",
13066 "passiveNSF");
13067 }
13068
13069 /* read timer */
13070 time_t uptime;
a2700b50 13071 struct tm tm;
d62a17ae 13072
13073 uptime = bgp_clock();
13074 uptime -= p->readtime;
a2700b50
MS
13075 gmtime_r(&uptime, &tm);
13076
d62a17ae 13077 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
13078 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13079 + (tm.tm_hour * 3600000));
d62a17ae 13080
13081 uptime = bgp_clock();
13082 uptime -= p->last_write;
a2700b50
MS
13083 gmtime_r(&uptime, &tm);
13084
d62a17ae 13085 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
13086 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13087 + (tm.tm_hour * 3600000));
d62a17ae 13088
13089 uptime = bgp_clock();
13090 uptime -= p->update_time;
a2700b50
MS
13091 gmtime_r(&uptime, &tm);
13092
d62a17ae 13093 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
13094 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13095 + (tm.tm_hour * 3600000));
d62a17ae 13096
13097 /* Configured timer values. */
13098 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13099 p->v_holdtime * 1000);
13100 json_object_int_add(json_neigh,
13101 "bgpTimerKeepAliveIntervalMsecs",
13102 p->v_keepalive * 1000);
d43114f3
DS
13103 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13104 json_object_int_add(json_neigh,
13105 "bgpTimerDelayOpenTimeMsecs",
13106 p->v_delayopen * 1000);
13107 }
13108
4ab46701
AR
13109 /* Configured and Synced tcp-mss value for peer */
13110 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13111 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13112 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13113 p->tcp_mss);
13114 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13115 sync_tcp_mss);
13116 }
13117
b90a8e13 13118 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 13119 json_object_int_add(json_neigh,
13120 "bgpTimerConfiguredHoldTimeMsecs",
13121 p->holdtime * 1000);
13122 json_object_int_add(
13123 json_neigh,
13124 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13125 p->keepalive * 1000);
5d5393b9
DL
13126 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13127 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
13128 json_object_int_add(json_neigh,
13129 "bgpTimerConfiguredHoldTimeMsecs",
13130 bgp->default_holdtime);
13131 json_object_int_add(
13132 json_neigh,
13133 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13134 bgp->default_keepalive);
d62a17ae 13135 }
13136 } else {
13137 /* Administrative shutdown. */
cb9196e7
DS
13138 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13139 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13140 vty_out(vty, " Administratively shut down\n");
13141
13142 /* BGP Version. */
13143 vty_out(vty, " BGP version 4");
0e38aeb4 13144 vty_out(vty, ", remote router ID %s",
d62a17ae 13145 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
13146 vty_out(vty, ", local router ID %s\n",
13147 inet_ntop(AF_INET, &bgp->router_id, buf1,
13148 sizeof(buf1)));
d62a17ae 13149
13150 /* Confederation */
13151 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13152 && bgp_confederation_peers_check(bgp, p->as))
13153 vty_out(vty,
13154 " Neighbor under common administration\n");
13155
13156 /* Status. */
13157 vty_out(vty, " BGP state = %s",
13158 lookup_msg(bgp_status_msg, p->status, NULL));
13159
13160 if (p->status == Established)
13161 vty_out(vty, ", up for %8s",
13162 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13163 0, NULL));
13164
13165 else if (p->status == Active) {
13166 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13167 vty_out(vty, " (passive)");
13168 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13169 vty_out(vty, " (NSF passive)");
13170 }
13171 vty_out(vty, "\n");
13172
13173 /* read timer */
13174 vty_out(vty, " Last read %s",
13175 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13176 NULL));
13177 vty_out(vty, ", Last write %s\n",
13178 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13179 NULL));
13180
13181 /* Configured timer values. */
13182 vty_out(vty,
13183 " Hold time is %d, keepalive interval is %d seconds\n",
13184 p->v_holdtime, p->v_keepalive);
b90a8e13 13185 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 13186 vty_out(vty, " Configured hold time is %d",
13187 p->holdtime);
13188 vty_out(vty, ", keepalive interval is %d seconds\n",
13189 p->keepalive);
5d5393b9
DL
13190 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13191 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
13192 vty_out(vty, " Configured hold time is %d",
13193 bgp->default_holdtime);
13194 vty_out(vty, ", keepalive interval is %d seconds\n",
13195 bgp->default_keepalive);
d62a17ae 13196 }
d43114f3
DS
13197 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13198 vty_out(vty,
13199 " Configured DelayOpenTime is %d seconds\n",
13200 p->delayopen);
4ab46701
AR
13201
13202 /* Configured and synced tcp-mss value for peer */
13203 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13204 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13205 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13206 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13207 }
d62a17ae 13208 }
13209 /* Capability. */
13210 if (p->status == Established) {
13211 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
13212 || p->afc_recv[AFI_IP][SAFI_UNICAST]
13213 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
13214 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
13215 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
13216 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
13217 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
13218 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
13219 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
13220 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
13221 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
13222 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 13223 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
13224 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 13225 || p->afc_adv[AFI_IP][SAFI_ENCAP]
13226 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 13227 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
13228 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 13229 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
13230 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
13231 if (use_json) {
13232 json_object *json_cap = NULL;
13233
13234 json_cap = json_object_new_object();
13235
13236 /* AS4 */
13237 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13238 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13239 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
13240 && CHECK_FLAG(p->cap,
13241 PEER_CAP_AS4_RCV))
13242 json_object_string_add(
13243 json_cap, "4byteAs",
13244 "advertisedAndReceived");
13245 else if (CHECK_FLAG(p->cap,
13246 PEER_CAP_AS4_ADV))
13247 json_object_string_add(
13248 json_cap, "4byteAs",
13249 "advertised");
13250 else if (CHECK_FLAG(p->cap,
13251 PEER_CAP_AS4_RCV))
13252 json_object_string_add(
13253 json_cap, "4byteAs",
13254 "received");
13255 }
13256
ef56aee4
DA
13257 /* Extended Message Support */
13258 if (CHECK_FLAG(p->cap,
13259 PEER_CAP_EXTENDED_MESSAGE_ADV)
13260 && CHECK_FLAG(
13261 p->cap,
13262 PEER_CAP_EXTENDED_MESSAGE_RCV))
13263 json_object_string_add(
13264 json_cap, "extendedMessage",
13265 "advertisedAndReceived");
13266 else if (CHECK_FLAG(
13267 p->cap,
13268 PEER_CAP_EXTENDED_MESSAGE_ADV))
13269 json_object_string_add(
13270 json_cap, "extendedMessage",
13271 "advertised");
13272 else if (CHECK_FLAG(
13273 p->cap,
13274 PEER_CAP_EXTENDED_MESSAGE_RCV))
13275 json_object_string_add(
13276 json_cap, "extendedMessage",
13277 "received");
13278
d62a17ae 13279 /* AddPath */
13280 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13281 || CHECK_FLAG(p->cap,
13282 PEER_CAP_ADDPATH_ADV)) {
13283 json_object *json_add = NULL;
13284 const char *print_store;
13285
13286 json_add = json_object_new_object();
13287
05c7a1cc
QY
13288 FOREACH_AFI_SAFI (afi, safi) {
13289 json_object *json_sub = NULL;
13290 json_sub =
13291 json_object_new_object();
5cb5f4d0
DD
13292 print_store = get_afi_safi_str(
13293 afi, safi, true);
d62a17ae 13294
05c7a1cc
QY
13295 if (CHECK_FLAG(
13296 p->af_cap[afi]
13297 [safi],
13298 PEER_CAP_ADDPATH_AF_TX_ADV)
13299 || CHECK_FLAG(
13300 p->af_cap[afi]
13301 [safi],
13302 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 13303 if (CHECK_FLAG(
13304 p->af_cap
13305 [afi]
13306 [safi],
13307 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 13308 && CHECK_FLAG(
d62a17ae 13309 p->af_cap
13310 [afi]
13311 [safi],
05c7a1cc
QY
13312 PEER_CAP_ADDPATH_AF_TX_RCV))
13313 json_object_boolean_true_add(
13314 json_sub,
13315 "txAdvertisedAndReceived");
13316 else if (
13317 CHECK_FLAG(
13318 p->af_cap
13319 [afi]
13320 [safi],
13321 PEER_CAP_ADDPATH_AF_TX_ADV))
13322 json_object_boolean_true_add(
13323 json_sub,
13324 "txAdvertised");
13325 else if (
13326 CHECK_FLAG(
13327 p->af_cap
13328 [afi]
13329 [safi],
13330 PEER_CAP_ADDPATH_AF_TX_RCV))
13331 json_object_boolean_true_add(
13332 json_sub,
13333 "txReceived");
13334 }
d62a17ae 13335
05c7a1cc
QY
13336 if (CHECK_FLAG(
13337 p->af_cap[afi]
13338 [safi],
13339 PEER_CAP_ADDPATH_AF_RX_ADV)
13340 || CHECK_FLAG(
13341 p->af_cap[afi]
13342 [safi],
13343 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 13344 if (CHECK_FLAG(
13345 p->af_cap
13346 [afi]
13347 [safi],
13348 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 13349 && CHECK_FLAG(
d62a17ae 13350 p->af_cap
13351 [afi]
13352 [safi],
13353 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
13354 json_object_boolean_true_add(
13355 json_sub,
13356 "rxAdvertisedAndReceived");
13357 else if (
13358 CHECK_FLAG(
13359 p->af_cap
13360 [afi]
13361 [safi],
13362 PEER_CAP_ADDPATH_AF_RX_ADV))
13363 json_object_boolean_true_add(
13364 json_sub,
13365 "rxAdvertised");
13366 else if (
13367 CHECK_FLAG(
13368 p->af_cap
13369 [afi]
13370 [safi],
13371 PEER_CAP_ADDPATH_AF_RX_RCV))
13372 json_object_boolean_true_add(
13373 json_sub,
13374 "rxReceived");
d62a17ae 13375 }
13376
05c7a1cc
QY
13377 if (CHECK_FLAG(
13378 p->af_cap[afi]
13379 [safi],
13380 PEER_CAP_ADDPATH_AF_TX_ADV)
13381 || CHECK_FLAG(
13382 p->af_cap[afi]
13383 [safi],
13384 PEER_CAP_ADDPATH_AF_TX_RCV)
13385 || CHECK_FLAG(
13386 p->af_cap[afi]
13387 [safi],
13388 PEER_CAP_ADDPATH_AF_RX_ADV)
13389 || CHECK_FLAG(
13390 p->af_cap[afi]
13391 [safi],
13392 PEER_CAP_ADDPATH_AF_RX_RCV))
13393 json_object_object_add(
13394 json_add,
13395 print_store,
13396 json_sub);
13397 else
13398 json_object_free(
13399 json_sub);
13400 }
13401
d62a17ae 13402 json_object_object_add(
13403 json_cap, "addPath", json_add);
13404 }
13405
13406 /* Dynamic */
13407 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13408 || CHECK_FLAG(p->cap,
13409 PEER_CAP_DYNAMIC_ADV)) {
13410 if (CHECK_FLAG(p->cap,
13411 PEER_CAP_DYNAMIC_ADV)
13412 && CHECK_FLAG(p->cap,
13413 PEER_CAP_DYNAMIC_RCV))
13414 json_object_string_add(
13415 json_cap, "dynamic",
13416 "advertisedAndReceived");
13417 else if (CHECK_FLAG(
13418 p->cap,
13419 PEER_CAP_DYNAMIC_ADV))
13420 json_object_string_add(
13421 json_cap, "dynamic",
13422 "advertised");
13423 else if (CHECK_FLAG(
13424 p->cap,
13425 PEER_CAP_DYNAMIC_RCV))
13426 json_object_string_add(
13427 json_cap, "dynamic",
13428 "received");
13429 }
13430
13431 /* Extended nexthop */
13432 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13433 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13434 json_object *json_nxt = NULL;
13435 const char *print_store;
13436
13437
13438 if (CHECK_FLAG(p->cap,
13439 PEER_CAP_ENHE_ADV)
13440 && CHECK_FLAG(p->cap,
13441 PEER_CAP_ENHE_RCV))
13442 json_object_string_add(
13443 json_cap,
13444 "extendedNexthop",
13445 "advertisedAndReceived");
13446 else if (CHECK_FLAG(p->cap,
13447 PEER_CAP_ENHE_ADV))
13448 json_object_string_add(
13449 json_cap,
13450 "extendedNexthop",
13451 "advertised");
13452 else if (CHECK_FLAG(p->cap,
13453 PEER_CAP_ENHE_RCV))
13454 json_object_string_add(
13455 json_cap,
13456 "extendedNexthop",
13457 "received");
13458
13459 if (CHECK_FLAG(p->cap,
13460 PEER_CAP_ENHE_RCV)) {
13461 json_nxt =
13462 json_object_new_object();
13463
13464 for (safi = SAFI_UNICAST;
13465 safi < SAFI_MAX; safi++) {
13466 if (CHECK_FLAG(
13467 p->af_cap
13468 [AFI_IP]
13469 [safi],
13470 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 13471 print_store = get_afi_safi_str(
d62a17ae 13472 AFI_IP,
5cb5f4d0 13473 safi, true);
d62a17ae 13474 json_object_string_add(
13475 json_nxt,
13476 print_store,
54f29523 13477 "recieved"); /* misspelled for compatibility */
d62a17ae 13478 }
13479 }
13480 json_object_object_add(
13481 json_cap,
13482 "extendedNexthopFamililesByPeer",
13483 json_nxt);
13484 }
13485 }
13486
13487 /* Route Refresh */
13488 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13489 || CHECK_FLAG(p->cap,
13490 PEER_CAP_REFRESH_NEW_RCV)
13491 || CHECK_FLAG(p->cap,
13492 PEER_CAP_REFRESH_OLD_RCV)) {
13493 if (CHECK_FLAG(p->cap,
13494 PEER_CAP_REFRESH_ADV)
13495 && (CHECK_FLAG(
13496 p->cap,
13497 PEER_CAP_REFRESH_NEW_RCV)
13498 || CHECK_FLAG(
13499 p->cap,
13500 PEER_CAP_REFRESH_OLD_RCV))) {
13501 if (CHECK_FLAG(
13502 p->cap,
13503 PEER_CAP_REFRESH_OLD_RCV)
13504 && CHECK_FLAG(
13505 p->cap,
13506 PEER_CAP_REFRESH_NEW_RCV))
13507 json_object_string_add(
13508 json_cap,
13509 "routeRefresh",
13510 "advertisedAndReceivedOldNew");
13511 else {
13512 if (CHECK_FLAG(
13513 p->cap,
13514 PEER_CAP_REFRESH_OLD_RCV))
13515 json_object_string_add(
13516 json_cap,
13517 "routeRefresh",
13518 "advertisedAndReceivedOld");
13519 else
13520 json_object_string_add(
13521 json_cap,
13522 "routeRefresh",
13523 "advertisedAndReceivedNew");
13524 }
13525 } else if (
13526 CHECK_FLAG(
13527 p->cap,
13528 PEER_CAP_REFRESH_ADV))
13529 json_object_string_add(
13530 json_cap,
13531 "routeRefresh",
13532 "advertised");
13533 else if (
13534 CHECK_FLAG(
13535 p->cap,
13536 PEER_CAP_REFRESH_NEW_RCV)
13537 || CHECK_FLAG(
13538 p->cap,
13539 PEER_CAP_REFRESH_OLD_RCV))
13540 json_object_string_add(
13541 json_cap,
13542 "routeRefresh",
13543 "received");
13544 }
13545
9af52ccf
DA
13546 /* Enhanced Route Refresh */
13547 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13548 || CHECK_FLAG(p->cap,
13549 PEER_CAP_ENHANCED_RR_RCV)) {
13550 if (CHECK_FLAG(p->cap,
13551 PEER_CAP_ENHANCED_RR_ADV)
13552 && CHECK_FLAG(
13553 p->cap,
13554 PEER_CAP_ENHANCED_RR_RCV))
13555 json_object_string_add(
13556 json_cap,
13557 "enhancedRouteRefresh",
13558 "advertisedAndReceived");
13559 else if (
13560 CHECK_FLAG(
13561 p->cap,
13562 PEER_CAP_ENHANCED_RR_ADV))
13563 json_object_string_add(
13564 json_cap,
13565 "enhancedRouteRefresh",
13566 "advertised");
13567 else if (
13568 CHECK_FLAG(
13569 p->cap,
13570 PEER_CAP_ENHANCED_RR_RCV))
13571 json_object_string_add(
13572 json_cap,
13573 "enhancedRouteRefresh",
13574 "received");
13575 }
13576
d62a17ae 13577 /* Multiprotocol Extensions */
13578 json_object *json_multi = NULL;
13579 json_multi = json_object_new_object();
13580
05c7a1cc
QY
13581 FOREACH_AFI_SAFI (afi, safi) {
13582 if (p->afc_adv[afi][safi]
13583 || p->afc_recv[afi][safi]) {
13584 json_object *json_exten = NULL;
13585 json_exten =
13586 json_object_new_object();
13587
d62a17ae 13588 if (p->afc_adv[afi][safi]
05c7a1cc
QY
13589 && p->afc_recv[afi][safi])
13590 json_object_boolean_true_add(
13591 json_exten,
13592 "advertisedAndReceived");
13593 else if (p->afc_adv[afi][safi])
13594 json_object_boolean_true_add(
13595 json_exten,
13596 "advertised");
13597 else if (p->afc_recv[afi][safi])
13598 json_object_boolean_true_add(
13599 json_exten,
13600 "received");
d62a17ae 13601
05c7a1cc
QY
13602 json_object_object_add(
13603 json_multi,
5cb5f4d0
DD
13604 get_afi_safi_str(afi,
13605 safi,
13606 true),
05c7a1cc 13607 json_exten);
d62a17ae 13608 }
13609 }
13610 json_object_object_add(
13611 json_cap, "multiprotocolExtensions",
13612 json_multi);
13613
d77114b7 13614 /* Hostname capabilities */
60466a63 13615 json_object *json_hname = NULL;
d77114b7
MK
13616
13617 json_hname = json_object_new_object();
13618
13619 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13620 json_object_string_add(
60466a63
QY
13621 json_hname, "advHostName",
13622 bgp->peer_self->hostname
13623 ? bgp->peer_self
13624 ->hostname
d77114b7
MK
13625 : "n/a");
13626 json_object_string_add(
60466a63
QY
13627 json_hname, "advDomainName",
13628 bgp->peer_self->domainname
13629 ? bgp->peer_self
13630 ->domainname
d77114b7
MK
13631 : "n/a");
13632 }
13633
13634
13635 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13636 json_object_string_add(
60466a63
QY
13637 json_hname, "rcvHostName",
13638 p->hostname ? p->hostname
13639 : "n/a");
d77114b7 13640 json_object_string_add(
60466a63
QY
13641 json_hname, "rcvDomainName",
13642 p->domainname ? p->domainname
13643 : "n/a");
d77114b7
MK
13644 }
13645
60466a63 13646 json_object_object_add(json_cap, "hostName",
d77114b7
MK
13647 json_hname);
13648
d62a17ae 13649 /* Gracefull Restart */
13650 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13651 || CHECK_FLAG(p->cap,
13652 PEER_CAP_RESTART_ADV)) {
13653 if (CHECK_FLAG(p->cap,
13654 PEER_CAP_RESTART_ADV)
13655 && CHECK_FLAG(p->cap,
13656 PEER_CAP_RESTART_RCV))
13657 json_object_string_add(
13658 json_cap,
13659 "gracefulRestart",
13660 "advertisedAndReceived");
13661 else if (CHECK_FLAG(
13662 p->cap,
13663 PEER_CAP_RESTART_ADV))
13664 json_object_string_add(
13665 json_cap,
13666 "gracefulRestartCapability",
13667 "advertised");
13668 else if (CHECK_FLAG(
13669 p->cap,
13670 PEER_CAP_RESTART_RCV))
13671 json_object_string_add(
13672 json_cap,
13673 "gracefulRestartCapability",
13674 "received");
13675
13676 if (CHECK_FLAG(p->cap,
13677 PEER_CAP_RESTART_RCV)) {
13678 int restart_af_count = 0;
13679 json_object *json_restart =
13680 NULL;
13681 json_restart =
13682 json_object_new_object();
13683
13684 json_object_int_add(
13685 json_cap,
13686 "gracefulRestartRemoteTimerMsecs",
13687 p->v_gr_restart * 1000);
13688
05c7a1cc
QY
13689 FOREACH_AFI_SAFI (afi, safi) {
13690 if (CHECK_FLAG(
13691 p->af_cap
13692 [afi]
13693 [safi],
13694 PEER_CAP_RESTART_AF_RCV)) {
13695 json_object *
13696 json_sub =
13697 NULL;
13698 json_sub =
13699 json_object_new_object();
13700
d62a17ae 13701 if (CHECK_FLAG(
13702 p->af_cap
13703 [afi]
13704 [safi],
05c7a1cc
QY
13705 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13706 json_object_boolean_true_add(
13707 json_sub,
13708 "preserved");
13709 restart_af_count++;
13710 json_object_object_add(
13711 json_restart,
5cb5f4d0 13712 get_afi_safi_str(
05c7a1cc 13713 afi,
5cb5f4d0
DD
13714 safi,
13715 true),
05c7a1cc 13716 json_sub);
d62a17ae 13717 }
13718 }
13719 if (!restart_af_count) {
13720 json_object_string_add(
13721 json_cap,
13722 "addressFamiliesByPeer",
13723 "none");
13724 json_object_free(
13725 json_restart);
13726 } else
13727 json_object_object_add(
13728 json_cap,
13729 "addressFamiliesByPeer",
13730 json_restart);
13731 }
13732 }
13733 json_object_object_add(json_neigh,
13734 "neighborCapabilities",
13735 json_cap);
13736 } else {
13737 vty_out(vty, " Neighbor capabilities:\n");
13738
13739 /* AS4 */
13740 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13741 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13742 vty_out(vty, " 4 Byte AS:");
13743 if (CHECK_FLAG(p->cap,
13744 PEER_CAP_AS4_ADV))
13745 vty_out(vty, " advertised");
13746 if (CHECK_FLAG(p->cap,
13747 PEER_CAP_AS4_RCV))
13748 vty_out(vty, " %sreceived",
13749 CHECK_FLAG(
13750 p->cap,
13751 PEER_CAP_AS4_ADV)
13752 ? "and "
13753 : "");
13754 vty_out(vty, "\n");
13755 }
13756
ef56aee4
DA
13757 /* Extended Message Support */
13758 if (CHECK_FLAG(p->cap,
13759 PEER_CAP_EXTENDED_MESSAGE_RCV)
13760 || CHECK_FLAG(
13761 p->cap,
13762 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13763 vty_out(vty, " Extended Message:");
13764 if (CHECK_FLAG(
13765 p->cap,
13766 PEER_CAP_EXTENDED_MESSAGE_ADV))
13767 vty_out(vty, " advertised");
13768 if (CHECK_FLAG(
13769 p->cap,
13770 PEER_CAP_EXTENDED_MESSAGE_RCV))
13771 vty_out(vty, " %sreceived",
13772 CHECK_FLAG(
13773 p->cap,
13774 PEER_CAP_EXTENDED_MESSAGE_ADV)
13775 ? "and "
13776 : "");
13777 vty_out(vty, "\n");
13778 }
13779
d62a17ae 13780 /* AddPath */
13781 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13782 || CHECK_FLAG(p->cap,
13783 PEER_CAP_ADDPATH_ADV)) {
13784 vty_out(vty, " AddPath:\n");
13785
05c7a1cc
QY
13786 FOREACH_AFI_SAFI (afi, safi) {
13787 if (CHECK_FLAG(
13788 p->af_cap[afi]
13789 [safi],
13790 PEER_CAP_ADDPATH_AF_TX_ADV)
13791 || CHECK_FLAG(
13792 p->af_cap[afi]
13793 [safi],
13794 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13795 vty_out(vty,
13796 " %s: TX ",
5cb5f4d0 13797 get_afi_safi_str(
05c7a1cc 13798 afi,
5cb5f4d0
DD
13799 safi,
13800 false));
05c7a1cc 13801
d62a17ae 13802 if (CHECK_FLAG(
13803 p->af_cap
13804 [afi]
13805 [safi],
05c7a1cc 13806 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 13807 vty_out(vty,
05c7a1cc 13808 "advertised %s",
5cb5f4d0 13809 get_afi_safi_str(
d62a17ae 13810 afi,
5cb5f4d0
DD
13811 safi,
13812 false));
d62a17ae 13813
05c7a1cc
QY
13814 if (CHECK_FLAG(
13815 p->af_cap
13816 [afi]
13817 [safi],
13818 PEER_CAP_ADDPATH_AF_TX_RCV))
13819 vty_out(vty,
13820 "%sreceived",
13821 CHECK_FLAG(
13822 p->af_cap
13823 [afi]
13824 [safi],
13825 PEER_CAP_ADDPATH_AF_TX_ADV)
13826 ? " and "
13827 : "");
d62a17ae 13828
05c7a1cc
QY
13829 vty_out(vty, "\n");
13830 }
d62a17ae 13831
05c7a1cc
QY
13832 if (CHECK_FLAG(
13833 p->af_cap[afi]
13834 [safi],
13835 PEER_CAP_ADDPATH_AF_RX_ADV)
13836 || CHECK_FLAG(
13837 p->af_cap[afi]
13838 [safi],
13839 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13840 vty_out(vty,
13841 " %s: RX ",
5cb5f4d0 13842 get_afi_safi_str(
05c7a1cc 13843 afi,
5cb5f4d0
DD
13844 safi,
13845 false));
d62a17ae 13846
13847 if (CHECK_FLAG(
13848 p->af_cap
13849 [afi]
13850 [safi],
05c7a1cc 13851 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 13852 vty_out(vty,
05c7a1cc 13853 "advertised %s",
5cb5f4d0 13854 get_afi_safi_str(
d62a17ae 13855 afi,
5cb5f4d0
DD
13856 safi,
13857 false));
d62a17ae 13858
05c7a1cc
QY
13859 if (CHECK_FLAG(
13860 p->af_cap
13861 [afi]
13862 [safi],
13863 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 13864 vty_out(vty,
05c7a1cc
QY
13865 "%sreceived",
13866 CHECK_FLAG(
13867 p->af_cap
13868 [afi]
13869 [safi],
13870 PEER_CAP_ADDPATH_AF_RX_ADV)
13871 ? " and "
13872 : "");
13873
13874 vty_out(vty, "\n");
d62a17ae 13875 }
05c7a1cc 13876 }
d62a17ae 13877 }
13878
13879 /* Dynamic */
13880 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13881 || CHECK_FLAG(p->cap,
13882 PEER_CAP_DYNAMIC_ADV)) {
13883 vty_out(vty, " Dynamic:");
13884 if (CHECK_FLAG(p->cap,
13885 PEER_CAP_DYNAMIC_ADV))
13886 vty_out(vty, " advertised");
13887 if (CHECK_FLAG(p->cap,
13888 PEER_CAP_DYNAMIC_RCV))
13889 vty_out(vty, " %sreceived",
13890 CHECK_FLAG(
13891 p->cap,
13892 PEER_CAP_DYNAMIC_ADV)
13893 ? "and "
13894 : "");
13895 vty_out(vty, "\n");
13896 }
13897
13898 /* Extended nexthop */
13899 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13900 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13901 vty_out(vty, " Extended nexthop:");
13902 if (CHECK_FLAG(p->cap,
13903 PEER_CAP_ENHE_ADV))
13904 vty_out(vty, " advertised");
13905 if (CHECK_FLAG(p->cap,
13906 PEER_CAP_ENHE_RCV))
13907 vty_out(vty, " %sreceived",
13908 CHECK_FLAG(
13909 p->cap,
13910 PEER_CAP_ENHE_ADV)
13911 ? "and "
13912 : "");
13913 vty_out(vty, "\n");
13914
13915 if (CHECK_FLAG(p->cap,
13916 PEER_CAP_ENHE_RCV)) {
13917 vty_out(vty,
13918 " Address families by peer:\n ");
13919 for (safi = SAFI_UNICAST;
13920 safi < SAFI_MAX; safi++)
13921 if (CHECK_FLAG(
13922 p->af_cap
13923 [AFI_IP]
13924 [safi],
13925 PEER_CAP_ENHE_AF_RCV))
13926 vty_out(vty,
13927 " %s\n",
5cb5f4d0 13928 get_afi_safi_str(
d62a17ae 13929 AFI_IP,
5cb5f4d0
DD
13930 safi,
13931 false));
d62a17ae 13932 }
13933 }
13934
13935 /* Route Refresh */
13936 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13937 || CHECK_FLAG(p->cap,
13938 PEER_CAP_REFRESH_NEW_RCV)
13939 || CHECK_FLAG(p->cap,
13940 PEER_CAP_REFRESH_OLD_RCV)) {
13941 vty_out(vty, " Route refresh:");
13942 if (CHECK_FLAG(p->cap,
13943 PEER_CAP_REFRESH_ADV))
13944 vty_out(vty, " advertised");
13945 if (CHECK_FLAG(p->cap,
13946 PEER_CAP_REFRESH_NEW_RCV)
13947 || CHECK_FLAG(
13948 p->cap,
13949 PEER_CAP_REFRESH_OLD_RCV))
13950 vty_out(vty, " %sreceived(%s)",
13951 CHECK_FLAG(
13952 p->cap,
13953 PEER_CAP_REFRESH_ADV)
13954 ? "and "
13955 : "",
13956 (CHECK_FLAG(
13957 p->cap,
13958 PEER_CAP_REFRESH_OLD_RCV)
13959 && CHECK_FLAG(
13960 p->cap,
13961 PEER_CAP_REFRESH_NEW_RCV))
13962 ? "old & new"
13963 : CHECK_FLAG(
13964 p->cap,
13965 PEER_CAP_REFRESH_OLD_RCV)
13966 ? "old"
13967 : "new");
13968
13969 vty_out(vty, "\n");
13970 }
13971
9af52ccf
DA
13972 /* Enhanced Route Refresh */
13973 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13974 || CHECK_FLAG(p->cap,
13975 PEER_CAP_ENHANCED_RR_RCV)) {
13976 vty_out(vty,
13977 " Enhanced Route Refresh:");
13978 if (CHECK_FLAG(
13979 p->cap,
13980 PEER_CAP_ENHANCED_RR_ADV))
13981 vty_out(vty, " advertised");
13982 if (CHECK_FLAG(
13983 p->cap,
13984 PEER_CAP_ENHANCED_RR_RCV))
13985 vty_out(vty, " %sreceived",
13986 CHECK_FLAG(
13987 p->cap,
13988 PEER_CAP_REFRESH_ADV)
13989 ? "and "
13990 : "");
13991 vty_out(vty, "\n");
13992 }
13993
d62a17ae 13994 /* Multiprotocol Extensions */
05c7a1cc
QY
13995 FOREACH_AFI_SAFI (afi, safi)
13996 if (p->afc_adv[afi][safi]
13997 || p->afc_recv[afi][safi]) {
13998 vty_out(vty,
13999 " Address Family %s:",
5cb5f4d0
DD
14000 get_afi_safi_str(
14001 afi,
14002 safi,
14003 false));
05c7a1cc 14004 if (p->afc_adv[afi][safi])
d62a17ae 14005 vty_out(vty,
05c7a1cc
QY
14006 " advertised");
14007 if (p->afc_recv[afi][safi])
14008 vty_out(vty,
14009 " %sreceived",
14010 p->afc_adv[afi]
14011 [safi]
14012 ? "and "
14013 : "");
14014 vty_out(vty, "\n");
14015 }
d62a17ae 14016
14017 /* Hostname capability */
60466a63 14018 vty_out(vty, " Hostname Capability:");
d77114b7
MK
14019
14020 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
14021 vty_out(vty,
14022 " advertised (name: %s,domain name: %s)",
60466a63
QY
14023 bgp->peer_self->hostname
14024 ? bgp->peer_self
14025 ->hostname
d77114b7 14026 : "n/a",
60466a63
QY
14027 bgp->peer_self->domainname
14028 ? bgp->peer_self
14029 ->domainname
d77114b7
MK
14030 : "n/a");
14031 } else {
14032 vty_out(vty, " not advertised");
d62a17ae 14033 }
14034
d77114b7 14035 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
14036 vty_out(vty,
14037 " received (name: %s,domain name: %s)",
60466a63
QY
14038 p->hostname ? p->hostname
14039 : "n/a",
14040 p->domainname ? p->domainname
14041 : "n/a");
d77114b7
MK
14042 } else {
14043 vty_out(vty, " not received");
14044 }
14045
14046 vty_out(vty, "\n");
14047
61bfbd51 14048 /* Graceful Restart */
d62a17ae 14049 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
14050 || CHECK_FLAG(p->cap,
14051 PEER_CAP_RESTART_ADV)) {
14052 vty_out(vty,
61bfbd51 14053 " Graceful Restart Capability:");
d62a17ae 14054 if (CHECK_FLAG(p->cap,
14055 PEER_CAP_RESTART_ADV))
14056 vty_out(vty, " advertised");
14057 if (CHECK_FLAG(p->cap,
14058 PEER_CAP_RESTART_RCV))
14059 vty_out(vty, " %sreceived",
14060 CHECK_FLAG(
14061 p->cap,
14062 PEER_CAP_RESTART_ADV)
14063 ? "and "
14064 : "");
14065 vty_out(vty, "\n");
14066
14067 if (CHECK_FLAG(p->cap,
14068 PEER_CAP_RESTART_RCV)) {
14069 int restart_af_count = 0;
14070
14071 vty_out(vty,
14072 " Remote Restart timer is %d seconds\n",
14073 p->v_gr_restart);
14074 vty_out(vty,
14075 " Address families by peer:\n ");
14076
05c7a1cc
QY
14077 FOREACH_AFI_SAFI (afi, safi)
14078 if (CHECK_FLAG(
14079 p->af_cap
14080 [afi]
14081 [safi],
14082 PEER_CAP_RESTART_AF_RCV)) {
14083 vty_out(vty,
14084 "%s%s(%s)",
14085 restart_af_count
14086 ? ", "
14087 : "",
5cb5f4d0 14088 get_afi_safi_str(
05c7a1cc 14089 afi,
5cb5f4d0
DD
14090 safi,
14091 false),
05c7a1cc
QY
14092 CHECK_FLAG(
14093 p->af_cap
14094 [afi]
14095 [safi],
14096 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14097 ? "preserved"
14098 : "not preserved");
14099 restart_af_count++;
14100 }
d62a17ae 14101 if (!restart_af_count)
14102 vty_out(vty, "none");
14103 vty_out(vty, "\n");
14104 }
2986cac2 14105 } /* Gracefull Restart */
d62a17ae 14106 }
14107 }
14108 }
14109
14110 /* graceful restart information */
d62a17ae 14111 json_object *json_grace = NULL;
14112 json_object *json_grace_send = NULL;
14113 json_object *json_grace_recv = NULL;
14114 int eor_send_af_count = 0;
14115 int eor_receive_af_count = 0;
14116
14117 if (use_json) {
14118 json_grace = json_object_new_object();
14119 json_grace_send = json_object_new_object();
14120 json_grace_recv = json_object_new_object();
14121
36235319
QY
14122 if ((p->status == Established)
14123 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
14124 FOREACH_AFI_SAFI (afi, safi) {
14125 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 14126 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
14127 json_object_boolean_true_add(
14128 json_grace_send,
5cb5f4d0
DD
14129 get_afi_safi_str(afi,
14130 safi,
14131 true));
05c7a1cc 14132 eor_send_af_count++;
d62a17ae 14133 }
14134 }
05c7a1cc
QY
14135 FOREACH_AFI_SAFI (afi, safi) {
14136 if (CHECK_FLAG(
36235319
QY
14137 p->af_sflags[afi][safi],
14138 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
14139 json_object_boolean_true_add(
14140 json_grace_recv,
5cb5f4d0
DD
14141 get_afi_safi_str(afi,
14142 safi,
14143 true));
05c7a1cc 14144 eor_receive_af_count++;
d62a17ae 14145 }
14146 }
14147 }
36235319
QY
14148 json_object_object_add(json_grace, "endOfRibSend",
14149 json_grace_send);
14150 json_object_object_add(json_grace, "endOfRibRecv",
14151 json_grace_recv);
d62a17ae 14152
d62a17ae 14153
14154 if (p->t_gr_restart)
14155 json_object_int_add(json_grace,
14156 "gracefulRestartTimerMsecs",
14157 thread_timer_remain_second(
14158 p->t_gr_restart)
14159 * 1000);
14160
14161 if (p->t_gr_stale)
14162 json_object_int_add(
14163 json_grace,
14164 "gracefulStalepathTimerMsecs",
14165 thread_timer_remain_second(
14166 p->t_gr_stale)
14167 * 1000);
2986cac2 14168 /* more gr info in new format */
14169 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 14170 json_grace);
d62a17ae 14171 json_object_object_add(
14172 json_neigh, "gracefulRestartInfo", json_grace);
14173 } else {
2089dd80 14174 vty_out(vty, " Graceful restart information:\n");
36235319
QY
14175 if ((p->status == Established)
14176 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 14177
d62a17ae 14178 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
14179 FOREACH_AFI_SAFI (afi, safi) {
14180 if (CHECK_FLAG(p->af_sflags[afi][safi],
14181 PEER_STATUS_EOR_SEND)) {
14182 vty_out(vty, "%s%s",
14183 eor_send_af_count ? ", "
14184 : "",
36235319
QY
14185 get_afi_safi_str(
14186 afi, safi,
14187 false));
05c7a1cc 14188 eor_send_af_count++;
d62a17ae 14189 }
14190 }
14191 vty_out(vty, "\n");
14192 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
14193 FOREACH_AFI_SAFI (afi, safi) {
14194 if (CHECK_FLAG(
14195 p->af_sflags[afi][safi],
14196 PEER_STATUS_EOR_RECEIVED)) {
14197 vty_out(vty, "%s%s",
14198 eor_receive_af_count
14199 ? ", "
14200 : "",
5cb5f4d0
DD
14201 get_afi_safi_str(afi,
14202 safi,
14203 false));
05c7a1cc 14204 eor_receive_af_count++;
d62a17ae 14205 }
14206 }
14207 vty_out(vty, "\n");
14208 }
14209
14210 if (p->t_gr_restart)
14211 vty_out(vty,
14212 " The remaining time of restart timer is %ld\n",
14213 thread_timer_remain_second(
14214 p->t_gr_restart));
14215
14216 if (p->t_gr_stale)
14217 vty_out(vty,
14218 " The remaining time of stalepath timer is %ld\n",
14219 thread_timer_remain_second(
14220 p->t_gr_stale));
2986cac2 14221
14222 /* more gr info in new format */
14223 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 14224 }
2986cac2 14225
d62a17ae 14226 if (use_json) {
14227 json_object *json_stat = NULL;
14228 json_stat = json_object_new_object();
14229 /* Packet counts. */
43aa5965
QY
14230
14231 atomic_size_t outq_count, inq_count;
14232 outq_count = atomic_load_explicit(&p->obuf->count,
14233 memory_order_relaxed);
14234 inq_count = atomic_load_explicit(&p->ibuf->count,
14235 memory_order_relaxed);
14236
14237 json_object_int_add(json_stat, "depthInq",
14238 (unsigned long)inq_count);
d62a17ae 14239 json_object_int_add(json_stat, "depthOutq",
43aa5965 14240 (unsigned long)outq_count);
0112e9e0
QY
14241 json_object_int_add(json_stat, "opensSent",
14242 atomic_load_explicit(&p->open_out,
14243 memory_order_relaxed));
14244 json_object_int_add(json_stat, "opensRecv",
14245 atomic_load_explicit(&p->open_in,
14246 memory_order_relaxed));
d62a17ae 14247 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14248 atomic_load_explicit(&p->notify_out,
14249 memory_order_relaxed));
d62a17ae 14250 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14251 atomic_load_explicit(&p->notify_in,
14252 memory_order_relaxed));
14253 json_object_int_add(json_stat, "updatesSent",
14254 atomic_load_explicit(&p->update_out,
14255 memory_order_relaxed));
14256 json_object_int_add(json_stat, "updatesRecv",
14257 atomic_load_explicit(&p->update_in,
14258 memory_order_relaxed));
d62a17ae 14259 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14260 atomic_load_explicit(&p->keepalive_out,
14261 memory_order_relaxed));
d62a17ae 14262 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14263 atomic_load_explicit(&p->keepalive_in,
14264 memory_order_relaxed));
d62a17ae 14265 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14266 atomic_load_explicit(&p->refresh_out,
14267 memory_order_relaxed));
d62a17ae 14268 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14269 atomic_load_explicit(&p->refresh_in,
14270 memory_order_relaxed));
d62a17ae 14271 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14272 atomic_load_explicit(&p->dynamic_cap_out,
14273 memory_order_relaxed));
d62a17ae 14274 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14275 atomic_load_explicit(&p->dynamic_cap_in,
14276 memory_order_relaxed));
14277 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14278 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14279 json_object_object_add(json_neigh, "messageStats", json_stat);
14280 } else {
43aa5965
QY
14281 atomic_size_t outq_count, inq_count;
14282 outq_count = atomic_load_explicit(&p->obuf->count,
14283 memory_order_relaxed);
14284 inq_count = atomic_load_explicit(&p->ibuf->count,
14285 memory_order_relaxed);
14286
d62a17ae 14287 /* Packet counts. */
14288 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14289 vty_out(vty, " Inq depth is %zu\n", inq_count);
14290 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14291 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
14292 vty_out(vty, " Opens: %10d %10d\n",
14293 atomic_load_explicit(&p->open_out,
14294 memory_order_relaxed),
14295 atomic_load_explicit(&p->open_in,
14296 memory_order_relaxed));
14297 vty_out(vty, " Notifications: %10d %10d\n",
14298 atomic_load_explicit(&p->notify_out,
14299 memory_order_relaxed),
14300 atomic_load_explicit(&p->notify_in,
14301 memory_order_relaxed));
14302 vty_out(vty, " Updates: %10d %10d\n",
14303 atomic_load_explicit(&p->update_out,
14304 memory_order_relaxed),
14305 atomic_load_explicit(&p->update_in,
14306 memory_order_relaxed));
14307 vty_out(vty, " Keepalives: %10d %10d\n",
14308 atomic_load_explicit(&p->keepalive_out,
14309 memory_order_relaxed),
14310 atomic_load_explicit(&p->keepalive_in,
14311 memory_order_relaxed));
14312 vty_out(vty, " Route Refresh: %10d %10d\n",
14313 atomic_load_explicit(&p->refresh_out,
14314 memory_order_relaxed),
14315 atomic_load_explicit(&p->refresh_in,
14316 memory_order_relaxed));
d62a17ae 14317 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
14318 atomic_load_explicit(&p->dynamic_cap_out,
14319 memory_order_relaxed),
14320 atomic_load_explicit(&p->dynamic_cap_in,
14321 memory_order_relaxed));
14322 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
14323 PEER_TOTAL_RX(p));
d62a17ae 14324 }
14325
14326 if (use_json) {
14327 /* advertisement-interval */
14328 json_object_int_add(json_neigh,
14329 "minBtwnAdvertisementRunsTimerMsecs",
14330 p->v_routeadv * 1000);
14331
14332 /* Update-source. */
14333 if (p->update_if || p->update_source) {
14334 if (p->update_if)
14335 json_object_string_add(json_neigh,
14336 "updateSource",
14337 p->update_if);
14338 else if (p->update_source)
14339 json_object_string_add(
14340 json_neigh, "updateSource",
14341 sockunion2str(p->update_source, buf1,
14342 SU_ADDRSTRLEN));
14343 }
14344 } else {
14345 /* advertisement-interval */
14346 vty_out(vty,
14347 " Minimum time between advertisement runs is %d seconds\n",
14348 p->v_routeadv);
14349
14350 /* Update-source. */
14351 if (p->update_if || p->update_source) {
14352 vty_out(vty, " Update source is ");
14353 if (p->update_if)
14354 vty_out(vty, "%s", p->update_if);
14355 else if (p->update_source)
14356 vty_out(vty, "%s",
14357 sockunion2str(p->update_source, buf1,
14358 SU_ADDRSTRLEN));
14359 vty_out(vty, "\n");
14360 }
14361
14362 vty_out(vty, "\n");
14363 }
14364
14365 /* Address Family Information */
14366 json_object *json_hold = NULL;
14367
14368 if (use_json)
14369 json_hold = json_object_new_object();
14370
05c7a1cc
QY
14371 FOREACH_AFI_SAFI (afi, safi)
14372 if (p->afc[afi][safi])
14373 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14374 json_hold);
d62a17ae 14375
14376 if (use_json) {
14377 json_object_object_add(json_neigh, "addressFamilyInfo",
14378 json_hold);
14379 json_object_int_add(json_neigh, "connectionsEstablished",
14380 p->established);
14381 json_object_int_add(json_neigh, "connectionsDropped",
14382 p->dropped);
14383 } else
14384 vty_out(vty, " Connections established %d; dropped %d\n",
14385 p->established, p->dropped);
14386
14387 if (!p->last_reset) {
14388 if (use_json)
14389 json_object_string_add(json_neigh, "lastReset",
14390 "never");
14391 else
14392 vty_out(vty, " Last reset never\n");
14393 } else {
14394 if (use_json) {
14395 time_t uptime;
a2700b50 14396 struct tm tm;
d62a17ae 14397
14398 uptime = bgp_clock();
14399 uptime -= p->resettime;
a2700b50
MS
14400 gmtime_r(&uptime, &tm);
14401
d62a17ae 14402 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14403 (tm.tm_sec * 1000)
14404 + (tm.tm_min * 60000)
14405 + (tm.tm_hour * 3600000));
3577f1c5 14406 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14407 } else {
14408 vty_out(vty, " Last reset %s, ",
14409 peer_uptime(p->resettime, timebuf,
14410 BGP_UPTIME_LEN, 0, NULL));
14411
3577f1c5 14412 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14413 if (p->last_reset_cause_size) {
14414 msg = p->last_reset_cause;
14415 vty_out(vty,
14416 " Message received that caused BGP to send a NOTIFICATION:\n ");
14417 for (i = 1; i <= p->last_reset_cause_size;
14418 i++) {
14419 vty_out(vty, "%02X", *msg++);
14420
14421 if (i != p->last_reset_cause_size) {
14422 if (i % 16 == 0) {
14423 vty_out(vty, "\n ");
14424 } else if (i % 4 == 0) {
14425 vty_out(vty, " ");
14426 }
14427 }
14428 }
14429 vty_out(vty, "\n");
14430 }
14431 }
14432 }
14433
14434 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14435 if (use_json)
14436 json_object_boolean_true_add(json_neigh,
14437 "prefixesConfigExceedMax");
14438 else
14439 vty_out(vty,
14440 " Peer had exceeded the max. no. of prefixes configured.\n");
14441
14442 if (p->t_pmax_restart) {
14443 if (use_json) {
14444 json_object_boolean_true_add(
14445 json_neigh, "reducePrefixNumFrom");
14446 json_object_int_add(json_neigh,
14447 "restartInTimerMsec",
14448 thread_timer_remain_second(
14449 p->t_pmax_restart)
14450 * 1000);
14451 } else
14452 vty_out(vty,
14453 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14454 p->host, thread_timer_remain_second(
14455 p->t_pmax_restart));
d62a17ae 14456 } else {
14457 if (use_json)
14458 json_object_boolean_true_add(
14459 json_neigh,
14460 "reducePrefixNumAndClearIpBgp");
14461 else
14462 vty_out(vty,
14463 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14464 p->host);
14465 }
14466 }
14467
14468 /* EBGP Multihop and GTSM */
14469 if (p->sort != BGP_PEER_IBGP) {
14470 if (use_json) {
e2521429 14471 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14472 json_object_int_add(json_neigh,
14473 "externalBgpNbrMaxHopsAway",
14474 p->gtsm_hops);
c8d6f0d6 14475 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14476 json_object_int_add(json_neigh,
14477 "externalBgpNbrMaxHopsAway",
14478 p->ttl);
14479 } else {
e2521429 14480 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14481 vty_out(vty,
14482 " External BGP neighbor may be up to %d hops away.\n",
14483 p->gtsm_hops);
c8d6f0d6 14484 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14485 vty_out(vty,
14486 " External BGP neighbor may be up to %d hops away.\n",
14487 p->ttl);
14488 }
14489 } else {
e2521429 14490 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 14491 if (use_json)
14492 json_object_int_add(json_neigh,
14493 "internalBgpNbrMaxHopsAway",
14494 p->gtsm_hops);
14495 else
14496 vty_out(vty,
14497 " Internal BGP neighbor may be up to %d hops away.\n",
14498 p->gtsm_hops);
14499 }
14500 }
14501
14502 /* Local address. */
14503 if (p->su_local) {
14504 if (use_json) {
14505 json_object_string_add(json_neigh, "hostLocal",
14506 sockunion2str(p->su_local, buf1,
14507 SU_ADDRSTRLEN));
14508 json_object_int_add(json_neigh, "portLocal",
14509 ntohs(p->su_local->sin.sin_port));
14510 } else
14511 vty_out(vty, "Local host: %s, Local port: %d\n",
14512 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14513 ntohs(p->su_local->sin.sin_port));
14514 }
14515
14516 /* Remote address. */
14517 if (p->su_remote) {
14518 if (use_json) {
14519 json_object_string_add(json_neigh, "hostForeign",
14520 sockunion2str(p->su_remote, buf1,
14521 SU_ADDRSTRLEN));
14522 json_object_int_add(json_neigh, "portForeign",
14523 ntohs(p->su_remote->sin.sin_port));
14524 } else
14525 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14526 sockunion2str(p->su_remote, buf1,
14527 SU_ADDRSTRLEN),
14528 ntohs(p->su_remote->sin.sin_port));
14529 }
14530
14531 /* Nexthop display. */
14532 if (p->su_local) {
14533 if (use_json) {
14534 json_object_string_add(json_neigh, "nexthop",
14535 inet_ntop(AF_INET,
14536 &p->nexthop.v4, buf1,
14537 sizeof(buf1)));
14538 json_object_string_add(json_neigh, "nexthopGlobal",
14539 inet_ntop(AF_INET6,
14540 &p->nexthop.v6_global,
14541 buf1, sizeof(buf1)));
14542 json_object_string_add(json_neigh, "nexthopLocal",
14543 inet_ntop(AF_INET6,
14544 &p->nexthop.v6_local,
14545 buf1, sizeof(buf1)));
14546 if (p->shared_network)
14547 json_object_string_add(json_neigh,
14548 "bgpConnection",
14549 "sharedNetwork");
14550 else
14551 json_object_string_add(json_neigh,
14552 "bgpConnection",
14553 "nonSharedNetwork");
14554 } else {
14555 vty_out(vty, "Nexthop: %s\n",
14556 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14557 sizeof(buf1)));
14558 vty_out(vty, "Nexthop global: %s\n",
14559 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14560 sizeof(buf1)));
14561 vty_out(vty, "Nexthop local: %s\n",
14562 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14563 sizeof(buf1)));
14564 vty_out(vty, "BGP connection: %s\n",
14565 p->shared_network ? "shared network"
14566 : "non shared network");
14567 }
14568 }
14569
14570 /* Timer information. */
14571 if (use_json) {
14572 json_object_int_add(json_neigh, "connectRetryTimer",
14573 p->v_connect);
14574 if (p->status == Established && p->rtt)
14575 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14576 p->rtt);
14577 if (p->t_start)
14578 json_object_int_add(
14579 json_neigh, "nextStartTimerDueInMsecs",
14580 thread_timer_remain_second(p->t_start) * 1000);
14581 if (p->t_connect)
14582 json_object_int_add(
14583 json_neigh, "nextConnectTimerDueInMsecs",
14584 thread_timer_remain_second(p->t_connect)
14585 * 1000);
14586 if (p->t_routeadv) {
14587 json_object_int_add(json_neigh, "mraiInterval",
14588 p->v_routeadv);
14589 json_object_int_add(
14590 json_neigh, "mraiTimerExpireInMsecs",
14591 thread_timer_remain_second(p->t_routeadv)
14592 * 1000);
14593 }
14594 if (p->password)
14595 json_object_int_add(json_neigh, "authenticationEnabled",
14596 1);
14597
14598 if (p->t_read)
14599 json_object_string_add(json_neigh, "readThread", "on");
14600 else
14601 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14602
14603 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14604 json_object_string_add(json_neigh, "writeThread", "on");
14605 else
14606 json_object_string_add(json_neigh, "writeThread",
14607 "off");
14608 } else {
14609 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14610 p->v_connect);
14611 if (p->status == Established && p->rtt)
14612 vty_out(vty, "Estimated round trip time: %d ms\n",
14613 p->rtt);
14614 if (p->t_start)
14615 vty_out(vty, "Next start timer due in %ld seconds\n",
14616 thread_timer_remain_second(p->t_start));
14617 if (p->t_connect)
14618 vty_out(vty, "Next connect timer due in %ld seconds\n",
14619 thread_timer_remain_second(p->t_connect));
14620 if (p->t_routeadv)
14621 vty_out(vty,
14622 "MRAI (interval %u) timer expires in %ld seconds\n",
14623 p->v_routeadv,
14624 thread_timer_remain_second(p->t_routeadv));
14625 if (p->password)
14626 vty_out(vty, "Peer Authentication Enabled\n");
14627
cac9e917 14628 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14629 p->t_read ? "on" : "off",
14630 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14631 ? "on"
cac9e917 14632 : "off", p->fd);
d62a17ae 14633 }
14634
14635 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14636 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14637 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14638
14639 if (!use_json)
14640 vty_out(vty, "\n");
14641
14642 /* BFD information. */
21bfce98
RZ
14643 if (p->bfd_config)
14644 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14645
14646 if (use_json) {
14647 if (p->conf_if) /* Configured interface name. */
14648 json_object_object_add(json, p->conf_if, json_neigh);
14649 else /* Configured IP address. */
14650 json_object_object_add(json, p->host, json_neigh);
14651 }
14652}
14653
36235319
QY
14654static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14655 enum show_type type,
14656 union sockunion *su,
14657 const char *conf_if, afi_t afi,
74a630b6 14658 bool use_json)
2986cac2 14659{
14660 struct listnode *node, *nnode;
14661 struct peer *peer;
14662 int find = 0;
14663 safi_t safi = SAFI_UNICAST;
74a630b6 14664 json_object *json = NULL;
2986cac2 14665 json_object *json_neighbor = NULL;
14666
74a630b6
NT
14667 if (use_json) {
14668 json = json_object_new_object();
14669 json_neighbor = json_object_new_object();
14670 }
14671
2986cac2 14672 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14673
14674 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14675 continue;
14676
14677 if ((peer->afc[afi][safi]) == 0)
14678 continue;
14679
2ba1fe69 14680 if (type == show_all) {
2986cac2 14681 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14682 json_neighbor);
2986cac2 14683
74a630b6 14684 if (use_json) {
13909c4f
DS
14685 json_object_object_add(json, peer->host,
14686 json_neighbor);
74a630b6
NT
14687 json_neighbor = NULL;
14688 }
2986cac2 14689
2ba1fe69 14690 } else if (type == show_peer) {
2986cac2 14691 if (conf_if) {
14692 if ((peer->conf_if
13909c4f
DS
14693 && !strcmp(peer->conf_if, conf_if))
14694 || (peer->hostname
2986cac2 14695 && !strcmp(peer->hostname, conf_if))) {
14696 find = 1;
13909c4f
DS
14697 bgp_show_peer_gr_status(vty, peer,
14698 use_json,
14699 json_neighbor);
2986cac2 14700 }
14701 } else {
14702 if (sockunion_same(&peer->su, su)) {
14703 find = 1;
13909c4f
DS
14704 bgp_show_peer_gr_status(vty, peer,
14705 use_json,
14706 json_neighbor);
2986cac2 14707 }
14708 }
13909c4f
DS
14709 if (use_json && find)
14710 json_object_object_add(json, peer->host,
14711 json_neighbor);
2986cac2 14712 }
14713
74a630b6
NT
14714 if (find) {
14715 json_neighbor = NULL;
2986cac2 14716 break;
74a630b6 14717 }
2986cac2 14718 }
14719
14720 if (type == show_peer && !find) {
14721 if (use_json)
13909c4f 14722 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14723 else
14724 vty_out(vty, "%% No such neighbor\n");
14725 }
14726 if (use_json) {
13909c4f
DS
14727 vty_out(vty, "%s\n",
14728 json_object_to_json_string_ext(
14729 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
14730
14731 if (json_neighbor)
14732 json_object_free(json_neighbor);
14733 json_object_free(json);
2986cac2 14734 } else {
14735 vty_out(vty, "\n");
14736 }
14737
14738 return CMD_SUCCESS;
14739}
14740
d62a17ae 14741static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14742 enum show_type type, union sockunion *su,
9f049418 14743 const char *conf_if, bool use_json,
d62a17ae 14744 json_object *json)
14745{
14746 struct listnode *node, *nnode;
14747 struct peer *peer;
14748 int find = 0;
9f049418 14749 bool nbr_output = false;
d1927ebe
AS
14750 afi_t afi = AFI_MAX;
14751 safi_t safi = SAFI_MAX;
14752
14753 if (type == show_ipv4_peer || type == show_ipv4_all) {
14754 afi = AFI_IP;
14755 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14756 afi = AFI_IP6;
14757 }
d62a17ae 14758
14759 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14760 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14761 continue;
14762
14763 switch (type) {
14764 case show_all:
14765 bgp_show_peer(vty, peer, use_json, json);
9f049418 14766 nbr_output = true;
d62a17ae 14767 break;
14768 case show_peer:
14769 if (conf_if) {
14770 if ((peer->conf_if
14771 && !strcmp(peer->conf_if, conf_if))
14772 || (peer->hostname
14773 && !strcmp(peer->hostname, conf_if))) {
14774 find = 1;
14775 bgp_show_peer(vty, peer, use_json,
14776 json);
14777 }
14778 } else {
14779 if (sockunion_same(&peer->su, su)) {
14780 find = 1;
14781 bgp_show_peer(vty, peer, use_json,
14782 json);
14783 }
14784 }
14785 break;
d1927ebe
AS
14786 case show_ipv4_peer:
14787 case show_ipv6_peer:
14788 FOREACH_SAFI (safi) {
14789 if (peer->afc[afi][safi]) {
14790 if (conf_if) {
14791 if ((peer->conf_if
14792 && !strcmp(peer->conf_if, conf_if))
14793 || (peer->hostname
14794 && !strcmp(peer->hostname, conf_if))) {
14795 find = 1;
14796 bgp_show_peer(vty, peer, use_json,
14797 json);
14798 break;
14799 }
14800 } else {
14801 if (sockunion_same(&peer->su, su)) {
14802 find = 1;
14803 bgp_show_peer(vty, peer, use_json,
14804 json);
14805 break;
14806 }
14807 }
14808 }
14809 }
14810 break;
14811 case show_ipv4_all:
14812 case show_ipv6_all:
14813 FOREACH_SAFI (safi) {
14814 if (peer->afc[afi][safi]) {
14815 bgp_show_peer(vty, peer, use_json, json);
14816 nbr_output = true;
14817 break;
14818 }
14819 }
14820 break;
d62a17ae 14821 }
14822 }
14823
d1927ebe
AS
14824 if ((type == show_peer || type == show_ipv4_peer ||
14825 type == show_ipv6_peer) && !find) {
d62a17ae 14826 if (use_json)
14827 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14828 else
88b7d255 14829 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14830 }
14831
d1927ebe
AS
14832 if (type != show_peer && type != show_ipv4_peer &&
14833 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14834 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14835
d62a17ae 14836 if (use_json) {
996c9314
LB
14837 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14838 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14839 } else {
14840 vty_out(vty, "\n");
14841 }
14842
14843 return CMD_SUCCESS;
14844}
14845
36235319
QY
14846static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14847 enum show_type type,
14848 const char *ip_str,
14849 afi_t afi, bool use_json)
2986cac2 14850{
14851
14852 int ret;
14853 struct bgp *bgp;
14854 union sockunion su;
2986cac2 14855
14856 bgp = bgp_get_default();
14857
13909c4f
DS
14858 if (!bgp)
14859 return;
2986cac2 14860
13909c4f
DS
14861 if (!use_json)
14862 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14863 NULL);
2986cac2 14864
13909c4f
DS
14865 if (ip_str) {
14866 ret = str2sockunion(ip_str, &su);
14867 if (ret < 0)
13909c4f 14868 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14869 vty, bgp, type, NULL, ip_str, afi, use_json);
14870 else
14871 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14872 NULL, afi, use_json);
13909c4f
DS
14873 } else
14874 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14875 afi, use_json);
2986cac2 14876}
14877
d62a17ae 14878static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14879 enum show_type type,
14880 const char *ip_str,
9f049418 14881 bool use_json)
d62a17ae 14882{
0291c246
MK
14883 struct listnode *node, *nnode;
14884 struct bgp *bgp;
71aedaa3 14885 union sockunion su;
0291c246 14886 json_object *json = NULL;
71aedaa3 14887 int ret, is_first = 1;
9f049418 14888 bool nbr_output = false;
d62a17ae 14889
14890 if (use_json)
14891 vty_out(vty, "{\n");
14892
14893 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14894 nbr_output = true;
d62a17ae 14895 if (use_json) {
14896 if (!(json = json_object_new_object())) {
af4c2728 14897 flog_err(
e50f7cfd 14898 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14899 "Unable to allocate memory for JSON object");
14900 vty_out(vty,
14901 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14902 return;
14903 }
14904
14905 json_object_int_add(json, "vrfId",
14906 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14907 ? -1
14908 : (int64_t)bgp->vrf_id);
d62a17ae 14909 json_object_string_add(
14910 json, "vrfName",
14911 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14912 ? VRF_DEFAULT_NAME
d62a17ae 14913 : bgp->name);
14914
14915 if (!is_first)
14916 vty_out(vty, ",\n");
14917 else
14918 is_first = 0;
14919
14920 vty_out(vty, "\"%s\":",
14921 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14922 ? VRF_DEFAULT_NAME
d62a17ae 14923 : bgp->name);
14924 } else {
14925 vty_out(vty, "\nInstance %s:\n",
14926 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14927 ? VRF_DEFAULT_NAME
d62a17ae 14928 : bgp->name);
14929 }
71aedaa3 14930
d1927ebe
AS
14931 if (type == show_peer || type == show_ipv4_peer ||
14932 type == show_ipv6_peer) {
71aedaa3
DS
14933 ret = str2sockunion(ip_str, &su);
14934 if (ret < 0)
14935 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14936 use_json, json);
14937 else
14938 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14939 use_json, json);
14940 } else {
d1927ebe 14941 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14942 use_json, json);
14943 }
b77004d6 14944 json_object_free(json);
121067e9 14945 json = NULL;
d62a17ae 14946 }
14947
3e78a6ce 14948 if (use_json)
d62a17ae 14949 vty_out(vty, "}\n");
9f049418
DS
14950 else if (!nbr_output)
14951 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14952}
14953
14954static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14955 enum show_type type, const char *ip_str,
9f049418 14956 bool use_json)
d62a17ae 14957{
14958 int ret;
14959 struct bgp *bgp;
14960 union sockunion su;
14961 json_object *json = NULL;
14962
14963 if (name) {
14964 if (strmatch(name, "all")) {
71aedaa3
DS
14965 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14966 use_json);
d62a17ae 14967 return CMD_SUCCESS;
14968 } else {
14969 bgp = bgp_lookup_by_name(name);
14970 if (!bgp) {
14971 if (use_json) {
14972 json = json_object_new_object();
d62a17ae 14973 vty_out(vty, "%s\n",
14974 json_object_to_json_string_ext(
14975 json,
14976 JSON_C_TO_STRING_PRETTY));
14977 json_object_free(json);
14978 } else
14979 vty_out(vty,
9f049418 14980 "%% BGP instance not found\n");
d62a17ae 14981
14982 return CMD_WARNING;
14983 }
14984 }
14985 } else {
14986 bgp = bgp_get_default();
14987 }
14988
14989 if (bgp) {
14990 json = json_object_new_object();
14991 if (ip_str) {
14992 ret = str2sockunion(ip_str, &su);
14993 if (ret < 0)
14994 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14995 use_json, json);
14996 else
14997 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14998 use_json, json);
14999 } else {
15000 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
15001 json);
15002 }
15003 json_object_free(json);
ca61fd25
DS
15004 } else {
15005 if (use_json)
15006 vty_out(vty, "{}\n");
15007 else
15008 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 15009 }
15010
15011 return CMD_SUCCESS;
4fb25c53
DW
15012}
15013
2986cac2 15014
15015
15016/* "show [ip] bgp neighbors graceful-restart" commands. */
15017DEFUN (show_ip_bgp_neighbors_gracrful_restart,
15018 show_ip_bgp_neighbors_graceful_restart_cmd,
15019 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
15020 SHOW_STR
15021 BGP_STR
15022 IP_STR
15023 IPV6_STR
15024 NEIGHBOR_STR
15025 "Neighbor to display information about\n"
15026 "Neighbor to display information about\n"
15027 "Neighbor on BGP configured interface\n"
15028 GR_SHOW
15029 JSON_STR)
15030{
15031 char *sh_arg = NULL;
15032 enum show_type sh_type;
15033 int idx = 0;
15034 afi_t afi = AFI_MAX;
2986cac2 15035 bool uj = use_json(argc, argv);
15036
36235319 15037 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 15038 afi = AFI_MAX;
15039
15040 idx++;
15041
15042 if (argv_find(argv, argc, "A.B.C.D", &idx)
15043 || argv_find(argv, argc, "X:X::X:X", &idx)
15044 || argv_find(argv, argc, "WORD", &idx)) {
15045 sh_type = show_peer;
15046 sh_arg = argv[idx]->arg;
15047 } else
15048 sh_type = show_all;
15049
15050 if (!argv_find(argv, argc, "graceful-restart", &idx))
15051 return CMD_SUCCESS;
15052
15053
36235319
QY
15054 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
15055 afi, uj);
2986cac2 15056}
15057
716b2d8a 15058/* "show [ip] bgp neighbors" commands. */
718e3744 15059DEFUN (show_ip_bgp_neighbors,
15060 show_ip_bgp_neighbors_cmd,
24345e82 15061 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 15062 SHOW_STR
15063 IP_STR
15064 BGP_STR
f2a8972b 15065 BGP_INSTANCE_HELP_STR
8c3deaae
QY
15066 "Address Family\n"
15067 "Address Family\n"
718e3744 15068 "Detailed information on TCP and BGP neighbor connections\n"
15069 "Neighbor to display information about\n"
a80beece 15070 "Neighbor to display information about\n"
91d37724 15071 "Neighbor on BGP configured interface\n"
9973d184 15072 JSON_STR)
718e3744 15073{
d62a17ae 15074 char *vrf = NULL;
15075 char *sh_arg = NULL;
15076 enum show_type sh_type;
d1927ebe 15077 afi_t afi = AFI_MAX;
718e3744 15078
9f049418 15079 bool uj = use_json(argc, argv);
718e3744 15080
d62a17ae 15081 int idx = 0;
718e3744 15082
9a8bdf1c
PG
15083 /* [<vrf> VIEWVRFNAME] */
15084 if (argv_find(argv, argc, "vrf", &idx)) {
15085 vrf = argv[idx + 1]->arg;
15086 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15087 vrf = NULL;
15088 } else if (argv_find(argv, argc, "view", &idx))
15089 /* [<view> VIEWVRFNAME] */
d62a17ae 15090 vrf = argv[idx + 1]->arg;
718e3744 15091
d62a17ae 15092 idx++;
d1927ebe
AS
15093
15094 if (argv_find(argv, argc, "ipv4", &idx)) {
15095 sh_type = show_ipv4_all;
15096 afi = AFI_IP;
15097 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15098 sh_type = show_ipv6_all;
15099 afi = AFI_IP6;
15100 } else {
15101 sh_type = show_all;
15102 }
15103
d62a17ae 15104 if (argv_find(argv, argc, "A.B.C.D", &idx)
15105 || argv_find(argv, argc, "X:X::X:X", &idx)
15106 || argv_find(argv, argc, "WORD", &idx)) {
15107 sh_type = show_peer;
15108 sh_arg = argv[idx]->arg;
d1927ebe
AS
15109 }
15110
15111 if (sh_type == show_peer && afi == AFI_IP) {
15112 sh_type = show_ipv4_peer;
15113 } else if (sh_type == show_peer && afi == AFI_IP6) {
15114 sh_type = show_ipv6_peer;
15115 }
856ca177 15116
d62a17ae 15117 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15118}
15119
716b2d8a 15120/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15121 paths' and `show ip mbgp paths'. Those functions results are the
15122 same.*/
f412b39a 15123DEFUN (show_ip_bgp_paths,
718e3744 15124 show_ip_bgp_paths_cmd,
46f296b4 15125 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15126 SHOW_STR
15127 IP_STR
15128 BGP_STR
46f296b4 15129 BGP_SAFI_HELP_STR
718e3744 15130 "Path information\n")
15131{
d62a17ae 15132 vty_out(vty, "Address Refcnt Path\n");
15133 aspath_print_all_vty(vty);
15134 return CMD_SUCCESS;
718e3744 15135}
15136
718e3744 15137#include "hash.h"
15138
e3b78da8 15139static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15140 struct vty *vty)
718e3744 15141{
d62a17ae 15142 struct community *com;
718e3744 15143
e3b78da8 15144 com = (struct community *)bucket->data;
3f65c5b1 15145 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 15146 community_str(com, false));
718e3744 15147}
15148
15149/* Show BGP's community internal data. */
f412b39a 15150DEFUN (show_ip_bgp_community_info,
718e3744 15151 show_ip_bgp_community_info_cmd,
bec37ba5 15152 "show [ip] bgp community-info",
718e3744 15153 SHOW_STR
15154 IP_STR
15155 BGP_STR
15156 "List all bgp community information\n")
15157{
d62a17ae 15158 vty_out(vty, "Address Refcnt Community\n");
718e3744 15159
d62a17ae 15160 hash_iterate(community_hash(),
e3b78da8 15161 (void (*)(struct hash_bucket *,
d62a17ae 15162 void *))community_show_all_iterator,
15163 vty);
718e3744 15164
d62a17ae 15165 return CMD_SUCCESS;
718e3744 15166}
15167
e3b78da8 15168static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15169 struct vty *vty)
57d187bc 15170{
d62a17ae 15171 struct lcommunity *lcom;
57d187bc 15172
e3b78da8 15173 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15174 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 15175 lcommunity_str(lcom, false));
57d187bc
JS
15176}
15177
15178/* Show BGP's community internal data. */
15179DEFUN (show_ip_bgp_lcommunity_info,
15180 show_ip_bgp_lcommunity_info_cmd,
15181 "show ip bgp large-community-info",
15182 SHOW_STR
15183 IP_STR
15184 BGP_STR
15185 "List all bgp large-community information\n")
15186{
d62a17ae 15187 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15188
d62a17ae 15189 hash_iterate(lcommunity_hash(),
e3b78da8 15190 (void (*)(struct hash_bucket *,
d62a17ae 15191 void *))lcommunity_show_all_iterator,
15192 vty);
57d187bc 15193
d62a17ae 15194 return CMD_SUCCESS;
57d187bc 15195}
2986cac2 15196/* Graceful Restart */
15197
15198static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
15199 struct bgp *bgp,
15200 bool use_json,
15201 json_object *json)
2986cac2 15202{
57d187bc
JS
15203
15204
2986cac2 15205 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15206
7318ae88 15207 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15208
15209 switch (bgp_global_gr_mode) {
15210
15211 case GLOBAL_HELPER:
13909c4f 15212 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15213 break;
15214
15215 case GLOBAL_GR:
13909c4f 15216 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15217 break;
15218
15219 case GLOBAL_DISABLE:
13909c4f 15220 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15221 break;
15222
15223 case GLOBAL_INVALID:
2986cac2 15224 vty_out(vty,
2ba1fe69 15225 "Global BGP GR Mode Invalid\n");
2986cac2 15226 break;
15227 }
15228 vty_out(vty, "\n");
15229}
15230
36235319
QY
15231static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15232 enum show_type type,
15233 const char *ip_str,
15234 afi_t afi, bool use_json)
2986cac2 15235{
15236 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15237 afi = AFI_IP;
15238
15239 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15240
36235319
QY
15241 bgp_show_neighbor_graceful_restart_vty(
15242 vty, type, ip_str, afi, use_json);
2986cac2 15243 afi++;
15244 }
15245 } else if (afi != AFI_MAX) {
36235319
QY
15246 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15247 use_json);
2986cac2 15248 } else {
15249 return CMD_ERR_INCOMPLETE;
15250 }
15251
15252 return CMD_SUCCESS;
15253}
15254/* Graceful Restart */
15255
f412b39a 15256DEFUN (show_ip_bgp_attr_info,
718e3744 15257 show_ip_bgp_attr_info_cmd,
bec37ba5 15258 "show [ip] bgp attribute-info",
718e3744 15259 SHOW_STR
15260 IP_STR
15261 BGP_STR
15262 "List all bgp attribute information\n")
15263{
d62a17ae 15264 attr_show_all(vty);
15265 return CMD_SUCCESS;
718e3744 15266}
6b0655a2 15267
03915806
CS
15268static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15269 afi_t afi, safi_t safi,
15270 bool use_json, json_object *json)
53089bec 15271{
15272 struct bgp *bgp;
15273 struct listnode *node;
15274 char *vname;
15275 char buf1[INET6_ADDRSTRLEN];
15276 char *ecom_str;
15277 vpn_policy_direction_t dir;
15278
03915806 15279 if (json) {
b46dfd20
DS
15280 json_object *json_import_vrfs = NULL;
15281 json_object *json_export_vrfs = NULL;
15282
b46dfd20
DS
15283 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15284
53089bec 15285 if (!bgp) {
b46dfd20
DS
15286 vty_out(vty, "%s\n",
15287 json_object_to_json_string_ext(
15288 json,
15289 JSON_C_TO_STRING_PRETTY));
15290 json_object_free(json);
15291
53089bec 15292 return CMD_WARNING;
15293 }
b46dfd20 15294
94d4c685
DS
15295 /* Provide context for the block */
15296 json_object_string_add(json, "vrf", name ? name : "default");
15297 json_object_string_add(json, "afiSafi",
5cb5f4d0 15298 get_afi_safi_str(afi, safi, true));
94d4c685 15299
b46dfd20
DS
15300 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15301 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15302 json_object_string_add(json, "importFromVrfs", "none");
15303 json_object_string_add(json, "importRts", "none");
15304 } else {
6ce24e52
DS
15305 json_import_vrfs = json_object_new_array();
15306
b46dfd20
DS
15307 for (ALL_LIST_ELEMENTS_RO(
15308 bgp->vpn_policy[afi].import_vrf,
15309 node, vname))
15310 json_object_array_add(json_import_vrfs,
15311 json_object_new_string(vname));
15312
b20875ea
CS
15313 json_object_object_add(json, "importFromVrfs",
15314 json_import_vrfs);
b46dfd20 15315 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15316 if (bgp->vpn_policy[afi].rtlist[dir]) {
15317 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15318 bgp->vpn_policy[afi].rtlist[dir],
15319 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15320 json_object_string_add(json, "importRts",
15321 ecom_str);
15322 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15323 } else
15324 json_object_string_add(json, "importRts",
15325 "none");
b46dfd20
DS
15326 }
15327
15328 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15329 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15330 json_object_string_add(json, "exportToVrfs", "none");
15331 json_object_string_add(json, "routeDistinguisher",
15332 "none");
15333 json_object_string_add(json, "exportRts", "none");
15334 } else {
6ce24e52
DS
15335 json_export_vrfs = json_object_new_array();
15336
b46dfd20
DS
15337 for (ALL_LIST_ELEMENTS_RO(
15338 bgp->vpn_policy[afi].export_vrf,
15339 node, vname))
15340 json_object_array_add(json_export_vrfs,
15341 json_object_new_string(vname));
15342 json_object_object_add(json, "exportToVrfs",
15343 json_export_vrfs);
15344 json_object_string_add(json, "routeDistinguisher",
15345 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15346 buf1, RD_ADDRSTRLEN));
15347
15348 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15349 if (bgp->vpn_policy[afi].rtlist[dir]) {
15350 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15351 bgp->vpn_policy[afi].rtlist[dir],
15352 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15353 json_object_string_add(json, "exportRts",
15354 ecom_str);
15355 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15356 } else
15357 json_object_string_add(json, "exportRts",
15358 "none");
b46dfd20
DS
15359 }
15360
03915806
CS
15361 if (use_json) {
15362 vty_out(vty, "%s\n",
15363 json_object_to_json_string_ext(json,
b46dfd20 15364 JSON_C_TO_STRING_PRETTY));
03915806
CS
15365 json_object_free(json);
15366 }
53089bec 15367 } else {
b46dfd20
DS
15368 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15369
53089bec 15370 if (!bgp) {
b46dfd20 15371 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15372 return CMD_WARNING;
15373 }
53089bec 15374
b46dfd20
DS
15375 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15376 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15377 vty_out(vty,
15378 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15379 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15380 else {
15381 vty_out(vty,
15382 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15383 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15384
15385 for (ALL_LIST_ELEMENTS_RO(
15386 bgp->vpn_policy[afi].import_vrf,
15387 node, vname))
15388 vty_out(vty, " %s\n", vname);
15389
15390 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15391 ecom_str = NULL;
15392 if (bgp->vpn_policy[afi].rtlist[dir]) {
15393 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15394 bgp->vpn_policy[afi].rtlist[dir],
15395 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15396 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15397
b20875ea
CS
15398 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15399 } else
15400 vty_out(vty, "Import RT(s):\n");
53089bec 15401 }
53089bec 15402
b46dfd20
DS
15403 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15404 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15405 vty_out(vty,
15406 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15407 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15408 else {
15409 vty_out(vty,
04c9077f 15410 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15411 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15412
15413 for (ALL_LIST_ELEMENTS_RO(
15414 bgp->vpn_policy[afi].export_vrf,
15415 node, vname))
15416 vty_out(vty, " %s\n", vname);
15417
15418 vty_out(vty, "RD: %s\n",
15419 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15420 buf1, RD_ADDRSTRLEN));
15421
15422 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15423 if (bgp->vpn_policy[afi].rtlist[dir]) {
15424 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15425 bgp->vpn_policy[afi].rtlist[dir],
15426 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15427 vty_out(vty, "Export RT: %s\n", ecom_str);
15428 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15429 } else
15430 vty_out(vty, "Import RT(s):\n");
53089bec 15431 }
53089bec 15432 }
15433
15434 return CMD_SUCCESS;
15435}
15436
03915806
CS
15437static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15438 safi_t safi, bool use_json)
15439{
15440 struct listnode *node, *nnode;
15441 struct bgp *bgp;
15442 char *vrf_name = NULL;
15443 json_object *json = NULL;
15444 json_object *json_vrf = NULL;
15445 json_object *json_vrfs = NULL;
15446
15447 if (use_json) {
15448 json = json_object_new_object();
15449 json_vrfs = json_object_new_object();
15450 }
15451
15452 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15453
15454 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15455 vrf_name = bgp->name;
15456
15457 if (use_json) {
15458 json_vrf = json_object_new_object();
15459 } else {
15460 vty_out(vty, "\nInstance %s:\n",
15461 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15462 ? VRF_DEFAULT_NAME : bgp->name);
15463 }
15464 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15465 if (use_json) {
15466 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15467 json_object_object_add(json_vrfs,
15468 VRF_DEFAULT_NAME, json_vrf);
15469 else
15470 json_object_object_add(json_vrfs, vrf_name,
15471 json_vrf);
15472 }
15473 }
15474
15475 if (use_json) {
15476 json_object_object_add(json, "vrfs", json_vrfs);
15477 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15478 JSON_C_TO_STRING_PRETTY));
15479 json_object_free(json);
15480 }
15481
15482 return CMD_SUCCESS;
15483}
15484
53089bec 15485/* "show [ip] bgp route-leak" command. */
15486DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15487 show_ip_bgp_route_leak_cmd,
15488 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15489 SHOW_STR
15490 IP_STR
15491 BGP_STR
15492 BGP_INSTANCE_HELP_STR
15493 BGP_AFI_HELP_STR
15494 BGP_SAFI_HELP_STR
15495 "Route leaking information\n"
15496 JSON_STR)
53089bec 15497{
15498 char *vrf = NULL;
15499 afi_t afi = AFI_MAX;
15500 safi_t safi = SAFI_MAX;
15501
9f049418 15502 bool uj = use_json(argc, argv);
53089bec 15503 int idx = 0;
03915806 15504 json_object *json = NULL;
53089bec 15505
15506 /* show [ip] bgp */
15507 if (argv_find(argv, argc, "ip", &idx)) {
15508 afi = AFI_IP;
15509 safi = SAFI_UNICAST;
15510 }
15511 /* [vrf VIEWVRFNAME] */
15512 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15513 vty_out(vty,
15514 "%% This command is not applicable to BGP views\n");
53089bec 15515 return CMD_WARNING;
15516 }
15517
9a8bdf1c
PG
15518 if (argv_find(argv, argc, "vrf", &idx)) {
15519 vrf = argv[idx + 1]->arg;
15520 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15521 vrf = NULL;
15522 }
53089bec 15523 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15524 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15525 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15526 }
15527
15528 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15529 vty_out(vty,
15530 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15531 return CMD_WARNING;
15532 }
15533
03915806
CS
15534 if (vrf && strmatch(vrf, "all"))
15535 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15536
15537 if (uj)
15538 json = json_object_new_object();
15539
15540 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15541}
15542
d62a17ae 15543static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15544 safi_t safi)
f186de26 15545{
d62a17ae 15546 struct listnode *node, *nnode;
15547 struct bgp *bgp;
f186de26 15548
d62a17ae 15549 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15550 vty_out(vty, "\nInstance %s:\n",
15551 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15552 ? VRF_DEFAULT_NAME
d62a17ae 15553 : bgp->name);
15554 update_group_show(bgp, afi, safi, vty, 0);
15555 }
f186de26 15556}
15557
d62a17ae 15558static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15559 int safi, uint64_t subgrp_id)
4fb25c53 15560{
d62a17ae 15561 struct bgp *bgp;
4fb25c53 15562
d62a17ae 15563 if (name) {
15564 if (strmatch(name, "all")) {
15565 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15566 return CMD_SUCCESS;
15567 } else {
15568 bgp = bgp_lookup_by_name(name);
15569 }
15570 } else {
15571 bgp = bgp_get_default();
15572 }
4fb25c53 15573
d62a17ae 15574 if (bgp)
15575 update_group_show(bgp, afi, safi, vty, subgrp_id);
15576 return CMD_SUCCESS;
4fb25c53
DW
15577}
15578
8fe8a7f6
DS
15579DEFUN (show_ip_bgp_updgrps,
15580 show_ip_bgp_updgrps_cmd,
c1a44e43 15581 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15582 SHOW_STR
15583 IP_STR
15584 BGP_STR
15585 BGP_INSTANCE_HELP_STR
c9e571b4 15586 BGP_AFI_HELP_STR
9bedbb1e 15587 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15588 "Detailed info about dynamic update groups\n"
15589 "Specific subgroup to display detailed info for\n")
8386ac43 15590{
d62a17ae 15591 char *vrf = NULL;
15592 afi_t afi = AFI_IP6;
15593 safi_t safi = SAFI_UNICAST;
15594 uint64_t subgrp_id = 0;
15595
15596 int idx = 0;
15597
15598 /* show [ip] bgp */
15599 if (argv_find(argv, argc, "ip", &idx))
15600 afi = AFI_IP;
9a8bdf1c
PG
15601 /* [<vrf> VIEWVRFNAME] */
15602 if (argv_find(argv, argc, "vrf", &idx)) {
15603 vrf = argv[idx + 1]->arg;
15604 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15605 vrf = NULL;
15606 } else if (argv_find(argv, argc, "view", &idx))
15607 /* [<view> VIEWVRFNAME] */
15608 vrf = argv[idx + 1]->arg;
d62a17ae 15609 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15610 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15611 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15612 }
5bf15956 15613
d62a17ae 15614 /* get subgroup id, if provided */
15615 idx = argc - 1;
15616 if (argv[idx]->type == VARIABLE_TKN)
15617 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15618
d62a17ae 15619 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15620}
15621
f186de26 15622DEFUN (show_bgp_instance_all_ipv6_updgrps,
15623 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15624 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15625 SHOW_STR
716b2d8a 15626 IP_STR
f186de26 15627 BGP_STR
15628 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15629 "Detailed info about dynamic update groups\n")
f186de26 15630{
d62a17ae 15631 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15632 return CMD_SUCCESS;
f186de26 15633}
15634
43d3f4fc
DS
15635DEFUN (show_bgp_l2vpn_evpn_updgrps,
15636 show_bgp_l2vpn_evpn_updgrps_cmd,
15637 "show [ip] bgp l2vpn evpn update-groups",
15638 SHOW_STR
15639 IP_STR
15640 BGP_STR
15641 "l2vpn address family\n"
15642 "evpn sub-address family\n"
15643 "Detailed info about dynamic update groups\n")
15644{
15645 char *vrf = NULL;
15646 uint64_t subgrp_id = 0;
15647
15648 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15649 return CMD_SUCCESS;
15650}
15651
5bf15956
DW
15652DEFUN (show_bgp_updgrps_stats,
15653 show_bgp_updgrps_stats_cmd,
716b2d8a 15654 "show [ip] bgp update-groups statistics",
3f9c7369 15655 SHOW_STR
716b2d8a 15656 IP_STR
3f9c7369 15657 BGP_STR
0c7b1b01 15658 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15659 "Statistics\n")
15660{
d62a17ae 15661 struct bgp *bgp;
3f9c7369 15662
d62a17ae 15663 bgp = bgp_get_default();
15664 if (bgp)
15665 update_group_show_stats(bgp, vty);
3f9c7369 15666
d62a17ae 15667 return CMD_SUCCESS;
3f9c7369
DS
15668}
15669
8386ac43 15670DEFUN (show_bgp_instance_updgrps_stats,
15671 show_bgp_instance_updgrps_stats_cmd,
18c57037 15672 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15673 SHOW_STR
716b2d8a 15674 IP_STR
8386ac43 15675 BGP_STR
15676 BGP_INSTANCE_HELP_STR
0c7b1b01 15677 "Detailed info about dynamic update groups\n"
8386ac43 15678 "Statistics\n")
15679{
d62a17ae 15680 int idx_word = 3;
15681 struct bgp *bgp;
8386ac43 15682
d62a17ae 15683 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15684 if (bgp)
15685 update_group_show_stats(bgp, vty);
8386ac43 15686
d62a17ae 15687 return CMD_SUCCESS;
8386ac43 15688}
15689
d62a17ae 15690static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15691 afi_t afi, safi_t safi,
15692 const char *what, uint64_t subgrp_id)
3f9c7369 15693{
d62a17ae 15694 struct bgp *bgp;
8386ac43 15695
d62a17ae 15696 if (name)
15697 bgp = bgp_lookup_by_name(name);
15698 else
15699 bgp = bgp_get_default();
8386ac43 15700
d62a17ae 15701 if (bgp) {
15702 if (!strcmp(what, "advertise-queue"))
15703 update_group_show_adj_queue(bgp, afi, safi, vty,
15704 subgrp_id);
15705 else if (!strcmp(what, "advertised-routes"))
15706 update_group_show_advertised(bgp, afi, safi, vty,
15707 subgrp_id);
15708 else if (!strcmp(what, "packet-queue"))
15709 update_group_show_packet_queue(bgp, afi, safi, vty,
15710 subgrp_id);
15711 }
3f9c7369
DS
15712}
15713
dc64bdec
QY
15714DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15715 show_ip_bgp_instance_updgrps_adj_s_cmd,
15716 "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",
15717 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15718 BGP_SAFI_HELP_STR
15719 "Detailed info about dynamic update groups\n"
15720 "Specific subgroup to display info for\n"
15721 "Advertisement queue\n"
15722 "Announced routes\n"
15723 "Packet queue\n")
3f9c7369 15724{
dc64bdec
QY
15725 uint64_t subgrp_id = 0;
15726 afi_t afiz;
15727 safi_t safiz;
15728 if (sgid)
15729 subgrp_id = strtoull(sgid, NULL, 10);
15730
15731 if (!ip && !afi)
15732 afiz = AFI_IP6;
15733 if (!ip && afi)
15734 afiz = bgp_vty_afi_from_str(afi);
15735 if (ip && !afi)
15736 afiz = AFI_IP;
15737 if (ip && afi) {
15738 afiz = bgp_vty_afi_from_str(afi);
15739 if (afiz != AFI_IP)
15740 vty_out(vty,
15741 "%% Cannot specify both 'ip' and 'ipv6'\n");
15742 return CMD_WARNING;
15743 }
d62a17ae 15744
dc64bdec 15745 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15746
dc64bdec 15747 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15748 return CMD_SUCCESS;
15749}
15750
6f4eacf3
DA
15751static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15752 json_object *json)
d62a17ae 15753{
15754 struct listnode *node, *nnode;
15755 struct prefix *range;
15756 struct peer *conf;
15757 struct peer *peer;
d62a17ae 15758 afi_t afi;
15759 safi_t safi;
15760 const char *peer_status;
d62a17ae 15761 int lr_count;
15762 int dynamic;
6f4eacf3
DA
15763 bool af_cfgd;
15764 json_object *json_peer_group = NULL;
15765 json_object *json_peer_group_afc = NULL;
15766 json_object *json_peer_group_members = NULL;
15767 json_object *json_peer_group_dynamic = NULL;
15768 json_object *json_peer_group_dynamic_af = NULL;
15769 json_object *json_peer_group_ranges = NULL;
d62a17ae 15770
15771 conf = group->conf;
15772
6f4eacf3
DA
15773 if (json) {
15774 json_peer_group = json_object_new_object();
15775 json_peer_group_afc = json_object_new_array();
15776 }
15777
d62a17ae 15778 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15779 if (json)
15780 json_object_int_add(json_peer_group, "remoteAs",
15781 conf->as);
15782 else
15783 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15784 group->name, conf->as);
d62a17ae 15785 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15786 if (json)
15787 json_object_int_add(json_peer_group, "remoteAs",
15788 group->bgp->as);
15789 else
15790 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15791 group->name, group->bgp->as);
d62a17ae 15792 } else {
6f4eacf3
DA
15793 if (!json)
15794 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15795 }
f14e6fdb 15796
6f4eacf3
DA
15797 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15798 if (json)
15799 json_object_string_add(json_peer_group, "type",
15800 "internal");
15801 else
15802 vty_out(vty, " Peer-group type is internal\n");
15803 } else {
15804 if (json)
15805 json_object_string_add(json_peer_group, "type",
15806 "external");
15807 else
15808 vty_out(vty, " Peer-group type is external\n");
15809 }
d62a17ae 15810
15811 /* Display AFs configured. */
6f4eacf3
DA
15812 if (!json)
15813 vty_out(vty, " Configured address-families:");
15814
05c7a1cc
QY
15815 FOREACH_AFI_SAFI (afi, safi) {
15816 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15817 af_cfgd = true;
15818 if (json)
15819 json_object_array_add(
15820 json_peer_group_afc,
15821 json_object_new_string(get_afi_safi_str(
15822 afi, safi, false)));
15823 else
15824 vty_out(vty, " %s;",
15825 get_afi_safi_str(afi, safi, false));
d62a17ae 15826 }
05c7a1cc 15827 }
6f4eacf3
DA
15828
15829 if (json) {
15830 json_object_object_add(json_peer_group,
15831 "addressFamiliesConfigured",
15832 json_peer_group_afc);
15833 } else {
15834 if (!af_cfgd)
15835 vty_out(vty, " none\n");
15836 else
15837 vty_out(vty, "\n");
15838 }
d62a17ae 15839
15840 /* Display listen ranges (for dynamic neighbors), if any */
15841 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15842 lr_count = listcount(group->listen_range[afi]);
15843 if (lr_count) {
6f4eacf3
DA
15844 if (json) {
15845 if (!json_peer_group_dynamic)
15846 json_peer_group_dynamic =
15847 json_object_new_object();
15848
15849 json_peer_group_dynamic_af =
15850 json_object_new_object();
15851 json_peer_group_ranges =
15852 json_object_new_array();
15853 json_object_int_add(json_peer_group_dynamic_af,
15854 "count", lr_count);
15855 } else {
15856 vty_out(vty, " %d %s listen range(s)\n",
15857 lr_count, afi2str(afi));
15858 }
d62a17ae 15859
15860 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15861 nnode, range)) {
15862 if (json) {
15863 char buf[BUFSIZ];
15864
15865 snprintfrr(buf, sizeof(buf), "%pFX",
15866 range);
15867
15868 json_object_array_add(
15869 json_peer_group_ranges,
15870 json_object_new_string(buf));
15871 } else {
15872 vty_out(vty, " %pFX\n", range);
15873 }
15874 }
15875
15876 if (json) {
15877 json_object_object_add(
15878 json_peer_group_dynamic_af, "ranges",
15879 json_peer_group_ranges);
15880
15881 json_object_object_add(
15882 json_peer_group_dynamic, afi2str(afi),
15883 json_peer_group_dynamic_af);
15884 }
d62a17ae 15885 }
15886 }
f14e6fdb 15887
6f4eacf3
DA
15888 if (json_peer_group_dynamic)
15889 json_object_object_add(json_peer_group, "dynamicRanges",
15890 json_peer_group_dynamic);
15891
d62a17ae 15892 /* Display group members and their status */
15893 if (listcount(group->peer)) {
6f4eacf3
DA
15894 if (json)
15895 json_peer_group_members = json_object_new_object();
15896 else
15897 vty_out(vty, " Peer-group members:\n");
d62a17ae 15898 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15899 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15900 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15901 peer_status = "Idle (Admin)";
15902 else if (CHECK_FLAG(peer->sflags,
15903 PEER_STATUS_PREFIX_OVERFLOW))
15904 peer_status = "Idle (PfxCt)";
15905 else
15906 peer_status = lookup_msg(bgp_status_msg,
15907 peer->status, NULL);
15908
15909 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15910
15911 if (json) {
15912 json_object *json_peer_group_member =
15913 json_object_new_object();
15914
15915 json_object_string_add(json_peer_group_member,
15916 "status", peer_status);
15917
15918 if (dynamic)
15919 json_object_boolean_true_add(
15920 json_peer_group_member,
15921 "dynamic");
15922
15923 json_object_object_add(json_peer_group_members,
15924 peer->host,
15925 json_peer_group_member);
15926 } else {
15927 vty_out(vty, " %s %s %s \n", peer->host,
15928 dynamic ? "(dynamic)" : "",
15929 peer_status);
15930 }
d62a17ae 15931 }
6f4eacf3
DA
15932 if (json)
15933 json_object_object_add(json_peer_group, "members",
15934 json_peer_group_members);
d62a17ae 15935 }
f14e6fdb 15936
6f4eacf3
DA
15937 if (json)
15938 json_object_object_add(json, group->name, json_peer_group);
15939
d62a17ae 15940 return CMD_SUCCESS;
15941}
15942
ff9959b0 15943static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15944 const char *group_name, bool uj)
d62a17ae 15945{
ff9959b0 15946 struct bgp *bgp;
d62a17ae 15947 struct listnode *node, *nnode;
15948 struct peer_group *group;
ff9959b0 15949 bool found = false;
6f4eacf3
DA
15950 json_object *json = NULL;
15951
15952 if (uj)
15953 json = json_object_new_object();
ff9959b0
QY
15954
15955 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15956
15957 if (!bgp) {
6f4eacf3
DA
15958 if (uj) {
15959 vty_out(vty, "%s\n",
15960 json_object_to_json_string_ext(
15961 json, JSON_C_TO_STRING_PRETTY));
15962 json_object_free(json);
15963 } else {
15964 vty_out(vty, "%% BGP instance not found\n");
15965 }
15966
ff9959b0
QY
15967 return CMD_WARNING;
15968 }
d62a17ae 15969
15970 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15971 if (group_name) {
15972 if (strmatch(group->name, group_name)) {
6f4eacf3 15973 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15974 found = true;
15975 break;
d62a17ae 15976 }
ff9959b0 15977 } else {
6f4eacf3 15978 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15979 }
f14e6fdb 15980 }
f14e6fdb 15981
6f4eacf3 15982 if (group_name && !found && !uj)
d62a17ae 15983 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15984
6f4eacf3
DA
15985 if (uj) {
15986 vty_out(vty, "%s\n",
15987 json_object_to_json_string_ext(
15988 json, JSON_C_TO_STRING_PRETTY));
15989 json_object_free(json);
15990 }
15991
d62a17ae 15992 return CMD_SUCCESS;
f14e6fdb
DS
15993}
15994
6f4eacf3
DA
15995DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15996 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15997 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15998 "Detailed information on BGP peer groups\n"
15999 "Peer group name\n" JSON_STR)
f14e6fdb 16000{
d62a17ae 16001 char *vrf, *pg;
d62a17ae 16002 int idx = 0;
6f4eacf3 16003 bool uj = use_json(argc, argv);
f14e6fdb 16004
a4d82a8a
PZ
16005 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
16006 : NULL;
d62a17ae 16007 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 16008
6f4eacf3 16009 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 16010}
3f9c7369 16011
d6e3c605 16012
718e3744 16013/* Redistribute VTY commands. */
16014
37a87b8f
CS
16015DEFUN_YANG (bgp_redistribute_ipv4,
16016 bgp_redistribute_ipv4_cmd,
16017 "redistribute " FRR_IP_REDIST_STR_BGPD,
16018 "Redistribute information from another routing protocol\n"
16019 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 16020{
d62a17ae 16021 int idx_protocol = 1;
37a87b8f 16022 char base_xpath[XPATH_MAXLEN];
718e3744 16023
37a87b8f
CS
16024 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16025 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16026 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16027 argv[idx_protocol]->text, "0");
16028
16029 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 16030
37a87b8f 16031 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16032}
16033
d62a17ae 16034ALIAS_HIDDEN(
16035 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
16036 "redistribute " FRR_IP_REDIST_STR_BGPD,
16037 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 16038
37a87b8f
CS
16039DEFUN_YANG (bgp_redistribute_ipv4_rmap,
16040 bgp_redistribute_ipv4_rmap_cmd,
16041 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
16042 "Redistribute information from another routing protocol\n"
16043 FRR_IP_REDIST_HELP_STR_BGPD
16044 "Route map reference\n"
16045 "Pointer to route-map entries\n")
718e3744 16046{
d62a17ae 16047 int idx_protocol = 1;
16048 int idx_word = 3;
37a87b8f
CS
16049 char base_xpath[XPATH_MAXLEN];
16050
16051 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16052 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16053 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16054 argv[idx_protocol]->text, "0");
718e3744 16055
37a87b8f
CS
16056 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16057 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16058 argv[idx_word]->arg);
16059
16060 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16061}
16062
d62a17ae 16063ALIAS_HIDDEN(
16064 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
16065 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
16066 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16067 "Route map reference\n"
16068 "Pointer to route-map entries\n")
596c17ba 16069
37a87b8f
CS
16070DEFUN_YANG (bgp_redistribute_ipv4_metric,
16071 bgp_redistribute_ipv4_metric_cmd,
16072 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16073 "Redistribute information from another routing protocol\n"
16074 FRR_IP_REDIST_HELP_STR_BGPD
16075 "Metric for redistributed routes\n"
16076 "Default metric\n")
718e3744 16077{
d62a17ae 16078 int idx_protocol = 1;
16079 int idx_number = 3;
37a87b8f
CS
16080 char base_xpath[XPATH_MAXLEN];
16081
16082 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16083 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16084 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16085 argv[idx_protocol]->text, "0");
d62a17ae 16086
37a87b8f
CS
16087 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16088 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16089 argv[idx_number]->arg);
16090
16091 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16092}
16093
16094ALIAS_HIDDEN(
16095 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16096 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16097 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16098 "Metric for redistributed routes\n"
16099 "Default metric\n")
596c17ba 16100
37a87b8f
CS
16101DEFUN_YANG(
16102 bgp_redistribute_ipv4_rmap_metric,
16103 bgp_redistribute_ipv4_rmap_metric_cmd,
16104 "redistribute " FRR_IP_REDIST_STR_BGPD
16105 " route-map WORD metric (0-4294967295)",
16106 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16107 "Route map reference\n"
16108 "Pointer to route-map entries\n"
16109 "Metric for redistributed routes\n"
16110 "Default metric\n")
718e3744 16111{
d62a17ae 16112 int idx_protocol = 1;
16113 int idx_word = 3;
16114 int idx_number = 5;
37a87b8f
CS
16115 char base_xpath[XPATH_MAXLEN];
16116
16117 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16118 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16119 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16120 argv[idx_protocol]->text, "0");
16121
16122 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16123 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16124 argv[idx_word]->arg);
16125 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16126 argv[idx_number]->arg);
d62a17ae 16127
37a87b8f 16128 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16129}
16130
16131ALIAS_HIDDEN(
16132 bgp_redistribute_ipv4_rmap_metric,
16133 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16134 "redistribute " FRR_IP_REDIST_STR_BGPD
16135 " route-map WORD metric (0-4294967295)",
16136 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16137 "Route map reference\n"
16138 "Pointer to route-map entries\n"
16139 "Metric for redistributed routes\n"
16140 "Default metric\n")
596c17ba 16141
37a87b8f
CS
16142DEFUN_YANG(
16143 bgp_redistribute_ipv4_metric_rmap,
16144 bgp_redistribute_ipv4_metric_rmap_cmd,
16145 "redistribute " FRR_IP_REDIST_STR_BGPD
16146 " metric (0-4294967295) route-map WORD",
16147 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16148 "Metric for redistributed routes\n"
16149 "Default metric\n"
16150 "Route map reference\n"
16151 "Pointer to route-map entries\n")
718e3744 16152{
d62a17ae 16153 int idx_protocol = 1;
d62a17ae 16154 int idx_word = 5;
37a87b8f
CS
16155 int idx_number = 3;
16156 char base_xpath[XPATH_MAXLEN];
16157
16158 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16159 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16160 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16161 argv[idx_protocol]->text, "0");
16162
16163 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16164 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16165 argv[idx_number]->arg);
16166 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16167 argv[idx_word]->arg);
d62a17ae 16168
37a87b8f 16169 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16170}
16171
16172ALIAS_HIDDEN(
16173 bgp_redistribute_ipv4_metric_rmap,
16174 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16175 "redistribute " FRR_IP_REDIST_STR_BGPD
16176 " metric (0-4294967295) route-map WORD",
16177 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16178 "Metric for redistributed routes\n"
16179 "Default metric\n"
16180 "Route map reference\n"
16181 "Pointer to route-map entries\n")
596c17ba 16182
37a87b8f
CS
16183DEFUN_YANG (bgp_redistribute_ipv4_ospf,
16184 bgp_redistribute_ipv4_ospf_cmd,
16185 "redistribute <ospf|table> (1-65535)",
16186 "Redistribute information from another routing protocol\n"
16187 "Open Shortest Path First (OSPFv2)\n"
16188 "Non-main Kernel Routing Table\n"
16189 "Instance ID/Table ID\n")
7c8ff89e 16190{
37a87b8f 16191 int idx_protocol = 1;
d62a17ae 16192 int idx_number = 2;
37a87b8f 16193 char base_xpath[XPATH_MAXLEN];
7c8ff89e 16194
37a87b8f
CS
16195 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16196 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16197 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16198 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 16199
37a87b8f 16200 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 16201
37a87b8f 16202 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
16203}
16204
d62a17ae 16205ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16206 "redistribute <ospf|table> (1-65535)",
16207 "Redistribute information from another routing protocol\n"
16208 "Open Shortest Path First (OSPFv2)\n"
16209 "Non-main Kernel Routing Table\n"
16210 "Instance ID/Table ID\n")
596c17ba 16211
37a87b8f
CS
16212DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
16213 bgp_redistribute_ipv4_ospf_rmap_cmd,
16214 "redistribute <ospf|table> (1-65535) route-map WORD",
16215 "Redistribute information from another routing protocol\n"
16216 "Open Shortest Path First (OSPFv2)\n"
16217 "Non-main Kernel Routing Table\n"
16218 "Instance ID/Table ID\n"
16219 "Route map reference\n"
16220 "Pointer to route-map entries\n")
7c8ff89e 16221{
37a87b8f 16222 int idx_protocol = 1;
d62a17ae 16223 int idx_number = 2;
16224 int idx_word = 4;
37a87b8f
CS
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_IP, SAFI_UNICAST),
16229 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16230 argv[idx_protocol]->text, argv[idx_number]->arg);
16231
16232 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16233
16234 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16235 argv[idx_word]->arg);
d62a17ae 16236
37a87b8f 16237 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16238}
16239
16240ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16241 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16242 "redistribute <ospf|table> (1-65535) route-map WORD",
16243 "Redistribute information from another routing protocol\n"
16244 "Open Shortest Path First (OSPFv2)\n"
16245 "Non-main Kernel Routing Table\n"
16246 "Instance ID/Table ID\n"
16247 "Route map reference\n"
16248 "Pointer to route-map entries\n")
596c17ba 16249
37a87b8f
CS
16250DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
16251 bgp_redistribute_ipv4_ospf_metric_cmd,
16252 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16253 "Redistribute information from another routing protocol\n"
16254 "Open Shortest Path First (OSPFv2)\n"
16255 "Non-main Kernel Routing Table\n"
16256 "Instance ID/Table ID\n"
16257 "Metric for redistributed routes\n"
16258 "Default metric\n")
7c8ff89e 16259{
37a87b8f 16260 int idx_protocol = 1;
d62a17ae 16261 int idx_number = 2;
16262 int idx_number_2 = 4;
37a87b8f
CS
16263 char base_xpath[XPATH_MAXLEN];
16264
16265 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16266 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16267 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16268 argv[idx_protocol]->text, argv[idx_number]->arg);
16269
16270 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16271
37a87b8f
CS
16272 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16273 argv[idx_number_2]->arg);
d62a17ae 16274
37a87b8f 16275 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16276}
16277
16278ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16279 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16280 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16281 "Redistribute information from another routing protocol\n"
16282 "Open Shortest Path First (OSPFv2)\n"
16283 "Non-main Kernel Routing Table\n"
16284 "Instance ID/Table ID\n"
16285 "Metric for redistributed routes\n"
16286 "Default metric\n")
596c17ba 16287
37a87b8f
CS
16288DEFUN_YANG(
16289 bgp_redistribute_ipv4_ospf_rmap_metric,
16290 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16291 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16292 "Redistribute information from another routing protocol\n"
16293 "Open Shortest Path First (OSPFv2)\n"
16294 "Non-main Kernel Routing Table\n"
16295 "Instance ID/Table ID\n"
16296 "Route map reference\n"
16297 "Pointer to route-map entries\n"
16298 "Metric for redistributed routes\n"
16299 "Default metric\n")
7c8ff89e 16300{
37a87b8f 16301 int idx_protocol = 1;
d62a17ae 16302 int idx_number = 2;
16303 int idx_word = 4;
16304 int idx_number_2 = 6;
37a87b8f
CS
16305 char base_xpath[XPATH_MAXLEN];
16306
16307 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16308 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16309 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16310 argv[idx_protocol]->text, argv[idx_number]->arg);
16311
16312 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16313
37a87b8f
CS
16314 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16315 argv[idx_word]->arg);
16316 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16317 argv[idx_number_2]->arg);
d62a17ae 16318
37a87b8f 16319 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16320}
16321
16322ALIAS_HIDDEN(
16323 bgp_redistribute_ipv4_ospf_rmap_metric,
16324 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16325 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16326 "Redistribute information from another routing protocol\n"
16327 "Open Shortest Path First (OSPFv2)\n"
16328 "Non-main Kernel Routing Table\n"
16329 "Instance ID/Table ID\n"
16330 "Route map reference\n"
16331 "Pointer to route-map entries\n"
16332 "Metric for redistributed routes\n"
16333 "Default metric\n")
596c17ba 16334
37a87b8f
CS
16335DEFUN_YANG(
16336 bgp_redistribute_ipv4_ospf_metric_rmap,
16337 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16338 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16339 "Redistribute information from another routing protocol\n"
16340 "Open Shortest Path First (OSPFv2)\n"
16341 "Non-main Kernel Routing Table\n"
16342 "Instance ID/Table ID\n"
16343 "Metric for redistributed routes\n"
16344 "Default metric\n"
16345 "Route map reference\n"
16346 "Pointer to route-map entries\n")
7c8ff89e 16347{
37a87b8f 16348 int idx_protocol = 1;
d62a17ae 16349 int idx_number = 2;
16350 int idx_number_2 = 4;
16351 int idx_word = 6;
37a87b8f
CS
16352 char base_xpath[XPATH_MAXLEN];
16353
16354 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16355 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16356 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16357 argv[idx_protocol]->text, argv[idx_number]->arg);
16358
16359 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16360
37a87b8f
CS
16361 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16362 argv[idx_number_2]->arg);
16363 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16364 argv[idx_word]->arg);
d62a17ae 16365
37a87b8f 16366 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16367}
16368
16369ALIAS_HIDDEN(
16370 bgp_redistribute_ipv4_ospf_metric_rmap,
16371 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16372 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16373 "Redistribute information from another routing protocol\n"
16374 "Open Shortest Path First (OSPFv2)\n"
16375 "Non-main Kernel Routing Table\n"
16376 "Instance ID/Table ID\n"
16377 "Metric for redistributed routes\n"
16378 "Default metric\n"
16379 "Route map reference\n"
16380 "Pointer to route-map entries\n")
596c17ba 16381
37a87b8f
CS
16382DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
16383 no_bgp_redistribute_ipv4_ospf_cmd,
16384 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16385 NO_STR
16386 "Redistribute information from another routing protocol\n"
16387 "Open Shortest Path First (OSPFv2)\n"
16388 "Non-main Kernel Routing Table\n"
16389 "Instance ID/Table ID\n"
16390 "Metric for redistributed routes\n"
16391 "Default metric\n"
16392 "Route map reference\n"
16393 "Pointer to route-map entries\n")
7c8ff89e 16394{
37a87b8f 16395 int idx_protocol = 2;
d62a17ae 16396 int idx_number = 3;
37a87b8f 16397 char base_xpath[XPATH_MAXLEN];
d62a17ae 16398
37a87b8f
CS
16399 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16400 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16401 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16402 argv[idx_protocol]->text, argv[idx_number]->arg);
16403
16404 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 16405
37a87b8f 16406 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16407}
16408
16409ALIAS_HIDDEN(
16410 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 16411 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16412 NO_STR
16413 "Redistribute information from another routing protocol\n"
16414 "Open Shortest Path First (OSPFv2)\n"
16415 "Non-main Kernel Routing Table\n"
16416 "Instance ID/Table ID\n"
16417 "Metric for redistributed routes\n"
16418 "Default metric\n"
16419 "Route map reference\n"
16420 "Pointer to route-map entries\n")
596c17ba 16421
37a87b8f
CS
16422DEFUN_YANG (no_bgp_redistribute_ipv4,
16423 no_bgp_redistribute_ipv4_cmd,
16424 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16425 NO_STR
16426 "Redistribute information from another routing protocol\n"
16427 FRR_IP_REDIST_HELP_STR_BGPD
16428 "Metric for redistributed routes\n"
16429 "Default metric\n"
16430 "Route map reference\n"
16431 "Pointer to route-map entries\n")
718e3744 16432{
d62a17ae 16433 int idx_protocol = 2;
37a87b8f 16434 char base_xpath[XPATH_MAXLEN];
d62a17ae 16435
37a87b8f
CS
16436 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16437 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16438 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16439 argv[idx_protocol]->text, "0");
16440
16441 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16442
16443 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16444}
16445
16446ALIAS_HIDDEN(
16447 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16448 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 16449 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16450 NO_STR
16451 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16452 "Metric for redistributed routes\n"
16453 "Default metric\n"
16454 "Route map reference\n"
16455 "Pointer to route-map entries\n")
596c17ba 16456
37a87b8f
CS
16457DEFUN_YANG (bgp_redistribute_ipv6,
16458 bgp_redistribute_ipv6_cmd,
16459 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16460 "Redistribute information from another routing protocol\n"
16461 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16462{
d62a17ae 16463 int idx_protocol = 1;
37a87b8f 16464 char base_xpath[XPATH_MAXLEN];
718e3744 16465
37a87b8f
CS
16466 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16467 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16468 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16469 argv[idx_protocol]->text, "0");
16470
16471 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 16472
37a87b8f 16473 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16474}
16475
37a87b8f
CS
16476DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16477 bgp_redistribute_ipv6_rmap_cmd,
16478 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16479 "Redistribute information from another routing protocol\n"
16480 FRR_IP6_REDIST_HELP_STR_BGPD
16481 "Route map reference\n"
16482 "Pointer to route-map entries\n")
718e3744 16483{
d62a17ae 16484 int idx_protocol = 1;
16485 int idx_word = 3;
37a87b8f
CS
16486 char base_xpath[XPATH_MAXLEN];
16487
16488 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16489 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16490 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16491 argv[idx_protocol]->text, "0");
718e3744 16492
37a87b8f
CS
16493 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16494 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16495 argv[idx_word]->arg);
16496
16497 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16498}
16499
37a87b8f 16500DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 16501 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16502 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16503 "Redistribute information from another routing protocol\n"
ab0181ee 16504 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16505 "Metric for redistributed routes\n"
16506 "Default metric\n")
16507{
d62a17ae 16508 int idx_protocol = 1;
16509 int idx_number = 3;
37a87b8f
CS
16510 char base_xpath[XPATH_MAXLEN];
16511
16512 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16513 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16514 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16515 argv[idx_protocol]->text, "0");
718e3744 16516
37a87b8f
CS
16517 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16518 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16519 argv[idx_number]->arg);
16520
16521 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16522}
16523
37a87b8f
CS
16524DEFUN_YANG(
16525 bgp_redistribute_ipv6_rmap_metric,
16526 bgp_redistribute_ipv6_rmap_metric_cmd,
16527 "redistribute " FRR_IP6_REDIST_STR_BGPD
16528 " route-map WORD metric (0-4294967295)",
16529 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16530 "Route map reference\n"
16531 "Pointer to route-map entries\n"
16532 "Metric for redistributed routes\n"
16533 "Default metric\n")
718e3744 16534{
d62a17ae 16535 int idx_protocol = 1;
16536 int idx_word = 3;
16537 int idx_number = 5;
37a87b8f
CS
16538 char base_xpath[XPATH_MAXLEN];
16539
16540 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16541 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16542 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16543 argv[idx_protocol]->text, "0");
718e3744 16544
37a87b8f
CS
16545 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16546 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16547 argv[idx_word]->arg);
16548 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16549 argv[idx_number]->arg);
16550
16551 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16552}
16553
37a87b8f
CS
16554DEFUN_YANG(
16555 bgp_redistribute_ipv6_metric_rmap,
16556 bgp_redistribute_ipv6_metric_rmap_cmd,
16557 "redistribute " FRR_IP6_REDIST_STR_BGPD
16558 " metric (0-4294967295) route-map WORD",
16559 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16560 "Metric for redistributed routes\n"
16561 "Default metric\n"
16562 "Route map reference\n"
16563 "Pointer to route-map entries\n")
718e3744 16564{
d62a17ae 16565 int idx_protocol = 1;
d62a17ae 16566 int idx_word = 5;
37a87b8f
CS
16567 int idx_number = 3;
16568 char base_xpath[XPATH_MAXLEN];
16569
16570 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16571 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16572 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16573 argv[idx_protocol]->text, "0");
718e3744 16574
37a87b8f
CS
16575 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16576 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16577 argv[idx_number]->arg);
16578 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16579 argv[idx_word]->arg);
16580
16581 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16582}
16583
37a87b8f
CS
16584DEFUN_YANG(
16585 no_bgp_redistribute_ipv6,
16586 no_bgp_redistribute_ipv6_cmd,
16587 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16588 " [{metric (0-4294967295)|route-map WORD}]",
16589 NO_STR
16590 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16591 "Metric for redistributed routes\n"
16592 "Default metric\n"
16593 "Route map reference\n"
16594 "Pointer to route-map entries\n")
718e3744 16595{
d62a17ae 16596 int idx_protocol = 2;
37a87b8f 16597 char base_xpath[XPATH_MAXLEN];
718e3744 16598
37a87b8f
CS
16599 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16600 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16601 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16602 argv[idx_protocol]->text, "0");
16603
16604 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16605
16606 return nb_cli_apply_changes(vty, base_xpath);
16607}
718e3744 16608
37a87b8f
CS
16609void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16610 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16611{
16612 uint32_t instance = 0;
16613
16614 vty_out(vty, " redistribute %s",
16615 yang_dnode_get_string(dnode, "./route-type"));
16616 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16617 vty_out(vty, " %d", instance);
16618 if (yang_dnode_exists(dnode, "./metric"))
16619 vty_out(vty, " metric %u",
16620 yang_dnode_get_uint32(dnode, "./metric"));
16621 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16622 vty_out(vty, " route-map %s",
16623 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16624 vty_out(vty, "\n");
d62a17ae 16625}
16626
4ab46701
AR
16627/* Neighbor update tcp-mss. */
16628static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16629 const char *tcp_mss_str)
16630{
16631 struct peer *peer;
16632 uint32_t tcp_mss_val = 0;
16633
16634 peer = peer_and_group_lookup_vty(vty, peer_str);
16635 if (!peer)
16636 return CMD_WARNING_CONFIG_FAILED;
16637
16638 if (tcp_mss_str) {
16639 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16640 peer_tcp_mss_set(peer, tcp_mss_val);
16641 } else {
16642 peer_tcp_mss_unset(peer);
16643 }
16644
16645 return CMD_SUCCESS;
16646}
16647
16648DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16649 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16650 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16651 "TCP max segment size\n"
16652 "TCP MSS value\n")
16653{
16654 int peer_index = 1;
16655 int mss_index = 3;
16656
16657 vty_out(vty,
16658 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16659 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16660 argv[mss_index]->arg);
16661}
16662
16663DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16664 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16665 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16666 "TCP max segment size\n"
16667 "TCP MSS value\n")
16668{
16669 int peer_index = 2;
16670
16671 vty_out(vty,
16672 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16673 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16674}
16675
dd65f45e
DL
16676static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16677 afi_t afi, safi_t safi)
d62a17ae 16678{
16679 int i;
16680
16681 /* Unicast redistribution only. */
16682 if (safi != SAFI_UNICAST)
2b791107 16683 return;
d62a17ae 16684
16685 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16686 /* Redistribute BGP does not make sense. */
16687 if (i != ZEBRA_ROUTE_BGP) {
16688 struct list *red_list;
16689 struct listnode *node;
16690 struct bgp_redist *red;
16691
16692 red_list = bgp->redist[afi][i];
16693 if (!red_list)
16694 continue;
16695
16696 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16697 /* "redistribute" configuration. */
16698 vty_out(vty, " redistribute %s",
16699 zebra_route_string(i));
16700 if (red->instance)
16701 vty_out(vty, " %d", red->instance);
16702 if (red->redist_metric_flag)
16703 vty_out(vty, " metric %u",
16704 red->redist_metric);
16705 if (red->rmap.name)
16706 vty_out(vty, " route-map %s",
16707 red->rmap.name);
16708 vty_out(vty, "\n");
16709 }
16710 }
16711 }
718e3744 16712}
6b0655a2 16713
dd65f45e
DL
16714/* peer-group helpers for config-write */
16715
16716static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16717{
16718 if (!peer_group_active(peer)) {
16719 if (CHECK_FLAG(peer->flags_invert, flag))
16720 return !CHECK_FLAG(peer->flags, flag);
16721 else
16722 return !!CHECK_FLAG(peer->flags, flag);
16723 }
16724
16725 return !!CHECK_FLAG(peer->flags_override, flag);
16726}
16727
16728static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16729 uint32_t flag)
16730{
16731 if (!peer_group_active(peer)) {
16732 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16733 return !peer_af_flag_check(peer, afi, safi, flag);
16734 else
16735 return !!peer_af_flag_check(peer, afi, safi, flag);
16736 }
16737
16738 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16739}
16740
16741static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16742 uint8_t type, int direct)
16743{
16744 struct bgp_filter *filter;
16745
16746 if (peer_group_active(peer))
16747 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16748 type);
16749
16750 filter = &peer->filter[afi][safi];
16751 switch (type) {
16752 case PEER_FT_DISTRIBUTE_LIST:
16753 return !!(filter->dlist[direct].name);
16754 case PEER_FT_FILTER_LIST:
16755 return !!(filter->aslist[direct].name);
16756 case PEER_FT_PREFIX_LIST:
16757 return !!(filter->plist[direct].name);
16758 case PEER_FT_ROUTE_MAP:
16759 return !!(filter->map[direct].name);
16760 case PEER_FT_UNSUPPRESS_MAP:
16761 return !!(filter->usmap.name);
7f7940e6
MK
16762 case PEER_FT_ADVERTISE_MAP:
16763 return !!(filter->advmap.aname
16764 && ((filter->advmap.condition == direct)
16765 && filter->advmap.cname));
dd65f45e
DL
16766 default:
16767 return false;
16768 }
16769}
16770
16771/* Return true if the addpath type is set for peer and different from
16772 * peer-group.
16773 */
3dc339cd
DA
16774static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16775 safi_t safi)
dd65f45e
DL
16776{
16777 enum bgp_addpath_strat type, g_type;
16778
16779 type = peer->addpath_type[afi][safi];
16780
16781 if (type != BGP_ADDPATH_NONE) {
16782 if (peer_group_active(peer)) {
16783 g_type = peer->group->conf->addpath_type[afi][safi];
16784
16785 if (type != g_type)
3dc339cd 16786 return true;
dd65f45e 16787 else
3dc339cd 16788 return false;
dd65f45e
DL
16789 }
16790
3dc339cd 16791 return true;
dd65f45e
DL
16792 }
16793
3dc339cd 16794 return false;
dd65f45e
DL
16795}
16796
b9c7bc5a 16797/* This is part of the address-family block (unicast only) */
dd65f45e 16798static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16799 afi_t afi)
16800{
b9c7bc5a 16801 int indent = 2;
ddb5b488 16802
8a066a70 16803 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16804 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16805 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16806 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16807 bgp->vpn_policy[afi]
bb4f6190 16808 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16809 else
16810 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16811 bgp->vpn_policy[afi]
16812 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16813 }
12a844a5
DS
16814 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16815 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16816 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16817 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16818 return;
16819
e70e9f8e
PZ
16820 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16821 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16822
16823 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16824
16825 } else {
16826 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16827 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16828 bgp->vpn_policy[afi].tovpn_label);
16829 }
ddb5b488
PZ
16830 }
16831 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16832 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16833 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16834 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16835 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16836 sizeof(buf)));
16837 }
16838 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16839 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16840
16841 char buf[PREFIX_STRLEN];
16842 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16843 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16844 sizeof(buf))) {
16845
b9c7bc5a
PZ
16846 vty_out(vty, "%*snexthop vpn export %s\n",
16847 indent, "", buf);
ddb5b488
PZ
16848 }
16849 }
16850 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16851 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16852 && ecommunity_cmp(
16853 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16854 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16855
16856 char *b = ecommunity_ecom2str(
16857 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16858 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16859 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16860 XFREE(MTYPE_ECOMMUNITY_STR, b);
16861 } else {
16862 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16863 char *b = ecommunity_ecom2str(
16864 bgp->vpn_policy[afi]
16865 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16866 ECOMMUNITY_FORMAT_ROUTE_MAP,
16867 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16868 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16869 XFREE(MTYPE_ECOMMUNITY_STR, b);
16870 }
16871 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16872 char *b = ecommunity_ecom2str(
16873 bgp->vpn_policy[afi]
16874 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16875 ECOMMUNITY_FORMAT_ROUTE_MAP,
16876 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16877 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16878 XFREE(MTYPE_ECOMMUNITY_STR, b);
16879 }
16880 }
bb4f6190
DS
16881
16882 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16883 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16884 bgp->vpn_policy[afi]
16885 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16886
301ad80a
PG
16887 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16888 char *b = ecommunity_ecom2str(
16889 bgp->vpn_policy[afi]
16890 .import_redirect_rtlist,
16891 ECOMMUNITY_FORMAT_ROUTE_MAP,
16892 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16893
9a659715
PG
16894 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16895 != ECOMMUNITY_SIZE)
c6423c31 16896 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16897 indent, "", b);
16898 else
16899 vty_out(vty, "%*srt redirect import %s\n",
16900 indent, "", b);
301ad80a
PG
16901 XFREE(MTYPE_ECOMMUNITY_STR, b);
16902 }
ddb5b488
PZ
16903}
16904
dd65f45e
DL
16905static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16906 afi_t afi, safi_t safi)
16907{
16908 struct bgp_filter *filter;
16909 char *addr;
16910
16911 addr = peer->host;
16912 filter = &peer->filter[afi][safi];
16913
16914 /* distribute-list. */
16915 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16916 FILTER_IN))
16917 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16918 filter->dlist[FILTER_IN].name);
16919
16920 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16921 FILTER_OUT))
16922 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16923 filter->dlist[FILTER_OUT].name);
16924
16925 /* prefix-list. */
16926 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16927 FILTER_IN))
16928 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16929 filter->plist[FILTER_IN].name);
16930
16931 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16932 FILTER_OUT))
16933 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16934 filter->plist[FILTER_OUT].name);
16935
16936 /* route-map. */
16937 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16938 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16939 filter->map[RMAP_IN].name);
16940
16941 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16942 RMAP_OUT))
16943 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16944 filter->map[RMAP_OUT].name);
16945
16946 /* unsuppress-map */
16947 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16948 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16949 filter->usmap.name);
16950
7f7940e6
MK
16951 /* advertise-map : always applied in OUT direction*/
16952 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16953 CONDITION_NON_EXIST))
16954 vty_out(vty,
16955 " neighbor %s advertise-map %s non-exist-map %s\n",
16956 addr, filter->advmap.aname, filter->advmap.cname);
16957
16958 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16959 CONDITION_EXIST))
16960 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16961 addr, filter->advmap.aname, filter->advmap.cname);
16962
dd65f45e
DL
16963 /* filter-list. */
16964 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16965 FILTER_IN))
16966 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16967 filter->aslist[FILTER_IN].name);
16968
16969 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16970 FILTER_OUT))
16971 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16972 filter->aslist[FILTER_OUT].name);
16973}
16974
16975/* BGP peer configuration display function. */
16976static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16977 struct peer *peer)
16978{
16979 struct peer *g_peer = NULL;
16980 char buf[SU_ADDRSTRLEN];
16981 char *addr;
16982 int if_pg_printed = false;
16983 int if_ras_printed = false;
16984
16985 /* Skip dynamic neighbors. */
16986 if (peer_dynamic_neighbor(peer))
16987 return;
16988
16989 if (peer->conf_if)
16990 addr = peer->conf_if;
16991 else
16992 addr = peer->host;
16993
16994 /************************************
16995 ****** Global to the neighbor ******
16996 ************************************/
16997 if (peer->conf_if) {
16998 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16999 vty_out(vty, " neighbor %s interface v6only", addr);
17000 else
17001 vty_out(vty, " neighbor %s interface", addr);
17002
17003 if (peer_group_active(peer)) {
17004 vty_out(vty, " peer-group %s", peer->group->name);
17005 if_pg_printed = true;
17006 } else if (peer->as_type == AS_SPECIFIED) {
17007 vty_out(vty, " remote-as %u", peer->as);
17008 if_ras_printed = true;
17009 } else if (peer->as_type == AS_INTERNAL) {
17010 vty_out(vty, " remote-as internal");
17011 if_ras_printed = true;
17012 } else if (peer->as_type == AS_EXTERNAL) {
17013 vty_out(vty, " remote-as external");
17014 if_ras_printed = true;
17015 }
17016
17017 vty_out(vty, "\n");
17018 }
17019
17020 /* remote-as and peer-group */
17021 /* peer is a member of a peer-group */
17022 if (peer_group_active(peer)) {
17023 g_peer = peer->group->conf;
17024
17025 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
17026 if (peer->as_type == AS_SPECIFIED) {
17027 vty_out(vty, " neighbor %s remote-as %u\n",
17028 addr, peer->as);
17029 } else if (peer->as_type == AS_INTERNAL) {
17030 vty_out(vty,
17031 " neighbor %s remote-as internal\n",
17032 addr);
17033 } else if (peer->as_type == AS_EXTERNAL) {
17034 vty_out(vty,
17035 " neighbor %s remote-as external\n",
17036 addr);
17037 }
17038 }
17039
17040 /* For swpX peers we displayed the peer-group
17041 * via 'neighbor swpX interface peer-group PGNAME' */
17042 if (!if_pg_printed)
17043 vty_out(vty, " neighbor %s peer-group %s\n", addr,
17044 peer->group->name);
17045 }
17046
17047 /* peer is NOT a member of a peer-group */
17048 else {
17049 /* peer is a peer-group, declare the peer-group */
17050 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
17051 vty_out(vty, " neighbor %s peer-group\n", addr);
17052 }
17053
17054 if (!if_ras_printed) {
17055 if (peer->as_type == AS_SPECIFIED) {
17056 vty_out(vty, " neighbor %s remote-as %u\n",
17057 addr, peer->as);
17058 } else if (peer->as_type == AS_INTERNAL) {
17059 vty_out(vty,
17060 " neighbor %s remote-as internal\n",
17061 addr);
17062 } else if (peer->as_type == AS_EXTERNAL) {
17063 vty_out(vty,
17064 " neighbor %s remote-as external\n",
17065 addr);
17066 }
17067 }
17068 }
17069
17070 /* local-as */
17071 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
17072 vty_out(vty, " neighbor %s local-as %u", addr,
17073 peer->change_local_as);
17074 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
17075 vty_out(vty, " no-prepend");
17076 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
17077 vty_out(vty, " replace-as");
17078 vty_out(vty, "\n");
17079 }
17080
17081 /* description */
17082 if (peer->desc) {
17083 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
17084 }
17085
17086 /* shutdown */
17087 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
17088 if (peer->tx_shutdown_message)
17089 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
17090 peer->tx_shutdown_message);
17091 else
17092 vty_out(vty, " neighbor %s shutdown\n", addr);
17093 }
17094
8336c896
DA
17095 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17096 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17097 peer->rtt_expected, peer->rtt_keepalive_conf);
17098
dd65f45e 17099 /* bfd */
21bfce98
RZ
17100 if (peer->bfd_config)
17101 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17102
17103 /* password */
17104 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17105 vty_out(vty, " neighbor %s password %s\n", addr,
17106 peer->password);
17107
17108 /* neighbor solo */
17109 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17110 if (!peer_group_active(peer)) {
17111 vty_out(vty, " neighbor %s solo\n", addr);
17112 }
17113 }
17114
17115 /* BGP port */
17116 if (peer->port != BGP_PORT_DEFAULT) {
17117 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17118 }
17119
17120 /* Local interface name */
17121 if (peer->ifname) {
17122 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17123 }
17124
4ab46701
AR
17125 /* TCP max segment size */
17126 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17127 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17128
dd65f45e
DL
17129 /* passive */
17130 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17131 vty_out(vty, " neighbor %s passive\n", addr);
17132
17133 /* ebgp-multihop */
17134 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17135 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17136 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17137 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17138 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17139 peer->ttl);
17140 }
17141 }
17142
17143 /* ttl-security hops */
e2521429 17144 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17145 if (!peer_group_active(peer)
17146 || g_peer->gtsm_hops != peer->gtsm_hops) {
17147 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17148 addr, peer->gtsm_hops);
17149 }
17150 }
17151
17152 /* disable-connected-check */
17153 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17154 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17155
17156 /* enforce-first-as */
17157 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17158 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17159
17160 /* update-source */
17161 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17162 if (peer->update_source)
17163 vty_out(vty, " neighbor %s update-source %s\n", addr,
17164 sockunion2str(peer->update_source, buf,
17165 SU_ADDRSTRLEN));
17166 else if (peer->update_if)
17167 vty_out(vty, " neighbor %s update-source %s\n", addr,
17168 peer->update_if);
17169 }
17170
17171 /* advertisement-interval */
17172 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17173 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17174 peer->routeadv);
17175
17176 /* timers */
17177 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17178 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17179 peer->keepalive, peer->holdtime);
17180
17181 /* timers connect */
17182 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17183 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17184 peer->connect);
5d5393b9
DL
17185 /* need special-case handling for changed default values due to
17186 * config profile / version (because there is no "timers bgp connect"
17187 * command, we need to save this per-peer :/)
17188 */
17189 else if (!peer_group_active(peer) && !peer->connect &&
17190 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17191 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17192 peer->bgp->default_connect_retry);
dd65f45e 17193
d43114f3
DS
17194 /* timers delayopen */
17195 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17196 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17197 peer->delayopen);
17198 /* Save config even though flag is not set if default values have been
17199 * changed
17200 */
17201 else if (!peer_group_active(peer) && !peer->delayopen
17202 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17203 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17204 peer->bgp->default_delayopen);
17205
dd65f45e
DL
17206 /* capability dynamic */
17207 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17208 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17209
17210 /* capability extended-nexthop */
17211 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17212 if (!peer->conf_if) {
17213 if (CHECK_FLAG(peer->flags_invert,
17214 PEER_FLAG_CAPABILITY_ENHE))
17215 vty_out(vty,
17216 " no neighbor %s capability extended-nexthop\n",
17217 addr);
17218 else
17219 vty_out(vty,
17220 " neighbor %s capability extended-nexthop\n",
17221 addr);
17222 }
17223 }
17224
17225 /* dont-capability-negotiation */
17226 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17227 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17228
17229 /* override-capability */
17230 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17231 vty_out(vty, " neighbor %s override-capability\n", addr);
17232
17233 /* strict-capability-match */
17234 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17235 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17236
17237 /* Sender side AS path loop detection. */
17238 if (peer->as_path_loop_detection)
17239 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17240 addr);
cfd47646 17241
17242 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17243 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17244
17245 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17246 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17247 vty_out(vty,
17248 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17249 } else if (CHECK_FLAG(
17250 peer->peer_gr_new_status_flag,
17251 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17252 vty_out(vty,
17253 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17254 } else if (
17255 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17256 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17257 && !(CHECK_FLAG(
17258 peer->peer_gr_new_status_flag,
17259 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17260 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17261 addr);
cfd47646 17262 }
17263 }
dd65f45e
DL
17264}
17265
17266/* BGP peer configuration display function. */
17267static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17268 struct peer *peer, afi_t afi, safi_t safi)
17269{
17270 struct peer *g_peer = NULL;
17271 char *addr;
17272 bool flag_scomm, flag_secomm, flag_slcomm;
17273
17274 /* Skip dynamic neighbors. */
17275 if (peer_dynamic_neighbor(peer))
17276 return;
17277
17278 if (peer->conf_if)
17279 addr = peer->conf_if;
17280 else
17281 addr = peer->host;
17282
17283 /************************************
17284 ****** Per AF to the neighbor ******
17285 ************************************/
17286 if (peer_group_active(peer)) {
17287 g_peer = peer->group->conf;
17288
17289 /* If the peer-group is active but peer is not, print a 'no
17290 * activate' */
17291 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17292 vty_out(vty, " no neighbor %s activate\n", addr);
17293 }
17294
17295 /* If the peer-group is not active but peer is, print an
17296 'activate' */
17297 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17298 vty_out(vty, " neighbor %s activate\n", addr);
17299 }
17300 } else {
17301 if (peer->afc[afi][safi]) {
e84c59af
DA
17302 if ((afi == AFI_IP || afi == AFI_IP6)
17303 && safi == SAFI_UNICAST) {
17304 if (afi == AFI_IP
17305 && CHECK_FLAG(bgp->flags,
17306 BGP_FLAG_NO_DEFAULT_IPV4)) {
17307 vty_out(vty, " neighbor %s activate\n",
17308 addr);
17309 } else if (afi == AFI_IP6
17310 && !CHECK_FLAG(
17311 bgp->flags,
17312 BGP_FLAG_DEFAULT_IPV6)) {
dd65f45e
DL
17313 vty_out(vty, " neighbor %s activate\n",
17314 addr);
17315 }
e84c59af 17316 } else {
dd65f45e 17317 vty_out(vty, " neighbor %s activate\n", addr);
e84c59af 17318 }
dd65f45e 17319 } else {
e84c59af
DA
17320 if ((afi == AFI_IP || afi == AFI_IP6)
17321 && safi == SAFI_UNICAST) {
17322 if (afi == AFI_IP
17323 && !CHECK_FLAG(bgp->flags,
17324 BGP_FLAG_NO_DEFAULT_IPV4)) {
17325 vty_out(vty,
17326 " no neighbor %s activate\n",
17327 addr);
17328 } else if (afi == AFI_IP6
17329 && CHECK_FLAG(
17330 bgp->flags,
17331 BGP_FLAG_DEFAULT_IPV6)) {
dd65f45e
DL
17332 vty_out(vty,
17333 " no neighbor %s activate\n",
17334 addr);
17335 }
17336 }
17337 }
17338 }
17339
17340 /* addpath TX knobs */
17341 if (peergroup_af_addpath_check(peer, afi, safi)) {
17342 switch (peer->addpath_type[afi][safi]) {
17343 case BGP_ADDPATH_ALL:
17344 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17345 addr);
17346 break;
17347 case BGP_ADDPATH_BEST_PER_AS:
17348 vty_out(vty,
17349 " neighbor %s addpath-tx-bestpath-per-AS\n",
17350 addr);
17351 break;
17352 case BGP_ADDPATH_MAX:
17353 case BGP_ADDPATH_NONE:
17354 break;
17355 }
17356 }
17357
17358 /* ORF capability. */
17359 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17360 || peergroup_af_flag_check(peer, afi, safi,
17361 PEER_FLAG_ORF_PREFIX_RM)) {
17362 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17363
17364 if (peergroup_af_flag_check(peer, afi, safi,
17365 PEER_FLAG_ORF_PREFIX_SM)
17366 && peergroup_af_flag_check(peer, afi, safi,
17367 PEER_FLAG_ORF_PREFIX_RM))
17368 vty_out(vty, " both");
17369 else if (peergroup_af_flag_check(peer, afi, safi,
17370 PEER_FLAG_ORF_PREFIX_SM))
17371 vty_out(vty, " send");
17372 else
17373 vty_out(vty, " receive");
17374 vty_out(vty, "\n");
17375 }
17376
dd65f45e
DL
17377 /* Route reflector client. */
17378 if (peergroup_af_flag_check(peer, afi, safi,
17379 PEER_FLAG_REFLECTOR_CLIENT)) {
17380 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17381 }
17382
17383 /* next-hop-self force */
17384 if (peergroup_af_flag_check(peer, afi, safi,
17385 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17386 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17387 }
17388
17389 /* next-hop-self */
17390 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17391 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17392 }
17393
17394 /* remove-private-AS */
17395 if (peergroup_af_flag_check(peer, afi, safi,
17396 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17397 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17398 addr);
17399 }
17400
17401 else if (peergroup_af_flag_check(peer, afi, safi,
17402 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17403 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17404 addr);
17405 }
17406
17407 else if (peergroup_af_flag_check(peer, afi, safi,
17408 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17409 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17410 }
17411
17412 else if (peergroup_af_flag_check(peer, afi, safi,
17413 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17414 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17415 }
17416
17417 /* as-override */
17418 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17419 vty_out(vty, " neighbor %s as-override\n", addr);
17420 }
17421
17422 /* send-community print. */
17423 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17424 PEER_FLAG_SEND_COMMUNITY);
17425 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17426 PEER_FLAG_SEND_EXT_COMMUNITY);
17427 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17428 PEER_FLAG_SEND_LARGE_COMMUNITY);
17429
17430 if (flag_scomm && flag_secomm && flag_slcomm) {
17431 vty_out(vty, " no neighbor %s send-community all\n", addr);
17432 } else {
17433 if (flag_scomm)
17434 vty_out(vty, " no neighbor %s send-community\n", addr);
17435 if (flag_secomm)
17436 vty_out(vty,
17437 " no neighbor %s send-community extended\n",
17438 addr);
17439
17440 if (flag_slcomm)
17441 vty_out(vty, " no neighbor %s send-community large\n",
17442 addr);
17443 }
17444
17445 /* Default information */
17446 if (peergroup_af_flag_check(peer, afi, safi,
17447 PEER_FLAG_DEFAULT_ORIGINATE)) {
17448 vty_out(vty, " neighbor %s default-originate", addr);
17449
17450 if (peer->default_rmap[afi][safi].name)
17451 vty_out(vty, " route-map %s",
17452 peer->default_rmap[afi][safi].name);
17453
17454 vty_out(vty, "\n");
17455 }
17456
17457 /* Soft reconfiguration inbound. */
17458 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17459 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17460 addr);
17461 }
17462
17463 /* maximum-prefix. */
17464 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17465 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17466 peer->pmax[afi][safi]);
17467
17468 if (peer->pmax_threshold[afi][safi]
17469 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17470 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17471 if (peer_af_flag_check(peer, afi, safi,
17472 PEER_FLAG_MAX_PREFIX_WARNING))
17473 vty_out(vty, " warning-only");
17474 if (peer->pmax_restart[afi][safi])
17475 vty_out(vty, " restart %u",
17476 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17477 if (peer_af_flag_check(peer, afi, safi,
17478 PEER_FLAG_MAX_PREFIX_FORCE))
17479 vty_out(vty, " force");
dd65f45e
DL
17480
17481 vty_out(vty, "\n");
17482 }
17483
fde246e8
DA
17484 /* maximum-prefix-out */
17485 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17486 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17487 addr, peer->pmax_out[afi][safi]);
17488
dd65f45e
DL
17489 /* Route server client. */
17490 if (peergroup_af_flag_check(peer, afi, safi,
17491 PEER_FLAG_RSERVER_CLIENT)) {
17492 vty_out(vty, " neighbor %s route-server-client\n", addr);
17493 }
17494
17495 /* Nexthop-local unchanged. */
17496 if (peergroup_af_flag_check(peer, afi, safi,
17497 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17498 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17499 }
17500
17501 /* allowas-in <1-10> */
17502 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17503 if (peer_af_flag_check(peer, afi, safi,
17504 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17505 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17506 } else if (peer->allowas_in[afi][safi] == 3) {
17507 vty_out(vty, " neighbor %s allowas-in\n", addr);
17508 } else {
17509 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17510 peer->allowas_in[afi][safi]);
17511 }
17512 }
17513
17514 /* weight */
17515 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17516 vty_out(vty, " neighbor %s weight %lu\n", addr,
17517 peer->weight[afi][safi]);
17518
17519 /* Filter. */
17520 bgp_config_write_filter(vty, peer, afi, safi);
17521
17522 /* atribute-unchanged. */
17523 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17524 || (safi != SAFI_EVPN
17525 && peer_af_flag_check(peer, afi, safi,
17526 PEER_FLAG_NEXTHOP_UNCHANGED))
17527 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17528
17529 if (!peer_group_active(peer)
17530 || peergroup_af_flag_check(peer, afi, safi,
17531 PEER_FLAG_AS_PATH_UNCHANGED)
17532 || peergroup_af_flag_check(peer, afi, safi,
17533 PEER_FLAG_NEXTHOP_UNCHANGED)
17534 || peergroup_af_flag_check(peer, afi, safi,
17535 PEER_FLAG_MED_UNCHANGED)) {
17536
17537 vty_out(vty,
17538 " neighbor %s attribute-unchanged%s%s%s\n",
17539 addr,
17540 peer_af_flag_check(peer, afi, safi,
17541 PEER_FLAG_AS_PATH_UNCHANGED)
17542 ? " as-path"
17543 : "",
17544 peer_af_flag_check(peer, afi, safi,
17545 PEER_FLAG_NEXTHOP_UNCHANGED)
17546 ? " next-hop"
17547 : "",
17548 peer_af_flag_check(peer, afi, safi,
17549 PEER_FLAG_MED_UNCHANGED)
17550 ? " med"
17551 : "");
17552 }
17553 }
39d8dd2d
DS
17554
17555 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_CONFIG_DAMPENING))
17556 bgp_config_write_peer_damp(vty, peer, afi, safi);
dd65f45e
DL
17557}
17558
17559/* Address family based peer configuration display. */
17560static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17561 safi_t safi)
17562{
17563 struct peer *peer;
17564 struct peer_group *group;
17565 struct listnode *node, *nnode;
17566
17567
17568 vty_frame(vty, " !\n address-family ");
17569 if (afi == AFI_IP) {
17570 if (safi == SAFI_UNICAST)
17571 vty_frame(vty, "ipv4 unicast");
17572 else if (safi == SAFI_LABELED_UNICAST)
17573 vty_frame(vty, "ipv4 labeled-unicast");
17574 else if (safi == SAFI_MULTICAST)
17575 vty_frame(vty, "ipv4 multicast");
17576 else if (safi == SAFI_MPLS_VPN)
17577 vty_frame(vty, "ipv4 vpn");
17578 else if (safi == SAFI_ENCAP)
17579 vty_frame(vty, "ipv4 encap");
17580 else if (safi == SAFI_FLOWSPEC)
17581 vty_frame(vty, "ipv4 flowspec");
17582 } else if (afi == AFI_IP6) {
17583 if (safi == SAFI_UNICAST)
17584 vty_frame(vty, "ipv6 unicast");
17585 else if (safi == SAFI_LABELED_UNICAST)
17586 vty_frame(vty, "ipv6 labeled-unicast");
17587 else if (safi == SAFI_MULTICAST)
17588 vty_frame(vty, "ipv6 multicast");
17589 else if (safi == SAFI_MPLS_VPN)
17590 vty_frame(vty, "ipv6 vpn");
17591 else if (safi == SAFI_ENCAP)
17592 vty_frame(vty, "ipv6 encap");
17593 else if (safi == SAFI_FLOWSPEC)
17594 vty_frame(vty, "ipv6 flowspec");
17595 } else if (afi == AFI_L2VPN) {
17596 if (safi == SAFI_EVPN)
17597 vty_frame(vty, "l2vpn evpn");
17598 }
17599 vty_frame(vty, "\n");
17600
17601 bgp_config_write_distance(vty, bgp, afi, safi);
17602
17603 bgp_config_write_network(vty, bgp, afi, safi);
17604
17605 bgp_config_write_redistribute(vty, bgp, afi, safi);
17606
8a4e7fe6
DA
17607 /* BGP flag dampening. */
17608 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
0221327c 17609 bgp_config_write_damp(vty, bgp, afi, safi);
8a4e7fe6 17610
dd65f45e
DL
17611 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17612 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17613
17614 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17615 /* Do not display doppelganger peers */
17616 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17617 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17618 }
17619
17620 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17621 bgp_config_write_table_map(vty, bgp, afi, safi);
17622
17623 if (safi == SAFI_EVPN)
17624 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17625
17626 if (safi == SAFI_FLOWSPEC)
17627 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17628
17629 if (safi == SAFI_UNICAST) {
17630 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17631 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17632 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17633
17634 vty_out(vty, " export vpn\n");
17635 }
17636 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17637 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17638
17639 vty_out(vty, " import vpn\n");
17640 }
17641 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17642 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17643 char *name;
17644
17645 for (ALL_LIST_ELEMENTS_RO(
17646 bgp->vpn_policy[afi].import_vrf, node,
17647 name))
17648 vty_out(vty, " import vrf %s\n", name);
17649 }
17650 }
17651
17652 vty_endframe(vty, " exit-address-family\n");
17653}
17654
17655int bgp_config_write(struct vty *vty)
17656{
17657 struct bgp *bgp;
17658 struct peer_group *group;
17659 struct peer *peer;
17660 struct listnode *node, *nnode;
17661 struct listnode *mnode, *mnnode;
17662
17663 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17664 vty_out(vty, "bgp route-map delay-timer %u\n",
17665 bm->rmap_update_timer);
17666
d70583f7
D
17667 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17668 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17669 if (bm->v_update_delay != bm->v_establish_wait)
17670 vty_out(vty, " %d", bm->v_establish_wait);
17671 vty_out(vty, "\n");
17672 }
17673
9acb67cb
DS
17674 if (bm->wait_for_fib)
17675 vty_out(vty, "bgp suppress-fib-pending\n");
17676
05bd726c 17677 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17678 vty_out(vty, "bgp graceful-shutdown\n");
17679
c163f297
DS
17680 /* No-RIB (Zebra) option flag configuration */
17681 if (bgp_option_check(BGP_OPT_NO_FIB))
17682 vty_out(vty, "bgp no-rib\n");
17683
ec0acb80 17684 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
17685 vty_out(vty, "no bgp send-extra-data zebra\n");
17686
dd65f45e
DL
17687 /* BGP configuration. */
17688 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17689
17690 /* skip all auto created vrf as they dont have user config */
17691 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17692 continue;
17693
17694 /* Router bgp ASN */
17695 vty_out(vty, "router bgp %u", bgp->as);
17696
17697 if (bgp->name)
17698 vty_out(vty, " %s %s",
17699 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17700 ? "view" : "vrf", bgp->name);
17701 vty_out(vty, "\n");
17702
17703 /* BGP fast-external-failover. */
17704 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17705 vty_out(vty, " no bgp fast-external-failover\n");
17706
17707 /* BGP router ID. */
3a6290bd 17708 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17709 vty_out(vty, " bgp router-id %pI4\n",
17710 &bgp->router_id_static);
dd65f45e 17711
c208c586
S
17712 /* Suppress fib pending */
17713 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17714 vty_out(vty, " bgp suppress-fib-pending\n");
17715
dd65f45e 17716 /* BGP log-neighbor-changes. */
892fedb6 17717 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17718 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17719 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17720 CHECK_FLAG(bgp->flags,
17721 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17722 ? ""
17723 : "no ");
17724
17725 /* BGP configuration. */
892fedb6 17726 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17727 vty_out(vty, " bgp always-compare-med\n");
17728
17729 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17730 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17731 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17732 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17733 CHECK_FLAG(bgp->flags,
17734 BGP_FLAG_EBGP_REQUIRES_POLICY)
17735 ? ""
17736 : "no ");
dd65f45e
DL
17737
17738 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17739 if (bgp->reject_as_sets)
dd65f45e
DL
17740 vty_out(vty, " bgp reject-as-sets\n");
17741
2adac256
DA
17742 /* Suppress duplicate updates if the route actually not changed
17743 */
17744 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17745 != SAVE_BGP_SUPPRESS_DUPLICATES)
17746 vty_out(vty, " %sbgp suppress-duplicates\n",
17747 CHECK_FLAG(bgp->flags,
17748 BGP_FLAG_SUPPRESS_DUPLICATES)
17749 ? ""
17750 : "no ");
17751
dd65f45e 17752 /* BGP default ipv4-unicast. */
892fedb6 17753 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
17754 vty_out(vty, " no bgp default ipv4-unicast\n");
17755
e84c59af
DA
17756 /* BGP default ipv6-unicast. */
17757 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6))
17758 vty_out(vty, " bgp default ipv6-unicast\n");
17759
dd65f45e
DL
17760 /* BGP default local-preference. */
17761 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17762 vty_out(vty, " bgp default local-preference %u\n",
17763 bgp->default_local_pref);
17764
17765 /* BGP default show-hostname */
892fedb6 17766 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17767 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17768 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17769 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17770 ? ""
17771 : "no ");
17772
aef999a2
DA
17773 /* BGP default show-nexthop-hostname */
17774 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17775 != SAVE_BGP_SHOW_HOSTNAME)
17776 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17777 CHECK_FLAG(bgp->flags,
17778 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17779 ? ""
17780 : "no ");
17781
dd65f45e
DL
17782 /* BGP default subgroup-pkt-queue-max. */
17783 if (bgp->default_subgroup_pkt_queue_max
17784 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17785 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17786 bgp->default_subgroup_pkt_queue_max);
17787
17788 /* BGP client-to-client reflection. */
892fedb6 17789 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17790 vty_out(vty, " no bgp client-to-client reflection\n");
17791
17792 /* BGP cluster ID. */
17793 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17794 vty_out(vty, " bgp cluster-id %pI4\n",
17795 &bgp->cluster_id);
dd65f45e
DL
17796
17797 /* Disable ebgp connected nexthop check */
892fedb6 17798 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17799 vty_out(vty,
17800 " bgp disable-ebgp-connected-route-check\n");
17801
17802 /* Confederation identifier*/
17803 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17804 vty_out(vty, " bgp confederation identifier %u\n",
17805 bgp->confed_id);
17806
17807 /* Confederation peer */
17808 if (bgp->confed_peers_cnt > 0) {
17809 int i;
17810
17811 vty_out(vty, " bgp confederation peers");
17812
17813 for (i = 0; i < bgp->confed_peers_cnt; i++)
17814 vty_out(vty, " %u", bgp->confed_peers[i]);
17815
17816 vty_out(vty, "\n");
17817 }
17818
17819 /* BGP deterministic-med. */
892fedb6 17820 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17821 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17822 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17823 CHECK_FLAG(bgp->flags,
17824 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17825 ? ""
17826 : "no ");
17827
17828 /* BGP update-delay. */
17829 bgp_config_write_update_delay(vty, bgp);
17830
17831 if (bgp->v_maxmed_onstartup
17832 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17833 vty_out(vty, " bgp max-med on-startup %u",
17834 bgp->v_maxmed_onstartup);
17835 if (bgp->maxmed_onstartup_value
17836 != BGP_MAXMED_VALUE_DEFAULT)
17837 vty_out(vty, " %u",
17838 bgp->maxmed_onstartup_value);
17839 vty_out(vty, "\n");
17840 }
17841 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17842 vty_out(vty, " bgp max-med administrative");
17843 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17844 vty_out(vty, " %u", bgp->maxmed_admin_value);
17845 vty_out(vty, "\n");
17846 }
17847
17848 /* write quanta */
17849 bgp_config_write_wpkt_quanta(vty, bgp);
17850 /* read quanta */
17851 bgp_config_write_rpkt_quanta(vty, bgp);
17852
17853 /* coalesce time */
17854 bgp_config_write_coalesce_time(vty, bgp);
17855
05bd726c 17856 /* BGP per-instance graceful-shutdown */
17857 /* BGP-wide settings and per-instance settings are mutually
17858 * exclusive.
17859 */
17860 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17861 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17862 vty_out(vty, " bgp graceful-shutdown\n");
17863
dd65f45e
DL
17864 /* BGP graceful-restart. */
17865 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17866 vty_out(vty,
17867 " bgp graceful-restart stalepath-time %u\n",
17868 bgp->stalepath_time);
cfd47646 17869
dd65f45e
DL
17870 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17871 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17872 bgp->restart_time);
cfd47646 17873
17874 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17875 vty_out(vty,
17876 " bgp graceful-restart select-defer-time %u\n",
17877 bgp->select_defer_time);
17878
17879 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17880 vty_out(vty, " bgp graceful-restart\n");
17881
cfd47646 17882 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17883 vty_out(vty, " bgp graceful-restart-disable\n");
17884
dd65f45e 17885 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17886 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17887 vty_out(vty,
17888 " bgp graceful-restart preserve-fw-state\n");
17889
dc95985f 17890 /* Stale timer for RIB */
17891 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17892 vty_out(vty,
17893 " bgp graceful-restart rib-stale-time %u\n",
17894 bgp->rib_stale_time);
17895
dd65f45e 17896 /* BGP bestpath method. */
892fedb6 17897 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17898 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17899 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17900 vty_out(vty, " bgp bestpath as-path confed\n");
17901
892fedb6
DA
17902 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17903 if (CHECK_FLAG(bgp->flags,
17904 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17905 vty_out(vty,
17906 " bgp bestpath as-path multipath-relax as-set\n");
17907 } else {
17908 vty_out(vty,
17909 " bgp bestpath as-path multipath-relax\n");
17910 }
17911 }
17912
892fedb6 17913 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17914 vty_out(vty,
17915 " bgp route-reflector allow-outbound-policy\n");
17916 }
892fedb6 17917 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17918 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17919 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17920 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17921 vty_out(vty, " bgp bestpath med");
892fedb6 17922 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17923 vty_out(vty, " confed");
892fedb6
DA
17924 if (CHECK_FLAG(bgp->flags,
17925 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17926 vty_out(vty, " missing-as-worst");
17927 vty_out(vty, "\n");
17928 }
17929
ee88563a
JM
17930 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17931 vty_out(vty,
17932 " bgp bestpath peer-type multipath-relax\n");
17933
f7e1c681 17934 /* Link bandwidth handling. */
17935 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17936 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17937 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17938 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17939 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17940 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17941
dd65f45e 17942 /* BGP network import check. */
892fedb6 17943 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17944 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17945 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17946 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17947 ? ""
17948 : "no ");
17949
17950 /* BGP timers configuration. */
5d5393b9 17951 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17952 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17953 vty_out(vty, " timers bgp %u %u\n",
17954 bgp->default_keepalive, bgp->default_holdtime);
17955
17956 /* peer-group */
17957 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17958 bgp_config_write_peer_global(vty, bgp, group->conf);
17959 }
17960
17961 /* Normal neighbor configuration. */
17962 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17963 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17964 bgp_config_write_peer_global(vty, bgp, peer);
17965 }
17966
17967 /* listen range and limit for dynamic BGP neighbors */
17968 bgp_config_write_listen(vty, bgp);
17969
17970 /*
17971 * BGP default autoshutdown neighbors
17972 *
17973 * This must be placed after any peer and peer-group
17974 * configuration, to avoid setting all peers to shutdown after
17975 * a daemon restart, which is undesired behavior. (see #2286)
17976 */
17977 if (bgp->autoshutdown)
17978 vty_out(vty, " bgp default shutdown\n");
17979
9cf59432
DS
17980 /* BGP instance administrative shutdown */
17981 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17982 vty_out(vty, " bgp shutdown\n");
17983
a0281b2e
HS
17984 if (bgp->srv6_enabled) {
17985 vty_frame(vty, " !\n segment-routing srv6\n");
17986 if (bgp->srv6_locator_name)
17987 vty_out(vty, " locator %s\n",
17988 bgp->srv6_locator_name);
17989 }
17990
17991
dd65f45e
DL
17992 /* IPv4 unicast configuration. */
17993 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17994
17995 /* IPv4 multicast configuration. */
17996 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17997
17998 /* IPv4 labeled-unicast configuration. */
17999 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
18000
18001 /* IPv4 VPN configuration. */
18002 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
18003
18004 /* ENCAPv4 configuration. */
18005 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
18006
18007 /* FLOWSPEC v4 configuration. */
18008 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
18009
18010 /* IPv6 unicast configuration. */
18011 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
18012
18013 /* IPv6 multicast configuration. */
18014 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
18015
18016 /* IPv6 labeled-unicast configuration. */
18017 bgp_config_write_family(vty, bgp, AFI_IP6,
18018 SAFI_LABELED_UNICAST);
18019
18020 /* IPv6 VPN configuration. */
18021 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
18022
18023 /* ENCAPv6 configuration. */
18024 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
18025
18026 /* FLOWSPEC v6 configuration. */
18027 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
18028
18029 /* EVPN configuration. */
18030 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
18031
18032 hook_call(bgp_inst_config_write, bgp, vty);
18033
49e5a4a0 18034#ifdef ENABLE_BGP_VNC
dd65f45e
DL
18035 bgp_rfapi_cfg_write(vty, bgp);
18036#endif
18037
18038 vty_out(vty, "!\n");
18039 }
18040 return 0;
18041}
18042
ddb5b488 18043
718e3744 18044/* BGP node structure. */
d62a17ae 18045static struct cmd_node bgp_node = {
f4b8291f 18046 .name = "bgp",
62b346ee 18047 .node = BGP_NODE,
24389580 18048 .parent_node = CONFIG_NODE,
62b346ee 18049 .prompt = "%s(config-router)# ",
612c2c15 18050 .config_write = bgp_config_write,
718e3744 18051};
18052
d62a17ae 18053static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 18054 .name = "bgp ipv4 unicast",
62b346ee 18055 .node = BGP_IPV4_NODE,
24389580 18056 .parent_node = BGP_NODE,
62b346ee 18057 .prompt = "%s(config-router-af)# ",
718e3744 18058};
18059
d62a17ae 18060static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 18061 .name = "bgp ipv4 multicast",
62b346ee 18062 .node = BGP_IPV4M_NODE,
24389580 18063 .parent_node = BGP_NODE,
62b346ee 18064 .prompt = "%s(config-router-af)# ",
718e3744 18065};
18066
d62a17ae 18067static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 18068 .name = "bgp ipv4 labeled unicast",
62b346ee 18069 .node = BGP_IPV4L_NODE,
24389580 18070 .parent_node = BGP_NODE,
62b346ee 18071 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
18072};
18073
d62a17ae 18074static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 18075 .name = "bgp ipv6",
62b346ee 18076 .node = BGP_IPV6_NODE,
24389580 18077 .parent_node = BGP_NODE,
62b346ee 18078 .prompt = "%s(config-router-af)# ",
718e3744 18079};
18080
d62a17ae 18081static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 18082 .name = "bgp ipv6 multicast",
62b346ee 18083 .node = BGP_IPV6M_NODE,
24389580 18084 .parent_node = BGP_NODE,
62b346ee 18085 .prompt = "%s(config-router-af)# ",
25ffbdc1 18086};
18087
d62a17ae 18088static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 18089 .name = "bgp ipv6 labeled unicast",
62b346ee 18090 .node = BGP_IPV6L_NODE,
24389580 18091 .parent_node = BGP_NODE,
62b346ee 18092 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
18093};
18094
62b346ee 18095static struct cmd_node bgp_vpnv4_node = {
f4b8291f 18096 .name = "bgp vpnv4",
62b346ee 18097 .node = BGP_VPNV4_NODE,
24389580 18098 .parent_node = BGP_NODE,
62b346ee 18099 .prompt = "%s(config-router-af)# ",
62b346ee 18100};
6b0655a2 18101
62b346ee 18102static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18103 .name = "bgp vpnv6",
62b346ee 18104 .node = BGP_VPNV6_NODE,
24389580 18105 .parent_node = BGP_NODE,
62b346ee 18106 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 18107};
8ecd3266 18108
62b346ee 18109static struct cmd_node bgp_evpn_node = {
f4b8291f 18110 .name = "bgp evpn",
62b346ee 18111 .node = BGP_EVPN_NODE,
24389580 18112 .parent_node = BGP_NODE,
62b346ee 18113 .prompt = "%s(config-router-evpn)# ",
62b346ee 18114};
4e0b7b6d 18115
62b346ee 18116static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18117 .name = "bgp evpn vni",
62b346ee 18118 .node = BGP_EVPN_VNI_NODE,
24389580 18119 .parent_node = BGP_EVPN_NODE,
62b346ee 18120 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18121};
90e60aa7 18122
62b346ee 18123static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18124 .name = "bgp ipv4 flowspec",
62b346ee 18125 .node = BGP_FLOWSPECV4_NODE,
24389580 18126 .parent_node = BGP_NODE,
62b346ee 18127 .prompt = "%s(config-router-af)# ",
62b346ee 18128};
7c40bf39 18129
62b346ee 18130static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18131 .name = "bgp ipv6 flowspec",
62b346ee 18132 .node = BGP_FLOWSPECV6_NODE,
24389580 18133 .parent_node = BGP_NODE,
62b346ee 18134 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 18135};
7c40bf39 18136
bfaab44d
HS
18137static struct cmd_node bgp_srv6_node = {
18138 .name = "bgp srv6",
18139 .node = BGP_SRV6_NODE,
18140 .parent_node = BGP_NODE,
18141 .prompt = "%s(config-router-srv6)# ",
18142};
18143
d62a17ae 18144static void community_list_vty(void);
1f8ae70b 18145
d62a17ae 18146static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 18147{
d62a17ae 18148 struct bgp *bgp;
18149 struct peer *peer;
d62a17ae 18150 struct listnode *lnbgp, *lnpeer;
b8a815e5 18151
d62a17ae 18152 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18153 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18154 /* only provide suggestions on the appropriate input
18155 * token type,
18156 * they'll otherwise show up multiple times */
18157 enum cmd_token_type match_type;
18158 char *name = peer->host;
d48ed3e0 18159
d62a17ae 18160 if (peer->conf_if) {
18161 match_type = VARIABLE_TKN;
18162 name = peer->conf_if;
18163 } else if (strchr(peer->host, ':'))
18164 match_type = IPV6_TKN;
18165 else
18166 match_type = IPV4_TKN;
d48ed3e0 18167
d62a17ae 18168 if (token->type != match_type)
18169 continue;
d48ed3e0 18170
d62a17ae 18171 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18172 }
d62a17ae 18173 }
b8a815e5
DL
18174}
18175
18176static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18177 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18178 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18179 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18180 {.completions = NULL}};
18181
47a306a0
DS
18182static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18183{
18184 struct bgp *bgp;
18185 struct peer_group *group;
18186 struct listnode *lnbgp, *lnpeer;
18187
18188 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18189 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18190 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
18191 group->name));
18192 }
18193}
18194
18195static const struct cmd_variable_handler bgp_var_peergroup[] = {
18196 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18197 {.completions = NULL} };
18198
d62a17ae 18199void bgp_vty_init(void)
18200{
18201 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 18202 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 18203
18204 /* Install bgp top node. */
612c2c15
DL
18205 install_node(&bgp_node);
18206 install_node(&bgp_ipv4_unicast_node);
18207 install_node(&bgp_ipv4_multicast_node);
18208 install_node(&bgp_ipv4_labeled_unicast_node);
18209 install_node(&bgp_ipv6_unicast_node);
18210 install_node(&bgp_ipv6_multicast_node);
18211 install_node(&bgp_ipv6_labeled_unicast_node);
18212 install_node(&bgp_vpnv4_node);
18213 install_node(&bgp_vpnv6_node);
18214 install_node(&bgp_evpn_node);
18215 install_node(&bgp_evpn_vni_node);
18216 install_node(&bgp_flowspecv4_node);
18217 install_node(&bgp_flowspecv6_node);
bfaab44d 18218 install_node(&bgp_srv6_node);
d62a17ae 18219
18220 /* Install default VTY commands to new nodes. */
18221 install_default(BGP_NODE);
18222 install_default(BGP_IPV4_NODE);
18223 install_default(BGP_IPV4M_NODE);
18224 install_default(BGP_IPV4L_NODE);
18225 install_default(BGP_IPV6_NODE);
18226 install_default(BGP_IPV6M_NODE);
18227 install_default(BGP_IPV6L_NODE);
18228 install_default(BGP_VPNV4_NODE);
18229 install_default(BGP_VPNV6_NODE);
7c40bf39 18230 install_default(BGP_FLOWSPECV4_NODE);
18231 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18232 install_default(BGP_EVPN_NODE);
18233 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 18234 install_default(BGP_SRV6_NODE);
d62a17ae 18235
8029b216
AK
18236 /* "bgp local-mac" hidden commands. */
18237 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18238 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18239
9acb67cb
DS
18240 /* "bgp suppress-fib-pending" global */
18241 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18242
d62a17ae 18243 /* bgp route-map delay-timer commands. */
18244 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18245 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18246
d70583f7
D
18247 /* global bgp update-delay command */
18248 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18249 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18250
05bd726c 18251 /* global bgp graceful-shutdown command */
18252 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18253 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18254
d62a17ae 18255 /* Dummy commands (Currently not supported) */
18256 install_element(BGP_NODE, &no_synchronization_cmd);
18257 install_element(BGP_NODE, &no_auto_summary_cmd);
18258
18259 /* "router bgp" commands. */
18260 install_element(CONFIG_NODE, &router_bgp_cmd);
18261
18262 /* "no router bgp" commands. */
18263 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18264
18265 /* "bgp router-id" commands. */
18266 install_element(BGP_NODE, &bgp_router_id_cmd);
18267 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18268
c208c586
S
18269 /* "bgp suppress-fib-pending" command */
18270 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18271
d62a17ae 18272 /* "bgp cluster-id" commands. */
18273 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18274 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18275
c163f297
DS
18276 /* "bgp no-rib" commands. */
18277 install_element(CONFIG_NODE, &bgp_norib_cmd);
18278 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18279
e46723a5
DS
18280 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18281
d62a17ae 18282 /* "bgp confederation" commands. */
18283 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18284 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18285
18286 /* "bgp confederation peers" commands. */
18287 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18288 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18289
18290 /* bgp max-med command */
18291 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18292 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18293 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18294 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18295 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18296
18297 /* bgp disable-ebgp-connected-nh-check */
18298 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18299 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18300
18301 /* bgp update-delay command */
18302 install_element(BGP_NODE, &bgp_update_delay_cmd);
18303 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 18304
18305 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 18306 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 18307
18308 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18309 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18310
18311 /* "maximum-paths" commands. */
18312 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18313 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18314 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18315 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18316 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18317 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18318 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18319 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18320 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18321 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18322 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18323 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18324 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18325 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18326 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18327
39edabac
PG
18328 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18329 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18330 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18331 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18332 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 18333 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18334 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18335 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18336 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18337 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18338
18339 /* "timers bgp" commands. */
18340 install_element(BGP_NODE, &bgp_timers_cmd);
18341 install_element(BGP_NODE, &no_bgp_timers_cmd);
18342
18343 /* route-map delay-timer commands - per instance for backwards compat.
18344 */
18345 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18346 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18347
18348 /* "bgp client-to-client reflection" commands */
18349 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18350 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18351
18352 /* "bgp always-compare-med" commands */
18353 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18354 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18355
9dac9fc8
DA
18356 /* bgp ebgp-requires-policy */
18357 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18358 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18359
2adac256
DA
18360 /* bgp suppress-duplicates */
18361 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18362 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18363
fb29348a
DA
18364 /* bgp reject-as-sets */
18365 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18366 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18367
d62a17ae 18368 /* "bgp deterministic-med" commands */
18369 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18370 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18371
055679e9 18372 /* "bgp graceful-restart" command */
36235319
QY
18373 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18374 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 18375
18376 /* "bgp graceful-restart-disable" command */
36235319
QY
18377 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18378 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 18379
18380 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
18381 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18382 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 18383
18384 /* "neighbor a:b:c:d graceful-restart-disable" command */
18385 install_element(BGP_NODE,
18386 &bgp_neighbor_graceful_restart_disable_set_cmd);
18387 install_element(BGP_NODE,
18388 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18389
18390 /* "neighbor a:b:c:d graceful-restart-helper" command */
18391 install_element(BGP_NODE,
18392 &bgp_neighbor_graceful_restart_helper_set_cmd);
18393 install_element(BGP_NODE,
18394 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18395
d62a17ae 18396 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18397 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18398 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18399 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 18400 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 18401 install_element(BGP_NODE,
18402 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 18403 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18404 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18405
d6e3c15b 18406 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18407 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 18408 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18409 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 18410
7f323236
DW
18411 /* "bgp graceful-shutdown" commands */
18412 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18413 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18414
d62a17ae 18415 /* "bgp fast-external-failover" commands */
18416 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18417 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18418
d62a17ae 18419 /* "bgp bestpath compare-routerid" commands */
18420 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18421 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18422
18423 /* "bgp bestpath as-path ignore" commands */
18424 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18425 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18426
18427 /* "bgp bestpath as-path confed" commands */
18428 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18429 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18430
18431 /* "bgp bestpath as-path multipath-relax" commands */
18432 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18433 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18434
ee88563a
JM
18435 /* "bgp bestpath peer-type multipath-relax" commands */
18436 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18437 install_element(BGP_NODE,
18438 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18439
d62a17ae 18440 /* "bgp log-neighbor-changes" commands */
18441 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18442 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18443
18444 /* "bgp bestpath med" commands */
18445 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18446 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18447
f7e1c681 18448 /* "bgp bestpath bandwidth" commands */
18449 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18450 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18451
d62a17ae 18452 /* "no bgp default ipv4-unicast" commands. */
18453 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
18454 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
18455
e84c59af
DA
18456 /* "no bgp default ipv6-unicast" commands. */
18457 install_element(BGP_NODE, &no_bgp_default_ipv6_unicast_cmd);
18458 install_element(BGP_NODE, &bgp_default_ipv6_unicast_cmd);
18459
d62a17ae 18460 /* "bgp network import-check" commands. */
18461 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18462 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18463 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18464
18465 /* "bgp default local-preference" commands. */
18466 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18467 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18468
18469 /* bgp default show-hostname */
18470 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18471 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18472
aef999a2
DA
18473 /* bgp default show-nexthop-hostname */
18474 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18475 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18476
d62a17ae 18477 /* "bgp default subgroup-pkt-queue-max" commands. */
18478 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18479 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18480
18481 /* bgp ibgp-allow-policy-mods command */
18482 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18483 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18484
18485 /* "bgp listen limit" commands. */
18486 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18487 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18488
18489 /* "bgp listen range" commands. */
18490 install_element(BGP_NODE, &bgp_listen_range_cmd);
18491 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18492
8175f54a 18493 /* "bgp default shutdown" command */
f26845f9 18494 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18495
18496 /* "bgp shutdown" commands */
18497 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18498 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18499 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18500 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18501
d62a17ae 18502 /* "neighbor remote-as" commands. */
18503 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18504 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18505 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18506 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18507 install_element(BGP_NODE,
18508 &neighbor_interface_v6only_config_remote_as_cmd);
18509 install_element(BGP_NODE, &no_neighbor_cmd);
18510 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18511
18512 /* "neighbor peer-group" commands. */
18513 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18514 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18515 install_element(BGP_NODE,
18516 &no_neighbor_interface_peer_group_remote_as_cmd);
18517
18518 /* "neighbor local-as" commands. */
18519 install_element(BGP_NODE, &neighbor_local_as_cmd);
18520 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18521 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18522 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18523
18524 /* "neighbor solo" commands. */
18525 install_element(BGP_NODE, &neighbor_solo_cmd);
18526 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18527
18528 /* "neighbor password" commands. */
18529 install_element(BGP_NODE, &neighbor_password_cmd);
18530 install_element(BGP_NODE, &no_neighbor_password_cmd);
18531
18532 /* "neighbor activate" commands. */
18533 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18534 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18535 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18536 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18537 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18538 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18539 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18540 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18541 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 18542 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18543 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18544 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18545
18546 /* "no neighbor activate" commands. */
18547 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18548 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18549 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18550 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18551 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18552 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18553 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18554 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18555 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18556 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18557 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18558 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18559
18560 /* "neighbor peer-group" set commands. */
18561 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18562 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18563 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18564 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18565 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18566 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18567 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18568 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18569 install_element(BGP_FLOWSPECV4_NODE,
18570 &neighbor_set_peer_group_hidden_cmd);
18571 install_element(BGP_FLOWSPECV6_NODE,
18572 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18573
18574 /* "no neighbor peer-group unset" commands. */
18575 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18576 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18577 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18578 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18579 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18580 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18581 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18582 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18583 install_element(BGP_FLOWSPECV4_NODE,
18584 &no_neighbor_set_peer_group_hidden_cmd);
18585 install_element(BGP_FLOWSPECV6_NODE,
18586 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18587
18588 /* "neighbor softreconfiguration inbound" commands.*/
18589 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18590 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18591 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18592 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18593 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18594 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18595 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18596 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18597 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18598 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18599 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18600 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18601 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18602 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18603 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18604 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18605 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18606 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18607 install_element(BGP_FLOWSPECV4_NODE,
18608 &neighbor_soft_reconfiguration_cmd);
18609 install_element(BGP_FLOWSPECV4_NODE,
18610 &no_neighbor_soft_reconfiguration_cmd);
18611 install_element(BGP_FLOWSPECV6_NODE,
18612 &neighbor_soft_reconfiguration_cmd);
18613 install_element(BGP_FLOWSPECV6_NODE,
18614 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18615 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18616 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18617
18618 /* "neighbor attribute-unchanged" commands. */
18619 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18620 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18621 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18622 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18623 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18624 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18625 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18626 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18627 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18628 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18629 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18630 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18631 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18632 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18633 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18634 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18635 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18636 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18637
18638 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18639 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18640
b8ad84d2
PG
18641 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18642 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18643 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18644 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18645
d62a17ae 18646 /* "nexthop-local unchanged" commands */
18647 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18648 install_element(BGP_IPV6_NODE,
18649 &no_neighbor_nexthop_local_unchanged_cmd);
18650
18651 /* "neighbor next-hop-self" commands. */
18652 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18653 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18654 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18655 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18656 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18657 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18658 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18659 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18660 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18661 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18662 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18663 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18664 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18665 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18666 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18667 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18668 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18669 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18670 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18671 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18672
18673 /* "neighbor next-hop-self force" commands. */
18674 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18675 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18676 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18677 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18678 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18679 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18680 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18681 install_element(BGP_IPV4_NODE,
18682 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18683 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18684 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18685 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18686 install_element(BGP_IPV4M_NODE,
18687 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18688 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18689 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18690 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18691 install_element(BGP_IPV4L_NODE,
18692 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18693 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18694 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18695 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18696 install_element(BGP_IPV6_NODE,
18697 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18698 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18699 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18700 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18701 install_element(BGP_IPV6M_NODE,
18702 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18703 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18704 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18705 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18706 install_element(BGP_IPV6L_NODE,
18707 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18708 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18709 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18710 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18711 install_element(BGP_VPNV4_NODE,
18712 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18713 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18714 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18715 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18716 install_element(BGP_VPNV6_NODE,
18717 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18718 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18719 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18720
18721 /* "neighbor as-override" commands. */
18722 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18723 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18724 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18725 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18726 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18727 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18728 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18729 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18730 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18731 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18732 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18733 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18734 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18735 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18736 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18737 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18738 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18739 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18740
18741 /* "neighbor remove-private-AS" commands. */
18742 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18743 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18744 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18745 install_element(BGP_NODE,
18746 &no_neighbor_remove_private_as_all_hidden_cmd);
18747 install_element(BGP_NODE,
18748 &neighbor_remove_private_as_replace_as_hidden_cmd);
18749 install_element(BGP_NODE,
18750 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18751 install_element(BGP_NODE,
18752 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18753 install_element(
18754 BGP_NODE,
18755 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18756 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18757 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18758 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18759 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18760 install_element(BGP_IPV4_NODE,
18761 &neighbor_remove_private_as_replace_as_cmd);
18762 install_element(BGP_IPV4_NODE,
18763 &no_neighbor_remove_private_as_replace_as_cmd);
18764 install_element(BGP_IPV4_NODE,
18765 &neighbor_remove_private_as_all_replace_as_cmd);
18766 install_element(BGP_IPV4_NODE,
18767 &no_neighbor_remove_private_as_all_replace_as_cmd);
18768 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18769 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18770 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18771 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18772 install_element(BGP_IPV4M_NODE,
18773 &neighbor_remove_private_as_replace_as_cmd);
18774 install_element(BGP_IPV4M_NODE,
18775 &no_neighbor_remove_private_as_replace_as_cmd);
18776 install_element(BGP_IPV4M_NODE,
18777 &neighbor_remove_private_as_all_replace_as_cmd);
18778 install_element(BGP_IPV4M_NODE,
18779 &no_neighbor_remove_private_as_all_replace_as_cmd);
18780 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18781 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18782 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18783 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18784 install_element(BGP_IPV4L_NODE,
18785 &neighbor_remove_private_as_replace_as_cmd);
18786 install_element(BGP_IPV4L_NODE,
18787 &no_neighbor_remove_private_as_replace_as_cmd);
18788 install_element(BGP_IPV4L_NODE,
18789 &neighbor_remove_private_as_all_replace_as_cmd);
18790 install_element(BGP_IPV4L_NODE,
18791 &no_neighbor_remove_private_as_all_replace_as_cmd);
18792 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18793 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18794 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18795 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18796 install_element(BGP_IPV6_NODE,
18797 &neighbor_remove_private_as_replace_as_cmd);
18798 install_element(BGP_IPV6_NODE,
18799 &no_neighbor_remove_private_as_replace_as_cmd);
18800 install_element(BGP_IPV6_NODE,
18801 &neighbor_remove_private_as_all_replace_as_cmd);
18802 install_element(BGP_IPV6_NODE,
18803 &no_neighbor_remove_private_as_all_replace_as_cmd);
18804 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18805 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18806 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18807 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18808 install_element(BGP_IPV6M_NODE,
18809 &neighbor_remove_private_as_replace_as_cmd);
18810 install_element(BGP_IPV6M_NODE,
18811 &no_neighbor_remove_private_as_replace_as_cmd);
18812 install_element(BGP_IPV6M_NODE,
18813 &neighbor_remove_private_as_all_replace_as_cmd);
18814 install_element(BGP_IPV6M_NODE,
18815 &no_neighbor_remove_private_as_all_replace_as_cmd);
18816 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18817 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18818 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18819 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18820 install_element(BGP_IPV6L_NODE,
18821 &neighbor_remove_private_as_replace_as_cmd);
18822 install_element(BGP_IPV6L_NODE,
18823 &no_neighbor_remove_private_as_replace_as_cmd);
18824 install_element(BGP_IPV6L_NODE,
18825 &neighbor_remove_private_as_all_replace_as_cmd);
18826 install_element(BGP_IPV6L_NODE,
18827 &no_neighbor_remove_private_as_all_replace_as_cmd);
18828 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18829 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18830 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18831 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18832 install_element(BGP_VPNV4_NODE,
18833 &neighbor_remove_private_as_replace_as_cmd);
18834 install_element(BGP_VPNV4_NODE,
18835 &no_neighbor_remove_private_as_replace_as_cmd);
18836 install_element(BGP_VPNV4_NODE,
18837 &neighbor_remove_private_as_all_replace_as_cmd);
18838 install_element(BGP_VPNV4_NODE,
18839 &no_neighbor_remove_private_as_all_replace_as_cmd);
18840 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18841 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18842 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18843 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18844 install_element(BGP_VPNV6_NODE,
18845 &neighbor_remove_private_as_replace_as_cmd);
18846 install_element(BGP_VPNV6_NODE,
18847 &no_neighbor_remove_private_as_replace_as_cmd);
18848 install_element(BGP_VPNV6_NODE,
18849 &neighbor_remove_private_as_all_replace_as_cmd);
18850 install_element(BGP_VPNV6_NODE,
18851 &no_neighbor_remove_private_as_all_replace_as_cmd);
18852
18853 /* "neighbor send-community" commands.*/
18854 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18855 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18856 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18857 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18858 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18859 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18860 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18861 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18862 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18863 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18864 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18865 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18866 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18867 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18868 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18869 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18870 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18871 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18872 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18873 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18874 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18875 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18876 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18877 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18878 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18879 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18880 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18881 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18882 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18883 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18884 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18885 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18886 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18887 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18888 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18889 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18890
18891 /* "neighbor route-reflector" commands.*/
18892 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18893 install_element(BGP_NODE,
18894 &no_neighbor_route_reflector_client_hidden_cmd);
18895 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18896 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18897 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18898 install_element(BGP_IPV4M_NODE,
18899 &no_neighbor_route_reflector_client_cmd);
18900 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18901 install_element(BGP_IPV4L_NODE,
18902 &no_neighbor_route_reflector_client_cmd);
18903 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18904 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18905 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18906 install_element(BGP_IPV6M_NODE,
18907 &no_neighbor_route_reflector_client_cmd);
18908 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18909 install_element(BGP_IPV6L_NODE,
18910 &no_neighbor_route_reflector_client_cmd);
18911 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18912 install_element(BGP_VPNV4_NODE,
18913 &no_neighbor_route_reflector_client_cmd);
18914 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18915 install_element(BGP_VPNV6_NODE,
18916 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18917 install_element(BGP_FLOWSPECV4_NODE,
18918 &neighbor_route_reflector_client_cmd);
18919 install_element(BGP_FLOWSPECV4_NODE,
18920 &no_neighbor_route_reflector_client_cmd);
18921 install_element(BGP_FLOWSPECV6_NODE,
18922 &neighbor_route_reflector_client_cmd);
18923 install_element(BGP_FLOWSPECV6_NODE,
18924 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18925 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18926 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18927
18928 /* "neighbor route-server" commands.*/
18929 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18930 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18931 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18932 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18933 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18934 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18935 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18936 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18937 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18938 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18939 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18940 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18941 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18942 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18943 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18944 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18945 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18946 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18947 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18948 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18949 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18950 install_element(BGP_FLOWSPECV4_NODE,
18951 &no_neighbor_route_server_client_cmd);
18952 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18953 install_element(BGP_FLOWSPECV6_NODE,
18954 &no_neighbor_route_server_client_cmd);
d62a17ae 18955
18956 /* "neighbor addpath-tx-all-paths" commands.*/
18957 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18958 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18959 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18960 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18961 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18962 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18963 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18964 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18965 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18966 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18967 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18968 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18969 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18970 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18971 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18972 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18973 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18974 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18975
18976 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18977 install_element(BGP_NODE,
18978 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18979 install_element(BGP_NODE,
18980 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18981 install_element(BGP_IPV4_NODE,
18982 &neighbor_addpath_tx_bestpath_per_as_cmd);
18983 install_element(BGP_IPV4_NODE,
18984 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18985 install_element(BGP_IPV4M_NODE,
18986 &neighbor_addpath_tx_bestpath_per_as_cmd);
18987 install_element(BGP_IPV4M_NODE,
18988 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18989 install_element(BGP_IPV4L_NODE,
18990 &neighbor_addpath_tx_bestpath_per_as_cmd);
18991 install_element(BGP_IPV4L_NODE,
18992 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18993 install_element(BGP_IPV6_NODE,
18994 &neighbor_addpath_tx_bestpath_per_as_cmd);
18995 install_element(BGP_IPV6_NODE,
18996 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18997 install_element(BGP_IPV6M_NODE,
18998 &neighbor_addpath_tx_bestpath_per_as_cmd);
18999 install_element(BGP_IPV6M_NODE,
19000 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19001 install_element(BGP_IPV6L_NODE,
19002 &neighbor_addpath_tx_bestpath_per_as_cmd);
19003 install_element(BGP_IPV6L_NODE,
19004 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19005 install_element(BGP_VPNV4_NODE,
19006 &neighbor_addpath_tx_bestpath_per_as_cmd);
19007 install_element(BGP_VPNV4_NODE,
19008 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19009 install_element(BGP_VPNV6_NODE,
19010 &neighbor_addpath_tx_bestpath_per_as_cmd);
19011 install_element(BGP_VPNV6_NODE,
19012 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
19013
2b31007c
RZ
19014 /* "neighbor sender-as-path-loop-detection" commands. */
19015 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
19016 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
19017
d62a17ae 19018 /* "neighbor passive" commands. */
19019 install_element(BGP_NODE, &neighbor_passive_cmd);
19020 install_element(BGP_NODE, &no_neighbor_passive_cmd);
19021
19022
19023 /* "neighbor shutdown" commands. */
19024 install_element(BGP_NODE, &neighbor_shutdown_cmd);
19025 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
19026 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
19027 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
19028 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
19029 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 19030
19031 /* "neighbor capability extended-nexthop" commands.*/
19032 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
19033 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
19034
19035 /* "neighbor capability orf prefix-list" commands.*/
19036 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
19037 install_element(BGP_NODE,
19038 &no_neighbor_capability_orf_prefix_hidden_cmd);
19039 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
19040 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
19041 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
19042 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19043 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
19044 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19045 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
19046 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
19047 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
19048 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
19049 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
19050 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
19051
19052 /* "neighbor capability dynamic" commands.*/
19053 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
19054 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
19055
19056 /* "neighbor dont-capability-negotiate" commands. */
19057 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
19058 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
19059
19060 /* "neighbor ebgp-multihop" commands. */
19061 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
19062 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
19063 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
19064
19065 /* "neighbor disable-connected-check" commands. */
19066 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
19067 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
19068
47cbc09b
PM
19069 /* "neighbor enforce-first-as" commands. */
19070 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
19071 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
19072
d62a17ae 19073 /* "neighbor description" commands. */
19074 install_element(BGP_NODE, &neighbor_description_cmd);
19075 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 19076 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 19077
19078 /* "neighbor update-source" commands. "*/
19079 install_element(BGP_NODE, &neighbor_update_source_cmd);
19080 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
19081
19082 /* "neighbor default-originate" commands. */
19083 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
19084 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
19085 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
19086 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
19087 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
19088 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
19089 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
19090 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
19091 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
19092 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
19093 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
19094 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
19095 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
19096 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
19097 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
19098 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
19099 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
19100 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
19101 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
19102 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19103 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19104
19105 /* "neighbor port" commands. */
19106 install_element(BGP_NODE, &neighbor_port_cmd);
19107 install_element(BGP_NODE, &no_neighbor_port_cmd);
19108
19109 /* "neighbor weight" commands. */
19110 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19111 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19112
19113 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19114 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19115 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19116 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19117 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19118 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19119 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19120 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19121 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19122 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19123 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19124 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19125 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19126 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19127 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19128 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19129
19130 /* "neighbor override-capability" commands. */
19131 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19132 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19133
19134 /* "neighbor strict-capability-match" commands. */
19135 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19136 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19137
19138 /* "neighbor timers" commands. */
19139 install_element(BGP_NODE, &neighbor_timers_cmd);
19140 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19141
19142 /* "neighbor timers connect" commands. */
19143 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19144 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19145
d43114f3
DS
19146 /* "neighbor timers delayopen" commands. */
19147 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19148 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19149
d62a17ae 19150 /* "neighbor advertisement-interval" commands. */
19151 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19152 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19153
19154 /* "neighbor interface" commands. */
19155 install_element(BGP_NODE, &neighbor_interface_cmd);
19156 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19157
19158 /* "neighbor distribute" commands. */
19159 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19160 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19161 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19162 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19163 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19164 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19165 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19166 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19167 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19168 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19169 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19170 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19171 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19172 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19173 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19174 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19175 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19176 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19177
19178 /* "neighbor prefix-list" commands. */
19179 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
d62a17ae 19180 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19181 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19182 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19183 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19184 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19185 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19186 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19187 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
7c40bf39 19188 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
7c40bf39 19189 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19190
19191 /* "neighbor filter-list" commands. */
19192 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19193 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19194 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19195 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19196 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19197 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19198 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19199 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19200 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19201 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19202 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19203 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19204 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19205 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19206 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19207 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19208 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19209 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 19210 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19211 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19212 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19213 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 19214
19215 /* "neighbor route-map" commands. */
d62a17ae 19216 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
d62a17ae 19217 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
d62a17ae 19218 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
d62a17ae 19219 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
d62a17ae 19220 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
d62a17ae 19221 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
d62a17ae 19222 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
d62a17ae 19223 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
7c40bf39 19224 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
7c40bf39 19225 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
d37ba549 19226 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
d62a17ae 19227
19228 /* "neighbor unsuppress-map" commands. */
19229 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19230 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19231 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19232 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19233 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19234 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19235 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19236 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19237 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19238 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19239 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19240 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19241 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19242 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19243 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19244 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19245 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19246 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19247
7f7940e6
MK
19248 /* "neighbor advertise-map" commands. */
19249 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 19250 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19251 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19252 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19253 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19254 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19255 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19256 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19257 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19258
fde246e8
DA
19259 /* neighbor maximum-prefix-out commands. */
19260 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19261 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19262 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19263 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19264 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19265 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19266 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19267 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19268 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19269 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19270 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19271 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19272 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19273 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19274 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19275 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19276 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19277 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19278
d62a17ae 19279 /* "neighbor maximum-prefix" commands. */
19280 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19281 install_element(BGP_NODE,
19282 &neighbor_maximum_prefix_threshold_hidden_cmd);
19283 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19284 install_element(BGP_NODE,
19285 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19286 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19287 install_element(BGP_NODE,
19288 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19289 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19290 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19291 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19292 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19293 install_element(BGP_IPV4_NODE,
19294 &neighbor_maximum_prefix_threshold_warning_cmd);
19295 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19296 install_element(BGP_IPV4_NODE,
19297 &neighbor_maximum_prefix_threshold_restart_cmd);
19298 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19299 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19300 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19301 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19302 install_element(BGP_IPV4M_NODE,
19303 &neighbor_maximum_prefix_threshold_warning_cmd);
19304 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19305 install_element(BGP_IPV4M_NODE,
19306 &neighbor_maximum_prefix_threshold_restart_cmd);
19307 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19308 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19309 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19310 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19311 install_element(BGP_IPV4L_NODE,
19312 &neighbor_maximum_prefix_threshold_warning_cmd);
19313 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19314 install_element(BGP_IPV4L_NODE,
19315 &neighbor_maximum_prefix_threshold_restart_cmd);
19316 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19317 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19318 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19319 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19320 install_element(BGP_IPV6_NODE,
19321 &neighbor_maximum_prefix_threshold_warning_cmd);
19322 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19323 install_element(BGP_IPV6_NODE,
19324 &neighbor_maximum_prefix_threshold_restart_cmd);
19325 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19326 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19327 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19328 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19329 install_element(BGP_IPV6M_NODE,
19330 &neighbor_maximum_prefix_threshold_warning_cmd);
19331 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19332 install_element(BGP_IPV6M_NODE,
19333 &neighbor_maximum_prefix_threshold_restart_cmd);
19334 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19335 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19336 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19337 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19338 install_element(BGP_IPV6L_NODE,
19339 &neighbor_maximum_prefix_threshold_warning_cmd);
19340 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19341 install_element(BGP_IPV6L_NODE,
19342 &neighbor_maximum_prefix_threshold_restart_cmd);
19343 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19344 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19345 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19346 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19347 install_element(BGP_VPNV4_NODE,
19348 &neighbor_maximum_prefix_threshold_warning_cmd);
19349 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19350 install_element(BGP_VPNV4_NODE,
19351 &neighbor_maximum_prefix_threshold_restart_cmd);
19352 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19353 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19354 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19355 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19356 install_element(BGP_VPNV6_NODE,
19357 &neighbor_maximum_prefix_threshold_warning_cmd);
19358 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19359 install_element(BGP_VPNV6_NODE,
19360 &neighbor_maximum_prefix_threshold_restart_cmd);
19361 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19362
19363 /* "neighbor allowas-in" */
19364 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19365 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19366 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19367 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19368 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19369 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19370 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19371 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19372 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19373 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19374 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19375 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19376 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19377 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19378 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19379 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19380 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19381 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19382 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19383 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19384
0221327c
DS
19385 /* "neighbor dampening" commands. */
19386 install_element(BGP_NODE, &neighbor_damp_cmd);
19387 install_element(BGP_NODE, &no_neighbor_damp_cmd);
19388 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
19389 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
19390 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
19391 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
19392 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
19393 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
19394 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
19395 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
19396 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
19397 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
19398 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
19399 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
19400 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
19401
d62a17ae 19402 /* address-family commands. */
19403 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19404 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 19405#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 19406 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19407 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 19408#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 19409
d62a17ae 19410 install_element(BGP_NODE, &address_family_evpn_cmd);
19411
19412 /* "exit-address-family" command. */
19413 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19414 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19415 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19416 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19417 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19418 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19419 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19420 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 19421 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19422 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 19423 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19424
19425 /* "clear ip bgp commands" */
19426 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19427
19428 /* clear ip bgp prefix */
19429 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19430 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19431 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19432
19433 /* "show [ip] bgp summary" commands. */
19434 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 19435 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 19436 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 19437 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 19438 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19439 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 19440 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19441
19442 /* "show [ip] bgp neighbors" commands. */
19443 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19444
36235319 19445 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 19446
d62a17ae 19447 /* "show [ip] bgp peer-group" commands. */
19448 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19449
19450 /* "show [ip] bgp paths" commands. */
19451 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19452
19453 /* "show [ip] bgp community" commands. */
19454 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19455
19456 /* "show ip bgp large-community" commands. */
19457 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19458 /* "show [ip] bgp attribute-info" commands. */
19459 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 19460 /* "show [ip] bgp route-leak" command */
19461 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 19462
19463 /* "redistribute" commands. */
19464 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19465 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19466 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19467 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19468 install_element(BGP_NODE,
19469 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19470 install_element(BGP_NODE,
19471 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19472 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19473 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19474 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19475 install_element(BGP_NODE,
19476 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19477 install_element(BGP_NODE,
19478 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19479 install_element(BGP_NODE,
19480 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19481 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19482 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19483 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19484 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19485 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19486 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19487 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19488 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19489 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19490 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19491 install_element(BGP_IPV4_NODE,
19492 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19493 install_element(BGP_IPV4_NODE,
19494 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19495 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19496 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19497 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19498 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19499 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19500 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19501
b9c7bc5a
PZ
19502 /* import|export vpn [route-map WORD] */
19503 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19504 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 19505
12a844a5
DS
19506 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19507 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19508
d62a17ae 19509 /* ttl_security commands */
19510 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19511 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19512
19513 /* "show [ip] bgp memory" commands. */
19514 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19515
acf71666
MK
19516 /* "show bgp martian next-hop" */
19517 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19518
48ecf8f5
DS
19519 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19520
d62a17ae 19521 /* "show [ip] bgp views" commands. */
19522 install_element(VIEW_NODE, &show_bgp_views_cmd);
19523
19524 /* "show [ip] bgp vrfs" commands. */
19525 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19526
19527 /* Community-list. */
19528 community_list_vty();
ddb5b488 19529
ed0e57e3
DA
19530 community_alias_vty();
19531
ddb5b488 19532 /* vpn-policy commands */
b9c7bc5a
PZ
19533 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19534 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19535 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19536 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19537 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19538 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19539 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19540 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19541 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19542 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
19543 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19544 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 19545
301ad80a
PG
19546 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19547 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19548
b9c7bc5a
PZ
19549 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19550 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19551 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19552 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
19553 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19554 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19555 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19556 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19557 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19558 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
19559
19560 /* tcp-mss command */
19561 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19562 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
19563
19564 /* srv6 commands */
19565 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
a0281b2e 19566 install_element(BGP_SRV6_NODE, &bgp_srv6_locator_cmd);
b72c9e14
HS
19567 install_element(BGP_IPV4_NODE, &af_sid_vpn_export_cmd);
19568 install_element(BGP_IPV6_NODE, &af_sid_vpn_export_cmd);
718e3744 19569}
6b0655a2 19570
718e3744 19571#include "memory.h"
19572#include "bgp_regex.h"
19573#include "bgp_clist.h"
19574#include "bgp_ecommunity.h"
19575
19576/* VTY functions. */
19577
19578/* Direction value to string conversion. */
d62a17ae 19579static const char *community_direct_str(int direct)
19580{
19581 switch (direct) {
19582 case COMMUNITY_DENY:
19583 return "deny";
19584 case COMMUNITY_PERMIT:
19585 return "permit";
19586 default:
19587 return "unknown";
19588 }
718e3744 19589}
19590
19591/* Display error string. */
d62a17ae 19592static void community_list_perror(struct vty *vty, int ret)
19593{
19594 switch (ret) {
19595 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19596 vty_out(vty, "%% Can't find community-list\n");
19597 break;
19598 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19599 vty_out(vty, "%% Malformed community-list value\n");
19600 break;
19601 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19602 vty_out(vty,
19603 "%% Community name conflict, previously defined as standard community\n");
19604 break;
19605 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19606 vty_out(vty,
19607 "%% Community name conflict, previously defined as expanded community\n");
19608 break;
19609 }
718e3744 19610}
19611
5bf15956
DW
19612/* "community-list" keyword help string. */
19613#define COMMUNITY_LIST_STR "Add a community list entry\n"
19614
7336e101
SP
19615/*community-list standard */
19616DEFUN (community_list_standard,
19617 bgp_community_list_standard_cmd,
a08032fe 19618 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19619 BGP_STR
718e3744 19620 COMMUNITY_LIST_STR
19621 "Community list number (standard)\n"
5bf15956 19622 "Add an standard community-list entry\n"
718e3744 19623 "Community list name\n"
2f8cc0e5
DA
19624 "Sequence number of an entry\n"
19625 "Sequence number\n"
718e3744 19626 "Specify community to reject\n"
19627 "Specify community to accept\n"
19628 COMMUNITY_VAL_STR)
19629{
d62a17ae 19630 char *cl_name_or_number = NULL;
2f8cc0e5 19631 char *seq = NULL;
d62a17ae 19632 int direct = 0;
19633 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19634 int idx = 0;
7336e101 19635
a08032fe 19636 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19637 if (idx)
19638 seq = argv[idx]->arg;
19639
19640 idx = 0;
d62a17ae 19641 argv_find(argv, argc, "(1-99)", &idx);
19642 argv_find(argv, argc, "WORD", &idx);
19643 cl_name_or_number = argv[idx]->arg;
19644 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19645 : COMMUNITY_DENY;
19646 argv_find(argv, argc, "AA:NN", &idx);
19647 char *str = argv_concat(argv, argc, idx);
42f914d4 19648
2f8cc0e5
DA
19649 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19650 direct, style);
42f914d4 19651
d62a17ae 19652 XFREE(MTYPE_TMP, str);
42f914d4 19653
d62a17ae 19654 if (ret < 0) {
19655 /* Display error string. */
19656 community_list_perror(vty, ret);
19657 return CMD_WARNING_CONFIG_FAILED;
19658 }
42f914d4 19659
d62a17ae 19660 return CMD_SUCCESS;
718e3744 19661}
19662
7336e101
SP
19663DEFUN (no_community_list_standard_all,
19664 no_bgp_community_list_standard_all_cmd,
a08032fe 19665 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19666 NO_STR
19667 BGP_STR
19668 COMMUNITY_LIST_STR
19669 "Community list number (standard)\n"
19670 "Add an standard community-list entry\n"
19671 "Community list name\n"
2f8cc0e5
DA
19672 "Sequence number of an entry\n"
19673 "Sequence number\n"
7336e101
SP
19674 "Specify community to reject\n"
19675 "Specify community to accept\n"
19676 COMMUNITY_VAL_STR)
718e3744 19677{
d62a17ae 19678 char *cl_name_or_number = NULL;
174b5cb9 19679 char *str = NULL;
d62a17ae 19680 int direct = 0;
19681 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19682 char *seq = NULL;
d62a17ae 19683 int idx = 0;
7336e101 19684
a08032fe 19685 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19686 if (idx)
19687 seq = argv[idx]->arg;
19688
19689 idx = 0;
174b5cb9
DA
19690 argv_find(argv, argc, "permit", &idx);
19691 argv_find(argv, argc, "deny", &idx);
19692
19693 if (idx) {
19694 direct = argv_find(argv, argc, "permit", &idx)
19695 ? COMMUNITY_PERMIT
19696 : COMMUNITY_DENY;
19697
19698 idx = 0;
19699 argv_find(argv, argc, "AA:NN", &idx);
19700 str = argv_concat(argv, argc, idx);
19701 }
19702
19703 idx = 0;
d62a17ae 19704 argv_find(argv, argc, "(1-99)", &idx);
19705 argv_find(argv, argc, "WORD", &idx);
19706 cl_name_or_number = argv[idx]->arg;
42f914d4 19707
2f8cc0e5 19708 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19709 direct, style);
42f914d4 19710
d62a17ae 19711 XFREE(MTYPE_TMP, str);
daf9ddbb 19712
d62a17ae 19713 if (ret < 0) {
19714 community_list_perror(vty, ret);
19715 return CMD_WARNING_CONFIG_FAILED;
19716 }
42f914d4 19717
d62a17ae 19718 return CMD_SUCCESS;
718e3744 19719}
7336e101 19720
174b5cb9
DA
19721ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19722 "no bgp community-list <(1-99)|standard WORD>",
19723 NO_STR BGP_STR COMMUNITY_LIST_STR
19724 "Community list number (standard)\n"
19725 "Add an standard community-list entry\n"
19726 "Community list name\n")
19727
7336e101
SP
19728/*community-list expanded */
19729DEFUN (community_list_expanded_all,
19730 bgp_community_list_expanded_all_cmd,
a08032fe 19731 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19732 BGP_STR
19733 COMMUNITY_LIST_STR
718e3744 19734 "Community list number (expanded)\n"
5bf15956 19735 "Add an expanded community-list entry\n"
718e3744 19736 "Community list name\n"
2f8cc0e5
DA
19737 "Sequence number of an entry\n"
19738 "Sequence number\n"
718e3744 19739 "Specify community to reject\n"
19740 "Specify community to accept\n"
19741 COMMUNITY_VAL_STR)
19742{
d62a17ae 19743 char *cl_name_or_number = NULL;
2f8cc0e5 19744 char *seq = NULL;
d62a17ae 19745 int direct = 0;
19746 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19747 int idx = 0;
7b9a4750 19748
a08032fe 19749 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19750 if (idx)
19751 seq = argv[idx]->arg;
19752
19753 idx = 0;
19754
d62a17ae 19755 argv_find(argv, argc, "(100-500)", &idx);
19756 argv_find(argv, argc, "WORD", &idx);
19757 cl_name_or_number = argv[idx]->arg;
19758 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19759 : COMMUNITY_DENY;
19760 argv_find(argv, argc, "AA:NN", &idx);
19761 char *str = argv_concat(argv, argc, idx);
42f914d4 19762
2f8cc0e5
DA
19763 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19764 direct, style);
42f914d4 19765
d62a17ae 19766 XFREE(MTYPE_TMP, str);
42f914d4 19767
d62a17ae 19768 if (ret < 0) {
19769 /* Display error string. */
19770 community_list_perror(vty, ret);
19771 return CMD_WARNING_CONFIG_FAILED;
19772 }
42f914d4 19773
d62a17ae 19774 return CMD_SUCCESS;
718e3744 19775}
19776
7336e101
SP
19777DEFUN (no_community_list_expanded_all,
19778 no_bgp_community_list_expanded_all_cmd,
a08032fe 19779 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19780 NO_STR
19781 BGP_STR
19782 COMMUNITY_LIST_STR
19783 "Community list number (expanded)\n"
19784 "Add an expanded community-list entry\n"
19785 "Community list name\n"
2f8cc0e5
DA
19786 "Sequence number of an entry\n"
19787 "Sequence number\n"
7336e101
SP
19788 "Specify community to reject\n"
19789 "Specify community to accept\n"
19790 COMMUNITY_VAL_STR)
718e3744 19791{
d62a17ae 19792 char *cl_name_or_number = NULL;
2f8cc0e5 19793 char *seq = NULL;
174b5cb9 19794 char *str = NULL;
d62a17ae 19795 int direct = 0;
19796 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19797 int idx = 0;
174b5cb9 19798
a08032fe 19799 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19800 if (idx)
19801 seq = argv[idx]->arg;
19802
19803 idx = 0;
174b5cb9
DA
19804 argv_find(argv, argc, "permit", &idx);
19805 argv_find(argv, argc, "deny", &idx);
19806
19807 if (idx) {
19808 direct = argv_find(argv, argc, "permit", &idx)
19809 ? COMMUNITY_PERMIT
19810 : COMMUNITY_DENY;
19811
19812 idx = 0;
19813 argv_find(argv, argc, "AA:NN", &idx);
19814 str = argv_concat(argv, argc, idx);
7336e101 19815 }
174b5cb9
DA
19816
19817 idx = 0;
d62a17ae 19818 argv_find(argv, argc, "(100-500)", &idx);
19819 argv_find(argv, argc, "WORD", &idx);
19820 cl_name_or_number = argv[idx]->arg;
42f914d4 19821
2f8cc0e5 19822 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19823 direct, style);
42f914d4 19824
d62a17ae 19825 XFREE(MTYPE_TMP, str);
daf9ddbb 19826
d62a17ae 19827 if (ret < 0) {
19828 community_list_perror(vty, ret);
19829 return CMD_WARNING_CONFIG_FAILED;
19830 }
42f914d4 19831
d62a17ae 19832 return CMD_SUCCESS;
718e3744 19833}
19834
36d4bb44
EB
19835ALIAS(no_community_list_expanded_all,
19836 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 19837 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 19838 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19839 "Community list number (expanded)\n"
19840 "Add an expanded community-list entry\n"
19841 "Community list name\n")
19842
8d9b8ed9
PM
19843/* Return configuration string of community-list entry. */
19844static const char *community_list_config_str(struct community_entry *entry)
19845{
19846 const char *str;
19847
19848 if (entry->any)
19849 str = "";
19850 else {
19851 if (entry->style == COMMUNITY_LIST_STANDARD)
19852 str = community_str(entry->u.com, false);
19853 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19854 str = lcommunity_str(entry->u.lcom, false);
19855 else
19856 str = entry->config;
19857 }
19858 return str;
19859}
19860
d62a17ae 19861static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19862{
d62a17ae 19863 struct community_entry *entry;
718e3744 19864
d62a17ae 19865 for (entry = list->head; entry; entry = entry->next) {
19866 if (entry == list->head) {
19867 if (all_digit(list->name))
19868 vty_out(vty, "Community %s list %s\n",
19869 entry->style == COMMUNITY_LIST_STANDARD
19870 ? "standard"
19871 : "(expanded) access",
19872 list->name);
19873 else
19874 vty_out(vty, "Named Community %s list %s\n",
19875 entry->style == COMMUNITY_LIST_STANDARD
19876 ? "standard"
19877 : "expanded",
19878 list->name);
19879 }
19880 if (entry->any)
19881 vty_out(vty, " %s\n",
19882 community_direct_str(entry->direct));
19883 else
19884 vty_out(vty, " %s %s\n",
19885 community_direct_str(entry->direct),
8d9b8ed9 19886 community_list_config_str(entry));
d62a17ae 19887 }
718e3744 19888}
19889
7336e101
SP
19890DEFUN (show_community_list,
19891 show_bgp_community_list_cmd,
19892 "show bgp community-list",
718e3744 19893 SHOW_STR
7336e101 19894 BGP_STR
718e3744 19895 "List community-list\n")
19896{
d62a17ae 19897 struct community_list *list;
19898 struct community_list_master *cm;
718e3744 19899
d62a17ae 19900 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19901 if (!cm)
19902 return CMD_SUCCESS;
718e3744 19903
d62a17ae 19904 for (list = cm->num.head; list; list = list->next)
19905 community_list_show(vty, list);
718e3744 19906
d62a17ae 19907 for (list = cm->str.head; list; list = list->next)
19908 community_list_show(vty, list);
718e3744 19909
d62a17ae 19910 return CMD_SUCCESS;
718e3744 19911}
19912
7336e101
SP
19913DEFUN (show_community_list_arg,
19914 show_bgp_community_list_arg_cmd,
960b69b9 19915 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
19916 SHOW_STR
19917 BGP_STR
718e3744 19918 "List community-list\n"
19919 "Community-list number\n"
960b69b9 19920 "Community-list name\n"
19921 "Detailed information on community-list\n")
718e3744 19922{
d62a17ae 19923 int idx_comm_list = 3;
19924 struct community_list *list;
718e3744 19925
e237b0d2 19926 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19927 COMMUNITY_LIST_MASTER);
19928 if (!list) {
19929 vty_out(vty, "%% Can't find community-list\n");
19930 return CMD_WARNING;
19931 }
718e3744 19932
d62a17ae 19933 community_list_show(vty, list);
718e3744 19934
d62a17ae 19935 return CMD_SUCCESS;
718e3744 19936}
6b0655a2 19937
57d187bc
JS
19938/*
19939 * Large Community code.
19940 */
d62a17ae 19941static int lcommunity_list_set_vty(struct vty *vty, int argc,
19942 struct cmd_token **argv, int style,
19943 int reject_all_digit_name)
19944{
19945 int ret;
19946 int direct;
19947 char *str;
19948 int idx = 0;
19949 char *cl_name;
2f8cc0e5
DA
19950 char *seq = NULL;
19951
a08032fe 19952 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19953 seq = argv[idx]->arg;
d62a17ae 19954
2f8cc0e5 19955 idx = 0;
d62a17ae 19956 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19957 : COMMUNITY_DENY;
19958
19959 /* All digit name check. */
19960 idx = 0;
19961 argv_find(argv, argc, "WORD", &idx);
19962 argv_find(argv, argc, "(1-99)", &idx);
19963 argv_find(argv, argc, "(100-500)", &idx);
19964 cl_name = argv[idx]->arg;
19965 if (reject_all_digit_name && all_digit(cl_name)) {
19966 vty_out(vty, "%% Community name cannot have all digits\n");
19967 return CMD_WARNING_CONFIG_FAILED;
19968 }
19969
19970 idx = 0;
19971 argv_find(argv, argc, "AA:BB:CC", &idx);
19972 argv_find(argv, argc, "LINE", &idx);
19973 /* Concat community string argument. */
19974 if (idx)
19975 str = argv_concat(argv, argc, idx);
19976 else
19977 str = NULL;
19978
2f8cc0e5 19979 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19980
19981 /* Free temporary community list string allocated by
19982 argv_concat(). */
0a22ddfb 19983 XFREE(MTYPE_TMP, str);
d62a17ae 19984
19985 if (ret < 0) {
19986 community_list_perror(vty, ret);
19987 return CMD_WARNING_CONFIG_FAILED;
19988 }
19989 return CMD_SUCCESS;
19990}
19991
19992static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19993 struct cmd_token **argv, int style)
19994{
19995 int ret;
19996 int direct = 0;
19997 char *str = NULL;
19998 int idx = 0;
2f8cc0e5 19999 char *seq = NULL;
d62a17ae 20000
a08032fe 20001 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 20002 seq = argv[idx]->arg;
d62a17ae 20003
2f8cc0e5 20004 idx = 0;
d62a17ae 20005 argv_find(argv, argc, "permit", &idx);
20006 argv_find(argv, argc, "deny", &idx);
20007
20008 if (idx) {
20009 /* Check the list direct. */
20010 if (strncmp(argv[idx]->arg, "p", 1) == 0)
20011 direct = COMMUNITY_PERMIT;
20012 else
20013 direct = COMMUNITY_DENY;
20014
20015 idx = 0;
20016 argv_find(argv, argc, "LINE", &idx);
20017 argv_find(argv, argc, "AA:AA:NN", &idx);
20018 /* Concat community string argument. */
20019 str = argv_concat(argv, argc, idx);
20020 }
20021
20022 idx = 0;
20023 argv_find(argv, argc, "(1-99)", &idx);
20024 argv_find(argv, argc, "(100-500)", &idx);
20025 argv_find(argv, argc, "WORD", &idx);
20026
20027 /* Unset community list. */
2f8cc0e5 20028 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 20029 style);
20030
20031 /* Free temporary community list string allocated by
20032 argv_concat(). */
0a22ddfb 20033 XFREE(MTYPE_TMP, str);
d62a17ae 20034
20035 if (ret < 0) {
20036 community_list_perror(vty, ret);
20037 return CMD_WARNING_CONFIG_FAILED;
20038 }
20039
20040 return CMD_SUCCESS;
57d187bc
JS
20041}
20042
20043/* "large-community-list" keyword help string. */
20044#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
20045#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
20046
7336e101
SP
20047DEFUN (lcommunity_list_standard,
20048 bgp_lcommunity_list_standard_cmd,
a08032fe 20049 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20050 BGP_STR
20051 LCOMMUNITY_LIST_STR
20052 "Large Community list number (standard)\n"
2f8cc0e5
DA
20053 "Sequence number of an entry\n"
20054 "Sequence number\n"
7336e101
SP
20055 "Specify large community to reject\n"
20056 "Specify large community to accept\n"
20057 LCOMMUNITY_VAL_STR)
52951b63 20058{
d62a17ae 20059 return lcommunity_list_set_vty(vty, argc, argv,
20060 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
20061}
20062
7336e101
SP
20063DEFUN (lcommunity_list_expanded,
20064 bgp_lcommunity_list_expanded_cmd,
a08032fe 20065 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20066 BGP_STR
20067 LCOMMUNITY_LIST_STR
20068 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20069 "Sequence number of an entry\n"
20070 "Sequence number\n"
7336e101
SP
20071 "Specify large community to reject\n"
20072 "Specify large community to accept\n"
20073 "An ordered list as a regular-expression\n")
57d187bc 20074{
d62a17ae 20075 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20076 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
20077}
20078
7336e101
SP
20079DEFUN (lcommunity_list_name_standard,
20080 bgp_lcommunity_list_name_standard_cmd,
a08032fe 20081 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
20082 BGP_STR
20083 LCOMMUNITY_LIST_STR
20084 "Specify standard large-community-list\n"
20085 "Large Community list name\n"
2f8cc0e5
DA
20086 "Sequence number of an entry\n"
20087 "Sequence number\n"
7336e101
SP
20088 "Specify large community to reject\n"
20089 "Specify large community to accept\n"
20090 LCOMMUNITY_VAL_STR)
52951b63 20091{
d62a17ae 20092 return lcommunity_list_set_vty(vty, argc, argv,
20093 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
20094}
20095
7336e101
SP
20096DEFUN (lcommunity_list_name_expanded,
20097 bgp_lcommunity_list_name_expanded_cmd,
a08032fe 20098 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20099 BGP_STR
20100 LCOMMUNITY_LIST_STR
20101 "Specify expanded large-community-list\n"
20102 "Large Community list name\n"
2f8cc0e5
DA
20103 "Sequence number of an entry\n"
20104 "Sequence number\n"
7336e101
SP
20105 "Specify large community to reject\n"
20106 "Specify large community to accept\n"
20107 "An ordered list as a regular-expression\n")
57d187bc 20108{
d62a17ae 20109 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20110 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
20111}
20112
4378f57c
DA
20113DEFUN (no_lcommunity_list_all,
20114 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
20115 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
20116 NO_STR
20117 BGP_STR
20118 LCOMMUNITY_LIST_STR
20119 "Large Community list number (standard)\n"
20120 "Large Community list number (expanded)\n"
20121 "Large Community list name\n")
57d187bc 20122{
7336e101
SP
20123 return lcommunity_list_unset_vty(vty, argc, argv,
20124 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20125}
20126
4378f57c
DA
20127DEFUN (no_lcommunity_list_name_standard_all,
20128 no_bgp_lcommunity_list_name_standard_all_cmd,
20129 "no bgp large-community-list standard WORD",
20130 NO_STR
20131 BGP_STR
20132 LCOMMUNITY_LIST_STR
20133 "Specify standard large-community-list\n"
20134 "Large Community list name\n")
20135{
20136 return lcommunity_list_unset_vty(vty, argc, argv,
20137 LARGE_COMMUNITY_LIST_STANDARD);
20138}
20139
7336e101
SP
20140DEFUN (no_lcommunity_list_name_expanded_all,
20141 no_bgp_lcommunity_list_name_expanded_all_cmd,
20142 "no bgp large-community-list expanded WORD",
20143 NO_STR
20144 BGP_STR
20145 LCOMMUNITY_LIST_STR
20146 "Specify expanded large-community-list\n"
20147 "Large Community list name\n")
57d187bc 20148{
d62a17ae 20149 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20150 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20151}
20152
7336e101
SP
20153DEFUN (no_lcommunity_list_standard,
20154 no_bgp_lcommunity_list_standard_cmd,
a08032fe 20155 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20156 NO_STR
20157 BGP_STR
20158 LCOMMUNITY_LIST_STR
20159 "Large Community list number (standard)\n"
2f8cc0e5
DA
20160 "Sequence number of an entry\n"
20161 "Sequence number\n"
7336e101
SP
20162 "Specify large community to reject\n"
20163 "Specify large community to accept\n"
20164 LCOMMUNITY_VAL_STR)
57d187bc 20165{
d62a17ae 20166 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20167 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20168}
20169
7336e101
SP
20170DEFUN (no_lcommunity_list_expanded,
20171 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 20172 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20173 NO_STR
20174 BGP_STR
20175 LCOMMUNITY_LIST_STR
20176 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20177 "Sequence number of an entry\n"
20178 "Sequence number\n"
7336e101
SP
20179 "Specify large community to reject\n"
20180 "Specify large community to accept\n"
20181 "An ordered list as a regular-expression\n")
57d187bc 20182{
d62a17ae 20183 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20184 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20185}
20186
7336e101
SP
20187DEFUN (no_lcommunity_list_name_standard,
20188 no_bgp_lcommunity_list_name_standard_cmd,
a08032fe 20189 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20190 NO_STR
20191 BGP_STR
20192 LCOMMUNITY_LIST_STR
20193 "Specify standard large-community-list\n"
20194 "Large Community list name\n"
2f8cc0e5
DA
20195 "Sequence number of an entry\n"
20196 "Sequence number\n"
7336e101
SP
20197 "Specify large community to reject\n"
20198 "Specify large community to accept\n"
20199 LCOMMUNITY_VAL_STR)
57d187bc 20200{
d62a17ae 20201 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20202 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20203}
20204
7336e101
SP
20205DEFUN (no_lcommunity_list_name_expanded,
20206 no_bgp_lcommunity_list_name_expanded_cmd,
a08032fe 20207 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20208 NO_STR
20209 BGP_STR
20210 LCOMMUNITY_LIST_STR
20211 "Specify expanded large-community-list\n"
20212 "Large community list name\n"
2f8cc0e5
DA
20213 "Sequence number of an entry\n"
20214 "Sequence number\n"
7336e101
SP
20215 "Specify large community to reject\n"
20216 "Specify large community to accept\n"
20217 "An ordered list as a regular-expression\n")
57d187bc 20218{
d62a17ae 20219 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20220 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20221}
20222
d62a17ae 20223static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20224{
20225 struct community_entry *entry;
20226
20227 for (entry = list->head; entry; entry = entry->next) {
20228 if (entry == list->head) {
20229 if (all_digit(list->name))
20230 vty_out(vty, "Large community %s list %s\n",
169b72c8 20231 entry->style ==
20232 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20233 ? "standard"
20234 : "(expanded) access",
20235 list->name);
20236 else
20237 vty_out(vty,
20238 "Named large community %s list %s\n",
169b72c8 20239 entry->style ==
20240 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20241 ? "standard"
20242 : "expanded",
20243 list->name);
20244 }
20245 if (entry->any)
20246 vty_out(vty, " %s\n",
20247 community_direct_str(entry->direct));
20248 else
20249 vty_out(vty, " %s %s\n",
20250 community_direct_str(entry->direct),
8d9b8ed9 20251 community_list_config_str(entry));
d62a17ae 20252 }
57d187bc
JS
20253}
20254
7336e101
SP
20255DEFUN (show_lcommunity_list,
20256 show_bgp_lcommunity_list_cmd,
20257 "show bgp large-community-list",
57d187bc 20258 SHOW_STR
7336e101 20259 BGP_STR
57d187bc
JS
20260 "List large-community list\n")
20261{
d62a17ae 20262 struct community_list *list;
20263 struct community_list_master *cm;
57d187bc 20264
d62a17ae 20265 cm = community_list_master_lookup(bgp_clist,
20266 LARGE_COMMUNITY_LIST_MASTER);
20267 if (!cm)
20268 return CMD_SUCCESS;
57d187bc 20269
d62a17ae 20270 for (list = cm->num.head; list; list = list->next)
20271 lcommunity_list_show(vty, list);
57d187bc 20272
d62a17ae 20273 for (list = cm->str.head; list; list = list->next)
20274 lcommunity_list_show(vty, list);
57d187bc 20275
d62a17ae 20276 return CMD_SUCCESS;
57d187bc
JS
20277}
20278
7336e101
SP
20279DEFUN (show_lcommunity_list_arg,
20280 show_bgp_lcommunity_list_arg_cmd,
960b69b9 20281 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
20282 SHOW_STR
20283 BGP_STR
57d187bc 20284 "List large-community list\n"
960b69b9 20285 "Large-community-list number\n"
20286 "Large-community-list name\n"
20287 "Detailed information on large-community-list\n")
57d187bc 20288{
d62a17ae 20289 struct community_list *list;
57d187bc 20290
e237b0d2 20291 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 20292 LARGE_COMMUNITY_LIST_MASTER);
20293 if (!list) {
960b69b9 20294 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 20295 return CMD_WARNING;
20296 }
57d187bc 20297
d62a17ae 20298 lcommunity_list_show(vty, list);
57d187bc 20299
d62a17ae 20300 return CMD_SUCCESS;
57d187bc
JS
20301}
20302
718e3744 20303/* "extcommunity-list" keyword help string. */
20304#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20305#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20306
7336e101
SP
20307DEFUN (extcommunity_list_standard,
20308 bgp_extcommunity_list_standard_cmd,
a08032fe 20309 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20310 BGP_STR
718e3744 20311 EXTCOMMUNITY_LIST_STR
20312 "Extended Community list number (standard)\n"
718e3744 20313 "Specify standard extcommunity-list\n"
5bf15956 20314 "Community list name\n"
2f8cc0e5
DA
20315 "Sequence number of an entry\n"
20316 "Sequence number\n"
718e3744 20317 "Specify community to reject\n"
20318 "Specify community to accept\n"
20319 EXTCOMMUNITY_VAL_STR)
20320{
d62a17ae 20321 int style = EXTCOMMUNITY_LIST_STANDARD;
20322 int direct = 0;
20323 char *cl_number_or_name = NULL;
2f8cc0e5 20324 char *seq = NULL;
42f914d4 20325
d62a17ae 20326 int idx = 0;
7b9a4750 20327
d62a17ae 20328 argv_find(argv, argc, "(1-99)", &idx);
20329 argv_find(argv, argc, "WORD", &idx);
20330 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20331
a08032fe 20332 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20333 seq = argv[idx]->arg;
20334
d62a17ae 20335 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20336 : COMMUNITY_DENY;
20337 argv_find(argv, argc, "AA:NN", &idx);
20338 char *str = argv_concat(argv, argc, idx);
42f914d4 20339
2f8cc0e5 20340 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20341 direct, style);
42f914d4 20342
d62a17ae 20343 XFREE(MTYPE_TMP, str);
42f914d4 20344
d62a17ae 20345 if (ret < 0) {
20346 community_list_perror(vty, ret);
20347 return CMD_WARNING_CONFIG_FAILED;
20348 }
42f914d4 20349
d62a17ae 20350 return CMD_SUCCESS;
718e3744 20351}
20352
7336e101
SP
20353DEFUN (extcommunity_list_name_expanded,
20354 bgp_extcommunity_list_name_expanded_cmd,
a08032fe 20355 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20356 BGP_STR
20357 EXTCOMMUNITY_LIST_STR
5bf15956 20358 "Extended Community list number (expanded)\n"
718e3744 20359 "Specify expanded extcommunity-list\n"
20360 "Extended Community list name\n"
2f8cc0e5
DA
20361 "Sequence number of an entry\n"
20362 "Sequence number\n"
718e3744 20363 "Specify community to reject\n"
20364 "Specify community to accept\n"
20365 "An ordered list as a regular-expression\n")
20366{
d62a17ae 20367 int style = EXTCOMMUNITY_LIST_EXPANDED;
20368 int direct = 0;
20369 char *cl_number_or_name = NULL;
2f8cc0e5 20370 char *seq = NULL;
d62a17ae 20371 int idx = 0;
7336e101 20372
d62a17ae 20373 argv_find(argv, argc, "(100-500)", &idx);
20374 argv_find(argv, argc, "WORD", &idx);
20375 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20376
a08032fe 20377 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20378 seq = argv[idx]->arg;
20379
d62a17ae 20380 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20381 : COMMUNITY_DENY;
20382 argv_find(argv, argc, "LINE", &idx);
20383 char *str = argv_concat(argv, argc, idx);
42f914d4 20384
2f8cc0e5 20385 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20386 direct, style);
42f914d4 20387
d62a17ae 20388 XFREE(MTYPE_TMP, str);
42f914d4 20389
d62a17ae 20390 if (ret < 0) {
20391 community_list_perror(vty, ret);
20392 return CMD_WARNING_CONFIG_FAILED;
20393 }
42f914d4 20394
d62a17ae 20395 return CMD_SUCCESS;
718e3744 20396}
20397
7336e101
SP
20398DEFUN (no_extcommunity_list_standard_all,
20399 no_bgp_extcommunity_list_standard_all_cmd,
a08032fe 20400 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20401 NO_STR
20402 BGP_STR
20403 EXTCOMMUNITY_LIST_STR
813d4307 20404 "Extended Community list number (standard)\n"
718e3744 20405 "Specify standard extcommunity-list\n"
5bf15956 20406 "Community list name\n"
2f8cc0e5
DA
20407 "Sequence number of an entry\n"
20408 "Sequence number\n"
718e3744 20409 "Specify community to reject\n"
20410 "Specify community to accept\n"
20411 EXTCOMMUNITY_VAL_STR)
20412{
d62a17ae 20413 int style = EXTCOMMUNITY_LIST_STANDARD;
20414 int direct = 0;
20415 char *cl_number_or_name = NULL;
d4455c89 20416 char *str = NULL;
2f8cc0e5 20417 char *seq = NULL;
d62a17ae 20418 int idx = 0;
d4455c89 20419
a08032fe 20420 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20421 seq = argv[idx]->arg;
20422
20423 idx = 0;
d4455c89
DA
20424 argv_find(argv, argc, "permit", &idx);
20425 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
20426 if (idx) {
20427 direct = argv_find(argv, argc, "permit", &idx)
20428 ? COMMUNITY_PERMIT
20429 : COMMUNITY_DENY;
20430
20431 idx = 0;
20432 argv_find(argv, argc, "AA:NN", &idx);
20433 str = argv_concat(argv, argc, idx);
20434 }
20435
20436 idx = 0;
d62a17ae 20437 argv_find(argv, argc, "(1-99)", &idx);
20438 argv_find(argv, argc, "WORD", &idx);
20439 cl_number_or_name = argv[idx]->arg;
42f914d4 20440
d62a17ae 20441 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20442 seq, direct, style);
42f914d4 20443
d62a17ae 20444 XFREE(MTYPE_TMP, str);
42f914d4 20445
d62a17ae 20446 if (ret < 0) {
20447 community_list_perror(vty, ret);
20448 return CMD_WARNING_CONFIG_FAILED;
20449 }
42f914d4 20450
d62a17ae 20451 return CMD_SUCCESS;
718e3744 20452}
20453
d4455c89
DA
20454ALIAS(no_extcommunity_list_standard_all,
20455 no_bgp_extcommunity_list_standard_all_list_cmd,
20456 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 20457 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20458 "Extended Community list number (standard)\n"
20459 "Specify standard extcommunity-list\n"
20460 "Community list name\n")
20461
7336e101
SP
20462DEFUN (no_extcommunity_list_expanded_all,
20463 no_bgp_extcommunity_list_expanded_all_cmd,
a08032fe 20464 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20465 NO_STR
20466 BGP_STR
20467 EXTCOMMUNITY_LIST_STR
718e3744 20468 "Extended Community list number (expanded)\n"
718e3744 20469 "Specify expanded extcommunity-list\n"
5bf15956 20470 "Extended Community list name\n"
2f8cc0e5
DA
20471 "Sequence number of an entry\n"
20472 "Sequence number\n"
718e3744 20473 "Specify community to reject\n"
20474 "Specify community to accept\n"
20475 "An ordered list as a regular-expression\n")
20476{
d62a17ae 20477 int style = EXTCOMMUNITY_LIST_EXPANDED;
20478 int direct = 0;
20479 char *cl_number_or_name = NULL;
d4455c89 20480 char *str = NULL;
2f8cc0e5 20481 char *seq = NULL;
d62a17ae 20482 int idx = 0;
d4455c89 20483
a08032fe 20484 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20485 seq = argv[idx]->arg;
20486
20487 idx = 0;
d4455c89
DA
20488 argv_find(argv, argc, "permit", &idx);
20489 argv_find(argv, argc, "deny", &idx);
20490
20491 if (idx) {
20492 direct = argv_find(argv, argc, "permit", &idx)
20493 ? COMMUNITY_PERMIT
20494 : COMMUNITY_DENY;
20495
20496 idx = 0;
20497 argv_find(argv, argc, "LINE", &idx);
20498 str = argv_concat(argv, argc, idx);
20499 }
20500
20501 idx = 0;
d62a17ae 20502 argv_find(argv, argc, "(100-500)", &idx);
20503 argv_find(argv, argc, "WORD", &idx);
20504 cl_number_or_name = argv[idx]->arg;
42f914d4 20505
d62a17ae 20506 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20507 seq, direct, style);
42f914d4 20508
d62a17ae 20509 XFREE(MTYPE_TMP, str);
42f914d4 20510
d62a17ae 20511 if (ret < 0) {
20512 community_list_perror(vty, ret);
20513 return CMD_WARNING_CONFIG_FAILED;
20514 }
42f914d4 20515
d62a17ae 20516 return CMD_SUCCESS;
718e3744 20517}
20518
d4455c89
DA
20519ALIAS(no_extcommunity_list_expanded_all,
20520 no_bgp_extcommunity_list_expanded_all_list_cmd,
20521 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 20522 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20523 "Extended Community list number (expanded)\n"
20524 "Specify expanded extcommunity-list\n"
20525 "Extended Community list name\n")
20526
d62a17ae 20527static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 20528{
d62a17ae 20529 struct community_entry *entry;
718e3744 20530
d62a17ae 20531 for (entry = list->head; entry; entry = entry->next) {
20532 if (entry == list->head) {
20533 if (all_digit(list->name))
20534 vty_out(vty, "Extended community %s list %s\n",
20535 entry->style == EXTCOMMUNITY_LIST_STANDARD
20536 ? "standard"
20537 : "(expanded) access",
20538 list->name);
20539 else
20540 vty_out(vty,
20541 "Named extended community %s list %s\n",
20542 entry->style == EXTCOMMUNITY_LIST_STANDARD
20543 ? "standard"
20544 : "expanded",
20545 list->name);
20546 }
20547 if (entry->any)
20548 vty_out(vty, " %s\n",
20549 community_direct_str(entry->direct));
20550 else
20551 vty_out(vty, " %s %s\n",
20552 community_direct_str(entry->direct),
8d9b8ed9 20553 community_list_config_str(entry));
d62a17ae 20554 }
718e3744 20555}
20556
7336e101
SP
20557DEFUN (show_extcommunity_list,
20558 show_bgp_extcommunity_list_cmd,
20559 "show bgp extcommunity-list",
718e3744 20560 SHOW_STR
7336e101 20561 BGP_STR
718e3744 20562 "List extended-community list\n")
20563{
d62a17ae 20564 struct community_list *list;
20565 struct community_list_master *cm;
718e3744 20566
d62a17ae 20567 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20568 if (!cm)
20569 return CMD_SUCCESS;
718e3744 20570
d62a17ae 20571 for (list = cm->num.head; list; list = list->next)
20572 extcommunity_list_show(vty, list);
718e3744 20573
d62a17ae 20574 for (list = cm->str.head; list; list = list->next)
20575 extcommunity_list_show(vty, list);
718e3744 20576
d62a17ae 20577 return CMD_SUCCESS;
718e3744 20578}
20579
7336e101
SP
20580DEFUN (show_extcommunity_list_arg,
20581 show_bgp_extcommunity_list_arg_cmd,
960b69b9 20582 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
20583 SHOW_STR
20584 BGP_STR
718e3744 20585 "List extended-community list\n"
20586 "Extcommunity-list number\n"
960b69b9 20587 "Extcommunity-list name\n"
20588 "Detailed information on extcommunity-list\n")
718e3744 20589{
d62a17ae 20590 int idx_comm_list = 3;
20591 struct community_list *list;
718e3744 20592
e237b0d2 20593 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20594 EXTCOMMUNITY_LIST_MASTER);
20595 if (!list) {
20596 vty_out(vty, "%% Can't find extcommunity-list\n");
20597 return CMD_WARNING;
20598 }
718e3744 20599
d62a17ae 20600 extcommunity_list_show(vty, list);
718e3744 20601
d62a17ae 20602 return CMD_SUCCESS;
718e3744 20603}
6b0655a2 20604
718e3744 20605/* Display community-list and extcommunity-list configuration. */
d62a17ae 20606static int community_list_config_write(struct vty *vty)
20607{
20608 struct community_list *list;
20609 struct community_entry *entry;
20610 struct community_list_master *cm;
20611 int write = 0;
20612
20613 /* Community-list. */
20614 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20615
20616 for (list = cm->num.head; list; list = list->next)
20617 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20618 vty_out(vty,
20619 "bgp community-list %s seq %" PRId64 " %s %s\n",
20620 list->name, entry->seq,
d62a17ae 20621 community_direct_str(entry->direct),
20622 community_list_config_str(entry));
20623 write++;
20624 }
20625 for (list = cm->str.head; list; list = list->next)
20626 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20627 vty_out(vty,
20628 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20629 entry->style == COMMUNITY_LIST_STANDARD
20630 ? "standard"
20631 : "expanded",
2f8cc0e5
DA
20632 list->name, entry->seq,
20633 community_direct_str(entry->direct),
d62a17ae 20634 community_list_config_str(entry));
20635 write++;
20636 }
20637
20638 /* Extcommunity-list. */
20639 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20640
20641 for (list = cm->num.head; list; list = list->next)
20642 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20643 vty_out(vty,
20644 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20645 list->name, entry->seq,
20646 community_direct_str(entry->direct),
d62a17ae 20647 community_list_config_str(entry));
20648 write++;
20649 }
20650 for (list = cm->str.head; list; list = list->next)
20651 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20652 vty_out(vty,
6cde4b45 20653 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20654 entry->style == EXTCOMMUNITY_LIST_STANDARD
20655 ? "standard"
20656 : "expanded",
2f8cc0e5
DA
20657 list->name, entry->seq,
20658 community_direct_str(entry->direct),
d62a17ae 20659 community_list_config_str(entry));
20660 write++;
20661 }
20662
20663
20664 /* lcommunity-list. */
20665 cm = community_list_master_lookup(bgp_clist,
20666 LARGE_COMMUNITY_LIST_MASTER);
20667
20668 for (list = cm->num.head; list; list = list->next)
20669 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20670 vty_out(vty,
6cde4b45 20671 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20672 list->name, entry->seq,
20673 community_direct_str(entry->direct),
d62a17ae 20674 community_list_config_str(entry));
20675 write++;
20676 }
20677 for (list = cm->str.head; list; list = list->next)
20678 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20679 vty_out(vty,
6cde4b45 20680 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20681
d62a17ae 20682 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20683 ? "standard"
20684 : "expanded",
2f8cc0e5 20685 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20686 community_list_config_str(entry));
20687 write++;
20688 }
20689
20690 return write;
20691}
20692
612c2c15 20693static int community_list_config_write(struct vty *vty);
d62a17ae 20694static struct cmd_node community_list_node = {
f4b8291f 20695 .name = "community list",
62b346ee
DL
20696 .node = COMMUNITY_LIST_NODE,
20697 .prompt = "",
612c2c15 20698 .config_write = community_list_config_write,
718e3744 20699};
20700
d62a17ae 20701static void community_list_vty(void)
20702{
612c2c15 20703 install_node(&community_list_node);
d62a17ae 20704
20705 /* Community-list. */
7336e101
SP
20706 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20707 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20708 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20709 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20710 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20711 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20712 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20713 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20714
20715 /* Extcommunity-list. */
7336e101
SP
20716 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20717 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20718 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20719 install_element(CONFIG_NODE,
20720 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20721 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20722 install_element(CONFIG_NODE,
20723 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20724 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20725 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20726
20727 /* Large Community List */
7336e101 20728 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20729 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20730 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20731 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20732 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20733 install_element(CONFIG_NODE,
20734 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20735 install_element(CONFIG_NODE,
20736 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20737 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20738 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20739 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20740 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20741 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20742 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 20743}
ed0e57e3
DA
20744
20745static struct cmd_node community_alias_node = {
20746 .name = "community alias",
20747 .node = COMMUNITY_ALIAS_NODE,
20748 .prompt = "",
20749 .config_write = bgp_community_alias_write,
20750};
20751
20752void community_alias_vty(void)
20753{
20754 install_node(&community_alias_node);
20755
20756 /* Community-list. */
20757 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20758}