]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #2624 from donaldsharp/PIM_ZOMILY_ZOM
[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 "prefix.h"
26 #include "plist.h"
27 #include "buffer.h"
28 #include "linklist.h"
29 #include "stream.h"
30 #include "thread.h"
31 #include "log.h"
32 #include "memory.h"
33 #include "memory_vty.h"
34 #include "hash.h"
35 #include "queue.h"
36 #include "filter.h"
37 #include "frrstr.h"
38
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_advertise.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_aspath.h"
43 #include "bgpd/bgp_community.h"
44 #include "bgpd/bgp_ecommunity.h"
45 #include "bgpd/bgp_lcommunity.h"
46 #include "bgpd/bgp_damp.h"
47 #include "bgpd/bgp_debug.h"
48 #include "bgpd/bgp_fsm.h"
49 #include "bgpd/bgp_nexthop.h"
50 #include "bgpd/bgp_open.h"
51 #include "bgpd/bgp_regex.h"
52 #include "bgpd/bgp_route.h"
53 #include "bgpd/bgp_mplsvpn.h"
54 #include "bgpd/bgp_zebra.h"
55 #include "bgpd/bgp_table.h"
56 #include "bgpd/bgp_vty.h"
57 #include "bgpd/bgp_mpath.h"
58 #include "bgpd/bgp_packet.h"
59 #include "bgpd/bgp_updgrp.h"
60 #include "bgpd/bgp_bfd.h"
61 #include "bgpd/bgp_io.h"
62 #include "bgpd/bgp_evpn.h"
63
64 static struct peer_group *listen_range_exists(struct bgp *bgp,
65 struct prefix *range, int exact);
66
67 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
68 {
69 switch (afi) {
70 case AFI_IP:
71 switch (safi) {
72 case SAFI_UNICAST:
73 return BGP_IPV4_NODE;
74 break;
75 case SAFI_MULTICAST:
76 return BGP_IPV4M_NODE;
77 break;
78 case SAFI_LABELED_UNICAST:
79 return BGP_IPV4L_NODE;
80 break;
81 case SAFI_MPLS_VPN:
82 return BGP_VPNV4_NODE;
83 break;
84 case SAFI_FLOWSPEC:
85 return BGP_FLOWSPECV4_NODE;
86 default:
87 /* not expected */
88 return BGP_IPV4_NODE;
89 break;
90 }
91 break;
92 case AFI_IP6:
93 switch (safi) {
94 case SAFI_UNICAST:
95 return BGP_IPV6_NODE;
96 break;
97 case SAFI_MULTICAST:
98 return BGP_IPV6M_NODE;
99 break;
100 case SAFI_LABELED_UNICAST:
101 return BGP_IPV6L_NODE;
102 break;
103 case SAFI_MPLS_VPN:
104 return BGP_VPNV6_NODE;
105 break;
106 case SAFI_FLOWSPEC:
107 return BGP_FLOWSPECV6_NODE;
108 default:
109 /* not expected */
110 return BGP_IPV4_NODE;
111 break;
112 }
113 break;
114 case AFI_L2VPN:
115 return BGP_EVPN_NODE;
116 break;
117 case AFI_MAX:
118 // We should never be here but to clarify the switch statement..
119 return BGP_IPV4_NODE;
120 break;
121 }
122
123 // Impossible to happen
124 return BGP_IPV4_NODE;
125 }
126
127 /* Utility function to get address family from current node. */
128 afi_t bgp_node_afi(struct vty *vty)
129 {
130 afi_t afi;
131 switch (vty->node) {
132 case BGP_IPV6_NODE:
133 case BGP_IPV6M_NODE:
134 case BGP_IPV6L_NODE:
135 case BGP_VPNV6_NODE:
136 case BGP_FLOWSPECV6_NODE:
137 afi = AFI_IP6;
138 break;
139 case BGP_EVPN_NODE:
140 afi = AFI_L2VPN;
141 break;
142 default:
143 afi = AFI_IP;
144 break;
145 }
146 return afi;
147 }
148
149 /* Utility function to get subsequent address family from current
150 node. */
151 safi_t bgp_node_safi(struct vty *vty)
152 {
153 safi_t safi;
154 switch (vty->node) {
155 case BGP_VPNV4_NODE:
156 case BGP_VPNV6_NODE:
157 safi = SAFI_MPLS_VPN;
158 break;
159 case BGP_IPV4M_NODE:
160 case BGP_IPV6M_NODE:
161 safi = SAFI_MULTICAST;
162 break;
163 case BGP_EVPN_NODE:
164 safi = SAFI_EVPN;
165 break;
166 case BGP_IPV4L_NODE:
167 case BGP_IPV6L_NODE:
168 safi = SAFI_LABELED_UNICAST;
169 break;
170 case BGP_FLOWSPECV4_NODE:
171 case BGP_FLOWSPECV6_NODE:
172 safi = SAFI_FLOWSPEC;
173 break;
174 default:
175 safi = SAFI_UNICAST;
176 break;
177 }
178 return safi;
179 }
180
181 /**
182 * Converts an AFI in string form to afi_t
183 *
184 * @param afi string, one of
185 * - "ipv4"
186 * - "ipv6"
187 * @return the corresponding afi_t
188 */
189 afi_t bgp_vty_afi_from_str(const char *afi_str)
190 {
191 afi_t afi = AFI_MAX; /* unknown */
192 if (strmatch(afi_str, "ipv4"))
193 afi = AFI_IP;
194 else if (strmatch(afi_str, "ipv6"))
195 afi = AFI_IP6;
196 return afi;
197 }
198
199 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
200 afi_t *afi)
201 {
202 int ret = 0;
203 if (argv_find(argv, argc, "ipv4", index)) {
204 ret = 1;
205 if (afi)
206 *afi = AFI_IP;
207 } else if (argv_find(argv, argc, "ipv6", index)) {
208 ret = 1;
209 if (afi)
210 *afi = AFI_IP6;
211 }
212 return ret;
213 }
214
215 /* supports <unicast|multicast|vpn|labeled-unicast> */
216 safi_t bgp_vty_safi_from_str(const char *safi_str)
217 {
218 safi_t safi = SAFI_MAX; /* unknown */
219 if (strmatch(safi_str, "multicast"))
220 safi = SAFI_MULTICAST;
221 else if (strmatch(safi_str, "unicast"))
222 safi = SAFI_UNICAST;
223 else if (strmatch(safi_str, "vpn"))
224 safi = SAFI_MPLS_VPN;
225 else if (strmatch(safi_str, "labeled-unicast"))
226 safi = SAFI_LABELED_UNICAST;
227 else if (strmatch(safi_str, "flowspec"))
228 safi = SAFI_FLOWSPEC;
229 return safi;
230 }
231
232 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
233 safi_t *safi)
234 {
235 int ret = 0;
236 if (argv_find(argv, argc, "unicast", index)) {
237 ret = 1;
238 if (safi)
239 *safi = SAFI_UNICAST;
240 } else if (argv_find(argv, argc, "multicast", index)) {
241 ret = 1;
242 if (safi)
243 *safi = SAFI_MULTICAST;
244 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
245 ret = 1;
246 if (safi)
247 *safi = SAFI_LABELED_UNICAST;
248 } else if (argv_find(argv, argc, "vpn", index)) {
249 ret = 1;
250 if (safi)
251 *safi = SAFI_MPLS_VPN;
252 } else if (argv_find(argv, argc, "flowspec", index)) {
253 ret = 1;
254 if (safi)
255 *safi = SAFI_FLOWSPEC;
256 }
257 return ret;
258 }
259
260 /*
261 * bgp_vty_find_and_parse_afi_safi_bgp
262 *
263 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
264 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
265 * to appropriate values for the calling function. This is to allow the
266 * calling function to make decisions appropriate for the show command
267 * that is being parsed.
268 *
269 * The show commands are generally of the form:
270 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
271 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
272 *
273 * Since we use argv_find if the show command in particular doesn't have:
274 * [ip]
275 * [<view|vrf> VIEWVRFNAME]
276 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
277 * The command parsing should still be ok.
278 *
279 * vty -> The vty for the command so we can output some useful data in
280 * the event of a parse error in the vrf.
281 * argv -> The command tokens
282 * argc -> How many command tokens we have
283 * idx -> The current place in the command, generally should be 0 for this
284 * function
285 * afi -> The parsed afi if it was included in the show command, returned here
286 * safi -> The parsed safi if it was included in the show command, returned here
287 * bgp -> Pointer to the bgp data structure we need to fill in.
288 *
289 * The function returns the correct location in the parse tree for the
290 * last token found.
291 *
292 * Returns 0 for failure to parse correctly, else the idx position of where
293 * it found the last token.
294 */
295 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
296 struct cmd_token **argv, int argc,
297 int *idx, afi_t *afi, safi_t *safi,
298 struct bgp **bgp)
299 {
300 char *vrf_name = NULL;
301
302 assert(afi);
303 assert(safi);
304 assert(bgp);
305
306 if (argv_find(argv, argc, "ip", idx))
307 *afi = AFI_IP;
308
309 if (argv_find(argv, argc, "view", idx)
310 || argv_find(argv, argc, "vrf", idx)) {
311 vrf_name = argv[*idx + 1]->arg;
312
313 if (strmatch(vrf_name, "all"))
314 *bgp = NULL;
315 else {
316 *bgp = bgp_lookup_by_name(vrf_name);
317 if (!*bgp) {
318 vty_out(vty,
319 "View/Vrf specified is unknown: %s\n",
320 vrf_name);
321 *idx = 0;
322 return 0;
323 }
324 }
325 } else {
326 *bgp = bgp_get_default();
327 if (!*bgp) {
328 vty_out(vty, "Unable to find default BGP instance\n");
329 *idx = 0;
330 return 0;
331 }
332 }
333
334 if (argv_find_and_parse_afi(argv, argc, idx, afi))
335 argv_find_and_parse_safi(argv, argc, idx, safi);
336
337 *idx += 1;
338 return *idx;
339 }
340
341 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
342 {
343 struct interface *ifp = NULL;
344
345 if (su->sa.sa_family == AF_INET)
346 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
347 else if (su->sa.sa_family == AF_INET6)
348 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
349 su->sin6.sin6_scope_id,
350 bgp->vrf_id);
351
352 if (ifp)
353 return 1;
354
355 return 0;
356 }
357
358 /* Utility function for looking up peer from VTY. */
359 /* This is used only for configuration, so disallow if attempted on
360 * a dynamic neighbor.
361 */
362 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
363 {
364 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
365 int ret;
366 union sockunion su;
367 struct peer *peer;
368
369 if (!bgp) {
370 return NULL;
371 }
372
373 ret = str2sockunion(ip_str, &su);
374 if (ret < 0) {
375 peer = peer_lookup_by_conf_if(bgp, ip_str);
376 if (!peer) {
377 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
378 == NULL) {
379 vty_out(vty,
380 "%% Malformed address or name: %s\n",
381 ip_str);
382 return NULL;
383 }
384 }
385 } else {
386 peer = peer_lookup(bgp, &su);
387 if (!peer) {
388 vty_out(vty,
389 "%% Specify remote-as or peer-group commands first\n");
390 return NULL;
391 }
392 if (peer_dynamic_neighbor(peer)) {
393 vty_out(vty,
394 "%% Operation not allowed on a dynamic neighbor\n");
395 return NULL;
396 }
397 }
398 return peer;
399 }
400
401 /* Utility function for looking up peer or peer group. */
402 /* This is used only for configuration, so disallow if attempted on
403 * a dynamic neighbor.
404 */
405 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
406 {
407 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
408 int ret;
409 union sockunion su;
410 struct peer *peer = NULL;
411 struct peer_group *group = NULL;
412
413 if (!bgp) {
414 return NULL;
415 }
416
417 ret = str2sockunion(peer_str, &su);
418 if (ret == 0) {
419 /* IP address, locate peer. */
420 peer = peer_lookup(bgp, &su);
421 } else {
422 /* Not IP, could match either peer configured on interface or a
423 * group. */
424 peer = peer_lookup_by_conf_if(bgp, peer_str);
425 if (!peer)
426 group = peer_group_lookup(bgp, peer_str);
427 }
428
429 if (peer) {
430 if (peer_dynamic_neighbor(peer)) {
431 vty_out(vty,
432 "%% Operation not allowed on a dynamic neighbor\n");
433 return NULL;
434 }
435
436 return peer;
437 }
438
439 if (group)
440 return group->conf;
441
442 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
443
444 return NULL;
445 }
446
447 int bgp_vty_return(struct vty *vty, int ret)
448 {
449 const char *str = NULL;
450
451 switch (ret) {
452 case BGP_ERR_INVALID_VALUE:
453 str = "Invalid value";
454 break;
455 case BGP_ERR_INVALID_FLAG:
456 str = "Invalid flag";
457 break;
458 case BGP_ERR_PEER_GROUP_SHUTDOWN:
459 str = "Peer-group has been shutdown. Activate the peer-group first";
460 break;
461 case BGP_ERR_PEER_FLAG_CONFLICT:
462 str = "Can't set override-capability and strict-capability-match at the same time";
463 break;
464 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
465 str = "Specify remote-as or peer-group remote AS first";
466 break;
467 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
468 str = "Cannot change the peer-group. Deconfigure first";
469 break;
470 case BGP_ERR_PEER_GROUP_MISMATCH:
471 str = "Peer is not a member of this peer-group";
472 break;
473 case BGP_ERR_PEER_FILTER_CONFLICT:
474 str = "Prefix/distribute list can not co-exist";
475 break;
476 case BGP_ERR_NOT_INTERNAL_PEER:
477 str = "Invalid command. Not an internal neighbor";
478 break;
479 case BGP_ERR_REMOVE_PRIVATE_AS:
480 str = "remove-private-AS cannot be configured for IBGP peers";
481 break;
482 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
483 str = "Local-AS allowed only for EBGP peers";
484 break;
485 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
486 str = "Cannot have local-as same as BGP AS number";
487 break;
488 case BGP_ERR_TCPSIG_FAILED:
489 str = "Error while applying TCP-Sig to session(s)";
490 break;
491 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
492 str = "ebgp-multihop and ttl-security cannot be configured together";
493 break;
494 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
495 str = "ttl-security only allowed for EBGP peers";
496 break;
497 case BGP_ERR_AS_OVERRIDE:
498 str = "as-override cannot be configured for IBGP peers";
499 break;
500 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
501 str = "Invalid limit for number of dynamic neighbors";
502 break;
503 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
504 str = "Dynamic neighbor listen range already exists";
505 break;
506 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
507 str = "Operation not allowed on a dynamic neighbor";
508 break;
509 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
510 str = "Operation not allowed on a directly connected neighbor";
511 break;
512 case BGP_ERR_PEER_SAFI_CONFLICT:
513 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
514 break;
515 }
516 if (str) {
517 vty_out(vty, "%% %s\n", str);
518 return CMD_WARNING_CONFIG_FAILED;
519 }
520 return CMD_SUCCESS;
521 }
522
523 /* BGP clear sort. */
524 enum clear_sort {
525 clear_all,
526 clear_peer,
527 clear_group,
528 clear_external,
529 clear_as
530 };
531
532 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
533 safi_t safi, int error)
534 {
535 switch (error) {
536 case BGP_ERR_AF_UNCONFIGURED:
537 vty_out(vty,
538 "%%BGP: Enable %s address family for the neighbor %s\n",
539 afi_safi_print(afi, safi), peer->host);
540 break;
541 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
542 vty_out(vty,
543 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
544 peer->host);
545 break;
546 default:
547 break;
548 }
549 }
550
551 /* `clear ip bgp' functions. */
552 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
553 enum clear_sort sort, enum bgp_clear_type stype,
554 const char *arg)
555 {
556 int ret;
557 bool found = false;
558 struct peer *peer;
559 struct listnode *node, *nnode;
560
561 /* Clear all neighbors. */
562 /*
563 * Pass along pointer to next node to peer_clear() when walking all
564 * nodes on the BGP instance as that may get freed if it is a
565 * doppelganger
566 */
567 if (sort == clear_all) {
568 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
569 if (!peer->afc[afi][safi])
570 continue;
571
572 if (stype == BGP_CLEAR_SOFT_NONE)
573 ret = peer_clear(peer, &nnode);
574 else
575 ret = peer_clear_soft(peer, afi, safi, stype);
576
577 if (ret < 0)
578 bgp_clear_vty_error(vty, peer, afi, safi, ret);
579 else
580 found = true;
581 }
582
583 /* This is to apply read-only mode on this clear. */
584 if (stype == BGP_CLEAR_SOFT_NONE)
585 bgp->update_delay_over = 0;
586
587 if (!found)
588 vty_out(vty, "%%BGP: No %s peer configured",
589 afi_safi_print(afi, safi));
590
591 return CMD_SUCCESS;
592 }
593
594 /* Clear specified neighbor. */
595 if (sort == clear_peer) {
596 union sockunion su;
597
598 /* Make sockunion for lookup. */
599 ret = str2sockunion(arg, &su);
600 if (ret < 0) {
601 peer = peer_lookup_by_conf_if(bgp, arg);
602 if (!peer) {
603 peer = peer_lookup_by_hostname(bgp, arg);
604 if (!peer) {
605 vty_out(vty,
606 "Malformed address or name: %s\n",
607 arg);
608 return CMD_WARNING;
609 }
610 }
611 } else {
612 peer = peer_lookup(bgp, &su);
613 if (!peer) {
614 vty_out(vty,
615 "%%BGP: Unknown neighbor - \"%s\"\n",
616 arg);
617 return CMD_WARNING;
618 }
619 }
620
621 if (!peer->afc[afi][safi])
622 ret = BGP_ERR_AF_UNCONFIGURED;
623 else if (stype == BGP_CLEAR_SOFT_NONE)
624 ret = peer_clear(peer, NULL);
625 else
626 ret = peer_clear_soft(peer, afi, safi, stype);
627
628 if (ret < 0)
629 bgp_clear_vty_error(vty, peer, afi, safi, ret);
630
631 return CMD_SUCCESS;
632 }
633
634 /* Clear all neighbors belonging to a specific peer-group. */
635 if (sort == clear_group) {
636 struct peer_group *group;
637
638 group = peer_group_lookup(bgp, arg);
639 if (!group) {
640 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
641 return CMD_WARNING;
642 }
643
644 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
645 if (!peer->afc[afi][safi])
646 continue;
647
648 if (stype == BGP_CLEAR_SOFT_NONE)
649 ret = peer_clear(peer, NULL);
650 else
651 ret = peer_clear_soft(peer, afi, safi, stype);
652
653 if (ret < 0)
654 bgp_clear_vty_error(vty, peer, afi, safi, ret);
655 else
656 found = true;
657 }
658
659 if (!found)
660 vty_out(vty,
661 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
662 afi_safi_print(afi, safi), arg);
663
664 return CMD_SUCCESS;
665 }
666
667 /* Clear all external (eBGP) neighbors. */
668 if (sort == clear_external) {
669 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
670 if (peer->sort == BGP_PEER_IBGP)
671 continue;
672
673 if (!peer->afc[afi][safi])
674 continue;
675
676 if (stype == BGP_CLEAR_SOFT_NONE)
677 ret = peer_clear(peer, &nnode);
678 else
679 ret = peer_clear_soft(peer, afi, safi, stype);
680
681 if (ret < 0)
682 bgp_clear_vty_error(vty, peer, afi, safi, ret);
683 else
684 found = true;
685 }
686
687 if (!found)
688 vty_out(vty,
689 "%%BGP: No external %s peer is configured\n",
690 afi_safi_print(afi, safi));
691
692 return CMD_SUCCESS;
693 }
694
695 /* Clear all neighbors belonging to a specific AS. */
696 if (sort == clear_as) {
697 as_t as = strtoul(arg, NULL, 10);
698
699 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
700 if (peer->as != as)
701 continue;
702
703 if (!peer->afc[afi][safi])
704 ret = BGP_ERR_AF_UNCONFIGURED;
705 else if (stype == BGP_CLEAR_SOFT_NONE)
706 ret = peer_clear(peer, &nnode);
707 else
708 ret = peer_clear_soft(peer, afi, safi, stype);
709
710 if (ret < 0)
711 bgp_clear_vty_error(vty, peer, afi, safi, ret);
712 else
713 found = true;
714 }
715
716 if (!found)
717 vty_out(vty,
718 "%%BGP: No %s peer is configured with AS %s\n",
719 afi_safi_print(afi, safi), arg);
720
721 return CMD_SUCCESS;
722 }
723
724 return CMD_SUCCESS;
725 }
726
727 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
728 safi_t safi, enum clear_sort sort,
729 enum bgp_clear_type stype, const char *arg)
730 {
731 struct bgp *bgp;
732
733 /* BGP structure lookup. */
734 if (name) {
735 bgp = bgp_lookup_by_name(name);
736 if (bgp == NULL) {
737 vty_out(vty, "Can't find BGP instance %s\n", name);
738 return CMD_WARNING;
739 }
740 } else {
741 bgp = bgp_get_default();
742 if (bgp == NULL) {
743 vty_out(vty, "No BGP process is configured\n");
744 return CMD_WARNING;
745 }
746 }
747
748 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
749 }
750
751 /* clear soft inbound */
752 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
753 {
754 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
755 BGP_CLEAR_SOFT_IN, NULL);
756 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
757 BGP_CLEAR_SOFT_IN, NULL);
758 }
759
760 /* clear soft outbound */
761 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
762 {
763 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
764 BGP_CLEAR_SOFT_OUT, NULL);
765 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
766 BGP_CLEAR_SOFT_OUT, NULL);
767 }
768
769
770 #ifndef VTYSH_EXTRACT_PL
771 #include "bgpd/bgp_vty_clippy.c"
772 #endif
773
774 /* BGP global configuration. */
775 #if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
776 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
777 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
778 #endif
779 DEFUN_HIDDEN (bgp_multiple_instance_func,
780 bgp_multiple_instance_cmd,
781 "bgp multiple-instance",
782 BGP_STR
783 "Enable bgp multiple instance\n")
784 {
785 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
786 return CMD_SUCCESS;
787 }
788
789 DEFUN_HIDDEN (no_bgp_multiple_instance,
790 no_bgp_multiple_instance_cmd,
791 "no bgp multiple-instance",
792 NO_STR
793 BGP_STR
794 "BGP multiple instance\n")
795 {
796 int ret;
797
798 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
799 vty_out(vty, "if you are using this please let the developers know\n");
800 zlog_warn("Deprecated option: `bgp multiple-instance` being used");
801 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
802 if (ret < 0) {
803 vty_out(vty, "%% There are more than two BGP instances\n");
804 return CMD_WARNING_CONFIG_FAILED;
805 }
806 return CMD_SUCCESS;
807 }
808
809 #if defined(VERSION_TYPE_DEV) && (CONFDATE > 20190601)
810 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
811 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
812 #endif
813 DEFUN_HIDDEN (bgp_config_type,
814 bgp_config_type_cmd,
815 "bgp config-type <cisco|zebra>",
816 BGP_STR
817 "Configuration type\n"
818 "cisco\n"
819 "zebra\n")
820 {
821 int idx = 0;
822 if (argv_find(argv, argc, "cisco", &idx)) {
823 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
824 vty_out(vty, "if you are using this please let the developers know!\n");
825 zlog_warn("Deprecated option: `bgp config-type cisco` being used");
826 bgp_option_set(BGP_OPT_CONFIG_CISCO);
827 } else
828 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
829
830 return CMD_SUCCESS;
831 }
832
833 DEFUN_HIDDEN (no_bgp_config_type,
834 no_bgp_config_type_cmd,
835 "no bgp config-type [<cisco|zebra>]",
836 NO_STR
837 BGP_STR
838 "Display configuration type\n"
839 "cisco\n"
840 "zebra\n")
841 {
842 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
843 return CMD_SUCCESS;
844 }
845
846
847 DEFUN (no_synchronization,
848 no_synchronization_cmd,
849 "no synchronization",
850 NO_STR
851 "Perform IGP synchronization\n")
852 {
853 return CMD_SUCCESS;
854 }
855
856 DEFUN (no_auto_summary,
857 no_auto_summary_cmd,
858 "no auto-summary",
859 NO_STR
860 "Enable automatic network number summarization\n")
861 {
862 return CMD_SUCCESS;
863 }
864
865 /* "router bgp" commands. */
866 DEFUN_NOSH (router_bgp,
867 router_bgp_cmd,
868 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
869 ROUTER_STR
870 BGP_STR
871 AS_STR
872 BGP_INSTANCE_HELP_STR)
873 {
874 int idx_asn = 2;
875 int idx_view_vrf = 3;
876 int idx_vrf = 4;
877 int ret;
878 as_t as;
879 struct bgp *bgp;
880 const char *name = NULL;
881 enum bgp_instance_type inst_type;
882
883 // "router bgp" without an ASN
884 if (argc == 2) {
885 // Pending: Make VRF option available for ASN less config
886 bgp = bgp_get_default();
887
888 if (bgp == NULL) {
889 vty_out(vty, "%% No BGP process is configured\n");
890 return CMD_WARNING_CONFIG_FAILED;
891 }
892
893 if (listcount(bm->bgp) > 1) {
894 vty_out(vty, "%% Please specify ASN and VRF\n");
895 return CMD_WARNING_CONFIG_FAILED;
896 }
897 }
898
899 // "router bgp X"
900 else {
901 as = strtoul(argv[idx_asn]->arg, NULL, 10);
902
903 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
904 if (argc > 3) {
905 name = argv[idx_vrf]->arg;
906
907 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
908 inst_type = BGP_INSTANCE_TYPE_VRF;
909 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
910 inst_type = BGP_INSTANCE_TYPE_VIEW;
911 }
912
913 ret = bgp_get(&bgp, &as, name, inst_type);
914 switch (ret) {
915 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
916 vty_out(vty,
917 "Please specify 'bgp multiple-instance' first\n");
918 return CMD_WARNING_CONFIG_FAILED;
919 case BGP_ERR_AS_MISMATCH:
920 vty_out(vty, "BGP is already running; AS is %u\n", as);
921 return CMD_WARNING_CONFIG_FAILED;
922 case BGP_ERR_INSTANCE_MISMATCH:
923 vty_out(vty,
924 "BGP instance name and AS number mismatch\n");
925 vty_out(vty,
926 "BGP instance is already running; AS is %u\n",
927 as);
928 return CMD_WARNING_CONFIG_FAILED;
929 }
930
931 /* Pending: handle when user tries to change a view to vrf n vv.
932 */
933 }
934
935 /* unset the auto created flag as the user config is now present */
936 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
937 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
938
939 return CMD_SUCCESS;
940 }
941
942 /* "no router bgp" commands. */
943 DEFUN (no_router_bgp,
944 no_router_bgp_cmd,
945 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
946 NO_STR
947 ROUTER_STR
948 BGP_STR
949 AS_STR
950 BGP_INSTANCE_HELP_STR)
951 {
952 int idx_asn = 3;
953 int idx_vrf = 5;
954 as_t as;
955 struct bgp *bgp;
956 const char *name = NULL;
957
958 // "no router bgp" without an ASN
959 if (argc == 3) {
960 // Pending: Make VRF option available for ASN less config
961 bgp = bgp_get_default();
962
963 if (bgp == NULL) {
964 vty_out(vty, "%% No BGP process is configured\n");
965 return CMD_WARNING_CONFIG_FAILED;
966 }
967
968 if (listcount(bm->bgp) > 1) {
969 vty_out(vty, "%% Please specify ASN and VRF\n");
970 return CMD_WARNING_CONFIG_FAILED;
971 }
972
973 if (bgp->l3vni) {
974 vty_out(vty, "%% Please unconfigure l3vni %u",
975 bgp->l3vni);
976 return CMD_WARNING_CONFIG_FAILED;
977 }
978 } else {
979 as = strtoul(argv[idx_asn]->arg, NULL, 10);
980
981 if (argc > 4)
982 name = argv[idx_vrf]->arg;
983
984 /* Lookup bgp structure. */
985 bgp = bgp_lookup(as, name);
986 if (!bgp) {
987 vty_out(vty, "%% Can't find BGP instance\n");
988 return CMD_WARNING_CONFIG_FAILED;
989 }
990
991 if (bgp->l3vni) {
992 vty_out(vty, "%% Please unconfigure l3vni %u",
993 bgp->l3vni);
994 return CMD_WARNING_CONFIG_FAILED;
995 }
996 }
997
998 bgp_delete(bgp);
999
1000 return CMD_SUCCESS;
1001 }
1002
1003
1004 /* BGP router-id. */
1005
1006 DEFPY (bgp_router_id,
1007 bgp_router_id_cmd,
1008 "bgp router-id A.B.C.D",
1009 BGP_STR
1010 "Override configured router identifier\n"
1011 "Manually configured router identifier\n")
1012 {
1013 VTY_DECLVAR_CONTEXT(bgp, bgp);
1014 bgp_router_id_static_set(bgp, router_id);
1015 return CMD_SUCCESS;
1016 }
1017
1018 DEFPY (no_bgp_router_id,
1019 no_bgp_router_id_cmd,
1020 "no bgp router-id [A.B.C.D]",
1021 NO_STR
1022 BGP_STR
1023 "Override configured router identifier\n"
1024 "Manually configured router identifier\n")
1025 {
1026 VTY_DECLVAR_CONTEXT(bgp, bgp);
1027
1028 if (router_id_str) {
1029 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1030 vty_out(vty, "%% BGP router-id doesn't match\n");
1031 return CMD_WARNING_CONFIG_FAILED;
1032 }
1033 }
1034
1035 router_id.s_addr = 0;
1036 bgp_router_id_static_set(bgp, router_id);
1037
1038 return CMD_SUCCESS;
1039 }
1040
1041
1042 /* BGP Cluster ID. */
1043 DEFUN (bgp_cluster_id,
1044 bgp_cluster_id_cmd,
1045 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1046 BGP_STR
1047 "Configure Route-Reflector Cluster-id\n"
1048 "Route-Reflector Cluster-id in IP address format\n"
1049 "Route-Reflector Cluster-id as 32 bit quantity\n")
1050 {
1051 VTY_DECLVAR_CONTEXT(bgp, bgp);
1052 int idx_ipv4 = 2;
1053 int ret;
1054 struct in_addr cluster;
1055
1056 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1057 if (!ret) {
1058 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1059 return CMD_WARNING_CONFIG_FAILED;
1060 }
1061
1062 bgp_cluster_id_set(bgp, &cluster);
1063 bgp_clear_star_soft_out(vty, bgp->name);
1064
1065 return CMD_SUCCESS;
1066 }
1067
1068 DEFUN (no_bgp_cluster_id,
1069 no_bgp_cluster_id_cmd,
1070 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1071 NO_STR
1072 BGP_STR
1073 "Configure Route-Reflector Cluster-id\n"
1074 "Route-Reflector Cluster-id in IP address format\n"
1075 "Route-Reflector Cluster-id as 32 bit quantity\n")
1076 {
1077 VTY_DECLVAR_CONTEXT(bgp, bgp);
1078 bgp_cluster_id_unset(bgp);
1079 bgp_clear_star_soft_out(vty, bgp->name);
1080
1081 return CMD_SUCCESS;
1082 }
1083
1084 DEFUN (bgp_confederation_identifier,
1085 bgp_confederation_identifier_cmd,
1086 "bgp confederation identifier (1-4294967295)",
1087 "BGP specific commands\n"
1088 "AS confederation parameters\n"
1089 "AS number\n"
1090 "Set routing domain confederation AS\n")
1091 {
1092 VTY_DECLVAR_CONTEXT(bgp, bgp);
1093 int idx_number = 3;
1094 as_t as;
1095
1096 as = strtoul(argv[idx_number]->arg, NULL, 10);
1097
1098 bgp_confederation_id_set(bgp, as);
1099
1100 return CMD_SUCCESS;
1101 }
1102
1103 DEFUN (no_bgp_confederation_identifier,
1104 no_bgp_confederation_identifier_cmd,
1105 "no bgp confederation identifier [(1-4294967295)]",
1106 NO_STR
1107 "BGP specific commands\n"
1108 "AS confederation parameters\n"
1109 "AS number\n"
1110 "Set routing domain confederation AS\n")
1111 {
1112 VTY_DECLVAR_CONTEXT(bgp, bgp);
1113 bgp_confederation_id_unset(bgp);
1114
1115 return CMD_SUCCESS;
1116 }
1117
1118 DEFUN (bgp_confederation_peers,
1119 bgp_confederation_peers_cmd,
1120 "bgp confederation peers (1-4294967295)...",
1121 "BGP specific commands\n"
1122 "AS confederation parameters\n"
1123 "Peer ASs in BGP confederation\n"
1124 AS_STR)
1125 {
1126 VTY_DECLVAR_CONTEXT(bgp, bgp);
1127 int idx_asn = 3;
1128 as_t as;
1129 int i;
1130
1131 for (i = idx_asn; i < argc; i++) {
1132 as = strtoul(argv[i]->arg, NULL, 10);
1133
1134 if (bgp->as == as) {
1135 vty_out(vty,
1136 "%% Local member-AS not allowed in confed peer list\n");
1137 continue;
1138 }
1139
1140 bgp_confederation_peers_add(bgp, as);
1141 }
1142 return CMD_SUCCESS;
1143 }
1144
1145 DEFUN (no_bgp_confederation_peers,
1146 no_bgp_confederation_peers_cmd,
1147 "no bgp confederation peers (1-4294967295)...",
1148 NO_STR
1149 "BGP specific commands\n"
1150 "AS confederation parameters\n"
1151 "Peer ASs in BGP confederation\n"
1152 AS_STR)
1153 {
1154 VTY_DECLVAR_CONTEXT(bgp, bgp);
1155 int idx_asn = 4;
1156 as_t as;
1157 int i;
1158
1159 for (i = idx_asn; i < argc; i++) {
1160 as = strtoul(argv[i]->arg, NULL, 10);
1161
1162 bgp_confederation_peers_remove(bgp, as);
1163 }
1164 return CMD_SUCCESS;
1165 }
1166
1167 /**
1168 * Central routine for maximum-paths configuration.
1169 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1170 * @set: 1 for setting values, 0 for removing the max-paths config.
1171 */
1172 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1173 const char *mpaths, uint16_t options,
1174 int set)
1175 {
1176 VTY_DECLVAR_CONTEXT(bgp, bgp);
1177 uint16_t maxpaths = 0;
1178 int ret;
1179 afi_t afi;
1180 safi_t safi;
1181
1182 afi = bgp_node_afi(vty);
1183 safi = bgp_node_safi(vty);
1184
1185 if (set) {
1186 maxpaths = strtol(mpaths, NULL, 10);
1187 if (maxpaths > multipath_num) {
1188 vty_out(vty,
1189 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1190 maxpaths, multipath_num);
1191 return CMD_WARNING_CONFIG_FAILED;
1192 }
1193 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1194 options);
1195 } else
1196 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1197
1198 if (ret < 0) {
1199 vty_out(vty,
1200 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1201 (set == 1) ? "" : "un",
1202 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1203 maxpaths, afi, safi);
1204 return CMD_WARNING_CONFIG_FAILED;
1205 }
1206
1207 bgp_recalculate_all_bestpaths(bgp);
1208
1209 return CMD_SUCCESS;
1210 }
1211
1212 DEFUN (bgp_maxmed_admin,
1213 bgp_maxmed_admin_cmd,
1214 "bgp max-med administrative ",
1215 BGP_STR
1216 "Advertise routes with max-med\n"
1217 "Administratively applied, for an indefinite period\n")
1218 {
1219 VTY_DECLVAR_CONTEXT(bgp, bgp);
1220
1221 bgp->v_maxmed_admin = 1;
1222 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1223
1224 bgp_maxmed_update(bgp);
1225
1226 return CMD_SUCCESS;
1227 }
1228
1229 DEFUN (bgp_maxmed_admin_medv,
1230 bgp_maxmed_admin_medv_cmd,
1231 "bgp max-med administrative (0-4294967295)",
1232 BGP_STR
1233 "Advertise routes with max-med\n"
1234 "Administratively applied, for an indefinite period\n"
1235 "Max MED value to be used\n")
1236 {
1237 VTY_DECLVAR_CONTEXT(bgp, bgp);
1238 int idx_number = 3;
1239
1240 bgp->v_maxmed_admin = 1;
1241 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1242
1243 bgp_maxmed_update(bgp);
1244
1245 return CMD_SUCCESS;
1246 }
1247
1248 DEFUN (no_bgp_maxmed_admin,
1249 no_bgp_maxmed_admin_cmd,
1250 "no bgp max-med administrative [(0-4294967295)]",
1251 NO_STR
1252 BGP_STR
1253 "Advertise routes with max-med\n"
1254 "Administratively applied, for an indefinite period\n"
1255 "Max MED value to be used\n")
1256 {
1257 VTY_DECLVAR_CONTEXT(bgp, bgp);
1258 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1259 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1260 bgp_maxmed_update(bgp);
1261
1262 return CMD_SUCCESS;
1263 }
1264
1265 DEFUN (bgp_maxmed_onstartup,
1266 bgp_maxmed_onstartup_cmd,
1267 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1268 BGP_STR
1269 "Advertise routes with max-med\n"
1270 "Effective on a startup\n"
1271 "Time (seconds) period for max-med\n"
1272 "Max MED value to be used\n")
1273 {
1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
1275 int idx = 0;
1276
1277 argv_find(argv, argc, "(5-86400)", &idx);
1278 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1279 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1280 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1281 else
1282 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1283
1284 bgp_maxmed_update(bgp);
1285
1286 return CMD_SUCCESS;
1287 }
1288
1289 DEFUN (no_bgp_maxmed_onstartup,
1290 no_bgp_maxmed_onstartup_cmd,
1291 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1292 NO_STR
1293 BGP_STR
1294 "Advertise routes with max-med\n"
1295 "Effective on a startup\n"
1296 "Time (seconds) period for max-med\n"
1297 "Max MED value to be used\n")
1298 {
1299 VTY_DECLVAR_CONTEXT(bgp, bgp);
1300
1301 /* Cancel max-med onstartup if its on */
1302 if (bgp->t_maxmed_onstartup) {
1303 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1304 bgp->maxmed_onstartup_over = 1;
1305 }
1306
1307 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1308 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1309
1310 bgp_maxmed_update(bgp);
1311
1312 return CMD_SUCCESS;
1313 }
1314
1315 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1316 const char *wait)
1317 {
1318 VTY_DECLVAR_CONTEXT(bgp, bgp);
1319 uint16_t update_delay;
1320 uint16_t establish_wait;
1321
1322 update_delay = strtoul(delay, NULL, 10);
1323
1324 if (!wait) /* update-delay <delay> */
1325 {
1326 bgp->v_update_delay = update_delay;
1327 bgp->v_establish_wait = bgp->v_update_delay;
1328 return CMD_SUCCESS;
1329 }
1330
1331 /* update-delay <delay> <establish-wait> */
1332 establish_wait = atoi(wait);
1333 if (update_delay < establish_wait) {
1334 vty_out(vty,
1335 "%%Failed: update-delay less than the establish-wait!\n");
1336 return CMD_WARNING_CONFIG_FAILED;
1337 }
1338
1339 bgp->v_update_delay = update_delay;
1340 bgp->v_establish_wait = establish_wait;
1341
1342 return CMD_SUCCESS;
1343 }
1344
1345 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1346 {
1347 VTY_DECLVAR_CONTEXT(bgp, bgp);
1348
1349 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1350 bgp->v_establish_wait = bgp->v_update_delay;
1351
1352 return CMD_SUCCESS;
1353 }
1354
1355 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1356 {
1357 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1358 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1359 if (bgp->v_update_delay != bgp->v_establish_wait)
1360 vty_out(vty, " %d", bgp->v_establish_wait);
1361 vty_out(vty, "\n");
1362 }
1363 }
1364
1365
1366 /* Update-delay configuration */
1367 DEFUN (bgp_update_delay,
1368 bgp_update_delay_cmd,
1369 "update-delay (0-3600)",
1370 "Force initial delay for best-path and updates\n"
1371 "Seconds\n")
1372 {
1373 int idx_number = 1;
1374 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1375 }
1376
1377 DEFUN (bgp_update_delay_establish_wait,
1378 bgp_update_delay_establish_wait_cmd,
1379 "update-delay (0-3600) (1-3600)",
1380 "Force initial delay for best-path and updates\n"
1381 "Seconds\n"
1382 "Seconds\n")
1383 {
1384 int idx_number = 1;
1385 int idx_number_2 = 2;
1386 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1387 argv[idx_number_2]->arg);
1388 }
1389
1390 /* Update-delay deconfiguration */
1391 DEFUN (no_bgp_update_delay,
1392 no_bgp_update_delay_cmd,
1393 "no update-delay [(0-3600) [(1-3600)]]",
1394 NO_STR
1395 "Force initial delay for best-path and updates\n"
1396 "Seconds\n"
1397 "Seconds\n")
1398 {
1399 return bgp_update_delay_deconfig_vty(vty);
1400 }
1401
1402
1403 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1404 char set)
1405 {
1406 VTY_DECLVAR_CONTEXT(bgp, bgp);
1407
1408 if (set) {
1409 uint32_t quanta = strtoul(num, NULL, 10);
1410 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1411 memory_order_relaxed);
1412 } else {
1413 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1414 memory_order_relaxed);
1415 }
1416
1417 return CMD_SUCCESS;
1418 }
1419
1420 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1421 char set)
1422 {
1423 VTY_DECLVAR_CONTEXT(bgp, bgp);
1424
1425 if (set) {
1426 uint32_t quanta = strtoul(num, NULL, 10);
1427 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1428 memory_order_relaxed);
1429 } else {
1430 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1431 memory_order_relaxed);
1432 }
1433
1434 return CMD_SUCCESS;
1435 }
1436
1437 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1438 {
1439 uint32_t quanta =
1440 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1441 if (quanta != BGP_WRITE_PACKET_MAX)
1442 vty_out(vty, " write-quanta %d\n", quanta);
1443 }
1444
1445 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1446 {
1447 uint32_t quanta =
1448 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1449 if (quanta != BGP_READ_PACKET_MAX)
1450 vty_out(vty, " read-quanta %d\n", quanta);
1451 }
1452
1453 /* Packet quanta configuration */
1454 DEFUN (bgp_wpkt_quanta,
1455 bgp_wpkt_quanta_cmd,
1456 "write-quanta (1-10)",
1457 "How many packets to write to peer socket per run\n"
1458 "Number of packets\n")
1459 {
1460 int idx_number = 1;
1461 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1462 }
1463
1464 DEFUN (no_bgp_wpkt_quanta,
1465 no_bgp_wpkt_quanta_cmd,
1466 "no write-quanta (1-10)",
1467 NO_STR
1468 "How many packets to write to peer socket per I/O cycle\n"
1469 "Number of packets\n")
1470 {
1471 int idx_number = 2;
1472 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1473 }
1474
1475 DEFUN (bgp_rpkt_quanta,
1476 bgp_rpkt_quanta_cmd,
1477 "read-quanta (1-10)",
1478 "How many packets to read from peer socket per I/O cycle\n"
1479 "Number of packets\n")
1480 {
1481 int idx_number = 1;
1482 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1483 }
1484
1485 DEFUN (no_bgp_rpkt_quanta,
1486 no_bgp_rpkt_quanta_cmd,
1487 "no read-quanta (1-10)",
1488 NO_STR
1489 "How many packets to read from peer socket per I/O cycle\n"
1490 "Number of packets\n")
1491 {
1492 int idx_number = 2;
1493 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1494 }
1495
1496 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1497 {
1498 if (!bgp->heuristic_coalesce)
1499 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1500 }
1501
1502
1503 DEFUN (bgp_coalesce_time,
1504 bgp_coalesce_time_cmd,
1505 "coalesce-time (0-4294967295)",
1506 "Subgroup coalesce timer\n"
1507 "Subgroup coalesce timer value (in ms)\n")
1508 {
1509 VTY_DECLVAR_CONTEXT(bgp, bgp);
1510
1511 int idx = 0;
1512 argv_find(argv, argc, "(0-4294967295)", &idx);
1513 bgp->heuristic_coalesce = false;
1514 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1515 return CMD_SUCCESS;
1516 }
1517
1518 DEFUN (no_bgp_coalesce_time,
1519 no_bgp_coalesce_time_cmd,
1520 "no coalesce-time (0-4294967295)",
1521 NO_STR
1522 "Subgroup coalesce timer\n"
1523 "Subgroup coalesce timer value (in ms)\n")
1524 {
1525 VTY_DECLVAR_CONTEXT(bgp, bgp);
1526
1527 bgp->heuristic_coalesce = true;
1528 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1529 return CMD_SUCCESS;
1530 }
1531
1532 /* Maximum-paths configuration */
1533 DEFUN (bgp_maxpaths,
1534 bgp_maxpaths_cmd,
1535 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1536 "Forward packets over multiple paths\n"
1537 "Number of paths\n")
1538 {
1539 int idx_number = 1;
1540 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1541 argv[idx_number]->arg, 0, 1);
1542 }
1543
1544 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1545 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1546 "Forward packets over multiple paths\n"
1547 "Number of paths\n")
1548
1549 DEFUN (bgp_maxpaths_ibgp,
1550 bgp_maxpaths_ibgp_cmd,
1551 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1552 "Forward packets over multiple paths\n"
1553 "iBGP-multipath\n"
1554 "Number of paths\n")
1555 {
1556 int idx_number = 2;
1557 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1558 argv[idx_number]->arg, 0, 1);
1559 }
1560
1561 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1562 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1563 "Forward packets over multiple paths\n"
1564 "iBGP-multipath\n"
1565 "Number of paths\n")
1566
1567 DEFUN (bgp_maxpaths_ibgp_cluster,
1568 bgp_maxpaths_ibgp_cluster_cmd,
1569 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1570 "Forward packets over multiple paths\n"
1571 "iBGP-multipath\n"
1572 "Number of paths\n"
1573 "Match the cluster length\n")
1574 {
1575 int idx_number = 2;
1576 return bgp_maxpaths_config_vty(
1577 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1578 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1579 }
1580
1581 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1582 "maximum-paths ibgp " CMD_RANGE_STR(
1583 1, MULTIPATH_NUM) " equal-cluster-length",
1584 "Forward packets over multiple paths\n"
1585 "iBGP-multipath\n"
1586 "Number of paths\n"
1587 "Match the cluster length\n")
1588
1589 DEFUN (no_bgp_maxpaths,
1590 no_bgp_maxpaths_cmd,
1591 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1592 NO_STR
1593 "Forward packets over multiple paths\n"
1594 "Number of paths\n")
1595 {
1596 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1597 }
1598
1599 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1600 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1601 "Forward packets over multiple paths\n"
1602 "Number of paths\n")
1603
1604 DEFUN (no_bgp_maxpaths_ibgp,
1605 no_bgp_maxpaths_ibgp_cmd,
1606 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1607 NO_STR
1608 "Forward packets over multiple paths\n"
1609 "iBGP-multipath\n"
1610 "Number of paths\n"
1611 "Match the cluster length\n")
1612 {
1613 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1614 }
1615
1616 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1617 "no maximum-paths ibgp [" CMD_RANGE_STR(
1618 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1619 NO_STR
1620 "Forward packets over multiple paths\n"
1621 "iBGP-multipath\n"
1622 "Number of paths\n"
1623 "Match the cluster length\n")
1624
1625 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1626 safi_t safi)
1627 {
1628 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1629 vty_out(vty, " maximum-paths %d\n",
1630 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1631 }
1632
1633 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1634 vty_out(vty, " maximum-paths ibgp %d",
1635 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1636 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1637 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1638 vty_out(vty, " equal-cluster-length");
1639 vty_out(vty, "\n");
1640 }
1641 }
1642
1643 /* BGP timers. */
1644
1645 DEFUN (bgp_timers,
1646 bgp_timers_cmd,
1647 "timers bgp (0-65535) (0-65535)",
1648 "Adjust routing timers\n"
1649 "BGP timers\n"
1650 "Keepalive interval\n"
1651 "Holdtime\n")
1652 {
1653 VTY_DECLVAR_CONTEXT(bgp, bgp);
1654 int idx_number = 2;
1655 int idx_number_2 = 3;
1656 unsigned long keepalive = 0;
1657 unsigned long holdtime = 0;
1658
1659 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1660 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1661
1662 /* Holdtime value check. */
1663 if (holdtime < 3 && holdtime != 0) {
1664 vty_out(vty,
1665 "%% hold time value must be either 0 or greater than 3\n");
1666 return CMD_WARNING_CONFIG_FAILED;
1667 }
1668
1669 bgp_timers_set(bgp, keepalive, holdtime);
1670
1671 return CMD_SUCCESS;
1672 }
1673
1674 DEFUN (no_bgp_timers,
1675 no_bgp_timers_cmd,
1676 "no timers bgp [(0-65535) (0-65535)]",
1677 NO_STR
1678 "Adjust routing timers\n"
1679 "BGP timers\n"
1680 "Keepalive interval\n"
1681 "Holdtime\n")
1682 {
1683 VTY_DECLVAR_CONTEXT(bgp, bgp);
1684 bgp_timers_unset(bgp);
1685
1686 return CMD_SUCCESS;
1687 }
1688
1689
1690 DEFUN (bgp_client_to_client_reflection,
1691 bgp_client_to_client_reflection_cmd,
1692 "bgp client-to-client reflection",
1693 "BGP specific commands\n"
1694 "Configure client to client route reflection\n"
1695 "reflection of routes allowed\n")
1696 {
1697 VTY_DECLVAR_CONTEXT(bgp, bgp);
1698 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1699 bgp_clear_star_soft_out(vty, bgp->name);
1700
1701 return CMD_SUCCESS;
1702 }
1703
1704 DEFUN (no_bgp_client_to_client_reflection,
1705 no_bgp_client_to_client_reflection_cmd,
1706 "no bgp client-to-client reflection",
1707 NO_STR
1708 "BGP specific commands\n"
1709 "Configure client to client route reflection\n"
1710 "reflection of routes allowed\n")
1711 {
1712 VTY_DECLVAR_CONTEXT(bgp, bgp);
1713 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1714 bgp_clear_star_soft_out(vty, bgp->name);
1715
1716 return CMD_SUCCESS;
1717 }
1718
1719 /* "bgp always-compare-med" configuration. */
1720 DEFUN (bgp_always_compare_med,
1721 bgp_always_compare_med_cmd,
1722 "bgp always-compare-med",
1723 "BGP specific commands\n"
1724 "Allow comparing MED from different neighbors\n")
1725 {
1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1728 bgp_recalculate_all_bestpaths(bgp);
1729
1730 return CMD_SUCCESS;
1731 }
1732
1733 DEFUN (no_bgp_always_compare_med,
1734 no_bgp_always_compare_med_cmd,
1735 "no bgp always-compare-med",
1736 NO_STR
1737 "BGP specific commands\n"
1738 "Allow comparing MED from different neighbors\n")
1739 {
1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1742 bgp_recalculate_all_bestpaths(bgp);
1743
1744 return CMD_SUCCESS;
1745 }
1746
1747 /* "bgp deterministic-med" configuration. */
1748 DEFUN (bgp_deterministic_med,
1749 bgp_deterministic_med_cmd,
1750 "bgp deterministic-med",
1751 "BGP specific commands\n"
1752 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1753 {
1754 VTY_DECLVAR_CONTEXT(bgp, bgp);
1755
1756 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1757 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1758 bgp_recalculate_all_bestpaths(bgp);
1759 }
1760
1761 return CMD_SUCCESS;
1762 }
1763
1764 DEFUN (no_bgp_deterministic_med,
1765 no_bgp_deterministic_med_cmd,
1766 "no bgp deterministic-med",
1767 NO_STR
1768 "BGP specific commands\n"
1769 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1770 {
1771 VTY_DECLVAR_CONTEXT(bgp, bgp);
1772 int bestpath_per_as_used;
1773 afi_t afi;
1774 safi_t safi;
1775 struct peer *peer;
1776 struct listnode *node, *nnode;
1777
1778 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1779 bestpath_per_as_used = 0;
1780
1781 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1782 FOREACH_AFI_SAFI (afi, safi)
1783 if (CHECK_FLAG(
1784 peer->af_flags[afi][safi],
1785 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1786 bestpath_per_as_used = 1;
1787 break;
1788 }
1789
1790 if (bestpath_per_as_used)
1791 break;
1792 }
1793
1794 if (bestpath_per_as_used) {
1795 vty_out(vty,
1796 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1797 return CMD_WARNING_CONFIG_FAILED;
1798 } else {
1799 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1800 bgp_recalculate_all_bestpaths(bgp);
1801 }
1802 }
1803
1804 return CMD_SUCCESS;
1805 }
1806
1807 /* "bgp graceful-restart" configuration. */
1808 DEFUN (bgp_graceful_restart,
1809 bgp_graceful_restart_cmd,
1810 "bgp graceful-restart",
1811 "BGP specific commands\n"
1812 "Graceful restart capability parameters\n")
1813 {
1814 VTY_DECLVAR_CONTEXT(bgp, bgp);
1815 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1816 return CMD_SUCCESS;
1817 }
1818
1819 DEFUN (no_bgp_graceful_restart,
1820 no_bgp_graceful_restart_cmd,
1821 "no bgp graceful-restart",
1822 NO_STR
1823 "BGP specific commands\n"
1824 "Graceful restart capability parameters\n")
1825 {
1826 VTY_DECLVAR_CONTEXT(bgp, bgp);
1827 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1828 return CMD_SUCCESS;
1829 }
1830
1831 DEFUN (bgp_graceful_restart_stalepath_time,
1832 bgp_graceful_restart_stalepath_time_cmd,
1833 "bgp graceful-restart stalepath-time (1-3600)",
1834 "BGP specific commands\n"
1835 "Graceful restart capability parameters\n"
1836 "Set the max time to hold onto restarting peer's stale paths\n"
1837 "Delay value (seconds)\n")
1838 {
1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 int idx_number = 3;
1841 uint32_t stalepath;
1842
1843 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1844 bgp->stalepath_time = stalepath;
1845 return CMD_SUCCESS;
1846 }
1847
1848 DEFUN (bgp_graceful_restart_restart_time,
1849 bgp_graceful_restart_restart_time_cmd,
1850 "bgp graceful-restart restart-time (1-3600)",
1851 "BGP specific commands\n"
1852 "Graceful restart capability parameters\n"
1853 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1854 "Delay value (seconds)\n")
1855 {
1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857 int idx_number = 3;
1858 uint32_t restart;
1859
1860 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1861 bgp->restart_time = restart;
1862 return CMD_SUCCESS;
1863 }
1864
1865 DEFUN (no_bgp_graceful_restart_stalepath_time,
1866 no_bgp_graceful_restart_stalepath_time_cmd,
1867 "no bgp graceful-restart stalepath-time [(1-3600)]",
1868 NO_STR
1869 "BGP specific commands\n"
1870 "Graceful restart capability parameters\n"
1871 "Set the max time to hold onto restarting peer's stale paths\n"
1872 "Delay value (seconds)\n")
1873 {
1874 VTY_DECLVAR_CONTEXT(bgp, bgp);
1875
1876 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1877 return CMD_SUCCESS;
1878 }
1879
1880 DEFUN (no_bgp_graceful_restart_restart_time,
1881 no_bgp_graceful_restart_restart_time_cmd,
1882 "no bgp graceful-restart restart-time [(1-3600)]",
1883 NO_STR
1884 "BGP specific commands\n"
1885 "Graceful restart capability parameters\n"
1886 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1887 "Delay value (seconds)\n")
1888 {
1889 VTY_DECLVAR_CONTEXT(bgp, bgp);
1890
1891 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1892 return CMD_SUCCESS;
1893 }
1894
1895 DEFUN (bgp_graceful_restart_preserve_fw,
1896 bgp_graceful_restart_preserve_fw_cmd,
1897 "bgp graceful-restart preserve-fw-state",
1898 "BGP specific commands\n"
1899 "Graceful restart capability parameters\n"
1900 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1901 {
1902 VTY_DECLVAR_CONTEXT(bgp, bgp);
1903 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1904 return CMD_SUCCESS;
1905 }
1906
1907 DEFUN (no_bgp_graceful_restart_preserve_fw,
1908 no_bgp_graceful_restart_preserve_fw_cmd,
1909 "no bgp graceful-restart preserve-fw-state",
1910 NO_STR
1911 "BGP specific commands\n"
1912 "Graceful restart capability parameters\n"
1913 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1914 {
1915 VTY_DECLVAR_CONTEXT(bgp, bgp);
1916 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1917 return CMD_SUCCESS;
1918 }
1919
1920 static void bgp_redistribute_redo(struct bgp *bgp)
1921 {
1922 afi_t afi;
1923 int i;
1924 struct list *red_list;
1925 struct listnode *node;
1926 struct bgp_redist *red;
1927
1928 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1929 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1930
1931 red_list = bgp->redist[afi][i];
1932 if (!red_list)
1933 continue;
1934
1935 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1936 bgp_redistribute_resend(bgp, afi, i,
1937 red->instance);
1938 }
1939 }
1940 }
1941 }
1942
1943 /* "bgp graceful-shutdown" configuration */
1944 DEFUN (bgp_graceful_shutdown,
1945 bgp_graceful_shutdown_cmd,
1946 "bgp graceful-shutdown",
1947 BGP_STR
1948 "Graceful shutdown parameters\n")
1949 {
1950 VTY_DECLVAR_CONTEXT(bgp, bgp);
1951
1952 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1953 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1954 bgp_static_redo_import_check(bgp);
1955 bgp_redistribute_redo(bgp);
1956 bgp_clear_star_soft_out(vty, bgp->name);
1957 bgp_clear_star_soft_in(vty, bgp->name);
1958 }
1959
1960 return CMD_SUCCESS;
1961 }
1962
1963 DEFUN (no_bgp_graceful_shutdown,
1964 no_bgp_graceful_shutdown_cmd,
1965 "no bgp graceful-shutdown",
1966 NO_STR
1967 BGP_STR
1968 "Graceful shutdown parameters\n")
1969 {
1970 VTY_DECLVAR_CONTEXT(bgp, bgp);
1971
1972 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1973 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1974 bgp_static_redo_import_check(bgp);
1975 bgp_redistribute_redo(bgp);
1976 bgp_clear_star_soft_out(vty, bgp->name);
1977 bgp_clear_star_soft_in(vty, bgp->name);
1978 }
1979
1980 return CMD_SUCCESS;
1981 }
1982
1983 /* "bgp fast-external-failover" configuration. */
1984 DEFUN (bgp_fast_external_failover,
1985 bgp_fast_external_failover_cmd,
1986 "bgp fast-external-failover",
1987 BGP_STR
1988 "Immediately reset session if a link to a directly connected external peer goes down\n")
1989 {
1990 VTY_DECLVAR_CONTEXT(bgp, bgp);
1991 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1992 return CMD_SUCCESS;
1993 }
1994
1995 DEFUN (no_bgp_fast_external_failover,
1996 no_bgp_fast_external_failover_cmd,
1997 "no bgp fast-external-failover",
1998 NO_STR
1999 BGP_STR
2000 "Immediately reset session if a link to a directly connected external peer goes down\n")
2001 {
2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2004 return CMD_SUCCESS;
2005 }
2006
2007 /* "bgp enforce-first-as" configuration. */
2008 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180517
2009 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2010 #endif
2011
2012 DEFUN_HIDDEN (bgp_enforce_first_as,
2013 bgp_enforce_first_as_cmd,
2014 "[no] bgp enforce-first-as",
2015 NO_STR
2016 BGP_STR
2017 "Enforce the first AS for EBGP routes\n")
2018 {
2019 VTY_DECLVAR_CONTEXT(bgp, bgp);
2020
2021 if (strmatch(argv[0]->text, "no"))
2022 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2023 else
2024 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2025
2026 return CMD_SUCCESS;
2027 }
2028
2029 /* "bgp bestpath compare-routerid" configuration. */
2030 DEFUN (bgp_bestpath_compare_router_id,
2031 bgp_bestpath_compare_router_id_cmd,
2032 "bgp bestpath compare-routerid",
2033 "BGP specific commands\n"
2034 "Change the default bestpath selection\n"
2035 "Compare router-id for identical EBGP paths\n")
2036 {
2037 VTY_DECLVAR_CONTEXT(bgp, bgp);
2038 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2039 bgp_recalculate_all_bestpaths(bgp);
2040
2041 return CMD_SUCCESS;
2042 }
2043
2044 DEFUN (no_bgp_bestpath_compare_router_id,
2045 no_bgp_bestpath_compare_router_id_cmd,
2046 "no bgp bestpath compare-routerid",
2047 NO_STR
2048 "BGP specific commands\n"
2049 "Change the default bestpath selection\n"
2050 "Compare router-id for identical EBGP paths\n")
2051 {
2052 VTY_DECLVAR_CONTEXT(bgp, bgp);
2053 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2054 bgp_recalculate_all_bestpaths(bgp);
2055
2056 return CMD_SUCCESS;
2057 }
2058
2059 /* "bgp bestpath as-path ignore" configuration. */
2060 DEFUN (bgp_bestpath_aspath_ignore,
2061 bgp_bestpath_aspath_ignore_cmd,
2062 "bgp bestpath as-path ignore",
2063 "BGP specific commands\n"
2064 "Change the default bestpath selection\n"
2065 "AS-path attribute\n"
2066 "Ignore as-path length in selecting a route\n")
2067 {
2068 VTY_DECLVAR_CONTEXT(bgp, bgp);
2069 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2070 bgp_recalculate_all_bestpaths(bgp);
2071
2072 return CMD_SUCCESS;
2073 }
2074
2075 DEFUN (no_bgp_bestpath_aspath_ignore,
2076 no_bgp_bestpath_aspath_ignore_cmd,
2077 "no bgp bestpath as-path ignore",
2078 NO_STR
2079 "BGP specific commands\n"
2080 "Change the default bestpath selection\n"
2081 "AS-path attribute\n"
2082 "Ignore as-path length in selecting a route\n")
2083 {
2084 VTY_DECLVAR_CONTEXT(bgp, bgp);
2085 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2086 bgp_recalculate_all_bestpaths(bgp);
2087
2088 return CMD_SUCCESS;
2089 }
2090
2091 /* "bgp bestpath as-path confed" configuration. */
2092 DEFUN (bgp_bestpath_aspath_confed,
2093 bgp_bestpath_aspath_confed_cmd,
2094 "bgp bestpath as-path confed",
2095 "BGP specific commands\n"
2096 "Change the default bestpath selection\n"
2097 "AS-path attribute\n"
2098 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2099 {
2100 VTY_DECLVAR_CONTEXT(bgp, bgp);
2101 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2102 bgp_recalculate_all_bestpaths(bgp);
2103
2104 return CMD_SUCCESS;
2105 }
2106
2107 DEFUN (no_bgp_bestpath_aspath_confed,
2108 no_bgp_bestpath_aspath_confed_cmd,
2109 "no bgp bestpath as-path confed",
2110 NO_STR
2111 "BGP specific commands\n"
2112 "Change the default bestpath selection\n"
2113 "AS-path attribute\n"
2114 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2115 {
2116 VTY_DECLVAR_CONTEXT(bgp, bgp);
2117 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2118 bgp_recalculate_all_bestpaths(bgp);
2119
2120 return CMD_SUCCESS;
2121 }
2122
2123 /* "bgp bestpath as-path multipath-relax" configuration. */
2124 DEFUN (bgp_bestpath_aspath_multipath_relax,
2125 bgp_bestpath_aspath_multipath_relax_cmd,
2126 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2127 "BGP specific commands\n"
2128 "Change the default bestpath selection\n"
2129 "AS-path attribute\n"
2130 "Allow load sharing across routes that have different AS paths (but same length)\n"
2131 "Generate an AS_SET\n"
2132 "Do not generate an AS_SET\n")
2133 {
2134 VTY_DECLVAR_CONTEXT(bgp, bgp);
2135 int idx = 0;
2136 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2137
2138 /* no-as-set is now the default behavior so we can silently
2139 * ignore it */
2140 if (argv_find(argv, argc, "as-set", &idx))
2141 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2142 else
2143 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2144
2145 bgp_recalculate_all_bestpaths(bgp);
2146
2147 return CMD_SUCCESS;
2148 }
2149
2150 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2151 no_bgp_bestpath_aspath_multipath_relax_cmd,
2152 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2153 NO_STR
2154 "BGP specific commands\n"
2155 "Change the default bestpath selection\n"
2156 "AS-path attribute\n"
2157 "Allow load sharing across routes that have different AS paths (but same length)\n"
2158 "Generate an AS_SET\n"
2159 "Do not generate an AS_SET\n")
2160 {
2161 VTY_DECLVAR_CONTEXT(bgp, bgp);
2162 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2163 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2164 bgp_recalculate_all_bestpaths(bgp);
2165
2166 return CMD_SUCCESS;
2167 }
2168
2169 /* "bgp log-neighbor-changes" configuration. */
2170 DEFUN (bgp_log_neighbor_changes,
2171 bgp_log_neighbor_changes_cmd,
2172 "bgp log-neighbor-changes",
2173 "BGP specific commands\n"
2174 "Log neighbor up/down and reset reason\n")
2175 {
2176 VTY_DECLVAR_CONTEXT(bgp, bgp);
2177 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2178 return CMD_SUCCESS;
2179 }
2180
2181 DEFUN (no_bgp_log_neighbor_changes,
2182 no_bgp_log_neighbor_changes_cmd,
2183 "no bgp log-neighbor-changes",
2184 NO_STR
2185 "BGP specific commands\n"
2186 "Log neighbor up/down and reset reason\n")
2187 {
2188 VTY_DECLVAR_CONTEXT(bgp, bgp);
2189 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2190 return CMD_SUCCESS;
2191 }
2192
2193 /* "bgp bestpath med" configuration. */
2194 DEFUN (bgp_bestpath_med,
2195 bgp_bestpath_med_cmd,
2196 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2197 "BGP specific commands\n"
2198 "Change the default bestpath selection\n"
2199 "MED attribute\n"
2200 "Compare MED among confederation paths\n"
2201 "Treat missing MED as the least preferred one\n"
2202 "Treat missing MED as the least preferred one\n"
2203 "Compare MED among confederation paths\n")
2204 {
2205 VTY_DECLVAR_CONTEXT(bgp, bgp);
2206
2207 int idx = 0;
2208 if (argv_find(argv, argc, "confed", &idx))
2209 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2210 idx = 0;
2211 if (argv_find(argv, argc, "missing-as-worst", &idx))
2212 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2213
2214 bgp_recalculate_all_bestpaths(bgp);
2215
2216 return CMD_SUCCESS;
2217 }
2218
2219 DEFUN (no_bgp_bestpath_med,
2220 no_bgp_bestpath_med_cmd,
2221 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2222 NO_STR
2223 "BGP specific commands\n"
2224 "Change the default bestpath selection\n"
2225 "MED attribute\n"
2226 "Compare MED among confederation paths\n"
2227 "Treat missing MED as the least preferred one\n"
2228 "Treat missing MED as the least preferred one\n"
2229 "Compare MED among confederation paths\n")
2230 {
2231 VTY_DECLVAR_CONTEXT(bgp, bgp);
2232
2233 int idx = 0;
2234 if (argv_find(argv, argc, "confed", &idx))
2235 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2236 idx = 0;
2237 if (argv_find(argv, argc, "missing-as-worst", &idx))
2238 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2239
2240 bgp_recalculate_all_bestpaths(bgp);
2241
2242 return CMD_SUCCESS;
2243 }
2244
2245 /* "no bgp default ipv4-unicast". */
2246 DEFUN (no_bgp_default_ipv4_unicast,
2247 no_bgp_default_ipv4_unicast_cmd,
2248 "no bgp default ipv4-unicast",
2249 NO_STR
2250 "BGP specific commands\n"
2251 "Configure BGP defaults\n"
2252 "Activate ipv4-unicast for a peer by default\n")
2253 {
2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2256 return CMD_SUCCESS;
2257 }
2258
2259 DEFUN (bgp_default_ipv4_unicast,
2260 bgp_default_ipv4_unicast_cmd,
2261 "bgp default ipv4-unicast",
2262 "BGP specific commands\n"
2263 "Configure BGP defaults\n"
2264 "Activate ipv4-unicast for a peer by default\n")
2265 {
2266 VTY_DECLVAR_CONTEXT(bgp, bgp);
2267 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2268 return CMD_SUCCESS;
2269 }
2270
2271 /* Display hostname in certain command outputs */
2272 DEFUN (bgp_default_show_hostname,
2273 bgp_default_show_hostname_cmd,
2274 "bgp default show-hostname",
2275 "BGP specific commands\n"
2276 "Configure BGP defaults\n"
2277 "Show hostname in certain command ouputs\n")
2278 {
2279 VTY_DECLVAR_CONTEXT(bgp, bgp);
2280 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2281 return CMD_SUCCESS;
2282 }
2283
2284 DEFUN (no_bgp_default_show_hostname,
2285 no_bgp_default_show_hostname_cmd,
2286 "no bgp default show-hostname",
2287 NO_STR
2288 "BGP specific commands\n"
2289 "Configure BGP defaults\n"
2290 "Show hostname in certain command ouputs\n")
2291 {
2292 VTY_DECLVAR_CONTEXT(bgp, bgp);
2293 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2294 return CMD_SUCCESS;
2295 }
2296
2297 /* "bgp network import-check" configuration. */
2298 DEFUN (bgp_network_import_check,
2299 bgp_network_import_check_cmd,
2300 "bgp network import-check",
2301 "BGP specific commands\n"
2302 "BGP network command\n"
2303 "Check BGP network route exists in IGP\n")
2304 {
2305 VTY_DECLVAR_CONTEXT(bgp, bgp);
2306 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2307 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2308 bgp_static_redo_import_check(bgp);
2309 }
2310
2311 return CMD_SUCCESS;
2312 }
2313
2314 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2315 "bgp network import-check exact",
2316 "BGP specific commands\n"
2317 "BGP network command\n"
2318 "Check BGP network route exists in IGP\n"
2319 "Match route precisely\n")
2320
2321 DEFUN (no_bgp_network_import_check,
2322 no_bgp_network_import_check_cmd,
2323 "no bgp network import-check",
2324 NO_STR
2325 "BGP specific commands\n"
2326 "BGP network command\n"
2327 "Check BGP network route exists in IGP\n")
2328 {
2329 VTY_DECLVAR_CONTEXT(bgp, bgp);
2330 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2331 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2332 bgp_static_redo_import_check(bgp);
2333 }
2334
2335 return CMD_SUCCESS;
2336 }
2337
2338 DEFUN (bgp_default_local_preference,
2339 bgp_default_local_preference_cmd,
2340 "bgp default local-preference (0-4294967295)",
2341 "BGP specific commands\n"
2342 "Configure BGP defaults\n"
2343 "local preference (higher=more preferred)\n"
2344 "Configure default local preference value\n")
2345 {
2346 VTY_DECLVAR_CONTEXT(bgp, bgp);
2347 int idx_number = 3;
2348 uint32_t local_pref;
2349
2350 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2351
2352 bgp_default_local_preference_set(bgp, local_pref);
2353 bgp_clear_star_soft_in(vty, bgp->name);
2354
2355 return CMD_SUCCESS;
2356 }
2357
2358 DEFUN (no_bgp_default_local_preference,
2359 no_bgp_default_local_preference_cmd,
2360 "no bgp default local-preference [(0-4294967295)]",
2361 NO_STR
2362 "BGP specific commands\n"
2363 "Configure BGP defaults\n"
2364 "local preference (higher=more preferred)\n"
2365 "Configure default local preference value\n")
2366 {
2367 VTY_DECLVAR_CONTEXT(bgp, bgp);
2368 bgp_default_local_preference_unset(bgp);
2369 bgp_clear_star_soft_in(vty, bgp->name);
2370
2371 return CMD_SUCCESS;
2372 }
2373
2374
2375 DEFUN (bgp_default_subgroup_pkt_queue_max,
2376 bgp_default_subgroup_pkt_queue_max_cmd,
2377 "bgp default subgroup-pkt-queue-max (20-100)",
2378 "BGP specific commands\n"
2379 "Configure BGP defaults\n"
2380 "subgroup-pkt-queue-max\n"
2381 "Configure subgroup packet queue max\n")
2382 {
2383 VTY_DECLVAR_CONTEXT(bgp, bgp);
2384 int idx_number = 3;
2385 uint32_t max_size;
2386
2387 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2388
2389 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2390
2391 return CMD_SUCCESS;
2392 }
2393
2394 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2395 no_bgp_default_subgroup_pkt_queue_max_cmd,
2396 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2397 NO_STR
2398 "BGP specific commands\n"
2399 "Configure BGP defaults\n"
2400 "subgroup-pkt-queue-max\n"
2401 "Configure subgroup packet queue max\n")
2402 {
2403 VTY_DECLVAR_CONTEXT(bgp, bgp);
2404 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2405 return CMD_SUCCESS;
2406 }
2407
2408
2409 DEFUN (bgp_rr_allow_outbound_policy,
2410 bgp_rr_allow_outbound_policy_cmd,
2411 "bgp route-reflector allow-outbound-policy",
2412 "BGP specific commands\n"
2413 "Allow modifications made by out route-map\n"
2414 "on ibgp neighbors\n")
2415 {
2416 VTY_DECLVAR_CONTEXT(bgp, bgp);
2417
2418 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2419 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2420 update_group_announce_rrclients(bgp);
2421 bgp_clear_star_soft_out(vty, bgp->name);
2422 }
2423
2424 return CMD_SUCCESS;
2425 }
2426
2427 DEFUN (no_bgp_rr_allow_outbound_policy,
2428 no_bgp_rr_allow_outbound_policy_cmd,
2429 "no bgp route-reflector allow-outbound-policy",
2430 NO_STR
2431 "BGP specific commands\n"
2432 "Allow modifications made by out route-map\n"
2433 "on ibgp neighbors\n")
2434 {
2435 VTY_DECLVAR_CONTEXT(bgp, bgp);
2436
2437 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2438 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2439 update_group_announce_rrclients(bgp);
2440 bgp_clear_star_soft_out(vty, bgp->name);
2441 }
2442
2443 return CMD_SUCCESS;
2444 }
2445
2446 DEFUN (bgp_listen_limit,
2447 bgp_listen_limit_cmd,
2448 "bgp listen limit (1-5000)",
2449 "BGP specific commands\n"
2450 "Configure BGP defaults\n"
2451 "maximum number of BGP Dynamic Neighbors that can be created\n"
2452 "Configure Dynamic Neighbors listen limit value\n")
2453 {
2454 VTY_DECLVAR_CONTEXT(bgp, bgp);
2455 int idx_number = 3;
2456 int listen_limit;
2457
2458 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2459
2460 bgp_listen_limit_set(bgp, listen_limit);
2461
2462 return CMD_SUCCESS;
2463 }
2464
2465 DEFUN (no_bgp_listen_limit,
2466 no_bgp_listen_limit_cmd,
2467 "no bgp listen limit [(1-5000)]",
2468 "BGP specific commands\n"
2469 "Configure BGP defaults\n"
2470 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2471 "Configure Dynamic Neighbors listen limit value to default\n"
2472 "Configure Dynamic Neighbors listen limit value\n")
2473 {
2474 VTY_DECLVAR_CONTEXT(bgp, bgp);
2475 bgp_listen_limit_unset(bgp);
2476 return CMD_SUCCESS;
2477 }
2478
2479
2480 /*
2481 * Check if this listen range is already configured. Check for exact
2482 * match or overlap based on input.
2483 */
2484 static struct peer_group *listen_range_exists(struct bgp *bgp,
2485 struct prefix *range, int exact)
2486 {
2487 struct listnode *node, *nnode;
2488 struct listnode *node1, *nnode1;
2489 struct peer_group *group;
2490 struct prefix *lr;
2491 afi_t afi;
2492 int match;
2493
2494 afi = family2afi(range->family);
2495 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2496 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2497 lr)) {
2498 if (exact)
2499 match = prefix_same(range, lr);
2500 else
2501 match = (prefix_match(range, lr)
2502 || prefix_match(lr, range));
2503 if (match)
2504 return group;
2505 }
2506 }
2507
2508 return NULL;
2509 }
2510
2511 DEFUN (bgp_listen_range,
2512 bgp_listen_range_cmd,
2513 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2514 "BGP specific commands\n"
2515 "Configure BGP dynamic neighbors listen range\n"
2516 "Configure BGP dynamic neighbors listen range\n"
2517 NEIGHBOR_ADDR_STR
2518 "Member of the peer-group\n"
2519 "Peer-group name\n")
2520 {
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 struct prefix range;
2523 struct peer_group *group, *existing_group;
2524 afi_t afi;
2525 int ret;
2526 int idx = 0;
2527
2528 argv_find(argv, argc, "A.B.C.D/M", &idx);
2529 argv_find(argv, argc, "X:X::X:X/M", &idx);
2530 char *prefix = argv[idx]->arg;
2531 argv_find(argv, argc, "WORD", &idx);
2532 char *peergroup = argv[idx]->arg;
2533
2534 /* Convert IP prefix string to struct prefix. */
2535 ret = str2prefix(prefix, &range);
2536 if (!ret) {
2537 vty_out(vty, "%% Malformed listen range\n");
2538 return CMD_WARNING_CONFIG_FAILED;
2539 }
2540
2541 afi = family2afi(range.family);
2542
2543 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2544 vty_out(vty,
2545 "%% Malformed listen range (link-local address)\n");
2546 return CMD_WARNING_CONFIG_FAILED;
2547 }
2548
2549 apply_mask(&range);
2550
2551 /* Check if same listen range is already configured. */
2552 existing_group = listen_range_exists(bgp, &range, 1);
2553 if (existing_group) {
2554 if (strcmp(existing_group->name, peergroup) == 0)
2555 return CMD_SUCCESS;
2556 else {
2557 vty_out(vty,
2558 "%% Same listen range is attached to peer-group %s\n",
2559 existing_group->name);
2560 return CMD_WARNING_CONFIG_FAILED;
2561 }
2562 }
2563
2564 /* Check if an overlapping listen range exists. */
2565 if (listen_range_exists(bgp, &range, 0)) {
2566 vty_out(vty,
2567 "%% Listen range overlaps with existing listen range\n");
2568 return CMD_WARNING_CONFIG_FAILED;
2569 }
2570
2571 group = peer_group_lookup(bgp, peergroup);
2572 if (!group) {
2573 vty_out(vty, "%% Configure the peer-group first\n");
2574 return CMD_WARNING_CONFIG_FAILED;
2575 }
2576
2577 ret = peer_group_listen_range_add(group, &range);
2578 return bgp_vty_return(vty, ret);
2579 }
2580
2581 DEFUN (no_bgp_listen_range,
2582 no_bgp_listen_range_cmd,
2583 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2584 NO_STR
2585 "BGP specific commands\n"
2586 "Unconfigure BGP dynamic neighbors listen range\n"
2587 "Unconfigure BGP dynamic neighbors listen range\n"
2588 NEIGHBOR_ADDR_STR
2589 "Member of the peer-group\n"
2590 "Peer-group name\n")
2591 {
2592 VTY_DECLVAR_CONTEXT(bgp, bgp);
2593 struct prefix range;
2594 struct peer_group *group;
2595 afi_t afi;
2596 int ret;
2597 int idx = 0;
2598
2599 argv_find(argv, argc, "A.B.C.D/M", &idx);
2600 argv_find(argv, argc, "X:X::X:X/M", &idx);
2601 char *prefix = argv[idx]->arg;
2602 argv_find(argv, argc, "WORD", &idx);
2603 char *peergroup = argv[idx]->arg;
2604
2605 /* Convert IP prefix string to struct prefix. */
2606 ret = str2prefix(prefix, &range);
2607 if (!ret) {
2608 vty_out(vty, "%% Malformed listen range\n");
2609 return CMD_WARNING_CONFIG_FAILED;
2610 }
2611
2612 afi = family2afi(range.family);
2613
2614 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2615 vty_out(vty,
2616 "%% Malformed listen range (link-local address)\n");
2617 return CMD_WARNING_CONFIG_FAILED;
2618 }
2619
2620 apply_mask(&range);
2621
2622 group = peer_group_lookup(bgp, peergroup);
2623 if (!group) {
2624 vty_out(vty, "%% Peer-group does not exist\n");
2625 return CMD_WARNING_CONFIG_FAILED;
2626 }
2627
2628 ret = peer_group_listen_range_del(group, &range);
2629 return bgp_vty_return(vty, ret);
2630 }
2631
2632 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2633 {
2634 struct peer_group *group;
2635 struct listnode *node, *nnode, *rnode, *nrnode;
2636 struct prefix *range;
2637 afi_t afi;
2638 char buf[PREFIX2STR_BUFFER];
2639
2640 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2641 vty_out(vty, " bgp listen limit %d\n",
2642 bgp->dynamic_neighbors_limit);
2643
2644 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2645 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2646 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2647 nrnode, range)) {
2648 prefix2str(range, buf, sizeof(buf));
2649 vty_out(vty,
2650 " bgp listen range %s peer-group %s\n",
2651 buf, group->name);
2652 }
2653 }
2654 }
2655 }
2656
2657
2658 DEFUN (bgp_disable_connected_route_check,
2659 bgp_disable_connected_route_check_cmd,
2660 "bgp disable-ebgp-connected-route-check",
2661 "BGP specific commands\n"
2662 "Disable checking if nexthop is connected on ebgp sessions\n")
2663 {
2664 VTY_DECLVAR_CONTEXT(bgp, bgp);
2665 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2666 bgp_clear_star_soft_in(vty, bgp->name);
2667
2668 return CMD_SUCCESS;
2669 }
2670
2671 DEFUN (no_bgp_disable_connected_route_check,
2672 no_bgp_disable_connected_route_check_cmd,
2673 "no bgp disable-ebgp-connected-route-check",
2674 NO_STR
2675 "BGP specific commands\n"
2676 "Disable checking if nexthop is connected on ebgp sessions\n")
2677 {
2678 VTY_DECLVAR_CONTEXT(bgp, bgp);
2679 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2680 bgp_clear_star_soft_in(vty, bgp->name);
2681
2682 return CMD_SUCCESS;
2683 }
2684
2685
2686 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2687 const char *as_str, afi_t afi, safi_t safi)
2688 {
2689 VTY_DECLVAR_CONTEXT(bgp, bgp);
2690 int ret;
2691 as_t as;
2692 int as_type = AS_SPECIFIED;
2693 union sockunion su;
2694
2695 if (as_str[0] == 'i') {
2696 as = 0;
2697 as_type = AS_INTERNAL;
2698 } else if (as_str[0] == 'e') {
2699 as = 0;
2700 as_type = AS_EXTERNAL;
2701 } else {
2702 /* Get AS number. */
2703 as = strtoul(as_str, NULL, 10);
2704 }
2705
2706 /* If peer is peer group, call proper function. */
2707 ret = str2sockunion(peer_str, &su);
2708 if (ret < 0) {
2709 /* Check for peer by interface */
2710 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2711 safi);
2712 if (ret < 0) {
2713 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2714 if (ret < 0) {
2715 vty_out(vty,
2716 "%% Create the peer-group or interface first\n");
2717 return CMD_WARNING_CONFIG_FAILED;
2718 }
2719 return CMD_SUCCESS;
2720 }
2721 } else {
2722 if (peer_address_self_check(bgp, &su)) {
2723 vty_out(vty,
2724 "%% Can not configure the local system as neighbor\n");
2725 return CMD_WARNING_CONFIG_FAILED;
2726 }
2727 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2728 }
2729
2730 /* This peer belongs to peer group. */
2731 switch (ret) {
2732 case BGP_ERR_PEER_GROUP_MEMBER:
2733 vty_out(vty,
2734 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2735 as);
2736 return CMD_WARNING_CONFIG_FAILED;
2737 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2738 vty_out(vty,
2739 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2740 as, as_str);
2741 return CMD_WARNING_CONFIG_FAILED;
2742 }
2743 return bgp_vty_return(vty, ret);
2744 }
2745
2746 DEFUN (bgp_default_shutdown,
2747 bgp_default_shutdown_cmd,
2748 "[no] bgp default shutdown",
2749 NO_STR
2750 BGP_STR
2751 "Configure BGP defaults\n"
2752 "Apply administrative shutdown to newly configured peers\n")
2753 {
2754 VTY_DECLVAR_CONTEXT(bgp, bgp);
2755 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2756 return CMD_SUCCESS;
2757 }
2758
2759 DEFUN (neighbor_remote_as,
2760 neighbor_remote_as_cmd,
2761 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2762 NEIGHBOR_STR
2763 NEIGHBOR_ADDR_STR2
2764 "Specify a BGP neighbor\n"
2765 AS_STR
2766 "Internal BGP peer\n"
2767 "External BGP peer\n")
2768 {
2769 int idx_peer = 1;
2770 int idx_remote_as = 3;
2771 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2772 argv[idx_remote_as]->arg, AFI_IP,
2773 SAFI_UNICAST);
2774 }
2775
2776 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2777 afi_t afi, safi_t safi, int v6only,
2778 const char *peer_group_name,
2779 const char *as_str)
2780 {
2781 VTY_DECLVAR_CONTEXT(bgp, bgp);
2782 as_t as = 0;
2783 int as_type = AS_UNSPECIFIED;
2784 struct peer *peer;
2785 struct peer_group *group;
2786 int ret = 0;
2787 union sockunion su;
2788
2789 group = peer_group_lookup(bgp, conf_if);
2790
2791 if (group) {
2792 vty_out(vty, "%% Name conflict with peer-group \n");
2793 return CMD_WARNING_CONFIG_FAILED;
2794 }
2795
2796 if (as_str) {
2797 if (as_str[0] == 'i') {
2798 as_type = AS_INTERNAL;
2799 } else if (as_str[0] == 'e') {
2800 as_type = AS_EXTERNAL;
2801 } else {
2802 /* Get AS number. */
2803 as = strtoul(as_str, NULL, 10);
2804 as_type = AS_SPECIFIED;
2805 }
2806 }
2807
2808 peer = peer_lookup_by_conf_if(bgp, conf_if);
2809 if (peer) {
2810 if (as_str)
2811 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2812 afi, safi);
2813 } else {
2814 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2815 && afi == AFI_IP && safi == SAFI_UNICAST)
2816 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2817 as_type, 0, 0, NULL);
2818 else
2819 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2820 as_type, afi, safi, NULL);
2821
2822 if (!peer) {
2823 vty_out(vty, "%% BGP failed to create peer\n");
2824 return CMD_WARNING_CONFIG_FAILED;
2825 }
2826
2827 if (v6only)
2828 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2829
2830 /* Request zebra to initiate IPv6 RAs on this interface. We do
2831 * this
2832 * any unnumbered peer in order to not worry about run-time
2833 * transitions
2834 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2835 * address
2836 * gets deleted later etc.)
2837 */
2838 if (peer->ifp)
2839 bgp_zebra_initiate_radv(bgp, peer);
2840 }
2841
2842 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2843 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2844 if (v6only)
2845 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2846 else
2847 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2848
2849 /* v6only flag changed. Reset bgp seesion */
2850 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2851 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2852 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2853 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2854 } else
2855 bgp_session_reset(peer);
2856 }
2857
2858 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2859 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2860 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2861 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2862 }
2863
2864 if (peer_group_name) {
2865 group = peer_group_lookup(bgp, peer_group_name);
2866 if (!group) {
2867 vty_out(vty, "%% Configure the peer-group first\n");
2868 return CMD_WARNING_CONFIG_FAILED;
2869 }
2870
2871 ret = peer_group_bind(bgp, &su, peer, group, &as);
2872 }
2873
2874 return bgp_vty_return(vty, ret);
2875 }
2876
2877 DEFUN (neighbor_interface_config,
2878 neighbor_interface_config_cmd,
2879 "neighbor WORD interface [peer-group WORD]",
2880 NEIGHBOR_STR
2881 "Interface name or neighbor tag\n"
2882 "Enable BGP on interface\n"
2883 "Member of the peer-group\n"
2884 "Peer-group name\n")
2885 {
2886 int idx_word = 1;
2887 int idx_peer_group_word = 4;
2888
2889 if (argc > idx_peer_group_word)
2890 return peer_conf_interface_get(
2891 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2892 argv[idx_peer_group_word]->arg, NULL);
2893 else
2894 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2895 SAFI_UNICAST, 0, NULL, NULL);
2896 }
2897
2898 DEFUN (neighbor_interface_config_v6only,
2899 neighbor_interface_config_v6only_cmd,
2900 "neighbor WORD interface v6only [peer-group WORD]",
2901 NEIGHBOR_STR
2902 "Interface name or neighbor tag\n"
2903 "Enable BGP on interface\n"
2904 "Enable BGP with v6 link-local only\n"
2905 "Member of the peer-group\n"
2906 "Peer-group name\n")
2907 {
2908 int idx_word = 1;
2909 int idx_peer_group_word = 5;
2910
2911 if (argc > idx_peer_group_word)
2912 return peer_conf_interface_get(
2913 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2914 argv[idx_peer_group_word]->arg, NULL);
2915
2916 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2917 SAFI_UNICAST, 1, NULL, NULL);
2918 }
2919
2920
2921 DEFUN (neighbor_interface_config_remote_as,
2922 neighbor_interface_config_remote_as_cmd,
2923 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2924 NEIGHBOR_STR
2925 "Interface name or neighbor tag\n"
2926 "Enable BGP on interface\n"
2927 "Specify a BGP neighbor\n"
2928 AS_STR
2929 "Internal BGP peer\n"
2930 "External BGP peer\n")
2931 {
2932 int idx_word = 1;
2933 int idx_remote_as = 4;
2934 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2935 SAFI_UNICAST, 0, NULL,
2936 argv[idx_remote_as]->arg);
2937 }
2938
2939 DEFUN (neighbor_interface_v6only_config_remote_as,
2940 neighbor_interface_v6only_config_remote_as_cmd,
2941 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2942 NEIGHBOR_STR
2943 "Interface name or neighbor tag\n"
2944 "Enable BGP with v6 link-local only\n"
2945 "Enable BGP on interface\n"
2946 "Specify a BGP neighbor\n"
2947 AS_STR
2948 "Internal BGP peer\n"
2949 "External BGP peer\n")
2950 {
2951 int idx_word = 1;
2952 int idx_remote_as = 5;
2953 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2954 SAFI_UNICAST, 1, NULL,
2955 argv[idx_remote_as]->arg);
2956 }
2957
2958 DEFUN (neighbor_peer_group,
2959 neighbor_peer_group_cmd,
2960 "neighbor WORD peer-group",
2961 NEIGHBOR_STR
2962 "Interface name or neighbor tag\n"
2963 "Configure peer-group\n")
2964 {
2965 VTY_DECLVAR_CONTEXT(bgp, bgp);
2966 int idx_word = 1;
2967 struct peer *peer;
2968 struct peer_group *group;
2969
2970 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2971 if (peer) {
2972 vty_out(vty, "%% Name conflict with interface: \n");
2973 return CMD_WARNING_CONFIG_FAILED;
2974 }
2975
2976 group = peer_group_get(bgp, argv[idx_word]->arg);
2977 if (!group) {
2978 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2979 return CMD_WARNING_CONFIG_FAILED;
2980 }
2981
2982 return CMD_SUCCESS;
2983 }
2984
2985 DEFUN (no_neighbor,
2986 no_neighbor_cmd,
2987 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
2988 NO_STR
2989 NEIGHBOR_STR
2990 NEIGHBOR_ADDR_STR2
2991 "Specify a BGP neighbor\n"
2992 AS_STR
2993 "Internal BGP peer\n"
2994 "External BGP peer\n")
2995 {
2996 VTY_DECLVAR_CONTEXT(bgp, bgp);
2997 int idx_peer = 2;
2998 int ret;
2999 union sockunion su;
3000 struct peer_group *group;
3001 struct peer *peer;
3002 struct peer *other;
3003
3004 ret = str2sockunion(argv[idx_peer]->arg, &su);
3005 if (ret < 0) {
3006 /* look up for neighbor by interface name config. */
3007 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3008 if (peer) {
3009 /* Request zebra to terminate IPv6 RAs on this
3010 * interface. */
3011 if (peer->ifp)
3012 bgp_zebra_terminate_radv(peer->bgp, peer);
3013 peer_delete(peer);
3014 return CMD_SUCCESS;
3015 }
3016
3017 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3018 if (group)
3019 peer_group_delete(group);
3020 else {
3021 vty_out(vty, "%% Create the peer-group first\n");
3022 return CMD_WARNING_CONFIG_FAILED;
3023 }
3024 } else {
3025 peer = peer_lookup(bgp, &su);
3026 if (peer) {
3027 if (peer_dynamic_neighbor(peer)) {
3028 vty_out(vty,
3029 "%% Operation not allowed on a dynamic neighbor\n");
3030 return CMD_WARNING_CONFIG_FAILED;
3031 }
3032
3033 other = peer->doppelganger;
3034 peer_delete(peer);
3035 if (other && other->status != Deleted)
3036 peer_delete(other);
3037 }
3038 }
3039
3040 return CMD_SUCCESS;
3041 }
3042
3043 DEFUN (no_neighbor_interface_config,
3044 no_neighbor_interface_config_cmd,
3045 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3046 NO_STR
3047 NEIGHBOR_STR
3048 "Interface name\n"
3049 "Configure BGP on interface\n"
3050 "Enable BGP with v6 link-local only\n"
3051 "Member of the peer-group\n"
3052 "Peer-group name\n"
3053 "Specify a BGP neighbor\n"
3054 AS_STR
3055 "Internal BGP peer\n"
3056 "External BGP peer\n")
3057 {
3058 VTY_DECLVAR_CONTEXT(bgp, bgp);
3059 int idx_word = 2;
3060 struct peer *peer;
3061
3062 /* look up for neighbor by interface name config. */
3063 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3064 if (peer) {
3065 /* Request zebra to terminate IPv6 RAs on this interface. */
3066 if (peer->ifp)
3067 bgp_zebra_terminate_radv(peer->bgp, peer);
3068 peer_delete(peer);
3069 } else {
3070 vty_out(vty, "%% Create the bgp interface first\n");
3071 return CMD_WARNING_CONFIG_FAILED;
3072 }
3073 return CMD_SUCCESS;
3074 }
3075
3076 DEFUN (no_neighbor_peer_group,
3077 no_neighbor_peer_group_cmd,
3078 "no neighbor WORD peer-group",
3079 NO_STR
3080 NEIGHBOR_STR
3081 "Neighbor tag\n"
3082 "Configure peer-group\n")
3083 {
3084 VTY_DECLVAR_CONTEXT(bgp, bgp);
3085 int idx_word = 2;
3086 struct peer_group *group;
3087
3088 group = peer_group_lookup(bgp, argv[idx_word]->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 return CMD_SUCCESS;
3096 }
3097
3098 DEFUN (no_neighbor_interface_peer_group_remote_as,
3099 no_neighbor_interface_peer_group_remote_as_cmd,
3100 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3101 NO_STR
3102 NEIGHBOR_STR
3103 "Interface name or neighbor tag\n"
3104 "Specify a BGP neighbor\n"
3105 AS_STR
3106 "Internal BGP peer\n"
3107 "External BGP peer\n")
3108 {
3109 VTY_DECLVAR_CONTEXT(bgp, bgp);
3110 int idx_word = 2;
3111 struct peer_group *group;
3112 struct peer *peer;
3113
3114 /* look up for neighbor by interface name config. */
3115 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3116 if (peer) {
3117 peer_as_change(peer, 0, AS_SPECIFIED);
3118 return CMD_SUCCESS;
3119 }
3120
3121 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3122 if (group)
3123 peer_group_remote_as_delete(group);
3124 else {
3125 vty_out(vty, "%% Create the peer-group or interface first\n");
3126 return CMD_WARNING_CONFIG_FAILED;
3127 }
3128 return CMD_SUCCESS;
3129 }
3130
3131 DEFUN (neighbor_local_as,
3132 neighbor_local_as_cmd,
3133 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3134 NEIGHBOR_STR
3135 NEIGHBOR_ADDR_STR2
3136 "Specify a local-as number\n"
3137 "AS number used as local AS\n")
3138 {
3139 int idx_peer = 1;
3140 int idx_number = 3;
3141 struct peer *peer;
3142 int ret;
3143 as_t as;
3144
3145 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3146 if (!peer)
3147 return CMD_WARNING_CONFIG_FAILED;
3148
3149 as = strtoul(argv[idx_number]->arg, NULL, 10);
3150 ret = peer_local_as_set(peer, as, 0, 0);
3151 return bgp_vty_return(vty, ret);
3152 }
3153
3154 DEFUN (neighbor_local_as_no_prepend,
3155 neighbor_local_as_no_prepend_cmd,
3156 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3157 NEIGHBOR_STR
3158 NEIGHBOR_ADDR_STR2
3159 "Specify a local-as number\n"
3160 "AS number used as local AS\n"
3161 "Do not prepend local-as to updates from ebgp peers\n")
3162 {
3163 int idx_peer = 1;
3164 int idx_number = 3;
3165 struct peer *peer;
3166 int ret;
3167 as_t as;
3168
3169 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3170 if (!peer)
3171 return CMD_WARNING_CONFIG_FAILED;
3172
3173 as = strtoul(argv[idx_number]->arg, NULL, 10);
3174 ret = peer_local_as_set(peer, as, 1, 0);
3175 return bgp_vty_return(vty, ret);
3176 }
3177
3178 DEFUN (neighbor_local_as_no_prepend_replace_as,
3179 neighbor_local_as_no_prepend_replace_as_cmd,
3180 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3181 NEIGHBOR_STR
3182 NEIGHBOR_ADDR_STR2
3183 "Specify a local-as number\n"
3184 "AS number used as local AS\n"
3185 "Do not prepend local-as to updates from ebgp peers\n"
3186 "Do not prepend local-as to updates from ibgp peers\n")
3187 {
3188 int idx_peer = 1;
3189 int idx_number = 3;
3190 struct peer *peer;
3191 int ret;
3192 as_t as;
3193
3194 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3195 if (!peer)
3196 return CMD_WARNING_CONFIG_FAILED;
3197
3198 as = strtoul(argv[idx_number]->arg, NULL, 10);
3199 ret = peer_local_as_set(peer, as, 1, 1);
3200 return bgp_vty_return(vty, ret);
3201 }
3202
3203 DEFUN (no_neighbor_local_as,
3204 no_neighbor_local_as_cmd,
3205 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3206 NO_STR
3207 NEIGHBOR_STR
3208 NEIGHBOR_ADDR_STR2
3209 "Specify a local-as number\n"
3210 "AS number used as local AS\n"
3211 "Do not prepend local-as to updates from ebgp peers\n"
3212 "Do not prepend local-as to updates from ibgp peers\n")
3213 {
3214 int idx_peer = 2;
3215 struct peer *peer;
3216 int ret;
3217
3218 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3219 if (!peer)
3220 return CMD_WARNING_CONFIG_FAILED;
3221
3222 ret = peer_local_as_unset(peer);
3223 return bgp_vty_return(vty, ret);
3224 }
3225
3226
3227 DEFUN (neighbor_solo,
3228 neighbor_solo_cmd,
3229 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3230 NEIGHBOR_STR
3231 NEIGHBOR_ADDR_STR2
3232 "Solo peer - part of its own update group\n")
3233 {
3234 int idx_peer = 1;
3235 struct peer *peer;
3236 int ret;
3237
3238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3239 if (!peer)
3240 return CMD_WARNING_CONFIG_FAILED;
3241
3242 ret = update_group_adjust_soloness(peer, 1);
3243 return bgp_vty_return(vty, ret);
3244 }
3245
3246 DEFUN (no_neighbor_solo,
3247 no_neighbor_solo_cmd,
3248 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3249 NO_STR
3250 NEIGHBOR_STR
3251 NEIGHBOR_ADDR_STR2
3252 "Solo peer - part of its own update group\n")
3253 {
3254 int idx_peer = 2;
3255 struct peer *peer;
3256 int ret;
3257
3258 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3259 if (!peer)
3260 return CMD_WARNING_CONFIG_FAILED;
3261
3262 ret = update_group_adjust_soloness(peer, 0);
3263 return bgp_vty_return(vty, ret);
3264 }
3265
3266 DEFUN (neighbor_password,
3267 neighbor_password_cmd,
3268 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3269 NEIGHBOR_STR
3270 NEIGHBOR_ADDR_STR2
3271 "Set a password\n"
3272 "The password\n")
3273 {
3274 int idx_peer = 1;
3275 int idx_line = 3;
3276 struct peer *peer;
3277 int ret;
3278
3279 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3280 if (!peer)
3281 return CMD_WARNING_CONFIG_FAILED;
3282
3283 ret = peer_password_set(peer, argv[idx_line]->arg);
3284 return bgp_vty_return(vty, ret);
3285 }
3286
3287 DEFUN (no_neighbor_password,
3288 no_neighbor_password_cmd,
3289 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3290 NO_STR
3291 NEIGHBOR_STR
3292 NEIGHBOR_ADDR_STR2
3293 "Set a password\n"
3294 "The password\n")
3295 {
3296 int idx_peer = 2;
3297 struct peer *peer;
3298 int ret;
3299
3300 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3301 if (!peer)
3302 return CMD_WARNING_CONFIG_FAILED;
3303
3304 ret = peer_password_unset(peer);
3305 return bgp_vty_return(vty, ret);
3306 }
3307
3308 DEFUN (neighbor_activate,
3309 neighbor_activate_cmd,
3310 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3311 NEIGHBOR_STR
3312 NEIGHBOR_ADDR_STR2
3313 "Enable the Address Family for this Neighbor\n")
3314 {
3315 int idx_peer = 1;
3316 int ret;
3317 struct peer *peer;
3318
3319 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3320 if (!peer)
3321 return CMD_WARNING_CONFIG_FAILED;
3322
3323 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3324 return bgp_vty_return(vty, ret);
3325 }
3326
3327 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3328 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3329 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3330 "Enable the Address Family for this Neighbor\n")
3331
3332 DEFUN (no_neighbor_activate,
3333 no_neighbor_activate_cmd,
3334 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3335 NO_STR
3336 NEIGHBOR_STR
3337 NEIGHBOR_ADDR_STR2
3338 "Enable the Address Family for this Neighbor\n")
3339 {
3340 int idx_peer = 2;
3341 int ret;
3342 struct peer *peer;
3343
3344 /* Lookup peer. */
3345 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3346 if (!peer)
3347 return CMD_WARNING_CONFIG_FAILED;
3348
3349 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3350 return bgp_vty_return(vty, ret);
3351 }
3352
3353 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3354 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3355 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3356 "Enable the Address Family for this Neighbor\n")
3357
3358 DEFUN (neighbor_set_peer_group,
3359 neighbor_set_peer_group_cmd,
3360 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3361 NEIGHBOR_STR
3362 NEIGHBOR_ADDR_STR2
3363 "Member of the peer-group\n"
3364 "Peer-group name\n")
3365 {
3366 VTY_DECLVAR_CONTEXT(bgp, bgp);
3367 int idx_peer = 1;
3368 int idx_word = 3;
3369 int ret;
3370 as_t as;
3371 union sockunion su;
3372 struct peer *peer;
3373 struct peer_group *group;
3374
3375 peer = NULL;
3376
3377 ret = str2sockunion(argv[idx_peer]->arg, &su);
3378 if (ret < 0) {
3379 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3380 if (!peer) {
3381 vty_out(vty, "%% Malformed address or name: %s\n",
3382 argv[idx_peer]->arg);
3383 return CMD_WARNING_CONFIG_FAILED;
3384 }
3385 } else {
3386 if (peer_address_self_check(bgp, &su)) {
3387 vty_out(vty,
3388 "%% Can not configure the local system as neighbor\n");
3389 return CMD_WARNING_CONFIG_FAILED;
3390 }
3391
3392 /* Disallow for dynamic neighbor. */
3393 peer = peer_lookup(bgp, &su);
3394 if (peer && peer_dynamic_neighbor(peer)) {
3395 vty_out(vty,
3396 "%% Operation not allowed on a dynamic neighbor\n");
3397 return CMD_WARNING_CONFIG_FAILED;
3398 }
3399 }
3400
3401 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3402 if (!group) {
3403 vty_out(vty, "%% Configure the peer-group first\n");
3404 return CMD_WARNING_CONFIG_FAILED;
3405 }
3406
3407 ret = peer_group_bind(bgp, &su, peer, group, &as);
3408
3409 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3410 vty_out(vty,
3411 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3412 as);
3413 return CMD_WARNING_CONFIG_FAILED;
3414 }
3415
3416 return bgp_vty_return(vty, ret);
3417 }
3418
3419 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3420 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3421 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3422 "Member of the peer-group\n"
3423 "Peer-group name\n")
3424
3425 DEFUN (no_neighbor_set_peer_group,
3426 no_neighbor_set_peer_group_cmd,
3427 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3428 NO_STR
3429 NEIGHBOR_STR
3430 NEIGHBOR_ADDR_STR2
3431 "Member of the peer-group\n"
3432 "Peer-group name\n")
3433 {
3434 VTY_DECLVAR_CONTEXT(bgp, bgp);
3435 int idx_peer = 2;
3436 int idx_word = 4;
3437 int ret;
3438 struct peer *peer;
3439 struct peer_group *group;
3440
3441 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3442 if (!peer)
3443 return CMD_WARNING_CONFIG_FAILED;
3444
3445 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3446 if (!group) {
3447 vty_out(vty, "%% Configure the peer-group first\n");
3448 return CMD_WARNING_CONFIG_FAILED;
3449 }
3450
3451 ret = peer_delete(peer);
3452
3453 return bgp_vty_return(vty, ret);
3454 }
3455
3456 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3457 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3458 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3459 "Member of the peer-group\n"
3460 "Peer-group name\n")
3461
3462 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3463 uint32_t flag, int set)
3464 {
3465 int ret;
3466 struct peer *peer;
3467
3468 peer = peer_and_group_lookup_vty(vty, ip_str);
3469 if (!peer)
3470 return CMD_WARNING_CONFIG_FAILED;
3471
3472 /*
3473 * If 'neighbor <interface>', then this is for directly connected peers,
3474 * we should not accept disable-connected-check.
3475 */
3476 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3477 vty_out(vty,
3478 "%s is directly connected peer, cannot accept disable-"
3479 "connected-check\n",
3480 ip_str);
3481 return CMD_WARNING_CONFIG_FAILED;
3482 }
3483
3484 if (!set && flag == PEER_FLAG_SHUTDOWN)
3485 peer_tx_shutdown_message_unset(peer);
3486
3487 if (set)
3488 ret = peer_flag_set(peer, flag);
3489 else
3490 ret = peer_flag_unset(peer, flag);
3491
3492 return bgp_vty_return(vty, ret);
3493 }
3494
3495 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3496 {
3497 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3498 }
3499
3500 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3501 uint32_t flag)
3502 {
3503 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3504 }
3505
3506 /* neighbor passive. */
3507 DEFUN (neighbor_passive,
3508 neighbor_passive_cmd,
3509 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3510 NEIGHBOR_STR
3511 NEIGHBOR_ADDR_STR2
3512 "Don't send open messages to this neighbor\n")
3513 {
3514 int idx_peer = 1;
3515 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3516 }
3517
3518 DEFUN (no_neighbor_passive,
3519 no_neighbor_passive_cmd,
3520 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3521 NO_STR
3522 NEIGHBOR_STR
3523 NEIGHBOR_ADDR_STR2
3524 "Don't send open messages to this neighbor\n")
3525 {
3526 int idx_peer = 2;
3527 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3528 }
3529
3530 /* neighbor shutdown. */
3531 DEFUN (neighbor_shutdown_msg,
3532 neighbor_shutdown_msg_cmd,
3533 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3534 NEIGHBOR_STR
3535 NEIGHBOR_ADDR_STR2
3536 "Administratively shut down this neighbor\n"
3537 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3538 "Shutdown message\n")
3539 {
3540 int idx_peer = 1;
3541
3542 if (argc >= 5) {
3543 struct peer *peer =
3544 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3545 char *message;
3546
3547 if (!peer)
3548 return CMD_WARNING_CONFIG_FAILED;
3549 message = argv_concat(argv, argc, 4);
3550 peer_tx_shutdown_message_set(peer, message);
3551 XFREE(MTYPE_TMP, message);
3552 }
3553
3554 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3555 }
3556
3557 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3558 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3559 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3560 "Administratively shut down this neighbor\n")
3561
3562 DEFUN (no_neighbor_shutdown_msg,
3563 no_neighbor_shutdown_msg_cmd,
3564 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3565 NO_STR
3566 NEIGHBOR_STR
3567 NEIGHBOR_ADDR_STR2
3568 "Administratively shut down this neighbor\n"
3569 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3570 "Shutdown message\n")
3571 {
3572 int idx_peer = 2;
3573
3574 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3575 PEER_FLAG_SHUTDOWN);
3576 }
3577
3578 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3579 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3580 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3581 "Administratively shut down this neighbor\n")
3582
3583 /* neighbor capability dynamic. */
3584 DEFUN (neighbor_capability_dynamic,
3585 neighbor_capability_dynamic_cmd,
3586 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3587 NEIGHBOR_STR
3588 NEIGHBOR_ADDR_STR2
3589 "Advertise capability to the peer\n"
3590 "Advertise dynamic capability to this neighbor\n")
3591 {
3592 int idx_peer = 1;
3593 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3594 PEER_FLAG_DYNAMIC_CAPABILITY);
3595 }
3596
3597 DEFUN (no_neighbor_capability_dynamic,
3598 no_neighbor_capability_dynamic_cmd,
3599 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3600 NO_STR
3601 NEIGHBOR_STR
3602 NEIGHBOR_ADDR_STR2
3603 "Advertise capability to the peer\n"
3604 "Advertise dynamic capability to this neighbor\n")
3605 {
3606 int idx_peer = 2;
3607 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3608 PEER_FLAG_DYNAMIC_CAPABILITY);
3609 }
3610
3611 /* neighbor dont-capability-negotiate */
3612 DEFUN (neighbor_dont_capability_negotiate,
3613 neighbor_dont_capability_negotiate_cmd,
3614 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3615 NEIGHBOR_STR
3616 NEIGHBOR_ADDR_STR2
3617 "Do not perform capability negotiation\n")
3618 {
3619 int idx_peer = 1;
3620 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3621 PEER_FLAG_DONT_CAPABILITY);
3622 }
3623
3624 DEFUN (no_neighbor_dont_capability_negotiate,
3625 no_neighbor_dont_capability_negotiate_cmd,
3626 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3627 NO_STR
3628 NEIGHBOR_STR
3629 NEIGHBOR_ADDR_STR2
3630 "Do not perform capability negotiation\n")
3631 {
3632 int idx_peer = 2;
3633 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3634 PEER_FLAG_DONT_CAPABILITY);
3635 }
3636
3637 /* neighbor capability extended next hop encoding */
3638 DEFUN (neighbor_capability_enhe,
3639 neighbor_capability_enhe_cmd,
3640 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3641 NEIGHBOR_STR
3642 NEIGHBOR_ADDR_STR2
3643 "Advertise capability to the peer\n"
3644 "Advertise extended next-hop capability to the peer\n")
3645 {
3646 int idx_peer = 1;
3647 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3648 PEER_FLAG_CAPABILITY_ENHE);
3649 }
3650
3651 DEFUN (no_neighbor_capability_enhe,
3652 no_neighbor_capability_enhe_cmd,
3653 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3654 NO_STR
3655 NEIGHBOR_STR
3656 NEIGHBOR_ADDR_STR2
3657 "Advertise capability to the peer\n"
3658 "Advertise extended next-hop capability to the peer\n")
3659 {
3660 int idx_peer = 2;
3661 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3662 PEER_FLAG_CAPABILITY_ENHE);
3663 }
3664
3665 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3666 afi_t afi, safi_t safi, uint32_t flag,
3667 int set)
3668 {
3669 int ret;
3670 struct peer *peer;
3671
3672 peer = peer_and_group_lookup_vty(vty, peer_str);
3673 if (!peer)
3674 return CMD_WARNING_CONFIG_FAILED;
3675
3676 if (set)
3677 ret = peer_af_flag_set(peer, afi, safi, flag);
3678 else
3679 ret = peer_af_flag_unset(peer, afi, safi, flag);
3680
3681 return bgp_vty_return(vty, ret);
3682 }
3683
3684 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3685 afi_t afi, safi_t safi, uint32_t flag)
3686 {
3687 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3688 }
3689
3690 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3691 afi_t afi, safi_t safi, uint32_t flag)
3692 {
3693 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3694 }
3695
3696 /* neighbor capability orf prefix-list. */
3697 DEFUN (neighbor_capability_orf_prefix,
3698 neighbor_capability_orf_prefix_cmd,
3699 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3700 NEIGHBOR_STR
3701 NEIGHBOR_ADDR_STR2
3702 "Advertise capability to the peer\n"
3703 "Advertise ORF capability to the peer\n"
3704 "Advertise prefixlist ORF capability to this neighbor\n"
3705 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3706 "Capability to RECEIVE the ORF from this neighbor\n"
3707 "Capability to SEND the ORF to this neighbor\n")
3708 {
3709 int idx_peer = 1;
3710 int idx_send_recv = 5;
3711 uint16_t flag = 0;
3712
3713 if (strmatch(argv[idx_send_recv]->text, "send"))
3714 flag = PEER_FLAG_ORF_PREFIX_SM;
3715 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3716 flag = PEER_FLAG_ORF_PREFIX_RM;
3717 else if (strmatch(argv[idx_send_recv]->text, "both"))
3718 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3719 else {
3720 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3721 return CMD_WARNING_CONFIG_FAILED;
3722 }
3723
3724 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3725 bgp_node_safi(vty), flag);
3726 }
3727
3728 ALIAS_HIDDEN(
3729 neighbor_capability_orf_prefix,
3730 neighbor_capability_orf_prefix_hidden_cmd,
3731 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3732 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3733 "Advertise capability to the peer\n"
3734 "Advertise ORF capability to the peer\n"
3735 "Advertise prefixlist ORF capability to this neighbor\n"
3736 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3737 "Capability to RECEIVE the ORF from this neighbor\n"
3738 "Capability to SEND the ORF to this neighbor\n")
3739
3740 DEFUN (no_neighbor_capability_orf_prefix,
3741 no_neighbor_capability_orf_prefix_cmd,
3742 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3743 NO_STR
3744 NEIGHBOR_STR
3745 NEIGHBOR_ADDR_STR2
3746 "Advertise capability to the peer\n"
3747 "Advertise ORF capability to the peer\n"
3748 "Advertise prefixlist ORF capability to this neighbor\n"
3749 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3750 "Capability to RECEIVE the ORF from this neighbor\n"
3751 "Capability to SEND the ORF to this neighbor\n")
3752 {
3753 int idx_peer = 2;
3754 int idx_send_recv = 6;
3755 uint16_t flag = 0;
3756
3757 if (strmatch(argv[idx_send_recv]->text, "send"))
3758 flag = PEER_FLAG_ORF_PREFIX_SM;
3759 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3760 flag = PEER_FLAG_ORF_PREFIX_RM;
3761 else if (strmatch(argv[idx_send_recv]->text, "both"))
3762 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3763 else {
3764 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3765 return CMD_WARNING_CONFIG_FAILED;
3766 }
3767
3768 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3769 bgp_node_afi(vty), bgp_node_safi(vty),
3770 flag);
3771 }
3772
3773 ALIAS_HIDDEN(
3774 no_neighbor_capability_orf_prefix,
3775 no_neighbor_capability_orf_prefix_hidden_cmd,
3776 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3777 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3778 "Advertise capability to the peer\n"
3779 "Advertise ORF capability to the peer\n"
3780 "Advertise prefixlist ORF capability to this neighbor\n"
3781 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3782 "Capability to RECEIVE the ORF from this neighbor\n"
3783 "Capability to SEND the ORF to this neighbor\n")
3784
3785 /* neighbor next-hop-self. */
3786 DEFUN (neighbor_nexthop_self,
3787 neighbor_nexthop_self_cmd,
3788 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3789 NEIGHBOR_STR
3790 NEIGHBOR_ADDR_STR2
3791 "Disable the next hop calculation for this neighbor\n")
3792 {
3793 int idx_peer = 1;
3794 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3795 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3796 }
3797
3798 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3799 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3800 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3801 "Disable the next hop calculation for this neighbor\n")
3802
3803 /* neighbor next-hop-self. */
3804 DEFUN (neighbor_nexthop_self_force,
3805 neighbor_nexthop_self_force_cmd,
3806 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3807 NEIGHBOR_STR
3808 NEIGHBOR_ADDR_STR2
3809 "Disable the next hop calculation for this neighbor\n"
3810 "Set the next hop to self for reflected routes\n")
3811 {
3812 int idx_peer = 1;
3813 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3814 bgp_node_safi(vty),
3815 PEER_FLAG_FORCE_NEXTHOP_SELF);
3816 }
3817
3818 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3819 neighbor_nexthop_self_force_hidden_cmd,
3820 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3821 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3822 "Disable the next hop calculation for this neighbor\n"
3823 "Set the next hop to self for reflected routes\n")
3824
3825 DEFUN (no_neighbor_nexthop_self,
3826 no_neighbor_nexthop_self_cmd,
3827 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3828 NO_STR
3829 NEIGHBOR_STR
3830 NEIGHBOR_ADDR_STR2
3831 "Disable the next hop calculation for this neighbor\n")
3832 {
3833 int idx_peer = 2;
3834 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3835 bgp_node_afi(vty), bgp_node_safi(vty),
3836 PEER_FLAG_NEXTHOP_SELF);
3837 }
3838
3839 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3840 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3841 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3842 "Disable the next hop calculation for this neighbor\n")
3843
3844 DEFUN (no_neighbor_nexthop_self_force,
3845 no_neighbor_nexthop_self_force_cmd,
3846 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3847 NO_STR
3848 NEIGHBOR_STR
3849 NEIGHBOR_ADDR_STR2
3850 "Disable the next hop calculation for this neighbor\n"
3851 "Set the next hop to self for reflected routes\n")
3852 {
3853 int idx_peer = 2;
3854 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3855 bgp_node_afi(vty), bgp_node_safi(vty),
3856 PEER_FLAG_FORCE_NEXTHOP_SELF);
3857 }
3858
3859 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3860 no_neighbor_nexthop_self_force_hidden_cmd,
3861 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3862 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3863 "Disable the next hop calculation for this neighbor\n"
3864 "Set the next hop to self for reflected routes\n")
3865
3866 /* neighbor as-override */
3867 DEFUN (neighbor_as_override,
3868 neighbor_as_override_cmd,
3869 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3870 NEIGHBOR_STR
3871 NEIGHBOR_ADDR_STR2
3872 "Override ASNs in outbound updates if aspath equals remote-as\n")
3873 {
3874 int idx_peer = 1;
3875 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3876 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3877 }
3878
3879 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3880 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3881 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3882 "Override ASNs in outbound updates if aspath equals remote-as\n")
3883
3884 DEFUN (no_neighbor_as_override,
3885 no_neighbor_as_override_cmd,
3886 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3887 NO_STR
3888 NEIGHBOR_STR
3889 NEIGHBOR_ADDR_STR2
3890 "Override ASNs in outbound updates if aspath equals remote-as\n")
3891 {
3892 int idx_peer = 2;
3893 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3894 bgp_node_afi(vty), bgp_node_safi(vty),
3895 PEER_FLAG_AS_OVERRIDE);
3896 }
3897
3898 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3899 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3900 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3901 "Override ASNs in outbound updates if aspath equals remote-as\n")
3902
3903 /* neighbor remove-private-AS. */
3904 DEFUN (neighbor_remove_private_as,
3905 neighbor_remove_private_as_cmd,
3906 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3907 NEIGHBOR_STR
3908 NEIGHBOR_ADDR_STR2
3909 "Remove private ASNs in outbound updates\n")
3910 {
3911 int idx_peer = 1;
3912 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3913 bgp_node_safi(vty),
3914 PEER_FLAG_REMOVE_PRIVATE_AS);
3915 }
3916
3917 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3918 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3920 "Remove private ASNs in outbound updates\n")
3921
3922 DEFUN (neighbor_remove_private_as_all,
3923 neighbor_remove_private_as_all_cmd,
3924 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3925 NEIGHBOR_STR
3926 NEIGHBOR_ADDR_STR2
3927 "Remove private ASNs in outbound updates\n"
3928 "Apply to all AS numbers\n")
3929 {
3930 int idx_peer = 1;
3931 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3932 bgp_node_safi(vty),
3933 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3934 }
3935
3936 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3937 neighbor_remove_private_as_all_hidden_cmd,
3938 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3939 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3940 "Remove private ASNs in outbound updates\n"
3941 "Apply to all AS numbers")
3942
3943 DEFUN (neighbor_remove_private_as_replace_as,
3944 neighbor_remove_private_as_replace_as_cmd,
3945 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3946 NEIGHBOR_STR
3947 NEIGHBOR_ADDR_STR2
3948 "Remove private ASNs in outbound updates\n"
3949 "Replace private ASNs with our ASN in outbound updates\n")
3950 {
3951 int idx_peer = 1;
3952 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3953 bgp_node_safi(vty),
3954 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3955 }
3956
3957 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3958 neighbor_remove_private_as_replace_as_hidden_cmd,
3959 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3960 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3961 "Remove private ASNs in outbound updates\n"
3962 "Replace private ASNs with our ASN in outbound updates\n")
3963
3964 DEFUN (neighbor_remove_private_as_all_replace_as,
3965 neighbor_remove_private_as_all_replace_as_cmd,
3966 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3967 NEIGHBOR_STR
3968 NEIGHBOR_ADDR_STR2
3969 "Remove private ASNs in outbound updates\n"
3970 "Apply to all AS numbers\n"
3971 "Replace private ASNs with our ASN in outbound updates\n")
3972 {
3973 int idx_peer = 1;
3974 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3975 bgp_node_safi(vty),
3976 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3977 }
3978
3979 ALIAS_HIDDEN(
3980 neighbor_remove_private_as_all_replace_as,
3981 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3982 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3983 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3984 "Remove private ASNs in outbound updates\n"
3985 "Apply to all AS numbers\n"
3986 "Replace private ASNs with our ASN in outbound updates\n")
3987
3988 DEFUN (no_neighbor_remove_private_as,
3989 no_neighbor_remove_private_as_cmd,
3990 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3991 NO_STR
3992 NEIGHBOR_STR
3993 NEIGHBOR_ADDR_STR2
3994 "Remove private ASNs in outbound updates\n")
3995 {
3996 int idx_peer = 2;
3997 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3998 bgp_node_afi(vty), bgp_node_safi(vty),
3999 PEER_FLAG_REMOVE_PRIVATE_AS);
4000 }
4001
4002 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4003 no_neighbor_remove_private_as_hidden_cmd,
4004 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4005 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4006 "Remove private ASNs in outbound updates\n")
4007
4008 DEFUN (no_neighbor_remove_private_as_all,
4009 no_neighbor_remove_private_as_all_cmd,
4010 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4011 NO_STR
4012 NEIGHBOR_STR
4013 NEIGHBOR_ADDR_STR2
4014 "Remove private ASNs in outbound updates\n"
4015 "Apply to all AS numbers\n")
4016 {
4017 int idx_peer = 2;
4018 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4019 bgp_node_afi(vty), bgp_node_safi(vty),
4020 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4021 }
4022
4023 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4024 no_neighbor_remove_private_as_all_hidden_cmd,
4025 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4026 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4027 "Remove private ASNs in outbound updates\n"
4028 "Apply to all AS numbers\n")
4029
4030 DEFUN (no_neighbor_remove_private_as_replace_as,
4031 no_neighbor_remove_private_as_replace_as_cmd,
4032 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4033 NO_STR
4034 NEIGHBOR_STR
4035 NEIGHBOR_ADDR_STR2
4036 "Remove private ASNs in outbound updates\n"
4037 "Replace private ASNs with our ASN in outbound updates\n")
4038 {
4039 int idx_peer = 2;
4040 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4041 bgp_node_afi(vty), bgp_node_safi(vty),
4042 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4043 }
4044
4045 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4046 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4047 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4048 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4049 "Remove private ASNs in outbound updates\n"
4050 "Replace private ASNs with our ASN in outbound updates\n")
4051
4052 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4053 no_neighbor_remove_private_as_all_replace_as_cmd,
4054 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4055 NO_STR
4056 NEIGHBOR_STR
4057 NEIGHBOR_ADDR_STR2
4058 "Remove private ASNs in outbound updates\n"
4059 "Apply to all AS numbers\n"
4060 "Replace private ASNs with our ASN in outbound updates\n")
4061 {
4062 int idx_peer = 2;
4063 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4064 bgp_node_afi(vty), bgp_node_safi(vty),
4065 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4066 }
4067
4068 ALIAS_HIDDEN(
4069 no_neighbor_remove_private_as_all_replace_as,
4070 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4071 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4072 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4073 "Remove private ASNs in outbound updates\n"
4074 "Apply to all AS numbers\n"
4075 "Replace private ASNs with our ASN in outbound updates\n")
4076
4077
4078 /* neighbor send-community. */
4079 DEFUN (neighbor_send_community,
4080 neighbor_send_community_cmd,
4081 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4082 NEIGHBOR_STR
4083 NEIGHBOR_ADDR_STR2
4084 "Send Community attribute to this neighbor\n")
4085 {
4086 int idx_peer = 1;
4087
4088 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4089 bgp_node_safi(vty),
4090 PEER_FLAG_SEND_COMMUNITY);
4091 }
4092
4093 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4094 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4096 "Send Community attribute to this neighbor\n")
4097
4098 DEFUN (no_neighbor_send_community,
4099 no_neighbor_send_community_cmd,
4100 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4101 NO_STR
4102 NEIGHBOR_STR
4103 NEIGHBOR_ADDR_STR2
4104 "Send Community attribute to this neighbor\n")
4105 {
4106 int idx_peer = 2;
4107
4108 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4109 bgp_node_afi(vty), bgp_node_safi(vty),
4110 PEER_FLAG_SEND_COMMUNITY);
4111 }
4112
4113 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4114 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4115 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4116 "Send Community attribute to this neighbor\n")
4117
4118 /* neighbor send-community extended. */
4119 DEFUN (neighbor_send_community_type,
4120 neighbor_send_community_type_cmd,
4121 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4122 NEIGHBOR_STR
4123 NEIGHBOR_ADDR_STR2
4124 "Send Community attribute to this neighbor\n"
4125 "Send Standard and Extended Community attributes\n"
4126 "Send Standard, Large and Extended Community attributes\n"
4127 "Send Extended Community attributes\n"
4128 "Send Standard Community attributes\n"
4129 "Send Large Community attributes\n")
4130 {
4131 int idx_peer = 1;
4132 uint32_t flag = 0;
4133 const char *type = argv[argc - 1]->text;
4134
4135 if (strmatch(type, "standard")) {
4136 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4137 } else if (strmatch(type, "extended")) {
4138 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4139 } else if (strmatch(type, "large")) {
4140 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4141 } else if (strmatch(type, "both")) {
4142 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4143 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4144 } else { /* if (strmatch(type, "all")) */
4145 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4146 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4147 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4148 }
4149
4150 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4151 bgp_node_safi(vty), flag);
4152 }
4153
4154 ALIAS_HIDDEN(
4155 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4156 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4157 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4158 "Send Community attribute to this neighbor\n"
4159 "Send Standard and Extended Community attributes\n"
4160 "Send Standard, Large and Extended Community attributes\n"
4161 "Send Extended Community attributes\n"
4162 "Send Standard Community attributes\n"
4163 "Send Large Community attributes\n")
4164
4165 DEFUN (no_neighbor_send_community_type,
4166 no_neighbor_send_community_type_cmd,
4167 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4168 NO_STR
4169 NEIGHBOR_STR
4170 NEIGHBOR_ADDR_STR2
4171 "Send Community attribute to this neighbor\n"
4172 "Send Standard and Extended Community attributes\n"
4173 "Send Standard, Large and Extended Community attributes\n"
4174 "Send Extended Community attributes\n"
4175 "Send Standard Community attributes\n"
4176 "Send Large Community attributes\n")
4177 {
4178 int idx_peer = 2;
4179 uint32_t flag = 0;
4180 const char *type = argv[argc - 1]->text;
4181
4182 if (strmatch(type, "standard")) {
4183 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4184 } else if (strmatch(type, "extended")) {
4185 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4186 } else if (strmatch(type, "large")) {
4187 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4188 } else if (strmatch(type, "both")) {
4189 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4190 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4191 } else { /* if (strmatch(type, "all")) */
4192 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4193 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4194 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4195 }
4196
4197 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4198 bgp_node_afi(vty), bgp_node_safi(vty),
4199 flag);
4200 }
4201
4202 ALIAS_HIDDEN(
4203 no_neighbor_send_community_type,
4204 no_neighbor_send_community_type_hidden_cmd,
4205 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4206 NO_STR NEIGHBOR_STR 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 /* neighbor soft-reconfig. */
4215 DEFUN (neighbor_soft_reconfiguration,
4216 neighbor_soft_reconfiguration_cmd,
4217 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4218 NEIGHBOR_STR
4219 NEIGHBOR_ADDR_STR2
4220 "Per neighbor soft reconfiguration\n"
4221 "Allow inbound soft reconfiguration for this neighbor\n")
4222 {
4223 int idx_peer = 1;
4224 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4225 bgp_node_safi(vty),
4226 PEER_FLAG_SOFT_RECONFIG);
4227 }
4228
4229 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4230 neighbor_soft_reconfiguration_hidden_cmd,
4231 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4232 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4233 "Per neighbor soft reconfiguration\n"
4234 "Allow inbound soft reconfiguration for this neighbor\n")
4235
4236 DEFUN (no_neighbor_soft_reconfiguration,
4237 no_neighbor_soft_reconfiguration_cmd,
4238 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4239 NO_STR
4240 NEIGHBOR_STR
4241 NEIGHBOR_ADDR_STR2
4242 "Per neighbor soft reconfiguration\n"
4243 "Allow inbound soft reconfiguration for this neighbor\n")
4244 {
4245 int idx_peer = 2;
4246 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4247 bgp_node_afi(vty), bgp_node_safi(vty),
4248 PEER_FLAG_SOFT_RECONFIG);
4249 }
4250
4251 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4252 no_neighbor_soft_reconfiguration_hidden_cmd,
4253 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4254 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4255 "Per neighbor soft reconfiguration\n"
4256 "Allow inbound soft reconfiguration for this neighbor\n")
4257
4258 DEFUN (neighbor_route_reflector_client,
4259 neighbor_route_reflector_client_cmd,
4260 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4261 NEIGHBOR_STR
4262 NEIGHBOR_ADDR_STR2
4263 "Configure a neighbor as Route Reflector client\n")
4264 {
4265 int idx_peer = 1;
4266 struct peer *peer;
4267
4268
4269 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4270 if (!peer)
4271 return CMD_WARNING_CONFIG_FAILED;
4272
4273 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4274 bgp_node_safi(vty),
4275 PEER_FLAG_REFLECTOR_CLIENT);
4276 }
4277
4278 ALIAS_HIDDEN(neighbor_route_reflector_client,
4279 neighbor_route_reflector_client_hidden_cmd,
4280 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4281 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4282 "Configure a neighbor as Route Reflector client\n")
4283
4284 DEFUN (no_neighbor_route_reflector_client,
4285 no_neighbor_route_reflector_client_cmd,
4286 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4287 NO_STR
4288 NEIGHBOR_STR
4289 NEIGHBOR_ADDR_STR2
4290 "Configure a neighbor as Route Reflector client\n")
4291 {
4292 int idx_peer = 2;
4293 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4294 bgp_node_afi(vty), bgp_node_safi(vty),
4295 PEER_FLAG_REFLECTOR_CLIENT);
4296 }
4297
4298 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4299 no_neighbor_route_reflector_client_hidden_cmd,
4300 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4301 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4302 "Configure a neighbor as Route Reflector client\n")
4303
4304 /* neighbor route-server-client. */
4305 DEFUN (neighbor_route_server_client,
4306 neighbor_route_server_client_cmd,
4307 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4308 NEIGHBOR_STR
4309 NEIGHBOR_ADDR_STR2
4310 "Configure a neighbor as Route Server client\n")
4311 {
4312 int idx_peer = 1;
4313 struct peer *peer;
4314
4315 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4316 if (!peer)
4317 return CMD_WARNING_CONFIG_FAILED;
4318 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4319 bgp_node_safi(vty),
4320 PEER_FLAG_RSERVER_CLIENT);
4321 }
4322
4323 ALIAS_HIDDEN(neighbor_route_server_client,
4324 neighbor_route_server_client_hidden_cmd,
4325 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4326 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4327 "Configure a neighbor as Route Server client\n")
4328
4329 DEFUN (no_neighbor_route_server_client,
4330 no_neighbor_route_server_client_cmd,
4331 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4332 NO_STR
4333 NEIGHBOR_STR
4334 NEIGHBOR_ADDR_STR2
4335 "Configure a neighbor as Route Server client\n")
4336 {
4337 int idx_peer = 2;
4338 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4339 bgp_node_afi(vty), bgp_node_safi(vty),
4340 PEER_FLAG_RSERVER_CLIENT);
4341 }
4342
4343 ALIAS_HIDDEN(no_neighbor_route_server_client,
4344 no_neighbor_route_server_client_hidden_cmd,
4345 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4346 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4347 "Configure a neighbor as Route Server client\n")
4348
4349 DEFUN (neighbor_nexthop_local_unchanged,
4350 neighbor_nexthop_local_unchanged_cmd,
4351 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4352 NEIGHBOR_STR
4353 NEIGHBOR_ADDR_STR2
4354 "Configure treatment of outgoing link-local nexthop attribute\n"
4355 "Leave link-local nexthop unchanged for this peer\n")
4356 {
4357 int idx_peer = 1;
4358 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4359 bgp_node_safi(vty),
4360 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4361 }
4362
4363 DEFUN (no_neighbor_nexthop_local_unchanged,
4364 no_neighbor_nexthop_local_unchanged_cmd,
4365 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4366 NO_STR
4367 NEIGHBOR_STR
4368 NEIGHBOR_ADDR_STR2
4369 "Configure treatment of outgoing link-local-nexthop attribute\n"
4370 "Leave link-local nexthop unchanged for this peer\n")
4371 {
4372 int idx_peer = 2;
4373 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4374 bgp_node_afi(vty), bgp_node_safi(vty),
4375 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4376 }
4377
4378 DEFUN (neighbor_attr_unchanged,
4379 neighbor_attr_unchanged_cmd,
4380 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4381 NEIGHBOR_STR
4382 NEIGHBOR_ADDR_STR2
4383 "BGP attribute is propagated unchanged to this neighbor\n"
4384 "As-path attribute\n"
4385 "Nexthop attribute\n"
4386 "Med attribute\n")
4387 {
4388 int idx = 0;
4389 char *peer_str = argv[1]->arg;
4390 struct peer *peer;
4391 uint16_t flags = 0;
4392 afi_t afi = bgp_node_afi(vty);
4393 safi_t safi = bgp_node_safi(vty);
4394
4395 peer = peer_and_group_lookup_vty(vty, peer_str);
4396 if (!peer)
4397 return CMD_WARNING_CONFIG_FAILED;
4398
4399 if (argv_find(argv, argc, "as-path", &idx))
4400 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4401 idx = 0;
4402 if (argv_find(argv, argc, "next-hop", &idx))
4403 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4404 idx = 0;
4405 if (argv_find(argv, argc, "med", &idx))
4406 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4407
4408 /* no flags means all of them! */
4409 if (!flags) {
4410 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4411 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4412 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4413 } else {
4414 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4415 && peer_af_flag_check(peer, afi, safi,
4416 PEER_FLAG_AS_PATH_UNCHANGED)) {
4417 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4418 PEER_FLAG_AS_PATH_UNCHANGED);
4419 }
4420
4421 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4422 && peer_af_flag_check(peer, afi, safi,
4423 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4424 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4425 PEER_FLAG_NEXTHOP_UNCHANGED);
4426 }
4427
4428 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4429 && peer_af_flag_check(peer, afi, safi,
4430 PEER_FLAG_MED_UNCHANGED)) {
4431 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4432 PEER_FLAG_MED_UNCHANGED);
4433 }
4434 }
4435
4436 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4437 }
4438
4439 ALIAS_HIDDEN(
4440 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4441 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4443 "BGP attribute is propagated unchanged to this neighbor\n"
4444 "As-path attribute\n"
4445 "Nexthop attribute\n"
4446 "Med attribute\n")
4447
4448 DEFUN (no_neighbor_attr_unchanged,
4449 no_neighbor_attr_unchanged_cmd,
4450 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4451 NO_STR
4452 NEIGHBOR_STR
4453 NEIGHBOR_ADDR_STR2
4454 "BGP attribute is propagated unchanged to this neighbor\n"
4455 "As-path attribute\n"
4456 "Nexthop attribute\n"
4457 "Med attribute\n")
4458 {
4459 int idx = 0;
4460 char *peer = argv[2]->arg;
4461 uint16_t flags = 0;
4462
4463 if (argv_find(argv, argc, "as-path", &idx))
4464 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4465 idx = 0;
4466 if (argv_find(argv, argc, "next-hop", &idx))
4467 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4468 idx = 0;
4469 if (argv_find(argv, argc, "med", &idx))
4470 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4471
4472 if (!flags) // no flags means all of them!
4473 {
4474 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4475 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4476 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4477 }
4478
4479 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4480 bgp_node_safi(vty), flags);
4481 }
4482
4483 ALIAS_HIDDEN(
4484 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4485 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4486 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4487 "BGP attribute is propagated unchanged to this neighbor\n"
4488 "As-path attribute\n"
4489 "Nexthop attribute\n"
4490 "Med attribute\n")
4491
4492 /* EBGP multihop configuration. */
4493 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4494 const char *ttl_str)
4495 {
4496 struct peer *peer;
4497 unsigned int ttl;
4498
4499 peer = peer_and_group_lookup_vty(vty, ip_str);
4500 if (!peer)
4501 return CMD_WARNING_CONFIG_FAILED;
4502
4503 if (peer->conf_if)
4504 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4505
4506 if (!ttl_str)
4507 ttl = MAXTTL;
4508 else
4509 ttl = strtoul(ttl_str, NULL, 10);
4510
4511 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4512 }
4513
4514 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4515 {
4516 struct peer *peer;
4517
4518 peer = peer_and_group_lookup_vty(vty, ip_str);
4519 if (!peer)
4520 return CMD_WARNING_CONFIG_FAILED;
4521
4522 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4523 }
4524
4525 /* neighbor ebgp-multihop. */
4526 DEFUN (neighbor_ebgp_multihop,
4527 neighbor_ebgp_multihop_cmd,
4528 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4529 NEIGHBOR_STR
4530 NEIGHBOR_ADDR_STR2
4531 "Allow EBGP neighbors not on directly connected networks\n")
4532 {
4533 int idx_peer = 1;
4534 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4535 }
4536
4537 DEFUN (neighbor_ebgp_multihop_ttl,
4538 neighbor_ebgp_multihop_ttl_cmd,
4539 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4540 NEIGHBOR_STR
4541 NEIGHBOR_ADDR_STR2
4542 "Allow EBGP neighbors not on directly connected networks\n"
4543 "maximum hop count\n")
4544 {
4545 int idx_peer = 1;
4546 int idx_number = 3;
4547 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4548 argv[idx_number]->arg);
4549 }
4550
4551 DEFUN (no_neighbor_ebgp_multihop,
4552 no_neighbor_ebgp_multihop_cmd,
4553 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4554 NO_STR
4555 NEIGHBOR_STR
4556 NEIGHBOR_ADDR_STR2
4557 "Allow EBGP neighbors not on directly connected networks\n"
4558 "maximum hop count\n")
4559 {
4560 int idx_peer = 2;
4561 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4562 }
4563
4564
4565 /* disable-connected-check */
4566 DEFUN (neighbor_disable_connected_check,
4567 neighbor_disable_connected_check_cmd,
4568 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4569 NEIGHBOR_STR
4570 NEIGHBOR_ADDR_STR2
4571 "one-hop away EBGP peer using loopback address\n"
4572 "Enforce EBGP neighbors perform multihop\n")
4573 {
4574 int idx_peer = 1;
4575 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4576 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4577 }
4578
4579 DEFUN (no_neighbor_disable_connected_check,
4580 no_neighbor_disable_connected_check_cmd,
4581 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4582 NO_STR
4583 NEIGHBOR_STR
4584 NEIGHBOR_ADDR_STR2
4585 "one-hop away EBGP peer using loopback address\n"
4586 "Enforce EBGP neighbors perform multihop\n")
4587 {
4588 int idx_peer = 2;
4589 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4590 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4591 }
4592
4593
4594 /* enforce-first-as */
4595 DEFUN (neighbor_enforce_first_as,
4596 neighbor_enforce_first_as_cmd,
4597 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4598 NEIGHBOR_STR
4599 NEIGHBOR_ADDR_STR2
4600 "Enforce the first AS for EBGP routes\n")
4601 {
4602 int idx_peer = 1;
4603
4604 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4605 PEER_FLAG_ENFORCE_FIRST_AS);
4606 }
4607
4608 DEFUN (no_neighbor_enforce_first_as,
4609 no_neighbor_enforce_first_as_cmd,
4610 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4611 NO_STR
4612 NEIGHBOR_STR
4613 NEIGHBOR_ADDR_STR2
4614 "Enforce the first AS for EBGP routes\n")
4615 {
4616 int idx_peer = 2;
4617
4618 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4619 PEER_FLAG_ENFORCE_FIRST_AS);
4620 }
4621
4622
4623 DEFUN (neighbor_description,
4624 neighbor_description_cmd,
4625 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4626 NEIGHBOR_STR
4627 NEIGHBOR_ADDR_STR2
4628 "Neighbor specific description\n"
4629 "Up to 80 characters describing this neighbor\n")
4630 {
4631 int idx_peer = 1;
4632 int idx_line = 3;
4633 struct peer *peer;
4634 char *str;
4635
4636 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4637 if (!peer)
4638 return CMD_WARNING_CONFIG_FAILED;
4639
4640 str = argv_concat(argv, argc, idx_line);
4641
4642 peer_description_set(peer, str);
4643
4644 XFREE(MTYPE_TMP, str);
4645
4646 return CMD_SUCCESS;
4647 }
4648
4649 DEFUN (no_neighbor_description,
4650 no_neighbor_description_cmd,
4651 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4652 NO_STR
4653 NEIGHBOR_STR
4654 NEIGHBOR_ADDR_STR2
4655 "Neighbor specific description\n")
4656 {
4657 int idx_peer = 2;
4658 struct peer *peer;
4659
4660 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4661 if (!peer)
4662 return CMD_WARNING_CONFIG_FAILED;
4663
4664 peer_description_unset(peer);
4665
4666 return CMD_SUCCESS;
4667 }
4668
4669 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4670 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4672 "Neighbor specific description\n"
4673 "Up to 80 characters describing this neighbor\n")
4674
4675 /* Neighbor update-source. */
4676 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4677 const char *source_str)
4678 {
4679 struct peer *peer;
4680 struct prefix p;
4681 union sockunion su;
4682
4683 peer = peer_and_group_lookup_vty(vty, peer_str);
4684 if (!peer)
4685 return CMD_WARNING_CONFIG_FAILED;
4686
4687 if (peer->conf_if)
4688 return CMD_WARNING;
4689
4690 if (source_str) {
4691 if (str2sockunion(source_str, &su) == 0)
4692 peer_update_source_addr_set(peer, &su);
4693 else {
4694 if (str2prefix(source_str, &p)) {
4695 vty_out(vty,
4696 "%% Invalid update-source, remove prefix length \n");
4697 return CMD_WARNING_CONFIG_FAILED;
4698 } else
4699 peer_update_source_if_set(peer, source_str);
4700 }
4701 } else
4702 peer_update_source_unset(peer);
4703
4704 return CMD_SUCCESS;
4705 }
4706
4707 #define BGP_UPDATE_SOURCE_HELP_STR \
4708 "IPv4 address\n" \
4709 "IPv6 address\n" \
4710 "Interface name (requires zebra to be running)\n"
4711
4712 DEFUN (neighbor_update_source,
4713 neighbor_update_source_cmd,
4714 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4715 NEIGHBOR_STR
4716 NEIGHBOR_ADDR_STR2
4717 "Source of routing updates\n"
4718 BGP_UPDATE_SOURCE_HELP_STR)
4719 {
4720 int idx_peer = 1;
4721 int idx_peer_2 = 3;
4722 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4723 argv[idx_peer_2]->arg);
4724 }
4725
4726 DEFUN (no_neighbor_update_source,
4727 no_neighbor_update_source_cmd,
4728 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4729 NO_STR
4730 NEIGHBOR_STR
4731 NEIGHBOR_ADDR_STR2
4732 "Source of routing updates\n"
4733 BGP_UPDATE_SOURCE_HELP_STR)
4734 {
4735 int idx_peer = 2;
4736 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4737 }
4738
4739 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4740 afi_t afi, safi_t safi,
4741 const char *rmap, int set)
4742 {
4743 int ret;
4744 struct peer *peer;
4745
4746 peer = peer_and_group_lookup_vty(vty, peer_str);
4747 if (!peer)
4748 return CMD_WARNING_CONFIG_FAILED;
4749
4750 if (set)
4751 ret = peer_default_originate_set(peer, afi, safi, rmap);
4752 else
4753 ret = peer_default_originate_unset(peer, afi, safi);
4754
4755 return bgp_vty_return(vty, ret);
4756 }
4757
4758 /* neighbor default-originate. */
4759 DEFUN (neighbor_default_originate,
4760 neighbor_default_originate_cmd,
4761 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4762 NEIGHBOR_STR
4763 NEIGHBOR_ADDR_STR2
4764 "Originate default route to this neighbor\n")
4765 {
4766 int idx_peer = 1;
4767 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4768 bgp_node_afi(vty),
4769 bgp_node_safi(vty), NULL, 1);
4770 }
4771
4772 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4773 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4774 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4775 "Originate default route to this neighbor\n")
4776
4777 DEFUN (neighbor_default_originate_rmap,
4778 neighbor_default_originate_rmap_cmd,
4779 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4780 NEIGHBOR_STR
4781 NEIGHBOR_ADDR_STR2
4782 "Originate default route to this neighbor\n"
4783 "Route-map to specify criteria to originate default\n"
4784 "route-map name\n")
4785 {
4786 int idx_peer = 1;
4787 int idx_word = 4;
4788 return peer_default_originate_set_vty(
4789 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4790 argv[idx_word]->arg, 1);
4791 }
4792
4793 ALIAS_HIDDEN(
4794 neighbor_default_originate_rmap,
4795 neighbor_default_originate_rmap_hidden_cmd,
4796 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4797 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4798 "Originate default route to this neighbor\n"
4799 "Route-map to specify criteria to originate default\n"
4800 "route-map name\n")
4801
4802 DEFUN (no_neighbor_default_originate,
4803 no_neighbor_default_originate_cmd,
4804 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4805 NO_STR
4806 NEIGHBOR_STR
4807 NEIGHBOR_ADDR_STR2
4808 "Originate default route to this neighbor\n"
4809 "Route-map to specify criteria to originate default\n"
4810 "route-map name\n")
4811 {
4812 int idx_peer = 2;
4813 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4814 bgp_node_afi(vty),
4815 bgp_node_safi(vty), NULL, 0);
4816 }
4817
4818 ALIAS_HIDDEN(
4819 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4820 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4821 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4822 "Originate default route to this neighbor\n"
4823 "Route-map to specify criteria to originate default\n"
4824 "route-map name\n")
4825
4826
4827 /* Set neighbor's BGP port. */
4828 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4829 const char *port_str)
4830 {
4831 struct peer *peer;
4832 uint16_t port;
4833 struct servent *sp;
4834
4835 peer = peer_lookup_vty(vty, ip_str);
4836 if (!peer)
4837 return CMD_WARNING_CONFIG_FAILED;
4838
4839 if (!port_str) {
4840 sp = getservbyname("bgp", "tcp");
4841 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4842 } else {
4843 port = strtoul(port_str, NULL, 10);
4844 }
4845
4846 peer_port_set(peer, port);
4847
4848 return CMD_SUCCESS;
4849 }
4850
4851 /* Set specified peer's BGP port. */
4852 DEFUN (neighbor_port,
4853 neighbor_port_cmd,
4854 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4855 NEIGHBOR_STR
4856 NEIGHBOR_ADDR_STR
4857 "Neighbor's BGP port\n"
4858 "TCP port number\n")
4859 {
4860 int idx_ip = 1;
4861 int idx_number = 3;
4862 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4863 argv[idx_number]->arg);
4864 }
4865
4866 DEFUN (no_neighbor_port,
4867 no_neighbor_port_cmd,
4868 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4869 NO_STR
4870 NEIGHBOR_STR
4871 NEIGHBOR_ADDR_STR
4872 "Neighbor's BGP port\n"
4873 "TCP port number\n")
4874 {
4875 int idx_ip = 2;
4876 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4877 }
4878
4879
4880 /* neighbor weight. */
4881 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4882 safi_t safi, const char *weight_str)
4883 {
4884 int ret;
4885 struct peer *peer;
4886 unsigned long weight;
4887
4888 peer = peer_and_group_lookup_vty(vty, ip_str);
4889 if (!peer)
4890 return CMD_WARNING_CONFIG_FAILED;
4891
4892 weight = strtoul(weight_str, NULL, 10);
4893
4894 ret = peer_weight_set(peer, afi, safi, weight);
4895 return bgp_vty_return(vty, ret);
4896 }
4897
4898 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4899 safi_t safi)
4900 {
4901 int ret;
4902 struct peer *peer;
4903
4904 peer = peer_and_group_lookup_vty(vty, ip_str);
4905 if (!peer)
4906 return CMD_WARNING_CONFIG_FAILED;
4907
4908 ret = peer_weight_unset(peer, afi, safi);
4909 return bgp_vty_return(vty, ret);
4910 }
4911
4912 DEFUN (neighbor_weight,
4913 neighbor_weight_cmd,
4914 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4915 NEIGHBOR_STR
4916 NEIGHBOR_ADDR_STR2
4917 "Set default weight for routes from this neighbor\n"
4918 "default weight\n")
4919 {
4920 int idx_peer = 1;
4921 int idx_number = 3;
4922 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4923 bgp_node_safi(vty), argv[idx_number]->arg);
4924 }
4925
4926 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4927 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4928 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4929 "Set default weight for routes from this neighbor\n"
4930 "default weight\n")
4931
4932 DEFUN (no_neighbor_weight,
4933 no_neighbor_weight_cmd,
4934 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4935 NO_STR
4936 NEIGHBOR_STR
4937 NEIGHBOR_ADDR_STR2
4938 "Set default weight for routes from this neighbor\n"
4939 "default weight\n")
4940 {
4941 int idx_peer = 2;
4942 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4943 bgp_node_afi(vty), bgp_node_safi(vty));
4944 }
4945
4946 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4947 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4948 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4949 "Set default weight for routes from this neighbor\n"
4950 "default weight\n")
4951
4952
4953 /* Override capability negotiation. */
4954 DEFUN (neighbor_override_capability,
4955 neighbor_override_capability_cmd,
4956 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4957 NEIGHBOR_STR
4958 NEIGHBOR_ADDR_STR2
4959 "Override capability negotiation result\n")
4960 {
4961 int idx_peer = 1;
4962 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4963 PEER_FLAG_OVERRIDE_CAPABILITY);
4964 }
4965
4966 DEFUN (no_neighbor_override_capability,
4967 no_neighbor_override_capability_cmd,
4968 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4969 NO_STR
4970 NEIGHBOR_STR
4971 NEIGHBOR_ADDR_STR2
4972 "Override capability negotiation result\n")
4973 {
4974 int idx_peer = 2;
4975 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4976 PEER_FLAG_OVERRIDE_CAPABILITY);
4977 }
4978
4979 DEFUN (neighbor_strict_capability,
4980 neighbor_strict_capability_cmd,
4981 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
4982 NEIGHBOR_STR
4983 NEIGHBOR_ADDR_STR2
4984 "Strict capability negotiation match\n")
4985 {
4986 int idx_peer = 1;
4987
4988 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4989 PEER_FLAG_STRICT_CAP_MATCH);
4990 }
4991
4992 DEFUN (no_neighbor_strict_capability,
4993 no_neighbor_strict_capability_cmd,
4994 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
4995 NO_STR
4996 NEIGHBOR_STR
4997 NEIGHBOR_ADDR_STR2
4998 "Strict capability negotiation match\n")
4999 {
5000 int idx_peer = 2;
5001
5002 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5003 PEER_FLAG_STRICT_CAP_MATCH);
5004 }
5005
5006 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5007 const char *keep_str, const char *hold_str)
5008 {
5009 int ret;
5010 struct peer *peer;
5011 uint32_t keepalive;
5012 uint32_t holdtime;
5013
5014 peer = peer_and_group_lookup_vty(vty, ip_str);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
5017
5018 keepalive = strtoul(keep_str, NULL, 10);
5019 holdtime = strtoul(hold_str, NULL, 10);
5020
5021 ret = peer_timers_set(peer, keepalive, holdtime);
5022
5023 return bgp_vty_return(vty, ret);
5024 }
5025
5026 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5027 {
5028 int ret;
5029 struct peer *peer;
5030
5031 peer = peer_and_group_lookup_vty(vty, ip_str);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
5034
5035 ret = peer_timers_unset(peer);
5036
5037 return bgp_vty_return(vty, ret);
5038 }
5039
5040 DEFUN (neighbor_timers,
5041 neighbor_timers_cmd,
5042 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "BGP per neighbor timers\n"
5046 "Keepalive interval\n"
5047 "Holdtime\n")
5048 {
5049 int idx_peer = 1;
5050 int idx_number = 3;
5051 int idx_number_2 = 4;
5052 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5053 argv[idx_number]->arg,
5054 argv[idx_number_2]->arg);
5055 }
5056
5057 DEFUN (no_neighbor_timers,
5058 no_neighbor_timers_cmd,
5059 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5060 NO_STR
5061 NEIGHBOR_STR
5062 NEIGHBOR_ADDR_STR2
5063 "BGP per neighbor timers\n"
5064 "Keepalive interval\n"
5065 "Holdtime\n")
5066 {
5067 int idx_peer = 2;
5068 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5069 }
5070
5071
5072 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5073 const char *time_str)
5074 {
5075 int ret;
5076 struct peer *peer;
5077 uint32_t connect;
5078
5079 peer = peer_and_group_lookup_vty(vty, ip_str);
5080 if (!peer)
5081 return CMD_WARNING_CONFIG_FAILED;
5082
5083 connect = strtoul(time_str, NULL, 10);
5084
5085 ret = peer_timers_connect_set(peer, connect);
5086
5087 return bgp_vty_return(vty, ret);
5088 }
5089
5090 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5091 {
5092 int ret;
5093 struct peer *peer;
5094
5095 peer = peer_and_group_lookup_vty(vty, ip_str);
5096 if (!peer)
5097 return CMD_WARNING_CONFIG_FAILED;
5098
5099 ret = peer_timers_connect_unset(peer);
5100
5101 return bgp_vty_return(vty, ret);
5102 }
5103
5104 DEFUN (neighbor_timers_connect,
5105 neighbor_timers_connect_cmd,
5106 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5107 NEIGHBOR_STR
5108 NEIGHBOR_ADDR_STR2
5109 "BGP per neighbor timers\n"
5110 "BGP connect timer\n"
5111 "Connect timer\n")
5112 {
5113 int idx_peer = 1;
5114 int idx_number = 4;
5115 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5116 argv[idx_number]->arg);
5117 }
5118
5119 DEFUN (no_neighbor_timers_connect,
5120 no_neighbor_timers_connect_cmd,
5121 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5122 NO_STR
5123 NEIGHBOR_STR
5124 NEIGHBOR_ADDR_STR2
5125 "BGP per neighbor timers\n"
5126 "BGP connect timer\n"
5127 "Connect timer\n")
5128 {
5129 int idx_peer = 2;
5130 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5131 }
5132
5133
5134 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5135 const char *time_str, int set)
5136 {
5137 int ret;
5138 struct peer *peer;
5139 uint32_t routeadv = 0;
5140
5141 peer = peer_and_group_lookup_vty(vty, ip_str);
5142 if (!peer)
5143 return CMD_WARNING_CONFIG_FAILED;
5144
5145 if (time_str)
5146 routeadv = strtoul(time_str, NULL, 10);
5147
5148 if (set)
5149 ret = peer_advertise_interval_set(peer, routeadv);
5150 else
5151 ret = peer_advertise_interval_unset(peer);
5152
5153 return bgp_vty_return(vty, ret);
5154 }
5155
5156 DEFUN (neighbor_advertise_interval,
5157 neighbor_advertise_interval_cmd,
5158 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5159 NEIGHBOR_STR
5160 NEIGHBOR_ADDR_STR2
5161 "Minimum interval between sending BGP routing updates\n"
5162 "time in seconds\n")
5163 {
5164 int idx_peer = 1;
5165 int idx_number = 3;
5166 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5167 argv[idx_number]->arg, 1);
5168 }
5169
5170 DEFUN (no_neighbor_advertise_interval,
5171 no_neighbor_advertise_interval_cmd,
5172 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5173 NO_STR
5174 NEIGHBOR_STR
5175 NEIGHBOR_ADDR_STR2
5176 "Minimum interval between sending BGP routing updates\n"
5177 "time in seconds\n")
5178 {
5179 int idx_peer = 2;
5180 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5181 }
5182
5183
5184 /* Time to wait before processing route-map updates */
5185 DEFUN (bgp_set_route_map_delay_timer,
5186 bgp_set_route_map_delay_timer_cmd,
5187 "bgp route-map delay-timer (0-600)",
5188 SET_STR
5189 "BGP route-map delay timer\n"
5190 "Time in secs to wait before processing route-map changes\n"
5191 "0 disables the timer, no route updates happen when route-maps change\n")
5192 {
5193 int idx_number = 3;
5194 uint32_t rmap_delay_timer;
5195
5196 if (argv[idx_number]->arg) {
5197 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5198 bm->rmap_update_timer = rmap_delay_timer;
5199
5200 /* if the dynamic update handling is being disabled, and a timer
5201 * is
5202 * running, stop the timer and act as if the timer has already
5203 * fired.
5204 */
5205 if (!rmap_delay_timer && bm->t_rmap_update) {
5206 BGP_TIMER_OFF(bm->t_rmap_update);
5207 thread_execute(bm->master, bgp_route_map_update_timer,
5208 NULL, 0);
5209 }
5210 return CMD_SUCCESS;
5211 } else {
5212 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5213 return CMD_WARNING_CONFIG_FAILED;
5214 }
5215 }
5216
5217 DEFUN (no_bgp_set_route_map_delay_timer,
5218 no_bgp_set_route_map_delay_timer_cmd,
5219 "no bgp route-map delay-timer [(0-600)]",
5220 NO_STR
5221 BGP_STR
5222 "Default BGP route-map delay timer\n"
5223 "Reset to default time to wait for processing route-map changes\n"
5224 "0 disables the timer, no route updates happen when route-maps change\n")
5225 {
5226
5227 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5228
5229 return CMD_SUCCESS;
5230 }
5231
5232
5233 /* neighbor interface */
5234 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5235 const char *str)
5236 {
5237 struct peer *peer;
5238
5239 peer = peer_lookup_vty(vty, ip_str);
5240 if (!peer || peer->conf_if) {
5241 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5242 return CMD_WARNING_CONFIG_FAILED;
5243 }
5244
5245 if (str)
5246 peer_interface_set(peer, str);
5247 else
5248 peer_interface_unset(peer);
5249
5250 return CMD_SUCCESS;
5251 }
5252
5253 DEFUN (neighbor_interface,
5254 neighbor_interface_cmd,
5255 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5256 NEIGHBOR_STR
5257 NEIGHBOR_ADDR_STR
5258 "Interface\n"
5259 "Interface name\n")
5260 {
5261 int idx_ip = 1;
5262 int idx_word = 3;
5263 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5264 }
5265
5266 DEFUN (no_neighbor_interface,
5267 no_neighbor_interface_cmd,
5268 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5269 NO_STR
5270 NEIGHBOR_STR
5271 NEIGHBOR_ADDR_STR2
5272 "Interface\n"
5273 "Interface name\n")
5274 {
5275 int idx_peer = 2;
5276 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5277 }
5278
5279 DEFUN (neighbor_distribute_list,
5280 neighbor_distribute_list_cmd,
5281 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5282 NEIGHBOR_STR
5283 NEIGHBOR_ADDR_STR2
5284 "Filter updates to/from this neighbor\n"
5285 "IP access-list number\n"
5286 "IP access-list number (expanded range)\n"
5287 "IP Access-list name\n"
5288 "Filter incoming updates\n"
5289 "Filter outgoing updates\n")
5290 {
5291 int idx_peer = 1;
5292 int idx_acl = 3;
5293 int direct, ret;
5294 struct peer *peer;
5295
5296 const char *pstr = argv[idx_peer]->arg;
5297 const char *acl = argv[idx_acl]->arg;
5298 const char *inout = argv[argc - 1]->text;
5299
5300 peer = peer_and_group_lookup_vty(vty, pstr);
5301 if (!peer)
5302 return CMD_WARNING_CONFIG_FAILED;
5303
5304 /* Check filter direction. */
5305 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5306 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5307 direct, acl);
5308
5309 return bgp_vty_return(vty, ret);
5310 }
5311
5312 ALIAS_HIDDEN(
5313 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5314 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5315 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5316 "Filter updates to/from this neighbor\n"
5317 "IP access-list number\n"
5318 "IP access-list number (expanded range)\n"
5319 "IP Access-list name\n"
5320 "Filter incoming updates\n"
5321 "Filter outgoing updates\n")
5322
5323 DEFUN (no_neighbor_distribute_list,
5324 no_neighbor_distribute_list_cmd,
5325 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5326 NO_STR
5327 NEIGHBOR_STR
5328 NEIGHBOR_ADDR_STR2
5329 "Filter updates to/from this neighbor\n"
5330 "IP access-list number\n"
5331 "IP access-list number (expanded range)\n"
5332 "IP Access-list name\n"
5333 "Filter incoming updates\n"
5334 "Filter outgoing updates\n")
5335 {
5336 int idx_peer = 2;
5337 int direct, ret;
5338 struct peer *peer;
5339
5340 const char *pstr = argv[idx_peer]->arg;
5341 const char *inout = argv[argc - 1]->text;
5342
5343 peer = peer_and_group_lookup_vty(vty, pstr);
5344 if (!peer)
5345 return CMD_WARNING_CONFIG_FAILED;
5346
5347 /* Check filter direction. */
5348 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5349 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5350 direct);
5351
5352 return bgp_vty_return(vty, ret);
5353 }
5354
5355 ALIAS_HIDDEN(
5356 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5357 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5358 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5359 "Filter updates to/from this neighbor\n"
5360 "IP access-list number\n"
5361 "IP access-list number (expanded range)\n"
5362 "IP Access-list name\n"
5363 "Filter incoming updates\n"
5364 "Filter outgoing updates\n")
5365
5366 /* Set prefix list to the peer. */
5367 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5368 afi_t afi, safi_t safi,
5369 const char *name_str,
5370 const char *direct_str)
5371 {
5372 int ret;
5373 int direct = FILTER_IN;
5374 struct peer *peer;
5375
5376 peer = peer_and_group_lookup_vty(vty, ip_str);
5377 if (!peer)
5378 return CMD_WARNING_CONFIG_FAILED;
5379
5380 /* Check filter direction. */
5381 if (strncmp(direct_str, "i", 1) == 0)
5382 direct = FILTER_IN;
5383 else if (strncmp(direct_str, "o", 1) == 0)
5384 direct = FILTER_OUT;
5385
5386 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5387
5388 return bgp_vty_return(vty, ret);
5389 }
5390
5391 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5392 afi_t afi, safi_t safi,
5393 const char *direct_str)
5394 {
5395 int ret;
5396 struct peer *peer;
5397 int direct = FILTER_IN;
5398
5399 peer = peer_and_group_lookup_vty(vty, ip_str);
5400 if (!peer)
5401 return CMD_WARNING_CONFIG_FAILED;
5402
5403 /* Check filter direction. */
5404 if (strncmp(direct_str, "i", 1) == 0)
5405 direct = FILTER_IN;
5406 else if (strncmp(direct_str, "o", 1) == 0)
5407 direct = FILTER_OUT;
5408
5409 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5410
5411 return bgp_vty_return(vty, ret);
5412 }
5413
5414 DEFUN (neighbor_prefix_list,
5415 neighbor_prefix_list_cmd,
5416 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5417 NEIGHBOR_STR
5418 NEIGHBOR_ADDR_STR2
5419 "Filter updates to/from this neighbor\n"
5420 "Name of a prefix list\n"
5421 "Filter incoming updates\n"
5422 "Filter outgoing updates\n")
5423 {
5424 int idx_peer = 1;
5425 int idx_word = 3;
5426 int idx_in_out = 4;
5427 return peer_prefix_list_set_vty(
5428 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5429 argv[idx_word]->arg, argv[idx_in_out]->arg);
5430 }
5431
5432 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5433 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5434 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5435 "Filter updates to/from this neighbor\n"
5436 "Name of a prefix list\n"
5437 "Filter incoming updates\n"
5438 "Filter outgoing updates\n")
5439
5440 DEFUN (no_neighbor_prefix_list,
5441 no_neighbor_prefix_list_cmd,
5442 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5443 NO_STR
5444 NEIGHBOR_STR
5445 NEIGHBOR_ADDR_STR2
5446 "Filter updates to/from this neighbor\n"
5447 "Name of a prefix list\n"
5448 "Filter incoming updates\n"
5449 "Filter outgoing updates\n")
5450 {
5451 int idx_peer = 2;
5452 int idx_in_out = 5;
5453 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5454 bgp_node_afi(vty), bgp_node_safi(vty),
5455 argv[idx_in_out]->arg);
5456 }
5457
5458 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5459 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5460 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5461 "Filter updates to/from this neighbor\n"
5462 "Name of a prefix list\n"
5463 "Filter incoming updates\n"
5464 "Filter outgoing updates\n")
5465
5466 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5467 safi_t safi, const char *name_str,
5468 const char *direct_str)
5469 {
5470 int ret;
5471 struct peer *peer;
5472 int direct = FILTER_IN;
5473
5474 peer = peer_and_group_lookup_vty(vty, ip_str);
5475 if (!peer)
5476 return CMD_WARNING_CONFIG_FAILED;
5477
5478 /* Check filter direction. */
5479 if (strncmp(direct_str, "i", 1) == 0)
5480 direct = FILTER_IN;
5481 else if (strncmp(direct_str, "o", 1) == 0)
5482 direct = FILTER_OUT;
5483
5484 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5485
5486 return bgp_vty_return(vty, ret);
5487 }
5488
5489 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5490 safi_t safi, const char *direct_str)
5491 {
5492 int ret;
5493 struct peer *peer;
5494 int direct = FILTER_IN;
5495
5496 peer = peer_and_group_lookup_vty(vty, ip_str);
5497 if (!peer)
5498 return CMD_WARNING_CONFIG_FAILED;
5499
5500 /* Check filter direction. */
5501 if (strncmp(direct_str, "i", 1) == 0)
5502 direct = FILTER_IN;
5503 else if (strncmp(direct_str, "o", 1) == 0)
5504 direct = FILTER_OUT;
5505
5506 ret = peer_aslist_unset(peer, afi, safi, direct);
5507
5508 return bgp_vty_return(vty, ret);
5509 }
5510
5511 DEFUN (neighbor_filter_list,
5512 neighbor_filter_list_cmd,
5513 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5514 NEIGHBOR_STR
5515 NEIGHBOR_ADDR_STR2
5516 "Establish BGP filters\n"
5517 "AS path access-list name\n"
5518 "Filter incoming routes\n"
5519 "Filter outgoing routes\n")
5520 {
5521 int idx_peer = 1;
5522 int idx_word = 3;
5523 int idx_in_out = 4;
5524 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5525 bgp_node_safi(vty), argv[idx_word]->arg,
5526 argv[idx_in_out]->arg);
5527 }
5528
5529 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5530 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5531 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5532 "Establish BGP filters\n"
5533 "AS path access-list name\n"
5534 "Filter incoming routes\n"
5535 "Filter outgoing routes\n")
5536
5537 DEFUN (no_neighbor_filter_list,
5538 no_neighbor_filter_list_cmd,
5539 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5540 NO_STR
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR2
5543 "Establish BGP filters\n"
5544 "AS path access-list name\n"
5545 "Filter incoming routes\n"
5546 "Filter outgoing routes\n")
5547 {
5548 int idx_peer = 2;
5549 int idx_in_out = 5;
5550 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5551 bgp_node_afi(vty), bgp_node_safi(vty),
5552 argv[idx_in_out]->arg);
5553 }
5554
5555 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5557 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5558 "Establish BGP filters\n"
5559 "AS path access-list name\n"
5560 "Filter incoming routes\n"
5561 "Filter outgoing routes\n")
5562
5563 /* Set route-map to the peer. */
5564 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5565 afi_t afi, safi_t safi, const char *name_str,
5566 const char *direct_str)
5567 {
5568 int ret;
5569 struct peer *peer;
5570 int direct = RMAP_IN;
5571
5572 peer = peer_and_group_lookup_vty(vty, ip_str);
5573 if (!peer)
5574 return CMD_WARNING_CONFIG_FAILED;
5575
5576 /* Check filter direction. */
5577 if (strncmp(direct_str, "in", 2) == 0)
5578 direct = RMAP_IN;
5579 else if (strncmp(direct_str, "o", 1) == 0)
5580 direct = RMAP_OUT;
5581
5582 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5583
5584 return bgp_vty_return(vty, ret);
5585 }
5586
5587 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5588 afi_t afi, safi_t safi,
5589 const char *direct_str)
5590 {
5591 int ret;
5592 struct peer *peer;
5593 int direct = RMAP_IN;
5594
5595 peer = peer_and_group_lookup_vty(vty, ip_str);
5596 if (!peer)
5597 return CMD_WARNING_CONFIG_FAILED;
5598
5599 /* Check filter direction. */
5600 if (strncmp(direct_str, "in", 2) == 0)
5601 direct = RMAP_IN;
5602 else if (strncmp(direct_str, "o", 1) == 0)
5603 direct = RMAP_OUT;
5604
5605 ret = peer_route_map_unset(peer, afi, safi, direct);
5606
5607 return bgp_vty_return(vty, ret);
5608 }
5609
5610 DEFUN (neighbor_route_map,
5611 neighbor_route_map_cmd,
5612 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5613 NEIGHBOR_STR
5614 NEIGHBOR_ADDR_STR2
5615 "Apply route map to neighbor\n"
5616 "Name of route map\n"
5617 "Apply map to incoming routes\n"
5618 "Apply map to outbound routes\n")
5619 {
5620 int idx_peer = 1;
5621 int idx_word = 3;
5622 int idx_in_out = 4;
5623 return peer_route_map_set_vty(
5624 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5625 argv[idx_word]->arg, argv[idx_in_out]->arg);
5626 }
5627
5628 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5629 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5630 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Apply route map to neighbor\n"
5632 "Name of route map\n"
5633 "Apply map to incoming routes\n"
5634 "Apply map to outbound routes\n")
5635
5636 DEFUN (no_neighbor_route_map,
5637 no_neighbor_route_map_cmd,
5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5639 NO_STR
5640 NEIGHBOR_STR
5641 NEIGHBOR_ADDR_STR2
5642 "Apply route map to neighbor\n"
5643 "Name of route map\n"
5644 "Apply map to incoming routes\n"
5645 "Apply map to outbound routes\n")
5646 {
5647 int idx_peer = 2;
5648 int idx_in_out = 5;
5649 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5650 bgp_node_afi(vty), bgp_node_safi(vty),
5651 argv[idx_in_out]->arg);
5652 }
5653
5654 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5655 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5656 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5657 "Apply route map to neighbor\n"
5658 "Name of route map\n"
5659 "Apply map to incoming routes\n"
5660 "Apply map to outbound routes\n")
5661
5662 /* Set unsuppress-map to the peer. */
5663 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5664 afi_t afi, safi_t safi,
5665 const char *name_str)
5666 {
5667 int ret;
5668 struct peer *peer;
5669
5670 peer = peer_and_group_lookup_vty(vty, ip_str);
5671 if (!peer)
5672 return CMD_WARNING_CONFIG_FAILED;
5673
5674 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5675
5676 return bgp_vty_return(vty, ret);
5677 }
5678
5679 /* Unset route-map from the peer. */
5680 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5681 afi_t afi, safi_t safi)
5682 {
5683 int ret;
5684 struct peer *peer;
5685
5686 peer = peer_and_group_lookup_vty(vty, ip_str);
5687 if (!peer)
5688 return CMD_WARNING_CONFIG_FAILED;
5689
5690 ret = peer_unsuppress_map_unset(peer, afi, safi);
5691
5692 return bgp_vty_return(vty, ret);
5693 }
5694
5695 DEFUN (neighbor_unsuppress_map,
5696 neighbor_unsuppress_map_cmd,
5697 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5698 NEIGHBOR_STR
5699 NEIGHBOR_ADDR_STR2
5700 "Route-map to selectively unsuppress suppressed routes\n"
5701 "Name of route map\n")
5702 {
5703 int idx_peer = 1;
5704 int idx_word = 3;
5705 return peer_unsuppress_map_set_vty(
5706 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5707 argv[idx_word]->arg);
5708 }
5709
5710 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5711 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5712 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5713 "Route-map to selectively unsuppress suppressed routes\n"
5714 "Name of route map\n")
5715
5716 DEFUN (no_neighbor_unsuppress_map,
5717 no_neighbor_unsuppress_map_cmd,
5718 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5719 NO_STR
5720 NEIGHBOR_STR
5721 NEIGHBOR_ADDR_STR2
5722 "Route-map to selectively unsuppress suppressed routes\n"
5723 "Name of route map\n")
5724 {
5725 int idx_peer = 2;
5726 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5727 bgp_node_afi(vty),
5728 bgp_node_safi(vty));
5729 }
5730
5731 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5732 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5733 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5734 "Route-map to selectively unsuppress suppressed routes\n"
5735 "Name of route map\n")
5736
5737 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5738 afi_t afi, safi_t safi,
5739 const char *num_str,
5740 const char *threshold_str, int warning,
5741 const char *restart_str)
5742 {
5743 int ret;
5744 struct peer *peer;
5745 uint32_t max;
5746 uint8_t threshold;
5747 uint16_t restart;
5748
5749 peer = peer_and_group_lookup_vty(vty, ip_str);
5750 if (!peer)
5751 return CMD_WARNING_CONFIG_FAILED;
5752
5753 max = strtoul(num_str, NULL, 10);
5754 if (threshold_str)
5755 threshold = atoi(threshold_str);
5756 else
5757 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5758
5759 if (restart_str)
5760 restart = atoi(restart_str);
5761 else
5762 restart = 0;
5763
5764 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5765 restart);
5766
5767 return bgp_vty_return(vty, ret);
5768 }
5769
5770 static int peer_maximum_prefix_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_maximum_prefix_unset(peer, afi, safi);
5781
5782 return bgp_vty_return(vty, ret);
5783 }
5784
5785 /* Maximum number of prefix configuration. prefix count is different
5786 for each peer configuration. So this configuration can be set for
5787 each peer configuration. */
5788 DEFUN (neighbor_maximum_prefix,
5789 neighbor_maximum_prefix_cmd,
5790 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5791 NEIGHBOR_STR
5792 NEIGHBOR_ADDR_STR2
5793 "Maximum number of prefix accept from this peer\n"
5794 "maximum no. of prefix limit\n")
5795 {
5796 int idx_peer = 1;
5797 int idx_number = 3;
5798 return peer_maximum_prefix_set_vty(
5799 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5800 argv[idx_number]->arg, NULL, 0, NULL);
5801 }
5802
5803 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5804 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5805 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5806 "Maximum number of prefix accept from this peer\n"
5807 "maximum no. of prefix limit\n")
5808
5809 DEFUN (neighbor_maximum_prefix_threshold,
5810 neighbor_maximum_prefix_threshold_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Maximum number of prefix accept from this peer\n"
5815 "maximum no. of prefix limit\n"
5816 "Threshold value (%) at which to generate a warning msg\n")
5817 {
5818 int idx_peer = 1;
5819 int idx_number = 3;
5820 int idx_number_2 = 4;
5821 return peer_maximum_prefix_set_vty(
5822 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5823 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5824 }
5825
5826 ALIAS_HIDDEN(
5827 neighbor_maximum_prefix_threshold,
5828 neighbor_maximum_prefix_threshold_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Maximum number of prefix accept from this peer\n"
5832 "maximum no. of prefix limit\n"
5833 "Threshold value (%) at which to generate a warning msg\n")
5834
5835 DEFUN (neighbor_maximum_prefix_warning,
5836 neighbor_maximum_prefix_warning_cmd,
5837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5838 NEIGHBOR_STR
5839 NEIGHBOR_ADDR_STR2
5840 "Maximum number of prefix accept from this peer\n"
5841 "maximum no. of prefix limit\n"
5842 "Only give warning message when limit is exceeded\n")
5843 {
5844 int idx_peer = 1;
5845 int idx_number = 3;
5846 return peer_maximum_prefix_set_vty(
5847 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5848 argv[idx_number]->arg, NULL, 1, NULL);
5849 }
5850
5851 ALIAS_HIDDEN(
5852 neighbor_maximum_prefix_warning,
5853 neighbor_maximum_prefix_warning_hidden_cmd,
5854 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5855 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5856 "Maximum number of prefix accept from this peer\n"
5857 "maximum no. of prefix limit\n"
5858 "Only give warning message when limit is exceeded\n")
5859
5860 DEFUN (neighbor_maximum_prefix_threshold_warning,
5861 neighbor_maximum_prefix_threshold_warning_cmd,
5862 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5863 NEIGHBOR_STR
5864 NEIGHBOR_ADDR_STR2
5865 "Maximum number of prefix accept from this peer\n"
5866 "maximum no. of prefix limit\n"
5867 "Threshold value (%) at which to generate a warning msg\n"
5868 "Only give warning message when limit is exceeded\n")
5869 {
5870 int idx_peer = 1;
5871 int idx_number = 3;
5872 int idx_number_2 = 4;
5873 return peer_maximum_prefix_set_vty(
5874 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5875 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5876 }
5877
5878 ALIAS_HIDDEN(
5879 neighbor_maximum_prefix_threshold_warning,
5880 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5881 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5882 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5883 "Maximum number of prefix accept from this peer\n"
5884 "maximum no. of prefix limit\n"
5885 "Threshold value (%) at which to generate a warning msg\n"
5886 "Only give warning message when limit is exceeded\n")
5887
5888 DEFUN (neighbor_maximum_prefix_restart,
5889 neighbor_maximum_prefix_restart_cmd,
5890 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5891 NEIGHBOR_STR
5892 NEIGHBOR_ADDR_STR2
5893 "Maximum number of prefix accept from this peer\n"
5894 "maximum no. of prefix limit\n"
5895 "Restart bgp connection after limit is exceeded\n"
5896 "Restart interval in minutes\n")
5897 {
5898 int idx_peer = 1;
5899 int idx_number = 3;
5900 int idx_number_2 = 5;
5901 return peer_maximum_prefix_set_vty(
5902 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5903 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5904 }
5905
5906 ALIAS_HIDDEN(
5907 neighbor_maximum_prefix_restart,
5908 neighbor_maximum_prefix_restart_hidden_cmd,
5909 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5910 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5911 "Maximum number of prefix accept from this peer\n"
5912 "maximum no. of prefix limit\n"
5913 "Restart bgp connection after limit is exceeded\n"
5914 "Restart interval in minutes\n")
5915
5916 DEFUN (neighbor_maximum_prefix_threshold_restart,
5917 neighbor_maximum_prefix_threshold_restart_cmd,
5918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5919 NEIGHBOR_STR
5920 NEIGHBOR_ADDR_STR2
5921 "Maximum number of prefixes to accept from this peer\n"
5922 "maximum no. of prefix limit\n"
5923 "Threshold value (%) at which to generate a warning msg\n"
5924 "Restart bgp connection after limit is exceeded\n"
5925 "Restart interval in minutes\n")
5926 {
5927 int idx_peer = 1;
5928 int idx_number = 3;
5929 int idx_number_2 = 4;
5930 int idx_number_3 = 6;
5931 return peer_maximum_prefix_set_vty(
5932 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5933 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5934 argv[idx_number_3]->arg);
5935 }
5936
5937 ALIAS_HIDDEN(
5938 neighbor_maximum_prefix_threshold_restart,
5939 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5940 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5941 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5942 "Maximum number of prefixes to accept from this peer\n"
5943 "maximum no. of prefix limit\n"
5944 "Threshold value (%) at which to generate a warning msg\n"
5945 "Restart bgp connection after limit is exceeded\n"
5946 "Restart interval in minutes\n")
5947
5948 DEFUN (no_neighbor_maximum_prefix,
5949 no_neighbor_maximum_prefix_cmd,
5950 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5951 NO_STR
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Maximum number of prefixes to accept from this peer\n"
5955 "maximum no. of prefix limit\n"
5956 "Threshold value (%) at which to generate a warning msg\n"
5957 "Restart bgp connection after limit is exceeded\n"
5958 "Restart interval in minutes\n"
5959 "Only give warning message when limit is exceeded\n")
5960 {
5961 int idx_peer = 2;
5962 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5963 bgp_node_afi(vty),
5964 bgp_node_safi(vty));
5965 }
5966
5967 ALIAS_HIDDEN(
5968 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5969 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5970 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5971 "Maximum number of prefixes to accept from this peer\n"
5972 "maximum no. of prefix limit\n"
5973 "Threshold value (%) at which to generate a warning msg\n"
5974 "Restart bgp connection after limit is exceeded\n"
5975 "Restart interval in minutes\n"
5976 "Only give warning message when limit is exceeded\n")
5977
5978
5979 /* "neighbor allowas-in" */
5980 DEFUN (neighbor_allowas_in,
5981 neighbor_allowas_in_cmd,
5982 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5983 NEIGHBOR_STR
5984 NEIGHBOR_ADDR_STR2
5985 "Accept as-path with my AS present in it\n"
5986 "Number of occurances of AS number\n"
5987 "Only accept my AS in the as-path if the route was originated in my AS\n")
5988 {
5989 int idx_peer = 1;
5990 int idx_number_origin = 3;
5991 int ret;
5992 int origin = 0;
5993 struct peer *peer;
5994 int allow_num = 0;
5995
5996 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5997 if (!peer)
5998 return CMD_WARNING_CONFIG_FAILED;
5999
6000 if (argc <= idx_number_origin)
6001 allow_num = 3;
6002 else {
6003 if (argv[idx_number_origin]->type == WORD_TKN)
6004 origin = 1;
6005 else
6006 allow_num = atoi(argv[idx_number_origin]->arg);
6007 }
6008
6009 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6010 allow_num, origin);
6011
6012 return bgp_vty_return(vty, ret);
6013 }
6014
6015 ALIAS_HIDDEN(
6016 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6017 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6018 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6019 "Accept as-path with my AS present in it\n"
6020 "Number of occurances of AS number\n"
6021 "Only accept my AS in the as-path if the route was originated in my AS\n")
6022
6023 DEFUN (no_neighbor_allowas_in,
6024 no_neighbor_allowas_in_cmd,
6025 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6026 NO_STR
6027 NEIGHBOR_STR
6028 NEIGHBOR_ADDR_STR2
6029 "allow local ASN appears in aspath attribute\n"
6030 "Number of occurances of AS number\n"
6031 "Only accept my AS in the as-path if the route was originated in my AS\n")
6032 {
6033 int idx_peer = 2;
6034 int ret;
6035 struct peer *peer;
6036
6037 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6038 if (!peer)
6039 return CMD_WARNING_CONFIG_FAILED;
6040
6041 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6042 bgp_node_safi(vty));
6043
6044 return bgp_vty_return(vty, ret);
6045 }
6046
6047 ALIAS_HIDDEN(
6048 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6049 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6050 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6051 "allow local ASN appears in aspath attribute\n"
6052 "Number of occurances of AS number\n"
6053 "Only accept my AS in the as-path if the route was originated in my AS\n")
6054
6055 DEFUN (neighbor_ttl_security,
6056 neighbor_ttl_security_cmd,
6057 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6058 NEIGHBOR_STR
6059 NEIGHBOR_ADDR_STR2
6060 "BGP ttl-security parameters\n"
6061 "Specify the maximum number of hops to the BGP peer\n"
6062 "Number of hops to BGP peer\n")
6063 {
6064 int idx_peer = 1;
6065 int idx_number = 4;
6066 struct peer *peer;
6067 int gtsm_hops;
6068
6069 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6070 if (!peer)
6071 return CMD_WARNING_CONFIG_FAILED;
6072
6073 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6074
6075 /*
6076 * If 'neighbor swpX', then this is for directly connected peers,
6077 * we should not accept a ttl-security hops value greater than 1.
6078 */
6079 if (peer->conf_if && (gtsm_hops > 1)) {
6080 vty_out(vty,
6081 "%s is directly connected peer, hops cannot exceed 1\n",
6082 argv[idx_peer]->arg);
6083 return CMD_WARNING_CONFIG_FAILED;
6084 }
6085
6086 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6087 }
6088
6089 DEFUN (no_neighbor_ttl_security,
6090 no_neighbor_ttl_security_cmd,
6091 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6092 NO_STR
6093 NEIGHBOR_STR
6094 NEIGHBOR_ADDR_STR2
6095 "BGP ttl-security parameters\n"
6096 "Specify the maximum number of hops to the BGP peer\n"
6097 "Number of hops to BGP peer\n")
6098 {
6099 int idx_peer = 2;
6100 struct peer *peer;
6101
6102 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6103 if (!peer)
6104 return CMD_WARNING_CONFIG_FAILED;
6105
6106 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6107 }
6108
6109 DEFUN (neighbor_addpath_tx_all_paths,
6110 neighbor_addpath_tx_all_paths_cmd,
6111 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6112 NEIGHBOR_STR
6113 NEIGHBOR_ADDR_STR2
6114 "Use addpath to advertise all paths to a neighbor\n")
6115 {
6116 int idx_peer = 1;
6117 struct peer *peer;
6118
6119 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6120 if (!peer)
6121 return CMD_WARNING_CONFIG_FAILED;
6122
6123 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6124 bgp_node_safi(vty),
6125 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6126 }
6127
6128 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6129 neighbor_addpath_tx_all_paths_hidden_cmd,
6130 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6131 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6132 "Use addpath to advertise all paths to a neighbor\n")
6133
6134 DEFUN (no_neighbor_addpath_tx_all_paths,
6135 no_neighbor_addpath_tx_all_paths_cmd,
6136 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6137 NO_STR
6138 NEIGHBOR_STR
6139 NEIGHBOR_ADDR_STR2
6140 "Use addpath to advertise all paths to a neighbor\n")
6141 {
6142 int idx_peer = 2;
6143 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6144 bgp_node_afi(vty), bgp_node_safi(vty),
6145 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6146 }
6147
6148 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6149 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6150 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6151 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6152 "Use addpath to advertise all paths to a neighbor\n")
6153
6154 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6155 neighbor_addpath_tx_bestpath_per_as_cmd,
6156 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6157 NEIGHBOR_STR
6158 NEIGHBOR_ADDR_STR2
6159 "Use addpath to advertise the bestpath per each neighboring AS\n")
6160 {
6161 int idx_peer = 1;
6162 struct peer *peer;
6163
6164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6165 if (!peer)
6166 return CMD_WARNING_CONFIG_FAILED;
6167
6168 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6169 bgp_node_safi(vty),
6170 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6171 }
6172
6173 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6174 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6175 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6176 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6177 "Use addpath to advertise the bestpath per each neighboring AS\n")
6178
6179 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6180 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6181 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6182 NO_STR
6183 NEIGHBOR_STR
6184 NEIGHBOR_ADDR_STR2
6185 "Use addpath to advertise the bestpath per each neighboring AS\n")
6186 {
6187 int idx_peer = 2;
6188 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6189 bgp_node_afi(vty), bgp_node_safi(vty),
6190 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6191 }
6192
6193 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6194 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6195 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6196 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6197 "Use addpath to advertise the bestpath per each neighboring AS\n")
6198
6199 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6200 struct ecommunity **list)
6201 {
6202 struct ecommunity *ecom = NULL;
6203 struct ecommunity *ecomadd;
6204
6205 for (; argc; --argc, ++argv) {
6206
6207 ecomadd = ecommunity_str2com(argv[0]->arg,
6208 ECOMMUNITY_ROUTE_TARGET, 0);
6209 if (!ecomadd) {
6210 vty_out(vty, "Malformed community-list value\n");
6211 if (ecom)
6212 ecommunity_free(&ecom);
6213 return CMD_WARNING_CONFIG_FAILED;
6214 }
6215
6216 if (ecom) {
6217 ecommunity_merge(ecom, ecomadd);
6218 ecommunity_free(&ecomadd);
6219 } else {
6220 ecom = ecomadd;
6221 }
6222 }
6223
6224 if (*list) {
6225 ecommunity_free(&*list);
6226 }
6227 *list = ecom;
6228
6229 return CMD_SUCCESS;
6230 }
6231
6232 /*
6233 * v2vimport is true if we are handling a `import vrf ...` command
6234 */
6235 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6236 {
6237 afi_t afi;
6238
6239 switch (vty->node) {
6240 case BGP_IPV4_NODE:
6241 afi = AFI_IP;
6242 break;
6243 case BGP_IPV6_NODE:
6244 afi = AFI_IP6;
6245 break;
6246 default:
6247 vty_out(vty,
6248 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6249 return AFI_MAX;
6250 }
6251
6252 if (!v2vimport) {
6253 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6254 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6255 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6256 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6257 vty_out(vty,
6258 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6259 return AFI_MAX;
6260 }
6261 } else {
6262 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6263 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6264 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6265 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6266 vty_out(vty,
6267 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6268 return AFI_MAX;
6269 }
6270 }
6271 return afi;
6272 }
6273
6274 DEFPY (af_rd_vpn_export,
6275 af_rd_vpn_export_cmd,
6276 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6277 NO_STR
6278 "Specify route distinguisher\n"
6279 "Between current address-family and vpn\n"
6280 "For routes leaked from current address-family to vpn\n"
6281 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6282 {
6283 VTY_DECLVAR_CONTEXT(bgp, bgp);
6284 struct prefix_rd prd;
6285 int ret;
6286 afi_t afi;
6287 int idx = 0;
6288 int yes = 1;
6289
6290 if (argv_find(argv, argc, "no", &idx))
6291 yes = 0;
6292
6293 if (yes) {
6294 ret = str2prefix_rd(rd_str, &prd);
6295 if (!ret) {
6296 vty_out(vty, "%% Malformed rd\n");
6297 return CMD_WARNING_CONFIG_FAILED;
6298 }
6299 }
6300
6301 afi = vpn_policy_getafi(vty, bgp, false);
6302 if (afi == AFI_MAX)
6303 return CMD_WARNING_CONFIG_FAILED;
6304
6305 /*
6306 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6307 */
6308 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6309 bgp_get_default(), bgp);
6310
6311 if (yes) {
6312 bgp->vpn_policy[afi].tovpn_rd = prd;
6313 SET_FLAG(bgp->vpn_policy[afi].flags,
6314 BGP_VPN_POLICY_TOVPN_RD_SET);
6315 } else {
6316 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6317 BGP_VPN_POLICY_TOVPN_RD_SET);
6318 }
6319
6320 /* post-change: re-export vpn routes */
6321 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6322 bgp_get_default(), bgp);
6323
6324 return CMD_SUCCESS;
6325 }
6326
6327 ALIAS (af_rd_vpn_export,
6328 af_no_rd_vpn_export_cmd,
6329 "no rd vpn export",
6330 NO_STR
6331 "Specify route distinguisher\n"
6332 "Between current address-family and vpn\n"
6333 "For routes leaked from current address-family to vpn\n")
6334
6335 DEFPY (af_label_vpn_export,
6336 af_label_vpn_export_cmd,
6337 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6338 NO_STR
6339 "label value for VRF\n"
6340 "Between current address-family and vpn\n"
6341 "For routes leaked from current address-family to vpn\n"
6342 "Label Value <0-1048575>\n"
6343 "Automatically assign a label\n")
6344 {
6345 VTY_DECLVAR_CONTEXT(bgp, bgp);
6346 mpls_label_t label = MPLS_LABEL_NONE;
6347 afi_t afi;
6348 int idx = 0;
6349 int yes = 1;
6350
6351 if (argv_find(argv, argc, "no", &idx))
6352 yes = 0;
6353
6354 /* If "no ...", squash trailing parameter */
6355 if (!yes)
6356 label_auto = NULL;
6357
6358 if (yes) {
6359 if (!label_auto)
6360 label = label_val; /* parser should force unsigned */
6361 }
6362
6363 afi = vpn_policy_getafi(vty, bgp, false);
6364 if (afi == AFI_MAX)
6365 return CMD_WARNING_CONFIG_FAILED;
6366
6367
6368 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6369 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6370 /* no change */
6371 return CMD_SUCCESS;
6372
6373 /*
6374 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6375 */
6376 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6377 bgp_get_default(), bgp);
6378
6379 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6380 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6381
6382 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6383
6384 /*
6385 * label has previously been automatically
6386 * assigned by labelpool: release it
6387 *
6388 * NB if tovpn_label == MPLS_LABEL_NONE it
6389 * means the automatic assignment is in flight
6390 * and therefore the labelpool callback must
6391 * detect that the auto label is not needed.
6392 */
6393
6394 bgp_lp_release(LP_TYPE_VRF,
6395 &bgp->vpn_policy[afi],
6396 bgp->vpn_policy[afi].tovpn_label);
6397 }
6398 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6399 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6400 }
6401
6402 bgp->vpn_policy[afi].tovpn_label = label;
6403 if (label_auto) {
6404 SET_FLAG(bgp->vpn_policy[afi].flags,
6405 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6406 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6407 vpn_leak_label_callback);
6408 }
6409
6410 /* post-change: re-export vpn routes */
6411 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6412 bgp_get_default(), bgp);
6413
6414 return CMD_SUCCESS;
6415 }
6416
6417 ALIAS (af_label_vpn_export,
6418 af_no_label_vpn_export_cmd,
6419 "no label vpn export",
6420 NO_STR
6421 "label value for VRF\n"
6422 "Between current address-family and vpn\n"
6423 "For routes leaked from current address-family to vpn\n")
6424
6425 DEFPY (af_nexthop_vpn_export,
6426 af_nexthop_vpn_export_cmd,
6427 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6428 NO_STR
6429 "Specify next hop to use for VRF advertised prefixes\n"
6430 "Between current address-family and vpn\n"
6431 "For routes leaked from current address-family to vpn\n"
6432 "IPv4 prefix\n"
6433 "IPv6 prefix\n")
6434 {
6435 VTY_DECLVAR_CONTEXT(bgp, bgp);
6436 afi_t afi;
6437 struct prefix p;
6438 int idx = 0;
6439 int yes = 1;
6440
6441 if (argv_find(argv, argc, "no", &idx))
6442 yes = 0;
6443
6444 if (yes) {
6445 if (!sockunion2hostprefix(nexthop_str, &p))
6446 return CMD_WARNING_CONFIG_FAILED;
6447 }
6448
6449 afi = vpn_policy_getafi(vty, bgp, false);
6450 if (afi == AFI_MAX)
6451 return CMD_WARNING_CONFIG_FAILED;
6452
6453 /*
6454 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6455 */
6456 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6457 bgp_get_default(), bgp);
6458
6459 if (yes) {
6460 bgp->vpn_policy[afi].tovpn_nexthop = p;
6461 SET_FLAG(bgp->vpn_policy[afi].flags,
6462 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6463 } else {
6464 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6465 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6466 }
6467
6468 /* post-change: re-export vpn routes */
6469 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6470 bgp_get_default(), bgp);
6471
6472 return CMD_SUCCESS;
6473 }
6474
6475 ALIAS (af_nexthop_vpn_export,
6476 af_no_nexthop_vpn_export_cmd,
6477 "no nexthop vpn export",
6478 NO_STR
6479 "Specify next hop to use for VRF advertised prefixes\n"
6480 "Between current address-family and vpn\n"
6481 "For routes leaked from current address-family to vpn\n")
6482
6483 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6484 {
6485 if (!strcmp(dstr, "import")) {
6486 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6487 } else if (!strcmp(dstr, "export")) {
6488 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6489 } else if (!strcmp(dstr, "both")) {
6490 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6491 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6492 } else {
6493 vty_out(vty, "%% direction parse error\n");
6494 return CMD_WARNING_CONFIG_FAILED;
6495 }
6496 return CMD_SUCCESS;
6497 }
6498
6499 DEFPY (af_rt_vpn_imexport,
6500 af_rt_vpn_imexport_cmd,
6501 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6502 NO_STR
6503 "Specify route target list\n"
6504 "Specify route target list\n"
6505 "Between current address-family and vpn\n"
6506 "For routes leaked from vpn to current address-family: match any\n"
6507 "For routes leaked from current address-family to vpn: set\n"
6508 "both import: match any and export: set\n"
6509 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6510 {
6511 VTY_DECLVAR_CONTEXT(bgp, bgp);
6512 int ret;
6513 struct ecommunity *ecom = NULL;
6514 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6515 vpn_policy_direction_t dir;
6516 afi_t afi;
6517 int idx = 0;
6518 int yes = 1;
6519
6520 if (argv_find(argv, argc, "no", &idx))
6521 yes = 0;
6522
6523 afi = vpn_policy_getafi(vty, bgp, false);
6524 if (afi == AFI_MAX)
6525 return CMD_WARNING_CONFIG_FAILED;
6526
6527 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6528 if (ret != CMD_SUCCESS)
6529 return ret;
6530
6531 if (yes) {
6532 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6533 vty_out(vty, "%% Missing RTLIST\n");
6534 return CMD_WARNING_CONFIG_FAILED;
6535 }
6536 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6537 if (ret != CMD_SUCCESS) {
6538 return ret;
6539 }
6540 }
6541
6542 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6543 if (!dodir[dir])
6544 continue;
6545
6546 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6547
6548 if (yes) {
6549 if (bgp->vpn_policy[afi].rtlist[dir])
6550 ecommunity_free(
6551 &bgp->vpn_policy[afi].rtlist[dir]);
6552 bgp->vpn_policy[afi].rtlist[dir] =
6553 ecommunity_dup(ecom);
6554 } else {
6555 if (bgp->vpn_policy[afi].rtlist[dir])
6556 ecommunity_free(
6557 &bgp->vpn_policy[afi].rtlist[dir]);
6558 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6559 }
6560
6561 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6562 }
6563
6564 if (ecom)
6565 ecommunity_free(&ecom);
6566
6567 return CMD_SUCCESS;
6568 }
6569
6570 ALIAS (af_rt_vpn_imexport,
6571 af_no_rt_vpn_imexport_cmd,
6572 "no <rt|route-target> vpn <import|export|both>$direction_str",
6573 NO_STR
6574 "Specify route target list\n"
6575 "Specify route target list\n"
6576 "Between current address-family and vpn\n"
6577 "For routes leaked from vpn to current address-family\n"
6578 "For routes leaked from current address-family to vpn\n"
6579 "both import and export\n")
6580
6581 DEFPY (af_route_map_vpn_imexport,
6582 af_route_map_vpn_imexport_cmd,
6583 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6584 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6585 NO_STR
6586 "Specify route map\n"
6587 "Between current address-family and vpn\n"
6588 "For routes leaked from vpn to current address-family\n"
6589 "For routes leaked from current address-family to vpn\n"
6590 "name of route-map\n")
6591 {
6592 VTY_DECLVAR_CONTEXT(bgp, bgp);
6593 int ret;
6594 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6595 vpn_policy_direction_t dir;
6596 afi_t afi;
6597 int idx = 0;
6598 int yes = 1;
6599
6600 if (argv_find(argv, argc, "no", &idx))
6601 yes = 0;
6602
6603 afi = vpn_policy_getafi(vty, bgp, false);
6604 if (afi == AFI_MAX)
6605 return CMD_WARNING_CONFIG_FAILED;
6606
6607 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6608 if (ret != CMD_SUCCESS)
6609 return ret;
6610
6611 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6612 if (!dodir[dir])
6613 continue;
6614
6615 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6616
6617 if (yes) {
6618 if (bgp->vpn_policy[afi].rmap_name[dir])
6619 XFREE(MTYPE_ROUTE_MAP_NAME,
6620 bgp->vpn_policy[afi].rmap_name[dir]);
6621 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6622 MTYPE_ROUTE_MAP_NAME, rmap_str);
6623 bgp->vpn_policy[afi].rmap[dir] =
6624 route_map_lookup_by_name(rmap_str);
6625 if (!bgp->vpn_policy[afi].rmap[dir])
6626 return CMD_SUCCESS;
6627 } else {
6628 if (bgp->vpn_policy[afi].rmap_name[dir])
6629 XFREE(MTYPE_ROUTE_MAP_NAME,
6630 bgp->vpn_policy[afi].rmap_name[dir]);
6631 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6632 bgp->vpn_policy[afi].rmap[dir] = NULL;
6633 }
6634
6635 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6636 }
6637
6638 return CMD_SUCCESS;
6639 }
6640
6641 ALIAS (af_route_map_vpn_imexport,
6642 af_no_route_map_vpn_imexport_cmd,
6643 "no route-map vpn <import|export>$direction_str",
6644 NO_STR
6645 "Specify route map\n"
6646 "Between current address-family and vpn\n"
6647 "For routes leaked from vpn to current address-family\n"
6648 "For routes leaked from current address-family to vpn\n")
6649
6650 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6651 "[no] import vrf route-map RMAP$rmap_str",
6652 NO_STR
6653 "Import routes from another VRF\n"
6654 "Vrf routes being filtered\n"
6655 "Specify route map\n"
6656 "name of route-map\n")
6657 {
6658 VTY_DECLVAR_CONTEXT(bgp, bgp);
6659 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6660 afi_t afi;
6661 int idx = 0;
6662 int yes = 1;
6663 struct bgp *bgp_default;
6664
6665 if (argv_find(argv, argc, "no", &idx))
6666 yes = 0;
6667
6668 afi = vpn_policy_getafi(vty, bgp, true);
6669 if (afi == AFI_MAX)
6670 return CMD_WARNING_CONFIG_FAILED;
6671
6672 bgp_default = bgp_get_default();
6673 if (!bgp_default) {
6674 int32_t ret;
6675 as_t as = bgp->as;
6676
6677 /* Auto-create assuming the same AS */
6678 ret = bgp_get(&bgp_default, &as, NULL,
6679 BGP_INSTANCE_TYPE_DEFAULT);
6680
6681 if (ret) {
6682 vty_out(vty,
6683 "VRF default is not configured as a bgp instance\n");
6684 return CMD_WARNING;
6685 }
6686 }
6687
6688 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6689
6690 if (yes) {
6691 if (bgp->vpn_policy[afi].rmap_name[dir])
6692 XFREE(MTYPE_ROUTE_MAP_NAME,
6693 bgp->vpn_policy[afi].rmap_name[dir]);
6694 bgp->vpn_policy[afi].rmap_name[dir] =
6695 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6696 bgp->vpn_policy[afi].rmap[dir] =
6697 route_map_lookup_by_name(rmap_str);
6698 if (!bgp->vpn_policy[afi].rmap[dir])
6699 return CMD_SUCCESS;
6700 } else {
6701 if (bgp->vpn_policy[afi].rmap_name[dir])
6702 XFREE(MTYPE_ROUTE_MAP_NAME,
6703 bgp->vpn_policy[afi].rmap_name[dir]);
6704 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6705 bgp->vpn_policy[afi].rmap[dir] = NULL;
6706 }
6707
6708 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6709
6710 return CMD_SUCCESS;
6711 }
6712
6713 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6714 "no import vrf route-map",
6715 NO_STR
6716 "Import routes from another VRF\n"
6717 "Vrf routes being filtered\n"
6718 "Specify route map\n")
6719
6720 DEFPY (bgp_imexport_vrf,
6721 bgp_imexport_vrf_cmd,
6722 "[no] import vrf NAME$import_name",
6723 NO_STR
6724 "Import routes from another VRF\n"
6725 "VRF to import from\n"
6726 "The name of the VRF\n")
6727 {
6728 VTY_DECLVAR_CONTEXT(bgp, bgp);
6729 struct listnode *node;
6730 struct bgp *vrf_bgp, *bgp_default;
6731 int32_t ret = 0;
6732 as_t as = bgp->as;
6733 bool remove = false;
6734 int32_t idx = 0;
6735 char *vname;
6736 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6737 safi_t safi;
6738 afi_t afi;
6739
6740 if (import_name == NULL) {
6741 vty_out(vty, "%% Missing import name\n");
6742 return CMD_WARNING;
6743 }
6744
6745 if (argv_find(argv, argc, "no", &idx))
6746 remove = true;
6747
6748 afi = vpn_policy_getafi(vty, bgp, true);
6749 if (afi == AFI_MAX)
6750 return CMD_WARNING_CONFIG_FAILED;
6751
6752 safi = bgp_node_safi(vty);
6753
6754 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6755 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6756 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6757 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6758 remove ? "unimport" : "import", import_name);
6759 return CMD_WARNING;
6760 }
6761
6762 bgp_default = bgp_get_default();
6763 if (!bgp_default) {
6764 /* Auto-create assuming the same AS */
6765 ret = bgp_get(&bgp_default, &as, NULL,
6766 BGP_INSTANCE_TYPE_DEFAULT);
6767
6768 if (ret) {
6769 vty_out(vty,
6770 "VRF default is not configured as a bgp instance\n");
6771 return CMD_WARNING;
6772 }
6773 }
6774
6775 vrf_bgp = bgp_lookup_by_name(import_name);
6776 if (!vrf_bgp) {
6777 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6778 vrf_bgp = bgp_default;
6779 else
6780 /* Auto-create assuming the same AS */
6781 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6782
6783 if (ret) {
6784 vty_out(vty,
6785 "VRF %s is not configured as a bgp instance\n",
6786 import_name);
6787 return CMD_WARNING;
6788 }
6789 }
6790
6791 if (remove) {
6792 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6793 } else {
6794 /* Already importing from "import_vrf"? */
6795 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6796 vname)) {
6797 if (strcmp(vname, import_name) == 0)
6798 return CMD_WARNING;
6799 }
6800
6801 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6802 }
6803
6804 return CMD_SUCCESS;
6805 }
6806
6807 /* This command is valid only in a bgp vrf instance or the default instance */
6808 DEFPY (bgp_imexport_vpn,
6809 bgp_imexport_vpn_cmd,
6810 "[no] <import|export>$direction_str vpn",
6811 NO_STR
6812 "Import routes to this address-family\n"
6813 "Export routes from this address-family\n"
6814 "to/from default instance VPN RIB\n")
6815 {
6816 VTY_DECLVAR_CONTEXT(bgp, bgp);
6817 int previous_state;
6818 afi_t afi;
6819 safi_t safi;
6820 int idx = 0;
6821 int yes = 1;
6822 int flag;
6823 vpn_policy_direction_t dir;
6824
6825 if (argv_find(argv, argc, "no", &idx))
6826 yes = 0;
6827
6828 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6829 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6830
6831 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6832 return CMD_WARNING_CONFIG_FAILED;
6833 }
6834
6835 afi = bgp_node_afi(vty);
6836 safi = bgp_node_safi(vty);
6837 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6838 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6839 return CMD_WARNING_CONFIG_FAILED;
6840 }
6841
6842 if (!strcmp(direction_str, "import")) {
6843 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6844 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6845 } else if (!strcmp(direction_str, "export")) {
6846 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6847 dir = BGP_VPN_POLICY_DIR_TOVPN;
6848 } else {
6849 vty_out(vty, "%% unknown direction %s\n", direction_str);
6850 return CMD_WARNING_CONFIG_FAILED;
6851 }
6852
6853 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6854
6855 if (yes) {
6856 SET_FLAG(bgp->af_flags[afi][safi], flag);
6857 if (!previous_state) {
6858 /* trigger export current vrf */
6859 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6860 }
6861 } else {
6862 if (previous_state) {
6863 /* trigger un-export current vrf */
6864 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6865 }
6866 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6867 }
6868
6869 return CMD_SUCCESS;
6870 }
6871
6872 DEFPY (af_routetarget_import,
6873 af_routetarget_import_cmd,
6874 "[no] <rt|route-target> redirect import RTLIST...",
6875 NO_STR
6876 "Specify route target list\n"
6877 "Specify route target list\n"
6878 "Flow-spec redirect type route target\n"
6879 "Import routes to this address-family\n"
6880 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6881 {
6882 VTY_DECLVAR_CONTEXT(bgp, bgp);
6883 int ret;
6884 struct ecommunity *ecom = NULL;
6885 afi_t afi;
6886 int idx = 0;
6887 int yes = 1;
6888
6889 if (argv_find(argv, argc, "no", &idx))
6890 yes = 0;
6891
6892 afi = vpn_policy_getafi(vty, bgp, false);
6893 if (afi == AFI_MAX)
6894 return CMD_WARNING_CONFIG_FAILED;
6895
6896 if (yes) {
6897 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6898 vty_out(vty, "%% Missing RTLIST\n");
6899 return CMD_WARNING_CONFIG_FAILED;
6900 }
6901 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6902 if (ret != CMD_SUCCESS)
6903 return ret;
6904 }
6905
6906 if (yes) {
6907 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6908 ecommunity_free(&bgp->vpn_policy[afi]
6909 .import_redirect_rtlist);
6910 bgp->vpn_policy[afi].import_redirect_rtlist =
6911 ecommunity_dup(ecom);
6912 } else {
6913 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6914 ecommunity_free(&bgp->vpn_policy[afi]
6915 .import_redirect_rtlist);
6916 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6917 }
6918
6919 if (ecom)
6920 ecommunity_free(&ecom);
6921
6922 return CMD_SUCCESS;
6923 }
6924
6925 DEFUN_NOSH (address_family_ipv4_safi,
6926 address_family_ipv4_safi_cmd,
6927 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6928 "Enter Address Family command mode\n"
6929 "Address Family\n"
6930 BGP_SAFI_WITH_LABEL_HELP_STR)
6931 {
6932
6933 if (argc == 3) {
6934 VTY_DECLVAR_CONTEXT(bgp, bgp);
6935 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6936 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6937 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6938 && safi != SAFI_EVPN) {
6939 vty_out(vty,
6940 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6941 return CMD_WARNING_CONFIG_FAILED;
6942 }
6943 vty->node = bgp_node_type(AFI_IP, safi);
6944 } else
6945 vty->node = BGP_IPV4_NODE;
6946
6947 return CMD_SUCCESS;
6948 }
6949
6950 DEFUN_NOSH (address_family_ipv6_safi,
6951 address_family_ipv6_safi_cmd,
6952 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6953 "Enter Address Family command mode\n"
6954 "Address Family\n"
6955 BGP_SAFI_WITH_LABEL_HELP_STR)
6956 {
6957 if (argc == 3) {
6958 VTY_DECLVAR_CONTEXT(bgp, bgp);
6959 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6960 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6961 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6962 && safi != SAFI_EVPN) {
6963 vty_out(vty,
6964 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6965 return CMD_WARNING_CONFIG_FAILED;
6966 }
6967 vty->node = bgp_node_type(AFI_IP6, safi);
6968 } else
6969 vty->node = BGP_IPV6_NODE;
6970
6971 return CMD_SUCCESS;
6972 }
6973
6974 #ifdef KEEP_OLD_VPN_COMMANDS
6975 DEFUN_NOSH (address_family_vpnv4,
6976 address_family_vpnv4_cmd,
6977 "address-family vpnv4 [unicast]",
6978 "Enter Address Family command mode\n"
6979 "Address Family\n"
6980 "Address Family modifier\n")
6981 {
6982 vty->node = BGP_VPNV4_NODE;
6983 return CMD_SUCCESS;
6984 }
6985
6986 DEFUN_NOSH (address_family_vpnv6,
6987 address_family_vpnv6_cmd,
6988 "address-family vpnv6 [unicast]",
6989 "Enter Address Family command mode\n"
6990 "Address Family\n"
6991 "Address Family modifier\n")
6992 {
6993 vty->node = BGP_VPNV6_NODE;
6994 return CMD_SUCCESS;
6995 }
6996 #endif
6997
6998 DEFUN_NOSH (address_family_evpn,
6999 address_family_evpn_cmd,
7000 "address-family l2vpn evpn",
7001 "Enter Address Family command mode\n"
7002 "Address Family\n"
7003 "Address Family modifier\n")
7004 {
7005 VTY_DECLVAR_CONTEXT(bgp, bgp);
7006 vty->node = BGP_EVPN_NODE;
7007 return CMD_SUCCESS;
7008 }
7009
7010 DEFUN_NOSH (exit_address_family,
7011 exit_address_family_cmd,
7012 "exit-address-family",
7013 "Exit from Address Family configuration mode\n")
7014 {
7015 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7016 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7017 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7018 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7019 || vty->node == BGP_EVPN_NODE
7020 || vty->node == BGP_FLOWSPECV4_NODE
7021 || vty->node == BGP_FLOWSPECV6_NODE)
7022 vty->node = BGP_NODE;
7023 return CMD_SUCCESS;
7024 }
7025
7026 /* Recalculate bestpath and re-advertise a prefix */
7027 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7028 const char *ip_str, afi_t afi, safi_t safi,
7029 struct prefix_rd *prd)
7030 {
7031 int ret;
7032 struct prefix match;
7033 struct bgp_node *rn;
7034 struct bgp_node *rm;
7035 struct bgp *bgp;
7036 struct bgp_table *table;
7037 struct bgp_table *rib;
7038
7039 /* BGP structure lookup. */
7040 if (view_name) {
7041 bgp = bgp_lookup_by_name(view_name);
7042 if (bgp == NULL) {
7043 vty_out(vty, "%% Can't find BGP instance %s\n",
7044 view_name);
7045 return CMD_WARNING;
7046 }
7047 } else {
7048 bgp = bgp_get_default();
7049 if (bgp == NULL) {
7050 vty_out(vty, "%% No BGP process is configured\n");
7051 return CMD_WARNING;
7052 }
7053 }
7054
7055 /* Check IP address argument. */
7056 ret = str2prefix(ip_str, &match);
7057 if (!ret) {
7058 vty_out(vty, "%% address is malformed\n");
7059 return CMD_WARNING;
7060 }
7061
7062 match.family = afi2family(afi);
7063 rib = bgp->rib[afi][safi];
7064
7065 if (safi == SAFI_MPLS_VPN) {
7066 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7067 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7068 continue;
7069
7070 if ((table = rn->info) != NULL) {
7071 if ((rm = bgp_node_match(table, &match))
7072 != NULL) {
7073 if (rm->p.prefixlen
7074 == match.prefixlen) {
7075 SET_FLAG(rm->flags,
7076 BGP_NODE_USER_CLEAR);
7077 bgp_process(bgp, rm, afi, safi);
7078 }
7079 bgp_unlock_node(rm);
7080 }
7081 }
7082 }
7083 } else {
7084 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7085 if (rn->p.prefixlen == match.prefixlen) {
7086 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7087 bgp_process(bgp, rn, afi, safi);
7088 }
7089 bgp_unlock_node(rn);
7090 }
7091 }
7092
7093 return CMD_SUCCESS;
7094 }
7095
7096 /* one clear bgp command to rule them all */
7097 DEFUN (clear_ip_bgp_all,
7098 clear_ip_bgp_all_cmd,
7099 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
7100 CLEAR_STR
7101 IP_STR
7102 BGP_STR
7103 BGP_INSTANCE_HELP_STR
7104 BGP_AFI_HELP_STR
7105 BGP_SAFI_WITH_LABEL_HELP_STR
7106 "Clear all peers\n"
7107 "BGP neighbor address to clear\n"
7108 "BGP IPv6 neighbor to clear\n"
7109 "BGP neighbor on interface to clear\n"
7110 "Clear peers with the AS number\n"
7111 "Clear all external peers\n"
7112 "Clear all members of peer-group\n"
7113 "BGP peer-group name\n"
7114 BGP_SOFT_STR
7115 BGP_SOFT_IN_STR
7116 BGP_SOFT_OUT_STR
7117 BGP_SOFT_IN_STR
7118 "Push out prefix-list ORF and do inbound soft reconfig\n"
7119 BGP_SOFT_OUT_STR)
7120 {
7121 char *vrf = NULL;
7122
7123 afi_t afi = AFI_IP6;
7124 safi_t safi = SAFI_UNICAST;
7125 enum clear_sort clr_sort = clear_peer;
7126 enum bgp_clear_type clr_type;
7127 char *clr_arg = NULL;
7128
7129 int idx = 0;
7130
7131 /* clear [ip] bgp */
7132 if (argv_find(argv, argc, "ip", &idx))
7133 afi = AFI_IP;
7134
7135 /* [<view|vrf> VIEWVRFNAME] */
7136 if (argv_find(argv, argc, "view", &idx)
7137 || argv_find(argv, argc, "vrf", &idx)) {
7138 vrf = argv[idx + 1]->arg;
7139 idx += 2;
7140 }
7141
7142 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7143 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7144 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7145
7146 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7147 if (argv_find(argv, argc, "*", &idx)) {
7148 clr_sort = clear_all;
7149 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7150 clr_sort = clear_peer;
7151 clr_arg = argv[idx]->arg;
7152 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7153 clr_sort = clear_peer;
7154 clr_arg = argv[idx]->arg;
7155 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7156 clr_sort = clear_group;
7157 idx++;
7158 clr_arg = argv[idx]->arg;
7159 } else if (argv_find(argv, argc, "WORD", &idx)) {
7160 clr_sort = clear_peer;
7161 clr_arg = argv[idx]->arg;
7162 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7163 clr_sort = clear_as;
7164 clr_arg = argv[idx]->arg;
7165 } else if (argv_find(argv, argc, "external", &idx)) {
7166 clr_sort = clear_external;
7167 }
7168
7169 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7170 if (argv_find(argv, argc, "soft", &idx)) {
7171 if (argv_find(argv, argc, "in", &idx)
7172 || argv_find(argv, argc, "out", &idx))
7173 clr_type = strmatch(argv[idx]->text, "in")
7174 ? BGP_CLEAR_SOFT_IN
7175 : BGP_CLEAR_SOFT_OUT;
7176 else
7177 clr_type = BGP_CLEAR_SOFT_BOTH;
7178 } else if (argv_find(argv, argc, "in", &idx)) {
7179 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7180 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7181 : BGP_CLEAR_SOFT_IN;
7182 } else if (argv_find(argv, argc, "out", &idx)) {
7183 clr_type = BGP_CLEAR_SOFT_OUT;
7184 } else
7185 clr_type = BGP_CLEAR_SOFT_NONE;
7186
7187 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7188 }
7189
7190 DEFUN (clear_ip_bgp_prefix,
7191 clear_ip_bgp_prefix_cmd,
7192 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7193 CLEAR_STR
7194 IP_STR
7195 BGP_STR
7196 BGP_INSTANCE_HELP_STR
7197 "Clear bestpath and re-advertise\n"
7198 "IPv4 prefix\n")
7199 {
7200 char *vrf = NULL;
7201 char *prefix = NULL;
7202
7203 int idx = 0;
7204
7205 /* [<view|vrf> VIEWVRFNAME] */
7206 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
7207 vrf = argv[idx]->arg;
7208
7209 prefix = argv[argc - 1]->arg;
7210
7211 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7212 }
7213
7214 DEFUN (clear_bgp_ipv6_safi_prefix,
7215 clear_bgp_ipv6_safi_prefix_cmd,
7216 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7217 CLEAR_STR
7218 IP_STR
7219 BGP_STR
7220 "Address Family\n"
7221 BGP_SAFI_HELP_STR
7222 "Clear bestpath and re-advertise\n"
7223 "IPv6 prefix\n")
7224 {
7225 int idx_safi = 0;
7226 int idx_ipv6_prefix = 0;
7227 safi_t safi = SAFI_UNICAST;
7228 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7229 argv[idx_ipv6_prefix]->arg : NULL;
7230
7231 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7232 return bgp_clear_prefix(
7233 vty, NULL, prefix, AFI_IP6,
7234 safi, NULL);
7235 }
7236
7237 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7238 clear_bgp_instance_ipv6_safi_prefix_cmd,
7239 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7240 CLEAR_STR
7241 IP_STR
7242 BGP_STR
7243 BGP_INSTANCE_HELP_STR
7244 "Address Family\n"
7245 BGP_SAFI_HELP_STR
7246 "Clear bestpath and re-advertise\n"
7247 "IPv6 prefix\n")
7248 {
7249 int idx_word = 3;
7250 int idx_safi = 0;
7251 int idx_ipv6_prefix = 0;
7252 safi_t safi = SAFI_UNICAST;
7253 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7254 argv[idx_ipv6_prefix]->arg : NULL;
7255 /* [<view|vrf> VIEWVRFNAME] */
7256 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7257 argv[idx_word]->arg : NULL;
7258
7259 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7260
7261 return bgp_clear_prefix(
7262 vty, vrfview, prefix,
7263 AFI_IP6, safi, NULL);
7264 }
7265
7266 DEFUN (show_bgp_views,
7267 show_bgp_views_cmd,
7268 "show [ip] bgp views",
7269 SHOW_STR
7270 IP_STR
7271 BGP_STR
7272 "Show the defined BGP views\n")
7273 {
7274 struct list *inst = bm->bgp;
7275 struct listnode *node;
7276 struct bgp *bgp;
7277
7278 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7279 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7280 return CMD_WARNING;
7281 }
7282
7283 vty_out(vty, "Defined BGP views:\n");
7284 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7285 /* Skip VRFs. */
7286 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7287 continue;
7288 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7289 bgp->as);
7290 }
7291
7292 return CMD_SUCCESS;
7293 }
7294
7295 DEFUN (show_bgp_vrfs,
7296 show_bgp_vrfs_cmd,
7297 "show [ip] bgp vrfs [json]",
7298 SHOW_STR
7299 IP_STR
7300 BGP_STR
7301 "Show BGP VRFs\n"
7302 JSON_STR)
7303 {
7304 char buf[ETHER_ADDR_STRLEN];
7305 struct list *inst = bm->bgp;
7306 struct listnode *node;
7307 struct bgp *bgp;
7308 uint8_t uj = use_json(argc, argv);
7309 json_object *json = NULL;
7310 json_object *json_vrfs = NULL;
7311 int count = 0;
7312
7313 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7314 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7315 return CMD_WARNING;
7316 }
7317
7318 if (uj) {
7319 json = json_object_new_object();
7320 json_vrfs = json_object_new_object();
7321 }
7322
7323 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7324 const char *name, *type;
7325 struct peer *peer;
7326 struct listnode *node, *nnode;
7327 int peers_cfg, peers_estb;
7328 json_object *json_vrf = NULL;
7329
7330 /* Skip Views. */
7331 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7332 continue;
7333
7334 count++;
7335 if (!uj && count == 1)
7336 vty_out(vty,
7337 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7338 "Type", "Id", "routerId", "#PeersVfg",
7339 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7340
7341 peers_cfg = peers_estb = 0;
7342 if (uj)
7343 json_vrf = json_object_new_object();
7344
7345
7346 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7347 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7348 continue;
7349 peers_cfg++;
7350 if (peer->status == Established)
7351 peers_estb++;
7352 }
7353
7354 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7355 name = "Default";
7356 type = "DFLT";
7357 } else {
7358 name = bgp->name;
7359 type = "VRF";
7360 }
7361
7362
7363 if (uj) {
7364 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7365 ? -1
7366 : (int64_t)bgp->vrf_id;
7367 json_object_string_add(json_vrf, "type", type);
7368 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7369 json_object_string_add(json_vrf, "routerId",
7370 inet_ntoa(bgp->router_id));
7371 json_object_int_add(json_vrf, "numConfiguredPeers",
7372 peers_cfg);
7373 json_object_int_add(json_vrf, "numEstablishedPeers",
7374 peers_estb);
7375
7376 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7377 json_object_string_add(
7378 json_vrf, "rmac",
7379 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7380 json_object_object_add(json_vrfs, name, json_vrf);
7381 } else
7382 vty_out(vty,
7383 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7384 type,
7385 bgp->vrf_id == VRF_UNKNOWN ? -1
7386 : (int)bgp->vrf_id,
7387 inet_ntoa(bgp->router_id), peers_cfg,
7388 peers_estb, name, bgp->l3vni,
7389 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7390 }
7391
7392 if (uj) {
7393 json_object_object_add(json, "vrfs", json_vrfs);
7394
7395 json_object_int_add(json, "totalVrfs", count);
7396
7397 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7398 json, JSON_C_TO_STRING_PRETTY));
7399 json_object_free(json);
7400 } else {
7401 if (count)
7402 vty_out(vty,
7403 "\nTotal number of VRFs (including default): %d\n",
7404 count);
7405 }
7406
7407 return CMD_SUCCESS;
7408 }
7409
7410 static void show_address_entry(struct hash_backet *backet, void *args)
7411 {
7412 struct vty *vty = (struct vty *)args;
7413 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7414
7415 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7416 addr->refcnt);
7417 }
7418
7419 static void show_tip_entry(struct hash_backet *backet, void *args)
7420 {
7421 struct vty *vty = (struct vty *)args;
7422 struct tip_addr *tip = (struct tip_addr *)backet->data;
7423
7424 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7425 tip->refcnt);
7426 }
7427
7428 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7429 {
7430 vty_out(vty, "self nexthop database:\n");
7431 hash_iterate(bgp->address_hash,
7432 (void (*)(struct hash_backet *, void *))show_address_entry,
7433 vty);
7434
7435 vty_out(vty, "Tunnel-ip database:\n");
7436 hash_iterate(bgp->tip_hash,
7437 (void (*)(struct hash_backet *, void *))show_tip_entry,
7438 vty);
7439 }
7440
7441 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7442 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7443 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7444 "martian next-hops\n"
7445 "martian next-hop database\n")
7446 {
7447 struct bgp *bgp = NULL;
7448 int idx = 0;
7449
7450 if (argv_find(argv, argc, "view", &idx)
7451 || argv_find(argv, argc, "vrf", &idx))
7452 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7453 else
7454 bgp = bgp_get_default();
7455
7456 if (!bgp) {
7457 vty_out(vty, "%% No BGP process is configured\n");
7458 return CMD_WARNING;
7459 }
7460 bgp_show_martian_nexthops(vty, bgp);
7461
7462 return CMD_SUCCESS;
7463 }
7464
7465 DEFUN (show_bgp_memory,
7466 show_bgp_memory_cmd,
7467 "show [ip] bgp memory",
7468 SHOW_STR
7469 IP_STR
7470 BGP_STR
7471 "Global BGP memory statistics\n")
7472 {
7473 char memstrbuf[MTYPE_MEMSTR_LEN];
7474 unsigned long count;
7475
7476 /* RIB related usage stats */
7477 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7478 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7479 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7480 count * sizeof(struct bgp_node)));
7481
7482 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7483 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7484 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7485 count * sizeof(struct bgp_info)));
7486 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7487 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7488 count,
7489 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7490 count * sizeof(struct bgp_info_extra)));
7491
7492 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7493 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7494 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7495 count * sizeof(struct bgp_static)));
7496
7497 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7498 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7499 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7500 count * sizeof(struct bpacket)));
7501
7502 /* Adj-In/Out */
7503 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7504 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7505 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7506 count * sizeof(struct bgp_adj_in)));
7507 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7508 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7509 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7510 count * sizeof(struct bgp_adj_out)));
7511
7512 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7513 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7514 count,
7515 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7516 count * sizeof(struct bgp_nexthop_cache)));
7517
7518 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7519 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7520 count,
7521 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7522 count * sizeof(struct bgp_damp_info)));
7523
7524 /* Attributes */
7525 count = attr_count();
7526 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7527 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7528 count * sizeof(struct attr)));
7529
7530 if ((count = attr_unknown_count()))
7531 vty_out(vty, "%ld unknown attributes\n", count);
7532
7533 /* AS_PATH attributes */
7534 count = aspath_count();
7535 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7536 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7537 count * sizeof(struct aspath)));
7538
7539 count = mtype_stats_alloc(MTYPE_AS_SEG);
7540 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7541 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7542 count * sizeof(struct assegment)));
7543
7544 /* Other attributes */
7545 if ((count = community_count()))
7546 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7547 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7548 count * sizeof(struct community)));
7549 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7550 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7551 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7552 count * sizeof(struct ecommunity)));
7553 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7554 vty_out(vty,
7555 "%ld BGP large-community entries, using %s of memory\n",
7556 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7557 count * sizeof(struct lcommunity)));
7558
7559 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7560 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7561 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7562 count * sizeof(struct cluster_list)));
7563
7564 /* Peer related usage */
7565 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7566 vty_out(vty, "%ld peers, using %s of memory\n", count,
7567 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7568 count * sizeof(struct peer)));
7569
7570 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7571 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7572 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7573 count * sizeof(struct peer_group)));
7574
7575 /* Other */
7576 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7577 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7578 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7579 count * sizeof(struct hash)));
7580 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7581 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7582 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7583 count * sizeof(struct hash_backet)));
7584 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7585 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7586 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7587 count * sizeof(regex_t)));
7588 return CMD_SUCCESS;
7589 }
7590
7591 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7592 {
7593 json_object *bestpath = json_object_new_object();
7594
7595 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7596 json_object_string_add(bestpath, "asPath", "ignore");
7597
7598 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7599 json_object_string_add(bestpath, "asPath", "confed");
7600
7601 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7602 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7603 json_object_string_add(bestpath, "multiPathRelax",
7604 "as-set");
7605 else
7606 json_object_string_add(bestpath, "multiPathRelax",
7607 "true");
7608 } else
7609 json_object_string_add(bestpath, "multiPathRelax", "false");
7610
7611 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7612 json_object_string_add(bestpath, "compareRouterId", "true");
7613 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7614 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7615 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7616 json_object_string_add(bestpath, "med", "confed");
7617 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7618 json_object_string_add(bestpath, "med",
7619 "missing-as-worst");
7620 else
7621 json_object_string_add(bestpath, "med", "true");
7622 }
7623
7624 json_object_object_add(json, "bestPath", bestpath);
7625 }
7626
7627 /* Show BGP peer's summary information. */
7628 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7629 uint8_t use_json, json_object *json)
7630 {
7631 struct peer *peer;
7632 struct listnode *node, *nnode;
7633 unsigned int count = 0, dn_count = 0;
7634 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7635 char neighbor_buf[VTY_BUFSIZ];
7636 int neighbor_col_default_width = 16;
7637 int len;
7638 int max_neighbor_width = 0;
7639 int pfx_rcd_safi;
7640 json_object *json_peer = NULL;
7641 json_object *json_peers = NULL;
7642
7643 /* labeled-unicast routes are installed in the unicast table so in order
7644 * to
7645 * display the correct PfxRcd value we must look at SAFI_UNICAST
7646 */
7647 if (safi == SAFI_LABELED_UNICAST)
7648 pfx_rcd_safi = SAFI_UNICAST;
7649 else
7650 pfx_rcd_safi = safi;
7651
7652 if (use_json) {
7653 if (json == NULL)
7654 json = json_object_new_object();
7655
7656 json_peers = json_object_new_object();
7657 } else {
7658 /* Loop over all neighbors that will be displayed to determine
7659 * how many
7660 * characters are needed for the Neighbor column
7661 */
7662 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7663 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7664 continue;
7665
7666 if (peer->afc[afi][safi]) {
7667 memset(dn_flag, '\0', sizeof(dn_flag));
7668 if (peer_dynamic_neighbor(peer))
7669 dn_flag[0] = '*';
7670
7671 if (peer->hostname
7672 && bgp_flag_check(bgp,
7673 BGP_FLAG_SHOW_HOSTNAME))
7674 sprintf(neighbor_buf, "%s%s(%s) ",
7675 dn_flag, peer->hostname,
7676 peer->host);
7677 else
7678 sprintf(neighbor_buf, "%s%s ", dn_flag,
7679 peer->host);
7680
7681 len = strlen(neighbor_buf);
7682
7683 if (len > max_neighbor_width)
7684 max_neighbor_width = len;
7685 }
7686 }
7687
7688 /* Originally we displayed the Neighbor column as 16
7689 * characters wide so make that the default
7690 */
7691 if (max_neighbor_width < neighbor_col_default_width)
7692 max_neighbor_width = neighbor_col_default_width;
7693 }
7694
7695 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7696 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7697 continue;
7698
7699 if (!peer->afc[afi][safi])
7700 continue;
7701
7702 if (!count) {
7703 unsigned long ents;
7704 char memstrbuf[MTYPE_MEMSTR_LEN];
7705 int64_t vrf_id_ui;
7706
7707 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7708 ? -1
7709 : (int64_t)bgp->vrf_id;
7710
7711 /* Usage summary and header */
7712 if (use_json) {
7713 json_object_string_add(
7714 json, "routerId",
7715 inet_ntoa(bgp->router_id));
7716 json_object_int_add(json, "as", bgp->as);
7717 json_object_int_add(json, "vrfId", vrf_id_ui);
7718 json_object_string_add(
7719 json, "vrfName",
7720 (bgp->inst_type
7721 == BGP_INSTANCE_TYPE_DEFAULT)
7722 ? "Default"
7723 : bgp->name);
7724 } else {
7725 vty_out(vty,
7726 "BGP router identifier %s, local AS number %u vrf-id %d",
7727 inet_ntoa(bgp->router_id), bgp->as,
7728 bgp->vrf_id == VRF_UNKNOWN
7729 ? -1
7730 : (int)bgp->vrf_id);
7731 vty_out(vty, "\n");
7732 }
7733
7734 if (bgp_update_delay_configured(bgp)) {
7735 if (use_json) {
7736 json_object_int_add(
7737 json, "updateDelayLimit",
7738 bgp->v_update_delay);
7739
7740 if (bgp->v_update_delay
7741 != bgp->v_establish_wait)
7742 json_object_int_add(
7743 json,
7744 "updateDelayEstablishWait",
7745 bgp->v_establish_wait);
7746
7747 if (bgp_update_delay_active(bgp)) {
7748 json_object_string_add(
7749 json,
7750 "updateDelayFirstNeighbor",
7751 bgp->update_delay_begin_time);
7752 json_object_boolean_true_add(
7753 json,
7754 "updateDelayInProgress");
7755 } else {
7756 if (bgp->update_delay_over) {
7757 json_object_string_add(
7758 json,
7759 "updateDelayFirstNeighbor",
7760 bgp->update_delay_begin_time);
7761 json_object_string_add(
7762 json,
7763 "updateDelayBestpathResumed",
7764 bgp->update_delay_end_time);
7765 json_object_string_add(
7766 json,
7767 "updateDelayZebraUpdateResume",
7768 bgp->update_delay_zebra_resume_time);
7769 json_object_string_add(
7770 json,
7771 "updateDelayPeerUpdateResume",
7772 bgp->update_delay_peers_resume_time);
7773 }
7774 }
7775 } else {
7776 vty_out(vty,
7777 "Read-only mode update-delay limit: %d seconds\n",
7778 bgp->v_update_delay);
7779 if (bgp->v_update_delay
7780 != bgp->v_establish_wait)
7781 vty_out(vty,
7782 " Establish wait: %d seconds\n",
7783 bgp->v_establish_wait);
7784
7785 if (bgp_update_delay_active(bgp)) {
7786 vty_out(vty,
7787 " First neighbor established: %s\n",
7788 bgp->update_delay_begin_time);
7789 vty_out(vty,
7790 " Delay in progress\n");
7791 } else {
7792 if (bgp->update_delay_over) {
7793 vty_out(vty,
7794 " First neighbor established: %s\n",
7795 bgp->update_delay_begin_time);
7796 vty_out(vty,
7797 " Best-paths resumed: %s\n",
7798 bgp->update_delay_end_time);
7799 vty_out(vty,
7800 " zebra update resumed: %s\n",
7801 bgp->update_delay_zebra_resume_time);
7802 vty_out(vty,
7803 " peers update resumed: %s\n",
7804 bgp->update_delay_peers_resume_time);
7805 }
7806 }
7807 }
7808 }
7809
7810 if (use_json) {
7811 if (bgp_maxmed_onstartup_configured(bgp)
7812 && bgp->maxmed_active)
7813 json_object_boolean_true_add(
7814 json, "maxMedOnStartup");
7815 if (bgp->v_maxmed_admin)
7816 json_object_boolean_true_add(
7817 json, "maxMedAdministrative");
7818
7819 json_object_int_add(
7820 json, "tableVersion",
7821 bgp_table_version(bgp->rib[afi][safi]));
7822
7823 ents = bgp_table_count(bgp->rib[afi][safi]);
7824 json_object_int_add(json, "ribCount", ents);
7825 json_object_int_add(
7826 json, "ribMemory",
7827 ents * sizeof(struct bgp_node));
7828
7829 ents = listcount(bgp->peer);
7830 json_object_int_add(json, "peerCount", ents);
7831 json_object_int_add(json, "peerMemory",
7832 ents * sizeof(struct peer));
7833
7834 if ((ents = listcount(bgp->group))) {
7835 json_object_int_add(
7836 json, "peerGroupCount", ents);
7837 json_object_int_add(
7838 json, "peerGroupMemory",
7839 ents * sizeof(struct
7840 peer_group));
7841 }
7842
7843 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7844 BGP_CONFIG_DAMPENING))
7845 json_object_boolean_true_add(
7846 json, "dampeningEnabled");
7847 } else {
7848 if (bgp_maxmed_onstartup_configured(bgp)
7849 && bgp->maxmed_active)
7850 vty_out(vty,
7851 "Max-med on-startup active\n");
7852 if (bgp->v_maxmed_admin)
7853 vty_out(vty,
7854 "Max-med administrative active\n");
7855
7856 vty_out(vty, "BGP table version %" PRIu64 "\n",
7857 bgp_table_version(bgp->rib[afi][safi]));
7858
7859 ents = bgp_table_count(bgp->rib[afi][safi]);
7860 vty_out(vty,
7861 "RIB entries %ld, using %s of memory\n",
7862 ents,
7863 mtype_memstr(memstrbuf,
7864 sizeof(memstrbuf),
7865 ents * sizeof(struct
7866 bgp_node)));
7867
7868 /* Peer related usage */
7869 ents = listcount(bgp->peer);
7870 vty_out(vty, "Peers %ld, using %s of memory\n",
7871 ents,
7872 mtype_memstr(
7873 memstrbuf, sizeof(memstrbuf),
7874 ents * sizeof(struct peer)));
7875
7876 if ((ents = listcount(bgp->group)))
7877 vty_out(vty,
7878 "Peer groups %ld, using %s of memory\n",
7879 ents,
7880 mtype_memstr(
7881 memstrbuf,
7882 sizeof(memstrbuf),
7883 ents * sizeof(struct
7884 peer_group)));
7885
7886 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7887 BGP_CONFIG_DAMPENING))
7888 vty_out(vty, "Dampening enabled.\n");
7889 vty_out(vty, "\n");
7890
7891 /* Subtract 8 here because 'Neighbor' is
7892 * 8 characters */
7893 vty_out(vty, "Neighbor");
7894 vty_out(vty, "%*s", max_neighbor_width - 8,
7895 " ");
7896 vty_out(vty,
7897 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7898 }
7899 }
7900
7901 count++;
7902
7903 if (use_json) {
7904 json_peer = json_object_new_object();
7905
7906 if (peer_dynamic_neighbor(peer))
7907 json_object_boolean_true_add(json_peer,
7908 "dynamicPeer");
7909
7910 if (peer->hostname)
7911 json_object_string_add(json_peer, "hostname",
7912 peer->hostname);
7913
7914 if (peer->domainname)
7915 json_object_string_add(json_peer, "domainname",
7916 peer->domainname);
7917
7918 json_object_int_add(json_peer, "remoteAs", peer->as);
7919 json_object_int_add(json_peer, "version", 4);
7920 json_object_int_add(json_peer, "msgRcvd",
7921 PEER_TOTAL_RX(peer));
7922 json_object_int_add(json_peer, "msgSent",
7923 PEER_TOTAL_TX(peer));
7924
7925 json_object_int_add(json_peer, "tableVersion",
7926 peer->version[afi][safi]);
7927 json_object_int_add(json_peer, "outq",
7928 peer->obuf->count);
7929 json_object_int_add(json_peer, "inq", 0);
7930 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7931 use_json, json_peer);
7932 json_object_int_add(json_peer, "prefixReceivedCount",
7933 peer->pcount[afi][pfx_rcd_safi]);
7934
7935 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7936 json_object_string_add(json_peer, "state",
7937 "Idle (Admin)");
7938 else if (peer->afc_recv[afi][safi])
7939 json_object_string_add(
7940 json_peer, "state",
7941 lookup_msg(bgp_status_msg, peer->status,
7942 NULL));
7943 else if (CHECK_FLAG(peer->sflags,
7944 PEER_STATUS_PREFIX_OVERFLOW))
7945 json_object_string_add(json_peer, "state",
7946 "Idle (PfxCt)");
7947 else
7948 json_object_string_add(
7949 json_peer, "state",
7950 lookup_msg(bgp_status_msg, peer->status,
7951 NULL));
7952
7953 if (peer->conf_if)
7954 json_object_string_add(json_peer, "idType",
7955 "interface");
7956 else if (peer->su.sa.sa_family == AF_INET)
7957 json_object_string_add(json_peer, "idType",
7958 "ipv4");
7959 else if (peer->su.sa.sa_family == AF_INET6)
7960 json_object_string_add(json_peer, "idType",
7961 "ipv6");
7962
7963 json_object_object_add(json_peers, peer->host,
7964 json_peer);
7965 } else {
7966 memset(dn_flag, '\0', sizeof(dn_flag));
7967 if (peer_dynamic_neighbor(peer)) {
7968 dn_count++;
7969 dn_flag[0] = '*';
7970 }
7971
7972 if (peer->hostname
7973 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7974 len = vty_out(vty, "%s%s(%s)", dn_flag,
7975 peer->hostname, peer->host);
7976 else
7977 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7978
7979 /* pad the neighbor column with spaces */
7980 if (len < max_neighbor_width)
7981 vty_out(vty, "%*s", max_neighbor_width - len,
7982 " ");
7983
7984 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7985 peer->as, PEER_TOTAL_RX(peer),
7986 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7987 0, peer->obuf->count,
7988 peer_uptime(peer->uptime, timebuf,
7989 BGP_UPTIME_LEN, 0, NULL));
7990
7991 if (peer->status == Established)
7992 if (peer->afc_recv[afi][safi])
7993 vty_out(vty, " %12ld",
7994 peer->pcount[afi]
7995 [pfx_rcd_safi]);
7996 else
7997 vty_out(vty, " NoNeg");
7998 else {
7999 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8000 vty_out(vty, " Idle (Admin)");
8001 else if (CHECK_FLAG(
8002 peer->sflags,
8003 PEER_STATUS_PREFIX_OVERFLOW))
8004 vty_out(vty, " Idle (PfxCt)");
8005 else
8006 vty_out(vty, " %12s",
8007 lookup_msg(bgp_status_msg,
8008 peer->status, NULL));
8009 }
8010 vty_out(vty, "\n");
8011 }
8012 }
8013
8014 if (use_json) {
8015 json_object_object_add(json, "peers", json_peers);
8016
8017 json_object_int_add(json, "totalPeers", count);
8018 json_object_int_add(json, "dynamicPeers", dn_count);
8019
8020 bgp_show_bestpath_json(bgp, json);
8021
8022 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8023 json, JSON_C_TO_STRING_PRETTY));
8024 json_object_free(json);
8025 } else {
8026 if (count)
8027 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8028 else {
8029 vty_out(vty, "No %s neighbor is configured\n",
8030 afi_safi_print(afi, safi));
8031 }
8032
8033 if (dn_count) {
8034 vty_out(vty, "* - dynamic neighbor\n");
8035 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8036 dn_count, bgp->dynamic_neighbors_limit);
8037 }
8038 }
8039
8040 return CMD_SUCCESS;
8041 }
8042
8043 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8044 int safi, uint8_t use_json,
8045 json_object *json)
8046 {
8047 int is_first = 1;
8048 int afi_wildcard = (afi == AFI_MAX);
8049 int safi_wildcard = (safi == SAFI_MAX);
8050 int is_wildcard = (afi_wildcard || safi_wildcard);
8051 bool json_output = false;
8052
8053 if (use_json && is_wildcard)
8054 vty_out(vty, "{\n");
8055 if (afi_wildcard)
8056 afi = 1; /* AFI_IP */
8057 while (afi < AFI_MAX) {
8058 if (safi_wildcard)
8059 safi = 1; /* SAFI_UNICAST */
8060 while (safi < SAFI_MAX) {
8061 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8062 json_output = true;
8063 if (is_wildcard) {
8064 /*
8065 * So limit output to those afi/safi
8066 * pairs that
8067 * actualy have something interesting in
8068 * them
8069 */
8070 if (use_json) {
8071 json = json_object_new_object();
8072
8073 if (!is_first)
8074 vty_out(vty, ",\n");
8075 else
8076 is_first = 0;
8077
8078 vty_out(vty, "\"%s\":",
8079 afi_safi_json(afi,
8080 safi));
8081 } else {
8082 vty_out(vty, "\n%s Summary:\n",
8083 afi_safi_print(afi,
8084 safi));
8085 }
8086 }
8087 bgp_show_summary(vty, bgp, afi, safi, use_json,
8088 json);
8089 }
8090 safi++;
8091 if (!safi_wildcard)
8092 safi = SAFI_MAX;
8093 }
8094 afi++;
8095 if (!afi_wildcard)
8096 afi = AFI_MAX;
8097 }
8098
8099 if (use_json && is_wildcard)
8100 vty_out(vty, "}\n");
8101 else if (use_json && !json_output)
8102 vty_out(vty, "{}\n");
8103 }
8104
8105 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8106 safi_t safi, uint8_t use_json)
8107 {
8108 struct listnode *node, *nnode;
8109 struct bgp *bgp;
8110 json_object *json = NULL;
8111 int is_first = 1;
8112
8113 if (use_json)
8114 vty_out(vty, "{\n");
8115
8116 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8117 if (use_json) {
8118 json = json_object_new_object();
8119
8120 if (!is_first)
8121 vty_out(vty, ",\n");
8122 else
8123 is_first = 0;
8124
8125 vty_out(vty, "\"%s\":",
8126 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8127 ? "Default"
8128 : bgp->name);
8129 } else {
8130 vty_out(vty, "\nInstance %s:\n",
8131 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8132 ? "Default"
8133 : bgp->name);
8134 }
8135 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8136 }
8137
8138 if (use_json)
8139 vty_out(vty, "}\n");
8140 }
8141
8142 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8143 safi_t safi, uint8_t use_json)
8144 {
8145 struct bgp *bgp;
8146
8147 if (name) {
8148 if (strmatch(name, "all")) {
8149 bgp_show_all_instances_summary_vty(vty, afi, safi,
8150 use_json);
8151 return CMD_SUCCESS;
8152 } else {
8153 bgp = bgp_lookup_by_name(name);
8154
8155 if (!bgp) {
8156 if (use_json)
8157 vty_out(vty, "{}\n");
8158 else
8159 vty_out(vty,
8160 "%% No such BGP instance exist\n");
8161 return CMD_WARNING;
8162 }
8163
8164 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8165 NULL);
8166 return CMD_SUCCESS;
8167 }
8168 }
8169
8170 bgp = bgp_get_default();
8171
8172 if (bgp)
8173 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8174
8175 return CMD_SUCCESS;
8176 }
8177
8178 /* `show [ip] bgp summary' commands. */
8179 DEFUN (show_ip_bgp_summary,
8180 show_ip_bgp_summary_cmd,
8181 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8182 SHOW_STR
8183 IP_STR
8184 BGP_STR
8185 BGP_INSTANCE_HELP_STR
8186 BGP_AFI_HELP_STR
8187 BGP_SAFI_WITH_LABEL_HELP_STR
8188 "Summary of BGP neighbor status\n"
8189 JSON_STR)
8190 {
8191 char *vrf = NULL;
8192 afi_t afi = AFI_MAX;
8193 safi_t safi = SAFI_MAX;
8194
8195 int idx = 0;
8196
8197 /* show [ip] bgp */
8198 if (argv_find(argv, argc, "ip", &idx))
8199 afi = AFI_IP;
8200 /* [<view|vrf> VIEWVRFNAME] */
8201 if (argv_find(argv, argc, "view", &idx)
8202 || argv_find(argv, argc, "vrf", &idx))
8203 vrf = argv[++idx]->arg;
8204 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8205 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8206 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8207 }
8208
8209 int uj = use_json(argc, argv);
8210
8211 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8212 }
8213
8214 const char *afi_safi_print(afi_t afi, safi_t safi)
8215 {
8216 if (afi == AFI_IP && safi == SAFI_UNICAST)
8217 return "IPv4 Unicast";
8218 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8219 return "IPv4 Multicast";
8220 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8221 return "IPv4 Labeled Unicast";
8222 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8223 return "IPv4 VPN";
8224 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8225 return "IPv4 Encap";
8226 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8227 return "IPv4 Flowspec";
8228 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8229 return "IPv6 Unicast";
8230 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8231 return "IPv6 Multicast";
8232 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8233 return "IPv6 Labeled Unicast";
8234 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8235 return "IPv6 VPN";
8236 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8237 return "IPv6 Encap";
8238 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8239 return "IPv6 Flowspec";
8240 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8241 return "L2VPN EVPN";
8242 else
8243 return "Unknown";
8244 }
8245
8246 /*
8247 * Please note that we have intentionally camelCased
8248 * the return strings here. So if you want
8249 * to use this function, please ensure you
8250 * are doing this within json output
8251 */
8252 const char *afi_safi_json(afi_t afi, safi_t safi)
8253 {
8254 if (afi == AFI_IP && safi == SAFI_UNICAST)
8255 return "ipv4Unicast";
8256 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8257 return "ipv4Multicast";
8258 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8259 return "ipv4LabeledUnicast";
8260 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8261 return "ipv4Vpn";
8262 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8263 return "ipv4Encap";
8264 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8265 return "ipv4Flowspec";
8266 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8267 return "ipv6Unicast";
8268 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8269 return "ipv6Multicast";
8270 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8271 return "ipv6LabeledUnicast";
8272 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8273 return "ipv6Vpn";
8274 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8275 return "ipv6Encap";
8276 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8277 return "ipv6Flowspec";
8278 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8279 return "l2VpnEvpn";
8280 else
8281 return "Unknown";
8282 }
8283
8284 /* Show BGP peer's information. */
8285 enum show_type { show_all, show_peer };
8286
8287 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8288 afi_t afi, safi_t safi,
8289 uint16_t adv_smcap, uint16_t adv_rmcap,
8290 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8291 uint8_t use_json, json_object *json_pref)
8292 {
8293 /* Send-Mode */
8294 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8295 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8296 if (use_json) {
8297 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8298 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8299 json_object_string_add(json_pref, "sendMode",
8300 "advertisedAndReceived");
8301 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8302 json_object_string_add(json_pref, "sendMode",
8303 "advertised");
8304 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8305 json_object_string_add(json_pref, "sendMode",
8306 "received");
8307 } else {
8308 vty_out(vty, " Send-mode: ");
8309 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8310 vty_out(vty, "advertised");
8311 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8312 vty_out(vty, "%sreceived",
8313 CHECK_FLAG(p->af_cap[afi][safi],
8314 adv_smcap)
8315 ? ", "
8316 : "");
8317 vty_out(vty, "\n");
8318 }
8319 }
8320
8321 /* Receive-Mode */
8322 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8323 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8324 if (use_json) {
8325 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8326 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8327 json_object_string_add(json_pref, "recvMode",
8328 "advertisedAndReceived");
8329 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8330 json_object_string_add(json_pref, "recvMode",
8331 "advertised");
8332 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8333 json_object_string_add(json_pref, "recvMode",
8334 "received");
8335 } else {
8336 vty_out(vty, " Receive-mode: ");
8337 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8338 vty_out(vty, "advertised");
8339 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8340 vty_out(vty, "%sreceived",
8341 CHECK_FLAG(p->af_cap[afi][safi],
8342 adv_rmcap)
8343 ? ", "
8344 : "");
8345 vty_out(vty, "\n");
8346 }
8347 }
8348 }
8349
8350 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8351 safi_t safi, uint8_t use_json,
8352 json_object *json_neigh)
8353 {
8354 struct bgp_filter *filter;
8355 struct peer_af *paf;
8356 char orf_pfx_name[BUFSIZ];
8357 int orf_pfx_count;
8358 json_object *json_af = NULL;
8359 json_object *json_prefA = NULL;
8360 json_object *json_prefB = NULL;
8361 json_object *json_addr = NULL;
8362
8363 if (use_json) {
8364 json_addr = json_object_new_object();
8365 json_af = json_object_new_object();
8366 filter = &p->filter[afi][safi];
8367
8368 if (peer_group_active(p))
8369 json_object_string_add(json_addr, "peerGroupMember",
8370 p->group->name);
8371
8372 paf = peer_af_find(p, afi, safi);
8373 if (paf && PAF_SUBGRP(paf)) {
8374 json_object_int_add(json_addr, "updateGroupId",
8375 PAF_UPDGRP(paf)->id);
8376 json_object_int_add(json_addr, "subGroupId",
8377 PAF_SUBGRP(paf)->id);
8378 json_object_int_add(json_addr, "packetQueueLength",
8379 bpacket_queue_virtual_length(paf));
8380 }
8381
8382 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8383 || CHECK_FLAG(p->af_cap[afi][safi],
8384 PEER_CAP_ORF_PREFIX_SM_RCV)
8385 || CHECK_FLAG(p->af_cap[afi][safi],
8386 PEER_CAP_ORF_PREFIX_RM_ADV)
8387 || CHECK_FLAG(p->af_cap[afi][safi],
8388 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8389 json_object_int_add(json_af, "orfType",
8390 ORF_TYPE_PREFIX);
8391 json_prefA = json_object_new_object();
8392 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8393 PEER_CAP_ORF_PREFIX_SM_ADV,
8394 PEER_CAP_ORF_PREFIX_RM_ADV,
8395 PEER_CAP_ORF_PREFIX_SM_RCV,
8396 PEER_CAP_ORF_PREFIX_RM_RCV,
8397 use_json, json_prefA);
8398 json_object_object_add(json_af, "orfPrefixList",
8399 json_prefA);
8400 }
8401
8402 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8403 || CHECK_FLAG(p->af_cap[afi][safi],
8404 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8405 || CHECK_FLAG(p->af_cap[afi][safi],
8406 PEER_CAP_ORF_PREFIX_RM_ADV)
8407 || CHECK_FLAG(p->af_cap[afi][safi],
8408 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8409 json_object_int_add(json_af, "orfOldType",
8410 ORF_TYPE_PREFIX_OLD);
8411 json_prefB = json_object_new_object();
8412 bgp_show_peer_afi_orf_cap(
8413 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8414 PEER_CAP_ORF_PREFIX_RM_ADV,
8415 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8416 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8417 json_prefB);
8418 json_object_object_add(json_af, "orfOldPrefixList",
8419 json_prefB);
8420 }
8421
8422 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8423 || CHECK_FLAG(p->af_cap[afi][safi],
8424 PEER_CAP_ORF_PREFIX_SM_RCV)
8425 || CHECK_FLAG(p->af_cap[afi][safi],
8426 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8427 || CHECK_FLAG(p->af_cap[afi][safi],
8428 PEER_CAP_ORF_PREFIX_RM_ADV)
8429 || CHECK_FLAG(p->af_cap[afi][safi],
8430 PEER_CAP_ORF_PREFIX_RM_RCV)
8431 || CHECK_FLAG(p->af_cap[afi][safi],
8432 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8433 json_object_object_add(json_addr, "afDependentCap",
8434 json_af);
8435 else
8436 json_object_free(json_af);
8437
8438 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8439 orf_pfx_count = prefix_bgp_show_prefix_list(
8440 NULL, afi, orf_pfx_name, use_json);
8441
8442 if (CHECK_FLAG(p->af_sflags[afi][safi],
8443 PEER_STATUS_ORF_PREFIX_SEND)
8444 || orf_pfx_count) {
8445 if (CHECK_FLAG(p->af_sflags[afi][safi],
8446 PEER_STATUS_ORF_PREFIX_SEND))
8447 json_object_boolean_true_add(json_neigh,
8448 "orfSent");
8449 if (orf_pfx_count)
8450 json_object_int_add(json_addr, "orfRecvCounter",
8451 orf_pfx_count);
8452 }
8453 if (CHECK_FLAG(p->af_sflags[afi][safi],
8454 PEER_STATUS_ORF_WAIT_REFRESH))
8455 json_object_string_add(
8456 json_addr, "orfFirstUpdate",
8457 "deferredUntilORFOrRouteRefreshRecvd");
8458
8459 if (CHECK_FLAG(p->af_flags[afi][safi],
8460 PEER_FLAG_REFLECTOR_CLIENT))
8461 json_object_boolean_true_add(json_addr,
8462 "routeReflectorClient");
8463 if (CHECK_FLAG(p->af_flags[afi][safi],
8464 PEER_FLAG_RSERVER_CLIENT))
8465 json_object_boolean_true_add(json_addr,
8466 "routeServerClient");
8467 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8468 json_object_boolean_true_add(json_addr,
8469 "inboundSoftConfigPermit");
8470
8471 if (CHECK_FLAG(p->af_flags[afi][safi],
8472 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8473 json_object_boolean_true_add(
8474 json_addr,
8475 "privateAsNumsAllReplacedInUpdatesToNbr");
8476 else if (CHECK_FLAG(p->af_flags[afi][safi],
8477 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8478 json_object_boolean_true_add(
8479 json_addr,
8480 "privateAsNumsReplacedInUpdatesToNbr");
8481 else if (CHECK_FLAG(p->af_flags[afi][safi],
8482 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8483 json_object_boolean_true_add(
8484 json_addr,
8485 "privateAsNumsAllRemovedInUpdatesToNbr");
8486 else if (CHECK_FLAG(p->af_flags[afi][safi],
8487 PEER_FLAG_REMOVE_PRIVATE_AS))
8488 json_object_boolean_true_add(
8489 json_addr,
8490 "privateAsNumsRemovedInUpdatesToNbr");
8491
8492 if (CHECK_FLAG(p->af_flags[afi][safi],
8493 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8494 json_object_boolean_true_add(json_addr,
8495 "addpathTxAllPaths");
8496
8497 if (CHECK_FLAG(p->af_flags[afi][safi],
8498 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8499 json_object_boolean_true_add(json_addr,
8500 "addpathTxBestpathPerAS");
8501
8502 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8503 json_object_string_add(json_addr,
8504 "overrideASNsInOutboundUpdates",
8505 "ifAspathEqualRemoteAs");
8506
8507 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8508 || CHECK_FLAG(p->af_flags[afi][safi],
8509 PEER_FLAG_FORCE_NEXTHOP_SELF))
8510 json_object_boolean_true_add(json_addr,
8511 "routerAlwaysNextHop");
8512 if (CHECK_FLAG(p->af_flags[afi][safi],
8513 PEER_FLAG_AS_PATH_UNCHANGED))
8514 json_object_boolean_true_add(
8515 json_addr, "unchangedAsPathPropogatedToNbr");
8516 if (CHECK_FLAG(p->af_flags[afi][safi],
8517 PEER_FLAG_NEXTHOP_UNCHANGED))
8518 json_object_boolean_true_add(
8519 json_addr, "unchangedNextHopPropogatedToNbr");
8520 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8521 json_object_boolean_true_add(
8522 json_addr, "unchangedMedPropogatedToNbr");
8523 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8524 || CHECK_FLAG(p->af_flags[afi][safi],
8525 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8526 if (CHECK_FLAG(p->af_flags[afi][safi],
8527 PEER_FLAG_SEND_COMMUNITY)
8528 && CHECK_FLAG(p->af_flags[afi][safi],
8529 PEER_FLAG_SEND_EXT_COMMUNITY))
8530 json_object_string_add(json_addr,
8531 "commAttriSentToNbr",
8532 "extendedAndStandard");
8533 else if (CHECK_FLAG(p->af_flags[afi][safi],
8534 PEER_FLAG_SEND_EXT_COMMUNITY))
8535 json_object_string_add(json_addr,
8536 "commAttriSentToNbr",
8537 "extended");
8538 else
8539 json_object_string_add(json_addr,
8540 "commAttriSentToNbr",
8541 "standard");
8542 }
8543 if (CHECK_FLAG(p->af_flags[afi][safi],
8544 PEER_FLAG_DEFAULT_ORIGINATE)) {
8545 if (p->default_rmap[afi][safi].name)
8546 json_object_string_add(
8547 json_addr, "defaultRouteMap",
8548 p->default_rmap[afi][safi].name);
8549
8550 if (paf && PAF_SUBGRP(paf)
8551 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8552 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8553 json_object_boolean_true_add(json_addr,
8554 "defaultSent");
8555 else
8556 json_object_boolean_true_add(json_addr,
8557 "defaultNotSent");
8558 }
8559
8560 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8561 if (is_evpn_enabled())
8562 json_object_boolean_true_add(
8563 json_addr, "advertiseAllVnis");
8564 }
8565
8566 if (filter->plist[FILTER_IN].name
8567 || filter->dlist[FILTER_IN].name
8568 || filter->aslist[FILTER_IN].name
8569 || filter->map[RMAP_IN].name)
8570 json_object_boolean_true_add(json_addr,
8571 "inboundPathPolicyConfig");
8572 if (filter->plist[FILTER_OUT].name
8573 || filter->dlist[FILTER_OUT].name
8574 || filter->aslist[FILTER_OUT].name
8575 || filter->map[RMAP_OUT].name || filter->usmap.name)
8576 json_object_boolean_true_add(
8577 json_addr, "outboundPathPolicyConfig");
8578
8579 /* prefix-list */
8580 if (filter->plist[FILTER_IN].name)
8581 json_object_string_add(json_addr,
8582 "incomingUpdatePrefixFilterList",
8583 filter->plist[FILTER_IN].name);
8584 if (filter->plist[FILTER_OUT].name)
8585 json_object_string_add(json_addr,
8586 "outgoingUpdatePrefixFilterList",
8587 filter->plist[FILTER_OUT].name);
8588
8589 /* distribute-list */
8590 if (filter->dlist[FILTER_IN].name)
8591 json_object_string_add(
8592 json_addr, "incomingUpdateNetworkFilterList",
8593 filter->dlist[FILTER_IN].name);
8594 if (filter->dlist[FILTER_OUT].name)
8595 json_object_string_add(
8596 json_addr, "outgoingUpdateNetworkFilterList",
8597 filter->dlist[FILTER_OUT].name);
8598
8599 /* filter-list. */
8600 if (filter->aslist[FILTER_IN].name)
8601 json_object_string_add(json_addr,
8602 "incomingUpdateAsPathFilterList",
8603 filter->aslist[FILTER_IN].name);
8604 if (filter->aslist[FILTER_OUT].name)
8605 json_object_string_add(json_addr,
8606 "outgoingUpdateAsPathFilterList",
8607 filter->aslist[FILTER_OUT].name);
8608
8609 /* route-map. */
8610 if (filter->map[RMAP_IN].name)
8611 json_object_string_add(
8612 json_addr, "routeMapForIncomingAdvertisements",
8613 filter->map[RMAP_IN].name);
8614 if (filter->map[RMAP_OUT].name)
8615 json_object_string_add(
8616 json_addr, "routeMapForOutgoingAdvertisements",
8617 filter->map[RMAP_OUT].name);
8618
8619 /* unsuppress-map */
8620 if (filter->usmap.name)
8621 json_object_string_add(json_addr,
8622 "selectiveUnsuppressRouteMap",
8623 filter->usmap.name);
8624
8625 /* Receive prefix count */
8626 json_object_int_add(json_addr, "acceptedPrefixCounter",
8627 p->pcount[afi][safi]);
8628
8629 /* Maximum prefix */
8630 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8631 json_object_int_add(json_addr, "prefixAllowedMax",
8632 p->pmax[afi][safi]);
8633 if (CHECK_FLAG(p->af_flags[afi][safi],
8634 PEER_FLAG_MAX_PREFIX_WARNING))
8635 json_object_boolean_true_add(
8636 json_addr, "prefixAllowedMaxWarning");
8637 json_object_int_add(json_addr,
8638 "prefixAllowedWarningThresh",
8639 p->pmax_threshold[afi][safi]);
8640 if (p->pmax_restart[afi][safi])
8641 json_object_int_add(
8642 json_addr,
8643 "prefixAllowedRestartIntervalMsecs",
8644 p->pmax_restart[afi][safi] * 60000);
8645 }
8646 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8647 json_addr);
8648
8649 } else {
8650 filter = &p->filter[afi][safi];
8651
8652 vty_out(vty, " For address family: %s\n",
8653 afi_safi_print(afi, safi));
8654
8655 if (peer_group_active(p))
8656 vty_out(vty, " %s peer-group member\n",
8657 p->group->name);
8658
8659 paf = peer_af_find(p, afi, safi);
8660 if (paf && PAF_SUBGRP(paf)) {
8661 vty_out(vty, " Update group %" PRIu64
8662 ", subgroup %" PRIu64 "\n",
8663 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8664 vty_out(vty, " Packet Queue length %d\n",
8665 bpacket_queue_virtual_length(paf));
8666 } else {
8667 vty_out(vty, " Not part of any update group\n");
8668 }
8669 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8670 || CHECK_FLAG(p->af_cap[afi][safi],
8671 PEER_CAP_ORF_PREFIX_SM_RCV)
8672 || CHECK_FLAG(p->af_cap[afi][safi],
8673 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8674 || CHECK_FLAG(p->af_cap[afi][safi],
8675 PEER_CAP_ORF_PREFIX_RM_ADV)
8676 || CHECK_FLAG(p->af_cap[afi][safi],
8677 PEER_CAP_ORF_PREFIX_RM_RCV)
8678 || CHECK_FLAG(p->af_cap[afi][safi],
8679 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8680 vty_out(vty, " AF-dependant capabilities:\n");
8681
8682 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8683 || CHECK_FLAG(p->af_cap[afi][safi],
8684 PEER_CAP_ORF_PREFIX_SM_RCV)
8685 || CHECK_FLAG(p->af_cap[afi][safi],
8686 PEER_CAP_ORF_PREFIX_RM_ADV)
8687 || CHECK_FLAG(p->af_cap[afi][safi],
8688 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8689 vty_out(vty,
8690 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8691 ORF_TYPE_PREFIX);
8692 bgp_show_peer_afi_orf_cap(
8693 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8694 PEER_CAP_ORF_PREFIX_RM_ADV,
8695 PEER_CAP_ORF_PREFIX_SM_RCV,
8696 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8697 }
8698 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8699 || CHECK_FLAG(p->af_cap[afi][safi],
8700 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8701 || CHECK_FLAG(p->af_cap[afi][safi],
8702 PEER_CAP_ORF_PREFIX_RM_ADV)
8703 || CHECK_FLAG(p->af_cap[afi][safi],
8704 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8705 vty_out(vty,
8706 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8707 ORF_TYPE_PREFIX_OLD);
8708 bgp_show_peer_afi_orf_cap(
8709 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8710 PEER_CAP_ORF_PREFIX_RM_ADV,
8711 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8712 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8713 }
8714
8715 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8716 orf_pfx_count = prefix_bgp_show_prefix_list(
8717 NULL, afi, orf_pfx_name, use_json);
8718
8719 if (CHECK_FLAG(p->af_sflags[afi][safi],
8720 PEER_STATUS_ORF_PREFIX_SEND)
8721 || orf_pfx_count) {
8722 vty_out(vty, " Outbound Route Filter (ORF):");
8723 if (CHECK_FLAG(p->af_sflags[afi][safi],
8724 PEER_STATUS_ORF_PREFIX_SEND))
8725 vty_out(vty, " sent;");
8726 if (orf_pfx_count)
8727 vty_out(vty, " received (%d entries)",
8728 orf_pfx_count);
8729 vty_out(vty, "\n");
8730 }
8731 if (CHECK_FLAG(p->af_sflags[afi][safi],
8732 PEER_STATUS_ORF_WAIT_REFRESH))
8733 vty_out(vty,
8734 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8735
8736 if (CHECK_FLAG(p->af_flags[afi][safi],
8737 PEER_FLAG_REFLECTOR_CLIENT))
8738 vty_out(vty, " Route-Reflector Client\n");
8739 if (CHECK_FLAG(p->af_flags[afi][safi],
8740 PEER_FLAG_RSERVER_CLIENT))
8741 vty_out(vty, " Route-Server Client\n");
8742 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8743 vty_out(vty,
8744 " Inbound soft reconfiguration allowed\n");
8745
8746 if (CHECK_FLAG(p->af_flags[afi][safi],
8747 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8748 vty_out(vty,
8749 " Private AS numbers (all) replaced in updates to this neighbor\n");
8750 else if (CHECK_FLAG(p->af_flags[afi][safi],
8751 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8752 vty_out(vty,
8753 " Private AS numbers replaced in updates to this neighbor\n");
8754 else if (CHECK_FLAG(p->af_flags[afi][safi],
8755 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8756 vty_out(vty,
8757 " Private AS numbers (all) removed in updates to this neighbor\n");
8758 else if (CHECK_FLAG(p->af_flags[afi][safi],
8759 PEER_FLAG_REMOVE_PRIVATE_AS))
8760 vty_out(vty,
8761 " Private AS numbers removed in updates to this neighbor\n");
8762
8763 if (CHECK_FLAG(p->af_flags[afi][safi],
8764 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8765 vty_out(vty, " Advertise all paths via addpath\n");
8766
8767 if (CHECK_FLAG(p->af_flags[afi][safi],
8768 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8769 vty_out(vty,
8770 " Advertise bestpath per AS via addpath\n");
8771
8772 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8773 vty_out(vty,
8774 " Override ASNs in outbound updates if aspath equals remote-as\n");
8775
8776 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8777 || CHECK_FLAG(p->af_flags[afi][safi],
8778 PEER_FLAG_FORCE_NEXTHOP_SELF))
8779 vty_out(vty, " NEXT_HOP is always this router\n");
8780 if (CHECK_FLAG(p->af_flags[afi][safi],
8781 PEER_FLAG_AS_PATH_UNCHANGED))
8782 vty_out(vty,
8783 " AS_PATH is propagated unchanged to this neighbor\n");
8784 if (CHECK_FLAG(p->af_flags[afi][safi],
8785 PEER_FLAG_NEXTHOP_UNCHANGED))
8786 vty_out(vty,
8787 " NEXT_HOP is propagated unchanged to this neighbor\n");
8788 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8789 vty_out(vty,
8790 " MED is propagated unchanged to this neighbor\n");
8791 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8792 || CHECK_FLAG(p->af_flags[afi][safi],
8793 PEER_FLAG_SEND_EXT_COMMUNITY)
8794 || CHECK_FLAG(p->af_flags[afi][safi],
8795 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8796 vty_out(vty,
8797 " Community attribute sent to this neighbor");
8798 if (CHECK_FLAG(p->af_flags[afi][safi],
8799 PEER_FLAG_SEND_COMMUNITY)
8800 && CHECK_FLAG(p->af_flags[afi][safi],
8801 PEER_FLAG_SEND_EXT_COMMUNITY)
8802 && CHECK_FLAG(p->af_flags[afi][safi],
8803 PEER_FLAG_SEND_LARGE_COMMUNITY))
8804 vty_out(vty, "(all)\n");
8805 else if (CHECK_FLAG(p->af_flags[afi][safi],
8806 PEER_FLAG_SEND_LARGE_COMMUNITY))
8807 vty_out(vty, "(large)\n");
8808 else if (CHECK_FLAG(p->af_flags[afi][safi],
8809 PEER_FLAG_SEND_EXT_COMMUNITY))
8810 vty_out(vty, "(extended)\n");
8811 else
8812 vty_out(vty, "(standard)\n");
8813 }
8814 if (CHECK_FLAG(p->af_flags[afi][safi],
8815 PEER_FLAG_DEFAULT_ORIGINATE)) {
8816 vty_out(vty, " Default information originate,");
8817
8818 if (p->default_rmap[afi][safi].name)
8819 vty_out(vty, " default route-map %s%s,",
8820 p->default_rmap[afi][safi].map ? "*"
8821 : "",
8822 p->default_rmap[afi][safi].name);
8823 if (paf && PAF_SUBGRP(paf)
8824 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8825 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8826 vty_out(vty, " default sent\n");
8827 else
8828 vty_out(vty, " default not sent\n");
8829 }
8830
8831 /* advertise-vni-all */
8832 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8833 if (is_evpn_enabled())
8834 vty_out(vty, " advertise-all-vni\n");
8835 }
8836
8837 if (filter->plist[FILTER_IN].name
8838 || filter->dlist[FILTER_IN].name
8839 || filter->aslist[FILTER_IN].name
8840 || filter->map[RMAP_IN].name)
8841 vty_out(vty, " Inbound path policy configured\n");
8842 if (filter->plist[FILTER_OUT].name
8843 || filter->dlist[FILTER_OUT].name
8844 || filter->aslist[FILTER_OUT].name
8845 || filter->map[RMAP_OUT].name || filter->usmap.name)
8846 vty_out(vty, " Outbound path policy configured\n");
8847
8848 /* prefix-list */
8849 if (filter->plist[FILTER_IN].name)
8850 vty_out(vty,
8851 " Incoming update prefix filter list is %s%s\n",
8852 filter->plist[FILTER_IN].plist ? "*" : "",
8853 filter->plist[FILTER_IN].name);
8854 if (filter->plist[FILTER_OUT].name)
8855 vty_out(vty,
8856 " Outgoing update prefix filter list is %s%s\n",
8857 filter->plist[FILTER_OUT].plist ? "*" : "",
8858 filter->plist[FILTER_OUT].name);
8859
8860 /* distribute-list */
8861 if (filter->dlist[FILTER_IN].name)
8862 vty_out(vty,
8863 " Incoming update network filter list is %s%s\n",
8864 filter->dlist[FILTER_IN].alist ? "*" : "",
8865 filter->dlist[FILTER_IN].name);
8866 if (filter->dlist[FILTER_OUT].name)
8867 vty_out(vty,
8868 " Outgoing update network filter list is %s%s\n",
8869 filter->dlist[FILTER_OUT].alist ? "*" : "",
8870 filter->dlist[FILTER_OUT].name);
8871
8872 /* filter-list. */
8873 if (filter->aslist[FILTER_IN].name)
8874 vty_out(vty,
8875 " Incoming update AS path filter list is %s%s\n",
8876 filter->aslist[FILTER_IN].aslist ? "*" : "",
8877 filter->aslist[FILTER_IN].name);
8878 if (filter->aslist[FILTER_OUT].name)
8879 vty_out(vty,
8880 " Outgoing update AS path filter list is %s%s\n",
8881 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8882 filter->aslist[FILTER_OUT].name);
8883
8884 /* route-map. */
8885 if (filter->map[RMAP_IN].name)
8886 vty_out(vty,
8887 " Route map for incoming advertisements is %s%s\n",
8888 filter->map[RMAP_IN].map ? "*" : "",
8889 filter->map[RMAP_IN].name);
8890 if (filter->map[RMAP_OUT].name)
8891 vty_out(vty,
8892 " Route map for outgoing advertisements is %s%s\n",
8893 filter->map[RMAP_OUT].map ? "*" : "",
8894 filter->map[RMAP_OUT].name);
8895
8896 /* unsuppress-map */
8897 if (filter->usmap.name)
8898 vty_out(vty,
8899 " Route map for selective unsuppress is %s%s\n",
8900 filter->usmap.map ? "*" : "",
8901 filter->usmap.name);
8902
8903 /* Receive prefix count */
8904 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8905
8906 /* Maximum prefix */
8907 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8908 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8909 p->pmax[afi][safi],
8910 CHECK_FLAG(p->af_flags[afi][safi],
8911 PEER_FLAG_MAX_PREFIX_WARNING)
8912 ? " (warning-only)"
8913 : "");
8914 vty_out(vty, " Threshold for warning message %d%%",
8915 p->pmax_threshold[afi][safi]);
8916 if (p->pmax_restart[afi][safi])
8917 vty_out(vty, ", restart interval %d min",
8918 p->pmax_restart[afi][safi]);
8919 vty_out(vty, "\n");
8920 }
8921
8922 vty_out(vty, "\n");
8923 }
8924 }
8925
8926 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8927 json_object *json)
8928 {
8929 struct bgp *bgp;
8930 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8931 char timebuf[BGP_UPTIME_LEN];
8932 char dn_flag[2];
8933 const char *subcode_str;
8934 const char *code_str;
8935 afi_t afi;
8936 safi_t safi;
8937 uint16_t i;
8938 uint8_t *msg;
8939 json_object *json_neigh = NULL;
8940 time_t epoch_tbuf;
8941
8942 bgp = p->bgp;
8943
8944 if (use_json)
8945 json_neigh = json_object_new_object();
8946
8947 memset(dn_flag, '\0', sizeof(dn_flag));
8948 if (!p->conf_if && peer_dynamic_neighbor(p))
8949 dn_flag[0] = '*';
8950
8951 if (!use_json) {
8952 if (p->conf_if) /* Configured interface name. */
8953 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8954 BGP_PEER_SU_UNSPEC(p)
8955 ? "None"
8956 : sockunion2str(&p->su, buf,
8957 SU_ADDRSTRLEN));
8958 else /* Configured IP address. */
8959 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8960 p->host);
8961 }
8962
8963 if (use_json) {
8964 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8965 json_object_string_add(json_neigh, "bgpNeighborAddr",
8966 "none");
8967 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8968 json_object_string_add(
8969 json_neigh, "bgpNeighborAddr",
8970 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8971
8972 json_object_int_add(json_neigh, "remoteAs", p->as);
8973
8974 if (p->change_local_as)
8975 json_object_int_add(json_neigh, "localAs",
8976 p->change_local_as);
8977 else
8978 json_object_int_add(json_neigh, "localAs", p->local_as);
8979
8980 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8981 json_object_boolean_true_add(json_neigh,
8982 "localAsNoPrepend");
8983
8984 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8985 json_object_boolean_true_add(json_neigh,
8986 "localAsReplaceAs");
8987 } else {
8988 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8989 || (p->as_type == AS_INTERNAL))
8990 vty_out(vty, "remote AS %u, ", p->as);
8991 else
8992 vty_out(vty, "remote AS Unspecified, ");
8993 vty_out(vty, "local AS %u%s%s, ",
8994 p->change_local_as ? p->change_local_as : p->local_as,
8995 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8996 ? " no-prepend"
8997 : "",
8998 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8999 ? " replace-as"
9000 : "");
9001 }
9002 /* peer type internal, external, confed-internal or confed-external */
9003 if (p->as == p->local_as) {
9004 if (use_json) {
9005 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9006 json_object_boolean_true_add(
9007 json_neigh, "nbrConfedInternalLink");
9008 else
9009 json_object_boolean_true_add(json_neigh,
9010 "nbrInternalLink");
9011 } else {
9012 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9013 vty_out(vty, "confed-internal link\n");
9014 else
9015 vty_out(vty, "internal link\n");
9016 }
9017 } else {
9018 if (use_json) {
9019 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9020 json_object_boolean_true_add(
9021 json_neigh, "nbrConfedExternalLink");
9022 else
9023 json_object_boolean_true_add(json_neigh,
9024 "nbrExternalLink");
9025 } else {
9026 if (bgp_confederation_peers_check(bgp, p->as))
9027 vty_out(vty, "confed-external link\n");
9028 else
9029 vty_out(vty, "external link\n");
9030 }
9031 }
9032
9033 /* Description. */
9034 if (p->desc) {
9035 if (use_json)
9036 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9037 else
9038 vty_out(vty, " Description: %s\n", p->desc);
9039 }
9040
9041 if (p->hostname) {
9042 if (use_json) {
9043 if (p->hostname)
9044 json_object_string_add(json_neigh, "hostname",
9045 p->hostname);
9046
9047 if (p->domainname)
9048 json_object_string_add(json_neigh, "domainname",
9049 p->domainname);
9050 } else {
9051 if (p->domainname && (p->domainname[0] != '\0'))
9052 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9053 p->domainname);
9054 else
9055 vty_out(vty, "Hostname: %s\n", p->hostname);
9056 }
9057 }
9058
9059 /* Peer-group */
9060 if (p->group) {
9061 if (use_json) {
9062 json_object_string_add(json_neigh, "peerGroup",
9063 p->group->name);
9064
9065 if (dn_flag[0]) {
9066 struct prefix prefix, *range = NULL;
9067
9068 sockunion2hostprefix(&(p->su), &prefix);
9069 range = peer_group_lookup_dynamic_neighbor_range(
9070 p->group, &prefix);
9071
9072 if (range) {
9073 prefix2str(range, buf1, sizeof(buf1));
9074 json_object_string_add(
9075 json_neigh,
9076 "peerSubnetRangeGroup", buf1);
9077 }
9078 }
9079 } else {
9080 vty_out(vty,
9081 " Member of peer-group %s for session parameters\n",
9082 p->group->name);
9083
9084 if (dn_flag[0]) {
9085 struct prefix prefix, *range = NULL;
9086
9087 sockunion2hostprefix(&(p->su), &prefix);
9088 range = peer_group_lookup_dynamic_neighbor_range(
9089 p->group, &prefix);
9090
9091 if (range) {
9092 prefix2str(range, buf1, sizeof(buf1));
9093 vty_out(vty,
9094 " Belongs to the subnet range group: %s\n",
9095 buf1);
9096 }
9097 }
9098 }
9099 }
9100
9101 if (use_json) {
9102 /* Administrative shutdown. */
9103 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9104 json_object_boolean_true_add(json_neigh,
9105 "adminShutDown");
9106
9107 /* BGP Version. */
9108 json_object_int_add(json_neigh, "bgpVersion", 4);
9109 json_object_string_add(
9110 json_neigh, "remoteRouterId",
9111 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9112
9113 /* Confederation */
9114 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9115 && bgp_confederation_peers_check(bgp, p->as))
9116 json_object_boolean_true_add(json_neigh,
9117 "nbrCommonAdmin");
9118
9119 /* Status. */
9120 json_object_string_add(
9121 json_neigh, "bgpState",
9122 lookup_msg(bgp_status_msg, p->status, NULL));
9123
9124 if (p->status == Established) {
9125 time_t uptime;
9126
9127 uptime = bgp_clock();
9128 uptime -= p->uptime;
9129 epoch_tbuf = time(NULL) - uptime;
9130
9131 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
9132 CPP_NOTICE(
9133 "bgpTimerUp should be deprecated and can be removed now");
9134 #endif
9135 /*
9136 * bgpTimerUp was miliseconds that was accurate
9137 * up to 1 day, then the value returned
9138 * became garbage. So in order to provide
9139 * some level of backwards compatability,
9140 * we still provde the data, but now
9141 * we are returning the correct value
9142 * and also adding a new bgpTimerUpMsec
9143 * which will allow us to deprecate
9144 * this eventually
9145 */
9146 json_object_int_add(json_neigh, "bgpTimerUp",
9147 uptime * 1000);
9148 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9149 uptime * 1000);
9150 json_object_string_add(json_neigh, "bgpTimerUpString",
9151 peer_uptime(p->uptime, timebuf,
9152 BGP_UPTIME_LEN, 0,
9153 NULL));
9154 json_object_int_add(json_neigh,
9155 "bgpTimerUpEstablishedEpoch",
9156 epoch_tbuf);
9157 }
9158
9159 else if (p->status == Active) {
9160 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9161 json_object_string_add(json_neigh, "bgpStateIs",
9162 "passive");
9163 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9164 json_object_string_add(json_neigh, "bgpStateIs",
9165 "passiveNSF");
9166 }
9167
9168 /* read timer */
9169 time_t uptime;
9170 struct tm *tm;
9171
9172 uptime = bgp_clock();
9173 uptime -= p->readtime;
9174 tm = gmtime(&uptime);
9175 json_object_int_add(json_neigh, "bgpTimerLastRead",
9176 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9177 + (tm->tm_hour * 3600000));
9178
9179 uptime = bgp_clock();
9180 uptime -= p->last_write;
9181 tm = gmtime(&uptime);
9182 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9183 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9184 + (tm->tm_hour * 3600000));
9185
9186 uptime = bgp_clock();
9187 uptime -= p->update_time;
9188 tm = gmtime(&uptime);
9189 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9190 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9191 + (tm->tm_hour * 3600000));
9192
9193 /* Configured timer values. */
9194 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9195 p->v_holdtime * 1000);
9196 json_object_int_add(json_neigh,
9197 "bgpTimerKeepAliveIntervalMsecs",
9198 p->v_keepalive * 1000);
9199 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9200 json_object_int_add(json_neigh,
9201 "bgpTimerConfiguredHoldTimeMsecs",
9202 p->holdtime * 1000);
9203 json_object_int_add(
9204 json_neigh,
9205 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9206 p->keepalive * 1000);
9207 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9208 || (bgp->default_keepalive
9209 != BGP_DEFAULT_KEEPALIVE)) {
9210 json_object_int_add(json_neigh,
9211 "bgpTimerConfiguredHoldTimeMsecs",
9212 bgp->default_holdtime);
9213 json_object_int_add(
9214 json_neigh,
9215 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9216 bgp->default_keepalive);
9217 }
9218 } else {
9219 /* Administrative shutdown. */
9220 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9221 vty_out(vty, " Administratively shut down\n");
9222
9223 /* BGP Version. */
9224 vty_out(vty, " BGP version 4");
9225 vty_out(vty, ", remote router ID %s\n",
9226 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9227
9228 /* Confederation */
9229 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9230 && bgp_confederation_peers_check(bgp, p->as))
9231 vty_out(vty,
9232 " Neighbor under common administration\n");
9233
9234 /* Status. */
9235 vty_out(vty, " BGP state = %s",
9236 lookup_msg(bgp_status_msg, p->status, NULL));
9237
9238 if (p->status == Established)
9239 vty_out(vty, ", up for %8s",
9240 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9241 0, NULL));
9242
9243 else if (p->status == Active) {
9244 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9245 vty_out(vty, " (passive)");
9246 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9247 vty_out(vty, " (NSF passive)");
9248 }
9249 vty_out(vty, "\n");
9250
9251 /* read timer */
9252 vty_out(vty, " Last read %s",
9253 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9254 NULL));
9255 vty_out(vty, ", Last write %s\n",
9256 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9257 NULL));
9258
9259 /* Configured timer values. */
9260 vty_out(vty,
9261 " Hold time is %d, keepalive interval is %d seconds\n",
9262 p->v_holdtime, p->v_keepalive);
9263 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9264 vty_out(vty, " Configured hold time is %d",
9265 p->holdtime);
9266 vty_out(vty, ", keepalive interval is %d seconds\n",
9267 p->keepalive);
9268 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9269 || (bgp->default_keepalive
9270 != BGP_DEFAULT_KEEPALIVE)) {
9271 vty_out(vty, " Configured hold time is %d",
9272 bgp->default_holdtime);
9273 vty_out(vty, ", keepalive interval is %d seconds\n",
9274 bgp->default_keepalive);
9275 }
9276 }
9277 /* Capability. */
9278 if (p->status == Established) {
9279 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9280 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9281 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9282 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9283 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9284 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9285 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9286 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9287 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9288 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9289 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9290 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9291 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9292 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9293 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9294 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9295 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9296 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9297 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9298 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9299 if (use_json) {
9300 json_object *json_cap = NULL;
9301
9302 json_cap = json_object_new_object();
9303
9304 /* AS4 */
9305 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9306 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9307 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9308 && CHECK_FLAG(p->cap,
9309 PEER_CAP_AS4_RCV))
9310 json_object_string_add(
9311 json_cap, "4byteAs",
9312 "advertisedAndReceived");
9313 else if (CHECK_FLAG(p->cap,
9314 PEER_CAP_AS4_ADV))
9315 json_object_string_add(
9316 json_cap, "4byteAs",
9317 "advertised");
9318 else if (CHECK_FLAG(p->cap,
9319 PEER_CAP_AS4_RCV))
9320 json_object_string_add(
9321 json_cap, "4byteAs",
9322 "received");
9323 }
9324
9325 /* AddPath */
9326 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9327 || CHECK_FLAG(p->cap,
9328 PEER_CAP_ADDPATH_ADV)) {
9329 json_object *json_add = NULL;
9330 const char *print_store;
9331
9332 json_add = json_object_new_object();
9333
9334 FOREACH_AFI_SAFI (afi, safi) {
9335 json_object *json_sub = NULL;
9336 json_sub =
9337 json_object_new_object();
9338 print_store = afi_safi_print(
9339 afi, safi);
9340
9341 if (CHECK_FLAG(
9342 p->af_cap[afi]
9343 [safi],
9344 PEER_CAP_ADDPATH_AF_TX_ADV)
9345 || CHECK_FLAG(
9346 p->af_cap[afi]
9347 [safi],
9348 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9349 if (CHECK_FLAG(
9350 p->af_cap
9351 [afi]
9352 [safi],
9353 PEER_CAP_ADDPATH_AF_TX_ADV)
9354 && CHECK_FLAG(
9355 p->af_cap
9356 [afi]
9357 [safi],
9358 PEER_CAP_ADDPATH_AF_TX_RCV))
9359 json_object_boolean_true_add(
9360 json_sub,
9361 "txAdvertisedAndReceived");
9362 else if (
9363 CHECK_FLAG(
9364 p->af_cap
9365 [afi]
9366 [safi],
9367 PEER_CAP_ADDPATH_AF_TX_ADV))
9368 json_object_boolean_true_add(
9369 json_sub,
9370 "txAdvertised");
9371 else if (
9372 CHECK_FLAG(
9373 p->af_cap
9374 [afi]
9375 [safi],
9376 PEER_CAP_ADDPATH_AF_TX_RCV))
9377 json_object_boolean_true_add(
9378 json_sub,
9379 "txReceived");
9380 }
9381
9382 if (CHECK_FLAG(
9383 p->af_cap[afi]
9384 [safi],
9385 PEER_CAP_ADDPATH_AF_RX_ADV)
9386 || CHECK_FLAG(
9387 p->af_cap[afi]
9388 [safi],
9389 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9390 if (CHECK_FLAG(
9391 p->af_cap
9392 [afi]
9393 [safi],
9394 PEER_CAP_ADDPATH_AF_RX_ADV)
9395 && CHECK_FLAG(
9396 p->af_cap
9397 [afi]
9398 [safi],
9399 PEER_CAP_ADDPATH_AF_RX_RCV))
9400 json_object_boolean_true_add(
9401 json_sub,
9402 "rxAdvertisedAndReceived");
9403 else if (
9404 CHECK_FLAG(
9405 p->af_cap
9406 [afi]
9407 [safi],
9408 PEER_CAP_ADDPATH_AF_RX_ADV))
9409 json_object_boolean_true_add(
9410 json_sub,
9411 "rxAdvertised");
9412 else if (
9413 CHECK_FLAG(
9414 p->af_cap
9415 [afi]
9416 [safi],
9417 PEER_CAP_ADDPATH_AF_RX_RCV))
9418 json_object_boolean_true_add(
9419 json_sub,
9420 "rxReceived");
9421 }
9422
9423 if (CHECK_FLAG(
9424 p->af_cap[afi]
9425 [safi],
9426 PEER_CAP_ADDPATH_AF_TX_ADV)
9427 || CHECK_FLAG(
9428 p->af_cap[afi]
9429 [safi],
9430 PEER_CAP_ADDPATH_AF_TX_RCV)
9431 || CHECK_FLAG(
9432 p->af_cap[afi]
9433 [safi],
9434 PEER_CAP_ADDPATH_AF_RX_ADV)
9435 || CHECK_FLAG(
9436 p->af_cap[afi]
9437 [safi],
9438 PEER_CAP_ADDPATH_AF_RX_RCV))
9439 json_object_object_add(
9440 json_add,
9441 print_store,
9442 json_sub);
9443 else
9444 json_object_free(
9445 json_sub);
9446 }
9447
9448 json_object_object_add(
9449 json_cap, "addPath", json_add);
9450 }
9451
9452 /* Dynamic */
9453 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9454 || CHECK_FLAG(p->cap,
9455 PEER_CAP_DYNAMIC_ADV)) {
9456 if (CHECK_FLAG(p->cap,
9457 PEER_CAP_DYNAMIC_ADV)
9458 && CHECK_FLAG(p->cap,
9459 PEER_CAP_DYNAMIC_RCV))
9460 json_object_string_add(
9461 json_cap, "dynamic",
9462 "advertisedAndReceived");
9463 else if (CHECK_FLAG(
9464 p->cap,
9465 PEER_CAP_DYNAMIC_ADV))
9466 json_object_string_add(
9467 json_cap, "dynamic",
9468 "advertised");
9469 else if (CHECK_FLAG(
9470 p->cap,
9471 PEER_CAP_DYNAMIC_RCV))
9472 json_object_string_add(
9473 json_cap, "dynamic",
9474 "received");
9475 }
9476
9477 /* Extended nexthop */
9478 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9479 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9480 json_object *json_nxt = NULL;
9481 const char *print_store;
9482
9483
9484 if (CHECK_FLAG(p->cap,
9485 PEER_CAP_ENHE_ADV)
9486 && CHECK_FLAG(p->cap,
9487 PEER_CAP_ENHE_RCV))
9488 json_object_string_add(
9489 json_cap,
9490 "extendedNexthop",
9491 "advertisedAndReceived");
9492 else if (CHECK_FLAG(p->cap,
9493 PEER_CAP_ENHE_ADV))
9494 json_object_string_add(
9495 json_cap,
9496 "extendedNexthop",
9497 "advertised");
9498 else if (CHECK_FLAG(p->cap,
9499 PEER_CAP_ENHE_RCV))
9500 json_object_string_add(
9501 json_cap,
9502 "extendedNexthop",
9503 "received");
9504
9505 if (CHECK_FLAG(p->cap,
9506 PEER_CAP_ENHE_RCV)) {
9507 json_nxt =
9508 json_object_new_object();
9509
9510 for (safi = SAFI_UNICAST;
9511 safi < SAFI_MAX; safi++) {
9512 if (CHECK_FLAG(
9513 p->af_cap
9514 [AFI_IP]
9515 [safi],
9516 PEER_CAP_ENHE_AF_RCV)) {
9517 print_store = afi_safi_print(
9518 AFI_IP,
9519 safi);
9520 json_object_string_add(
9521 json_nxt,
9522 print_store,
9523 "recieved");
9524 }
9525 }
9526 json_object_object_add(
9527 json_cap,
9528 "extendedNexthopFamililesByPeer",
9529 json_nxt);
9530 }
9531 }
9532
9533 /* Route Refresh */
9534 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9535 || CHECK_FLAG(p->cap,
9536 PEER_CAP_REFRESH_NEW_RCV)
9537 || CHECK_FLAG(p->cap,
9538 PEER_CAP_REFRESH_OLD_RCV)) {
9539 if (CHECK_FLAG(p->cap,
9540 PEER_CAP_REFRESH_ADV)
9541 && (CHECK_FLAG(
9542 p->cap,
9543 PEER_CAP_REFRESH_NEW_RCV)
9544 || CHECK_FLAG(
9545 p->cap,
9546 PEER_CAP_REFRESH_OLD_RCV))) {
9547 if (CHECK_FLAG(
9548 p->cap,
9549 PEER_CAP_REFRESH_OLD_RCV)
9550 && CHECK_FLAG(
9551 p->cap,
9552 PEER_CAP_REFRESH_NEW_RCV))
9553 json_object_string_add(
9554 json_cap,
9555 "routeRefresh",
9556 "advertisedAndReceivedOldNew");
9557 else {
9558 if (CHECK_FLAG(
9559 p->cap,
9560 PEER_CAP_REFRESH_OLD_RCV))
9561 json_object_string_add(
9562 json_cap,
9563 "routeRefresh",
9564 "advertisedAndReceivedOld");
9565 else
9566 json_object_string_add(
9567 json_cap,
9568 "routeRefresh",
9569 "advertisedAndReceivedNew");
9570 }
9571 } else if (
9572 CHECK_FLAG(
9573 p->cap,
9574 PEER_CAP_REFRESH_ADV))
9575 json_object_string_add(
9576 json_cap,
9577 "routeRefresh",
9578 "advertised");
9579 else if (
9580 CHECK_FLAG(
9581 p->cap,
9582 PEER_CAP_REFRESH_NEW_RCV)
9583 || CHECK_FLAG(
9584 p->cap,
9585 PEER_CAP_REFRESH_OLD_RCV))
9586 json_object_string_add(
9587 json_cap,
9588 "routeRefresh",
9589 "received");
9590 }
9591
9592 /* Multiprotocol Extensions */
9593 json_object *json_multi = NULL;
9594 json_multi = json_object_new_object();
9595
9596 FOREACH_AFI_SAFI (afi, safi) {
9597 if (p->afc_adv[afi][safi]
9598 || p->afc_recv[afi][safi]) {
9599 json_object *json_exten = NULL;
9600 json_exten =
9601 json_object_new_object();
9602
9603 if (p->afc_adv[afi][safi]
9604 && p->afc_recv[afi][safi])
9605 json_object_boolean_true_add(
9606 json_exten,
9607 "advertisedAndReceived");
9608 else if (p->afc_adv[afi][safi])
9609 json_object_boolean_true_add(
9610 json_exten,
9611 "advertised");
9612 else if (p->afc_recv[afi][safi])
9613 json_object_boolean_true_add(
9614 json_exten,
9615 "received");
9616
9617 json_object_object_add(
9618 json_multi,
9619 afi_safi_print(afi,
9620 safi),
9621 json_exten);
9622 }
9623 }
9624 json_object_object_add(
9625 json_cap, "multiprotocolExtensions",
9626 json_multi);
9627
9628 /* Hostname capabilities */
9629 json_object *json_hname = NULL;
9630
9631 json_hname = json_object_new_object();
9632
9633 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9634 json_object_string_add(
9635 json_hname, "advHostName",
9636 bgp->peer_self->hostname
9637 ? bgp->peer_self
9638 ->hostname
9639 : "n/a");
9640 json_object_string_add(
9641 json_hname, "advDomainName",
9642 bgp->peer_self->domainname
9643 ? bgp->peer_self
9644 ->domainname
9645 : "n/a");
9646 }
9647
9648
9649 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9650 json_object_string_add(
9651 json_hname, "rcvHostName",
9652 p->hostname ? p->hostname
9653 : "n/a");
9654 json_object_string_add(
9655 json_hname, "rcvDomainName",
9656 p->domainname ? p->domainname
9657 : "n/a");
9658 }
9659
9660 json_object_object_add(json_cap, "hostName",
9661 json_hname);
9662
9663 /* Gracefull Restart */
9664 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9665 || CHECK_FLAG(p->cap,
9666 PEER_CAP_RESTART_ADV)) {
9667 if (CHECK_FLAG(p->cap,
9668 PEER_CAP_RESTART_ADV)
9669 && CHECK_FLAG(p->cap,
9670 PEER_CAP_RESTART_RCV))
9671 json_object_string_add(
9672 json_cap,
9673 "gracefulRestart",
9674 "advertisedAndReceived");
9675 else if (CHECK_FLAG(
9676 p->cap,
9677 PEER_CAP_RESTART_ADV))
9678 json_object_string_add(
9679 json_cap,
9680 "gracefulRestartCapability",
9681 "advertised");
9682 else if (CHECK_FLAG(
9683 p->cap,
9684 PEER_CAP_RESTART_RCV))
9685 json_object_string_add(
9686 json_cap,
9687 "gracefulRestartCapability",
9688 "received");
9689
9690 if (CHECK_FLAG(p->cap,
9691 PEER_CAP_RESTART_RCV)) {
9692 int restart_af_count = 0;
9693 json_object *json_restart =
9694 NULL;
9695 json_restart =
9696 json_object_new_object();
9697
9698 json_object_int_add(
9699 json_cap,
9700 "gracefulRestartRemoteTimerMsecs",
9701 p->v_gr_restart * 1000);
9702
9703 FOREACH_AFI_SAFI (afi, safi) {
9704 if (CHECK_FLAG(
9705 p->af_cap
9706 [afi]
9707 [safi],
9708 PEER_CAP_RESTART_AF_RCV)) {
9709 json_object *
9710 json_sub =
9711 NULL;
9712 json_sub =
9713 json_object_new_object();
9714
9715 if (CHECK_FLAG(
9716 p->af_cap
9717 [afi]
9718 [safi],
9719 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9720 json_object_boolean_true_add(
9721 json_sub,
9722 "preserved");
9723 restart_af_count++;
9724 json_object_object_add(
9725 json_restart,
9726 afi_safi_print(
9727 afi,
9728 safi),
9729 json_sub);
9730 }
9731 }
9732 if (!restart_af_count) {
9733 json_object_string_add(
9734 json_cap,
9735 "addressFamiliesByPeer",
9736 "none");
9737 json_object_free(
9738 json_restart);
9739 } else
9740 json_object_object_add(
9741 json_cap,
9742 "addressFamiliesByPeer",
9743 json_restart);
9744 }
9745 }
9746 json_object_object_add(json_neigh,
9747 "neighborCapabilities",
9748 json_cap);
9749 } else {
9750 vty_out(vty, " Neighbor capabilities:\n");
9751
9752 /* AS4 */
9753 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9754 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9755 vty_out(vty, " 4 Byte AS:");
9756 if (CHECK_FLAG(p->cap,
9757 PEER_CAP_AS4_ADV))
9758 vty_out(vty, " advertised");
9759 if (CHECK_FLAG(p->cap,
9760 PEER_CAP_AS4_RCV))
9761 vty_out(vty, " %sreceived",
9762 CHECK_FLAG(
9763 p->cap,
9764 PEER_CAP_AS4_ADV)
9765 ? "and "
9766 : "");
9767 vty_out(vty, "\n");
9768 }
9769
9770 /* AddPath */
9771 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9772 || CHECK_FLAG(p->cap,
9773 PEER_CAP_ADDPATH_ADV)) {
9774 vty_out(vty, " AddPath:\n");
9775
9776 FOREACH_AFI_SAFI (afi, safi) {
9777 if (CHECK_FLAG(
9778 p->af_cap[afi]
9779 [safi],
9780 PEER_CAP_ADDPATH_AF_TX_ADV)
9781 || CHECK_FLAG(
9782 p->af_cap[afi]
9783 [safi],
9784 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9785 vty_out(vty,
9786 " %s: TX ",
9787 afi_safi_print(
9788 afi,
9789 safi));
9790
9791 if (CHECK_FLAG(
9792 p->af_cap
9793 [afi]
9794 [safi],
9795 PEER_CAP_ADDPATH_AF_TX_ADV))
9796 vty_out(vty,
9797 "advertised %s",
9798 afi_safi_print(
9799 afi,
9800 safi));
9801
9802 if (CHECK_FLAG(
9803 p->af_cap
9804 [afi]
9805 [safi],
9806 PEER_CAP_ADDPATH_AF_TX_RCV))
9807 vty_out(vty,
9808 "%sreceived",
9809 CHECK_FLAG(
9810 p->af_cap
9811 [afi]
9812 [safi],
9813 PEER_CAP_ADDPATH_AF_TX_ADV)
9814 ? " and "
9815 : "");
9816
9817 vty_out(vty, "\n");
9818 }
9819
9820 if (CHECK_FLAG(
9821 p->af_cap[afi]
9822 [safi],
9823 PEER_CAP_ADDPATH_AF_RX_ADV)
9824 || CHECK_FLAG(
9825 p->af_cap[afi]
9826 [safi],
9827 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9828 vty_out(vty,
9829 " %s: RX ",
9830 afi_safi_print(
9831 afi,
9832 safi));
9833
9834 if (CHECK_FLAG(
9835 p->af_cap
9836 [afi]
9837 [safi],
9838 PEER_CAP_ADDPATH_AF_RX_ADV))
9839 vty_out(vty,
9840 "advertised %s",
9841 afi_safi_print(
9842 afi,
9843 safi));
9844
9845 if (CHECK_FLAG(
9846 p->af_cap
9847 [afi]
9848 [safi],
9849 PEER_CAP_ADDPATH_AF_RX_RCV))
9850 vty_out(vty,
9851 "%sreceived",
9852 CHECK_FLAG(
9853 p->af_cap
9854 [afi]
9855 [safi],
9856 PEER_CAP_ADDPATH_AF_RX_ADV)
9857 ? " and "
9858 : "");
9859
9860 vty_out(vty, "\n");
9861 }
9862 }
9863 }
9864
9865 /* Dynamic */
9866 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9867 || CHECK_FLAG(p->cap,
9868 PEER_CAP_DYNAMIC_ADV)) {
9869 vty_out(vty, " Dynamic:");
9870 if (CHECK_FLAG(p->cap,
9871 PEER_CAP_DYNAMIC_ADV))
9872 vty_out(vty, " advertised");
9873 if (CHECK_FLAG(p->cap,
9874 PEER_CAP_DYNAMIC_RCV))
9875 vty_out(vty, " %sreceived",
9876 CHECK_FLAG(
9877 p->cap,
9878 PEER_CAP_DYNAMIC_ADV)
9879 ? "and "
9880 : "");
9881 vty_out(vty, "\n");
9882 }
9883
9884 /* Extended nexthop */
9885 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9886 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9887 vty_out(vty, " Extended nexthop:");
9888 if (CHECK_FLAG(p->cap,
9889 PEER_CAP_ENHE_ADV))
9890 vty_out(vty, " advertised");
9891 if (CHECK_FLAG(p->cap,
9892 PEER_CAP_ENHE_RCV))
9893 vty_out(vty, " %sreceived",
9894 CHECK_FLAG(
9895 p->cap,
9896 PEER_CAP_ENHE_ADV)
9897 ? "and "
9898 : "");
9899 vty_out(vty, "\n");
9900
9901 if (CHECK_FLAG(p->cap,
9902 PEER_CAP_ENHE_RCV)) {
9903 vty_out(vty,
9904 " Address families by peer:\n ");
9905 for (safi = SAFI_UNICAST;
9906 safi < SAFI_MAX; safi++)
9907 if (CHECK_FLAG(
9908 p->af_cap
9909 [AFI_IP]
9910 [safi],
9911 PEER_CAP_ENHE_AF_RCV))
9912 vty_out(vty,
9913 " %s\n",
9914 afi_safi_print(
9915 AFI_IP,
9916 safi));
9917 }
9918 }
9919
9920 /* Route Refresh */
9921 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9922 || CHECK_FLAG(p->cap,
9923 PEER_CAP_REFRESH_NEW_RCV)
9924 || CHECK_FLAG(p->cap,
9925 PEER_CAP_REFRESH_OLD_RCV)) {
9926 vty_out(vty, " Route refresh:");
9927 if (CHECK_FLAG(p->cap,
9928 PEER_CAP_REFRESH_ADV))
9929 vty_out(vty, " advertised");
9930 if (CHECK_FLAG(p->cap,
9931 PEER_CAP_REFRESH_NEW_RCV)
9932 || CHECK_FLAG(
9933 p->cap,
9934 PEER_CAP_REFRESH_OLD_RCV))
9935 vty_out(vty, " %sreceived(%s)",
9936 CHECK_FLAG(
9937 p->cap,
9938 PEER_CAP_REFRESH_ADV)
9939 ? "and "
9940 : "",
9941 (CHECK_FLAG(
9942 p->cap,
9943 PEER_CAP_REFRESH_OLD_RCV)
9944 && CHECK_FLAG(
9945 p->cap,
9946 PEER_CAP_REFRESH_NEW_RCV))
9947 ? "old & new"
9948 : CHECK_FLAG(
9949 p->cap,
9950 PEER_CAP_REFRESH_OLD_RCV)
9951 ? "old"
9952 : "new");
9953
9954 vty_out(vty, "\n");
9955 }
9956
9957 /* Multiprotocol Extensions */
9958 FOREACH_AFI_SAFI (afi, safi)
9959 if (p->afc_adv[afi][safi]
9960 || p->afc_recv[afi][safi]) {
9961 vty_out(vty,
9962 " Address Family %s:",
9963 afi_safi_print(afi,
9964 safi));
9965 if (p->afc_adv[afi][safi])
9966 vty_out(vty,
9967 " advertised");
9968 if (p->afc_recv[afi][safi])
9969 vty_out(vty,
9970 " %sreceived",
9971 p->afc_adv[afi]
9972 [safi]
9973 ? "and "
9974 : "");
9975 vty_out(vty, "\n");
9976 }
9977
9978 /* Hostname capability */
9979 vty_out(vty, " Hostname Capability:");
9980
9981 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9982 vty_out(vty,
9983 " advertised (name: %s,domain name: %s)",
9984 bgp->peer_self->hostname
9985 ? bgp->peer_self
9986 ->hostname
9987 : "n/a",
9988 bgp->peer_self->domainname
9989 ? bgp->peer_self
9990 ->domainname
9991 : "n/a");
9992 } else {
9993 vty_out(vty, " not advertised");
9994 }
9995
9996 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9997 vty_out(vty,
9998 " received (name: %s,domain name: %s)",
9999 p->hostname ? p->hostname
10000 : "n/a",
10001 p->domainname ? p->domainname
10002 : "n/a");
10003 } else {
10004 vty_out(vty, " not received");
10005 }
10006
10007 vty_out(vty, "\n");
10008
10009 /* Gracefull Restart */
10010 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10011 || CHECK_FLAG(p->cap,
10012 PEER_CAP_RESTART_ADV)) {
10013 vty_out(vty,
10014 " Graceful Restart Capabilty:");
10015 if (CHECK_FLAG(p->cap,
10016 PEER_CAP_RESTART_ADV))
10017 vty_out(vty, " advertised");
10018 if (CHECK_FLAG(p->cap,
10019 PEER_CAP_RESTART_RCV))
10020 vty_out(vty, " %sreceived",
10021 CHECK_FLAG(
10022 p->cap,
10023 PEER_CAP_RESTART_ADV)
10024 ? "and "
10025 : "");
10026 vty_out(vty, "\n");
10027
10028 if (CHECK_FLAG(p->cap,
10029 PEER_CAP_RESTART_RCV)) {
10030 int restart_af_count = 0;
10031
10032 vty_out(vty,
10033 " Remote Restart timer is %d seconds\n",
10034 p->v_gr_restart);
10035 vty_out(vty,
10036 " Address families by peer:\n ");
10037
10038 FOREACH_AFI_SAFI (afi, safi)
10039 if (CHECK_FLAG(
10040 p->af_cap
10041 [afi]
10042 [safi],
10043 PEER_CAP_RESTART_AF_RCV)) {
10044 vty_out(vty,
10045 "%s%s(%s)",
10046 restart_af_count
10047 ? ", "
10048 : "",
10049 afi_safi_print(
10050 afi,
10051 safi),
10052 CHECK_FLAG(
10053 p->af_cap
10054 [afi]
10055 [safi],
10056 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10057 ? "preserved"
10058 : "not preserved");
10059 restart_af_count++;
10060 }
10061 if (!restart_af_count)
10062 vty_out(vty, "none");
10063 vty_out(vty, "\n");
10064 }
10065 }
10066 }
10067 }
10068 }
10069
10070 /* graceful restart information */
10071 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10072 || p->t_gr_stale) {
10073 json_object *json_grace = NULL;
10074 json_object *json_grace_send = NULL;
10075 json_object *json_grace_recv = NULL;
10076 int eor_send_af_count = 0;
10077 int eor_receive_af_count = 0;
10078
10079 if (use_json) {
10080 json_grace = json_object_new_object();
10081 json_grace_send = json_object_new_object();
10082 json_grace_recv = json_object_new_object();
10083
10084 if (p->status == Established) {
10085 FOREACH_AFI_SAFI (afi, safi) {
10086 if (CHECK_FLAG(p->af_sflags[afi][safi],
10087 PEER_STATUS_EOR_SEND)) {
10088 json_object_boolean_true_add(
10089 json_grace_send,
10090 afi_safi_print(afi,
10091 safi));
10092 eor_send_af_count++;
10093 }
10094 }
10095 FOREACH_AFI_SAFI (afi, safi) {
10096 if (CHECK_FLAG(
10097 p->af_sflags[afi][safi],
10098 PEER_STATUS_EOR_RECEIVED)) {
10099 json_object_boolean_true_add(
10100 json_grace_recv,
10101 afi_safi_print(afi,
10102 safi));
10103 eor_receive_af_count++;
10104 }
10105 }
10106 }
10107
10108 json_object_object_add(json_grace, "endOfRibSend",
10109 json_grace_send);
10110 json_object_object_add(json_grace, "endOfRibRecv",
10111 json_grace_recv);
10112
10113 if (p->t_gr_restart)
10114 json_object_int_add(json_grace,
10115 "gracefulRestartTimerMsecs",
10116 thread_timer_remain_second(
10117 p->t_gr_restart)
10118 * 1000);
10119
10120 if (p->t_gr_stale)
10121 json_object_int_add(
10122 json_grace,
10123 "gracefulStalepathTimerMsecs",
10124 thread_timer_remain_second(
10125 p->t_gr_stale)
10126 * 1000);
10127
10128 json_object_object_add(
10129 json_neigh, "gracefulRestartInfo", json_grace);
10130 } else {
10131 vty_out(vty, " Graceful restart informations:\n");
10132 if (p->status == Established) {
10133 vty_out(vty, " End-of-RIB send: ");
10134 FOREACH_AFI_SAFI (afi, safi) {
10135 if (CHECK_FLAG(p->af_sflags[afi][safi],
10136 PEER_STATUS_EOR_SEND)) {
10137 vty_out(vty, "%s%s",
10138 eor_send_af_count ? ", "
10139 : "",
10140 afi_safi_print(afi,
10141 safi));
10142 eor_send_af_count++;
10143 }
10144 }
10145 vty_out(vty, "\n");
10146 vty_out(vty, " End-of-RIB received: ");
10147 FOREACH_AFI_SAFI (afi, safi) {
10148 if (CHECK_FLAG(
10149 p->af_sflags[afi][safi],
10150 PEER_STATUS_EOR_RECEIVED)) {
10151 vty_out(vty, "%s%s",
10152 eor_receive_af_count
10153 ? ", "
10154 : "",
10155 afi_safi_print(afi,
10156 safi));
10157 eor_receive_af_count++;
10158 }
10159 }
10160 vty_out(vty, "\n");
10161 }
10162
10163 if (p->t_gr_restart)
10164 vty_out(vty,
10165 " The remaining time of restart timer is %ld\n",
10166 thread_timer_remain_second(
10167 p->t_gr_restart));
10168
10169 if (p->t_gr_stale)
10170 vty_out(vty,
10171 " The remaining time of stalepath timer is %ld\n",
10172 thread_timer_remain_second(
10173 p->t_gr_stale));
10174 }
10175 }
10176 if (use_json) {
10177 json_object *json_stat = NULL;
10178 json_stat = json_object_new_object();
10179 /* Packet counts. */
10180 json_object_int_add(json_stat, "depthInq", 0);
10181 json_object_int_add(json_stat, "depthOutq",
10182 (unsigned long)p->obuf->count);
10183 json_object_int_add(json_stat, "opensSent",
10184 atomic_load_explicit(&p->open_out,
10185 memory_order_relaxed));
10186 json_object_int_add(json_stat, "opensRecv",
10187 atomic_load_explicit(&p->open_in,
10188 memory_order_relaxed));
10189 json_object_int_add(json_stat, "notificationsSent",
10190 atomic_load_explicit(&p->notify_out,
10191 memory_order_relaxed));
10192 json_object_int_add(json_stat, "notificationsRecv",
10193 atomic_load_explicit(&p->notify_in,
10194 memory_order_relaxed));
10195 json_object_int_add(json_stat, "updatesSent",
10196 atomic_load_explicit(&p->update_out,
10197 memory_order_relaxed));
10198 json_object_int_add(json_stat, "updatesRecv",
10199 atomic_load_explicit(&p->update_in,
10200 memory_order_relaxed));
10201 json_object_int_add(json_stat, "keepalivesSent",
10202 atomic_load_explicit(&p->keepalive_out,
10203 memory_order_relaxed));
10204 json_object_int_add(json_stat, "keepalivesRecv",
10205 atomic_load_explicit(&p->keepalive_in,
10206 memory_order_relaxed));
10207 json_object_int_add(json_stat, "routeRefreshSent",
10208 atomic_load_explicit(&p->refresh_out,
10209 memory_order_relaxed));
10210 json_object_int_add(json_stat, "routeRefreshRecv",
10211 atomic_load_explicit(&p->refresh_in,
10212 memory_order_relaxed));
10213 json_object_int_add(json_stat, "capabilitySent",
10214 atomic_load_explicit(&p->dynamic_cap_out,
10215 memory_order_relaxed));
10216 json_object_int_add(json_stat, "capabilityRecv",
10217 atomic_load_explicit(&p->dynamic_cap_in,
10218 memory_order_relaxed));
10219 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10220 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10221 json_object_object_add(json_neigh, "messageStats", json_stat);
10222 } else {
10223 /* Packet counts. */
10224 vty_out(vty, " Message statistics:\n");
10225 vty_out(vty, " Inq depth is 0\n");
10226 vty_out(vty, " Outq depth is %lu\n",
10227 (unsigned long)p->obuf->count);
10228 vty_out(vty, " Sent Rcvd\n");
10229 vty_out(vty, " Opens: %10d %10d\n",
10230 atomic_load_explicit(&p->open_out,
10231 memory_order_relaxed),
10232 atomic_load_explicit(&p->open_in,
10233 memory_order_relaxed));
10234 vty_out(vty, " Notifications: %10d %10d\n",
10235 atomic_load_explicit(&p->notify_out,
10236 memory_order_relaxed),
10237 atomic_load_explicit(&p->notify_in,
10238 memory_order_relaxed));
10239 vty_out(vty, " Updates: %10d %10d\n",
10240 atomic_load_explicit(&p->update_out,
10241 memory_order_relaxed),
10242 atomic_load_explicit(&p->update_in,
10243 memory_order_relaxed));
10244 vty_out(vty, " Keepalives: %10d %10d\n",
10245 atomic_load_explicit(&p->keepalive_out,
10246 memory_order_relaxed),
10247 atomic_load_explicit(&p->keepalive_in,
10248 memory_order_relaxed));
10249 vty_out(vty, " Route Refresh: %10d %10d\n",
10250 atomic_load_explicit(&p->refresh_out,
10251 memory_order_relaxed),
10252 atomic_load_explicit(&p->refresh_in,
10253 memory_order_relaxed));
10254 vty_out(vty, " Capability: %10d %10d\n",
10255 atomic_load_explicit(&p->dynamic_cap_out,
10256 memory_order_relaxed),
10257 atomic_load_explicit(&p->dynamic_cap_in,
10258 memory_order_relaxed));
10259 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10260 PEER_TOTAL_RX(p));
10261 }
10262
10263 if (use_json) {
10264 /* advertisement-interval */
10265 json_object_int_add(json_neigh,
10266 "minBtwnAdvertisementRunsTimerMsecs",
10267 p->v_routeadv * 1000);
10268
10269 /* Update-source. */
10270 if (p->update_if || p->update_source) {
10271 if (p->update_if)
10272 json_object_string_add(json_neigh,
10273 "updateSource",
10274 p->update_if);
10275 else if (p->update_source)
10276 json_object_string_add(
10277 json_neigh, "updateSource",
10278 sockunion2str(p->update_source, buf1,
10279 SU_ADDRSTRLEN));
10280 }
10281 } else {
10282 /* advertisement-interval */
10283 vty_out(vty,
10284 " Minimum time between advertisement runs is %d seconds\n",
10285 p->v_routeadv);
10286
10287 /* Update-source. */
10288 if (p->update_if || p->update_source) {
10289 vty_out(vty, " Update source is ");
10290 if (p->update_if)
10291 vty_out(vty, "%s", p->update_if);
10292 else if (p->update_source)
10293 vty_out(vty, "%s",
10294 sockunion2str(p->update_source, buf1,
10295 SU_ADDRSTRLEN));
10296 vty_out(vty, "\n");
10297 }
10298
10299 vty_out(vty, "\n");
10300 }
10301
10302 /* Address Family Information */
10303 json_object *json_hold = NULL;
10304
10305 if (use_json)
10306 json_hold = json_object_new_object();
10307
10308 FOREACH_AFI_SAFI (afi, safi)
10309 if (p->afc[afi][safi])
10310 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10311 json_hold);
10312
10313 if (use_json) {
10314 json_object_object_add(json_neigh, "addressFamilyInfo",
10315 json_hold);
10316 json_object_int_add(json_neigh, "connectionsEstablished",
10317 p->established);
10318 json_object_int_add(json_neigh, "connectionsDropped",
10319 p->dropped);
10320 } else
10321 vty_out(vty, " Connections established %d; dropped %d\n",
10322 p->established, p->dropped);
10323
10324 if (!p->last_reset) {
10325 if (use_json)
10326 json_object_string_add(json_neigh, "lastReset",
10327 "never");
10328 else
10329 vty_out(vty, " Last reset never\n");
10330 } else {
10331 if (use_json) {
10332 time_t uptime;
10333 struct tm *tm;
10334
10335 uptime = bgp_clock();
10336 uptime -= p->resettime;
10337 tm = gmtime(&uptime);
10338 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10339 (tm->tm_sec * 1000)
10340 + (tm->tm_min * 60000)
10341 + (tm->tm_hour * 3600000));
10342 json_object_string_add(
10343 json_neigh, "lastResetDueTo",
10344 peer_down_str[(int)p->last_reset]);
10345 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10346 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10347 char errorcodesubcode_hexstr[5];
10348 char errorcodesubcode_str[256];
10349
10350 code_str = bgp_notify_code_str(p->notify.code);
10351 subcode_str = bgp_notify_subcode_str(
10352 p->notify.code, p->notify.subcode);
10353
10354 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10355 p->notify.code, p->notify.subcode);
10356 json_object_string_add(json_neigh,
10357 "lastErrorCodeSubcode",
10358 errorcodesubcode_hexstr);
10359 snprintf(errorcodesubcode_str, 255, "%s%s",
10360 code_str, subcode_str);
10361 json_object_string_add(json_neigh,
10362 "lastNotificationReason",
10363 errorcodesubcode_str);
10364 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10365 && p->notify.code == BGP_NOTIFY_CEASE
10366 && (p->notify.subcode
10367 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10368 || p->notify.subcode
10369 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10370 && p->notify.length) {
10371 char msgbuf[1024];
10372 const char *msg_str;
10373
10374 msg_str = bgp_notify_admin_message(
10375 msgbuf, sizeof(msgbuf),
10376 (uint8_t *)p->notify.data,
10377 p->notify.length);
10378 if (msg_str)
10379 json_object_string_add(
10380 json_neigh,
10381 "lastShutdownDescription",
10382 msg_str);
10383 }
10384 }
10385 } else {
10386 vty_out(vty, " Last reset %s, ",
10387 peer_uptime(p->resettime, timebuf,
10388 BGP_UPTIME_LEN, 0, NULL));
10389
10390 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10391 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10392 code_str = bgp_notify_code_str(p->notify.code);
10393 subcode_str = bgp_notify_subcode_str(
10394 p->notify.code, p->notify.subcode);
10395 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10396 p->last_reset == PEER_DOWN_NOTIFY_SEND
10397 ? "sent"
10398 : "received",
10399 code_str, subcode_str);
10400 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10401 && p->notify.code == BGP_NOTIFY_CEASE
10402 && (p->notify.subcode
10403 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10404 || p->notify.subcode
10405 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10406 && p->notify.length) {
10407 char msgbuf[1024];
10408 const char *msg_str;
10409
10410 msg_str = bgp_notify_admin_message(
10411 msgbuf, sizeof(msgbuf),
10412 (uint8_t *)p->notify.data,
10413 p->notify.length);
10414 if (msg_str)
10415 vty_out(vty,
10416 " Message: \"%s\"\n",
10417 msg_str);
10418 }
10419 } else {
10420 vty_out(vty, "due to %s\n",
10421 peer_down_str[(int)p->last_reset]);
10422 }
10423
10424 if (p->last_reset_cause_size) {
10425 msg = p->last_reset_cause;
10426 vty_out(vty,
10427 " Message received that caused BGP to send a NOTIFICATION:\n ");
10428 for (i = 1; i <= p->last_reset_cause_size;
10429 i++) {
10430 vty_out(vty, "%02X", *msg++);
10431
10432 if (i != p->last_reset_cause_size) {
10433 if (i % 16 == 0) {
10434 vty_out(vty, "\n ");
10435 } else if (i % 4 == 0) {
10436 vty_out(vty, " ");
10437 }
10438 }
10439 }
10440 vty_out(vty, "\n");
10441 }
10442 }
10443 }
10444
10445 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10446 if (use_json)
10447 json_object_boolean_true_add(json_neigh,
10448 "prefixesConfigExceedMax");
10449 else
10450 vty_out(vty,
10451 " Peer had exceeded the max. no. of prefixes configured.\n");
10452
10453 if (p->t_pmax_restart) {
10454 if (use_json) {
10455 json_object_boolean_true_add(
10456 json_neigh, "reducePrefixNumFrom");
10457 json_object_int_add(json_neigh,
10458 "restartInTimerMsec",
10459 thread_timer_remain_second(
10460 p->t_pmax_restart)
10461 * 1000);
10462 } else
10463 vty_out(vty,
10464 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10465 p->host, thread_timer_remain_second(
10466 p->t_pmax_restart));
10467 } else {
10468 if (use_json)
10469 json_object_boolean_true_add(
10470 json_neigh,
10471 "reducePrefixNumAndClearIpBgp");
10472 else
10473 vty_out(vty,
10474 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10475 p->host);
10476 }
10477 }
10478
10479 /* EBGP Multihop and GTSM */
10480 if (p->sort != BGP_PEER_IBGP) {
10481 if (use_json) {
10482 if (p->gtsm_hops > 0)
10483 json_object_int_add(json_neigh,
10484 "externalBgpNbrMaxHopsAway",
10485 p->gtsm_hops);
10486 else if (p->ttl > 1)
10487 json_object_int_add(json_neigh,
10488 "externalBgpNbrMaxHopsAway",
10489 p->ttl);
10490 } else {
10491 if (p->gtsm_hops > 0)
10492 vty_out(vty,
10493 " External BGP neighbor may be up to %d hops away.\n",
10494 p->gtsm_hops);
10495 else if (p->ttl > 1)
10496 vty_out(vty,
10497 " External BGP neighbor may be up to %d hops away.\n",
10498 p->ttl);
10499 }
10500 } else {
10501 if (p->gtsm_hops > 0) {
10502 if (use_json)
10503 json_object_int_add(json_neigh,
10504 "internalBgpNbrMaxHopsAway",
10505 p->gtsm_hops);
10506 else
10507 vty_out(vty,
10508 " Internal BGP neighbor may be up to %d hops away.\n",
10509 p->gtsm_hops);
10510 }
10511 }
10512
10513 /* Local address. */
10514 if (p->su_local) {
10515 if (use_json) {
10516 json_object_string_add(json_neigh, "hostLocal",
10517 sockunion2str(p->su_local, buf1,
10518 SU_ADDRSTRLEN));
10519 json_object_int_add(json_neigh, "portLocal",
10520 ntohs(p->su_local->sin.sin_port));
10521 } else
10522 vty_out(vty, "Local host: %s, Local port: %d\n",
10523 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10524 ntohs(p->su_local->sin.sin_port));
10525 }
10526
10527 /* Remote address. */
10528 if (p->su_remote) {
10529 if (use_json) {
10530 json_object_string_add(json_neigh, "hostForeign",
10531 sockunion2str(p->su_remote, buf1,
10532 SU_ADDRSTRLEN));
10533 json_object_int_add(json_neigh, "portForeign",
10534 ntohs(p->su_remote->sin.sin_port));
10535 } else
10536 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10537 sockunion2str(p->su_remote, buf1,
10538 SU_ADDRSTRLEN),
10539 ntohs(p->su_remote->sin.sin_port));
10540 }
10541
10542 /* Nexthop display. */
10543 if (p->su_local) {
10544 if (use_json) {
10545 json_object_string_add(json_neigh, "nexthop",
10546 inet_ntop(AF_INET,
10547 &p->nexthop.v4, buf1,
10548 sizeof(buf1)));
10549 json_object_string_add(json_neigh, "nexthopGlobal",
10550 inet_ntop(AF_INET6,
10551 &p->nexthop.v6_global,
10552 buf1, sizeof(buf1)));
10553 json_object_string_add(json_neigh, "nexthopLocal",
10554 inet_ntop(AF_INET6,
10555 &p->nexthop.v6_local,
10556 buf1, sizeof(buf1)));
10557 if (p->shared_network)
10558 json_object_string_add(json_neigh,
10559 "bgpConnection",
10560 "sharedNetwork");
10561 else
10562 json_object_string_add(json_neigh,
10563 "bgpConnection",
10564 "nonSharedNetwork");
10565 } else {
10566 vty_out(vty, "Nexthop: %s\n",
10567 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10568 sizeof(buf1)));
10569 vty_out(vty, "Nexthop global: %s\n",
10570 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10571 sizeof(buf1)));
10572 vty_out(vty, "Nexthop local: %s\n",
10573 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10574 sizeof(buf1)));
10575 vty_out(vty, "BGP connection: %s\n",
10576 p->shared_network ? "shared network"
10577 : "non shared network");
10578 }
10579 }
10580
10581 /* Timer information. */
10582 if (use_json) {
10583 json_object_int_add(json_neigh, "connectRetryTimer",
10584 p->v_connect);
10585 if (p->status == Established && p->rtt)
10586 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10587 p->rtt);
10588 if (p->t_start)
10589 json_object_int_add(
10590 json_neigh, "nextStartTimerDueInMsecs",
10591 thread_timer_remain_second(p->t_start) * 1000);
10592 if (p->t_connect)
10593 json_object_int_add(
10594 json_neigh, "nextConnectTimerDueInMsecs",
10595 thread_timer_remain_second(p->t_connect)
10596 * 1000);
10597 if (p->t_routeadv) {
10598 json_object_int_add(json_neigh, "mraiInterval",
10599 p->v_routeadv);
10600 json_object_int_add(
10601 json_neigh, "mraiTimerExpireInMsecs",
10602 thread_timer_remain_second(p->t_routeadv)
10603 * 1000);
10604 }
10605 if (p->password)
10606 json_object_int_add(json_neigh, "authenticationEnabled",
10607 1);
10608
10609 if (p->t_read)
10610 json_object_string_add(json_neigh, "readThread", "on");
10611 else
10612 json_object_string_add(json_neigh, "readThread", "off");
10613
10614 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10615 json_object_string_add(json_neigh, "writeThread", "on");
10616 else
10617 json_object_string_add(json_neigh, "writeThread",
10618 "off");
10619 } else {
10620 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10621 p->v_connect);
10622 if (p->status == Established && p->rtt)
10623 vty_out(vty, "Estimated round trip time: %d ms\n",
10624 p->rtt);
10625 if (p->t_start)
10626 vty_out(vty, "Next start timer due in %ld seconds\n",
10627 thread_timer_remain_second(p->t_start));
10628 if (p->t_connect)
10629 vty_out(vty, "Next connect timer due in %ld seconds\n",
10630 thread_timer_remain_second(p->t_connect));
10631 if (p->t_routeadv)
10632 vty_out(vty,
10633 "MRAI (interval %u) timer expires in %ld seconds\n",
10634 p->v_routeadv,
10635 thread_timer_remain_second(p->t_routeadv));
10636 if (p->password)
10637 vty_out(vty, "Peer Authentication Enabled\n");
10638
10639 vty_out(vty, "Read thread: %s Write thread: %s\n",
10640 p->t_read ? "on" : "off",
10641 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10642 ? "on"
10643 : "off");
10644 }
10645
10646 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10647 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10648 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10649
10650 if (!use_json)
10651 vty_out(vty, "\n");
10652
10653 /* BFD information. */
10654 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10655
10656 if (use_json) {
10657 if (p->conf_if) /* Configured interface name. */
10658 json_object_object_add(json, p->conf_if, json_neigh);
10659 else /* Configured IP address. */
10660 json_object_object_add(json, p->host, json_neigh);
10661 }
10662 }
10663
10664 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10665 enum show_type type, union sockunion *su,
10666 const char *conf_if, uint8_t use_json,
10667 json_object *json)
10668 {
10669 struct listnode *node, *nnode;
10670 struct peer *peer;
10671 int find = 0;
10672
10673 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10674 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10675 continue;
10676
10677 switch (type) {
10678 case show_all:
10679 bgp_show_peer(vty, peer, use_json, json);
10680 break;
10681 case show_peer:
10682 if (conf_if) {
10683 if ((peer->conf_if
10684 && !strcmp(peer->conf_if, conf_if))
10685 || (peer->hostname
10686 && !strcmp(peer->hostname, conf_if))) {
10687 find = 1;
10688 bgp_show_peer(vty, peer, use_json,
10689 json);
10690 }
10691 } else {
10692 if (sockunion_same(&peer->su, su)) {
10693 find = 1;
10694 bgp_show_peer(vty, peer, use_json,
10695 json);
10696 }
10697 }
10698 break;
10699 }
10700 }
10701
10702 if (type == show_peer && !find) {
10703 if (use_json)
10704 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10705 else
10706 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10707 }
10708
10709 if (use_json) {
10710 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10711 json, JSON_C_TO_STRING_PRETTY));
10712 json_object_free(json);
10713 } else {
10714 vty_out(vty, "\n");
10715 }
10716
10717 return CMD_SUCCESS;
10718 }
10719
10720 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10721 enum show_type type,
10722 const char *ip_str,
10723 uint8_t use_json)
10724 {
10725 struct listnode *node, *nnode;
10726 struct bgp *bgp;
10727 union sockunion su;
10728 json_object *json = NULL;
10729 int ret, is_first = 1;
10730
10731 if (use_json)
10732 vty_out(vty, "{\n");
10733
10734 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10735 if (use_json) {
10736 if (!(json = json_object_new_object())) {
10737 zlog_err(
10738 "Unable to allocate memory for JSON object");
10739 vty_out(vty,
10740 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10741 return;
10742 }
10743
10744 json_object_int_add(json, "vrfId",
10745 (bgp->vrf_id == VRF_UNKNOWN)
10746 ? -1
10747 : (int64_t)bgp->vrf_id);
10748 json_object_string_add(
10749 json, "vrfName",
10750 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10751 ? "Default"
10752 : bgp->name);
10753
10754 if (!is_first)
10755 vty_out(vty, ",\n");
10756 else
10757 is_first = 0;
10758
10759 vty_out(vty, "\"%s\":",
10760 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10761 ? "Default"
10762 : bgp->name);
10763 } else {
10764 vty_out(vty, "\nInstance %s:\n",
10765 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10766 ? "Default"
10767 : bgp->name);
10768 }
10769
10770 if (type == show_peer) {
10771 ret = str2sockunion(ip_str, &su);
10772 if (ret < 0)
10773 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10774 use_json, json);
10775 else
10776 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10777 use_json, json);
10778 } else {
10779 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10780 use_json, json);
10781 }
10782 }
10783
10784 if (use_json)
10785 vty_out(vty, "}\n");
10786 }
10787
10788 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10789 enum show_type type, const char *ip_str,
10790 uint8_t use_json)
10791 {
10792 int ret;
10793 struct bgp *bgp;
10794 union sockunion su;
10795 json_object *json = NULL;
10796
10797 if (name) {
10798 if (strmatch(name, "all")) {
10799 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10800 use_json);
10801 return CMD_SUCCESS;
10802 } else {
10803 bgp = bgp_lookup_by_name(name);
10804 if (!bgp) {
10805 if (use_json) {
10806 json = json_object_new_object();
10807 json_object_boolean_true_add(
10808 json, "bgpNoSuchInstance");
10809 vty_out(vty, "%s\n",
10810 json_object_to_json_string_ext(
10811 json,
10812 JSON_C_TO_STRING_PRETTY));
10813 json_object_free(json);
10814 } else
10815 vty_out(vty,
10816 "%% No such BGP instance exist\n");
10817
10818 return CMD_WARNING;
10819 }
10820 }
10821 } else {
10822 bgp = bgp_get_default();
10823 }
10824
10825 if (bgp) {
10826 json = json_object_new_object();
10827 if (ip_str) {
10828 ret = str2sockunion(ip_str, &su);
10829 if (ret < 0)
10830 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10831 use_json, json);
10832 else
10833 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10834 use_json, json);
10835 } else {
10836 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10837 json);
10838 }
10839 json_object_free(json);
10840 }
10841
10842 return CMD_SUCCESS;
10843 }
10844
10845 /* "show [ip] bgp neighbors" commands. */
10846 DEFUN (show_ip_bgp_neighbors,
10847 show_ip_bgp_neighbors_cmd,
10848 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10849 SHOW_STR
10850 IP_STR
10851 BGP_STR
10852 BGP_INSTANCE_HELP_STR
10853 "Address Family\n"
10854 "Address Family\n"
10855 "Detailed information on TCP and BGP neighbor connections\n"
10856 "Neighbor to display information about\n"
10857 "Neighbor to display information about\n"
10858 "Neighbor on BGP configured interface\n"
10859 JSON_STR)
10860 {
10861 char *vrf = NULL;
10862 char *sh_arg = NULL;
10863 enum show_type sh_type;
10864
10865 uint8_t uj = use_json(argc, argv);
10866
10867 int idx = 0;
10868
10869 if (argv_find(argv, argc, "view", &idx)
10870 || argv_find(argv, argc, "vrf", &idx))
10871 vrf = argv[idx + 1]->arg;
10872
10873 idx++;
10874 if (argv_find(argv, argc, "A.B.C.D", &idx)
10875 || argv_find(argv, argc, "X:X::X:X", &idx)
10876 || argv_find(argv, argc, "WORD", &idx)) {
10877 sh_type = show_peer;
10878 sh_arg = argv[idx]->arg;
10879 } else
10880 sh_type = show_all;
10881
10882 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10883 }
10884
10885 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10886 paths' and `show ip mbgp paths'. Those functions results are the
10887 same.*/
10888 DEFUN (show_ip_bgp_paths,
10889 show_ip_bgp_paths_cmd,
10890 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10891 SHOW_STR
10892 IP_STR
10893 BGP_STR
10894 BGP_SAFI_HELP_STR
10895 "Path information\n")
10896 {
10897 vty_out(vty, "Address Refcnt Path\n");
10898 aspath_print_all_vty(vty);
10899 return CMD_SUCCESS;
10900 }
10901
10902 #include "hash.h"
10903
10904 static void community_show_all_iterator(struct hash_backet *backet,
10905 struct vty *vty)
10906 {
10907 struct community *com;
10908
10909 com = (struct community *)backet->data;
10910 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10911 community_str(com, false));
10912 }
10913
10914 /* Show BGP's community internal data. */
10915 DEFUN (show_ip_bgp_community_info,
10916 show_ip_bgp_community_info_cmd,
10917 "show [ip] bgp community-info",
10918 SHOW_STR
10919 IP_STR
10920 BGP_STR
10921 "List all bgp community information\n")
10922 {
10923 vty_out(vty, "Address Refcnt Community\n");
10924
10925 hash_iterate(community_hash(),
10926 (void (*)(struct hash_backet *,
10927 void *))community_show_all_iterator,
10928 vty);
10929
10930 return CMD_SUCCESS;
10931 }
10932
10933 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10934 struct vty *vty)
10935 {
10936 struct lcommunity *lcom;
10937
10938 lcom = (struct lcommunity *)backet->data;
10939 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10940 lcommunity_str(lcom, false));
10941 }
10942
10943 /* Show BGP's community internal data. */
10944 DEFUN (show_ip_bgp_lcommunity_info,
10945 show_ip_bgp_lcommunity_info_cmd,
10946 "show ip bgp large-community-info",
10947 SHOW_STR
10948 IP_STR
10949 BGP_STR
10950 "List all bgp large-community information\n")
10951 {
10952 vty_out(vty, "Address Refcnt Large-community\n");
10953
10954 hash_iterate(lcommunity_hash(),
10955 (void (*)(struct hash_backet *,
10956 void *))lcommunity_show_all_iterator,
10957 vty);
10958
10959 return CMD_SUCCESS;
10960 }
10961
10962
10963 DEFUN (show_ip_bgp_attr_info,
10964 show_ip_bgp_attr_info_cmd,
10965 "show [ip] bgp attribute-info",
10966 SHOW_STR
10967 IP_STR
10968 BGP_STR
10969 "List all bgp attribute information\n")
10970 {
10971 attr_show_all(vty);
10972 return CMD_SUCCESS;
10973 }
10974
10975 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10976 afi_t afi, safi_t safi)
10977 {
10978 struct bgp *bgp;
10979 struct listnode *node;
10980 char *vname;
10981 char buf1[INET6_ADDRSTRLEN];
10982 char *ecom_str;
10983 vpn_policy_direction_t dir;
10984
10985 if (name) {
10986 bgp = bgp_lookup_by_name(name);
10987 if (!bgp) {
10988 vty_out(vty, "%% No such BGP instance exist\n");
10989 return CMD_WARNING;
10990 }
10991 } else {
10992 bgp = bgp_get_default();
10993 if (!bgp) {
10994 vty_out(vty,
10995 "%% Default BGP instance does not exist\n");
10996 return CMD_WARNING;
10997 }
10998 }
10999
11000 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11001 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11002 vty_out(vty,
11003 "This VRF is not importing %s routes from any other VRF\n",
11004 afi_safi_print(afi, safi));
11005 } else {
11006 vty_out(vty,
11007 "This VRF is importing %s routes from the following VRFs:\n",
11008 afi_safi_print(afi, safi));
11009 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
11010 vname)) {
11011 vty_out(vty, " %s\n", vname);
11012 }
11013 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11014 ecom_str = ecommunity_ecom2str(
11015 bgp->vpn_policy[afi].rtlist[dir],
11016 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11017 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11018 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11019 }
11020
11021 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11022 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11023 vty_out(vty,
11024 "This VRF is not exporting %s routes to any other VRF\n",
11025 afi_safi_print(afi, safi));
11026 } else {
11027 vty_out(vty,
11028 "This VRF is exporting %s routes to the following VRFs:\n",
11029 afi_safi_print(afi, safi));
11030 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11031 vname)) {
11032 vty_out(vty, " %s\n", vname);
11033 }
11034 vty_out(vty, "RD: %s\n",
11035 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11036 buf1, RD_ADDRSTRLEN));
11037 dir = BGP_VPN_POLICY_DIR_TOVPN;
11038 ecom_str = ecommunity_ecom2str(
11039 bgp->vpn_policy[afi].rtlist[dir],
11040 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11041 vty_out(vty, "Emport RT: %s\n", ecom_str);
11042 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11043 }
11044
11045 return CMD_SUCCESS;
11046 }
11047
11048 /* "show [ip] bgp route-leak" command. */
11049 DEFUN (show_ip_bgp_route_leak,
11050 show_ip_bgp_route_leak_cmd,
11051 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11052 SHOW_STR
11053 IP_STR
11054 BGP_STR
11055 BGP_INSTANCE_HELP_STR
11056 BGP_AFI_HELP_STR
11057 BGP_SAFI_HELP_STR
11058 "Route leaking information\n")
11059 {
11060 char *vrf = NULL;
11061 afi_t afi = AFI_MAX;
11062 safi_t safi = SAFI_MAX;
11063
11064 int idx = 0;
11065
11066 /* show [ip] bgp */
11067 if (argv_find(argv, argc, "ip", &idx)) {
11068 afi = AFI_IP;
11069 safi = SAFI_UNICAST;
11070 }
11071 /* [vrf VIEWVRFNAME] */
11072 if (argv_find(argv, argc, "view", &idx)) {
11073 vty_out(vty,
11074 "%% This command is not applicable to BGP views\n");
11075 return CMD_WARNING;
11076 }
11077
11078 if (argv_find(argv, argc, "vrf", &idx))
11079 vrf = argv[++idx]->arg;
11080 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11081 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11082 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11083 }
11084
11085 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11086 vty_out(vty,
11087 "%% This command is applicable only for unicast ipv4|ipv6\n");
11088 return CMD_WARNING;
11089 }
11090
11091 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11092 }
11093
11094 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11095 safi_t safi)
11096 {
11097 struct listnode *node, *nnode;
11098 struct bgp *bgp;
11099
11100 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11101 vty_out(vty, "\nInstance %s:\n",
11102 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11103 ? "Default"
11104 : bgp->name);
11105 update_group_show(bgp, afi, safi, vty, 0);
11106 }
11107 }
11108
11109 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11110 int safi, uint64_t subgrp_id)
11111 {
11112 struct bgp *bgp;
11113
11114 if (name) {
11115 if (strmatch(name, "all")) {
11116 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11117 return CMD_SUCCESS;
11118 } else {
11119 bgp = bgp_lookup_by_name(name);
11120 }
11121 } else {
11122 bgp = bgp_get_default();
11123 }
11124
11125 if (bgp)
11126 update_group_show(bgp, afi, safi, vty, subgrp_id);
11127 return CMD_SUCCESS;
11128 }
11129
11130 DEFUN (show_ip_bgp_updgrps,
11131 show_ip_bgp_updgrps_cmd,
11132 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11133 SHOW_STR
11134 IP_STR
11135 BGP_STR
11136 BGP_INSTANCE_HELP_STR
11137 BGP_AFI_HELP_STR
11138 BGP_SAFI_WITH_LABEL_HELP_STR
11139 "Detailed info about dynamic update groups\n"
11140 "Specific subgroup to display detailed info for\n")
11141 {
11142 char *vrf = NULL;
11143 afi_t afi = AFI_IP6;
11144 safi_t safi = SAFI_UNICAST;
11145 uint64_t subgrp_id = 0;
11146
11147 int idx = 0;
11148
11149 /* show [ip] bgp */
11150 if (argv_find(argv, argc, "ip", &idx))
11151 afi = AFI_IP;
11152 /* [<view|vrf> VIEWVRFNAME] */
11153 if (argv_find(argv, argc, "view", &idx)
11154 || argv_find(argv, argc, "vrf", &idx))
11155 vrf = argv[++idx]->arg;
11156 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11157 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11158 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11159 }
11160
11161 /* get subgroup id, if provided */
11162 idx = argc - 1;
11163 if (argv[idx]->type == VARIABLE_TKN)
11164 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11165
11166 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11167 }
11168
11169 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11170 show_bgp_instance_all_ipv6_updgrps_cmd,
11171 "show [ip] bgp <view|vrf> all update-groups",
11172 SHOW_STR
11173 IP_STR
11174 BGP_STR
11175 BGP_INSTANCE_ALL_HELP_STR
11176 "Detailed info about dynamic update groups\n")
11177 {
11178 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11179 return CMD_SUCCESS;
11180 }
11181
11182 DEFUN (show_bgp_updgrps_stats,
11183 show_bgp_updgrps_stats_cmd,
11184 "show [ip] bgp update-groups statistics",
11185 SHOW_STR
11186 IP_STR
11187 BGP_STR
11188 "Detailed info about dynamic update groups\n"
11189 "Statistics\n")
11190 {
11191 struct bgp *bgp;
11192
11193 bgp = bgp_get_default();
11194 if (bgp)
11195 update_group_show_stats(bgp, vty);
11196
11197 return CMD_SUCCESS;
11198 }
11199
11200 DEFUN (show_bgp_instance_updgrps_stats,
11201 show_bgp_instance_updgrps_stats_cmd,
11202 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11203 SHOW_STR
11204 IP_STR
11205 BGP_STR
11206 BGP_INSTANCE_HELP_STR
11207 "Detailed info about dynamic update groups\n"
11208 "Statistics\n")
11209 {
11210 int idx_word = 3;
11211 struct bgp *bgp;
11212
11213 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11214 if (bgp)
11215 update_group_show_stats(bgp, vty);
11216
11217 return CMD_SUCCESS;
11218 }
11219
11220 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11221 afi_t afi, safi_t safi,
11222 const char *what, uint64_t subgrp_id)
11223 {
11224 struct bgp *bgp;
11225
11226 if (name)
11227 bgp = bgp_lookup_by_name(name);
11228 else
11229 bgp = bgp_get_default();
11230
11231 if (bgp) {
11232 if (!strcmp(what, "advertise-queue"))
11233 update_group_show_adj_queue(bgp, afi, safi, vty,
11234 subgrp_id);
11235 else if (!strcmp(what, "advertised-routes"))
11236 update_group_show_advertised(bgp, afi, safi, vty,
11237 subgrp_id);
11238 else if (!strcmp(what, "packet-queue"))
11239 update_group_show_packet_queue(bgp, afi, safi, vty,
11240 subgrp_id);
11241 }
11242 }
11243
11244 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11245 show_ip_bgp_instance_updgrps_adj_s_cmd,
11246 "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",
11247 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11248 BGP_SAFI_HELP_STR
11249 "Detailed info about dynamic update groups\n"
11250 "Specific subgroup to display info for\n"
11251 "Advertisement queue\n"
11252 "Announced routes\n"
11253 "Packet queue\n")
11254 {
11255 uint64_t subgrp_id = 0;
11256 afi_t afiz;
11257 safi_t safiz;
11258 if (sgid)
11259 subgrp_id = strtoull(sgid, NULL, 10);
11260
11261 if (!ip && !afi)
11262 afiz = AFI_IP6;
11263 if (!ip && afi)
11264 afiz = bgp_vty_afi_from_str(afi);
11265 if (ip && !afi)
11266 afiz = AFI_IP;
11267 if (ip && afi) {
11268 afiz = bgp_vty_afi_from_str(afi);
11269 if (afiz != AFI_IP)
11270 vty_out(vty,
11271 "%% Cannot specify both 'ip' and 'ipv6'\n");
11272 return CMD_WARNING;
11273 }
11274
11275 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11276
11277 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11278 return CMD_SUCCESS;
11279 }
11280
11281 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11282 {
11283 struct listnode *node, *nnode;
11284 struct prefix *range;
11285 struct peer *conf;
11286 struct peer *peer;
11287 char buf[PREFIX2STR_BUFFER];
11288 afi_t afi;
11289 safi_t safi;
11290 const char *peer_status;
11291 const char *af_str;
11292 int lr_count;
11293 int dynamic;
11294 int af_cfgd;
11295
11296 conf = group->conf;
11297
11298 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11299 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11300 conf->as);
11301 } else if (conf->as_type == AS_INTERNAL) {
11302 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11303 group->bgp->as);
11304 } else {
11305 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11306 }
11307
11308 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11309 vty_out(vty, " Peer-group type is internal\n");
11310 else
11311 vty_out(vty, " Peer-group type is external\n");
11312
11313 /* Display AFs configured. */
11314 vty_out(vty, " Configured address-families:");
11315 FOREACH_AFI_SAFI (afi, safi) {
11316 if (conf->afc[afi][safi]) {
11317 af_cfgd = 1;
11318 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11319 }
11320 }
11321 if (!af_cfgd)
11322 vty_out(vty, " none\n");
11323 else
11324 vty_out(vty, "\n");
11325
11326 /* Display listen ranges (for dynamic neighbors), if any */
11327 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11328 if (afi == AFI_IP)
11329 af_str = "IPv4";
11330 else if (afi == AFI_IP6)
11331 af_str = "IPv6";
11332 else
11333 af_str = "???";
11334 lr_count = listcount(group->listen_range[afi]);
11335 if (lr_count) {
11336 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11337 af_str);
11338
11339
11340 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11341 nnode, range)) {
11342 prefix2str(range, buf, sizeof(buf));
11343 vty_out(vty, " %s\n", buf);
11344 }
11345 }
11346 }
11347
11348 /* Display group members and their status */
11349 if (listcount(group->peer)) {
11350 vty_out(vty, " Peer-group members:\n");
11351 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11352 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11353 peer_status = "Idle (Admin)";
11354 else if (CHECK_FLAG(peer->sflags,
11355 PEER_STATUS_PREFIX_OVERFLOW))
11356 peer_status = "Idle (PfxCt)";
11357 else
11358 peer_status = lookup_msg(bgp_status_msg,
11359 peer->status, NULL);
11360
11361 dynamic = peer_dynamic_neighbor(peer);
11362 vty_out(vty, " %s %s %s \n", peer->host,
11363 dynamic ? "(dynamic)" : "", peer_status);
11364 }
11365 }
11366
11367 return CMD_SUCCESS;
11368 }
11369
11370 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11371 const char *group_name)
11372 {
11373 struct bgp *bgp;
11374 struct listnode *node, *nnode;
11375 struct peer_group *group;
11376 bool found = false;
11377
11378 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11379
11380 if (!bgp) {
11381 vty_out(vty, "%% No such BGP instance exists\n");
11382 return CMD_WARNING;
11383 }
11384
11385 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11386 if (group_name) {
11387 if (strmatch(group->name, group_name)) {
11388 bgp_show_one_peer_group(vty, group);
11389 found = true;
11390 break;
11391 }
11392 } else {
11393 bgp_show_one_peer_group(vty, group);
11394 }
11395 }
11396
11397 if (group_name && !found)
11398 vty_out(vty, "%% No such peer-group\n");
11399
11400 return CMD_SUCCESS;
11401 }
11402
11403 DEFUN (show_ip_bgp_peer_groups,
11404 show_ip_bgp_peer_groups_cmd,
11405 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11406 SHOW_STR
11407 IP_STR
11408 BGP_STR
11409 BGP_INSTANCE_HELP_STR
11410 "Detailed information on BGP peer groups\n"
11411 "Peer group name\n")
11412 {
11413 char *vrf, *pg;
11414 int idx = 0;
11415
11416 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11417 : NULL;
11418 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11419
11420 return bgp_show_peer_group_vty(vty, vrf, pg);
11421 }
11422
11423
11424 /* Redistribute VTY commands. */
11425
11426 DEFUN (bgp_redistribute_ipv4,
11427 bgp_redistribute_ipv4_cmd,
11428 "redistribute " FRR_IP_REDIST_STR_BGPD,
11429 "Redistribute information from another routing protocol\n"
11430 FRR_IP_REDIST_HELP_STR_BGPD)
11431 {
11432 VTY_DECLVAR_CONTEXT(bgp, bgp);
11433 int idx_protocol = 1;
11434 int type;
11435
11436 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11437 if (type < 0) {
11438 vty_out(vty, "%% Invalid route type\n");
11439 return CMD_WARNING_CONFIG_FAILED;
11440 }
11441
11442 bgp_redist_add(bgp, AFI_IP, type, 0);
11443 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11444 }
11445
11446 ALIAS_HIDDEN(
11447 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11448 "redistribute " FRR_IP_REDIST_STR_BGPD,
11449 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11450
11451 DEFUN (bgp_redistribute_ipv4_rmap,
11452 bgp_redistribute_ipv4_rmap_cmd,
11453 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11454 "Redistribute information from another routing protocol\n"
11455 FRR_IP_REDIST_HELP_STR_BGPD
11456 "Route map reference\n"
11457 "Pointer to route-map entries\n")
11458 {
11459 VTY_DECLVAR_CONTEXT(bgp, bgp);
11460 int idx_protocol = 1;
11461 int idx_word = 3;
11462 int type;
11463 struct bgp_redist *red;
11464
11465 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11466 if (type < 0) {
11467 vty_out(vty, "%% Invalid route type\n");
11468 return CMD_WARNING_CONFIG_FAILED;
11469 }
11470
11471 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11472 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11473 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11474 }
11475
11476 ALIAS_HIDDEN(
11477 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11478 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11479 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11480 "Route map reference\n"
11481 "Pointer to route-map entries\n")
11482
11483 DEFUN (bgp_redistribute_ipv4_metric,
11484 bgp_redistribute_ipv4_metric_cmd,
11485 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11486 "Redistribute information from another routing protocol\n"
11487 FRR_IP_REDIST_HELP_STR_BGPD
11488 "Metric for redistributed routes\n"
11489 "Default metric\n")
11490 {
11491 VTY_DECLVAR_CONTEXT(bgp, bgp);
11492 int idx_protocol = 1;
11493 int idx_number = 3;
11494 int type;
11495 uint32_t metric;
11496 struct bgp_redist *red;
11497
11498 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11499 if (type < 0) {
11500 vty_out(vty, "%% Invalid route type\n");
11501 return CMD_WARNING_CONFIG_FAILED;
11502 }
11503 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11504
11505 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11506 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11507 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11508 }
11509
11510 ALIAS_HIDDEN(
11511 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11512 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11513 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11514 "Metric for redistributed routes\n"
11515 "Default metric\n")
11516
11517 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11518 bgp_redistribute_ipv4_rmap_metric_cmd,
11519 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11520 "Redistribute information from another routing protocol\n"
11521 FRR_IP_REDIST_HELP_STR_BGPD
11522 "Route map reference\n"
11523 "Pointer to route-map entries\n"
11524 "Metric for redistributed routes\n"
11525 "Default metric\n")
11526 {
11527 VTY_DECLVAR_CONTEXT(bgp, bgp);
11528 int idx_protocol = 1;
11529 int idx_word = 3;
11530 int idx_number = 5;
11531 int type;
11532 uint32_t metric;
11533 struct bgp_redist *red;
11534
11535 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11536 if (type < 0) {
11537 vty_out(vty, "%% Invalid route type\n");
11538 return CMD_WARNING_CONFIG_FAILED;
11539 }
11540 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11541
11542 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11543 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11544 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11545 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11546 }
11547
11548 ALIAS_HIDDEN(
11549 bgp_redistribute_ipv4_rmap_metric,
11550 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11551 "redistribute " FRR_IP_REDIST_STR_BGPD
11552 " route-map WORD metric (0-4294967295)",
11553 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11554 "Route map reference\n"
11555 "Pointer to route-map entries\n"
11556 "Metric for redistributed routes\n"
11557 "Default metric\n")
11558
11559 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11560 bgp_redistribute_ipv4_metric_rmap_cmd,
11561 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11562 "Redistribute information from another routing protocol\n"
11563 FRR_IP_REDIST_HELP_STR_BGPD
11564 "Metric for redistributed routes\n"
11565 "Default metric\n"
11566 "Route map reference\n"
11567 "Pointer to route-map entries\n")
11568 {
11569 VTY_DECLVAR_CONTEXT(bgp, bgp);
11570 int idx_protocol = 1;
11571 int idx_number = 3;
11572 int idx_word = 5;
11573 int type;
11574 uint32_t metric;
11575 struct bgp_redist *red;
11576
11577 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11578 if (type < 0) {
11579 vty_out(vty, "%% Invalid route type\n");
11580 return CMD_WARNING_CONFIG_FAILED;
11581 }
11582 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11583
11584 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11585 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11586 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11587 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11588 }
11589
11590 ALIAS_HIDDEN(
11591 bgp_redistribute_ipv4_metric_rmap,
11592 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11593 "redistribute " FRR_IP_REDIST_STR_BGPD
11594 " metric (0-4294967295) route-map WORD",
11595 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11596 "Metric for redistributed routes\n"
11597 "Default metric\n"
11598 "Route map reference\n"
11599 "Pointer to route-map entries\n")
11600
11601 DEFUN (bgp_redistribute_ipv4_ospf,
11602 bgp_redistribute_ipv4_ospf_cmd,
11603 "redistribute <ospf|table> (1-65535)",
11604 "Redistribute information from another routing protocol\n"
11605 "Open Shortest Path First (OSPFv2)\n"
11606 "Non-main Kernel Routing Table\n"
11607 "Instance ID/Table ID\n")
11608 {
11609 VTY_DECLVAR_CONTEXT(bgp, bgp);
11610 int idx_ospf_table = 1;
11611 int idx_number = 2;
11612 unsigned short instance;
11613 unsigned short protocol;
11614
11615 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11616
11617 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11618 protocol = ZEBRA_ROUTE_OSPF;
11619 else
11620 protocol = ZEBRA_ROUTE_TABLE;
11621
11622 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11623 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11624 }
11625
11626 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11627 "redistribute <ospf|table> (1-65535)",
11628 "Redistribute information from another routing protocol\n"
11629 "Open Shortest Path First (OSPFv2)\n"
11630 "Non-main Kernel Routing Table\n"
11631 "Instance ID/Table ID\n")
11632
11633 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11634 bgp_redistribute_ipv4_ospf_rmap_cmd,
11635 "redistribute <ospf|table> (1-65535) route-map WORD",
11636 "Redistribute information from another routing protocol\n"
11637 "Open Shortest Path First (OSPFv2)\n"
11638 "Non-main Kernel Routing Table\n"
11639 "Instance ID/Table ID\n"
11640 "Route map reference\n"
11641 "Pointer to route-map entries\n")
11642 {
11643 VTY_DECLVAR_CONTEXT(bgp, bgp);
11644 int idx_ospf_table = 1;
11645 int idx_number = 2;
11646 int idx_word = 4;
11647 struct bgp_redist *red;
11648 unsigned short instance;
11649 int protocol;
11650
11651 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11652 protocol = ZEBRA_ROUTE_OSPF;
11653 else
11654 protocol = ZEBRA_ROUTE_TABLE;
11655
11656 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11657 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11658 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11659 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11660 }
11661
11662 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11663 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11664 "redistribute <ospf|table> (1-65535) route-map WORD",
11665 "Redistribute information from another routing protocol\n"
11666 "Open Shortest Path First (OSPFv2)\n"
11667 "Non-main Kernel Routing Table\n"
11668 "Instance ID/Table ID\n"
11669 "Route map reference\n"
11670 "Pointer to route-map entries\n")
11671
11672 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11673 bgp_redistribute_ipv4_ospf_metric_cmd,
11674 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11675 "Redistribute information from another routing protocol\n"
11676 "Open Shortest Path First (OSPFv2)\n"
11677 "Non-main Kernel Routing Table\n"
11678 "Instance ID/Table ID\n"
11679 "Metric for redistributed routes\n"
11680 "Default metric\n")
11681 {
11682 VTY_DECLVAR_CONTEXT(bgp, bgp);
11683 int idx_ospf_table = 1;
11684 int idx_number = 2;
11685 int idx_number_2 = 4;
11686 uint32_t metric;
11687 struct bgp_redist *red;
11688 unsigned short instance;
11689 int protocol;
11690
11691 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11692 protocol = ZEBRA_ROUTE_OSPF;
11693 else
11694 protocol = ZEBRA_ROUTE_TABLE;
11695
11696 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11697 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11698
11699 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11700 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11701 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11702 }
11703
11704 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11705 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11706 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11707 "Redistribute information from another routing protocol\n"
11708 "Open Shortest Path First (OSPFv2)\n"
11709 "Non-main Kernel Routing Table\n"
11710 "Instance ID/Table ID\n"
11711 "Metric for redistributed routes\n"
11712 "Default metric\n")
11713
11714 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11715 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11716 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11717 "Redistribute information from another routing protocol\n"
11718 "Open Shortest Path First (OSPFv2)\n"
11719 "Non-main Kernel Routing Table\n"
11720 "Instance ID/Table ID\n"
11721 "Route map reference\n"
11722 "Pointer to route-map entries\n"
11723 "Metric for redistributed routes\n"
11724 "Default metric\n")
11725 {
11726 VTY_DECLVAR_CONTEXT(bgp, bgp);
11727 int idx_ospf_table = 1;
11728 int idx_number = 2;
11729 int idx_word = 4;
11730 int idx_number_2 = 6;
11731 uint32_t metric;
11732 struct bgp_redist *red;
11733 unsigned short instance;
11734 int protocol;
11735
11736 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11737 protocol = ZEBRA_ROUTE_OSPF;
11738 else
11739 protocol = ZEBRA_ROUTE_TABLE;
11740
11741 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11742 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11743
11744 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11745 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11746 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11747 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11748 }
11749
11750 ALIAS_HIDDEN(
11751 bgp_redistribute_ipv4_ospf_rmap_metric,
11752 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11753 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11754 "Redistribute information from another routing protocol\n"
11755 "Open Shortest Path First (OSPFv2)\n"
11756 "Non-main Kernel Routing Table\n"
11757 "Instance ID/Table ID\n"
11758 "Route map reference\n"
11759 "Pointer to route-map entries\n"
11760 "Metric for redistributed routes\n"
11761 "Default metric\n")
11762
11763 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11764 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11765 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11766 "Redistribute information from another routing protocol\n"
11767 "Open Shortest Path First (OSPFv2)\n"
11768 "Non-main Kernel Routing Table\n"
11769 "Instance ID/Table ID\n"
11770 "Metric for redistributed routes\n"
11771 "Default metric\n"
11772 "Route map reference\n"
11773 "Pointer to route-map entries\n")
11774 {
11775 VTY_DECLVAR_CONTEXT(bgp, bgp);
11776 int idx_ospf_table = 1;
11777 int idx_number = 2;
11778 int idx_number_2 = 4;
11779 int idx_word = 6;
11780 uint32_t metric;
11781 struct bgp_redist *red;
11782 unsigned short instance;
11783 int protocol;
11784
11785 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11786 protocol = ZEBRA_ROUTE_OSPF;
11787 else
11788 protocol = ZEBRA_ROUTE_TABLE;
11789
11790 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11791 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11792
11793 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11794 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11795 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11796 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11797 }
11798
11799 ALIAS_HIDDEN(
11800 bgp_redistribute_ipv4_ospf_metric_rmap,
11801 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11802 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11803 "Redistribute information from another routing protocol\n"
11804 "Open Shortest Path First (OSPFv2)\n"
11805 "Non-main Kernel Routing Table\n"
11806 "Instance ID/Table ID\n"
11807 "Metric for redistributed routes\n"
11808 "Default metric\n"
11809 "Route map reference\n"
11810 "Pointer to route-map entries\n")
11811
11812 DEFUN (no_bgp_redistribute_ipv4_ospf,
11813 no_bgp_redistribute_ipv4_ospf_cmd,
11814 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11815 NO_STR
11816 "Redistribute information from another routing protocol\n"
11817 "Open Shortest Path First (OSPFv2)\n"
11818 "Non-main Kernel Routing Table\n"
11819 "Instance ID/Table ID\n"
11820 "Metric for redistributed routes\n"
11821 "Default metric\n"
11822 "Route map reference\n"
11823 "Pointer to route-map entries\n")
11824 {
11825 VTY_DECLVAR_CONTEXT(bgp, bgp);
11826 int idx_ospf_table = 2;
11827 int idx_number = 3;
11828 unsigned short instance;
11829 int protocol;
11830
11831 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11832 protocol = ZEBRA_ROUTE_OSPF;
11833 else
11834 protocol = ZEBRA_ROUTE_TABLE;
11835
11836 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11837 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11838 }
11839
11840 ALIAS_HIDDEN(
11841 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11842 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11843 NO_STR
11844 "Redistribute information from another routing protocol\n"
11845 "Open Shortest Path First (OSPFv2)\n"
11846 "Non-main Kernel Routing Table\n"
11847 "Instance ID/Table ID\n"
11848 "Metric for redistributed routes\n"
11849 "Default metric\n"
11850 "Route map reference\n"
11851 "Pointer to route-map entries\n")
11852
11853 DEFUN (no_bgp_redistribute_ipv4,
11854 no_bgp_redistribute_ipv4_cmd,
11855 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11856 NO_STR
11857 "Redistribute information from another routing protocol\n"
11858 FRR_IP_REDIST_HELP_STR_BGPD
11859 "Metric for redistributed routes\n"
11860 "Default metric\n"
11861 "Route map reference\n"
11862 "Pointer to route-map entries\n")
11863 {
11864 VTY_DECLVAR_CONTEXT(bgp, bgp);
11865 int idx_protocol = 2;
11866 int type;
11867
11868 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11869 if (type < 0) {
11870 vty_out(vty, "%% Invalid route type\n");
11871 return CMD_WARNING_CONFIG_FAILED;
11872 }
11873 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11874 }
11875
11876 ALIAS_HIDDEN(
11877 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11878 "no redistribute " FRR_IP_REDIST_STR_BGPD
11879 " [metric (0-4294967295)] [route-map WORD]",
11880 NO_STR
11881 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11882 "Metric for redistributed routes\n"
11883 "Default metric\n"
11884 "Route map reference\n"
11885 "Pointer to route-map entries\n")
11886
11887 DEFUN (bgp_redistribute_ipv6,
11888 bgp_redistribute_ipv6_cmd,
11889 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11890 "Redistribute information from another routing protocol\n"
11891 FRR_IP6_REDIST_HELP_STR_BGPD)
11892 {
11893 VTY_DECLVAR_CONTEXT(bgp, bgp);
11894 int idx_protocol = 1;
11895 int type;
11896
11897 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11898 if (type < 0) {
11899 vty_out(vty, "%% Invalid route type\n");
11900 return CMD_WARNING_CONFIG_FAILED;
11901 }
11902
11903 bgp_redist_add(bgp, AFI_IP6, type, 0);
11904 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11905 }
11906
11907 DEFUN (bgp_redistribute_ipv6_rmap,
11908 bgp_redistribute_ipv6_rmap_cmd,
11909 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11910 "Redistribute information from another routing protocol\n"
11911 FRR_IP6_REDIST_HELP_STR_BGPD
11912 "Route map reference\n"
11913 "Pointer to route-map entries\n")
11914 {
11915 VTY_DECLVAR_CONTEXT(bgp, bgp);
11916 int idx_protocol = 1;
11917 int idx_word = 3;
11918 int type;
11919 struct bgp_redist *red;
11920
11921 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11922 if (type < 0) {
11923 vty_out(vty, "%% Invalid route type\n");
11924 return CMD_WARNING_CONFIG_FAILED;
11925 }
11926
11927 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11928 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11929 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11930 }
11931
11932 DEFUN (bgp_redistribute_ipv6_metric,
11933 bgp_redistribute_ipv6_metric_cmd,
11934 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11935 "Redistribute information from another routing protocol\n"
11936 FRR_IP6_REDIST_HELP_STR_BGPD
11937 "Metric for redistributed routes\n"
11938 "Default metric\n")
11939 {
11940 VTY_DECLVAR_CONTEXT(bgp, bgp);
11941 int idx_protocol = 1;
11942 int idx_number = 3;
11943 int type;
11944 uint32_t metric;
11945 struct bgp_redist *red;
11946
11947 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11948 if (type < 0) {
11949 vty_out(vty, "%% Invalid route type\n");
11950 return CMD_WARNING_CONFIG_FAILED;
11951 }
11952 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11953
11954 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11955 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11956 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11957 }
11958
11959 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11960 bgp_redistribute_ipv6_rmap_metric_cmd,
11961 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11962 "Redistribute information from another routing protocol\n"
11963 FRR_IP6_REDIST_HELP_STR_BGPD
11964 "Route map reference\n"
11965 "Pointer to route-map entries\n"
11966 "Metric for redistributed routes\n"
11967 "Default metric\n")
11968 {
11969 VTY_DECLVAR_CONTEXT(bgp, bgp);
11970 int idx_protocol = 1;
11971 int idx_word = 3;
11972 int idx_number = 5;
11973 int type;
11974 uint32_t metric;
11975 struct bgp_redist *red;
11976
11977 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11978 if (type < 0) {
11979 vty_out(vty, "%% Invalid route type\n");
11980 return CMD_WARNING_CONFIG_FAILED;
11981 }
11982 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11983
11984 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11985 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11986 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11987 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11988 }
11989
11990 DEFUN (bgp_redistribute_ipv6_metric_rmap,
11991 bgp_redistribute_ipv6_metric_rmap_cmd,
11992 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11993 "Redistribute information from another routing protocol\n"
11994 FRR_IP6_REDIST_HELP_STR_BGPD
11995 "Metric for redistributed routes\n"
11996 "Default metric\n"
11997 "Route map reference\n"
11998 "Pointer to route-map entries\n")
11999 {
12000 VTY_DECLVAR_CONTEXT(bgp, bgp);
12001 int idx_protocol = 1;
12002 int idx_number = 3;
12003 int idx_word = 5;
12004 int type;
12005 uint32_t metric;
12006 struct bgp_redist *red;
12007
12008 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12009 if (type < 0) {
12010 vty_out(vty, "%% Invalid route type\n");
12011 return CMD_WARNING_CONFIG_FAILED;
12012 }
12013 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12014
12015 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12016 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12017 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12018 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12019 }
12020
12021 DEFUN (no_bgp_redistribute_ipv6,
12022 no_bgp_redistribute_ipv6_cmd,
12023 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12024 NO_STR
12025 "Redistribute information from another routing protocol\n"
12026 FRR_IP6_REDIST_HELP_STR_BGPD
12027 "Metric for redistributed routes\n"
12028 "Default metric\n"
12029 "Route map reference\n"
12030 "Pointer to route-map entries\n")
12031 {
12032 VTY_DECLVAR_CONTEXT(bgp, bgp);
12033 int idx_protocol = 2;
12034 int type;
12035
12036 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12037 if (type < 0) {
12038 vty_out(vty, "%% Invalid route type\n");
12039 return CMD_WARNING_CONFIG_FAILED;
12040 }
12041
12042 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12043 }
12044
12045 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12046 safi_t safi)
12047 {
12048 int i;
12049
12050 /* Unicast redistribution only. */
12051 if (safi != SAFI_UNICAST)
12052 return;
12053
12054 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12055 /* Redistribute BGP does not make sense. */
12056 if (i != ZEBRA_ROUTE_BGP) {
12057 struct list *red_list;
12058 struct listnode *node;
12059 struct bgp_redist *red;
12060
12061 red_list = bgp->redist[afi][i];
12062 if (!red_list)
12063 continue;
12064
12065 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12066 /* "redistribute" configuration. */
12067 vty_out(vty, " redistribute %s",
12068 zebra_route_string(i));
12069 if (red->instance)
12070 vty_out(vty, " %d", red->instance);
12071 if (red->redist_metric_flag)
12072 vty_out(vty, " metric %u",
12073 red->redist_metric);
12074 if (red->rmap.name)
12075 vty_out(vty, " route-map %s",
12076 red->rmap.name);
12077 vty_out(vty, "\n");
12078 }
12079 }
12080 }
12081 }
12082
12083 /* This is part of the address-family block (unicast only) */
12084 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12085 afi_t afi)
12086 {
12087 int indent = 2;
12088
12089 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12090 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12091 bgp->vpn_policy[afi]
12092 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12093
12094 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12095 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12096 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12097 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12098 return;
12099
12100 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12101 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12102
12103 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12104
12105 } else {
12106 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12107 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12108 bgp->vpn_policy[afi].tovpn_label);
12109 }
12110 }
12111 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12112 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12113 char buf[RD_ADDRSTRLEN];
12114 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12115 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12116 sizeof(buf)));
12117 }
12118 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12119 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12120
12121 char buf[PREFIX_STRLEN];
12122 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12123 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12124 sizeof(buf))) {
12125
12126 vty_out(vty, "%*snexthop vpn export %s\n",
12127 indent, "", buf);
12128 }
12129 }
12130 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12131 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12132 && ecommunity_cmp(
12133 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12134 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12135
12136 char *b = ecommunity_ecom2str(
12137 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12138 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12139 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12140 XFREE(MTYPE_ECOMMUNITY_STR, b);
12141 } else {
12142 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12143 char *b = ecommunity_ecom2str(
12144 bgp->vpn_policy[afi]
12145 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12146 ECOMMUNITY_FORMAT_ROUTE_MAP,
12147 ECOMMUNITY_ROUTE_TARGET);
12148 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12149 XFREE(MTYPE_ECOMMUNITY_STR, b);
12150 }
12151 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12152 char *b = ecommunity_ecom2str(
12153 bgp->vpn_policy[afi]
12154 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12155 ECOMMUNITY_FORMAT_ROUTE_MAP,
12156 ECOMMUNITY_ROUTE_TARGET);
12157 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12158 XFREE(MTYPE_ECOMMUNITY_STR, b);
12159 }
12160 }
12161
12162 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12163 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12164 bgp->vpn_policy[afi]
12165 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12166
12167 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12168 char *b = ecommunity_ecom2str(
12169 bgp->vpn_policy[afi]
12170 .import_redirect_rtlist,
12171 ECOMMUNITY_FORMAT_ROUTE_MAP,
12172 ECOMMUNITY_ROUTE_TARGET);
12173
12174 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12175 XFREE(MTYPE_ECOMMUNITY_STR, b);
12176 }
12177 }
12178
12179
12180 /* BGP node structure. */
12181 static struct cmd_node bgp_node = {
12182 BGP_NODE, "%s(config-router)# ", 1,
12183 };
12184
12185 static struct cmd_node bgp_ipv4_unicast_node = {
12186 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12187 };
12188
12189 static struct cmd_node bgp_ipv4_multicast_node = {
12190 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12191 };
12192
12193 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12194 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12195 };
12196
12197 static struct cmd_node bgp_ipv6_unicast_node = {
12198 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12199 };
12200
12201 static struct cmd_node bgp_ipv6_multicast_node = {
12202 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12203 };
12204
12205 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12206 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12207 };
12208
12209 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12210 "%s(config-router-af)# ", 1};
12211
12212 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12213 "%s(config-router-af-vpnv6)# ", 1};
12214
12215 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12216 "%s(config-router-evpn)# ", 1};
12217
12218 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12219 "%s(config-router-af-vni)# ", 1};
12220
12221 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12222 "%s(config-router-af)# ", 1};
12223
12224 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12225 "%s(config-router-af-vpnv6)# ", 1};
12226
12227 static void community_list_vty(void);
12228
12229 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12230 {
12231 struct bgp *bgp;
12232 struct peer *peer;
12233 struct listnode *lnbgp, *lnpeer;
12234
12235 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12236 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12237 /* only provide suggestions on the appropriate input
12238 * token type,
12239 * they'll otherwise show up multiple times */
12240 enum cmd_token_type match_type;
12241 char *name = peer->host;
12242
12243 if (peer->conf_if) {
12244 match_type = VARIABLE_TKN;
12245 name = peer->conf_if;
12246 } else if (strchr(peer->host, ':'))
12247 match_type = IPV6_TKN;
12248 else
12249 match_type = IPV4_TKN;
12250
12251 if (token->type != match_type)
12252 continue;
12253
12254 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12255 }
12256 }
12257 }
12258
12259 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12260 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12261 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12262 {.varname = "peer", .completions = bgp_ac_neighbor},
12263 {.completions = NULL}};
12264
12265 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12266 {
12267 struct bgp *bgp;
12268 struct peer_group *group;
12269 struct listnode *lnbgp, *lnpeer;
12270
12271 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12272 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12273 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12274 group->name));
12275 }
12276 }
12277
12278 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12279 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12280 {.completions = NULL} };
12281
12282 void bgp_vty_init(void)
12283 {
12284 cmd_variable_handler_register(bgp_var_neighbor);
12285 cmd_variable_handler_register(bgp_var_peergroup);
12286
12287 /* Install bgp top node. */
12288 install_node(&bgp_node, bgp_config_write);
12289 install_node(&bgp_ipv4_unicast_node, NULL);
12290 install_node(&bgp_ipv4_multicast_node, NULL);
12291 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12292 install_node(&bgp_ipv6_unicast_node, NULL);
12293 install_node(&bgp_ipv6_multicast_node, NULL);
12294 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12295 install_node(&bgp_vpnv4_node, NULL);
12296 install_node(&bgp_vpnv6_node, NULL);
12297 install_node(&bgp_evpn_node, NULL);
12298 install_node(&bgp_evpn_vni_node, NULL);
12299 install_node(&bgp_flowspecv4_node, NULL);
12300 install_node(&bgp_flowspecv6_node, NULL);
12301
12302 /* Install default VTY commands to new nodes. */
12303 install_default(BGP_NODE);
12304 install_default(BGP_IPV4_NODE);
12305 install_default(BGP_IPV4M_NODE);
12306 install_default(BGP_IPV4L_NODE);
12307 install_default(BGP_IPV6_NODE);
12308 install_default(BGP_IPV6M_NODE);
12309 install_default(BGP_IPV6L_NODE);
12310 install_default(BGP_VPNV4_NODE);
12311 install_default(BGP_VPNV6_NODE);
12312 install_default(BGP_FLOWSPECV4_NODE);
12313 install_default(BGP_FLOWSPECV6_NODE);
12314 install_default(BGP_EVPN_NODE);
12315 install_default(BGP_EVPN_VNI_NODE);
12316
12317 /* "bgp multiple-instance" commands. */
12318 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12319 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12320
12321 /* "bgp config-type" commands. */
12322 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12323 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12324
12325 /* bgp route-map delay-timer commands. */
12326 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12327 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12328
12329 /* Dummy commands (Currently not supported) */
12330 install_element(BGP_NODE, &no_synchronization_cmd);
12331 install_element(BGP_NODE, &no_auto_summary_cmd);
12332
12333 /* "router bgp" commands. */
12334 install_element(CONFIG_NODE, &router_bgp_cmd);
12335
12336 /* "no router bgp" commands. */
12337 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12338
12339 /* "bgp router-id" commands. */
12340 install_element(BGP_NODE, &bgp_router_id_cmd);
12341 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12342
12343 /* "bgp cluster-id" commands. */
12344 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12345 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12346
12347 /* "bgp confederation" commands. */
12348 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12349 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12350
12351 /* "bgp confederation peers" commands. */
12352 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12353 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12354
12355 /* bgp max-med command */
12356 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12357 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12358 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12359 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12360 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12361
12362 /* bgp disable-ebgp-connected-nh-check */
12363 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12364 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12365
12366 /* bgp update-delay command */
12367 install_element(BGP_NODE, &bgp_update_delay_cmd);
12368 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12369 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12370
12371 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12372 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12373 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12374 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12375
12376 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12377 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12378
12379 /* "maximum-paths" commands. */
12380 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12381 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12382 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12383 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12384 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12385 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12386 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12387 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12388 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12389 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12390 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12391 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12392 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12393 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12394 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12395
12396 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12397 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12398 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12399 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12400 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12401
12402 /* "timers bgp" commands. */
12403 install_element(BGP_NODE, &bgp_timers_cmd);
12404 install_element(BGP_NODE, &no_bgp_timers_cmd);
12405
12406 /* route-map delay-timer commands - per instance for backwards compat.
12407 */
12408 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12409 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12410
12411 /* "bgp client-to-client reflection" commands */
12412 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12413 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12414
12415 /* "bgp always-compare-med" commands */
12416 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12417 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12418
12419 /* "bgp deterministic-med" commands */
12420 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12421 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12422
12423 /* "bgp graceful-restart" commands */
12424 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12425 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12426 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12427 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12428 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12429 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12430
12431 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12432 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12433
12434 /* "bgp graceful-shutdown" commands */
12435 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12436 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12437
12438 /* "bgp fast-external-failover" commands */
12439 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12440 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12441
12442 /* "bgp enforce-first-as" commands */
12443 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12444
12445 /* "bgp bestpath compare-routerid" commands */
12446 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12447 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12448
12449 /* "bgp bestpath as-path ignore" commands */
12450 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12451 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12452
12453 /* "bgp bestpath as-path confed" commands */
12454 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12455 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12456
12457 /* "bgp bestpath as-path multipath-relax" commands */
12458 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12459 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12460
12461 /* "bgp log-neighbor-changes" commands */
12462 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12463 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12464
12465 /* "bgp bestpath med" commands */
12466 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12467 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12468
12469 /* "no bgp default ipv4-unicast" commands. */
12470 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12471 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12472
12473 /* "bgp network import-check" commands. */
12474 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12475 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12476 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12477
12478 /* "bgp default local-preference" commands. */
12479 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12480 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12481
12482 /* bgp default show-hostname */
12483 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12484 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12485
12486 /* "bgp default subgroup-pkt-queue-max" commands. */
12487 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12488 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12489
12490 /* bgp ibgp-allow-policy-mods command */
12491 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12492 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12493
12494 /* "bgp listen limit" commands. */
12495 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12496 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12497
12498 /* "bgp listen range" commands. */
12499 install_element(BGP_NODE, &bgp_listen_range_cmd);
12500 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12501
12502 /* "bgp default shutdown" command */
12503 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12504
12505 /* "neighbor remote-as" commands. */
12506 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12507 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12508 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12509 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12510 install_element(BGP_NODE,
12511 &neighbor_interface_v6only_config_remote_as_cmd);
12512 install_element(BGP_NODE, &no_neighbor_cmd);
12513 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12514
12515 /* "neighbor peer-group" commands. */
12516 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12517 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12518 install_element(BGP_NODE,
12519 &no_neighbor_interface_peer_group_remote_as_cmd);
12520
12521 /* "neighbor local-as" commands. */
12522 install_element(BGP_NODE, &neighbor_local_as_cmd);
12523 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12524 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12525 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12526
12527 /* "neighbor solo" commands. */
12528 install_element(BGP_NODE, &neighbor_solo_cmd);
12529 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12530
12531 /* "neighbor password" commands. */
12532 install_element(BGP_NODE, &neighbor_password_cmd);
12533 install_element(BGP_NODE, &no_neighbor_password_cmd);
12534
12535 /* "neighbor activate" commands. */
12536 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12537 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12538 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12539 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12540 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12541 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12542 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12543 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12544 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12545 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12546 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12547 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12548
12549 /* "no neighbor activate" commands. */
12550 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12551 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12552 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12553 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12554 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12555 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12556 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12557 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12558 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12559 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12560 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12561 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12562
12563 /* "neighbor peer-group" set commands. */
12564 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12565 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12566 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12567 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12568 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12569 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12570 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12571 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12572 install_element(BGP_FLOWSPECV4_NODE,
12573 &neighbor_set_peer_group_hidden_cmd);
12574 install_element(BGP_FLOWSPECV6_NODE,
12575 &neighbor_set_peer_group_hidden_cmd);
12576
12577 /* "no neighbor peer-group unset" commands. */
12578 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12579 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12580 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12581 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12582 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12583 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12584 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12585 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12586 install_element(BGP_FLOWSPECV4_NODE,
12587 &no_neighbor_set_peer_group_hidden_cmd);
12588 install_element(BGP_FLOWSPECV6_NODE,
12589 &no_neighbor_set_peer_group_hidden_cmd);
12590
12591 /* "neighbor softreconfiguration inbound" commands.*/
12592 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12593 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12594 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12595 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12596 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12597 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12598 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12599 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12600 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12601 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12602 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12603 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12604 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12605 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12606 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12607 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12608 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12609 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12610 install_element(BGP_FLOWSPECV4_NODE,
12611 &neighbor_soft_reconfiguration_cmd);
12612 install_element(BGP_FLOWSPECV4_NODE,
12613 &no_neighbor_soft_reconfiguration_cmd);
12614 install_element(BGP_FLOWSPECV6_NODE,
12615 &neighbor_soft_reconfiguration_cmd);
12616 install_element(BGP_FLOWSPECV6_NODE,
12617 &no_neighbor_soft_reconfiguration_cmd);
12618
12619 /* "neighbor attribute-unchanged" commands. */
12620 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12621 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12622 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12623 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12624 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12625 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12626 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12627 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12628 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12629 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12630 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12631 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12632 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12633 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12634 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12635 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12636 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12637 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12638
12639 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12640 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12641
12642 /* "nexthop-local unchanged" commands */
12643 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12644 install_element(BGP_IPV6_NODE,
12645 &no_neighbor_nexthop_local_unchanged_cmd);
12646
12647 /* "neighbor next-hop-self" commands. */
12648 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12649 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12650 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12651 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12652 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12653 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12654 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12655 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12656 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12657 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12658 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12659 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12660 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12661 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12662 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12663 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12664 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12665 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12666 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12667 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12668
12669 /* "neighbor next-hop-self force" commands. */
12670 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12671 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12672 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12673 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12674 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12675 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12676 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12677 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12678 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12679 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12680 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12681 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12682 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12683 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12684 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12685 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12686 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12687 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12688
12689 /* "neighbor as-override" commands. */
12690 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12691 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12692 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12693 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12694 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12695 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12696 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12697 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12698 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12699 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12700 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12701 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12702 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12703 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12704 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12705 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12706 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12707 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12708
12709 /* "neighbor remove-private-AS" commands. */
12710 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12711 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12712 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12713 install_element(BGP_NODE,
12714 &no_neighbor_remove_private_as_all_hidden_cmd);
12715 install_element(BGP_NODE,
12716 &neighbor_remove_private_as_replace_as_hidden_cmd);
12717 install_element(BGP_NODE,
12718 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12719 install_element(BGP_NODE,
12720 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12721 install_element(
12722 BGP_NODE,
12723 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12724 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12725 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12726 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12727 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12728 install_element(BGP_IPV4_NODE,
12729 &neighbor_remove_private_as_replace_as_cmd);
12730 install_element(BGP_IPV4_NODE,
12731 &no_neighbor_remove_private_as_replace_as_cmd);
12732 install_element(BGP_IPV4_NODE,
12733 &neighbor_remove_private_as_all_replace_as_cmd);
12734 install_element(BGP_IPV4_NODE,
12735 &no_neighbor_remove_private_as_all_replace_as_cmd);
12736 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12737 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12738 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12739 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12740 install_element(BGP_IPV4M_NODE,
12741 &neighbor_remove_private_as_replace_as_cmd);
12742 install_element(BGP_IPV4M_NODE,
12743 &no_neighbor_remove_private_as_replace_as_cmd);
12744 install_element(BGP_IPV4M_NODE,
12745 &neighbor_remove_private_as_all_replace_as_cmd);
12746 install_element(BGP_IPV4M_NODE,
12747 &no_neighbor_remove_private_as_all_replace_as_cmd);
12748 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12749 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12750 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12751 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12752 install_element(BGP_IPV4L_NODE,
12753 &neighbor_remove_private_as_replace_as_cmd);
12754 install_element(BGP_IPV4L_NODE,
12755 &no_neighbor_remove_private_as_replace_as_cmd);
12756 install_element(BGP_IPV4L_NODE,
12757 &neighbor_remove_private_as_all_replace_as_cmd);
12758 install_element(BGP_IPV4L_NODE,
12759 &no_neighbor_remove_private_as_all_replace_as_cmd);
12760 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12761 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12762 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12763 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12764 install_element(BGP_IPV6_NODE,
12765 &neighbor_remove_private_as_replace_as_cmd);
12766 install_element(BGP_IPV6_NODE,
12767 &no_neighbor_remove_private_as_replace_as_cmd);
12768 install_element(BGP_IPV6_NODE,
12769 &neighbor_remove_private_as_all_replace_as_cmd);
12770 install_element(BGP_IPV6_NODE,
12771 &no_neighbor_remove_private_as_all_replace_as_cmd);
12772 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12773 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12774 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12775 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12776 install_element(BGP_IPV6M_NODE,
12777 &neighbor_remove_private_as_replace_as_cmd);
12778 install_element(BGP_IPV6M_NODE,
12779 &no_neighbor_remove_private_as_replace_as_cmd);
12780 install_element(BGP_IPV6M_NODE,
12781 &neighbor_remove_private_as_all_replace_as_cmd);
12782 install_element(BGP_IPV6M_NODE,
12783 &no_neighbor_remove_private_as_all_replace_as_cmd);
12784 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12785 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12786 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12787 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12788 install_element(BGP_IPV6L_NODE,
12789 &neighbor_remove_private_as_replace_as_cmd);
12790 install_element(BGP_IPV6L_NODE,
12791 &no_neighbor_remove_private_as_replace_as_cmd);
12792 install_element(BGP_IPV6L_NODE,
12793 &neighbor_remove_private_as_all_replace_as_cmd);
12794 install_element(BGP_IPV6L_NODE,
12795 &no_neighbor_remove_private_as_all_replace_as_cmd);
12796 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12797 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12798 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12799 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12800 install_element(BGP_VPNV4_NODE,
12801 &neighbor_remove_private_as_replace_as_cmd);
12802 install_element(BGP_VPNV4_NODE,
12803 &no_neighbor_remove_private_as_replace_as_cmd);
12804 install_element(BGP_VPNV4_NODE,
12805 &neighbor_remove_private_as_all_replace_as_cmd);
12806 install_element(BGP_VPNV4_NODE,
12807 &no_neighbor_remove_private_as_all_replace_as_cmd);
12808 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12809 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12810 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12811 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12812 install_element(BGP_VPNV6_NODE,
12813 &neighbor_remove_private_as_replace_as_cmd);
12814 install_element(BGP_VPNV6_NODE,
12815 &no_neighbor_remove_private_as_replace_as_cmd);
12816 install_element(BGP_VPNV6_NODE,
12817 &neighbor_remove_private_as_all_replace_as_cmd);
12818 install_element(BGP_VPNV6_NODE,
12819 &no_neighbor_remove_private_as_all_replace_as_cmd);
12820
12821 /* "neighbor send-community" commands.*/
12822 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12823 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12824 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12825 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12826 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12827 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12828 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12829 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12830 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12831 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12832 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12833 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12834 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12835 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12836 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12837 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12838 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12839 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12840 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12841 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12842 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12843 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12844 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12845 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12846 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12847 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12848 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12849 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12850 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12851 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12852 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12853 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12854 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12855 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12856 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12857 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12858
12859 /* "neighbor route-reflector" commands.*/
12860 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12861 install_element(BGP_NODE,
12862 &no_neighbor_route_reflector_client_hidden_cmd);
12863 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12864 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12865 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12866 install_element(BGP_IPV4M_NODE,
12867 &no_neighbor_route_reflector_client_cmd);
12868 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12869 install_element(BGP_IPV4L_NODE,
12870 &no_neighbor_route_reflector_client_cmd);
12871 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12872 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12873 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12874 install_element(BGP_IPV6M_NODE,
12875 &no_neighbor_route_reflector_client_cmd);
12876 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12877 install_element(BGP_IPV6L_NODE,
12878 &no_neighbor_route_reflector_client_cmd);
12879 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12880 install_element(BGP_VPNV4_NODE,
12881 &no_neighbor_route_reflector_client_cmd);
12882 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12883 install_element(BGP_VPNV6_NODE,
12884 &no_neighbor_route_reflector_client_cmd);
12885 install_element(BGP_FLOWSPECV4_NODE,
12886 &neighbor_route_reflector_client_cmd);
12887 install_element(BGP_FLOWSPECV4_NODE,
12888 &no_neighbor_route_reflector_client_cmd);
12889 install_element(BGP_FLOWSPECV6_NODE,
12890 &neighbor_route_reflector_client_cmd);
12891 install_element(BGP_FLOWSPECV6_NODE,
12892 &no_neighbor_route_reflector_client_cmd);
12893 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12894 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12895
12896 /* "neighbor route-server" commands.*/
12897 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12898 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12899 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12900 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12901 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12902 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12903 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12904 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12905 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12906 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12907 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12908 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12909 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12910 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12911 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12912 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12913 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12914 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12915 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12916 install_element(BGP_FLOWSPECV4_NODE,
12917 &no_neighbor_route_server_client_cmd);
12918 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12919 install_element(BGP_FLOWSPECV6_NODE,
12920 &no_neighbor_route_server_client_cmd);
12921
12922 /* "neighbor addpath-tx-all-paths" commands.*/
12923 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12924 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12925 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12926 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12927 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12928 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12929 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12930 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12931 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12932 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12933 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12934 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12935 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12936 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12937 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12938 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12939 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12940 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12941
12942 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12943 install_element(BGP_NODE,
12944 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12945 install_element(BGP_NODE,
12946 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12947 install_element(BGP_IPV4_NODE,
12948 &neighbor_addpath_tx_bestpath_per_as_cmd);
12949 install_element(BGP_IPV4_NODE,
12950 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12951 install_element(BGP_IPV4M_NODE,
12952 &neighbor_addpath_tx_bestpath_per_as_cmd);
12953 install_element(BGP_IPV4M_NODE,
12954 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12955 install_element(BGP_IPV4L_NODE,
12956 &neighbor_addpath_tx_bestpath_per_as_cmd);
12957 install_element(BGP_IPV4L_NODE,
12958 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12959 install_element(BGP_IPV6_NODE,
12960 &neighbor_addpath_tx_bestpath_per_as_cmd);
12961 install_element(BGP_IPV6_NODE,
12962 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12963 install_element(BGP_IPV6M_NODE,
12964 &neighbor_addpath_tx_bestpath_per_as_cmd);
12965 install_element(BGP_IPV6M_NODE,
12966 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12967 install_element(BGP_IPV6L_NODE,
12968 &neighbor_addpath_tx_bestpath_per_as_cmd);
12969 install_element(BGP_IPV6L_NODE,
12970 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12971 install_element(BGP_VPNV4_NODE,
12972 &neighbor_addpath_tx_bestpath_per_as_cmd);
12973 install_element(BGP_VPNV4_NODE,
12974 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12975 install_element(BGP_VPNV6_NODE,
12976 &neighbor_addpath_tx_bestpath_per_as_cmd);
12977 install_element(BGP_VPNV6_NODE,
12978 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12979
12980 /* "neighbor passive" commands. */
12981 install_element(BGP_NODE, &neighbor_passive_cmd);
12982 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12983
12984
12985 /* "neighbor shutdown" commands. */
12986 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12987 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12988 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12989 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12990
12991 /* "neighbor capability extended-nexthop" commands.*/
12992 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12993 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12994
12995 /* "neighbor capability orf prefix-list" commands.*/
12996 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12997 install_element(BGP_NODE,
12998 &no_neighbor_capability_orf_prefix_hidden_cmd);
12999 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13000 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13001 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13002 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13003 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13004 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13005 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13006 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13007 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13008 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13009 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13010 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13011
13012 /* "neighbor capability dynamic" commands.*/
13013 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13014 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13015
13016 /* "neighbor dont-capability-negotiate" commands. */
13017 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13018 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13019
13020 /* "neighbor ebgp-multihop" commands. */
13021 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13022 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13023 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13024
13025 /* "neighbor disable-connected-check" commands. */
13026 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13027 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13028
13029 /* "neighbor enforce-first-as" commands. */
13030 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13031 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13032
13033 /* "neighbor description" commands. */
13034 install_element(BGP_NODE, &neighbor_description_cmd);
13035 install_element(BGP_NODE, &no_neighbor_description_cmd);
13036 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13037
13038 /* "neighbor update-source" commands. "*/
13039 install_element(BGP_NODE, &neighbor_update_source_cmd);
13040 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13041
13042 /* "neighbor default-originate" commands. */
13043 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13044 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13045 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13046 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13047 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13048 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13049 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13050 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13051 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13052 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13053 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13054 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13055 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13056 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13057 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13058 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13059 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13060 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13061 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13062 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13063 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13064
13065 /* "neighbor port" commands. */
13066 install_element(BGP_NODE, &neighbor_port_cmd);
13067 install_element(BGP_NODE, &no_neighbor_port_cmd);
13068
13069 /* "neighbor weight" commands. */
13070 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13071 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13072
13073 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13074 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13075 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13076 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13077 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13078 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13079 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13080 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13081 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13082 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13083 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13084 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13085 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13086 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13087 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13088 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13089
13090 /* "neighbor override-capability" commands. */
13091 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13092 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13093
13094 /* "neighbor strict-capability-match" commands. */
13095 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13096 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13097
13098 /* "neighbor timers" commands. */
13099 install_element(BGP_NODE, &neighbor_timers_cmd);
13100 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13101
13102 /* "neighbor timers connect" commands. */
13103 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13104 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13105
13106 /* "neighbor advertisement-interval" commands. */
13107 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13108 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13109
13110 /* "neighbor interface" commands. */
13111 install_element(BGP_NODE, &neighbor_interface_cmd);
13112 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13113
13114 /* "neighbor distribute" commands. */
13115 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13116 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13117 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13118 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13119 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13120 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13121 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13122 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13123 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13124 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13125 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13126 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13127 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13128 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13129 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13130 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13131 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13132 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13133
13134 /* "neighbor prefix-list" commands. */
13135 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13136 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13137 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13138 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13139 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13140 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13141 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13142 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13143 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13144 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13145 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13146 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13147 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13148 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13149 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13150 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13151 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13152 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13153 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13154 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13155 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13156 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13157
13158 /* "neighbor filter-list" commands. */
13159 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13160 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13161 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13162 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13163 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13164 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13165 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13166 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13167 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13168 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13169 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13170 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13171 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13172 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13173 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13174 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13175 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13176 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13177 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13178 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13179 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13180 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13181
13182 /* "neighbor route-map" commands. */
13183 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13184 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13185 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13186 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13187 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13188 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13189 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13190 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13191 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13192 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13193 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13194 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13195 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13196 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13197 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13198 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13199 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13200 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13201 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13202 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13203 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13204 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13205 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13206 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13207
13208 /* "neighbor unsuppress-map" commands. */
13209 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13210 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13211 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13212 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13213 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13214 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13215 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13216 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13217 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13218 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13219 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13220 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13221 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13222 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13223 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13224 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13225 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13226 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13227
13228 /* "neighbor maximum-prefix" commands. */
13229 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13230 install_element(BGP_NODE,
13231 &neighbor_maximum_prefix_threshold_hidden_cmd);
13232 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13233 install_element(BGP_NODE,
13234 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13235 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13236 install_element(BGP_NODE,
13237 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13238 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13239 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13240 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13241 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13242 install_element(BGP_IPV4_NODE,
13243 &neighbor_maximum_prefix_threshold_warning_cmd);
13244 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13245 install_element(BGP_IPV4_NODE,
13246 &neighbor_maximum_prefix_threshold_restart_cmd);
13247 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13248 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13249 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13250 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13251 install_element(BGP_IPV4M_NODE,
13252 &neighbor_maximum_prefix_threshold_warning_cmd);
13253 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13254 install_element(BGP_IPV4M_NODE,
13255 &neighbor_maximum_prefix_threshold_restart_cmd);
13256 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13257 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13258 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13259 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13260 install_element(BGP_IPV4L_NODE,
13261 &neighbor_maximum_prefix_threshold_warning_cmd);
13262 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13263 install_element(BGP_IPV4L_NODE,
13264 &neighbor_maximum_prefix_threshold_restart_cmd);
13265 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13266 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13267 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13268 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13269 install_element(BGP_IPV6_NODE,
13270 &neighbor_maximum_prefix_threshold_warning_cmd);
13271 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13272 install_element(BGP_IPV6_NODE,
13273 &neighbor_maximum_prefix_threshold_restart_cmd);
13274 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13275 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13276 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13277 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13278 install_element(BGP_IPV6M_NODE,
13279 &neighbor_maximum_prefix_threshold_warning_cmd);
13280 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13281 install_element(BGP_IPV6M_NODE,
13282 &neighbor_maximum_prefix_threshold_restart_cmd);
13283 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13284 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13285 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13287 install_element(BGP_IPV6L_NODE,
13288 &neighbor_maximum_prefix_threshold_warning_cmd);
13289 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13290 install_element(BGP_IPV6L_NODE,
13291 &neighbor_maximum_prefix_threshold_restart_cmd);
13292 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13293 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13294 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13295 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13296 install_element(BGP_VPNV4_NODE,
13297 &neighbor_maximum_prefix_threshold_warning_cmd);
13298 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13299 install_element(BGP_VPNV4_NODE,
13300 &neighbor_maximum_prefix_threshold_restart_cmd);
13301 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13302 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13303 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13304 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13305 install_element(BGP_VPNV6_NODE,
13306 &neighbor_maximum_prefix_threshold_warning_cmd);
13307 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13308 install_element(BGP_VPNV6_NODE,
13309 &neighbor_maximum_prefix_threshold_restart_cmd);
13310 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13311
13312 /* "neighbor allowas-in" */
13313 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13314 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13315 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13316 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13317 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13318 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13319 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13320 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13321 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13322 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13323 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13324 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13325 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13326 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13327 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13328 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13329 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13330 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13331 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13332 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13333
13334 /* address-family commands. */
13335 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13336 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13337 #ifdef KEEP_OLD_VPN_COMMANDS
13338 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13339 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13340 #endif /* KEEP_OLD_VPN_COMMANDS */
13341
13342 install_element(BGP_NODE, &address_family_evpn_cmd);
13343
13344 /* "exit-address-family" command. */
13345 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13346 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13347 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13348 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13349 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13350 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13351 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13352 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13353 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13354 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13355 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13356
13357 /* "clear ip bgp commands" */
13358 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13359
13360 /* clear ip bgp prefix */
13361 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13362 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13363 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13364
13365 /* "show [ip] bgp summary" commands. */
13366 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13367 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13368 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13369 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13370 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13371 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13372
13373 /* "show [ip] bgp neighbors" commands. */
13374 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13375
13376 /* "show [ip] bgp peer-group" commands. */
13377 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13378
13379 /* "show [ip] bgp paths" commands. */
13380 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13381
13382 /* "show [ip] bgp community" commands. */
13383 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13384
13385 /* "show ip bgp large-community" commands. */
13386 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13387 /* "show [ip] bgp attribute-info" commands. */
13388 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13389 /* "show [ip] bgp route-leak" command */
13390 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13391
13392 /* "redistribute" commands. */
13393 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13394 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13395 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13396 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13397 install_element(BGP_NODE,
13398 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13399 install_element(BGP_NODE,
13400 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13401 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13402 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13403 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13404 install_element(BGP_NODE,
13405 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13406 install_element(BGP_NODE,
13407 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13408 install_element(BGP_NODE,
13409 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13410 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13411 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13412 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13413 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13414 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13415 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13416 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13417 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13418 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13419 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13420 install_element(BGP_IPV4_NODE,
13421 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13422 install_element(BGP_IPV4_NODE,
13423 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13424 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13425 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13426 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13427 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13428 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13429 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13430
13431 /* import|export vpn [route-map WORD] */
13432 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13433 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13434
13435 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13436 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13437
13438 /* ttl_security commands */
13439 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13440 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13441
13442 /* "show [ip] bgp memory" commands. */
13443 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13444
13445 /* "show bgp martian next-hop" */
13446 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13447
13448 /* "show [ip] bgp views" commands. */
13449 install_element(VIEW_NODE, &show_bgp_views_cmd);
13450
13451 /* "show [ip] bgp vrfs" commands. */
13452 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13453
13454 /* Community-list. */
13455 community_list_vty();
13456
13457 /* vpn-policy commands */
13458 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13459 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13460 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13461 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13462 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13463 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13464 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13465 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13466 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13467 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13468 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13469 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13470
13471 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13472 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13473
13474 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13475 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13476 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13477 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13478 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13479 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13480 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13481 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13482 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13483 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13484 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13485 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13486 }
13487
13488 #include "memory.h"
13489 #include "bgp_regex.h"
13490 #include "bgp_clist.h"
13491 #include "bgp_ecommunity.h"
13492
13493 /* VTY functions. */
13494
13495 /* Direction value to string conversion. */
13496 static const char *community_direct_str(int direct)
13497 {
13498 switch (direct) {
13499 case COMMUNITY_DENY:
13500 return "deny";
13501 case COMMUNITY_PERMIT:
13502 return "permit";
13503 default:
13504 return "unknown";
13505 }
13506 }
13507
13508 /* Display error string. */
13509 static void community_list_perror(struct vty *vty, int ret)
13510 {
13511 switch (ret) {
13512 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13513 vty_out(vty, "%% Can't find community-list\n");
13514 break;
13515 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13516 vty_out(vty, "%% Malformed community-list value\n");
13517 break;
13518 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13519 vty_out(vty,
13520 "%% Community name conflict, previously defined as standard community\n");
13521 break;
13522 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13523 vty_out(vty,
13524 "%% Community name conflict, previously defined as expanded community\n");
13525 break;
13526 }
13527 }
13528
13529 /* "community-list" keyword help string. */
13530 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13531
13532 /* ip community-list standard */
13533 DEFUN (ip_community_list_standard,
13534 ip_community_list_standard_cmd,
13535 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13536 IP_STR
13537 COMMUNITY_LIST_STR
13538 "Community list number (standard)\n"
13539 "Add an standard community-list entry\n"
13540 "Community list name\n"
13541 "Specify community to reject\n"
13542 "Specify community to accept\n"
13543 COMMUNITY_VAL_STR)
13544 {
13545 char *cl_name_or_number = NULL;
13546 int direct = 0;
13547 int style = COMMUNITY_LIST_STANDARD;
13548
13549 int idx = 0;
13550 argv_find(argv, argc, "(1-99)", &idx);
13551 argv_find(argv, argc, "WORD", &idx);
13552 cl_name_or_number = argv[idx]->arg;
13553 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13554 : COMMUNITY_DENY;
13555 argv_find(argv, argc, "AA:NN", &idx);
13556 char *str = argv_concat(argv, argc, idx);
13557
13558 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13559 style);
13560
13561 XFREE(MTYPE_TMP, str);
13562
13563 if (ret < 0) {
13564 /* Display error string. */
13565 community_list_perror(vty, ret);
13566 return CMD_WARNING_CONFIG_FAILED;
13567 }
13568
13569 return CMD_SUCCESS;
13570 }
13571
13572 DEFUN (no_ip_community_list_standard_all,
13573 no_ip_community_list_standard_all_cmd,
13574 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13575 NO_STR
13576 IP_STR
13577 COMMUNITY_LIST_STR
13578 "Community list number (standard)\n"
13579 "Add an standard community-list entry\n"
13580 "Community list name\n"
13581 "Specify community to reject\n"
13582 "Specify community to accept\n"
13583 COMMUNITY_VAL_STR)
13584 {
13585 char *cl_name_or_number = NULL;
13586 int direct = 0;
13587 int style = COMMUNITY_LIST_STANDARD;
13588
13589 int idx = 0;
13590 argv_find(argv, argc, "(1-99)", &idx);
13591 argv_find(argv, argc, "WORD", &idx);
13592 cl_name_or_number = argv[idx]->arg;
13593 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13594 : COMMUNITY_DENY;
13595 argv_find(argv, argc, "AA:NN", &idx);
13596 char *str = argv_concat(argv, argc, idx);
13597
13598 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13599 direct, style);
13600
13601 XFREE(MTYPE_TMP, str);
13602
13603 if (ret < 0) {
13604 community_list_perror(vty, ret);
13605 return CMD_WARNING_CONFIG_FAILED;
13606 }
13607
13608 return CMD_SUCCESS;
13609 }
13610
13611 /* ip community-list expanded */
13612 DEFUN (ip_community_list_expanded_all,
13613 ip_community_list_expanded_all_cmd,
13614 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13615 IP_STR
13616 COMMUNITY_LIST_STR
13617 "Community list number (expanded)\n"
13618 "Add an expanded community-list entry\n"
13619 "Community list name\n"
13620 "Specify community to reject\n"
13621 "Specify community to accept\n"
13622 COMMUNITY_VAL_STR)
13623 {
13624 char *cl_name_or_number = NULL;
13625 int direct = 0;
13626 int style = COMMUNITY_LIST_EXPANDED;
13627
13628 int idx = 0;
13629 argv_find(argv, argc, "(100-500)", &idx);
13630 argv_find(argv, argc, "WORD", &idx);
13631 cl_name_or_number = argv[idx]->arg;
13632 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13633 : COMMUNITY_DENY;
13634 argv_find(argv, argc, "AA:NN", &idx);
13635 char *str = argv_concat(argv, argc, idx);
13636
13637 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13638 style);
13639
13640 XFREE(MTYPE_TMP, str);
13641
13642 if (ret < 0) {
13643 /* Display error string. */
13644 community_list_perror(vty, ret);
13645 return CMD_WARNING_CONFIG_FAILED;
13646 }
13647
13648 return CMD_SUCCESS;
13649 }
13650
13651 DEFUN (no_ip_community_list_expanded_all,
13652 no_ip_community_list_expanded_all_cmd,
13653 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13654 NO_STR
13655 IP_STR
13656 COMMUNITY_LIST_STR
13657 "Community list number (expanded)\n"
13658 "Add an expanded community-list entry\n"
13659 "Community list name\n"
13660 "Specify community to reject\n"
13661 "Specify community to accept\n"
13662 COMMUNITY_VAL_STR)
13663 {
13664 char *cl_name_or_number = NULL;
13665 int direct = 0;
13666 int style = COMMUNITY_LIST_EXPANDED;
13667
13668 int idx = 0;
13669 argv_find(argv, argc, "(100-500)", &idx);
13670 argv_find(argv, argc, "WORD", &idx);
13671 cl_name_or_number = argv[idx]->arg;
13672 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13673 : COMMUNITY_DENY;
13674 argv_find(argv, argc, "AA:NN", &idx);
13675 char *str = argv_concat(argv, argc, idx);
13676
13677 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13678 direct, style);
13679
13680 XFREE(MTYPE_TMP, str);
13681
13682 if (ret < 0) {
13683 community_list_perror(vty, ret);
13684 return CMD_WARNING_CONFIG_FAILED;
13685 }
13686
13687 return CMD_SUCCESS;
13688 }
13689
13690 /* Return configuration string of community-list entry. */
13691 static const char *community_list_config_str(struct community_entry *entry)
13692 {
13693 const char *str;
13694
13695 if (entry->any)
13696 str = "";
13697 else {
13698 if (entry->style == COMMUNITY_LIST_STANDARD)
13699 str = community_str(entry->u.com, false);
13700 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13701 str = lcommunity_str(entry->u.lcom, false);
13702 else
13703 str = entry->config;
13704 }
13705 return str;
13706 }
13707
13708 static void community_list_show(struct vty *vty, struct community_list *list)
13709 {
13710 struct community_entry *entry;
13711
13712 for (entry = list->head; entry; entry = entry->next) {
13713 if (entry == list->head) {
13714 if (all_digit(list->name))
13715 vty_out(vty, "Community %s list %s\n",
13716 entry->style == COMMUNITY_LIST_STANDARD
13717 ? "standard"
13718 : "(expanded) access",
13719 list->name);
13720 else
13721 vty_out(vty, "Named Community %s list %s\n",
13722 entry->style == COMMUNITY_LIST_STANDARD
13723 ? "standard"
13724 : "expanded",
13725 list->name);
13726 }
13727 if (entry->any)
13728 vty_out(vty, " %s\n",
13729 community_direct_str(entry->direct));
13730 else
13731 vty_out(vty, " %s %s\n",
13732 community_direct_str(entry->direct),
13733 community_list_config_str(entry));
13734 }
13735 }
13736
13737 DEFUN (show_ip_community_list,
13738 show_ip_community_list_cmd,
13739 "show ip community-list",
13740 SHOW_STR
13741 IP_STR
13742 "List community-list\n")
13743 {
13744 struct community_list *list;
13745 struct community_list_master *cm;
13746
13747 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13748 if (!cm)
13749 return CMD_SUCCESS;
13750
13751 for (list = cm->num.head; list; list = list->next)
13752 community_list_show(vty, list);
13753
13754 for (list = cm->str.head; list; list = list->next)
13755 community_list_show(vty, list);
13756
13757 return CMD_SUCCESS;
13758 }
13759
13760 DEFUN (show_ip_community_list_arg,
13761 show_ip_community_list_arg_cmd,
13762 "show ip community-list <(1-500)|WORD>",
13763 SHOW_STR
13764 IP_STR
13765 "List community-list\n"
13766 "Community-list number\n"
13767 "Community-list name\n")
13768 {
13769 int idx_comm_list = 3;
13770 struct community_list *list;
13771
13772 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13773 COMMUNITY_LIST_MASTER);
13774 if (!list) {
13775 vty_out(vty, "%% Can't find community-list\n");
13776 return CMD_WARNING;
13777 }
13778
13779 community_list_show(vty, list);
13780
13781 return CMD_SUCCESS;
13782 }
13783
13784 /*
13785 * Large Community code.
13786 */
13787 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13788 struct cmd_token **argv, int style,
13789 int reject_all_digit_name)
13790 {
13791 int ret;
13792 int direct;
13793 char *str;
13794 int idx = 0;
13795 char *cl_name;
13796
13797 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13798 : COMMUNITY_DENY;
13799
13800 /* All digit name check. */
13801 idx = 0;
13802 argv_find(argv, argc, "WORD", &idx);
13803 argv_find(argv, argc, "(1-99)", &idx);
13804 argv_find(argv, argc, "(100-500)", &idx);
13805 cl_name = argv[idx]->arg;
13806 if (reject_all_digit_name && all_digit(cl_name)) {
13807 vty_out(vty, "%% Community name cannot have all digits\n");
13808 return CMD_WARNING_CONFIG_FAILED;
13809 }
13810
13811 idx = 0;
13812 argv_find(argv, argc, "AA:BB:CC", &idx);
13813 argv_find(argv, argc, "LINE", &idx);
13814 /* Concat community string argument. */
13815 if (idx)
13816 str = argv_concat(argv, argc, idx);
13817 else
13818 str = NULL;
13819
13820 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13821
13822 /* Free temporary community list string allocated by
13823 argv_concat(). */
13824 if (str)
13825 XFREE(MTYPE_TMP, str);
13826
13827 if (ret < 0) {
13828 community_list_perror(vty, ret);
13829 return CMD_WARNING_CONFIG_FAILED;
13830 }
13831 return CMD_SUCCESS;
13832 }
13833
13834 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13835 struct cmd_token **argv, int style)
13836 {
13837 int ret;
13838 int direct = 0;
13839 char *str = NULL;
13840 int idx = 0;
13841
13842 argv_find(argv, argc, "permit", &idx);
13843 argv_find(argv, argc, "deny", &idx);
13844
13845 if (idx) {
13846 /* Check the list direct. */
13847 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13848 direct = COMMUNITY_PERMIT;
13849 else
13850 direct = COMMUNITY_DENY;
13851
13852 idx = 0;
13853 argv_find(argv, argc, "LINE", &idx);
13854 argv_find(argv, argc, "AA:AA:NN", &idx);
13855 /* Concat community string argument. */
13856 str = argv_concat(argv, argc, idx);
13857 }
13858
13859 idx = 0;
13860 argv_find(argv, argc, "(1-99)", &idx);
13861 argv_find(argv, argc, "(100-500)", &idx);
13862 argv_find(argv, argc, "WORD", &idx);
13863
13864 /* Unset community list. */
13865 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13866 style);
13867
13868 /* Free temporary community list string allocated by
13869 argv_concat(). */
13870 if (str)
13871 XFREE(MTYPE_TMP, str);
13872
13873 if (ret < 0) {
13874 community_list_perror(vty, ret);
13875 return CMD_WARNING_CONFIG_FAILED;
13876 }
13877
13878 return CMD_SUCCESS;
13879 }
13880
13881 /* "large-community-list" keyword help string. */
13882 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13883 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13884
13885 DEFUN (ip_lcommunity_list_standard,
13886 ip_lcommunity_list_standard_cmd,
13887 "ip large-community-list (1-99) <deny|permit>",
13888 IP_STR
13889 LCOMMUNITY_LIST_STR
13890 "Large Community list number (standard)\n"
13891 "Specify large community to reject\n"
13892 "Specify large community to accept\n")
13893 {
13894 return lcommunity_list_set_vty(vty, argc, argv,
13895 LARGE_COMMUNITY_LIST_STANDARD, 0);
13896 }
13897
13898 DEFUN (ip_lcommunity_list_standard1,
13899 ip_lcommunity_list_standard1_cmd,
13900 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
13901 IP_STR
13902 LCOMMUNITY_LIST_STR
13903 "Large Community list number (standard)\n"
13904 "Specify large community to reject\n"
13905 "Specify large community to accept\n"
13906 LCOMMUNITY_VAL_STR)
13907 {
13908 return lcommunity_list_set_vty(vty, argc, argv,
13909 LARGE_COMMUNITY_LIST_STANDARD, 0);
13910 }
13911
13912 DEFUN (ip_lcommunity_list_expanded,
13913 ip_lcommunity_list_expanded_cmd,
13914 "ip large-community-list (100-500) <deny|permit> LINE...",
13915 IP_STR
13916 LCOMMUNITY_LIST_STR
13917 "Large Community list number (expanded)\n"
13918 "Specify large community to reject\n"
13919 "Specify large community to accept\n"
13920 "An ordered list as a regular-expression\n")
13921 {
13922 return lcommunity_list_set_vty(vty, argc, argv,
13923 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13924 }
13925
13926 DEFUN (ip_lcommunity_list_name_standard,
13927 ip_lcommunity_list_name_standard_cmd,
13928 "ip large-community-list standard WORD <deny|permit>",
13929 IP_STR
13930 LCOMMUNITY_LIST_STR
13931 "Specify standard large-community-list\n"
13932 "Large Community list name\n"
13933 "Specify large community to reject\n"
13934 "Specify large community to accept\n")
13935 {
13936 return lcommunity_list_set_vty(vty, argc, argv,
13937 LARGE_COMMUNITY_LIST_STANDARD, 1);
13938 }
13939
13940 DEFUN (ip_lcommunity_list_name_standard1,
13941 ip_lcommunity_list_name_standard1_cmd,
13942 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13943 IP_STR
13944 LCOMMUNITY_LIST_STR
13945 "Specify standard large-community-list\n"
13946 "Large Community list name\n"
13947 "Specify large community to reject\n"
13948 "Specify large community to accept\n"
13949 LCOMMUNITY_VAL_STR)
13950 {
13951 return lcommunity_list_set_vty(vty, argc, argv,
13952 LARGE_COMMUNITY_LIST_STANDARD, 1);
13953 }
13954
13955 DEFUN (ip_lcommunity_list_name_expanded,
13956 ip_lcommunity_list_name_expanded_cmd,
13957 "ip large-community-list expanded WORD <deny|permit> LINE...",
13958 IP_STR
13959 LCOMMUNITY_LIST_STR
13960 "Specify expanded large-community-list\n"
13961 "Large Community list name\n"
13962 "Specify large community to reject\n"
13963 "Specify large community to accept\n"
13964 "An ordered list as a regular-expression\n")
13965 {
13966 return lcommunity_list_set_vty(vty, argc, argv,
13967 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13968 }
13969
13970 DEFUN (no_ip_lcommunity_list_standard_all,
13971 no_ip_lcommunity_list_standard_all_cmd,
13972 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13973 NO_STR
13974 IP_STR
13975 LCOMMUNITY_LIST_STR
13976 "Large Community list number (standard)\n"
13977 "Large Community list number (expanded)\n"
13978 "Large Community list name\n")
13979 {
13980 return lcommunity_list_unset_vty(vty, argc, argv,
13981 LARGE_COMMUNITY_LIST_STANDARD);
13982 }
13983
13984 DEFUN (no_ip_lcommunity_list_name_expanded_all,
13985 no_ip_lcommunity_list_name_expanded_all_cmd,
13986 "no ip large-community-list expanded WORD",
13987 NO_STR
13988 IP_STR
13989 LCOMMUNITY_LIST_STR
13990 "Specify expanded large-community-list\n"
13991 "Large Community list name\n")
13992 {
13993 return lcommunity_list_unset_vty(vty, argc, argv,
13994 LARGE_COMMUNITY_LIST_EXPANDED);
13995 }
13996
13997 DEFUN (no_ip_lcommunity_list_standard,
13998 no_ip_lcommunity_list_standard_cmd,
13999 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14000 NO_STR
14001 IP_STR
14002 LCOMMUNITY_LIST_STR
14003 "Large Community list number (standard)\n"
14004 "Specify large community to reject\n"
14005 "Specify large community to accept\n"
14006 LCOMMUNITY_VAL_STR)
14007 {
14008 return lcommunity_list_unset_vty(vty, argc, argv,
14009 LARGE_COMMUNITY_LIST_STANDARD);
14010 }
14011
14012 DEFUN (no_ip_lcommunity_list_expanded,
14013 no_ip_lcommunity_list_expanded_cmd,
14014 "no ip large-community-list (100-500) <deny|permit> LINE...",
14015 NO_STR
14016 IP_STR
14017 LCOMMUNITY_LIST_STR
14018 "Large Community list number (expanded)\n"
14019 "Specify large community to reject\n"
14020 "Specify large community to accept\n"
14021 "An ordered list as a regular-expression\n")
14022 {
14023 return lcommunity_list_unset_vty(vty, argc, argv,
14024 LARGE_COMMUNITY_LIST_EXPANDED);
14025 }
14026
14027 DEFUN (no_ip_lcommunity_list_name_standard,
14028 no_ip_lcommunity_list_name_standard_cmd,
14029 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14030 NO_STR
14031 IP_STR
14032 LCOMMUNITY_LIST_STR
14033 "Specify standard large-community-list\n"
14034 "Large Community list name\n"
14035 "Specify large community to reject\n"
14036 "Specify large community to accept\n"
14037 LCOMMUNITY_VAL_STR)
14038 {
14039 return lcommunity_list_unset_vty(vty, argc, argv,
14040 LARGE_COMMUNITY_LIST_STANDARD);
14041 }
14042
14043 DEFUN (no_ip_lcommunity_list_name_expanded,
14044 no_ip_lcommunity_list_name_expanded_cmd,
14045 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14046 NO_STR
14047 IP_STR
14048 LCOMMUNITY_LIST_STR
14049 "Specify expanded large-community-list\n"
14050 "Large community list name\n"
14051 "Specify large community to reject\n"
14052 "Specify large community to accept\n"
14053 "An ordered list as a regular-expression\n")
14054 {
14055 return lcommunity_list_unset_vty(vty, argc, argv,
14056 LARGE_COMMUNITY_LIST_EXPANDED);
14057 }
14058
14059 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14060 {
14061 struct community_entry *entry;
14062
14063 for (entry = list->head; entry; entry = entry->next) {
14064 if (entry == list->head) {
14065 if (all_digit(list->name))
14066 vty_out(vty, "Large community %s list %s\n",
14067 entry->style == EXTCOMMUNITY_LIST_STANDARD
14068 ? "standard"
14069 : "(expanded) access",
14070 list->name);
14071 else
14072 vty_out(vty,
14073 "Named large community %s list %s\n",
14074 entry->style == EXTCOMMUNITY_LIST_STANDARD
14075 ? "standard"
14076 : "expanded",
14077 list->name);
14078 }
14079 if (entry->any)
14080 vty_out(vty, " %s\n",
14081 community_direct_str(entry->direct));
14082 else
14083 vty_out(vty, " %s %s\n",
14084 community_direct_str(entry->direct),
14085 community_list_config_str(entry));
14086 }
14087 }
14088
14089 DEFUN (show_ip_lcommunity_list,
14090 show_ip_lcommunity_list_cmd,
14091 "show ip large-community-list",
14092 SHOW_STR
14093 IP_STR
14094 "List large-community list\n")
14095 {
14096 struct community_list *list;
14097 struct community_list_master *cm;
14098
14099 cm = community_list_master_lookup(bgp_clist,
14100 LARGE_COMMUNITY_LIST_MASTER);
14101 if (!cm)
14102 return CMD_SUCCESS;
14103
14104 for (list = cm->num.head; list; list = list->next)
14105 lcommunity_list_show(vty, list);
14106
14107 for (list = cm->str.head; list; list = list->next)
14108 lcommunity_list_show(vty, list);
14109
14110 return CMD_SUCCESS;
14111 }
14112
14113 DEFUN (show_ip_lcommunity_list_arg,
14114 show_ip_lcommunity_list_arg_cmd,
14115 "show ip large-community-list <(1-500)|WORD>",
14116 SHOW_STR
14117 IP_STR
14118 "List large-community list\n"
14119 "large-community-list number\n"
14120 "large-community-list name\n")
14121 {
14122 struct community_list *list;
14123
14124 list = community_list_lookup(bgp_clist, argv[3]->arg,
14125 LARGE_COMMUNITY_LIST_MASTER);
14126 if (!list) {
14127 vty_out(vty, "%% Can't find extcommunity-list\n");
14128 return CMD_WARNING;
14129 }
14130
14131 lcommunity_list_show(vty, list);
14132
14133 return CMD_SUCCESS;
14134 }
14135
14136 /* "extcommunity-list" keyword help string. */
14137 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14138 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14139
14140 DEFUN (ip_extcommunity_list_standard,
14141 ip_extcommunity_list_standard_cmd,
14142 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14143 IP_STR
14144 EXTCOMMUNITY_LIST_STR
14145 "Extended Community list number (standard)\n"
14146 "Specify standard extcommunity-list\n"
14147 "Community list name\n"
14148 "Specify community to reject\n"
14149 "Specify community to accept\n"
14150 EXTCOMMUNITY_VAL_STR)
14151 {
14152 int style = EXTCOMMUNITY_LIST_STANDARD;
14153 int direct = 0;
14154 char *cl_number_or_name = NULL;
14155
14156 int idx = 0;
14157 argv_find(argv, argc, "(1-99)", &idx);
14158 argv_find(argv, argc, "WORD", &idx);
14159 cl_number_or_name = argv[idx]->arg;
14160 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14161 : COMMUNITY_DENY;
14162 argv_find(argv, argc, "AA:NN", &idx);
14163 char *str = argv_concat(argv, argc, idx);
14164
14165 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14166 direct, style);
14167
14168 XFREE(MTYPE_TMP, str);
14169
14170 if (ret < 0) {
14171 community_list_perror(vty, ret);
14172 return CMD_WARNING_CONFIG_FAILED;
14173 }
14174
14175 return CMD_SUCCESS;
14176 }
14177
14178 DEFUN (ip_extcommunity_list_name_expanded,
14179 ip_extcommunity_list_name_expanded_cmd,
14180 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14181 IP_STR
14182 EXTCOMMUNITY_LIST_STR
14183 "Extended Community list number (expanded)\n"
14184 "Specify expanded extcommunity-list\n"
14185 "Extended Community list name\n"
14186 "Specify community to reject\n"
14187 "Specify community to accept\n"
14188 "An ordered list as a regular-expression\n")
14189 {
14190 int style = EXTCOMMUNITY_LIST_EXPANDED;
14191 int direct = 0;
14192 char *cl_number_or_name = NULL;
14193
14194 int idx = 0;
14195 argv_find(argv, argc, "(100-500)", &idx);
14196 argv_find(argv, argc, "WORD", &idx);
14197 cl_number_or_name = argv[idx]->arg;
14198 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14199 : COMMUNITY_DENY;
14200 argv_find(argv, argc, "LINE", &idx);
14201 char *str = argv_concat(argv, argc, idx);
14202
14203 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14204 direct, style);
14205
14206 XFREE(MTYPE_TMP, str);
14207
14208 if (ret < 0) {
14209 community_list_perror(vty, ret);
14210 return CMD_WARNING_CONFIG_FAILED;
14211 }
14212
14213 return CMD_SUCCESS;
14214 }
14215
14216 DEFUN (no_ip_extcommunity_list_standard_all,
14217 no_ip_extcommunity_list_standard_all_cmd,
14218 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14219 NO_STR
14220 IP_STR
14221 EXTCOMMUNITY_LIST_STR
14222 "Extended Community list number (standard)\n"
14223 "Specify standard extcommunity-list\n"
14224 "Community list name\n"
14225 "Specify community to reject\n"
14226 "Specify community to accept\n"
14227 EXTCOMMUNITY_VAL_STR)
14228 {
14229 int style = EXTCOMMUNITY_LIST_STANDARD;
14230 int direct = 0;
14231 char *cl_number_or_name = NULL;
14232
14233 int idx = 0;
14234 argv_find(argv, argc, "(1-99)", &idx);
14235 argv_find(argv, argc, "WORD", &idx);
14236 cl_number_or_name = argv[idx]->arg;
14237 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14238 : COMMUNITY_DENY;
14239 argv_find(argv, argc, "AA:NN", &idx);
14240 char *str = argv_concat(argv, argc, idx);
14241
14242 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14243 direct, style);
14244
14245 XFREE(MTYPE_TMP, str);
14246
14247 if (ret < 0) {
14248 community_list_perror(vty, ret);
14249 return CMD_WARNING_CONFIG_FAILED;
14250 }
14251
14252 return CMD_SUCCESS;
14253 }
14254
14255 DEFUN (no_ip_extcommunity_list_expanded_all,
14256 no_ip_extcommunity_list_expanded_all_cmd,
14257 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14258 NO_STR
14259 IP_STR
14260 EXTCOMMUNITY_LIST_STR
14261 "Extended Community list number (expanded)\n"
14262 "Specify expanded extcommunity-list\n"
14263 "Extended Community list name\n"
14264 "Specify community to reject\n"
14265 "Specify community to accept\n"
14266 "An ordered list as a regular-expression\n")
14267 {
14268 int style = EXTCOMMUNITY_LIST_EXPANDED;
14269 int direct = 0;
14270 char *cl_number_or_name = NULL;
14271
14272 int idx = 0;
14273 argv_find(argv, argc, "(100-500)", &idx);
14274 argv_find(argv, argc, "WORD", &idx);
14275 cl_number_or_name = argv[idx]->arg;
14276 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14277 : COMMUNITY_DENY;
14278 argv_find(argv, argc, "LINE", &idx);
14279 char *str = argv_concat(argv, argc, idx);
14280
14281 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14282 direct, style);
14283
14284 XFREE(MTYPE_TMP, str);
14285
14286 if (ret < 0) {
14287 community_list_perror(vty, ret);
14288 return CMD_WARNING_CONFIG_FAILED;
14289 }
14290
14291 return CMD_SUCCESS;
14292 }
14293
14294 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14295 {
14296 struct community_entry *entry;
14297
14298 for (entry = list->head; entry; entry = entry->next) {
14299 if (entry == list->head) {
14300 if (all_digit(list->name))
14301 vty_out(vty, "Extended community %s list %s\n",
14302 entry->style == EXTCOMMUNITY_LIST_STANDARD
14303 ? "standard"
14304 : "(expanded) access",
14305 list->name);
14306 else
14307 vty_out(vty,
14308 "Named extended community %s list %s\n",
14309 entry->style == EXTCOMMUNITY_LIST_STANDARD
14310 ? "standard"
14311 : "expanded",
14312 list->name);
14313 }
14314 if (entry->any)
14315 vty_out(vty, " %s\n",
14316 community_direct_str(entry->direct));
14317 else
14318 vty_out(vty, " %s %s\n",
14319 community_direct_str(entry->direct),
14320 community_list_config_str(entry));
14321 }
14322 }
14323
14324 DEFUN (show_ip_extcommunity_list,
14325 show_ip_extcommunity_list_cmd,
14326 "show ip extcommunity-list",
14327 SHOW_STR
14328 IP_STR
14329 "List extended-community list\n")
14330 {
14331 struct community_list *list;
14332 struct community_list_master *cm;
14333
14334 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14335 if (!cm)
14336 return CMD_SUCCESS;
14337
14338 for (list = cm->num.head; list; list = list->next)
14339 extcommunity_list_show(vty, list);
14340
14341 for (list = cm->str.head; list; list = list->next)
14342 extcommunity_list_show(vty, list);
14343
14344 return CMD_SUCCESS;
14345 }
14346
14347 DEFUN (show_ip_extcommunity_list_arg,
14348 show_ip_extcommunity_list_arg_cmd,
14349 "show ip extcommunity-list <(1-500)|WORD>",
14350 SHOW_STR
14351 IP_STR
14352 "List extended-community list\n"
14353 "Extcommunity-list number\n"
14354 "Extcommunity-list name\n")
14355 {
14356 int idx_comm_list = 3;
14357 struct community_list *list;
14358
14359 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14360 EXTCOMMUNITY_LIST_MASTER);
14361 if (!list) {
14362 vty_out(vty, "%% Can't find extcommunity-list\n");
14363 return CMD_WARNING;
14364 }
14365
14366 extcommunity_list_show(vty, list);
14367
14368 return CMD_SUCCESS;
14369 }
14370
14371 /* Display community-list and extcommunity-list configuration. */
14372 static int community_list_config_write(struct vty *vty)
14373 {
14374 struct community_list *list;
14375 struct community_entry *entry;
14376 struct community_list_master *cm;
14377 int write = 0;
14378
14379 /* Community-list. */
14380 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14381
14382 for (list = cm->num.head; list; list = list->next)
14383 for (entry = list->head; entry; entry = entry->next) {
14384 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14385 community_direct_str(entry->direct),
14386 community_list_config_str(entry));
14387 write++;
14388 }
14389 for (list = cm->str.head; list; list = list->next)
14390 for (entry = list->head; entry; entry = entry->next) {
14391 vty_out(vty, "ip community-list %s %s %s %s\n",
14392 entry->style == COMMUNITY_LIST_STANDARD
14393 ? "standard"
14394 : "expanded",
14395 list->name, community_direct_str(entry->direct),
14396 community_list_config_str(entry));
14397 write++;
14398 }
14399
14400 /* Extcommunity-list. */
14401 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14402
14403 for (list = cm->num.head; list; list = list->next)
14404 for (entry = list->head; entry; entry = entry->next) {
14405 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14406 list->name, community_direct_str(entry->direct),
14407 community_list_config_str(entry));
14408 write++;
14409 }
14410 for (list = cm->str.head; list; list = list->next)
14411 for (entry = list->head; entry; entry = entry->next) {
14412 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14413 entry->style == EXTCOMMUNITY_LIST_STANDARD
14414 ? "standard"
14415 : "expanded",
14416 list->name, community_direct_str(entry->direct),
14417 community_list_config_str(entry));
14418 write++;
14419 }
14420
14421
14422 /* lcommunity-list. */
14423 cm = community_list_master_lookup(bgp_clist,
14424 LARGE_COMMUNITY_LIST_MASTER);
14425
14426 for (list = cm->num.head; list; list = list->next)
14427 for (entry = list->head; entry; entry = entry->next) {
14428 vty_out(vty, "ip large-community-list %s %s %s\n",
14429 list->name, community_direct_str(entry->direct),
14430 community_list_config_str(entry));
14431 write++;
14432 }
14433 for (list = cm->str.head; list; list = list->next)
14434 for (entry = list->head; entry; entry = entry->next) {
14435 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14436 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14437 ? "standard"
14438 : "expanded",
14439 list->name, community_direct_str(entry->direct),
14440 community_list_config_str(entry));
14441 write++;
14442 }
14443
14444 return write;
14445 }
14446
14447 static struct cmd_node community_list_node = {
14448 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14449 };
14450
14451 static void community_list_vty(void)
14452 {
14453 install_node(&community_list_node, community_list_config_write);
14454
14455 /* Community-list. */
14456 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14457 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14458 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14459 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14460 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14461 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14462
14463 /* Extcommunity-list. */
14464 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14465 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14466 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14467 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14468 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14469 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14470
14471 /* Large Community List */
14472 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14473 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14474 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14475 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14476 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14477 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14478 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14479 install_element(CONFIG_NODE,
14480 &no_ip_lcommunity_list_name_expanded_all_cmd);
14481 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14482 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14483 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14484 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14485 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14486 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14487 }