]> git.proxmox.com Git - mirror_frr.git/blame_incremental - bgpd/bgp_vty.c
Merge pull request #8082 from donaldsharp/nhrp_priv
[mirror_frr.git] / bgpd / bgp_vty.c
... / ...
CommitLineData
1/* BGP VTY interface.
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 */
20
21#include <zebra.h>
22
23#include "command.h"
24#include "lib/json.h"
25#include "lib_errors.h"
26#include "lib/zclient.h"
27#include "prefix.h"
28#include "plist.h"
29#include "buffer.h"
30#include "linklist.h"
31#include "stream.h"
32#include "thread.h"
33#include "log.h"
34#include "memory.h"
35#include "lib_vty.h"
36#include "hash.h"
37#include "queue.h"
38#include "filter.h"
39#include "frrstr.h"
40
41#include "bgpd/bgpd.h"
42#include "bgpd/bgp_attr_evpn.h"
43#include "bgpd/bgp_advertise.h"
44#include "bgpd/bgp_attr.h"
45#include "bgpd/bgp_aspath.h"
46#include "bgpd/bgp_community.h"
47#include "bgpd/bgp_ecommunity.h"
48#include "bgpd/bgp_lcommunity.h"
49#include "bgpd/bgp_damp.h"
50#include "bgpd/bgp_debug.h"
51#include "bgpd/bgp_errors.h"
52#include "bgpd/bgp_fsm.h"
53#include "bgpd/bgp_nexthop.h"
54#include "bgpd/bgp_open.h"
55#include "bgpd/bgp_regex.h"
56#include "bgpd/bgp_route.h"
57#include "bgpd/bgp_mplsvpn.h"
58#include "bgpd/bgp_zebra.h"
59#include "bgpd/bgp_table.h"
60#include "bgpd/bgp_vty.h"
61#include "bgpd/bgp_mpath.h"
62#include "bgpd/bgp_packet.h"
63#include "bgpd/bgp_updgrp.h"
64#include "bgpd/bgp_bfd.h"
65#include "bgpd/bgp_io.h"
66#include "bgpd/bgp_evpn.h"
67#include "bgpd/bgp_evpn_vty.h"
68#include "bgpd/bgp_evpn_mh.h"
69#include "bgpd/bgp_addpath.h"
70#include "bgpd/bgp_mac.h"
71#include "bgpd/bgp_flowspec.h"
72#ifdef ENABLE_BGP_VNC
73#include "bgpd/rfapi/bgp_rfapi_cfg.h"
74#endif
75
76#include "northbound.h"
77#include "northbound_cli.h"
78#include "bgpd/bgp_nb.h"
79
80
81FRR_CFG_DEFAULT_BOOL(BGP_IMPORT_CHECK,
82 {
83 .val_bool = false,
84 .match_profile = "traditional",
85 .match_version = "< 7.4",
86 },
87 { .val_bool = true },
88)
89FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
90 { .val_bool = true, .match_profile = "datacenter", },
91 { .val_bool = false },
92)
93FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
94 { .val_bool = true, .match_profile = "datacenter", },
95 { .val_bool = false },
96)
97FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
98 { .val_bool = true, .match_profile = "datacenter", },
99 { .val_bool = false },
100)
101FRR_CFG_DEFAULT_BOOL(BGP_DETERMINISTIC_MED,
102 { .val_bool = true, .match_profile = "datacenter", },
103 { .val_bool = false },
104)
105FRR_CFG_DEFAULT_ULONG(BGP_CONNECT_RETRY,
106 { .val_ulong = 10, .match_profile = "datacenter", },
107 { .val_ulong = 120 },
108)
109FRR_CFG_DEFAULT_ULONG(BGP_HOLDTIME,
110 { .val_ulong = 9, .match_profile = "datacenter", },
111 { .val_ulong = 180 },
112)
113FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
114 { .val_ulong = 3, .match_profile = "datacenter", },
115 { .val_ulong = 60 },
116)
117FRR_CFG_DEFAULT_BOOL(BGP_EBGP_REQUIRES_POLICY,
118 { .val_bool = false, .match_profile = "datacenter", },
119 { .val_bool = false, .match_version = "< 7.4", },
120 { .val_bool = true },
121)
122FRR_CFG_DEFAULT_BOOL(BGP_SUPPRESS_DUPLICATES,
123 { .val_bool = false, .match_version = "< 7.6", },
124 { .val_bool = true },
125)
126
127DEFINE_HOOK(bgp_inst_config_write,
128 (struct bgp *bgp, struct vty *vty),
129 (bgp, vty))
130DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp))
131
132#define GR_NO_OPER \
133 "The Graceful Restart No Operation was executed as cmd same as previous one."
134#define GR_INVALID \
135 "The Graceful Restart command used is not valid at this moment."
136static struct peer_group *listen_range_exists(struct bgp *bgp,
137 struct prefix *range, int exact);
138
139/* Show BGP peer's information. */
140enum show_type {
141 show_all,
142 show_peer,
143 show_ipv4_all,
144 show_ipv6_all,
145 show_ipv4_peer,
146 show_ipv6_peer
147};
148
149static struct peer_group *listen_range_exists(struct bgp *bgp,
150 struct prefix *range, int exact);
151
152static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
153 struct bgp *bgp,
154 bool use_json,
155 json_object *json);
156
157static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
158 enum show_type type,
159 const char *ip_str,
160 afi_t afi, bool use_json);
161
162static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
163 char *base_xpath, int xpath_len,
164 char *abs_xpath);
165
166static enum node_type bgp_node_type(afi_t afi, safi_t safi)
167{
168 switch (afi) {
169 case AFI_IP:
170 switch (safi) {
171 case SAFI_UNICAST:
172 return BGP_IPV4_NODE;
173 case SAFI_MULTICAST:
174 return BGP_IPV4M_NODE;
175 case SAFI_LABELED_UNICAST:
176 return BGP_IPV4L_NODE;
177 case SAFI_MPLS_VPN:
178 return BGP_VPNV4_NODE;
179 case SAFI_FLOWSPEC:
180 return BGP_FLOWSPECV4_NODE;
181 default:
182 /* not expected */
183 return BGP_IPV4_NODE;
184 }
185 break;
186 case AFI_IP6:
187 switch (safi) {
188 case SAFI_UNICAST:
189 return BGP_IPV6_NODE;
190 case SAFI_MULTICAST:
191 return BGP_IPV6M_NODE;
192 case SAFI_LABELED_UNICAST:
193 return BGP_IPV6L_NODE;
194 case SAFI_MPLS_VPN:
195 return BGP_VPNV6_NODE;
196 case SAFI_FLOWSPEC:
197 return BGP_FLOWSPECV6_NODE;
198 default:
199 /* not expected */
200 return BGP_IPV4_NODE;
201 }
202 break;
203 case AFI_L2VPN:
204 return BGP_EVPN_NODE;
205 case AFI_UNSPEC:
206 case AFI_MAX:
207 // We should never be here but to clarify the switch statement..
208 return BGP_IPV4_NODE;
209 }
210
211 // Impossible to happen
212 return BGP_IPV4_NODE;
213}
214
215static const char *get_afi_safi_vty_str(afi_t afi, safi_t safi)
216{
217 if (afi == AFI_IP) {
218 if (safi == SAFI_UNICAST)
219 return "IPv4 Unicast";
220 if (safi == SAFI_MULTICAST)
221 return "IPv4 Multicast";
222 if (safi == SAFI_LABELED_UNICAST)
223 return "IPv4 Labeled Unicast";
224 if (safi == SAFI_MPLS_VPN)
225 return "IPv4 VPN";
226 if (safi == SAFI_ENCAP)
227 return "IPv4 Encap";
228 if (safi == SAFI_FLOWSPEC)
229 return "IPv4 Flowspec";
230 } else if (afi == AFI_IP6) {
231 if (safi == SAFI_UNICAST)
232 return "IPv6 Unicast";
233 if (safi == SAFI_MULTICAST)
234 return "IPv6 Multicast";
235 if (safi == SAFI_LABELED_UNICAST)
236 return "IPv6 Labeled Unicast";
237 if (safi == SAFI_MPLS_VPN)
238 return "IPv6 VPN";
239 if (safi == SAFI_ENCAP)
240 return "IPv6 Encap";
241 if (safi == SAFI_FLOWSPEC)
242 return "IPv6 Flowspec";
243 } else if (afi == AFI_L2VPN) {
244 if (safi == SAFI_EVPN)
245 return "L2VPN EVPN";
246 }
247
248 return "Unknown";
249}
250
251/*
252 * Please note that we have intentionally camelCased
253 * the return strings here. So if you want
254 * to use this function, please ensure you
255 * are doing this within json output
256 */
257static const char *get_afi_safi_json_str(afi_t afi, safi_t safi)
258{
259 if (afi == AFI_IP) {
260 if (safi == SAFI_UNICAST)
261 return "ipv4Unicast";
262 if (safi == SAFI_MULTICAST)
263 return "ipv4Multicast";
264 if (safi == SAFI_LABELED_UNICAST)
265 return "ipv4LabeledUnicast";
266 if (safi == SAFI_MPLS_VPN)
267 return "ipv4Vpn";
268 if (safi == SAFI_ENCAP)
269 return "ipv4Encap";
270 if (safi == SAFI_FLOWSPEC)
271 return "ipv4Flowspec";
272 } else if (afi == AFI_IP6) {
273 if (safi == SAFI_UNICAST)
274 return "ipv6Unicast";
275 if (safi == SAFI_MULTICAST)
276 return "ipv6Multicast";
277 if (safi == SAFI_LABELED_UNICAST)
278 return "ipv6LabeledUnicast";
279 if (safi == SAFI_MPLS_VPN)
280 return "ipv6Vpn";
281 if (safi == SAFI_ENCAP)
282 return "ipv6Encap";
283 if (safi == SAFI_FLOWSPEC)
284 return "ipv6Flowspec";
285 } else if (afi == AFI_L2VPN) {
286 if (safi == SAFI_EVPN)
287 return "l2VpnEvpn";
288 }
289
290 return "Unknown";
291}
292
293/* return string maps to afi-safi specific container names
294 * defined in bgp yang file.
295 */
296const char *bgp_afi_safi_get_container_str(afi_t afi, safi_t safi)
297{
298 if (afi == AFI_IP) {
299 if (safi == SAFI_UNICAST)
300 return "ipv4-unicast";
301 if (safi == SAFI_MULTICAST)
302 return "ipv4-multicast";
303 if (safi == SAFI_LABELED_UNICAST)
304 return "ipv4-labeled-unicast";
305 if (safi == SAFI_MPLS_VPN)
306 return "l3vpn-ipv4-unicast";
307 if (safi == SAFI_FLOWSPEC)
308 return "ipv4-flowspec";
309 } else if (afi == AFI_IP6) {
310 if (safi == SAFI_UNICAST)
311 return "ipv6-unicast";
312 if (safi == SAFI_MULTICAST)
313 return "ipv6-multicast";
314 if (safi == SAFI_LABELED_UNICAST)
315 return "ipv6-labeled-unicast";
316 if (safi == SAFI_MPLS_VPN)
317 return "l3vpn-ipv6-unicast";
318 if (safi == SAFI_FLOWSPEC)
319 return "ipv6-flowspec";
320 } else if (afi == AFI_L2VPN) {
321 if (safi == SAFI_EVPN)
322 return "l2vpn-evpn";
323 }
324
325 return "Unknown";
326}
327
328/* Utility function to get address family from current node. */
329afi_t bgp_node_afi(struct vty *vty)
330{
331 afi_t afi;
332 switch (vty->node) {
333 case BGP_IPV6_NODE:
334 case BGP_IPV6M_NODE:
335 case BGP_IPV6L_NODE:
336 case BGP_VPNV6_NODE:
337 case BGP_FLOWSPECV6_NODE:
338 afi = AFI_IP6;
339 break;
340 case BGP_EVPN_NODE:
341 afi = AFI_L2VPN;
342 break;
343 default:
344 afi = AFI_IP;
345 break;
346 }
347 return afi;
348}
349
350/* Utility function to get subsequent address family from current
351 node. */
352safi_t bgp_node_safi(struct vty *vty)
353{
354 safi_t safi;
355 switch (vty->node) {
356 case BGP_VPNV4_NODE:
357 case BGP_VPNV6_NODE:
358 safi = SAFI_MPLS_VPN;
359 break;
360 case BGP_IPV4M_NODE:
361 case BGP_IPV6M_NODE:
362 safi = SAFI_MULTICAST;
363 break;
364 case BGP_EVPN_NODE:
365 safi = SAFI_EVPN;
366 break;
367 case BGP_IPV4L_NODE:
368 case BGP_IPV6L_NODE:
369 safi = SAFI_LABELED_UNICAST;
370 break;
371 case BGP_FLOWSPECV4_NODE:
372 case BGP_FLOWSPECV6_NODE:
373 safi = SAFI_FLOWSPEC;
374 break;
375 default:
376 safi = SAFI_UNICAST;
377 break;
378 }
379 return safi;
380}
381
382/**
383 * Converts an AFI in string form to afi_t
384 *
385 * @param afi string, one of
386 * - "ipv4"
387 * - "ipv6"
388 * - "l2vpn"
389 * @return the corresponding afi_t
390 */
391afi_t bgp_vty_afi_from_str(const char *afi_str)
392{
393 afi_t afi = AFI_MAX; /* unknown */
394 if (strmatch(afi_str, "ipv4"))
395 afi = AFI_IP;
396 else if (strmatch(afi_str, "ipv6"))
397 afi = AFI_IP6;
398 else if (strmatch(afi_str, "l2vpn"))
399 afi = AFI_L2VPN;
400 return afi;
401}
402
403int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
404 afi_t *afi)
405{
406 int ret = 0;
407 if (argv_find(argv, argc, "ipv4", index)) {
408 ret = 1;
409 if (afi)
410 *afi = AFI_IP;
411 } else if (argv_find(argv, argc, "ipv6", index)) {
412 ret = 1;
413 if (afi)
414 *afi = AFI_IP6;
415 } else if (argv_find(argv, argc, "l2vpn", index)) {
416 ret = 1;
417 if (afi)
418 *afi = AFI_L2VPN;
419 }
420 return ret;
421}
422
423/* supports <unicast|multicast|vpn|labeled-unicast> */
424safi_t bgp_vty_safi_from_str(const char *safi_str)
425{
426 safi_t safi = SAFI_MAX; /* unknown */
427 if (strmatch(safi_str, "multicast"))
428 safi = SAFI_MULTICAST;
429 else if (strmatch(safi_str, "unicast"))
430 safi = SAFI_UNICAST;
431 else if (strmatch(safi_str, "vpn"))
432 safi = SAFI_MPLS_VPN;
433 else if (strmatch(safi_str, "evpn"))
434 safi = SAFI_EVPN;
435 else if (strmatch(safi_str, "labeled-unicast"))
436 safi = SAFI_LABELED_UNICAST;
437 else if (strmatch(safi_str, "flowspec"))
438 safi = SAFI_FLOWSPEC;
439 return safi;
440}
441
442int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
443 safi_t *safi)
444{
445 int ret = 0;
446 if (argv_find(argv, argc, "unicast", index)) {
447 ret = 1;
448 if (safi)
449 *safi = SAFI_UNICAST;
450 } else if (argv_find(argv, argc, "multicast", index)) {
451 ret = 1;
452 if (safi)
453 *safi = SAFI_MULTICAST;
454 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
455 ret = 1;
456 if (safi)
457 *safi = SAFI_LABELED_UNICAST;
458 } else if (argv_find(argv, argc, "vpn", index)) {
459 ret = 1;
460 if (safi)
461 *safi = SAFI_MPLS_VPN;
462 } else if (argv_find(argv, argc, "evpn", index)) {
463 ret = 1;
464 if (safi)
465 *safi = SAFI_EVPN;
466 } else if (argv_find(argv, argc, "flowspec", index)) {
467 ret = 1;
468 if (safi)
469 *safi = SAFI_FLOWSPEC;
470 }
471 return ret;
472}
473
474int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
475 enum bgp_instance_type inst_type)
476{
477 int ret = bgp_get(bgp, as, name, inst_type);
478
479 if (ret == BGP_CREATED) {
480 bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
481 DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN);
482
483 if (DFLT_BGP_IMPORT_CHECK)
484 SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
485 if (DFLT_BGP_SHOW_HOSTNAME)
486 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
487 if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
488 SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
489 if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
490 SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
491 if (DFLT_BGP_DETERMINISTIC_MED)
492 SET_FLAG((*bgp)->flags, BGP_FLAG_DETERMINISTIC_MED);
493 if (DFLT_BGP_EBGP_REQUIRES_POLICY)
494 SET_FLAG((*bgp)->flags, BGP_FLAG_EBGP_REQUIRES_POLICY);
495 if (DFLT_BGP_SUPPRESS_DUPLICATES)
496 SET_FLAG((*bgp)->flags, BGP_FLAG_SUPPRESS_DUPLICATES);
497
498 ret = BGP_SUCCESS;
499 }
500 return ret;
501}
502
503/*
504 * bgp_vty_find_and_parse_afi_safi_bgp
505 *
506 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
507 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
508 * to appropriate values for the calling function. This is to allow the
509 * calling function to make decisions appropriate for the show command
510 * that is being parsed.
511 *
512 * The show commands are generally of the form:
513 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
514 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
515 *
516 * Since we use argv_find if the show command in particular doesn't have:
517 * [ip]
518 * [<view|vrf> VIEWVRFNAME]
519 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
520 * The command parsing should still be ok.
521 *
522 * vty -> The vty for the command so we can output some useful data in
523 * the event of a parse error in the vrf.
524 * argv -> The command tokens
525 * argc -> How many command tokens we have
526 * idx -> The current place in the command, generally should be 0 for this
527 * function
528 * afi -> The parsed afi if it was included in the show command, returned here
529 * safi -> The parsed safi if it was included in the show command, returned here
530 * bgp -> Pointer to the bgp data structure we need to fill in.
531 * use_json -> json is configured or not
532 *
533 * The function returns the correct location in the parse tree for the
534 * last token found.
535 *
536 * Returns 0 for failure to parse correctly, else the idx position of where
537 * it found the last token.
538 */
539int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
540 struct cmd_token **argv, int argc,
541 int *idx, afi_t *afi, safi_t *safi,
542 struct bgp **bgp, bool use_json)
543{
544 char *vrf_name = NULL;
545
546 assert(afi);
547 assert(safi);
548 assert(bgp);
549
550 if (argv_find(argv, argc, "ip", idx))
551 *afi = AFI_IP;
552
553 if (argv_find(argv, argc, "view", idx))
554 vrf_name = argv[*idx + 1]->arg;
555 else if (argv_find(argv, argc, "vrf", idx)) {
556 vrf_name = argv[*idx + 1]->arg;
557 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
558 vrf_name = NULL;
559 }
560 if (vrf_name) {
561 if (strmatch(vrf_name, "all"))
562 *bgp = NULL;
563 else {
564 *bgp = bgp_lookup_by_name(vrf_name);
565 if (!*bgp) {
566 if (use_json) {
567 json_object *json = NULL;
568 json = json_object_new_object();
569 json_object_string_add(
570 json, "warning",
571 "View/Vrf is unknown");
572 vty_out(vty, "%s\n",
573 json_object_to_json_string_ext(json,
574 JSON_C_TO_STRING_PRETTY));
575 json_object_free(json);
576 }
577 else
578 vty_out(vty, "View/Vrf %s is unknown\n",
579 vrf_name);
580 *idx = 0;
581 return 0;
582 }
583 }
584 } else {
585 *bgp = bgp_get_default();
586 if (!*bgp) {
587 if (use_json) {
588 json_object *json = NULL;
589 json = json_object_new_object();
590 json_object_string_add(
591 json, "warning",
592 "Default BGP instance not found");
593 vty_out(vty, "%s\n",
594 json_object_to_json_string_ext(json,
595 JSON_C_TO_STRING_PRETTY));
596 json_object_free(json);
597 }
598 else
599 vty_out(vty,
600 "Default BGP instance not found\n");
601 *idx = 0;
602 return 0;
603 }
604 }
605
606 if (argv_find_and_parse_afi(argv, argc, idx, afi))
607 argv_find_and_parse_safi(argv, argc, idx, safi);
608
609 *idx += 1;
610 return *idx;
611}
612
613bool peer_address_self_check(struct bgp *bgp, union sockunion *su)
614{
615 struct interface *ifp = NULL;
616
617 if (su->sa.sa_family == AF_INET)
618 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
619 else if (su->sa.sa_family == AF_INET6)
620 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
621 su->sin6.sin6_scope_id,
622 bgp->vrf_id);
623
624 if (ifp)
625 return true;
626
627 return false;
628}
629
630/* Utility function for looking up peer or peer group. */
631/* This is used only for configuration, so disallow if attempted on
632 * a dynamic neighbor.
633 */
634struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
635{
636 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
637 int ret;
638 union sockunion su;
639 struct peer *peer = NULL;
640 struct peer_group *group = NULL;
641
642 if (!bgp) {
643 return NULL;
644 }
645
646 ret = str2sockunion(peer_str, &su);
647 if (ret == 0) {
648 /* IP address, locate peer. */
649 peer = peer_lookup(bgp, &su);
650 } else {
651 /* Not IP, could match either peer configured on interface or a
652 * group. */
653 peer = peer_lookup_by_conf_if(bgp, peer_str);
654 if (!peer)
655 group = peer_group_lookup(bgp, peer_str);
656 }
657
658 if (peer) {
659 if (peer_dynamic_neighbor(peer)) {
660 vty_out(vty,
661 "%% Operation not allowed on a dynamic neighbor\n");
662 return NULL;
663 }
664
665 return peer;
666 }
667
668 if (group)
669 return group->conf;
670
671 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
672
673 return NULL;
674}
675
676int bgp_nb_errmsg_return(char *errmsg, size_t errmsg_len, int ret)
677{
678 const char *str = NULL;
679
680 switch (ret) {
681 case BGP_ERR_INVALID_VALUE:
682 str = "Invalid value";
683 break;
684 case BGP_ERR_INVALID_FLAG:
685 str = "Invalid flag";
686 break;
687 case BGP_ERR_PEER_GROUP_SHUTDOWN:
688 str = "Peer-group has been shutdown. Activate the peer-group first";
689 break;
690 case BGP_ERR_PEER_FLAG_CONFLICT:
691 str = "Can't set override-capability and strict-capability-match at the same time";
692 break;
693 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
694 str = "Specify remote-as or peer-group remote AS first";
695 break;
696 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
697 str = "Cannot change the peer-group. Deconfigure first";
698 break;
699 case BGP_ERR_PEER_GROUP_MISMATCH:
700 str = "Peer is not a member of this peer-group";
701 break;
702 case BGP_ERR_PEER_FILTER_CONFLICT:
703 str = "Prefix/distribute list can not co-exist";
704 break;
705 case BGP_ERR_NOT_INTERNAL_PEER:
706 str = "Invalid command. Not an internal neighbor";
707 break;
708 case BGP_ERR_REMOVE_PRIVATE_AS:
709 str = "remove-private-AS cannot be configured for IBGP peers";
710 break;
711 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
712 str = "Local-AS allowed only for EBGP peers";
713 break;
714 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
715 str = "Cannot have local-as same as BGP AS number";
716 break;
717 case BGP_ERR_TCPSIG_FAILED:
718 str = "Error while applying TCP-Sig to session(s)";
719 break;
720 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
721 str = "ebgp-multihop and ttl-security cannot be configured together";
722 break;
723 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
724 str = "ttl-security only allowed for EBGP peers";
725 break;
726 case BGP_ERR_AS_OVERRIDE:
727 str = "as-override cannot be configured for IBGP peers";
728 break;
729 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
730 str = "Invalid limit for number of dynamic neighbors";
731 break;
732 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
733 str = "Dynamic neighbor listen range already exists";
734 break;
735 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
736 str = "Operation not allowed on a dynamic neighbor";
737 break;
738 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
739 str = "Operation not allowed on a directly connected neighbor";
740 break;
741 case BGP_ERR_PEER_SAFI_CONFLICT:
742 str = GR_INVALID;
743 break;
744 case BGP_ERR_GR_INVALID_CMD:
745 str = "The Graceful Restart command used is not valid at this moment.";
746 break;
747 case BGP_ERR_GR_OPERATION_FAILED:
748 str = "The Graceful Restart Operation failed due to an err.";
749 break;
750 case BGP_GR_NO_OPERATION:
751 str = GR_NO_OPER;
752 break;
753 case BGP_ERR_PEER_GROUP_MEMBER:
754 str = "Peer-group member cannot override remote-as of peer-group";
755 break;
756 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
757 str = "Peer-group members must be all internal or all external";
758 break;
759 }
760 if (str) {
761 snprintf(errmsg, errmsg_len, "%s", str);
762 return -1;
763 }
764
765 return 0;
766}
767
768int bgp_vty_return(struct vty *vty, int ret)
769{
770 const char *str = NULL;
771
772 switch (ret) {
773 case BGP_ERR_INVALID_VALUE:
774 str = "Invalid value";
775 break;
776 case BGP_ERR_INVALID_FLAG:
777 str = "Invalid flag";
778 break;
779 case BGP_ERR_PEER_GROUP_SHUTDOWN:
780 str = "Peer-group has been shutdown. Activate the peer-group first";
781 break;
782 case BGP_ERR_PEER_FLAG_CONFLICT:
783 str = "Can't set override-capability and strict-capability-match at the same time";
784 break;
785 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
786 str = "Specify remote-as or peer-group remote AS first";
787 break;
788 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
789 str = "Cannot change the peer-group. Deconfigure first";
790 break;
791 case BGP_ERR_PEER_GROUP_MISMATCH:
792 str = "Peer is not a member of this peer-group";
793 break;
794 case BGP_ERR_PEER_FILTER_CONFLICT:
795 str = "Prefix/distribute list can not co-exist";
796 break;
797 case BGP_ERR_NOT_INTERNAL_PEER:
798 str = "Invalid command. Not an internal neighbor";
799 break;
800 case BGP_ERR_REMOVE_PRIVATE_AS:
801 str = "remove-private-AS cannot be configured for IBGP peers";
802 break;
803 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
804 str = "Local-AS allowed only for EBGP peers";
805 break;
806 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
807 str = "Cannot have local-as same as BGP AS number";
808 break;
809 case BGP_ERR_TCPSIG_FAILED:
810 str = "Error while applying TCP-Sig to session(s)";
811 break;
812 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
813 str = "ebgp-multihop and ttl-security cannot be configured together";
814 break;
815 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
816 str = "ttl-security only allowed for EBGP peers";
817 break;
818 case BGP_ERR_AS_OVERRIDE:
819 str = "as-override cannot be configured for IBGP peers";
820 break;
821 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
822 str = "Invalid limit for number of dynamic neighbors";
823 break;
824 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
825 str = "Dynamic neighbor listen range already exists";
826 break;
827 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
828 str = "Operation not allowed on a dynamic neighbor";
829 break;
830 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
831 str = "Operation not allowed on a directly connected neighbor";
832 break;
833 case BGP_ERR_PEER_SAFI_CONFLICT:
834 str = GR_INVALID;
835 break;
836 case BGP_ERR_GR_INVALID_CMD:
837 str = "The Graceful Restart command used is not valid at this moment.";
838 break;
839 case BGP_ERR_GR_OPERATION_FAILED:
840 str = "The Graceful Restart Operation failed due to an err.";
841 break;
842 case BGP_GR_NO_OPERATION:
843 str = GR_NO_OPER;
844 break;
845 }
846 if (str) {
847 vty_out(vty, "%% %s\n", str);
848 return CMD_WARNING_CONFIG_FAILED;
849 }
850 return CMD_SUCCESS;
851}
852
853/* BGP clear sort. */
854enum clear_sort {
855 clear_all,
856 clear_peer,
857 clear_group,
858 clear_external,
859 clear_as
860};
861
862static void bgp_clear_vty_error(struct peer *peer, afi_t afi, safi_t safi,
863 int error, char *errmsg, size_t errmsg_len)
864{
865 switch (error) {
866 case BGP_ERR_AF_UNCONFIGURED:
867 snprintf(errmsg, errmsg_len,
868 "%%BGP: Enable %s address family for the neighbor %s",
869 get_afi_safi_str(afi, safi, false), peer->host);
870 break;
871 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
872 snprintf(
873 errmsg, errmsg_len,
874 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig",
875 peer->host);
876 break;
877 default:
878 break;
879 }
880}
881
882static int bgp_peer_clear(struct peer *peer, afi_t afi, safi_t safi,
883 struct listnode **nnode, enum bgp_clear_type stype)
884{
885 int ret = 0;
886 struct peer_af *paf;
887
888 /* if afi/.safi not specified, spin thru all of them */
889 if ((afi == AFI_UNSPEC) && (safi == SAFI_UNSPEC)) {
890 afi_t tmp_afi;
891 safi_t tmp_safi;
892
893 FOREACH_AFI_SAFI (tmp_afi, tmp_safi) {
894 paf = peer_af_find(peer, tmp_afi, tmp_safi);
895 if (paf && paf->subgroup)
896 SET_FLAG(paf->subgroup->sflags,
897 SUBGRP_STATUS_FORCE_UPDATES);
898
899 if (!peer->afc[tmp_afi][tmp_safi])
900 continue;
901
902 if (stype == BGP_CLEAR_SOFT_NONE)
903 ret = peer_clear(peer, nnode);
904 else
905 ret = peer_clear_soft(peer, tmp_afi, tmp_safi,
906 stype);
907 }
908 /* if afi specified and safi not, spin thru safis on this afi */
909 } else if (safi == SAFI_UNSPEC) {
910 safi_t tmp_safi;
911
912 for (tmp_safi = SAFI_UNICAST;
913 tmp_safi < SAFI_MAX; tmp_safi++) {
914 if (!peer->afc[afi][tmp_safi])
915 continue;
916
917 paf = peer_af_find(peer, afi, tmp_safi);
918 if (paf && paf->subgroup)
919 SET_FLAG(paf->subgroup->sflags,
920 SUBGRP_STATUS_FORCE_UPDATES);
921
922 if (stype == BGP_CLEAR_SOFT_NONE)
923 ret = peer_clear(peer, nnode);
924 else
925 ret = peer_clear_soft(peer, afi,
926 tmp_safi, stype);
927 }
928 /* both afi/safi specified, let the caller know if not defined */
929 } else {
930 if (!peer->afc[afi][safi])
931 return 1;
932
933 paf = peer_af_find(peer, afi, safi);
934 if (paf && paf->subgroup)
935 SET_FLAG(paf->subgroup->sflags,
936 SUBGRP_STATUS_FORCE_UPDATES);
937
938 if (stype == BGP_CLEAR_SOFT_NONE)
939 ret = peer_clear(peer, nnode);
940 else
941 ret = peer_clear_soft(peer, afi, safi, stype);
942 }
943
944 return ret;
945}
946
947/* `clear ip bgp' functions. */
948static int bgp_clear(struct bgp *bgp, afi_t afi, safi_t safi,
949 enum clear_sort sort, enum bgp_clear_type stype,
950 const char *arg, char *errmsg, size_t errmsg_len)
951{
952 int ret = 0;
953 bool found = false;
954 struct peer *peer;
955
956 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
957
958 /* Clear all neighbors. */
959 /*
960 * Pass along pointer to next node to peer_clear() when walking all
961 * nodes on the BGP instance as that may get freed if it is a
962 * doppelganger
963 */
964 if (sort == clear_all) {
965 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
966
967 bgp_peer_gr_flags_update(peer);
968
969 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
970 gr_router_detected = true;
971
972 ret = bgp_peer_clear(peer, afi, safi, &nnode,
973 stype);
974
975 if (ret < 0)
976 bgp_clear_vty_error(peer, afi, safi, ret,
977 errmsg, errmsg_len);
978 }
979
980 if (gr_router_detected
981 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
982 bgp_zebra_send_capabilities(bgp, false);
983 } else if (!gr_router_detected
984 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
985 bgp_zebra_send_capabilities(bgp, true);
986 }
987
988 /* This is to apply read-only mode on this clear. */
989 if (stype == BGP_CLEAR_SOFT_NONE)
990 bgp->update_delay_over = 0;
991
992 return CMD_SUCCESS;
993 }
994
995 /* Clear specified neighbor. */
996 if (sort == clear_peer) {
997 union sockunion su;
998
999 /* Make sockunion for lookup. */
1000 ret = str2sockunion(arg, &su);
1001 if (ret < 0) {
1002 peer = peer_lookup_by_conf_if(bgp, arg);
1003 if (!peer) {
1004 peer = peer_lookup_by_hostname(bgp, arg);
1005 if (!peer) {
1006 snprintf(
1007 errmsg, errmsg_len,
1008 "Malformed address or name: %s",
1009 arg);
1010 return CMD_WARNING;
1011 }
1012 }
1013 } else {
1014 peer = peer_lookup(bgp, &su);
1015 if (!peer) {
1016 snprintf(errmsg, errmsg_len,
1017 "%%BGP: Unknown neighbor - \"%s\"",
1018 arg);
1019 return CMD_WARNING;
1020 }
1021 }
1022
1023 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
1024 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
1025
1026 ret = bgp_peer_clear(peer, afi, safi, NULL, stype);
1027
1028 /* if afi/safi not defined for this peer, let caller know */
1029 if (ret == 1)
1030 ret = BGP_ERR_AF_UNCONFIGURED;
1031
1032 if (ret < 0)
1033 bgp_clear_vty_error(peer, afi, safi, ret, errmsg,
1034 errmsg_len);
1035
1036 return CMD_SUCCESS;
1037 }
1038
1039 /* Clear all neighbors belonging to a specific peer-group. */
1040 if (sort == clear_group) {
1041 struct peer_group *group;
1042
1043 group = peer_group_lookup(bgp, arg);
1044 if (!group) {
1045 snprintf(errmsg, errmsg_len,
1046 "%%BGP: No such peer-group %s", arg);
1047 return CMD_WARNING;
1048 }
1049
1050 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1051 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1052
1053 if (ret < 0)
1054 bgp_clear_vty_error(peer, afi, safi, ret,
1055 errmsg, errmsg_len);
1056 else
1057 found = true;
1058 }
1059
1060 if (!found)
1061 snprintf(
1062 errmsg, errmsg_len,
1063 "%%BGP: No %s peer belonging to peer-group %s is configured",
1064 get_afi_safi_str(afi, safi, false), arg);
1065
1066 return CMD_SUCCESS;
1067 }
1068
1069 /* Clear all external (eBGP) neighbors. */
1070 if (sort == clear_external) {
1071 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1072 if (peer->sort == BGP_PEER_IBGP)
1073 continue;
1074
1075 bgp_peer_gr_flags_update(peer);
1076
1077 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1078 gr_router_detected = true;
1079
1080 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1081
1082 if (ret < 0)
1083 bgp_clear_vty_error(peer, afi, safi, ret,
1084 errmsg, errmsg_len);
1085 else
1086 found = true;
1087 }
1088
1089 if (gr_router_detected
1090 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1091 bgp_zebra_send_capabilities(bgp, false);
1092 } else if (!gr_router_detected
1093 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1094 bgp_zebra_send_capabilities(bgp, true);
1095 }
1096
1097 if (!found)
1098 snprintf(errmsg, errmsg_len,
1099 "%%BGP: No external %s peer is configured",
1100 get_afi_safi_str(afi, safi, false));
1101
1102 return CMD_SUCCESS;
1103 }
1104
1105 /* Clear all neighbors belonging to a specific AS. */
1106 if (sort == clear_as) {
1107 as_t as = strtoul(arg, NULL, 10);
1108
1109 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1110 if (peer->as != as)
1111 continue;
1112
1113 bgp_peer_gr_flags_update(peer);
1114
1115 if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART))
1116 gr_router_detected = true;
1117
1118 ret = bgp_peer_clear(peer, afi, safi, &nnode, stype);
1119
1120 if (ret < 0)
1121 bgp_clear_vty_error(peer, afi, safi, ret,
1122 errmsg, errmsg_len);
1123 else
1124 found = true;
1125 }
1126
1127 if (gr_router_detected
1128 && bgp->present_zebra_gr_state == ZEBRA_GR_DISABLE) {
1129 bgp_zebra_send_capabilities(bgp, false);
1130 } else if (!gr_router_detected
1131 && bgp->present_zebra_gr_state == ZEBRA_GR_ENABLE) {
1132 bgp_zebra_send_capabilities(bgp, true);
1133 }
1134
1135 if (!found)
1136 snprintf(errmsg, errmsg_len,
1137 "%%BGP: No %s peer is configured with AS %s",
1138 get_afi_safi_str(afi, safi, false), arg);
1139
1140 return CMD_SUCCESS;
1141 }
1142
1143 return CMD_SUCCESS;
1144}
1145
1146static int bgp_clear_vty(const char *name, afi_t afi, safi_t safi,
1147 enum clear_sort sort, enum bgp_clear_type stype,
1148 const char *arg, char *errmsg, size_t errmsg_len)
1149{
1150 struct bgp *bgp;
1151
1152 /* BGP structure lookup. */
1153 if (name) {
1154 bgp = bgp_lookup_by_name(name);
1155 if (bgp == NULL) {
1156 snprintf(errmsg, errmsg_len,
1157 "Can't find BGP instance %s", name);
1158 return CMD_WARNING;
1159 }
1160 } else {
1161 bgp = bgp_get_default();
1162 if (bgp == NULL) {
1163 snprintf(errmsg, errmsg_len,
1164 "No BGP process is configured");
1165 return CMD_WARNING;
1166 }
1167 }
1168
1169 return bgp_clear(bgp, afi, safi, sort, stype, arg, errmsg, errmsg_len);
1170}
1171
1172/* clear soft inbound */
1173int bgp_clear_star_soft_in(const char *name, char *errmsg, size_t errmsg_len)
1174{
1175 afi_t afi;
1176 safi_t safi;
1177 int ret;
1178
1179 FOREACH_AFI_SAFI (afi, safi) {
1180 ret = bgp_clear_vty(name, afi, safi, clear_all,
1181 BGP_CLEAR_SOFT_IN, NULL, errmsg,
1182 errmsg_len);
1183 if (ret != CMD_SUCCESS)
1184 return -1;
1185 }
1186
1187 return 0;
1188}
1189
1190/* clear soft outbound */
1191int bgp_clear_star_soft_out(const char *name, char *errmsg, size_t errmsg_len)
1192{
1193 afi_t afi;
1194 safi_t safi;
1195 int ret;
1196
1197 FOREACH_AFI_SAFI (afi, safi) {
1198 ret = bgp_clear_vty(name, afi, safi, clear_all,
1199 BGP_CLEAR_SOFT_OUT, NULL, errmsg,
1200 errmsg_len);
1201 if (ret != CMD_SUCCESS)
1202 return -1;
1203 }
1204
1205 return 0;
1206}
1207
1208
1209#ifndef VTYSH_EXTRACT_PL
1210#include "bgpd/bgp_vty_clippy.c"
1211#endif
1212
1213DEFUN_HIDDEN (bgp_local_mac,
1214 bgp_local_mac_cmd,
1215 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
1216 BGP_STR
1217 "Local MAC config\n"
1218 "VxLAN Network Identifier\n"
1219 "VNI number\n"
1220 "local mac\n"
1221 "mac address\n"
1222 "mac-mobility sequence\n"
1223 "seq number\n")
1224{
1225 int rv;
1226 vni_t vni;
1227 struct ethaddr mac;
1228 struct ipaddr ip;
1229 uint32_t seq;
1230 struct bgp *bgp;
1231
1232 vni = strtoul(argv[3]->arg, NULL, 10);
1233 if (!prefix_str2mac(argv[5]->arg, &mac)) {
1234 vty_out(vty, "%% Malformed MAC address\n");
1235 return CMD_WARNING;
1236 }
1237 memset(&ip, 0, sizeof(ip));
1238 seq = strtoul(argv[7]->arg, NULL, 10);
1239
1240 bgp = bgp_get_default();
1241 if (!bgp) {
1242 vty_out(vty, "Default BGP instance is not there\n");
1243 return CMD_WARNING;
1244 }
1245
1246 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
1247 zero_esi);
1248 if (rv < 0) {
1249 vty_out(vty, "Internal error\n");
1250 return CMD_WARNING;
1251 }
1252
1253 return CMD_SUCCESS;
1254}
1255
1256DEFUN_HIDDEN (no_bgp_local_mac,
1257 no_bgp_local_mac_cmd,
1258 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
1259 NO_STR
1260 BGP_STR
1261 "Local MAC config\n"
1262 "VxLAN Network Identifier\n"
1263 "VNI number\n"
1264 "local mac\n"
1265 "mac address\n")
1266{
1267 int rv;
1268 vni_t vni;
1269 struct ethaddr mac;
1270 struct ipaddr ip;
1271 struct bgp *bgp;
1272
1273 vni = strtoul(argv[4]->arg, NULL, 10);
1274 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1275 vty_out(vty, "%% Malformed MAC address\n");
1276 return CMD_WARNING;
1277 }
1278 memset(&ip, 0, sizeof(ip));
1279
1280 bgp = bgp_get_default();
1281 if (!bgp) {
1282 vty_out(vty, "Default BGP instance is not there\n");
1283 return CMD_WARNING;
1284 }
1285
1286 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
1287 if (rv < 0) {
1288 vty_out(vty, "Internal error\n");
1289 return CMD_WARNING;
1290 }
1291
1292 return CMD_SUCCESS;
1293}
1294
1295DEFUN (no_synchronization,
1296 no_synchronization_cmd,
1297 "no synchronization",
1298 NO_STR
1299 "Perform IGP synchronization\n")
1300{
1301 return CMD_SUCCESS;
1302}
1303
1304DEFUN (no_auto_summary,
1305 no_auto_summary_cmd,
1306 "no auto-summary",
1307 NO_STR
1308 "Enable automatic network number summarization\n")
1309{
1310 return CMD_SUCCESS;
1311}
1312
1313/* "router bgp" commands. */
1314DEFUN_YANG_NOSH(router_bgp,
1315 router_bgp_cmd,
1316 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1317 ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1318{
1319 int idx_asn = 2;
1320 int idx_view_vrf = 3;
1321 int idx_vrf = 4;
1322 int ret = CMD_SUCCESS;
1323 as_t as;
1324 struct bgp *bgp;
1325 const char *name = NULL;
1326 char as_str[12] = {'\0'};
1327 enum bgp_instance_type inst_type;
1328 char base_xpath[XPATH_MAXLEN];
1329
1330 // "router bgp" without an ASN
1331 if (argc == 2) {
1332 // Pending: Make VRF option available for ASN less config
1333 bgp = bgp_get_default();
1334
1335 if (bgp == NULL) {
1336 vty_out(vty, "%% No BGP process is configured\n");
1337 return CMD_WARNING_CONFIG_FAILED;
1338 }
1339
1340 if (listcount(bm->bgp) > 1) {
1341 vty_out(vty, "%% Please specify ASN and VRF\n");
1342 return CMD_WARNING_CONFIG_FAILED;
1343 }
1344
1345 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1346 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1347
1348 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1349 snprintf(as_str, 12, "%d", bgp->as);
1350 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1351 as_str);
1352 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) {
1353 nb_cli_enqueue_change(vty,
1354 "./global/instance-type-view",
1355 NB_OP_MODIFY, "true");
1356 }
1357
1358 nb_cli_pending_commit_check(vty);
1359 ret = nb_cli_apply_changes(vty, base_xpath);
1360 if (ret == CMD_SUCCESS) {
1361 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1362
1363 /*
1364 * For backward compatibility with old commands we still
1365 * need to use the qobj infrastructure.
1366 */
1367 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1368 }
1369 return ret;
1370 }
1371
1372 // "router bgp X"
1373 else {
1374
1375 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1376 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1377 if (argc > 3) {
1378 name = argv[idx_vrf]->arg;
1379
1380 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1381 if (strmatch(name, VRF_DEFAULT_NAME))
1382 name = NULL;
1383 else
1384 inst_type = BGP_INSTANCE_TYPE_VRF;
1385 } else if (!strcmp(argv[idx_view_vrf]->text, "view")) {
1386 inst_type = BGP_INSTANCE_TYPE_VIEW;
1387 }
1388 }
1389 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1390 "frr-bgp:bgp", "bgp", name ? name : VRF_DEFAULT_NAME);
1391
1392 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
1393 nb_cli_enqueue_change(vty, "./global/local-as", NB_OP_MODIFY,
1394 argv[idx_asn]->arg);
1395 if (inst_type == BGP_INSTANCE_TYPE_VIEW) {
1396 nb_cli_enqueue_change(vty,
1397 "./global/instance-type-view",
1398 NB_OP_MODIFY, "true");
1399 }
1400
1401 nb_cli_pending_commit_check(vty);
1402 ret = nb_cli_apply_changes(vty, base_xpath);
1403 if (ret == CMD_SUCCESS) {
1404 VTY_PUSH_XPATH(BGP_NODE, base_xpath);
1405
1406 /*
1407 * For backward compatibility with old commands we still
1408 * need to use the qobj infrastructure.
1409 */
1410 bgp = bgp_lookup(as, name);
1411 if (bgp)
1412 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1413 }
1414 }
1415
1416 return ret;
1417}
1418
1419/* "no router bgp" commands. */
1420DEFUN_YANG(no_router_bgp,
1421 no_router_bgp_cmd,
1422 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1423 NO_STR ROUTER_STR BGP_STR AS_STR BGP_INSTANCE_HELP_STR)
1424{
1425 int idx_asn = 3;
1426 int idx_vrf = 5;
1427 as_t as = 0;
1428 struct bgp *bgp;
1429 const char *name = NULL;
1430 char base_xpath[XPATH_MAXLEN];
1431 const struct lyd_node *bgp_glb_dnode;
1432
1433 // "no router bgp" without an ASN
1434 if (argc == 3) {
1435 // Pending: Make VRF option available for ASN less config
1436 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1437 "frr-bgp:bgp", "bgp", VRF_DEFAULT_NAME);
1438
1439 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
1440 base_xpath);
1441 if (!bgp_glb_dnode) {
1442 vty_out(vty, "%% No BGP process is configured\n");
1443 return CMD_WARNING_CONFIG_FAILED;
1444 }
1445
1446 if (listcount(bm->bgp) > 1) {
1447 vty_out(vty, "%% Please specify ASN and VRF\n");
1448 return CMD_WARNING_CONFIG_FAILED;
1449 }
1450
1451 /* tcli mode bgp would not be set until apply stage. */
1452 bgp = nb_running_get_entry(bgp_glb_dnode, NULL, false);
1453 if (!bgp)
1454 return CMD_SUCCESS;
1455
1456 if (bgp->l3vni) {
1457 vty_out(vty, "%% Please unconfigure l3vni %u",
1458 bgp->l3vni);
1459 return CMD_WARNING_CONFIG_FAILED;
1460 }
1461 } else {
1462 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1463
1464 if (argc > 4)
1465 name = argv[idx_vrf]->arg;
1466
1467 /* Lookup bgp structure. */
1468 bgp = bgp_lookup(as, name);
1469 if (!bgp) {
1470 vty_out(vty, "%% Can't find BGP instance\n");
1471 return CMD_WARNING_CONFIG_FAILED;
1472 }
1473
1474 if (bgp->l3vni) {
1475 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1476 bgp->l3vni);
1477 return CMD_WARNING_CONFIG_FAILED;
1478 }
1479
1480 /* Cannot delete default instance if vrf instances exist */
1481 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1482 struct listnode *node;
1483 struct bgp *tmp_bgp;
1484
1485 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1486 if (tmp_bgp->inst_type
1487 == BGP_INSTANCE_TYPE_VRF) {
1488 vty_out(vty,
1489 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1490 return CMD_WARNING_CONFIG_FAILED;
1491 }
1492 }
1493 }
1494 }
1495 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_GLOBAL_XPATH,
1496 "frr-bgp:bgp", "bgp",
1497 bgp->name ? bgp->name : VRF_DEFAULT_NAME);
1498
1499 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
1500
1501 return nb_cli_apply_changes(vty, base_xpath);
1502}
1503
1504void cli_show_router_bgp(struct vty *vty, struct lyd_node *dnode,
1505 bool show_defaults)
1506{
1507 const struct lyd_node *vrf_dnode;
1508 const char *vrf_name;
1509 as_t as;
1510
1511 vrf_dnode = yang_dnode_get_parent(dnode, "control-plane-protocol");
1512 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
1513 as = yang_dnode_get_uint32(dnode, "./global/local-as");
1514
1515 vty_out(vty, "!\n");
1516 vty_out(vty, "router bgp %u", as);
1517 if (!strmatch(vrf_name, VRF_DEFAULT_NAME))
1518 vty_out(vty, " vrf %s", vrf_name);
1519 vty_out(vty, "\n");
1520}
1521
1522/* BGP router-id. */
1523
1524DEFPY_YANG(bgp_router_id, bgp_router_id_cmd, "bgp router-id A.B.C.D",
1525 BGP_STR
1526 "Override configured router identifier\n"
1527 "Manually configured router identifier\n")
1528{
1529 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_MODIFY,
1530 router_id_str);
1531
1532 return nb_cli_apply_changes(vty, NULL);
1533}
1534
1535DEFPY_YANG(no_bgp_router_id, no_bgp_router_id_cmd, "no bgp router-id [A.B.C.D]",
1536 NO_STR BGP_STR
1537 "Override configured router identifier\n"
1538 "Manually configured router identifier\n")
1539{
1540 nb_cli_enqueue_change(vty, "./global/router-id", NB_OP_DESTROY,
1541 router_id_str ? router_id_str : NULL);
1542
1543 return nb_cli_apply_changes(vty, NULL);
1544}
1545
1546void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode,
1547 bool show_defaults)
1548{
1549 vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL));
1550}
1551
1552DEFPY (bgp_global_suppress_fib_pending,
1553 bgp_global_suppress_fib_pending_cmd,
1554 "[no] bgp suppress-fib-pending",
1555 NO_STR
1556 BGP_STR
1557 "Advertise only routes that are programmed in kernel to peers globally\n")
1558{
1559 bm_wait_for_fib_set(!no);
1560
1561 return CMD_SUCCESS;
1562}
1563
1564DEFPY (bgp_suppress_fib_pending,
1565 bgp_suppress_fib_pending_cmd,
1566 "[no] bgp suppress-fib-pending",
1567 NO_STR
1568 BGP_STR
1569 "Advertise only routes that are programmed in kernel to peers\n")
1570{
1571 VTY_DECLVAR_CONTEXT(bgp, bgp);
1572
1573 bgp_suppress_fib_pending_set(bgp, !no);
1574 return CMD_SUCCESS;
1575}
1576
1577
1578/* BGP Cluster ID. */
1579DEFUN_YANG(bgp_cluster_id,
1580 bgp_cluster_id_cmd,
1581 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1582 BGP_STR
1583 "Configure Route-Reflector Cluster-id\n"
1584 "Route-Reflector Cluster-id in IP address format\n"
1585 "Route-Reflector Cluster-id as 32 bit quantity\n")
1586{
1587 int idx_ipv4 = 2;
1588
1589 nb_cli_enqueue_change(
1590 vty, "./global/route-reflector/route-reflector-cluster-id",
1591 NB_OP_MODIFY, argv[idx_ipv4]->arg);
1592
1593 return nb_cli_apply_changes(vty, NULL);
1594}
1595
1596DEFUN_YANG(no_bgp_cluster_id,
1597 no_bgp_cluster_id_cmd,
1598 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1599 NO_STR BGP_STR
1600 "Configure Route-Reflector Cluster-id\n"
1601 "Route-Reflector Cluster-id in IP address format\n"
1602 "Route-Reflector Cluster-id as 32 bit quantity\n")
1603{
1604 nb_cli_enqueue_change(
1605 vty, "./global/route-reflector/route-reflector-cluster-id",
1606 NB_OP_DESTROY, NULL);
1607
1608 return nb_cli_apply_changes(vty, NULL);
1609}
1610
1611DEFPY (bgp_norib,
1612 bgp_norib_cmd,
1613 "bgp no-rib",
1614 BGP_STR
1615 "Disable BGP route installation to RIB (Zebra)\n")
1616{
1617 if (bgp_option_check(BGP_OPT_NO_FIB)) {
1618 vty_out(vty,
1619 "%% No-RIB option is already set, nothing to do here.\n");
1620 return CMD_SUCCESS;
1621 }
1622
1623 bgp_option_norib_set_runtime();
1624
1625 return CMD_SUCCESS;
1626}
1627
1628DEFPY (no_bgp_norib,
1629 no_bgp_norib_cmd,
1630 "no bgp no-rib",
1631 NO_STR
1632 BGP_STR
1633 "Disable BGP route installation to RIB (Zebra)\n")
1634{
1635 if (!bgp_option_check(BGP_OPT_NO_FIB)) {
1636 vty_out(vty,
1637 "%% No-RIB option is not set, nothing to do here.\n");
1638 return CMD_SUCCESS;
1639 }
1640
1641 bgp_option_norib_unset_runtime();
1642
1643 return CMD_SUCCESS;
1644}
1645
1646DEFPY (no_bgp_send_extra_data,
1647 no_bgp_send_extra_data_cmd,
1648 "[no] bgp send-extra-data zebra",
1649 NO_STR
1650 BGP_STR
1651 "Extra data to Zebra for display/use\n"
1652 "To zebra\n")
1653{
1654 if (no)
1655 UNSET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1656 else
1657 SET_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA);
1658
1659 return CMD_SUCCESS;
1660}
1661
1662DEFUN_YANG(bgp_confederation_identifier,
1663 bgp_confederation_identifier_cmd,
1664 "bgp confederation identifier (1-4294967295)",
1665 "BGP specific commands\n"
1666 "AS confederation parameters\n"
1667 "AS number\n"
1668 "Set routing domain confederation AS\n")
1669{
1670 int idx_number = 3;
1671
1672 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1673 NB_OP_MODIFY, argv[idx_number]->arg);
1674
1675 return nb_cli_apply_changes(vty, NULL);
1676}
1677
1678DEFUN_YANG(no_bgp_confederation_identifier,
1679 no_bgp_confederation_identifier_cmd,
1680 "no bgp confederation identifier [(1-4294967295)]",
1681 NO_STR
1682 "BGP specific commands\n"
1683 "AS confederation parameters\n"
1684 "AS number\n"
1685 "Set routing domain confederation AS\n")
1686{
1687 nb_cli_enqueue_change(vty, "./global/confederation/identifier",
1688 NB_OP_DESTROY, NULL);
1689
1690 return nb_cli_apply_changes(vty, NULL);
1691}
1692
1693void cli_show_router_bgp_confederation_identifier(struct vty *vty,
1694 struct lyd_node *dnode,
1695 bool show_defaults)
1696{
1697 vty_out(vty, " bgp confederation identifier %u\n",
1698 yang_dnode_get_uint32(dnode, NULL));
1699}
1700
1701DEFUN_YANG(bgp_confederation_peers,
1702 bgp_confederation_peers_cmd,
1703 "bgp confederation peers (1-4294967295)...",
1704 "BGP specific commands\n"
1705 "AS confederation parameters\n"
1706 "Peer ASs in BGP confederation\n" AS_STR)
1707{
1708 int idx_asn = 3;
1709 int i;
1710
1711 for (i = idx_asn; i < argc; i++)
1712 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1713 NB_OP_CREATE, argv[i]->arg);
1714
1715 return nb_cli_apply_changes(vty, NULL);
1716}
1717
1718DEFUN_YANG(no_bgp_confederation_peers,
1719 no_bgp_confederation_peers_cmd,
1720 "no bgp confederation peers (1-4294967295)...",
1721 NO_STR
1722 "BGP specific commands\n"
1723 "AS confederation parameters\n"
1724 "Peer ASs in BGP confederation\n" AS_STR)
1725{
1726 int idx_asn = 4;
1727 int i;
1728
1729 for (i = idx_asn; i < argc; i++)
1730 nb_cli_enqueue_change(vty, "./global/confederation/member-as",
1731 NB_OP_DESTROY, argv[i]->arg);
1732
1733 return nb_cli_apply_changes(vty, NULL);
1734}
1735
1736void cli_show_router_bgp_confederation_member_as(struct vty *vty,
1737 struct lyd_node *dnode,
1738 bool show_defaults)
1739{
1740 vty_out(vty, " bgp confederation peers %u \n",
1741 yang_dnode_get_uint32(dnode, NULL));
1742}
1743
1744/**
1745 * Central routine for maximum-paths configuration.
1746 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1747 * @set: 1 for setting values, 0 for removing the max-paths config.
1748 */
1749int bgp_maxpaths_config_vty(struct bgp *bgp, afi_t afi, safi_t safi,
1750 int peer_type, uint16_t maxpaths, uint16_t options,
1751 int set, char *errmsg, size_t errmsg_len)
1752{
1753 int ret;
1754
1755 if (set) {
1756 if (maxpaths > multipath_num) {
1757 snprintf(
1758 errmsg, errmsg_len,
1759 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1760 maxpaths, multipath_num);
1761 return CMD_WARNING_CONFIG_FAILED;
1762 }
1763 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1764 options);
1765 } else
1766 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1767
1768 if (ret < 0) {
1769 snprintf(
1770 errmsg, errmsg_len,
1771 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1772 (set == 1) ? "" : "un",
1773 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1774 maxpaths, afi, safi);
1775 return CMD_WARNING_CONFIG_FAILED;
1776 }
1777
1778 bgp_recalculate_all_bestpaths(bgp);
1779
1780 return CMD_SUCCESS;
1781}
1782
1783void cli_show_router_bgp_med_config(struct vty *vty, struct lyd_node *dnode,
1784 bool show_defaults)
1785{
1786 if (yang_dnode_get_bool(dnode, "./enable-med-admin")) {
1787 uint32_t med_admin_val;
1788
1789 vty_out(vty, " bgp max-med administrative");
1790 if ((med_admin_val =
1791 yang_dnode_get_uint32(dnode, "./max-med-admin"))
1792 != BGP_MAXMED_VALUE_DEFAULT)
1793 vty_out(vty, " %u", med_admin_val);
1794 vty_out(vty, "\n");
1795 }
1796
1797 if (yang_dnode_exists(dnode, "./max-med-onstart-up-time")) {
1798 uint32_t onstartup_val;
1799
1800 vty_out(vty, " bgp max-med on-startup %u",
1801 yang_dnode_get_uint32(dnode,
1802 "./max-med-onstart-up-time"));
1803 onstartup_val = yang_dnode_get_uint32(
1804 dnode, "./max-med-onstart-up-value");
1805 if (onstartup_val != BGP_MAXMED_VALUE_DEFAULT)
1806 vty_out(vty, " %u", onstartup_val);
1807
1808 vty_out(vty, "\n");
1809 }
1810}
1811
1812DEFUN_YANG(bgp_maxmed_admin,
1813 bgp_maxmed_admin_cmd,
1814 "bgp max-med administrative ",
1815 BGP_STR
1816 "Advertise routes with max-med\n"
1817 "Administratively applied, for an indefinite period\n")
1818{
1819 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1820 NB_OP_MODIFY, "true");
1821
1822 return nb_cli_apply_changes(vty, NULL);
1823}
1824
1825DEFUN_YANG(bgp_maxmed_admin_medv,
1826 bgp_maxmed_admin_medv_cmd,
1827 "bgp max-med administrative (0-4294967295)",
1828 BGP_STR
1829 "Advertise routes with max-med\n"
1830 "Administratively applied, for an indefinite period\n"
1831 "Max MED value to be used\n")
1832{
1833 int idx_number = 3;
1834
1835 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1836 NB_OP_MODIFY, "true");
1837
1838 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1839 NB_OP_MODIFY, argv[idx_number]->arg);
1840
1841 return nb_cli_apply_changes(vty, NULL);
1842}
1843
1844DEFUN_YANG(no_bgp_maxmed_admin,
1845 no_bgp_maxmed_admin_cmd,
1846 "no bgp max-med administrative [(0-4294967295)]",
1847 NO_STR BGP_STR
1848 "Advertise routes with max-med\n"
1849 "Administratively applied, for an indefinite period\n"
1850 "Max MED value to be used\n")
1851{
1852 nb_cli_enqueue_change(vty, "./global/med-config/enable-med-admin",
1853 NB_OP_MODIFY, "false");
1854
1855 nb_cli_enqueue_change(vty, "./global/med-config/max-med-admin",
1856 NB_OP_MODIFY, NULL);
1857
1858 return nb_cli_apply_changes(vty, NULL);
1859}
1860
1861DEFUN_YANG (bgp_maxmed_onstartup,
1862 bgp_maxmed_onstartup_cmd,
1863 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1864 BGP_STR
1865 "Advertise routes with max-med\n"
1866 "Effective on a startup\n"
1867 "Time (seconds) period for max-med\n"
1868 "Max MED value to be used\n")
1869{
1870 int idx = 0;
1871
1872 argv_find(argv, argc, "(5-86400)", &idx);
1873 nb_cli_enqueue_change(vty,
1874 "./global/med-config/max-med-onstart-up-time",
1875 NB_OP_MODIFY, argv[idx]->arg);
1876
1877 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1878 nb_cli_enqueue_change(
1879 vty, "./global/med-config/max-med-onstart-up-value",
1880 NB_OP_MODIFY, argv[idx]->arg);
1881 else
1882 nb_cli_enqueue_change(
1883 vty, "./global/med-config/max-med-onstart-up-value",
1884 NB_OP_MODIFY, NULL);
1885
1886 return nb_cli_apply_changes(vty, NULL);
1887}
1888
1889DEFUN_YANG (no_bgp_maxmed_onstartup,
1890 no_bgp_maxmed_onstartup_cmd,
1891 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1892 NO_STR BGP_STR
1893 "Advertise routes with max-med\n"
1894 "Effective on a startup\n"
1895 "Time (seconds) period for max-med\n"
1896 "Max MED value to be used\n")
1897{
1898 nb_cli_enqueue_change(vty,
1899 "./global/med-config/max-med-onstart-up-time",
1900 NB_OP_DESTROY, NULL);
1901
1902 nb_cli_enqueue_change(vty,
1903 "./global/med-config/max-med-onstart-up-value",
1904 NB_OP_MODIFY, NULL);
1905
1906 return nb_cli_apply_changes(vty, NULL);
1907}
1908
1909static int bgp_global_update_delay_config_vty(struct vty *vty,
1910 uint16_t update_delay,
1911 uint16_t establish_wait)
1912{
1913 struct listnode *node, *nnode;
1914 struct bgp *bgp;
1915 bool vrf_cfg = false;
1916
1917 /*
1918 * See if update-delay is set per-vrf and warn user to delete it
1919 * Note that we only need to check this if this is the first time
1920 * setting the global config.
1921 */
1922 if (bm->v_update_delay == BGP_UPDATE_DELAY_DEF) {
1923 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1924 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1925 vty_out(vty,
1926 "%% update-delay configuration found in vrf %s\n",
1927 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
1928 ? VRF_DEFAULT_NAME
1929 : bgp->name);
1930 vrf_cfg = true;
1931 }
1932 }
1933 }
1934
1935 if (vrf_cfg) {
1936 vty_out(vty,
1937 "%%Failed: global update-delay config not permitted\n");
1938 return CMD_WARNING;
1939 }
1940
1941 if (!establish_wait) { /* update-delay <delay> */
1942 bm->v_update_delay = update_delay;
1943 bm->v_establish_wait = bm->v_update_delay;
1944 } else {
1945 /* update-delay <delay> <establish-wait> */
1946 if (update_delay < establish_wait) {
1947 vty_out(vty,
1948 "%%Failed: update-delay less than the establish-wait!\n");
1949 return CMD_WARNING_CONFIG_FAILED;
1950 }
1951
1952 bm->v_update_delay = update_delay;
1953 bm->v_establish_wait = establish_wait;
1954 }
1955
1956 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1957 bgp->v_update_delay = bm->v_update_delay;
1958 bgp->v_establish_wait = bm->v_establish_wait;
1959 }
1960
1961 return CMD_SUCCESS;
1962}
1963
1964static int bgp_global_update_delay_deconfig_vty(struct vty *vty)
1965{
1966 struct listnode *node, *nnode;
1967 struct bgp *bgp;
1968
1969 bm->v_update_delay = BGP_UPDATE_DELAY_DEF;
1970 bm->v_establish_wait = bm->v_update_delay;
1971
1972 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
1973 bgp->v_update_delay = bm->v_update_delay;
1974 bgp->v_establish_wait = bm->v_establish_wait;
1975 }
1976
1977 return CMD_SUCCESS;
1978}
1979
1980static int bgp_update_delay_config_vty(struct vty *vty, uint16_t update_delay,
1981 uint16_t establish_wait)
1982{
1983 VTY_DECLVAR_CONTEXT(bgp, bgp);
1984
1985 /* if configured globally, per-instance config is not allowed */
1986 if (bm->v_update_delay) {
1987 vty_out(vty,
1988 "%%Failed: per-vrf update-delay config not permitted with global update-delay\n");
1989 return CMD_WARNING_CONFIG_FAILED;
1990 }
1991
1992
1993 if (!establish_wait) /* update-delay <delay> */
1994 {
1995 bgp->v_update_delay = update_delay;
1996 bgp->v_establish_wait = bgp->v_update_delay;
1997 return CMD_SUCCESS;
1998 }
1999
2000 /* update-delay <delay> <establish-wait> */
2001 if (update_delay < establish_wait) {
2002 vty_out(vty,
2003 "%%Failed: update-delay less than the establish-wait!\n");
2004 return CMD_WARNING_CONFIG_FAILED;
2005 }
2006
2007 bgp->v_update_delay = update_delay;
2008 bgp->v_establish_wait = establish_wait;
2009
2010 return CMD_SUCCESS;
2011}
2012
2013static int bgp_update_delay_deconfig_vty(struct vty *vty)
2014{
2015 VTY_DECLVAR_CONTEXT(bgp, bgp);
2016
2017 /* If configured globally, cannot remove from one bgp instance */
2018 if (bm->v_update_delay) {
2019 vty_out(vty,
2020 "%%Failed: bgp update-delay configured globally. Delete per-vrf not permitted\n");
2021 return CMD_WARNING_CONFIG_FAILED;
2022 }
2023 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
2024 bgp->v_establish_wait = bgp->v_update_delay;
2025
2026 return CMD_SUCCESS;
2027}
2028
2029void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
2030{
2031 /* If configured globally, no need to display per-instance value */
2032 if (bgp->v_update_delay != bm->v_update_delay) {
2033 vty_out(vty, " update-delay %d", bgp->v_update_delay);
2034 if (bgp->v_update_delay != bgp->v_establish_wait)
2035 vty_out(vty, " %d", bgp->v_establish_wait);
2036 vty_out(vty, "\n");
2037 }
2038}
2039
2040/* Global update-delay configuration */
2041DEFPY (bgp_global_update_delay,
2042 bgp_global_update_delay_cmd,
2043 "bgp update-delay (0-3600)$delay [(1-3600)$wait]",
2044 BGP_STR
2045 "Force initial delay for best-path and updates for all bgp instances\n"
2046 "Max delay in seconds\n"
2047 "Establish wait in seconds\n")
2048{
2049 return bgp_global_update_delay_config_vty(vty, delay, wait);
2050}
2051
2052/* Global update-delay deconfiguration */
2053DEFPY (no_bgp_global_update_delay,
2054 no_bgp_global_update_delay_cmd,
2055 "no bgp update-delay [(0-3600) [(1-3600)]]",
2056 NO_STR
2057 BGP_STR
2058 "Force initial delay for best-path and updates\n"
2059 "Max delay in seconds\n"
2060 "Establish wait in seconds\n")
2061{
2062 return bgp_global_update_delay_deconfig_vty(vty);
2063}
2064
2065/* Update-delay configuration */
2066
2067DEFPY (bgp_update_delay,
2068 bgp_update_delay_cmd,
2069 "update-delay (0-3600)$delay [(1-3600)$wait]",
2070 "Force initial delay for best-path and updates\n"
2071 "Max delay in seconds\n"
2072 "Establish wait in seconds\n")
2073{
2074 return bgp_update_delay_config_vty(vty, delay, wait);
2075}
2076
2077/* Update-delay deconfiguration */
2078DEFPY (no_bgp_update_delay,
2079 no_bgp_update_delay_cmd,
2080 "no update-delay [(0-3600) [(1-3600)]]",
2081 NO_STR
2082 "Force initial delay for best-path and updates\n"
2083 "Max delay in seconds\n"
2084 "Establish wait in seconds\n")
2085{
2086 return bgp_update_delay_deconfig_vty(vty);
2087}
2088
2089
2090int bgp_wpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2091{
2092 quanta = set ? quanta : BGP_WRITE_PACKET_MAX;
2093 atomic_store_explicit(&bgp->wpkt_quanta, quanta, memory_order_relaxed);
2094
2095 return CMD_SUCCESS;
2096}
2097
2098int bgp_rpkt_quanta_config_vty(struct bgp *bgp, uint32_t quanta, bool set)
2099{
2100 quanta = set ? quanta : BGP_READ_PACKET_MAX;
2101 atomic_store_explicit(&bgp->rpkt_quanta, quanta, memory_order_relaxed);
2102
2103 return CMD_SUCCESS;
2104}
2105
2106void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
2107{
2108 uint32_t quanta =
2109 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
2110 if (quanta != BGP_WRITE_PACKET_MAX)
2111 vty_out(vty, " write-quanta %d\n", quanta);
2112}
2113
2114void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
2115{
2116 uint32_t quanta =
2117 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
2118 if (quanta != BGP_READ_PACKET_MAX)
2119 vty_out(vty, " read-quanta %d\n", quanta);
2120}
2121
2122/* Packet quanta configuration
2123 *
2124 * XXX: The value set here controls the size of a stack buffer in the IO
2125 * thread. When changing these limits be careful to prevent stack overflow.
2126 *
2127 * Furthermore, the maximums used here should correspond to
2128 * BGP_WRITE_PACKET_MAX and BGP_READ_PACKET_MAX.
2129 */
2130DEFPY_YANG (bgp_wpkt_quanta,
2131 bgp_wpkt_quanta_cmd,
2132 "[no] write-quanta (1-64)$quanta",
2133 NO_STR
2134 "How many packets to write to peer socket per run\n"
2135 "Number of packets\n")
2136{
2137 if (!no)
2138 nb_cli_enqueue_change(
2139 vty,
2140 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2141 NB_OP_MODIFY, quanta_str);
2142 else
2143 nb_cli_enqueue_change(
2144 vty,
2145 "./global/global-neighbor-config/packet-quanta-config/wpkt-quanta",
2146 NB_OP_MODIFY, NULL);
2147
2148 return nb_cli_apply_changes(vty, NULL);
2149}
2150
2151DEFPY_YANG (bgp_rpkt_quanta,
2152 bgp_rpkt_quanta_cmd,
2153 "[no] read-quanta (1-10)$quanta",
2154 NO_STR
2155 "How many packets to read from peer socket per I/O cycle\n"
2156 "Number of packets\n")
2157{
2158 if (!no)
2159 nb_cli_enqueue_change(
2160 vty,
2161 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2162 NB_OP_MODIFY, quanta_str);
2163 else
2164 nb_cli_enqueue_change(
2165 vty,
2166 "./global/global-neighbor-config/packet-quanta-config/rpkt-quanta",
2167 NB_OP_MODIFY, NULL);
2168
2169 return nb_cli_apply_changes(vty, NULL);
2170}
2171
2172void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
2173{
2174 if (!bgp->heuristic_coalesce)
2175 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
2176}
2177
2178void cli_show_router_global_update_group_config_coalesce_time(
2179 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2180{
2181 vty_out(vty, " coalesce-time %u\n", yang_dnode_get_uint32(dnode, NULL));
2182}
2183
2184
2185DEFUN_YANG (bgp_coalesce_time,
2186 bgp_coalesce_time_cmd,
2187 "coalesce-time (0-4294967295)",
2188 "Subgroup coalesce timer\n"
2189 "Subgroup coalesce timer value (in ms)\n")
2190{
2191 int idx = 0;
2192
2193 argv_find(argv, argc, "(0-4294967295)", &idx);
2194 nb_cli_enqueue_change(
2195 vty, "./global/global-update-group-config/coalesce-time",
2196 NB_OP_MODIFY, argv[idx]->arg);
2197
2198 return nb_cli_apply_changes(vty, NULL);
2199}
2200
2201DEFUN_YANG(no_bgp_coalesce_time,
2202 no_bgp_coalesce_time_cmd,
2203 "no coalesce-time (0-4294967295)",
2204 NO_STR
2205 "Subgroup coalesce timer\n"
2206 "Subgroup coalesce timer value (in ms)\n")
2207{
2208 nb_cli_enqueue_change(
2209 vty, "./global/global-update-group-config/coalesce-time",
2210 NB_OP_MODIFY, NULL);
2211
2212 return nb_cli_apply_changes(vty, NULL);
2213}
2214
2215/* Maximum-paths configuration */
2216DEFUN_YANG (bgp_maxpaths,
2217 bgp_maxpaths_cmd,
2218 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2219 "Forward packets over multiple paths\n"
2220 "Number of paths\n")
2221{
2222 int idx_number = 1;
2223 char base_xpath[XPATH_MAXLEN];
2224 afi_t afi;
2225 safi_t safi;
2226
2227 afi = bgp_node_afi(vty);
2228 safi = bgp_node_safi(vty);
2229
2230 snprintf(
2231 base_xpath, sizeof(base_xpath),
2232 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2233 yang_afi_safi_value2identity(afi, safi),
2234 bgp_afi_safi_get_container_str(afi, safi));
2235
2236 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2237 argv[idx_number]->arg);
2238
2239 return nb_cli_apply_changes(vty, NULL);
2240}
2241
2242void cli_show_bgp_global_afi_safi_unicast_use_multiple_paths_ebgp_maximum_paths(
2243 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2244{
2245 vty_out(vty, " maximum-paths %d\n",
2246 yang_dnode_get_uint16(dnode, NULL));
2247}
2248
2249ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
2250 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2251 "Forward packets over multiple paths\n"
2252 "Number of paths\n")
2253
2254DEFUN_YANG (bgp_maxpaths_ibgp,
2255 bgp_maxpaths_ibgp_cmd,
2256 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2257 "Forward packets over multiple paths\n"
2258 "iBGP-multipath\n"
2259 "Number of paths\n")
2260{
2261 int idx_number = 2;
2262 char base_xpath[XPATH_MAXLEN];
2263 afi_t afi;
2264 safi_t safi;
2265
2266 afi = bgp_node_afi(vty);
2267 safi = bgp_node_safi(vty);
2268
2269 snprintf(
2270 base_xpath, sizeof(base_xpath),
2271 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2272 yang_afi_safi_value2identity(afi, safi),
2273 bgp_afi_safi_get_container_str(afi, safi));
2274
2275 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2276 argv[idx_number]->arg);
2277
2278 return nb_cli_apply_changes(vty, NULL);
2279}
2280
2281ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
2282 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
2283 "Forward packets over multiple paths\n"
2284 "iBGP-multipath\n"
2285 "Number of paths\n")
2286
2287DEFUN_YANG (bgp_maxpaths_ibgp_cluster,
2288 bgp_maxpaths_ibgp_cluster_cmd,
2289 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
2290 "Forward packets over multiple paths\n"
2291 "iBGP-multipath\n"
2292 "Number of paths\n"
2293 "Match the cluster length\n")
2294{
2295 int idx_number = 2;
2296 char base_xpath[XPATH_MAXLEN];
2297 afi_t afi;
2298 safi_t safi;
2299
2300 afi = bgp_node_afi(vty);
2301 safi = bgp_node_safi(vty);
2302
2303 snprintf(
2304 base_xpath, sizeof(base_xpath),
2305 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2306 yang_afi_safi_value2identity(afi, safi),
2307 bgp_afi_safi_get_container_str(afi, safi));
2308
2309 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY,
2310 argv[idx_number]->arg);
2311
2312 snprintf(
2313 base_xpath, sizeof(base_xpath),
2314 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2315 yang_afi_safi_value2identity(afi, safi),
2316 bgp_afi_safi_get_container_str(afi, safi));
2317
2318 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "true");
2319
2320 return nb_cli_apply_changes(vty, NULL);
2321}
2322
2323void cli_show_bgp_global_afi_safi_ip_unicast_use_multiple_paths_ibgp_maximum_paths(
2324 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
2325{
2326 vty_out(vty, " maximum-paths ibgp %d",
2327 yang_dnode_get_uint16(dnode, "./maximum-paths"));
2328 if (yang_dnode_get_bool(dnode, "./cluster-length-list"))
2329 vty_out(vty, " equal-cluster-length");
2330 vty_out(vty, "\n");
2331}
2332
2333ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
2334 "maximum-paths ibgp " CMD_RANGE_STR(
2335 1, MULTIPATH_NUM) " equal-cluster-length",
2336 "Forward packets over multiple paths\n"
2337 "iBGP-multipath\n"
2338 "Number of paths\n"
2339 "Match the cluster length\n")
2340
2341DEFUN_YANG (no_bgp_maxpaths,
2342 no_bgp_maxpaths_cmd,
2343 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
2344 NO_STR
2345 "Forward packets over multiple paths\n"
2346 "Number of paths\n")
2347{
2348 char base_xpath[XPATH_MAXLEN];
2349 afi_t afi;
2350 safi_t safi;
2351
2352 afi = bgp_node_afi(vty);
2353 safi = bgp_node_safi(vty);
2354
2355 snprintf(
2356 base_xpath, sizeof(base_xpath),
2357 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ebgp/maximum-paths",
2358 yang_afi_safi_value2identity(afi, safi),
2359 bgp_afi_safi_get_container_str(afi, safi));
2360
2361 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2362
2363 return nb_cli_apply_changes(vty, NULL);
2364}
2365
2366ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
2367 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
2368 "Forward packets over multiple paths\n"
2369 "Number of paths\n")
2370
2371DEFUN_YANG (no_bgp_maxpaths_ibgp,
2372 no_bgp_maxpaths_ibgp_cmd,
2373 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
2374 NO_STR
2375 "Forward packets over multiple paths\n"
2376 "iBGP-multipath\n"
2377 "Number of paths\n"
2378 "Match the cluster length\n")
2379{
2380 char base_xpath[XPATH_MAXLEN];
2381 afi_t afi;
2382 safi_t safi;
2383
2384 afi = bgp_node_afi(vty);
2385 safi = bgp_node_safi(vty);
2386
2387 snprintf(
2388 base_xpath, sizeof(base_xpath),
2389 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/maximum-paths",
2390 yang_afi_safi_value2identity(afi, safi),
2391 bgp_afi_safi_get_container_str(afi, safi));
2392
2393 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, NULL);
2394
2395 snprintf(
2396 base_xpath, sizeof(base_xpath),
2397 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/use-multiple-paths/ibgp/cluster-length-list",
2398 yang_afi_safi_value2identity(afi, safi),
2399 bgp_afi_safi_get_container_str(afi, safi));
2400
2401 nb_cli_enqueue_change(vty, base_xpath, NB_OP_MODIFY, "false");
2402
2403 return nb_cli_apply_changes(vty, NULL);
2404}
2405
2406ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
2407 "no maximum-paths ibgp [" CMD_RANGE_STR(
2408 1, MULTIPATH_NUM) " [equal-cluster-length]]",
2409 NO_STR
2410 "Forward packets over multiple paths\n"
2411 "iBGP-multipath\n"
2412 "Number of paths\n"
2413 "Match the cluster length\n")
2414
2415static void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp,
2416 afi_t afi, safi_t safi)
2417{
2418 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != multipath_num) {
2419 vty_out(vty, " maximum-paths %d\n",
2420 bgp->maxpaths[afi][safi].maxpaths_ebgp);
2421 }
2422
2423 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != multipath_num) {
2424 vty_out(vty, " maximum-paths ibgp %d",
2425 bgp->maxpaths[afi][safi].maxpaths_ibgp);
2426 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
2427 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
2428 vty_out(vty, " equal-cluster-length");
2429 vty_out(vty, "\n");
2430 }
2431}
2432
2433/* BGP timers. */
2434
2435DEFUN_YANG (bgp_timers,
2436 bgp_timers_cmd,
2437 "timers bgp (0-65535) (0-65535)",
2438 "Adjust routing timers\n"
2439 "BGP timers\n"
2440 "Keepalive interval\n"
2441 "Holdtime\n")
2442{
2443 int idx_number = 2;
2444 int idx_number_2 = 3;
2445
2446 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2447 NB_OP_MODIFY, argv[idx_number]->arg);
2448 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2449 NB_OP_MODIFY, argv[idx_number_2]->arg);
2450
2451 return nb_cli_apply_changes(vty, NULL);
2452}
2453
2454DEFUN_YANG (no_bgp_timers,
2455 no_bgp_timers_cmd,
2456 "no timers bgp [(0-65535) (0-65535)]",
2457 NO_STR
2458 "Adjust routing timers\n"
2459 "BGP timers\n"
2460 "Keepalive interval\n"
2461 "Holdtime\n")
2462{
2463 nb_cli_enqueue_change(vty, "./global/global-config-timers/keepalive",
2464 NB_OP_DESTROY, NULL);
2465 nb_cli_enqueue_change(vty, "./global/global-config-timers/hold-time",
2466 NB_OP_DESTROY, NULL);
2467
2468 return nb_cli_apply_changes(vty, NULL);
2469}
2470
2471void cli_show_router_bgp_route_reflector(struct vty *vty,
2472 struct lyd_node *dnode,
2473 bool show_defaults)
2474{
2475 if (yang_dnode_get_bool(dnode, "./no-client-reflect"))
2476 vty_out(vty, " no bgp client-to-client reflection\n");
2477
2478 if (yang_dnode_get_bool(dnode, "./allow-outbound-policy"))
2479 vty_out(vty, " bgp route-reflector allow-outbound-policy\n");
2480
2481 if (yang_dnode_exists(dnode, "./route-reflector-cluster-id"))
2482 vty_out(vty, " bgp cluster-id %s\n",
2483 yang_dnode_get_string(dnode,
2484 "./route-reflector-cluster-id"));
2485}
2486
2487DEFUN_YANG(bgp_client_to_client_reflection,
2488 bgp_client_to_client_reflection_cmd,
2489 "bgp client-to-client reflection",
2490 "BGP specific commands\n"
2491 "Configure client to client route reflection\n"
2492 "reflection of routes allowed\n")
2493{
2494 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2495 NB_OP_MODIFY, "false");
2496
2497 return nb_cli_apply_changes(vty, NULL);
2498}
2499
2500DEFUN_YANG(no_bgp_client_to_client_reflection,
2501 no_bgp_client_to_client_reflection_cmd,
2502 "no bgp client-to-client reflection",
2503 NO_STR
2504 "BGP specific commands\n"
2505 "Configure client to client route reflection\n"
2506 "reflection of routes allowed\n")
2507{
2508 nb_cli_enqueue_change(vty, "./global/route-reflector/no-client-reflect",
2509 NB_OP_MODIFY, "true");
2510
2511 return nb_cli_apply_changes(vty, NULL);
2512}
2513
2514void cli_show_router_bgp_route_selection(struct vty *vty,
2515 struct lyd_node *dnode,
2516 bool show_defaults)
2517{
2518
2519 if (yang_dnode_get_bool(dnode, "./always-compare-med"))
2520 vty_out(vty, " bgp always-compare-med\n");
2521
2522 if (yang_dnode_get_bool(dnode, "./ignore-as-path-length"))
2523 vty_out(vty, " bgp bestpath as-path ignore\n");
2524
2525 if (yang_dnode_get_bool(dnode, "./aspath-confed"))
2526 vty_out(vty, " bgp bestpath as-path confed\n");
2527
2528 if (yang_dnode_get_bool(dnode, "./external-compare-router-id"))
2529 vty_out(vty, " bgp bestpath compare-routerid\n");
2530
2531 if (yang_dnode_get_bool(dnode, "./allow-multiple-as")) {
2532 if (yang_dnode_get_bool(dnode, "./multi-path-as-set"))
2533 vty_out(vty,
2534 " bgp bestpath as-path multipath-relax as-set\n");
2535 else
2536 vty_out(vty, " bgp bestpath as-path multipath-relax\n");
2537 }
2538
2539 if (yang_dnode_get_bool(dnode, "./deterministic-med"))
2540 vty_out(vty, " bgp deterministic-med\n");
2541
2542 if (yang_dnode_get_bool(dnode, "./confed-med")
2543 || yang_dnode_get_bool(dnode, "./missing-as-worst-med")) {
2544 vty_out(vty, " bgp bestpath med");
2545 if (yang_dnode_get_bool(dnode, "./confed-med"))
2546 vty_out(vty, " confed");
2547 if (yang_dnode_get_bool(dnode, "./missing-as-worst-med"))
2548 vty_out(vty, " missing-as-worst");
2549 vty_out(vty, "\n");
2550 }
2551}
2552
2553/* "bgp always-compare-med" configuration. */
2554DEFUN_YANG(bgp_always_compare_med,
2555 bgp_always_compare_med_cmd,
2556 "bgp always-compare-med",
2557 "BGP specific commands\n"
2558 "Allow comparing MED from different neighbors\n")
2559{
2560 nb_cli_enqueue_change(
2561 vty, "./global/route-selection-options/always-compare-med",
2562 NB_OP_MODIFY, "true");
2563
2564 return nb_cli_apply_changes(vty, NULL);
2565}
2566
2567DEFUN_YANG(no_bgp_always_compare_med,
2568 no_bgp_always_compare_med_cmd,
2569 "no bgp always-compare-med",
2570 NO_STR
2571 "BGP specific commands\n"
2572 "Allow comparing MED from different neighbors\n")
2573{
2574 nb_cli_enqueue_change(
2575 vty, "./global/route-selection-options/always-compare-med",
2576 NB_OP_MODIFY, "false");
2577
2578 return nb_cli_apply_changes(vty, NULL);
2579}
2580
2581DEFUN_YANG(bgp_suppress_duplicates,
2582 bgp_suppress_duplicates_cmd,
2583 "bgp suppress-duplicates",
2584 "BGP specific commands\n"
2585 "Suppress duplicate updates if the route actually not changed\n")
2586{
2587 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2588 NB_OP_MODIFY, "true");
2589 return nb_cli_apply_changes(vty, NULL);
2590}
2591
2592DEFUN_YANG(no_bgp_suppress_duplicates,
2593 no_bgp_suppress_duplicates_cmd,
2594 "no bgp suppress-duplicates",
2595 NO_STR
2596 "BGP specific commands\n"
2597 "Suppress duplicate updates if the route actually not changed\n")
2598{
2599 nb_cli_enqueue_change(vty, "./global/suppress-duplicates",
2600 NB_OP_MODIFY, "false");
2601 return nb_cli_apply_changes(vty, NULL);
2602}
2603
2604void cli_show_router_bgp_suppress_duplicates(struct vty *vty,
2605 struct lyd_node *dnode,
2606 bool show_defaults)
2607{
2608 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SUPPRESS_DUPLICATES)
2609 vty_out(vty, " bgp suppress-duplicates\n");
2610}
2611
2612DEFUN_YANG(bgp_ebgp_requires_policy,
2613 bgp_ebgp_requires_policy_cmd,
2614 "bgp ebgp-requires-policy",
2615 "BGP specific commands\n"
2616 "Require in and out policy for eBGP peers (RFC8212)\n")
2617{
2618 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2619 NB_OP_MODIFY, "true");
2620 return nb_cli_apply_changes(vty, NULL);
2621}
2622
2623DEFUN_YANG(no_bgp_ebgp_requires_policy,
2624 no_bgp_ebgp_requires_policy_cmd,
2625 "no bgp ebgp-requires-policy",
2626 NO_STR
2627 "BGP specific commands\n"
2628 "Require in and out policy for eBGP peers (RFC8212)\n")
2629{
2630 nb_cli_enqueue_change(vty, "./global/ebgp-requires-policy",
2631 NB_OP_MODIFY, "false");
2632 return nb_cli_apply_changes(vty, NULL);
2633}
2634
2635void cli_show_router_bgp_ebgp_requires_policy(struct vty *vty,
2636 struct lyd_node *dnode,
2637 bool show_defaults)
2638{
2639 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_EBGP_REQUIRES_POLICY)
2640 vty_out(vty, " bgp ebgp-requires-policy\n");
2641}
2642
2643DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd,
2644 "bgp reject-as-sets",
2645 "BGP specific commands\n"
2646 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2647{
2648 VTY_DECLVAR_CONTEXT(bgp, bgp);
2649 struct listnode *node, *nnode;
2650 struct peer *peer;
2651
2652 bgp->reject_as_sets = true;
2653
2654 /* Reset existing BGP sessions to reject routes
2655 * with aspath containing AS_SET or AS_CONFED_SET.
2656 */
2657 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2658 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2659 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2660 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2661 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2662 }
2663 }
2664
2665 return CMD_SUCCESS;
2666}
2667
2668DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd,
2669 "no bgp reject-as-sets",
2670 NO_STR
2671 "BGP specific commands\n"
2672 "Reject routes with AS_SET or AS_CONFED_SET flag\n")
2673{
2674 VTY_DECLVAR_CONTEXT(bgp, bgp);
2675 struct listnode *node, *nnode;
2676 struct peer *peer;
2677
2678 bgp->reject_as_sets = false;
2679
2680 /* Reset existing BGP sessions to reject routes
2681 * with aspath containing AS_SET or AS_CONFED_SET.
2682 */
2683 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
2684 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2685 peer->last_reset = PEER_DOWN_AS_SETS_REJECT;
2686 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2687 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2688 }
2689 }
2690
2691 return CMD_SUCCESS;
2692}
2693
2694/* "bgp deterministic-med" configuration. */
2695DEFUN_YANG (bgp_deterministic_med,
2696 bgp_deterministic_med_cmd,
2697 "bgp deterministic-med",
2698 "BGP specific commands\n"
2699 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2700{
2701 nb_cli_enqueue_change(
2702 vty, "./global/route-selection-options/deterministic-med",
2703 NB_OP_MODIFY, "true");
2704
2705 return nb_cli_apply_changes(vty, NULL);
2706}
2707
2708DEFUN_YANG (no_bgp_deterministic_med,
2709 no_bgp_deterministic_med_cmd,
2710 "no bgp deterministic-med",
2711 NO_STR
2712 "BGP specific commands\n"
2713 "Pick the best-MED path among paths advertised from the neighboring AS\n")
2714{
2715 nb_cli_enqueue_change(
2716 vty, "./global/route-selection-options/deterministic-med",
2717 NB_OP_MODIFY, "false");
2718
2719 return nb_cli_apply_changes(vty, NULL);
2720}
2721
2722/* "bgp graceful-restart mode" configuration. */
2723DEFUN (bgp_graceful_restart,
2724 bgp_graceful_restart_cmd,
2725 "bgp graceful-restart",
2726 "BGP specific commands\n"
2727 GR_CMD
2728 )
2729{
2730 int ret = BGP_GR_FAILURE;
2731
2732 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2733 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : START ");
2734
2735 VTY_DECLVAR_CONTEXT(bgp, bgp);
2736
2737 ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);
2738
2739 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2740 ret);
2741
2742 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2743 zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
2744 vty_out(vty,
2745 "Graceful restart configuration changed, reset all peers to take effect\n");
2746 return bgp_vty_return(vty, ret);
2747}
2748
2749DEFUN (no_bgp_graceful_restart,
2750 no_bgp_graceful_restart_cmd,
2751 "no bgp graceful-restart",
2752 NO_STR
2753 "BGP specific commands\n"
2754 NO_GR_CMD
2755 )
2756{
2757 VTY_DECLVAR_CONTEXT(bgp, bgp);
2758
2759 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2760 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : START ");
2761
2762 int ret = BGP_GR_FAILURE;
2763
2764 ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);
2765
2766 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2767 ret);
2768
2769 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2770 zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
2771 vty_out(vty,
2772 "Graceful restart configuration changed, reset all peers to take effect\n");
2773
2774 return bgp_vty_return(vty, ret);
2775}
2776
2777DEFUN (bgp_graceful_restart_stalepath_time,
2778 bgp_graceful_restart_stalepath_time_cmd,
2779 "bgp graceful-restart stalepath-time (1-4095)",
2780 "BGP specific commands\n"
2781 "Graceful restart capability parameters\n"
2782 "Set the max time to hold onto restarting peer's stale paths\n"
2783 "Delay value (seconds)\n")
2784{
2785 VTY_DECLVAR_CONTEXT(bgp, bgp);
2786 int idx_number = 3;
2787 uint32_t stalepath;
2788
2789 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
2790 bgp->stalepath_time = stalepath;
2791 return CMD_SUCCESS;
2792}
2793
2794DEFUN (bgp_graceful_restart_restart_time,
2795 bgp_graceful_restart_restart_time_cmd,
2796 "bgp graceful-restart restart-time (1-4095)",
2797 "BGP specific commands\n"
2798 "Graceful restart capability parameters\n"
2799 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2800 "Delay value (seconds)\n")
2801{
2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
2803 int idx_number = 3;
2804 uint32_t restart;
2805
2806 restart = strtoul(argv[idx_number]->arg, NULL, 10);
2807 bgp->restart_time = restart;
2808 return CMD_SUCCESS;
2809}
2810
2811DEFUN (bgp_graceful_restart_select_defer_time,
2812 bgp_graceful_restart_select_defer_time_cmd,
2813 "bgp graceful-restart select-defer-time (0-3600)",
2814 "BGP specific commands\n"
2815 "Graceful restart capability parameters\n"
2816 "Set the time to defer the BGP route selection after restart\n"
2817 "Delay value (seconds, 0 - disable)\n")
2818{
2819 VTY_DECLVAR_CONTEXT(bgp, bgp);
2820 int idx_number = 3;
2821 uint32_t defer_time;
2822
2823 defer_time = strtoul(argv[idx_number]->arg, NULL, 10);
2824 bgp->select_defer_time = defer_time;
2825 if (defer_time == 0)
2826 SET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2827 else
2828 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2829
2830 return CMD_SUCCESS;
2831}
2832
2833DEFUN (no_bgp_graceful_restart_stalepath_time,
2834 no_bgp_graceful_restart_stalepath_time_cmd,
2835 "no bgp graceful-restart stalepath-time [(1-4095)]",
2836 NO_STR
2837 "BGP specific commands\n"
2838 "Graceful restart capability parameters\n"
2839 "Set the max time to hold onto restarting peer's stale paths\n"
2840 "Delay value (seconds)\n")
2841{
2842 VTY_DECLVAR_CONTEXT(bgp, bgp);
2843
2844 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2845 return CMD_SUCCESS;
2846}
2847
2848DEFUN (no_bgp_graceful_restart_restart_time,
2849 no_bgp_graceful_restart_restart_time_cmd,
2850 "no bgp graceful-restart restart-time [(1-4095)]",
2851 NO_STR
2852 "BGP specific commands\n"
2853 "Graceful restart capability parameters\n"
2854 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2855 "Delay value (seconds)\n")
2856{
2857 VTY_DECLVAR_CONTEXT(bgp, bgp);
2858
2859 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2860 return CMD_SUCCESS;
2861}
2862
2863DEFUN (no_bgp_graceful_restart_select_defer_time,
2864 no_bgp_graceful_restart_select_defer_time_cmd,
2865 "no bgp graceful-restart select-defer-time [(0-3600)]",
2866 NO_STR
2867 "BGP specific commands\n"
2868 "Graceful restart capability parameters\n"
2869 "Set the time to defer the BGP route selection after restart\n"
2870 "Delay value (seconds)\n")
2871{
2872 VTY_DECLVAR_CONTEXT(bgp, bgp);
2873
2874 bgp->select_defer_time = BGP_DEFAULT_SELECT_DEFERRAL_TIME;
2875 UNSET_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE);
2876
2877 return CMD_SUCCESS;
2878}
2879
2880DEFUN (bgp_graceful_restart_preserve_fw,
2881 bgp_graceful_restart_preserve_fw_cmd,
2882 "bgp graceful-restart preserve-fw-state",
2883 "BGP specific commands\n"
2884 "Graceful restart capability parameters\n"
2885 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2886{
2887 VTY_DECLVAR_CONTEXT(bgp, bgp);
2888 SET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2889 return CMD_SUCCESS;
2890}
2891
2892DEFUN (no_bgp_graceful_restart_preserve_fw,
2893 no_bgp_graceful_restart_preserve_fw_cmd,
2894 "no bgp graceful-restart preserve-fw-state",
2895 NO_STR
2896 "BGP specific commands\n"
2897 "Graceful restart capability parameters\n"
2898 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2899{
2900 VTY_DECLVAR_CONTEXT(bgp, bgp);
2901 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD);
2902 return CMD_SUCCESS;
2903}
2904
2905DEFUN (bgp_graceful_restart_disable,
2906 bgp_graceful_restart_disable_cmd,
2907 "bgp graceful-restart-disable",
2908 "BGP specific commands\n"
2909 GR_DISABLE)
2910{
2911 int ret = BGP_GR_FAILURE;
2912
2913 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2914 zlog_debug(
2915 "[BGP_GR] bgp_graceful_restart_disable_cmd : START ");
2916
2917 VTY_DECLVAR_CONTEXT(bgp, bgp);
2918
2919 ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
2920
2921 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
2922 bgp->peer, ret);
2923
2924 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2925 zlog_debug(
2926 "[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
2927 vty_out(vty,
2928 "Graceful restart configuration changed, reset all peers to take effect\n");
2929
2930 return bgp_vty_return(vty, ret);
2931}
2932
2933DEFUN (no_bgp_graceful_restart_disable,
2934 no_bgp_graceful_restart_disable_cmd,
2935 "no bgp graceful-restart-disable",
2936 NO_STR
2937 "BGP specific commands\n"
2938 NO_GR_DISABLE
2939 )
2940{
2941 VTY_DECLVAR_CONTEXT(bgp, bgp);
2942
2943 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2944 zlog_debug(
2945 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : START ");
2946
2947 int ret = BGP_GR_FAILURE;
2948
2949 ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);
2950
2951 VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
2952 ret);
2953
2954 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2955 zlog_debug(
2956 "[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
2957 vty_out(vty,
2958 "Graceful restart configuration changed, reset all peers to take effect\n");
2959
2960 return bgp_vty_return(vty, ret);
2961}
2962
2963DEFUN (bgp_neighbor_graceful_restart_set,
2964 bgp_neighbor_graceful_restart_set_cmd,
2965 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
2966 NEIGHBOR_STR
2967 NEIGHBOR_ADDR_STR2
2968 GR_NEIGHBOR_CMD
2969 )
2970{
2971 int idx_peer = 1;
2972 struct peer *peer;
2973 int ret = BGP_GR_FAILURE;
2974
2975 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
2976
2977 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2978 zlog_debug(
2979 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : START ");
2980
2981 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2982 if (!peer)
2983 return CMD_WARNING_CONFIG_FAILED;
2984
2985 ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);
2986
2987 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
2988 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
2989
2990 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
2991 zlog_debug(
2992 "[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
2993 vty_out(vty,
2994 "Graceful restart configuration changed, reset this peer to take effect\n");
2995
2996 return bgp_vty_return(vty, ret);
2997}
2998
2999DEFUN (no_bgp_neighbor_graceful_restart,
3000 no_bgp_neighbor_graceful_restart_set_cmd,
3001 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart",
3002 NO_STR
3003 NEIGHBOR_STR
3004 NEIGHBOR_ADDR_STR2
3005 NO_GR_NEIGHBOR_CMD
3006 )
3007{
3008 int idx_peer = 2;
3009 int ret = BGP_GR_FAILURE;
3010 struct peer *peer;
3011
3012 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3013
3014 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3015 if (!peer)
3016 return CMD_WARNING_CONFIG_FAILED;
3017
3018 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3019 zlog_debug(
3020 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");
3021
3022 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);
3023
3024 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3025 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3026
3027 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3028 zlog_debug(
3029 "[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
3030 vty_out(vty,
3031 "Graceful restart configuration changed, reset this peer to take effect\n");
3032
3033 return bgp_vty_return(vty, ret);
3034}
3035
3036DEFUN (bgp_neighbor_graceful_restart_helper_set,
3037 bgp_neighbor_graceful_restart_helper_set_cmd,
3038 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3039 NEIGHBOR_STR
3040 NEIGHBOR_ADDR_STR2
3041 GR_NEIGHBOR_HELPER_CMD
3042 )
3043{
3044 int idx_peer = 1;
3045 struct peer *peer;
3046 int ret = BGP_GR_FAILURE;
3047
3048 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3049
3050 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3051 zlog_debug(
3052 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3053
3054 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3055
3056 if (!peer)
3057 return CMD_WARNING_CONFIG_FAILED;
3058
3059
3060 ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);
3061
3062 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3063 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3064
3065 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3066 zlog_debug(
3067 "[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3068 vty_out(vty,
3069 "Graceful restart configuration changed, reset this peer to take effect\n");
3070
3071 return bgp_vty_return(vty, ret);
3072}
3073
3074DEFUN (no_bgp_neighbor_graceful_restart_helper,
3075 no_bgp_neighbor_graceful_restart_helper_set_cmd,
3076 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-helper",
3077 NO_STR
3078 NEIGHBOR_STR
3079 NEIGHBOR_ADDR_STR2
3080 NO_GR_NEIGHBOR_HELPER_CMD
3081 )
3082{
3083 int idx_peer = 2;
3084 int ret = BGP_GR_FAILURE;
3085 struct peer *peer;
3086
3087 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3088
3089 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3090 if (!peer)
3091 return CMD_WARNING_CONFIG_FAILED;
3092
3093 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3094 zlog_debug(
3095 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");
3096
3097 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);
3098
3099 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3100 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3101
3102 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3103 zlog_debug(
3104 "[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
3105 vty_out(vty,
3106 "Graceful restart configuration changed, reset this peer to take effect\n");
3107
3108 return bgp_vty_return(vty, ret);
3109}
3110
3111DEFUN (bgp_neighbor_graceful_restart_disable_set,
3112 bgp_neighbor_graceful_restart_disable_set_cmd,
3113 "neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3114 NEIGHBOR_STR
3115 NEIGHBOR_ADDR_STR2
3116 GR_NEIGHBOR_DISABLE_CMD
3117 )
3118{
3119 int idx_peer = 1;
3120 struct peer *peer;
3121 int ret = BGP_GR_FAILURE;
3122
3123 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3124
3125 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3126 zlog_debug(
3127 "[BGP_GR] bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3128
3129 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3130 if (!peer)
3131 return CMD_WARNING_CONFIG_FAILED;
3132
3133 ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
3134
3135 if (peer->bgp->t_startup)
3136 bgp_peer_gr_flags_update(peer);
3137
3138 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3139 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3140
3141 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3142 zlog_debug(
3143 "[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3144 vty_out(vty,
3145 "Graceful restart configuration changed, reset this peer to take effect\n");
3146
3147 return bgp_vty_return(vty, ret);
3148}
3149
3150DEFUN (no_bgp_neighbor_graceful_restart_disable,
3151 no_bgp_neighbor_graceful_restart_disable_set_cmd,
3152 "no neighbor <A.B.C.D|X:X::X:X|WORD> graceful-restart-disable",
3153 NO_STR
3154 NEIGHBOR_STR
3155 NEIGHBOR_ADDR_STR2
3156 NO_GR_NEIGHBOR_DISABLE_CMD
3157 )
3158{
3159 int idx_peer = 2;
3160 int ret = BGP_GR_FAILURE;
3161 struct peer *peer;
3162
3163 VTY_BGP_GR_DEFINE_LOOP_VARIABLE;
3164
3165 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3166 if (!peer)
3167 return CMD_WARNING_CONFIG_FAILED;
3168
3169 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3170 zlog_debug(
3171 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");
3172
3173 ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);
3174
3175 VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
3176 VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
3177
3178 if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
3179 zlog_debug(
3180 "[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
3181 vty_out(vty,
3182 "Graceful restart configuration changed, reset this peer to take effect\n");
3183
3184 return bgp_vty_return(vty, ret);
3185}
3186
3187DEFUN_HIDDEN (bgp_graceful_restart_disable_eor,
3188 bgp_graceful_restart_disable_eor_cmd,
3189 "bgp graceful-restart disable-eor",
3190 "BGP specific commands\n"
3191 "Graceful restart configuration parameters\n"
3192 "Disable EOR Check\n")
3193{
3194 VTY_DECLVAR_CONTEXT(bgp, bgp);
3195 SET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3196
3197 return CMD_SUCCESS;
3198}
3199
3200DEFUN_HIDDEN (no_bgp_graceful_restart_disable_eor,
3201 no_bgp_graceful_restart_disable_eor_cmd,
3202 "no bgp graceful-restart disable-eor",
3203 NO_STR
3204 "BGP specific commands\n"
3205 "Graceful restart configuration parameters\n"
3206 "Disable EOR Check\n")
3207{
3208 VTY_DECLVAR_CONTEXT(bgp, bgp);
3209 UNSET_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR);
3210
3211 return CMD_SUCCESS;
3212}
3213
3214DEFUN (bgp_graceful_restart_rib_stale_time,
3215 bgp_graceful_restart_rib_stale_time_cmd,
3216 "bgp graceful-restart rib-stale-time (1-3600)",
3217 "BGP specific commands\n"
3218 "Graceful restart configuration parameters\n"
3219 "Specify the stale route removal timer in rib\n"
3220 "Delay value (seconds)\n")
3221{
3222 VTY_DECLVAR_CONTEXT(bgp, bgp);
3223 int idx_number = 3;
3224 uint32_t stale_time;
3225
3226 stale_time = strtoul(argv[idx_number]->arg, NULL, 10);
3227 bgp->rib_stale_time = stale_time;
3228 /* Send the stale timer update message to RIB */
3229 if (bgp_zebra_stale_timer_update(bgp))
3230 return CMD_WARNING;
3231
3232 return CMD_SUCCESS;
3233}
3234
3235DEFUN (no_bgp_graceful_restart_rib_stale_time,
3236 no_bgp_graceful_restart_rib_stale_time_cmd,
3237 "no bgp graceful-restart rib-stale-time [(1-3600)]",
3238 NO_STR
3239 "BGP specific commands\n"
3240 "Graceful restart configuration parameters\n"
3241 "Specify the stale route removal timer in rib\n"
3242 "Delay value (seconds)\n")
3243{
3244 VTY_DECLVAR_CONTEXT(bgp, bgp);
3245
3246 bgp->rib_stale_time = BGP_DEFAULT_RIB_STALE_TIME;
3247 /* Send the stale timer update message to RIB */
3248 if (bgp_zebra_stale_timer_update(bgp))
3249 return CMD_WARNING;
3250
3251 return CMD_SUCCESS;
3252}
3253
3254static inline int bgp_initiate_graceful_shut_unshut(struct bgp *bgp,
3255 char *errmsg,
3256 size_t errmsg_len)
3257{
3258 bgp_static_redo_import_check(bgp);
3259 bgp_redistribute_redo(bgp);
3260 if (bgp_clear_star_soft_out(bgp->name, errmsg, errmsg_len) < 0)
3261 return -1;
3262 if (bgp_clear_star_soft_in(bgp->name, errmsg, errmsg_len) < 0)
3263 return -1;
3264
3265 return 0;
3266}
3267
3268static int bgp_global_graceful_shutdown_config_vty(struct vty *vty)
3269{
3270 struct listnode *node, *nnode;
3271 struct bgp *bgp;
3272 bool vrf_cfg = false;
3273 char errmsg[BUFSIZ] = {'\0'};
3274
3275 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3276 return CMD_SUCCESS;
3277
3278 /* See if graceful-shutdown is set per-vrf and warn user to delete */
3279 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3280 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
3281 vty_out(vty,
3282 "%% graceful-shutdown configuration found in vrf %s\n",
3283 bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ?
3284 VRF_DEFAULT_NAME : bgp->name);
3285 vrf_cfg = true;
3286 }
3287 }
3288
3289 if (vrf_cfg) {
3290 vty_out(vty,
3291 "%%Failed: global graceful-shutdown not permitted\n");
3292 return CMD_WARNING;
3293 }
3294
3295 /* Set flag globally */
3296 SET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3297
3298 /* Initiate processing for all BGP instances. */
3299 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3300 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3301 sizeof(errmsg))
3302 < 0)
3303 if (strlen(errmsg))
3304 vty_out(vty, "%s\n", errmsg);
3305 }
3306
3307 return CMD_SUCCESS;
3308}
3309
3310static int bgp_global_graceful_shutdown_deconfig_vty(struct vty *vty)
3311{
3312 struct listnode *node, *nnode;
3313 struct bgp *bgp;
3314 char errmsg[BUFSIZ] = {'\0'};
3315
3316 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
3317 return CMD_SUCCESS;
3318
3319 /* Unset flag globally */
3320 UNSET_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN);
3321
3322 /* Initiate processing for all BGP instances. */
3323 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
3324 if (bgp_initiate_graceful_shut_unshut(bgp, errmsg,
3325 sizeof(errmsg))
3326 < 0)
3327 if (strlen(errmsg))
3328 vty_out(vty, "%s\n", errmsg);
3329 }
3330
3331 return CMD_SUCCESS;
3332}
3333
3334/* "bgp graceful-shutdown" configuration */
3335DEFUN (bgp_graceful_shutdown,
3336 bgp_graceful_shutdown_cmd,
3337 "bgp graceful-shutdown",
3338 BGP_STR
3339 "Graceful shutdown parameters\n")
3340{
3341 if (vty->node == CONFIG_NODE)
3342 return bgp_global_graceful_shutdown_config_vty(vty);
3343
3344 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3345 NB_OP_MODIFY, "true");
3346
3347 return nb_cli_apply_changes(vty, NULL);
3348}
3349
3350DEFUN_YANG (no_bgp_graceful_shutdown,
3351 no_bgp_graceful_shutdown_cmd,
3352 "no bgp graceful-shutdown",
3353 NO_STR
3354 BGP_STR
3355 "Graceful shutdown parameters\n")
3356{
3357 if (vty->node == CONFIG_NODE)
3358 return bgp_global_graceful_shutdown_deconfig_vty(vty);
3359
3360 nb_cli_enqueue_change(vty, "./global/graceful-shutdown/enable",
3361 NB_OP_MODIFY, "false");
3362
3363 return nb_cli_apply_changes(vty, NULL);
3364}
3365
3366void cli_show_router_bgp_graceful_shutdown(struct vty *vty,
3367 struct lyd_node *dnode,
3368 bool show_defaults)
3369{
3370 if (yang_dnode_get_bool(dnode, NULL))
3371 vty_out(vty, " bgp graceful-shutdown\n");
3372}
3373
3374/* "bgp fast-external-failover" configuration. */
3375DEFUN_YANG (bgp_fast_external_failover,
3376 bgp_fast_external_failover_cmd,
3377 "bgp fast-external-failover",
3378 BGP_STR
3379 "Immediately reset session if a link to a directly connected external peer goes down\n")
3380{
3381 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3382 NB_OP_MODIFY, "false");
3383
3384 return nb_cli_apply_changes(vty, NULL);
3385}
3386
3387DEFUN_YANG (no_bgp_fast_external_failover,
3388 no_bgp_fast_external_failover_cmd,
3389 "no bgp fast-external-failover",
3390 NO_STR
3391 BGP_STR
3392 "Immediately reset session if a link to a directly connected external peer goes down\n")
3393{
3394 nb_cli_enqueue_change(vty, "./global/fast-external-failover",
3395 NB_OP_MODIFY, "true");
3396
3397 return nb_cli_apply_changes(vty, NULL);
3398}
3399
3400void cli_show_router_bgp_fast_external_failover(struct vty *vty,
3401 struct lyd_node *dnode,
3402 bool show_defaults)
3403{
3404 if (!yang_dnode_get_bool(dnode, NULL))
3405 vty_out(vty, " no bgp fast-external-failover\n");
3406}
3407
3408/* "bgp bestpath compare-routerid" configuration. */
3409DEFUN_YANG(bgp_bestpath_compare_router_id,
3410 bgp_bestpath_compare_router_id_cmd,
3411 "bgp bestpath compare-routerid",
3412 "BGP specific commands\n"
3413 "Change the default bestpath selection\n"
3414 "Compare router-id for identical EBGP paths\n")
3415{
3416 nb_cli_enqueue_change(
3417 vty,
3418 "./global/route-selection-options/external-compare-router-id",
3419 NB_OP_MODIFY, "true");
3420
3421 return nb_cli_apply_changes(vty, NULL);
3422}
3423
3424DEFUN_YANG(no_bgp_bestpath_compare_router_id,
3425 no_bgp_bestpath_compare_router_id_cmd,
3426 "no bgp bestpath compare-routerid",
3427 NO_STR
3428 "BGP specific commands\n"
3429 "Change the default bestpath selection\n"
3430 "Compare router-id for identical EBGP paths\n")
3431{
3432 nb_cli_enqueue_change(
3433 vty,
3434 "./global/route-selection-options/external-compare-router-id",
3435 NB_OP_MODIFY, "false");
3436
3437 return nb_cli_apply_changes(vty, NULL);
3438}
3439
3440/* "bgp bestpath as-path ignore" configuration. */
3441DEFUN_YANG(bgp_bestpath_aspath_ignore,
3442 bgp_bestpath_aspath_ignore_cmd,
3443 "bgp bestpath as-path ignore",
3444 "BGP specific commands\n"
3445 "Change the default bestpath selection\n"
3446 "AS-path attribute\n"
3447 "Ignore as-path length in selecting a route\n")
3448{
3449 nb_cli_enqueue_change(
3450 vty, "./global/route-selection-options/ignore-as-path-length",
3451 NB_OP_MODIFY, "true");
3452
3453 return nb_cli_apply_changes(vty, NULL);
3454}
3455
3456DEFUN_YANG(no_bgp_bestpath_aspath_ignore,
3457 no_bgp_bestpath_aspath_ignore_cmd,
3458 "no bgp bestpath as-path ignore",
3459 NO_STR
3460 "BGP specific commands\n"
3461 "Change the default bestpath selection\n"
3462 "AS-path attribute\n"
3463 "Ignore as-path length in selecting a route\n")
3464{
3465 nb_cli_enqueue_change(
3466 vty, "./global/route-selection-options/ignore-as-path-length",
3467 NB_OP_MODIFY, "false");
3468
3469 return nb_cli_apply_changes(vty, NULL);
3470}
3471
3472/* "bgp bestpath as-path confed" configuration. */
3473DEFUN_YANG (bgp_bestpath_aspath_confed,
3474 bgp_bestpath_aspath_confed_cmd,
3475 "bgp bestpath as-path confed",
3476 "BGP specific commands\n"
3477 "Change the default bestpath selection\n"
3478 "AS-path attribute\n"
3479 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3480{
3481 nb_cli_enqueue_change(vty,
3482 "./global/route-selection-options/aspath-confed",
3483 NB_OP_MODIFY, "true");
3484
3485 return nb_cli_apply_changes(vty, NULL);
3486}
3487
3488DEFUN_YANG (no_bgp_bestpath_aspath_confed,
3489 no_bgp_bestpath_aspath_confed_cmd,
3490 "no bgp bestpath as-path confed",
3491 NO_STR
3492 "BGP specific commands\n"
3493 "Change the default bestpath selection\n"
3494 "AS-path attribute\n"
3495 "Compare path lengths including confederation sets & sequences in selecting a route\n")
3496{
3497 nb_cli_enqueue_change(vty,
3498 "./global/route-selection-options/aspath-confed",
3499 NB_OP_MODIFY, "false");
3500
3501 return nb_cli_apply_changes(vty, NULL);
3502}
3503
3504/* "bgp bestpath as-path multipath-relax" configuration. */
3505DEFUN_YANG (bgp_bestpath_aspath_multipath_relax,
3506 bgp_bestpath_aspath_multipath_relax_cmd,
3507 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3508 "BGP specific commands\n"
3509 "Change the default bestpath selection\n"
3510 "AS-path attribute\n"
3511 "Allow load sharing across routes that have different AS paths (but same length)\n"
3512 "Generate an AS_SET\n"
3513 "Do not generate an AS_SET\n")
3514{
3515 int idx = 0;
3516
3517 nb_cli_enqueue_change(
3518 vty, "./global/route-selection-options/allow-multiple-as",
3519 NB_OP_MODIFY, "true");
3520 if (argv_find(argv, argc, "as-set", &idx))
3521 nb_cli_enqueue_change(
3522 vty,
3523 "./global/route-selection-options/multi-path-as-set",
3524 NB_OP_MODIFY, "true");
3525 else
3526 nb_cli_enqueue_change(
3527 vty,
3528 "./global/route-selection-options/multi-path-as-set",
3529 NB_OP_MODIFY, "false");
3530
3531 return nb_cli_apply_changes(vty, NULL);
3532}
3533
3534DEFUN_YANG (no_bgp_bestpath_aspath_multipath_relax,
3535 no_bgp_bestpath_aspath_multipath_relax_cmd,
3536 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
3537 NO_STR
3538 "BGP specific commands\n"
3539 "Change the default bestpath selection\n"
3540 "AS-path attribute\n"
3541 "Allow load sharing across routes that have different AS paths (but same length)\n"
3542 "Generate an AS_SET\n"
3543 "Do not generate an AS_SET\n")
3544{
3545 nb_cli_enqueue_change(
3546 vty, "./global/route-selection-options/allow-multiple-as",
3547 NB_OP_MODIFY, "false");
3548 nb_cli_enqueue_change(
3549 vty, "./global/route-selection-options/multi-path-as-set",
3550 NB_OP_MODIFY, "false");
3551
3552 return nb_cli_apply_changes(vty, NULL);
3553}
3554
3555/* "bgp log-neighbor-changes" configuration. */
3556DEFUN_YANG(bgp_log_neighbor_changes,
3557 bgp_log_neighbor_changes_cmd,
3558 "bgp log-neighbor-changes",
3559 "BGP specific commands\n"
3560 "Log neighbor up/down and reset reason\n")
3561{
3562 nb_cli_enqueue_change(
3563 vty, "./global/global-neighbor-config/log-neighbor-changes",
3564 NB_OP_MODIFY, "true");
3565
3566 return nb_cli_apply_changes(vty, NULL);
3567}
3568
3569DEFUN_YANG(no_bgp_log_neighbor_changes,
3570 no_bgp_log_neighbor_changes_cmd,
3571 "no bgp log-neighbor-changes",
3572 NO_STR
3573 "BGP specific commands\n"
3574 "Log neighbor up/down and reset reason\n")
3575{
3576 nb_cli_enqueue_change(
3577 vty, "./global/global-neighbor-config/log-neighbor-changes",
3578 NB_OP_MODIFY, "false");
3579
3580 return nb_cli_apply_changes(vty, NULL);
3581}
3582
3583/* "bgp bestpath med" configuration. */
3584DEFUN_YANG (bgp_bestpath_med,
3585 bgp_bestpath_med_cmd,
3586 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3587 "BGP specific commands\n"
3588 "Change the default bestpath selection\n"
3589 "MED attribute\n"
3590 "Compare MED among confederation paths\n"
3591 "Treat missing MED as the least preferred one\n"
3592 "Treat missing MED as the least preferred one\n"
3593 "Compare MED among confederation paths\n")
3594{
3595 int idx = 0;
3596 bool confed = false;
3597 bool worst_med = false;
3598
3599
3600 if (argv_find(argv, argc, "confed", &idx))
3601 confed = true;
3602
3603 nb_cli_enqueue_change(vty,
3604 "./global/route-selection-options/confed-med",
3605 NB_OP_MODIFY, confed ? "true" : "false");
3606
3607 idx = 0;
3608 if (argv_find(argv, argc, "missing-as-worst", &idx))
3609 worst_med = true;
3610
3611 nb_cli_enqueue_change(
3612 vty, "./global/route-selection-options/missing-as-worst-med",
3613 NB_OP_MODIFY, worst_med ? "true" : "false");
3614
3615 return nb_cli_apply_changes(vty, NULL);
3616}
3617
3618DEFUN_YANG (no_bgp_bestpath_med,
3619 no_bgp_bestpath_med_cmd,
3620 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
3621 NO_STR
3622 "BGP specific commands\n"
3623 "Change the default bestpath selection\n"
3624 "MED attribute\n"
3625 "Compare MED among confederation paths\n"
3626 "Treat missing MED as the least preferred one\n"
3627 "Treat missing MED as the least preferred one\n"
3628 "Compare MED among confederation paths\n")
3629{
3630 int idx = 0;
3631
3632 if (argv_find(argv, argc, "confed", &idx))
3633 nb_cli_enqueue_change(
3634 vty, "./global/route-selection-options/confed-med",
3635 NB_OP_MODIFY, "false");
3636
3637 idx = 0;
3638 if (argv_find(argv, argc, "missing-as-worst", &idx))
3639 nb_cli_enqueue_change(
3640 vty,
3641 "./global/route-selection-options/missing-as-worst-med",
3642 NB_OP_MODIFY, "false");
3643
3644 return nb_cli_apply_changes(vty, NULL);
3645}
3646
3647/* "bgp bestpath bandwidth" configuration. */
3648DEFPY (bgp_bestpath_bw,
3649 bgp_bestpath_bw_cmd,
3650 "bgp bestpath bandwidth <ignore|skip-missing|default-weight-for-missing>$bw_cfg",
3651 "BGP specific commands\n"
3652 "Change the default bestpath selection\n"
3653 "Link Bandwidth attribute\n"
3654 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3655 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3656 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3657{
3658 VTY_DECLVAR_CONTEXT(bgp, bgp);
3659 afi_t afi;
3660 safi_t safi;
3661
3662 if (!bw_cfg) {
3663 vty_out(vty, "%% Bandwidth configuration must be specified\n");
3664 return CMD_ERR_INCOMPLETE;
3665 }
3666 if (!strcmp(bw_cfg, "ignore"))
3667 bgp->lb_handling = BGP_LINK_BW_IGNORE_BW;
3668 else if (!strcmp(bw_cfg, "skip-missing"))
3669 bgp->lb_handling = BGP_LINK_BW_SKIP_MISSING;
3670 else if (!strcmp(bw_cfg, "default-weight-for-missing"))
3671 bgp->lb_handling = BGP_LINK_BW_DEFWT_4_MISSING;
3672 else
3673 return CMD_ERR_NO_MATCH;
3674
3675 /* This config is used in route install, so redo that. */
3676 FOREACH_AFI_SAFI (afi, safi) {
3677 if (!bgp_fibupd_safi(safi))
3678 continue;
3679 bgp_zebra_announce_table(bgp, afi, safi);
3680 }
3681
3682 return CMD_SUCCESS;
3683}
3684
3685DEFPY (no_bgp_bestpath_bw,
3686 no_bgp_bestpath_bw_cmd,
3687 "no bgp bestpath bandwidth [<ignore|skip-missing|default-weight-for-missing>$bw_cfg]",
3688 NO_STR
3689 "BGP specific commands\n"
3690 "Change the default bestpath selection\n"
3691 "Link Bandwidth attribute\n"
3692 "Ignore link bandwidth (i.e., do regular ECMP, not weighted)\n"
3693 "Ignore paths without link bandwidth for ECMP (if other paths have it)\n"
3694 "Assign a low default weight (value 1) to paths not having link bandwidth\n")
3695{
3696 VTY_DECLVAR_CONTEXT(bgp, bgp);
3697 afi_t afi;
3698 safi_t safi;
3699
3700 bgp->lb_handling = BGP_LINK_BW_ECMP;
3701
3702 /* This config is used in route install, so redo that. */
3703 FOREACH_AFI_SAFI (afi, safi) {
3704 if (!bgp_fibupd_safi(safi))
3705 continue;
3706 bgp_zebra_announce_table(bgp, afi, safi);
3707 }
3708 return CMD_SUCCESS;
3709}
3710
3711/* "no bgp default ipv4-unicast". */
3712DEFUN (no_bgp_default_ipv4_unicast,
3713 no_bgp_default_ipv4_unicast_cmd,
3714 "no bgp default ipv4-unicast",
3715 NO_STR
3716 "BGP specific commands\n"
3717 "Configure BGP defaults\n"
3718 "Activate ipv4-unicast for a peer by default\n")
3719{
3720 VTY_DECLVAR_CONTEXT(bgp, bgp);
3721 SET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3722 return CMD_SUCCESS;
3723}
3724
3725DEFUN (bgp_default_ipv4_unicast,
3726 bgp_default_ipv4_unicast_cmd,
3727 "bgp default ipv4-unicast",
3728 "BGP specific commands\n"
3729 "Configure BGP defaults\n"
3730 "Activate ipv4-unicast for a peer by default\n")
3731{
3732 VTY_DECLVAR_CONTEXT(bgp, bgp);
3733 UNSET_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4);
3734 return CMD_SUCCESS;
3735}
3736
3737/* Display hostname in certain command outputs */
3738DEFUN_YANG (bgp_default_show_hostname,
3739 bgp_default_show_hostname_cmd,
3740 "bgp default show-hostname",
3741 "BGP specific commands\n"
3742 "Configure BGP defaults\n"
3743 "Show hostname in certain command outputs\n")
3744{
3745 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3746 "true");
3747
3748 return nb_cli_apply_changes(vty, NULL);
3749}
3750
3751DEFUN_YANG(no_bgp_default_show_hostname,
3752 no_bgp_default_show_hostname_cmd,
3753 "no bgp default show-hostname",
3754 NO_STR
3755 "BGP specific commands\n"
3756 "Configure BGP defaults\n"
3757 "Show hostname in certain command outputs\n")
3758{
3759 nb_cli_enqueue_change(vty, "./global/show-hostname", NB_OP_MODIFY,
3760 "false");
3761
3762 return nb_cli_apply_changes(vty, NULL);
3763}
3764
3765void cli_show_router_bgp_show_hostname(struct vty *vty, struct lyd_node *dnode,
3766 bool show_defaults)
3767{
3768 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3769 vty_out(vty, " bgp default show-hostname\n");
3770}
3771
3772/* Display hostname in certain command outputs */
3773DEFUN_YANG(bgp_default_show_nexthop_hostname,
3774 bgp_default_show_nexthop_hostname_cmd,
3775 "bgp default show-nexthop-hostname",
3776 "BGP specific commands\n"
3777 "Configure BGP defaults\n"
3778 "Show hostname for nexthop in certain command outputs\n")
3779{
3780 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3781 NB_OP_MODIFY, "true");
3782
3783 return nb_cli_apply_changes(vty, NULL);
3784}
3785
3786DEFUN (no_bgp_default_show_nexthop_hostname,
3787 no_bgp_default_show_nexthop_hostname_cmd,
3788 "no bgp default show-nexthop-hostname",
3789 NO_STR
3790 "BGP specific commands\n"
3791 "Configure BGP defaults\n"
3792 "Show hostname for nexthop in certain command outputs\n")
3793{
3794 nb_cli_enqueue_change(vty, "./global/show-nexthop-hostname",
3795 NB_OP_MODIFY, "false");
3796
3797 return nb_cli_apply_changes(vty, NULL);
3798}
3799
3800void cli_show_router_bgp_show_nexthop_hostname(struct vty *vty,
3801 struct lyd_node *dnode,
3802 bool show_defaults)
3803{
3804 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_SHOW_HOSTNAME)
3805 vty_out(vty, " bgp default show-nexthop-hostname\n");
3806}
3807
3808/* "bgp network import-check" configuration. */
3809DEFUN_YANG(bgp_network_import_check,
3810 bgp_network_import_check_cmd,
3811 "bgp network import-check",
3812 "BGP specific commands\n"
3813 "BGP network command\n"
3814 "Check BGP network route exists in IGP\n")
3815{
3816 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3817 "true");
3818
3819 return nb_cli_apply_changes(vty, NULL);
3820}
3821
3822ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
3823 "bgp network import-check exact",
3824 "BGP specific commands\n"
3825 "BGP network command\n"
3826 "Check BGP network route exists in IGP\n"
3827 "Match route precisely\n")
3828
3829DEFUN_YANG(no_bgp_network_import_check,
3830 no_bgp_network_import_check_cmd,
3831 "no bgp network import-check",
3832 NO_STR
3833 "BGP specific commands\n"
3834 "BGP network command\n"
3835 "Check BGP network route exists in IGP\n")
3836{
3837 nb_cli_enqueue_change(vty, "./global/import-check", NB_OP_MODIFY,
3838 "false");
3839
3840 return nb_cli_apply_changes(vty, NULL);
3841}
3842
3843void cli_show_router_bgp_import_check(struct vty *vty, struct lyd_node *dnode,
3844 bool show_defaults)
3845{
3846 if (yang_dnode_get_bool(dnode, NULL) != SAVE_BGP_IMPORT_CHECK)
3847 vty_out(vty, " bgp network import-check\n");
3848}
3849
3850DEFUN_YANG(bgp_default_local_preference,
3851 bgp_default_local_preference_cmd,
3852 "bgp default local-preference (0-4294967295)",
3853 "BGP specific commands\n"
3854 "Configure BGP defaults\n"
3855 "local preference (higher=more preferred)\n"
3856 "Configure default local preference value\n")
3857{
3858 int idx_number = 3;
3859
3860 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY,
3861 argv[idx_number]->arg);
3862
3863 return nb_cli_apply_changes(vty, NULL);
3864}
3865
3866DEFUN_YANG(no_bgp_default_local_preference,
3867 no_bgp_default_local_preference_cmd,
3868 "no bgp default local-preference [(0-4294967295)]",
3869 NO_STR
3870 "BGP specific commands\n"
3871 "Configure BGP defaults\n"
3872 "local preference (higher=more preferred)\n"
3873 "Configure default local preference value\n")
3874{
3875 nb_cli_enqueue_change(vty, "./global/local-pref", NB_OP_MODIFY, NULL);
3876
3877 return nb_cli_apply_changes(vty, NULL);
3878}
3879
3880void cli_show_router_bgp_local_pref(struct vty *vty, struct lyd_node *dnode,
3881 bool show_defaults)
3882{
3883 vty_out(vty, " bgp default local-preference %u\n",
3884 yang_dnode_get_uint32(dnode, NULL));
3885}
3886
3887
3888DEFUN_YANG(bgp_default_subgroup_pkt_queue_max,
3889 bgp_default_subgroup_pkt_queue_max_cmd,
3890 "bgp default subgroup-pkt-queue-max (20-100)",
3891 "BGP specific commands\n"
3892 "Configure BGP defaults\n"
3893 "subgroup-pkt-queue-max\n"
3894 "Configure subgroup packet queue max\n")
3895{
3896 int idx_number = 3;
3897
3898 nb_cli_enqueue_change(
3899 vty,
3900 "./global/global-update-group-config/subgroup-pkt-queue-size",
3901 NB_OP_MODIFY, argv[idx_number]->arg);
3902
3903 return nb_cli_apply_changes(vty, NULL);
3904}
3905
3906DEFUN_YANG(no_bgp_default_subgroup_pkt_queue_max,
3907 no_bgp_default_subgroup_pkt_queue_max_cmd,
3908 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3909 NO_STR
3910 "BGP specific commands\n"
3911 "Configure BGP defaults\n"
3912 "subgroup-pkt-queue-max\n"
3913 "Configure subgroup packet queue max\n")
3914{
3915 nb_cli_enqueue_change(
3916 vty,
3917 "./global/global-update-group-config/subgroup-pkt-queue-size",
3918 NB_OP_MODIFY, NULL);
3919
3920 return nb_cli_apply_changes(vty, NULL);
3921}
3922
3923void cli_show_router_global_update_group_config_subgroup_pkt_queue_size(
3924 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
3925{
3926 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
3927 yang_dnode_get_uint32(dnode, NULL));
3928}
3929
3930DEFUN_YANG(bgp_rr_allow_outbound_policy,
3931 bgp_rr_allow_outbound_policy_cmd,
3932 "bgp route-reflector allow-outbound-policy",
3933 "BGP specific commands\n"
3934 "Allow modifications made by out route-map\n"
3935 "on ibgp neighbors\n")
3936{
3937 nb_cli_enqueue_change(vty,
3938 "./global/route-reflector/allow-outbound-policy",
3939 NB_OP_MODIFY, "true");
3940
3941 return nb_cli_apply_changes(vty, NULL);
3942}
3943
3944DEFUN_YANG(no_bgp_rr_allow_outbound_policy,
3945 no_bgp_rr_allow_outbound_policy_cmd,
3946 "no bgp route-reflector allow-outbound-policy",
3947 NO_STR
3948 "BGP specific commands\n"
3949 "Allow modifications made by out route-map\n"
3950 "on ibgp neighbors\n")
3951{
3952 nb_cli_enqueue_change(vty,
3953 "./global/route-reflector/allow-outbound-policy",
3954 NB_OP_MODIFY, "false");
3955
3956 return nb_cli_apply_changes(vty, NULL);
3957}
3958
3959
3960void cli_show_router_global_neighbor_config(struct vty *vty,
3961 struct lyd_node *dnode,
3962 bool show_defaults)
3963{
3964 uint32_t write_quanta, read_quanta;
3965
3966 if (yang_dnode_get_bool(dnode, "./log-neighbor-changes"))
3967 vty_out(vty, " bgp log-neighbor-changes\n");
3968
3969 if (yang_dnode_exists(dnode, "./dynamic-neighbors-limit")) {
3970 uint32_t listen_limit = yang_dnode_get_uint32(
3971 dnode, "./dynamic-neighbors-limit");
3972 vty_out(vty, " bgp listen limit %u\n", listen_limit);
3973 }
3974
3975 write_quanta = yang_dnode_get_uint32(
3976 dnode, "./packet-quanta-config/wpkt-quanta");
3977 if (write_quanta != BGP_WRITE_PACKET_MAX)
3978 vty_out(vty, " write-quanta %d\n", write_quanta);
3979
3980 read_quanta = yang_dnode_get_uint32(
3981 dnode, "./packet-quanta-config/rpkt-quanta");
3982
3983 if (read_quanta != BGP_READ_PACKET_MAX)
3984 vty_out(vty, " read-quanta %d\n", read_quanta);
3985}
3986
3987DEFUN_YANG(bgp_listen_limit,
3988 bgp_listen_limit_cmd,
3989 "bgp listen limit (1-5000)",
3990 "BGP specific commands\n"
3991 "BGP Dynamic Neighbors listen commands\n"
3992 "Maximum number of BGP Dynamic Neighbors that can be created\n"
3993 "Configure Dynamic Neighbors listen limit value\n")
3994{
3995 int idx_number = 3;
3996
3997 nb_cli_enqueue_change(
3998 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
3999 NB_OP_MODIFY, argv[idx_number]->arg);
4000
4001 return nb_cli_apply_changes(vty, NULL);
4002}
4003
4004DEFUN_YANG(no_bgp_listen_limit,
4005 no_bgp_listen_limit_cmd,
4006 "no bgp listen limit [(1-5000)]",
4007 NO_STR
4008 "BGP specific commands\n"
4009 "BGP Dynamic Neighbors listen commands\n"
4010 "Maximum number of BGP Dynamic Neighbors that can be created\n"
4011 "Configure Dynamic Neighbors listen limit value\n")
4012{
4013 nb_cli_enqueue_change(
4014 vty, "./global/global-neighbor-config/dynamic-neighbors-limit",
4015 NB_OP_DESTROY, NULL);
4016
4017 return nb_cli_apply_changes(vty, NULL);
4018}
4019
4020
4021/*
4022 * Check if this listen range is already configured. Check for exact
4023 * match or overlap based on input.
4024 */
4025static struct peer_group *listen_range_exists(struct bgp *bgp,
4026 struct prefix *range, int exact)
4027{
4028 struct listnode *node, *nnode;
4029 struct listnode *node1, *nnode1;
4030 struct peer_group *group;
4031 struct prefix *lr;
4032 afi_t afi;
4033 int match;
4034
4035 afi = family2afi(range->family);
4036 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4037 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
4038 lr)) {
4039 if (exact)
4040 match = prefix_same(range, lr);
4041 else
4042 match = (prefix_match(range, lr)
4043 || prefix_match(lr, range));
4044 if (match)
4045 return group;
4046 }
4047 }
4048
4049 return NULL;
4050}
4051
4052DEFUN (bgp_listen_range,
4053 bgp_listen_range_cmd,
4054 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4055 "BGP specific commands\n"
4056 "Configure BGP dynamic neighbors listen range\n"
4057 "Configure BGP dynamic neighbors listen range\n"
4058 NEIGHBOR_ADDR_STR
4059 "Member of the peer-group\n"
4060 "Peer-group name\n")
4061{
4062 VTY_DECLVAR_CONTEXT(bgp, bgp);
4063 struct prefix range;
4064 struct peer_group *group, *existing_group;
4065 afi_t afi;
4066 int ret;
4067 int idx = 0;
4068
4069 argv_find(argv, argc, "A.B.C.D/M", &idx);
4070 argv_find(argv, argc, "X:X::X:X/M", &idx);
4071 char *prefix = argv[idx]->arg;
4072 argv_find(argv, argc, "PGNAME", &idx);
4073 char *peergroup = argv[idx]->arg;
4074
4075 /* Convert IP prefix string to struct prefix. */
4076 ret = str2prefix(prefix, &range);
4077 if (!ret) {
4078 vty_out(vty, "%% Malformed listen range\n");
4079 return CMD_WARNING_CONFIG_FAILED;
4080 }
4081
4082 afi = family2afi(range.family);
4083
4084 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4085 vty_out(vty,
4086 "%% Malformed listen range (link-local address)\n");
4087 return CMD_WARNING_CONFIG_FAILED;
4088 }
4089
4090 apply_mask(&range);
4091
4092 /* Check if same listen range is already configured. */
4093 existing_group = listen_range_exists(bgp, &range, 1);
4094 if (existing_group) {
4095 if (strcmp(existing_group->name, peergroup) == 0)
4096 return CMD_SUCCESS;
4097 else {
4098 vty_out(vty,
4099 "%% Same listen range is attached to peer-group %s\n",
4100 existing_group->name);
4101 return CMD_WARNING_CONFIG_FAILED;
4102 }
4103 }
4104
4105 /* Check if an overlapping listen range exists. */
4106 if (listen_range_exists(bgp, &range, 0)) {
4107 vty_out(vty,
4108 "%% Listen range overlaps with existing listen range\n");
4109 return CMD_WARNING_CONFIG_FAILED;
4110 }
4111
4112 group = peer_group_lookup(bgp, peergroup);
4113 if (!group) {
4114 vty_out(vty, "%% Configure the peer-group first\n");
4115 return CMD_WARNING_CONFIG_FAILED;
4116 }
4117
4118 ret = peer_group_listen_range_add(group, &range);
4119 return bgp_vty_return(vty, ret);
4120}
4121
4122DEFUN (no_bgp_listen_range,
4123 no_bgp_listen_range_cmd,
4124 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
4125 NO_STR
4126 "BGP specific commands\n"
4127 "Unconfigure BGP dynamic neighbors listen range\n"
4128 "Unconfigure BGP dynamic neighbors listen range\n"
4129 NEIGHBOR_ADDR_STR
4130 "Member of the peer-group\n"
4131 "Peer-group name\n")
4132{
4133 VTY_DECLVAR_CONTEXT(bgp, bgp);
4134 struct prefix range;
4135 struct peer_group *group;
4136 afi_t afi;
4137 int ret;
4138 int idx = 0;
4139
4140 argv_find(argv, argc, "A.B.C.D/M", &idx);
4141 argv_find(argv, argc, "X:X::X:X/M", &idx);
4142 char *prefix = argv[idx]->arg;
4143 argv_find(argv, argc, "PGNAME", &idx);
4144 char *peergroup = argv[idx]->arg;
4145
4146 /* Convert IP prefix string to struct prefix. */
4147 ret = str2prefix(prefix, &range);
4148 if (!ret) {
4149 vty_out(vty, "%% Malformed listen range\n");
4150 return CMD_WARNING_CONFIG_FAILED;
4151 }
4152
4153 afi = family2afi(range.family);
4154
4155 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
4156 vty_out(vty,
4157 "%% Malformed listen range (link-local address)\n");
4158 return CMD_WARNING_CONFIG_FAILED;
4159 }
4160
4161 apply_mask(&range);
4162
4163 group = peer_group_lookup(bgp, peergroup);
4164 if (!group) {
4165 vty_out(vty, "%% Peer-group does not exist\n");
4166 return CMD_WARNING_CONFIG_FAILED;
4167 }
4168
4169 ret = peer_group_listen_range_del(group, &range);
4170 return bgp_vty_return(vty, ret);
4171}
4172
4173void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
4174{
4175 struct peer_group *group;
4176 struct listnode *node, *nnode, *rnode, *nrnode;
4177 struct prefix *range;
4178 afi_t afi;
4179
4180 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
4181 vty_out(vty, " bgp listen limit %d\n",
4182 bgp->dynamic_neighbors_limit);
4183
4184 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
4185 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
4186 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
4187 nrnode, range)) {
4188 vty_out(vty,
4189 " bgp listen range %pFX peer-group %s\n",
4190 range, group->name);
4191 }
4192 }
4193 }
4194}
4195
4196
4197DEFUN_YANG(bgp_disable_connected_route_check,
4198 bgp_disable_connected_route_check_cmd,
4199 "bgp disable-ebgp-connected-route-check",
4200 "BGP specific commands\n"
4201 "Disable checking if nexthop is connected on ebgp sessions\n")
4202{
4203 nb_cli_enqueue_change(vty,
4204 "./global/ebgp-multihop-connected-route-check",
4205 NB_OP_MODIFY, "true");
4206
4207 return nb_cli_apply_changes(vty, NULL);
4208}
4209
4210DEFUN_YANG(no_bgp_disable_connected_route_check,
4211 no_bgp_disable_connected_route_check_cmd,
4212 "no bgp disable-ebgp-connected-route-check",
4213 NO_STR
4214 "BGP specific commands\n"
4215 "Disable checking if nexthop is connected on ebgp sessions\n")
4216{
4217 nb_cli_enqueue_change(vty,
4218 "./global/ebgp-multihop-connected-route-check",
4219 NB_OP_MODIFY, "false");
4220
4221 return nb_cli_apply_changes(vty, NULL);
4222}
4223
4224void cli_show_router_global_ebgp_multihop_connected_route_check(
4225 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
4226{
4227 if (yang_dnode_get_bool(dnode, NULL))
4228 vty_out(vty, " bgp disable-ebgp-connected-route-check\n");
4229}
4230
4231DEFUN_YANG(bgp_default_shutdown,
4232 bgp_default_shutdown_cmd,
4233 "[no] bgp default shutdown",
4234 NO_STR BGP_STR
4235 "Configure BGP defaults\n"
4236 "Apply administrative shutdown to newly configured peers\n")
4237{
4238 nb_cli_enqueue_change(vty, "./global/default-shutdown", NB_OP_MODIFY,
4239 strmatch(argv[0]->text, "no") ? "false" : "true");
4240
4241 return nb_cli_apply_changes(vty, NULL);
4242}
4243
4244void cli_show_router_bgp_default_shutdown(struct vty *vty,
4245 struct lyd_node *dnode,
4246 bool show_defaults)
4247{
4248 if (yang_dnode_get_bool(dnode, NULL))
4249 vty_out(vty, " bgp default shutdown\n");
4250}
4251
4252DEFPY(bgp_shutdown_msg, bgp_shutdown_msg_cmd, "bgp shutdown message MSG...",
4253 BGP_STR
4254 "Administrative shutdown of the BGP instance\n"
4255 "Add a shutdown message (RFC 8203)\n"
4256 "Shutdown message\n")
4257{
4258 char *msgstr = NULL;
4259
4260 VTY_DECLVAR_CONTEXT(bgp, bgp);
4261
4262 if (argc > 3)
4263 msgstr = argv_concat(argv, argc, 3);
4264
4265 bgp_shutdown_enable(bgp, msgstr);
4266 XFREE(MTYPE_TMP, msgstr);
4267
4268 return CMD_SUCCESS;
4269}
4270
4271DEFPY(bgp_shutdown, bgp_shutdown_cmd, "bgp shutdown",
4272 BGP_STR "Administrative shutdown of the BGP instance\n")
4273{
4274 VTY_DECLVAR_CONTEXT(bgp, bgp);
4275
4276 bgp_shutdown_enable(bgp, NULL);
4277
4278 return CMD_SUCCESS;
4279}
4280
4281DEFPY(no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown",
4282 NO_STR BGP_STR "Administrative shutdown of the BGP instance\n")
4283{
4284 VTY_DECLVAR_CONTEXT(bgp, bgp);
4285
4286 bgp_shutdown_disable(bgp);
4287
4288 return CMD_SUCCESS;
4289}
4290
4291ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
4292 "no bgp shutdown message MSG...", NO_STR BGP_STR
4293 "Administrative shutdown of the BGP instance\n"
4294 "Add a shutdown message (RFC 8203)\n" "Shutdown message\n")
4295
4296DEFUN_YANG(neighbor_remote_as,
4297 neighbor_remote_as_cmd,
4298 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
4299 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4300 "Specify a BGP neighbor\n" AS_STR
4301 "Internal BGP peer\n"
4302 "External BGP peer\n")
4303{
4304 int idx_peer = 1;
4305 int idx_remote_as = 3;
4306 char base_xpath[XPATH_MAXLEN];
4307 char unnbr_xpath[XPATH_MAXLEN];
4308 char prgrp_xpath[XPATH_MAXLEN];
4309 union sockunion su;
4310 const char *as_type_str = "as-specified";
4311
4312 if (str2sockunion(argv[idx_peer]->arg, &su) < 0) {
4313 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4314 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4315
4316 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4317 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4318
4319 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4320 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4321 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4322 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4323 "%s%s", VTY_CURR_XPATH,
4324 prgrp_xpath + 1)) {
4325 snprintf(base_xpath, sizeof(base_xpath),
4326 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
4327 "");
4328 } else {
4329 vty_out(vty,
4330 "%% Create the peer-group or interface first\n");
4331 return CMD_WARNING_CONFIG_FAILED;
4332 }
4333 } else {
4334 snprintf(base_xpath, sizeof(base_xpath),
4335 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4336 }
4337
4338 if (argv[idx_remote_as]->arg[0] == 'i') {
4339 as_type_str = "internal";
4340 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4341 as_type_str = "external";
4342 } else {
4343 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4344 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4345 }
4346 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4347 NB_OP_MODIFY, as_type_str);
4348
4349 return nb_cli_apply_changes(vty, base_xpath);
4350}
4351
4352int peer_conf_interface_create(struct bgp *bgp, const char *conf_if, afi_t afi,
4353 safi_t safi, bool v6only,
4354 const char *peer_group_name, int as_type,
4355 as_t as, char *errmsg, size_t errmsg_len)
4356{
4357 struct peer *peer;
4358 struct peer_group *group;
4359 int ret = 0;
4360
4361 group = peer_group_lookup(bgp, conf_if);
4362
4363 if (group) {
4364 snprintf(errmsg, errmsg_len,
4365 "Name conflict with peer-group \n");
4366 return -1;
4367 }
4368
4369 peer = peer_lookup_by_conf_if(bgp, conf_if);
4370 if (peer) {
4371 if (as_type != AS_UNSPECIFIED)
4372 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
4373 afi, safi);
4374 } else {
4375 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4)
4376 && afi == AFI_IP && safi == SAFI_UNICAST)
4377 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4378 as_type, 0, 0, NULL);
4379 else
4380 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
4381 as_type, afi, safi, NULL);
4382
4383 if (!peer) {
4384 snprintf(errmsg, errmsg_len,
4385 "BGP failed to create peer\n");
4386 return -1;
4387 }
4388
4389 if (v6only)
4390 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4391
4392 /* Request zebra to initiate IPv6 RAs on this interface. We do
4393 * this
4394 * any unnumbered peer in order to not worry about run-time
4395 * transitions
4396 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
4397 * address
4398 * gets deleted later etc.)
4399 */
4400 if (peer->ifp)
4401 bgp_zebra_initiate_radv(bgp, peer);
4402 }
4403
4404 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
4405 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
4406 if (v6only)
4407 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
4408 else
4409 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
4410
4411 /* v6only flag changed. Reset bgp seesion */
4412 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
4413 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
4414 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
4415 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
4416 } else
4417 bgp_session_reset(peer);
4418 }
4419
4420 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
4421 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
4422 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
4423 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
4424 }
4425
4426 if (peer_group_name) {
4427 group = peer_group_lookup(bgp, peer_group_name);
4428 if (!group) {
4429 snprintf(errmsg, errmsg_len,
4430 "Configure the peer-group first\n");
4431 return -1;
4432 }
4433
4434 ret = peer_group_bind(bgp, NULL, peer, group, &as);
4435 }
4436
4437 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
4438}
4439
4440DEFUN_YANG(neighbor_interface_config,
4441 neighbor_interface_config_cmd,
4442 "neighbor WORD interface [peer-group PGNAME]",
4443 NEIGHBOR_STR
4444 "Interface name or neighbor tag\n"
4445 "Enable BGP on interface\n"
4446 "Member of the peer-group\n"
4447 "Peer-group name\n")
4448{
4449 int idx_word = 1;
4450 int idx_peer_group_word = 4;
4451 char base_xpath[XPATH_MAXLEN];
4452
4453 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4454 argv[idx_word]->arg, "");
4455
4456 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4457 if (argc > idx_peer_group_word)
4458 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4459 argv[idx_peer_group_word]->arg);
4460
4461 return nb_cli_apply_changes(vty, base_xpath);
4462}
4463
4464DEFUN_YANG(neighbor_interface_config_v6only,
4465 neighbor_interface_config_v6only_cmd,
4466 "neighbor WORD interface v6only [peer-group PGNAME]",
4467 NEIGHBOR_STR
4468 "Interface name or neighbor tag\n"
4469 "Enable BGP on interface\n"
4470 "Enable BGP with v6 link-local only\n"
4471 "Member of the peer-group\n"
4472 "Peer-group name\n")
4473{
4474 int idx_word = 1;
4475 int idx_peer_group_word = 5;
4476 char base_xpath[XPATH_MAXLEN];
4477
4478 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4479 argv[idx_word]->arg, "");
4480
4481 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4482 if (argc > idx_peer_group_word)
4483 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_MODIFY,
4484 argv[idx_peer_group_word]->arg);
4485
4486 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4487
4488 return nb_cli_apply_changes(vty, base_xpath);
4489}
4490
4491
4492DEFUN_YANG(
4493 neighbor_interface_config_remote_as,
4494 neighbor_interface_config_remote_as_cmd,
4495 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
4496 NEIGHBOR_STR
4497 "Interface name or neighbor tag\n"
4498 "Enable BGP on interface\n"
4499 "Specify a BGP neighbor\n" AS_STR
4500 "Internal BGP peer\n"
4501 "External BGP peer\n")
4502{
4503 int idx_word = 1;
4504 int idx_remote_as = 4;
4505 char base_xpath[XPATH_MAXLEN];
4506 const char *as_type_str = "as-specified";
4507
4508 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4509 argv[idx_word]->arg, "");
4510
4511 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4512
4513 if (argv[idx_remote_as]->arg[0] == 'i') {
4514 as_type_str = "internal";
4515 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4516 as_type_str = "external";
4517 } else {
4518 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4519 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4520 }
4521 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4522 NB_OP_MODIFY, as_type_str);
4523
4524 return nb_cli_apply_changes(vty, base_xpath);
4525}
4526
4527DEFUN_YANG(
4528 neighbor_interface_v6only_config_remote_as,
4529 neighbor_interface_v6only_config_remote_as_cmd,
4530 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
4531 NEIGHBOR_STR
4532 "Interface name or neighbor tag\n"
4533 "Enable BGP with v6 link-local only\n"
4534 "Enable BGP on interface\n"
4535 "Specify a BGP neighbor\n" AS_STR
4536 "Internal BGP peer\n"
4537 "External BGP peer\n")
4538{
4539 int idx_word = 1;
4540 int idx_remote_as = 5;
4541 char base_xpath[XPATH_MAXLEN];
4542 const char *as_type_str = "as-specified";
4543
4544 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4545 argv[idx_word]->arg, "");
4546
4547 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4548
4549 nb_cli_enqueue_change(vty, "./v6only", NB_OP_MODIFY, "true");
4550
4551 if (argv[idx_remote_as]->arg[0] == 'i') {
4552 as_type_str = "internal";
4553 } else if (argv[idx_remote_as]->arg[0] == 'e') {
4554 as_type_str = "external";
4555 } else {
4556 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as",
4557 NB_OP_MODIFY, argv[idx_remote_as]->arg);
4558 }
4559 nb_cli_enqueue_change(vty, "./neighbor-remote-as/remote-as-type",
4560 NB_OP_MODIFY, as_type_str);
4561
4562 return nb_cli_apply_changes(vty, base_xpath);
4563}
4564
4565DEFUN_YANG(neighbor_peer_group, neighbor_peer_group_cmd,
4566 "neighbor WORD peer-group",
4567 NEIGHBOR_STR
4568 "Interface name or neighbor tag\n"
4569 "Configure peer-group\n")
4570{
4571 char base_xpath[XPATH_MAXLEN];
4572 int idx_word = 1;
4573
4574 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4575 argv[idx_word]->arg, "");
4576
4577 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
4578
4579 return nb_cli_apply_changes(vty, base_xpath);
4580}
4581
4582DEFUN_YANG(no_neighbor,
4583 no_neighbor_cmd,
4584 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
4585 NO_STR NEIGHBOR_STR
4586 NEIGHBOR_ADDR_STR2
4587 "Specify a BGP neighbor\n" AS_STR
4588 "Internal BGP peer\n"
4589 "External BGP peer\n")
4590{
4591 int idx_peer = 2;
4592 char base_xpath[XPATH_MAXLEN];
4593 char num_xpath[XPATH_MAXLEN];
4594 char unnbr_xpath[XPATH_MAXLEN];
4595 char prgrp_xpath[XPATH_MAXLEN];
4596 union sockunion su;
4597
4598 if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
4599 snprintf(num_xpath, sizeof(num_xpath),
4600 FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
4601 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4602 VTY_CURR_XPATH, num_xpath + 1)) {
4603 strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
4604 }
4605 } else {
4606 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
4607 FRR_BGP_NEIGHBOR_UNNUM_XPATH, argv[idx_peer]->arg, "");
4608
4609 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
4610 FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");
4611
4612 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4613 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4614 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4615 } else if (yang_dnode_exists(vty->candidate_config->dnode,
4616 "%s%s", VTY_CURR_XPATH,
4617 prgrp_xpath + 1)) {
4618 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4619 } else {
4620 vty_out(vty,
4621 "%% Create the peer-group or interface first\n");
4622 return CMD_WARNING_CONFIG_FAILED;
4623 }
4624 }
4625
4626 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4627
4628 return nb_cli_apply_changes(vty, NULL);
4629}
4630
4631DEFUN_YANG(no_neighbor_interface_config,
4632 no_neighbor_interface_config_cmd,
4633 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
4634 NO_STR NEIGHBOR_STR
4635 "Interface name\n"
4636 "Configure BGP on interface\n"
4637 "Enable BGP with v6 link-local only\n"
4638 "Member of the peer-group\n"
4639 "Peer-group name\n"
4640 "Specify a BGP neighbor\n" AS_STR
4641 "Internal BGP peer\n"
4642 "External BGP peer\n")
4643{
4644 int idx_word = 2;
4645 char base_xpath[XPATH_MAXLEN];
4646
4647 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4648 argv[idx_word]->arg, "");
4649
4650 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4651
4652 return nb_cli_apply_changes(vty, base_xpath);
4653}
4654
4655DEFUN_YANG(no_neighbor_peer_group,
4656 no_neighbor_peer_group_cmd,
4657 "no neighbor WORD peer-group",
4658 NO_STR NEIGHBOR_STR
4659 "Neighbor tag\n"
4660 "Configure peer-group\n")
4661{
4662 char base_xpath[XPATH_MAXLEN];
4663 int idx_word = 2;
4664
4665 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_PEER_GROUP_XPATH,
4666 argv[idx_word]->arg, "");
4667
4668 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
4669
4670 return nb_cli_apply_changes(vty, base_xpath);
4671}
4672
4673DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
4674 no_neighbor_interface_peer_group_remote_as_cmd,
4675 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
4676 NO_STR NEIGHBOR_STR
4677 "Interface name or neighbor tag\n"
4678 "Specify a BGP neighbor\n" AS_STR
4679 "Internal BGP peer\n"
4680 "External BGP peer\n")
4681{
4682 int idx_peer = 2;
4683 char base_xpath[XPATH_MAXLEN];
4684 char unnbr_xpath[XPATH_MAXLEN];
4685 char prgrp_xpath[XPATH_MAXLEN];
4686
4687 snprintf(unnbr_xpath, sizeof(unnbr_xpath), FRR_BGP_NEIGHBOR_UNNUM_XPATH,
4688 argv[idx_peer]->arg, "");
4689
4690 snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
4691 argv[idx_peer]->arg, "");
4692
4693 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4694 VTY_CURR_XPATH, unnbr_xpath + 1)) {
4695 strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
4696 } else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
4697 VTY_CURR_XPATH, prgrp_xpath + 1)) {
4698 strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
4699 } else {
4700 vty_out(vty, "%% Create the peer-group or interface first\n");
4701 return CMD_WARNING_CONFIG_FAILED;
4702 }
4703
4704 strlcat(base_xpath, "/neighbor-remote-as/remote-as-type",
4705 sizeof(base_xpath));
4706
4707 nb_cli_enqueue_change(vty, base_xpath, NB_OP_DESTROY, NULL);
4708
4709 return nb_cli_apply_changes(vty, NULL);
4710}
4711
4712DEFUN_YANG(neighbor_local_as,
4713 neighbor_local_as_cmd,
4714 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
4715 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4716 "Specify a local-as number\n"
4717 "AS number used as local AS\n")
4718{
4719 int idx_peer = 1;
4720 int idx_number = 3;
4721 char base_xpath[XPATH_MAXLEN];
4722
4723 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4724 sizeof(base_xpath), NULL)
4725 < 0)
4726 return CMD_WARNING_CONFIG_FAILED;
4727
4728 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4729 argv[idx_number]->arg);
4730
4731 return nb_cli_apply_changes(vty, base_xpath);
4732}
4733
4734DEFUN_YANG(
4735 neighbor_local_as_no_prepend, neighbor_local_as_no_prepend_cmd,
4736 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
4737 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4738 "Specify a local-as number\n"
4739 "AS number used as local AS\n"
4740 "Do not prepend local-as to updates from ebgp peers\n")
4741{
4742 int idx_peer = 1;
4743 int idx_number = 3;
4744 char base_xpath[XPATH_MAXLEN];
4745
4746 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4747 sizeof(base_xpath), NULL)
4748 < 0)
4749 return CMD_WARNING_CONFIG_FAILED;
4750
4751 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4752 argv[idx_number]->arg);
4753 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4754 "true");
4755
4756 return nb_cli_apply_changes(vty, base_xpath);
4757}
4758
4759DEFUN_YANG(
4760 neighbor_local_as_no_prepend_replace_as,
4761 neighbor_local_as_no_prepend_replace_as_cmd,
4762 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
4763 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4764 "Specify a local-as number\n"
4765 "AS number used as local AS\n"
4766 "Do not prepend local-as to updates from ebgp peers\n"
4767 "Do not prepend local-as to updates from ibgp peers\n")
4768{
4769 int idx_peer = 1;
4770 int idx_number = 3;
4771 char base_xpath[XPATH_MAXLEN];
4772
4773 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4774 sizeof(base_xpath), NULL)
4775 < 0)
4776 return CMD_WARNING_CONFIG_FAILED;
4777
4778 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_MODIFY,
4779 argv[idx_number]->arg);
4780 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4781 "true");
4782 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4783 "true");
4784
4785 return nb_cli_apply_changes(vty, base_xpath);
4786}
4787
4788DEFUN_YANG(no_neighbor_local_as,
4789 no_neighbor_local_as_cmd,
4790 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
4791 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4792 "Specify a local-as number\n"
4793 "AS number used as local AS\n"
4794 "Do not prepend local-as to updates from ebgp peers\n"
4795 "Do not prepend local-as to updates from ibgp peers\n")
4796{
4797 int idx_peer = 2;
4798 char base_xpath[XPATH_MAXLEN];
4799
4800 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4801 sizeof(base_xpath), NULL)
4802 < 0)
4803 return CMD_WARNING_CONFIG_FAILED;
4804
4805 nb_cli_enqueue_change(vty, "./local-as/local-as", NB_OP_DESTROY, NULL);
4806 nb_cli_enqueue_change(vty, "./local-as/no-prepend", NB_OP_MODIFY,
4807 "false");
4808 nb_cli_enqueue_change(vty, "./local-as/no-replace-as", NB_OP_MODIFY,
4809 "false");
4810
4811 return nb_cli_apply_changes(vty, base_xpath);
4812}
4813
4814
4815DEFUN (neighbor_solo,
4816 neighbor_solo_cmd,
4817 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4818 NEIGHBOR_STR
4819 NEIGHBOR_ADDR_STR2
4820 "Solo peer - part of its own update group\n")
4821{
4822 int idx_peer = 1;
4823 struct peer *peer;
4824 int ret;
4825
4826 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4827 if (!peer)
4828 return CMD_WARNING_CONFIG_FAILED;
4829
4830 ret = update_group_adjust_soloness(peer, 1);
4831 return bgp_vty_return(vty, ret);
4832}
4833
4834DEFUN (no_neighbor_solo,
4835 no_neighbor_solo_cmd,
4836 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
4837 NO_STR
4838 NEIGHBOR_STR
4839 NEIGHBOR_ADDR_STR2
4840 "Solo peer - part of its own update group\n")
4841{
4842 int idx_peer = 2;
4843 struct peer *peer;
4844 int ret;
4845
4846 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4847 if (!peer)
4848 return CMD_WARNING_CONFIG_FAILED;
4849
4850 ret = update_group_adjust_soloness(peer, 0);
4851 return bgp_vty_return(vty, ret);
4852}
4853
4854DEFUN_YANG(neighbor_password,
4855 neighbor_password_cmd,
4856 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
4857 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4858 "Set a password\n"
4859 "The password\n")
4860{
4861 int idx_peer = 1;
4862 int idx_line = 3;
4863 char base_xpath[XPATH_MAXLEN];
4864
4865 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4866 sizeof(base_xpath), NULL)
4867 < 0)
4868 return CMD_WARNING_CONFIG_FAILED;
4869
4870 nb_cli_enqueue_change(vty, "./password", NB_OP_MODIFY,
4871 argv[idx_line]->arg);
4872
4873 return nb_cli_apply_changes(vty, base_xpath);
4874}
4875
4876DEFUN_YANG(no_neighbor_password,
4877 no_neighbor_password_cmd,
4878 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
4879 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4880 "Set a password\n"
4881 "The password\n")
4882{
4883 int idx_peer = 2;
4884 char base_xpath[XPATH_MAXLEN];
4885
4886 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4887 sizeof(base_xpath), NULL)
4888 < 0)
4889 return CMD_WARNING_CONFIG_FAILED;
4890
4891 nb_cli_enqueue_change(vty, "./password", NB_OP_DESTROY, NULL);
4892
4893 return nb_cli_apply_changes(vty, base_xpath);
4894}
4895
4896DEFUN_YANG(neighbor_activate,
4897 neighbor_activate_cmd,
4898 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4899 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4900 "Enable the Address Family for this Neighbor\n")
4901{
4902 int idx_peer = 1;
4903 char base_xpath[XPATH_MAXLEN];
4904 char af_xpath[XPATH_MAXLEN];
4905 afi_t afi = bgp_node_afi(vty);
4906 safi_t safi = bgp_node_safi(vty);
4907
4908 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4909 yang_afi_safi_value2identity(afi, safi));
4910 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4911 sizeof(base_xpath), af_xpath)
4912 < 0)
4913 return CMD_WARNING_CONFIG_FAILED;
4914
4915 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
4916
4917 return nb_cli_apply_changes(vty, base_xpath);
4918}
4919
4920ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
4921 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4922 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4923 "Enable the Address Family for this Neighbor\n")
4924
4925DEFUN_YANG(no_neighbor_activate,
4926 no_neighbor_activate_cmd,
4927 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4928 NO_STR NEIGHBOR_STR
4929 NEIGHBOR_ADDR_STR2
4930 "Enable the Address Family for this Neighbor\n")
4931{
4932 int idx_peer = 2;
4933 char base_xpath[XPATH_MAXLEN];
4934 char af_xpath[XPATH_MAXLEN];
4935 afi_t afi = bgp_node_afi(vty);
4936 safi_t safi = bgp_node_safi(vty);
4937
4938 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
4939 yang_afi_safi_value2identity(afi, safi));
4940
4941 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
4942 sizeof(base_xpath), af_xpath)
4943 < 0)
4944 return CMD_WARNING_CONFIG_FAILED;
4945
4946 nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "false");
4947
4948 return nb_cli_apply_changes(vty, base_xpath);
4949}
4950
4951ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
4952 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
4953 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4954 "Enable the Address Family for this Neighbor\n")
4955
4956DEFUN (neighbor_set_peer_group,
4957 neighbor_set_peer_group_cmd,
4958 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
4959 NEIGHBOR_STR
4960 NEIGHBOR_ADDR_STR2
4961 "Member of the peer-group\n"
4962 "Peer-group name\n")
4963{
4964 VTY_DECLVAR_CONTEXT(bgp, bgp);
4965 int idx_peer = 1;
4966 int idx_word = 3;
4967 int ret;
4968 as_t as;
4969 union sockunion su;
4970 struct peer *peer;
4971 struct peer_group *group;
4972
4973 ret = str2sockunion(argv[idx_peer]->arg, &su);
4974 if (ret < 0) {
4975 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
4976 if (!peer) {
4977 vty_out(vty, "%% Malformed address or name: %s\n",
4978 argv[idx_peer]->arg);
4979 return CMD_WARNING_CONFIG_FAILED;
4980 }
4981 } else {
4982 if (peer_address_self_check(bgp, &su)) {
4983 vty_out(vty,
4984 "%% Can not configure the local system as neighbor\n");
4985 return CMD_WARNING_CONFIG_FAILED;
4986 }
4987
4988 /* Disallow for dynamic neighbor. */
4989 peer = peer_lookup(bgp, &su);
4990 if (peer && peer_dynamic_neighbor(peer)) {
4991 vty_out(vty,
4992 "%% Operation not allowed on a dynamic neighbor\n");
4993 return CMD_WARNING_CONFIG_FAILED;
4994 }
4995 }
4996
4997 group = peer_group_lookup(bgp, argv[idx_word]->arg);
4998 if (!group) {
4999 vty_out(vty, "%% Configure the peer-group first\n");
5000 return CMD_WARNING_CONFIG_FAILED;
5001 }
5002
5003 ret = peer_group_bind(bgp, &su, peer, group, &as);
5004
5005 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
5006 vty_out(vty,
5007 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
5008 as);
5009 return CMD_WARNING_CONFIG_FAILED;
5010 }
5011
5012 return bgp_vty_return(vty, ret);
5013}
5014
5015ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
5016 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
5017 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5018 "Member of the peer-group\n"
5019 "Peer-group name\n")
5020
5021DEFUN_YANG (no_neighbor_set_peer_group,
5022 no_neighbor_set_peer_group_cmd,
5023 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
5024 NO_STR
5025 NEIGHBOR_STR
5026 NEIGHBOR_ADDR_STR2
5027 "Member of the peer-group\n"
5028 "Peer-group name\n")
5029{
5030 int idx_peer = 2;
5031 char base_xpath[XPATH_MAXLEN];
5032
5033 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5034 sizeof(base_xpath), NULL)
5035 < 0)
5036 return CMD_WARNING_CONFIG_FAILED;
5037
5038 nb_cli_enqueue_change(vty, "./peer-group", NB_OP_DESTROY, NULL);
5039
5040 return nb_cli_apply_changes(vty, base_xpath);
5041}
5042
5043ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
5044 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group [PGNAME]",
5045 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5046 "Member of the peer-group\n"
5047 "Peer-group name\n")
5048
5049static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
5050 uint32_t flag, int set)
5051{
5052 int ret;
5053 struct peer *peer;
5054
5055 peer = peer_and_group_lookup_vty(vty, ip_str);
5056 if (!peer)
5057 return CMD_WARNING_CONFIG_FAILED;
5058
5059 /*
5060 * If 'neighbor <interface>', then this is for directly connected peers,
5061 * we should not accept disable-connected-check.
5062 */
5063 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5064 vty_out(vty,
5065 "%s is directly connected peer, cannot accept disable-connected-check\n",
5066 ip_str);
5067 return CMD_WARNING_CONFIG_FAILED;
5068 }
5069
5070 if (!set && flag == PEER_FLAG_SHUTDOWN)
5071 peer_tx_shutdown_message_unset(peer);
5072
5073 if (set)
5074 ret = peer_flag_set(peer, flag);
5075 else
5076 ret = peer_flag_unset(peer, flag);
5077
5078 return bgp_vty_return(vty, ret);
5079}
5080
5081static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
5082{
5083 return peer_flag_modify_vty(vty, ip_str, flag, 1);
5084}
5085
5086static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
5087 uint32_t flag)
5088{
5089 return peer_flag_modify_vty(vty, ip_str, flag, 0);
5090}
5091
5092int peer_flag_modify_nb(struct bgp *bgp, const char *ip_str, struct peer *peer,
5093 uint32_t flag, bool set, char *errmsg,
5094 size_t errmsg_len)
5095{
5096 int ret;
5097
5098 /*
5099 * If 'neighbor <interface>', then this is for directly connected peers,
5100 * we should not accept disable-connected-check.
5101 */
5102 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
5103 snprintf(
5104 errmsg, errmsg_len,
5105 "%s is directly connected peer, cannot accept disable-connected-check\n",
5106 ip_str);
5107 return -1;
5108 }
5109
5110 if (!set && flag == PEER_FLAG_SHUTDOWN)
5111 peer_tx_shutdown_message_unset(peer);
5112
5113 if (set)
5114 ret = peer_flag_set(peer, flag);
5115 else
5116 ret = peer_flag_unset(peer, flag);
5117
5118 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5119}
5120
5121/* neighbor passive. */
5122DEFUN_YANG(neighbor_passive,
5123 neighbor_passive_cmd,
5124 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5125 NEIGHBOR_STR
5126 NEIGHBOR_ADDR_STR2
5127 "Don't send open messages to this neighbor\n")
5128{
5129 int idx_peer = 1;
5130 char base_xpath[XPATH_MAXLEN];
5131
5132 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5133 sizeof(base_xpath), NULL)
5134 < 0)
5135 return CMD_WARNING_CONFIG_FAILED;
5136
5137 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "true");
5138
5139 return nb_cli_apply_changes(vty, base_xpath);
5140}
5141
5142DEFUN_YANG(no_neighbor_passive,
5143 no_neighbor_passive_cmd,
5144 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
5145 NO_STR NEIGHBOR_STR
5146 NEIGHBOR_ADDR_STR2
5147 "Don't send open messages to this neighbor\n")
5148{
5149 int idx_peer = 2;
5150 char base_xpath[XPATH_MAXLEN];
5151
5152 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5153 sizeof(base_xpath), NULL)
5154 < 0)
5155 return CMD_WARNING_CONFIG_FAILED;
5156
5157 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY, "false");
5158
5159 return nb_cli_apply_changes(vty, base_xpath);
5160}
5161
5162/* neighbor shutdown. */
5163DEFUN_YANG(neighbor_shutdown_msg,
5164 neighbor_shutdown_msg_cmd,
5165 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5166 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5167 "Administratively shut down this neighbor\n"
5168 "Add a shutdown message (RFC 8203)\n"
5169 "Shutdown message\n")
5170{
5171 int idx_peer = 1;
5172 char base_xpath[XPATH_MAXLEN];
5173
5174 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5175 sizeof(base_xpath), NULL)
5176 < 0)
5177 return CMD_WARNING_CONFIG_FAILED;
5178
5179 if (argc >= 5) {
5180 char *message;
5181
5182 message = argv_concat(argv, argc, 4);
5183 nb_cli_enqueue_change(vty, "./admin-shutdown/message",
5184 NB_OP_MODIFY, message);
5185 }
5186
5187 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5188 "true");
5189
5190 return nb_cli_apply_changes(vty, base_xpath);
5191}
5192
5193ALIAS_YANG(neighbor_shutdown_msg, neighbor_shutdown_cmd,
5194 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5195 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5196 "Administratively shut down this neighbor\n")
5197
5198DEFUN_YANG(no_neighbor_shutdown_msg,
5199 no_neighbor_shutdown_msg_cmd,
5200 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
5201 NO_STR NEIGHBOR_STR
5202 NEIGHBOR_ADDR_STR2
5203 "Administratively shut down this neighbor\n"
5204 "Remove a shutdown message (RFC 8203)\n"
5205 "Shutdown message\n")
5206{
5207 int idx_peer = 2;
5208 char base_xpath[XPATH_MAXLEN];
5209
5210 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5211 sizeof(base_xpath), NULL)
5212 < 0)
5213 return CMD_WARNING_CONFIG_FAILED;
5214
5215 nb_cli_enqueue_change(vty, "./admin-shutdown/enable", NB_OP_MODIFY,
5216 "false");
5217
5218 return nb_cli_apply_changes(vty, base_xpath);
5219}
5220
5221ALIAS_YANG(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
5222 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
5223 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5224 "Administratively shut down this neighbor\n")
5225
5226DEFUN(neighbor_shutdown_rtt,
5227 neighbor_shutdown_rtt_cmd,
5228 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt (1-65535) [count (1-255)]",
5229 NEIGHBOR_STR
5230 NEIGHBOR_ADDR_STR2
5231 "Administratively shut down this neighbor\n"
5232 "Shutdown if round-trip-time is higher than expected\n"
5233 "Round-trip-time in milliseconds\n"
5234 "Specify the number of keepalives before shutdown\n"
5235 "The number of keepalives with higher RTT to shutdown\n")
5236{
5237 int idx_peer = 1;
5238 int idx_rtt = 4;
5239 int idx_count = 0;
5240 struct peer *peer;
5241
5242 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5243
5244 if (!peer)
5245 return CMD_WARNING_CONFIG_FAILED;
5246
5247 peer->rtt_expected = strtol(argv[idx_rtt]->arg, NULL, 10);
5248
5249 if (argv_find(argv, argc, "count", &idx_count))
5250 peer->rtt_keepalive_conf =
5251 strtol(argv[idx_count + 1]->arg, NULL, 10);
5252
5253 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5254 PEER_FLAG_RTT_SHUTDOWN);
5255}
5256
5257DEFUN(no_neighbor_shutdown_rtt,
5258 no_neighbor_shutdown_rtt_cmd,
5259 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown rtt [(1-65535) [count (1-255)]]",
5260 NO_STR
5261 NEIGHBOR_STR
5262 NEIGHBOR_ADDR_STR2
5263 "Administratively shut down this neighbor\n"
5264 "Shutdown if round-trip-time is higher than expected\n"
5265 "Round-trip-time in milliseconds\n"
5266 "Specify the number of keepalives before shutdown\n"
5267 "The number of keepalives with higher RTT to shutdown\n")
5268{
5269 int idx_peer = 2;
5270 struct peer *peer;
5271
5272 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5273
5274 if (!peer)
5275 return CMD_WARNING_CONFIG_FAILED;
5276
5277 peer->rtt_expected = 0;
5278 peer->rtt_keepalive_conf = 1;
5279
5280 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5281 PEER_FLAG_RTT_SHUTDOWN);
5282}
5283
5284/* neighbor capability dynamic. */
5285DEFUN_YANG (neighbor_capability_dynamic,
5286 neighbor_capability_dynamic_cmd,
5287 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5288 NEIGHBOR_STR
5289 NEIGHBOR_ADDR_STR2
5290 "Advertise capability to the peer\n"
5291 "Advertise dynamic capability to this neighbor\n")
5292{
5293 int idx_peer = 1;
5294 char base_xpath[XPATH_MAXLEN];
5295
5296 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5297 sizeof(base_xpath), NULL)
5298 < 0)
5299 return CMD_WARNING_CONFIG_FAILED;
5300
5301 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5302 NB_OP_MODIFY, "true");
5303
5304 return nb_cli_apply_changes(vty, base_xpath);
5305}
5306
5307DEFUN_YANG (no_neighbor_capability_dynamic,
5308 no_neighbor_capability_dynamic_cmd,
5309 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
5310 NO_STR
5311 NEIGHBOR_STR
5312 NEIGHBOR_ADDR_STR2
5313 "Advertise capability to the peer\n"
5314 "Advertise dynamic capability to this neighbor\n")
5315{
5316 int idx_peer = 2;
5317 char base_xpath[XPATH_MAXLEN];
5318
5319 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5320 sizeof(base_xpath), NULL)
5321 < 0)
5322 return CMD_WARNING_CONFIG_FAILED;
5323
5324 nb_cli_enqueue_change(vty, "./capability-options/dynamic-capability",
5325 NB_OP_MODIFY, "false");
5326
5327 return nb_cli_apply_changes(vty, base_xpath);
5328}
5329
5330/* neighbor dont-capability-negotiate */
5331DEFUN (neighbor_dont_capability_negotiate,
5332 neighbor_dont_capability_negotiate_cmd,
5333 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5334 NEIGHBOR_STR
5335 NEIGHBOR_ADDR_STR2
5336 "Do not perform capability negotiation\n")
5337{
5338 int idx_peer = 1;
5339 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5340 PEER_FLAG_DONT_CAPABILITY);
5341}
5342
5343DEFUN (no_neighbor_dont_capability_negotiate,
5344 no_neighbor_dont_capability_negotiate_cmd,
5345 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
5346 NO_STR
5347 NEIGHBOR_STR
5348 NEIGHBOR_ADDR_STR2
5349 "Do not perform capability negotiation\n")
5350{
5351 int idx_peer = 2;
5352 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5353 PEER_FLAG_DONT_CAPABILITY);
5354}
5355
5356/* neighbor capability extended next hop encoding */
5357DEFUN_YANG (neighbor_capability_enhe,
5358 neighbor_capability_enhe_cmd,
5359 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5360 NEIGHBOR_STR
5361 NEIGHBOR_ADDR_STR2
5362 "Advertise capability to the peer\n"
5363 "Advertise extended next-hop capability to the peer\n")
5364{
5365 int idx_peer = 1;
5366 char base_xpath[XPATH_MAXLEN];
5367
5368 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5369 sizeof(base_xpath), NULL)
5370 < 0)
5371 return CMD_WARNING_CONFIG_FAILED;
5372
5373 nb_cli_enqueue_change(
5374 vty, "./capability-options/extended-nexthop-capability",
5375 NB_OP_MODIFY, "true");
5376
5377 return nb_cli_apply_changes(vty, base_xpath);
5378}
5379
5380DEFUN_YANG (no_neighbor_capability_enhe,
5381 no_neighbor_capability_enhe_cmd,
5382 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
5383 NO_STR
5384 NEIGHBOR_STR
5385 NEIGHBOR_ADDR_STR2
5386 "Advertise capability to the peer\n"
5387 "Advertise extended next-hop capability to the peer\n")
5388{
5389 int idx_peer = 2;
5390 char base_xpath[XPATH_MAXLEN];
5391
5392 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5393 sizeof(base_xpath), NULL)
5394 < 0)
5395 return CMD_WARNING_CONFIG_FAILED;
5396
5397 nb_cli_enqueue_change(
5398 vty, "./capability-options/extended-nexthop-capability",
5399 NB_OP_MODIFY, "false");
5400
5401 return nb_cli_apply_changes(vty, base_xpath);
5402}
5403
5404int peer_af_flag_modify_nb(struct peer *peer, afi_t afi, safi_t safi,
5405 uint32_t flag, int set, char *errmsg,
5406 size_t errmsg_len)
5407{
5408 int ret;
5409
5410 if (set)
5411 ret = peer_af_flag_set(peer, afi, safi, flag);
5412 else
5413 ret = peer_af_flag_unset(peer, afi, safi, flag);
5414
5415 return bgp_nb_errmsg_return(errmsg, errmsg_len, ret);
5416}
5417
5418static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
5419 afi_t afi, safi_t safi, uint32_t flag,
5420 int set)
5421{
5422 int ret;
5423 struct peer *peer;
5424
5425 peer = peer_and_group_lookup_vty(vty, peer_str);
5426 if (!peer)
5427 return CMD_WARNING_CONFIG_FAILED;
5428
5429 if (set)
5430 ret = peer_af_flag_set(peer, afi, safi, flag);
5431 else
5432 ret = peer_af_flag_unset(peer, afi, safi, flag);
5433
5434 return bgp_vty_return(vty, ret);
5435}
5436
5437static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
5438 afi_t afi, safi_t safi, uint32_t flag)
5439{
5440 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
5441}
5442
5443static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
5444 afi_t afi, safi_t safi, uint32_t flag)
5445{
5446 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
5447}
5448
5449/* neighbor capability orf prefix-list. */
5450DEFUN (neighbor_capability_orf_prefix,
5451 neighbor_capability_orf_prefix_cmd,
5452 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5453 NEIGHBOR_STR
5454 NEIGHBOR_ADDR_STR2
5455 "Advertise capability to the peer\n"
5456 "Advertise ORF capability to the peer\n"
5457 "Advertise prefixlist ORF capability to this neighbor\n"
5458 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5459 "Capability to RECEIVE the ORF from this neighbor\n"
5460 "Capability to SEND the ORF to this neighbor\n")
5461{
5462 int idx_send_recv = 5;
5463 char *peer_str = argv[1]->arg;
5464 struct peer *peer;
5465 afi_t afi = bgp_node_afi(vty);
5466 safi_t safi = bgp_node_safi(vty);
5467
5468 peer = peer_and_group_lookup_vty(vty, peer_str);
5469 if (!peer)
5470 return CMD_WARNING_CONFIG_FAILED;
5471
5472 if (strmatch(argv[idx_send_recv]->text, "send"))
5473 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5474 PEER_FLAG_ORF_PREFIX_SM);
5475
5476 if (strmatch(argv[idx_send_recv]->text, "receive"))
5477 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5478 PEER_FLAG_ORF_PREFIX_RM);
5479
5480 if (strmatch(argv[idx_send_recv]->text, "both"))
5481 return peer_af_flag_set_vty(vty, peer_str, afi, safi,
5482 PEER_FLAG_ORF_PREFIX_SM)
5483 | peer_af_flag_set_vty(vty, peer_str, afi, safi,
5484 PEER_FLAG_ORF_PREFIX_RM);
5485
5486 return CMD_WARNING_CONFIG_FAILED;
5487}
5488
5489ALIAS_HIDDEN(
5490 neighbor_capability_orf_prefix,
5491 neighbor_capability_orf_prefix_hidden_cmd,
5492 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5493 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5494 "Advertise capability to the peer\n"
5495 "Advertise ORF capability to the peer\n"
5496 "Advertise prefixlist ORF capability to this neighbor\n"
5497 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5498 "Capability to RECEIVE the ORF from this neighbor\n"
5499 "Capability to SEND the ORF to this neighbor\n")
5500
5501DEFUN (no_neighbor_capability_orf_prefix,
5502 no_neighbor_capability_orf_prefix_cmd,
5503 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5504 NO_STR
5505 NEIGHBOR_STR
5506 NEIGHBOR_ADDR_STR2
5507 "Advertise capability to the peer\n"
5508 "Advertise ORF capability to the peer\n"
5509 "Advertise prefixlist ORF capability to this neighbor\n"
5510 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5511 "Capability to RECEIVE the ORF from this neighbor\n"
5512 "Capability to SEND the ORF to this neighbor\n")
5513{
5514 int idx_send_recv = 6;
5515 char *peer_str = argv[2]->arg;
5516 struct peer *peer;
5517 afi_t afi = bgp_node_afi(vty);
5518 safi_t safi = bgp_node_safi(vty);
5519
5520 peer = peer_and_group_lookup_vty(vty, peer_str);
5521 if (!peer)
5522 return CMD_WARNING_CONFIG_FAILED;
5523
5524 if (strmatch(argv[idx_send_recv]->text, "send"))
5525 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5526 PEER_FLAG_ORF_PREFIX_SM);
5527
5528 if (strmatch(argv[idx_send_recv]->text, "receive"))
5529 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5530 PEER_FLAG_ORF_PREFIX_RM);
5531
5532 if (strmatch(argv[idx_send_recv]->text, "both"))
5533 return peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5534 PEER_FLAG_ORF_PREFIX_SM)
5535 | peer_af_flag_unset_vty(vty, peer_str, afi, safi,
5536 PEER_FLAG_ORF_PREFIX_RM);
5537
5538 return CMD_WARNING_CONFIG_FAILED;
5539}
5540
5541ALIAS_HIDDEN(
5542 no_neighbor_capability_orf_prefix,
5543 no_neighbor_capability_orf_prefix_hidden_cmd,
5544 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
5545 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5546 "Advertise capability to the peer\n"
5547 "Advertise ORF capability to the peer\n"
5548 "Advertise prefixlist ORF capability to this neighbor\n"
5549 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
5550 "Capability to RECEIVE the ORF from this neighbor\n"
5551 "Capability to SEND the ORF to this neighbor\n")
5552
5553/* neighbor next-hop-self. */
5554DEFUN_YANG (neighbor_nexthop_self,
5555 neighbor_nexthop_self_cmd,
5556 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5557 NEIGHBOR_STR
5558 NEIGHBOR_ADDR_STR2
5559 "Disable the next hop calculation for this neighbor\n")
5560{
5561 int idx_peer = 1;
5562 char base_xpath[XPATH_MAXLEN];
5563 char af_xpath[XPATH_MAXLEN];
5564 char attr_xpath[XPATH_MAXLEN];
5565 afi_t afi = bgp_node_afi(vty);
5566 safi_t safi = bgp_node_safi(vty);
5567
5568 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5569 yang_afi_safi_value2identity(afi, safi));
5570
5571 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5572 sizeof(base_xpath), af_xpath)
5573 < 0)
5574 return CMD_WARNING_CONFIG_FAILED;
5575
5576 snprintf(attr_xpath, sizeof(attr_xpath),
5577 "./%s/nexthop-self/next-hop-self",
5578 bgp_afi_safi_get_container_str(afi, safi));
5579
5580 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5581
5582 return nb_cli_apply_changes(vty, base_xpath);
5583}
5584
5585ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
5586 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5587 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5588 "Disable the next hop calculation for this neighbor\n")
5589
5590/* neighbor next-hop-self. */
5591DEFUN_YANG(neighbor_nexthop_self_force,
5592 neighbor_nexthop_self_force_cmd,
5593 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5594 NEIGHBOR_STR
5595 NEIGHBOR_ADDR_STR2
5596 "Disable the next hop calculation for this neighbor\n"
5597 "Set the next hop to self for reflected routes\n")
5598{
5599 int idx_peer = 1;
5600 char base_xpath[XPATH_MAXLEN];
5601 char af_xpath[XPATH_MAXLEN];
5602 char attr_xpath[XPATH_MAXLEN];
5603 afi_t afi = bgp_node_afi(vty);
5604 safi_t safi = bgp_node_safi(vty);
5605
5606 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5607 yang_afi_safi_value2identity(afi, safi));
5608
5609 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5610 sizeof(base_xpath), af_xpath)
5611 < 0)
5612 return CMD_WARNING_CONFIG_FAILED;
5613
5614 snprintf(attr_xpath, sizeof(attr_xpath),
5615 "./%s/nexthop-self/next-hop-self-force",
5616 bgp_afi_safi_get_container_str(afi, safi));
5617
5618 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5619
5620 return nb_cli_apply_changes(vty, base_xpath);
5621}
5622
5623ALIAS_HIDDEN(neighbor_nexthop_self_force,
5624 neighbor_nexthop_self_force_hidden_cmd,
5625 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5626 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5627 "Disable the next hop calculation for this neighbor\n"
5628 "Set the next hop to self for reflected routes\n")
5629
5630ALIAS_HIDDEN(neighbor_nexthop_self_force,
5631 neighbor_nexthop_self_all_hidden_cmd,
5632 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5633 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5634 "Disable the next hop calculation for this neighbor\n"
5635 "Set the next hop to self for reflected routes\n")
5636
5637DEFUN_YANG (no_neighbor_nexthop_self,
5638 no_neighbor_nexthop_self_cmd,
5639 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5640 NO_STR
5641 NEIGHBOR_STR
5642 NEIGHBOR_ADDR_STR2
5643 "Disable the next hop calculation for this neighbor\n")
5644{
5645 int idx_peer = 2;
5646 char base_xpath[XPATH_MAXLEN];
5647 char af_xpath[XPATH_MAXLEN];
5648 char attr_xpath[XPATH_MAXLEN];
5649 afi_t afi = bgp_node_afi(vty);
5650 safi_t safi = bgp_node_safi(vty);
5651
5652 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5653 yang_afi_safi_value2identity(afi, safi));
5654
5655 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5656 sizeof(base_xpath), af_xpath)
5657 < 0)
5658 return CMD_WARNING_CONFIG_FAILED;
5659
5660 snprintf(attr_xpath, sizeof(attr_xpath),
5661 "./%s/nexthop-self/next-hop-self",
5662 bgp_afi_safi_get_container_str(afi, safi));
5663
5664 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5665
5666 return nb_cli_apply_changes(vty, base_xpath);
5667}
5668
5669ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
5670 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
5671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5672 "Disable the next hop calculation for this neighbor\n")
5673
5674DEFUN_YANG (no_neighbor_nexthop_self_force,
5675 no_neighbor_nexthop_self_force_cmd,
5676 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5677 NO_STR
5678 NEIGHBOR_STR
5679 NEIGHBOR_ADDR_STR2
5680 "Disable the next hop calculation for this neighbor\n"
5681 "Set the next hop to self for reflected routes\n")
5682{
5683 int idx_peer = 2;
5684 char base_xpath[XPATH_MAXLEN];
5685 char af_xpath[XPATH_MAXLEN];
5686 char attr_xpath[XPATH_MAXLEN];
5687 afi_t afi = bgp_node_afi(vty);
5688 safi_t safi = bgp_node_safi(vty);
5689
5690 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5691 yang_afi_safi_value2identity(afi, safi));
5692
5693 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5694 sizeof(base_xpath), af_xpath)
5695 < 0)
5696 return CMD_WARNING_CONFIG_FAILED;
5697
5698 snprintf(attr_xpath, sizeof(attr_xpath),
5699 "./%s/nexthop-self/next-hop-self-force",
5700 bgp_afi_safi_get_container_str(afi, safi));
5701
5702 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5703
5704 return nb_cli_apply_changes(vty, base_xpath);
5705}
5706
5707ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5708 no_neighbor_nexthop_self_force_hidden_cmd,
5709 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
5710 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5711 "Disable the next hop calculation for this neighbor\n"
5712 "Set the next hop to self for reflected routes\n")
5713
5714ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
5715 no_neighbor_nexthop_self_all_hidden_cmd,
5716 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
5717 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5718 "Disable the next hop calculation for this neighbor\n"
5719 "Set the next hop to self for reflected routes\n")
5720
5721/* neighbor as-override */
5722DEFUN_YANG (neighbor_as_override,
5723 neighbor_as_override_cmd,
5724 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5725 NEIGHBOR_STR
5726 NEIGHBOR_ADDR_STR2
5727 "Override ASNs in outbound updates if aspath equals remote-as\n")
5728{
5729 int idx_peer = 1;
5730 char base_xpath[XPATH_MAXLEN];
5731 char af_xpath[XPATH_MAXLEN];
5732 char attr_xpath[XPATH_MAXLEN];
5733 afi_t afi = bgp_node_afi(vty);
5734 safi_t safi = bgp_node_safi(vty);
5735
5736 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5737 yang_afi_safi_value2identity(afi, safi));
5738
5739 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5740 sizeof(base_xpath), af_xpath)
5741 < 0)
5742 return CMD_WARNING_CONFIG_FAILED;
5743
5744 snprintf(attr_xpath, sizeof(attr_xpath),
5745 "./%s/as-path-options/replace-peer-as",
5746 bgp_afi_safi_get_container_str(afi, safi));
5747
5748 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5749
5750 return nb_cli_apply_changes(vty, base_xpath);
5751}
5752
5753ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
5754 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5755 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5756 "Override ASNs in outbound updates if aspath equals remote-as\n")
5757
5758DEFUN_YANG (no_neighbor_as_override,
5759 no_neighbor_as_override_cmd,
5760 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5761 NO_STR
5762 NEIGHBOR_STR
5763 NEIGHBOR_ADDR_STR2
5764 "Override ASNs in outbound updates if aspath equals remote-as\n")
5765{
5766 int idx_peer = 2;
5767 char base_xpath[XPATH_MAXLEN];
5768 char af_xpath[XPATH_MAXLEN];
5769 char attr_xpath[XPATH_MAXLEN];
5770 afi_t afi = bgp_node_afi(vty);
5771 safi_t safi = bgp_node_safi(vty);
5772
5773 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5774 yang_afi_safi_value2identity(afi, safi));
5775
5776 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5777 sizeof(base_xpath), af_xpath)
5778 < 0)
5779 return CMD_WARNING_CONFIG_FAILED;
5780
5781 snprintf(attr_xpath, sizeof(attr_xpath),
5782 "./%s/as-path-options/replace-peer-as",
5783 bgp_afi_safi_get_container_str(afi, safi));
5784
5785 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5786
5787 return nb_cli_apply_changes(vty, base_xpath);
5788}
5789
5790ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
5791 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
5792 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5793 "Override ASNs in outbound updates if aspath equals remote-as\n")
5794
5795/* neighbor remove-private-AS. */
5796DEFUN_YANG (neighbor_remove_private_as,
5797 neighbor_remove_private_as_cmd,
5798 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5799 NEIGHBOR_STR
5800 NEIGHBOR_ADDR_STR2
5801 "Remove private ASNs in outbound updates\n")
5802{
5803 int idx_peer = 1;
5804 char base_xpath[XPATH_MAXLEN];
5805 char af_xpath[XPATH_MAXLEN];
5806 char attr_xpath[XPATH_MAXLEN];
5807 afi_t afi = bgp_node_afi(vty);
5808 safi_t safi = bgp_node_safi(vty);
5809
5810 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5811 yang_afi_safi_value2identity(afi, safi));
5812
5813 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5814 sizeof(base_xpath), af_xpath)
5815 < 0)
5816 return CMD_WARNING_CONFIG_FAILED;
5817
5818 snprintf(attr_xpath, sizeof(attr_xpath),
5819 "./%s/private-as/remove-private-as",
5820 bgp_afi_safi_get_container_str(afi, safi));
5821
5822 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5823
5824 return nb_cli_apply_changes(vty, base_xpath);
5825}
5826
5827ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
5828 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5829 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5830 "Remove private ASNs in outbound updates\n")
5831
5832DEFUN_YANG (neighbor_remove_private_as_all,
5833 neighbor_remove_private_as_all_cmd,
5834 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5835 NEIGHBOR_STR
5836 NEIGHBOR_ADDR_STR2
5837 "Remove private ASNs in outbound updates\n"
5838 "Apply to all AS numbers\n")
5839{
5840 int idx_peer = 1;
5841 char base_xpath[XPATH_MAXLEN];
5842 char af_xpath[XPATH_MAXLEN];
5843 char attr_xpath[XPATH_MAXLEN];
5844 afi_t afi = bgp_node_afi(vty);
5845 safi_t safi = bgp_node_safi(vty);
5846
5847 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5848 yang_afi_safi_value2identity(afi, safi));
5849
5850 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5851 sizeof(base_xpath), af_xpath)
5852 < 0)
5853 return CMD_WARNING_CONFIG_FAILED;
5854
5855 snprintf(attr_xpath, sizeof(attr_xpath),
5856 "./%s/private-as/remove-private-as-all",
5857 bgp_afi_safi_get_container_str(afi, safi));
5858
5859 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5860
5861 return nb_cli_apply_changes(vty, base_xpath);
5862}
5863
5864ALIAS_HIDDEN(neighbor_remove_private_as_all,
5865 neighbor_remove_private_as_all_hidden_cmd,
5866 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5867 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5868 "Remove private ASNs in outbound updates\n"
5869 "Apply to all AS numbers")
5870
5871DEFUN_YANG (neighbor_remove_private_as_replace_as,
5872 neighbor_remove_private_as_replace_as_cmd,
5873 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5874 NEIGHBOR_STR
5875 NEIGHBOR_ADDR_STR2
5876 "Remove private ASNs in outbound updates\n"
5877 "Replace private ASNs with our ASN in outbound updates\n")
5878{
5879 int idx_peer = 1;
5880 char base_xpath[XPATH_MAXLEN];
5881 char af_xpath[XPATH_MAXLEN];
5882 char attr_xpath[XPATH_MAXLEN];
5883 afi_t afi = bgp_node_afi(vty);
5884 safi_t safi = bgp_node_safi(vty);
5885
5886 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5887 yang_afi_safi_value2identity(afi, safi));
5888
5889 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5890 sizeof(base_xpath), af_xpath)
5891 < 0)
5892 return CMD_WARNING_CONFIG_FAILED;
5893
5894 snprintf(attr_xpath, sizeof(attr_xpath),
5895 "./%s/private-as/remove-private-as-replace",
5896 bgp_afi_safi_get_container_str(afi, safi));
5897
5898 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5899
5900 return nb_cli_apply_changes(vty, base_xpath);
5901}
5902
5903ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
5904 neighbor_remove_private_as_replace_as_hidden_cmd,
5905 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5906 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5907 "Remove private ASNs in outbound updates\n"
5908 "Replace private ASNs with our ASN in outbound updates\n")
5909
5910DEFUN_YANG (neighbor_remove_private_as_all_replace_as,
5911 neighbor_remove_private_as_all_replace_as_cmd,
5912 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5913 NEIGHBOR_STR
5914 NEIGHBOR_ADDR_STR2
5915 "Remove private ASNs in outbound updates\n"
5916 "Apply to all AS numbers\n"
5917 "Replace private ASNs with our ASN in outbound updates\n")
5918{
5919 int idx_peer = 1;
5920 char base_xpath[XPATH_MAXLEN];
5921 char af_xpath[XPATH_MAXLEN];
5922 char attr_xpath[XPATH_MAXLEN];
5923 afi_t afi = bgp_node_afi(vty);
5924 safi_t safi = bgp_node_safi(vty);
5925
5926 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5927 yang_afi_safi_value2identity(afi, safi));
5928
5929 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5930 sizeof(base_xpath), af_xpath)
5931 < 0)
5932 return CMD_WARNING_CONFIG_FAILED;
5933
5934 snprintf(attr_xpath, sizeof(attr_xpath),
5935 "./%s/private-as/remove-private-as-all-replace",
5936 bgp_afi_safi_get_container_str(afi, safi));
5937
5938 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
5939
5940 return nb_cli_apply_changes(vty, base_xpath);
5941}
5942
5943ALIAS_HIDDEN(
5944 neighbor_remove_private_as_all_replace_as,
5945 neighbor_remove_private_as_all_replace_as_hidden_cmd,
5946 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Remove private ASNs in outbound updates\n"
5949 "Apply to all AS numbers\n"
5950 "Replace private ASNs with our ASN in outbound updates\n")
5951
5952DEFUN_YANG (no_neighbor_remove_private_as,
5953 no_neighbor_remove_private_as_cmd,
5954 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5955 NO_STR
5956 NEIGHBOR_STR
5957 NEIGHBOR_ADDR_STR2
5958 "Remove private ASNs in outbound updates\n")
5959{
5960 int idx_peer = 2;
5961 char base_xpath[XPATH_MAXLEN];
5962 char af_xpath[XPATH_MAXLEN];
5963 char attr_xpath[XPATH_MAXLEN];
5964 afi_t afi = bgp_node_afi(vty);
5965 safi_t safi = bgp_node_safi(vty);
5966
5967 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
5968 yang_afi_safi_value2identity(afi, safi));
5969
5970 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
5971 sizeof(base_xpath), af_xpath)
5972 < 0)
5973 return CMD_WARNING_CONFIG_FAILED;
5974
5975 snprintf(attr_xpath, sizeof(attr_xpath),
5976 "./%s/private-as/remove-private-as",
5977 bgp_afi_safi_get_container_str(afi, safi));
5978
5979 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
5980
5981 return nb_cli_apply_changes(vty, base_xpath);
5982}
5983
5984ALIAS_HIDDEN(no_neighbor_remove_private_as,
5985 no_neighbor_remove_private_as_hidden_cmd,
5986 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
5987 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5988 "Remove private ASNs in outbound updates\n")
5989
5990DEFUN_YANG (no_neighbor_remove_private_as_all,
5991 no_neighbor_remove_private_as_all_cmd,
5992 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5993 NO_STR
5994 NEIGHBOR_STR
5995 NEIGHBOR_ADDR_STR2
5996 "Remove private ASNs in outbound updates\n"
5997 "Apply to all AS numbers\n")
5998{
5999 int idx_peer = 2;
6000 char base_xpath[XPATH_MAXLEN];
6001 char af_xpath[XPATH_MAXLEN];
6002 char attr_xpath[XPATH_MAXLEN];
6003 afi_t afi = bgp_node_afi(vty);
6004 safi_t safi = bgp_node_safi(vty);
6005
6006 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6007 yang_afi_safi_value2identity(afi, safi));
6008
6009 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6010 sizeof(base_xpath), af_xpath)
6011 < 0)
6012 return CMD_WARNING_CONFIG_FAILED;
6013
6014 snprintf(attr_xpath, sizeof(attr_xpath),
6015 "./%s/private-as/remove-private-as-all",
6016 bgp_afi_safi_get_container_str(afi, safi));
6017
6018 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6019
6020 return nb_cli_apply_changes(vty, base_xpath);
6021}
6022
6023ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
6024 no_neighbor_remove_private_as_all_hidden_cmd,
6025 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
6026 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6027 "Remove private ASNs in outbound updates\n"
6028 "Apply to all AS numbers\n")
6029
6030DEFUN_YANG (no_neighbor_remove_private_as_replace_as,
6031 no_neighbor_remove_private_as_replace_as_cmd,
6032 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6033 NO_STR
6034 NEIGHBOR_STR
6035 NEIGHBOR_ADDR_STR2
6036 "Remove private ASNs in outbound updates\n"
6037 "Replace private ASNs with our ASN in outbound updates\n")
6038{
6039 int idx_peer = 2;
6040 char base_xpath[XPATH_MAXLEN];
6041 char af_xpath[XPATH_MAXLEN];
6042 char attr_xpath[XPATH_MAXLEN];
6043 afi_t afi = bgp_node_afi(vty);
6044 safi_t safi = bgp_node_safi(vty);
6045
6046 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6047 yang_afi_safi_value2identity(afi, safi));
6048
6049 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6050 sizeof(base_xpath), af_xpath)
6051 < 0)
6052 return CMD_WARNING_CONFIG_FAILED;
6053
6054 snprintf(attr_xpath, sizeof(attr_xpath),
6055 "./%s/private-as/remove-private-as-replace",
6056 bgp_afi_safi_get_container_str(afi, safi));
6057
6058 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6059
6060 return nb_cli_apply_changes(vty, base_xpath);
6061}
6062
6063ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
6064 no_neighbor_remove_private_as_replace_as_hidden_cmd,
6065 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
6066 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6067 "Remove private ASNs in outbound updates\n"
6068 "Replace private ASNs with our ASN in outbound updates\n")
6069
6070DEFUN_YANG (no_neighbor_remove_private_as_all_replace_as,
6071 no_neighbor_remove_private_as_all_replace_as_cmd,
6072 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6073 NO_STR
6074 NEIGHBOR_STR
6075 NEIGHBOR_ADDR_STR2
6076 "Remove private ASNs in outbound updates\n"
6077 "Apply to all AS numbers\n"
6078 "Replace private ASNs with our ASN in outbound updates\n")
6079{
6080 int idx_peer = 2;
6081 char base_xpath[XPATH_MAXLEN];
6082 char af_xpath[XPATH_MAXLEN];
6083 char attr_xpath[XPATH_MAXLEN];
6084 afi_t afi = bgp_node_afi(vty);
6085 safi_t safi = bgp_node_safi(vty);
6086
6087 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6088 yang_afi_safi_value2identity(afi, safi));
6089
6090 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6091 sizeof(base_xpath), af_xpath)
6092 < 0)
6093 return CMD_WARNING_CONFIG_FAILED;
6094
6095 snprintf(attr_xpath, sizeof(attr_xpath),
6096 "./%s/private-as/remove-private-as-all-replace",
6097 bgp_afi_safi_get_container_str(afi, safi));
6098
6099 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6100
6101 return nb_cli_apply_changes(vty, base_xpath);
6102}
6103
6104ALIAS_HIDDEN(
6105 no_neighbor_remove_private_as_all_replace_as,
6106 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
6107 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
6108 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6109 "Remove private ASNs in outbound updates\n"
6110 "Apply to all AS numbers\n"
6111 "Replace private ASNs with our ASN in outbound updates\n")
6112
6113
6114/* neighbor send-community. */
6115DEFUN_YANG (neighbor_send_community,
6116 neighbor_send_community_cmd,
6117 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6118 NEIGHBOR_STR
6119 NEIGHBOR_ADDR_STR2
6120 "Send Community attribute to this neighbor\n")
6121{
6122 int idx_peer = 1;
6123
6124 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6125 bgp_node_safi(vty),
6126 PEER_FLAG_SEND_COMMUNITY);
6127}
6128
6129ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
6130 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6132 "Send Community attribute to this neighbor\n")
6133
6134DEFUN_YANG (no_neighbor_send_community,
6135 no_neighbor_send_community_cmd,
6136 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6137 NO_STR
6138 NEIGHBOR_STR
6139 NEIGHBOR_ADDR_STR2
6140 "Send Community attribute to this neighbor\n")
6141{
6142 int idx_peer = 2;
6143
6144 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6145 bgp_node_afi(vty), bgp_node_safi(vty),
6146 PEER_FLAG_SEND_COMMUNITY);
6147}
6148
6149ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
6150 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
6151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6152 "Send Community attribute to this neighbor\n")
6153
6154/* neighbor send-community extended. */
6155DEFUN_YANG (neighbor_send_community_type,
6156 neighbor_send_community_type_cmd,
6157 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6158 NEIGHBOR_STR
6159 NEIGHBOR_ADDR_STR2
6160 "Send Community attribute to this neighbor\n"
6161 "Send Standard and Extended Community attributes\n"
6162 "Send Standard, Large and Extended Community attributes\n"
6163 "Send Extended Community attributes\n"
6164 "Send Standard Community attributes\n"
6165 "Send Large Community attributes\n")
6166{
6167 const char *type = argv[argc - 1]->text;
6168 char *peer_str = argv[1]->arg;
6169 char base_xpath[XPATH_MAXLEN];
6170 char af_xpath[XPATH_MAXLEN];
6171 char std_xpath[XPATH_MAXLEN];
6172 char ext_xpath[XPATH_MAXLEN];
6173 char lrg_xpath[XPATH_MAXLEN];
6174 afi_t afi = bgp_node_afi(vty);
6175 safi_t safi = bgp_node_safi(vty);
6176
6177 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6178 yang_afi_safi_value2identity(afi, safi));
6179
6180 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6181 sizeof(base_xpath), af_xpath)
6182 < 0)
6183 return CMD_WARNING_CONFIG_FAILED;
6184
6185 if (strmatch(type, "standard")) {
6186 snprintf(std_xpath, sizeof(std_xpath),
6187 "./%s/send-community/send-community",
6188 bgp_afi_safi_get_container_str(afi, safi));
6189
6190 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6191 }
6192
6193 if (strmatch(type, "extended")) {
6194 snprintf(ext_xpath, sizeof(ext_xpath),
6195 "./%s/send-community/send-ext-community",
6196 bgp_afi_safi_get_container_str(afi, safi));
6197
6198 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6199 }
6200
6201 if (strmatch(type, "large")) {
6202 snprintf(lrg_xpath, sizeof(lrg_xpath),
6203 "./%s/send-community/send-large-community",
6204 bgp_afi_safi_get_container_str(afi, safi));
6205
6206 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6207 }
6208
6209 if (strmatch(type, "both")) {
6210 snprintf(std_xpath, sizeof(std_xpath),
6211 "./%s/send-community/send-community",
6212 bgp_afi_safi_get_container_str(afi, safi));
6213
6214 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6215
6216 snprintf(ext_xpath, sizeof(ext_xpath),
6217 "./%s/send-community/send-ext-community",
6218 bgp_afi_safi_get_container_str(afi, safi));
6219
6220 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6221 }
6222
6223 if (strmatch(type, "all")) {
6224 snprintf(std_xpath, sizeof(std_xpath),
6225 "./%s/send-community/send-community",
6226 bgp_afi_safi_get_container_str(afi, safi));
6227
6228 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "true");
6229
6230 snprintf(ext_xpath, sizeof(ext_xpath),
6231 "./%s/send-community/send-ext-community",
6232 bgp_afi_safi_get_container_str(afi, safi));
6233
6234 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "true");
6235
6236 snprintf(lrg_xpath, sizeof(lrg_xpath),
6237 "./%s/send-community/send-large-community",
6238 bgp_afi_safi_get_container_str(afi, safi));
6239
6240 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "true");
6241 }
6242
6243 return nb_cli_apply_changes(vty, base_xpath);
6244}
6245
6246ALIAS_HIDDEN(
6247 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
6248 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6250 "Send Community attribute to this neighbor\n"
6251 "Send Standard and Extended Community attributes\n"
6252 "Send Standard, Large and Extended Community attributes\n"
6253 "Send Extended Community attributes\n"
6254 "Send Standard Community attributes\n"
6255 "Send Large Community attributes\n")
6256
6257DEFUN_YANG (no_neighbor_send_community_type,
6258 no_neighbor_send_community_type_cmd,
6259 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6260 NO_STR
6261 NEIGHBOR_STR
6262 NEIGHBOR_ADDR_STR2
6263 "Send Community attribute to this neighbor\n"
6264 "Send Standard and Extended Community attributes\n"
6265 "Send Standard, Large and Extended Community attributes\n"
6266 "Send Extended Community attributes\n"
6267 "Send Standard Community attributes\n"
6268 "Send Large Community attributes\n")
6269{
6270 const char *type = argv[argc - 1]->text;
6271 char *peer_str = argv[2]->arg;
6272 char base_xpath[XPATH_MAXLEN];
6273 char af_xpath[XPATH_MAXLEN];
6274 char std_xpath[XPATH_MAXLEN];
6275 char ext_xpath[XPATH_MAXLEN];
6276 char lrg_xpath[XPATH_MAXLEN];
6277 afi_t afi = bgp_node_afi(vty);
6278 safi_t safi = bgp_node_safi(vty);
6279
6280 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6281 yang_afi_safi_value2identity(afi, safi));
6282
6283 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6284 sizeof(base_xpath), af_xpath)
6285 < 0)
6286 return CMD_WARNING_CONFIG_FAILED;
6287
6288 if (strmatch(type, "standard")) {
6289 snprintf(std_xpath, sizeof(std_xpath),
6290 "./%s/send-community/send-community",
6291 bgp_afi_safi_get_container_str(afi, safi));
6292
6293 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6294 }
6295
6296 if (strmatch(type, "extended")) {
6297 snprintf(ext_xpath, sizeof(ext_xpath),
6298 "./%s/send-community/send-ext-community",
6299 bgp_afi_safi_get_container_str(afi, safi));
6300
6301 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6302 }
6303
6304 if (strmatch(type, "large")) {
6305 snprintf(lrg_xpath, sizeof(lrg_xpath),
6306 "./%s/send-community/send-large-community",
6307 bgp_afi_safi_get_container_str(afi, safi));
6308
6309 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6310 }
6311
6312 if (strmatch(type, "both")) {
6313 snprintf(std_xpath, sizeof(std_xpath),
6314 "./%s/send-community/send-community",
6315 bgp_afi_safi_get_container_str(afi, safi));
6316
6317 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6318
6319 snprintf(ext_xpath, sizeof(ext_xpath),
6320 "./%s/send-community/send-ext-community",
6321 bgp_afi_safi_get_container_str(afi, safi));
6322
6323 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6324 }
6325
6326 if (strmatch(type, "all")) {
6327 snprintf(std_xpath, sizeof(std_xpath),
6328 "./%s/send-community/send-community",
6329 bgp_afi_safi_get_container_str(afi, safi));
6330
6331 nb_cli_enqueue_change(vty, std_xpath, NB_OP_MODIFY, "false");
6332
6333 snprintf(ext_xpath, sizeof(ext_xpath),
6334 "./%s/send-community/send-ext-community",
6335 bgp_afi_safi_get_container_str(afi, safi));
6336
6337 nb_cli_enqueue_change(vty, ext_xpath, NB_OP_MODIFY, "false");
6338
6339 snprintf(lrg_xpath, sizeof(lrg_xpath),
6340 "./%s/send-community/send-large-community",
6341 bgp_afi_safi_get_container_str(afi, safi));
6342
6343 nb_cli_enqueue_change(vty, lrg_xpath, NB_OP_MODIFY, "false");
6344 }
6345
6346 return nb_cli_apply_changes(vty, base_xpath);
6347}
6348
6349ALIAS_HIDDEN(
6350 no_neighbor_send_community_type,
6351 no_neighbor_send_community_type_hidden_cmd,
6352 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
6353 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6354 "Send Community attribute to this neighbor\n"
6355 "Send Standard and Extended Community attributes\n"
6356 "Send Standard, Large and Extended Community attributes\n"
6357 "Send Extended Community attributes\n"
6358 "Send Standard Community attributes\n"
6359 "Send Large Community attributes\n")
6360
6361/* neighbor soft-reconfig. */
6362DEFUN_YANG (neighbor_soft_reconfiguration,
6363 neighbor_soft_reconfiguration_cmd,
6364 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6365 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6366 "Per neighbor soft reconfiguration\n"
6367 "Allow inbound soft reconfiguration for this neighbor\n")
6368{
6369 int idx_peer = 1;
6370 char base_xpath[XPATH_MAXLEN];
6371 char af_xpath[XPATH_MAXLEN];
6372 char soft_xpath[XPATH_MAXLEN];
6373 afi_t afi = bgp_node_afi(vty);
6374 safi_t safi = bgp_node_safi(vty);
6375
6376 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6377 yang_afi_safi_value2identity(afi, safi));
6378
6379 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6380 sizeof(base_xpath), af_xpath)
6381 < 0)
6382 return CMD_WARNING_CONFIG_FAILED;
6383
6384 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6385 bgp_afi_safi_get_container_str(afi, safi));
6386
6387 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "true");
6388
6389 return nb_cli_apply_changes(vty, base_xpath);
6390}
6391
6392ALIAS_HIDDEN(neighbor_soft_reconfiguration,
6393 neighbor_soft_reconfiguration_hidden_cmd,
6394 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6395 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6396 "Per neighbor soft reconfiguration\n"
6397 "Allow inbound soft reconfiguration for this neighbor\n")
6398
6399DEFUN_YANG (no_neighbor_soft_reconfiguration,
6400 no_neighbor_soft_reconfiguration_cmd,
6401 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6402 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6403 "Per neighbor soft reconfiguration\n"
6404 "Allow inbound soft reconfiguration for this neighbor\n")
6405{
6406 int idx_peer = 2;
6407 char base_xpath[XPATH_MAXLEN];
6408 char af_xpath[XPATH_MAXLEN];
6409 char soft_xpath[XPATH_MAXLEN];
6410 afi_t afi = bgp_node_afi(vty);
6411 safi_t safi = bgp_node_safi(vty);
6412
6413 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6414 yang_afi_safi_value2identity(afi, safi));
6415
6416 snprintf(soft_xpath, sizeof(soft_xpath), "./%s/soft-reconfiguration",
6417 bgp_afi_safi_get_container_str(afi, safi));
6418
6419 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6420 sizeof(base_xpath), af_xpath)
6421 < 0)
6422 return CMD_WARNING_CONFIG_FAILED;
6423
6424 nb_cli_enqueue_change(vty, soft_xpath, NB_OP_MODIFY, "false");
6425
6426 return nb_cli_apply_changes(vty, base_xpath);
6427}
6428
6429ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
6430 no_neighbor_soft_reconfiguration_hidden_cmd,
6431 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
6432 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6433 "Per neighbor soft reconfiguration\n"
6434 "Allow inbound soft reconfiguration for this neighbor\n")
6435
6436DEFUN_YANG (neighbor_route_reflector_client,
6437 neighbor_route_reflector_client_cmd,
6438 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6439 NEIGHBOR_STR
6440 NEIGHBOR_ADDR_STR2
6441 "Configure a neighbor as Route Reflector client\n")
6442{
6443 int idx_peer = 1;
6444 char base_xpath[XPATH_MAXLEN];
6445 char af_xpath[XPATH_MAXLEN];
6446 char attr_xpath[XPATH_MAXLEN];
6447 afi_t afi = bgp_node_afi(vty);
6448 safi_t safi = bgp_node_safi(vty);
6449
6450 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6451 yang_afi_safi_value2identity(afi, safi));
6452
6453 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6454 sizeof(base_xpath), af_xpath)
6455 < 0)
6456 return CMD_WARNING_CONFIG_FAILED;
6457
6458 snprintf(attr_xpath, sizeof(attr_xpath),
6459 "./%s/route-reflector/route-reflector-client",
6460 bgp_afi_safi_get_container_str(afi, safi));
6461
6462 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6463
6464 return nb_cli_apply_changes(vty, base_xpath);
6465}
6466
6467ALIAS_HIDDEN(neighbor_route_reflector_client,
6468 neighbor_route_reflector_client_hidden_cmd,
6469 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6470 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6471 "Configure a neighbor as Route Reflector client\n")
6472
6473DEFUN_YANG (no_neighbor_route_reflector_client,
6474 no_neighbor_route_reflector_client_cmd,
6475 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6476 NO_STR
6477 NEIGHBOR_STR
6478 NEIGHBOR_ADDR_STR2
6479 "Configure a neighbor as Route Reflector client\n")
6480{
6481 int idx_peer = 2;
6482 char base_xpath[XPATH_MAXLEN];
6483 char af_xpath[XPATH_MAXLEN];
6484 char attr_xpath[XPATH_MAXLEN];
6485 afi_t afi = bgp_node_afi(vty);
6486 safi_t safi = bgp_node_safi(vty);
6487
6488 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6489 yang_afi_safi_value2identity(afi, safi));
6490
6491 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6492 sizeof(base_xpath), af_xpath)
6493 < 0)
6494 return CMD_WARNING_CONFIG_FAILED;
6495
6496 snprintf(attr_xpath, sizeof(attr_xpath),
6497 "./%s/route-reflector/route-reflector-client",
6498 bgp_afi_safi_get_container_str(afi, safi));
6499
6500 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6501
6502 return nb_cli_apply_changes(vty, base_xpath);
6503}
6504
6505ALIAS_HIDDEN(no_neighbor_route_reflector_client,
6506 no_neighbor_route_reflector_client_hidden_cmd,
6507 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
6508 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6509 "Configure a neighbor as Route Reflector client\n")
6510
6511/* neighbor route-server-client. */
6512DEFUN_YANG (neighbor_route_server_client,
6513 neighbor_route_server_client_cmd,
6514 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6515 NEIGHBOR_STR
6516 NEIGHBOR_ADDR_STR2
6517 "Configure a neighbor as Route Server client\n")
6518{
6519 int idx_peer = 1;
6520 char base_xpath[XPATH_MAXLEN];
6521 char af_xpath[XPATH_MAXLEN];
6522 char attr_xpath[XPATH_MAXLEN];
6523 afi_t afi = bgp_node_afi(vty);
6524 safi_t safi = bgp_node_safi(vty);
6525
6526 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6527 yang_afi_safi_value2identity(afi, safi));
6528
6529 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6530 sizeof(base_xpath), af_xpath)
6531 < 0)
6532 return CMD_WARNING_CONFIG_FAILED;
6533
6534 snprintf(attr_xpath, sizeof(attr_xpath),
6535 "./%s/route-server/route-server-client",
6536 bgp_afi_safi_get_container_str(afi, safi));
6537
6538 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "true");
6539
6540 return nb_cli_apply_changes(vty, base_xpath);
6541}
6542
6543ALIAS_HIDDEN(neighbor_route_server_client,
6544 neighbor_route_server_client_hidden_cmd,
6545 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6546 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6547 "Configure a neighbor as Route Server client\n")
6548
6549DEFUN_YANG (no_neighbor_route_server_client,
6550 no_neighbor_route_server_client_cmd,
6551 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6552 NO_STR
6553 NEIGHBOR_STR
6554 NEIGHBOR_ADDR_STR2
6555 "Configure a neighbor as Route Server client\n")
6556{
6557 int idx_peer = 2;
6558 char base_xpath[XPATH_MAXLEN];
6559 char af_xpath[XPATH_MAXLEN];
6560 char attr_xpath[XPATH_MAXLEN];
6561 afi_t afi = bgp_node_afi(vty);
6562 safi_t safi = bgp_node_safi(vty);
6563
6564 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6565 yang_afi_safi_value2identity(afi, safi));
6566
6567 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6568 sizeof(base_xpath), af_xpath)
6569 < 0)
6570 return CMD_WARNING_CONFIG_FAILED;
6571
6572 snprintf(attr_xpath, sizeof(attr_xpath),
6573 "./%s/route-server/route-server-client",
6574 bgp_afi_safi_get_container_str(afi, safi));
6575
6576 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY, "false");
6577
6578 return nb_cli_apply_changes(vty, base_xpath);
6579}
6580
6581ALIAS_HIDDEN(no_neighbor_route_server_client,
6582 no_neighbor_route_server_client_hidden_cmd,
6583 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
6584 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6585 "Configure a neighbor as Route Server client\n")
6586
6587DEFUN (neighbor_nexthop_local_unchanged,
6588 neighbor_nexthop_local_unchanged_cmd,
6589 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6590 NEIGHBOR_STR
6591 NEIGHBOR_ADDR_STR2
6592 "Configure treatment of outgoing link-local nexthop attribute\n"
6593 "Leave link-local nexthop unchanged for this peer\n")
6594{
6595 int idx_peer = 1;
6596 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6597 bgp_node_safi(vty),
6598 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6599}
6600
6601DEFUN (no_neighbor_nexthop_local_unchanged,
6602 no_neighbor_nexthop_local_unchanged_cmd,
6603 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
6604 NO_STR
6605 NEIGHBOR_STR
6606 NEIGHBOR_ADDR_STR2
6607 "Configure treatment of outgoing link-local-nexthop attribute\n"
6608 "Leave link-local nexthop unchanged for this peer\n")
6609{
6610 int idx_peer = 2;
6611 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6612 bgp_node_afi(vty), bgp_node_safi(vty),
6613 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
6614}
6615
6616DEFUN_YANG (neighbor_attr_unchanged,
6617 neighbor_attr_unchanged_cmd,
6618 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6619 NEIGHBOR_STR
6620 NEIGHBOR_ADDR_STR2
6621 "BGP attribute is propagated unchanged to this neighbor\n"
6622 "As-path attribute\n"
6623 "Nexthop attribute\n"
6624 "Med attribute\n")
6625{
6626 int idx = 0;
6627 char *peer_str = argv[1]->arg;
6628 bool aspath = false;
6629 bool nexthop = false;
6630 bool med = false;
6631 afi_t afi = bgp_node_afi(vty);
6632 safi_t safi = bgp_node_safi(vty);
6633 char base_xpath[XPATH_MAXLEN];
6634 char af_xpath[XPATH_MAXLEN];
6635 char as_xpath[XPATH_MAXLEN];
6636 char nxthop_xpath[XPATH_MAXLEN];
6637 char med_xpath[XPATH_MAXLEN];
6638
6639 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6640 yang_afi_safi_value2identity(afi, safi));
6641
6642 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6643 sizeof(base_xpath), af_xpath)
6644 < 0)
6645 return CMD_WARNING_CONFIG_FAILED;
6646
6647 if (argv_find(argv, argc, "as-path", &idx))
6648 aspath = true;
6649
6650 idx = 0;
6651 if (argv_find(argv, argc, "next-hop", &idx))
6652 nexthop = true;
6653
6654 idx = 0;
6655 if (argv_find(argv, argc, "med", &idx))
6656 med = true;
6657
6658 snprintf(as_xpath, sizeof(as_xpath),
6659 "./%s/attr-unchanged/as-path-unchanged",
6660 bgp_afi_safi_get_container_str(afi, safi));
6661 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6662 "./%s/attr-unchanged/next-hop-unchanged",
6663 bgp_afi_safi_get_container_str(afi, safi));
6664 snprintf(med_xpath, sizeof(med_xpath),
6665 "./%s/attr-unchanged/med-unchanged",
6666 bgp_afi_safi_get_container_str(afi, safi));
6667
6668 /* no flags means all of them! */
6669 if (!aspath && !nexthop && !med) {
6670 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "true");
6671 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "true");
6672 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "true");
6673 } else {
6674 if (!aspath)
6675 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6676 "false");
6677 else
6678 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY,
6679 "true");
6680
6681 if (!nexthop)
6682 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6683 "false");
6684 else
6685 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY,
6686 "true");
6687
6688 if (!med)
6689 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6690 "false");
6691 else
6692 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY,
6693 "true");
6694 }
6695
6696 return nb_cli_apply_changes(vty, base_xpath);
6697}
6698
6699ALIAS_HIDDEN(
6700 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
6701 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6702 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6703 "BGP attribute is propagated unchanged to this neighbor\n"
6704 "As-path attribute\n"
6705 "Nexthop attribute\n"
6706 "Med attribute\n")
6707
6708DEFUN_YANG (no_neighbor_attr_unchanged,
6709 no_neighbor_attr_unchanged_cmd,
6710 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6711 NO_STR
6712 NEIGHBOR_STR
6713 NEIGHBOR_ADDR_STR2
6714 "BGP attribute is propagated unchanged to this neighbor\n"
6715 "As-path attribute\n"
6716 "Nexthop attribute\n"
6717 "Med attribute\n")
6718{
6719 int idx = 0;
6720 char *peer_str = argv[2]->arg;
6721 bool aspath = false;
6722 bool nexthop = false;
6723 bool med = false;
6724 afi_t afi = bgp_node_afi(vty);
6725 safi_t safi = bgp_node_safi(vty);
6726 char base_xpath[XPATH_MAXLEN];
6727 char af_xpath[XPATH_MAXLEN];
6728 char as_xpath[XPATH_MAXLEN];
6729 char nxthop_xpath[XPATH_MAXLEN];
6730 char med_xpath[XPATH_MAXLEN];
6731
6732 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
6733 yang_afi_safi_value2identity(afi, safi));
6734
6735 if (peer_and_group_lookup_nb(vty, peer_str, base_xpath,
6736 sizeof(base_xpath), af_xpath)
6737 < 0)
6738 return CMD_WARNING_CONFIG_FAILED;
6739
6740 if (argv_find(argv, argc, "as-path", &idx))
6741 aspath = true;
6742
6743 idx = 0;
6744 if (argv_find(argv, argc, "next-hop", &idx))
6745 nexthop = true;
6746
6747 idx = 0;
6748 if (argv_find(argv, argc, "med", &idx))
6749 med = true;
6750
6751 snprintf(as_xpath, sizeof(as_xpath),
6752 "./%s/attr-unchanged/as-path-unchanged",
6753 bgp_afi_safi_get_container_str(afi, safi));
6754 snprintf(nxthop_xpath, sizeof(nxthop_xpath),
6755 "./%s/attr-unchanged/next-hop-unchanged",
6756 bgp_afi_safi_get_container_str(afi, safi));
6757 snprintf(med_xpath, sizeof(med_xpath),
6758 "./%s/attr-unchanged/med-unchanged",
6759 bgp_afi_safi_get_container_str(afi, safi));
6760
6761 /* no flags means all of them! */
6762 if (!aspath && !nexthop && !med) {
6763 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6764 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6765 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6766 }
6767
6768 if (aspath)
6769 nb_cli_enqueue_change(vty, as_xpath, NB_OP_MODIFY, "false");
6770
6771 if (nexthop)
6772 nb_cli_enqueue_change(vty, nxthop_xpath, NB_OP_MODIFY, "false");
6773
6774 if (med)
6775 nb_cli_enqueue_change(vty, med_xpath, NB_OP_MODIFY, "false");
6776
6777 return nb_cli_apply_changes(vty, base_xpath);
6778}
6779
6780ALIAS_HIDDEN(
6781 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
6782 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
6783 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6784 "BGP attribute is propagated unchanged to this neighbor\n"
6785 "As-path attribute\n"
6786 "Nexthop attribute\n"
6787 "Med attribute\n")
6788
6789/* neighbor ebgp-multihop. */
6790DEFUN_YANG (neighbor_ebgp_multihop,
6791 neighbor_ebgp_multihop_cmd,
6792 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
6793 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6794 "Allow EBGP neighbors not on directly connected networks\n")
6795{
6796 int idx_peer = 1;
6797 char base_xpath[XPATH_MAXLEN];
6798
6799 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6800 sizeof(base_xpath), NULL)
6801 < 0)
6802 return CMD_WARNING_CONFIG_FAILED;
6803
6804 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled", NB_OP_MODIFY,
6805 "true");
6806
6807 return nb_cli_apply_changes(vty, base_xpath);
6808}
6809
6810DEFUN_YANG (neighbor_ebgp_multihop_ttl,
6811 neighbor_ebgp_multihop_ttl_cmd,
6812 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
6813 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6814 "Allow EBGP neighbors not on directly connected networks\n"
6815 "maximum hop count\n")
6816{
6817 int idx_peer = 1;
6818 int idx_number = 3;
6819 char base_xpath[XPATH_MAXLEN];
6820
6821 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6822 sizeof(base_xpath), NULL)
6823 < 0)
6824 return CMD_WARNING_CONFIG_FAILED;
6825
6826 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl", NB_OP_MODIFY,
6827 argv[idx_number]->arg);
6828
6829 return nb_cli_apply_changes(vty, base_xpath);
6830}
6831
6832DEFUN_YANG (no_neighbor_ebgp_multihop,
6833 no_neighbor_ebgp_multihop_cmd,
6834 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
6835 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6836 "Allow EBGP neighbors not on directly connected networks\n"
6837 "maximum hop count\n")
6838{
6839 int idx_peer = 2;
6840 char base_xpath[XPATH_MAXLEN];
6841
6842 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6843 sizeof(base_xpath), NULL)
6844 < 0)
6845 return CMD_WARNING_CONFIG_FAILED;
6846
6847 if (argc > 4)
6848 nb_cli_enqueue_change(vty, "./ebgp-multihop/multihop-ttl",
6849 NB_OP_DESTROY, NULL);
6850 else
6851 nb_cli_enqueue_change(vty, "./ebgp-multihop/enabled",
6852 NB_OP_MODIFY, "false");
6853
6854 return nb_cli_apply_changes(vty, base_xpath);
6855}
6856
6857
6858/* disable-connected-check */
6859DEFUN_YANG (neighbor_disable_connected_check,
6860 neighbor_disable_connected_check_cmd,
6861 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6862 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6863 "one-hop away EBGP peer using loopback address\n"
6864 "Enforce EBGP neighbors perform multihop\n")
6865{
6866 int idx_peer = 1;
6867 char base_xpath[XPATH_MAXLEN];
6868
6869 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6870 sizeof(base_xpath), NULL)
6871 < 0)
6872 return CMD_WARNING_CONFIG_FAILED;
6873
6874 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6875 NB_OP_MODIFY, "true");
6876
6877 return nb_cli_apply_changes(vty, base_xpath);
6878}
6879
6880DEFUN_YANG (no_neighbor_disable_connected_check,
6881 no_neighbor_disable_connected_check_cmd,
6882 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6883 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6884 "one-hop away EBGP peer using loopback address\n"
6885 "Enforce EBGP neighbors perform multihop\n")
6886{
6887 int idx_peer = 2;
6888 char base_xpath[XPATH_MAXLEN];
6889
6890 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6891 sizeof(base_xpath), NULL)
6892 < 0)
6893 return CMD_WARNING_CONFIG_FAILED;
6894
6895 nb_cli_enqueue_change(vty, "./ebgp-multihop/disable-connected-check",
6896 NB_OP_MODIFY, "false");
6897
6898 return nb_cli_apply_changes(vty, base_xpath);
6899}
6900
6901
6902/* enforce-first-as */
6903DEFUN_YANG (neighbor_enforce_first_as,
6904 neighbor_enforce_first_as_cmd,
6905 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6906 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6907 "Enforce the first AS for EBGP routes\n")
6908{
6909 int idx_peer = 1;
6910 char base_xpath[XPATH_MAXLEN];
6911
6912 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6913 sizeof(base_xpath), NULL)
6914 < 0)
6915 return CMD_WARNING_CONFIG_FAILED;
6916
6917 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "true");
6918
6919 return nb_cli_apply_changes(vty, base_xpath);
6920}
6921
6922DEFUN_YANG (no_neighbor_enforce_first_as,
6923 no_neighbor_enforce_first_as_cmd,
6924 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
6925 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6926 "Enforce the first AS for EBGP routes\n")
6927{
6928 int idx_peer = 2;
6929 char base_xpath[XPATH_MAXLEN];
6930
6931 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
6932 sizeof(base_xpath), NULL)
6933 < 0)
6934 return CMD_WARNING_CONFIG_FAILED;
6935
6936 nb_cli_enqueue_change(vty, "./enforce-first-as", NB_OP_MODIFY, "false");
6937
6938 return nb_cli_apply_changes(vty, base_xpath);
6939}
6940
6941static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
6942 char *base_xpath, int xpath_len,
6943 char *xpath)
6944{
6945 union sockunion su;
6946 char num_xpath[XPATH_MAXLEN];
6947 char unnbr_xpath[XPATH_MAXLEN];
6948 char prgrp_xpath[XPATH_MAXLEN];
6949
6950 if (str2sockunion(peer_str, &su) == 0) {
6951 snprintf(num_xpath, sizeof(num_xpath),
6952 "/neighbors/neighbor[remote-address='%s']", peer_str);
6953 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6954 VTY_CURR_XPATH, num_xpath)) {
6955 snprintf(base_xpath, xpath_len,
6956 FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
6957 xpath ? xpath : "");
6958 } else {
6959 vty_out(vty,
6960 "%% Specify remote-as or peer-group commands first\n");
6961 return -1;
6962 }
6963
6964 } else {
6965 snprintf(unnbr_xpath, sizeof(unnbr_xpath),
6966 "/neighbors/unnumbered-neighbor[interface='%s']",
6967 peer_str);
6968
6969 snprintf(prgrp_xpath, sizeof(prgrp_xpath),
6970 "/peer-groups/peer-group[peer-group-name='%s']",
6971 peer_str);
6972
6973 if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
6974 VTY_CURR_XPATH, unnbr_xpath)) {
6975 snprintf(base_xpath, xpath_len,
6976 FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
6977 xpath ? xpath : "");
6978 } else if (yang_dnode_exists(vty->candidate_config->dnode,
6979 "%s%s", VTY_CURR_XPATH,
6980 prgrp_xpath)) {
6981 snprintf(base_xpath, xpath_len,
6982 FRR_BGP_PEER_GROUP_XPATH, peer_str,
6983 xpath ? xpath : "");
6984 } else {
6985 vty_out(vty,
6986 "%% Create the peer-group or interface first\n");
6987 return -1;
6988 }
6989 }
6990
6991 return 0;
6992}
6993
6994DEFUN_YANG (neighbor_description,
6995 neighbor_description_cmd,
6996 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
6997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6998 "Neighbor specific description\n"
6999 "Up to 80 characters describing this neighbor\n")
7000{
7001 int idx_peer = 1;
7002 int idx_line = 3;
7003 int ret;
7004 char base_xpath[XPATH_MAXLEN];
7005 char *str;
7006
7007 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7008 sizeof(base_xpath), NULL)
7009 < 0)
7010 return CMD_WARNING_CONFIG_FAILED;
7011
7012 str = argv_concat(argv, argc, idx_line);
7013
7014 nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, str);
7015
7016 ret = nb_cli_apply_changes(vty, base_xpath);
7017
7018 XFREE(MTYPE_TMP, str);
7019
7020 return ret;
7021}
7022
7023DEFUN_YANG (no_neighbor_description,
7024 no_neighbor_description_cmd,
7025 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
7026 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7027 "Neighbor specific description\n")
7028{
7029 int idx_peer = 2;
7030 char base_xpath[XPATH_MAXLEN];
7031
7032 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7033 sizeof(base_xpath), NULL)
7034 < 0)
7035 return CMD_WARNING_CONFIG_FAILED;
7036
7037 nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
7038
7039 return nb_cli_apply_changes(vty, base_xpath);
7040}
7041
7042ALIAS_YANG(no_neighbor_description, no_neighbor_description_comment_cmd,
7043 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
7044 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7045 "Neighbor specific description\n"
7046 "Up to 80 characters describing this neighbor\n")
7047
7048#define BGP_UPDATE_SOURCE_HELP_STR \
7049 "IPv4 address\n" \
7050 "IPv6 address\n" \
7051 "Interface name (requires zebra to be running)\n"
7052
7053DEFUN_YANG (neighbor_update_source,
7054 neighbor_update_source_cmd,
7055 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
7056 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7057 "Source of routing updates\n"
7058 BGP_UPDATE_SOURCE_HELP_STR)
7059{
7060 int idx_peer = 1;
7061 int idx_peer_2 = 3;
7062 union sockunion su;
7063 char base_xpath[XPATH_MAXLEN];
7064
7065 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7066 sizeof(base_xpath), NULL)
7067 < 0)
7068 return CMD_WARNING_CONFIG_FAILED;
7069
7070 if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
7071 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
7072 argv[idx_peer_2]->arg);
7073 else
7074 nb_cli_enqueue_change(vty, "./update-source/interface",
7075 NB_OP_MODIFY, argv[idx_peer_2]->arg);
7076
7077 return nb_cli_apply_changes(vty, base_xpath);
7078}
7079
7080DEFUN_YANG (no_neighbor_update_source,
7081 no_neighbor_update_source_cmd,
7082 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
7083 NO_STR NEIGHBOR_STR
7084 NEIGHBOR_ADDR_STR2
7085 "Source of routing updates\n"
7086 BGP_UPDATE_SOURCE_HELP_STR)
7087{
7088 int idx_peer = 2;
7089 char base_xpath[XPATH_MAXLEN];
7090
7091 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7092 sizeof(base_xpath), NULL)
7093 < 0)
7094 return CMD_WARNING_CONFIG_FAILED;
7095
7096 nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
7097 nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
7098 NULL);
7099
7100 return nb_cli_apply_changes(vty, base_xpath);
7101}
7102
7103static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
7104 afi_t afi, safi_t safi,
7105 const char *rmap, int set)
7106{
7107 int ret;
7108 struct peer *peer;
7109 struct route_map *route_map = NULL;
7110
7111 peer = peer_and_group_lookup_vty(vty, peer_str);
7112 if (!peer)
7113 return CMD_WARNING_CONFIG_FAILED;
7114
7115 if (set) {
7116 if (rmap)
7117 route_map = route_map_lookup_warn_noexist(vty, rmap);
7118 ret = peer_default_originate_set(peer, afi, safi,
7119 rmap, route_map);
7120 } else
7121 ret = peer_default_originate_unset(peer, afi, safi);
7122
7123 return bgp_vty_return(vty, ret);
7124}
7125
7126/* neighbor default-originate. */
7127DEFUN (neighbor_default_originate,
7128 neighbor_default_originate_cmd,
7129 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7130 NEIGHBOR_STR
7131 NEIGHBOR_ADDR_STR2
7132 "Originate default route to this neighbor\n")
7133{
7134 int idx_peer = 1;
7135 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7136 bgp_node_afi(vty),
7137 bgp_node_safi(vty), NULL, 1);
7138}
7139
7140ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
7141 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
7142 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7143 "Originate default route to this neighbor\n")
7144
7145DEFUN (neighbor_default_originate_rmap,
7146 neighbor_default_originate_rmap_cmd,
7147 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7148 NEIGHBOR_STR
7149 NEIGHBOR_ADDR_STR2
7150 "Originate default route to this neighbor\n"
7151 "Route-map to specify criteria to originate default\n"
7152 "route-map name\n")
7153{
7154 int idx_peer = 1;
7155 int idx_word = 4;
7156 return peer_default_originate_set_vty(
7157 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
7158 argv[idx_word]->arg, 1);
7159}
7160
7161ALIAS_HIDDEN(
7162 neighbor_default_originate_rmap,
7163 neighbor_default_originate_rmap_hidden_cmd,
7164 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
7165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7166 "Originate default route to this neighbor\n"
7167 "Route-map to specify criteria to originate default\n"
7168 "route-map name\n")
7169
7170DEFUN (no_neighbor_default_originate,
7171 no_neighbor_default_originate_cmd,
7172 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7173 NO_STR
7174 NEIGHBOR_STR
7175 NEIGHBOR_ADDR_STR2
7176 "Originate default route to this neighbor\n"
7177 "Route-map to specify criteria to originate default\n"
7178 "route-map name\n")
7179{
7180 int idx_peer = 2;
7181 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
7182 bgp_node_afi(vty),
7183 bgp_node_safi(vty), NULL, 0);
7184}
7185
7186ALIAS_HIDDEN(
7187 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
7188 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
7189 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7190 "Originate default route to this neighbor\n"
7191 "Route-map to specify criteria to originate default\n"
7192 "route-map name\n")
7193
7194
7195/* Set specified peer's BGP port. */
7196DEFUN_YANG (neighbor_port,
7197 neighbor_port_cmd,
7198 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
7199 NEIGHBOR_STR
7200 NEIGHBOR_ADDR_STR
7201 "Neighbor's BGP port\n"
7202 "TCP port number\n")
7203{
7204 int idx_ip = 1;
7205 int idx_number = 3;
7206 char base_xpath[XPATH_MAXLEN];
7207
7208 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7209 argv[idx_ip]->arg, "");
7210
7211 nb_cli_enqueue_change(vty, "./local-port", NB_OP_MODIFY,
7212 argv[idx_number]->arg);
7213
7214 return nb_cli_apply_changes(vty, base_xpath);
7215}
7216
7217DEFUN_YANG (no_neighbor_port,
7218 no_neighbor_port_cmd,
7219 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
7220 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR
7221 "Neighbor's BGP port\n"
7222 "TCP port number\n")
7223{
7224 int idx_ip = 2;
7225 char base_xpath[XPATH_MAXLEN];
7226
7227 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7228 argv[idx_ip]->arg, "");
7229
7230 nb_cli_enqueue_change(vty, "./local-port", NB_OP_DESTROY, NULL);
7231
7232 return nb_cli_apply_changes(vty, base_xpath);
7233}
7234
7235DEFUN_YANG (neighbor_weight,
7236 neighbor_weight_cmd,
7237 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7238 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7239 "Set default weight for routes from this neighbor\n"
7240 "default weight\n")
7241{
7242 int idx_peer = 1;
7243 int idx_number = 3;
7244 char base_xpath[XPATH_MAXLEN];
7245 char af_xpath[XPATH_MAXLEN];
7246 char attr_xpath[XPATH_MAXLEN];
7247 afi_t afi = bgp_node_afi(vty);
7248 safi_t safi = bgp_node_safi(vty);
7249
7250 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7251 yang_afi_safi_value2identity(afi, safi));
7252
7253 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7254 sizeof(base_xpath), af_xpath)
7255 < 0)
7256 return CMD_WARNING_CONFIG_FAILED;
7257
7258 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7259 bgp_afi_safi_get_container_str(afi, safi));
7260
7261 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_MODIFY,
7262 argv[idx_number]->arg);
7263
7264 return nb_cli_apply_changes(vty, base_xpath);
7265}
7266
7267ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
7268 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
7269 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7270 "Set default weight for routes from this neighbor\n"
7271 "default weight\n")
7272
7273DEFUN_YANG (no_neighbor_weight,
7274 no_neighbor_weight_cmd,
7275 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7276 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7277 "Set default weight for routes from this neighbor\n"
7278 "default weight\n")
7279{
7280 int idx_peer = 2;
7281 char base_xpath[XPATH_MAXLEN];
7282 char af_xpath[XPATH_MAXLEN];
7283 char attr_xpath[XPATH_MAXLEN];
7284 afi_t afi = bgp_node_afi(vty);
7285 safi_t safi = bgp_node_safi(vty);
7286
7287 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7288 yang_afi_safi_value2identity(afi, safi));
7289
7290 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7291 sizeof(base_xpath), af_xpath)
7292 < 0)
7293 return CMD_WARNING_CONFIG_FAILED;
7294
7295 snprintf(attr_xpath, sizeof(attr_xpath), "./%s/weight/weight-attribute",
7296 bgp_afi_safi_get_container_str(afi, safi));
7297
7298 nb_cli_enqueue_change(vty, attr_xpath, NB_OP_DESTROY, NULL);
7299
7300 return nb_cli_apply_changes(vty, base_xpath);
7301}
7302
7303ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
7304 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
7305 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7306 "Set default weight for routes from this neighbor\n"
7307 "default weight\n")
7308
7309
7310/* Override capability negotiation. */
7311DEFUN_YANG (neighbor_override_capability,
7312 neighbor_override_capability_cmd,
7313 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7314 NEIGHBOR_STR
7315 NEIGHBOR_ADDR_STR2
7316 "Override capability negotiation result\n")
7317{
7318 int idx_peer = 1;
7319 char base_xpath[XPATH_MAXLEN];
7320
7321 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7322 sizeof(base_xpath), NULL)
7323 < 0)
7324 return CMD_WARNING_CONFIG_FAILED;
7325
7326 nb_cli_enqueue_change(
7327 vty, "./capability-options/override-capability",
7328 NB_OP_MODIFY, "true");
7329
7330 return nb_cli_apply_changes(vty, base_xpath);
7331}
7332
7333DEFUN_YANG (no_neighbor_override_capability,
7334 no_neighbor_override_capability_cmd,
7335 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
7336 NO_STR
7337 NEIGHBOR_STR
7338 NEIGHBOR_ADDR_STR2
7339 "Override capability negotiation result\n")
7340{
7341 int idx_peer = 2;
7342 char base_xpath[XPATH_MAXLEN];
7343
7344 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7345 sizeof(base_xpath), NULL)
7346 < 0)
7347 return CMD_WARNING_CONFIG_FAILED;
7348
7349 nb_cli_enqueue_change(
7350 vty, "./capability-options/override-capability",
7351 NB_OP_MODIFY, "false");
7352
7353 return nb_cli_apply_changes(vty, base_xpath);
7354}
7355
7356DEFUN_YANG (neighbor_strict_capability,
7357 neighbor_strict_capability_cmd,
7358 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7359 NEIGHBOR_STR
7360 NEIGHBOR_ADDR_STR2
7361 "Strict capability negotiation match\n")
7362{
7363 int idx_peer = 1;
7364 char base_xpath[XPATH_MAXLEN];
7365
7366 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7367 sizeof(base_xpath), NULL)
7368 < 0)
7369 return CMD_WARNING_CONFIG_FAILED;
7370
7371 nb_cli_enqueue_change(
7372 vty, "./capability-options/strict-capability",
7373 NB_OP_MODIFY, "true");
7374
7375 return nb_cli_apply_changes(vty, base_xpath);
7376}
7377
7378DEFUN_YANG (no_neighbor_strict_capability,
7379 no_neighbor_strict_capability_cmd,
7380 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
7381 NO_STR
7382 NEIGHBOR_STR
7383 NEIGHBOR_ADDR_STR2
7384 "Strict capability negotiation match\n")
7385{
7386 int idx_peer = 2;
7387 char base_xpath[XPATH_MAXLEN];
7388
7389 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7390 sizeof(base_xpath), NULL)
7391 < 0)
7392 return CMD_WARNING_CONFIG_FAILED;
7393
7394 nb_cli_enqueue_change(
7395 vty, "./capability-options/strict-capability",
7396 NB_OP_MODIFY, "false");
7397
7398 return nb_cli_apply_changes(vty, base_xpath);
7399}
7400
7401DEFUN_YANG (neighbor_timers,
7402 neighbor_timers_cmd,
7403 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
7404 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7405 "BGP per neighbor timers\n"
7406 "Keepalive interval\n"
7407 "Holdtime\n")
7408{
7409 int idx_peer = 1;
7410 int idx_number = 3;
7411 int idx_number_2 = 4;
7412 char base_xpath[XPATH_MAXLEN];
7413
7414 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7415 sizeof(base_xpath), NULL)
7416 < 0)
7417 return CMD_WARNING_CONFIG_FAILED;
7418
7419 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_MODIFY,
7420 argv[idx_number]->arg);
7421
7422 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_MODIFY,
7423 argv[idx_number_2]->arg);
7424
7425 return nb_cli_apply_changes(vty, base_xpath);
7426}
7427
7428DEFUN_YANG (no_neighbor_timers,
7429 no_neighbor_timers_cmd,
7430 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
7431 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7432 "BGP per neighbor timers\n"
7433 "Keepalive interval\n"
7434 "Holdtime\n")
7435{
7436 int idx_peer = 2;
7437 char base_xpath[XPATH_MAXLEN];
7438
7439 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7440 sizeof(base_xpath), NULL)
7441 < 0)
7442 return CMD_WARNING_CONFIG_FAILED;
7443
7444 nb_cli_enqueue_change(vty, "./timers/hold-time", NB_OP_DESTROY, NULL);
7445
7446 nb_cli_enqueue_change(vty, "./timers/keepalive", NB_OP_DESTROY, NULL);
7447
7448 return nb_cli_apply_changes(vty, base_xpath);
7449}
7450
7451DEFUN_YANG (neighbor_timers_connect,
7452 neighbor_timers_connect_cmd,
7453 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
7454 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7455 "BGP per neighbor timers\n"
7456 "BGP connect timer\n"
7457 "Connect timer\n")
7458{
7459 int idx_peer = 1;
7460 int idx_number = 4;
7461 char base_xpath[XPATH_MAXLEN];
7462
7463 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7464 sizeof(base_xpath), NULL)
7465 < 0)
7466 return CMD_WARNING_CONFIG_FAILED;
7467
7468 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_MODIFY,
7469 argv[idx_number]->arg);
7470
7471 return nb_cli_apply_changes(vty, base_xpath);
7472}
7473
7474DEFUN_YANG (no_neighbor_timers_connect,
7475 no_neighbor_timers_connect_cmd,
7476 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
7477 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7478 "BGP per neighbor timers\n"
7479 "BGP connect timer\n"
7480 "Connect timer\n")
7481{
7482 int idx_peer = 2;
7483 char base_xpath[XPATH_MAXLEN];
7484
7485 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7486 sizeof(base_xpath), NULL)
7487 < 0)
7488 return CMD_WARNING_CONFIG_FAILED;
7489
7490 nb_cli_enqueue_change(vty, "./timers/connect-time", NB_OP_DESTROY,
7491 NULL);
7492
7493 return nb_cli_apply_changes(vty, base_xpath);
7494}
7495
7496DEFPY (neighbor_timers_delayopen,
7497 neighbor_timers_delayopen_cmd,
7498 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen (1-240)$interval",
7499 NEIGHBOR_STR
7500 NEIGHBOR_ADDR_STR2
7501 "BGP per neighbor timers\n"
7502 "RFC 4271 DelayOpenTimer\n"
7503 "DelayOpenTime timer interval\n")
7504{
7505 struct peer *peer;
7506
7507 peer = peer_and_group_lookup_vty(vty, neighbor);
7508 if (!peer)
7509 return CMD_WARNING_CONFIG_FAILED;
7510
7511 if (!interval) {
7512 if (peer_timers_delayopen_unset(peer))
7513 return CMD_WARNING_CONFIG_FAILED;
7514 } else {
7515 if (peer_timers_delayopen_set(peer, interval))
7516 return CMD_WARNING_CONFIG_FAILED;
7517 }
7518
7519 return CMD_SUCCESS;
7520}
7521
7522DEFPY (no_neighbor_timers_delayopen,
7523 no_neighbor_timers_delayopen_cmd,
7524 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor timers delayopen [(0-65535)]",
7525 NO_STR
7526 NEIGHBOR_STR
7527 NEIGHBOR_ADDR_STR2
7528 "BGP per neighbor timers\n"
7529 "RFC 4271 DelayOpenTimer\n"
7530 "DelayOpenTime timer interval\n")
7531{
7532 struct peer *peer;
7533
7534 peer = peer_and_group_lookup_vty(vty, neighbor);
7535 if (!peer)
7536 return CMD_WARNING_CONFIG_FAILED;
7537
7538 if (peer_timers_delayopen_unset(peer))
7539 return CMD_WARNING_CONFIG_FAILED;
7540
7541 return CMD_SUCCESS;
7542}
7543
7544DEFUN_YANG (neighbor_advertise_interval,
7545 neighbor_advertise_interval_cmd,
7546 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
7547 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7548 "Minimum interval between sending BGP routing updates\n"
7549 "time in seconds\n")
7550{
7551 int idx_peer = 1;
7552 int idx_number = 3;
7553 char base_xpath[XPATH_MAXLEN];
7554
7555 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7556 sizeof(base_xpath), NULL)
7557 < 0)
7558 return CMD_WARNING_CONFIG_FAILED;
7559
7560 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_MODIFY,
7561 argv[idx_number]->arg);
7562
7563 return nb_cli_apply_changes(vty, base_xpath);
7564}
7565
7566DEFUN_YANG (no_neighbor_advertise_interval,
7567 no_neighbor_advertise_interval_cmd,
7568 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
7569 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7570 "Minimum interval between sending BGP routing updates\n"
7571 "time in seconds\n")
7572{
7573 int idx_peer = 2;
7574 char base_xpath[XPATH_MAXLEN];
7575
7576 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
7577 sizeof(base_xpath), NULL)
7578 < 0)
7579 return CMD_WARNING_CONFIG_FAILED;
7580
7581 nb_cli_enqueue_change(vty, "./timers/advertise-interval", NB_OP_DESTROY,
7582 NULL);
7583
7584 return nb_cli_apply_changes(vty, base_xpath);
7585}
7586
7587
7588/* Time to wait before processing route-map updates */
7589DEFUN (bgp_set_route_map_delay_timer,
7590 bgp_set_route_map_delay_timer_cmd,
7591 "bgp route-map delay-timer (0-600)",
7592 SET_STR
7593 "BGP route-map delay timer\n"
7594 "Time in secs to wait before processing route-map changes\n"
7595 "0 disables the timer, no route updates happen when route-maps change\n")
7596{
7597 int idx_number = 3;
7598 uint32_t rmap_delay_timer;
7599
7600 if (argv[idx_number]->arg) {
7601 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
7602 bm->rmap_update_timer = rmap_delay_timer;
7603
7604 /* if the dynamic update handling is being disabled, and a timer
7605 * is
7606 * running, stop the timer and act as if the timer has already
7607 * fired.
7608 */
7609 if (!rmap_delay_timer && bm->t_rmap_update) {
7610 BGP_TIMER_OFF(bm->t_rmap_update);
7611 thread_execute(bm->master, bgp_route_map_update_timer,
7612 NULL, 0);
7613 }
7614 return CMD_SUCCESS;
7615 } else {
7616 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
7617 return CMD_WARNING_CONFIG_FAILED;
7618 }
7619}
7620
7621DEFUN (no_bgp_set_route_map_delay_timer,
7622 no_bgp_set_route_map_delay_timer_cmd,
7623 "no bgp route-map delay-timer [(0-600)]",
7624 NO_STR
7625 BGP_STR
7626 "Default BGP route-map delay timer\n"
7627 "Reset to default time to wait for processing route-map changes\n"
7628 "0 disables the timer, no route updates happen when route-maps change\n")
7629{
7630
7631 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
7632
7633 return CMD_SUCCESS;
7634}
7635
7636DEFUN_YANG (neighbor_interface,
7637 neighbor_interface_cmd,
7638 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
7639 NEIGHBOR_STR NEIGHBOR_ADDR_STR
7640 "Interface\n"
7641 "Interface name\n")
7642{
7643 int idx_ip = 1;
7644 int idx_word = 3;
7645 char base_xpath[XPATH_MAXLEN];
7646
7647 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7648 argv[idx_ip]->arg, "");
7649
7650 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_MODIFY,
7651 argv[idx_word]->arg);
7652
7653 return nb_cli_apply_changes(vty, base_xpath);
7654}
7655
7656DEFUN_YANG (no_neighbor_interface,
7657 no_neighbor_interface_cmd,
7658 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
7659 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7660 "Interface\n"
7661 "Interface name\n")
7662{
7663 int idx_peer = 2;
7664 char base_xpath[XPATH_MAXLEN];
7665
7666 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_NEIGHBOR_NUM_XPATH,
7667 argv[idx_peer]->arg, "");
7668
7669 nb_cli_enqueue_change(vty, "./local-interface", NB_OP_DESTROY, NULL);
7670
7671 return nb_cli_apply_changes(vty, base_xpath);
7672}
7673
7674DEFUN (neighbor_distribute_list,
7675 neighbor_distribute_list_cmd,
7676 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7677 NEIGHBOR_STR
7678 NEIGHBOR_ADDR_STR2
7679 "Filter updates to/from this neighbor\n"
7680 "IP access-list number\n"
7681 "IP access-list number (expanded range)\n"
7682 "IP Access-list name\n"
7683 "Filter incoming updates\n"
7684 "Filter outgoing updates\n")
7685{
7686 int idx_peer = 1;
7687 int idx_acl = 3;
7688 int direct, ret;
7689 struct peer *peer;
7690
7691 const char *pstr = argv[idx_peer]->arg;
7692 const char *acl = argv[idx_acl]->arg;
7693 const char *inout = argv[argc - 1]->text;
7694
7695 peer = peer_and_group_lookup_vty(vty, pstr);
7696 if (!peer)
7697 return CMD_WARNING_CONFIG_FAILED;
7698
7699 /* Check filter direction. */
7700 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7701 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7702 direct, acl);
7703
7704 return bgp_vty_return(vty, ret);
7705}
7706
7707ALIAS_HIDDEN(
7708 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
7709 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7710 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7711 "Filter updates to/from this neighbor\n"
7712 "IP access-list number\n"
7713 "IP access-list number (expanded range)\n"
7714 "IP Access-list name\n"
7715 "Filter incoming updates\n"
7716 "Filter outgoing updates\n")
7717
7718DEFUN (no_neighbor_distribute_list,
7719 no_neighbor_distribute_list_cmd,
7720 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7721 NO_STR
7722 NEIGHBOR_STR
7723 NEIGHBOR_ADDR_STR2
7724 "Filter updates to/from this neighbor\n"
7725 "IP access-list number\n"
7726 "IP access-list number (expanded range)\n"
7727 "IP Access-list name\n"
7728 "Filter incoming updates\n"
7729 "Filter outgoing updates\n")
7730{
7731 int idx_peer = 2;
7732 int direct, ret;
7733 struct peer *peer;
7734
7735 const char *pstr = argv[idx_peer]->arg;
7736 const char *inout = argv[argc - 1]->text;
7737
7738 peer = peer_and_group_lookup_vty(vty, pstr);
7739 if (!peer)
7740 return CMD_WARNING_CONFIG_FAILED;
7741
7742 /* Check filter direction. */
7743 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
7744 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
7745 direct);
7746
7747 return bgp_vty_return(vty, ret);
7748}
7749
7750ALIAS_HIDDEN(
7751 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
7752 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
7753 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7754 "Filter updates to/from this neighbor\n"
7755 "IP access-list number\n"
7756 "IP access-list number (expanded range)\n"
7757 "IP Access-list name\n"
7758 "Filter incoming updates\n"
7759 "Filter outgoing updates\n")
7760
7761/* Set prefix list to the peer. */
7762DEFPY_YANG(
7763 neighbor_prefix_list, neighbor_prefix_list_cmd,
7764 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str prefix-list WORD$prefix_str <in|out>$direction",
7765 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7766 "Filter updates to/from this neighbor\n"
7767 "Name of a prefix list\n"
7768 "Filter incoming updates\n"
7769 "Filter outgoing updates\n")
7770{
7771 char base_xpath[XPATH_MAXLEN];
7772 char af_xpath[XPATH_MAXLEN];
7773 char plist_xpath[XPATH_MAXLEN];
7774 afi_t afi = bgp_node_afi(vty);
7775 safi_t safi = bgp_node_safi(vty);
7776
7777 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7778 yang_afi_safi_value2identity(afi, safi));
7779 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7780 sizeof(base_xpath), af_xpath)
7781 < 0)
7782 return CMD_WARNING_CONFIG_FAILED;
7783
7784 if (strmatch(direction, "in"))
7785 snprintf(plist_xpath, sizeof(plist_xpath),
7786 "./%s/filter-config/plist-import",
7787 bgp_afi_safi_get_container_str(afi, safi));
7788 else if (strmatch(direction, "out"))
7789 snprintf(plist_xpath, sizeof(plist_xpath),
7790 "./%s/filter-config/plist-export",
7791 bgp_afi_safi_get_container_str(afi, safi));
7792
7793 if (!no)
7794 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_MODIFY,
7795 prefix_str);
7796 else
7797 nb_cli_enqueue_change(vty, plist_xpath, NB_OP_DESTROY, NULL);
7798
7799 return nb_cli_apply_changes(vty, base_xpath);
7800}
7801
7802ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
7803 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
7804 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7805 "Filter updates to/from this neighbor\n"
7806 "Name of a prefix list\n"
7807 "Filter incoming updates\n"
7808 "Filter outgoing updates\n")
7809
7810static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
7811 safi_t safi, const char *name_str,
7812 const char *direct_str)
7813{
7814 int ret;
7815 struct peer *peer;
7816 int direct = FILTER_IN;
7817
7818 peer = peer_and_group_lookup_vty(vty, ip_str);
7819 if (!peer)
7820 return CMD_WARNING_CONFIG_FAILED;
7821
7822 /* Check filter direction. */
7823 if (strncmp(direct_str, "i", 1) == 0)
7824 direct = FILTER_IN;
7825 else if (strncmp(direct_str, "o", 1) == 0)
7826 direct = FILTER_OUT;
7827
7828 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
7829
7830 return bgp_vty_return(vty, ret);
7831}
7832
7833static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
7834 safi_t safi, const char *direct_str)
7835{
7836 int ret;
7837 struct peer *peer;
7838 int direct = FILTER_IN;
7839
7840 peer = peer_and_group_lookup_vty(vty, ip_str);
7841 if (!peer)
7842 return CMD_WARNING_CONFIG_FAILED;
7843
7844 /* Check filter direction. */
7845 if (strncmp(direct_str, "i", 1) == 0)
7846 direct = FILTER_IN;
7847 else if (strncmp(direct_str, "o", 1) == 0)
7848 direct = FILTER_OUT;
7849
7850 ret = peer_aslist_unset(peer, afi, safi, direct);
7851
7852 return bgp_vty_return(vty, ret);
7853}
7854
7855DEFUN (neighbor_filter_list,
7856 neighbor_filter_list_cmd,
7857 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7858 NEIGHBOR_STR
7859 NEIGHBOR_ADDR_STR2
7860 "Establish BGP filters\n"
7861 "AS path access-list name\n"
7862 "Filter incoming routes\n"
7863 "Filter outgoing routes\n")
7864{
7865 int idx_peer = 1;
7866 int idx_word = 3;
7867 int idx_in_out = 4;
7868 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
7869 bgp_node_safi(vty), argv[idx_word]->arg,
7870 argv[idx_in_out]->arg);
7871}
7872
7873ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
7874 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7875 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7876 "Establish BGP filters\n"
7877 "AS path access-list name\n"
7878 "Filter incoming routes\n"
7879 "Filter outgoing routes\n")
7880
7881DEFUN (no_neighbor_filter_list,
7882 no_neighbor_filter_list_cmd,
7883 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7884 NO_STR
7885 NEIGHBOR_STR
7886 NEIGHBOR_ADDR_STR2
7887 "Establish BGP filters\n"
7888 "AS path access-list name\n"
7889 "Filter incoming routes\n"
7890 "Filter outgoing routes\n")
7891{
7892 int idx_peer = 2;
7893 int idx_in_out = 5;
7894 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
7895 bgp_node_afi(vty), bgp_node_safi(vty),
7896 argv[idx_in_out]->arg);
7897}
7898
7899ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
7900 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
7901 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7902 "Establish BGP filters\n"
7903 "AS path access-list name\n"
7904 "Filter incoming routes\n"
7905 "Filter outgoing routes\n")
7906
7907/* Set advertise-map to the peer. */
7908static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
7909 afi_t afi, safi_t safi,
7910 const char *advertise_str,
7911 const char *condition_str, bool condition,
7912 bool set)
7913{
7914 int ret = CMD_WARNING_CONFIG_FAILED;
7915 struct peer *peer;
7916 struct route_map *advertise_map;
7917 struct route_map *condition_map;
7918
7919 peer = peer_and_group_lookup_vty(vty, ip_str);
7920 if (!peer)
7921 return ret;
7922
7923 condition_map = route_map_lookup_warn_noexist(vty, condition_str);
7924 advertise_map = route_map_lookup_warn_noexist(vty, advertise_str);
7925
7926 if (set)
7927 ret = peer_advertise_map_set(peer, afi, safi, advertise_str,
7928 advertise_map, condition_str,
7929 condition_map, condition);
7930 else
7931 ret = peer_advertise_map_unset(peer, afi, safi, advertise_str,
7932 advertise_map, condition_str,
7933 condition_map, condition);
7934
7935 return bgp_vty_return(vty, ret);
7936}
7937
7938DEFPY (neighbor_advertise_map,
7939 neighbor_advertise_map_cmd,
7940 "[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",
7941 NO_STR
7942 NEIGHBOR_STR
7943 NEIGHBOR_ADDR_STR2
7944 "Route-map to conditionally advertise routes\n"
7945 "Name of advertise map\n"
7946 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7947 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7948 "Name of the exist or non exist map\n")
7949{
7950 bool condition = CONDITION_EXIST;
7951
7952 if (!strcmp(exist, "non-exist-map"))
7953 condition = CONDITION_NON_EXIST;
7954
7955 return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
7956 bgp_node_safi(vty), advertise_str,
7957 condition_str, condition, !no);
7958}
7959
7960ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
7961 "[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",
7962 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7963 "Route-map to conditionally advertise routes\n"
7964 "Name of advertise map\n"
7965 "Advertise routes only if prefixes in exist-map are installed in BGP table\n"
7966 "Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
7967 "Name of the exist or non exist map\n")
7968
7969/* Set route-map to the peer. */
7970DEFPY_YANG(
7971 neighbor_route_map, neighbor_route_map_cmd,
7972 "[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor_str route-map WORD$rmap_str <in|out>$direction",
7973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
7974 "Apply route map to neighbor\n"
7975 "Name of route map\n"
7976 "Apply map to incoming routes\n"
7977 "Apply map to outbound routes\n")
7978{
7979 char base_xpath[XPATH_MAXLEN];
7980 char af_xpath[XPATH_MAXLEN];
7981 char rmap_xpath[XPATH_MAXLEN];
7982 afi_t afi = bgp_node_afi(vty);
7983 safi_t safi = bgp_node_safi(vty);
7984
7985 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
7986 yang_afi_safi_value2identity(afi, safi));
7987 if (peer_and_group_lookup_nb(vty, neighbor_str, base_xpath,
7988 sizeof(base_xpath), af_xpath)
7989 < 0)
7990 return CMD_WARNING_CONFIG_FAILED;
7991
7992 if (strmatch(direction, "in"))
7993 snprintf(rmap_xpath, sizeof(rmap_xpath),
7994 "./%s/filter-config/rmap-import",
7995 bgp_afi_safi_get_container_str(afi, safi));
7996 else if (strmatch(direction, "out"))
7997 snprintf(rmap_xpath, sizeof(rmap_xpath),
7998 "./%s/filter-config/rmap-export",
7999 bgp_afi_safi_get_container_str(afi, safi));
8000
8001 if (!no) {
8002 if (!yang_dnode_exists(
8003 vty->candidate_config->dnode,
8004 "/frr-route-map:lib/route-map[name='%s']",
8005 rmap_str)) {
8006 if (vty_shell_serv(vty))
8007 vty_out(vty,
8008 "The route-map '%s' does not exist.\n",
8009 rmap_str);
8010 }
8011 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_MODIFY, rmap_str);
8012 } else
8013 nb_cli_enqueue_change(vty, rmap_xpath, NB_OP_DESTROY, NULL);
8014
8015 return nb_cli_apply_changes(vty, base_xpath);
8016}
8017
8018/* Set unsuppress-map to the peer. */
8019static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
8020 afi_t afi, safi_t safi,
8021 const char *name_str)
8022{
8023 int ret;
8024 struct peer *peer;
8025 struct route_map *route_map;
8026
8027 peer = peer_and_group_lookup_vty(vty, ip_str);
8028 if (!peer)
8029 return CMD_WARNING_CONFIG_FAILED;
8030
8031 route_map = route_map_lookup_warn_noexist(vty, name_str);
8032 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
8033
8034 return bgp_vty_return(vty, ret);
8035}
8036
8037/* Unset route-map from the peer. */
8038static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
8039 afi_t afi, safi_t safi)
8040{
8041 int ret;
8042 struct peer *peer;
8043
8044 peer = peer_and_group_lookup_vty(vty, ip_str);
8045 if (!peer)
8046 return CMD_WARNING_CONFIG_FAILED;
8047
8048 ret = peer_unsuppress_map_unset(peer, afi, safi);
8049
8050 return bgp_vty_return(vty, ret);
8051}
8052
8053DEFUN (neighbor_unsuppress_map,
8054 neighbor_unsuppress_map_cmd,
8055 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8056 NEIGHBOR_STR
8057 NEIGHBOR_ADDR_STR2
8058 "Route-map to selectively unsuppress suppressed routes\n"
8059 "Name of route map\n")
8060{
8061 int idx_peer = 1;
8062 int idx_word = 3;
8063 return peer_unsuppress_map_set_vty(
8064 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
8065 argv[idx_word]->arg);
8066}
8067
8068ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
8069 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8070 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8071 "Route-map to selectively unsuppress suppressed routes\n"
8072 "Name of route map\n")
8073
8074DEFUN (no_neighbor_unsuppress_map,
8075 no_neighbor_unsuppress_map_cmd,
8076 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8077 NO_STR
8078 NEIGHBOR_STR
8079 NEIGHBOR_ADDR_STR2
8080 "Route-map to selectively unsuppress suppressed routes\n"
8081 "Name of route map\n")
8082{
8083 int idx_peer = 2;
8084 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
8085 bgp_node_afi(vty),
8086 bgp_node_safi(vty));
8087}
8088
8089ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
8090 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
8091 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8092 "Route-map to selectively unsuppress suppressed routes\n"
8093 "Name of route map\n")
8094
8095/* Maximum number of prefix to be sent to the neighbor. */
8096DEFUN_YANG(neighbor_maximum_prefix_out,
8097 neighbor_maximum_prefix_out_cmd,
8098 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out (1-4294967295)",
8099 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8100 "Maximum number of prefixes to be sent to this peer\n"
8101 "Maximum no. of prefix limit\n")
8102{
8103 char base_xpath[XPATH_MAXLEN];
8104 char af_xpath[XPATH_MAXLEN];
8105 char attr_xpath[XPATH_MAXLEN];
8106 int idx_peer = 1;
8107 int idx_number = 3;
8108 afi_t afi = bgp_node_afi(vty);
8109 safi_t safi = bgp_node_safi(vty);
8110
8111 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8112 yang_afi_safi_value2identity(afi, safi));
8113 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8114 sizeof(base_xpath), af_xpath)
8115 < 0)
8116 return CMD_WARNING_CONFIG_FAILED;
8117
8118 snprintf(attr_xpath, sizeof(attr_xpath),
8119 "/%s/prefix-limit/direction-list[direction='out']",
8120 bgp_afi_safi_get_container_str(afi, safi));
8121 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8122
8123 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8124
8125 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8126 argv[idx_number]->arg);
8127
8128 return nb_cli_apply_changes(vty, base_xpath);
8129}
8130
8131DEFUN_YANG(no_neighbor_maximum_prefix_out,
8132 no_neighbor_maximum_prefix_out_cmd,
8133 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix-out",
8134 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8135 "Maximum number of prefixes to be sent to this peer\n")
8136{
8137 char base_xpath[XPATH_MAXLEN];
8138 char af_xpath[XPATH_MAXLEN];
8139 char attr_xpath[XPATH_MAXLEN];
8140 int idx_peer = 2;
8141 afi_t afi = bgp_node_afi(vty);
8142 safi_t safi = bgp_node_safi(vty);
8143
8144 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8145 yang_afi_safi_value2identity(afi, safi));
8146 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8147 sizeof(base_xpath), af_xpath)
8148 < 0)
8149 return CMD_WARNING_CONFIG_FAILED;
8150
8151 snprintf(attr_xpath, sizeof(attr_xpath),
8152 "/%s/prefix-limit/direction-list[direction='out']",
8153 bgp_afi_safi_get_container_str(afi, safi));
8154 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8155
8156 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8157
8158 return nb_cli_apply_changes(vty, base_xpath);
8159}
8160
8161/* Maximum number of prefix configuration. Prefix count is different
8162 for each peer configuration. So this configuration can be set for
8163 each peer configuration. */
8164DEFUN_YANG(neighbor_maximum_prefix,
8165 neighbor_maximum_prefix_cmd,
8166 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8167 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8168 "Maximum number of prefix accept from this peer\n"
8169 "maximum no. of prefix limit\n"
8170 "Force checking all received routes not only accepted\n")
8171{
8172 int idx_peer = 1;
8173 int idx_number = 3;
8174 int idx_force = 0;
8175 char base_xpath[XPATH_MAXLEN];
8176 char af_xpath[XPATH_MAXLEN];
8177 char attr_xpath[XPATH_MAXLEN];
8178 afi_t afi = bgp_node_afi(vty);
8179 safi_t safi = bgp_node_safi(vty);
8180
8181 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8182 yang_afi_safi_value2identity(afi, safi));
8183 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8184 sizeof(base_xpath), af_xpath)
8185 < 0)
8186 return CMD_WARNING_CONFIG_FAILED;
8187
8188 snprintf(attr_xpath, sizeof(attr_xpath),
8189 "/%s/prefix-limit/direction-list[direction='in']",
8190 bgp_afi_safi_get_container_str(afi, safi));
8191 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8192
8193 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8194
8195 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8196 argv[idx_number]->arg);
8197 if (argv_find(argv, argc, "force", &idx_force))
8198 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8199 "true");
8200
8201 return nb_cli_apply_changes(vty, base_xpath);
8202}
8203
8204ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
8205 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) [force]",
8206 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8207 "Maximum number of prefix accept from this peer\n"
8208 "maximum no. of prefix limit\n"
8209 "Force checking all received routes not only accepted\n")
8210
8211DEFUN_YANG(neighbor_maximum_prefix_threshold,
8212 neighbor_maximum_prefix_threshold_cmd,
8213 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8214 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8215 "Maximum number of prefix accept from this peer\n"
8216 "maximum no. of prefix limit\n"
8217 "Threshold value (%) at which to generate a warning msg\n"
8218 "Force checking all received routes not only accepted\n")
8219{
8220 int idx_peer = 1;
8221 int idx_number = 3;
8222 int idx_number_2 = 4;
8223 int idx_force = 0;
8224 char base_xpath[XPATH_MAXLEN];
8225 char af_xpath[XPATH_MAXLEN];
8226 char attr_xpath[XPATH_MAXLEN];
8227 afi_t afi = bgp_node_afi(vty);
8228 safi_t safi = bgp_node_safi(vty);
8229
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)
8235 return CMD_WARNING_CONFIG_FAILED;
8236
8237 snprintf(attr_xpath, sizeof(attr_xpath),
8238 "/%s/prefix-limit/direction-list[direction='in']",
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_CREATE, NULL);
8243
8244 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8245 argv[idx_number]->arg);
8246
8247 nb_cli_enqueue_change(vty, "./options/shutdown-threshold-pct",
8248 NB_OP_MODIFY, argv[idx_number_2]->arg);
8249
8250 if (argv_find(argv, argc, "force", &idx_force))
8251 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8252 "true");
8253
8254 return nb_cli_apply_changes(vty, base_xpath);
8255}
8256
8257ALIAS_HIDDEN(
8258 neighbor_maximum_prefix_threshold,
8259 neighbor_maximum_prefix_threshold_hidden_cmd,
8260 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) [force]",
8261 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8262 "Maximum number of prefix accept from this peer\n"
8263 "maximum no. of prefix limit\n"
8264 "Threshold value (%) at which to generate a warning msg\n"
8265 "Force checking all received routes not only accepted\n")
8266
8267DEFUN_YANG(neighbor_maximum_prefix_warning,
8268 neighbor_maximum_prefix_warning_cmd,
8269 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8270 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8271 "Maximum number of prefix accept from this peer\n"
8272 "maximum no. of prefix limit\n"
8273 "Only give warning message when limit is exceeded\n"
8274 "Force checking all received routes not only accepted\n")
8275{
8276 int idx_peer = 1;
8277 int idx_number = 3;
8278 int idx_force = 0;
8279 char base_xpath[XPATH_MAXLEN];
8280 char af_xpath[XPATH_MAXLEN];
8281 char attr_xpath[XPATH_MAXLEN];
8282 afi_t afi = bgp_node_afi(vty);
8283 safi_t safi = bgp_node_safi(vty);
8284
8285 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8286 yang_afi_safi_value2identity(afi, safi));
8287 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8288 sizeof(base_xpath), af_xpath)
8289 < 0)
8290 return CMD_WARNING_CONFIG_FAILED;
8291
8292 snprintf(attr_xpath, sizeof(attr_xpath),
8293 "/%s/prefix-limit/direction-list[direction='in']",
8294 bgp_afi_safi_get_container_str(afi, safi));
8295 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8296
8297 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8298
8299 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8300 argv[idx_number]->arg);
8301
8302 nb_cli_enqueue_change(vty, "./options/warning-only", NB_OP_MODIFY,
8303 "true");
8304 if (argv_find(argv, argc, "force", &idx_force))
8305 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8306 "true");
8307
8308 return nb_cli_apply_changes(vty, base_xpath);
8309}
8310
8311ALIAS_HIDDEN(
8312 neighbor_maximum_prefix_warning,
8313 neighbor_maximum_prefix_warning_hidden_cmd,
8314 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only [force]",
8315 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8316 "Maximum number of prefix accept from this peer\n"
8317 "maximum no. of prefix limit\n"
8318 "Only give warning message when limit is exceeded\n"
8319 "Force checking all received routes not only accepted\n")
8320
8321DEFUN_YANG(neighbor_maximum_prefix_threshold_warning,
8322 neighbor_maximum_prefix_threshold_warning_cmd,
8323 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8324 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8325 "Maximum number of prefix accept from this peer\n"
8326 "maximum no. of prefix limit\n"
8327 "Threshold value (%) at which to generate a warning msg\n"
8328 "Only give warning message when limit is exceeded\n"
8329 "Force checking all received routes not only accepted\n")
8330{
8331 int idx_peer = 1;
8332 int idx_number = 3;
8333 int idx_number_2 = 4;
8334 int idx_force = 0;
8335 char base_xpath[XPATH_MAXLEN];
8336 char af_xpath[XPATH_MAXLEN];
8337 char attr_xpath[XPATH_MAXLEN];
8338 afi_t afi = bgp_node_afi(vty);
8339 safi_t safi = bgp_node_safi(vty);
8340
8341 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8342 yang_afi_safi_value2identity(afi, safi));
8343 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8344 sizeof(base_xpath), af_xpath)
8345 < 0)
8346 return CMD_WARNING_CONFIG_FAILED;
8347
8348 snprintf(attr_xpath, sizeof(attr_xpath),
8349 "/%s/prefix-limit/direction-list[direction='in']",
8350 bgp_afi_safi_get_container_str(afi, safi));
8351 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8352
8353 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8354
8355 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8356 argv[idx_number]->arg);
8357 nb_cli_enqueue_change(vty, "./options/tw-shutdown-threshold-pct",
8358 NB_OP_MODIFY, argv[idx_number_2]->arg);
8359 nb_cli_enqueue_change(vty, "./options/tw-warning-only", NB_OP_MODIFY,
8360 "true");
8361 if (argv_find(argv, argc, "force", &idx_force))
8362 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8363 "true");
8364
8365 return nb_cli_apply_changes(vty, base_xpath);
8366}
8367
8368ALIAS_HIDDEN(
8369 neighbor_maximum_prefix_threshold_warning,
8370 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
8371 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only [force]",
8372 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8373 "Maximum number of prefix accept from this peer\n"
8374 "maximum no. of prefix limit\n"
8375 "Threshold value (%) at which to generate a warning msg\n"
8376 "Only give warning message when limit is exceeded\n"
8377 "Force checking all received routes not only accepted\n")
8378
8379DEFUN_YANG(neighbor_maximum_prefix_restart,
8380 neighbor_maximum_prefix_restart_cmd,
8381 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8382 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8383 "Maximum number of prefix accept from this peer\n"
8384 "maximum no. of prefix limit\n"
8385 "Restart bgp connection after limit is exceeded\n"
8386 "Restart interval in minutes\n"
8387 "Force checking all received routes not only accepted\n")
8388{
8389 int idx_peer = 1;
8390 int idx_number = 3;
8391 int idx_number_2 = 5;
8392 int idx_force = 0;
8393 char base_xpath[XPATH_MAXLEN];
8394 char af_xpath[XPATH_MAXLEN];
8395 char attr_xpath[XPATH_MAXLEN];
8396 afi_t afi = bgp_node_afi(vty);
8397 safi_t safi = bgp_node_safi(vty);
8398
8399 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8400 yang_afi_safi_value2identity(afi, safi));
8401 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8402 sizeof(base_xpath), af_xpath)
8403 < 0)
8404 return CMD_WARNING_CONFIG_FAILED;
8405
8406 snprintf(attr_xpath, sizeof(attr_xpath),
8407 "/%s/prefix-limit/direction-list[direction='in']",
8408 bgp_afi_safi_get_container_str(afi, safi));
8409 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8410
8411 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8412
8413 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8414 argv[idx_number]->arg);
8415 nb_cli_enqueue_change(vty, "./options/restart-timer", NB_OP_MODIFY,
8416 argv[idx_number_2]->arg);
8417 if (argv_find(argv, argc, "force", &idx_force))
8418 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8419 "true");
8420
8421 return nb_cli_apply_changes(vty, base_xpath);
8422}
8423
8424ALIAS_HIDDEN(
8425 neighbor_maximum_prefix_restart,
8426 neighbor_maximum_prefix_restart_hidden_cmd,
8427 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535) [force]",
8428 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8429 "Maximum number of prefix accept from this peer\n"
8430 "maximum no. of prefix limit\n"
8431 "Restart bgp connection after limit is exceeded\n"
8432 "Restart interval in minutes\n"
8433 "Force checking all received routes not only accepted\n")
8434
8435DEFUN_YANG(neighbor_maximum_prefix_threshold_restart,
8436 neighbor_maximum_prefix_threshold_restart_cmd,
8437 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8438 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8439 "Maximum number of prefixes to accept from this peer\n"
8440 "maximum no. of prefix limit\n"
8441 "Threshold value (%) at which to generate a warning msg\n"
8442 "Restart bgp connection after limit is exceeded\n"
8443 "Restart interval in minutes\n"
8444 "Force checking all received routes not only accepted\n")
8445{
8446 int idx_peer = 1;
8447 int idx_number = 3;
8448 int idx_number_2 = 4;
8449 int idx_number_3 = 6;
8450 int idx_force = 0;
8451 char base_xpath[XPATH_MAXLEN];
8452 char af_xpath[XPATH_MAXLEN];
8453 char attr_xpath[XPATH_MAXLEN];
8454 afi_t afi = bgp_node_afi(vty);
8455 safi_t safi = bgp_node_safi(vty);
8456
8457 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8458 yang_afi_safi_value2identity(afi, safi));
8459 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8460 sizeof(base_xpath), af_xpath)
8461 < 0)
8462 return CMD_WARNING_CONFIG_FAILED;
8463
8464 snprintf(attr_xpath, sizeof(attr_xpath),
8465 "/%s/prefix-limit/direction-list[direction='in']",
8466 bgp_afi_safi_get_container_str(afi, safi));
8467 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8468
8469 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
8470
8471 nb_cli_enqueue_change(vty, "./max-prefixes", NB_OP_MODIFY,
8472 argv[idx_number]->arg);
8473 nb_cli_enqueue_change(vty, "./options/tr-shutdown-threshold-pct",
8474 NB_OP_MODIFY, argv[idx_number_2]->arg);
8475 nb_cli_enqueue_change(vty, "./options/tr-restart-timer", NB_OP_MODIFY,
8476 argv[idx_number_3]->arg);
8477 if (argv_find(argv, argc, "force", &idx_force))
8478 nb_cli_enqueue_change(vty, "./force-check", NB_OP_MODIFY,
8479 "true");
8480
8481 return nb_cli_apply_changes(vty, base_xpath);
8482}
8483
8484ALIAS_HIDDEN(
8485 neighbor_maximum_prefix_threshold_restart,
8486 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
8487 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535) [force]",
8488 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8489 "Maximum number of prefixes to accept from this peer\n"
8490 "maximum no. of prefix limit\n"
8491 "Threshold value (%) at which to generate a warning msg\n"
8492 "Restart bgp connection after limit is exceeded\n"
8493 "Restart interval in minutes\n"
8494 "Force checking all received routes not only accepted\n")
8495
8496DEFUN_YANG(no_neighbor_maximum_prefix,
8497 no_neighbor_maximum_prefix_cmd,
8498 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8499 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8500 "Maximum number of prefixes to accept from this peer\n"
8501 "maximum no. of prefix limit\n"
8502 "Threshold value (%) at which to generate a warning msg\n"
8503 "Restart bgp connection after limit is exceeded\n"
8504 "Restart interval in minutes\n"
8505 "Only give warning message when limit is exceeded\n"
8506 "Force checking all received routes not only accepted\n")
8507{
8508 int idx_peer = 2;
8509 char base_xpath[XPATH_MAXLEN];
8510 char af_xpath[XPATH_MAXLEN];
8511 char attr_xpath[XPATH_MAXLEN];
8512 afi_t afi = bgp_node_afi(vty);
8513 safi_t safi = bgp_node_safi(vty);
8514
8515 snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
8516 yang_afi_safi_value2identity(afi, safi));
8517 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8518 sizeof(base_xpath), af_xpath)
8519 < 0)
8520 return CMD_WARNING_CONFIG_FAILED;
8521
8522 snprintf(attr_xpath, sizeof(attr_xpath),
8523 "/%s/prefix-limit/direction-list[direction='in']",
8524 bgp_afi_safi_get_container_str(afi, safi));
8525 strlcat(base_xpath, attr_xpath, sizeof(base_xpath));
8526
8527 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
8528
8529 return nb_cli_apply_changes(vty, base_xpath);
8530}
8531
8532ALIAS_HIDDEN(
8533 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
8534 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only] [force]]",
8535 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8536 "Maximum number of prefixes to accept from this peer\n"
8537 "maximum no. of prefix limit\n"
8538 "Threshold value (%) at which to generate a warning msg\n"
8539 "Restart bgp connection after limit is exceeded\n"
8540 "Restart interval in minutes\n"
8541 "Only give warning message when limit is exceeded\n"
8542 "Force checking all received routes not only accepted\n")
8543
8544
8545/* "neighbor allowas-in" */
8546DEFUN (neighbor_allowas_in,
8547 neighbor_allowas_in_cmd,
8548 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8549 NEIGHBOR_STR
8550 NEIGHBOR_ADDR_STR2
8551 "Accept as-path with my AS present in it\n"
8552 "Number of occurrences of AS number\n"
8553 "Only accept my AS in the as-path if the route was originated in my AS\n")
8554{
8555 int idx_peer = 1;
8556 int idx_number_origin = 3;
8557 int ret;
8558 int origin = 0;
8559 struct peer *peer;
8560 int allow_num = 0;
8561
8562 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8563 if (!peer)
8564 return CMD_WARNING_CONFIG_FAILED;
8565
8566 if (argc <= idx_number_origin)
8567 allow_num = 3;
8568 else {
8569 if (argv[idx_number_origin]->type == WORD_TKN)
8570 origin = 1;
8571 else
8572 allow_num = atoi(argv[idx_number_origin]->arg);
8573 }
8574
8575 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8576 allow_num, origin);
8577
8578 return bgp_vty_return(vty, ret);
8579}
8580
8581ALIAS_HIDDEN(
8582 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
8583 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8584 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8585 "Accept as-path with my AS present in it\n"
8586 "Number of occurrences of AS number\n"
8587 "Only accept my AS in the as-path if the route was originated in my AS\n")
8588
8589DEFUN (no_neighbor_allowas_in,
8590 no_neighbor_allowas_in_cmd,
8591 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8592 NO_STR
8593 NEIGHBOR_STR
8594 NEIGHBOR_ADDR_STR2
8595 "allow local ASN appears in aspath attribute\n"
8596 "Number of occurrences of AS number\n"
8597 "Only accept my AS in the as-path if the route was originated in my AS\n")
8598{
8599 int idx_peer = 2;
8600 int ret;
8601 struct peer *peer;
8602
8603 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8604 if (!peer)
8605 return CMD_WARNING_CONFIG_FAILED;
8606
8607 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
8608 bgp_node_safi(vty));
8609
8610 return bgp_vty_return(vty, ret);
8611}
8612
8613ALIAS_HIDDEN(
8614 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
8615 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
8616 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8617 "allow local ASN appears in aspath attribute\n"
8618 "Number of occurrences of AS number\n"
8619 "Only accept my AS in the as-path if the route was originated in my AS\n")
8620
8621DEFUN_YANG (neighbor_ttl_security,
8622 neighbor_ttl_security_cmd,
8623 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8624 NEIGHBOR_STR
8625 NEIGHBOR_ADDR_STR2
8626 "BGP ttl-security parameters\n"
8627 "Specify the maximum number of hops to the BGP peer\n"
8628 "Number of hops to BGP peer\n")
8629{
8630 int idx_peer = 1;
8631 int idx_number = 4;
8632 char base_xpath[XPATH_MAXLEN];
8633
8634 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8635 sizeof(base_xpath), NULL)
8636 < 0)
8637 return CMD_WARNING_CONFIG_FAILED;
8638
8639 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_MODIFY,
8640 argv[idx_number]->arg);
8641
8642 return nb_cli_apply_changes(vty, base_xpath);
8643}
8644
8645DEFUN_YANG(no_neighbor_ttl_security,
8646 no_neighbor_ttl_security_cmd,
8647 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
8648 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8649 "BGP ttl-security parameters\n"
8650 "Specify the maximum number of hops to the BGP peer\n"
8651 "Number of hops to BGP peer\n")
8652{
8653 int idx_peer = 2;
8654 char base_xpath[XPATH_MAXLEN];
8655
8656 if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
8657 sizeof(base_xpath), NULL)
8658 < 0)
8659 return CMD_WARNING_CONFIG_FAILED;
8660
8661 nb_cli_enqueue_change(vty, "./ttl-security", NB_OP_DESTROY, NULL);
8662
8663 return nb_cli_apply_changes(vty, base_xpath);
8664}
8665
8666DEFUN (neighbor_addpath_tx_all_paths,
8667 neighbor_addpath_tx_all_paths_cmd,
8668 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8669 NEIGHBOR_STR
8670 NEIGHBOR_ADDR_STR2
8671 "Use addpath to advertise all paths to a neighbor\n")
8672{
8673 int idx_peer = 1;
8674 struct peer *peer;
8675
8676 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8677 if (!peer)
8678 return CMD_WARNING_CONFIG_FAILED;
8679
8680 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8681 BGP_ADDPATH_ALL);
8682 return CMD_SUCCESS;
8683}
8684
8685ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
8686 neighbor_addpath_tx_all_paths_hidden_cmd,
8687 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8688 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8689 "Use addpath to advertise all paths to a neighbor\n")
8690
8691DEFUN (no_neighbor_addpath_tx_all_paths,
8692 no_neighbor_addpath_tx_all_paths_cmd,
8693 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8694 NO_STR
8695 NEIGHBOR_STR
8696 NEIGHBOR_ADDR_STR2
8697 "Use addpath to advertise all paths to a neighbor\n")
8698{
8699 int idx_peer = 2;
8700 struct peer *peer;
8701
8702 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8703 if (!peer)
8704 return CMD_WARNING_CONFIG_FAILED;
8705
8706 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8707 != BGP_ADDPATH_ALL) {
8708 vty_out(vty,
8709 "%% Peer not currently configured to transmit all paths.");
8710 return CMD_WARNING_CONFIG_FAILED;
8711 }
8712
8713 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8714 BGP_ADDPATH_NONE);
8715
8716 return CMD_SUCCESS;
8717}
8718
8719ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
8720 no_neighbor_addpath_tx_all_paths_hidden_cmd,
8721 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
8722 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8723 "Use addpath to advertise all paths to a neighbor\n")
8724
8725DEFUN (neighbor_addpath_tx_bestpath_per_as,
8726 neighbor_addpath_tx_bestpath_per_as_cmd,
8727 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8728 NEIGHBOR_STR
8729 NEIGHBOR_ADDR_STR2
8730 "Use addpath to advertise the bestpath per each neighboring AS\n")
8731{
8732 int idx_peer = 1;
8733 struct peer *peer;
8734
8735 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8736 if (!peer)
8737 return CMD_WARNING_CONFIG_FAILED;
8738
8739 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8740 BGP_ADDPATH_BEST_PER_AS);
8741
8742 return CMD_SUCCESS;
8743}
8744
8745ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
8746 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8747 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8748 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8749 "Use addpath to advertise the bestpath per each neighboring AS\n")
8750
8751DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
8752 no_neighbor_addpath_tx_bestpath_per_as_cmd,
8753 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8754 NO_STR
8755 NEIGHBOR_STR
8756 NEIGHBOR_ADDR_STR2
8757 "Use addpath to advertise the bestpath per each neighboring AS\n")
8758{
8759 int idx_peer = 2;
8760 struct peer *peer;
8761
8762 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
8763 if (!peer)
8764 return CMD_WARNING_CONFIG_FAILED;
8765
8766 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
8767 != BGP_ADDPATH_BEST_PER_AS) {
8768 vty_out(vty,
8769 "%% Peer not currently configured to transmit all best path per as.");
8770 return CMD_WARNING_CONFIG_FAILED;
8771 }
8772
8773 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8774 BGP_ADDPATH_NONE);
8775
8776 return CMD_SUCCESS;
8777}
8778
8779ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
8780 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
8781 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
8782 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
8783 "Use addpath to advertise the bestpath per each neighboring AS\n")
8784
8785DEFPY(
8786 neighbor_aspath_loop_detection, neighbor_aspath_loop_detection_cmd,
8787 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8788 NEIGHBOR_STR
8789 NEIGHBOR_ADDR_STR2
8790 "Detect AS loops before sending to neighbor\n")
8791{
8792 struct peer *peer;
8793
8794 peer = peer_and_group_lookup_vty(vty, neighbor);
8795 if (!peer)
8796 return CMD_WARNING_CONFIG_FAILED;
8797
8798 peer->as_path_loop_detection = true;
8799
8800 return CMD_SUCCESS;
8801}
8802
8803DEFPY(
8804 no_neighbor_aspath_loop_detection,
8805 no_neighbor_aspath_loop_detection_cmd,
8806 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor sender-as-path-loop-detection",
8807 NO_STR
8808 NEIGHBOR_STR
8809 NEIGHBOR_ADDR_STR2
8810 "Detect AS loops before sending to neighbor\n")
8811{
8812 struct peer *peer;
8813
8814 peer = peer_and_group_lookup_vty(vty, neighbor);
8815 if (!peer)
8816 return CMD_WARNING_CONFIG_FAILED;
8817
8818 peer->as_path_loop_detection = false;
8819
8820 return CMD_SUCCESS;
8821}
8822
8823DEFPY(neighbor_damp,
8824 neighbor_damp_cmd,
8825 "neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [(1-45)$half [(1-20000)$reuse (1-20000)$suppress (1-255)$max]]",
8826 NEIGHBOR_STR
8827 NEIGHBOR_ADDR_STR2
8828 "Enable neighbor route-flap dampening\n"
8829 "Half-life time for the penalty\n"
8830 "Value to start reusing a route\n"
8831 "Value to start suppressing a route\n"
8832 "Maximum duration to suppress a stable route\n")
8833{
8834 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8835
8836 if (!peer)
8837 return CMD_WARNING_CONFIG_FAILED;
8838 if (!half)
8839 half = DEFAULT_HALF_LIFE;
8840 if (!reuse) {
8841 reuse = DEFAULT_REUSE;
8842 suppress = DEFAULT_SUPPRESS;
8843 max = half * 4;
8844 }
8845 if (suppress < reuse) {
8846 vty_out(vty,
8847 "Suppress value cannot be less than reuse value\n");
8848 return CMD_WARNING_CONFIG_FAILED;
8849 }
8850 bgp_peer_damp_enable(peer, bgp_node_afi(vty), bgp_node_safi(vty),
8851 half * 60, reuse, suppress, max * 60);
8852 return CMD_SUCCESS;
8853}
8854
8855DEFPY(no_neighbor_damp,
8856 no_neighbor_damp_cmd,
8857 "no neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor dampening [HALF [REUSE SUPPRESS MAX]]",
8858 NO_STR
8859 NEIGHBOR_STR
8860 NEIGHBOR_ADDR_STR2
8861 "Enable neighbor route-flap dampening\n"
8862 "Half-life time for the penalty\n"
8863 "Value to start reusing a route\n"
8864 "Value to start suppressing a route\n"
8865 "Maximum duration to suppress a stable route\n")
8866{
8867 struct peer *peer = peer_and_group_lookup_vty(vty, neighbor);
8868
8869 if (!peer)
8870 return CMD_WARNING_CONFIG_FAILED;
8871 bgp_peer_damp_disable(peer, bgp_node_afi(vty), bgp_node_safi(vty));
8872 return CMD_SUCCESS;
8873}
8874
8875DEFPY (show_ip_bgp_neighbor_damp_param,
8876 show_ip_bgp_neighbor_damp_param_cmd,
8877 "show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD>$neighbor dampening parameters [json]$json",
8878 SHOW_STR
8879 IP_STR
8880 BGP_STR
8881 BGP_AFI_HELP_STR
8882 "Address Family modifier\n"
8883 NEIGHBOR_STR
8884 NEIGHBOR_ADDR_STR2
8885 "Neighbor route-flap dampening information\n"
8886 "Display detail of configured dampening parameters\n"
8887 JSON_STR)
8888{
8889 bool use_json = false;
8890 int idx = 0;
8891 afi_t afi = AFI_IP;
8892 safi_t safi = SAFI_UNICAST;
8893 struct peer *peer;
8894
8895 if (argv_find(argv, argc, "ip", &idx))
8896 afi = AFI_IP;
8897 if (argv_find(argv, argc, "ipv4", &idx))
8898 afi = AFI_IP;
8899 if (argv_find(argv, argc, "ipv6", &idx))
8900 afi = AFI_IP6;
8901 peer = peer_and_group_lookup_vty(vty, neighbor);
8902 if (!peer)
8903 return CMD_WARNING;
8904 if (json)
8905 use_json = true;
8906 bgp_show_peer_dampening_parameters(vty, peer, afi, safi, use_json);
8907 return CMD_SUCCESS;
8908}
8909
8910static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
8911 struct ecommunity **list, bool is_rt6)
8912{
8913 struct ecommunity *ecom = NULL;
8914 struct ecommunity *ecomadd;
8915
8916 for (; argc; --argc, ++argv) {
8917 if (is_rt6)
8918 ecomadd = ecommunity_str2com_ipv6(argv[0]->arg,
8919 ECOMMUNITY_ROUTE_TARGET,
8920 0);
8921 else
8922 ecomadd = ecommunity_str2com(argv[0]->arg,
8923 ECOMMUNITY_ROUTE_TARGET,
8924 0);
8925 if (!ecomadd) {
8926 vty_out(vty, "Malformed community-list value\n");
8927 if (ecom)
8928 ecommunity_free(&ecom);
8929 return CMD_WARNING_CONFIG_FAILED;
8930 }
8931
8932 if (ecom) {
8933 ecommunity_merge(ecom, ecomadd);
8934 ecommunity_free(&ecomadd);
8935 } else {
8936 ecom = ecomadd;
8937 }
8938 }
8939
8940 if (*list) {
8941 ecommunity_free(&*list);
8942 }
8943 *list = ecom;
8944
8945 return CMD_SUCCESS;
8946}
8947
8948bool vpn_policy_check_import(struct bgp *bgp, afi_t afi, safi_t safi,
8949 bool v2vimport, char *errmsg, size_t errmsg_len)
8950{
8951 if (!v2vimport) {
8952 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8953 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8954 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8955 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
8956 snprintf(
8957 errmsg, errmsg_len, "%s",
8958 "%% error: Please unconfigure import vrf commands before using vpn commands");
8959 return false;
8960 }
8961 } else {
8962 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8963 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
8964 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8965 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
8966 snprintf(
8967 errmsg, errmsg_len, "%s",
8968 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands");
8969 return false;
8970 }
8971 }
8972 return true;
8973}
8974
8975/*
8976 * v2vimport is true if we are handling a `import vrf ...` command
8977 */
8978static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
8979{
8980 afi_t afi;
8981
8982 switch (vty->node) {
8983 case BGP_IPV4_NODE:
8984 afi = AFI_IP;
8985 break;
8986 case BGP_IPV6_NODE:
8987 afi = AFI_IP6;
8988 break;
8989 default:
8990 vty_out(vty,
8991 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
8992 return AFI_MAX;
8993 }
8994
8995 if (!v2vimport) {
8996 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8997 BGP_CONFIG_VRF_TO_VRF_IMPORT)
8998 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
8999 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
9000 vty_out(vty,
9001 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
9002 return AFI_MAX;
9003 }
9004 } else {
9005 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9006 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
9007 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9008 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
9009 vty_out(vty,
9010 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
9011 return AFI_MAX;
9012 }
9013 }
9014 return afi;
9015}
9016
9017DEFPY_YANG(
9018 af_rd_vpn_export,
9019 af_rd_vpn_export_cmd,
9020 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
9021 NO_STR
9022 "Specify route distinguisher\n"
9023 "Between current address-family and vpn\n"
9024 "For routes leaked from current address-family to vpn\n"
9025 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
9026{
9027 char base_xpath[XPATH_MAXLEN];
9028 afi_t afi;
9029 safi_t safi;
9030 int idx = 0;
9031
9032 afi = bgp_node_afi(vty);
9033 safi = bgp_node_safi(vty);
9034
9035 snprintf(
9036 base_xpath, sizeof(base_xpath),
9037 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9038 yang_afi_safi_value2identity(afi, safi),
9039 bgp_afi_safi_get_container_str(afi, safi));
9040
9041 if (argv_find(argv, argc, "no", &idx))
9042 nb_cli_enqueue_change(vty, "./rd", NB_OP_DESTROY, NULL);
9043 else
9044 nb_cli_enqueue_change(vty, "./rd", NB_OP_MODIFY, rd_str);
9045
9046 return nb_cli_apply_changes(vty, base_xpath);
9047}
9048
9049void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rd(
9050 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9051{
9052 int indent = 2;
9053
9054 vty_out(vty, "%*srd vpn export %s\n", indent, "",
9055 yang_dnode_get_string(dnode, NULL));
9056}
9057
9058ALIAS (af_rd_vpn_export,
9059 af_no_rd_vpn_export_cmd,
9060 "no rd vpn export",
9061 NO_STR
9062 "Specify route distinguisher\n"
9063 "Between current address-family and vpn\n"
9064 "For routes leaked from current address-family to vpn\n")
9065
9066DEFPY (af_label_vpn_export,
9067 af_label_vpn_export_cmd,
9068 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
9069 NO_STR
9070 "label value for VRF\n"
9071 "Between current address-family and vpn\n"
9072 "For routes leaked from current address-family to vpn\n"
9073 "Label Value <0-1048575>\n"
9074 "Automatically assign a label\n")
9075{
9076 VTY_DECLVAR_CONTEXT(bgp, bgp);
9077 mpls_label_t label = MPLS_LABEL_NONE;
9078 afi_t afi;
9079 int idx = 0;
9080 bool yes = true;
9081
9082 if (argv_find(argv, argc, "no", &idx))
9083 yes = false;
9084
9085 /* If "no ...", squash trailing parameter */
9086 if (!yes)
9087 label_auto = NULL;
9088
9089 if (yes) {
9090 if (!label_auto)
9091 label = label_val; /* parser should force unsigned */
9092 }
9093
9094 afi = vpn_policy_getafi(vty, bgp, false);
9095 if (afi == AFI_MAX)
9096 return CMD_WARNING_CONFIG_FAILED;
9097
9098
9099 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9100 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
9101 /* no change */
9102 return CMD_SUCCESS;
9103
9104 /*
9105 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
9106 */
9107 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9108 bgp_get_default(), bgp);
9109
9110 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
9111 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
9112
9113 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
9114
9115 /*
9116 * label has previously been automatically
9117 * assigned by labelpool: release it
9118 *
9119 * NB if tovpn_label == MPLS_LABEL_NONE it
9120 * means the automatic assignment is in flight
9121 * and therefore the labelpool callback must
9122 * detect that the auto label is not needed.
9123 */
9124
9125 bgp_lp_release(LP_TYPE_VRF,
9126 &bgp->vpn_policy[afi],
9127 bgp->vpn_policy[afi].tovpn_label);
9128 }
9129 UNSET_FLAG(bgp->vpn_policy[afi].flags,
9130 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9131 }
9132
9133 bgp->vpn_policy[afi].tovpn_label = label;
9134 if (label_auto) {
9135 SET_FLAG(bgp->vpn_policy[afi].flags,
9136 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
9137 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
9138 vpn_leak_label_callback);
9139 }
9140
9141 /* post-change: re-export vpn routes */
9142 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
9143 bgp_get_default(), bgp);
9144
9145 hook_call(bgp_snmp_update_last_changed, bgp);
9146 return CMD_SUCCESS;
9147}
9148
9149ALIAS (af_label_vpn_export,
9150 af_no_label_vpn_export_cmd,
9151 "no label vpn export",
9152 NO_STR
9153 "label value for VRF\n"
9154 "Between current address-family and vpn\n"
9155 "For routes leaked from current address-family to vpn\n")
9156
9157DEFPY_YANG (af_nexthop_vpn_export,
9158 af_nexthop_vpn_export_cmd,
9159 "[no] nexthop vpn export [<A.B.C.D|X:X::X:X>$nexthop_su]",
9160 NO_STR
9161 "Specify next hop to use for VRF advertised prefixes\n"
9162 "Between current address-family and vpn\n"
9163 "For routes leaked from current address-family to vpn\n"
9164 "IPv4 prefix\n"
9165 "IPv6 prefix\n")
9166{
9167 char base_xpath[XPATH_MAXLEN];
9168 afi_t afi;
9169 safi_t safi;
9170 int idx = 0;
9171 struct prefix p;
9172
9173 if (!no) {
9174 if (!nexthop_su) {
9175 vty_out(vty, "%% Nexthop required\n");
9176 return CMD_WARNING_CONFIG_FAILED;
9177 }
9178 if (!sockunion2hostprefix(nexthop_su, &p))
9179 return CMD_WARNING_CONFIG_FAILED;
9180 }
9181
9182 afi = bgp_node_afi(vty);
9183 safi = bgp_node_safi(vty);
9184
9185 snprintf(
9186 base_xpath, sizeof(base_xpath),
9187 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9188 yang_afi_safi_value2identity(afi, safi),
9189 bgp_afi_safi_get_container_str(afi, safi));
9190
9191 if (argv_find(argv, argc, "no", &idx))
9192 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_DESTROY, NULL);
9193 else
9194 nb_cli_enqueue_change(vty, "./nexthop", NB_OP_MODIFY,
9195 nexthop_su_str);
9196
9197 return nb_cli_apply_changes(vty, base_xpath);
9198}
9199
9200void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_nexthop(
9201 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9202{
9203 int indent = 2;
9204
9205 vty_out(vty, "%*snexthop vpn export %s\n", indent, "",
9206 yang_dnode_get_string(dnode, NULL));
9207}
9208
9209static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
9210{
9211 if (!strcmp(dstr, "import")) {
9212 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9213 } else if (!strcmp(dstr, "export")) {
9214 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9215 } else if (!strcmp(dstr, "both")) {
9216 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
9217 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
9218 } else {
9219 vty_out(vty, "%% direction parse error\n");
9220 return CMD_WARNING_CONFIG_FAILED;
9221 }
9222 return CMD_SUCCESS;
9223}
9224
9225DEFPY (af_rt_vpn_imexport,
9226 af_rt_vpn_imexport_cmd,
9227 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
9228 NO_STR
9229 "Specify route target list\n"
9230 "Specify route target list\n"
9231 "Between current address-family and vpn\n"
9232 "For routes leaked from vpn to current address-family: match any\n"
9233 "For routes leaked from current address-family to vpn: set\n"
9234 "both import: match any and export: set\n"
9235 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
9236{
9237 VTY_DECLVAR_CONTEXT(bgp, bgp);
9238 int ret;
9239 struct ecommunity *ecom = NULL;
9240 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
9241 vpn_policy_direction_t dir;
9242 afi_t afi;
9243 int idx = 0;
9244 bool yes = true;
9245
9246 if (argv_find(argv, argc, "no", &idx))
9247 yes = false;
9248
9249 afi = vpn_policy_getafi(vty, bgp, false);
9250 if (afi == AFI_MAX)
9251 return CMD_WARNING_CONFIG_FAILED;
9252
9253 ret = vpn_policy_getdirs(vty, direction_str, dodir);
9254 if (ret != CMD_SUCCESS)
9255 return ret;
9256
9257 if (yes) {
9258 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9259 vty_out(vty, "%% Missing RTLIST\n");
9260 return CMD_WARNING_CONFIG_FAILED;
9261 }
9262 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, false);
9263 if (ret != CMD_SUCCESS) {
9264 return ret;
9265 }
9266 }
9267
9268 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
9269 if (!dodir[dir])
9270 continue;
9271
9272 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9273
9274 if (yes) {
9275 if (bgp->vpn_policy[afi].rtlist[dir])
9276 ecommunity_free(
9277 &bgp->vpn_policy[afi].rtlist[dir]);
9278 bgp->vpn_policy[afi].rtlist[dir] =
9279 ecommunity_dup(ecom);
9280 } else {
9281 if (bgp->vpn_policy[afi].rtlist[dir])
9282 ecommunity_free(
9283 &bgp->vpn_policy[afi].rtlist[dir]);
9284 bgp->vpn_policy[afi].rtlist[dir] = NULL;
9285 }
9286
9287 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9288 }
9289
9290 if (ecom)
9291 ecommunity_free(&ecom);
9292
9293 return CMD_SUCCESS;
9294}
9295
9296ALIAS (af_rt_vpn_imexport,
9297 af_no_rt_vpn_imexport_cmd,
9298 "no <rt|route-target> vpn <import|export|both>$direction_str",
9299 NO_STR
9300 "Specify route target list\n"
9301 "Specify route target list\n"
9302 "Between current address-family and vpn\n"
9303 "For routes leaked from vpn to current address-family\n"
9304 "For routes leaked from current address-family to vpn\n"
9305 "both import and export\n")
9306
9307DEFPY_YANG (af_route_map_vpn_imexport,
9308 af_route_map_vpn_imexport_cmd,
9309/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
9310 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
9311 NO_STR
9312 "Specify route map\n"
9313 "Between current address-family and vpn\n"
9314 "For routes leaked from vpn to current address-family\n"
9315 "For routes leaked from current address-family to vpn\n"
9316 "name of route-map\n")
9317{
9318 char base_xpath[XPATH_MAXLEN];
9319 afi_t afi;
9320 safi_t safi;
9321 int idx = 0;
9322
9323 afi = bgp_node_afi(vty);
9324 safi = bgp_node_safi(vty);
9325
9326 snprintf(
9327 base_xpath, sizeof(base_xpath),
9328 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config",
9329 yang_afi_safi_value2identity(afi, safi),
9330 bgp_afi_safi_get_container_str(afi, safi));
9331
9332 if (argv_find(argv, argc, "no", &idx)) {
9333 if (!strcmp(direction_str, "import"))
9334 nb_cli_enqueue_change(vty, "./rmap-import",
9335 NB_OP_DESTROY, NULL);
9336 else if (!strcmp(direction_str, "export"))
9337 nb_cli_enqueue_change(vty, "./rmap-export",
9338 NB_OP_DESTROY, NULL);
9339 } else {
9340 if (!strcmp(direction_str, "import"))
9341 nb_cli_enqueue_change(vty, "./rmap-import",
9342 NB_OP_MODIFY, rmap_str);
9343 if (!strcmp(direction_str, "export"))
9344 nb_cli_enqueue_change(vty, "./rmap-export",
9345 NB_OP_MODIFY, rmap_str);
9346 }
9347 return nb_cli_apply_changes(vty, base_xpath);
9348}
9349
9350void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_import(
9351 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9352{
9353 int indent = 2;
9354
9355 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9356 yang_dnode_get_string(dnode, NULL));
9357}
9358
9359void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_rmap_export(
9360 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9361{
9362 int indent = 2;
9363
9364 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
9365 yang_dnode_get_string(dnode, NULL));
9366}
9367
9368ALIAS (af_route_map_vpn_imexport,
9369 af_no_route_map_vpn_imexport_cmd,
9370 "no route-map vpn <import|export>$direction_str",
9371 NO_STR
9372 "Specify route map\n"
9373 "Between current address-family and vpn\n"
9374 "For routes leaked from vpn to current address-family\n"
9375 "For routes leaked from current address-family to vpn\n")
9376
9377DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
9378 "import vrf route-map RMAP$rmap_str",
9379 "Import routes from another VRF\n"
9380 "Vrf routes being filtered\n"
9381 "Specify route map\n"
9382 "name of route-map\n")
9383{
9384 VTY_DECLVAR_CONTEXT(bgp, bgp);
9385 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9386 afi_t afi;
9387 struct bgp *bgp_default;
9388
9389 afi = vpn_policy_getafi(vty, bgp, true);
9390 if (afi == AFI_MAX)
9391 return CMD_WARNING_CONFIG_FAILED;
9392
9393 bgp_default = bgp_get_default();
9394 if (!bgp_default) {
9395 int32_t ret;
9396 as_t as = bgp->as;
9397
9398 /* Auto-create assuming the same AS */
9399 ret = bgp_get_vty(&bgp_default, &as, NULL,
9400 BGP_INSTANCE_TYPE_DEFAULT);
9401
9402 if (ret) {
9403 vty_out(vty,
9404 "VRF default is not configured as a bgp instance\n");
9405 return CMD_WARNING;
9406 }
9407 }
9408
9409 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9410
9411 if (bgp->vpn_policy[afi].rmap_name[dir])
9412 XFREE(MTYPE_ROUTE_MAP_NAME,
9413 bgp->vpn_policy[afi].rmap_name[dir]);
9414 bgp->vpn_policy[afi].rmap_name[dir] =
9415 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
9416 bgp->vpn_policy[afi].rmap[dir] =
9417 route_map_lookup_warn_noexist(vty, rmap_str);
9418 if (!bgp->vpn_policy[afi].rmap[dir])
9419 return CMD_SUCCESS;
9420
9421 SET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9422 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9423
9424 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9425
9426 return CMD_SUCCESS;
9427}
9428
9429DEFPY(af_no_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
9430 "no import vrf route-map [RMAP$rmap_str]",
9431 NO_STR
9432 "Import routes from another VRF\n"
9433 "Vrf routes being filtered\n"
9434 "Specify route map\n"
9435 "name of route-map\n")
9436{
9437 VTY_DECLVAR_CONTEXT(bgp, bgp);
9438 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
9439 afi_t afi;
9440
9441 afi = vpn_policy_getafi(vty, bgp, true);
9442 if (afi == AFI_MAX)
9443 return CMD_WARNING_CONFIG_FAILED;
9444
9445 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
9446
9447 if (bgp->vpn_policy[afi].rmap_name[dir])
9448 XFREE(MTYPE_ROUTE_MAP_NAME,
9449 bgp->vpn_policy[afi].rmap_name[dir]);
9450 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
9451 bgp->vpn_policy[afi].rmap[dir] = NULL;
9452
9453 if (bgp->vpn_policy[afi].import_vrf->count == 0)
9454 UNSET_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
9455 BGP_CONFIG_VRF_TO_VRF_IMPORT);
9456
9457 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
9458
9459 return CMD_SUCCESS;
9460}
9461
9462DEFPY_YANG(bgp_imexport_vrf,
9463 bgp_imexport_vrf_cmd,
9464 "[no] import vrf VIEWVRFNAME$import_name",
9465 NO_STR
9466 "Import routes from another VRF\n"
9467 "VRF to import from\n"
9468 "The name of the VRF\n")
9469{
9470 char base_xpath[XPATH_MAXLEN];
9471 safi_t safi;
9472 afi_t afi;
9473 int32_t idx = 0;
9474
9475 if (import_name == NULL) {
9476 vty_out(vty, "%% Missing import name\n");
9477 return CMD_WARNING;
9478 }
9479
9480 if (strcmp(import_name, "route-map") == 0) {
9481 vty_out(vty, "%% Must include route-map name\n");
9482 return CMD_WARNING;
9483 }
9484
9485 afi = bgp_node_afi(vty);
9486 safi = bgp_node_safi(vty);
9487
9488 snprintf(
9489 base_xpath, sizeof(base_xpath),
9490 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vrf-list[vrf='%s']",
9491 yang_afi_safi_value2identity(afi, safi),
9492 bgp_afi_safi_get_container_str(afi, safi), import_name);
9493
9494 if (argv_find(argv, argc, "no", &idx))
9495 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9496 else
9497 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
9498
9499 return nb_cli_apply_changes(vty, base_xpath);
9500}
9501
9502void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vrfs(
9503 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9504{
9505 vty_out(vty, " import vrf %s\n",
9506 yang_dnode_get_string(dnode, "./vrf"));
9507}
9508
9509/* This command is valid only in a bgp vrf instance or the default instance */
9510DEFPY_YANG (bgp_imexport_vpn,
9511 bgp_imexport_vpn_cmd,
9512 "[no] <import|export>$direction_str vpn",
9513 NO_STR
9514 "Import routes to this address-family\n"
9515 "Export routes from this address-family\n"
9516 "to/from default instance VPN RIB\n")
9517{
9518 char base_xpath[XPATH_MAXLEN];
9519 safi_t safi;
9520 afi_t afi;
9521 int32_t idx = 0;
9522
9523 afi = bgp_node_afi(vty);
9524 safi = bgp_node_safi(vty);
9525
9526 if (!strcmp(direction_str, "import")) {
9527 snprintf(
9528 base_xpath, sizeof(base_xpath),
9529 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/import-vpn",
9530 yang_afi_safi_value2identity(afi, safi),
9531 bgp_afi_safi_get_container_str(afi, safi));
9532 } else if (!strcmp(direction_str, "export")) {
9533 snprintf(
9534 base_xpath, sizeof(base_xpath),
9535 "./global/afi-safis/afi-safi[afi-safi-name='%s']/%s/vpn-config/export-vpn",
9536 yang_afi_safi_value2identity(afi, safi),
9537 bgp_afi_safi_get_container_str(afi, safi));
9538 } else {
9539 vty_out(vty, "%% unknown direction %s\n", direction_str);
9540 return CMD_WARNING_CONFIG_FAILED;
9541 }
9542
9543 if (argv_find(argv, argc, "no", &idx))
9544 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
9545 else
9546 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, "true");
9547
9548 return nb_cli_apply_changes(vty, base_xpath);
9549}
9550
9551void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_import_vpn(
9552 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9553{
9554 if (yang_dnode_get_bool(dnode, NULL))
9555 vty_out(vty, " import vpn\n");
9556}
9557
9558void cli_show_bgp_global_afi_safi_ip_unicast_vpn_config_export_vpn(
9559 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
9560{
9561 if (yang_dnode_get_bool(dnode, NULL))
9562 vty_out(vty, " export vpn\n");
9563}
9564
9565DEFPY (af_routetarget_import,
9566 af_routetarget_import_cmd,
9567 "[no] <rt|route-target|route-target6|rt6> redirect import RTLIST...",
9568 NO_STR
9569 "Specify route target list\n"
9570 "Specify route target list\n"
9571 "Specify route target list\n"
9572 "Specify route target list\n"
9573 "Flow-spec redirect type route target\n"
9574 "Import routes to this address-family\n"
9575 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN|IPV6:MN)\n")
9576{
9577 VTY_DECLVAR_CONTEXT(bgp, bgp);
9578 int ret;
9579 struct ecommunity *ecom = NULL;
9580 afi_t afi;
9581 int idx = 0, idx_unused = 0;
9582 bool yes = true;
9583 bool rt6 = false;
9584
9585 if (argv_find(argv, argc, "no", &idx))
9586 yes = false;
9587
9588 if (argv_find(argv, argc, "rt6", &idx_unused) ||
9589 argv_find(argv, argc, "route-target6", &idx_unused))
9590 rt6 = true;
9591
9592 afi = vpn_policy_getafi(vty, bgp, false);
9593 if (afi == AFI_MAX)
9594 return CMD_WARNING_CONFIG_FAILED;
9595
9596 if (rt6 && afi != AFI_IP6)
9597 return CMD_WARNING_CONFIG_FAILED;
9598
9599 if (yes) {
9600 if (!argv_find(argv, argc, "RTLIST", &idx)) {
9601 vty_out(vty, "%% Missing RTLIST\n");
9602 return CMD_WARNING_CONFIG_FAILED;
9603 }
9604 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom, rt6);
9605 if (ret != CMD_SUCCESS)
9606 return ret;
9607 }
9608
9609 if (yes) {
9610 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9611 ecommunity_free(&bgp->vpn_policy[afi]
9612 .import_redirect_rtlist);
9613 bgp->vpn_policy[afi].import_redirect_rtlist =
9614 ecommunity_dup(ecom);
9615 } else {
9616 if (bgp->vpn_policy[afi].import_redirect_rtlist)
9617 ecommunity_free(&bgp->vpn_policy[afi]
9618 .import_redirect_rtlist);
9619 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
9620 }
9621
9622 if (ecom)
9623 ecommunity_free(&ecom);
9624
9625 return CMD_SUCCESS;
9626}
9627
9628void cli_show_bgp_global_afi_safi_header(struct vty *vty,
9629 struct lyd_node *dnode,
9630 bool show_defaults)
9631{
9632 const char *af_name;
9633 afi_t afi;
9634 safi_t safi;
9635
9636 af_name = yang_dnode_get_string(dnode, "./afi-safi-name");
9637 yang_afi_safi_identity2value(af_name, &afi, &safi);
9638
9639 vty_out(vty, " !\n address-family ");
9640 if (afi == AFI_IP) {
9641 if (safi == SAFI_UNICAST)
9642 vty_out(vty, "ipv4 unicast");
9643 else if (safi == SAFI_LABELED_UNICAST)
9644 vty_out(vty, "ipv4 labeled-unicast");
9645 else if (safi == SAFI_MULTICAST)
9646 vty_out(vty, "ipv4 multicast");
9647 else if (safi == SAFI_MPLS_VPN)
9648 vty_out(vty, "ipv4 vpn");
9649 else if (safi == SAFI_ENCAP)
9650 vty_out(vty, "ipv4 encap");
9651 else if (safi == SAFI_FLOWSPEC)
9652 vty_out(vty, "ipv4 flowspec");
9653 } else if (afi == AFI_IP6) {
9654 if (safi == SAFI_UNICAST)
9655 vty_out(vty, "ipv6 unicast");
9656 else if (safi == SAFI_LABELED_UNICAST)
9657 vty_out(vty, "ipv6 labeled-unicast");
9658 else if (safi == SAFI_MULTICAST)
9659 vty_out(vty, "ipv6 multicast");
9660 else if (safi == SAFI_MPLS_VPN)
9661 vty_out(vty, "ipv6 vpn");
9662 else if (safi == SAFI_ENCAP)
9663 vty_out(vty, "ipv6 encap");
9664 else if (safi == SAFI_FLOWSPEC)
9665 vty_out(vty, "ipv6 flowspec");
9666 } else if (afi == AFI_L2VPN) {
9667 if (safi == SAFI_EVPN)
9668 vty_out(vty, "l2vpn evpn");
9669 }
9670 vty_out(vty, "\n");
9671}
9672
9673DEFUN_NOSH (address_family_ipv4_safi,
9674 address_family_ipv4_safi_cmd,
9675 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9676 "Enter Address Family command mode\n"
9677 "Address Family\n"
9678 BGP_SAFI_WITH_LABEL_HELP_STR)
9679{
9680
9681 safi_t safi = SAFI_UNICAST;
9682 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9683 const char *vrf_name = NULL;
9684
9685 if (argc == 3) {
9686 safi = bgp_vty_safi_from_str(argv[2]->text);
9687
9688 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9689 VTY_CURR_XPATH);
9690 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9691 "control-plane-protocol");
9692 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9693
9694 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9695 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9696 && safi != SAFI_EVPN) {
9697 vty_out(vty,
9698 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9699 return CMD_WARNING_CONFIG_FAILED;
9700 }
9701 }
9702 vty->node = bgp_node_type(AFI_IP, safi);
9703
9704 return CMD_SUCCESS;
9705}
9706
9707DEFUN_NOSH (address_family_ipv6_safi,
9708 address_family_ipv6_safi_cmd,
9709 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
9710 "Enter Address Family command mode\n"
9711 "Address Family\n"
9712 BGP_SAFI_WITH_LABEL_HELP_STR)
9713{
9714 safi_t safi = SAFI_UNICAST;
9715 const struct lyd_node *vrf_dnode, *bgp_glb_dnode;
9716 const char *vrf_name = NULL;
9717
9718 if (argc == 3) {
9719 safi = bgp_vty_safi_from_str(argv[2]->text);
9720 bgp_glb_dnode = yang_dnode_get(vty->candidate_config->dnode,
9721 VTY_CURR_XPATH);
9722 vrf_dnode = yang_dnode_get_parent(bgp_glb_dnode,
9723 "control-plane-protocol");
9724 vrf_name = yang_dnode_get_string(vrf_dnode, "./vrf");
9725
9726 if (!strmatch(vrf_name, VRF_DEFAULT_NAME)
9727 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9728 && safi != SAFI_EVPN) {
9729 vty_out(vty,
9730 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
9731 return CMD_WARNING_CONFIG_FAILED;
9732 }
9733 }
9734 vty->node = bgp_node_type(AFI_IP6, safi);
9735
9736 return CMD_SUCCESS;
9737}
9738
9739#ifdef KEEP_OLD_VPN_COMMANDS
9740DEFUN_NOSH (address_family_vpnv4,
9741 address_family_vpnv4_cmd,
9742 "address-family vpnv4 [unicast]",
9743 "Enter Address Family command mode\n"
9744 "Address Family\n"
9745 "Address Family modifier\n")
9746{
9747 vty->node = BGP_VPNV4_NODE;
9748 return CMD_SUCCESS;
9749}
9750
9751DEFUN_NOSH (address_family_vpnv6,
9752 address_family_vpnv6_cmd,
9753 "address-family vpnv6 [unicast]",
9754 "Enter Address Family command mode\n"
9755 "Address Family\n"
9756 "Address Family modifier\n")
9757{
9758 vty->node = BGP_VPNV6_NODE;
9759 return CMD_SUCCESS;
9760}
9761#endif /* KEEP_OLD_VPN_COMMANDS */
9762
9763DEFUN_NOSH (address_family_evpn,
9764 address_family_evpn_cmd,
9765 "address-family l2vpn evpn",
9766 "Enter Address Family command mode\n"
9767 "Address Family\n"
9768 "Address Family modifier\n")
9769{
9770 VTY_DECLVAR_CONTEXT(bgp, bgp);
9771 vty->node = BGP_EVPN_NODE;
9772 return CMD_SUCCESS;
9773}
9774
9775DEFUN_NOSH (exit_address_family,
9776 exit_address_family_cmd,
9777 "exit-address-family",
9778 "Exit from Address Family configuration mode\n")
9779{
9780 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
9781 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
9782 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
9783 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
9784 || vty->node == BGP_EVPN_NODE
9785 || vty->node == BGP_FLOWSPECV4_NODE
9786 || vty->node == BGP_FLOWSPECV6_NODE)
9787 vty->node = BGP_NODE;
9788 return CMD_SUCCESS;
9789}
9790
9791void cli_show_bgp_global_afi_safi_header_end(struct vty *vty,
9792 struct lyd_node *dnode
9793 __attribute__((__unused__)))
9794{
9795 vty_out(vty, " exit-address-family\n");
9796}
9797
9798/* Recalculate bestpath and re-advertise a prefix */
9799static int bgp_clear_prefix(struct vty *vty, const char *view_name,
9800 const char *ip_str, afi_t afi, safi_t safi,
9801 struct prefix_rd *prd)
9802{
9803 int ret;
9804 struct prefix match;
9805 struct bgp_dest *dest;
9806 struct bgp_dest *rm;
9807 struct bgp *bgp;
9808 struct bgp_table *table;
9809 struct bgp_table *rib;
9810
9811 /* BGP structure lookup. */
9812 if (view_name) {
9813 bgp = bgp_lookup_by_name(view_name);
9814 if (bgp == NULL) {
9815 vty_out(vty, "%% Can't find BGP instance %s\n",
9816 view_name);
9817 return CMD_WARNING;
9818 }
9819 } else {
9820 bgp = bgp_get_default();
9821 if (bgp == NULL) {
9822 vty_out(vty, "%% No BGP process is configured\n");
9823 return CMD_WARNING;
9824 }
9825 }
9826
9827 /* Check IP address argument. */
9828 ret = str2prefix(ip_str, &match);
9829 if (!ret) {
9830 vty_out(vty, "%% address is malformed\n");
9831 return CMD_WARNING;
9832 }
9833
9834 match.family = afi2family(afi);
9835 rib = bgp->rib[afi][safi];
9836
9837 if (safi == SAFI_MPLS_VPN) {
9838 for (dest = bgp_table_top(rib); dest;
9839 dest = bgp_route_next(dest)) {
9840 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9841
9842 if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
9843 continue;
9844
9845 table = bgp_dest_get_bgp_table_info(dest);
9846 if (table == NULL)
9847 continue;
9848
9849 if ((rm = bgp_node_match(table, &match)) != NULL) {
9850 const struct prefix *rm_p =
9851 bgp_dest_get_prefix(rm);
9852
9853 if (rm_p->prefixlen == match.prefixlen) {
9854 SET_FLAG(rm->flags,
9855 BGP_NODE_USER_CLEAR);
9856 bgp_process(bgp, rm, afi, safi);
9857 }
9858 bgp_dest_unlock_node(rm);
9859 }
9860 }
9861 } else {
9862 if ((dest = bgp_node_match(rib, &match)) != NULL) {
9863 const struct prefix *dest_p = bgp_dest_get_prefix(dest);
9864
9865 if (dest_p->prefixlen == match.prefixlen) {
9866 SET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
9867 bgp_process(bgp, dest, afi, safi);
9868 }
9869 bgp_dest_unlock_node(dest);
9870 }
9871 }
9872
9873 return CMD_SUCCESS;
9874}
9875
9876/* one clear bgp command to rule them all */
9877DEFUN (clear_ip_bgp_all,
9878 clear_ip_bgp_all_cmd,
9879 "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>]",
9880 CLEAR_STR
9881 IP_STR
9882 BGP_STR
9883 BGP_INSTANCE_HELP_STR
9884 BGP_AFI_HELP_STR
9885 "Address Family\n"
9886 BGP_SAFI_WITH_LABEL_HELP_STR
9887 "Address Family modifier\n"
9888 "Clear all peers\n"
9889 "BGP IPv4 neighbor to clear\n"
9890 "BGP IPv6 neighbor to clear\n"
9891 "BGP neighbor on interface to clear\n"
9892 "Clear peers with the AS number\n"
9893 "Clear all external peers\n"
9894 "Clear all members of peer-group\n"
9895 "BGP peer-group name\n"
9896 BGP_SOFT_STR
9897 BGP_SOFT_IN_STR
9898 BGP_SOFT_OUT_STR
9899 BGP_SOFT_IN_STR
9900 "Push out prefix-list ORF and do inbound soft reconfig\n"
9901 BGP_SOFT_OUT_STR)
9902{
9903 char *vrf = NULL;
9904
9905 afi_t afi = AFI_UNSPEC;
9906 safi_t safi = SAFI_UNSPEC;
9907 enum clear_sort clr_sort = clear_peer;
9908 enum bgp_clear_type clr_type;
9909 char *clr_arg = NULL;
9910
9911 int idx = 0;
9912 char errmsg[BUFSIZ] = {'\0'};
9913 int ret;
9914
9915 /* clear [ip] bgp */
9916 if (argv_find(argv, argc, "ip", &idx))
9917 afi = AFI_IP;
9918
9919 /* [<vrf> VIEWVRFNAME] */
9920 if (argv_find(argv, argc, "vrf", &idx)) {
9921 vrf = argv[idx + 1]->arg;
9922 idx += 2;
9923 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
9924 vrf = NULL;
9925 } else if (argv_find(argv, argc, "view", &idx)) {
9926 /* [<view> VIEWVRFNAME] */
9927 vrf = argv[idx + 1]->arg;
9928 idx += 2;
9929 }
9930 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9931 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
9932 argv_find_and_parse_safi(argv, argc, &idx, &safi);
9933
9934 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
9935 if (argv_find(argv, argc, "*", &idx)) {
9936 clr_sort = clear_all;
9937 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
9938 clr_sort = clear_peer;
9939 clr_arg = argv[idx]->arg;
9940 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
9941 clr_sort = clear_peer;
9942 clr_arg = argv[idx]->arg;
9943 } else if (argv_find(argv, argc, "peer-group", &idx)) {
9944 clr_sort = clear_group;
9945 idx++;
9946 clr_arg = argv[idx]->arg;
9947 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
9948 clr_sort = clear_peer;
9949 clr_arg = argv[idx]->arg;
9950 } else if (argv_find(argv, argc, "WORD", &idx)) {
9951 clr_sort = clear_peer;
9952 clr_arg = argv[idx]->arg;
9953 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
9954 clr_sort = clear_as;
9955 clr_arg = argv[idx]->arg;
9956 } else if (argv_find(argv, argc, "external", &idx)) {
9957 clr_sort = clear_external;
9958 }
9959
9960 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
9961 if (argv_find(argv, argc, "soft", &idx)) {
9962 if (argv_find(argv, argc, "in", &idx)
9963 || argv_find(argv, argc, "out", &idx))
9964 clr_type = strmatch(argv[idx]->text, "in")
9965 ? BGP_CLEAR_SOFT_IN
9966 : BGP_CLEAR_SOFT_OUT;
9967 else
9968 clr_type = BGP_CLEAR_SOFT_BOTH;
9969 } else if (argv_find(argv, argc, "in", &idx)) {
9970 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
9971 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
9972 : BGP_CLEAR_SOFT_IN;
9973 } else if (argv_find(argv, argc, "out", &idx)) {
9974 clr_type = BGP_CLEAR_SOFT_OUT;
9975 } else
9976 clr_type = BGP_CLEAR_SOFT_NONE;
9977
9978 ret = bgp_clear_vty(vrf, afi, safi, clr_sort, clr_type, clr_arg, errmsg,
9979 sizeof(errmsg));
9980 if (ret != NB_OK)
9981 vty_out(vty, "Error description: %s\n", errmsg);
9982
9983 return ret;
9984}
9985
9986DEFUN (clear_ip_bgp_prefix,
9987 clear_ip_bgp_prefix_cmd,
9988 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
9989 CLEAR_STR
9990 IP_STR
9991 BGP_STR
9992 BGP_INSTANCE_HELP_STR
9993 "Clear bestpath and re-advertise\n"
9994 "IPv4 prefix\n")
9995{
9996 char *vrf = NULL;
9997 char *prefix = NULL;
9998
9999 int idx = 0;
10000
10001 /* [<view|vrf> VIEWVRFNAME] */
10002 if (argv_find(argv, argc, "vrf", &idx)) {
10003 vrf = argv[idx + 1]->arg;
10004 idx += 2;
10005 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10006 vrf = NULL;
10007 } else if (argv_find(argv, argc, "view", &idx)) {
10008 /* [<view> VIEWVRFNAME] */
10009 vrf = argv[idx + 1]->arg;
10010 idx += 2;
10011 }
10012
10013 prefix = argv[argc - 1]->arg;
10014
10015 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
10016}
10017
10018DEFUN (clear_bgp_ipv6_safi_prefix,
10019 clear_bgp_ipv6_safi_prefix_cmd,
10020 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10021 CLEAR_STR
10022 IP_STR
10023 BGP_STR
10024 "Address Family\n"
10025 BGP_SAFI_HELP_STR
10026 "Clear bestpath and re-advertise\n"
10027 "IPv6 prefix\n")
10028{
10029 int idx_safi = 0;
10030 int idx_ipv6_prefix = 0;
10031 safi_t safi = SAFI_UNICAST;
10032 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10033 argv[idx_ipv6_prefix]->arg : NULL;
10034
10035 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10036 return bgp_clear_prefix(
10037 vty, NULL, prefix, AFI_IP6,
10038 safi, NULL);
10039}
10040
10041DEFUN (clear_bgp_instance_ipv6_safi_prefix,
10042 clear_bgp_instance_ipv6_safi_prefix_cmd,
10043 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
10044 CLEAR_STR
10045 IP_STR
10046 BGP_STR
10047 BGP_INSTANCE_HELP_STR
10048 "Address Family\n"
10049 BGP_SAFI_HELP_STR
10050 "Clear bestpath and re-advertise\n"
10051 "IPv6 prefix\n")
10052{
10053 int idx_safi = 0;
10054 int idx_vrfview = 0;
10055 int idx_ipv6_prefix = 0;
10056 safi_t safi = SAFI_UNICAST;
10057 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
10058 argv[idx_ipv6_prefix]->arg : NULL;
10059 char *vrfview = NULL;
10060
10061 /* [<view|vrf> VIEWVRFNAME] */
10062 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
10063 vrfview = argv[idx_vrfview + 1]->arg;
10064 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
10065 vrfview = NULL;
10066 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
10067 /* [<view> VIEWVRFNAME] */
10068 vrfview = argv[idx_vrfview + 1]->arg;
10069 }
10070 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
10071
10072 return bgp_clear_prefix(
10073 vty, vrfview, prefix,
10074 AFI_IP6, safi, NULL);
10075}
10076
10077DEFUN (show_bgp_views,
10078 show_bgp_views_cmd,
10079 "show [ip] bgp views",
10080 SHOW_STR
10081 IP_STR
10082 BGP_STR
10083 "Show the defined BGP views\n")
10084{
10085 struct list *inst = bm->bgp;
10086 struct listnode *node;
10087 struct bgp *bgp;
10088
10089 vty_out(vty, "Defined BGP views:\n");
10090 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10091 /* Skip VRFs. */
10092 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
10093 continue;
10094 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
10095 bgp->as);
10096 }
10097
10098 return CMD_SUCCESS;
10099}
10100
10101DEFUN (show_bgp_vrfs,
10102 show_bgp_vrfs_cmd,
10103 "show [ip] bgp vrfs [json]",
10104 SHOW_STR
10105 IP_STR
10106 BGP_STR
10107 "Show BGP VRFs\n"
10108 JSON_STR)
10109{
10110 char buf[ETHER_ADDR_STRLEN];
10111 struct list *inst = bm->bgp;
10112 struct listnode *node;
10113 struct bgp *bgp;
10114 bool uj = use_json(argc, argv);
10115 json_object *json = NULL;
10116 json_object *json_vrfs = NULL;
10117 int count = 0;
10118
10119 if (uj) {
10120 json = json_object_new_object();
10121 json_vrfs = json_object_new_object();
10122 }
10123
10124 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
10125 const char *name, *type;
10126 struct peer *peer;
10127 struct listnode *node2, *nnode2;
10128 int peers_cfg, peers_estb;
10129 json_object *json_vrf = NULL;
10130
10131 /* Skip Views. */
10132 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
10133 continue;
10134
10135 count++;
10136 if (!uj && count == 1) {
10137 vty_out(vty,
10138 "%4s %-5s %-16s %9s %10s %-37s\n",
10139 "Type", "Id", "routerId", "#PeersCfg",
10140 "#PeersEstb", "Name");
10141 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
10142 "L3-VNI", "RouterMAC", "Interface");
10143 }
10144
10145 peers_cfg = peers_estb = 0;
10146 if (uj)
10147 json_vrf = json_object_new_object();
10148
10149
10150 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
10151 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10152 continue;
10153 peers_cfg++;
10154 if (peer->status == Established)
10155 peers_estb++;
10156 }
10157
10158 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
10159 name = VRF_DEFAULT_NAME;
10160 type = "DFLT";
10161 } else {
10162 name = bgp->name;
10163 type = "VRF";
10164 }
10165
10166
10167 if (uj) {
10168 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10169 ? -1
10170 : (int64_t)bgp->vrf_id;
10171 char buf[BUFSIZ] = {0};
10172
10173 json_object_string_add(json_vrf, "type", type);
10174 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
10175 json_object_string_add(json_vrf, "routerId",
10176 inet_ntop(AF_INET,
10177 &bgp->router_id, buf,
10178 sizeof(buf)));
10179 json_object_int_add(json_vrf, "numConfiguredPeers",
10180 peers_cfg);
10181 json_object_int_add(json_vrf, "numEstablishedPeers",
10182 peers_estb);
10183
10184 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
10185 json_object_string_add(
10186 json_vrf, "rmac",
10187 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
10188 json_object_string_add(json_vrf, "interface",
10189 ifindex2ifname(bgp->l3vni_svi_ifindex,
10190 bgp->vrf_id));
10191 json_object_object_add(json_vrfs, name, json_vrf);
10192 } else {
10193 vty_out(vty, "%4s %-5d %-16pI4 %-9u %-10u %-37s\n",
10194 type,
10195 bgp->vrf_id == VRF_UNKNOWN ? -1
10196 : (int)bgp->vrf_id,
10197 &bgp->router_id, peers_cfg, peers_estb, name);
10198 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
10199 bgp->l3vni,
10200 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
10201 ifindex2ifname(bgp->l3vni_svi_ifindex,
10202 bgp->vrf_id));
10203 }
10204 }
10205
10206 if (uj) {
10207 json_object_object_add(json, "vrfs", json_vrfs);
10208
10209 json_object_int_add(json, "totalVrfs", count);
10210
10211 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10212 json, JSON_C_TO_STRING_PRETTY));
10213 json_object_free(json);
10214 } else {
10215 if (count)
10216 vty_out(vty,
10217 "\nTotal number of VRFs (including default): %d\n",
10218 count);
10219 }
10220
10221 return CMD_SUCCESS;
10222}
10223
10224DEFUN (show_bgp_mac_hash,
10225 show_bgp_mac_hash_cmd,
10226 "show bgp mac hash",
10227 SHOW_STR
10228 BGP_STR
10229 "Mac Address\n"
10230 "Mac Address database\n")
10231{
10232 bgp_mac_dump_table(vty);
10233
10234 return CMD_SUCCESS;
10235}
10236
10237static void show_tip_entry(struct hash_bucket *bucket, void *args)
10238{
10239 struct vty *vty = (struct vty *)args;
10240 struct tip_addr *tip = (struct tip_addr *)bucket->data;
10241
10242 vty_out(vty, "addr: %pI4, count: %d\n", &tip->addr, tip->refcnt);
10243}
10244
10245static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
10246{
10247 vty_out(vty, "self nexthop database:\n");
10248 bgp_nexthop_show_address_hash(vty, bgp);
10249
10250 vty_out(vty, "Tunnel-ip database:\n");
10251 hash_iterate(bgp->tip_hash,
10252 (void (*)(struct hash_bucket *, void *))show_tip_entry,
10253 vty);
10254}
10255
10256DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
10257 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
10258 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
10259 "martian next-hops\n"
10260 "martian next-hop database\n")
10261{
10262 struct bgp *bgp = NULL;
10263 int idx = 0;
10264 char *name = NULL;
10265
10266 /* [<vrf> VIEWVRFNAME] */
10267 if (argv_find(argv, argc, "vrf", &idx)) {
10268 name = argv[idx + 1]->arg;
10269 if (name && strmatch(name, VRF_DEFAULT_NAME))
10270 name = NULL;
10271 } else if (argv_find(argv, argc, "view", &idx))
10272 /* [<view> VIEWVRFNAME] */
10273 name = argv[idx + 1]->arg;
10274 if (name)
10275 bgp = bgp_lookup_by_name(name);
10276 else
10277 bgp = bgp_get_default();
10278
10279 if (!bgp) {
10280 vty_out(vty, "%% No BGP process is configured\n");
10281 return CMD_WARNING;
10282 }
10283 bgp_show_martian_nexthops(vty, bgp);
10284
10285 return CMD_SUCCESS;
10286}
10287
10288DEFUN (show_bgp_memory,
10289 show_bgp_memory_cmd,
10290 "show [ip] bgp memory",
10291 SHOW_STR
10292 IP_STR
10293 BGP_STR
10294 "Global BGP memory statistics\n")
10295{
10296 char memstrbuf[MTYPE_MEMSTR_LEN];
10297 unsigned long count;
10298
10299 /* RIB related usage stats */
10300 count = mtype_stats_alloc(MTYPE_BGP_NODE);
10301 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
10302 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10303 count * sizeof(struct bgp_dest)));
10304
10305 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
10306 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
10307 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10308 count * sizeof(struct bgp_path_info)));
10309 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
10310 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
10311 count,
10312 mtype_memstr(
10313 memstrbuf, sizeof(memstrbuf),
10314 count * sizeof(struct bgp_path_info_extra)));
10315
10316 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
10317 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
10318 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10319 count * sizeof(struct bgp_static)));
10320
10321 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
10322 vty_out(vty, "%ld Packets, using %s of memory\n", count,
10323 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10324 count * sizeof(struct bpacket)));
10325
10326 /* Adj-In/Out */
10327 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
10328 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
10329 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10330 count * sizeof(struct bgp_adj_in)));
10331 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
10332 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
10333 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10334 count * sizeof(struct bgp_adj_out)));
10335
10336 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
10337 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
10338 count,
10339 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10340 count * sizeof(struct bgp_nexthop_cache)));
10341
10342 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
10343 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
10344 count,
10345 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10346 count * sizeof(struct bgp_damp_info)));
10347
10348 /* Attributes */
10349 count = attr_count();
10350 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
10351 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10352 count * sizeof(struct attr)));
10353
10354 if ((count = attr_unknown_count()))
10355 vty_out(vty, "%ld unknown attributes\n", count);
10356
10357 /* AS_PATH attributes */
10358 count = aspath_count();
10359 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
10360 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10361 count * sizeof(struct aspath)));
10362
10363 count = mtype_stats_alloc(MTYPE_AS_SEG);
10364 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
10365 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10366 count * sizeof(struct assegment)));
10367
10368 /* Other attributes */
10369 if ((count = community_count()))
10370 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10371 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10372 count * sizeof(struct community)));
10373 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
10374 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
10375 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10376 count * sizeof(struct ecommunity)));
10377 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
10378 vty_out(vty,
10379 "%ld BGP large-community entries, using %s of memory\n",
10380 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10381 count * sizeof(struct lcommunity)));
10382
10383 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
10384 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
10385 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10386 count * sizeof(struct cluster_list)));
10387
10388 /* Peer related usage */
10389 count = mtype_stats_alloc(MTYPE_BGP_PEER);
10390 vty_out(vty, "%ld peers, using %s of memory\n", count,
10391 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10392 count * sizeof(struct peer)));
10393
10394 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
10395 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
10396 mtype_memstr(memstrbuf, sizeof(memstrbuf),
10397 count * sizeof(struct peer_group)));
10398
10399 /* Other */
10400 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
10401 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
10402 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
10403 count * sizeof(regex_t)));
10404 return CMD_SUCCESS;
10405}
10406
10407static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
10408{
10409 json_object *bestpath = json_object_new_object();
10410
10411 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
10412 json_object_string_add(bestpath, "asPath", "ignore");
10413
10414 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
10415 json_object_string_add(bestpath, "asPath", "confed");
10416
10417 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
10418 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
10419 json_object_string_add(bestpath, "multiPathRelax",
10420 "as-set");
10421 else
10422 json_object_string_add(bestpath, "multiPathRelax",
10423 "true");
10424 } else
10425 json_object_string_add(bestpath, "multiPathRelax", "false");
10426
10427 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
10428 json_object_string_add(bestpath, "compareRouterId", "true");
10429 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
10430 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
10431 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
10432 json_object_string_add(bestpath, "med", "confed");
10433 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
10434 json_object_string_add(bestpath, "med",
10435 "missing-as-worst");
10436 else
10437 json_object_string_add(bestpath, "med", "true");
10438 }
10439
10440 json_object_object_add(json, "bestPath", bestpath);
10441}
10442
10443/* Print the error code/subcode for why the peer is down */
10444static void bgp_show_peer_reset(struct vty * vty, struct peer *peer,
10445 json_object *json_peer, bool use_json)
10446{
10447 const char *code_str;
10448 const char *subcode_str;
10449
10450 if (use_json) {
10451 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10452 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10453 char errorcodesubcode_hexstr[5];
10454 char errorcodesubcode_str[256];
10455
10456 code_str = bgp_notify_code_str(peer->notify.code);
10457 subcode_str = bgp_notify_subcode_str(
10458 peer->notify.code,
10459 peer->notify.subcode);
10460
10461 snprintf(errorcodesubcode_hexstr,
10462 sizeof(errorcodesubcode_hexstr), "%02X%02X",
10463 peer->notify.code, peer->notify.subcode);
10464 json_object_string_add(json_peer,
10465 "lastErrorCodeSubcode",
10466 errorcodesubcode_hexstr);
10467 snprintf(errorcodesubcode_str, 255, "%s%s",
10468 code_str, subcode_str);
10469 json_object_string_add(json_peer,
10470 "lastNotificationReason",
10471 errorcodesubcode_str);
10472 if (peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10473 && peer->notify.code == BGP_NOTIFY_CEASE
10474 && (peer->notify.subcode
10475 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10476 || peer->notify.subcode
10477 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10478 && peer->notify.length) {
10479 char msgbuf[1024];
10480 const char *msg_str;
10481
10482 msg_str = bgp_notify_admin_message(
10483 msgbuf, sizeof(msgbuf),
10484 (uint8_t *)peer->notify.data,
10485 peer->notify.length);
10486 if (msg_str)
10487 json_object_string_add(
10488 json_peer,
10489 "lastShutdownDescription",
10490 msg_str);
10491 }
10492
10493 }
10494 json_object_string_add(json_peer, "lastResetDueTo",
10495 peer_down_str[(int)peer->last_reset]);
10496 json_object_int_add(json_peer, "lastResetCode",
10497 peer->last_reset);
10498 } else {
10499 if (peer->last_reset == PEER_DOWN_NOTIFY_SEND
10500 || peer->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10501 code_str = bgp_notify_code_str(peer->notify.code);
10502 subcode_str =
10503 bgp_notify_subcode_str(peer->notify.code,
10504 peer->notify.subcode);
10505 vty_out(vty, " Notification %s (%s%s)\n",
10506 peer->last_reset == PEER_DOWN_NOTIFY_SEND
10507 ? "sent"
10508 : "received",
10509 code_str, subcode_str);
10510 } else {
10511 vty_out(vty, " %s\n",
10512 peer_down_str[(int)peer->last_reset]);
10513 }
10514 }
10515}
10516
10517static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi,
10518 safi_t safi)
10519{
10520 return ((peer->status != Established) ||
10521 !peer->afc_recv[afi][safi]);
10522}
10523
10524static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
10525 struct peer *peer, json_object *json_peer,
10526 int max_neighbor_width, bool use_json)
10527{
10528 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10529 int len;
10530
10531 if (use_json) {
10532 if (peer_dynamic_neighbor(peer))
10533 json_object_boolean_true_add(json_peer,
10534 "dynamicPeer");
10535 if (peer->hostname)
10536 json_object_string_add(json_peer, "hostname",
10537 peer->hostname);
10538
10539 if (peer->domainname)
10540 json_object_string_add(json_peer, "domainname",
10541 peer->domainname);
10542 json_object_int_add(json_peer, "connectionsEstablished",
10543 peer->established);
10544 json_object_int_add(json_peer, "connectionsDropped",
10545 peer->dropped);
10546 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10547 use_json, json_peer);
10548 if (peer->status == Established)
10549 json_object_string_add(json_peer, "lastResetDueTo",
10550 "AFI/SAFI Not Negotiated");
10551 else
10552 bgp_show_peer_reset(NULL, peer, json_peer, true);
10553 } else {
10554 dn_flag[1] = '\0';
10555 dn_flag[0] = peer_dynamic_neighbor(peer) ? '*' : '\0';
10556 if (peer->hostname
10557 && CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME))
10558 len = vty_out(vty, "%s%s(%s)", dn_flag,
10559 peer->hostname, peer->host);
10560 else
10561 len = vty_out(vty, "%s%s", dn_flag, peer->host);
10562
10563 /* pad the neighbor column with spaces */
10564 if (len < max_neighbor_width)
10565 vty_out(vty, "%*s", max_neighbor_width - len,
10566 " ");
10567 vty_out(vty, "%7d %7d %9s", peer->established,
10568 peer->dropped,
10569 peer_uptime(peer->uptime, timebuf,
10570 BGP_UPTIME_LEN, 0, NULL));
10571 if (peer->status == Established)
10572 vty_out(vty, " AFI/SAFI Not Negotiated\n");
10573 else
10574 bgp_show_peer_reset(vty, peer, NULL,
10575 false);
10576 }
10577}
10578
10579/* If the peer's description includes whitespaces
10580 * then return the first occurrence. Also strip description
10581 * to the given size if needed.
10582 */
10583static char *bgp_peer_description_stripped(char *desc, uint32_t size)
10584{
10585 static char stripped[BUFSIZ];
10586 char *pnt;
10587 uint32_t len = size > strlen(desc) ? strlen(desc) : size;
10588
10589 pnt = strchr(desc, ' ');
10590 if (pnt)
10591 len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
10592 : size;
10593
10594 strlcpy(stripped, desc, len + 1);
10595
10596 return stripped;
10597}
10598
10599/* Show BGP peer's summary information. */
10600static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
10601 uint8_t show_flags)
10602{
10603 struct peer *peer;
10604 struct listnode *node, *nnode;
10605 unsigned int count = 0, dn_count = 0;
10606 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
10607 char neighbor_buf[VTY_BUFSIZ];
10608 int neighbor_col_default_width = 16;
10609 int len, failed_count = 0;
10610 int max_neighbor_width = 0;
10611 int pfx_rcd_safi;
10612 json_object *json = NULL;
10613 json_object *json_peer = NULL;
10614 json_object *json_peers = NULL;
10615 struct peer_af *paf;
10616 struct bgp_filter *filter;
10617 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
10618 bool show_failed = CHECK_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
10619 bool show_established =
10620 CHECK_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
10621 bool show_wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
10622
10623 /* labeled-unicast routes are installed in the unicast table so in order
10624 * to
10625 * display the correct PfxRcd value we must look at SAFI_UNICAST
10626 */
10627
10628 if (safi == SAFI_LABELED_UNICAST)
10629 pfx_rcd_safi = SAFI_UNICAST;
10630 else
10631 pfx_rcd_safi = safi;
10632
10633 if (use_json) {
10634 json = json_object_new_object();
10635 json_peers = json_object_new_object();
10636 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10637 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10638 continue;
10639
10640 if (peer->afc[afi][safi]) {
10641 /* See if we have at least a single failed peer */
10642 if (bgp_has_peer_failed(peer, afi, safi))
10643 failed_count++;
10644 count++;
10645 }
10646 if (peer_dynamic_neighbor(peer))
10647 dn_count++;
10648 }
10649
10650 } else {
10651 /* Loop over all neighbors that will be displayed to determine
10652 * how many
10653 * characters are needed for the Neighbor column
10654 */
10655 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10656 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10657 continue;
10658
10659 if (peer->afc[afi][safi]) {
10660 memset(dn_flag, '\0', sizeof(dn_flag));
10661 if (peer_dynamic_neighbor(peer))
10662 dn_flag[0] = '*';
10663
10664 if (peer->hostname
10665 && CHECK_FLAG(bgp->flags,
10666 BGP_FLAG_SHOW_HOSTNAME))
10667 snprintf(neighbor_buf,
10668 sizeof(neighbor_buf),
10669 "%s%s(%s) ", dn_flag,
10670 peer->hostname, peer->host);
10671 else
10672 snprintf(neighbor_buf,
10673 sizeof(neighbor_buf), "%s%s ",
10674 dn_flag, peer->host);
10675
10676 len = strlen(neighbor_buf);
10677
10678 if (len > max_neighbor_width)
10679 max_neighbor_width = len;
10680
10681 /* See if we have at least a single failed peer */
10682 if (bgp_has_peer_failed(peer, afi, safi))
10683 failed_count++;
10684 count++;
10685 }
10686 }
10687
10688 /* Originally we displayed the Neighbor column as 16
10689 * characters wide so make that the default
10690 */
10691 if (max_neighbor_width < neighbor_col_default_width)
10692 max_neighbor_width = neighbor_col_default_width;
10693 }
10694
10695 if (show_failed && !failed_count) {
10696 if (use_json) {
10697 json_object_int_add(json, "failedPeersCount", 0);
10698 json_object_int_add(json, "dynamicPeers", dn_count);
10699 json_object_int_add(json, "totalPeers", count);
10700
10701 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10702 json, JSON_C_TO_STRING_PRETTY));
10703 json_object_free(json);
10704 } else {
10705 vty_out(vty, "%% No failed BGP neighbors found\n");
10706 vty_out(vty, "\nTotal number of neighbors %d\n", count);
10707 }
10708 return CMD_SUCCESS;
10709 }
10710
10711 count = 0; /* Reset the value as its used again */
10712 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10713 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10714 continue;
10715
10716 if (!peer->afc[afi][safi])
10717 continue;
10718
10719 if (!count) {
10720 unsigned long ents;
10721 char memstrbuf[MTYPE_MEMSTR_LEN];
10722 int64_t vrf_id_ui;
10723
10724 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
10725 ? -1
10726 : (int64_t)bgp->vrf_id;
10727
10728 /* Usage summary and header */
10729 if (use_json) {
10730 char buf[BUFSIZ] = {0};
10731
10732 json_object_string_add(
10733 json, "routerId",
10734 inet_ntop(AF_INET, &bgp->router_id, buf,
10735 sizeof(buf)));
10736 json_object_int_add(json, "as", bgp->as);
10737 json_object_int_add(json, "vrfId", vrf_id_ui);
10738 json_object_string_add(
10739 json, "vrfName",
10740 (bgp->inst_type
10741 == BGP_INSTANCE_TYPE_DEFAULT)
10742 ? VRF_DEFAULT_NAME
10743 : bgp->name);
10744 } else {
10745 vty_out(vty,
10746 "BGP router identifier %pI4, local AS number %u vrf-id %d",
10747 &bgp->router_id, bgp->as,
10748 bgp->vrf_id == VRF_UNKNOWN
10749 ? -1
10750 : (int)bgp->vrf_id);
10751 vty_out(vty, "\n");
10752 }
10753
10754 if (bgp_update_delay_configured(bgp)) {
10755 if (use_json) {
10756 json_object_int_add(
10757 json, "updateDelayLimit",
10758 bgp->v_update_delay);
10759
10760 if (bgp->v_update_delay
10761 != bgp->v_establish_wait)
10762 json_object_int_add(
10763 json,
10764 "updateDelayEstablishWait",
10765 bgp->v_establish_wait);
10766
10767 if (bgp_update_delay_active(bgp)) {
10768 json_object_string_add(
10769 json,
10770 "updateDelayFirstNeighbor",
10771 bgp->update_delay_begin_time);
10772 json_object_boolean_true_add(
10773 json,
10774 "updateDelayInProgress");
10775 } else {
10776 if (bgp->update_delay_over) {
10777 json_object_string_add(
10778 json,
10779 "updateDelayFirstNeighbor",
10780 bgp->update_delay_begin_time);
10781 json_object_string_add(
10782 json,
10783 "updateDelayBestpathResumed",
10784 bgp->update_delay_end_time);
10785 json_object_string_add(
10786 json,
10787 "updateDelayZebraUpdateResume",
10788 bgp->update_delay_zebra_resume_time);
10789 json_object_string_add(
10790 json,
10791 "updateDelayPeerUpdateResume",
10792 bgp->update_delay_peers_resume_time);
10793 }
10794 }
10795 } else {
10796 vty_out(vty,
10797 "Read-only mode update-delay limit: %d seconds\n",
10798 bgp->v_update_delay);
10799 if (bgp->v_update_delay
10800 != bgp->v_establish_wait)
10801 vty_out(vty,
10802 " Establish wait: %d seconds\n",
10803 bgp->v_establish_wait);
10804
10805 if (bgp_update_delay_active(bgp)) {
10806 vty_out(vty,
10807 " First neighbor established: %s\n",
10808 bgp->update_delay_begin_time);
10809 vty_out(vty,
10810 " Delay in progress\n");
10811 } else {
10812 if (bgp->update_delay_over) {
10813 vty_out(vty,
10814 " First neighbor established: %s\n",
10815 bgp->update_delay_begin_time);
10816 vty_out(vty,
10817 " Best-paths resumed: %s\n",
10818 bgp->update_delay_end_time);
10819 vty_out(vty,
10820 " zebra update resumed: %s\n",
10821 bgp->update_delay_zebra_resume_time);
10822 vty_out(vty,
10823 " peers update resumed: %s\n",
10824 bgp->update_delay_peers_resume_time);
10825 }
10826 }
10827 }
10828 }
10829
10830 if (use_json) {
10831 if (bgp_maxmed_onstartup_configured(bgp)
10832 && bgp->maxmed_active)
10833 json_object_boolean_true_add(
10834 json, "maxMedOnStartup");
10835 if (bgp->v_maxmed_admin)
10836 json_object_boolean_true_add(
10837 json, "maxMedAdministrative");
10838
10839 json_object_int_add(
10840 json, "tableVersion",
10841 bgp_table_version(bgp->rib[afi][safi]));
10842
10843 ents = bgp_table_count(bgp->rib[afi][safi]);
10844 json_object_int_add(json, "ribCount", ents);
10845 json_object_int_add(
10846 json, "ribMemory",
10847 ents * sizeof(struct bgp_dest));
10848
10849 ents = bgp->af_peer_count[afi][safi];
10850 json_object_int_add(json, "peerCount", ents);
10851 json_object_int_add(json, "peerMemory",
10852 ents * sizeof(struct peer));
10853
10854 if ((ents = listcount(bgp->group))) {
10855 json_object_int_add(
10856 json, "peerGroupCount", ents);
10857 json_object_int_add(
10858 json, "peerGroupMemory",
10859 ents * sizeof(struct
10860 peer_group));
10861 }
10862
10863 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10864 BGP_CONFIG_DAMPENING))
10865 json_object_boolean_true_add(
10866 json, "dampeningEnabled");
10867 } else {
10868 if (bgp_maxmed_onstartup_configured(bgp)
10869 && bgp->maxmed_active)
10870 vty_out(vty,
10871 "Max-med on-startup active\n");
10872 if (bgp->v_maxmed_admin)
10873 vty_out(vty,
10874 "Max-med administrative active\n");
10875
10876 vty_out(vty, "BGP table version %" PRIu64 "\n",
10877 bgp_table_version(bgp->rib[afi][safi]));
10878
10879 ents = bgp_table_count(bgp->rib[afi][safi]);
10880 vty_out(vty,
10881 "RIB entries %ld, using %s of memory\n",
10882 ents,
10883 mtype_memstr(
10884 memstrbuf, sizeof(memstrbuf),
10885 ents
10886 * sizeof(struct
10887 bgp_dest)));
10888
10889 /* Peer related usage */
10890 ents = bgp->af_peer_count[afi][safi];
10891 vty_out(vty, "Peers %ld, using %s of memory\n",
10892 ents,
10893 mtype_memstr(
10894 memstrbuf, sizeof(memstrbuf),
10895 ents * sizeof(struct peer)));
10896
10897 if ((ents = listcount(bgp->group)))
10898 vty_out(vty,
10899 "Peer groups %ld, using %s of memory\n",
10900 ents,
10901 mtype_memstr(
10902 memstrbuf,
10903 sizeof(memstrbuf),
10904 ents * sizeof(struct
10905 peer_group)));
10906
10907 if (CHECK_FLAG(bgp->af_flags[afi][safi],
10908 BGP_CONFIG_DAMPENING))
10909 vty_out(vty, "Dampening enabled.\n");
10910 vty_out(vty, "\n");
10911
10912 /* Subtract 8 here because 'Neighbor' is
10913 * 8 characters */
10914 vty_out(vty, "Neighbor");
10915 vty_out(vty, "%*s", max_neighbor_width - 8,
10916 " ");
10917 if (show_failed)
10918 vty_out(vty,
10919 BGP_SHOW_SUMMARY_HEADER_FAILED);
10920 else
10921 vty_out(vty,
10922 show_wide
10923 ? BGP_SHOW_SUMMARY_HEADER_ALL_WIDE
10924 : BGP_SHOW_SUMMARY_HEADER_ALL);
10925 }
10926 }
10927
10928 paf = peer_af_find(peer, afi, safi);
10929 filter = &peer->filter[afi][safi];
10930
10931 count++;
10932 /* Works for both failed & successful cases */
10933 if (peer_dynamic_neighbor(peer))
10934 dn_count++;
10935
10936 if (use_json) {
10937 json_peer = NULL;
10938
10939 if (show_failed &&
10940 bgp_has_peer_failed(peer, afi, safi)) {
10941 json_peer = json_object_new_object();
10942 bgp_show_failed_summary(vty, bgp, peer,
10943 json_peer, 0, use_json);
10944 } else if (!show_failed) {
10945 if (show_established
10946 && bgp_has_peer_failed(peer, afi, safi))
10947 continue;
10948
10949 json_peer = json_object_new_object();
10950 if (peer_dynamic_neighbor(peer)) {
10951 json_object_boolean_true_add(json_peer,
10952 "dynamicPeer");
10953 }
10954
10955 if (peer->hostname)
10956 json_object_string_add(json_peer, "hostname",
10957 peer->hostname);
10958
10959 if (peer->domainname)
10960 json_object_string_add(json_peer, "domainname",
10961 peer->domainname);
10962
10963 json_object_int_add(json_peer, "remoteAs", peer->as);
10964 json_object_int_add(
10965 json_peer, "localAs",
10966 peer->change_local_as
10967 ? peer->change_local_as
10968 : peer->local_as);
10969 json_object_int_add(json_peer, "version", 4);
10970 json_object_int_add(json_peer, "msgRcvd",
10971 PEER_TOTAL_RX(peer));
10972 json_object_int_add(json_peer, "msgSent",
10973 PEER_TOTAL_TX(peer));
10974
10975 atomic_size_t outq_count, inq_count;
10976 outq_count = atomic_load_explicit(
10977 &peer->obuf->count,
10978 memory_order_relaxed);
10979 inq_count = atomic_load_explicit(
10980 &peer->ibuf->count,
10981 memory_order_relaxed);
10982
10983 json_object_int_add(json_peer, "tableVersion",
10984 peer->version[afi][safi]);
10985 json_object_int_add(json_peer, "outq",
10986 outq_count);
10987 json_object_int_add(json_peer, "inq",
10988 inq_count);
10989 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
10990 use_json, json_peer);
10991
10992 json_object_int_add(json_peer, "pfxRcd",
10993 peer->pcount[afi][pfx_rcd_safi]);
10994
10995 if (paf && PAF_SUBGRP(paf))
10996 json_object_int_add(
10997 json_peer, "pfxSnt",
10998 (PAF_SUBGRP(paf))->scount);
10999 else
11000 json_object_int_add(json_peer, "pfxSnt",
11001 0);
11002
11003 /* BGP FSM state */
11004 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11005 || CHECK_FLAG(peer->bgp->flags,
11006 BGP_FLAG_SHUTDOWN))
11007 json_object_string_add(json_peer,
11008 "state",
11009 "Idle (Admin)");
11010 else if (peer->afc_recv[afi][safi])
11011 json_object_string_add(
11012 json_peer, "state",
11013 lookup_msg(bgp_status_msg,
11014 peer->status, NULL));
11015 else if (CHECK_FLAG(
11016 peer->sflags,
11017 PEER_STATUS_PREFIX_OVERFLOW))
11018 json_object_string_add(json_peer,
11019 "state",
11020 "Idle (PfxCt)");
11021 else
11022 json_object_string_add(
11023 json_peer, "state",
11024 lookup_msg(bgp_status_msg,
11025 peer->status, NULL));
11026
11027 /* BGP peer state */
11028 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
11029 || CHECK_FLAG(peer->bgp->flags,
11030 BGP_FLAG_SHUTDOWN))
11031 json_object_string_add(json_peer,
11032 "peerState",
11033 "Admin");
11034 else if (CHECK_FLAG(
11035 peer->sflags,
11036 PEER_STATUS_PREFIX_OVERFLOW))
11037 json_object_string_add(json_peer,
11038 "peerState",
11039 "PfxCt");
11040 else if (CHECK_FLAG(peer->flags,
11041 PEER_FLAG_PASSIVE))
11042 json_object_string_add(json_peer,
11043 "peerState",
11044 "Passive");
11045 else if (CHECK_FLAG(peer->sflags,
11046 PEER_STATUS_NSF_WAIT))
11047 json_object_string_add(json_peer,
11048 "peerState",
11049 "NSF passive");
11050 else if (CHECK_FLAG(
11051 peer->bgp->flags,
11052 BGP_FLAG_EBGP_REQUIRES_POLICY)
11053 && (!bgp_inbound_policy_exists(peer,
11054 filter)
11055 || !bgp_outbound_policy_exists(
11056 peer, filter)))
11057 json_object_string_add(json_peer,
11058 "peerState",
11059 "Policy");
11060 else
11061 json_object_string_add(
11062 json_peer, "peerState", "OK");
11063
11064 json_object_int_add(json_peer, "connectionsEstablished",
11065 peer->established);
11066 json_object_int_add(json_peer, "connectionsDropped",
11067 peer->dropped);
11068 if (peer->desc)
11069 json_object_string_add(
11070 json_peer, "desc", peer->desc);
11071 }
11072 /* Avoid creating empty peer dicts in JSON */
11073 if (json_peer == NULL)
11074 continue;
11075
11076 if (peer->conf_if)
11077 json_object_string_add(json_peer, "idType",
11078 "interface");
11079 else if (peer->su.sa.sa_family == AF_INET)
11080 json_object_string_add(json_peer, "idType",
11081 "ipv4");
11082 else if (peer->su.sa.sa_family == AF_INET6)
11083 json_object_string_add(json_peer, "idType",
11084 "ipv6");
11085 json_object_object_add(json_peers, peer->host,
11086 json_peer);
11087 } else {
11088 if (show_failed &&
11089 bgp_has_peer_failed(peer, afi, safi)) {
11090 bgp_show_failed_summary(vty, bgp, peer, NULL,
11091 max_neighbor_width,
11092 use_json);
11093 } else if (!show_failed) {
11094 if (show_established
11095 && bgp_has_peer_failed(peer, afi, safi))
11096 continue;
11097
11098 memset(dn_flag, '\0', sizeof(dn_flag));
11099 if (peer_dynamic_neighbor(peer)) {
11100 dn_flag[0] = '*';
11101 }
11102
11103 if (peer->hostname
11104 && CHECK_FLAG(bgp->flags,
11105 BGP_FLAG_SHOW_HOSTNAME))
11106 len = vty_out(vty, "%s%s(%s)", dn_flag,
11107 peer->hostname,
11108 peer->host);
11109 else
11110 len = vty_out(vty, "%s%s", dn_flag, peer->host);
11111
11112 /* pad the neighbor column with spaces */
11113 if (len < max_neighbor_width)
11114 vty_out(vty, "%*s", max_neighbor_width - len,
11115 " ");
11116
11117 atomic_size_t outq_count, inq_count;
11118 outq_count = atomic_load_explicit(
11119 &peer->obuf->count,
11120 memory_order_relaxed);
11121 inq_count = atomic_load_explicit(
11122 &peer->ibuf->count,
11123 memory_order_relaxed);
11124
11125 if (show_wide)
11126 vty_out(vty,
11127 "4 %10u %10u %9u %9u %8" PRIu64
11128 " %4zu %4zu %8s",
11129 peer->as,
11130 peer->change_local_as
11131 ? peer->change_local_as
11132 : peer->local_as,
11133 PEER_TOTAL_RX(peer),
11134 PEER_TOTAL_TX(peer),
11135 peer->version[afi][safi],
11136 inq_count, outq_count,
11137 peer_uptime(peer->uptime,
11138 timebuf,
11139 BGP_UPTIME_LEN, 0,
11140 NULL));
11141 else
11142 vty_out(vty, "4 %10u %9u %9u %8" PRIu64
11143 " %4zu %4zu %8s",
11144 peer->as, PEER_TOTAL_RX(peer),
11145 PEER_TOTAL_TX(peer),
11146 peer->version[afi][safi],
11147 inq_count, outq_count,
11148 peer_uptime(peer->uptime,
11149 timebuf,
11150 BGP_UPTIME_LEN, 0,
11151 NULL));
11152
11153 if (peer->status == Established) {
11154 if (peer->afc_recv[afi][safi]) {
11155 if (CHECK_FLAG(
11156 bgp->flags,
11157 BGP_FLAG_EBGP_REQUIRES_POLICY)
11158 && !bgp_inbound_policy_exists(
11159 peer, filter))
11160 vty_out(vty, " %12s",
11161 "(Policy)");
11162 else
11163 vty_out(vty,
11164 " %12u",
11165 peer->pcount
11166 [afi]
11167 [pfx_rcd_safi]);
11168 } else {
11169 vty_out(vty, " NoNeg");
11170 }
11171
11172 if (paf && PAF_SUBGRP(paf)) {
11173 if (CHECK_FLAG(
11174 bgp->flags,
11175 BGP_FLAG_EBGP_REQUIRES_POLICY)
11176 && !bgp_outbound_policy_exists(
11177 peer, filter))
11178 vty_out(vty, " %8s",
11179 "(Policy)");
11180 else
11181 vty_out(vty,
11182 " %8u",
11183 (PAF_SUBGRP(
11184 paf))
11185 ->scount);
11186 } else {
11187 vty_out(vty, " NoNeg");
11188 }
11189 } else {
11190 if (CHECK_FLAG(peer->flags,
11191 PEER_FLAG_SHUTDOWN)
11192 || CHECK_FLAG(peer->bgp->flags,
11193 BGP_FLAG_SHUTDOWN))
11194 vty_out(vty, " Idle (Admin)");
11195 else if (CHECK_FLAG(
11196 peer->sflags,
11197 PEER_STATUS_PREFIX_OVERFLOW))
11198 vty_out(vty, " Idle (PfxCt)");
11199 else
11200 vty_out(vty, " %12s",
11201 lookup_msg(bgp_status_msg,
11202 peer->status, NULL));
11203
11204 vty_out(vty, " %8u", 0);
11205 }
11206 if (peer->desc)
11207 vty_out(vty, " %s",
11208 bgp_peer_description_stripped(
11209 peer->desc,
11210 show_wide ? 64 : 20));
11211 else
11212 vty_out(vty, " N/A");
11213 vty_out(vty, "\n");
11214 }
11215
11216 }
11217 }
11218
11219 if (use_json) {
11220 json_object_object_add(json, "peers", json_peers);
11221 json_object_int_add(json, "failedPeers", failed_count);
11222 json_object_int_add(json, "totalPeers", count);
11223 json_object_int_add(json, "dynamicPeers", dn_count);
11224
11225 if (!show_failed)
11226 bgp_show_bestpath_json(bgp, json);
11227
11228 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11229 json, JSON_C_TO_STRING_PRETTY));
11230 json_object_free(json);
11231 } else {
11232 if (count)
11233 vty_out(vty, "\nTotal number of neighbors %d\n", count);
11234 else {
11235 vty_out(vty, "No %s neighbor is configured\n",
11236 get_afi_safi_str(afi, safi, false));
11237 }
11238
11239 if (dn_count) {
11240 vty_out(vty, "* - dynamic neighbor\n");
11241 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
11242 dn_count, bgp->dynamic_neighbors_limit);
11243 }
11244 }
11245
11246 return CMD_SUCCESS;
11247}
11248
11249static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
11250 int safi, uint8_t show_flags)
11251{
11252 int is_first = 1;
11253 int afi_wildcard = (afi == AFI_MAX);
11254 int safi_wildcard = (safi == SAFI_MAX);
11255 int is_wildcard = (afi_wildcard || safi_wildcard);
11256 bool nbr_output = false;
11257 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11258
11259 if (use_json && is_wildcard)
11260 vty_out(vty, "{\n");
11261 if (afi_wildcard)
11262 afi = 1; /* AFI_IP */
11263 while (afi < AFI_MAX) {
11264 if (safi_wildcard)
11265 safi = 1; /* SAFI_UNICAST */
11266 while (safi < SAFI_MAX) {
11267 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
11268 nbr_output = true;
11269
11270 if (is_wildcard) {
11271 /*
11272 * So limit output to those afi/safi
11273 * pairs that
11274 * actualy have something interesting in
11275 * them
11276 */
11277 if (use_json) {
11278 if (!is_first)
11279 vty_out(vty, ",\n");
11280 else
11281 is_first = 0;
11282
11283 vty_out(vty, "\"%s\":",
11284 get_afi_safi_str(afi,
11285 safi,
11286 true));
11287 } else {
11288 vty_out(vty, "\n%s Summary:\n",
11289 get_afi_safi_str(afi,
11290 safi,
11291 false));
11292 }
11293 }
11294 bgp_show_summary(vty, bgp, afi, safi,
11295 show_flags);
11296 }
11297 safi++;
11298 if (!safi_wildcard)
11299 safi = SAFI_MAX;
11300 }
11301 afi++;
11302 if (!afi_wildcard)
11303 afi = AFI_MAX;
11304 }
11305
11306 if (use_json && is_wildcard)
11307 vty_out(vty, "}\n");
11308 else if (!nbr_output) {
11309 if (use_json)
11310 vty_out(vty, "{}\n");
11311 else
11312 vty_out(vty, "%% No BGP neighbors found\n");
11313 }
11314}
11315
11316static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
11317 safi_t safi, uint8_t show_flags)
11318{
11319 struct listnode *node, *nnode;
11320 struct bgp *bgp;
11321 int is_first = 1;
11322 bool nbr_output = false;
11323 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11324
11325 if (use_json)
11326 vty_out(vty, "{\n");
11327
11328 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11329 nbr_output = true;
11330 if (use_json) {
11331 if (!is_first)
11332 vty_out(vty, ",\n");
11333 else
11334 is_first = 0;
11335
11336 vty_out(vty, "\"%s\":",
11337 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11338 ? VRF_DEFAULT_NAME
11339 : bgp->name);
11340 } else {
11341 vty_out(vty, "\nInstance %s:\n",
11342 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11343 ? VRF_DEFAULT_NAME
11344 : bgp->name);
11345 }
11346 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
11347 }
11348
11349 if (use_json)
11350 vty_out(vty, "}\n");
11351 else if (!nbr_output)
11352 vty_out(vty, "%% BGP instance not found\n");
11353}
11354
11355int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
11356 safi_t safi, uint8_t show_flags)
11357{
11358 struct bgp *bgp;
11359 bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11360
11361 if (name) {
11362 if (strmatch(name, "all")) {
11363 bgp_show_all_instances_summary_vty(vty, afi, safi,
11364 show_flags);
11365 return CMD_SUCCESS;
11366 } else {
11367 bgp = bgp_lookup_by_name(name);
11368
11369 if (!bgp) {
11370 if (use_json)
11371 vty_out(vty, "{}\n");
11372 else
11373 vty_out(vty,
11374 "%% BGP instance not found\n");
11375 return CMD_WARNING;
11376 }
11377
11378 bgp_show_summary_afi_safi(vty, bgp, afi, safi,
11379 show_flags);
11380 return CMD_SUCCESS;
11381 }
11382 }
11383
11384 bgp = bgp_get_default();
11385
11386 if (bgp)
11387 bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_flags);
11388 else {
11389 if (use_json)
11390 vty_out(vty, "{}\n");
11391 else
11392 vty_out(vty, "%% BGP instance not found\n");
11393 return CMD_WARNING;
11394 }
11395
11396 return CMD_SUCCESS;
11397}
11398
11399/* `show [ip] bgp summary' commands. */
11400DEFPY (show_ip_bgp_summary,
11401 show_ip_bgp_summary_cmd,
11402 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] summary [established|failed] [wide] [json$uj]",
11403 SHOW_STR
11404 IP_STR
11405 BGP_STR
11406 BGP_INSTANCE_HELP_STR
11407 BGP_AFI_HELP_STR
11408 BGP_SAFI_WITH_LABEL_HELP_STR
11409 "Display the entries for all address families\n"
11410 "Summary of BGP neighbor status\n"
11411 "Show only sessions in Established state\n"
11412 "Show only sessions not in Established state\n"
11413 "Increase table width for longer output\n"
11414 JSON_STR)
11415{
11416 char *vrf = NULL;
11417 afi_t afi = AFI_MAX;
11418 safi_t safi = SAFI_MAX;
11419 uint8_t show_flags = 0;
11420
11421 int idx = 0;
11422
11423 /* show [ip] bgp */
11424 if (!all && argv_find(argv, argc, "ip", &idx))
11425 afi = AFI_IP;
11426 /* [<vrf> VIEWVRFNAME] */
11427 if (argv_find(argv, argc, "vrf", &idx)) {
11428 vrf = argv[idx + 1]->arg;
11429 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11430 vrf = NULL;
11431 } else if (argv_find(argv, argc, "view", &idx))
11432 /* [<view> VIEWVRFNAME] */
11433 vrf = argv[idx + 1]->arg;
11434 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11435 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11436 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11437 }
11438
11439 if (argv_find(argv, argc, "failed", &idx))
11440 SET_FLAG(show_flags, BGP_SHOW_OPT_FAILED);
11441
11442 if (argv_find(argv, argc, "established", &idx))
11443 SET_FLAG(show_flags, BGP_SHOW_OPT_ESTABLISHED);
11444
11445 if (argv_find(argv, argc, "wide", &idx))
11446 SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
11447
11448 if (argv_find(argv, argc, "json", &idx))
11449 SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
11450
11451 return bgp_show_summary_vty(vty, vrf, afi, safi, show_flags);
11452}
11453
11454const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
11455{
11456 if (for_json)
11457 return get_afi_safi_json_str(afi, safi);
11458 else
11459 return get_afi_safi_vty_str(afi, safi);
11460}
11461
11462
11463static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
11464 afi_t afi, safi_t safi,
11465 uint16_t adv_smcap, uint16_t adv_rmcap,
11466 uint16_t rcv_smcap, uint16_t rcv_rmcap,
11467 bool use_json, json_object *json_pref)
11468{
11469 /* Send-Mode */
11470 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11471 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
11472 if (use_json) {
11473 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
11474 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11475 json_object_string_add(json_pref, "sendMode",
11476 "advertisedAndReceived");
11477 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11478 json_object_string_add(json_pref, "sendMode",
11479 "advertised");
11480 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11481 json_object_string_add(json_pref, "sendMode",
11482 "received");
11483 } else {
11484 vty_out(vty, " Send-mode: ");
11485 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
11486 vty_out(vty, "advertised");
11487 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
11488 vty_out(vty, "%sreceived",
11489 CHECK_FLAG(p->af_cap[afi][safi],
11490 adv_smcap)
11491 ? ", "
11492 : "");
11493 vty_out(vty, "\n");
11494 }
11495 }
11496
11497 /* Receive-Mode */
11498 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11499 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
11500 if (use_json) {
11501 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
11502 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11503 json_object_string_add(json_pref, "recvMode",
11504 "advertisedAndReceived");
11505 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11506 json_object_string_add(json_pref, "recvMode",
11507 "advertised");
11508 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11509 json_object_string_add(json_pref, "recvMode",
11510 "received");
11511 } else {
11512 vty_out(vty, " Receive-mode: ");
11513 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
11514 vty_out(vty, "advertised");
11515 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
11516 vty_out(vty, "%sreceived",
11517 CHECK_FLAG(p->af_cap[afi][safi],
11518 adv_rmcap)
11519 ? ", "
11520 : "");
11521 vty_out(vty, "\n");
11522 }
11523 }
11524}
11525
11526static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty,
11527 struct peer *p,
11528 bool use_json,
11529 json_object *json)
11530{
11531 bool rbit_status = false;
11532
11533 if (!use_json)
11534 vty_out(vty, "\n R bit: ");
11535
11536 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV)
11537 && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV))
11538 && (p->status == Established)) {
11539
11540 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_BIT_RCV))
11541 rbit_status = true;
11542 else
11543 rbit_status = false;
11544 }
11545
11546 if (rbit_status) {
11547 if (use_json)
11548 json_object_boolean_true_add(json, "rBit");
11549 else
11550 vty_out(vty, "True\n");
11551 } else {
11552 if (use_json)
11553 json_object_boolean_false_add(json, "rBit");
11554 else
11555 vty_out(vty, "False\n");
11556 }
11557}
11558
11559static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty,
11560 struct peer *peer,
11561 bool use_json,
11562 json_object *json)
11563{
11564 const char *mode = "NotApplicable";
11565
11566 if (!use_json)
11567 vty_out(vty, "\n Remote GR Mode: ");
11568
11569 if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11570 && (peer->status == Established)) {
11571
11572 if ((peer->nsf_af_count == 0)
11573 && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11574
11575 mode = "Disable";
11576
11577 } else if (peer->nsf_af_count == 0
11578 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11579
11580 mode = "Helper";
11581
11582 } else if (peer->nsf_af_count != 0
11583 && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) {
11584
11585 mode = "Restart";
11586 }
11587 }
11588
11589 if (use_json) {
11590 json_object_string_add(json, "remoteGrMode", mode);
11591 } else
11592 vty_out(vty, mode, "\n");
11593}
11594
11595static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty,
11596 struct peer *p,
11597 bool use_json,
11598 json_object *json)
11599{
11600 const char *mode = "Invalid";
11601
11602 if (!use_json)
11603 vty_out(vty, " Local GR Mode: ");
11604
11605 if (bgp_peer_gr_mode_get(p) == PEER_HELPER)
11606 mode = "Helper";
11607 else if (bgp_peer_gr_mode_get(p) == PEER_GR)
11608 mode = "Restart";
11609 else if (bgp_peer_gr_mode_get(p) == PEER_DISABLE)
11610 mode = "Disable";
11611 else if (bgp_peer_gr_mode_get(p) == PEER_GLOBAL_INHERIT) {
11612 if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_HELPER)
11613 mode = "Helper*";
11614 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_GR)
11615 mode = "Restart*";
11616 else if (bgp_global_gr_mode_get(p->bgp) == GLOBAL_DISABLE)
11617 mode = "Disable*";
11618 else
11619 mode = "Invalid*";
11620 }
11621
11622 if (use_json) {
11623 json_object_string_add(json, "localGrMode", mode);
11624 } else {
11625 vty_out(vty, mode, "\n");
11626 }
11627}
11628
11629static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
11630 struct vty *vty, struct peer *peer, bool use_json, json_object *json)
11631{
11632 afi_t afi;
11633 safi_t safi;
11634 json_object *json_afi_safi = NULL;
11635 json_object *json_timer = NULL;
11636 json_object *json_endofrib_status = NULL;
11637 bool eor_flag = false;
11638
11639 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11640 for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
11641 if (!peer->afc[afi][safi])
11642 continue;
11643
11644 if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
11645 || !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV))
11646 continue;
11647
11648 if (use_json) {
11649 json_afi_safi = json_object_new_object();
11650 json_endofrib_status = json_object_new_object();
11651 json_timer = json_object_new_object();
11652 }
11653
11654 if (peer->eor_stime[afi][safi]
11655 >= peer->pkt_stime[afi][safi])
11656 eor_flag = true;
11657 else
11658 eor_flag = false;
11659
11660 if (!use_json) {
11661 vty_out(vty, " %s:\n",
11662 get_afi_safi_str(afi, safi, false));
11663
11664 vty_out(vty, " F bit: ");
11665 }
11666
11667 if (peer->nsf[afi][safi]
11668 && CHECK_FLAG(peer->af_cap[afi][safi],
11669 PEER_CAP_RESTART_AF_PRESERVE_RCV)) {
11670
11671 if (use_json) {
11672 json_object_boolean_true_add(
11673 json_afi_safi, "fBit");
11674 } else
11675 vty_out(vty, "True\n");
11676 } else {
11677 if (use_json)
11678 json_object_boolean_false_add(
11679 json_afi_safi, "fBit");
11680 else
11681 vty_out(vty, "False\n");
11682 }
11683
11684 if (!use_json)
11685 vty_out(vty, " End-of-RIB sent: ");
11686
11687 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11688 PEER_STATUS_EOR_SEND)) {
11689 if (use_json) {
11690 json_object_boolean_true_add(
11691 json_endofrib_status,
11692 "endOfRibSend");
11693
11694 PRINT_EOR_JSON(eor_flag);
11695 } else {
11696 vty_out(vty, "Yes\n");
11697 vty_out(vty,
11698 " End-of-RIB sent after update: ");
11699
11700 PRINT_EOR(eor_flag);
11701 }
11702 } else {
11703 if (use_json) {
11704 json_object_boolean_false_add(
11705 json_endofrib_status,
11706 "endOfRibSend");
11707 json_object_boolean_false_add(
11708 json_endofrib_status,
11709 "endOfRibSentAfterUpdate");
11710 } else {
11711 vty_out(vty, "No\n");
11712 vty_out(vty,
11713 " End-of-RIB sent after update: ");
11714 vty_out(vty, "No\n");
11715 }
11716 }
11717
11718 if (!use_json)
11719 vty_out(vty, " End-of-RIB received: ");
11720
11721 if (CHECK_FLAG(peer->af_sflags[afi][safi],
11722 PEER_STATUS_EOR_RECEIVED)) {
11723 if (use_json)
11724 json_object_boolean_true_add(
11725 json_endofrib_status,
11726 "endOfRibRecv");
11727 else
11728 vty_out(vty, "Yes\n");
11729 } else {
11730 if (use_json)
11731 json_object_boolean_false_add(
11732 json_endofrib_status,
11733 "endOfRibRecv");
11734 else
11735 vty_out(vty, "No\n");
11736 }
11737
11738 if (use_json) {
11739 json_object_int_add(json_timer,
11740 "stalePathTimer",
11741 peer->bgp->stalepath_time);
11742
11743 if (peer->t_gr_stale != NULL) {
11744 json_object_int_add(
11745 json_timer,
11746 "stalePathTimerRemaining",
11747 thread_timer_remain_second(
11748 peer->t_gr_stale));
11749 }
11750
11751 /* Display Configured Selection
11752 * Deferral only when when
11753 * Gr mode is enabled.
11754 */
11755 if (CHECK_FLAG(peer->flags,
11756 PEER_FLAG_GRACEFUL_RESTART)) {
11757 json_object_int_add(
11758 json_timer,
11759 "selectionDeferralTimer",
11760 peer->bgp->stalepath_time);
11761 }
11762
11763 if (peer->bgp->gr_info[afi][safi]
11764 .t_select_deferral
11765 != NULL) {
11766
11767 json_object_int_add(
11768 json_timer,
11769 "selectionDeferralTimerRemaining",
11770 thread_timer_remain_second(
11771 peer->bgp
11772 ->gr_info[afi]
11773 [safi]
11774 .t_select_deferral));
11775 }
11776 } else {
11777 vty_out(vty, " Timers:\n");
11778 vty_out(vty,
11779 " Configured Stale Path Time(sec): %u\n",
11780 peer->bgp->stalepath_time);
11781
11782 if (peer->t_gr_stale != NULL)
11783 vty_out(vty,
11784 " Stale Path Remaining(sec): %ld\n",
11785 thread_timer_remain_second(
11786 peer->t_gr_stale));
11787 /* Display Configured Selection
11788 * Deferral only when when
11789 * Gr mode is enabled.
11790 */
11791 if (CHECK_FLAG(peer->flags,
11792 PEER_FLAG_GRACEFUL_RESTART))
11793 vty_out(vty,
11794 " Configured Selection Deferral Time(sec): %u\n",
11795 peer->bgp->select_defer_time);
11796
11797 if (peer->bgp->gr_info[afi][safi]
11798 .t_select_deferral
11799 != NULL)
11800 vty_out(vty,
11801 " Selection Deferral Time Remaining(sec): %ld\n",
11802 thread_timer_remain_second(
11803 peer->bgp
11804 ->gr_info[afi]
11805 [safi]
11806 .t_select_deferral));
11807 }
11808 if (use_json) {
11809 json_object_object_add(json_afi_safi,
11810 "endOfRibStatus",
11811 json_endofrib_status);
11812 json_object_object_add(json_afi_safi, "timers",
11813 json_timer);
11814 json_object_object_add(
11815 json, get_afi_safi_str(afi, safi, true),
11816 json_afi_safi);
11817 }
11818 }
11819 }
11820}
11821
11822static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
11823 struct peer *p,
11824 bool use_json,
11825 json_object *json)
11826{
11827 if (use_json) {
11828 json_object *json_timer = NULL;
11829
11830 json_timer = json_object_new_object();
11831
11832 json_object_int_add(json_timer, "configuredRestartTimer",
11833 p->bgp->restart_time);
11834
11835 json_object_int_add(json_timer, "receivedRestartTimer",
11836 p->v_gr_restart);
11837
11838 if (p->t_gr_restart != NULL)
11839 json_object_int_add(
11840 json_timer, "restartTimerRemaining",
11841 thread_timer_remain_second(p->t_gr_restart));
11842
11843 json_object_object_add(json, "timers", json_timer);
11844 } else {
11845
11846 vty_out(vty, " Timers:\n");
11847 vty_out(vty, " Configured Restart Time(sec): %u\n",
11848 p->bgp->restart_time);
11849
11850 vty_out(vty, " Received Restart Time(sec): %u\n",
11851 p->v_gr_restart);
11852 if (p->t_gr_restart != NULL)
11853 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11854 thread_timer_remain_second(p->t_gr_restart));
11855 if (p->t_gr_restart != NULL) {
11856 vty_out(vty, " Restart Time Remaining(sec): %ld\n",
11857 thread_timer_remain_second(p->t_gr_restart));
11858 }
11859 }
11860}
11861
11862static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
11863 bool use_json, json_object *json)
11864{
11865 char buf[SU_ADDRSTRLEN] = {0};
11866 char dn_flag[2] = {0};
11867 /* '*' + v6 address of neighbor */
11868 char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
11869
11870 if (!p->conf_if && peer_dynamic_neighbor(p))
11871 dn_flag[0] = '*';
11872
11873 if (p->conf_if) {
11874 if (use_json)
11875 json_object_string_add(
11876 json, "neighborAddr",
11877 BGP_PEER_SU_UNSPEC(p)
11878 ? "none"
11879 : sockunion2str(&p->su, buf,
11880 SU_ADDRSTRLEN));
11881 else
11882 vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
11883 BGP_PEER_SU_UNSPEC(p)
11884 ? "none"
11885 : sockunion2str(&p->su, buf,
11886 SU_ADDRSTRLEN));
11887 } else {
11888 snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
11889 p->host);
11890
11891 if (use_json)
11892 json_object_string_add(json, "neighborAddr",
11893 neighborAddr);
11894 else
11895 vty_out(vty, "BGP neighbor is %s\n", neighborAddr);
11896 }
11897
11898 /* more gr info in new format */
11899 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, json);
11900}
11901
11902static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
11903 safi_t safi, bool use_json,
11904 json_object *json_neigh)
11905{
11906 struct bgp_filter *filter;
11907 struct peer_af *paf;
11908 char orf_pfx_name[BUFSIZ];
11909 int orf_pfx_count;
11910 json_object *json_af = NULL;
11911 json_object *json_prefA = NULL;
11912 json_object *json_prefB = NULL;
11913 json_object *json_addr = NULL;
11914 json_object *json_advmap = NULL;
11915
11916 if (use_json) {
11917 json_addr = json_object_new_object();
11918 json_af = json_object_new_object();
11919 filter = &p->filter[afi][safi];
11920
11921 if (peer_group_active(p))
11922 json_object_string_add(json_addr, "peerGroupMember",
11923 p->group->name);
11924
11925 paf = peer_af_find(p, afi, safi);
11926 if (paf && PAF_SUBGRP(paf)) {
11927 json_object_int_add(json_addr, "updateGroupId",
11928 PAF_UPDGRP(paf)->id);
11929 json_object_int_add(json_addr, "subGroupId",
11930 PAF_SUBGRP(paf)->id);
11931 json_object_int_add(json_addr, "packetQueueLength",
11932 bpacket_queue_virtual_length(paf));
11933 }
11934
11935 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11936 || CHECK_FLAG(p->af_cap[afi][safi],
11937 PEER_CAP_ORF_PREFIX_SM_RCV)
11938 || CHECK_FLAG(p->af_cap[afi][safi],
11939 PEER_CAP_ORF_PREFIX_RM_ADV)
11940 || CHECK_FLAG(p->af_cap[afi][safi],
11941 PEER_CAP_ORF_PREFIX_RM_RCV)) {
11942 json_object_int_add(json_af, "orfType",
11943 ORF_TYPE_PREFIX);
11944 json_prefA = json_object_new_object();
11945 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
11946 PEER_CAP_ORF_PREFIX_SM_ADV,
11947 PEER_CAP_ORF_PREFIX_RM_ADV,
11948 PEER_CAP_ORF_PREFIX_SM_RCV,
11949 PEER_CAP_ORF_PREFIX_RM_RCV,
11950 use_json, json_prefA);
11951 json_object_object_add(json_af, "orfPrefixList",
11952 json_prefA);
11953 }
11954
11955 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11956 || CHECK_FLAG(p->af_cap[afi][safi],
11957 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11958 || CHECK_FLAG(p->af_cap[afi][safi],
11959 PEER_CAP_ORF_PREFIX_RM_ADV)
11960 || CHECK_FLAG(p->af_cap[afi][safi],
11961 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
11962 json_object_int_add(json_af, "orfOldType",
11963 ORF_TYPE_PREFIX_OLD);
11964 json_prefB = json_object_new_object();
11965 bgp_show_peer_afi_orf_cap(
11966 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
11967 PEER_CAP_ORF_PREFIX_RM_ADV,
11968 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
11969 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
11970 json_prefB);
11971 json_object_object_add(json_af, "orfOldPrefixList",
11972 json_prefB);
11973 }
11974
11975 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
11976 || CHECK_FLAG(p->af_cap[afi][safi],
11977 PEER_CAP_ORF_PREFIX_SM_RCV)
11978 || CHECK_FLAG(p->af_cap[afi][safi],
11979 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
11980 || CHECK_FLAG(p->af_cap[afi][safi],
11981 PEER_CAP_ORF_PREFIX_RM_ADV)
11982 || CHECK_FLAG(p->af_cap[afi][safi],
11983 PEER_CAP_ORF_PREFIX_RM_RCV)
11984 || CHECK_FLAG(p->af_cap[afi][safi],
11985 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
11986 json_object_object_add(json_addr, "afDependentCap",
11987 json_af);
11988 else
11989 json_object_free(json_af);
11990
11991 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
11992 p->host, afi, safi);
11993 orf_pfx_count = prefix_bgp_show_prefix_list(
11994 NULL, afi, orf_pfx_name, use_json);
11995
11996 if (CHECK_FLAG(p->af_sflags[afi][safi],
11997 PEER_STATUS_ORF_PREFIX_SEND)
11998 || orf_pfx_count) {
11999 if (CHECK_FLAG(p->af_sflags[afi][safi],
12000 PEER_STATUS_ORF_PREFIX_SEND))
12001 json_object_boolean_true_add(json_neigh,
12002 "orfSent");
12003 if (orf_pfx_count)
12004 json_object_int_add(json_addr, "orfRecvCounter",
12005 orf_pfx_count);
12006 }
12007 if (CHECK_FLAG(p->af_sflags[afi][safi],
12008 PEER_STATUS_ORF_WAIT_REFRESH))
12009 json_object_string_add(
12010 json_addr, "orfFirstUpdate",
12011 "deferredUntilORFOrRouteRefreshRecvd");
12012
12013 if (CHECK_FLAG(p->af_flags[afi][safi],
12014 PEER_FLAG_REFLECTOR_CLIENT))
12015 json_object_boolean_true_add(json_addr,
12016 "routeReflectorClient");
12017 if (CHECK_FLAG(p->af_flags[afi][safi],
12018 PEER_FLAG_RSERVER_CLIENT))
12019 json_object_boolean_true_add(json_addr,
12020 "routeServerClient");
12021 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12022 json_object_boolean_true_add(json_addr,
12023 "inboundSoftConfigPermit");
12024
12025 if (CHECK_FLAG(p->af_flags[afi][safi],
12026 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12027 json_object_boolean_true_add(
12028 json_addr,
12029 "privateAsNumsAllReplacedInUpdatesToNbr");
12030 else if (CHECK_FLAG(p->af_flags[afi][safi],
12031 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12032 json_object_boolean_true_add(
12033 json_addr,
12034 "privateAsNumsReplacedInUpdatesToNbr");
12035 else if (CHECK_FLAG(p->af_flags[afi][safi],
12036 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12037 json_object_boolean_true_add(
12038 json_addr,
12039 "privateAsNumsAllRemovedInUpdatesToNbr");
12040 else if (CHECK_FLAG(p->af_flags[afi][safi],
12041 PEER_FLAG_REMOVE_PRIVATE_AS))
12042 json_object_boolean_true_add(
12043 json_addr,
12044 "privateAsNumsRemovedInUpdatesToNbr");
12045
12046 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12047 json_object_boolean_true_add(
12048 json_addr,
12049 bgp_addpath_names(p->addpath_type[afi][safi])
12050 ->type_json_name);
12051
12052 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12053 json_object_string_add(json_addr,
12054 "overrideASNsInOutboundUpdates",
12055 "ifAspathEqualRemoteAs");
12056
12057 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12058 || CHECK_FLAG(p->af_flags[afi][safi],
12059 PEER_FLAG_FORCE_NEXTHOP_SELF))
12060 json_object_boolean_true_add(json_addr,
12061 "routerAlwaysNextHop");
12062 if (CHECK_FLAG(p->af_flags[afi][safi],
12063 PEER_FLAG_AS_PATH_UNCHANGED))
12064 json_object_boolean_true_add(
12065 json_addr, "unchangedAsPathPropogatedToNbr");
12066 if (CHECK_FLAG(p->af_flags[afi][safi],
12067 PEER_FLAG_NEXTHOP_UNCHANGED))
12068 json_object_boolean_true_add(
12069 json_addr, "unchangedNextHopPropogatedToNbr");
12070 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12071 json_object_boolean_true_add(
12072 json_addr, "unchangedMedPropogatedToNbr");
12073 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12074 || CHECK_FLAG(p->af_flags[afi][safi],
12075 PEER_FLAG_SEND_EXT_COMMUNITY)) {
12076 if (CHECK_FLAG(p->af_flags[afi][safi],
12077 PEER_FLAG_SEND_COMMUNITY)
12078 && CHECK_FLAG(p->af_flags[afi][safi],
12079 PEER_FLAG_SEND_EXT_COMMUNITY))
12080 json_object_string_add(json_addr,
12081 "commAttriSentToNbr",
12082 "extendedAndStandard");
12083 else if (CHECK_FLAG(p->af_flags[afi][safi],
12084 PEER_FLAG_SEND_EXT_COMMUNITY))
12085 json_object_string_add(json_addr,
12086 "commAttriSentToNbr",
12087 "extended");
12088 else
12089 json_object_string_add(json_addr,
12090 "commAttriSentToNbr",
12091 "standard");
12092 }
12093 if (CHECK_FLAG(p->af_flags[afi][safi],
12094 PEER_FLAG_DEFAULT_ORIGINATE)) {
12095 if (p->default_rmap[afi][safi].name)
12096 json_object_string_add(
12097 json_addr, "defaultRouteMap",
12098 p->default_rmap[afi][safi].name);
12099
12100 if (paf && PAF_SUBGRP(paf)
12101 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12102 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12103 json_object_boolean_true_add(json_addr,
12104 "defaultSent");
12105 else
12106 json_object_boolean_true_add(json_addr,
12107 "defaultNotSent");
12108 }
12109
12110 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12111 if (is_evpn_enabled())
12112 json_object_boolean_true_add(
12113 json_addr, "advertiseAllVnis");
12114 }
12115
12116 if (filter->plist[FILTER_IN].name
12117 || filter->dlist[FILTER_IN].name
12118 || filter->aslist[FILTER_IN].name
12119 || filter->map[RMAP_IN].name)
12120 json_object_boolean_true_add(json_addr,
12121 "inboundPathPolicyConfig");
12122 if (filter->plist[FILTER_OUT].name
12123 || filter->dlist[FILTER_OUT].name
12124 || filter->aslist[FILTER_OUT].name
12125 || filter->map[RMAP_OUT].name || filter->usmap.name)
12126 json_object_boolean_true_add(
12127 json_addr, "outboundPathPolicyConfig");
12128
12129 /* prefix-list */
12130 if (filter->plist[FILTER_IN].name)
12131 json_object_string_add(json_addr,
12132 "incomingUpdatePrefixFilterList",
12133 filter->plist[FILTER_IN].name);
12134 if (filter->plist[FILTER_OUT].name)
12135 json_object_string_add(json_addr,
12136 "outgoingUpdatePrefixFilterList",
12137 filter->plist[FILTER_OUT].name);
12138
12139 /* distribute-list */
12140 if (filter->dlist[FILTER_IN].name)
12141 json_object_string_add(
12142 json_addr, "incomingUpdateNetworkFilterList",
12143 filter->dlist[FILTER_IN].name);
12144 if (filter->dlist[FILTER_OUT].name)
12145 json_object_string_add(
12146 json_addr, "outgoingUpdateNetworkFilterList",
12147 filter->dlist[FILTER_OUT].name);
12148
12149 /* filter-list. */
12150 if (filter->aslist[FILTER_IN].name)
12151 json_object_string_add(json_addr,
12152 "incomingUpdateAsPathFilterList",
12153 filter->aslist[FILTER_IN].name);
12154 if (filter->aslist[FILTER_OUT].name)
12155 json_object_string_add(json_addr,
12156 "outgoingUpdateAsPathFilterList",
12157 filter->aslist[FILTER_OUT].name);
12158
12159 /* route-map. */
12160 if (filter->map[RMAP_IN].name)
12161 json_object_string_add(
12162 json_addr, "routeMapForIncomingAdvertisements",
12163 filter->map[RMAP_IN].name);
12164 if (filter->map[RMAP_OUT].name)
12165 json_object_string_add(
12166 json_addr, "routeMapForOutgoingAdvertisements",
12167 filter->map[RMAP_OUT].name);
12168
12169 /* ebgp-requires-policy (inbound) */
12170 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12171 && !bgp_inbound_policy_exists(p, filter))
12172 json_object_string_add(
12173 json_addr, "inboundEbgpRequiresPolicy",
12174 "Inbound updates discarded due to missing policy");
12175
12176 /* ebgp-requires-policy (outbound) */
12177 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12178 && (!bgp_outbound_policy_exists(p, filter)))
12179 json_object_string_add(
12180 json_addr, "outboundEbgpRequiresPolicy",
12181 "Outbound updates discarded due to missing policy");
12182
12183 /* unsuppress-map */
12184 if (filter->usmap.name)
12185 json_object_string_add(json_addr,
12186 "selectiveUnsuppressRouteMap",
12187 filter->usmap.name);
12188
12189 /* advertise-map */
12190 if (filter->advmap.aname) {
12191 json_advmap = json_object_new_object();
12192 json_object_string_add(json_advmap, "condition",
12193 filter->advmap.condition
12194 ? "EXIST"
12195 : "NON_EXIST");
12196 json_object_string_add(json_advmap, "conditionMap",
12197 filter->advmap.cname);
12198 json_object_string_add(json_advmap, "advertiseMap",
12199 filter->advmap.aname);
12200 json_object_string_add(json_advmap, "advertiseStatus",
12201 filter->advmap.update_type
12202 == ADVERTISE
12203 ? "Advertise"
12204 : "Withdraw");
12205 json_object_object_add(json_addr, "advertiseMap",
12206 json_advmap);
12207 }
12208
12209 /* Receive prefix count */
12210 json_object_int_add(json_addr, "acceptedPrefixCounter",
12211 p->pcount[afi][safi]);
12212 if (paf && PAF_SUBGRP(paf))
12213 json_object_int_add(json_addr, "sentPrefixCounter",
12214 (PAF_SUBGRP(paf))->scount);
12215
12216 /* Maximum prefix */
12217 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
12218 json_object_int_add(json_addr, "prefixOutAllowedMax",
12219 p->pmax_out[afi][safi]);
12220
12221 /* Maximum prefix */
12222 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12223 json_object_int_add(json_addr, "prefixAllowedMax",
12224 p->pmax[afi][safi]);
12225 if (CHECK_FLAG(p->af_flags[afi][safi],
12226 PEER_FLAG_MAX_PREFIX_WARNING))
12227 json_object_boolean_true_add(
12228 json_addr, "prefixAllowedMaxWarning");
12229 json_object_int_add(json_addr,
12230 "prefixAllowedWarningThresh",
12231 p->pmax_threshold[afi][safi]);
12232 if (p->pmax_restart[afi][safi])
12233 json_object_int_add(
12234 json_addr,
12235 "prefixAllowedRestartIntervalMsecs",
12236 p->pmax_restart[afi][safi] * 60000);
12237 }
12238 json_object_object_add(json_neigh,
12239 get_afi_safi_str(afi, safi, true),
12240 json_addr);
12241
12242 } else {
12243 filter = &p->filter[afi][safi];
12244
12245 vty_out(vty, " For address family: %s\n",
12246 get_afi_safi_str(afi, safi, false));
12247
12248 if (peer_group_active(p))
12249 vty_out(vty, " %s peer-group member\n",
12250 p->group->name);
12251
12252 paf = peer_af_find(p, afi, safi);
12253 if (paf && PAF_SUBGRP(paf)) {
12254 vty_out(vty, " Update group %" PRIu64", subgroup %" PRIu64 "\n",
12255 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
12256 vty_out(vty, " Packet Queue length %d\n",
12257 bpacket_queue_virtual_length(paf));
12258 } else {
12259 vty_out(vty, " Not part of any update group\n");
12260 }
12261 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12262 || CHECK_FLAG(p->af_cap[afi][safi],
12263 PEER_CAP_ORF_PREFIX_SM_RCV)
12264 || CHECK_FLAG(p->af_cap[afi][safi],
12265 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12266 || CHECK_FLAG(p->af_cap[afi][safi],
12267 PEER_CAP_ORF_PREFIX_RM_ADV)
12268 || CHECK_FLAG(p->af_cap[afi][safi],
12269 PEER_CAP_ORF_PREFIX_RM_RCV)
12270 || CHECK_FLAG(p->af_cap[afi][safi],
12271 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
12272 vty_out(vty, " AF-dependant capabilities:\n");
12273
12274 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12275 || CHECK_FLAG(p->af_cap[afi][safi],
12276 PEER_CAP_ORF_PREFIX_SM_RCV)
12277 || CHECK_FLAG(p->af_cap[afi][safi],
12278 PEER_CAP_ORF_PREFIX_RM_ADV)
12279 || CHECK_FLAG(p->af_cap[afi][safi],
12280 PEER_CAP_ORF_PREFIX_RM_RCV)) {
12281 vty_out(vty,
12282 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12283 ORF_TYPE_PREFIX);
12284 bgp_show_peer_afi_orf_cap(
12285 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12286 PEER_CAP_ORF_PREFIX_RM_ADV,
12287 PEER_CAP_ORF_PREFIX_SM_RCV,
12288 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
12289 }
12290 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
12291 || CHECK_FLAG(p->af_cap[afi][safi],
12292 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
12293 || CHECK_FLAG(p->af_cap[afi][safi],
12294 PEER_CAP_ORF_PREFIX_RM_ADV)
12295 || CHECK_FLAG(p->af_cap[afi][safi],
12296 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
12297 vty_out(vty,
12298 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
12299 ORF_TYPE_PREFIX_OLD);
12300 bgp_show_peer_afi_orf_cap(
12301 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
12302 PEER_CAP_ORF_PREFIX_RM_ADV,
12303 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
12304 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
12305 }
12306
12307 snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d",
12308 p->host, afi, safi);
12309 orf_pfx_count = prefix_bgp_show_prefix_list(
12310 NULL, afi, orf_pfx_name, use_json);
12311
12312 if (CHECK_FLAG(p->af_sflags[afi][safi],
12313 PEER_STATUS_ORF_PREFIX_SEND)
12314 || orf_pfx_count) {
12315 vty_out(vty, " Outbound Route Filter (ORF):");
12316 if (CHECK_FLAG(p->af_sflags[afi][safi],
12317 PEER_STATUS_ORF_PREFIX_SEND))
12318 vty_out(vty, " sent;");
12319 if (orf_pfx_count)
12320 vty_out(vty, " received (%d entries)",
12321 orf_pfx_count);
12322 vty_out(vty, "\n");
12323 }
12324 if (CHECK_FLAG(p->af_sflags[afi][safi],
12325 PEER_STATUS_ORF_WAIT_REFRESH))
12326 vty_out(vty,
12327 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
12328
12329 if (CHECK_FLAG(p->af_flags[afi][safi],
12330 PEER_FLAG_REFLECTOR_CLIENT))
12331 vty_out(vty, " Route-Reflector Client\n");
12332 if (CHECK_FLAG(p->af_flags[afi][safi],
12333 PEER_FLAG_RSERVER_CLIENT))
12334 vty_out(vty, " Route-Server Client\n");
12335 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12336 vty_out(vty,
12337 " Inbound soft reconfiguration allowed\n");
12338
12339 if (CHECK_FLAG(p->af_flags[afi][safi],
12340 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
12341 vty_out(vty,
12342 " Private AS numbers (all) replaced in updates to this neighbor\n");
12343 else if (CHECK_FLAG(p->af_flags[afi][safi],
12344 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
12345 vty_out(vty,
12346 " Private AS numbers replaced in updates to this neighbor\n");
12347 else if (CHECK_FLAG(p->af_flags[afi][safi],
12348 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
12349 vty_out(vty,
12350 " Private AS numbers (all) removed in updates to this neighbor\n");
12351 else if (CHECK_FLAG(p->af_flags[afi][safi],
12352 PEER_FLAG_REMOVE_PRIVATE_AS))
12353 vty_out(vty,
12354 " Private AS numbers removed in updates to this neighbor\n");
12355
12356 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
12357 vty_out(vty, " %s\n",
12358 bgp_addpath_names(p->addpath_type[afi][safi])
12359 ->human_description);
12360
12361 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
12362 vty_out(vty,
12363 " Override ASNs in outbound updates if aspath equals remote-as\n");
12364
12365 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
12366 || CHECK_FLAG(p->af_flags[afi][safi],
12367 PEER_FLAG_FORCE_NEXTHOP_SELF))
12368 vty_out(vty, " NEXT_HOP is always this router\n");
12369 if (CHECK_FLAG(p->af_flags[afi][safi],
12370 PEER_FLAG_AS_PATH_UNCHANGED))
12371 vty_out(vty,
12372 " AS_PATH is propagated unchanged to this neighbor\n");
12373 if (CHECK_FLAG(p->af_flags[afi][safi],
12374 PEER_FLAG_NEXTHOP_UNCHANGED))
12375 vty_out(vty,
12376 " NEXT_HOP is propagated unchanged to this neighbor\n");
12377 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
12378 vty_out(vty,
12379 " MED is propagated unchanged to this neighbor\n");
12380 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
12381 || CHECK_FLAG(p->af_flags[afi][safi],
12382 PEER_FLAG_SEND_EXT_COMMUNITY)
12383 || CHECK_FLAG(p->af_flags[afi][safi],
12384 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
12385 vty_out(vty,
12386 " Community attribute sent to this neighbor");
12387 if (CHECK_FLAG(p->af_flags[afi][safi],
12388 PEER_FLAG_SEND_COMMUNITY)
12389 && CHECK_FLAG(p->af_flags[afi][safi],
12390 PEER_FLAG_SEND_EXT_COMMUNITY)
12391 && CHECK_FLAG(p->af_flags[afi][safi],
12392 PEER_FLAG_SEND_LARGE_COMMUNITY))
12393 vty_out(vty, "(all)\n");
12394 else if (CHECK_FLAG(p->af_flags[afi][safi],
12395 PEER_FLAG_SEND_LARGE_COMMUNITY))
12396 vty_out(vty, "(large)\n");
12397 else if (CHECK_FLAG(p->af_flags[afi][safi],
12398 PEER_FLAG_SEND_EXT_COMMUNITY))
12399 vty_out(vty, "(extended)\n");
12400 else
12401 vty_out(vty, "(standard)\n");
12402 }
12403 if (CHECK_FLAG(p->af_flags[afi][safi],
12404 PEER_FLAG_DEFAULT_ORIGINATE)) {
12405 vty_out(vty, " Default information originate,");
12406
12407 if (p->default_rmap[afi][safi].name)
12408 vty_out(vty, " default route-map %s%s,",
12409 p->default_rmap[afi][safi].map ? "*"
12410 : "",
12411 p->default_rmap[afi][safi].name);
12412 if (paf && PAF_SUBGRP(paf)
12413 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
12414 SUBGRP_STATUS_DEFAULT_ORIGINATE))
12415 vty_out(vty, " default sent\n");
12416 else
12417 vty_out(vty, " default not sent\n");
12418 }
12419
12420 /* advertise-vni-all */
12421 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
12422 if (is_evpn_enabled())
12423 vty_out(vty, " advertise-all-vni\n");
12424 }
12425
12426 if (filter->plist[FILTER_IN].name
12427 || filter->dlist[FILTER_IN].name
12428 || filter->aslist[FILTER_IN].name
12429 || filter->map[RMAP_IN].name)
12430 vty_out(vty, " Inbound path policy configured\n");
12431 if (filter->plist[FILTER_OUT].name
12432 || filter->dlist[FILTER_OUT].name
12433 || filter->aslist[FILTER_OUT].name
12434 || filter->map[RMAP_OUT].name || filter->usmap.name)
12435 vty_out(vty, " Outbound path policy configured\n");
12436
12437 /* prefix-list */
12438 if (filter->plist[FILTER_IN].name)
12439 vty_out(vty,
12440 " Incoming update prefix filter list is %s%s\n",
12441 filter->plist[FILTER_IN].plist ? "*" : "",
12442 filter->plist[FILTER_IN].name);
12443 if (filter->plist[FILTER_OUT].name)
12444 vty_out(vty,
12445 " Outgoing update prefix filter list is %s%s\n",
12446 filter->plist[FILTER_OUT].plist ? "*" : "",
12447 filter->plist[FILTER_OUT].name);
12448
12449 /* distribute-list */
12450 if (filter->dlist[FILTER_IN].name)
12451 vty_out(vty,
12452 " Incoming update network filter list is %s%s\n",
12453 filter->dlist[FILTER_IN].alist ? "*" : "",
12454 filter->dlist[FILTER_IN].name);
12455 if (filter->dlist[FILTER_OUT].name)
12456 vty_out(vty,
12457 " Outgoing update network filter list is %s%s\n",
12458 filter->dlist[FILTER_OUT].alist ? "*" : "",
12459 filter->dlist[FILTER_OUT].name);
12460
12461 /* filter-list. */
12462 if (filter->aslist[FILTER_IN].name)
12463 vty_out(vty,
12464 " Incoming update AS path filter list is %s%s\n",
12465 filter->aslist[FILTER_IN].aslist ? "*" : "",
12466 filter->aslist[FILTER_IN].name);
12467 if (filter->aslist[FILTER_OUT].name)
12468 vty_out(vty,
12469 " Outgoing update AS path filter list is %s%s\n",
12470 filter->aslist[FILTER_OUT].aslist ? "*" : "",
12471 filter->aslist[FILTER_OUT].name);
12472
12473 /* route-map. */
12474 if (filter->map[RMAP_IN].name)
12475 vty_out(vty,
12476 " Route map for incoming advertisements is %s%s\n",
12477 filter->map[RMAP_IN].map ? "*" : "",
12478 filter->map[RMAP_IN].name);
12479 if (filter->map[RMAP_OUT].name)
12480 vty_out(vty,
12481 " Route map for outgoing advertisements is %s%s\n",
12482 filter->map[RMAP_OUT].map ? "*" : "",
12483 filter->map[RMAP_OUT].name);
12484
12485 /* ebgp-requires-policy (inbound) */
12486 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12487 && !bgp_inbound_policy_exists(p, filter))
12488 vty_out(vty,
12489 " Inbound updates discarded due to missing policy\n");
12490
12491 /* ebgp-requires-policy (outbound) */
12492 if (CHECK_FLAG(p->bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
12493 && !bgp_outbound_policy_exists(p, filter))
12494 vty_out(vty,
12495 " Outbound updates discarded due to missing policy\n");
12496
12497 /* unsuppress-map */
12498 if (filter->usmap.name)
12499 vty_out(vty,
12500 " Route map for selective unsuppress is %s%s\n",
12501 filter->usmap.map ? "*" : "",
12502 filter->usmap.name);
12503
12504 /* advertise-map */
12505 if (filter->advmap.aname && filter->advmap.cname)
12506 vty_out(vty,
12507 " Condition %s, Condition-map %s%s, Advertise-map %s%s, status: %s\n",
12508 filter->advmap.condition ? "EXIST"
12509 : "NON_EXIST",
12510 filter->advmap.cmap ? "*" : "",
12511 filter->advmap.cname,
12512 filter->advmap.amap ? "*" : "",
12513 filter->advmap.aname,
12514 filter->advmap.update_type == ADVERTISE
12515 ? "Advertise"
12516 : "Withdraw");
12517
12518 /* Receive prefix count */
12519 vty_out(vty, " %u accepted prefixes\n",
12520 p->pcount[afi][safi]);
12521
12522 /* maximum-prefix-out */
12523 if (CHECK_FLAG(p->af_flags[afi][safi],
12524 PEER_FLAG_MAX_PREFIX_OUT))
12525 vty_out(vty,
12526 " Maximum allowed prefixes sent %u\n",
12527 p->pmax_out[afi][safi]);
12528
12529 /* Maximum prefix */
12530 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
12531 vty_out(vty,
12532 " Maximum prefixes allowed %u%s\n",
12533 p->pmax[afi][safi],
12534 CHECK_FLAG(p->af_flags[afi][safi],
12535 PEER_FLAG_MAX_PREFIX_WARNING)
12536 ? " (warning-only)"
12537 : "");
12538 vty_out(vty, " Threshold for warning message %d%%",
12539 p->pmax_threshold[afi][safi]);
12540 if (p->pmax_restart[afi][safi])
12541 vty_out(vty, ", restart interval %d min",
12542 p->pmax_restart[afi][safi]);
12543 vty_out(vty, "\n");
12544 }
12545
12546 vty_out(vty, "\n");
12547 }
12548}
12549
12550static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
12551 json_object *json)
12552{
12553 struct bgp *bgp;
12554 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
12555 char timebuf[BGP_UPTIME_LEN];
12556 char dn_flag[2];
12557 afi_t afi;
12558 safi_t safi;
12559 uint16_t i;
12560 uint8_t *msg;
12561 json_object *json_neigh = NULL;
12562 time_t epoch_tbuf;
12563
12564 bgp = p->bgp;
12565
12566 if (use_json)
12567 json_neigh = json_object_new_object();
12568
12569 memset(dn_flag, '\0', sizeof(dn_flag));
12570 if (!p->conf_if && peer_dynamic_neighbor(p))
12571 dn_flag[0] = '*';
12572
12573 if (!use_json) {
12574 if (p->conf_if) /* Configured interface name. */
12575 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
12576 BGP_PEER_SU_UNSPEC(p)
12577 ? "None"
12578 : sockunion2str(&p->su, buf,
12579 SU_ADDRSTRLEN));
12580 else /* Configured IP address. */
12581 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
12582 p->host);
12583 }
12584
12585 if (use_json) {
12586 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
12587 json_object_string_add(json_neigh, "bgpNeighborAddr",
12588 "none");
12589 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
12590 json_object_string_add(
12591 json_neigh, "bgpNeighborAddr",
12592 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
12593
12594 json_object_int_add(json_neigh, "remoteAs", p->as);
12595
12596 if (p->change_local_as)
12597 json_object_int_add(json_neigh, "localAs",
12598 p->change_local_as);
12599 else
12600 json_object_int_add(json_neigh, "localAs", p->local_as);
12601
12602 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
12603 json_object_boolean_true_add(json_neigh,
12604 "localAsNoPrepend");
12605
12606 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
12607 json_object_boolean_true_add(json_neigh,
12608 "localAsReplaceAs");
12609 } else {
12610 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
12611 || (p->as_type == AS_INTERNAL))
12612 vty_out(vty, "remote AS %u, ", p->as);
12613 else
12614 vty_out(vty, "remote AS Unspecified, ");
12615 vty_out(vty, "local AS %u%s%s, ",
12616 p->change_local_as ? p->change_local_as : p->local_as,
12617 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
12618 ? " no-prepend"
12619 : "",
12620 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
12621 ? " replace-as"
12622 : "");
12623 }
12624 /* peer type internal or confed-internal */
12625 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
12626 if (use_json) {
12627 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12628 json_object_boolean_true_add(
12629 json_neigh, "nbrConfedInternalLink");
12630 else
12631 json_object_boolean_true_add(json_neigh,
12632 "nbrInternalLink");
12633 } else {
12634 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12635 vty_out(vty, "confed-internal link\n");
12636 else
12637 vty_out(vty, "internal link\n");
12638 }
12639 /* peer type external or confed-external */
12640 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
12641 if (use_json) {
12642 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
12643 json_object_boolean_true_add(
12644 json_neigh, "nbrConfedExternalLink");
12645 else
12646 json_object_boolean_true_add(json_neigh,
12647 "nbrExternalLink");
12648 } else {
12649 if (bgp_confederation_peers_check(bgp, p->as))
12650 vty_out(vty, "confed-external link\n");
12651 else
12652 vty_out(vty, "external link\n");
12653 }
12654 } else {
12655 if (use_json)
12656 json_object_boolean_true_add(json_neigh,
12657 "nbrUnspecifiedLink");
12658 else
12659 vty_out(vty, "unspecified link\n");
12660 }
12661
12662 /* Description. */
12663 if (p->desc) {
12664 if (use_json)
12665 json_object_string_add(json_neigh, "nbrDesc", p->desc);
12666 else
12667 vty_out(vty, " Description: %s\n", p->desc);
12668 }
12669
12670 if (p->hostname) {
12671 if (use_json) {
12672 if (p->hostname)
12673 json_object_string_add(json_neigh, "hostname",
12674 p->hostname);
12675
12676 if (p->domainname)
12677 json_object_string_add(json_neigh, "domainname",
12678 p->domainname);
12679 } else {
12680 if (p->domainname && (p->domainname[0] != '\0'))
12681 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
12682 p->domainname);
12683 else
12684 vty_out(vty, "Hostname: %s\n", p->hostname);
12685 }
12686 }
12687
12688 /* Peer-group */
12689 if (p->group) {
12690 if (use_json) {
12691 json_object_string_add(json_neigh, "peerGroup",
12692 p->group->name);
12693
12694 if (dn_flag[0]) {
12695 struct prefix prefix, *range = NULL;
12696
12697 if (sockunion2hostprefix(&(p->su), &prefix))
12698 range = peer_group_lookup_dynamic_neighbor_range(
12699 p->group, &prefix);
12700
12701 if (range) {
12702 prefix2str(range, buf1, sizeof(buf1));
12703 json_object_string_add(
12704 json_neigh,
12705 "peerSubnetRangeGroup", buf1);
12706 }
12707 }
12708 } else {
12709 vty_out(vty,
12710 " Member of peer-group %s for session parameters\n",
12711 p->group->name);
12712
12713 if (dn_flag[0]) {
12714 struct prefix prefix, *range = NULL;
12715
12716 if (sockunion2hostprefix(&(p->su), &prefix))
12717 range = peer_group_lookup_dynamic_neighbor_range(
12718 p->group, &prefix);
12719
12720 if (range) {
12721 vty_out(vty,
12722 " Belongs to the subnet range group: %pFX\n",
12723 range);
12724 }
12725 }
12726 }
12727 }
12728
12729 if (use_json) {
12730 /* Administrative shutdown. */
12731 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12732 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12733 json_object_boolean_true_add(json_neigh,
12734 "adminShutDown");
12735
12736 /* BGP Version. */
12737 json_object_int_add(json_neigh, "bgpVersion", 4);
12738 json_object_string_add(
12739 json_neigh, "remoteRouterId",
12740 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12741 json_object_string_add(
12742 json_neigh, "localRouterId",
12743 inet_ntop(AF_INET, &bgp->router_id, buf1,
12744 sizeof(buf1)));
12745
12746 /* Confederation */
12747 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12748 && bgp_confederation_peers_check(bgp, p->as))
12749 json_object_boolean_true_add(json_neigh,
12750 "nbrCommonAdmin");
12751
12752 /* Status. */
12753 json_object_string_add(
12754 json_neigh, "bgpState",
12755 lookup_msg(bgp_status_msg, p->status, NULL));
12756
12757 if (p->status == Established) {
12758 time_t uptime;
12759
12760 uptime = bgp_clock();
12761 uptime -= p->uptime;
12762 epoch_tbuf = time(NULL) - uptime;
12763
12764 json_object_int_add(json_neigh, "bgpTimerUpMsec",
12765 uptime * 1000);
12766 json_object_string_add(json_neigh, "bgpTimerUpString",
12767 peer_uptime(p->uptime, timebuf,
12768 BGP_UPTIME_LEN, 0,
12769 NULL));
12770 json_object_int_add(json_neigh,
12771 "bgpTimerUpEstablishedEpoch",
12772 epoch_tbuf);
12773 }
12774
12775 else if (p->status == Active) {
12776 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12777 json_object_string_add(json_neigh, "bgpStateIs",
12778 "passive");
12779 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12780 json_object_string_add(json_neigh, "bgpStateIs",
12781 "passiveNSF");
12782 }
12783
12784 /* read timer */
12785 time_t uptime;
12786 struct tm tm;
12787
12788 uptime = bgp_clock();
12789 uptime -= p->readtime;
12790 gmtime_r(&uptime, &tm);
12791
12792 json_object_int_add(json_neigh, "bgpTimerLastRead",
12793 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12794 + (tm.tm_hour * 3600000));
12795
12796 uptime = bgp_clock();
12797 uptime -= p->last_write;
12798 gmtime_r(&uptime, &tm);
12799
12800 json_object_int_add(json_neigh, "bgpTimerLastWrite",
12801 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12802 + (tm.tm_hour * 3600000));
12803
12804 uptime = bgp_clock();
12805 uptime -= p->update_time;
12806 gmtime_r(&uptime, &tm);
12807
12808 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
12809 (tm.tm_sec * 1000) + (tm.tm_min * 60000)
12810 + (tm.tm_hour * 3600000));
12811
12812 /* Configured timer values. */
12813 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
12814 p->v_holdtime * 1000);
12815 json_object_int_add(json_neigh,
12816 "bgpTimerKeepAliveIntervalMsecs",
12817 p->v_keepalive * 1000);
12818 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN)) {
12819 json_object_int_add(json_neigh,
12820 "bgpTimerDelayOpenTimeMsecs",
12821 p->v_delayopen * 1000);
12822 }
12823
12824 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12825 json_object_int_add(json_neigh,
12826 "bgpTimerConfiguredHoldTimeMsecs",
12827 p->holdtime * 1000);
12828 json_object_int_add(
12829 json_neigh,
12830 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12831 p->keepalive * 1000);
12832 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12833 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12834 json_object_int_add(json_neigh,
12835 "bgpTimerConfiguredHoldTimeMsecs",
12836 bgp->default_holdtime);
12837 json_object_int_add(
12838 json_neigh,
12839 "bgpTimerConfiguredKeepAliveIntervalMsecs",
12840 bgp->default_keepalive);
12841 }
12842 } else {
12843 /* Administrative shutdown. */
12844 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN)
12845 || CHECK_FLAG(p->bgp->flags, BGP_FLAG_SHUTDOWN))
12846 vty_out(vty, " Administratively shut down\n");
12847
12848 /* BGP Version. */
12849 vty_out(vty, " BGP version 4");
12850 vty_out(vty, ", remote router ID %s",
12851 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
12852 vty_out(vty, ", local router ID %s\n",
12853 inet_ntop(AF_INET, &bgp->router_id, buf1,
12854 sizeof(buf1)));
12855
12856 /* Confederation */
12857 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
12858 && bgp_confederation_peers_check(bgp, p->as))
12859 vty_out(vty,
12860 " Neighbor under common administration\n");
12861
12862 /* Status. */
12863 vty_out(vty, " BGP state = %s",
12864 lookup_msg(bgp_status_msg, p->status, NULL));
12865
12866 if (p->status == Established)
12867 vty_out(vty, ", up for %8s",
12868 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
12869 0, NULL));
12870
12871 else if (p->status == Active) {
12872 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
12873 vty_out(vty, " (passive)");
12874 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
12875 vty_out(vty, " (NSF passive)");
12876 }
12877 vty_out(vty, "\n");
12878
12879 /* read timer */
12880 vty_out(vty, " Last read %s",
12881 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
12882 NULL));
12883 vty_out(vty, ", Last write %s\n",
12884 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
12885 NULL));
12886
12887 /* Configured timer values. */
12888 vty_out(vty,
12889 " Hold time is %d, keepalive interval is %d seconds\n",
12890 p->v_holdtime, p->v_keepalive);
12891 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
12892 vty_out(vty, " Configured hold time is %d",
12893 p->holdtime);
12894 vty_out(vty, ", keepalive interval is %d seconds\n",
12895 p->keepalive);
12896 } else if ((bgp->default_holdtime != SAVE_BGP_HOLDTIME)
12897 || (bgp->default_keepalive != SAVE_BGP_KEEPALIVE)) {
12898 vty_out(vty, " Configured hold time is %d",
12899 bgp->default_holdtime);
12900 vty_out(vty, ", keepalive interval is %d seconds\n",
12901 bgp->default_keepalive);
12902 }
12903 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER_DELAYOPEN))
12904 vty_out(vty,
12905 " Configured DelayOpenTime is %d seconds\n",
12906 p->delayopen);
12907 }
12908 /* Capability. */
12909 if (p->status == Established) {
12910 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
12911 || p->afc_recv[AFI_IP][SAFI_UNICAST]
12912 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
12913 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
12914 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
12915 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
12916 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
12917 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
12918 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
12919 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
12920 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
12921 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
12922 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
12923 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
12924 || p->afc_adv[AFI_IP][SAFI_ENCAP]
12925 || p->afc_recv[AFI_IP][SAFI_ENCAP]
12926 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
12927 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
12928 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
12929 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
12930 if (use_json) {
12931 json_object *json_cap = NULL;
12932
12933 json_cap = json_object_new_object();
12934
12935 /* AS4 */
12936 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
12937 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
12938 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
12939 && CHECK_FLAG(p->cap,
12940 PEER_CAP_AS4_RCV))
12941 json_object_string_add(
12942 json_cap, "4byteAs",
12943 "advertisedAndReceived");
12944 else if (CHECK_FLAG(p->cap,
12945 PEER_CAP_AS4_ADV))
12946 json_object_string_add(
12947 json_cap, "4byteAs",
12948 "advertised");
12949 else if (CHECK_FLAG(p->cap,
12950 PEER_CAP_AS4_RCV))
12951 json_object_string_add(
12952 json_cap, "4byteAs",
12953 "received");
12954 }
12955
12956 /* AddPath */
12957 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
12958 || CHECK_FLAG(p->cap,
12959 PEER_CAP_ADDPATH_ADV)) {
12960 json_object *json_add = NULL;
12961 const char *print_store;
12962
12963 json_add = json_object_new_object();
12964
12965 FOREACH_AFI_SAFI (afi, safi) {
12966 json_object *json_sub = NULL;
12967 json_sub =
12968 json_object_new_object();
12969 print_store = get_afi_safi_str(
12970 afi, safi, true);
12971
12972 if (CHECK_FLAG(
12973 p->af_cap[afi]
12974 [safi],
12975 PEER_CAP_ADDPATH_AF_TX_ADV)
12976 || CHECK_FLAG(
12977 p->af_cap[afi]
12978 [safi],
12979 PEER_CAP_ADDPATH_AF_TX_RCV)) {
12980 if (CHECK_FLAG(
12981 p->af_cap
12982 [afi]
12983 [safi],
12984 PEER_CAP_ADDPATH_AF_TX_ADV)
12985 && CHECK_FLAG(
12986 p->af_cap
12987 [afi]
12988 [safi],
12989 PEER_CAP_ADDPATH_AF_TX_RCV))
12990 json_object_boolean_true_add(
12991 json_sub,
12992 "txAdvertisedAndReceived");
12993 else if (
12994 CHECK_FLAG(
12995 p->af_cap
12996 [afi]
12997 [safi],
12998 PEER_CAP_ADDPATH_AF_TX_ADV))
12999 json_object_boolean_true_add(
13000 json_sub,
13001 "txAdvertised");
13002 else if (
13003 CHECK_FLAG(
13004 p->af_cap
13005 [afi]
13006 [safi],
13007 PEER_CAP_ADDPATH_AF_TX_RCV))
13008 json_object_boolean_true_add(
13009 json_sub,
13010 "txReceived");
13011 }
13012
13013 if (CHECK_FLAG(
13014 p->af_cap[afi]
13015 [safi],
13016 PEER_CAP_ADDPATH_AF_RX_ADV)
13017 || CHECK_FLAG(
13018 p->af_cap[afi]
13019 [safi],
13020 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13021 if (CHECK_FLAG(
13022 p->af_cap
13023 [afi]
13024 [safi],
13025 PEER_CAP_ADDPATH_AF_RX_ADV)
13026 && CHECK_FLAG(
13027 p->af_cap
13028 [afi]
13029 [safi],
13030 PEER_CAP_ADDPATH_AF_RX_RCV))
13031 json_object_boolean_true_add(
13032 json_sub,
13033 "rxAdvertisedAndReceived");
13034 else if (
13035 CHECK_FLAG(
13036 p->af_cap
13037 [afi]
13038 [safi],
13039 PEER_CAP_ADDPATH_AF_RX_ADV))
13040 json_object_boolean_true_add(
13041 json_sub,
13042 "rxAdvertised");
13043 else if (
13044 CHECK_FLAG(
13045 p->af_cap
13046 [afi]
13047 [safi],
13048 PEER_CAP_ADDPATH_AF_RX_RCV))
13049 json_object_boolean_true_add(
13050 json_sub,
13051 "rxReceived");
13052 }
13053
13054 if (CHECK_FLAG(
13055 p->af_cap[afi]
13056 [safi],
13057 PEER_CAP_ADDPATH_AF_TX_ADV)
13058 || CHECK_FLAG(
13059 p->af_cap[afi]
13060 [safi],
13061 PEER_CAP_ADDPATH_AF_TX_RCV)
13062 || CHECK_FLAG(
13063 p->af_cap[afi]
13064 [safi],
13065 PEER_CAP_ADDPATH_AF_RX_ADV)
13066 || CHECK_FLAG(
13067 p->af_cap[afi]
13068 [safi],
13069 PEER_CAP_ADDPATH_AF_RX_RCV))
13070 json_object_object_add(
13071 json_add,
13072 print_store,
13073 json_sub);
13074 else
13075 json_object_free(
13076 json_sub);
13077 }
13078
13079 json_object_object_add(
13080 json_cap, "addPath", json_add);
13081 }
13082
13083 /* Dynamic */
13084 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13085 || CHECK_FLAG(p->cap,
13086 PEER_CAP_DYNAMIC_ADV)) {
13087 if (CHECK_FLAG(p->cap,
13088 PEER_CAP_DYNAMIC_ADV)
13089 && CHECK_FLAG(p->cap,
13090 PEER_CAP_DYNAMIC_RCV))
13091 json_object_string_add(
13092 json_cap, "dynamic",
13093 "advertisedAndReceived");
13094 else if (CHECK_FLAG(
13095 p->cap,
13096 PEER_CAP_DYNAMIC_ADV))
13097 json_object_string_add(
13098 json_cap, "dynamic",
13099 "advertised");
13100 else if (CHECK_FLAG(
13101 p->cap,
13102 PEER_CAP_DYNAMIC_RCV))
13103 json_object_string_add(
13104 json_cap, "dynamic",
13105 "received");
13106 }
13107
13108 /* Extended nexthop */
13109 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13110 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13111 json_object *json_nxt = NULL;
13112 const char *print_store;
13113
13114
13115 if (CHECK_FLAG(p->cap,
13116 PEER_CAP_ENHE_ADV)
13117 && CHECK_FLAG(p->cap,
13118 PEER_CAP_ENHE_RCV))
13119 json_object_string_add(
13120 json_cap,
13121 "extendedNexthop",
13122 "advertisedAndReceived");
13123 else if (CHECK_FLAG(p->cap,
13124 PEER_CAP_ENHE_ADV))
13125 json_object_string_add(
13126 json_cap,
13127 "extendedNexthop",
13128 "advertised");
13129 else if (CHECK_FLAG(p->cap,
13130 PEER_CAP_ENHE_RCV))
13131 json_object_string_add(
13132 json_cap,
13133 "extendedNexthop",
13134 "received");
13135
13136 if (CHECK_FLAG(p->cap,
13137 PEER_CAP_ENHE_RCV)) {
13138 json_nxt =
13139 json_object_new_object();
13140
13141 for (safi = SAFI_UNICAST;
13142 safi < SAFI_MAX; safi++) {
13143 if (CHECK_FLAG(
13144 p->af_cap
13145 [AFI_IP]
13146 [safi],
13147 PEER_CAP_ENHE_AF_RCV)) {
13148 print_store = get_afi_safi_str(
13149 AFI_IP,
13150 safi, true);
13151 json_object_string_add(
13152 json_nxt,
13153 print_store,
13154 "recieved"); /* misspelled for compatibility */
13155 }
13156 }
13157 json_object_object_add(
13158 json_cap,
13159 "extendedNexthopFamililesByPeer",
13160 json_nxt);
13161 }
13162 }
13163
13164 /* Route Refresh */
13165 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13166 || CHECK_FLAG(p->cap,
13167 PEER_CAP_REFRESH_NEW_RCV)
13168 || CHECK_FLAG(p->cap,
13169 PEER_CAP_REFRESH_OLD_RCV)) {
13170 if (CHECK_FLAG(p->cap,
13171 PEER_CAP_REFRESH_ADV)
13172 && (CHECK_FLAG(
13173 p->cap,
13174 PEER_CAP_REFRESH_NEW_RCV)
13175 || CHECK_FLAG(
13176 p->cap,
13177 PEER_CAP_REFRESH_OLD_RCV))) {
13178 if (CHECK_FLAG(
13179 p->cap,
13180 PEER_CAP_REFRESH_OLD_RCV)
13181 && CHECK_FLAG(
13182 p->cap,
13183 PEER_CAP_REFRESH_NEW_RCV))
13184 json_object_string_add(
13185 json_cap,
13186 "routeRefresh",
13187 "advertisedAndReceivedOldNew");
13188 else {
13189 if (CHECK_FLAG(
13190 p->cap,
13191 PEER_CAP_REFRESH_OLD_RCV))
13192 json_object_string_add(
13193 json_cap,
13194 "routeRefresh",
13195 "advertisedAndReceivedOld");
13196 else
13197 json_object_string_add(
13198 json_cap,
13199 "routeRefresh",
13200 "advertisedAndReceivedNew");
13201 }
13202 } else if (
13203 CHECK_FLAG(
13204 p->cap,
13205 PEER_CAP_REFRESH_ADV))
13206 json_object_string_add(
13207 json_cap,
13208 "routeRefresh",
13209 "advertised");
13210 else if (
13211 CHECK_FLAG(
13212 p->cap,
13213 PEER_CAP_REFRESH_NEW_RCV)
13214 || CHECK_FLAG(
13215 p->cap,
13216 PEER_CAP_REFRESH_OLD_RCV))
13217 json_object_string_add(
13218 json_cap,
13219 "routeRefresh",
13220 "received");
13221 }
13222
13223 /* Enhanced Route Refresh */
13224 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13225 || CHECK_FLAG(p->cap,
13226 PEER_CAP_ENHANCED_RR_RCV)) {
13227 if (CHECK_FLAG(p->cap,
13228 PEER_CAP_ENHANCED_RR_ADV)
13229 && CHECK_FLAG(
13230 p->cap,
13231 PEER_CAP_ENHANCED_RR_RCV))
13232 json_object_string_add(
13233 json_cap,
13234 "enhancedRouteRefresh",
13235 "advertisedAndReceived");
13236 else if (
13237 CHECK_FLAG(
13238 p->cap,
13239 PEER_CAP_ENHANCED_RR_ADV))
13240 json_object_string_add(
13241 json_cap,
13242 "enhancedRouteRefresh",
13243 "advertised");
13244 else if (
13245 CHECK_FLAG(
13246 p->cap,
13247 PEER_CAP_ENHANCED_RR_RCV))
13248 json_object_string_add(
13249 json_cap,
13250 "enhancedRouteRefresh",
13251 "received");
13252 }
13253
13254 /* Multiprotocol Extensions */
13255 json_object *json_multi = NULL;
13256 json_multi = json_object_new_object();
13257
13258 FOREACH_AFI_SAFI (afi, safi) {
13259 if (p->afc_adv[afi][safi]
13260 || p->afc_recv[afi][safi]) {
13261 json_object *json_exten = NULL;
13262 json_exten =
13263 json_object_new_object();
13264
13265 if (p->afc_adv[afi][safi]
13266 && p->afc_recv[afi][safi])
13267 json_object_boolean_true_add(
13268 json_exten,
13269 "advertisedAndReceived");
13270 else if (p->afc_adv[afi][safi])
13271 json_object_boolean_true_add(
13272 json_exten,
13273 "advertised");
13274 else if (p->afc_recv[afi][safi])
13275 json_object_boolean_true_add(
13276 json_exten,
13277 "received");
13278
13279 json_object_object_add(
13280 json_multi,
13281 get_afi_safi_str(afi,
13282 safi,
13283 true),
13284 json_exten);
13285 }
13286 }
13287 json_object_object_add(
13288 json_cap, "multiprotocolExtensions",
13289 json_multi);
13290
13291 /* Hostname capabilities */
13292 json_object *json_hname = NULL;
13293
13294 json_hname = json_object_new_object();
13295
13296 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13297 json_object_string_add(
13298 json_hname, "advHostName",
13299 bgp->peer_self->hostname
13300 ? bgp->peer_self
13301 ->hostname
13302 : "n/a");
13303 json_object_string_add(
13304 json_hname, "advDomainName",
13305 bgp->peer_self->domainname
13306 ? bgp->peer_self
13307 ->domainname
13308 : "n/a");
13309 }
13310
13311
13312 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13313 json_object_string_add(
13314 json_hname, "rcvHostName",
13315 p->hostname ? p->hostname
13316 : "n/a");
13317 json_object_string_add(
13318 json_hname, "rcvDomainName",
13319 p->domainname ? p->domainname
13320 : "n/a");
13321 }
13322
13323 json_object_object_add(json_cap, "hostName",
13324 json_hname);
13325
13326 /* Gracefull Restart */
13327 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13328 || CHECK_FLAG(p->cap,
13329 PEER_CAP_RESTART_ADV)) {
13330 if (CHECK_FLAG(p->cap,
13331 PEER_CAP_RESTART_ADV)
13332 && CHECK_FLAG(p->cap,
13333 PEER_CAP_RESTART_RCV))
13334 json_object_string_add(
13335 json_cap,
13336 "gracefulRestart",
13337 "advertisedAndReceived");
13338 else if (CHECK_FLAG(
13339 p->cap,
13340 PEER_CAP_RESTART_ADV))
13341 json_object_string_add(
13342 json_cap,
13343 "gracefulRestartCapability",
13344 "advertised");
13345 else if (CHECK_FLAG(
13346 p->cap,
13347 PEER_CAP_RESTART_RCV))
13348 json_object_string_add(
13349 json_cap,
13350 "gracefulRestartCapability",
13351 "received");
13352
13353 if (CHECK_FLAG(p->cap,
13354 PEER_CAP_RESTART_RCV)) {
13355 int restart_af_count = 0;
13356 json_object *json_restart =
13357 NULL;
13358 json_restart =
13359 json_object_new_object();
13360
13361 json_object_int_add(
13362 json_cap,
13363 "gracefulRestartRemoteTimerMsecs",
13364 p->v_gr_restart * 1000);
13365
13366 FOREACH_AFI_SAFI (afi, safi) {
13367 if (CHECK_FLAG(
13368 p->af_cap
13369 [afi]
13370 [safi],
13371 PEER_CAP_RESTART_AF_RCV)) {
13372 json_object *
13373 json_sub =
13374 NULL;
13375 json_sub =
13376 json_object_new_object();
13377
13378 if (CHECK_FLAG(
13379 p->af_cap
13380 [afi]
13381 [safi],
13382 PEER_CAP_RESTART_AF_PRESERVE_RCV))
13383 json_object_boolean_true_add(
13384 json_sub,
13385 "preserved");
13386 restart_af_count++;
13387 json_object_object_add(
13388 json_restart,
13389 get_afi_safi_str(
13390 afi,
13391 safi,
13392 true),
13393 json_sub);
13394 }
13395 }
13396 if (!restart_af_count) {
13397 json_object_string_add(
13398 json_cap,
13399 "addressFamiliesByPeer",
13400 "none");
13401 json_object_free(
13402 json_restart);
13403 } else
13404 json_object_object_add(
13405 json_cap,
13406 "addressFamiliesByPeer",
13407 json_restart);
13408 }
13409 }
13410 json_object_object_add(json_neigh,
13411 "neighborCapabilities",
13412 json_cap);
13413 } else {
13414 vty_out(vty, " Neighbor capabilities:\n");
13415
13416 /* AS4 */
13417 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
13418 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
13419 vty_out(vty, " 4 Byte AS:");
13420 if (CHECK_FLAG(p->cap,
13421 PEER_CAP_AS4_ADV))
13422 vty_out(vty, " advertised");
13423 if (CHECK_FLAG(p->cap,
13424 PEER_CAP_AS4_RCV))
13425 vty_out(vty, " %sreceived",
13426 CHECK_FLAG(
13427 p->cap,
13428 PEER_CAP_AS4_ADV)
13429 ? "and "
13430 : "");
13431 vty_out(vty, "\n");
13432 }
13433
13434 /* AddPath */
13435 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
13436 || CHECK_FLAG(p->cap,
13437 PEER_CAP_ADDPATH_ADV)) {
13438 vty_out(vty, " AddPath:\n");
13439
13440 FOREACH_AFI_SAFI (afi, safi) {
13441 if (CHECK_FLAG(
13442 p->af_cap[afi]
13443 [safi],
13444 PEER_CAP_ADDPATH_AF_TX_ADV)
13445 || CHECK_FLAG(
13446 p->af_cap[afi]
13447 [safi],
13448 PEER_CAP_ADDPATH_AF_TX_RCV)) {
13449 vty_out(vty,
13450 " %s: TX ",
13451 get_afi_safi_str(
13452 afi,
13453 safi,
13454 false));
13455
13456 if (CHECK_FLAG(
13457 p->af_cap
13458 [afi]
13459 [safi],
13460 PEER_CAP_ADDPATH_AF_TX_ADV))
13461 vty_out(vty,
13462 "advertised %s",
13463 get_afi_safi_str(
13464 afi,
13465 safi,
13466 false));
13467
13468 if (CHECK_FLAG(
13469 p->af_cap
13470 [afi]
13471 [safi],
13472 PEER_CAP_ADDPATH_AF_TX_RCV))
13473 vty_out(vty,
13474 "%sreceived",
13475 CHECK_FLAG(
13476 p->af_cap
13477 [afi]
13478 [safi],
13479 PEER_CAP_ADDPATH_AF_TX_ADV)
13480 ? " and "
13481 : "");
13482
13483 vty_out(vty, "\n");
13484 }
13485
13486 if (CHECK_FLAG(
13487 p->af_cap[afi]
13488 [safi],
13489 PEER_CAP_ADDPATH_AF_RX_ADV)
13490 || CHECK_FLAG(
13491 p->af_cap[afi]
13492 [safi],
13493 PEER_CAP_ADDPATH_AF_RX_RCV)) {
13494 vty_out(vty,
13495 " %s: RX ",
13496 get_afi_safi_str(
13497 afi,
13498 safi,
13499 false));
13500
13501 if (CHECK_FLAG(
13502 p->af_cap
13503 [afi]
13504 [safi],
13505 PEER_CAP_ADDPATH_AF_RX_ADV))
13506 vty_out(vty,
13507 "advertised %s",
13508 get_afi_safi_str(
13509 afi,
13510 safi,
13511 false));
13512
13513 if (CHECK_FLAG(
13514 p->af_cap
13515 [afi]
13516 [safi],
13517 PEER_CAP_ADDPATH_AF_RX_RCV))
13518 vty_out(vty,
13519 "%sreceived",
13520 CHECK_FLAG(
13521 p->af_cap
13522 [afi]
13523 [safi],
13524 PEER_CAP_ADDPATH_AF_RX_ADV)
13525 ? " and "
13526 : "");
13527
13528 vty_out(vty, "\n");
13529 }
13530 }
13531 }
13532
13533 /* Dynamic */
13534 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
13535 || CHECK_FLAG(p->cap,
13536 PEER_CAP_DYNAMIC_ADV)) {
13537 vty_out(vty, " Dynamic:");
13538 if (CHECK_FLAG(p->cap,
13539 PEER_CAP_DYNAMIC_ADV))
13540 vty_out(vty, " advertised");
13541 if (CHECK_FLAG(p->cap,
13542 PEER_CAP_DYNAMIC_RCV))
13543 vty_out(vty, " %sreceived",
13544 CHECK_FLAG(
13545 p->cap,
13546 PEER_CAP_DYNAMIC_ADV)
13547 ? "and "
13548 : "");
13549 vty_out(vty, "\n");
13550 }
13551
13552 /* Extended nexthop */
13553 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
13554 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
13555 vty_out(vty, " Extended nexthop:");
13556 if (CHECK_FLAG(p->cap,
13557 PEER_CAP_ENHE_ADV))
13558 vty_out(vty, " advertised");
13559 if (CHECK_FLAG(p->cap,
13560 PEER_CAP_ENHE_RCV))
13561 vty_out(vty, " %sreceived",
13562 CHECK_FLAG(
13563 p->cap,
13564 PEER_CAP_ENHE_ADV)
13565 ? "and "
13566 : "");
13567 vty_out(vty, "\n");
13568
13569 if (CHECK_FLAG(p->cap,
13570 PEER_CAP_ENHE_RCV)) {
13571 vty_out(vty,
13572 " Address families by peer:\n ");
13573 for (safi = SAFI_UNICAST;
13574 safi < SAFI_MAX; safi++)
13575 if (CHECK_FLAG(
13576 p->af_cap
13577 [AFI_IP]
13578 [safi],
13579 PEER_CAP_ENHE_AF_RCV))
13580 vty_out(vty,
13581 " %s\n",
13582 get_afi_safi_str(
13583 AFI_IP,
13584 safi,
13585 false));
13586 }
13587 }
13588
13589 /* Route Refresh */
13590 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
13591 || CHECK_FLAG(p->cap,
13592 PEER_CAP_REFRESH_NEW_RCV)
13593 || CHECK_FLAG(p->cap,
13594 PEER_CAP_REFRESH_OLD_RCV)) {
13595 vty_out(vty, " Route refresh:");
13596 if (CHECK_FLAG(p->cap,
13597 PEER_CAP_REFRESH_ADV))
13598 vty_out(vty, " advertised");
13599 if (CHECK_FLAG(p->cap,
13600 PEER_CAP_REFRESH_NEW_RCV)
13601 || CHECK_FLAG(
13602 p->cap,
13603 PEER_CAP_REFRESH_OLD_RCV))
13604 vty_out(vty, " %sreceived(%s)",
13605 CHECK_FLAG(
13606 p->cap,
13607 PEER_CAP_REFRESH_ADV)
13608 ? "and "
13609 : "",
13610 (CHECK_FLAG(
13611 p->cap,
13612 PEER_CAP_REFRESH_OLD_RCV)
13613 && CHECK_FLAG(
13614 p->cap,
13615 PEER_CAP_REFRESH_NEW_RCV))
13616 ? "old & new"
13617 : CHECK_FLAG(
13618 p->cap,
13619 PEER_CAP_REFRESH_OLD_RCV)
13620 ? "old"
13621 : "new");
13622
13623 vty_out(vty, "\n");
13624 }
13625
13626 /* Enhanced Route Refresh */
13627 if (CHECK_FLAG(p->cap, PEER_CAP_ENHANCED_RR_ADV)
13628 || CHECK_FLAG(p->cap,
13629 PEER_CAP_ENHANCED_RR_RCV)) {
13630 vty_out(vty,
13631 " Enhanced Route Refresh:");
13632 if (CHECK_FLAG(
13633 p->cap,
13634 PEER_CAP_ENHANCED_RR_ADV))
13635 vty_out(vty, " advertised");
13636 if (CHECK_FLAG(
13637 p->cap,
13638 PEER_CAP_ENHANCED_RR_RCV))
13639 vty_out(vty, " %sreceived",
13640 CHECK_FLAG(
13641 p->cap,
13642 PEER_CAP_REFRESH_ADV)
13643 ? "and "
13644 : "");
13645 vty_out(vty, "\n");
13646 }
13647
13648 /* Multiprotocol Extensions */
13649 FOREACH_AFI_SAFI (afi, safi)
13650 if (p->afc_adv[afi][safi]
13651 || p->afc_recv[afi][safi]) {
13652 vty_out(vty,
13653 " Address Family %s:",
13654 get_afi_safi_str(
13655 afi,
13656 safi,
13657 false));
13658 if (p->afc_adv[afi][safi])
13659 vty_out(vty,
13660 " advertised");
13661 if (p->afc_recv[afi][safi])
13662 vty_out(vty,
13663 " %sreceived",
13664 p->afc_adv[afi]
13665 [safi]
13666 ? "and "
13667 : "");
13668 vty_out(vty, "\n");
13669 }
13670
13671 /* Hostname capability */
13672 vty_out(vty, " Hostname Capability:");
13673
13674 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
13675 vty_out(vty,
13676 " advertised (name: %s,domain name: %s)",
13677 bgp->peer_self->hostname
13678 ? bgp->peer_self
13679 ->hostname
13680 : "n/a",
13681 bgp->peer_self->domainname
13682 ? bgp->peer_self
13683 ->domainname
13684 : "n/a");
13685 } else {
13686 vty_out(vty, " not advertised");
13687 }
13688
13689 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
13690 vty_out(vty,
13691 " received (name: %s,domain name: %s)",
13692 p->hostname ? p->hostname
13693 : "n/a",
13694 p->domainname ? p->domainname
13695 : "n/a");
13696 } else {
13697 vty_out(vty, " not received");
13698 }
13699
13700 vty_out(vty, "\n");
13701
13702 /* Graceful Restart */
13703 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
13704 || CHECK_FLAG(p->cap,
13705 PEER_CAP_RESTART_ADV)) {
13706 vty_out(vty,
13707 " Graceful Restart Capability:");
13708 if (CHECK_FLAG(p->cap,
13709 PEER_CAP_RESTART_ADV))
13710 vty_out(vty, " advertised");
13711 if (CHECK_FLAG(p->cap,
13712 PEER_CAP_RESTART_RCV))
13713 vty_out(vty, " %sreceived",
13714 CHECK_FLAG(
13715 p->cap,
13716 PEER_CAP_RESTART_ADV)
13717 ? "and "
13718 : "");
13719 vty_out(vty, "\n");
13720
13721 if (CHECK_FLAG(p->cap,
13722 PEER_CAP_RESTART_RCV)) {
13723 int restart_af_count = 0;
13724
13725 vty_out(vty,
13726 " Remote Restart timer is %d seconds\n",
13727 p->v_gr_restart);
13728 vty_out(vty,
13729 " Address families by peer:\n ");
13730
13731 FOREACH_AFI_SAFI (afi, safi)
13732 if (CHECK_FLAG(
13733 p->af_cap
13734 [afi]
13735 [safi],
13736 PEER_CAP_RESTART_AF_RCV)) {
13737 vty_out(vty,
13738 "%s%s(%s)",
13739 restart_af_count
13740 ? ", "
13741 : "",
13742 get_afi_safi_str(
13743 afi,
13744 safi,
13745 false),
13746 CHECK_FLAG(
13747 p->af_cap
13748 [afi]
13749 [safi],
13750 PEER_CAP_RESTART_AF_PRESERVE_RCV)
13751 ? "preserved"
13752 : "not preserved");
13753 restart_af_count++;
13754 }
13755 if (!restart_af_count)
13756 vty_out(vty, "none");
13757 vty_out(vty, "\n");
13758 }
13759 } /* Gracefull Restart */
13760 }
13761 }
13762 }
13763
13764 /* graceful restart information */
13765 json_object *json_grace = NULL;
13766 json_object *json_grace_send = NULL;
13767 json_object *json_grace_recv = NULL;
13768 int eor_send_af_count = 0;
13769 int eor_receive_af_count = 0;
13770
13771 if (use_json) {
13772 json_grace = json_object_new_object();
13773 json_grace_send = json_object_new_object();
13774 json_grace_recv = json_object_new_object();
13775
13776 if ((p->status == Established)
13777 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13778 FOREACH_AFI_SAFI (afi, safi) {
13779 if (CHECK_FLAG(p->af_sflags[afi][safi],
13780 PEER_STATUS_EOR_SEND)) {
13781 json_object_boolean_true_add(
13782 json_grace_send,
13783 get_afi_safi_str(afi,
13784 safi,
13785 true));
13786 eor_send_af_count++;
13787 }
13788 }
13789 FOREACH_AFI_SAFI (afi, safi) {
13790 if (CHECK_FLAG(
13791 p->af_sflags[afi][safi],
13792 PEER_STATUS_EOR_RECEIVED)) {
13793 json_object_boolean_true_add(
13794 json_grace_recv,
13795 get_afi_safi_str(afi,
13796 safi,
13797 true));
13798 eor_receive_af_count++;
13799 }
13800 }
13801 }
13802 json_object_object_add(json_grace, "endOfRibSend",
13803 json_grace_send);
13804 json_object_object_add(json_grace, "endOfRibRecv",
13805 json_grace_recv);
13806
13807
13808 if (p->t_gr_restart)
13809 json_object_int_add(json_grace,
13810 "gracefulRestartTimerMsecs",
13811 thread_timer_remain_second(
13812 p->t_gr_restart)
13813 * 1000);
13814
13815 if (p->t_gr_stale)
13816 json_object_int_add(
13817 json_grace,
13818 "gracefulStalepathTimerMsecs",
13819 thread_timer_remain_second(
13820 p->t_gr_stale)
13821 * 1000);
13822 /* more gr info in new format */
13823 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json,
13824 json_grace);
13825 json_object_object_add(
13826 json_neigh, "gracefulRestartInfo", json_grace);
13827 } else {
13828 vty_out(vty, " Graceful restart information:\n");
13829 if ((p->status == Established)
13830 && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) {
13831
13832 vty_out(vty, " End-of-RIB send: ");
13833 FOREACH_AFI_SAFI (afi, safi) {
13834 if (CHECK_FLAG(p->af_sflags[afi][safi],
13835 PEER_STATUS_EOR_SEND)) {
13836 vty_out(vty, "%s%s",
13837 eor_send_af_count ? ", "
13838 : "",
13839 get_afi_safi_str(
13840 afi, safi,
13841 false));
13842 eor_send_af_count++;
13843 }
13844 }
13845 vty_out(vty, "\n");
13846 vty_out(vty, " End-of-RIB received: ");
13847 FOREACH_AFI_SAFI (afi, safi) {
13848 if (CHECK_FLAG(
13849 p->af_sflags[afi][safi],
13850 PEER_STATUS_EOR_RECEIVED)) {
13851 vty_out(vty, "%s%s",
13852 eor_receive_af_count
13853 ? ", "
13854 : "",
13855 get_afi_safi_str(afi,
13856 safi,
13857 false));
13858 eor_receive_af_count++;
13859 }
13860 }
13861 vty_out(vty, "\n");
13862 }
13863
13864 if (p->t_gr_restart)
13865 vty_out(vty,
13866 " The remaining time of restart timer is %ld\n",
13867 thread_timer_remain_second(
13868 p->t_gr_restart));
13869
13870 if (p->t_gr_stale)
13871 vty_out(vty,
13872 " The remaining time of stalepath timer is %ld\n",
13873 thread_timer_remain_second(
13874 p->t_gr_stale));
13875
13876 /* more gr info in new format */
13877 BGP_SHOW_PEER_GR_CAPABILITY(vty, p, use_json, NULL);
13878 }
13879
13880 if (use_json) {
13881 json_object *json_stat = NULL;
13882 json_stat = json_object_new_object();
13883 /* Packet counts. */
13884
13885 atomic_size_t outq_count, inq_count;
13886 outq_count = atomic_load_explicit(&p->obuf->count,
13887 memory_order_relaxed);
13888 inq_count = atomic_load_explicit(&p->ibuf->count,
13889 memory_order_relaxed);
13890
13891 json_object_int_add(json_stat, "depthInq",
13892 (unsigned long)inq_count);
13893 json_object_int_add(json_stat, "depthOutq",
13894 (unsigned long)outq_count);
13895 json_object_int_add(json_stat, "opensSent",
13896 atomic_load_explicit(&p->open_out,
13897 memory_order_relaxed));
13898 json_object_int_add(json_stat, "opensRecv",
13899 atomic_load_explicit(&p->open_in,
13900 memory_order_relaxed));
13901 json_object_int_add(json_stat, "notificationsSent",
13902 atomic_load_explicit(&p->notify_out,
13903 memory_order_relaxed));
13904 json_object_int_add(json_stat, "notificationsRecv",
13905 atomic_load_explicit(&p->notify_in,
13906 memory_order_relaxed));
13907 json_object_int_add(json_stat, "updatesSent",
13908 atomic_load_explicit(&p->update_out,
13909 memory_order_relaxed));
13910 json_object_int_add(json_stat, "updatesRecv",
13911 atomic_load_explicit(&p->update_in,
13912 memory_order_relaxed));
13913 json_object_int_add(json_stat, "keepalivesSent",
13914 atomic_load_explicit(&p->keepalive_out,
13915 memory_order_relaxed));
13916 json_object_int_add(json_stat, "keepalivesRecv",
13917 atomic_load_explicit(&p->keepalive_in,
13918 memory_order_relaxed));
13919 json_object_int_add(json_stat, "routeRefreshSent",
13920 atomic_load_explicit(&p->refresh_out,
13921 memory_order_relaxed));
13922 json_object_int_add(json_stat, "routeRefreshRecv",
13923 atomic_load_explicit(&p->refresh_in,
13924 memory_order_relaxed));
13925 json_object_int_add(json_stat, "capabilitySent",
13926 atomic_load_explicit(&p->dynamic_cap_out,
13927 memory_order_relaxed));
13928 json_object_int_add(json_stat, "capabilityRecv",
13929 atomic_load_explicit(&p->dynamic_cap_in,
13930 memory_order_relaxed));
13931 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
13932 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
13933 json_object_object_add(json_neigh, "messageStats", json_stat);
13934 } else {
13935 atomic_size_t outq_count, inq_count;
13936 outq_count = atomic_load_explicit(&p->obuf->count,
13937 memory_order_relaxed);
13938 inq_count = atomic_load_explicit(&p->ibuf->count,
13939 memory_order_relaxed);
13940
13941 /* Packet counts. */
13942 vty_out(vty, " Message statistics:\n");
13943 vty_out(vty, " Inq depth is %zu\n", inq_count);
13944 vty_out(vty, " Outq depth is %zu\n", outq_count);
13945 vty_out(vty, " Sent Rcvd\n");
13946 vty_out(vty, " Opens: %10d %10d\n",
13947 atomic_load_explicit(&p->open_out,
13948 memory_order_relaxed),
13949 atomic_load_explicit(&p->open_in,
13950 memory_order_relaxed));
13951 vty_out(vty, " Notifications: %10d %10d\n",
13952 atomic_load_explicit(&p->notify_out,
13953 memory_order_relaxed),
13954 atomic_load_explicit(&p->notify_in,
13955 memory_order_relaxed));
13956 vty_out(vty, " Updates: %10d %10d\n",
13957 atomic_load_explicit(&p->update_out,
13958 memory_order_relaxed),
13959 atomic_load_explicit(&p->update_in,
13960 memory_order_relaxed));
13961 vty_out(vty, " Keepalives: %10d %10d\n",
13962 atomic_load_explicit(&p->keepalive_out,
13963 memory_order_relaxed),
13964 atomic_load_explicit(&p->keepalive_in,
13965 memory_order_relaxed));
13966 vty_out(vty, " Route Refresh: %10d %10d\n",
13967 atomic_load_explicit(&p->refresh_out,
13968 memory_order_relaxed),
13969 atomic_load_explicit(&p->refresh_in,
13970 memory_order_relaxed));
13971 vty_out(vty, " Capability: %10d %10d\n",
13972 atomic_load_explicit(&p->dynamic_cap_out,
13973 memory_order_relaxed),
13974 atomic_load_explicit(&p->dynamic_cap_in,
13975 memory_order_relaxed));
13976 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
13977 PEER_TOTAL_RX(p));
13978 }
13979
13980 if (use_json) {
13981 /* advertisement-interval */
13982 json_object_int_add(json_neigh,
13983 "minBtwnAdvertisementRunsTimerMsecs",
13984 p->v_routeadv * 1000);
13985
13986 /* Update-source. */
13987 if (p->update_if || p->update_source) {
13988 if (p->update_if)
13989 json_object_string_add(json_neigh,
13990 "updateSource",
13991 p->update_if);
13992 else if (p->update_source)
13993 json_object_string_add(
13994 json_neigh, "updateSource",
13995 sockunion2str(p->update_source, buf1,
13996 SU_ADDRSTRLEN));
13997 }
13998 } else {
13999 /* advertisement-interval */
14000 vty_out(vty,
14001 " Minimum time between advertisement runs is %d seconds\n",
14002 p->v_routeadv);
14003
14004 /* Update-source. */
14005 if (p->update_if || p->update_source) {
14006 vty_out(vty, " Update source is ");
14007 if (p->update_if)
14008 vty_out(vty, "%s", p->update_if);
14009 else if (p->update_source)
14010 vty_out(vty, "%s",
14011 sockunion2str(p->update_source, buf1,
14012 SU_ADDRSTRLEN));
14013 vty_out(vty, "\n");
14014 }
14015
14016 vty_out(vty, "\n");
14017 }
14018
14019 /* Address Family Information */
14020 json_object *json_hold = NULL;
14021
14022 if (use_json)
14023 json_hold = json_object_new_object();
14024
14025 FOREACH_AFI_SAFI (afi, safi)
14026 if (p->afc[afi][safi])
14027 bgp_show_peer_afi(vty, p, afi, safi, use_json,
14028 json_hold);
14029
14030 if (use_json) {
14031 json_object_object_add(json_neigh, "addressFamilyInfo",
14032 json_hold);
14033 json_object_int_add(json_neigh, "connectionsEstablished",
14034 p->established);
14035 json_object_int_add(json_neigh, "connectionsDropped",
14036 p->dropped);
14037 } else
14038 vty_out(vty, " Connections established %d; dropped %d\n",
14039 p->established, p->dropped);
14040
14041 if (!p->last_reset) {
14042 if (use_json)
14043 json_object_string_add(json_neigh, "lastReset",
14044 "never");
14045 else
14046 vty_out(vty, " Last reset never\n");
14047 } else {
14048 if (use_json) {
14049 time_t uptime;
14050 struct tm tm;
14051
14052 uptime = bgp_clock();
14053 uptime -= p->resettime;
14054 gmtime_r(&uptime, &tm);
14055
14056 json_object_int_add(json_neigh, "lastResetTimerMsecs",
14057 (tm.tm_sec * 1000)
14058 + (tm.tm_min * 60000)
14059 + (tm.tm_hour * 3600000));
14060 bgp_show_peer_reset(NULL, p, json_neigh, true);
14061 } else {
14062 vty_out(vty, " Last reset %s, ",
14063 peer_uptime(p->resettime, timebuf,
14064 BGP_UPTIME_LEN, 0, NULL));
14065
14066 bgp_show_peer_reset(vty, p, NULL, false);
14067 if (p->last_reset_cause_size) {
14068 msg = p->last_reset_cause;
14069 vty_out(vty,
14070 " Message received that caused BGP to send a NOTIFICATION:\n ");
14071 for (i = 1; i <= p->last_reset_cause_size;
14072 i++) {
14073 vty_out(vty, "%02X", *msg++);
14074
14075 if (i != p->last_reset_cause_size) {
14076 if (i % 16 == 0) {
14077 vty_out(vty, "\n ");
14078 } else if (i % 4 == 0) {
14079 vty_out(vty, " ");
14080 }
14081 }
14082 }
14083 vty_out(vty, "\n");
14084 }
14085 }
14086 }
14087
14088 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
14089 if (use_json)
14090 json_object_boolean_true_add(json_neigh,
14091 "prefixesConfigExceedMax");
14092 else
14093 vty_out(vty,
14094 " Peer had exceeded the max. no. of prefixes configured.\n");
14095
14096 if (p->t_pmax_restart) {
14097 if (use_json) {
14098 json_object_boolean_true_add(
14099 json_neigh, "reducePrefixNumFrom");
14100 json_object_int_add(json_neigh,
14101 "restartInTimerMsec",
14102 thread_timer_remain_second(
14103 p->t_pmax_restart)
14104 * 1000);
14105 } else
14106 vty_out(vty,
14107 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
14108 p->host, thread_timer_remain_second(
14109 p->t_pmax_restart));
14110 } else {
14111 if (use_json)
14112 json_object_boolean_true_add(
14113 json_neigh,
14114 "reducePrefixNumAndClearIpBgp");
14115 else
14116 vty_out(vty,
14117 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
14118 p->host);
14119 }
14120 }
14121
14122 /* EBGP Multihop and GTSM */
14123 if (p->sort != BGP_PEER_IBGP) {
14124 if (use_json) {
14125 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14126 json_object_int_add(json_neigh,
14127 "externalBgpNbrMaxHopsAway",
14128 p->gtsm_hops);
14129 else if (p->ttl > BGP_DEFAULT_TTL)
14130 json_object_int_add(json_neigh,
14131 "externalBgpNbrMaxHopsAway",
14132 p->ttl);
14133 } else {
14134 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED)
14135 vty_out(vty,
14136 " External BGP neighbor may be up to %d hops away.\n",
14137 p->gtsm_hops);
14138 else if (p->ttl > BGP_DEFAULT_TTL)
14139 vty_out(vty,
14140 " External BGP neighbor may be up to %d hops away.\n",
14141 p->ttl);
14142 }
14143 } else {
14144 if (p->gtsm_hops > BGP_GTSM_HOPS_DISABLED) {
14145 if (use_json)
14146 json_object_int_add(json_neigh,
14147 "internalBgpNbrMaxHopsAway",
14148 p->gtsm_hops);
14149 else
14150 vty_out(vty,
14151 " Internal BGP neighbor may be up to %d hops away.\n",
14152 p->gtsm_hops);
14153 }
14154 }
14155
14156 /* Local address. */
14157 if (p->su_local) {
14158 if (use_json) {
14159 json_object_string_add(json_neigh, "hostLocal",
14160 sockunion2str(p->su_local, buf1,
14161 SU_ADDRSTRLEN));
14162 json_object_int_add(json_neigh, "portLocal",
14163 ntohs(p->su_local->sin.sin_port));
14164 } else
14165 vty_out(vty, "Local host: %s, Local port: %d\n",
14166 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
14167 ntohs(p->su_local->sin.sin_port));
14168 }
14169
14170 /* Remote address. */
14171 if (p->su_remote) {
14172 if (use_json) {
14173 json_object_string_add(json_neigh, "hostForeign",
14174 sockunion2str(p->su_remote, buf1,
14175 SU_ADDRSTRLEN));
14176 json_object_int_add(json_neigh, "portForeign",
14177 ntohs(p->su_remote->sin.sin_port));
14178 } else
14179 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
14180 sockunion2str(p->su_remote, buf1,
14181 SU_ADDRSTRLEN),
14182 ntohs(p->su_remote->sin.sin_port));
14183 }
14184
14185 /* Nexthop display. */
14186 if (p->su_local) {
14187 if (use_json) {
14188 json_object_string_add(json_neigh, "nexthop",
14189 inet_ntop(AF_INET,
14190 &p->nexthop.v4, buf1,
14191 sizeof(buf1)));
14192 json_object_string_add(json_neigh, "nexthopGlobal",
14193 inet_ntop(AF_INET6,
14194 &p->nexthop.v6_global,
14195 buf1, sizeof(buf1)));
14196 json_object_string_add(json_neigh, "nexthopLocal",
14197 inet_ntop(AF_INET6,
14198 &p->nexthop.v6_local,
14199 buf1, sizeof(buf1)));
14200 if (p->shared_network)
14201 json_object_string_add(json_neigh,
14202 "bgpConnection",
14203 "sharedNetwork");
14204 else
14205 json_object_string_add(json_neigh,
14206 "bgpConnection",
14207 "nonSharedNetwork");
14208 } else {
14209 vty_out(vty, "Nexthop: %s\n",
14210 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
14211 sizeof(buf1)));
14212 vty_out(vty, "Nexthop global: %s\n",
14213 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
14214 sizeof(buf1)));
14215 vty_out(vty, "Nexthop local: %s\n",
14216 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
14217 sizeof(buf1)));
14218 vty_out(vty, "BGP connection: %s\n",
14219 p->shared_network ? "shared network"
14220 : "non shared network");
14221 }
14222 }
14223
14224 /* Timer information. */
14225 if (use_json) {
14226 json_object_int_add(json_neigh, "connectRetryTimer",
14227 p->v_connect);
14228 if (p->status == Established && p->rtt)
14229 json_object_int_add(json_neigh, "estimatedRttInMsecs",
14230 p->rtt);
14231 if (p->t_start)
14232 json_object_int_add(
14233 json_neigh, "nextStartTimerDueInMsecs",
14234 thread_timer_remain_second(p->t_start) * 1000);
14235 if (p->t_connect)
14236 json_object_int_add(
14237 json_neigh, "nextConnectTimerDueInMsecs",
14238 thread_timer_remain_second(p->t_connect)
14239 * 1000);
14240 if (p->t_routeadv) {
14241 json_object_int_add(json_neigh, "mraiInterval",
14242 p->v_routeadv);
14243 json_object_int_add(
14244 json_neigh, "mraiTimerExpireInMsecs",
14245 thread_timer_remain_second(p->t_routeadv)
14246 * 1000);
14247 }
14248 if (p->password)
14249 json_object_int_add(json_neigh, "authenticationEnabled",
14250 1);
14251
14252 if (p->t_read)
14253 json_object_string_add(json_neigh, "readThread", "on");
14254 else
14255 json_object_string_add(json_neigh, "readThread", "off");
14256
14257 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
14258 json_object_string_add(json_neigh, "writeThread", "on");
14259 else
14260 json_object_string_add(json_neigh, "writeThread",
14261 "off");
14262 } else {
14263 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
14264 p->v_connect);
14265 if (p->status == Established && p->rtt)
14266 vty_out(vty, "Estimated round trip time: %d ms\n",
14267 p->rtt);
14268 if (p->t_start)
14269 vty_out(vty, "Next start timer due in %ld seconds\n",
14270 thread_timer_remain_second(p->t_start));
14271 if (p->t_connect)
14272 vty_out(vty, "Next connect timer due in %ld seconds\n",
14273 thread_timer_remain_second(p->t_connect));
14274 if (p->t_routeadv)
14275 vty_out(vty,
14276 "MRAI (interval %u) timer expires in %ld seconds\n",
14277 p->v_routeadv,
14278 thread_timer_remain_second(p->t_routeadv));
14279 if (p->password)
14280 vty_out(vty, "Peer Authentication Enabled\n");
14281
14282 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
14283 p->t_read ? "on" : "off",
14284 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
14285 ? "on"
14286 : "off", p->fd);
14287 }
14288
14289 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
14290 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
14291 bgp_capability_vty_out(vty, p, use_json, json_neigh);
14292
14293 if (!use_json)
14294 vty_out(vty, "\n");
14295
14296 /* BFD information. */
14297 bgp_bfd_show_info(vty, p, use_json, json_neigh);
14298
14299 if (use_json) {
14300 if (p->conf_if) /* Configured interface name. */
14301 json_object_object_add(json, p->conf_if, json_neigh);
14302 else /* Configured IP address. */
14303 json_object_object_add(json, p->host, json_neigh);
14304 }
14305}
14306
14307static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
14308 enum show_type type,
14309 union sockunion *su,
14310 const char *conf_if, afi_t afi,
14311 bool use_json)
14312{
14313 struct listnode *node, *nnode;
14314 struct peer *peer;
14315 int find = 0;
14316 safi_t safi = SAFI_UNICAST;
14317 json_object *json = NULL;
14318 json_object *json_neighbor = NULL;
14319
14320 if (use_json) {
14321 json = json_object_new_object();
14322 json_neighbor = json_object_new_object();
14323 }
14324
14325 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14326
14327 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14328 continue;
14329
14330 if ((peer->afc[afi][safi]) == 0)
14331 continue;
14332
14333 if (type == show_all) {
14334 bgp_show_peer_gr_status(vty, peer, use_json,
14335 json_neighbor);
14336
14337 if (use_json) {
14338 json_object_object_add(json, peer->host,
14339 json_neighbor);
14340 json_neighbor = NULL;
14341 }
14342
14343 } else if (type == show_peer) {
14344 if (conf_if) {
14345 if ((peer->conf_if
14346 && !strcmp(peer->conf_if, conf_if))
14347 || (peer->hostname
14348 && !strcmp(peer->hostname, conf_if))) {
14349 find = 1;
14350 bgp_show_peer_gr_status(vty, peer,
14351 use_json,
14352 json_neighbor);
14353 }
14354 } else {
14355 if (sockunion_same(&peer->su, su)) {
14356 find = 1;
14357 bgp_show_peer_gr_status(vty, peer,
14358 use_json,
14359 json_neighbor);
14360 }
14361 }
14362 if (use_json && find)
14363 json_object_object_add(json, peer->host,
14364 json_neighbor);
14365 }
14366
14367 if (find) {
14368 json_neighbor = NULL;
14369 break;
14370 }
14371 }
14372
14373 if (type == show_peer && !find) {
14374 if (use_json)
14375 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14376 else
14377 vty_out(vty, "%% No such neighbor\n");
14378 }
14379 if (use_json) {
14380 vty_out(vty, "%s\n",
14381 json_object_to_json_string_ext(
14382 json, JSON_C_TO_STRING_PRETTY));
14383
14384 if (json_neighbor)
14385 json_object_free(json_neighbor);
14386 json_object_free(json);
14387 } else {
14388 vty_out(vty, "\n");
14389 }
14390
14391 return CMD_SUCCESS;
14392}
14393
14394static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
14395 enum show_type type, union sockunion *su,
14396 const char *conf_if, bool use_json,
14397 json_object *json)
14398{
14399 struct listnode *node, *nnode;
14400 struct peer *peer;
14401 int find = 0;
14402 bool nbr_output = false;
14403 afi_t afi = AFI_MAX;
14404 safi_t safi = SAFI_MAX;
14405
14406 if (type == show_ipv4_peer || type == show_ipv4_all) {
14407 afi = AFI_IP;
14408 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
14409 afi = AFI_IP6;
14410 }
14411
14412 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
14413 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
14414 continue;
14415
14416 switch (type) {
14417 case show_all:
14418 bgp_show_peer(vty, peer, use_json, json);
14419 nbr_output = true;
14420 break;
14421 case show_peer:
14422 if (conf_if) {
14423 if ((peer->conf_if
14424 && !strcmp(peer->conf_if, conf_if))
14425 || (peer->hostname
14426 && !strcmp(peer->hostname, conf_if))) {
14427 find = 1;
14428 bgp_show_peer(vty, peer, use_json,
14429 json);
14430 }
14431 } else {
14432 if (sockunion_same(&peer->su, su)) {
14433 find = 1;
14434 bgp_show_peer(vty, peer, use_json,
14435 json);
14436 }
14437 }
14438 break;
14439 case show_ipv4_peer:
14440 case show_ipv6_peer:
14441 FOREACH_SAFI (safi) {
14442 if (peer->afc[afi][safi]) {
14443 if (conf_if) {
14444 if ((peer->conf_if
14445 && !strcmp(peer->conf_if, conf_if))
14446 || (peer->hostname
14447 && !strcmp(peer->hostname, conf_if))) {
14448 find = 1;
14449 bgp_show_peer(vty, peer, use_json,
14450 json);
14451 break;
14452 }
14453 } else {
14454 if (sockunion_same(&peer->su, su)) {
14455 find = 1;
14456 bgp_show_peer(vty, peer, use_json,
14457 json);
14458 break;
14459 }
14460 }
14461 }
14462 }
14463 break;
14464 case show_ipv4_all:
14465 case show_ipv6_all:
14466 FOREACH_SAFI (safi) {
14467 if (peer->afc[afi][safi]) {
14468 bgp_show_peer(vty, peer, use_json, json);
14469 nbr_output = true;
14470 break;
14471 }
14472 }
14473 break;
14474 }
14475 }
14476
14477 if ((type == show_peer || type == show_ipv4_peer ||
14478 type == show_ipv6_peer) && !find) {
14479 if (use_json)
14480 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
14481 else
14482 vty_out(vty, "%% No such neighbor in this view/vrf\n");
14483 }
14484
14485 if (type != show_peer && type != show_ipv4_peer &&
14486 type != show_ipv6_peer && !nbr_output && !use_json)
14487 vty_out(vty, "%% No BGP neighbors found\n");
14488
14489 if (use_json) {
14490 vty_out(vty, "%s\n", json_object_to_json_string_ext(
14491 json, JSON_C_TO_STRING_PRETTY));
14492 } else {
14493 vty_out(vty, "\n");
14494 }
14495
14496 return CMD_SUCCESS;
14497}
14498
14499static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
14500 enum show_type type,
14501 const char *ip_str,
14502 afi_t afi, bool use_json)
14503{
14504
14505 int ret;
14506 struct bgp *bgp;
14507 union sockunion su;
14508
14509 bgp = bgp_get_default();
14510
14511 if (!bgp)
14512 return;
14513
14514 if (!use_json)
14515 bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
14516 NULL);
14517
14518 if (ip_str) {
14519 ret = str2sockunion(ip_str, &su);
14520 if (ret < 0)
14521 bgp_show_neighbor_graceful_restart(
14522 vty, bgp, type, NULL, ip_str, afi, use_json);
14523 else
14524 bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
14525 NULL, afi, use_json);
14526 } else
14527 bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
14528 afi, use_json);
14529}
14530
14531static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
14532 enum show_type type,
14533 const char *ip_str,
14534 bool use_json)
14535{
14536 struct listnode *node, *nnode;
14537 struct bgp *bgp;
14538 union sockunion su;
14539 json_object *json = NULL;
14540 int ret, is_first = 1;
14541 bool nbr_output = false;
14542
14543 if (use_json)
14544 vty_out(vty, "{\n");
14545
14546 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
14547 nbr_output = true;
14548 if (use_json) {
14549 if (!(json = json_object_new_object())) {
14550 flog_err(
14551 EC_BGP_JSON_MEM_ERROR,
14552 "Unable to allocate memory for JSON object");
14553 vty_out(vty,
14554 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
14555 return;
14556 }
14557
14558 json_object_int_add(json, "vrfId",
14559 (bgp->vrf_id == VRF_UNKNOWN)
14560 ? -1
14561 : (int64_t)bgp->vrf_id);
14562 json_object_string_add(
14563 json, "vrfName",
14564 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14565 ? VRF_DEFAULT_NAME
14566 : bgp->name);
14567
14568 if (!is_first)
14569 vty_out(vty, ",\n");
14570 else
14571 is_first = 0;
14572
14573 vty_out(vty, "\"%s\":",
14574 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14575 ? VRF_DEFAULT_NAME
14576 : bgp->name);
14577 } else {
14578 vty_out(vty, "\nInstance %s:\n",
14579 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
14580 ? VRF_DEFAULT_NAME
14581 : bgp->name);
14582 }
14583
14584 if (type == show_peer || type == show_ipv4_peer ||
14585 type == show_ipv6_peer) {
14586 ret = str2sockunion(ip_str, &su);
14587 if (ret < 0)
14588 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14589 use_json, json);
14590 else
14591 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14592 use_json, json);
14593 } else {
14594 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
14595 use_json, json);
14596 }
14597 json_object_free(json);
14598 json = NULL;
14599 }
14600
14601 if (use_json)
14602 vty_out(vty, "}\n");
14603 else if (!nbr_output)
14604 vty_out(vty, "%% BGP instance not found\n");
14605}
14606
14607static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
14608 enum show_type type, const char *ip_str,
14609 bool use_json)
14610{
14611 int ret;
14612 struct bgp *bgp;
14613 union sockunion su;
14614 json_object *json = NULL;
14615
14616 if (name) {
14617 if (strmatch(name, "all")) {
14618 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
14619 use_json);
14620 return CMD_SUCCESS;
14621 } else {
14622 bgp = bgp_lookup_by_name(name);
14623 if (!bgp) {
14624 if (use_json) {
14625 json = json_object_new_object();
14626 vty_out(vty, "%s\n",
14627 json_object_to_json_string_ext(
14628 json,
14629 JSON_C_TO_STRING_PRETTY));
14630 json_object_free(json);
14631 } else
14632 vty_out(vty,
14633 "%% BGP instance not found\n");
14634
14635 return CMD_WARNING;
14636 }
14637 }
14638 } else {
14639 bgp = bgp_get_default();
14640 }
14641
14642 if (bgp) {
14643 json = json_object_new_object();
14644 if (ip_str) {
14645 ret = str2sockunion(ip_str, &su);
14646 if (ret < 0)
14647 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
14648 use_json, json);
14649 else
14650 bgp_show_neighbor(vty, bgp, type, &su, NULL,
14651 use_json, json);
14652 } else {
14653 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
14654 json);
14655 }
14656 json_object_free(json);
14657 } else {
14658 if (use_json)
14659 vty_out(vty, "{}\n");
14660 else
14661 vty_out(vty, "%% BGP instance not found\n");
14662 }
14663
14664 return CMD_SUCCESS;
14665}
14666
14667
14668
14669/* "show [ip] bgp neighbors graceful-restart" commands. */
14670DEFUN (show_ip_bgp_neighbors_gracrful_restart,
14671 show_ip_bgp_neighbors_graceful_restart_cmd,
14672 "show bgp [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] graceful-restart [json]",
14673 SHOW_STR
14674 BGP_STR
14675 IP_STR
14676 IPV6_STR
14677 NEIGHBOR_STR
14678 "Neighbor to display information about\n"
14679 "Neighbor to display information about\n"
14680 "Neighbor on BGP configured interface\n"
14681 GR_SHOW
14682 JSON_STR)
14683{
14684 char *sh_arg = NULL;
14685 enum show_type sh_type;
14686 int idx = 0;
14687 afi_t afi = AFI_MAX;
14688 bool uj = use_json(argc, argv);
14689
14690 if (!argv_find_and_parse_afi(argv, argc, &idx, &afi))
14691 afi = AFI_MAX;
14692
14693 idx++;
14694
14695 if (argv_find(argv, argc, "A.B.C.D", &idx)
14696 || argv_find(argv, argc, "X:X::X:X", &idx)
14697 || argv_find(argv, argc, "WORD", &idx)) {
14698 sh_type = show_peer;
14699 sh_arg = argv[idx]->arg;
14700 } else
14701 sh_type = show_all;
14702
14703 if (!argv_find(argv, argc, "graceful-restart", &idx))
14704 return CMD_SUCCESS;
14705
14706
14707 return bgp_show_neighbor_graceful_restart_afi_all(vty, sh_type, sh_arg,
14708 afi, uj);
14709}
14710
14711/* "show [ip] bgp neighbors" commands. */
14712DEFUN (show_ip_bgp_neighbors,
14713 show_ip_bgp_neighbors_cmd,
14714 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
14715 SHOW_STR
14716 IP_STR
14717 BGP_STR
14718 BGP_INSTANCE_HELP_STR
14719 "Address Family\n"
14720 "Address Family\n"
14721 "Detailed information on TCP and BGP neighbor connections\n"
14722 "Neighbor to display information about\n"
14723 "Neighbor to display information about\n"
14724 "Neighbor on BGP configured interface\n"
14725 JSON_STR)
14726{
14727 char *vrf = NULL;
14728 char *sh_arg = NULL;
14729 enum show_type sh_type;
14730 afi_t afi = AFI_MAX;
14731
14732 bool uj = use_json(argc, argv);
14733
14734 int idx = 0;
14735
14736 /* [<vrf> VIEWVRFNAME] */
14737 if (argv_find(argv, argc, "vrf", &idx)) {
14738 vrf = argv[idx + 1]->arg;
14739 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
14740 vrf = NULL;
14741 } else if (argv_find(argv, argc, "view", &idx))
14742 /* [<view> VIEWVRFNAME] */
14743 vrf = argv[idx + 1]->arg;
14744
14745 idx++;
14746
14747 if (argv_find(argv, argc, "ipv4", &idx)) {
14748 sh_type = show_ipv4_all;
14749 afi = AFI_IP;
14750 } else if (argv_find(argv, argc, "ipv6", &idx)) {
14751 sh_type = show_ipv6_all;
14752 afi = AFI_IP6;
14753 } else {
14754 sh_type = show_all;
14755 }
14756
14757 if (argv_find(argv, argc, "A.B.C.D", &idx)
14758 || argv_find(argv, argc, "X:X::X:X", &idx)
14759 || argv_find(argv, argc, "WORD", &idx)) {
14760 sh_type = show_peer;
14761 sh_arg = argv[idx]->arg;
14762 }
14763
14764 if (sh_type == show_peer && afi == AFI_IP) {
14765 sh_type = show_ipv4_peer;
14766 } else if (sh_type == show_peer && afi == AFI_IP6) {
14767 sh_type = show_ipv6_peer;
14768 }
14769
14770 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
14771}
14772
14773/* Show BGP's AS paths internal data. There are both `show [ip] bgp
14774 paths' and `show ip mbgp paths'. Those functions results are the
14775 same.*/
14776DEFUN (show_ip_bgp_paths,
14777 show_ip_bgp_paths_cmd,
14778 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
14779 SHOW_STR
14780 IP_STR
14781 BGP_STR
14782 BGP_SAFI_HELP_STR
14783 "Path information\n")
14784{
14785 vty_out(vty, "Address Refcnt Path\n");
14786 aspath_print_all_vty(vty);
14787 return CMD_SUCCESS;
14788}
14789
14790#include "hash.h"
14791
14792static void community_show_all_iterator(struct hash_bucket *bucket,
14793 struct vty *vty)
14794{
14795 struct community *com;
14796
14797 com = (struct community *)bucket->data;
14798 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
14799 community_str(com, false));
14800}
14801
14802/* Show BGP's community internal data. */
14803DEFUN (show_ip_bgp_community_info,
14804 show_ip_bgp_community_info_cmd,
14805 "show [ip] bgp community-info",
14806 SHOW_STR
14807 IP_STR
14808 BGP_STR
14809 "List all bgp community information\n")
14810{
14811 vty_out(vty, "Address Refcnt Community\n");
14812
14813 hash_iterate(community_hash(),
14814 (void (*)(struct hash_bucket *,
14815 void *))community_show_all_iterator,
14816 vty);
14817
14818 return CMD_SUCCESS;
14819}
14820
14821static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
14822 struct vty *vty)
14823{
14824 struct lcommunity *lcom;
14825
14826 lcom = (struct lcommunity *)bucket->data;
14827 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
14828 lcommunity_str(lcom, false));
14829}
14830
14831/* Show BGP's community internal data. */
14832DEFUN (show_ip_bgp_lcommunity_info,
14833 show_ip_bgp_lcommunity_info_cmd,
14834 "show ip bgp large-community-info",
14835 SHOW_STR
14836 IP_STR
14837 BGP_STR
14838 "List all bgp large-community information\n")
14839{
14840 vty_out(vty, "Address Refcnt Large-community\n");
14841
14842 hash_iterate(lcommunity_hash(),
14843 (void (*)(struct hash_bucket *,
14844 void *))lcommunity_show_all_iterator,
14845 vty);
14846
14847 return CMD_SUCCESS;
14848}
14849/* Graceful Restart */
14850
14851static void bgp_show_global_graceful_restart_mode_vty(struct vty *vty,
14852 struct bgp *bgp,
14853 bool use_json,
14854 json_object *json)
14855{
14856
14857
14858 vty_out(vty, "\n%s", SHOW_GR_HEADER);
14859
14860 enum global_mode bgp_global_gr_mode = bgp_global_gr_mode_get(bgp);
14861
14862 switch (bgp_global_gr_mode) {
14863
14864 case GLOBAL_HELPER:
14865 vty_out(vty, "Global BGP GR Mode : Helper\n");
14866 break;
14867
14868 case GLOBAL_GR:
14869 vty_out(vty, "Global BGP GR Mode : Restart\n");
14870 break;
14871
14872 case GLOBAL_DISABLE:
14873 vty_out(vty, "Global BGP GR Mode : Disable\n");
14874 break;
14875
14876 case GLOBAL_INVALID:
14877 vty_out(vty,
14878 "Global BGP GR Mode Invalid\n");
14879 break;
14880 }
14881 vty_out(vty, "\n");
14882}
14883
14884static int bgp_show_neighbor_graceful_restart_afi_all(struct vty *vty,
14885 enum show_type type,
14886 const char *ip_str,
14887 afi_t afi, bool use_json)
14888{
14889 if ((afi == AFI_MAX) && (ip_str == NULL)) {
14890 afi = AFI_IP;
14891
14892 while ((afi != AFI_L2VPN) && (afi < AFI_MAX)) {
14893
14894 bgp_show_neighbor_graceful_restart_vty(
14895 vty, type, ip_str, afi, use_json);
14896 afi++;
14897 }
14898 } else if (afi != AFI_MAX) {
14899 bgp_show_neighbor_graceful_restart_vty(vty, type, ip_str, afi,
14900 use_json);
14901 } else {
14902 return CMD_ERR_INCOMPLETE;
14903 }
14904
14905 return CMD_SUCCESS;
14906}
14907/* Graceful Restart */
14908
14909DEFUN (show_ip_bgp_attr_info,
14910 show_ip_bgp_attr_info_cmd,
14911 "show [ip] bgp attribute-info",
14912 SHOW_STR
14913 IP_STR
14914 BGP_STR
14915 "List all bgp attribute information\n")
14916{
14917 attr_show_all(vty);
14918 return CMD_SUCCESS;
14919}
14920
14921static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
14922 afi_t afi, safi_t safi,
14923 bool use_json, json_object *json)
14924{
14925 struct bgp *bgp;
14926 struct listnode *node;
14927 char *vname;
14928 char buf1[INET6_ADDRSTRLEN];
14929 char *ecom_str;
14930 vpn_policy_direction_t dir;
14931
14932 if (json) {
14933 json_object *json_import_vrfs = NULL;
14934 json_object *json_export_vrfs = NULL;
14935
14936 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
14937
14938 if (!bgp) {
14939 vty_out(vty, "%s\n",
14940 json_object_to_json_string_ext(
14941 json,
14942 JSON_C_TO_STRING_PRETTY));
14943 json_object_free(json);
14944
14945 return CMD_WARNING;
14946 }
14947
14948 /* Provide context for the block */
14949 json_object_string_add(json, "vrf", name ? name : "default");
14950 json_object_string_add(json, "afiSafi",
14951 get_afi_safi_str(afi, safi, true));
14952
14953 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14954 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
14955 json_object_string_add(json, "importFromVrfs", "none");
14956 json_object_string_add(json, "importRts", "none");
14957 } else {
14958 json_import_vrfs = json_object_new_array();
14959
14960 for (ALL_LIST_ELEMENTS_RO(
14961 bgp->vpn_policy[afi].import_vrf,
14962 node, vname))
14963 json_object_array_add(json_import_vrfs,
14964 json_object_new_string(vname));
14965
14966 json_object_object_add(json, "importFromVrfs",
14967 json_import_vrfs);
14968 dir = BGP_VPN_POLICY_DIR_FROMVPN;
14969 if (bgp->vpn_policy[afi].rtlist[dir]) {
14970 ecom_str = ecommunity_ecom2str(
14971 bgp->vpn_policy[afi].rtlist[dir],
14972 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
14973 json_object_string_add(json, "importRts",
14974 ecom_str);
14975 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
14976 } else
14977 json_object_string_add(json, "importRts",
14978 "none");
14979 }
14980
14981 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
14982 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
14983 json_object_string_add(json, "exportToVrfs", "none");
14984 json_object_string_add(json, "routeDistinguisher",
14985 "none");
14986 json_object_string_add(json, "exportRts", "none");
14987 } else {
14988 json_export_vrfs = json_object_new_array();
14989
14990 for (ALL_LIST_ELEMENTS_RO(
14991 bgp->vpn_policy[afi].export_vrf,
14992 node, vname))
14993 json_object_array_add(json_export_vrfs,
14994 json_object_new_string(vname));
14995 json_object_object_add(json, "exportToVrfs",
14996 json_export_vrfs);
14997 json_object_string_add(json, "routeDistinguisher",
14998 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
14999 buf1, RD_ADDRSTRLEN));
15000
15001 dir = BGP_VPN_POLICY_DIR_TOVPN;
15002 if (bgp->vpn_policy[afi].rtlist[dir]) {
15003 ecom_str = ecommunity_ecom2str(
15004 bgp->vpn_policy[afi].rtlist[dir],
15005 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15006 json_object_string_add(json, "exportRts",
15007 ecom_str);
15008 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15009 } else
15010 json_object_string_add(json, "exportRts",
15011 "none");
15012 }
15013
15014 if (use_json) {
15015 vty_out(vty, "%s\n",
15016 json_object_to_json_string_ext(json,
15017 JSON_C_TO_STRING_PRETTY));
15018 json_object_free(json);
15019 }
15020 } else {
15021 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15022
15023 if (!bgp) {
15024 vty_out(vty, "%% No such BGP instance exist\n");
15025 return CMD_WARNING;
15026 }
15027
15028 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15029 BGP_CONFIG_VRF_TO_VRF_IMPORT))
15030 vty_out(vty,
15031 "This VRF is not importing %s routes from any other VRF\n",
15032 get_afi_safi_str(afi, safi, false));
15033 else {
15034 vty_out(vty,
15035 "This VRF is importing %s routes from the following VRFs:\n",
15036 get_afi_safi_str(afi, safi, false));
15037
15038 for (ALL_LIST_ELEMENTS_RO(
15039 bgp->vpn_policy[afi].import_vrf,
15040 node, vname))
15041 vty_out(vty, " %s\n", vname);
15042
15043 dir = BGP_VPN_POLICY_DIR_FROMVPN;
15044 ecom_str = NULL;
15045 if (bgp->vpn_policy[afi].rtlist[dir]) {
15046 ecom_str = ecommunity_ecom2str(
15047 bgp->vpn_policy[afi].rtlist[dir],
15048 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15049 vty_out(vty, "Import RT(s): %s\n", ecom_str);
15050
15051 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15052 } else
15053 vty_out(vty, "Import RT(s):\n");
15054 }
15055
15056 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
15057 BGP_CONFIG_VRF_TO_VRF_EXPORT))
15058 vty_out(vty,
15059 "This VRF is not exporting %s routes to any other VRF\n",
15060 get_afi_safi_str(afi, safi, false));
15061 else {
15062 vty_out(vty,
15063 "This VRF is exporting %s routes to the following VRFs:\n",
15064 get_afi_safi_str(afi, safi, false));
15065
15066 for (ALL_LIST_ELEMENTS_RO(
15067 bgp->vpn_policy[afi].export_vrf,
15068 node, vname))
15069 vty_out(vty, " %s\n", vname);
15070
15071 vty_out(vty, "RD: %s\n",
15072 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
15073 buf1, RD_ADDRSTRLEN));
15074
15075 dir = BGP_VPN_POLICY_DIR_TOVPN;
15076 if (bgp->vpn_policy[afi].rtlist[dir]) {
15077 ecom_str = ecommunity_ecom2str(
15078 bgp->vpn_policy[afi].rtlist[dir],
15079 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
15080 vty_out(vty, "Export RT: %s\n", ecom_str);
15081 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
15082 } else
15083 vty_out(vty, "Import RT(s):\n");
15084 }
15085 }
15086
15087 return CMD_SUCCESS;
15088}
15089
15090static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
15091 safi_t safi, bool use_json)
15092{
15093 struct listnode *node, *nnode;
15094 struct bgp *bgp;
15095 char *vrf_name = NULL;
15096 json_object *json = NULL;
15097 json_object *json_vrf = NULL;
15098 json_object *json_vrfs = NULL;
15099
15100 if (use_json) {
15101 json = json_object_new_object();
15102 json_vrfs = json_object_new_object();
15103 }
15104
15105 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15106
15107 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
15108 vrf_name = bgp->name;
15109
15110 if (use_json) {
15111 json_vrf = json_object_new_object();
15112 } else {
15113 vty_out(vty, "\nInstance %s:\n",
15114 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15115 ? VRF_DEFAULT_NAME : bgp->name);
15116 }
15117 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
15118 if (use_json) {
15119 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15120 json_object_object_add(json_vrfs,
15121 VRF_DEFAULT_NAME, json_vrf);
15122 else
15123 json_object_object_add(json_vrfs, vrf_name,
15124 json_vrf);
15125 }
15126 }
15127
15128 if (use_json) {
15129 json_object_object_add(json, "vrfs", json_vrfs);
15130 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
15131 JSON_C_TO_STRING_PRETTY));
15132 json_object_free(json);
15133 }
15134
15135 return CMD_SUCCESS;
15136}
15137
15138/* "show [ip] bgp route-leak" command. */
15139DEFUN (show_ip_bgp_route_leak,
15140 show_ip_bgp_route_leak_cmd,
15141 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
15142 SHOW_STR
15143 IP_STR
15144 BGP_STR
15145 BGP_INSTANCE_HELP_STR
15146 BGP_AFI_HELP_STR
15147 BGP_SAFI_HELP_STR
15148 "Route leaking information\n"
15149 JSON_STR)
15150{
15151 char *vrf = NULL;
15152 afi_t afi = AFI_MAX;
15153 safi_t safi = SAFI_MAX;
15154
15155 bool uj = use_json(argc, argv);
15156 int idx = 0;
15157 json_object *json = NULL;
15158
15159 /* show [ip] bgp */
15160 if (argv_find(argv, argc, "ip", &idx)) {
15161 afi = AFI_IP;
15162 safi = SAFI_UNICAST;
15163 }
15164 /* [vrf VIEWVRFNAME] */
15165 if (argv_find(argv, argc, "view", &idx)) {
15166 vty_out(vty,
15167 "%% This command is not applicable to BGP views\n");
15168 return CMD_WARNING;
15169 }
15170
15171 if (argv_find(argv, argc, "vrf", &idx)) {
15172 vrf = argv[idx + 1]->arg;
15173 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15174 vrf = NULL;
15175 }
15176 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15177 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15178 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15179 }
15180
15181 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
15182 vty_out(vty,
15183 "%% This command is applicable only for unicast ipv4|ipv6\n");
15184 return CMD_WARNING;
15185 }
15186
15187 if (vrf && strmatch(vrf, "all"))
15188 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
15189
15190 if (uj)
15191 json = json_object_new_object();
15192
15193 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
15194}
15195
15196static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
15197 safi_t safi)
15198{
15199 struct listnode *node, *nnode;
15200 struct bgp *bgp;
15201
15202 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
15203 vty_out(vty, "\nInstance %s:\n",
15204 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
15205 ? VRF_DEFAULT_NAME
15206 : bgp->name);
15207 update_group_show(bgp, afi, safi, vty, 0);
15208 }
15209}
15210
15211static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
15212 int safi, uint64_t subgrp_id)
15213{
15214 struct bgp *bgp;
15215
15216 if (name) {
15217 if (strmatch(name, "all")) {
15218 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
15219 return CMD_SUCCESS;
15220 } else {
15221 bgp = bgp_lookup_by_name(name);
15222 }
15223 } else {
15224 bgp = bgp_get_default();
15225 }
15226
15227 if (bgp)
15228 update_group_show(bgp, afi, safi, vty, subgrp_id);
15229 return CMD_SUCCESS;
15230}
15231
15232DEFUN (show_ip_bgp_updgrps,
15233 show_ip_bgp_updgrps_cmd,
15234 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
15235 SHOW_STR
15236 IP_STR
15237 BGP_STR
15238 BGP_INSTANCE_HELP_STR
15239 BGP_AFI_HELP_STR
15240 BGP_SAFI_WITH_LABEL_HELP_STR
15241 "Detailed info about dynamic update groups\n"
15242 "Specific subgroup to display detailed info for\n")
15243{
15244 char *vrf = NULL;
15245 afi_t afi = AFI_IP6;
15246 safi_t safi = SAFI_UNICAST;
15247 uint64_t subgrp_id = 0;
15248
15249 int idx = 0;
15250
15251 /* show [ip] bgp */
15252 if (argv_find(argv, argc, "ip", &idx))
15253 afi = AFI_IP;
15254 /* [<vrf> VIEWVRFNAME] */
15255 if (argv_find(argv, argc, "vrf", &idx)) {
15256 vrf = argv[idx + 1]->arg;
15257 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
15258 vrf = NULL;
15259 } else if (argv_find(argv, argc, "view", &idx))
15260 /* [<view> VIEWVRFNAME] */
15261 vrf = argv[idx + 1]->arg;
15262 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
15263 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
15264 argv_find_and_parse_safi(argv, argc, &idx, &safi);
15265 }
15266
15267 /* get subgroup id, if provided */
15268 idx = argc - 1;
15269 if (argv[idx]->type == VARIABLE_TKN)
15270 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
15271
15272 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
15273}
15274
15275DEFUN (show_bgp_instance_all_ipv6_updgrps,
15276 show_bgp_instance_all_ipv6_updgrps_cmd,
15277 "show [ip] bgp <view|vrf> all update-groups",
15278 SHOW_STR
15279 IP_STR
15280 BGP_STR
15281 BGP_INSTANCE_ALL_HELP_STR
15282 "Detailed info about dynamic update groups\n")
15283{
15284 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
15285 return CMD_SUCCESS;
15286}
15287
15288DEFUN (show_bgp_l2vpn_evpn_updgrps,
15289 show_bgp_l2vpn_evpn_updgrps_cmd,
15290 "show [ip] bgp l2vpn evpn update-groups",
15291 SHOW_STR
15292 IP_STR
15293 BGP_STR
15294 "l2vpn address family\n"
15295 "evpn sub-address family\n"
15296 "Detailed info about dynamic update groups\n")
15297{
15298 char *vrf = NULL;
15299 uint64_t subgrp_id = 0;
15300
15301 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
15302 return CMD_SUCCESS;
15303}
15304
15305DEFUN (show_bgp_updgrps_stats,
15306 show_bgp_updgrps_stats_cmd,
15307 "show [ip] bgp update-groups statistics",
15308 SHOW_STR
15309 IP_STR
15310 BGP_STR
15311 "Detailed info about dynamic update groups\n"
15312 "Statistics\n")
15313{
15314 struct bgp *bgp;
15315
15316 bgp = bgp_get_default();
15317 if (bgp)
15318 update_group_show_stats(bgp, vty);
15319
15320 return CMD_SUCCESS;
15321}
15322
15323DEFUN (show_bgp_instance_updgrps_stats,
15324 show_bgp_instance_updgrps_stats_cmd,
15325 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
15326 SHOW_STR
15327 IP_STR
15328 BGP_STR
15329 BGP_INSTANCE_HELP_STR
15330 "Detailed info about dynamic update groups\n"
15331 "Statistics\n")
15332{
15333 int idx_word = 3;
15334 struct bgp *bgp;
15335
15336 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
15337 if (bgp)
15338 update_group_show_stats(bgp, vty);
15339
15340 return CMD_SUCCESS;
15341}
15342
15343static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
15344 afi_t afi, safi_t safi,
15345 const char *what, uint64_t subgrp_id)
15346{
15347 struct bgp *bgp;
15348
15349 if (name)
15350 bgp = bgp_lookup_by_name(name);
15351 else
15352 bgp = bgp_get_default();
15353
15354 if (bgp) {
15355 if (!strcmp(what, "advertise-queue"))
15356 update_group_show_adj_queue(bgp, afi, safi, vty,
15357 subgrp_id);
15358 else if (!strcmp(what, "advertised-routes"))
15359 update_group_show_advertised(bgp, afi, safi, vty,
15360 subgrp_id);
15361 else if (!strcmp(what, "packet-queue"))
15362 update_group_show_packet_queue(bgp, afi, safi, vty,
15363 subgrp_id);
15364 }
15365}
15366
15367DEFPY(show_ip_bgp_instance_updgrps_adj_s,
15368 show_ip_bgp_instance_updgrps_adj_s_cmd,
15369 "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",
15370 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
15371 BGP_SAFI_HELP_STR
15372 "Detailed info about dynamic update groups\n"
15373 "Specific subgroup to display info for\n"
15374 "Advertisement queue\n"
15375 "Announced routes\n"
15376 "Packet queue\n")
15377{
15378 uint64_t subgrp_id = 0;
15379 afi_t afiz;
15380 safi_t safiz;
15381 if (sgid)
15382 subgrp_id = strtoull(sgid, NULL, 10);
15383
15384 if (!ip && !afi)
15385 afiz = AFI_IP6;
15386 if (!ip && afi)
15387 afiz = bgp_vty_afi_from_str(afi);
15388 if (ip && !afi)
15389 afiz = AFI_IP;
15390 if (ip && afi) {
15391 afiz = bgp_vty_afi_from_str(afi);
15392 if (afiz != AFI_IP)
15393 vty_out(vty,
15394 "%% Cannot specify both 'ip' and 'ipv6'\n");
15395 return CMD_WARNING;
15396 }
15397
15398 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
15399
15400 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
15401 return CMD_SUCCESS;
15402}
15403
15404static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
15405{
15406 struct listnode *node, *nnode;
15407 struct prefix *range;
15408 struct peer *conf;
15409 struct peer *peer;
15410 afi_t afi;
15411 safi_t safi;
15412 const char *peer_status;
15413 const char *af_str;
15414 int lr_count;
15415 int dynamic;
15416 int af_cfgd;
15417
15418 conf = group->conf;
15419
15420 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
15421 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15422 group->name, conf->as);
15423 } else if (conf->as_type == AS_INTERNAL) {
15424 vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
15425 group->name, group->bgp->as);
15426 } else {
15427 vty_out(vty, "\nBGP peer-group %s\n", group->name);
15428 }
15429
15430 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
15431 vty_out(vty, " Peer-group type is internal\n");
15432 else
15433 vty_out(vty, " Peer-group type is external\n");
15434
15435 /* Display AFs configured. */
15436 vty_out(vty, " Configured address-families:");
15437 FOREACH_AFI_SAFI (afi, safi) {
15438 if (conf->afc[afi][safi]) {
15439 af_cfgd = 1;
15440 vty_out(vty, " %s;", get_afi_safi_str(afi, safi, false));
15441 }
15442 }
15443 if (!af_cfgd)
15444 vty_out(vty, " none\n");
15445 else
15446 vty_out(vty, "\n");
15447
15448 /* Display listen ranges (for dynamic neighbors), if any */
15449 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
15450 if (afi == AFI_IP)
15451 af_str = "IPv4";
15452 else if (afi == AFI_IP6)
15453 af_str = "IPv6";
15454 else
15455 af_str = "???";
15456 lr_count = listcount(group->listen_range[afi]);
15457 if (lr_count) {
15458 vty_out(vty, " %d %s listen range(s)\n", lr_count,
15459 af_str);
15460
15461
15462 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
15463 nnode, range))
15464 vty_out(vty, " %pFX\n", range);
15465 }
15466 }
15467
15468 /* Display group members and their status */
15469 if (listcount(group->peer)) {
15470 vty_out(vty, " Peer-group members:\n");
15471 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
15472 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)
15473 || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHUTDOWN))
15474 peer_status = "Idle (Admin)";
15475 else if (CHECK_FLAG(peer->sflags,
15476 PEER_STATUS_PREFIX_OVERFLOW))
15477 peer_status = "Idle (PfxCt)";
15478 else
15479 peer_status = lookup_msg(bgp_status_msg,
15480 peer->status, NULL);
15481
15482 dynamic = peer_dynamic_neighbor(peer);
15483 vty_out(vty, " %s %s %s \n", peer->host,
15484 dynamic ? "(dynamic)" : "", peer_status);
15485 }
15486 }
15487
15488 return CMD_SUCCESS;
15489}
15490
15491static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
15492 const char *group_name)
15493{
15494 struct bgp *bgp;
15495 struct listnode *node, *nnode;
15496 struct peer_group *group;
15497 bool found = false;
15498
15499 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
15500
15501 if (!bgp) {
15502 vty_out(vty, "%% BGP instance not found\n");
15503 return CMD_WARNING;
15504 }
15505
15506 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
15507 if (group_name) {
15508 if (strmatch(group->name, group_name)) {
15509 bgp_show_one_peer_group(vty, group);
15510 found = true;
15511 break;
15512 }
15513 } else {
15514 bgp_show_one_peer_group(vty, group);
15515 }
15516 }
15517
15518 if (group_name && !found)
15519 vty_out(vty, "%% No such peer-group\n");
15520
15521 return CMD_SUCCESS;
15522}
15523
15524DEFUN (show_ip_bgp_peer_groups,
15525 show_ip_bgp_peer_groups_cmd,
15526 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
15527 SHOW_STR
15528 IP_STR
15529 BGP_STR
15530 BGP_INSTANCE_HELP_STR
15531 "Detailed information on BGP peer groups\n"
15532 "Peer group name\n")
15533{
15534 char *vrf, *pg;
15535 int idx = 0;
15536
15537 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
15538 : NULL;
15539 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
15540
15541 return bgp_show_peer_group_vty(vty, vrf, pg);
15542}
15543
15544
15545/* Redistribute VTY commands. */
15546
15547DEFUN_YANG (bgp_redistribute_ipv4,
15548 bgp_redistribute_ipv4_cmd,
15549 "redistribute " FRR_IP_REDIST_STR_BGPD,
15550 "Redistribute information from another routing protocol\n"
15551 FRR_IP_REDIST_HELP_STR_BGPD)
15552{
15553 int idx_protocol = 1;
15554 char base_xpath[XPATH_MAXLEN];
15555
15556 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15557 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15558 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15559 argv[idx_protocol]->text, "0");
15560
15561 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15562
15563 return nb_cli_apply_changes(vty, base_xpath);
15564}
15565
15566ALIAS_HIDDEN(
15567 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
15568 "redistribute " FRR_IP_REDIST_STR_BGPD,
15569 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
15570
15571DEFUN_YANG (bgp_redistribute_ipv4_rmap,
15572 bgp_redistribute_ipv4_rmap_cmd,
15573 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15574 "Redistribute information from another routing protocol\n"
15575 FRR_IP_REDIST_HELP_STR_BGPD
15576 "Route map reference\n"
15577 "Pointer to route-map entries\n")
15578{
15579 int idx_protocol = 1;
15580 int idx_word = 3;
15581 char base_xpath[XPATH_MAXLEN];
15582
15583 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15584 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15585 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15586 argv[idx_protocol]->text, "0");
15587
15588 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15589 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15590 argv[idx_word]->arg);
15591
15592 return nb_cli_apply_changes(vty, base_xpath);
15593}
15594
15595ALIAS_HIDDEN(
15596 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
15597 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
15598 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15599 "Route map reference\n"
15600 "Pointer to route-map entries\n")
15601
15602DEFUN_YANG (bgp_redistribute_ipv4_metric,
15603 bgp_redistribute_ipv4_metric_cmd,
15604 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15605 "Redistribute information from another routing protocol\n"
15606 FRR_IP_REDIST_HELP_STR_BGPD
15607 "Metric for redistributed routes\n"
15608 "Default metric\n")
15609{
15610 int idx_protocol = 1;
15611 int idx_number = 3;
15612 char base_xpath[XPATH_MAXLEN];
15613
15614 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15615 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15616 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15617 argv[idx_protocol]->text, "0");
15618
15619 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15620 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15621 argv[idx_number]->arg);
15622
15623 return nb_cli_apply_changes(vty, base_xpath);
15624}
15625
15626ALIAS_HIDDEN(
15627 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
15628 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
15629 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15630 "Metric for redistributed routes\n"
15631 "Default metric\n")
15632
15633DEFUN_YANG(
15634 bgp_redistribute_ipv4_rmap_metric,
15635 bgp_redistribute_ipv4_rmap_metric_cmd,
15636 "redistribute " FRR_IP_REDIST_STR_BGPD
15637 " route-map WORD metric (0-4294967295)",
15638 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15639 "Route map reference\n"
15640 "Pointer to route-map entries\n"
15641 "Metric for redistributed routes\n"
15642 "Default metric\n")
15643{
15644 int idx_protocol = 1;
15645 int idx_word = 3;
15646 int idx_number = 5;
15647 char base_xpath[XPATH_MAXLEN];
15648
15649 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15650 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15651 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15652 argv[idx_protocol]->text, "0");
15653
15654 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15655 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15656 argv[idx_word]->arg);
15657 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15658 argv[idx_number]->arg);
15659
15660 return nb_cli_apply_changes(vty, base_xpath);
15661}
15662
15663ALIAS_HIDDEN(
15664 bgp_redistribute_ipv4_rmap_metric,
15665 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
15666 "redistribute " FRR_IP_REDIST_STR_BGPD
15667 " route-map WORD metric (0-4294967295)",
15668 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15669 "Route map reference\n"
15670 "Pointer to route-map entries\n"
15671 "Metric for redistributed routes\n"
15672 "Default metric\n")
15673
15674DEFUN_YANG(
15675 bgp_redistribute_ipv4_metric_rmap,
15676 bgp_redistribute_ipv4_metric_rmap_cmd,
15677 "redistribute " FRR_IP_REDIST_STR_BGPD
15678 " metric (0-4294967295) route-map WORD",
15679 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15680 "Metric for redistributed routes\n"
15681 "Default metric\n"
15682 "Route map reference\n"
15683 "Pointer to route-map entries\n")
15684{
15685 int idx_protocol = 1;
15686 int idx_word = 5;
15687 int idx_number = 3;
15688 char base_xpath[XPATH_MAXLEN];
15689
15690 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15691 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15692 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15693 argv[idx_protocol]->text, "0");
15694
15695 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15696 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15697 argv[idx_number]->arg);
15698 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15699 argv[idx_word]->arg);
15700
15701 return nb_cli_apply_changes(vty, base_xpath);
15702}
15703
15704ALIAS_HIDDEN(
15705 bgp_redistribute_ipv4_metric_rmap,
15706 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
15707 "redistribute " FRR_IP_REDIST_STR_BGPD
15708 " metric (0-4294967295) route-map WORD",
15709 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15710 "Metric for redistributed routes\n"
15711 "Default metric\n"
15712 "Route map reference\n"
15713 "Pointer to route-map entries\n")
15714
15715DEFUN_YANG (bgp_redistribute_ipv4_ospf,
15716 bgp_redistribute_ipv4_ospf_cmd,
15717 "redistribute <ospf|table> (1-65535)",
15718 "Redistribute information from another routing protocol\n"
15719 "Open Shortest Path First (OSPFv2)\n"
15720 "Non-main Kernel Routing Table\n"
15721 "Instance ID/Table ID\n")
15722{
15723 int idx_protocol = 1;
15724 int idx_number = 2;
15725 char base_xpath[XPATH_MAXLEN];
15726
15727 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15728 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15729 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15730 argv[idx_protocol]->text, argv[idx_number]->arg);
15731
15732 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15733
15734 return nb_cli_apply_changes(vty, base_xpath);
15735}
15736
15737ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
15738 "redistribute <ospf|table> (1-65535)",
15739 "Redistribute information from another routing protocol\n"
15740 "Open Shortest Path First (OSPFv2)\n"
15741 "Non-main Kernel Routing Table\n"
15742 "Instance ID/Table ID\n")
15743
15744DEFUN_YANG (bgp_redistribute_ipv4_ospf_rmap,
15745 bgp_redistribute_ipv4_ospf_rmap_cmd,
15746 "redistribute <ospf|table> (1-65535) route-map WORD",
15747 "Redistribute information from another routing protocol\n"
15748 "Open Shortest Path First (OSPFv2)\n"
15749 "Non-main Kernel Routing Table\n"
15750 "Instance ID/Table ID\n"
15751 "Route map reference\n"
15752 "Pointer to route-map entries\n")
15753{
15754 int idx_protocol = 1;
15755 int idx_number = 2;
15756 int idx_word = 4;
15757 char base_xpath[XPATH_MAXLEN];
15758
15759 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15760 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15761 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15762 argv[idx_protocol]->text, argv[idx_number]->arg);
15763
15764 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15765
15766 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15767 argv[idx_word]->arg);
15768
15769 return nb_cli_apply_changes(vty, base_xpath);
15770}
15771
15772ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
15773 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
15774 "redistribute <ospf|table> (1-65535) route-map WORD",
15775 "Redistribute information from another routing protocol\n"
15776 "Open Shortest Path First (OSPFv2)\n"
15777 "Non-main Kernel Routing Table\n"
15778 "Instance ID/Table ID\n"
15779 "Route map reference\n"
15780 "Pointer to route-map entries\n")
15781
15782DEFUN_YANG(bgp_redistribute_ipv4_ospf_metric,
15783 bgp_redistribute_ipv4_ospf_metric_cmd,
15784 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15785 "Redistribute information from another routing protocol\n"
15786 "Open Shortest Path First (OSPFv2)\n"
15787 "Non-main Kernel Routing Table\n"
15788 "Instance ID/Table ID\n"
15789 "Metric for redistributed routes\n"
15790 "Default metric\n")
15791{
15792 int idx_protocol = 1;
15793 int idx_number = 2;
15794 int idx_number_2 = 4;
15795 char base_xpath[XPATH_MAXLEN];
15796
15797 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15798 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15799 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15800 argv[idx_protocol]->text, argv[idx_number]->arg);
15801
15802 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15803
15804 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15805 argv[idx_number_2]->arg);
15806
15807 return nb_cli_apply_changes(vty, base_xpath);
15808}
15809
15810ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
15811 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
15812 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
15813 "Redistribute information from another routing protocol\n"
15814 "Open Shortest Path First (OSPFv2)\n"
15815 "Non-main Kernel Routing Table\n"
15816 "Instance ID/Table ID\n"
15817 "Metric for redistributed routes\n"
15818 "Default metric\n")
15819
15820DEFUN_YANG(
15821 bgp_redistribute_ipv4_ospf_rmap_metric,
15822 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
15823 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15824 "Redistribute information from another routing protocol\n"
15825 "Open Shortest Path First (OSPFv2)\n"
15826 "Non-main Kernel Routing Table\n"
15827 "Instance ID/Table ID\n"
15828 "Route map reference\n"
15829 "Pointer to route-map entries\n"
15830 "Metric for redistributed routes\n"
15831 "Default metric\n")
15832{
15833 int idx_protocol = 1;
15834 int idx_number = 2;
15835 int idx_word = 4;
15836 int idx_number_2 = 6;
15837 char base_xpath[XPATH_MAXLEN];
15838
15839 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15840 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15841 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15842 argv[idx_protocol]->text, argv[idx_number]->arg);
15843
15844 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15845
15846 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15847 argv[idx_word]->arg);
15848 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15849 argv[idx_number_2]->arg);
15850
15851 return nb_cli_apply_changes(vty, base_xpath);
15852}
15853
15854ALIAS_HIDDEN(
15855 bgp_redistribute_ipv4_ospf_rmap_metric,
15856 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
15857 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
15858 "Redistribute information from another routing protocol\n"
15859 "Open Shortest Path First (OSPFv2)\n"
15860 "Non-main Kernel Routing Table\n"
15861 "Instance ID/Table ID\n"
15862 "Route map reference\n"
15863 "Pointer to route-map entries\n"
15864 "Metric for redistributed routes\n"
15865 "Default metric\n")
15866
15867DEFUN_YANG(
15868 bgp_redistribute_ipv4_ospf_metric_rmap,
15869 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
15870 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15871 "Redistribute information from another routing protocol\n"
15872 "Open Shortest Path First (OSPFv2)\n"
15873 "Non-main Kernel Routing Table\n"
15874 "Instance ID/Table ID\n"
15875 "Metric for redistributed routes\n"
15876 "Default metric\n"
15877 "Route map reference\n"
15878 "Pointer to route-map entries\n")
15879{
15880 int idx_protocol = 1;
15881 int idx_number = 2;
15882 int idx_number_2 = 4;
15883 int idx_word = 6;
15884 char base_xpath[XPATH_MAXLEN];
15885
15886 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15887 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15888 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15889 argv[idx_protocol]->text, argv[idx_number]->arg);
15890
15891 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
15892
15893 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
15894 argv[idx_number_2]->arg);
15895 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
15896 argv[idx_word]->arg);
15897
15898 return nb_cli_apply_changes(vty, base_xpath);
15899}
15900
15901ALIAS_HIDDEN(
15902 bgp_redistribute_ipv4_ospf_metric_rmap,
15903 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
15904 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
15905 "Redistribute information from another routing protocol\n"
15906 "Open Shortest Path First (OSPFv2)\n"
15907 "Non-main Kernel Routing Table\n"
15908 "Instance ID/Table ID\n"
15909 "Metric for redistributed routes\n"
15910 "Default metric\n"
15911 "Route map reference\n"
15912 "Pointer to route-map entries\n")
15913
15914DEFUN_YANG (no_bgp_redistribute_ipv4_ospf,
15915 no_bgp_redistribute_ipv4_ospf_cmd,
15916 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15917 NO_STR
15918 "Redistribute information from another routing protocol\n"
15919 "Open Shortest Path First (OSPFv2)\n"
15920 "Non-main Kernel Routing Table\n"
15921 "Instance ID/Table ID\n"
15922 "Metric for redistributed routes\n"
15923 "Default metric\n"
15924 "Route map reference\n"
15925 "Pointer to route-map entries\n")
15926{
15927 int idx_protocol = 2;
15928 int idx_number = 3;
15929 char base_xpath[XPATH_MAXLEN];
15930
15931 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15932 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15933 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15934 argv[idx_protocol]->text, argv[idx_number]->arg);
15935
15936 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15937
15938 return nb_cli_apply_changes(vty, base_xpath);
15939}
15940
15941ALIAS_HIDDEN(
15942 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
15943 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
15944 NO_STR
15945 "Redistribute information from another routing protocol\n"
15946 "Open Shortest Path First (OSPFv2)\n"
15947 "Non-main Kernel Routing Table\n"
15948 "Instance ID/Table ID\n"
15949 "Metric for redistributed routes\n"
15950 "Default metric\n"
15951 "Route map reference\n"
15952 "Pointer to route-map entries\n")
15953
15954DEFUN_YANG (no_bgp_redistribute_ipv4,
15955 no_bgp_redistribute_ipv4_cmd,
15956 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
15957 NO_STR
15958 "Redistribute information from another routing protocol\n"
15959 FRR_IP_REDIST_HELP_STR_BGPD
15960 "Metric for redistributed routes\n"
15961 "Default metric\n"
15962 "Route map reference\n"
15963 "Pointer to route-map entries\n")
15964{
15965 int idx_protocol = 2;
15966 char base_xpath[XPATH_MAXLEN];
15967
15968 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15969 yang_afi_safi_value2identity(AFI_IP, SAFI_UNICAST),
15970 bgp_afi_safi_get_container_str(AFI_IP, SAFI_UNICAST),
15971 argv[idx_protocol]->text, "0");
15972
15973 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
15974
15975 return nb_cli_apply_changes(vty, base_xpath);
15976}
15977
15978ALIAS_HIDDEN(
15979 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
15980 "no redistribute " FRR_IP_REDIST_STR_BGPD
15981 " [{metric (0-4294967295)|route-map WORD}]",
15982 NO_STR
15983 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
15984 "Metric for redistributed routes\n"
15985 "Default metric\n"
15986 "Route map reference\n"
15987 "Pointer to route-map entries\n")
15988
15989DEFUN_YANG (bgp_redistribute_ipv6,
15990 bgp_redistribute_ipv6_cmd,
15991 "redistribute " FRR_IP6_REDIST_STR_BGPD,
15992 "Redistribute information from another routing protocol\n"
15993 FRR_IP6_REDIST_HELP_STR_BGPD)
15994{
15995 int idx_protocol = 1;
15996 char base_xpath[XPATH_MAXLEN];
15997
15998 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
15999 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16000 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16001 argv[idx_protocol]->text, "0");
16002
16003 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16004
16005 return nb_cli_apply_changes(vty, base_xpath);
16006}
16007
16008DEFUN_YANG (bgp_redistribute_ipv6_rmap,
16009 bgp_redistribute_ipv6_rmap_cmd,
16010 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
16011 "Redistribute information from another routing protocol\n"
16012 FRR_IP6_REDIST_HELP_STR_BGPD
16013 "Route map reference\n"
16014 "Pointer to route-map entries\n")
16015{
16016 int idx_protocol = 1;
16017 int idx_word = 3;
16018 char base_xpath[XPATH_MAXLEN];
16019
16020 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16021 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16022 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16023 argv[idx_protocol]->text, "0");
16024
16025 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16026 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16027 argv[idx_word]->arg);
16028
16029 return nb_cli_apply_changes(vty, base_xpath);
16030}
16031
16032DEFUN_YANG (bgp_redistribute_ipv6_metric,
16033 bgp_redistribute_ipv6_metric_cmd,
16034 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
16035 "Redistribute information from another routing protocol\n"
16036 FRR_IP6_REDIST_HELP_STR_BGPD
16037 "Metric for redistributed routes\n"
16038 "Default metric\n")
16039{
16040 int idx_protocol = 1;
16041 int idx_number = 3;
16042 char base_xpath[XPATH_MAXLEN];
16043
16044 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16045 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16046 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16047 argv[idx_protocol]->text, "0");
16048
16049 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16050 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16051 argv[idx_number]->arg);
16052
16053 return nb_cli_apply_changes(vty, base_xpath);
16054}
16055
16056DEFUN_YANG(
16057 bgp_redistribute_ipv6_rmap_metric,
16058 bgp_redistribute_ipv6_rmap_metric_cmd,
16059 "redistribute " FRR_IP6_REDIST_STR_BGPD
16060 " route-map WORD metric (0-4294967295)",
16061 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16062 "Route map reference\n"
16063 "Pointer to route-map entries\n"
16064 "Metric for redistributed routes\n"
16065 "Default metric\n")
16066{
16067 int idx_protocol = 1;
16068 int idx_word = 3;
16069 int idx_number = 5;
16070 char base_xpath[XPATH_MAXLEN];
16071
16072 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16073 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16074 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16075 argv[idx_protocol]->text, "0");
16076
16077 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16078 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16079 argv[idx_word]->arg);
16080 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16081 argv[idx_number]->arg);
16082
16083 return nb_cli_apply_changes(vty, base_xpath);
16084}
16085
16086DEFUN_YANG(
16087 bgp_redistribute_ipv6_metric_rmap,
16088 bgp_redistribute_ipv6_metric_rmap_cmd,
16089 "redistribute " FRR_IP6_REDIST_STR_BGPD
16090 " metric (0-4294967295) route-map WORD",
16091 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16092 "Metric for redistributed routes\n"
16093 "Default metric\n"
16094 "Route map reference\n"
16095 "Pointer to route-map entries\n")
16096{
16097 int idx_protocol = 1;
16098 int idx_word = 5;
16099 int idx_number = 3;
16100 char base_xpath[XPATH_MAXLEN];
16101
16102 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16103 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16104 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16105 argv[idx_protocol]->text, "0");
16106
16107 nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
16108 nb_cli_enqueue_change(vty, "./metric", NB_OP_CREATE,
16109 argv[idx_number]->arg);
16110 nb_cli_enqueue_change(vty, "./rmap-policy-import", NB_OP_CREATE,
16111 argv[idx_word]->arg);
16112
16113 return nb_cli_apply_changes(vty, base_xpath);
16114}
16115
16116DEFUN_YANG(
16117 no_bgp_redistribute_ipv6,
16118 no_bgp_redistribute_ipv6_cmd,
16119 "no redistribute " FRR_IP6_REDIST_STR_BGPD
16120 " [{metric (0-4294967295)|route-map WORD}]",
16121 NO_STR
16122 "Redistribute information from another routing protocol\n" FRR_IP6_REDIST_HELP_STR_BGPD
16123 "Metric for redistributed routes\n"
16124 "Default metric\n"
16125 "Route map reference\n"
16126 "Pointer to route-map entries\n")
16127{
16128 int idx_protocol = 2;
16129 char base_xpath[XPATH_MAXLEN];
16130
16131 snprintf(base_xpath, sizeof(base_xpath), FRR_BGP_AFI_SAFI_REDIST_XPATH,
16132 yang_afi_safi_value2identity(AFI_IP6, SAFI_UNICAST),
16133 bgp_afi_safi_get_container_str(AFI_IP6, SAFI_UNICAST),
16134 argv[idx_protocol]->text, "0");
16135
16136 nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
16137
16138 return nb_cli_apply_changes(vty, base_xpath);
16139}
16140
16141void cli_show_bgp_global_afi_safi_ip_unicast_redistribution_list(
16142 struct vty *vty, struct lyd_node *dnode, bool show_defaults)
16143{
16144 uint32_t instance = 0;
16145
16146 vty_out(vty, " redistribute %s",
16147 yang_dnode_get_string(dnode, "./route-type"));
16148 if ((instance = yang_dnode_get_uint16(dnode, "./route-instance")))
16149 vty_out(vty, " %d", instance);
16150 if (yang_dnode_exists(dnode, "./metric"))
16151 vty_out(vty, " metric %u",
16152 yang_dnode_get_uint32(dnode, "./metric"));
16153 if (yang_dnode_exists(dnode, "./rmap-policy-import"))
16154 vty_out(vty, " route-map %s",
16155 yang_dnode_get_string(dnode, "./rmap-policy-import"));
16156 vty_out(vty, "\n");
16157}
16158
16159static void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp,
16160 afi_t afi, safi_t safi)
16161{
16162 int i;
16163
16164 /* Unicast redistribution only. */
16165 if (safi != SAFI_UNICAST)
16166 return;
16167
16168 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
16169 /* Redistribute BGP does not make sense. */
16170 if (i != ZEBRA_ROUTE_BGP) {
16171 struct list *red_list;
16172 struct listnode *node;
16173 struct bgp_redist *red;
16174
16175 red_list = bgp->redist[afi][i];
16176 if (!red_list)
16177 continue;
16178
16179 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
16180 /* "redistribute" configuration. */
16181 vty_out(vty, " redistribute %s",
16182 zebra_route_string(i));
16183 if (red->instance)
16184 vty_out(vty, " %d", red->instance);
16185 if (red->redist_metric_flag)
16186 vty_out(vty, " metric %u",
16187 red->redist_metric);
16188 if (red->rmap.name)
16189 vty_out(vty, " route-map %s",
16190 red->rmap.name);
16191 vty_out(vty, "\n");
16192 }
16193 }
16194 }
16195}
16196
16197/* peer-group helpers for config-write */
16198
16199static bool peergroup_flag_check(struct peer *peer, uint32_t flag)
16200{
16201 if (!peer_group_active(peer)) {
16202 if (CHECK_FLAG(peer->flags_invert, flag))
16203 return !CHECK_FLAG(peer->flags, flag);
16204 else
16205 return !!CHECK_FLAG(peer->flags, flag);
16206 }
16207
16208 return !!CHECK_FLAG(peer->flags_override, flag);
16209}
16210
16211static bool peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi,
16212 uint32_t flag)
16213{
16214 if (!peer_group_active(peer)) {
16215 if (CHECK_FLAG(peer->af_flags_invert[afi][safi], flag))
16216 return !peer_af_flag_check(peer, afi, safi, flag);
16217 else
16218 return !!peer_af_flag_check(peer, afi, safi, flag);
16219 }
16220
16221 return !!CHECK_FLAG(peer->af_flags_override[afi][safi], flag);
16222}
16223
16224static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
16225 uint8_t type, int direct)
16226{
16227 struct bgp_filter *filter;
16228
16229 if (peer_group_active(peer))
16230 return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
16231 type);
16232
16233 filter = &peer->filter[afi][safi];
16234 switch (type) {
16235 case PEER_FT_DISTRIBUTE_LIST:
16236 return !!(filter->dlist[direct].name);
16237 case PEER_FT_FILTER_LIST:
16238 return !!(filter->aslist[direct].name);
16239 case PEER_FT_PREFIX_LIST:
16240 return !!(filter->plist[direct].name);
16241 case PEER_FT_ROUTE_MAP:
16242 return !!(filter->map[direct].name);
16243 case PEER_FT_UNSUPPRESS_MAP:
16244 return !!(filter->usmap.name);
16245 case PEER_FT_ADVERTISE_MAP:
16246 return !!(filter->advmap.aname
16247 && ((filter->advmap.condition == direct)
16248 && filter->advmap.cname));
16249 default:
16250 return false;
16251 }
16252}
16253
16254/* Return true if the addpath type is set for peer and different from
16255 * peer-group.
16256 */
16257static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi,
16258 safi_t safi)
16259{
16260 enum bgp_addpath_strat type, g_type;
16261
16262 type = peer->addpath_type[afi][safi];
16263
16264 if (type != BGP_ADDPATH_NONE) {
16265 if (peer_group_active(peer)) {
16266 g_type = peer->group->conf->addpath_type[afi][safi];
16267
16268 if (type != g_type)
16269 return true;
16270 else
16271 return false;
16272 }
16273
16274 return true;
16275 }
16276
16277 return false;
16278}
16279
16280/* This is part of the address-family block (unicast only) */
16281static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
16282 afi_t afi)
16283{
16284 int indent = 2;
16285
16286 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
16287 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16288 BGP_CONFIG_VRF_TO_VRF_IMPORT))
16289 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
16290 bgp->vpn_policy[afi]
16291 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16292 else
16293 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
16294 bgp->vpn_policy[afi]
16295 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
16296 }
16297 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16298 BGP_CONFIG_VRF_TO_VRF_IMPORT)
16299 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
16300 BGP_CONFIG_VRF_TO_VRF_EXPORT))
16301 return;
16302
16303 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16304 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
16305
16306 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
16307
16308 } else {
16309 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
16310 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
16311 bgp->vpn_policy[afi].tovpn_label);
16312 }
16313 }
16314 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16315 BGP_VPN_POLICY_TOVPN_RD_SET)) {
16316 char buf[RD_ADDRSTRLEN];
16317 vty_out(vty, "%*srd vpn export %s\n", indent, "",
16318 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
16319 sizeof(buf)));
16320 }
16321 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
16322 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
16323
16324 char buf[PREFIX_STRLEN];
16325 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
16326 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
16327 sizeof(buf))) {
16328
16329 vty_out(vty, "%*snexthop vpn export %s\n",
16330 indent, "", buf);
16331 }
16332 }
16333 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
16334 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
16335 && ecommunity_cmp(
16336 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16337 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
16338
16339 char *b = ecommunity_ecom2str(
16340 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16341 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
16342 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
16343 XFREE(MTYPE_ECOMMUNITY_STR, b);
16344 } else {
16345 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
16346 char *b = ecommunity_ecom2str(
16347 bgp->vpn_policy[afi]
16348 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
16349 ECOMMUNITY_FORMAT_ROUTE_MAP,
16350 ECOMMUNITY_ROUTE_TARGET);
16351 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
16352 XFREE(MTYPE_ECOMMUNITY_STR, b);
16353 }
16354 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
16355 char *b = ecommunity_ecom2str(
16356 bgp->vpn_policy[afi]
16357 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
16358 ECOMMUNITY_FORMAT_ROUTE_MAP,
16359 ECOMMUNITY_ROUTE_TARGET);
16360 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
16361 XFREE(MTYPE_ECOMMUNITY_STR, b);
16362 }
16363 }
16364
16365 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
16366 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
16367 bgp->vpn_policy[afi]
16368 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
16369
16370 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
16371 char *b = ecommunity_ecom2str(
16372 bgp->vpn_policy[afi]
16373 .import_redirect_rtlist,
16374 ECOMMUNITY_FORMAT_ROUTE_MAP,
16375 ECOMMUNITY_ROUTE_TARGET);
16376
16377 if (bgp->vpn_policy[afi].import_redirect_rtlist->unit_size
16378 != ECOMMUNITY_SIZE)
16379 vty_out(vty, "%*srt6 redirect import %s\n",
16380 indent, "", b);
16381 else
16382 vty_out(vty, "%*srt redirect import %s\n",
16383 indent, "", b);
16384 XFREE(MTYPE_ECOMMUNITY_STR, b);
16385 }
16386}
16387
16388static void bgp_config_write_filter(struct vty *vty, struct peer *peer,
16389 afi_t afi, safi_t safi)
16390{
16391 struct bgp_filter *filter;
16392 char *addr;
16393
16394 addr = peer->host;
16395 filter = &peer->filter[afi][safi];
16396
16397 /* distribute-list. */
16398 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16399 FILTER_IN))
16400 vty_out(vty, " neighbor %s distribute-list %s in\n", addr,
16401 filter->dlist[FILTER_IN].name);
16402
16403 if (peergroup_filter_check(peer, afi, safi, PEER_FT_DISTRIBUTE_LIST,
16404 FILTER_OUT))
16405 vty_out(vty, " neighbor %s distribute-list %s out\n", addr,
16406 filter->dlist[FILTER_OUT].name);
16407
16408 /* prefix-list. */
16409 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16410 FILTER_IN))
16411 vty_out(vty, " neighbor %s prefix-list %s in\n", addr,
16412 filter->plist[FILTER_IN].name);
16413
16414 if (peergroup_filter_check(peer, afi, safi, PEER_FT_PREFIX_LIST,
16415 FILTER_OUT))
16416 vty_out(vty, " neighbor %s prefix-list %s out\n", addr,
16417 filter->plist[FILTER_OUT].name);
16418
16419 /* route-map. */
16420 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP, RMAP_IN))
16421 vty_out(vty, " neighbor %s route-map %s in\n", addr,
16422 filter->map[RMAP_IN].name);
16423
16424 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ROUTE_MAP,
16425 RMAP_OUT))
16426 vty_out(vty, " neighbor %s route-map %s out\n", addr,
16427 filter->map[RMAP_OUT].name);
16428
16429 /* unsuppress-map */
16430 if (peergroup_filter_check(peer, afi, safi, PEER_FT_UNSUPPRESS_MAP, 0))
16431 vty_out(vty, " neighbor %s unsuppress-map %s\n", addr,
16432 filter->usmap.name);
16433
16434 /* advertise-map : always applied in OUT direction*/
16435 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16436 CONDITION_NON_EXIST))
16437 vty_out(vty,
16438 " neighbor %s advertise-map %s non-exist-map %s\n",
16439 addr, filter->advmap.aname, filter->advmap.cname);
16440
16441 if (peergroup_filter_check(peer, afi, safi, PEER_FT_ADVERTISE_MAP,
16442 CONDITION_EXIST))
16443 vty_out(vty, " neighbor %s advertise-map %s exist-map %s\n",
16444 addr, filter->advmap.aname, filter->advmap.cname);
16445
16446 /* filter-list. */
16447 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16448 FILTER_IN))
16449 vty_out(vty, " neighbor %s filter-list %s in\n", addr,
16450 filter->aslist[FILTER_IN].name);
16451
16452 if (peergroup_filter_check(peer, afi, safi, PEER_FT_FILTER_LIST,
16453 FILTER_OUT))
16454 vty_out(vty, " neighbor %s filter-list %s out\n", addr,
16455 filter->aslist[FILTER_OUT].name);
16456}
16457
16458/* BGP peer configuration display function. */
16459static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
16460 struct peer *peer)
16461{
16462 struct peer *g_peer = NULL;
16463 char buf[SU_ADDRSTRLEN];
16464 char *addr;
16465 int if_pg_printed = false;
16466 int if_ras_printed = false;
16467
16468 /* Skip dynamic neighbors. */
16469 if (peer_dynamic_neighbor(peer))
16470 return;
16471
16472 if (peer->conf_if)
16473 addr = peer->conf_if;
16474 else
16475 addr = peer->host;
16476
16477 /************************************
16478 ****** Global to the neighbor ******
16479 ************************************/
16480 if (peer->conf_if) {
16481 if (CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
16482 vty_out(vty, " neighbor %s interface v6only", addr);
16483 else
16484 vty_out(vty, " neighbor %s interface", addr);
16485
16486 if (peer_group_active(peer)) {
16487 vty_out(vty, " peer-group %s", peer->group->name);
16488 if_pg_printed = true;
16489 } else if (peer->as_type == AS_SPECIFIED) {
16490 vty_out(vty, " remote-as %u", peer->as);
16491 if_ras_printed = true;
16492 } else if (peer->as_type == AS_INTERNAL) {
16493 vty_out(vty, " remote-as internal");
16494 if_ras_printed = true;
16495 } else if (peer->as_type == AS_EXTERNAL) {
16496 vty_out(vty, " remote-as external");
16497 if_ras_printed = true;
16498 }
16499
16500 vty_out(vty, "\n");
16501 }
16502
16503 /* remote-as and peer-group */
16504 /* peer is a member of a peer-group */
16505 if (peer_group_active(peer)) {
16506 g_peer = peer->group->conf;
16507
16508 if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
16509 if (peer->as_type == AS_SPECIFIED) {
16510 vty_out(vty, " neighbor %s remote-as %u\n",
16511 addr, peer->as);
16512 } else if (peer->as_type == AS_INTERNAL) {
16513 vty_out(vty,
16514 " neighbor %s remote-as internal\n",
16515 addr);
16516 } else if (peer->as_type == AS_EXTERNAL) {
16517 vty_out(vty,
16518 " neighbor %s remote-as external\n",
16519 addr);
16520 }
16521 }
16522
16523 /* For swpX peers we displayed the peer-group
16524 * via 'neighbor swpX interface peer-group PGNAME' */
16525 if (!if_pg_printed)
16526 vty_out(vty, " neighbor %s peer-group %s\n", addr,
16527 peer->group->name);
16528 }
16529
16530 /* peer is NOT a member of a peer-group */
16531 else {
16532 /* peer is a peer-group, declare the peer-group */
16533 if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
16534 vty_out(vty, " neighbor %s peer-group\n", addr);
16535 }
16536
16537 if (!if_ras_printed) {
16538 if (peer->as_type == AS_SPECIFIED) {
16539 vty_out(vty, " neighbor %s remote-as %u\n",
16540 addr, peer->as);
16541 } else if (peer->as_type == AS_INTERNAL) {
16542 vty_out(vty,
16543 " neighbor %s remote-as internal\n",
16544 addr);
16545 } else if (peer->as_type == AS_EXTERNAL) {
16546 vty_out(vty,
16547 " neighbor %s remote-as external\n",
16548 addr);
16549 }
16550 }
16551 }
16552
16553 /* local-as */
16554 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
16555 vty_out(vty, " neighbor %s local-as %u", addr,
16556 peer->change_local_as);
16557 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
16558 vty_out(vty, " no-prepend");
16559 if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
16560 vty_out(vty, " replace-as");
16561 vty_out(vty, "\n");
16562 }
16563
16564 /* description */
16565 if (peer->desc) {
16566 vty_out(vty, " neighbor %s description %s\n", addr, peer->desc);
16567 }
16568
16569 /* shutdown */
16570 if (peergroup_flag_check(peer, PEER_FLAG_SHUTDOWN)) {
16571 if (peer->tx_shutdown_message)
16572 vty_out(vty, " neighbor %s shutdown message %s\n", addr,
16573 peer->tx_shutdown_message);
16574 else
16575 vty_out(vty, " neighbor %s shutdown\n", addr);
16576 }
16577
16578 if (peergroup_flag_check(peer, PEER_FLAG_RTT_SHUTDOWN))
16579 vty_out(vty, " neighbor %s shutdown rtt %u count %u\n", addr,
16580 peer->rtt_expected, peer->rtt_keepalive_conf);
16581
16582 /* bfd */
16583 if (peer->bfd_info) {
16584 if (!peer_group_active(peer) || !g_peer->bfd_info) {
16585 bgp_bfd_peer_config_write(vty, peer, addr);
16586 }
16587 }
16588
16589 /* password */
16590 if (peergroup_flag_check(peer, PEER_FLAG_PASSWORD))
16591 vty_out(vty, " neighbor %s password %s\n", addr,
16592 peer->password);
16593
16594 /* neighbor solo */
16595 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)) {
16596 if (!peer_group_active(peer)) {
16597 vty_out(vty, " neighbor %s solo\n", addr);
16598 }
16599 }
16600
16601 /* BGP port */
16602 if (peer->port != BGP_PORT_DEFAULT) {
16603 vty_out(vty, " neighbor %s port %d\n", addr, peer->port);
16604 }
16605
16606 /* Local interface name */
16607 if (peer->ifname) {
16608 vty_out(vty, " neighbor %s interface %s\n", addr, peer->ifname);
16609 }
16610
16611 /* passive */
16612 if (peergroup_flag_check(peer, PEER_FLAG_PASSIVE))
16613 vty_out(vty, " neighbor %s passive\n", addr);
16614
16615 /* ebgp-multihop */
16616 if (peer->sort != BGP_PEER_IBGP && peer->ttl != BGP_DEFAULT_TTL
16617 && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED
16618 && peer->ttl == MAXTTL)) {
16619 if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) {
16620 vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr,
16621 peer->ttl);
16622 }
16623 }
16624
16625 /* ttl-security hops */
16626 if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) {
16627 if (!peer_group_active(peer)
16628 || g_peer->gtsm_hops != peer->gtsm_hops) {
16629 vty_out(vty, " neighbor %s ttl-security hops %d\n",
16630 addr, peer->gtsm_hops);
16631 }
16632 }
16633
16634 /* disable-connected-check */
16635 if (peergroup_flag_check(peer, PEER_FLAG_DISABLE_CONNECTED_CHECK))
16636 vty_out(vty, " neighbor %s disable-connected-check\n", addr);
16637
16638 /* enforce-first-as */
16639 if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS))
16640 vty_out(vty, " neighbor %s enforce-first-as\n", addr);
16641
16642 /* update-source */
16643 if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
16644 if (peer->update_source)
16645 vty_out(vty, " neighbor %s update-source %s\n", addr,
16646 sockunion2str(peer->update_source, buf,
16647 SU_ADDRSTRLEN));
16648 else if (peer->update_if)
16649 vty_out(vty, " neighbor %s update-source %s\n", addr,
16650 peer->update_if);
16651 }
16652
16653 /* advertisement-interval */
16654 if (peergroup_flag_check(peer, PEER_FLAG_ROUTEADV))
16655 vty_out(vty, " neighbor %s advertisement-interval %u\n", addr,
16656 peer->routeadv);
16657
16658 /* timers */
16659 if (peergroup_flag_check(peer, PEER_FLAG_TIMER))
16660 vty_out(vty, " neighbor %s timers %u %u\n", addr,
16661 peer->keepalive, peer->holdtime);
16662
16663 /* timers connect */
16664 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_CONNECT))
16665 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16666 peer->connect);
16667 /* need special-case handling for changed default values due to
16668 * config profile / version (because there is no "timers bgp connect"
16669 * command, we need to save this per-peer :/)
16670 */
16671 else if (!peer_group_active(peer) && !peer->connect &&
16672 peer->bgp->default_connect_retry != SAVE_BGP_CONNECT_RETRY)
16673 vty_out(vty, " neighbor %s timers connect %u\n", addr,
16674 peer->bgp->default_connect_retry);
16675
16676 /* timers delayopen */
16677 if (peergroup_flag_check(peer, PEER_FLAG_TIMER_DELAYOPEN))
16678 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16679 peer->delayopen);
16680 /* Save config even though flag is not set if default values have been
16681 * changed
16682 */
16683 else if (!peer_group_active(peer) && !peer->delayopen
16684 && peer->bgp->default_delayopen != BGP_DEFAULT_DELAYOPEN)
16685 vty_out(vty, " neighbor %s timers delayopen %u\n", addr,
16686 peer->bgp->default_delayopen);
16687
16688 /* capability dynamic */
16689 if (peergroup_flag_check(peer, PEER_FLAG_DYNAMIC_CAPABILITY))
16690 vty_out(vty, " neighbor %s capability dynamic\n", addr);
16691
16692 /* capability extended-nexthop */
16693 if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_ENHE)) {
16694 if (!peer->conf_if) {
16695 if (CHECK_FLAG(peer->flags_invert,
16696 PEER_FLAG_CAPABILITY_ENHE))
16697 vty_out(vty,
16698 " no neighbor %s capability extended-nexthop\n",
16699 addr);
16700 else
16701 vty_out(vty,
16702 " neighbor %s capability extended-nexthop\n",
16703 addr);
16704 }
16705 }
16706
16707 /* dont-capability-negotiation */
16708 if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
16709 vty_out(vty, " neighbor %s dont-capability-negotiate\n", addr);
16710
16711 /* override-capability */
16712 if (peergroup_flag_check(peer, PEER_FLAG_OVERRIDE_CAPABILITY))
16713 vty_out(vty, " neighbor %s override-capability\n", addr);
16714
16715 /* strict-capability-match */
16716 if (peergroup_flag_check(peer, PEER_FLAG_STRICT_CAP_MATCH))
16717 vty_out(vty, " neighbor %s strict-capability-match\n", addr);
16718
16719 /* Sender side AS path loop detection. */
16720 if (peer->as_path_loop_detection)
16721 vty_out(vty, " neighbor %s sender-as-path-loop-detection\n",
16722 addr);
16723
16724 if (!CHECK_FLAG(peer->peer_gr_new_status_flag,
16725 PEER_GRACEFUL_RESTART_NEW_STATE_INHERIT)) {
16726
16727 if (CHECK_FLAG(peer->peer_gr_new_status_flag,
16728 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER)) {
16729 vty_out(vty,
16730 " neighbor %s graceful-restart-helper\n", addr);
16731 } else if (CHECK_FLAG(
16732 peer->peer_gr_new_status_flag,
16733 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)) {
16734 vty_out(vty,
16735 " neighbor %s graceful-restart\n", addr);
16736 } else if (
16737 (!(CHECK_FLAG(peer->peer_gr_new_status_flag,
16738 PEER_GRACEFUL_RESTART_NEW_STATE_HELPER))
16739 && !(CHECK_FLAG(
16740 peer->peer_gr_new_status_flag,
16741 PEER_GRACEFUL_RESTART_NEW_STATE_RESTART)))) {
16742 vty_out(vty, " neighbor %s graceful-restart-disable\n",
16743 addr);
16744 }
16745 }
16746}
16747
16748/* BGP peer configuration display function. */
16749static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp,
16750 struct peer *peer, afi_t afi, safi_t safi)
16751{
16752 struct peer *g_peer = NULL;
16753 char *addr;
16754 bool flag_scomm, flag_secomm, flag_slcomm;
16755
16756 /* Skip dynamic neighbors. */
16757 if (peer_dynamic_neighbor(peer))
16758 return;
16759
16760 if (peer->conf_if)
16761 addr = peer->conf_if;
16762 else
16763 addr = peer->host;
16764
16765 /************************************
16766 ****** Per AF to the neighbor ******
16767 ************************************/
16768 if (peer_group_active(peer)) {
16769 g_peer = peer->group->conf;
16770
16771 /* If the peer-group is active but peer is not, print a 'no
16772 * activate' */
16773 if (g_peer->afc[afi][safi] && !peer->afc[afi][safi]) {
16774 vty_out(vty, " no neighbor %s activate\n", addr);
16775 }
16776
16777 /* If the peer-group is not active but peer is, print an
16778 'activate' */
16779 else if (!g_peer->afc[afi][safi] && peer->afc[afi][safi]) {
16780 vty_out(vty, " neighbor %s activate\n", addr);
16781 }
16782 } else {
16783 if (peer->afc[afi][safi]) {
16784 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16785 if (CHECK_FLAG(bgp->flags,
16786 BGP_FLAG_NO_DEFAULT_IPV4)) {
16787 vty_out(vty, " neighbor %s activate\n",
16788 addr);
16789 }
16790 } else
16791 vty_out(vty, " neighbor %s activate\n", addr);
16792 } else {
16793 if ((afi == AFI_IP) && (safi == SAFI_UNICAST)) {
16794 if (!CHECK_FLAG(bgp->flags,
16795 BGP_FLAG_NO_DEFAULT_IPV4)) {
16796 vty_out(vty,
16797 " no neighbor %s activate\n",
16798 addr);
16799 }
16800 }
16801 }
16802 }
16803
16804 /* addpath TX knobs */
16805 if (peergroup_af_addpath_check(peer, afi, safi)) {
16806 switch (peer->addpath_type[afi][safi]) {
16807 case BGP_ADDPATH_ALL:
16808 vty_out(vty, " neighbor %s addpath-tx-all-paths\n",
16809 addr);
16810 break;
16811 case BGP_ADDPATH_BEST_PER_AS:
16812 vty_out(vty,
16813 " neighbor %s addpath-tx-bestpath-per-AS\n",
16814 addr);
16815 break;
16816 case BGP_ADDPATH_MAX:
16817 case BGP_ADDPATH_NONE:
16818 break;
16819 }
16820 }
16821
16822 /* ORF capability. */
16823 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ORF_PREFIX_SM)
16824 || peergroup_af_flag_check(peer, afi, safi,
16825 PEER_FLAG_ORF_PREFIX_RM)) {
16826 vty_out(vty, " neighbor %s capability orf prefix-list", addr);
16827
16828 if (peergroup_af_flag_check(peer, afi, safi,
16829 PEER_FLAG_ORF_PREFIX_SM)
16830 && peergroup_af_flag_check(peer, afi, safi,
16831 PEER_FLAG_ORF_PREFIX_RM))
16832 vty_out(vty, " both");
16833 else if (peergroup_af_flag_check(peer, afi, safi,
16834 PEER_FLAG_ORF_PREFIX_SM))
16835 vty_out(vty, " send");
16836 else
16837 vty_out(vty, " receive");
16838 vty_out(vty, "\n");
16839 }
16840
16841 /* Route reflector client. */
16842 if (peergroup_af_flag_check(peer, afi, safi,
16843 PEER_FLAG_REFLECTOR_CLIENT)) {
16844 vty_out(vty, " neighbor %s route-reflector-client\n", addr);
16845 }
16846
16847 /* next-hop-self force */
16848 if (peergroup_af_flag_check(peer, afi, safi,
16849 PEER_FLAG_FORCE_NEXTHOP_SELF)) {
16850 vty_out(vty, " neighbor %s next-hop-self force\n", addr);
16851 }
16852
16853 /* next-hop-self */
16854 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_SELF)) {
16855 vty_out(vty, " neighbor %s next-hop-self\n", addr);
16856 }
16857
16858 /* remove-private-AS */
16859 if (peergroup_af_flag_check(peer, afi, safi,
16860 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) {
16861 vty_out(vty, " neighbor %s remove-private-AS all replace-AS\n",
16862 addr);
16863 }
16864
16865 else if (peergroup_af_flag_check(peer, afi, safi,
16866 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) {
16867 vty_out(vty, " neighbor %s remove-private-AS replace-AS\n",
16868 addr);
16869 }
16870
16871 else if (peergroup_af_flag_check(peer, afi, safi,
16872 PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
16873 vty_out(vty, " neighbor %s remove-private-AS all\n", addr);
16874 }
16875
16876 else if (peergroup_af_flag_check(peer, afi, safi,
16877 PEER_FLAG_REMOVE_PRIVATE_AS)) {
16878 vty_out(vty, " neighbor %s remove-private-AS\n", addr);
16879 }
16880
16881 /* as-override */
16882 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
16883 vty_out(vty, " neighbor %s as-override\n", addr);
16884 }
16885
16886 /* send-community print. */
16887 flag_scomm = peergroup_af_flag_check(peer, afi, safi,
16888 PEER_FLAG_SEND_COMMUNITY);
16889 flag_secomm = peergroup_af_flag_check(peer, afi, safi,
16890 PEER_FLAG_SEND_EXT_COMMUNITY);
16891 flag_slcomm = peergroup_af_flag_check(peer, afi, safi,
16892 PEER_FLAG_SEND_LARGE_COMMUNITY);
16893
16894 if (flag_scomm && flag_secomm && flag_slcomm) {
16895 vty_out(vty, " no neighbor %s send-community all\n", addr);
16896 } else {
16897 if (flag_scomm)
16898 vty_out(vty, " no neighbor %s send-community\n", addr);
16899 if (flag_secomm)
16900 vty_out(vty,
16901 " no neighbor %s send-community extended\n",
16902 addr);
16903
16904 if (flag_slcomm)
16905 vty_out(vty, " no neighbor %s send-community large\n",
16906 addr);
16907 }
16908
16909 /* Default information */
16910 if (peergroup_af_flag_check(peer, afi, safi,
16911 PEER_FLAG_DEFAULT_ORIGINATE)) {
16912 vty_out(vty, " neighbor %s default-originate", addr);
16913
16914 if (peer->default_rmap[afi][safi].name)
16915 vty_out(vty, " route-map %s",
16916 peer->default_rmap[afi][safi].name);
16917
16918 vty_out(vty, "\n");
16919 }
16920
16921 /* Soft reconfiguration inbound. */
16922 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_SOFT_RECONFIG)) {
16923 vty_out(vty, " neighbor %s soft-reconfiguration inbound\n",
16924 addr);
16925 }
16926
16927 /* maximum-prefix. */
16928 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX)) {
16929 vty_out(vty, " neighbor %s maximum-prefix %u", addr,
16930 peer->pmax[afi][safi]);
16931
16932 if (peer->pmax_threshold[afi][safi]
16933 != MAXIMUM_PREFIX_THRESHOLD_DEFAULT)
16934 vty_out(vty, " %u", peer->pmax_threshold[afi][safi]);
16935 if (peer_af_flag_check(peer, afi, safi,
16936 PEER_FLAG_MAX_PREFIX_WARNING))
16937 vty_out(vty, " warning-only");
16938 if (peer->pmax_restart[afi][safi])
16939 vty_out(vty, " restart %u",
16940 peer->pmax_restart[afi][safi]);
16941 if (peer_af_flag_check(peer, afi, safi,
16942 PEER_FLAG_MAX_PREFIX_FORCE))
16943 vty_out(vty, " force");
16944
16945 vty_out(vty, "\n");
16946 }
16947
16948 /* maximum-prefix-out */
16949 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_MAX_PREFIX_OUT))
16950 vty_out(vty, " neighbor %s maximum-prefix-out %u\n",
16951 addr, peer->pmax_out[afi][safi]);
16952
16953 /* Route server client. */
16954 if (peergroup_af_flag_check(peer, afi, safi,
16955 PEER_FLAG_RSERVER_CLIENT)) {
16956 vty_out(vty, " neighbor %s route-server-client\n", addr);
16957 }
16958
16959 /* Nexthop-local unchanged. */
16960 if (peergroup_af_flag_check(peer, afi, safi,
16961 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)) {
16962 vty_out(vty, " neighbor %s nexthop-local unchanged\n", addr);
16963 }
16964
16965 /* allowas-in <1-10> */
16966 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_ALLOWAS_IN)) {
16967 if (peer_af_flag_check(peer, afi, safi,
16968 PEER_FLAG_ALLOWAS_IN_ORIGIN)) {
16969 vty_out(vty, " neighbor %s allowas-in origin\n", addr);
16970 } else if (peer->allowas_in[afi][safi] == 3) {
16971 vty_out(vty, " neighbor %s allowas-in\n", addr);
16972 } else {
16973 vty_out(vty, " neighbor %s allowas-in %d\n", addr,
16974 peer->allowas_in[afi][safi]);
16975 }
16976 }
16977
16978 /* weight */
16979 if (peergroup_af_flag_check(peer, afi, safi, PEER_FLAG_WEIGHT))
16980 vty_out(vty, " neighbor %s weight %lu\n", addr,
16981 peer->weight[afi][safi]);
16982
16983 /* Filter. */
16984 bgp_config_write_filter(vty, peer, afi, safi);
16985
16986 /* atribute-unchanged. */
16987 if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED)
16988 || (safi != SAFI_EVPN
16989 && peer_af_flag_check(peer, afi, safi,
16990 PEER_FLAG_NEXTHOP_UNCHANGED))
16991 || peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) {
16992
16993 if (!peer_group_active(peer)
16994 || peergroup_af_flag_check(peer, afi, safi,
16995 PEER_FLAG_AS_PATH_UNCHANGED)
16996 || peergroup_af_flag_check(peer, afi, safi,
16997 PEER_FLAG_NEXTHOP_UNCHANGED)
16998 || peergroup_af_flag_check(peer, afi, safi,
16999 PEER_FLAG_MED_UNCHANGED)) {
17000
17001 vty_out(vty,
17002 " neighbor %s attribute-unchanged%s%s%s\n",
17003 addr,
17004 peer_af_flag_check(peer, afi, safi,
17005 PEER_FLAG_AS_PATH_UNCHANGED)
17006 ? " as-path"
17007 : "",
17008 peer_af_flag_check(peer, afi, safi,
17009 PEER_FLAG_NEXTHOP_UNCHANGED)
17010 ? " next-hop"
17011 : "",
17012 peer_af_flag_check(peer, afi, safi,
17013 PEER_FLAG_MED_UNCHANGED)
17014 ? " med"
17015 : "");
17016 }
17017 }
17018}
17019
17020/* Address family based peer configuration display. */
17021static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi,
17022 safi_t safi)
17023{
17024 struct peer *peer;
17025 struct peer_group *group;
17026 struct listnode *node, *nnode;
17027
17028
17029 vty_frame(vty, " !\n address-family ");
17030 if (afi == AFI_IP) {
17031 if (safi == SAFI_UNICAST)
17032 vty_frame(vty, "ipv4 unicast");
17033 else if (safi == SAFI_LABELED_UNICAST)
17034 vty_frame(vty, "ipv4 labeled-unicast");
17035 else if (safi == SAFI_MULTICAST)
17036 vty_frame(vty, "ipv4 multicast");
17037 else if (safi == SAFI_MPLS_VPN)
17038 vty_frame(vty, "ipv4 vpn");
17039 else if (safi == SAFI_ENCAP)
17040 vty_frame(vty, "ipv4 encap");
17041 else if (safi == SAFI_FLOWSPEC)
17042 vty_frame(vty, "ipv4 flowspec");
17043 } else if (afi == AFI_IP6) {
17044 if (safi == SAFI_UNICAST)
17045 vty_frame(vty, "ipv6 unicast");
17046 else if (safi == SAFI_LABELED_UNICAST)
17047 vty_frame(vty, "ipv6 labeled-unicast");
17048 else if (safi == SAFI_MULTICAST)
17049 vty_frame(vty, "ipv6 multicast");
17050 else if (safi == SAFI_MPLS_VPN)
17051 vty_frame(vty, "ipv6 vpn");
17052 else if (safi == SAFI_ENCAP)
17053 vty_frame(vty, "ipv6 encap");
17054 else if (safi == SAFI_FLOWSPEC)
17055 vty_frame(vty, "ipv6 flowspec");
17056 } else if (afi == AFI_L2VPN) {
17057 if (safi == SAFI_EVPN)
17058 vty_frame(vty, "l2vpn evpn");
17059 }
17060 vty_frame(vty, "\n");
17061
17062 bgp_config_write_distance(vty, bgp, afi, safi);
17063
17064 bgp_config_write_network(vty, bgp, afi, safi);
17065
17066 bgp_config_write_redistribute(vty, bgp, afi, safi);
17067
17068 /* BGP flag dampening. */
17069 if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
17070 bgp_config_write_damp(vty, bgp, afi, safi);
17071 for (ALL_LIST_ELEMENTS_RO(bgp->group, node, group))
17072 if (peer_af_flag_check(group->conf, afi, safi,
17073 PEER_FLAG_CONFIG_DAMPENING))
17074 bgp_config_write_peer_damp(vty, group->conf, afi, safi);
17075 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer))
17076 if (peer_af_flag_check(peer, afi, safi,
17077 PEER_FLAG_CONFIG_DAMPENING))
17078 bgp_config_write_peer_damp(vty, peer, afi, safi);
17079
17080 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group))
17081 bgp_config_write_peer_af(vty, bgp, group->conf, afi, safi);
17082
17083 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17084 /* Skip dynamic neighbors. */
17085 if (peer_dynamic_neighbor(peer))
17086 continue;
17087
17088 /* Do not display doppelganger peers */
17089 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17090 bgp_config_write_peer_af(vty, bgp, peer, afi, safi);
17091 }
17092
17093 bgp_config_write_maxpaths(vty, bgp, afi, safi);
17094 bgp_config_write_table_map(vty, bgp, afi, safi);
17095
17096 if (safi == SAFI_EVPN)
17097 bgp_config_write_evpn_info(vty, bgp, afi, safi);
17098
17099 if (safi == SAFI_FLOWSPEC)
17100 bgp_fs_config_write_pbr(vty, bgp, afi, safi);
17101
17102 if (safi == SAFI_UNICAST) {
17103 bgp_vpn_policy_config_write_afi(vty, bgp, afi);
17104 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17105 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
17106
17107 vty_out(vty, " export vpn\n");
17108 }
17109 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17110 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
17111
17112 vty_out(vty, " import vpn\n");
17113 }
17114 if (CHECK_FLAG(bgp->af_flags[afi][safi],
17115 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
17116 char *name;
17117
17118 for (ALL_LIST_ELEMENTS_RO(
17119 bgp->vpn_policy[afi].import_vrf, node,
17120 name))
17121 vty_out(vty, " import vrf %s\n", name);
17122 }
17123 }
17124
17125 vty_endframe(vty, " exit-address-family\n");
17126}
17127
17128int bgp_config_write(struct vty *vty)
17129{
17130 struct bgp *bgp;
17131 struct peer_group *group;
17132 struct peer *peer;
17133 struct listnode *node, *nnode;
17134 struct listnode *mnode, *mnnode;
17135
17136 if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
17137 vty_out(vty, "bgp route-map delay-timer %u\n",
17138 bm->rmap_update_timer);
17139
17140 if (bm->v_update_delay != BGP_UPDATE_DELAY_DEF) {
17141 vty_out(vty, "bgp update-delay %d", bm->v_update_delay);
17142 if (bm->v_update_delay != bm->v_establish_wait)
17143 vty_out(vty, " %d", bm->v_establish_wait);
17144 vty_out(vty, "\n");
17145 }
17146
17147 if (bm->wait_for_fib)
17148 vty_out(vty, "bgp suppress-fib-pending\n");
17149
17150 if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17151 vty_out(vty, "bgp graceful-shutdown\n");
17152
17153 /* No-RIB (Zebra) option flag configuration */
17154 if (bgp_option_check(BGP_OPT_NO_FIB))
17155 vty_out(vty, "bgp no-rib\n");
17156
17157 if (!CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA))
17158 vty_out(vty, "no bgp send-extra-data zebra\n");
17159
17160 /* BGP configuration. */
17161 for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) {
17162
17163 /* skip all auto created vrf as they dont have user config */
17164 if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO))
17165 continue;
17166
17167 /* Router bgp ASN */
17168 vty_out(vty, "router bgp %u", bgp->as);
17169
17170 if (bgp->name)
17171 vty_out(vty, " %s %s",
17172 (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
17173 ? "view" : "vrf", bgp->name);
17174 vty_out(vty, "\n");
17175
17176 /* BGP fast-external-failover. */
17177 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER))
17178 vty_out(vty, " no bgp fast-external-failover\n");
17179
17180 /* BGP router ID. */
17181 if (bgp->router_id_static.s_addr != INADDR_ANY)
17182 vty_out(vty, " bgp router-id %pI4\n",
17183 &bgp->router_id_static);
17184
17185 /* Suppress fib pending */
17186 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING))
17187 vty_out(vty, " bgp suppress-fib-pending\n");
17188
17189 /* BGP log-neighbor-changes. */
17190 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17191 != SAVE_BGP_LOG_NEIGHBOR_CHANGES)
17192 vty_out(vty, " %sbgp log-neighbor-changes\n",
17193 CHECK_FLAG(bgp->flags,
17194 BGP_FLAG_LOG_NEIGHBOR_CHANGES)
17195 ? ""
17196 : "no ");
17197
17198 /* BGP configuration. */
17199 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED))
17200 vty_out(vty, " bgp always-compare-med\n");
17201
17202 /* RFC8212 default eBGP policy. */
17203 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY)
17204 != SAVE_BGP_EBGP_REQUIRES_POLICY)
17205 vty_out(vty, " %sbgp ebgp-requires-policy\n",
17206 CHECK_FLAG(bgp->flags,
17207 BGP_FLAG_EBGP_REQUIRES_POLICY)
17208 ? ""
17209 : "no ");
17210
17211 /* draft-ietf-idr-deprecate-as-set-confed-set */
17212 if (bgp->reject_as_sets)
17213 vty_out(vty, " bgp reject-as-sets\n");
17214
17215 /* Suppress duplicate updates if the route actually not changed
17216 */
17217 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_DUPLICATES)
17218 != SAVE_BGP_SUPPRESS_DUPLICATES)
17219 vty_out(vty, " %sbgp suppress-duplicates\n",
17220 CHECK_FLAG(bgp->flags,
17221 BGP_FLAG_SUPPRESS_DUPLICATES)
17222 ? ""
17223 : "no ");
17224
17225 /* BGP default ipv4-unicast. */
17226 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_DEFAULT_IPV4))
17227 vty_out(vty, " no bgp default ipv4-unicast\n");
17228
17229 /* BGP default local-preference. */
17230 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
17231 vty_out(vty, " bgp default local-preference %u\n",
17232 bgp->default_local_pref);
17233
17234 /* BGP default show-hostname */
17235 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17236 != SAVE_BGP_SHOW_HOSTNAME)
17237 vty_out(vty, " %sbgp default show-hostname\n",
17238 CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
17239 ? ""
17240 : "no ");
17241
17242 /* BGP default show-nexthop-hostname */
17243 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17244 != SAVE_BGP_SHOW_HOSTNAME)
17245 vty_out(vty, " %sbgp default show-nexthop-hostname\n",
17246 CHECK_FLAG(bgp->flags,
17247 BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
17248 ? ""
17249 : "no ");
17250
17251 /* BGP default subgroup-pkt-queue-max. */
17252 if (bgp->default_subgroup_pkt_queue_max
17253 != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
17254 vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n",
17255 bgp->default_subgroup_pkt_queue_max);
17256
17257 /* BGP client-to-client reflection. */
17258 if (CHECK_FLAG(bgp->flags, BGP_FLAG_NO_CLIENT_TO_CLIENT))
17259 vty_out(vty, " no bgp client-to-client reflection\n");
17260
17261 /* BGP cluster ID. */
17262 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CLUSTER_ID))
17263 vty_out(vty, " bgp cluster-id %pI4\n",
17264 &bgp->cluster_id);
17265
17266 /* Disable ebgp connected nexthop check */
17267 if (CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
17268 vty_out(vty,
17269 " bgp disable-ebgp-connected-route-check\n");
17270
17271 /* Confederation identifier*/
17272 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
17273 vty_out(vty, " bgp confederation identifier %u\n",
17274 bgp->confed_id);
17275
17276 /* Confederation peer */
17277 if (bgp->confed_peers_cnt > 0) {
17278 int i;
17279
17280 vty_out(vty, " bgp confederation peers");
17281
17282 for (i = 0; i < bgp->confed_peers_cnt; i++)
17283 vty_out(vty, " %u", bgp->confed_peers[i]);
17284
17285 vty_out(vty, "\n");
17286 }
17287
17288 /* BGP deterministic-med. */
17289 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
17290 != SAVE_BGP_DETERMINISTIC_MED)
17291 vty_out(vty, " %sbgp deterministic-med\n",
17292 CHECK_FLAG(bgp->flags,
17293 BGP_FLAG_DETERMINISTIC_MED)
17294 ? ""
17295 : "no ");
17296
17297 /* BGP update-delay. */
17298 bgp_config_write_update_delay(vty, bgp);
17299
17300 if (bgp->v_maxmed_onstartup
17301 != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) {
17302 vty_out(vty, " bgp max-med on-startup %u",
17303 bgp->v_maxmed_onstartup);
17304 if (bgp->maxmed_onstartup_value
17305 != BGP_MAXMED_VALUE_DEFAULT)
17306 vty_out(vty, " %u",
17307 bgp->maxmed_onstartup_value);
17308 vty_out(vty, "\n");
17309 }
17310 if (bgp->v_maxmed_admin != BGP_MAXMED_ADMIN_UNCONFIGURED) {
17311 vty_out(vty, " bgp max-med administrative");
17312 if (bgp->maxmed_admin_value != BGP_MAXMED_VALUE_DEFAULT)
17313 vty_out(vty, " %u", bgp->maxmed_admin_value);
17314 vty_out(vty, "\n");
17315 }
17316
17317 /* write quanta */
17318 bgp_config_write_wpkt_quanta(vty, bgp);
17319 /* read quanta */
17320 bgp_config_write_rpkt_quanta(vty, bgp);
17321
17322 /* coalesce time */
17323 bgp_config_write_coalesce_time(vty, bgp);
17324
17325 /* BGP per-instance graceful-shutdown */
17326 /* BGP-wide settings and per-instance settings are mutually
17327 * exclusive.
17328 */
17329 if (!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN))
17330 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_SHUTDOWN))
17331 vty_out(vty, " bgp graceful-shutdown\n");
17332
17333 /* BGP graceful-restart. */
17334 if (bgp->stalepath_time != BGP_DEFAULT_STALEPATH_TIME)
17335 vty_out(vty,
17336 " bgp graceful-restart stalepath-time %u\n",
17337 bgp->stalepath_time);
17338
17339 if (bgp->restart_time != BGP_DEFAULT_RESTART_TIME)
17340 vty_out(vty, " bgp graceful-restart restart-time %u\n",
17341 bgp->restart_time);
17342
17343 if (bgp->select_defer_time != BGP_DEFAULT_SELECT_DEFERRAL_TIME)
17344 vty_out(vty,
17345 " bgp graceful-restart select-defer-time %u\n",
17346 bgp->select_defer_time);
17347
17348 if (bgp_global_gr_mode_get(bgp) == GLOBAL_GR)
17349 vty_out(vty, " bgp graceful-restart\n");
17350
17351 if (bgp_global_gr_mode_get(bgp) == GLOBAL_DISABLE)
17352 vty_out(vty, " bgp graceful-restart-disable\n");
17353
17354 /* BGP graceful-restart Preserve State F bit. */
17355 if (CHECK_FLAG(bgp->flags, BGP_FLAG_GR_PRESERVE_FWD))
17356 vty_out(vty,
17357 " bgp graceful-restart preserve-fw-state\n");
17358
17359 /* Stale timer for RIB */
17360 if (bgp->rib_stale_time != BGP_DEFAULT_RIB_STALE_TIME)
17361 vty_out(vty,
17362 " bgp graceful-restart rib-stale-time %u\n",
17363 bgp->rib_stale_time);
17364
17365 /* BGP bestpath method. */
17366 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE))
17367 vty_out(vty, " bgp bestpath as-path ignore\n");
17368 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED))
17369 vty_out(vty, " bgp bestpath as-path confed\n");
17370
17371 if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
17372 if (CHECK_FLAG(bgp->flags,
17373 BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
17374 vty_out(vty,
17375 " bgp bestpath as-path multipath-relax as-set\n");
17376 } else {
17377 vty_out(vty,
17378 " bgp bestpath as-path multipath-relax\n");
17379 }
17380 }
17381
17382 if (CHECK_FLAG(bgp->flags, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
17383 vty_out(vty,
17384 " bgp route-reflector allow-outbound-policy\n");
17385 }
17386 if (CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID))
17387 vty_out(vty, " bgp bestpath compare-routerid\n");
17388 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)
17389 || CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
17390 vty_out(vty, " bgp bestpath med");
17391 if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
17392 vty_out(vty, " confed");
17393 if (CHECK_FLAG(bgp->flags,
17394 BGP_FLAG_MED_MISSING_AS_WORST))
17395 vty_out(vty, " missing-as-worst");
17396 vty_out(vty, "\n");
17397 }
17398
17399 /* Link bandwidth handling. */
17400 if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW)
17401 vty_out(vty, " bgp bestpath bandwidth ignore\n");
17402 else if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
17403 vty_out(vty, " bgp bestpath bandwidth skip-missing\n");
17404 else if (bgp->lb_handling == BGP_LINK_BW_DEFWT_4_MISSING)
17405 vty_out(vty, " bgp bestpath bandwidth default-weight-for-missing\n");
17406
17407 /* BGP network import check. */
17408 if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17409 != SAVE_BGP_IMPORT_CHECK)
17410 vty_out(vty, " %sbgp network import-check\n",
17411 CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
17412 ? ""
17413 : "no ");
17414
17415 /* BGP timers configuration. */
17416 if (bgp->default_keepalive != SAVE_BGP_KEEPALIVE
17417 && bgp->default_holdtime != SAVE_BGP_HOLDTIME)
17418 vty_out(vty, " timers bgp %u %u\n",
17419 bgp->default_keepalive, bgp->default_holdtime);
17420
17421 /* peer-group */
17422 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
17423 bgp_config_write_peer_global(vty, bgp, group->conf);
17424 }
17425
17426 /* Normal neighbor configuration. */
17427 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
17428 if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
17429 bgp_config_write_peer_global(vty, bgp, peer);
17430 }
17431
17432 /* listen range and limit for dynamic BGP neighbors */
17433 bgp_config_write_listen(vty, bgp);
17434
17435 /*
17436 * BGP default autoshutdown neighbors
17437 *
17438 * This must be placed after any peer and peer-group
17439 * configuration, to avoid setting all peers to shutdown after
17440 * a daemon restart, which is undesired behavior. (see #2286)
17441 */
17442 if (bgp->autoshutdown)
17443 vty_out(vty, " bgp default shutdown\n");
17444
17445 /* BGP instance administrative shutdown */
17446 if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN))
17447 vty_out(vty, " bgp shutdown\n");
17448
17449 /* IPv4 unicast configuration. */
17450 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_UNICAST);
17451
17452 /* IPv4 multicast configuration. */
17453 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MULTICAST);
17454
17455 /* IPv4 labeled-unicast configuration. */
17456 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_LABELED_UNICAST);
17457
17458 /* IPv4 VPN configuration. */
17459 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_MPLS_VPN);
17460
17461 /* ENCAPv4 configuration. */
17462 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP);
17463
17464 /* FLOWSPEC v4 configuration. */
17465 bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC);
17466
17467 /* IPv6 unicast configuration. */
17468 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST);
17469
17470 /* IPv6 multicast configuration. */
17471 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MULTICAST);
17472
17473 /* IPv6 labeled-unicast configuration. */
17474 bgp_config_write_family(vty, bgp, AFI_IP6,
17475 SAFI_LABELED_UNICAST);
17476
17477 /* IPv6 VPN configuration. */
17478 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_MPLS_VPN);
17479
17480 /* ENCAPv6 configuration. */
17481 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP);
17482
17483 /* FLOWSPEC v6 configuration. */
17484 bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC);
17485
17486 /* EVPN configuration. */
17487 bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN);
17488
17489 hook_call(bgp_inst_config_write, bgp, vty);
17490
17491#ifdef ENABLE_BGP_VNC
17492 bgp_rfapi_cfg_write(vty, bgp);
17493#endif
17494
17495 vty_out(vty, "!\n");
17496 }
17497 return 0;
17498}
17499
17500
17501/* BGP node structure. */
17502static struct cmd_node bgp_node = {
17503 .name = "bgp",
17504 .node = BGP_NODE,
17505 .parent_node = CONFIG_NODE,
17506 .prompt = "%s(config-router)# ",
17507 .config_write = bgp_config_write,
17508};
17509
17510static struct cmd_node bgp_ipv4_unicast_node = {
17511 .name = "bgp ipv4 unicast",
17512 .node = BGP_IPV4_NODE,
17513 .parent_node = BGP_NODE,
17514 .prompt = "%s(config-router-af)# ",
17515};
17516
17517static struct cmd_node bgp_ipv4_multicast_node = {
17518 .name = "bgp ipv4 multicast",
17519 .node = BGP_IPV4M_NODE,
17520 .parent_node = BGP_NODE,
17521 .prompt = "%s(config-router-af)# ",
17522};
17523
17524static struct cmd_node bgp_ipv4_labeled_unicast_node = {
17525 .name = "bgp ipv4 labeled unicast",
17526 .node = BGP_IPV4L_NODE,
17527 .parent_node = BGP_NODE,
17528 .prompt = "%s(config-router-af)# ",
17529};
17530
17531static struct cmd_node bgp_ipv6_unicast_node = {
17532 .name = "bgp ipv6",
17533 .node = BGP_IPV6_NODE,
17534 .parent_node = BGP_NODE,
17535 .prompt = "%s(config-router-af)# ",
17536};
17537
17538static struct cmd_node bgp_ipv6_multicast_node = {
17539 .name = "bgp ipv6 multicast",
17540 .node = BGP_IPV6M_NODE,
17541 .parent_node = BGP_NODE,
17542 .prompt = "%s(config-router-af)# ",
17543};
17544
17545static struct cmd_node bgp_ipv6_labeled_unicast_node = {
17546 .name = "bgp ipv6 labeled unicast",
17547 .node = BGP_IPV6L_NODE,
17548 .parent_node = BGP_NODE,
17549 .prompt = "%s(config-router-af)# ",
17550};
17551
17552static struct cmd_node bgp_vpnv4_node = {
17553 .name = "bgp vpnv4",
17554 .node = BGP_VPNV4_NODE,
17555 .parent_node = BGP_NODE,
17556 .prompt = "%s(config-router-af)# ",
17557};
17558
17559static struct cmd_node bgp_vpnv6_node = {
17560 .name = "bgp vpnv6",
17561 .node = BGP_VPNV6_NODE,
17562 .parent_node = BGP_NODE,
17563 .prompt = "%s(config-router-af-vpnv6)# ",
17564};
17565
17566static struct cmd_node bgp_evpn_node = {
17567 .name = "bgp evpn",
17568 .node = BGP_EVPN_NODE,
17569 .parent_node = BGP_NODE,
17570 .prompt = "%s(config-router-evpn)# ",
17571};
17572
17573static struct cmd_node bgp_evpn_vni_node = {
17574 .name = "bgp evpn vni",
17575 .node = BGP_EVPN_VNI_NODE,
17576 .parent_node = BGP_EVPN_NODE,
17577 .prompt = "%s(config-router-af-vni)# ",
17578};
17579
17580static struct cmd_node bgp_flowspecv4_node = {
17581 .name = "bgp ipv4 flowspec",
17582 .node = BGP_FLOWSPECV4_NODE,
17583 .parent_node = BGP_NODE,
17584 .prompt = "%s(config-router-af)# ",
17585};
17586
17587static struct cmd_node bgp_flowspecv6_node = {
17588 .name = "bgp ipv6 flowspec",
17589 .node = BGP_FLOWSPECV6_NODE,
17590 .parent_node = BGP_NODE,
17591 .prompt = "%s(config-router-af-vpnv6)# ",
17592};
17593
17594static void community_list_vty(void);
17595
17596static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
17597{
17598 struct bgp *bgp;
17599 struct peer *peer;
17600 struct listnode *lnbgp, *lnpeer;
17601
17602 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17603 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
17604 /* only provide suggestions on the appropriate input
17605 * token type,
17606 * they'll otherwise show up multiple times */
17607 enum cmd_token_type match_type;
17608 char *name = peer->host;
17609
17610 if (peer->conf_if) {
17611 match_type = VARIABLE_TKN;
17612 name = peer->conf_if;
17613 } else if (strchr(peer->host, ':'))
17614 match_type = IPV6_TKN;
17615 else
17616 match_type = IPV4_TKN;
17617
17618 if (token->type != match_type)
17619 continue;
17620
17621 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
17622 }
17623 }
17624}
17625
17626static const struct cmd_variable_handler bgp_var_neighbor[] = {
17627 {.varname = "neighbor", .completions = bgp_ac_neighbor},
17628 {.varname = "neighbors", .completions = bgp_ac_neighbor},
17629 {.varname = "peer", .completions = bgp_ac_neighbor},
17630 {.completions = NULL}};
17631
17632static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
17633{
17634 struct bgp *bgp;
17635 struct peer_group *group;
17636 struct listnode *lnbgp, *lnpeer;
17637
17638 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
17639 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
17640 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
17641 group->name));
17642 }
17643}
17644
17645static const struct cmd_variable_handler bgp_var_peergroup[] = {
17646 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
17647 {.completions = NULL} };
17648
17649void bgp_vty_init(void)
17650{
17651 cmd_variable_handler_register(bgp_var_neighbor);
17652 cmd_variable_handler_register(bgp_var_peergroup);
17653
17654 /* Install bgp top node. */
17655 install_node(&bgp_node);
17656 install_node(&bgp_ipv4_unicast_node);
17657 install_node(&bgp_ipv4_multicast_node);
17658 install_node(&bgp_ipv4_labeled_unicast_node);
17659 install_node(&bgp_ipv6_unicast_node);
17660 install_node(&bgp_ipv6_multicast_node);
17661 install_node(&bgp_ipv6_labeled_unicast_node);
17662 install_node(&bgp_vpnv4_node);
17663 install_node(&bgp_vpnv6_node);
17664 install_node(&bgp_evpn_node);
17665 install_node(&bgp_evpn_vni_node);
17666 install_node(&bgp_flowspecv4_node);
17667 install_node(&bgp_flowspecv6_node);
17668
17669 /* Install default VTY commands to new nodes. */
17670 install_default(BGP_NODE);
17671 install_default(BGP_IPV4_NODE);
17672 install_default(BGP_IPV4M_NODE);
17673 install_default(BGP_IPV4L_NODE);
17674 install_default(BGP_IPV6_NODE);
17675 install_default(BGP_IPV6M_NODE);
17676 install_default(BGP_IPV6L_NODE);
17677 install_default(BGP_VPNV4_NODE);
17678 install_default(BGP_VPNV6_NODE);
17679 install_default(BGP_FLOWSPECV4_NODE);
17680 install_default(BGP_FLOWSPECV6_NODE);
17681 install_default(BGP_EVPN_NODE);
17682 install_default(BGP_EVPN_VNI_NODE);
17683
17684 /* "bgp local-mac" hidden commands. */
17685 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
17686 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
17687
17688 /* "bgp suppress-fib-pending" global */
17689 install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd);
17690
17691 /* bgp route-map delay-timer commands. */
17692 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
17693 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17694
17695 /* global bgp update-delay command */
17696 install_element(CONFIG_NODE, &bgp_global_update_delay_cmd);
17697 install_element(CONFIG_NODE, &no_bgp_global_update_delay_cmd);
17698
17699 /* global bgp graceful-shutdown command */
17700 install_element(CONFIG_NODE, &bgp_graceful_shutdown_cmd);
17701 install_element(CONFIG_NODE, &no_bgp_graceful_shutdown_cmd);
17702
17703 /* Dummy commands (Currently not supported) */
17704 install_element(BGP_NODE, &no_synchronization_cmd);
17705 install_element(BGP_NODE, &no_auto_summary_cmd);
17706
17707 /* "router bgp" commands. */
17708 install_element(CONFIG_NODE, &router_bgp_cmd);
17709
17710 /* "no router bgp" commands. */
17711 install_element(CONFIG_NODE, &no_router_bgp_cmd);
17712
17713 /* "bgp router-id" commands. */
17714 install_element(BGP_NODE, &bgp_router_id_cmd);
17715 install_element(BGP_NODE, &no_bgp_router_id_cmd);
17716
17717 /* "bgp suppress-fib-pending" command */
17718 install_element(BGP_NODE, &bgp_suppress_fib_pending_cmd);
17719
17720 /* "bgp cluster-id" commands. */
17721 install_element(BGP_NODE, &bgp_cluster_id_cmd);
17722 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
17723
17724 /* "bgp no-rib" commands. */
17725 install_element(CONFIG_NODE, &bgp_norib_cmd);
17726 install_element(CONFIG_NODE, &no_bgp_norib_cmd);
17727
17728 install_element(CONFIG_NODE, &no_bgp_send_extra_data_cmd);
17729
17730 /* "bgp confederation" commands. */
17731 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
17732 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
17733
17734 /* "bgp confederation peers" commands. */
17735 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
17736 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
17737
17738 /* bgp max-med command */
17739 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
17740 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
17741 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
17742 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
17743 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
17744
17745 /* bgp disable-ebgp-connected-nh-check */
17746 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
17747 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
17748
17749 /* bgp update-delay command */
17750 install_element(BGP_NODE, &bgp_update_delay_cmd);
17751 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
17752
17753 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
17754 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
17755
17756 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
17757 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
17758
17759 /* "maximum-paths" commands. */
17760 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
17761 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
17762 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
17763 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
17764 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
17765 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
17766 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
17767 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
17768 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
17769 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
17770 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17771 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
17772 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
17773 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17774 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
17775
17776 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
17777 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
17778 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
17779 install_element(BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17780 install_element(BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17781 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
17782 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
17783 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
17784 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
17785 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
17786
17787 /* "timers bgp" commands. */
17788 install_element(BGP_NODE, &bgp_timers_cmd);
17789 install_element(BGP_NODE, &no_bgp_timers_cmd);
17790
17791 /* route-map delay-timer commands - per instance for backwards compat.
17792 */
17793 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
17794 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
17795
17796 /* "bgp client-to-client reflection" commands */
17797 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
17798 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
17799
17800 /* "bgp always-compare-med" commands */
17801 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
17802 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
17803
17804 /* bgp ebgp-requires-policy */
17805 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
17806 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
17807
17808 /* bgp suppress-duplicates */
17809 install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
17810 install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
17811
17812 /* bgp reject-as-sets */
17813 install_element(BGP_NODE, &bgp_reject_as_sets_cmd);
17814 install_element(BGP_NODE, &no_bgp_reject_as_sets_cmd);
17815
17816 /* "bgp deterministic-med" commands */
17817 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
17818 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
17819
17820 /* "bgp graceful-restart" command */
17821 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
17822 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
17823
17824 /* "bgp graceful-restart-disable" command */
17825 install_element(BGP_NODE, &bgp_graceful_restart_disable_cmd);
17826 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_cmd);
17827
17828 /* "neighbor a:b:c:d graceful-restart" command */
17829 install_element(BGP_NODE, &bgp_neighbor_graceful_restart_set_cmd);
17830 install_element(BGP_NODE, &no_bgp_neighbor_graceful_restart_set_cmd);
17831
17832 /* "neighbor a:b:c:d graceful-restart-disable" command */
17833 install_element(BGP_NODE,
17834 &bgp_neighbor_graceful_restart_disable_set_cmd);
17835 install_element(BGP_NODE,
17836 &no_bgp_neighbor_graceful_restart_disable_set_cmd);
17837
17838 /* "neighbor a:b:c:d graceful-restart-helper" command */
17839 install_element(BGP_NODE,
17840 &bgp_neighbor_graceful_restart_helper_set_cmd);
17841 install_element(BGP_NODE,
17842 &no_bgp_neighbor_graceful_restart_helper_set_cmd);
17843
17844 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
17845 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
17846 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
17847 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
17848 install_element(BGP_NODE, &bgp_graceful_restart_select_defer_time_cmd);
17849 install_element(BGP_NODE,
17850 &no_bgp_graceful_restart_select_defer_time_cmd);
17851 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
17852 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
17853
17854 install_element(BGP_NODE, &bgp_graceful_restart_disable_eor_cmd);
17855 install_element(BGP_NODE, &no_bgp_graceful_restart_disable_eor_cmd);
17856 install_element(BGP_NODE, &bgp_graceful_restart_rib_stale_time_cmd);
17857 install_element(BGP_NODE, &no_bgp_graceful_restart_rib_stale_time_cmd);
17858
17859 /* "bgp graceful-shutdown" commands */
17860 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
17861 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
17862
17863 /* "bgp fast-external-failover" commands */
17864 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
17865 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
17866
17867 /* "bgp bestpath compare-routerid" commands */
17868 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
17869 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
17870
17871 /* "bgp bestpath as-path ignore" commands */
17872 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
17873 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
17874
17875 /* "bgp bestpath as-path confed" commands */
17876 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
17877 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
17878
17879 /* "bgp bestpath as-path multipath-relax" commands */
17880 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
17881 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
17882
17883 /* "bgp log-neighbor-changes" commands */
17884 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
17885 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
17886
17887 /* "bgp bestpath med" commands */
17888 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
17889 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
17890
17891 /* "bgp bestpath bandwidth" commands */
17892 install_element(BGP_NODE, &bgp_bestpath_bw_cmd);
17893 install_element(BGP_NODE, &no_bgp_bestpath_bw_cmd);
17894
17895 /* "no bgp default ipv4-unicast" commands. */
17896 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
17897 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
17898
17899 /* "bgp network import-check" commands. */
17900 install_element(BGP_NODE, &bgp_network_import_check_cmd);
17901 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
17902 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
17903
17904 /* "bgp default local-preference" commands. */
17905 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
17906 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
17907
17908 /* bgp default show-hostname */
17909 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
17910 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
17911
17912 /* bgp default show-nexthop-hostname */
17913 install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
17914 install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
17915
17916 /* "bgp default subgroup-pkt-queue-max" commands. */
17917 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
17918 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
17919
17920 /* bgp ibgp-allow-policy-mods command */
17921 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
17922 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
17923
17924 /* "bgp listen limit" commands. */
17925 install_element(BGP_NODE, &bgp_listen_limit_cmd);
17926 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
17927
17928 /* "bgp listen range" commands. */
17929 install_element(BGP_NODE, &bgp_listen_range_cmd);
17930 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
17931
17932 /* "bgp default shutdown" command */
17933 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
17934
17935 /* "bgp shutdown" commands */
17936 install_element(BGP_NODE, &bgp_shutdown_cmd);
17937 install_element(BGP_NODE, &bgp_shutdown_msg_cmd);
17938 install_element(BGP_NODE, &no_bgp_shutdown_cmd);
17939 install_element(BGP_NODE, &no_bgp_shutdown_msg_cmd);
17940
17941 /* "neighbor remote-as" commands. */
17942 install_element(BGP_NODE, &neighbor_remote_as_cmd);
17943 install_element(BGP_NODE, &neighbor_interface_config_cmd);
17944 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
17945 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
17946 install_element(BGP_NODE,
17947 &neighbor_interface_v6only_config_remote_as_cmd);
17948 install_element(BGP_NODE, &no_neighbor_cmd);
17949 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
17950
17951 /* "neighbor peer-group" commands. */
17952 install_element(BGP_NODE, &neighbor_peer_group_cmd);
17953 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
17954 install_element(BGP_NODE,
17955 &no_neighbor_interface_peer_group_remote_as_cmd);
17956
17957 /* "neighbor local-as" commands. */
17958 install_element(BGP_NODE, &neighbor_local_as_cmd);
17959 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
17960 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
17961 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
17962
17963 /* "neighbor solo" commands. */
17964 install_element(BGP_NODE, &neighbor_solo_cmd);
17965 install_element(BGP_NODE, &no_neighbor_solo_cmd);
17966
17967 /* "neighbor password" commands. */
17968 install_element(BGP_NODE, &neighbor_password_cmd);
17969 install_element(BGP_NODE, &no_neighbor_password_cmd);
17970
17971 /* "neighbor activate" commands. */
17972 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
17973 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
17974 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
17975 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
17976 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
17977 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
17978 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
17979 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
17980 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
17981 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
17982 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
17983 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
17984
17985 /* "no neighbor activate" commands. */
17986 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
17987 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
17988 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
17989 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
17990 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
17991 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
17992 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
17993 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
17994 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
17995 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
17996 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
17997 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
17998
17999 /* "neighbor peer-group" set commands. */
18000 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
18001 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18002 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
18003 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18004 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
18005 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
18006 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
18007 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
18008 install_element(BGP_FLOWSPECV4_NODE,
18009 &neighbor_set_peer_group_hidden_cmd);
18010 install_element(BGP_FLOWSPECV6_NODE,
18011 &neighbor_set_peer_group_hidden_cmd);
18012
18013 /* "no neighbor peer-group unset" commands. */
18014 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
18015 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18016 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18017 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18018 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18019 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18020 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18021 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
18022 install_element(BGP_FLOWSPECV4_NODE,
18023 &no_neighbor_set_peer_group_hidden_cmd);
18024 install_element(BGP_FLOWSPECV6_NODE,
18025 &no_neighbor_set_peer_group_hidden_cmd);
18026
18027 /* "neighbor softreconfiguration inbound" commands.*/
18028 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
18029 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
18030 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
18031 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18032 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
18033 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18034 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
18035 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18036 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
18037 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18038 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
18039 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
18040 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
18041 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
18042 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
18043 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
18044 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
18045 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
18046 install_element(BGP_FLOWSPECV4_NODE,
18047 &neighbor_soft_reconfiguration_cmd);
18048 install_element(BGP_FLOWSPECV4_NODE,
18049 &no_neighbor_soft_reconfiguration_cmd);
18050 install_element(BGP_FLOWSPECV6_NODE,
18051 &neighbor_soft_reconfiguration_cmd);
18052 install_element(BGP_FLOWSPECV6_NODE,
18053 &no_neighbor_soft_reconfiguration_cmd);
18054 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
18055 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
18056
18057 /* "neighbor attribute-unchanged" commands. */
18058 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
18059 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
18060 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
18061 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
18062 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
18063 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
18064 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
18065 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
18066 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
18067 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
18068 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
18069 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
18070 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
18071 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
18072 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
18073 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
18074 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
18075 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
18076
18077 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
18078 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
18079
18080 /* "nexthop-local unchanged" commands */
18081 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
18082 install_element(BGP_IPV6_NODE,
18083 &no_neighbor_nexthop_local_unchanged_cmd);
18084
18085 /* "neighbor next-hop-self" commands. */
18086 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
18087 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
18088 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
18089 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
18090 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
18091 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
18092 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
18093 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
18094 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
18095 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
18096 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
18097 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
18098 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
18099 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
18100 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
18101 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
18102 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
18103 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
18104 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
18105 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
18106
18107 /* "neighbor next-hop-self force" commands. */
18108 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
18109 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
18110 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18111 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
18112 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
18113 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18114 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18115 install_element(BGP_IPV4_NODE,
18116 &no_neighbor_nexthop_self_all_hidden_cmd);
18117 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
18118 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
18119 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18120 install_element(BGP_IPV4M_NODE,
18121 &no_neighbor_nexthop_self_all_hidden_cmd);
18122 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
18123 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
18124 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18125 install_element(BGP_IPV4L_NODE,
18126 &no_neighbor_nexthop_self_all_hidden_cmd);
18127 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
18128 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18129 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18130 install_element(BGP_IPV6_NODE,
18131 &no_neighbor_nexthop_self_all_hidden_cmd);
18132 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
18133 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
18134 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18135 install_element(BGP_IPV6M_NODE,
18136 &no_neighbor_nexthop_self_all_hidden_cmd);
18137 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
18138 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
18139 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18140 install_element(BGP_IPV6L_NODE,
18141 &no_neighbor_nexthop_self_all_hidden_cmd);
18142 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
18143 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
18144 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18145 install_element(BGP_VPNV4_NODE,
18146 &no_neighbor_nexthop_self_all_hidden_cmd);
18147 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
18148 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
18149 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_all_hidden_cmd);
18150 install_element(BGP_VPNV6_NODE,
18151 &no_neighbor_nexthop_self_all_hidden_cmd);
18152 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_force_cmd);
18153 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_force_cmd);
18154
18155 /* "neighbor as-override" commands. */
18156 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
18157 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
18158 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
18159 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
18160 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
18161 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
18162 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
18163 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
18164 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
18165 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
18166 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
18167 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
18168 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
18169 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
18170 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
18171 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
18172 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
18173 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
18174
18175 /* "neighbor remove-private-AS" commands. */
18176 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
18177 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
18178 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
18179 install_element(BGP_NODE,
18180 &no_neighbor_remove_private_as_all_hidden_cmd);
18181 install_element(BGP_NODE,
18182 &neighbor_remove_private_as_replace_as_hidden_cmd);
18183 install_element(BGP_NODE,
18184 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
18185 install_element(BGP_NODE,
18186 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
18187 install_element(
18188 BGP_NODE,
18189 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
18190 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
18191 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
18192 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
18193 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18194 install_element(BGP_IPV4_NODE,
18195 &neighbor_remove_private_as_replace_as_cmd);
18196 install_element(BGP_IPV4_NODE,
18197 &no_neighbor_remove_private_as_replace_as_cmd);
18198 install_element(BGP_IPV4_NODE,
18199 &neighbor_remove_private_as_all_replace_as_cmd);
18200 install_element(BGP_IPV4_NODE,
18201 &no_neighbor_remove_private_as_all_replace_as_cmd);
18202 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
18203 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
18204 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
18205 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
18206 install_element(BGP_IPV4M_NODE,
18207 &neighbor_remove_private_as_replace_as_cmd);
18208 install_element(BGP_IPV4M_NODE,
18209 &no_neighbor_remove_private_as_replace_as_cmd);
18210 install_element(BGP_IPV4M_NODE,
18211 &neighbor_remove_private_as_all_replace_as_cmd);
18212 install_element(BGP_IPV4M_NODE,
18213 &no_neighbor_remove_private_as_all_replace_as_cmd);
18214 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
18215 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
18216 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
18217 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
18218 install_element(BGP_IPV4L_NODE,
18219 &neighbor_remove_private_as_replace_as_cmd);
18220 install_element(BGP_IPV4L_NODE,
18221 &no_neighbor_remove_private_as_replace_as_cmd);
18222 install_element(BGP_IPV4L_NODE,
18223 &neighbor_remove_private_as_all_replace_as_cmd);
18224 install_element(BGP_IPV4L_NODE,
18225 &no_neighbor_remove_private_as_all_replace_as_cmd);
18226 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
18227 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
18228 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
18229 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18230 install_element(BGP_IPV6_NODE,
18231 &neighbor_remove_private_as_replace_as_cmd);
18232 install_element(BGP_IPV6_NODE,
18233 &no_neighbor_remove_private_as_replace_as_cmd);
18234 install_element(BGP_IPV6_NODE,
18235 &neighbor_remove_private_as_all_replace_as_cmd);
18236 install_element(BGP_IPV6_NODE,
18237 &no_neighbor_remove_private_as_all_replace_as_cmd);
18238 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
18239 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
18240 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
18241 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
18242 install_element(BGP_IPV6M_NODE,
18243 &neighbor_remove_private_as_replace_as_cmd);
18244 install_element(BGP_IPV6M_NODE,
18245 &no_neighbor_remove_private_as_replace_as_cmd);
18246 install_element(BGP_IPV6M_NODE,
18247 &neighbor_remove_private_as_all_replace_as_cmd);
18248 install_element(BGP_IPV6M_NODE,
18249 &no_neighbor_remove_private_as_all_replace_as_cmd);
18250 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
18251 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
18252 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
18253 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
18254 install_element(BGP_IPV6L_NODE,
18255 &neighbor_remove_private_as_replace_as_cmd);
18256 install_element(BGP_IPV6L_NODE,
18257 &no_neighbor_remove_private_as_replace_as_cmd);
18258 install_element(BGP_IPV6L_NODE,
18259 &neighbor_remove_private_as_all_replace_as_cmd);
18260 install_element(BGP_IPV6L_NODE,
18261 &no_neighbor_remove_private_as_all_replace_as_cmd);
18262 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
18263 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
18264 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
18265 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
18266 install_element(BGP_VPNV4_NODE,
18267 &neighbor_remove_private_as_replace_as_cmd);
18268 install_element(BGP_VPNV4_NODE,
18269 &no_neighbor_remove_private_as_replace_as_cmd);
18270 install_element(BGP_VPNV4_NODE,
18271 &neighbor_remove_private_as_all_replace_as_cmd);
18272 install_element(BGP_VPNV4_NODE,
18273 &no_neighbor_remove_private_as_all_replace_as_cmd);
18274 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
18275 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
18276 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
18277 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
18278 install_element(BGP_VPNV6_NODE,
18279 &neighbor_remove_private_as_replace_as_cmd);
18280 install_element(BGP_VPNV6_NODE,
18281 &no_neighbor_remove_private_as_replace_as_cmd);
18282 install_element(BGP_VPNV6_NODE,
18283 &neighbor_remove_private_as_all_replace_as_cmd);
18284 install_element(BGP_VPNV6_NODE,
18285 &no_neighbor_remove_private_as_all_replace_as_cmd);
18286
18287 /* "neighbor send-community" commands.*/
18288 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
18289 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
18290 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
18291 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
18292 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
18293 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
18294 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
18295 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
18296 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
18297 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
18298 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
18299 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
18300 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
18301 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
18302 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
18303 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
18304 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
18305 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
18306 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
18307 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
18308 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
18309 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
18310 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
18311 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
18312 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
18313 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
18314 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
18315 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
18316 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
18317 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
18318 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
18319 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
18320 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
18321 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
18322 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
18323 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
18324
18325 /* "neighbor route-reflector" commands.*/
18326 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
18327 install_element(BGP_NODE,
18328 &no_neighbor_route_reflector_client_hidden_cmd);
18329 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
18330 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
18331 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
18332 install_element(BGP_IPV4M_NODE,
18333 &no_neighbor_route_reflector_client_cmd);
18334 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
18335 install_element(BGP_IPV4L_NODE,
18336 &no_neighbor_route_reflector_client_cmd);
18337 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
18338 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
18339 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
18340 install_element(BGP_IPV6M_NODE,
18341 &no_neighbor_route_reflector_client_cmd);
18342 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
18343 install_element(BGP_IPV6L_NODE,
18344 &no_neighbor_route_reflector_client_cmd);
18345 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
18346 install_element(BGP_VPNV4_NODE,
18347 &no_neighbor_route_reflector_client_cmd);
18348 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
18349 install_element(BGP_VPNV6_NODE,
18350 &no_neighbor_route_reflector_client_cmd);
18351 install_element(BGP_FLOWSPECV4_NODE,
18352 &neighbor_route_reflector_client_cmd);
18353 install_element(BGP_FLOWSPECV4_NODE,
18354 &no_neighbor_route_reflector_client_cmd);
18355 install_element(BGP_FLOWSPECV6_NODE,
18356 &neighbor_route_reflector_client_cmd);
18357 install_element(BGP_FLOWSPECV6_NODE,
18358 &no_neighbor_route_reflector_client_cmd);
18359 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
18360 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
18361
18362 /* "neighbor route-server" commands.*/
18363 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
18364 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
18365 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
18366 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
18367 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
18368 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
18369 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
18370 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
18371 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
18372 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
18373 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
18374 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
18375 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
18376 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
18377 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
18378 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
18379 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
18380 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
18381 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
18382 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
18383 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
18384 install_element(BGP_FLOWSPECV4_NODE,
18385 &no_neighbor_route_server_client_cmd);
18386 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
18387 install_element(BGP_FLOWSPECV6_NODE,
18388 &no_neighbor_route_server_client_cmd);
18389
18390 /* "neighbor addpath-tx-all-paths" commands.*/
18391 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
18392 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
18393 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18394 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18395 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18396 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18397 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18398 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18399 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18400 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18401 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
18402 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18403 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
18404 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18405 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
18406 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18407 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
18408 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
18409
18410 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
18411 install_element(BGP_NODE,
18412 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18413 install_element(BGP_NODE,
18414 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
18415 install_element(BGP_IPV4_NODE,
18416 &neighbor_addpath_tx_bestpath_per_as_cmd);
18417 install_element(BGP_IPV4_NODE,
18418 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18419 install_element(BGP_IPV4M_NODE,
18420 &neighbor_addpath_tx_bestpath_per_as_cmd);
18421 install_element(BGP_IPV4M_NODE,
18422 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18423 install_element(BGP_IPV4L_NODE,
18424 &neighbor_addpath_tx_bestpath_per_as_cmd);
18425 install_element(BGP_IPV4L_NODE,
18426 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18427 install_element(BGP_IPV6_NODE,
18428 &neighbor_addpath_tx_bestpath_per_as_cmd);
18429 install_element(BGP_IPV6_NODE,
18430 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18431 install_element(BGP_IPV6M_NODE,
18432 &neighbor_addpath_tx_bestpath_per_as_cmd);
18433 install_element(BGP_IPV6M_NODE,
18434 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18435 install_element(BGP_IPV6L_NODE,
18436 &neighbor_addpath_tx_bestpath_per_as_cmd);
18437 install_element(BGP_IPV6L_NODE,
18438 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18439 install_element(BGP_VPNV4_NODE,
18440 &neighbor_addpath_tx_bestpath_per_as_cmd);
18441 install_element(BGP_VPNV4_NODE,
18442 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18443 install_element(BGP_VPNV6_NODE,
18444 &neighbor_addpath_tx_bestpath_per_as_cmd);
18445 install_element(BGP_VPNV6_NODE,
18446 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
18447
18448 /* "neighbor sender-as-path-loop-detection" commands. */
18449 install_element(BGP_NODE, &neighbor_aspath_loop_detection_cmd);
18450 install_element(BGP_NODE, &no_neighbor_aspath_loop_detection_cmd);
18451
18452 /* "neighbor passive" commands. */
18453 install_element(BGP_NODE, &neighbor_passive_cmd);
18454 install_element(BGP_NODE, &no_neighbor_passive_cmd);
18455
18456
18457 /* "neighbor shutdown" commands. */
18458 install_element(BGP_NODE, &neighbor_shutdown_cmd);
18459 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
18460 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
18461 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
18462 install_element(BGP_NODE, &neighbor_shutdown_rtt_cmd);
18463 install_element(BGP_NODE, &no_neighbor_shutdown_rtt_cmd);
18464
18465 /* "neighbor capability extended-nexthop" commands.*/
18466 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
18467 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
18468
18469 /* "neighbor capability orf prefix-list" commands.*/
18470 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
18471 install_element(BGP_NODE,
18472 &no_neighbor_capability_orf_prefix_hidden_cmd);
18473 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
18474 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
18475 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
18476 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18477 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
18478 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18479 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
18480 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
18481 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
18482 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
18483 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
18484 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
18485
18486 /* "neighbor capability dynamic" commands.*/
18487 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
18488 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
18489
18490 /* "neighbor dont-capability-negotiate" commands. */
18491 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
18492 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
18493
18494 /* "neighbor ebgp-multihop" commands. */
18495 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
18496 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
18497 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
18498
18499 /* "neighbor disable-connected-check" commands. */
18500 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
18501 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
18502
18503 /* "neighbor enforce-first-as" commands. */
18504 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
18505 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
18506
18507 /* "neighbor description" commands. */
18508 install_element(BGP_NODE, &neighbor_description_cmd);
18509 install_element(BGP_NODE, &no_neighbor_description_cmd);
18510 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
18511
18512 /* "neighbor update-source" commands. "*/
18513 install_element(BGP_NODE, &neighbor_update_source_cmd);
18514 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
18515
18516 /* "neighbor default-originate" commands. */
18517 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
18518 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
18519 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
18520 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
18521 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
18522 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
18523 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
18524 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
18525 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
18526 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
18527 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
18528 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
18529 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
18530 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
18531 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
18532 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
18533 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
18534 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
18535 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
18536 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
18537 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
18538
18539 /* "neighbor port" commands. */
18540 install_element(BGP_NODE, &neighbor_port_cmd);
18541 install_element(BGP_NODE, &no_neighbor_port_cmd);
18542
18543 /* "neighbor weight" commands. */
18544 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
18545 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
18546
18547 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
18548 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
18549 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
18550 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
18551 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
18552 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
18553 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
18554 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
18555 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
18556 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
18557 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
18558 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
18559 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
18560 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
18561 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
18562 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
18563
18564 /* "neighbor override-capability" commands. */
18565 install_element(BGP_NODE, &neighbor_override_capability_cmd);
18566 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
18567
18568 /* "neighbor strict-capability-match" commands. */
18569 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
18570 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
18571
18572 /* "neighbor timers" commands. */
18573 install_element(BGP_NODE, &neighbor_timers_cmd);
18574 install_element(BGP_NODE, &no_neighbor_timers_cmd);
18575
18576 /* "neighbor timers connect" commands. */
18577 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
18578 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
18579
18580 /* "neighbor timers delayopen" commands. */
18581 install_element(BGP_NODE, &neighbor_timers_delayopen_cmd);
18582 install_element(BGP_NODE, &no_neighbor_timers_delayopen_cmd);
18583
18584 /* "neighbor advertisement-interval" commands. */
18585 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
18586 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
18587
18588 /* "neighbor interface" commands. */
18589 install_element(BGP_NODE, &neighbor_interface_cmd);
18590 install_element(BGP_NODE, &no_neighbor_interface_cmd);
18591
18592 /* "neighbor distribute" commands. */
18593 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
18594 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
18595 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
18596 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
18597 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
18598 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
18599 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
18600 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
18601 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
18602 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
18603 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
18604 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
18605 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
18606 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
18607 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
18608 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
18609 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
18610 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
18611
18612 /* "neighbor prefix-list" commands. */
18613 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
18614 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
18615 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
18616 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
18617 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
18618 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
18619 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
18620 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
18621 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
18622 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
18623 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
18624
18625 /* "neighbor filter-list" commands. */
18626 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
18627 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
18628 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
18629 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
18630 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
18631 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
18632 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
18633 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
18634 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
18635 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
18636 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
18637 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
18638 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
18639 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
18640 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
18641 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
18642 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
18643 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
18644 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
18645 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
18646 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
18647 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
18648
18649 /* "neighbor route-map" commands. */
18650 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
18651 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
18652 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
18653 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
18654 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
18655 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
18656 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
18657 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
18658 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
18659 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
18660 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
18661
18662 /* "neighbor unsuppress-map" commands. */
18663 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
18664 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
18665 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
18666 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
18667 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
18668 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
18669 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
18670 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
18671 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
18672 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
18673 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
18674 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
18675 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
18676 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
18677 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
18678 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
18679 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
18680 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
18681
18682 /* "neighbor advertise-map" commands. */
18683 install_element(BGP_NODE, &neighbor_advertise_map_hidden_cmd);
18684 install_element(BGP_IPV4_NODE, &neighbor_advertise_map_cmd);
18685 install_element(BGP_IPV4M_NODE, &neighbor_advertise_map_cmd);
18686 install_element(BGP_IPV4L_NODE, &neighbor_advertise_map_cmd);
18687 install_element(BGP_IPV6_NODE, &neighbor_advertise_map_cmd);
18688 install_element(BGP_IPV6M_NODE, &neighbor_advertise_map_cmd);
18689 install_element(BGP_IPV6L_NODE, &neighbor_advertise_map_cmd);
18690 install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd);
18691 install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd);
18692
18693 /* neighbor maximum-prefix-out commands. */
18694 install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd);
18695 install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd);
18696 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_out_cmd);
18697 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18698 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_out_cmd);
18699 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18700 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_out_cmd);
18701 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18702 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_out_cmd);
18703 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18704 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_out_cmd);
18705 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_out_cmd);
18706 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_out_cmd);
18707 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_out_cmd);
18708 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_out_cmd);
18709 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_out_cmd);
18710 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_out_cmd);
18711 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_out_cmd);
18712
18713 /* "neighbor maximum-prefix" commands. */
18714 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
18715 install_element(BGP_NODE,
18716 &neighbor_maximum_prefix_threshold_hidden_cmd);
18717 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
18718 install_element(BGP_NODE,
18719 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
18720 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
18721 install_element(BGP_NODE,
18722 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
18723 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
18724 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
18725 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18726 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18727 install_element(BGP_IPV4_NODE,
18728 &neighbor_maximum_prefix_threshold_warning_cmd);
18729 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18730 install_element(BGP_IPV4_NODE,
18731 &neighbor_maximum_prefix_threshold_restart_cmd);
18732 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
18733 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
18734 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18735 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
18736 install_element(BGP_IPV4M_NODE,
18737 &neighbor_maximum_prefix_threshold_warning_cmd);
18738 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
18739 install_element(BGP_IPV4M_NODE,
18740 &neighbor_maximum_prefix_threshold_restart_cmd);
18741 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
18742 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
18743 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18744 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
18745 install_element(BGP_IPV4L_NODE,
18746 &neighbor_maximum_prefix_threshold_warning_cmd);
18747 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
18748 install_element(BGP_IPV4L_NODE,
18749 &neighbor_maximum_prefix_threshold_restart_cmd);
18750 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
18751 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
18752 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18753 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18754 install_element(BGP_IPV6_NODE,
18755 &neighbor_maximum_prefix_threshold_warning_cmd);
18756 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18757 install_element(BGP_IPV6_NODE,
18758 &neighbor_maximum_prefix_threshold_restart_cmd);
18759 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
18760 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
18761 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
18762 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
18763 install_element(BGP_IPV6M_NODE,
18764 &neighbor_maximum_prefix_threshold_warning_cmd);
18765 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
18766 install_element(BGP_IPV6M_NODE,
18767 &neighbor_maximum_prefix_threshold_restart_cmd);
18768 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
18769 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
18770 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
18771 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
18772 install_element(BGP_IPV6L_NODE,
18773 &neighbor_maximum_prefix_threshold_warning_cmd);
18774 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
18775 install_element(BGP_IPV6L_NODE,
18776 &neighbor_maximum_prefix_threshold_restart_cmd);
18777 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
18778 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
18779 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
18780 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
18781 install_element(BGP_VPNV4_NODE,
18782 &neighbor_maximum_prefix_threshold_warning_cmd);
18783 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
18784 install_element(BGP_VPNV4_NODE,
18785 &neighbor_maximum_prefix_threshold_restart_cmd);
18786 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
18787 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
18788 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
18789 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
18790 install_element(BGP_VPNV6_NODE,
18791 &neighbor_maximum_prefix_threshold_warning_cmd);
18792 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
18793 install_element(BGP_VPNV6_NODE,
18794 &neighbor_maximum_prefix_threshold_restart_cmd);
18795 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
18796
18797 /* "neighbor allowas-in" */
18798 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
18799 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
18800 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
18801 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
18802 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
18803 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
18804 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
18805 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
18806 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
18807 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
18808 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
18809 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
18810 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
18811 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
18812 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
18813 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
18814 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
18815 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
18816 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
18817 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
18818
18819 /* "neighbor dampening" commands. */
18820 install_element(BGP_NODE, &neighbor_damp_cmd);
18821 install_element(BGP_NODE, &no_neighbor_damp_cmd);
18822 install_element(BGP_IPV4_NODE, &neighbor_damp_cmd);
18823 install_element(BGP_IPV4_NODE, &no_neighbor_damp_cmd);
18824 install_element(BGP_IPV4M_NODE, &neighbor_damp_cmd);
18825 install_element(BGP_IPV4M_NODE, &no_neighbor_damp_cmd);
18826 install_element(BGP_IPV4L_NODE, &neighbor_damp_cmd);
18827 install_element(BGP_IPV4L_NODE, &no_neighbor_damp_cmd);
18828 install_element(BGP_IPV6_NODE, &neighbor_damp_cmd);
18829 install_element(BGP_IPV6_NODE, &no_neighbor_damp_cmd);
18830 install_element(BGP_IPV6M_NODE, &neighbor_damp_cmd);
18831 install_element(BGP_IPV6M_NODE, &no_neighbor_damp_cmd);
18832 install_element(BGP_IPV6L_NODE, &neighbor_damp_cmd);
18833 install_element(BGP_IPV6L_NODE, &no_neighbor_damp_cmd);
18834 install_element(VIEW_NODE, &show_ip_bgp_neighbor_damp_param_cmd);
18835
18836 /* address-family commands. */
18837 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
18838 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
18839#ifdef KEEP_OLD_VPN_COMMANDS
18840 install_element(BGP_NODE, &address_family_vpnv4_cmd);
18841 install_element(BGP_NODE, &address_family_vpnv6_cmd);
18842#endif /* KEEP_OLD_VPN_COMMANDS */
18843
18844 install_element(BGP_NODE, &address_family_evpn_cmd);
18845
18846 /* "exit-address-family" command. */
18847 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
18848 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
18849 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
18850 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
18851 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
18852 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
18853 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
18854 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
18855 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
18856 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
18857 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
18858
18859 /* "clear ip bgp commands" */
18860 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
18861
18862 /* clear ip bgp prefix */
18863 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
18864 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
18865 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
18866
18867 /* "show [ip] bgp summary" commands. */
18868 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
18869 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
18870 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
18871 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
18872 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
18873 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
18874 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
18875
18876 /* "show [ip] bgp neighbors" commands. */
18877 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
18878
18879 install_element(VIEW_NODE, &show_ip_bgp_neighbors_graceful_restart_cmd);
18880
18881 /* "show [ip] bgp peer-group" commands. */
18882 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
18883
18884 /* "show [ip] bgp paths" commands. */
18885 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
18886
18887 /* "show [ip] bgp community" commands. */
18888 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
18889
18890 /* "show ip bgp large-community" commands. */
18891 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
18892 /* "show [ip] bgp attribute-info" commands. */
18893 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
18894 /* "show [ip] bgp route-leak" command */
18895 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
18896
18897 /* "redistribute" commands. */
18898 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
18899 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
18900 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
18901 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
18902 install_element(BGP_NODE,
18903 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
18904 install_element(BGP_NODE,
18905 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
18906 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
18907 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
18908 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
18909 install_element(BGP_NODE,
18910 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
18911 install_element(BGP_NODE,
18912 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
18913 install_element(BGP_NODE,
18914 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
18915 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
18916 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
18917 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
18918 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
18919 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
18920 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
18921 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
18922 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
18923 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
18924 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
18925 install_element(BGP_IPV4_NODE,
18926 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
18927 install_element(BGP_IPV4_NODE,
18928 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
18929 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
18930 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
18931 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
18932 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
18933 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
18934 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
18935
18936 /* import|export vpn [route-map WORD] */
18937 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
18938 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
18939
18940 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
18941 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
18942
18943 /* ttl_security commands */
18944 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
18945 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
18946
18947 /* "show [ip] bgp memory" commands. */
18948 install_element(VIEW_NODE, &show_bgp_memory_cmd);
18949
18950 /* "show bgp martian next-hop" */
18951 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
18952
18953 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
18954
18955 /* "show [ip] bgp views" commands. */
18956 install_element(VIEW_NODE, &show_bgp_views_cmd);
18957
18958 /* "show [ip] bgp vrfs" commands. */
18959 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
18960
18961 /* Community-list. */
18962 community_list_vty();
18963
18964 /* vpn-policy commands */
18965 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
18966 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
18967 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
18968 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
18969 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
18970 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
18971 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
18972 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
18973 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
18974 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
18975 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
18976 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
18977
18978 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
18979 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
18980
18981 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
18982 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
18983 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
18984 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
18985 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
18986 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
18987 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
18988 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
18989 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
18990 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
18991}
18992
18993#include "memory.h"
18994#include "bgp_regex.h"
18995#include "bgp_clist.h"
18996#include "bgp_ecommunity.h"
18997
18998/* VTY functions. */
18999
19000/* Direction value to string conversion. */
19001static const char *community_direct_str(int direct)
19002{
19003 switch (direct) {
19004 case COMMUNITY_DENY:
19005 return "deny";
19006 case COMMUNITY_PERMIT:
19007 return "permit";
19008 default:
19009 return "unknown";
19010 }
19011}
19012
19013/* Display error string. */
19014static void community_list_perror(struct vty *vty, int ret)
19015{
19016 switch (ret) {
19017 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
19018 vty_out(vty, "%% Can't find community-list\n");
19019 break;
19020 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
19021 vty_out(vty, "%% Malformed community-list value\n");
19022 break;
19023 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
19024 vty_out(vty,
19025 "%% Community name conflict, previously defined as standard community\n");
19026 break;
19027 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
19028 vty_out(vty,
19029 "%% Community name conflict, previously defined as expanded community\n");
19030 break;
19031 }
19032}
19033
19034/* "community-list" keyword help string. */
19035#define COMMUNITY_LIST_STR "Add a community list entry\n"
19036
19037/*community-list standard */
19038DEFUN (community_list_standard,
19039 bgp_community_list_standard_cmd,
19040 "bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19041 BGP_STR
19042 COMMUNITY_LIST_STR
19043 "Community list number (standard)\n"
19044 "Add an standard community-list entry\n"
19045 "Community list name\n"
19046 "Sequence number of an entry\n"
19047 "Sequence number\n"
19048 "Specify community to reject\n"
19049 "Specify community to accept\n"
19050 COMMUNITY_VAL_STR)
19051{
19052 char *cl_name_or_number = NULL;
19053 char *seq = NULL;
19054 int direct = 0;
19055 int style = COMMUNITY_LIST_STANDARD;
19056 int idx = 0;
19057
19058 argv_find(argv, argc, "(1-4294967295)", &idx);
19059 if (idx)
19060 seq = argv[idx]->arg;
19061
19062 idx = 0;
19063 argv_find(argv, argc, "(1-99)", &idx);
19064 argv_find(argv, argc, "WORD", &idx);
19065 cl_name_or_number = argv[idx]->arg;
19066 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19067 : COMMUNITY_DENY;
19068 argv_find(argv, argc, "AA:NN", &idx);
19069 char *str = argv_concat(argv, argc, idx);
19070
19071 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19072 direct, style);
19073
19074 XFREE(MTYPE_TMP, str);
19075
19076 if (ret < 0) {
19077 /* Display error string. */
19078 community_list_perror(vty, ret);
19079 return CMD_WARNING_CONFIG_FAILED;
19080 }
19081
19082 return CMD_SUCCESS;
19083}
19084
19085DEFUN (no_community_list_standard_all,
19086 no_bgp_community_list_standard_all_cmd,
19087 "no bgp community-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19088 NO_STR
19089 BGP_STR
19090 COMMUNITY_LIST_STR
19091 "Community list number (standard)\n"
19092 "Add an standard community-list entry\n"
19093 "Community list name\n"
19094 "Sequence number of an entry\n"
19095 "Sequence number\n"
19096 "Specify community to reject\n"
19097 "Specify community to accept\n"
19098 COMMUNITY_VAL_STR)
19099{
19100 char *cl_name_or_number = NULL;
19101 char *str = NULL;
19102 int direct = 0;
19103 int style = COMMUNITY_LIST_STANDARD;
19104 char *seq = NULL;
19105 int idx = 0;
19106
19107 argv_find(argv, argc, "(1-4294967295)", &idx);
19108 if (idx)
19109 seq = argv[idx]->arg;
19110
19111 idx = 0;
19112 argv_find(argv, argc, "permit", &idx);
19113 argv_find(argv, argc, "deny", &idx);
19114
19115 if (idx) {
19116 direct = argv_find(argv, argc, "permit", &idx)
19117 ? COMMUNITY_PERMIT
19118 : COMMUNITY_DENY;
19119
19120 idx = 0;
19121 argv_find(argv, argc, "AA:NN", &idx);
19122 str = argv_concat(argv, argc, idx);
19123 }
19124
19125 idx = 0;
19126 argv_find(argv, argc, "(1-99)", &idx);
19127 argv_find(argv, argc, "WORD", &idx);
19128 cl_name_or_number = argv[idx]->arg;
19129
19130 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19131 direct, style);
19132
19133 XFREE(MTYPE_TMP, str);
19134
19135 if (ret < 0) {
19136 community_list_perror(vty, ret);
19137 return CMD_WARNING_CONFIG_FAILED;
19138 }
19139
19140 return CMD_SUCCESS;
19141}
19142
19143ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
19144 "no bgp community-list <(1-99)|standard WORD>",
19145 NO_STR BGP_STR COMMUNITY_LIST_STR
19146 "Community list number (standard)\n"
19147 "Add an standard community-list entry\n"
19148 "Community list name\n")
19149
19150/*community-list expanded */
19151DEFUN (community_list_expanded_all,
19152 bgp_community_list_expanded_all_cmd,
19153 "bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19154 BGP_STR
19155 COMMUNITY_LIST_STR
19156 "Community list number (expanded)\n"
19157 "Add an expanded community-list entry\n"
19158 "Community list name\n"
19159 "Sequence number of an entry\n"
19160 "Sequence number\n"
19161 "Specify community to reject\n"
19162 "Specify community to accept\n"
19163 COMMUNITY_VAL_STR)
19164{
19165 char *cl_name_or_number = NULL;
19166 char *seq = NULL;
19167 int direct = 0;
19168 int style = COMMUNITY_LIST_EXPANDED;
19169 int idx = 0;
19170
19171 argv_find(argv, argc, "(1-4294967295)", &idx);
19172 if (idx)
19173 seq = argv[idx]->arg;
19174
19175 idx = 0;
19176
19177 argv_find(argv, argc, "(100-500)", &idx);
19178 argv_find(argv, argc, "WORD", &idx);
19179 cl_name_or_number = argv[idx]->arg;
19180 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19181 : COMMUNITY_DENY;
19182 argv_find(argv, argc, "AA:NN", &idx);
19183 char *str = argv_concat(argv, argc, idx);
19184
19185 int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq,
19186 direct, style);
19187
19188 XFREE(MTYPE_TMP, str);
19189
19190 if (ret < 0) {
19191 /* Display error string. */
19192 community_list_perror(vty, ret);
19193 return CMD_WARNING_CONFIG_FAILED;
19194 }
19195
19196 return CMD_SUCCESS;
19197}
19198
19199DEFUN (no_community_list_expanded_all,
19200 no_bgp_community_list_expanded_all_cmd,
19201 "no bgp community-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19202 NO_STR
19203 BGP_STR
19204 COMMUNITY_LIST_STR
19205 "Community list number (expanded)\n"
19206 "Add an expanded community-list entry\n"
19207 "Community list name\n"
19208 "Sequence number of an entry\n"
19209 "Sequence number\n"
19210 "Specify community to reject\n"
19211 "Specify community to accept\n"
19212 COMMUNITY_VAL_STR)
19213{
19214 char *cl_name_or_number = NULL;
19215 char *seq = NULL;
19216 char *str = NULL;
19217 int direct = 0;
19218 int style = COMMUNITY_LIST_EXPANDED;
19219 int idx = 0;
19220
19221 argv_find(argv, argc, "(1-4294967295)", &idx);
19222 if (idx)
19223 seq = argv[idx]->arg;
19224
19225 idx = 0;
19226 argv_find(argv, argc, "permit", &idx);
19227 argv_find(argv, argc, "deny", &idx);
19228
19229 if (idx) {
19230 direct = argv_find(argv, argc, "permit", &idx)
19231 ? COMMUNITY_PERMIT
19232 : COMMUNITY_DENY;
19233
19234 idx = 0;
19235 argv_find(argv, argc, "AA:NN", &idx);
19236 str = argv_concat(argv, argc, idx);
19237 }
19238
19239 idx = 0;
19240 argv_find(argv, argc, "(100-500)", &idx);
19241 argv_find(argv, argc, "WORD", &idx);
19242 cl_name_or_number = argv[idx]->arg;
19243
19244 int ret = community_list_unset(bgp_clist, cl_name_or_number, str, seq,
19245 direct, style);
19246
19247 XFREE(MTYPE_TMP, str);
19248
19249 if (ret < 0) {
19250 community_list_perror(vty, ret);
19251 return CMD_WARNING_CONFIG_FAILED;
19252 }
19253
19254 return CMD_SUCCESS;
19255}
19256
19257ALIAS(no_community_list_expanded_all,
19258 no_bgp_community_list_expanded_all_list_cmd,
19259 "no bgp community-list <(100-500)|expanded WORD>",
19260 NO_STR BGP_STR COMMUNITY_LIST_STR
19261 "Community list number (expanded)\n"
19262 "Add an expanded community-list entry\n"
19263 "Community list name\n")
19264
19265/* Return configuration string of community-list entry. */
19266static const char *community_list_config_str(struct community_entry *entry)
19267{
19268 const char *str;
19269
19270 if (entry->any)
19271 str = "";
19272 else {
19273 if (entry->style == COMMUNITY_LIST_STANDARD)
19274 str = community_str(entry->u.com, false);
19275 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
19276 str = lcommunity_str(entry->u.lcom, false);
19277 else
19278 str = entry->config;
19279 }
19280 return str;
19281}
19282
19283static void community_list_show(struct vty *vty, struct community_list *list)
19284{
19285 struct community_entry *entry;
19286
19287 for (entry = list->head; entry; entry = entry->next) {
19288 if (entry == list->head) {
19289 if (all_digit(list->name))
19290 vty_out(vty, "Community %s list %s\n",
19291 entry->style == COMMUNITY_LIST_STANDARD
19292 ? "standard"
19293 : "(expanded) access",
19294 list->name);
19295 else
19296 vty_out(vty, "Named Community %s list %s\n",
19297 entry->style == COMMUNITY_LIST_STANDARD
19298 ? "standard"
19299 : "expanded",
19300 list->name);
19301 }
19302 if (entry->any)
19303 vty_out(vty, " %s\n",
19304 community_direct_str(entry->direct));
19305 else
19306 vty_out(vty, " %s %s\n",
19307 community_direct_str(entry->direct),
19308 community_list_config_str(entry));
19309 }
19310}
19311
19312DEFUN (show_community_list,
19313 show_bgp_community_list_cmd,
19314 "show bgp community-list",
19315 SHOW_STR
19316 BGP_STR
19317 "List community-list\n")
19318{
19319 struct community_list *list;
19320 struct community_list_master *cm;
19321
19322 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
19323 if (!cm)
19324 return CMD_SUCCESS;
19325
19326 for (list = cm->num.head; list; list = list->next)
19327 community_list_show(vty, list);
19328
19329 for (list = cm->str.head; list; list = list->next)
19330 community_list_show(vty, list);
19331
19332 return CMD_SUCCESS;
19333}
19334
19335DEFUN (show_community_list_arg,
19336 show_bgp_community_list_arg_cmd,
19337 "show bgp community-list <(1-500)|WORD> detail",
19338 SHOW_STR
19339 BGP_STR
19340 "List community-list\n"
19341 "Community-list number\n"
19342 "Community-list name\n"
19343 "Detailed information on community-list\n")
19344{
19345 int idx_comm_list = 3;
19346 struct community_list *list;
19347
19348 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
19349 COMMUNITY_LIST_MASTER);
19350 if (!list) {
19351 vty_out(vty, "%% Can't find community-list\n");
19352 return CMD_WARNING;
19353 }
19354
19355 community_list_show(vty, list);
19356
19357 return CMD_SUCCESS;
19358}
19359
19360/*
19361 * Large Community code.
19362 */
19363static int lcommunity_list_set_vty(struct vty *vty, int argc,
19364 struct cmd_token **argv, int style,
19365 int reject_all_digit_name)
19366{
19367 int ret;
19368 int direct;
19369 char *str;
19370 int idx = 0;
19371 char *cl_name;
19372 char *seq = NULL;
19373
19374 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19375 seq = argv[idx]->arg;
19376
19377 idx = 0;
19378 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19379 : COMMUNITY_DENY;
19380
19381 /* All digit name check. */
19382 idx = 0;
19383 argv_find(argv, argc, "WORD", &idx);
19384 argv_find(argv, argc, "(1-99)", &idx);
19385 argv_find(argv, argc, "(100-500)", &idx);
19386 cl_name = argv[idx]->arg;
19387 if (reject_all_digit_name && all_digit(cl_name)) {
19388 vty_out(vty, "%% Community name cannot have all digits\n");
19389 return CMD_WARNING_CONFIG_FAILED;
19390 }
19391
19392 idx = 0;
19393 argv_find(argv, argc, "AA:BB:CC", &idx);
19394 argv_find(argv, argc, "LINE", &idx);
19395 /* Concat community string argument. */
19396 if (idx)
19397 str = argv_concat(argv, argc, idx);
19398 else
19399 str = NULL;
19400
19401 ret = lcommunity_list_set(bgp_clist, cl_name, str, seq, direct, style);
19402
19403 /* Free temporary community list string allocated by
19404 argv_concat(). */
19405 XFREE(MTYPE_TMP, str);
19406
19407 if (ret < 0) {
19408 community_list_perror(vty, ret);
19409 return CMD_WARNING_CONFIG_FAILED;
19410 }
19411 return CMD_SUCCESS;
19412}
19413
19414static int lcommunity_list_unset_vty(struct vty *vty, int argc,
19415 struct cmd_token **argv, int style)
19416{
19417 int ret;
19418 int direct = 0;
19419 char *str = NULL;
19420 int idx = 0;
19421 char *seq = NULL;
19422
19423 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19424 seq = argv[idx]->arg;
19425
19426 idx = 0;
19427 argv_find(argv, argc, "permit", &idx);
19428 argv_find(argv, argc, "deny", &idx);
19429
19430 if (idx) {
19431 /* Check the list direct. */
19432 if (strncmp(argv[idx]->arg, "p", 1) == 0)
19433 direct = COMMUNITY_PERMIT;
19434 else
19435 direct = COMMUNITY_DENY;
19436
19437 idx = 0;
19438 argv_find(argv, argc, "LINE", &idx);
19439 argv_find(argv, argc, "AA:AA:NN", &idx);
19440 /* Concat community string argument. */
19441 str = argv_concat(argv, argc, idx);
19442 }
19443
19444 idx = 0;
19445 argv_find(argv, argc, "(1-99)", &idx);
19446 argv_find(argv, argc, "(100-500)", &idx);
19447 argv_find(argv, argc, "WORD", &idx);
19448
19449 /* Unset community list. */
19450 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, seq, direct,
19451 style);
19452
19453 /* Free temporary community list string allocated by
19454 argv_concat(). */
19455 XFREE(MTYPE_TMP, str);
19456
19457 if (ret < 0) {
19458 community_list_perror(vty, ret);
19459 return CMD_WARNING_CONFIG_FAILED;
19460 }
19461
19462 return CMD_SUCCESS;
19463}
19464
19465/* "large-community-list" keyword help string. */
19466#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
19467#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
19468
19469DEFUN (lcommunity_list_standard,
19470 bgp_lcommunity_list_standard_cmd,
19471 "bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19472 BGP_STR
19473 LCOMMUNITY_LIST_STR
19474 "Large Community list number (standard)\n"
19475 "Sequence number of an entry\n"
19476 "Sequence number\n"
19477 "Specify large community to reject\n"
19478 "Specify large community to accept\n"
19479 LCOMMUNITY_VAL_STR)
19480{
19481 return lcommunity_list_set_vty(vty, argc, argv,
19482 LARGE_COMMUNITY_LIST_STANDARD, 0);
19483}
19484
19485DEFUN (lcommunity_list_expanded,
19486 bgp_lcommunity_list_expanded_cmd,
19487 "bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19488 BGP_STR
19489 LCOMMUNITY_LIST_STR
19490 "Large Community list number (expanded)\n"
19491 "Sequence number of an entry\n"
19492 "Sequence number\n"
19493 "Specify large community to reject\n"
19494 "Specify large community to accept\n"
19495 "An ordered list as a regular-expression\n")
19496{
19497 return lcommunity_list_set_vty(vty, argc, argv,
19498 LARGE_COMMUNITY_LIST_EXPANDED, 0);
19499}
19500
19501DEFUN (lcommunity_list_name_standard,
19502 bgp_lcommunity_list_name_standard_cmd,
19503 "bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:BB:CC...",
19504 BGP_STR
19505 LCOMMUNITY_LIST_STR
19506 "Specify standard large-community-list\n"
19507 "Large Community list name\n"
19508 "Sequence number of an entry\n"
19509 "Sequence number\n"
19510 "Specify large community to reject\n"
19511 "Specify large community to accept\n"
19512 LCOMMUNITY_VAL_STR)
19513{
19514 return lcommunity_list_set_vty(vty, argc, argv,
19515 LARGE_COMMUNITY_LIST_STANDARD, 1);
19516}
19517
19518DEFUN (lcommunity_list_name_expanded,
19519 bgp_lcommunity_list_name_expanded_cmd,
19520 "bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19521 BGP_STR
19522 LCOMMUNITY_LIST_STR
19523 "Specify expanded large-community-list\n"
19524 "Large Community list name\n"
19525 "Sequence number of an entry\n"
19526 "Sequence number\n"
19527 "Specify large community to reject\n"
19528 "Specify large community to accept\n"
19529 "An ordered list as a regular-expression\n")
19530{
19531 return lcommunity_list_set_vty(vty, argc, argv,
19532 LARGE_COMMUNITY_LIST_EXPANDED, 1);
19533}
19534
19535DEFUN (no_lcommunity_list_all,
19536 no_bgp_lcommunity_list_all_cmd,
19537 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
19538 NO_STR
19539 BGP_STR
19540 LCOMMUNITY_LIST_STR
19541 "Large Community list number (standard)\n"
19542 "Large Community list number (expanded)\n"
19543 "Large Community list name\n")
19544{
19545 return lcommunity_list_unset_vty(vty, argc, argv,
19546 LARGE_COMMUNITY_LIST_STANDARD);
19547}
19548
19549DEFUN (no_lcommunity_list_name_standard_all,
19550 no_bgp_lcommunity_list_name_standard_all_cmd,
19551 "no bgp large-community-list standard WORD",
19552 NO_STR
19553 BGP_STR
19554 LCOMMUNITY_LIST_STR
19555 "Specify standard large-community-list\n"
19556 "Large Community list name\n")
19557{
19558 return lcommunity_list_unset_vty(vty, argc, argv,
19559 LARGE_COMMUNITY_LIST_STANDARD);
19560}
19561
19562DEFUN (no_lcommunity_list_name_expanded_all,
19563 no_bgp_lcommunity_list_name_expanded_all_cmd,
19564 "no bgp large-community-list expanded WORD",
19565 NO_STR
19566 BGP_STR
19567 LCOMMUNITY_LIST_STR
19568 "Specify expanded large-community-list\n"
19569 "Large Community list name\n")
19570{
19571 return lcommunity_list_unset_vty(vty, argc, argv,
19572 LARGE_COMMUNITY_LIST_EXPANDED);
19573}
19574
19575DEFUN (no_lcommunity_list_standard,
19576 no_bgp_lcommunity_list_standard_cmd,
19577 "no bgp large-community-list (1-99) [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19578 NO_STR
19579 BGP_STR
19580 LCOMMUNITY_LIST_STR
19581 "Large Community list number (standard)\n"
19582 "Sequence number of an entry\n"
19583 "Sequence number\n"
19584 "Specify large community to reject\n"
19585 "Specify large community to accept\n"
19586 LCOMMUNITY_VAL_STR)
19587{
19588 return lcommunity_list_unset_vty(vty, argc, argv,
19589 LARGE_COMMUNITY_LIST_STANDARD);
19590}
19591
19592DEFUN (no_lcommunity_list_expanded,
19593 no_bgp_lcommunity_list_expanded_cmd,
19594 "no bgp large-community-list (100-500) [seq (1-4294967295)] <deny|permit> LINE...",
19595 NO_STR
19596 BGP_STR
19597 LCOMMUNITY_LIST_STR
19598 "Large Community list number (expanded)\n"
19599 "Sequence number of an entry\n"
19600 "Sequence number\n"
19601 "Specify large community to reject\n"
19602 "Specify large community to accept\n"
19603 "An ordered list as a regular-expression\n")
19604{
19605 return lcommunity_list_unset_vty(vty, argc, argv,
19606 LARGE_COMMUNITY_LIST_EXPANDED);
19607}
19608
19609DEFUN (no_lcommunity_list_name_standard,
19610 no_bgp_lcommunity_list_name_standard_cmd,
19611 "no bgp large-community-list standard WORD [seq (1-4294967295)] <deny|permit> AA:AA:NN...",
19612 NO_STR
19613 BGP_STR
19614 LCOMMUNITY_LIST_STR
19615 "Specify standard large-community-list\n"
19616 "Large Community list name\n"
19617 "Sequence number of an entry\n"
19618 "Sequence number\n"
19619 "Specify large community to reject\n"
19620 "Specify large community to accept\n"
19621 LCOMMUNITY_VAL_STR)
19622{
19623 return lcommunity_list_unset_vty(vty, argc, argv,
19624 LARGE_COMMUNITY_LIST_STANDARD);
19625}
19626
19627DEFUN (no_lcommunity_list_name_expanded,
19628 no_bgp_lcommunity_list_name_expanded_cmd,
19629 "no bgp large-community-list expanded WORD [seq (1-4294967295)] <deny|permit> LINE...",
19630 NO_STR
19631 BGP_STR
19632 LCOMMUNITY_LIST_STR
19633 "Specify expanded large-community-list\n"
19634 "Large community list name\n"
19635 "Sequence number of an entry\n"
19636 "Sequence number\n"
19637 "Specify large community to reject\n"
19638 "Specify large community to accept\n"
19639 "An ordered list as a regular-expression\n")
19640{
19641 return lcommunity_list_unset_vty(vty, argc, argv,
19642 LARGE_COMMUNITY_LIST_EXPANDED);
19643}
19644
19645static void lcommunity_list_show(struct vty *vty, struct community_list *list)
19646{
19647 struct community_entry *entry;
19648
19649 for (entry = list->head; entry; entry = entry->next) {
19650 if (entry == list->head) {
19651 if (all_digit(list->name))
19652 vty_out(vty, "Large community %s list %s\n",
19653 entry->style ==
19654 LARGE_COMMUNITY_LIST_STANDARD
19655 ? "standard"
19656 : "(expanded) access",
19657 list->name);
19658 else
19659 vty_out(vty,
19660 "Named large community %s list %s\n",
19661 entry->style ==
19662 LARGE_COMMUNITY_LIST_STANDARD
19663 ? "standard"
19664 : "expanded",
19665 list->name);
19666 }
19667 if (entry->any)
19668 vty_out(vty, " %s\n",
19669 community_direct_str(entry->direct));
19670 else
19671 vty_out(vty, " %s %s\n",
19672 community_direct_str(entry->direct),
19673 community_list_config_str(entry));
19674 }
19675}
19676
19677DEFUN (show_lcommunity_list,
19678 show_bgp_lcommunity_list_cmd,
19679 "show bgp large-community-list",
19680 SHOW_STR
19681 BGP_STR
19682 "List large-community list\n")
19683{
19684 struct community_list *list;
19685 struct community_list_master *cm;
19686
19687 cm = community_list_master_lookup(bgp_clist,
19688 LARGE_COMMUNITY_LIST_MASTER);
19689 if (!cm)
19690 return CMD_SUCCESS;
19691
19692 for (list = cm->num.head; list; list = list->next)
19693 lcommunity_list_show(vty, list);
19694
19695 for (list = cm->str.head; list; list = list->next)
19696 lcommunity_list_show(vty, list);
19697
19698 return CMD_SUCCESS;
19699}
19700
19701DEFUN (show_lcommunity_list_arg,
19702 show_bgp_lcommunity_list_arg_cmd,
19703 "show bgp large-community-list <(1-500)|WORD> detail",
19704 SHOW_STR
19705 BGP_STR
19706 "List large-community list\n"
19707 "Large-community-list number\n"
19708 "Large-community-list name\n"
19709 "Detailed information on large-community-list\n")
19710{
19711 struct community_list *list;
19712
19713 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
19714 LARGE_COMMUNITY_LIST_MASTER);
19715 if (!list) {
19716 vty_out(vty, "%% Can't find large-community-list\n");
19717 return CMD_WARNING;
19718 }
19719
19720 lcommunity_list_show(vty, list);
19721
19722 return CMD_SUCCESS;
19723}
19724
19725/* "extcommunity-list" keyword help string. */
19726#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
19727#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
19728
19729DEFUN (extcommunity_list_standard,
19730 bgp_extcommunity_list_standard_cmd,
19731 "bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19732 BGP_STR
19733 EXTCOMMUNITY_LIST_STR
19734 "Extended Community list number (standard)\n"
19735 "Specify standard extcommunity-list\n"
19736 "Community list name\n"
19737 "Sequence number of an entry\n"
19738 "Sequence number\n"
19739 "Specify community to reject\n"
19740 "Specify community to accept\n"
19741 EXTCOMMUNITY_VAL_STR)
19742{
19743 int style = EXTCOMMUNITY_LIST_STANDARD;
19744 int direct = 0;
19745 char *cl_number_or_name = NULL;
19746 char *seq = NULL;
19747
19748 int idx = 0;
19749
19750 argv_find(argv, argc, "(1-99)", &idx);
19751 argv_find(argv, argc, "WORD", &idx);
19752 cl_number_or_name = argv[idx]->arg;
19753
19754 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19755 seq = argv[idx]->arg;
19756
19757 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19758 : COMMUNITY_DENY;
19759 argv_find(argv, argc, "AA:NN", &idx);
19760 char *str = argv_concat(argv, argc, idx);
19761
19762 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19763 direct, style);
19764
19765 XFREE(MTYPE_TMP, str);
19766
19767 if (ret < 0) {
19768 community_list_perror(vty, ret);
19769 return CMD_WARNING_CONFIG_FAILED;
19770 }
19771
19772 return CMD_SUCCESS;
19773}
19774
19775DEFUN (extcommunity_list_name_expanded,
19776 bgp_extcommunity_list_name_expanded_cmd,
19777 "bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19778 BGP_STR
19779 EXTCOMMUNITY_LIST_STR
19780 "Extended Community list number (expanded)\n"
19781 "Specify expanded extcommunity-list\n"
19782 "Extended Community list name\n"
19783 "Sequence number of an entry\n"
19784 "Sequence number\n"
19785 "Specify community to reject\n"
19786 "Specify community to accept\n"
19787 "An ordered list as a regular-expression\n")
19788{
19789 int style = EXTCOMMUNITY_LIST_EXPANDED;
19790 int direct = 0;
19791 char *cl_number_or_name = NULL;
19792 char *seq = NULL;
19793 int idx = 0;
19794
19795 argv_find(argv, argc, "(100-500)", &idx);
19796 argv_find(argv, argc, "WORD", &idx);
19797 cl_number_or_name = argv[idx]->arg;
19798
19799 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19800 seq = argv[idx]->arg;
19801
19802 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
19803 : COMMUNITY_DENY;
19804 argv_find(argv, argc, "LINE", &idx);
19805 char *str = argv_concat(argv, argc, idx);
19806
19807 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str, seq,
19808 direct, style);
19809
19810 XFREE(MTYPE_TMP, str);
19811
19812 if (ret < 0) {
19813 community_list_perror(vty, ret);
19814 return CMD_WARNING_CONFIG_FAILED;
19815 }
19816
19817 return CMD_SUCCESS;
19818}
19819
19820DEFUN (no_extcommunity_list_standard_all,
19821 no_bgp_extcommunity_list_standard_all_cmd,
19822 "no bgp extcommunity-list <(1-99)|standard WORD> [seq (1-4294967295)] <deny|permit> AA:NN...",
19823 NO_STR
19824 BGP_STR
19825 EXTCOMMUNITY_LIST_STR
19826 "Extended Community list number (standard)\n"
19827 "Specify standard extcommunity-list\n"
19828 "Community list name\n"
19829 "Sequence number of an entry\n"
19830 "Sequence number\n"
19831 "Specify community to reject\n"
19832 "Specify community to accept\n"
19833 EXTCOMMUNITY_VAL_STR)
19834{
19835 int style = EXTCOMMUNITY_LIST_STANDARD;
19836 int direct = 0;
19837 char *cl_number_or_name = NULL;
19838 char *str = NULL;
19839 char *seq = NULL;
19840 int idx = 0;
19841
19842 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19843 seq = argv[idx]->arg;
19844
19845 idx = 0;
19846 argv_find(argv, argc, "permit", &idx);
19847 argv_find(argv, argc, "deny", &idx);
19848 if (idx) {
19849 direct = argv_find(argv, argc, "permit", &idx)
19850 ? COMMUNITY_PERMIT
19851 : COMMUNITY_DENY;
19852
19853 idx = 0;
19854 argv_find(argv, argc, "AA:NN", &idx);
19855 str = argv_concat(argv, argc, idx);
19856 }
19857
19858 idx = 0;
19859 argv_find(argv, argc, "(1-99)", &idx);
19860 argv_find(argv, argc, "WORD", &idx);
19861 cl_number_or_name = argv[idx]->arg;
19862
19863 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19864 seq, direct, style);
19865
19866 XFREE(MTYPE_TMP, str);
19867
19868 if (ret < 0) {
19869 community_list_perror(vty, ret);
19870 return CMD_WARNING_CONFIG_FAILED;
19871 }
19872
19873 return CMD_SUCCESS;
19874}
19875
19876ALIAS(no_extcommunity_list_standard_all,
19877 no_bgp_extcommunity_list_standard_all_list_cmd,
19878 "no bgp extcommunity-list <(1-99)|standard WORD>",
19879 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19880 "Extended Community list number (standard)\n"
19881 "Specify standard extcommunity-list\n"
19882 "Community list name\n")
19883
19884DEFUN (no_extcommunity_list_expanded_all,
19885 no_bgp_extcommunity_list_expanded_all_cmd,
19886 "no bgp extcommunity-list <(100-500)|expanded WORD> [seq (1-4294967295)] <deny|permit> LINE...",
19887 NO_STR
19888 BGP_STR
19889 EXTCOMMUNITY_LIST_STR
19890 "Extended Community list number (expanded)\n"
19891 "Specify expanded extcommunity-list\n"
19892 "Extended Community list name\n"
19893 "Sequence number of an entry\n"
19894 "Sequence number\n"
19895 "Specify community to reject\n"
19896 "Specify community to accept\n"
19897 "An ordered list as a regular-expression\n")
19898{
19899 int style = EXTCOMMUNITY_LIST_EXPANDED;
19900 int direct = 0;
19901 char *cl_number_or_name = NULL;
19902 char *str = NULL;
19903 char *seq = NULL;
19904 int idx = 0;
19905
19906 if (argv_find(argv, argc, "(1-4294967295)", &idx))
19907 seq = argv[idx]->arg;
19908
19909 idx = 0;
19910 argv_find(argv, argc, "permit", &idx);
19911 argv_find(argv, argc, "deny", &idx);
19912
19913 if (idx) {
19914 direct = argv_find(argv, argc, "permit", &idx)
19915 ? COMMUNITY_PERMIT
19916 : COMMUNITY_DENY;
19917
19918 idx = 0;
19919 argv_find(argv, argc, "LINE", &idx);
19920 str = argv_concat(argv, argc, idx);
19921 }
19922
19923 idx = 0;
19924 argv_find(argv, argc, "(100-500)", &idx);
19925 argv_find(argv, argc, "WORD", &idx);
19926 cl_number_or_name = argv[idx]->arg;
19927
19928 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
19929 seq, direct, style);
19930
19931 XFREE(MTYPE_TMP, str);
19932
19933 if (ret < 0) {
19934 community_list_perror(vty, ret);
19935 return CMD_WARNING_CONFIG_FAILED;
19936 }
19937
19938 return CMD_SUCCESS;
19939}
19940
19941ALIAS(no_extcommunity_list_expanded_all,
19942 no_bgp_extcommunity_list_expanded_all_list_cmd,
19943 "no bgp extcommunity-list <(100-500)|expanded WORD>",
19944 NO_STR BGP_STR EXTCOMMUNITY_LIST_STR
19945 "Extended Community list number (expanded)\n"
19946 "Specify expanded extcommunity-list\n"
19947 "Extended Community list name\n")
19948
19949static void extcommunity_list_show(struct vty *vty, struct community_list *list)
19950{
19951 struct community_entry *entry;
19952
19953 for (entry = list->head; entry; entry = entry->next) {
19954 if (entry == list->head) {
19955 if (all_digit(list->name))
19956 vty_out(vty, "Extended community %s list %s\n",
19957 entry->style == EXTCOMMUNITY_LIST_STANDARD
19958 ? "standard"
19959 : "(expanded) access",
19960 list->name);
19961 else
19962 vty_out(vty,
19963 "Named extended community %s list %s\n",
19964 entry->style == EXTCOMMUNITY_LIST_STANDARD
19965 ? "standard"
19966 : "expanded",
19967 list->name);
19968 }
19969 if (entry->any)
19970 vty_out(vty, " %s\n",
19971 community_direct_str(entry->direct));
19972 else
19973 vty_out(vty, " %s %s\n",
19974 community_direct_str(entry->direct),
19975 community_list_config_str(entry));
19976 }
19977}
19978
19979DEFUN (show_extcommunity_list,
19980 show_bgp_extcommunity_list_cmd,
19981 "show bgp extcommunity-list",
19982 SHOW_STR
19983 BGP_STR
19984 "List extended-community list\n")
19985{
19986 struct community_list *list;
19987 struct community_list_master *cm;
19988
19989 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
19990 if (!cm)
19991 return CMD_SUCCESS;
19992
19993 for (list = cm->num.head; list; list = list->next)
19994 extcommunity_list_show(vty, list);
19995
19996 for (list = cm->str.head; list; list = list->next)
19997 extcommunity_list_show(vty, list);
19998
19999 return CMD_SUCCESS;
20000}
20001
20002DEFUN (show_extcommunity_list_arg,
20003 show_bgp_extcommunity_list_arg_cmd,
20004 "show bgp extcommunity-list <(1-500)|WORD> detail",
20005 SHOW_STR
20006 BGP_STR
20007 "List extended-community list\n"
20008 "Extcommunity-list number\n"
20009 "Extcommunity-list name\n"
20010 "Detailed information on extcommunity-list\n")
20011{
20012 int idx_comm_list = 3;
20013 struct community_list *list;
20014
20015 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
20016 EXTCOMMUNITY_LIST_MASTER);
20017 if (!list) {
20018 vty_out(vty, "%% Can't find extcommunity-list\n");
20019 return CMD_WARNING;
20020 }
20021
20022 extcommunity_list_show(vty, list);
20023
20024 return CMD_SUCCESS;
20025}
20026
20027/* Display community-list and extcommunity-list configuration. */
20028static int community_list_config_write(struct vty *vty)
20029{
20030 struct community_list *list;
20031 struct community_entry *entry;
20032 struct community_list_master *cm;
20033 int write = 0;
20034
20035 /* Community-list. */
20036 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
20037
20038 for (list = cm->num.head; list; list = list->next)
20039 for (entry = list->head; entry; entry = entry->next) {
20040 vty_out(vty,
20041 "bgp community-list %s seq %" PRId64 " %s %s\n",
20042 list->name, entry->seq,
20043 community_direct_str(entry->direct),
20044 community_list_config_str(entry));
20045 write++;
20046 }
20047 for (list = cm->str.head; list; list = list->next)
20048 for (entry = list->head; entry; entry = entry->next) {
20049 vty_out(vty,
20050 "bgp community-list %s %s seq %" PRId64 " %s %s\n",
20051 entry->style == COMMUNITY_LIST_STANDARD
20052 ? "standard"
20053 : "expanded",
20054 list->name, entry->seq,
20055 community_direct_str(entry->direct),
20056 community_list_config_str(entry));
20057 write++;
20058 }
20059
20060 /* Extcommunity-list. */
20061 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
20062
20063 for (list = cm->num.head; list; list = list->next)
20064 for (entry = list->head; entry; entry = entry->next) {
20065 vty_out(vty,
20066 "bgp extcommunity-list %s seq %" PRId64 " %s %s\n",
20067 list->name, entry->seq,
20068 community_direct_str(entry->direct),
20069 community_list_config_str(entry));
20070 write++;
20071 }
20072 for (list = cm->str.head; list; list = list->next)
20073 for (entry = list->head; entry; entry = entry->next) {
20074 vty_out(vty,
20075 "bgp extcommunity-list %s %s seq %" PRId64" %s %s\n",
20076 entry->style == EXTCOMMUNITY_LIST_STANDARD
20077 ? "standard"
20078 : "expanded",
20079 list->name, entry->seq,
20080 community_direct_str(entry->direct),
20081 community_list_config_str(entry));
20082 write++;
20083 }
20084
20085
20086 /* lcommunity-list. */
20087 cm = community_list_master_lookup(bgp_clist,
20088 LARGE_COMMUNITY_LIST_MASTER);
20089
20090 for (list = cm->num.head; list; list = list->next)
20091 for (entry = list->head; entry; entry = entry->next) {
20092 vty_out(vty,
20093 "bgp large-community-list %s seq %" PRId64" %s %s\n",
20094 list->name, entry->seq,
20095 community_direct_str(entry->direct),
20096 community_list_config_str(entry));
20097 write++;
20098 }
20099 for (list = cm->str.head; list; list = list->next)
20100 for (entry = list->head; entry; entry = entry->next) {
20101 vty_out(vty,
20102 "bgp large-community-list %s %s seq %" PRId64" %s %s\n",
20103
20104 entry->style == LARGE_COMMUNITY_LIST_STANDARD
20105 ? "standard"
20106 : "expanded",
20107 list->name, entry->seq, community_direct_str(entry->direct),
20108 community_list_config_str(entry));
20109 write++;
20110 }
20111
20112 return write;
20113}
20114
20115static int community_list_config_write(struct vty *vty);
20116static struct cmd_node community_list_node = {
20117 .name = "community list",
20118 .node = COMMUNITY_LIST_NODE,
20119 .prompt = "",
20120 .config_write = community_list_config_write,
20121};
20122
20123static void community_list_vty(void)
20124{
20125 install_node(&community_list_node);
20126
20127 /* Community-list. */
20128 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
20129 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
20130 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
20131 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
20132 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
20133 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
20134 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
20135 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
20136
20137 /* Extcommunity-list. */
20138 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
20139 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
20140 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
20141 install_element(CONFIG_NODE,
20142 &no_bgp_extcommunity_list_standard_all_list_cmd);
20143 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
20144 install_element(CONFIG_NODE,
20145 &no_bgp_extcommunity_list_expanded_all_list_cmd);
20146 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
20147 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
20148
20149 /* Large Community List */
20150 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
20151 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
20152 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
20153 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
20154 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_all_cmd);
20155 install_element(CONFIG_NODE,
20156 &no_bgp_lcommunity_list_name_standard_all_cmd);
20157 install_element(CONFIG_NODE,
20158 &no_bgp_lcommunity_list_name_expanded_all_cmd);
20159 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
20160 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
20161 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
20162 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
20163 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
20164 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
20165}