]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #4737 from opensourcerouting/bgp-path-attr-fix
[mirror_frr.git] / bgpd / bgp_vty.c
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/zclient.h"
26 #include "prefix.h"
27 #include "plist.h"
28 #include "buffer.h"
29 #include "linklist.h"
30 #include "stream.h"
31 #include "thread.h"
32 #include "log.h"
33 #include "memory.h"
34 #include "memory_vty.h"
35 #include "hash.h"
36 #include "queue.h"
37 #include "filter.h"
38 #include "frrstr.h"
39
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_attr_evpn.h"
42 #include "bgpd/bgp_advertise.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_aspath.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_ecommunity.h"
47 #include "bgpd/bgp_lcommunity.h"
48 #include "bgpd/bgp_damp.h"
49 #include "bgpd/bgp_debug.h"
50 #include "bgpd/bgp_errors.h"
51 #include "bgpd/bgp_fsm.h"
52 #include "bgpd/bgp_nexthop.h"
53 #include "bgpd/bgp_open.h"
54 #include "bgpd/bgp_regex.h"
55 #include "bgpd/bgp_route.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_table.h"
59 #include "bgpd/bgp_vty.h"
60 #include "bgpd/bgp_mpath.h"
61 #include "bgpd/bgp_packet.h"
62 #include "bgpd/bgp_updgrp.h"
63 #include "bgpd/bgp_bfd.h"
64 #include "bgpd/bgp_io.h"
65 #include "bgpd/bgp_evpn.h"
66 #include "bgpd/bgp_addpath.h"
67 #include "bgpd/bgp_mac.h"
68
69 static struct peer_group *listen_range_exists(struct bgp *bgp,
70 struct prefix *range, int exact);
71
72 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
73 {
74 switch (afi) {
75 case AFI_IP:
76 switch (safi) {
77 case SAFI_UNICAST:
78 return BGP_IPV4_NODE;
79 break;
80 case SAFI_MULTICAST:
81 return BGP_IPV4M_NODE;
82 break;
83 case SAFI_LABELED_UNICAST:
84 return BGP_IPV4L_NODE;
85 break;
86 case SAFI_MPLS_VPN:
87 return BGP_VPNV4_NODE;
88 break;
89 case SAFI_FLOWSPEC:
90 return BGP_FLOWSPECV4_NODE;
91 default:
92 /* not expected */
93 return BGP_IPV4_NODE;
94 break;
95 }
96 break;
97 case AFI_IP6:
98 switch (safi) {
99 case SAFI_UNICAST:
100 return BGP_IPV6_NODE;
101 break;
102 case SAFI_MULTICAST:
103 return BGP_IPV6M_NODE;
104 break;
105 case SAFI_LABELED_UNICAST:
106 return BGP_IPV6L_NODE;
107 break;
108 case SAFI_MPLS_VPN:
109 return BGP_VPNV6_NODE;
110 break;
111 case SAFI_FLOWSPEC:
112 return BGP_FLOWSPECV6_NODE;
113 default:
114 /* not expected */
115 return BGP_IPV4_NODE;
116 break;
117 }
118 break;
119 case AFI_L2VPN:
120 return BGP_EVPN_NODE;
121 break;
122 case AFI_UNSPEC:
123 case AFI_MAX:
124 // We should never be here but to clarify the switch statement..
125 return BGP_IPV4_NODE;
126 break;
127 }
128
129 // Impossible to happen
130 return BGP_IPV4_NODE;
131 }
132
133 /* Utility function to get address family from current node. */
134 afi_t bgp_node_afi(struct vty *vty)
135 {
136 afi_t afi;
137 switch (vty->node) {
138 case BGP_IPV6_NODE:
139 case BGP_IPV6M_NODE:
140 case BGP_IPV6L_NODE:
141 case BGP_VPNV6_NODE:
142 case BGP_FLOWSPECV6_NODE:
143 afi = AFI_IP6;
144 break;
145 case BGP_EVPN_NODE:
146 afi = AFI_L2VPN;
147 break;
148 default:
149 afi = AFI_IP;
150 break;
151 }
152 return afi;
153 }
154
155 /* Utility function to get subsequent address family from current
156 node. */
157 safi_t bgp_node_safi(struct vty *vty)
158 {
159 safi_t safi;
160 switch (vty->node) {
161 case BGP_VPNV4_NODE:
162 case BGP_VPNV6_NODE:
163 safi = SAFI_MPLS_VPN;
164 break;
165 case BGP_IPV4M_NODE:
166 case BGP_IPV6M_NODE:
167 safi = SAFI_MULTICAST;
168 break;
169 case BGP_EVPN_NODE:
170 safi = SAFI_EVPN;
171 break;
172 case BGP_IPV4L_NODE:
173 case BGP_IPV6L_NODE:
174 safi = SAFI_LABELED_UNICAST;
175 break;
176 case BGP_FLOWSPECV4_NODE:
177 case BGP_FLOWSPECV6_NODE:
178 safi = SAFI_FLOWSPEC;
179 break;
180 default:
181 safi = SAFI_UNICAST;
182 break;
183 }
184 return safi;
185 }
186
187 /**
188 * Converts an AFI in string form to afi_t
189 *
190 * @param afi string, one of
191 * - "ipv4"
192 * - "ipv6"
193 * - "l2vpn"
194 * @return the corresponding afi_t
195 */
196 afi_t bgp_vty_afi_from_str(const char *afi_str)
197 {
198 afi_t afi = AFI_MAX; /* unknown */
199 if (strmatch(afi_str, "ipv4"))
200 afi = AFI_IP;
201 else if (strmatch(afi_str, "ipv6"))
202 afi = AFI_IP6;
203 else if (strmatch(afi_str, "l2vpn"))
204 afi = AFI_L2VPN;
205 return afi;
206 }
207
208 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
209 afi_t *afi)
210 {
211 int ret = 0;
212 if (argv_find(argv, argc, "ipv4", index)) {
213 ret = 1;
214 if (afi)
215 *afi = AFI_IP;
216 } else if (argv_find(argv, argc, "ipv6", index)) {
217 ret = 1;
218 if (afi)
219 *afi = AFI_IP6;
220 } else if (argv_find(argv, argc, "l2vpn", index)) {
221 ret = 1;
222 if (afi)
223 *afi = AFI_L2VPN;
224 }
225 return ret;
226 }
227
228 /* supports <unicast|multicast|vpn|labeled-unicast> */
229 safi_t bgp_vty_safi_from_str(const char *safi_str)
230 {
231 safi_t safi = SAFI_MAX; /* unknown */
232 if (strmatch(safi_str, "multicast"))
233 safi = SAFI_MULTICAST;
234 else if (strmatch(safi_str, "unicast"))
235 safi = SAFI_UNICAST;
236 else if (strmatch(safi_str, "vpn"))
237 safi = SAFI_MPLS_VPN;
238 else if (strmatch(safi_str, "evpn"))
239 safi = SAFI_EVPN;
240 else if (strmatch(safi_str, "labeled-unicast"))
241 safi = SAFI_LABELED_UNICAST;
242 else if (strmatch(safi_str, "flowspec"))
243 safi = SAFI_FLOWSPEC;
244 return safi;
245 }
246
247 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
248 safi_t *safi)
249 {
250 int ret = 0;
251 if (argv_find(argv, argc, "unicast", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_UNICAST;
255 } else if (argv_find(argv, argc, "multicast", index)) {
256 ret = 1;
257 if (safi)
258 *safi = SAFI_MULTICAST;
259 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
260 ret = 1;
261 if (safi)
262 *safi = SAFI_LABELED_UNICAST;
263 } else if (argv_find(argv, argc, "vpn", index)) {
264 ret = 1;
265 if (safi)
266 *safi = SAFI_MPLS_VPN;
267 } else if (argv_find(argv, argc, "evpn", index)) {
268 ret = 1;
269 if (safi)
270 *safi = SAFI_EVPN;
271 } else if (argv_find(argv, argc, "flowspec", index)) {
272 ret = 1;
273 if (safi)
274 *safi = SAFI_FLOWSPEC;
275 }
276 return ret;
277 }
278
279 /*
280 * bgp_vty_find_and_parse_afi_safi_bgp
281 *
282 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
283 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
284 * to appropriate values for the calling function. This is to allow the
285 * calling function to make decisions appropriate for the show command
286 * that is being parsed.
287 *
288 * The show commands are generally of the form:
289 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
290 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
291 *
292 * Since we use argv_find if the show command in particular doesn't have:
293 * [ip]
294 * [<view|vrf> VIEWVRFNAME]
295 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
296 * The command parsing should still be ok.
297 *
298 * vty -> The vty for the command so we can output some useful data in
299 * the event of a parse error in the vrf.
300 * argv -> The command tokens
301 * argc -> How many command tokens we have
302 * idx -> The current place in the command, generally should be 0 for this
303 * function
304 * afi -> The parsed afi if it was included in the show command, returned here
305 * safi -> The parsed safi if it was included in the show command, returned here
306 * bgp -> Pointer to the bgp data structure we need to fill in.
307 * use_json -> json is configured or not
308 *
309 * The function returns the correct location in the parse tree for the
310 * last token found.
311 *
312 * Returns 0 for failure to parse correctly, else the idx position of where
313 * it found the last token.
314 */
315 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
316 struct cmd_token **argv, int argc,
317 int *idx, afi_t *afi, safi_t *safi,
318 struct bgp **bgp, bool use_json)
319 {
320 char *vrf_name = NULL;
321
322 assert(afi);
323 assert(safi);
324 assert(bgp);
325
326 if (argv_find(argv, argc, "ip", idx))
327 *afi = AFI_IP;
328
329 if (argv_find(argv, argc, "view", idx))
330 vrf_name = argv[*idx + 1]->arg;
331 else if (argv_find(argv, argc, "vrf", idx)) {
332 vrf_name = argv[*idx + 1]->arg;
333 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
334 vrf_name = NULL;
335 }
336 if (vrf_name) {
337 if (strmatch(vrf_name, "all"))
338 *bgp = NULL;
339 else {
340 *bgp = bgp_lookup_by_name(vrf_name);
341 if (!*bgp) {
342 if (use_json) {
343 json_object *json = NULL;
344 json = json_object_new_object();
345 json_object_string_add(
346 json, "warning",
347 "View/Vrf is unknown");
348 vty_out(vty, "%s\n",
349 json_object_to_json_string_ext(json,
350 JSON_C_TO_STRING_PRETTY));
351 json_object_free(json);
352 }
353 else
354 vty_out(vty, "View/Vrf %s is unknown\n",
355 vrf_name);
356 *idx = 0;
357 return 0;
358 }
359 }
360 } else {
361 *bgp = bgp_get_default();
362 if (!*bgp) {
363 if (use_json) {
364 json_object *json = NULL;
365 json = json_object_new_object();
366 json_object_string_add(
367 json, "warning",
368 "Default BGP instance not found");
369 vty_out(vty, "%s\n",
370 json_object_to_json_string_ext(json,
371 JSON_C_TO_STRING_PRETTY));
372 json_object_free(json);
373 }
374 else
375 vty_out(vty,
376 "Default BGP instance not found\n");
377 *idx = 0;
378 return 0;
379 }
380 }
381
382 if (argv_find_and_parse_afi(argv, argc, idx, afi))
383 argv_find_and_parse_safi(argv, argc, idx, safi);
384
385 *idx += 1;
386 return *idx;
387 }
388
389 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
390 {
391 struct interface *ifp = NULL;
392
393 if (su->sa.sa_family == AF_INET)
394 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
395 else if (su->sa.sa_family == AF_INET6)
396 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
397 su->sin6.sin6_scope_id,
398 bgp->vrf_id);
399
400 if (ifp)
401 return 1;
402
403 return 0;
404 }
405
406 /* Utility function for looking up peer from VTY. */
407 /* This is used only for configuration, so disallow if attempted on
408 * a dynamic neighbor.
409 */
410 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
411 {
412 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
413 int ret;
414 union sockunion su;
415 struct peer *peer;
416
417 if (!bgp) {
418 return NULL;
419 }
420
421 ret = str2sockunion(ip_str, &su);
422 if (ret < 0) {
423 peer = peer_lookup_by_conf_if(bgp, ip_str);
424 if (!peer) {
425 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
426 == NULL) {
427 vty_out(vty,
428 "%% Malformed address or name: %s\n",
429 ip_str);
430 return NULL;
431 }
432 }
433 } else {
434 peer = peer_lookup(bgp, &su);
435 if (!peer) {
436 vty_out(vty,
437 "%% Specify remote-as or peer-group commands first\n");
438 return NULL;
439 }
440 if (peer_dynamic_neighbor(peer)) {
441 vty_out(vty,
442 "%% Operation not allowed on a dynamic neighbor\n");
443 return NULL;
444 }
445 }
446 return peer;
447 }
448
449 /* Utility function for looking up peer or peer group. */
450 /* This is used only for configuration, so disallow if attempted on
451 * a dynamic neighbor.
452 */
453 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
454 {
455 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
456 int ret;
457 union sockunion su;
458 struct peer *peer = NULL;
459 struct peer_group *group = NULL;
460
461 if (!bgp) {
462 return NULL;
463 }
464
465 ret = str2sockunion(peer_str, &su);
466 if (ret == 0) {
467 /* IP address, locate peer. */
468 peer = peer_lookup(bgp, &su);
469 } else {
470 /* Not IP, could match either peer configured on interface or a
471 * group. */
472 peer = peer_lookup_by_conf_if(bgp, peer_str);
473 if (!peer)
474 group = peer_group_lookup(bgp, peer_str);
475 }
476
477 if (peer) {
478 if (peer_dynamic_neighbor(peer)) {
479 vty_out(vty,
480 "%% Operation not allowed on a dynamic neighbor\n");
481 return NULL;
482 }
483
484 return peer;
485 }
486
487 if (group)
488 return group->conf;
489
490 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
491
492 return NULL;
493 }
494
495 int bgp_vty_return(struct vty *vty, int ret)
496 {
497 const char *str = NULL;
498
499 switch (ret) {
500 case BGP_ERR_INVALID_VALUE:
501 str = "Invalid value";
502 break;
503 case BGP_ERR_INVALID_FLAG:
504 str = "Invalid flag";
505 break;
506 case BGP_ERR_PEER_GROUP_SHUTDOWN:
507 str = "Peer-group has been shutdown. Activate the peer-group first";
508 break;
509 case BGP_ERR_PEER_FLAG_CONFLICT:
510 str = "Can't set override-capability and strict-capability-match at the same time";
511 break;
512 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
513 str = "Specify remote-as or peer-group remote AS first";
514 break;
515 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
516 str = "Cannot change the peer-group. Deconfigure first";
517 break;
518 case BGP_ERR_PEER_GROUP_MISMATCH:
519 str = "Peer is not a member of this peer-group";
520 break;
521 case BGP_ERR_PEER_FILTER_CONFLICT:
522 str = "Prefix/distribute list can not co-exist";
523 break;
524 case BGP_ERR_NOT_INTERNAL_PEER:
525 str = "Invalid command. Not an internal neighbor";
526 break;
527 case BGP_ERR_REMOVE_PRIVATE_AS:
528 str = "remove-private-AS cannot be configured for IBGP peers";
529 break;
530 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
531 str = "Local-AS allowed only for EBGP peers";
532 break;
533 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
534 str = "Cannot have local-as same as BGP AS number";
535 break;
536 case BGP_ERR_TCPSIG_FAILED:
537 str = "Error while applying TCP-Sig to session(s)";
538 break;
539 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
540 str = "ebgp-multihop and ttl-security cannot be configured together";
541 break;
542 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
543 str = "ttl-security only allowed for EBGP peers";
544 break;
545 case BGP_ERR_AS_OVERRIDE:
546 str = "as-override cannot be configured for IBGP peers";
547 break;
548 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
549 str = "Invalid limit for number of dynamic neighbors";
550 break;
551 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
552 str = "Dynamic neighbor listen range already exists";
553 break;
554 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
555 str = "Operation not allowed on a dynamic neighbor";
556 break;
557 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
558 str = "Operation not allowed on a directly connected neighbor";
559 break;
560 case BGP_ERR_PEER_SAFI_CONFLICT:
561 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
562 break;
563 }
564 if (str) {
565 vty_out(vty, "%% %s\n", str);
566 return CMD_WARNING_CONFIG_FAILED;
567 }
568 return CMD_SUCCESS;
569 }
570
571 /* BGP clear sort. */
572 enum clear_sort {
573 clear_all,
574 clear_peer,
575 clear_group,
576 clear_external,
577 clear_as
578 };
579
580 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
581 safi_t safi, int error)
582 {
583 switch (error) {
584 case BGP_ERR_AF_UNCONFIGURED:
585 vty_out(vty,
586 "%%BGP: Enable %s address family for the neighbor %s\n",
587 afi_safi_print(afi, safi), peer->host);
588 break;
589 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
590 vty_out(vty,
591 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
592 peer->host);
593 break;
594 default:
595 break;
596 }
597 }
598
599 /* `clear ip bgp' functions. */
600 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
601 enum clear_sort sort, enum bgp_clear_type stype,
602 const char *arg)
603 {
604 int ret;
605 bool found = false;
606 struct peer *peer;
607 struct listnode *node, *nnode;
608
609 /* Clear all neighbors. */
610 /*
611 * Pass along pointer to next node to peer_clear() when walking all
612 * nodes on the BGP instance as that may get freed if it is a
613 * doppelganger
614 */
615 if (sort == clear_all) {
616 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
617 if (!peer->afc[afi][safi])
618 continue;
619
620 if (stype == BGP_CLEAR_SOFT_NONE)
621 ret = peer_clear(peer, &nnode);
622 else
623 ret = peer_clear_soft(peer, afi, safi, stype);
624
625 if (ret < 0)
626 bgp_clear_vty_error(vty, peer, afi, safi, ret);
627 else
628 found = true;
629 }
630
631 /* This is to apply read-only mode on this clear. */
632 if (stype == BGP_CLEAR_SOFT_NONE)
633 bgp->update_delay_over = 0;
634
635 if (!found)
636 vty_out(vty, "%%BGP: No %s peer configured\n",
637 afi_safi_print(afi, safi));
638
639 return CMD_SUCCESS;
640 }
641
642 /* Clear specified neighbor. */
643 if (sort == clear_peer) {
644 union sockunion su;
645
646 /* Make sockunion for lookup. */
647 ret = str2sockunion(arg, &su);
648 if (ret < 0) {
649 peer = peer_lookup_by_conf_if(bgp, arg);
650 if (!peer) {
651 peer = peer_lookup_by_hostname(bgp, arg);
652 if (!peer) {
653 vty_out(vty,
654 "Malformed address or name: %s\n",
655 arg);
656 return CMD_WARNING;
657 }
658 }
659 } else {
660 peer = peer_lookup(bgp, &su);
661 if (!peer) {
662 vty_out(vty,
663 "%%BGP: Unknown neighbor - \"%s\"\n",
664 arg);
665 return CMD_WARNING;
666 }
667 }
668
669 if (!peer->afc[afi][safi])
670 ret = BGP_ERR_AF_UNCONFIGURED;
671 else if (stype == BGP_CLEAR_SOFT_NONE)
672 ret = peer_clear(peer, NULL);
673 else
674 ret = peer_clear_soft(peer, afi, safi, stype);
675
676 if (ret < 0)
677 bgp_clear_vty_error(vty, peer, afi, safi, ret);
678
679 return CMD_SUCCESS;
680 }
681
682 /* Clear all neighbors belonging to a specific peer-group. */
683 if (sort == clear_group) {
684 struct peer_group *group;
685
686 group = peer_group_lookup(bgp, arg);
687 if (!group) {
688 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
689 return CMD_WARNING;
690 }
691
692 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
693 if (!peer->afc[afi][safi])
694 continue;
695
696 if (stype == BGP_CLEAR_SOFT_NONE)
697 ret = peer_clear(peer, NULL);
698 else
699 ret = peer_clear_soft(peer, afi, safi, stype);
700
701 if (ret < 0)
702 bgp_clear_vty_error(vty, peer, afi, safi, ret);
703 else
704 found = true;
705 }
706
707 if (!found)
708 vty_out(vty,
709 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
710 afi_safi_print(afi, safi), arg);
711
712 return CMD_SUCCESS;
713 }
714
715 /* Clear all external (eBGP) neighbors. */
716 if (sort == clear_external) {
717 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
718 if (peer->sort == BGP_PEER_IBGP)
719 continue;
720
721 if (!peer->afc[afi][safi])
722 continue;
723
724 if (stype == BGP_CLEAR_SOFT_NONE)
725 ret = peer_clear(peer, &nnode);
726 else
727 ret = peer_clear_soft(peer, afi, safi, stype);
728
729 if (ret < 0)
730 bgp_clear_vty_error(vty, peer, afi, safi, ret);
731 else
732 found = true;
733 }
734
735 if (!found)
736 vty_out(vty,
737 "%%BGP: No external %s peer is configured\n",
738 afi_safi_print(afi, safi));
739
740 return CMD_SUCCESS;
741 }
742
743 /* Clear all neighbors belonging to a specific AS. */
744 if (sort == clear_as) {
745 as_t as = strtoul(arg, NULL, 10);
746
747 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
748 if (peer->as != as)
749 continue;
750
751 if (!peer->afc[afi][safi])
752 ret = BGP_ERR_AF_UNCONFIGURED;
753 else if (stype == BGP_CLEAR_SOFT_NONE)
754 ret = peer_clear(peer, &nnode);
755 else
756 ret = peer_clear_soft(peer, afi, safi, stype);
757
758 if (ret < 0)
759 bgp_clear_vty_error(vty, peer, afi, safi, ret);
760 else
761 found = true;
762 }
763
764 if (!found)
765 vty_out(vty,
766 "%%BGP: No %s peer is configured with AS %s\n",
767 afi_safi_print(afi, safi), arg);
768
769 return CMD_SUCCESS;
770 }
771
772 return CMD_SUCCESS;
773 }
774
775 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
776 safi_t safi, enum clear_sort sort,
777 enum bgp_clear_type stype, const char *arg)
778 {
779 struct bgp *bgp;
780
781 /* BGP structure lookup. */
782 if (name) {
783 bgp = bgp_lookup_by_name(name);
784 if (bgp == NULL) {
785 vty_out(vty, "Can't find BGP instance %s\n", name);
786 return CMD_WARNING;
787 }
788 } else {
789 bgp = bgp_get_default();
790 if (bgp == NULL) {
791 vty_out(vty, "No BGP process is configured\n");
792 return CMD_WARNING;
793 }
794 }
795
796 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
797 }
798
799 /* clear soft inbound */
800 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
801 {
802 afi_t afi;
803 safi_t safi;
804
805 FOREACH_AFI_SAFI (afi, safi)
806 bgp_clear_vty(vty, name, afi, safi, clear_all,
807 BGP_CLEAR_SOFT_IN, NULL);
808 }
809
810 /* clear soft outbound */
811 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
812 {
813 afi_t afi;
814 safi_t safi;
815
816 FOREACH_AFI_SAFI (afi, safi)
817 bgp_clear_vty(vty, name, afi, safi, clear_all,
818 BGP_CLEAR_SOFT_OUT, NULL);
819 }
820
821
822 #ifndef VTYSH_EXTRACT_PL
823 #include "bgpd/bgp_vty_clippy.c"
824 #endif
825
826 DEFUN_HIDDEN (bgp_local_mac,
827 bgp_local_mac_cmd,
828 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
829 BGP_STR
830 "Local MAC config\n"
831 "VxLAN Network Identifier\n"
832 "VNI number\n"
833 "local mac\n"
834 "mac address\n"
835 "mac-mobility sequence\n"
836 "seq number\n")
837 {
838 int rv;
839 vni_t vni;
840 struct ethaddr mac;
841 struct ipaddr ip;
842 uint32_t seq;
843 struct bgp *bgp;
844
845 vni = strtoul(argv[3]->arg, NULL, 10);
846 if (!prefix_str2mac(argv[5]->arg, &mac)) {
847 vty_out(vty, "%% Malformed MAC address\n");
848 return CMD_WARNING;
849 }
850 memset(&ip, 0, sizeof(ip));
851 seq = strtoul(argv[7]->arg, NULL, 10);
852
853 bgp = bgp_get_default();
854 if (!bgp) {
855 vty_out(vty, "Default BGP instance is not there\n");
856 return CMD_WARNING;
857 }
858
859 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
860 if (rv < 0) {
861 vty_out(vty, "Internal error\n");
862 return CMD_WARNING;
863 }
864
865 return CMD_SUCCESS;
866 }
867
868 DEFUN_HIDDEN (no_bgp_local_mac,
869 no_bgp_local_mac_cmd,
870 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
871 NO_STR
872 BGP_STR
873 "Local MAC config\n"
874 "VxLAN Network Identifier\n"
875 "VNI number\n"
876 "local mac\n"
877 "mac address\n")
878 {
879 int rv;
880 vni_t vni;
881 struct ethaddr mac;
882 struct ipaddr ip;
883 struct bgp *bgp;
884
885 vni = strtoul(argv[4]->arg, NULL, 10);
886 if (!prefix_str2mac(argv[6]->arg, &mac)) {
887 vty_out(vty, "%% Malformed MAC address\n");
888 return CMD_WARNING;
889 }
890 memset(&ip, 0, sizeof(ip));
891
892 bgp = bgp_get_default();
893 if (!bgp) {
894 vty_out(vty, "Default BGP instance is not there\n");
895 return CMD_WARNING;
896 }
897
898 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
899 if (rv < 0) {
900 vty_out(vty, "Internal error\n");
901 return CMD_WARNING;
902 }
903
904 return CMD_SUCCESS;
905 }
906
907 DEFUN (no_synchronization,
908 no_synchronization_cmd,
909 "no synchronization",
910 NO_STR
911 "Perform IGP synchronization\n")
912 {
913 return CMD_SUCCESS;
914 }
915
916 DEFUN (no_auto_summary,
917 no_auto_summary_cmd,
918 "no auto-summary",
919 NO_STR
920 "Enable automatic network number summarization\n")
921 {
922 return CMD_SUCCESS;
923 }
924
925 /* "router bgp" commands. */
926 DEFUN_NOSH (router_bgp,
927 router_bgp_cmd,
928 "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
929 ROUTER_STR
930 BGP_STR
931 AS_STR
932 BGP_INSTANCE_HELP_STR)
933 {
934 int idx_asn = 2;
935 int idx_view_vrf = 3;
936 int idx_vrf = 4;
937 int is_new_bgp = 0;
938 int ret;
939 as_t as;
940 struct bgp *bgp;
941 const char *name = NULL;
942 enum bgp_instance_type inst_type;
943
944 // "router bgp" without an ASN
945 if (argc == 2) {
946 // Pending: Make VRF option available for ASN less config
947 bgp = bgp_get_default();
948
949 if (bgp == NULL) {
950 vty_out(vty, "%% No BGP process is configured\n");
951 return CMD_WARNING_CONFIG_FAILED;
952 }
953
954 if (listcount(bm->bgp) > 1) {
955 vty_out(vty, "%% Please specify ASN and VRF\n");
956 return CMD_WARNING_CONFIG_FAILED;
957 }
958 }
959
960 // "router bgp X"
961 else {
962 as = strtoul(argv[idx_asn]->arg, NULL, 10);
963
964 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
965 if (argc > 3) {
966 name = argv[idx_vrf]->arg;
967
968 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
969 if (strmatch(name, VRF_DEFAULT_NAME))
970 name = NULL;
971 else
972 inst_type = BGP_INSTANCE_TYPE_VRF;
973 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
974 inst_type = BGP_INSTANCE_TYPE_VIEW;
975 }
976
977 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
978 is_new_bgp = (bgp_lookup(as, name) == NULL);
979
980 ret = bgp_get(&bgp, &as, name, inst_type);
981 switch (ret) {
982 case BGP_ERR_AS_MISMATCH:
983 vty_out(vty, "BGP is already running; AS is %u\n", as);
984 return CMD_WARNING_CONFIG_FAILED;
985 case BGP_ERR_INSTANCE_MISMATCH:
986 vty_out(vty,
987 "BGP instance name and AS number mismatch\n");
988 vty_out(vty,
989 "BGP instance is already running; AS is %u\n",
990 as);
991 return CMD_WARNING_CONFIG_FAILED;
992 }
993
994 /*
995 * If we just instantiated the default instance, complete
996 * any pending VRF-VPN leaking that was configured via
997 * earlier "router bgp X vrf FOO" blocks.
998 */
999 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1000 vpn_leak_postchange_all();
1001
1002 if (inst_type == BGP_INSTANCE_TYPE_VRF)
1003 bgp_vpn_leak_export(bgp);
1004 /* Pending: handle when user tries to change a view to vrf n vv.
1005 */
1006 }
1007
1008 /* unset the auto created flag as the user config is now present */
1009 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1010 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1011
1012 return CMD_SUCCESS;
1013 }
1014
1015 /* "no router bgp" commands. */
1016 DEFUN (no_router_bgp,
1017 no_router_bgp_cmd,
1018 "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
1019 NO_STR
1020 ROUTER_STR
1021 BGP_STR
1022 AS_STR
1023 BGP_INSTANCE_HELP_STR)
1024 {
1025 int idx_asn = 3;
1026 int idx_vrf = 5;
1027 as_t as;
1028 struct bgp *bgp;
1029 const char *name = NULL;
1030
1031 // "no router bgp" without an ASN
1032 if (argc == 3) {
1033 // Pending: Make VRF option available for ASN less config
1034 bgp = bgp_get_default();
1035
1036 if (bgp == NULL) {
1037 vty_out(vty, "%% No BGP process is configured\n");
1038 return CMD_WARNING_CONFIG_FAILED;
1039 }
1040
1041 if (listcount(bm->bgp) > 1) {
1042 vty_out(vty, "%% Please specify ASN and VRF\n");
1043 return CMD_WARNING_CONFIG_FAILED;
1044 }
1045
1046 if (bgp->l3vni) {
1047 vty_out(vty, "%% Please unconfigure l3vni %u",
1048 bgp->l3vni);
1049 return CMD_WARNING_CONFIG_FAILED;
1050 }
1051 } else {
1052 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1053
1054 if (argc > 4)
1055 name = argv[idx_vrf]->arg;
1056
1057 /* Lookup bgp structure. */
1058 bgp = bgp_lookup(as, name);
1059 if (!bgp) {
1060 vty_out(vty, "%% Can't find BGP instance\n");
1061 return CMD_WARNING_CONFIG_FAILED;
1062 }
1063
1064 if (bgp->l3vni) {
1065 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1066 bgp->l3vni);
1067 return CMD_WARNING_CONFIG_FAILED;
1068 }
1069
1070 /* Cannot delete default instance if vrf instances exist */
1071 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1072 struct listnode *node;
1073 struct bgp *tmp_bgp;
1074
1075 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1076 if (tmp_bgp->inst_type
1077 == BGP_INSTANCE_TYPE_VRF) {
1078 vty_out(vty,
1079 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1080 return CMD_WARNING_CONFIG_FAILED;
1081 }
1082 }
1083 }
1084 }
1085
1086 if (bgp_vpn_leak_unimport(bgp, vty))
1087 return CMD_WARNING_CONFIG_FAILED;
1088
1089 bgp_delete(bgp);
1090
1091 return CMD_SUCCESS;
1092 }
1093
1094
1095 /* BGP router-id. */
1096
1097 DEFPY (bgp_router_id,
1098 bgp_router_id_cmd,
1099 "bgp router-id A.B.C.D",
1100 BGP_STR
1101 "Override configured router identifier\n"
1102 "Manually configured router identifier\n")
1103 {
1104 VTY_DECLVAR_CONTEXT(bgp, bgp);
1105 bgp_router_id_static_set(bgp, router_id);
1106 return CMD_SUCCESS;
1107 }
1108
1109 DEFPY (no_bgp_router_id,
1110 no_bgp_router_id_cmd,
1111 "no bgp router-id [A.B.C.D]",
1112 NO_STR
1113 BGP_STR
1114 "Override configured router identifier\n"
1115 "Manually configured router identifier\n")
1116 {
1117 VTY_DECLVAR_CONTEXT(bgp, bgp);
1118
1119 if (router_id_str) {
1120 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1121 vty_out(vty, "%% BGP router-id doesn't match\n");
1122 return CMD_WARNING_CONFIG_FAILED;
1123 }
1124 }
1125
1126 router_id.s_addr = 0;
1127 bgp_router_id_static_set(bgp, router_id);
1128
1129 return CMD_SUCCESS;
1130 }
1131
1132
1133 /* BGP Cluster ID. */
1134 DEFUN (bgp_cluster_id,
1135 bgp_cluster_id_cmd,
1136 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1137 BGP_STR
1138 "Configure Route-Reflector Cluster-id\n"
1139 "Route-Reflector Cluster-id in IP address format\n"
1140 "Route-Reflector Cluster-id as 32 bit quantity\n")
1141 {
1142 VTY_DECLVAR_CONTEXT(bgp, bgp);
1143 int idx_ipv4 = 2;
1144 int ret;
1145 struct in_addr cluster;
1146
1147 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1148 if (!ret) {
1149 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1150 return CMD_WARNING_CONFIG_FAILED;
1151 }
1152
1153 bgp_cluster_id_set(bgp, &cluster);
1154 bgp_clear_star_soft_out(vty, bgp->name);
1155
1156 return CMD_SUCCESS;
1157 }
1158
1159 DEFUN (no_bgp_cluster_id,
1160 no_bgp_cluster_id_cmd,
1161 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1162 NO_STR
1163 BGP_STR
1164 "Configure Route-Reflector Cluster-id\n"
1165 "Route-Reflector Cluster-id in IP address format\n"
1166 "Route-Reflector Cluster-id as 32 bit quantity\n")
1167 {
1168 VTY_DECLVAR_CONTEXT(bgp, bgp);
1169 bgp_cluster_id_unset(bgp);
1170 bgp_clear_star_soft_out(vty, bgp->name);
1171
1172 return CMD_SUCCESS;
1173 }
1174
1175 DEFUN (bgp_confederation_identifier,
1176 bgp_confederation_identifier_cmd,
1177 "bgp confederation identifier (1-4294967295)",
1178 "BGP specific commands\n"
1179 "AS confederation parameters\n"
1180 "AS number\n"
1181 "Set routing domain confederation AS\n")
1182 {
1183 VTY_DECLVAR_CONTEXT(bgp, bgp);
1184 int idx_number = 3;
1185 as_t as;
1186
1187 as = strtoul(argv[idx_number]->arg, NULL, 10);
1188
1189 bgp_confederation_id_set(bgp, as);
1190
1191 return CMD_SUCCESS;
1192 }
1193
1194 DEFUN (no_bgp_confederation_identifier,
1195 no_bgp_confederation_identifier_cmd,
1196 "no bgp confederation identifier [(1-4294967295)]",
1197 NO_STR
1198 "BGP specific commands\n"
1199 "AS confederation parameters\n"
1200 "AS number\n"
1201 "Set routing domain confederation AS\n")
1202 {
1203 VTY_DECLVAR_CONTEXT(bgp, bgp);
1204 bgp_confederation_id_unset(bgp);
1205
1206 return CMD_SUCCESS;
1207 }
1208
1209 DEFUN (bgp_confederation_peers,
1210 bgp_confederation_peers_cmd,
1211 "bgp confederation peers (1-4294967295)...",
1212 "BGP specific commands\n"
1213 "AS confederation parameters\n"
1214 "Peer ASs in BGP confederation\n"
1215 AS_STR)
1216 {
1217 VTY_DECLVAR_CONTEXT(bgp, bgp);
1218 int idx_asn = 3;
1219 as_t as;
1220 int i;
1221
1222 for (i = idx_asn; i < argc; i++) {
1223 as = strtoul(argv[i]->arg, NULL, 10);
1224
1225 if (bgp->as == as) {
1226 vty_out(vty,
1227 "%% Local member-AS not allowed in confed peer list\n");
1228 continue;
1229 }
1230
1231 bgp_confederation_peers_add(bgp, as);
1232 }
1233 return CMD_SUCCESS;
1234 }
1235
1236 DEFUN (no_bgp_confederation_peers,
1237 no_bgp_confederation_peers_cmd,
1238 "no bgp confederation peers (1-4294967295)...",
1239 NO_STR
1240 "BGP specific commands\n"
1241 "AS confederation parameters\n"
1242 "Peer ASs in BGP confederation\n"
1243 AS_STR)
1244 {
1245 VTY_DECLVAR_CONTEXT(bgp, bgp);
1246 int idx_asn = 4;
1247 as_t as;
1248 int i;
1249
1250 for (i = idx_asn; i < argc; i++) {
1251 as = strtoul(argv[i]->arg, NULL, 10);
1252
1253 bgp_confederation_peers_remove(bgp, as);
1254 }
1255 return CMD_SUCCESS;
1256 }
1257
1258 /**
1259 * Central routine for maximum-paths configuration.
1260 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1261 * @set: 1 for setting values, 0 for removing the max-paths config.
1262 */
1263 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1264 const char *mpaths, uint16_t options,
1265 int set)
1266 {
1267 VTY_DECLVAR_CONTEXT(bgp, bgp);
1268 uint16_t maxpaths = 0;
1269 int ret;
1270 afi_t afi;
1271 safi_t safi;
1272
1273 afi = bgp_node_afi(vty);
1274 safi = bgp_node_safi(vty);
1275
1276 if (set) {
1277 maxpaths = strtol(mpaths, NULL, 10);
1278 if (maxpaths > multipath_num) {
1279 vty_out(vty,
1280 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1281 maxpaths, multipath_num);
1282 return CMD_WARNING_CONFIG_FAILED;
1283 }
1284 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1285 options);
1286 } else
1287 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1288
1289 if (ret < 0) {
1290 vty_out(vty,
1291 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1292 (set == 1) ? "" : "un",
1293 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1294 maxpaths, afi, safi);
1295 return CMD_WARNING_CONFIG_FAILED;
1296 }
1297
1298 bgp_recalculate_all_bestpaths(bgp);
1299
1300 return CMD_SUCCESS;
1301 }
1302
1303 DEFUN (bgp_maxmed_admin,
1304 bgp_maxmed_admin_cmd,
1305 "bgp max-med administrative ",
1306 BGP_STR
1307 "Advertise routes with max-med\n"
1308 "Administratively applied, for an indefinite period\n")
1309 {
1310 VTY_DECLVAR_CONTEXT(bgp, bgp);
1311
1312 bgp->v_maxmed_admin = 1;
1313 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1314
1315 bgp_maxmed_update(bgp);
1316
1317 return CMD_SUCCESS;
1318 }
1319
1320 DEFUN (bgp_maxmed_admin_medv,
1321 bgp_maxmed_admin_medv_cmd,
1322 "bgp max-med administrative (0-4294967295)",
1323 BGP_STR
1324 "Advertise routes with max-med\n"
1325 "Administratively applied, for an indefinite period\n"
1326 "Max MED value to be used\n")
1327 {
1328 VTY_DECLVAR_CONTEXT(bgp, bgp);
1329 int idx_number = 3;
1330
1331 bgp->v_maxmed_admin = 1;
1332 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1333
1334 bgp_maxmed_update(bgp);
1335
1336 return CMD_SUCCESS;
1337 }
1338
1339 DEFUN (no_bgp_maxmed_admin,
1340 no_bgp_maxmed_admin_cmd,
1341 "no bgp max-med administrative [(0-4294967295)]",
1342 NO_STR
1343 BGP_STR
1344 "Advertise routes with max-med\n"
1345 "Administratively applied, for an indefinite period\n"
1346 "Max MED value to be used\n")
1347 {
1348 VTY_DECLVAR_CONTEXT(bgp, bgp);
1349 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1350 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1351 bgp_maxmed_update(bgp);
1352
1353 return CMD_SUCCESS;
1354 }
1355
1356 DEFUN (bgp_maxmed_onstartup,
1357 bgp_maxmed_onstartup_cmd,
1358 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1359 BGP_STR
1360 "Advertise routes with max-med\n"
1361 "Effective on a startup\n"
1362 "Time (seconds) period for max-med\n"
1363 "Max MED value to be used\n")
1364 {
1365 VTY_DECLVAR_CONTEXT(bgp, bgp);
1366 int idx = 0;
1367
1368 argv_find(argv, argc, "(5-86400)", &idx);
1369 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1370 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1371 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1372 else
1373 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1374
1375 bgp_maxmed_update(bgp);
1376
1377 return CMD_SUCCESS;
1378 }
1379
1380 DEFUN (no_bgp_maxmed_onstartup,
1381 no_bgp_maxmed_onstartup_cmd,
1382 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1383 NO_STR
1384 BGP_STR
1385 "Advertise routes with max-med\n"
1386 "Effective on a startup\n"
1387 "Time (seconds) period for max-med\n"
1388 "Max MED value to be used\n")
1389 {
1390 VTY_DECLVAR_CONTEXT(bgp, bgp);
1391
1392 /* Cancel max-med onstartup if its on */
1393 if (bgp->t_maxmed_onstartup) {
1394 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1395 bgp->maxmed_onstartup_over = 1;
1396 }
1397
1398 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1399 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1400
1401 bgp_maxmed_update(bgp);
1402
1403 return CMD_SUCCESS;
1404 }
1405
1406 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1407 const char *wait)
1408 {
1409 VTY_DECLVAR_CONTEXT(bgp, bgp);
1410 uint16_t update_delay;
1411 uint16_t establish_wait;
1412
1413 update_delay = strtoul(delay, NULL, 10);
1414
1415 if (!wait) /* update-delay <delay> */
1416 {
1417 bgp->v_update_delay = update_delay;
1418 bgp->v_establish_wait = bgp->v_update_delay;
1419 return CMD_SUCCESS;
1420 }
1421
1422 /* update-delay <delay> <establish-wait> */
1423 establish_wait = atoi(wait);
1424 if (update_delay < establish_wait) {
1425 vty_out(vty,
1426 "%%Failed: update-delay less than the establish-wait!\n");
1427 return CMD_WARNING_CONFIG_FAILED;
1428 }
1429
1430 bgp->v_update_delay = update_delay;
1431 bgp->v_establish_wait = establish_wait;
1432
1433 return CMD_SUCCESS;
1434 }
1435
1436 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1437 {
1438 VTY_DECLVAR_CONTEXT(bgp, bgp);
1439
1440 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1441 bgp->v_establish_wait = bgp->v_update_delay;
1442
1443 return CMD_SUCCESS;
1444 }
1445
1446 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1447 {
1448 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1449 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1450 if (bgp->v_update_delay != bgp->v_establish_wait)
1451 vty_out(vty, " %d", bgp->v_establish_wait);
1452 vty_out(vty, "\n");
1453 }
1454 }
1455
1456
1457 /* Update-delay configuration */
1458 DEFUN (bgp_update_delay,
1459 bgp_update_delay_cmd,
1460 "update-delay (0-3600)",
1461 "Force initial delay for best-path and updates\n"
1462 "Seconds\n")
1463 {
1464 int idx_number = 1;
1465 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1466 }
1467
1468 DEFUN (bgp_update_delay_establish_wait,
1469 bgp_update_delay_establish_wait_cmd,
1470 "update-delay (0-3600) (1-3600)",
1471 "Force initial delay for best-path and updates\n"
1472 "Seconds\n"
1473 "Seconds\n")
1474 {
1475 int idx_number = 1;
1476 int idx_number_2 = 2;
1477 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1478 argv[idx_number_2]->arg);
1479 }
1480
1481 /* Update-delay deconfiguration */
1482 DEFUN (no_bgp_update_delay,
1483 no_bgp_update_delay_cmd,
1484 "no update-delay [(0-3600) [(1-3600)]]",
1485 NO_STR
1486 "Force initial delay for best-path and updates\n"
1487 "Seconds\n"
1488 "Seconds\n")
1489 {
1490 return bgp_update_delay_deconfig_vty(vty);
1491 }
1492
1493
1494 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1495 char set)
1496 {
1497 VTY_DECLVAR_CONTEXT(bgp, bgp);
1498
1499 if (set) {
1500 uint32_t quanta = strtoul(num, NULL, 10);
1501 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1502 memory_order_relaxed);
1503 } else {
1504 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1505 memory_order_relaxed);
1506 }
1507
1508 return CMD_SUCCESS;
1509 }
1510
1511 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1512 char set)
1513 {
1514 VTY_DECLVAR_CONTEXT(bgp, bgp);
1515
1516 if (set) {
1517 uint32_t quanta = strtoul(num, NULL, 10);
1518 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1519 memory_order_relaxed);
1520 } else {
1521 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1522 memory_order_relaxed);
1523 }
1524
1525 return CMD_SUCCESS;
1526 }
1527
1528 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1529 {
1530 uint32_t quanta =
1531 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1532 if (quanta != BGP_WRITE_PACKET_MAX)
1533 vty_out(vty, " write-quanta %d\n", quanta);
1534 }
1535
1536 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1537 {
1538 uint32_t quanta =
1539 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1540 if (quanta != BGP_READ_PACKET_MAX)
1541 vty_out(vty, " read-quanta %d\n", quanta);
1542 }
1543
1544 /* Packet quanta configuration */
1545 DEFUN (bgp_wpkt_quanta,
1546 bgp_wpkt_quanta_cmd,
1547 "write-quanta (1-10)",
1548 "How many packets to write to peer socket per run\n"
1549 "Number of packets\n")
1550 {
1551 int idx_number = 1;
1552 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1553 }
1554
1555 DEFUN (no_bgp_wpkt_quanta,
1556 no_bgp_wpkt_quanta_cmd,
1557 "no write-quanta (1-10)",
1558 NO_STR
1559 "How many packets to write to peer socket per I/O cycle\n"
1560 "Number of packets\n")
1561 {
1562 int idx_number = 2;
1563 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1564 }
1565
1566 DEFUN (bgp_rpkt_quanta,
1567 bgp_rpkt_quanta_cmd,
1568 "read-quanta (1-10)",
1569 "How many packets to read from peer socket per I/O cycle\n"
1570 "Number of packets\n")
1571 {
1572 int idx_number = 1;
1573 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1574 }
1575
1576 DEFUN (no_bgp_rpkt_quanta,
1577 no_bgp_rpkt_quanta_cmd,
1578 "no read-quanta (1-10)",
1579 NO_STR
1580 "How many packets to read from peer socket per I/O cycle\n"
1581 "Number of packets\n")
1582 {
1583 int idx_number = 2;
1584 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1585 }
1586
1587 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1588 {
1589 if (!bgp->heuristic_coalesce)
1590 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1591 }
1592
1593
1594 DEFUN (bgp_coalesce_time,
1595 bgp_coalesce_time_cmd,
1596 "coalesce-time (0-4294967295)",
1597 "Subgroup coalesce timer\n"
1598 "Subgroup coalesce timer value (in ms)\n")
1599 {
1600 VTY_DECLVAR_CONTEXT(bgp, bgp);
1601
1602 int idx = 0;
1603 argv_find(argv, argc, "(0-4294967295)", &idx);
1604 bgp->heuristic_coalesce = false;
1605 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1606 return CMD_SUCCESS;
1607 }
1608
1609 DEFUN (no_bgp_coalesce_time,
1610 no_bgp_coalesce_time_cmd,
1611 "no coalesce-time (0-4294967295)",
1612 NO_STR
1613 "Subgroup coalesce timer\n"
1614 "Subgroup coalesce timer value (in ms)\n")
1615 {
1616 VTY_DECLVAR_CONTEXT(bgp, bgp);
1617
1618 bgp->heuristic_coalesce = true;
1619 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1620 return CMD_SUCCESS;
1621 }
1622
1623 /* Maximum-paths configuration */
1624 DEFUN (bgp_maxpaths,
1625 bgp_maxpaths_cmd,
1626 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1627 "Forward packets over multiple paths\n"
1628 "Number of paths\n")
1629 {
1630 int idx_number = 1;
1631 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1632 argv[idx_number]->arg, 0, 1);
1633 }
1634
1635 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1636 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1637 "Forward packets over multiple paths\n"
1638 "Number of paths\n")
1639
1640 DEFUN (bgp_maxpaths_ibgp,
1641 bgp_maxpaths_ibgp_cmd,
1642 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1643 "Forward packets over multiple paths\n"
1644 "iBGP-multipath\n"
1645 "Number of paths\n")
1646 {
1647 int idx_number = 2;
1648 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1649 argv[idx_number]->arg, 0, 1);
1650 }
1651
1652 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1653 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1654 "Forward packets over multiple paths\n"
1655 "iBGP-multipath\n"
1656 "Number of paths\n")
1657
1658 DEFUN (bgp_maxpaths_ibgp_cluster,
1659 bgp_maxpaths_ibgp_cluster_cmd,
1660 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1661 "Forward packets over multiple paths\n"
1662 "iBGP-multipath\n"
1663 "Number of paths\n"
1664 "Match the cluster length\n")
1665 {
1666 int idx_number = 2;
1667 return bgp_maxpaths_config_vty(
1668 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1669 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1670 }
1671
1672 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1673 "maximum-paths ibgp " CMD_RANGE_STR(
1674 1, MULTIPATH_NUM) " equal-cluster-length",
1675 "Forward packets over multiple paths\n"
1676 "iBGP-multipath\n"
1677 "Number of paths\n"
1678 "Match the cluster length\n")
1679
1680 DEFUN (no_bgp_maxpaths,
1681 no_bgp_maxpaths_cmd,
1682 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1683 NO_STR
1684 "Forward packets over multiple paths\n"
1685 "Number of paths\n")
1686 {
1687 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1688 }
1689
1690 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1691 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1692 "Forward packets over multiple paths\n"
1693 "Number of paths\n")
1694
1695 DEFUN (no_bgp_maxpaths_ibgp,
1696 no_bgp_maxpaths_ibgp_cmd,
1697 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1698 NO_STR
1699 "Forward packets over multiple paths\n"
1700 "iBGP-multipath\n"
1701 "Number of paths\n"
1702 "Match the cluster length\n")
1703 {
1704 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1705 }
1706
1707 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1708 "no maximum-paths ibgp [" CMD_RANGE_STR(
1709 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1710 NO_STR
1711 "Forward packets over multiple paths\n"
1712 "iBGP-multipath\n"
1713 "Number of paths\n"
1714 "Match the cluster length\n")
1715
1716 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1717 safi_t safi)
1718 {
1719 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1720 vty_out(vty, " maximum-paths %d\n",
1721 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1722 }
1723
1724 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1725 vty_out(vty, " maximum-paths ibgp %d",
1726 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1727 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1728 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1729 vty_out(vty, " equal-cluster-length");
1730 vty_out(vty, "\n");
1731 }
1732 }
1733
1734 /* BGP timers. */
1735
1736 DEFUN (bgp_timers,
1737 bgp_timers_cmd,
1738 "timers bgp (0-65535) (0-65535)",
1739 "Adjust routing timers\n"
1740 "BGP timers\n"
1741 "Keepalive interval\n"
1742 "Holdtime\n")
1743 {
1744 VTY_DECLVAR_CONTEXT(bgp, bgp);
1745 int idx_number = 2;
1746 int idx_number_2 = 3;
1747 unsigned long keepalive = 0;
1748 unsigned long holdtime = 0;
1749
1750 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1751 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1752
1753 /* Holdtime value check. */
1754 if (holdtime < 3 && holdtime != 0) {
1755 vty_out(vty,
1756 "%% hold time value must be either 0 or greater than 3\n");
1757 return CMD_WARNING_CONFIG_FAILED;
1758 }
1759
1760 bgp_timers_set(bgp, keepalive, holdtime);
1761
1762 return CMD_SUCCESS;
1763 }
1764
1765 DEFUN (no_bgp_timers,
1766 no_bgp_timers_cmd,
1767 "no timers bgp [(0-65535) (0-65535)]",
1768 NO_STR
1769 "Adjust routing timers\n"
1770 "BGP timers\n"
1771 "Keepalive interval\n"
1772 "Holdtime\n")
1773 {
1774 VTY_DECLVAR_CONTEXT(bgp, bgp);
1775 bgp_timers_unset(bgp);
1776
1777 return CMD_SUCCESS;
1778 }
1779
1780
1781 DEFUN (bgp_client_to_client_reflection,
1782 bgp_client_to_client_reflection_cmd,
1783 "bgp client-to-client reflection",
1784 "BGP specific commands\n"
1785 "Configure client to client route reflection\n"
1786 "reflection of routes allowed\n")
1787 {
1788 VTY_DECLVAR_CONTEXT(bgp, bgp);
1789 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1790 bgp_clear_star_soft_out(vty, bgp->name);
1791
1792 return CMD_SUCCESS;
1793 }
1794
1795 DEFUN (no_bgp_client_to_client_reflection,
1796 no_bgp_client_to_client_reflection_cmd,
1797 "no bgp client-to-client reflection",
1798 NO_STR
1799 "BGP specific commands\n"
1800 "Configure client to client route reflection\n"
1801 "reflection of routes allowed\n")
1802 {
1803 VTY_DECLVAR_CONTEXT(bgp, bgp);
1804 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1805 bgp_clear_star_soft_out(vty, bgp->name);
1806
1807 return CMD_SUCCESS;
1808 }
1809
1810 /* "bgp always-compare-med" configuration. */
1811 DEFUN (bgp_always_compare_med,
1812 bgp_always_compare_med_cmd,
1813 "bgp always-compare-med",
1814 "BGP specific commands\n"
1815 "Allow comparing MED from different neighbors\n")
1816 {
1817 VTY_DECLVAR_CONTEXT(bgp, bgp);
1818 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1819 bgp_recalculate_all_bestpaths(bgp);
1820
1821 return CMD_SUCCESS;
1822 }
1823
1824 DEFUN (no_bgp_always_compare_med,
1825 no_bgp_always_compare_med_cmd,
1826 "no bgp always-compare-med",
1827 NO_STR
1828 "BGP specific commands\n"
1829 "Allow comparing MED from different neighbors\n")
1830 {
1831 VTY_DECLVAR_CONTEXT(bgp, bgp);
1832 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1833 bgp_recalculate_all_bestpaths(bgp);
1834
1835 return CMD_SUCCESS;
1836 }
1837
1838
1839 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1840 "bgp ebgp-requires-policy",
1841 "BGP specific commands\n"
1842 "Require in and out policy for eBGP peers (RFC8212)\n")
1843 {
1844 VTY_DECLVAR_CONTEXT(bgp, bgp);
1845 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1846 return CMD_SUCCESS;
1847 }
1848
1849 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1850 "no bgp ebgp-requires-policy",
1851 NO_STR
1852 "BGP specific commands\n"
1853 "Require in and out policy for eBGP peers (RFC8212)\n")
1854 {
1855 VTY_DECLVAR_CONTEXT(bgp, bgp);
1856 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1857 return CMD_SUCCESS;
1858 }
1859
1860
1861 /* "bgp deterministic-med" configuration. */
1862 DEFUN (bgp_deterministic_med,
1863 bgp_deterministic_med_cmd,
1864 "bgp deterministic-med",
1865 "BGP specific commands\n"
1866 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1867 {
1868 VTY_DECLVAR_CONTEXT(bgp, bgp);
1869
1870 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1871 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1872 bgp_recalculate_all_bestpaths(bgp);
1873 }
1874
1875 return CMD_SUCCESS;
1876 }
1877
1878 DEFUN (no_bgp_deterministic_med,
1879 no_bgp_deterministic_med_cmd,
1880 "no bgp deterministic-med",
1881 NO_STR
1882 "BGP specific commands\n"
1883 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1884 {
1885 VTY_DECLVAR_CONTEXT(bgp, bgp);
1886 int bestpath_per_as_used;
1887 afi_t afi;
1888 safi_t safi;
1889 struct peer *peer;
1890 struct listnode *node, *nnode;
1891
1892 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1893 bestpath_per_as_used = 0;
1894
1895 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1896 FOREACH_AFI_SAFI (afi, safi)
1897 if (bgp_addpath_dmed_required(
1898 peer->addpath_type[afi][safi])) {
1899 bestpath_per_as_used = 1;
1900 break;
1901 }
1902
1903 if (bestpath_per_as_used)
1904 break;
1905 }
1906
1907 if (bestpath_per_as_used) {
1908 vty_out(vty,
1909 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1910 return CMD_WARNING_CONFIG_FAILED;
1911 } else {
1912 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1913 bgp_recalculate_all_bestpaths(bgp);
1914 }
1915 }
1916
1917 return CMD_SUCCESS;
1918 }
1919
1920 /* "bgp graceful-restart" configuration. */
1921 DEFUN (bgp_graceful_restart,
1922 bgp_graceful_restart_cmd,
1923 "bgp graceful-restart",
1924 "BGP specific commands\n"
1925 "Graceful restart capability parameters\n")
1926 {
1927 VTY_DECLVAR_CONTEXT(bgp, bgp);
1928 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1929 return CMD_SUCCESS;
1930 }
1931
1932 DEFUN (no_bgp_graceful_restart,
1933 no_bgp_graceful_restart_cmd,
1934 "no bgp graceful-restart",
1935 NO_STR
1936 "BGP specific commands\n"
1937 "Graceful restart capability parameters\n")
1938 {
1939 VTY_DECLVAR_CONTEXT(bgp, bgp);
1940 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1941 return CMD_SUCCESS;
1942 }
1943
1944 DEFUN (bgp_graceful_restart_stalepath_time,
1945 bgp_graceful_restart_stalepath_time_cmd,
1946 "bgp graceful-restart stalepath-time (1-4095)",
1947 "BGP specific commands\n"
1948 "Graceful restart capability parameters\n"
1949 "Set the max time to hold onto restarting peer's stale paths\n"
1950 "Delay value (seconds)\n")
1951 {
1952 VTY_DECLVAR_CONTEXT(bgp, bgp);
1953 int idx_number = 3;
1954 uint32_t stalepath;
1955
1956 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1957 bgp->stalepath_time = stalepath;
1958 return CMD_SUCCESS;
1959 }
1960
1961 DEFUN (bgp_graceful_restart_restart_time,
1962 bgp_graceful_restart_restart_time_cmd,
1963 "bgp graceful-restart restart-time (1-4095)",
1964 "BGP specific commands\n"
1965 "Graceful restart capability parameters\n"
1966 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1967 "Delay value (seconds)\n")
1968 {
1969 VTY_DECLVAR_CONTEXT(bgp, bgp);
1970 int idx_number = 3;
1971 uint32_t restart;
1972
1973 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1974 bgp->restart_time = restart;
1975 return CMD_SUCCESS;
1976 }
1977
1978 DEFUN (no_bgp_graceful_restart_stalepath_time,
1979 no_bgp_graceful_restart_stalepath_time_cmd,
1980 "no bgp graceful-restart stalepath-time [(1-4095)]",
1981 NO_STR
1982 "BGP specific commands\n"
1983 "Graceful restart capability parameters\n"
1984 "Set the max time to hold onto restarting peer's stale paths\n"
1985 "Delay value (seconds)\n")
1986 {
1987 VTY_DECLVAR_CONTEXT(bgp, bgp);
1988
1989 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1990 return CMD_SUCCESS;
1991 }
1992
1993 DEFUN (no_bgp_graceful_restart_restart_time,
1994 no_bgp_graceful_restart_restart_time_cmd,
1995 "no bgp graceful-restart restart-time [(1-4095)]",
1996 NO_STR
1997 "BGP specific commands\n"
1998 "Graceful restart capability parameters\n"
1999 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2000 "Delay value (seconds)\n")
2001 {
2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003
2004 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2005 return CMD_SUCCESS;
2006 }
2007
2008 DEFUN (bgp_graceful_restart_preserve_fw,
2009 bgp_graceful_restart_preserve_fw_cmd,
2010 "bgp graceful-restart preserve-fw-state",
2011 "BGP specific commands\n"
2012 "Graceful restart capability parameters\n"
2013 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2014 {
2015 VTY_DECLVAR_CONTEXT(bgp, bgp);
2016 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2017 return CMD_SUCCESS;
2018 }
2019
2020 DEFUN (no_bgp_graceful_restart_preserve_fw,
2021 no_bgp_graceful_restart_preserve_fw_cmd,
2022 "no bgp graceful-restart preserve-fw-state",
2023 NO_STR
2024 "BGP specific commands\n"
2025 "Graceful restart capability parameters\n"
2026 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2027 {
2028 VTY_DECLVAR_CONTEXT(bgp, bgp);
2029 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2030 return CMD_SUCCESS;
2031 }
2032
2033 /* "bgp graceful-shutdown" configuration */
2034 DEFUN (bgp_graceful_shutdown,
2035 bgp_graceful_shutdown_cmd,
2036 "bgp graceful-shutdown",
2037 BGP_STR
2038 "Graceful shutdown parameters\n")
2039 {
2040 VTY_DECLVAR_CONTEXT(bgp, bgp);
2041
2042 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2043 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2044 bgp_static_redo_import_check(bgp);
2045 bgp_redistribute_redo(bgp);
2046 bgp_clear_star_soft_out(vty, bgp->name);
2047 bgp_clear_star_soft_in(vty, bgp->name);
2048 }
2049
2050 return CMD_SUCCESS;
2051 }
2052
2053 DEFUN (no_bgp_graceful_shutdown,
2054 no_bgp_graceful_shutdown_cmd,
2055 "no bgp graceful-shutdown",
2056 NO_STR
2057 BGP_STR
2058 "Graceful shutdown parameters\n")
2059 {
2060 VTY_DECLVAR_CONTEXT(bgp, bgp);
2061
2062 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2063 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2064 bgp_static_redo_import_check(bgp);
2065 bgp_redistribute_redo(bgp);
2066 bgp_clear_star_soft_out(vty, bgp->name);
2067 bgp_clear_star_soft_in(vty, bgp->name);
2068 }
2069
2070 return CMD_SUCCESS;
2071 }
2072
2073 /* "bgp fast-external-failover" configuration. */
2074 DEFUN (bgp_fast_external_failover,
2075 bgp_fast_external_failover_cmd,
2076 "bgp fast-external-failover",
2077 BGP_STR
2078 "Immediately reset session if a link to a directly connected external peer goes down\n")
2079 {
2080 VTY_DECLVAR_CONTEXT(bgp, bgp);
2081 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2082 return CMD_SUCCESS;
2083 }
2084
2085 DEFUN (no_bgp_fast_external_failover,
2086 no_bgp_fast_external_failover_cmd,
2087 "no bgp fast-external-failover",
2088 NO_STR
2089 BGP_STR
2090 "Immediately reset session if a link to a directly connected external peer goes down\n")
2091 {
2092 VTY_DECLVAR_CONTEXT(bgp, bgp);
2093 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2094 return CMD_SUCCESS;
2095 }
2096
2097 /* "bgp bestpath compare-routerid" configuration. */
2098 DEFUN (bgp_bestpath_compare_router_id,
2099 bgp_bestpath_compare_router_id_cmd,
2100 "bgp bestpath compare-routerid",
2101 "BGP specific commands\n"
2102 "Change the default bestpath selection\n"
2103 "Compare router-id for identical EBGP paths\n")
2104 {
2105 VTY_DECLVAR_CONTEXT(bgp, bgp);
2106 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2107 bgp_recalculate_all_bestpaths(bgp);
2108
2109 return CMD_SUCCESS;
2110 }
2111
2112 DEFUN (no_bgp_bestpath_compare_router_id,
2113 no_bgp_bestpath_compare_router_id_cmd,
2114 "no bgp bestpath compare-routerid",
2115 NO_STR
2116 "BGP specific commands\n"
2117 "Change the default bestpath selection\n"
2118 "Compare router-id for identical EBGP paths\n")
2119 {
2120 VTY_DECLVAR_CONTEXT(bgp, bgp);
2121 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2122 bgp_recalculate_all_bestpaths(bgp);
2123
2124 return CMD_SUCCESS;
2125 }
2126
2127 /* "bgp bestpath as-path ignore" configuration. */
2128 DEFUN (bgp_bestpath_aspath_ignore,
2129 bgp_bestpath_aspath_ignore_cmd,
2130 "bgp bestpath as-path ignore",
2131 "BGP specific commands\n"
2132 "Change the default bestpath selection\n"
2133 "AS-path attribute\n"
2134 "Ignore as-path length in selecting a route\n")
2135 {
2136 VTY_DECLVAR_CONTEXT(bgp, bgp);
2137 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2138 bgp_recalculate_all_bestpaths(bgp);
2139
2140 return CMD_SUCCESS;
2141 }
2142
2143 DEFUN (no_bgp_bestpath_aspath_ignore,
2144 no_bgp_bestpath_aspath_ignore_cmd,
2145 "no bgp bestpath as-path ignore",
2146 NO_STR
2147 "BGP specific commands\n"
2148 "Change the default bestpath selection\n"
2149 "AS-path attribute\n"
2150 "Ignore as-path length in selecting a route\n")
2151 {
2152 VTY_DECLVAR_CONTEXT(bgp, bgp);
2153 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2154 bgp_recalculate_all_bestpaths(bgp);
2155
2156 return CMD_SUCCESS;
2157 }
2158
2159 /* "bgp bestpath as-path confed" configuration. */
2160 DEFUN (bgp_bestpath_aspath_confed,
2161 bgp_bestpath_aspath_confed_cmd,
2162 "bgp bestpath as-path confed",
2163 "BGP specific commands\n"
2164 "Change the default bestpath selection\n"
2165 "AS-path attribute\n"
2166 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2167 {
2168 VTY_DECLVAR_CONTEXT(bgp, bgp);
2169 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2170 bgp_recalculate_all_bestpaths(bgp);
2171
2172 return CMD_SUCCESS;
2173 }
2174
2175 DEFUN (no_bgp_bestpath_aspath_confed,
2176 no_bgp_bestpath_aspath_confed_cmd,
2177 "no bgp bestpath as-path confed",
2178 NO_STR
2179 "BGP specific commands\n"
2180 "Change the default bestpath selection\n"
2181 "AS-path attribute\n"
2182 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2183 {
2184 VTY_DECLVAR_CONTEXT(bgp, bgp);
2185 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2186 bgp_recalculate_all_bestpaths(bgp);
2187
2188 return CMD_SUCCESS;
2189 }
2190
2191 /* "bgp bestpath as-path multipath-relax" configuration. */
2192 DEFUN (bgp_bestpath_aspath_multipath_relax,
2193 bgp_bestpath_aspath_multipath_relax_cmd,
2194 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2195 "BGP specific commands\n"
2196 "Change the default bestpath selection\n"
2197 "AS-path attribute\n"
2198 "Allow load sharing across routes that have different AS paths (but same length)\n"
2199 "Generate an AS_SET\n"
2200 "Do not generate an AS_SET\n")
2201 {
2202 VTY_DECLVAR_CONTEXT(bgp, bgp);
2203 int idx = 0;
2204 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2205
2206 /* no-as-set is now the default behavior so we can silently
2207 * ignore it */
2208 if (argv_find(argv, argc, "as-set", &idx))
2209 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2210 else
2211 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2212
2213 bgp_recalculate_all_bestpaths(bgp);
2214
2215 return CMD_SUCCESS;
2216 }
2217
2218 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2219 no_bgp_bestpath_aspath_multipath_relax_cmd,
2220 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2221 NO_STR
2222 "BGP specific commands\n"
2223 "Change the default bestpath selection\n"
2224 "AS-path attribute\n"
2225 "Allow load sharing across routes that have different AS paths (but same length)\n"
2226 "Generate an AS_SET\n"
2227 "Do not generate an AS_SET\n")
2228 {
2229 VTY_DECLVAR_CONTEXT(bgp, bgp);
2230 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2231 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2232 bgp_recalculate_all_bestpaths(bgp);
2233
2234 return CMD_SUCCESS;
2235 }
2236
2237 /* "bgp log-neighbor-changes" configuration. */
2238 DEFUN (bgp_log_neighbor_changes,
2239 bgp_log_neighbor_changes_cmd,
2240 "bgp log-neighbor-changes",
2241 "BGP specific commands\n"
2242 "Log neighbor up/down and reset reason\n")
2243 {
2244 VTY_DECLVAR_CONTEXT(bgp, bgp);
2245 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2246 return CMD_SUCCESS;
2247 }
2248
2249 DEFUN (no_bgp_log_neighbor_changes,
2250 no_bgp_log_neighbor_changes_cmd,
2251 "no bgp log-neighbor-changes",
2252 NO_STR
2253 "BGP specific commands\n"
2254 "Log neighbor up/down and reset reason\n")
2255 {
2256 VTY_DECLVAR_CONTEXT(bgp, bgp);
2257 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2258 return CMD_SUCCESS;
2259 }
2260
2261 /* "bgp bestpath med" configuration. */
2262 DEFUN (bgp_bestpath_med,
2263 bgp_bestpath_med_cmd,
2264 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2265 "BGP specific commands\n"
2266 "Change the default bestpath selection\n"
2267 "MED attribute\n"
2268 "Compare MED among confederation paths\n"
2269 "Treat missing MED as the least preferred one\n"
2270 "Treat missing MED as the least preferred one\n"
2271 "Compare MED among confederation paths\n")
2272 {
2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274
2275 int idx = 0;
2276 if (argv_find(argv, argc, "confed", &idx))
2277 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2278 idx = 0;
2279 if (argv_find(argv, argc, "missing-as-worst", &idx))
2280 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2281
2282 bgp_recalculate_all_bestpaths(bgp);
2283
2284 return CMD_SUCCESS;
2285 }
2286
2287 DEFUN (no_bgp_bestpath_med,
2288 no_bgp_bestpath_med_cmd,
2289 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2290 NO_STR
2291 "BGP specific commands\n"
2292 "Change the default bestpath selection\n"
2293 "MED attribute\n"
2294 "Compare MED among confederation paths\n"
2295 "Treat missing MED as the least preferred one\n"
2296 "Treat missing MED as the least preferred one\n"
2297 "Compare MED among confederation paths\n")
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300
2301 int idx = 0;
2302 if (argv_find(argv, argc, "confed", &idx))
2303 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2304 idx = 0;
2305 if (argv_find(argv, argc, "missing-as-worst", &idx))
2306 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2307
2308 bgp_recalculate_all_bestpaths(bgp);
2309
2310 return CMD_SUCCESS;
2311 }
2312
2313 /* "no bgp default ipv4-unicast". */
2314 DEFUN (no_bgp_default_ipv4_unicast,
2315 no_bgp_default_ipv4_unicast_cmd,
2316 "no bgp default ipv4-unicast",
2317 NO_STR
2318 "BGP specific commands\n"
2319 "Configure BGP defaults\n"
2320 "Activate ipv4-unicast for a peer by default\n")
2321 {
2322 VTY_DECLVAR_CONTEXT(bgp, bgp);
2323 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2324 return CMD_SUCCESS;
2325 }
2326
2327 DEFUN (bgp_default_ipv4_unicast,
2328 bgp_default_ipv4_unicast_cmd,
2329 "bgp default ipv4-unicast",
2330 "BGP specific commands\n"
2331 "Configure BGP defaults\n"
2332 "Activate ipv4-unicast for a peer by default\n")
2333 {
2334 VTY_DECLVAR_CONTEXT(bgp, bgp);
2335 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2336 return CMD_SUCCESS;
2337 }
2338
2339 /* Display hostname in certain command outputs */
2340 DEFUN (bgp_default_show_hostname,
2341 bgp_default_show_hostname_cmd,
2342 "bgp default show-hostname",
2343 "BGP specific commands\n"
2344 "Configure BGP defaults\n"
2345 "Show hostname in certain command outputs\n")
2346 {
2347 VTY_DECLVAR_CONTEXT(bgp, bgp);
2348 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2349 return CMD_SUCCESS;
2350 }
2351
2352 DEFUN (no_bgp_default_show_hostname,
2353 no_bgp_default_show_hostname_cmd,
2354 "no bgp default show-hostname",
2355 NO_STR
2356 "BGP specific commands\n"
2357 "Configure BGP defaults\n"
2358 "Show hostname in certain command outputs\n")
2359 {
2360 VTY_DECLVAR_CONTEXT(bgp, bgp);
2361 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2362 return CMD_SUCCESS;
2363 }
2364
2365 /* "bgp network import-check" configuration. */
2366 DEFUN (bgp_network_import_check,
2367 bgp_network_import_check_cmd,
2368 "bgp network import-check",
2369 "BGP specific commands\n"
2370 "BGP network command\n"
2371 "Check BGP network route exists in IGP\n")
2372 {
2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
2374 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2375 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2376 bgp_static_redo_import_check(bgp);
2377 }
2378
2379 return CMD_SUCCESS;
2380 }
2381
2382 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2383 "bgp network import-check exact",
2384 "BGP specific commands\n"
2385 "BGP network command\n"
2386 "Check BGP network route exists in IGP\n"
2387 "Match route precisely\n")
2388
2389 DEFUN (no_bgp_network_import_check,
2390 no_bgp_network_import_check_cmd,
2391 "no bgp network import-check",
2392 NO_STR
2393 "BGP specific commands\n"
2394 "BGP network command\n"
2395 "Check BGP network route exists in IGP\n")
2396 {
2397 VTY_DECLVAR_CONTEXT(bgp, bgp);
2398 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2399 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2400 bgp_static_redo_import_check(bgp);
2401 }
2402
2403 return CMD_SUCCESS;
2404 }
2405
2406 DEFUN (bgp_default_local_preference,
2407 bgp_default_local_preference_cmd,
2408 "bgp default local-preference (0-4294967295)",
2409 "BGP specific commands\n"
2410 "Configure BGP defaults\n"
2411 "local preference (higher=more preferred)\n"
2412 "Configure default local preference value\n")
2413 {
2414 VTY_DECLVAR_CONTEXT(bgp, bgp);
2415 int idx_number = 3;
2416 uint32_t local_pref;
2417
2418 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2419
2420 bgp_default_local_preference_set(bgp, local_pref);
2421 bgp_clear_star_soft_in(vty, bgp->name);
2422
2423 return CMD_SUCCESS;
2424 }
2425
2426 DEFUN (no_bgp_default_local_preference,
2427 no_bgp_default_local_preference_cmd,
2428 "no bgp default local-preference [(0-4294967295)]",
2429 NO_STR
2430 "BGP specific commands\n"
2431 "Configure BGP defaults\n"
2432 "local preference (higher=more preferred)\n"
2433 "Configure default local preference value\n")
2434 {
2435 VTY_DECLVAR_CONTEXT(bgp, bgp);
2436 bgp_default_local_preference_unset(bgp);
2437 bgp_clear_star_soft_in(vty, bgp->name);
2438
2439 return CMD_SUCCESS;
2440 }
2441
2442
2443 DEFUN (bgp_default_subgroup_pkt_queue_max,
2444 bgp_default_subgroup_pkt_queue_max_cmd,
2445 "bgp default subgroup-pkt-queue-max (20-100)",
2446 "BGP specific commands\n"
2447 "Configure BGP defaults\n"
2448 "subgroup-pkt-queue-max\n"
2449 "Configure subgroup packet queue max\n")
2450 {
2451 VTY_DECLVAR_CONTEXT(bgp, bgp);
2452 int idx_number = 3;
2453 uint32_t max_size;
2454
2455 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2456
2457 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2458
2459 return CMD_SUCCESS;
2460 }
2461
2462 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2463 no_bgp_default_subgroup_pkt_queue_max_cmd,
2464 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2465 NO_STR
2466 "BGP specific commands\n"
2467 "Configure BGP defaults\n"
2468 "subgroup-pkt-queue-max\n"
2469 "Configure subgroup packet queue max\n")
2470 {
2471 VTY_DECLVAR_CONTEXT(bgp, bgp);
2472 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2473 return CMD_SUCCESS;
2474 }
2475
2476
2477 DEFUN (bgp_rr_allow_outbound_policy,
2478 bgp_rr_allow_outbound_policy_cmd,
2479 "bgp route-reflector allow-outbound-policy",
2480 "BGP specific commands\n"
2481 "Allow modifications made by out route-map\n"
2482 "on ibgp neighbors\n")
2483 {
2484 VTY_DECLVAR_CONTEXT(bgp, bgp);
2485
2486 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2487 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2488 update_group_announce_rrclients(bgp);
2489 bgp_clear_star_soft_out(vty, bgp->name);
2490 }
2491
2492 return CMD_SUCCESS;
2493 }
2494
2495 DEFUN (no_bgp_rr_allow_outbound_policy,
2496 no_bgp_rr_allow_outbound_policy_cmd,
2497 "no bgp route-reflector allow-outbound-policy",
2498 NO_STR
2499 "BGP specific commands\n"
2500 "Allow modifications made by out route-map\n"
2501 "on ibgp neighbors\n")
2502 {
2503 VTY_DECLVAR_CONTEXT(bgp, bgp);
2504
2505 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2506 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2507 update_group_announce_rrclients(bgp);
2508 bgp_clear_star_soft_out(vty, bgp->name);
2509 }
2510
2511 return CMD_SUCCESS;
2512 }
2513
2514 DEFUN (bgp_listen_limit,
2515 bgp_listen_limit_cmd,
2516 "bgp listen limit (1-5000)",
2517 "BGP specific commands\n"
2518 "Configure BGP defaults\n"
2519 "maximum number of BGP Dynamic Neighbors that can be created\n"
2520 "Configure Dynamic Neighbors listen limit value\n")
2521 {
2522 VTY_DECLVAR_CONTEXT(bgp, bgp);
2523 int idx_number = 3;
2524 int listen_limit;
2525
2526 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2527
2528 bgp_listen_limit_set(bgp, listen_limit);
2529
2530 return CMD_SUCCESS;
2531 }
2532
2533 DEFUN (no_bgp_listen_limit,
2534 no_bgp_listen_limit_cmd,
2535 "no bgp listen limit [(1-5000)]",
2536 "BGP specific commands\n"
2537 "Configure BGP defaults\n"
2538 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2539 "Configure Dynamic Neighbors listen limit value to default\n"
2540 "Configure Dynamic Neighbors listen limit value\n")
2541 {
2542 VTY_DECLVAR_CONTEXT(bgp, bgp);
2543 bgp_listen_limit_unset(bgp);
2544 return CMD_SUCCESS;
2545 }
2546
2547
2548 /*
2549 * Check if this listen range is already configured. Check for exact
2550 * match or overlap based on input.
2551 */
2552 static struct peer_group *listen_range_exists(struct bgp *bgp,
2553 struct prefix *range, int exact)
2554 {
2555 struct listnode *node, *nnode;
2556 struct listnode *node1, *nnode1;
2557 struct peer_group *group;
2558 struct prefix *lr;
2559 afi_t afi;
2560 int match;
2561
2562 afi = family2afi(range->family);
2563 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2564 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2565 lr)) {
2566 if (exact)
2567 match = prefix_same(range, lr);
2568 else
2569 match = (prefix_match(range, lr)
2570 || prefix_match(lr, range));
2571 if (match)
2572 return group;
2573 }
2574 }
2575
2576 return NULL;
2577 }
2578
2579 DEFUN (bgp_listen_range,
2580 bgp_listen_range_cmd,
2581 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2582 "BGP specific commands\n"
2583 "Configure BGP dynamic neighbors listen range\n"
2584 "Configure BGP dynamic neighbors listen range\n"
2585 NEIGHBOR_ADDR_STR
2586 "Member of the peer-group\n"
2587 "Peer-group name\n")
2588 {
2589 VTY_DECLVAR_CONTEXT(bgp, bgp);
2590 struct prefix range;
2591 struct peer_group *group, *existing_group;
2592 afi_t afi;
2593 int ret;
2594 int idx = 0;
2595
2596 argv_find(argv, argc, "A.B.C.D/M", &idx);
2597 argv_find(argv, argc, "X:X::X:X/M", &idx);
2598 char *prefix = argv[idx]->arg;
2599 argv_find(argv, argc, "PGNAME", &idx);
2600 char *peergroup = argv[idx]->arg;
2601
2602 /* Convert IP prefix string to struct prefix. */
2603 ret = str2prefix(prefix, &range);
2604 if (!ret) {
2605 vty_out(vty, "%% Malformed listen range\n");
2606 return CMD_WARNING_CONFIG_FAILED;
2607 }
2608
2609 afi = family2afi(range.family);
2610
2611 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2612 vty_out(vty,
2613 "%% Malformed listen range (link-local address)\n");
2614 return CMD_WARNING_CONFIG_FAILED;
2615 }
2616
2617 apply_mask(&range);
2618
2619 /* Check if same listen range is already configured. */
2620 existing_group = listen_range_exists(bgp, &range, 1);
2621 if (existing_group) {
2622 if (strcmp(existing_group->name, peergroup) == 0)
2623 return CMD_SUCCESS;
2624 else {
2625 vty_out(vty,
2626 "%% Same listen range is attached to peer-group %s\n",
2627 existing_group->name);
2628 return CMD_WARNING_CONFIG_FAILED;
2629 }
2630 }
2631
2632 /* Check if an overlapping listen range exists. */
2633 if (listen_range_exists(bgp, &range, 0)) {
2634 vty_out(vty,
2635 "%% Listen range overlaps with existing listen range\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
2638
2639 group = peer_group_lookup(bgp, peergroup);
2640 if (!group) {
2641 vty_out(vty, "%% Configure the peer-group first\n");
2642 return CMD_WARNING_CONFIG_FAILED;
2643 }
2644
2645 ret = peer_group_listen_range_add(group, &range);
2646 return bgp_vty_return(vty, ret);
2647 }
2648
2649 DEFUN (no_bgp_listen_range,
2650 no_bgp_listen_range_cmd,
2651 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME",
2652 NO_STR
2653 "BGP specific commands\n"
2654 "Unconfigure BGP dynamic neighbors listen range\n"
2655 "Unconfigure BGP dynamic neighbors listen range\n"
2656 NEIGHBOR_ADDR_STR
2657 "Member of the peer-group\n"
2658 "Peer-group name\n")
2659 {
2660 VTY_DECLVAR_CONTEXT(bgp, bgp);
2661 struct prefix range;
2662 struct peer_group *group;
2663 afi_t afi;
2664 int ret;
2665 int idx = 0;
2666
2667 argv_find(argv, argc, "A.B.C.D/M", &idx);
2668 argv_find(argv, argc, "X:X::X:X/M", &idx);
2669 char *prefix = argv[idx]->arg;
2670 argv_find(argv, argc, "WORD", &idx);
2671 char *peergroup = argv[idx]->arg;
2672
2673 /* Convert IP prefix string to struct prefix. */
2674 ret = str2prefix(prefix, &range);
2675 if (!ret) {
2676 vty_out(vty, "%% Malformed listen range\n");
2677 return CMD_WARNING_CONFIG_FAILED;
2678 }
2679
2680 afi = family2afi(range.family);
2681
2682 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2683 vty_out(vty,
2684 "%% Malformed listen range (link-local address)\n");
2685 return CMD_WARNING_CONFIG_FAILED;
2686 }
2687
2688 apply_mask(&range);
2689
2690 group = peer_group_lookup(bgp, peergroup);
2691 if (!group) {
2692 vty_out(vty, "%% Peer-group does not exist\n");
2693 return CMD_WARNING_CONFIG_FAILED;
2694 }
2695
2696 ret = peer_group_listen_range_del(group, &range);
2697 return bgp_vty_return(vty, ret);
2698 }
2699
2700 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2701 {
2702 struct peer_group *group;
2703 struct listnode *node, *nnode, *rnode, *nrnode;
2704 struct prefix *range;
2705 afi_t afi;
2706 char buf[PREFIX2STR_BUFFER];
2707
2708 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2709 vty_out(vty, " bgp listen limit %d\n",
2710 bgp->dynamic_neighbors_limit);
2711
2712 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2713 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2714 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2715 nrnode, range)) {
2716 prefix2str(range, buf, sizeof(buf));
2717 vty_out(vty,
2718 " bgp listen range %s peer-group %s\n",
2719 buf, group->name);
2720 }
2721 }
2722 }
2723 }
2724
2725
2726 DEFUN (bgp_disable_connected_route_check,
2727 bgp_disable_connected_route_check_cmd,
2728 "bgp disable-ebgp-connected-route-check",
2729 "BGP specific commands\n"
2730 "Disable checking if nexthop is connected on ebgp sessions\n")
2731 {
2732 VTY_DECLVAR_CONTEXT(bgp, bgp);
2733 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2734 bgp_clear_star_soft_in(vty, bgp->name);
2735
2736 return CMD_SUCCESS;
2737 }
2738
2739 DEFUN (no_bgp_disable_connected_route_check,
2740 no_bgp_disable_connected_route_check_cmd,
2741 "no bgp disable-ebgp-connected-route-check",
2742 NO_STR
2743 "BGP specific commands\n"
2744 "Disable checking if nexthop is connected on ebgp sessions\n")
2745 {
2746 VTY_DECLVAR_CONTEXT(bgp, bgp);
2747 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2748 bgp_clear_star_soft_in(vty, bgp->name);
2749
2750 return CMD_SUCCESS;
2751 }
2752
2753
2754 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2755 const char *as_str, afi_t afi, safi_t safi)
2756 {
2757 VTY_DECLVAR_CONTEXT(bgp, bgp);
2758 int ret;
2759 as_t as;
2760 int as_type = AS_SPECIFIED;
2761 union sockunion su;
2762
2763 if (as_str[0] == 'i') {
2764 as = 0;
2765 as_type = AS_INTERNAL;
2766 } else if (as_str[0] == 'e') {
2767 as = 0;
2768 as_type = AS_EXTERNAL;
2769 } else {
2770 /* Get AS number. */
2771 as = strtoul(as_str, NULL, 10);
2772 }
2773
2774 /* If peer is peer group or interface peer, call proper function. */
2775 ret = str2sockunion(peer_str, &su);
2776 if (ret < 0) {
2777 struct peer *peer;
2778
2779 /* Check if existing interface peer */
2780 peer = peer_lookup_by_conf_if(bgp, peer_str);
2781
2782 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2783 safi);
2784
2785 /* if not interface peer, check peer-group settings */
2786 if (ret < 0 && !peer) {
2787 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2788 if (ret < 0) {
2789 vty_out(vty,
2790 "%% Create the peer-group or interface first\n");
2791 return CMD_WARNING_CONFIG_FAILED;
2792 }
2793 return CMD_SUCCESS;
2794 }
2795 } else {
2796 if (peer_address_self_check(bgp, &su)) {
2797 vty_out(vty,
2798 "%% Can not configure the local system as neighbor\n");
2799 return CMD_WARNING_CONFIG_FAILED;
2800 }
2801 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2802 }
2803
2804 /* This peer belongs to peer group. */
2805 switch (ret) {
2806 case BGP_ERR_PEER_GROUP_MEMBER:
2807 vty_out(vty,
2808 "%% Peer-group member cannot override remote-as of peer-group\n");
2809 return CMD_WARNING_CONFIG_FAILED;
2810 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2811 vty_out(vty,
2812 "%% Peer-group members must be all internal or all external\n");
2813 return CMD_WARNING_CONFIG_FAILED;
2814 }
2815 return bgp_vty_return(vty, ret);
2816 }
2817
2818 DEFUN (bgp_default_shutdown,
2819 bgp_default_shutdown_cmd,
2820 "[no] bgp default shutdown",
2821 NO_STR
2822 BGP_STR
2823 "Configure BGP defaults\n"
2824 "Apply administrative shutdown to newly configured peers\n")
2825 {
2826 VTY_DECLVAR_CONTEXT(bgp, bgp);
2827 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2828 return CMD_SUCCESS;
2829 }
2830
2831 DEFUN (neighbor_remote_as,
2832 neighbor_remote_as_cmd,
2833 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2834 NEIGHBOR_STR
2835 NEIGHBOR_ADDR_STR2
2836 "Specify a BGP neighbor\n"
2837 AS_STR
2838 "Internal BGP peer\n"
2839 "External BGP peer\n")
2840 {
2841 int idx_peer = 1;
2842 int idx_remote_as = 3;
2843 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2844 argv[idx_remote_as]->arg, AFI_IP,
2845 SAFI_UNICAST);
2846 }
2847
2848 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2849 afi_t afi, safi_t safi, int v6only,
2850 const char *peer_group_name,
2851 const char *as_str)
2852 {
2853 VTY_DECLVAR_CONTEXT(bgp, bgp);
2854 as_t as = 0;
2855 int as_type = AS_UNSPECIFIED;
2856 struct peer *peer;
2857 struct peer_group *group;
2858 int ret = 0;
2859 union sockunion su;
2860
2861 group = peer_group_lookup(bgp, conf_if);
2862
2863 if (group) {
2864 vty_out(vty, "%% Name conflict with peer-group \n");
2865 return CMD_WARNING_CONFIG_FAILED;
2866 }
2867
2868 if (as_str) {
2869 if (as_str[0] == 'i') {
2870 as_type = AS_INTERNAL;
2871 } else if (as_str[0] == 'e') {
2872 as_type = AS_EXTERNAL;
2873 } else {
2874 /* Get AS number. */
2875 as = strtoul(as_str, NULL, 10);
2876 as_type = AS_SPECIFIED;
2877 }
2878 }
2879
2880 peer = peer_lookup_by_conf_if(bgp, conf_if);
2881 if (peer) {
2882 if (as_str)
2883 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2884 afi, safi);
2885 } else {
2886 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2887 && afi == AFI_IP && safi == SAFI_UNICAST)
2888 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2889 as_type, 0, 0, NULL);
2890 else
2891 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2892 as_type, afi, safi, NULL);
2893
2894 if (!peer) {
2895 vty_out(vty, "%% BGP failed to create peer\n");
2896 return CMD_WARNING_CONFIG_FAILED;
2897 }
2898
2899 if (v6only)
2900 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2901
2902 /* Request zebra to initiate IPv6 RAs on this interface. We do
2903 * this
2904 * any unnumbered peer in order to not worry about run-time
2905 * transitions
2906 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2907 * address
2908 * gets deleted later etc.)
2909 */
2910 if (peer->ifp)
2911 bgp_zebra_initiate_radv(bgp, peer);
2912 }
2913
2914 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2915 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2916 if (v6only)
2917 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2918 else
2919 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2920
2921 /* v6only flag changed. Reset bgp seesion */
2922 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2923 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2924 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2925 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2926 } else
2927 bgp_session_reset(peer);
2928 }
2929
2930 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2931 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2932 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2933 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2934 }
2935
2936 if (peer_group_name) {
2937 group = peer_group_lookup(bgp, peer_group_name);
2938 if (!group) {
2939 vty_out(vty, "%% Configure the peer-group first\n");
2940 return CMD_WARNING_CONFIG_FAILED;
2941 }
2942
2943 ret = peer_group_bind(bgp, &su, peer, group, &as);
2944 }
2945
2946 return bgp_vty_return(vty, ret);
2947 }
2948
2949 DEFUN (neighbor_interface_config,
2950 neighbor_interface_config_cmd,
2951 "neighbor WORD interface [peer-group PGNAME]",
2952 NEIGHBOR_STR
2953 "Interface name or neighbor tag\n"
2954 "Enable BGP on interface\n"
2955 "Member of the peer-group\n"
2956 "Peer-group name\n")
2957 {
2958 int idx_word = 1;
2959 int idx_peer_group_word = 4;
2960
2961 if (argc > idx_peer_group_word)
2962 return peer_conf_interface_get(
2963 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2964 argv[idx_peer_group_word]->arg, NULL);
2965 else
2966 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2967 SAFI_UNICAST, 0, NULL, NULL);
2968 }
2969
2970 DEFUN (neighbor_interface_config_v6only,
2971 neighbor_interface_config_v6only_cmd,
2972 "neighbor WORD interface v6only [peer-group PGNAME]",
2973 NEIGHBOR_STR
2974 "Interface name or neighbor tag\n"
2975 "Enable BGP on interface\n"
2976 "Enable BGP with v6 link-local only\n"
2977 "Member of the peer-group\n"
2978 "Peer-group name\n")
2979 {
2980 int idx_word = 1;
2981 int idx_peer_group_word = 5;
2982
2983 if (argc > idx_peer_group_word)
2984 return peer_conf_interface_get(
2985 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2986 argv[idx_peer_group_word]->arg, NULL);
2987
2988 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2989 SAFI_UNICAST, 1, NULL, NULL);
2990 }
2991
2992
2993 DEFUN (neighbor_interface_config_remote_as,
2994 neighbor_interface_config_remote_as_cmd,
2995 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2996 NEIGHBOR_STR
2997 "Interface name or neighbor tag\n"
2998 "Enable BGP on interface\n"
2999 "Specify a BGP neighbor\n"
3000 AS_STR
3001 "Internal BGP peer\n"
3002 "External BGP peer\n")
3003 {
3004 int idx_word = 1;
3005 int idx_remote_as = 4;
3006 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3007 SAFI_UNICAST, 0, NULL,
3008 argv[idx_remote_as]->arg);
3009 }
3010
3011 DEFUN (neighbor_interface_v6only_config_remote_as,
3012 neighbor_interface_v6only_config_remote_as_cmd,
3013 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3014 NEIGHBOR_STR
3015 "Interface name or neighbor tag\n"
3016 "Enable BGP with v6 link-local only\n"
3017 "Enable BGP on interface\n"
3018 "Specify a BGP neighbor\n"
3019 AS_STR
3020 "Internal BGP peer\n"
3021 "External BGP peer\n")
3022 {
3023 int idx_word = 1;
3024 int idx_remote_as = 5;
3025 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3026 SAFI_UNICAST, 1, NULL,
3027 argv[idx_remote_as]->arg);
3028 }
3029
3030 DEFUN (neighbor_peer_group,
3031 neighbor_peer_group_cmd,
3032 "neighbor WORD peer-group",
3033 NEIGHBOR_STR
3034 "Interface name or neighbor tag\n"
3035 "Configure peer-group\n")
3036 {
3037 VTY_DECLVAR_CONTEXT(bgp, bgp);
3038 int idx_word = 1;
3039 struct peer *peer;
3040 struct peer_group *group;
3041
3042 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3043 if (peer) {
3044 vty_out(vty, "%% Name conflict with interface: \n");
3045 return CMD_WARNING_CONFIG_FAILED;
3046 }
3047
3048 group = peer_group_get(bgp, argv[idx_word]->arg);
3049 if (!group) {
3050 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3051 return CMD_WARNING_CONFIG_FAILED;
3052 }
3053
3054 return CMD_SUCCESS;
3055 }
3056
3057 DEFUN (no_neighbor,
3058 no_neighbor_cmd,
3059 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3060 NO_STR
3061 NEIGHBOR_STR
3062 NEIGHBOR_ADDR_STR2
3063 "Specify a BGP neighbor\n"
3064 AS_STR
3065 "Internal BGP peer\n"
3066 "External BGP peer\n")
3067 {
3068 VTY_DECLVAR_CONTEXT(bgp, bgp);
3069 int idx_peer = 2;
3070 int ret;
3071 union sockunion su;
3072 struct peer_group *group;
3073 struct peer *peer;
3074 struct peer *other;
3075
3076 ret = str2sockunion(argv[idx_peer]->arg, &su);
3077 if (ret < 0) {
3078 /* look up for neighbor by interface name config. */
3079 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3080 if (peer) {
3081 /* Request zebra to terminate IPv6 RAs on this
3082 * interface. */
3083 if (peer->ifp)
3084 bgp_zebra_terminate_radv(peer->bgp, peer);
3085 peer_delete(peer);
3086 return CMD_SUCCESS;
3087 }
3088
3089 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3090 if (group)
3091 peer_group_delete(group);
3092 else {
3093 vty_out(vty, "%% Create the peer-group first\n");
3094 return CMD_WARNING_CONFIG_FAILED;
3095 }
3096 } else {
3097 peer = peer_lookup(bgp, &su);
3098 if (peer) {
3099 if (peer_dynamic_neighbor(peer)) {
3100 vty_out(vty,
3101 "%% Operation not allowed on a dynamic neighbor\n");
3102 return CMD_WARNING_CONFIG_FAILED;
3103 }
3104
3105 other = peer->doppelganger;
3106 peer_delete(peer);
3107 if (other && other->status != Deleted)
3108 peer_delete(other);
3109 }
3110 }
3111
3112 return CMD_SUCCESS;
3113 }
3114
3115 DEFUN (no_neighbor_interface_config,
3116 no_neighbor_interface_config_cmd,
3117 "no neighbor WORD interface [v6only] [peer-group PGNAME] [remote-as <(1-4294967295)|internal|external>]",
3118 NO_STR
3119 NEIGHBOR_STR
3120 "Interface name\n"
3121 "Configure BGP on interface\n"
3122 "Enable BGP with v6 link-local only\n"
3123 "Member of the peer-group\n"
3124 "Peer-group name\n"
3125 "Specify a BGP neighbor\n"
3126 AS_STR
3127 "Internal BGP peer\n"
3128 "External BGP peer\n")
3129 {
3130 VTY_DECLVAR_CONTEXT(bgp, bgp);
3131 int idx_word = 2;
3132 struct peer *peer;
3133
3134 /* look up for neighbor by interface name config. */
3135 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3136 if (peer) {
3137 /* Request zebra to terminate IPv6 RAs on this interface. */
3138 if (peer->ifp)
3139 bgp_zebra_terminate_radv(peer->bgp, peer);
3140 peer_delete(peer);
3141 } else {
3142 vty_out(vty, "%% Create the bgp interface first\n");
3143 return CMD_WARNING_CONFIG_FAILED;
3144 }
3145 return CMD_SUCCESS;
3146 }
3147
3148 DEFUN (no_neighbor_peer_group,
3149 no_neighbor_peer_group_cmd,
3150 "no neighbor WORD peer-group",
3151 NO_STR
3152 NEIGHBOR_STR
3153 "Neighbor tag\n"
3154 "Configure peer-group\n")
3155 {
3156 VTY_DECLVAR_CONTEXT(bgp, bgp);
3157 int idx_word = 2;
3158 struct peer_group *group;
3159
3160 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3161 if (group)
3162 peer_group_delete(group);
3163 else {
3164 vty_out(vty, "%% Create the peer-group first\n");
3165 return CMD_WARNING_CONFIG_FAILED;
3166 }
3167 return CMD_SUCCESS;
3168 }
3169
3170 DEFUN (no_neighbor_interface_peer_group_remote_as,
3171 no_neighbor_interface_peer_group_remote_as_cmd,
3172 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3173 NO_STR
3174 NEIGHBOR_STR
3175 "Interface name or neighbor tag\n"
3176 "Specify a BGP neighbor\n"
3177 AS_STR
3178 "Internal BGP peer\n"
3179 "External BGP peer\n")
3180 {
3181 VTY_DECLVAR_CONTEXT(bgp, bgp);
3182 int idx_word = 2;
3183 struct peer_group *group;
3184 struct peer *peer;
3185
3186 /* look up for neighbor by interface name config. */
3187 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3188 if (peer) {
3189 peer_as_change(peer, 0, AS_UNSPECIFIED);
3190 return CMD_SUCCESS;
3191 }
3192
3193 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3194 if (group)
3195 peer_group_remote_as_delete(group);
3196 else {
3197 vty_out(vty, "%% Create the peer-group or interface first\n");
3198 return CMD_WARNING_CONFIG_FAILED;
3199 }
3200 return CMD_SUCCESS;
3201 }
3202
3203 DEFUN (neighbor_local_as,
3204 neighbor_local_as_cmd,
3205 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3206 NEIGHBOR_STR
3207 NEIGHBOR_ADDR_STR2
3208 "Specify a local-as number\n"
3209 "AS number used as local AS\n")
3210 {
3211 int idx_peer = 1;
3212 int idx_number = 3;
3213 struct peer *peer;
3214 int ret;
3215 as_t as;
3216
3217 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3218 if (!peer)
3219 return CMD_WARNING_CONFIG_FAILED;
3220
3221 as = strtoul(argv[idx_number]->arg, NULL, 10);
3222 ret = peer_local_as_set(peer, as, 0, 0);
3223 return bgp_vty_return(vty, ret);
3224 }
3225
3226 DEFUN (neighbor_local_as_no_prepend,
3227 neighbor_local_as_no_prepend_cmd,
3228 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3229 NEIGHBOR_STR
3230 NEIGHBOR_ADDR_STR2
3231 "Specify a local-as number\n"
3232 "AS number used as local AS\n"
3233 "Do not prepend local-as to updates from ebgp peers\n")
3234 {
3235 int idx_peer = 1;
3236 int idx_number = 3;
3237 struct peer *peer;
3238 int ret;
3239 as_t as;
3240
3241 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3242 if (!peer)
3243 return CMD_WARNING_CONFIG_FAILED;
3244
3245 as = strtoul(argv[idx_number]->arg, NULL, 10);
3246 ret = peer_local_as_set(peer, as, 1, 0);
3247 return bgp_vty_return(vty, ret);
3248 }
3249
3250 DEFUN (neighbor_local_as_no_prepend_replace_as,
3251 neighbor_local_as_no_prepend_replace_as_cmd,
3252 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3253 NEIGHBOR_STR
3254 NEIGHBOR_ADDR_STR2
3255 "Specify a local-as number\n"
3256 "AS number used as local AS\n"
3257 "Do not prepend local-as to updates from ebgp peers\n"
3258 "Do not prepend local-as to updates from ibgp peers\n")
3259 {
3260 int idx_peer = 1;
3261 int idx_number = 3;
3262 struct peer *peer;
3263 int ret;
3264 as_t as;
3265
3266 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3267 if (!peer)
3268 return CMD_WARNING_CONFIG_FAILED;
3269
3270 as = strtoul(argv[idx_number]->arg, NULL, 10);
3271 ret = peer_local_as_set(peer, as, 1, 1);
3272 return bgp_vty_return(vty, ret);
3273 }
3274
3275 DEFUN (no_neighbor_local_as,
3276 no_neighbor_local_as_cmd,
3277 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3278 NO_STR
3279 NEIGHBOR_STR
3280 NEIGHBOR_ADDR_STR2
3281 "Specify a local-as number\n"
3282 "AS number used as local AS\n"
3283 "Do not prepend local-as to updates from ebgp peers\n"
3284 "Do not prepend local-as to updates from ibgp peers\n")
3285 {
3286 int idx_peer = 2;
3287 struct peer *peer;
3288 int ret;
3289
3290 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3291 if (!peer)
3292 return CMD_WARNING_CONFIG_FAILED;
3293
3294 ret = peer_local_as_unset(peer);
3295 return bgp_vty_return(vty, ret);
3296 }
3297
3298
3299 DEFUN (neighbor_solo,
3300 neighbor_solo_cmd,
3301 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3302 NEIGHBOR_STR
3303 NEIGHBOR_ADDR_STR2
3304 "Solo peer - part of its own update group\n")
3305 {
3306 int idx_peer = 1;
3307 struct peer *peer;
3308 int ret;
3309
3310 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3311 if (!peer)
3312 return CMD_WARNING_CONFIG_FAILED;
3313
3314 ret = update_group_adjust_soloness(peer, 1);
3315 return bgp_vty_return(vty, ret);
3316 }
3317
3318 DEFUN (no_neighbor_solo,
3319 no_neighbor_solo_cmd,
3320 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3321 NO_STR
3322 NEIGHBOR_STR
3323 NEIGHBOR_ADDR_STR2
3324 "Solo peer - part of its own update group\n")
3325 {
3326 int idx_peer = 2;
3327 struct peer *peer;
3328 int ret;
3329
3330 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3331 if (!peer)
3332 return CMD_WARNING_CONFIG_FAILED;
3333
3334 ret = update_group_adjust_soloness(peer, 0);
3335 return bgp_vty_return(vty, ret);
3336 }
3337
3338 DEFUN (neighbor_password,
3339 neighbor_password_cmd,
3340 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3341 NEIGHBOR_STR
3342 NEIGHBOR_ADDR_STR2
3343 "Set a password\n"
3344 "The password\n")
3345 {
3346 int idx_peer = 1;
3347 int idx_line = 3;
3348 struct peer *peer;
3349 int ret;
3350
3351 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3352 if (!peer)
3353 return CMD_WARNING_CONFIG_FAILED;
3354
3355 ret = peer_password_set(peer, argv[idx_line]->arg);
3356 return bgp_vty_return(vty, ret);
3357 }
3358
3359 DEFUN (no_neighbor_password,
3360 no_neighbor_password_cmd,
3361 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3362 NO_STR
3363 NEIGHBOR_STR
3364 NEIGHBOR_ADDR_STR2
3365 "Set a password\n"
3366 "The password\n")
3367 {
3368 int idx_peer = 2;
3369 struct peer *peer;
3370 int ret;
3371
3372 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3373 if (!peer)
3374 return CMD_WARNING_CONFIG_FAILED;
3375
3376 ret = peer_password_unset(peer);
3377 return bgp_vty_return(vty, ret);
3378 }
3379
3380 DEFUN (neighbor_activate,
3381 neighbor_activate_cmd,
3382 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3383 NEIGHBOR_STR
3384 NEIGHBOR_ADDR_STR2
3385 "Enable the Address Family for this Neighbor\n")
3386 {
3387 int idx_peer = 1;
3388 int ret;
3389 struct peer *peer;
3390
3391 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3392 if (!peer)
3393 return CMD_WARNING_CONFIG_FAILED;
3394
3395 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3396 return bgp_vty_return(vty, ret);
3397 }
3398
3399 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3400 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3401 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3402 "Enable the Address Family for this Neighbor\n")
3403
3404 DEFUN (no_neighbor_activate,
3405 no_neighbor_activate_cmd,
3406 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3407 NO_STR
3408 NEIGHBOR_STR
3409 NEIGHBOR_ADDR_STR2
3410 "Enable the Address Family for this Neighbor\n")
3411 {
3412 int idx_peer = 2;
3413 int ret;
3414 struct peer *peer;
3415
3416 /* Lookup peer. */
3417 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3418 if (!peer)
3419 return CMD_WARNING_CONFIG_FAILED;
3420
3421 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3422 return bgp_vty_return(vty, ret);
3423 }
3424
3425 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3426 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3427 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3428 "Enable the Address Family for this Neighbor\n")
3429
3430 DEFUN (neighbor_set_peer_group,
3431 neighbor_set_peer_group_cmd,
3432 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3433 NEIGHBOR_STR
3434 NEIGHBOR_ADDR_STR2
3435 "Member of the peer-group\n"
3436 "Peer-group name\n")
3437 {
3438 VTY_DECLVAR_CONTEXT(bgp, bgp);
3439 int idx_peer = 1;
3440 int idx_word = 3;
3441 int ret;
3442 as_t as;
3443 union sockunion su;
3444 struct peer *peer;
3445 struct peer_group *group;
3446
3447 ret = str2sockunion(argv[idx_peer]->arg, &su);
3448 if (ret < 0) {
3449 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3450 if (!peer) {
3451 vty_out(vty, "%% Malformed address or name: %s\n",
3452 argv[idx_peer]->arg);
3453 return CMD_WARNING_CONFIG_FAILED;
3454 }
3455 } else {
3456 if (peer_address_self_check(bgp, &su)) {
3457 vty_out(vty,
3458 "%% Can not configure the local system as neighbor\n");
3459 return CMD_WARNING_CONFIG_FAILED;
3460 }
3461
3462 /* Disallow for dynamic neighbor. */
3463 peer = peer_lookup(bgp, &su);
3464 if (peer && peer_dynamic_neighbor(peer)) {
3465 vty_out(vty,
3466 "%% Operation not allowed on a dynamic neighbor\n");
3467 return CMD_WARNING_CONFIG_FAILED;
3468 }
3469 }
3470
3471 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3472 if (!group) {
3473 vty_out(vty, "%% Configure the peer-group first\n");
3474 return CMD_WARNING_CONFIG_FAILED;
3475 }
3476
3477 ret = peer_group_bind(bgp, &su, peer, group, &as);
3478
3479 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3480 vty_out(vty,
3481 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3482 as);
3483 return CMD_WARNING_CONFIG_FAILED;
3484 }
3485
3486 return bgp_vty_return(vty, ret);
3487 }
3488
3489 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3490 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3491 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3492 "Member of the peer-group\n"
3493 "Peer-group name\n")
3494
3495 DEFUN (no_neighbor_set_peer_group,
3496 no_neighbor_set_peer_group_cmd,
3497 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3498 NO_STR
3499 NEIGHBOR_STR
3500 NEIGHBOR_ADDR_STR2
3501 "Member of the peer-group\n"
3502 "Peer-group name\n")
3503 {
3504 VTY_DECLVAR_CONTEXT(bgp, bgp);
3505 int idx_peer = 2;
3506 int idx_word = 4;
3507 int ret;
3508 struct peer *peer;
3509 struct peer_group *group;
3510
3511 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3512 if (!peer)
3513 return CMD_WARNING_CONFIG_FAILED;
3514
3515 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3516 if (!group) {
3517 vty_out(vty, "%% Configure the peer-group first\n");
3518 return CMD_WARNING_CONFIG_FAILED;
3519 }
3520
3521 ret = peer_delete(peer);
3522
3523 return bgp_vty_return(vty, ret);
3524 }
3525
3526 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3527 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group PGNAME",
3528 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3529 "Member of the peer-group\n"
3530 "Peer-group name\n")
3531
3532 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3533 uint32_t flag, int set)
3534 {
3535 int ret;
3536 struct peer *peer;
3537
3538 peer = peer_and_group_lookup_vty(vty, ip_str);
3539 if (!peer)
3540 return CMD_WARNING_CONFIG_FAILED;
3541
3542 /*
3543 * If 'neighbor <interface>', then this is for directly connected peers,
3544 * we should not accept disable-connected-check.
3545 */
3546 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3547 vty_out(vty,
3548 "%s is directly connected peer, cannot accept disable-"
3549 "connected-check\n",
3550 ip_str);
3551 return CMD_WARNING_CONFIG_FAILED;
3552 }
3553
3554 if (!set && flag == PEER_FLAG_SHUTDOWN)
3555 peer_tx_shutdown_message_unset(peer);
3556
3557 if (set)
3558 ret = peer_flag_set(peer, flag);
3559 else
3560 ret = peer_flag_unset(peer, flag);
3561
3562 return bgp_vty_return(vty, ret);
3563 }
3564
3565 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3566 {
3567 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3568 }
3569
3570 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3571 uint32_t flag)
3572 {
3573 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3574 }
3575
3576 /* neighbor passive. */
3577 DEFUN (neighbor_passive,
3578 neighbor_passive_cmd,
3579 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3580 NEIGHBOR_STR
3581 NEIGHBOR_ADDR_STR2
3582 "Don't send open messages to this neighbor\n")
3583 {
3584 int idx_peer = 1;
3585 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3586 }
3587
3588 DEFUN (no_neighbor_passive,
3589 no_neighbor_passive_cmd,
3590 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3591 NO_STR
3592 NEIGHBOR_STR
3593 NEIGHBOR_ADDR_STR2
3594 "Don't send open messages to this neighbor\n")
3595 {
3596 int idx_peer = 2;
3597 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3598 }
3599
3600 /* neighbor shutdown. */
3601 DEFUN (neighbor_shutdown_msg,
3602 neighbor_shutdown_msg_cmd,
3603 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3604 NEIGHBOR_STR
3605 NEIGHBOR_ADDR_STR2
3606 "Administratively shut down this neighbor\n"
3607 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3608 "Shutdown message\n")
3609 {
3610 int idx_peer = 1;
3611
3612 if (argc >= 5) {
3613 struct peer *peer =
3614 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3615 char *message;
3616
3617 if (!peer)
3618 return CMD_WARNING_CONFIG_FAILED;
3619 message = argv_concat(argv, argc, 4);
3620 peer_tx_shutdown_message_set(peer, message);
3621 XFREE(MTYPE_TMP, message);
3622 }
3623
3624 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3625 }
3626
3627 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3628 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3629 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3630 "Administratively shut down this neighbor\n")
3631
3632 DEFUN (no_neighbor_shutdown_msg,
3633 no_neighbor_shutdown_msg_cmd,
3634 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3635 NO_STR
3636 NEIGHBOR_STR
3637 NEIGHBOR_ADDR_STR2
3638 "Administratively shut down this neighbor\n"
3639 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3640 "Shutdown message\n")
3641 {
3642 int idx_peer = 2;
3643
3644 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3645 PEER_FLAG_SHUTDOWN);
3646 }
3647
3648 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3649 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3650 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3651 "Administratively shut down this neighbor\n")
3652
3653 /* neighbor capability dynamic. */
3654 DEFUN (neighbor_capability_dynamic,
3655 neighbor_capability_dynamic_cmd,
3656 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3657 NEIGHBOR_STR
3658 NEIGHBOR_ADDR_STR2
3659 "Advertise capability to the peer\n"
3660 "Advertise dynamic capability to this neighbor\n")
3661 {
3662 int idx_peer = 1;
3663 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3664 PEER_FLAG_DYNAMIC_CAPABILITY);
3665 }
3666
3667 DEFUN (no_neighbor_capability_dynamic,
3668 no_neighbor_capability_dynamic_cmd,
3669 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3670 NO_STR
3671 NEIGHBOR_STR
3672 NEIGHBOR_ADDR_STR2
3673 "Advertise capability to the peer\n"
3674 "Advertise dynamic capability to this neighbor\n")
3675 {
3676 int idx_peer = 2;
3677 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3678 PEER_FLAG_DYNAMIC_CAPABILITY);
3679 }
3680
3681 /* neighbor dont-capability-negotiate */
3682 DEFUN (neighbor_dont_capability_negotiate,
3683 neighbor_dont_capability_negotiate_cmd,
3684 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3685 NEIGHBOR_STR
3686 NEIGHBOR_ADDR_STR2
3687 "Do not perform capability negotiation\n")
3688 {
3689 int idx_peer = 1;
3690 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3691 PEER_FLAG_DONT_CAPABILITY);
3692 }
3693
3694 DEFUN (no_neighbor_dont_capability_negotiate,
3695 no_neighbor_dont_capability_negotiate_cmd,
3696 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3697 NO_STR
3698 NEIGHBOR_STR
3699 NEIGHBOR_ADDR_STR2
3700 "Do not perform capability negotiation\n")
3701 {
3702 int idx_peer = 2;
3703 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3704 PEER_FLAG_DONT_CAPABILITY);
3705 }
3706
3707 /* neighbor capability extended next hop encoding */
3708 DEFUN (neighbor_capability_enhe,
3709 neighbor_capability_enhe_cmd,
3710 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3711 NEIGHBOR_STR
3712 NEIGHBOR_ADDR_STR2
3713 "Advertise capability to the peer\n"
3714 "Advertise extended next-hop capability to the peer\n")
3715 {
3716 int idx_peer = 1;
3717 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3718 PEER_FLAG_CAPABILITY_ENHE);
3719 }
3720
3721 DEFUN (no_neighbor_capability_enhe,
3722 no_neighbor_capability_enhe_cmd,
3723 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3724 NO_STR
3725 NEIGHBOR_STR
3726 NEIGHBOR_ADDR_STR2
3727 "Advertise capability to the peer\n"
3728 "Advertise extended next-hop capability to the peer\n")
3729 {
3730 int idx_peer = 2;
3731 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3732 PEER_FLAG_CAPABILITY_ENHE);
3733 }
3734
3735 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3736 afi_t afi, safi_t safi, uint32_t flag,
3737 int set)
3738 {
3739 int ret;
3740 struct peer *peer;
3741
3742 peer = peer_and_group_lookup_vty(vty, peer_str);
3743 if (!peer)
3744 return CMD_WARNING_CONFIG_FAILED;
3745
3746 if (set)
3747 ret = peer_af_flag_set(peer, afi, safi, flag);
3748 else
3749 ret = peer_af_flag_unset(peer, afi, safi, flag);
3750
3751 return bgp_vty_return(vty, ret);
3752 }
3753
3754 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3755 afi_t afi, safi_t safi, uint32_t flag)
3756 {
3757 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3758 }
3759
3760 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3761 afi_t afi, safi_t safi, uint32_t flag)
3762 {
3763 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3764 }
3765
3766 /* neighbor capability orf prefix-list. */
3767 DEFUN (neighbor_capability_orf_prefix,
3768 neighbor_capability_orf_prefix_cmd,
3769 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3770 NEIGHBOR_STR
3771 NEIGHBOR_ADDR_STR2
3772 "Advertise capability to the peer\n"
3773 "Advertise ORF capability to the peer\n"
3774 "Advertise prefixlist ORF capability to this neighbor\n"
3775 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3776 "Capability to RECEIVE the ORF from this neighbor\n"
3777 "Capability to SEND the ORF to this neighbor\n")
3778 {
3779 int idx_peer = 1;
3780 int idx_send_recv = 5;
3781 uint16_t flag = 0;
3782
3783 if (strmatch(argv[idx_send_recv]->text, "send"))
3784 flag = PEER_FLAG_ORF_PREFIX_SM;
3785 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3786 flag = PEER_FLAG_ORF_PREFIX_RM;
3787 else if (strmatch(argv[idx_send_recv]->text, "both"))
3788 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3789 else {
3790 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3791 return CMD_WARNING_CONFIG_FAILED;
3792 }
3793
3794 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3795 bgp_node_safi(vty), flag);
3796 }
3797
3798 ALIAS_HIDDEN(
3799 neighbor_capability_orf_prefix,
3800 neighbor_capability_orf_prefix_hidden_cmd,
3801 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3803 "Advertise capability to the peer\n"
3804 "Advertise ORF capability to the peer\n"
3805 "Advertise prefixlist ORF capability to this neighbor\n"
3806 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3807 "Capability to RECEIVE the ORF from this neighbor\n"
3808 "Capability to SEND the ORF to this neighbor\n")
3809
3810 DEFUN (no_neighbor_capability_orf_prefix,
3811 no_neighbor_capability_orf_prefix_cmd,
3812 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3813 NO_STR
3814 NEIGHBOR_STR
3815 NEIGHBOR_ADDR_STR2
3816 "Advertise capability to the peer\n"
3817 "Advertise ORF capability to the peer\n"
3818 "Advertise prefixlist ORF capability to this neighbor\n"
3819 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3820 "Capability to RECEIVE the ORF from this neighbor\n"
3821 "Capability to SEND the ORF to this neighbor\n")
3822 {
3823 int idx_peer = 2;
3824 int idx_send_recv = 6;
3825 uint16_t flag = 0;
3826
3827 if (strmatch(argv[idx_send_recv]->text, "send"))
3828 flag = PEER_FLAG_ORF_PREFIX_SM;
3829 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3830 flag = PEER_FLAG_ORF_PREFIX_RM;
3831 else if (strmatch(argv[idx_send_recv]->text, "both"))
3832 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3833 else {
3834 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3835 return CMD_WARNING_CONFIG_FAILED;
3836 }
3837
3838 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3839 bgp_node_afi(vty), bgp_node_safi(vty),
3840 flag);
3841 }
3842
3843 ALIAS_HIDDEN(
3844 no_neighbor_capability_orf_prefix,
3845 no_neighbor_capability_orf_prefix_hidden_cmd,
3846 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3847 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3848 "Advertise capability to the peer\n"
3849 "Advertise ORF capability to the peer\n"
3850 "Advertise prefixlist ORF capability to this neighbor\n"
3851 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3852 "Capability to RECEIVE the ORF from this neighbor\n"
3853 "Capability to SEND the ORF to this neighbor\n")
3854
3855 /* neighbor next-hop-self. */
3856 DEFUN (neighbor_nexthop_self,
3857 neighbor_nexthop_self_cmd,
3858 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3859 NEIGHBOR_STR
3860 NEIGHBOR_ADDR_STR2
3861 "Disable the next hop calculation for this neighbor\n")
3862 {
3863 int idx_peer = 1;
3864 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3865 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3866 }
3867
3868 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3869 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3870 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3871 "Disable the next hop calculation for this neighbor\n")
3872
3873 /* neighbor next-hop-self. */
3874 DEFUN (neighbor_nexthop_self_force,
3875 neighbor_nexthop_self_force_cmd,
3876 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3877 NEIGHBOR_STR
3878 NEIGHBOR_ADDR_STR2
3879 "Disable the next hop calculation for this neighbor\n"
3880 "Set the next hop to self for reflected routes\n")
3881 {
3882 int idx_peer = 1;
3883 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3884 bgp_node_safi(vty),
3885 PEER_FLAG_FORCE_NEXTHOP_SELF);
3886 }
3887
3888 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3889 neighbor_nexthop_self_force_hidden_cmd,
3890 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3891 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3892 "Disable the next hop calculation for this neighbor\n"
3893 "Set the next hop to self for reflected routes\n")
3894
3895 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3896 neighbor_nexthop_self_all_hidden_cmd,
3897 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3898 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3899 "Disable the next hop calculation for this neighbor\n"
3900 "Set the next hop to self for reflected routes\n")
3901
3902 DEFUN (no_neighbor_nexthop_self,
3903 no_neighbor_nexthop_self_cmd,
3904 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3905 NO_STR
3906 NEIGHBOR_STR
3907 NEIGHBOR_ADDR_STR2
3908 "Disable the next hop calculation for this neighbor\n")
3909 {
3910 int idx_peer = 2;
3911 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3912 bgp_node_afi(vty), bgp_node_safi(vty),
3913 PEER_FLAG_NEXTHOP_SELF);
3914 }
3915
3916 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3917 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3918 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3919 "Disable the next hop calculation for this neighbor\n")
3920
3921 DEFUN (no_neighbor_nexthop_self_force,
3922 no_neighbor_nexthop_self_force_cmd,
3923 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3924 NO_STR
3925 NEIGHBOR_STR
3926 NEIGHBOR_ADDR_STR2
3927 "Disable the next hop calculation for this neighbor\n"
3928 "Set the next hop to self for reflected routes\n")
3929 {
3930 int idx_peer = 2;
3931 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3932 bgp_node_afi(vty), bgp_node_safi(vty),
3933 PEER_FLAG_FORCE_NEXTHOP_SELF);
3934 }
3935
3936 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3937 no_neighbor_nexthop_self_force_hidden_cmd,
3938 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3939 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3940 "Disable the next hop calculation for this neighbor\n"
3941 "Set the next hop to self for reflected routes\n")
3942
3943 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3944 no_neighbor_nexthop_self_all_hidden_cmd,
3945 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3946 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3947 "Disable the next hop calculation for this neighbor\n"
3948 "Set the next hop to self for reflected routes\n")
3949
3950 /* neighbor as-override */
3951 DEFUN (neighbor_as_override,
3952 neighbor_as_override_cmd,
3953 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3954 NEIGHBOR_STR
3955 NEIGHBOR_ADDR_STR2
3956 "Override ASNs in outbound updates if aspath equals remote-as\n")
3957 {
3958 int idx_peer = 1;
3959 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3960 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3961 }
3962
3963 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3964 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3966 "Override ASNs in outbound updates if aspath equals remote-as\n")
3967
3968 DEFUN (no_neighbor_as_override,
3969 no_neighbor_as_override_cmd,
3970 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3971 NO_STR
3972 NEIGHBOR_STR
3973 NEIGHBOR_ADDR_STR2
3974 "Override ASNs in outbound updates if aspath equals remote-as\n")
3975 {
3976 int idx_peer = 2;
3977 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3978 bgp_node_afi(vty), bgp_node_safi(vty),
3979 PEER_FLAG_AS_OVERRIDE);
3980 }
3981
3982 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3983 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3984 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3985 "Override ASNs in outbound updates if aspath equals remote-as\n")
3986
3987 /* neighbor remove-private-AS. */
3988 DEFUN (neighbor_remove_private_as,
3989 neighbor_remove_private_as_cmd,
3990 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3991 NEIGHBOR_STR
3992 NEIGHBOR_ADDR_STR2
3993 "Remove private ASNs in outbound updates\n")
3994 {
3995 int idx_peer = 1;
3996 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3997 bgp_node_safi(vty),
3998 PEER_FLAG_REMOVE_PRIVATE_AS);
3999 }
4000
4001 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4002 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4003 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4004 "Remove private ASNs in outbound updates\n")
4005
4006 DEFUN (neighbor_remove_private_as_all,
4007 neighbor_remove_private_as_all_cmd,
4008 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4009 NEIGHBOR_STR
4010 NEIGHBOR_ADDR_STR2
4011 "Remove private ASNs in outbound updates\n"
4012 "Apply to all AS numbers\n")
4013 {
4014 int idx_peer = 1;
4015 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4016 bgp_node_safi(vty),
4017 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4018 }
4019
4020 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4021 neighbor_remove_private_as_all_hidden_cmd,
4022 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4023 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4024 "Remove private ASNs in outbound updates\n"
4025 "Apply to all AS numbers")
4026
4027 DEFUN (neighbor_remove_private_as_replace_as,
4028 neighbor_remove_private_as_replace_as_cmd,
4029 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4030 NEIGHBOR_STR
4031 NEIGHBOR_ADDR_STR2
4032 "Remove private ASNs in outbound updates\n"
4033 "Replace private ASNs with our ASN in outbound updates\n")
4034 {
4035 int idx_peer = 1;
4036 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4037 bgp_node_safi(vty),
4038 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4039 }
4040
4041 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4042 neighbor_remove_private_as_replace_as_hidden_cmd,
4043 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4044 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4045 "Remove private ASNs in outbound updates\n"
4046 "Replace private ASNs with our ASN in outbound updates\n")
4047
4048 DEFUN (neighbor_remove_private_as_all_replace_as,
4049 neighbor_remove_private_as_all_replace_as_cmd,
4050 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4051 NEIGHBOR_STR
4052 NEIGHBOR_ADDR_STR2
4053 "Remove private ASNs in outbound updates\n"
4054 "Apply to all AS numbers\n"
4055 "Replace private ASNs with our ASN in outbound updates\n")
4056 {
4057 int idx_peer = 1;
4058 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4059 bgp_node_safi(vty),
4060 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4061 }
4062
4063 ALIAS_HIDDEN(
4064 neighbor_remove_private_as_all_replace_as,
4065 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4066 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4067 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4068 "Remove private ASNs in outbound updates\n"
4069 "Apply to all AS numbers\n"
4070 "Replace private ASNs with our ASN in outbound updates\n")
4071
4072 DEFUN (no_neighbor_remove_private_as,
4073 no_neighbor_remove_private_as_cmd,
4074 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4075 NO_STR
4076 NEIGHBOR_STR
4077 NEIGHBOR_ADDR_STR2
4078 "Remove private ASNs in outbound updates\n")
4079 {
4080 int idx_peer = 2;
4081 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4082 bgp_node_afi(vty), bgp_node_safi(vty),
4083 PEER_FLAG_REMOVE_PRIVATE_AS);
4084 }
4085
4086 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4087 no_neighbor_remove_private_as_hidden_cmd,
4088 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4089 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4090 "Remove private ASNs in outbound updates\n")
4091
4092 DEFUN (no_neighbor_remove_private_as_all,
4093 no_neighbor_remove_private_as_all_cmd,
4094 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4095 NO_STR
4096 NEIGHBOR_STR
4097 NEIGHBOR_ADDR_STR2
4098 "Remove private ASNs in outbound updates\n"
4099 "Apply to all AS numbers\n")
4100 {
4101 int idx_peer = 2;
4102 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4103 bgp_node_afi(vty), bgp_node_safi(vty),
4104 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4105 }
4106
4107 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4108 no_neighbor_remove_private_as_all_hidden_cmd,
4109 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4110 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4111 "Remove private ASNs in outbound updates\n"
4112 "Apply to all AS numbers\n")
4113
4114 DEFUN (no_neighbor_remove_private_as_replace_as,
4115 no_neighbor_remove_private_as_replace_as_cmd,
4116 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4117 NO_STR
4118 NEIGHBOR_STR
4119 NEIGHBOR_ADDR_STR2
4120 "Remove private ASNs in outbound updates\n"
4121 "Replace private ASNs with our ASN in outbound updates\n")
4122 {
4123 int idx_peer = 2;
4124 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4125 bgp_node_afi(vty), bgp_node_safi(vty),
4126 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4127 }
4128
4129 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4130 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4131 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4132 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4133 "Remove private ASNs in outbound updates\n"
4134 "Replace private ASNs with our ASN in outbound updates\n")
4135
4136 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4137 no_neighbor_remove_private_as_all_replace_as_cmd,
4138 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4139 NO_STR
4140 NEIGHBOR_STR
4141 NEIGHBOR_ADDR_STR2
4142 "Remove private ASNs in outbound updates\n"
4143 "Apply to all AS numbers\n"
4144 "Replace private ASNs with our ASN in outbound updates\n")
4145 {
4146 int idx_peer = 2;
4147 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4148 bgp_node_afi(vty), bgp_node_safi(vty),
4149 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4150 }
4151
4152 ALIAS_HIDDEN(
4153 no_neighbor_remove_private_as_all_replace_as,
4154 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4155 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4156 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4157 "Remove private ASNs in outbound updates\n"
4158 "Apply to all AS numbers\n"
4159 "Replace private ASNs with our ASN in outbound updates\n")
4160
4161
4162 /* neighbor send-community. */
4163 DEFUN (neighbor_send_community,
4164 neighbor_send_community_cmd,
4165 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4166 NEIGHBOR_STR
4167 NEIGHBOR_ADDR_STR2
4168 "Send Community attribute to this neighbor\n")
4169 {
4170 int idx_peer = 1;
4171
4172 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4173 bgp_node_safi(vty),
4174 PEER_FLAG_SEND_COMMUNITY);
4175 }
4176
4177 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4178 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4179 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4180 "Send Community attribute to this neighbor\n")
4181
4182 DEFUN (no_neighbor_send_community,
4183 no_neighbor_send_community_cmd,
4184 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4185 NO_STR
4186 NEIGHBOR_STR
4187 NEIGHBOR_ADDR_STR2
4188 "Send Community attribute to this neighbor\n")
4189 {
4190 int idx_peer = 2;
4191
4192 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4193 bgp_node_afi(vty), bgp_node_safi(vty),
4194 PEER_FLAG_SEND_COMMUNITY);
4195 }
4196
4197 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4198 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4199 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4200 "Send Community attribute to this neighbor\n")
4201
4202 /* neighbor send-community extended. */
4203 DEFUN (neighbor_send_community_type,
4204 neighbor_send_community_type_cmd,
4205 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4206 NEIGHBOR_STR
4207 NEIGHBOR_ADDR_STR2
4208 "Send Community attribute to this neighbor\n"
4209 "Send Standard and Extended Community attributes\n"
4210 "Send Standard, Large and Extended Community attributes\n"
4211 "Send Extended Community attributes\n"
4212 "Send Standard Community attributes\n"
4213 "Send Large Community attributes\n")
4214 {
4215 int idx_peer = 1;
4216 uint32_t flag = 0;
4217 const char *type = argv[argc - 1]->text;
4218
4219 if (strmatch(type, "standard")) {
4220 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4221 } else if (strmatch(type, "extended")) {
4222 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4223 } else if (strmatch(type, "large")) {
4224 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4225 } else if (strmatch(type, "both")) {
4226 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4227 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4228 } else { /* if (strmatch(type, "all")) */
4229 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4230 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4231 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4232 }
4233
4234 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4235 bgp_node_safi(vty), flag);
4236 }
4237
4238 ALIAS_HIDDEN(
4239 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4240 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4241 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4242 "Send Community attribute to this neighbor\n"
4243 "Send Standard and Extended Community attributes\n"
4244 "Send Standard, Large and Extended Community attributes\n"
4245 "Send Extended Community attributes\n"
4246 "Send Standard Community attributes\n"
4247 "Send Large Community attributes\n")
4248
4249 DEFUN (no_neighbor_send_community_type,
4250 no_neighbor_send_community_type_cmd,
4251 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4252 NO_STR
4253 NEIGHBOR_STR
4254 NEIGHBOR_ADDR_STR2
4255 "Send Community attribute to this neighbor\n"
4256 "Send Standard and Extended Community attributes\n"
4257 "Send Standard, Large and Extended Community attributes\n"
4258 "Send Extended Community attributes\n"
4259 "Send Standard Community attributes\n"
4260 "Send Large Community attributes\n")
4261 {
4262 int idx_peer = 2;
4263 uint32_t flag = 0;
4264 const char *type = argv[argc - 1]->text;
4265
4266 if (strmatch(type, "standard")) {
4267 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4268 } else if (strmatch(type, "extended")) {
4269 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4270 } else if (strmatch(type, "large")) {
4271 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4272 } else if (strmatch(type, "both")) {
4273 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4274 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4275 } else { /* if (strmatch(type, "all")) */
4276 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4277 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4278 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4279 }
4280
4281 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4282 bgp_node_afi(vty), bgp_node_safi(vty),
4283 flag);
4284 }
4285
4286 ALIAS_HIDDEN(
4287 no_neighbor_send_community_type,
4288 no_neighbor_send_community_type_hidden_cmd,
4289 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4290 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4291 "Send Community attribute to this neighbor\n"
4292 "Send Standard and Extended Community attributes\n"
4293 "Send Standard, Large and Extended Community attributes\n"
4294 "Send Extended Community attributes\n"
4295 "Send Standard Community attributes\n"
4296 "Send Large Community attributes\n")
4297
4298 /* neighbor soft-reconfig. */
4299 DEFUN (neighbor_soft_reconfiguration,
4300 neighbor_soft_reconfiguration_cmd,
4301 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4302 NEIGHBOR_STR
4303 NEIGHBOR_ADDR_STR2
4304 "Per neighbor soft reconfiguration\n"
4305 "Allow inbound soft reconfiguration for this neighbor\n")
4306 {
4307 int idx_peer = 1;
4308 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4309 bgp_node_safi(vty),
4310 PEER_FLAG_SOFT_RECONFIG);
4311 }
4312
4313 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4314 neighbor_soft_reconfiguration_hidden_cmd,
4315 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4316 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4317 "Per neighbor soft reconfiguration\n"
4318 "Allow inbound soft reconfiguration for this neighbor\n")
4319
4320 DEFUN (no_neighbor_soft_reconfiguration,
4321 no_neighbor_soft_reconfiguration_cmd,
4322 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4323 NO_STR
4324 NEIGHBOR_STR
4325 NEIGHBOR_ADDR_STR2
4326 "Per neighbor soft reconfiguration\n"
4327 "Allow inbound soft reconfiguration for this neighbor\n")
4328 {
4329 int idx_peer = 2;
4330 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4331 bgp_node_afi(vty), bgp_node_safi(vty),
4332 PEER_FLAG_SOFT_RECONFIG);
4333 }
4334
4335 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4336 no_neighbor_soft_reconfiguration_hidden_cmd,
4337 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4338 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4339 "Per neighbor soft reconfiguration\n"
4340 "Allow inbound soft reconfiguration for this neighbor\n")
4341
4342 DEFUN (neighbor_route_reflector_client,
4343 neighbor_route_reflector_client_cmd,
4344 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4345 NEIGHBOR_STR
4346 NEIGHBOR_ADDR_STR2
4347 "Configure a neighbor as Route Reflector client\n")
4348 {
4349 int idx_peer = 1;
4350 struct peer *peer;
4351
4352
4353 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4354 if (!peer)
4355 return CMD_WARNING_CONFIG_FAILED;
4356
4357 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4358 bgp_node_safi(vty),
4359 PEER_FLAG_REFLECTOR_CLIENT);
4360 }
4361
4362 ALIAS_HIDDEN(neighbor_route_reflector_client,
4363 neighbor_route_reflector_client_hidden_cmd,
4364 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4365 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4366 "Configure a neighbor as Route Reflector client\n")
4367
4368 DEFUN (no_neighbor_route_reflector_client,
4369 no_neighbor_route_reflector_client_cmd,
4370 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4371 NO_STR
4372 NEIGHBOR_STR
4373 NEIGHBOR_ADDR_STR2
4374 "Configure a neighbor as Route Reflector client\n")
4375 {
4376 int idx_peer = 2;
4377 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4378 bgp_node_afi(vty), bgp_node_safi(vty),
4379 PEER_FLAG_REFLECTOR_CLIENT);
4380 }
4381
4382 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4383 no_neighbor_route_reflector_client_hidden_cmd,
4384 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4385 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4386 "Configure a neighbor as Route Reflector client\n")
4387
4388 /* neighbor route-server-client. */
4389 DEFUN (neighbor_route_server_client,
4390 neighbor_route_server_client_cmd,
4391 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4392 NEIGHBOR_STR
4393 NEIGHBOR_ADDR_STR2
4394 "Configure a neighbor as Route Server client\n")
4395 {
4396 int idx_peer = 1;
4397 struct peer *peer;
4398
4399 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4400 if (!peer)
4401 return CMD_WARNING_CONFIG_FAILED;
4402 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4403 bgp_node_safi(vty),
4404 PEER_FLAG_RSERVER_CLIENT);
4405 }
4406
4407 ALIAS_HIDDEN(neighbor_route_server_client,
4408 neighbor_route_server_client_hidden_cmd,
4409 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4410 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4411 "Configure a neighbor as Route Server client\n")
4412
4413 DEFUN (no_neighbor_route_server_client,
4414 no_neighbor_route_server_client_cmd,
4415 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4416 NO_STR
4417 NEIGHBOR_STR
4418 NEIGHBOR_ADDR_STR2
4419 "Configure a neighbor as Route Server client\n")
4420 {
4421 int idx_peer = 2;
4422 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4423 bgp_node_afi(vty), bgp_node_safi(vty),
4424 PEER_FLAG_RSERVER_CLIENT);
4425 }
4426
4427 ALIAS_HIDDEN(no_neighbor_route_server_client,
4428 no_neighbor_route_server_client_hidden_cmd,
4429 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4430 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4431 "Configure a neighbor as Route Server client\n")
4432
4433 DEFUN (neighbor_nexthop_local_unchanged,
4434 neighbor_nexthop_local_unchanged_cmd,
4435 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4436 NEIGHBOR_STR
4437 NEIGHBOR_ADDR_STR2
4438 "Configure treatment of outgoing link-local nexthop attribute\n"
4439 "Leave link-local nexthop unchanged for this peer\n")
4440 {
4441 int idx_peer = 1;
4442 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4443 bgp_node_safi(vty),
4444 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4445 }
4446
4447 DEFUN (no_neighbor_nexthop_local_unchanged,
4448 no_neighbor_nexthop_local_unchanged_cmd,
4449 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4450 NO_STR
4451 NEIGHBOR_STR
4452 NEIGHBOR_ADDR_STR2
4453 "Configure treatment of outgoing link-local-nexthop attribute\n"
4454 "Leave link-local nexthop unchanged for this peer\n")
4455 {
4456 int idx_peer = 2;
4457 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4458 bgp_node_afi(vty), bgp_node_safi(vty),
4459 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4460 }
4461
4462 DEFUN (neighbor_attr_unchanged,
4463 neighbor_attr_unchanged_cmd,
4464 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4465 NEIGHBOR_STR
4466 NEIGHBOR_ADDR_STR2
4467 "BGP attribute is propagated unchanged to this neighbor\n"
4468 "As-path attribute\n"
4469 "Nexthop attribute\n"
4470 "Med attribute\n")
4471 {
4472 int idx = 0;
4473 char *peer_str = argv[1]->arg;
4474 struct peer *peer;
4475 uint16_t flags = 0;
4476 afi_t afi = bgp_node_afi(vty);
4477 safi_t safi = bgp_node_safi(vty);
4478
4479 peer = peer_and_group_lookup_vty(vty, peer_str);
4480 if (!peer)
4481 return CMD_WARNING_CONFIG_FAILED;
4482
4483 if (argv_find(argv, argc, "as-path", &idx))
4484 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4485 idx = 0;
4486 if (argv_find(argv, argc, "next-hop", &idx))
4487 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4488 idx = 0;
4489 if (argv_find(argv, argc, "med", &idx))
4490 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4491
4492 /* no flags means all of them! */
4493 if (!flags) {
4494 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4495 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4496 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4497 } else {
4498 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4499 && peer_af_flag_check(peer, afi, safi,
4500 PEER_FLAG_AS_PATH_UNCHANGED)) {
4501 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4502 PEER_FLAG_AS_PATH_UNCHANGED);
4503 }
4504
4505 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4506 && peer_af_flag_check(peer, afi, safi,
4507 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4508 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4509 PEER_FLAG_NEXTHOP_UNCHANGED);
4510 }
4511
4512 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4513 && peer_af_flag_check(peer, afi, safi,
4514 PEER_FLAG_MED_UNCHANGED)) {
4515 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4516 PEER_FLAG_MED_UNCHANGED);
4517 }
4518 }
4519
4520 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4521 }
4522
4523 ALIAS_HIDDEN(
4524 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4525 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4526 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4527 "BGP attribute is propagated unchanged to this neighbor\n"
4528 "As-path attribute\n"
4529 "Nexthop attribute\n"
4530 "Med attribute\n")
4531
4532 DEFUN (no_neighbor_attr_unchanged,
4533 no_neighbor_attr_unchanged_cmd,
4534 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4535 NO_STR
4536 NEIGHBOR_STR
4537 NEIGHBOR_ADDR_STR2
4538 "BGP attribute is propagated unchanged to this neighbor\n"
4539 "As-path attribute\n"
4540 "Nexthop attribute\n"
4541 "Med attribute\n")
4542 {
4543 int idx = 0;
4544 char *peer = argv[2]->arg;
4545 uint16_t flags = 0;
4546
4547 if (argv_find(argv, argc, "as-path", &idx))
4548 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4549 idx = 0;
4550 if (argv_find(argv, argc, "next-hop", &idx))
4551 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4552 idx = 0;
4553 if (argv_find(argv, argc, "med", &idx))
4554 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4555
4556 if (!flags) // no flags means all of them!
4557 {
4558 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4559 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4560 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4561 }
4562
4563 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4564 bgp_node_safi(vty), flags);
4565 }
4566
4567 ALIAS_HIDDEN(
4568 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4569 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4570 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4571 "BGP attribute is propagated unchanged to this neighbor\n"
4572 "As-path attribute\n"
4573 "Nexthop attribute\n"
4574 "Med attribute\n")
4575
4576 /* EBGP multihop configuration. */
4577 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4578 const char *ttl_str)
4579 {
4580 struct peer *peer;
4581 unsigned int ttl;
4582
4583 peer = peer_and_group_lookup_vty(vty, ip_str);
4584 if (!peer)
4585 return CMD_WARNING_CONFIG_FAILED;
4586
4587 if (peer->conf_if)
4588 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4589
4590 if (!ttl_str)
4591 ttl = MAXTTL;
4592 else
4593 ttl = strtoul(ttl_str, NULL, 10);
4594
4595 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4596 }
4597
4598 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4599 {
4600 struct peer *peer;
4601
4602 peer = peer_and_group_lookup_vty(vty, ip_str);
4603 if (!peer)
4604 return CMD_WARNING_CONFIG_FAILED;
4605
4606 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4607 }
4608
4609 /* neighbor ebgp-multihop. */
4610 DEFUN (neighbor_ebgp_multihop,
4611 neighbor_ebgp_multihop_cmd,
4612 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4613 NEIGHBOR_STR
4614 NEIGHBOR_ADDR_STR2
4615 "Allow EBGP neighbors not on directly connected networks\n")
4616 {
4617 int idx_peer = 1;
4618 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4619 }
4620
4621 DEFUN (neighbor_ebgp_multihop_ttl,
4622 neighbor_ebgp_multihop_ttl_cmd,
4623 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4624 NEIGHBOR_STR
4625 NEIGHBOR_ADDR_STR2
4626 "Allow EBGP neighbors not on directly connected networks\n"
4627 "maximum hop count\n")
4628 {
4629 int idx_peer = 1;
4630 int idx_number = 3;
4631 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4632 argv[idx_number]->arg);
4633 }
4634
4635 DEFUN (no_neighbor_ebgp_multihop,
4636 no_neighbor_ebgp_multihop_cmd,
4637 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4638 NO_STR
4639 NEIGHBOR_STR
4640 NEIGHBOR_ADDR_STR2
4641 "Allow EBGP neighbors not on directly connected networks\n"
4642 "maximum hop count\n")
4643 {
4644 int idx_peer = 2;
4645 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4646 }
4647
4648
4649 /* disable-connected-check */
4650 DEFUN (neighbor_disable_connected_check,
4651 neighbor_disable_connected_check_cmd,
4652 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4653 NEIGHBOR_STR
4654 NEIGHBOR_ADDR_STR2
4655 "one-hop away EBGP peer using loopback address\n"
4656 "Enforce EBGP neighbors perform multihop\n")
4657 {
4658 int idx_peer = 1;
4659 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4660 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4661 }
4662
4663 DEFUN (no_neighbor_disable_connected_check,
4664 no_neighbor_disable_connected_check_cmd,
4665 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4666 NO_STR
4667 NEIGHBOR_STR
4668 NEIGHBOR_ADDR_STR2
4669 "one-hop away EBGP peer using loopback address\n"
4670 "Enforce EBGP neighbors perform multihop\n")
4671 {
4672 int idx_peer = 2;
4673 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4674 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4675 }
4676
4677
4678 /* enforce-first-as */
4679 DEFUN (neighbor_enforce_first_as,
4680 neighbor_enforce_first_as_cmd,
4681 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4682 NEIGHBOR_STR
4683 NEIGHBOR_ADDR_STR2
4684 "Enforce the first AS for EBGP routes\n")
4685 {
4686 int idx_peer = 1;
4687
4688 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4689 PEER_FLAG_ENFORCE_FIRST_AS);
4690 }
4691
4692 DEFUN (no_neighbor_enforce_first_as,
4693 no_neighbor_enforce_first_as_cmd,
4694 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4695 NO_STR
4696 NEIGHBOR_STR
4697 NEIGHBOR_ADDR_STR2
4698 "Enforce the first AS for EBGP routes\n")
4699 {
4700 int idx_peer = 2;
4701
4702 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4703 PEER_FLAG_ENFORCE_FIRST_AS);
4704 }
4705
4706
4707 DEFUN (neighbor_description,
4708 neighbor_description_cmd,
4709 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4710 NEIGHBOR_STR
4711 NEIGHBOR_ADDR_STR2
4712 "Neighbor specific description\n"
4713 "Up to 80 characters describing this neighbor\n")
4714 {
4715 int idx_peer = 1;
4716 int idx_line = 3;
4717 struct peer *peer;
4718 char *str;
4719
4720 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4721 if (!peer)
4722 return CMD_WARNING_CONFIG_FAILED;
4723
4724 str = argv_concat(argv, argc, idx_line);
4725
4726 peer_description_set(peer, str);
4727
4728 XFREE(MTYPE_TMP, str);
4729
4730 return CMD_SUCCESS;
4731 }
4732
4733 DEFUN (no_neighbor_description,
4734 no_neighbor_description_cmd,
4735 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4736 NO_STR
4737 NEIGHBOR_STR
4738 NEIGHBOR_ADDR_STR2
4739 "Neighbor specific description\n")
4740 {
4741 int idx_peer = 2;
4742 struct peer *peer;
4743
4744 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4745 if (!peer)
4746 return CMD_WARNING_CONFIG_FAILED;
4747
4748 peer_description_unset(peer);
4749
4750 return CMD_SUCCESS;
4751 }
4752
4753 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4754 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4755 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4756 "Neighbor specific description\n"
4757 "Up to 80 characters describing this neighbor\n")
4758
4759 /* Neighbor update-source. */
4760 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4761 const char *source_str)
4762 {
4763 struct peer *peer;
4764 struct prefix p;
4765 union sockunion su;
4766
4767 peer = peer_and_group_lookup_vty(vty, peer_str);
4768 if (!peer)
4769 return CMD_WARNING_CONFIG_FAILED;
4770
4771 if (peer->conf_if)
4772 return CMD_WARNING;
4773
4774 if (source_str) {
4775 if (str2sockunion(source_str, &su) == 0)
4776 peer_update_source_addr_set(peer, &su);
4777 else {
4778 if (str2prefix(source_str, &p)) {
4779 vty_out(vty,
4780 "%% Invalid update-source, remove prefix length \n");
4781 return CMD_WARNING_CONFIG_FAILED;
4782 } else
4783 peer_update_source_if_set(peer, source_str);
4784 }
4785 } else
4786 peer_update_source_unset(peer);
4787
4788 return CMD_SUCCESS;
4789 }
4790
4791 #define BGP_UPDATE_SOURCE_HELP_STR \
4792 "IPv4 address\n" \
4793 "IPv6 address\n" \
4794 "Interface name (requires zebra to be running)\n"
4795
4796 DEFUN (neighbor_update_source,
4797 neighbor_update_source_cmd,
4798 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4799 NEIGHBOR_STR
4800 NEIGHBOR_ADDR_STR2
4801 "Source of routing updates\n"
4802 BGP_UPDATE_SOURCE_HELP_STR)
4803 {
4804 int idx_peer = 1;
4805 int idx_peer_2 = 3;
4806 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4807 argv[idx_peer_2]->arg);
4808 }
4809
4810 DEFUN (no_neighbor_update_source,
4811 no_neighbor_update_source_cmd,
4812 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4813 NO_STR
4814 NEIGHBOR_STR
4815 NEIGHBOR_ADDR_STR2
4816 "Source of routing updates\n"
4817 BGP_UPDATE_SOURCE_HELP_STR)
4818 {
4819 int idx_peer = 2;
4820 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4821 }
4822
4823 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4824 afi_t afi, safi_t safi,
4825 const char *rmap, int set)
4826 {
4827 int ret;
4828 struct peer *peer;
4829 struct route_map *route_map = NULL;
4830
4831 peer = peer_and_group_lookup_vty(vty, peer_str);
4832 if (!peer)
4833 return CMD_WARNING_CONFIG_FAILED;
4834
4835 if (set) {
4836 if (rmap)
4837 route_map = route_map_lookup_warn_noexist(vty, rmap);
4838 ret = peer_default_originate_set(peer, afi, safi,
4839 rmap, route_map);
4840 } else
4841 ret = peer_default_originate_unset(peer, afi, safi);
4842
4843 return bgp_vty_return(vty, ret);
4844 }
4845
4846 /* neighbor default-originate. */
4847 DEFUN (neighbor_default_originate,
4848 neighbor_default_originate_cmd,
4849 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4850 NEIGHBOR_STR
4851 NEIGHBOR_ADDR_STR2
4852 "Originate default route to this neighbor\n")
4853 {
4854 int idx_peer = 1;
4855 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4856 bgp_node_afi(vty),
4857 bgp_node_safi(vty), NULL, 1);
4858 }
4859
4860 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4861 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4862 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4863 "Originate default route to this neighbor\n")
4864
4865 DEFUN (neighbor_default_originate_rmap,
4866 neighbor_default_originate_rmap_cmd,
4867 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4868 NEIGHBOR_STR
4869 NEIGHBOR_ADDR_STR2
4870 "Originate default route to this neighbor\n"
4871 "Route-map to specify criteria to originate default\n"
4872 "route-map name\n")
4873 {
4874 int idx_peer = 1;
4875 int idx_word = 4;
4876 return peer_default_originate_set_vty(
4877 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4878 argv[idx_word]->arg, 1);
4879 }
4880
4881 ALIAS_HIDDEN(
4882 neighbor_default_originate_rmap,
4883 neighbor_default_originate_rmap_hidden_cmd,
4884 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4885 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4886 "Originate default route to this neighbor\n"
4887 "Route-map to specify criteria to originate default\n"
4888 "route-map name\n")
4889
4890 DEFUN (no_neighbor_default_originate,
4891 no_neighbor_default_originate_cmd,
4892 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4893 NO_STR
4894 NEIGHBOR_STR
4895 NEIGHBOR_ADDR_STR2
4896 "Originate default route to this neighbor\n"
4897 "Route-map to specify criteria to originate default\n"
4898 "route-map name\n")
4899 {
4900 int idx_peer = 2;
4901 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4902 bgp_node_afi(vty),
4903 bgp_node_safi(vty), NULL, 0);
4904 }
4905
4906 ALIAS_HIDDEN(
4907 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4908 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4909 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4910 "Originate default route to this neighbor\n"
4911 "Route-map to specify criteria to originate default\n"
4912 "route-map name\n")
4913
4914
4915 /* Set neighbor's BGP port. */
4916 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4917 const char *port_str)
4918 {
4919 struct peer *peer;
4920 uint16_t port;
4921 struct servent *sp;
4922
4923 peer = peer_lookup_vty(vty, ip_str);
4924 if (!peer)
4925 return CMD_WARNING_CONFIG_FAILED;
4926
4927 if (!port_str) {
4928 sp = getservbyname("bgp", "tcp");
4929 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4930 } else {
4931 port = strtoul(port_str, NULL, 10);
4932 }
4933
4934 peer_port_set(peer, port);
4935
4936 return CMD_SUCCESS;
4937 }
4938
4939 /* Set specified peer's BGP port. */
4940 DEFUN (neighbor_port,
4941 neighbor_port_cmd,
4942 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4943 NEIGHBOR_STR
4944 NEIGHBOR_ADDR_STR
4945 "Neighbor's BGP port\n"
4946 "TCP port number\n")
4947 {
4948 int idx_ip = 1;
4949 int idx_number = 3;
4950 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4951 argv[idx_number]->arg);
4952 }
4953
4954 DEFUN (no_neighbor_port,
4955 no_neighbor_port_cmd,
4956 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4957 NO_STR
4958 NEIGHBOR_STR
4959 NEIGHBOR_ADDR_STR
4960 "Neighbor's BGP port\n"
4961 "TCP port number\n")
4962 {
4963 int idx_ip = 2;
4964 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4965 }
4966
4967
4968 /* neighbor weight. */
4969 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4970 safi_t safi, const char *weight_str)
4971 {
4972 int ret;
4973 struct peer *peer;
4974 unsigned long weight;
4975
4976 peer = peer_and_group_lookup_vty(vty, ip_str);
4977 if (!peer)
4978 return CMD_WARNING_CONFIG_FAILED;
4979
4980 weight = strtoul(weight_str, NULL, 10);
4981
4982 ret = peer_weight_set(peer, afi, safi, weight);
4983 return bgp_vty_return(vty, ret);
4984 }
4985
4986 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4987 safi_t safi)
4988 {
4989 int ret;
4990 struct peer *peer;
4991
4992 peer = peer_and_group_lookup_vty(vty, ip_str);
4993 if (!peer)
4994 return CMD_WARNING_CONFIG_FAILED;
4995
4996 ret = peer_weight_unset(peer, afi, safi);
4997 return bgp_vty_return(vty, ret);
4998 }
4999
5000 DEFUN (neighbor_weight,
5001 neighbor_weight_cmd,
5002 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5003 NEIGHBOR_STR
5004 NEIGHBOR_ADDR_STR2
5005 "Set default weight for routes from this neighbor\n"
5006 "default weight\n")
5007 {
5008 int idx_peer = 1;
5009 int idx_number = 3;
5010 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5011 bgp_node_safi(vty), argv[idx_number]->arg);
5012 }
5013
5014 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5015 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5017 "Set default weight for routes from this neighbor\n"
5018 "default weight\n")
5019
5020 DEFUN (no_neighbor_weight,
5021 no_neighbor_weight_cmd,
5022 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5023 NO_STR
5024 NEIGHBOR_STR
5025 NEIGHBOR_ADDR_STR2
5026 "Set default weight for routes from this neighbor\n"
5027 "default weight\n")
5028 {
5029 int idx_peer = 2;
5030 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5031 bgp_node_afi(vty), bgp_node_safi(vty));
5032 }
5033
5034 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5035 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5036 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5037 "Set default weight for routes from this neighbor\n"
5038 "default weight\n")
5039
5040
5041 /* Override capability negotiation. */
5042 DEFUN (neighbor_override_capability,
5043 neighbor_override_capability_cmd,
5044 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5045 NEIGHBOR_STR
5046 NEIGHBOR_ADDR_STR2
5047 "Override capability negotiation result\n")
5048 {
5049 int idx_peer = 1;
5050 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5051 PEER_FLAG_OVERRIDE_CAPABILITY);
5052 }
5053
5054 DEFUN (no_neighbor_override_capability,
5055 no_neighbor_override_capability_cmd,
5056 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5057 NO_STR
5058 NEIGHBOR_STR
5059 NEIGHBOR_ADDR_STR2
5060 "Override capability negotiation result\n")
5061 {
5062 int idx_peer = 2;
5063 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5064 PEER_FLAG_OVERRIDE_CAPABILITY);
5065 }
5066
5067 DEFUN (neighbor_strict_capability,
5068 neighbor_strict_capability_cmd,
5069 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5070 NEIGHBOR_STR
5071 NEIGHBOR_ADDR_STR2
5072 "Strict capability negotiation match\n")
5073 {
5074 int idx_peer = 1;
5075
5076 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5077 PEER_FLAG_STRICT_CAP_MATCH);
5078 }
5079
5080 DEFUN (no_neighbor_strict_capability,
5081 no_neighbor_strict_capability_cmd,
5082 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5083 NO_STR
5084 NEIGHBOR_STR
5085 NEIGHBOR_ADDR_STR2
5086 "Strict capability negotiation match\n")
5087 {
5088 int idx_peer = 2;
5089
5090 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5091 PEER_FLAG_STRICT_CAP_MATCH);
5092 }
5093
5094 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5095 const char *keep_str, const char *hold_str)
5096 {
5097 int ret;
5098 struct peer *peer;
5099 uint32_t keepalive;
5100 uint32_t holdtime;
5101
5102 peer = peer_and_group_lookup_vty(vty, ip_str);
5103 if (!peer)
5104 return CMD_WARNING_CONFIG_FAILED;
5105
5106 keepalive = strtoul(keep_str, NULL, 10);
5107 holdtime = strtoul(hold_str, NULL, 10);
5108
5109 ret = peer_timers_set(peer, keepalive, holdtime);
5110
5111 return bgp_vty_return(vty, ret);
5112 }
5113
5114 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5115 {
5116 int ret;
5117 struct peer *peer;
5118
5119 peer = peer_and_group_lookup_vty(vty, ip_str);
5120 if (!peer)
5121 return CMD_WARNING_CONFIG_FAILED;
5122
5123 ret = peer_timers_unset(peer);
5124
5125 return bgp_vty_return(vty, ret);
5126 }
5127
5128 DEFUN (neighbor_timers,
5129 neighbor_timers_cmd,
5130 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5131 NEIGHBOR_STR
5132 NEIGHBOR_ADDR_STR2
5133 "BGP per neighbor timers\n"
5134 "Keepalive interval\n"
5135 "Holdtime\n")
5136 {
5137 int idx_peer = 1;
5138 int idx_number = 3;
5139 int idx_number_2 = 4;
5140 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5141 argv[idx_number]->arg,
5142 argv[idx_number_2]->arg);
5143 }
5144
5145 DEFUN (no_neighbor_timers,
5146 no_neighbor_timers_cmd,
5147 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5148 NO_STR
5149 NEIGHBOR_STR
5150 NEIGHBOR_ADDR_STR2
5151 "BGP per neighbor timers\n"
5152 "Keepalive interval\n"
5153 "Holdtime\n")
5154 {
5155 int idx_peer = 2;
5156 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5157 }
5158
5159
5160 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5161 const char *time_str)
5162 {
5163 int ret;
5164 struct peer *peer;
5165 uint32_t connect;
5166
5167 peer = peer_and_group_lookup_vty(vty, ip_str);
5168 if (!peer)
5169 return CMD_WARNING_CONFIG_FAILED;
5170
5171 connect = strtoul(time_str, NULL, 10);
5172
5173 ret = peer_timers_connect_set(peer, connect);
5174
5175 return bgp_vty_return(vty, ret);
5176 }
5177
5178 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5179 {
5180 int ret;
5181 struct peer *peer;
5182
5183 peer = peer_and_group_lookup_vty(vty, ip_str);
5184 if (!peer)
5185 return CMD_WARNING_CONFIG_FAILED;
5186
5187 ret = peer_timers_connect_unset(peer);
5188
5189 return bgp_vty_return(vty, ret);
5190 }
5191
5192 DEFUN (neighbor_timers_connect,
5193 neighbor_timers_connect_cmd,
5194 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5195 NEIGHBOR_STR
5196 NEIGHBOR_ADDR_STR2
5197 "BGP per neighbor timers\n"
5198 "BGP connect timer\n"
5199 "Connect timer\n")
5200 {
5201 int idx_peer = 1;
5202 int idx_number = 4;
5203 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5204 argv[idx_number]->arg);
5205 }
5206
5207 DEFUN (no_neighbor_timers_connect,
5208 no_neighbor_timers_connect_cmd,
5209 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5210 NO_STR
5211 NEIGHBOR_STR
5212 NEIGHBOR_ADDR_STR2
5213 "BGP per neighbor timers\n"
5214 "BGP connect timer\n"
5215 "Connect timer\n")
5216 {
5217 int idx_peer = 2;
5218 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5219 }
5220
5221
5222 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5223 const char *time_str, int set)
5224 {
5225 int ret;
5226 struct peer *peer;
5227 uint32_t routeadv = 0;
5228
5229 peer = peer_and_group_lookup_vty(vty, ip_str);
5230 if (!peer)
5231 return CMD_WARNING_CONFIG_FAILED;
5232
5233 if (time_str)
5234 routeadv = strtoul(time_str, NULL, 10);
5235
5236 if (set)
5237 ret = peer_advertise_interval_set(peer, routeadv);
5238 else
5239 ret = peer_advertise_interval_unset(peer);
5240
5241 return bgp_vty_return(vty, ret);
5242 }
5243
5244 DEFUN (neighbor_advertise_interval,
5245 neighbor_advertise_interval_cmd,
5246 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5247 NEIGHBOR_STR
5248 NEIGHBOR_ADDR_STR2
5249 "Minimum interval between sending BGP routing updates\n"
5250 "time in seconds\n")
5251 {
5252 int idx_peer = 1;
5253 int idx_number = 3;
5254 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5255 argv[idx_number]->arg, 1);
5256 }
5257
5258 DEFUN (no_neighbor_advertise_interval,
5259 no_neighbor_advertise_interval_cmd,
5260 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5261 NO_STR
5262 NEIGHBOR_STR
5263 NEIGHBOR_ADDR_STR2
5264 "Minimum interval between sending BGP routing updates\n"
5265 "time in seconds\n")
5266 {
5267 int idx_peer = 2;
5268 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5269 }
5270
5271
5272 /* Time to wait before processing route-map updates */
5273 DEFUN (bgp_set_route_map_delay_timer,
5274 bgp_set_route_map_delay_timer_cmd,
5275 "bgp route-map delay-timer (0-600)",
5276 SET_STR
5277 "BGP route-map delay timer\n"
5278 "Time in secs to wait before processing route-map changes\n"
5279 "0 disables the timer, no route updates happen when route-maps change\n")
5280 {
5281 int idx_number = 3;
5282 uint32_t rmap_delay_timer;
5283
5284 if (argv[idx_number]->arg) {
5285 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5286 bm->rmap_update_timer = rmap_delay_timer;
5287
5288 /* if the dynamic update handling is being disabled, and a timer
5289 * is
5290 * running, stop the timer and act as if the timer has already
5291 * fired.
5292 */
5293 if (!rmap_delay_timer && bm->t_rmap_update) {
5294 BGP_TIMER_OFF(bm->t_rmap_update);
5295 thread_execute(bm->master, bgp_route_map_update_timer,
5296 NULL, 0);
5297 }
5298 return CMD_SUCCESS;
5299 } else {
5300 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5301 return CMD_WARNING_CONFIG_FAILED;
5302 }
5303 }
5304
5305 DEFUN (no_bgp_set_route_map_delay_timer,
5306 no_bgp_set_route_map_delay_timer_cmd,
5307 "no bgp route-map delay-timer [(0-600)]",
5308 NO_STR
5309 BGP_STR
5310 "Default BGP route-map delay timer\n"
5311 "Reset to default time to wait for processing route-map changes\n"
5312 "0 disables the timer, no route updates happen when route-maps change\n")
5313 {
5314
5315 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5316
5317 return CMD_SUCCESS;
5318 }
5319
5320
5321 /* neighbor interface */
5322 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5323 const char *str)
5324 {
5325 struct peer *peer;
5326
5327 peer = peer_lookup_vty(vty, ip_str);
5328 if (!peer || peer->conf_if) {
5329 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5330 return CMD_WARNING_CONFIG_FAILED;
5331 }
5332
5333 if (str)
5334 peer_interface_set(peer, str);
5335 else
5336 peer_interface_unset(peer);
5337
5338 return CMD_SUCCESS;
5339 }
5340
5341 DEFUN (neighbor_interface,
5342 neighbor_interface_cmd,
5343 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5344 NEIGHBOR_STR
5345 NEIGHBOR_ADDR_STR
5346 "Interface\n"
5347 "Interface name\n")
5348 {
5349 int idx_ip = 1;
5350 int idx_word = 3;
5351 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5352 }
5353
5354 DEFUN (no_neighbor_interface,
5355 no_neighbor_interface_cmd,
5356 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5357 NO_STR
5358 NEIGHBOR_STR
5359 NEIGHBOR_ADDR_STR2
5360 "Interface\n"
5361 "Interface name\n")
5362 {
5363 int idx_peer = 2;
5364 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5365 }
5366
5367 DEFUN (neighbor_distribute_list,
5368 neighbor_distribute_list_cmd,
5369 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5370 NEIGHBOR_STR
5371 NEIGHBOR_ADDR_STR2
5372 "Filter updates to/from this neighbor\n"
5373 "IP access-list number\n"
5374 "IP access-list number (expanded range)\n"
5375 "IP Access-list name\n"
5376 "Filter incoming updates\n"
5377 "Filter outgoing updates\n")
5378 {
5379 int idx_peer = 1;
5380 int idx_acl = 3;
5381 int direct, ret;
5382 struct peer *peer;
5383
5384 const char *pstr = argv[idx_peer]->arg;
5385 const char *acl = argv[idx_acl]->arg;
5386 const char *inout = argv[argc - 1]->text;
5387
5388 peer = peer_and_group_lookup_vty(vty, pstr);
5389 if (!peer)
5390 return CMD_WARNING_CONFIG_FAILED;
5391
5392 /* Check filter direction. */
5393 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5394 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5395 direct, acl);
5396
5397 return bgp_vty_return(vty, ret);
5398 }
5399
5400 ALIAS_HIDDEN(
5401 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5402 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5403 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5404 "Filter updates to/from this neighbor\n"
5405 "IP access-list number\n"
5406 "IP access-list number (expanded range)\n"
5407 "IP Access-list name\n"
5408 "Filter incoming updates\n"
5409 "Filter outgoing updates\n")
5410
5411 DEFUN (no_neighbor_distribute_list,
5412 no_neighbor_distribute_list_cmd,
5413 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5414 NO_STR
5415 NEIGHBOR_STR
5416 NEIGHBOR_ADDR_STR2
5417 "Filter updates to/from this neighbor\n"
5418 "IP access-list number\n"
5419 "IP access-list number (expanded range)\n"
5420 "IP Access-list name\n"
5421 "Filter incoming updates\n"
5422 "Filter outgoing updates\n")
5423 {
5424 int idx_peer = 2;
5425 int direct, ret;
5426 struct peer *peer;
5427
5428 const char *pstr = argv[idx_peer]->arg;
5429 const char *inout = argv[argc - 1]->text;
5430
5431 peer = peer_and_group_lookup_vty(vty, pstr);
5432 if (!peer)
5433 return CMD_WARNING_CONFIG_FAILED;
5434
5435 /* Check filter direction. */
5436 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5437 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5438 direct);
5439
5440 return bgp_vty_return(vty, ret);
5441 }
5442
5443 ALIAS_HIDDEN(
5444 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5445 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5446 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5447 "Filter updates to/from this neighbor\n"
5448 "IP access-list number\n"
5449 "IP access-list number (expanded range)\n"
5450 "IP Access-list name\n"
5451 "Filter incoming updates\n"
5452 "Filter outgoing updates\n")
5453
5454 /* Set prefix list to the peer. */
5455 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5456 afi_t afi, safi_t safi,
5457 const char *name_str,
5458 const char *direct_str)
5459 {
5460 int ret;
5461 int direct = FILTER_IN;
5462 struct peer *peer;
5463
5464 peer = peer_and_group_lookup_vty(vty, ip_str);
5465 if (!peer)
5466 return CMD_WARNING_CONFIG_FAILED;
5467
5468 /* Check filter direction. */
5469 if (strncmp(direct_str, "i", 1) == 0)
5470 direct = FILTER_IN;
5471 else if (strncmp(direct_str, "o", 1) == 0)
5472 direct = FILTER_OUT;
5473
5474 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5475
5476 return bgp_vty_return(vty, ret);
5477 }
5478
5479 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5480 afi_t afi, safi_t safi,
5481 const char *direct_str)
5482 {
5483 int ret;
5484 struct peer *peer;
5485 int direct = FILTER_IN;
5486
5487 peer = peer_and_group_lookup_vty(vty, ip_str);
5488 if (!peer)
5489 return CMD_WARNING_CONFIG_FAILED;
5490
5491 /* Check filter direction. */
5492 if (strncmp(direct_str, "i", 1) == 0)
5493 direct = FILTER_IN;
5494 else if (strncmp(direct_str, "o", 1) == 0)
5495 direct = FILTER_OUT;
5496
5497 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5498
5499 return bgp_vty_return(vty, ret);
5500 }
5501
5502 DEFUN (neighbor_prefix_list,
5503 neighbor_prefix_list_cmd,
5504 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5505 NEIGHBOR_STR
5506 NEIGHBOR_ADDR_STR2
5507 "Filter updates to/from this neighbor\n"
5508 "Name of a prefix list\n"
5509 "Filter incoming updates\n"
5510 "Filter outgoing updates\n")
5511 {
5512 int idx_peer = 1;
5513 int idx_word = 3;
5514 int idx_in_out = 4;
5515 return peer_prefix_list_set_vty(
5516 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5517 argv[idx_word]->arg, argv[idx_in_out]->arg);
5518 }
5519
5520 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5521 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5522 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5523 "Filter updates to/from this neighbor\n"
5524 "Name of a prefix list\n"
5525 "Filter incoming updates\n"
5526 "Filter outgoing updates\n")
5527
5528 DEFUN (no_neighbor_prefix_list,
5529 no_neighbor_prefix_list_cmd,
5530 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5531 NO_STR
5532 NEIGHBOR_STR
5533 NEIGHBOR_ADDR_STR2
5534 "Filter updates to/from this neighbor\n"
5535 "Name of a prefix list\n"
5536 "Filter incoming updates\n"
5537 "Filter outgoing updates\n")
5538 {
5539 int idx_peer = 2;
5540 int idx_in_out = 5;
5541 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5542 bgp_node_afi(vty), bgp_node_safi(vty),
5543 argv[idx_in_out]->arg);
5544 }
5545
5546 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5547 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5548 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5549 "Filter updates to/from this neighbor\n"
5550 "Name of a prefix list\n"
5551 "Filter incoming updates\n"
5552 "Filter outgoing updates\n")
5553
5554 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5555 safi_t safi, const char *name_str,
5556 const char *direct_str)
5557 {
5558 int ret;
5559 struct peer *peer;
5560 int direct = FILTER_IN;
5561
5562 peer = peer_and_group_lookup_vty(vty, ip_str);
5563 if (!peer)
5564 return CMD_WARNING_CONFIG_FAILED;
5565
5566 /* Check filter direction. */
5567 if (strncmp(direct_str, "i", 1) == 0)
5568 direct = FILTER_IN;
5569 else if (strncmp(direct_str, "o", 1) == 0)
5570 direct = FILTER_OUT;
5571
5572 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5573
5574 return bgp_vty_return(vty, ret);
5575 }
5576
5577 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5578 safi_t safi, const char *direct_str)
5579 {
5580 int ret;
5581 struct peer *peer;
5582 int direct = FILTER_IN;
5583
5584 peer = peer_and_group_lookup_vty(vty, ip_str);
5585 if (!peer)
5586 return CMD_WARNING_CONFIG_FAILED;
5587
5588 /* Check filter direction. */
5589 if (strncmp(direct_str, "i", 1) == 0)
5590 direct = FILTER_IN;
5591 else if (strncmp(direct_str, "o", 1) == 0)
5592 direct = FILTER_OUT;
5593
5594 ret = peer_aslist_unset(peer, afi, safi, direct);
5595
5596 return bgp_vty_return(vty, ret);
5597 }
5598
5599 DEFUN (neighbor_filter_list,
5600 neighbor_filter_list_cmd,
5601 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5602 NEIGHBOR_STR
5603 NEIGHBOR_ADDR_STR2
5604 "Establish BGP filters\n"
5605 "AS path access-list name\n"
5606 "Filter incoming routes\n"
5607 "Filter outgoing routes\n")
5608 {
5609 int idx_peer = 1;
5610 int idx_word = 3;
5611 int idx_in_out = 4;
5612 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5613 bgp_node_safi(vty), argv[idx_word]->arg,
5614 argv[idx_in_out]->arg);
5615 }
5616
5617 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5618 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5619 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5620 "Establish BGP filters\n"
5621 "AS path access-list name\n"
5622 "Filter incoming routes\n"
5623 "Filter outgoing routes\n")
5624
5625 DEFUN (no_neighbor_filter_list,
5626 no_neighbor_filter_list_cmd,
5627 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5628 NO_STR
5629 NEIGHBOR_STR
5630 NEIGHBOR_ADDR_STR2
5631 "Establish BGP filters\n"
5632 "AS path access-list name\n"
5633 "Filter incoming routes\n"
5634 "Filter outgoing routes\n")
5635 {
5636 int idx_peer = 2;
5637 int idx_in_out = 5;
5638 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5639 bgp_node_afi(vty), bgp_node_safi(vty),
5640 argv[idx_in_out]->arg);
5641 }
5642
5643 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5644 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5645 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5646 "Establish BGP filters\n"
5647 "AS path access-list name\n"
5648 "Filter incoming routes\n"
5649 "Filter outgoing routes\n")
5650
5651 /* Set route-map to the peer. */
5652 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5653 afi_t afi, safi_t safi, const char *name_str,
5654 const char *direct_str)
5655 {
5656 int ret;
5657 struct peer *peer;
5658 int direct = RMAP_IN;
5659 struct route_map *route_map;
5660
5661 peer = peer_and_group_lookup_vty(vty, ip_str);
5662 if (!peer)
5663 return CMD_WARNING_CONFIG_FAILED;
5664
5665 /* Check filter direction. */
5666 if (strncmp(direct_str, "in", 2) == 0)
5667 direct = RMAP_IN;
5668 else if (strncmp(direct_str, "o", 1) == 0)
5669 direct = RMAP_OUT;
5670
5671 route_map = route_map_lookup_warn_noexist(vty, name_str);
5672 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5673
5674 return bgp_vty_return(vty, ret);
5675 }
5676
5677 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5678 afi_t afi, safi_t safi,
5679 const char *direct_str)
5680 {
5681 int ret;
5682 struct peer *peer;
5683 int direct = RMAP_IN;
5684
5685 peer = peer_and_group_lookup_vty(vty, ip_str);
5686 if (!peer)
5687 return CMD_WARNING_CONFIG_FAILED;
5688
5689 /* Check filter direction. */
5690 if (strncmp(direct_str, "in", 2) == 0)
5691 direct = RMAP_IN;
5692 else if (strncmp(direct_str, "o", 1) == 0)
5693 direct = RMAP_OUT;
5694
5695 ret = peer_route_map_unset(peer, afi, safi, direct);
5696
5697 return bgp_vty_return(vty, ret);
5698 }
5699
5700 DEFUN (neighbor_route_map,
5701 neighbor_route_map_cmd,
5702 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5703 NEIGHBOR_STR
5704 NEIGHBOR_ADDR_STR2
5705 "Apply route map to neighbor\n"
5706 "Name of route map\n"
5707 "Apply map to incoming routes\n"
5708 "Apply map to outbound routes\n")
5709 {
5710 int idx_peer = 1;
5711 int idx_word = 3;
5712 int idx_in_out = 4;
5713 return peer_route_map_set_vty(
5714 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5715 argv[idx_word]->arg, argv[idx_in_out]->arg);
5716 }
5717
5718 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5719 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5720 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5721 "Apply route map to neighbor\n"
5722 "Name of route map\n"
5723 "Apply map to incoming routes\n"
5724 "Apply map to outbound routes\n")
5725
5726 DEFUN (no_neighbor_route_map,
5727 no_neighbor_route_map_cmd,
5728 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5729 NO_STR
5730 NEIGHBOR_STR
5731 NEIGHBOR_ADDR_STR2
5732 "Apply route map to neighbor\n"
5733 "Name of route map\n"
5734 "Apply map to incoming routes\n"
5735 "Apply map to outbound routes\n")
5736 {
5737 int idx_peer = 2;
5738 int idx_in_out = 5;
5739 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5740 bgp_node_afi(vty), bgp_node_safi(vty),
5741 argv[idx_in_out]->arg);
5742 }
5743
5744 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5745 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5746 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5747 "Apply route map to neighbor\n"
5748 "Name of route map\n"
5749 "Apply map to incoming routes\n"
5750 "Apply map to outbound routes\n")
5751
5752 /* Set unsuppress-map to the peer. */
5753 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5754 afi_t afi, safi_t safi,
5755 const char *name_str)
5756 {
5757 int ret;
5758 struct peer *peer;
5759 struct route_map *route_map;
5760
5761 peer = peer_and_group_lookup_vty(vty, ip_str);
5762 if (!peer)
5763 return CMD_WARNING_CONFIG_FAILED;
5764
5765 route_map = route_map_lookup_warn_noexist(vty, name_str);
5766 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5767
5768 return bgp_vty_return(vty, ret);
5769 }
5770
5771 /* Unset route-map from the peer. */
5772 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5773 afi_t afi, safi_t safi)
5774 {
5775 int ret;
5776 struct peer *peer;
5777
5778 peer = peer_and_group_lookup_vty(vty, ip_str);
5779 if (!peer)
5780 return CMD_WARNING_CONFIG_FAILED;
5781
5782 ret = peer_unsuppress_map_unset(peer, afi, safi);
5783
5784 return bgp_vty_return(vty, ret);
5785 }
5786
5787 DEFUN (neighbor_unsuppress_map,
5788 neighbor_unsuppress_map_cmd,
5789 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5790 NEIGHBOR_STR
5791 NEIGHBOR_ADDR_STR2
5792 "Route-map to selectively unsuppress suppressed routes\n"
5793 "Name of route map\n")
5794 {
5795 int idx_peer = 1;
5796 int idx_word = 3;
5797 return peer_unsuppress_map_set_vty(
5798 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5799 argv[idx_word]->arg);
5800 }
5801
5802 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5803 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5804 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5805 "Route-map to selectively unsuppress suppressed routes\n"
5806 "Name of route map\n")
5807
5808 DEFUN (no_neighbor_unsuppress_map,
5809 no_neighbor_unsuppress_map_cmd,
5810 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5811 NO_STR
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Route-map to selectively unsuppress suppressed routes\n"
5815 "Name of route map\n")
5816 {
5817 int idx_peer = 2;
5818 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5819 bgp_node_afi(vty),
5820 bgp_node_safi(vty));
5821 }
5822
5823 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5824 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5825 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5826 "Route-map to selectively unsuppress suppressed routes\n"
5827 "Name of route map\n")
5828
5829 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5830 afi_t afi, safi_t safi,
5831 const char *num_str,
5832 const char *threshold_str, int warning,
5833 const char *restart_str)
5834 {
5835 int ret;
5836 struct peer *peer;
5837 uint32_t max;
5838 uint8_t threshold;
5839 uint16_t restart;
5840
5841 peer = peer_and_group_lookup_vty(vty, ip_str);
5842 if (!peer)
5843 return CMD_WARNING_CONFIG_FAILED;
5844
5845 max = strtoul(num_str, NULL, 10);
5846 if (threshold_str)
5847 threshold = atoi(threshold_str);
5848 else
5849 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5850
5851 if (restart_str)
5852 restart = atoi(restart_str);
5853 else
5854 restart = 0;
5855
5856 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5857 restart);
5858
5859 return bgp_vty_return(vty, ret);
5860 }
5861
5862 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5863 afi_t afi, safi_t safi)
5864 {
5865 int ret;
5866 struct peer *peer;
5867
5868 peer = peer_and_group_lookup_vty(vty, ip_str);
5869 if (!peer)
5870 return CMD_WARNING_CONFIG_FAILED;
5871
5872 ret = peer_maximum_prefix_unset(peer, afi, safi);
5873
5874 return bgp_vty_return(vty, ret);
5875 }
5876
5877 /* Maximum number of prefix configuration. prefix count is different
5878 for each peer configuration. So this configuration can be set for
5879 each peer configuration. */
5880 DEFUN (neighbor_maximum_prefix,
5881 neighbor_maximum_prefix_cmd,
5882 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5883 NEIGHBOR_STR
5884 NEIGHBOR_ADDR_STR2
5885 "Maximum number of prefix accept from this peer\n"
5886 "maximum no. of prefix limit\n")
5887 {
5888 int idx_peer = 1;
5889 int idx_number = 3;
5890 return peer_maximum_prefix_set_vty(
5891 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5892 argv[idx_number]->arg, NULL, 0, NULL);
5893 }
5894
5895 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5896 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5897 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5898 "Maximum number of prefix accept from this peer\n"
5899 "maximum no. of prefix limit\n")
5900
5901 DEFUN (neighbor_maximum_prefix_threshold,
5902 neighbor_maximum_prefix_threshold_cmd,
5903 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5904 NEIGHBOR_STR
5905 NEIGHBOR_ADDR_STR2
5906 "Maximum number of prefix accept from this peer\n"
5907 "maximum no. of prefix limit\n"
5908 "Threshold value (%) at which to generate a warning msg\n")
5909 {
5910 int idx_peer = 1;
5911 int idx_number = 3;
5912 int idx_number_2 = 4;
5913 return peer_maximum_prefix_set_vty(
5914 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5915 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5916 }
5917
5918 ALIAS_HIDDEN(
5919 neighbor_maximum_prefix_threshold,
5920 neighbor_maximum_prefix_threshold_hidden_cmd,
5921 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5922 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5923 "Maximum number of prefix accept from this peer\n"
5924 "maximum no. of prefix limit\n"
5925 "Threshold value (%) at which to generate a warning msg\n")
5926
5927 DEFUN (neighbor_maximum_prefix_warning,
5928 neighbor_maximum_prefix_warning_cmd,
5929 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Maximum number of prefix accept from this peer\n"
5933 "maximum no. of prefix limit\n"
5934 "Only give warning message when limit is exceeded\n")
5935 {
5936 int idx_peer = 1;
5937 int idx_number = 3;
5938 return peer_maximum_prefix_set_vty(
5939 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5940 argv[idx_number]->arg, NULL, 1, NULL);
5941 }
5942
5943 ALIAS_HIDDEN(
5944 neighbor_maximum_prefix_warning,
5945 neighbor_maximum_prefix_warning_hidden_cmd,
5946 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Maximum number of prefix accept from this peer\n"
5949 "maximum no. of prefix limit\n"
5950 "Only give warning message when limit is exceeded\n")
5951
5952 DEFUN (neighbor_maximum_prefix_threshold_warning,
5953 neighbor_maximum_prefix_threshold_warning_cmd,
5954 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5955 NEIGHBOR_STR
5956 NEIGHBOR_ADDR_STR2
5957 "Maximum number of prefix accept from this peer\n"
5958 "maximum no. of prefix limit\n"
5959 "Threshold value (%) at which to generate a warning msg\n"
5960 "Only give warning message when limit is exceeded\n")
5961 {
5962 int idx_peer = 1;
5963 int idx_number = 3;
5964 int idx_number_2 = 4;
5965 return peer_maximum_prefix_set_vty(
5966 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5967 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5968 }
5969
5970 ALIAS_HIDDEN(
5971 neighbor_maximum_prefix_threshold_warning,
5972 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5973 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5975 "Maximum number of prefix accept from this peer\n"
5976 "maximum no. of prefix limit\n"
5977 "Threshold value (%) at which to generate a warning msg\n"
5978 "Only give warning message when limit is exceeded\n")
5979
5980 DEFUN (neighbor_maximum_prefix_restart,
5981 neighbor_maximum_prefix_restart_cmd,
5982 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5983 NEIGHBOR_STR
5984 NEIGHBOR_ADDR_STR2
5985 "Maximum number of prefix accept from this peer\n"
5986 "maximum no. of prefix limit\n"
5987 "Restart bgp connection after limit is exceeded\n"
5988 "Restart interval in minutes\n")
5989 {
5990 int idx_peer = 1;
5991 int idx_number = 3;
5992 int idx_number_2 = 5;
5993 return peer_maximum_prefix_set_vty(
5994 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5995 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5996 }
5997
5998 ALIAS_HIDDEN(
5999 neighbor_maximum_prefix_restart,
6000 neighbor_maximum_prefix_restart_hidden_cmd,
6001 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6002 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6003 "Maximum number of prefix accept from this peer\n"
6004 "maximum no. of prefix limit\n"
6005 "Restart bgp connection after limit is exceeded\n"
6006 "Restart interval in minutes\n")
6007
6008 DEFUN (neighbor_maximum_prefix_threshold_restart,
6009 neighbor_maximum_prefix_threshold_restart_cmd,
6010 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6011 NEIGHBOR_STR
6012 NEIGHBOR_ADDR_STR2
6013 "Maximum number of prefixes to accept from this peer\n"
6014 "maximum no. of prefix limit\n"
6015 "Threshold value (%) at which to generate a warning msg\n"
6016 "Restart bgp connection after limit is exceeded\n"
6017 "Restart interval in minutes\n")
6018 {
6019 int idx_peer = 1;
6020 int idx_number = 3;
6021 int idx_number_2 = 4;
6022 int idx_number_3 = 6;
6023 return peer_maximum_prefix_set_vty(
6024 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6025 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6026 argv[idx_number_3]->arg);
6027 }
6028
6029 ALIAS_HIDDEN(
6030 neighbor_maximum_prefix_threshold_restart,
6031 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6032 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6033 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6034 "Maximum number of prefixes to accept from this peer\n"
6035 "maximum no. of prefix limit\n"
6036 "Threshold value (%) at which to generate a warning msg\n"
6037 "Restart bgp connection after limit is exceeded\n"
6038 "Restart interval in minutes\n")
6039
6040 DEFUN (no_neighbor_maximum_prefix,
6041 no_neighbor_maximum_prefix_cmd,
6042 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6043 NO_STR
6044 NEIGHBOR_STR
6045 NEIGHBOR_ADDR_STR2
6046 "Maximum number of prefixes to accept from this peer\n"
6047 "maximum no. of prefix limit\n"
6048 "Threshold value (%) at which to generate a warning msg\n"
6049 "Restart bgp connection after limit is exceeded\n"
6050 "Restart interval in minutes\n"
6051 "Only give warning message when limit is exceeded\n")
6052 {
6053 int idx_peer = 2;
6054 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6055 bgp_node_afi(vty),
6056 bgp_node_safi(vty));
6057 }
6058
6059 ALIAS_HIDDEN(
6060 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6061 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6063 "Maximum number of prefixes to accept from this peer\n"
6064 "maximum no. of prefix limit\n"
6065 "Threshold value (%) at which to generate a warning msg\n"
6066 "Restart bgp connection after limit is exceeded\n"
6067 "Restart interval in minutes\n"
6068 "Only give warning message when limit is exceeded\n")
6069
6070
6071 /* "neighbor allowas-in" */
6072 DEFUN (neighbor_allowas_in,
6073 neighbor_allowas_in_cmd,
6074 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6075 NEIGHBOR_STR
6076 NEIGHBOR_ADDR_STR2
6077 "Accept as-path with my AS present in it\n"
6078 "Number of occurences of AS number\n"
6079 "Only accept my AS in the as-path if the route was originated in my AS\n")
6080 {
6081 int idx_peer = 1;
6082 int idx_number_origin = 3;
6083 int ret;
6084 int origin = 0;
6085 struct peer *peer;
6086 int allow_num = 0;
6087
6088 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6089 if (!peer)
6090 return CMD_WARNING_CONFIG_FAILED;
6091
6092 if (argc <= idx_number_origin)
6093 allow_num = 3;
6094 else {
6095 if (argv[idx_number_origin]->type == WORD_TKN)
6096 origin = 1;
6097 else
6098 allow_num = atoi(argv[idx_number_origin]->arg);
6099 }
6100
6101 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6102 allow_num, origin);
6103
6104 return bgp_vty_return(vty, ret);
6105 }
6106
6107 ALIAS_HIDDEN(
6108 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6109 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6110 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6111 "Accept as-path with my AS present in it\n"
6112 "Number of occurences of AS number\n"
6113 "Only accept my AS in the as-path if the route was originated in my AS\n")
6114
6115 DEFUN (no_neighbor_allowas_in,
6116 no_neighbor_allowas_in_cmd,
6117 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6118 NO_STR
6119 NEIGHBOR_STR
6120 NEIGHBOR_ADDR_STR2
6121 "allow local ASN appears in aspath attribute\n"
6122 "Number of occurences of AS number\n"
6123 "Only accept my AS in the as-path if the route was originated in my AS\n")
6124 {
6125 int idx_peer = 2;
6126 int ret;
6127 struct peer *peer;
6128
6129 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6130 if (!peer)
6131 return CMD_WARNING_CONFIG_FAILED;
6132
6133 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6134 bgp_node_safi(vty));
6135
6136 return bgp_vty_return(vty, ret);
6137 }
6138
6139 ALIAS_HIDDEN(
6140 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6141 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6142 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6143 "allow local ASN appears in aspath attribute\n"
6144 "Number of occurences of AS number\n"
6145 "Only accept my AS in the as-path if the route was originated in my AS\n")
6146
6147 DEFUN (neighbor_ttl_security,
6148 neighbor_ttl_security_cmd,
6149 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6150 NEIGHBOR_STR
6151 NEIGHBOR_ADDR_STR2
6152 "BGP ttl-security parameters\n"
6153 "Specify the maximum number of hops to the BGP peer\n"
6154 "Number of hops to BGP peer\n")
6155 {
6156 int idx_peer = 1;
6157 int idx_number = 4;
6158 struct peer *peer;
6159 int gtsm_hops;
6160
6161 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6162 if (!peer)
6163 return CMD_WARNING_CONFIG_FAILED;
6164
6165 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6166
6167 /*
6168 * If 'neighbor swpX', then this is for directly connected peers,
6169 * we should not accept a ttl-security hops value greater than 1.
6170 */
6171 if (peer->conf_if && (gtsm_hops > 1)) {
6172 vty_out(vty,
6173 "%s is directly connected peer, hops cannot exceed 1\n",
6174 argv[idx_peer]->arg);
6175 return CMD_WARNING_CONFIG_FAILED;
6176 }
6177
6178 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6179 }
6180
6181 DEFUN (no_neighbor_ttl_security,
6182 no_neighbor_ttl_security_cmd,
6183 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6184 NO_STR
6185 NEIGHBOR_STR
6186 NEIGHBOR_ADDR_STR2
6187 "BGP ttl-security parameters\n"
6188 "Specify the maximum number of hops to the BGP peer\n"
6189 "Number of hops to BGP peer\n")
6190 {
6191 int idx_peer = 2;
6192 struct peer *peer;
6193
6194 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6195 if (!peer)
6196 return CMD_WARNING_CONFIG_FAILED;
6197
6198 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6199 }
6200
6201 DEFUN (neighbor_addpath_tx_all_paths,
6202 neighbor_addpath_tx_all_paths_cmd,
6203 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6204 NEIGHBOR_STR
6205 NEIGHBOR_ADDR_STR2
6206 "Use addpath to advertise all paths to a neighbor\n")
6207 {
6208 int idx_peer = 1;
6209 struct peer *peer;
6210
6211 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6212 if (!peer)
6213 return CMD_WARNING_CONFIG_FAILED;
6214
6215 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6216 BGP_ADDPATH_ALL);
6217 return CMD_SUCCESS;
6218 }
6219
6220 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6221 neighbor_addpath_tx_all_paths_hidden_cmd,
6222 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6223 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6224 "Use addpath to advertise all paths to a neighbor\n")
6225
6226 DEFUN (no_neighbor_addpath_tx_all_paths,
6227 no_neighbor_addpath_tx_all_paths_cmd,
6228 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6229 NO_STR
6230 NEIGHBOR_STR
6231 NEIGHBOR_ADDR_STR2
6232 "Use addpath to advertise all paths to a neighbor\n")
6233 {
6234 int idx_peer = 2;
6235 struct peer *peer;
6236
6237 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6238 if (!peer)
6239 return CMD_WARNING_CONFIG_FAILED;
6240
6241 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6242 != BGP_ADDPATH_ALL) {
6243 vty_out(vty,
6244 "%% Peer not currently configured to transmit all paths.");
6245 return CMD_WARNING_CONFIG_FAILED;
6246 }
6247
6248 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6249 BGP_ADDPATH_NONE);
6250
6251 return CMD_SUCCESS;
6252 }
6253
6254 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6255 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6256 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6257 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6258 "Use addpath to advertise all paths to a neighbor\n")
6259
6260 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6261 neighbor_addpath_tx_bestpath_per_as_cmd,
6262 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6263 NEIGHBOR_STR
6264 NEIGHBOR_ADDR_STR2
6265 "Use addpath to advertise the bestpath per each neighboring AS\n")
6266 {
6267 int idx_peer = 1;
6268 struct peer *peer;
6269
6270 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6271 if (!peer)
6272 return CMD_WARNING_CONFIG_FAILED;
6273
6274 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6275 BGP_ADDPATH_BEST_PER_AS);
6276
6277 return CMD_SUCCESS;
6278 }
6279
6280 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6281 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6282 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6283 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6284 "Use addpath to advertise the bestpath per each neighboring AS\n")
6285
6286 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6287 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6288 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6289 NO_STR
6290 NEIGHBOR_STR
6291 NEIGHBOR_ADDR_STR2
6292 "Use addpath to advertise the bestpath per each neighboring AS\n")
6293 {
6294 int idx_peer = 2;
6295 struct peer *peer;
6296
6297 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6298 if (!peer)
6299 return CMD_WARNING_CONFIG_FAILED;
6300
6301 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6302 != BGP_ADDPATH_BEST_PER_AS) {
6303 vty_out(vty,
6304 "%% Peer not currently configured to transmit all best path per as.");
6305 return CMD_WARNING_CONFIG_FAILED;
6306 }
6307
6308 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6309 BGP_ADDPATH_NONE);
6310
6311 return CMD_SUCCESS;
6312 }
6313
6314 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6315 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6316 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6317 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6318 "Use addpath to advertise the bestpath per each neighboring AS\n")
6319
6320 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6321 struct ecommunity **list)
6322 {
6323 struct ecommunity *ecom = NULL;
6324 struct ecommunity *ecomadd;
6325
6326 for (; argc; --argc, ++argv) {
6327
6328 ecomadd = ecommunity_str2com(argv[0]->arg,
6329 ECOMMUNITY_ROUTE_TARGET, 0);
6330 if (!ecomadd) {
6331 vty_out(vty, "Malformed community-list value\n");
6332 if (ecom)
6333 ecommunity_free(&ecom);
6334 return CMD_WARNING_CONFIG_FAILED;
6335 }
6336
6337 if (ecom) {
6338 ecommunity_merge(ecom, ecomadd);
6339 ecommunity_free(&ecomadd);
6340 } else {
6341 ecom = ecomadd;
6342 }
6343 }
6344
6345 if (*list) {
6346 ecommunity_free(&*list);
6347 }
6348 *list = ecom;
6349
6350 return CMD_SUCCESS;
6351 }
6352
6353 /*
6354 * v2vimport is true if we are handling a `import vrf ...` command
6355 */
6356 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6357 {
6358 afi_t afi;
6359
6360 switch (vty->node) {
6361 case BGP_IPV4_NODE:
6362 afi = AFI_IP;
6363 break;
6364 case BGP_IPV6_NODE:
6365 afi = AFI_IP6;
6366 break;
6367 default:
6368 vty_out(vty,
6369 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6370 return AFI_MAX;
6371 }
6372
6373 if (!v2vimport) {
6374 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6375 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6376 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6377 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6378 vty_out(vty,
6379 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6380 return AFI_MAX;
6381 }
6382 } else {
6383 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6384 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6385 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6386 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6387 vty_out(vty,
6388 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6389 return AFI_MAX;
6390 }
6391 }
6392 return afi;
6393 }
6394
6395 DEFPY (af_rd_vpn_export,
6396 af_rd_vpn_export_cmd,
6397 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6398 NO_STR
6399 "Specify route distinguisher\n"
6400 "Between current address-family and vpn\n"
6401 "For routes leaked from current address-family to vpn\n"
6402 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6403 {
6404 VTY_DECLVAR_CONTEXT(bgp, bgp);
6405 struct prefix_rd prd;
6406 int ret;
6407 afi_t afi;
6408 int idx = 0;
6409 int yes = 1;
6410
6411 if (argv_find(argv, argc, "no", &idx))
6412 yes = 0;
6413
6414 if (yes) {
6415 ret = str2prefix_rd(rd_str, &prd);
6416 if (!ret) {
6417 vty_out(vty, "%% Malformed rd\n");
6418 return CMD_WARNING_CONFIG_FAILED;
6419 }
6420 }
6421
6422 afi = vpn_policy_getafi(vty, bgp, false);
6423 if (afi == AFI_MAX)
6424 return CMD_WARNING_CONFIG_FAILED;
6425
6426 /*
6427 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6428 */
6429 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6430 bgp_get_default(), bgp);
6431
6432 if (yes) {
6433 bgp->vpn_policy[afi].tovpn_rd = prd;
6434 SET_FLAG(bgp->vpn_policy[afi].flags,
6435 BGP_VPN_POLICY_TOVPN_RD_SET);
6436 } else {
6437 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6438 BGP_VPN_POLICY_TOVPN_RD_SET);
6439 }
6440
6441 /* post-change: re-export vpn routes */
6442 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6443 bgp_get_default(), bgp);
6444
6445 return CMD_SUCCESS;
6446 }
6447
6448 ALIAS (af_rd_vpn_export,
6449 af_no_rd_vpn_export_cmd,
6450 "no rd vpn export",
6451 NO_STR
6452 "Specify route distinguisher\n"
6453 "Between current address-family and vpn\n"
6454 "For routes leaked from current address-family to vpn\n")
6455
6456 DEFPY (af_label_vpn_export,
6457 af_label_vpn_export_cmd,
6458 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6459 NO_STR
6460 "label value for VRF\n"
6461 "Between current address-family and vpn\n"
6462 "For routes leaked from current address-family to vpn\n"
6463 "Label Value <0-1048575>\n"
6464 "Automatically assign a label\n")
6465 {
6466 VTY_DECLVAR_CONTEXT(bgp, bgp);
6467 mpls_label_t label = MPLS_LABEL_NONE;
6468 afi_t afi;
6469 int idx = 0;
6470 int yes = 1;
6471
6472 if (argv_find(argv, argc, "no", &idx))
6473 yes = 0;
6474
6475 /* If "no ...", squash trailing parameter */
6476 if (!yes)
6477 label_auto = NULL;
6478
6479 if (yes) {
6480 if (!label_auto)
6481 label = label_val; /* parser should force unsigned */
6482 }
6483
6484 afi = vpn_policy_getafi(vty, bgp, false);
6485 if (afi == AFI_MAX)
6486 return CMD_WARNING_CONFIG_FAILED;
6487
6488
6489 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6490 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6491 /* no change */
6492 return CMD_SUCCESS;
6493
6494 /*
6495 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6496 */
6497 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6498 bgp_get_default(), bgp);
6499
6500 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6501 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6502
6503 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6504
6505 /*
6506 * label has previously been automatically
6507 * assigned by labelpool: release it
6508 *
6509 * NB if tovpn_label == MPLS_LABEL_NONE it
6510 * means the automatic assignment is in flight
6511 * and therefore the labelpool callback must
6512 * detect that the auto label is not needed.
6513 */
6514
6515 bgp_lp_release(LP_TYPE_VRF,
6516 &bgp->vpn_policy[afi],
6517 bgp->vpn_policy[afi].tovpn_label);
6518 }
6519 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6520 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6521 }
6522
6523 bgp->vpn_policy[afi].tovpn_label = label;
6524 if (label_auto) {
6525 SET_FLAG(bgp->vpn_policy[afi].flags,
6526 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6527 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6528 vpn_leak_label_callback);
6529 }
6530
6531 /* post-change: re-export vpn routes */
6532 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6533 bgp_get_default(), bgp);
6534
6535 return CMD_SUCCESS;
6536 }
6537
6538 ALIAS (af_label_vpn_export,
6539 af_no_label_vpn_export_cmd,
6540 "no label vpn export",
6541 NO_STR
6542 "label value for VRF\n"
6543 "Between current address-family and vpn\n"
6544 "For routes leaked from current address-family to vpn\n")
6545
6546 DEFPY (af_nexthop_vpn_export,
6547 af_nexthop_vpn_export_cmd,
6548 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6549 NO_STR
6550 "Specify next hop to use for VRF advertised prefixes\n"
6551 "Between current address-family and vpn\n"
6552 "For routes leaked from current address-family to vpn\n"
6553 "IPv4 prefix\n"
6554 "IPv6 prefix\n")
6555 {
6556 VTY_DECLVAR_CONTEXT(bgp, bgp);
6557 afi_t afi;
6558 struct prefix p;
6559 int idx = 0;
6560 int yes = 1;
6561
6562 if (argv_find(argv, argc, "no", &idx))
6563 yes = 0;
6564
6565 if (yes) {
6566 if (!sockunion2hostprefix(nexthop_str, &p))
6567 return CMD_WARNING_CONFIG_FAILED;
6568 }
6569
6570 afi = vpn_policy_getafi(vty, bgp, false);
6571 if (afi == AFI_MAX)
6572 return CMD_WARNING_CONFIG_FAILED;
6573
6574 /*
6575 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6576 */
6577 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6578 bgp_get_default(), bgp);
6579
6580 if (yes) {
6581 bgp->vpn_policy[afi].tovpn_nexthop = p;
6582 SET_FLAG(bgp->vpn_policy[afi].flags,
6583 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6584 } else {
6585 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6586 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6587 }
6588
6589 /* post-change: re-export vpn routes */
6590 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6591 bgp_get_default(), bgp);
6592
6593 return CMD_SUCCESS;
6594 }
6595
6596 ALIAS (af_nexthop_vpn_export,
6597 af_no_nexthop_vpn_export_cmd,
6598 "no nexthop vpn export",
6599 NO_STR
6600 "Specify next hop to use for VRF advertised prefixes\n"
6601 "Between current address-family and vpn\n"
6602 "For routes leaked from current address-family to vpn\n")
6603
6604 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6605 {
6606 if (!strcmp(dstr, "import")) {
6607 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6608 } else if (!strcmp(dstr, "export")) {
6609 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6610 } else if (!strcmp(dstr, "both")) {
6611 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6612 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6613 } else {
6614 vty_out(vty, "%% direction parse error\n");
6615 return CMD_WARNING_CONFIG_FAILED;
6616 }
6617 return CMD_SUCCESS;
6618 }
6619
6620 DEFPY (af_rt_vpn_imexport,
6621 af_rt_vpn_imexport_cmd,
6622 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6623 NO_STR
6624 "Specify route target list\n"
6625 "Specify route target list\n"
6626 "Between current address-family and vpn\n"
6627 "For routes leaked from vpn to current address-family: match any\n"
6628 "For routes leaked from current address-family to vpn: set\n"
6629 "both import: match any and export: set\n"
6630 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6631 {
6632 VTY_DECLVAR_CONTEXT(bgp, bgp);
6633 int ret;
6634 struct ecommunity *ecom = NULL;
6635 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6636 vpn_policy_direction_t dir;
6637 afi_t afi;
6638 int idx = 0;
6639 int yes = 1;
6640
6641 if (argv_find(argv, argc, "no", &idx))
6642 yes = 0;
6643
6644 afi = vpn_policy_getafi(vty, bgp, false);
6645 if (afi == AFI_MAX)
6646 return CMD_WARNING_CONFIG_FAILED;
6647
6648 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6649 if (ret != CMD_SUCCESS)
6650 return ret;
6651
6652 if (yes) {
6653 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6654 vty_out(vty, "%% Missing RTLIST\n");
6655 return CMD_WARNING_CONFIG_FAILED;
6656 }
6657 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6658 if (ret != CMD_SUCCESS) {
6659 return ret;
6660 }
6661 }
6662
6663 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6664 if (!dodir[dir])
6665 continue;
6666
6667 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6668
6669 if (yes) {
6670 if (bgp->vpn_policy[afi].rtlist[dir])
6671 ecommunity_free(
6672 &bgp->vpn_policy[afi].rtlist[dir]);
6673 bgp->vpn_policy[afi].rtlist[dir] =
6674 ecommunity_dup(ecom);
6675 } else {
6676 if (bgp->vpn_policy[afi].rtlist[dir])
6677 ecommunity_free(
6678 &bgp->vpn_policy[afi].rtlist[dir]);
6679 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6680 }
6681
6682 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6683 }
6684
6685 if (ecom)
6686 ecommunity_free(&ecom);
6687
6688 return CMD_SUCCESS;
6689 }
6690
6691 ALIAS (af_rt_vpn_imexport,
6692 af_no_rt_vpn_imexport_cmd,
6693 "no <rt|route-target> vpn <import|export|both>$direction_str",
6694 NO_STR
6695 "Specify route target list\n"
6696 "Specify route target list\n"
6697 "Between current address-family and vpn\n"
6698 "For routes leaked from vpn to current address-family\n"
6699 "For routes leaked from current address-family to vpn\n"
6700 "both import and export\n")
6701
6702 DEFPY (af_route_map_vpn_imexport,
6703 af_route_map_vpn_imexport_cmd,
6704 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6705 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6706 NO_STR
6707 "Specify route map\n"
6708 "Between current address-family and vpn\n"
6709 "For routes leaked from vpn to current address-family\n"
6710 "For routes leaked from current address-family to vpn\n"
6711 "name of route-map\n")
6712 {
6713 VTY_DECLVAR_CONTEXT(bgp, bgp);
6714 int ret;
6715 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6716 vpn_policy_direction_t dir;
6717 afi_t afi;
6718 int idx = 0;
6719 int yes = 1;
6720
6721 if (argv_find(argv, argc, "no", &idx))
6722 yes = 0;
6723
6724 afi = vpn_policy_getafi(vty, bgp, false);
6725 if (afi == AFI_MAX)
6726 return CMD_WARNING_CONFIG_FAILED;
6727
6728 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6729 if (ret != CMD_SUCCESS)
6730 return ret;
6731
6732 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6733 if (!dodir[dir])
6734 continue;
6735
6736 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6737
6738 if (yes) {
6739 if (bgp->vpn_policy[afi].rmap_name[dir])
6740 XFREE(MTYPE_ROUTE_MAP_NAME,
6741 bgp->vpn_policy[afi].rmap_name[dir]);
6742 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6743 MTYPE_ROUTE_MAP_NAME, rmap_str);
6744 bgp->vpn_policy[afi].rmap[dir] =
6745 route_map_lookup_warn_noexist(vty, rmap_str);
6746 if (!bgp->vpn_policy[afi].rmap[dir])
6747 return CMD_SUCCESS;
6748 } else {
6749 if (bgp->vpn_policy[afi].rmap_name[dir])
6750 XFREE(MTYPE_ROUTE_MAP_NAME,
6751 bgp->vpn_policy[afi].rmap_name[dir]);
6752 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6753 bgp->vpn_policy[afi].rmap[dir] = NULL;
6754 }
6755
6756 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6757 }
6758
6759 return CMD_SUCCESS;
6760 }
6761
6762 ALIAS (af_route_map_vpn_imexport,
6763 af_no_route_map_vpn_imexport_cmd,
6764 "no route-map vpn <import|export>$direction_str",
6765 NO_STR
6766 "Specify route map\n"
6767 "Between current address-family and vpn\n"
6768 "For routes leaked from vpn to current address-family\n"
6769 "For routes leaked from current address-family to vpn\n")
6770
6771 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6772 "[no] import vrf route-map RMAP$rmap_str",
6773 NO_STR
6774 "Import routes from another VRF\n"
6775 "Vrf routes being filtered\n"
6776 "Specify route map\n"
6777 "name of route-map\n")
6778 {
6779 VTY_DECLVAR_CONTEXT(bgp, bgp);
6780 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6781 afi_t afi;
6782 int idx = 0;
6783 int yes = 1;
6784 struct bgp *bgp_default;
6785
6786 if (argv_find(argv, argc, "no", &idx))
6787 yes = 0;
6788
6789 afi = vpn_policy_getafi(vty, bgp, true);
6790 if (afi == AFI_MAX)
6791 return CMD_WARNING_CONFIG_FAILED;
6792
6793 bgp_default = bgp_get_default();
6794 if (!bgp_default) {
6795 int32_t ret;
6796 as_t as = bgp->as;
6797
6798 /* Auto-create assuming the same AS */
6799 ret = bgp_get(&bgp_default, &as, NULL,
6800 BGP_INSTANCE_TYPE_DEFAULT);
6801
6802 if (ret) {
6803 vty_out(vty,
6804 "VRF default is not configured as a bgp instance\n");
6805 return CMD_WARNING;
6806 }
6807 }
6808
6809 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6810
6811 if (yes) {
6812 if (bgp->vpn_policy[afi].rmap_name[dir])
6813 XFREE(MTYPE_ROUTE_MAP_NAME,
6814 bgp->vpn_policy[afi].rmap_name[dir]);
6815 bgp->vpn_policy[afi].rmap_name[dir] =
6816 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6817 bgp->vpn_policy[afi].rmap[dir] =
6818 route_map_lookup_warn_noexist(vty, rmap_str);
6819 if (!bgp->vpn_policy[afi].rmap[dir])
6820 return CMD_SUCCESS;
6821 } else {
6822 if (bgp->vpn_policy[afi].rmap_name[dir])
6823 XFREE(MTYPE_ROUTE_MAP_NAME,
6824 bgp->vpn_policy[afi].rmap_name[dir]);
6825 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6826 bgp->vpn_policy[afi].rmap[dir] = NULL;
6827 }
6828
6829 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6830
6831 return CMD_SUCCESS;
6832 }
6833
6834 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6835 "no import vrf route-map",
6836 NO_STR
6837 "Import routes from another VRF\n"
6838 "Vrf routes being filtered\n"
6839 "Specify route map\n")
6840
6841 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6842 "[no] import vrf VIEWVRFNAME$import_name",
6843 NO_STR
6844 "Import routes from another VRF\n"
6845 "VRF to import from\n"
6846 "The name of the VRF\n")
6847 {
6848 VTY_DECLVAR_CONTEXT(bgp, bgp);
6849 struct listnode *node;
6850 struct bgp *vrf_bgp, *bgp_default;
6851 int32_t ret = 0;
6852 as_t as = bgp->as;
6853 bool remove = false;
6854 int32_t idx = 0;
6855 char *vname;
6856 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6857 safi_t safi;
6858 afi_t afi;
6859
6860 if (import_name == NULL) {
6861 vty_out(vty, "%% Missing import name\n");
6862 return CMD_WARNING;
6863 }
6864
6865 if (argv_find(argv, argc, "no", &idx))
6866 remove = true;
6867
6868 afi = vpn_policy_getafi(vty, bgp, true);
6869 if (afi == AFI_MAX)
6870 return CMD_WARNING_CONFIG_FAILED;
6871
6872 safi = bgp_node_safi(vty);
6873
6874 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6875 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6876 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6877 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6878 remove ? "unimport" : "import", import_name);
6879 return CMD_WARNING;
6880 }
6881
6882 bgp_default = bgp_get_default();
6883 if (!bgp_default) {
6884 /* Auto-create assuming the same AS */
6885 ret = bgp_get(&bgp_default, &as, NULL,
6886 BGP_INSTANCE_TYPE_DEFAULT);
6887
6888 if (ret) {
6889 vty_out(vty,
6890 "VRF default is not configured as a bgp instance\n");
6891 return CMD_WARNING;
6892 }
6893 }
6894
6895 vrf_bgp = bgp_lookup_by_name(import_name);
6896 if (!vrf_bgp) {
6897 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6898 vrf_bgp = bgp_default;
6899 else
6900 /* Auto-create assuming the same AS */
6901 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6902
6903 if (ret) {
6904 vty_out(vty,
6905 "VRF %s is not configured as a bgp instance\n",
6906 import_name);
6907 return CMD_WARNING;
6908 }
6909 }
6910
6911 if (remove) {
6912 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6913 } else {
6914 /* Already importing from "import_vrf"? */
6915 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6916 vname)) {
6917 if (strcmp(vname, import_name) == 0)
6918 return CMD_WARNING;
6919 }
6920
6921 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6922 }
6923
6924 return CMD_SUCCESS;
6925 }
6926
6927 /* This command is valid only in a bgp vrf instance or the default instance */
6928 DEFPY (bgp_imexport_vpn,
6929 bgp_imexport_vpn_cmd,
6930 "[no] <import|export>$direction_str vpn",
6931 NO_STR
6932 "Import routes to this address-family\n"
6933 "Export routes from this address-family\n"
6934 "to/from default instance VPN RIB\n")
6935 {
6936 VTY_DECLVAR_CONTEXT(bgp, bgp);
6937 int previous_state;
6938 afi_t afi;
6939 safi_t safi;
6940 int idx = 0;
6941 int yes = 1;
6942 int flag;
6943 vpn_policy_direction_t dir;
6944
6945 if (argv_find(argv, argc, "no", &idx))
6946 yes = 0;
6947
6948 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6949 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6950
6951 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6952 return CMD_WARNING_CONFIG_FAILED;
6953 }
6954
6955 afi = bgp_node_afi(vty);
6956 safi = bgp_node_safi(vty);
6957 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6958 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6959 return CMD_WARNING_CONFIG_FAILED;
6960 }
6961
6962 if (!strcmp(direction_str, "import")) {
6963 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6964 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6965 } else if (!strcmp(direction_str, "export")) {
6966 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6967 dir = BGP_VPN_POLICY_DIR_TOVPN;
6968 } else {
6969 vty_out(vty, "%% unknown direction %s\n", direction_str);
6970 return CMD_WARNING_CONFIG_FAILED;
6971 }
6972
6973 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6974
6975 if (yes) {
6976 SET_FLAG(bgp->af_flags[afi][safi], flag);
6977 if (!previous_state) {
6978 /* trigger export current vrf */
6979 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6980 }
6981 } else {
6982 if (previous_state) {
6983 /* trigger un-export current vrf */
6984 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6985 }
6986 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6987 }
6988
6989 return CMD_SUCCESS;
6990 }
6991
6992 DEFPY (af_routetarget_import,
6993 af_routetarget_import_cmd,
6994 "[no] <rt|route-target> redirect import RTLIST...",
6995 NO_STR
6996 "Specify route target list\n"
6997 "Specify route target list\n"
6998 "Flow-spec redirect type route target\n"
6999 "Import routes to this address-family\n"
7000 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7001 {
7002 VTY_DECLVAR_CONTEXT(bgp, bgp);
7003 int ret;
7004 struct ecommunity *ecom = NULL;
7005 afi_t afi;
7006 int idx = 0;
7007 int yes = 1;
7008
7009 if (argv_find(argv, argc, "no", &idx))
7010 yes = 0;
7011
7012 afi = vpn_policy_getafi(vty, bgp, false);
7013 if (afi == AFI_MAX)
7014 return CMD_WARNING_CONFIG_FAILED;
7015
7016 if (yes) {
7017 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7018 vty_out(vty, "%% Missing RTLIST\n");
7019 return CMD_WARNING_CONFIG_FAILED;
7020 }
7021 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7022 if (ret != CMD_SUCCESS)
7023 return ret;
7024 }
7025
7026 if (yes) {
7027 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7028 ecommunity_free(&bgp->vpn_policy[afi]
7029 .import_redirect_rtlist);
7030 bgp->vpn_policy[afi].import_redirect_rtlist =
7031 ecommunity_dup(ecom);
7032 } else {
7033 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7034 ecommunity_free(&bgp->vpn_policy[afi]
7035 .import_redirect_rtlist);
7036 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7037 }
7038
7039 if (ecom)
7040 ecommunity_free(&ecom);
7041
7042 return CMD_SUCCESS;
7043 }
7044
7045 DEFUN_NOSH (address_family_ipv4_safi,
7046 address_family_ipv4_safi_cmd,
7047 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7048 "Enter Address Family command mode\n"
7049 "Address Family\n"
7050 BGP_SAFI_WITH_LABEL_HELP_STR)
7051 {
7052
7053 if (argc == 3) {
7054 VTY_DECLVAR_CONTEXT(bgp, bgp);
7055 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7056 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7057 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7058 && safi != SAFI_EVPN) {
7059 vty_out(vty,
7060 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7061 return CMD_WARNING_CONFIG_FAILED;
7062 }
7063 vty->node = bgp_node_type(AFI_IP, safi);
7064 } else
7065 vty->node = BGP_IPV4_NODE;
7066
7067 return CMD_SUCCESS;
7068 }
7069
7070 DEFUN_NOSH (address_family_ipv6_safi,
7071 address_family_ipv6_safi_cmd,
7072 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7073 "Enter Address Family command mode\n"
7074 "Address Family\n"
7075 BGP_SAFI_WITH_LABEL_HELP_STR)
7076 {
7077 if (argc == 3) {
7078 VTY_DECLVAR_CONTEXT(bgp, bgp);
7079 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7080 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7081 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7082 && safi != SAFI_EVPN) {
7083 vty_out(vty,
7084 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7085 return CMD_WARNING_CONFIG_FAILED;
7086 }
7087 vty->node = bgp_node_type(AFI_IP6, safi);
7088 } else
7089 vty->node = BGP_IPV6_NODE;
7090
7091 return CMD_SUCCESS;
7092 }
7093
7094 #ifdef KEEP_OLD_VPN_COMMANDS
7095 DEFUN_NOSH (address_family_vpnv4,
7096 address_family_vpnv4_cmd,
7097 "address-family vpnv4 [unicast]",
7098 "Enter Address Family command mode\n"
7099 "Address Family\n"
7100 "Address Family modifier\n")
7101 {
7102 vty->node = BGP_VPNV4_NODE;
7103 return CMD_SUCCESS;
7104 }
7105
7106 DEFUN_NOSH (address_family_vpnv6,
7107 address_family_vpnv6_cmd,
7108 "address-family vpnv6 [unicast]",
7109 "Enter Address Family command mode\n"
7110 "Address Family\n"
7111 "Address Family modifier\n")
7112 {
7113 vty->node = BGP_VPNV6_NODE;
7114 return CMD_SUCCESS;
7115 }
7116 #endif /* KEEP_OLD_VPN_COMMANDS */
7117
7118 DEFUN_NOSH (address_family_evpn,
7119 address_family_evpn_cmd,
7120 "address-family l2vpn evpn",
7121 "Enter Address Family command mode\n"
7122 "Address Family\n"
7123 "Address Family modifier\n")
7124 {
7125 VTY_DECLVAR_CONTEXT(bgp, bgp);
7126 vty->node = BGP_EVPN_NODE;
7127 return CMD_SUCCESS;
7128 }
7129
7130 DEFUN_NOSH (exit_address_family,
7131 exit_address_family_cmd,
7132 "exit-address-family",
7133 "Exit from Address Family configuration mode\n")
7134 {
7135 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7136 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7137 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7138 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7139 || vty->node == BGP_EVPN_NODE
7140 || vty->node == BGP_FLOWSPECV4_NODE
7141 || vty->node == BGP_FLOWSPECV6_NODE)
7142 vty->node = BGP_NODE;
7143 return CMD_SUCCESS;
7144 }
7145
7146 /* Recalculate bestpath and re-advertise a prefix */
7147 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7148 const char *ip_str, afi_t afi, safi_t safi,
7149 struct prefix_rd *prd)
7150 {
7151 int ret;
7152 struct prefix match;
7153 struct bgp_node *rn;
7154 struct bgp_node *rm;
7155 struct bgp *bgp;
7156 struct bgp_table *table;
7157 struct bgp_table *rib;
7158
7159 /* BGP structure lookup. */
7160 if (view_name) {
7161 bgp = bgp_lookup_by_name(view_name);
7162 if (bgp == NULL) {
7163 vty_out(vty, "%% Can't find BGP instance %s\n",
7164 view_name);
7165 return CMD_WARNING;
7166 }
7167 } else {
7168 bgp = bgp_get_default();
7169 if (bgp == NULL) {
7170 vty_out(vty, "%% No BGP process is configured\n");
7171 return CMD_WARNING;
7172 }
7173 }
7174
7175 /* Check IP address argument. */
7176 ret = str2prefix(ip_str, &match);
7177 if (!ret) {
7178 vty_out(vty, "%% address is malformed\n");
7179 return CMD_WARNING;
7180 }
7181
7182 match.family = afi2family(afi);
7183 rib = bgp->rib[afi][safi];
7184
7185 if (safi == SAFI_MPLS_VPN) {
7186 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7187 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7188 continue;
7189
7190 table = bgp_node_get_bgp_table_info(rn);
7191 if (table != NULL) {
7192
7193 if ((rm = bgp_node_match(table, &match))
7194 != NULL) {
7195 if (rm->p.prefixlen
7196 == match.prefixlen) {
7197 SET_FLAG(rm->flags,
7198 BGP_NODE_USER_CLEAR);
7199 bgp_process(bgp, rm, afi, safi);
7200 }
7201 bgp_unlock_node(rm);
7202 }
7203 }
7204 }
7205 } else {
7206 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7207 if (rn->p.prefixlen == match.prefixlen) {
7208 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7209 bgp_process(bgp, rn, afi, safi);
7210 }
7211 bgp_unlock_node(rn);
7212 }
7213 }
7214
7215 return CMD_SUCCESS;
7216 }
7217
7218 /* one clear bgp command to rule them all */
7219 DEFUN (clear_ip_bgp_all,
7220 clear_ip_bgp_all_cmd,
7221 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out>]",
7222 CLEAR_STR
7223 IP_STR
7224 BGP_STR
7225 BGP_INSTANCE_HELP_STR
7226 BGP_AFI_HELP_STR
7227 "Address Family\n"
7228 BGP_SAFI_WITH_LABEL_HELP_STR
7229 "Address Family modifier\n"
7230 "Clear all peers\n"
7231 "BGP neighbor address to clear\n"
7232 "BGP IPv6 neighbor to clear\n"
7233 "BGP neighbor on interface to clear\n"
7234 "Clear peers with the AS number\n"
7235 "Clear all external peers\n"
7236 "Clear all members of peer-group\n"
7237 "BGP peer-group name\n"
7238 BGP_SOFT_STR
7239 BGP_SOFT_IN_STR
7240 BGP_SOFT_OUT_STR
7241 BGP_SOFT_IN_STR
7242 "Push out prefix-list ORF and do inbound soft reconfig\n"
7243 BGP_SOFT_OUT_STR)
7244 {
7245 char *vrf = NULL;
7246
7247 afi_t afi = AFI_IP6;
7248 safi_t safi = SAFI_UNICAST;
7249 enum clear_sort clr_sort = clear_peer;
7250 enum bgp_clear_type clr_type;
7251 char *clr_arg = NULL;
7252
7253 int idx = 0;
7254
7255 /* clear [ip] bgp */
7256 if (argv_find(argv, argc, "ip", &idx))
7257 afi = AFI_IP;
7258
7259 /* [<vrf> VIEWVRFNAME] */
7260 if (argv_find(argv, argc, "vrf", &idx)) {
7261 vrf = argv[idx + 1]->arg;
7262 idx += 2;
7263 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7264 vrf = NULL;
7265 } else if (argv_find(argv, argc, "view", &idx)) {
7266 /* [<view> VIEWVRFNAME] */
7267 vrf = argv[idx + 1]->arg;
7268 idx += 2;
7269 }
7270 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7271 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7272 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7273
7274 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
7275 if (argv_find(argv, argc, "*", &idx)) {
7276 clr_sort = clear_all;
7277 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7278 clr_sort = clear_peer;
7279 clr_arg = argv[idx]->arg;
7280 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7281 clr_sort = clear_peer;
7282 clr_arg = argv[idx]->arg;
7283 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7284 clr_sort = clear_group;
7285 idx++;
7286 clr_arg = argv[idx]->arg;
7287 } else if (argv_find(argv, argc, "PGNAME", &idx)) {
7288 clr_sort = clear_peer;
7289 clr_arg = argv[idx]->arg;
7290 } else if (argv_find(argv, argc, "WORD", &idx)) {
7291 clr_sort = clear_peer;
7292 clr_arg = argv[idx]->arg;
7293 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7294 clr_sort = clear_as;
7295 clr_arg = argv[idx]->arg;
7296 } else if (argv_find(argv, argc, "external", &idx)) {
7297 clr_sort = clear_external;
7298 }
7299
7300 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7301 if (argv_find(argv, argc, "soft", &idx)) {
7302 if (argv_find(argv, argc, "in", &idx)
7303 || argv_find(argv, argc, "out", &idx))
7304 clr_type = strmatch(argv[idx]->text, "in")
7305 ? BGP_CLEAR_SOFT_IN
7306 : BGP_CLEAR_SOFT_OUT;
7307 else
7308 clr_type = BGP_CLEAR_SOFT_BOTH;
7309 } else if (argv_find(argv, argc, "in", &idx)) {
7310 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7311 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7312 : BGP_CLEAR_SOFT_IN;
7313 } else if (argv_find(argv, argc, "out", &idx)) {
7314 clr_type = BGP_CLEAR_SOFT_OUT;
7315 } else
7316 clr_type = BGP_CLEAR_SOFT_NONE;
7317
7318 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7319 }
7320
7321 DEFUN (clear_ip_bgp_prefix,
7322 clear_ip_bgp_prefix_cmd,
7323 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7324 CLEAR_STR
7325 IP_STR
7326 BGP_STR
7327 BGP_INSTANCE_HELP_STR
7328 "Clear bestpath and re-advertise\n"
7329 "IPv4 prefix\n")
7330 {
7331 char *vrf = NULL;
7332 char *prefix = NULL;
7333
7334 int idx = 0;
7335
7336 /* [<view|vrf> VIEWVRFNAME] */
7337 if (argv_find(argv, argc, "vrf", &idx)) {
7338 vrf = argv[idx + 1]->arg;
7339 idx += 2;
7340 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7341 vrf = NULL;
7342 } else if (argv_find(argv, argc, "view", &idx)) {
7343 /* [<view> VIEWVRFNAME] */
7344 vrf = argv[idx + 1]->arg;
7345 idx += 2;
7346 }
7347
7348 prefix = argv[argc - 1]->arg;
7349
7350 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7351 }
7352
7353 DEFUN (clear_bgp_ipv6_safi_prefix,
7354 clear_bgp_ipv6_safi_prefix_cmd,
7355 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7356 CLEAR_STR
7357 IP_STR
7358 BGP_STR
7359 "Address Family\n"
7360 BGP_SAFI_HELP_STR
7361 "Clear bestpath and re-advertise\n"
7362 "IPv6 prefix\n")
7363 {
7364 int idx_safi = 0;
7365 int idx_ipv6_prefix = 0;
7366 safi_t safi = SAFI_UNICAST;
7367 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7368 argv[idx_ipv6_prefix]->arg : NULL;
7369
7370 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7371 return bgp_clear_prefix(
7372 vty, NULL, prefix, AFI_IP6,
7373 safi, NULL);
7374 }
7375
7376 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7377 clear_bgp_instance_ipv6_safi_prefix_cmd,
7378 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7379 CLEAR_STR
7380 IP_STR
7381 BGP_STR
7382 BGP_INSTANCE_HELP_STR
7383 "Address Family\n"
7384 BGP_SAFI_HELP_STR
7385 "Clear bestpath and re-advertise\n"
7386 "IPv6 prefix\n")
7387 {
7388 int idx_safi = 0;
7389 int idx_vrfview = 0;
7390 int idx_ipv6_prefix = 0;
7391 safi_t safi = SAFI_UNICAST;
7392 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7393 argv[idx_ipv6_prefix]->arg : NULL;
7394 char *vrfview = NULL;
7395
7396 /* [<view|vrf> VIEWVRFNAME] */
7397 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7398 vrfview = argv[idx_vrfview + 1]->arg;
7399 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7400 vrfview = NULL;
7401 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7402 /* [<view> VIEWVRFNAME] */
7403 vrfview = argv[idx_vrfview + 1]->arg;
7404 }
7405 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7406
7407 return bgp_clear_prefix(
7408 vty, vrfview, prefix,
7409 AFI_IP6, safi, NULL);
7410 }
7411
7412 DEFUN (show_bgp_views,
7413 show_bgp_views_cmd,
7414 "show [ip] bgp views",
7415 SHOW_STR
7416 IP_STR
7417 BGP_STR
7418 "Show the defined BGP views\n")
7419 {
7420 struct list *inst = bm->bgp;
7421 struct listnode *node;
7422 struct bgp *bgp;
7423
7424 vty_out(vty, "Defined BGP views:\n");
7425 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7426 /* Skip VRFs. */
7427 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7428 continue;
7429 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7430 bgp->as);
7431 }
7432
7433 return CMD_SUCCESS;
7434 }
7435
7436 DEFUN (show_bgp_vrfs,
7437 show_bgp_vrfs_cmd,
7438 "show [ip] bgp vrfs [json]",
7439 SHOW_STR
7440 IP_STR
7441 BGP_STR
7442 "Show BGP VRFs\n"
7443 JSON_STR)
7444 {
7445 char buf[ETHER_ADDR_STRLEN];
7446 struct list *inst = bm->bgp;
7447 struct listnode *node;
7448 struct bgp *bgp;
7449 bool uj = use_json(argc, argv);
7450 json_object *json = NULL;
7451 json_object *json_vrfs = NULL;
7452 int count = 0;
7453
7454 if (uj) {
7455 json = json_object_new_object();
7456 json_vrfs = json_object_new_object();
7457 }
7458
7459 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7460 const char *name, *type;
7461 struct peer *peer;
7462 struct listnode *node2, *nnode2;
7463 int peers_cfg, peers_estb;
7464 json_object *json_vrf = NULL;
7465
7466 /* Skip Views. */
7467 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7468 continue;
7469
7470 count++;
7471 if (!uj && count == 1) {
7472 vty_out(vty,
7473 "%4s %-5s %-16s %9s %10s %-37s\n",
7474 "Type", "Id", "routerId", "#PeersVfg",
7475 "#PeersEstb", "Name");
7476 vty_out(vty, "%11s %-16s %-21s %-6s\n", " ",
7477 "L3-VNI", "RouterMAC", "Interface");
7478 }
7479
7480 peers_cfg = peers_estb = 0;
7481 if (uj)
7482 json_vrf = json_object_new_object();
7483
7484
7485 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7486 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7487 continue;
7488 peers_cfg++;
7489 if (peer->status == Established)
7490 peers_estb++;
7491 }
7492
7493 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7494 name = VRF_DEFAULT_NAME;
7495 type = "DFLT";
7496 } else {
7497 name = bgp->name;
7498 type = "VRF";
7499 }
7500
7501
7502 if (uj) {
7503 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7504 ? -1
7505 : (int64_t)bgp->vrf_id;
7506 json_object_string_add(json_vrf, "type", type);
7507 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7508 json_object_string_add(json_vrf, "routerId",
7509 inet_ntoa(bgp->router_id));
7510 json_object_int_add(json_vrf, "numConfiguredPeers",
7511 peers_cfg);
7512 json_object_int_add(json_vrf, "numEstablishedPeers",
7513 peers_estb);
7514
7515 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7516 json_object_string_add(
7517 json_vrf, "rmac",
7518 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7519 json_object_string_add(json_vrf, "interface",
7520 ifindex2ifname(bgp->l3vni_svi_ifindex,
7521 bgp->vrf_id));
7522 json_object_object_add(json_vrfs, name, json_vrf);
7523 } else {
7524 vty_out(vty,
7525 "%4s %-5d %-16s %-9u %-10u %-37s\n",
7526 type,
7527 bgp->vrf_id == VRF_UNKNOWN ? -1
7528 : (int)bgp->vrf_id,
7529 inet_ntoa(bgp->router_id), peers_cfg,
7530 peers_estb, name);
7531 vty_out(vty,"%11s %-16u %-21s %-20s\n", " ",
7532 bgp->l3vni,
7533 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)),
7534 ifindex2ifname(bgp->l3vni_svi_ifindex,
7535 bgp->vrf_id));
7536 }
7537 }
7538
7539 if (uj) {
7540 json_object_object_add(json, "vrfs", json_vrfs);
7541
7542 json_object_int_add(json, "totalVrfs", count);
7543
7544 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7545 json, JSON_C_TO_STRING_PRETTY));
7546 json_object_free(json);
7547 } else {
7548 if (count)
7549 vty_out(vty,
7550 "\nTotal number of VRFs (including default): %d\n",
7551 count);
7552 }
7553
7554 return CMD_SUCCESS;
7555 }
7556
7557 DEFUN (show_bgp_mac_hash,
7558 show_bgp_mac_hash_cmd,
7559 "show bgp mac hash",
7560 SHOW_STR
7561 BGP_STR
7562 "Mac Address\n"
7563 "Mac Address database\n")
7564 {
7565 bgp_mac_dump_table(vty);
7566
7567 return CMD_SUCCESS;
7568 }
7569
7570 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7571 {
7572 struct vty *vty = (struct vty *)args;
7573 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7574
7575 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7576 tip->refcnt);
7577 }
7578
7579 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7580 {
7581 vty_out(vty, "self nexthop database:\n");
7582 bgp_nexthop_show_address_hash(vty, bgp);
7583
7584 vty_out(vty, "Tunnel-ip database:\n");
7585 hash_iterate(bgp->tip_hash,
7586 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7587 vty);
7588 }
7589
7590 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7591 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7592 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7593 "martian next-hops\n"
7594 "martian next-hop database\n")
7595 {
7596 struct bgp *bgp = NULL;
7597 int idx = 0;
7598 char *name = NULL;
7599
7600 /* [<vrf> VIEWVRFNAME] */
7601 if (argv_find(argv, argc, "vrf", &idx)) {
7602 name = argv[idx + 1]->arg;
7603 if (name && strmatch(name, VRF_DEFAULT_NAME))
7604 name = NULL;
7605 } else if (argv_find(argv, argc, "view", &idx))
7606 /* [<view> VIEWVRFNAME] */
7607 name = argv[idx + 1]->arg;
7608 if (name)
7609 bgp = bgp_lookup_by_name(name);
7610 else
7611 bgp = bgp_get_default();
7612
7613 if (!bgp) {
7614 vty_out(vty, "%% No BGP process is configured\n");
7615 return CMD_WARNING;
7616 }
7617 bgp_show_martian_nexthops(vty, bgp);
7618
7619 return CMD_SUCCESS;
7620 }
7621
7622 DEFUN (show_bgp_memory,
7623 show_bgp_memory_cmd,
7624 "show [ip] bgp memory",
7625 SHOW_STR
7626 IP_STR
7627 BGP_STR
7628 "Global BGP memory statistics\n")
7629 {
7630 char memstrbuf[MTYPE_MEMSTR_LEN];
7631 unsigned long count;
7632
7633 /* RIB related usage stats */
7634 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7635 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7636 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7637 count * sizeof(struct bgp_node)));
7638
7639 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7640 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7641 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7642 count * sizeof(struct bgp_path_info)));
7643 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7644 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7645 count,
7646 mtype_memstr(
7647 memstrbuf, sizeof(memstrbuf),
7648 count * sizeof(struct bgp_path_info_extra)));
7649
7650 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7651 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7652 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7653 count * sizeof(struct bgp_static)));
7654
7655 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7656 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7657 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7658 count * sizeof(struct bpacket)));
7659
7660 /* Adj-In/Out */
7661 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7662 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7663 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7664 count * sizeof(struct bgp_adj_in)));
7665 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7666 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7667 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7668 count * sizeof(struct bgp_adj_out)));
7669
7670 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7671 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7672 count,
7673 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7674 count * sizeof(struct bgp_nexthop_cache)));
7675
7676 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7677 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7678 count,
7679 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7680 count * sizeof(struct bgp_damp_info)));
7681
7682 /* Attributes */
7683 count = attr_count();
7684 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7685 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7686 count * sizeof(struct attr)));
7687
7688 if ((count = attr_unknown_count()))
7689 vty_out(vty, "%ld unknown attributes\n", count);
7690
7691 /* AS_PATH attributes */
7692 count = aspath_count();
7693 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7694 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7695 count * sizeof(struct aspath)));
7696
7697 count = mtype_stats_alloc(MTYPE_AS_SEG);
7698 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7699 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7700 count * sizeof(struct assegment)));
7701
7702 /* Other attributes */
7703 if ((count = community_count()))
7704 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7705 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7706 count * sizeof(struct community)));
7707 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7708 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7709 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7710 count * sizeof(struct ecommunity)));
7711 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7712 vty_out(vty,
7713 "%ld BGP large-community entries, using %s of memory\n",
7714 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7715 count * sizeof(struct lcommunity)));
7716
7717 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7718 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7719 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7720 count * sizeof(struct cluster_list)));
7721
7722 /* Peer related usage */
7723 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7724 vty_out(vty, "%ld peers, using %s of memory\n", count,
7725 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7726 count * sizeof(struct peer)));
7727
7728 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7729 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7730 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7731 count * sizeof(struct peer_group)));
7732
7733 /* Other */
7734 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7735 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7736 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7737 count * sizeof(regex_t)));
7738 return CMD_SUCCESS;
7739 }
7740
7741 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7742 {
7743 json_object *bestpath = json_object_new_object();
7744
7745 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7746 json_object_string_add(bestpath, "asPath", "ignore");
7747
7748 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7749 json_object_string_add(bestpath, "asPath", "confed");
7750
7751 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7752 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7753 json_object_string_add(bestpath, "multiPathRelax",
7754 "as-set");
7755 else
7756 json_object_string_add(bestpath, "multiPathRelax",
7757 "true");
7758 } else
7759 json_object_string_add(bestpath, "multiPathRelax", "false");
7760
7761 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7762 json_object_string_add(bestpath, "compareRouterId", "true");
7763 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7764 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7765 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7766 json_object_string_add(bestpath, "med", "confed");
7767 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7768 json_object_string_add(bestpath, "med",
7769 "missing-as-worst");
7770 else
7771 json_object_string_add(bestpath, "med", "true");
7772 }
7773
7774 json_object_object_add(json, "bestPath", bestpath);
7775 }
7776
7777 /* Show BGP peer's summary information. */
7778 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7779 bool use_json, json_object *json)
7780 {
7781 struct peer *peer;
7782 struct listnode *node, *nnode;
7783 unsigned int count = 0, dn_count = 0;
7784 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7785 char neighbor_buf[VTY_BUFSIZ];
7786 int neighbor_col_default_width = 16;
7787 int len;
7788 int max_neighbor_width = 0;
7789 int pfx_rcd_safi;
7790 json_object *json_peer = NULL;
7791 json_object *json_peers = NULL;
7792 struct peer_af *paf;
7793
7794 /* labeled-unicast routes are installed in the unicast table so in order
7795 * to
7796 * display the correct PfxRcd value we must look at SAFI_UNICAST
7797 */
7798 if (safi == SAFI_LABELED_UNICAST)
7799 pfx_rcd_safi = SAFI_UNICAST;
7800 else
7801 pfx_rcd_safi = safi;
7802
7803 if (use_json) {
7804 if (json == NULL)
7805 json = json_object_new_object();
7806
7807 json_peers = json_object_new_object();
7808 } else {
7809 /* Loop over all neighbors that will be displayed to determine
7810 * how many
7811 * characters are needed for the Neighbor column
7812 */
7813 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7814 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7815 continue;
7816
7817 if (peer->afc[afi][safi]) {
7818 memset(dn_flag, '\0', sizeof(dn_flag));
7819 if (peer_dynamic_neighbor(peer))
7820 dn_flag[0] = '*';
7821
7822 if (peer->hostname
7823 && bgp_flag_check(bgp,
7824 BGP_FLAG_SHOW_HOSTNAME))
7825 sprintf(neighbor_buf, "%s%s(%s) ",
7826 dn_flag, peer->hostname,
7827 peer->host);
7828 else
7829 sprintf(neighbor_buf, "%s%s ", dn_flag,
7830 peer->host);
7831
7832 len = strlen(neighbor_buf);
7833
7834 if (len > max_neighbor_width)
7835 max_neighbor_width = len;
7836 }
7837 }
7838
7839 /* Originally we displayed the Neighbor column as 16
7840 * characters wide so make that the default
7841 */
7842 if (max_neighbor_width < neighbor_col_default_width)
7843 max_neighbor_width = neighbor_col_default_width;
7844 }
7845
7846 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7847 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7848 continue;
7849
7850 if (!peer->afc[afi][safi])
7851 continue;
7852
7853 if (!count) {
7854 unsigned long ents;
7855 char memstrbuf[MTYPE_MEMSTR_LEN];
7856 int64_t vrf_id_ui;
7857
7858 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7859 ? -1
7860 : (int64_t)bgp->vrf_id;
7861
7862 /* Usage summary and header */
7863 if (use_json) {
7864 json_object_string_add(
7865 json, "routerId",
7866 inet_ntoa(bgp->router_id));
7867 json_object_int_add(json, "as", bgp->as);
7868 json_object_int_add(json, "vrfId", vrf_id_ui);
7869 json_object_string_add(
7870 json, "vrfName",
7871 (bgp->inst_type
7872 == BGP_INSTANCE_TYPE_DEFAULT)
7873 ? VRF_DEFAULT_NAME
7874 : bgp->name);
7875 } else {
7876 vty_out(vty,
7877 "BGP router identifier %s, local AS number %u vrf-id %d",
7878 inet_ntoa(bgp->router_id), bgp->as,
7879 bgp->vrf_id == VRF_UNKNOWN
7880 ? -1
7881 : (int)bgp->vrf_id);
7882 vty_out(vty, "\n");
7883 }
7884
7885 if (bgp_update_delay_configured(bgp)) {
7886 if (use_json) {
7887 json_object_int_add(
7888 json, "updateDelayLimit",
7889 bgp->v_update_delay);
7890
7891 if (bgp->v_update_delay
7892 != bgp->v_establish_wait)
7893 json_object_int_add(
7894 json,
7895 "updateDelayEstablishWait",
7896 bgp->v_establish_wait);
7897
7898 if (bgp_update_delay_active(bgp)) {
7899 json_object_string_add(
7900 json,
7901 "updateDelayFirstNeighbor",
7902 bgp->update_delay_begin_time);
7903 json_object_boolean_true_add(
7904 json,
7905 "updateDelayInProgress");
7906 } else {
7907 if (bgp->update_delay_over) {
7908 json_object_string_add(
7909 json,
7910 "updateDelayFirstNeighbor",
7911 bgp->update_delay_begin_time);
7912 json_object_string_add(
7913 json,
7914 "updateDelayBestpathResumed",
7915 bgp->update_delay_end_time);
7916 json_object_string_add(
7917 json,
7918 "updateDelayZebraUpdateResume",
7919 bgp->update_delay_zebra_resume_time);
7920 json_object_string_add(
7921 json,
7922 "updateDelayPeerUpdateResume",
7923 bgp->update_delay_peers_resume_time);
7924 }
7925 }
7926 } else {
7927 vty_out(vty,
7928 "Read-only mode update-delay limit: %d seconds\n",
7929 bgp->v_update_delay);
7930 if (bgp->v_update_delay
7931 != bgp->v_establish_wait)
7932 vty_out(vty,
7933 " Establish wait: %d seconds\n",
7934 bgp->v_establish_wait);
7935
7936 if (bgp_update_delay_active(bgp)) {
7937 vty_out(vty,
7938 " First neighbor established: %s\n",
7939 bgp->update_delay_begin_time);
7940 vty_out(vty,
7941 " Delay in progress\n");
7942 } else {
7943 if (bgp->update_delay_over) {
7944 vty_out(vty,
7945 " First neighbor established: %s\n",
7946 bgp->update_delay_begin_time);
7947 vty_out(vty,
7948 " Best-paths resumed: %s\n",
7949 bgp->update_delay_end_time);
7950 vty_out(vty,
7951 " zebra update resumed: %s\n",
7952 bgp->update_delay_zebra_resume_time);
7953 vty_out(vty,
7954 " peers update resumed: %s\n",
7955 bgp->update_delay_peers_resume_time);
7956 }
7957 }
7958 }
7959 }
7960
7961 if (use_json) {
7962 if (bgp_maxmed_onstartup_configured(bgp)
7963 && bgp->maxmed_active)
7964 json_object_boolean_true_add(
7965 json, "maxMedOnStartup");
7966 if (bgp->v_maxmed_admin)
7967 json_object_boolean_true_add(
7968 json, "maxMedAdministrative");
7969
7970 json_object_int_add(
7971 json, "tableVersion",
7972 bgp_table_version(bgp->rib[afi][safi]));
7973
7974 ents = bgp_table_count(bgp->rib[afi][safi]);
7975 json_object_int_add(json, "ribCount", ents);
7976 json_object_int_add(
7977 json, "ribMemory",
7978 ents * sizeof(struct bgp_node));
7979
7980 ents = bgp->af_peer_count[afi][safi];
7981 json_object_int_add(json, "peerCount", ents);
7982 json_object_int_add(json, "peerMemory",
7983 ents * sizeof(struct peer));
7984
7985 if ((ents = listcount(bgp->group))) {
7986 json_object_int_add(
7987 json, "peerGroupCount", ents);
7988 json_object_int_add(
7989 json, "peerGroupMemory",
7990 ents * sizeof(struct
7991 peer_group));
7992 }
7993
7994 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7995 BGP_CONFIG_DAMPENING))
7996 json_object_boolean_true_add(
7997 json, "dampeningEnabled");
7998 } else {
7999 if (bgp_maxmed_onstartup_configured(bgp)
8000 && bgp->maxmed_active)
8001 vty_out(vty,
8002 "Max-med on-startup active\n");
8003 if (bgp->v_maxmed_admin)
8004 vty_out(vty,
8005 "Max-med administrative active\n");
8006
8007 vty_out(vty, "BGP table version %" PRIu64 "\n",
8008 bgp_table_version(bgp->rib[afi][safi]));
8009
8010 ents = bgp_table_count(bgp->rib[afi][safi]);
8011 vty_out(vty,
8012 "RIB entries %ld, using %s of memory\n",
8013 ents,
8014 mtype_memstr(memstrbuf,
8015 sizeof(memstrbuf),
8016 ents * sizeof(struct
8017 bgp_node)));
8018
8019 /* Peer related usage */
8020 ents = bgp->af_peer_count[afi][safi];
8021 vty_out(vty, "Peers %ld, using %s of memory\n",
8022 ents,
8023 mtype_memstr(
8024 memstrbuf, sizeof(memstrbuf),
8025 ents * sizeof(struct peer)));
8026
8027 if ((ents = listcount(bgp->group)))
8028 vty_out(vty,
8029 "Peer groups %ld, using %s of memory\n",
8030 ents,
8031 mtype_memstr(
8032 memstrbuf,
8033 sizeof(memstrbuf),
8034 ents * sizeof(struct
8035 peer_group)));
8036
8037 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8038 BGP_CONFIG_DAMPENING))
8039 vty_out(vty, "Dampening enabled.\n");
8040 vty_out(vty, "\n");
8041
8042 /* Subtract 8 here because 'Neighbor' is
8043 * 8 characters */
8044 vty_out(vty, "Neighbor");
8045 vty_out(vty, "%*s", max_neighbor_width - 8,
8046 " ");
8047 vty_out(vty,
8048 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8049 }
8050 }
8051
8052 count++;
8053
8054 if (use_json) {
8055 json_peer = json_object_new_object();
8056
8057 if (peer_dynamic_neighbor(peer)) {
8058 dn_count++;
8059 json_object_boolean_true_add(json_peer,
8060 "dynamicPeer");
8061 }
8062
8063 if (peer->hostname)
8064 json_object_string_add(json_peer, "hostname",
8065 peer->hostname);
8066
8067 if (peer->domainname)
8068 json_object_string_add(json_peer, "domainname",
8069 peer->domainname);
8070
8071 json_object_int_add(json_peer, "remoteAs", peer->as);
8072 json_object_int_add(json_peer, "version", 4);
8073 json_object_int_add(json_peer, "msgRcvd",
8074 PEER_TOTAL_RX(peer));
8075 json_object_int_add(json_peer, "msgSent",
8076 PEER_TOTAL_TX(peer));
8077
8078 json_object_int_add(json_peer, "tableVersion",
8079 peer->version[afi][safi]);
8080 json_object_int_add(json_peer, "outq",
8081 peer->obuf->count);
8082 json_object_int_add(json_peer, "inq", 0);
8083 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8084 use_json, json_peer);
8085
8086 /*
8087 * Adding "pfxRcd" field to match with the corresponding
8088 * CLI. "prefixReceivedCount" will be deprecated in
8089 * future.
8090 */
8091 json_object_int_add(json_peer, "prefixReceivedCount",
8092 peer->pcount[afi][pfx_rcd_safi]);
8093 json_object_int_add(json_peer, "pfxRcd",
8094 peer->pcount[afi][pfx_rcd_safi]);
8095
8096 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8097 if (paf && PAF_SUBGRP(paf))
8098 json_object_int_add(json_peer,
8099 "pfxSnt",
8100 (PAF_SUBGRP(paf))->scount);
8101
8102 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8103 json_object_string_add(json_peer, "state",
8104 "Idle (Admin)");
8105 else if (peer->afc_recv[afi][safi])
8106 json_object_string_add(
8107 json_peer, "state",
8108 lookup_msg(bgp_status_msg, peer->status,
8109 NULL));
8110 else if (CHECK_FLAG(peer->sflags,
8111 PEER_STATUS_PREFIX_OVERFLOW))
8112 json_object_string_add(json_peer, "state",
8113 "Idle (PfxCt)");
8114 else
8115 json_object_string_add(
8116 json_peer, "state",
8117 lookup_msg(bgp_status_msg, peer->status,
8118 NULL));
8119
8120 if (peer->conf_if)
8121 json_object_string_add(json_peer, "idType",
8122 "interface");
8123 else if (peer->su.sa.sa_family == AF_INET)
8124 json_object_string_add(json_peer, "idType",
8125 "ipv4");
8126 else if (peer->su.sa.sa_family == AF_INET6)
8127 json_object_string_add(json_peer, "idType",
8128 "ipv6");
8129
8130 json_object_object_add(json_peers, peer->host,
8131 json_peer);
8132 } else {
8133 memset(dn_flag, '\0', sizeof(dn_flag));
8134 if (peer_dynamic_neighbor(peer)) {
8135 dn_count++;
8136 dn_flag[0] = '*';
8137 }
8138
8139 if (peer->hostname
8140 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8141 len = vty_out(vty, "%s%s(%s)", dn_flag,
8142 peer->hostname, peer->host);
8143 else
8144 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8145
8146 /* pad the neighbor column with spaces */
8147 if (len < max_neighbor_width)
8148 vty_out(vty, "%*s", max_neighbor_width - len,
8149 " ");
8150
8151 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8152 peer->as, PEER_TOTAL_RX(peer),
8153 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8154 0, peer->obuf->count,
8155 peer_uptime(peer->uptime, timebuf,
8156 BGP_UPTIME_LEN, 0, NULL));
8157
8158 if (peer->status == Established)
8159 if (peer->afc_recv[afi][safi])
8160 vty_out(vty, " %12ld",
8161 peer->pcount[afi]
8162 [pfx_rcd_safi]);
8163 else
8164 vty_out(vty, " NoNeg");
8165 else {
8166 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8167 vty_out(vty, " Idle (Admin)");
8168 else if (CHECK_FLAG(
8169 peer->sflags,
8170 PEER_STATUS_PREFIX_OVERFLOW))
8171 vty_out(vty, " Idle (PfxCt)");
8172 else
8173 vty_out(vty, " %12s",
8174 lookup_msg(bgp_status_msg,
8175 peer->status, NULL));
8176 }
8177 vty_out(vty, "\n");
8178 }
8179 }
8180
8181 if (use_json) {
8182 json_object_object_add(json, "peers", json_peers);
8183
8184 json_object_int_add(json, "totalPeers", count);
8185 json_object_int_add(json, "dynamicPeers", dn_count);
8186
8187 bgp_show_bestpath_json(bgp, json);
8188
8189 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8190 json, JSON_C_TO_STRING_PRETTY));
8191 json_object_free(json);
8192 } else {
8193 if (count)
8194 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8195 else {
8196 vty_out(vty, "No %s neighbor is configured\n",
8197 afi_safi_print(afi, safi));
8198 }
8199
8200 if (dn_count) {
8201 vty_out(vty, "* - dynamic neighbor\n");
8202 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8203 dn_count, bgp->dynamic_neighbors_limit);
8204 }
8205 }
8206
8207 return CMD_SUCCESS;
8208 }
8209
8210 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8211 int safi, bool use_json,
8212 json_object *json)
8213 {
8214 int is_first = 1;
8215 int afi_wildcard = (afi == AFI_MAX);
8216 int safi_wildcard = (safi == SAFI_MAX);
8217 int is_wildcard = (afi_wildcard || safi_wildcard);
8218 bool nbr_output = false;
8219
8220 if (use_json && is_wildcard)
8221 vty_out(vty, "{\n");
8222 if (afi_wildcard)
8223 afi = 1; /* AFI_IP */
8224 while (afi < AFI_MAX) {
8225 if (safi_wildcard)
8226 safi = 1; /* SAFI_UNICAST */
8227 while (safi < SAFI_MAX) {
8228 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8229 nbr_output = true;
8230 if (is_wildcard) {
8231 /*
8232 * So limit output to those afi/safi
8233 * pairs that
8234 * actualy have something interesting in
8235 * them
8236 */
8237 if (use_json) {
8238 json = json_object_new_object();
8239
8240 if (!is_first)
8241 vty_out(vty, ",\n");
8242 else
8243 is_first = 0;
8244
8245 vty_out(vty, "\"%s\":",
8246 afi_safi_json(afi,
8247 safi));
8248 } else {
8249 vty_out(vty, "\n%s Summary:\n",
8250 afi_safi_print(afi,
8251 safi));
8252 }
8253 }
8254 bgp_show_summary(vty, bgp, afi, safi, use_json,
8255 json);
8256 }
8257 safi++;
8258 if (!safi_wildcard)
8259 safi = SAFI_MAX;
8260 }
8261 afi++;
8262 if (!afi_wildcard)
8263 afi = AFI_MAX;
8264 }
8265
8266 if (use_json && is_wildcard)
8267 vty_out(vty, "}\n");
8268 else if (!nbr_output) {
8269 if (use_json)
8270 vty_out(vty, "{}\n");
8271 else
8272 vty_out(vty, "%% No BGP neighbors found\n");
8273 }
8274 }
8275
8276 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8277 safi_t safi, bool use_json)
8278 {
8279 struct listnode *node, *nnode;
8280 struct bgp *bgp;
8281 json_object *json = NULL;
8282 int is_first = 1;
8283 bool nbr_output = false;
8284
8285 if (use_json)
8286 vty_out(vty, "{\n");
8287
8288 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8289 nbr_output = true;
8290 if (use_json) {
8291 json = json_object_new_object();
8292
8293 if (!is_first)
8294 vty_out(vty, ",\n");
8295 else
8296 is_first = 0;
8297
8298 vty_out(vty, "\"%s\":",
8299 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8300 ? VRF_DEFAULT_NAME
8301 : bgp->name);
8302 } else {
8303 vty_out(vty, "\nInstance %s:\n",
8304 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8305 ? VRF_DEFAULT_NAME
8306 : bgp->name);
8307 }
8308 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8309 }
8310
8311 if (use_json)
8312 vty_out(vty, "}\n");
8313 else if (!nbr_output)
8314 vty_out(vty, "%% BGP instance not found\n");
8315 }
8316
8317 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8318 safi_t safi, bool use_json)
8319 {
8320 struct bgp *bgp;
8321
8322 if (name) {
8323 if (strmatch(name, "all")) {
8324 bgp_show_all_instances_summary_vty(vty, afi, safi,
8325 use_json);
8326 return CMD_SUCCESS;
8327 } else {
8328 bgp = bgp_lookup_by_name(name);
8329
8330 if (!bgp) {
8331 if (use_json)
8332 vty_out(vty, "{}\n");
8333 else
8334 vty_out(vty,
8335 "%% BGP instance not found\n");
8336 return CMD_WARNING;
8337 }
8338
8339 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8340 NULL);
8341 return CMD_SUCCESS;
8342 }
8343 }
8344
8345 bgp = bgp_get_default();
8346
8347 if (bgp)
8348 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8349 else {
8350 if (use_json)
8351 vty_out(vty, "{}\n");
8352 else
8353 vty_out(vty, "%% BGP instance not found\n");
8354 return CMD_WARNING;
8355 }
8356
8357 return CMD_SUCCESS;
8358 }
8359
8360 /* `show [ip] bgp summary' commands. */
8361 DEFUN (show_ip_bgp_summary,
8362 show_ip_bgp_summary_cmd,
8363 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8364 SHOW_STR
8365 IP_STR
8366 BGP_STR
8367 BGP_INSTANCE_HELP_STR
8368 BGP_AFI_HELP_STR
8369 BGP_SAFI_WITH_LABEL_HELP_STR
8370 "Summary of BGP neighbor status\n"
8371 JSON_STR)
8372 {
8373 char *vrf = NULL;
8374 afi_t afi = AFI_MAX;
8375 safi_t safi = SAFI_MAX;
8376
8377 int idx = 0;
8378
8379 /* show [ip] bgp */
8380 if (argv_find(argv, argc, "ip", &idx))
8381 afi = AFI_IP;
8382 /* [<vrf> VIEWVRFNAME] */
8383 if (argv_find(argv, argc, "vrf", &idx)) {
8384 vrf = argv[idx + 1]->arg;
8385 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8386 vrf = NULL;
8387 } else if (argv_find(argv, argc, "view", &idx))
8388 /* [<view> VIEWVRFNAME] */
8389 vrf = argv[idx + 1]->arg;
8390 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8391 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8392 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8393 }
8394
8395 bool uj = use_json(argc, argv);
8396
8397 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8398 }
8399
8400 const char *afi_safi_print(afi_t afi, safi_t safi)
8401 {
8402 if (afi == AFI_IP && safi == SAFI_UNICAST)
8403 return "IPv4 Unicast";
8404 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8405 return "IPv4 Multicast";
8406 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8407 return "IPv4 Labeled Unicast";
8408 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8409 return "IPv4 VPN";
8410 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8411 return "IPv4 Encap";
8412 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8413 return "IPv4 Flowspec";
8414 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8415 return "IPv6 Unicast";
8416 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8417 return "IPv6 Multicast";
8418 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8419 return "IPv6 Labeled Unicast";
8420 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8421 return "IPv6 VPN";
8422 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8423 return "IPv6 Encap";
8424 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8425 return "IPv6 Flowspec";
8426 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8427 return "L2VPN EVPN";
8428 else
8429 return "Unknown";
8430 }
8431
8432 /*
8433 * Please note that we have intentionally camelCased
8434 * the return strings here. So if you want
8435 * to use this function, please ensure you
8436 * are doing this within json output
8437 */
8438 const char *afi_safi_json(afi_t afi, safi_t safi)
8439 {
8440 if (afi == AFI_IP && safi == SAFI_UNICAST)
8441 return "ipv4Unicast";
8442 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8443 return "ipv4Multicast";
8444 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8445 return "ipv4LabeledUnicast";
8446 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8447 return "ipv4Vpn";
8448 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8449 return "ipv4Encap";
8450 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8451 return "ipv4Flowspec";
8452 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8453 return "ipv6Unicast";
8454 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8455 return "ipv6Multicast";
8456 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8457 return "ipv6LabeledUnicast";
8458 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8459 return "ipv6Vpn";
8460 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8461 return "ipv6Encap";
8462 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8463 return "ipv6Flowspec";
8464 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8465 return "l2VpnEvpn";
8466 else
8467 return "Unknown";
8468 }
8469
8470 /* Show BGP peer's information. */
8471 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8472
8473 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8474 afi_t afi, safi_t safi,
8475 uint16_t adv_smcap, uint16_t adv_rmcap,
8476 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8477 bool use_json, json_object *json_pref)
8478 {
8479 /* Send-Mode */
8480 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8481 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8482 if (use_json) {
8483 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8484 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8485 json_object_string_add(json_pref, "sendMode",
8486 "advertisedAndReceived");
8487 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8488 json_object_string_add(json_pref, "sendMode",
8489 "advertised");
8490 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8491 json_object_string_add(json_pref, "sendMode",
8492 "received");
8493 } else {
8494 vty_out(vty, " Send-mode: ");
8495 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8496 vty_out(vty, "advertised");
8497 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8498 vty_out(vty, "%sreceived",
8499 CHECK_FLAG(p->af_cap[afi][safi],
8500 adv_smcap)
8501 ? ", "
8502 : "");
8503 vty_out(vty, "\n");
8504 }
8505 }
8506
8507 /* Receive-Mode */
8508 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8509 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8510 if (use_json) {
8511 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8512 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8513 json_object_string_add(json_pref, "recvMode",
8514 "advertisedAndReceived");
8515 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8516 json_object_string_add(json_pref, "recvMode",
8517 "advertised");
8518 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8519 json_object_string_add(json_pref, "recvMode",
8520 "received");
8521 } else {
8522 vty_out(vty, " Receive-mode: ");
8523 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8524 vty_out(vty, "advertised");
8525 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8526 vty_out(vty, "%sreceived",
8527 CHECK_FLAG(p->af_cap[afi][safi],
8528 adv_rmcap)
8529 ? ", "
8530 : "");
8531 vty_out(vty, "\n");
8532 }
8533 }
8534 }
8535
8536 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8537 safi_t safi, bool use_json,
8538 json_object *json_neigh)
8539 {
8540 struct bgp_filter *filter;
8541 struct peer_af *paf;
8542 char orf_pfx_name[BUFSIZ];
8543 int orf_pfx_count;
8544 json_object *json_af = NULL;
8545 json_object *json_prefA = NULL;
8546 json_object *json_prefB = NULL;
8547 json_object *json_addr = NULL;
8548
8549 if (use_json) {
8550 json_addr = json_object_new_object();
8551 json_af = json_object_new_object();
8552 filter = &p->filter[afi][safi];
8553
8554 if (peer_group_active(p))
8555 json_object_string_add(json_addr, "peerGroupMember",
8556 p->group->name);
8557
8558 paf = peer_af_find(p, afi, safi);
8559 if (paf && PAF_SUBGRP(paf)) {
8560 json_object_int_add(json_addr, "updateGroupId",
8561 PAF_UPDGRP(paf)->id);
8562 json_object_int_add(json_addr, "subGroupId",
8563 PAF_SUBGRP(paf)->id);
8564 json_object_int_add(json_addr, "packetQueueLength",
8565 bpacket_queue_virtual_length(paf));
8566 }
8567
8568 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8569 || CHECK_FLAG(p->af_cap[afi][safi],
8570 PEER_CAP_ORF_PREFIX_SM_RCV)
8571 || CHECK_FLAG(p->af_cap[afi][safi],
8572 PEER_CAP_ORF_PREFIX_RM_ADV)
8573 || CHECK_FLAG(p->af_cap[afi][safi],
8574 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8575 json_object_int_add(json_af, "orfType",
8576 ORF_TYPE_PREFIX);
8577 json_prefA = json_object_new_object();
8578 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8579 PEER_CAP_ORF_PREFIX_SM_ADV,
8580 PEER_CAP_ORF_PREFIX_RM_ADV,
8581 PEER_CAP_ORF_PREFIX_SM_RCV,
8582 PEER_CAP_ORF_PREFIX_RM_RCV,
8583 use_json, json_prefA);
8584 json_object_object_add(json_af, "orfPrefixList",
8585 json_prefA);
8586 }
8587
8588 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8589 || CHECK_FLAG(p->af_cap[afi][safi],
8590 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8591 || CHECK_FLAG(p->af_cap[afi][safi],
8592 PEER_CAP_ORF_PREFIX_RM_ADV)
8593 || CHECK_FLAG(p->af_cap[afi][safi],
8594 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8595 json_object_int_add(json_af, "orfOldType",
8596 ORF_TYPE_PREFIX_OLD);
8597 json_prefB = json_object_new_object();
8598 bgp_show_peer_afi_orf_cap(
8599 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8600 PEER_CAP_ORF_PREFIX_RM_ADV,
8601 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8602 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8603 json_prefB);
8604 json_object_object_add(json_af, "orfOldPrefixList",
8605 json_prefB);
8606 }
8607
8608 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8609 || CHECK_FLAG(p->af_cap[afi][safi],
8610 PEER_CAP_ORF_PREFIX_SM_RCV)
8611 || CHECK_FLAG(p->af_cap[afi][safi],
8612 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8613 || CHECK_FLAG(p->af_cap[afi][safi],
8614 PEER_CAP_ORF_PREFIX_RM_ADV)
8615 || CHECK_FLAG(p->af_cap[afi][safi],
8616 PEER_CAP_ORF_PREFIX_RM_RCV)
8617 || CHECK_FLAG(p->af_cap[afi][safi],
8618 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8619 json_object_object_add(json_addr, "afDependentCap",
8620 json_af);
8621 else
8622 json_object_free(json_af);
8623
8624 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8625 orf_pfx_count = prefix_bgp_show_prefix_list(
8626 NULL, afi, orf_pfx_name, use_json);
8627
8628 if (CHECK_FLAG(p->af_sflags[afi][safi],
8629 PEER_STATUS_ORF_PREFIX_SEND)
8630 || orf_pfx_count) {
8631 if (CHECK_FLAG(p->af_sflags[afi][safi],
8632 PEER_STATUS_ORF_PREFIX_SEND))
8633 json_object_boolean_true_add(json_neigh,
8634 "orfSent");
8635 if (orf_pfx_count)
8636 json_object_int_add(json_addr, "orfRecvCounter",
8637 orf_pfx_count);
8638 }
8639 if (CHECK_FLAG(p->af_sflags[afi][safi],
8640 PEER_STATUS_ORF_WAIT_REFRESH))
8641 json_object_string_add(
8642 json_addr, "orfFirstUpdate",
8643 "deferredUntilORFOrRouteRefreshRecvd");
8644
8645 if (CHECK_FLAG(p->af_flags[afi][safi],
8646 PEER_FLAG_REFLECTOR_CLIENT))
8647 json_object_boolean_true_add(json_addr,
8648 "routeReflectorClient");
8649 if (CHECK_FLAG(p->af_flags[afi][safi],
8650 PEER_FLAG_RSERVER_CLIENT))
8651 json_object_boolean_true_add(json_addr,
8652 "routeServerClient");
8653 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8654 json_object_boolean_true_add(json_addr,
8655 "inboundSoftConfigPermit");
8656
8657 if (CHECK_FLAG(p->af_flags[afi][safi],
8658 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8659 json_object_boolean_true_add(
8660 json_addr,
8661 "privateAsNumsAllReplacedInUpdatesToNbr");
8662 else if (CHECK_FLAG(p->af_flags[afi][safi],
8663 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8664 json_object_boolean_true_add(
8665 json_addr,
8666 "privateAsNumsReplacedInUpdatesToNbr");
8667 else if (CHECK_FLAG(p->af_flags[afi][safi],
8668 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8669 json_object_boolean_true_add(
8670 json_addr,
8671 "privateAsNumsAllRemovedInUpdatesToNbr");
8672 else if (CHECK_FLAG(p->af_flags[afi][safi],
8673 PEER_FLAG_REMOVE_PRIVATE_AS))
8674 json_object_boolean_true_add(
8675 json_addr,
8676 "privateAsNumsRemovedInUpdatesToNbr");
8677
8678 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8679 json_object_boolean_true_add(
8680 json_addr,
8681 bgp_addpath_names(p->addpath_type[afi][safi])
8682 ->type_json_name);
8683
8684 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8685 json_object_string_add(json_addr,
8686 "overrideASNsInOutboundUpdates",
8687 "ifAspathEqualRemoteAs");
8688
8689 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8690 || CHECK_FLAG(p->af_flags[afi][safi],
8691 PEER_FLAG_FORCE_NEXTHOP_SELF))
8692 json_object_boolean_true_add(json_addr,
8693 "routerAlwaysNextHop");
8694 if (CHECK_FLAG(p->af_flags[afi][safi],
8695 PEER_FLAG_AS_PATH_UNCHANGED))
8696 json_object_boolean_true_add(
8697 json_addr, "unchangedAsPathPropogatedToNbr");
8698 if (CHECK_FLAG(p->af_flags[afi][safi],
8699 PEER_FLAG_NEXTHOP_UNCHANGED))
8700 json_object_boolean_true_add(
8701 json_addr, "unchangedNextHopPropogatedToNbr");
8702 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8703 json_object_boolean_true_add(
8704 json_addr, "unchangedMedPropogatedToNbr");
8705 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8706 || CHECK_FLAG(p->af_flags[afi][safi],
8707 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8708 if (CHECK_FLAG(p->af_flags[afi][safi],
8709 PEER_FLAG_SEND_COMMUNITY)
8710 && CHECK_FLAG(p->af_flags[afi][safi],
8711 PEER_FLAG_SEND_EXT_COMMUNITY))
8712 json_object_string_add(json_addr,
8713 "commAttriSentToNbr",
8714 "extendedAndStandard");
8715 else if (CHECK_FLAG(p->af_flags[afi][safi],
8716 PEER_FLAG_SEND_EXT_COMMUNITY))
8717 json_object_string_add(json_addr,
8718 "commAttriSentToNbr",
8719 "extended");
8720 else
8721 json_object_string_add(json_addr,
8722 "commAttriSentToNbr",
8723 "standard");
8724 }
8725 if (CHECK_FLAG(p->af_flags[afi][safi],
8726 PEER_FLAG_DEFAULT_ORIGINATE)) {
8727 if (p->default_rmap[afi][safi].name)
8728 json_object_string_add(
8729 json_addr, "defaultRouteMap",
8730 p->default_rmap[afi][safi].name);
8731
8732 if (paf && PAF_SUBGRP(paf)
8733 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8734 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8735 json_object_boolean_true_add(json_addr,
8736 "defaultSent");
8737 else
8738 json_object_boolean_true_add(json_addr,
8739 "defaultNotSent");
8740 }
8741
8742 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8743 if (is_evpn_enabled())
8744 json_object_boolean_true_add(
8745 json_addr, "advertiseAllVnis");
8746 }
8747
8748 if (filter->plist[FILTER_IN].name
8749 || filter->dlist[FILTER_IN].name
8750 || filter->aslist[FILTER_IN].name
8751 || filter->map[RMAP_IN].name)
8752 json_object_boolean_true_add(json_addr,
8753 "inboundPathPolicyConfig");
8754 if (filter->plist[FILTER_OUT].name
8755 || filter->dlist[FILTER_OUT].name
8756 || filter->aslist[FILTER_OUT].name
8757 || filter->map[RMAP_OUT].name || filter->usmap.name)
8758 json_object_boolean_true_add(
8759 json_addr, "outboundPathPolicyConfig");
8760
8761 /* prefix-list */
8762 if (filter->plist[FILTER_IN].name)
8763 json_object_string_add(json_addr,
8764 "incomingUpdatePrefixFilterList",
8765 filter->plist[FILTER_IN].name);
8766 if (filter->plist[FILTER_OUT].name)
8767 json_object_string_add(json_addr,
8768 "outgoingUpdatePrefixFilterList",
8769 filter->plist[FILTER_OUT].name);
8770
8771 /* distribute-list */
8772 if (filter->dlist[FILTER_IN].name)
8773 json_object_string_add(
8774 json_addr, "incomingUpdateNetworkFilterList",
8775 filter->dlist[FILTER_IN].name);
8776 if (filter->dlist[FILTER_OUT].name)
8777 json_object_string_add(
8778 json_addr, "outgoingUpdateNetworkFilterList",
8779 filter->dlist[FILTER_OUT].name);
8780
8781 /* filter-list. */
8782 if (filter->aslist[FILTER_IN].name)
8783 json_object_string_add(json_addr,
8784 "incomingUpdateAsPathFilterList",
8785 filter->aslist[FILTER_IN].name);
8786 if (filter->aslist[FILTER_OUT].name)
8787 json_object_string_add(json_addr,
8788 "outgoingUpdateAsPathFilterList",
8789 filter->aslist[FILTER_OUT].name);
8790
8791 /* route-map. */
8792 if (filter->map[RMAP_IN].name)
8793 json_object_string_add(
8794 json_addr, "routeMapForIncomingAdvertisements",
8795 filter->map[RMAP_IN].name);
8796 if (filter->map[RMAP_OUT].name)
8797 json_object_string_add(
8798 json_addr, "routeMapForOutgoingAdvertisements",
8799 filter->map[RMAP_OUT].name);
8800
8801 /* ebgp-requires-policy (inbound) */
8802 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8803 && !bgp_inbound_policy_exists(p, filter))
8804 json_object_string_add(
8805 json_addr, "inboundEbgpRequiresPolicy",
8806 "Inbound updates discarded due to missing policy");
8807
8808 /* ebgp-requires-policy (outbound) */
8809 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8810 && (!bgp_outbound_policy_exists(p, filter)))
8811 json_object_string_add(
8812 json_addr, "outboundEbgpRequiresPolicy",
8813 "Outbound updates discarded due to missing policy");
8814
8815 /* unsuppress-map */
8816 if (filter->usmap.name)
8817 json_object_string_add(json_addr,
8818 "selectiveUnsuppressRouteMap",
8819 filter->usmap.name);
8820
8821 /* Receive prefix count */
8822 json_object_int_add(json_addr, "acceptedPrefixCounter",
8823 p->pcount[afi][safi]);
8824 if (paf && PAF_SUBGRP(paf))
8825 json_object_int_add(json_addr, "sentPrefixCounter",
8826 (PAF_SUBGRP(paf))->scount);
8827
8828 /* Maximum prefix */
8829 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8830 json_object_int_add(json_addr, "prefixAllowedMax",
8831 p->pmax[afi][safi]);
8832 if (CHECK_FLAG(p->af_flags[afi][safi],
8833 PEER_FLAG_MAX_PREFIX_WARNING))
8834 json_object_boolean_true_add(
8835 json_addr, "prefixAllowedMaxWarning");
8836 json_object_int_add(json_addr,
8837 "prefixAllowedWarningThresh",
8838 p->pmax_threshold[afi][safi]);
8839 if (p->pmax_restart[afi][safi])
8840 json_object_int_add(
8841 json_addr,
8842 "prefixAllowedRestartIntervalMsecs",
8843 p->pmax_restart[afi][safi] * 60000);
8844 }
8845 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8846 json_addr);
8847
8848 } else {
8849 filter = &p->filter[afi][safi];
8850
8851 vty_out(vty, " For address family: %s\n",
8852 afi_safi_print(afi, safi));
8853
8854 if (peer_group_active(p))
8855 vty_out(vty, " %s peer-group member\n",
8856 p->group->name);
8857
8858 paf = peer_af_find(p, afi, safi);
8859 if (paf && PAF_SUBGRP(paf)) {
8860 vty_out(vty, " Update group %" PRIu64
8861 ", subgroup %" PRIu64 "\n",
8862 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8863 vty_out(vty, " Packet Queue length %d\n",
8864 bpacket_queue_virtual_length(paf));
8865 } else {
8866 vty_out(vty, " Not part of any update group\n");
8867 }
8868 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8869 || CHECK_FLAG(p->af_cap[afi][safi],
8870 PEER_CAP_ORF_PREFIX_SM_RCV)
8871 || CHECK_FLAG(p->af_cap[afi][safi],
8872 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8873 || CHECK_FLAG(p->af_cap[afi][safi],
8874 PEER_CAP_ORF_PREFIX_RM_ADV)
8875 || CHECK_FLAG(p->af_cap[afi][safi],
8876 PEER_CAP_ORF_PREFIX_RM_RCV)
8877 || CHECK_FLAG(p->af_cap[afi][safi],
8878 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8879 vty_out(vty, " AF-dependant capabilities:\n");
8880
8881 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8882 || CHECK_FLAG(p->af_cap[afi][safi],
8883 PEER_CAP_ORF_PREFIX_SM_RCV)
8884 || CHECK_FLAG(p->af_cap[afi][safi],
8885 PEER_CAP_ORF_PREFIX_RM_ADV)
8886 || CHECK_FLAG(p->af_cap[afi][safi],
8887 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8888 vty_out(vty,
8889 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8890 ORF_TYPE_PREFIX);
8891 bgp_show_peer_afi_orf_cap(
8892 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8893 PEER_CAP_ORF_PREFIX_RM_ADV,
8894 PEER_CAP_ORF_PREFIX_SM_RCV,
8895 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8896 }
8897 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8898 || CHECK_FLAG(p->af_cap[afi][safi],
8899 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8900 || CHECK_FLAG(p->af_cap[afi][safi],
8901 PEER_CAP_ORF_PREFIX_RM_ADV)
8902 || CHECK_FLAG(p->af_cap[afi][safi],
8903 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8904 vty_out(vty,
8905 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8906 ORF_TYPE_PREFIX_OLD);
8907 bgp_show_peer_afi_orf_cap(
8908 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8909 PEER_CAP_ORF_PREFIX_RM_ADV,
8910 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8911 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8912 }
8913
8914 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8915 orf_pfx_count = prefix_bgp_show_prefix_list(
8916 NULL, afi, orf_pfx_name, use_json);
8917
8918 if (CHECK_FLAG(p->af_sflags[afi][safi],
8919 PEER_STATUS_ORF_PREFIX_SEND)
8920 || orf_pfx_count) {
8921 vty_out(vty, " Outbound Route Filter (ORF):");
8922 if (CHECK_FLAG(p->af_sflags[afi][safi],
8923 PEER_STATUS_ORF_PREFIX_SEND))
8924 vty_out(vty, " sent;");
8925 if (orf_pfx_count)
8926 vty_out(vty, " received (%d entries)",
8927 orf_pfx_count);
8928 vty_out(vty, "\n");
8929 }
8930 if (CHECK_FLAG(p->af_sflags[afi][safi],
8931 PEER_STATUS_ORF_WAIT_REFRESH))
8932 vty_out(vty,
8933 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8934
8935 if (CHECK_FLAG(p->af_flags[afi][safi],
8936 PEER_FLAG_REFLECTOR_CLIENT))
8937 vty_out(vty, " Route-Reflector Client\n");
8938 if (CHECK_FLAG(p->af_flags[afi][safi],
8939 PEER_FLAG_RSERVER_CLIENT))
8940 vty_out(vty, " Route-Server Client\n");
8941 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8942 vty_out(vty,
8943 " Inbound soft reconfiguration allowed\n");
8944
8945 if (CHECK_FLAG(p->af_flags[afi][safi],
8946 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8947 vty_out(vty,
8948 " Private AS numbers (all) replaced in updates to this neighbor\n");
8949 else if (CHECK_FLAG(p->af_flags[afi][safi],
8950 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8951 vty_out(vty,
8952 " Private AS numbers replaced in updates to this neighbor\n");
8953 else if (CHECK_FLAG(p->af_flags[afi][safi],
8954 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8955 vty_out(vty,
8956 " Private AS numbers (all) removed in updates to this neighbor\n");
8957 else if (CHECK_FLAG(p->af_flags[afi][safi],
8958 PEER_FLAG_REMOVE_PRIVATE_AS))
8959 vty_out(vty,
8960 " Private AS numbers removed in updates to this neighbor\n");
8961
8962 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8963 vty_out(vty, " %s\n",
8964 bgp_addpath_names(p->addpath_type[afi][safi])
8965 ->human_description);
8966
8967 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8968 vty_out(vty,
8969 " Override ASNs in outbound updates if aspath equals remote-as\n");
8970
8971 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8972 || CHECK_FLAG(p->af_flags[afi][safi],
8973 PEER_FLAG_FORCE_NEXTHOP_SELF))
8974 vty_out(vty, " NEXT_HOP is always this router\n");
8975 if (CHECK_FLAG(p->af_flags[afi][safi],
8976 PEER_FLAG_AS_PATH_UNCHANGED))
8977 vty_out(vty,
8978 " AS_PATH is propagated unchanged to this neighbor\n");
8979 if (CHECK_FLAG(p->af_flags[afi][safi],
8980 PEER_FLAG_NEXTHOP_UNCHANGED))
8981 vty_out(vty,
8982 " NEXT_HOP is propagated unchanged to this neighbor\n");
8983 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8984 vty_out(vty,
8985 " MED is propagated unchanged to this neighbor\n");
8986 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8987 || CHECK_FLAG(p->af_flags[afi][safi],
8988 PEER_FLAG_SEND_EXT_COMMUNITY)
8989 || CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8991 vty_out(vty,
8992 " Community attribute sent to this neighbor");
8993 if (CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_SEND_COMMUNITY)
8995 && CHECK_FLAG(p->af_flags[afi][safi],
8996 PEER_FLAG_SEND_EXT_COMMUNITY)
8997 && CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_SEND_LARGE_COMMUNITY))
8999 vty_out(vty, "(all)\n");
9000 else if (CHECK_FLAG(p->af_flags[afi][safi],
9001 PEER_FLAG_SEND_LARGE_COMMUNITY))
9002 vty_out(vty, "(large)\n");
9003 else if (CHECK_FLAG(p->af_flags[afi][safi],
9004 PEER_FLAG_SEND_EXT_COMMUNITY))
9005 vty_out(vty, "(extended)\n");
9006 else
9007 vty_out(vty, "(standard)\n");
9008 }
9009 if (CHECK_FLAG(p->af_flags[afi][safi],
9010 PEER_FLAG_DEFAULT_ORIGINATE)) {
9011 vty_out(vty, " Default information originate,");
9012
9013 if (p->default_rmap[afi][safi].name)
9014 vty_out(vty, " default route-map %s%s,",
9015 p->default_rmap[afi][safi].map ? "*"
9016 : "",
9017 p->default_rmap[afi][safi].name);
9018 if (paf && PAF_SUBGRP(paf)
9019 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9020 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9021 vty_out(vty, " default sent\n");
9022 else
9023 vty_out(vty, " default not sent\n");
9024 }
9025
9026 /* advertise-vni-all */
9027 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9028 if (is_evpn_enabled())
9029 vty_out(vty, " advertise-all-vni\n");
9030 }
9031
9032 if (filter->plist[FILTER_IN].name
9033 || filter->dlist[FILTER_IN].name
9034 || filter->aslist[FILTER_IN].name
9035 || filter->map[RMAP_IN].name)
9036 vty_out(vty, " Inbound path policy configured\n");
9037 if (filter->plist[FILTER_OUT].name
9038 || filter->dlist[FILTER_OUT].name
9039 || filter->aslist[FILTER_OUT].name
9040 || filter->map[RMAP_OUT].name || filter->usmap.name)
9041 vty_out(vty, " Outbound path policy configured\n");
9042
9043 /* prefix-list */
9044 if (filter->plist[FILTER_IN].name)
9045 vty_out(vty,
9046 " Incoming update prefix filter list is %s%s\n",
9047 filter->plist[FILTER_IN].plist ? "*" : "",
9048 filter->plist[FILTER_IN].name);
9049 if (filter->plist[FILTER_OUT].name)
9050 vty_out(vty,
9051 " Outgoing update prefix filter list is %s%s\n",
9052 filter->plist[FILTER_OUT].plist ? "*" : "",
9053 filter->plist[FILTER_OUT].name);
9054
9055 /* distribute-list */
9056 if (filter->dlist[FILTER_IN].name)
9057 vty_out(vty,
9058 " Incoming update network filter list is %s%s\n",
9059 filter->dlist[FILTER_IN].alist ? "*" : "",
9060 filter->dlist[FILTER_IN].name);
9061 if (filter->dlist[FILTER_OUT].name)
9062 vty_out(vty,
9063 " Outgoing update network filter list is %s%s\n",
9064 filter->dlist[FILTER_OUT].alist ? "*" : "",
9065 filter->dlist[FILTER_OUT].name);
9066
9067 /* filter-list. */
9068 if (filter->aslist[FILTER_IN].name)
9069 vty_out(vty,
9070 " Incoming update AS path filter list is %s%s\n",
9071 filter->aslist[FILTER_IN].aslist ? "*" : "",
9072 filter->aslist[FILTER_IN].name);
9073 if (filter->aslist[FILTER_OUT].name)
9074 vty_out(vty,
9075 " Outgoing update AS path filter list is %s%s\n",
9076 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9077 filter->aslist[FILTER_OUT].name);
9078
9079 /* route-map. */
9080 if (filter->map[RMAP_IN].name)
9081 vty_out(vty,
9082 " Route map for incoming advertisements is %s%s\n",
9083 filter->map[RMAP_IN].map ? "*" : "",
9084 filter->map[RMAP_IN].name);
9085 if (filter->map[RMAP_OUT].name)
9086 vty_out(vty,
9087 " Route map for outgoing advertisements is %s%s\n",
9088 filter->map[RMAP_OUT].map ? "*" : "",
9089 filter->map[RMAP_OUT].name);
9090
9091 /* ebgp-requires-policy (inbound) */
9092 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9093 && !bgp_inbound_policy_exists(p, filter))
9094 vty_out(vty,
9095 " Inbound updates discarded due to missing policy\n");
9096
9097 /* ebgp-requires-policy (outbound) */
9098 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9099 && !bgp_outbound_policy_exists(p, filter))
9100 vty_out(vty,
9101 " Outbound updates discarded due to missing policy\n");
9102
9103 /* unsuppress-map */
9104 if (filter->usmap.name)
9105 vty_out(vty,
9106 " Route map for selective unsuppress is %s%s\n",
9107 filter->usmap.map ? "*" : "",
9108 filter->usmap.name);
9109
9110 /* Receive prefix count */
9111 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9112
9113 /* Maximum prefix */
9114 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9115 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9116 p->pmax[afi][safi],
9117 CHECK_FLAG(p->af_flags[afi][safi],
9118 PEER_FLAG_MAX_PREFIX_WARNING)
9119 ? " (warning-only)"
9120 : "");
9121 vty_out(vty, " Threshold for warning message %d%%",
9122 p->pmax_threshold[afi][safi]);
9123 if (p->pmax_restart[afi][safi])
9124 vty_out(vty, ", restart interval %d min",
9125 p->pmax_restart[afi][safi]);
9126 vty_out(vty, "\n");
9127 }
9128
9129 vty_out(vty, "\n");
9130 }
9131 }
9132
9133 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9134 json_object *json)
9135 {
9136 struct bgp *bgp;
9137 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9138 char timebuf[BGP_UPTIME_LEN];
9139 char dn_flag[2];
9140 const char *subcode_str;
9141 const char *code_str;
9142 afi_t afi;
9143 safi_t safi;
9144 uint16_t i;
9145 uint8_t *msg;
9146 json_object *json_neigh = NULL;
9147 time_t epoch_tbuf;
9148
9149 bgp = p->bgp;
9150
9151 if (use_json)
9152 json_neigh = json_object_new_object();
9153
9154 memset(dn_flag, '\0', sizeof(dn_flag));
9155 if (!p->conf_if && peer_dynamic_neighbor(p))
9156 dn_flag[0] = '*';
9157
9158 if (!use_json) {
9159 if (p->conf_if) /* Configured interface name. */
9160 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9161 BGP_PEER_SU_UNSPEC(p)
9162 ? "None"
9163 : sockunion2str(&p->su, buf,
9164 SU_ADDRSTRLEN));
9165 else /* Configured IP address. */
9166 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9167 p->host);
9168 }
9169
9170 if (use_json) {
9171 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9172 json_object_string_add(json_neigh, "bgpNeighborAddr",
9173 "none");
9174 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9175 json_object_string_add(
9176 json_neigh, "bgpNeighborAddr",
9177 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9178
9179 json_object_int_add(json_neigh, "remoteAs", p->as);
9180
9181 if (p->change_local_as)
9182 json_object_int_add(json_neigh, "localAs",
9183 p->change_local_as);
9184 else
9185 json_object_int_add(json_neigh, "localAs", p->local_as);
9186
9187 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9188 json_object_boolean_true_add(json_neigh,
9189 "localAsNoPrepend");
9190
9191 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9192 json_object_boolean_true_add(json_neigh,
9193 "localAsReplaceAs");
9194 } else {
9195 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9196 || (p->as_type == AS_INTERNAL))
9197 vty_out(vty, "remote AS %u, ", p->as);
9198 else
9199 vty_out(vty, "remote AS Unspecified, ");
9200 vty_out(vty, "local AS %u%s%s, ",
9201 p->change_local_as ? p->change_local_as : p->local_as,
9202 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9203 ? " no-prepend"
9204 : "",
9205 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9206 ? " replace-as"
9207 : "");
9208 }
9209 /* peer type internal or confed-internal */
9210 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9211 if (use_json) {
9212 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9213 json_object_boolean_true_add(
9214 json_neigh, "nbrConfedInternalLink");
9215 else
9216 json_object_boolean_true_add(json_neigh,
9217 "nbrInternalLink");
9218 } else {
9219 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9220 vty_out(vty, "confed-internal link\n");
9221 else
9222 vty_out(vty, "internal link\n");
9223 }
9224 /* peer type external or confed-external */
9225 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9226 if (use_json) {
9227 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9228 json_object_boolean_true_add(
9229 json_neigh, "nbrConfedExternalLink");
9230 else
9231 json_object_boolean_true_add(json_neigh,
9232 "nbrExternalLink");
9233 } else {
9234 if (bgp_confederation_peers_check(bgp, p->as))
9235 vty_out(vty, "confed-external link\n");
9236 else
9237 vty_out(vty, "external link\n");
9238 }
9239 } else {
9240 if (use_json)
9241 json_object_boolean_true_add(json_neigh,
9242 "nbrUnspecifiedLink");
9243 else
9244 vty_out(vty, "unspecified link\n");
9245 }
9246
9247 /* Description. */
9248 if (p->desc) {
9249 if (use_json)
9250 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9251 else
9252 vty_out(vty, " Description: %s\n", p->desc);
9253 }
9254
9255 if (p->hostname) {
9256 if (use_json) {
9257 if (p->hostname)
9258 json_object_string_add(json_neigh, "hostname",
9259 p->hostname);
9260
9261 if (p->domainname)
9262 json_object_string_add(json_neigh, "domainname",
9263 p->domainname);
9264 } else {
9265 if (p->domainname && (p->domainname[0] != '\0'))
9266 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9267 p->domainname);
9268 else
9269 vty_out(vty, "Hostname: %s\n", p->hostname);
9270 }
9271 }
9272
9273 /* Peer-group */
9274 if (p->group) {
9275 if (use_json) {
9276 json_object_string_add(json_neigh, "peerGroup",
9277 p->group->name);
9278
9279 if (dn_flag[0]) {
9280 struct prefix prefix, *range = NULL;
9281
9282 sockunion2hostprefix(&(p->su), &prefix);
9283 range = peer_group_lookup_dynamic_neighbor_range(
9284 p->group, &prefix);
9285
9286 if (range) {
9287 prefix2str(range, buf1, sizeof(buf1));
9288 json_object_string_add(
9289 json_neigh,
9290 "peerSubnetRangeGroup", buf1);
9291 }
9292 }
9293 } else {
9294 vty_out(vty,
9295 " Member of peer-group %s for session parameters\n",
9296 p->group->name);
9297
9298 if (dn_flag[0]) {
9299 struct prefix prefix, *range = NULL;
9300
9301 sockunion2hostprefix(&(p->su), &prefix);
9302 range = peer_group_lookup_dynamic_neighbor_range(
9303 p->group, &prefix);
9304
9305 if (range) {
9306 prefix2str(range, buf1, sizeof(buf1));
9307 vty_out(vty,
9308 " Belongs to the subnet range group: %s\n",
9309 buf1);
9310 }
9311 }
9312 }
9313 }
9314
9315 if (use_json) {
9316 /* Administrative shutdown. */
9317 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9318 json_object_boolean_true_add(json_neigh,
9319 "adminShutDown");
9320
9321 /* BGP Version. */
9322 json_object_int_add(json_neigh, "bgpVersion", 4);
9323 json_object_string_add(
9324 json_neigh, "remoteRouterId",
9325 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9326 json_object_string_add(
9327 json_neigh, "localRouterId",
9328 inet_ntop(AF_INET, &bgp->router_id, buf1,
9329 sizeof(buf1)));
9330
9331 /* Confederation */
9332 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9333 && bgp_confederation_peers_check(bgp, p->as))
9334 json_object_boolean_true_add(json_neigh,
9335 "nbrCommonAdmin");
9336
9337 /* Status. */
9338 json_object_string_add(
9339 json_neigh, "bgpState",
9340 lookup_msg(bgp_status_msg, p->status, NULL));
9341
9342 if (p->status == Established) {
9343 time_t uptime;
9344
9345 uptime = bgp_clock();
9346 uptime -= p->uptime;
9347 epoch_tbuf = time(NULL) - uptime;
9348
9349 #if CONFDATE > 20200101
9350 CPP_NOTICE(
9351 "bgpTimerUp should be deprecated and can be removed now");
9352 #endif
9353 /*
9354 * bgpTimerUp was miliseconds that was accurate
9355 * up to 1 day, then the value returned
9356 * became garbage. So in order to provide
9357 * some level of backwards compatability,
9358 * we still provde the data, but now
9359 * we are returning the correct value
9360 * and also adding a new bgpTimerUpMsec
9361 * which will allow us to deprecate
9362 * this eventually
9363 */
9364 json_object_int_add(json_neigh, "bgpTimerUp",
9365 uptime * 1000);
9366 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9367 uptime * 1000);
9368 json_object_string_add(json_neigh, "bgpTimerUpString",
9369 peer_uptime(p->uptime, timebuf,
9370 BGP_UPTIME_LEN, 0,
9371 NULL));
9372 json_object_int_add(json_neigh,
9373 "bgpTimerUpEstablishedEpoch",
9374 epoch_tbuf);
9375 }
9376
9377 else if (p->status == Active) {
9378 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9379 json_object_string_add(json_neigh, "bgpStateIs",
9380 "passive");
9381 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9382 json_object_string_add(json_neigh, "bgpStateIs",
9383 "passiveNSF");
9384 }
9385
9386 /* read timer */
9387 time_t uptime;
9388 struct tm *tm;
9389
9390 uptime = bgp_clock();
9391 uptime -= p->readtime;
9392 tm = gmtime(&uptime);
9393 json_object_int_add(json_neigh, "bgpTimerLastRead",
9394 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9395 + (tm->tm_hour * 3600000));
9396
9397 uptime = bgp_clock();
9398 uptime -= p->last_write;
9399 tm = gmtime(&uptime);
9400 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9401 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9402 + (tm->tm_hour * 3600000));
9403
9404 uptime = bgp_clock();
9405 uptime -= p->update_time;
9406 tm = gmtime(&uptime);
9407 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9408 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9409 + (tm->tm_hour * 3600000));
9410
9411 /* Configured timer values. */
9412 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9413 p->v_holdtime * 1000);
9414 json_object_int_add(json_neigh,
9415 "bgpTimerKeepAliveIntervalMsecs",
9416 p->v_keepalive * 1000);
9417 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9418 json_object_int_add(json_neigh,
9419 "bgpTimerConfiguredHoldTimeMsecs",
9420 p->holdtime * 1000);
9421 json_object_int_add(
9422 json_neigh,
9423 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9424 p->keepalive * 1000);
9425 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9426 || (bgp->default_keepalive
9427 != BGP_DEFAULT_KEEPALIVE)) {
9428 json_object_int_add(json_neigh,
9429 "bgpTimerConfiguredHoldTimeMsecs",
9430 bgp->default_holdtime);
9431 json_object_int_add(
9432 json_neigh,
9433 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9434 bgp->default_keepalive);
9435 }
9436 } else {
9437 /* Administrative shutdown. */
9438 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9439 vty_out(vty, " Administratively shut down\n");
9440
9441 /* BGP Version. */
9442 vty_out(vty, " BGP version 4");
9443 vty_out(vty, ", remote router ID %s",
9444 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9445 vty_out(vty, ", local router ID %s\n",
9446 inet_ntop(AF_INET, &bgp->router_id, buf1,
9447 sizeof(buf1)));
9448
9449 /* Confederation */
9450 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9451 && bgp_confederation_peers_check(bgp, p->as))
9452 vty_out(vty,
9453 " Neighbor under common administration\n");
9454
9455 /* Status. */
9456 vty_out(vty, " BGP state = %s",
9457 lookup_msg(bgp_status_msg, p->status, NULL));
9458
9459 if (p->status == Established)
9460 vty_out(vty, ", up for %8s",
9461 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9462 0, NULL));
9463
9464 else if (p->status == Active) {
9465 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9466 vty_out(vty, " (passive)");
9467 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9468 vty_out(vty, " (NSF passive)");
9469 }
9470 vty_out(vty, "\n");
9471
9472 /* read timer */
9473 vty_out(vty, " Last read %s",
9474 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9475 NULL));
9476 vty_out(vty, ", Last write %s\n",
9477 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9478 NULL));
9479
9480 /* Configured timer values. */
9481 vty_out(vty,
9482 " Hold time is %d, keepalive interval is %d seconds\n",
9483 p->v_holdtime, p->v_keepalive);
9484 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9485 vty_out(vty, " Configured hold time is %d",
9486 p->holdtime);
9487 vty_out(vty, ", keepalive interval is %d seconds\n",
9488 p->keepalive);
9489 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9490 || (bgp->default_keepalive
9491 != BGP_DEFAULT_KEEPALIVE)) {
9492 vty_out(vty, " Configured hold time is %d",
9493 bgp->default_holdtime);
9494 vty_out(vty, ", keepalive interval is %d seconds\n",
9495 bgp->default_keepalive);
9496 }
9497 }
9498 /* Capability. */
9499 if (p->status == Established) {
9500 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9501 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9502 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9503 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9504 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9505 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9506 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9507 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9508 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9509 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9510 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9511 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9512 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9513 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9514 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9515 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9516 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9517 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9518 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9519 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9520 if (use_json) {
9521 json_object *json_cap = NULL;
9522
9523 json_cap = json_object_new_object();
9524
9525 /* AS4 */
9526 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9527 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9528 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9529 && CHECK_FLAG(p->cap,
9530 PEER_CAP_AS4_RCV))
9531 json_object_string_add(
9532 json_cap, "4byteAs",
9533 "advertisedAndReceived");
9534 else if (CHECK_FLAG(p->cap,
9535 PEER_CAP_AS4_ADV))
9536 json_object_string_add(
9537 json_cap, "4byteAs",
9538 "advertised");
9539 else if (CHECK_FLAG(p->cap,
9540 PEER_CAP_AS4_RCV))
9541 json_object_string_add(
9542 json_cap, "4byteAs",
9543 "received");
9544 }
9545
9546 /* AddPath */
9547 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9548 || CHECK_FLAG(p->cap,
9549 PEER_CAP_ADDPATH_ADV)) {
9550 json_object *json_add = NULL;
9551 const char *print_store;
9552
9553 json_add = json_object_new_object();
9554
9555 FOREACH_AFI_SAFI (afi, safi) {
9556 json_object *json_sub = NULL;
9557 json_sub =
9558 json_object_new_object();
9559 print_store = afi_safi_print(
9560 afi, safi);
9561
9562 if (CHECK_FLAG(
9563 p->af_cap[afi]
9564 [safi],
9565 PEER_CAP_ADDPATH_AF_TX_ADV)
9566 || CHECK_FLAG(
9567 p->af_cap[afi]
9568 [safi],
9569 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9570 if (CHECK_FLAG(
9571 p->af_cap
9572 [afi]
9573 [safi],
9574 PEER_CAP_ADDPATH_AF_TX_ADV)
9575 && CHECK_FLAG(
9576 p->af_cap
9577 [afi]
9578 [safi],
9579 PEER_CAP_ADDPATH_AF_TX_RCV))
9580 json_object_boolean_true_add(
9581 json_sub,
9582 "txAdvertisedAndReceived");
9583 else if (
9584 CHECK_FLAG(
9585 p->af_cap
9586 [afi]
9587 [safi],
9588 PEER_CAP_ADDPATH_AF_TX_ADV))
9589 json_object_boolean_true_add(
9590 json_sub,
9591 "txAdvertised");
9592 else if (
9593 CHECK_FLAG(
9594 p->af_cap
9595 [afi]
9596 [safi],
9597 PEER_CAP_ADDPATH_AF_TX_RCV))
9598 json_object_boolean_true_add(
9599 json_sub,
9600 "txReceived");
9601 }
9602
9603 if (CHECK_FLAG(
9604 p->af_cap[afi]
9605 [safi],
9606 PEER_CAP_ADDPATH_AF_RX_ADV)
9607 || CHECK_FLAG(
9608 p->af_cap[afi]
9609 [safi],
9610 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9611 if (CHECK_FLAG(
9612 p->af_cap
9613 [afi]
9614 [safi],
9615 PEER_CAP_ADDPATH_AF_RX_ADV)
9616 && CHECK_FLAG(
9617 p->af_cap
9618 [afi]
9619 [safi],
9620 PEER_CAP_ADDPATH_AF_RX_RCV))
9621 json_object_boolean_true_add(
9622 json_sub,
9623 "rxAdvertisedAndReceived");
9624 else if (
9625 CHECK_FLAG(
9626 p->af_cap
9627 [afi]
9628 [safi],
9629 PEER_CAP_ADDPATH_AF_RX_ADV))
9630 json_object_boolean_true_add(
9631 json_sub,
9632 "rxAdvertised");
9633 else if (
9634 CHECK_FLAG(
9635 p->af_cap
9636 [afi]
9637 [safi],
9638 PEER_CAP_ADDPATH_AF_RX_RCV))
9639 json_object_boolean_true_add(
9640 json_sub,
9641 "rxReceived");
9642 }
9643
9644 if (CHECK_FLAG(
9645 p->af_cap[afi]
9646 [safi],
9647 PEER_CAP_ADDPATH_AF_TX_ADV)
9648 || CHECK_FLAG(
9649 p->af_cap[afi]
9650 [safi],
9651 PEER_CAP_ADDPATH_AF_TX_RCV)
9652 || CHECK_FLAG(
9653 p->af_cap[afi]
9654 [safi],
9655 PEER_CAP_ADDPATH_AF_RX_ADV)
9656 || CHECK_FLAG(
9657 p->af_cap[afi]
9658 [safi],
9659 PEER_CAP_ADDPATH_AF_RX_RCV))
9660 json_object_object_add(
9661 json_add,
9662 print_store,
9663 json_sub);
9664 else
9665 json_object_free(
9666 json_sub);
9667 }
9668
9669 json_object_object_add(
9670 json_cap, "addPath", json_add);
9671 }
9672
9673 /* Dynamic */
9674 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9675 || CHECK_FLAG(p->cap,
9676 PEER_CAP_DYNAMIC_ADV)) {
9677 if (CHECK_FLAG(p->cap,
9678 PEER_CAP_DYNAMIC_ADV)
9679 && CHECK_FLAG(p->cap,
9680 PEER_CAP_DYNAMIC_RCV))
9681 json_object_string_add(
9682 json_cap, "dynamic",
9683 "advertisedAndReceived");
9684 else if (CHECK_FLAG(
9685 p->cap,
9686 PEER_CAP_DYNAMIC_ADV))
9687 json_object_string_add(
9688 json_cap, "dynamic",
9689 "advertised");
9690 else if (CHECK_FLAG(
9691 p->cap,
9692 PEER_CAP_DYNAMIC_RCV))
9693 json_object_string_add(
9694 json_cap, "dynamic",
9695 "received");
9696 }
9697
9698 /* Extended nexthop */
9699 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9700 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9701 json_object *json_nxt = NULL;
9702 const char *print_store;
9703
9704
9705 if (CHECK_FLAG(p->cap,
9706 PEER_CAP_ENHE_ADV)
9707 && CHECK_FLAG(p->cap,
9708 PEER_CAP_ENHE_RCV))
9709 json_object_string_add(
9710 json_cap,
9711 "extendedNexthop",
9712 "advertisedAndReceived");
9713 else if (CHECK_FLAG(p->cap,
9714 PEER_CAP_ENHE_ADV))
9715 json_object_string_add(
9716 json_cap,
9717 "extendedNexthop",
9718 "advertised");
9719 else if (CHECK_FLAG(p->cap,
9720 PEER_CAP_ENHE_RCV))
9721 json_object_string_add(
9722 json_cap,
9723 "extendedNexthop",
9724 "received");
9725
9726 if (CHECK_FLAG(p->cap,
9727 PEER_CAP_ENHE_RCV)) {
9728 json_nxt =
9729 json_object_new_object();
9730
9731 for (safi = SAFI_UNICAST;
9732 safi < SAFI_MAX; safi++) {
9733 if (CHECK_FLAG(
9734 p->af_cap
9735 [AFI_IP]
9736 [safi],
9737 PEER_CAP_ENHE_AF_RCV)) {
9738 print_store = afi_safi_print(
9739 AFI_IP,
9740 safi);
9741 json_object_string_add(
9742 json_nxt,
9743 print_store,
9744 "recieved"); /* misspelled for compatibility */
9745 }
9746 }
9747 json_object_object_add(
9748 json_cap,
9749 "extendedNexthopFamililesByPeer",
9750 json_nxt);
9751 }
9752 }
9753
9754 /* Route Refresh */
9755 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9756 || CHECK_FLAG(p->cap,
9757 PEER_CAP_REFRESH_NEW_RCV)
9758 || CHECK_FLAG(p->cap,
9759 PEER_CAP_REFRESH_OLD_RCV)) {
9760 if (CHECK_FLAG(p->cap,
9761 PEER_CAP_REFRESH_ADV)
9762 && (CHECK_FLAG(
9763 p->cap,
9764 PEER_CAP_REFRESH_NEW_RCV)
9765 || CHECK_FLAG(
9766 p->cap,
9767 PEER_CAP_REFRESH_OLD_RCV))) {
9768 if (CHECK_FLAG(
9769 p->cap,
9770 PEER_CAP_REFRESH_OLD_RCV)
9771 && CHECK_FLAG(
9772 p->cap,
9773 PEER_CAP_REFRESH_NEW_RCV))
9774 json_object_string_add(
9775 json_cap,
9776 "routeRefresh",
9777 "advertisedAndReceivedOldNew");
9778 else {
9779 if (CHECK_FLAG(
9780 p->cap,
9781 PEER_CAP_REFRESH_OLD_RCV))
9782 json_object_string_add(
9783 json_cap,
9784 "routeRefresh",
9785 "advertisedAndReceivedOld");
9786 else
9787 json_object_string_add(
9788 json_cap,
9789 "routeRefresh",
9790 "advertisedAndReceivedNew");
9791 }
9792 } else if (
9793 CHECK_FLAG(
9794 p->cap,
9795 PEER_CAP_REFRESH_ADV))
9796 json_object_string_add(
9797 json_cap,
9798 "routeRefresh",
9799 "advertised");
9800 else if (
9801 CHECK_FLAG(
9802 p->cap,
9803 PEER_CAP_REFRESH_NEW_RCV)
9804 || CHECK_FLAG(
9805 p->cap,
9806 PEER_CAP_REFRESH_OLD_RCV))
9807 json_object_string_add(
9808 json_cap,
9809 "routeRefresh",
9810 "received");
9811 }
9812
9813 /* Multiprotocol Extensions */
9814 json_object *json_multi = NULL;
9815 json_multi = json_object_new_object();
9816
9817 FOREACH_AFI_SAFI (afi, safi) {
9818 if (p->afc_adv[afi][safi]
9819 || p->afc_recv[afi][safi]) {
9820 json_object *json_exten = NULL;
9821 json_exten =
9822 json_object_new_object();
9823
9824 if (p->afc_adv[afi][safi]
9825 && p->afc_recv[afi][safi])
9826 json_object_boolean_true_add(
9827 json_exten,
9828 "advertisedAndReceived");
9829 else if (p->afc_adv[afi][safi])
9830 json_object_boolean_true_add(
9831 json_exten,
9832 "advertised");
9833 else if (p->afc_recv[afi][safi])
9834 json_object_boolean_true_add(
9835 json_exten,
9836 "received");
9837
9838 json_object_object_add(
9839 json_multi,
9840 afi_safi_print(afi,
9841 safi),
9842 json_exten);
9843 }
9844 }
9845 json_object_object_add(
9846 json_cap, "multiprotocolExtensions",
9847 json_multi);
9848
9849 /* Hostname capabilities */
9850 json_object *json_hname = NULL;
9851
9852 json_hname = json_object_new_object();
9853
9854 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9855 json_object_string_add(
9856 json_hname, "advHostName",
9857 bgp->peer_self->hostname
9858 ? bgp->peer_self
9859 ->hostname
9860 : "n/a");
9861 json_object_string_add(
9862 json_hname, "advDomainName",
9863 bgp->peer_self->domainname
9864 ? bgp->peer_self
9865 ->domainname
9866 : "n/a");
9867 }
9868
9869
9870 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9871 json_object_string_add(
9872 json_hname, "rcvHostName",
9873 p->hostname ? p->hostname
9874 : "n/a");
9875 json_object_string_add(
9876 json_hname, "rcvDomainName",
9877 p->domainname ? p->domainname
9878 : "n/a");
9879 }
9880
9881 json_object_object_add(json_cap, "hostName",
9882 json_hname);
9883
9884 /* Gracefull Restart */
9885 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9886 || CHECK_FLAG(p->cap,
9887 PEER_CAP_RESTART_ADV)) {
9888 if (CHECK_FLAG(p->cap,
9889 PEER_CAP_RESTART_ADV)
9890 && CHECK_FLAG(p->cap,
9891 PEER_CAP_RESTART_RCV))
9892 json_object_string_add(
9893 json_cap,
9894 "gracefulRestart",
9895 "advertisedAndReceived");
9896 else if (CHECK_FLAG(
9897 p->cap,
9898 PEER_CAP_RESTART_ADV))
9899 json_object_string_add(
9900 json_cap,
9901 "gracefulRestartCapability",
9902 "advertised");
9903 else if (CHECK_FLAG(
9904 p->cap,
9905 PEER_CAP_RESTART_RCV))
9906 json_object_string_add(
9907 json_cap,
9908 "gracefulRestartCapability",
9909 "received");
9910
9911 if (CHECK_FLAG(p->cap,
9912 PEER_CAP_RESTART_RCV)) {
9913 int restart_af_count = 0;
9914 json_object *json_restart =
9915 NULL;
9916 json_restart =
9917 json_object_new_object();
9918
9919 json_object_int_add(
9920 json_cap,
9921 "gracefulRestartRemoteTimerMsecs",
9922 p->v_gr_restart * 1000);
9923
9924 FOREACH_AFI_SAFI (afi, safi) {
9925 if (CHECK_FLAG(
9926 p->af_cap
9927 [afi]
9928 [safi],
9929 PEER_CAP_RESTART_AF_RCV)) {
9930 json_object *
9931 json_sub =
9932 NULL;
9933 json_sub =
9934 json_object_new_object();
9935
9936 if (CHECK_FLAG(
9937 p->af_cap
9938 [afi]
9939 [safi],
9940 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9941 json_object_boolean_true_add(
9942 json_sub,
9943 "preserved");
9944 restart_af_count++;
9945 json_object_object_add(
9946 json_restart,
9947 afi_safi_print(
9948 afi,
9949 safi),
9950 json_sub);
9951 }
9952 }
9953 if (!restart_af_count) {
9954 json_object_string_add(
9955 json_cap,
9956 "addressFamiliesByPeer",
9957 "none");
9958 json_object_free(
9959 json_restart);
9960 } else
9961 json_object_object_add(
9962 json_cap,
9963 "addressFamiliesByPeer",
9964 json_restart);
9965 }
9966 }
9967 json_object_object_add(json_neigh,
9968 "neighborCapabilities",
9969 json_cap);
9970 } else {
9971 vty_out(vty, " Neighbor capabilities:\n");
9972
9973 /* AS4 */
9974 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9975 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9976 vty_out(vty, " 4 Byte AS:");
9977 if (CHECK_FLAG(p->cap,
9978 PEER_CAP_AS4_ADV))
9979 vty_out(vty, " advertised");
9980 if (CHECK_FLAG(p->cap,
9981 PEER_CAP_AS4_RCV))
9982 vty_out(vty, " %sreceived",
9983 CHECK_FLAG(
9984 p->cap,
9985 PEER_CAP_AS4_ADV)
9986 ? "and "
9987 : "");
9988 vty_out(vty, "\n");
9989 }
9990
9991 /* AddPath */
9992 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9993 || CHECK_FLAG(p->cap,
9994 PEER_CAP_ADDPATH_ADV)) {
9995 vty_out(vty, " AddPath:\n");
9996
9997 FOREACH_AFI_SAFI (afi, safi) {
9998 if (CHECK_FLAG(
9999 p->af_cap[afi]
10000 [safi],
10001 PEER_CAP_ADDPATH_AF_TX_ADV)
10002 || CHECK_FLAG(
10003 p->af_cap[afi]
10004 [safi],
10005 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10006 vty_out(vty,
10007 " %s: TX ",
10008 afi_safi_print(
10009 afi,
10010 safi));
10011
10012 if (CHECK_FLAG(
10013 p->af_cap
10014 [afi]
10015 [safi],
10016 PEER_CAP_ADDPATH_AF_TX_ADV))
10017 vty_out(vty,
10018 "advertised %s",
10019 afi_safi_print(
10020 afi,
10021 safi));
10022
10023 if (CHECK_FLAG(
10024 p->af_cap
10025 [afi]
10026 [safi],
10027 PEER_CAP_ADDPATH_AF_TX_RCV))
10028 vty_out(vty,
10029 "%sreceived",
10030 CHECK_FLAG(
10031 p->af_cap
10032 [afi]
10033 [safi],
10034 PEER_CAP_ADDPATH_AF_TX_ADV)
10035 ? " and "
10036 : "");
10037
10038 vty_out(vty, "\n");
10039 }
10040
10041 if (CHECK_FLAG(
10042 p->af_cap[afi]
10043 [safi],
10044 PEER_CAP_ADDPATH_AF_RX_ADV)
10045 || CHECK_FLAG(
10046 p->af_cap[afi]
10047 [safi],
10048 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10049 vty_out(vty,
10050 " %s: RX ",
10051 afi_safi_print(
10052 afi,
10053 safi));
10054
10055 if (CHECK_FLAG(
10056 p->af_cap
10057 [afi]
10058 [safi],
10059 PEER_CAP_ADDPATH_AF_RX_ADV))
10060 vty_out(vty,
10061 "advertised %s",
10062 afi_safi_print(
10063 afi,
10064 safi));
10065
10066 if (CHECK_FLAG(
10067 p->af_cap
10068 [afi]
10069 [safi],
10070 PEER_CAP_ADDPATH_AF_RX_RCV))
10071 vty_out(vty,
10072 "%sreceived",
10073 CHECK_FLAG(
10074 p->af_cap
10075 [afi]
10076 [safi],
10077 PEER_CAP_ADDPATH_AF_RX_ADV)
10078 ? " and "
10079 : "");
10080
10081 vty_out(vty, "\n");
10082 }
10083 }
10084 }
10085
10086 /* Dynamic */
10087 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10088 || CHECK_FLAG(p->cap,
10089 PEER_CAP_DYNAMIC_ADV)) {
10090 vty_out(vty, " Dynamic:");
10091 if (CHECK_FLAG(p->cap,
10092 PEER_CAP_DYNAMIC_ADV))
10093 vty_out(vty, " advertised");
10094 if (CHECK_FLAG(p->cap,
10095 PEER_CAP_DYNAMIC_RCV))
10096 vty_out(vty, " %sreceived",
10097 CHECK_FLAG(
10098 p->cap,
10099 PEER_CAP_DYNAMIC_ADV)
10100 ? "and "
10101 : "");
10102 vty_out(vty, "\n");
10103 }
10104
10105 /* Extended nexthop */
10106 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10107 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10108 vty_out(vty, " Extended nexthop:");
10109 if (CHECK_FLAG(p->cap,
10110 PEER_CAP_ENHE_ADV))
10111 vty_out(vty, " advertised");
10112 if (CHECK_FLAG(p->cap,
10113 PEER_CAP_ENHE_RCV))
10114 vty_out(vty, " %sreceived",
10115 CHECK_FLAG(
10116 p->cap,
10117 PEER_CAP_ENHE_ADV)
10118 ? "and "
10119 : "");
10120 vty_out(vty, "\n");
10121
10122 if (CHECK_FLAG(p->cap,
10123 PEER_CAP_ENHE_RCV)) {
10124 vty_out(vty,
10125 " Address families by peer:\n ");
10126 for (safi = SAFI_UNICAST;
10127 safi < SAFI_MAX; safi++)
10128 if (CHECK_FLAG(
10129 p->af_cap
10130 [AFI_IP]
10131 [safi],
10132 PEER_CAP_ENHE_AF_RCV))
10133 vty_out(vty,
10134 " %s\n",
10135 afi_safi_print(
10136 AFI_IP,
10137 safi));
10138 }
10139 }
10140
10141 /* Route Refresh */
10142 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10143 || CHECK_FLAG(p->cap,
10144 PEER_CAP_REFRESH_NEW_RCV)
10145 || CHECK_FLAG(p->cap,
10146 PEER_CAP_REFRESH_OLD_RCV)) {
10147 vty_out(vty, " Route refresh:");
10148 if (CHECK_FLAG(p->cap,
10149 PEER_CAP_REFRESH_ADV))
10150 vty_out(vty, " advertised");
10151 if (CHECK_FLAG(p->cap,
10152 PEER_CAP_REFRESH_NEW_RCV)
10153 || CHECK_FLAG(
10154 p->cap,
10155 PEER_CAP_REFRESH_OLD_RCV))
10156 vty_out(vty, " %sreceived(%s)",
10157 CHECK_FLAG(
10158 p->cap,
10159 PEER_CAP_REFRESH_ADV)
10160 ? "and "
10161 : "",
10162 (CHECK_FLAG(
10163 p->cap,
10164 PEER_CAP_REFRESH_OLD_RCV)
10165 && CHECK_FLAG(
10166 p->cap,
10167 PEER_CAP_REFRESH_NEW_RCV))
10168 ? "old & new"
10169 : CHECK_FLAG(
10170 p->cap,
10171 PEER_CAP_REFRESH_OLD_RCV)
10172 ? "old"
10173 : "new");
10174
10175 vty_out(vty, "\n");
10176 }
10177
10178 /* Multiprotocol Extensions */
10179 FOREACH_AFI_SAFI (afi, safi)
10180 if (p->afc_adv[afi][safi]
10181 || p->afc_recv[afi][safi]) {
10182 vty_out(vty,
10183 " Address Family %s:",
10184 afi_safi_print(afi,
10185 safi));
10186 if (p->afc_adv[afi][safi])
10187 vty_out(vty,
10188 " advertised");
10189 if (p->afc_recv[afi][safi])
10190 vty_out(vty,
10191 " %sreceived",
10192 p->afc_adv[afi]
10193 [safi]
10194 ? "and "
10195 : "");
10196 vty_out(vty, "\n");
10197 }
10198
10199 /* Hostname capability */
10200 vty_out(vty, " Hostname Capability:");
10201
10202 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10203 vty_out(vty,
10204 " advertised (name: %s,domain name: %s)",
10205 bgp->peer_self->hostname
10206 ? bgp->peer_self
10207 ->hostname
10208 : "n/a",
10209 bgp->peer_self->domainname
10210 ? bgp->peer_self
10211 ->domainname
10212 : "n/a");
10213 } else {
10214 vty_out(vty, " not advertised");
10215 }
10216
10217 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10218 vty_out(vty,
10219 " received (name: %s,domain name: %s)",
10220 p->hostname ? p->hostname
10221 : "n/a",
10222 p->domainname ? p->domainname
10223 : "n/a");
10224 } else {
10225 vty_out(vty, " not received");
10226 }
10227
10228 vty_out(vty, "\n");
10229
10230 /* Gracefull Restart */
10231 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10232 || CHECK_FLAG(p->cap,
10233 PEER_CAP_RESTART_ADV)) {
10234 vty_out(vty,
10235 " Graceful Restart Capabilty:");
10236 if (CHECK_FLAG(p->cap,
10237 PEER_CAP_RESTART_ADV))
10238 vty_out(vty, " advertised");
10239 if (CHECK_FLAG(p->cap,
10240 PEER_CAP_RESTART_RCV))
10241 vty_out(vty, " %sreceived",
10242 CHECK_FLAG(
10243 p->cap,
10244 PEER_CAP_RESTART_ADV)
10245 ? "and "
10246 : "");
10247 vty_out(vty, "\n");
10248
10249 if (CHECK_FLAG(p->cap,
10250 PEER_CAP_RESTART_RCV)) {
10251 int restart_af_count = 0;
10252
10253 vty_out(vty,
10254 " Remote Restart timer is %d seconds\n",
10255 p->v_gr_restart);
10256 vty_out(vty,
10257 " Address families by peer:\n ");
10258
10259 FOREACH_AFI_SAFI (afi, safi)
10260 if (CHECK_FLAG(
10261 p->af_cap
10262 [afi]
10263 [safi],
10264 PEER_CAP_RESTART_AF_RCV)) {
10265 vty_out(vty,
10266 "%s%s(%s)",
10267 restart_af_count
10268 ? ", "
10269 : "",
10270 afi_safi_print(
10271 afi,
10272 safi),
10273 CHECK_FLAG(
10274 p->af_cap
10275 [afi]
10276 [safi],
10277 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10278 ? "preserved"
10279 : "not preserved");
10280 restart_af_count++;
10281 }
10282 if (!restart_af_count)
10283 vty_out(vty, "none");
10284 vty_out(vty, "\n");
10285 }
10286 }
10287 }
10288 }
10289 }
10290
10291 /* graceful restart information */
10292 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10293 || p->t_gr_stale) {
10294 json_object *json_grace = NULL;
10295 json_object *json_grace_send = NULL;
10296 json_object *json_grace_recv = NULL;
10297 int eor_send_af_count = 0;
10298 int eor_receive_af_count = 0;
10299
10300 if (use_json) {
10301 json_grace = json_object_new_object();
10302 json_grace_send = json_object_new_object();
10303 json_grace_recv = json_object_new_object();
10304
10305 if (p->status == Established) {
10306 FOREACH_AFI_SAFI (afi, safi) {
10307 if (CHECK_FLAG(p->af_sflags[afi][safi],
10308 PEER_STATUS_EOR_SEND)) {
10309 json_object_boolean_true_add(
10310 json_grace_send,
10311 afi_safi_print(afi,
10312 safi));
10313 eor_send_af_count++;
10314 }
10315 }
10316 FOREACH_AFI_SAFI (afi, safi) {
10317 if (CHECK_FLAG(
10318 p->af_sflags[afi][safi],
10319 PEER_STATUS_EOR_RECEIVED)) {
10320 json_object_boolean_true_add(
10321 json_grace_recv,
10322 afi_safi_print(afi,
10323 safi));
10324 eor_receive_af_count++;
10325 }
10326 }
10327 }
10328
10329 json_object_object_add(json_grace, "endOfRibSend",
10330 json_grace_send);
10331 json_object_object_add(json_grace, "endOfRibRecv",
10332 json_grace_recv);
10333
10334 if (p->t_gr_restart)
10335 json_object_int_add(json_grace,
10336 "gracefulRestartTimerMsecs",
10337 thread_timer_remain_second(
10338 p->t_gr_restart)
10339 * 1000);
10340
10341 if (p->t_gr_stale)
10342 json_object_int_add(
10343 json_grace,
10344 "gracefulStalepathTimerMsecs",
10345 thread_timer_remain_second(
10346 p->t_gr_stale)
10347 * 1000);
10348
10349 json_object_object_add(
10350 json_neigh, "gracefulRestartInfo", json_grace);
10351 } else {
10352 vty_out(vty, " Graceful restart information:\n");
10353 if (p->status == Established) {
10354 vty_out(vty, " End-of-RIB send: ");
10355 FOREACH_AFI_SAFI (afi, safi) {
10356 if (CHECK_FLAG(p->af_sflags[afi][safi],
10357 PEER_STATUS_EOR_SEND)) {
10358 vty_out(vty, "%s%s",
10359 eor_send_af_count ? ", "
10360 : "",
10361 afi_safi_print(afi,
10362 safi));
10363 eor_send_af_count++;
10364 }
10365 }
10366 vty_out(vty, "\n");
10367 vty_out(vty, " End-of-RIB received: ");
10368 FOREACH_AFI_SAFI (afi, safi) {
10369 if (CHECK_FLAG(
10370 p->af_sflags[afi][safi],
10371 PEER_STATUS_EOR_RECEIVED)) {
10372 vty_out(vty, "%s%s",
10373 eor_receive_af_count
10374 ? ", "
10375 : "",
10376 afi_safi_print(afi,
10377 safi));
10378 eor_receive_af_count++;
10379 }
10380 }
10381 vty_out(vty, "\n");
10382 }
10383
10384 if (p->t_gr_restart)
10385 vty_out(vty,
10386 " The remaining time of restart timer is %ld\n",
10387 thread_timer_remain_second(
10388 p->t_gr_restart));
10389
10390 if (p->t_gr_stale)
10391 vty_out(vty,
10392 " The remaining time of stalepath timer is %ld\n",
10393 thread_timer_remain_second(
10394 p->t_gr_stale));
10395 }
10396 }
10397 if (use_json) {
10398 json_object *json_stat = NULL;
10399 json_stat = json_object_new_object();
10400 /* Packet counts. */
10401 json_object_int_add(json_stat, "depthInq", 0);
10402 json_object_int_add(json_stat, "depthOutq",
10403 (unsigned long)p->obuf->count);
10404 json_object_int_add(json_stat, "opensSent",
10405 atomic_load_explicit(&p->open_out,
10406 memory_order_relaxed));
10407 json_object_int_add(json_stat, "opensRecv",
10408 atomic_load_explicit(&p->open_in,
10409 memory_order_relaxed));
10410 json_object_int_add(json_stat, "notificationsSent",
10411 atomic_load_explicit(&p->notify_out,
10412 memory_order_relaxed));
10413 json_object_int_add(json_stat, "notificationsRecv",
10414 atomic_load_explicit(&p->notify_in,
10415 memory_order_relaxed));
10416 json_object_int_add(json_stat, "updatesSent",
10417 atomic_load_explicit(&p->update_out,
10418 memory_order_relaxed));
10419 json_object_int_add(json_stat, "updatesRecv",
10420 atomic_load_explicit(&p->update_in,
10421 memory_order_relaxed));
10422 json_object_int_add(json_stat, "keepalivesSent",
10423 atomic_load_explicit(&p->keepalive_out,
10424 memory_order_relaxed));
10425 json_object_int_add(json_stat, "keepalivesRecv",
10426 atomic_load_explicit(&p->keepalive_in,
10427 memory_order_relaxed));
10428 json_object_int_add(json_stat, "routeRefreshSent",
10429 atomic_load_explicit(&p->refresh_out,
10430 memory_order_relaxed));
10431 json_object_int_add(json_stat, "routeRefreshRecv",
10432 atomic_load_explicit(&p->refresh_in,
10433 memory_order_relaxed));
10434 json_object_int_add(json_stat, "capabilitySent",
10435 atomic_load_explicit(&p->dynamic_cap_out,
10436 memory_order_relaxed));
10437 json_object_int_add(json_stat, "capabilityRecv",
10438 atomic_load_explicit(&p->dynamic_cap_in,
10439 memory_order_relaxed));
10440 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10441 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10442 json_object_object_add(json_neigh, "messageStats", json_stat);
10443 } else {
10444 /* Packet counts. */
10445 vty_out(vty, " Message statistics:\n");
10446 vty_out(vty, " Inq depth is 0\n");
10447 vty_out(vty, " Outq depth is %lu\n",
10448 (unsigned long)p->obuf->count);
10449 vty_out(vty, " Sent Rcvd\n");
10450 vty_out(vty, " Opens: %10d %10d\n",
10451 atomic_load_explicit(&p->open_out,
10452 memory_order_relaxed),
10453 atomic_load_explicit(&p->open_in,
10454 memory_order_relaxed));
10455 vty_out(vty, " Notifications: %10d %10d\n",
10456 atomic_load_explicit(&p->notify_out,
10457 memory_order_relaxed),
10458 atomic_load_explicit(&p->notify_in,
10459 memory_order_relaxed));
10460 vty_out(vty, " Updates: %10d %10d\n",
10461 atomic_load_explicit(&p->update_out,
10462 memory_order_relaxed),
10463 atomic_load_explicit(&p->update_in,
10464 memory_order_relaxed));
10465 vty_out(vty, " Keepalives: %10d %10d\n",
10466 atomic_load_explicit(&p->keepalive_out,
10467 memory_order_relaxed),
10468 atomic_load_explicit(&p->keepalive_in,
10469 memory_order_relaxed));
10470 vty_out(vty, " Route Refresh: %10d %10d\n",
10471 atomic_load_explicit(&p->refresh_out,
10472 memory_order_relaxed),
10473 atomic_load_explicit(&p->refresh_in,
10474 memory_order_relaxed));
10475 vty_out(vty, " Capability: %10d %10d\n",
10476 atomic_load_explicit(&p->dynamic_cap_out,
10477 memory_order_relaxed),
10478 atomic_load_explicit(&p->dynamic_cap_in,
10479 memory_order_relaxed));
10480 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10481 PEER_TOTAL_RX(p));
10482 }
10483
10484 if (use_json) {
10485 /* advertisement-interval */
10486 json_object_int_add(json_neigh,
10487 "minBtwnAdvertisementRunsTimerMsecs",
10488 p->v_routeadv * 1000);
10489
10490 /* Update-source. */
10491 if (p->update_if || p->update_source) {
10492 if (p->update_if)
10493 json_object_string_add(json_neigh,
10494 "updateSource",
10495 p->update_if);
10496 else if (p->update_source)
10497 json_object_string_add(
10498 json_neigh, "updateSource",
10499 sockunion2str(p->update_source, buf1,
10500 SU_ADDRSTRLEN));
10501 }
10502 } else {
10503 /* advertisement-interval */
10504 vty_out(vty,
10505 " Minimum time between advertisement runs is %d seconds\n",
10506 p->v_routeadv);
10507
10508 /* Update-source. */
10509 if (p->update_if || p->update_source) {
10510 vty_out(vty, " Update source is ");
10511 if (p->update_if)
10512 vty_out(vty, "%s", p->update_if);
10513 else if (p->update_source)
10514 vty_out(vty, "%s",
10515 sockunion2str(p->update_source, buf1,
10516 SU_ADDRSTRLEN));
10517 vty_out(vty, "\n");
10518 }
10519
10520 vty_out(vty, "\n");
10521 }
10522
10523 /* Address Family Information */
10524 json_object *json_hold = NULL;
10525
10526 if (use_json)
10527 json_hold = json_object_new_object();
10528
10529 FOREACH_AFI_SAFI (afi, safi)
10530 if (p->afc[afi][safi])
10531 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10532 json_hold);
10533
10534 if (use_json) {
10535 json_object_object_add(json_neigh, "addressFamilyInfo",
10536 json_hold);
10537 json_object_int_add(json_neigh, "connectionsEstablished",
10538 p->established);
10539 json_object_int_add(json_neigh, "connectionsDropped",
10540 p->dropped);
10541 } else
10542 vty_out(vty, " Connections established %d; dropped %d\n",
10543 p->established, p->dropped);
10544
10545 if (!p->last_reset) {
10546 if (use_json)
10547 json_object_string_add(json_neigh, "lastReset",
10548 "never");
10549 else
10550 vty_out(vty, " Last reset never\n");
10551 } else {
10552 if (use_json) {
10553 time_t uptime;
10554 struct tm *tm;
10555
10556 uptime = bgp_clock();
10557 uptime -= p->resettime;
10558 tm = gmtime(&uptime);
10559 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10560 (tm->tm_sec * 1000)
10561 + (tm->tm_min * 60000)
10562 + (tm->tm_hour * 3600000));
10563 json_object_string_add(
10564 json_neigh, "lastResetDueTo",
10565 peer_down_str[(int)p->last_reset]);
10566 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10567 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10568 char errorcodesubcode_hexstr[5];
10569 char errorcodesubcode_str[256];
10570
10571 code_str = bgp_notify_code_str(p->notify.code);
10572 subcode_str = bgp_notify_subcode_str(
10573 p->notify.code, p->notify.subcode);
10574
10575 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10576 p->notify.code, p->notify.subcode);
10577 json_object_string_add(json_neigh,
10578 "lastErrorCodeSubcode",
10579 errorcodesubcode_hexstr);
10580 snprintf(errorcodesubcode_str, 255, "%s%s",
10581 code_str, subcode_str);
10582 json_object_string_add(json_neigh,
10583 "lastNotificationReason",
10584 errorcodesubcode_str);
10585 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10586 && p->notify.code == BGP_NOTIFY_CEASE
10587 && (p->notify.subcode
10588 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10589 || p->notify.subcode
10590 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10591 && p->notify.length) {
10592 char msgbuf[1024];
10593 const char *msg_str;
10594
10595 msg_str = bgp_notify_admin_message(
10596 msgbuf, sizeof(msgbuf),
10597 (uint8_t *)p->notify.data,
10598 p->notify.length);
10599 if (msg_str)
10600 json_object_string_add(
10601 json_neigh,
10602 "lastShutdownDescription",
10603 msg_str);
10604 }
10605 }
10606 } else {
10607 vty_out(vty, " Last reset %s, ",
10608 peer_uptime(p->resettime, timebuf,
10609 BGP_UPTIME_LEN, 0, NULL));
10610
10611 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10612 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10613 code_str = bgp_notify_code_str(p->notify.code);
10614 subcode_str = bgp_notify_subcode_str(
10615 p->notify.code, p->notify.subcode);
10616 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10617 p->last_reset == PEER_DOWN_NOTIFY_SEND
10618 ? "sent"
10619 : "received",
10620 code_str, subcode_str);
10621 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10622 && p->notify.code == BGP_NOTIFY_CEASE
10623 && (p->notify.subcode
10624 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10625 || p->notify.subcode
10626 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10627 && p->notify.length) {
10628 char msgbuf[1024];
10629 const char *msg_str;
10630
10631 msg_str = bgp_notify_admin_message(
10632 msgbuf, sizeof(msgbuf),
10633 (uint8_t *)p->notify.data,
10634 p->notify.length);
10635 if (msg_str)
10636 vty_out(vty,
10637 " Message: \"%s\"\n",
10638 msg_str);
10639 }
10640 } else {
10641 vty_out(vty, "due to %s\n",
10642 peer_down_str[(int)p->last_reset]);
10643 }
10644
10645 if (p->last_reset_cause_size) {
10646 msg = p->last_reset_cause;
10647 vty_out(vty,
10648 " Message received that caused BGP to send a NOTIFICATION:\n ");
10649 for (i = 1; i <= p->last_reset_cause_size;
10650 i++) {
10651 vty_out(vty, "%02X", *msg++);
10652
10653 if (i != p->last_reset_cause_size) {
10654 if (i % 16 == 0) {
10655 vty_out(vty, "\n ");
10656 } else if (i % 4 == 0) {
10657 vty_out(vty, " ");
10658 }
10659 }
10660 }
10661 vty_out(vty, "\n");
10662 }
10663 }
10664 }
10665
10666 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10667 if (use_json)
10668 json_object_boolean_true_add(json_neigh,
10669 "prefixesConfigExceedMax");
10670 else
10671 vty_out(vty,
10672 " Peer had exceeded the max. no. of prefixes configured.\n");
10673
10674 if (p->t_pmax_restart) {
10675 if (use_json) {
10676 json_object_boolean_true_add(
10677 json_neigh, "reducePrefixNumFrom");
10678 json_object_int_add(json_neigh,
10679 "restartInTimerMsec",
10680 thread_timer_remain_second(
10681 p->t_pmax_restart)
10682 * 1000);
10683 } else
10684 vty_out(vty,
10685 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10686 p->host, thread_timer_remain_second(
10687 p->t_pmax_restart));
10688 } else {
10689 if (use_json)
10690 json_object_boolean_true_add(
10691 json_neigh,
10692 "reducePrefixNumAndClearIpBgp");
10693 else
10694 vty_out(vty,
10695 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10696 p->host);
10697 }
10698 }
10699
10700 /* EBGP Multihop and GTSM */
10701 if (p->sort != BGP_PEER_IBGP) {
10702 if (use_json) {
10703 if (p->gtsm_hops > 0)
10704 json_object_int_add(json_neigh,
10705 "externalBgpNbrMaxHopsAway",
10706 p->gtsm_hops);
10707 else if (p->ttl > 1)
10708 json_object_int_add(json_neigh,
10709 "externalBgpNbrMaxHopsAway",
10710 p->ttl);
10711 } else {
10712 if (p->gtsm_hops > 0)
10713 vty_out(vty,
10714 " External BGP neighbor may be up to %d hops away.\n",
10715 p->gtsm_hops);
10716 else if (p->ttl > 1)
10717 vty_out(vty,
10718 " External BGP neighbor may be up to %d hops away.\n",
10719 p->ttl);
10720 }
10721 } else {
10722 if (p->gtsm_hops > 0) {
10723 if (use_json)
10724 json_object_int_add(json_neigh,
10725 "internalBgpNbrMaxHopsAway",
10726 p->gtsm_hops);
10727 else
10728 vty_out(vty,
10729 " Internal BGP neighbor may be up to %d hops away.\n",
10730 p->gtsm_hops);
10731 }
10732 }
10733
10734 /* Local address. */
10735 if (p->su_local) {
10736 if (use_json) {
10737 json_object_string_add(json_neigh, "hostLocal",
10738 sockunion2str(p->su_local, buf1,
10739 SU_ADDRSTRLEN));
10740 json_object_int_add(json_neigh, "portLocal",
10741 ntohs(p->su_local->sin.sin_port));
10742 } else
10743 vty_out(vty, "Local host: %s, Local port: %d\n",
10744 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10745 ntohs(p->su_local->sin.sin_port));
10746 }
10747
10748 /* Remote address. */
10749 if (p->su_remote) {
10750 if (use_json) {
10751 json_object_string_add(json_neigh, "hostForeign",
10752 sockunion2str(p->su_remote, buf1,
10753 SU_ADDRSTRLEN));
10754 json_object_int_add(json_neigh, "portForeign",
10755 ntohs(p->su_remote->sin.sin_port));
10756 } else
10757 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10758 sockunion2str(p->su_remote, buf1,
10759 SU_ADDRSTRLEN),
10760 ntohs(p->su_remote->sin.sin_port));
10761 }
10762
10763 /* Nexthop display. */
10764 if (p->su_local) {
10765 if (use_json) {
10766 json_object_string_add(json_neigh, "nexthop",
10767 inet_ntop(AF_INET,
10768 &p->nexthop.v4, buf1,
10769 sizeof(buf1)));
10770 json_object_string_add(json_neigh, "nexthopGlobal",
10771 inet_ntop(AF_INET6,
10772 &p->nexthop.v6_global,
10773 buf1, sizeof(buf1)));
10774 json_object_string_add(json_neigh, "nexthopLocal",
10775 inet_ntop(AF_INET6,
10776 &p->nexthop.v6_local,
10777 buf1, sizeof(buf1)));
10778 if (p->shared_network)
10779 json_object_string_add(json_neigh,
10780 "bgpConnection",
10781 "sharedNetwork");
10782 else
10783 json_object_string_add(json_neigh,
10784 "bgpConnection",
10785 "nonSharedNetwork");
10786 } else {
10787 vty_out(vty, "Nexthop: %s\n",
10788 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10789 sizeof(buf1)));
10790 vty_out(vty, "Nexthop global: %s\n",
10791 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10792 sizeof(buf1)));
10793 vty_out(vty, "Nexthop local: %s\n",
10794 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10795 sizeof(buf1)));
10796 vty_out(vty, "BGP connection: %s\n",
10797 p->shared_network ? "shared network"
10798 : "non shared network");
10799 }
10800 }
10801
10802 /* Timer information. */
10803 if (use_json) {
10804 json_object_int_add(json_neigh, "connectRetryTimer",
10805 p->v_connect);
10806 if (p->status == Established && p->rtt)
10807 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10808 p->rtt);
10809 if (p->t_start)
10810 json_object_int_add(
10811 json_neigh, "nextStartTimerDueInMsecs",
10812 thread_timer_remain_second(p->t_start) * 1000);
10813 if (p->t_connect)
10814 json_object_int_add(
10815 json_neigh, "nextConnectTimerDueInMsecs",
10816 thread_timer_remain_second(p->t_connect)
10817 * 1000);
10818 if (p->t_routeadv) {
10819 json_object_int_add(json_neigh, "mraiInterval",
10820 p->v_routeadv);
10821 json_object_int_add(
10822 json_neigh, "mraiTimerExpireInMsecs",
10823 thread_timer_remain_second(p->t_routeadv)
10824 * 1000);
10825 }
10826 if (p->password)
10827 json_object_int_add(json_neigh, "authenticationEnabled",
10828 1);
10829
10830 if (p->t_read)
10831 json_object_string_add(json_neigh, "readThread", "on");
10832 else
10833 json_object_string_add(json_neigh, "readThread", "off");
10834
10835 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10836 json_object_string_add(json_neigh, "writeThread", "on");
10837 else
10838 json_object_string_add(json_neigh, "writeThread",
10839 "off");
10840 } else {
10841 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10842 p->v_connect);
10843 if (p->status == Established && p->rtt)
10844 vty_out(vty, "Estimated round trip time: %d ms\n",
10845 p->rtt);
10846 if (p->t_start)
10847 vty_out(vty, "Next start timer due in %ld seconds\n",
10848 thread_timer_remain_second(p->t_start));
10849 if (p->t_connect)
10850 vty_out(vty, "Next connect timer due in %ld seconds\n",
10851 thread_timer_remain_second(p->t_connect));
10852 if (p->t_routeadv)
10853 vty_out(vty,
10854 "MRAI (interval %u) timer expires in %ld seconds\n",
10855 p->v_routeadv,
10856 thread_timer_remain_second(p->t_routeadv));
10857 if (p->password)
10858 vty_out(vty, "Peer Authentication Enabled\n");
10859
10860 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
10861 p->t_read ? "on" : "off",
10862 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10863 ? "on"
10864 : "off", p->fd);
10865 }
10866
10867 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10868 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10869 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10870
10871 if (!use_json)
10872 vty_out(vty, "\n");
10873
10874 /* BFD information. */
10875 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10876
10877 if (use_json) {
10878 if (p->conf_if) /* Configured interface name. */
10879 json_object_object_add(json, p->conf_if, json_neigh);
10880 else /* Configured IP address. */
10881 json_object_object_add(json, p->host, json_neigh);
10882 }
10883 }
10884
10885 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10886 enum show_type type, union sockunion *su,
10887 const char *conf_if, bool use_json,
10888 json_object *json)
10889 {
10890 struct listnode *node, *nnode;
10891 struct peer *peer;
10892 int find = 0;
10893 bool nbr_output = false;
10894 afi_t afi = AFI_MAX;
10895 safi_t safi = SAFI_MAX;
10896
10897 if (type == show_ipv4_peer || type == show_ipv4_all) {
10898 afi = AFI_IP;
10899 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10900 afi = AFI_IP6;
10901 }
10902
10903 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10904 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10905 continue;
10906
10907 switch (type) {
10908 case show_all:
10909 bgp_show_peer(vty, peer, use_json, json);
10910 nbr_output = true;
10911 break;
10912 case show_peer:
10913 if (conf_if) {
10914 if ((peer->conf_if
10915 && !strcmp(peer->conf_if, conf_if))
10916 || (peer->hostname
10917 && !strcmp(peer->hostname, conf_if))) {
10918 find = 1;
10919 bgp_show_peer(vty, peer, use_json,
10920 json);
10921 }
10922 } else {
10923 if (sockunion_same(&peer->su, su)) {
10924 find = 1;
10925 bgp_show_peer(vty, peer, use_json,
10926 json);
10927 }
10928 }
10929 break;
10930 case show_ipv4_peer:
10931 case show_ipv6_peer:
10932 FOREACH_SAFI (safi) {
10933 if (peer->afc[afi][safi]) {
10934 if (conf_if) {
10935 if ((peer->conf_if
10936 && !strcmp(peer->conf_if, conf_if))
10937 || (peer->hostname
10938 && !strcmp(peer->hostname, conf_if))) {
10939 find = 1;
10940 bgp_show_peer(vty, peer, use_json,
10941 json);
10942 break;
10943 }
10944 } else {
10945 if (sockunion_same(&peer->su, su)) {
10946 find = 1;
10947 bgp_show_peer(vty, peer, use_json,
10948 json);
10949 break;
10950 }
10951 }
10952 }
10953 }
10954 break;
10955 case show_ipv4_all:
10956 case show_ipv6_all:
10957 FOREACH_SAFI (safi) {
10958 if (peer->afc[afi][safi]) {
10959 bgp_show_peer(vty, peer, use_json, json);
10960 nbr_output = true;
10961 break;
10962 }
10963 }
10964 break;
10965 }
10966 }
10967
10968 if ((type == show_peer || type == show_ipv4_peer ||
10969 type == show_ipv6_peer) && !find) {
10970 if (use_json)
10971 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10972 else
10973 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10974 }
10975
10976 if (type != show_peer && type != show_ipv4_peer &&
10977 type != show_ipv6_peer && !nbr_output && !use_json)
10978 vty_out(vty, "%% No BGP neighbors found\n");
10979
10980 if (use_json) {
10981 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10982 json, JSON_C_TO_STRING_PRETTY));
10983 } else {
10984 vty_out(vty, "\n");
10985 }
10986
10987 return CMD_SUCCESS;
10988 }
10989
10990 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10991 enum show_type type,
10992 const char *ip_str,
10993 bool use_json)
10994 {
10995 struct listnode *node, *nnode;
10996 struct bgp *bgp;
10997 union sockunion su;
10998 json_object *json = NULL;
10999 int ret, is_first = 1;
11000 bool nbr_output = false;
11001
11002 if (use_json)
11003 vty_out(vty, "{\n");
11004
11005 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11006 nbr_output = true;
11007 if (use_json) {
11008 if (!(json = json_object_new_object())) {
11009 flog_err(
11010 EC_BGP_JSON_MEM_ERROR,
11011 "Unable to allocate memory for JSON object");
11012 vty_out(vty,
11013 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11014 return;
11015 }
11016
11017 json_object_int_add(json, "vrfId",
11018 (bgp->vrf_id == VRF_UNKNOWN)
11019 ? -1
11020 : (int64_t)bgp->vrf_id);
11021 json_object_string_add(
11022 json, "vrfName",
11023 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11024 ? VRF_DEFAULT_NAME
11025 : bgp->name);
11026
11027 if (!is_first)
11028 vty_out(vty, ",\n");
11029 else
11030 is_first = 0;
11031
11032 vty_out(vty, "\"%s\":",
11033 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11034 ? VRF_DEFAULT_NAME
11035 : bgp->name);
11036 } else {
11037 vty_out(vty, "\nInstance %s:\n",
11038 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11039 ? VRF_DEFAULT_NAME
11040 : bgp->name);
11041 }
11042
11043 if (type == show_peer || type == show_ipv4_peer ||
11044 type == show_ipv6_peer) {
11045 ret = str2sockunion(ip_str, &su);
11046 if (ret < 0)
11047 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11048 use_json, json);
11049 else
11050 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11051 use_json, json);
11052 } else {
11053 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11054 use_json, json);
11055 }
11056 json_object_free(json);
11057 }
11058
11059 if (use_json) {
11060 vty_out(vty, "}\n");
11061 json_object_free(json);
11062 }
11063 else if (!nbr_output)
11064 vty_out(vty, "%% BGP instance not found\n");
11065 }
11066
11067 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11068 enum show_type type, const char *ip_str,
11069 bool use_json)
11070 {
11071 int ret;
11072 struct bgp *bgp;
11073 union sockunion su;
11074 json_object *json = NULL;
11075
11076 if (name) {
11077 if (strmatch(name, "all")) {
11078 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11079 use_json);
11080 return CMD_SUCCESS;
11081 } else {
11082 bgp = bgp_lookup_by_name(name);
11083 if (!bgp) {
11084 if (use_json) {
11085 json = json_object_new_object();
11086 vty_out(vty, "%s\n",
11087 json_object_to_json_string_ext(
11088 json,
11089 JSON_C_TO_STRING_PRETTY));
11090 json_object_free(json);
11091 } else
11092 vty_out(vty,
11093 "%% BGP instance not found\n");
11094
11095 return CMD_WARNING;
11096 }
11097 }
11098 } else {
11099 bgp = bgp_get_default();
11100 }
11101
11102 if (bgp) {
11103 json = json_object_new_object();
11104 if (ip_str) {
11105 ret = str2sockunion(ip_str, &su);
11106 if (ret < 0)
11107 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11108 use_json, json);
11109 else
11110 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11111 use_json, json);
11112 } else {
11113 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11114 json);
11115 }
11116 json_object_free(json);
11117 } else {
11118 if (use_json)
11119 vty_out(vty, "{}\n");
11120 else
11121 vty_out(vty, "%% BGP instance not found\n");
11122 }
11123
11124 return CMD_SUCCESS;
11125 }
11126
11127 /* "show [ip] bgp neighbors" commands. */
11128 DEFUN (show_ip_bgp_neighbors,
11129 show_ip_bgp_neighbors_cmd,
11130 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11131 SHOW_STR
11132 IP_STR
11133 BGP_STR
11134 BGP_INSTANCE_HELP_STR
11135 "Address Family\n"
11136 "Address Family\n"
11137 "Detailed information on TCP and BGP neighbor connections\n"
11138 "Neighbor to display information about\n"
11139 "Neighbor to display information about\n"
11140 "Neighbor on BGP configured interface\n"
11141 JSON_STR)
11142 {
11143 char *vrf = NULL;
11144 char *sh_arg = NULL;
11145 enum show_type sh_type;
11146 afi_t afi = AFI_MAX;
11147
11148 bool uj = use_json(argc, argv);
11149
11150 int idx = 0;
11151
11152 /* [<vrf> VIEWVRFNAME] */
11153 if (argv_find(argv, argc, "vrf", &idx)) {
11154 vrf = argv[idx + 1]->arg;
11155 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11156 vrf = NULL;
11157 } else if (argv_find(argv, argc, "view", &idx))
11158 /* [<view> VIEWVRFNAME] */
11159 vrf = argv[idx + 1]->arg;
11160
11161 idx++;
11162
11163 if (argv_find(argv, argc, "ipv4", &idx)) {
11164 sh_type = show_ipv4_all;
11165 afi = AFI_IP;
11166 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11167 sh_type = show_ipv6_all;
11168 afi = AFI_IP6;
11169 } else {
11170 sh_type = show_all;
11171 }
11172
11173 if (argv_find(argv, argc, "A.B.C.D", &idx)
11174 || argv_find(argv, argc, "X:X::X:X", &idx)
11175 || argv_find(argv, argc, "WORD", &idx)) {
11176 sh_type = show_peer;
11177 sh_arg = argv[idx]->arg;
11178 }
11179
11180 if (sh_type == show_peer && afi == AFI_IP) {
11181 sh_type = show_ipv4_peer;
11182 } else if (sh_type == show_peer && afi == AFI_IP6) {
11183 sh_type = show_ipv6_peer;
11184 }
11185
11186 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11187 }
11188
11189 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11190 paths' and `show ip mbgp paths'. Those functions results are the
11191 same.*/
11192 DEFUN (show_ip_bgp_paths,
11193 show_ip_bgp_paths_cmd,
11194 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11195 SHOW_STR
11196 IP_STR
11197 BGP_STR
11198 BGP_SAFI_HELP_STR
11199 "Path information\n")
11200 {
11201 vty_out(vty, "Address Refcnt Path\n");
11202 aspath_print_all_vty(vty);
11203 return CMD_SUCCESS;
11204 }
11205
11206 #include "hash.h"
11207
11208 static void community_show_all_iterator(struct hash_bucket *bucket,
11209 struct vty *vty)
11210 {
11211 struct community *com;
11212
11213 com = (struct community *)bucket->data;
11214 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11215 community_str(com, false));
11216 }
11217
11218 /* Show BGP's community internal data. */
11219 DEFUN (show_ip_bgp_community_info,
11220 show_ip_bgp_community_info_cmd,
11221 "show [ip] bgp community-info",
11222 SHOW_STR
11223 IP_STR
11224 BGP_STR
11225 "List all bgp community information\n")
11226 {
11227 vty_out(vty, "Address Refcnt Community\n");
11228
11229 hash_iterate(community_hash(),
11230 (void (*)(struct hash_bucket *,
11231 void *))community_show_all_iterator,
11232 vty);
11233
11234 return CMD_SUCCESS;
11235 }
11236
11237 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11238 struct vty *vty)
11239 {
11240 struct lcommunity *lcom;
11241
11242 lcom = (struct lcommunity *)bucket->data;
11243 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11244 lcommunity_str(lcom, false));
11245 }
11246
11247 /* Show BGP's community internal data. */
11248 DEFUN (show_ip_bgp_lcommunity_info,
11249 show_ip_bgp_lcommunity_info_cmd,
11250 "show ip bgp large-community-info",
11251 SHOW_STR
11252 IP_STR
11253 BGP_STR
11254 "List all bgp large-community information\n")
11255 {
11256 vty_out(vty, "Address Refcnt Large-community\n");
11257
11258 hash_iterate(lcommunity_hash(),
11259 (void (*)(struct hash_bucket *,
11260 void *))lcommunity_show_all_iterator,
11261 vty);
11262
11263 return CMD_SUCCESS;
11264 }
11265
11266
11267 DEFUN (show_ip_bgp_attr_info,
11268 show_ip_bgp_attr_info_cmd,
11269 "show [ip] bgp attribute-info",
11270 SHOW_STR
11271 IP_STR
11272 BGP_STR
11273 "List all bgp attribute information\n")
11274 {
11275 attr_show_all(vty);
11276 return CMD_SUCCESS;
11277 }
11278
11279 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11280 afi_t afi, safi_t safi,
11281 bool use_json, json_object *json)
11282 {
11283 struct bgp *bgp;
11284 struct listnode *node;
11285 char *vname;
11286 char buf1[INET6_ADDRSTRLEN];
11287 char *ecom_str;
11288 vpn_policy_direction_t dir;
11289
11290 if (json) {
11291 json_object *json_import_vrfs = NULL;
11292 json_object *json_export_vrfs = NULL;
11293
11294 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11295
11296 if (!bgp) {
11297 vty_out(vty, "%s\n",
11298 json_object_to_json_string_ext(
11299 json,
11300 JSON_C_TO_STRING_PRETTY));
11301 json_object_free(json);
11302
11303 return CMD_WARNING;
11304 }
11305
11306 /* Provide context for the block */
11307 json_object_string_add(json, "vrf", name ? name : "default");
11308 json_object_string_add(json, "afiSafi",
11309 afi_safi_print(afi, safi));
11310
11311 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11312 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11313 json_object_string_add(json, "importFromVrfs", "none");
11314 json_object_string_add(json, "importRts", "none");
11315 } else {
11316 json_import_vrfs = json_object_new_array();
11317
11318 for (ALL_LIST_ELEMENTS_RO(
11319 bgp->vpn_policy[afi].import_vrf,
11320 node, vname))
11321 json_object_array_add(json_import_vrfs,
11322 json_object_new_string(vname));
11323
11324 json_object_object_add(json, "importFromVrfs",
11325 json_import_vrfs);
11326 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11327 if (bgp->vpn_policy[afi].rtlist[dir]) {
11328 ecom_str = ecommunity_ecom2str(
11329 bgp->vpn_policy[afi].rtlist[dir],
11330 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11331 json_object_string_add(json, "importRts",
11332 ecom_str);
11333 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11334 } else
11335 json_object_string_add(json, "importRts",
11336 "none");
11337 }
11338
11339 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11340 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11341 json_object_string_add(json, "exportToVrfs", "none");
11342 json_object_string_add(json, "routeDistinguisher",
11343 "none");
11344 json_object_string_add(json, "exportRts", "none");
11345 } else {
11346 json_export_vrfs = json_object_new_array();
11347
11348 for (ALL_LIST_ELEMENTS_RO(
11349 bgp->vpn_policy[afi].export_vrf,
11350 node, vname))
11351 json_object_array_add(json_export_vrfs,
11352 json_object_new_string(vname));
11353 json_object_object_add(json, "exportToVrfs",
11354 json_export_vrfs);
11355 json_object_string_add(json, "routeDistinguisher",
11356 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11357 buf1, RD_ADDRSTRLEN));
11358
11359 dir = BGP_VPN_POLICY_DIR_TOVPN;
11360 if (bgp->vpn_policy[afi].rtlist[dir]) {
11361 ecom_str = ecommunity_ecom2str(
11362 bgp->vpn_policy[afi].rtlist[dir],
11363 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11364 json_object_string_add(json, "exportRts",
11365 ecom_str);
11366 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11367 } else
11368 json_object_string_add(json, "exportRts",
11369 "none");
11370 }
11371
11372 if (use_json) {
11373 vty_out(vty, "%s\n",
11374 json_object_to_json_string_ext(json,
11375 JSON_C_TO_STRING_PRETTY));
11376 json_object_free(json);
11377 }
11378 } else {
11379 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11380
11381 if (!bgp) {
11382 vty_out(vty, "%% No such BGP instance exist\n");
11383 return CMD_WARNING;
11384 }
11385
11386 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11387 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11388 vty_out(vty,
11389 "This VRF is not importing %s routes from any other VRF\n",
11390 afi_safi_print(afi, safi));
11391 else {
11392 vty_out(vty,
11393 "This VRF is importing %s routes from the following VRFs:\n",
11394 afi_safi_print(afi, safi));
11395
11396 for (ALL_LIST_ELEMENTS_RO(
11397 bgp->vpn_policy[afi].import_vrf,
11398 node, vname))
11399 vty_out(vty, " %s\n", vname);
11400
11401 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11402 ecom_str = NULL;
11403 if (bgp->vpn_policy[afi].rtlist[dir]) {
11404 ecom_str = ecommunity_ecom2str(
11405 bgp->vpn_policy[afi].rtlist[dir],
11406 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11407 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11408
11409 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11410 } else
11411 vty_out(vty, "Import RT(s):\n");
11412 }
11413
11414 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11415 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11416 vty_out(vty,
11417 "This VRF is not exporting %s routes to any other VRF\n",
11418 afi_safi_print(afi, safi));
11419 else {
11420 vty_out(vty,
11421 "This VRF is exporting %s routes to the following VRFs:\n",
11422 afi_safi_print(afi, safi));
11423
11424 for (ALL_LIST_ELEMENTS_RO(
11425 bgp->vpn_policy[afi].export_vrf,
11426 node, vname))
11427 vty_out(vty, " %s\n", vname);
11428
11429 vty_out(vty, "RD: %s\n",
11430 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11431 buf1, RD_ADDRSTRLEN));
11432
11433 dir = BGP_VPN_POLICY_DIR_TOVPN;
11434 if (bgp->vpn_policy[afi].rtlist[dir]) {
11435 ecom_str = ecommunity_ecom2str(
11436 bgp->vpn_policy[afi].rtlist[dir],
11437 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11438 vty_out(vty, "Export RT: %s\n", ecom_str);
11439 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11440 } else
11441 vty_out(vty, "Import RT(s):\n");
11442 }
11443 }
11444
11445 return CMD_SUCCESS;
11446 }
11447
11448 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11449 safi_t safi, bool use_json)
11450 {
11451 struct listnode *node, *nnode;
11452 struct bgp *bgp;
11453 char *vrf_name = NULL;
11454 json_object *json = NULL;
11455 json_object *json_vrf = NULL;
11456 json_object *json_vrfs = NULL;
11457
11458 if (use_json) {
11459 json = json_object_new_object();
11460 json_vrfs = json_object_new_object();
11461 }
11462
11463 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11464
11465 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11466 vrf_name = bgp->name;
11467
11468 if (use_json) {
11469 json_vrf = json_object_new_object();
11470 } else {
11471 vty_out(vty, "\nInstance %s:\n",
11472 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11473 ? VRF_DEFAULT_NAME : bgp->name);
11474 }
11475 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11476 if (use_json) {
11477 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11478 json_object_object_add(json_vrfs,
11479 VRF_DEFAULT_NAME, json_vrf);
11480 else
11481 json_object_object_add(json_vrfs, vrf_name,
11482 json_vrf);
11483 }
11484 }
11485
11486 if (use_json) {
11487 json_object_object_add(json, "vrfs", json_vrfs);
11488 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11489 JSON_C_TO_STRING_PRETTY));
11490 json_object_free(json);
11491 }
11492
11493 return CMD_SUCCESS;
11494 }
11495
11496 /* "show [ip] bgp route-leak" command. */
11497 DEFUN (show_ip_bgp_route_leak,
11498 show_ip_bgp_route_leak_cmd,
11499 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11500 SHOW_STR
11501 IP_STR
11502 BGP_STR
11503 BGP_INSTANCE_HELP_STR
11504 BGP_AFI_HELP_STR
11505 BGP_SAFI_HELP_STR
11506 "Route leaking information\n"
11507 JSON_STR)
11508 {
11509 char *vrf = NULL;
11510 afi_t afi = AFI_MAX;
11511 safi_t safi = SAFI_MAX;
11512
11513 bool uj = use_json(argc, argv);
11514 int idx = 0;
11515 json_object *json = NULL;
11516
11517 /* show [ip] bgp */
11518 if (argv_find(argv, argc, "ip", &idx)) {
11519 afi = AFI_IP;
11520 safi = SAFI_UNICAST;
11521 }
11522 /* [vrf VIEWVRFNAME] */
11523 if (argv_find(argv, argc, "view", &idx)) {
11524 vty_out(vty,
11525 "%% This command is not applicable to BGP views\n");
11526 return CMD_WARNING;
11527 }
11528
11529 if (argv_find(argv, argc, "vrf", &idx)) {
11530 vrf = argv[idx + 1]->arg;
11531 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11532 vrf = NULL;
11533 }
11534 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11535 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11536 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11537 }
11538
11539 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11540 vty_out(vty,
11541 "%% This command is applicable only for unicast ipv4|ipv6\n");
11542 return CMD_WARNING;
11543 }
11544
11545 if (vrf && strmatch(vrf, "all"))
11546 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11547
11548 if (uj)
11549 json = json_object_new_object();
11550
11551 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11552 }
11553
11554 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11555 safi_t safi)
11556 {
11557 struct listnode *node, *nnode;
11558 struct bgp *bgp;
11559
11560 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11561 vty_out(vty, "\nInstance %s:\n",
11562 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11563 ? VRF_DEFAULT_NAME
11564 : bgp->name);
11565 update_group_show(bgp, afi, safi, vty, 0);
11566 }
11567 }
11568
11569 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11570 int safi, uint64_t subgrp_id)
11571 {
11572 struct bgp *bgp;
11573
11574 if (name) {
11575 if (strmatch(name, "all")) {
11576 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11577 return CMD_SUCCESS;
11578 } else {
11579 bgp = bgp_lookup_by_name(name);
11580 }
11581 } else {
11582 bgp = bgp_get_default();
11583 }
11584
11585 if (bgp)
11586 update_group_show(bgp, afi, safi, vty, subgrp_id);
11587 return CMD_SUCCESS;
11588 }
11589
11590 DEFUN (show_ip_bgp_updgrps,
11591 show_ip_bgp_updgrps_cmd,
11592 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11593 SHOW_STR
11594 IP_STR
11595 BGP_STR
11596 BGP_INSTANCE_HELP_STR
11597 BGP_AFI_HELP_STR
11598 BGP_SAFI_WITH_LABEL_HELP_STR
11599 "Detailed info about dynamic update groups\n"
11600 "Specific subgroup to display detailed info for\n")
11601 {
11602 char *vrf = NULL;
11603 afi_t afi = AFI_IP6;
11604 safi_t safi = SAFI_UNICAST;
11605 uint64_t subgrp_id = 0;
11606
11607 int idx = 0;
11608
11609 /* show [ip] bgp */
11610 if (argv_find(argv, argc, "ip", &idx))
11611 afi = AFI_IP;
11612 /* [<vrf> VIEWVRFNAME] */
11613 if (argv_find(argv, argc, "vrf", &idx)) {
11614 vrf = argv[idx + 1]->arg;
11615 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11616 vrf = NULL;
11617 } else if (argv_find(argv, argc, "view", &idx))
11618 /* [<view> VIEWVRFNAME] */
11619 vrf = argv[idx + 1]->arg;
11620 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11621 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11622 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11623 }
11624
11625 /* get subgroup id, if provided */
11626 idx = argc - 1;
11627 if (argv[idx]->type == VARIABLE_TKN)
11628 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11629
11630 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11631 }
11632
11633 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11634 show_bgp_instance_all_ipv6_updgrps_cmd,
11635 "show [ip] bgp <view|vrf> all update-groups",
11636 SHOW_STR
11637 IP_STR
11638 BGP_STR
11639 BGP_INSTANCE_ALL_HELP_STR
11640 "Detailed info about dynamic update groups\n")
11641 {
11642 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11643 return CMD_SUCCESS;
11644 }
11645
11646 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11647 show_bgp_l2vpn_evpn_updgrps_cmd,
11648 "show [ip] bgp l2vpn evpn update-groups",
11649 SHOW_STR
11650 IP_STR
11651 BGP_STR
11652 "l2vpn address family\n"
11653 "evpn sub-address family\n"
11654 "Detailed info about dynamic update groups\n")
11655 {
11656 char *vrf = NULL;
11657 uint64_t subgrp_id = 0;
11658
11659 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11660 return CMD_SUCCESS;
11661 }
11662
11663 DEFUN (show_bgp_updgrps_stats,
11664 show_bgp_updgrps_stats_cmd,
11665 "show [ip] bgp update-groups statistics",
11666 SHOW_STR
11667 IP_STR
11668 BGP_STR
11669 "Detailed info about dynamic update groups\n"
11670 "Statistics\n")
11671 {
11672 struct bgp *bgp;
11673
11674 bgp = bgp_get_default();
11675 if (bgp)
11676 update_group_show_stats(bgp, vty);
11677
11678 return CMD_SUCCESS;
11679 }
11680
11681 DEFUN (show_bgp_instance_updgrps_stats,
11682 show_bgp_instance_updgrps_stats_cmd,
11683 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11684 SHOW_STR
11685 IP_STR
11686 BGP_STR
11687 BGP_INSTANCE_HELP_STR
11688 "Detailed info about dynamic update groups\n"
11689 "Statistics\n")
11690 {
11691 int idx_word = 3;
11692 struct bgp *bgp;
11693
11694 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11695 if (bgp)
11696 update_group_show_stats(bgp, vty);
11697
11698 return CMD_SUCCESS;
11699 }
11700
11701 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11702 afi_t afi, safi_t safi,
11703 const char *what, uint64_t subgrp_id)
11704 {
11705 struct bgp *bgp;
11706
11707 if (name)
11708 bgp = bgp_lookup_by_name(name);
11709 else
11710 bgp = bgp_get_default();
11711
11712 if (bgp) {
11713 if (!strcmp(what, "advertise-queue"))
11714 update_group_show_adj_queue(bgp, afi, safi, vty,
11715 subgrp_id);
11716 else if (!strcmp(what, "advertised-routes"))
11717 update_group_show_advertised(bgp, afi, safi, vty,
11718 subgrp_id);
11719 else if (!strcmp(what, "packet-queue"))
11720 update_group_show_packet_queue(bgp, afi, safi, vty,
11721 subgrp_id);
11722 }
11723 }
11724
11725 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11726 show_ip_bgp_instance_updgrps_adj_s_cmd,
11727 "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",
11728 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11729 BGP_SAFI_HELP_STR
11730 "Detailed info about dynamic update groups\n"
11731 "Specific subgroup to display info for\n"
11732 "Advertisement queue\n"
11733 "Announced routes\n"
11734 "Packet queue\n")
11735 {
11736 uint64_t subgrp_id = 0;
11737 afi_t afiz;
11738 safi_t safiz;
11739 if (sgid)
11740 subgrp_id = strtoull(sgid, NULL, 10);
11741
11742 if (!ip && !afi)
11743 afiz = AFI_IP6;
11744 if (!ip && afi)
11745 afiz = bgp_vty_afi_from_str(afi);
11746 if (ip && !afi)
11747 afiz = AFI_IP;
11748 if (ip && afi) {
11749 afiz = bgp_vty_afi_from_str(afi);
11750 if (afiz != AFI_IP)
11751 vty_out(vty,
11752 "%% Cannot specify both 'ip' and 'ipv6'\n");
11753 return CMD_WARNING;
11754 }
11755
11756 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11757
11758 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11759 return CMD_SUCCESS;
11760 }
11761
11762 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11763 {
11764 struct listnode *node, *nnode;
11765 struct prefix *range;
11766 struct peer *conf;
11767 struct peer *peer;
11768 char buf[PREFIX2STR_BUFFER];
11769 afi_t afi;
11770 safi_t safi;
11771 const char *peer_status;
11772 const char *af_str;
11773 int lr_count;
11774 int dynamic;
11775 int af_cfgd;
11776
11777 conf = group->conf;
11778
11779 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11780 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11781 group->name, conf->as);
11782 } else if (conf->as_type == AS_INTERNAL) {
11783 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11784 group->name, group->bgp->as);
11785 } else {
11786 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11787 }
11788
11789 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11790 vty_out(vty, " Peer-group type is internal\n");
11791 else
11792 vty_out(vty, " Peer-group type is external\n");
11793
11794 /* Display AFs configured. */
11795 vty_out(vty, " Configured address-families:");
11796 FOREACH_AFI_SAFI (afi, safi) {
11797 if (conf->afc[afi][safi]) {
11798 af_cfgd = 1;
11799 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11800 }
11801 }
11802 if (!af_cfgd)
11803 vty_out(vty, " none\n");
11804 else
11805 vty_out(vty, "\n");
11806
11807 /* Display listen ranges (for dynamic neighbors), if any */
11808 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11809 if (afi == AFI_IP)
11810 af_str = "IPv4";
11811 else if (afi == AFI_IP6)
11812 af_str = "IPv6";
11813 else
11814 af_str = "???";
11815 lr_count = listcount(group->listen_range[afi]);
11816 if (lr_count) {
11817 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11818 af_str);
11819
11820
11821 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11822 nnode, range)) {
11823 prefix2str(range, buf, sizeof(buf));
11824 vty_out(vty, " %s\n", buf);
11825 }
11826 }
11827 }
11828
11829 /* Display group members and their status */
11830 if (listcount(group->peer)) {
11831 vty_out(vty, " Peer-group members:\n");
11832 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11833 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11834 peer_status = "Idle (Admin)";
11835 else if (CHECK_FLAG(peer->sflags,
11836 PEER_STATUS_PREFIX_OVERFLOW))
11837 peer_status = "Idle (PfxCt)";
11838 else
11839 peer_status = lookup_msg(bgp_status_msg,
11840 peer->status, NULL);
11841
11842 dynamic = peer_dynamic_neighbor(peer);
11843 vty_out(vty, " %s %s %s \n", peer->host,
11844 dynamic ? "(dynamic)" : "", peer_status);
11845 }
11846 }
11847
11848 return CMD_SUCCESS;
11849 }
11850
11851 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11852 const char *group_name)
11853 {
11854 struct bgp *bgp;
11855 struct listnode *node, *nnode;
11856 struct peer_group *group;
11857 bool found = false;
11858
11859 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11860
11861 if (!bgp) {
11862 vty_out(vty, "%% BGP instance not found\n");
11863 return CMD_WARNING;
11864 }
11865
11866 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11867 if (group_name) {
11868 if (strmatch(group->name, group_name)) {
11869 bgp_show_one_peer_group(vty, group);
11870 found = true;
11871 break;
11872 }
11873 } else {
11874 bgp_show_one_peer_group(vty, group);
11875 }
11876 }
11877
11878 if (group_name && !found)
11879 vty_out(vty, "%% No such peer-group\n");
11880
11881 return CMD_SUCCESS;
11882 }
11883
11884 DEFUN (show_ip_bgp_peer_groups,
11885 show_ip_bgp_peer_groups_cmd,
11886 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11887 SHOW_STR
11888 IP_STR
11889 BGP_STR
11890 BGP_INSTANCE_HELP_STR
11891 "Detailed information on BGP peer groups\n"
11892 "Peer group name\n")
11893 {
11894 char *vrf, *pg;
11895 int idx = 0;
11896
11897 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11898 : NULL;
11899 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11900
11901 return bgp_show_peer_group_vty(vty, vrf, pg);
11902 }
11903
11904
11905 /* Redistribute VTY commands. */
11906
11907 DEFUN (bgp_redistribute_ipv4,
11908 bgp_redistribute_ipv4_cmd,
11909 "redistribute " FRR_IP_REDIST_STR_BGPD,
11910 "Redistribute information from another routing protocol\n"
11911 FRR_IP_REDIST_HELP_STR_BGPD)
11912 {
11913 VTY_DECLVAR_CONTEXT(bgp, bgp);
11914 int idx_protocol = 1;
11915 int type;
11916
11917 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11918 if (type < 0) {
11919 vty_out(vty, "%% Invalid route type\n");
11920 return CMD_WARNING_CONFIG_FAILED;
11921 }
11922
11923 bgp_redist_add(bgp, AFI_IP, type, 0);
11924 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11925 }
11926
11927 ALIAS_HIDDEN(
11928 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11929 "redistribute " FRR_IP_REDIST_STR_BGPD,
11930 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11931
11932 DEFUN (bgp_redistribute_ipv4_rmap,
11933 bgp_redistribute_ipv4_rmap_cmd,
11934 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11935 "Redistribute information from another routing protocol\n"
11936 FRR_IP_REDIST_HELP_STR_BGPD
11937 "Route map reference\n"
11938 "Pointer to route-map entries\n")
11939 {
11940 VTY_DECLVAR_CONTEXT(bgp, bgp);
11941 int idx_protocol = 1;
11942 int idx_word = 3;
11943 int type;
11944 struct bgp_redist *red;
11945 bool changed;
11946 struct route_map *route_map = route_map_lookup_warn_noexist(
11947 vty, argv[idx_word]->arg);
11948
11949 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11950 if (type < 0) {
11951 vty_out(vty, "%% Invalid route type\n");
11952 return CMD_WARNING_CONFIG_FAILED;
11953 }
11954
11955 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11956 changed =
11957 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11958 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11959 }
11960
11961 ALIAS_HIDDEN(
11962 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11963 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11964 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11965 "Route map reference\n"
11966 "Pointer to route-map entries\n")
11967
11968 DEFUN (bgp_redistribute_ipv4_metric,
11969 bgp_redistribute_ipv4_metric_cmd,
11970 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11971 "Redistribute information from another routing protocol\n"
11972 FRR_IP_REDIST_HELP_STR_BGPD
11973 "Metric for redistributed routes\n"
11974 "Default metric\n")
11975 {
11976 VTY_DECLVAR_CONTEXT(bgp, bgp);
11977 int idx_protocol = 1;
11978 int idx_number = 3;
11979 int type;
11980 uint32_t metric;
11981 struct bgp_redist *red;
11982 bool changed;
11983
11984 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11985 if (type < 0) {
11986 vty_out(vty, "%% Invalid route type\n");
11987 return CMD_WARNING_CONFIG_FAILED;
11988 }
11989 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11990
11991 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11992 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11993 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11994 }
11995
11996 ALIAS_HIDDEN(
11997 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11998 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11999 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12000 "Metric for redistributed routes\n"
12001 "Default metric\n")
12002
12003 DEFUN (bgp_redistribute_ipv4_rmap_metric,
12004 bgp_redistribute_ipv4_rmap_metric_cmd,
12005 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12006 "Redistribute information from another routing protocol\n"
12007 FRR_IP_REDIST_HELP_STR_BGPD
12008 "Route map reference\n"
12009 "Pointer to route-map entries\n"
12010 "Metric for redistributed routes\n"
12011 "Default metric\n")
12012 {
12013 VTY_DECLVAR_CONTEXT(bgp, bgp);
12014 int idx_protocol = 1;
12015 int idx_word = 3;
12016 int idx_number = 5;
12017 int type;
12018 uint32_t metric;
12019 struct bgp_redist *red;
12020 bool changed;
12021 struct route_map *route_map =
12022 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12023
12024 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12025 if (type < 0) {
12026 vty_out(vty, "%% Invalid route type\n");
12027 return CMD_WARNING_CONFIG_FAILED;
12028 }
12029 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12030
12031 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12032 changed =
12033 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12034 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12035 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12036 }
12037
12038 ALIAS_HIDDEN(
12039 bgp_redistribute_ipv4_rmap_metric,
12040 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12041 "redistribute " FRR_IP_REDIST_STR_BGPD
12042 " route-map WORD metric (0-4294967295)",
12043 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12044 "Route map reference\n"
12045 "Pointer to route-map entries\n"
12046 "Metric for redistributed routes\n"
12047 "Default metric\n")
12048
12049 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12050 bgp_redistribute_ipv4_metric_rmap_cmd,
12051 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12052 "Redistribute information from another routing protocol\n"
12053 FRR_IP_REDIST_HELP_STR_BGPD
12054 "Metric for redistributed routes\n"
12055 "Default metric\n"
12056 "Route map reference\n"
12057 "Pointer to route-map entries\n")
12058 {
12059 VTY_DECLVAR_CONTEXT(bgp, bgp);
12060 int idx_protocol = 1;
12061 int idx_number = 3;
12062 int idx_word = 5;
12063 int type;
12064 uint32_t metric;
12065 struct bgp_redist *red;
12066 bool changed;
12067 struct route_map *route_map =
12068 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12069
12070 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12071 if (type < 0) {
12072 vty_out(vty, "%% Invalid route type\n");
12073 return CMD_WARNING_CONFIG_FAILED;
12074 }
12075 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12076
12077 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12078 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12079 changed |=
12080 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12081 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12082 }
12083
12084 ALIAS_HIDDEN(
12085 bgp_redistribute_ipv4_metric_rmap,
12086 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12087 "redistribute " FRR_IP_REDIST_STR_BGPD
12088 " metric (0-4294967295) route-map WORD",
12089 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12090 "Metric for redistributed routes\n"
12091 "Default metric\n"
12092 "Route map reference\n"
12093 "Pointer to route-map entries\n")
12094
12095 DEFUN (bgp_redistribute_ipv4_ospf,
12096 bgp_redistribute_ipv4_ospf_cmd,
12097 "redistribute <ospf|table> (1-65535)",
12098 "Redistribute information from another routing protocol\n"
12099 "Open Shortest Path First (OSPFv2)\n"
12100 "Non-main Kernel Routing Table\n"
12101 "Instance ID/Table ID\n")
12102 {
12103 VTY_DECLVAR_CONTEXT(bgp, bgp);
12104 int idx_ospf_table = 1;
12105 int idx_number = 2;
12106 unsigned short instance;
12107 unsigned short protocol;
12108
12109 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12110
12111 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12112 protocol = ZEBRA_ROUTE_OSPF;
12113 else
12114 protocol = ZEBRA_ROUTE_TABLE;
12115
12116 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12117 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12118 }
12119
12120 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12121 "redistribute <ospf|table> (1-65535)",
12122 "Redistribute information from another routing protocol\n"
12123 "Open Shortest Path First (OSPFv2)\n"
12124 "Non-main Kernel Routing Table\n"
12125 "Instance ID/Table ID\n")
12126
12127 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12128 bgp_redistribute_ipv4_ospf_rmap_cmd,
12129 "redistribute <ospf|table> (1-65535) route-map WORD",
12130 "Redistribute information from another routing protocol\n"
12131 "Open Shortest Path First (OSPFv2)\n"
12132 "Non-main Kernel Routing Table\n"
12133 "Instance ID/Table ID\n"
12134 "Route map reference\n"
12135 "Pointer to route-map entries\n")
12136 {
12137 VTY_DECLVAR_CONTEXT(bgp, bgp);
12138 int idx_ospf_table = 1;
12139 int idx_number = 2;
12140 int idx_word = 4;
12141 struct bgp_redist *red;
12142 unsigned short instance;
12143 int protocol;
12144 bool changed;
12145 struct route_map *route_map =
12146 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12147
12148 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12149 protocol = ZEBRA_ROUTE_OSPF;
12150 else
12151 protocol = ZEBRA_ROUTE_TABLE;
12152
12153 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12154 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12155 changed =
12156 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12157 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12158 }
12159
12160 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12161 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12162 "redistribute <ospf|table> (1-65535) route-map WORD",
12163 "Redistribute information from another routing protocol\n"
12164 "Open Shortest Path First (OSPFv2)\n"
12165 "Non-main Kernel Routing Table\n"
12166 "Instance ID/Table ID\n"
12167 "Route map reference\n"
12168 "Pointer to route-map entries\n")
12169
12170 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12171 bgp_redistribute_ipv4_ospf_metric_cmd,
12172 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12173 "Redistribute information from another routing protocol\n"
12174 "Open Shortest Path First (OSPFv2)\n"
12175 "Non-main Kernel Routing Table\n"
12176 "Instance ID/Table ID\n"
12177 "Metric for redistributed routes\n"
12178 "Default metric\n")
12179 {
12180 VTY_DECLVAR_CONTEXT(bgp, bgp);
12181 int idx_ospf_table = 1;
12182 int idx_number = 2;
12183 int idx_number_2 = 4;
12184 uint32_t metric;
12185 struct bgp_redist *red;
12186 unsigned short instance;
12187 int protocol;
12188 bool changed;
12189
12190 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12191 protocol = ZEBRA_ROUTE_OSPF;
12192 else
12193 protocol = ZEBRA_ROUTE_TABLE;
12194
12195 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12196 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12197
12198 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12199 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12200 metric);
12201 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12202 }
12203
12204 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12205 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12206 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12207 "Redistribute information from another routing protocol\n"
12208 "Open Shortest Path First (OSPFv2)\n"
12209 "Non-main Kernel Routing Table\n"
12210 "Instance ID/Table ID\n"
12211 "Metric for redistributed routes\n"
12212 "Default metric\n")
12213
12214 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12215 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12216 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12217 "Redistribute information from another routing protocol\n"
12218 "Open Shortest Path First (OSPFv2)\n"
12219 "Non-main Kernel Routing Table\n"
12220 "Instance ID/Table ID\n"
12221 "Route map reference\n"
12222 "Pointer to route-map entries\n"
12223 "Metric for redistributed routes\n"
12224 "Default metric\n")
12225 {
12226 VTY_DECLVAR_CONTEXT(bgp, bgp);
12227 int idx_ospf_table = 1;
12228 int idx_number = 2;
12229 int idx_word = 4;
12230 int idx_number_2 = 6;
12231 uint32_t metric;
12232 struct bgp_redist *red;
12233 unsigned short instance;
12234 int protocol;
12235 bool changed;
12236 struct route_map *route_map =
12237 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12238
12239 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12240 protocol = ZEBRA_ROUTE_OSPF;
12241 else
12242 protocol = ZEBRA_ROUTE_TABLE;
12243
12244 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12245 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12246
12247 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12248 changed =
12249 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12250 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12251 metric);
12252 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12253 }
12254
12255 ALIAS_HIDDEN(
12256 bgp_redistribute_ipv4_ospf_rmap_metric,
12257 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12258 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12259 "Redistribute information from another routing protocol\n"
12260 "Open Shortest Path First (OSPFv2)\n"
12261 "Non-main Kernel Routing Table\n"
12262 "Instance ID/Table ID\n"
12263 "Route map reference\n"
12264 "Pointer to route-map entries\n"
12265 "Metric for redistributed routes\n"
12266 "Default metric\n")
12267
12268 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12269 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12270 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12271 "Redistribute information from another routing protocol\n"
12272 "Open Shortest Path First (OSPFv2)\n"
12273 "Non-main Kernel Routing Table\n"
12274 "Instance ID/Table ID\n"
12275 "Metric for redistributed routes\n"
12276 "Default metric\n"
12277 "Route map reference\n"
12278 "Pointer to route-map entries\n")
12279 {
12280 VTY_DECLVAR_CONTEXT(bgp, bgp);
12281 int idx_ospf_table = 1;
12282 int idx_number = 2;
12283 int idx_number_2 = 4;
12284 int idx_word = 6;
12285 uint32_t metric;
12286 struct bgp_redist *red;
12287 unsigned short instance;
12288 int protocol;
12289 bool changed;
12290 struct route_map *route_map =
12291 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12292
12293 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12294 protocol = ZEBRA_ROUTE_OSPF;
12295 else
12296 protocol = ZEBRA_ROUTE_TABLE;
12297
12298 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12299 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12300
12301 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12302 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12303 metric);
12304 changed |=
12305 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12306 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12307 }
12308
12309 ALIAS_HIDDEN(
12310 bgp_redistribute_ipv4_ospf_metric_rmap,
12311 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12312 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12313 "Redistribute information from another routing protocol\n"
12314 "Open Shortest Path First (OSPFv2)\n"
12315 "Non-main Kernel Routing Table\n"
12316 "Instance ID/Table ID\n"
12317 "Metric for redistributed routes\n"
12318 "Default metric\n"
12319 "Route map reference\n"
12320 "Pointer to route-map entries\n")
12321
12322 DEFUN (no_bgp_redistribute_ipv4_ospf,
12323 no_bgp_redistribute_ipv4_ospf_cmd,
12324 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12325 NO_STR
12326 "Redistribute information from another routing protocol\n"
12327 "Open Shortest Path First (OSPFv2)\n"
12328 "Non-main Kernel Routing Table\n"
12329 "Instance ID/Table ID\n"
12330 "Metric for redistributed routes\n"
12331 "Default metric\n"
12332 "Route map reference\n"
12333 "Pointer to route-map entries\n")
12334 {
12335 VTY_DECLVAR_CONTEXT(bgp, bgp);
12336 int idx_ospf_table = 2;
12337 int idx_number = 3;
12338 unsigned short instance;
12339 int protocol;
12340
12341 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12342 protocol = ZEBRA_ROUTE_OSPF;
12343 else
12344 protocol = ZEBRA_ROUTE_TABLE;
12345
12346 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12347 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12348 }
12349
12350 ALIAS_HIDDEN(
12351 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12352 "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
12353 NO_STR
12354 "Redistribute information from another routing protocol\n"
12355 "Open Shortest Path First (OSPFv2)\n"
12356 "Non-main Kernel Routing Table\n"
12357 "Instance ID/Table ID\n"
12358 "Metric for redistributed routes\n"
12359 "Default metric\n"
12360 "Route map reference\n"
12361 "Pointer to route-map entries\n")
12362
12363 DEFUN (no_bgp_redistribute_ipv4,
12364 no_bgp_redistribute_ipv4_cmd,
12365 "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12366 NO_STR
12367 "Redistribute information from another routing protocol\n"
12368 FRR_IP_REDIST_HELP_STR_BGPD
12369 "Metric for redistributed routes\n"
12370 "Default metric\n"
12371 "Route map reference\n"
12372 "Pointer to route-map entries\n")
12373 {
12374 VTY_DECLVAR_CONTEXT(bgp, bgp);
12375 int idx_protocol = 2;
12376 int type;
12377
12378 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12379 if (type < 0) {
12380 vty_out(vty, "%% Invalid route type\n");
12381 return CMD_WARNING_CONFIG_FAILED;
12382 }
12383 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12384 }
12385
12386 ALIAS_HIDDEN(
12387 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12388 "no redistribute " FRR_IP_REDIST_STR_BGPD
12389 " [{metric (0-4294967295)|route-map WORD}]",
12390 NO_STR
12391 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12392 "Metric for redistributed routes\n"
12393 "Default metric\n"
12394 "Route map reference\n"
12395 "Pointer to route-map entries\n")
12396
12397 DEFUN (bgp_redistribute_ipv6,
12398 bgp_redistribute_ipv6_cmd,
12399 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12400 "Redistribute information from another routing protocol\n"
12401 FRR_IP6_REDIST_HELP_STR_BGPD)
12402 {
12403 VTY_DECLVAR_CONTEXT(bgp, bgp);
12404 int idx_protocol = 1;
12405 int type;
12406
12407 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12408 if (type < 0) {
12409 vty_out(vty, "%% Invalid route type\n");
12410 return CMD_WARNING_CONFIG_FAILED;
12411 }
12412
12413 bgp_redist_add(bgp, AFI_IP6, type, 0);
12414 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12415 }
12416
12417 DEFUN (bgp_redistribute_ipv6_rmap,
12418 bgp_redistribute_ipv6_rmap_cmd,
12419 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12420 "Redistribute information from another routing protocol\n"
12421 FRR_IP6_REDIST_HELP_STR_BGPD
12422 "Route map reference\n"
12423 "Pointer to route-map entries\n")
12424 {
12425 VTY_DECLVAR_CONTEXT(bgp, bgp);
12426 int idx_protocol = 1;
12427 int idx_word = 3;
12428 int type;
12429 struct bgp_redist *red;
12430 bool changed;
12431 struct route_map *route_map =
12432 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12433
12434 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12435 if (type < 0) {
12436 vty_out(vty, "%% Invalid route type\n");
12437 return CMD_WARNING_CONFIG_FAILED;
12438 }
12439
12440 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12441 changed =
12442 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12443 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12444 }
12445
12446 DEFUN (bgp_redistribute_ipv6_metric,
12447 bgp_redistribute_ipv6_metric_cmd,
12448 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12449 "Redistribute information from another routing protocol\n"
12450 FRR_IP6_REDIST_HELP_STR_BGPD
12451 "Metric for redistributed routes\n"
12452 "Default metric\n")
12453 {
12454 VTY_DECLVAR_CONTEXT(bgp, bgp);
12455 int idx_protocol = 1;
12456 int idx_number = 3;
12457 int type;
12458 uint32_t metric;
12459 struct bgp_redist *red;
12460 bool changed;
12461
12462 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12463 if (type < 0) {
12464 vty_out(vty, "%% Invalid route type\n");
12465 return CMD_WARNING_CONFIG_FAILED;
12466 }
12467 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12468
12469 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12470 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12471 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12472 }
12473
12474 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12475 bgp_redistribute_ipv6_rmap_metric_cmd,
12476 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12477 "Redistribute information from another routing protocol\n"
12478 FRR_IP6_REDIST_HELP_STR_BGPD
12479 "Route map reference\n"
12480 "Pointer to route-map entries\n"
12481 "Metric for redistributed routes\n"
12482 "Default metric\n")
12483 {
12484 VTY_DECLVAR_CONTEXT(bgp, bgp);
12485 int idx_protocol = 1;
12486 int idx_word = 3;
12487 int idx_number = 5;
12488 int type;
12489 uint32_t metric;
12490 struct bgp_redist *red;
12491 bool changed;
12492 struct route_map *route_map =
12493 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12494
12495 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12496 if (type < 0) {
12497 vty_out(vty, "%% Invalid route type\n");
12498 return CMD_WARNING_CONFIG_FAILED;
12499 }
12500 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12501
12502 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12503 changed =
12504 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12505 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12506 metric);
12507 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12508 }
12509
12510 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12511 bgp_redistribute_ipv6_metric_rmap_cmd,
12512 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12513 "Redistribute information from another routing protocol\n"
12514 FRR_IP6_REDIST_HELP_STR_BGPD
12515 "Metric for redistributed routes\n"
12516 "Default metric\n"
12517 "Route map reference\n"
12518 "Pointer to route-map entries\n")
12519 {
12520 VTY_DECLVAR_CONTEXT(bgp, bgp);
12521 int idx_protocol = 1;
12522 int idx_number = 3;
12523 int idx_word = 5;
12524 int type;
12525 uint32_t metric;
12526 struct bgp_redist *red;
12527 bool changed;
12528 struct route_map *route_map =
12529 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12530
12531 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12532 if (type < 0) {
12533 vty_out(vty, "%% Invalid route type\n");
12534 return CMD_WARNING_CONFIG_FAILED;
12535 }
12536 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12537
12538 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12539 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12540 metric);
12541 changed |=
12542 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12543 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12544 }
12545
12546 DEFUN (no_bgp_redistribute_ipv6,
12547 no_bgp_redistribute_ipv6_cmd,
12548 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
12549 NO_STR
12550 "Redistribute information from another routing protocol\n"
12551 FRR_IP6_REDIST_HELP_STR_BGPD
12552 "Metric for redistributed routes\n"
12553 "Default metric\n"
12554 "Route map reference\n"
12555 "Pointer to route-map entries\n")
12556 {
12557 VTY_DECLVAR_CONTEXT(bgp, bgp);
12558 int idx_protocol = 2;
12559 int type;
12560
12561 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12562 if (type < 0) {
12563 vty_out(vty, "%% Invalid route type\n");
12564 return CMD_WARNING_CONFIG_FAILED;
12565 }
12566
12567 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12568 }
12569
12570 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12571 safi_t safi)
12572 {
12573 int i;
12574
12575 /* Unicast redistribution only. */
12576 if (safi != SAFI_UNICAST)
12577 return;
12578
12579 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12580 /* Redistribute BGP does not make sense. */
12581 if (i != ZEBRA_ROUTE_BGP) {
12582 struct list *red_list;
12583 struct listnode *node;
12584 struct bgp_redist *red;
12585
12586 red_list = bgp->redist[afi][i];
12587 if (!red_list)
12588 continue;
12589
12590 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12591 /* "redistribute" configuration. */
12592 vty_out(vty, " redistribute %s",
12593 zebra_route_string(i));
12594 if (red->instance)
12595 vty_out(vty, " %d", red->instance);
12596 if (red->redist_metric_flag)
12597 vty_out(vty, " metric %u",
12598 red->redist_metric);
12599 if (red->rmap.name)
12600 vty_out(vty, " route-map %s",
12601 red->rmap.name);
12602 vty_out(vty, "\n");
12603 }
12604 }
12605 }
12606 }
12607
12608 /* This is part of the address-family block (unicast only) */
12609 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12610 afi_t afi)
12611 {
12612 int indent = 2;
12613
12614 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12615 if (listcount(bgp->vpn_policy[afi].import_vrf))
12616 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12617 bgp->vpn_policy[afi]
12618 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12619 else
12620 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12621 bgp->vpn_policy[afi]
12622 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12623 }
12624 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12625 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12626 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12627 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12628 return;
12629
12630 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12631 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12632
12633 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12634
12635 } else {
12636 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12637 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12638 bgp->vpn_policy[afi].tovpn_label);
12639 }
12640 }
12641 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12642 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12643 char buf[RD_ADDRSTRLEN];
12644 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12645 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12646 sizeof(buf)));
12647 }
12648 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12649 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12650
12651 char buf[PREFIX_STRLEN];
12652 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12653 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12654 sizeof(buf))) {
12655
12656 vty_out(vty, "%*snexthop vpn export %s\n",
12657 indent, "", buf);
12658 }
12659 }
12660 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12661 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12662 && ecommunity_cmp(
12663 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12664 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12665
12666 char *b = ecommunity_ecom2str(
12667 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12668 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12669 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12670 XFREE(MTYPE_ECOMMUNITY_STR, b);
12671 } else {
12672 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12673 char *b = ecommunity_ecom2str(
12674 bgp->vpn_policy[afi]
12675 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12676 ECOMMUNITY_FORMAT_ROUTE_MAP,
12677 ECOMMUNITY_ROUTE_TARGET);
12678 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12679 XFREE(MTYPE_ECOMMUNITY_STR, b);
12680 }
12681 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12682 char *b = ecommunity_ecom2str(
12683 bgp->vpn_policy[afi]
12684 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12685 ECOMMUNITY_FORMAT_ROUTE_MAP,
12686 ECOMMUNITY_ROUTE_TARGET);
12687 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12688 XFREE(MTYPE_ECOMMUNITY_STR, b);
12689 }
12690 }
12691
12692 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12693 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12694 bgp->vpn_policy[afi]
12695 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12696
12697 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12698 char *b = ecommunity_ecom2str(
12699 bgp->vpn_policy[afi]
12700 .import_redirect_rtlist,
12701 ECOMMUNITY_FORMAT_ROUTE_MAP,
12702 ECOMMUNITY_ROUTE_TARGET);
12703
12704 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12705 XFREE(MTYPE_ECOMMUNITY_STR, b);
12706 }
12707 }
12708
12709
12710 /* BGP node structure. */
12711 static struct cmd_node bgp_node = {
12712 BGP_NODE, "%s(config-router)# ", 1,
12713 };
12714
12715 static struct cmd_node bgp_ipv4_unicast_node = {
12716 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12717 };
12718
12719 static struct cmd_node bgp_ipv4_multicast_node = {
12720 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12721 };
12722
12723 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12724 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12725 };
12726
12727 static struct cmd_node bgp_ipv6_unicast_node = {
12728 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12729 };
12730
12731 static struct cmd_node bgp_ipv6_multicast_node = {
12732 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12733 };
12734
12735 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12736 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12737 };
12738
12739 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12740 "%s(config-router-af)# ", 1};
12741
12742 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12743 "%s(config-router-af-vpnv6)# ", 1};
12744
12745 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12746 "%s(config-router-evpn)# ", 1};
12747
12748 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12749 "%s(config-router-af-vni)# ", 1};
12750
12751 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12752 "%s(config-router-af)# ", 1};
12753
12754 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12755 "%s(config-router-af-vpnv6)# ", 1};
12756
12757 static void community_list_vty(void);
12758
12759 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12760 {
12761 struct bgp *bgp;
12762 struct peer *peer;
12763 struct listnode *lnbgp, *lnpeer;
12764
12765 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12766 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12767 /* only provide suggestions on the appropriate input
12768 * token type,
12769 * they'll otherwise show up multiple times */
12770 enum cmd_token_type match_type;
12771 char *name = peer->host;
12772
12773 if (peer->conf_if) {
12774 match_type = VARIABLE_TKN;
12775 name = peer->conf_if;
12776 } else if (strchr(peer->host, ':'))
12777 match_type = IPV6_TKN;
12778 else
12779 match_type = IPV4_TKN;
12780
12781 if (token->type != match_type)
12782 continue;
12783
12784 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12785 }
12786 }
12787 }
12788
12789 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12790 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12791 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12792 {.varname = "peer", .completions = bgp_ac_neighbor},
12793 {.completions = NULL}};
12794
12795 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12796 {
12797 struct bgp *bgp;
12798 struct peer_group *group;
12799 struct listnode *lnbgp, *lnpeer;
12800
12801 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12802 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12803 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12804 group->name));
12805 }
12806 }
12807
12808 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12809 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12810 {.completions = NULL} };
12811
12812 void bgp_vty_init(void)
12813 {
12814 cmd_variable_handler_register(bgp_var_neighbor);
12815 cmd_variable_handler_register(bgp_var_peergroup);
12816
12817 /* Install bgp top node. */
12818 install_node(&bgp_node, bgp_config_write);
12819 install_node(&bgp_ipv4_unicast_node, NULL);
12820 install_node(&bgp_ipv4_multicast_node, NULL);
12821 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12822 install_node(&bgp_ipv6_unicast_node, NULL);
12823 install_node(&bgp_ipv6_multicast_node, NULL);
12824 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12825 install_node(&bgp_vpnv4_node, NULL);
12826 install_node(&bgp_vpnv6_node, NULL);
12827 install_node(&bgp_evpn_node, NULL);
12828 install_node(&bgp_evpn_vni_node, NULL);
12829 install_node(&bgp_flowspecv4_node, NULL);
12830 install_node(&bgp_flowspecv6_node, NULL);
12831
12832 /* Install default VTY commands to new nodes. */
12833 install_default(BGP_NODE);
12834 install_default(BGP_IPV4_NODE);
12835 install_default(BGP_IPV4M_NODE);
12836 install_default(BGP_IPV4L_NODE);
12837 install_default(BGP_IPV6_NODE);
12838 install_default(BGP_IPV6M_NODE);
12839 install_default(BGP_IPV6L_NODE);
12840 install_default(BGP_VPNV4_NODE);
12841 install_default(BGP_VPNV6_NODE);
12842 install_default(BGP_FLOWSPECV4_NODE);
12843 install_default(BGP_FLOWSPECV6_NODE);
12844 install_default(BGP_EVPN_NODE);
12845 install_default(BGP_EVPN_VNI_NODE);
12846
12847 /* "bgp local-mac" hidden commands. */
12848 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12849 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12850
12851 /* bgp route-map delay-timer commands. */
12852 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12853 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12854
12855 /* Dummy commands (Currently not supported) */
12856 install_element(BGP_NODE, &no_synchronization_cmd);
12857 install_element(BGP_NODE, &no_auto_summary_cmd);
12858
12859 /* "router bgp" commands. */
12860 install_element(CONFIG_NODE, &router_bgp_cmd);
12861
12862 /* "no router bgp" commands. */
12863 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12864
12865 /* "bgp router-id" commands. */
12866 install_element(BGP_NODE, &bgp_router_id_cmd);
12867 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12868
12869 /* "bgp cluster-id" commands. */
12870 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12871 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12872
12873 /* "bgp confederation" commands. */
12874 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12875 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12876
12877 /* "bgp confederation peers" commands. */
12878 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12879 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12880
12881 /* bgp max-med command */
12882 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12883 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12884 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12885 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12886 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12887
12888 /* bgp disable-ebgp-connected-nh-check */
12889 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12890 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12891
12892 /* bgp update-delay command */
12893 install_element(BGP_NODE, &bgp_update_delay_cmd);
12894 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12895 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12896
12897 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12898 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12899 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12900 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12901
12902 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12903 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12904
12905 /* "maximum-paths" commands. */
12906 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12907 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12908 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12909 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12910 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12911 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12912 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12913 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12914 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12915 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12916 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12917 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12918 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12919 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12920 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12921
12922 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12923 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12924 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12925 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12926 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12927
12928 /* "timers bgp" commands. */
12929 install_element(BGP_NODE, &bgp_timers_cmd);
12930 install_element(BGP_NODE, &no_bgp_timers_cmd);
12931
12932 /* route-map delay-timer commands - per instance for backwards compat.
12933 */
12934 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12935 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12936
12937 /* "bgp client-to-client reflection" commands */
12938 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12939 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12940
12941 /* "bgp always-compare-med" commands */
12942 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12943 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12944
12945 /* bgp ebgp-requires-policy */
12946 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12947 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12948
12949 /* "bgp deterministic-med" commands */
12950 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12951 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12952
12953 /* "bgp graceful-restart" commands */
12954 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12955 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12956 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12957 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12958 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12959 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12960
12961 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12962 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12963
12964 /* "bgp graceful-shutdown" commands */
12965 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12966 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12967
12968 /* "bgp fast-external-failover" commands */
12969 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12970 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12971
12972 /* "bgp bestpath compare-routerid" commands */
12973 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12974 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12975
12976 /* "bgp bestpath as-path ignore" commands */
12977 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12978 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12979
12980 /* "bgp bestpath as-path confed" commands */
12981 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12982 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12983
12984 /* "bgp bestpath as-path multipath-relax" commands */
12985 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12986 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12987
12988 /* "bgp log-neighbor-changes" commands */
12989 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12990 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12991
12992 /* "bgp bestpath med" commands */
12993 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12994 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12995
12996 /* "no bgp default ipv4-unicast" commands. */
12997 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12998 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12999
13000 /* "bgp network import-check" commands. */
13001 install_element(BGP_NODE, &bgp_network_import_check_cmd);
13002 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
13003 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
13004
13005 /* "bgp default local-preference" commands. */
13006 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
13007 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
13008
13009 /* bgp default show-hostname */
13010 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
13011 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
13012
13013 /* "bgp default subgroup-pkt-queue-max" commands. */
13014 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
13015 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
13016
13017 /* bgp ibgp-allow-policy-mods command */
13018 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
13019 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
13020
13021 /* "bgp listen limit" commands. */
13022 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13023 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13024
13025 /* "bgp listen range" commands. */
13026 install_element(BGP_NODE, &bgp_listen_range_cmd);
13027 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13028
13029 /* "bgp default shutdown" command */
13030 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13031
13032 /* "neighbor remote-as" commands. */
13033 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13034 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13035 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13036 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13037 install_element(BGP_NODE,
13038 &neighbor_interface_v6only_config_remote_as_cmd);
13039 install_element(BGP_NODE, &no_neighbor_cmd);
13040 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13041
13042 /* "neighbor peer-group" commands. */
13043 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13044 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13045 install_element(BGP_NODE,
13046 &no_neighbor_interface_peer_group_remote_as_cmd);
13047
13048 /* "neighbor local-as" commands. */
13049 install_element(BGP_NODE, &neighbor_local_as_cmd);
13050 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13051 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13052 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13053
13054 /* "neighbor solo" commands. */
13055 install_element(BGP_NODE, &neighbor_solo_cmd);
13056 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13057
13058 /* "neighbor password" commands. */
13059 install_element(BGP_NODE, &neighbor_password_cmd);
13060 install_element(BGP_NODE, &no_neighbor_password_cmd);
13061
13062 /* "neighbor activate" commands. */
13063 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13064 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13065 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13066 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13067 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13068 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13069 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13070 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13071 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13072 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13073 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13074 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13075
13076 /* "no neighbor activate" commands. */
13077 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13078 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13079 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13080 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13081 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13082 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13083 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13084 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13085 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13086 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13087 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13088 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13089
13090 /* "neighbor peer-group" set commands. */
13091 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13092 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13093 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13094 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13095 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13096 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13097 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13098 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13099 install_element(BGP_FLOWSPECV4_NODE,
13100 &neighbor_set_peer_group_hidden_cmd);
13101 install_element(BGP_FLOWSPECV6_NODE,
13102 &neighbor_set_peer_group_hidden_cmd);
13103
13104 /* "no neighbor peer-group unset" commands. */
13105 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13106 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13107 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13108 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13109 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13110 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13111 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13112 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13113 install_element(BGP_FLOWSPECV4_NODE,
13114 &no_neighbor_set_peer_group_hidden_cmd);
13115 install_element(BGP_FLOWSPECV6_NODE,
13116 &no_neighbor_set_peer_group_hidden_cmd);
13117
13118 /* "neighbor softreconfiguration inbound" commands.*/
13119 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13120 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13121 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13122 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13123 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13124 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13125 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13126 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13127 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13128 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13129 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13130 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13131 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13132 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13133 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13134 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13135 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13136 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13137 install_element(BGP_FLOWSPECV4_NODE,
13138 &neighbor_soft_reconfiguration_cmd);
13139 install_element(BGP_FLOWSPECV4_NODE,
13140 &no_neighbor_soft_reconfiguration_cmd);
13141 install_element(BGP_FLOWSPECV6_NODE,
13142 &neighbor_soft_reconfiguration_cmd);
13143 install_element(BGP_FLOWSPECV6_NODE,
13144 &no_neighbor_soft_reconfiguration_cmd);
13145 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13146 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13147
13148 /* "neighbor attribute-unchanged" commands. */
13149 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13150 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13151 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13152 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13153 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13154 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13155 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13156 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13157 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13158 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13159 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13160 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13161 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13162 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13163 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13164 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13165 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13166 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13167
13168 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13169 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13170
13171 /* "nexthop-local unchanged" commands */
13172 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13173 install_element(BGP_IPV6_NODE,
13174 &no_neighbor_nexthop_local_unchanged_cmd);
13175
13176 /* "neighbor next-hop-self" commands. */
13177 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13178 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13179 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13180 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13181 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13182 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13183 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13184 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13185 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13186 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13187 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13188 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13189 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13190 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13191 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13192 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13193 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13194 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13195 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13196 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13197
13198 /* "neighbor next-hop-self force" commands. */
13199 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13200 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13201 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13202 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13203 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13204 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13205 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13206 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13207 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13208 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13209 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13210 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13211 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13212 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13213 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13214 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13215 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13216 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13217 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13218 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13219
13220 /* "neighbor as-override" commands. */
13221 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13222 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13223 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13224 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13225 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13226 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13227 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13228 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13229 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13230 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13231 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13232 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13233 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13234 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13235 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13236 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13237 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13238 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13239
13240 /* "neighbor remove-private-AS" commands. */
13241 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13242 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13243 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13244 install_element(BGP_NODE,
13245 &no_neighbor_remove_private_as_all_hidden_cmd);
13246 install_element(BGP_NODE,
13247 &neighbor_remove_private_as_replace_as_hidden_cmd);
13248 install_element(BGP_NODE,
13249 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13250 install_element(BGP_NODE,
13251 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13252 install_element(
13253 BGP_NODE,
13254 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13255 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13256 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13257 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13258 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13259 install_element(BGP_IPV4_NODE,
13260 &neighbor_remove_private_as_replace_as_cmd);
13261 install_element(BGP_IPV4_NODE,
13262 &no_neighbor_remove_private_as_replace_as_cmd);
13263 install_element(BGP_IPV4_NODE,
13264 &neighbor_remove_private_as_all_replace_as_cmd);
13265 install_element(BGP_IPV4_NODE,
13266 &no_neighbor_remove_private_as_all_replace_as_cmd);
13267 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13268 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13269 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13270 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13271 install_element(BGP_IPV4M_NODE,
13272 &neighbor_remove_private_as_replace_as_cmd);
13273 install_element(BGP_IPV4M_NODE,
13274 &no_neighbor_remove_private_as_replace_as_cmd);
13275 install_element(BGP_IPV4M_NODE,
13276 &neighbor_remove_private_as_all_replace_as_cmd);
13277 install_element(BGP_IPV4M_NODE,
13278 &no_neighbor_remove_private_as_all_replace_as_cmd);
13279 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13280 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13281 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13282 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13283 install_element(BGP_IPV4L_NODE,
13284 &neighbor_remove_private_as_replace_as_cmd);
13285 install_element(BGP_IPV4L_NODE,
13286 &no_neighbor_remove_private_as_replace_as_cmd);
13287 install_element(BGP_IPV4L_NODE,
13288 &neighbor_remove_private_as_all_replace_as_cmd);
13289 install_element(BGP_IPV4L_NODE,
13290 &no_neighbor_remove_private_as_all_replace_as_cmd);
13291 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13292 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13293 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13294 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13295 install_element(BGP_IPV6_NODE,
13296 &neighbor_remove_private_as_replace_as_cmd);
13297 install_element(BGP_IPV6_NODE,
13298 &no_neighbor_remove_private_as_replace_as_cmd);
13299 install_element(BGP_IPV6_NODE,
13300 &neighbor_remove_private_as_all_replace_as_cmd);
13301 install_element(BGP_IPV6_NODE,
13302 &no_neighbor_remove_private_as_all_replace_as_cmd);
13303 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13304 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13305 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13306 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13307 install_element(BGP_IPV6M_NODE,
13308 &neighbor_remove_private_as_replace_as_cmd);
13309 install_element(BGP_IPV6M_NODE,
13310 &no_neighbor_remove_private_as_replace_as_cmd);
13311 install_element(BGP_IPV6M_NODE,
13312 &neighbor_remove_private_as_all_replace_as_cmd);
13313 install_element(BGP_IPV6M_NODE,
13314 &no_neighbor_remove_private_as_all_replace_as_cmd);
13315 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13316 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13317 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13318 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13319 install_element(BGP_IPV6L_NODE,
13320 &neighbor_remove_private_as_replace_as_cmd);
13321 install_element(BGP_IPV6L_NODE,
13322 &no_neighbor_remove_private_as_replace_as_cmd);
13323 install_element(BGP_IPV6L_NODE,
13324 &neighbor_remove_private_as_all_replace_as_cmd);
13325 install_element(BGP_IPV6L_NODE,
13326 &no_neighbor_remove_private_as_all_replace_as_cmd);
13327 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13328 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13329 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13330 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13331 install_element(BGP_VPNV4_NODE,
13332 &neighbor_remove_private_as_replace_as_cmd);
13333 install_element(BGP_VPNV4_NODE,
13334 &no_neighbor_remove_private_as_replace_as_cmd);
13335 install_element(BGP_VPNV4_NODE,
13336 &neighbor_remove_private_as_all_replace_as_cmd);
13337 install_element(BGP_VPNV4_NODE,
13338 &no_neighbor_remove_private_as_all_replace_as_cmd);
13339 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13340 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13341 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13342 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13343 install_element(BGP_VPNV6_NODE,
13344 &neighbor_remove_private_as_replace_as_cmd);
13345 install_element(BGP_VPNV6_NODE,
13346 &no_neighbor_remove_private_as_replace_as_cmd);
13347 install_element(BGP_VPNV6_NODE,
13348 &neighbor_remove_private_as_all_replace_as_cmd);
13349 install_element(BGP_VPNV6_NODE,
13350 &no_neighbor_remove_private_as_all_replace_as_cmd);
13351
13352 /* "neighbor send-community" commands.*/
13353 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13354 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13355 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13356 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13357 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13358 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13359 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13360 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13361 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13362 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13363 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13364 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13365 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13366 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13367 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13368 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13369 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13370 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13371 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13372 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13373 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13374 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13375 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13376 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13377 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13378 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13379 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13380 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13381 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13382 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13383 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13384 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13385 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13386 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13387 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13388 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13389
13390 /* "neighbor route-reflector" commands.*/
13391 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13392 install_element(BGP_NODE,
13393 &no_neighbor_route_reflector_client_hidden_cmd);
13394 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13395 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13396 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13397 install_element(BGP_IPV4M_NODE,
13398 &no_neighbor_route_reflector_client_cmd);
13399 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13400 install_element(BGP_IPV4L_NODE,
13401 &no_neighbor_route_reflector_client_cmd);
13402 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13403 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13404 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13405 install_element(BGP_IPV6M_NODE,
13406 &no_neighbor_route_reflector_client_cmd);
13407 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13408 install_element(BGP_IPV6L_NODE,
13409 &no_neighbor_route_reflector_client_cmd);
13410 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13411 install_element(BGP_VPNV4_NODE,
13412 &no_neighbor_route_reflector_client_cmd);
13413 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13414 install_element(BGP_VPNV6_NODE,
13415 &no_neighbor_route_reflector_client_cmd);
13416 install_element(BGP_FLOWSPECV4_NODE,
13417 &neighbor_route_reflector_client_cmd);
13418 install_element(BGP_FLOWSPECV4_NODE,
13419 &no_neighbor_route_reflector_client_cmd);
13420 install_element(BGP_FLOWSPECV6_NODE,
13421 &neighbor_route_reflector_client_cmd);
13422 install_element(BGP_FLOWSPECV6_NODE,
13423 &no_neighbor_route_reflector_client_cmd);
13424 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13425 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13426
13427 /* "neighbor route-server" commands.*/
13428 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13429 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13430 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13431 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13432 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13433 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13434 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13435 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13436 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13437 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13438 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13439 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13440 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13441 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13442 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13443 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13444 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13445 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13446 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13447 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13448 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13449 install_element(BGP_FLOWSPECV4_NODE,
13450 &no_neighbor_route_server_client_cmd);
13451 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13452 install_element(BGP_FLOWSPECV6_NODE,
13453 &no_neighbor_route_server_client_cmd);
13454
13455 /* "neighbor addpath-tx-all-paths" commands.*/
13456 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13457 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13458 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13459 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13460 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13461 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13462 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13463 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13464 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13465 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13466 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13467 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13468 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13469 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13470 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13471 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13472 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13473 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13474
13475 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13476 install_element(BGP_NODE,
13477 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13478 install_element(BGP_NODE,
13479 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13480 install_element(BGP_IPV4_NODE,
13481 &neighbor_addpath_tx_bestpath_per_as_cmd);
13482 install_element(BGP_IPV4_NODE,
13483 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13484 install_element(BGP_IPV4M_NODE,
13485 &neighbor_addpath_tx_bestpath_per_as_cmd);
13486 install_element(BGP_IPV4M_NODE,
13487 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13488 install_element(BGP_IPV4L_NODE,
13489 &neighbor_addpath_tx_bestpath_per_as_cmd);
13490 install_element(BGP_IPV4L_NODE,
13491 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13492 install_element(BGP_IPV6_NODE,
13493 &neighbor_addpath_tx_bestpath_per_as_cmd);
13494 install_element(BGP_IPV6_NODE,
13495 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13496 install_element(BGP_IPV6M_NODE,
13497 &neighbor_addpath_tx_bestpath_per_as_cmd);
13498 install_element(BGP_IPV6M_NODE,
13499 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13500 install_element(BGP_IPV6L_NODE,
13501 &neighbor_addpath_tx_bestpath_per_as_cmd);
13502 install_element(BGP_IPV6L_NODE,
13503 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13504 install_element(BGP_VPNV4_NODE,
13505 &neighbor_addpath_tx_bestpath_per_as_cmd);
13506 install_element(BGP_VPNV4_NODE,
13507 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13508 install_element(BGP_VPNV6_NODE,
13509 &neighbor_addpath_tx_bestpath_per_as_cmd);
13510 install_element(BGP_VPNV6_NODE,
13511 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13512
13513 /* "neighbor passive" commands. */
13514 install_element(BGP_NODE, &neighbor_passive_cmd);
13515 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13516
13517
13518 /* "neighbor shutdown" commands. */
13519 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13520 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13521 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13522 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13523
13524 /* "neighbor capability extended-nexthop" commands.*/
13525 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13526 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13527
13528 /* "neighbor capability orf prefix-list" commands.*/
13529 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13530 install_element(BGP_NODE,
13531 &no_neighbor_capability_orf_prefix_hidden_cmd);
13532 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13533 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13534 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13535 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13536 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13537 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13538 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13539 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13540 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13541 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13542 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13543 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13544
13545 /* "neighbor capability dynamic" commands.*/
13546 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13547 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13548
13549 /* "neighbor dont-capability-negotiate" commands. */
13550 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13551 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13552
13553 /* "neighbor ebgp-multihop" commands. */
13554 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13555 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13556 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13557
13558 /* "neighbor disable-connected-check" commands. */
13559 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13560 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13561
13562 /* "neighbor enforce-first-as" commands. */
13563 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13564 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13565
13566 /* "neighbor description" commands. */
13567 install_element(BGP_NODE, &neighbor_description_cmd);
13568 install_element(BGP_NODE, &no_neighbor_description_cmd);
13569 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13570
13571 /* "neighbor update-source" commands. "*/
13572 install_element(BGP_NODE, &neighbor_update_source_cmd);
13573 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13574
13575 /* "neighbor default-originate" commands. */
13576 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13577 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13578 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13579 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13580 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13581 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13582 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13583 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13584 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13585 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13586 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13587 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13588 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13589 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13590 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13591 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13592 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13593 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13594 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13595 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13596 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13597
13598 /* "neighbor port" commands. */
13599 install_element(BGP_NODE, &neighbor_port_cmd);
13600 install_element(BGP_NODE, &no_neighbor_port_cmd);
13601
13602 /* "neighbor weight" commands. */
13603 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13604 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13605
13606 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13607 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13608 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13609 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13610 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13611 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13612 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13613 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13614 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13615 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13616 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13617 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13618 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13619 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13620 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13621 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13622
13623 /* "neighbor override-capability" commands. */
13624 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13625 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13626
13627 /* "neighbor strict-capability-match" commands. */
13628 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13629 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13630
13631 /* "neighbor timers" commands. */
13632 install_element(BGP_NODE, &neighbor_timers_cmd);
13633 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13634
13635 /* "neighbor timers connect" commands. */
13636 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13637 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13638
13639 /* "neighbor advertisement-interval" commands. */
13640 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13641 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13642
13643 /* "neighbor interface" commands. */
13644 install_element(BGP_NODE, &neighbor_interface_cmd);
13645 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13646
13647 /* "neighbor distribute" commands. */
13648 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13649 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13650 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13651 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13652 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13653 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13654 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13655 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13656 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13657 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13658 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13659 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13660 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13661 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13662 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13663 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13664 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13665 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13666
13667 /* "neighbor prefix-list" commands. */
13668 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13669 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13670 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13671 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13672 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13673 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13674 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13675 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13676 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13677 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13678 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13679 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13680 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13681 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13682 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13683 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13684 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13685 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13686 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13687 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13688 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13689 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13690
13691 /* "neighbor filter-list" commands. */
13692 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13693 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13694 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13695 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13696 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13697 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13698 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13699 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13700 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13701 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13702 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13703 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13704 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13705 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13706 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13707 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13708 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13709 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13710 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13711 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13712 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13713 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13714
13715 /* "neighbor route-map" commands. */
13716 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13717 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13718 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13719 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13720 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13721 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13722 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13723 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13724 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13725 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13726 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13727 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13728 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13729 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13730 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13731 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13732 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13733 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13734 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13735 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13736 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13737 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13738 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13739 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13740
13741 /* "neighbor unsuppress-map" commands. */
13742 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13743 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13744 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13745 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13746 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13747 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13748 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13749 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13750 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13751 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13752 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13753 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13754 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13755 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13756 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13757 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13758 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13759 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13760
13761 /* "neighbor maximum-prefix" commands. */
13762 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13763 install_element(BGP_NODE,
13764 &neighbor_maximum_prefix_threshold_hidden_cmd);
13765 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13766 install_element(BGP_NODE,
13767 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13768 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13769 install_element(BGP_NODE,
13770 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13771 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13772 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13773 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13774 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13775 install_element(BGP_IPV4_NODE,
13776 &neighbor_maximum_prefix_threshold_warning_cmd);
13777 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13778 install_element(BGP_IPV4_NODE,
13779 &neighbor_maximum_prefix_threshold_restart_cmd);
13780 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13781 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13782 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13783 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13784 install_element(BGP_IPV4M_NODE,
13785 &neighbor_maximum_prefix_threshold_warning_cmd);
13786 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13787 install_element(BGP_IPV4M_NODE,
13788 &neighbor_maximum_prefix_threshold_restart_cmd);
13789 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13790 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13791 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13792 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13793 install_element(BGP_IPV4L_NODE,
13794 &neighbor_maximum_prefix_threshold_warning_cmd);
13795 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13796 install_element(BGP_IPV4L_NODE,
13797 &neighbor_maximum_prefix_threshold_restart_cmd);
13798 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13799 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13800 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13801 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13802 install_element(BGP_IPV6_NODE,
13803 &neighbor_maximum_prefix_threshold_warning_cmd);
13804 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13805 install_element(BGP_IPV6_NODE,
13806 &neighbor_maximum_prefix_threshold_restart_cmd);
13807 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13808 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13809 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13810 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13811 install_element(BGP_IPV6M_NODE,
13812 &neighbor_maximum_prefix_threshold_warning_cmd);
13813 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13814 install_element(BGP_IPV6M_NODE,
13815 &neighbor_maximum_prefix_threshold_restart_cmd);
13816 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13817 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13818 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13819 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13820 install_element(BGP_IPV6L_NODE,
13821 &neighbor_maximum_prefix_threshold_warning_cmd);
13822 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13823 install_element(BGP_IPV6L_NODE,
13824 &neighbor_maximum_prefix_threshold_restart_cmd);
13825 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13826 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13827 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13828 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13829 install_element(BGP_VPNV4_NODE,
13830 &neighbor_maximum_prefix_threshold_warning_cmd);
13831 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13832 install_element(BGP_VPNV4_NODE,
13833 &neighbor_maximum_prefix_threshold_restart_cmd);
13834 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13835 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13836 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13837 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13838 install_element(BGP_VPNV6_NODE,
13839 &neighbor_maximum_prefix_threshold_warning_cmd);
13840 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13841 install_element(BGP_VPNV6_NODE,
13842 &neighbor_maximum_prefix_threshold_restart_cmd);
13843 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13844
13845 /* "neighbor allowas-in" */
13846 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13847 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13848 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13849 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13850 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13851 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13852 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13853 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13854 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13855 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13856 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13857 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13858 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13859 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13860 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13861 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13862 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13863 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13864 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13865 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13866
13867 /* address-family commands. */
13868 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13869 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13870 #ifdef KEEP_OLD_VPN_COMMANDS
13871 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13872 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13873 #endif /* KEEP_OLD_VPN_COMMANDS */
13874
13875 install_element(BGP_NODE, &address_family_evpn_cmd);
13876
13877 /* "exit-address-family" command. */
13878 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13879 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13880 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13881 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13882 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13883 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13884 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13885 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13886 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13887 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13888 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13889
13890 /* "clear ip bgp commands" */
13891 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13892
13893 /* clear ip bgp prefix */
13894 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13895 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13896 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13897
13898 /* "show [ip] bgp summary" commands. */
13899 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13900 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13901 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13902 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13903 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13904 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13905 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13906
13907 /* "show [ip] bgp neighbors" commands. */
13908 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13909
13910 /* "show [ip] bgp peer-group" commands. */
13911 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13912
13913 /* "show [ip] bgp paths" commands. */
13914 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13915
13916 /* "show [ip] bgp community" commands. */
13917 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13918
13919 /* "show ip bgp large-community" commands. */
13920 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13921 /* "show [ip] bgp attribute-info" commands. */
13922 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13923 /* "show [ip] bgp route-leak" command */
13924 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13925
13926 /* "redistribute" commands. */
13927 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13928 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13929 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13930 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13931 install_element(BGP_NODE,
13932 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13933 install_element(BGP_NODE,
13934 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13935 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13936 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13937 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13938 install_element(BGP_NODE,
13939 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13940 install_element(BGP_NODE,
13941 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13942 install_element(BGP_NODE,
13943 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13944 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13945 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13946 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13947 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13948 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13949 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13950 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13951 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13952 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13953 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13954 install_element(BGP_IPV4_NODE,
13955 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13956 install_element(BGP_IPV4_NODE,
13957 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13958 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13959 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13960 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13961 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13962 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13963 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13964
13965 /* import|export vpn [route-map WORD] */
13966 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13967 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13968
13969 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13970 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13971
13972 /* ttl_security commands */
13973 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13974 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13975
13976 /* "show [ip] bgp memory" commands. */
13977 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13978
13979 /* "show bgp martian next-hop" */
13980 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13981
13982 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
13983
13984 /* "show [ip] bgp views" commands. */
13985 install_element(VIEW_NODE, &show_bgp_views_cmd);
13986
13987 /* "show [ip] bgp vrfs" commands. */
13988 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13989
13990 /* Community-list. */
13991 community_list_vty();
13992
13993 /* vpn-policy commands */
13994 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13995 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13996 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13997 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13998 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13999 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
14000 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
14001 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
14002 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
14003 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
14004 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
14005 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
14006
14007 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
14008 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
14009
14010 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
14011 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
14012 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
14013 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
14014 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
14015 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
14016 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
14017 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
14018 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
14019 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
14020 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
14021 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
14022 }
14023
14024 #include "memory.h"
14025 #include "bgp_regex.h"
14026 #include "bgp_clist.h"
14027 #include "bgp_ecommunity.h"
14028
14029 /* VTY functions. */
14030
14031 /* Direction value to string conversion. */
14032 static const char *community_direct_str(int direct)
14033 {
14034 switch (direct) {
14035 case COMMUNITY_DENY:
14036 return "deny";
14037 case COMMUNITY_PERMIT:
14038 return "permit";
14039 default:
14040 return "unknown";
14041 }
14042 }
14043
14044 /* Display error string. */
14045 static void community_list_perror(struct vty *vty, int ret)
14046 {
14047 switch (ret) {
14048 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14049 vty_out(vty, "%% Can't find community-list\n");
14050 break;
14051 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14052 vty_out(vty, "%% Malformed community-list value\n");
14053 break;
14054 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14055 vty_out(vty,
14056 "%% Community name conflict, previously defined as standard community\n");
14057 break;
14058 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14059 vty_out(vty,
14060 "%% Community name conflict, previously defined as expanded community\n");
14061 break;
14062 }
14063 }
14064
14065 /* "community-list" keyword help string. */
14066 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14067
14068 /*community-list standard */
14069 DEFUN (community_list_standard,
14070 bgp_community_list_standard_cmd,
14071 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14072 BGP_STR
14073 COMMUNITY_LIST_STR
14074 "Community list number (standard)\n"
14075 "Add an standard community-list entry\n"
14076 "Community list name\n"
14077 "Specify community to reject\n"
14078 "Specify community to accept\n"
14079 COMMUNITY_VAL_STR)
14080 {
14081 char *cl_name_or_number = NULL;
14082 int direct = 0;
14083 int style = COMMUNITY_LIST_STANDARD;
14084
14085 int idx = 0;
14086
14087 if (argv_find(argv, argc, "ip", &idx)) {
14088 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14089 vty_out(vty, "if you are using this please migrate to the below command.\n");
14090 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14091 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14092 }
14093
14094 argv_find(argv, argc, "(1-99)", &idx);
14095 argv_find(argv, argc, "WORD", &idx);
14096 cl_name_or_number = argv[idx]->arg;
14097 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14098 : COMMUNITY_DENY;
14099 argv_find(argv, argc, "AA:NN", &idx);
14100 char *str = argv_concat(argv, argc, idx);
14101
14102 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14103 style);
14104
14105 XFREE(MTYPE_TMP, str);
14106
14107 if (ret < 0) {
14108 /* Display error string. */
14109 community_list_perror(vty, ret);
14110 return CMD_WARNING_CONFIG_FAILED;
14111 }
14112
14113 return CMD_SUCCESS;
14114 }
14115
14116 #if CONFDATE > 20191005
14117 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14118 #endif
14119 ALIAS (community_list_standard,
14120 ip_community_list_standard_cmd,
14121 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14122 IP_STR
14123 COMMUNITY_LIST_STR
14124 "Community list number (standard)\n"
14125 "Add an standard community-list entry\n"
14126 "Community list name\n"
14127 "Specify community to reject\n"
14128 "Specify community to accept\n"
14129 COMMUNITY_VAL_STR)
14130
14131 DEFUN (no_community_list_standard_all,
14132 no_bgp_community_list_standard_all_cmd,
14133 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14134 NO_STR
14135 BGP_STR
14136 COMMUNITY_LIST_STR
14137 "Community list number (standard)\n"
14138 "Add an standard community-list entry\n"
14139 "Community list name\n"
14140 "Specify community to reject\n"
14141 "Specify community to accept\n"
14142 COMMUNITY_VAL_STR)
14143 {
14144 char *cl_name_or_number = NULL;
14145 char *str = NULL;
14146 int direct = 0;
14147 int style = COMMUNITY_LIST_STANDARD;
14148
14149 int idx = 0;
14150
14151 if (argv_find(argv, argc, "ip", &idx)) {
14152 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14153 vty_out(vty, "if you are using this please migrate to the below command.\n");
14154 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14155 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14156 }
14157
14158 argv_find(argv, argc, "permit", &idx);
14159 argv_find(argv, argc, "deny", &idx);
14160
14161 if (idx) {
14162 direct = argv_find(argv, argc, "permit", &idx)
14163 ? COMMUNITY_PERMIT
14164 : COMMUNITY_DENY;
14165
14166 idx = 0;
14167 argv_find(argv, argc, "AA:NN", &idx);
14168 str = argv_concat(argv, argc, idx);
14169 }
14170
14171 idx = 0;
14172 argv_find(argv, argc, "(1-99)", &idx);
14173 argv_find(argv, argc, "WORD", &idx);
14174 cl_name_or_number = argv[idx]->arg;
14175
14176 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14177 direct, style);
14178
14179 XFREE(MTYPE_TMP, str);
14180
14181 if (ret < 0) {
14182 community_list_perror(vty, ret);
14183 return CMD_WARNING_CONFIG_FAILED;
14184 }
14185
14186 return CMD_SUCCESS;
14187 }
14188 ALIAS (no_community_list_standard_all,
14189 no_ip_community_list_standard_all_cmd,
14190 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14191 NO_STR
14192 IP_STR
14193 COMMUNITY_LIST_STR
14194 "Community list number (standard)\n"
14195 "Add an standard community-list entry\n"
14196 "Community list name\n"
14197 "Specify community to reject\n"
14198 "Specify community to accept\n"
14199 COMMUNITY_VAL_STR)
14200
14201 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14202 "no bgp community-list <(1-99)|standard WORD>",
14203 NO_STR BGP_STR COMMUNITY_LIST_STR
14204 "Community list number (standard)\n"
14205 "Add an standard community-list entry\n"
14206 "Community list name\n")
14207
14208 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14209 "no ip community-list <(1-99)|standard WORD>",
14210 NO_STR BGP_STR COMMUNITY_LIST_STR
14211 "Community list number (standard)\n"
14212 "Add an standard community-list entry\n"
14213 "Community list name\n")
14214
14215 /*community-list expanded */
14216 DEFUN (community_list_expanded_all,
14217 bgp_community_list_expanded_all_cmd,
14218 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14219 BGP_STR
14220 COMMUNITY_LIST_STR
14221 "Community list number (expanded)\n"
14222 "Add an expanded community-list entry\n"
14223 "Community list name\n"
14224 "Specify community to reject\n"
14225 "Specify community to accept\n"
14226 COMMUNITY_VAL_STR)
14227 {
14228 char *cl_name_or_number = NULL;
14229 int direct = 0;
14230 int style = COMMUNITY_LIST_EXPANDED;
14231
14232 int idx = 0;
14233 if (argv_find(argv, argc, "ip", &idx)) {
14234 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14235 vty_out(vty, "if you are using this please migrate to the below command.\n");
14236 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14237 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14238 }
14239 argv_find(argv, argc, "(100-500)", &idx);
14240 argv_find(argv, argc, "WORD", &idx);
14241 cl_name_or_number = argv[idx]->arg;
14242 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14243 : COMMUNITY_DENY;
14244 argv_find(argv, argc, "AA:NN", &idx);
14245 char *str = argv_concat(argv, argc, idx);
14246
14247 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14248 style);
14249
14250 XFREE(MTYPE_TMP, str);
14251
14252 if (ret < 0) {
14253 /* Display error string. */
14254 community_list_perror(vty, ret);
14255 return CMD_WARNING_CONFIG_FAILED;
14256 }
14257
14258 return CMD_SUCCESS;
14259 }
14260
14261 ALIAS (community_list_expanded_all,
14262 ip_community_list_expanded_all_cmd,
14263 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14264 IP_STR
14265 COMMUNITY_LIST_STR
14266 "Community list number (expanded)\n"
14267 "Add an expanded community-list entry\n"
14268 "Community list name\n"
14269 "Specify community to reject\n"
14270 "Specify community to accept\n"
14271 COMMUNITY_VAL_STR)
14272
14273 DEFUN (no_community_list_expanded_all,
14274 no_bgp_community_list_expanded_all_cmd,
14275 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14276 NO_STR
14277 BGP_STR
14278 COMMUNITY_LIST_STR
14279 "Community list number (expanded)\n"
14280 "Add an expanded community-list entry\n"
14281 "Community list name\n"
14282 "Specify community to reject\n"
14283 "Specify community to accept\n"
14284 COMMUNITY_VAL_STR)
14285 {
14286 char *cl_name_or_number = NULL;
14287 char *str = NULL;
14288 int direct = 0;
14289 int style = COMMUNITY_LIST_EXPANDED;
14290
14291 int idx = 0;
14292 if (argv_find(argv, argc, "ip", &idx)) {
14293 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14294 vty_out(vty, "if you are using this please migrate to the below command.\n");
14295 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14296 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14297 }
14298
14299 idx = 0;
14300 argv_find(argv, argc, "permit", &idx);
14301 argv_find(argv, argc, "deny", &idx);
14302
14303 if (idx) {
14304 direct = argv_find(argv, argc, "permit", &idx)
14305 ? COMMUNITY_PERMIT
14306 : COMMUNITY_DENY;
14307
14308 idx = 0;
14309 argv_find(argv, argc, "AA:NN", &idx);
14310 str = argv_concat(argv, argc, idx);
14311 }
14312
14313 idx = 0;
14314 argv_find(argv, argc, "(100-500)", &idx);
14315 argv_find(argv, argc, "WORD", &idx);
14316 cl_name_or_number = argv[idx]->arg;
14317
14318 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14319 direct, style);
14320
14321 XFREE(MTYPE_TMP, str);
14322
14323 if (ret < 0) {
14324 community_list_perror(vty, ret);
14325 return CMD_WARNING_CONFIG_FAILED;
14326 }
14327
14328 return CMD_SUCCESS;
14329 }
14330
14331 ALIAS (no_community_list_expanded_all,
14332 no_ip_community_list_expanded_all_cmd,
14333 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14334 NO_STR
14335 IP_STR
14336 COMMUNITY_LIST_STR
14337 "Community list number (expanded)\n"
14338 "Add an expanded community-list entry\n"
14339 "Community list name\n"
14340 "Specify community to reject\n"
14341 "Specify community to accept\n"
14342 COMMUNITY_VAL_STR)
14343
14344 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14345 "no bgp community-list <(100-500)|expanded WORD>",
14346 NO_STR IP_STR COMMUNITY_LIST_STR
14347 "Community list number (expanded)\n"
14348 "Add an expanded community-list entry\n"
14349 "Community list name\n")
14350
14351 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14352 "no ip community-list <(100-500)|expanded WORD>",
14353 NO_STR IP_STR COMMUNITY_LIST_STR
14354 "Community list number (expanded)\n"
14355 "Add an expanded community-list entry\n"
14356 "Community list name\n")
14357
14358 /* Return configuration string of community-list entry. */
14359 static const char *community_list_config_str(struct community_entry *entry)
14360 {
14361 const char *str;
14362
14363 if (entry->any)
14364 str = "";
14365 else {
14366 if (entry->style == COMMUNITY_LIST_STANDARD)
14367 str = community_str(entry->u.com, false);
14368 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14369 str = lcommunity_str(entry->u.lcom, false);
14370 else
14371 str = entry->config;
14372 }
14373 return str;
14374 }
14375
14376 static void community_list_show(struct vty *vty, struct community_list *list)
14377 {
14378 struct community_entry *entry;
14379
14380 for (entry = list->head; entry; entry = entry->next) {
14381 if (entry == list->head) {
14382 if (all_digit(list->name))
14383 vty_out(vty, "Community %s list %s\n",
14384 entry->style == COMMUNITY_LIST_STANDARD
14385 ? "standard"
14386 : "(expanded) access",
14387 list->name);
14388 else
14389 vty_out(vty, "Named Community %s list %s\n",
14390 entry->style == COMMUNITY_LIST_STANDARD
14391 ? "standard"
14392 : "expanded",
14393 list->name);
14394 }
14395 if (entry->any)
14396 vty_out(vty, " %s\n",
14397 community_direct_str(entry->direct));
14398 else
14399 vty_out(vty, " %s %s\n",
14400 community_direct_str(entry->direct),
14401 community_list_config_str(entry));
14402 }
14403 }
14404
14405 DEFUN (show_community_list,
14406 show_bgp_community_list_cmd,
14407 "show bgp community-list",
14408 SHOW_STR
14409 BGP_STR
14410 "List community-list\n")
14411 {
14412 struct community_list *list;
14413 struct community_list_master *cm;
14414
14415 int idx = 0;
14416 if (argv_find(argv, argc, "ip", &idx)) {
14417 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14418 vty_out(vty, "if you are using this please migrate to the below command.\n");
14419 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14420 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14421 }
14422 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14423 if (!cm)
14424 return CMD_SUCCESS;
14425
14426 for (list = cm->num.head; list; list = list->next)
14427 community_list_show(vty, list);
14428
14429 for (list = cm->str.head; list; list = list->next)
14430 community_list_show(vty, list);
14431
14432 return CMD_SUCCESS;
14433 }
14434
14435 ALIAS (show_community_list,
14436 show_ip_community_list_cmd,
14437 "show ip community-list",
14438 SHOW_STR
14439 IP_STR
14440 "List community-list\n")
14441
14442 DEFUN (show_community_list_arg,
14443 show_bgp_community_list_arg_cmd,
14444 "show bgp community-list <(1-500)|WORD>",
14445 SHOW_STR
14446 BGP_STR
14447 "List community-list\n"
14448 "Community-list number\n"
14449 "Community-list name\n")
14450 {
14451 int idx_comm_list = 3;
14452 struct community_list *list;
14453
14454 int idx = 0;
14455 if (argv_find(argv, argc, "ip", &idx)) {
14456 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14457 vty_out(vty, "if you are using this please migrate to the below command.\n");
14458 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14459 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14460 }
14461 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14462 COMMUNITY_LIST_MASTER);
14463 if (!list) {
14464 vty_out(vty, "%% Can't find community-list\n");
14465 return CMD_WARNING;
14466 }
14467
14468 community_list_show(vty, list);
14469
14470 return CMD_SUCCESS;
14471 }
14472
14473 ALIAS (show_community_list_arg,
14474 show_ip_community_list_arg_cmd,
14475 "show ip community-list <(1-500)|WORD>",
14476 SHOW_STR
14477 IP_STR
14478 "List community-list\n"
14479 "Community-list number\n"
14480 "Community-list name\n")
14481
14482 /*
14483 * Large Community code.
14484 */
14485 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14486 struct cmd_token **argv, int style,
14487 int reject_all_digit_name)
14488 {
14489 int ret;
14490 int direct;
14491 char *str;
14492 int idx = 0;
14493 char *cl_name;
14494
14495 if (argv_find(argv, argc, "ip", &idx)) {
14496 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14497 vty_out(vty, "if you are using this please migrate to the below command.\n");
14498 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14499 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14500 }
14501 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14502 : COMMUNITY_DENY;
14503
14504 /* All digit name check. */
14505 idx = 0;
14506 argv_find(argv, argc, "WORD", &idx);
14507 argv_find(argv, argc, "(1-99)", &idx);
14508 argv_find(argv, argc, "(100-500)", &idx);
14509 cl_name = argv[idx]->arg;
14510 if (reject_all_digit_name && all_digit(cl_name)) {
14511 vty_out(vty, "%% Community name cannot have all digits\n");
14512 return CMD_WARNING_CONFIG_FAILED;
14513 }
14514
14515 idx = 0;
14516 argv_find(argv, argc, "AA:BB:CC", &idx);
14517 argv_find(argv, argc, "LINE", &idx);
14518 /* Concat community string argument. */
14519 if (idx)
14520 str = argv_concat(argv, argc, idx);
14521 else
14522 str = NULL;
14523
14524 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14525
14526 /* Free temporary community list string allocated by
14527 argv_concat(). */
14528 XFREE(MTYPE_TMP, str);
14529
14530 if (ret < 0) {
14531 community_list_perror(vty, ret);
14532 return CMD_WARNING_CONFIG_FAILED;
14533 }
14534 return CMD_SUCCESS;
14535 }
14536
14537 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14538 struct cmd_token **argv, int style)
14539 {
14540 int ret;
14541 int direct = 0;
14542 char *str = NULL;
14543 int idx = 0;
14544
14545 if (argv_find(argv, argc, "ip", &idx)) {
14546 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14547 vty_out(vty, "if you are using this please migrate to the below command.\n");
14548 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14549 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14550 }
14551 argv_find(argv, argc, "permit", &idx);
14552 argv_find(argv, argc, "deny", &idx);
14553
14554 if (idx) {
14555 /* Check the list direct. */
14556 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14557 direct = COMMUNITY_PERMIT;
14558 else
14559 direct = COMMUNITY_DENY;
14560
14561 idx = 0;
14562 argv_find(argv, argc, "LINE", &idx);
14563 argv_find(argv, argc, "AA:AA:NN", &idx);
14564 /* Concat community string argument. */
14565 str = argv_concat(argv, argc, idx);
14566 }
14567
14568 idx = 0;
14569 argv_find(argv, argc, "(1-99)", &idx);
14570 argv_find(argv, argc, "(100-500)", &idx);
14571 argv_find(argv, argc, "WORD", &idx);
14572
14573 /* Unset community list. */
14574 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14575 style);
14576
14577 /* Free temporary community list string allocated by
14578 argv_concat(). */
14579 XFREE(MTYPE_TMP, str);
14580
14581 if (ret < 0) {
14582 community_list_perror(vty, ret);
14583 return CMD_WARNING_CONFIG_FAILED;
14584 }
14585
14586 return CMD_SUCCESS;
14587 }
14588
14589 /* "large-community-list" keyword help string. */
14590 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14591 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14592
14593 #if CONFDATE > 20191005
14594 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14595 #endif
14596 DEFUN (lcommunity_list_standard,
14597 bgp_lcommunity_list_standard_cmd,
14598 "bgp large-community-list (1-99) <deny|permit>",
14599 BGP_STR
14600 LCOMMUNITY_LIST_STR
14601 "Large Community list number (standard)\n"
14602 "Specify large community to reject\n"
14603 "Specify large community to accept\n")
14604 {
14605 return lcommunity_list_set_vty(vty, argc, argv,
14606 LARGE_COMMUNITY_LIST_STANDARD, 0);
14607 }
14608
14609 ALIAS (lcommunity_list_standard,
14610 ip_lcommunity_list_standard_cmd,
14611 "ip large-community-list (1-99) <deny|permit>",
14612 IP_STR
14613 LCOMMUNITY_LIST_STR
14614 "Large Community list number (standard)\n"
14615 "Specify large community to reject\n"
14616 "Specify large community to accept\n")
14617
14618 DEFUN (lcommunity_list_standard1,
14619 bgp_lcommunity_list_standard1_cmd,
14620 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14621 BGP_STR
14622 LCOMMUNITY_LIST_STR
14623 "Large Community list number (standard)\n"
14624 "Specify large community to reject\n"
14625 "Specify large community to accept\n"
14626 LCOMMUNITY_VAL_STR)
14627 {
14628 return lcommunity_list_set_vty(vty, argc, argv,
14629 LARGE_COMMUNITY_LIST_STANDARD, 0);
14630 }
14631
14632 ALIAS (lcommunity_list_standard1,
14633 ip_lcommunity_list_standard1_cmd,
14634 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14635 IP_STR
14636 LCOMMUNITY_LIST_STR
14637 "Large Community list number (standard)\n"
14638 "Specify large community to reject\n"
14639 "Specify large community to accept\n"
14640 LCOMMUNITY_VAL_STR)
14641
14642 DEFUN (lcommunity_list_expanded,
14643 bgp_lcommunity_list_expanded_cmd,
14644 "bgp large-community-list (100-500) <deny|permit> LINE...",
14645 BGP_STR
14646 LCOMMUNITY_LIST_STR
14647 "Large Community list number (expanded)\n"
14648 "Specify large community to reject\n"
14649 "Specify large community to accept\n"
14650 "An ordered list as a regular-expression\n")
14651 {
14652 return lcommunity_list_set_vty(vty, argc, argv,
14653 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14654 }
14655
14656 ALIAS (lcommunity_list_expanded,
14657 ip_lcommunity_list_expanded_cmd,
14658 "ip large-community-list (100-500) <deny|permit> LINE...",
14659 IP_STR
14660 LCOMMUNITY_LIST_STR
14661 "Large Community list number (expanded)\n"
14662 "Specify large community to reject\n"
14663 "Specify large community to accept\n"
14664 "An ordered list as a regular-expression\n")
14665
14666 DEFUN (lcommunity_list_name_standard,
14667 bgp_lcommunity_list_name_standard_cmd,
14668 "bgp large-community-list standard WORD <deny|permit>",
14669 BGP_STR
14670 LCOMMUNITY_LIST_STR
14671 "Specify standard large-community-list\n"
14672 "Large Community list name\n"
14673 "Specify large community to reject\n"
14674 "Specify large community to accept\n")
14675 {
14676 return lcommunity_list_set_vty(vty, argc, argv,
14677 LARGE_COMMUNITY_LIST_STANDARD, 1);
14678 }
14679
14680 ALIAS (lcommunity_list_name_standard,
14681 ip_lcommunity_list_name_standard_cmd,
14682 "ip large-community-list standard WORD <deny|permit>",
14683 IP_STR
14684 LCOMMUNITY_LIST_STR
14685 "Specify standard large-community-list\n"
14686 "Large Community list name\n"
14687 "Specify large community to reject\n"
14688 "Specify large community to accept\n")
14689
14690 DEFUN (lcommunity_list_name_standard1,
14691 bgp_lcommunity_list_name_standard1_cmd,
14692 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14693 BGP_STR
14694 LCOMMUNITY_LIST_STR
14695 "Specify standard large-community-list\n"
14696 "Large Community list name\n"
14697 "Specify large community to reject\n"
14698 "Specify large community to accept\n"
14699 LCOMMUNITY_VAL_STR)
14700 {
14701 return lcommunity_list_set_vty(vty, argc, argv,
14702 LARGE_COMMUNITY_LIST_STANDARD, 1);
14703 }
14704
14705 ALIAS (lcommunity_list_name_standard1,
14706 ip_lcommunity_list_name_standard1_cmd,
14707 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14708 IP_STR
14709 LCOMMUNITY_LIST_STR
14710 "Specify standard large-community-list\n"
14711 "Large Community list name\n"
14712 "Specify large community to reject\n"
14713 "Specify large community to accept\n"
14714 LCOMMUNITY_VAL_STR)
14715
14716 DEFUN (lcommunity_list_name_expanded,
14717 bgp_lcommunity_list_name_expanded_cmd,
14718 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14719 BGP_STR
14720 LCOMMUNITY_LIST_STR
14721 "Specify expanded large-community-list\n"
14722 "Large Community list name\n"
14723 "Specify large community to reject\n"
14724 "Specify large community to accept\n"
14725 "An ordered list as a regular-expression\n")
14726 {
14727 return lcommunity_list_set_vty(vty, argc, argv,
14728 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14729 }
14730
14731 ALIAS (lcommunity_list_name_expanded,
14732 ip_lcommunity_list_name_expanded_cmd,
14733 "ip large-community-list expanded WORD <deny|permit> LINE...",
14734 IP_STR
14735 LCOMMUNITY_LIST_STR
14736 "Specify expanded large-community-list\n"
14737 "Large Community list name\n"
14738 "Specify large community to reject\n"
14739 "Specify large community to accept\n"
14740 "An ordered list as a regular-expression\n")
14741
14742 DEFUN (no_lcommunity_list_standard_all,
14743 no_bgp_lcommunity_list_standard_all_cmd,
14744 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14745 NO_STR
14746 BGP_STR
14747 LCOMMUNITY_LIST_STR
14748 "Large Community list number (standard)\n"
14749 "Large Community list number (expanded)\n"
14750 "Large Community list name\n")
14751 {
14752 return lcommunity_list_unset_vty(vty, argc, argv,
14753 LARGE_COMMUNITY_LIST_STANDARD);
14754 }
14755
14756 ALIAS (no_lcommunity_list_standard_all,
14757 no_ip_lcommunity_list_standard_all_cmd,
14758 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14759 NO_STR
14760 IP_STR
14761 LCOMMUNITY_LIST_STR
14762 "Large Community list number (standard)\n"
14763 "Large Community list number (expanded)\n"
14764 "Large Community list name\n")
14765
14766 DEFUN (no_lcommunity_list_name_expanded_all,
14767 no_bgp_lcommunity_list_name_expanded_all_cmd,
14768 "no bgp large-community-list expanded WORD",
14769 NO_STR
14770 BGP_STR
14771 LCOMMUNITY_LIST_STR
14772 "Specify expanded large-community-list\n"
14773 "Large Community list name\n")
14774 {
14775 return lcommunity_list_unset_vty(vty, argc, argv,
14776 LARGE_COMMUNITY_LIST_EXPANDED);
14777 }
14778
14779 ALIAS (no_lcommunity_list_name_expanded_all,
14780 no_ip_lcommunity_list_name_expanded_all_cmd,
14781 "no ip large-community-list expanded WORD",
14782 NO_STR
14783 IP_STR
14784 LCOMMUNITY_LIST_STR
14785 "Specify expanded large-community-list\n"
14786 "Large Community list name\n")
14787
14788 DEFUN (no_lcommunity_list_standard,
14789 no_bgp_lcommunity_list_standard_cmd,
14790 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14791 NO_STR
14792 BGP_STR
14793 LCOMMUNITY_LIST_STR
14794 "Large Community list number (standard)\n"
14795 "Specify large community to reject\n"
14796 "Specify large community to accept\n"
14797 LCOMMUNITY_VAL_STR)
14798 {
14799 return lcommunity_list_unset_vty(vty, argc, argv,
14800 LARGE_COMMUNITY_LIST_STANDARD);
14801 }
14802
14803 ALIAS (no_lcommunity_list_standard,
14804 no_ip_lcommunity_list_standard_cmd,
14805 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14806 NO_STR
14807 IP_STR
14808 LCOMMUNITY_LIST_STR
14809 "Large Community list number (standard)\n"
14810 "Specify large community to reject\n"
14811 "Specify large community to accept\n"
14812 LCOMMUNITY_VAL_STR)
14813
14814 DEFUN (no_lcommunity_list_expanded,
14815 no_bgp_lcommunity_list_expanded_cmd,
14816 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14817 NO_STR
14818 BGP_STR
14819 LCOMMUNITY_LIST_STR
14820 "Large Community list number (expanded)\n"
14821 "Specify large community to reject\n"
14822 "Specify large community to accept\n"
14823 "An ordered list as a regular-expression\n")
14824 {
14825 return lcommunity_list_unset_vty(vty, argc, argv,
14826 LARGE_COMMUNITY_LIST_EXPANDED);
14827 }
14828
14829 ALIAS (no_lcommunity_list_expanded,
14830 no_ip_lcommunity_list_expanded_cmd,
14831 "no ip large-community-list (100-500) <deny|permit> LINE...",
14832 NO_STR
14833 IP_STR
14834 LCOMMUNITY_LIST_STR
14835 "Large Community list number (expanded)\n"
14836 "Specify large community to reject\n"
14837 "Specify large community to accept\n"
14838 "An ordered list as a regular-expression\n")
14839
14840 DEFUN (no_lcommunity_list_name_standard,
14841 no_bgp_lcommunity_list_name_standard_cmd,
14842 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14843 NO_STR
14844 BGP_STR
14845 LCOMMUNITY_LIST_STR
14846 "Specify standard large-community-list\n"
14847 "Large Community list name\n"
14848 "Specify large community to reject\n"
14849 "Specify large community to accept\n"
14850 LCOMMUNITY_VAL_STR)
14851 {
14852 return lcommunity_list_unset_vty(vty, argc, argv,
14853 LARGE_COMMUNITY_LIST_STANDARD);
14854 }
14855
14856 ALIAS (no_lcommunity_list_name_standard,
14857 no_ip_lcommunity_list_name_standard_cmd,
14858 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14859 NO_STR
14860 IP_STR
14861 LCOMMUNITY_LIST_STR
14862 "Specify standard large-community-list\n"
14863 "Large Community list name\n"
14864 "Specify large community to reject\n"
14865 "Specify large community to accept\n"
14866 LCOMMUNITY_VAL_STR)
14867
14868 DEFUN (no_lcommunity_list_name_expanded,
14869 no_bgp_lcommunity_list_name_expanded_cmd,
14870 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14871 NO_STR
14872 BGP_STR
14873 LCOMMUNITY_LIST_STR
14874 "Specify expanded large-community-list\n"
14875 "Large community list name\n"
14876 "Specify large community to reject\n"
14877 "Specify large community to accept\n"
14878 "An ordered list as a regular-expression\n")
14879 {
14880 return lcommunity_list_unset_vty(vty, argc, argv,
14881 LARGE_COMMUNITY_LIST_EXPANDED);
14882 }
14883
14884 ALIAS (no_lcommunity_list_name_expanded,
14885 no_ip_lcommunity_list_name_expanded_cmd,
14886 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14887 NO_STR
14888 IP_STR
14889 LCOMMUNITY_LIST_STR
14890 "Specify expanded large-community-list\n"
14891 "Large community list name\n"
14892 "Specify large community to reject\n"
14893 "Specify large community to accept\n"
14894 "An ordered list as a regular-expression\n")
14895
14896 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14897 {
14898 struct community_entry *entry;
14899
14900 for (entry = list->head; entry; entry = entry->next) {
14901 if (entry == list->head) {
14902 if (all_digit(list->name))
14903 vty_out(vty, "Large community %s list %s\n",
14904 entry->style ==
14905 LARGE_COMMUNITY_LIST_STANDARD
14906 ? "standard"
14907 : "(expanded) access",
14908 list->name);
14909 else
14910 vty_out(vty,
14911 "Named large community %s list %s\n",
14912 entry->style ==
14913 LARGE_COMMUNITY_LIST_STANDARD
14914 ? "standard"
14915 : "expanded",
14916 list->name);
14917 }
14918 if (entry->any)
14919 vty_out(vty, " %s\n",
14920 community_direct_str(entry->direct));
14921 else
14922 vty_out(vty, " %s %s\n",
14923 community_direct_str(entry->direct),
14924 community_list_config_str(entry));
14925 }
14926 }
14927
14928 DEFUN (show_lcommunity_list,
14929 show_bgp_lcommunity_list_cmd,
14930 "show bgp large-community-list",
14931 SHOW_STR
14932 BGP_STR
14933 "List large-community list\n")
14934 {
14935 struct community_list *list;
14936 struct community_list_master *cm;
14937 int idx = 0;
14938
14939 if (argv_find(argv, argc, "ip", &idx)) {
14940 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14941 vty_out(vty, "if you are using this please migrate to the below command.\n");
14942 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14943 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14944 }
14945
14946 cm = community_list_master_lookup(bgp_clist,
14947 LARGE_COMMUNITY_LIST_MASTER);
14948 if (!cm)
14949 return CMD_SUCCESS;
14950
14951 for (list = cm->num.head; list; list = list->next)
14952 lcommunity_list_show(vty, list);
14953
14954 for (list = cm->str.head; list; list = list->next)
14955 lcommunity_list_show(vty, list);
14956
14957 return CMD_SUCCESS;
14958 }
14959
14960 ALIAS (show_lcommunity_list,
14961 show_ip_lcommunity_list_cmd,
14962 "show ip large-community-list",
14963 SHOW_STR
14964 IP_STR
14965 "List large-community list\n")
14966
14967 DEFUN (show_lcommunity_list_arg,
14968 show_bgp_lcommunity_list_arg_cmd,
14969 "show bgp large-community-list <(1-500)|WORD>",
14970 SHOW_STR
14971 BGP_STR
14972 "List large-community list\n"
14973 "large-community-list number\n"
14974 "large-community-list name\n")
14975 {
14976 struct community_list *list;
14977 int idx = 0;
14978
14979 if (argv_find(argv, argc, "ip", &idx)) {
14980 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14981 vty_out(vty, "if you are using this please migrate to the below command.\n");
14982 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14983 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14984 }
14985
14986 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
14987 LARGE_COMMUNITY_LIST_MASTER);
14988 if (!list) {
14989 vty_out(vty, "%% Can't find extcommunity-list\n");
14990 return CMD_WARNING;
14991 }
14992
14993 lcommunity_list_show(vty, list);
14994
14995 return CMD_SUCCESS;
14996 }
14997
14998 ALIAS (show_lcommunity_list_arg,
14999 show_ip_lcommunity_list_arg_cmd,
15000 "show ip large-community-list <(1-500)|WORD>",
15001 SHOW_STR
15002 IP_STR
15003 "List large-community list\n"
15004 "large-community-list number\n"
15005 "large-community-list name\n")
15006
15007 /* "extcommunity-list" keyword help string. */
15008 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
15009 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
15010
15011 DEFUN (extcommunity_list_standard,
15012 bgp_extcommunity_list_standard_cmd,
15013 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15014 BGP_STR
15015 EXTCOMMUNITY_LIST_STR
15016 "Extended Community list number (standard)\n"
15017 "Specify standard extcommunity-list\n"
15018 "Community list name\n"
15019 "Specify community to reject\n"
15020 "Specify community to accept\n"
15021 EXTCOMMUNITY_VAL_STR)
15022 {
15023 int style = EXTCOMMUNITY_LIST_STANDARD;
15024 int direct = 0;
15025 char *cl_number_or_name = NULL;
15026
15027 int idx = 0;
15028 if (argv_find(argv, argc, "ip", &idx)) {
15029 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15030 vty_out(vty, "if you are using this please migrate to the below command.\n");
15031 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15032 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15033 }
15034 argv_find(argv, argc, "(1-99)", &idx);
15035 argv_find(argv, argc, "WORD", &idx);
15036 cl_number_or_name = argv[idx]->arg;
15037 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15038 : COMMUNITY_DENY;
15039 argv_find(argv, argc, "AA:NN", &idx);
15040 char *str = argv_concat(argv, argc, idx);
15041
15042 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15043 direct, style);
15044
15045 XFREE(MTYPE_TMP, str);
15046
15047 if (ret < 0) {
15048 community_list_perror(vty, ret);
15049 return CMD_WARNING_CONFIG_FAILED;
15050 }
15051
15052 return CMD_SUCCESS;
15053 }
15054
15055 #if CONFDATE > 20191005
15056 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15057 #endif
15058 ALIAS (extcommunity_list_standard,
15059 ip_extcommunity_list_standard_cmd,
15060 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15061 IP_STR
15062 EXTCOMMUNITY_LIST_STR
15063 "Extended Community list number (standard)\n"
15064 "Specify standard extcommunity-list\n"
15065 "Community list name\n"
15066 "Specify community to reject\n"
15067 "Specify community to accept\n"
15068 EXTCOMMUNITY_VAL_STR)
15069
15070 DEFUN (extcommunity_list_name_expanded,
15071 bgp_extcommunity_list_name_expanded_cmd,
15072 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15073 BGP_STR
15074 EXTCOMMUNITY_LIST_STR
15075 "Extended Community list number (expanded)\n"
15076 "Specify expanded extcommunity-list\n"
15077 "Extended Community list name\n"
15078 "Specify community to reject\n"
15079 "Specify community to accept\n"
15080 "An ordered list as a regular-expression\n")
15081 {
15082 int style = EXTCOMMUNITY_LIST_EXPANDED;
15083 int direct = 0;
15084 char *cl_number_or_name = NULL;
15085
15086 int idx = 0;
15087 if (argv_find(argv, argc, "ip", &idx)) {
15088 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15089 vty_out(vty, "if you are using this please migrate to the below command.\n");
15090 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15091 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15092 }
15093
15094 argv_find(argv, argc, "(100-500)", &idx);
15095 argv_find(argv, argc, "WORD", &idx);
15096 cl_number_or_name = argv[idx]->arg;
15097 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15098 : COMMUNITY_DENY;
15099 argv_find(argv, argc, "LINE", &idx);
15100 char *str = argv_concat(argv, argc, idx);
15101
15102 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15103 direct, style);
15104
15105 XFREE(MTYPE_TMP, str);
15106
15107 if (ret < 0) {
15108 community_list_perror(vty, ret);
15109 return CMD_WARNING_CONFIG_FAILED;
15110 }
15111
15112 return CMD_SUCCESS;
15113 }
15114
15115 ALIAS (extcommunity_list_name_expanded,
15116 ip_extcommunity_list_name_expanded_cmd,
15117 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15118 IP_STR
15119 EXTCOMMUNITY_LIST_STR
15120 "Extended Community list number (expanded)\n"
15121 "Specify expanded extcommunity-list\n"
15122 "Extended Community list name\n"
15123 "Specify community to reject\n"
15124 "Specify community to accept\n"
15125 "An ordered list as a regular-expression\n")
15126
15127 DEFUN (no_extcommunity_list_standard_all,
15128 no_bgp_extcommunity_list_standard_all_cmd,
15129 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15130 NO_STR
15131 BGP_STR
15132 EXTCOMMUNITY_LIST_STR
15133 "Extended Community list number (standard)\n"
15134 "Specify standard extcommunity-list\n"
15135 "Community list name\n"
15136 "Specify community to reject\n"
15137 "Specify community to accept\n"
15138 EXTCOMMUNITY_VAL_STR)
15139 {
15140 int style = EXTCOMMUNITY_LIST_STANDARD;
15141 int direct = 0;
15142 char *cl_number_or_name = NULL;
15143 char *str = NULL;
15144
15145 int idx = 0;
15146 if (argv_find(argv, argc, "ip", &idx)) {
15147 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15148 vty_out(vty, "if you are using this please migrate to the below command.\n");
15149 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15150 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15151 }
15152
15153 idx = 0;
15154 argv_find(argv, argc, "permit", &idx);
15155 argv_find(argv, argc, "deny", &idx);
15156
15157 if (idx) {
15158 direct = argv_find(argv, argc, "permit", &idx)
15159 ? COMMUNITY_PERMIT
15160 : COMMUNITY_DENY;
15161
15162 idx = 0;
15163 argv_find(argv, argc, "AA:NN", &idx);
15164 str = argv_concat(argv, argc, idx);
15165 }
15166
15167 idx = 0;
15168 argv_find(argv, argc, "(1-99)", &idx);
15169 argv_find(argv, argc, "WORD", &idx);
15170 cl_number_or_name = argv[idx]->arg;
15171
15172 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15173 direct, style);
15174
15175 XFREE(MTYPE_TMP, str);
15176
15177 if (ret < 0) {
15178 community_list_perror(vty, ret);
15179 return CMD_WARNING_CONFIG_FAILED;
15180 }
15181
15182 return CMD_SUCCESS;
15183 }
15184
15185 ALIAS (no_extcommunity_list_standard_all,
15186 no_ip_extcommunity_list_standard_all_cmd,
15187 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15188 NO_STR
15189 IP_STR
15190 EXTCOMMUNITY_LIST_STR
15191 "Extended Community list number (standard)\n"
15192 "Specify standard extcommunity-list\n"
15193 "Community list name\n"
15194 "Specify community to reject\n"
15195 "Specify community to accept\n"
15196 EXTCOMMUNITY_VAL_STR)
15197
15198 ALIAS(no_extcommunity_list_standard_all,
15199 no_bgp_extcommunity_list_standard_all_list_cmd,
15200 "no bgp extcommunity-list <(1-99)|standard WORD>",
15201 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15202 "Extended Community list number (standard)\n"
15203 "Specify standard extcommunity-list\n"
15204 "Community list name\n")
15205
15206 ALIAS(no_extcommunity_list_standard_all,
15207 no_ip_extcommunity_list_standard_all_list_cmd,
15208 "no ip extcommunity-list <(1-99)|standard WORD>",
15209 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15210 "Extended Community list number (standard)\n"
15211 "Specify standard extcommunity-list\n"
15212 "Community list name\n")
15213
15214 DEFUN (no_extcommunity_list_expanded_all,
15215 no_bgp_extcommunity_list_expanded_all_cmd,
15216 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15217 NO_STR
15218 BGP_STR
15219 EXTCOMMUNITY_LIST_STR
15220 "Extended Community list number (expanded)\n"
15221 "Specify expanded extcommunity-list\n"
15222 "Extended Community list name\n"
15223 "Specify community to reject\n"
15224 "Specify community to accept\n"
15225 "An ordered list as a regular-expression\n")
15226 {
15227 int style = EXTCOMMUNITY_LIST_EXPANDED;
15228 int direct = 0;
15229 char *cl_number_or_name = NULL;
15230 char *str = NULL;
15231
15232 int idx = 0;
15233 if (argv_find(argv, argc, "ip", &idx)) {
15234 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15235 vty_out(vty, "if you are using this please migrate to the below command.\n");
15236 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15237 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15238 }
15239
15240 idx = 0;
15241 argv_find(argv, argc, "permit", &idx);
15242 argv_find(argv, argc, "deny", &idx);
15243
15244 if (idx) {
15245 direct = argv_find(argv, argc, "permit", &idx)
15246 ? COMMUNITY_PERMIT
15247 : COMMUNITY_DENY;
15248
15249 idx = 0;
15250 argv_find(argv, argc, "LINE", &idx);
15251 str = argv_concat(argv, argc, idx);
15252 }
15253
15254 idx = 0;
15255 argv_find(argv, argc, "(100-500)", &idx);
15256 argv_find(argv, argc, "WORD", &idx);
15257 cl_number_or_name = argv[idx]->arg;
15258
15259 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15260 direct, style);
15261
15262 XFREE(MTYPE_TMP, str);
15263
15264 if (ret < 0) {
15265 community_list_perror(vty, ret);
15266 return CMD_WARNING_CONFIG_FAILED;
15267 }
15268
15269 return CMD_SUCCESS;
15270 }
15271
15272 ALIAS (no_extcommunity_list_expanded_all,
15273 no_ip_extcommunity_list_expanded_all_cmd,
15274 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15275 NO_STR
15276 IP_STR
15277 EXTCOMMUNITY_LIST_STR
15278 "Extended Community list number (expanded)\n"
15279 "Specify expanded extcommunity-list\n"
15280 "Extended Community list name\n"
15281 "Specify community to reject\n"
15282 "Specify community to accept\n"
15283 "An ordered list as a regular-expression\n")
15284
15285 ALIAS(no_extcommunity_list_expanded_all,
15286 no_ip_extcommunity_list_expanded_all_list_cmd,
15287 "no ip extcommunity-list <(100-500)|expanded WORD>",
15288 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15289 "Extended Community list number (expanded)\n"
15290 "Specify expanded extcommunity-list\n"
15291 "Extended Community list name\n")
15292
15293 ALIAS(no_extcommunity_list_expanded_all,
15294 no_bgp_extcommunity_list_expanded_all_list_cmd,
15295 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15296 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15297 "Extended Community list number (expanded)\n"
15298 "Specify expanded extcommunity-list\n"
15299 "Extended Community list name\n")
15300
15301 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15302 {
15303 struct community_entry *entry;
15304
15305 for (entry = list->head; entry; entry = entry->next) {
15306 if (entry == list->head) {
15307 if (all_digit(list->name))
15308 vty_out(vty, "Extended community %s list %s\n",
15309 entry->style == EXTCOMMUNITY_LIST_STANDARD
15310 ? "standard"
15311 : "(expanded) access",
15312 list->name);
15313 else
15314 vty_out(vty,
15315 "Named extended community %s list %s\n",
15316 entry->style == EXTCOMMUNITY_LIST_STANDARD
15317 ? "standard"
15318 : "expanded",
15319 list->name);
15320 }
15321 if (entry->any)
15322 vty_out(vty, " %s\n",
15323 community_direct_str(entry->direct));
15324 else
15325 vty_out(vty, " %s %s\n",
15326 community_direct_str(entry->direct),
15327 community_list_config_str(entry));
15328 }
15329 }
15330
15331 DEFUN (show_extcommunity_list,
15332 show_bgp_extcommunity_list_cmd,
15333 "show bgp extcommunity-list",
15334 SHOW_STR
15335 BGP_STR
15336 "List extended-community list\n")
15337 {
15338 struct community_list *list;
15339 struct community_list_master *cm;
15340 int idx = 0;
15341
15342 if (argv_find(argv, argc, "ip", &idx)) {
15343 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15344 vty_out(vty, "if you are using this please migrate to the below command.\n");
15345 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15346 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15347 }
15348 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15349 if (!cm)
15350 return CMD_SUCCESS;
15351
15352 for (list = cm->num.head; list; list = list->next)
15353 extcommunity_list_show(vty, list);
15354
15355 for (list = cm->str.head; list; list = list->next)
15356 extcommunity_list_show(vty, list);
15357
15358 return CMD_SUCCESS;
15359 }
15360
15361 ALIAS (show_extcommunity_list,
15362 show_ip_extcommunity_list_cmd,
15363 "show ip extcommunity-list",
15364 SHOW_STR
15365 IP_STR
15366 "List extended-community list\n")
15367
15368 DEFUN (show_extcommunity_list_arg,
15369 show_bgp_extcommunity_list_arg_cmd,
15370 "show bgp extcommunity-list <(1-500)|WORD>",
15371 SHOW_STR
15372 BGP_STR
15373 "List extended-community list\n"
15374 "Extcommunity-list number\n"
15375 "Extcommunity-list name\n")
15376 {
15377 int idx_comm_list = 3;
15378 struct community_list *list;
15379 int idx = 0;
15380
15381 if (argv_find(argv, argc, "ip", &idx)) {
15382 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15383 vty_out(vty, "if you are using this please migrate to the below command.\n");
15384 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15385 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15386 }
15387 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15388 EXTCOMMUNITY_LIST_MASTER);
15389 if (!list) {
15390 vty_out(vty, "%% Can't find extcommunity-list\n");
15391 return CMD_WARNING;
15392 }
15393
15394 extcommunity_list_show(vty, list);
15395
15396 return CMD_SUCCESS;
15397 }
15398
15399 ALIAS (show_extcommunity_list_arg,
15400 show_ip_extcommunity_list_arg_cmd,
15401 "show ip extcommunity-list <(1-500)|WORD>",
15402 SHOW_STR
15403 IP_STR
15404 "List extended-community list\n"
15405 "Extcommunity-list number\n"
15406 "Extcommunity-list name\n")
15407
15408 /* Display community-list and extcommunity-list configuration. */
15409 static int community_list_config_write(struct vty *vty)
15410 {
15411 struct community_list *list;
15412 struct community_entry *entry;
15413 struct community_list_master *cm;
15414 int write = 0;
15415
15416 /* Community-list. */
15417 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15418
15419 for (list = cm->num.head; list; list = list->next)
15420 for (entry = list->head; entry; entry = entry->next) {
15421 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15422 community_direct_str(entry->direct),
15423 community_list_config_str(entry));
15424 write++;
15425 }
15426 for (list = cm->str.head; list; list = list->next)
15427 for (entry = list->head; entry; entry = entry->next) {
15428 vty_out(vty, "bgp community-list %s %s %s %s\n",
15429 entry->style == COMMUNITY_LIST_STANDARD
15430 ? "standard"
15431 : "expanded",
15432 list->name, community_direct_str(entry->direct),
15433 community_list_config_str(entry));
15434 write++;
15435 }
15436
15437 /* Extcommunity-list. */
15438 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15439
15440 for (list = cm->num.head; list; list = list->next)
15441 for (entry = list->head; entry; entry = entry->next) {
15442 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15443 list->name, community_direct_str(entry->direct),
15444 community_list_config_str(entry));
15445 write++;
15446 }
15447 for (list = cm->str.head; list; list = list->next)
15448 for (entry = list->head; entry; entry = entry->next) {
15449 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15450 entry->style == EXTCOMMUNITY_LIST_STANDARD
15451 ? "standard"
15452 : "expanded",
15453 list->name, community_direct_str(entry->direct),
15454 community_list_config_str(entry));
15455 write++;
15456 }
15457
15458
15459 /* lcommunity-list. */
15460 cm = community_list_master_lookup(bgp_clist,
15461 LARGE_COMMUNITY_LIST_MASTER);
15462
15463 for (list = cm->num.head; list; list = list->next)
15464 for (entry = list->head; entry; entry = entry->next) {
15465 vty_out(vty, "bgp large-community-list %s %s %s\n",
15466 list->name, community_direct_str(entry->direct),
15467 community_list_config_str(entry));
15468 write++;
15469 }
15470 for (list = cm->str.head; list; list = list->next)
15471 for (entry = list->head; entry; entry = entry->next) {
15472 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15473 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15474 ? "standard"
15475 : "expanded",
15476 list->name, community_direct_str(entry->direct),
15477 community_list_config_str(entry));
15478 write++;
15479 }
15480
15481 return write;
15482 }
15483
15484 static struct cmd_node community_list_node = {
15485 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15486 };
15487
15488 static void community_list_vty(void)
15489 {
15490 install_node(&community_list_node, community_list_config_write);
15491
15492 /* Community-list. */
15493 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15494 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15495 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15496 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15497 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15498 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15499 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15500 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15501 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15502 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15503 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15504 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15505 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15506 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15507 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15508 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15509
15510 /* Extcommunity-list. */
15511 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15512 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15513 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15514 install_element(CONFIG_NODE,
15515 &no_bgp_extcommunity_list_standard_all_list_cmd);
15516 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15517 install_element(CONFIG_NODE,
15518 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15519 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15520 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15521 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15522 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15523 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15524 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15525 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15526 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15527 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15528 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15529
15530 /* Large Community List */
15531 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15532 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15533 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15534 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15535 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15536 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15537 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15538 install_element(CONFIG_NODE,
15539 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15540 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15541 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15542 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15543 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15544 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15545 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15546 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15547 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15548 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15549 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15550 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15551 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15552 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15553 install_element(CONFIG_NODE,
15554 &no_ip_lcommunity_list_name_expanded_all_cmd);
15555 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15556 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15557 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15558 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15559 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15560 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15561 }