]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #4483 from donaldsharp/pim_mroute_debug_detail
[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) [<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_MULTIPLE_INSTANCE_NOT_SET:
983 vty_out(vty,
984 "Please specify 'bgp multiple-instance' first\n");
985 return CMD_WARNING_CONFIG_FAILED;
986 case BGP_ERR_AS_MISMATCH:
987 vty_out(vty, "BGP is already running; AS is %u\n", as);
988 return CMD_WARNING_CONFIG_FAILED;
989 case BGP_ERR_INSTANCE_MISMATCH:
990 vty_out(vty,
991 "BGP instance name and AS number mismatch\n");
992 vty_out(vty,
993 "BGP instance is already running; AS is %u\n",
994 as);
995 return CMD_WARNING_CONFIG_FAILED;
996 }
997
998 /*
999 * If we just instantiated the default instance, complete
1000 * any pending VRF-VPN leaking that was configured via
1001 * earlier "router bgp X vrf FOO" blocks.
1002 */
1003 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1004 vpn_leak_postchange_all();
1005
1006 /* Pending: handle when user tries to change a view to vrf n vv.
1007 */
1008 }
1009
1010 /* unset the auto created flag as the user config is now present */
1011 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1012 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1013
1014 return CMD_SUCCESS;
1015 }
1016
1017 /* "no router bgp" commands. */
1018 DEFUN (no_router_bgp,
1019 no_router_bgp_cmd,
1020 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1021 NO_STR
1022 ROUTER_STR
1023 BGP_STR
1024 AS_STR
1025 BGP_INSTANCE_HELP_STR)
1026 {
1027 int idx_asn = 3;
1028 int idx_vrf = 5;
1029 as_t as;
1030 struct bgp *bgp;
1031 const char *name = NULL;
1032
1033 // "no router bgp" without an ASN
1034 if (argc == 3) {
1035 // Pending: Make VRF option available for ASN less config
1036 bgp = bgp_get_default();
1037
1038 if (bgp == NULL) {
1039 vty_out(vty, "%% No BGP process is configured\n");
1040 return CMD_WARNING_CONFIG_FAILED;
1041 }
1042
1043 if (listcount(bm->bgp) > 1) {
1044 vty_out(vty, "%% Please specify ASN and VRF\n");
1045 return CMD_WARNING_CONFIG_FAILED;
1046 }
1047
1048 if (bgp->l3vni) {
1049 vty_out(vty, "%% Please unconfigure l3vni %u",
1050 bgp->l3vni);
1051 return CMD_WARNING_CONFIG_FAILED;
1052 }
1053 } else {
1054 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1055
1056 if (argc > 4)
1057 name = argv[idx_vrf]->arg;
1058
1059 /* Lookup bgp structure. */
1060 bgp = bgp_lookup(as, name);
1061 if (!bgp) {
1062 vty_out(vty, "%% Can't find BGP instance\n");
1063 return CMD_WARNING_CONFIG_FAILED;
1064 }
1065
1066 if (bgp->l3vni) {
1067 vty_out(vty, "%% Please unconfigure l3vni %u\n",
1068 bgp->l3vni);
1069 return CMD_WARNING_CONFIG_FAILED;
1070 }
1071
1072 /* Cannot delete default instance if vrf instances exist */
1073 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
1074 struct listnode *node;
1075 struct bgp *tmp_bgp;
1076
1077 for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
1078 if (tmp_bgp->inst_type
1079 == BGP_INSTANCE_TYPE_VRF) {
1080 vty_out(vty,
1081 "%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
1082 return CMD_WARNING_CONFIG_FAILED;
1083 }
1084 }
1085 }
1086 }
1087
1088 bgp_delete(bgp);
1089
1090 return CMD_SUCCESS;
1091 }
1092
1093
1094 /* BGP router-id. */
1095
1096 DEFPY (bgp_router_id,
1097 bgp_router_id_cmd,
1098 "bgp router-id A.B.C.D",
1099 BGP_STR
1100 "Override configured router identifier\n"
1101 "Manually configured router identifier\n")
1102 {
1103 VTY_DECLVAR_CONTEXT(bgp, bgp);
1104 bgp_router_id_static_set(bgp, router_id);
1105 return CMD_SUCCESS;
1106 }
1107
1108 DEFPY (no_bgp_router_id,
1109 no_bgp_router_id_cmd,
1110 "no bgp router-id [A.B.C.D]",
1111 NO_STR
1112 BGP_STR
1113 "Override configured router identifier\n"
1114 "Manually configured router identifier\n")
1115 {
1116 VTY_DECLVAR_CONTEXT(bgp, bgp);
1117
1118 if (router_id_str) {
1119 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1120 vty_out(vty, "%% BGP router-id doesn't match\n");
1121 return CMD_WARNING_CONFIG_FAILED;
1122 }
1123 }
1124
1125 router_id.s_addr = 0;
1126 bgp_router_id_static_set(bgp, router_id);
1127
1128 return CMD_SUCCESS;
1129 }
1130
1131
1132 /* BGP Cluster ID. */
1133 DEFUN (bgp_cluster_id,
1134 bgp_cluster_id_cmd,
1135 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1136 BGP_STR
1137 "Configure Route-Reflector Cluster-id\n"
1138 "Route-Reflector Cluster-id in IP address format\n"
1139 "Route-Reflector Cluster-id as 32 bit quantity\n")
1140 {
1141 VTY_DECLVAR_CONTEXT(bgp, bgp);
1142 int idx_ipv4 = 2;
1143 int ret;
1144 struct in_addr cluster;
1145
1146 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1147 if (!ret) {
1148 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1149 return CMD_WARNING_CONFIG_FAILED;
1150 }
1151
1152 bgp_cluster_id_set(bgp, &cluster);
1153 bgp_clear_star_soft_out(vty, bgp->name);
1154
1155 return CMD_SUCCESS;
1156 }
1157
1158 DEFUN (no_bgp_cluster_id,
1159 no_bgp_cluster_id_cmd,
1160 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1161 NO_STR
1162 BGP_STR
1163 "Configure Route-Reflector Cluster-id\n"
1164 "Route-Reflector Cluster-id in IP address format\n"
1165 "Route-Reflector Cluster-id as 32 bit quantity\n")
1166 {
1167 VTY_DECLVAR_CONTEXT(bgp, bgp);
1168 bgp_cluster_id_unset(bgp);
1169 bgp_clear_star_soft_out(vty, bgp->name);
1170
1171 return CMD_SUCCESS;
1172 }
1173
1174 DEFUN (bgp_confederation_identifier,
1175 bgp_confederation_identifier_cmd,
1176 "bgp confederation identifier (1-4294967295)",
1177 "BGP specific commands\n"
1178 "AS confederation parameters\n"
1179 "AS number\n"
1180 "Set routing domain confederation AS\n")
1181 {
1182 VTY_DECLVAR_CONTEXT(bgp, bgp);
1183 int idx_number = 3;
1184 as_t as;
1185
1186 as = strtoul(argv[idx_number]->arg, NULL, 10);
1187
1188 bgp_confederation_id_set(bgp, as);
1189
1190 return CMD_SUCCESS;
1191 }
1192
1193 DEFUN (no_bgp_confederation_identifier,
1194 no_bgp_confederation_identifier_cmd,
1195 "no bgp confederation identifier [(1-4294967295)]",
1196 NO_STR
1197 "BGP specific commands\n"
1198 "AS confederation parameters\n"
1199 "AS number\n"
1200 "Set routing domain confederation AS\n")
1201 {
1202 VTY_DECLVAR_CONTEXT(bgp, bgp);
1203 bgp_confederation_id_unset(bgp);
1204
1205 return CMD_SUCCESS;
1206 }
1207
1208 DEFUN (bgp_confederation_peers,
1209 bgp_confederation_peers_cmd,
1210 "bgp confederation peers (1-4294967295)...",
1211 "BGP specific commands\n"
1212 "AS confederation parameters\n"
1213 "Peer ASs in BGP confederation\n"
1214 AS_STR)
1215 {
1216 VTY_DECLVAR_CONTEXT(bgp, bgp);
1217 int idx_asn = 3;
1218 as_t as;
1219 int i;
1220
1221 for (i = idx_asn; i < argc; i++) {
1222 as = strtoul(argv[i]->arg, NULL, 10);
1223
1224 if (bgp->as == as) {
1225 vty_out(vty,
1226 "%% Local member-AS not allowed in confed peer list\n");
1227 continue;
1228 }
1229
1230 bgp_confederation_peers_add(bgp, as);
1231 }
1232 return CMD_SUCCESS;
1233 }
1234
1235 DEFUN (no_bgp_confederation_peers,
1236 no_bgp_confederation_peers_cmd,
1237 "no bgp confederation peers (1-4294967295)...",
1238 NO_STR
1239 "BGP specific commands\n"
1240 "AS confederation parameters\n"
1241 "Peer ASs in BGP confederation\n"
1242 AS_STR)
1243 {
1244 VTY_DECLVAR_CONTEXT(bgp, bgp);
1245 int idx_asn = 4;
1246 as_t as;
1247 int i;
1248
1249 for (i = idx_asn; i < argc; i++) {
1250 as = strtoul(argv[i]->arg, NULL, 10);
1251
1252 bgp_confederation_peers_remove(bgp, as);
1253 }
1254 return CMD_SUCCESS;
1255 }
1256
1257 /**
1258 * Central routine for maximum-paths configuration.
1259 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1260 * @set: 1 for setting values, 0 for removing the max-paths config.
1261 */
1262 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1263 const char *mpaths, uint16_t options,
1264 int set)
1265 {
1266 VTY_DECLVAR_CONTEXT(bgp, bgp);
1267 uint16_t maxpaths = 0;
1268 int ret;
1269 afi_t afi;
1270 safi_t safi;
1271
1272 afi = bgp_node_afi(vty);
1273 safi = bgp_node_safi(vty);
1274
1275 if (set) {
1276 maxpaths = strtol(mpaths, NULL, 10);
1277 if (maxpaths > multipath_num) {
1278 vty_out(vty,
1279 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1280 maxpaths, multipath_num);
1281 return CMD_WARNING_CONFIG_FAILED;
1282 }
1283 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1284 options);
1285 } else
1286 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1287
1288 if (ret < 0) {
1289 vty_out(vty,
1290 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1291 (set == 1) ? "" : "un",
1292 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1293 maxpaths, afi, safi);
1294 return CMD_WARNING_CONFIG_FAILED;
1295 }
1296
1297 bgp_recalculate_all_bestpaths(bgp);
1298
1299 return CMD_SUCCESS;
1300 }
1301
1302 DEFUN (bgp_maxmed_admin,
1303 bgp_maxmed_admin_cmd,
1304 "bgp max-med administrative ",
1305 BGP_STR
1306 "Advertise routes with max-med\n"
1307 "Administratively applied, for an indefinite period\n")
1308 {
1309 VTY_DECLVAR_CONTEXT(bgp, bgp);
1310
1311 bgp->v_maxmed_admin = 1;
1312 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1313
1314 bgp_maxmed_update(bgp);
1315
1316 return CMD_SUCCESS;
1317 }
1318
1319 DEFUN (bgp_maxmed_admin_medv,
1320 bgp_maxmed_admin_medv_cmd,
1321 "bgp max-med administrative (0-4294967295)",
1322 BGP_STR
1323 "Advertise routes with max-med\n"
1324 "Administratively applied, for an indefinite period\n"
1325 "Max MED value to be used\n")
1326 {
1327 VTY_DECLVAR_CONTEXT(bgp, bgp);
1328 int idx_number = 3;
1329
1330 bgp->v_maxmed_admin = 1;
1331 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1332
1333 bgp_maxmed_update(bgp);
1334
1335 return CMD_SUCCESS;
1336 }
1337
1338 DEFUN (no_bgp_maxmed_admin,
1339 no_bgp_maxmed_admin_cmd,
1340 "no bgp max-med administrative [(0-4294967295)]",
1341 NO_STR
1342 BGP_STR
1343 "Advertise routes with max-med\n"
1344 "Administratively applied, for an indefinite period\n"
1345 "Max MED value to be used\n")
1346 {
1347 VTY_DECLVAR_CONTEXT(bgp, bgp);
1348 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1349 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1350 bgp_maxmed_update(bgp);
1351
1352 return CMD_SUCCESS;
1353 }
1354
1355 DEFUN (bgp_maxmed_onstartup,
1356 bgp_maxmed_onstartup_cmd,
1357 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1358 BGP_STR
1359 "Advertise routes with max-med\n"
1360 "Effective on a startup\n"
1361 "Time (seconds) period for max-med\n"
1362 "Max MED value to be used\n")
1363 {
1364 VTY_DECLVAR_CONTEXT(bgp, bgp);
1365 int idx = 0;
1366
1367 argv_find(argv, argc, "(5-86400)", &idx);
1368 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1369 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1370 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1371 else
1372 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1373
1374 bgp_maxmed_update(bgp);
1375
1376 return CMD_SUCCESS;
1377 }
1378
1379 DEFUN (no_bgp_maxmed_onstartup,
1380 no_bgp_maxmed_onstartup_cmd,
1381 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1382 NO_STR
1383 BGP_STR
1384 "Advertise routes with max-med\n"
1385 "Effective on a startup\n"
1386 "Time (seconds) period for max-med\n"
1387 "Max MED value to be used\n")
1388 {
1389 VTY_DECLVAR_CONTEXT(bgp, bgp);
1390
1391 /* Cancel max-med onstartup if its on */
1392 if (bgp->t_maxmed_onstartup) {
1393 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1394 bgp->maxmed_onstartup_over = 1;
1395 }
1396
1397 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1398 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1399
1400 bgp_maxmed_update(bgp);
1401
1402 return CMD_SUCCESS;
1403 }
1404
1405 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1406 const char *wait)
1407 {
1408 VTY_DECLVAR_CONTEXT(bgp, bgp);
1409 uint16_t update_delay;
1410 uint16_t establish_wait;
1411
1412 update_delay = strtoul(delay, NULL, 10);
1413
1414 if (!wait) /* update-delay <delay> */
1415 {
1416 bgp->v_update_delay = update_delay;
1417 bgp->v_establish_wait = bgp->v_update_delay;
1418 return CMD_SUCCESS;
1419 }
1420
1421 /* update-delay <delay> <establish-wait> */
1422 establish_wait = atoi(wait);
1423 if (update_delay < establish_wait) {
1424 vty_out(vty,
1425 "%%Failed: update-delay less than the establish-wait!\n");
1426 return CMD_WARNING_CONFIG_FAILED;
1427 }
1428
1429 bgp->v_update_delay = update_delay;
1430 bgp->v_establish_wait = establish_wait;
1431
1432 return CMD_SUCCESS;
1433 }
1434
1435 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1436 {
1437 VTY_DECLVAR_CONTEXT(bgp, bgp);
1438
1439 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1440 bgp->v_establish_wait = bgp->v_update_delay;
1441
1442 return CMD_SUCCESS;
1443 }
1444
1445 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1446 {
1447 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1448 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1449 if (bgp->v_update_delay != bgp->v_establish_wait)
1450 vty_out(vty, " %d", bgp->v_establish_wait);
1451 vty_out(vty, "\n");
1452 }
1453 }
1454
1455
1456 /* Update-delay configuration */
1457 DEFUN (bgp_update_delay,
1458 bgp_update_delay_cmd,
1459 "update-delay (0-3600)",
1460 "Force initial delay for best-path and updates\n"
1461 "Seconds\n")
1462 {
1463 int idx_number = 1;
1464 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1465 }
1466
1467 DEFUN (bgp_update_delay_establish_wait,
1468 bgp_update_delay_establish_wait_cmd,
1469 "update-delay (0-3600) (1-3600)",
1470 "Force initial delay for best-path and updates\n"
1471 "Seconds\n"
1472 "Seconds\n")
1473 {
1474 int idx_number = 1;
1475 int idx_number_2 = 2;
1476 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1477 argv[idx_number_2]->arg);
1478 }
1479
1480 /* Update-delay deconfiguration */
1481 DEFUN (no_bgp_update_delay,
1482 no_bgp_update_delay_cmd,
1483 "no update-delay [(0-3600) [(1-3600)]]",
1484 NO_STR
1485 "Force initial delay for best-path and updates\n"
1486 "Seconds\n"
1487 "Seconds\n")
1488 {
1489 return bgp_update_delay_deconfig_vty(vty);
1490 }
1491
1492
1493 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1494 char set)
1495 {
1496 VTY_DECLVAR_CONTEXT(bgp, bgp);
1497
1498 if (set) {
1499 uint32_t quanta = strtoul(num, NULL, 10);
1500 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1501 memory_order_relaxed);
1502 } else {
1503 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1504 memory_order_relaxed);
1505 }
1506
1507 return CMD_SUCCESS;
1508 }
1509
1510 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1511 char set)
1512 {
1513 VTY_DECLVAR_CONTEXT(bgp, bgp);
1514
1515 if (set) {
1516 uint32_t quanta = strtoul(num, NULL, 10);
1517 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1518 memory_order_relaxed);
1519 } else {
1520 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1521 memory_order_relaxed);
1522 }
1523
1524 return CMD_SUCCESS;
1525 }
1526
1527 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1528 {
1529 uint32_t quanta =
1530 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1531 if (quanta != BGP_WRITE_PACKET_MAX)
1532 vty_out(vty, " write-quanta %d\n", quanta);
1533 }
1534
1535 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1536 {
1537 uint32_t quanta =
1538 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1539 if (quanta != BGP_READ_PACKET_MAX)
1540 vty_out(vty, " read-quanta %d\n", quanta);
1541 }
1542
1543 /* Packet quanta configuration */
1544 DEFUN (bgp_wpkt_quanta,
1545 bgp_wpkt_quanta_cmd,
1546 "write-quanta (1-10)",
1547 "How many packets to write to peer socket per run\n"
1548 "Number of packets\n")
1549 {
1550 int idx_number = 1;
1551 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1552 }
1553
1554 DEFUN (no_bgp_wpkt_quanta,
1555 no_bgp_wpkt_quanta_cmd,
1556 "no write-quanta (1-10)",
1557 NO_STR
1558 "How many packets to write to peer socket per I/O cycle\n"
1559 "Number of packets\n")
1560 {
1561 int idx_number = 2;
1562 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1563 }
1564
1565 DEFUN (bgp_rpkt_quanta,
1566 bgp_rpkt_quanta_cmd,
1567 "read-quanta (1-10)",
1568 "How many packets to read from peer socket per I/O cycle\n"
1569 "Number of packets\n")
1570 {
1571 int idx_number = 1;
1572 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1573 }
1574
1575 DEFUN (no_bgp_rpkt_quanta,
1576 no_bgp_rpkt_quanta_cmd,
1577 "no read-quanta (1-10)",
1578 NO_STR
1579 "How many packets to read from peer socket per I/O cycle\n"
1580 "Number of packets\n")
1581 {
1582 int idx_number = 2;
1583 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1584 }
1585
1586 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1587 {
1588 if (!bgp->heuristic_coalesce)
1589 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1590 }
1591
1592
1593 DEFUN (bgp_coalesce_time,
1594 bgp_coalesce_time_cmd,
1595 "coalesce-time (0-4294967295)",
1596 "Subgroup coalesce timer\n"
1597 "Subgroup coalesce timer value (in ms)\n")
1598 {
1599 VTY_DECLVAR_CONTEXT(bgp, bgp);
1600
1601 int idx = 0;
1602 argv_find(argv, argc, "(0-4294967295)", &idx);
1603 bgp->heuristic_coalesce = false;
1604 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1605 return CMD_SUCCESS;
1606 }
1607
1608 DEFUN (no_bgp_coalesce_time,
1609 no_bgp_coalesce_time_cmd,
1610 "no coalesce-time (0-4294967295)",
1611 NO_STR
1612 "Subgroup coalesce timer\n"
1613 "Subgroup coalesce timer value (in ms)\n")
1614 {
1615 VTY_DECLVAR_CONTEXT(bgp, bgp);
1616
1617 bgp->heuristic_coalesce = true;
1618 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1619 return CMD_SUCCESS;
1620 }
1621
1622 /* Maximum-paths configuration */
1623 DEFUN (bgp_maxpaths,
1624 bgp_maxpaths_cmd,
1625 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1626 "Forward packets over multiple paths\n"
1627 "Number of paths\n")
1628 {
1629 int idx_number = 1;
1630 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1631 argv[idx_number]->arg, 0, 1);
1632 }
1633
1634 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1635 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1636 "Forward packets over multiple paths\n"
1637 "Number of paths\n")
1638
1639 DEFUN (bgp_maxpaths_ibgp,
1640 bgp_maxpaths_ibgp_cmd,
1641 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1642 "Forward packets over multiple paths\n"
1643 "iBGP-multipath\n"
1644 "Number of paths\n")
1645 {
1646 int idx_number = 2;
1647 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1648 argv[idx_number]->arg, 0, 1);
1649 }
1650
1651 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1652 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1653 "Forward packets over multiple paths\n"
1654 "iBGP-multipath\n"
1655 "Number of paths\n")
1656
1657 DEFUN (bgp_maxpaths_ibgp_cluster,
1658 bgp_maxpaths_ibgp_cluster_cmd,
1659 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1660 "Forward packets over multiple paths\n"
1661 "iBGP-multipath\n"
1662 "Number of paths\n"
1663 "Match the cluster length\n")
1664 {
1665 int idx_number = 2;
1666 return bgp_maxpaths_config_vty(
1667 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1668 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1669 }
1670
1671 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1672 "maximum-paths ibgp " CMD_RANGE_STR(
1673 1, MULTIPATH_NUM) " equal-cluster-length",
1674 "Forward packets over multiple paths\n"
1675 "iBGP-multipath\n"
1676 "Number of paths\n"
1677 "Match the cluster length\n")
1678
1679 DEFUN (no_bgp_maxpaths,
1680 no_bgp_maxpaths_cmd,
1681 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1682 NO_STR
1683 "Forward packets over multiple paths\n"
1684 "Number of paths\n")
1685 {
1686 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1687 }
1688
1689 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1690 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1691 "Forward packets over multiple paths\n"
1692 "Number of paths\n")
1693
1694 DEFUN (no_bgp_maxpaths_ibgp,
1695 no_bgp_maxpaths_ibgp_cmd,
1696 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1697 NO_STR
1698 "Forward packets over multiple paths\n"
1699 "iBGP-multipath\n"
1700 "Number of paths\n"
1701 "Match the cluster length\n")
1702 {
1703 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1704 }
1705
1706 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1707 "no maximum-paths ibgp [" CMD_RANGE_STR(
1708 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1709 NO_STR
1710 "Forward packets over multiple paths\n"
1711 "iBGP-multipath\n"
1712 "Number of paths\n"
1713 "Match the cluster length\n")
1714
1715 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1716 safi_t safi)
1717 {
1718 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1719 vty_out(vty, " maximum-paths %d\n",
1720 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1721 }
1722
1723 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1724 vty_out(vty, " maximum-paths ibgp %d",
1725 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1726 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1727 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1728 vty_out(vty, " equal-cluster-length");
1729 vty_out(vty, "\n");
1730 }
1731 }
1732
1733 /* BGP timers. */
1734
1735 DEFUN (bgp_timers,
1736 bgp_timers_cmd,
1737 "timers bgp (0-65535) (0-65535)",
1738 "Adjust routing timers\n"
1739 "BGP timers\n"
1740 "Keepalive interval\n"
1741 "Holdtime\n")
1742 {
1743 VTY_DECLVAR_CONTEXT(bgp, bgp);
1744 int idx_number = 2;
1745 int idx_number_2 = 3;
1746 unsigned long keepalive = 0;
1747 unsigned long holdtime = 0;
1748
1749 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1750 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1751
1752 /* Holdtime value check. */
1753 if (holdtime < 3 && holdtime != 0) {
1754 vty_out(vty,
1755 "%% hold time value must be either 0 or greater than 3\n");
1756 return CMD_WARNING_CONFIG_FAILED;
1757 }
1758
1759 bgp_timers_set(bgp, keepalive, holdtime);
1760
1761 return CMD_SUCCESS;
1762 }
1763
1764 DEFUN (no_bgp_timers,
1765 no_bgp_timers_cmd,
1766 "no timers bgp [(0-65535) (0-65535)]",
1767 NO_STR
1768 "Adjust routing timers\n"
1769 "BGP timers\n"
1770 "Keepalive interval\n"
1771 "Holdtime\n")
1772 {
1773 VTY_DECLVAR_CONTEXT(bgp, bgp);
1774 bgp_timers_unset(bgp);
1775
1776 return CMD_SUCCESS;
1777 }
1778
1779
1780 DEFUN (bgp_client_to_client_reflection,
1781 bgp_client_to_client_reflection_cmd,
1782 "bgp client-to-client reflection",
1783 "BGP specific commands\n"
1784 "Configure client to client route reflection\n"
1785 "reflection of routes allowed\n")
1786 {
1787 VTY_DECLVAR_CONTEXT(bgp, bgp);
1788 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1789 bgp_clear_star_soft_out(vty, bgp->name);
1790
1791 return CMD_SUCCESS;
1792 }
1793
1794 DEFUN (no_bgp_client_to_client_reflection,
1795 no_bgp_client_to_client_reflection_cmd,
1796 "no bgp client-to-client reflection",
1797 NO_STR
1798 "BGP specific commands\n"
1799 "Configure client to client route reflection\n"
1800 "reflection of routes allowed\n")
1801 {
1802 VTY_DECLVAR_CONTEXT(bgp, bgp);
1803 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1804 bgp_clear_star_soft_out(vty, bgp->name);
1805
1806 return CMD_SUCCESS;
1807 }
1808
1809 /* "bgp always-compare-med" configuration. */
1810 DEFUN (bgp_always_compare_med,
1811 bgp_always_compare_med_cmd,
1812 "bgp always-compare-med",
1813 "BGP specific commands\n"
1814 "Allow comparing MED from different neighbors\n")
1815 {
1816 VTY_DECLVAR_CONTEXT(bgp, bgp);
1817 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1818 bgp_recalculate_all_bestpaths(bgp);
1819
1820 return CMD_SUCCESS;
1821 }
1822
1823 DEFUN (no_bgp_always_compare_med,
1824 no_bgp_always_compare_med_cmd,
1825 "no bgp always-compare-med",
1826 NO_STR
1827 "BGP specific commands\n"
1828 "Allow comparing MED from different neighbors\n")
1829 {
1830 VTY_DECLVAR_CONTEXT(bgp, bgp);
1831 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1832 bgp_recalculate_all_bestpaths(bgp);
1833
1834 return CMD_SUCCESS;
1835 }
1836
1837
1838 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1839 "bgp ebgp-requires-policy",
1840 "BGP specific commands\n"
1841 "Require in and out policy for eBGP peers (RFC8212)\n")
1842 {
1843 VTY_DECLVAR_CONTEXT(bgp, bgp);
1844 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1845 return CMD_SUCCESS;
1846 }
1847
1848 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1849 "no bgp ebgp-requires-policy",
1850 NO_STR
1851 "BGP specific commands\n"
1852 "Require in and out policy for eBGP peers (RFC8212)\n")
1853 {
1854 VTY_DECLVAR_CONTEXT(bgp, bgp);
1855 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1856 return CMD_SUCCESS;
1857 }
1858
1859
1860 /* "bgp deterministic-med" configuration. */
1861 DEFUN (bgp_deterministic_med,
1862 bgp_deterministic_med_cmd,
1863 "bgp deterministic-med",
1864 "BGP specific commands\n"
1865 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1866 {
1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1868
1869 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1870 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1871 bgp_recalculate_all_bestpaths(bgp);
1872 }
1873
1874 return CMD_SUCCESS;
1875 }
1876
1877 DEFUN (no_bgp_deterministic_med,
1878 no_bgp_deterministic_med_cmd,
1879 "no bgp deterministic-med",
1880 NO_STR
1881 "BGP specific commands\n"
1882 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1883 {
1884 VTY_DECLVAR_CONTEXT(bgp, bgp);
1885 int bestpath_per_as_used;
1886 afi_t afi;
1887 safi_t safi;
1888 struct peer *peer;
1889 struct listnode *node, *nnode;
1890
1891 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1892 bestpath_per_as_used = 0;
1893
1894 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1895 FOREACH_AFI_SAFI (afi, safi)
1896 if (bgp_addpath_dmed_required(
1897 peer->addpath_type[afi][safi])) {
1898 bestpath_per_as_used = 1;
1899 break;
1900 }
1901
1902 if (bestpath_per_as_used)
1903 break;
1904 }
1905
1906 if (bestpath_per_as_used) {
1907 vty_out(vty,
1908 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1909 return CMD_WARNING_CONFIG_FAILED;
1910 } else {
1911 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1912 bgp_recalculate_all_bestpaths(bgp);
1913 }
1914 }
1915
1916 return CMD_SUCCESS;
1917 }
1918
1919 /* "bgp graceful-restart" configuration. */
1920 DEFUN (bgp_graceful_restart,
1921 bgp_graceful_restart_cmd,
1922 "bgp graceful-restart",
1923 "BGP specific commands\n"
1924 "Graceful restart capability parameters\n")
1925 {
1926 VTY_DECLVAR_CONTEXT(bgp, bgp);
1927 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1928 return CMD_SUCCESS;
1929 }
1930
1931 DEFUN (no_bgp_graceful_restart,
1932 no_bgp_graceful_restart_cmd,
1933 "no bgp graceful-restart",
1934 NO_STR
1935 "BGP specific commands\n"
1936 "Graceful restart capability parameters\n")
1937 {
1938 VTY_DECLVAR_CONTEXT(bgp, bgp);
1939 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1940 return CMD_SUCCESS;
1941 }
1942
1943 DEFUN (bgp_graceful_restart_stalepath_time,
1944 bgp_graceful_restart_stalepath_time_cmd,
1945 "bgp graceful-restart stalepath-time (1-4095)",
1946 "BGP specific commands\n"
1947 "Graceful restart capability parameters\n"
1948 "Set the max time to hold onto restarting peer's stale paths\n"
1949 "Delay value (seconds)\n")
1950 {
1951 VTY_DECLVAR_CONTEXT(bgp, bgp);
1952 int idx_number = 3;
1953 uint32_t stalepath;
1954
1955 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1956 bgp->stalepath_time = stalepath;
1957 return CMD_SUCCESS;
1958 }
1959
1960 DEFUN (bgp_graceful_restart_restart_time,
1961 bgp_graceful_restart_restart_time_cmd,
1962 "bgp graceful-restart restart-time (1-4095)",
1963 "BGP specific commands\n"
1964 "Graceful restart capability parameters\n"
1965 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1966 "Delay value (seconds)\n")
1967 {
1968 VTY_DECLVAR_CONTEXT(bgp, bgp);
1969 int idx_number = 3;
1970 uint32_t restart;
1971
1972 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1973 bgp->restart_time = restart;
1974 return CMD_SUCCESS;
1975 }
1976
1977 DEFUN (no_bgp_graceful_restart_stalepath_time,
1978 no_bgp_graceful_restart_stalepath_time_cmd,
1979 "no bgp graceful-restart stalepath-time [(1-4095)]",
1980 NO_STR
1981 "BGP specific commands\n"
1982 "Graceful restart capability parameters\n"
1983 "Set the max time to hold onto restarting peer's stale paths\n"
1984 "Delay value (seconds)\n")
1985 {
1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
1987
1988 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1989 return CMD_SUCCESS;
1990 }
1991
1992 DEFUN (no_bgp_graceful_restart_restart_time,
1993 no_bgp_graceful_restart_restart_time_cmd,
1994 "no bgp graceful-restart restart-time [(1-4095)]",
1995 NO_STR
1996 "BGP specific commands\n"
1997 "Graceful restart capability parameters\n"
1998 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1999 "Delay value (seconds)\n")
2000 {
2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002
2003 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2004 return CMD_SUCCESS;
2005 }
2006
2007 DEFUN (bgp_graceful_restart_preserve_fw,
2008 bgp_graceful_restart_preserve_fw_cmd,
2009 "bgp graceful-restart preserve-fw-state",
2010 "BGP specific commands\n"
2011 "Graceful restart capability parameters\n"
2012 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2013 {
2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
2015 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2016 return CMD_SUCCESS;
2017 }
2018
2019 DEFUN (no_bgp_graceful_restart_preserve_fw,
2020 no_bgp_graceful_restart_preserve_fw_cmd,
2021 "no bgp graceful-restart preserve-fw-state",
2022 NO_STR
2023 "BGP specific commands\n"
2024 "Graceful restart capability parameters\n"
2025 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2026 {
2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
2028 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2029 return CMD_SUCCESS;
2030 }
2031
2032 /* "bgp graceful-shutdown" configuration */
2033 DEFUN (bgp_graceful_shutdown,
2034 bgp_graceful_shutdown_cmd,
2035 "bgp graceful-shutdown",
2036 BGP_STR
2037 "Graceful shutdown parameters\n")
2038 {
2039 VTY_DECLVAR_CONTEXT(bgp, bgp);
2040
2041 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2042 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2043 bgp_static_redo_import_check(bgp);
2044 bgp_redistribute_redo(bgp);
2045 bgp_clear_star_soft_out(vty, bgp->name);
2046 bgp_clear_star_soft_in(vty, bgp->name);
2047 }
2048
2049 return CMD_SUCCESS;
2050 }
2051
2052 DEFUN (no_bgp_graceful_shutdown,
2053 no_bgp_graceful_shutdown_cmd,
2054 "no bgp graceful-shutdown",
2055 NO_STR
2056 BGP_STR
2057 "Graceful shutdown parameters\n")
2058 {
2059 VTY_DECLVAR_CONTEXT(bgp, bgp);
2060
2061 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2062 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2063 bgp_static_redo_import_check(bgp);
2064 bgp_redistribute_redo(bgp);
2065 bgp_clear_star_soft_out(vty, bgp->name);
2066 bgp_clear_star_soft_in(vty, bgp->name);
2067 }
2068
2069 return CMD_SUCCESS;
2070 }
2071
2072 /* "bgp fast-external-failover" configuration. */
2073 DEFUN (bgp_fast_external_failover,
2074 bgp_fast_external_failover_cmd,
2075 "bgp fast-external-failover",
2076 BGP_STR
2077 "Immediately reset session if a link to a directly connected external peer goes down\n")
2078 {
2079 VTY_DECLVAR_CONTEXT(bgp, bgp);
2080 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2081 return CMD_SUCCESS;
2082 }
2083
2084 DEFUN (no_bgp_fast_external_failover,
2085 no_bgp_fast_external_failover_cmd,
2086 "no bgp fast-external-failover",
2087 NO_STR
2088 BGP_STR
2089 "Immediately reset session if a link to a directly connected external peer goes down\n")
2090 {
2091 VTY_DECLVAR_CONTEXT(bgp, bgp);
2092 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2093 return CMD_SUCCESS;
2094 }
2095
2096 /* "bgp bestpath compare-routerid" configuration. */
2097 DEFUN (bgp_bestpath_compare_router_id,
2098 bgp_bestpath_compare_router_id_cmd,
2099 "bgp bestpath compare-routerid",
2100 "BGP specific commands\n"
2101 "Change the default bestpath selection\n"
2102 "Compare router-id for identical EBGP paths\n")
2103 {
2104 VTY_DECLVAR_CONTEXT(bgp, bgp);
2105 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2106 bgp_recalculate_all_bestpaths(bgp);
2107
2108 return CMD_SUCCESS;
2109 }
2110
2111 DEFUN (no_bgp_bestpath_compare_router_id,
2112 no_bgp_bestpath_compare_router_id_cmd,
2113 "no bgp bestpath compare-routerid",
2114 NO_STR
2115 "BGP specific commands\n"
2116 "Change the default bestpath selection\n"
2117 "Compare router-id for identical EBGP paths\n")
2118 {
2119 VTY_DECLVAR_CONTEXT(bgp, bgp);
2120 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2121 bgp_recalculate_all_bestpaths(bgp);
2122
2123 return CMD_SUCCESS;
2124 }
2125
2126 /* "bgp bestpath as-path ignore" configuration. */
2127 DEFUN (bgp_bestpath_aspath_ignore,
2128 bgp_bestpath_aspath_ignore_cmd,
2129 "bgp bestpath as-path ignore",
2130 "BGP specific commands\n"
2131 "Change the default bestpath selection\n"
2132 "AS-path attribute\n"
2133 "Ignore as-path length in selecting a route\n")
2134 {
2135 VTY_DECLVAR_CONTEXT(bgp, bgp);
2136 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2137 bgp_recalculate_all_bestpaths(bgp);
2138
2139 return CMD_SUCCESS;
2140 }
2141
2142 DEFUN (no_bgp_bestpath_aspath_ignore,
2143 no_bgp_bestpath_aspath_ignore_cmd,
2144 "no bgp bestpath as-path ignore",
2145 NO_STR
2146 "BGP specific commands\n"
2147 "Change the default bestpath selection\n"
2148 "AS-path attribute\n"
2149 "Ignore as-path length in selecting a route\n")
2150 {
2151 VTY_DECLVAR_CONTEXT(bgp, bgp);
2152 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2153 bgp_recalculate_all_bestpaths(bgp);
2154
2155 return CMD_SUCCESS;
2156 }
2157
2158 /* "bgp bestpath as-path confed" configuration. */
2159 DEFUN (bgp_bestpath_aspath_confed,
2160 bgp_bestpath_aspath_confed_cmd,
2161 "bgp bestpath as-path confed",
2162 "BGP specific commands\n"
2163 "Change the default bestpath selection\n"
2164 "AS-path attribute\n"
2165 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2166 {
2167 VTY_DECLVAR_CONTEXT(bgp, bgp);
2168 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2169 bgp_recalculate_all_bestpaths(bgp);
2170
2171 return CMD_SUCCESS;
2172 }
2173
2174 DEFUN (no_bgp_bestpath_aspath_confed,
2175 no_bgp_bestpath_aspath_confed_cmd,
2176 "no bgp bestpath as-path confed",
2177 NO_STR
2178 "BGP specific commands\n"
2179 "Change the default bestpath selection\n"
2180 "AS-path attribute\n"
2181 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2182 {
2183 VTY_DECLVAR_CONTEXT(bgp, bgp);
2184 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2185 bgp_recalculate_all_bestpaths(bgp);
2186
2187 return CMD_SUCCESS;
2188 }
2189
2190 /* "bgp bestpath as-path multipath-relax" configuration. */
2191 DEFUN (bgp_bestpath_aspath_multipath_relax,
2192 bgp_bestpath_aspath_multipath_relax_cmd,
2193 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2194 "BGP specific commands\n"
2195 "Change the default bestpath selection\n"
2196 "AS-path attribute\n"
2197 "Allow load sharing across routes that have different AS paths (but same length)\n"
2198 "Generate an AS_SET\n"
2199 "Do not generate an AS_SET\n")
2200 {
2201 VTY_DECLVAR_CONTEXT(bgp, bgp);
2202 int idx = 0;
2203 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2204
2205 /* no-as-set is now the default behavior so we can silently
2206 * ignore it */
2207 if (argv_find(argv, argc, "as-set", &idx))
2208 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2209 else
2210 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2211
2212 bgp_recalculate_all_bestpaths(bgp);
2213
2214 return CMD_SUCCESS;
2215 }
2216
2217 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2218 no_bgp_bestpath_aspath_multipath_relax_cmd,
2219 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2220 NO_STR
2221 "BGP specific commands\n"
2222 "Change the default bestpath selection\n"
2223 "AS-path attribute\n"
2224 "Allow load sharing across routes that have different AS paths (but same length)\n"
2225 "Generate an AS_SET\n"
2226 "Do not generate an AS_SET\n")
2227 {
2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2230 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2231 bgp_recalculate_all_bestpaths(bgp);
2232
2233 return CMD_SUCCESS;
2234 }
2235
2236 /* "bgp log-neighbor-changes" configuration. */
2237 DEFUN (bgp_log_neighbor_changes,
2238 bgp_log_neighbor_changes_cmd,
2239 "bgp log-neighbor-changes",
2240 "BGP specific commands\n"
2241 "Log neighbor up/down and reset reason\n")
2242 {
2243 VTY_DECLVAR_CONTEXT(bgp, bgp);
2244 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2245 return CMD_SUCCESS;
2246 }
2247
2248 DEFUN (no_bgp_log_neighbor_changes,
2249 no_bgp_log_neighbor_changes_cmd,
2250 "no bgp log-neighbor-changes",
2251 NO_STR
2252 "BGP specific commands\n"
2253 "Log neighbor up/down and reset reason\n")
2254 {
2255 VTY_DECLVAR_CONTEXT(bgp, bgp);
2256 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2257 return CMD_SUCCESS;
2258 }
2259
2260 /* "bgp bestpath med" configuration. */
2261 DEFUN (bgp_bestpath_med,
2262 bgp_bestpath_med_cmd,
2263 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2264 "BGP specific commands\n"
2265 "Change the default bestpath selection\n"
2266 "MED attribute\n"
2267 "Compare MED among confederation paths\n"
2268 "Treat missing MED as the least preferred one\n"
2269 "Treat missing MED as the least preferred one\n"
2270 "Compare MED among confederation paths\n")
2271 {
2272 VTY_DECLVAR_CONTEXT(bgp, bgp);
2273
2274 int idx = 0;
2275 if (argv_find(argv, argc, "confed", &idx))
2276 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2277 idx = 0;
2278 if (argv_find(argv, argc, "missing-as-worst", &idx))
2279 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2280
2281 bgp_recalculate_all_bestpaths(bgp);
2282
2283 return CMD_SUCCESS;
2284 }
2285
2286 DEFUN (no_bgp_bestpath_med,
2287 no_bgp_bestpath_med_cmd,
2288 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2289 NO_STR
2290 "BGP specific commands\n"
2291 "Change the default bestpath selection\n"
2292 "MED attribute\n"
2293 "Compare MED among confederation paths\n"
2294 "Treat missing MED as the least preferred one\n"
2295 "Treat missing MED as the least preferred one\n"
2296 "Compare MED among confederation paths\n")
2297 {
2298 VTY_DECLVAR_CONTEXT(bgp, bgp);
2299
2300 int idx = 0;
2301 if (argv_find(argv, argc, "confed", &idx))
2302 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2303 idx = 0;
2304 if (argv_find(argv, argc, "missing-as-worst", &idx))
2305 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2306
2307 bgp_recalculate_all_bestpaths(bgp);
2308
2309 return CMD_SUCCESS;
2310 }
2311
2312 /* "no bgp default ipv4-unicast". */
2313 DEFUN (no_bgp_default_ipv4_unicast,
2314 no_bgp_default_ipv4_unicast_cmd,
2315 "no bgp default ipv4-unicast",
2316 NO_STR
2317 "BGP specific commands\n"
2318 "Configure BGP defaults\n"
2319 "Activate ipv4-unicast for a peer by default\n")
2320 {
2321 VTY_DECLVAR_CONTEXT(bgp, bgp);
2322 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2323 return CMD_SUCCESS;
2324 }
2325
2326 DEFUN (bgp_default_ipv4_unicast,
2327 bgp_default_ipv4_unicast_cmd,
2328 "bgp default ipv4-unicast",
2329 "BGP specific commands\n"
2330 "Configure BGP defaults\n"
2331 "Activate ipv4-unicast for a peer by default\n")
2332 {
2333 VTY_DECLVAR_CONTEXT(bgp, bgp);
2334 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2335 return CMD_SUCCESS;
2336 }
2337
2338 /* Display hostname in certain command outputs */
2339 DEFUN (bgp_default_show_hostname,
2340 bgp_default_show_hostname_cmd,
2341 "bgp default show-hostname",
2342 "BGP specific commands\n"
2343 "Configure BGP defaults\n"
2344 "Show hostname in certain command outputs\n")
2345 {
2346 VTY_DECLVAR_CONTEXT(bgp, bgp);
2347 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2348 return CMD_SUCCESS;
2349 }
2350
2351 DEFUN (no_bgp_default_show_hostname,
2352 no_bgp_default_show_hostname_cmd,
2353 "no bgp default show-hostname",
2354 NO_STR
2355 "BGP specific commands\n"
2356 "Configure BGP defaults\n"
2357 "Show hostname in certain command outputs\n")
2358 {
2359 VTY_DECLVAR_CONTEXT(bgp, bgp);
2360 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2361 return CMD_SUCCESS;
2362 }
2363
2364 /* "bgp network import-check" configuration. */
2365 DEFUN (bgp_network_import_check,
2366 bgp_network_import_check_cmd,
2367 "bgp network import-check",
2368 "BGP specific commands\n"
2369 "BGP network command\n"
2370 "Check BGP network route exists in IGP\n")
2371 {
2372 VTY_DECLVAR_CONTEXT(bgp, bgp);
2373 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2374 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2375 bgp_static_redo_import_check(bgp);
2376 }
2377
2378 return CMD_SUCCESS;
2379 }
2380
2381 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2382 "bgp network import-check exact",
2383 "BGP specific commands\n"
2384 "BGP network command\n"
2385 "Check BGP network route exists in IGP\n"
2386 "Match route precisely\n")
2387
2388 DEFUN (no_bgp_network_import_check,
2389 no_bgp_network_import_check_cmd,
2390 "no bgp network import-check",
2391 NO_STR
2392 "BGP specific commands\n"
2393 "BGP network command\n"
2394 "Check BGP network route exists in IGP\n")
2395 {
2396 VTY_DECLVAR_CONTEXT(bgp, bgp);
2397 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2398 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2399 bgp_static_redo_import_check(bgp);
2400 }
2401
2402 return CMD_SUCCESS;
2403 }
2404
2405 DEFUN (bgp_default_local_preference,
2406 bgp_default_local_preference_cmd,
2407 "bgp default local-preference (0-4294967295)",
2408 "BGP specific commands\n"
2409 "Configure BGP defaults\n"
2410 "local preference (higher=more preferred)\n"
2411 "Configure default local preference value\n")
2412 {
2413 VTY_DECLVAR_CONTEXT(bgp, bgp);
2414 int idx_number = 3;
2415 uint32_t local_pref;
2416
2417 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2418
2419 bgp_default_local_preference_set(bgp, local_pref);
2420 bgp_clear_star_soft_in(vty, bgp->name);
2421
2422 return CMD_SUCCESS;
2423 }
2424
2425 DEFUN (no_bgp_default_local_preference,
2426 no_bgp_default_local_preference_cmd,
2427 "no bgp default local-preference [(0-4294967295)]",
2428 NO_STR
2429 "BGP specific commands\n"
2430 "Configure BGP defaults\n"
2431 "local preference (higher=more preferred)\n"
2432 "Configure default local preference value\n")
2433 {
2434 VTY_DECLVAR_CONTEXT(bgp, bgp);
2435 bgp_default_local_preference_unset(bgp);
2436 bgp_clear_star_soft_in(vty, bgp->name);
2437
2438 return CMD_SUCCESS;
2439 }
2440
2441
2442 DEFUN (bgp_default_subgroup_pkt_queue_max,
2443 bgp_default_subgroup_pkt_queue_max_cmd,
2444 "bgp default subgroup-pkt-queue-max (20-100)",
2445 "BGP specific commands\n"
2446 "Configure BGP defaults\n"
2447 "subgroup-pkt-queue-max\n"
2448 "Configure subgroup packet queue max\n")
2449 {
2450 VTY_DECLVAR_CONTEXT(bgp, bgp);
2451 int idx_number = 3;
2452 uint32_t max_size;
2453
2454 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2455
2456 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2457
2458 return CMD_SUCCESS;
2459 }
2460
2461 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2462 no_bgp_default_subgroup_pkt_queue_max_cmd,
2463 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2464 NO_STR
2465 "BGP specific commands\n"
2466 "Configure BGP defaults\n"
2467 "subgroup-pkt-queue-max\n"
2468 "Configure subgroup packet queue max\n")
2469 {
2470 VTY_DECLVAR_CONTEXT(bgp, bgp);
2471 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2472 return CMD_SUCCESS;
2473 }
2474
2475
2476 DEFUN (bgp_rr_allow_outbound_policy,
2477 bgp_rr_allow_outbound_policy_cmd,
2478 "bgp route-reflector allow-outbound-policy",
2479 "BGP specific commands\n"
2480 "Allow modifications made by out route-map\n"
2481 "on ibgp neighbors\n")
2482 {
2483 VTY_DECLVAR_CONTEXT(bgp, bgp);
2484
2485 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2486 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2487 update_group_announce_rrclients(bgp);
2488 bgp_clear_star_soft_out(vty, bgp->name);
2489 }
2490
2491 return CMD_SUCCESS;
2492 }
2493
2494 DEFUN (no_bgp_rr_allow_outbound_policy,
2495 no_bgp_rr_allow_outbound_policy_cmd,
2496 "no bgp route-reflector allow-outbound-policy",
2497 NO_STR
2498 "BGP specific commands\n"
2499 "Allow modifications made by out route-map\n"
2500 "on ibgp neighbors\n")
2501 {
2502 VTY_DECLVAR_CONTEXT(bgp, bgp);
2503
2504 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2505 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2506 update_group_announce_rrclients(bgp);
2507 bgp_clear_star_soft_out(vty, bgp->name);
2508 }
2509
2510 return CMD_SUCCESS;
2511 }
2512
2513 DEFUN (bgp_listen_limit,
2514 bgp_listen_limit_cmd,
2515 "bgp listen limit (1-5000)",
2516 "BGP specific commands\n"
2517 "Configure BGP defaults\n"
2518 "maximum number of BGP Dynamic Neighbors that can be created\n"
2519 "Configure Dynamic Neighbors listen limit value\n")
2520 {
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 int idx_number = 3;
2523 int listen_limit;
2524
2525 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2526
2527 bgp_listen_limit_set(bgp, listen_limit);
2528
2529 return CMD_SUCCESS;
2530 }
2531
2532 DEFUN (no_bgp_listen_limit,
2533 no_bgp_listen_limit_cmd,
2534 "no bgp listen limit [(1-5000)]",
2535 "BGP specific commands\n"
2536 "Configure BGP defaults\n"
2537 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2538 "Configure Dynamic Neighbors listen limit value to default\n"
2539 "Configure Dynamic Neighbors listen limit value\n")
2540 {
2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 bgp_listen_limit_unset(bgp);
2543 return CMD_SUCCESS;
2544 }
2545
2546
2547 /*
2548 * Check if this listen range is already configured. Check for exact
2549 * match or overlap based on input.
2550 */
2551 static struct peer_group *listen_range_exists(struct bgp *bgp,
2552 struct prefix *range, int exact)
2553 {
2554 struct listnode *node, *nnode;
2555 struct listnode *node1, *nnode1;
2556 struct peer_group *group;
2557 struct prefix *lr;
2558 afi_t afi;
2559 int match;
2560
2561 afi = family2afi(range->family);
2562 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2563 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2564 lr)) {
2565 if (exact)
2566 match = prefix_same(range, lr);
2567 else
2568 match = (prefix_match(range, lr)
2569 || prefix_match(lr, range));
2570 if (match)
2571 return group;
2572 }
2573 }
2574
2575 return NULL;
2576 }
2577
2578 DEFUN (bgp_listen_range,
2579 bgp_listen_range_cmd,
2580 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2581 "BGP specific commands\n"
2582 "Configure BGP dynamic neighbors listen range\n"
2583 "Configure BGP dynamic neighbors listen range\n"
2584 NEIGHBOR_ADDR_STR
2585 "Member of the peer-group\n"
2586 "Peer-group name\n")
2587 {
2588 VTY_DECLVAR_CONTEXT(bgp, bgp);
2589 struct prefix range;
2590 struct peer_group *group, *existing_group;
2591 afi_t afi;
2592 int ret;
2593 int idx = 0;
2594
2595 argv_find(argv, argc, "A.B.C.D/M", &idx);
2596 argv_find(argv, argc, "X:X::X:X/M", &idx);
2597 char *prefix = argv[idx]->arg;
2598 argv_find(argv, argc, "WORD", &idx);
2599 char *peergroup = argv[idx]->arg;
2600
2601 /* Convert IP prefix string to struct prefix. */
2602 ret = str2prefix(prefix, &range);
2603 if (!ret) {
2604 vty_out(vty, "%% Malformed listen range\n");
2605 return CMD_WARNING_CONFIG_FAILED;
2606 }
2607
2608 afi = family2afi(range.family);
2609
2610 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2611 vty_out(vty,
2612 "%% Malformed listen range (link-local address)\n");
2613 return CMD_WARNING_CONFIG_FAILED;
2614 }
2615
2616 apply_mask(&range);
2617
2618 /* Check if same listen range is already configured. */
2619 existing_group = listen_range_exists(bgp, &range, 1);
2620 if (existing_group) {
2621 if (strcmp(existing_group->name, peergroup) == 0)
2622 return CMD_SUCCESS;
2623 else {
2624 vty_out(vty,
2625 "%% Same listen range is attached to peer-group %s\n",
2626 existing_group->name);
2627 return CMD_WARNING_CONFIG_FAILED;
2628 }
2629 }
2630
2631 /* Check if an overlapping listen range exists. */
2632 if (listen_range_exists(bgp, &range, 0)) {
2633 vty_out(vty,
2634 "%% Listen range overlaps with existing listen range\n");
2635 return CMD_WARNING_CONFIG_FAILED;
2636 }
2637
2638 group = peer_group_lookup(bgp, peergroup);
2639 if (!group) {
2640 vty_out(vty, "%% Configure the peer-group first\n");
2641 return CMD_WARNING_CONFIG_FAILED;
2642 }
2643
2644 ret = peer_group_listen_range_add(group, &range);
2645 return bgp_vty_return(vty, ret);
2646 }
2647
2648 DEFUN (no_bgp_listen_range,
2649 no_bgp_listen_range_cmd,
2650 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2651 NO_STR
2652 "BGP specific commands\n"
2653 "Unconfigure BGP dynamic neighbors listen range\n"
2654 "Unconfigure BGP dynamic neighbors listen range\n"
2655 NEIGHBOR_ADDR_STR
2656 "Member of the peer-group\n"
2657 "Peer-group name\n")
2658 {
2659 VTY_DECLVAR_CONTEXT(bgp, bgp);
2660 struct prefix range;
2661 struct peer_group *group;
2662 afi_t afi;
2663 int ret;
2664 int idx = 0;
2665
2666 argv_find(argv, argc, "A.B.C.D/M", &idx);
2667 argv_find(argv, argc, "X:X::X:X/M", &idx);
2668 char *prefix = argv[idx]->arg;
2669 argv_find(argv, argc, "WORD", &idx);
2670 char *peergroup = argv[idx]->arg;
2671
2672 /* Convert IP prefix string to struct prefix. */
2673 ret = str2prefix(prefix, &range);
2674 if (!ret) {
2675 vty_out(vty, "%% Malformed listen range\n");
2676 return CMD_WARNING_CONFIG_FAILED;
2677 }
2678
2679 afi = family2afi(range.family);
2680
2681 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2682 vty_out(vty,
2683 "%% Malformed listen range (link-local address)\n");
2684 return CMD_WARNING_CONFIG_FAILED;
2685 }
2686
2687 apply_mask(&range);
2688
2689 group = peer_group_lookup(bgp, peergroup);
2690 if (!group) {
2691 vty_out(vty, "%% Peer-group does not exist\n");
2692 return CMD_WARNING_CONFIG_FAILED;
2693 }
2694
2695 ret = peer_group_listen_range_del(group, &range);
2696 return bgp_vty_return(vty, ret);
2697 }
2698
2699 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2700 {
2701 struct peer_group *group;
2702 struct listnode *node, *nnode, *rnode, *nrnode;
2703 struct prefix *range;
2704 afi_t afi;
2705 char buf[PREFIX2STR_BUFFER];
2706
2707 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2708 vty_out(vty, " bgp listen limit %d\n",
2709 bgp->dynamic_neighbors_limit);
2710
2711 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2712 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2713 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2714 nrnode, range)) {
2715 prefix2str(range, buf, sizeof(buf));
2716 vty_out(vty,
2717 " bgp listen range %s peer-group %s\n",
2718 buf, group->name);
2719 }
2720 }
2721 }
2722 }
2723
2724
2725 DEFUN (bgp_disable_connected_route_check,
2726 bgp_disable_connected_route_check_cmd,
2727 "bgp disable-ebgp-connected-route-check",
2728 "BGP specific commands\n"
2729 "Disable checking if nexthop is connected on ebgp sessions\n")
2730 {
2731 VTY_DECLVAR_CONTEXT(bgp, bgp);
2732 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2733 bgp_clear_star_soft_in(vty, bgp->name);
2734
2735 return CMD_SUCCESS;
2736 }
2737
2738 DEFUN (no_bgp_disable_connected_route_check,
2739 no_bgp_disable_connected_route_check_cmd,
2740 "no bgp disable-ebgp-connected-route-check",
2741 NO_STR
2742 "BGP specific commands\n"
2743 "Disable checking if nexthop is connected on ebgp sessions\n")
2744 {
2745 VTY_DECLVAR_CONTEXT(bgp, bgp);
2746 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2747 bgp_clear_star_soft_in(vty, bgp->name);
2748
2749 return CMD_SUCCESS;
2750 }
2751
2752
2753 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2754 const char *as_str, afi_t afi, safi_t safi)
2755 {
2756 VTY_DECLVAR_CONTEXT(bgp, bgp);
2757 int ret;
2758 as_t as;
2759 int as_type = AS_SPECIFIED;
2760 union sockunion su;
2761
2762 if (as_str[0] == 'i') {
2763 as = 0;
2764 as_type = AS_INTERNAL;
2765 } else if (as_str[0] == 'e') {
2766 as = 0;
2767 as_type = AS_EXTERNAL;
2768 } else {
2769 /* Get AS number. */
2770 as = strtoul(as_str, NULL, 10);
2771 }
2772
2773 /* If peer is peer group or interface peer, call proper function. */
2774 ret = str2sockunion(peer_str, &su);
2775 if (ret < 0) {
2776 struct peer *peer;
2777
2778 /* Check if existing interface peer */
2779 peer = peer_lookup_by_conf_if(bgp, peer_str);
2780
2781 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2782 safi);
2783
2784 /* if not interface peer, check peer-group settings */
2785 if (ret < 0 && !peer) {
2786 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2787 if (ret < 0) {
2788 vty_out(vty,
2789 "%% Create the peer-group or interface first\n");
2790 return CMD_WARNING_CONFIG_FAILED;
2791 }
2792 return CMD_SUCCESS;
2793 }
2794 } else {
2795 if (peer_address_self_check(bgp, &su)) {
2796 vty_out(vty,
2797 "%% Can not configure the local system as neighbor\n");
2798 return CMD_WARNING_CONFIG_FAILED;
2799 }
2800 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2801 }
2802
2803 /* This peer belongs to peer group. */
2804 switch (ret) {
2805 case BGP_ERR_PEER_GROUP_MEMBER:
2806 vty_out(vty,
2807 "%% Peer-group member cannot override remote-as of peer-group\n");
2808 return CMD_WARNING_CONFIG_FAILED;
2809 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2810 vty_out(vty,
2811 "%% Peer-group members must be all internal or all external\n");
2812 return CMD_WARNING_CONFIG_FAILED;
2813 }
2814 return bgp_vty_return(vty, ret);
2815 }
2816
2817 DEFUN (bgp_default_shutdown,
2818 bgp_default_shutdown_cmd,
2819 "[no] bgp default shutdown",
2820 NO_STR
2821 BGP_STR
2822 "Configure BGP defaults\n"
2823 "Apply administrative shutdown to newly configured peers\n")
2824 {
2825 VTY_DECLVAR_CONTEXT(bgp, bgp);
2826 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2827 return CMD_SUCCESS;
2828 }
2829
2830 DEFUN (neighbor_remote_as,
2831 neighbor_remote_as_cmd,
2832 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2833 NEIGHBOR_STR
2834 NEIGHBOR_ADDR_STR2
2835 "Specify a BGP neighbor\n"
2836 AS_STR
2837 "Internal BGP peer\n"
2838 "External BGP peer\n")
2839 {
2840 int idx_peer = 1;
2841 int idx_remote_as = 3;
2842 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2843 argv[idx_remote_as]->arg, AFI_IP,
2844 SAFI_UNICAST);
2845 }
2846
2847 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2848 afi_t afi, safi_t safi, int v6only,
2849 const char *peer_group_name,
2850 const char *as_str)
2851 {
2852 VTY_DECLVAR_CONTEXT(bgp, bgp);
2853 as_t as = 0;
2854 int as_type = AS_UNSPECIFIED;
2855 struct peer *peer;
2856 struct peer_group *group;
2857 int ret = 0;
2858 union sockunion su;
2859
2860 group = peer_group_lookup(bgp, conf_if);
2861
2862 if (group) {
2863 vty_out(vty, "%% Name conflict with peer-group \n");
2864 return CMD_WARNING_CONFIG_FAILED;
2865 }
2866
2867 if (as_str) {
2868 if (as_str[0] == 'i') {
2869 as_type = AS_INTERNAL;
2870 } else if (as_str[0] == 'e') {
2871 as_type = AS_EXTERNAL;
2872 } else {
2873 /* Get AS number. */
2874 as = strtoul(as_str, NULL, 10);
2875 as_type = AS_SPECIFIED;
2876 }
2877 }
2878
2879 peer = peer_lookup_by_conf_if(bgp, conf_if);
2880 if (peer) {
2881 if (as_str)
2882 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2883 afi, safi);
2884 } else {
2885 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2886 && afi == AFI_IP && safi == SAFI_UNICAST)
2887 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2888 as_type, 0, 0, NULL);
2889 else
2890 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2891 as_type, afi, safi, NULL);
2892
2893 if (!peer) {
2894 vty_out(vty, "%% BGP failed to create peer\n");
2895 return CMD_WARNING_CONFIG_FAILED;
2896 }
2897
2898 if (v6only)
2899 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2900
2901 /* Request zebra to initiate IPv6 RAs on this interface. We do
2902 * this
2903 * any unnumbered peer in order to not worry about run-time
2904 * transitions
2905 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2906 * address
2907 * gets deleted later etc.)
2908 */
2909 if (peer->ifp)
2910 bgp_zebra_initiate_radv(bgp, peer);
2911 }
2912
2913 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2914 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2915 if (v6only)
2916 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2917 else
2918 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2919
2920 /* v6only flag changed. Reset bgp seesion */
2921 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2922 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2923 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2924 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2925 } else
2926 bgp_session_reset(peer);
2927 }
2928
2929 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2930 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2931 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2932 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2933 }
2934
2935 if (peer_group_name) {
2936 group = peer_group_lookup(bgp, peer_group_name);
2937 if (!group) {
2938 vty_out(vty, "%% Configure the peer-group first\n");
2939 return CMD_WARNING_CONFIG_FAILED;
2940 }
2941
2942 ret = peer_group_bind(bgp, &su, peer, group, &as);
2943 }
2944
2945 return bgp_vty_return(vty, ret);
2946 }
2947
2948 DEFUN (neighbor_interface_config,
2949 neighbor_interface_config_cmd,
2950 "neighbor WORD interface [peer-group WORD]",
2951 NEIGHBOR_STR
2952 "Interface name or neighbor tag\n"
2953 "Enable BGP on interface\n"
2954 "Member of the peer-group\n"
2955 "Peer-group name\n")
2956 {
2957 int idx_word = 1;
2958 int idx_peer_group_word = 4;
2959
2960 if (argc > idx_peer_group_word)
2961 return peer_conf_interface_get(
2962 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2963 argv[idx_peer_group_word]->arg, NULL);
2964 else
2965 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2966 SAFI_UNICAST, 0, NULL, NULL);
2967 }
2968
2969 DEFUN (neighbor_interface_config_v6only,
2970 neighbor_interface_config_v6only_cmd,
2971 "neighbor WORD interface v6only [peer-group WORD]",
2972 NEIGHBOR_STR
2973 "Interface name or neighbor tag\n"
2974 "Enable BGP on interface\n"
2975 "Enable BGP with v6 link-local only\n"
2976 "Member of the peer-group\n"
2977 "Peer-group name\n")
2978 {
2979 int idx_word = 1;
2980 int idx_peer_group_word = 5;
2981
2982 if (argc > idx_peer_group_word)
2983 return peer_conf_interface_get(
2984 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2985 argv[idx_peer_group_word]->arg, NULL);
2986
2987 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2988 SAFI_UNICAST, 1, NULL, NULL);
2989 }
2990
2991
2992 DEFUN (neighbor_interface_config_remote_as,
2993 neighbor_interface_config_remote_as_cmd,
2994 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2995 NEIGHBOR_STR
2996 "Interface name or neighbor tag\n"
2997 "Enable BGP on interface\n"
2998 "Specify a BGP neighbor\n"
2999 AS_STR
3000 "Internal BGP peer\n"
3001 "External BGP peer\n")
3002 {
3003 int idx_word = 1;
3004 int idx_remote_as = 4;
3005 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3006 SAFI_UNICAST, 0, NULL,
3007 argv[idx_remote_as]->arg);
3008 }
3009
3010 DEFUN (neighbor_interface_v6only_config_remote_as,
3011 neighbor_interface_v6only_config_remote_as_cmd,
3012 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3013 NEIGHBOR_STR
3014 "Interface name or neighbor tag\n"
3015 "Enable BGP with v6 link-local only\n"
3016 "Enable BGP on interface\n"
3017 "Specify a BGP neighbor\n"
3018 AS_STR
3019 "Internal BGP peer\n"
3020 "External BGP peer\n")
3021 {
3022 int idx_word = 1;
3023 int idx_remote_as = 5;
3024 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3025 SAFI_UNICAST, 1, NULL,
3026 argv[idx_remote_as]->arg);
3027 }
3028
3029 DEFUN (neighbor_peer_group,
3030 neighbor_peer_group_cmd,
3031 "neighbor WORD peer-group",
3032 NEIGHBOR_STR
3033 "Interface name or neighbor tag\n"
3034 "Configure peer-group\n")
3035 {
3036 VTY_DECLVAR_CONTEXT(bgp, bgp);
3037 int idx_word = 1;
3038 struct peer *peer;
3039 struct peer_group *group;
3040
3041 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3042 if (peer) {
3043 vty_out(vty, "%% Name conflict with interface: \n");
3044 return CMD_WARNING_CONFIG_FAILED;
3045 }
3046
3047 group = peer_group_get(bgp, argv[idx_word]->arg);
3048 if (!group) {
3049 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3050 return CMD_WARNING_CONFIG_FAILED;
3051 }
3052
3053 return CMD_SUCCESS;
3054 }
3055
3056 DEFUN (no_neighbor,
3057 no_neighbor_cmd,
3058 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3059 NO_STR
3060 NEIGHBOR_STR
3061 NEIGHBOR_ADDR_STR2
3062 "Specify a BGP neighbor\n"
3063 AS_STR
3064 "Internal BGP peer\n"
3065 "External BGP peer\n")
3066 {
3067 VTY_DECLVAR_CONTEXT(bgp, bgp);
3068 int idx_peer = 2;
3069 int ret;
3070 union sockunion su;
3071 struct peer_group *group;
3072 struct peer *peer;
3073 struct peer *other;
3074
3075 ret = str2sockunion(argv[idx_peer]->arg, &su);
3076 if (ret < 0) {
3077 /* look up for neighbor by interface name config. */
3078 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3079 if (peer) {
3080 /* Request zebra to terminate IPv6 RAs on this
3081 * interface. */
3082 if (peer->ifp)
3083 bgp_zebra_terminate_radv(peer->bgp, peer);
3084 peer_delete(peer);
3085 return CMD_SUCCESS;
3086 }
3087
3088 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3089 if (group)
3090 peer_group_delete(group);
3091 else {
3092 vty_out(vty, "%% Create the peer-group first\n");
3093 return CMD_WARNING_CONFIG_FAILED;
3094 }
3095 } else {
3096 peer = peer_lookup(bgp, &su);
3097 if (peer) {
3098 if (peer_dynamic_neighbor(peer)) {
3099 vty_out(vty,
3100 "%% Operation not allowed on a dynamic neighbor\n");
3101 return CMD_WARNING_CONFIG_FAILED;
3102 }
3103
3104 other = peer->doppelganger;
3105 peer_delete(peer);
3106 if (other && other->status != Deleted)
3107 peer_delete(other);
3108 }
3109 }
3110
3111 return CMD_SUCCESS;
3112 }
3113
3114 DEFUN (no_neighbor_interface_config,
3115 no_neighbor_interface_config_cmd,
3116 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3117 NO_STR
3118 NEIGHBOR_STR
3119 "Interface name\n"
3120 "Configure BGP on interface\n"
3121 "Enable BGP with v6 link-local only\n"
3122 "Member of the peer-group\n"
3123 "Peer-group name\n"
3124 "Specify a BGP neighbor\n"
3125 AS_STR
3126 "Internal BGP peer\n"
3127 "External BGP peer\n")
3128 {
3129 VTY_DECLVAR_CONTEXT(bgp, bgp);
3130 int idx_word = 2;
3131 struct peer *peer;
3132
3133 /* look up for neighbor by interface name config. */
3134 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3135 if (peer) {
3136 /* Request zebra to terminate IPv6 RAs on this interface. */
3137 if (peer->ifp)
3138 bgp_zebra_terminate_radv(peer->bgp, peer);
3139 peer_delete(peer);
3140 } else {
3141 vty_out(vty, "%% Create the bgp interface first\n");
3142 return CMD_WARNING_CONFIG_FAILED;
3143 }
3144 return CMD_SUCCESS;
3145 }
3146
3147 DEFUN (no_neighbor_peer_group,
3148 no_neighbor_peer_group_cmd,
3149 "no neighbor WORD peer-group",
3150 NO_STR
3151 NEIGHBOR_STR
3152 "Neighbor tag\n"
3153 "Configure peer-group\n")
3154 {
3155 VTY_DECLVAR_CONTEXT(bgp, bgp);
3156 int idx_word = 2;
3157 struct peer_group *group;
3158
3159 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3160 if (group)
3161 peer_group_delete(group);
3162 else {
3163 vty_out(vty, "%% Create the peer-group first\n");
3164 return CMD_WARNING_CONFIG_FAILED;
3165 }
3166 return CMD_SUCCESS;
3167 }
3168
3169 DEFUN (no_neighbor_interface_peer_group_remote_as,
3170 no_neighbor_interface_peer_group_remote_as_cmd,
3171 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3172 NO_STR
3173 NEIGHBOR_STR
3174 "Interface name or neighbor tag\n"
3175 "Specify a BGP neighbor\n"
3176 AS_STR
3177 "Internal BGP peer\n"
3178 "External BGP peer\n")
3179 {
3180 VTY_DECLVAR_CONTEXT(bgp, bgp);
3181 int idx_word = 2;
3182 struct peer_group *group;
3183 struct peer *peer;
3184
3185 /* look up for neighbor by interface name config. */
3186 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3187 if (peer) {
3188 peer_as_change(peer, 0, AS_UNSPECIFIED);
3189 return CMD_SUCCESS;
3190 }
3191
3192 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3193 if (group)
3194 peer_group_remote_as_delete(group);
3195 else {
3196 vty_out(vty, "%% Create the peer-group or interface first\n");
3197 return CMD_WARNING_CONFIG_FAILED;
3198 }
3199 return CMD_SUCCESS;
3200 }
3201
3202 DEFUN (neighbor_local_as,
3203 neighbor_local_as_cmd,
3204 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3205 NEIGHBOR_STR
3206 NEIGHBOR_ADDR_STR2
3207 "Specify a local-as number\n"
3208 "AS number used as local AS\n")
3209 {
3210 int idx_peer = 1;
3211 int idx_number = 3;
3212 struct peer *peer;
3213 int ret;
3214 as_t as;
3215
3216 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3217 if (!peer)
3218 return CMD_WARNING_CONFIG_FAILED;
3219
3220 as = strtoul(argv[idx_number]->arg, NULL, 10);
3221 ret = peer_local_as_set(peer, as, 0, 0);
3222 return bgp_vty_return(vty, ret);
3223 }
3224
3225 DEFUN (neighbor_local_as_no_prepend,
3226 neighbor_local_as_no_prepend_cmd,
3227 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3228 NEIGHBOR_STR
3229 NEIGHBOR_ADDR_STR2
3230 "Specify a local-as number\n"
3231 "AS number used as local AS\n"
3232 "Do not prepend local-as to updates from ebgp peers\n")
3233 {
3234 int idx_peer = 1;
3235 int idx_number = 3;
3236 struct peer *peer;
3237 int ret;
3238 as_t as;
3239
3240 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3241 if (!peer)
3242 return CMD_WARNING_CONFIG_FAILED;
3243
3244 as = strtoul(argv[idx_number]->arg, NULL, 10);
3245 ret = peer_local_as_set(peer, as, 1, 0);
3246 return bgp_vty_return(vty, ret);
3247 }
3248
3249 DEFUN (neighbor_local_as_no_prepend_replace_as,
3250 neighbor_local_as_no_prepend_replace_as_cmd,
3251 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3252 NEIGHBOR_STR
3253 NEIGHBOR_ADDR_STR2
3254 "Specify a local-as number\n"
3255 "AS number used as local AS\n"
3256 "Do not prepend local-as to updates from ebgp peers\n"
3257 "Do not prepend local-as to updates from ibgp peers\n")
3258 {
3259 int idx_peer = 1;
3260 int idx_number = 3;
3261 struct peer *peer;
3262 int ret;
3263 as_t as;
3264
3265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3266 if (!peer)
3267 return CMD_WARNING_CONFIG_FAILED;
3268
3269 as = strtoul(argv[idx_number]->arg, NULL, 10);
3270 ret = peer_local_as_set(peer, as, 1, 1);
3271 return bgp_vty_return(vty, ret);
3272 }
3273
3274 DEFUN (no_neighbor_local_as,
3275 no_neighbor_local_as_cmd,
3276 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3277 NO_STR
3278 NEIGHBOR_STR
3279 NEIGHBOR_ADDR_STR2
3280 "Specify a local-as number\n"
3281 "AS number used as local AS\n"
3282 "Do not prepend local-as to updates from ebgp peers\n"
3283 "Do not prepend local-as to updates from ibgp peers\n")
3284 {
3285 int idx_peer = 2;
3286 struct peer *peer;
3287 int ret;
3288
3289 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3290 if (!peer)
3291 return CMD_WARNING_CONFIG_FAILED;
3292
3293 ret = peer_local_as_unset(peer);
3294 return bgp_vty_return(vty, ret);
3295 }
3296
3297
3298 DEFUN (neighbor_solo,
3299 neighbor_solo_cmd,
3300 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3301 NEIGHBOR_STR
3302 NEIGHBOR_ADDR_STR2
3303 "Solo peer - part of its own update group\n")
3304 {
3305 int idx_peer = 1;
3306 struct peer *peer;
3307 int ret;
3308
3309 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3310 if (!peer)
3311 return CMD_WARNING_CONFIG_FAILED;
3312
3313 ret = update_group_adjust_soloness(peer, 1);
3314 return bgp_vty_return(vty, ret);
3315 }
3316
3317 DEFUN (no_neighbor_solo,
3318 no_neighbor_solo_cmd,
3319 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3320 NO_STR
3321 NEIGHBOR_STR
3322 NEIGHBOR_ADDR_STR2
3323 "Solo peer - part of its own update group\n")
3324 {
3325 int idx_peer = 2;
3326 struct peer *peer;
3327 int ret;
3328
3329 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3330 if (!peer)
3331 return CMD_WARNING_CONFIG_FAILED;
3332
3333 ret = update_group_adjust_soloness(peer, 0);
3334 return bgp_vty_return(vty, ret);
3335 }
3336
3337 DEFUN (neighbor_password,
3338 neighbor_password_cmd,
3339 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3340 NEIGHBOR_STR
3341 NEIGHBOR_ADDR_STR2
3342 "Set a password\n"
3343 "The password\n")
3344 {
3345 int idx_peer = 1;
3346 int idx_line = 3;
3347 struct peer *peer;
3348 int ret;
3349
3350 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3351 if (!peer)
3352 return CMD_WARNING_CONFIG_FAILED;
3353
3354 ret = peer_password_set(peer, argv[idx_line]->arg);
3355 return bgp_vty_return(vty, ret);
3356 }
3357
3358 DEFUN (no_neighbor_password,
3359 no_neighbor_password_cmd,
3360 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3361 NO_STR
3362 NEIGHBOR_STR
3363 NEIGHBOR_ADDR_STR2
3364 "Set a password\n"
3365 "The password\n")
3366 {
3367 int idx_peer = 2;
3368 struct peer *peer;
3369 int ret;
3370
3371 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3372 if (!peer)
3373 return CMD_WARNING_CONFIG_FAILED;
3374
3375 ret = peer_password_unset(peer);
3376 return bgp_vty_return(vty, ret);
3377 }
3378
3379 DEFUN (neighbor_activate,
3380 neighbor_activate_cmd,
3381 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3382 NEIGHBOR_STR
3383 NEIGHBOR_ADDR_STR2
3384 "Enable the Address Family for this Neighbor\n")
3385 {
3386 int idx_peer = 1;
3387 int ret;
3388 struct peer *peer;
3389
3390 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3391 if (!peer)
3392 return CMD_WARNING_CONFIG_FAILED;
3393
3394 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3395 return bgp_vty_return(vty, ret);
3396 }
3397
3398 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3399 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3400 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3401 "Enable the Address Family for this Neighbor\n")
3402
3403 DEFUN (no_neighbor_activate,
3404 no_neighbor_activate_cmd,
3405 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3406 NO_STR
3407 NEIGHBOR_STR
3408 NEIGHBOR_ADDR_STR2
3409 "Enable the Address Family for this Neighbor\n")
3410 {
3411 int idx_peer = 2;
3412 int ret;
3413 struct peer *peer;
3414
3415 /* Lookup peer. */
3416 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3417 if (!peer)
3418 return CMD_WARNING_CONFIG_FAILED;
3419
3420 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3421 return bgp_vty_return(vty, ret);
3422 }
3423
3424 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3425 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3426 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3427 "Enable the Address Family for this Neighbor\n")
3428
3429 DEFUN (neighbor_set_peer_group,
3430 neighbor_set_peer_group_cmd,
3431 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3432 NEIGHBOR_STR
3433 NEIGHBOR_ADDR_STR2
3434 "Member of the peer-group\n"
3435 "Peer-group name\n")
3436 {
3437 VTY_DECLVAR_CONTEXT(bgp, bgp);
3438 int idx_peer = 1;
3439 int idx_word = 3;
3440 int ret;
3441 as_t as;
3442 union sockunion su;
3443 struct peer *peer;
3444 struct peer_group *group;
3445
3446 ret = str2sockunion(argv[idx_peer]->arg, &su);
3447 if (ret < 0) {
3448 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3449 if (!peer) {
3450 vty_out(vty, "%% Malformed address or name: %s\n",
3451 argv[idx_peer]->arg);
3452 return CMD_WARNING_CONFIG_FAILED;
3453 }
3454 } else {
3455 if (peer_address_self_check(bgp, &su)) {
3456 vty_out(vty,
3457 "%% Can not configure the local system as neighbor\n");
3458 return CMD_WARNING_CONFIG_FAILED;
3459 }
3460
3461 /* Disallow for dynamic neighbor. */
3462 peer = peer_lookup(bgp, &su);
3463 if (peer && peer_dynamic_neighbor(peer)) {
3464 vty_out(vty,
3465 "%% Operation not allowed on a dynamic neighbor\n");
3466 return CMD_WARNING_CONFIG_FAILED;
3467 }
3468 }
3469
3470 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3471 if (!group) {
3472 vty_out(vty, "%% Configure the peer-group first\n");
3473 return CMD_WARNING_CONFIG_FAILED;
3474 }
3475
3476 ret = peer_group_bind(bgp, &su, peer, group, &as);
3477
3478 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3479 vty_out(vty,
3480 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3481 as);
3482 return CMD_WARNING_CONFIG_FAILED;
3483 }
3484
3485 return bgp_vty_return(vty, ret);
3486 }
3487
3488 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3489 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3490 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3491 "Member of the peer-group\n"
3492 "Peer-group name\n")
3493
3494 DEFUN (no_neighbor_set_peer_group,
3495 no_neighbor_set_peer_group_cmd,
3496 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3497 NO_STR
3498 NEIGHBOR_STR
3499 NEIGHBOR_ADDR_STR2
3500 "Member of the peer-group\n"
3501 "Peer-group name\n")
3502 {
3503 VTY_DECLVAR_CONTEXT(bgp, bgp);
3504 int idx_peer = 2;
3505 int idx_word = 4;
3506 int ret;
3507 struct peer *peer;
3508 struct peer_group *group;
3509
3510 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3511 if (!peer)
3512 return CMD_WARNING_CONFIG_FAILED;
3513
3514 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3515 if (!group) {
3516 vty_out(vty, "%% Configure the peer-group first\n");
3517 return CMD_WARNING_CONFIG_FAILED;
3518 }
3519
3520 ret = peer_delete(peer);
3521
3522 return bgp_vty_return(vty, ret);
3523 }
3524
3525 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3526 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3527 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3528 "Member of the peer-group\n"
3529 "Peer-group name\n")
3530
3531 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3532 uint32_t flag, int set)
3533 {
3534 int ret;
3535 struct peer *peer;
3536
3537 peer = peer_and_group_lookup_vty(vty, ip_str);
3538 if (!peer)
3539 return CMD_WARNING_CONFIG_FAILED;
3540
3541 /*
3542 * If 'neighbor <interface>', then this is for directly connected peers,
3543 * we should not accept disable-connected-check.
3544 */
3545 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3546 vty_out(vty,
3547 "%s is directly connected peer, cannot accept disable-"
3548 "connected-check\n",
3549 ip_str);
3550 return CMD_WARNING_CONFIG_FAILED;
3551 }
3552
3553 if (!set && flag == PEER_FLAG_SHUTDOWN)
3554 peer_tx_shutdown_message_unset(peer);
3555
3556 if (set)
3557 ret = peer_flag_set(peer, flag);
3558 else
3559 ret = peer_flag_unset(peer, flag);
3560
3561 return bgp_vty_return(vty, ret);
3562 }
3563
3564 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3565 {
3566 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3567 }
3568
3569 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3570 uint32_t flag)
3571 {
3572 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3573 }
3574
3575 /* neighbor passive. */
3576 DEFUN (neighbor_passive,
3577 neighbor_passive_cmd,
3578 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3579 NEIGHBOR_STR
3580 NEIGHBOR_ADDR_STR2
3581 "Don't send open messages to this neighbor\n")
3582 {
3583 int idx_peer = 1;
3584 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3585 }
3586
3587 DEFUN (no_neighbor_passive,
3588 no_neighbor_passive_cmd,
3589 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3590 NO_STR
3591 NEIGHBOR_STR
3592 NEIGHBOR_ADDR_STR2
3593 "Don't send open messages to this neighbor\n")
3594 {
3595 int idx_peer = 2;
3596 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3597 }
3598
3599 /* neighbor shutdown. */
3600 DEFUN (neighbor_shutdown_msg,
3601 neighbor_shutdown_msg_cmd,
3602 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3603 NEIGHBOR_STR
3604 NEIGHBOR_ADDR_STR2
3605 "Administratively shut down this neighbor\n"
3606 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3607 "Shutdown message\n")
3608 {
3609 int idx_peer = 1;
3610
3611 if (argc >= 5) {
3612 struct peer *peer =
3613 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3614 char *message;
3615
3616 if (!peer)
3617 return CMD_WARNING_CONFIG_FAILED;
3618 message = argv_concat(argv, argc, 4);
3619 peer_tx_shutdown_message_set(peer, message);
3620 XFREE(MTYPE_TMP, message);
3621 }
3622
3623 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3624 }
3625
3626 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3627 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3628 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3629 "Administratively shut down this neighbor\n")
3630
3631 DEFUN (no_neighbor_shutdown_msg,
3632 no_neighbor_shutdown_msg_cmd,
3633 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3634 NO_STR
3635 NEIGHBOR_STR
3636 NEIGHBOR_ADDR_STR2
3637 "Administratively shut down this neighbor\n"
3638 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3639 "Shutdown message\n")
3640 {
3641 int idx_peer = 2;
3642
3643 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3644 PEER_FLAG_SHUTDOWN);
3645 }
3646
3647 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3648 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3649 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3650 "Administratively shut down this neighbor\n")
3651
3652 /* neighbor capability dynamic. */
3653 DEFUN (neighbor_capability_dynamic,
3654 neighbor_capability_dynamic_cmd,
3655 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3656 NEIGHBOR_STR
3657 NEIGHBOR_ADDR_STR2
3658 "Advertise capability to the peer\n"
3659 "Advertise dynamic capability to this neighbor\n")
3660 {
3661 int idx_peer = 1;
3662 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3663 PEER_FLAG_DYNAMIC_CAPABILITY);
3664 }
3665
3666 DEFUN (no_neighbor_capability_dynamic,
3667 no_neighbor_capability_dynamic_cmd,
3668 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3669 NO_STR
3670 NEIGHBOR_STR
3671 NEIGHBOR_ADDR_STR2
3672 "Advertise capability to the peer\n"
3673 "Advertise dynamic capability to this neighbor\n")
3674 {
3675 int idx_peer = 2;
3676 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3677 PEER_FLAG_DYNAMIC_CAPABILITY);
3678 }
3679
3680 /* neighbor dont-capability-negotiate */
3681 DEFUN (neighbor_dont_capability_negotiate,
3682 neighbor_dont_capability_negotiate_cmd,
3683 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3684 NEIGHBOR_STR
3685 NEIGHBOR_ADDR_STR2
3686 "Do not perform capability negotiation\n")
3687 {
3688 int idx_peer = 1;
3689 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3690 PEER_FLAG_DONT_CAPABILITY);
3691 }
3692
3693 DEFUN (no_neighbor_dont_capability_negotiate,
3694 no_neighbor_dont_capability_negotiate_cmd,
3695 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3696 NO_STR
3697 NEIGHBOR_STR
3698 NEIGHBOR_ADDR_STR2
3699 "Do not perform capability negotiation\n")
3700 {
3701 int idx_peer = 2;
3702 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3703 PEER_FLAG_DONT_CAPABILITY);
3704 }
3705
3706 /* neighbor capability extended next hop encoding */
3707 DEFUN (neighbor_capability_enhe,
3708 neighbor_capability_enhe_cmd,
3709 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3710 NEIGHBOR_STR
3711 NEIGHBOR_ADDR_STR2
3712 "Advertise capability to the peer\n"
3713 "Advertise extended next-hop capability to the peer\n")
3714 {
3715 int idx_peer = 1;
3716 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3717 PEER_FLAG_CAPABILITY_ENHE);
3718 }
3719
3720 DEFUN (no_neighbor_capability_enhe,
3721 no_neighbor_capability_enhe_cmd,
3722 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3723 NO_STR
3724 NEIGHBOR_STR
3725 NEIGHBOR_ADDR_STR2
3726 "Advertise capability to the peer\n"
3727 "Advertise extended next-hop capability to the peer\n")
3728 {
3729 int idx_peer = 2;
3730 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3731 PEER_FLAG_CAPABILITY_ENHE);
3732 }
3733
3734 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3735 afi_t afi, safi_t safi, uint32_t flag,
3736 int set)
3737 {
3738 int ret;
3739 struct peer *peer;
3740
3741 peer = peer_and_group_lookup_vty(vty, peer_str);
3742 if (!peer)
3743 return CMD_WARNING_CONFIG_FAILED;
3744
3745 if (set)
3746 ret = peer_af_flag_set(peer, afi, safi, flag);
3747 else
3748 ret = peer_af_flag_unset(peer, afi, safi, flag);
3749
3750 return bgp_vty_return(vty, ret);
3751 }
3752
3753 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3754 afi_t afi, safi_t safi, uint32_t flag)
3755 {
3756 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3757 }
3758
3759 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3760 afi_t afi, safi_t safi, uint32_t flag)
3761 {
3762 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3763 }
3764
3765 /* neighbor capability orf prefix-list. */
3766 DEFUN (neighbor_capability_orf_prefix,
3767 neighbor_capability_orf_prefix_cmd,
3768 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3769 NEIGHBOR_STR
3770 NEIGHBOR_ADDR_STR2
3771 "Advertise capability to the peer\n"
3772 "Advertise ORF capability to the peer\n"
3773 "Advertise prefixlist ORF capability to this neighbor\n"
3774 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3775 "Capability to RECEIVE the ORF from this neighbor\n"
3776 "Capability to SEND the ORF to this neighbor\n")
3777 {
3778 int idx_peer = 1;
3779 int idx_send_recv = 5;
3780 uint16_t flag = 0;
3781
3782 if (strmatch(argv[idx_send_recv]->text, "send"))
3783 flag = PEER_FLAG_ORF_PREFIX_SM;
3784 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3785 flag = PEER_FLAG_ORF_PREFIX_RM;
3786 else if (strmatch(argv[idx_send_recv]->text, "both"))
3787 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3788 else {
3789 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3790 return CMD_WARNING_CONFIG_FAILED;
3791 }
3792
3793 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3794 bgp_node_safi(vty), flag);
3795 }
3796
3797 ALIAS_HIDDEN(
3798 neighbor_capability_orf_prefix,
3799 neighbor_capability_orf_prefix_hidden_cmd,
3800 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3801 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3802 "Advertise capability to the peer\n"
3803 "Advertise ORF capability to the peer\n"
3804 "Advertise prefixlist ORF capability to this neighbor\n"
3805 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3806 "Capability to RECEIVE the ORF from this neighbor\n"
3807 "Capability to SEND the ORF to this neighbor\n")
3808
3809 DEFUN (no_neighbor_capability_orf_prefix,
3810 no_neighbor_capability_orf_prefix_cmd,
3811 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3812 NO_STR
3813 NEIGHBOR_STR
3814 NEIGHBOR_ADDR_STR2
3815 "Advertise capability to the peer\n"
3816 "Advertise ORF capability to the peer\n"
3817 "Advertise prefixlist ORF capability to this neighbor\n"
3818 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3819 "Capability to RECEIVE the ORF from this neighbor\n"
3820 "Capability to SEND the ORF to this neighbor\n")
3821 {
3822 int idx_peer = 2;
3823 int idx_send_recv = 6;
3824 uint16_t flag = 0;
3825
3826 if (strmatch(argv[idx_send_recv]->text, "send"))
3827 flag = PEER_FLAG_ORF_PREFIX_SM;
3828 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3829 flag = PEER_FLAG_ORF_PREFIX_RM;
3830 else if (strmatch(argv[idx_send_recv]->text, "both"))
3831 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3832 else {
3833 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3834 return CMD_WARNING_CONFIG_FAILED;
3835 }
3836
3837 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3838 bgp_node_afi(vty), bgp_node_safi(vty),
3839 flag);
3840 }
3841
3842 ALIAS_HIDDEN(
3843 no_neighbor_capability_orf_prefix,
3844 no_neighbor_capability_orf_prefix_hidden_cmd,
3845 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3846 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3847 "Advertise capability to the peer\n"
3848 "Advertise ORF capability to the peer\n"
3849 "Advertise prefixlist ORF capability to this neighbor\n"
3850 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3851 "Capability to RECEIVE the ORF from this neighbor\n"
3852 "Capability to SEND the ORF to this neighbor\n")
3853
3854 /* neighbor next-hop-self. */
3855 DEFUN (neighbor_nexthop_self,
3856 neighbor_nexthop_self_cmd,
3857 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3858 NEIGHBOR_STR
3859 NEIGHBOR_ADDR_STR2
3860 "Disable the next hop calculation for this neighbor\n")
3861 {
3862 int idx_peer = 1;
3863 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3864 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3865 }
3866
3867 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3868 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3869 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3870 "Disable the next hop calculation for this neighbor\n")
3871
3872 /* neighbor next-hop-self. */
3873 DEFUN (neighbor_nexthop_self_force,
3874 neighbor_nexthop_self_force_cmd,
3875 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3876 NEIGHBOR_STR
3877 NEIGHBOR_ADDR_STR2
3878 "Disable the next hop calculation for this neighbor\n"
3879 "Set the next hop to self for reflected routes\n")
3880 {
3881 int idx_peer = 1;
3882 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3883 bgp_node_safi(vty),
3884 PEER_FLAG_FORCE_NEXTHOP_SELF);
3885 }
3886
3887 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3888 neighbor_nexthop_self_force_hidden_cmd,
3889 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3890 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3891 "Disable the next hop calculation for this neighbor\n"
3892 "Set the next hop to self for reflected routes\n")
3893
3894 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3895 neighbor_nexthop_self_all_hidden_cmd,
3896 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3897 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3898 "Disable the next hop calculation for this neighbor\n"
3899 "Set the next hop to self for reflected routes\n")
3900
3901 DEFUN (no_neighbor_nexthop_self,
3902 no_neighbor_nexthop_self_cmd,
3903 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3904 NO_STR
3905 NEIGHBOR_STR
3906 NEIGHBOR_ADDR_STR2
3907 "Disable the next hop calculation for this neighbor\n")
3908 {
3909 int idx_peer = 2;
3910 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3911 bgp_node_afi(vty), bgp_node_safi(vty),
3912 PEER_FLAG_NEXTHOP_SELF);
3913 }
3914
3915 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3916 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3917 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3918 "Disable the next hop calculation for this neighbor\n")
3919
3920 DEFUN (no_neighbor_nexthop_self_force,
3921 no_neighbor_nexthop_self_force_cmd,
3922 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3923 NO_STR
3924 NEIGHBOR_STR
3925 NEIGHBOR_ADDR_STR2
3926 "Disable the next hop calculation for this neighbor\n"
3927 "Set the next hop to self for reflected routes\n")
3928 {
3929 int idx_peer = 2;
3930 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3931 bgp_node_afi(vty), bgp_node_safi(vty),
3932 PEER_FLAG_FORCE_NEXTHOP_SELF);
3933 }
3934
3935 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3936 no_neighbor_nexthop_self_force_hidden_cmd,
3937 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3938 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3939 "Disable the next hop calculation for this neighbor\n"
3940 "Set the next hop to self for reflected routes\n")
3941
3942 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3943 no_neighbor_nexthop_self_all_hidden_cmd,
3944 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self all",
3945 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3946 "Disable the next hop calculation for this neighbor\n"
3947 "Set the next hop to self for reflected routes\n")
3948
3949 /* neighbor as-override */
3950 DEFUN (neighbor_as_override,
3951 neighbor_as_override_cmd,
3952 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3953 NEIGHBOR_STR
3954 NEIGHBOR_ADDR_STR2
3955 "Override ASNs in outbound updates if aspath equals remote-as\n")
3956 {
3957 int idx_peer = 1;
3958 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3959 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3960 }
3961
3962 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3963 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3964 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3965 "Override ASNs in outbound updates if aspath equals remote-as\n")
3966
3967 DEFUN (no_neighbor_as_override,
3968 no_neighbor_as_override_cmd,
3969 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3970 NO_STR
3971 NEIGHBOR_STR
3972 NEIGHBOR_ADDR_STR2
3973 "Override ASNs in outbound updates if aspath equals remote-as\n")
3974 {
3975 int idx_peer = 2;
3976 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3977 bgp_node_afi(vty), bgp_node_safi(vty),
3978 PEER_FLAG_AS_OVERRIDE);
3979 }
3980
3981 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3982 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3983 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3984 "Override ASNs in outbound updates if aspath equals remote-as\n")
3985
3986 /* neighbor remove-private-AS. */
3987 DEFUN (neighbor_remove_private_as,
3988 neighbor_remove_private_as_cmd,
3989 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3990 NEIGHBOR_STR
3991 NEIGHBOR_ADDR_STR2
3992 "Remove private ASNs in outbound updates\n")
3993 {
3994 int idx_peer = 1;
3995 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3996 bgp_node_safi(vty),
3997 PEER_FLAG_REMOVE_PRIVATE_AS);
3998 }
3999
4000 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4001 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4002 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4003 "Remove private ASNs in outbound updates\n")
4004
4005 DEFUN (neighbor_remove_private_as_all,
4006 neighbor_remove_private_as_all_cmd,
4007 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4008 NEIGHBOR_STR
4009 NEIGHBOR_ADDR_STR2
4010 "Remove private ASNs in outbound updates\n"
4011 "Apply to all AS numbers\n")
4012 {
4013 int idx_peer = 1;
4014 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4015 bgp_node_safi(vty),
4016 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4017 }
4018
4019 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4020 neighbor_remove_private_as_all_hidden_cmd,
4021 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4022 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4023 "Remove private ASNs in outbound updates\n"
4024 "Apply to all AS numbers")
4025
4026 DEFUN (neighbor_remove_private_as_replace_as,
4027 neighbor_remove_private_as_replace_as_cmd,
4028 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4029 NEIGHBOR_STR
4030 NEIGHBOR_ADDR_STR2
4031 "Remove private ASNs in outbound updates\n"
4032 "Replace private ASNs with our ASN in outbound updates\n")
4033 {
4034 int idx_peer = 1;
4035 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4036 bgp_node_safi(vty),
4037 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4038 }
4039
4040 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4041 neighbor_remove_private_as_replace_as_hidden_cmd,
4042 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4043 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4044 "Remove private ASNs in outbound updates\n"
4045 "Replace private ASNs with our ASN in outbound updates\n")
4046
4047 DEFUN (neighbor_remove_private_as_all_replace_as,
4048 neighbor_remove_private_as_all_replace_as_cmd,
4049 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4050 NEIGHBOR_STR
4051 NEIGHBOR_ADDR_STR2
4052 "Remove private ASNs in outbound updates\n"
4053 "Apply to all AS numbers\n"
4054 "Replace private ASNs with our ASN in outbound updates\n")
4055 {
4056 int idx_peer = 1;
4057 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4058 bgp_node_safi(vty),
4059 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4060 }
4061
4062 ALIAS_HIDDEN(
4063 neighbor_remove_private_as_all_replace_as,
4064 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4065 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4066 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4067 "Remove private ASNs in outbound updates\n"
4068 "Apply to all AS numbers\n"
4069 "Replace private ASNs with our ASN in outbound updates\n")
4070
4071 DEFUN (no_neighbor_remove_private_as,
4072 no_neighbor_remove_private_as_cmd,
4073 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4074 NO_STR
4075 NEIGHBOR_STR
4076 NEIGHBOR_ADDR_STR2
4077 "Remove private ASNs in outbound updates\n")
4078 {
4079 int idx_peer = 2;
4080 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4081 bgp_node_afi(vty), bgp_node_safi(vty),
4082 PEER_FLAG_REMOVE_PRIVATE_AS);
4083 }
4084
4085 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4086 no_neighbor_remove_private_as_hidden_cmd,
4087 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4088 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4089 "Remove private ASNs in outbound updates\n")
4090
4091 DEFUN (no_neighbor_remove_private_as_all,
4092 no_neighbor_remove_private_as_all_cmd,
4093 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4094 NO_STR
4095 NEIGHBOR_STR
4096 NEIGHBOR_ADDR_STR2
4097 "Remove private ASNs in outbound updates\n"
4098 "Apply to all AS numbers\n")
4099 {
4100 int idx_peer = 2;
4101 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4102 bgp_node_afi(vty), bgp_node_safi(vty),
4103 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4104 }
4105
4106 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4107 no_neighbor_remove_private_as_all_hidden_cmd,
4108 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4109 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4110 "Remove private ASNs in outbound updates\n"
4111 "Apply to all AS numbers\n")
4112
4113 DEFUN (no_neighbor_remove_private_as_replace_as,
4114 no_neighbor_remove_private_as_replace_as_cmd,
4115 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4116 NO_STR
4117 NEIGHBOR_STR
4118 NEIGHBOR_ADDR_STR2
4119 "Remove private ASNs in outbound updates\n"
4120 "Replace private ASNs with our ASN in outbound updates\n")
4121 {
4122 int idx_peer = 2;
4123 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4124 bgp_node_afi(vty), bgp_node_safi(vty),
4125 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4126 }
4127
4128 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4129 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4130 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4131 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4132 "Remove private ASNs in outbound updates\n"
4133 "Replace private ASNs with our ASN in outbound updates\n")
4134
4135 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4136 no_neighbor_remove_private_as_all_replace_as_cmd,
4137 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4138 NO_STR
4139 NEIGHBOR_STR
4140 NEIGHBOR_ADDR_STR2
4141 "Remove private ASNs in outbound updates\n"
4142 "Apply to all AS numbers\n"
4143 "Replace private ASNs with our ASN in outbound updates\n")
4144 {
4145 int idx_peer = 2;
4146 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4147 bgp_node_afi(vty), bgp_node_safi(vty),
4148 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4149 }
4150
4151 ALIAS_HIDDEN(
4152 no_neighbor_remove_private_as_all_replace_as,
4153 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4154 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4155 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4156 "Remove private ASNs in outbound updates\n"
4157 "Apply to all AS numbers\n"
4158 "Replace private ASNs with our ASN in outbound updates\n")
4159
4160
4161 /* neighbor send-community. */
4162 DEFUN (neighbor_send_community,
4163 neighbor_send_community_cmd,
4164 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4165 NEIGHBOR_STR
4166 NEIGHBOR_ADDR_STR2
4167 "Send Community attribute to this neighbor\n")
4168 {
4169 int idx_peer = 1;
4170
4171 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4172 bgp_node_safi(vty),
4173 PEER_FLAG_SEND_COMMUNITY);
4174 }
4175
4176 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4177 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4178 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4179 "Send Community attribute to this neighbor\n")
4180
4181 DEFUN (no_neighbor_send_community,
4182 no_neighbor_send_community_cmd,
4183 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4184 NO_STR
4185 NEIGHBOR_STR
4186 NEIGHBOR_ADDR_STR2
4187 "Send Community attribute to this neighbor\n")
4188 {
4189 int idx_peer = 2;
4190
4191 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4192 bgp_node_afi(vty), bgp_node_safi(vty),
4193 PEER_FLAG_SEND_COMMUNITY);
4194 }
4195
4196 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4197 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4198 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4199 "Send Community attribute to this neighbor\n")
4200
4201 /* neighbor send-community extended. */
4202 DEFUN (neighbor_send_community_type,
4203 neighbor_send_community_type_cmd,
4204 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4205 NEIGHBOR_STR
4206 NEIGHBOR_ADDR_STR2
4207 "Send Community attribute to this neighbor\n"
4208 "Send Standard and Extended Community attributes\n"
4209 "Send Standard, Large and Extended Community attributes\n"
4210 "Send Extended Community attributes\n"
4211 "Send Standard Community attributes\n"
4212 "Send Large Community attributes\n")
4213 {
4214 int idx_peer = 1;
4215 uint32_t flag = 0;
4216 const char *type = argv[argc - 1]->text;
4217
4218 if (strmatch(type, "standard")) {
4219 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4220 } else if (strmatch(type, "extended")) {
4221 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4222 } else if (strmatch(type, "large")) {
4223 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4224 } else if (strmatch(type, "both")) {
4225 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4226 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4227 } else { /* if (strmatch(type, "all")) */
4228 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4229 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4230 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4231 }
4232
4233 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4234 bgp_node_safi(vty), flag);
4235 }
4236
4237 ALIAS_HIDDEN(
4238 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4239 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4240 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4241 "Send Community attribute to this neighbor\n"
4242 "Send Standard and Extended Community attributes\n"
4243 "Send Standard, Large and Extended Community attributes\n"
4244 "Send Extended Community attributes\n"
4245 "Send Standard Community attributes\n"
4246 "Send Large Community attributes\n")
4247
4248 DEFUN (no_neighbor_send_community_type,
4249 no_neighbor_send_community_type_cmd,
4250 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4251 NO_STR
4252 NEIGHBOR_STR
4253 NEIGHBOR_ADDR_STR2
4254 "Send Community attribute to this neighbor\n"
4255 "Send Standard and Extended Community attributes\n"
4256 "Send Standard, Large and Extended Community attributes\n"
4257 "Send Extended Community attributes\n"
4258 "Send Standard Community attributes\n"
4259 "Send Large Community attributes\n")
4260 {
4261 int idx_peer = 2;
4262 uint32_t flag = 0;
4263 const char *type = argv[argc - 1]->text;
4264
4265 if (strmatch(type, "standard")) {
4266 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4267 } else if (strmatch(type, "extended")) {
4268 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4269 } else if (strmatch(type, "large")) {
4270 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4271 } else if (strmatch(type, "both")) {
4272 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4273 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4274 } else { /* if (strmatch(type, "all")) */
4275 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4276 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4277 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4278 }
4279
4280 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4281 bgp_node_afi(vty), bgp_node_safi(vty),
4282 flag);
4283 }
4284
4285 ALIAS_HIDDEN(
4286 no_neighbor_send_community_type,
4287 no_neighbor_send_community_type_hidden_cmd,
4288 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4289 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4290 "Send Community attribute to this neighbor\n"
4291 "Send Standard and Extended Community attributes\n"
4292 "Send Standard, Large and Extended Community attributes\n"
4293 "Send Extended Community attributes\n"
4294 "Send Standard Community attributes\n"
4295 "Send Large Community attributes\n")
4296
4297 /* neighbor soft-reconfig. */
4298 DEFUN (neighbor_soft_reconfiguration,
4299 neighbor_soft_reconfiguration_cmd,
4300 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4301 NEIGHBOR_STR
4302 NEIGHBOR_ADDR_STR2
4303 "Per neighbor soft reconfiguration\n"
4304 "Allow inbound soft reconfiguration for this neighbor\n")
4305 {
4306 int idx_peer = 1;
4307 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4308 bgp_node_safi(vty),
4309 PEER_FLAG_SOFT_RECONFIG);
4310 }
4311
4312 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4313 neighbor_soft_reconfiguration_hidden_cmd,
4314 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4315 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4316 "Per neighbor soft reconfiguration\n"
4317 "Allow inbound soft reconfiguration for this neighbor\n")
4318
4319 DEFUN (no_neighbor_soft_reconfiguration,
4320 no_neighbor_soft_reconfiguration_cmd,
4321 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4322 NO_STR
4323 NEIGHBOR_STR
4324 NEIGHBOR_ADDR_STR2
4325 "Per neighbor soft reconfiguration\n"
4326 "Allow inbound soft reconfiguration for this neighbor\n")
4327 {
4328 int idx_peer = 2;
4329 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4330 bgp_node_afi(vty), bgp_node_safi(vty),
4331 PEER_FLAG_SOFT_RECONFIG);
4332 }
4333
4334 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4335 no_neighbor_soft_reconfiguration_hidden_cmd,
4336 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4337 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4338 "Per neighbor soft reconfiguration\n"
4339 "Allow inbound soft reconfiguration for this neighbor\n")
4340
4341 DEFUN (neighbor_route_reflector_client,
4342 neighbor_route_reflector_client_cmd,
4343 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4344 NEIGHBOR_STR
4345 NEIGHBOR_ADDR_STR2
4346 "Configure a neighbor as Route Reflector client\n")
4347 {
4348 int idx_peer = 1;
4349 struct peer *peer;
4350
4351
4352 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4353 if (!peer)
4354 return CMD_WARNING_CONFIG_FAILED;
4355
4356 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4357 bgp_node_safi(vty),
4358 PEER_FLAG_REFLECTOR_CLIENT);
4359 }
4360
4361 ALIAS_HIDDEN(neighbor_route_reflector_client,
4362 neighbor_route_reflector_client_hidden_cmd,
4363 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4364 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4365 "Configure a neighbor as Route Reflector client\n")
4366
4367 DEFUN (no_neighbor_route_reflector_client,
4368 no_neighbor_route_reflector_client_cmd,
4369 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4370 NO_STR
4371 NEIGHBOR_STR
4372 NEIGHBOR_ADDR_STR2
4373 "Configure a neighbor as Route Reflector client\n")
4374 {
4375 int idx_peer = 2;
4376 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4377 bgp_node_afi(vty), bgp_node_safi(vty),
4378 PEER_FLAG_REFLECTOR_CLIENT);
4379 }
4380
4381 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4382 no_neighbor_route_reflector_client_hidden_cmd,
4383 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4384 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4385 "Configure a neighbor as Route Reflector client\n")
4386
4387 /* neighbor route-server-client. */
4388 DEFUN (neighbor_route_server_client,
4389 neighbor_route_server_client_cmd,
4390 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4391 NEIGHBOR_STR
4392 NEIGHBOR_ADDR_STR2
4393 "Configure a neighbor as Route Server client\n")
4394 {
4395 int idx_peer = 1;
4396 struct peer *peer;
4397
4398 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4399 if (!peer)
4400 return CMD_WARNING_CONFIG_FAILED;
4401 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4402 bgp_node_safi(vty),
4403 PEER_FLAG_RSERVER_CLIENT);
4404 }
4405
4406 ALIAS_HIDDEN(neighbor_route_server_client,
4407 neighbor_route_server_client_hidden_cmd,
4408 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4409 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4410 "Configure a neighbor as Route Server client\n")
4411
4412 DEFUN (no_neighbor_route_server_client,
4413 no_neighbor_route_server_client_cmd,
4414 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4415 NO_STR
4416 NEIGHBOR_STR
4417 NEIGHBOR_ADDR_STR2
4418 "Configure a neighbor as Route Server client\n")
4419 {
4420 int idx_peer = 2;
4421 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4422 bgp_node_afi(vty), bgp_node_safi(vty),
4423 PEER_FLAG_RSERVER_CLIENT);
4424 }
4425
4426 ALIAS_HIDDEN(no_neighbor_route_server_client,
4427 no_neighbor_route_server_client_hidden_cmd,
4428 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4429 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4430 "Configure a neighbor as Route Server client\n")
4431
4432 DEFUN (neighbor_nexthop_local_unchanged,
4433 neighbor_nexthop_local_unchanged_cmd,
4434 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4435 NEIGHBOR_STR
4436 NEIGHBOR_ADDR_STR2
4437 "Configure treatment of outgoing link-local nexthop attribute\n"
4438 "Leave link-local nexthop unchanged for this peer\n")
4439 {
4440 int idx_peer = 1;
4441 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4442 bgp_node_safi(vty),
4443 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4444 }
4445
4446 DEFUN (no_neighbor_nexthop_local_unchanged,
4447 no_neighbor_nexthop_local_unchanged_cmd,
4448 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4449 NO_STR
4450 NEIGHBOR_STR
4451 NEIGHBOR_ADDR_STR2
4452 "Configure treatment of outgoing link-local-nexthop attribute\n"
4453 "Leave link-local nexthop unchanged for this peer\n")
4454 {
4455 int idx_peer = 2;
4456 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4457 bgp_node_afi(vty), bgp_node_safi(vty),
4458 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4459 }
4460
4461 DEFUN (neighbor_attr_unchanged,
4462 neighbor_attr_unchanged_cmd,
4463 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4464 NEIGHBOR_STR
4465 NEIGHBOR_ADDR_STR2
4466 "BGP attribute is propagated unchanged to this neighbor\n"
4467 "As-path attribute\n"
4468 "Nexthop attribute\n"
4469 "Med attribute\n")
4470 {
4471 int idx = 0;
4472 char *peer_str = argv[1]->arg;
4473 struct peer *peer;
4474 uint16_t flags = 0;
4475 afi_t afi = bgp_node_afi(vty);
4476 safi_t safi = bgp_node_safi(vty);
4477
4478 peer = peer_and_group_lookup_vty(vty, peer_str);
4479 if (!peer)
4480 return CMD_WARNING_CONFIG_FAILED;
4481
4482 if (argv_find(argv, argc, "as-path", &idx))
4483 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4484 idx = 0;
4485 if (argv_find(argv, argc, "next-hop", &idx))
4486 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4487 idx = 0;
4488 if (argv_find(argv, argc, "med", &idx))
4489 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4490
4491 /* no flags means all of them! */
4492 if (!flags) {
4493 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4494 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4495 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4496 } else {
4497 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4498 && peer_af_flag_check(peer, afi, safi,
4499 PEER_FLAG_AS_PATH_UNCHANGED)) {
4500 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4501 PEER_FLAG_AS_PATH_UNCHANGED);
4502 }
4503
4504 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4505 && peer_af_flag_check(peer, afi, safi,
4506 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4507 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4508 PEER_FLAG_NEXTHOP_UNCHANGED);
4509 }
4510
4511 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4512 && peer_af_flag_check(peer, afi, safi,
4513 PEER_FLAG_MED_UNCHANGED)) {
4514 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4515 PEER_FLAG_MED_UNCHANGED);
4516 }
4517 }
4518
4519 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4520 }
4521
4522 ALIAS_HIDDEN(
4523 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4524 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4525 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4526 "BGP attribute is propagated unchanged to this neighbor\n"
4527 "As-path attribute\n"
4528 "Nexthop attribute\n"
4529 "Med attribute\n")
4530
4531 DEFUN (no_neighbor_attr_unchanged,
4532 no_neighbor_attr_unchanged_cmd,
4533 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4534 NO_STR
4535 NEIGHBOR_STR
4536 NEIGHBOR_ADDR_STR2
4537 "BGP attribute is propagated unchanged to this neighbor\n"
4538 "As-path attribute\n"
4539 "Nexthop attribute\n"
4540 "Med attribute\n")
4541 {
4542 int idx = 0;
4543 char *peer = argv[2]->arg;
4544 uint16_t flags = 0;
4545
4546 if (argv_find(argv, argc, "as-path", &idx))
4547 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4548 idx = 0;
4549 if (argv_find(argv, argc, "next-hop", &idx))
4550 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4551 idx = 0;
4552 if (argv_find(argv, argc, "med", &idx))
4553 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4554
4555 if (!flags) // no flags means all of them!
4556 {
4557 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4558 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4559 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4560 }
4561
4562 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4563 bgp_node_safi(vty), flags);
4564 }
4565
4566 ALIAS_HIDDEN(
4567 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4568 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4569 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4570 "BGP attribute is propagated unchanged to this neighbor\n"
4571 "As-path attribute\n"
4572 "Nexthop attribute\n"
4573 "Med attribute\n")
4574
4575 /* EBGP multihop configuration. */
4576 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4577 const char *ttl_str)
4578 {
4579 struct peer *peer;
4580 unsigned int ttl;
4581
4582 peer = peer_and_group_lookup_vty(vty, ip_str);
4583 if (!peer)
4584 return CMD_WARNING_CONFIG_FAILED;
4585
4586 if (peer->conf_if)
4587 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4588
4589 if (!ttl_str)
4590 ttl = MAXTTL;
4591 else
4592 ttl = strtoul(ttl_str, NULL, 10);
4593
4594 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4595 }
4596
4597 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4598 {
4599 struct peer *peer;
4600
4601 peer = peer_and_group_lookup_vty(vty, ip_str);
4602 if (!peer)
4603 return CMD_WARNING_CONFIG_FAILED;
4604
4605 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4606 }
4607
4608 /* neighbor ebgp-multihop. */
4609 DEFUN (neighbor_ebgp_multihop,
4610 neighbor_ebgp_multihop_cmd,
4611 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4612 NEIGHBOR_STR
4613 NEIGHBOR_ADDR_STR2
4614 "Allow EBGP neighbors not on directly connected networks\n")
4615 {
4616 int idx_peer = 1;
4617 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4618 }
4619
4620 DEFUN (neighbor_ebgp_multihop_ttl,
4621 neighbor_ebgp_multihop_ttl_cmd,
4622 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4623 NEIGHBOR_STR
4624 NEIGHBOR_ADDR_STR2
4625 "Allow EBGP neighbors not on directly connected networks\n"
4626 "maximum hop count\n")
4627 {
4628 int idx_peer = 1;
4629 int idx_number = 3;
4630 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4631 argv[idx_number]->arg);
4632 }
4633
4634 DEFUN (no_neighbor_ebgp_multihop,
4635 no_neighbor_ebgp_multihop_cmd,
4636 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4637 NO_STR
4638 NEIGHBOR_STR
4639 NEIGHBOR_ADDR_STR2
4640 "Allow EBGP neighbors not on directly connected networks\n"
4641 "maximum hop count\n")
4642 {
4643 int idx_peer = 2;
4644 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4645 }
4646
4647
4648 /* disable-connected-check */
4649 DEFUN (neighbor_disable_connected_check,
4650 neighbor_disable_connected_check_cmd,
4651 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4652 NEIGHBOR_STR
4653 NEIGHBOR_ADDR_STR2
4654 "one-hop away EBGP peer using loopback address\n"
4655 "Enforce EBGP neighbors perform multihop\n")
4656 {
4657 int idx_peer = 1;
4658 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4659 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4660 }
4661
4662 DEFUN (no_neighbor_disable_connected_check,
4663 no_neighbor_disable_connected_check_cmd,
4664 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4665 NO_STR
4666 NEIGHBOR_STR
4667 NEIGHBOR_ADDR_STR2
4668 "one-hop away EBGP peer using loopback address\n"
4669 "Enforce EBGP neighbors perform multihop\n")
4670 {
4671 int idx_peer = 2;
4672 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4673 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4674 }
4675
4676
4677 /* enforce-first-as */
4678 DEFUN (neighbor_enforce_first_as,
4679 neighbor_enforce_first_as_cmd,
4680 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4681 NEIGHBOR_STR
4682 NEIGHBOR_ADDR_STR2
4683 "Enforce the first AS for EBGP routes\n")
4684 {
4685 int idx_peer = 1;
4686
4687 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4688 PEER_FLAG_ENFORCE_FIRST_AS);
4689 }
4690
4691 DEFUN (no_neighbor_enforce_first_as,
4692 no_neighbor_enforce_first_as_cmd,
4693 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4694 NO_STR
4695 NEIGHBOR_STR
4696 NEIGHBOR_ADDR_STR2
4697 "Enforce the first AS for EBGP routes\n")
4698 {
4699 int idx_peer = 2;
4700
4701 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4702 PEER_FLAG_ENFORCE_FIRST_AS);
4703 }
4704
4705
4706 DEFUN (neighbor_description,
4707 neighbor_description_cmd,
4708 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
4711 "Neighbor specific description\n"
4712 "Up to 80 characters describing this neighbor\n")
4713 {
4714 int idx_peer = 1;
4715 int idx_line = 3;
4716 struct peer *peer;
4717 char *str;
4718
4719 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4720 if (!peer)
4721 return CMD_WARNING_CONFIG_FAILED;
4722
4723 str = argv_concat(argv, argc, idx_line);
4724
4725 peer_description_set(peer, str);
4726
4727 XFREE(MTYPE_TMP, str);
4728
4729 return CMD_SUCCESS;
4730 }
4731
4732 DEFUN (no_neighbor_description,
4733 no_neighbor_description_cmd,
4734 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4735 NO_STR
4736 NEIGHBOR_STR
4737 NEIGHBOR_ADDR_STR2
4738 "Neighbor specific description\n")
4739 {
4740 int idx_peer = 2;
4741 struct peer *peer;
4742
4743 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4744 if (!peer)
4745 return CMD_WARNING_CONFIG_FAILED;
4746
4747 peer_description_unset(peer);
4748
4749 return CMD_SUCCESS;
4750 }
4751
4752 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4753 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4754 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4755 "Neighbor specific description\n"
4756 "Up to 80 characters describing this neighbor\n")
4757
4758 /* Neighbor update-source. */
4759 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4760 const char *source_str)
4761 {
4762 struct peer *peer;
4763 struct prefix p;
4764 union sockunion su;
4765
4766 peer = peer_and_group_lookup_vty(vty, peer_str);
4767 if (!peer)
4768 return CMD_WARNING_CONFIG_FAILED;
4769
4770 if (peer->conf_if)
4771 return CMD_WARNING;
4772
4773 if (source_str) {
4774 if (str2sockunion(source_str, &su) == 0)
4775 peer_update_source_addr_set(peer, &su);
4776 else {
4777 if (str2prefix(source_str, &p)) {
4778 vty_out(vty,
4779 "%% Invalid update-source, remove prefix length \n");
4780 return CMD_WARNING_CONFIG_FAILED;
4781 } else
4782 peer_update_source_if_set(peer, source_str);
4783 }
4784 } else
4785 peer_update_source_unset(peer);
4786
4787 return CMD_SUCCESS;
4788 }
4789
4790 #define BGP_UPDATE_SOURCE_HELP_STR \
4791 "IPv4 address\n" \
4792 "IPv6 address\n" \
4793 "Interface name (requires zebra to be running)\n"
4794
4795 DEFUN (neighbor_update_source,
4796 neighbor_update_source_cmd,
4797 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4798 NEIGHBOR_STR
4799 NEIGHBOR_ADDR_STR2
4800 "Source of routing updates\n"
4801 BGP_UPDATE_SOURCE_HELP_STR)
4802 {
4803 int idx_peer = 1;
4804 int idx_peer_2 = 3;
4805 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4806 argv[idx_peer_2]->arg);
4807 }
4808
4809 DEFUN (no_neighbor_update_source,
4810 no_neighbor_update_source_cmd,
4811 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4812 NO_STR
4813 NEIGHBOR_STR
4814 NEIGHBOR_ADDR_STR2
4815 "Source of routing updates\n"
4816 BGP_UPDATE_SOURCE_HELP_STR)
4817 {
4818 int idx_peer = 2;
4819 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4820 }
4821
4822 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4823 afi_t afi, safi_t safi,
4824 const char *rmap, int set)
4825 {
4826 int ret;
4827 struct peer *peer;
4828 struct route_map *route_map;
4829
4830 peer = peer_and_group_lookup_vty(vty, peer_str);
4831 if (!peer)
4832 return CMD_WARNING_CONFIG_FAILED;
4833
4834 if (set) {
4835 route_map = route_map_lookup_warn_noexist(vty, rmap);
4836 ret = peer_default_originate_set(peer, afi, safi,
4837 rmap, route_map);
4838 } else
4839 ret = peer_default_originate_unset(peer, afi, safi);
4840
4841 return bgp_vty_return(vty, ret);
4842 }
4843
4844 /* neighbor default-originate. */
4845 DEFUN (neighbor_default_originate,
4846 neighbor_default_originate_cmd,
4847 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4848 NEIGHBOR_STR
4849 NEIGHBOR_ADDR_STR2
4850 "Originate default route to this neighbor\n")
4851 {
4852 int idx_peer = 1;
4853 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4854 bgp_node_afi(vty),
4855 bgp_node_safi(vty), NULL, 1);
4856 }
4857
4858 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4859 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4860 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4861 "Originate default route to this neighbor\n")
4862
4863 DEFUN (neighbor_default_originate_rmap,
4864 neighbor_default_originate_rmap_cmd,
4865 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4866 NEIGHBOR_STR
4867 NEIGHBOR_ADDR_STR2
4868 "Originate default route to this neighbor\n"
4869 "Route-map to specify criteria to originate default\n"
4870 "route-map name\n")
4871 {
4872 int idx_peer = 1;
4873 int idx_word = 4;
4874 return peer_default_originate_set_vty(
4875 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4876 argv[idx_word]->arg, 1);
4877 }
4878
4879 ALIAS_HIDDEN(
4880 neighbor_default_originate_rmap,
4881 neighbor_default_originate_rmap_hidden_cmd,
4882 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4883 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4884 "Originate default route to this neighbor\n"
4885 "Route-map to specify criteria to originate default\n"
4886 "route-map name\n")
4887
4888 DEFUN (no_neighbor_default_originate,
4889 no_neighbor_default_originate_cmd,
4890 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4891 NO_STR
4892 NEIGHBOR_STR
4893 NEIGHBOR_ADDR_STR2
4894 "Originate default route to this neighbor\n"
4895 "Route-map to specify criteria to originate default\n"
4896 "route-map name\n")
4897 {
4898 int idx_peer = 2;
4899 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4900 bgp_node_afi(vty),
4901 bgp_node_safi(vty), NULL, 0);
4902 }
4903
4904 ALIAS_HIDDEN(
4905 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4906 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4907 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4908 "Originate default route to this neighbor\n"
4909 "Route-map to specify criteria to originate default\n"
4910 "route-map name\n")
4911
4912
4913 /* Set neighbor's BGP port. */
4914 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4915 const char *port_str)
4916 {
4917 struct peer *peer;
4918 uint16_t port;
4919 struct servent *sp;
4920
4921 peer = peer_lookup_vty(vty, ip_str);
4922 if (!peer)
4923 return CMD_WARNING_CONFIG_FAILED;
4924
4925 if (!port_str) {
4926 sp = getservbyname("bgp", "tcp");
4927 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4928 } else {
4929 port = strtoul(port_str, NULL, 10);
4930 }
4931
4932 peer_port_set(peer, port);
4933
4934 return CMD_SUCCESS;
4935 }
4936
4937 /* Set specified peer's BGP port. */
4938 DEFUN (neighbor_port,
4939 neighbor_port_cmd,
4940 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4941 NEIGHBOR_STR
4942 NEIGHBOR_ADDR_STR
4943 "Neighbor's BGP port\n"
4944 "TCP port number\n")
4945 {
4946 int idx_ip = 1;
4947 int idx_number = 3;
4948 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4949 argv[idx_number]->arg);
4950 }
4951
4952 DEFUN (no_neighbor_port,
4953 no_neighbor_port_cmd,
4954 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4955 NO_STR
4956 NEIGHBOR_STR
4957 NEIGHBOR_ADDR_STR
4958 "Neighbor's BGP port\n"
4959 "TCP port number\n")
4960 {
4961 int idx_ip = 2;
4962 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4963 }
4964
4965
4966 /* neighbor weight. */
4967 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4968 safi_t safi, const char *weight_str)
4969 {
4970 int ret;
4971 struct peer *peer;
4972 unsigned long weight;
4973
4974 peer = peer_and_group_lookup_vty(vty, ip_str);
4975 if (!peer)
4976 return CMD_WARNING_CONFIG_FAILED;
4977
4978 weight = strtoul(weight_str, NULL, 10);
4979
4980 ret = peer_weight_set(peer, afi, safi, weight);
4981 return bgp_vty_return(vty, ret);
4982 }
4983
4984 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4985 safi_t safi)
4986 {
4987 int ret;
4988 struct peer *peer;
4989
4990 peer = peer_and_group_lookup_vty(vty, ip_str);
4991 if (!peer)
4992 return CMD_WARNING_CONFIG_FAILED;
4993
4994 ret = peer_weight_unset(peer, afi, safi);
4995 return bgp_vty_return(vty, ret);
4996 }
4997
4998 DEFUN (neighbor_weight,
4999 neighbor_weight_cmd,
5000 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5001 NEIGHBOR_STR
5002 NEIGHBOR_ADDR_STR2
5003 "Set default weight for routes from this neighbor\n"
5004 "default weight\n")
5005 {
5006 int idx_peer = 1;
5007 int idx_number = 3;
5008 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5009 bgp_node_safi(vty), argv[idx_number]->arg);
5010 }
5011
5012 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5013 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5014 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5015 "Set default weight for routes from this neighbor\n"
5016 "default weight\n")
5017
5018 DEFUN (no_neighbor_weight,
5019 no_neighbor_weight_cmd,
5020 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5021 NO_STR
5022 NEIGHBOR_STR
5023 NEIGHBOR_ADDR_STR2
5024 "Set default weight for routes from this neighbor\n"
5025 "default weight\n")
5026 {
5027 int idx_peer = 2;
5028 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5029 bgp_node_afi(vty), bgp_node_safi(vty));
5030 }
5031
5032 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5033 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5034 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5035 "Set default weight for routes from this neighbor\n"
5036 "default weight\n")
5037
5038
5039 /* Override capability negotiation. */
5040 DEFUN (neighbor_override_capability,
5041 neighbor_override_capability_cmd,
5042 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "Override capability negotiation result\n")
5046 {
5047 int idx_peer = 1;
5048 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5049 PEER_FLAG_OVERRIDE_CAPABILITY);
5050 }
5051
5052 DEFUN (no_neighbor_override_capability,
5053 no_neighbor_override_capability_cmd,
5054 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5055 NO_STR
5056 NEIGHBOR_STR
5057 NEIGHBOR_ADDR_STR2
5058 "Override capability negotiation result\n")
5059 {
5060 int idx_peer = 2;
5061 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5062 PEER_FLAG_OVERRIDE_CAPABILITY);
5063 }
5064
5065 DEFUN (neighbor_strict_capability,
5066 neighbor_strict_capability_cmd,
5067 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5068 NEIGHBOR_STR
5069 NEIGHBOR_ADDR_STR2
5070 "Strict capability negotiation match\n")
5071 {
5072 int idx_peer = 1;
5073
5074 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5075 PEER_FLAG_STRICT_CAP_MATCH);
5076 }
5077
5078 DEFUN (no_neighbor_strict_capability,
5079 no_neighbor_strict_capability_cmd,
5080 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5081 NO_STR
5082 NEIGHBOR_STR
5083 NEIGHBOR_ADDR_STR2
5084 "Strict capability negotiation match\n")
5085 {
5086 int idx_peer = 2;
5087
5088 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5089 PEER_FLAG_STRICT_CAP_MATCH);
5090 }
5091
5092 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5093 const char *keep_str, const char *hold_str)
5094 {
5095 int ret;
5096 struct peer *peer;
5097 uint32_t keepalive;
5098 uint32_t holdtime;
5099
5100 peer = peer_and_group_lookup_vty(vty, ip_str);
5101 if (!peer)
5102 return CMD_WARNING_CONFIG_FAILED;
5103
5104 keepalive = strtoul(keep_str, NULL, 10);
5105 holdtime = strtoul(hold_str, NULL, 10);
5106
5107 ret = peer_timers_set(peer, keepalive, holdtime);
5108
5109 return bgp_vty_return(vty, ret);
5110 }
5111
5112 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5113 {
5114 int ret;
5115 struct peer *peer;
5116
5117 peer = peer_and_group_lookup_vty(vty, ip_str);
5118 if (!peer)
5119 return CMD_WARNING_CONFIG_FAILED;
5120
5121 ret = peer_timers_unset(peer);
5122
5123 return bgp_vty_return(vty, ret);
5124 }
5125
5126 DEFUN (neighbor_timers,
5127 neighbor_timers_cmd,
5128 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5129 NEIGHBOR_STR
5130 NEIGHBOR_ADDR_STR2
5131 "BGP per neighbor timers\n"
5132 "Keepalive interval\n"
5133 "Holdtime\n")
5134 {
5135 int idx_peer = 1;
5136 int idx_number = 3;
5137 int idx_number_2 = 4;
5138 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5139 argv[idx_number]->arg,
5140 argv[idx_number_2]->arg);
5141 }
5142
5143 DEFUN (no_neighbor_timers,
5144 no_neighbor_timers_cmd,
5145 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5146 NO_STR
5147 NEIGHBOR_STR
5148 NEIGHBOR_ADDR_STR2
5149 "BGP per neighbor timers\n"
5150 "Keepalive interval\n"
5151 "Holdtime\n")
5152 {
5153 int idx_peer = 2;
5154 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5155 }
5156
5157
5158 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5159 const char *time_str)
5160 {
5161 int ret;
5162 struct peer *peer;
5163 uint32_t connect;
5164
5165 peer = peer_and_group_lookup_vty(vty, ip_str);
5166 if (!peer)
5167 return CMD_WARNING_CONFIG_FAILED;
5168
5169 connect = strtoul(time_str, NULL, 10);
5170
5171 ret = peer_timers_connect_set(peer, connect);
5172
5173 return bgp_vty_return(vty, ret);
5174 }
5175
5176 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5177 {
5178 int ret;
5179 struct peer *peer;
5180
5181 peer = peer_and_group_lookup_vty(vty, ip_str);
5182 if (!peer)
5183 return CMD_WARNING_CONFIG_FAILED;
5184
5185 ret = peer_timers_connect_unset(peer);
5186
5187 return bgp_vty_return(vty, ret);
5188 }
5189
5190 DEFUN (neighbor_timers_connect,
5191 neighbor_timers_connect_cmd,
5192 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5193 NEIGHBOR_STR
5194 NEIGHBOR_ADDR_STR2
5195 "BGP per neighbor timers\n"
5196 "BGP connect timer\n"
5197 "Connect timer\n")
5198 {
5199 int idx_peer = 1;
5200 int idx_number = 4;
5201 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5202 argv[idx_number]->arg);
5203 }
5204
5205 DEFUN (no_neighbor_timers_connect,
5206 no_neighbor_timers_connect_cmd,
5207 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5208 NO_STR
5209 NEIGHBOR_STR
5210 NEIGHBOR_ADDR_STR2
5211 "BGP per neighbor timers\n"
5212 "BGP connect timer\n"
5213 "Connect timer\n")
5214 {
5215 int idx_peer = 2;
5216 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5217 }
5218
5219
5220 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5221 const char *time_str, int set)
5222 {
5223 int ret;
5224 struct peer *peer;
5225 uint32_t routeadv = 0;
5226
5227 peer = peer_and_group_lookup_vty(vty, ip_str);
5228 if (!peer)
5229 return CMD_WARNING_CONFIG_FAILED;
5230
5231 if (time_str)
5232 routeadv = strtoul(time_str, NULL, 10);
5233
5234 if (set)
5235 ret = peer_advertise_interval_set(peer, routeadv);
5236 else
5237 ret = peer_advertise_interval_unset(peer);
5238
5239 return bgp_vty_return(vty, ret);
5240 }
5241
5242 DEFUN (neighbor_advertise_interval,
5243 neighbor_advertise_interval_cmd,
5244 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5245 NEIGHBOR_STR
5246 NEIGHBOR_ADDR_STR2
5247 "Minimum interval between sending BGP routing updates\n"
5248 "time in seconds\n")
5249 {
5250 int idx_peer = 1;
5251 int idx_number = 3;
5252 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5253 argv[idx_number]->arg, 1);
5254 }
5255
5256 DEFUN (no_neighbor_advertise_interval,
5257 no_neighbor_advertise_interval_cmd,
5258 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5259 NO_STR
5260 NEIGHBOR_STR
5261 NEIGHBOR_ADDR_STR2
5262 "Minimum interval between sending BGP routing updates\n"
5263 "time in seconds\n")
5264 {
5265 int idx_peer = 2;
5266 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5267 }
5268
5269
5270 /* Time to wait before processing route-map updates */
5271 DEFUN (bgp_set_route_map_delay_timer,
5272 bgp_set_route_map_delay_timer_cmd,
5273 "bgp route-map delay-timer (0-600)",
5274 SET_STR
5275 "BGP route-map delay timer\n"
5276 "Time in secs to wait before processing route-map changes\n"
5277 "0 disables the timer, no route updates happen when route-maps change\n")
5278 {
5279 int idx_number = 3;
5280 uint32_t rmap_delay_timer;
5281
5282 if (argv[idx_number]->arg) {
5283 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5284 bm->rmap_update_timer = rmap_delay_timer;
5285
5286 /* if the dynamic update handling is being disabled, and a timer
5287 * is
5288 * running, stop the timer and act as if the timer has already
5289 * fired.
5290 */
5291 if (!rmap_delay_timer && bm->t_rmap_update) {
5292 BGP_TIMER_OFF(bm->t_rmap_update);
5293 thread_execute(bm->master, bgp_route_map_update_timer,
5294 NULL, 0);
5295 }
5296 return CMD_SUCCESS;
5297 } else {
5298 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5299 return CMD_WARNING_CONFIG_FAILED;
5300 }
5301 }
5302
5303 DEFUN (no_bgp_set_route_map_delay_timer,
5304 no_bgp_set_route_map_delay_timer_cmd,
5305 "no bgp route-map delay-timer [(0-600)]",
5306 NO_STR
5307 BGP_STR
5308 "Default BGP route-map delay timer\n"
5309 "Reset to default time to wait for processing route-map changes\n"
5310 "0 disables the timer, no route updates happen when route-maps change\n")
5311 {
5312
5313 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5314
5315 return CMD_SUCCESS;
5316 }
5317
5318
5319 /* neighbor interface */
5320 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5321 const char *str)
5322 {
5323 struct peer *peer;
5324
5325 peer = peer_lookup_vty(vty, ip_str);
5326 if (!peer || peer->conf_if) {
5327 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5328 return CMD_WARNING_CONFIG_FAILED;
5329 }
5330
5331 if (str)
5332 peer_interface_set(peer, str);
5333 else
5334 peer_interface_unset(peer);
5335
5336 return CMD_SUCCESS;
5337 }
5338
5339 DEFUN (neighbor_interface,
5340 neighbor_interface_cmd,
5341 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5342 NEIGHBOR_STR
5343 NEIGHBOR_ADDR_STR
5344 "Interface\n"
5345 "Interface name\n")
5346 {
5347 int idx_ip = 1;
5348 int idx_word = 3;
5349 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5350 }
5351
5352 DEFUN (no_neighbor_interface,
5353 no_neighbor_interface_cmd,
5354 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5355 NO_STR
5356 NEIGHBOR_STR
5357 NEIGHBOR_ADDR_STR2
5358 "Interface\n"
5359 "Interface name\n")
5360 {
5361 int idx_peer = 2;
5362 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5363 }
5364
5365 DEFUN (neighbor_distribute_list,
5366 neighbor_distribute_list_cmd,
5367 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5368 NEIGHBOR_STR
5369 NEIGHBOR_ADDR_STR2
5370 "Filter updates to/from this neighbor\n"
5371 "IP access-list number\n"
5372 "IP access-list number (expanded range)\n"
5373 "IP Access-list name\n"
5374 "Filter incoming updates\n"
5375 "Filter outgoing updates\n")
5376 {
5377 int idx_peer = 1;
5378 int idx_acl = 3;
5379 int direct, ret;
5380 struct peer *peer;
5381
5382 const char *pstr = argv[idx_peer]->arg;
5383 const char *acl = argv[idx_acl]->arg;
5384 const char *inout = argv[argc - 1]->text;
5385
5386 peer = peer_and_group_lookup_vty(vty, pstr);
5387 if (!peer)
5388 return CMD_WARNING_CONFIG_FAILED;
5389
5390 /* Check filter direction. */
5391 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5392 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5393 direct, acl);
5394
5395 return bgp_vty_return(vty, ret);
5396 }
5397
5398 ALIAS_HIDDEN(
5399 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5400 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5401 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5402 "Filter updates to/from this neighbor\n"
5403 "IP access-list number\n"
5404 "IP access-list number (expanded range)\n"
5405 "IP Access-list name\n"
5406 "Filter incoming updates\n"
5407 "Filter outgoing updates\n")
5408
5409 DEFUN (no_neighbor_distribute_list,
5410 no_neighbor_distribute_list_cmd,
5411 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5412 NO_STR
5413 NEIGHBOR_STR
5414 NEIGHBOR_ADDR_STR2
5415 "Filter updates to/from this neighbor\n"
5416 "IP access-list number\n"
5417 "IP access-list number (expanded range)\n"
5418 "IP Access-list name\n"
5419 "Filter incoming updates\n"
5420 "Filter outgoing updates\n")
5421 {
5422 int idx_peer = 2;
5423 int direct, ret;
5424 struct peer *peer;
5425
5426 const char *pstr = argv[idx_peer]->arg;
5427 const char *inout = argv[argc - 1]->text;
5428
5429 peer = peer_and_group_lookup_vty(vty, pstr);
5430 if (!peer)
5431 return CMD_WARNING_CONFIG_FAILED;
5432
5433 /* Check filter direction. */
5434 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5435 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5436 direct);
5437
5438 return bgp_vty_return(vty, ret);
5439 }
5440
5441 ALIAS_HIDDEN(
5442 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5443 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5444 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5445 "Filter updates to/from this neighbor\n"
5446 "IP access-list number\n"
5447 "IP access-list number (expanded range)\n"
5448 "IP Access-list name\n"
5449 "Filter incoming updates\n"
5450 "Filter outgoing updates\n")
5451
5452 /* Set prefix list to the peer. */
5453 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5454 afi_t afi, safi_t safi,
5455 const char *name_str,
5456 const char *direct_str)
5457 {
5458 int ret;
5459 int direct = FILTER_IN;
5460 struct peer *peer;
5461
5462 peer = peer_and_group_lookup_vty(vty, ip_str);
5463 if (!peer)
5464 return CMD_WARNING_CONFIG_FAILED;
5465
5466 /* Check filter direction. */
5467 if (strncmp(direct_str, "i", 1) == 0)
5468 direct = FILTER_IN;
5469 else if (strncmp(direct_str, "o", 1) == 0)
5470 direct = FILTER_OUT;
5471
5472 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5473
5474 return bgp_vty_return(vty, ret);
5475 }
5476
5477 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5478 afi_t afi, safi_t safi,
5479 const char *direct_str)
5480 {
5481 int ret;
5482 struct peer *peer;
5483 int direct = FILTER_IN;
5484
5485 peer = peer_and_group_lookup_vty(vty, ip_str);
5486 if (!peer)
5487 return CMD_WARNING_CONFIG_FAILED;
5488
5489 /* Check filter direction. */
5490 if (strncmp(direct_str, "i", 1) == 0)
5491 direct = FILTER_IN;
5492 else if (strncmp(direct_str, "o", 1) == 0)
5493 direct = FILTER_OUT;
5494
5495 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5496
5497 return bgp_vty_return(vty, ret);
5498 }
5499
5500 DEFUN (neighbor_prefix_list,
5501 neighbor_prefix_list_cmd,
5502 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5503 NEIGHBOR_STR
5504 NEIGHBOR_ADDR_STR2
5505 "Filter updates to/from this neighbor\n"
5506 "Name of a prefix list\n"
5507 "Filter incoming updates\n"
5508 "Filter outgoing updates\n")
5509 {
5510 int idx_peer = 1;
5511 int idx_word = 3;
5512 int idx_in_out = 4;
5513 return peer_prefix_list_set_vty(
5514 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5515 argv[idx_word]->arg, argv[idx_in_out]->arg);
5516 }
5517
5518 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5519 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5520 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5521 "Filter updates to/from this neighbor\n"
5522 "Name of a prefix list\n"
5523 "Filter incoming updates\n"
5524 "Filter outgoing updates\n")
5525
5526 DEFUN (no_neighbor_prefix_list,
5527 no_neighbor_prefix_list_cmd,
5528 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5529 NO_STR
5530 NEIGHBOR_STR
5531 NEIGHBOR_ADDR_STR2
5532 "Filter updates to/from this neighbor\n"
5533 "Name of a prefix list\n"
5534 "Filter incoming updates\n"
5535 "Filter outgoing updates\n")
5536 {
5537 int idx_peer = 2;
5538 int idx_in_out = 5;
5539 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5540 bgp_node_afi(vty), bgp_node_safi(vty),
5541 argv[idx_in_out]->arg);
5542 }
5543
5544 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5545 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5546 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5547 "Filter updates to/from this neighbor\n"
5548 "Name of a prefix list\n"
5549 "Filter incoming updates\n"
5550 "Filter outgoing updates\n")
5551
5552 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5553 safi_t safi, const char *name_str,
5554 const char *direct_str)
5555 {
5556 int ret;
5557 struct peer *peer;
5558 int direct = FILTER_IN;
5559
5560 peer = peer_and_group_lookup_vty(vty, ip_str);
5561 if (!peer)
5562 return CMD_WARNING_CONFIG_FAILED;
5563
5564 /* Check filter direction. */
5565 if (strncmp(direct_str, "i", 1) == 0)
5566 direct = FILTER_IN;
5567 else if (strncmp(direct_str, "o", 1) == 0)
5568 direct = FILTER_OUT;
5569
5570 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5571
5572 return bgp_vty_return(vty, ret);
5573 }
5574
5575 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5576 safi_t safi, const char *direct_str)
5577 {
5578 int ret;
5579 struct peer *peer;
5580 int direct = FILTER_IN;
5581
5582 peer = peer_and_group_lookup_vty(vty, ip_str);
5583 if (!peer)
5584 return CMD_WARNING_CONFIG_FAILED;
5585
5586 /* Check filter direction. */
5587 if (strncmp(direct_str, "i", 1) == 0)
5588 direct = FILTER_IN;
5589 else if (strncmp(direct_str, "o", 1) == 0)
5590 direct = FILTER_OUT;
5591
5592 ret = peer_aslist_unset(peer, afi, safi, direct);
5593
5594 return bgp_vty_return(vty, ret);
5595 }
5596
5597 DEFUN (neighbor_filter_list,
5598 neighbor_filter_list_cmd,
5599 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5600 NEIGHBOR_STR
5601 NEIGHBOR_ADDR_STR2
5602 "Establish BGP filters\n"
5603 "AS path access-list name\n"
5604 "Filter incoming routes\n"
5605 "Filter outgoing routes\n")
5606 {
5607 int idx_peer = 1;
5608 int idx_word = 3;
5609 int idx_in_out = 4;
5610 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5611 bgp_node_safi(vty), argv[idx_word]->arg,
5612 argv[idx_in_out]->arg);
5613 }
5614
5615 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5616 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5617 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5618 "Establish BGP filters\n"
5619 "AS path access-list name\n"
5620 "Filter incoming routes\n"
5621 "Filter outgoing routes\n")
5622
5623 DEFUN (no_neighbor_filter_list,
5624 no_neighbor_filter_list_cmd,
5625 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5626 NO_STR
5627 NEIGHBOR_STR
5628 NEIGHBOR_ADDR_STR2
5629 "Establish BGP filters\n"
5630 "AS path access-list name\n"
5631 "Filter incoming routes\n"
5632 "Filter outgoing routes\n")
5633 {
5634 int idx_peer = 2;
5635 int idx_in_out = 5;
5636 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5637 bgp_node_afi(vty), bgp_node_safi(vty),
5638 argv[idx_in_out]->arg);
5639 }
5640
5641 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5642 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5643 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5644 "Establish BGP filters\n"
5645 "AS path access-list name\n"
5646 "Filter incoming routes\n"
5647 "Filter outgoing routes\n")
5648
5649 /* Set route-map to the peer. */
5650 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5651 afi_t afi, safi_t safi, const char *name_str,
5652 const char *direct_str)
5653 {
5654 int ret;
5655 struct peer *peer;
5656 int direct = RMAP_IN;
5657 struct route_map *route_map;
5658
5659 peer = peer_and_group_lookup_vty(vty, ip_str);
5660 if (!peer)
5661 return CMD_WARNING_CONFIG_FAILED;
5662
5663 /* Check filter direction. */
5664 if (strncmp(direct_str, "in", 2) == 0)
5665 direct = RMAP_IN;
5666 else if (strncmp(direct_str, "o", 1) == 0)
5667 direct = RMAP_OUT;
5668
5669 route_map = route_map_lookup_warn_noexist(vty, name_str);
5670 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5671
5672 return bgp_vty_return(vty, ret);
5673 }
5674
5675 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5676 afi_t afi, safi_t safi,
5677 const char *direct_str)
5678 {
5679 int ret;
5680 struct peer *peer;
5681 int direct = RMAP_IN;
5682
5683 peer = peer_and_group_lookup_vty(vty, ip_str);
5684 if (!peer)
5685 return CMD_WARNING_CONFIG_FAILED;
5686
5687 /* Check filter direction. */
5688 if (strncmp(direct_str, "in", 2) == 0)
5689 direct = RMAP_IN;
5690 else if (strncmp(direct_str, "o", 1) == 0)
5691 direct = RMAP_OUT;
5692
5693 ret = peer_route_map_unset(peer, afi, safi, direct);
5694
5695 return bgp_vty_return(vty, ret);
5696 }
5697
5698 DEFUN (neighbor_route_map,
5699 neighbor_route_map_cmd,
5700 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5701 NEIGHBOR_STR
5702 NEIGHBOR_ADDR_STR2
5703 "Apply route map to neighbor\n"
5704 "Name of route map\n"
5705 "Apply map to incoming routes\n"
5706 "Apply map to outbound routes\n")
5707 {
5708 int idx_peer = 1;
5709 int idx_word = 3;
5710 int idx_in_out = 4;
5711 return peer_route_map_set_vty(
5712 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5713 argv[idx_word]->arg, argv[idx_in_out]->arg);
5714 }
5715
5716 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5717 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5718 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5719 "Apply route map to neighbor\n"
5720 "Name of route map\n"
5721 "Apply map to incoming routes\n"
5722 "Apply map to outbound routes\n")
5723
5724 DEFUN (no_neighbor_route_map,
5725 no_neighbor_route_map_cmd,
5726 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5727 NO_STR
5728 NEIGHBOR_STR
5729 NEIGHBOR_ADDR_STR2
5730 "Apply route map to neighbor\n"
5731 "Name of route map\n"
5732 "Apply map to incoming routes\n"
5733 "Apply map to outbound routes\n")
5734 {
5735 int idx_peer = 2;
5736 int idx_in_out = 5;
5737 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5738 bgp_node_afi(vty), bgp_node_safi(vty),
5739 argv[idx_in_out]->arg);
5740 }
5741
5742 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5743 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5744 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5745 "Apply route map to neighbor\n"
5746 "Name of route map\n"
5747 "Apply map to incoming routes\n"
5748 "Apply map to outbound routes\n")
5749
5750 /* Set unsuppress-map to the peer. */
5751 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5752 afi_t afi, safi_t safi,
5753 const char *name_str)
5754 {
5755 int ret;
5756 struct peer *peer;
5757 struct route_map *route_map;
5758
5759 peer = peer_and_group_lookup_vty(vty, ip_str);
5760 if (!peer)
5761 return CMD_WARNING_CONFIG_FAILED;
5762
5763 route_map = route_map_lookup_warn_noexist(vty, name_str);
5764 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5765
5766 return bgp_vty_return(vty, ret);
5767 }
5768
5769 /* Unset route-map from the peer. */
5770 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5771 afi_t afi, safi_t safi)
5772 {
5773 int ret;
5774 struct peer *peer;
5775
5776 peer = peer_and_group_lookup_vty(vty, ip_str);
5777 if (!peer)
5778 return CMD_WARNING_CONFIG_FAILED;
5779
5780 ret = peer_unsuppress_map_unset(peer, afi, safi);
5781
5782 return bgp_vty_return(vty, ret);
5783 }
5784
5785 DEFUN (neighbor_unsuppress_map,
5786 neighbor_unsuppress_map_cmd,
5787 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5788 NEIGHBOR_STR
5789 NEIGHBOR_ADDR_STR2
5790 "Route-map to selectively unsuppress suppressed routes\n"
5791 "Name of route map\n")
5792 {
5793 int idx_peer = 1;
5794 int idx_word = 3;
5795 return peer_unsuppress_map_set_vty(
5796 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5797 argv[idx_word]->arg);
5798 }
5799
5800 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5801 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5802 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5803 "Route-map to selectively unsuppress suppressed routes\n"
5804 "Name of route map\n")
5805
5806 DEFUN (no_neighbor_unsuppress_map,
5807 no_neighbor_unsuppress_map_cmd,
5808 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5809 NO_STR
5810 NEIGHBOR_STR
5811 NEIGHBOR_ADDR_STR2
5812 "Route-map to selectively unsuppress suppressed routes\n"
5813 "Name of route map\n")
5814 {
5815 int idx_peer = 2;
5816 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5817 bgp_node_afi(vty),
5818 bgp_node_safi(vty));
5819 }
5820
5821 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5822 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5823 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5824 "Route-map to selectively unsuppress suppressed routes\n"
5825 "Name of route map\n")
5826
5827 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5828 afi_t afi, safi_t safi,
5829 const char *num_str,
5830 const char *threshold_str, int warning,
5831 const char *restart_str)
5832 {
5833 int ret;
5834 struct peer *peer;
5835 uint32_t max;
5836 uint8_t threshold;
5837 uint16_t restart;
5838
5839 peer = peer_and_group_lookup_vty(vty, ip_str);
5840 if (!peer)
5841 return CMD_WARNING_CONFIG_FAILED;
5842
5843 max = strtoul(num_str, NULL, 10);
5844 if (threshold_str)
5845 threshold = atoi(threshold_str);
5846 else
5847 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5848
5849 if (restart_str)
5850 restart = atoi(restart_str);
5851 else
5852 restart = 0;
5853
5854 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5855 restart);
5856
5857 return bgp_vty_return(vty, ret);
5858 }
5859
5860 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5861 afi_t afi, safi_t safi)
5862 {
5863 int ret;
5864 struct peer *peer;
5865
5866 peer = peer_and_group_lookup_vty(vty, ip_str);
5867 if (!peer)
5868 return CMD_WARNING_CONFIG_FAILED;
5869
5870 ret = peer_maximum_prefix_unset(peer, afi, safi);
5871
5872 return bgp_vty_return(vty, ret);
5873 }
5874
5875 /* Maximum number of prefix configuration. prefix count is different
5876 for each peer configuration. So this configuration can be set for
5877 each peer configuration. */
5878 DEFUN (neighbor_maximum_prefix,
5879 neighbor_maximum_prefix_cmd,
5880 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5881 NEIGHBOR_STR
5882 NEIGHBOR_ADDR_STR2
5883 "Maximum number of prefix accept from this peer\n"
5884 "maximum no. of prefix limit\n")
5885 {
5886 int idx_peer = 1;
5887 int idx_number = 3;
5888 return peer_maximum_prefix_set_vty(
5889 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5890 argv[idx_number]->arg, NULL, 0, NULL);
5891 }
5892
5893 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5894 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5895 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5896 "Maximum number of prefix accept from this peer\n"
5897 "maximum no. of prefix limit\n")
5898
5899 DEFUN (neighbor_maximum_prefix_threshold,
5900 neighbor_maximum_prefix_threshold_cmd,
5901 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5902 NEIGHBOR_STR
5903 NEIGHBOR_ADDR_STR2
5904 "Maximum number of prefix accept from this peer\n"
5905 "maximum no. of prefix limit\n"
5906 "Threshold value (%) at which to generate a warning msg\n")
5907 {
5908 int idx_peer = 1;
5909 int idx_number = 3;
5910 int idx_number_2 = 4;
5911 return peer_maximum_prefix_set_vty(
5912 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5913 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5914 }
5915
5916 ALIAS_HIDDEN(
5917 neighbor_maximum_prefix_threshold,
5918 neighbor_maximum_prefix_threshold_hidden_cmd,
5919 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5920 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5921 "Maximum number of prefix accept from this peer\n"
5922 "maximum no. of prefix limit\n"
5923 "Threshold value (%) at which to generate a warning msg\n")
5924
5925 DEFUN (neighbor_maximum_prefix_warning,
5926 neighbor_maximum_prefix_warning_cmd,
5927 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5928 NEIGHBOR_STR
5929 NEIGHBOR_ADDR_STR2
5930 "Maximum number of prefix accept from this peer\n"
5931 "maximum no. of prefix limit\n"
5932 "Only give warning message when limit is exceeded\n")
5933 {
5934 int idx_peer = 1;
5935 int idx_number = 3;
5936 return peer_maximum_prefix_set_vty(
5937 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5938 argv[idx_number]->arg, NULL, 1, NULL);
5939 }
5940
5941 ALIAS_HIDDEN(
5942 neighbor_maximum_prefix_warning,
5943 neighbor_maximum_prefix_warning_hidden_cmd,
5944 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5945 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5946 "Maximum number of prefix accept from this peer\n"
5947 "maximum no. of prefix limit\n"
5948 "Only give warning message when limit is exceeded\n")
5949
5950 DEFUN (neighbor_maximum_prefix_threshold_warning,
5951 neighbor_maximum_prefix_threshold_warning_cmd,
5952 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5953 NEIGHBOR_STR
5954 NEIGHBOR_ADDR_STR2
5955 "Maximum number of prefix accept from this peer\n"
5956 "maximum no. of prefix limit\n"
5957 "Threshold value (%) at which to generate a warning msg\n"
5958 "Only give warning message when limit is exceeded\n")
5959 {
5960 int idx_peer = 1;
5961 int idx_number = 3;
5962 int idx_number_2 = 4;
5963 return peer_maximum_prefix_set_vty(
5964 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5965 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5966 }
5967
5968 ALIAS_HIDDEN(
5969 neighbor_maximum_prefix_threshold_warning,
5970 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5971 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5972 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5973 "Maximum number of prefix accept from this peer\n"
5974 "maximum no. of prefix limit\n"
5975 "Threshold value (%) at which to generate a warning msg\n"
5976 "Only give warning message when limit is exceeded\n")
5977
5978 DEFUN (neighbor_maximum_prefix_restart,
5979 neighbor_maximum_prefix_restart_cmd,
5980 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5981 NEIGHBOR_STR
5982 NEIGHBOR_ADDR_STR2
5983 "Maximum number of prefix accept from this peer\n"
5984 "maximum no. of prefix limit\n"
5985 "Restart bgp connection after limit is exceeded\n"
5986 "Restart interval in minutes\n")
5987 {
5988 int idx_peer = 1;
5989 int idx_number = 3;
5990 int idx_number_2 = 5;
5991 return peer_maximum_prefix_set_vty(
5992 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5993 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5994 }
5995
5996 ALIAS_HIDDEN(
5997 neighbor_maximum_prefix_restart,
5998 neighbor_maximum_prefix_restart_hidden_cmd,
5999 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6000 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6001 "Maximum number of prefix accept from this peer\n"
6002 "maximum no. of prefix limit\n"
6003 "Restart bgp connection after limit is exceeded\n"
6004 "Restart interval in minutes\n")
6005
6006 DEFUN (neighbor_maximum_prefix_threshold_restart,
6007 neighbor_maximum_prefix_threshold_restart_cmd,
6008 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6009 NEIGHBOR_STR
6010 NEIGHBOR_ADDR_STR2
6011 "Maximum number of prefixes to accept from this peer\n"
6012 "maximum no. of prefix limit\n"
6013 "Threshold value (%) at which to generate a warning msg\n"
6014 "Restart bgp connection after limit is exceeded\n"
6015 "Restart interval in minutes\n")
6016 {
6017 int idx_peer = 1;
6018 int idx_number = 3;
6019 int idx_number_2 = 4;
6020 int idx_number_3 = 6;
6021 return peer_maximum_prefix_set_vty(
6022 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6023 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6024 argv[idx_number_3]->arg);
6025 }
6026
6027 ALIAS_HIDDEN(
6028 neighbor_maximum_prefix_threshold_restart,
6029 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6030 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6031 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6032 "Maximum number of prefixes to accept from this peer\n"
6033 "maximum no. of prefix limit\n"
6034 "Threshold value (%) at which to generate a warning msg\n"
6035 "Restart bgp connection after limit is exceeded\n"
6036 "Restart interval in minutes\n")
6037
6038 DEFUN (no_neighbor_maximum_prefix,
6039 no_neighbor_maximum_prefix_cmd,
6040 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6041 NO_STR
6042 NEIGHBOR_STR
6043 NEIGHBOR_ADDR_STR2
6044 "Maximum number of prefixes to accept from this peer\n"
6045 "maximum no. of prefix limit\n"
6046 "Threshold value (%) at which to generate a warning msg\n"
6047 "Restart bgp connection after limit is exceeded\n"
6048 "Restart interval in minutes\n"
6049 "Only give warning message when limit is exceeded\n")
6050 {
6051 int idx_peer = 2;
6052 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6053 bgp_node_afi(vty),
6054 bgp_node_safi(vty));
6055 }
6056
6057 ALIAS_HIDDEN(
6058 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6059 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6060 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6061 "Maximum number of prefixes to accept from this peer\n"
6062 "maximum no. of prefix limit\n"
6063 "Threshold value (%) at which to generate a warning msg\n"
6064 "Restart bgp connection after limit is exceeded\n"
6065 "Restart interval in minutes\n"
6066 "Only give warning message when limit is exceeded\n")
6067
6068
6069 /* "neighbor allowas-in" */
6070 DEFUN (neighbor_allowas_in,
6071 neighbor_allowas_in_cmd,
6072 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6073 NEIGHBOR_STR
6074 NEIGHBOR_ADDR_STR2
6075 "Accept as-path with my AS present in it\n"
6076 "Number of occurences of AS number\n"
6077 "Only accept my AS in the as-path if the route was originated in my AS\n")
6078 {
6079 int idx_peer = 1;
6080 int idx_number_origin = 3;
6081 int ret;
6082 int origin = 0;
6083 struct peer *peer;
6084 int allow_num = 0;
6085
6086 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6087 if (!peer)
6088 return CMD_WARNING_CONFIG_FAILED;
6089
6090 if (argc <= idx_number_origin)
6091 allow_num = 3;
6092 else {
6093 if (argv[idx_number_origin]->type == WORD_TKN)
6094 origin = 1;
6095 else
6096 allow_num = atoi(argv[idx_number_origin]->arg);
6097 }
6098
6099 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6100 allow_num, origin);
6101
6102 return bgp_vty_return(vty, ret);
6103 }
6104
6105 ALIAS_HIDDEN(
6106 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6107 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6108 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6109 "Accept as-path with my AS present in it\n"
6110 "Number of occurences of AS number\n"
6111 "Only accept my AS in the as-path if the route was originated in my AS\n")
6112
6113 DEFUN (no_neighbor_allowas_in,
6114 no_neighbor_allowas_in_cmd,
6115 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6116 NO_STR
6117 NEIGHBOR_STR
6118 NEIGHBOR_ADDR_STR2
6119 "allow local ASN appears in aspath attribute\n"
6120 "Number of occurences of AS number\n"
6121 "Only accept my AS in the as-path if the route was originated in my AS\n")
6122 {
6123 int idx_peer = 2;
6124 int ret;
6125 struct peer *peer;
6126
6127 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6128 if (!peer)
6129 return CMD_WARNING_CONFIG_FAILED;
6130
6131 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6132 bgp_node_safi(vty));
6133
6134 return bgp_vty_return(vty, ret);
6135 }
6136
6137 ALIAS_HIDDEN(
6138 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6139 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6140 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6141 "allow local ASN appears in aspath attribute\n"
6142 "Number of occurences of AS number\n"
6143 "Only accept my AS in the as-path if the route was originated in my AS\n")
6144
6145 DEFUN (neighbor_ttl_security,
6146 neighbor_ttl_security_cmd,
6147 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6148 NEIGHBOR_STR
6149 NEIGHBOR_ADDR_STR2
6150 "BGP ttl-security parameters\n"
6151 "Specify the maximum number of hops to the BGP peer\n"
6152 "Number of hops to BGP peer\n")
6153 {
6154 int idx_peer = 1;
6155 int idx_number = 4;
6156 struct peer *peer;
6157 int gtsm_hops;
6158
6159 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6160 if (!peer)
6161 return CMD_WARNING_CONFIG_FAILED;
6162
6163 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6164
6165 /*
6166 * If 'neighbor swpX', then this is for directly connected peers,
6167 * we should not accept a ttl-security hops value greater than 1.
6168 */
6169 if (peer->conf_if && (gtsm_hops > 1)) {
6170 vty_out(vty,
6171 "%s is directly connected peer, hops cannot exceed 1\n",
6172 argv[idx_peer]->arg);
6173 return CMD_WARNING_CONFIG_FAILED;
6174 }
6175
6176 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6177 }
6178
6179 DEFUN (no_neighbor_ttl_security,
6180 no_neighbor_ttl_security_cmd,
6181 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6182 NO_STR
6183 NEIGHBOR_STR
6184 NEIGHBOR_ADDR_STR2
6185 "BGP ttl-security parameters\n"
6186 "Specify the maximum number of hops to the BGP peer\n"
6187 "Number of hops to BGP peer\n")
6188 {
6189 int idx_peer = 2;
6190 struct peer *peer;
6191
6192 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6193 if (!peer)
6194 return CMD_WARNING_CONFIG_FAILED;
6195
6196 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6197 }
6198
6199 DEFUN (neighbor_addpath_tx_all_paths,
6200 neighbor_addpath_tx_all_paths_cmd,
6201 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6202 NEIGHBOR_STR
6203 NEIGHBOR_ADDR_STR2
6204 "Use addpath to advertise all paths to a neighbor\n")
6205 {
6206 int idx_peer = 1;
6207 struct peer *peer;
6208
6209 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6210 if (!peer)
6211 return CMD_WARNING_CONFIG_FAILED;
6212
6213 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6214 BGP_ADDPATH_ALL);
6215 return CMD_SUCCESS;
6216 }
6217
6218 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6219 neighbor_addpath_tx_all_paths_hidden_cmd,
6220 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6221 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6222 "Use addpath to advertise all paths to a neighbor\n")
6223
6224 DEFUN (no_neighbor_addpath_tx_all_paths,
6225 no_neighbor_addpath_tx_all_paths_cmd,
6226 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6227 NO_STR
6228 NEIGHBOR_STR
6229 NEIGHBOR_ADDR_STR2
6230 "Use addpath to advertise all paths to a neighbor\n")
6231 {
6232 int idx_peer = 2;
6233 struct peer *peer;
6234
6235 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6236 if (!peer)
6237 return CMD_WARNING_CONFIG_FAILED;
6238
6239 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6240 != BGP_ADDPATH_ALL) {
6241 vty_out(vty,
6242 "%% Peer not currently configured to transmit all paths.");
6243 return CMD_WARNING_CONFIG_FAILED;
6244 }
6245
6246 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6247 BGP_ADDPATH_NONE);
6248
6249 return CMD_SUCCESS;
6250 }
6251
6252 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6253 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6254 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6255 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6256 "Use addpath to advertise all paths to a neighbor\n")
6257
6258 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6259 neighbor_addpath_tx_bestpath_per_as_cmd,
6260 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6261 NEIGHBOR_STR
6262 NEIGHBOR_ADDR_STR2
6263 "Use addpath to advertise the bestpath per each neighboring AS\n")
6264 {
6265 int idx_peer = 1;
6266 struct peer *peer;
6267
6268 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6269 if (!peer)
6270 return CMD_WARNING_CONFIG_FAILED;
6271
6272 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6273 BGP_ADDPATH_BEST_PER_AS);
6274
6275 return CMD_SUCCESS;
6276 }
6277
6278 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6279 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6280 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6281 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6282 "Use addpath to advertise the bestpath per each neighboring AS\n")
6283
6284 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6285 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6286 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6287 NO_STR
6288 NEIGHBOR_STR
6289 NEIGHBOR_ADDR_STR2
6290 "Use addpath to advertise the bestpath per each neighboring AS\n")
6291 {
6292 int idx_peer = 2;
6293 struct peer *peer;
6294
6295 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6296 if (!peer)
6297 return CMD_WARNING_CONFIG_FAILED;
6298
6299 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6300 != BGP_ADDPATH_BEST_PER_AS) {
6301 vty_out(vty,
6302 "%% Peer not currently configured to transmit all best path per as.");
6303 return CMD_WARNING_CONFIG_FAILED;
6304 }
6305
6306 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6307 BGP_ADDPATH_NONE);
6308
6309 return CMD_SUCCESS;
6310 }
6311
6312 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6313 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6314 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6315 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6316 "Use addpath to advertise the bestpath per each neighboring AS\n")
6317
6318 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6319 struct ecommunity **list)
6320 {
6321 struct ecommunity *ecom = NULL;
6322 struct ecommunity *ecomadd;
6323
6324 for (; argc; --argc, ++argv) {
6325
6326 ecomadd = ecommunity_str2com(argv[0]->arg,
6327 ECOMMUNITY_ROUTE_TARGET, 0);
6328 if (!ecomadd) {
6329 vty_out(vty, "Malformed community-list value\n");
6330 if (ecom)
6331 ecommunity_free(&ecom);
6332 return CMD_WARNING_CONFIG_FAILED;
6333 }
6334
6335 if (ecom) {
6336 ecommunity_merge(ecom, ecomadd);
6337 ecommunity_free(&ecomadd);
6338 } else {
6339 ecom = ecomadd;
6340 }
6341 }
6342
6343 if (*list) {
6344 ecommunity_free(&*list);
6345 }
6346 *list = ecom;
6347
6348 return CMD_SUCCESS;
6349 }
6350
6351 /*
6352 * v2vimport is true if we are handling a `import vrf ...` command
6353 */
6354 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6355 {
6356 afi_t afi;
6357
6358 switch (vty->node) {
6359 case BGP_IPV4_NODE:
6360 afi = AFI_IP;
6361 break;
6362 case BGP_IPV6_NODE:
6363 afi = AFI_IP6;
6364 break;
6365 default:
6366 vty_out(vty,
6367 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6368 return AFI_MAX;
6369 }
6370
6371 if (!v2vimport) {
6372 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6373 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6374 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6375 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6376 vty_out(vty,
6377 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6378 return AFI_MAX;
6379 }
6380 } else {
6381 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6382 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6383 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6384 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6385 vty_out(vty,
6386 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6387 return AFI_MAX;
6388 }
6389 }
6390 return afi;
6391 }
6392
6393 DEFPY (af_rd_vpn_export,
6394 af_rd_vpn_export_cmd,
6395 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6396 NO_STR
6397 "Specify route distinguisher\n"
6398 "Between current address-family and vpn\n"
6399 "For routes leaked from current address-family to vpn\n"
6400 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6401 {
6402 VTY_DECLVAR_CONTEXT(bgp, bgp);
6403 struct prefix_rd prd;
6404 int ret;
6405 afi_t afi;
6406 int idx = 0;
6407 int yes = 1;
6408
6409 if (argv_find(argv, argc, "no", &idx))
6410 yes = 0;
6411
6412 if (yes) {
6413 ret = str2prefix_rd(rd_str, &prd);
6414 if (!ret) {
6415 vty_out(vty, "%% Malformed rd\n");
6416 return CMD_WARNING_CONFIG_FAILED;
6417 }
6418 }
6419
6420 afi = vpn_policy_getafi(vty, bgp, false);
6421 if (afi == AFI_MAX)
6422 return CMD_WARNING_CONFIG_FAILED;
6423
6424 /*
6425 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6426 */
6427 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6428 bgp_get_default(), bgp);
6429
6430 if (yes) {
6431 bgp->vpn_policy[afi].tovpn_rd = prd;
6432 SET_FLAG(bgp->vpn_policy[afi].flags,
6433 BGP_VPN_POLICY_TOVPN_RD_SET);
6434 } else {
6435 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6436 BGP_VPN_POLICY_TOVPN_RD_SET);
6437 }
6438
6439 /* post-change: re-export vpn routes */
6440 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6441 bgp_get_default(), bgp);
6442
6443 return CMD_SUCCESS;
6444 }
6445
6446 ALIAS (af_rd_vpn_export,
6447 af_no_rd_vpn_export_cmd,
6448 "no rd vpn export",
6449 NO_STR
6450 "Specify route distinguisher\n"
6451 "Between current address-family and vpn\n"
6452 "For routes leaked from current address-family to vpn\n")
6453
6454 DEFPY (af_label_vpn_export,
6455 af_label_vpn_export_cmd,
6456 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6457 NO_STR
6458 "label value for VRF\n"
6459 "Between current address-family and vpn\n"
6460 "For routes leaked from current address-family to vpn\n"
6461 "Label Value <0-1048575>\n"
6462 "Automatically assign a label\n")
6463 {
6464 VTY_DECLVAR_CONTEXT(bgp, bgp);
6465 mpls_label_t label = MPLS_LABEL_NONE;
6466 afi_t afi;
6467 int idx = 0;
6468 int yes = 1;
6469
6470 if (argv_find(argv, argc, "no", &idx))
6471 yes = 0;
6472
6473 /* If "no ...", squash trailing parameter */
6474 if (!yes)
6475 label_auto = NULL;
6476
6477 if (yes) {
6478 if (!label_auto)
6479 label = label_val; /* parser should force unsigned */
6480 }
6481
6482 afi = vpn_policy_getafi(vty, bgp, false);
6483 if (afi == AFI_MAX)
6484 return CMD_WARNING_CONFIG_FAILED;
6485
6486
6487 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6488 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6489 /* no change */
6490 return CMD_SUCCESS;
6491
6492 /*
6493 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6494 */
6495 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6496 bgp_get_default(), bgp);
6497
6498 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6499 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6500
6501 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6502
6503 /*
6504 * label has previously been automatically
6505 * assigned by labelpool: release it
6506 *
6507 * NB if tovpn_label == MPLS_LABEL_NONE it
6508 * means the automatic assignment is in flight
6509 * and therefore the labelpool callback must
6510 * detect that the auto label is not needed.
6511 */
6512
6513 bgp_lp_release(LP_TYPE_VRF,
6514 &bgp->vpn_policy[afi],
6515 bgp->vpn_policy[afi].tovpn_label);
6516 }
6517 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6518 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6519 }
6520
6521 bgp->vpn_policy[afi].tovpn_label = label;
6522 if (label_auto) {
6523 SET_FLAG(bgp->vpn_policy[afi].flags,
6524 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6525 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6526 vpn_leak_label_callback);
6527 }
6528
6529 /* post-change: re-export vpn routes */
6530 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6531 bgp_get_default(), bgp);
6532
6533 return CMD_SUCCESS;
6534 }
6535
6536 ALIAS (af_label_vpn_export,
6537 af_no_label_vpn_export_cmd,
6538 "no label vpn export",
6539 NO_STR
6540 "label value for VRF\n"
6541 "Between current address-family and vpn\n"
6542 "For routes leaked from current address-family to vpn\n")
6543
6544 DEFPY (af_nexthop_vpn_export,
6545 af_nexthop_vpn_export_cmd,
6546 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6547 NO_STR
6548 "Specify next hop to use for VRF advertised prefixes\n"
6549 "Between current address-family and vpn\n"
6550 "For routes leaked from current address-family to vpn\n"
6551 "IPv4 prefix\n"
6552 "IPv6 prefix\n")
6553 {
6554 VTY_DECLVAR_CONTEXT(bgp, bgp);
6555 afi_t afi;
6556 struct prefix p;
6557 int idx = 0;
6558 int yes = 1;
6559
6560 if (argv_find(argv, argc, "no", &idx))
6561 yes = 0;
6562
6563 if (yes) {
6564 if (!sockunion2hostprefix(nexthop_str, &p))
6565 return CMD_WARNING_CONFIG_FAILED;
6566 }
6567
6568 afi = vpn_policy_getafi(vty, bgp, false);
6569 if (afi == AFI_MAX)
6570 return CMD_WARNING_CONFIG_FAILED;
6571
6572 /*
6573 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6574 */
6575 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6576 bgp_get_default(), bgp);
6577
6578 if (yes) {
6579 bgp->vpn_policy[afi].tovpn_nexthop = p;
6580 SET_FLAG(bgp->vpn_policy[afi].flags,
6581 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6582 } else {
6583 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6584 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6585 }
6586
6587 /* post-change: re-export vpn routes */
6588 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6589 bgp_get_default(), bgp);
6590
6591 return CMD_SUCCESS;
6592 }
6593
6594 ALIAS (af_nexthop_vpn_export,
6595 af_no_nexthop_vpn_export_cmd,
6596 "no nexthop vpn export",
6597 NO_STR
6598 "Specify next hop to use for VRF advertised prefixes\n"
6599 "Between current address-family and vpn\n"
6600 "For routes leaked from current address-family to vpn\n")
6601
6602 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6603 {
6604 if (!strcmp(dstr, "import")) {
6605 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6606 } else if (!strcmp(dstr, "export")) {
6607 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6608 } else if (!strcmp(dstr, "both")) {
6609 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6610 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6611 } else {
6612 vty_out(vty, "%% direction parse error\n");
6613 return CMD_WARNING_CONFIG_FAILED;
6614 }
6615 return CMD_SUCCESS;
6616 }
6617
6618 DEFPY (af_rt_vpn_imexport,
6619 af_rt_vpn_imexport_cmd,
6620 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6621 NO_STR
6622 "Specify route target list\n"
6623 "Specify route target list\n"
6624 "Between current address-family and vpn\n"
6625 "For routes leaked from vpn to current address-family: match any\n"
6626 "For routes leaked from current address-family to vpn: set\n"
6627 "both import: match any and export: set\n"
6628 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6629 {
6630 VTY_DECLVAR_CONTEXT(bgp, bgp);
6631 int ret;
6632 struct ecommunity *ecom = NULL;
6633 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6634 vpn_policy_direction_t dir;
6635 afi_t afi;
6636 int idx = 0;
6637 int yes = 1;
6638
6639 if (argv_find(argv, argc, "no", &idx))
6640 yes = 0;
6641
6642 afi = vpn_policy_getafi(vty, bgp, false);
6643 if (afi == AFI_MAX)
6644 return CMD_WARNING_CONFIG_FAILED;
6645
6646 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6647 if (ret != CMD_SUCCESS)
6648 return ret;
6649
6650 if (yes) {
6651 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6652 vty_out(vty, "%% Missing RTLIST\n");
6653 return CMD_WARNING_CONFIG_FAILED;
6654 }
6655 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6656 if (ret != CMD_SUCCESS) {
6657 return ret;
6658 }
6659 }
6660
6661 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6662 if (!dodir[dir])
6663 continue;
6664
6665 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6666
6667 if (yes) {
6668 if (bgp->vpn_policy[afi].rtlist[dir])
6669 ecommunity_free(
6670 &bgp->vpn_policy[afi].rtlist[dir]);
6671 bgp->vpn_policy[afi].rtlist[dir] =
6672 ecommunity_dup(ecom);
6673 } else {
6674 if (bgp->vpn_policy[afi].rtlist[dir])
6675 ecommunity_free(
6676 &bgp->vpn_policy[afi].rtlist[dir]);
6677 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6678 }
6679
6680 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6681 }
6682
6683 if (ecom)
6684 ecommunity_free(&ecom);
6685
6686 return CMD_SUCCESS;
6687 }
6688
6689 ALIAS (af_rt_vpn_imexport,
6690 af_no_rt_vpn_imexport_cmd,
6691 "no <rt|route-target> vpn <import|export|both>$direction_str",
6692 NO_STR
6693 "Specify route target list\n"
6694 "Specify route target list\n"
6695 "Between current address-family and vpn\n"
6696 "For routes leaked from vpn to current address-family\n"
6697 "For routes leaked from current address-family to vpn\n"
6698 "both import and export\n")
6699
6700 DEFPY (af_route_map_vpn_imexport,
6701 af_route_map_vpn_imexport_cmd,
6702 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6703 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6704 NO_STR
6705 "Specify route map\n"
6706 "Between current address-family and vpn\n"
6707 "For routes leaked from vpn to current address-family\n"
6708 "For routes leaked from current address-family to vpn\n"
6709 "name of route-map\n")
6710 {
6711 VTY_DECLVAR_CONTEXT(bgp, bgp);
6712 int ret;
6713 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6714 vpn_policy_direction_t dir;
6715 afi_t afi;
6716 int idx = 0;
6717 int yes = 1;
6718
6719 if (argv_find(argv, argc, "no", &idx))
6720 yes = 0;
6721
6722 afi = vpn_policy_getafi(vty, bgp, false);
6723 if (afi == AFI_MAX)
6724 return CMD_WARNING_CONFIG_FAILED;
6725
6726 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6727 if (ret != CMD_SUCCESS)
6728 return ret;
6729
6730 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6731 if (!dodir[dir])
6732 continue;
6733
6734 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6735
6736 if (yes) {
6737 if (bgp->vpn_policy[afi].rmap_name[dir])
6738 XFREE(MTYPE_ROUTE_MAP_NAME,
6739 bgp->vpn_policy[afi].rmap_name[dir]);
6740 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6741 MTYPE_ROUTE_MAP_NAME, rmap_str);
6742 bgp->vpn_policy[afi].rmap[dir] =
6743 route_map_lookup_warn_noexist(vty, rmap_str);
6744 if (!bgp->vpn_policy[afi].rmap[dir])
6745 return CMD_SUCCESS;
6746 } else {
6747 if (bgp->vpn_policy[afi].rmap_name[dir])
6748 XFREE(MTYPE_ROUTE_MAP_NAME,
6749 bgp->vpn_policy[afi].rmap_name[dir]);
6750 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6751 bgp->vpn_policy[afi].rmap[dir] = NULL;
6752 }
6753
6754 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6755 }
6756
6757 return CMD_SUCCESS;
6758 }
6759
6760 ALIAS (af_route_map_vpn_imexport,
6761 af_no_route_map_vpn_imexport_cmd,
6762 "no route-map vpn <import|export>$direction_str",
6763 NO_STR
6764 "Specify route map\n"
6765 "Between current address-family and vpn\n"
6766 "For routes leaked from vpn to current address-family\n"
6767 "For routes leaked from current address-family to vpn\n")
6768
6769 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6770 "[no] import vrf route-map RMAP$rmap_str",
6771 NO_STR
6772 "Import routes from another VRF\n"
6773 "Vrf routes being filtered\n"
6774 "Specify route map\n"
6775 "name of route-map\n")
6776 {
6777 VTY_DECLVAR_CONTEXT(bgp, bgp);
6778 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6779 afi_t afi;
6780 int idx = 0;
6781 int yes = 1;
6782 struct bgp *bgp_default;
6783
6784 if (argv_find(argv, argc, "no", &idx))
6785 yes = 0;
6786
6787 afi = vpn_policy_getafi(vty, bgp, true);
6788 if (afi == AFI_MAX)
6789 return CMD_WARNING_CONFIG_FAILED;
6790
6791 bgp_default = bgp_get_default();
6792 if (!bgp_default) {
6793 int32_t ret;
6794 as_t as = bgp->as;
6795
6796 /* Auto-create assuming the same AS */
6797 ret = bgp_get(&bgp_default, &as, NULL,
6798 BGP_INSTANCE_TYPE_DEFAULT);
6799
6800 if (ret) {
6801 vty_out(vty,
6802 "VRF default is not configured as a bgp instance\n");
6803 return CMD_WARNING;
6804 }
6805 }
6806
6807 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6808
6809 if (yes) {
6810 if (bgp->vpn_policy[afi].rmap_name[dir])
6811 XFREE(MTYPE_ROUTE_MAP_NAME,
6812 bgp->vpn_policy[afi].rmap_name[dir]);
6813 bgp->vpn_policy[afi].rmap_name[dir] =
6814 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6815 bgp->vpn_policy[afi].rmap[dir] =
6816 route_map_lookup_warn_noexist(vty, rmap_str);
6817 if (!bgp->vpn_policy[afi].rmap[dir])
6818 return CMD_SUCCESS;
6819 } else {
6820 if (bgp->vpn_policy[afi].rmap_name[dir])
6821 XFREE(MTYPE_ROUTE_MAP_NAME,
6822 bgp->vpn_policy[afi].rmap_name[dir]);
6823 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6824 bgp->vpn_policy[afi].rmap[dir] = NULL;
6825 }
6826
6827 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6828
6829 return CMD_SUCCESS;
6830 }
6831
6832 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6833 "no import vrf route-map",
6834 NO_STR
6835 "Import routes from another VRF\n"
6836 "Vrf routes being filtered\n"
6837 "Specify route map\n")
6838
6839 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6840 "[no] import vrf VIEWVRFNAME$import_name",
6841 NO_STR
6842 "Import routes from another VRF\n"
6843 "VRF to import from\n"
6844 "The name of the VRF\n")
6845 {
6846 VTY_DECLVAR_CONTEXT(bgp, bgp);
6847 struct listnode *node;
6848 struct bgp *vrf_bgp, *bgp_default;
6849 int32_t ret = 0;
6850 as_t as = bgp->as;
6851 bool remove = false;
6852 int32_t idx = 0;
6853 char *vname;
6854 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6855 safi_t safi;
6856 afi_t afi;
6857
6858 if (import_name == NULL) {
6859 vty_out(vty, "%% Missing import name\n");
6860 return CMD_WARNING;
6861 }
6862
6863 if (argv_find(argv, argc, "no", &idx))
6864 remove = true;
6865
6866 afi = vpn_policy_getafi(vty, bgp, true);
6867 if (afi == AFI_MAX)
6868 return CMD_WARNING_CONFIG_FAILED;
6869
6870 safi = bgp_node_safi(vty);
6871
6872 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6873 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6874 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6875 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6876 remove ? "unimport" : "import", import_name);
6877 return CMD_WARNING;
6878 }
6879
6880 bgp_default = bgp_get_default();
6881 if (!bgp_default) {
6882 /* Auto-create assuming the same AS */
6883 ret = bgp_get(&bgp_default, &as, NULL,
6884 BGP_INSTANCE_TYPE_DEFAULT);
6885
6886 if (ret) {
6887 vty_out(vty,
6888 "VRF default is not configured as a bgp instance\n");
6889 return CMD_WARNING;
6890 }
6891 }
6892
6893 vrf_bgp = bgp_lookup_by_name(import_name);
6894 if (!vrf_bgp) {
6895 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6896 vrf_bgp = bgp_default;
6897 else
6898 /* Auto-create assuming the same AS */
6899 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6900
6901 if (ret) {
6902 vty_out(vty,
6903 "VRF %s is not configured as a bgp instance\n",
6904 import_name);
6905 return CMD_WARNING;
6906 }
6907 }
6908
6909 if (remove) {
6910 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6911 } else {
6912 /* Already importing from "import_vrf"? */
6913 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6914 vname)) {
6915 if (strcmp(vname, import_name) == 0)
6916 return CMD_WARNING;
6917 }
6918
6919 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6920 }
6921
6922 return CMD_SUCCESS;
6923 }
6924
6925 /* This command is valid only in a bgp vrf instance or the default instance */
6926 DEFPY (bgp_imexport_vpn,
6927 bgp_imexport_vpn_cmd,
6928 "[no] <import|export>$direction_str vpn",
6929 NO_STR
6930 "Import routes to this address-family\n"
6931 "Export routes from this address-family\n"
6932 "to/from default instance VPN RIB\n")
6933 {
6934 VTY_DECLVAR_CONTEXT(bgp, bgp);
6935 int previous_state;
6936 afi_t afi;
6937 safi_t safi;
6938 int idx = 0;
6939 int yes = 1;
6940 int flag;
6941 vpn_policy_direction_t dir;
6942
6943 if (argv_find(argv, argc, "no", &idx))
6944 yes = 0;
6945
6946 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6947 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6948
6949 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6950 return CMD_WARNING_CONFIG_FAILED;
6951 }
6952
6953 afi = bgp_node_afi(vty);
6954 safi = bgp_node_safi(vty);
6955 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6956 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6957 return CMD_WARNING_CONFIG_FAILED;
6958 }
6959
6960 if (!strcmp(direction_str, "import")) {
6961 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6962 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6963 } else if (!strcmp(direction_str, "export")) {
6964 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6965 dir = BGP_VPN_POLICY_DIR_TOVPN;
6966 } else {
6967 vty_out(vty, "%% unknown direction %s\n", direction_str);
6968 return CMD_WARNING_CONFIG_FAILED;
6969 }
6970
6971 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6972
6973 if (yes) {
6974 SET_FLAG(bgp->af_flags[afi][safi], flag);
6975 if (!previous_state) {
6976 /* trigger export current vrf */
6977 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6978 }
6979 } else {
6980 if (previous_state) {
6981 /* trigger un-export current vrf */
6982 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6983 }
6984 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6985 }
6986
6987 return CMD_SUCCESS;
6988 }
6989
6990 DEFPY (af_routetarget_import,
6991 af_routetarget_import_cmd,
6992 "[no] <rt|route-target> redirect import RTLIST...",
6993 NO_STR
6994 "Specify route target list\n"
6995 "Specify route target list\n"
6996 "Flow-spec redirect type route target\n"
6997 "Import routes to this address-family\n"
6998 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6999 {
7000 VTY_DECLVAR_CONTEXT(bgp, bgp);
7001 int ret;
7002 struct ecommunity *ecom = NULL;
7003 afi_t afi;
7004 int idx = 0;
7005 int yes = 1;
7006
7007 if (argv_find(argv, argc, "no", &idx))
7008 yes = 0;
7009
7010 afi = vpn_policy_getafi(vty, bgp, false);
7011 if (afi == AFI_MAX)
7012 return CMD_WARNING_CONFIG_FAILED;
7013
7014 if (yes) {
7015 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7016 vty_out(vty, "%% Missing RTLIST\n");
7017 return CMD_WARNING_CONFIG_FAILED;
7018 }
7019 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7020 if (ret != CMD_SUCCESS)
7021 return ret;
7022 }
7023
7024 if (yes) {
7025 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7026 ecommunity_free(&bgp->vpn_policy[afi]
7027 .import_redirect_rtlist);
7028 bgp->vpn_policy[afi].import_redirect_rtlist =
7029 ecommunity_dup(ecom);
7030 } else {
7031 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7032 ecommunity_free(&bgp->vpn_policy[afi]
7033 .import_redirect_rtlist);
7034 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7035 }
7036
7037 if (ecom)
7038 ecommunity_free(&ecom);
7039
7040 return CMD_SUCCESS;
7041 }
7042
7043 DEFUN_NOSH (address_family_ipv4_safi,
7044 address_family_ipv4_safi_cmd,
7045 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7046 "Enter Address Family command mode\n"
7047 "Address Family\n"
7048 BGP_SAFI_WITH_LABEL_HELP_STR)
7049 {
7050
7051 if (argc == 3) {
7052 VTY_DECLVAR_CONTEXT(bgp, bgp);
7053 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7054 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7055 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7056 && safi != SAFI_EVPN) {
7057 vty_out(vty,
7058 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7059 return CMD_WARNING_CONFIG_FAILED;
7060 }
7061 vty->node = bgp_node_type(AFI_IP, safi);
7062 } else
7063 vty->node = BGP_IPV4_NODE;
7064
7065 return CMD_SUCCESS;
7066 }
7067
7068 DEFUN_NOSH (address_family_ipv6_safi,
7069 address_family_ipv6_safi_cmd,
7070 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7071 "Enter Address Family command mode\n"
7072 "Address Family\n"
7073 BGP_SAFI_WITH_LABEL_HELP_STR)
7074 {
7075 if (argc == 3) {
7076 VTY_DECLVAR_CONTEXT(bgp, bgp);
7077 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7078 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7079 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7080 && safi != SAFI_EVPN) {
7081 vty_out(vty,
7082 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7083 return CMD_WARNING_CONFIG_FAILED;
7084 }
7085 vty->node = bgp_node_type(AFI_IP6, safi);
7086 } else
7087 vty->node = BGP_IPV6_NODE;
7088
7089 return CMD_SUCCESS;
7090 }
7091
7092 #ifdef KEEP_OLD_VPN_COMMANDS
7093 DEFUN_NOSH (address_family_vpnv4,
7094 address_family_vpnv4_cmd,
7095 "address-family vpnv4 [unicast]",
7096 "Enter Address Family command mode\n"
7097 "Address Family\n"
7098 "Address Family modifier\n")
7099 {
7100 vty->node = BGP_VPNV4_NODE;
7101 return CMD_SUCCESS;
7102 }
7103
7104 DEFUN_NOSH (address_family_vpnv6,
7105 address_family_vpnv6_cmd,
7106 "address-family vpnv6 [unicast]",
7107 "Enter Address Family command mode\n"
7108 "Address Family\n"
7109 "Address Family modifier\n")
7110 {
7111 vty->node = BGP_VPNV6_NODE;
7112 return CMD_SUCCESS;
7113 }
7114 #endif /* KEEP_OLD_VPN_COMMANDS */
7115
7116 DEFUN_NOSH (address_family_evpn,
7117 address_family_evpn_cmd,
7118 "address-family l2vpn evpn",
7119 "Enter Address Family command mode\n"
7120 "Address Family\n"
7121 "Address Family modifier\n")
7122 {
7123 VTY_DECLVAR_CONTEXT(bgp, bgp);
7124 vty->node = BGP_EVPN_NODE;
7125 return CMD_SUCCESS;
7126 }
7127
7128 DEFUN_NOSH (exit_address_family,
7129 exit_address_family_cmd,
7130 "exit-address-family",
7131 "Exit from Address Family configuration mode\n")
7132 {
7133 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7134 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7135 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7136 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7137 || vty->node == BGP_EVPN_NODE
7138 || vty->node == BGP_FLOWSPECV4_NODE
7139 || vty->node == BGP_FLOWSPECV6_NODE)
7140 vty->node = BGP_NODE;
7141 return CMD_SUCCESS;
7142 }
7143
7144 /* Recalculate bestpath and re-advertise a prefix */
7145 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7146 const char *ip_str, afi_t afi, safi_t safi,
7147 struct prefix_rd *prd)
7148 {
7149 int ret;
7150 struct prefix match;
7151 struct bgp_node *rn;
7152 struct bgp_node *rm;
7153 struct bgp *bgp;
7154 struct bgp_table *table;
7155 struct bgp_table *rib;
7156
7157 /* BGP structure lookup. */
7158 if (view_name) {
7159 bgp = bgp_lookup_by_name(view_name);
7160 if (bgp == NULL) {
7161 vty_out(vty, "%% Can't find BGP instance %s\n",
7162 view_name);
7163 return CMD_WARNING;
7164 }
7165 } else {
7166 bgp = bgp_get_default();
7167 if (bgp == NULL) {
7168 vty_out(vty, "%% No BGP process is configured\n");
7169 return CMD_WARNING;
7170 }
7171 }
7172
7173 /* Check IP address argument. */
7174 ret = str2prefix(ip_str, &match);
7175 if (!ret) {
7176 vty_out(vty, "%% address is malformed\n");
7177 return CMD_WARNING;
7178 }
7179
7180 match.family = afi2family(afi);
7181 rib = bgp->rib[afi][safi];
7182
7183 if (safi == SAFI_MPLS_VPN) {
7184 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7185 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7186 continue;
7187
7188 table = bgp_node_get_bgp_table_info(rn);
7189 if (table != NULL) {
7190
7191 if ((rm = bgp_node_match(table, &match))
7192 != NULL) {
7193 if (rm->p.prefixlen
7194 == match.prefixlen) {
7195 SET_FLAG(rm->flags,
7196 BGP_NODE_USER_CLEAR);
7197 bgp_process(bgp, rm, afi, safi);
7198 }
7199 bgp_unlock_node(rm);
7200 }
7201 }
7202 }
7203 } else {
7204 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7205 if (rn->p.prefixlen == match.prefixlen) {
7206 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7207 bgp_process(bgp, rn, afi, safi);
7208 }
7209 bgp_unlock_node(rn);
7210 }
7211 }
7212
7213 return CMD_SUCCESS;
7214 }
7215
7216 /* one clear bgp command to rule them all */
7217 DEFUN (clear_ip_bgp_all,
7218 clear_ip_bgp_all_cmd,
7219 "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 WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
7220 CLEAR_STR
7221 IP_STR
7222 BGP_STR
7223 BGP_INSTANCE_HELP_STR
7224 BGP_AFI_HELP_STR
7225 "Address Family\n"
7226 BGP_SAFI_WITH_LABEL_HELP_STR
7227 "Address Family modifier\n"
7228 "Clear all peers\n"
7229 "BGP neighbor address to clear\n"
7230 "BGP IPv6 neighbor to clear\n"
7231 "BGP neighbor on interface to clear\n"
7232 "Clear peers with the AS number\n"
7233 "Clear all external peers\n"
7234 "Clear all members of peer-group\n"
7235 "BGP peer-group name\n"
7236 BGP_SOFT_STR
7237 BGP_SOFT_IN_STR
7238 BGP_SOFT_OUT_STR
7239 BGP_SOFT_IN_STR
7240 "Push out prefix-list ORF and do inbound soft reconfig\n"
7241 BGP_SOFT_OUT_STR)
7242 {
7243 char *vrf = NULL;
7244
7245 afi_t afi = AFI_IP6;
7246 safi_t safi = SAFI_UNICAST;
7247 enum clear_sort clr_sort = clear_peer;
7248 enum bgp_clear_type clr_type;
7249 char *clr_arg = NULL;
7250
7251 int idx = 0;
7252
7253 /* clear [ip] bgp */
7254 if (argv_find(argv, argc, "ip", &idx))
7255 afi = AFI_IP;
7256
7257 /* [<vrf> VIEWVRFNAME] */
7258 if (argv_find(argv, argc, "vrf", &idx)) {
7259 vrf = argv[idx + 1]->arg;
7260 idx += 2;
7261 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7262 vrf = NULL;
7263 } else if (argv_find(argv, argc, "view", &idx)) {
7264 /* [<view> VIEWVRFNAME] */
7265 vrf = argv[idx + 1]->arg;
7266 idx += 2;
7267 }
7268 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7269 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7270 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7271
7272 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7273 if (argv_find(argv, argc, "*", &idx)) {
7274 clr_sort = clear_all;
7275 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7276 clr_sort = clear_peer;
7277 clr_arg = argv[idx]->arg;
7278 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7279 clr_sort = clear_peer;
7280 clr_arg = argv[idx]->arg;
7281 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7282 clr_sort = clear_group;
7283 idx++;
7284 clr_arg = argv[idx]->arg;
7285 } else if (argv_find(argv, argc, "WORD", &idx)) {
7286 clr_sort = clear_peer;
7287 clr_arg = argv[idx]->arg;
7288 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7289 clr_sort = clear_as;
7290 clr_arg = argv[idx]->arg;
7291 } else if (argv_find(argv, argc, "external", &idx)) {
7292 clr_sort = clear_external;
7293 }
7294
7295 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7296 if (argv_find(argv, argc, "soft", &idx)) {
7297 if (argv_find(argv, argc, "in", &idx)
7298 || argv_find(argv, argc, "out", &idx))
7299 clr_type = strmatch(argv[idx]->text, "in")
7300 ? BGP_CLEAR_SOFT_IN
7301 : BGP_CLEAR_SOFT_OUT;
7302 else
7303 clr_type = BGP_CLEAR_SOFT_BOTH;
7304 } else if (argv_find(argv, argc, "in", &idx)) {
7305 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7306 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7307 : BGP_CLEAR_SOFT_IN;
7308 } else if (argv_find(argv, argc, "out", &idx)) {
7309 clr_type = BGP_CLEAR_SOFT_OUT;
7310 } else
7311 clr_type = BGP_CLEAR_SOFT_NONE;
7312
7313 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7314 }
7315
7316 DEFUN (clear_ip_bgp_prefix,
7317 clear_ip_bgp_prefix_cmd,
7318 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7319 CLEAR_STR
7320 IP_STR
7321 BGP_STR
7322 BGP_INSTANCE_HELP_STR
7323 "Clear bestpath and re-advertise\n"
7324 "IPv4 prefix\n")
7325 {
7326 char *vrf = NULL;
7327 char *prefix = NULL;
7328
7329 int idx = 0;
7330
7331 /* [<view|vrf> VIEWVRFNAME] */
7332 if (argv_find(argv, argc, "vrf", &idx)) {
7333 vrf = argv[idx + 1]->arg;
7334 idx += 2;
7335 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7336 vrf = NULL;
7337 } else if (argv_find(argv, argc, "view", &idx)) {
7338 /* [<view> VIEWVRFNAME] */
7339 vrf = argv[idx + 1]->arg;
7340 idx += 2;
7341 }
7342
7343 prefix = argv[argc - 1]->arg;
7344
7345 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7346 }
7347
7348 DEFUN (clear_bgp_ipv6_safi_prefix,
7349 clear_bgp_ipv6_safi_prefix_cmd,
7350 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7351 CLEAR_STR
7352 IP_STR
7353 BGP_STR
7354 "Address Family\n"
7355 BGP_SAFI_HELP_STR
7356 "Clear bestpath and re-advertise\n"
7357 "IPv6 prefix\n")
7358 {
7359 int idx_safi = 0;
7360 int idx_ipv6_prefix = 0;
7361 safi_t safi = SAFI_UNICAST;
7362 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7363 argv[idx_ipv6_prefix]->arg : NULL;
7364
7365 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7366 return bgp_clear_prefix(
7367 vty, NULL, prefix, AFI_IP6,
7368 safi, NULL);
7369 }
7370
7371 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7372 clear_bgp_instance_ipv6_safi_prefix_cmd,
7373 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7374 CLEAR_STR
7375 IP_STR
7376 BGP_STR
7377 BGP_INSTANCE_HELP_STR
7378 "Address Family\n"
7379 BGP_SAFI_HELP_STR
7380 "Clear bestpath and re-advertise\n"
7381 "IPv6 prefix\n")
7382 {
7383 int idx_safi = 0;
7384 int idx_vrfview = 0;
7385 int idx_ipv6_prefix = 0;
7386 safi_t safi = SAFI_UNICAST;
7387 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7388 argv[idx_ipv6_prefix]->arg : NULL;
7389 char *vrfview = NULL;
7390
7391 /* [<view|vrf> VIEWVRFNAME] */
7392 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7393 vrfview = argv[idx_vrfview + 1]->arg;
7394 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7395 vrfview = NULL;
7396 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7397 /* [<view> VIEWVRFNAME] */
7398 vrfview = argv[idx_vrfview + 1]->arg;
7399 }
7400 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7401
7402 return bgp_clear_prefix(
7403 vty, vrfview, prefix,
7404 AFI_IP6, safi, NULL);
7405 }
7406
7407 DEFUN (show_bgp_views,
7408 show_bgp_views_cmd,
7409 "show [ip] bgp views",
7410 SHOW_STR
7411 IP_STR
7412 BGP_STR
7413 "Show the defined BGP views\n")
7414 {
7415 struct list *inst = bm->bgp;
7416 struct listnode *node;
7417 struct bgp *bgp;
7418
7419 vty_out(vty, "Defined BGP views:\n");
7420 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7421 /* Skip VRFs. */
7422 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7423 continue;
7424 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7425 bgp->as);
7426 }
7427
7428 return CMD_SUCCESS;
7429 }
7430
7431 DEFUN (show_bgp_vrfs,
7432 show_bgp_vrfs_cmd,
7433 "show [ip] bgp vrfs [json]",
7434 SHOW_STR
7435 IP_STR
7436 BGP_STR
7437 "Show BGP VRFs\n"
7438 JSON_STR)
7439 {
7440 char buf[ETHER_ADDR_STRLEN];
7441 struct list *inst = bm->bgp;
7442 struct listnode *node;
7443 struct bgp *bgp;
7444 bool uj = use_json(argc, argv);
7445 json_object *json = NULL;
7446 json_object *json_vrfs = NULL;
7447 int count = 0;
7448
7449 if (uj) {
7450 json = json_object_new_object();
7451 json_vrfs = json_object_new_object();
7452 }
7453
7454 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7455 const char *name, *type;
7456 struct peer *peer;
7457 struct listnode *node2, *nnode2;
7458 int peers_cfg, peers_estb;
7459 json_object *json_vrf = NULL;
7460
7461 /* Skip Views. */
7462 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7463 continue;
7464
7465 count++;
7466 if (!uj && count == 1)
7467 vty_out(vty,
7468 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7469 "Type", "Id", "routerId", "#PeersVfg",
7470 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7471
7472 peers_cfg = peers_estb = 0;
7473 if (uj)
7474 json_vrf = json_object_new_object();
7475
7476
7477 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7478 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7479 continue;
7480 peers_cfg++;
7481 if (peer->status == Established)
7482 peers_estb++;
7483 }
7484
7485 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7486 name = VRF_DEFAULT_NAME;
7487 type = "DFLT";
7488 } else {
7489 name = bgp->name;
7490 type = "VRF";
7491 }
7492
7493
7494 if (uj) {
7495 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7496 ? -1
7497 : (int64_t)bgp->vrf_id;
7498 json_object_string_add(json_vrf, "type", type);
7499 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7500 json_object_string_add(json_vrf, "routerId",
7501 inet_ntoa(bgp->router_id));
7502 json_object_int_add(json_vrf, "numConfiguredPeers",
7503 peers_cfg);
7504 json_object_int_add(json_vrf, "numEstablishedPeers",
7505 peers_estb);
7506
7507 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7508 json_object_string_add(
7509 json_vrf, "rmac",
7510 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7511 json_object_object_add(json_vrfs, name, json_vrf);
7512 } else
7513 vty_out(vty,
7514 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7515 type,
7516 bgp->vrf_id == VRF_UNKNOWN ? -1
7517 : (int)bgp->vrf_id,
7518 inet_ntoa(bgp->router_id), peers_cfg,
7519 peers_estb, name, bgp->l3vni,
7520 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7521 }
7522
7523 if (uj) {
7524 json_object_object_add(json, "vrfs", json_vrfs);
7525
7526 json_object_int_add(json, "totalVrfs", count);
7527
7528 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7529 json, JSON_C_TO_STRING_PRETTY));
7530 json_object_free(json);
7531 } else {
7532 if (count)
7533 vty_out(vty,
7534 "\nTotal number of VRFs (including default): %d\n",
7535 count);
7536 }
7537
7538 return CMD_SUCCESS;
7539 }
7540
7541 DEFUN (show_bgp_mac_hash,
7542 show_bgp_mac_hash_cmd,
7543 "show bgp mac hash",
7544 SHOW_STR
7545 BGP_STR
7546 "Mac Address\n"
7547 "Mac Address database\n")
7548 {
7549 bgp_mac_dump_table(vty);
7550
7551 return CMD_SUCCESS;
7552 }
7553
7554 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7555 {
7556 struct vty *vty = (struct vty *)args;
7557 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7558
7559 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7560 tip->refcnt);
7561 }
7562
7563 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7564 {
7565 vty_out(vty, "self nexthop database:\n");
7566 bgp_nexthop_show_address_hash(vty, bgp);
7567
7568 vty_out(vty, "Tunnel-ip database:\n");
7569 hash_iterate(bgp->tip_hash,
7570 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7571 vty);
7572 }
7573
7574 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7575 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7576 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7577 "martian next-hops\n"
7578 "martian next-hop database\n")
7579 {
7580 struct bgp *bgp = NULL;
7581 int idx = 0;
7582 char *name = NULL;
7583
7584 /* [<vrf> VIEWVRFNAME] */
7585 if (argv_find(argv, argc, "vrf", &idx)) {
7586 name = argv[idx + 1]->arg;
7587 if (name && strmatch(name, VRF_DEFAULT_NAME))
7588 name = NULL;
7589 } else if (argv_find(argv, argc, "view", &idx))
7590 /* [<view> VIEWVRFNAME] */
7591 name = argv[idx + 1]->arg;
7592 if (name)
7593 bgp = bgp_lookup_by_name(name);
7594 else
7595 bgp = bgp_get_default();
7596
7597 if (!bgp) {
7598 vty_out(vty, "%% No BGP process is configured\n");
7599 return CMD_WARNING;
7600 }
7601 bgp_show_martian_nexthops(vty, bgp);
7602
7603 return CMD_SUCCESS;
7604 }
7605
7606 DEFUN (show_bgp_memory,
7607 show_bgp_memory_cmd,
7608 "show [ip] bgp memory",
7609 SHOW_STR
7610 IP_STR
7611 BGP_STR
7612 "Global BGP memory statistics\n")
7613 {
7614 char memstrbuf[MTYPE_MEMSTR_LEN];
7615 unsigned long count;
7616
7617 /* RIB related usage stats */
7618 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7619 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7620 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7621 count * sizeof(struct bgp_node)));
7622
7623 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7624 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7625 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7626 count * sizeof(struct bgp_path_info)));
7627 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7628 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7629 count,
7630 mtype_memstr(
7631 memstrbuf, sizeof(memstrbuf),
7632 count * sizeof(struct bgp_path_info_extra)));
7633
7634 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7635 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7636 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7637 count * sizeof(struct bgp_static)));
7638
7639 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7640 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7641 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7642 count * sizeof(struct bpacket)));
7643
7644 /* Adj-In/Out */
7645 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7646 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7647 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7648 count * sizeof(struct bgp_adj_in)));
7649 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7650 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7651 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7652 count * sizeof(struct bgp_adj_out)));
7653
7654 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7655 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7656 count,
7657 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7658 count * sizeof(struct bgp_nexthop_cache)));
7659
7660 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7661 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7662 count,
7663 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7664 count * sizeof(struct bgp_damp_info)));
7665
7666 /* Attributes */
7667 count = attr_count();
7668 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7669 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7670 count * sizeof(struct attr)));
7671
7672 if ((count = attr_unknown_count()))
7673 vty_out(vty, "%ld unknown attributes\n", count);
7674
7675 /* AS_PATH attributes */
7676 count = aspath_count();
7677 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7678 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7679 count * sizeof(struct aspath)));
7680
7681 count = mtype_stats_alloc(MTYPE_AS_SEG);
7682 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7683 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7684 count * sizeof(struct assegment)));
7685
7686 /* Other attributes */
7687 if ((count = community_count()))
7688 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7689 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7690 count * sizeof(struct community)));
7691 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7692 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7693 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7694 count * sizeof(struct ecommunity)));
7695 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7696 vty_out(vty,
7697 "%ld BGP large-community entries, using %s of memory\n",
7698 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7699 count * sizeof(struct lcommunity)));
7700
7701 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7702 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7703 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7704 count * sizeof(struct cluster_list)));
7705
7706 /* Peer related usage */
7707 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7708 vty_out(vty, "%ld peers, using %s of memory\n", count,
7709 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7710 count * sizeof(struct peer)));
7711
7712 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7713 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7714 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7715 count * sizeof(struct peer_group)));
7716
7717 /* Other */
7718 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7719 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7720 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7721 count * sizeof(struct hash)));
7722 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7723 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7724 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7725 count * sizeof(struct hash_bucket)));
7726 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7727 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7728 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7729 count * sizeof(regex_t)));
7730 return CMD_SUCCESS;
7731 }
7732
7733 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7734 {
7735 json_object *bestpath = json_object_new_object();
7736
7737 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7738 json_object_string_add(bestpath, "asPath", "ignore");
7739
7740 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7741 json_object_string_add(bestpath, "asPath", "confed");
7742
7743 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7744 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7745 json_object_string_add(bestpath, "multiPathRelax",
7746 "as-set");
7747 else
7748 json_object_string_add(bestpath, "multiPathRelax",
7749 "true");
7750 } else
7751 json_object_string_add(bestpath, "multiPathRelax", "false");
7752
7753 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7754 json_object_string_add(bestpath, "compareRouterId", "true");
7755 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7756 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7757 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7758 json_object_string_add(bestpath, "med", "confed");
7759 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7760 json_object_string_add(bestpath, "med",
7761 "missing-as-worst");
7762 else
7763 json_object_string_add(bestpath, "med", "true");
7764 }
7765
7766 json_object_object_add(json, "bestPath", bestpath);
7767 }
7768
7769 /* Show BGP peer's summary information. */
7770 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7771 bool use_json, json_object *json)
7772 {
7773 struct peer *peer;
7774 struct listnode *node, *nnode;
7775 unsigned int count = 0, dn_count = 0;
7776 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7777 char neighbor_buf[VTY_BUFSIZ];
7778 int neighbor_col_default_width = 16;
7779 int len;
7780 int max_neighbor_width = 0;
7781 int pfx_rcd_safi;
7782 json_object *json_peer = NULL;
7783 json_object *json_peers = NULL;
7784 struct peer_af *paf;
7785
7786 /* labeled-unicast routes are installed in the unicast table so in order
7787 * to
7788 * display the correct PfxRcd value we must look at SAFI_UNICAST
7789 */
7790 if (safi == SAFI_LABELED_UNICAST)
7791 pfx_rcd_safi = SAFI_UNICAST;
7792 else
7793 pfx_rcd_safi = safi;
7794
7795 if (use_json) {
7796 if (json == NULL)
7797 json = json_object_new_object();
7798
7799 json_peers = json_object_new_object();
7800 } else {
7801 /* Loop over all neighbors that will be displayed to determine
7802 * how many
7803 * characters are needed for the Neighbor column
7804 */
7805 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7806 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7807 continue;
7808
7809 if (peer->afc[afi][safi]) {
7810 memset(dn_flag, '\0', sizeof(dn_flag));
7811 if (peer_dynamic_neighbor(peer))
7812 dn_flag[0] = '*';
7813
7814 if (peer->hostname
7815 && bgp_flag_check(bgp,
7816 BGP_FLAG_SHOW_HOSTNAME))
7817 sprintf(neighbor_buf, "%s%s(%s) ",
7818 dn_flag, peer->hostname,
7819 peer->host);
7820 else
7821 sprintf(neighbor_buf, "%s%s ", dn_flag,
7822 peer->host);
7823
7824 len = strlen(neighbor_buf);
7825
7826 if (len > max_neighbor_width)
7827 max_neighbor_width = len;
7828 }
7829 }
7830
7831 /* Originally we displayed the Neighbor column as 16
7832 * characters wide so make that the default
7833 */
7834 if (max_neighbor_width < neighbor_col_default_width)
7835 max_neighbor_width = neighbor_col_default_width;
7836 }
7837
7838 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7839 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7840 continue;
7841
7842 if (!peer->afc[afi][safi])
7843 continue;
7844
7845 if (!count) {
7846 unsigned long ents;
7847 char memstrbuf[MTYPE_MEMSTR_LEN];
7848 int64_t vrf_id_ui;
7849
7850 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7851 ? -1
7852 : (int64_t)bgp->vrf_id;
7853
7854 /* Usage summary and header */
7855 if (use_json) {
7856 json_object_string_add(
7857 json, "routerId",
7858 inet_ntoa(bgp->router_id));
7859 json_object_int_add(json, "as", bgp->as);
7860 json_object_int_add(json, "vrfId", vrf_id_ui);
7861 json_object_string_add(
7862 json, "vrfName",
7863 (bgp->inst_type
7864 == BGP_INSTANCE_TYPE_DEFAULT)
7865 ? VRF_DEFAULT_NAME
7866 : bgp->name);
7867 } else {
7868 vty_out(vty,
7869 "BGP router identifier %s, local AS number %u vrf-id %d",
7870 inet_ntoa(bgp->router_id), bgp->as,
7871 bgp->vrf_id == VRF_UNKNOWN
7872 ? -1
7873 : (int)bgp->vrf_id);
7874 vty_out(vty, "\n");
7875 }
7876
7877 if (bgp_update_delay_configured(bgp)) {
7878 if (use_json) {
7879 json_object_int_add(
7880 json, "updateDelayLimit",
7881 bgp->v_update_delay);
7882
7883 if (bgp->v_update_delay
7884 != bgp->v_establish_wait)
7885 json_object_int_add(
7886 json,
7887 "updateDelayEstablishWait",
7888 bgp->v_establish_wait);
7889
7890 if (bgp_update_delay_active(bgp)) {
7891 json_object_string_add(
7892 json,
7893 "updateDelayFirstNeighbor",
7894 bgp->update_delay_begin_time);
7895 json_object_boolean_true_add(
7896 json,
7897 "updateDelayInProgress");
7898 } else {
7899 if (bgp->update_delay_over) {
7900 json_object_string_add(
7901 json,
7902 "updateDelayFirstNeighbor",
7903 bgp->update_delay_begin_time);
7904 json_object_string_add(
7905 json,
7906 "updateDelayBestpathResumed",
7907 bgp->update_delay_end_time);
7908 json_object_string_add(
7909 json,
7910 "updateDelayZebraUpdateResume",
7911 bgp->update_delay_zebra_resume_time);
7912 json_object_string_add(
7913 json,
7914 "updateDelayPeerUpdateResume",
7915 bgp->update_delay_peers_resume_time);
7916 }
7917 }
7918 } else {
7919 vty_out(vty,
7920 "Read-only mode update-delay limit: %d seconds\n",
7921 bgp->v_update_delay);
7922 if (bgp->v_update_delay
7923 != bgp->v_establish_wait)
7924 vty_out(vty,
7925 " Establish wait: %d seconds\n",
7926 bgp->v_establish_wait);
7927
7928 if (bgp_update_delay_active(bgp)) {
7929 vty_out(vty,
7930 " First neighbor established: %s\n",
7931 bgp->update_delay_begin_time);
7932 vty_out(vty,
7933 " Delay in progress\n");
7934 } else {
7935 if (bgp->update_delay_over) {
7936 vty_out(vty,
7937 " First neighbor established: %s\n",
7938 bgp->update_delay_begin_time);
7939 vty_out(vty,
7940 " Best-paths resumed: %s\n",
7941 bgp->update_delay_end_time);
7942 vty_out(vty,
7943 " zebra update resumed: %s\n",
7944 bgp->update_delay_zebra_resume_time);
7945 vty_out(vty,
7946 " peers update resumed: %s\n",
7947 bgp->update_delay_peers_resume_time);
7948 }
7949 }
7950 }
7951 }
7952
7953 if (use_json) {
7954 if (bgp_maxmed_onstartup_configured(bgp)
7955 && bgp->maxmed_active)
7956 json_object_boolean_true_add(
7957 json, "maxMedOnStartup");
7958 if (bgp->v_maxmed_admin)
7959 json_object_boolean_true_add(
7960 json, "maxMedAdministrative");
7961
7962 json_object_int_add(
7963 json, "tableVersion",
7964 bgp_table_version(bgp->rib[afi][safi]));
7965
7966 ents = bgp_table_count(bgp->rib[afi][safi]);
7967 json_object_int_add(json, "ribCount", ents);
7968 json_object_int_add(
7969 json, "ribMemory",
7970 ents * sizeof(struct bgp_node));
7971
7972 ents = bgp->af_peer_count[afi][safi];
7973 json_object_int_add(json, "peerCount", ents);
7974 json_object_int_add(json, "peerMemory",
7975 ents * sizeof(struct peer));
7976
7977 if ((ents = listcount(bgp->group))) {
7978 json_object_int_add(
7979 json, "peerGroupCount", ents);
7980 json_object_int_add(
7981 json, "peerGroupMemory",
7982 ents * sizeof(struct
7983 peer_group));
7984 }
7985
7986 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7987 BGP_CONFIG_DAMPENING))
7988 json_object_boolean_true_add(
7989 json, "dampeningEnabled");
7990 } else {
7991 if (bgp_maxmed_onstartup_configured(bgp)
7992 && bgp->maxmed_active)
7993 vty_out(vty,
7994 "Max-med on-startup active\n");
7995 if (bgp->v_maxmed_admin)
7996 vty_out(vty,
7997 "Max-med administrative active\n");
7998
7999 vty_out(vty, "BGP table version %" PRIu64 "\n",
8000 bgp_table_version(bgp->rib[afi][safi]));
8001
8002 ents = bgp_table_count(bgp->rib[afi][safi]);
8003 vty_out(vty,
8004 "RIB entries %ld, using %s of memory\n",
8005 ents,
8006 mtype_memstr(memstrbuf,
8007 sizeof(memstrbuf),
8008 ents * sizeof(struct
8009 bgp_node)));
8010
8011 /* Peer related usage */
8012 ents = bgp->af_peer_count[afi][safi];
8013 vty_out(vty, "Peers %ld, using %s of memory\n",
8014 ents,
8015 mtype_memstr(
8016 memstrbuf, sizeof(memstrbuf),
8017 ents * sizeof(struct peer)));
8018
8019 if ((ents = listcount(bgp->group)))
8020 vty_out(vty,
8021 "Peer groups %ld, using %s of memory\n",
8022 ents,
8023 mtype_memstr(
8024 memstrbuf,
8025 sizeof(memstrbuf),
8026 ents * sizeof(struct
8027 peer_group)));
8028
8029 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8030 BGP_CONFIG_DAMPENING))
8031 vty_out(vty, "Dampening enabled.\n");
8032 vty_out(vty, "\n");
8033
8034 /* Subtract 8 here because 'Neighbor' is
8035 * 8 characters */
8036 vty_out(vty, "Neighbor");
8037 vty_out(vty, "%*s", max_neighbor_width - 8,
8038 " ");
8039 vty_out(vty,
8040 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8041 }
8042 }
8043
8044 count++;
8045
8046 if (use_json) {
8047 json_peer = json_object_new_object();
8048
8049 if (peer_dynamic_neighbor(peer)) {
8050 dn_count++;
8051 json_object_boolean_true_add(json_peer,
8052 "dynamicPeer");
8053 }
8054
8055 if (peer->hostname)
8056 json_object_string_add(json_peer, "hostname",
8057 peer->hostname);
8058
8059 if (peer->domainname)
8060 json_object_string_add(json_peer, "domainname",
8061 peer->domainname);
8062
8063 json_object_int_add(json_peer, "remoteAs", peer->as);
8064 json_object_int_add(json_peer, "version", 4);
8065 json_object_int_add(json_peer, "msgRcvd",
8066 PEER_TOTAL_RX(peer));
8067 json_object_int_add(json_peer, "msgSent",
8068 PEER_TOTAL_TX(peer));
8069
8070 json_object_int_add(json_peer, "tableVersion",
8071 peer->version[afi][safi]);
8072 json_object_int_add(json_peer, "outq",
8073 peer->obuf->count);
8074 json_object_int_add(json_peer, "inq", 0);
8075 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8076 use_json, json_peer);
8077
8078 /*
8079 * Adding "pfxRcd" field to match with the corresponding
8080 * CLI. "prefixReceivedCount" will be deprecated in
8081 * future.
8082 */
8083 json_object_int_add(json_peer, "prefixReceivedCount",
8084 peer->pcount[afi][pfx_rcd_safi]);
8085 json_object_int_add(json_peer, "pfxRcd",
8086 peer->pcount[afi][pfx_rcd_safi]);
8087
8088 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8089 if (paf && PAF_SUBGRP(paf))
8090 json_object_int_add(json_peer,
8091 "pfxSnt",
8092 (PAF_SUBGRP(paf))->scount);
8093
8094 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8095 json_object_string_add(json_peer, "state",
8096 "Idle (Admin)");
8097 else if (peer->afc_recv[afi][safi])
8098 json_object_string_add(
8099 json_peer, "state",
8100 lookup_msg(bgp_status_msg, peer->status,
8101 NULL));
8102 else if (CHECK_FLAG(peer->sflags,
8103 PEER_STATUS_PREFIX_OVERFLOW))
8104 json_object_string_add(json_peer, "state",
8105 "Idle (PfxCt)");
8106 else
8107 json_object_string_add(
8108 json_peer, "state",
8109 lookup_msg(bgp_status_msg, peer->status,
8110 NULL));
8111
8112 if (peer->conf_if)
8113 json_object_string_add(json_peer, "idType",
8114 "interface");
8115 else if (peer->su.sa.sa_family == AF_INET)
8116 json_object_string_add(json_peer, "idType",
8117 "ipv4");
8118 else if (peer->su.sa.sa_family == AF_INET6)
8119 json_object_string_add(json_peer, "idType",
8120 "ipv6");
8121
8122 json_object_object_add(json_peers, peer->host,
8123 json_peer);
8124 } else {
8125 memset(dn_flag, '\0', sizeof(dn_flag));
8126 if (peer_dynamic_neighbor(peer)) {
8127 dn_count++;
8128 dn_flag[0] = '*';
8129 }
8130
8131 if (peer->hostname
8132 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8133 len = vty_out(vty, "%s%s(%s)", dn_flag,
8134 peer->hostname, peer->host);
8135 else
8136 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8137
8138 /* pad the neighbor column with spaces */
8139 if (len < max_neighbor_width)
8140 vty_out(vty, "%*s", max_neighbor_width - len,
8141 " ");
8142
8143 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8144 peer->as, PEER_TOTAL_RX(peer),
8145 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8146 0, peer->obuf->count,
8147 peer_uptime(peer->uptime, timebuf,
8148 BGP_UPTIME_LEN, 0, NULL));
8149
8150 if (peer->status == Established)
8151 if (peer->afc_recv[afi][safi])
8152 vty_out(vty, " %12ld",
8153 peer->pcount[afi]
8154 [pfx_rcd_safi]);
8155 else
8156 vty_out(vty, " NoNeg");
8157 else {
8158 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8159 vty_out(vty, " Idle (Admin)");
8160 else if (CHECK_FLAG(
8161 peer->sflags,
8162 PEER_STATUS_PREFIX_OVERFLOW))
8163 vty_out(vty, " Idle (PfxCt)");
8164 else
8165 vty_out(vty, " %12s",
8166 lookup_msg(bgp_status_msg,
8167 peer->status, NULL));
8168 }
8169 vty_out(vty, "\n");
8170 }
8171 }
8172
8173 if (use_json) {
8174 json_object_object_add(json, "peers", json_peers);
8175
8176 json_object_int_add(json, "totalPeers", count);
8177 json_object_int_add(json, "dynamicPeers", dn_count);
8178
8179 bgp_show_bestpath_json(bgp, json);
8180
8181 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8182 json, JSON_C_TO_STRING_PRETTY));
8183 json_object_free(json);
8184 } else {
8185 if (count)
8186 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8187 else {
8188 vty_out(vty, "No %s neighbor is configured\n",
8189 afi_safi_print(afi, safi));
8190 }
8191
8192 if (dn_count) {
8193 vty_out(vty, "* - dynamic neighbor\n");
8194 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8195 dn_count, bgp->dynamic_neighbors_limit);
8196 }
8197 }
8198
8199 return CMD_SUCCESS;
8200 }
8201
8202 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8203 int safi, bool use_json,
8204 json_object *json)
8205 {
8206 int is_first = 1;
8207 int afi_wildcard = (afi == AFI_MAX);
8208 int safi_wildcard = (safi == SAFI_MAX);
8209 int is_wildcard = (afi_wildcard || safi_wildcard);
8210 bool nbr_output = false;
8211
8212 if (use_json && is_wildcard)
8213 vty_out(vty, "{\n");
8214 if (afi_wildcard)
8215 afi = 1; /* AFI_IP */
8216 while (afi < AFI_MAX) {
8217 if (safi_wildcard)
8218 safi = 1; /* SAFI_UNICAST */
8219 while (safi < SAFI_MAX) {
8220 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8221 nbr_output = true;
8222 if (is_wildcard) {
8223 /*
8224 * So limit output to those afi/safi
8225 * pairs that
8226 * actualy have something interesting in
8227 * them
8228 */
8229 if (use_json) {
8230 json = json_object_new_object();
8231
8232 if (!is_first)
8233 vty_out(vty, ",\n");
8234 else
8235 is_first = 0;
8236
8237 vty_out(vty, "\"%s\":",
8238 afi_safi_json(afi,
8239 safi));
8240 } else {
8241 vty_out(vty, "\n%s Summary:\n",
8242 afi_safi_print(afi,
8243 safi));
8244 }
8245 }
8246 bgp_show_summary(vty, bgp, afi, safi, use_json,
8247 json);
8248 }
8249 safi++;
8250 if (!safi_wildcard)
8251 safi = SAFI_MAX;
8252 }
8253 afi++;
8254 if (!afi_wildcard)
8255 afi = AFI_MAX;
8256 }
8257
8258 if (use_json && is_wildcard)
8259 vty_out(vty, "}\n");
8260 else if (!nbr_output) {
8261 if (use_json)
8262 vty_out(vty, "{}\n");
8263 else
8264 vty_out(vty, "%% No BGP neighbors found\n");
8265 }
8266 }
8267
8268 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8269 safi_t safi, bool use_json)
8270 {
8271 struct listnode *node, *nnode;
8272 struct bgp *bgp;
8273 json_object *json = NULL;
8274 int is_first = 1;
8275 bool nbr_output = false;
8276
8277 if (use_json)
8278 vty_out(vty, "{\n");
8279
8280 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8281 nbr_output = true;
8282 if (use_json) {
8283 json = json_object_new_object();
8284
8285 if (!is_first)
8286 vty_out(vty, ",\n");
8287 else
8288 is_first = 0;
8289
8290 vty_out(vty, "\"%s\":",
8291 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8292 ? VRF_DEFAULT_NAME
8293 : bgp->name);
8294 } else {
8295 vty_out(vty, "\nInstance %s:\n",
8296 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8297 ? VRF_DEFAULT_NAME
8298 : bgp->name);
8299 }
8300 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8301 }
8302
8303 if (use_json)
8304 vty_out(vty, "}\n");
8305 else if (!nbr_output)
8306 vty_out(vty, "%% BGP instance not found\n");
8307 }
8308
8309 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8310 safi_t safi, bool use_json)
8311 {
8312 struct bgp *bgp;
8313
8314 if (name) {
8315 if (strmatch(name, "all")) {
8316 bgp_show_all_instances_summary_vty(vty, afi, safi,
8317 use_json);
8318 return CMD_SUCCESS;
8319 } else {
8320 bgp = bgp_lookup_by_name(name);
8321
8322 if (!bgp) {
8323 if (use_json)
8324 vty_out(vty, "{}\n");
8325 else
8326 vty_out(vty,
8327 "%% BGP instance not found\n");
8328 return CMD_WARNING;
8329 }
8330
8331 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8332 NULL);
8333 return CMD_SUCCESS;
8334 }
8335 }
8336
8337 bgp = bgp_get_default();
8338
8339 if (bgp)
8340 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8341 else {
8342 if (use_json)
8343 vty_out(vty, "{}\n");
8344 else
8345 vty_out(vty, "%% BGP instance not found\n");
8346 return CMD_WARNING;
8347 }
8348
8349 return CMD_SUCCESS;
8350 }
8351
8352 /* `show [ip] bgp summary' commands. */
8353 DEFUN (show_ip_bgp_summary,
8354 show_ip_bgp_summary_cmd,
8355 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8356 SHOW_STR
8357 IP_STR
8358 BGP_STR
8359 BGP_INSTANCE_HELP_STR
8360 BGP_AFI_HELP_STR
8361 BGP_SAFI_WITH_LABEL_HELP_STR
8362 "Summary of BGP neighbor status\n"
8363 JSON_STR)
8364 {
8365 char *vrf = NULL;
8366 afi_t afi = AFI_MAX;
8367 safi_t safi = SAFI_MAX;
8368
8369 int idx = 0;
8370
8371 /* show [ip] bgp */
8372 if (argv_find(argv, argc, "ip", &idx))
8373 afi = AFI_IP;
8374 /* [<vrf> VIEWVRFNAME] */
8375 if (argv_find(argv, argc, "vrf", &idx)) {
8376 vrf = argv[idx + 1]->arg;
8377 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8378 vrf = NULL;
8379 } else if (argv_find(argv, argc, "view", &idx))
8380 /* [<view> VIEWVRFNAME] */
8381 vrf = argv[idx + 1]->arg;
8382 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8383 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8384 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8385 }
8386
8387 bool uj = use_json(argc, argv);
8388
8389 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8390 }
8391
8392 const char *afi_safi_print(afi_t afi, safi_t safi)
8393 {
8394 if (afi == AFI_IP && safi == SAFI_UNICAST)
8395 return "IPv4 Unicast";
8396 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8397 return "IPv4 Multicast";
8398 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8399 return "IPv4 Labeled Unicast";
8400 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8401 return "IPv4 VPN";
8402 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8403 return "IPv4 Encap";
8404 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8405 return "IPv4 Flowspec";
8406 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8407 return "IPv6 Unicast";
8408 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8409 return "IPv6 Multicast";
8410 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8411 return "IPv6 Labeled Unicast";
8412 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8413 return "IPv6 VPN";
8414 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8415 return "IPv6 Encap";
8416 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8417 return "IPv6 Flowspec";
8418 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8419 return "L2VPN EVPN";
8420 else
8421 return "Unknown";
8422 }
8423
8424 /*
8425 * Please note that we have intentionally camelCased
8426 * the return strings here. So if you want
8427 * to use this function, please ensure you
8428 * are doing this within json output
8429 */
8430 const char *afi_safi_json(afi_t afi, safi_t safi)
8431 {
8432 if (afi == AFI_IP && safi == SAFI_UNICAST)
8433 return "ipv4Unicast";
8434 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8435 return "ipv4Multicast";
8436 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8437 return "ipv4LabeledUnicast";
8438 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8439 return "ipv4Vpn";
8440 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8441 return "ipv4Encap";
8442 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8443 return "ipv4Flowspec";
8444 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8445 return "ipv6Unicast";
8446 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8447 return "ipv6Multicast";
8448 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8449 return "ipv6LabeledUnicast";
8450 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8451 return "ipv6Vpn";
8452 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8453 return "ipv6Encap";
8454 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8455 return "ipv6Flowspec";
8456 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8457 return "l2VpnEvpn";
8458 else
8459 return "Unknown";
8460 }
8461
8462 /* Show BGP peer's information. */
8463 enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
8464
8465 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8466 afi_t afi, safi_t safi,
8467 uint16_t adv_smcap, uint16_t adv_rmcap,
8468 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8469 bool use_json, json_object *json_pref)
8470 {
8471 /* Send-Mode */
8472 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8473 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8474 if (use_json) {
8475 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8476 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8477 json_object_string_add(json_pref, "sendMode",
8478 "advertisedAndReceived");
8479 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8480 json_object_string_add(json_pref, "sendMode",
8481 "advertised");
8482 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8483 json_object_string_add(json_pref, "sendMode",
8484 "received");
8485 } else {
8486 vty_out(vty, " Send-mode: ");
8487 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8488 vty_out(vty, "advertised");
8489 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8490 vty_out(vty, "%sreceived",
8491 CHECK_FLAG(p->af_cap[afi][safi],
8492 adv_smcap)
8493 ? ", "
8494 : "");
8495 vty_out(vty, "\n");
8496 }
8497 }
8498
8499 /* Receive-Mode */
8500 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8501 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8502 if (use_json) {
8503 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8504 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8505 json_object_string_add(json_pref, "recvMode",
8506 "advertisedAndReceived");
8507 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8508 json_object_string_add(json_pref, "recvMode",
8509 "advertised");
8510 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8511 json_object_string_add(json_pref, "recvMode",
8512 "received");
8513 } else {
8514 vty_out(vty, " Receive-mode: ");
8515 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8516 vty_out(vty, "advertised");
8517 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8518 vty_out(vty, "%sreceived",
8519 CHECK_FLAG(p->af_cap[afi][safi],
8520 adv_rmcap)
8521 ? ", "
8522 : "");
8523 vty_out(vty, "\n");
8524 }
8525 }
8526 }
8527
8528 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8529 safi_t safi, bool use_json,
8530 json_object *json_neigh)
8531 {
8532 struct bgp_filter *filter;
8533 struct peer_af *paf;
8534 char orf_pfx_name[BUFSIZ];
8535 int orf_pfx_count;
8536 json_object *json_af = NULL;
8537 json_object *json_prefA = NULL;
8538 json_object *json_prefB = NULL;
8539 json_object *json_addr = NULL;
8540
8541 if (use_json) {
8542 json_addr = json_object_new_object();
8543 json_af = json_object_new_object();
8544 filter = &p->filter[afi][safi];
8545
8546 if (peer_group_active(p))
8547 json_object_string_add(json_addr, "peerGroupMember",
8548 p->group->name);
8549
8550 paf = peer_af_find(p, afi, safi);
8551 if (paf && PAF_SUBGRP(paf)) {
8552 json_object_int_add(json_addr, "updateGroupId",
8553 PAF_UPDGRP(paf)->id);
8554 json_object_int_add(json_addr, "subGroupId",
8555 PAF_SUBGRP(paf)->id);
8556 json_object_int_add(json_addr, "packetQueueLength",
8557 bpacket_queue_virtual_length(paf));
8558 }
8559
8560 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8561 || CHECK_FLAG(p->af_cap[afi][safi],
8562 PEER_CAP_ORF_PREFIX_SM_RCV)
8563 || CHECK_FLAG(p->af_cap[afi][safi],
8564 PEER_CAP_ORF_PREFIX_RM_ADV)
8565 || CHECK_FLAG(p->af_cap[afi][safi],
8566 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8567 json_object_int_add(json_af, "orfType",
8568 ORF_TYPE_PREFIX);
8569 json_prefA = json_object_new_object();
8570 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8571 PEER_CAP_ORF_PREFIX_SM_ADV,
8572 PEER_CAP_ORF_PREFIX_RM_ADV,
8573 PEER_CAP_ORF_PREFIX_SM_RCV,
8574 PEER_CAP_ORF_PREFIX_RM_RCV,
8575 use_json, json_prefA);
8576 json_object_object_add(json_af, "orfPrefixList",
8577 json_prefA);
8578 }
8579
8580 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8581 || CHECK_FLAG(p->af_cap[afi][safi],
8582 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8583 || CHECK_FLAG(p->af_cap[afi][safi],
8584 PEER_CAP_ORF_PREFIX_RM_ADV)
8585 || CHECK_FLAG(p->af_cap[afi][safi],
8586 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8587 json_object_int_add(json_af, "orfOldType",
8588 ORF_TYPE_PREFIX_OLD);
8589 json_prefB = json_object_new_object();
8590 bgp_show_peer_afi_orf_cap(
8591 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8592 PEER_CAP_ORF_PREFIX_RM_ADV,
8593 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8594 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8595 json_prefB);
8596 json_object_object_add(json_af, "orfOldPrefixList",
8597 json_prefB);
8598 }
8599
8600 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8601 || CHECK_FLAG(p->af_cap[afi][safi],
8602 PEER_CAP_ORF_PREFIX_SM_RCV)
8603 || CHECK_FLAG(p->af_cap[afi][safi],
8604 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8605 || CHECK_FLAG(p->af_cap[afi][safi],
8606 PEER_CAP_ORF_PREFIX_RM_ADV)
8607 || CHECK_FLAG(p->af_cap[afi][safi],
8608 PEER_CAP_ORF_PREFIX_RM_RCV)
8609 || CHECK_FLAG(p->af_cap[afi][safi],
8610 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8611 json_object_object_add(json_addr, "afDependentCap",
8612 json_af);
8613 else
8614 json_object_free(json_af);
8615
8616 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8617 orf_pfx_count = prefix_bgp_show_prefix_list(
8618 NULL, afi, orf_pfx_name, use_json);
8619
8620 if (CHECK_FLAG(p->af_sflags[afi][safi],
8621 PEER_STATUS_ORF_PREFIX_SEND)
8622 || orf_pfx_count) {
8623 if (CHECK_FLAG(p->af_sflags[afi][safi],
8624 PEER_STATUS_ORF_PREFIX_SEND))
8625 json_object_boolean_true_add(json_neigh,
8626 "orfSent");
8627 if (orf_pfx_count)
8628 json_object_int_add(json_addr, "orfRecvCounter",
8629 orf_pfx_count);
8630 }
8631 if (CHECK_FLAG(p->af_sflags[afi][safi],
8632 PEER_STATUS_ORF_WAIT_REFRESH))
8633 json_object_string_add(
8634 json_addr, "orfFirstUpdate",
8635 "deferredUntilORFOrRouteRefreshRecvd");
8636
8637 if (CHECK_FLAG(p->af_flags[afi][safi],
8638 PEER_FLAG_REFLECTOR_CLIENT))
8639 json_object_boolean_true_add(json_addr,
8640 "routeReflectorClient");
8641 if (CHECK_FLAG(p->af_flags[afi][safi],
8642 PEER_FLAG_RSERVER_CLIENT))
8643 json_object_boolean_true_add(json_addr,
8644 "routeServerClient");
8645 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8646 json_object_boolean_true_add(json_addr,
8647 "inboundSoftConfigPermit");
8648
8649 if (CHECK_FLAG(p->af_flags[afi][safi],
8650 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8651 json_object_boolean_true_add(
8652 json_addr,
8653 "privateAsNumsAllReplacedInUpdatesToNbr");
8654 else if (CHECK_FLAG(p->af_flags[afi][safi],
8655 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8656 json_object_boolean_true_add(
8657 json_addr,
8658 "privateAsNumsReplacedInUpdatesToNbr");
8659 else if (CHECK_FLAG(p->af_flags[afi][safi],
8660 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8661 json_object_boolean_true_add(
8662 json_addr,
8663 "privateAsNumsAllRemovedInUpdatesToNbr");
8664 else if (CHECK_FLAG(p->af_flags[afi][safi],
8665 PEER_FLAG_REMOVE_PRIVATE_AS))
8666 json_object_boolean_true_add(
8667 json_addr,
8668 "privateAsNumsRemovedInUpdatesToNbr");
8669
8670 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8671 json_object_boolean_true_add(
8672 json_addr,
8673 bgp_addpath_names(p->addpath_type[afi][safi])
8674 ->type_json_name);
8675
8676 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8677 json_object_string_add(json_addr,
8678 "overrideASNsInOutboundUpdates",
8679 "ifAspathEqualRemoteAs");
8680
8681 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8682 || CHECK_FLAG(p->af_flags[afi][safi],
8683 PEER_FLAG_FORCE_NEXTHOP_SELF))
8684 json_object_boolean_true_add(json_addr,
8685 "routerAlwaysNextHop");
8686 if (CHECK_FLAG(p->af_flags[afi][safi],
8687 PEER_FLAG_AS_PATH_UNCHANGED))
8688 json_object_boolean_true_add(
8689 json_addr, "unchangedAsPathPropogatedToNbr");
8690 if (CHECK_FLAG(p->af_flags[afi][safi],
8691 PEER_FLAG_NEXTHOP_UNCHANGED))
8692 json_object_boolean_true_add(
8693 json_addr, "unchangedNextHopPropogatedToNbr");
8694 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8695 json_object_boolean_true_add(
8696 json_addr, "unchangedMedPropogatedToNbr");
8697 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8698 || CHECK_FLAG(p->af_flags[afi][safi],
8699 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8700 if (CHECK_FLAG(p->af_flags[afi][safi],
8701 PEER_FLAG_SEND_COMMUNITY)
8702 && CHECK_FLAG(p->af_flags[afi][safi],
8703 PEER_FLAG_SEND_EXT_COMMUNITY))
8704 json_object_string_add(json_addr,
8705 "commAttriSentToNbr",
8706 "extendedAndStandard");
8707 else if (CHECK_FLAG(p->af_flags[afi][safi],
8708 PEER_FLAG_SEND_EXT_COMMUNITY))
8709 json_object_string_add(json_addr,
8710 "commAttriSentToNbr",
8711 "extended");
8712 else
8713 json_object_string_add(json_addr,
8714 "commAttriSentToNbr",
8715 "standard");
8716 }
8717 if (CHECK_FLAG(p->af_flags[afi][safi],
8718 PEER_FLAG_DEFAULT_ORIGINATE)) {
8719 if (p->default_rmap[afi][safi].name)
8720 json_object_string_add(
8721 json_addr, "defaultRouteMap",
8722 p->default_rmap[afi][safi].name);
8723
8724 if (paf && PAF_SUBGRP(paf)
8725 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8726 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8727 json_object_boolean_true_add(json_addr,
8728 "defaultSent");
8729 else
8730 json_object_boolean_true_add(json_addr,
8731 "defaultNotSent");
8732 }
8733
8734 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8735 if (is_evpn_enabled())
8736 json_object_boolean_true_add(
8737 json_addr, "advertiseAllVnis");
8738 }
8739
8740 if (filter->plist[FILTER_IN].name
8741 || filter->dlist[FILTER_IN].name
8742 || filter->aslist[FILTER_IN].name
8743 || filter->map[RMAP_IN].name)
8744 json_object_boolean_true_add(json_addr,
8745 "inboundPathPolicyConfig");
8746 if (filter->plist[FILTER_OUT].name
8747 || filter->dlist[FILTER_OUT].name
8748 || filter->aslist[FILTER_OUT].name
8749 || filter->map[RMAP_OUT].name || filter->usmap.name)
8750 json_object_boolean_true_add(
8751 json_addr, "outboundPathPolicyConfig");
8752
8753 /* prefix-list */
8754 if (filter->plist[FILTER_IN].name)
8755 json_object_string_add(json_addr,
8756 "incomingUpdatePrefixFilterList",
8757 filter->plist[FILTER_IN].name);
8758 if (filter->plist[FILTER_OUT].name)
8759 json_object_string_add(json_addr,
8760 "outgoingUpdatePrefixFilterList",
8761 filter->plist[FILTER_OUT].name);
8762
8763 /* distribute-list */
8764 if (filter->dlist[FILTER_IN].name)
8765 json_object_string_add(
8766 json_addr, "incomingUpdateNetworkFilterList",
8767 filter->dlist[FILTER_IN].name);
8768 if (filter->dlist[FILTER_OUT].name)
8769 json_object_string_add(
8770 json_addr, "outgoingUpdateNetworkFilterList",
8771 filter->dlist[FILTER_OUT].name);
8772
8773 /* filter-list. */
8774 if (filter->aslist[FILTER_IN].name)
8775 json_object_string_add(json_addr,
8776 "incomingUpdateAsPathFilterList",
8777 filter->aslist[FILTER_IN].name);
8778 if (filter->aslist[FILTER_OUT].name)
8779 json_object_string_add(json_addr,
8780 "outgoingUpdateAsPathFilterList",
8781 filter->aslist[FILTER_OUT].name);
8782
8783 /* route-map. */
8784 if (filter->map[RMAP_IN].name)
8785 json_object_string_add(
8786 json_addr, "routeMapForIncomingAdvertisements",
8787 filter->map[RMAP_IN].name);
8788 if (filter->map[RMAP_OUT].name)
8789 json_object_string_add(
8790 json_addr, "routeMapForOutgoingAdvertisements",
8791 filter->map[RMAP_OUT].name);
8792
8793 /* ebgp-requires-policy (inbound) */
8794 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8795 && !bgp_inbound_policy_exists(p, filter))
8796 json_object_string_add(
8797 json_addr, "inboundEbgpRequiresPolicy",
8798 "Inbound updates discarded due to missing policy");
8799
8800 /* ebgp-requires-policy (outbound) */
8801 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8802 && (!bgp_outbound_policy_exists(p, filter)))
8803 json_object_string_add(
8804 json_addr, "outboundEbgpRequiresPolicy",
8805 "Outbound updates discarded due to missing policy");
8806
8807 /* unsuppress-map */
8808 if (filter->usmap.name)
8809 json_object_string_add(json_addr,
8810 "selectiveUnsuppressRouteMap",
8811 filter->usmap.name);
8812
8813 /* Receive prefix count */
8814 json_object_int_add(json_addr, "acceptedPrefixCounter",
8815 p->pcount[afi][safi]);
8816 if (paf && PAF_SUBGRP(paf))
8817 json_object_int_add(json_addr, "sentPrefixCounter",
8818 (PAF_SUBGRP(paf))->scount);
8819
8820 /* Maximum prefix */
8821 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8822 json_object_int_add(json_addr, "prefixAllowedMax",
8823 p->pmax[afi][safi]);
8824 if (CHECK_FLAG(p->af_flags[afi][safi],
8825 PEER_FLAG_MAX_PREFIX_WARNING))
8826 json_object_boolean_true_add(
8827 json_addr, "prefixAllowedMaxWarning");
8828 json_object_int_add(json_addr,
8829 "prefixAllowedWarningThresh",
8830 p->pmax_threshold[afi][safi]);
8831 if (p->pmax_restart[afi][safi])
8832 json_object_int_add(
8833 json_addr,
8834 "prefixAllowedRestartIntervalMsecs",
8835 p->pmax_restart[afi][safi] * 60000);
8836 }
8837 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8838 json_addr);
8839
8840 } else {
8841 filter = &p->filter[afi][safi];
8842
8843 vty_out(vty, " For address family: %s\n",
8844 afi_safi_print(afi, safi));
8845
8846 if (peer_group_active(p))
8847 vty_out(vty, " %s peer-group member\n",
8848 p->group->name);
8849
8850 paf = peer_af_find(p, afi, safi);
8851 if (paf && PAF_SUBGRP(paf)) {
8852 vty_out(vty, " Update group %" PRIu64
8853 ", subgroup %" PRIu64 "\n",
8854 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8855 vty_out(vty, " Packet Queue length %d\n",
8856 bpacket_queue_virtual_length(paf));
8857 } else {
8858 vty_out(vty, " Not part of any update group\n");
8859 }
8860 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8861 || CHECK_FLAG(p->af_cap[afi][safi],
8862 PEER_CAP_ORF_PREFIX_SM_RCV)
8863 || CHECK_FLAG(p->af_cap[afi][safi],
8864 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8865 || CHECK_FLAG(p->af_cap[afi][safi],
8866 PEER_CAP_ORF_PREFIX_RM_ADV)
8867 || CHECK_FLAG(p->af_cap[afi][safi],
8868 PEER_CAP_ORF_PREFIX_RM_RCV)
8869 || CHECK_FLAG(p->af_cap[afi][safi],
8870 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8871 vty_out(vty, " AF-dependant capabilities:\n");
8872
8873 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8874 || CHECK_FLAG(p->af_cap[afi][safi],
8875 PEER_CAP_ORF_PREFIX_SM_RCV)
8876 || CHECK_FLAG(p->af_cap[afi][safi],
8877 PEER_CAP_ORF_PREFIX_RM_ADV)
8878 || CHECK_FLAG(p->af_cap[afi][safi],
8879 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8880 vty_out(vty,
8881 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8882 ORF_TYPE_PREFIX);
8883 bgp_show_peer_afi_orf_cap(
8884 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8885 PEER_CAP_ORF_PREFIX_RM_ADV,
8886 PEER_CAP_ORF_PREFIX_SM_RCV,
8887 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8888 }
8889 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8890 || CHECK_FLAG(p->af_cap[afi][safi],
8891 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8892 || CHECK_FLAG(p->af_cap[afi][safi],
8893 PEER_CAP_ORF_PREFIX_RM_ADV)
8894 || CHECK_FLAG(p->af_cap[afi][safi],
8895 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8896 vty_out(vty,
8897 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8898 ORF_TYPE_PREFIX_OLD);
8899 bgp_show_peer_afi_orf_cap(
8900 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8901 PEER_CAP_ORF_PREFIX_RM_ADV,
8902 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8903 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8904 }
8905
8906 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8907 orf_pfx_count = prefix_bgp_show_prefix_list(
8908 NULL, afi, orf_pfx_name, use_json);
8909
8910 if (CHECK_FLAG(p->af_sflags[afi][safi],
8911 PEER_STATUS_ORF_PREFIX_SEND)
8912 || orf_pfx_count) {
8913 vty_out(vty, " Outbound Route Filter (ORF):");
8914 if (CHECK_FLAG(p->af_sflags[afi][safi],
8915 PEER_STATUS_ORF_PREFIX_SEND))
8916 vty_out(vty, " sent;");
8917 if (orf_pfx_count)
8918 vty_out(vty, " received (%d entries)",
8919 orf_pfx_count);
8920 vty_out(vty, "\n");
8921 }
8922 if (CHECK_FLAG(p->af_sflags[afi][safi],
8923 PEER_STATUS_ORF_WAIT_REFRESH))
8924 vty_out(vty,
8925 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8926
8927 if (CHECK_FLAG(p->af_flags[afi][safi],
8928 PEER_FLAG_REFLECTOR_CLIENT))
8929 vty_out(vty, " Route-Reflector Client\n");
8930 if (CHECK_FLAG(p->af_flags[afi][safi],
8931 PEER_FLAG_RSERVER_CLIENT))
8932 vty_out(vty, " Route-Server Client\n");
8933 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8934 vty_out(vty,
8935 " Inbound soft reconfiguration allowed\n");
8936
8937 if (CHECK_FLAG(p->af_flags[afi][safi],
8938 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8939 vty_out(vty,
8940 " Private AS numbers (all) replaced in updates to this neighbor\n");
8941 else if (CHECK_FLAG(p->af_flags[afi][safi],
8942 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8943 vty_out(vty,
8944 " Private AS numbers replaced in updates to this neighbor\n");
8945 else if (CHECK_FLAG(p->af_flags[afi][safi],
8946 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8947 vty_out(vty,
8948 " Private AS numbers (all) removed in updates to this neighbor\n");
8949 else if (CHECK_FLAG(p->af_flags[afi][safi],
8950 PEER_FLAG_REMOVE_PRIVATE_AS))
8951 vty_out(vty,
8952 " Private AS numbers removed in updates to this neighbor\n");
8953
8954 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8955 vty_out(vty, " %s\n",
8956 bgp_addpath_names(p->addpath_type[afi][safi])
8957 ->human_description);
8958
8959 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8960 vty_out(vty,
8961 " Override ASNs in outbound updates if aspath equals remote-as\n");
8962
8963 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8964 || CHECK_FLAG(p->af_flags[afi][safi],
8965 PEER_FLAG_FORCE_NEXTHOP_SELF))
8966 vty_out(vty, " NEXT_HOP is always this router\n");
8967 if (CHECK_FLAG(p->af_flags[afi][safi],
8968 PEER_FLAG_AS_PATH_UNCHANGED))
8969 vty_out(vty,
8970 " AS_PATH is propagated unchanged to this neighbor\n");
8971 if (CHECK_FLAG(p->af_flags[afi][safi],
8972 PEER_FLAG_NEXTHOP_UNCHANGED))
8973 vty_out(vty,
8974 " NEXT_HOP is propagated unchanged to this neighbor\n");
8975 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8976 vty_out(vty,
8977 " MED is propagated unchanged to this neighbor\n");
8978 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8979 || CHECK_FLAG(p->af_flags[afi][safi],
8980 PEER_FLAG_SEND_EXT_COMMUNITY)
8981 || CHECK_FLAG(p->af_flags[afi][safi],
8982 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8983 vty_out(vty,
8984 " Community attribute sent to this neighbor");
8985 if (CHECK_FLAG(p->af_flags[afi][safi],
8986 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, "(all)\n");
8992 else if (CHECK_FLAG(p->af_flags[afi][safi],
8993 PEER_FLAG_SEND_LARGE_COMMUNITY))
8994 vty_out(vty, "(large)\n");
8995 else if (CHECK_FLAG(p->af_flags[afi][safi],
8996 PEER_FLAG_SEND_EXT_COMMUNITY))
8997 vty_out(vty, "(extended)\n");
8998 else
8999 vty_out(vty, "(standard)\n");
9000 }
9001 if (CHECK_FLAG(p->af_flags[afi][safi],
9002 PEER_FLAG_DEFAULT_ORIGINATE)) {
9003 vty_out(vty, " Default information originate,");
9004
9005 if (p->default_rmap[afi][safi].name)
9006 vty_out(vty, " default route-map %s%s,",
9007 p->default_rmap[afi][safi].map ? "*"
9008 : "",
9009 p->default_rmap[afi][safi].name);
9010 if (paf && PAF_SUBGRP(paf)
9011 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9012 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9013 vty_out(vty, " default sent\n");
9014 else
9015 vty_out(vty, " default not sent\n");
9016 }
9017
9018 /* advertise-vni-all */
9019 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9020 if (is_evpn_enabled())
9021 vty_out(vty, " advertise-all-vni\n");
9022 }
9023
9024 if (filter->plist[FILTER_IN].name
9025 || filter->dlist[FILTER_IN].name
9026 || filter->aslist[FILTER_IN].name
9027 || filter->map[RMAP_IN].name)
9028 vty_out(vty, " Inbound path policy configured\n");
9029 if (filter->plist[FILTER_OUT].name
9030 || filter->dlist[FILTER_OUT].name
9031 || filter->aslist[FILTER_OUT].name
9032 || filter->map[RMAP_OUT].name || filter->usmap.name)
9033 vty_out(vty, " Outbound path policy configured\n");
9034
9035 /* prefix-list */
9036 if (filter->plist[FILTER_IN].name)
9037 vty_out(vty,
9038 " Incoming update prefix filter list is %s%s\n",
9039 filter->plist[FILTER_IN].plist ? "*" : "",
9040 filter->plist[FILTER_IN].name);
9041 if (filter->plist[FILTER_OUT].name)
9042 vty_out(vty,
9043 " Outgoing update prefix filter list is %s%s\n",
9044 filter->plist[FILTER_OUT].plist ? "*" : "",
9045 filter->plist[FILTER_OUT].name);
9046
9047 /* distribute-list */
9048 if (filter->dlist[FILTER_IN].name)
9049 vty_out(vty,
9050 " Incoming update network filter list is %s%s\n",
9051 filter->dlist[FILTER_IN].alist ? "*" : "",
9052 filter->dlist[FILTER_IN].name);
9053 if (filter->dlist[FILTER_OUT].name)
9054 vty_out(vty,
9055 " Outgoing update network filter list is %s%s\n",
9056 filter->dlist[FILTER_OUT].alist ? "*" : "",
9057 filter->dlist[FILTER_OUT].name);
9058
9059 /* filter-list. */
9060 if (filter->aslist[FILTER_IN].name)
9061 vty_out(vty,
9062 " Incoming update AS path filter list is %s%s\n",
9063 filter->aslist[FILTER_IN].aslist ? "*" : "",
9064 filter->aslist[FILTER_IN].name);
9065 if (filter->aslist[FILTER_OUT].name)
9066 vty_out(vty,
9067 " Outgoing update AS path filter list is %s%s\n",
9068 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9069 filter->aslist[FILTER_OUT].name);
9070
9071 /* route-map. */
9072 if (filter->map[RMAP_IN].name)
9073 vty_out(vty,
9074 " Route map for incoming advertisements is %s%s\n",
9075 filter->map[RMAP_IN].map ? "*" : "",
9076 filter->map[RMAP_IN].name);
9077 if (filter->map[RMAP_OUT].name)
9078 vty_out(vty,
9079 " Route map for outgoing advertisements is %s%s\n",
9080 filter->map[RMAP_OUT].map ? "*" : "",
9081 filter->map[RMAP_OUT].name);
9082
9083 /* ebgp-requires-policy (inbound) */
9084 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9085 && !bgp_inbound_policy_exists(p, filter))
9086 vty_out(vty,
9087 " Inbound updates discarded due to missing policy\n");
9088
9089 /* ebgp-requires-policy (outbound) */
9090 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9091 && !bgp_outbound_policy_exists(p, filter))
9092 vty_out(vty,
9093 " Outbound updates discarded due to missing policy\n");
9094
9095 /* unsuppress-map */
9096 if (filter->usmap.name)
9097 vty_out(vty,
9098 " Route map for selective unsuppress is %s%s\n",
9099 filter->usmap.map ? "*" : "",
9100 filter->usmap.name);
9101
9102 /* Receive prefix count */
9103 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9104
9105 /* Maximum prefix */
9106 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9107 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9108 p->pmax[afi][safi],
9109 CHECK_FLAG(p->af_flags[afi][safi],
9110 PEER_FLAG_MAX_PREFIX_WARNING)
9111 ? " (warning-only)"
9112 : "");
9113 vty_out(vty, " Threshold for warning message %d%%",
9114 p->pmax_threshold[afi][safi]);
9115 if (p->pmax_restart[afi][safi])
9116 vty_out(vty, ", restart interval %d min",
9117 p->pmax_restart[afi][safi]);
9118 vty_out(vty, "\n");
9119 }
9120
9121 vty_out(vty, "\n");
9122 }
9123 }
9124
9125 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9126 json_object *json)
9127 {
9128 struct bgp *bgp;
9129 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9130 char timebuf[BGP_UPTIME_LEN];
9131 char dn_flag[2];
9132 const char *subcode_str;
9133 const char *code_str;
9134 afi_t afi;
9135 safi_t safi;
9136 uint16_t i;
9137 uint8_t *msg;
9138 json_object *json_neigh = NULL;
9139 time_t epoch_tbuf;
9140
9141 bgp = p->bgp;
9142
9143 if (use_json)
9144 json_neigh = json_object_new_object();
9145
9146 memset(dn_flag, '\0', sizeof(dn_flag));
9147 if (!p->conf_if && peer_dynamic_neighbor(p))
9148 dn_flag[0] = '*';
9149
9150 if (!use_json) {
9151 if (p->conf_if) /* Configured interface name. */
9152 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9153 BGP_PEER_SU_UNSPEC(p)
9154 ? "None"
9155 : sockunion2str(&p->su, buf,
9156 SU_ADDRSTRLEN));
9157 else /* Configured IP address. */
9158 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9159 p->host);
9160 }
9161
9162 if (use_json) {
9163 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9164 json_object_string_add(json_neigh, "bgpNeighborAddr",
9165 "none");
9166 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9167 json_object_string_add(
9168 json_neigh, "bgpNeighborAddr",
9169 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9170
9171 json_object_int_add(json_neigh, "remoteAs", p->as);
9172
9173 if (p->change_local_as)
9174 json_object_int_add(json_neigh, "localAs",
9175 p->change_local_as);
9176 else
9177 json_object_int_add(json_neigh, "localAs", p->local_as);
9178
9179 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9180 json_object_boolean_true_add(json_neigh,
9181 "localAsNoPrepend");
9182
9183 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9184 json_object_boolean_true_add(json_neigh,
9185 "localAsReplaceAs");
9186 } else {
9187 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9188 || (p->as_type == AS_INTERNAL))
9189 vty_out(vty, "remote AS %u, ", p->as);
9190 else
9191 vty_out(vty, "remote AS Unspecified, ");
9192 vty_out(vty, "local AS %u%s%s, ",
9193 p->change_local_as ? p->change_local_as : p->local_as,
9194 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9195 ? " no-prepend"
9196 : "",
9197 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9198 ? " replace-as"
9199 : "");
9200 }
9201 /* peer type internal or confed-internal */
9202 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9203 if (use_json) {
9204 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9205 json_object_boolean_true_add(
9206 json_neigh, "nbrConfedInternalLink");
9207 else
9208 json_object_boolean_true_add(json_neigh,
9209 "nbrInternalLink");
9210 } else {
9211 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9212 vty_out(vty, "confed-internal link\n");
9213 else
9214 vty_out(vty, "internal link\n");
9215 }
9216 /* peer type external or confed-external */
9217 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9218 if (use_json) {
9219 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9220 json_object_boolean_true_add(
9221 json_neigh, "nbrConfedExternalLink");
9222 else
9223 json_object_boolean_true_add(json_neigh,
9224 "nbrExternalLink");
9225 } else {
9226 if (bgp_confederation_peers_check(bgp, p->as))
9227 vty_out(vty, "confed-external link\n");
9228 else
9229 vty_out(vty, "external link\n");
9230 }
9231 } else {
9232 if (use_json)
9233 json_object_boolean_true_add(json_neigh,
9234 "nbrUnspecifiedLink");
9235 else
9236 vty_out(vty, "unspecified link\n");
9237 }
9238
9239 /* Description. */
9240 if (p->desc) {
9241 if (use_json)
9242 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9243 else
9244 vty_out(vty, " Description: %s\n", p->desc);
9245 }
9246
9247 if (p->hostname) {
9248 if (use_json) {
9249 if (p->hostname)
9250 json_object_string_add(json_neigh, "hostname",
9251 p->hostname);
9252
9253 if (p->domainname)
9254 json_object_string_add(json_neigh, "domainname",
9255 p->domainname);
9256 } else {
9257 if (p->domainname && (p->domainname[0] != '\0'))
9258 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9259 p->domainname);
9260 else
9261 vty_out(vty, "Hostname: %s\n", p->hostname);
9262 }
9263 }
9264
9265 /* Peer-group */
9266 if (p->group) {
9267 if (use_json) {
9268 json_object_string_add(json_neigh, "peerGroup",
9269 p->group->name);
9270
9271 if (dn_flag[0]) {
9272 struct prefix prefix, *range = NULL;
9273
9274 sockunion2hostprefix(&(p->su), &prefix);
9275 range = peer_group_lookup_dynamic_neighbor_range(
9276 p->group, &prefix);
9277
9278 if (range) {
9279 prefix2str(range, buf1, sizeof(buf1));
9280 json_object_string_add(
9281 json_neigh,
9282 "peerSubnetRangeGroup", buf1);
9283 }
9284 }
9285 } else {
9286 vty_out(vty,
9287 " Member of peer-group %s for session parameters\n",
9288 p->group->name);
9289
9290 if (dn_flag[0]) {
9291 struct prefix prefix, *range = NULL;
9292
9293 sockunion2hostprefix(&(p->su), &prefix);
9294 range = peer_group_lookup_dynamic_neighbor_range(
9295 p->group, &prefix);
9296
9297 if (range) {
9298 prefix2str(range, buf1, sizeof(buf1));
9299 vty_out(vty,
9300 " Belongs to the subnet range group: %s\n",
9301 buf1);
9302 }
9303 }
9304 }
9305 }
9306
9307 if (use_json) {
9308 /* Administrative shutdown. */
9309 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9310 json_object_boolean_true_add(json_neigh,
9311 "adminShutDown");
9312
9313 /* BGP Version. */
9314 json_object_int_add(json_neigh, "bgpVersion", 4);
9315 json_object_string_add(
9316 json_neigh, "remoteRouterId",
9317 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9318 json_object_string_add(
9319 json_neigh, "localRouterId",
9320 inet_ntop(AF_INET, &bgp->router_id, buf1,
9321 sizeof(buf1)));
9322
9323 /* Confederation */
9324 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9325 && bgp_confederation_peers_check(bgp, p->as))
9326 json_object_boolean_true_add(json_neigh,
9327 "nbrCommonAdmin");
9328
9329 /* Status. */
9330 json_object_string_add(
9331 json_neigh, "bgpState",
9332 lookup_msg(bgp_status_msg, p->status, NULL));
9333
9334 if (p->status == Established) {
9335 time_t uptime;
9336
9337 uptime = bgp_clock();
9338 uptime -= p->uptime;
9339 epoch_tbuf = time(NULL) - uptime;
9340
9341 #if CONFDATE > 20200101
9342 CPP_NOTICE(
9343 "bgpTimerUp should be deprecated and can be removed now");
9344 #endif
9345 /*
9346 * bgpTimerUp was miliseconds that was accurate
9347 * up to 1 day, then the value returned
9348 * became garbage. So in order to provide
9349 * some level of backwards compatability,
9350 * we still provde the data, but now
9351 * we are returning the correct value
9352 * and also adding a new bgpTimerUpMsec
9353 * which will allow us to deprecate
9354 * this eventually
9355 */
9356 json_object_int_add(json_neigh, "bgpTimerUp",
9357 uptime * 1000);
9358 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9359 uptime * 1000);
9360 json_object_string_add(json_neigh, "bgpTimerUpString",
9361 peer_uptime(p->uptime, timebuf,
9362 BGP_UPTIME_LEN, 0,
9363 NULL));
9364 json_object_int_add(json_neigh,
9365 "bgpTimerUpEstablishedEpoch",
9366 epoch_tbuf);
9367 }
9368
9369 else if (p->status == Active) {
9370 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9371 json_object_string_add(json_neigh, "bgpStateIs",
9372 "passive");
9373 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9374 json_object_string_add(json_neigh, "bgpStateIs",
9375 "passiveNSF");
9376 }
9377
9378 /* read timer */
9379 time_t uptime;
9380 struct tm *tm;
9381
9382 uptime = bgp_clock();
9383 uptime -= p->readtime;
9384 tm = gmtime(&uptime);
9385 json_object_int_add(json_neigh, "bgpTimerLastRead",
9386 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9387 + (tm->tm_hour * 3600000));
9388
9389 uptime = bgp_clock();
9390 uptime -= p->last_write;
9391 tm = gmtime(&uptime);
9392 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9393 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9394 + (tm->tm_hour * 3600000));
9395
9396 uptime = bgp_clock();
9397 uptime -= p->update_time;
9398 tm = gmtime(&uptime);
9399 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9400 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9401 + (tm->tm_hour * 3600000));
9402
9403 /* Configured timer values. */
9404 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9405 p->v_holdtime * 1000);
9406 json_object_int_add(json_neigh,
9407 "bgpTimerKeepAliveIntervalMsecs",
9408 p->v_keepalive * 1000);
9409 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9410 json_object_int_add(json_neigh,
9411 "bgpTimerConfiguredHoldTimeMsecs",
9412 p->holdtime * 1000);
9413 json_object_int_add(
9414 json_neigh,
9415 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9416 p->keepalive * 1000);
9417 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9418 || (bgp->default_keepalive
9419 != BGP_DEFAULT_KEEPALIVE)) {
9420 json_object_int_add(json_neigh,
9421 "bgpTimerConfiguredHoldTimeMsecs",
9422 bgp->default_holdtime);
9423 json_object_int_add(
9424 json_neigh,
9425 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9426 bgp->default_keepalive);
9427 }
9428 } else {
9429 /* Administrative shutdown. */
9430 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9431 vty_out(vty, " Administratively shut down\n");
9432
9433 /* BGP Version. */
9434 vty_out(vty, " BGP version 4");
9435 vty_out(vty, ", remote router ID %s",
9436 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9437 vty_out(vty, ", local router ID %s\n",
9438 inet_ntop(AF_INET, &bgp->router_id, buf1,
9439 sizeof(buf1)));
9440
9441 /* Confederation */
9442 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9443 && bgp_confederation_peers_check(bgp, p->as))
9444 vty_out(vty,
9445 " Neighbor under common administration\n");
9446
9447 /* Status. */
9448 vty_out(vty, " BGP state = %s",
9449 lookup_msg(bgp_status_msg, p->status, NULL));
9450
9451 if (p->status == Established)
9452 vty_out(vty, ", up for %8s",
9453 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9454 0, NULL));
9455
9456 else if (p->status == Active) {
9457 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9458 vty_out(vty, " (passive)");
9459 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9460 vty_out(vty, " (NSF passive)");
9461 }
9462 vty_out(vty, "\n");
9463
9464 /* read timer */
9465 vty_out(vty, " Last read %s",
9466 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9467 NULL));
9468 vty_out(vty, ", Last write %s\n",
9469 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9470 NULL));
9471
9472 /* Configured timer values. */
9473 vty_out(vty,
9474 " Hold time is %d, keepalive interval is %d seconds\n",
9475 p->v_holdtime, p->v_keepalive);
9476 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9477 vty_out(vty, " Configured hold time is %d",
9478 p->holdtime);
9479 vty_out(vty, ", keepalive interval is %d seconds\n",
9480 p->keepalive);
9481 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9482 || (bgp->default_keepalive
9483 != BGP_DEFAULT_KEEPALIVE)) {
9484 vty_out(vty, " Configured hold time is %d",
9485 bgp->default_holdtime);
9486 vty_out(vty, ", keepalive interval is %d seconds\n",
9487 bgp->default_keepalive);
9488 }
9489 }
9490 /* Capability. */
9491 if (p->status == Established) {
9492 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9493 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9494 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9495 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9496 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9497 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9498 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9499 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9500 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9501 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9502 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9503 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9504 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9505 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9506 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9507 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9508 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9509 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9510 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9511 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9512 if (use_json) {
9513 json_object *json_cap = NULL;
9514
9515 json_cap = json_object_new_object();
9516
9517 /* AS4 */
9518 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9519 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9520 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9521 && CHECK_FLAG(p->cap,
9522 PEER_CAP_AS4_RCV))
9523 json_object_string_add(
9524 json_cap, "4byteAs",
9525 "advertisedAndReceived");
9526 else if (CHECK_FLAG(p->cap,
9527 PEER_CAP_AS4_ADV))
9528 json_object_string_add(
9529 json_cap, "4byteAs",
9530 "advertised");
9531 else if (CHECK_FLAG(p->cap,
9532 PEER_CAP_AS4_RCV))
9533 json_object_string_add(
9534 json_cap, "4byteAs",
9535 "received");
9536 }
9537
9538 /* AddPath */
9539 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9540 || CHECK_FLAG(p->cap,
9541 PEER_CAP_ADDPATH_ADV)) {
9542 json_object *json_add = NULL;
9543 const char *print_store;
9544
9545 json_add = json_object_new_object();
9546
9547 FOREACH_AFI_SAFI (afi, safi) {
9548 json_object *json_sub = NULL;
9549 json_sub =
9550 json_object_new_object();
9551 print_store = afi_safi_print(
9552 afi, safi);
9553
9554 if (CHECK_FLAG(
9555 p->af_cap[afi]
9556 [safi],
9557 PEER_CAP_ADDPATH_AF_TX_ADV)
9558 || CHECK_FLAG(
9559 p->af_cap[afi]
9560 [safi],
9561 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9562 if (CHECK_FLAG(
9563 p->af_cap
9564 [afi]
9565 [safi],
9566 PEER_CAP_ADDPATH_AF_TX_ADV)
9567 && CHECK_FLAG(
9568 p->af_cap
9569 [afi]
9570 [safi],
9571 PEER_CAP_ADDPATH_AF_TX_RCV))
9572 json_object_boolean_true_add(
9573 json_sub,
9574 "txAdvertisedAndReceived");
9575 else if (
9576 CHECK_FLAG(
9577 p->af_cap
9578 [afi]
9579 [safi],
9580 PEER_CAP_ADDPATH_AF_TX_ADV))
9581 json_object_boolean_true_add(
9582 json_sub,
9583 "txAdvertised");
9584 else if (
9585 CHECK_FLAG(
9586 p->af_cap
9587 [afi]
9588 [safi],
9589 PEER_CAP_ADDPATH_AF_TX_RCV))
9590 json_object_boolean_true_add(
9591 json_sub,
9592 "txReceived");
9593 }
9594
9595 if (CHECK_FLAG(
9596 p->af_cap[afi]
9597 [safi],
9598 PEER_CAP_ADDPATH_AF_RX_ADV)
9599 || CHECK_FLAG(
9600 p->af_cap[afi]
9601 [safi],
9602 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9603 if (CHECK_FLAG(
9604 p->af_cap
9605 [afi]
9606 [safi],
9607 PEER_CAP_ADDPATH_AF_RX_ADV)
9608 && CHECK_FLAG(
9609 p->af_cap
9610 [afi]
9611 [safi],
9612 PEER_CAP_ADDPATH_AF_RX_RCV))
9613 json_object_boolean_true_add(
9614 json_sub,
9615 "rxAdvertisedAndReceived");
9616 else if (
9617 CHECK_FLAG(
9618 p->af_cap
9619 [afi]
9620 [safi],
9621 PEER_CAP_ADDPATH_AF_RX_ADV))
9622 json_object_boolean_true_add(
9623 json_sub,
9624 "rxAdvertised");
9625 else if (
9626 CHECK_FLAG(
9627 p->af_cap
9628 [afi]
9629 [safi],
9630 PEER_CAP_ADDPATH_AF_RX_RCV))
9631 json_object_boolean_true_add(
9632 json_sub,
9633 "rxReceived");
9634 }
9635
9636 if (CHECK_FLAG(
9637 p->af_cap[afi]
9638 [safi],
9639 PEER_CAP_ADDPATH_AF_TX_ADV)
9640 || CHECK_FLAG(
9641 p->af_cap[afi]
9642 [safi],
9643 PEER_CAP_ADDPATH_AF_TX_RCV)
9644 || CHECK_FLAG(
9645 p->af_cap[afi]
9646 [safi],
9647 PEER_CAP_ADDPATH_AF_RX_ADV)
9648 || CHECK_FLAG(
9649 p->af_cap[afi]
9650 [safi],
9651 PEER_CAP_ADDPATH_AF_RX_RCV))
9652 json_object_object_add(
9653 json_add,
9654 print_store,
9655 json_sub);
9656 else
9657 json_object_free(
9658 json_sub);
9659 }
9660
9661 json_object_object_add(
9662 json_cap, "addPath", json_add);
9663 }
9664
9665 /* Dynamic */
9666 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9667 || CHECK_FLAG(p->cap,
9668 PEER_CAP_DYNAMIC_ADV)) {
9669 if (CHECK_FLAG(p->cap,
9670 PEER_CAP_DYNAMIC_ADV)
9671 && CHECK_FLAG(p->cap,
9672 PEER_CAP_DYNAMIC_RCV))
9673 json_object_string_add(
9674 json_cap, "dynamic",
9675 "advertisedAndReceived");
9676 else if (CHECK_FLAG(
9677 p->cap,
9678 PEER_CAP_DYNAMIC_ADV))
9679 json_object_string_add(
9680 json_cap, "dynamic",
9681 "advertised");
9682 else if (CHECK_FLAG(
9683 p->cap,
9684 PEER_CAP_DYNAMIC_RCV))
9685 json_object_string_add(
9686 json_cap, "dynamic",
9687 "received");
9688 }
9689
9690 /* Extended nexthop */
9691 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9692 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9693 json_object *json_nxt = NULL;
9694 const char *print_store;
9695
9696
9697 if (CHECK_FLAG(p->cap,
9698 PEER_CAP_ENHE_ADV)
9699 && CHECK_FLAG(p->cap,
9700 PEER_CAP_ENHE_RCV))
9701 json_object_string_add(
9702 json_cap,
9703 "extendedNexthop",
9704 "advertisedAndReceived");
9705 else if (CHECK_FLAG(p->cap,
9706 PEER_CAP_ENHE_ADV))
9707 json_object_string_add(
9708 json_cap,
9709 "extendedNexthop",
9710 "advertised");
9711 else if (CHECK_FLAG(p->cap,
9712 PEER_CAP_ENHE_RCV))
9713 json_object_string_add(
9714 json_cap,
9715 "extendedNexthop",
9716 "received");
9717
9718 if (CHECK_FLAG(p->cap,
9719 PEER_CAP_ENHE_RCV)) {
9720 json_nxt =
9721 json_object_new_object();
9722
9723 for (safi = SAFI_UNICAST;
9724 safi < SAFI_MAX; safi++) {
9725 if (CHECK_FLAG(
9726 p->af_cap
9727 [AFI_IP]
9728 [safi],
9729 PEER_CAP_ENHE_AF_RCV)) {
9730 print_store = afi_safi_print(
9731 AFI_IP,
9732 safi);
9733 json_object_string_add(
9734 json_nxt,
9735 print_store,
9736 "recieved"); /* misspelled for compatibility */
9737 }
9738 }
9739 json_object_object_add(
9740 json_cap,
9741 "extendedNexthopFamililesByPeer",
9742 json_nxt);
9743 }
9744 }
9745
9746 /* Route Refresh */
9747 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9748 || CHECK_FLAG(p->cap,
9749 PEER_CAP_REFRESH_NEW_RCV)
9750 || CHECK_FLAG(p->cap,
9751 PEER_CAP_REFRESH_OLD_RCV)) {
9752 if (CHECK_FLAG(p->cap,
9753 PEER_CAP_REFRESH_ADV)
9754 && (CHECK_FLAG(
9755 p->cap,
9756 PEER_CAP_REFRESH_NEW_RCV)
9757 || CHECK_FLAG(
9758 p->cap,
9759 PEER_CAP_REFRESH_OLD_RCV))) {
9760 if (CHECK_FLAG(
9761 p->cap,
9762 PEER_CAP_REFRESH_OLD_RCV)
9763 && CHECK_FLAG(
9764 p->cap,
9765 PEER_CAP_REFRESH_NEW_RCV))
9766 json_object_string_add(
9767 json_cap,
9768 "routeRefresh",
9769 "advertisedAndReceivedOldNew");
9770 else {
9771 if (CHECK_FLAG(
9772 p->cap,
9773 PEER_CAP_REFRESH_OLD_RCV))
9774 json_object_string_add(
9775 json_cap,
9776 "routeRefresh",
9777 "advertisedAndReceivedOld");
9778 else
9779 json_object_string_add(
9780 json_cap,
9781 "routeRefresh",
9782 "advertisedAndReceivedNew");
9783 }
9784 } else if (
9785 CHECK_FLAG(
9786 p->cap,
9787 PEER_CAP_REFRESH_ADV))
9788 json_object_string_add(
9789 json_cap,
9790 "routeRefresh",
9791 "advertised");
9792 else if (
9793 CHECK_FLAG(
9794 p->cap,
9795 PEER_CAP_REFRESH_NEW_RCV)
9796 || CHECK_FLAG(
9797 p->cap,
9798 PEER_CAP_REFRESH_OLD_RCV))
9799 json_object_string_add(
9800 json_cap,
9801 "routeRefresh",
9802 "received");
9803 }
9804
9805 /* Multiprotocol Extensions */
9806 json_object *json_multi = NULL;
9807 json_multi = json_object_new_object();
9808
9809 FOREACH_AFI_SAFI (afi, safi) {
9810 if (p->afc_adv[afi][safi]
9811 || p->afc_recv[afi][safi]) {
9812 json_object *json_exten = NULL;
9813 json_exten =
9814 json_object_new_object();
9815
9816 if (p->afc_adv[afi][safi]
9817 && p->afc_recv[afi][safi])
9818 json_object_boolean_true_add(
9819 json_exten,
9820 "advertisedAndReceived");
9821 else if (p->afc_adv[afi][safi])
9822 json_object_boolean_true_add(
9823 json_exten,
9824 "advertised");
9825 else if (p->afc_recv[afi][safi])
9826 json_object_boolean_true_add(
9827 json_exten,
9828 "received");
9829
9830 json_object_object_add(
9831 json_multi,
9832 afi_safi_print(afi,
9833 safi),
9834 json_exten);
9835 }
9836 }
9837 json_object_object_add(
9838 json_cap, "multiprotocolExtensions",
9839 json_multi);
9840
9841 /* Hostname capabilities */
9842 json_object *json_hname = NULL;
9843
9844 json_hname = json_object_new_object();
9845
9846 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9847 json_object_string_add(
9848 json_hname, "advHostName",
9849 bgp->peer_self->hostname
9850 ? bgp->peer_self
9851 ->hostname
9852 : "n/a");
9853 json_object_string_add(
9854 json_hname, "advDomainName",
9855 bgp->peer_self->domainname
9856 ? bgp->peer_self
9857 ->domainname
9858 : "n/a");
9859 }
9860
9861
9862 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9863 json_object_string_add(
9864 json_hname, "rcvHostName",
9865 p->hostname ? p->hostname
9866 : "n/a");
9867 json_object_string_add(
9868 json_hname, "rcvDomainName",
9869 p->domainname ? p->domainname
9870 : "n/a");
9871 }
9872
9873 json_object_object_add(json_cap, "hostName",
9874 json_hname);
9875
9876 /* Gracefull Restart */
9877 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9878 || CHECK_FLAG(p->cap,
9879 PEER_CAP_RESTART_ADV)) {
9880 if (CHECK_FLAG(p->cap,
9881 PEER_CAP_RESTART_ADV)
9882 && CHECK_FLAG(p->cap,
9883 PEER_CAP_RESTART_RCV))
9884 json_object_string_add(
9885 json_cap,
9886 "gracefulRestart",
9887 "advertisedAndReceived");
9888 else if (CHECK_FLAG(
9889 p->cap,
9890 PEER_CAP_RESTART_ADV))
9891 json_object_string_add(
9892 json_cap,
9893 "gracefulRestartCapability",
9894 "advertised");
9895 else if (CHECK_FLAG(
9896 p->cap,
9897 PEER_CAP_RESTART_RCV))
9898 json_object_string_add(
9899 json_cap,
9900 "gracefulRestartCapability",
9901 "received");
9902
9903 if (CHECK_FLAG(p->cap,
9904 PEER_CAP_RESTART_RCV)) {
9905 int restart_af_count = 0;
9906 json_object *json_restart =
9907 NULL;
9908 json_restart =
9909 json_object_new_object();
9910
9911 json_object_int_add(
9912 json_cap,
9913 "gracefulRestartRemoteTimerMsecs",
9914 p->v_gr_restart * 1000);
9915
9916 FOREACH_AFI_SAFI (afi, safi) {
9917 if (CHECK_FLAG(
9918 p->af_cap
9919 [afi]
9920 [safi],
9921 PEER_CAP_RESTART_AF_RCV)) {
9922 json_object *
9923 json_sub =
9924 NULL;
9925 json_sub =
9926 json_object_new_object();
9927
9928 if (CHECK_FLAG(
9929 p->af_cap
9930 [afi]
9931 [safi],
9932 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9933 json_object_boolean_true_add(
9934 json_sub,
9935 "preserved");
9936 restart_af_count++;
9937 json_object_object_add(
9938 json_restart,
9939 afi_safi_print(
9940 afi,
9941 safi),
9942 json_sub);
9943 }
9944 }
9945 if (!restart_af_count) {
9946 json_object_string_add(
9947 json_cap,
9948 "addressFamiliesByPeer",
9949 "none");
9950 json_object_free(
9951 json_restart);
9952 } else
9953 json_object_object_add(
9954 json_cap,
9955 "addressFamiliesByPeer",
9956 json_restart);
9957 }
9958 }
9959 json_object_object_add(json_neigh,
9960 "neighborCapabilities",
9961 json_cap);
9962 } else {
9963 vty_out(vty, " Neighbor capabilities:\n");
9964
9965 /* AS4 */
9966 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9967 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9968 vty_out(vty, " 4 Byte AS:");
9969 if (CHECK_FLAG(p->cap,
9970 PEER_CAP_AS4_ADV))
9971 vty_out(vty, " advertised");
9972 if (CHECK_FLAG(p->cap,
9973 PEER_CAP_AS4_RCV))
9974 vty_out(vty, " %sreceived",
9975 CHECK_FLAG(
9976 p->cap,
9977 PEER_CAP_AS4_ADV)
9978 ? "and "
9979 : "");
9980 vty_out(vty, "\n");
9981 }
9982
9983 /* AddPath */
9984 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9985 || CHECK_FLAG(p->cap,
9986 PEER_CAP_ADDPATH_ADV)) {
9987 vty_out(vty, " AddPath:\n");
9988
9989 FOREACH_AFI_SAFI (afi, safi) {
9990 if (CHECK_FLAG(
9991 p->af_cap[afi]
9992 [safi],
9993 PEER_CAP_ADDPATH_AF_TX_ADV)
9994 || CHECK_FLAG(
9995 p->af_cap[afi]
9996 [safi],
9997 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9998 vty_out(vty,
9999 " %s: TX ",
10000 afi_safi_print(
10001 afi,
10002 safi));
10003
10004 if (CHECK_FLAG(
10005 p->af_cap
10006 [afi]
10007 [safi],
10008 PEER_CAP_ADDPATH_AF_TX_ADV))
10009 vty_out(vty,
10010 "advertised %s",
10011 afi_safi_print(
10012 afi,
10013 safi));
10014
10015 if (CHECK_FLAG(
10016 p->af_cap
10017 [afi]
10018 [safi],
10019 PEER_CAP_ADDPATH_AF_TX_RCV))
10020 vty_out(vty,
10021 "%sreceived",
10022 CHECK_FLAG(
10023 p->af_cap
10024 [afi]
10025 [safi],
10026 PEER_CAP_ADDPATH_AF_TX_ADV)
10027 ? " and "
10028 : "");
10029
10030 vty_out(vty, "\n");
10031 }
10032
10033 if (CHECK_FLAG(
10034 p->af_cap[afi]
10035 [safi],
10036 PEER_CAP_ADDPATH_AF_RX_ADV)
10037 || CHECK_FLAG(
10038 p->af_cap[afi]
10039 [safi],
10040 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10041 vty_out(vty,
10042 " %s: RX ",
10043 afi_safi_print(
10044 afi,
10045 safi));
10046
10047 if (CHECK_FLAG(
10048 p->af_cap
10049 [afi]
10050 [safi],
10051 PEER_CAP_ADDPATH_AF_RX_ADV))
10052 vty_out(vty,
10053 "advertised %s",
10054 afi_safi_print(
10055 afi,
10056 safi));
10057
10058 if (CHECK_FLAG(
10059 p->af_cap
10060 [afi]
10061 [safi],
10062 PEER_CAP_ADDPATH_AF_RX_RCV))
10063 vty_out(vty,
10064 "%sreceived",
10065 CHECK_FLAG(
10066 p->af_cap
10067 [afi]
10068 [safi],
10069 PEER_CAP_ADDPATH_AF_RX_ADV)
10070 ? " and "
10071 : "");
10072
10073 vty_out(vty, "\n");
10074 }
10075 }
10076 }
10077
10078 /* Dynamic */
10079 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10080 || CHECK_FLAG(p->cap,
10081 PEER_CAP_DYNAMIC_ADV)) {
10082 vty_out(vty, " Dynamic:");
10083 if (CHECK_FLAG(p->cap,
10084 PEER_CAP_DYNAMIC_ADV))
10085 vty_out(vty, " advertised");
10086 if (CHECK_FLAG(p->cap,
10087 PEER_CAP_DYNAMIC_RCV))
10088 vty_out(vty, " %sreceived",
10089 CHECK_FLAG(
10090 p->cap,
10091 PEER_CAP_DYNAMIC_ADV)
10092 ? "and "
10093 : "");
10094 vty_out(vty, "\n");
10095 }
10096
10097 /* Extended nexthop */
10098 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10099 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10100 vty_out(vty, " Extended nexthop:");
10101 if (CHECK_FLAG(p->cap,
10102 PEER_CAP_ENHE_ADV))
10103 vty_out(vty, " advertised");
10104 if (CHECK_FLAG(p->cap,
10105 PEER_CAP_ENHE_RCV))
10106 vty_out(vty, " %sreceived",
10107 CHECK_FLAG(
10108 p->cap,
10109 PEER_CAP_ENHE_ADV)
10110 ? "and "
10111 : "");
10112 vty_out(vty, "\n");
10113
10114 if (CHECK_FLAG(p->cap,
10115 PEER_CAP_ENHE_RCV)) {
10116 vty_out(vty,
10117 " Address families by peer:\n ");
10118 for (safi = SAFI_UNICAST;
10119 safi < SAFI_MAX; safi++)
10120 if (CHECK_FLAG(
10121 p->af_cap
10122 [AFI_IP]
10123 [safi],
10124 PEER_CAP_ENHE_AF_RCV))
10125 vty_out(vty,
10126 " %s\n",
10127 afi_safi_print(
10128 AFI_IP,
10129 safi));
10130 }
10131 }
10132
10133 /* Route Refresh */
10134 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10135 || CHECK_FLAG(p->cap,
10136 PEER_CAP_REFRESH_NEW_RCV)
10137 || CHECK_FLAG(p->cap,
10138 PEER_CAP_REFRESH_OLD_RCV)) {
10139 vty_out(vty, " Route refresh:");
10140 if (CHECK_FLAG(p->cap,
10141 PEER_CAP_REFRESH_ADV))
10142 vty_out(vty, " advertised");
10143 if (CHECK_FLAG(p->cap,
10144 PEER_CAP_REFRESH_NEW_RCV)
10145 || CHECK_FLAG(
10146 p->cap,
10147 PEER_CAP_REFRESH_OLD_RCV))
10148 vty_out(vty, " %sreceived(%s)",
10149 CHECK_FLAG(
10150 p->cap,
10151 PEER_CAP_REFRESH_ADV)
10152 ? "and "
10153 : "",
10154 (CHECK_FLAG(
10155 p->cap,
10156 PEER_CAP_REFRESH_OLD_RCV)
10157 && CHECK_FLAG(
10158 p->cap,
10159 PEER_CAP_REFRESH_NEW_RCV))
10160 ? "old & new"
10161 : CHECK_FLAG(
10162 p->cap,
10163 PEER_CAP_REFRESH_OLD_RCV)
10164 ? "old"
10165 : "new");
10166
10167 vty_out(vty, "\n");
10168 }
10169
10170 /* Multiprotocol Extensions */
10171 FOREACH_AFI_SAFI (afi, safi)
10172 if (p->afc_adv[afi][safi]
10173 || p->afc_recv[afi][safi]) {
10174 vty_out(vty,
10175 " Address Family %s:",
10176 afi_safi_print(afi,
10177 safi));
10178 if (p->afc_adv[afi][safi])
10179 vty_out(vty,
10180 " advertised");
10181 if (p->afc_recv[afi][safi])
10182 vty_out(vty,
10183 " %sreceived",
10184 p->afc_adv[afi]
10185 [safi]
10186 ? "and "
10187 : "");
10188 vty_out(vty, "\n");
10189 }
10190
10191 /* Hostname capability */
10192 vty_out(vty, " Hostname Capability:");
10193
10194 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10195 vty_out(vty,
10196 " advertised (name: %s,domain name: %s)",
10197 bgp->peer_self->hostname
10198 ? bgp->peer_self
10199 ->hostname
10200 : "n/a",
10201 bgp->peer_self->domainname
10202 ? bgp->peer_self
10203 ->domainname
10204 : "n/a");
10205 } else {
10206 vty_out(vty, " not advertised");
10207 }
10208
10209 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10210 vty_out(vty,
10211 " received (name: %s,domain name: %s)",
10212 p->hostname ? p->hostname
10213 : "n/a",
10214 p->domainname ? p->domainname
10215 : "n/a");
10216 } else {
10217 vty_out(vty, " not received");
10218 }
10219
10220 vty_out(vty, "\n");
10221
10222 /* Gracefull Restart */
10223 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10224 || CHECK_FLAG(p->cap,
10225 PEER_CAP_RESTART_ADV)) {
10226 vty_out(vty,
10227 " Graceful Restart Capabilty:");
10228 if (CHECK_FLAG(p->cap,
10229 PEER_CAP_RESTART_ADV))
10230 vty_out(vty, " advertised");
10231 if (CHECK_FLAG(p->cap,
10232 PEER_CAP_RESTART_RCV))
10233 vty_out(vty, " %sreceived",
10234 CHECK_FLAG(
10235 p->cap,
10236 PEER_CAP_RESTART_ADV)
10237 ? "and "
10238 : "");
10239 vty_out(vty, "\n");
10240
10241 if (CHECK_FLAG(p->cap,
10242 PEER_CAP_RESTART_RCV)) {
10243 int restart_af_count = 0;
10244
10245 vty_out(vty,
10246 " Remote Restart timer is %d seconds\n",
10247 p->v_gr_restart);
10248 vty_out(vty,
10249 " Address families by peer:\n ");
10250
10251 FOREACH_AFI_SAFI (afi, safi)
10252 if (CHECK_FLAG(
10253 p->af_cap
10254 [afi]
10255 [safi],
10256 PEER_CAP_RESTART_AF_RCV)) {
10257 vty_out(vty,
10258 "%s%s(%s)",
10259 restart_af_count
10260 ? ", "
10261 : "",
10262 afi_safi_print(
10263 afi,
10264 safi),
10265 CHECK_FLAG(
10266 p->af_cap
10267 [afi]
10268 [safi],
10269 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10270 ? "preserved"
10271 : "not preserved");
10272 restart_af_count++;
10273 }
10274 if (!restart_af_count)
10275 vty_out(vty, "none");
10276 vty_out(vty, "\n");
10277 }
10278 }
10279 }
10280 }
10281 }
10282
10283 /* graceful restart information */
10284 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10285 || p->t_gr_stale) {
10286 json_object *json_grace = NULL;
10287 json_object *json_grace_send = NULL;
10288 json_object *json_grace_recv = NULL;
10289 int eor_send_af_count = 0;
10290 int eor_receive_af_count = 0;
10291
10292 if (use_json) {
10293 json_grace = json_object_new_object();
10294 json_grace_send = json_object_new_object();
10295 json_grace_recv = json_object_new_object();
10296
10297 if (p->status == Established) {
10298 FOREACH_AFI_SAFI (afi, safi) {
10299 if (CHECK_FLAG(p->af_sflags[afi][safi],
10300 PEER_STATUS_EOR_SEND)) {
10301 json_object_boolean_true_add(
10302 json_grace_send,
10303 afi_safi_print(afi,
10304 safi));
10305 eor_send_af_count++;
10306 }
10307 }
10308 FOREACH_AFI_SAFI (afi, safi) {
10309 if (CHECK_FLAG(
10310 p->af_sflags[afi][safi],
10311 PEER_STATUS_EOR_RECEIVED)) {
10312 json_object_boolean_true_add(
10313 json_grace_recv,
10314 afi_safi_print(afi,
10315 safi));
10316 eor_receive_af_count++;
10317 }
10318 }
10319 }
10320
10321 json_object_object_add(json_grace, "endOfRibSend",
10322 json_grace_send);
10323 json_object_object_add(json_grace, "endOfRibRecv",
10324 json_grace_recv);
10325
10326 if (p->t_gr_restart)
10327 json_object_int_add(json_grace,
10328 "gracefulRestartTimerMsecs",
10329 thread_timer_remain_second(
10330 p->t_gr_restart)
10331 * 1000);
10332
10333 if (p->t_gr_stale)
10334 json_object_int_add(
10335 json_grace,
10336 "gracefulStalepathTimerMsecs",
10337 thread_timer_remain_second(
10338 p->t_gr_stale)
10339 * 1000);
10340
10341 json_object_object_add(
10342 json_neigh, "gracefulRestartInfo", json_grace);
10343 } else {
10344 vty_out(vty, " Graceful restart information:\n");
10345 if (p->status == Established) {
10346 vty_out(vty, " End-of-RIB send: ");
10347 FOREACH_AFI_SAFI (afi, safi) {
10348 if (CHECK_FLAG(p->af_sflags[afi][safi],
10349 PEER_STATUS_EOR_SEND)) {
10350 vty_out(vty, "%s%s",
10351 eor_send_af_count ? ", "
10352 : "",
10353 afi_safi_print(afi,
10354 safi));
10355 eor_send_af_count++;
10356 }
10357 }
10358 vty_out(vty, "\n");
10359 vty_out(vty, " End-of-RIB received: ");
10360 FOREACH_AFI_SAFI (afi, safi) {
10361 if (CHECK_FLAG(
10362 p->af_sflags[afi][safi],
10363 PEER_STATUS_EOR_RECEIVED)) {
10364 vty_out(vty, "%s%s",
10365 eor_receive_af_count
10366 ? ", "
10367 : "",
10368 afi_safi_print(afi,
10369 safi));
10370 eor_receive_af_count++;
10371 }
10372 }
10373 vty_out(vty, "\n");
10374 }
10375
10376 if (p->t_gr_restart)
10377 vty_out(vty,
10378 " The remaining time of restart timer is %ld\n",
10379 thread_timer_remain_second(
10380 p->t_gr_restart));
10381
10382 if (p->t_gr_stale)
10383 vty_out(vty,
10384 " The remaining time of stalepath timer is %ld\n",
10385 thread_timer_remain_second(
10386 p->t_gr_stale));
10387 }
10388 }
10389 if (use_json) {
10390 json_object *json_stat = NULL;
10391 json_stat = json_object_new_object();
10392 /* Packet counts. */
10393 json_object_int_add(json_stat, "depthInq", 0);
10394 json_object_int_add(json_stat, "depthOutq",
10395 (unsigned long)p->obuf->count);
10396 json_object_int_add(json_stat, "opensSent",
10397 atomic_load_explicit(&p->open_out,
10398 memory_order_relaxed));
10399 json_object_int_add(json_stat, "opensRecv",
10400 atomic_load_explicit(&p->open_in,
10401 memory_order_relaxed));
10402 json_object_int_add(json_stat, "notificationsSent",
10403 atomic_load_explicit(&p->notify_out,
10404 memory_order_relaxed));
10405 json_object_int_add(json_stat, "notificationsRecv",
10406 atomic_load_explicit(&p->notify_in,
10407 memory_order_relaxed));
10408 json_object_int_add(json_stat, "updatesSent",
10409 atomic_load_explicit(&p->update_out,
10410 memory_order_relaxed));
10411 json_object_int_add(json_stat, "updatesRecv",
10412 atomic_load_explicit(&p->update_in,
10413 memory_order_relaxed));
10414 json_object_int_add(json_stat, "keepalivesSent",
10415 atomic_load_explicit(&p->keepalive_out,
10416 memory_order_relaxed));
10417 json_object_int_add(json_stat, "keepalivesRecv",
10418 atomic_load_explicit(&p->keepalive_in,
10419 memory_order_relaxed));
10420 json_object_int_add(json_stat, "routeRefreshSent",
10421 atomic_load_explicit(&p->refresh_out,
10422 memory_order_relaxed));
10423 json_object_int_add(json_stat, "routeRefreshRecv",
10424 atomic_load_explicit(&p->refresh_in,
10425 memory_order_relaxed));
10426 json_object_int_add(json_stat, "capabilitySent",
10427 atomic_load_explicit(&p->dynamic_cap_out,
10428 memory_order_relaxed));
10429 json_object_int_add(json_stat, "capabilityRecv",
10430 atomic_load_explicit(&p->dynamic_cap_in,
10431 memory_order_relaxed));
10432 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10433 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10434 json_object_object_add(json_neigh, "messageStats", json_stat);
10435 } else {
10436 /* Packet counts. */
10437 vty_out(vty, " Message statistics:\n");
10438 vty_out(vty, " Inq depth is 0\n");
10439 vty_out(vty, " Outq depth is %lu\n",
10440 (unsigned long)p->obuf->count);
10441 vty_out(vty, " Sent Rcvd\n");
10442 vty_out(vty, " Opens: %10d %10d\n",
10443 atomic_load_explicit(&p->open_out,
10444 memory_order_relaxed),
10445 atomic_load_explicit(&p->open_in,
10446 memory_order_relaxed));
10447 vty_out(vty, " Notifications: %10d %10d\n",
10448 atomic_load_explicit(&p->notify_out,
10449 memory_order_relaxed),
10450 atomic_load_explicit(&p->notify_in,
10451 memory_order_relaxed));
10452 vty_out(vty, " Updates: %10d %10d\n",
10453 atomic_load_explicit(&p->update_out,
10454 memory_order_relaxed),
10455 atomic_load_explicit(&p->update_in,
10456 memory_order_relaxed));
10457 vty_out(vty, " Keepalives: %10d %10d\n",
10458 atomic_load_explicit(&p->keepalive_out,
10459 memory_order_relaxed),
10460 atomic_load_explicit(&p->keepalive_in,
10461 memory_order_relaxed));
10462 vty_out(vty, " Route Refresh: %10d %10d\n",
10463 atomic_load_explicit(&p->refresh_out,
10464 memory_order_relaxed),
10465 atomic_load_explicit(&p->refresh_in,
10466 memory_order_relaxed));
10467 vty_out(vty, " Capability: %10d %10d\n",
10468 atomic_load_explicit(&p->dynamic_cap_out,
10469 memory_order_relaxed),
10470 atomic_load_explicit(&p->dynamic_cap_in,
10471 memory_order_relaxed));
10472 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10473 PEER_TOTAL_RX(p));
10474 }
10475
10476 if (use_json) {
10477 /* advertisement-interval */
10478 json_object_int_add(json_neigh,
10479 "minBtwnAdvertisementRunsTimerMsecs",
10480 p->v_routeadv * 1000);
10481
10482 /* Update-source. */
10483 if (p->update_if || p->update_source) {
10484 if (p->update_if)
10485 json_object_string_add(json_neigh,
10486 "updateSource",
10487 p->update_if);
10488 else if (p->update_source)
10489 json_object_string_add(
10490 json_neigh, "updateSource",
10491 sockunion2str(p->update_source, buf1,
10492 SU_ADDRSTRLEN));
10493 }
10494 } else {
10495 /* advertisement-interval */
10496 vty_out(vty,
10497 " Minimum time between advertisement runs is %d seconds\n",
10498 p->v_routeadv);
10499
10500 /* Update-source. */
10501 if (p->update_if || p->update_source) {
10502 vty_out(vty, " Update source is ");
10503 if (p->update_if)
10504 vty_out(vty, "%s", p->update_if);
10505 else if (p->update_source)
10506 vty_out(vty, "%s",
10507 sockunion2str(p->update_source, buf1,
10508 SU_ADDRSTRLEN));
10509 vty_out(vty, "\n");
10510 }
10511
10512 vty_out(vty, "\n");
10513 }
10514
10515 /* Address Family Information */
10516 json_object *json_hold = NULL;
10517
10518 if (use_json)
10519 json_hold = json_object_new_object();
10520
10521 FOREACH_AFI_SAFI (afi, safi)
10522 if (p->afc[afi][safi])
10523 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10524 json_hold);
10525
10526 if (use_json) {
10527 json_object_object_add(json_neigh, "addressFamilyInfo",
10528 json_hold);
10529 json_object_int_add(json_neigh, "connectionsEstablished",
10530 p->established);
10531 json_object_int_add(json_neigh, "connectionsDropped",
10532 p->dropped);
10533 } else
10534 vty_out(vty, " Connections established %d; dropped %d\n",
10535 p->established, p->dropped);
10536
10537 if (!p->last_reset) {
10538 if (use_json)
10539 json_object_string_add(json_neigh, "lastReset",
10540 "never");
10541 else
10542 vty_out(vty, " Last reset never\n");
10543 } else {
10544 if (use_json) {
10545 time_t uptime;
10546 struct tm *tm;
10547
10548 uptime = bgp_clock();
10549 uptime -= p->resettime;
10550 tm = gmtime(&uptime);
10551 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10552 (tm->tm_sec * 1000)
10553 + (tm->tm_min * 60000)
10554 + (tm->tm_hour * 3600000));
10555 json_object_string_add(
10556 json_neigh, "lastResetDueTo",
10557 peer_down_str[(int)p->last_reset]);
10558 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10559 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10560 char errorcodesubcode_hexstr[5];
10561 char errorcodesubcode_str[256];
10562
10563 code_str = bgp_notify_code_str(p->notify.code);
10564 subcode_str = bgp_notify_subcode_str(
10565 p->notify.code, p->notify.subcode);
10566
10567 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10568 p->notify.code, p->notify.subcode);
10569 json_object_string_add(json_neigh,
10570 "lastErrorCodeSubcode",
10571 errorcodesubcode_hexstr);
10572 snprintf(errorcodesubcode_str, 255, "%s%s",
10573 code_str, subcode_str);
10574 json_object_string_add(json_neigh,
10575 "lastNotificationReason",
10576 errorcodesubcode_str);
10577 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10578 && p->notify.code == BGP_NOTIFY_CEASE
10579 && (p->notify.subcode
10580 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10581 || p->notify.subcode
10582 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10583 && p->notify.length) {
10584 char msgbuf[1024];
10585 const char *msg_str;
10586
10587 msg_str = bgp_notify_admin_message(
10588 msgbuf, sizeof(msgbuf),
10589 (uint8_t *)p->notify.data,
10590 p->notify.length);
10591 if (msg_str)
10592 json_object_string_add(
10593 json_neigh,
10594 "lastShutdownDescription",
10595 msg_str);
10596 }
10597 }
10598 } else {
10599 vty_out(vty, " Last reset %s, ",
10600 peer_uptime(p->resettime, timebuf,
10601 BGP_UPTIME_LEN, 0, NULL));
10602
10603 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10604 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10605 code_str = bgp_notify_code_str(p->notify.code);
10606 subcode_str = bgp_notify_subcode_str(
10607 p->notify.code, p->notify.subcode);
10608 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10609 p->last_reset == PEER_DOWN_NOTIFY_SEND
10610 ? "sent"
10611 : "received",
10612 code_str, subcode_str);
10613 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10614 && p->notify.code == BGP_NOTIFY_CEASE
10615 && (p->notify.subcode
10616 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10617 || p->notify.subcode
10618 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10619 && p->notify.length) {
10620 char msgbuf[1024];
10621 const char *msg_str;
10622
10623 msg_str = bgp_notify_admin_message(
10624 msgbuf, sizeof(msgbuf),
10625 (uint8_t *)p->notify.data,
10626 p->notify.length);
10627 if (msg_str)
10628 vty_out(vty,
10629 " Message: \"%s\"\n",
10630 msg_str);
10631 }
10632 } else {
10633 vty_out(vty, "due to %s\n",
10634 peer_down_str[(int)p->last_reset]);
10635 }
10636
10637 if (p->last_reset_cause_size) {
10638 msg = p->last_reset_cause;
10639 vty_out(vty,
10640 " Message received that caused BGP to send a NOTIFICATION:\n ");
10641 for (i = 1; i <= p->last_reset_cause_size;
10642 i++) {
10643 vty_out(vty, "%02X", *msg++);
10644
10645 if (i != p->last_reset_cause_size) {
10646 if (i % 16 == 0) {
10647 vty_out(vty, "\n ");
10648 } else if (i % 4 == 0) {
10649 vty_out(vty, " ");
10650 }
10651 }
10652 }
10653 vty_out(vty, "\n");
10654 }
10655 }
10656 }
10657
10658 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10659 if (use_json)
10660 json_object_boolean_true_add(json_neigh,
10661 "prefixesConfigExceedMax");
10662 else
10663 vty_out(vty,
10664 " Peer had exceeded the max. no. of prefixes configured.\n");
10665
10666 if (p->t_pmax_restart) {
10667 if (use_json) {
10668 json_object_boolean_true_add(
10669 json_neigh, "reducePrefixNumFrom");
10670 json_object_int_add(json_neigh,
10671 "restartInTimerMsec",
10672 thread_timer_remain_second(
10673 p->t_pmax_restart)
10674 * 1000);
10675 } else
10676 vty_out(vty,
10677 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10678 p->host, thread_timer_remain_second(
10679 p->t_pmax_restart));
10680 } else {
10681 if (use_json)
10682 json_object_boolean_true_add(
10683 json_neigh,
10684 "reducePrefixNumAndClearIpBgp");
10685 else
10686 vty_out(vty,
10687 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10688 p->host);
10689 }
10690 }
10691
10692 /* EBGP Multihop and GTSM */
10693 if (p->sort != BGP_PEER_IBGP) {
10694 if (use_json) {
10695 if (p->gtsm_hops > 0)
10696 json_object_int_add(json_neigh,
10697 "externalBgpNbrMaxHopsAway",
10698 p->gtsm_hops);
10699 else if (p->ttl > 1)
10700 json_object_int_add(json_neigh,
10701 "externalBgpNbrMaxHopsAway",
10702 p->ttl);
10703 } else {
10704 if (p->gtsm_hops > 0)
10705 vty_out(vty,
10706 " External BGP neighbor may be up to %d hops away.\n",
10707 p->gtsm_hops);
10708 else if (p->ttl > 1)
10709 vty_out(vty,
10710 " External BGP neighbor may be up to %d hops away.\n",
10711 p->ttl);
10712 }
10713 } else {
10714 if (p->gtsm_hops > 0) {
10715 if (use_json)
10716 json_object_int_add(json_neigh,
10717 "internalBgpNbrMaxHopsAway",
10718 p->gtsm_hops);
10719 else
10720 vty_out(vty,
10721 " Internal BGP neighbor may be up to %d hops away.\n",
10722 p->gtsm_hops);
10723 }
10724 }
10725
10726 /* Local address. */
10727 if (p->su_local) {
10728 if (use_json) {
10729 json_object_string_add(json_neigh, "hostLocal",
10730 sockunion2str(p->su_local, buf1,
10731 SU_ADDRSTRLEN));
10732 json_object_int_add(json_neigh, "portLocal",
10733 ntohs(p->su_local->sin.sin_port));
10734 } else
10735 vty_out(vty, "Local host: %s, Local port: %d\n",
10736 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10737 ntohs(p->su_local->sin.sin_port));
10738 }
10739
10740 /* Remote address. */
10741 if (p->su_remote) {
10742 if (use_json) {
10743 json_object_string_add(json_neigh, "hostForeign",
10744 sockunion2str(p->su_remote, buf1,
10745 SU_ADDRSTRLEN));
10746 json_object_int_add(json_neigh, "portForeign",
10747 ntohs(p->su_remote->sin.sin_port));
10748 } else
10749 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10750 sockunion2str(p->su_remote, buf1,
10751 SU_ADDRSTRLEN),
10752 ntohs(p->su_remote->sin.sin_port));
10753 }
10754
10755 /* Nexthop display. */
10756 if (p->su_local) {
10757 if (use_json) {
10758 json_object_string_add(json_neigh, "nexthop",
10759 inet_ntop(AF_INET,
10760 &p->nexthop.v4, buf1,
10761 sizeof(buf1)));
10762 json_object_string_add(json_neigh, "nexthopGlobal",
10763 inet_ntop(AF_INET6,
10764 &p->nexthop.v6_global,
10765 buf1, sizeof(buf1)));
10766 json_object_string_add(json_neigh, "nexthopLocal",
10767 inet_ntop(AF_INET6,
10768 &p->nexthop.v6_local,
10769 buf1, sizeof(buf1)));
10770 if (p->shared_network)
10771 json_object_string_add(json_neigh,
10772 "bgpConnection",
10773 "sharedNetwork");
10774 else
10775 json_object_string_add(json_neigh,
10776 "bgpConnection",
10777 "nonSharedNetwork");
10778 } else {
10779 vty_out(vty, "Nexthop: %s\n",
10780 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10781 sizeof(buf1)));
10782 vty_out(vty, "Nexthop global: %s\n",
10783 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10784 sizeof(buf1)));
10785 vty_out(vty, "Nexthop local: %s\n",
10786 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10787 sizeof(buf1)));
10788 vty_out(vty, "BGP connection: %s\n",
10789 p->shared_network ? "shared network"
10790 : "non shared network");
10791 }
10792 }
10793
10794 /* Timer information. */
10795 if (use_json) {
10796 json_object_int_add(json_neigh, "connectRetryTimer",
10797 p->v_connect);
10798 if (p->status == Established && p->rtt)
10799 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10800 p->rtt);
10801 if (p->t_start)
10802 json_object_int_add(
10803 json_neigh, "nextStartTimerDueInMsecs",
10804 thread_timer_remain_second(p->t_start) * 1000);
10805 if (p->t_connect)
10806 json_object_int_add(
10807 json_neigh, "nextConnectTimerDueInMsecs",
10808 thread_timer_remain_second(p->t_connect)
10809 * 1000);
10810 if (p->t_routeadv) {
10811 json_object_int_add(json_neigh, "mraiInterval",
10812 p->v_routeadv);
10813 json_object_int_add(
10814 json_neigh, "mraiTimerExpireInMsecs",
10815 thread_timer_remain_second(p->t_routeadv)
10816 * 1000);
10817 }
10818 if (p->password)
10819 json_object_int_add(json_neigh, "authenticationEnabled",
10820 1);
10821
10822 if (p->t_read)
10823 json_object_string_add(json_neigh, "readThread", "on");
10824 else
10825 json_object_string_add(json_neigh, "readThread", "off");
10826
10827 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10828 json_object_string_add(json_neigh, "writeThread", "on");
10829 else
10830 json_object_string_add(json_neigh, "writeThread",
10831 "off");
10832 } else {
10833 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10834 p->v_connect);
10835 if (p->status == Established && p->rtt)
10836 vty_out(vty, "Estimated round trip time: %d ms\n",
10837 p->rtt);
10838 if (p->t_start)
10839 vty_out(vty, "Next start timer due in %ld seconds\n",
10840 thread_timer_remain_second(p->t_start));
10841 if (p->t_connect)
10842 vty_out(vty, "Next connect timer due in %ld seconds\n",
10843 thread_timer_remain_second(p->t_connect));
10844 if (p->t_routeadv)
10845 vty_out(vty,
10846 "MRAI (interval %u) timer expires in %ld seconds\n",
10847 p->v_routeadv,
10848 thread_timer_remain_second(p->t_routeadv));
10849 if (p->password)
10850 vty_out(vty, "Peer Authentication Enabled\n");
10851
10852 vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n",
10853 p->t_read ? "on" : "off",
10854 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10855 ? "on"
10856 : "off", p->fd);
10857 }
10858
10859 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10860 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10861 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10862
10863 if (!use_json)
10864 vty_out(vty, "\n");
10865
10866 /* BFD information. */
10867 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10868
10869 if (use_json) {
10870 if (p->conf_if) /* Configured interface name. */
10871 json_object_object_add(json, p->conf_if, json_neigh);
10872 else /* Configured IP address. */
10873 json_object_object_add(json, p->host, json_neigh);
10874 }
10875 }
10876
10877 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10878 enum show_type type, union sockunion *su,
10879 const char *conf_if, bool use_json,
10880 json_object *json)
10881 {
10882 struct listnode *node, *nnode;
10883 struct peer *peer;
10884 int find = 0;
10885 bool nbr_output = false;
10886 afi_t afi = AFI_MAX;
10887 safi_t safi = SAFI_MAX;
10888
10889 if (type == show_ipv4_peer || type == show_ipv4_all) {
10890 afi = AFI_IP;
10891 } else if (type == show_ipv6_peer || type == show_ipv6_all) {
10892 afi = AFI_IP6;
10893 }
10894
10895 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10896 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10897 continue;
10898
10899 switch (type) {
10900 case show_all:
10901 bgp_show_peer(vty, peer, use_json, json);
10902 nbr_output = true;
10903 break;
10904 case show_peer:
10905 if (conf_if) {
10906 if ((peer->conf_if
10907 && !strcmp(peer->conf_if, conf_if))
10908 || (peer->hostname
10909 && !strcmp(peer->hostname, conf_if))) {
10910 find = 1;
10911 bgp_show_peer(vty, peer, use_json,
10912 json);
10913 }
10914 } else {
10915 if (sockunion_same(&peer->su, su)) {
10916 find = 1;
10917 bgp_show_peer(vty, peer, use_json,
10918 json);
10919 }
10920 }
10921 break;
10922 case show_ipv4_peer:
10923 case show_ipv6_peer:
10924 FOREACH_SAFI (safi) {
10925 if (peer->afc[afi][safi]) {
10926 if (conf_if) {
10927 if ((peer->conf_if
10928 && !strcmp(peer->conf_if, conf_if))
10929 || (peer->hostname
10930 && !strcmp(peer->hostname, conf_if))) {
10931 find = 1;
10932 bgp_show_peer(vty, peer, use_json,
10933 json);
10934 break;
10935 }
10936 } else {
10937 if (sockunion_same(&peer->su, su)) {
10938 find = 1;
10939 bgp_show_peer(vty, peer, use_json,
10940 json);
10941 break;
10942 }
10943 }
10944 }
10945 }
10946 break;
10947 case show_ipv4_all:
10948 case show_ipv6_all:
10949 FOREACH_SAFI (safi) {
10950 if (peer->afc[afi][safi]) {
10951 bgp_show_peer(vty, peer, use_json, json);
10952 nbr_output = true;
10953 break;
10954 }
10955 }
10956 break;
10957 }
10958 }
10959
10960 if ((type == show_peer || type == show_ipv4_peer ||
10961 type == show_ipv6_peer) && !find) {
10962 if (use_json)
10963 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10964 else
10965 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10966 }
10967
10968 if (type != show_peer && type != show_ipv4_peer &&
10969 type != show_ipv6_peer && !nbr_output && !use_json)
10970 vty_out(vty, "%% No BGP neighbors found\n");
10971
10972 if (use_json) {
10973 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10974 json, JSON_C_TO_STRING_PRETTY));
10975 } else {
10976 vty_out(vty, "\n");
10977 }
10978
10979 return CMD_SUCCESS;
10980 }
10981
10982 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10983 enum show_type type,
10984 const char *ip_str,
10985 bool use_json)
10986 {
10987 struct listnode *node, *nnode;
10988 struct bgp *bgp;
10989 union sockunion su;
10990 json_object *json = NULL;
10991 int ret, is_first = 1;
10992 bool nbr_output = false;
10993
10994 if (use_json)
10995 vty_out(vty, "{\n");
10996
10997 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10998 nbr_output = true;
10999 if (use_json) {
11000 if (!(json = json_object_new_object())) {
11001 flog_err(
11002 EC_BGP_JSON_MEM_ERROR,
11003 "Unable to allocate memory for JSON object");
11004 vty_out(vty,
11005 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11006 return;
11007 }
11008
11009 json_object_int_add(json, "vrfId",
11010 (bgp->vrf_id == VRF_UNKNOWN)
11011 ? -1
11012 : (int64_t)bgp->vrf_id);
11013 json_object_string_add(
11014 json, "vrfName",
11015 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11016 ? VRF_DEFAULT_NAME
11017 : bgp->name);
11018
11019 if (!is_first)
11020 vty_out(vty, ",\n");
11021 else
11022 is_first = 0;
11023
11024 vty_out(vty, "\"%s\":",
11025 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11026 ? VRF_DEFAULT_NAME
11027 : bgp->name);
11028 } else {
11029 vty_out(vty, "\nInstance %s:\n",
11030 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11031 ? VRF_DEFAULT_NAME
11032 : bgp->name);
11033 }
11034
11035 if (type == show_peer || type == show_ipv4_peer ||
11036 type == show_ipv6_peer) {
11037 ret = str2sockunion(ip_str, &su);
11038 if (ret < 0)
11039 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11040 use_json, json);
11041 else
11042 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11043 use_json, json);
11044 } else {
11045 bgp_show_neighbor(vty, bgp, type, NULL, NULL,
11046 use_json, json);
11047 }
11048 json_object_free(json);
11049 }
11050
11051 if (use_json) {
11052 vty_out(vty, "}\n");
11053 json_object_free(json);
11054 }
11055 else if (!nbr_output)
11056 vty_out(vty, "%% BGP instance not found\n");
11057 }
11058
11059 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11060 enum show_type type, const char *ip_str,
11061 bool use_json)
11062 {
11063 int ret;
11064 struct bgp *bgp;
11065 union sockunion su;
11066 json_object *json = NULL;
11067
11068 if (name) {
11069 if (strmatch(name, "all")) {
11070 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11071 use_json);
11072 return CMD_SUCCESS;
11073 } else {
11074 bgp = bgp_lookup_by_name(name);
11075 if (!bgp) {
11076 if (use_json) {
11077 json = json_object_new_object();
11078 vty_out(vty, "%s\n",
11079 json_object_to_json_string_ext(
11080 json,
11081 JSON_C_TO_STRING_PRETTY));
11082 json_object_free(json);
11083 } else
11084 vty_out(vty,
11085 "%% BGP instance not found\n");
11086
11087 return CMD_WARNING;
11088 }
11089 }
11090 } else {
11091 bgp = bgp_get_default();
11092 }
11093
11094 if (bgp) {
11095 json = json_object_new_object();
11096 if (ip_str) {
11097 ret = str2sockunion(ip_str, &su);
11098 if (ret < 0)
11099 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11100 use_json, json);
11101 else
11102 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11103 use_json, json);
11104 } else {
11105 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11106 json);
11107 }
11108 json_object_free(json);
11109 } else {
11110 if (use_json)
11111 vty_out(vty, "{}\n");
11112 else
11113 vty_out(vty, "%% BGP instance not found\n");
11114 }
11115
11116 return CMD_SUCCESS;
11117 }
11118
11119 /* "show [ip] bgp neighbors" commands. */
11120 DEFUN (show_ip_bgp_neighbors,
11121 show_ip_bgp_neighbors_cmd,
11122 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11123 SHOW_STR
11124 IP_STR
11125 BGP_STR
11126 BGP_INSTANCE_HELP_STR
11127 "Address Family\n"
11128 "Address Family\n"
11129 "Detailed information on TCP and BGP neighbor connections\n"
11130 "Neighbor to display information about\n"
11131 "Neighbor to display information about\n"
11132 "Neighbor on BGP configured interface\n"
11133 JSON_STR)
11134 {
11135 char *vrf = NULL;
11136 char *sh_arg = NULL;
11137 enum show_type sh_type;
11138 afi_t afi = AFI_MAX;
11139
11140 bool uj = use_json(argc, argv);
11141
11142 int idx = 0;
11143
11144 /* [<vrf> VIEWVRFNAME] */
11145 if (argv_find(argv, argc, "vrf", &idx)) {
11146 vrf = argv[idx + 1]->arg;
11147 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11148 vrf = NULL;
11149 } else if (argv_find(argv, argc, "view", &idx))
11150 /* [<view> VIEWVRFNAME] */
11151 vrf = argv[idx + 1]->arg;
11152
11153 idx++;
11154
11155 if (argv_find(argv, argc, "ipv4", &idx)) {
11156 sh_type = show_ipv4_all;
11157 afi = AFI_IP;
11158 } else if (argv_find(argv, argc, "ipv6", &idx)) {
11159 sh_type = show_ipv6_all;
11160 afi = AFI_IP6;
11161 } else {
11162 sh_type = show_all;
11163 }
11164
11165 if (argv_find(argv, argc, "A.B.C.D", &idx)
11166 || argv_find(argv, argc, "X:X::X:X", &idx)
11167 || argv_find(argv, argc, "WORD", &idx)) {
11168 sh_type = show_peer;
11169 sh_arg = argv[idx]->arg;
11170 }
11171
11172 if (sh_type == show_peer && afi == AFI_IP) {
11173 sh_type = show_ipv4_peer;
11174 } else if (sh_type == show_peer && afi == AFI_IP6) {
11175 sh_type = show_ipv6_peer;
11176 }
11177
11178 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11179 }
11180
11181 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11182 paths' and `show ip mbgp paths'. Those functions results are the
11183 same.*/
11184 DEFUN (show_ip_bgp_paths,
11185 show_ip_bgp_paths_cmd,
11186 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11187 SHOW_STR
11188 IP_STR
11189 BGP_STR
11190 BGP_SAFI_HELP_STR
11191 "Path information\n")
11192 {
11193 vty_out(vty, "Address Refcnt Path\n");
11194 aspath_print_all_vty(vty);
11195 return CMD_SUCCESS;
11196 }
11197
11198 #include "hash.h"
11199
11200 static void community_show_all_iterator(struct hash_bucket *bucket,
11201 struct vty *vty)
11202 {
11203 struct community *com;
11204
11205 com = (struct community *)bucket->data;
11206 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11207 community_str(com, false));
11208 }
11209
11210 /* Show BGP's community internal data. */
11211 DEFUN (show_ip_bgp_community_info,
11212 show_ip_bgp_community_info_cmd,
11213 "show [ip] bgp community-info",
11214 SHOW_STR
11215 IP_STR
11216 BGP_STR
11217 "List all bgp community information\n")
11218 {
11219 vty_out(vty, "Address Refcnt Community\n");
11220
11221 hash_iterate(community_hash(),
11222 (void (*)(struct hash_bucket *,
11223 void *))community_show_all_iterator,
11224 vty);
11225
11226 return CMD_SUCCESS;
11227 }
11228
11229 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11230 struct vty *vty)
11231 {
11232 struct lcommunity *lcom;
11233
11234 lcom = (struct lcommunity *)bucket->data;
11235 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11236 lcommunity_str(lcom, false));
11237 }
11238
11239 /* Show BGP's community internal data. */
11240 DEFUN (show_ip_bgp_lcommunity_info,
11241 show_ip_bgp_lcommunity_info_cmd,
11242 "show ip bgp large-community-info",
11243 SHOW_STR
11244 IP_STR
11245 BGP_STR
11246 "List all bgp large-community information\n")
11247 {
11248 vty_out(vty, "Address Refcnt Large-community\n");
11249
11250 hash_iterate(lcommunity_hash(),
11251 (void (*)(struct hash_bucket *,
11252 void *))lcommunity_show_all_iterator,
11253 vty);
11254
11255 return CMD_SUCCESS;
11256 }
11257
11258
11259 DEFUN (show_ip_bgp_attr_info,
11260 show_ip_bgp_attr_info_cmd,
11261 "show [ip] bgp attribute-info",
11262 SHOW_STR
11263 IP_STR
11264 BGP_STR
11265 "List all bgp attribute information\n")
11266 {
11267 attr_show_all(vty);
11268 return CMD_SUCCESS;
11269 }
11270
11271 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
11272 afi_t afi, safi_t safi,
11273 bool use_json, json_object *json)
11274 {
11275 struct bgp *bgp;
11276 struct listnode *node;
11277 char *vname;
11278 char buf1[INET6_ADDRSTRLEN];
11279 char *ecom_str;
11280 vpn_policy_direction_t dir;
11281
11282 if (json) {
11283 json_object *json_import_vrfs = NULL;
11284 json_object *json_export_vrfs = NULL;
11285
11286 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11287
11288 if (!bgp) {
11289 vty_out(vty, "%s\n",
11290 json_object_to_json_string_ext(
11291 json,
11292 JSON_C_TO_STRING_PRETTY));
11293 json_object_free(json);
11294
11295 return CMD_WARNING;
11296 }
11297
11298 /* Provide context for the block */
11299 json_object_string_add(json, "vrf", name ? name : "default");
11300 json_object_string_add(json, "afiSafi",
11301 afi_safi_print(afi, safi));
11302
11303 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11304 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11305 json_object_string_add(json, "importFromVrfs", "none");
11306 json_object_string_add(json, "importRts", "none");
11307 } else {
11308 json_import_vrfs = json_object_new_array();
11309
11310 for (ALL_LIST_ELEMENTS_RO(
11311 bgp->vpn_policy[afi].import_vrf,
11312 node, vname))
11313 json_object_array_add(json_import_vrfs,
11314 json_object_new_string(vname));
11315
11316 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11317 ecom_str = ecommunity_ecom2str(
11318 bgp->vpn_policy[afi].rtlist[dir],
11319 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11320 json_object_object_add(json, "importFromVrfs",
11321 json_import_vrfs);
11322 json_object_string_add(json, "importRts", ecom_str);
11323
11324 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11325 }
11326
11327 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11328 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11329 json_object_string_add(json, "exportToVrfs", "none");
11330 json_object_string_add(json, "routeDistinguisher",
11331 "none");
11332 json_object_string_add(json, "exportRts", "none");
11333 } else {
11334 json_export_vrfs = json_object_new_array();
11335
11336 for (ALL_LIST_ELEMENTS_RO(
11337 bgp->vpn_policy[afi].export_vrf,
11338 node, vname))
11339 json_object_array_add(json_export_vrfs,
11340 json_object_new_string(vname));
11341 json_object_object_add(json, "exportToVrfs",
11342 json_export_vrfs);
11343 json_object_string_add(json, "routeDistinguisher",
11344 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11345 buf1, RD_ADDRSTRLEN));
11346
11347 dir = BGP_VPN_POLICY_DIR_TOVPN;
11348 ecom_str = ecommunity_ecom2str(
11349 bgp->vpn_policy[afi].rtlist[dir],
11350 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11351 json_object_string_add(json, "exportRts", ecom_str);
11352
11353 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11354 }
11355
11356 if (use_json) {
11357 vty_out(vty, "%s\n",
11358 json_object_to_json_string_ext(json,
11359 JSON_C_TO_STRING_PRETTY));
11360 json_object_free(json);
11361 }
11362 } else {
11363 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11364
11365 if (!bgp) {
11366 vty_out(vty, "%% No such BGP instance exist\n");
11367 return CMD_WARNING;
11368 }
11369
11370 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11371 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11372 vty_out(vty,
11373 "This VRF is not importing %s routes from any other VRF\n",
11374 afi_safi_print(afi, safi));
11375 else {
11376 vty_out(vty,
11377 "This VRF is importing %s routes from the following VRFs:\n",
11378 afi_safi_print(afi, safi));
11379
11380 for (ALL_LIST_ELEMENTS_RO(
11381 bgp->vpn_policy[afi].import_vrf,
11382 node, vname))
11383 vty_out(vty, " %s\n", vname);
11384
11385 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11386 ecom_str = ecommunity_ecom2str(
11387 bgp->vpn_policy[afi].rtlist[dir],
11388 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11389 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11390
11391 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11392 }
11393
11394 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11395 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11396 vty_out(vty,
11397 "This VRF is not exporting %s routes to any other VRF\n",
11398 afi_safi_print(afi, safi));
11399 else {
11400 vty_out(vty,
11401 "This VRF is exporting %s routes to the following VRFs:\n",
11402 afi_safi_print(afi, safi));
11403
11404 for (ALL_LIST_ELEMENTS_RO(
11405 bgp->vpn_policy[afi].export_vrf,
11406 node, vname))
11407 vty_out(vty, " %s\n", vname);
11408
11409 vty_out(vty, "RD: %s\n",
11410 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11411 buf1, RD_ADDRSTRLEN));
11412
11413 dir = BGP_VPN_POLICY_DIR_TOVPN;
11414 ecom_str = ecommunity_ecom2str(
11415 bgp->vpn_policy[afi].rtlist[dir],
11416 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11417 vty_out(vty, "Export RT: %s\n", ecom_str);
11418 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11419 }
11420 }
11421
11422 return CMD_SUCCESS;
11423 }
11424
11425 static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,
11426 safi_t safi, bool use_json)
11427 {
11428 struct listnode *node, *nnode;
11429 struct bgp *bgp;
11430 char *vrf_name = NULL;
11431 json_object *json = NULL;
11432 json_object *json_vrf = NULL;
11433 json_object *json_vrfs = NULL;
11434
11435 if (use_json) {
11436 json = json_object_new_object();
11437 json_vrfs = json_object_new_object();
11438 }
11439
11440 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11441
11442 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)
11443 vrf_name = bgp->name;
11444
11445 if (use_json) {
11446 json_vrf = json_object_new_object();
11447 } else {
11448 vty_out(vty, "\nInstance %s:\n",
11449 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11450 ? VRF_DEFAULT_NAME : bgp->name);
11451 }
11452 bgp_show_route_leak_vty(vty, vrf_name, afi, safi, 0, json_vrf);
11453 if (use_json) {
11454 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11455 json_object_object_add(json_vrfs,
11456 VRF_DEFAULT_NAME, json_vrf);
11457 else
11458 json_object_object_add(json_vrfs, vrf_name,
11459 json_vrf);
11460 }
11461 }
11462
11463 if (use_json) {
11464 json_object_object_add(json, "vrfs", json_vrfs);
11465 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
11466 JSON_C_TO_STRING_PRETTY));
11467 json_object_free(json);
11468 }
11469
11470 return CMD_SUCCESS;
11471 }
11472
11473 /* "show [ip] bgp route-leak" command. */
11474 DEFUN (show_ip_bgp_route_leak,
11475 show_ip_bgp_route_leak_cmd,
11476 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11477 SHOW_STR
11478 IP_STR
11479 BGP_STR
11480 BGP_INSTANCE_HELP_STR
11481 BGP_AFI_HELP_STR
11482 BGP_SAFI_HELP_STR
11483 "Route leaking information\n"
11484 JSON_STR)
11485 {
11486 char *vrf = NULL;
11487 afi_t afi = AFI_MAX;
11488 safi_t safi = SAFI_MAX;
11489
11490 bool uj = use_json(argc, argv);
11491 int idx = 0;
11492 json_object *json = NULL;
11493
11494 /* show [ip] bgp */
11495 if (argv_find(argv, argc, "ip", &idx)) {
11496 afi = AFI_IP;
11497 safi = SAFI_UNICAST;
11498 }
11499 /* [vrf VIEWVRFNAME] */
11500 if (argv_find(argv, argc, "view", &idx)) {
11501 vty_out(vty,
11502 "%% This command is not applicable to BGP views\n");
11503 return CMD_WARNING;
11504 }
11505
11506 if (argv_find(argv, argc, "vrf", &idx)) {
11507 vrf = argv[idx + 1]->arg;
11508 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11509 vrf = NULL;
11510 }
11511 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11512 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11513 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11514 }
11515
11516 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11517 vty_out(vty,
11518 "%% This command is applicable only for unicast ipv4|ipv6\n");
11519 return CMD_WARNING;
11520 }
11521
11522 if (vrf && strmatch(vrf, "all"))
11523 return bgp_show_all_instance_route_leak_vty(vty, afi, safi, uj);
11524
11525 if (uj)
11526 json = json_object_new_object();
11527
11528 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj, json);
11529 }
11530
11531 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11532 safi_t safi)
11533 {
11534 struct listnode *node, *nnode;
11535 struct bgp *bgp;
11536
11537 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11538 vty_out(vty, "\nInstance %s:\n",
11539 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11540 ? VRF_DEFAULT_NAME
11541 : bgp->name);
11542 update_group_show(bgp, afi, safi, vty, 0);
11543 }
11544 }
11545
11546 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11547 int safi, uint64_t subgrp_id)
11548 {
11549 struct bgp *bgp;
11550
11551 if (name) {
11552 if (strmatch(name, "all")) {
11553 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11554 return CMD_SUCCESS;
11555 } else {
11556 bgp = bgp_lookup_by_name(name);
11557 }
11558 } else {
11559 bgp = bgp_get_default();
11560 }
11561
11562 if (bgp)
11563 update_group_show(bgp, afi, safi, vty, subgrp_id);
11564 return CMD_SUCCESS;
11565 }
11566
11567 DEFUN (show_ip_bgp_updgrps,
11568 show_ip_bgp_updgrps_cmd,
11569 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11570 SHOW_STR
11571 IP_STR
11572 BGP_STR
11573 BGP_INSTANCE_HELP_STR
11574 BGP_AFI_HELP_STR
11575 BGP_SAFI_WITH_LABEL_HELP_STR
11576 "Detailed info about dynamic update groups\n"
11577 "Specific subgroup to display detailed info for\n")
11578 {
11579 char *vrf = NULL;
11580 afi_t afi = AFI_IP6;
11581 safi_t safi = SAFI_UNICAST;
11582 uint64_t subgrp_id = 0;
11583
11584 int idx = 0;
11585
11586 /* show [ip] bgp */
11587 if (argv_find(argv, argc, "ip", &idx))
11588 afi = AFI_IP;
11589 /* [<vrf> VIEWVRFNAME] */
11590 if (argv_find(argv, argc, "vrf", &idx)) {
11591 vrf = argv[idx + 1]->arg;
11592 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11593 vrf = NULL;
11594 } else if (argv_find(argv, argc, "view", &idx))
11595 /* [<view> VIEWVRFNAME] */
11596 vrf = argv[idx + 1]->arg;
11597 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11598 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11599 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11600 }
11601
11602 /* get subgroup id, if provided */
11603 idx = argc - 1;
11604 if (argv[idx]->type == VARIABLE_TKN)
11605 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11606
11607 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11608 }
11609
11610 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11611 show_bgp_instance_all_ipv6_updgrps_cmd,
11612 "show [ip] bgp <view|vrf> all update-groups",
11613 SHOW_STR
11614 IP_STR
11615 BGP_STR
11616 BGP_INSTANCE_ALL_HELP_STR
11617 "Detailed info about dynamic update groups\n")
11618 {
11619 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11620 return CMD_SUCCESS;
11621 }
11622
11623 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11624 show_bgp_l2vpn_evpn_updgrps_cmd,
11625 "show [ip] bgp l2vpn evpn update-groups",
11626 SHOW_STR
11627 IP_STR
11628 BGP_STR
11629 "l2vpn address family\n"
11630 "evpn sub-address family\n"
11631 "Detailed info about dynamic update groups\n")
11632 {
11633 char *vrf = NULL;
11634 uint64_t subgrp_id = 0;
11635
11636 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11637 return CMD_SUCCESS;
11638 }
11639
11640 DEFUN (show_bgp_updgrps_stats,
11641 show_bgp_updgrps_stats_cmd,
11642 "show [ip] bgp update-groups statistics",
11643 SHOW_STR
11644 IP_STR
11645 BGP_STR
11646 "Detailed info about dynamic update groups\n"
11647 "Statistics\n")
11648 {
11649 struct bgp *bgp;
11650
11651 bgp = bgp_get_default();
11652 if (bgp)
11653 update_group_show_stats(bgp, vty);
11654
11655 return CMD_SUCCESS;
11656 }
11657
11658 DEFUN (show_bgp_instance_updgrps_stats,
11659 show_bgp_instance_updgrps_stats_cmd,
11660 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11661 SHOW_STR
11662 IP_STR
11663 BGP_STR
11664 BGP_INSTANCE_HELP_STR
11665 "Detailed info about dynamic update groups\n"
11666 "Statistics\n")
11667 {
11668 int idx_word = 3;
11669 struct bgp *bgp;
11670
11671 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11672 if (bgp)
11673 update_group_show_stats(bgp, vty);
11674
11675 return CMD_SUCCESS;
11676 }
11677
11678 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11679 afi_t afi, safi_t safi,
11680 const char *what, uint64_t subgrp_id)
11681 {
11682 struct bgp *bgp;
11683
11684 if (name)
11685 bgp = bgp_lookup_by_name(name);
11686 else
11687 bgp = bgp_get_default();
11688
11689 if (bgp) {
11690 if (!strcmp(what, "advertise-queue"))
11691 update_group_show_adj_queue(bgp, afi, safi, vty,
11692 subgrp_id);
11693 else if (!strcmp(what, "advertised-routes"))
11694 update_group_show_advertised(bgp, afi, safi, vty,
11695 subgrp_id);
11696 else if (!strcmp(what, "packet-queue"))
11697 update_group_show_packet_queue(bgp, afi, safi, vty,
11698 subgrp_id);
11699 }
11700 }
11701
11702 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11703 show_ip_bgp_instance_updgrps_adj_s_cmd,
11704 "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",
11705 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11706 BGP_SAFI_HELP_STR
11707 "Detailed info about dynamic update groups\n"
11708 "Specific subgroup to display info for\n"
11709 "Advertisement queue\n"
11710 "Announced routes\n"
11711 "Packet queue\n")
11712 {
11713 uint64_t subgrp_id = 0;
11714 afi_t afiz;
11715 safi_t safiz;
11716 if (sgid)
11717 subgrp_id = strtoull(sgid, NULL, 10);
11718
11719 if (!ip && !afi)
11720 afiz = AFI_IP6;
11721 if (!ip && afi)
11722 afiz = bgp_vty_afi_from_str(afi);
11723 if (ip && !afi)
11724 afiz = AFI_IP;
11725 if (ip && afi) {
11726 afiz = bgp_vty_afi_from_str(afi);
11727 if (afiz != AFI_IP)
11728 vty_out(vty,
11729 "%% Cannot specify both 'ip' and 'ipv6'\n");
11730 return CMD_WARNING;
11731 }
11732
11733 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11734
11735 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11736 return CMD_SUCCESS;
11737 }
11738
11739 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11740 {
11741 struct listnode *node, *nnode;
11742 struct prefix *range;
11743 struct peer *conf;
11744 struct peer *peer;
11745 char buf[PREFIX2STR_BUFFER];
11746 afi_t afi;
11747 safi_t safi;
11748 const char *peer_status;
11749 const char *af_str;
11750 int lr_count;
11751 int dynamic;
11752 int af_cfgd;
11753
11754 conf = group->conf;
11755
11756 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11757 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11758 group->name, conf->as);
11759 } else if (conf->as_type == AS_INTERNAL) {
11760 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11761 group->name, group->bgp->as);
11762 } else {
11763 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11764 }
11765
11766 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11767 vty_out(vty, " Peer-group type is internal\n");
11768 else
11769 vty_out(vty, " Peer-group type is external\n");
11770
11771 /* Display AFs configured. */
11772 vty_out(vty, " Configured address-families:");
11773 FOREACH_AFI_SAFI (afi, safi) {
11774 if (conf->afc[afi][safi]) {
11775 af_cfgd = 1;
11776 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11777 }
11778 }
11779 if (!af_cfgd)
11780 vty_out(vty, " none\n");
11781 else
11782 vty_out(vty, "\n");
11783
11784 /* Display listen ranges (for dynamic neighbors), if any */
11785 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11786 if (afi == AFI_IP)
11787 af_str = "IPv4";
11788 else if (afi == AFI_IP6)
11789 af_str = "IPv6";
11790 else
11791 af_str = "???";
11792 lr_count = listcount(group->listen_range[afi]);
11793 if (lr_count) {
11794 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11795 af_str);
11796
11797
11798 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11799 nnode, range)) {
11800 prefix2str(range, buf, sizeof(buf));
11801 vty_out(vty, " %s\n", buf);
11802 }
11803 }
11804 }
11805
11806 /* Display group members and their status */
11807 if (listcount(group->peer)) {
11808 vty_out(vty, " Peer-group members:\n");
11809 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11810 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11811 peer_status = "Idle (Admin)";
11812 else if (CHECK_FLAG(peer->sflags,
11813 PEER_STATUS_PREFIX_OVERFLOW))
11814 peer_status = "Idle (PfxCt)";
11815 else
11816 peer_status = lookup_msg(bgp_status_msg,
11817 peer->status, NULL);
11818
11819 dynamic = peer_dynamic_neighbor(peer);
11820 vty_out(vty, " %s %s %s \n", peer->host,
11821 dynamic ? "(dynamic)" : "", peer_status);
11822 }
11823 }
11824
11825 return CMD_SUCCESS;
11826 }
11827
11828 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11829 const char *group_name)
11830 {
11831 struct bgp *bgp;
11832 struct listnode *node, *nnode;
11833 struct peer_group *group;
11834 bool found = false;
11835
11836 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11837
11838 if (!bgp) {
11839 vty_out(vty, "%% BGP instance not found\n");
11840 return CMD_WARNING;
11841 }
11842
11843 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11844 if (group_name) {
11845 if (strmatch(group->name, group_name)) {
11846 bgp_show_one_peer_group(vty, group);
11847 found = true;
11848 break;
11849 }
11850 } else {
11851 bgp_show_one_peer_group(vty, group);
11852 }
11853 }
11854
11855 if (group_name && !found)
11856 vty_out(vty, "%% No such peer-group\n");
11857
11858 return CMD_SUCCESS;
11859 }
11860
11861 DEFUN (show_ip_bgp_peer_groups,
11862 show_ip_bgp_peer_groups_cmd,
11863 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11864 SHOW_STR
11865 IP_STR
11866 BGP_STR
11867 BGP_INSTANCE_HELP_STR
11868 "Detailed information on BGP peer groups\n"
11869 "Peer group name\n")
11870 {
11871 char *vrf, *pg;
11872 int idx = 0;
11873
11874 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11875 : NULL;
11876 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11877
11878 return bgp_show_peer_group_vty(vty, vrf, pg);
11879 }
11880
11881
11882 /* Redistribute VTY commands. */
11883
11884 DEFUN (bgp_redistribute_ipv4,
11885 bgp_redistribute_ipv4_cmd,
11886 "redistribute " FRR_IP_REDIST_STR_BGPD,
11887 "Redistribute information from another routing protocol\n"
11888 FRR_IP_REDIST_HELP_STR_BGPD)
11889 {
11890 VTY_DECLVAR_CONTEXT(bgp, bgp);
11891 int idx_protocol = 1;
11892 int type;
11893
11894 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11895 if (type < 0) {
11896 vty_out(vty, "%% Invalid route type\n");
11897 return CMD_WARNING_CONFIG_FAILED;
11898 }
11899
11900 bgp_redist_add(bgp, AFI_IP, type, 0);
11901 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11902 }
11903
11904 ALIAS_HIDDEN(
11905 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11906 "redistribute " FRR_IP_REDIST_STR_BGPD,
11907 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11908
11909 DEFUN (bgp_redistribute_ipv4_rmap,
11910 bgp_redistribute_ipv4_rmap_cmd,
11911 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11912 "Redistribute information from another routing protocol\n"
11913 FRR_IP_REDIST_HELP_STR_BGPD
11914 "Route map reference\n"
11915 "Pointer to route-map entries\n")
11916 {
11917 VTY_DECLVAR_CONTEXT(bgp, bgp);
11918 int idx_protocol = 1;
11919 int idx_word = 3;
11920 int type;
11921 struct bgp_redist *red;
11922 bool changed;
11923 struct route_map *route_map = route_map_lookup_warn_noexist(
11924 vty, argv[idx_word]->arg);
11925
11926 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11927 if (type < 0) {
11928 vty_out(vty, "%% Invalid route type\n");
11929 return CMD_WARNING_CONFIG_FAILED;
11930 }
11931
11932 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11933 changed =
11934 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11935 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11936 }
11937
11938 ALIAS_HIDDEN(
11939 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11940 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11941 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11942 "Route map reference\n"
11943 "Pointer to route-map entries\n")
11944
11945 DEFUN (bgp_redistribute_ipv4_metric,
11946 bgp_redistribute_ipv4_metric_cmd,
11947 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11948 "Redistribute information from another routing protocol\n"
11949 FRR_IP_REDIST_HELP_STR_BGPD
11950 "Metric for redistributed routes\n"
11951 "Default metric\n")
11952 {
11953 VTY_DECLVAR_CONTEXT(bgp, bgp);
11954 int idx_protocol = 1;
11955 int idx_number = 3;
11956 int type;
11957 uint32_t metric;
11958 struct bgp_redist *red;
11959 bool changed;
11960
11961 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11962 if (type < 0) {
11963 vty_out(vty, "%% Invalid route type\n");
11964 return CMD_WARNING_CONFIG_FAILED;
11965 }
11966 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11967
11968 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11969 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11970 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11971 }
11972
11973 ALIAS_HIDDEN(
11974 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11975 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11976 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11977 "Metric for redistributed routes\n"
11978 "Default metric\n")
11979
11980 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11981 bgp_redistribute_ipv4_rmap_metric_cmd,
11982 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11983 "Redistribute information from another routing protocol\n"
11984 FRR_IP_REDIST_HELP_STR_BGPD
11985 "Route map reference\n"
11986 "Pointer to route-map entries\n"
11987 "Metric for redistributed routes\n"
11988 "Default metric\n")
11989 {
11990 VTY_DECLVAR_CONTEXT(bgp, bgp);
11991 int idx_protocol = 1;
11992 int idx_word = 3;
11993 int idx_number = 5;
11994 int type;
11995 uint32_t metric;
11996 struct bgp_redist *red;
11997 bool changed;
11998 struct route_map *route_map =
11999 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12000
12001 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12002 if (type < 0) {
12003 vty_out(vty, "%% Invalid route type\n");
12004 return CMD_WARNING_CONFIG_FAILED;
12005 }
12006 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12007
12008 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12009 changed =
12010 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12011 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12012 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12013 }
12014
12015 ALIAS_HIDDEN(
12016 bgp_redistribute_ipv4_rmap_metric,
12017 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
12018 "redistribute " FRR_IP_REDIST_STR_BGPD
12019 " route-map WORD metric (0-4294967295)",
12020 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12021 "Route map reference\n"
12022 "Pointer to route-map entries\n"
12023 "Metric for redistributed routes\n"
12024 "Default metric\n")
12025
12026 DEFUN (bgp_redistribute_ipv4_metric_rmap,
12027 bgp_redistribute_ipv4_metric_rmap_cmd,
12028 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12029 "Redistribute information from another routing protocol\n"
12030 FRR_IP_REDIST_HELP_STR_BGPD
12031 "Metric for redistributed routes\n"
12032 "Default metric\n"
12033 "Route map reference\n"
12034 "Pointer to route-map entries\n")
12035 {
12036 VTY_DECLVAR_CONTEXT(bgp, bgp);
12037 int idx_protocol = 1;
12038 int idx_number = 3;
12039 int idx_word = 5;
12040 int type;
12041 uint32_t metric;
12042 struct bgp_redist *red;
12043 bool changed;
12044 struct route_map *route_map =
12045 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12046
12047 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12048 if (type < 0) {
12049 vty_out(vty, "%% Invalid route type\n");
12050 return CMD_WARNING_CONFIG_FAILED;
12051 }
12052 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12053
12054 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12055 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12056 changed |=
12057 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12058 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12059 }
12060
12061 ALIAS_HIDDEN(
12062 bgp_redistribute_ipv4_metric_rmap,
12063 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12064 "redistribute " FRR_IP_REDIST_STR_BGPD
12065 " metric (0-4294967295) route-map WORD",
12066 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12067 "Metric for redistributed routes\n"
12068 "Default metric\n"
12069 "Route map reference\n"
12070 "Pointer to route-map entries\n")
12071
12072 DEFUN (bgp_redistribute_ipv4_ospf,
12073 bgp_redistribute_ipv4_ospf_cmd,
12074 "redistribute <ospf|table> (1-65535)",
12075 "Redistribute information from another routing protocol\n"
12076 "Open Shortest Path First (OSPFv2)\n"
12077 "Non-main Kernel Routing Table\n"
12078 "Instance ID/Table ID\n")
12079 {
12080 VTY_DECLVAR_CONTEXT(bgp, bgp);
12081 int idx_ospf_table = 1;
12082 int idx_number = 2;
12083 unsigned short instance;
12084 unsigned short protocol;
12085
12086 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12087
12088 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12089 protocol = ZEBRA_ROUTE_OSPF;
12090 else
12091 protocol = ZEBRA_ROUTE_TABLE;
12092
12093 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12094 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12095 }
12096
12097 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12098 "redistribute <ospf|table> (1-65535)",
12099 "Redistribute information from another routing protocol\n"
12100 "Open Shortest Path First (OSPFv2)\n"
12101 "Non-main Kernel Routing Table\n"
12102 "Instance ID/Table ID\n")
12103
12104 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12105 bgp_redistribute_ipv4_ospf_rmap_cmd,
12106 "redistribute <ospf|table> (1-65535) route-map WORD",
12107 "Redistribute information from another routing protocol\n"
12108 "Open Shortest Path First (OSPFv2)\n"
12109 "Non-main Kernel Routing Table\n"
12110 "Instance ID/Table ID\n"
12111 "Route map reference\n"
12112 "Pointer to route-map entries\n")
12113 {
12114 VTY_DECLVAR_CONTEXT(bgp, bgp);
12115 int idx_ospf_table = 1;
12116 int idx_number = 2;
12117 int idx_word = 4;
12118 struct bgp_redist *red;
12119 unsigned short instance;
12120 int protocol;
12121 bool changed;
12122 struct route_map *route_map =
12123 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12124
12125 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12126 protocol = ZEBRA_ROUTE_OSPF;
12127 else
12128 protocol = ZEBRA_ROUTE_TABLE;
12129
12130 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12131 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12132 changed =
12133 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12134 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12135 }
12136
12137 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12138 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12139 "redistribute <ospf|table> (1-65535) route-map WORD",
12140 "Redistribute information from another routing protocol\n"
12141 "Open Shortest Path First (OSPFv2)\n"
12142 "Non-main Kernel Routing Table\n"
12143 "Instance ID/Table ID\n"
12144 "Route map reference\n"
12145 "Pointer to route-map entries\n")
12146
12147 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12148 bgp_redistribute_ipv4_ospf_metric_cmd,
12149 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12150 "Redistribute information from another routing protocol\n"
12151 "Open Shortest Path First (OSPFv2)\n"
12152 "Non-main Kernel Routing Table\n"
12153 "Instance ID/Table ID\n"
12154 "Metric for redistributed routes\n"
12155 "Default metric\n")
12156 {
12157 VTY_DECLVAR_CONTEXT(bgp, bgp);
12158 int idx_ospf_table = 1;
12159 int idx_number = 2;
12160 int idx_number_2 = 4;
12161 uint32_t metric;
12162 struct bgp_redist *red;
12163 unsigned short instance;
12164 int protocol;
12165 bool changed;
12166
12167 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12168 protocol = ZEBRA_ROUTE_OSPF;
12169 else
12170 protocol = ZEBRA_ROUTE_TABLE;
12171
12172 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12173 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12174
12175 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12176 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12177 metric);
12178 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12179 }
12180
12181 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12182 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12183 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12184 "Redistribute information from another routing protocol\n"
12185 "Open Shortest Path First (OSPFv2)\n"
12186 "Non-main Kernel Routing Table\n"
12187 "Instance ID/Table ID\n"
12188 "Metric for redistributed routes\n"
12189 "Default metric\n")
12190
12191 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12192 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12193 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12194 "Redistribute information from another routing protocol\n"
12195 "Open Shortest Path First (OSPFv2)\n"
12196 "Non-main Kernel Routing Table\n"
12197 "Instance ID/Table ID\n"
12198 "Route map reference\n"
12199 "Pointer to route-map entries\n"
12200 "Metric for redistributed routes\n"
12201 "Default metric\n")
12202 {
12203 VTY_DECLVAR_CONTEXT(bgp, bgp);
12204 int idx_ospf_table = 1;
12205 int idx_number = 2;
12206 int idx_word = 4;
12207 int idx_number_2 = 6;
12208 uint32_t metric;
12209 struct bgp_redist *red;
12210 unsigned short instance;
12211 int protocol;
12212 bool changed;
12213 struct route_map *route_map =
12214 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12215
12216 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12217 protocol = ZEBRA_ROUTE_OSPF;
12218 else
12219 protocol = ZEBRA_ROUTE_TABLE;
12220
12221 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12222 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12223
12224 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12225 changed =
12226 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12227 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12228 metric);
12229 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12230 }
12231
12232 ALIAS_HIDDEN(
12233 bgp_redistribute_ipv4_ospf_rmap_metric,
12234 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12235 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12236 "Redistribute information from another routing protocol\n"
12237 "Open Shortest Path First (OSPFv2)\n"
12238 "Non-main Kernel Routing Table\n"
12239 "Instance ID/Table ID\n"
12240 "Route map reference\n"
12241 "Pointer to route-map entries\n"
12242 "Metric for redistributed routes\n"
12243 "Default metric\n")
12244
12245 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12246 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12247 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12248 "Redistribute information from another routing protocol\n"
12249 "Open Shortest Path First (OSPFv2)\n"
12250 "Non-main Kernel Routing Table\n"
12251 "Instance ID/Table ID\n"
12252 "Metric for redistributed routes\n"
12253 "Default metric\n"
12254 "Route map reference\n"
12255 "Pointer to route-map entries\n")
12256 {
12257 VTY_DECLVAR_CONTEXT(bgp, bgp);
12258 int idx_ospf_table = 1;
12259 int idx_number = 2;
12260 int idx_number_2 = 4;
12261 int idx_word = 6;
12262 uint32_t metric;
12263 struct bgp_redist *red;
12264 unsigned short instance;
12265 int protocol;
12266 bool changed;
12267 struct route_map *route_map =
12268 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12269
12270 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12271 protocol = ZEBRA_ROUTE_OSPF;
12272 else
12273 protocol = ZEBRA_ROUTE_TABLE;
12274
12275 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12276 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12277
12278 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12279 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12280 metric);
12281 changed |=
12282 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12283 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12284 }
12285
12286 ALIAS_HIDDEN(
12287 bgp_redistribute_ipv4_ospf_metric_rmap,
12288 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12289 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12290 "Redistribute information from another routing protocol\n"
12291 "Open Shortest Path First (OSPFv2)\n"
12292 "Non-main Kernel Routing Table\n"
12293 "Instance ID/Table ID\n"
12294 "Metric for redistributed routes\n"
12295 "Default metric\n"
12296 "Route map reference\n"
12297 "Pointer to route-map entries\n")
12298
12299 DEFUN (no_bgp_redistribute_ipv4_ospf,
12300 no_bgp_redistribute_ipv4_ospf_cmd,
12301 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12302 NO_STR
12303 "Redistribute information from another routing protocol\n"
12304 "Open Shortest Path First (OSPFv2)\n"
12305 "Non-main Kernel Routing Table\n"
12306 "Instance ID/Table ID\n"
12307 "Metric for redistributed routes\n"
12308 "Default metric\n"
12309 "Route map reference\n"
12310 "Pointer to route-map entries\n")
12311 {
12312 VTY_DECLVAR_CONTEXT(bgp, bgp);
12313 int idx_ospf_table = 2;
12314 int idx_number = 3;
12315 unsigned short instance;
12316 int protocol;
12317
12318 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12319 protocol = ZEBRA_ROUTE_OSPF;
12320 else
12321 protocol = ZEBRA_ROUTE_TABLE;
12322
12323 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12324 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12325 }
12326
12327 ALIAS_HIDDEN(
12328 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12329 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12330 NO_STR
12331 "Redistribute information from another routing protocol\n"
12332 "Open Shortest Path First (OSPFv2)\n"
12333 "Non-main Kernel Routing Table\n"
12334 "Instance ID/Table ID\n"
12335 "Metric for redistributed routes\n"
12336 "Default metric\n"
12337 "Route map reference\n"
12338 "Pointer to route-map entries\n")
12339
12340 DEFUN (no_bgp_redistribute_ipv4,
12341 no_bgp_redistribute_ipv4_cmd,
12342 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12343 NO_STR
12344 "Redistribute information from another routing protocol\n"
12345 FRR_IP_REDIST_HELP_STR_BGPD
12346 "Metric for redistributed routes\n"
12347 "Default metric\n"
12348 "Route map reference\n"
12349 "Pointer to route-map entries\n")
12350 {
12351 VTY_DECLVAR_CONTEXT(bgp, bgp);
12352 int idx_protocol = 2;
12353 int type;
12354
12355 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12356 if (type < 0) {
12357 vty_out(vty, "%% Invalid route type\n");
12358 return CMD_WARNING_CONFIG_FAILED;
12359 }
12360 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12361 }
12362
12363 ALIAS_HIDDEN(
12364 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12365 "no redistribute " FRR_IP_REDIST_STR_BGPD
12366 " [metric (0-4294967295)] [route-map WORD]",
12367 NO_STR
12368 "Redistribute information from another routing protocol\n" 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 DEFUN (bgp_redistribute_ipv6,
12375 bgp_redistribute_ipv6_cmd,
12376 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12377 "Redistribute information from another routing protocol\n"
12378 FRR_IP6_REDIST_HELP_STR_BGPD)
12379 {
12380 VTY_DECLVAR_CONTEXT(bgp, bgp);
12381 int idx_protocol = 1;
12382 int type;
12383
12384 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12385 if (type < 0) {
12386 vty_out(vty, "%% Invalid route type\n");
12387 return CMD_WARNING_CONFIG_FAILED;
12388 }
12389
12390 bgp_redist_add(bgp, AFI_IP6, type, 0);
12391 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12392 }
12393
12394 DEFUN (bgp_redistribute_ipv6_rmap,
12395 bgp_redistribute_ipv6_rmap_cmd,
12396 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12397 "Redistribute information from another routing protocol\n"
12398 FRR_IP6_REDIST_HELP_STR_BGPD
12399 "Route map reference\n"
12400 "Pointer to route-map entries\n")
12401 {
12402 VTY_DECLVAR_CONTEXT(bgp, bgp);
12403 int idx_protocol = 1;
12404 int idx_word = 3;
12405 int type;
12406 struct bgp_redist *red;
12407 bool changed;
12408 struct route_map *route_map =
12409 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12410
12411 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12412 if (type < 0) {
12413 vty_out(vty, "%% Invalid route type\n");
12414 return CMD_WARNING_CONFIG_FAILED;
12415 }
12416
12417 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12418 changed =
12419 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12420 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12421 }
12422
12423 DEFUN (bgp_redistribute_ipv6_metric,
12424 bgp_redistribute_ipv6_metric_cmd,
12425 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12426 "Redistribute information from another routing protocol\n"
12427 FRR_IP6_REDIST_HELP_STR_BGPD
12428 "Metric for redistributed routes\n"
12429 "Default metric\n")
12430 {
12431 VTY_DECLVAR_CONTEXT(bgp, bgp);
12432 int idx_protocol = 1;
12433 int idx_number = 3;
12434 int type;
12435 uint32_t metric;
12436 struct bgp_redist *red;
12437 bool changed;
12438
12439 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12440 if (type < 0) {
12441 vty_out(vty, "%% Invalid route type\n");
12442 return CMD_WARNING_CONFIG_FAILED;
12443 }
12444 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12445
12446 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12447 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12448 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12449 }
12450
12451 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12452 bgp_redistribute_ipv6_rmap_metric_cmd,
12453 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12454 "Redistribute information from another routing protocol\n"
12455 FRR_IP6_REDIST_HELP_STR_BGPD
12456 "Route map reference\n"
12457 "Pointer to route-map entries\n"
12458 "Metric for redistributed routes\n"
12459 "Default metric\n")
12460 {
12461 VTY_DECLVAR_CONTEXT(bgp, bgp);
12462 int idx_protocol = 1;
12463 int idx_word = 3;
12464 int idx_number = 5;
12465 int type;
12466 uint32_t metric;
12467 struct bgp_redist *red;
12468 bool changed;
12469 struct route_map *route_map =
12470 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12471
12472 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12473 if (type < 0) {
12474 vty_out(vty, "%% Invalid route type\n");
12475 return CMD_WARNING_CONFIG_FAILED;
12476 }
12477 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12478
12479 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12480 changed =
12481 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12482 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12483 metric);
12484 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12485 }
12486
12487 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12488 bgp_redistribute_ipv6_metric_rmap_cmd,
12489 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12490 "Redistribute information from another routing protocol\n"
12491 FRR_IP6_REDIST_HELP_STR_BGPD
12492 "Metric for redistributed routes\n"
12493 "Default metric\n"
12494 "Route map reference\n"
12495 "Pointer to route-map entries\n")
12496 {
12497 VTY_DECLVAR_CONTEXT(bgp, bgp);
12498 int idx_protocol = 1;
12499 int idx_number = 3;
12500 int idx_word = 5;
12501 int type;
12502 uint32_t metric;
12503 struct bgp_redist *red;
12504 bool changed;
12505 struct route_map *route_map =
12506 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12507
12508 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12509 if (type < 0) {
12510 vty_out(vty, "%% Invalid route type\n");
12511 return CMD_WARNING_CONFIG_FAILED;
12512 }
12513 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12514
12515 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12516 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12517 metric);
12518 changed |=
12519 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12520 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12521 }
12522
12523 DEFUN (no_bgp_redistribute_ipv6,
12524 no_bgp_redistribute_ipv6_cmd,
12525 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12526 NO_STR
12527 "Redistribute information from another routing protocol\n"
12528 FRR_IP6_REDIST_HELP_STR_BGPD
12529 "Metric for redistributed routes\n"
12530 "Default metric\n"
12531 "Route map reference\n"
12532 "Pointer to route-map entries\n")
12533 {
12534 VTY_DECLVAR_CONTEXT(bgp, bgp);
12535 int idx_protocol = 2;
12536 int type;
12537
12538 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12539 if (type < 0) {
12540 vty_out(vty, "%% Invalid route type\n");
12541 return CMD_WARNING_CONFIG_FAILED;
12542 }
12543
12544 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12545 }
12546
12547 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12548 safi_t safi)
12549 {
12550 int i;
12551
12552 /* Unicast redistribution only. */
12553 if (safi != SAFI_UNICAST)
12554 return;
12555
12556 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12557 /* Redistribute BGP does not make sense. */
12558 if (i != ZEBRA_ROUTE_BGP) {
12559 struct list *red_list;
12560 struct listnode *node;
12561 struct bgp_redist *red;
12562
12563 red_list = bgp->redist[afi][i];
12564 if (!red_list)
12565 continue;
12566
12567 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12568 /* "redistribute" configuration. */
12569 vty_out(vty, " redistribute %s",
12570 zebra_route_string(i));
12571 if (red->instance)
12572 vty_out(vty, " %d", red->instance);
12573 if (red->redist_metric_flag)
12574 vty_out(vty, " metric %u",
12575 red->redist_metric);
12576 if (red->rmap.name)
12577 vty_out(vty, " route-map %s",
12578 red->rmap.name);
12579 vty_out(vty, "\n");
12580 }
12581 }
12582 }
12583 }
12584
12585 /* This is part of the address-family block (unicast only) */
12586 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12587 afi_t afi)
12588 {
12589 int indent = 2;
12590
12591 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12592 if (listcount(bgp->vpn_policy[afi].import_vrf))
12593 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12594 bgp->vpn_policy[afi]
12595 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12596 else
12597 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12598 bgp->vpn_policy[afi]
12599 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12600 }
12601 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12602 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12603 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12604 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12605 return;
12606
12607 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12608 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12609
12610 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12611
12612 } else {
12613 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12614 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12615 bgp->vpn_policy[afi].tovpn_label);
12616 }
12617 }
12618 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12619 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12620 char buf[RD_ADDRSTRLEN];
12621 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12622 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12623 sizeof(buf)));
12624 }
12625 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12626 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12627
12628 char buf[PREFIX_STRLEN];
12629 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12630 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12631 sizeof(buf))) {
12632
12633 vty_out(vty, "%*snexthop vpn export %s\n",
12634 indent, "", buf);
12635 }
12636 }
12637 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12638 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12639 && ecommunity_cmp(
12640 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12641 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12642
12643 char *b = ecommunity_ecom2str(
12644 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12645 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12646 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12647 XFREE(MTYPE_ECOMMUNITY_STR, b);
12648 } else {
12649 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12650 char *b = ecommunity_ecom2str(
12651 bgp->vpn_policy[afi]
12652 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12653 ECOMMUNITY_FORMAT_ROUTE_MAP,
12654 ECOMMUNITY_ROUTE_TARGET);
12655 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12656 XFREE(MTYPE_ECOMMUNITY_STR, b);
12657 }
12658 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12659 char *b = ecommunity_ecom2str(
12660 bgp->vpn_policy[afi]
12661 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12662 ECOMMUNITY_FORMAT_ROUTE_MAP,
12663 ECOMMUNITY_ROUTE_TARGET);
12664 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12665 XFREE(MTYPE_ECOMMUNITY_STR, b);
12666 }
12667 }
12668
12669 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12670 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12671 bgp->vpn_policy[afi]
12672 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12673
12674 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12675 char *b = ecommunity_ecom2str(
12676 bgp->vpn_policy[afi]
12677 .import_redirect_rtlist,
12678 ECOMMUNITY_FORMAT_ROUTE_MAP,
12679 ECOMMUNITY_ROUTE_TARGET);
12680
12681 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12682 XFREE(MTYPE_ECOMMUNITY_STR, b);
12683 }
12684 }
12685
12686
12687 /* BGP node structure. */
12688 static struct cmd_node bgp_node = {
12689 BGP_NODE, "%s(config-router)# ", 1,
12690 };
12691
12692 static struct cmd_node bgp_ipv4_unicast_node = {
12693 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12694 };
12695
12696 static struct cmd_node bgp_ipv4_multicast_node = {
12697 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12698 };
12699
12700 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12701 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12702 };
12703
12704 static struct cmd_node bgp_ipv6_unicast_node = {
12705 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12706 };
12707
12708 static struct cmd_node bgp_ipv6_multicast_node = {
12709 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12710 };
12711
12712 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12713 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12714 };
12715
12716 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12717 "%s(config-router-af)# ", 1};
12718
12719 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12720 "%s(config-router-af-vpnv6)# ", 1};
12721
12722 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12723 "%s(config-router-evpn)# ", 1};
12724
12725 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12726 "%s(config-router-af-vni)# ", 1};
12727
12728 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12729 "%s(config-router-af)# ", 1};
12730
12731 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12732 "%s(config-router-af-vpnv6)# ", 1};
12733
12734 static void community_list_vty(void);
12735
12736 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12737 {
12738 struct bgp *bgp;
12739 struct peer *peer;
12740 struct listnode *lnbgp, *lnpeer;
12741
12742 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12743 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12744 /* only provide suggestions on the appropriate input
12745 * token type,
12746 * they'll otherwise show up multiple times */
12747 enum cmd_token_type match_type;
12748 char *name = peer->host;
12749
12750 if (peer->conf_if) {
12751 match_type = VARIABLE_TKN;
12752 name = peer->conf_if;
12753 } else if (strchr(peer->host, ':'))
12754 match_type = IPV6_TKN;
12755 else
12756 match_type = IPV4_TKN;
12757
12758 if (token->type != match_type)
12759 continue;
12760
12761 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12762 }
12763 }
12764 }
12765
12766 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12767 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12768 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12769 {.varname = "peer", .completions = bgp_ac_neighbor},
12770 {.completions = NULL}};
12771
12772 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12773 {
12774 struct bgp *bgp;
12775 struct peer_group *group;
12776 struct listnode *lnbgp, *lnpeer;
12777
12778 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12779 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12780 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12781 group->name));
12782 }
12783 }
12784
12785 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12786 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12787 {.completions = NULL} };
12788
12789 void bgp_vty_init(void)
12790 {
12791 cmd_variable_handler_register(bgp_var_neighbor);
12792 cmd_variable_handler_register(bgp_var_peergroup);
12793
12794 /* Install bgp top node. */
12795 install_node(&bgp_node, bgp_config_write);
12796 install_node(&bgp_ipv4_unicast_node, NULL);
12797 install_node(&bgp_ipv4_multicast_node, NULL);
12798 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12799 install_node(&bgp_ipv6_unicast_node, NULL);
12800 install_node(&bgp_ipv6_multicast_node, NULL);
12801 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12802 install_node(&bgp_vpnv4_node, NULL);
12803 install_node(&bgp_vpnv6_node, NULL);
12804 install_node(&bgp_evpn_node, NULL);
12805 install_node(&bgp_evpn_vni_node, NULL);
12806 install_node(&bgp_flowspecv4_node, NULL);
12807 install_node(&bgp_flowspecv6_node, NULL);
12808
12809 /* Install default VTY commands to new nodes. */
12810 install_default(BGP_NODE);
12811 install_default(BGP_IPV4_NODE);
12812 install_default(BGP_IPV4M_NODE);
12813 install_default(BGP_IPV4L_NODE);
12814 install_default(BGP_IPV6_NODE);
12815 install_default(BGP_IPV6M_NODE);
12816 install_default(BGP_IPV6L_NODE);
12817 install_default(BGP_VPNV4_NODE);
12818 install_default(BGP_VPNV6_NODE);
12819 install_default(BGP_FLOWSPECV4_NODE);
12820 install_default(BGP_FLOWSPECV6_NODE);
12821 install_default(BGP_EVPN_NODE);
12822 install_default(BGP_EVPN_VNI_NODE);
12823
12824 /* "bgp local-mac" hidden commands. */
12825 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12826 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12827
12828 /* bgp route-map delay-timer commands. */
12829 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12830 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12831
12832 /* Dummy commands (Currently not supported) */
12833 install_element(BGP_NODE, &no_synchronization_cmd);
12834 install_element(BGP_NODE, &no_auto_summary_cmd);
12835
12836 /* "router bgp" commands. */
12837 install_element(CONFIG_NODE, &router_bgp_cmd);
12838
12839 /* "no router bgp" commands. */
12840 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12841
12842 /* "bgp router-id" commands. */
12843 install_element(BGP_NODE, &bgp_router_id_cmd);
12844 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12845
12846 /* "bgp cluster-id" commands. */
12847 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12848 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12849
12850 /* "bgp confederation" commands. */
12851 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12852 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12853
12854 /* "bgp confederation peers" commands. */
12855 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12856 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12857
12858 /* bgp max-med command */
12859 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12860 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12861 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12862 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12863 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12864
12865 /* bgp disable-ebgp-connected-nh-check */
12866 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12867 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12868
12869 /* bgp update-delay command */
12870 install_element(BGP_NODE, &bgp_update_delay_cmd);
12871 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12872 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12873
12874 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12875 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12876 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12877 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12878
12879 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12880 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12881
12882 /* "maximum-paths" commands. */
12883 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12884 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12885 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12886 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12887 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12888 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12889 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12890 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12891 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12892 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12893 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12894 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12895 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12896 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12897 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12898
12899 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12900 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12901 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12902 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12903 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12904
12905 /* "timers bgp" commands. */
12906 install_element(BGP_NODE, &bgp_timers_cmd);
12907 install_element(BGP_NODE, &no_bgp_timers_cmd);
12908
12909 /* route-map delay-timer commands - per instance for backwards compat.
12910 */
12911 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12912 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12913
12914 /* "bgp client-to-client reflection" commands */
12915 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12916 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12917
12918 /* "bgp always-compare-med" commands */
12919 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12920 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12921
12922 /* bgp ebgp-requires-policy */
12923 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12924 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12925
12926 /* "bgp deterministic-med" commands */
12927 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12928 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12929
12930 /* "bgp graceful-restart" commands */
12931 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12932 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12933 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12934 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12935 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12936 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12937
12938 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12939 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12940
12941 /* "bgp graceful-shutdown" commands */
12942 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12943 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12944
12945 /* "bgp fast-external-failover" commands */
12946 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12947 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12948
12949 /* "bgp bestpath compare-routerid" commands */
12950 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12951 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12952
12953 /* "bgp bestpath as-path ignore" commands */
12954 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12955 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12956
12957 /* "bgp bestpath as-path confed" commands */
12958 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12959 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12960
12961 /* "bgp bestpath as-path multipath-relax" commands */
12962 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12963 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12964
12965 /* "bgp log-neighbor-changes" commands */
12966 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12967 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12968
12969 /* "bgp bestpath med" commands */
12970 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12971 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12972
12973 /* "no bgp default ipv4-unicast" commands. */
12974 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12975 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12976
12977 /* "bgp network import-check" commands. */
12978 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12979 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12980 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12981
12982 /* "bgp default local-preference" commands. */
12983 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12984 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12985
12986 /* bgp default show-hostname */
12987 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12988 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12989
12990 /* "bgp default subgroup-pkt-queue-max" commands. */
12991 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12992 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12993
12994 /* bgp ibgp-allow-policy-mods command */
12995 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12996 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12997
12998 /* "bgp listen limit" commands. */
12999 install_element(BGP_NODE, &bgp_listen_limit_cmd);
13000 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
13001
13002 /* "bgp listen range" commands. */
13003 install_element(BGP_NODE, &bgp_listen_range_cmd);
13004 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
13005
13006 /* "bgp default shutdown" command */
13007 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
13008
13009 /* "neighbor remote-as" commands. */
13010 install_element(BGP_NODE, &neighbor_remote_as_cmd);
13011 install_element(BGP_NODE, &neighbor_interface_config_cmd);
13012 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
13013 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
13014 install_element(BGP_NODE,
13015 &neighbor_interface_v6only_config_remote_as_cmd);
13016 install_element(BGP_NODE, &no_neighbor_cmd);
13017 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
13018
13019 /* "neighbor peer-group" commands. */
13020 install_element(BGP_NODE, &neighbor_peer_group_cmd);
13021 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
13022 install_element(BGP_NODE,
13023 &no_neighbor_interface_peer_group_remote_as_cmd);
13024
13025 /* "neighbor local-as" commands. */
13026 install_element(BGP_NODE, &neighbor_local_as_cmd);
13027 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
13028 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
13029 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
13030
13031 /* "neighbor solo" commands. */
13032 install_element(BGP_NODE, &neighbor_solo_cmd);
13033 install_element(BGP_NODE, &no_neighbor_solo_cmd);
13034
13035 /* "neighbor password" commands. */
13036 install_element(BGP_NODE, &neighbor_password_cmd);
13037 install_element(BGP_NODE, &no_neighbor_password_cmd);
13038
13039 /* "neighbor activate" commands. */
13040 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13041 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13042 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13043 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13044 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13045 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13046 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13047 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13048 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13049 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13050 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13051 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13052
13053 /* "no neighbor activate" commands. */
13054 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13055 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13056 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13057 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13058 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13059 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13060 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13061 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13062 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13063 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13064 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13065 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13066
13067 /* "neighbor peer-group" set commands. */
13068 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13069 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13070 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13071 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13072 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13073 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13074 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13075 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13076 install_element(BGP_FLOWSPECV4_NODE,
13077 &neighbor_set_peer_group_hidden_cmd);
13078 install_element(BGP_FLOWSPECV6_NODE,
13079 &neighbor_set_peer_group_hidden_cmd);
13080
13081 /* "no neighbor peer-group unset" commands. */
13082 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13083 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13084 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13085 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13086 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13087 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13088 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13089 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13090 install_element(BGP_FLOWSPECV4_NODE,
13091 &no_neighbor_set_peer_group_hidden_cmd);
13092 install_element(BGP_FLOWSPECV6_NODE,
13093 &no_neighbor_set_peer_group_hidden_cmd);
13094
13095 /* "neighbor softreconfiguration inbound" commands.*/
13096 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13097 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13098 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13099 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13100 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13101 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13102 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13103 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13104 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13105 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13106 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13107 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13108 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13109 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13110 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13111 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13112 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13113 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13114 install_element(BGP_FLOWSPECV4_NODE,
13115 &neighbor_soft_reconfiguration_cmd);
13116 install_element(BGP_FLOWSPECV4_NODE,
13117 &no_neighbor_soft_reconfiguration_cmd);
13118 install_element(BGP_FLOWSPECV6_NODE,
13119 &neighbor_soft_reconfiguration_cmd);
13120 install_element(BGP_FLOWSPECV6_NODE,
13121 &no_neighbor_soft_reconfiguration_cmd);
13122 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13123 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13124
13125 /* "neighbor attribute-unchanged" commands. */
13126 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13127 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13128 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13129 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13130 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13131 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13132 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13133 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13134 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13135 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13136 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13137 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13138 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13139 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13140 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13141 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13142 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13143 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13144
13145 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13146 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13147
13148 /* "nexthop-local unchanged" commands */
13149 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13150 install_element(BGP_IPV6_NODE,
13151 &no_neighbor_nexthop_local_unchanged_cmd);
13152
13153 /* "neighbor next-hop-self" commands. */
13154 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13155 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13156 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13157 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13158 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13159 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13160 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13161 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13162 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13163 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13164 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13165 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13166 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13167 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13168 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13169 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13170 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13171 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13172 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13173 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13174
13175 /* "neighbor next-hop-self force" commands. */
13176 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13177 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13178 install_element(BGP_NODE, &neighbor_nexthop_self_all_hidden_cmd);
13179 install_element(BGP_NODE, &no_neighbor_nexthop_self_all_hidden_cmd);
13180 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13181 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13182 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13183 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13184 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13185 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13186 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13187 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13188 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13189 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13190 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13191 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13192 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13193 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13194 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13195 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13196
13197 /* "neighbor as-override" commands. */
13198 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13199 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13200 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13201 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13202 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13203 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13204 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13205 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13206 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13207 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13208 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13209 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13210 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13211 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13212 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13213 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13214 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13215 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13216
13217 /* "neighbor remove-private-AS" commands. */
13218 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13219 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13220 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13221 install_element(BGP_NODE,
13222 &no_neighbor_remove_private_as_all_hidden_cmd);
13223 install_element(BGP_NODE,
13224 &neighbor_remove_private_as_replace_as_hidden_cmd);
13225 install_element(BGP_NODE,
13226 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13227 install_element(BGP_NODE,
13228 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13229 install_element(
13230 BGP_NODE,
13231 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13232 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13233 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13234 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13235 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13236 install_element(BGP_IPV4_NODE,
13237 &neighbor_remove_private_as_replace_as_cmd);
13238 install_element(BGP_IPV4_NODE,
13239 &no_neighbor_remove_private_as_replace_as_cmd);
13240 install_element(BGP_IPV4_NODE,
13241 &neighbor_remove_private_as_all_replace_as_cmd);
13242 install_element(BGP_IPV4_NODE,
13243 &no_neighbor_remove_private_as_all_replace_as_cmd);
13244 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13245 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13246 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13247 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13248 install_element(BGP_IPV4M_NODE,
13249 &neighbor_remove_private_as_replace_as_cmd);
13250 install_element(BGP_IPV4M_NODE,
13251 &no_neighbor_remove_private_as_replace_as_cmd);
13252 install_element(BGP_IPV4M_NODE,
13253 &neighbor_remove_private_as_all_replace_as_cmd);
13254 install_element(BGP_IPV4M_NODE,
13255 &no_neighbor_remove_private_as_all_replace_as_cmd);
13256 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13257 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13258 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13259 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13260 install_element(BGP_IPV4L_NODE,
13261 &neighbor_remove_private_as_replace_as_cmd);
13262 install_element(BGP_IPV4L_NODE,
13263 &no_neighbor_remove_private_as_replace_as_cmd);
13264 install_element(BGP_IPV4L_NODE,
13265 &neighbor_remove_private_as_all_replace_as_cmd);
13266 install_element(BGP_IPV4L_NODE,
13267 &no_neighbor_remove_private_as_all_replace_as_cmd);
13268 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13269 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13270 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13271 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13272 install_element(BGP_IPV6_NODE,
13273 &neighbor_remove_private_as_replace_as_cmd);
13274 install_element(BGP_IPV6_NODE,
13275 &no_neighbor_remove_private_as_replace_as_cmd);
13276 install_element(BGP_IPV6_NODE,
13277 &neighbor_remove_private_as_all_replace_as_cmd);
13278 install_element(BGP_IPV6_NODE,
13279 &no_neighbor_remove_private_as_all_replace_as_cmd);
13280 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13281 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13282 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13283 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13284 install_element(BGP_IPV6M_NODE,
13285 &neighbor_remove_private_as_replace_as_cmd);
13286 install_element(BGP_IPV6M_NODE,
13287 &no_neighbor_remove_private_as_replace_as_cmd);
13288 install_element(BGP_IPV6M_NODE,
13289 &neighbor_remove_private_as_all_replace_as_cmd);
13290 install_element(BGP_IPV6M_NODE,
13291 &no_neighbor_remove_private_as_all_replace_as_cmd);
13292 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13293 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13294 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13295 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13296 install_element(BGP_IPV6L_NODE,
13297 &neighbor_remove_private_as_replace_as_cmd);
13298 install_element(BGP_IPV6L_NODE,
13299 &no_neighbor_remove_private_as_replace_as_cmd);
13300 install_element(BGP_IPV6L_NODE,
13301 &neighbor_remove_private_as_all_replace_as_cmd);
13302 install_element(BGP_IPV6L_NODE,
13303 &no_neighbor_remove_private_as_all_replace_as_cmd);
13304 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13305 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13306 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13307 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13308 install_element(BGP_VPNV4_NODE,
13309 &neighbor_remove_private_as_replace_as_cmd);
13310 install_element(BGP_VPNV4_NODE,
13311 &no_neighbor_remove_private_as_replace_as_cmd);
13312 install_element(BGP_VPNV4_NODE,
13313 &neighbor_remove_private_as_all_replace_as_cmd);
13314 install_element(BGP_VPNV4_NODE,
13315 &no_neighbor_remove_private_as_all_replace_as_cmd);
13316 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13317 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13318 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13319 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13320 install_element(BGP_VPNV6_NODE,
13321 &neighbor_remove_private_as_replace_as_cmd);
13322 install_element(BGP_VPNV6_NODE,
13323 &no_neighbor_remove_private_as_replace_as_cmd);
13324 install_element(BGP_VPNV6_NODE,
13325 &neighbor_remove_private_as_all_replace_as_cmd);
13326 install_element(BGP_VPNV6_NODE,
13327 &no_neighbor_remove_private_as_all_replace_as_cmd);
13328
13329 /* "neighbor send-community" commands.*/
13330 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13331 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13332 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13333 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13334 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13335 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13336 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13337 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13338 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13339 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13340 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13341 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13342 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13343 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13344 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13345 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13346 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13347 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13348 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13349 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13350 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13351 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13352 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13353 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13354 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13355 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13356 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13357 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13358 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13359 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13360 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13361 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13362 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13363 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13364 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13365 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13366
13367 /* "neighbor route-reflector" commands.*/
13368 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13369 install_element(BGP_NODE,
13370 &no_neighbor_route_reflector_client_hidden_cmd);
13371 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13372 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13373 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13374 install_element(BGP_IPV4M_NODE,
13375 &no_neighbor_route_reflector_client_cmd);
13376 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13377 install_element(BGP_IPV4L_NODE,
13378 &no_neighbor_route_reflector_client_cmd);
13379 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13380 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13381 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13382 install_element(BGP_IPV6M_NODE,
13383 &no_neighbor_route_reflector_client_cmd);
13384 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13385 install_element(BGP_IPV6L_NODE,
13386 &no_neighbor_route_reflector_client_cmd);
13387 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13388 install_element(BGP_VPNV4_NODE,
13389 &no_neighbor_route_reflector_client_cmd);
13390 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13391 install_element(BGP_VPNV6_NODE,
13392 &no_neighbor_route_reflector_client_cmd);
13393 install_element(BGP_FLOWSPECV4_NODE,
13394 &neighbor_route_reflector_client_cmd);
13395 install_element(BGP_FLOWSPECV4_NODE,
13396 &no_neighbor_route_reflector_client_cmd);
13397 install_element(BGP_FLOWSPECV6_NODE,
13398 &neighbor_route_reflector_client_cmd);
13399 install_element(BGP_FLOWSPECV6_NODE,
13400 &no_neighbor_route_reflector_client_cmd);
13401 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13402 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13403
13404 /* "neighbor route-server" commands.*/
13405 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13406 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13407 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13408 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13409 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13410 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13411 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13412 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13413 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13414 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13415 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13416 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13417 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13418 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13419 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13420 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13421 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13422 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13423 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13424 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13425 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13426 install_element(BGP_FLOWSPECV4_NODE,
13427 &no_neighbor_route_server_client_cmd);
13428 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13429 install_element(BGP_FLOWSPECV6_NODE,
13430 &no_neighbor_route_server_client_cmd);
13431
13432 /* "neighbor addpath-tx-all-paths" commands.*/
13433 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13434 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13435 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13436 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13437 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13438 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13439 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13440 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13441 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13442 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13443 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13444 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13445 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13446 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13447 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13448 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13449 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13450 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13451
13452 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13453 install_element(BGP_NODE,
13454 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13455 install_element(BGP_NODE,
13456 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13457 install_element(BGP_IPV4_NODE,
13458 &neighbor_addpath_tx_bestpath_per_as_cmd);
13459 install_element(BGP_IPV4_NODE,
13460 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13461 install_element(BGP_IPV4M_NODE,
13462 &neighbor_addpath_tx_bestpath_per_as_cmd);
13463 install_element(BGP_IPV4M_NODE,
13464 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13465 install_element(BGP_IPV4L_NODE,
13466 &neighbor_addpath_tx_bestpath_per_as_cmd);
13467 install_element(BGP_IPV4L_NODE,
13468 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13469 install_element(BGP_IPV6_NODE,
13470 &neighbor_addpath_tx_bestpath_per_as_cmd);
13471 install_element(BGP_IPV6_NODE,
13472 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13473 install_element(BGP_IPV6M_NODE,
13474 &neighbor_addpath_tx_bestpath_per_as_cmd);
13475 install_element(BGP_IPV6M_NODE,
13476 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13477 install_element(BGP_IPV6L_NODE,
13478 &neighbor_addpath_tx_bestpath_per_as_cmd);
13479 install_element(BGP_IPV6L_NODE,
13480 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13481 install_element(BGP_VPNV4_NODE,
13482 &neighbor_addpath_tx_bestpath_per_as_cmd);
13483 install_element(BGP_VPNV4_NODE,
13484 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13485 install_element(BGP_VPNV6_NODE,
13486 &neighbor_addpath_tx_bestpath_per_as_cmd);
13487 install_element(BGP_VPNV6_NODE,
13488 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13489
13490 /* "neighbor passive" commands. */
13491 install_element(BGP_NODE, &neighbor_passive_cmd);
13492 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13493
13494
13495 /* "neighbor shutdown" commands. */
13496 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13497 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13498 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13499 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13500
13501 /* "neighbor capability extended-nexthop" commands.*/
13502 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13503 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13504
13505 /* "neighbor capability orf prefix-list" commands.*/
13506 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13507 install_element(BGP_NODE,
13508 &no_neighbor_capability_orf_prefix_hidden_cmd);
13509 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13510 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13511 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13512 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13513 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13514 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13515 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13516 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13517 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13518 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13519 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13520 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13521
13522 /* "neighbor capability dynamic" commands.*/
13523 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13524 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13525
13526 /* "neighbor dont-capability-negotiate" commands. */
13527 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13528 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13529
13530 /* "neighbor ebgp-multihop" commands. */
13531 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13532 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13533 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13534
13535 /* "neighbor disable-connected-check" commands. */
13536 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13537 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13538
13539 /* "neighbor enforce-first-as" commands. */
13540 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13541 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13542
13543 /* "neighbor description" commands. */
13544 install_element(BGP_NODE, &neighbor_description_cmd);
13545 install_element(BGP_NODE, &no_neighbor_description_cmd);
13546 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13547
13548 /* "neighbor update-source" commands. "*/
13549 install_element(BGP_NODE, &neighbor_update_source_cmd);
13550 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13551
13552 /* "neighbor default-originate" commands. */
13553 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13554 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13555 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13556 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13557 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13558 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13559 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13560 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13561 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13562 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13563 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13564 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13565 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13566 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13567 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13568 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13569 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13570 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13571 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13572 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13573 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13574
13575 /* "neighbor port" commands. */
13576 install_element(BGP_NODE, &neighbor_port_cmd);
13577 install_element(BGP_NODE, &no_neighbor_port_cmd);
13578
13579 /* "neighbor weight" commands. */
13580 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13581 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13582
13583 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13584 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13585 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13586 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13587 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13588 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13589 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13590 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13591 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13592 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13593 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13594 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13595 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13596 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13597 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13598 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13599
13600 /* "neighbor override-capability" commands. */
13601 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13602 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13603
13604 /* "neighbor strict-capability-match" commands. */
13605 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13606 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13607
13608 /* "neighbor timers" commands. */
13609 install_element(BGP_NODE, &neighbor_timers_cmd);
13610 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13611
13612 /* "neighbor timers connect" commands. */
13613 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13614 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13615
13616 /* "neighbor advertisement-interval" commands. */
13617 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13618 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13619
13620 /* "neighbor interface" commands. */
13621 install_element(BGP_NODE, &neighbor_interface_cmd);
13622 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13623
13624 /* "neighbor distribute" commands. */
13625 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13626 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13627 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13628 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13629 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13630 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13631 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13632 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13633 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13634 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13635 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13636 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13637 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13638 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13639 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13640 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13641 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13642 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13643
13644 /* "neighbor prefix-list" commands. */
13645 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13646 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13647 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13648 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13649 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13650 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13651 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13652 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13653 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13654 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13655 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13656 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13657 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13658 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13659 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13660 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13661 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13662 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13663 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13664 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13665 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13666 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13667
13668 /* "neighbor filter-list" commands. */
13669 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13670 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13671 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13672 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13673 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13674 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13675 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13676 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13677 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13678 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13679 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13680 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13681 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13682 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13683 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13684 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13685 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13686 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13687 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13688 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13689 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13690 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13691
13692 /* "neighbor route-map" commands. */
13693 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13694 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13695 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13696 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13697 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13698 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13699 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13700 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13701 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13702 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13703 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13704 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13705 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13706 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13707 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13708 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13709 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13710 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13711 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13712 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13713 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13714 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13715 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13716 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13717
13718 /* "neighbor unsuppress-map" commands. */
13719 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13720 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13721 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13722 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13723 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13724 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13725 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13726 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13727 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13728 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13729 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13730 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13731 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13732 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13733 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13734 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13735 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13736 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13737
13738 /* "neighbor maximum-prefix" commands. */
13739 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13740 install_element(BGP_NODE,
13741 &neighbor_maximum_prefix_threshold_hidden_cmd);
13742 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13743 install_element(BGP_NODE,
13744 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13745 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13746 install_element(BGP_NODE,
13747 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13748 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13749 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13750 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13751 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13752 install_element(BGP_IPV4_NODE,
13753 &neighbor_maximum_prefix_threshold_warning_cmd);
13754 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13755 install_element(BGP_IPV4_NODE,
13756 &neighbor_maximum_prefix_threshold_restart_cmd);
13757 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13758 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13759 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13760 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13761 install_element(BGP_IPV4M_NODE,
13762 &neighbor_maximum_prefix_threshold_warning_cmd);
13763 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13764 install_element(BGP_IPV4M_NODE,
13765 &neighbor_maximum_prefix_threshold_restart_cmd);
13766 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13767 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13768 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13769 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13770 install_element(BGP_IPV4L_NODE,
13771 &neighbor_maximum_prefix_threshold_warning_cmd);
13772 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13773 install_element(BGP_IPV4L_NODE,
13774 &neighbor_maximum_prefix_threshold_restart_cmd);
13775 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13776 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13777 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13778 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13779 install_element(BGP_IPV6_NODE,
13780 &neighbor_maximum_prefix_threshold_warning_cmd);
13781 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13782 install_element(BGP_IPV6_NODE,
13783 &neighbor_maximum_prefix_threshold_restart_cmd);
13784 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13785 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13786 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13787 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13788 install_element(BGP_IPV6M_NODE,
13789 &neighbor_maximum_prefix_threshold_warning_cmd);
13790 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13791 install_element(BGP_IPV6M_NODE,
13792 &neighbor_maximum_prefix_threshold_restart_cmd);
13793 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13794 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13795 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13796 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13797 install_element(BGP_IPV6L_NODE,
13798 &neighbor_maximum_prefix_threshold_warning_cmd);
13799 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13800 install_element(BGP_IPV6L_NODE,
13801 &neighbor_maximum_prefix_threshold_restart_cmd);
13802 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13803 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13804 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13805 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13806 install_element(BGP_VPNV4_NODE,
13807 &neighbor_maximum_prefix_threshold_warning_cmd);
13808 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13809 install_element(BGP_VPNV4_NODE,
13810 &neighbor_maximum_prefix_threshold_restart_cmd);
13811 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13812 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13813 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13814 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13815 install_element(BGP_VPNV6_NODE,
13816 &neighbor_maximum_prefix_threshold_warning_cmd);
13817 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13818 install_element(BGP_VPNV6_NODE,
13819 &neighbor_maximum_prefix_threshold_restart_cmd);
13820 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13821
13822 /* "neighbor allowas-in" */
13823 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13824 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13825 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13826 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13827 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13828 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13829 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13830 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13831 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13832 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13833 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13834 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13835 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13836 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13837 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13838 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13839 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13840 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13841 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13842 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13843
13844 /* address-family commands. */
13845 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13846 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13847 #ifdef KEEP_OLD_VPN_COMMANDS
13848 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13849 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13850 #endif /* KEEP_OLD_VPN_COMMANDS */
13851
13852 install_element(BGP_NODE, &address_family_evpn_cmd);
13853
13854 /* "exit-address-family" command. */
13855 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13856 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13857 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13858 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13859 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13860 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13861 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13862 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13863 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13864 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13865 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13866
13867 /* "clear ip bgp commands" */
13868 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13869
13870 /* clear ip bgp prefix */
13871 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13872 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13873 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13874
13875 /* "show [ip] bgp summary" commands. */
13876 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13877 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13878 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13879 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13880 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13881 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13882 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13883
13884 /* "show [ip] bgp neighbors" commands. */
13885 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13886
13887 /* "show [ip] bgp peer-group" commands. */
13888 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13889
13890 /* "show [ip] bgp paths" commands. */
13891 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13892
13893 /* "show [ip] bgp community" commands. */
13894 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13895
13896 /* "show ip bgp large-community" commands. */
13897 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13898 /* "show [ip] bgp attribute-info" commands. */
13899 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13900 /* "show [ip] bgp route-leak" command */
13901 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13902
13903 /* "redistribute" commands. */
13904 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13905 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13906 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13907 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13908 install_element(BGP_NODE,
13909 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13910 install_element(BGP_NODE,
13911 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13912 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13913 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13914 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13915 install_element(BGP_NODE,
13916 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13917 install_element(BGP_NODE,
13918 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13919 install_element(BGP_NODE,
13920 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13921 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13922 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13923 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13924 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13925 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13926 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13927 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13928 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13929 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13930 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13931 install_element(BGP_IPV4_NODE,
13932 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13933 install_element(BGP_IPV4_NODE,
13934 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13935 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13936 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13937 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13938 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13939 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13940 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13941
13942 /* import|export vpn [route-map WORD] */
13943 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13944 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13945
13946 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13947 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13948
13949 /* ttl_security commands */
13950 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13951 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13952
13953 /* "show [ip] bgp memory" commands. */
13954 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13955
13956 /* "show bgp martian next-hop" */
13957 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13958
13959 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
13960
13961 /* "show [ip] bgp views" commands. */
13962 install_element(VIEW_NODE, &show_bgp_views_cmd);
13963
13964 /* "show [ip] bgp vrfs" commands. */
13965 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13966
13967 /* Community-list. */
13968 community_list_vty();
13969
13970 /* vpn-policy commands */
13971 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13972 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13973 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13974 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13975 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13976 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13977 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13978 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13979 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13980 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13981 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13982 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13983
13984 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13985 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13986
13987 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13988 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13989 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13990 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13991 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13992 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13993 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13994 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13995 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13996 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13997 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13998 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13999 }
14000
14001 #include "memory.h"
14002 #include "bgp_regex.h"
14003 #include "bgp_clist.h"
14004 #include "bgp_ecommunity.h"
14005
14006 /* VTY functions. */
14007
14008 /* Direction value to string conversion. */
14009 static const char *community_direct_str(int direct)
14010 {
14011 switch (direct) {
14012 case COMMUNITY_DENY:
14013 return "deny";
14014 case COMMUNITY_PERMIT:
14015 return "permit";
14016 default:
14017 return "unknown";
14018 }
14019 }
14020
14021 /* Display error string. */
14022 static void community_list_perror(struct vty *vty, int ret)
14023 {
14024 switch (ret) {
14025 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
14026 vty_out(vty, "%% Can't find community-list\n");
14027 break;
14028 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
14029 vty_out(vty, "%% Malformed community-list value\n");
14030 break;
14031 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
14032 vty_out(vty,
14033 "%% Community name conflict, previously defined as standard community\n");
14034 break;
14035 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
14036 vty_out(vty,
14037 "%% Community name conflict, previously defined as expanded community\n");
14038 break;
14039 }
14040 }
14041
14042 /* "community-list" keyword help string. */
14043 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14044
14045 /*community-list standard */
14046 DEFUN (community_list_standard,
14047 bgp_community_list_standard_cmd,
14048 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14049 BGP_STR
14050 COMMUNITY_LIST_STR
14051 "Community list number (standard)\n"
14052 "Add an standard community-list entry\n"
14053 "Community list name\n"
14054 "Specify community to reject\n"
14055 "Specify community to accept\n"
14056 COMMUNITY_VAL_STR)
14057 {
14058 char *cl_name_or_number = NULL;
14059 int direct = 0;
14060 int style = COMMUNITY_LIST_STANDARD;
14061
14062 int idx = 0;
14063
14064 if (argv_find(argv, argc, "ip", &idx)) {
14065 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14066 vty_out(vty, "if you are using this please migrate to the below command.\n");
14067 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14068 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14069 }
14070
14071 argv_find(argv, argc, "(1-99)", &idx);
14072 argv_find(argv, argc, "WORD", &idx);
14073 cl_name_or_number = argv[idx]->arg;
14074 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14075 : COMMUNITY_DENY;
14076 argv_find(argv, argc, "AA:NN", &idx);
14077 char *str = argv_concat(argv, argc, idx);
14078
14079 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14080 style);
14081
14082 XFREE(MTYPE_TMP, str);
14083
14084 if (ret < 0) {
14085 /* Display error string. */
14086 community_list_perror(vty, ret);
14087 return CMD_WARNING_CONFIG_FAILED;
14088 }
14089
14090 return CMD_SUCCESS;
14091 }
14092
14093 #if CONFDATE > 20191005
14094 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14095 #endif
14096 ALIAS (community_list_standard,
14097 ip_community_list_standard_cmd,
14098 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14099 IP_STR
14100 COMMUNITY_LIST_STR
14101 "Community list number (standard)\n"
14102 "Add an standard community-list entry\n"
14103 "Community list name\n"
14104 "Specify community to reject\n"
14105 "Specify community to accept\n"
14106 COMMUNITY_VAL_STR)
14107
14108 DEFUN (no_community_list_standard_all,
14109 no_bgp_community_list_standard_all_cmd,
14110 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14111 NO_STR
14112 BGP_STR
14113 COMMUNITY_LIST_STR
14114 "Community list number (standard)\n"
14115 "Add an standard community-list entry\n"
14116 "Community list name\n"
14117 "Specify community to reject\n"
14118 "Specify community to accept\n"
14119 COMMUNITY_VAL_STR)
14120 {
14121 char *cl_name_or_number = NULL;
14122 char *str = NULL;
14123 int direct = 0;
14124 int style = COMMUNITY_LIST_STANDARD;
14125
14126 int idx = 0;
14127
14128 if (argv_find(argv, argc, "ip", &idx)) {
14129 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14130 vty_out(vty, "if you are using this please migrate to the below command.\n");
14131 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14132 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14133 }
14134
14135 argv_find(argv, argc, "permit", &idx);
14136 argv_find(argv, argc, "deny", &idx);
14137
14138 if (idx) {
14139 direct = argv_find(argv, argc, "permit", &idx)
14140 ? COMMUNITY_PERMIT
14141 : COMMUNITY_DENY;
14142
14143 idx = 0;
14144 argv_find(argv, argc, "AA:NN", &idx);
14145 str = argv_concat(argv, argc, idx);
14146 }
14147
14148 idx = 0;
14149 argv_find(argv, argc, "(1-99)", &idx);
14150 argv_find(argv, argc, "WORD", &idx);
14151 cl_name_or_number = argv[idx]->arg;
14152
14153 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14154 direct, style);
14155
14156 XFREE(MTYPE_TMP, str);
14157
14158 if (ret < 0) {
14159 community_list_perror(vty, ret);
14160 return CMD_WARNING_CONFIG_FAILED;
14161 }
14162
14163 return CMD_SUCCESS;
14164 }
14165 ALIAS (no_community_list_standard_all,
14166 no_ip_community_list_standard_all_cmd,
14167 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14168 NO_STR
14169 IP_STR
14170 COMMUNITY_LIST_STR
14171 "Community list number (standard)\n"
14172 "Add an standard community-list entry\n"
14173 "Community list name\n"
14174 "Specify community to reject\n"
14175 "Specify community to accept\n"
14176 COMMUNITY_VAL_STR)
14177
14178 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14179 "no bgp community-list <(1-99)|standard WORD>",
14180 NO_STR BGP_STR COMMUNITY_LIST_STR
14181 "Community list number (standard)\n"
14182 "Add an standard community-list entry\n"
14183 "Community list name\n")
14184
14185 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14186 "no ip community-list <(1-99)|standard WORD>",
14187 NO_STR BGP_STR COMMUNITY_LIST_STR
14188 "Community list number (standard)\n"
14189 "Add an standard community-list entry\n"
14190 "Community list name\n")
14191
14192 /*community-list expanded */
14193 DEFUN (community_list_expanded_all,
14194 bgp_community_list_expanded_all_cmd,
14195 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14196 BGP_STR
14197 COMMUNITY_LIST_STR
14198 "Community list number (expanded)\n"
14199 "Add an expanded community-list entry\n"
14200 "Community list name\n"
14201 "Specify community to reject\n"
14202 "Specify community to accept\n"
14203 COMMUNITY_VAL_STR)
14204 {
14205 char *cl_name_or_number = NULL;
14206 int direct = 0;
14207 int style = COMMUNITY_LIST_EXPANDED;
14208
14209 int idx = 0;
14210 if (argv_find(argv, argc, "ip", &idx)) {
14211 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14212 vty_out(vty, "if you are using this please migrate to the below command.\n");
14213 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14214 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14215 }
14216 argv_find(argv, argc, "(100-500)", &idx);
14217 argv_find(argv, argc, "WORD", &idx);
14218 cl_name_or_number = argv[idx]->arg;
14219 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14220 : COMMUNITY_DENY;
14221 argv_find(argv, argc, "AA:NN", &idx);
14222 char *str = argv_concat(argv, argc, idx);
14223
14224 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14225 style);
14226
14227 XFREE(MTYPE_TMP, str);
14228
14229 if (ret < 0) {
14230 /* Display error string. */
14231 community_list_perror(vty, ret);
14232 return CMD_WARNING_CONFIG_FAILED;
14233 }
14234
14235 return CMD_SUCCESS;
14236 }
14237
14238 ALIAS (community_list_expanded_all,
14239 ip_community_list_expanded_all_cmd,
14240 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14241 IP_STR
14242 COMMUNITY_LIST_STR
14243 "Community list number (expanded)\n"
14244 "Add an expanded community-list entry\n"
14245 "Community list name\n"
14246 "Specify community to reject\n"
14247 "Specify community to accept\n"
14248 COMMUNITY_VAL_STR)
14249
14250 DEFUN (no_community_list_expanded_all,
14251 no_bgp_community_list_expanded_all_cmd,
14252 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14253 NO_STR
14254 BGP_STR
14255 COMMUNITY_LIST_STR
14256 "Community list number (expanded)\n"
14257 "Add an expanded community-list entry\n"
14258 "Community list name\n"
14259 "Specify community to reject\n"
14260 "Specify community to accept\n"
14261 COMMUNITY_VAL_STR)
14262 {
14263 char *cl_name_or_number = NULL;
14264 char *str = NULL;
14265 int direct = 0;
14266 int style = COMMUNITY_LIST_EXPANDED;
14267
14268 int idx = 0;
14269 if (argv_find(argv, argc, "ip", &idx)) {
14270 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14271 vty_out(vty, "if you are using this please migrate to the below command.\n");
14272 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14273 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14274 }
14275
14276 idx = 0;
14277 argv_find(argv, argc, "permit", &idx);
14278 argv_find(argv, argc, "deny", &idx);
14279
14280 if (idx) {
14281 direct = argv_find(argv, argc, "permit", &idx)
14282 ? COMMUNITY_PERMIT
14283 : COMMUNITY_DENY;
14284
14285 idx = 0;
14286 argv_find(argv, argc, "AA:NN", &idx);
14287 str = argv_concat(argv, argc, idx);
14288 }
14289
14290 idx = 0;
14291 argv_find(argv, argc, "(100-500)", &idx);
14292 argv_find(argv, argc, "WORD", &idx);
14293 cl_name_or_number = argv[idx]->arg;
14294
14295 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14296 direct, style);
14297
14298 XFREE(MTYPE_TMP, str);
14299
14300 if (ret < 0) {
14301 community_list_perror(vty, ret);
14302 return CMD_WARNING_CONFIG_FAILED;
14303 }
14304
14305 return CMD_SUCCESS;
14306 }
14307
14308 ALIAS (no_community_list_expanded_all,
14309 no_ip_community_list_expanded_all_cmd,
14310 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14311 NO_STR
14312 IP_STR
14313 COMMUNITY_LIST_STR
14314 "Community list number (expanded)\n"
14315 "Add an expanded community-list entry\n"
14316 "Community list name\n"
14317 "Specify community to reject\n"
14318 "Specify community to accept\n"
14319 COMMUNITY_VAL_STR)
14320
14321 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14322 "no bgp community-list <(100-500)|expanded WORD>",
14323 NO_STR IP_STR COMMUNITY_LIST_STR
14324 "Community list number (expanded)\n"
14325 "Add an expanded community-list entry\n"
14326 "Community list name\n")
14327
14328 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14329 "no ip community-list <(100-500)|expanded WORD>",
14330 NO_STR IP_STR COMMUNITY_LIST_STR
14331 "Community list number (expanded)\n"
14332 "Add an expanded community-list entry\n"
14333 "Community list name\n")
14334
14335 /* Return configuration string of community-list entry. */
14336 static const char *community_list_config_str(struct community_entry *entry)
14337 {
14338 const char *str;
14339
14340 if (entry->any)
14341 str = "";
14342 else {
14343 if (entry->style == COMMUNITY_LIST_STANDARD)
14344 str = community_str(entry->u.com, false);
14345 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14346 str = lcommunity_str(entry->u.lcom, false);
14347 else
14348 str = entry->config;
14349 }
14350 return str;
14351 }
14352
14353 static void community_list_show(struct vty *vty, struct community_list *list)
14354 {
14355 struct community_entry *entry;
14356
14357 for (entry = list->head; entry; entry = entry->next) {
14358 if (entry == list->head) {
14359 if (all_digit(list->name))
14360 vty_out(vty, "Community %s list %s\n",
14361 entry->style == COMMUNITY_LIST_STANDARD
14362 ? "standard"
14363 : "(expanded) access",
14364 list->name);
14365 else
14366 vty_out(vty, "Named Community %s list %s\n",
14367 entry->style == COMMUNITY_LIST_STANDARD
14368 ? "standard"
14369 : "expanded",
14370 list->name);
14371 }
14372 if (entry->any)
14373 vty_out(vty, " %s\n",
14374 community_direct_str(entry->direct));
14375 else
14376 vty_out(vty, " %s %s\n",
14377 community_direct_str(entry->direct),
14378 community_list_config_str(entry));
14379 }
14380 }
14381
14382 DEFUN (show_community_list,
14383 show_bgp_community_list_cmd,
14384 "show bgp community-list",
14385 SHOW_STR
14386 BGP_STR
14387 "List community-list\n")
14388 {
14389 struct community_list *list;
14390 struct community_list_master *cm;
14391
14392 int idx = 0;
14393 if (argv_find(argv, argc, "ip", &idx)) {
14394 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14395 vty_out(vty, "if you are using this please migrate to the below command.\n");
14396 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14397 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14398 }
14399 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14400 if (!cm)
14401 return CMD_SUCCESS;
14402
14403 for (list = cm->num.head; list; list = list->next)
14404 community_list_show(vty, list);
14405
14406 for (list = cm->str.head; list; list = list->next)
14407 community_list_show(vty, list);
14408
14409 return CMD_SUCCESS;
14410 }
14411
14412 ALIAS (show_community_list,
14413 show_ip_community_list_cmd,
14414 "show ip community-list",
14415 SHOW_STR
14416 IP_STR
14417 "List community-list\n")
14418
14419 DEFUN (show_community_list_arg,
14420 show_bgp_community_list_arg_cmd,
14421 "show bgp community-list <(1-500)|WORD>",
14422 SHOW_STR
14423 BGP_STR
14424 "List community-list\n"
14425 "Community-list number\n"
14426 "Community-list name\n")
14427 {
14428 int idx_comm_list = 3;
14429 struct community_list *list;
14430
14431 int idx = 0;
14432 if (argv_find(argv, argc, "ip", &idx)) {
14433 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14434 vty_out(vty, "if you are using this please migrate to the below command.\n");
14435 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14436 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14437 }
14438 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14439 COMMUNITY_LIST_MASTER);
14440 if (!list) {
14441 vty_out(vty, "%% Can't find community-list\n");
14442 return CMD_WARNING;
14443 }
14444
14445 community_list_show(vty, list);
14446
14447 return CMD_SUCCESS;
14448 }
14449
14450 ALIAS (show_community_list_arg,
14451 show_ip_community_list_arg_cmd,
14452 "show ip community-list <(1-500)|WORD>",
14453 SHOW_STR
14454 IP_STR
14455 "List community-list\n"
14456 "Community-list number\n"
14457 "Community-list name\n")
14458
14459 /*
14460 * Large Community code.
14461 */
14462 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14463 struct cmd_token **argv, int style,
14464 int reject_all_digit_name)
14465 {
14466 int ret;
14467 int direct;
14468 char *str;
14469 int idx = 0;
14470 char *cl_name;
14471
14472 if (argv_find(argv, argc, "ip", &idx)) {
14473 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14474 vty_out(vty, "if you are using this please migrate to the below command.\n");
14475 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14476 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14477 }
14478 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14479 : COMMUNITY_DENY;
14480
14481 /* All digit name check. */
14482 idx = 0;
14483 argv_find(argv, argc, "WORD", &idx);
14484 argv_find(argv, argc, "(1-99)", &idx);
14485 argv_find(argv, argc, "(100-500)", &idx);
14486 cl_name = argv[idx]->arg;
14487 if (reject_all_digit_name && all_digit(cl_name)) {
14488 vty_out(vty, "%% Community name cannot have all digits\n");
14489 return CMD_WARNING_CONFIG_FAILED;
14490 }
14491
14492 idx = 0;
14493 argv_find(argv, argc, "AA:BB:CC", &idx);
14494 argv_find(argv, argc, "LINE", &idx);
14495 /* Concat community string argument. */
14496 if (idx)
14497 str = argv_concat(argv, argc, idx);
14498 else
14499 str = NULL;
14500
14501 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14502
14503 /* Free temporary community list string allocated by
14504 argv_concat(). */
14505 XFREE(MTYPE_TMP, str);
14506
14507 if (ret < 0) {
14508 community_list_perror(vty, ret);
14509 return CMD_WARNING_CONFIG_FAILED;
14510 }
14511 return CMD_SUCCESS;
14512 }
14513
14514 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14515 struct cmd_token **argv, int style)
14516 {
14517 int ret;
14518 int direct = 0;
14519 char *str = NULL;
14520 int idx = 0;
14521
14522 if (argv_find(argv, argc, "ip", &idx)) {
14523 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14524 vty_out(vty, "if you are using this please migrate to the below command.\n");
14525 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14526 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14527 }
14528 argv_find(argv, argc, "permit", &idx);
14529 argv_find(argv, argc, "deny", &idx);
14530
14531 if (idx) {
14532 /* Check the list direct. */
14533 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14534 direct = COMMUNITY_PERMIT;
14535 else
14536 direct = COMMUNITY_DENY;
14537
14538 idx = 0;
14539 argv_find(argv, argc, "LINE", &idx);
14540 argv_find(argv, argc, "AA:AA:NN", &idx);
14541 /* Concat community string argument. */
14542 str = argv_concat(argv, argc, idx);
14543 }
14544
14545 idx = 0;
14546 argv_find(argv, argc, "(1-99)", &idx);
14547 argv_find(argv, argc, "(100-500)", &idx);
14548 argv_find(argv, argc, "WORD", &idx);
14549
14550 /* Unset community list. */
14551 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14552 style);
14553
14554 /* Free temporary community list string allocated by
14555 argv_concat(). */
14556 XFREE(MTYPE_TMP, str);
14557
14558 if (ret < 0) {
14559 community_list_perror(vty, ret);
14560 return CMD_WARNING_CONFIG_FAILED;
14561 }
14562
14563 return CMD_SUCCESS;
14564 }
14565
14566 /* "large-community-list" keyword help string. */
14567 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14568 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14569
14570 #if CONFDATE > 20191005
14571 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14572 #endif
14573 DEFUN (lcommunity_list_standard,
14574 bgp_lcommunity_list_standard_cmd,
14575 "bgp large-community-list (1-99) <deny|permit>",
14576 BGP_STR
14577 LCOMMUNITY_LIST_STR
14578 "Large Community list number (standard)\n"
14579 "Specify large community to reject\n"
14580 "Specify large community to accept\n")
14581 {
14582 return lcommunity_list_set_vty(vty, argc, argv,
14583 LARGE_COMMUNITY_LIST_STANDARD, 0);
14584 }
14585
14586 ALIAS (lcommunity_list_standard,
14587 ip_lcommunity_list_standard_cmd,
14588 "ip large-community-list (1-99) <deny|permit>",
14589 IP_STR
14590 LCOMMUNITY_LIST_STR
14591 "Large Community list number (standard)\n"
14592 "Specify large community to reject\n"
14593 "Specify large community to accept\n")
14594
14595 DEFUN (lcommunity_list_standard1,
14596 bgp_lcommunity_list_standard1_cmd,
14597 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14598 BGP_STR
14599 LCOMMUNITY_LIST_STR
14600 "Large Community list number (standard)\n"
14601 "Specify large community to reject\n"
14602 "Specify large community to accept\n"
14603 LCOMMUNITY_VAL_STR)
14604 {
14605 return lcommunity_list_set_vty(vty, argc, argv,
14606 LARGE_COMMUNITY_LIST_STANDARD, 0);
14607 }
14608
14609 ALIAS (lcommunity_list_standard1,
14610 ip_lcommunity_list_standard1_cmd,
14611 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
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 LCOMMUNITY_VAL_STR)
14618
14619 DEFUN (lcommunity_list_expanded,
14620 bgp_lcommunity_list_expanded_cmd,
14621 "bgp large-community-list (100-500) <deny|permit> LINE...",
14622 BGP_STR
14623 LCOMMUNITY_LIST_STR
14624 "Large Community list number (expanded)\n"
14625 "Specify large community to reject\n"
14626 "Specify large community to accept\n"
14627 "An ordered list as a regular-expression\n")
14628 {
14629 return lcommunity_list_set_vty(vty, argc, argv,
14630 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14631 }
14632
14633 ALIAS (lcommunity_list_expanded,
14634 ip_lcommunity_list_expanded_cmd,
14635 "ip large-community-list (100-500) <deny|permit> LINE...",
14636 IP_STR
14637 LCOMMUNITY_LIST_STR
14638 "Large Community list number (expanded)\n"
14639 "Specify large community to reject\n"
14640 "Specify large community to accept\n"
14641 "An ordered list as a regular-expression\n")
14642
14643 DEFUN (lcommunity_list_name_standard,
14644 bgp_lcommunity_list_name_standard_cmd,
14645 "bgp large-community-list standard WORD <deny|permit>",
14646 BGP_STR
14647 LCOMMUNITY_LIST_STR
14648 "Specify standard large-community-list\n"
14649 "Large Community list name\n"
14650 "Specify large community to reject\n"
14651 "Specify large community to accept\n")
14652 {
14653 return lcommunity_list_set_vty(vty, argc, argv,
14654 LARGE_COMMUNITY_LIST_STANDARD, 1);
14655 }
14656
14657 ALIAS (lcommunity_list_name_standard,
14658 ip_lcommunity_list_name_standard_cmd,
14659 "ip large-community-list standard WORD <deny|permit>",
14660 IP_STR
14661 LCOMMUNITY_LIST_STR
14662 "Specify standard large-community-list\n"
14663 "Large Community list name\n"
14664 "Specify large community to reject\n"
14665 "Specify large community to accept\n")
14666
14667 DEFUN (lcommunity_list_name_standard1,
14668 bgp_lcommunity_list_name_standard1_cmd,
14669 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14670 BGP_STR
14671 LCOMMUNITY_LIST_STR
14672 "Specify standard large-community-list\n"
14673 "Large Community list name\n"
14674 "Specify large community to reject\n"
14675 "Specify large community to accept\n"
14676 LCOMMUNITY_VAL_STR)
14677 {
14678 return lcommunity_list_set_vty(vty, argc, argv,
14679 LARGE_COMMUNITY_LIST_STANDARD, 1);
14680 }
14681
14682 ALIAS (lcommunity_list_name_standard1,
14683 ip_lcommunity_list_name_standard1_cmd,
14684 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14685 IP_STR
14686 LCOMMUNITY_LIST_STR
14687 "Specify standard large-community-list\n"
14688 "Large Community list name\n"
14689 "Specify large community to reject\n"
14690 "Specify large community to accept\n"
14691 LCOMMUNITY_VAL_STR)
14692
14693 DEFUN (lcommunity_list_name_expanded,
14694 bgp_lcommunity_list_name_expanded_cmd,
14695 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14696 BGP_STR
14697 LCOMMUNITY_LIST_STR
14698 "Specify expanded large-community-list\n"
14699 "Large Community list name\n"
14700 "Specify large community to reject\n"
14701 "Specify large community to accept\n"
14702 "An ordered list as a regular-expression\n")
14703 {
14704 return lcommunity_list_set_vty(vty, argc, argv,
14705 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14706 }
14707
14708 ALIAS (lcommunity_list_name_expanded,
14709 ip_lcommunity_list_name_expanded_cmd,
14710 "ip large-community-list expanded WORD <deny|permit> LINE...",
14711 IP_STR
14712 LCOMMUNITY_LIST_STR
14713 "Specify expanded large-community-list\n"
14714 "Large Community list name\n"
14715 "Specify large community to reject\n"
14716 "Specify large community to accept\n"
14717 "An ordered list as a regular-expression\n")
14718
14719 DEFUN (no_lcommunity_list_standard_all,
14720 no_bgp_lcommunity_list_standard_all_cmd,
14721 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14722 NO_STR
14723 BGP_STR
14724 LCOMMUNITY_LIST_STR
14725 "Large Community list number (standard)\n"
14726 "Large Community list number (expanded)\n"
14727 "Large Community list name\n")
14728 {
14729 return lcommunity_list_unset_vty(vty, argc, argv,
14730 LARGE_COMMUNITY_LIST_STANDARD);
14731 }
14732
14733 ALIAS (no_lcommunity_list_standard_all,
14734 no_ip_lcommunity_list_standard_all_cmd,
14735 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14736 NO_STR
14737 IP_STR
14738 LCOMMUNITY_LIST_STR
14739 "Large Community list number (standard)\n"
14740 "Large Community list number (expanded)\n"
14741 "Large Community list name\n")
14742
14743 DEFUN (no_lcommunity_list_name_expanded_all,
14744 no_bgp_lcommunity_list_name_expanded_all_cmd,
14745 "no bgp large-community-list expanded WORD",
14746 NO_STR
14747 BGP_STR
14748 LCOMMUNITY_LIST_STR
14749 "Specify expanded large-community-list\n"
14750 "Large Community list name\n")
14751 {
14752 return lcommunity_list_unset_vty(vty, argc, argv,
14753 LARGE_COMMUNITY_LIST_EXPANDED);
14754 }
14755
14756 ALIAS (no_lcommunity_list_name_expanded_all,
14757 no_ip_lcommunity_list_name_expanded_all_cmd,
14758 "no ip large-community-list expanded WORD",
14759 NO_STR
14760 IP_STR
14761 LCOMMUNITY_LIST_STR
14762 "Specify expanded large-community-list\n"
14763 "Large Community list name\n")
14764
14765 DEFUN (no_lcommunity_list_standard,
14766 no_bgp_lcommunity_list_standard_cmd,
14767 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14768 NO_STR
14769 BGP_STR
14770 LCOMMUNITY_LIST_STR
14771 "Large Community list number (standard)\n"
14772 "Specify large community to reject\n"
14773 "Specify large community to accept\n"
14774 LCOMMUNITY_VAL_STR)
14775 {
14776 return lcommunity_list_unset_vty(vty, argc, argv,
14777 LARGE_COMMUNITY_LIST_STANDARD);
14778 }
14779
14780 ALIAS (no_lcommunity_list_standard,
14781 no_ip_lcommunity_list_standard_cmd,
14782 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14783 NO_STR
14784 IP_STR
14785 LCOMMUNITY_LIST_STR
14786 "Large Community list number (standard)\n"
14787 "Specify large community to reject\n"
14788 "Specify large community to accept\n"
14789 LCOMMUNITY_VAL_STR)
14790
14791 DEFUN (no_lcommunity_list_expanded,
14792 no_bgp_lcommunity_list_expanded_cmd,
14793 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14794 NO_STR
14795 BGP_STR
14796 LCOMMUNITY_LIST_STR
14797 "Large Community list number (expanded)\n"
14798 "Specify large community to reject\n"
14799 "Specify large community to accept\n"
14800 "An ordered list as a regular-expression\n")
14801 {
14802 return lcommunity_list_unset_vty(vty, argc, argv,
14803 LARGE_COMMUNITY_LIST_EXPANDED);
14804 }
14805
14806 ALIAS (no_lcommunity_list_expanded,
14807 no_ip_lcommunity_list_expanded_cmd,
14808 "no ip large-community-list (100-500) <deny|permit> LINE...",
14809 NO_STR
14810 IP_STR
14811 LCOMMUNITY_LIST_STR
14812 "Large Community list number (expanded)\n"
14813 "Specify large community to reject\n"
14814 "Specify large community to accept\n"
14815 "An ordered list as a regular-expression\n")
14816
14817 DEFUN (no_lcommunity_list_name_standard,
14818 no_bgp_lcommunity_list_name_standard_cmd,
14819 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14820 NO_STR
14821 BGP_STR
14822 LCOMMUNITY_LIST_STR
14823 "Specify standard large-community-list\n"
14824 "Large Community list name\n"
14825 "Specify large community to reject\n"
14826 "Specify large community to accept\n"
14827 LCOMMUNITY_VAL_STR)
14828 {
14829 return lcommunity_list_unset_vty(vty, argc, argv,
14830 LARGE_COMMUNITY_LIST_STANDARD);
14831 }
14832
14833 ALIAS (no_lcommunity_list_name_standard,
14834 no_ip_lcommunity_list_name_standard_cmd,
14835 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14836 NO_STR
14837 IP_STR
14838 LCOMMUNITY_LIST_STR
14839 "Specify standard large-community-list\n"
14840 "Large Community list name\n"
14841 "Specify large community to reject\n"
14842 "Specify large community to accept\n"
14843 LCOMMUNITY_VAL_STR)
14844
14845 DEFUN (no_lcommunity_list_name_expanded,
14846 no_bgp_lcommunity_list_name_expanded_cmd,
14847 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14848 NO_STR
14849 BGP_STR
14850 LCOMMUNITY_LIST_STR
14851 "Specify expanded large-community-list\n"
14852 "Large community list name\n"
14853 "Specify large community to reject\n"
14854 "Specify large community to accept\n"
14855 "An ordered list as a regular-expression\n")
14856 {
14857 return lcommunity_list_unset_vty(vty, argc, argv,
14858 LARGE_COMMUNITY_LIST_EXPANDED);
14859 }
14860
14861 ALIAS (no_lcommunity_list_name_expanded,
14862 no_ip_lcommunity_list_name_expanded_cmd,
14863 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14864 NO_STR
14865 IP_STR
14866 LCOMMUNITY_LIST_STR
14867 "Specify expanded large-community-list\n"
14868 "Large community list name\n"
14869 "Specify large community to reject\n"
14870 "Specify large community to accept\n"
14871 "An ordered list as a regular-expression\n")
14872
14873 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14874 {
14875 struct community_entry *entry;
14876
14877 for (entry = list->head; entry; entry = entry->next) {
14878 if (entry == list->head) {
14879 if (all_digit(list->name))
14880 vty_out(vty, "Large community %s list %s\n",
14881 entry->style ==
14882 LARGE_COMMUNITY_LIST_STANDARD
14883 ? "standard"
14884 : "(expanded) access",
14885 list->name);
14886 else
14887 vty_out(vty,
14888 "Named large community %s list %s\n",
14889 entry->style ==
14890 LARGE_COMMUNITY_LIST_STANDARD
14891 ? "standard"
14892 : "expanded",
14893 list->name);
14894 }
14895 if (entry->any)
14896 vty_out(vty, " %s\n",
14897 community_direct_str(entry->direct));
14898 else
14899 vty_out(vty, " %s %s\n",
14900 community_direct_str(entry->direct),
14901 community_list_config_str(entry));
14902 }
14903 }
14904
14905 DEFUN (show_lcommunity_list,
14906 show_bgp_lcommunity_list_cmd,
14907 "show bgp large-community-list",
14908 SHOW_STR
14909 BGP_STR
14910 "List large-community list\n")
14911 {
14912 struct community_list *list;
14913 struct community_list_master *cm;
14914 int idx = 0;
14915
14916 if (argv_find(argv, argc, "ip", &idx)) {
14917 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14918 vty_out(vty, "if you are using this please migrate to the below command.\n");
14919 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14920 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14921 }
14922
14923 cm = community_list_master_lookup(bgp_clist,
14924 LARGE_COMMUNITY_LIST_MASTER);
14925 if (!cm)
14926 return CMD_SUCCESS;
14927
14928 for (list = cm->num.head; list; list = list->next)
14929 lcommunity_list_show(vty, list);
14930
14931 for (list = cm->str.head; list; list = list->next)
14932 lcommunity_list_show(vty, list);
14933
14934 return CMD_SUCCESS;
14935 }
14936
14937 ALIAS (show_lcommunity_list,
14938 show_ip_lcommunity_list_cmd,
14939 "show ip large-community-list",
14940 SHOW_STR
14941 IP_STR
14942 "List large-community list\n")
14943
14944 DEFUN (show_lcommunity_list_arg,
14945 show_bgp_lcommunity_list_arg_cmd,
14946 "show bgp large-community-list <(1-500)|WORD>",
14947 SHOW_STR
14948 BGP_STR
14949 "List large-community list\n"
14950 "large-community-list number\n"
14951 "large-community-list name\n")
14952 {
14953 struct community_list *list;
14954 int idx = 0;
14955
14956 if (argv_find(argv, argc, "ip", &idx)) {
14957 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14958 vty_out(vty, "if you are using this please migrate to the below command.\n");
14959 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14960 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14961 }
14962
14963 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
14964 LARGE_COMMUNITY_LIST_MASTER);
14965 if (!list) {
14966 vty_out(vty, "%% Can't find extcommunity-list\n");
14967 return CMD_WARNING;
14968 }
14969
14970 lcommunity_list_show(vty, list);
14971
14972 return CMD_SUCCESS;
14973 }
14974
14975 ALIAS (show_lcommunity_list_arg,
14976 show_ip_lcommunity_list_arg_cmd,
14977 "show ip large-community-list <(1-500)|WORD>",
14978 SHOW_STR
14979 IP_STR
14980 "List large-community list\n"
14981 "large-community-list number\n"
14982 "large-community-list name\n")
14983
14984 /* "extcommunity-list" keyword help string. */
14985 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14986 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14987
14988 DEFUN (extcommunity_list_standard,
14989 bgp_extcommunity_list_standard_cmd,
14990 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14991 BGP_STR
14992 EXTCOMMUNITY_LIST_STR
14993 "Extended Community list number (standard)\n"
14994 "Specify standard extcommunity-list\n"
14995 "Community list name\n"
14996 "Specify community to reject\n"
14997 "Specify community to accept\n"
14998 EXTCOMMUNITY_VAL_STR)
14999 {
15000 int style = EXTCOMMUNITY_LIST_STANDARD;
15001 int direct = 0;
15002 char *cl_number_or_name = NULL;
15003
15004 int idx = 0;
15005 if (argv_find(argv, argc, "ip", &idx)) {
15006 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15007 vty_out(vty, "if you are using this please migrate to the below command.\n");
15008 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15009 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15010 }
15011 argv_find(argv, argc, "(1-99)", &idx);
15012 argv_find(argv, argc, "WORD", &idx);
15013 cl_number_or_name = argv[idx]->arg;
15014 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15015 : COMMUNITY_DENY;
15016 argv_find(argv, argc, "AA:NN", &idx);
15017 char *str = argv_concat(argv, argc, idx);
15018
15019 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15020 direct, style);
15021
15022 XFREE(MTYPE_TMP, str);
15023
15024 if (ret < 0) {
15025 community_list_perror(vty, ret);
15026 return CMD_WARNING_CONFIG_FAILED;
15027 }
15028
15029 return CMD_SUCCESS;
15030 }
15031
15032 #if CONFDATE > 20191005
15033 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
15034 #endif
15035 ALIAS (extcommunity_list_standard,
15036 ip_extcommunity_list_standard_cmd,
15037 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15038 IP_STR
15039 EXTCOMMUNITY_LIST_STR
15040 "Extended Community list number (standard)\n"
15041 "Specify standard extcommunity-list\n"
15042 "Community list name\n"
15043 "Specify community to reject\n"
15044 "Specify community to accept\n"
15045 EXTCOMMUNITY_VAL_STR)
15046
15047 DEFUN (extcommunity_list_name_expanded,
15048 bgp_extcommunity_list_name_expanded_cmd,
15049 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15050 BGP_STR
15051 EXTCOMMUNITY_LIST_STR
15052 "Extended Community list number (expanded)\n"
15053 "Specify expanded extcommunity-list\n"
15054 "Extended Community list name\n"
15055 "Specify community to reject\n"
15056 "Specify community to accept\n"
15057 "An ordered list as a regular-expression\n")
15058 {
15059 int style = EXTCOMMUNITY_LIST_EXPANDED;
15060 int direct = 0;
15061 char *cl_number_or_name = NULL;
15062
15063 int idx = 0;
15064 if (argv_find(argv, argc, "ip", &idx)) {
15065 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15066 vty_out(vty, "if you are using this please migrate to the below command.\n");
15067 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15068 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15069 }
15070
15071 argv_find(argv, argc, "(100-500)", &idx);
15072 argv_find(argv, argc, "WORD", &idx);
15073 cl_number_or_name = argv[idx]->arg;
15074 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15075 : COMMUNITY_DENY;
15076 argv_find(argv, argc, "LINE", &idx);
15077 char *str = argv_concat(argv, argc, idx);
15078
15079 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15080 direct, style);
15081
15082 XFREE(MTYPE_TMP, str);
15083
15084 if (ret < 0) {
15085 community_list_perror(vty, ret);
15086 return CMD_WARNING_CONFIG_FAILED;
15087 }
15088
15089 return CMD_SUCCESS;
15090 }
15091
15092 ALIAS (extcommunity_list_name_expanded,
15093 ip_extcommunity_list_name_expanded_cmd,
15094 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15095 IP_STR
15096 EXTCOMMUNITY_LIST_STR
15097 "Extended Community list number (expanded)\n"
15098 "Specify expanded extcommunity-list\n"
15099 "Extended Community list name\n"
15100 "Specify community to reject\n"
15101 "Specify community to accept\n"
15102 "An ordered list as a regular-expression\n")
15103
15104 DEFUN (no_extcommunity_list_standard_all,
15105 no_bgp_extcommunity_list_standard_all_cmd,
15106 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15107 NO_STR
15108 BGP_STR
15109 EXTCOMMUNITY_LIST_STR
15110 "Extended Community list number (standard)\n"
15111 "Specify standard extcommunity-list\n"
15112 "Community list name\n"
15113 "Specify community to reject\n"
15114 "Specify community to accept\n"
15115 EXTCOMMUNITY_VAL_STR)
15116 {
15117 int style = EXTCOMMUNITY_LIST_STANDARD;
15118 int direct = 0;
15119 char *cl_number_or_name = NULL;
15120 char *str = NULL;
15121
15122 int idx = 0;
15123 if (argv_find(argv, argc, "ip", &idx)) {
15124 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15125 vty_out(vty, "if you are using this please migrate to the below command.\n");
15126 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15127 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15128 }
15129
15130 idx = 0;
15131 argv_find(argv, argc, "permit", &idx);
15132 argv_find(argv, argc, "deny", &idx);
15133
15134 if (idx) {
15135 direct = argv_find(argv, argc, "permit", &idx)
15136 ? COMMUNITY_PERMIT
15137 : COMMUNITY_DENY;
15138
15139 idx = 0;
15140 argv_find(argv, argc, "AA:NN", &idx);
15141 str = argv_concat(argv, argc, idx);
15142 }
15143
15144 idx = 0;
15145 argv_find(argv, argc, "(1-99)", &idx);
15146 argv_find(argv, argc, "WORD", &idx);
15147 cl_number_or_name = argv[idx]->arg;
15148
15149 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15150 direct, style);
15151
15152 XFREE(MTYPE_TMP, str);
15153
15154 if (ret < 0) {
15155 community_list_perror(vty, ret);
15156 return CMD_WARNING_CONFIG_FAILED;
15157 }
15158
15159 return CMD_SUCCESS;
15160 }
15161
15162 ALIAS (no_extcommunity_list_standard_all,
15163 no_ip_extcommunity_list_standard_all_cmd,
15164 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15165 NO_STR
15166 IP_STR
15167 EXTCOMMUNITY_LIST_STR
15168 "Extended Community list number (standard)\n"
15169 "Specify standard extcommunity-list\n"
15170 "Community list name\n"
15171 "Specify community to reject\n"
15172 "Specify community to accept\n"
15173 EXTCOMMUNITY_VAL_STR)
15174
15175 ALIAS(no_extcommunity_list_standard_all,
15176 no_bgp_extcommunity_list_standard_all_list_cmd,
15177 "no bgp extcommunity-list <(1-99)|standard WORD>",
15178 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15179 "Extended Community list number (standard)\n"
15180 "Specify standard extcommunity-list\n"
15181 "Community list name\n")
15182
15183 ALIAS(no_extcommunity_list_standard_all,
15184 no_ip_extcommunity_list_standard_all_list_cmd,
15185 "no ip extcommunity-list <(1-99)|standard WORD>",
15186 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15187 "Extended Community list number (standard)\n"
15188 "Specify standard extcommunity-list\n"
15189 "Community list name\n")
15190
15191 DEFUN (no_extcommunity_list_expanded_all,
15192 no_bgp_extcommunity_list_expanded_all_cmd,
15193 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15194 NO_STR
15195 BGP_STR
15196 EXTCOMMUNITY_LIST_STR
15197 "Extended Community list number (expanded)\n"
15198 "Specify expanded extcommunity-list\n"
15199 "Extended Community list name\n"
15200 "Specify community to reject\n"
15201 "Specify community to accept\n"
15202 "An ordered list as a regular-expression\n")
15203 {
15204 int style = EXTCOMMUNITY_LIST_EXPANDED;
15205 int direct = 0;
15206 char *cl_number_or_name = NULL;
15207 char *str = NULL;
15208
15209 int idx = 0;
15210 if (argv_find(argv, argc, "ip", &idx)) {
15211 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15212 vty_out(vty, "if you are using this please migrate to the below command.\n");
15213 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15214 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15215 }
15216
15217 idx = 0;
15218 argv_find(argv, argc, "permit", &idx);
15219 argv_find(argv, argc, "deny", &idx);
15220
15221 if (idx) {
15222 direct = argv_find(argv, argc, "permit", &idx)
15223 ? COMMUNITY_PERMIT
15224 : COMMUNITY_DENY;
15225
15226 idx = 0;
15227 argv_find(argv, argc, "LINE", &idx);
15228 str = argv_concat(argv, argc, idx);
15229 }
15230
15231 idx = 0;
15232 argv_find(argv, argc, "(100-500)", &idx);
15233 argv_find(argv, argc, "WORD", &idx);
15234 cl_number_or_name = argv[idx]->arg;
15235
15236 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15237 direct, style);
15238
15239 XFREE(MTYPE_TMP, str);
15240
15241 if (ret < 0) {
15242 community_list_perror(vty, ret);
15243 return CMD_WARNING_CONFIG_FAILED;
15244 }
15245
15246 return CMD_SUCCESS;
15247 }
15248
15249 ALIAS (no_extcommunity_list_expanded_all,
15250 no_ip_extcommunity_list_expanded_all_cmd,
15251 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15252 NO_STR
15253 IP_STR
15254 EXTCOMMUNITY_LIST_STR
15255 "Extended Community list number (expanded)\n"
15256 "Specify expanded extcommunity-list\n"
15257 "Extended Community list name\n"
15258 "Specify community to reject\n"
15259 "Specify community to accept\n"
15260 "An ordered list as a regular-expression\n")
15261
15262 ALIAS(no_extcommunity_list_expanded_all,
15263 no_ip_extcommunity_list_expanded_all_list_cmd,
15264 "no ip extcommunity-list <(100-500)|expanded WORD>",
15265 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15266 "Extended Community list number (expanded)\n"
15267 "Specify expanded extcommunity-list\n"
15268 "Extended Community list name\n")
15269
15270 ALIAS(no_extcommunity_list_expanded_all,
15271 no_bgp_extcommunity_list_expanded_all_list_cmd,
15272 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15273 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15274 "Extended Community list number (expanded)\n"
15275 "Specify expanded extcommunity-list\n"
15276 "Extended Community list name\n")
15277
15278 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15279 {
15280 struct community_entry *entry;
15281
15282 for (entry = list->head; entry; entry = entry->next) {
15283 if (entry == list->head) {
15284 if (all_digit(list->name))
15285 vty_out(vty, "Extended community %s list %s\n",
15286 entry->style == EXTCOMMUNITY_LIST_STANDARD
15287 ? "standard"
15288 : "(expanded) access",
15289 list->name);
15290 else
15291 vty_out(vty,
15292 "Named extended community %s list %s\n",
15293 entry->style == EXTCOMMUNITY_LIST_STANDARD
15294 ? "standard"
15295 : "expanded",
15296 list->name);
15297 }
15298 if (entry->any)
15299 vty_out(vty, " %s\n",
15300 community_direct_str(entry->direct));
15301 else
15302 vty_out(vty, " %s %s\n",
15303 community_direct_str(entry->direct),
15304 community_list_config_str(entry));
15305 }
15306 }
15307
15308 DEFUN (show_extcommunity_list,
15309 show_bgp_extcommunity_list_cmd,
15310 "show bgp extcommunity-list",
15311 SHOW_STR
15312 BGP_STR
15313 "List extended-community list\n")
15314 {
15315 struct community_list *list;
15316 struct community_list_master *cm;
15317 int idx = 0;
15318
15319 if (argv_find(argv, argc, "ip", &idx)) {
15320 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15321 vty_out(vty, "if you are using this please migrate to the below command.\n");
15322 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15323 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15324 }
15325 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15326 if (!cm)
15327 return CMD_SUCCESS;
15328
15329 for (list = cm->num.head; list; list = list->next)
15330 extcommunity_list_show(vty, list);
15331
15332 for (list = cm->str.head; list; list = list->next)
15333 extcommunity_list_show(vty, list);
15334
15335 return CMD_SUCCESS;
15336 }
15337
15338 ALIAS (show_extcommunity_list,
15339 show_ip_extcommunity_list_cmd,
15340 "show ip extcommunity-list",
15341 SHOW_STR
15342 IP_STR
15343 "List extended-community list\n")
15344
15345 DEFUN (show_extcommunity_list_arg,
15346 show_bgp_extcommunity_list_arg_cmd,
15347 "show bgp extcommunity-list <(1-500)|WORD>",
15348 SHOW_STR
15349 BGP_STR
15350 "List extended-community list\n"
15351 "Extcommunity-list number\n"
15352 "Extcommunity-list name\n")
15353 {
15354 int idx_comm_list = 3;
15355 struct community_list *list;
15356 int idx = 0;
15357
15358 if (argv_find(argv, argc, "ip", &idx)) {
15359 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15360 vty_out(vty, "if you are using this please migrate to the below command.\n");
15361 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15362 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15363 }
15364 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15365 EXTCOMMUNITY_LIST_MASTER);
15366 if (!list) {
15367 vty_out(vty, "%% Can't find extcommunity-list\n");
15368 return CMD_WARNING;
15369 }
15370
15371 extcommunity_list_show(vty, list);
15372
15373 return CMD_SUCCESS;
15374 }
15375
15376 ALIAS (show_extcommunity_list_arg,
15377 show_ip_extcommunity_list_arg_cmd,
15378 "show ip extcommunity-list <(1-500)|WORD>",
15379 SHOW_STR
15380 IP_STR
15381 "List extended-community list\n"
15382 "Extcommunity-list number\n"
15383 "Extcommunity-list name\n")
15384
15385 /* Display community-list and extcommunity-list configuration. */
15386 static int community_list_config_write(struct vty *vty)
15387 {
15388 struct community_list *list;
15389 struct community_entry *entry;
15390 struct community_list_master *cm;
15391 int write = 0;
15392
15393 /* Community-list. */
15394 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15395
15396 for (list = cm->num.head; list; list = list->next)
15397 for (entry = list->head; entry; entry = entry->next) {
15398 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15399 community_direct_str(entry->direct),
15400 community_list_config_str(entry));
15401 write++;
15402 }
15403 for (list = cm->str.head; list; list = list->next)
15404 for (entry = list->head; entry; entry = entry->next) {
15405 vty_out(vty, "bgp community-list %s %s %s %s\n",
15406 entry->style == COMMUNITY_LIST_STANDARD
15407 ? "standard"
15408 : "expanded",
15409 list->name, community_direct_str(entry->direct),
15410 community_list_config_str(entry));
15411 write++;
15412 }
15413
15414 /* Extcommunity-list. */
15415 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15416
15417 for (list = cm->num.head; list; list = list->next)
15418 for (entry = list->head; entry; entry = entry->next) {
15419 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15420 list->name, community_direct_str(entry->direct),
15421 community_list_config_str(entry));
15422 write++;
15423 }
15424 for (list = cm->str.head; list; list = list->next)
15425 for (entry = list->head; entry; entry = entry->next) {
15426 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15427 entry->style == EXTCOMMUNITY_LIST_STANDARD
15428 ? "standard"
15429 : "expanded",
15430 list->name, community_direct_str(entry->direct),
15431 community_list_config_str(entry));
15432 write++;
15433 }
15434
15435
15436 /* lcommunity-list. */
15437 cm = community_list_master_lookup(bgp_clist,
15438 LARGE_COMMUNITY_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 large-community-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 large-community-list %s %s %s %s\n",
15450 entry->style == LARGE_COMMUNITY_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 return write;
15459 }
15460
15461 static struct cmd_node community_list_node = {
15462 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15463 };
15464
15465 static void community_list_vty(void)
15466 {
15467 install_node(&community_list_node, community_list_config_write);
15468
15469 /* Community-list. */
15470 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15471 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15472 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15473 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15474 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15475 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15476 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15477 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15478 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15479 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15480 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15481 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15482 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15483 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15484 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15485 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15486
15487 /* Extcommunity-list. */
15488 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15489 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15490 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15491 install_element(CONFIG_NODE,
15492 &no_bgp_extcommunity_list_standard_all_list_cmd);
15493 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15494 install_element(CONFIG_NODE,
15495 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15496 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15497 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15498 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15499 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15500 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15501 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15502 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15503 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15504 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15505 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15506
15507 /* Large Community List */
15508 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15509 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15510 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15511 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15512 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15513 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15514 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15515 install_element(CONFIG_NODE,
15516 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15517 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15518 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15519 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15520 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15521 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15522 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15523 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15524 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15525 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15526 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15527 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15528 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15529 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15530 install_element(CONFIG_NODE,
15531 &no_ip_lcommunity_list_name_expanded_all_cmd);
15532 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15533 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15534 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15535 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15536 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15537 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15538 }