]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: implement nb-func to im/ex-port vrf-rib to vpn-rib (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
b9c7bc5a
PZ
9235ALIAS (af_label_vpn_export,
9236 af_no_label_vpn_export_cmd,
9237 "no label vpn export",
9238 NO_STR
9239 "label value for VRF\n"
9240 "Between current address-family and vpn\n"
9241 "For routes leaked from current address-family to vpn\n")
ddb5b488 9242
37a87b8f 9243DEFPY_YANG (af_nexthop_vpn_export,
b9c7bc5a 9244 af_nexthop_vpn_export_cmd,
8c85ca28 9245 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
b9c7bc5a 9246 NO_STR
ddb5b488 9247 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
9248 "Between current address-family and vpn\n"
9249 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9250 "IPv4 prefix\n"
9251 "IPv6 prefix\n")
9252{
37a87b8f 9253 char base_xpath[XPATH_MAXLEN];
ddb5b488 9254 afi_t afi;
37a87b8f
CS
9255 safi_t safi;
9256 int idx = 0;
ddb5b488
PZ
9257 struct prefix p;
9258
8c85ca28
QY
9259 if (!no) {
9260 if (!nexthop_su) {
9261 vty_out(vty, "%% Nexthop required\n");
9262 return CMD_WARNING_CONFIG_FAILED;
9263 }
8c85ca28 9264 if (!sockunion2hostprefix(nexthop_su, &p))
b9c7bc5a
PZ
9265 return CMD_WARNING_CONFIG_FAILED;
9266 }
ddb5b488 9267
37a87b8f
CS
9268 afi = bgp_node_afi(vty);
9269 safi = bgp_node_safi(vty);
ddb5b488 9270
37a87b8f
CS
9271 snprintf(
9272 base_xpath, sizeof(base_xpath),
9273 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9274 yang_afi_safi_value2identity(afi, safi),
9275 bgp_afi_safi_get_container_str(afi, safi));
ddb5b488 9276
37a87b8f
CS
9277 if (argv_find(argv, argc, "no", &idx))
9278 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9279 else
9280 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9281 nexthop_su_str);
ddb5b488 9282
37a87b8f
CS
9283 return nb_cli_apply_changes(vty, base_xpath);
9284}
69b07479 9285
37a87b8f
CS
9286void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9287 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9288{
9289 int indent = 2;
9290
9291 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9292 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9293}
9294
b9c7bc5a 9295static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 9296{
b9c7bc5a
PZ
9297 if (!strcmp(dstr, "import")) {
9298 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9299 } else if (!strcmp(dstr, "export")) {
9300 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9301 } else if (!strcmp(dstr, "both")) {
9302 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9303 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9304 } else {
9305 vty_out(vty, "%% direction parse error\n");
9306 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9307 }
ddb5b488
PZ
9308 return CMD_SUCCESS;
9309}
9310
b9c7bc5a
PZ
9311DEFPY (af_rt_vpn_imexport,
9312 af_rt_vpn_imexport_cmd,
9313 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9314 NO_STR
9315 "Specify route target list\n"
ddb5b488 9316 "Specify route target list\n"
b9c7bc5a
PZ
9317 "Between current address-family and vpn\n"
9318 "For routes leaked from vpn to current address-family: match any\n"
9319 "For routes leaked from current address-family to vpn: set\n"
9320 "both import: match any and export: set\n"
ddb5b488
PZ
9321 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9322{
9323 VTY_DECLVAR_CONTEXT(bgp, bgp);
9324 int ret;
9325 struct ecommunity *ecom = NULL;
9326 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
ddb5b488
PZ
9327 vpn_policy_direction_t dir;
9328 afi_t afi;
9329 int idx = 0;
c6423c31 9330 bool yes = true;
ddb5b488 9331
b9c7bc5a 9332 if (argv_find(argv, argc, "no", &idx))
c6423c31 9333 yes = false;
b9c7bc5a 9334
0ca70ba5 9335 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9336 if (afi == AFI_MAX)
9337 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 9338
b9c7bc5a 9339 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
9340 if (ret != CMD_SUCCESS)
9341 return ret;
9342
b9c7bc5a
PZ
9343 if (yes) {
9344 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9345 vty_out(vty, "%% Missing RTLIST\n");
9346 return CMD_WARNING_CONFIG_FAILED;
9347 }
c6423c31 9348 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
b9c7bc5a
PZ
9349 if (ret != CMD_SUCCESS) {
9350 return ret;
9351 }
ddb5b488
PZ
9352 }
9353
69b07479
DS
9354 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9355 if (!dodir[dir])
ddb5b488 9356 continue;
ddb5b488 9357
69b07479 9358 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9359
69b07479
DS
9360 if (yes) {
9361 if (bgp->vpn_policy[afi].rtlist[dir])
9362 ecommunity_free(
9363 &bgp->vpn_policy[afi].rtlist[dir]);
9364 bgp->vpn_policy[afi].rtlist[dir] =
9365 ecommunity_dup(ecom);
9366 } else {
9367 if (bgp->vpn_policy[afi].rtlist[dir])
9368 ecommunity_free(
9369 &bgp->vpn_policy[afi].rtlist[dir]);
9370 bgp->vpn_policy[afi].rtlist[dir] = NULL;
ddb5b488 9371 }
69b07479
DS
9372
9373 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
ddb5b488 9374 }
69b07479 9375
d555f3e9
PZ
9376 if (ecom)
9377 ecommunity_free(&ecom);
ddb5b488
PZ
9378
9379 return CMD_SUCCESS;
9380}
9381
b9c7bc5a
PZ
9382ALIAS (af_rt_vpn_imexport,
9383 af_no_rt_vpn_imexport_cmd,
9384 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
9385 NO_STR
9386 "Specify route target list\n"
b9c7bc5a
PZ
9387 "Specify route target list\n"
9388 "Between current address-family and vpn\n"
9389 "For routes leaked from vpn to current address-family\n"
9390 "For routes leaked from current address-family to vpn\n"
9391 "both import and export\n")
9392
37a87b8f 9393DEFPY_YANG (af_route_map_vpn_imexport,
b9c7bc5a
PZ
9394 af_route_map_vpn_imexport_cmd,
9395/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9396 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9397 NO_STR
ddb5b488 9398 "Specify route map\n"
b9c7bc5a
PZ
9399 "Between current address-family and vpn\n"
9400 "For routes leaked from vpn to current address-family\n"
9401 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
9402 "name of route-map\n")
9403{
37a87b8f 9404 char base_xpath[XPATH_MAXLEN];
ddb5b488 9405 afi_t afi;
37a87b8f 9406 safi_t safi;
ddb5b488 9407 int idx = 0;
ddb5b488 9408
37a87b8f
CS
9409 afi = bgp_node_afi(vty);
9410 safi = bgp_node_safi(vty);
ddb5b488 9411
37a87b8f
CS
9412 snprintf(
9413 base_xpath, sizeof(base_xpath),
9414 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9415 yang_afi_safi_value2identity(afi, safi),
9416 bgp_afi_safi_get_container_str(afi, safi));
9417
9418 if (argv_find(argv, argc, "no", &idx)) {
9419 if (!strcmp(direction_str, "import"))
9420 nb_cli_enqueue_change(vty, "./rmap-import",
9421 NB_OP_DESTROY, NULL);
9422 else if (!strcmp(direction_str, "export"))
9423 nb_cli_enqueue_change(vty, "./rmap-export",
9424 NB_OP_DESTROY, NULL);
9425 } else {
9426 if (!strcmp(direction_str, "import"))
9427 nb_cli_enqueue_change(vty, "./rmap-import",
9428 NB_OP_MODIFY, rmap_str);
9429 if (!strcmp(direction_str, "export"))
9430 nb_cli_enqueue_change(vty, "./rmap-export",
9431 NB_OP_MODIFY, rmap_str);
9432 }
9433 return nb_cli_apply_changes(vty, base_xpath);
9434}
ddb5b488 9435
37a87b8f
CS
9436void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9437 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9438{
9439 int indent = 2;
ddb5b488 9440
37a87b8f
CS
9441 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9442 yang_dnode_get_string(dnode, NULL));
9443}
69b07479 9444
37a87b8f
CS
9445void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9446 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9447{
9448 int indent = 2;
ddb5b488 9449
37a87b8f
CS
9450 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9451 yang_dnode_get_string(dnode, NULL));
ddb5b488
PZ
9452}
9453
b9c7bc5a
PZ
9454ALIAS (af_route_map_vpn_imexport,
9455 af_no_route_map_vpn_imexport_cmd,
9456 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
9457 NO_STR
9458 "Specify route map\n"
b9c7bc5a
PZ
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
bb4f6190 9463DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
ae6a6fb4 9464 "import vrf route-map RMAP$rmap_str",
bb4f6190
DS
9465 "Import routes from another VRF\n"
9466 "Vrf routes being filtered\n"
9467 "Specify route map\n"
9468 "name of route-map\n")
9469{
9470 VTY_DECLVAR_CONTEXT(bgp, bgp);
bb4f6190
DS
9471 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9472 afi_t afi;
bb4f6190
DS
9473 struct bgp *bgp_default;
9474
0ca70ba5 9475 afi = vpn_policy_getafi(vty, bgp, true);
69b07479
DS
9476 if (afi == AFI_MAX)
9477 return CMD_WARNING_CONFIG_FAILED;
bb4f6190
DS
9478
9479 bgp_default = bgp_get_default();
9480 if (!bgp_default) {
9481 int32_t ret;
9482 as_t as = bgp->as;
9483
9484 /* Auto-create assuming the same AS */
5d5393b9
DL
9485 ret = bgp_get_vty(&bgp_default, &as, NULL,
9486 BGP_INSTANCE_TYPE_DEFAULT);
bb4f6190
DS
9487
9488 if (ret) {
9489 vty_out(vty,
9490 "VRF default is not configured as a bgp instance\n");
9491 return CMD_WARNING;
9492 }
9493 }
9494
69b07479 9495 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
bb4f6190 9496
ae6a6fb4
DS
9497 if (bgp->vpn_policy[afi].rmap_name[dir])
9498 XFREE(MTYPE_ROUTE_MAP_NAME,
9499 bgp->vpn_policy[afi].rmap_name[dir]);
9500 bgp->vpn_policy[afi].rmap_name[dir] =
9501 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9502 bgp->vpn_policy[afi].rmap[dir] =
9503 route_map_lookup_warn_noexist(vty, rmap_str);
9504 if (!bgp->vpn_policy[afi].rmap[dir])
9505 return CMD_SUCCESS;
9506
9507 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9508 BGP_CONFIG_VRF_TO_VRF_IMPORT);
bb4f6190 9509
69b07479
DS
9510 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9511
bb4f6190
DS
9512 return CMD_SUCCESS;
9513}
9514
ae6a6fb4
DS
9515DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9516 "no import vrf route-map [RMAP$rmap_str]",
bb4f6190
DS
9517 NO_STR
9518 "Import routes from another VRF\n"
9519 "Vrf routes being filtered\n"
ae6a6fb4
DS
9520 "Specify route map\n"
9521 "name of route-map\n")
9522{
9523 VTY_DECLVAR_CONTEXT(bgp, bgp);
9524 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9525 afi_t afi;
9526
9527 afi = vpn_policy_getafi(vty, bgp, true);
9528 if (afi == AFI_MAX)
9529 return CMD_WARNING_CONFIG_FAILED;
9530
9531 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9532
9533 if (bgp->vpn_policy[afi].rmap_name[dir])
9534 XFREE(MTYPE_ROUTE_MAP_NAME,
9535 bgp->vpn_policy[afi].rmap_name[dir]);
9536 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9537 bgp->vpn_policy[afi].rmap[dir] = NULL;
9538
9539 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9540 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9541 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9542
9543 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9544
9545 return CMD_SUCCESS;
9546}
bb4f6190 9547
37a87b8f
CS
9548DEFPY_YANG(bgp_imexport_vrf,
9549 bgp_imexport_vrf_cmd,
9550 "[no] import vrf VIEWVRFNAME$import_name",
9551 NO_STR
9552 "Import routes from another VRF\n"
9553 "VRF to import from\n"
9554 "The name of the VRF\n")
12a844a5 9555{
37a87b8f 9556 char base_xpath[XPATH_MAXLEN];
12a844a5
DS
9557 safi_t safi;
9558 afi_t afi;
37a87b8f 9559 int32_t idx = 0;
12a844a5 9560
867f0cca 9561 if (import_name == NULL) {
9562 vty_out(vty, "%% Missing import name\n");
9563 return CMD_WARNING;
9564 }
9565
ae6a6fb4
DS
9566 if (strcmp(import_name, "route-map") == 0) {
9567 vty_out(vty, "%% Must include route-map name\n");
9568 return CMD_WARNING;
9569 }
9570
37a87b8f 9571 afi = bgp_node_afi(vty);
12a844a5
DS
9572 safi = bgp_node_safi(vty);
9573
37a87b8f
CS
9574 snprintf(
9575 base_xpath, sizeof(base_xpath),
9576 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9577 yang_afi_safi_value2identity(afi, safi),
9578 bgp_afi_safi_get_container_str(afi, safi), import_name);
25679caa 9579
37a87b8f
CS
9580 if (argv_find(argv, argc, "no", &idx))
9581 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9582 else
9583 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
12a844a5 9584
37a87b8f
CS
9585 return nb_cli_apply_changes(vty, base_xpath);
9586}
12a844a5 9587
37a87b8f
CS
9588void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9589 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9590{
9591 vty_out(vty, " import vrf %s\n",
9592 yang_dnode_get_string(dnode, "./vrf"));
12a844a5
DS
9593}
9594
b9c7bc5a 9595/* This command is valid only in a bgp vrf instance or the default instance */
37a87b8f 9596DEFPY_YANG (bgp_imexport_vpn,
b9c7bc5a
PZ
9597 bgp_imexport_vpn_cmd,
9598 "[no] <import|export>$direction_str vpn",
c7109e09
PZ
9599 NO_STR
9600 "Import routes to this address-family\n"
9601 "Export routes from this address-family\n"
9602 "to/from default instance VPN RIB\n")
ddb5b488 9603{
37a87b8f 9604 char base_xpath[XPATH_MAXLEN];
b9c7bc5a 9605 safi_t safi;
37a87b8f
CS
9606 afi_t afi;
9607 int32_t idx = 0;
ddb5b488 9608
b9c7bc5a
PZ
9609 afi = bgp_node_afi(vty);
9610 safi = bgp_node_safi(vty);
ddb5b488 9611
b9c7bc5a 9612 if (!strcmp(direction_str, "import")) {
37a87b8f
CS
9613 snprintf(
9614 base_xpath, sizeof(base_xpath),
9615 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9616 yang_afi_safi_value2identity(afi, safi),
9617 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a 9618 } else if (!strcmp(direction_str, "export")) {
37a87b8f
CS
9619 snprintf(
9620 base_xpath, sizeof(base_xpath),
9621 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9622 yang_afi_safi_value2identity(afi, safi),
9623 bgp_afi_safi_get_container_str(afi, safi));
b9c7bc5a
PZ
9624 } else {
9625 vty_out(vty, "%% unknown direction %s\n", direction_str);
9626 return CMD_WARNING_CONFIG_FAILED;
9627 }
9628
37a87b8f
CS
9629 if (argv_find(argv, argc, "no", &idx))
9630 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9631 else
9632 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
ddb5b488 9633
37a87b8f
CS
9634 return nb_cli_apply_changes(vty, base_xpath);
9635}
ddb5b488 9636
37a87b8f
CS
9637void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9638 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9639{
9640 if (yang_dnode_get_bool(dnode, NULL))
9641 vty_out(vty, " import vpn\n");
9642}
9643
9644void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9645 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9646{
9647 if (yang_dnode_get_bool(dnode, NULL))
9648 vty_out(vty, " export vpn\n");
ddb5b488
PZ
9649}
9650
301ad80a
PG
9651DEFPY (af_routetarget_import,
9652 af_routetarget_import_cmd,
9a659715 9653 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
301ad80a
PG
9654 NO_STR
9655 "Specify route target list\n"
9656 "Specify route target list\n"
9a659715
PG
9657 "Specify route target list\n"
9658 "Specify route target list\n"
301ad80a
PG
9659 "Flow-spec redirect type route target\n"
9660 "Import routes to this address-family\n"
9a659715 9661 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
301ad80a
PG
9662{
9663 VTY_DECLVAR_CONTEXT(bgp, bgp);
9664 int ret;
9665 struct ecommunity *ecom = NULL;
301ad80a 9666 afi_t afi;
9a659715 9667 int idx = 0, idx_unused = 0;
c6423c31
PG
9668 bool yes = true;
9669 bool rt6 = false;
301ad80a
PG
9670
9671 if (argv_find(argv, argc, "no", &idx))
c6423c31 9672 yes = false;
301ad80a 9673
9a659715
PG
9674 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9675 argv_find(argv, argc, "route-target6", &idx_unused))
c6423c31 9676 rt6 = true;
301ad80a 9677
0ca70ba5 9678 afi = vpn_policy_getafi(vty, bgp, false);
69b07479
DS
9679 if (afi == AFI_MAX)
9680 return CMD_WARNING_CONFIG_FAILED;
9681
9a659715
PG
9682 if (rt6 && afi != AFI_IP6)
9683 return CMD_WARNING_CONFIG_FAILED;
9684
301ad80a
PG
9685 if (yes) {
9686 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9687 vty_out(vty, "%% Missing RTLIST\n");
9688 return CMD_WARNING_CONFIG_FAILED;
9689 }
9a659715 9690 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
301ad80a
PG
9691 if (ret != CMD_SUCCESS)
9692 return ret;
9693 }
69b07479
DS
9694
9695 if (yes) {
9696 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9697 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9698 .import_redirect_rtlist);
69b07479
DS
9699 bgp->vpn_policy[afi].import_redirect_rtlist =
9700 ecommunity_dup(ecom);
9701 } else {
9702 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9703 ecommunity_free(&bgp->vpn_policy[afi]
301ad80a 9704 .import_redirect_rtlist);
69b07479 9705 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
301ad80a 9706 }
69b07479 9707
301ad80a
PG
9708 if (ecom)
9709 ecommunity_free(&ecom);
9710
9711 return CMD_SUCCESS;
9712}
9713
37a87b8f
CS
9714void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9715 struct lyd_node *dnode,
9716 bool show_defaults)
9717{
9718 const char *af_name;
9719 afi_t afi;
9720 safi_t safi;
9721
9722 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9723 yang_afi_safi_identity2value(af_name, &afi, &safi);
9724
9725 vty_out(vty, " !\n address-family ");
9726 if (afi == AFI_IP) {
9727 if (safi == SAFI_UNICAST)
9728 vty_out(vty, "ipv4 unicast");
9729 else if (safi == SAFI_LABELED_UNICAST)
9730 vty_out(vty, "ipv4 labeled-unicast");
9731 else if (safi == SAFI_MULTICAST)
9732 vty_out(vty, "ipv4 multicast");
9733 else if (safi == SAFI_MPLS_VPN)
9734 vty_out(vty, "ipv4 vpn");
9735 else if (safi == SAFI_ENCAP)
9736 vty_out(vty, "ipv4 encap");
9737 else if (safi == SAFI_FLOWSPEC)
9738 vty_out(vty, "ipv4 flowspec");
9739 } else if (afi == AFI_IP6) {
9740 if (safi == SAFI_UNICAST)
9741 vty_out(vty, "ipv6 unicast");
9742 else if (safi == SAFI_LABELED_UNICAST)
9743 vty_out(vty, "ipv6 labeled-unicast");
9744 else if (safi == SAFI_MULTICAST)
9745 vty_out(vty, "ipv6 multicast");
9746 else if (safi == SAFI_MPLS_VPN)
9747 vty_out(vty, "ipv6 vpn");
9748 else if (safi == SAFI_ENCAP)
9749 vty_out(vty, "ipv6 encap");
9750 else if (safi == SAFI_FLOWSPEC)
9751 vty_out(vty, "ipv6 flowspec");
9752 } else if (afi == AFI_L2VPN) {
9753 if (safi == SAFI_EVPN)
9754 vty_out(vty, "l2vpn evpn");
9755 }
9756 vty_out(vty, "\n");
9757}
9758
505e5056 9759DEFUN_NOSH (address_family_ipv4_safi,
7c40bf39 9760 address_family_ipv4_safi_cmd,
9761 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9762 "Enter Address Family command mode\n"
9763 "Address Family\n"
9764 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 9765{
f51bae9c 9766
37a87b8f
CS
9767 safi_t safi = SAFI_UNICAST;
9768 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9769 const char *vrf_name = NULL;
9770
d62a17ae 9771 if (argc == 3) {
37a87b8f
CS
9772 safi = bgp_vty_safi_from_str(argv[2]->text);
9773
9774 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9775 VTY_CURR_XPATH);
9776 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9777 "control-plane-protocol");
9778 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9779
9780 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9781 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9782 && safi != SAFI_EVPN) {
31947174
MK
9783 vty_out(vty,
9784 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9785 return CMD_WARNING_CONFIG_FAILED;
9786 }
37a87b8f
CS
9787 }
9788 vty->node = bgp_node_type(AFI_IP, safi);
718e3744 9789
d62a17ae 9790 return CMD_SUCCESS;
718e3744 9791}
9792
505e5056 9793DEFUN_NOSH (address_family_ipv6_safi,
7c40bf39 9794 address_family_ipv6_safi_cmd,
9795 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9796 "Enter Address Family command mode\n"
9797 "Address Family\n"
9798 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 9799{
37a87b8f
CS
9800 safi_t safi = SAFI_UNICAST;
9801 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9802 const char *vrf_name = NULL;
9803
d62a17ae 9804 if (argc == 3) {
37a87b8f
CS
9805 safi = bgp_vty_safi_from_str(argv[2]->text);
9806 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9807 VTY_CURR_XPATH);
9808 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9809 "control-plane-protocol");
9810 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9811
9812 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
a4d82a8a 9813 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 9814 && safi != SAFI_EVPN) {
31947174
MK
9815 vty_out(vty,
9816 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
9817 return CMD_WARNING_CONFIG_FAILED;
9818 }
37a87b8f
CS
9819 }
9820 vty->node = bgp_node_type(AFI_IP6, safi);
25ffbdc1 9821
d62a17ae 9822 return CMD_SUCCESS;
25ffbdc1 9823}
718e3744 9824
d6902373 9825#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 9826DEFUN_NOSH (address_family_vpnv4,
718e3744 9827 address_family_vpnv4_cmd,
8334fd5a 9828 "address-family vpnv4 [unicast]",
718e3744 9829 "Enter Address Family command mode\n"
8c3deaae 9830 "Address Family\n"
3a2d747c 9831 "Address Family modifier\n")
718e3744 9832{
d62a17ae 9833 vty->node = BGP_VPNV4_NODE;
9834 return CMD_SUCCESS;
718e3744 9835}
9836
505e5056 9837DEFUN_NOSH (address_family_vpnv6,
8ecd3266 9838 address_family_vpnv6_cmd,
8334fd5a 9839 "address-family vpnv6 [unicast]",
8ecd3266 9840 "Enter Address Family command mode\n"
8c3deaae 9841 "Address Family\n"
3a2d747c 9842 "Address Family modifier\n")
8ecd3266 9843{
d62a17ae 9844 vty->node = BGP_VPNV6_NODE;
9845 return CMD_SUCCESS;
8ecd3266 9846}
64e4a6c5 9847#endif /* KEEP_OLD_VPN_COMMANDS */
d6902373 9848
505e5056 9849DEFUN_NOSH (address_family_evpn,
4e0b7b6d 9850 address_family_evpn_cmd,
7111c1a0 9851 "address-family l2vpn evpn",
4e0b7b6d 9852 "Enter Address Family command mode\n"
7111c1a0
QY
9853 "Address Family\n"
9854 "Address Family modifier\n")
4e0b7b6d 9855{
2131d5cf 9856 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 9857 vty->node = BGP_EVPN_NODE;
9858 return CMD_SUCCESS;
4e0b7b6d
PG
9859}
9860
bfaab44d
HS
9861DEFUN_NOSH (bgp_segment_routing_srv6,
9862 bgp_segment_routing_srv6_cmd,
9863 "segment-routing srv6",
9864 "Segment-Routing configuration\n"
9865 "Segment-Routing SRv6 configuration\n")
9866{
9867 VTY_DECLVAR_CONTEXT(bgp, bgp);
9868 vty->node = BGP_SRV6_NODE;
9869 return CMD_SUCCESS;
9870}
9871
505e5056 9872DEFUN_NOSH (exit_address_family,
718e3744 9873 exit_address_family_cmd,
9874 "exit-address-family",
9875 "Exit from Address Family configuration mode\n")
9876{
d62a17ae 9877 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9878 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9879 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9880 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
925bf671
PG
9881 || vty->node == BGP_EVPN_NODE
9882 || vty->node == BGP_FLOWSPECV4_NODE
9883 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 9884 vty->node = BGP_NODE;
9885 return CMD_SUCCESS;
718e3744 9886}
6b0655a2 9887
37a87b8f
CS
9888void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9889 struct lyd_node *dnode
9890 __attribute__((__unused__)))
9891{
9892 vty_out(vty, " exit-address-family\n");
9893}
9894
8ad7271d 9895/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 9896static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9897 const char *ip_str, afi_t afi, safi_t safi,
9898 struct prefix_rd *prd)
9899{
9900 int ret;
9901 struct prefix match;
9bcb3eef
DS
9902 struct bgp_dest *dest;
9903 struct bgp_dest *rm;
d62a17ae 9904 struct bgp *bgp;
9905 struct bgp_table *table;
9906 struct bgp_table *rib;
9907
9908 /* BGP structure lookup. */
9909 if (view_name) {
9910 bgp = bgp_lookup_by_name(view_name);
9911 if (bgp == NULL) {
9912 vty_out(vty, "%% Can't find BGP instance %s\n",
9913 view_name);
9914 return CMD_WARNING;
9915 }
9916 } else {
9917 bgp = bgp_get_default();
9918 if (bgp == NULL) {
9919 vty_out(vty, "%% No BGP process is configured\n");
9920 return CMD_WARNING;
9921 }
9922 }
9923
9924 /* Check IP address argument. */
9925 ret = str2prefix(ip_str, &match);
9926 if (!ret) {
9927 vty_out(vty, "%% address is malformed\n");
9928 return CMD_WARNING;
9929 }
9930
9931 match.family = afi2family(afi);
9932 rib = bgp->rib[afi][safi];
9933
9934 if (safi == SAFI_MPLS_VPN) {
9bcb3eef
DS
9935 for (dest = bgp_table_top(rib); dest;
9936 dest = bgp_route_next(dest)) {
9937 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9938
9bcb3eef 9939 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
d62a17ae 9940 continue;
9941
9bcb3eef 9942 table = bgp_dest_get_bgp_table_info(dest);
b54892e0
DS
9943 if (table == NULL)
9944 continue;
9945
9946 if ((rm = bgp_node_match(table, &match)) != NULL) {
9947 const struct prefix *rm_p =
9bcb3eef 9948 bgp_dest_get_prefix(rm);
b54892e0
DS
9949
9950 if (rm_p->prefixlen == match.prefixlen) {
9951 SET_FLAG(rm->flags,
9952 BGP_NODE_USER_CLEAR);
9953 bgp_process(bgp, rm, afi, safi);
d62a17ae 9954 }
9bcb3eef 9955 bgp_dest_unlock_node(rm);
d62a17ae 9956 }
9957 }
9958 } else {
9bcb3eef
DS
9959 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9960 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
b54892e0 9961
9bcb3eef
DS
9962 if (dest_p->prefixlen == match.prefixlen) {
9963 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9964 bgp_process(bgp, dest, afi, safi);
d62a17ae 9965 }
9bcb3eef 9966 bgp_dest_unlock_node(dest);
d62a17ae 9967 }
9968 }
9969
9970 return CMD_SUCCESS;
8ad7271d
DS
9971}
9972
b09b5ae0 9973/* one clear bgp command to rule them all */
718e3744 9974DEFUN (clear_ip_bgp_all,
9975 clear_ip_bgp_all_cmd,
453c92f6 9976 "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 9977 CLEAR_STR
9978 IP_STR
9979 BGP_STR
838758ac 9980 BGP_INSTANCE_HELP_STR
510afcd6 9981 BGP_AFI_HELP_STR
fd5e7b70 9982 "Address Family\n"
510afcd6 9983 BGP_SAFI_WITH_LABEL_HELP_STR
fd5e7b70 9984 "Address Family modifier\n"
b09b5ae0 9985 "Clear all peers\n"
453c92f6 9986 "BGP IPv4 neighbor to clear\n"
a80beece 9987 "BGP IPv6 neighbor to clear\n"
838758ac 9988 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
9989 "Clear peers with the AS number\n"
9990 "Clear all external peers\n"
718e3744 9991 "Clear all members of peer-group\n"
b09b5ae0 9992 "BGP peer-group name\n"
b09b5ae0
DW
9993 BGP_SOFT_STR
9994 BGP_SOFT_IN_STR
b09b5ae0
DW
9995 BGP_SOFT_OUT_STR
9996 BGP_SOFT_IN_STR
9997 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 9998 BGP_SOFT_OUT_STR)
718e3744 9999{
d62a17ae 10000 char *vrf = NULL;
10001
dc912615
DS
10002 afi_t afi = AFI_UNSPEC;
10003 safi_t safi = SAFI_UNSPEC;
d62a17ae 10004 enum clear_sort clr_sort = clear_peer;
10005 enum bgp_clear_type clr_type;
10006 char *clr_arg = NULL;
10007
10008 int idx = 0;
ff8a8a7a
CS
10009 char errmsg[BUFSIZ] = {'\0'};
10010 int ret;
d62a17ae 10011
10012 /* clear [ip] bgp */
10013 if (argv_find(argv, argc, "ip", &idx))
10014 afi = AFI_IP;
10015
9a8bdf1c
PG
10016 /* [<vrf> VIEWVRFNAME] */
10017 if (argv_find(argv, argc, "vrf", &idx)) {
10018 vrf = argv[idx + 1]->arg;
10019 idx += 2;
10020 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10021 vrf = NULL;
10022 } else if (argv_find(argv, argc, "view", &idx)) {
10023 /* [<view> VIEWVRFNAME] */
d62a17ae 10024 vrf = argv[idx + 1]->arg;
10025 idx += 2;
10026 }
d62a17ae 10027 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10028 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
10029 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10030
d7b9898c 10031 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
d62a17ae 10032 if (argv_find(argv, argc, "*", &idx)) {
10033 clr_sort = clear_all;
10034 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
10035 clr_sort = clear_peer;
10036 clr_arg = argv[idx]->arg;
10037 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
10038 clr_sort = clear_peer;
10039 clr_arg = argv[idx]->arg;
10040 } else if (argv_find(argv, argc, "peer-group", &idx)) {
10041 clr_sort = clear_group;
10042 idx++;
10043 clr_arg = argv[idx]->arg;
d7b9898c 10044 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
d62a17ae 10045 clr_sort = clear_peer;
10046 clr_arg = argv[idx]->arg;
8fa7d444
DS
10047 } else if (argv_find(argv, argc, "WORD", &idx)) {
10048 clr_sort = clear_peer;
10049 clr_arg = argv[idx]->arg;
d62a17ae 10050 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
10051 clr_sort = clear_as;
10052 clr_arg = argv[idx]->arg;
10053 } else if (argv_find(argv, argc, "external", &idx)) {
10054 clr_sort = clear_external;
10055 }
10056
10057 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
10058 if (argv_find(argv, argc, "soft", &idx)) {
10059 if (argv_find(argv, argc, "in", &idx)
10060 || argv_find(argv, argc, "out", &idx))
10061 clr_type = strmatch(argv[idx]->text, "in")
10062 ? BGP_CLEAR_SOFT_IN
10063 : BGP_CLEAR_SOFT_OUT;
10064 else
10065 clr_type = BGP_CLEAR_SOFT_BOTH;
10066 } else if (argv_find(argv, argc, "in", &idx)) {
10067 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
10068 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
10069 : BGP_CLEAR_SOFT_IN;
10070 } else if (argv_find(argv, argc, "out", &idx)) {
10071 clr_type = BGP_CLEAR_SOFT_OUT;
10072 } else
10073 clr_type = BGP_CLEAR_SOFT_NONE;
10074
ff8a8a7a
CS
10075 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
10076 sizeof(errmsg));
10077 if (ret != NB_OK)
10078 vty_out(vty, "Error description: %s\n", errmsg);
10079
10080 return ret;
838758ac 10081}
01080f7c 10082
8ad7271d
DS
10083DEFUN (clear_ip_bgp_prefix,
10084 clear_ip_bgp_prefix_cmd,
18c57037 10085 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
10086 CLEAR_STR
10087 IP_STR
10088 BGP_STR
838758ac 10089 BGP_INSTANCE_HELP_STR
8ad7271d 10090 "Clear bestpath and re-advertise\n"
0c7b1b01 10091 "IPv4 prefix\n")
8ad7271d 10092{
d62a17ae 10093 char *vrf = NULL;
10094 char *prefix = NULL;
8ad7271d 10095
d62a17ae 10096 int idx = 0;
01080f7c 10097
d62a17ae 10098 /* [<view|vrf> VIEWVRFNAME] */
9a8bdf1c
PG
10099 if (argv_find(argv, argc, "vrf", &idx)) {
10100 vrf = argv[idx + 1]->arg;
10101 idx += 2;
10102 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10103 vrf = NULL;
10104 } else if (argv_find(argv, argc, "view", &idx)) {
10105 /* [<view> VIEWVRFNAME] */
10106 vrf = argv[idx + 1]->arg;
10107 idx += 2;
10108 }
0c7b1b01 10109
d62a17ae 10110 prefix = argv[argc - 1]->arg;
8ad7271d 10111
d62a17ae 10112 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 10113}
8ad7271d 10114
b09b5ae0
DW
10115DEFUN (clear_bgp_ipv6_safi_prefix,
10116 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 10117 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10118 CLEAR_STR
3a2d747c 10119 IP_STR
718e3744 10120 BGP_STR
8c3deaae 10121 "Address Family\n"
46f296b4 10122 BGP_SAFI_HELP_STR
b09b5ae0 10123 "Clear bestpath and re-advertise\n"
0c7b1b01 10124 "IPv6 prefix\n")
718e3744 10125{
9b475e76
PG
10126 int idx_safi = 0;
10127 int idx_ipv6_prefix = 0;
10128 safi_t safi = SAFI_UNICAST;
10129 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10130 argv[idx_ipv6_prefix]->arg : NULL;
10131
10132 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 10133 return bgp_clear_prefix(
9b475e76
PG
10134 vty, NULL, prefix, AFI_IP6,
10135 safi, NULL);
838758ac 10136}
01080f7c 10137
b09b5ae0
DW
10138DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10139 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 10140 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 10141 CLEAR_STR
3a2d747c 10142 IP_STR
718e3744 10143 BGP_STR
838758ac 10144 BGP_INSTANCE_HELP_STR
8c3deaae 10145 "Address Family\n"
46f296b4 10146 BGP_SAFI_HELP_STR
b09b5ae0 10147 "Clear bestpath and re-advertise\n"
0c7b1b01 10148 "IPv6 prefix\n")
718e3744 10149{
9b475e76 10150 int idx_safi = 0;
9a8bdf1c 10151 int idx_vrfview = 0;
9b475e76
PG
10152 int idx_ipv6_prefix = 0;
10153 safi_t safi = SAFI_UNICAST;
10154 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10155 argv[idx_ipv6_prefix]->arg : NULL;
9a8bdf1c 10156 char *vrfview = NULL;
9b475e76 10157
9a8bdf1c
PG
10158 /* [<view|vrf> VIEWVRFNAME] */
10159 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10160 vrfview = argv[idx_vrfview + 1]->arg;
10161 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10162 vrfview = NULL;
10163 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10164 /* [<view> VIEWVRFNAME] */
10165 vrfview = argv[idx_vrfview + 1]->arg;
10166 }
9b475e76
PG
10167 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10168
d62a17ae 10169 return bgp_clear_prefix(
9b475e76
PG
10170 vty, vrfview, prefix,
10171 AFI_IP6, safi, NULL);
718e3744 10172}
10173
b09b5ae0
DW
10174DEFUN (show_bgp_views,
10175 show_bgp_views_cmd,
d6e3c605 10176 "show [ip] bgp views",
b09b5ae0 10177 SHOW_STR
d6e3c605 10178 IP_STR
01080f7c 10179 BGP_STR
b09b5ae0 10180 "Show the defined BGP views\n")
01080f7c 10181{
d62a17ae 10182 struct list *inst = bm->bgp;
10183 struct listnode *node;
10184 struct bgp *bgp;
01080f7c 10185
d62a17ae 10186 vty_out(vty, "Defined BGP views:\n");
10187 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10188 /* Skip VRFs. */
10189 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10190 continue;
10191 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10192 bgp->as);
10193 }
e52702f2 10194
d62a17ae 10195 return CMD_SUCCESS;
e0081f70
ML
10196}
10197
8386ac43 10198DEFUN (show_bgp_vrfs,
10199 show_bgp_vrfs_cmd,
d6e3c605 10200 "show [ip] bgp vrfs [json]",
8386ac43 10201 SHOW_STR
d6e3c605 10202 IP_STR
8386ac43 10203 BGP_STR
10204 "Show BGP VRFs\n"
9973d184 10205 JSON_STR)
8386ac43 10206{
fe1dc5a3 10207 char buf[ETHER_ADDR_STRLEN];
d62a17ae 10208 struct list *inst = bm->bgp;
10209 struct listnode *node;
10210 struct bgp *bgp;
9f049418 10211 bool uj = use_json(argc, argv);
d62a17ae 10212 json_object *json = NULL;
10213 json_object *json_vrfs = NULL;
10214 int count = 0;
d62a17ae 10215
d62a17ae 10216 if (uj) {
10217 json = json_object_new_object();
10218 json_vrfs = json_object_new_object();
10219 }
10220
10221 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10222 const char *name, *type;
10223 struct peer *peer;
7fe96307 10224 struct listnode *node2, *nnode2;
d62a17ae 10225 int peers_cfg, peers_estb;
10226 json_object *json_vrf = NULL;
d62a17ae 10227
10228 /* Skip Views. */
10229 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10230 continue;
10231
10232 count++;
efb4077a 10233 if (!uj && count == 1) {
fe1dc5a3 10234 vty_out(vty,
efb4077a 10235 "%4s %-5s %-16s %9s %10s %-37s\n",
3c0e7aa4 10236 "Type", "Id", "routerId", "#PeersCfg",
efb4077a
CS
10237 "#PeersEstb", "Name");
10238 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10239 "L3-VNI", "RouterMAC", "Interface");
10240 }
d62a17ae 10241
10242 peers_cfg = peers_estb = 0;
10243 if (uj)
10244 json_vrf = json_object_new_object();
10245
10246
7fe96307 10247 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
d62a17ae 10248 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10249 continue;
10250 peers_cfg++;
10251 if (peer->status == Established)
10252 peers_estb++;
10253 }
10254
10255 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
5742e42b 10256 name = VRF_DEFAULT_NAME;
d62a17ae 10257 type = "DFLT";
10258 } else {
10259 name = bgp->name;
10260 type = "VRF";
10261 }
10262
a8bf7d9c 10263
d62a17ae 10264 if (uj) {
a4d82a8a
PZ
10265 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10266 ? -1
10267 : (int64_t)bgp->vrf_id;
23d0a753
DA
10268 char buf[BUFSIZ] = {0};
10269
d62a17ae 10270 json_object_string_add(json_vrf, "type", type);
10271 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10272 json_object_string_add(json_vrf, "routerId",
23d0a753
DA
10273 inet_ntop(AF_INET,
10274 &bgp->router_id, buf,
10275 sizeof(buf)));
d62a17ae 10276 json_object_int_add(json_vrf, "numConfiguredPeers",
10277 peers_cfg);
10278 json_object_int_add(json_vrf, "numEstablishedPeers",
10279 peers_estb);
10280
fe1dc5a3 10281 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
10282 json_object_string_add(
10283 json_vrf, "rmac",
10284 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
efb4077a
CS
10285 json_object_string_add(json_vrf, "interface",
10286 ifindex2ifname(bgp->l3vni_svi_ifindex,
10287 bgp->vrf_id));
d62a17ae 10288 json_object_object_add(json_vrfs, name, json_vrf);
efb4077a 10289 } else {
23d0a753 10290 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
a4d82a8a
PZ
10291 type,
10292 bgp->vrf_id == VRF_UNKNOWN ? -1
10293 : (int)bgp->vrf_id,
23d0a753 10294 &bgp->router_id, peers_cfg, peers_estb, name);
efb4077a
CS
10295 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10296 bgp->l3vni,
10297 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10298 ifindex2ifname(bgp->l3vni_svi_ifindex,
10299 bgp->vrf_id));
10300 }
d62a17ae 10301 }
10302
10303 if (uj) {
10304 json_object_object_add(json, "vrfs", json_vrfs);
10305
10306 json_object_int_add(json, "totalVrfs", count);
10307
996c9314
LB
10308 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10309 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10310 json_object_free(json);
10311 } else {
10312 if (count)
10313 vty_out(vty,
10314 "\nTotal number of VRFs (including default): %d\n",
10315 count);
10316 }
10317
10318 return CMD_SUCCESS;
8386ac43 10319}
10320
48ecf8f5
DS
10321DEFUN (show_bgp_mac_hash,
10322 show_bgp_mac_hash_cmd,
10323 "show bgp mac hash",
10324 SHOW_STR
10325 BGP_STR
10326 "Mac Address\n"
10327 "Mac Address database\n")
10328{
10329 bgp_mac_dump_table(vty);
10330
10331 return CMD_SUCCESS;
10332}
acf71666 10333
e3b78da8 10334static void show_tip_entry(struct hash_bucket *bucket, void *args)
acf71666 10335{
0291c246 10336 struct vty *vty = (struct vty *)args;
e3b78da8 10337 struct tip_addr *tip = (struct tip_addr *)bucket->data;
acf71666 10338
23d0a753 10339 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
acf71666
MK
10340}
10341
10342static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10343{
10344 vty_out(vty, "self nexthop database:\n");
af97a18b 10345 bgp_nexthop_show_address_hash(vty, bgp);
acf71666
MK
10346
10347 vty_out(vty, "Tunnel-ip database:\n");
10348 hash_iterate(bgp->tip_hash,
e3b78da8 10349 (void (*)(struct hash_bucket *, void *))show_tip_entry,
acf71666
MK
10350 vty);
10351}
10352
15c81ca4
DS
10353DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10354 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10355 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
10356 "martian next-hops\n"
10357 "martian next-hop database\n")
acf71666 10358{
0291c246 10359 struct bgp *bgp = NULL;
15c81ca4 10360 int idx = 0;
9a8bdf1c
PG
10361 char *name = NULL;
10362
10363 /* [<vrf> VIEWVRFNAME] */
10364 if (argv_find(argv, argc, "vrf", &idx)) {
10365 name = argv[idx + 1]->arg;
10366 if (name && strmatch(name, VRF_DEFAULT_NAME))
10367 name = NULL;
10368 } else if (argv_find(argv, argc, "view", &idx))
10369 /* [<view> VIEWVRFNAME] */
10370 name = argv[idx + 1]->arg;
10371 if (name)
10372 bgp = bgp_lookup_by_name(name);
15c81ca4
DS
10373 else
10374 bgp = bgp_get_default();
acf71666 10375
acf71666
MK
10376 if (!bgp) {
10377 vty_out(vty, "%% No BGP process is configured\n");
10378 return CMD_WARNING;
10379 }
10380 bgp_show_martian_nexthops(vty, bgp);
10381
10382 return CMD_SUCCESS;
10383}
10384
f412b39a 10385DEFUN (show_bgp_memory,
4bf6a362 10386 show_bgp_memory_cmd,
7fa12b13 10387 "show [ip] bgp memory",
4bf6a362 10388 SHOW_STR
3a2d747c 10389 IP_STR
4bf6a362
PJ
10390 BGP_STR
10391 "Global BGP memory statistics\n")
10392{
d62a17ae 10393 char memstrbuf[MTYPE_MEMSTR_LEN];
10394 unsigned long count;
10395
10396 /* RIB related usage stats */
10397 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10398 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10399 mtype_memstr(memstrbuf, sizeof(memstrbuf),
9bcb3eef 10400 count * sizeof(struct bgp_dest)));
d62a17ae 10401
10402 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10403 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10404 mtype_memstr(memstrbuf, sizeof(memstrbuf),
4b7e6066 10405 count * sizeof(struct bgp_path_info)));
d62a17ae 10406 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10407 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10408 count,
4b7e6066
DS
10409 mtype_memstr(
10410 memstrbuf, sizeof(memstrbuf),
10411 count * sizeof(struct bgp_path_info_extra)));
d62a17ae 10412
10413 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10414 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10415 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10416 count * sizeof(struct bgp_static)));
10417
10418 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10419 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10420 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10421 count * sizeof(struct bpacket)));
10422
10423 /* Adj-In/Out */
10424 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10425 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10426 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10427 count * sizeof(struct bgp_adj_in)));
10428 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10429 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10430 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10431 count * sizeof(struct bgp_adj_out)));
10432
10433 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10434 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10435 count,
10436 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10437 count * sizeof(struct bgp_nexthop_cache)));
10438
10439 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10440 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10441 count,
10442 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10443 count * sizeof(struct bgp_damp_info)));
10444
10445 /* Attributes */
10446 count = attr_count();
10447 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10448 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10449 count * sizeof(struct attr)));
10450
10451 if ((count = attr_unknown_count()))
10452 vty_out(vty, "%ld unknown attributes\n", count);
10453
10454 /* AS_PATH attributes */
10455 count = aspath_count();
10456 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10457 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10458 count * sizeof(struct aspath)));
10459
10460 count = mtype_stats_alloc(MTYPE_AS_SEG);
10461 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10462 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10463 count * sizeof(struct assegment)));
10464
10465 /* Other attributes */
10466 if ((count = community_count()))
10467 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10468 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10469 count * sizeof(struct community)));
d62a17ae 10470 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10471 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
10472 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10473 count * sizeof(struct ecommunity)));
d62a17ae 10474 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10475 vty_out(vty,
10476 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
10477 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10478 count * sizeof(struct lcommunity)));
d62a17ae 10479
10480 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10481 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10482 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10483 count * sizeof(struct cluster_list)));
10484
10485 /* Peer related usage */
10486 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10487 vty_out(vty, "%ld peers, using %s of memory\n", count,
10488 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10489 count * sizeof(struct peer)));
10490
10491 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10492 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10493 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10494 count * sizeof(struct peer_group)));
10495
10496 /* Other */
d62a17ae 10497 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10498 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
10499 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10500 count * sizeof(regex_t)));
d62a17ae 10501 return CMD_SUCCESS;
4bf6a362 10502}
fee0f4c6 10503
57a9c8a8
DS
10504static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10505{
10506 json_object *bestpath = json_object_new_object();
10507
892fedb6 10508 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
57a9c8a8
DS
10509 json_object_string_add(bestpath, "asPath", "ignore");
10510
892fedb6 10511 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
57a9c8a8
DS
10512 json_object_string_add(bestpath, "asPath", "confed");
10513
892fedb6
DA
10514 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10515 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
a4d82a8a 10516 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10517 "as-set");
10518 else
a4d82a8a 10519 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
10520 "true");
10521 } else
a4d82a8a 10522 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8 10523
ee88563a
JM
10524 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
10525 json_object_boolean_true_add(bestpath, "peerTypeRelax");
10526
892fedb6 10527 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
57a9c8a8 10528 json_object_string_add(bestpath, "compareRouterId", "true");
892fedb6
DA
10529 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10530 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10531 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
a4d82a8a 10532 json_object_string_add(bestpath, "med", "confed");
892fedb6 10533 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
57a9c8a8
DS
10534 json_object_string_add(bestpath, "med",
10535 "missing-as-worst");
10536 else
10537 json_object_string_add(bestpath, "med", "true");
10538 }
10539
10540 json_object_object_add(json, "bestPath", bestpath);
10541}
10542
3577f1c5
DD
10543/* Print the error code/subcode for why the peer is down */
10544static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10545 json_object *json_peer, bool use_json)
10546{
10547 const char *code_str;
10548 const char *subcode_str;
10549
10550 if (use_json) {
10551 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10552 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10553 char errorcodesubcode_hexstr[5];
10554 char errorcodesubcode_str[256];
10555
10556 code_str = bgp_notify_code_str(peer->notify.code);
10557 subcode_str = bgp_notify_subcode_str(
10558 peer->notify.code,
10559 peer->notify.subcode);
10560
772270f3
QY
10561 snprintf(errorcodesubcode_hexstr,
10562 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10563 peer->notify.code, peer->notify.subcode);
3577f1c5
DD
10564 json_object_string_add(json_peer,
10565 "lastErrorCodeSubcode",
10566 errorcodesubcode_hexstr);
10567 snprintf(errorcodesubcode_str, 255, "%s%s",
10568 code_str, subcode_str);
10569 json_object_string_add(json_peer,
10570 "lastNotificationReason",
10571 errorcodesubcode_str);
10572 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10573 && peer->notify.code == BGP_NOTIFY_CEASE
10574 && (peer->notify.subcode
10575 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10576 || peer->notify.subcode
10577 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10578 && peer->notify.length) {
10579 char msgbuf[1024];
10580 const char *msg_str;
10581
10582 msg_str = bgp_notify_admin_message(
10583 msgbuf, sizeof(msgbuf),
10584 (uint8_t *)peer->notify.data,
10585 peer->notify.length);
10586 if (msg_str)
10587 json_object_string_add(
10588 json_peer,
10589 "lastShutdownDescription",
10590 msg_str);
10591 }
10592
c258527b 10593 }
3577f1c5
DD
10594 json_object_string_add(json_peer, "lastResetDueTo",
10595 peer_down_str[(int)peer->last_reset]);
05912a17
DD
10596 json_object_int_add(json_peer, "lastResetCode",
10597 peer->last_reset);
3577f1c5
DD
10598 } else {
10599 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10600 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10601 code_str = bgp_notify_code_str(peer->notify.code);
10602 subcode_str =
10603 bgp_notify_subcode_str(peer->notify.code,
10604 peer->notify.subcode);
10605 vty_out(vty, " Notification %s (%s%s)\n",
10606 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10607 ? "sent"
10608 : "received",
10609 code_str, subcode_str);
10610 } else {
e91c24c8 10611 vty_out(vty, " %s\n",
3577f1c5
DD
10612 peer_down_str[(int)peer->last_reset]);
10613 }
10614 }
10615}
10616
10617static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10618 safi_t safi)
10619{
10620 return ((peer->status != Established) ||
10621 !peer->afc_recv[afi][safi]);
10622}
10623
10624static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10625 struct peer *peer, json_object *json_peer,
10626 int max_neighbor_width, bool use_json)
10627{
10628 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10629 int len;
10630
10631 if (use_json) {
10632 if (peer_dynamic_neighbor(peer))
10633 json_object_boolean_true_add(json_peer,
10634 "dynamicPeer");
10635 if (peer->hostname)
10636 json_object_string_add(json_peer, "hostname",
10637 peer->hostname);
10638
10639 if (peer->domainname)
10640 json_object_string_add(json_peer, "domainname",
10641 peer->domainname);
10642 json_object_int_add(json_peer, "connectionsEstablished",
10643 peer->established);
10644 json_object_int_add(json_peer, "connectionsDropped",
10645 peer->dropped);
10646 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10647 use_json, json_peer);
10648 if (peer->status == Established)
10649 json_object_string_add(json_peer, "lastResetDueTo",
10650 "AFI/SAFI Not Negotiated");
10651 else
10652 bgp_show_peer_reset(NULL, peer, json_peer, true);
10653 } else {
10654 dn_flag[1] = '\0';
10655 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10656 if (peer->hostname
892fedb6 10657 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
3577f1c5
DD
10658 len = vty_out(vty, "%s%s(%s)", dn_flag,
10659 peer->hostname, peer->host);
10660 else
10661 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10662
10663 /* pad the neighbor column with spaces */
10664 if (len < max_neighbor_width)
10665 vty_out(vty, "%*s", max_neighbor_width - len,
10666 " ");
e91c24c8 10667 vty_out(vty, "%7d %7d %9s", peer->established,
3577f1c5
DD
10668 peer->dropped,
10669 peer_uptime(peer->uptime, timebuf,
10670 BGP_UPTIME_LEN, 0, NULL));
10671 if (peer->status == Established)
10672 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10673 else
10674 bgp_show_peer_reset(vty, peer, NULL,
10675 false);
10676 }
10677}
c258527b 10678
cb75bb31
DA
10679/* If the peer's description includes whitespaces
10680 * then return the first occurrence. Also strip description
10681 * to the given size if needed.
10682 */
10683static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10684{
10685 static char stripped[BUFSIZ];
10686 char *pnt;
10687 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10688
10689 pnt = strchr(desc, ' ');
10690 if (pnt)
10691 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10692 : size;
10693
10694 strlcpy(stripped, desc, len + 1);
10695
10696 return stripped;
10697}
3577f1c5 10698
8c1d4cd5
LS
10699/* Determine whether var peer should be filtered out of the summary. */
10700static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
10701 struct peer *fpeer, int as_type,
10702 as_t as)
10703{
10704
10705 /* filter neighbor XXXX */
10706 if (fpeer && fpeer != peer)
10707 return true;
10708
10709 /* filter remote-as (internal|external) */
10710 if (as_type != AS_UNSPECIFIED) {
10711 if (peer->as_type == AS_SPECIFIED) {
10712 if (as_type == AS_INTERNAL) {
10713 if (peer->as != peer->local_as)
10714 return true;
10715 } else if (peer->as == peer->local_as)
10716 return true;
10717 } else if (as_type != peer->as_type)
10718 return true;
10719 } else if (as && as != peer->as) /* filter remote-as XXX */
10720 return true;
10721
10722 return false;
10723}
10724
718e3744 10725/* Show BGP peer's summary information. */
d62a17ae 10726static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
8c1d4cd5 10727 struct peer *fpeer, int as_type, as_t as,
85eeb029 10728 uint8_t show_flags)
d62a17ae 10729{
10730 struct peer *peer;
10731 struct listnode *node, *nnode;
10732 unsigned int count = 0, dn_count = 0;
10733 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10734 char neighbor_buf[VTY_BUFSIZ];
10735 int neighbor_col_default_width = 16;
3577f1c5 10736 int len, failed_count = 0;
d62a17ae 10737 int max_neighbor_width = 0;
10738 int pfx_rcd_safi;
3c13337d 10739 json_object *json = NULL;
d62a17ae 10740 json_object *json_peer = NULL;
10741 json_object *json_peers = NULL;
50e05855 10742 struct peer_af *paf;
d3ada366 10743 struct bgp_filter *filter;
85eeb029
DA
10744 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10745 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10746 bool show_established =
10747 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10748 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
d62a17ae 10749
10750 /* labeled-unicast routes are installed in the unicast table so in order
10751 * to
10752 * display the correct PfxRcd value we must look at SAFI_UNICAST
10753 */
3577f1c5 10754
d62a17ae 10755 if (safi == SAFI_LABELED_UNICAST)
10756 pfx_rcd_safi = SAFI_UNICAST;
10757 else
10758 pfx_rcd_safi = safi;
10759
10760 if (use_json) {
3c13337d 10761 json = json_object_new_object();
d62a17ae 10762 json_peers = json_object_new_object();
3577f1c5 10763 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10764 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10765 as_type, as)) {
10766 count++;
10767 continue;
10768 }
10769
3577f1c5
DD
10770 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10771 continue;
10772
10773 if (peer->afc[afi][safi]) {
10774 /* See if we have at least a single failed peer */
10775 if (bgp_has_peer_failed(peer, afi, safi))
10776 failed_count++;
10777 count++;
10778 }
10779 if (peer_dynamic_neighbor(peer))
10780 dn_count++;
10781 }
c258527b 10782
d62a17ae 10783 } else {
10784 /* Loop over all neighbors that will be displayed to determine
10785 * how many
10786 * characters are needed for the Neighbor column
10787 */
10788 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
8c1d4cd5
LS
10789 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
10790 as_type, as)) {
10791 count++;
10792 continue;
10793 }
10794
d62a17ae 10795 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10796 continue;
10797
10798 if (peer->afc[afi][safi]) {
10799 memset(dn_flag, '\0', sizeof(dn_flag));
10800 if (peer_dynamic_neighbor(peer))
10801 dn_flag[0] = '*';
10802
10803 if (peer->hostname
892fedb6
DA
10804 && CHECK_FLAG(bgp->flags,
10805 BGP_FLAG_SHOW_HOSTNAME))
772270f3
QY
10806 snprintf(neighbor_buf,
10807 sizeof(neighbor_buf),
10808 "%s%s(%s) ", dn_flag,
10809 peer->hostname, peer->host);
d62a17ae 10810 else
772270f3
QY
10811 snprintf(neighbor_buf,
10812 sizeof(neighbor_buf), "%s%s ",
10813 dn_flag, peer->host);
d62a17ae 10814
10815 len = strlen(neighbor_buf);
10816
10817 if (len > max_neighbor_width)
10818 max_neighbor_width = len;
c258527b 10819
3577f1c5
DD
10820 /* See if we have at least a single failed peer */
10821 if (bgp_has_peer_failed(peer, afi, safi))
10822 failed_count++;
10823 count++;
d62a17ae 10824 }
10825 }
f933309e 10826
d62a17ae 10827 /* Originally we displayed the Neighbor column as 16
10828 * characters wide so make that the default
10829 */
10830 if (max_neighbor_width < neighbor_col_default_width)
10831 max_neighbor_width = neighbor_col_default_width;
10832 }
f933309e 10833
3577f1c5
DD
10834 if (show_failed && !failed_count) {
10835 if (use_json) {
10836 json_object_int_add(json, "failedPeersCount", 0);
10837 json_object_int_add(json, "dynamicPeers", dn_count);
c258527b 10838 json_object_int_add(json, "totalPeers", count);
3577f1c5
DD
10839
10840 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10841 json, JSON_C_TO_STRING_PRETTY));
10842 json_object_free(json);
10843 } else {
10844 vty_out(vty, "%% No failed BGP neighbors found\n");
10845 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10846 }
10847 return CMD_SUCCESS;
10848 }
c258527b 10849
3577f1c5 10850 count = 0; /* Reset the value as its used again */
d62a17ae 10851 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10852 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10853 continue;
10854
ea47320b
DL
10855 if (!peer->afc[afi][safi])
10856 continue;
d62a17ae 10857
ea47320b
DL
10858 if (!count) {
10859 unsigned long ents;
10860 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 10861 int64_t vrf_id_ui;
d62a17ae 10862
a4d82a8a
PZ
10863 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10864 ? -1
10865 : (int64_t)bgp->vrf_id;
ea47320b
DL
10866
10867 /* Usage summary and header */
10868 if (use_json) {
23d0a753
DA
10869 char buf[BUFSIZ] = {0};
10870
ea47320b
DL
10871 json_object_string_add(
10872 json, "routerId",
23d0a753
DA
10873 inet_ntop(AF_INET, &bgp->router_id, buf,
10874 sizeof(buf)));
60466a63
QY
10875 json_object_int_add(json, "as", bgp->as);
10876 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
10877 json_object_string_add(
10878 json, "vrfName",
10879 (bgp->inst_type
10880 == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 10881 ? VRF_DEFAULT_NAME
ea47320b
DL
10882 : bgp->name);
10883 } else {
10884 vty_out(vty,
23d0a753
DA
10885 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10886 &bgp->router_id, bgp->as,
a4d82a8a
PZ
10887 bgp->vrf_id == VRF_UNKNOWN
10888 ? -1
10889 : (int)bgp->vrf_id);
ea47320b
DL
10890 vty_out(vty, "\n");
10891 }
d62a17ae 10892
ea47320b 10893 if (bgp_update_delay_configured(bgp)) {
d62a17ae 10894 if (use_json) {
ea47320b 10895 json_object_int_add(
60466a63 10896 json, "updateDelayLimit",
ea47320b 10897 bgp->v_update_delay);
d62a17ae 10898
ea47320b
DL
10899 if (bgp->v_update_delay
10900 != bgp->v_establish_wait)
d62a17ae 10901 json_object_int_add(
10902 json,
ea47320b
DL
10903 "updateDelayEstablishWait",
10904 bgp->v_establish_wait);
d62a17ae 10905
60466a63 10906 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10907 json_object_string_add(
10908 json,
10909 "updateDelayFirstNeighbor",
10910 bgp->update_delay_begin_time);
10911 json_object_boolean_true_add(
10912 json,
10913 "updateDelayInProgress");
10914 } else {
10915 if (bgp->update_delay_over) {
d62a17ae 10916 json_object_string_add(
10917 json,
10918 "updateDelayFirstNeighbor",
10919 bgp->update_delay_begin_time);
ea47320b 10920 json_object_string_add(
d62a17ae 10921 json,
ea47320b
DL
10922 "updateDelayBestpathResumed",
10923 bgp->update_delay_end_time);
10924 json_object_string_add(
d62a17ae 10925 json,
ea47320b
DL
10926 "updateDelayZebraUpdateResume",
10927 bgp->update_delay_zebra_resume_time);
10928 json_object_string_add(
10929 json,
10930 "updateDelayPeerUpdateResume",
10931 bgp->update_delay_peers_resume_time);
d62a17ae 10932 }
ea47320b
DL
10933 }
10934 } else {
10935 vty_out(vty,
10936 "Read-only mode update-delay limit: %d seconds\n",
10937 bgp->v_update_delay);
10938 if (bgp->v_update_delay
10939 != bgp->v_establish_wait)
d62a17ae 10940 vty_out(vty,
ea47320b
DL
10941 " Establish wait: %d seconds\n",
10942 bgp->v_establish_wait);
d62a17ae 10943
60466a63 10944 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
10945 vty_out(vty,
10946 " First neighbor established: %s\n",
10947 bgp->update_delay_begin_time);
10948 vty_out(vty,
10949 " Delay in progress\n");
10950 } else {
10951 if (bgp->update_delay_over) {
d62a17ae 10952 vty_out(vty,
10953 " First neighbor established: %s\n",
10954 bgp->update_delay_begin_time);
10955 vty_out(vty,
ea47320b
DL
10956 " Best-paths resumed: %s\n",
10957 bgp->update_delay_end_time);
10958 vty_out(vty,
10959 " zebra update resumed: %s\n",
10960 bgp->update_delay_zebra_resume_time);
10961 vty_out(vty,
10962 " peers update resumed: %s\n",
10963 bgp->update_delay_peers_resume_time);
d62a17ae 10964 }
10965 }
10966 }
ea47320b 10967 }
d62a17ae 10968
ea47320b
DL
10969 if (use_json) {
10970 if (bgp_maxmed_onstartup_configured(bgp)
10971 && bgp->maxmed_active)
10972 json_object_boolean_true_add(
60466a63 10973 json, "maxMedOnStartup");
ea47320b
DL
10974 if (bgp->v_maxmed_admin)
10975 json_object_boolean_true_add(
60466a63 10976 json, "maxMedAdministrative");
d62a17ae 10977
ea47320b
DL
10978 json_object_int_add(
10979 json, "tableVersion",
60466a63 10980 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 10981
60466a63
QY
10982 ents = bgp_table_count(bgp->rib[afi][safi]);
10983 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
10984 json_object_int_add(
10985 json, "ribMemory",
9bcb3eef 10986 ents * sizeof(struct bgp_dest));
d62a17ae 10987
210ec2a0 10988 ents = bgp->af_peer_count[afi][safi];
60466a63
QY
10989 json_object_int_add(json, "peerCount", ents);
10990 json_object_int_add(json, "peerMemory",
10991 ents * sizeof(struct peer));
d62a17ae 10992
ea47320b
DL
10993 if ((ents = listcount(bgp->group))) {
10994 json_object_int_add(
60466a63 10995 json, "peerGroupCount", ents);
ea47320b
DL
10996 json_object_int_add(
10997 json, "peerGroupMemory",
996c9314
LB
10998 ents * sizeof(struct
10999 peer_group));
ea47320b 11000 }
d62a17ae 11001
ea47320b
DL
11002 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11003 BGP_CONFIG_DAMPENING))
11004 json_object_boolean_true_add(
60466a63 11005 json, "dampeningEnabled");
ea47320b
DL
11006 } else {
11007 if (bgp_maxmed_onstartup_configured(bgp)
11008 && bgp->maxmed_active)
d62a17ae 11009 vty_out(vty,
ea47320b
DL
11010 "Max-med on-startup active\n");
11011 if (bgp->v_maxmed_admin)
d62a17ae 11012 vty_out(vty,
ea47320b 11013 "Max-med administrative active\n");
d62a17ae 11014
60466a63
QY
11015 vty_out(vty, "BGP table version %" PRIu64 "\n",
11016 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 11017
60466a63 11018 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
11019 vty_out(vty,
11020 "RIB entries %ld, using %s of memory\n",
11021 ents,
9bcb3eef
DS
11022 mtype_memstr(
11023 memstrbuf, sizeof(memstrbuf),
11024 ents
11025 * sizeof(struct
11026 bgp_dest)));
ea47320b
DL
11027
11028 /* Peer related usage */
210ec2a0 11029 ents = bgp->af_peer_count[afi][safi];
60466a63 11030 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
11031 ents,
11032 mtype_memstr(
60466a63
QY
11033 memstrbuf, sizeof(memstrbuf),
11034 ents * sizeof(struct peer)));
ea47320b
DL
11035
11036 if ((ents = listcount(bgp->group)))
d62a17ae 11037 vty_out(vty,
ea47320b 11038 "Peer groups %ld, using %s of memory\n",
d62a17ae 11039 ents,
11040 mtype_memstr(
11041 memstrbuf,
11042 sizeof(memstrbuf),
996c9314
LB
11043 ents * sizeof(struct
11044 peer_group)));
d62a17ae 11045
ea47320b
DL
11046 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11047 BGP_CONFIG_DAMPENING))
60466a63 11048 vty_out(vty, "Dampening enabled.\n");
ea47320b 11049 vty_out(vty, "\n");
d62a17ae 11050
ea47320b
DL
11051 /* Subtract 8 here because 'Neighbor' is
11052 * 8 characters */
11053 vty_out(vty, "Neighbor");
60466a63
QY
11054 vty_out(vty, "%*s", max_neighbor_width - 8,
11055 " ");
3577f1c5 11056 if (show_failed)
85eeb029
DA
11057 vty_out(vty,
11058 BGP_SHOW_SUMMARY_HEADER_FAILED);
3577f1c5
DD
11059 else
11060 vty_out(vty,
85eeb029
DA
11061 show_wide
11062 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
11063 : BGP_SHOW_SUMMARY_HEADER_ALL);
d62a17ae 11064 }
ea47320b 11065 }
d62a17ae 11066
d55811cc 11067 paf = peer_af_find(peer, afi, safi);
d3ada366 11068 filter = &peer->filter[afi][safi];
db92d226 11069
ea47320b 11070 count++;
3577f1c5
DD
11071 /* Works for both failed & successful cases */
11072 if (peer_dynamic_neighbor(peer))
11073 dn_count++;
d62a17ae 11074
ea47320b 11075 if (use_json) {
3577f1c5
DD
11076 json_peer = NULL;
11077
8c1d4cd5
LS
11078 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11079 as_type, as))
11080 continue;
11081
3577f1c5
DD
11082 if (show_failed &&
11083 bgp_has_peer_failed(peer, afi, safi)) {
11084 json_peer = json_object_new_object();
11085 bgp_show_failed_summary(vty, bgp, peer,
11086 json_peer, 0, use_json);
11087 } else if (!show_failed) {
10b49f14
DA
11088 if (show_established
11089 && bgp_has_peer_failed(peer, afi, safi))
11090 continue;
11091
3577f1c5
DD
11092 json_peer = json_object_new_object();
11093 if (peer_dynamic_neighbor(peer)) {
11094 json_object_boolean_true_add(json_peer,
11095 "dynamicPeer");
11096 }
d62a17ae 11097
3577f1c5
DD
11098 if (peer->hostname)
11099 json_object_string_add(json_peer, "hostname",
11100 peer->hostname);
11101
11102 if (peer->domainname)
11103 json_object_string_add(json_peer, "domainname",
11104 peer->domainname);
11105
11106 json_object_int_add(json_peer, "remoteAs", peer->as);
c854765f
DA
11107 json_object_int_add(
11108 json_peer, "localAs",
11109 peer->change_local_as
11110 ? peer->change_local_as
11111 : peer->local_as);
3577f1c5
DD
11112 json_object_int_add(json_peer, "version", 4);
11113 json_object_int_add(json_peer, "msgRcvd",
11114 PEER_TOTAL_RX(peer));
11115 json_object_int_add(json_peer, "msgSent",
11116 PEER_TOTAL_TX(peer));
11117
43aa5965
QY
11118 atomic_size_t outq_count, inq_count;
11119 outq_count = atomic_load_explicit(
11120 &peer->obuf->count,
11121 memory_order_relaxed);
11122 inq_count = atomic_load_explicit(
11123 &peer->ibuf->count,
11124 memory_order_relaxed);
11125
3577f1c5
DD
11126 json_object_int_add(json_peer, "tableVersion",
11127 peer->version[afi][safi]);
11128 json_object_int_add(json_peer, "outq",
43aa5965
QY
11129 outq_count);
11130 json_object_int_add(json_peer, "inq",
11131 inq_count);
3577f1c5
DD
11132 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
11133 use_json, json_peer);
11134
3577f1c5
DD
11135 json_object_int_add(json_peer, "pfxRcd",
11136 peer->pcount[afi][pfx_rcd_safi]);
11137
3577f1c5 11138 if (paf && PAF_SUBGRP(paf))
a616dd1f
DA
11139 json_object_int_add(
11140 json_peer, "pfxSnt",
11141 (PAF_SUBGRP(paf))->scount);
11142 else
11143 json_object_int_add(json_peer, "pfxSnt",
11144 0);
0e1f8ab5
DA
11145
11146 /* BGP FSM state */
cb9196e7 11147 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
736b68f3
DS
11148 || CHECK_FLAG(peer->bgp->flags,
11149 BGP_FLAG_SHUTDOWN))
0e1f8ab5
DA
11150 json_object_string_add(json_peer,
11151 "state",
3577f1c5
DD
11152 "Idle (Admin)");
11153 else if (peer->afc_recv[afi][safi])
11154 json_object_string_add(
0e1f8ab5
DA
11155 json_peer, "state",
11156 lookup_msg(bgp_status_msg,
11157 peer->status, NULL));
11158 else if (CHECK_FLAG(
11159 peer->sflags,
11160 PEER_STATUS_PREFIX_OVERFLOW))
11161 json_object_string_add(json_peer,
11162 "state",
3577f1c5
DD
11163 "Idle (PfxCt)");
11164 else
11165 json_object_string_add(
0e1f8ab5
DA
11166 json_peer, "state",
11167 lookup_msg(bgp_status_msg,
11168 peer->status, NULL));
11169
11170 /* BGP peer state */
11171 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11172 || CHECK_FLAG(peer->bgp->flags,
11173 BGP_FLAG_SHUTDOWN))
11174 json_object_string_add(json_peer,
11175 "peerState",
11176 "Admin");
11177 else if (CHECK_FLAG(
11178 peer->sflags,
11179 PEER_STATUS_PREFIX_OVERFLOW))
11180 json_object_string_add(json_peer,
11181 "peerState",
11182 "PfxCt");
11183 else if (CHECK_FLAG(peer->flags,
11184 PEER_FLAG_PASSIVE))
11185 json_object_string_add(json_peer,
11186 "peerState",
11187 "Passive");
11188 else if (CHECK_FLAG(peer->sflags,
11189 PEER_STATUS_NSF_WAIT))
11190 json_object_string_add(json_peer,
11191 "peerState",
11192 "NSF passive");
11193 else if (CHECK_FLAG(
11194 peer->bgp->flags,
11195 BGP_FLAG_EBGP_REQUIRES_POLICY)
11196 && (!bgp_inbound_policy_exists(peer,
11197 filter)
11198 || !bgp_outbound_policy_exists(
11199 peer, filter)))
11200 json_object_string_add(json_peer,
11201 "peerState",
11202 "Policy");
11203 else
11204 json_object_string_add(
11205 json_peer, "peerState", "OK");
11206
200116db
DD
11207 json_object_int_add(json_peer, "connectionsEstablished",
11208 peer->established);
11209 json_object_int_add(json_peer, "connectionsDropped",
11210 peer->dropped);
aa72bd7e
PG
11211 if (peer->desc)
11212 json_object_string_add(
11213 json_peer, "desc", peer->desc);
b4e9dcba 11214 }
3577f1c5
DD
11215 /* Avoid creating empty peer dicts in JSON */
11216 if (json_peer == NULL)
11217 continue;
ea47320b
DL
11218
11219 if (peer->conf_if)
60466a63 11220 json_object_string_add(json_peer, "idType",
ea47320b
DL
11221 "interface");
11222 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
11223 json_object_string_add(json_peer, "idType",
11224 "ipv4");
ea47320b 11225 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
11226 json_object_string_add(json_peer, "idType",
11227 "ipv6");
ea47320b
DL
11228 json_object_object_add(json_peers, peer->host,
11229 json_peer);
11230 } else {
8c1d4cd5
LS
11231 if (bgp_show_summary_is_peer_filtered(peer, fpeer,
11232 as_type, as))
11233 continue;
3577f1c5
DD
11234 if (show_failed &&
11235 bgp_has_peer_failed(peer, afi, safi)) {
11236 bgp_show_failed_summary(vty, bgp, peer, NULL,
11237 max_neighbor_width,
11238 use_json);
11239 } else if (!show_failed) {
10b49f14
DA
11240 if (show_established
11241 && bgp_has_peer_failed(peer, afi, safi))
11242 continue;
3577f1c5
DD
11243 memset(dn_flag, '\0', sizeof(dn_flag));
11244 if (peer_dynamic_neighbor(peer)) {
11245 dn_flag[0] = '*';
11246 }
d62a17ae 11247
3577f1c5 11248 if (peer->hostname
892fedb6
DA
11249 && CHECK_FLAG(bgp->flags,
11250 BGP_FLAG_SHOW_HOSTNAME))
3577f1c5 11251 len = vty_out(vty, "%s%s(%s)", dn_flag,
892fedb6
DA
11252 peer->hostname,
11253 peer->host);
d62a17ae 11254 else
3577f1c5
DD
11255 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11256
11257 /* pad the neighbor column with spaces */
11258 if (len < max_neighbor_width)
11259 vty_out(vty, "%*s", max_neighbor_width - len,
11260 " ");
11261
43aa5965
QY
11262 atomic_size_t outq_count, inq_count;
11263 outq_count = atomic_load_explicit(
11264 &peer->obuf->count,
11265 memory_order_relaxed);
11266 inq_count = atomic_load_explicit(
11267 &peer->ibuf->count,
11268 memory_order_relaxed);
11269
85eeb029
DA
11270 if (show_wide)
11271 vty_out(vty,
11272 "4 %10u %10u %9u %9u %8" PRIu64
11273 " %4zu %4zu %8s",
11274 peer->as,
11275 peer->change_local_as
11276 ? peer->change_local_as
11277 : peer->local_as,
11278 PEER_TOTAL_RX(peer),
11279 PEER_TOTAL_TX(peer),
11280 peer->version[afi][safi],
11281 inq_count, outq_count,
11282 peer_uptime(peer->uptime,
11283 timebuf,
11284 BGP_UPTIME_LEN, 0,
11285 NULL));
11286 else
11287 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11288 " %4zu %4zu %8s",
11289 peer->as, PEER_TOTAL_RX(peer),
11290 PEER_TOTAL_TX(peer),
11291 peer->version[afi][safi],
11292 inq_count, outq_count,
11293 peer_uptime(peer->uptime,
11294 timebuf,
11295 BGP_UPTIME_LEN, 0,
11296 NULL));
3577f1c5 11297
db92d226 11298 if (peer->status == Established) {
d3ada366
DA
11299 if (peer->afc_recv[afi][safi]) {
11300 if (CHECK_FLAG(
11301 bgp->flags,
11302 BGP_FLAG_EBGP_REQUIRES_POLICY)
11303 && !bgp_inbound_policy_exists(
11304 peer, filter))
11305 vty_out(vty, " %12s",
11306 "(Policy)");
11307 else
11308 vty_out(vty,
6cde4b45 11309 " %12u",
d3ada366
DA
11310 peer->pcount
11311 [afi]
11312 [pfx_rcd_safi]);
11313 } else {
749d0f27 11314 vty_out(vty, " NoNeg");
d3ada366 11315 }
db92d226 11316
d3ada366
DA
11317 if (paf && PAF_SUBGRP(paf)) {
11318 if (CHECK_FLAG(
11319 bgp->flags,
11320 BGP_FLAG_EBGP_REQUIRES_POLICY)
11321 && !bgp_outbound_policy_exists(
11322 peer, filter))
11323 vty_out(vty, " %8s",
11324 "(Policy)");
11325 else
11326 vty_out(vty,
6cde4b45 11327 " %8u",
d3ada366
DA
11328 (PAF_SUBGRP(
11329 paf))
11330 ->scount);
749d0f27
DA
11331 } else {
11332 vty_out(vty, " NoNeg");
d3ada366 11333 }
db92d226 11334 } else {
736b68f3
DS
11335 if (CHECK_FLAG(peer->flags,
11336 PEER_FLAG_SHUTDOWN)
11337 || CHECK_FLAG(peer->bgp->flags,
11338 BGP_FLAG_SHUTDOWN))
3577f1c5
DD
11339 vty_out(vty, " Idle (Admin)");
11340 else if (CHECK_FLAG(
11341 peer->sflags,
11342 PEER_STATUS_PREFIX_OVERFLOW))
11343 vty_out(vty, " Idle (PfxCt)");
11344 else
11345 vty_out(vty, " %12s",
11346 lookup_msg(bgp_status_msg,
11347 peer->status, NULL));
db92d226 11348
6cde4b45 11349 vty_out(vty, " %8u", 0);
3577f1c5 11350 }
aa72bd7e 11351 if (peer->desc)
cb75bb31
DA
11352 vty_out(vty, " %s",
11353 bgp_peer_description_stripped(
85eeb029
DA
11354 peer->desc,
11355 show_wide ? 64 : 20));
aa72bd7e
PG
11356 else
11357 vty_out(vty, " N/A");
3577f1c5 11358 vty_out(vty, "\n");
d62a17ae 11359 }
3577f1c5 11360
d62a17ae 11361 }
11362 }
f933309e 11363
d62a17ae 11364 if (use_json) {
11365 json_object_object_add(json, "peers", json_peers);
3577f1c5 11366 json_object_int_add(json, "failedPeers", failed_count);
d62a17ae 11367 json_object_int_add(json, "totalPeers", count);
11368 json_object_int_add(json, "dynamicPeers", dn_count);
11369
3577f1c5
DD
11370 if (!show_failed)
11371 bgp_show_bestpath_json(bgp, json);
57a9c8a8 11372
996c9314
LB
11373 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11374 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 11375 json_object_free(json);
11376 } else {
11377 if (count)
11378 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11379 else {
d6ceaca3 11380 vty_out(vty, "No %s neighbor is configured\n",
5cb5f4d0 11381 get_afi_safi_str(afi, safi, false));
d62a17ae 11382 }
b05a1c8b 11383
d6ceaca3 11384 if (dn_count) {
d62a17ae 11385 vty_out(vty, "* - dynamic neighbor\n");
11386 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11387 dn_count, bgp->dynamic_neighbors_limit);
11388 }
11389 }
1ff9a340 11390
d62a17ae 11391 return CMD_SUCCESS;
718e3744 11392}
11393
d62a17ae 11394static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8c1d4cd5
LS
11395 int safi, struct peer *fpeer, int as_type,
11396 as_t as, uint8_t show_flags)
d62a17ae 11397{
11398 int is_first = 1;
11399 int afi_wildcard = (afi == AFI_MAX);
11400 int safi_wildcard = (safi == SAFI_MAX);
11401 int is_wildcard = (afi_wildcard || safi_wildcard);
9f049418 11402 bool nbr_output = false;
85eeb029 11403 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11404
11405 if (use_json && is_wildcard)
11406 vty_out(vty, "{\n");
11407 if (afi_wildcard)
11408 afi = 1; /* AFI_IP */
11409 while (afi < AFI_MAX) {
11410 if (safi_wildcard)
11411 safi = 1; /* SAFI_UNICAST */
11412 while (safi < SAFI_MAX) {
318cac96 11413 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
9f049418 11414 nbr_output = true;
f86897b9 11415
d62a17ae 11416 if (is_wildcard) {
11417 /*
11418 * So limit output to those afi/safi
11419 * pairs that
11420 * actualy have something interesting in
11421 * them
11422 */
11423 if (use_json) {
d62a17ae 11424 if (!is_first)
11425 vty_out(vty, ",\n");
11426 else
11427 is_first = 0;
11428
11429 vty_out(vty, "\"%s\":",
5cb5f4d0
DD
11430 get_afi_safi_str(afi,
11431 safi,
11432 true));
d62a17ae 11433 } else {
11434 vty_out(vty, "\n%s Summary:\n",
5cb5f4d0
DD
11435 get_afi_safi_str(afi,
11436 safi,
11437 false));
d62a17ae 11438 }
11439 }
8c1d4cd5
LS
11440 bgp_show_summary(vty, bgp, afi, safi, fpeer,
11441 as_type, as, show_flags);
d62a17ae 11442 }
11443 safi++;
d62a17ae 11444 if (!safi_wildcard)
11445 safi = SAFI_MAX;
11446 }
11447 afi++;
ee851c8c 11448 if (!afi_wildcard)
d62a17ae 11449 afi = AFI_MAX;
11450 }
11451
11452 if (use_json && is_wildcard)
11453 vty_out(vty, "}\n");
ca61fd25
DS
11454 else if (!nbr_output) {
11455 if (use_json)
11456 vty_out(vty, "{}\n");
11457 else
11458 vty_out(vty, "%% No BGP neighbors found\n");
11459 }
d62a17ae 11460}
11461
11462static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8c1d4cd5
LS
11463 safi_t safi,
11464 const char *neighbor,
11465 int as_type, as_t as,
11466 uint8_t show_flags)
d62a17ae 11467{
11468 struct listnode *node, *nnode;
11469 struct bgp *bgp;
8c1d4cd5 11470 struct peer *fpeer = NULL;
d62a17ae 11471 int is_first = 1;
9f049418 11472 bool nbr_output = false;
85eeb029 11473 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
d62a17ae 11474
11475 if (use_json)
11476 vty_out(vty, "{\n");
11477
11478 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 11479 nbr_output = true;
d62a17ae 11480 if (use_json) {
d62a17ae 11481 if (!is_first)
11482 vty_out(vty, ",\n");
11483 else
11484 is_first = 0;
11485
11486 vty_out(vty, "\"%s\":",
11487 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11488 ? VRF_DEFAULT_NAME
d62a17ae 11489 : bgp->name);
11490 } else {
11491 vty_out(vty, "\nInstance %s:\n",
11492 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 11493 ? VRF_DEFAULT_NAME
d62a17ae 11494 : bgp->name);
11495 }
8c1d4cd5
LS
11496 if (neighbor) {
11497 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11498 use_json);
11499 if (!fpeer)
11500 continue;
11501 }
11502 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11503 as, show_flags);
d62a17ae 11504 }
11505
11506 if (use_json)
11507 vty_out(vty, "}\n");
9f049418
DS
11508 else if (!nbr_output)
11509 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 11510}
11511
11512int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8c1d4cd5
LS
11513 safi_t safi, const char *neighbor, int as_type,
11514 as_t as, uint8_t show_flags)
d62a17ae 11515{
11516 struct bgp *bgp;
85eeb029 11517 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
8c1d4cd5 11518 struct peer *fpeer = NULL;
d62a17ae 11519
11520 if (name) {
11521 if (strmatch(name, "all")) {
85eeb029 11522 bgp_show_all_instances_summary_vty(vty, afi, safi,
8c1d4cd5
LS
11523 neighbor, as_type,
11524 as, show_flags);
d62a17ae 11525 return CMD_SUCCESS;
11526 } else {
11527 bgp = bgp_lookup_by_name(name);
11528
11529 if (!bgp) {
11530 if (use_json)
11531 vty_out(vty, "{}\n");
11532 else
11533 vty_out(vty,
ca61fd25 11534 "%% BGP instance not found\n");
d62a17ae 11535 return CMD_WARNING;
11536 }
11537
8c1d4cd5
LS
11538 if (neighbor) {
11539 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11540 use_json);
11541 if (!fpeer)
11542 return CMD_WARNING;
11543 }
11544 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer,
11545 as_type, as, show_flags);
d62a17ae 11546 return CMD_SUCCESS;
11547 }
11548 }
11549
11550 bgp = bgp_get_default();
11551
8c1d4cd5
LS
11552 if (bgp) {
11553 if (neighbor) {
11554 fpeer = peer_lookup_in_view(vty, bgp, neighbor,
11555 use_json);
11556 if (!fpeer)
11557 return CMD_WARNING;
11558 }
11559 bgp_show_summary_afi_safi(vty, bgp, afi, safi, fpeer, as_type,
11560 as, show_flags);
11561 } else {
ca61fd25
DS
11562 if (use_json)
11563 vty_out(vty, "{}\n");
11564 else
11565 vty_out(vty, "%% BGP instance not found\n");
9f049418
DS
11566 return CMD_WARNING;
11567 }
d62a17ae 11568
11569 return CMD_SUCCESS;
4fb25c53
DW
11570}
11571
716b2d8a 11572/* `show [ip] bgp summary' commands. */
8c1d4cd5
LS
11573DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
11574 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
11575 " [" BGP_SAFI_WITH_LABEL_CMD_STR
11576 "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [wide] [json$uj]",
11577 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11578 BGP_SAFI_WITH_LABEL_HELP_STR
11579 "Display the entries for all address families\n"
11580 "Summary of BGP neighbor status\n"
11581 "Show only sessions in Established state\n"
11582 "Show only sessions not in Established state\n"
11583 "Show only the specified neighbor session\n"
11584 "Neighbor to display information about\n"
11585 "Neighbor to display information about\n"
11586 "Neighbor on BGP configured interface\n"
11587 "Show only the specified remote AS sessions\n"
11588 "AS number\n"
11589 "Internal (iBGP) AS sessions\n"
11590 "External (eBGP) AS sessions\n"
11591 "Increase table width for longer output\n" JSON_STR)
718e3744 11592{
d62a17ae 11593 char *vrf = NULL;
11594 afi_t afi = AFI_MAX;
11595 safi_t safi = SAFI_MAX;
8c1d4cd5
LS
11596 as_t as = 0; /* 0 means AS filter not set */
11597 int as_type = AS_UNSPECIFIED;
85eeb029 11598 uint8_t show_flags = 0;
d62a17ae 11599
11600 int idx = 0;
11601
11602 /* show [ip] bgp */
96f3485c 11603 if (!all && argv_find(argv, argc, "ip", &idx))
d62a17ae 11604 afi = AFI_IP;
9a8bdf1c
PG
11605 /* [<vrf> VIEWVRFNAME] */
11606 if (argv_find(argv, argc, "vrf", &idx)) {
11607 vrf = argv[idx + 1]->arg;
11608 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11609 vrf = NULL;
11610 } else if (argv_find(argv, argc, "view", &idx))
11611 /* [<view> VIEWVRFNAME] */
11612 vrf = argv[idx + 1]->arg;
d62a17ae 11613 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11614 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11615 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11616 }
11617
3577f1c5 11618 if (argv_find(argv, argc, "failed", &idx))
85eeb029
DA
11619 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11620
10b49f14 11621 if (argv_find(argv, argc, "established", &idx))
85eeb029
DA
11622 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11623
8c1d4cd5
LS
11624 if (argv_find(argv, argc, "remote-as", &idx)) {
11625 if (argv[idx + 1]->arg[0] == 'i')
11626 as_type = AS_INTERNAL;
11627 else if (argv[idx + 1]->arg[0] == 'e')
11628 as_type = AS_EXTERNAL;
11629 else
11630 as = (as_t)atoi(argv[idx + 1]->arg);
11631 }
11632
85eeb029
DA
11633 if (argv_find(argv, argc, "wide", &idx))
11634 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11635
11636 if (argv_find(argv, argc, "json", &idx))
11637 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
3577f1c5 11638
8c1d4cd5
LS
11639 return bgp_show_summary_vty(vty, vrf, afi, safi, neighbor, as_type, as,
11640 show_flags);
d62a17ae 11641}
11642
5cb5f4d0 11643const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
d62a17ae 11644{
5cb5f4d0
DD
11645 if (for_json)
11646 return get_afi_safi_json_str(afi, safi);
d62a17ae 11647 else
5cb5f4d0 11648 return get_afi_safi_vty_str(afi, safi);
27162734
LB
11649}
11650
d62a17ae 11651
11652static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11653 afi_t afi, safi_t safi,
d7c0a89a
QY
11654 uint16_t adv_smcap, uint16_t adv_rmcap,
11655 uint16_t rcv_smcap, uint16_t rcv_rmcap,
9f049418 11656 bool use_json, json_object *json_pref)
d62a17ae 11657{
11658 /* Send-Mode */
11659 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11660 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11661 if (use_json) {
11662 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11663 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11664 json_object_string_add(json_pref, "sendMode",
11665 "advertisedAndReceived");
11666 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11667 json_object_string_add(json_pref, "sendMode",
11668 "advertised");
11669 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11670 json_object_string_add(json_pref, "sendMode",
11671 "received");
11672 } else {
11673 vty_out(vty, " Send-mode: ");
11674 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11675 vty_out(vty, "advertised");
11676 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11677 vty_out(vty, "%sreceived",
11678 CHECK_FLAG(p->af_cap[afi][safi],
11679 adv_smcap)
11680 ? ", "
11681 : "");
11682 vty_out(vty, "\n");
11683 }
11684 }
11685
11686 /* Receive-Mode */
11687 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11688 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11689 if (use_json) {
11690 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11691 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11692 json_object_string_add(json_pref, "recvMode",
11693 "advertisedAndReceived");
11694 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11695 json_object_string_add(json_pref, "recvMode",
11696 "advertised");
11697 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11698 json_object_string_add(json_pref, "recvMode",
11699 "received");
11700 } else {
11701 vty_out(vty, " Receive-mode: ");
11702 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11703 vty_out(vty, "advertised");
11704 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11705 vty_out(vty, "%sreceived",
11706 CHECK_FLAG(p->af_cap[afi][safi],
11707 adv_rmcap)
11708 ? ", "
11709 : "");
11710 vty_out(vty, "\n");
11711 }
11712 }
11713}
11714
13909c4f
DS
11715static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11716 struct peer *p,
11717 bool use_json,
11718 json_object *json)
2986cac2 11719{
08c2d52a 11720 bool rbit_status = false;
2986cac2 11721
11722 if (!use_json)
a53ca37b 11723 vty_out(vty, "\n R bit: ");
2986cac2 11724
13909c4f
DS
11725 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11726 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11727 && (p->status == Established)) {
2986cac2 11728
11729 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
08c2d52a 11730 rbit_status = true;
2986cac2 11731 else
08c2d52a 11732 rbit_status = false;
2986cac2 11733 }
11734
11735 if (rbit_status) {
11736 if (use_json)
13909c4f 11737 json_object_boolean_true_add(json, "rBit");
2986cac2 11738 else
11739 vty_out(vty, "True\n");
11740 } else {
11741 if (use_json)
13909c4f 11742 json_object_boolean_false_add(json, "rBit");
2986cac2 11743 else
11744 vty_out(vty, "False\n");
11745 }
11746}
11747
13909c4f
DS
11748static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11749 struct peer *peer,
11750 bool use_json,
11751 json_object *json)
2986cac2 11752{
2bb5d39b 11753 const char *mode = "NotApplicable";
2986cac2 11754
11755 if (!use_json)
a53ca37b 11756 vty_out(vty, "\n Remote GR Mode: ");
2986cac2 11757
13909c4f
DS
11758 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11759 && (peer->status == Established)) {
2986cac2 11760
13909c4f
DS
11761 if ((peer->nsf_af_count == 0)
11762 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11763
2986cac2 11764 mode = "Disable";
11765
13909c4f
DS
11766 } else if (peer->nsf_af_count == 0
11767 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11768
2986cac2 11769 mode = "Helper";
11770
13909c4f
DS
11771 } else if (peer->nsf_af_count != 0
11772 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 11773
2986cac2 11774 mode = "Restart";
2986cac2 11775 }
11776 }
11777
11778 if (use_json) {
13909c4f 11779 json_object_string_add(json, "remoteGrMode", mode);
2986cac2 11780 } else
11781 vty_out(vty, mode, "\n");
11782}
11783
13909c4f
DS
11784static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11785 struct peer *p,
11786 bool use_json,
11787 json_object *json)
2986cac2 11788{
11789 const char *mode = "Invalid";
11790
11791 if (!use_json)
a53ca37b 11792 vty_out(vty, " Local GR Mode: ");
2986cac2 11793
11794 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11795 mode = "Helper";
11796 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11797 mode = "Restart";
11798 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11799 mode = "Disable";
2ba1fe69 11800 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
2986cac2 11801 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11802 mode = "Helper*";
11803 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11804 mode = "Restart*";
11805 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11806 mode = "Disable*";
11807 else
11808 mode = "Invalid*";
2ba1fe69 11809 }
2986cac2 11810
11811 if (use_json) {
13909c4f 11812 json_object_string_add(json, "localGrMode", mode);
2986cac2 11813 } else {
11814 vty_out(vty, mode, "\n");
11815 }
11816}
11817
13909c4f
DS
11818static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11819 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
2986cac2 11820{
2ba1fe69 11821 afi_t afi;
11822 safi_t safi;
2986cac2 11823 json_object *json_afi_safi = NULL;
11824 json_object *json_timer = NULL;
11825 json_object *json_endofrib_status = NULL;
9e3b51a7 11826 bool eor_flag = false;
2986cac2 11827
11828 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11829 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
13909c4f
DS
11830 if (!peer->afc[afi][safi])
11831 continue;
2986cac2 11832
13909c4f
DS
11833 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11834 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11835 continue;
9e3b51a7 11836
13909c4f
DS
11837 if (use_json) {
11838 json_afi_safi = json_object_new_object();
11839 json_endofrib_status = json_object_new_object();
11840 json_timer = json_object_new_object();
11841 }
2986cac2 11842
13909c4f
DS
11843 if (peer->eor_stime[afi][safi]
11844 >= peer->pkt_stime[afi][safi])
11845 eor_flag = true;
11846 else
11847 eor_flag = false;
2986cac2 11848
13909c4f 11849 if (!use_json) {
a53ca37b 11850 vty_out(vty, " %s:\n",
13909c4f 11851 get_afi_safi_str(afi, safi, false));
2986cac2 11852
a53ca37b 11853 vty_out(vty, " F bit: ");
698ba8d0 11854 }
2986cac2 11855
13909c4f
DS
11856 if (peer->nsf[afi][safi]
11857 && CHECK_FLAG(peer->af_cap[afi][safi],
11858 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
2986cac2 11859
13909c4f
DS
11860 if (use_json) {
11861 json_object_boolean_true_add(
2986cac2 11862 json_afi_safi, "fBit");
13909c4f
DS
11863 } else
11864 vty_out(vty, "True\n");
11865 } else {
11866 if (use_json)
11867 json_object_boolean_false_add(
11868 json_afi_safi, "fBit");
11869 else
11870 vty_out(vty, "False\n");
11871 }
2986cac2 11872
13909c4f 11873 if (!use_json)
a53ca37b 11874 vty_out(vty, " End-of-RIB sent: ");
2986cac2 11875
13909c4f
DS
11876 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11877 PEER_STATUS_EOR_SEND)) {
11878 if (use_json) {
11879 json_object_boolean_true_add(
2986cac2 11880 json_endofrib_status,
13909c4f 11881 "endOfRibSend");
9e3b51a7 11882
13909c4f
DS
11883 PRINT_EOR_JSON(eor_flag);
11884 } else {
11885 vty_out(vty, "Yes\n");
11886 vty_out(vty,
a53ca37b 11887 " End-of-RIB sent after update: ");
2986cac2 11888
13909c4f
DS
11889 PRINT_EOR(eor_flag);
11890 }
11891 } else {
11892 if (use_json) {
11893 json_object_boolean_false_add(
2986cac2 11894 json_endofrib_status,
13909c4f
DS
11895 "endOfRibSend");
11896 json_object_boolean_false_add(
9e3b51a7 11897 json_endofrib_status,
13909c4f
DS
11898 "endOfRibSentAfterUpdate");
11899 } else {
11900 vty_out(vty, "No\n");
11901 vty_out(vty,
a53ca37b 11902 " End-of-RIB sent after update: ");
13909c4f 11903 vty_out(vty, "No\n");
2986cac2 11904 }
13909c4f 11905 }
2986cac2 11906
a53ca37b
DA
11907 if (!use_json)
11908 vty_out(vty, " End-of-RIB received: ");
11909
11910 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11911 PEER_STATUS_EOR_RECEIVED)) {
11912 if (use_json)
11913 json_object_boolean_true_add(
11914 json_endofrib_status,
11915 "endOfRibRecv");
11916 else
11917 vty_out(vty, "Yes\n");
11918 } else {
11919 if (use_json)
11920 json_object_boolean_false_add(
11921 json_endofrib_status,
11922 "endOfRibRecv");
11923 else
11924 vty_out(vty, "No\n");
11925 }
11926
13909c4f
DS
11927 if (use_json) {
11928 json_object_int_add(json_timer,
11929 "stalePathTimer",
11930 peer->bgp->stalepath_time);
2986cac2 11931
13909c4f
DS
11932 if (peer->t_gr_stale != NULL) {
11933 json_object_int_add(
2986cac2 11934 json_timer,
11935 "stalePathTimerRemaining",
11936 thread_timer_remain_second(
13909c4f
DS
11937 peer->t_gr_stale));
11938 }
3a75afa4 11939
13909c4f
DS
11940 /* Display Configured Selection
11941 * Deferral only when when
11942 * Gr mode is enabled.
11943 */
11944 if (CHECK_FLAG(peer->flags,
11945 PEER_FLAG_GRACEFUL_RESTART)) {
11946 json_object_int_add(
3a75afa4 11947 json_timer,
2986cac2 11948 "selectionDeferralTimer",
11949 peer->bgp->stalepath_time);
13909c4f 11950 }
2986cac2 11951
13909c4f
DS
11952 if (peer->bgp->gr_info[afi][safi]
11953 .t_select_deferral
11954 != NULL) {
2986cac2 11955
13909c4f 11956 json_object_int_add(
2986cac2 11957 json_timer,
11958 "selectionDeferralTimerRemaining",
11959 thread_timer_remain_second(
13909c4f
DS
11960 peer->bgp
11961 ->gr_info[afi]
11962 [safi]
11963 .t_select_deferral));
11964 }
11965 } else {
a53ca37b 11966 vty_out(vty, " Timers:\n");
13909c4f 11967 vty_out(vty,
a53ca37b
DA
11968 " Configured Stale Path Time(sec): %u\n",
11969 peer->bgp->stalepath_time);
2986cac2 11970
a53ca37b 11971 if (peer->t_gr_stale != NULL)
2986cac2 11972 vty_out(vty,
a53ca37b 11973 " Stale Path Remaining(sec): %ld\n",
2986cac2 11974 thread_timer_remain_second(
13909c4f 11975 peer->t_gr_stale));
13909c4f
DS
11976 /* Display Configured Selection
11977 * Deferral only when when
11978 * Gr mode is enabled.
11979 */
11980 if (CHECK_FLAG(peer->flags,
a53ca37b 11981 PEER_FLAG_GRACEFUL_RESTART))
13909c4f 11982 vty_out(vty,
a53ca37b 11983 " Configured Selection Deferral Time(sec): %u\n",
3a75afa4 11984 peer->bgp->select_defer_time);
2986cac2 11985
13909c4f
DS
11986 if (peer->bgp->gr_info[afi][safi]
11987 .t_select_deferral
a53ca37b 11988 != NULL)
13909c4f 11989 vty_out(vty,
a53ca37b 11990 " Selection Deferral Time Remaining(sec): %ld\n",
2986cac2 11991 thread_timer_remain_second(
13909c4f
DS
11992 peer->bgp
11993 ->gr_info[afi]
11994 [safi]
11995 .t_select_deferral));
2986cac2 11996 }
13909c4f
DS
11997 if (use_json) {
11998 json_object_object_add(json_afi_safi,
11999 "endOfRibStatus",
12000 json_endofrib_status);
12001 json_object_object_add(json_afi_safi, "timers",
12002 json_timer);
12003 json_object_object_add(
12004 json, get_afi_safi_str(afi, safi, true),
12005 json_afi_safi);
12006 }
2986cac2 12007 }
12008 }
12009}
12010
36235319
QY
12011static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
12012 struct peer *p,
12013 bool use_json,
12014 json_object *json)
2986cac2 12015{
12016 if (use_json) {
12017 json_object *json_timer = NULL;
12018
12019 json_timer = json_object_new_object();
12020
13909c4f
DS
12021 json_object_int_add(json_timer, "configuredRestartTimer",
12022 p->bgp->restart_time);
2986cac2 12023
13909c4f
DS
12024 json_object_int_add(json_timer, "receivedRestartTimer",
12025 p->v_gr_restart);
2986cac2 12026
13909c4f
DS
12027 if (p->t_gr_restart != NULL)
12028 json_object_int_add(
12029 json_timer, "restartTimerRemaining",
12030 thread_timer_remain_second(p->t_gr_restart));
2986cac2 12031
12032 json_object_object_add(json, "timers", json_timer);
12033 } else {
12034
a53ca37b
DA
12035 vty_out(vty, " Timers:\n");
12036 vty_out(vty, " Configured Restart Time(sec): %u\n",
13909c4f 12037 p->bgp->restart_time);
2986cac2 12038
a53ca37b 12039 vty_out(vty, " Received Restart Time(sec): %u\n",
13909c4f
DS
12040 p->v_gr_restart);
12041 if (p->t_gr_restart != NULL)
a53ca37b 12042 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
13909c4f 12043 thread_timer_remain_second(p->t_gr_restart));
36235319 12044 if (p->t_gr_restart != NULL) {
a53ca37b 12045 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
36235319
QY
12046 thread_timer_remain_second(p->t_gr_restart));
12047 }
2986cac2 12048 }
12049}
12050
12051static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
36235319 12052 bool use_json, json_object *json)
2986cac2 12053{
12054 char buf[SU_ADDRSTRLEN] = {0};
12055 char dn_flag[2] = {0};
2b7165e7
QY
12056 /* '*' + v6 address of neighbor */
12057 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
2986cac2 12058
2986cac2 12059 if (!p->conf_if && peer_dynamic_neighbor(p))
12060 dn_flag[0] = '*';
12061
12062 if (p->conf_if) {
12063 if (use_json)
13909c4f
DS
12064 json_object_string_add(
12065 json, "neighborAddr",
2986cac2 12066 BGP_PEER_SU_UNSPEC(p)
13909c4f
DS
12067 ? "none"
12068 : sockunion2str(&p->su, buf,
12069 SU_ADDRSTRLEN));
2986cac2 12070 else
13909c4f 12071 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
2986cac2 12072 BGP_PEER_SU_UNSPEC(p)
12073 ? "none"
12074 : sockunion2str(&p->su, buf,
12075 SU_ADDRSTRLEN));
12076 } else {
772270f3
QY
12077 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
12078 p->host);
2986cac2 12079
12080 if (use_json)
36235319
QY
12081 json_object_string_add(json, "neighborAddr",
12082 neighborAddr);
2986cac2 12083 else
36235319 12084 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
2986cac2 12085 }
12086
12087 /* more gr info in new format */
12088 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
12089}
12090
d62a17ae 12091static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
9f049418 12092 safi_t safi, bool use_json,
d62a17ae 12093 json_object *json_neigh)
12094{
0291c246
MK
12095 struct bgp_filter *filter;
12096 struct peer_af *paf;
12097 char orf_pfx_name[BUFSIZ];
12098 int orf_pfx_count;
12099 json_object *json_af = NULL;
12100 json_object *json_prefA = NULL;
12101 json_object *json_prefB = NULL;
12102 json_object *json_addr = NULL;
fa36596c 12103 json_object *json_advmap = NULL;
d62a17ae 12104
12105 if (use_json) {
12106 json_addr = json_object_new_object();
12107 json_af = json_object_new_object();
12108 filter = &p->filter[afi][safi];
12109
12110 if (peer_group_active(p))
12111 json_object_string_add(json_addr, "peerGroupMember",
12112 p->group->name);
12113
12114 paf = peer_af_find(p, afi, safi);
12115 if (paf && PAF_SUBGRP(paf)) {
12116 json_object_int_add(json_addr, "updateGroupId",
12117 PAF_UPDGRP(paf)->id);
12118 json_object_int_add(json_addr, "subGroupId",
12119 PAF_SUBGRP(paf)->id);
12120 json_object_int_add(json_addr, "packetQueueLength",
12121 bpacket_queue_virtual_length(paf));
12122 }
12123
12124 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12125 || CHECK_FLAG(p->af_cap[afi][safi],
12126 PEER_CAP_ORF_PREFIX_SM_RCV)
12127 || CHECK_FLAG(p->af_cap[afi][safi],
12128 PEER_CAP_ORF_PREFIX_RM_ADV)
12129 || CHECK_FLAG(p->af_cap[afi][safi],
12130 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12131 json_object_int_add(json_af, "orfType",
12132 ORF_TYPE_PREFIX);
12133 json_prefA = json_object_new_object();
12134 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
12135 PEER_CAP_ORF_PREFIX_SM_ADV,
12136 PEER_CAP_ORF_PREFIX_RM_ADV,
12137 PEER_CAP_ORF_PREFIX_SM_RCV,
12138 PEER_CAP_ORF_PREFIX_RM_RCV,
12139 use_json, json_prefA);
12140 json_object_object_add(json_af, "orfPrefixList",
12141 json_prefA);
12142 }
12143
12144 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12145 || CHECK_FLAG(p->af_cap[afi][safi],
12146 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12147 || CHECK_FLAG(p->af_cap[afi][safi],
12148 PEER_CAP_ORF_PREFIX_RM_ADV)
12149 || CHECK_FLAG(p->af_cap[afi][safi],
12150 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12151 json_object_int_add(json_af, "orfOldType",
12152 ORF_TYPE_PREFIX_OLD);
12153 json_prefB = json_object_new_object();
12154 bgp_show_peer_afi_orf_cap(
12155 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12156 PEER_CAP_ORF_PREFIX_RM_ADV,
12157 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12158 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
12159 json_prefB);
12160 json_object_object_add(json_af, "orfOldPrefixList",
12161 json_prefB);
12162 }
12163
12164 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12165 || CHECK_FLAG(p->af_cap[afi][safi],
12166 PEER_CAP_ORF_PREFIX_SM_RCV)
12167 || CHECK_FLAG(p->af_cap[afi][safi],
12168 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12169 || CHECK_FLAG(p->af_cap[afi][safi],
12170 PEER_CAP_ORF_PREFIX_RM_ADV)
12171 || CHECK_FLAG(p->af_cap[afi][safi],
12172 PEER_CAP_ORF_PREFIX_RM_RCV)
12173 || CHECK_FLAG(p->af_cap[afi][safi],
12174 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12175 json_object_object_add(json_addr, "afDependentCap",
12176 json_af);
12177 else
12178 json_object_free(json_af);
12179
772270f3
QY
12180 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12181 p->host, afi, safi);
d62a17ae 12182 orf_pfx_count = prefix_bgp_show_prefix_list(
12183 NULL, afi, orf_pfx_name, use_json);
12184
12185 if (CHECK_FLAG(p->af_sflags[afi][safi],
12186 PEER_STATUS_ORF_PREFIX_SEND)
12187 || orf_pfx_count) {
12188 if (CHECK_FLAG(p->af_sflags[afi][safi],
12189 PEER_STATUS_ORF_PREFIX_SEND))
12190 json_object_boolean_true_add(json_neigh,
12191 "orfSent");
12192 if (orf_pfx_count)
12193 json_object_int_add(json_addr, "orfRecvCounter",
12194 orf_pfx_count);
12195 }
12196 if (CHECK_FLAG(p->af_sflags[afi][safi],
12197 PEER_STATUS_ORF_WAIT_REFRESH))
12198 json_object_string_add(
12199 json_addr, "orfFirstUpdate",
12200 "deferredUntilORFOrRouteRefreshRecvd");
12201
12202 if (CHECK_FLAG(p->af_flags[afi][safi],
12203 PEER_FLAG_REFLECTOR_CLIENT))
12204 json_object_boolean_true_add(json_addr,
12205 "routeReflectorClient");
12206 if (CHECK_FLAG(p->af_flags[afi][safi],
12207 PEER_FLAG_RSERVER_CLIENT))
12208 json_object_boolean_true_add(json_addr,
12209 "routeServerClient");
12210 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12211 json_object_boolean_true_add(json_addr,
12212 "inboundSoftConfigPermit");
12213
12214 if (CHECK_FLAG(p->af_flags[afi][safi],
12215 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12216 json_object_boolean_true_add(
12217 json_addr,
12218 "privateAsNumsAllReplacedInUpdatesToNbr");
12219 else if (CHECK_FLAG(p->af_flags[afi][safi],
12220 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12221 json_object_boolean_true_add(
12222 json_addr,
12223 "privateAsNumsReplacedInUpdatesToNbr");
12224 else if (CHECK_FLAG(p->af_flags[afi][safi],
12225 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12226 json_object_boolean_true_add(
12227 json_addr,
12228 "privateAsNumsAllRemovedInUpdatesToNbr");
12229 else if (CHECK_FLAG(p->af_flags[afi][safi],
12230 PEER_FLAG_REMOVE_PRIVATE_AS))
12231 json_object_boolean_true_add(
12232 json_addr,
12233 "privateAsNumsRemovedInUpdatesToNbr");
12234
dcc68b5e
MS
12235 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12236 json_object_boolean_true_add(
12237 json_addr,
12238 bgp_addpath_names(p->addpath_type[afi][safi])
12239 ->type_json_name);
d62a17ae 12240
12241 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12242 json_object_string_add(json_addr,
12243 "overrideASNsInOutboundUpdates",
12244 "ifAspathEqualRemoteAs");
12245
12246 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12247 || CHECK_FLAG(p->af_flags[afi][safi],
12248 PEER_FLAG_FORCE_NEXTHOP_SELF))
12249 json_object_boolean_true_add(json_addr,
12250 "routerAlwaysNextHop");
12251 if (CHECK_FLAG(p->af_flags[afi][safi],
12252 PEER_FLAG_AS_PATH_UNCHANGED))
12253 json_object_boolean_true_add(
12254 json_addr, "unchangedAsPathPropogatedToNbr");
12255 if (CHECK_FLAG(p->af_flags[afi][safi],
12256 PEER_FLAG_NEXTHOP_UNCHANGED))
12257 json_object_boolean_true_add(
12258 json_addr, "unchangedNextHopPropogatedToNbr");
12259 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12260 json_object_boolean_true_add(
12261 json_addr, "unchangedMedPropogatedToNbr");
12262 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12263 || CHECK_FLAG(p->af_flags[afi][safi],
12264 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12265 if (CHECK_FLAG(p->af_flags[afi][safi],
12266 PEER_FLAG_SEND_COMMUNITY)
12267 && CHECK_FLAG(p->af_flags[afi][safi],
12268 PEER_FLAG_SEND_EXT_COMMUNITY))
12269 json_object_string_add(json_addr,
12270 "commAttriSentToNbr",
12271 "extendedAndStandard");
12272 else if (CHECK_FLAG(p->af_flags[afi][safi],
12273 PEER_FLAG_SEND_EXT_COMMUNITY))
12274 json_object_string_add(json_addr,
12275 "commAttriSentToNbr",
12276 "extended");
12277 else
12278 json_object_string_add(json_addr,
12279 "commAttriSentToNbr",
12280 "standard");
12281 }
12282 if (CHECK_FLAG(p->af_flags[afi][safi],
12283 PEER_FLAG_DEFAULT_ORIGINATE)) {
12284 if (p->default_rmap[afi][safi].name)
12285 json_object_string_add(
12286 json_addr, "defaultRouteMap",
12287 p->default_rmap[afi][safi].name);
12288
12289 if (paf && PAF_SUBGRP(paf)
12290 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12291 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12292 json_object_boolean_true_add(json_addr,
12293 "defaultSent");
12294 else
12295 json_object_boolean_true_add(json_addr,
12296 "defaultNotSent");
12297 }
12298
dff8f48d 12299 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12300 if (is_evpn_enabled())
60466a63
QY
12301 json_object_boolean_true_add(
12302 json_addr, "advertiseAllVnis");
dff8f48d
MK
12303 }
12304
d62a17ae 12305 if (filter->plist[FILTER_IN].name
12306 || filter->dlist[FILTER_IN].name
12307 || filter->aslist[FILTER_IN].name
12308 || filter->map[RMAP_IN].name)
12309 json_object_boolean_true_add(json_addr,
12310 "inboundPathPolicyConfig");
12311 if (filter->plist[FILTER_OUT].name
12312 || filter->dlist[FILTER_OUT].name
12313 || filter->aslist[FILTER_OUT].name
12314 || filter->map[RMAP_OUT].name || filter->usmap.name)
12315 json_object_boolean_true_add(
12316 json_addr, "outboundPathPolicyConfig");
12317
12318 /* prefix-list */
12319 if (filter->plist[FILTER_IN].name)
12320 json_object_string_add(json_addr,
12321 "incomingUpdatePrefixFilterList",
12322 filter->plist[FILTER_IN].name);
12323 if (filter->plist[FILTER_OUT].name)
12324 json_object_string_add(json_addr,
12325 "outgoingUpdatePrefixFilterList",
12326 filter->plist[FILTER_OUT].name);
12327
12328 /* distribute-list */
12329 if (filter->dlist[FILTER_IN].name)
12330 json_object_string_add(
12331 json_addr, "incomingUpdateNetworkFilterList",
12332 filter->dlist[FILTER_IN].name);
12333 if (filter->dlist[FILTER_OUT].name)
12334 json_object_string_add(
12335 json_addr, "outgoingUpdateNetworkFilterList",
12336 filter->dlist[FILTER_OUT].name);
12337
12338 /* filter-list. */
12339 if (filter->aslist[FILTER_IN].name)
12340 json_object_string_add(json_addr,
12341 "incomingUpdateAsPathFilterList",
12342 filter->aslist[FILTER_IN].name);
12343 if (filter->aslist[FILTER_OUT].name)
12344 json_object_string_add(json_addr,
12345 "outgoingUpdateAsPathFilterList",
12346 filter->aslist[FILTER_OUT].name);
12347
12348 /* route-map. */
12349 if (filter->map[RMAP_IN].name)
12350 json_object_string_add(
12351 json_addr, "routeMapForIncomingAdvertisements",
12352 filter->map[RMAP_IN].name);
12353 if (filter->map[RMAP_OUT].name)
12354 json_object_string_add(
12355 json_addr, "routeMapForOutgoingAdvertisements",
12356 filter->map[RMAP_OUT].name);
12357
9dac9fc8 12358 /* ebgp-requires-policy (inbound) */
1d3fdccf 12359 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12360 && !bgp_inbound_policy_exists(p, filter))
12361 json_object_string_add(
12362 json_addr, "inboundEbgpRequiresPolicy",
12363 "Inbound updates discarded due to missing policy");
12364
12365 /* ebgp-requires-policy (outbound) */
1d3fdccf 12366 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12367 && (!bgp_outbound_policy_exists(p, filter)))
12368 json_object_string_add(
12369 json_addr, "outboundEbgpRequiresPolicy",
12370 "Outbound updates discarded due to missing policy");
12371
d62a17ae 12372 /* unsuppress-map */
12373 if (filter->usmap.name)
12374 json_object_string_add(json_addr,
12375 "selectiveUnsuppressRouteMap",
12376 filter->usmap.name);
12377
fa36596c
MK
12378 /* advertise-map */
12379 if (filter->advmap.aname) {
12380 json_advmap = json_object_new_object();
12381 json_object_string_add(json_advmap, "condition",
12382 filter->advmap.condition
12383 ? "EXIST"
12384 : "NON_EXIST");
12385 json_object_string_add(json_advmap, "conditionMap",
12386 filter->advmap.cname);
12387 json_object_string_add(json_advmap, "advertiseMap",
12388 filter->advmap.aname);
12389 json_object_string_add(json_advmap, "advertiseStatus",
12390 filter->advmap.update_type
12391 == ADVERTISE
12392 ? "Advertise"
12393 : "Withdraw");
12394 json_object_object_add(json_addr, "advertiseMap",
12395 json_advmap);
12396 }
12397
d62a17ae 12398 /* Receive prefix count */
12399 json_object_int_add(json_addr, "acceptedPrefixCounter",
12400 p->pcount[afi][safi]);
50e05855
AD
12401 if (paf && PAF_SUBGRP(paf))
12402 json_object_int_add(json_addr, "sentPrefixCounter",
12403 (PAF_SUBGRP(paf))->scount);
d62a17ae 12404
fde246e8
DA
12405 /* Maximum prefix */
12406 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12407 json_object_int_add(json_addr, "prefixOutAllowedMax",
12408 p->pmax_out[afi][safi]);
12409
d62a17ae 12410 /* Maximum prefix */
12411 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12412 json_object_int_add(json_addr, "prefixAllowedMax",
12413 p->pmax[afi][safi]);
12414 if (CHECK_FLAG(p->af_flags[afi][safi],
12415 PEER_FLAG_MAX_PREFIX_WARNING))
12416 json_object_boolean_true_add(
12417 json_addr, "prefixAllowedMaxWarning");
12418 json_object_int_add(json_addr,
12419 "prefixAllowedWarningThresh",
12420 p->pmax_threshold[afi][safi]);
12421 if (p->pmax_restart[afi][safi])
12422 json_object_int_add(
12423 json_addr,
12424 "prefixAllowedRestartIntervalMsecs",
12425 p->pmax_restart[afi][safi] * 60000);
12426 }
2986cac2 12427 json_object_object_add(json_neigh,
36235319 12428 get_afi_safi_str(afi, safi, true),
d62a17ae 12429 json_addr);
12430
12431 } else {
12432 filter = &p->filter[afi][safi];
12433
12434 vty_out(vty, " For address family: %s\n",
5cb5f4d0 12435 get_afi_safi_str(afi, safi, false));
d62a17ae 12436
12437 if (peer_group_active(p))
12438 vty_out(vty, " %s peer-group member\n",
12439 p->group->name);
12440
12441 paf = peer_af_find(p, afi, safi);
12442 if (paf && PAF_SUBGRP(paf)) {
6cde4b45 12443 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
d62a17ae 12444 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12445 vty_out(vty, " Packet Queue length %d\n",
12446 bpacket_queue_virtual_length(paf));
12447 } else {
12448 vty_out(vty, " Not part of any update group\n");
12449 }
12450 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12451 || CHECK_FLAG(p->af_cap[afi][safi],
12452 PEER_CAP_ORF_PREFIX_SM_RCV)
12453 || CHECK_FLAG(p->af_cap[afi][safi],
12454 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12455 || CHECK_FLAG(p->af_cap[afi][safi],
12456 PEER_CAP_ORF_PREFIX_RM_ADV)
12457 || CHECK_FLAG(p->af_cap[afi][safi],
12458 PEER_CAP_ORF_PREFIX_RM_RCV)
12459 || CHECK_FLAG(p->af_cap[afi][safi],
12460 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12461 vty_out(vty, " AF-dependant capabilities:\n");
12462
12463 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12464 || CHECK_FLAG(p->af_cap[afi][safi],
12465 PEER_CAP_ORF_PREFIX_SM_RCV)
12466 || CHECK_FLAG(p->af_cap[afi][safi],
12467 PEER_CAP_ORF_PREFIX_RM_ADV)
12468 || CHECK_FLAG(p->af_cap[afi][safi],
12469 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12470 vty_out(vty,
12471 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12472 ORF_TYPE_PREFIX);
12473 bgp_show_peer_afi_orf_cap(
12474 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12475 PEER_CAP_ORF_PREFIX_RM_ADV,
12476 PEER_CAP_ORF_PREFIX_SM_RCV,
12477 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12478 }
12479 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12480 || CHECK_FLAG(p->af_cap[afi][safi],
12481 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12482 || CHECK_FLAG(p->af_cap[afi][safi],
12483 PEER_CAP_ORF_PREFIX_RM_ADV)
12484 || CHECK_FLAG(p->af_cap[afi][safi],
12485 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12486 vty_out(vty,
12487 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12488 ORF_TYPE_PREFIX_OLD);
12489 bgp_show_peer_afi_orf_cap(
12490 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12491 PEER_CAP_ORF_PREFIX_RM_ADV,
12492 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12493 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12494 }
12495
772270f3
QY
12496 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12497 p->host, afi, safi);
d62a17ae 12498 orf_pfx_count = prefix_bgp_show_prefix_list(
12499 NULL, afi, orf_pfx_name, use_json);
12500
12501 if (CHECK_FLAG(p->af_sflags[afi][safi],
12502 PEER_STATUS_ORF_PREFIX_SEND)
12503 || orf_pfx_count) {
12504 vty_out(vty, " Outbound Route Filter (ORF):");
12505 if (CHECK_FLAG(p->af_sflags[afi][safi],
12506 PEER_STATUS_ORF_PREFIX_SEND))
12507 vty_out(vty, " sent;");
12508 if (orf_pfx_count)
12509 vty_out(vty, " received (%d entries)",
12510 orf_pfx_count);
12511 vty_out(vty, "\n");
12512 }
12513 if (CHECK_FLAG(p->af_sflags[afi][safi],
12514 PEER_STATUS_ORF_WAIT_REFRESH))
12515 vty_out(vty,
12516 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12517
12518 if (CHECK_FLAG(p->af_flags[afi][safi],
12519 PEER_FLAG_REFLECTOR_CLIENT))
12520 vty_out(vty, " Route-Reflector Client\n");
12521 if (CHECK_FLAG(p->af_flags[afi][safi],
12522 PEER_FLAG_RSERVER_CLIENT))
12523 vty_out(vty, " Route-Server Client\n");
12524 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12525 vty_out(vty,
12526 " Inbound soft reconfiguration allowed\n");
12527
12528 if (CHECK_FLAG(p->af_flags[afi][safi],
12529 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12530 vty_out(vty,
12531 " Private AS numbers (all) replaced in updates to this neighbor\n");
12532 else if (CHECK_FLAG(p->af_flags[afi][safi],
12533 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12534 vty_out(vty,
12535 " Private AS numbers replaced in updates to this neighbor\n");
12536 else if (CHECK_FLAG(p->af_flags[afi][safi],
12537 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12538 vty_out(vty,
12539 " Private AS numbers (all) removed in updates to this neighbor\n");
12540 else if (CHECK_FLAG(p->af_flags[afi][safi],
12541 PEER_FLAG_REMOVE_PRIVATE_AS))
12542 vty_out(vty,
12543 " Private AS numbers removed in updates to this neighbor\n");
12544
dcc68b5e
MS
12545 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12546 vty_out(vty, " %s\n",
12547 bgp_addpath_names(p->addpath_type[afi][safi])
12548 ->human_description);
d62a17ae 12549
12550 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12551 vty_out(vty,
12552 " Override ASNs in outbound updates if aspath equals remote-as\n");
12553
12554 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12555 || CHECK_FLAG(p->af_flags[afi][safi],
12556 PEER_FLAG_FORCE_NEXTHOP_SELF))
12557 vty_out(vty, " NEXT_HOP is always this router\n");
12558 if (CHECK_FLAG(p->af_flags[afi][safi],
12559 PEER_FLAG_AS_PATH_UNCHANGED))
12560 vty_out(vty,
12561 " AS_PATH is propagated unchanged to this neighbor\n");
12562 if (CHECK_FLAG(p->af_flags[afi][safi],
12563 PEER_FLAG_NEXTHOP_UNCHANGED))
12564 vty_out(vty,
12565 " NEXT_HOP is propagated unchanged to this neighbor\n");
12566 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12567 vty_out(vty,
12568 " MED is propagated unchanged to this neighbor\n");
12569 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12570 || CHECK_FLAG(p->af_flags[afi][safi],
12571 PEER_FLAG_SEND_EXT_COMMUNITY)
12572 || CHECK_FLAG(p->af_flags[afi][safi],
12573 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12574 vty_out(vty,
12575 " Community attribute sent to this neighbor");
12576 if (CHECK_FLAG(p->af_flags[afi][safi],
12577 PEER_FLAG_SEND_COMMUNITY)
12578 && CHECK_FLAG(p->af_flags[afi][safi],
12579 PEER_FLAG_SEND_EXT_COMMUNITY)
12580 && CHECK_FLAG(p->af_flags[afi][safi],
12581 PEER_FLAG_SEND_LARGE_COMMUNITY))
12582 vty_out(vty, "(all)\n");
12583 else if (CHECK_FLAG(p->af_flags[afi][safi],
12584 PEER_FLAG_SEND_LARGE_COMMUNITY))
12585 vty_out(vty, "(large)\n");
12586 else if (CHECK_FLAG(p->af_flags[afi][safi],
12587 PEER_FLAG_SEND_EXT_COMMUNITY))
12588 vty_out(vty, "(extended)\n");
12589 else
12590 vty_out(vty, "(standard)\n");
12591 }
12592 if (CHECK_FLAG(p->af_flags[afi][safi],
12593 PEER_FLAG_DEFAULT_ORIGINATE)) {
12594 vty_out(vty, " Default information originate,");
12595
12596 if (p->default_rmap[afi][safi].name)
12597 vty_out(vty, " default route-map %s%s,",
12598 p->default_rmap[afi][safi].map ? "*"
12599 : "",
12600 p->default_rmap[afi][safi].name);
12601 if (paf && PAF_SUBGRP(paf)
12602 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12603 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12604 vty_out(vty, " default sent\n");
12605 else
12606 vty_out(vty, " default not sent\n");
12607 }
12608
dff8f48d
MK
12609 /* advertise-vni-all */
12610 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 12611 if (is_evpn_enabled())
dff8f48d
MK
12612 vty_out(vty, " advertise-all-vni\n");
12613 }
12614
d62a17ae 12615 if (filter->plist[FILTER_IN].name
12616 || filter->dlist[FILTER_IN].name
12617 || filter->aslist[FILTER_IN].name
12618 || filter->map[RMAP_IN].name)
12619 vty_out(vty, " Inbound path policy configured\n");
12620 if (filter->plist[FILTER_OUT].name
12621 || filter->dlist[FILTER_OUT].name
12622 || filter->aslist[FILTER_OUT].name
12623 || filter->map[RMAP_OUT].name || filter->usmap.name)
12624 vty_out(vty, " Outbound path policy configured\n");
12625
12626 /* prefix-list */
12627 if (filter->plist[FILTER_IN].name)
12628 vty_out(vty,
12629 " Incoming update prefix filter list is %s%s\n",
12630 filter->plist[FILTER_IN].plist ? "*" : "",
12631 filter->plist[FILTER_IN].name);
12632 if (filter->plist[FILTER_OUT].name)
12633 vty_out(vty,
12634 " Outgoing update prefix filter list is %s%s\n",
12635 filter->plist[FILTER_OUT].plist ? "*" : "",
12636 filter->plist[FILTER_OUT].name);
12637
12638 /* distribute-list */
12639 if (filter->dlist[FILTER_IN].name)
12640 vty_out(vty,
12641 " Incoming update network filter list is %s%s\n",
12642 filter->dlist[FILTER_IN].alist ? "*" : "",
12643 filter->dlist[FILTER_IN].name);
12644 if (filter->dlist[FILTER_OUT].name)
12645 vty_out(vty,
12646 " Outgoing update network filter list is %s%s\n",
12647 filter->dlist[FILTER_OUT].alist ? "*" : "",
12648 filter->dlist[FILTER_OUT].name);
12649
12650 /* filter-list. */
12651 if (filter->aslist[FILTER_IN].name)
12652 vty_out(vty,
12653 " Incoming update AS path filter list is %s%s\n",
12654 filter->aslist[FILTER_IN].aslist ? "*" : "",
12655 filter->aslist[FILTER_IN].name);
12656 if (filter->aslist[FILTER_OUT].name)
12657 vty_out(vty,
12658 " Outgoing update AS path filter list is %s%s\n",
12659 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12660 filter->aslist[FILTER_OUT].name);
12661
12662 /* route-map. */
12663 if (filter->map[RMAP_IN].name)
12664 vty_out(vty,
12665 " Route map for incoming advertisements is %s%s\n",
12666 filter->map[RMAP_IN].map ? "*" : "",
12667 filter->map[RMAP_IN].name);
12668 if (filter->map[RMAP_OUT].name)
12669 vty_out(vty,
12670 " Route map for outgoing advertisements is %s%s\n",
12671 filter->map[RMAP_OUT].map ? "*" : "",
12672 filter->map[RMAP_OUT].name);
12673
9dac9fc8 12674 /* ebgp-requires-policy (inbound) */
1d3fdccf 12675 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12676 && !bgp_inbound_policy_exists(p, filter))
12677 vty_out(vty,
12678 " Inbound updates discarded due to missing policy\n");
12679
12680 /* ebgp-requires-policy (outbound) */
1d3fdccf 12681 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
9dac9fc8
DA
12682 && !bgp_outbound_policy_exists(p, filter))
12683 vty_out(vty,
12684 " Outbound updates discarded due to missing policy\n");
12685
d62a17ae 12686 /* unsuppress-map */
12687 if (filter->usmap.name)
12688 vty_out(vty,
12689 " Route map for selective unsuppress is %s%s\n",
12690 filter->usmap.map ? "*" : "",
12691 filter->usmap.name);
12692
7f7940e6
MK
12693 /* advertise-map */
12694 if (filter->advmap.aname && filter->advmap.cname)
12695 vty_out(vty,
12696 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12697 filter->advmap.condition ? "EXIST"
12698 : "NON_EXIST",
12699 filter->advmap.cmap ? "*" : "",
12700 filter->advmap.cname,
12701 filter->advmap.amap ? "*" : "",
12702 filter->advmap.aname,
fa36596c 12703 filter->advmap.update_type == ADVERTISE
c385f82a
MK
12704 ? "Advertise"
12705 : "Withdraw");
7f7940e6 12706
d62a17ae 12707 /* Receive prefix count */
6cde4b45 12708 vty_out(vty, " %u accepted prefixes\n",
a0a87037 12709 p->pcount[afi][safi]);
d62a17ae 12710
fde246e8
DA
12711 /* maximum-prefix-out */
12712 if (CHECK_FLAG(p->af_flags[afi][safi],
12713 PEER_FLAG_MAX_PREFIX_OUT))
12714 vty_out(vty,
6cde4b45 12715 " Maximum allowed prefixes sent %u\n",
fde246e8
DA
12716 p->pmax_out[afi][safi]);
12717
d62a17ae 12718 /* Maximum prefix */
12719 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
a0a87037 12720 vty_out(vty,
6cde4b45 12721 " Maximum prefixes allowed %u%s\n",
d62a17ae 12722 p->pmax[afi][safi],
12723 CHECK_FLAG(p->af_flags[afi][safi],
12724 PEER_FLAG_MAX_PREFIX_WARNING)
12725 ? " (warning-only)"
12726 : "");
12727 vty_out(vty, " Threshold for warning message %d%%",
12728 p->pmax_threshold[afi][safi]);
12729 if (p->pmax_restart[afi][safi])
12730 vty_out(vty, ", restart interval %d min",
12731 p->pmax_restart[afi][safi]);
12732 vty_out(vty, "\n");
12733 }
12734
12735 vty_out(vty, "\n");
12736 }
12737}
12738
9f049418 12739static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
d62a17ae 12740 json_object *json)
718e3744 12741{
d62a17ae 12742 struct bgp *bgp;
12743 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12744 char timebuf[BGP_UPTIME_LEN];
12745 char dn_flag[2];
d62a17ae 12746 afi_t afi;
12747 safi_t safi;
d7c0a89a
QY
12748 uint16_t i;
12749 uint8_t *msg;
d62a17ae 12750 json_object *json_neigh = NULL;
12751 time_t epoch_tbuf;
4ab46701 12752 uint32_t sync_tcp_mss;
718e3744 12753
d62a17ae 12754 bgp = p->bgp;
12755
12756 if (use_json)
12757 json_neigh = json_object_new_object();
12758
12759 memset(dn_flag, '\0', sizeof(dn_flag));
12760 if (!p->conf_if && peer_dynamic_neighbor(p))
12761 dn_flag[0] = '*';
12762
12763 if (!use_json) {
12764 if (p->conf_if) /* Configured interface name. */
12765 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12766 BGP_PEER_SU_UNSPEC(p)
12767 ? "None"
12768 : sockunion2str(&p->su, buf,
12769 SU_ADDRSTRLEN));
12770 else /* Configured IP address. */
12771 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12772 p->host);
12773 }
12774
12775 if (use_json) {
12776 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12777 json_object_string_add(json_neigh, "bgpNeighborAddr",
12778 "none");
12779 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12780 json_object_string_add(
12781 json_neigh, "bgpNeighborAddr",
12782 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12783
12784 json_object_int_add(json_neigh, "remoteAs", p->as);
12785
12786 if (p->change_local_as)
12787 json_object_int_add(json_neigh, "localAs",
12788 p->change_local_as);
12789 else
12790 json_object_int_add(json_neigh, "localAs", p->local_as);
12791
12792 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12793 json_object_boolean_true_add(json_neigh,
12794 "localAsNoPrepend");
12795
12796 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12797 json_object_boolean_true_add(json_neigh,
12798 "localAsReplaceAs");
12799 } else {
12800 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12801 || (p->as_type == AS_INTERNAL))
12802 vty_out(vty, "remote AS %u, ", p->as);
12803 else
12804 vty_out(vty, "remote AS Unspecified, ");
12805 vty_out(vty, "local AS %u%s%s, ",
12806 p->change_local_as ? p->change_local_as : p->local_as,
12807 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12808 ? " no-prepend"
12809 : "",
12810 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12811 ? " replace-as"
12812 : "");
12813 }
faa16034
DS
12814 /* peer type internal or confed-internal */
12815 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
d62a17ae 12816 if (use_json) {
12817 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12818 json_object_boolean_true_add(
12819 json_neigh, "nbrConfedInternalLink");
12820 else
12821 json_object_boolean_true_add(json_neigh,
12822 "nbrInternalLink");
12823 } else {
12824 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12825 vty_out(vty, "confed-internal link\n");
12826 else
12827 vty_out(vty, "internal link\n");
12828 }
faa16034
DS
12829 /* peer type external or confed-external */
12830 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
d62a17ae 12831 if (use_json) {
12832 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12833 json_object_boolean_true_add(
12834 json_neigh, "nbrConfedExternalLink");
12835 else
12836 json_object_boolean_true_add(json_neigh,
12837 "nbrExternalLink");
12838 } else {
12839 if (bgp_confederation_peers_check(bgp, p->as))
12840 vty_out(vty, "confed-external link\n");
12841 else
12842 vty_out(vty, "external link\n");
12843 }
faa16034
DS
12844 } else {
12845 if (use_json)
12846 json_object_boolean_true_add(json_neigh,
12847 "nbrUnspecifiedLink");
12848 else
12849 vty_out(vty, "unspecified link\n");
d62a17ae 12850 }
12851
12852 /* Description. */
12853 if (p->desc) {
12854 if (use_json)
12855 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12856 else
12857 vty_out(vty, " Description: %s\n", p->desc);
12858 }
12859
12860 if (p->hostname) {
12861 if (use_json) {
12862 if (p->hostname)
12863 json_object_string_add(json_neigh, "hostname",
12864 p->hostname);
12865
12866 if (p->domainname)
12867 json_object_string_add(json_neigh, "domainname",
12868 p->domainname);
12869 } else {
12870 if (p->domainname && (p->domainname[0] != '\0'))
12871 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12872 p->domainname);
12873 else
12874 vty_out(vty, "Hostname: %s\n", p->hostname);
12875 }
12876 }
12877
12878 /* Peer-group */
12879 if (p->group) {
12880 if (use_json) {
12881 json_object_string_add(json_neigh, "peerGroup",
12882 p->group->name);
12883
12884 if (dn_flag[0]) {
12885 struct prefix prefix, *range = NULL;
12886
0154d8ce
DS
12887 if (sockunion2hostprefix(&(p->su), &prefix))
12888 range = peer_group_lookup_dynamic_neighbor_range(
12889 p->group, &prefix);
d62a17ae 12890
12891 if (range) {
12892 prefix2str(range, buf1, sizeof(buf1));
12893 json_object_string_add(
12894 json_neigh,
12895 "peerSubnetRangeGroup", buf1);
12896 }
12897 }
12898 } else {
12899 vty_out(vty,
12900 " Member of peer-group %s for session parameters\n",
12901 p->group->name);
12902
12903 if (dn_flag[0]) {
12904 struct prefix prefix, *range = NULL;
12905
0154d8ce
DS
12906 if (sockunion2hostprefix(&(p->su), &prefix))
12907 range = peer_group_lookup_dynamic_neighbor_range(
12908 p->group, &prefix);
d62a17ae 12909
12910 if (range) {
d62a17ae 12911 vty_out(vty,
1b78780b
DL
12912 " Belongs to the subnet range group: %pFX\n",
12913 range);
d62a17ae 12914 }
12915 }
12916 }
12917 }
12918
12919 if (use_json) {
12920 /* Administrative shutdown. */
cb9196e7
DS
12921 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12922 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 12923 json_object_boolean_true_add(json_neigh,
12924 "adminShutDown");
12925
12926 /* BGP Version. */
12927 json_object_int_add(json_neigh, "bgpVersion", 4);
12928 json_object_string_add(
12929 json_neigh, "remoteRouterId",
12930 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
d0086e8e
AD
12931 json_object_string_add(
12932 json_neigh, "localRouterId",
12933 inet_ntop(AF_INET, &bgp->router_id, buf1,
12934 sizeof(buf1)));
d62a17ae 12935
12936 /* Confederation */
12937 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12938 && bgp_confederation_peers_check(bgp, p->as))
12939 json_object_boolean_true_add(json_neigh,
12940 "nbrCommonAdmin");
12941
12942 /* Status. */
12943 json_object_string_add(
12944 json_neigh, "bgpState",
12945 lookup_msg(bgp_status_msg, p->status, NULL));
12946
12947 if (p->status == Established) {
12948 time_t uptime;
d62a17ae 12949
12950 uptime = bgp_clock();
12951 uptime -= p->uptime;
d62a17ae 12952 epoch_tbuf = time(NULL) - uptime;
12953
d3c7efed
DS
12954 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12955 uptime * 1000);
d62a17ae 12956 json_object_string_add(json_neigh, "bgpTimerUpString",
12957 peer_uptime(p->uptime, timebuf,
12958 BGP_UPTIME_LEN, 0,
12959 NULL));
12960 json_object_int_add(json_neigh,
12961 "bgpTimerUpEstablishedEpoch",
12962 epoch_tbuf);
12963 }
12964
12965 else if (p->status == Active) {
12966 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12967 json_object_string_add(json_neigh, "bgpStateIs",
12968 "passive");
12969 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12970 json_object_string_add(json_neigh, "bgpStateIs",
12971 "passiveNSF");
12972 }
12973
12974 /* read timer */
12975 time_t uptime;
a2700b50 12976 struct tm tm;
d62a17ae 12977
12978 uptime = bgp_clock();
12979 uptime -= p->readtime;
a2700b50
MS
12980 gmtime_r(&uptime, &tm);
12981
d62a17ae 12982 json_object_int_add(json_neigh, "bgpTimerLastRead",
a2700b50
MS
12983 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12984 + (tm.tm_hour * 3600000));
d62a17ae 12985
12986 uptime = bgp_clock();
12987 uptime -= p->last_write;
a2700b50
MS
12988 gmtime_r(&uptime, &tm);
12989
d62a17ae 12990 json_object_int_add(json_neigh, "bgpTimerLastWrite",
a2700b50
MS
12991 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12992 + (tm.tm_hour * 3600000));
d62a17ae 12993
12994 uptime = bgp_clock();
12995 uptime -= p->update_time;
a2700b50
MS
12996 gmtime_r(&uptime, &tm);
12997
d62a17ae 12998 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
a2700b50
MS
12999 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
13000 + (tm.tm_hour * 3600000));
d62a17ae 13001
13002 /* Configured timer values. */
13003 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
13004 p->v_holdtime * 1000);
13005 json_object_int_add(json_neigh,
13006 "bgpTimerKeepAliveIntervalMsecs",
13007 p->v_keepalive * 1000);
d43114f3
DS
13008 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
13009 json_object_int_add(json_neigh,
13010 "bgpTimerDelayOpenTimeMsecs",
13011 p->v_delayopen * 1000);
13012 }
13013
4ab46701
AR
13014 /* Configured and Synced tcp-mss value for peer */
13015 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13016 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13017 json_object_int_add(json_neigh, "bgpTcpMssConfigured",
13018 p->tcp_mss);
13019 json_object_int_add(json_neigh, "bgpTcpMssSynced",
13020 sync_tcp_mss);
13021 }
13022
b90a8e13 13023 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 13024 json_object_int_add(json_neigh,
13025 "bgpTimerConfiguredHoldTimeMsecs",
13026 p->holdtime * 1000);
13027 json_object_int_add(
13028 json_neigh,
13029 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13030 p->keepalive * 1000);
5d5393b9
DL
13031 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13032 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
13033 json_object_int_add(json_neigh,
13034 "bgpTimerConfiguredHoldTimeMsecs",
13035 bgp->default_holdtime);
13036 json_object_int_add(
13037 json_neigh,
13038 "bgpTimerConfiguredKeepAliveIntervalMsecs",
13039 bgp->default_keepalive);
d62a17ae 13040 }
13041 } else {
13042 /* Administrative shutdown. */
cb9196e7
DS
13043 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
13044 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 13045 vty_out(vty, " Administratively shut down\n");
13046
13047 /* BGP Version. */
13048 vty_out(vty, " BGP version 4");
0e38aeb4 13049 vty_out(vty, ", remote router ID %s",
d62a17ae 13050 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
0e38aeb4
AD
13051 vty_out(vty, ", local router ID %s\n",
13052 inet_ntop(AF_INET, &bgp->router_id, buf1,
13053 sizeof(buf1)));
d62a17ae 13054
13055 /* Confederation */
13056 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
13057 && bgp_confederation_peers_check(bgp, p->as))
13058 vty_out(vty,
13059 " Neighbor under common administration\n");
13060
13061 /* Status. */
13062 vty_out(vty, " BGP state = %s",
13063 lookup_msg(bgp_status_msg, p->status, NULL));
13064
13065 if (p->status == Established)
13066 vty_out(vty, ", up for %8s",
13067 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
13068 0, NULL));
13069
13070 else if (p->status == Active) {
13071 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
13072 vty_out(vty, " (passive)");
13073 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
13074 vty_out(vty, " (NSF passive)");
13075 }
13076 vty_out(vty, "\n");
13077
13078 /* read timer */
13079 vty_out(vty, " Last read %s",
13080 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
13081 NULL));
13082 vty_out(vty, ", Last write %s\n",
13083 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
13084 NULL));
13085
13086 /* Configured timer values. */
13087 vty_out(vty,
13088 " Hold time is %d, keepalive interval is %d seconds\n",
13089 p->v_holdtime, p->v_keepalive);
b90a8e13 13090 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
d62a17ae 13091 vty_out(vty, " Configured hold time is %d",
13092 p->holdtime);
13093 vty_out(vty, ", keepalive interval is %d seconds\n",
13094 p->keepalive);
5d5393b9
DL
13095 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
13096 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
d25e4efc
DS
13097 vty_out(vty, " Configured hold time is %d",
13098 bgp->default_holdtime);
13099 vty_out(vty, ", keepalive interval is %d seconds\n",
13100 bgp->default_keepalive);
d62a17ae 13101 }
d43114f3
DS
13102 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
13103 vty_out(vty,
13104 " Configured DelayOpenTime is %d seconds\n",
13105 p->delayopen);
4ab46701
AR
13106
13107 /* Configured and synced tcp-mss value for peer */
13108 if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) {
13109 sync_tcp_mss = sockopt_tcp_mss_get(p->fd);
13110 vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss);
13111 vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss);
13112 }
d62a17ae 13113 }
13114 /* Capability. */
13115 if (p->status == Established) {
13116 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
13117 || p->afc_recv[AFI_IP][SAFI_UNICAST]
13118 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
13119 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
13120 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
13121 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
13122 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
13123 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
13124 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
13125 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
13126 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
13127 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7c40bf39 13128 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
13129 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
d62a17ae 13130 || p->afc_adv[AFI_IP][SAFI_ENCAP]
13131 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7c40bf39 13132 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
13133 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
d62a17ae 13134 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
13135 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
13136 if (use_json) {
13137 json_object *json_cap = NULL;
13138
13139 json_cap = json_object_new_object();
13140
13141 /* AS4 */
13142 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13143 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13144 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
13145 && CHECK_FLAG(p->cap,
13146 PEER_CAP_AS4_RCV))
13147 json_object_string_add(
13148 json_cap, "4byteAs",
13149 "advertisedAndReceived");
13150 else if (CHECK_FLAG(p->cap,
13151 PEER_CAP_AS4_ADV))
13152 json_object_string_add(
13153 json_cap, "4byteAs",
13154 "advertised");
13155 else if (CHECK_FLAG(p->cap,
13156 PEER_CAP_AS4_RCV))
13157 json_object_string_add(
13158 json_cap, "4byteAs",
13159 "received");
13160 }
13161
ef56aee4
DA
13162 /* Extended Message Support */
13163 if (CHECK_FLAG(p->cap,
13164 PEER_CAP_EXTENDED_MESSAGE_ADV)
13165 && CHECK_FLAG(
13166 p->cap,
13167 PEER_CAP_EXTENDED_MESSAGE_RCV))
13168 json_object_string_add(
13169 json_cap, "extendedMessage",
13170 "advertisedAndReceived");
13171 else if (CHECK_FLAG(
13172 p->cap,
13173 PEER_CAP_EXTENDED_MESSAGE_ADV))
13174 json_object_string_add(
13175 json_cap, "extendedMessage",
13176 "advertised");
13177 else if (CHECK_FLAG(
13178 p->cap,
13179 PEER_CAP_EXTENDED_MESSAGE_RCV))
13180 json_object_string_add(
13181 json_cap, "extendedMessage",
13182 "received");
13183
d62a17ae 13184 /* AddPath */
13185 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13186 || CHECK_FLAG(p->cap,
13187 PEER_CAP_ADDPATH_ADV)) {
13188 json_object *json_add = NULL;
13189 const char *print_store;
13190
13191 json_add = json_object_new_object();
13192
05c7a1cc
QY
13193 FOREACH_AFI_SAFI (afi, safi) {
13194 json_object *json_sub = NULL;
13195 json_sub =
13196 json_object_new_object();
5cb5f4d0
DD
13197 print_store = get_afi_safi_str(
13198 afi, safi, true);
d62a17ae 13199
05c7a1cc
QY
13200 if (CHECK_FLAG(
13201 p->af_cap[afi]
13202 [safi],
13203 PEER_CAP_ADDPATH_AF_TX_ADV)
13204 || CHECK_FLAG(
13205 p->af_cap[afi]
13206 [safi],
13207 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 13208 if (CHECK_FLAG(
13209 p->af_cap
13210 [afi]
13211 [safi],
13212 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 13213 && CHECK_FLAG(
d62a17ae 13214 p->af_cap
13215 [afi]
13216 [safi],
05c7a1cc
QY
13217 PEER_CAP_ADDPATH_AF_TX_RCV))
13218 json_object_boolean_true_add(
13219 json_sub,
13220 "txAdvertisedAndReceived");
13221 else if (
13222 CHECK_FLAG(
13223 p->af_cap
13224 [afi]
13225 [safi],
13226 PEER_CAP_ADDPATH_AF_TX_ADV))
13227 json_object_boolean_true_add(
13228 json_sub,
13229 "txAdvertised");
13230 else if (
13231 CHECK_FLAG(
13232 p->af_cap
13233 [afi]
13234 [safi],
13235 PEER_CAP_ADDPATH_AF_TX_RCV))
13236 json_object_boolean_true_add(
13237 json_sub,
13238 "txReceived");
13239 }
d62a17ae 13240
05c7a1cc
QY
13241 if (CHECK_FLAG(
13242 p->af_cap[afi]
13243 [safi],
13244 PEER_CAP_ADDPATH_AF_RX_ADV)
13245 || CHECK_FLAG(
13246 p->af_cap[afi]
13247 [safi],
13248 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 13249 if (CHECK_FLAG(
13250 p->af_cap
13251 [afi]
13252 [safi],
13253 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 13254 && CHECK_FLAG(
d62a17ae 13255 p->af_cap
13256 [afi]
13257 [safi],
13258 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
13259 json_object_boolean_true_add(
13260 json_sub,
13261 "rxAdvertisedAndReceived");
13262 else if (
13263 CHECK_FLAG(
13264 p->af_cap
13265 [afi]
13266 [safi],
13267 PEER_CAP_ADDPATH_AF_RX_ADV))
13268 json_object_boolean_true_add(
13269 json_sub,
13270 "rxAdvertised");
13271 else if (
13272 CHECK_FLAG(
13273 p->af_cap
13274 [afi]
13275 [safi],
13276 PEER_CAP_ADDPATH_AF_RX_RCV))
13277 json_object_boolean_true_add(
13278 json_sub,
13279 "rxReceived");
d62a17ae 13280 }
13281
05c7a1cc
QY
13282 if (CHECK_FLAG(
13283 p->af_cap[afi]
13284 [safi],
13285 PEER_CAP_ADDPATH_AF_TX_ADV)
13286 || CHECK_FLAG(
13287 p->af_cap[afi]
13288 [safi],
13289 PEER_CAP_ADDPATH_AF_TX_RCV)
13290 || CHECK_FLAG(
13291 p->af_cap[afi]
13292 [safi],
13293 PEER_CAP_ADDPATH_AF_RX_ADV)
13294 || CHECK_FLAG(
13295 p->af_cap[afi]
13296 [safi],
13297 PEER_CAP_ADDPATH_AF_RX_RCV))
13298 json_object_object_add(
13299 json_add,
13300 print_store,
13301 json_sub);
13302 else
13303 json_object_free(
13304 json_sub);
13305 }
13306
d62a17ae 13307 json_object_object_add(
13308 json_cap, "addPath", json_add);
13309 }
13310
13311 /* Dynamic */
13312 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13313 || CHECK_FLAG(p->cap,
13314 PEER_CAP_DYNAMIC_ADV)) {
13315 if (CHECK_FLAG(p->cap,
13316 PEER_CAP_DYNAMIC_ADV)
13317 && CHECK_FLAG(p->cap,
13318 PEER_CAP_DYNAMIC_RCV))
13319 json_object_string_add(
13320 json_cap, "dynamic",
13321 "advertisedAndReceived");
13322 else if (CHECK_FLAG(
13323 p->cap,
13324 PEER_CAP_DYNAMIC_ADV))
13325 json_object_string_add(
13326 json_cap, "dynamic",
13327 "advertised");
13328 else if (CHECK_FLAG(
13329 p->cap,
13330 PEER_CAP_DYNAMIC_RCV))
13331 json_object_string_add(
13332 json_cap, "dynamic",
13333 "received");
13334 }
13335
13336 /* Extended nexthop */
13337 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13338 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13339 json_object *json_nxt = NULL;
13340 const char *print_store;
13341
13342
13343 if (CHECK_FLAG(p->cap,
13344 PEER_CAP_ENHE_ADV)
13345 && CHECK_FLAG(p->cap,
13346 PEER_CAP_ENHE_RCV))
13347 json_object_string_add(
13348 json_cap,
13349 "extendedNexthop",
13350 "advertisedAndReceived");
13351 else if (CHECK_FLAG(p->cap,
13352 PEER_CAP_ENHE_ADV))
13353 json_object_string_add(
13354 json_cap,
13355 "extendedNexthop",
13356 "advertised");
13357 else if (CHECK_FLAG(p->cap,
13358 PEER_CAP_ENHE_RCV))
13359 json_object_string_add(
13360 json_cap,
13361 "extendedNexthop",
13362 "received");
13363
13364 if (CHECK_FLAG(p->cap,
13365 PEER_CAP_ENHE_RCV)) {
13366 json_nxt =
13367 json_object_new_object();
13368
13369 for (safi = SAFI_UNICAST;
13370 safi < SAFI_MAX; safi++) {
13371 if (CHECK_FLAG(
13372 p->af_cap
13373 [AFI_IP]
13374 [safi],
13375 PEER_CAP_ENHE_AF_RCV)) {
5cb5f4d0 13376 print_store = get_afi_safi_str(
d62a17ae 13377 AFI_IP,
5cb5f4d0 13378 safi, true);
d62a17ae 13379 json_object_string_add(
13380 json_nxt,
13381 print_store,
54f29523 13382 "recieved"); /* misspelled for compatibility */
d62a17ae 13383 }
13384 }
13385 json_object_object_add(
13386 json_cap,
13387 "extendedNexthopFamililesByPeer",
13388 json_nxt);
13389 }
13390 }
13391
13392 /* Route Refresh */
13393 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13394 || CHECK_FLAG(p->cap,
13395 PEER_CAP_REFRESH_NEW_RCV)
13396 || CHECK_FLAG(p->cap,
13397 PEER_CAP_REFRESH_OLD_RCV)) {
13398 if (CHECK_FLAG(p->cap,
13399 PEER_CAP_REFRESH_ADV)
13400 && (CHECK_FLAG(
13401 p->cap,
13402 PEER_CAP_REFRESH_NEW_RCV)
13403 || CHECK_FLAG(
13404 p->cap,
13405 PEER_CAP_REFRESH_OLD_RCV))) {
13406 if (CHECK_FLAG(
13407 p->cap,
13408 PEER_CAP_REFRESH_OLD_RCV)
13409 && CHECK_FLAG(
13410 p->cap,
13411 PEER_CAP_REFRESH_NEW_RCV))
13412 json_object_string_add(
13413 json_cap,
13414 "routeRefresh",
13415 "advertisedAndReceivedOldNew");
13416 else {
13417 if (CHECK_FLAG(
13418 p->cap,
13419 PEER_CAP_REFRESH_OLD_RCV))
13420 json_object_string_add(
13421 json_cap,
13422 "routeRefresh",
13423 "advertisedAndReceivedOld");
13424 else
13425 json_object_string_add(
13426 json_cap,
13427 "routeRefresh",
13428 "advertisedAndReceivedNew");
13429 }
13430 } else if (
13431 CHECK_FLAG(
13432 p->cap,
13433 PEER_CAP_REFRESH_ADV))
13434 json_object_string_add(
13435 json_cap,
13436 "routeRefresh",
13437 "advertised");
13438 else if (
13439 CHECK_FLAG(
13440 p->cap,
13441 PEER_CAP_REFRESH_NEW_RCV)
13442 || CHECK_FLAG(
13443 p->cap,
13444 PEER_CAP_REFRESH_OLD_RCV))
13445 json_object_string_add(
13446 json_cap,
13447 "routeRefresh",
13448 "received");
13449 }
13450
9af52ccf
DA
13451 /* Enhanced Route Refresh */
13452 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13453 || CHECK_FLAG(p->cap,
13454 PEER_CAP_ENHANCED_RR_RCV)) {
13455 if (CHECK_FLAG(p->cap,
13456 PEER_CAP_ENHANCED_RR_ADV)
13457 && CHECK_FLAG(
13458 p->cap,
13459 PEER_CAP_ENHANCED_RR_RCV))
13460 json_object_string_add(
13461 json_cap,
13462 "enhancedRouteRefresh",
13463 "advertisedAndReceived");
13464 else if (
13465 CHECK_FLAG(
13466 p->cap,
13467 PEER_CAP_ENHANCED_RR_ADV))
13468 json_object_string_add(
13469 json_cap,
13470 "enhancedRouteRefresh",
13471 "advertised");
13472 else if (
13473 CHECK_FLAG(
13474 p->cap,
13475 PEER_CAP_ENHANCED_RR_RCV))
13476 json_object_string_add(
13477 json_cap,
13478 "enhancedRouteRefresh",
13479 "received");
13480 }
13481
d62a17ae 13482 /* Multiprotocol Extensions */
13483 json_object *json_multi = NULL;
13484 json_multi = json_object_new_object();
13485
05c7a1cc
QY
13486 FOREACH_AFI_SAFI (afi, safi) {
13487 if (p->afc_adv[afi][safi]
13488 || p->afc_recv[afi][safi]) {
13489 json_object *json_exten = NULL;
13490 json_exten =
13491 json_object_new_object();
13492
d62a17ae 13493 if (p->afc_adv[afi][safi]
05c7a1cc
QY
13494 && p->afc_recv[afi][safi])
13495 json_object_boolean_true_add(
13496 json_exten,
13497 "advertisedAndReceived");
13498 else if (p->afc_adv[afi][safi])
13499 json_object_boolean_true_add(
13500 json_exten,
13501 "advertised");
13502 else if (p->afc_recv[afi][safi])
13503 json_object_boolean_true_add(
13504 json_exten,
13505 "received");
d62a17ae 13506
05c7a1cc
QY
13507 json_object_object_add(
13508 json_multi,
5cb5f4d0
DD
13509 get_afi_safi_str(afi,
13510 safi,
13511 true),
05c7a1cc 13512 json_exten);
d62a17ae 13513 }
13514 }
13515 json_object_object_add(
13516 json_cap, "multiprotocolExtensions",
13517 json_multi);
13518
d77114b7 13519 /* Hostname capabilities */
60466a63 13520 json_object *json_hname = NULL;
d77114b7
MK
13521
13522 json_hname = json_object_new_object();
13523
13524 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13525 json_object_string_add(
60466a63
QY
13526 json_hname, "advHostName",
13527 bgp->peer_self->hostname
13528 ? bgp->peer_self
13529 ->hostname
d77114b7
MK
13530 : "n/a");
13531 json_object_string_add(
60466a63
QY
13532 json_hname, "advDomainName",
13533 bgp->peer_self->domainname
13534 ? bgp->peer_self
13535 ->domainname
d77114b7
MK
13536 : "n/a");
13537 }
13538
13539
13540 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13541 json_object_string_add(
60466a63
QY
13542 json_hname, "rcvHostName",
13543 p->hostname ? p->hostname
13544 : "n/a");
d77114b7 13545 json_object_string_add(
60466a63
QY
13546 json_hname, "rcvDomainName",
13547 p->domainname ? p->domainname
13548 : "n/a");
d77114b7
MK
13549 }
13550
60466a63 13551 json_object_object_add(json_cap, "hostName",
d77114b7
MK
13552 json_hname);
13553
d62a17ae 13554 /* Gracefull Restart */
13555 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13556 || CHECK_FLAG(p->cap,
13557 PEER_CAP_RESTART_ADV)) {
13558 if (CHECK_FLAG(p->cap,
13559 PEER_CAP_RESTART_ADV)
13560 && CHECK_FLAG(p->cap,
13561 PEER_CAP_RESTART_RCV))
13562 json_object_string_add(
13563 json_cap,
13564 "gracefulRestart",
13565 "advertisedAndReceived");
13566 else if (CHECK_FLAG(
13567 p->cap,
13568 PEER_CAP_RESTART_ADV))
13569 json_object_string_add(
13570 json_cap,
13571 "gracefulRestartCapability",
13572 "advertised");
13573 else if (CHECK_FLAG(
13574 p->cap,
13575 PEER_CAP_RESTART_RCV))
13576 json_object_string_add(
13577 json_cap,
13578 "gracefulRestartCapability",
13579 "received");
13580
13581 if (CHECK_FLAG(p->cap,
13582 PEER_CAP_RESTART_RCV)) {
13583 int restart_af_count = 0;
13584 json_object *json_restart =
13585 NULL;
13586 json_restart =
13587 json_object_new_object();
13588
13589 json_object_int_add(
13590 json_cap,
13591 "gracefulRestartRemoteTimerMsecs",
13592 p->v_gr_restart * 1000);
13593
05c7a1cc
QY
13594 FOREACH_AFI_SAFI (afi, safi) {
13595 if (CHECK_FLAG(
13596 p->af_cap
13597 [afi]
13598 [safi],
13599 PEER_CAP_RESTART_AF_RCV)) {
13600 json_object *
13601 json_sub =
13602 NULL;
13603 json_sub =
13604 json_object_new_object();
13605
d62a17ae 13606 if (CHECK_FLAG(
13607 p->af_cap
13608 [afi]
13609 [safi],
05c7a1cc
QY
13610 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13611 json_object_boolean_true_add(
13612 json_sub,
13613 "preserved");
13614 restart_af_count++;
13615 json_object_object_add(
13616 json_restart,
5cb5f4d0 13617 get_afi_safi_str(
05c7a1cc 13618 afi,
5cb5f4d0
DD
13619 safi,
13620 true),
05c7a1cc 13621 json_sub);
d62a17ae 13622 }
13623 }
13624 if (!restart_af_count) {
13625 json_object_string_add(
13626 json_cap,
13627 "addressFamiliesByPeer",
13628 "none");
13629 json_object_free(
13630 json_restart);
13631 } else
13632 json_object_object_add(
13633 json_cap,
13634 "addressFamiliesByPeer",
13635 json_restart);
13636 }
13637 }
13638 json_object_object_add(json_neigh,
13639 "neighborCapabilities",
13640 json_cap);
13641 } else {
13642 vty_out(vty, " Neighbor capabilities:\n");
13643
13644 /* AS4 */
13645 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13646 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13647 vty_out(vty, " 4 Byte AS:");
13648 if (CHECK_FLAG(p->cap,
13649 PEER_CAP_AS4_ADV))
13650 vty_out(vty, " advertised");
13651 if (CHECK_FLAG(p->cap,
13652 PEER_CAP_AS4_RCV))
13653 vty_out(vty, " %sreceived",
13654 CHECK_FLAG(
13655 p->cap,
13656 PEER_CAP_AS4_ADV)
13657 ? "and "
13658 : "");
13659 vty_out(vty, "\n");
13660 }
13661
ef56aee4
DA
13662 /* Extended Message Support */
13663 if (CHECK_FLAG(p->cap,
13664 PEER_CAP_EXTENDED_MESSAGE_RCV)
13665 || CHECK_FLAG(
13666 p->cap,
13667 PEER_CAP_EXTENDED_MESSAGE_ADV)) {
13668 vty_out(vty, " Extended Message:");
13669 if (CHECK_FLAG(
13670 p->cap,
13671 PEER_CAP_EXTENDED_MESSAGE_ADV))
13672 vty_out(vty, " advertised");
13673 if (CHECK_FLAG(
13674 p->cap,
13675 PEER_CAP_EXTENDED_MESSAGE_RCV))
13676 vty_out(vty, " %sreceived",
13677 CHECK_FLAG(
13678 p->cap,
13679 PEER_CAP_EXTENDED_MESSAGE_ADV)
13680 ? "and "
13681 : "");
13682 vty_out(vty, "\n");
13683 }
13684
d62a17ae 13685 /* AddPath */
13686 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13687 || CHECK_FLAG(p->cap,
13688 PEER_CAP_ADDPATH_ADV)) {
13689 vty_out(vty, " AddPath:\n");
13690
05c7a1cc
QY
13691 FOREACH_AFI_SAFI (afi, safi) {
13692 if (CHECK_FLAG(
13693 p->af_cap[afi]
13694 [safi],
13695 PEER_CAP_ADDPATH_AF_TX_ADV)
13696 || CHECK_FLAG(
13697 p->af_cap[afi]
13698 [safi],
13699 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13700 vty_out(vty,
13701 " %s: TX ",
5cb5f4d0 13702 get_afi_safi_str(
05c7a1cc 13703 afi,
5cb5f4d0
DD
13704 safi,
13705 false));
05c7a1cc 13706
d62a17ae 13707 if (CHECK_FLAG(
13708 p->af_cap
13709 [afi]
13710 [safi],
05c7a1cc 13711 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 13712 vty_out(vty,
05c7a1cc 13713 "advertised %s",
5cb5f4d0 13714 get_afi_safi_str(
d62a17ae 13715 afi,
5cb5f4d0
DD
13716 safi,
13717 false));
d62a17ae 13718
05c7a1cc
QY
13719 if (CHECK_FLAG(
13720 p->af_cap
13721 [afi]
13722 [safi],
13723 PEER_CAP_ADDPATH_AF_TX_RCV))
13724 vty_out(vty,
13725 "%sreceived",
13726 CHECK_FLAG(
13727 p->af_cap
13728 [afi]
13729 [safi],
13730 PEER_CAP_ADDPATH_AF_TX_ADV)
13731 ? " and "
13732 : "");
d62a17ae 13733
05c7a1cc
QY
13734 vty_out(vty, "\n");
13735 }
d62a17ae 13736
05c7a1cc
QY
13737 if (CHECK_FLAG(
13738 p->af_cap[afi]
13739 [safi],
13740 PEER_CAP_ADDPATH_AF_RX_ADV)
13741 || CHECK_FLAG(
13742 p->af_cap[afi]
13743 [safi],
13744 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13745 vty_out(vty,
13746 " %s: RX ",
5cb5f4d0 13747 get_afi_safi_str(
05c7a1cc 13748 afi,
5cb5f4d0
DD
13749 safi,
13750 false));
d62a17ae 13751
13752 if (CHECK_FLAG(
13753 p->af_cap
13754 [afi]
13755 [safi],
05c7a1cc 13756 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 13757 vty_out(vty,
05c7a1cc 13758 "advertised %s",
5cb5f4d0 13759 get_afi_safi_str(
d62a17ae 13760 afi,
5cb5f4d0
DD
13761 safi,
13762 false));
d62a17ae 13763
05c7a1cc
QY
13764 if (CHECK_FLAG(
13765 p->af_cap
13766 [afi]
13767 [safi],
13768 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 13769 vty_out(vty,
05c7a1cc
QY
13770 "%sreceived",
13771 CHECK_FLAG(
13772 p->af_cap
13773 [afi]
13774 [safi],
13775 PEER_CAP_ADDPATH_AF_RX_ADV)
13776 ? " and "
13777 : "");
13778
13779 vty_out(vty, "\n");
d62a17ae 13780 }
05c7a1cc 13781 }
d62a17ae 13782 }
13783
13784 /* Dynamic */
13785 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13786 || CHECK_FLAG(p->cap,
13787 PEER_CAP_DYNAMIC_ADV)) {
13788 vty_out(vty, " Dynamic:");
13789 if (CHECK_FLAG(p->cap,
13790 PEER_CAP_DYNAMIC_ADV))
13791 vty_out(vty, " advertised");
13792 if (CHECK_FLAG(p->cap,
13793 PEER_CAP_DYNAMIC_RCV))
13794 vty_out(vty, " %sreceived",
13795 CHECK_FLAG(
13796 p->cap,
13797 PEER_CAP_DYNAMIC_ADV)
13798 ? "and "
13799 : "");
13800 vty_out(vty, "\n");
13801 }
13802
13803 /* Extended nexthop */
13804 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13805 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13806 vty_out(vty, " Extended nexthop:");
13807 if (CHECK_FLAG(p->cap,
13808 PEER_CAP_ENHE_ADV))
13809 vty_out(vty, " advertised");
13810 if (CHECK_FLAG(p->cap,
13811 PEER_CAP_ENHE_RCV))
13812 vty_out(vty, " %sreceived",
13813 CHECK_FLAG(
13814 p->cap,
13815 PEER_CAP_ENHE_ADV)
13816 ? "and "
13817 : "");
13818 vty_out(vty, "\n");
13819
13820 if (CHECK_FLAG(p->cap,
13821 PEER_CAP_ENHE_RCV)) {
13822 vty_out(vty,
13823 " Address families by peer:\n ");
13824 for (safi = SAFI_UNICAST;
13825 safi < SAFI_MAX; safi++)
13826 if (CHECK_FLAG(
13827 p->af_cap
13828 [AFI_IP]
13829 [safi],
13830 PEER_CAP_ENHE_AF_RCV))
13831 vty_out(vty,
13832 " %s\n",
5cb5f4d0 13833 get_afi_safi_str(
d62a17ae 13834 AFI_IP,
5cb5f4d0
DD
13835 safi,
13836 false));
d62a17ae 13837 }
13838 }
13839
13840 /* Route Refresh */
13841 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13842 || CHECK_FLAG(p->cap,
13843 PEER_CAP_REFRESH_NEW_RCV)
13844 || CHECK_FLAG(p->cap,
13845 PEER_CAP_REFRESH_OLD_RCV)) {
13846 vty_out(vty, " Route refresh:");
13847 if (CHECK_FLAG(p->cap,
13848 PEER_CAP_REFRESH_ADV))
13849 vty_out(vty, " advertised");
13850 if (CHECK_FLAG(p->cap,
13851 PEER_CAP_REFRESH_NEW_RCV)
13852 || CHECK_FLAG(
13853 p->cap,
13854 PEER_CAP_REFRESH_OLD_RCV))
13855 vty_out(vty, " %sreceived(%s)",
13856 CHECK_FLAG(
13857 p->cap,
13858 PEER_CAP_REFRESH_ADV)
13859 ? "and "
13860 : "",
13861 (CHECK_FLAG(
13862 p->cap,
13863 PEER_CAP_REFRESH_OLD_RCV)
13864 && CHECK_FLAG(
13865 p->cap,
13866 PEER_CAP_REFRESH_NEW_RCV))
13867 ? "old & new"
13868 : CHECK_FLAG(
13869 p->cap,
13870 PEER_CAP_REFRESH_OLD_RCV)
13871 ? "old"
13872 : "new");
13873
13874 vty_out(vty, "\n");
13875 }
13876
9af52ccf
DA
13877 /* Enhanced Route Refresh */
13878 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13879 || CHECK_FLAG(p->cap,
13880 PEER_CAP_ENHANCED_RR_RCV)) {
13881 vty_out(vty,
13882 " Enhanced Route Refresh:");
13883 if (CHECK_FLAG(
13884 p->cap,
13885 PEER_CAP_ENHANCED_RR_ADV))
13886 vty_out(vty, " advertised");
13887 if (CHECK_FLAG(
13888 p->cap,
13889 PEER_CAP_ENHANCED_RR_RCV))
13890 vty_out(vty, " %sreceived",
13891 CHECK_FLAG(
13892 p->cap,
13893 PEER_CAP_REFRESH_ADV)
13894 ? "and "
13895 : "");
13896 vty_out(vty, "\n");
13897 }
13898
d62a17ae 13899 /* Multiprotocol Extensions */
05c7a1cc
QY
13900 FOREACH_AFI_SAFI (afi, safi)
13901 if (p->afc_adv[afi][safi]
13902 || p->afc_recv[afi][safi]) {
13903 vty_out(vty,
13904 " Address Family %s:",
5cb5f4d0
DD
13905 get_afi_safi_str(
13906 afi,
13907 safi,
13908 false));
05c7a1cc 13909 if (p->afc_adv[afi][safi])
d62a17ae 13910 vty_out(vty,
05c7a1cc
QY
13911 " advertised");
13912 if (p->afc_recv[afi][safi])
13913 vty_out(vty,
13914 " %sreceived",
13915 p->afc_adv[afi]
13916 [safi]
13917 ? "and "
13918 : "");
13919 vty_out(vty, "\n");
13920 }
d62a17ae 13921
13922 /* Hostname capability */
60466a63 13923 vty_out(vty, " Hostname Capability:");
d77114b7
MK
13924
13925 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
13926 vty_out(vty,
13927 " advertised (name: %s,domain name: %s)",
60466a63
QY
13928 bgp->peer_self->hostname
13929 ? bgp->peer_self
13930 ->hostname
d77114b7 13931 : "n/a",
60466a63
QY
13932 bgp->peer_self->domainname
13933 ? bgp->peer_self
13934 ->domainname
d77114b7
MK
13935 : "n/a");
13936 } else {
13937 vty_out(vty, " not advertised");
d62a17ae 13938 }
13939
d77114b7 13940 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
13941 vty_out(vty,
13942 " received (name: %s,domain name: %s)",
60466a63
QY
13943 p->hostname ? p->hostname
13944 : "n/a",
13945 p->domainname ? p->domainname
13946 : "n/a");
d77114b7
MK
13947 } else {
13948 vty_out(vty, " not received");
13949 }
13950
13951 vty_out(vty, "\n");
13952
61bfbd51 13953 /* Graceful Restart */
d62a17ae 13954 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13955 || CHECK_FLAG(p->cap,
13956 PEER_CAP_RESTART_ADV)) {
13957 vty_out(vty,
61bfbd51 13958 " Graceful Restart Capability:");
d62a17ae 13959 if (CHECK_FLAG(p->cap,
13960 PEER_CAP_RESTART_ADV))
13961 vty_out(vty, " advertised");
13962 if (CHECK_FLAG(p->cap,
13963 PEER_CAP_RESTART_RCV))
13964 vty_out(vty, " %sreceived",
13965 CHECK_FLAG(
13966 p->cap,
13967 PEER_CAP_RESTART_ADV)
13968 ? "and "
13969 : "");
13970 vty_out(vty, "\n");
13971
13972 if (CHECK_FLAG(p->cap,
13973 PEER_CAP_RESTART_RCV)) {
13974 int restart_af_count = 0;
13975
13976 vty_out(vty,
13977 " Remote Restart timer is %d seconds\n",
13978 p->v_gr_restart);
13979 vty_out(vty,
13980 " Address families by peer:\n ");
13981
05c7a1cc
QY
13982 FOREACH_AFI_SAFI (afi, safi)
13983 if (CHECK_FLAG(
13984 p->af_cap
13985 [afi]
13986 [safi],
13987 PEER_CAP_RESTART_AF_RCV)) {
13988 vty_out(vty,
13989 "%s%s(%s)",
13990 restart_af_count
13991 ? ", "
13992 : "",
5cb5f4d0 13993 get_afi_safi_str(
05c7a1cc 13994 afi,
5cb5f4d0
DD
13995 safi,
13996 false),
05c7a1cc
QY
13997 CHECK_FLAG(
13998 p->af_cap
13999 [afi]
14000 [safi],
14001 PEER_CAP_RESTART_AF_PRESERVE_RCV)
14002 ? "preserved"
14003 : "not preserved");
14004 restart_af_count++;
14005 }
d62a17ae 14006 if (!restart_af_count)
14007 vty_out(vty, "none");
14008 vty_out(vty, "\n");
14009 }
2986cac2 14010 } /* Gracefull Restart */
d62a17ae 14011 }
14012 }
14013 }
14014
14015 /* graceful restart information */
d62a17ae 14016 json_object *json_grace = NULL;
14017 json_object *json_grace_send = NULL;
14018 json_object *json_grace_recv = NULL;
14019 int eor_send_af_count = 0;
14020 int eor_receive_af_count = 0;
14021
14022 if (use_json) {
14023 json_grace = json_object_new_object();
14024 json_grace_send = json_object_new_object();
14025 json_grace_recv = json_object_new_object();
14026
36235319
QY
14027 if ((p->status == Established)
14028 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
05c7a1cc
QY
14029 FOREACH_AFI_SAFI (afi, safi) {
14030 if (CHECK_FLAG(p->af_sflags[afi][safi],
36235319 14031 PEER_STATUS_EOR_SEND)) {
05c7a1cc
QY
14032 json_object_boolean_true_add(
14033 json_grace_send,
5cb5f4d0
DD
14034 get_afi_safi_str(afi,
14035 safi,
14036 true));
05c7a1cc 14037 eor_send_af_count++;
d62a17ae 14038 }
14039 }
05c7a1cc
QY
14040 FOREACH_AFI_SAFI (afi, safi) {
14041 if (CHECK_FLAG(
36235319
QY
14042 p->af_sflags[afi][safi],
14043 PEER_STATUS_EOR_RECEIVED)) {
05c7a1cc
QY
14044 json_object_boolean_true_add(
14045 json_grace_recv,
5cb5f4d0
DD
14046 get_afi_safi_str(afi,
14047 safi,
14048 true));
05c7a1cc 14049 eor_receive_af_count++;
d62a17ae 14050 }
14051 }
14052 }
36235319
QY
14053 json_object_object_add(json_grace, "endOfRibSend",
14054 json_grace_send);
14055 json_object_object_add(json_grace, "endOfRibRecv",
14056 json_grace_recv);
d62a17ae 14057
d62a17ae 14058
14059 if (p->t_gr_restart)
14060 json_object_int_add(json_grace,
14061 "gracefulRestartTimerMsecs",
14062 thread_timer_remain_second(
14063 p->t_gr_restart)
14064 * 1000);
14065
14066 if (p->t_gr_stale)
14067 json_object_int_add(
14068 json_grace,
14069 "gracefulStalepathTimerMsecs",
14070 thread_timer_remain_second(
14071 p->t_gr_stale)
14072 * 1000);
2986cac2 14073 /* more gr info in new format */
14074 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
36235319 14075 json_grace);
d62a17ae 14076 json_object_object_add(
14077 json_neigh, "gracefulRestartInfo", json_grace);
14078 } else {
2089dd80 14079 vty_out(vty, " Graceful restart information:\n");
36235319
QY
14080 if ((p->status == Established)
14081 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
2986cac2 14082
d62a17ae 14083 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
14084 FOREACH_AFI_SAFI (afi, safi) {
14085 if (CHECK_FLAG(p->af_sflags[afi][safi],
14086 PEER_STATUS_EOR_SEND)) {
14087 vty_out(vty, "%s%s",
14088 eor_send_af_count ? ", "
14089 : "",
36235319
QY
14090 get_afi_safi_str(
14091 afi, safi,
14092 false));
05c7a1cc 14093 eor_send_af_count++;
d62a17ae 14094 }
14095 }
14096 vty_out(vty, "\n");
14097 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
14098 FOREACH_AFI_SAFI (afi, safi) {
14099 if (CHECK_FLAG(
14100 p->af_sflags[afi][safi],
14101 PEER_STATUS_EOR_RECEIVED)) {
14102 vty_out(vty, "%s%s",
14103 eor_receive_af_count
14104 ? ", "
14105 : "",
5cb5f4d0
DD
14106 get_afi_safi_str(afi,
14107 safi,
14108 false));
05c7a1cc 14109 eor_receive_af_count++;
d62a17ae 14110 }
14111 }
14112 vty_out(vty, "\n");
14113 }
14114
14115 if (p->t_gr_restart)
14116 vty_out(vty,
14117 " The remaining time of restart timer is %ld\n",
14118 thread_timer_remain_second(
14119 p->t_gr_restart));
14120
14121 if (p->t_gr_stale)
14122 vty_out(vty,
14123 " The remaining time of stalepath timer is %ld\n",
14124 thread_timer_remain_second(
14125 p->t_gr_stale));
2986cac2 14126
14127 /* more gr info in new format */
14128 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
d62a17ae 14129 }
2986cac2 14130
d62a17ae 14131 if (use_json) {
14132 json_object *json_stat = NULL;
14133 json_stat = json_object_new_object();
14134 /* Packet counts. */
43aa5965
QY
14135
14136 atomic_size_t outq_count, inq_count;
14137 outq_count = atomic_load_explicit(&p->obuf->count,
14138 memory_order_relaxed);
14139 inq_count = atomic_load_explicit(&p->ibuf->count,
14140 memory_order_relaxed);
14141
14142 json_object_int_add(json_stat, "depthInq",
14143 (unsigned long)inq_count);
d62a17ae 14144 json_object_int_add(json_stat, "depthOutq",
43aa5965 14145 (unsigned long)outq_count);
0112e9e0
QY
14146 json_object_int_add(json_stat, "opensSent",
14147 atomic_load_explicit(&p->open_out,
14148 memory_order_relaxed));
14149 json_object_int_add(json_stat, "opensRecv",
14150 atomic_load_explicit(&p->open_in,
14151 memory_order_relaxed));
d62a17ae 14152 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
14153 atomic_load_explicit(&p->notify_out,
14154 memory_order_relaxed));
d62a17ae 14155 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
14156 atomic_load_explicit(&p->notify_in,
14157 memory_order_relaxed));
14158 json_object_int_add(json_stat, "updatesSent",
14159 atomic_load_explicit(&p->update_out,
14160 memory_order_relaxed));
14161 json_object_int_add(json_stat, "updatesRecv",
14162 atomic_load_explicit(&p->update_in,
14163 memory_order_relaxed));
d62a17ae 14164 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
14165 atomic_load_explicit(&p->keepalive_out,
14166 memory_order_relaxed));
d62a17ae 14167 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
14168 atomic_load_explicit(&p->keepalive_in,
14169 memory_order_relaxed));
d62a17ae 14170 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
14171 atomic_load_explicit(&p->refresh_out,
14172 memory_order_relaxed));
d62a17ae 14173 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
14174 atomic_load_explicit(&p->refresh_in,
14175 memory_order_relaxed));
d62a17ae 14176 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
14177 atomic_load_explicit(&p->dynamic_cap_out,
14178 memory_order_relaxed));
d62a17ae 14179 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
14180 atomic_load_explicit(&p->dynamic_cap_in,
14181 memory_order_relaxed));
14182 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
14183 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 14184 json_object_object_add(json_neigh, "messageStats", json_stat);
14185 } else {
43aa5965
QY
14186 atomic_size_t outq_count, inq_count;
14187 outq_count = atomic_load_explicit(&p->obuf->count,
14188 memory_order_relaxed);
14189 inq_count = atomic_load_explicit(&p->ibuf->count,
14190 memory_order_relaxed);
14191
d62a17ae 14192 /* Packet counts. */
14193 vty_out(vty, " Message statistics:\n");
43aa5965
QY
14194 vty_out(vty, " Inq depth is %zu\n", inq_count);
14195 vty_out(vty, " Outq depth is %zu\n", outq_count);
d62a17ae 14196 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
14197 vty_out(vty, " Opens: %10d %10d\n",
14198 atomic_load_explicit(&p->open_out,
14199 memory_order_relaxed),
14200 atomic_load_explicit(&p->open_in,
14201 memory_order_relaxed));
14202 vty_out(vty, " Notifications: %10d %10d\n",
14203 atomic_load_explicit(&p->notify_out,
14204 memory_order_relaxed),
14205 atomic_load_explicit(&p->notify_in,
14206 memory_order_relaxed));
14207 vty_out(vty, " Updates: %10d %10d\n",
14208 atomic_load_explicit(&p->update_out,
14209 memory_order_relaxed),
14210 atomic_load_explicit(&p->update_in,
14211 memory_order_relaxed));
14212 vty_out(vty, " Keepalives: %10d %10d\n",
14213 atomic_load_explicit(&p->keepalive_out,
14214 memory_order_relaxed),
14215 atomic_load_explicit(&p->keepalive_in,
14216 memory_order_relaxed));
14217 vty_out(vty, " Route Refresh: %10d %10d\n",
14218 atomic_load_explicit(&p->refresh_out,
14219 memory_order_relaxed),
14220 atomic_load_explicit(&p->refresh_in,
14221 memory_order_relaxed));
d62a17ae 14222 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
14223 atomic_load_explicit(&p->dynamic_cap_out,
14224 memory_order_relaxed),
14225 atomic_load_explicit(&p->dynamic_cap_in,
14226 memory_order_relaxed));
14227 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
14228 PEER_TOTAL_RX(p));
d62a17ae 14229 }
14230
14231 if (use_json) {
14232 /* advertisement-interval */
14233 json_object_int_add(json_neigh,
14234 "minBtwnAdvertisementRunsTimerMsecs",
14235 p->v_routeadv * 1000);
14236
14237 /* Update-source. */
14238 if (p->update_if || p->update_source) {
14239 if (p->update_if)
14240 json_object_string_add(json_neigh,
14241 "updateSource",
14242 p->update_if);
14243 else if (p->update_source)
14244 json_object_string_add(
14245 json_neigh, "updateSource",
14246 sockunion2str(p->update_source, buf1,
14247 SU_ADDRSTRLEN));
14248 }
14249 } else {
14250 /* advertisement-interval */
14251 vty_out(vty,
14252 " Minimum time between advertisement runs is %d seconds\n",
14253 p->v_routeadv);
14254
14255 /* Update-source. */
14256 if (p->update_if || p->update_source) {
14257 vty_out(vty, " Update source is ");
14258 if (p->update_if)
14259 vty_out(vty, "%s", p->update_if);
14260 else if (p->update_source)
14261 vty_out(vty, "%s",
14262 sockunion2str(p->update_source, buf1,
14263 SU_ADDRSTRLEN));
14264 vty_out(vty, "\n");
14265 }
14266
14267 vty_out(vty, "\n");
14268 }
14269
14270 /* Address Family Information */
14271 json_object *json_hold = NULL;
14272
14273 if (use_json)
14274 json_hold = json_object_new_object();
14275
05c7a1cc
QY
14276 FOREACH_AFI_SAFI (afi, safi)
14277 if (p->afc[afi][safi])
14278 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14279 json_hold);
d62a17ae 14280
14281 if (use_json) {
14282 json_object_object_add(json_neigh, "addressFamilyInfo",
14283 json_hold);
14284 json_object_int_add(json_neigh, "connectionsEstablished",
14285 p->established);
14286 json_object_int_add(json_neigh, "connectionsDropped",
14287 p->dropped);
14288 } else
14289 vty_out(vty, " Connections established %d; dropped %d\n",
14290 p->established, p->dropped);
14291
14292 if (!p->last_reset) {
14293 if (use_json)
14294 json_object_string_add(json_neigh, "lastReset",
14295 "never");
14296 else
14297 vty_out(vty, " Last reset never\n");
14298 } else {
14299 if (use_json) {
14300 time_t uptime;
a2700b50 14301 struct tm tm;
d62a17ae 14302
14303 uptime = bgp_clock();
14304 uptime -= p->resettime;
a2700b50
MS
14305 gmtime_r(&uptime, &tm);
14306
d62a17ae 14307 json_object_int_add(json_neigh, "lastResetTimerMsecs",
a2700b50
MS
14308 (tm.tm_sec * 1000)
14309 + (tm.tm_min * 60000)
14310 + (tm.tm_hour * 3600000));
3577f1c5 14311 bgp_show_peer_reset(NULL, p, json_neigh, true);
d62a17ae 14312 } else {
14313 vty_out(vty, " Last reset %s, ",
14314 peer_uptime(p->resettime, timebuf,
14315 BGP_UPTIME_LEN, 0, NULL));
14316
3577f1c5 14317 bgp_show_peer_reset(vty, p, NULL, false);
d62a17ae 14318 if (p->last_reset_cause_size) {
14319 msg = p->last_reset_cause;
14320 vty_out(vty,
14321 " Message received that caused BGP to send a NOTIFICATION:\n ");
14322 for (i = 1; i <= p->last_reset_cause_size;
14323 i++) {
14324 vty_out(vty, "%02X", *msg++);
14325
14326 if (i != p->last_reset_cause_size) {
14327 if (i % 16 == 0) {
14328 vty_out(vty, "\n ");
14329 } else if (i % 4 == 0) {
14330 vty_out(vty, " ");
14331 }
14332 }
14333 }
14334 vty_out(vty, "\n");
14335 }
14336 }
14337 }
14338
14339 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14340 if (use_json)
14341 json_object_boolean_true_add(json_neigh,
14342 "prefixesConfigExceedMax");
14343 else
14344 vty_out(vty,
14345 " Peer had exceeded the max. no. of prefixes configured.\n");
14346
14347 if (p->t_pmax_restart) {
14348 if (use_json) {
14349 json_object_boolean_true_add(
14350 json_neigh, "reducePrefixNumFrom");
14351 json_object_int_add(json_neigh,
14352 "restartInTimerMsec",
14353 thread_timer_remain_second(
14354 p->t_pmax_restart)
14355 * 1000);
14356 } else
14357 vty_out(vty,
14358 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
14359 p->host, thread_timer_remain_second(
14360 p->t_pmax_restart));
d62a17ae 14361 } else {
14362 if (use_json)
14363 json_object_boolean_true_add(
14364 json_neigh,
14365 "reducePrefixNumAndClearIpBgp");
14366 else
14367 vty_out(vty,
14368 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14369 p->host);
14370 }
14371 }
14372
14373 /* EBGP Multihop and GTSM */
14374 if (p->sort != BGP_PEER_IBGP) {
14375 if (use_json) {
e2521429 14376 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14377 json_object_int_add(json_neigh,
14378 "externalBgpNbrMaxHopsAway",
14379 p->gtsm_hops);
c8d6f0d6 14380 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14381 json_object_int_add(json_neigh,
14382 "externalBgpNbrMaxHopsAway",
14383 p->ttl);
14384 } else {
e2521429 14385 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
d62a17ae 14386 vty_out(vty,
14387 " External BGP neighbor may be up to %d hops away.\n",
14388 p->gtsm_hops);
c8d6f0d6 14389 else if (p->ttl > BGP_DEFAULT_TTL)
d62a17ae 14390 vty_out(vty,
14391 " External BGP neighbor may be up to %d hops away.\n",
14392 p->ttl);
14393 }
14394 } else {
e2521429 14395 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
d62a17ae 14396 if (use_json)
14397 json_object_int_add(json_neigh,
14398 "internalBgpNbrMaxHopsAway",
14399 p->gtsm_hops);
14400 else
14401 vty_out(vty,
14402 " Internal BGP neighbor may be up to %d hops away.\n",
14403 p->gtsm_hops);
14404 }
14405 }
14406
14407 /* Local address. */
14408 if (p->su_local) {
14409 if (use_json) {
14410 json_object_string_add(json_neigh, "hostLocal",
14411 sockunion2str(p->su_local, buf1,
14412 SU_ADDRSTRLEN));
14413 json_object_int_add(json_neigh, "portLocal",
14414 ntohs(p->su_local->sin.sin_port));
14415 } else
14416 vty_out(vty, "Local host: %s, Local port: %d\n",
14417 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14418 ntohs(p->su_local->sin.sin_port));
14419 }
14420
14421 /* Remote address. */
14422 if (p->su_remote) {
14423 if (use_json) {
14424 json_object_string_add(json_neigh, "hostForeign",
14425 sockunion2str(p->su_remote, buf1,
14426 SU_ADDRSTRLEN));
14427 json_object_int_add(json_neigh, "portForeign",
14428 ntohs(p->su_remote->sin.sin_port));
14429 } else
14430 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14431 sockunion2str(p->su_remote, buf1,
14432 SU_ADDRSTRLEN),
14433 ntohs(p->su_remote->sin.sin_port));
14434 }
14435
14436 /* Nexthop display. */
14437 if (p->su_local) {
14438 if (use_json) {
14439 json_object_string_add(json_neigh, "nexthop",
14440 inet_ntop(AF_INET,
14441 &p->nexthop.v4, buf1,
14442 sizeof(buf1)));
14443 json_object_string_add(json_neigh, "nexthopGlobal",
14444 inet_ntop(AF_INET6,
14445 &p->nexthop.v6_global,
14446 buf1, sizeof(buf1)));
14447 json_object_string_add(json_neigh, "nexthopLocal",
14448 inet_ntop(AF_INET6,
14449 &p->nexthop.v6_local,
14450 buf1, sizeof(buf1)));
14451 if (p->shared_network)
14452 json_object_string_add(json_neigh,
14453 "bgpConnection",
14454 "sharedNetwork");
14455 else
14456 json_object_string_add(json_neigh,
14457 "bgpConnection",
14458 "nonSharedNetwork");
14459 } else {
14460 vty_out(vty, "Nexthop: %s\n",
14461 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14462 sizeof(buf1)));
14463 vty_out(vty, "Nexthop global: %s\n",
14464 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14465 sizeof(buf1)));
14466 vty_out(vty, "Nexthop local: %s\n",
14467 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14468 sizeof(buf1)));
14469 vty_out(vty, "BGP connection: %s\n",
14470 p->shared_network ? "shared network"
14471 : "non shared network");
14472 }
14473 }
14474
14475 /* Timer information. */
14476 if (use_json) {
14477 json_object_int_add(json_neigh, "connectRetryTimer",
14478 p->v_connect);
14479 if (p->status == Established && p->rtt)
14480 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14481 p->rtt);
14482 if (p->t_start)
14483 json_object_int_add(
14484 json_neigh, "nextStartTimerDueInMsecs",
14485 thread_timer_remain_second(p->t_start) * 1000);
14486 if (p->t_connect)
14487 json_object_int_add(
14488 json_neigh, "nextConnectTimerDueInMsecs",
14489 thread_timer_remain_second(p->t_connect)
14490 * 1000);
14491 if (p->t_routeadv) {
14492 json_object_int_add(json_neigh, "mraiInterval",
14493 p->v_routeadv);
14494 json_object_int_add(
14495 json_neigh, "mraiTimerExpireInMsecs",
14496 thread_timer_remain_second(p->t_routeadv)
14497 * 1000);
14498 }
14499 if (p->password)
14500 json_object_int_add(json_neigh, "authenticationEnabled",
14501 1);
14502
14503 if (p->t_read)
14504 json_object_string_add(json_neigh, "readThread", "on");
14505 else
14506 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
14507
14508 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 14509 json_object_string_add(json_neigh, "writeThread", "on");
14510 else
14511 json_object_string_add(json_neigh, "writeThread",
14512 "off");
14513 } else {
14514 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14515 p->v_connect);
14516 if (p->status == Established && p->rtt)
14517 vty_out(vty, "Estimated round trip time: %d ms\n",
14518 p->rtt);
14519 if (p->t_start)
14520 vty_out(vty, "Next start timer due in %ld seconds\n",
14521 thread_timer_remain_second(p->t_start));
14522 if (p->t_connect)
14523 vty_out(vty, "Next connect timer due in %ld seconds\n",
14524 thread_timer_remain_second(p->t_connect));
14525 if (p->t_routeadv)
14526 vty_out(vty,
14527 "MRAI (interval %u) timer expires in %ld seconds\n",
14528 p->v_routeadv,
14529 thread_timer_remain_second(p->t_routeadv));
14530 if (p->password)
14531 vty_out(vty, "Peer Authentication Enabled\n");
14532
cac9e917 14533 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
49507a6f
QY
14534 p->t_read ? "on" : "off",
14535 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14536 ? "on"
cac9e917 14537 : "off", p->fd);
d62a17ae 14538 }
14539
14540 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14541 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14542 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14543
14544 if (!use_json)
14545 vty_out(vty, "\n");
14546
14547 /* BFD information. */
21bfce98
RZ
14548 if (p->bfd_config)
14549 bgp_bfd_show_info(vty, p, json_neigh);
d62a17ae 14550
14551 if (use_json) {
14552 if (p->conf_if) /* Configured interface name. */
14553 json_object_object_add(json, p->conf_if, json_neigh);
14554 else /* Configured IP address. */
14555 json_object_object_add(json, p->host, json_neigh);
14556 }
14557}
14558
36235319
QY
14559static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14560 enum show_type type,
14561 union sockunion *su,
14562 const char *conf_if, afi_t afi,
74a630b6 14563 bool use_json)
2986cac2 14564{
14565 struct listnode *node, *nnode;
14566 struct peer *peer;
14567 int find = 0;
14568 safi_t safi = SAFI_UNICAST;
74a630b6 14569 json_object *json = NULL;
2986cac2 14570 json_object *json_neighbor = NULL;
14571
74a630b6
NT
14572 if (use_json) {
14573 json = json_object_new_object();
14574 json_neighbor = json_object_new_object();
14575 }
14576
2986cac2 14577 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14578
14579 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14580 continue;
14581
14582 if ((peer->afc[afi][safi]) == 0)
14583 continue;
14584
2ba1fe69 14585 if (type == show_all) {
2986cac2 14586 bgp_show_peer_gr_status(vty, peer, use_json,
13909c4f 14587 json_neighbor);
2986cac2 14588
74a630b6 14589 if (use_json) {
13909c4f
DS
14590 json_object_object_add(json, peer->host,
14591 json_neighbor);
74a630b6
NT
14592 json_neighbor = NULL;
14593 }
2986cac2 14594
2ba1fe69 14595 } else if (type == show_peer) {
2986cac2 14596 if (conf_if) {
14597 if ((peer->conf_if
13909c4f
DS
14598 && !strcmp(peer->conf_if, conf_if))
14599 || (peer->hostname
2986cac2 14600 && !strcmp(peer->hostname, conf_if))) {
14601 find = 1;
13909c4f
DS
14602 bgp_show_peer_gr_status(vty, peer,
14603 use_json,
14604 json_neighbor);
2986cac2 14605 }
14606 } else {
14607 if (sockunion_same(&peer->su, su)) {
14608 find = 1;
13909c4f
DS
14609 bgp_show_peer_gr_status(vty, peer,
14610 use_json,
14611 json_neighbor);
2986cac2 14612 }
14613 }
13909c4f
DS
14614 if (use_json && find)
14615 json_object_object_add(json, peer->host,
14616 json_neighbor);
2986cac2 14617 }
14618
74a630b6
NT
14619 if (find) {
14620 json_neighbor = NULL;
2986cac2 14621 break;
74a630b6 14622 }
2986cac2 14623 }
14624
14625 if (type == show_peer && !find) {
14626 if (use_json)
13909c4f 14627 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
2986cac2 14628 else
14629 vty_out(vty, "%% No such neighbor\n");
14630 }
14631 if (use_json) {
13909c4f
DS
14632 vty_out(vty, "%s\n",
14633 json_object_to_json_string_ext(
14634 json, JSON_C_TO_STRING_PRETTY));
74a630b6
NT
14635
14636 if (json_neighbor)
14637 json_object_free(json_neighbor);
14638 json_object_free(json);
2986cac2 14639 } else {
14640 vty_out(vty, "\n");
14641 }
14642
14643 return CMD_SUCCESS;
14644}
14645
d62a17ae 14646static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14647 enum show_type type, union sockunion *su,
9f049418 14648 const char *conf_if, bool use_json,
d62a17ae 14649 json_object *json)
14650{
14651 struct listnode *node, *nnode;
14652 struct peer *peer;
14653 int find = 0;
9f049418 14654 bool nbr_output = false;
d1927ebe
AS
14655 afi_t afi = AFI_MAX;
14656 safi_t safi = SAFI_MAX;
14657
14658 if (type == show_ipv4_peer || type == show_ipv4_all) {
14659 afi = AFI_IP;
14660 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14661 afi = AFI_IP6;
14662 }
d62a17ae 14663
14664 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14665 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14666 continue;
14667
14668 switch (type) {
14669 case show_all:
14670 bgp_show_peer(vty, peer, use_json, json);
9f049418 14671 nbr_output = true;
d62a17ae 14672 break;
14673 case show_peer:
14674 if (conf_if) {
14675 if ((peer->conf_if
14676 && !strcmp(peer->conf_if, conf_if))
14677 || (peer->hostname
14678 && !strcmp(peer->hostname, conf_if))) {
14679 find = 1;
14680 bgp_show_peer(vty, peer, use_json,
14681 json);
14682 }
14683 } else {
14684 if (sockunion_same(&peer->su, su)) {
14685 find = 1;
14686 bgp_show_peer(vty, peer, use_json,
14687 json);
14688 }
14689 }
14690 break;
d1927ebe
AS
14691 case show_ipv4_peer:
14692 case show_ipv6_peer:
14693 FOREACH_SAFI (safi) {
14694 if (peer->afc[afi][safi]) {
14695 if (conf_if) {
14696 if ((peer->conf_if
14697 && !strcmp(peer->conf_if, conf_if))
14698 || (peer->hostname
14699 && !strcmp(peer->hostname, conf_if))) {
14700 find = 1;
14701 bgp_show_peer(vty, peer, use_json,
14702 json);
14703 break;
14704 }
14705 } else {
14706 if (sockunion_same(&peer->su, su)) {
14707 find = 1;
14708 bgp_show_peer(vty, peer, use_json,
14709 json);
14710 break;
14711 }
14712 }
14713 }
14714 }
14715 break;
14716 case show_ipv4_all:
14717 case show_ipv6_all:
14718 FOREACH_SAFI (safi) {
14719 if (peer->afc[afi][safi]) {
14720 bgp_show_peer(vty, peer, use_json, json);
14721 nbr_output = true;
14722 break;
14723 }
14724 }
14725 break;
d62a17ae 14726 }
14727 }
14728
d1927ebe
AS
14729 if ((type == show_peer || type == show_ipv4_peer ||
14730 type == show_ipv6_peer) && !find) {
d62a17ae 14731 if (use_json)
14732 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14733 else
88b7d255 14734 vty_out(vty, "%% No such neighbor in this view/vrf\n");
d62a17ae 14735 }
14736
d1927ebe
AS
14737 if (type != show_peer && type != show_ipv4_peer &&
14738 type != show_ipv6_peer && !nbr_output && !use_json)
94d4c685 14739 vty_out(vty, "%% No BGP neighbors found\n");
9f049418 14740
d62a17ae 14741 if (use_json) {
996c9314
LB
14742 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14743 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 14744 } else {
14745 vty_out(vty, "\n");
14746 }
14747
14748 return CMD_SUCCESS;
14749}
14750
36235319
QY
14751static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14752 enum show_type type,
14753 const char *ip_str,
14754 afi_t afi, bool use_json)
2986cac2 14755{
14756
14757 int ret;
14758 struct bgp *bgp;
14759 union sockunion su;
2986cac2 14760
14761 bgp = bgp_get_default();
14762
13909c4f
DS
14763 if (!bgp)
14764 return;
2986cac2 14765
13909c4f
DS
14766 if (!use_json)
14767 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14768 NULL);
2986cac2 14769
13909c4f
DS
14770 if (ip_str) {
14771 ret = str2sockunion(ip_str, &su);
14772 if (ret < 0)
13909c4f 14773 bgp_show_neighbor_graceful_restart(
74a630b6
NT
14774 vty, bgp, type, NULL, ip_str, afi, use_json);
14775 else
14776 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14777 NULL, afi, use_json);
13909c4f
DS
14778 } else
14779 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
74a630b6 14780 afi, use_json);
2986cac2 14781}
14782
d62a17ae 14783static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
14784 enum show_type type,
14785 const char *ip_str,
9f049418 14786 bool use_json)
d62a17ae 14787{
0291c246
MK
14788 struct listnode *node, *nnode;
14789 struct bgp *bgp;
71aedaa3 14790 union sockunion su;
0291c246 14791 json_object *json = NULL;
71aedaa3 14792 int ret, is_first = 1;
9f049418 14793 bool nbr_output = false;
d62a17ae 14794
14795 if (use_json)
14796 vty_out(vty, "{\n");
14797
14798 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9f049418 14799 nbr_output = true;
d62a17ae 14800 if (use_json) {
14801 if (!(json = json_object_new_object())) {
af4c2728 14802 flog_err(
e50f7cfd 14803 EC_BGP_JSON_MEM_ERROR,
d62a17ae 14804 "Unable to allocate memory for JSON object");
14805 vty_out(vty,
14806 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14807 return;
14808 }
14809
14810 json_object_int_add(json, "vrfId",
14811 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
14812 ? -1
14813 : (int64_t)bgp->vrf_id);
d62a17ae 14814 json_object_string_add(
14815 json, "vrfName",
14816 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14817 ? VRF_DEFAULT_NAME
d62a17ae 14818 : bgp->name);
14819
14820 if (!is_first)
14821 vty_out(vty, ",\n");
14822 else
14823 is_first = 0;
14824
14825 vty_out(vty, "\"%s\":",
14826 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14827 ? VRF_DEFAULT_NAME
d62a17ae 14828 : bgp->name);
14829 } else {
14830 vty_out(vty, "\nInstance %s:\n",
14831 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 14832 ? VRF_DEFAULT_NAME
d62a17ae 14833 : bgp->name);
14834 }
71aedaa3 14835
d1927ebe
AS
14836 if (type == show_peer || type == show_ipv4_peer ||
14837 type == show_ipv6_peer) {
71aedaa3
DS
14838 ret = str2sockunion(ip_str, &su);
14839 if (ret < 0)
14840 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14841 use_json, json);
14842 else
14843 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14844 use_json, json);
14845 } else {
d1927ebe 14846 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
71aedaa3
DS
14847 use_json, json);
14848 }
b77004d6 14849 json_object_free(json);
121067e9 14850 json = NULL;
d62a17ae 14851 }
14852
3e78a6ce 14853 if (use_json)
d62a17ae 14854 vty_out(vty, "}\n");
9f049418
DS
14855 else if (!nbr_output)
14856 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14857}
14858
14859static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14860 enum show_type type, const char *ip_str,
9f049418 14861 bool use_json)
d62a17ae 14862{
14863 int ret;
14864 struct bgp *bgp;
14865 union sockunion su;
14866 json_object *json = NULL;
14867
14868 if (name) {
14869 if (strmatch(name, "all")) {
71aedaa3
DS
14870 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14871 use_json);
d62a17ae 14872 return CMD_SUCCESS;
14873 } else {
14874 bgp = bgp_lookup_by_name(name);
14875 if (!bgp) {
14876 if (use_json) {
14877 json = json_object_new_object();
d62a17ae 14878 vty_out(vty, "%s\n",
14879 json_object_to_json_string_ext(
14880 json,
14881 JSON_C_TO_STRING_PRETTY));
14882 json_object_free(json);
14883 } else
14884 vty_out(vty,
9f049418 14885 "%% BGP instance not found\n");
d62a17ae 14886
14887 return CMD_WARNING;
14888 }
14889 }
14890 } else {
14891 bgp = bgp_get_default();
14892 }
14893
14894 if (bgp) {
14895 json = json_object_new_object();
14896 if (ip_str) {
14897 ret = str2sockunion(ip_str, &su);
14898 if (ret < 0)
14899 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14900 use_json, json);
14901 else
14902 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14903 use_json, json);
14904 } else {
14905 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14906 json);
14907 }
14908 json_object_free(json);
ca61fd25
DS
14909 } else {
14910 if (use_json)
14911 vty_out(vty, "{}\n");
14912 else
14913 vty_out(vty, "%% BGP instance not found\n");
d62a17ae 14914 }
14915
14916 return CMD_SUCCESS;
4fb25c53
DW
14917}
14918
2986cac2 14919
14920
14921/* "show [ip] bgp neighbors graceful-restart" commands. */
14922DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14923 show_ip_bgp_neighbors_graceful_restart_cmd,
14924 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14925 SHOW_STR
14926 BGP_STR
14927 IP_STR
14928 IPV6_STR
14929 NEIGHBOR_STR
14930 "Neighbor to display information about\n"
14931 "Neighbor to display information about\n"
14932 "Neighbor on BGP configured interface\n"
14933 GR_SHOW
14934 JSON_STR)
14935{
14936 char *sh_arg = NULL;
14937 enum show_type sh_type;
14938 int idx = 0;
14939 afi_t afi = AFI_MAX;
2986cac2 14940 bool uj = use_json(argc, argv);
14941
36235319 14942 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
2986cac2 14943 afi = AFI_MAX;
14944
14945 idx++;
14946
14947 if (argv_find(argv, argc, "A.B.C.D", &idx)
14948 || argv_find(argv, argc, "X:X::X:X", &idx)
14949 || argv_find(argv, argc, "WORD", &idx)) {
14950 sh_type = show_peer;
14951 sh_arg = argv[idx]->arg;
14952 } else
14953 sh_type = show_all;
14954
14955 if (!argv_find(argv, argc, "graceful-restart", &idx))
14956 return CMD_SUCCESS;
14957
14958
36235319
QY
14959 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14960 afi, uj);
2986cac2 14961}
14962
716b2d8a 14963/* "show [ip] bgp neighbors" commands. */
718e3744 14964DEFUN (show_ip_bgp_neighbors,
14965 show_ip_bgp_neighbors_cmd,
24345e82 14966 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 14967 SHOW_STR
14968 IP_STR
14969 BGP_STR
f2a8972b 14970 BGP_INSTANCE_HELP_STR
8c3deaae
QY
14971 "Address Family\n"
14972 "Address Family\n"
718e3744 14973 "Detailed information on TCP and BGP neighbor connections\n"
14974 "Neighbor to display information about\n"
a80beece 14975 "Neighbor to display information about\n"
91d37724 14976 "Neighbor on BGP configured interface\n"
9973d184 14977 JSON_STR)
718e3744 14978{
d62a17ae 14979 char *vrf = NULL;
14980 char *sh_arg = NULL;
14981 enum show_type sh_type;
d1927ebe 14982 afi_t afi = AFI_MAX;
718e3744 14983
9f049418 14984 bool uj = use_json(argc, argv);
718e3744 14985
d62a17ae 14986 int idx = 0;
718e3744 14987
9a8bdf1c
PG
14988 /* [<vrf> VIEWVRFNAME] */
14989 if (argv_find(argv, argc, "vrf", &idx)) {
14990 vrf = argv[idx + 1]->arg;
14991 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14992 vrf = NULL;
14993 } else if (argv_find(argv, argc, "view", &idx))
14994 /* [<view> VIEWVRFNAME] */
d62a17ae 14995 vrf = argv[idx + 1]->arg;
718e3744 14996
d62a17ae 14997 idx++;
d1927ebe
AS
14998
14999 if (argv_find(argv, argc, "ipv4", &idx)) {
15000 sh_type = show_ipv4_all;
15001 afi = AFI_IP;
15002 } else if (argv_find(argv, argc, "ipv6", &idx)) {
15003 sh_type = show_ipv6_all;
15004 afi = AFI_IP6;
15005 } else {
15006 sh_type = show_all;
15007 }
15008
d62a17ae 15009 if (argv_find(argv, argc, "A.B.C.D", &idx)
15010 || argv_find(argv, argc, "X:X::X:X", &idx)
15011 || argv_find(argv, argc, "WORD", &idx)) {
15012 sh_type = show_peer;
15013 sh_arg = argv[idx]->arg;
d1927ebe
AS
15014 }
15015
15016 if (sh_type == show_peer && afi == AFI_IP) {
15017 sh_type = show_ipv4_peer;
15018 } else if (sh_type == show_peer && afi == AFI_IP6) {
15019 sh_type = show_ipv6_peer;
15020 }
856ca177 15021
d62a17ae 15022 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 15023}
15024
716b2d8a 15025/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 15026 paths' and `show ip mbgp paths'. Those functions results are the
15027 same.*/
f412b39a 15028DEFUN (show_ip_bgp_paths,
718e3744 15029 show_ip_bgp_paths_cmd,
46f296b4 15030 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 15031 SHOW_STR
15032 IP_STR
15033 BGP_STR
46f296b4 15034 BGP_SAFI_HELP_STR
718e3744 15035 "Path information\n")
15036{
d62a17ae 15037 vty_out(vty, "Address Refcnt Path\n");
15038 aspath_print_all_vty(vty);
15039 return CMD_SUCCESS;
718e3744 15040}
15041
718e3744 15042#include "hash.h"
15043
e3b78da8 15044static void community_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15045 struct vty *vty)
718e3744 15046{
d62a17ae 15047 struct community *com;
718e3744 15048
e3b78da8 15049 com = (struct community *)bucket->data;
3f65c5b1 15050 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 15051 community_str(com, false));
718e3744 15052}
15053
15054/* Show BGP's community internal data. */
f412b39a 15055DEFUN (show_ip_bgp_community_info,
718e3744 15056 show_ip_bgp_community_info_cmd,
bec37ba5 15057 "show [ip] bgp community-info",
718e3744 15058 SHOW_STR
15059 IP_STR
15060 BGP_STR
15061 "List all bgp community information\n")
15062{
d62a17ae 15063 vty_out(vty, "Address Refcnt Community\n");
718e3744 15064
d62a17ae 15065 hash_iterate(community_hash(),
e3b78da8 15066 (void (*)(struct hash_bucket *,
d62a17ae 15067 void *))community_show_all_iterator,
15068 vty);
718e3744 15069
d62a17ae 15070 return CMD_SUCCESS;
718e3744 15071}
15072
e3b78da8 15073static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
d62a17ae 15074 struct vty *vty)
57d187bc 15075{
d62a17ae 15076 struct lcommunity *lcom;
57d187bc 15077
e3b78da8 15078 lcom = (struct lcommunity *)bucket->data;
3f65c5b1 15079 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
8d9b8ed9 15080 lcommunity_str(lcom, false));
57d187bc
JS
15081}
15082
15083/* Show BGP's community internal data. */
15084DEFUN (show_ip_bgp_lcommunity_info,
15085 show_ip_bgp_lcommunity_info_cmd,
15086 "show ip bgp large-community-info",
15087 SHOW_STR
15088 IP_STR
15089 BGP_STR
15090 "List all bgp large-community information\n")
15091{
d62a17ae 15092 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 15093
d62a17ae 15094 hash_iterate(lcommunity_hash(),
e3b78da8 15095 (void (*)(struct hash_bucket *,
d62a17ae 15096 void *))lcommunity_show_all_iterator,
15097 vty);
57d187bc 15098
d62a17ae 15099 return CMD_SUCCESS;
57d187bc 15100}
2986cac2 15101/* Graceful Restart */
15102
15103static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
36235319
QY
15104 struct bgp *bgp,
15105 bool use_json,
15106 json_object *json)
2986cac2 15107{
57d187bc
JS
15108
15109
2986cac2 15110 vty_out(vty, "\n%s", SHOW_GR_HEADER);
15111
7318ae88 15112 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
2986cac2 15113
15114 switch (bgp_global_gr_mode) {
15115
15116 case GLOBAL_HELPER:
13909c4f 15117 vty_out(vty, "Global BGP GR Mode : Helper\n");
2986cac2 15118 break;
15119
15120 case GLOBAL_GR:
13909c4f 15121 vty_out(vty, "Global BGP GR Mode : Restart\n");
2986cac2 15122 break;
15123
15124 case GLOBAL_DISABLE:
13909c4f 15125 vty_out(vty, "Global BGP GR Mode : Disable\n");
2986cac2 15126 break;
15127
15128 case GLOBAL_INVALID:
2986cac2 15129 vty_out(vty,
2ba1fe69 15130 "Global BGP GR Mode Invalid\n");
2986cac2 15131 break;
15132 }
15133 vty_out(vty, "\n");
15134}
15135
36235319
QY
15136static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
15137 enum show_type type,
15138 const char *ip_str,
15139 afi_t afi, bool use_json)
2986cac2 15140{
15141 if ((afi == AFI_MAX) && (ip_str == NULL)) {
15142 afi = AFI_IP;
15143
15144 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
15145
36235319
QY
15146 bgp_show_neighbor_graceful_restart_vty(
15147 vty, type, ip_str, afi, use_json);
2986cac2 15148 afi++;
15149 }
15150 } else if (afi != AFI_MAX) {
36235319
QY
15151 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
15152 use_json);
2986cac2 15153 } else {
15154 return CMD_ERR_INCOMPLETE;
15155 }
15156
15157 return CMD_SUCCESS;
15158}
15159/* Graceful Restart */
15160
f412b39a 15161DEFUN (show_ip_bgp_attr_info,
718e3744 15162 show_ip_bgp_attr_info_cmd,
bec37ba5 15163 "show [ip] bgp attribute-info",
718e3744 15164 SHOW_STR
15165 IP_STR
15166 BGP_STR
15167 "List all bgp attribute information\n")
15168{
d62a17ae 15169 attr_show_all(vty);
15170 return CMD_SUCCESS;
718e3744 15171}
6b0655a2 15172
03915806
CS
15173static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
15174 afi_t afi, safi_t safi,
15175 bool use_json, json_object *json)
53089bec 15176{
15177 struct bgp *bgp;
15178 struct listnode *node;
15179 char *vname;
15180 char buf1[INET6_ADDRSTRLEN];
15181 char *ecom_str;
15182 vpn_policy_direction_t dir;
15183
03915806 15184 if (json) {
b46dfd20
DS
15185 json_object *json_import_vrfs = NULL;
15186 json_object *json_export_vrfs = NULL;
15187
b46dfd20
DS
15188 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15189
53089bec 15190 if (!bgp) {
b46dfd20
DS
15191 vty_out(vty, "%s\n",
15192 json_object_to_json_string_ext(
15193 json,
15194 JSON_C_TO_STRING_PRETTY));
15195 json_object_free(json);
15196
53089bec 15197 return CMD_WARNING;
15198 }
b46dfd20 15199
94d4c685
DS
15200 /* Provide context for the block */
15201 json_object_string_add(json, "vrf", name ? name : "default");
15202 json_object_string_add(json, "afiSafi",
5cb5f4d0 15203 get_afi_safi_str(afi, safi, true));
94d4c685 15204
b46dfd20
DS
15205 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15206 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
15207 json_object_string_add(json, "importFromVrfs", "none");
15208 json_object_string_add(json, "importRts", "none");
15209 } else {
6ce24e52
DS
15210 json_import_vrfs = json_object_new_array();
15211
b46dfd20
DS
15212 for (ALL_LIST_ELEMENTS_RO(
15213 bgp->vpn_policy[afi].import_vrf,
15214 node, vname))
15215 json_object_array_add(json_import_vrfs,
15216 json_object_new_string(vname));
15217
b20875ea
CS
15218 json_object_object_add(json, "importFromVrfs",
15219 json_import_vrfs);
b46dfd20 15220 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15221 if (bgp->vpn_policy[afi].rtlist[dir]) {
15222 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15223 bgp->vpn_policy[afi].rtlist[dir],
15224 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15225 json_object_string_add(json, "importRts",
15226 ecom_str);
15227 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15228 } else
15229 json_object_string_add(json, "importRts",
15230 "none");
b46dfd20
DS
15231 }
15232
15233 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15234 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
15235 json_object_string_add(json, "exportToVrfs", "none");
15236 json_object_string_add(json, "routeDistinguisher",
15237 "none");
15238 json_object_string_add(json, "exportRts", "none");
15239 } else {
6ce24e52
DS
15240 json_export_vrfs = json_object_new_array();
15241
b46dfd20
DS
15242 for (ALL_LIST_ELEMENTS_RO(
15243 bgp->vpn_policy[afi].export_vrf,
15244 node, vname))
15245 json_object_array_add(json_export_vrfs,
15246 json_object_new_string(vname));
15247 json_object_object_add(json, "exportToVrfs",
15248 json_export_vrfs);
15249 json_object_string_add(json, "routeDistinguisher",
15250 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15251 buf1, RD_ADDRSTRLEN));
15252
15253 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15254 if (bgp->vpn_policy[afi].rtlist[dir]) {
15255 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15256 bgp->vpn_policy[afi].rtlist[dir],
15257 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15258 json_object_string_add(json, "exportRts",
15259 ecom_str);
15260 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15261 } else
15262 json_object_string_add(json, "exportRts",
15263 "none");
b46dfd20
DS
15264 }
15265
03915806
CS
15266 if (use_json) {
15267 vty_out(vty, "%s\n",
15268 json_object_to_json_string_ext(json,
b46dfd20 15269 JSON_C_TO_STRING_PRETTY));
03915806
CS
15270 json_object_free(json);
15271 }
53089bec 15272 } else {
b46dfd20
DS
15273 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15274
53089bec 15275 if (!bgp) {
b46dfd20 15276 vty_out(vty, "%% No such BGP instance exist\n");
53089bec 15277 return CMD_WARNING;
15278 }
53089bec 15279
b46dfd20
DS
15280 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15281 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15282 vty_out(vty,
15283 "This VRF is not importing %s routes from any other VRF\n",
5cb5f4d0 15284 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15285 else {
15286 vty_out(vty,
15287 "This VRF is importing %s routes from the following VRFs:\n",
5cb5f4d0 15288 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15289
15290 for (ALL_LIST_ELEMENTS_RO(
15291 bgp->vpn_policy[afi].import_vrf,
15292 node, vname))
15293 vty_out(vty, " %s\n", vname);
15294
15295 dir = BGP_VPN_POLICY_DIR_FROMVPN;
b20875ea
CS
15296 ecom_str = NULL;
15297 if (bgp->vpn_policy[afi].rtlist[dir]) {
15298 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15299 bgp->vpn_policy[afi].rtlist[dir],
15300 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea 15301 vty_out(vty, "Import RT(s): %s\n", ecom_str);
b46dfd20 15302
b20875ea
CS
15303 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15304 } else
15305 vty_out(vty, "Import RT(s):\n");
53089bec 15306 }
53089bec 15307
b46dfd20
DS
15308 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15309 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15310 vty_out(vty,
15311 "This VRF is not exporting %s routes to any other VRF\n",
5cb5f4d0 15312 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15313 else {
15314 vty_out(vty,
04c9077f 15315 "This VRF is exporting %s routes to the following VRFs:\n",
5cb5f4d0 15316 get_afi_safi_str(afi, safi, false));
b46dfd20
DS
15317
15318 for (ALL_LIST_ELEMENTS_RO(
15319 bgp->vpn_policy[afi].export_vrf,
15320 node, vname))
15321 vty_out(vty, " %s\n", vname);
15322
15323 vty_out(vty, "RD: %s\n",
15324 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15325 buf1, RD_ADDRSTRLEN));
15326
15327 dir = BGP_VPN_POLICY_DIR_TOVPN;
b20875ea
CS
15328 if (bgp->vpn_policy[afi].rtlist[dir]) {
15329 ecom_str = ecommunity_ecom2str(
b46dfd20
DS
15330 bgp->vpn_policy[afi].rtlist[dir],
15331 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
b20875ea
CS
15332 vty_out(vty, "Export RT: %s\n", ecom_str);
15333 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15334 } else
15335 vty_out(vty, "Import RT(s):\n");
53089bec 15336 }
53089bec 15337 }
15338
15339 return CMD_SUCCESS;
15340}
15341
03915806
CS
15342static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15343 safi_t safi, bool use_json)
15344{
15345 struct listnode *node, *nnode;
15346 struct bgp *bgp;
15347 char *vrf_name = NULL;
15348 json_object *json = NULL;
15349 json_object *json_vrf = NULL;
15350 json_object *json_vrfs = NULL;
15351
15352 if (use_json) {
15353 json = json_object_new_object();
15354 json_vrfs = json_object_new_object();
15355 }
15356
15357 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15358
15359 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15360 vrf_name = bgp->name;
15361
15362 if (use_json) {
15363 json_vrf = json_object_new_object();
15364 } else {
15365 vty_out(vty, "\nInstance %s:\n",
15366 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15367 ? VRF_DEFAULT_NAME : bgp->name);
15368 }
15369 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15370 if (use_json) {
15371 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15372 json_object_object_add(json_vrfs,
15373 VRF_DEFAULT_NAME, json_vrf);
15374 else
15375 json_object_object_add(json_vrfs, vrf_name,
15376 json_vrf);
15377 }
15378 }
15379
15380 if (use_json) {
15381 json_object_object_add(json, "vrfs", json_vrfs);
15382 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15383 JSON_C_TO_STRING_PRETTY));
15384 json_object_free(json);
15385 }
15386
15387 return CMD_SUCCESS;
15388}
15389
53089bec 15390/* "show [ip] bgp route-leak" command. */
15391DEFUN (show_ip_bgp_route_leak,
04c9077f
DS
15392 show_ip_bgp_route_leak_cmd,
15393 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
b46dfd20
DS
15394 SHOW_STR
15395 IP_STR
15396 BGP_STR
15397 BGP_INSTANCE_HELP_STR
15398 BGP_AFI_HELP_STR
15399 BGP_SAFI_HELP_STR
15400 "Route leaking information\n"
15401 JSON_STR)
53089bec 15402{
15403 char *vrf = NULL;
15404 afi_t afi = AFI_MAX;
15405 safi_t safi = SAFI_MAX;
15406
9f049418 15407 bool uj = use_json(argc, argv);
53089bec 15408 int idx = 0;
03915806 15409 json_object *json = NULL;
53089bec 15410
15411 /* show [ip] bgp */
15412 if (argv_find(argv, argc, "ip", &idx)) {
15413 afi = AFI_IP;
15414 safi = SAFI_UNICAST;
15415 }
15416 /* [vrf VIEWVRFNAME] */
15417 if (argv_find(argv, argc, "view", &idx)) {
020a3f60
DS
15418 vty_out(vty,
15419 "%% This command is not applicable to BGP views\n");
53089bec 15420 return CMD_WARNING;
15421 }
15422
9a8bdf1c
PG
15423 if (argv_find(argv, argc, "vrf", &idx)) {
15424 vrf = argv[idx + 1]->arg;
15425 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15426 vrf = NULL;
15427 }
53089bec 15428 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15429 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15430 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15431 }
15432
15433 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
020a3f60
DS
15434 vty_out(vty,
15435 "%% This command is applicable only for unicast ipv4|ipv6\n");
53089bec 15436 return CMD_WARNING;
15437 }
15438
03915806
CS
15439 if (vrf && strmatch(vrf, "all"))
15440 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15441
15442 if (uj)
15443 json = json_object_new_object();
15444
15445 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
53089bec 15446}
15447
d62a17ae 15448static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15449 safi_t safi)
f186de26 15450{
d62a17ae 15451 struct listnode *node, *nnode;
15452 struct bgp *bgp;
f186de26 15453
d62a17ae 15454 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15455 vty_out(vty, "\nInstance %s:\n",
15456 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
5742e42b 15457 ? VRF_DEFAULT_NAME
d62a17ae 15458 : bgp->name);
15459 update_group_show(bgp, afi, safi, vty, 0);
15460 }
f186de26 15461}
15462
d62a17ae 15463static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15464 int safi, uint64_t subgrp_id)
4fb25c53 15465{
d62a17ae 15466 struct bgp *bgp;
4fb25c53 15467
d62a17ae 15468 if (name) {
15469 if (strmatch(name, "all")) {
15470 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15471 return CMD_SUCCESS;
15472 } else {
15473 bgp = bgp_lookup_by_name(name);
15474 }
15475 } else {
15476 bgp = bgp_get_default();
15477 }
4fb25c53 15478
d62a17ae 15479 if (bgp)
15480 update_group_show(bgp, afi, safi, vty, subgrp_id);
15481 return CMD_SUCCESS;
4fb25c53
DW
15482}
15483
8fe8a7f6
DS
15484DEFUN (show_ip_bgp_updgrps,
15485 show_ip_bgp_updgrps_cmd,
c1a44e43 15486 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 15487 SHOW_STR
15488 IP_STR
15489 BGP_STR
15490 BGP_INSTANCE_HELP_STR
c9e571b4 15491 BGP_AFI_HELP_STR
9bedbb1e 15492 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
15493 "Detailed info about dynamic update groups\n"
15494 "Specific subgroup to display detailed info for\n")
8386ac43 15495{
d62a17ae 15496 char *vrf = NULL;
15497 afi_t afi = AFI_IP6;
15498 safi_t safi = SAFI_UNICAST;
15499 uint64_t subgrp_id = 0;
15500
15501 int idx = 0;
15502
15503 /* show [ip] bgp */
15504 if (argv_find(argv, argc, "ip", &idx))
15505 afi = AFI_IP;
9a8bdf1c
PG
15506 /* [<vrf> VIEWVRFNAME] */
15507 if (argv_find(argv, argc, "vrf", &idx)) {
15508 vrf = argv[idx + 1]->arg;
15509 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15510 vrf = NULL;
15511 } else if (argv_find(argv, argc, "view", &idx))
15512 /* [<view> VIEWVRFNAME] */
15513 vrf = argv[idx + 1]->arg;
d62a17ae 15514 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15515 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15516 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15517 }
5bf15956 15518
d62a17ae 15519 /* get subgroup id, if provided */
15520 idx = argc - 1;
15521 if (argv[idx]->type == VARIABLE_TKN)
15522 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 15523
d62a17ae 15524 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
15525}
15526
f186de26 15527DEFUN (show_bgp_instance_all_ipv6_updgrps,
15528 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 15529 "show [ip] bgp <view|vrf> all update-groups",
f186de26 15530 SHOW_STR
716b2d8a 15531 IP_STR
f186de26 15532 BGP_STR
15533 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 15534 "Detailed info about dynamic update groups\n")
f186de26 15535{
d62a17ae 15536 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15537 return CMD_SUCCESS;
f186de26 15538}
15539
43d3f4fc
DS
15540DEFUN (show_bgp_l2vpn_evpn_updgrps,
15541 show_bgp_l2vpn_evpn_updgrps_cmd,
15542 "show [ip] bgp l2vpn evpn update-groups",
15543 SHOW_STR
15544 IP_STR
15545 BGP_STR
15546 "l2vpn address family\n"
15547 "evpn sub-address family\n"
15548 "Detailed info about dynamic update groups\n")
15549{
15550 char *vrf = NULL;
15551 uint64_t subgrp_id = 0;
15552
15553 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15554 return CMD_SUCCESS;
15555}
15556
5bf15956
DW
15557DEFUN (show_bgp_updgrps_stats,
15558 show_bgp_updgrps_stats_cmd,
716b2d8a 15559 "show [ip] bgp update-groups statistics",
3f9c7369 15560 SHOW_STR
716b2d8a 15561 IP_STR
3f9c7369 15562 BGP_STR
0c7b1b01 15563 "Detailed info about dynamic update groups\n"
3f9c7369
DS
15564 "Statistics\n")
15565{
d62a17ae 15566 struct bgp *bgp;
3f9c7369 15567
d62a17ae 15568 bgp = bgp_get_default();
15569 if (bgp)
15570 update_group_show_stats(bgp, vty);
3f9c7369 15571
d62a17ae 15572 return CMD_SUCCESS;
3f9c7369
DS
15573}
15574
8386ac43 15575DEFUN (show_bgp_instance_updgrps_stats,
15576 show_bgp_instance_updgrps_stats_cmd,
18c57037 15577 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 15578 SHOW_STR
716b2d8a 15579 IP_STR
8386ac43 15580 BGP_STR
15581 BGP_INSTANCE_HELP_STR
0c7b1b01 15582 "Detailed info about dynamic update groups\n"
8386ac43 15583 "Statistics\n")
15584{
d62a17ae 15585 int idx_word = 3;
15586 struct bgp *bgp;
8386ac43 15587
d62a17ae 15588 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15589 if (bgp)
15590 update_group_show_stats(bgp, vty);
8386ac43 15591
d62a17ae 15592 return CMD_SUCCESS;
8386ac43 15593}
15594
d62a17ae 15595static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15596 afi_t afi, safi_t safi,
15597 const char *what, uint64_t subgrp_id)
3f9c7369 15598{
d62a17ae 15599 struct bgp *bgp;
8386ac43 15600
d62a17ae 15601 if (name)
15602 bgp = bgp_lookup_by_name(name);
15603 else
15604 bgp = bgp_get_default();
8386ac43 15605
d62a17ae 15606 if (bgp) {
15607 if (!strcmp(what, "advertise-queue"))
15608 update_group_show_adj_queue(bgp, afi, safi, vty,
15609 subgrp_id);
15610 else if (!strcmp(what, "advertised-routes"))
15611 update_group_show_advertised(bgp, afi, safi, vty,
15612 subgrp_id);
15613 else if (!strcmp(what, "packet-queue"))
15614 update_group_show_packet_queue(bgp, afi, safi, vty,
15615 subgrp_id);
15616 }
3f9c7369
DS
15617}
15618
dc64bdec
QY
15619DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15620 show_ip_bgp_instance_updgrps_adj_s_cmd,
15621 "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",
15622 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15623 BGP_SAFI_HELP_STR
15624 "Detailed info about dynamic update groups\n"
15625 "Specific subgroup to display info for\n"
15626 "Advertisement queue\n"
15627 "Announced routes\n"
15628 "Packet queue\n")
3f9c7369 15629{
dc64bdec
QY
15630 uint64_t subgrp_id = 0;
15631 afi_t afiz;
15632 safi_t safiz;
15633 if (sgid)
15634 subgrp_id = strtoull(sgid, NULL, 10);
15635
15636 if (!ip && !afi)
15637 afiz = AFI_IP6;
15638 if (!ip && afi)
15639 afiz = bgp_vty_afi_from_str(afi);
15640 if (ip && !afi)
15641 afiz = AFI_IP;
15642 if (ip && afi) {
15643 afiz = bgp_vty_afi_from_str(afi);
15644 if (afiz != AFI_IP)
15645 vty_out(vty,
15646 "%% Cannot specify both 'ip' and 'ipv6'\n");
15647 return CMD_WARNING;
15648 }
d62a17ae 15649
dc64bdec 15650 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 15651
dc64bdec 15652 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 15653 return CMD_SUCCESS;
15654}
15655
6f4eacf3
DA
15656static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
15657 json_object *json)
d62a17ae 15658{
15659 struct listnode *node, *nnode;
15660 struct prefix *range;
15661 struct peer *conf;
15662 struct peer *peer;
d62a17ae 15663 afi_t afi;
15664 safi_t safi;
15665 const char *peer_status;
d62a17ae 15666 int lr_count;
15667 int dynamic;
6f4eacf3
DA
15668 bool af_cfgd;
15669 json_object *json_peer_group = NULL;
15670 json_object *json_peer_group_afc = NULL;
15671 json_object *json_peer_group_members = NULL;
15672 json_object *json_peer_group_dynamic = NULL;
15673 json_object *json_peer_group_dynamic_af = NULL;
15674 json_object *json_peer_group_ranges = NULL;
d62a17ae 15675
15676 conf = group->conf;
15677
6f4eacf3
DA
15678 if (json) {
15679 json_peer_group = json_object_new_object();
15680 json_peer_group_afc = json_object_new_array();
15681 }
15682
d62a17ae 15683 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
6f4eacf3
DA
15684 if (json)
15685 json_object_int_add(json_peer_group, "remoteAs",
15686 conf->as);
15687 else
15688 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15689 group->name, conf->as);
d62a17ae 15690 } else if (conf->as_type == AS_INTERNAL) {
6f4eacf3
DA
15691 if (json)
15692 json_object_int_add(json_peer_group, "remoteAs",
15693 group->bgp->as);
15694 else
15695 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15696 group->name, group->bgp->as);
d62a17ae 15697 } else {
6f4eacf3
DA
15698 if (!json)
15699 vty_out(vty, "\nBGP peer-group %s\n", group->name);
d62a17ae 15700 }
f14e6fdb 15701
6f4eacf3
DA
15702 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL)) {
15703 if (json)
15704 json_object_string_add(json_peer_group, "type",
15705 "internal");
15706 else
15707 vty_out(vty, " Peer-group type is internal\n");
15708 } else {
15709 if (json)
15710 json_object_string_add(json_peer_group, "type",
15711 "external");
15712 else
15713 vty_out(vty, " Peer-group type is external\n");
15714 }
d62a17ae 15715
15716 /* Display AFs configured. */
6f4eacf3
DA
15717 if (!json)
15718 vty_out(vty, " Configured address-families:");
15719
05c7a1cc
QY
15720 FOREACH_AFI_SAFI (afi, safi) {
15721 if (conf->afc[afi][safi]) {
6f4eacf3
DA
15722 af_cfgd = true;
15723 if (json)
15724 json_object_array_add(
15725 json_peer_group_afc,
15726 json_object_new_string(get_afi_safi_str(
15727 afi, safi, false)));
15728 else
15729 vty_out(vty, " %s;",
15730 get_afi_safi_str(afi, safi, false));
d62a17ae 15731 }
05c7a1cc 15732 }
6f4eacf3
DA
15733
15734 if (json) {
15735 json_object_object_add(json_peer_group,
15736 "addressFamiliesConfigured",
15737 json_peer_group_afc);
15738 } else {
15739 if (!af_cfgd)
15740 vty_out(vty, " none\n");
15741 else
15742 vty_out(vty, "\n");
15743 }
d62a17ae 15744
15745 /* Display listen ranges (for dynamic neighbors), if any */
15746 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
d62a17ae 15747 lr_count = listcount(group->listen_range[afi]);
15748 if (lr_count) {
6f4eacf3
DA
15749 if (json) {
15750 if (!json_peer_group_dynamic)
15751 json_peer_group_dynamic =
15752 json_object_new_object();
15753
15754 json_peer_group_dynamic_af =
15755 json_object_new_object();
15756 json_peer_group_ranges =
15757 json_object_new_array();
15758 json_object_int_add(json_peer_group_dynamic_af,
15759 "count", lr_count);
15760 } else {
15761 vty_out(vty, " %d %s listen range(s)\n",
15762 lr_count, afi2str(afi));
15763 }
d62a17ae 15764
15765 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
6f4eacf3
DA
15766 nnode, range)) {
15767 if (json) {
15768 char buf[BUFSIZ];
15769
15770 snprintfrr(buf, sizeof(buf), "%pFX",
15771 range);
15772
15773 json_object_array_add(
15774 json_peer_group_ranges,
15775 json_object_new_string(buf));
15776 } else {
15777 vty_out(vty, " %pFX\n", range);
15778 }
15779 }
15780
15781 if (json) {
15782 json_object_object_add(
15783 json_peer_group_dynamic_af, "ranges",
15784 json_peer_group_ranges);
15785
15786 json_object_object_add(
15787 json_peer_group_dynamic, afi2str(afi),
15788 json_peer_group_dynamic_af);
15789 }
d62a17ae 15790 }
15791 }
f14e6fdb 15792
6f4eacf3
DA
15793 if (json_peer_group_dynamic)
15794 json_object_object_add(json_peer_group, "dynamicRanges",
15795 json_peer_group_dynamic);
15796
d62a17ae 15797 /* Display group members and their status */
15798 if (listcount(group->peer)) {
6f4eacf3
DA
15799 if (json)
15800 json_peer_group_members = json_object_new_object();
15801 else
15802 vty_out(vty, " Peer-group members:\n");
d62a17ae 15803 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
cb9196e7
DS
15804 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15805 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
d62a17ae 15806 peer_status = "Idle (Admin)";
15807 else if (CHECK_FLAG(peer->sflags,
15808 PEER_STATUS_PREFIX_OVERFLOW))
15809 peer_status = "Idle (PfxCt)";
15810 else
15811 peer_status = lookup_msg(bgp_status_msg,
15812 peer->status, NULL);
15813
15814 dynamic = peer_dynamic_neighbor(peer);
6f4eacf3
DA
15815
15816 if (json) {
15817 json_object *json_peer_group_member =
15818 json_object_new_object();
15819
15820 json_object_string_add(json_peer_group_member,
15821 "status", peer_status);
15822
15823 if (dynamic)
15824 json_object_boolean_true_add(
15825 json_peer_group_member,
15826 "dynamic");
15827
15828 json_object_object_add(json_peer_group_members,
15829 peer->host,
15830 json_peer_group_member);
15831 } else {
15832 vty_out(vty, " %s %s %s \n", peer->host,
15833 dynamic ? "(dynamic)" : "",
15834 peer_status);
15835 }
d62a17ae 15836 }
6f4eacf3
DA
15837 if (json)
15838 json_object_object_add(json_peer_group, "members",
15839 json_peer_group_members);
d62a17ae 15840 }
f14e6fdb 15841
6f4eacf3
DA
15842 if (json)
15843 json_object_object_add(json, group->name, json_peer_group);
15844
d62a17ae 15845 return CMD_SUCCESS;
15846}
15847
ff9959b0 15848static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
6f4eacf3 15849 const char *group_name, bool uj)
d62a17ae 15850{
ff9959b0 15851 struct bgp *bgp;
d62a17ae 15852 struct listnode *node, *nnode;
15853 struct peer_group *group;
ff9959b0 15854 bool found = false;
6f4eacf3
DA
15855 json_object *json = NULL;
15856
15857 if (uj)
15858 json = json_object_new_object();
ff9959b0
QY
15859
15860 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15861
15862 if (!bgp) {
6f4eacf3
DA
15863 if (uj) {
15864 vty_out(vty, "%s\n",
15865 json_object_to_json_string_ext(
15866 json, JSON_C_TO_STRING_PRETTY));
15867 json_object_free(json);
15868 } else {
15869 vty_out(vty, "%% BGP instance not found\n");
15870 }
15871
ff9959b0
QY
15872 return CMD_WARNING;
15873 }
d62a17ae 15874
15875 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
15876 if (group_name) {
15877 if (strmatch(group->name, group_name)) {
6f4eacf3 15878 bgp_show_one_peer_group(vty, group, json);
ff9959b0
QY
15879 found = true;
15880 break;
d62a17ae 15881 }
ff9959b0 15882 } else {
6f4eacf3 15883 bgp_show_one_peer_group(vty, group, json);
d62a17ae 15884 }
f14e6fdb 15885 }
f14e6fdb 15886
6f4eacf3 15887 if (group_name && !found && !uj)
d62a17ae 15888 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 15889
6f4eacf3
DA
15890 if (uj) {
15891 vty_out(vty, "%s\n",
15892 json_object_to_json_string_ext(
15893 json, JSON_C_TO_STRING_PRETTY));
15894 json_object_free(json);
15895 }
15896
d62a17ae 15897 return CMD_SUCCESS;
f14e6fdb
DS
15898}
15899
6f4eacf3
DA
15900DEFUN(show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd,
15901 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME] [json]",
15902 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
15903 "Detailed information on BGP peer groups\n"
15904 "Peer group name\n" JSON_STR)
f14e6fdb 15905{
d62a17ae 15906 char *vrf, *pg;
d62a17ae 15907 int idx = 0;
6f4eacf3 15908 bool uj = use_json(argc, argv);
f14e6fdb 15909
a4d82a8a
PZ
15910 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15911 : NULL;
d62a17ae 15912 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 15913
6f4eacf3 15914 return bgp_show_peer_group_vty(vty, vrf, pg, uj);
f14e6fdb 15915}
3f9c7369 15916
d6e3c605 15917
718e3744 15918/* Redistribute VTY commands. */
15919
37a87b8f
CS
15920DEFUN_YANG (bgp_redistribute_ipv4,
15921 bgp_redistribute_ipv4_cmd,
15922 "redistribute " FRR_IP_REDIST_STR_BGPD,
15923 "Redistribute information from another routing protocol\n"
15924 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 15925{
d62a17ae 15926 int idx_protocol = 1;
37a87b8f 15927 char base_xpath[XPATH_MAXLEN];
718e3744 15928
37a87b8f
CS
15929 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15930 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15931 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15932 argv[idx_protocol]->text, "0");
15933
15934 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7f323236 15935
37a87b8f 15936 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15937}
15938
d62a17ae 15939ALIAS_HIDDEN(
15940 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15941 "redistribute " FRR_IP_REDIST_STR_BGPD,
15942 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 15943
37a87b8f
CS
15944DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15945 bgp_redistribute_ipv4_rmap_cmd,
15946 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15947 "Redistribute information from another routing protocol\n"
15948 FRR_IP_REDIST_HELP_STR_BGPD
15949 "Route map reference\n"
15950 "Pointer to route-map entries\n")
718e3744 15951{
d62a17ae 15952 int idx_protocol = 1;
15953 int idx_word = 3;
37a87b8f
CS
15954 char base_xpath[XPATH_MAXLEN];
15955
15956 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15957 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15958 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15959 argv[idx_protocol]->text, "0");
718e3744 15960
37a87b8f
CS
15961 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15962 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15963 argv[idx_word]->arg);
15964
15965 return nb_cli_apply_changes(vty, base_xpath);
718e3744 15966}
15967
d62a17ae 15968ALIAS_HIDDEN(
15969 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15970 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15971 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15972 "Route map reference\n"
15973 "Pointer to route-map entries\n")
596c17ba 15974
37a87b8f
CS
15975DEFUN_YANG (bgp_redistribute_ipv4_metric,
15976 bgp_redistribute_ipv4_metric_cmd,
15977 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15978 "Redistribute information from another routing protocol\n"
15979 FRR_IP_REDIST_HELP_STR_BGPD
15980 "Metric for redistributed routes\n"
15981 "Default metric\n")
718e3744 15982{
d62a17ae 15983 int idx_protocol = 1;
15984 int idx_number = 3;
37a87b8f
CS
15985 char base_xpath[XPATH_MAXLEN];
15986
15987 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15988 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15989 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15990 argv[idx_protocol]->text, "0");
d62a17ae 15991
37a87b8f
CS
15992 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15993 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15994 argv[idx_number]->arg);
15995
15996 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 15997}
15998
15999ALIAS_HIDDEN(
16000 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
16001 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
16002 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16003 "Metric for redistributed routes\n"
16004 "Default metric\n")
596c17ba 16005
37a87b8f
CS
16006DEFUN_YANG(
16007 bgp_redistribute_ipv4_rmap_metric,
16008 bgp_redistribute_ipv4_rmap_metric_cmd,
16009 "redistribute " FRR_IP_REDIST_STR_BGPD
16010 " route-map WORD metric (0-4294967295)",
16011 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16012 "Route map reference\n"
16013 "Pointer to route-map entries\n"
16014 "Metric for redistributed routes\n"
16015 "Default metric\n")
718e3744 16016{
d62a17ae 16017 int idx_protocol = 1;
16018 int idx_word = 3;
16019 int idx_number = 5;
37a87b8f
CS
16020 char base_xpath[XPATH_MAXLEN];
16021
16022 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16023 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16024 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16025 argv[idx_protocol]->text, "0");
16026
16027 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16028 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16029 argv[idx_word]->arg);
16030 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16031 argv[idx_number]->arg);
d62a17ae 16032
37a87b8f 16033 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16034}
16035
16036ALIAS_HIDDEN(
16037 bgp_redistribute_ipv4_rmap_metric,
16038 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
16039 "redistribute " FRR_IP_REDIST_STR_BGPD
16040 " route-map WORD metric (0-4294967295)",
16041 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16042 "Route map reference\n"
16043 "Pointer to route-map entries\n"
16044 "Metric for redistributed routes\n"
16045 "Default metric\n")
596c17ba 16046
37a87b8f
CS
16047DEFUN_YANG(
16048 bgp_redistribute_ipv4_metric_rmap,
16049 bgp_redistribute_ipv4_metric_rmap_cmd,
16050 "redistribute " FRR_IP_REDIST_STR_BGPD
16051 " metric (0-4294967295) route-map WORD",
16052 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16053 "Metric for redistributed routes\n"
16054 "Default metric\n"
16055 "Route map reference\n"
16056 "Pointer to route-map entries\n")
718e3744 16057{
d62a17ae 16058 int idx_protocol = 1;
d62a17ae 16059 int idx_word = 5;
37a87b8f
CS
16060 int idx_number = 3;
16061 char base_xpath[XPATH_MAXLEN];
16062
16063 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16064 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16065 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16066 argv[idx_protocol]->text, "0");
16067
16068 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16069 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16070 argv[idx_number]->arg);
16071 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16072 argv[idx_word]->arg);
d62a17ae 16073
37a87b8f 16074 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16075}
16076
16077ALIAS_HIDDEN(
16078 bgp_redistribute_ipv4_metric_rmap,
16079 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
16080 "redistribute " FRR_IP_REDIST_STR_BGPD
16081 " metric (0-4294967295) route-map WORD",
16082 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16083 "Metric for redistributed routes\n"
16084 "Default metric\n"
16085 "Route map reference\n"
16086 "Pointer to route-map entries\n")
596c17ba 16087
37a87b8f
CS
16088DEFUN_YANG (bgp_redistribute_ipv4_ospf,
16089 bgp_redistribute_ipv4_ospf_cmd,
16090 "redistribute <ospf|table> (1-65535)",
16091 "Redistribute information from another routing protocol\n"
16092 "Open Shortest Path First (OSPFv2)\n"
16093 "Non-main Kernel Routing Table\n"
16094 "Instance ID/Table ID\n")
7c8ff89e 16095{
37a87b8f 16096 int idx_protocol = 1;
d62a17ae 16097 int idx_number = 2;
37a87b8f 16098 char base_xpath[XPATH_MAXLEN];
7c8ff89e 16099
37a87b8f
CS
16100 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16101 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16102 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16103 argv[idx_protocol]->text, argv[idx_number]->arg);
7a4bb9c5 16104
37a87b8f 16105 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
7a4bb9c5 16106
37a87b8f 16107 return nb_cli_apply_changes(vty, base_xpath);
7c8ff89e
DS
16108}
16109
d62a17ae 16110ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
16111 "redistribute <ospf|table> (1-65535)",
16112 "Redistribute information from another routing protocol\n"
16113 "Open Shortest Path First (OSPFv2)\n"
16114 "Non-main Kernel Routing Table\n"
16115 "Instance ID/Table ID\n")
596c17ba 16116
37a87b8f
CS
16117DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
16118 bgp_redistribute_ipv4_ospf_rmap_cmd,
16119 "redistribute <ospf|table> (1-65535) route-map WORD",
16120 "Redistribute information from another routing protocol\n"
16121 "Open Shortest Path First (OSPFv2)\n"
16122 "Non-main Kernel Routing Table\n"
16123 "Instance ID/Table ID\n"
16124 "Route map reference\n"
16125 "Pointer to route-map entries\n")
7c8ff89e 16126{
37a87b8f 16127 int idx_protocol = 1;
d62a17ae 16128 int idx_number = 2;
16129 int idx_word = 4;
37a87b8f
CS
16130 char base_xpath[XPATH_MAXLEN];
16131
16132 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16133 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16134 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16135 argv[idx_protocol]->text, argv[idx_number]->arg);
16136
16137 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16138
16139 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16140 argv[idx_word]->arg);
d62a17ae 16141
37a87b8f 16142 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16143}
16144
16145ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
16146 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
16147 "redistribute <ospf|table> (1-65535) route-map WORD",
16148 "Redistribute information from another routing protocol\n"
16149 "Open Shortest Path First (OSPFv2)\n"
16150 "Non-main Kernel Routing Table\n"
16151 "Instance ID/Table ID\n"
16152 "Route map reference\n"
16153 "Pointer to route-map entries\n")
596c17ba 16154
37a87b8f
CS
16155DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
16156 bgp_redistribute_ipv4_ospf_metric_cmd,
16157 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
16158 "Redistribute information from another routing protocol\n"
16159 "Open Shortest Path First (OSPFv2)\n"
16160 "Non-main Kernel Routing Table\n"
16161 "Instance ID/Table ID\n"
16162 "Metric for redistributed routes\n"
16163 "Default metric\n")
7c8ff89e 16164{
37a87b8f 16165 int idx_protocol = 1;
d62a17ae 16166 int idx_number = 2;
16167 int idx_number_2 = 4;
37a87b8f
CS
16168 char base_xpath[XPATH_MAXLEN];
16169
16170 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16171 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16172 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16173 argv[idx_protocol]->text, argv[idx_number]->arg);
16174
16175 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16176
37a87b8f
CS
16177 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16178 argv[idx_number_2]->arg);
d62a17ae 16179
37a87b8f 16180 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16181}
16182
16183ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
16184 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
16185 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
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"
16190 "Metric for redistributed routes\n"
16191 "Default metric\n")
596c17ba 16192
37a87b8f
CS
16193DEFUN_YANG(
16194 bgp_redistribute_ipv4_ospf_rmap_metric,
16195 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
16196 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16197 "Redistribute information from another routing protocol\n"
16198 "Open Shortest Path First (OSPFv2)\n"
16199 "Non-main Kernel Routing Table\n"
16200 "Instance ID/Table ID\n"
16201 "Route map reference\n"
16202 "Pointer to route-map entries\n"
16203 "Metric for redistributed routes\n"
16204 "Default metric\n")
7c8ff89e 16205{
37a87b8f 16206 int idx_protocol = 1;
d62a17ae 16207 int idx_number = 2;
16208 int idx_word = 4;
16209 int idx_number_2 = 6;
37a87b8f
CS
16210 char base_xpath[XPATH_MAXLEN];
16211
16212 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16213 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16214 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16215 argv[idx_protocol]->text, argv[idx_number]->arg);
16216
16217 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16218
37a87b8f
CS
16219 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16220 argv[idx_word]->arg);
16221 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16222 argv[idx_number_2]->arg);
d62a17ae 16223
37a87b8f 16224 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16225}
16226
16227ALIAS_HIDDEN(
16228 bgp_redistribute_ipv4_ospf_rmap_metric,
16229 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
16230 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
16231 "Redistribute information from another routing protocol\n"
16232 "Open Shortest Path First (OSPFv2)\n"
16233 "Non-main Kernel Routing Table\n"
16234 "Instance ID/Table ID\n"
16235 "Route map reference\n"
16236 "Pointer to route-map entries\n"
16237 "Metric for redistributed routes\n"
16238 "Default metric\n")
596c17ba 16239
37a87b8f
CS
16240DEFUN_YANG(
16241 bgp_redistribute_ipv4_ospf_metric_rmap,
16242 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
16243 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16244 "Redistribute information from another routing protocol\n"
16245 "Open Shortest Path First (OSPFv2)\n"
16246 "Non-main Kernel Routing Table\n"
16247 "Instance ID/Table ID\n"
16248 "Metric for redistributed routes\n"
16249 "Default metric\n"
16250 "Route map reference\n"
16251 "Pointer to route-map entries\n")
7c8ff89e 16252{
37a87b8f 16253 int idx_protocol = 1;
d62a17ae 16254 int idx_number = 2;
16255 int idx_number_2 = 4;
16256 int idx_word = 6;
37a87b8f
CS
16257 char base_xpath[XPATH_MAXLEN];
16258
16259 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16260 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16261 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16262 argv[idx_protocol]->text, argv[idx_number]->arg);
16263
16264 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
d62a17ae 16265
37a87b8f
CS
16266 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16267 argv[idx_number_2]->arg);
16268 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16269 argv[idx_word]->arg);
d62a17ae 16270
37a87b8f 16271 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16272}
16273
16274ALIAS_HIDDEN(
16275 bgp_redistribute_ipv4_ospf_metric_rmap,
16276 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
16277 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
16278 "Redistribute information from another routing protocol\n"
16279 "Open Shortest Path First (OSPFv2)\n"
16280 "Non-main Kernel Routing Table\n"
16281 "Instance ID/Table ID\n"
16282 "Metric for redistributed routes\n"
16283 "Default metric\n"
16284 "Route map reference\n"
16285 "Pointer to route-map entries\n")
596c17ba 16286
37a87b8f
CS
16287DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
16288 no_bgp_redistribute_ipv4_ospf_cmd,
16289 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
16290 NO_STR
16291 "Redistribute information from another routing protocol\n"
16292 "Open Shortest Path First (OSPFv2)\n"
16293 "Non-main Kernel Routing Table\n"
16294 "Instance ID/Table ID\n"
16295 "Metric for redistributed routes\n"
16296 "Default metric\n"
16297 "Route map reference\n"
16298 "Pointer to route-map entries\n")
7c8ff89e 16299{
37a87b8f 16300 int idx_protocol = 2;
d62a17ae 16301 int idx_number = 3;
37a87b8f 16302 char base_xpath[XPATH_MAXLEN];
d62a17ae 16303
37a87b8f
CS
16304 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16305 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16306 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16307 argv[idx_protocol]->text, argv[idx_number]->arg);
16308
16309 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
d62a17ae 16310
37a87b8f 16311 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16312}
16313
16314ALIAS_HIDDEN(
16315 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
e27957c0 16316 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16317 NO_STR
16318 "Redistribute information from another routing protocol\n"
16319 "Open Shortest Path First (OSPFv2)\n"
16320 "Non-main Kernel Routing Table\n"
16321 "Instance ID/Table ID\n"
16322 "Metric for redistributed routes\n"
16323 "Default metric\n"
16324 "Route map reference\n"
16325 "Pointer to route-map entries\n")
596c17ba 16326
37a87b8f
CS
16327DEFUN_YANG (no_bgp_redistribute_ipv4,
16328 no_bgp_redistribute_ipv4_cmd,
16329 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
16330 NO_STR
16331 "Redistribute information from another routing protocol\n"
16332 FRR_IP_REDIST_HELP_STR_BGPD
16333 "Metric for redistributed routes\n"
16334 "Default metric\n"
16335 "Route map reference\n"
16336 "Pointer to route-map entries\n")
718e3744 16337{
d62a17ae 16338 int idx_protocol = 2;
37a87b8f 16339 char base_xpath[XPATH_MAXLEN];
d62a17ae 16340
37a87b8f
CS
16341 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16342 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
16343 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
16344 argv[idx_protocol]->text, "0");
16345
16346 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16347
16348 return nb_cli_apply_changes(vty, base_xpath);
d62a17ae 16349}
16350
16351ALIAS_HIDDEN(
16352 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
16353 "no redistribute " FRR_IP_REDIST_STR_BGPD
e27957c0 16354 " [{metric (0-4294967295)|route-map WORD}]",
d62a17ae 16355 NO_STR
16356 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
16357 "Metric for redistributed routes\n"
16358 "Default metric\n"
16359 "Route map reference\n"
16360 "Pointer to route-map entries\n")
596c17ba 16361
37a87b8f
CS
16362DEFUN_YANG (bgp_redistribute_ipv6,
16363 bgp_redistribute_ipv6_cmd,
16364 "redistribute " FRR_IP6_REDIST_STR_BGPD,
16365 "Redistribute information from another routing protocol\n"
16366 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 16367{
d62a17ae 16368 int idx_protocol = 1;
37a87b8f 16369 char base_xpath[XPATH_MAXLEN];
718e3744 16370
37a87b8f
CS
16371 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16372 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16373 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16374 argv[idx_protocol]->text, "0");
16375
16376 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
718e3744 16377
37a87b8f 16378 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16379}
16380
37a87b8f
CS
16381DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16382 bgp_redistribute_ipv6_rmap_cmd,
16383 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16384 "Redistribute information from another routing protocol\n"
16385 FRR_IP6_REDIST_HELP_STR_BGPD
16386 "Route map reference\n"
16387 "Pointer to route-map entries\n")
718e3744 16388{
d62a17ae 16389 int idx_protocol = 1;
16390 int idx_word = 3;
37a87b8f
CS
16391 char base_xpath[XPATH_MAXLEN];
16392
16393 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16394 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16395 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16396 argv[idx_protocol]->text, "0");
718e3744 16397
37a87b8f
CS
16398 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16399 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16400 argv[idx_word]->arg);
16401
16402 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16403}
16404
37a87b8f 16405DEFUN_YANG (bgp_redistribute_ipv6_metric,
718e3744 16406 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 16407 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 16408 "Redistribute information from another routing protocol\n"
ab0181ee 16409 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 16410 "Metric for redistributed routes\n"
16411 "Default metric\n")
16412{
d62a17ae 16413 int idx_protocol = 1;
16414 int idx_number = 3;
37a87b8f
CS
16415 char base_xpath[XPATH_MAXLEN];
16416
16417 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16418 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16419 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16420 argv[idx_protocol]->text, "0");
718e3744 16421
37a87b8f
CS
16422 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16423 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16424 argv[idx_number]->arg);
16425
16426 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16427}
16428
37a87b8f
CS
16429DEFUN_YANG(
16430 bgp_redistribute_ipv6_rmap_metric,
16431 bgp_redistribute_ipv6_rmap_metric_cmd,
16432 "redistribute " FRR_IP6_REDIST_STR_BGPD
16433 " route-map WORD metric (0-4294967295)",
16434 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16435 "Route map reference\n"
16436 "Pointer to route-map entries\n"
16437 "Metric for redistributed routes\n"
16438 "Default metric\n")
718e3744 16439{
d62a17ae 16440 int idx_protocol = 1;
16441 int idx_word = 3;
16442 int idx_number = 5;
37a87b8f
CS
16443 char base_xpath[XPATH_MAXLEN];
16444
16445 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16446 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16447 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16448 argv[idx_protocol]->text, "0");
718e3744 16449
37a87b8f
CS
16450 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16451 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16452 argv[idx_word]->arg);
16453 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16454 argv[idx_number]->arg);
16455
16456 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16457}
16458
37a87b8f
CS
16459DEFUN_YANG(
16460 bgp_redistribute_ipv6_metric_rmap,
16461 bgp_redistribute_ipv6_metric_rmap_cmd,
16462 "redistribute " FRR_IP6_REDIST_STR_BGPD
16463 " metric (0-4294967295) route-map WORD",
16464 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16465 "Metric for redistributed routes\n"
16466 "Default metric\n"
16467 "Route map reference\n"
16468 "Pointer to route-map entries\n")
718e3744 16469{
d62a17ae 16470 int idx_protocol = 1;
d62a17ae 16471 int idx_word = 5;
37a87b8f
CS
16472 int idx_number = 3;
16473 char base_xpath[XPATH_MAXLEN];
16474
16475 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16476 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16477 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16478 argv[idx_protocol]->text, "0");
718e3744 16479
37a87b8f
CS
16480 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16481 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16482 argv[idx_number]->arg);
16483 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16484 argv[idx_word]->arg);
16485
16486 return nb_cli_apply_changes(vty, base_xpath);
718e3744 16487}
16488
37a87b8f
CS
16489DEFUN_YANG(
16490 no_bgp_redistribute_ipv6,
16491 no_bgp_redistribute_ipv6_cmd,
16492 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16493 " [{metric (0-4294967295)|route-map WORD}]",
16494 NO_STR
16495 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16496 "Metric for redistributed routes\n"
16497 "Default metric\n"
16498 "Route map reference\n"
16499 "Pointer to route-map entries\n")
718e3744 16500{
d62a17ae 16501 int idx_protocol = 2;
37a87b8f 16502 char base_xpath[XPATH_MAXLEN];
718e3744 16503
37a87b8f
CS
16504 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16505 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16506 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16507 argv[idx_protocol]->text, "0");
16508
16509 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16510
16511 return nb_cli_apply_changes(vty, base_xpath);
16512}
718e3744 16513
37a87b8f
CS
16514void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16515 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16516{
16517 uint32_t instance = 0;
16518
16519 vty_out(vty, " redistribute %s",
16520 yang_dnode_get_string(dnode, "./route-type"));
16521 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16522 vty_out(vty, " %d", instance);
16523 if (yang_dnode_exists(dnode, "./metric"))
16524 vty_out(vty, " metric %u",
16525 yang_dnode_get_uint32(dnode, "./metric"));
16526 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16527 vty_out(vty, " route-map %s",
16528 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16529 vty_out(vty, "\n");
d62a17ae 16530}
16531
4ab46701
AR
16532/* Neighbor update tcp-mss. */
16533static int peer_tcp_mss_vty(struct vty *vty, const char *peer_str,
16534 const char *tcp_mss_str)
16535{
16536 struct peer *peer;
16537 uint32_t tcp_mss_val = 0;
16538
16539 peer = peer_and_group_lookup_vty(vty, peer_str);
16540 if (!peer)
16541 return CMD_WARNING_CONFIG_FAILED;
16542
16543 if (tcp_mss_str) {
16544 tcp_mss_val = strtoul(tcp_mss_str, NULL, 10);
16545 peer_tcp_mss_set(peer, tcp_mss_val);
16546 } else {
16547 peer_tcp_mss_unset(peer);
16548 }
16549
16550 return CMD_SUCCESS;
16551}
16552
16553DEFUN(neighbor_tcp_mss, neighbor_tcp_mss_cmd,
16554 "neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)",
16555 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16556 "TCP max segment size\n"
16557 "TCP MSS value\n")
16558{
16559 int peer_index = 1;
16560 int mss_index = 3;
16561
16562 vty_out(vty,
16563 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16564 return peer_tcp_mss_vty(vty, argv[peer_index]->arg,
16565 argv[mss_index]->arg);
16566}
16567
16568DEFUN(no_neighbor_tcp_mss, no_neighbor_tcp_mss_cmd,
16569 "no neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss [(1-65535)]",
16570 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
16571 "TCP max segment size\n"
16572 "TCP MSS value\n")
16573{
16574 int peer_index = 2;
16575
16576 vty_out(vty,
16577 " Warning: Reset BGP session for tcp-mss value to take effect\n");
16578 return peer_tcp_mss_vty(vty, argv[peer_index]->arg, NULL);
16579}
16580
dd65f45e
DL
16581static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16582 afi_t afi, safi_t safi)
d62a17ae 16583{
16584 int i;
16585
16586 /* Unicast redistribution only. */
16587 if (safi != SAFI_UNICAST)
2b791107 16588 return;
d62a17ae 16589
16590 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16591 /* Redistribute BGP does not make sense. */
16592 if (i != ZEBRA_ROUTE_BGP) {
16593 struct list *red_list;
16594 struct listnode *node;
16595 struct bgp_redist *red;
16596
16597 red_list = bgp->redist[afi][i];
16598 if (!red_list)
16599 continue;
16600
16601 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 16602 /* "redistribute" configuration. */
16603 vty_out(vty, " redistribute %s",
16604 zebra_route_string(i));
16605 if (red->instance)
16606 vty_out(vty, " %d", red->instance);
16607 if (red->redist_metric_flag)
16608 vty_out(vty, " metric %u",
16609 red->redist_metric);
16610 if (red->rmap.name)
16611 vty_out(vty, " route-map %s",
16612 red->rmap.name);
16613 vty_out(vty, "\n");
16614 }
16615 }
16616 }
718e3744 16617}
6b0655a2 16618
dd65f45e
DL
16619/* peer-group helpers for config-write */
16620
16621static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16622{
16623 if (!peer_group_active(peer)) {
16624 if (CHECK_FLAG(peer->flags_invert, flag))
16625 return !CHECK_FLAG(peer->flags, flag);
16626 else
16627 return !!CHECK_FLAG(peer->flags, flag);
16628 }
16629
16630 return !!CHECK_FLAG(peer->flags_override, flag);
16631}
16632
16633static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16634 uint32_t flag)
16635{
16636 if (!peer_group_active(peer)) {
16637 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16638 return !peer_af_flag_check(peer, afi, safi, flag);
16639 else
16640 return !!peer_af_flag_check(peer, afi, safi, flag);
16641 }
16642
16643 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16644}
16645
16646static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16647 uint8_t type, int direct)
16648{
16649 struct bgp_filter *filter;
16650
16651 if (peer_group_active(peer))
16652 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16653 type);
16654
16655 filter = &peer->filter[afi][safi];
16656 switch (type) {
16657 case PEER_FT_DISTRIBUTE_LIST:
16658 return !!(filter->dlist[direct].name);
16659 case PEER_FT_FILTER_LIST:
16660 return !!(filter->aslist[direct].name);
16661 case PEER_FT_PREFIX_LIST:
16662 return !!(filter->plist[direct].name);
16663 case PEER_FT_ROUTE_MAP:
16664 return !!(filter->map[direct].name);
16665 case PEER_FT_UNSUPPRESS_MAP:
16666 return !!(filter->usmap.name);
7f7940e6
MK
16667 case PEER_FT_ADVERTISE_MAP:
16668 return !!(filter->advmap.aname
16669 && ((filter->advmap.condition == direct)
16670 && filter->advmap.cname));
dd65f45e
DL
16671 default:
16672 return false;
16673 }
16674}
16675
16676/* Return true if the addpath type is set for peer and different from
16677 * peer-group.
16678 */
3dc339cd
DA
16679static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16680 safi_t safi)
dd65f45e
DL
16681{
16682 enum bgp_addpath_strat type, g_type;
16683
16684 type = peer->addpath_type[afi][safi];
16685
16686 if (type != BGP_ADDPATH_NONE) {
16687 if (peer_group_active(peer)) {
16688 g_type = peer->group->conf->addpath_type[afi][safi];
16689
16690 if (type != g_type)
3dc339cd 16691 return true;
dd65f45e 16692 else
3dc339cd 16693 return false;
dd65f45e
DL
16694 }
16695
3dc339cd 16696 return true;
dd65f45e
DL
16697 }
16698
3dc339cd 16699 return false;
dd65f45e
DL
16700}
16701
b9c7bc5a 16702/* This is part of the address-family block (unicast only) */
dd65f45e 16703static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
16704 afi_t afi)
16705{
b9c7bc5a 16706 int indent = 2;
ddb5b488 16707
8a066a70 16708 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
ae6a6fb4
DS
16709 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16710 BGP_CONFIG_VRF_TO_VRF_IMPORT))
8a066a70
PG
16711 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16712 bgp->vpn_policy[afi]
bb4f6190 16713 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
8a066a70
PG
16714 else
16715 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16716 bgp->vpn_policy[afi]
16717 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16718 }
12a844a5
DS
16719 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16720 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16721 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16722 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16723 return;
16724
e70e9f8e
PZ
16725 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16726 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16727
16728 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16729
16730 } else {
16731 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16732 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16733 bgp->vpn_policy[afi].tovpn_label);
16734 }
ddb5b488
PZ
16735 }
16736 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16737 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16738 char buf[RD_ADDRSTRLEN];
b9c7bc5a 16739 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
16740 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16741 sizeof(buf)));
16742 }
16743 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16744 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16745
16746 char buf[PREFIX_STRLEN];
16747 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16748 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16749 sizeof(buf))) {
16750
b9c7bc5a
PZ
16751 vty_out(vty, "%*snexthop vpn export %s\n",
16752 indent, "", buf);
ddb5b488
PZ
16753 }
16754 }
16755 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16756 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16757 && ecommunity_cmp(
16758 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16759 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16760
16761 char *b = ecommunity_ecom2str(
16762 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16763 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16764 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
16765 XFREE(MTYPE_ECOMMUNITY_STR, b);
16766 } else {
16767 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16768 char *b = ecommunity_ecom2str(
16769 bgp->vpn_policy[afi]
16770 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16771 ECOMMUNITY_FORMAT_ROUTE_MAP,
16772 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16773 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
16774 XFREE(MTYPE_ECOMMUNITY_STR, b);
16775 }
16776 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16777 char *b = ecommunity_ecom2str(
16778 bgp->vpn_policy[afi]
16779 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16780 ECOMMUNITY_FORMAT_ROUTE_MAP,
16781 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 16782 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
16783 XFREE(MTYPE_ECOMMUNITY_STR, b);
16784 }
16785 }
bb4f6190
DS
16786
16787 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
b9c7bc5a 16788 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
16789 bgp->vpn_policy[afi]
16790 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
bb4f6190 16791
301ad80a
PG
16792 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16793 char *b = ecommunity_ecom2str(
16794 bgp->vpn_policy[afi]
16795 .import_redirect_rtlist,
16796 ECOMMUNITY_FORMAT_ROUTE_MAP,
16797 ECOMMUNITY_ROUTE_TARGET);
ddb5b488 16798
9a659715
PG
16799 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16800 != ECOMMUNITY_SIZE)
c6423c31 16801 vty_out(vty, "%*srt6 redirect import %s\n",
9a659715
PG
16802 indent, "", b);
16803 else
16804 vty_out(vty, "%*srt redirect import %s\n",
16805 indent, "", b);
301ad80a
PG
16806 XFREE(MTYPE_ECOMMUNITY_STR, b);
16807 }
ddb5b488
PZ
16808}
16809
dd65f45e
DL
16810static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16811 afi_t afi, safi_t safi)
16812{
16813 struct bgp_filter *filter;
16814 char *addr;
16815
16816 addr = peer->host;
16817 filter = &peer->filter[afi][safi];
16818
16819 /* distribute-list. */
16820 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16821 FILTER_IN))
16822 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16823 filter->dlist[FILTER_IN].name);
16824
16825 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16826 FILTER_OUT))
16827 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16828 filter->dlist[FILTER_OUT].name);
16829
16830 /* prefix-list. */
16831 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16832 FILTER_IN))
16833 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16834 filter->plist[FILTER_IN].name);
16835
16836 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16837 FILTER_OUT))
16838 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16839 filter->plist[FILTER_OUT].name);
16840
16841 /* route-map. */
16842 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16843 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16844 filter->map[RMAP_IN].name);
16845
16846 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16847 RMAP_OUT))
16848 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16849 filter->map[RMAP_OUT].name);
16850
16851 /* unsuppress-map */
16852 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16853 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16854 filter->usmap.name);
16855
7f7940e6
MK
16856 /* advertise-map : always applied in OUT direction*/
16857 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16858 CONDITION_NON_EXIST))
16859 vty_out(vty,
16860 " neighbor %s advertise-map %s non-exist-map %s\n",
16861 addr, filter->advmap.aname, filter->advmap.cname);
16862
16863 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16864 CONDITION_EXIST))
16865 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16866 addr, filter->advmap.aname, filter->advmap.cname);
16867
dd65f45e
DL
16868 /* filter-list. */
16869 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16870 FILTER_IN))
16871 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16872 filter->aslist[FILTER_IN].name);
16873
16874 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16875 FILTER_OUT))
16876 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16877 filter->aslist[FILTER_OUT].name);
16878}
16879
16880/* BGP peer configuration display function. */
16881static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16882 struct peer *peer)
16883{
16884 struct peer *g_peer = NULL;
16885 char buf[SU_ADDRSTRLEN];
16886 char *addr;
16887 int if_pg_printed = false;
16888 int if_ras_printed = false;
16889
16890 /* Skip dynamic neighbors. */
16891 if (peer_dynamic_neighbor(peer))
16892 return;
16893
16894 if (peer->conf_if)
16895 addr = peer->conf_if;
16896 else
16897 addr = peer->host;
16898
16899 /************************************
16900 ****** Global to the neighbor ******
16901 ************************************/
16902 if (peer->conf_if) {
16903 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16904 vty_out(vty, " neighbor %s interface v6only", addr);
16905 else
16906 vty_out(vty, " neighbor %s interface", addr);
16907
16908 if (peer_group_active(peer)) {
16909 vty_out(vty, " peer-group %s", peer->group->name);
16910 if_pg_printed = true;
16911 } else if (peer->as_type == AS_SPECIFIED) {
16912 vty_out(vty, " remote-as %u", peer->as);
16913 if_ras_printed = true;
16914 } else if (peer->as_type == AS_INTERNAL) {
16915 vty_out(vty, " remote-as internal");
16916 if_ras_printed = true;
16917 } else if (peer->as_type == AS_EXTERNAL) {
16918 vty_out(vty, " remote-as external");
16919 if_ras_printed = true;
16920 }
16921
16922 vty_out(vty, "\n");
16923 }
16924
16925 /* remote-as and peer-group */
16926 /* peer is a member of a peer-group */
16927 if (peer_group_active(peer)) {
16928 g_peer = peer->group->conf;
16929
16930 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16931 if (peer->as_type == AS_SPECIFIED) {
16932 vty_out(vty, " neighbor %s remote-as %u\n",
16933 addr, peer->as);
16934 } else if (peer->as_type == AS_INTERNAL) {
16935 vty_out(vty,
16936 " neighbor %s remote-as internal\n",
16937 addr);
16938 } else if (peer->as_type == AS_EXTERNAL) {
16939 vty_out(vty,
16940 " neighbor %s remote-as external\n",
16941 addr);
16942 }
16943 }
16944
16945 /* For swpX peers we displayed the peer-group
16946 * via 'neighbor swpX interface peer-group PGNAME' */
16947 if (!if_pg_printed)
16948 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16949 peer->group->name);
16950 }
16951
16952 /* peer is NOT a member of a peer-group */
16953 else {
16954 /* peer is a peer-group, declare the peer-group */
16955 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16956 vty_out(vty, " neighbor %s peer-group\n", addr);
16957 }
16958
16959 if (!if_ras_printed) {
16960 if (peer->as_type == AS_SPECIFIED) {
16961 vty_out(vty, " neighbor %s remote-as %u\n",
16962 addr, peer->as);
16963 } else if (peer->as_type == AS_INTERNAL) {
16964 vty_out(vty,
16965 " neighbor %s remote-as internal\n",
16966 addr);
16967 } else if (peer->as_type == AS_EXTERNAL) {
16968 vty_out(vty,
16969 " neighbor %s remote-as external\n",
16970 addr);
16971 }
16972 }
16973 }
16974
16975 /* local-as */
16976 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16977 vty_out(vty, " neighbor %s local-as %u", addr,
16978 peer->change_local_as);
16979 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16980 vty_out(vty, " no-prepend");
16981 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16982 vty_out(vty, " replace-as");
16983 vty_out(vty, "\n");
16984 }
16985
16986 /* description */
16987 if (peer->desc) {
16988 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16989 }
16990
16991 /* shutdown */
16992 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16993 if (peer->tx_shutdown_message)
16994 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16995 peer->tx_shutdown_message);
16996 else
16997 vty_out(vty, " neighbor %s shutdown\n", addr);
16998 }
16999
8336c896
DA
17000 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
17001 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
17002 peer->rtt_expected, peer->rtt_keepalive_conf);
17003
dd65f45e 17004 /* bfd */
21bfce98
RZ
17005 if (peer->bfd_config)
17006 bgp_bfd_peer_config_write(vty, peer, addr);
dd65f45e
DL
17007
17008 /* password */
17009 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
17010 vty_out(vty, " neighbor %s password %s\n", addr,
17011 peer->password);
17012
17013 /* neighbor solo */
17014 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
17015 if (!peer_group_active(peer)) {
17016 vty_out(vty, " neighbor %s solo\n", addr);
17017 }
17018 }
17019
17020 /* BGP port */
17021 if (peer->port != BGP_PORT_DEFAULT) {
17022 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
17023 }
17024
17025 /* Local interface name */
17026 if (peer->ifname) {
17027 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
17028 }
17029
4ab46701
AR
17030 /* TCP max segment size */
17031 if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS))
17032 vty_out(vty, " neighbor %s tcp-mss %d\n", addr, peer->tcp_mss);
17033
dd65f45e
DL
17034 /* passive */
17035 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
17036 vty_out(vty, " neighbor %s passive\n", addr);
17037
17038 /* ebgp-multihop */
17039 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
e2521429
DA
17040 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
17041 && peer->ttl == MAXTTL)) {
dd65f45e
DL
17042 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
17043 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
17044 peer->ttl);
17045 }
17046 }
17047
17048 /* ttl-security hops */
e2521429 17049 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
dd65f45e
DL
17050 if (!peer_group_active(peer)
17051 || g_peer->gtsm_hops != peer->gtsm_hops) {
17052 vty_out(vty, " neighbor %s ttl-security hops %d\n",
17053 addr, peer->gtsm_hops);
17054 }
17055 }
17056
17057 /* disable-connected-check */
17058 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
17059 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
17060
17061 /* enforce-first-as */
17062 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
17063 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
17064
17065 /* update-source */
17066 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
17067 if (peer->update_source)
17068 vty_out(vty, " neighbor %s update-source %s\n", addr,
17069 sockunion2str(peer->update_source, buf,
17070 SU_ADDRSTRLEN));
17071 else if (peer->update_if)
17072 vty_out(vty, " neighbor %s update-source %s\n", addr,
17073 peer->update_if);
17074 }
17075
17076 /* advertisement-interval */
17077 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
17078 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
17079 peer->routeadv);
17080
17081 /* timers */
17082 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
17083 vty_out(vty, " neighbor %s timers %u %u\n", addr,
17084 peer->keepalive, peer->holdtime);
17085
17086 /* timers connect */
17087 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
17088 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17089 peer->connect);
5d5393b9
DL
17090 /* need special-case handling for changed default values due to
17091 * config profile / version (because there is no "timers bgp connect"
17092 * command, we need to save this per-peer :/)
17093 */
17094 else if (!peer_group_active(peer) && !peer->connect &&
17095 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
17096 vty_out(vty, " neighbor %s timers connect %u\n", addr,
17097 peer->bgp->default_connect_retry);
dd65f45e 17098
d43114f3
DS
17099 /* timers delayopen */
17100 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
17101 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17102 peer->delayopen);
17103 /* Save config even though flag is not set if default values have been
17104 * changed
17105 */
17106 else if (!peer_group_active(peer) && !peer->delayopen
17107 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
17108 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
17109 peer->bgp->default_delayopen);
17110
dd65f45e
DL
17111 /* capability dynamic */
17112 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
17113 vty_out(vty, " neighbor %s capability dynamic\n", addr);
17114
17115 /* capability extended-nexthop */
17116 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
17117 if (!peer->conf_if) {
17118 if (CHECK_FLAG(peer->flags_invert,
17119 PEER_FLAG_CAPABILITY_ENHE))
17120 vty_out(vty,
17121 " no neighbor %s capability extended-nexthop\n",
17122 addr);
17123 else
17124 vty_out(vty,
17125 " neighbor %s capability extended-nexthop\n",
17126 addr);
17127 }
17128 }
17129
17130 /* dont-capability-negotiation */
17131 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
17132 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
17133
17134 /* override-capability */
17135 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
17136 vty_out(vty, " neighbor %s override-capability\n", addr);
17137
17138 /* strict-capability-match */
17139 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
17140 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
17141
17142 /* Sender side AS path loop detection. */
17143 if (peer->as_path_loop_detection)
17144 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
17145 addr);
cfd47646 17146
17147 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17148 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
cfd47646 17149
17150 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
13909c4f 17151 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
cfd47646 17152 vty_out(vty,
17153 " neighbor %s graceful-restart-helper\n", addr);
13909c4f
DS
17154 } else if (CHECK_FLAG(
17155 peer->peer_gr_new_status_flag,
17156 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
cfd47646 17157 vty_out(vty,
17158 " neighbor %s graceful-restart\n", addr);
13909c4f
DS
17159 } else if (
17160 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
17161 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
17162 && !(CHECK_FLAG(
17163 peer->peer_gr_new_status_flag,
17164 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
17165 vty_out(vty, " neighbor %s graceful-restart-disable\n",
17166 addr);
cfd47646 17167 }
17168 }
dd65f45e
DL
17169}
17170
17171/* BGP peer configuration display function. */
17172static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
17173 struct peer *peer, afi_t afi, safi_t safi)
17174{
17175 struct peer *g_peer = NULL;
17176 char *addr;
17177 bool flag_scomm, flag_secomm, flag_slcomm;
17178
17179 /* Skip dynamic neighbors. */
17180 if (peer_dynamic_neighbor(peer))
17181 return;
17182
17183 if (peer->conf_if)
17184 addr = peer->conf_if;
17185 else
17186 addr = peer->host;
17187
17188 /************************************
17189 ****** Per AF to the neighbor ******
17190 ************************************/
17191 if (peer_group_active(peer)) {
17192 g_peer = peer->group->conf;
17193
17194 /* If the peer-group is active but peer is not, print a 'no
17195 * activate' */
17196 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
17197 vty_out(vty, " no neighbor %s activate\n", addr);
17198 }
17199
17200 /* If the peer-group is not active but peer is, print an
17201 'activate' */
17202 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
17203 vty_out(vty, " neighbor %s activate\n", addr);
17204 }
17205 } else {
17206 if (peer->afc[afi][safi]) {
e84c59af
DA
17207 if ((afi == AFI_IP || afi == AFI_IP6)
17208 && safi == SAFI_UNICAST) {
17209 if (afi == AFI_IP
17210 && CHECK_FLAG(bgp->flags,
17211 BGP_FLAG_NO_DEFAULT_IPV4)) {
17212 vty_out(vty, " neighbor %s activate\n",
17213 addr);
17214 } else if (afi == AFI_IP6
17215 && !CHECK_FLAG(
17216 bgp->flags,
17217 BGP_FLAG_DEFAULT_IPV6)) {
dd65f45e
DL
17218 vty_out(vty, " neighbor %s activate\n",
17219 addr);
17220 }
e84c59af 17221 } else {
dd65f45e 17222 vty_out(vty, " neighbor %s activate\n", addr);
e84c59af 17223 }
dd65f45e 17224 } else {
e84c59af
DA
17225 if ((afi == AFI_IP || afi == AFI_IP6)
17226 && safi == SAFI_UNICAST) {
17227 if (afi == AFI_IP
17228 && !CHECK_FLAG(bgp->flags,
17229 BGP_FLAG_NO_DEFAULT_IPV4)) {
17230 vty_out(vty,
17231 " no neighbor %s activate\n",
17232 addr);
17233 } else if (afi == AFI_IP6
17234 && CHECK_FLAG(
17235 bgp->flags,
17236 BGP_FLAG_DEFAULT_IPV6)) {
dd65f45e
DL
17237 vty_out(vty,
17238 " no neighbor %s activate\n",
17239 addr);
17240 }
17241 }
17242 }
17243 }
17244
17245 /* addpath TX knobs */
17246 if (peergroup_af_addpath_check(peer, afi, safi)) {
17247 switch (peer->addpath_type[afi][safi]) {
17248 case BGP_ADDPATH_ALL:
17249 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
17250 addr);
17251 break;
17252 case BGP_ADDPATH_BEST_PER_AS:
17253 vty_out(vty,
17254 " neighbor %s addpath-tx-bestpath-per-AS\n",
17255 addr);
17256 break;
17257 case BGP_ADDPATH_MAX:
17258 case BGP_ADDPATH_NONE:
17259 break;
17260 }
17261 }
17262
17263 /* ORF capability. */
17264 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
17265 || peergroup_af_flag_check(peer, afi, safi,
17266 PEER_FLAG_ORF_PREFIX_RM)) {
17267 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
17268
17269 if (peergroup_af_flag_check(peer, afi, safi,
17270 PEER_FLAG_ORF_PREFIX_SM)
17271 && peergroup_af_flag_check(peer, afi, safi,
17272 PEER_FLAG_ORF_PREFIX_RM))
17273 vty_out(vty, " both");
17274 else if (peergroup_af_flag_check(peer, afi, safi,
17275 PEER_FLAG_ORF_PREFIX_SM))
17276 vty_out(vty, " send");
17277 else
17278 vty_out(vty, " receive");
17279 vty_out(vty, "\n");
17280 }
17281
dd65f45e
DL
17282 /* Route reflector client. */
17283 if (peergroup_af_flag_check(peer, afi, safi,
17284 PEER_FLAG_REFLECTOR_CLIENT)) {
17285 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
17286 }
17287
17288 /* next-hop-self force */
17289 if (peergroup_af_flag_check(peer, afi, safi,
17290 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
17291 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
17292 }
17293
17294 /* next-hop-self */
17295 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
17296 vty_out(vty, " neighbor %s next-hop-self\n", addr);
17297 }
17298
17299 /* remove-private-AS */
17300 if (peergroup_af_flag_check(peer, afi, safi,
17301 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
17302 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
17303 addr);
17304 }
17305
17306 else if (peergroup_af_flag_check(peer, afi, safi,
17307 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
17308 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
17309 addr);
17310 }
17311
17312 else if (peergroup_af_flag_check(peer, afi, safi,
17313 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
17314 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
17315 }
17316
17317 else if (peergroup_af_flag_check(peer, afi, safi,
17318 PEER_FLAG_REMOVE_PRIVATE_AS)) {
17319 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
17320 }
17321
17322 /* as-override */
17323 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
17324 vty_out(vty, " neighbor %s as-override\n", addr);
17325 }
17326
17327 /* send-community print. */
17328 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
17329 PEER_FLAG_SEND_COMMUNITY);
17330 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
17331 PEER_FLAG_SEND_EXT_COMMUNITY);
17332 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
17333 PEER_FLAG_SEND_LARGE_COMMUNITY);
17334
17335 if (flag_scomm && flag_secomm && flag_slcomm) {
17336 vty_out(vty, " no neighbor %s send-community all\n", addr);
17337 } else {
17338 if (flag_scomm)
17339 vty_out(vty, " no neighbor %s send-community\n", addr);
17340 if (flag_secomm)
17341 vty_out(vty,
17342 " no neighbor %s send-community extended\n",
17343 addr);
17344
17345 if (flag_slcomm)
17346 vty_out(vty, " no neighbor %s send-community large\n",
17347 addr);
17348 }
17349
17350 /* Default information */
17351 if (peergroup_af_flag_check(peer, afi, safi,
17352 PEER_FLAG_DEFAULT_ORIGINATE)) {
17353 vty_out(vty, " neighbor %s default-originate", addr);
17354
17355 if (peer->default_rmap[afi][safi].name)
17356 vty_out(vty, " route-map %s",
17357 peer->default_rmap[afi][safi].name);
17358
17359 vty_out(vty, "\n");
17360 }
17361
17362 /* Soft reconfiguration inbound. */
17363 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
17364 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
17365 addr);
17366 }
17367
17368 /* maximum-prefix. */
17369 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
6cde4b45 17370 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
dd65f45e
DL
17371 peer->pmax[afi][safi]);
17372
17373 if (peer->pmax_threshold[afi][safi]
17374 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
17375 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
17376 if (peer_af_flag_check(peer, afi, safi,
17377 PEER_FLAG_MAX_PREFIX_WARNING))
17378 vty_out(vty, " warning-only");
17379 if (peer->pmax_restart[afi][safi])
17380 vty_out(vty, " restart %u",
17381 peer->pmax_restart[afi][safi]);
9cbd06e0
DA
17382 if (peer_af_flag_check(peer, afi, safi,
17383 PEER_FLAG_MAX_PREFIX_FORCE))
17384 vty_out(vty, " force");
dd65f45e
DL
17385
17386 vty_out(vty, "\n");
17387 }
17388
fde246e8
DA
17389 /* maximum-prefix-out */
17390 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
6cde4b45 17391 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
fde246e8
DA
17392 addr, peer->pmax_out[afi][safi]);
17393
dd65f45e
DL
17394 /* Route server client. */
17395 if (peergroup_af_flag_check(peer, afi, safi,
17396 PEER_FLAG_RSERVER_CLIENT)) {
17397 vty_out(vty, " neighbor %s route-server-client\n", addr);
17398 }
17399
17400 /* Nexthop-local unchanged. */
17401 if (peergroup_af_flag_check(peer, afi, safi,
17402 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
17403 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
17404 }
17405
17406 /* allowas-in <1-10> */
17407 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
17408 if (peer_af_flag_check(peer, afi, safi,
17409 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
17410 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
17411 } else if (peer->allowas_in[afi][safi] == 3) {
17412 vty_out(vty, " neighbor %s allowas-in\n", addr);
17413 } else {
17414 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
17415 peer->allowas_in[afi][safi]);
17416 }
17417 }
17418
17419 /* weight */
17420 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
17421 vty_out(vty, " neighbor %s weight %lu\n", addr,
17422 peer->weight[afi][safi]);
17423
17424 /* Filter. */
17425 bgp_config_write_filter(vty, peer, afi, safi);
17426
17427 /* atribute-unchanged. */
17428 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
17429 || (safi != SAFI_EVPN
17430 && peer_af_flag_check(peer, afi, safi,
17431 PEER_FLAG_NEXTHOP_UNCHANGED))
17432 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
17433
17434 if (!peer_group_active(peer)
17435 || peergroup_af_flag_check(peer, afi, safi,
17436 PEER_FLAG_AS_PATH_UNCHANGED)
17437 || peergroup_af_flag_check(peer, afi, safi,
17438 PEER_FLAG_NEXTHOP_UNCHANGED)
17439 || peergroup_af_flag_check(peer, afi, safi,
17440 PEER_FLAG_MED_UNCHANGED)) {
17441
17442 vty_out(vty,
17443 " neighbor %s attribute-unchanged%s%s%s\n",
17444 addr,
17445 peer_af_flag_check(peer, afi, safi,
17446 PEER_FLAG_AS_PATH_UNCHANGED)
17447 ? " as-path"
17448 : "",
17449 peer_af_flag_check(peer, afi, safi,
17450 PEER_FLAG_NEXTHOP_UNCHANGED)
17451 ? " next-hop"
17452 : "",
17453 peer_af_flag_check(peer, afi, safi,
17454 PEER_FLAG_MED_UNCHANGED)
17455 ? " med"
17456 : "");
17457 }
17458 }
39d8dd2d
DS
17459
17460 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_CONFIG_DAMPENING))
17461 bgp_config_write_peer_damp(vty, peer, afi, safi);
dd65f45e
DL
17462}
17463
17464/* Address family based peer configuration display. */
17465static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17466 safi_t safi)
17467{
17468 struct peer *peer;
17469 struct peer_group *group;
17470 struct listnode *node, *nnode;
17471
17472
17473 vty_frame(vty, " !\n address-family ");
17474 if (afi == AFI_IP) {
17475 if (safi == SAFI_UNICAST)
17476 vty_frame(vty, "ipv4 unicast");
17477 else if (safi == SAFI_LABELED_UNICAST)
17478 vty_frame(vty, "ipv4 labeled-unicast");
17479 else if (safi == SAFI_MULTICAST)
17480 vty_frame(vty, "ipv4 multicast");
17481 else if (safi == SAFI_MPLS_VPN)
17482 vty_frame(vty, "ipv4 vpn");
17483 else if (safi == SAFI_ENCAP)
17484 vty_frame(vty, "ipv4 encap");
17485 else if (safi == SAFI_FLOWSPEC)
17486 vty_frame(vty, "ipv4 flowspec");
17487 } else if (afi == AFI_IP6) {
17488 if (safi == SAFI_UNICAST)
17489 vty_frame(vty, "ipv6 unicast");
17490 else if (safi == SAFI_LABELED_UNICAST)
17491 vty_frame(vty, "ipv6 labeled-unicast");
17492 else if (safi == SAFI_MULTICAST)
17493 vty_frame(vty, "ipv6 multicast");
17494 else if (safi == SAFI_MPLS_VPN)
17495 vty_frame(vty, "ipv6 vpn");
17496 else if (safi == SAFI_ENCAP)
17497 vty_frame(vty, "ipv6 encap");
17498 else if (safi == SAFI_FLOWSPEC)
17499 vty_frame(vty, "ipv6 flowspec");
17500 } else if (afi == AFI_L2VPN) {
17501 if (safi == SAFI_EVPN)
17502 vty_frame(vty, "l2vpn evpn");
17503 }
17504 vty_frame(vty, "\n");
17505
17506 bgp_config_write_distance(vty, bgp, afi, safi);
17507
17508 bgp_config_write_network(vty, bgp, afi, safi);
17509
17510 bgp_config_write_redistribute(vty, bgp, afi, safi);
17511
8a4e7fe6
DA
17512 /* BGP flag dampening. */
17513 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
0221327c 17514 bgp_config_write_damp(vty, bgp, afi, safi);
8a4e7fe6 17515
dd65f45e
DL
17516 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17517 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17518
17519 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
dd65f45e
DL
17520 /* Do not display doppelganger peers */
17521 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17522 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17523 }
17524
17525 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17526 bgp_config_write_table_map(vty, bgp, afi, safi);
17527
17528 if (safi == SAFI_EVPN)
17529 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17530
17531 if (safi == SAFI_FLOWSPEC)
17532 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17533
17534 if (safi == SAFI_UNICAST) {
17535 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17536 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17537 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17538
17539 vty_out(vty, " export vpn\n");
17540 }
17541 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17542 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17543
17544 vty_out(vty, " import vpn\n");
17545 }
17546 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17547 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17548 char *name;
17549
17550 for (ALL_LIST_ELEMENTS_RO(
17551 bgp->vpn_policy[afi].import_vrf, node,
17552 name))
17553 vty_out(vty, " import vrf %s\n", name);
17554 }
17555 }
17556
17557 vty_endframe(vty, " exit-address-family\n");
17558}
17559
17560int bgp_config_write(struct vty *vty)
17561{
17562 struct bgp *bgp;
17563 struct peer_group *group;
17564 struct peer *peer;
17565 struct listnode *node, *nnode;
17566 struct listnode *mnode, *mnnode;
17567
17568 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17569 vty_out(vty, "bgp route-map delay-timer %u\n",
17570 bm->rmap_update_timer);
17571
d70583f7
D
17572 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17573 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17574 if (bm->v_update_delay != bm->v_establish_wait)
17575 vty_out(vty, " %d", bm->v_establish_wait);
17576 vty_out(vty, "\n");
17577 }
17578
9acb67cb
DS
17579 if (bm->wait_for_fib)
17580 vty_out(vty, "bgp suppress-fib-pending\n");
17581
05bd726c 17582 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17583 vty_out(vty, "bgp graceful-shutdown\n");
17584
c163f297
DS
17585 /* No-RIB (Zebra) option flag configuration */
17586 if (bgp_option_check(BGP_OPT_NO_FIB))
17587 vty_out(vty, "bgp no-rib\n");
17588
ec0acb80 17589 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
e46723a5
DS
17590 vty_out(vty, "no bgp send-extra-data zebra\n");
17591
dd65f45e
DL
17592 /* BGP configuration. */
17593 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17594
17595 /* skip all auto created vrf as they dont have user config */
17596 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17597 continue;
17598
17599 /* Router bgp ASN */
17600 vty_out(vty, "router bgp %u", bgp->as);
17601
17602 if (bgp->name)
17603 vty_out(vty, " %s %s",
17604 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17605 ? "view" : "vrf", bgp->name);
17606 vty_out(vty, "\n");
17607
17608 /* BGP fast-external-failover. */
17609 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17610 vty_out(vty, " no bgp fast-external-failover\n");
17611
17612 /* BGP router ID. */
3a6290bd 17613 if (bgp->router_id_static.s_addr != INADDR_ANY)
23d0a753
DA
17614 vty_out(vty, " bgp router-id %pI4\n",
17615 &bgp->router_id_static);
dd65f45e 17616
c208c586
S
17617 /* Suppress fib pending */
17618 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17619 vty_out(vty, " bgp suppress-fib-pending\n");
17620
dd65f45e 17621 /* BGP log-neighbor-changes. */
892fedb6 17622 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
5d5393b9 17623 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
dd65f45e 17624 vty_out(vty, " %sbgp log-neighbor-changes\n",
892fedb6
DA
17625 CHECK_FLAG(bgp->flags,
17626 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
dd65f45e
DL
17627 ? ""
17628 : "no ");
17629
17630 /* BGP configuration. */
892fedb6 17631 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
dd65f45e
DL
17632 vty_out(vty, " bgp always-compare-med\n");
17633
17634 /* RFC8212 default eBGP policy. */
1d3fdccf
DA
17635 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17636 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17637 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17638 CHECK_FLAG(bgp->flags,
17639 BGP_FLAG_EBGP_REQUIRES_POLICY)
17640 ? ""
17641 : "no ");
dd65f45e
DL
17642
17643 /* draft-ietf-idr-deprecate-as-set-confed-set */
7f972cd8 17644 if (bgp->reject_as_sets)
dd65f45e
DL
17645 vty_out(vty, " bgp reject-as-sets\n");
17646
2adac256
DA
17647 /* Suppress duplicate updates if the route actually not changed
17648 */
17649 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17650 != SAVE_BGP_SUPPRESS_DUPLICATES)
17651 vty_out(vty, " %sbgp suppress-duplicates\n",
17652 CHECK_FLAG(bgp->flags,
17653 BGP_FLAG_SUPPRESS_DUPLICATES)
17654 ? ""
17655 : "no ");
17656
dd65f45e 17657 /* BGP default ipv4-unicast. */
892fedb6 17658 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
dd65f45e
DL
17659 vty_out(vty, " no bgp default ipv4-unicast\n");
17660
e84c59af
DA
17661 /* BGP default ipv6-unicast. */
17662 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DEFAULT_IPV6))
17663 vty_out(vty, " bgp default ipv6-unicast\n");
17664
dd65f45e
DL
17665 /* BGP default local-preference. */
17666 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17667 vty_out(vty, " bgp default local-preference %u\n",
17668 bgp->default_local_pref);
17669
17670 /* BGP default show-hostname */
892fedb6 17671 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
5d5393b9 17672 != SAVE_BGP_SHOW_HOSTNAME)
dd65f45e 17673 vty_out(vty, " %sbgp default show-hostname\n",
892fedb6 17674 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
dd65f45e
DL
17675 ? ""
17676 : "no ");
17677
aef999a2
DA
17678 /* BGP default show-nexthop-hostname */
17679 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17680 != SAVE_BGP_SHOW_HOSTNAME)
17681 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17682 CHECK_FLAG(bgp->flags,
17683 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17684 ? ""
17685 : "no ");
17686
dd65f45e
DL
17687 /* BGP default subgroup-pkt-queue-max. */
17688 if (bgp->default_subgroup_pkt_queue_max
17689 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17690 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17691 bgp->default_subgroup_pkt_queue_max);
17692
17693 /* BGP client-to-client reflection. */
892fedb6 17694 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
dd65f45e
DL
17695 vty_out(vty, " no bgp client-to-client reflection\n");
17696
17697 /* BGP cluster ID. */
17698 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
23d0a753
DA
17699 vty_out(vty, " bgp cluster-id %pI4\n",
17700 &bgp->cluster_id);
dd65f45e
DL
17701
17702 /* Disable ebgp connected nexthop check */
892fedb6 17703 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
dd65f45e
DL
17704 vty_out(vty,
17705 " bgp disable-ebgp-connected-route-check\n");
17706
17707 /* Confederation identifier*/
17708 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17709 vty_out(vty, " bgp confederation identifier %u\n",
17710 bgp->confed_id);
17711
17712 /* Confederation peer */
17713 if (bgp->confed_peers_cnt > 0) {
17714 int i;
17715
17716 vty_out(vty, " bgp confederation peers");
17717
17718 for (i = 0; i < bgp->confed_peers_cnt; i++)
17719 vty_out(vty, " %u", bgp->confed_peers[i]);
17720
17721 vty_out(vty, "\n");
17722 }
17723
17724 /* BGP deterministic-med. */
892fedb6 17725 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
5d5393b9 17726 != SAVE_BGP_DETERMINISTIC_MED)
dd65f45e 17727 vty_out(vty, " %sbgp deterministic-med\n",
892fedb6
DA
17728 CHECK_FLAG(bgp->flags,
17729 BGP_FLAG_DETERMINISTIC_MED)
dd65f45e
DL
17730 ? ""
17731 : "no ");
17732
17733 /* BGP update-delay. */
17734 bgp_config_write_update_delay(vty, bgp);
17735
17736 if (bgp->v_maxmed_onstartup
17737 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17738 vty_out(vty, " bgp max-med on-startup %u",
17739 bgp->v_maxmed_onstartup);
17740 if (bgp->maxmed_onstartup_value
17741 != BGP_MAXMED_VALUE_DEFAULT)
17742 vty_out(vty, " %u",
17743 bgp->maxmed_onstartup_value);
17744 vty_out(vty, "\n");
17745 }
17746 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17747 vty_out(vty, " bgp max-med administrative");
17748 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17749 vty_out(vty, " %u", bgp->maxmed_admin_value);
17750 vty_out(vty, "\n");
17751 }
17752
17753 /* write quanta */
17754 bgp_config_write_wpkt_quanta(vty, bgp);
17755 /* read quanta */
17756 bgp_config_write_rpkt_quanta(vty, bgp);
17757
17758 /* coalesce time */
17759 bgp_config_write_coalesce_time(vty, bgp);
17760
05bd726c 17761 /* BGP per-instance graceful-shutdown */
17762 /* BGP-wide settings and per-instance settings are mutually
17763 * exclusive.
17764 */
17765 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17766 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17767 vty_out(vty, " bgp graceful-shutdown\n");
17768
dd65f45e
DL
17769 /* BGP graceful-restart. */
17770 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17771 vty_out(vty,
17772 " bgp graceful-restart stalepath-time %u\n",
17773 bgp->stalepath_time);
cfd47646 17774
dd65f45e
DL
17775 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17776 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17777 bgp->restart_time);
cfd47646 17778
17779 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17780 vty_out(vty,
17781 " bgp graceful-restart select-defer-time %u\n",
17782 bgp->select_defer_time);
17783
17784 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
dd65f45e
DL
17785 vty_out(vty, " bgp graceful-restart\n");
17786
cfd47646 17787 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17788 vty_out(vty, " bgp graceful-restart-disable\n");
17789
dd65f45e 17790 /* BGP graceful-restart Preserve State F bit. */
892fedb6 17791 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
dd65f45e
DL
17792 vty_out(vty,
17793 " bgp graceful-restart preserve-fw-state\n");
17794
dc95985f 17795 /* Stale timer for RIB */
17796 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17797 vty_out(vty,
17798 " bgp graceful-restart rib-stale-time %u\n",
17799 bgp->rib_stale_time);
17800
dd65f45e 17801 /* BGP bestpath method. */
892fedb6 17802 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
dd65f45e 17803 vty_out(vty, " bgp bestpath as-path ignore\n");
892fedb6 17804 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
dd65f45e
DL
17805 vty_out(vty, " bgp bestpath as-path confed\n");
17806
892fedb6
DA
17807 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17808 if (CHECK_FLAG(bgp->flags,
17809 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
dd65f45e
DL
17810 vty_out(vty,
17811 " bgp bestpath as-path multipath-relax as-set\n");
17812 } else {
17813 vty_out(vty,
17814 " bgp bestpath as-path multipath-relax\n");
17815 }
17816 }
17817
892fedb6 17818 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dd65f45e
DL
17819 vty_out(vty,
17820 " bgp route-reflector allow-outbound-policy\n");
17821 }
892fedb6 17822 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
dd65f45e 17823 vty_out(vty, " bgp bestpath compare-routerid\n");
892fedb6
DA
17824 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17825 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
dd65f45e 17826 vty_out(vty, " bgp bestpath med");
892fedb6 17827 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
dd65f45e 17828 vty_out(vty, " confed");
892fedb6
DA
17829 if (CHECK_FLAG(bgp->flags,
17830 BGP_FLAG_MED_MISSING_AS_WORST))
dd65f45e
DL
17831 vty_out(vty, " missing-as-worst");
17832 vty_out(vty, "\n");
17833 }
17834
ee88563a
JM
17835 if (CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
17836 vty_out(vty,
17837 " bgp bestpath peer-type multipath-relax\n");
17838
f7e1c681 17839 /* Link bandwidth handling. */
17840 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17841 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17842 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17843 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17844 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17845 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17846
dd65f45e 17847 /* BGP network import check. */
892fedb6 17848 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
5d5393b9 17849 != SAVE_BGP_IMPORT_CHECK)
dd65f45e 17850 vty_out(vty, " %sbgp network import-check\n",
892fedb6 17851 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
dd65f45e
DL
17852 ? ""
17853 : "no ");
17854
17855 /* BGP timers configuration. */
5d5393b9 17856 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
9800cfff 17857 || bgp->default_holdtime != SAVE_BGP_HOLDTIME)
dd65f45e
DL
17858 vty_out(vty, " timers bgp %u %u\n",
17859 bgp->default_keepalive, bgp->default_holdtime);
17860
17861 /* peer-group */
17862 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17863 bgp_config_write_peer_global(vty, bgp, group->conf);
17864 }
17865
17866 /* Normal neighbor configuration. */
17867 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17868 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17869 bgp_config_write_peer_global(vty, bgp, peer);
17870 }
17871
17872 /* listen range and limit for dynamic BGP neighbors */
17873 bgp_config_write_listen(vty, bgp);
17874
17875 /*
17876 * BGP default autoshutdown neighbors
17877 *
17878 * This must be placed after any peer and peer-group
17879 * configuration, to avoid setting all peers to shutdown after
17880 * a daemon restart, which is undesired behavior. (see #2286)
17881 */
17882 if (bgp->autoshutdown)
17883 vty_out(vty, " bgp default shutdown\n");
17884
9cf59432
DS
17885 /* BGP instance administrative shutdown */
17886 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17887 vty_out(vty, " bgp shutdown\n");
17888
dd65f45e
DL
17889 /* IPv4 unicast configuration. */
17890 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17891
17892 /* IPv4 multicast configuration. */
17893 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17894
17895 /* IPv4 labeled-unicast configuration. */
17896 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17897
17898 /* IPv4 VPN configuration. */
17899 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17900
17901 /* ENCAPv4 configuration. */
17902 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17903
17904 /* FLOWSPEC v4 configuration. */
17905 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17906
17907 /* IPv6 unicast configuration. */
17908 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17909
17910 /* IPv6 multicast configuration. */
17911 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17912
17913 /* IPv6 labeled-unicast configuration. */
17914 bgp_config_write_family(vty, bgp, AFI_IP6,
17915 SAFI_LABELED_UNICAST);
17916
17917 /* IPv6 VPN configuration. */
17918 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17919
17920 /* ENCAPv6 configuration. */
17921 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17922
17923 /* FLOWSPEC v6 configuration. */
17924 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17925
17926 /* EVPN configuration. */
17927 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17928
17929 hook_call(bgp_inst_config_write, bgp, vty);
17930
49e5a4a0 17931#ifdef ENABLE_BGP_VNC
dd65f45e
DL
17932 bgp_rfapi_cfg_write(vty, bgp);
17933#endif
17934
17935 vty_out(vty, "!\n");
17936 }
17937 return 0;
17938}
17939
ddb5b488 17940
718e3744 17941/* BGP node structure. */
d62a17ae 17942static struct cmd_node bgp_node = {
f4b8291f 17943 .name = "bgp",
62b346ee 17944 .node = BGP_NODE,
24389580 17945 .parent_node = CONFIG_NODE,
62b346ee 17946 .prompt = "%s(config-router)# ",
612c2c15 17947 .config_write = bgp_config_write,
718e3744 17948};
17949
d62a17ae 17950static struct cmd_node bgp_ipv4_unicast_node = {
f4b8291f 17951 .name = "bgp ipv4 unicast",
62b346ee 17952 .node = BGP_IPV4_NODE,
24389580 17953 .parent_node = BGP_NODE,
62b346ee 17954 .prompt = "%s(config-router-af)# ",
718e3744 17955};
17956
d62a17ae 17957static struct cmd_node bgp_ipv4_multicast_node = {
f4b8291f 17958 .name = "bgp ipv4 multicast",
62b346ee 17959 .node = BGP_IPV4M_NODE,
24389580 17960 .parent_node = BGP_NODE,
62b346ee 17961 .prompt = "%s(config-router-af)# ",
718e3744 17962};
17963
d62a17ae 17964static struct cmd_node bgp_ipv4_labeled_unicast_node = {
f4b8291f 17965 .name = "bgp ipv4 labeled unicast",
62b346ee 17966 .node = BGP_IPV4L_NODE,
24389580 17967 .parent_node = BGP_NODE,
62b346ee 17968 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17969};
17970
d62a17ae 17971static struct cmd_node bgp_ipv6_unicast_node = {
f4b8291f 17972 .name = "bgp ipv6",
62b346ee 17973 .node = BGP_IPV6_NODE,
24389580 17974 .parent_node = BGP_NODE,
62b346ee 17975 .prompt = "%s(config-router-af)# ",
718e3744 17976};
17977
d62a17ae 17978static struct cmd_node bgp_ipv6_multicast_node = {
f4b8291f 17979 .name = "bgp ipv6 multicast",
62b346ee 17980 .node = BGP_IPV6M_NODE,
24389580 17981 .parent_node = BGP_NODE,
62b346ee 17982 .prompt = "%s(config-router-af)# ",
25ffbdc1 17983};
17984
d62a17ae 17985static struct cmd_node bgp_ipv6_labeled_unicast_node = {
f4b8291f 17986 .name = "bgp ipv6 labeled unicast",
62b346ee 17987 .node = BGP_IPV6L_NODE,
24389580 17988 .parent_node = BGP_NODE,
62b346ee 17989 .prompt = "%s(config-router-af)# ",
f51bae9c
DS
17990};
17991
62b346ee 17992static struct cmd_node bgp_vpnv4_node = {
f4b8291f 17993 .name = "bgp vpnv4",
62b346ee 17994 .node = BGP_VPNV4_NODE,
24389580 17995 .parent_node = BGP_NODE,
62b346ee 17996 .prompt = "%s(config-router-af)# ",
62b346ee 17997};
6b0655a2 17998
62b346ee 17999static struct cmd_node bgp_vpnv6_node = {
f4b8291f 18000 .name = "bgp vpnv6",
62b346ee 18001 .node = BGP_VPNV6_NODE,
24389580 18002 .parent_node = BGP_NODE,
62b346ee 18003 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 18004};
8ecd3266 18005
62b346ee 18006static struct cmd_node bgp_evpn_node = {
f4b8291f 18007 .name = "bgp evpn",
62b346ee 18008 .node = BGP_EVPN_NODE,
24389580 18009 .parent_node = BGP_NODE,
62b346ee 18010 .prompt = "%s(config-router-evpn)# ",
62b346ee 18011};
4e0b7b6d 18012
62b346ee 18013static struct cmd_node bgp_evpn_vni_node = {
f4b8291f 18014 .name = "bgp evpn vni",
62b346ee 18015 .node = BGP_EVPN_VNI_NODE,
24389580 18016 .parent_node = BGP_EVPN_NODE,
62b346ee 18017 .prompt = "%s(config-router-af-vni)# ",
62b346ee 18018};
90e60aa7 18019
62b346ee 18020static struct cmd_node bgp_flowspecv4_node = {
f4b8291f 18021 .name = "bgp ipv4 flowspec",
62b346ee 18022 .node = BGP_FLOWSPECV4_NODE,
24389580 18023 .parent_node = BGP_NODE,
62b346ee 18024 .prompt = "%s(config-router-af)# ",
62b346ee 18025};
7c40bf39 18026
62b346ee 18027static struct cmd_node bgp_flowspecv6_node = {
f4b8291f 18028 .name = "bgp ipv6 flowspec",
62b346ee 18029 .node = BGP_FLOWSPECV6_NODE,
24389580 18030 .parent_node = BGP_NODE,
62b346ee 18031 .prompt = "%s(config-router-af-vpnv6)# ",
62b346ee 18032};
7c40bf39 18033
bfaab44d
HS
18034static struct cmd_node bgp_srv6_node = {
18035 .name = "bgp srv6",
18036 .node = BGP_SRV6_NODE,
18037 .parent_node = BGP_NODE,
18038 .prompt = "%s(config-router-srv6)# ",
18039};
18040
d62a17ae 18041static void community_list_vty(void);
1f8ae70b 18042
d62a17ae 18043static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 18044{
d62a17ae 18045 struct bgp *bgp;
18046 struct peer *peer;
d62a17ae 18047 struct listnode *lnbgp, *lnpeer;
b8a815e5 18048
d62a17ae 18049 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18050 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
18051 /* only provide suggestions on the appropriate input
18052 * token type,
18053 * they'll otherwise show up multiple times */
18054 enum cmd_token_type match_type;
18055 char *name = peer->host;
d48ed3e0 18056
d62a17ae 18057 if (peer->conf_if) {
18058 match_type = VARIABLE_TKN;
18059 name = peer->conf_if;
18060 } else if (strchr(peer->host, ':'))
18061 match_type = IPV6_TKN;
18062 else
18063 match_type = IPV4_TKN;
d48ed3e0 18064
d62a17ae 18065 if (token->type != match_type)
18066 continue;
d48ed3e0 18067
d62a17ae 18068 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
18069 }
d62a17ae 18070 }
b8a815e5
DL
18071}
18072
18073static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 18074 {.varname = "neighbor", .completions = bgp_ac_neighbor},
18075 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 18076 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 18077 {.completions = NULL}};
18078
47a306a0
DS
18079static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
18080{
18081 struct bgp *bgp;
18082 struct peer_group *group;
18083 struct listnode *lnbgp, *lnpeer;
18084
18085 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
18086 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
18087 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
18088 group->name));
18089 }
18090}
18091
18092static const struct cmd_variable_handler bgp_var_peergroup[] = {
18093 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
18094 {.completions = NULL} };
18095
d62a17ae 18096void bgp_vty_init(void)
18097{
18098 cmd_variable_handler_register(bgp_var_neighbor);
47a306a0 18099 cmd_variable_handler_register(bgp_var_peergroup);
d62a17ae 18100
18101 /* Install bgp top node. */
612c2c15
DL
18102 install_node(&bgp_node);
18103 install_node(&bgp_ipv4_unicast_node);
18104 install_node(&bgp_ipv4_multicast_node);
18105 install_node(&bgp_ipv4_labeled_unicast_node);
18106 install_node(&bgp_ipv6_unicast_node);
18107 install_node(&bgp_ipv6_multicast_node);
18108 install_node(&bgp_ipv6_labeled_unicast_node);
18109 install_node(&bgp_vpnv4_node);
18110 install_node(&bgp_vpnv6_node);
18111 install_node(&bgp_evpn_node);
18112 install_node(&bgp_evpn_vni_node);
18113 install_node(&bgp_flowspecv4_node);
18114 install_node(&bgp_flowspecv6_node);
bfaab44d 18115 install_node(&bgp_srv6_node);
d62a17ae 18116
18117 /* Install default VTY commands to new nodes. */
18118 install_default(BGP_NODE);
18119 install_default(BGP_IPV4_NODE);
18120 install_default(BGP_IPV4M_NODE);
18121 install_default(BGP_IPV4L_NODE);
18122 install_default(BGP_IPV6_NODE);
18123 install_default(BGP_IPV6M_NODE);
18124 install_default(BGP_IPV6L_NODE);
18125 install_default(BGP_VPNV4_NODE);
18126 install_default(BGP_VPNV6_NODE);
7c40bf39 18127 install_default(BGP_FLOWSPECV4_NODE);
18128 install_default(BGP_FLOWSPECV6_NODE);
d62a17ae 18129 install_default(BGP_EVPN_NODE);
18130 install_default(BGP_EVPN_VNI_NODE);
bfaab44d 18131 install_default(BGP_SRV6_NODE);
d62a17ae 18132
8029b216
AK
18133 /* "bgp local-mac" hidden commands. */
18134 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
18135 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
18136
9acb67cb
DS
18137 /* "bgp suppress-fib-pending" global */
18138 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
18139
d62a17ae 18140 /* bgp route-map delay-timer commands. */
18141 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
18142 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18143
d70583f7
D
18144 /* global bgp update-delay command */
18145 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
18146 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
18147
05bd726c 18148 /* global bgp graceful-shutdown command */
18149 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
18150 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
18151
d62a17ae 18152 /* Dummy commands (Currently not supported) */
18153 install_element(BGP_NODE, &no_synchronization_cmd);
18154 install_element(BGP_NODE, &no_auto_summary_cmd);
18155
18156 /* "router bgp" commands. */
18157 install_element(CONFIG_NODE, &router_bgp_cmd);
18158
18159 /* "no router bgp" commands. */
18160 install_element(CONFIG_NODE, &no_router_bgp_cmd);
18161
18162 /* "bgp router-id" commands. */
18163 install_element(BGP_NODE, &bgp_router_id_cmd);
18164 install_element(BGP_NODE, &no_bgp_router_id_cmd);
18165
c208c586
S
18166 /* "bgp suppress-fib-pending" command */
18167 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
18168
d62a17ae 18169 /* "bgp cluster-id" commands. */
18170 install_element(BGP_NODE, &bgp_cluster_id_cmd);
18171 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
18172
c163f297
DS
18173 /* "bgp no-rib" commands. */
18174 install_element(CONFIG_NODE, &bgp_norib_cmd);
18175 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
18176
e46723a5
DS
18177 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
18178
d62a17ae 18179 /* "bgp confederation" commands. */
18180 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
18181 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
18182
18183 /* "bgp confederation peers" commands. */
18184 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
18185 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
18186
18187 /* bgp max-med command */
18188 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
18189 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
18190 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
18191 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
18192 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
18193
18194 /* bgp disable-ebgp-connected-nh-check */
18195 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
18196 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
18197
18198 /* bgp update-delay command */
18199 install_element(BGP_NODE, &bgp_update_delay_cmd);
18200 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
d62a17ae 18201
18202 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
555e09d4 18203 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
d62a17ae 18204
18205 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
18206 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
18207
18208 /* "maximum-paths" commands. */
18209 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
18210 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
18211 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
18212 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
18213 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
18214 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
18215 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
18216 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
18217 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
18218 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
18219 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18220 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
18221 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
18222 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18223 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
18224
39edabac
PG
18225 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
18226 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
18227 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
18228 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18229 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
d62a17ae 18230 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
18231 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
18232 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
18233 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
18234 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
18235
18236 /* "timers bgp" commands. */
18237 install_element(BGP_NODE, &bgp_timers_cmd);
18238 install_element(BGP_NODE, &no_bgp_timers_cmd);
18239
18240 /* route-map delay-timer commands - per instance for backwards compat.
18241 */
18242 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
18243 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
18244
18245 /* "bgp client-to-client reflection" commands */
18246 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
18247 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
18248
18249 /* "bgp always-compare-med" commands */
18250 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
18251 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
18252
9dac9fc8
DA
18253 /* bgp ebgp-requires-policy */
18254 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
18255 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
18256
2adac256
DA
18257 /* bgp suppress-duplicates */
18258 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
18259 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
18260
fb29348a
DA
18261 /* bgp reject-as-sets */
18262 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
18263 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
18264
d62a17ae 18265 /* "bgp deterministic-med" commands */
18266 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
18267 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
18268
055679e9 18269 /* "bgp graceful-restart" command */
36235319
QY
18270 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
18271 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
055679e9 18272
18273 /* "bgp graceful-restart-disable" command */
36235319
QY
18274 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
18275 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
055679e9 18276
18277 /* "neighbor a:b:c:d graceful-restart" command */
36235319
QY
18278 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
18279 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
055679e9 18280
18281 /* "neighbor a:b:c:d graceful-restart-disable" command */
18282 install_element(BGP_NODE,
18283 &bgp_neighbor_graceful_restart_disable_set_cmd);
18284 install_element(BGP_NODE,
18285 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
18286
18287 /* "neighbor a:b:c:d graceful-restart-helper" command */
18288 install_element(BGP_NODE,
18289 &bgp_neighbor_graceful_restart_helper_set_cmd);
18290 install_element(BGP_NODE,
18291 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
18292
d62a17ae 18293 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
18294 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
18295 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
18296 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
cfd47646 18297 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
f009ff26 18298 install_element(BGP_NODE,
18299 &no_bgp_graceful_restart_select_defer_time_cmd);
d62a17ae 18300 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
18301 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
18302
d6e3c15b 18303 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
18304 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
dc95985f 18305 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
18306 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
d6e3c15b 18307
7f323236
DW
18308 /* "bgp graceful-shutdown" commands */
18309 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
18310 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
18311
d62a17ae 18312 /* "bgp fast-external-failover" commands */
18313 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
18314 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
18315
d62a17ae 18316 /* "bgp bestpath compare-routerid" commands */
18317 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
18318 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
18319
18320 /* "bgp bestpath as-path ignore" commands */
18321 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
18322 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
18323
18324 /* "bgp bestpath as-path confed" commands */
18325 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
18326 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
18327
18328 /* "bgp bestpath as-path multipath-relax" commands */
18329 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
18330 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
18331
ee88563a
JM
18332 /* "bgp bestpath peer-type multipath-relax" commands */
18333 install_element(BGP_NODE, &bgp_bestpath_peer_type_multipath_relax_cmd);
18334 install_element(BGP_NODE,
18335 &no_bgp_bestpath_peer_type_multipath_relax_cmd);
18336
d62a17ae 18337 /* "bgp log-neighbor-changes" commands */
18338 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
18339 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
18340
18341 /* "bgp bestpath med" commands */
18342 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
18343 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
18344
f7e1c681 18345 /* "bgp bestpath bandwidth" commands */
18346 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
ad36d216 18347 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
f7e1c681 18348
d62a17ae 18349 /* "no bgp default ipv4-unicast" commands. */
18350 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
18351 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
18352
e84c59af
DA
18353 /* "no bgp default ipv6-unicast" commands. */
18354 install_element(BGP_NODE, &no_bgp_default_ipv6_unicast_cmd);
18355 install_element(BGP_NODE, &bgp_default_ipv6_unicast_cmd);
18356
d62a17ae 18357 /* "bgp network import-check" commands. */
18358 install_element(BGP_NODE, &bgp_network_import_check_cmd);
18359 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
18360 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
18361
18362 /* "bgp default local-preference" commands. */
18363 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
18364 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
18365
18366 /* bgp default show-hostname */
18367 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
18368 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
18369
aef999a2
DA
18370 /* bgp default show-nexthop-hostname */
18371 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
18372 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
18373
d62a17ae 18374 /* "bgp default subgroup-pkt-queue-max" commands. */
18375 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
18376 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
18377
18378 /* bgp ibgp-allow-policy-mods command */
18379 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
18380 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
18381
18382 /* "bgp listen limit" commands. */
18383 install_element(BGP_NODE, &bgp_listen_limit_cmd);
18384 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
18385
18386 /* "bgp listen range" commands. */
18387 install_element(BGP_NODE, &bgp_listen_range_cmd);
18388 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
18389
8175f54a 18390 /* "bgp default shutdown" command */
f26845f9 18391 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
9cf59432
DS
18392
18393 /* "bgp shutdown" commands */
18394 install_element(BGP_NODE, &bgp_shutdown_cmd);
8389c83a 18395 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
9cf59432 18396 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
1b6e7a88 18397 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
f26845f9 18398
d62a17ae 18399 /* "neighbor remote-as" commands. */
18400 install_element(BGP_NODE, &neighbor_remote_as_cmd);
18401 install_element(BGP_NODE, &neighbor_interface_config_cmd);
18402 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
18403 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
18404 install_element(BGP_NODE,
18405 &neighbor_interface_v6only_config_remote_as_cmd);
18406 install_element(BGP_NODE, &no_neighbor_cmd);
18407 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
18408
18409 /* "neighbor peer-group" commands. */
18410 install_element(BGP_NODE, &neighbor_peer_group_cmd);
18411 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
18412 install_element(BGP_NODE,
18413 &no_neighbor_interface_peer_group_remote_as_cmd);
18414
18415 /* "neighbor local-as" commands. */
18416 install_element(BGP_NODE, &neighbor_local_as_cmd);
18417 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
18418 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
18419 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
18420
18421 /* "neighbor solo" commands. */
18422 install_element(BGP_NODE, &neighbor_solo_cmd);
18423 install_element(BGP_NODE, &no_neighbor_solo_cmd);
18424
18425 /* "neighbor password" commands. */
18426 install_element(BGP_NODE, &neighbor_password_cmd);
18427 install_element(BGP_NODE, &no_neighbor_password_cmd);
18428
18429 /* "neighbor activate" commands. */
18430 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
18431 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
18432 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
18433 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
18434 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
18435 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
18436 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
18437 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
18438 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
7c40bf39 18439 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
18440 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
d62a17ae 18441 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
18442
18443 /* "no neighbor activate" commands. */
18444 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
18445 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
18446 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
18447 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
18448 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
18449 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
18450 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
18451 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
18452 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
7c40bf39 18453 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
18454 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
d62a17ae 18455 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
18456
18457 /* "neighbor peer-group" set commands. */
18458 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18459 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18460 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18461 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18462 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18463 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18464 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18465 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
7c40bf39 18466 install_element(BGP_FLOWSPECV4_NODE,
18467 &neighbor_set_peer_group_hidden_cmd);
18468 install_element(BGP_FLOWSPECV6_NODE,
18469 &neighbor_set_peer_group_hidden_cmd);
d62a17ae 18470
18471 /* "no neighbor peer-group unset" commands. */
18472 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18473 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18474 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18475 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18476 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18477 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18478 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18479 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
7c40bf39 18480 install_element(BGP_FLOWSPECV4_NODE,
18481 &no_neighbor_set_peer_group_hidden_cmd);
18482 install_element(BGP_FLOWSPECV6_NODE,
18483 &no_neighbor_set_peer_group_hidden_cmd);
d62a17ae 18484
18485 /* "neighbor softreconfiguration inbound" commands.*/
18486 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18487 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18488 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18489 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18490 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18491 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18492 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18493 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18494 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18495 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18496 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18497 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18498 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18499 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18500 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18501 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18502 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18503 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
7c40bf39 18504 install_element(BGP_FLOWSPECV4_NODE,
18505 &neighbor_soft_reconfiguration_cmd);
18506 install_element(BGP_FLOWSPECV4_NODE,
18507 &no_neighbor_soft_reconfiguration_cmd);
18508 install_element(BGP_FLOWSPECV6_NODE,
18509 &neighbor_soft_reconfiguration_cmd);
18510 install_element(BGP_FLOWSPECV6_NODE,
18511 &no_neighbor_soft_reconfiguration_cmd);
616c6ee8
PG
18512 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18513 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
d62a17ae 18514
18515 /* "neighbor attribute-unchanged" commands. */
18516 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18517 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18518 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18519 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18520 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18521 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18522 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18523 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18524 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18525 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18526 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18527 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18528 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18529 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18530 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18531 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18532 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18533 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18534
18535 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18536 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18537
b8ad84d2
PG
18538 install_element(BGP_FLOWSPECV4_NODE, &neighbor_attr_unchanged_cmd);
18539 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_attr_unchanged_cmd);
18540 install_element(BGP_FLOWSPECV6_NODE, &neighbor_attr_unchanged_cmd);
18541 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_attr_unchanged_cmd);
18542
d62a17ae 18543 /* "nexthop-local unchanged" commands */
18544 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18545 install_element(BGP_IPV6_NODE,
18546 &no_neighbor_nexthop_local_unchanged_cmd);
18547
18548 /* "neighbor next-hop-self" commands. */
18549 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18550 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18551 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18552 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18553 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18554 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18555 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18556 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18557 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18558 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18559 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18560 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18561 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18562 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18563 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18564 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18565 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18566 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
ace295a9
MK
18567 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18568 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
d62a17ae 18569
18570 /* "neighbor next-hop-self force" commands. */
18571 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18572 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
1bc4e531
DA
18573 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18574 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18575 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18576 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18577 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18578 install_element(BGP_IPV4_NODE,
18579 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18580 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18581 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18582 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18583 install_element(BGP_IPV4M_NODE,
18584 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18585 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18586 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18587 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18588 install_element(BGP_IPV4L_NODE,
18589 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18590 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18591 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18592 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18593 install_element(BGP_IPV6_NODE,
18594 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18595 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18596 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18597 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18598 install_element(BGP_IPV6M_NODE,
18599 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18600 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18601 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18602 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18603 install_element(BGP_IPV6L_NODE,
18604 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18605 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18606 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18607 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18608 install_element(BGP_VPNV4_NODE,
18609 &no_neighbor_nexthop_self_all_hidden_cmd);
d62a17ae 18610 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18611 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
2d94b6d1
DA
18612 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18613 install_element(BGP_VPNV6_NODE,
18614 &no_neighbor_nexthop_self_all_hidden_cmd);
be7e1fa3
MS
18615 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18616 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
d62a17ae 18617
18618 /* "neighbor as-override" commands. */
18619 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18620 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18621 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18622 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18623 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18624 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18625 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18626 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18627 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18628 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18629 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18630 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18631 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18632 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18633 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18634 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18635 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18636 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18637
18638 /* "neighbor remove-private-AS" commands. */
18639 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18640 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18641 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18642 install_element(BGP_NODE,
18643 &no_neighbor_remove_private_as_all_hidden_cmd);
18644 install_element(BGP_NODE,
18645 &neighbor_remove_private_as_replace_as_hidden_cmd);
18646 install_element(BGP_NODE,
18647 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18648 install_element(BGP_NODE,
18649 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18650 install_element(
18651 BGP_NODE,
18652 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18653 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18654 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18655 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18656 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18657 install_element(BGP_IPV4_NODE,
18658 &neighbor_remove_private_as_replace_as_cmd);
18659 install_element(BGP_IPV4_NODE,
18660 &no_neighbor_remove_private_as_replace_as_cmd);
18661 install_element(BGP_IPV4_NODE,
18662 &neighbor_remove_private_as_all_replace_as_cmd);
18663 install_element(BGP_IPV4_NODE,
18664 &no_neighbor_remove_private_as_all_replace_as_cmd);
18665 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18666 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18667 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18668 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18669 install_element(BGP_IPV4M_NODE,
18670 &neighbor_remove_private_as_replace_as_cmd);
18671 install_element(BGP_IPV4M_NODE,
18672 &no_neighbor_remove_private_as_replace_as_cmd);
18673 install_element(BGP_IPV4M_NODE,
18674 &neighbor_remove_private_as_all_replace_as_cmd);
18675 install_element(BGP_IPV4M_NODE,
18676 &no_neighbor_remove_private_as_all_replace_as_cmd);
18677 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18678 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18679 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18680 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18681 install_element(BGP_IPV4L_NODE,
18682 &neighbor_remove_private_as_replace_as_cmd);
18683 install_element(BGP_IPV4L_NODE,
18684 &no_neighbor_remove_private_as_replace_as_cmd);
18685 install_element(BGP_IPV4L_NODE,
18686 &neighbor_remove_private_as_all_replace_as_cmd);
18687 install_element(BGP_IPV4L_NODE,
18688 &no_neighbor_remove_private_as_all_replace_as_cmd);
18689 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18690 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18691 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18692 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18693 install_element(BGP_IPV6_NODE,
18694 &neighbor_remove_private_as_replace_as_cmd);
18695 install_element(BGP_IPV6_NODE,
18696 &no_neighbor_remove_private_as_replace_as_cmd);
18697 install_element(BGP_IPV6_NODE,
18698 &neighbor_remove_private_as_all_replace_as_cmd);
18699 install_element(BGP_IPV6_NODE,
18700 &no_neighbor_remove_private_as_all_replace_as_cmd);
18701 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18702 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18703 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18704 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18705 install_element(BGP_IPV6M_NODE,
18706 &neighbor_remove_private_as_replace_as_cmd);
18707 install_element(BGP_IPV6M_NODE,
18708 &no_neighbor_remove_private_as_replace_as_cmd);
18709 install_element(BGP_IPV6M_NODE,
18710 &neighbor_remove_private_as_all_replace_as_cmd);
18711 install_element(BGP_IPV6M_NODE,
18712 &no_neighbor_remove_private_as_all_replace_as_cmd);
18713 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18714 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18715 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18716 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18717 install_element(BGP_IPV6L_NODE,
18718 &neighbor_remove_private_as_replace_as_cmd);
18719 install_element(BGP_IPV6L_NODE,
18720 &no_neighbor_remove_private_as_replace_as_cmd);
18721 install_element(BGP_IPV6L_NODE,
18722 &neighbor_remove_private_as_all_replace_as_cmd);
18723 install_element(BGP_IPV6L_NODE,
18724 &no_neighbor_remove_private_as_all_replace_as_cmd);
18725 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18726 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18727 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18728 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18729 install_element(BGP_VPNV4_NODE,
18730 &neighbor_remove_private_as_replace_as_cmd);
18731 install_element(BGP_VPNV4_NODE,
18732 &no_neighbor_remove_private_as_replace_as_cmd);
18733 install_element(BGP_VPNV4_NODE,
18734 &neighbor_remove_private_as_all_replace_as_cmd);
18735 install_element(BGP_VPNV4_NODE,
18736 &no_neighbor_remove_private_as_all_replace_as_cmd);
18737 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18738 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18739 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18740 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18741 install_element(BGP_VPNV6_NODE,
18742 &neighbor_remove_private_as_replace_as_cmd);
18743 install_element(BGP_VPNV6_NODE,
18744 &no_neighbor_remove_private_as_replace_as_cmd);
18745 install_element(BGP_VPNV6_NODE,
18746 &neighbor_remove_private_as_all_replace_as_cmd);
18747 install_element(BGP_VPNV6_NODE,
18748 &no_neighbor_remove_private_as_all_replace_as_cmd);
18749
18750 /* "neighbor send-community" commands.*/
18751 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18752 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18753 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18754 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18755 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18756 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18757 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18758 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18759 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18760 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18761 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18762 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18763 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18764 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18765 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18766 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18767 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18768 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18769 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18770 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18771 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18772 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18773 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18774 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18775 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18776 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18777 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18778 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18779 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18780 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18781 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18782 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18783 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18784 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18785 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18786 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18787
18788 /* "neighbor route-reflector" commands.*/
18789 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18790 install_element(BGP_NODE,
18791 &no_neighbor_route_reflector_client_hidden_cmd);
18792 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18793 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18794 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18795 install_element(BGP_IPV4M_NODE,
18796 &no_neighbor_route_reflector_client_cmd);
18797 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18798 install_element(BGP_IPV4L_NODE,
18799 &no_neighbor_route_reflector_client_cmd);
18800 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18801 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18802 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18803 install_element(BGP_IPV6M_NODE,
18804 &no_neighbor_route_reflector_client_cmd);
18805 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18806 install_element(BGP_IPV6L_NODE,
18807 &no_neighbor_route_reflector_client_cmd);
18808 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18809 install_element(BGP_VPNV4_NODE,
18810 &no_neighbor_route_reflector_client_cmd);
18811 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18812 install_element(BGP_VPNV6_NODE,
18813 &no_neighbor_route_reflector_client_cmd);
7c40bf39 18814 install_element(BGP_FLOWSPECV4_NODE,
18815 &neighbor_route_reflector_client_cmd);
18816 install_element(BGP_FLOWSPECV4_NODE,
18817 &no_neighbor_route_reflector_client_cmd);
18818 install_element(BGP_FLOWSPECV6_NODE,
18819 &neighbor_route_reflector_client_cmd);
18820 install_element(BGP_FLOWSPECV6_NODE,
18821 &no_neighbor_route_reflector_client_cmd);
d62a17ae 18822 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18823 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18824
18825 /* "neighbor route-server" commands.*/
18826 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18827 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18828 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18829 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18830 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18831 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18832 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18833 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18834 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18835 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18836 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18837 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18838 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18839 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18840 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18841 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18842 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18843 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
a6627c99
LK
18844 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18845 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
7c40bf39 18846 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18847 install_element(BGP_FLOWSPECV4_NODE,
18848 &no_neighbor_route_server_client_cmd);
18849 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18850 install_element(BGP_FLOWSPECV6_NODE,
18851 &no_neighbor_route_server_client_cmd);
d62a17ae 18852
18853 /* "neighbor addpath-tx-all-paths" commands.*/
18854 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18855 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18856 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18857 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18858 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18859 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18860 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18861 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18862 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18863 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18864 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18865 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18866 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18867 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18868 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18869 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18870 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18871 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18872
18873 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18874 install_element(BGP_NODE,
18875 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18876 install_element(BGP_NODE,
18877 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18878 install_element(BGP_IPV4_NODE,
18879 &neighbor_addpath_tx_bestpath_per_as_cmd);
18880 install_element(BGP_IPV4_NODE,
18881 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18882 install_element(BGP_IPV4M_NODE,
18883 &neighbor_addpath_tx_bestpath_per_as_cmd);
18884 install_element(BGP_IPV4M_NODE,
18885 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18886 install_element(BGP_IPV4L_NODE,
18887 &neighbor_addpath_tx_bestpath_per_as_cmd);
18888 install_element(BGP_IPV4L_NODE,
18889 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18890 install_element(BGP_IPV6_NODE,
18891 &neighbor_addpath_tx_bestpath_per_as_cmd);
18892 install_element(BGP_IPV6_NODE,
18893 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18894 install_element(BGP_IPV6M_NODE,
18895 &neighbor_addpath_tx_bestpath_per_as_cmd);
18896 install_element(BGP_IPV6M_NODE,
18897 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18898 install_element(BGP_IPV6L_NODE,
18899 &neighbor_addpath_tx_bestpath_per_as_cmd);
18900 install_element(BGP_IPV6L_NODE,
18901 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18902 install_element(BGP_VPNV4_NODE,
18903 &neighbor_addpath_tx_bestpath_per_as_cmd);
18904 install_element(BGP_VPNV4_NODE,
18905 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18906 install_element(BGP_VPNV6_NODE,
18907 &neighbor_addpath_tx_bestpath_per_as_cmd);
18908 install_element(BGP_VPNV6_NODE,
18909 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18910
2b31007c
RZ
18911 /* "neighbor sender-as-path-loop-detection" commands. */
18912 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18913 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18914
d62a17ae 18915 /* "neighbor passive" commands. */
18916 install_element(BGP_NODE, &neighbor_passive_cmd);
18917 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18918
18919
18920 /* "neighbor shutdown" commands. */
18921 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18922 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18923 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18924 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
8336c896
DA
18925 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18926 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
d62a17ae 18927
18928 /* "neighbor capability extended-nexthop" commands.*/
18929 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18930 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18931
18932 /* "neighbor capability orf prefix-list" commands.*/
18933 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18934 install_element(BGP_NODE,
18935 &no_neighbor_capability_orf_prefix_hidden_cmd);
18936 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18937 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18938 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18939 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18940 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18941 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18942 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18943 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18944 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18945 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18946 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18947 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18948
18949 /* "neighbor capability dynamic" commands.*/
18950 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18951 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18952
18953 /* "neighbor dont-capability-negotiate" commands. */
18954 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18955 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18956
18957 /* "neighbor ebgp-multihop" commands. */
18958 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18959 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18960 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18961
18962 /* "neighbor disable-connected-check" commands. */
18963 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18964 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18965
47cbc09b
PM
18966 /* "neighbor enforce-first-as" commands. */
18967 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18968 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18969
d62a17ae 18970 /* "neighbor description" commands. */
18971 install_element(BGP_NODE, &neighbor_description_cmd);
18972 install_element(BGP_NODE, &no_neighbor_description_cmd);
a14810f4 18973 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
d62a17ae 18974
18975 /* "neighbor update-source" commands. "*/
18976 install_element(BGP_NODE, &neighbor_update_source_cmd);
18977 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18978
18979 /* "neighbor default-originate" commands. */
18980 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18981 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18982 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18983 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18984 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18985 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18986 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18987 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18988 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18989 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18990 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18991 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18992 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18993 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18994 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18995 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18996 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18997 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18998 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18999 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
19000 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
19001
19002 /* "neighbor port" commands. */
19003 install_element(BGP_NODE, &neighbor_port_cmd);
19004 install_element(BGP_NODE, &no_neighbor_port_cmd);
19005
19006 /* "neighbor weight" commands. */
19007 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
19008 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
19009
19010 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
19011 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
19012 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
19013 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
19014 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
19015 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
19016 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
19017 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
19018 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
19019 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
19020 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
19021 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
19022 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
19023 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
19024 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
19025 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
19026
19027 /* "neighbor override-capability" commands. */
19028 install_element(BGP_NODE, &neighbor_override_capability_cmd);
19029 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
19030
19031 /* "neighbor strict-capability-match" commands. */
19032 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
19033 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
19034
19035 /* "neighbor timers" commands. */
19036 install_element(BGP_NODE, &neighbor_timers_cmd);
19037 install_element(BGP_NODE, &no_neighbor_timers_cmd);
19038
19039 /* "neighbor timers connect" commands. */
19040 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
19041 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
19042
d43114f3
DS
19043 /* "neighbor timers delayopen" commands. */
19044 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
19045 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
19046
d62a17ae 19047 /* "neighbor advertisement-interval" commands. */
19048 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
19049 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
19050
19051 /* "neighbor interface" commands. */
19052 install_element(BGP_NODE, &neighbor_interface_cmd);
19053 install_element(BGP_NODE, &no_neighbor_interface_cmd);
19054
19055 /* "neighbor distribute" commands. */
19056 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
19057 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
19058 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
19059 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
19060 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
19061 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
19062 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
19063 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
19064 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
19065 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
19066 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
19067 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
19068 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
19069 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
19070 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
19071 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
19072 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
19073 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
19074
19075 /* "neighbor prefix-list" commands. */
19076 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
d62a17ae 19077 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19078 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19079 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19080 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19081 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19082 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19083 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19084 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
7c40bf39 19085 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
7c40bf39 19086 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
d62a17ae 19087
19088 /* "neighbor filter-list" commands. */
19089 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
19090 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
19091 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
19092 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
19093 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
19094 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
19095 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
19096 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
19097 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
19098 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
19099 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
19100 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
19101 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
19102 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
19103 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
19104 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
19105 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
19106 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
7c40bf39 19107 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
19108 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
19109 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
19110 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
d62a17ae 19111
19112 /* "neighbor route-map" commands. */
d62a17ae 19113 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
d62a17ae 19114 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
d62a17ae 19115 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
d62a17ae 19116 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
d62a17ae 19117 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
d62a17ae 19118 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
d62a17ae 19119 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
d62a17ae 19120 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
7c40bf39 19121 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
7c40bf39 19122 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
d37ba549 19123 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
d62a17ae 19124
19125 /* "neighbor unsuppress-map" commands. */
19126 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
19127 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
19128 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
19129 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
19130 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
19131 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
19132 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
19133 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
19134 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
19135 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
19136 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
19137 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
19138 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
19139 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
19140 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
19141 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
19142 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
19143 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
19144
7f7940e6
MK
19145 /* "neighbor advertise-map" commands. */
19146 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
7f7940e6 19147 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19148 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19149 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19150 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19151 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19152 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19153 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19154 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
7f7940e6 19155
fde246e8
DA
19156 /* neighbor maximum-prefix-out commands. */
19157 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
19158 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
19159 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
19160 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19161 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
19162 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19163 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
19164 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19165 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
19166 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19167 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
19168 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
19169 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
19170 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
19171 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
19172 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
19173 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
19174 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
19175
d62a17ae 19176 /* "neighbor maximum-prefix" commands. */
19177 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
19178 install_element(BGP_NODE,
19179 &neighbor_maximum_prefix_threshold_hidden_cmd);
19180 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
19181 install_element(BGP_NODE,
19182 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
19183 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
19184 install_element(BGP_NODE,
19185 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
19186 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
19187 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
19188 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19189 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19190 install_element(BGP_IPV4_NODE,
19191 &neighbor_maximum_prefix_threshold_warning_cmd);
19192 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19193 install_element(BGP_IPV4_NODE,
19194 &neighbor_maximum_prefix_threshold_restart_cmd);
19195 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
19196 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
19197 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19198 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
19199 install_element(BGP_IPV4M_NODE,
19200 &neighbor_maximum_prefix_threshold_warning_cmd);
19201 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
19202 install_element(BGP_IPV4M_NODE,
19203 &neighbor_maximum_prefix_threshold_restart_cmd);
19204 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
19205 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
19206 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19207 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
19208 install_element(BGP_IPV4L_NODE,
19209 &neighbor_maximum_prefix_threshold_warning_cmd);
19210 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
19211 install_element(BGP_IPV4L_NODE,
19212 &neighbor_maximum_prefix_threshold_restart_cmd);
19213 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
19214 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
19215 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19216 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19217 install_element(BGP_IPV6_NODE,
19218 &neighbor_maximum_prefix_threshold_warning_cmd);
19219 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19220 install_element(BGP_IPV6_NODE,
19221 &neighbor_maximum_prefix_threshold_restart_cmd);
19222 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
19223 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
19224 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
19225 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
19226 install_element(BGP_IPV6M_NODE,
19227 &neighbor_maximum_prefix_threshold_warning_cmd);
19228 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
19229 install_element(BGP_IPV6M_NODE,
19230 &neighbor_maximum_prefix_threshold_restart_cmd);
19231 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
19232 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
19233 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
19234 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
19235 install_element(BGP_IPV6L_NODE,
19236 &neighbor_maximum_prefix_threshold_warning_cmd);
19237 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
19238 install_element(BGP_IPV6L_NODE,
19239 &neighbor_maximum_prefix_threshold_restart_cmd);
19240 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
19241 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
19242 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
19243 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
19244 install_element(BGP_VPNV4_NODE,
19245 &neighbor_maximum_prefix_threshold_warning_cmd);
19246 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
19247 install_element(BGP_VPNV4_NODE,
19248 &neighbor_maximum_prefix_threshold_restart_cmd);
19249 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
19250 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
19251 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
19252 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
19253 install_element(BGP_VPNV6_NODE,
19254 &neighbor_maximum_prefix_threshold_warning_cmd);
19255 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
19256 install_element(BGP_VPNV6_NODE,
19257 &neighbor_maximum_prefix_threshold_restart_cmd);
19258 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
19259
19260 /* "neighbor allowas-in" */
19261 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
19262 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
19263 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
19264 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
19265 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
19266 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
19267 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
19268 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
19269 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
19270 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
19271 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
19272 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
19273 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
19274 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
19275 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
19276 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
19277 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
19278 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
19279 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
19280 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
19281
0221327c
DS
19282 /* "neighbor dampening" commands. */
19283 install_element(BGP_NODE, &neighbor_damp_cmd);
19284 install_element(BGP_NODE, &no_neighbor_damp_cmd);
19285 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
19286 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
19287 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
19288 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
19289 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
19290 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
19291 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
19292 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
19293 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
19294 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
19295 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
19296 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
19297 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
19298
d62a17ae 19299 /* address-family commands. */
19300 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
19301 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 19302#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 19303 install_element(BGP_NODE, &address_family_vpnv4_cmd);
19304 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 19305#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 19306
d62a17ae 19307 install_element(BGP_NODE, &address_family_evpn_cmd);
19308
19309 /* "exit-address-family" command. */
19310 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
19311 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
19312 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
19313 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
19314 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
19315 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
19316 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
19317 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
7c40bf39 19318 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
19319 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
d62a17ae 19320 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
19321
19322 /* "clear ip bgp commands" */
19323 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
19324
19325 /* clear ip bgp prefix */
19326 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
19327 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
19328 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
19329
19330 /* "show [ip] bgp summary" commands. */
19331 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
43d3f4fc 19332 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
d62a17ae 19333 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 19334 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 19335 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
19336 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 19337 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
19338
19339 /* "show [ip] bgp neighbors" commands. */
19340 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
19341
36235319 19342 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
2986cac2 19343
d62a17ae 19344 /* "show [ip] bgp peer-group" commands. */
19345 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
19346
19347 /* "show [ip] bgp paths" commands. */
19348 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
19349
19350 /* "show [ip] bgp community" commands. */
19351 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
19352
19353 /* "show ip bgp large-community" commands. */
19354 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
19355 /* "show [ip] bgp attribute-info" commands. */
19356 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
53089bec 19357 /* "show [ip] bgp route-leak" command */
19358 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
d62a17ae 19359
19360 /* "redistribute" commands. */
19361 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
19362 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
19363 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
19364 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
19365 install_element(BGP_NODE,
19366 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
19367 install_element(BGP_NODE,
19368 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
19369 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
19370 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
19371 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
19372 install_element(BGP_NODE,
19373 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
19374 install_element(BGP_NODE,
19375 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
19376 install_element(BGP_NODE,
19377 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
19378 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
19379 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
19380 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
19381 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
19382 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
19383 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
19384 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
19385 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
19386 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
19387 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
19388 install_element(BGP_IPV4_NODE,
19389 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
19390 install_element(BGP_IPV4_NODE,
19391 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
19392 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
19393 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
19394 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
19395 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
19396 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
19397 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
19398
b9c7bc5a
PZ
19399 /* import|export vpn [route-map WORD] */
19400 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
19401 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 19402
12a844a5
DS
19403 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
19404 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
19405
d62a17ae 19406 /* ttl_security commands */
19407 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
19408 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
19409
19410 /* "show [ip] bgp memory" commands. */
19411 install_element(VIEW_NODE, &show_bgp_memory_cmd);
19412
acf71666
MK
19413 /* "show bgp martian next-hop" */
19414 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
19415
48ecf8f5
DS
19416 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
19417
d62a17ae 19418 /* "show [ip] bgp views" commands. */
19419 install_element(VIEW_NODE, &show_bgp_views_cmd);
19420
19421 /* "show [ip] bgp vrfs" commands. */
19422 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
19423
19424 /* Community-list. */
19425 community_list_vty();
ddb5b488 19426
ed0e57e3
DA
19427 community_alias_vty();
19428
ddb5b488 19429 /* vpn-policy commands */
b9c7bc5a
PZ
19430 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
19431 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
19432 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
19433 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
19434 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
19435 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
19436 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
19437 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
19438 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
19439 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
bb4f6190
DS
19440 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
19441 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
b9c7bc5a 19442
301ad80a
PG
19443 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
19444 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
19445
b9c7bc5a
PZ
19446 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
19447 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
19448 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
19449 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
b9c7bc5a
PZ
19450 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
19451 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
19452 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
19453 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
bb4f6190
DS
19454 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
19455 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
4ab46701
AR
19456
19457 /* tcp-mss command */
19458 install_element(BGP_NODE, &neighbor_tcp_mss_cmd);
19459 install_element(BGP_NODE, &no_neighbor_tcp_mss_cmd);
bfaab44d
HS
19460
19461 /* srv6 commands */
19462 install_element(BGP_NODE, &bgp_segment_routing_srv6_cmd);
718e3744 19463}
6b0655a2 19464
718e3744 19465#include "memory.h"
19466#include "bgp_regex.h"
19467#include "bgp_clist.h"
19468#include "bgp_ecommunity.h"
19469
19470/* VTY functions. */
19471
19472/* Direction value to string conversion. */
d62a17ae 19473static const char *community_direct_str(int direct)
19474{
19475 switch (direct) {
19476 case COMMUNITY_DENY:
19477 return "deny";
19478 case COMMUNITY_PERMIT:
19479 return "permit";
19480 default:
19481 return "unknown";
19482 }
718e3744 19483}
19484
19485/* Display error string. */
d62a17ae 19486static void community_list_perror(struct vty *vty, int ret)
19487{
19488 switch (ret) {
19489 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19490 vty_out(vty, "%% Can't find community-list\n");
19491 break;
19492 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19493 vty_out(vty, "%% Malformed community-list value\n");
19494 break;
19495 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19496 vty_out(vty,
19497 "%% Community name conflict, previously defined as standard community\n");
19498 break;
19499 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19500 vty_out(vty,
19501 "%% Community name conflict, previously defined as expanded community\n");
19502 break;
19503 }
718e3744 19504}
19505
5bf15956
DW
19506/* "community-list" keyword help string. */
19507#define COMMUNITY_LIST_STR "Add a community list entry\n"
19508
7336e101
SP
19509/*community-list standard */
19510DEFUN (community_list_standard,
19511 bgp_community_list_standard_cmd,
a08032fe 19512 "bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 19513 BGP_STR
718e3744 19514 COMMUNITY_LIST_STR
19515 "Community list number (standard)\n"
5bf15956 19516 "Add an standard community-list entry\n"
718e3744 19517 "Community list name\n"
2f8cc0e5
DA
19518 "Sequence number of an entry\n"
19519 "Sequence number\n"
718e3744 19520 "Specify community to reject\n"
19521 "Specify community to accept\n"
19522 COMMUNITY_VAL_STR)
19523{
d62a17ae 19524 char *cl_name_or_number = NULL;
2f8cc0e5 19525 char *seq = NULL;
d62a17ae 19526 int direct = 0;
19527 int style = COMMUNITY_LIST_STANDARD;
d62a17ae 19528 int idx = 0;
7336e101 19529
a08032fe 19530 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19531 if (idx)
19532 seq = argv[idx]->arg;
19533
19534 idx = 0;
d62a17ae 19535 argv_find(argv, argc, "(1-99)", &idx);
19536 argv_find(argv, argc, "WORD", &idx);
19537 cl_name_or_number = argv[idx]->arg;
19538 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19539 : COMMUNITY_DENY;
19540 argv_find(argv, argc, "AA:NN", &idx);
19541 char *str = argv_concat(argv, argc, idx);
42f914d4 19542
2f8cc0e5
DA
19543 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19544 direct, style);
42f914d4 19545
d62a17ae 19546 XFREE(MTYPE_TMP, str);
42f914d4 19547
d62a17ae 19548 if (ret < 0) {
19549 /* Display error string. */
19550 community_list_perror(vty, ret);
19551 return CMD_WARNING_CONFIG_FAILED;
19552 }
42f914d4 19553
d62a17ae 19554 return CMD_SUCCESS;
718e3744 19555}
19556
7336e101
SP
19557DEFUN (no_community_list_standard_all,
19558 no_bgp_community_list_standard_all_cmd,
a08032fe 19559 "no bgp community-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19560 NO_STR
19561 BGP_STR
19562 COMMUNITY_LIST_STR
19563 "Community list number (standard)\n"
19564 "Add an standard community-list entry\n"
19565 "Community list name\n"
2f8cc0e5
DA
19566 "Sequence number of an entry\n"
19567 "Sequence number\n"
7336e101
SP
19568 "Specify community to reject\n"
19569 "Specify community to accept\n"
19570 COMMUNITY_VAL_STR)
718e3744 19571{
d62a17ae 19572 char *cl_name_or_number = NULL;
174b5cb9 19573 char *str = NULL;
d62a17ae 19574 int direct = 0;
19575 int style = COMMUNITY_LIST_STANDARD;
2f8cc0e5 19576 char *seq = NULL;
d62a17ae 19577 int idx = 0;
7336e101 19578
a08032fe 19579 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19580 if (idx)
19581 seq = argv[idx]->arg;
19582
19583 idx = 0;
174b5cb9
DA
19584 argv_find(argv, argc, "permit", &idx);
19585 argv_find(argv, argc, "deny", &idx);
19586
19587 if (idx) {
19588 direct = argv_find(argv, argc, "permit", &idx)
19589 ? COMMUNITY_PERMIT
19590 : COMMUNITY_DENY;
19591
19592 idx = 0;
19593 argv_find(argv, argc, "AA:NN", &idx);
19594 str = argv_concat(argv, argc, idx);
19595 }
19596
19597 idx = 0;
d62a17ae 19598 argv_find(argv, argc, "(1-99)", &idx);
19599 argv_find(argv, argc, "WORD", &idx);
19600 cl_name_or_number = argv[idx]->arg;
42f914d4 19601
2f8cc0e5 19602 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19603 direct, style);
42f914d4 19604
d62a17ae 19605 XFREE(MTYPE_TMP, str);
daf9ddbb 19606
d62a17ae 19607 if (ret < 0) {
19608 community_list_perror(vty, ret);
19609 return CMD_WARNING_CONFIG_FAILED;
19610 }
42f914d4 19611
d62a17ae 19612 return CMD_SUCCESS;
718e3744 19613}
7336e101 19614
174b5cb9
DA
19615ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19616 "no bgp community-list <(1-99)|standard WORD>",
19617 NO_STR BGP_STR COMMUNITY_LIST_STR
19618 "Community list number (standard)\n"
19619 "Add an standard community-list entry\n"
19620 "Community list name\n")
19621
7336e101
SP
19622/*community-list expanded */
19623DEFUN (community_list_expanded_all,
19624 bgp_community_list_expanded_all_cmd,
a08032fe 19625 "bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19626 BGP_STR
19627 COMMUNITY_LIST_STR
718e3744 19628 "Community list number (expanded)\n"
5bf15956 19629 "Add an expanded community-list entry\n"
718e3744 19630 "Community list name\n"
2f8cc0e5
DA
19631 "Sequence number of an entry\n"
19632 "Sequence number\n"
718e3744 19633 "Specify community to reject\n"
19634 "Specify community to accept\n"
19635 COMMUNITY_VAL_STR)
19636{
d62a17ae 19637 char *cl_name_or_number = NULL;
2f8cc0e5 19638 char *seq = NULL;
d62a17ae 19639 int direct = 0;
19640 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19641 int idx = 0;
7b9a4750 19642
a08032fe 19643 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19644 if (idx)
19645 seq = argv[idx]->arg;
19646
19647 idx = 0;
19648
d62a17ae 19649 argv_find(argv, argc, "(100-500)", &idx);
19650 argv_find(argv, argc, "WORD", &idx);
19651 cl_name_or_number = argv[idx]->arg;
19652 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19653 : COMMUNITY_DENY;
19654 argv_find(argv, argc, "AA:NN", &idx);
19655 char *str = argv_concat(argv, argc, idx);
42f914d4 19656
2f8cc0e5
DA
19657 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19658 direct, style);
42f914d4 19659
d62a17ae 19660 XFREE(MTYPE_TMP, str);
42f914d4 19661
d62a17ae 19662 if (ret < 0) {
19663 /* Display error string. */
19664 community_list_perror(vty, ret);
19665 return CMD_WARNING_CONFIG_FAILED;
19666 }
42f914d4 19667
d62a17ae 19668 return CMD_SUCCESS;
718e3744 19669}
19670
7336e101
SP
19671DEFUN (no_community_list_expanded_all,
19672 no_bgp_community_list_expanded_all_cmd,
a08032fe 19673 "no bgp community-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
19674 NO_STR
19675 BGP_STR
19676 COMMUNITY_LIST_STR
19677 "Community list number (expanded)\n"
19678 "Add an expanded community-list entry\n"
19679 "Community list name\n"
2f8cc0e5
DA
19680 "Sequence number of an entry\n"
19681 "Sequence number\n"
7336e101
SP
19682 "Specify community to reject\n"
19683 "Specify community to accept\n"
19684 COMMUNITY_VAL_STR)
718e3744 19685{
d62a17ae 19686 char *cl_name_or_number = NULL;
2f8cc0e5 19687 char *seq = NULL;
174b5cb9 19688 char *str = NULL;
d62a17ae 19689 int direct = 0;
19690 int style = COMMUNITY_LIST_EXPANDED;
d62a17ae 19691 int idx = 0;
174b5cb9 19692
a08032fe 19693 argv_find(argv, argc, "(0-4294967295)", &idx);
2f8cc0e5
DA
19694 if (idx)
19695 seq = argv[idx]->arg;
19696
19697 idx = 0;
174b5cb9
DA
19698 argv_find(argv, argc, "permit", &idx);
19699 argv_find(argv, argc, "deny", &idx);
19700
19701 if (idx) {
19702 direct = argv_find(argv, argc, "permit", &idx)
19703 ? COMMUNITY_PERMIT
19704 : COMMUNITY_DENY;
19705
19706 idx = 0;
19707 argv_find(argv, argc, "AA:NN", &idx);
19708 str = argv_concat(argv, argc, idx);
7336e101 19709 }
174b5cb9
DA
19710
19711 idx = 0;
d62a17ae 19712 argv_find(argv, argc, "(100-500)", &idx);
19713 argv_find(argv, argc, "WORD", &idx);
19714 cl_name_or_number = argv[idx]->arg;
42f914d4 19715
2f8cc0e5 19716 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
7298a8e1 19717 direct, style);
42f914d4 19718
d62a17ae 19719 XFREE(MTYPE_TMP, str);
daf9ddbb 19720
d62a17ae 19721 if (ret < 0) {
19722 community_list_perror(vty, ret);
19723 return CMD_WARNING_CONFIG_FAILED;
19724 }
42f914d4 19725
d62a17ae 19726 return CMD_SUCCESS;
718e3744 19727}
19728
36d4bb44
EB
19729ALIAS(no_community_list_expanded_all,
19730 no_bgp_community_list_expanded_all_list_cmd,
174b5cb9 19731 "no bgp community-list <(100-500)|expanded WORD>",
36d4bb44 19732 NO_STR BGP_STR COMMUNITY_LIST_STR
174b5cb9
DA
19733 "Community list number (expanded)\n"
19734 "Add an expanded community-list entry\n"
19735 "Community list name\n")
19736
8d9b8ed9
PM
19737/* Return configuration string of community-list entry. */
19738static const char *community_list_config_str(struct community_entry *entry)
19739{
19740 const char *str;
19741
19742 if (entry->any)
19743 str = "";
19744 else {
19745 if (entry->style == COMMUNITY_LIST_STANDARD)
19746 str = community_str(entry->u.com, false);
19747 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19748 str = lcommunity_str(entry->u.lcom, false);
19749 else
19750 str = entry->config;
19751 }
19752 return str;
19753}
19754
d62a17ae 19755static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 19756{
d62a17ae 19757 struct community_entry *entry;
718e3744 19758
d62a17ae 19759 for (entry = list->head; entry; entry = entry->next) {
19760 if (entry == list->head) {
19761 if (all_digit(list->name))
19762 vty_out(vty, "Community %s list %s\n",
19763 entry->style == COMMUNITY_LIST_STANDARD
19764 ? "standard"
19765 : "(expanded) access",
19766 list->name);
19767 else
19768 vty_out(vty, "Named Community %s list %s\n",
19769 entry->style == COMMUNITY_LIST_STANDARD
19770 ? "standard"
19771 : "expanded",
19772 list->name);
19773 }
19774 if (entry->any)
19775 vty_out(vty, " %s\n",
19776 community_direct_str(entry->direct));
19777 else
19778 vty_out(vty, " %s %s\n",
19779 community_direct_str(entry->direct),
8d9b8ed9 19780 community_list_config_str(entry));
d62a17ae 19781 }
718e3744 19782}
19783
7336e101
SP
19784DEFUN (show_community_list,
19785 show_bgp_community_list_cmd,
19786 "show bgp community-list",
718e3744 19787 SHOW_STR
7336e101 19788 BGP_STR
718e3744 19789 "List community-list\n")
19790{
d62a17ae 19791 struct community_list *list;
19792 struct community_list_master *cm;
718e3744 19793
d62a17ae 19794 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19795 if (!cm)
19796 return CMD_SUCCESS;
718e3744 19797
d62a17ae 19798 for (list = cm->num.head; list; list = list->next)
19799 community_list_show(vty, list);
718e3744 19800
d62a17ae 19801 for (list = cm->str.head; list; list = list->next)
19802 community_list_show(vty, list);
718e3744 19803
d62a17ae 19804 return CMD_SUCCESS;
718e3744 19805}
19806
7336e101
SP
19807DEFUN (show_community_list_arg,
19808 show_bgp_community_list_arg_cmd,
960b69b9 19809 "show bgp community-list <(1-500)|WORD> detail",
7336e101
SP
19810 SHOW_STR
19811 BGP_STR
718e3744 19812 "List community-list\n"
19813 "Community-list number\n"
960b69b9 19814 "Community-list name\n"
19815 "Detailed information on community-list\n")
718e3744 19816{
d62a17ae 19817 int idx_comm_list = 3;
19818 struct community_list *list;
718e3744 19819
e237b0d2 19820 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 19821 COMMUNITY_LIST_MASTER);
19822 if (!list) {
19823 vty_out(vty, "%% Can't find community-list\n");
19824 return CMD_WARNING;
19825 }
718e3744 19826
d62a17ae 19827 community_list_show(vty, list);
718e3744 19828
d62a17ae 19829 return CMD_SUCCESS;
718e3744 19830}
6b0655a2 19831
57d187bc
JS
19832/*
19833 * Large Community code.
19834 */
d62a17ae 19835static int lcommunity_list_set_vty(struct vty *vty, int argc,
19836 struct cmd_token **argv, int style,
19837 int reject_all_digit_name)
19838{
19839 int ret;
19840 int direct;
19841 char *str;
19842 int idx = 0;
19843 char *cl_name;
2f8cc0e5
DA
19844 char *seq = NULL;
19845
a08032fe 19846 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19847 seq = argv[idx]->arg;
d62a17ae 19848
2f8cc0e5 19849 idx = 0;
d62a17ae 19850 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19851 : COMMUNITY_DENY;
19852
19853 /* All digit name check. */
19854 idx = 0;
19855 argv_find(argv, argc, "WORD", &idx);
19856 argv_find(argv, argc, "(1-99)", &idx);
19857 argv_find(argv, argc, "(100-500)", &idx);
19858 cl_name = argv[idx]->arg;
19859 if (reject_all_digit_name && all_digit(cl_name)) {
19860 vty_out(vty, "%% Community name cannot have all digits\n");
19861 return CMD_WARNING_CONFIG_FAILED;
19862 }
19863
19864 idx = 0;
19865 argv_find(argv, argc, "AA:BB:CC", &idx);
19866 argv_find(argv, argc, "LINE", &idx);
19867 /* Concat community string argument. */
19868 if (idx)
19869 str = argv_concat(argv, argc, idx);
19870 else
19871 str = NULL;
19872
2f8cc0e5 19873 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
d62a17ae 19874
19875 /* Free temporary community list string allocated by
19876 argv_concat(). */
0a22ddfb 19877 XFREE(MTYPE_TMP, str);
d62a17ae 19878
19879 if (ret < 0) {
19880 community_list_perror(vty, ret);
19881 return CMD_WARNING_CONFIG_FAILED;
19882 }
19883 return CMD_SUCCESS;
19884}
19885
19886static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19887 struct cmd_token **argv, int style)
19888{
19889 int ret;
19890 int direct = 0;
19891 char *str = NULL;
19892 int idx = 0;
2f8cc0e5 19893 char *seq = NULL;
d62a17ae 19894
a08032fe 19895 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5 19896 seq = argv[idx]->arg;
d62a17ae 19897
2f8cc0e5 19898 idx = 0;
d62a17ae 19899 argv_find(argv, argc, "permit", &idx);
19900 argv_find(argv, argc, "deny", &idx);
19901
19902 if (idx) {
19903 /* Check the list direct. */
19904 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19905 direct = COMMUNITY_PERMIT;
19906 else
19907 direct = COMMUNITY_DENY;
19908
19909 idx = 0;
19910 argv_find(argv, argc, "LINE", &idx);
19911 argv_find(argv, argc, "AA:AA:NN", &idx);
19912 /* Concat community string argument. */
19913 str = argv_concat(argv, argc, idx);
19914 }
19915
19916 idx = 0;
19917 argv_find(argv, argc, "(1-99)", &idx);
19918 argv_find(argv, argc, "(100-500)", &idx);
19919 argv_find(argv, argc, "WORD", &idx);
19920
19921 /* Unset community list. */
2f8cc0e5 19922 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
d62a17ae 19923 style);
19924
19925 /* Free temporary community list string allocated by
19926 argv_concat(). */
0a22ddfb 19927 XFREE(MTYPE_TMP, str);
d62a17ae 19928
19929 if (ret < 0) {
19930 community_list_perror(vty, ret);
19931 return CMD_WARNING_CONFIG_FAILED;
19932 }
19933
19934 return CMD_SUCCESS;
57d187bc
JS
19935}
19936
19937/* "large-community-list" keyword help string. */
19938#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19939#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19940
7336e101
SP
19941DEFUN (lcommunity_list_standard,
19942 bgp_lcommunity_list_standard_cmd,
a08032fe 19943 "bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19944 BGP_STR
19945 LCOMMUNITY_LIST_STR
19946 "Large Community list number (standard)\n"
2f8cc0e5
DA
19947 "Sequence number of an entry\n"
19948 "Sequence number\n"
7336e101
SP
19949 "Specify large community to reject\n"
19950 "Specify large community to accept\n"
19951 LCOMMUNITY_VAL_STR)
52951b63 19952{
d62a17ae 19953 return lcommunity_list_set_vty(vty, argc, argv,
19954 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
19955}
19956
7336e101
SP
19957DEFUN (lcommunity_list_expanded,
19958 bgp_lcommunity_list_expanded_cmd,
a08032fe 19959 "bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19960 BGP_STR
19961 LCOMMUNITY_LIST_STR
19962 "Large Community list number (expanded)\n"
2f8cc0e5
DA
19963 "Sequence number of an entry\n"
19964 "Sequence number\n"
7336e101
SP
19965 "Specify large community to reject\n"
19966 "Specify large community to accept\n"
19967 "An ordered list as a regular-expression\n")
57d187bc 19968{
d62a17ae 19969 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 19970 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
19971}
19972
7336e101
SP
19973DEFUN (lcommunity_list_name_standard,
19974 bgp_lcommunity_list_name_standard_cmd,
a08032fe 19975 "bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:BB:CC...",
7336e101
SP
19976 BGP_STR
19977 LCOMMUNITY_LIST_STR
19978 "Specify standard large-community-list\n"
19979 "Large Community list name\n"
2f8cc0e5
DA
19980 "Sequence number of an entry\n"
19981 "Sequence number\n"
7336e101
SP
19982 "Specify large community to reject\n"
19983 "Specify large community to accept\n"
19984 LCOMMUNITY_VAL_STR)
52951b63 19985{
d62a17ae 19986 return lcommunity_list_set_vty(vty, argc, argv,
19987 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
19988}
19989
7336e101
SP
19990DEFUN (lcommunity_list_name_expanded,
19991 bgp_lcommunity_list_name_expanded_cmd,
a08032fe 19992 "bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
19993 BGP_STR
19994 LCOMMUNITY_LIST_STR
19995 "Specify expanded large-community-list\n"
19996 "Large Community list name\n"
2f8cc0e5
DA
19997 "Sequence number of an entry\n"
19998 "Sequence number\n"
7336e101
SP
19999 "Specify large community to reject\n"
20000 "Specify large community to accept\n"
20001 "An ordered list as a regular-expression\n")
57d187bc 20002{
d62a17ae 20003 return lcommunity_list_set_vty(vty, argc, argv,
7336e101 20004 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
20005}
20006
4378f57c
DA
20007DEFUN (no_lcommunity_list_all,
20008 no_bgp_lcommunity_list_all_cmd,
7336e101
SP
20009 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
20010 NO_STR
20011 BGP_STR
20012 LCOMMUNITY_LIST_STR
20013 "Large Community list number (standard)\n"
20014 "Large Community list number (expanded)\n"
20015 "Large Community list name\n")
57d187bc 20016{
7336e101
SP
20017 return lcommunity_list_unset_vty(vty, argc, argv,
20018 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20019}
20020
4378f57c
DA
20021DEFUN (no_lcommunity_list_name_standard_all,
20022 no_bgp_lcommunity_list_name_standard_all_cmd,
20023 "no bgp large-community-list standard WORD",
20024 NO_STR
20025 BGP_STR
20026 LCOMMUNITY_LIST_STR
20027 "Specify standard large-community-list\n"
20028 "Large Community list name\n")
20029{
20030 return lcommunity_list_unset_vty(vty, argc, argv,
20031 LARGE_COMMUNITY_LIST_STANDARD);
20032}
20033
7336e101
SP
20034DEFUN (no_lcommunity_list_name_expanded_all,
20035 no_bgp_lcommunity_list_name_expanded_all_cmd,
20036 "no bgp large-community-list expanded WORD",
20037 NO_STR
20038 BGP_STR
20039 LCOMMUNITY_LIST_STR
20040 "Specify expanded large-community-list\n"
20041 "Large Community list name\n")
57d187bc 20042{
d62a17ae 20043 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20044 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20045}
20046
7336e101
SP
20047DEFUN (no_lcommunity_list_standard,
20048 no_bgp_lcommunity_list_standard_cmd,
a08032fe 20049 "no bgp large-community-list (1-99) [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20050 NO_STR
20051 BGP_STR
20052 LCOMMUNITY_LIST_STR
20053 "Large Community list number (standard)\n"
2f8cc0e5
DA
20054 "Sequence number of an entry\n"
20055 "Sequence number\n"
7336e101
SP
20056 "Specify large community to reject\n"
20057 "Specify large community to accept\n"
20058 LCOMMUNITY_VAL_STR)
57d187bc 20059{
d62a17ae 20060 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20061 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20062}
20063
7336e101
SP
20064DEFUN (no_lcommunity_list_expanded,
20065 no_bgp_lcommunity_list_expanded_cmd,
a08032fe 20066 "no bgp large-community-list (100-500) [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20067 NO_STR
20068 BGP_STR
20069 LCOMMUNITY_LIST_STR
20070 "Large Community list number (expanded)\n"
2f8cc0e5
DA
20071 "Sequence number of an entry\n"
20072 "Sequence number\n"
7336e101
SP
20073 "Specify large community to reject\n"
20074 "Specify large community to accept\n"
20075 "An ordered list as a regular-expression\n")
57d187bc 20076{
d62a17ae 20077 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20078 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20079}
20080
7336e101
SP
20081DEFUN (no_lcommunity_list_name_standard,
20082 no_bgp_lcommunity_list_name_standard_cmd,
a08032fe 20083 "no bgp large-community-list standard WORD [seq (0-4294967295)] <deny|permit> AA:AA:NN...",
7336e101
SP
20084 NO_STR
20085 BGP_STR
20086 LCOMMUNITY_LIST_STR
20087 "Specify standard large-community-list\n"
20088 "Large Community list name\n"
2f8cc0e5
DA
20089 "Sequence number of an entry\n"
20090 "Sequence number\n"
7336e101
SP
20091 "Specify large community to reject\n"
20092 "Specify large community to accept\n"
20093 LCOMMUNITY_VAL_STR)
57d187bc 20094{
d62a17ae 20095 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20096 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
20097}
20098
7336e101
SP
20099DEFUN (no_lcommunity_list_name_expanded,
20100 no_bgp_lcommunity_list_name_expanded_cmd,
a08032fe 20101 "no bgp large-community-list expanded WORD [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20102 NO_STR
20103 BGP_STR
20104 LCOMMUNITY_LIST_STR
20105 "Specify expanded large-community-list\n"
20106 "Large community list name\n"
2f8cc0e5
DA
20107 "Sequence number of an entry\n"
20108 "Sequence number\n"
7336e101
SP
20109 "Specify large community to reject\n"
20110 "Specify large community to accept\n"
20111 "An ordered list as a regular-expression\n")
57d187bc 20112{
d62a17ae 20113 return lcommunity_list_unset_vty(vty, argc, argv,
7336e101 20114 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
20115}
20116
d62a17ae 20117static void lcommunity_list_show(struct vty *vty, struct community_list *list)
20118{
20119 struct community_entry *entry;
20120
20121 for (entry = list->head; entry; entry = entry->next) {
20122 if (entry == list->head) {
20123 if (all_digit(list->name))
20124 vty_out(vty, "Large community %s list %s\n",
169b72c8 20125 entry->style ==
20126 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20127 ? "standard"
20128 : "(expanded) access",
20129 list->name);
20130 else
20131 vty_out(vty,
20132 "Named large community %s list %s\n",
169b72c8 20133 entry->style ==
20134 LARGE_COMMUNITY_LIST_STANDARD
d62a17ae 20135 ? "standard"
20136 : "expanded",
20137 list->name);
20138 }
20139 if (entry->any)
20140 vty_out(vty, " %s\n",
20141 community_direct_str(entry->direct));
20142 else
20143 vty_out(vty, " %s %s\n",
20144 community_direct_str(entry->direct),
8d9b8ed9 20145 community_list_config_str(entry));
d62a17ae 20146 }
57d187bc
JS
20147}
20148
7336e101
SP
20149DEFUN (show_lcommunity_list,
20150 show_bgp_lcommunity_list_cmd,
20151 "show bgp large-community-list",
57d187bc 20152 SHOW_STR
7336e101 20153 BGP_STR
57d187bc
JS
20154 "List large-community list\n")
20155{
d62a17ae 20156 struct community_list *list;
20157 struct community_list_master *cm;
57d187bc 20158
d62a17ae 20159 cm = community_list_master_lookup(bgp_clist,
20160 LARGE_COMMUNITY_LIST_MASTER);
20161 if (!cm)
20162 return CMD_SUCCESS;
57d187bc 20163
d62a17ae 20164 for (list = cm->num.head; list; list = list->next)
20165 lcommunity_list_show(vty, list);
57d187bc 20166
d62a17ae 20167 for (list = cm->str.head; list; list = list->next)
20168 lcommunity_list_show(vty, list);
57d187bc 20169
d62a17ae 20170 return CMD_SUCCESS;
57d187bc
JS
20171}
20172
7336e101
SP
20173DEFUN (show_lcommunity_list_arg,
20174 show_bgp_lcommunity_list_arg_cmd,
960b69b9 20175 "show bgp large-community-list <(1-500)|WORD> detail",
7336e101
SP
20176 SHOW_STR
20177 BGP_STR
57d187bc 20178 "List large-community list\n"
960b69b9 20179 "Large-community-list number\n"
20180 "Large-community-list name\n"
20181 "Detailed information on large-community-list\n")
57d187bc 20182{
d62a17ae 20183 struct community_list *list;
57d187bc 20184
e237b0d2 20185 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
d62a17ae 20186 LARGE_COMMUNITY_LIST_MASTER);
20187 if (!list) {
960b69b9 20188 vty_out(vty, "%% Can't find large-community-list\n");
d62a17ae 20189 return CMD_WARNING;
20190 }
57d187bc 20191
d62a17ae 20192 lcommunity_list_show(vty, list);
57d187bc 20193
d62a17ae 20194 return CMD_SUCCESS;
57d187bc
JS
20195}
20196
718e3744 20197/* "extcommunity-list" keyword help string. */
20198#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
20199#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
20200
7336e101
SP
20201DEFUN (extcommunity_list_standard,
20202 bgp_extcommunity_list_standard_cmd,
a08032fe 20203 "bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101 20204 BGP_STR
718e3744 20205 EXTCOMMUNITY_LIST_STR
20206 "Extended Community list number (standard)\n"
718e3744 20207 "Specify standard extcommunity-list\n"
5bf15956 20208 "Community list name\n"
2f8cc0e5
DA
20209 "Sequence number of an entry\n"
20210 "Sequence number\n"
718e3744 20211 "Specify community to reject\n"
20212 "Specify community to accept\n"
20213 EXTCOMMUNITY_VAL_STR)
20214{
d62a17ae 20215 int style = EXTCOMMUNITY_LIST_STANDARD;
20216 int direct = 0;
20217 char *cl_number_or_name = NULL;
2f8cc0e5 20218 char *seq = NULL;
42f914d4 20219
d62a17ae 20220 int idx = 0;
7b9a4750 20221
d62a17ae 20222 argv_find(argv, argc, "(1-99)", &idx);
20223 argv_find(argv, argc, "WORD", &idx);
20224 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20225
a08032fe 20226 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20227 seq = argv[idx]->arg;
20228
d62a17ae 20229 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20230 : COMMUNITY_DENY;
20231 argv_find(argv, argc, "AA:NN", &idx);
20232 char *str = argv_concat(argv, argc, idx);
42f914d4 20233
2f8cc0e5 20234 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20235 direct, style);
42f914d4 20236
d62a17ae 20237 XFREE(MTYPE_TMP, str);
42f914d4 20238
d62a17ae 20239 if (ret < 0) {
20240 community_list_perror(vty, ret);
20241 return CMD_WARNING_CONFIG_FAILED;
20242 }
42f914d4 20243
d62a17ae 20244 return CMD_SUCCESS;
718e3744 20245}
20246
7336e101
SP
20247DEFUN (extcommunity_list_name_expanded,
20248 bgp_extcommunity_list_name_expanded_cmd,
a08032fe 20249 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20250 BGP_STR
20251 EXTCOMMUNITY_LIST_STR
5bf15956 20252 "Extended Community list number (expanded)\n"
718e3744 20253 "Specify expanded extcommunity-list\n"
20254 "Extended Community list name\n"
2f8cc0e5
DA
20255 "Sequence number of an entry\n"
20256 "Sequence number\n"
718e3744 20257 "Specify community to reject\n"
20258 "Specify community to accept\n"
20259 "An ordered list as a regular-expression\n")
20260{
d62a17ae 20261 int style = EXTCOMMUNITY_LIST_EXPANDED;
20262 int direct = 0;
20263 char *cl_number_or_name = NULL;
2f8cc0e5 20264 char *seq = NULL;
d62a17ae 20265 int idx = 0;
7336e101 20266
d62a17ae 20267 argv_find(argv, argc, "(100-500)", &idx);
20268 argv_find(argv, argc, "WORD", &idx);
20269 cl_number_or_name = argv[idx]->arg;
2f8cc0e5 20270
a08032fe 20271 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20272 seq = argv[idx]->arg;
20273
d62a17ae 20274 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
20275 : COMMUNITY_DENY;
20276 argv_find(argv, argc, "LINE", &idx);
20277 char *str = argv_concat(argv, argc, idx);
42f914d4 20278
2f8cc0e5 20279 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
d62a17ae 20280 direct, style);
42f914d4 20281
d62a17ae 20282 XFREE(MTYPE_TMP, str);
42f914d4 20283
d62a17ae 20284 if (ret < 0) {
20285 community_list_perror(vty, ret);
20286 return CMD_WARNING_CONFIG_FAILED;
20287 }
42f914d4 20288
d62a17ae 20289 return CMD_SUCCESS;
718e3744 20290}
20291
7336e101
SP
20292DEFUN (no_extcommunity_list_standard_all,
20293 no_bgp_extcommunity_list_standard_all_cmd,
a08032fe 20294 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (0-4294967295)] <deny|permit> AA:NN...",
7336e101
SP
20295 NO_STR
20296 BGP_STR
20297 EXTCOMMUNITY_LIST_STR
813d4307 20298 "Extended Community list number (standard)\n"
718e3744 20299 "Specify standard extcommunity-list\n"
5bf15956 20300 "Community list name\n"
2f8cc0e5
DA
20301 "Sequence number of an entry\n"
20302 "Sequence number\n"
718e3744 20303 "Specify community to reject\n"
20304 "Specify community to accept\n"
20305 EXTCOMMUNITY_VAL_STR)
20306{
d62a17ae 20307 int style = EXTCOMMUNITY_LIST_STANDARD;
20308 int direct = 0;
20309 char *cl_number_or_name = NULL;
d4455c89 20310 char *str = NULL;
2f8cc0e5 20311 char *seq = NULL;
d62a17ae 20312 int idx = 0;
d4455c89 20313
a08032fe 20314 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20315 seq = argv[idx]->arg;
20316
20317 idx = 0;
d4455c89
DA
20318 argv_find(argv, argc, "permit", &idx);
20319 argv_find(argv, argc, "deny", &idx);
d4455c89
DA
20320 if (idx) {
20321 direct = argv_find(argv, argc, "permit", &idx)
20322 ? COMMUNITY_PERMIT
20323 : COMMUNITY_DENY;
20324
20325 idx = 0;
20326 argv_find(argv, argc, "AA:NN", &idx);
20327 str = argv_concat(argv, argc, idx);
20328 }
20329
20330 idx = 0;
d62a17ae 20331 argv_find(argv, argc, "(1-99)", &idx);
20332 argv_find(argv, argc, "WORD", &idx);
20333 cl_number_or_name = argv[idx]->arg;
42f914d4 20334
d62a17ae 20335 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20336 seq, direct, style);
42f914d4 20337
d62a17ae 20338 XFREE(MTYPE_TMP, str);
42f914d4 20339
d62a17ae 20340 if (ret < 0) {
20341 community_list_perror(vty, ret);
20342 return CMD_WARNING_CONFIG_FAILED;
20343 }
42f914d4 20344
d62a17ae 20345 return CMD_SUCCESS;
718e3744 20346}
20347
d4455c89
DA
20348ALIAS(no_extcommunity_list_standard_all,
20349 no_bgp_extcommunity_list_standard_all_list_cmd,
20350 "no bgp extcommunity-list <(1-99)|standard WORD>",
36d4bb44 20351 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20352 "Extended Community list number (standard)\n"
20353 "Specify standard extcommunity-list\n"
20354 "Community list name\n")
20355
7336e101
SP
20356DEFUN (no_extcommunity_list_expanded_all,
20357 no_bgp_extcommunity_list_expanded_all_cmd,
a08032fe 20358 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (0-4294967295)] <deny|permit> LINE...",
7336e101
SP
20359 NO_STR
20360 BGP_STR
20361 EXTCOMMUNITY_LIST_STR
718e3744 20362 "Extended Community list number (expanded)\n"
718e3744 20363 "Specify expanded extcommunity-list\n"
5bf15956 20364 "Extended Community list name\n"
2f8cc0e5
DA
20365 "Sequence number of an entry\n"
20366 "Sequence number\n"
718e3744 20367 "Specify community to reject\n"
20368 "Specify community to accept\n"
20369 "An ordered list as a regular-expression\n")
20370{
d62a17ae 20371 int style = EXTCOMMUNITY_LIST_EXPANDED;
20372 int direct = 0;
20373 char *cl_number_or_name = NULL;
d4455c89 20374 char *str = NULL;
2f8cc0e5 20375 char *seq = NULL;
d62a17ae 20376 int idx = 0;
d4455c89 20377
a08032fe 20378 if (argv_find(argv, argc, "(0-4294967295)", &idx))
2f8cc0e5
DA
20379 seq = argv[idx]->arg;
20380
20381 idx = 0;
d4455c89
DA
20382 argv_find(argv, argc, "permit", &idx);
20383 argv_find(argv, argc, "deny", &idx);
20384
20385 if (idx) {
20386 direct = argv_find(argv, argc, "permit", &idx)
20387 ? COMMUNITY_PERMIT
20388 : COMMUNITY_DENY;
20389
20390 idx = 0;
20391 argv_find(argv, argc, "LINE", &idx);
20392 str = argv_concat(argv, argc, idx);
20393 }
20394
20395 idx = 0;
d62a17ae 20396 argv_find(argv, argc, "(100-500)", &idx);
20397 argv_find(argv, argc, "WORD", &idx);
20398 cl_number_or_name = argv[idx]->arg;
42f914d4 20399
d62a17ae 20400 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
2f8cc0e5 20401 seq, direct, style);
42f914d4 20402
d62a17ae 20403 XFREE(MTYPE_TMP, str);
42f914d4 20404
d62a17ae 20405 if (ret < 0) {
20406 community_list_perror(vty, ret);
20407 return CMD_WARNING_CONFIG_FAILED;
20408 }
42f914d4 20409
d62a17ae 20410 return CMD_SUCCESS;
718e3744 20411}
20412
d4455c89
DA
20413ALIAS(no_extcommunity_list_expanded_all,
20414 no_bgp_extcommunity_list_expanded_all_list_cmd,
20415 "no bgp extcommunity-list <(100-500)|expanded WORD>",
36d4bb44 20416 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
d4455c89
DA
20417 "Extended Community list number (expanded)\n"
20418 "Specify expanded extcommunity-list\n"
20419 "Extended Community list name\n")
20420
d62a17ae 20421static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 20422{
d62a17ae 20423 struct community_entry *entry;
718e3744 20424
d62a17ae 20425 for (entry = list->head; entry; entry = entry->next) {
20426 if (entry == list->head) {
20427 if (all_digit(list->name))
20428 vty_out(vty, "Extended community %s list %s\n",
20429 entry->style == EXTCOMMUNITY_LIST_STANDARD
20430 ? "standard"
20431 : "(expanded) access",
20432 list->name);
20433 else
20434 vty_out(vty,
20435 "Named extended community %s list %s\n",
20436 entry->style == EXTCOMMUNITY_LIST_STANDARD
20437 ? "standard"
20438 : "expanded",
20439 list->name);
20440 }
20441 if (entry->any)
20442 vty_out(vty, " %s\n",
20443 community_direct_str(entry->direct));
20444 else
20445 vty_out(vty, " %s %s\n",
20446 community_direct_str(entry->direct),
8d9b8ed9 20447 community_list_config_str(entry));
d62a17ae 20448 }
718e3744 20449}
20450
7336e101
SP
20451DEFUN (show_extcommunity_list,
20452 show_bgp_extcommunity_list_cmd,
20453 "show bgp extcommunity-list",
718e3744 20454 SHOW_STR
7336e101 20455 BGP_STR
718e3744 20456 "List extended-community list\n")
20457{
d62a17ae 20458 struct community_list *list;
20459 struct community_list_master *cm;
718e3744 20460
d62a17ae 20461 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20462 if (!cm)
20463 return CMD_SUCCESS;
718e3744 20464
d62a17ae 20465 for (list = cm->num.head; list; list = list->next)
20466 extcommunity_list_show(vty, list);
718e3744 20467
d62a17ae 20468 for (list = cm->str.head; list; list = list->next)
20469 extcommunity_list_show(vty, list);
718e3744 20470
d62a17ae 20471 return CMD_SUCCESS;
718e3744 20472}
20473
7336e101
SP
20474DEFUN (show_extcommunity_list_arg,
20475 show_bgp_extcommunity_list_arg_cmd,
960b69b9 20476 "show bgp extcommunity-list <(1-500)|WORD> detail",
7336e101
SP
20477 SHOW_STR
20478 BGP_STR
718e3744 20479 "List extended-community list\n"
20480 "Extcommunity-list number\n"
960b69b9 20481 "Extcommunity-list name\n"
20482 "Detailed information on extcommunity-list\n")
718e3744 20483{
d62a17ae 20484 int idx_comm_list = 3;
20485 struct community_list *list;
718e3744 20486
e237b0d2 20487 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
d62a17ae 20488 EXTCOMMUNITY_LIST_MASTER);
20489 if (!list) {
20490 vty_out(vty, "%% Can't find extcommunity-list\n");
20491 return CMD_WARNING;
20492 }
718e3744 20493
d62a17ae 20494 extcommunity_list_show(vty, list);
718e3744 20495
d62a17ae 20496 return CMD_SUCCESS;
718e3744 20497}
6b0655a2 20498
718e3744 20499/* Display community-list and extcommunity-list configuration. */
d62a17ae 20500static int community_list_config_write(struct vty *vty)
20501{
20502 struct community_list *list;
20503 struct community_entry *entry;
20504 struct community_list_master *cm;
20505 int write = 0;
20506
20507 /* Community-list. */
20508 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20509
20510 for (list = cm->num.head; list; list = list->next)
20511 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20512 vty_out(vty,
20513 "bgp community-list %s seq %" PRId64 " %s %s\n",
20514 list->name, entry->seq,
d62a17ae 20515 community_direct_str(entry->direct),
20516 community_list_config_str(entry));
20517 write++;
20518 }
20519 for (list = cm->str.head; list; list = list->next)
20520 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20521 vty_out(vty,
20522 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
d62a17ae 20523 entry->style == COMMUNITY_LIST_STANDARD
20524 ? "standard"
20525 : "expanded",
2f8cc0e5
DA
20526 list->name, entry->seq,
20527 community_direct_str(entry->direct),
d62a17ae 20528 community_list_config_str(entry));
20529 write++;
20530 }
20531
20532 /* Extcommunity-list. */
20533 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20534
20535 for (list = cm->num.head; list; list = list->next)
20536 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5
DA
20537 vty_out(vty,
20538 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20539 list->name, entry->seq,
20540 community_direct_str(entry->direct),
d62a17ae 20541 community_list_config_str(entry));
20542 write++;
20543 }
20544 for (list = cm->str.head; list; list = list->next)
20545 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20546 vty_out(vty,
6cde4b45 20547 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
d62a17ae 20548 entry->style == EXTCOMMUNITY_LIST_STANDARD
20549 ? "standard"
20550 : "expanded",
2f8cc0e5
DA
20551 list->name, entry->seq,
20552 community_direct_str(entry->direct),
d62a17ae 20553 community_list_config_str(entry));
20554 write++;
20555 }
20556
20557
20558 /* lcommunity-list. */
20559 cm = community_list_master_lookup(bgp_clist,
20560 LARGE_COMMUNITY_LIST_MASTER);
20561
20562 for (list = cm->num.head; list; list = list->next)
20563 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20564 vty_out(vty,
6cde4b45 20565 "bgp large-community-list %s seq %" PRId64" %s %s\n",
2f8cc0e5
DA
20566 list->name, entry->seq,
20567 community_direct_str(entry->direct),
d62a17ae 20568 community_list_config_str(entry));
20569 write++;
20570 }
20571 for (list = cm->str.head; list; list = list->next)
20572 for (entry = list->head; entry; entry = entry->next) {
2f8cc0e5 20573 vty_out(vty,
6cde4b45 20574 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
2f8cc0e5 20575
d62a17ae 20576 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20577 ? "standard"
20578 : "expanded",
2f8cc0e5 20579 list->name, entry->seq, community_direct_str(entry->direct),
d62a17ae 20580 community_list_config_str(entry));
20581 write++;
20582 }
20583
20584 return write;
20585}
20586
612c2c15 20587static int community_list_config_write(struct vty *vty);
d62a17ae 20588static struct cmd_node community_list_node = {
f4b8291f 20589 .name = "community list",
62b346ee
DL
20590 .node = COMMUNITY_LIST_NODE,
20591 .prompt = "",
612c2c15 20592 .config_write = community_list_config_write,
718e3744 20593};
20594
d62a17ae 20595static void community_list_vty(void)
20596{
612c2c15 20597 install_node(&community_list_node);
d62a17ae 20598
20599 /* Community-list. */
7336e101
SP
20600 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20601 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20602 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
174b5cb9 20603 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
7336e101 20604 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
174b5cb9 20605 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
7336e101
SP
20606 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20607 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
d62a17ae 20608
20609 /* Extcommunity-list. */
7336e101
SP
20610 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20611 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20612 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
d4455c89
DA
20613 install_element(CONFIG_NODE,
20614 &no_bgp_extcommunity_list_standard_all_list_cmd);
7336e101 20615 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
d4455c89
DA
20616 install_element(CONFIG_NODE,
20617 &no_bgp_extcommunity_list_expanded_all_list_cmd);
7336e101
SP
20618 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20619 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
d62a17ae 20620
20621 /* Large Community List */
7336e101 20622 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
7336e101
SP
20623 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20624 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
7336e101 20625 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
4378f57c
DA
20626 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20627 install_element(CONFIG_NODE,
20628 &no_bgp_lcommunity_list_name_standard_all_cmd);
7336e101
SP
20629 install_element(CONFIG_NODE,
20630 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20631 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20632 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20633 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20634 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20635 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20636 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
5bf15956 20637}
ed0e57e3
DA
20638
20639static struct cmd_node community_alias_node = {
20640 .name = "community alias",
20641 .node = COMMUNITY_ALIAS_NODE,
20642 .prompt = "",
20643 .config_write = bgp_community_alias_write,
20644};
20645
20646void community_alias_vty(void)
20647{
20648 install_node(&community_alias_node);
20649
20650 /* Community-list. */
20651 install_element(CONFIG_NODE, &bgp_community_alias_cmd);
20652}