]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bpgd: resolve more neighbor peer-group issues
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "lib/zclient.h"
26 #include "prefix.h"
27 #include "plist.h"
28 #include "buffer.h"
29 #include "linklist.h"
30 #include "stream.h"
31 #include "thread.h"
32 #include "log.h"
33 #include "memory.h"
34 #include "memory_vty.h"
35 #include "hash.h"
36 #include "queue.h"
37 #include "filter.h"
38 #include "frrstr.h"
39
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_attr_evpn.h"
42 #include "bgpd/bgp_advertise.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_aspath.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_ecommunity.h"
47 #include "bgpd/bgp_lcommunity.h"
48 #include "bgpd/bgp_damp.h"
49 #include "bgpd/bgp_debug.h"
50 #include "bgpd/bgp_errors.h"
51 #include "bgpd/bgp_fsm.h"
52 #include "bgpd/bgp_nexthop.h"
53 #include "bgpd/bgp_open.h"
54 #include "bgpd/bgp_regex.h"
55 #include "bgpd/bgp_route.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_table.h"
59 #include "bgpd/bgp_vty.h"
60 #include "bgpd/bgp_mpath.h"
61 #include "bgpd/bgp_packet.h"
62 #include "bgpd/bgp_updgrp.h"
63 #include "bgpd/bgp_bfd.h"
64 #include "bgpd/bgp_io.h"
65 #include "bgpd/bgp_evpn.h"
66 #include "bgpd/bgp_addpath.h"
67 #include "bgpd/bgp_mac.h"
68
69 static struct peer_group *listen_range_exists(struct bgp *bgp,
70 struct prefix *range, int exact);
71
72 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
73 {
74 switch (afi) {
75 case AFI_IP:
76 switch (safi) {
77 case SAFI_UNICAST:
78 return BGP_IPV4_NODE;
79 break;
80 case SAFI_MULTICAST:
81 return BGP_IPV4M_NODE;
82 break;
83 case SAFI_LABELED_UNICAST:
84 return BGP_IPV4L_NODE;
85 break;
86 case SAFI_MPLS_VPN:
87 return BGP_VPNV4_NODE;
88 break;
89 case SAFI_FLOWSPEC:
90 return BGP_FLOWSPECV4_NODE;
91 default:
92 /* not expected */
93 return BGP_IPV4_NODE;
94 break;
95 }
96 break;
97 case AFI_IP6:
98 switch (safi) {
99 case SAFI_UNICAST:
100 return BGP_IPV6_NODE;
101 break;
102 case SAFI_MULTICAST:
103 return BGP_IPV6M_NODE;
104 break;
105 case SAFI_LABELED_UNICAST:
106 return BGP_IPV6L_NODE;
107 break;
108 case SAFI_MPLS_VPN:
109 return BGP_VPNV6_NODE;
110 break;
111 case SAFI_FLOWSPEC:
112 return BGP_FLOWSPECV6_NODE;
113 default:
114 /* not expected */
115 return BGP_IPV4_NODE;
116 break;
117 }
118 break;
119 case AFI_L2VPN:
120 return BGP_EVPN_NODE;
121 break;
122 case AFI_MAX:
123 // We should never be here but to clarify the switch statement..
124 return BGP_IPV4_NODE;
125 break;
126 }
127
128 // Impossible to happen
129 return BGP_IPV4_NODE;
130 }
131
132 /* Utility function to get address family from current node. */
133 afi_t bgp_node_afi(struct vty *vty)
134 {
135 afi_t afi;
136 switch (vty->node) {
137 case BGP_IPV6_NODE:
138 case BGP_IPV6M_NODE:
139 case BGP_IPV6L_NODE:
140 case BGP_VPNV6_NODE:
141 case BGP_FLOWSPECV6_NODE:
142 afi = AFI_IP6;
143 break;
144 case BGP_EVPN_NODE:
145 afi = AFI_L2VPN;
146 break;
147 default:
148 afi = AFI_IP;
149 break;
150 }
151 return afi;
152 }
153
154 /* Utility function to get subsequent address family from current
155 node. */
156 safi_t bgp_node_safi(struct vty *vty)
157 {
158 safi_t safi;
159 switch (vty->node) {
160 case BGP_VPNV4_NODE:
161 case BGP_VPNV6_NODE:
162 safi = SAFI_MPLS_VPN;
163 break;
164 case BGP_IPV4M_NODE:
165 case BGP_IPV6M_NODE:
166 safi = SAFI_MULTICAST;
167 break;
168 case BGP_EVPN_NODE:
169 safi = SAFI_EVPN;
170 break;
171 case BGP_IPV4L_NODE:
172 case BGP_IPV6L_NODE:
173 safi = SAFI_LABELED_UNICAST;
174 break;
175 case BGP_FLOWSPECV4_NODE:
176 case BGP_FLOWSPECV6_NODE:
177 safi = SAFI_FLOWSPEC;
178 break;
179 default:
180 safi = SAFI_UNICAST;
181 break;
182 }
183 return safi;
184 }
185
186 /**
187 * Converts an AFI in string form to afi_t
188 *
189 * @param afi string, one of
190 * - "ipv4"
191 * - "ipv6"
192 * - "l2vpn"
193 * @return the corresponding afi_t
194 */
195 afi_t bgp_vty_afi_from_str(const char *afi_str)
196 {
197 afi_t afi = AFI_MAX; /* unknown */
198 if (strmatch(afi_str, "ipv4"))
199 afi = AFI_IP;
200 else if (strmatch(afi_str, "ipv6"))
201 afi = AFI_IP6;
202 else if (strmatch(afi_str, "l2vpn"))
203 afi = AFI_L2VPN;
204 return afi;
205 }
206
207 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
208 afi_t *afi)
209 {
210 int ret = 0;
211 if (argv_find(argv, argc, "ipv4", index)) {
212 ret = 1;
213 if (afi)
214 *afi = AFI_IP;
215 } else if (argv_find(argv, argc, "ipv6", index)) {
216 ret = 1;
217 if (afi)
218 *afi = AFI_IP6;
219 }
220 return ret;
221 }
222
223 /* supports <unicast|multicast|vpn|labeled-unicast> */
224 safi_t bgp_vty_safi_from_str(const char *safi_str)
225 {
226 safi_t safi = SAFI_MAX; /* unknown */
227 if (strmatch(safi_str, "multicast"))
228 safi = SAFI_MULTICAST;
229 else if (strmatch(safi_str, "unicast"))
230 safi = SAFI_UNICAST;
231 else if (strmatch(safi_str, "vpn"))
232 safi = SAFI_MPLS_VPN;
233 else if (strmatch(safi_str, "evpn"))
234 safi = SAFI_EVPN;
235 else if (strmatch(safi_str, "labeled-unicast"))
236 safi = SAFI_LABELED_UNICAST;
237 else if (strmatch(safi_str, "flowspec"))
238 safi = SAFI_FLOWSPEC;
239 return safi;
240 }
241
242 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
243 safi_t *safi)
244 {
245 int ret = 0;
246 if (argv_find(argv, argc, "unicast", index)) {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_UNICAST;
250 } else if (argv_find(argv, argc, "multicast", index)) {
251 ret = 1;
252 if (safi)
253 *safi = SAFI_MULTICAST;
254 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_LABELED_UNICAST;
258 } else if (argv_find(argv, argc, "vpn", index)) {
259 ret = 1;
260 if (safi)
261 *safi = SAFI_MPLS_VPN;
262 } else if (argv_find(argv, argc, "flowspec", index)) {
263 ret = 1;
264 if (safi)
265 *safi = SAFI_FLOWSPEC;
266 }
267 return ret;
268 }
269
270 /*
271 * bgp_vty_find_and_parse_afi_safi_bgp
272 *
273 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
274 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
275 * to appropriate values for the calling function. This is to allow the
276 * calling function to make decisions appropriate for the show command
277 * that is being parsed.
278 *
279 * The show commands are generally of the form:
280 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
281 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
282 *
283 * Since we use argv_find if the show command in particular doesn't have:
284 * [ip]
285 * [<view|vrf> VIEWVRFNAME]
286 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
287 * The command parsing should still be ok.
288 *
289 * vty -> The vty for the command so we can output some useful data in
290 * the event of a parse error in the vrf.
291 * argv -> The command tokens
292 * argc -> How many command tokens we have
293 * idx -> The current place in the command, generally should be 0 for this
294 * function
295 * afi -> The parsed afi if it was included in the show command, returned here
296 * safi -> The parsed safi if it was included in the show command, returned here
297 * bgp -> Pointer to the bgp data structure we need to fill in.
298 *
299 * The function returns the correct location in the parse tree for the
300 * last token found.
301 *
302 * Returns 0 for failure to parse correctly, else the idx position of where
303 * it found the last token.
304 */
305 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
306 struct cmd_token **argv, int argc,
307 int *idx, afi_t *afi, safi_t *safi,
308 struct bgp **bgp, bool use_json)
309 {
310 char *vrf_name = NULL;
311
312 assert(afi);
313 assert(safi);
314 assert(bgp);
315
316 if (argv_find(argv, argc, "ip", idx))
317 *afi = AFI_IP;
318
319 if (argv_find(argv, argc, "view", idx))
320 vrf_name = argv[*idx + 1]->arg;
321 else if (argv_find(argv, argc, "vrf", idx)) {
322 vrf_name = argv[*idx + 1]->arg;
323 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
324 vrf_name = NULL;
325 }
326 if (vrf_name) {
327 if (strmatch(vrf_name, "all"))
328 *bgp = NULL;
329 else {
330 *bgp = bgp_lookup_by_name(vrf_name);
331 if (!*bgp) {
332 if (use_json)
333 vty_out(vty, "{}\n");
334 else
335 vty_out(vty, "View/Vrf %s is unknown\n",
336 vrf_name);
337 *idx = 0;
338 return 0;
339 }
340 }
341 } else {
342 *bgp = bgp_get_default();
343 if (!*bgp) {
344 if (use_json)
345 vty_out(vty, "{}\n");
346 else
347 vty_out(vty,
348 "Default BGP instance not found\n");
349 *idx = 0;
350 return 0;
351 }
352 }
353
354 if (argv_find_and_parse_afi(argv, argc, idx, afi))
355 argv_find_and_parse_safi(argv, argc, idx, safi);
356
357 *idx += 1;
358 return *idx;
359 }
360
361 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
362 {
363 struct interface *ifp = NULL;
364
365 if (su->sa.sa_family == AF_INET)
366 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
367 else if (su->sa.sa_family == AF_INET6)
368 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
369 su->sin6.sin6_scope_id,
370 bgp->vrf_id);
371
372 if (ifp)
373 return 1;
374
375 return 0;
376 }
377
378 /* Utility function for looking up peer from VTY. */
379 /* This is used only for configuration, so disallow if attempted on
380 * a dynamic neighbor.
381 */
382 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
383 {
384 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
385 int ret;
386 union sockunion su;
387 struct peer *peer;
388
389 if (!bgp) {
390 return NULL;
391 }
392
393 ret = str2sockunion(ip_str, &su);
394 if (ret < 0) {
395 peer = peer_lookup_by_conf_if(bgp, ip_str);
396 if (!peer) {
397 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
398 == NULL) {
399 vty_out(vty,
400 "%% Malformed address or name: %s\n",
401 ip_str);
402 return NULL;
403 }
404 }
405 } else {
406 peer = peer_lookup(bgp, &su);
407 if (!peer) {
408 vty_out(vty,
409 "%% Specify remote-as or peer-group commands first\n");
410 return NULL;
411 }
412 if (peer_dynamic_neighbor(peer)) {
413 vty_out(vty,
414 "%% Operation not allowed on a dynamic neighbor\n");
415 return NULL;
416 }
417 }
418 return peer;
419 }
420
421 /* Utility function for looking up peer or peer group. */
422 /* This is used only for configuration, so disallow if attempted on
423 * a dynamic neighbor.
424 */
425 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
426 {
427 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
428 int ret;
429 union sockunion su;
430 struct peer *peer = NULL;
431 struct peer_group *group = NULL;
432
433 if (!bgp) {
434 return NULL;
435 }
436
437 ret = str2sockunion(peer_str, &su);
438 if (ret == 0) {
439 /* IP address, locate peer. */
440 peer = peer_lookup(bgp, &su);
441 } else {
442 /* Not IP, could match either peer configured on interface or a
443 * group. */
444 peer = peer_lookup_by_conf_if(bgp, peer_str);
445 if (!peer)
446 group = peer_group_lookup(bgp, peer_str);
447 }
448
449 if (peer) {
450 if (peer_dynamic_neighbor(peer)) {
451 vty_out(vty,
452 "%% Operation not allowed on a dynamic neighbor\n");
453 return NULL;
454 }
455
456 return peer;
457 }
458
459 if (group)
460 return group->conf;
461
462 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
463
464 return NULL;
465 }
466
467 int bgp_vty_return(struct vty *vty, int ret)
468 {
469 const char *str = NULL;
470
471 switch (ret) {
472 case BGP_ERR_INVALID_VALUE:
473 str = "Invalid value";
474 break;
475 case BGP_ERR_INVALID_FLAG:
476 str = "Invalid flag";
477 break;
478 case BGP_ERR_PEER_GROUP_SHUTDOWN:
479 str = "Peer-group has been shutdown. Activate the peer-group first";
480 break;
481 case BGP_ERR_PEER_FLAG_CONFLICT:
482 str = "Can't set override-capability and strict-capability-match at the same time";
483 break;
484 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
485 str = "Specify remote-as or peer-group remote AS first";
486 break;
487 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
488 str = "Cannot change the peer-group. Deconfigure first";
489 break;
490 case BGP_ERR_PEER_GROUP_MISMATCH:
491 str = "Peer is not a member of this peer-group";
492 break;
493 case BGP_ERR_PEER_FILTER_CONFLICT:
494 str = "Prefix/distribute list can not co-exist";
495 break;
496 case BGP_ERR_NOT_INTERNAL_PEER:
497 str = "Invalid command. Not an internal neighbor";
498 break;
499 case BGP_ERR_REMOVE_PRIVATE_AS:
500 str = "remove-private-AS cannot be configured for IBGP peers";
501 break;
502 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
503 str = "Local-AS allowed only for EBGP peers";
504 break;
505 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
506 str = "Cannot have local-as same as BGP AS number";
507 break;
508 case BGP_ERR_TCPSIG_FAILED:
509 str = "Error while applying TCP-Sig to session(s)";
510 break;
511 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
512 str = "ebgp-multihop and ttl-security cannot be configured together";
513 break;
514 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
515 str = "ttl-security only allowed for EBGP peers";
516 break;
517 case BGP_ERR_AS_OVERRIDE:
518 str = "as-override cannot be configured for IBGP peers";
519 break;
520 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
521 str = "Invalid limit for number of dynamic neighbors";
522 break;
523 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
524 str = "Dynamic neighbor listen range already exists";
525 break;
526 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
527 str = "Operation not allowed on a dynamic neighbor";
528 break;
529 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
530 str = "Operation not allowed on a directly connected neighbor";
531 break;
532 case BGP_ERR_PEER_SAFI_CONFLICT:
533 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
534 break;
535 }
536 if (str) {
537 vty_out(vty, "%% %s\n", str);
538 return CMD_WARNING_CONFIG_FAILED;
539 }
540 return CMD_SUCCESS;
541 }
542
543 /* BGP clear sort. */
544 enum clear_sort {
545 clear_all,
546 clear_peer,
547 clear_group,
548 clear_external,
549 clear_as
550 };
551
552 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
553 safi_t safi, int error)
554 {
555 switch (error) {
556 case BGP_ERR_AF_UNCONFIGURED:
557 vty_out(vty,
558 "%%BGP: Enable %s address family for the neighbor %s\n",
559 afi_safi_print(afi, safi), peer->host);
560 break;
561 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
562 vty_out(vty,
563 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
564 peer->host);
565 break;
566 default:
567 break;
568 }
569 }
570
571 /* `clear ip bgp' functions. */
572 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
573 enum clear_sort sort, enum bgp_clear_type stype,
574 const char *arg)
575 {
576 int ret;
577 bool found = false;
578 struct peer *peer;
579 struct listnode *node, *nnode;
580
581 /* Clear all neighbors. */
582 /*
583 * Pass along pointer to next node to peer_clear() when walking all
584 * nodes on the BGP instance as that may get freed if it is a
585 * doppelganger
586 */
587 if (sort == clear_all) {
588 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
589 if (!peer->afc[afi][safi])
590 continue;
591
592 if (stype == BGP_CLEAR_SOFT_NONE)
593 ret = peer_clear(peer, &nnode);
594 else
595 ret = peer_clear_soft(peer, afi, safi, stype);
596
597 if (ret < 0)
598 bgp_clear_vty_error(vty, peer, afi, safi, ret);
599 else
600 found = true;
601 }
602
603 /* This is to apply read-only mode on this clear. */
604 if (stype == BGP_CLEAR_SOFT_NONE)
605 bgp->update_delay_over = 0;
606
607 if (!found)
608 vty_out(vty, "%%BGP: No %s peer configured\n",
609 afi_safi_print(afi, safi));
610
611 return CMD_SUCCESS;
612 }
613
614 /* Clear specified neighbor. */
615 if (sort == clear_peer) {
616 union sockunion su;
617
618 /* Make sockunion for lookup. */
619 ret = str2sockunion(arg, &su);
620 if (ret < 0) {
621 peer = peer_lookup_by_conf_if(bgp, arg);
622 if (!peer) {
623 peer = peer_lookup_by_hostname(bgp, arg);
624 if (!peer) {
625 vty_out(vty,
626 "Malformed address or name: %s\n",
627 arg);
628 return CMD_WARNING;
629 }
630 }
631 } else {
632 peer = peer_lookup(bgp, &su);
633 if (!peer) {
634 vty_out(vty,
635 "%%BGP: Unknown neighbor - \"%s\"\n",
636 arg);
637 return CMD_WARNING;
638 }
639 }
640
641 if (!peer->afc[afi][safi])
642 ret = BGP_ERR_AF_UNCONFIGURED;
643 else if (stype == BGP_CLEAR_SOFT_NONE)
644 ret = peer_clear(peer, NULL);
645 else
646 ret = peer_clear_soft(peer, afi, safi, stype);
647
648 if (ret < 0)
649 bgp_clear_vty_error(vty, peer, afi, safi, ret);
650
651 return CMD_SUCCESS;
652 }
653
654 /* Clear all neighbors belonging to a specific peer-group. */
655 if (sort == clear_group) {
656 struct peer_group *group;
657
658 group = peer_group_lookup(bgp, arg);
659 if (!group) {
660 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
661 return CMD_WARNING;
662 }
663
664 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
665 if (!peer->afc[afi][safi])
666 continue;
667
668 if (stype == BGP_CLEAR_SOFT_NONE)
669 ret = peer_clear(peer, NULL);
670 else
671 ret = peer_clear_soft(peer, afi, safi, stype);
672
673 if (ret < 0)
674 bgp_clear_vty_error(vty, peer, afi, safi, ret);
675 else
676 found = true;
677 }
678
679 if (!found)
680 vty_out(vty,
681 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
682 afi_safi_print(afi, safi), arg);
683
684 return CMD_SUCCESS;
685 }
686
687 /* Clear all external (eBGP) neighbors. */
688 if (sort == clear_external) {
689 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
690 if (peer->sort == BGP_PEER_IBGP)
691 continue;
692
693 if (!peer->afc[afi][safi])
694 continue;
695
696 if (stype == BGP_CLEAR_SOFT_NONE)
697 ret = peer_clear(peer, &nnode);
698 else
699 ret = peer_clear_soft(peer, afi, safi, stype);
700
701 if (ret < 0)
702 bgp_clear_vty_error(vty, peer, afi, safi, ret);
703 else
704 found = true;
705 }
706
707 if (!found)
708 vty_out(vty,
709 "%%BGP: No external %s peer is configured\n",
710 afi_safi_print(afi, safi));
711
712 return CMD_SUCCESS;
713 }
714
715 /* Clear all neighbors belonging to a specific AS. */
716 if (sort == clear_as) {
717 as_t as = strtoul(arg, NULL, 10);
718
719 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
720 if (peer->as != as)
721 continue;
722
723 if (!peer->afc[afi][safi])
724 ret = BGP_ERR_AF_UNCONFIGURED;
725 else if (stype == BGP_CLEAR_SOFT_NONE)
726 ret = peer_clear(peer, &nnode);
727 else
728 ret = peer_clear_soft(peer, afi, safi, stype);
729
730 if (ret < 0)
731 bgp_clear_vty_error(vty, peer, afi, safi, ret);
732 else
733 found = true;
734 }
735
736 if (!found)
737 vty_out(vty,
738 "%%BGP: No %s peer is configured with AS %s\n",
739 afi_safi_print(afi, safi), arg);
740
741 return CMD_SUCCESS;
742 }
743
744 return CMD_SUCCESS;
745 }
746
747 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
748 safi_t safi, enum clear_sort sort,
749 enum bgp_clear_type stype, const char *arg)
750 {
751 struct bgp *bgp;
752
753 /* BGP structure lookup. */
754 if (name) {
755 bgp = bgp_lookup_by_name(name);
756 if (bgp == NULL) {
757 vty_out(vty, "Can't find BGP instance %s\n", name);
758 return CMD_WARNING;
759 }
760 } else {
761 bgp = bgp_get_default();
762 if (bgp == NULL) {
763 vty_out(vty, "No BGP process is configured\n");
764 return CMD_WARNING;
765 }
766 }
767
768 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
769 }
770
771 /* clear soft inbound */
772 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
773 {
774 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
775 BGP_CLEAR_SOFT_IN, NULL);
776 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
777 BGP_CLEAR_SOFT_IN, NULL);
778 }
779
780 /* clear soft outbound */
781 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
782 {
783 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
784 BGP_CLEAR_SOFT_OUT, NULL);
785 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
786 BGP_CLEAR_SOFT_OUT, NULL);
787 }
788
789
790 #ifndef VTYSH_EXTRACT_PL
791 #include "bgpd/bgp_vty_clippy.c"
792 #endif
793
794 /* BGP global configuration. */
795 #if (CONFDATE > 20190601)
796 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
797 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
798 #endif
799 DEFUN_HIDDEN (bgp_multiple_instance_func,
800 bgp_multiple_instance_cmd,
801 "bgp multiple-instance",
802 BGP_STR
803 "Enable bgp multiple instance\n")
804 {
805 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
806 return CMD_SUCCESS;
807 }
808
809 DEFUN_HIDDEN (no_bgp_multiple_instance,
810 no_bgp_multiple_instance_cmd,
811 "no bgp multiple-instance",
812 NO_STR
813 BGP_STR
814 "BGP multiple instance\n")
815 {
816 int ret;
817
818 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
819 vty_out(vty, "if you are using this please let the developers know\n");
820 zlog_info("Deprecated option: `bgp multiple-instance` being used");
821 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
822 if (ret < 0) {
823 vty_out(vty, "%% There are more than two BGP instances\n");
824 return CMD_WARNING_CONFIG_FAILED;
825 }
826 return CMD_SUCCESS;
827 }
828
829 DEFUN_HIDDEN (bgp_local_mac,
830 bgp_local_mac_cmd,
831 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
832 BGP_STR
833 "Local MAC config\n"
834 "VxLAN Network Identifier\n"
835 "VNI number\n"
836 "local mac\n"
837 "mac address\n"
838 "mac-mobility sequence\n"
839 "seq number\n")
840 {
841 int rv;
842 vni_t vni;
843 struct ethaddr mac;
844 struct ipaddr ip;
845 uint32_t seq;
846 struct bgp *bgp;
847
848 vni = strtoul(argv[3]->arg, NULL, 10);
849 if (!prefix_str2mac(argv[5]->arg, &mac)) {
850 vty_out(vty, "%% Malformed MAC address\n");
851 return CMD_WARNING;
852 }
853 memset(&ip, 0, sizeof(ip));
854 seq = strtoul(argv[7]->arg, NULL, 10);
855
856 bgp = bgp_get_default();
857 if (!bgp) {
858 vty_out(vty, "Default BGP instance is not there\n");
859 return CMD_WARNING;
860 }
861
862 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
863 if (rv < 0) {
864 vty_out(vty, "Internal error\n");
865 return CMD_WARNING;
866 }
867
868 return CMD_SUCCESS;
869 }
870
871 DEFUN_HIDDEN (no_bgp_local_mac,
872 no_bgp_local_mac_cmd,
873 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
874 NO_STR
875 BGP_STR
876 "Local MAC config\n"
877 "VxLAN Network Identifier\n"
878 "VNI number\n"
879 "local mac\n"
880 "mac address\n")
881 {
882 int rv;
883 vni_t vni;
884 struct ethaddr mac;
885 struct ipaddr ip;
886 struct bgp *bgp;
887
888 vni = strtoul(argv[4]->arg, NULL, 10);
889 if (!prefix_str2mac(argv[6]->arg, &mac)) {
890 vty_out(vty, "%% Malformed MAC address\n");
891 return CMD_WARNING;
892 }
893 memset(&ip, 0, sizeof(ip));
894
895 bgp = bgp_get_default();
896 if (!bgp) {
897 vty_out(vty, "Default BGP instance is not there\n");
898 return CMD_WARNING;
899 }
900
901 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, ZEBRA_NEIGH_ACTIVE);
902 if (rv < 0) {
903 vty_out(vty, "Internal error\n");
904 return CMD_WARNING;
905 }
906
907 return CMD_SUCCESS;
908 }
909
910 #if (CONFDATE > 20190601)
911 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
912 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
913 #endif
914 DEFUN_HIDDEN (bgp_config_type,
915 bgp_config_type_cmd,
916 "bgp config-type <cisco|zebra>",
917 BGP_STR
918 "Configuration type\n"
919 "cisco\n"
920 "zebra\n")
921 {
922 int idx = 0;
923 if (argv_find(argv, argc, "cisco", &idx)) {
924 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
925 vty_out(vty, "if you are using this please let the developers know!\n");
926 zlog_info("Deprecated option: `bgp config-type cisco` being used");
927 bgp_option_set(BGP_OPT_CONFIG_CISCO);
928 } else
929 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
930
931 return CMD_SUCCESS;
932 }
933
934 DEFUN_HIDDEN (no_bgp_config_type,
935 no_bgp_config_type_cmd,
936 "no bgp config-type [<cisco|zebra>]",
937 NO_STR
938 BGP_STR
939 "Display configuration type\n"
940 "cisco\n"
941 "zebra\n")
942 {
943 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
944 return CMD_SUCCESS;
945 }
946
947
948 DEFUN (no_synchronization,
949 no_synchronization_cmd,
950 "no synchronization",
951 NO_STR
952 "Perform IGP synchronization\n")
953 {
954 return CMD_SUCCESS;
955 }
956
957 DEFUN (no_auto_summary,
958 no_auto_summary_cmd,
959 "no auto-summary",
960 NO_STR
961 "Enable automatic network number summarization\n")
962 {
963 return CMD_SUCCESS;
964 }
965
966 /* "router bgp" commands. */
967 DEFUN_NOSH (router_bgp,
968 router_bgp_cmd,
969 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
970 ROUTER_STR
971 BGP_STR
972 AS_STR
973 BGP_INSTANCE_HELP_STR)
974 {
975 int idx_asn = 2;
976 int idx_view_vrf = 3;
977 int idx_vrf = 4;
978 int is_new_bgp = 0;
979 int ret;
980 as_t as;
981 struct bgp *bgp;
982 const char *name = NULL;
983 enum bgp_instance_type inst_type;
984
985 // "router bgp" without an ASN
986 if (argc == 2) {
987 // Pending: Make VRF option available for ASN less config
988 bgp = bgp_get_default();
989
990 if (bgp == NULL) {
991 vty_out(vty, "%% No BGP process is configured\n");
992 return CMD_WARNING_CONFIG_FAILED;
993 }
994
995 if (listcount(bm->bgp) > 1) {
996 vty_out(vty, "%% Please specify ASN and VRF\n");
997 return CMD_WARNING_CONFIG_FAILED;
998 }
999 }
1000
1001 // "router bgp X"
1002 else {
1003 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1004
1005 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1006 if (argc > 3) {
1007 name = argv[idx_vrf]->arg;
1008
1009 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1010 if (strmatch(name, VRF_DEFAULT_NAME))
1011 name = NULL;
1012 else
1013 inst_type = BGP_INSTANCE_TYPE_VRF;
1014 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1015 inst_type = BGP_INSTANCE_TYPE_VIEW;
1016 }
1017
1018 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1019 is_new_bgp = (bgp_lookup(as, name) == NULL);
1020
1021 ret = bgp_get(&bgp, &as, name, inst_type);
1022 switch (ret) {
1023 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1024 vty_out(vty,
1025 "Please specify 'bgp multiple-instance' first\n");
1026 return CMD_WARNING_CONFIG_FAILED;
1027 case BGP_ERR_AS_MISMATCH:
1028 vty_out(vty, "BGP is already running; AS is %u\n", as);
1029 return CMD_WARNING_CONFIG_FAILED;
1030 case BGP_ERR_INSTANCE_MISMATCH:
1031 vty_out(vty,
1032 "BGP instance name and AS number mismatch\n");
1033 vty_out(vty,
1034 "BGP instance is already running; AS is %u\n",
1035 as);
1036 return CMD_WARNING_CONFIG_FAILED;
1037 }
1038
1039 /*
1040 * If we just instantiated the default instance, complete
1041 * any pending VRF-VPN leaking that was configured via
1042 * earlier "router bgp X vrf FOO" blocks.
1043 */
1044 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1045 vpn_leak_postchange_all();
1046
1047 /* Pending: handle when user tries to change a view to vrf n vv.
1048 */
1049 }
1050
1051 /* unset the auto created flag as the user config is now present */
1052 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1053 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1054
1055 return CMD_SUCCESS;
1056 }
1057
1058 /* "no router bgp" commands. */
1059 DEFUN (no_router_bgp,
1060 no_router_bgp_cmd,
1061 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1062 NO_STR
1063 ROUTER_STR
1064 BGP_STR
1065 AS_STR
1066 BGP_INSTANCE_HELP_STR)
1067 {
1068 int idx_asn = 3;
1069 int idx_vrf = 5;
1070 as_t as;
1071 struct bgp *bgp;
1072 const char *name = NULL;
1073
1074 // "no router bgp" without an ASN
1075 if (argc == 3) {
1076 // Pending: Make VRF option available for ASN less config
1077 bgp = bgp_get_default();
1078
1079 if (bgp == NULL) {
1080 vty_out(vty, "%% No BGP process is configured\n");
1081 return CMD_WARNING_CONFIG_FAILED;
1082 }
1083
1084 if (listcount(bm->bgp) > 1) {
1085 vty_out(vty, "%% Please specify ASN and VRF\n");
1086 return CMD_WARNING_CONFIG_FAILED;
1087 }
1088
1089 if (bgp->l3vni) {
1090 vty_out(vty, "%% Please unconfigure l3vni %u",
1091 bgp->l3vni);
1092 return CMD_WARNING_CONFIG_FAILED;
1093 }
1094 } else {
1095 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1096
1097 if (argc > 4)
1098 name = argv[idx_vrf]->arg;
1099
1100 /* Lookup bgp structure. */
1101 bgp = bgp_lookup(as, name);
1102 if (!bgp) {
1103 vty_out(vty, "%% Can't find BGP instance\n");
1104 return CMD_WARNING_CONFIG_FAILED;
1105 }
1106
1107 if (bgp->l3vni) {
1108 vty_out(vty, "%% Please unconfigure l3vni %u",
1109 bgp->l3vni);
1110 return CMD_WARNING_CONFIG_FAILED;
1111 }
1112 }
1113
1114 bgp_delete(bgp);
1115
1116 return CMD_SUCCESS;
1117 }
1118
1119
1120 /* BGP router-id. */
1121
1122 DEFPY (bgp_router_id,
1123 bgp_router_id_cmd,
1124 "bgp router-id A.B.C.D",
1125 BGP_STR
1126 "Override configured router identifier\n"
1127 "Manually configured router identifier\n")
1128 {
1129 VTY_DECLVAR_CONTEXT(bgp, bgp);
1130 bgp_router_id_static_set(bgp, router_id);
1131 return CMD_SUCCESS;
1132 }
1133
1134 DEFPY (no_bgp_router_id,
1135 no_bgp_router_id_cmd,
1136 "no bgp router-id [A.B.C.D]",
1137 NO_STR
1138 BGP_STR
1139 "Override configured router identifier\n"
1140 "Manually configured router identifier\n")
1141 {
1142 VTY_DECLVAR_CONTEXT(bgp, bgp);
1143
1144 if (router_id_str) {
1145 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1146 vty_out(vty, "%% BGP router-id doesn't match\n");
1147 return CMD_WARNING_CONFIG_FAILED;
1148 }
1149 }
1150
1151 router_id.s_addr = 0;
1152 bgp_router_id_static_set(bgp, router_id);
1153
1154 return CMD_SUCCESS;
1155 }
1156
1157
1158 /* BGP Cluster ID. */
1159 DEFUN (bgp_cluster_id,
1160 bgp_cluster_id_cmd,
1161 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1162 BGP_STR
1163 "Configure Route-Reflector Cluster-id\n"
1164 "Route-Reflector Cluster-id in IP address format\n"
1165 "Route-Reflector Cluster-id as 32 bit quantity\n")
1166 {
1167 VTY_DECLVAR_CONTEXT(bgp, bgp);
1168 int idx_ipv4 = 2;
1169 int ret;
1170 struct in_addr cluster;
1171
1172 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1173 if (!ret) {
1174 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1175 return CMD_WARNING_CONFIG_FAILED;
1176 }
1177
1178 bgp_cluster_id_set(bgp, &cluster);
1179 bgp_clear_star_soft_out(vty, bgp->name);
1180
1181 return CMD_SUCCESS;
1182 }
1183
1184 DEFUN (no_bgp_cluster_id,
1185 no_bgp_cluster_id_cmd,
1186 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1187 NO_STR
1188 BGP_STR
1189 "Configure Route-Reflector Cluster-id\n"
1190 "Route-Reflector Cluster-id in IP address format\n"
1191 "Route-Reflector Cluster-id as 32 bit quantity\n")
1192 {
1193 VTY_DECLVAR_CONTEXT(bgp, bgp);
1194 bgp_cluster_id_unset(bgp);
1195 bgp_clear_star_soft_out(vty, bgp->name);
1196
1197 return CMD_SUCCESS;
1198 }
1199
1200 DEFUN (bgp_confederation_identifier,
1201 bgp_confederation_identifier_cmd,
1202 "bgp confederation identifier (1-4294967295)",
1203 "BGP specific commands\n"
1204 "AS confederation parameters\n"
1205 "AS number\n"
1206 "Set routing domain confederation AS\n")
1207 {
1208 VTY_DECLVAR_CONTEXT(bgp, bgp);
1209 int idx_number = 3;
1210 as_t as;
1211
1212 as = strtoul(argv[idx_number]->arg, NULL, 10);
1213
1214 bgp_confederation_id_set(bgp, as);
1215
1216 return CMD_SUCCESS;
1217 }
1218
1219 DEFUN (no_bgp_confederation_identifier,
1220 no_bgp_confederation_identifier_cmd,
1221 "no bgp confederation identifier [(1-4294967295)]",
1222 NO_STR
1223 "BGP specific commands\n"
1224 "AS confederation parameters\n"
1225 "AS number\n"
1226 "Set routing domain confederation AS\n")
1227 {
1228 VTY_DECLVAR_CONTEXT(bgp, bgp);
1229 bgp_confederation_id_unset(bgp);
1230
1231 return CMD_SUCCESS;
1232 }
1233
1234 DEFUN (bgp_confederation_peers,
1235 bgp_confederation_peers_cmd,
1236 "bgp confederation peers (1-4294967295)...",
1237 "BGP specific commands\n"
1238 "AS confederation parameters\n"
1239 "Peer ASs in BGP confederation\n"
1240 AS_STR)
1241 {
1242 VTY_DECLVAR_CONTEXT(bgp, bgp);
1243 int idx_asn = 3;
1244 as_t as;
1245 int i;
1246
1247 for (i = idx_asn; i < argc; i++) {
1248 as = strtoul(argv[i]->arg, NULL, 10);
1249
1250 if (bgp->as == as) {
1251 vty_out(vty,
1252 "%% Local member-AS not allowed in confed peer list\n");
1253 continue;
1254 }
1255
1256 bgp_confederation_peers_add(bgp, as);
1257 }
1258 return CMD_SUCCESS;
1259 }
1260
1261 DEFUN (no_bgp_confederation_peers,
1262 no_bgp_confederation_peers_cmd,
1263 "no bgp confederation peers (1-4294967295)...",
1264 NO_STR
1265 "BGP specific commands\n"
1266 "AS confederation parameters\n"
1267 "Peer ASs in BGP confederation\n"
1268 AS_STR)
1269 {
1270 VTY_DECLVAR_CONTEXT(bgp, bgp);
1271 int idx_asn = 4;
1272 as_t as;
1273 int i;
1274
1275 for (i = idx_asn; i < argc; i++) {
1276 as = strtoul(argv[i]->arg, NULL, 10);
1277
1278 bgp_confederation_peers_remove(bgp, as);
1279 }
1280 return CMD_SUCCESS;
1281 }
1282
1283 /**
1284 * Central routine for maximum-paths configuration.
1285 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1286 * @set: 1 for setting values, 0 for removing the max-paths config.
1287 */
1288 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1289 const char *mpaths, uint16_t options,
1290 int set)
1291 {
1292 VTY_DECLVAR_CONTEXT(bgp, bgp);
1293 uint16_t maxpaths = 0;
1294 int ret;
1295 afi_t afi;
1296 safi_t safi;
1297
1298 afi = bgp_node_afi(vty);
1299 safi = bgp_node_safi(vty);
1300
1301 if (set) {
1302 maxpaths = strtol(mpaths, NULL, 10);
1303 if (maxpaths > multipath_num) {
1304 vty_out(vty,
1305 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1306 maxpaths, multipath_num);
1307 return CMD_WARNING_CONFIG_FAILED;
1308 }
1309 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1310 options);
1311 } else
1312 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1313
1314 if (ret < 0) {
1315 vty_out(vty,
1316 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1317 (set == 1) ? "" : "un",
1318 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1319 maxpaths, afi, safi);
1320 return CMD_WARNING_CONFIG_FAILED;
1321 }
1322
1323 bgp_recalculate_all_bestpaths(bgp);
1324
1325 return CMD_SUCCESS;
1326 }
1327
1328 DEFUN (bgp_maxmed_admin,
1329 bgp_maxmed_admin_cmd,
1330 "bgp max-med administrative ",
1331 BGP_STR
1332 "Advertise routes with max-med\n"
1333 "Administratively applied, for an indefinite period\n")
1334 {
1335 VTY_DECLVAR_CONTEXT(bgp, bgp);
1336
1337 bgp->v_maxmed_admin = 1;
1338 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1339
1340 bgp_maxmed_update(bgp);
1341
1342 return CMD_SUCCESS;
1343 }
1344
1345 DEFUN (bgp_maxmed_admin_medv,
1346 bgp_maxmed_admin_medv_cmd,
1347 "bgp max-med administrative (0-4294967295)",
1348 BGP_STR
1349 "Advertise routes with max-med\n"
1350 "Administratively applied, for an indefinite period\n"
1351 "Max MED value to be used\n")
1352 {
1353 VTY_DECLVAR_CONTEXT(bgp, bgp);
1354 int idx_number = 3;
1355
1356 bgp->v_maxmed_admin = 1;
1357 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1358
1359 bgp_maxmed_update(bgp);
1360
1361 return CMD_SUCCESS;
1362 }
1363
1364 DEFUN (no_bgp_maxmed_admin,
1365 no_bgp_maxmed_admin_cmd,
1366 "no bgp max-med administrative [(0-4294967295)]",
1367 NO_STR
1368 BGP_STR
1369 "Advertise routes with max-med\n"
1370 "Administratively applied, for an indefinite period\n"
1371 "Max MED value to be used\n")
1372 {
1373 VTY_DECLVAR_CONTEXT(bgp, bgp);
1374 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1375 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1376 bgp_maxmed_update(bgp);
1377
1378 return CMD_SUCCESS;
1379 }
1380
1381 DEFUN (bgp_maxmed_onstartup,
1382 bgp_maxmed_onstartup_cmd,
1383 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1384 BGP_STR
1385 "Advertise routes with max-med\n"
1386 "Effective on a startup\n"
1387 "Time (seconds) period for max-med\n"
1388 "Max MED value to be used\n")
1389 {
1390 VTY_DECLVAR_CONTEXT(bgp, bgp);
1391 int idx = 0;
1392
1393 argv_find(argv, argc, "(5-86400)", &idx);
1394 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1395 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1396 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1397 else
1398 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1399
1400 bgp_maxmed_update(bgp);
1401
1402 return CMD_SUCCESS;
1403 }
1404
1405 DEFUN (no_bgp_maxmed_onstartup,
1406 no_bgp_maxmed_onstartup_cmd,
1407 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1408 NO_STR
1409 BGP_STR
1410 "Advertise routes with max-med\n"
1411 "Effective on a startup\n"
1412 "Time (seconds) period for max-med\n"
1413 "Max MED value to be used\n")
1414 {
1415 VTY_DECLVAR_CONTEXT(bgp, bgp);
1416
1417 /* Cancel max-med onstartup if its on */
1418 if (bgp->t_maxmed_onstartup) {
1419 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1420 bgp->maxmed_onstartup_over = 1;
1421 }
1422
1423 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1424 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1425
1426 bgp_maxmed_update(bgp);
1427
1428 return CMD_SUCCESS;
1429 }
1430
1431 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1432 const char *wait)
1433 {
1434 VTY_DECLVAR_CONTEXT(bgp, bgp);
1435 uint16_t update_delay;
1436 uint16_t establish_wait;
1437
1438 update_delay = strtoul(delay, NULL, 10);
1439
1440 if (!wait) /* update-delay <delay> */
1441 {
1442 bgp->v_update_delay = update_delay;
1443 bgp->v_establish_wait = bgp->v_update_delay;
1444 return CMD_SUCCESS;
1445 }
1446
1447 /* update-delay <delay> <establish-wait> */
1448 establish_wait = atoi(wait);
1449 if (update_delay < establish_wait) {
1450 vty_out(vty,
1451 "%%Failed: update-delay less than the establish-wait!\n");
1452 return CMD_WARNING_CONFIG_FAILED;
1453 }
1454
1455 bgp->v_update_delay = update_delay;
1456 bgp->v_establish_wait = establish_wait;
1457
1458 return CMD_SUCCESS;
1459 }
1460
1461 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1462 {
1463 VTY_DECLVAR_CONTEXT(bgp, bgp);
1464
1465 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1466 bgp->v_establish_wait = bgp->v_update_delay;
1467
1468 return CMD_SUCCESS;
1469 }
1470
1471 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1472 {
1473 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1474 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1475 if (bgp->v_update_delay != bgp->v_establish_wait)
1476 vty_out(vty, " %d", bgp->v_establish_wait);
1477 vty_out(vty, "\n");
1478 }
1479 }
1480
1481
1482 /* Update-delay configuration */
1483 DEFUN (bgp_update_delay,
1484 bgp_update_delay_cmd,
1485 "update-delay (0-3600)",
1486 "Force initial delay for best-path and updates\n"
1487 "Seconds\n")
1488 {
1489 int idx_number = 1;
1490 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1491 }
1492
1493 DEFUN (bgp_update_delay_establish_wait,
1494 bgp_update_delay_establish_wait_cmd,
1495 "update-delay (0-3600) (1-3600)",
1496 "Force initial delay for best-path and updates\n"
1497 "Seconds\n"
1498 "Seconds\n")
1499 {
1500 int idx_number = 1;
1501 int idx_number_2 = 2;
1502 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1503 argv[idx_number_2]->arg);
1504 }
1505
1506 /* Update-delay deconfiguration */
1507 DEFUN (no_bgp_update_delay,
1508 no_bgp_update_delay_cmd,
1509 "no update-delay [(0-3600) [(1-3600)]]",
1510 NO_STR
1511 "Force initial delay for best-path and updates\n"
1512 "Seconds\n"
1513 "Seconds\n")
1514 {
1515 return bgp_update_delay_deconfig_vty(vty);
1516 }
1517
1518
1519 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1520 char set)
1521 {
1522 VTY_DECLVAR_CONTEXT(bgp, bgp);
1523
1524 if (set) {
1525 uint32_t quanta = strtoul(num, NULL, 10);
1526 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1527 memory_order_relaxed);
1528 } else {
1529 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1530 memory_order_relaxed);
1531 }
1532
1533 return CMD_SUCCESS;
1534 }
1535
1536 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1537 char set)
1538 {
1539 VTY_DECLVAR_CONTEXT(bgp, bgp);
1540
1541 if (set) {
1542 uint32_t quanta = strtoul(num, NULL, 10);
1543 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1544 memory_order_relaxed);
1545 } else {
1546 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1547 memory_order_relaxed);
1548 }
1549
1550 return CMD_SUCCESS;
1551 }
1552
1553 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1554 {
1555 uint32_t quanta =
1556 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1557 if (quanta != BGP_WRITE_PACKET_MAX)
1558 vty_out(vty, " write-quanta %d\n", quanta);
1559 }
1560
1561 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1562 {
1563 uint32_t quanta =
1564 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1565 if (quanta != BGP_READ_PACKET_MAX)
1566 vty_out(vty, " read-quanta %d\n", quanta);
1567 }
1568
1569 /* Packet quanta configuration */
1570 DEFUN (bgp_wpkt_quanta,
1571 bgp_wpkt_quanta_cmd,
1572 "write-quanta (1-10)",
1573 "How many packets to write to peer socket per run\n"
1574 "Number of packets\n")
1575 {
1576 int idx_number = 1;
1577 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1578 }
1579
1580 DEFUN (no_bgp_wpkt_quanta,
1581 no_bgp_wpkt_quanta_cmd,
1582 "no write-quanta (1-10)",
1583 NO_STR
1584 "How many packets to write to peer socket per I/O cycle\n"
1585 "Number of packets\n")
1586 {
1587 int idx_number = 2;
1588 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1589 }
1590
1591 DEFUN (bgp_rpkt_quanta,
1592 bgp_rpkt_quanta_cmd,
1593 "read-quanta (1-10)",
1594 "How many packets to read from peer socket per I/O cycle\n"
1595 "Number of packets\n")
1596 {
1597 int idx_number = 1;
1598 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1599 }
1600
1601 DEFUN (no_bgp_rpkt_quanta,
1602 no_bgp_rpkt_quanta_cmd,
1603 "no read-quanta (1-10)",
1604 NO_STR
1605 "How many packets to read from peer socket per I/O cycle\n"
1606 "Number of packets\n")
1607 {
1608 int idx_number = 2;
1609 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1610 }
1611
1612 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1613 {
1614 if (!bgp->heuristic_coalesce)
1615 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1616 }
1617
1618
1619 DEFUN (bgp_coalesce_time,
1620 bgp_coalesce_time_cmd,
1621 "coalesce-time (0-4294967295)",
1622 "Subgroup coalesce timer\n"
1623 "Subgroup coalesce timer value (in ms)\n")
1624 {
1625 VTY_DECLVAR_CONTEXT(bgp, bgp);
1626
1627 int idx = 0;
1628 argv_find(argv, argc, "(0-4294967295)", &idx);
1629 bgp->heuristic_coalesce = false;
1630 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1631 return CMD_SUCCESS;
1632 }
1633
1634 DEFUN (no_bgp_coalesce_time,
1635 no_bgp_coalesce_time_cmd,
1636 "no coalesce-time (0-4294967295)",
1637 NO_STR
1638 "Subgroup coalesce timer\n"
1639 "Subgroup coalesce timer value (in ms)\n")
1640 {
1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642
1643 bgp->heuristic_coalesce = true;
1644 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1645 return CMD_SUCCESS;
1646 }
1647
1648 /* Maximum-paths configuration */
1649 DEFUN (bgp_maxpaths,
1650 bgp_maxpaths_cmd,
1651 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1652 "Forward packets over multiple paths\n"
1653 "Number of paths\n")
1654 {
1655 int idx_number = 1;
1656 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1657 argv[idx_number]->arg, 0, 1);
1658 }
1659
1660 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1661 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1662 "Forward packets over multiple paths\n"
1663 "Number of paths\n")
1664
1665 DEFUN (bgp_maxpaths_ibgp,
1666 bgp_maxpaths_ibgp_cmd,
1667 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1668 "Forward packets over multiple paths\n"
1669 "iBGP-multipath\n"
1670 "Number of paths\n")
1671 {
1672 int idx_number = 2;
1673 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1674 argv[idx_number]->arg, 0, 1);
1675 }
1676
1677 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1678 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1679 "Forward packets over multiple paths\n"
1680 "iBGP-multipath\n"
1681 "Number of paths\n")
1682
1683 DEFUN (bgp_maxpaths_ibgp_cluster,
1684 bgp_maxpaths_ibgp_cluster_cmd,
1685 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1686 "Forward packets over multiple paths\n"
1687 "iBGP-multipath\n"
1688 "Number of paths\n"
1689 "Match the cluster length\n")
1690 {
1691 int idx_number = 2;
1692 return bgp_maxpaths_config_vty(
1693 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1694 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1695 }
1696
1697 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1698 "maximum-paths ibgp " CMD_RANGE_STR(
1699 1, MULTIPATH_NUM) " equal-cluster-length",
1700 "Forward packets over multiple paths\n"
1701 "iBGP-multipath\n"
1702 "Number of paths\n"
1703 "Match the cluster length\n")
1704
1705 DEFUN (no_bgp_maxpaths,
1706 no_bgp_maxpaths_cmd,
1707 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1708 NO_STR
1709 "Forward packets over multiple paths\n"
1710 "Number of paths\n")
1711 {
1712 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1713 }
1714
1715 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1716 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1717 "Forward packets over multiple paths\n"
1718 "Number of paths\n")
1719
1720 DEFUN (no_bgp_maxpaths_ibgp,
1721 no_bgp_maxpaths_ibgp_cmd,
1722 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1723 NO_STR
1724 "Forward packets over multiple paths\n"
1725 "iBGP-multipath\n"
1726 "Number of paths\n"
1727 "Match the cluster length\n")
1728 {
1729 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1730 }
1731
1732 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1733 "no maximum-paths ibgp [" CMD_RANGE_STR(
1734 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1735 NO_STR
1736 "Forward packets over multiple paths\n"
1737 "iBGP-multipath\n"
1738 "Number of paths\n"
1739 "Match the cluster length\n")
1740
1741 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1742 safi_t safi)
1743 {
1744 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1745 vty_out(vty, " maximum-paths %d\n",
1746 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1747 }
1748
1749 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1750 vty_out(vty, " maximum-paths ibgp %d",
1751 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1752 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1753 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1754 vty_out(vty, " equal-cluster-length");
1755 vty_out(vty, "\n");
1756 }
1757 }
1758
1759 /* BGP timers. */
1760
1761 DEFUN (bgp_timers,
1762 bgp_timers_cmd,
1763 "timers bgp (0-65535) (0-65535)",
1764 "Adjust routing timers\n"
1765 "BGP timers\n"
1766 "Keepalive interval\n"
1767 "Holdtime\n")
1768 {
1769 VTY_DECLVAR_CONTEXT(bgp, bgp);
1770 int idx_number = 2;
1771 int idx_number_2 = 3;
1772 unsigned long keepalive = 0;
1773 unsigned long holdtime = 0;
1774
1775 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1776 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1777
1778 /* Holdtime value check. */
1779 if (holdtime < 3 && holdtime != 0) {
1780 vty_out(vty,
1781 "%% hold time value must be either 0 or greater than 3\n");
1782 return CMD_WARNING_CONFIG_FAILED;
1783 }
1784
1785 bgp_timers_set(bgp, keepalive, holdtime);
1786
1787 return CMD_SUCCESS;
1788 }
1789
1790 DEFUN (no_bgp_timers,
1791 no_bgp_timers_cmd,
1792 "no timers bgp [(0-65535) (0-65535)]",
1793 NO_STR
1794 "Adjust routing timers\n"
1795 "BGP timers\n"
1796 "Keepalive interval\n"
1797 "Holdtime\n")
1798 {
1799 VTY_DECLVAR_CONTEXT(bgp, bgp);
1800 bgp_timers_unset(bgp);
1801
1802 return CMD_SUCCESS;
1803 }
1804
1805
1806 DEFUN (bgp_client_to_client_reflection,
1807 bgp_client_to_client_reflection_cmd,
1808 "bgp client-to-client reflection",
1809 "BGP specific commands\n"
1810 "Configure client to client route reflection\n"
1811 "reflection of routes allowed\n")
1812 {
1813 VTY_DECLVAR_CONTEXT(bgp, bgp);
1814 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1815 bgp_clear_star_soft_out(vty, bgp->name);
1816
1817 return CMD_SUCCESS;
1818 }
1819
1820 DEFUN (no_bgp_client_to_client_reflection,
1821 no_bgp_client_to_client_reflection_cmd,
1822 "no bgp client-to-client reflection",
1823 NO_STR
1824 "BGP specific commands\n"
1825 "Configure client to client route reflection\n"
1826 "reflection of routes allowed\n")
1827 {
1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1830 bgp_clear_star_soft_out(vty, bgp->name);
1831
1832 return CMD_SUCCESS;
1833 }
1834
1835 /* "bgp always-compare-med" configuration. */
1836 DEFUN (bgp_always_compare_med,
1837 bgp_always_compare_med_cmd,
1838 "bgp always-compare-med",
1839 "BGP specific commands\n"
1840 "Allow comparing MED from different neighbors\n")
1841 {
1842 VTY_DECLVAR_CONTEXT(bgp, bgp);
1843 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1844 bgp_recalculate_all_bestpaths(bgp);
1845
1846 return CMD_SUCCESS;
1847 }
1848
1849 DEFUN (no_bgp_always_compare_med,
1850 no_bgp_always_compare_med_cmd,
1851 "no bgp always-compare-med",
1852 NO_STR
1853 "BGP specific commands\n"
1854 "Allow comparing MED from different neighbors\n")
1855 {
1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1858 bgp_recalculate_all_bestpaths(bgp);
1859
1860 return CMD_SUCCESS;
1861 }
1862
1863
1864 DEFUN(bgp_ebgp_requires_policy, bgp_ebgp_requires_policy_cmd,
1865 "bgp ebgp-requires-policy",
1866 "BGP specific commands\n"
1867 "Require in and out policy for eBGP peers (RFC8212)\n")
1868 {
1869 VTY_DECLVAR_CONTEXT(bgp, bgp);
1870 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_ENABLED;
1871 return CMD_SUCCESS;
1872 }
1873
1874 DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
1875 "no bgp ebgp-requires-policy",
1876 NO_STR
1877 "BGP specific commands\n"
1878 "Require in and out policy for eBGP peers (RFC8212)\n")
1879 {
1880 VTY_DECLVAR_CONTEXT(bgp, bgp);
1881 bgp->ebgp_requires_policy = DEFAULT_EBGP_POLICY_DISABLED;
1882 return CMD_SUCCESS;
1883 }
1884
1885
1886 /* "bgp deterministic-med" configuration. */
1887 DEFUN (bgp_deterministic_med,
1888 bgp_deterministic_med_cmd,
1889 "bgp deterministic-med",
1890 "BGP specific commands\n"
1891 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1892 {
1893 VTY_DECLVAR_CONTEXT(bgp, bgp);
1894
1895 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1896 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1897 bgp_recalculate_all_bestpaths(bgp);
1898 }
1899
1900 return CMD_SUCCESS;
1901 }
1902
1903 DEFUN (no_bgp_deterministic_med,
1904 no_bgp_deterministic_med_cmd,
1905 "no bgp deterministic-med",
1906 NO_STR
1907 "BGP specific commands\n"
1908 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1909 {
1910 VTY_DECLVAR_CONTEXT(bgp, bgp);
1911 int bestpath_per_as_used;
1912 afi_t afi;
1913 safi_t safi;
1914 struct peer *peer;
1915 struct listnode *node, *nnode;
1916
1917 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1918 bestpath_per_as_used = 0;
1919
1920 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1921 FOREACH_AFI_SAFI (afi, safi)
1922 if (bgp_addpath_dmed_required(
1923 peer->addpath_type[afi][safi])) {
1924 bestpath_per_as_used = 1;
1925 break;
1926 }
1927
1928 if (bestpath_per_as_used)
1929 break;
1930 }
1931
1932 if (bestpath_per_as_used) {
1933 vty_out(vty,
1934 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1935 return CMD_WARNING_CONFIG_FAILED;
1936 } else {
1937 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1938 bgp_recalculate_all_bestpaths(bgp);
1939 }
1940 }
1941
1942 return CMD_SUCCESS;
1943 }
1944
1945 /* "bgp graceful-restart" configuration. */
1946 DEFUN (bgp_graceful_restart,
1947 bgp_graceful_restart_cmd,
1948 "bgp graceful-restart",
1949 "BGP specific commands\n"
1950 "Graceful restart capability parameters\n")
1951 {
1952 VTY_DECLVAR_CONTEXT(bgp, bgp);
1953 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1954 return CMD_SUCCESS;
1955 }
1956
1957 DEFUN (no_bgp_graceful_restart,
1958 no_bgp_graceful_restart_cmd,
1959 "no bgp graceful-restart",
1960 NO_STR
1961 "BGP specific commands\n"
1962 "Graceful restart capability parameters\n")
1963 {
1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1966 return CMD_SUCCESS;
1967 }
1968
1969 DEFUN (bgp_graceful_restart_stalepath_time,
1970 bgp_graceful_restart_stalepath_time_cmd,
1971 "bgp graceful-restart stalepath-time (1-4095)",
1972 "BGP specific commands\n"
1973 "Graceful restart capability parameters\n"
1974 "Set the max time to hold onto restarting peer's stale paths\n"
1975 "Delay value (seconds)\n")
1976 {
1977 VTY_DECLVAR_CONTEXT(bgp, bgp);
1978 int idx_number = 3;
1979 uint32_t stalepath;
1980
1981 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1982 bgp->stalepath_time = stalepath;
1983 return CMD_SUCCESS;
1984 }
1985
1986 DEFUN (bgp_graceful_restart_restart_time,
1987 bgp_graceful_restart_restart_time_cmd,
1988 "bgp graceful-restart restart-time (1-4095)",
1989 "BGP specific commands\n"
1990 "Graceful restart capability parameters\n"
1991 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1992 "Delay value (seconds)\n")
1993 {
1994 VTY_DECLVAR_CONTEXT(bgp, bgp);
1995 int idx_number = 3;
1996 uint32_t restart;
1997
1998 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1999 bgp->restart_time = restart;
2000 return CMD_SUCCESS;
2001 }
2002
2003 DEFUN (no_bgp_graceful_restart_stalepath_time,
2004 no_bgp_graceful_restart_stalepath_time_cmd,
2005 "no bgp graceful-restart stalepath-time [(1-4095)]",
2006 NO_STR
2007 "BGP specific commands\n"
2008 "Graceful restart capability parameters\n"
2009 "Set the max time to hold onto restarting peer's stale paths\n"
2010 "Delay value (seconds)\n")
2011 {
2012 VTY_DECLVAR_CONTEXT(bgp, bgp);
2013
2014 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
2015 return CMD_SUCCESS;
2016 }
2017
2018 DEFUN (no_bgp_graceful_restart_restart_time,
2019 no_bgp_graceful_restart_restart_time_cmd,
2020 "no bgp graceful-restart restart-time [(1-4095)]",
2021 NO_STR
2022 "BGP specific commands\n"
2023 "Graceful restart capability parameters\n"
2024 "Set the time to wait to delete stale routes before a BGP open message is received\n"
2025 "Delay value (seconds)\n")
2026 {
2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
2028
2029 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2030 return CMD_SUCCESS;
2031 }
2032
2033 DEFUN (bgp_graceful_restart_preserve_fw,
2034 bgp_graceful_restart_preserve_fw_cmd,
2035 "bgp graceful-restart preserve-fw-state",
2036 "BGP specific commands\n"
2037 "Graceful restart capability parameters\n"
2038 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2039 {
2040 VTY_DECLVAR_CONTEXT(bgp, bgp);
2041 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2042 return CMD_SUCCESS;
2043 }
2044
2045 DEFUN (no_bgp_graceful_restart_preserve_fw,
2046 no_bgp_graceful_restart_preserve_fw_cmd,
2047 "no bgp graceful-restart preserve-fw-state",
2048 NO_STR
2049 "BGP specific commands\n"
2050 "Graceful restart capability parameters\n"
2051 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2052 {
2053 VTY_DECLVAR_CONTEXT(bgp, bgp);
2054 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2055 return CMD_SUCCESS;
2056 }
2057
2058 static void bgp_redistribute_redo(struct bgp *bgp)
2059 {
2060 afi_t afi;
2061 int i;
2062 struct list *red_list;
2063 struct listnode *node;
2064 struct bgp_redist *red;
2065
2066 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2067 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
2068
2069 red_list = bgp->redist[afi][i];
2070 if (!red_list)
2071 continue;
2072
2073 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
2074 bgp_redistribute_resend(bgp, afi, i,
2075 red->instance);
2076 }
2077 }
2078 }
2079 }
2080
2081 /* "bgp graceful-shutdown" configuration */
2082 DEFUN (bgp_graceful_shutdown,
2083 bgp_graceful_shutdown_cmd,
2084 "bgp graceful-shutdown",
2085 BGP_STR
2086 "Graceful shutdown parameters\n")
2087 {
2088 VTY_DECLVAR_CONTEXT(bgp, bgp);
2089
2090 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2091 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2092 bgp_static_redo_import_check(bgp);
2093 bgp_redistribute_redo(bgp);
2094 bgp_clear_star_soft_out(vty, bgp->name);
2095 bgp_clear_star_soft_in(vty, bgp->name);
2096 }
2097
2098 return CMD_SUCCESS;
2099 }
2100
2101 DEFUN (no_bgp_graceful_shutdown,
2102 no_bgp_graceful_shutdown_cmd,
2103 "no bgp graceful-shutdown",
2104 NO_STR
2105 BGP_STR
2106 "Graceful shutdown parameters\n")
2107 {
2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109
2110 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2111 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2112 bgp_static_redo_import_check(bgp);
2113 bgp_redistribute_redo(bgp);
2114 bgp_clear_star_soft_out(vty, bgp->name);
2115 bgp_clear_star_soft_in(vty, bgp->name);
2116 }
2117
2118 return CMD_SUCCESS;
2119 }
2120
2121 /* "bgp fast-external-failover" configuration. */
2122 DEFUN (bgp_fast_external_failover,
2123 bgp_fast_external_failover_cmd,
2124 "bgp fast-external-failover",
2125 BGP_STR
2126 "Immediately reset session if a link to a directly connected external peer goes down\n")
2127 {
2128 VTY_DECLVAR_CONTEXT(bgp, bgp);
2129 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2130 return CMD_SUCCESS;
2131 }
2132
2133 DEFUN (no_bgp_fast_external_failover,
2134 no_bgp_fast_external_failover_cmd,
2135 "no bgp fast-external-failover",
2136 NO_STR
2137 BGP_STR
2138 "Immediately reset session if a link to a directly connected external peer goes down\n")
2139 {
2140 VTY_DECLVAR_CONTEXT(bgp, bgp);
2141 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2142 return CMD_SUCCESS;
2143 }
2144
2145 /* "bgp enforce-first-as" configuration. */
2146 #if CONFDATE > 20190517
2147 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2148 #endif
2149
2150 DEFUN_HIDDEN (bgp_enforce_first_as,
2151 bgp_enforce_first_as_cmd,
2152 "[no] bgp enforce-first-as",
2153 NO_STR
2154 BGP_STR
2155 "Enforce the first AS for EBGP routes\n")
2156 {
2157 VTY_DECLVAR_CONTEXT(bgp, bgp);
2158
2159 if (strmatch(argv[0]->text, "no"))
2160 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2161 else
2162 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2163
2164 return CMD_SUCCESS;
2165 }
2166
2167 /* "bgp bestpath compare-routerid" configuration. */
2168 DEFUN (bgp_bestpath_compare_router_id,
2169 bgp_bestpath_compare_router_id_cmd,
2170 "bgp bestpath compare-routerid",
2171 "BGP specific commands\n"
2172 "Change the default bestpath selection\n"
2173 "Compare router-id for identical EBGP paths\n")
2174 {
2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2177 bgp_recalculate_all_bestpaths(bgp);
2178
2179 return CMD_SUCCESS;
2180 }
2181
2182 DEFUN (no_bgp_bestpath_compare_router_id,
2183 no_bgp_bestpath_compare_router_id_cmd,
2184 "no bgp bestpath compare-routerid",
2185 NO_STR
2186 "BGP specific commands\n"
2187 "Change the default bestpath selection\n"
2188 "Compare router-id for identical EBGP paths\n")
2189 {
2190 VTY_DECLVAR_CONTEXT(bgp, bgp);
2191 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2192 bgp_recalculate_all_bestpaths(bgp);
2193
2194 return CMD_SUCCESS;
2195 }
2196
2197 /* "bgp bestpath as-path ignore" configuration. */
2198 DEFUN (bgp_bestpath_aspath_ignore,
2199 bgp_bestpath_aspath_ignore_cmd,
2200 "bgp bestpath as-path ignore",
2201 "BGP specific commands\n"
2202 "Change the default bestpath selection\n"
2203 "AS-path attribute\n"
2204 "Ignore as-path length in selecting a route\n")
2205 {
2206 VTY_DECLVAR_CONTEXT(bgp, bgp);
2207 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2208 bgp_recalculate_all_bestpaths(bgp);
2209
2210 return CMD_SUCCESS;
2211 }
2212
2213 DEFUN (no_bgp_bestpath_aspath_ignore,
2214 no_bgp_bestpath_aspath_ignore_cmd,
2215 "no bgp bestpath as-path ignore",
2216 NO_STR
2217 "BGP specific commands\n"
2218 "Change the default bestpath selection\n"
2219 "AS-path attribute\n"
2220 "Ignore as-path length in selecting a route\n")
2221 {
2222 VTY_DECLVAR_CONTEXT(bgp, bgp);
2223 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2224 bgp_recalculate_all_bestpaths(bgp);
2225
2226 return CMD_SUCCESS;
2227 }
2228
2229 /* "bgp bestpath as-path confed" configuration. */
2230 DEFUN (bgp_bestpath_aspath_confed,
2231 bgp_bestpath_aspath_confed_cmd,
2232 "bgp bestpath as-path confed",
2233 "BGP specific commands\n"
2234 "Change the default bestpath selection\n"
2235 "AS-path attribute\n"
2236 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2237 {
2238 VTY_DECLVAR_CONTEXT(bgp, bgp);
2239 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2240 bgp_recalculate_all_bestpaths(bgp);
2241
2242 return CMD_SUCCESS;
2243 }
2244
2245 DEFUN (no_bgp_bestpath_aspath_confed,
2246 no_bgp_bestpath_aspath_confed_cmd,
2247 "no bgp bestpath as-path confed",
2248 NO_STR
2249 "BGP specific commands\n"
2250 "Change the default bestpath selection\n"
2251 "AS-path attribute\n"
2252 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2253 {
2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2256 bgp_recalculate_all_bestpaths(bgp);
2257
2258 return CMD_SUCCESS;
2259 }
2260
2261 /* "bgp bestpath as-path multipath-relax" configuration. */
2262 DEFUN (bgp_bestpath_aspath_multipath_relax,
2263 bgp_bestpath_aspath_multipath_relax_cmd,
2264 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2265 "BGP specific commands\n"
2266 "Change the default bestpath selection\n"
2267 "AS-path attribute\n"
2268 "Allow load sharing across routes that have different AS paths (but same length)\n"
2269 "Generate an AS_SET\n"
2270 "Do not generate an AS_SET\n")
2271 {
2272 VTY_DECLVAR_CONTEXT(bgp, bgp);
2273 int idx = 0;
2274 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2275
2276 /* no-as-set is now the default behavior so we can silently
2277 * ignore it */
2278 if (argv_find(argv, argc, "as-set", &idx))
2279 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2280 else
2281 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2282
2283 bgp_recalculate_all_bestpaths(bgp);
2284
2285 return CMD_SUCCESS;
2286 }
2287
2288 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2289 no_bgp_bestpath_aspath_multipath_relax_cmd,
2290 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2291 NO_STR
2292 "BGP specific commands\n"
2293 "Change the default bestpath selection\n"
2294 "AS-path attribute\n"
2295 "Allow load sharing across routes that have different AS paths (but same length)\n"
2296 "Generate an AS_SET\n"
2297 "Do not generate an AS_SET\n")
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2301 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2302 bgp_recalculate_all_bestpaths(bgp);
2303
2304 return CMD_SUCCESS;
2305 }
2306
2307 /* "bgp log-neighbor-changes" configuration. */
2308 DEFUN (bgp_log_neighbor_changes,
2309 bgp_log_neighbor_changes_cmd,
2310 "bgp log-neighbor-changes",
2311 "BGP specific commands\n"
2312 "Log neighbor up/down and reset reason\n")
2313 {
2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
2315 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2316 return CMD_SUCCESS;
2317 }
2318
2319 DEFUN (no_bgp_log_neighbor_changes,
2320 no_bgp_log_neighbor_changes_cmd,
2321 "no bgp log-neighbor-changes",
2322 NO_STR
2323 "BGP specific commands\n"
2324 "Log neighbor up/down and reset reason\n")
2325 {
2326 VTY_DECLVAR_CONTEXT(bgp, bgp);
2327 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2328 return CMD_SUCCESS;
2329 }
2330
2331 /* "bgp bestpath med" configuration. */
2332 DEFUN (bgp_bestpath_med,
2333 bgp_bestpath_med_cmd,
2334 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2335 "BGP specific commands\n"
2336 "Change the default bestpath selection\n"
2337 "MED attribute\n"
2338 "Compare MED among confederation paths\n"
2339 "Treat missing MED as the least preferred one\n"
2340 "Treat missing MED as the least preferred one\n"
2341 "Compare MED among confederation paths\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344
2345 int idx = 0;
2346 if (argv_find(argv, argc, "confed", &idx))
2347 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2348 idx = 0;
2349 if (argv_find(argv, argc, "missing-as-worst", &idx))
2350 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2351
2352 bgp_recalculate_all_bestpaths(bgp);
2353
2354 return CMD_SUCCESS;
2355 }
2356
2357 DEFUN (no_bgp_bestpath_med,
2358 no_bgp_bestpath_med_cmd,
2359 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2360 NO_STR
2361 "BGP specific commands\n"
2362 "Change the default bestpath selection\n"
2363 "MED attribute\n"
2364 "Compare MED among confederation paths\n"
2365 "Treat missing MED as the least preferred one\n"
2366 "Treat missing MED as the least preferred one\n"
2367 "Compare MED among confederation paths\n")
2368 {
2369 VTY_DECLVAR_CONTEXT(bgp, bgp);
2370
2371 int idx = 0;
2372 if (argv_find(argv, argc, "confed", &idx))
2373 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2374 idx = 0;
2375 if (argv_find(argv, argc, "missing-as-worst", &idx))
2376 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2377
2378 bgp_recalculate_all_bestpaths(bgp);
2379
2380 return CMD_SUCCESS;
2381 }
2382
2383 /* "no bgp default ipv4-unicast". */
2384 DEFUN (no_bgp_default_ipv4_unicast,
2385 no_bgp_default_ipv4_unicast_cmd,
2386 "no bgp default ipv4-unicast",
2387 NO_STR
2388 "BGP specific commands\n"
2389 "Configure BGP defaults\n"
2390 "Activate ipv4-unicast for a peer by default\n")
2391 {
2392 VTY_DECLVAR_CONTEXT(bgp, bgp);
2393 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2394 return CMD_SUCCESS;
2395 }
2396
2397 DEFUN (bgp_default_ipv4_unicast,
2398 bgp_default_ipv4_unicast_cmd,
2399 "bgp default ipv4-unicast",
2400 "BGP specific commands\n"
2401 "Configure BGP defaults\n"
2402 "Activate ipv4-unicast for a peer by default\n")
2403 {
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2406 return CMD_SUCCESS;
2407 }
2408
2409 /* Display hostname in certain command outputs */
2410 DEFUN (bgp_default_show_hostname,
2411 bgp_default_show_hostname_cmd,
2412 "bgp default show-hostname",
2413 "BGP specific commands\n"
2414 "Configure BGP defaults\n"
2415 "Show hostname in certain command outputs\n")
2416 {
2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2419 return CMD_SUCCESS;
2420 }
2421
2422 DEFUN (no_bgp_default_show_hostname,
2423 no_bgp_default_show_hostname_cmd,
2424 "no bgp default show-hostname",
2425 NO_STR
2426 "BGP specific commands\n"
2427 "Configure BGP defaults\n"
2428 "Show hostname in certain command outputs\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2432 return CMD_SUCCESS;
2433 }
2434
2435 /* "bgp network import-check" configuration. */
2436 DEFUN (bgp_network_import_check,
2437 bgp_network_import_check_cmd,
2438 "bgp network import-check",
2439 "BGP specific commands\n"
2440 "BGP network command\n"
2441 "Check BGP network route exists in IGP\n")
2442 {
2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2445 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2446 bgp_static_redo_import_check(bgp);
2447 }
2448
2449 return CMD_SUCCESS;
2450 }
2451
2452 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2453 "bgp network import-check exact",
2454 "BGP specific commands\n"
2455 "BGP network command\n"
2456 "Check BGP network route exists in IGP\n"
2457 "Match route precisely\n")
2458
2459 DEFUN (no_bgp_network_import_check,
2460 no_bgp_network_import_check_cmd,
2461 "no bgp network import-check",
2462 NO_STR
2463 "BGP specific commands\n"
2464 "BGP network command\n"
2465 "Check BGP network route exists in IGP\n")
2466 {
2467 VTY_DECLVAR_CONTEXT(bgp, bgp);
2468 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2469 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2470 bgp_static_redo_import_check(bgp);
2471 }
2472
2473 return CMD_SUCCESS;
2474 }
2475
2476 DEFUN (bgp_default_local_preference,
2477 bgp_default_local_preference_cmd,
2478 "bgp default local-preference (0-4294967295)",
2479 "BGP specific commands\n"
2480 "Configure BGP defaults\n"
2481 "local preference (higher=more preferred)\n"
2482 "Configure default local preference value\n")
2483 {
2484 VTY_DECLVAR_CONTEXT(bgp, bgp);
2485 int idx_number = 3;
2486 uint32_t local_pref;
2487
2488 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2489
2490 bgp_default_local_preference_set(bgp, local_pref);
2491 bgp_clear_star_soft_in(vty, bgp->name);
2492
2493 return CMD_SUCCESS;
2494 }
2495
2496 DEFUN (no_bgp_default_local_preference,
2497 no_bgp_default_local_preference_cmd,
2498 "no bgp default local-preference [(0-4294967295)]",
2499 NO_STR
2500 "BGP specific commands\n"
2501 "Configure BGP defaults\n"
2502 "local preference (higher=more preferred)\n"
2503 "Configure default local preference value\n")
2504 {
2505 VTY_DECLVAR_CONTEXT(bgp, bgp);
2506 bgp_default_local_preference_unset(bgp);
2507 bgp_clear_star_soft_in(vty, bgp->name);
2508
2509 return CMD_SUCCESS;
2510 }
2511
2512
2513 DEFUN (bgp_default_subgroup_pkt_queue_max,
2514 bgp_default_subgroup_pkt_queue_max_cmd,
2515 "bgp default subgroup-pkt-queue-max (20-100)",
2516 "BGP specific commands\n"
2517 "Configure BGP defaults\n"
2518 "subgroup-pkt-queue-max\n"
2519 "Configure subgroup packet queue max\n")
2520 {
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 int idx_number = 3;
2523 uint32_t max_size;
2524
2525 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2526
2527 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2528
2529 return CMD_SUCCESS;
2530 }
2531
2532 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2533 no_bgp_default_subgroup_pkt_queue_max_cmd,
2534 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2535 NO_STR
2536 "BGP specific commands\n"
2537 "Configure BGP defaults\n"
2538 "subgroup-pkt-queue-max\n"
2539 "Configure subgroup packet queue max\n")
2540 {
2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2543 return CMD_SUCCESS;
2544 }
2545
2546
2547 DEFUN (bgp_rr_allow_outbound_policy,
2548 bgp_rr_allow_outbound_policy_cmd,
2549 "bgp route-reflector allow-outbound-policy",
2550 "BGP specific commands\n"
2551 "Allow modifications made by out route-map\n"
2552 "on ibgp neighbors\n")
2553 {
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555
2556 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2557 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2558 update_group_announce_rrclients(bgp);
2559 bgp_clear_star_soft_out(vty, bgp->name);
2560 }
2561
2562 return CMD_SUCCESS;
2563 }
2564
2565 DEFUN (no_bgp_rr_allow_outbound_policy,
2566 no_bgp_rr_allow_outbound_policy_cmd,
2567 "no bgp route-reflector allow-outbound-policy",
2568 NO_STR
2569 "BGP specific commands\n"
2570 "Allow modifications made by out route-map\n"
2571 "on ibgp neighbors\n")
2572 {
2573 VTY_DECLVAR_CONTEXT(bgp, bgp);
2574
2575 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2576 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2577 update_group_announce_rrclients(bgp);
2578 bgp_clear_star_soft_out(vty, bgp->name);
2579 }
2580
2581 return CMD_SUCCESS;
2582 }
2583
2584 DEFUN (bgp_listen_limit,
2585 bgp_listen_limit_cmd,
2586 "bgp listen limit (1-5000)",
2587 "BGP specific commands\n"
2588 "Configure BGP defaults\n"
2589 "maximum number of BGP Dynamic Neighbors that can be created\n"
2590 "Configure Dynamic Neighbors listen limit value\n")
2591 {
2592 VTY_DECLVAR_CONTEXT(bgp, bgp);
2593 int idx_number = 3;
2594 int listen_limit;
2595
2596 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2597
2598 bgp_listen_limit_set(bgp, listen_limit);
2599
2600 return CMD_SUCCESS;
2601 }
2602
2603 DEFUN (no_bgp_listen_limit,
2604 no_bgp_listen_limit_cmd,
2605 "no bgp listen limit [(1-5000)]",
2606 "BGP specific commands\n"
2607 "Configure BGP defaults\n"
2608 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2609 "Configure Dynamic Neighbors listen limit value to default\n"
2610 "Configure Dynamic Neighbors listen limit value\n")
2611 {
2612 VTY_DECLVAR_CONTEXT(bgp, bgp);
2613 bgp_listen_limit_unset(bgp);
2614 return CMD_SUCCESS;
2615 }
2616
2617
2618 /*
2619 * Check if this listen range is already configured. Check for exact
2620 * match or overlap based on input.
2621 */
2622 static struct peer_group *listen_range_exists(struct bgp *bgp,
2623 struct prefix *range, int exact)
2624 {
2625 struct listnode *node, *nnode;
2626 struct listnode *node1, *nnode1;
2627 struct peer_group *group;
2628 struct prefix *lr;
2629 afi_t afi;
2630 int match;
2631
2632 afi = family2afi(range->family);
2633 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2634 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2635 lr)) {
2636 if (exact)
2637 match = prefix_same(range, lr);
2638 else
2639 match = (prefix_match(range, lr)
2640 || prefix_match(lr, range));
2641 if (match)
2642 return group;
2643 }
2644 }
2645
2646 return NULL;
2647 }
2648
2649 DEFUN (bgp_listen_range,
2650 bgp_listen_range_cmd,
2651 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2652 "BGP specific commands\n"
2653 "Configure BGP dynamic neighbors listen range\n"
2654 "Configure BGP dynamic neighbors listen range\n"
2655 NEIGHBOR_ADDR_STR
2656 "Member of the peer-group\n"
2657 "Peer-group name\n")
2658 {
2659 VTY_DECLVAR_CONTEXT(bgp, bgp);
2660 struct prefix range;
2661 struct peer_group *group, *existing_group;
2662 afi_t afi;
2663 int ret;
2664 int idx = 0;
2665
2666 argv_find(argv, argc, "A.B.C.D/M", &idx);
2667 argv_find(argv, argc, "X:X::X:X/M", &idx);
2668 char *prefix = argv[idx]->arg;
2669 argv_find(argv, argc, "WORD", &idx);
2670 char *peergroup = argv[idx]->arg;
2671
2672 /* Convert IP prefix string to struct prefix. */
2673 ret = str2prefix(prefix, &range);
2674 if (!ret) {
2675 vty_out(vty, "%% Malformed listen range\n");
2676 return CMD_WARNING_CONFIG_FAILED;
2677 }
2678
2679 afi = family2afi(range.family);
2680
2681 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2682 vty_out(vty,
2683 "%% Malformed listen range (link-local address)\n");
2684 return CMD_WARNING_CONFIG_FAILED;
2685 }
2686
2687 apply_mask(&range);
2688
2689 /* Check if same listen range is already configured. */
2690 existing_group = listen_range_exists(bgp, &range, 1);
2691 if (existing_group) {
2692 if (strcmp(existing_group->name, peergroup) == 0)
2693 return CMD_SUCCESS;
2694 else {
2695 vty_out(vty,
2696 "%% Same listen range is attached to peer-group %s\n",
2697 existing_group->name);
2698 return CMD_WARNING_CONFIG_FAILED;
2699 }
2700 }
2701
2702 /* Check if an overlapping listen range exists. */
2703 if (listen_range_exists(bgp, &range, 0)) {
2704 vty_out(vty,
2705 "%% Listen range overlaps with existing listen range\n");
2706 return CMD_WARNING_CONFIG_FAILED;
2707 }
2708
2709 group = peer_group_lookup(bgp, peergroup);
2710 if (!group) {
2711 vty_out(vty, "%% Configure the peer-group first\n");
2712 return CMD_WARNING_CONFIG_FAILED;
2713 }
2714
2715 ret = peer_group_listen_range_add(group, &range);
2716 return bgp_vty_return(vty, ret);
2717 }
2718
2719 DEFUN (no_bgp_listen_range,
2720 no_bgp_listen_range_cmd,
2721 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2722 NO_STR
2723 "BGP specific commands\n"
2724 "Unconfigure BGP dynamic neighbors listen range\n"
2725 "Unconfigure BGP dynamic neighbors listen range\n"
2726 NEIGHBOR_ADDR_STR
2727 "Member of the peer-group\n"
2728 "Peer-group name\n")
2729 {
2730 VTY_DECLVAR_CONTEXT(bgp, bgp);
2731 struct prefix range;
2732 struct peer_group *group;
2733 afi_t afi;
2734 int ret;
2735 int idx = 0;
2736
2737 argv_find(argv, argc, "A.B.C.D/M", &idx);
2738 argv_find(argv, argc, "X:X::X:X/M", &idx);
2739 char *prefix = argv[idx]->arg;
2740 argv_find(argv, argc, "WORD", &idx);
2741 char *peergroup = argv[idx]->arg;
2742
2743 /* Convert IP prefix string to struct prefix. */
2744 ret = str2prefix(prefix, &range);
2745 if (!ret) {
2746 vty_out(vty, "%% Malformed listen range\n");
2747 return CMD_WARNING_CONFIG_FAILED;
2748 }
2749
2750 afi = family2afi(range.family);
2751
2752 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2753 vty_out(vty,
2754 "%% Malformed listen range (link-local address)\n");
2755 return CMD_WARNING_CONFIG_FAILED;
2756 }
2757
2758 apply_mask(&range);
2759
2760 group = peer_group_lookup(bgp, peergroup);
2761 if (!group) {
2762 vty_out(vty, "%% Peer-group does not exist\n");
2763 return CMD_WARNING_CONFIG_FAILED;
2764 }
2765
2766 ret = peer_group_listen_range_del(group, &range);
2767 return bgp_vty_return(vty, ret);
2768 }
2769
2770 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2771 {
2772 struct peer_group *group;
2773 struct listnode *node, *nnode, *rnode, *nrnode;
2774 struct prefix *range;
2775 afi_t afi;
2776 char buf[PREFIX2STR_BUFFER];
2777
2778 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2779 vty_out(vty, " bgp listen limit %d\n",
2780 bgp->dynamic_neighbors_limit);
2781
2782 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2783 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2784 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2785 nrnode, range)) {
2786 prefix2str(range, buf, sizeof(buf));
2787 vty_out(vty,
2788 " bgp listen range %s peer-group %s\n",
2789 buf, group->name);
2790 }
2791 }
2792 }
2793 }
2794
2795
2796 DEFUN (bgp_disable_connected_route_check,
2797 bgp_disable_connected_route_check_cmd,
2798 "bgp disable-ebgp-connected-route-check",
2799 "BGP specific commands\n"
2800 "Disable checking if nexthop is connected on ebgp sessions\n")
2801 {
2802 VTY_DECLVAR_CONTEXT(bgp, bgp);
2803 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2804 bgp_clear_star_soft_in(vty, bgp->name);
2805
2806 return CMD_SUCCESS;
2807 }
2808
2809 DEFUN (no_bgp_disable_connected_route_check,
2810 no_bgp_disable_connected_route_check_cmd,
2811 "no bgp disable-ebgp-connected-route-check",
2812 NO_STR
2813 "BGP specific commands\n"
2814 "Disable checking if nexthop is connected on ebgp sessions\n")
2815 {
2816 VTY_DECLVAR_CONTEXT(bgp, bgp);
2817 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2818 bgp_clear_star_soft_in(vty, bgp->name);
2819
2820 return CMD_SUCCESS;
2821 }
2822
2823
2824 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2825 const char *as_str, afi_t afi, safi_t safi)
2826 {
2827 VTY_DECLVAR_CONTEXT(bgp, bgp);
2828 int ret;
2829 as_t as;
2830 int as_type = AS_SPECIFIED;
2831 union sockunion su;
2832
2833 if (as_str[0] == 'i') {
2834 as = 0;
2835 as_type = AS_INTERNAL;
2836 } else if (as_str[0] == 'e') {
2837 as = 0;
2838 as_type = AS_EXTERNAL;
2839 } else {
2840 /* Get AS number. */
2841 as = strtoul(as_str, NULL, 10);
2842 }
2843
2844 /* If peer is peer group or interface peer, call proper function. */
2845 ret = str2sockunion(peer_str, &su);
2846 if (ret < 0) {
2847 struct peer *peer;
2848
2849 /* Check if existing interface peer */
2850 peer = peer_lookup_by_conf_if(bgp, peer_str);
2851
2852 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2853 safi);
2854
2855 /* if not interface peer, check peer-group settings */
2856 if (ret < 0 && !peer) {
2857 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2858 if (ret < 0) {
2859 vty_out(vty,
2860 "%% Create the peer-group or interface first\n");
2861 return CMD_WARNING_CONFIG_FAILED;
2862 }
2863 return CMD_SUCCESS;
2864 }
2865 } else {
2866 if (peer_address_self_check(bgp, &su)) {
2867 vty_out(vty,
2868 "%% Can not configure the local system as neighbor\n");
2869 return CMD_WARNING_CONFIG_FAILED;
2870 }
2871 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2872 }
2873
2874 /* This peer belongs to peer group. */
2875 switch (ret) {
2876 case BGP_ERR_PEER_GROUP_MEMBER:
2877 vty_out(vty,
2878 "%% Peer-group member cannot override remote-as of peer-group\n");
2879 return CMD_WARNING_CONFIG_FAILED;
2880 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2881 vty_out(vty,
2882 "%% Peer-group members must be all internal or all external\n");
2883 return CMD_WARNING_CONFIG_FAILED;
2884 }
2885 return bgp_vty_return(vty, ret);
2886 }
2887
2888 DEFUN (bgp_default_shutdown,
2889 bgp_default_shutdown_cmd,
2890 "[no] bgp default shutdown",
2891 NO_STR
2892 BGP_STR
2893 "Configure BGP defaults\n"
2894 "Apply administrative shutdown to newly configured peers\n")
2895 {
2896 VTY_DECLVAR_CONTEXT(bgp, bgp);
2897 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2898 return CMD_SUCCESS;
2899 }
2900
2901 DEFUN (neighbor_remote_as,
2902 neighbor_remote_as_cmd,
2903 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2904 NEIGHBOR_STR
2905 NEIGHBOR_ADDR_STR2
2906 "Specify a BGP neighbor\n"
2907 AS_STR
2908 "Internal BGP peer\n"
2909 "External BGP peer\n")
2910 {
2911 int idx_peer = 1;
2912 int idx_remote_as = 3;
2913 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2914 argv[idx_remote_as]->arg, AFI_IP,
2915 SAFI_UNICAST);
2916 }
2917
2918 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2919 afi_t afi, safi_t safi, int v6only,
2920 const char *peer_group_name,
2921 const char *as_str)
2922 {
2923 VTY_DECLVAR_CONTEXT(bgp, bgp);
2924 as_t as = 0;
2925 int as_type = AS_UNSPECIFIED;
2926 struct peer *peer;
2927 struct peer_group *group;
2928 int ret = 0;
2929 union sockunion su;
2930
2931 group = peer_group_lookup(bgp, conf_if);
2932
2933 if (group) {
2934 vty_out(vty, "%% Name conflict with peer-group \n");
2935 return CMD_WARNING_CONFIG_FAILED;
2936 }
2937
2938 if (as_str) {
2939 if (as_str[0] == 'i') {
2940 as_type = AS_INTERNAL;
2941 } else if (as_str[0] == 'e') {
2942 as_type = AS_EXTERNAL;
2943 } else {
2944 /* Get AS number. */
2945 as = strtoul(as_str, NULL, 10);
2946 as_type = AS_SPECIFIED;
2947 }
2948 }
2949
2950 peer = peer_lookup_by_conf_if(bgp, conf_if);
2951 if (peer) {
2952 if (as_str)
2953 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2954 afi, safi);
2955 } else {
2956 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2957 && afi == AFI_IP && safi == SAFI_UNICAST)
2958 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2959 as_type, 0, 0, NULL);
2960 else
2961 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2962 as_type, afi, safi, NULL);
2963
2964 if (!peer) {
2965 vty_out(vty, "%% BGP failed to create peer\n");
2966 return CMD_WARNING_CONFIG_FAILED;
2967 }
2968
2969 if (v6only)
2970 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2971
2972 /* Request zebra to initiate IPv6 RAs on this interface. We do
2973 * this
2974 * any unnumbered peer in order to not worry about run-time
2975 * transitions
2976 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2977 * address
2978 * gets deleted later etc.)
2979 */
2980 if (peer->ifp)
2981 bgp_zebra_initiate_radv(bgp, peer);
2982 }
2983
2984 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2985 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2986 if (v6only)
2987 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2988 else
2989 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2990
2991 /* v6only flag changed. Reset bgp seesion */
2992 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2993 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2994 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2995 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2996 } else
2997 bgp_session_reset(peer);
2998 }
2999
3000 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
3001 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
3002 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
3003 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
3004 }
3005
3006 if (peer_group_name) {
3007 group = peer_group_lookup(bgp, peer_group_name);
3008 if (!group) {
3009 vty_out(vty, "%% Configure the peer-group first\n");
3010 return CMD_WARNING_CONFIG_FAILED;
3011 }
3012
3013 ret = peer_group_bind(bgp, &su, peer, group, &as);
3014 }
3015
3016 return bgp_vty_return(vty, ret);
3017 }
3018
3019 DEFUN (neighbor_interface_config,
3020 neighbor_interface_config_cmd,
3021 "neighbor WORD interface [peer-group WORD]",
3022 NEIGHBOR_STR
3023 "Interface name or neighbor tag\n"
3024 "Enable BGP on interface\n"
3025 "Member of the peer-group\n"
3026 "Peer-group name\n")
3027 {
3028 int idx_word = 1;
3029 int idx_peer_group_word = 4;
3030
3031 if (argc > idx_peer_group_word)
3032 return peer_conf_interface_get(
3033 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3034 argv[idx_peer_group_word]->arg, NULL);
3035 else
3036 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3037 SAFI_UNICAST, 0, NULL, NULL);
3038 }
3039
3040 DEFUN (neighbor_interface_config_v6only,
3041 neighbor_interface_config_v6only_cmd,
3042 "neighbor WORD interface v6only [peer-group WORD]",
3043 NEIGHBOR_STR
3044 "Interface name or neighbor tag\n"
3045 "Enable BGP on interface\n"
3046 "Enable BGP with v6 link-local only\n"
3047 "Member of the peer-group\n"
3048 "Peer-group name\n")
3049 {
3050 int idx_word = 1;
3051 int idx_peer_group_word = 5;
3052
3053 if (argc > idx_peer_group_word)
3054 return peer_conf_interface_get(
3055 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3056 argv[idx_peer_group_word]->arg, NULL);
3057
3058 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3059 SAFI_UNICAST, 1, NULL, NULL);
3060 }
3061
3062
3063 DEFUN (neighbor_interface_config_remote_as,
3064 neighbor_interface_config_remote_as_cmd,
3065 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3066 NEIGHBOR_STR
3067 "Interface name or neighbor tag\n"
3068 "Enable BGP on interface\n"
3069 "Specify a BGP neighbor\n"
3070 AS_STR
3071 "Internal BGP peer\n"
3072 "External BGP peer\n")
3073 {
3074 int idx_word = 1;
3075 int idx_remote_as = 4;
3076 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3077 SAFI_UNICAST, 0, NULL,
3078 argv[idx_remote_as]->arg);
3079 }
3080
3081 DEFUN (neighbor_interface_v6only_config_remote_as,
3082 neighbor_interface_v6only_config_remote_as_cmd,
3083 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3084 NEIGHBOR_STR
3085 "Interface name or neighbor tag\n"
3086 "Enable BGP with v6 link-local only\n"
3087 "Enable BGP on interface\n"
3088 "Specify a BGP neighbor\n"
3089 AS_STR
3090 "Internal BGP peer\n"
3091 "External BGP peer\n")
3092 {
3093 int idx_word = 1;
3094 int idx_remote_as = 5;
3095 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3096 SAFI_UNICAST, 1, NULL,
3097 argv[idx_remote_as]->arg);
3098 }
3099
3100 DEFUN (neighbor_peer_group,
3101 neighbor_peer_group_cmd,
3102 "neighbor WORD peer-group",
3103 NEIGHBOR_STR
3104 "Interface name or neighbor tag\n"
3105 "Configure peer-group\n")
3106 {
3107 VTY_DECLVAR_CONTEXT(bgp, bgp);
3108 int idx_word = 1;
3109 struct peer *peer;
3110 struct peer_group *group;
3111
3112 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3113 if (peer) {
3114 vty_out(vty, "%% Name conflict with interface: \n");
3115 return CMD_WARNING_CONFIG_FAILED;
3116 }
3117
3118 group = peer_group_get(bgp, argv[idx_word]->arg);
3119 if (!group) {
3120 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3121 return CMD_WARNING_CONFIG_FAILED;
3122 }
3123
3124 return CMD_SUCCESS;
3125 }
3126
3127 DEFUN (no_neighbor,
3128 no_neighbor_cmd,
3129 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3130 NO_STR
3131 NEIGHBOR_STR
3132 NEIGHBOR_ADDR_STR2
3133 "Specify a BGP neighbor\n"
3134 AS_STR
3135 "Internal BGP peer\n"
3136 "External BGP peer\n")
3137 {
3138 VTY_DECLVAR_CONTEXT(bgp, bgp);
3139 int idx_peer = 2;
3140 int ret;
3141 union sockunion su;
3142 struct peer_group *group;
3143 struct peer *peer;
3144 struct peer *other;
3145
3146 ret = str2sockunion(argv[idx_peer]->arg, &su);
3147 if (ret < 0) {
3148 /* look up for neighbor by interface name config. */
3149 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3150 if (peer) {
3151 /* Request zebra to terminate IPv6 RAs on this
3152 * interface. */
3153 if (peer->ifp)
3154 bgp_zebra_terminate_radv(peer->bgp, peer);
3155 peer_delete(peer);
3156 return CMD_SUCCESS;
3157 }
3158
3159 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3160 if (group)
3161 peer_group_delete(group);
3162 else {
3163 vty_out(vty, "%% Create the peer-group first\n");
3164 return CMD_WARNING_CONFIG_FAILED;
3165 }
3166 } else {
3167 peer = peer_lookup(bgp, &su);
3168 if (peer) {
3169 if (peer_dynamic_neighbor(peer)) {
3170 vty_out(vty,
3171 "%% Operation not allowed on a dynamic neighbor\n");
3172 return CMD_WARNING_CONFIG_FAILED;
3173 }
3174
3175 other = peer->doppelganger;
3176 peer_delete(peer);
3177 if (other && other->status != Deleted)
3178 peer_delete(other);
3179 }
3180 }
3181
3182 return CMD_SUCCESS;
3183 }
3184
3185 DEFUN (no_neighbor_interface_config,
3186 no_neighbor_interface_config_cmd,
3187 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3188 NO_STR
3189 NEIGHBOR_STR
3190 "Interface name\n"
3191 "Configure BGP on interface\n"
3192 "Enable BGP with v6 link-local only\n"
3193 "Member of the peer-group\n"
3194 "Peer-group name\n"
3195 "Specify a BGP neighbor\n"
3196 AS_STR
3197 "Internal BGP peer\n"
3198 "External BGP peer\n")
3199 {
3200 VTY_DECLVAR_CONTEXT(bgp, bgp);
3201 int idx_word = 2;
3202 struct peer *peer;
3203
3204 /* look up for neighbor by interface name config. */
3205 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3206 if (peer) {
3207 /* Request zebra to terminate IPv6 RAs on this interface. */
3208 if (peer->ifp)
3209 bgp_zebra_terminate_radv(peer->bgp, peer);
3210 peer_delete(peer);
3211 } else {
3212 vty_out(vty, "%% Create the bgp interface first\n");
3213 return CMD_WARNING_CONFIG_FAILED;
3214 }
3215 return CMD_SUCCESS;
3216 }
3217
3218 DEFUN (no_neighbor_peer_group,
3219 no_neighbor_peer_group_cmd,
3220 "no neighbor WORD peer-group",
3221 NO_STR
3222 NEIGHBOR_STR
3223 "Neighbor tag\n"
3224 "Configure peer-group\n")
3225 {
3226 VTY_DECLVAR_CONTEXT(bgp, bgp);
3227 int idx_word = 2;
3228 struct peer_group *group;
3229
3230 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3231 if (group)
3232 peer_group_delete(group);
3233 else {
3234 vty_out(vty, "%% Create the peer-group first\n");
3235 return CMD_WARNING_CONFIG_FAILED;
3236 }
3237 return CMD_SUCCESS;
3238 }
3239
3240 DEFUN (no_neighbor_interface_peer_group_remote_as,
3241 no_neighbor_interface_peer_group_remote_as_cmd,
3242 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3243 NO_STR
3244 NEIGHBOR_STR
3245 "Interface name or neighbor tag\n"
3246 "Specify a BGP neighbor\n"
3247 AS_STR
3248 "Internal BGP peer\n"
3249 "External BGP peer\n")
3250 {
3251 VTY_DECLVAR_CONTEXT(bgp, bgp);
3252 int idx_word = 2;
3253 struct peer_group *group;
3254 struct peer *peer;
3255
3256 /* look up for neighbor by interface name config. */
3257 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3258 if (peer) {
3259 peer_as_change(peer, 0, AS_UNSPECIFIED);
3260 return CMD_SUCCESS;
3261 }
3262
3263 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3264 if (group)
3265 peer_group_remote_as_delete(group);
3266 else {
3267 vty_out(vty, "%% Create the peer-group or interface first\n");
3268 return CMD_WARNING_CONFIG_FAILED;
3269 }
3270 return CMD_SUCCESS;
3271 }
3272
3273 DEFUN (neighbor_local_as,
3274 neighbor_local_as_cmd,
3275 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3276 NEIGHBOR_STR
3277 NEIGHBOR_ADDR_STR2
3278 "Specify a local-as number\n"
3279 "AS number used as local AS\n")
3280 {
3281 int idx_peer = 1;
3282 int idx_number = 3;
3283 struct peer *peer;
3284 int ret;
3285 as_t as;
3286
3287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3288 if (!peer)
3289 return CMD_WARNING_CONFIG_FAILED;
3290
3291 as = strtoul(argv[idx_number]->arg, NULL, 10);
3292 ret = peer_local_as_set(peer, as, 0, 0);
3293 return bgp_vty_return(vty, ret);
3294 }
3295
3296 DEFUN (neighbor_local_as_no_prepend,
3297 neighbor_local_as_no_prepend_cmd,
3298 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3299 NEIGHBOR_STR
3300 NEIGHBOR_ADDR_STR2
3301 "Specify a local-as number\n"
3302 "AS number used as local AS\n"
3303 "Do not prepend local-as to updates from ebgp peers\n")
3304 {
3305 int idx_peer = 1;
3306 int idx_number = 3;
3307 struct peer *peer;
3308 int ret;
3309 as_t as;
3310
3311 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3312 if (!peer)
3313 return CMD_WARNING_CONFIG_FAILED;
3314
3315 as = strtoul(argv[idx_number]->arg, NULL, 10);
3316 ret = peer_local_as_set(peer, as, 1, 0);
3317 return bgp_vty_return(vty, ret);
3318 }
3319
3320 DEFUN (neighbor_local_as_no_prepend_replace_as,
3321 neighbor_local_as_no_prepend_replace_as_cmd,
3322 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3323 NEIGHBOR_STR
3324 NEIGHBOR_ADDR_STR2
3325 "Specify a local-as number\n"
3326 "AS number used as local AS\n"
3327 "Do not prepend local-as to updates from ebgp peers\n"
3328 "Do not prepend local-as to updates from ibgp peers\n")
3329 {
3330 int idx_peer = 1;
3331 int idx_number = 3;
3332 struct peer *peer;
3333 int ret;
3334 as_t as;
3335
3336 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3337 if (!peer)
3338 return CMD_WARNING_CONFIG_FAILED;
3339
3340 as = strtoul(argv[idx_number]->arg, NULL, 10);
3341 ret = peer_local_as_set(peer, as, 1, 1);
3342 return bgp_vty_return(vty, ret);
3343 }
3344
3345 DEFUN (no_neighbor_local_as,
3346 no_neighbor_local_as_cmd,
3347 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3348 NO_STR
3349 NEIGHBOR_STR
3350 NEIGHBOR_ADDR_STR2
3351 "Specify a local-as number\n"
3352 "AS number used as local AS\n"
3353 "Do not prepend local-as to updates from ebgp peers\n"
3354 "Do not prepend local-as to updates from ibgp peers\n")
3355 {
3356 int idx_peer = 2;
3357 struct peer *peer;
3358 int ret;
3359
3360 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3361 if (!peer)
3362 return CMD_WARNING_CONFIG_FAILED;
3363
3364 ret = peer_local_as_unset(peer);
3365 return bgp_vty_return(vty, ret);
3366 }
3367
3368
3369 DEFUN (neighbor_solo,
3370 neighbor_solo_cmd,
3371 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3372 NEIGHBOR_STR
3373 NEIGHBOR_ADDR_STR2
3374 "Solo peer - part of its own update group\n")
3375 {
3376 int idx_peer = 1;
3377 struct peer *peer;
3378 int ret;
3379
3380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3381 if (!peer)
3382 return CMD_WARNING_CONFIG_FAILED;
3383
3384 ret = update_group_adjust_soloness(peer, 1);
3385 return bgp_vty_return(vty, ret);
3386 }
3387
3388 DEFUN (no_neighbor_solo,
3389 no_neighbor_solo_cmd,
3390 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3391 NO_STR
3392 NEIGHBOR_STR
3393 NEIGHBOR_ADDR_STR2
3394 "Solo peer - part of its own update group\n")
3395 {
3396 int idx_peer = 2;
3397 struct peer *peer;
3398 int ret;
3399
3400 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3401 if (!peer)
3402 return CMD_WARNING_CONFIG_FAILED;
3403
3404 ret = update_group_adjust_soloness(peer, 0);
3405 return bgp_vty_return(vty, ret);
3406 }
3407
3408 DEFUN (neighbor_password,
3409 neighbor_password_cmd,
3410 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3411 NEIGHBOR_STR
3412 NEIGHBOR_ADDR_STR2
3413 "Set a password\n"
3414 "The password\n")
3415 {
3416 int idx_peer = 1;
3417 int idx_line = 3;
3418 struct peer *peer;
3419 int ret;
3420
3421 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3422 if (!peer)
3423 return CMD_WARNING_CONFIG_FAILED;
3424
3425 ret = peer_password_set(peer, argv[idx_line]->arg);
3426 return bgp_vty_return(vty, ret);
3427 }
3428
3429 DEFUN (no_neighbor_password,
3430 no_neighbor_password_cmd,
3431 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3432 NO_STR
3433 NEIGHBOR_STR
3434 NEIGHBOR_ADDR_STR2
3435 "Set a password\n"
3436 "The password\n")
3437 {
3438 int idx_peer = 2;
3439 struct peer *peer;
3440 int ret;
3441
3442 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3443 if (!peer)
3444 return CMD_WARNING_CONFIG_FAILED;
3445
3446 ret = peer_password_unset(peer);
3447 return bgp_vty_return(vty, ret);
3448 }
3449
3450 DEFUN (neighbor_activate,
3451 neighbor_activate_cmd,
3452 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3453 NEIGHBOR_STR
3454 NEIGHBOR_ADDR_STR2
3455 "Enable the Address Family for this Neighbor\n")
3456 {
3457 int idx_peer = 1;
3458 int ret;
3459 struct peer *peer;
3460
3461 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3462 if (!peer)
3463 return CMD_WARNING_CONFIG_FAILED;
3464
3465 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3466 return bgp_vty_return(vty, ret);
3467 }
3468
3469 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3470 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3471 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3472 "Enable the Address Family for this Neighbor\n")
3473
3474 DEFUN (no_neighbor_activate,
3475 no_neighbor_activate_cmd,
3476 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3477 NO_STR
3478 NEIGHBOR_STR
3479 NEIGHBOR_ADDR_STR2
3480 "Enable the Address Family for this Neighbor\n")
3481 {
3482 int idx_peer = 2;
3483 int ret;
3484 struct peer *peer;
3485
3486 /* Lookup peer. */
3487 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3488 if (!peer)
3489 return CMD_WARNING_CONFIG_FAILED;
3490
3491 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3492 return bgp_vty_return(vty, ret);
3493 }
3494
3495 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3496 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3497 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3498 "Enable the Address Family for this Neighbor\n")
3499
3500 DEFUN (neighbor_set_peer_group,
3501 neighbor_set_peer_group_cmd,
3502 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3503 NEIGHBOR_STR
3504 NEIGHBOR_ADDR_STR2
3505 "Member of the peer-group\n"
3506 "Peer-group name\n")
3507 {
3508 VTY_DECLVAR_CONTEXT(bgp, bgp);
3509 int idx_peer = 1;
3510 int idx_word = 3;
3511 int ret;
3512 as_t as;
3513 union sockunion su;
3514 struct peer *peer;
3515 struct peer_group *group;
3516
3517 ret = str2sockunion(argv[idx_peer]->arg, &su);
3518 if (ret < 0) {
3519 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3520 if (!peer) {
3521 vty_out(vty, "%% Malformed address or name: %s\n",
3522 argv[idx_peer]->arg);
3523 return CMD_WARNING_CONFIG_FAILED;
3524 }
3525 } else {
3526 if (peer_address_self_check(bgp, &su)) {
3527 vty_out(vty,
3528 "%% Can not configure the local system as neighbor\n");
3529 return CMD_WARNING_CONFIG_FAILED;
3530 }
3531
3532 /* Disallow for dynamic neighbor. */
3533 peer = peer_lookup(bgp, &su);
3534 if (peer && peer_dynamic_neighbor(peer)) {
3535 vty_out(vty,
3536 "%% Operation not allowed on a dynamic neighbor\n");
3537 return CMD_WARNING_CONFIG_FAILED;
3538 }
3539 }
3540
3541 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3542 if (!group) {
3543 vty_out(vty, "%% Configure the peer-group first\n");
3544 return CMD_WARNING_CONFIG_FAILED;
3545 }
3546
3547 ret = peer_group_bind(bgp, &su, peer, group, &as);
3548
3549 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3550 vty_out(vty,
3551 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3552 as);
3553 return CMD_WARNING_CONFIG_FAILED;
3554 }
3555
3556 return bgp_vty_return(vty, ret);
3557 }
3558
3559 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3560 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3561 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3562 "Member of the peer-group\n"
3563 "Peer-group name\n")
3564
3565 DEFUN (no_neighbor_set_peer_group,
3566 no_neighbor_set_peer_group_cmd,
3567 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3568 NO_STR
3569 NEIGHBOR_STR
3570 NEIGHBOR_ADDR_STR2
3571 "Member of the peer-group\n"
3572 "Peer-group name\n")
3573 {
3574 VTY_DECLVAR_CONTEXT(bgp, bgp);
3575 int idx_peer = 2;
3576 int idx_word = 4;
3577 int ret;
3578 struct peer *peer;
3579 struct peer_group *group;
3580
3581 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3582 if (!peer)
3583 return CMD_WARNING_CONFIG_FAILED;
3584
3585 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3586 if (!group) {
3587 vty_out(vty, "%% Configure the peer-group first\n");
3588 return CMD_WARNING_CONFIG_FAILED;
3589 }
3590
3591 ret = peer_delete(peer);
3592
3593 return bgp_vty_return(vty, ret);
3594 }
3595
3596 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3597 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3598 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3599 "Member of the peer-group\n"
3600 "Peer-group name\n")
3601
3602 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3603 uint32_t flag, int set)
3604 {
3605 int ret;
3606 struct peer *peer;
3607
3608 peer = peer_and_group_lookup_vty(vty, ip_str);
3609 if (!peer)
3610 return CMD_WARNING_CONFIG_FAILED;
3611
3612 /*
3613 * If 'neighbor <interface>', then this is for directly connected peers,
3614 * we should not accept disable-connected-check.
3615 */
3616 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3617 vty_out(vty,
3618 "%s is directly connected peer, cannot accept disable-"
3619 "connected-check\n",
3620 ip_str);
3621 return CMD_WARNING_CONFIG_FAILED;
3622 }
3623
3624 if (!set && flag == PEER_FLAG_SHUTDOWN)
3625 peer_tx_shutdown_message_unset(peer);
3626
3627 if (set)
3628 ret = peer_flag_set(peer, flag);
3629 else
3630 ret = peer_flag_unset(peer, flag);
3631
3632 return bgp_vty_return(vty, ret);
3633 }
3634
3635 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3636 {
3637 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3638 }
3639
3640 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3641 uint32_t flag)
3642 {
3643 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3644 }
3645
3646 /* neighbor passive. */
3647 DEFUN (neighbor_passive,
3648 neighbor_passive_cmd,
3649 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3650 NEIGHBOR_STR
3651 NEIGHBOR_ADDR_STR2
3652 "Don't send open messages to this neighbor\n")
3653 {
3654 int idx_peer = 1;
3655 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3656 }
3657
3658 DEFUN (no_neighbor_passive,
3659 no_neighbor_passive_cmd,
3660 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3661 NO_STR
3662 NEIGHBOR_STR
3663 NEIGHBOR_ADDR_STR2
3664 "Don't send open messages to this neighbor\n")
3665 {
3666 int idx_peer = 2;
3667 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3668 }
3669
3670 /* neighbor shutdown. */
3671 DEFUN (neighbor_shutdown_msg,
3672 neighbor_shutdown_msg_cmd,
3673 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3674 NEIGHBOR_STR
3675 NEIGHBOR_ADDR_STR2
3676 "Administratively shut down this neighbor\n"
3677 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3678 "Shutdown message\n")
3679 {
3680 int idx_peer = 1;
3681
3682 if (argc >= 5) {
3683 struct peer *peer =
3684 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3685 char *message;
3686
3687 if (!peer)
3688 return CMD_WARNING_CONFIG_FAILED;
3689 message = argv_concat(argv, argc, 4);
3690 peer_tx_shutdown_message_set(peer, message);
3691 XFREE(MTYPE_TMP, message);
3692 }
3693
3694 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3695 }
3696
3697 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3698 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3700 "Administratively shut down this neighbor\n")
3701
3702 DEFUN (no_neighbor_shutdown_msg,
3703 no_neighbor_shutdown_msg_cmd,
3704 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3705 NO_STR
3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Administratively shut down this neighbor\n"
3709 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3710 "Shutdown message\n")
3711 {
3712 int idx_peer = 2;
3713
3714 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3715 PEER_FLAG_SHUTDOWN);
3716 }
3717
3718 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3719 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3720 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3721 "Administratively shut down this neighbor\n")
3722
3723 /* neighbor capability dynamic. */
3724 DEFUN (neighbor_capability_dynamic,
3725 neighbor_capability_dynamic_cmd,
3726 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3727 NEIGHBOR_STR
3728 NEIGHBOR_ADDR_STR2
3729 "Advertise capability to the peer\n"
3730 "Advertise dynamic capability to this neighbor\n")
3731 {
3732 int idx_peer = 1;
3733 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3734 PEER_FLAG_DYNAMIC_CAPABILITY);
3735 }
3736
3737 DEFUN (no_neighbor_capability_dynamic,
3738 no_neighbor_capability_dynamic_cmd,
3739 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3740 NO_STR
3741 NEIGHBOR_STR
3742 NEIGHBOR_ADDR_STR2
3743 "Advertise capability to the peer\n"
3744 "Advertise dynamic capability to this neighbor\n")
3745 {
3746 int idx_peer = 2;
3747 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3748 PEER_FLAG_DYNAMIC_CAPABILITY);
3749 }
3750
3751 /* neighbor dont-capability-negotiate */
3752 DEFUN (neighbor_dont_capability_negotiate,
3753 neighbor_dont_capability_negotiate_cmd,
3754 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3755 NEIGHBOR_STR
3756 NEIGHBOR_ADDR_STR2
3757 "Do not perform capability negotiation\n")
3758 {
3759 int idx_peer = 1;
3760 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3761 PEER_FLAG_DONT_CAPABILITY);
3762 }
3763
3764 DEFUN (no_neighbor_dont_capability_negotiate,
3765 no_neighbor_dont_capability_negotiate_cmd,
3766 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3767 NO_STR
3768 NEIGHBOR_STR
3769 NEIGHBOR_ADDR_STR2
3770 "Do not perform capability negotiation\n")
3771 {
3772 int idx_peer = 2;
3773 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3774 PEER_FLAG_DONT_CAPABILITY);
3775 }
3776
3777 /* neighbor capability extended next hop encoding */
3778 DEFUN (neighbor_capability_enhe,
3779 neighbor_capability_enhe_cmd,
3780 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3781 NEIGHBOR_STR
3782 NEIGHBOR_ADDR_STR2
3783 "Advertise capability to the peer\n"
3784 "Advertise extended next-hop capability to the peer\n")
3785 {
3786 int idx_peer = 1;
3787 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3788 PEER_FLAG_CAPABILITY_ENHE);
3789 }
3790
3791 DEFUN (no_neighbor_capability_enhe,
3792 no_neighbor_capability_enhe_cmd,
3793 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3794 NO_STR
3795 NEIGHBOR_STR
3796 NEIGHBOR_ADDR_STR2
3797 "Advertise capability to the peer\n"
3798 "Advertise extended next-hop capability to the peer\n")
3799 {
3800 int idx_peer = 2;
3801 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3802 PEER_FLAG_CAPABILITY_ENHE);
3803 }
3804
3805 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3806 afi_t afi, safi_t safi, uint32_t flag,
3807 int set)
3808 {
3809 int ret;
3810 struct peer *peer;
3811
3812 peer = peer_and_group_lookup_vty(vty, peer_str);
3813 if (!peer)
3814 return CMD_WARNING_CONFIG_FAILED;
3815
3816 if (set)
3817 ret = peer_af_flag_set(peer, afi, safi, flag);
3818 else
3819 ret = peer_af_flag_unset(peer, afi, safi, flag);
3820
3821 return bgp_vty_return(vty, ret);
3822 }
3823
3824 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3825 afi_t afi, safi_t safi, uint32_t flag)
3826 {
3827 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3828 }
3829
3830 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3831 afi_t afi, safi_t safi, uint32_t flag)
3832 {
3833 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3834 }
3835
3836 /* neighbor capability orf prefix-list. */
3837 DEFUN (neighbor_capability_orf_prefix,
3838 neighbor_capability_orf_prefix_cmd,
3839 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3840 NEIGHBOR_STR
3841 NEIGHBOR_ADDR_STR2
3842 "Advertise capability to the peer\n"
3843 "Advertise ORF capability to the peer\n"
3844 "Advertise prefixlist ORF capability to this neighbor\n"
3845 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3846 "Capability to RECEIVE the ORF from this neighbor\n"
3847 "Capability to SEND the ORF to this neighbor\n")
3848 {
3849 int idx_peer = 1;
3850 int idx_send_recv = 5;
3851 uint16_t flag = 0;
3852
3853 if (strmatch(argv[idx_send_recv]->text, "send"))
3854 flag = PEER_FLAG_ORF_PREFIX_SM;
3855 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3856 flag = PEER_FLAG_ORF_PREFIX_RM;
3857 else if (strmatch(argv[idx_send_recv]->text, "both"))
3858 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3859 else {
3860 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3861 return CMD_WARNING_CONFIG_FAILED;
3862 }
3863
3864 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3865 bgp_node_safi(vty), flag);
3866 }
3867
3868 ALIAS_HIDDEN(
3869 neighbor_capability_orf_prefix,
3870 neighbor_capability_orf_prefix_hidden_cmd,
3871 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3872 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3873 "Advertise capability to the peer\n"
3874 "Advertise ORF capability to the peer\n"
3875 "Advertise prefixlist ORF capability to this neighbor\n"
3876 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3877 "Capability to RECEIVE the ORF from this neighbor\n"
3878 "Capability to SEND the ORF to this neighbor\n")
3879
3880 DEFUN (no_neighbor_capability_orf_prefix,
3881 no_neighbor_capability_orf_prefix_cmd,
3882 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3883 NO_STR
3884 NEIGHBOR_STR
3885 NEIGHBOR_ADDR_STR2
3886 "Advertise capability to the peer\n"
3887 "Advertise ORF capability to the peer\n"
3888 "Advertise prefixlist ORF capability to this neighbor\n"
3889 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3890 "Capability to RECEIVE the ORF from this neighbor\n"
3891 "Capability to SEND the ORF to this neighbor\n")
3892 {
3893 int idx_peer = 2;
3894 int idx_send_recv = 6;
3895 uint16_t flag = 0;
3896
3897 if (strmatch(argv[idx_send_recv]->text, "send"))
3898 flag = PEER_FLAG_ORF_PREFIX_SM;
3899 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3900 flag = PEER_FLAG_ORF_PREFIX_RM;
3901 else if (strmatch(argv[idx_send_recv]->text, "both"))
3902 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3903 else {
3904 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3905 return CMD_WARNING_CONFIG_FAILED;
3906 }
3907
3908 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3909 bgp_node_afi(vty), bgp_node_safi(vty),
3910 flag);
3911 }
3912
3913 ALIAS_HIDDEN(
3914 no_neighbor_capability_orf_prefix,
3915 no_neighbor_capability_orf_prefix_hidden_cmd,
3916 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3917 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3918 "Advertise capability to the peer\n"
3919 "Advertise ORF capability to the peer\n"
3920 "Advertise prefixlist ORF capability to this neighbor\n"
3921 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3922 "Capability to RECEIVE the ORF from this neighbor\n"
3923 "Capability to SEND the ORF to this neighbor\n")
3924
3925 /* neighbor next-hop-self. */
3926 DEFUN (neighbor_nexthop_self,
3927 neighbor_nexthop_self_cmd,
3928 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3929 NEIGHBOR_STR
3930 NEIGHBOR_ADDR_STR2
3931 "Disable the next hop calculation for this neighbor\n")
3932 {
3933 int idx_peer = 1;
3934 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3935 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3936 }
3937
3938 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3939 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3941 "Disable the next hop calculation for this neighbor\n")
3942
3943 /* neighbor next-hop-self. */
3944 DEFUN (neighbor_nexthop_self_force,
3945 neighbor_nexthop_self_force_cmd,
3946 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3947 NEIGHBOR_STR
3948 NEIGHBOR_ADDR_STR2
3949 "Disable the next hop calculation for this neighbor\n"
3950 "Set the next hop to self for reflected routes\n")
3951 {
3952 int idx_peer = 1;
3953 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3954 bgp_node_safi(vty),
3955 PEER_FLAG_FORCE_NEXTHOP_SELF);
3956 }
3957
3958 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3959 neighbor_nexthop_self_force_hidden_cmd,
3960 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3961 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3962 "Disable the next hop calculation for this neighbor\n"
3963 "Set the next hop to self for reflected routes\n")
3964
3965 DEFUN (no_neighbor_nexthop_self,
3966 no_neighbor_nexthop_self_cmd,
3967 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3968 NO_STR
3969 NEIGHBOR_STR
3970 NEIGHBOR_ADDR_STR2
3971 "Disable the next hop calculation for this neighbor\n")
3972 {
3973 int idx_peer = 2;
3974 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3975 bgp_node_afi(vty), bgp_node_safi(vty),
3976 PEER_FLAG_NEXTHOP_SELF);
3977 }
3978
3979 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3980 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3981 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3982 "Disable the next hop calculation for this neighbor\n")
3983
3984 DEFUN (no_neighbor_nexthop_self_force,
3985 no_neighbor_nexthop_self_force_cmd,
3986 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3987 NO_STR
3988 NEIGHBOR_STR
3989 NEIGHBOR_ADDR_STR2
3990 "Disable the next hop calculation for this neighbor\n"
3991 "Set the next hop to self for reflected routes\n")
3992 {
3993 int idx_peer = 2;
3994 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3995 bgp_node_afi(vty), bgp_node_safi(vty),
3996 PEER_FLAG_FORCE_NEXTHOP_SELF);
3997 }
3998
3999 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
4000 no_neighbor_nexthop_self_force_hidden_cmd,
4001 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
4002 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4003 "Disable the next hop calculation for this neighbor\n"
4004 "Set the next hop to self for reflected routes\n")
4005
4006 /* neighbor as-override */
4007 DEFUN (neighbor_as_override,
4008 neighbor_as_override_cmd,
4009 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4010 NEIGHBOR_STR
4011 NEIGHBOR_ADDR_STR2
4012 "Override ASNs in outbound updates if aspath equals remote-as\n")
4013 {
4014 int idx_peer = 1;
4015 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4016 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4017 }
4018
4019 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4020 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4021 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4022 "Override ASNs in outbound updates if aspath equals remote-as\n")
4023
4024 DEFUN (no_neighbor_as_override,
4025 no_neighbor_as_override_cmd,
4026 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4027 NO_STR
4028 NEIGHBOR_STR
4029 NEIGHBOR_ADDR_STR2
4030 "Override ASNs in outbound updates if aspath equals remote-as\n")
4031 {
4032 int idx_peer = 2;
4033 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4034 bgp_node_afi(vty), bgp_node_safi(vty),
4035 PEER_FLAG_AS_OVERRIDE);
4036 }
4037
4038 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4039 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4040 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4041 "Override ASNs in outbound updates if aspath equals remote-as\n")
4042
4043 /* neighbor remove-private-AS. */
4044 DEFUN (neighbor_remove_private_as,
4045 neighbor_remove_private_as_cmd,
4046 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4047 NEIGHBOR_STR
4048 NEIGHBOR_ADDR_STR2
4049 "Remove private ASNs in outbound updates\n")
4050 {
4051 int idx_peer = 1;
4052 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4053 bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS);
4055 }
4056
4057 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4058 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4059 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4060 "Remove private ASNs in outbound updates\n")
4061
4062 DEFUN (neighbor_remove_private_as_all,
4063 neighbor_remove_private_as_all_cmd,
4064 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4065 NEIGHBOR_STR
4066 NEIGHBOR_ADDR_STR2
4067 "Remove private ASNs in outbound updates\n"
4068 "Apply to all AS numbers\n")
4069 {
4070 int idx_peer = 1;
4071 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4072 bgp_node_safi(vty),
4073 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4074 }
4075
4076 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4077 neighbor_remove_private_as_all_hidden_cmd,
4078 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4079 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4080 "Remove private ASNs in outbound updates\n"
4081 "Apply to all AS numbers")
4082
4083 DEFUN (neighbor_remove_private_as_replace_as,
4084 neighbor_remove_private_as_replace_as_cmd,
4085 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4086 NEIGHBOR_STR
4087 NEIGHBOR_ADDR_STR2
4088 "Remove private ASNs in outbound updates\n"
4089 "Replace private ASNs with our ASN in outbound updates\n")
4090 {
4091 int idx_peer = 1;
4092 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4093 bgp_node_safi(vty),
4094 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4095 }
4096
4097 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4098 neighbor_remove_private_as_replace_as_hidden_cmd,
4099 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4100 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4101 "Remove private ASNs in outbound updates\n"
4102 "Replace private ASNs with our ASN in outbound updates\n")
4103
4104 DEFUN (neighbor_remove_private_as_all_replace_as,
4105 neighbor_remove_private_as_all_replace_as_cmd,
4106 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4107 NEIGHBOR_STR
4108 NEIGHBOR_ADDR_STR2
4109 "Remove private ASNs in outbound updates\n"
4110 "Apply to all AS numbers\n"
4111 "Replace private ASNs with our ASN in outbound updates\n")
4112 {
4113 int idx_peer = 1;
4114 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4115 bgp_node_safi(vty),
4116 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4117 }
4118
4119 ALIAS_HIDDEN(
4120 neighbor_remove_private_as_all_replace_as,
4121 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4122 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4123 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4124 "Remove private ASNs in outbound updates\n"
4125 "Apply to all AS numbers\n"
4126 "Replace private ASNs with our ASN in outbound updates\n")
4127
4128 DEFUN (no_neighbor_remove_private_as,
4129 no_neighbor_remove_private_as_cmd,
4130 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4131 NO_STR
4132 NEIGHBOR_STR
4133 NEIGHBOR_ADDR_STR2
4134 "Remove private ASNs in outbound updates\n")
4135 {
4136 int idx_peer = 2;
4137 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4138 bgp_node_afi(vty), bgp_node_safi(vty),
4139 PEER_FLAG_REMOVE_PRIVATE_AS);
4140 }
4141
4142 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4143 no_neighbor_remove_private_as_hidden_cmd,
4144 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4145 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4146 "Remove private ASNs in outbound updates\n")
4147
4148 DEFUN (no_neighbor_remove_private_as_all,
4149 no_neighbor_remove_private_as_all_cmd,
4150 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4151 NO_STR
4152 NEIGHBOR_STR
4153 NEIGHBOR_ADDR_STR2
4154 "Remove private ASNs in outbound updates\n"
4155 "Apply to all AS numbers\n")
4156 {
4157 int idx_peer = 2;
4158 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4159 bgp_node_afi(vty), bgp_node_safi(vty),
4160 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4161 }
4162
4163 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4164 no_neighbor_remove_private_as_all_hidden_cmd,
4165 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4166 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4167 "Remove private ASNs in outbound updates\n"
4168 "Apply to all AS numbers\n")
4169
4170 DEFUN (no_neighbor_remove_private_as_replace_as,
4171 no_neighbor_remove_private_as_replace_as_cmd,
4172 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4173 NO_STR
4174 NEIGHBOR_STR
4175 NEIGHBOR_ADDR_STR2
4176 "Remove private ASNs in outbound updates\n"
4177 "Replace private ASNs with our ASN in outbound updates\n")
4178 {
4179 int idx_peer = 2;
4180 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4181 bgp_node_afi(vty), bgp_node_safi(vty),
4182 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4183 }
4184
4185 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4186 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4187 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4188 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4189 "Remove private ASNs in outbound updates\n"
4190 "Replace private ASNs with our ASN in outbound updates\n")
4191
4192 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4193 no_neighbor_remove_private_as_all_replace_as_cmd,
4194 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4195 NO_STR
4196 NEIGHBOR_STR
4197 NEIGHBOR_ADDR_STR2
4198 "Remove private ASNs in outbound updates\n"
4199 "Apply to all AS numbers\n"
4200 "Replace private ASNs with our ASN in outbound updates\n")
4201 {
4202 int idx_peer = 2;
4203 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4204 bgp_node_afi(vty), bgp_node_safi(vty),
4205 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4206 }
4207
4208 ALIAS_HIDDEN(
4209 no_neighbor_remove_private_as_all_replace_as,
4210 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4212 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4213 "Remove private ASNs in outbound updates\n"
4214 "Apply to all AS numbers\n"
4215 "Replace private ASNs with our ASN in outbound updates\n")
4216
4217
4218 /* neighbor send-community. */
4219 DEFUN (neighbor_send_community,
4220 neighbor_send_community_cmd,
4221 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4222 NEIGHBOR_STR
4223 NEIGHBOR_ADDR_STR2
4224 "Send Community attribute to this neighbor\n")
4225 {
4226 int idx_peer = 1;
4227
4228 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4229 bgp_node_safi(vty),
4230 PEER_FLAG_SEND_COMMUNITY);
4231 }
4232
4233 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4234 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4235 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4236 "Send Community attribute to this neighbor\n")
4237
4238 DEFUN (no_neighbor_send_community,
4239 no_neighbor_send_community_cmd,
4240 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4241 NO_STR
4242 NEIGHBOR_STR
4243 NEIGHBOR_ADDR_STR2
4244 "Send Community attribute to this neighbor\n")
4245 {
4246 int idx_peer = 2;
4247
4248 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4249 bgp_node_afi(vty), bgp_node_safi(vty),
4250 PEER_FLAG_SEND_COMMUNITY);
4251 }
4252
4253 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4254 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4255 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4256 "Send Community attribute to this neighbor\n")
4257
4258 /* neighbor send-community extended. */
4259 DEFUN (neighbor_send_community_type,
4260 neighbor_send_community_type_cmd,
4261 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4262 NEIGHBOR_STR
4263 NEIGHBOR_ADDR_STR2
4264 "Send Community attribute to this neighbor\n"
4265 "Send Standard and Extended Community attributes\n"
4266 "Send Standard, Large and Extended Community attributes\n"
4267 "Send Extended Community attributes\n"
4268 "Send Standard Community attributes\n"
4269 "Send Large Community attributes\n")
4270 {
4271 int idx_peer = 1;
4272 uint32_t flag = 0;
4273 const char *type = argv[argc - 1]->text;
4274
4275 if (strmatch(type, "standard")) {
4276 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4277 } else if (strmatch(type, "extended")) {
4278 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4279 } else if (strmatch(type, "large")) {
4280 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4281 } else if (strmatch(type, "both")) {
4282 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4283 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4284 } else { /* if (strmatch(type, "all")) */
4285 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4286 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4287 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4288 }
4289
4290 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4291 bgp_node_safi(vty), flag);
4292 }
4293
4294 ALIAS_HIDDEN(
4295 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4296 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4297 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4298 "Send Community attribute to this neighbor\n"
4299 "Send Standard and Extended Community attributes\n"
4300 "Send Standard, Large and Extended Community attributes\n"
4301 "Send Extended Community attributes\n"
4302 "Send Standard Community attributes\n"
4303 "Send Large Community attributes\n")
4304
4305 DEFUN (no_neighbor_send_community_type,
4306 no_neighbor_send_community_type_cmd,
4307 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4308 NO_STR
4309 NEIGHBOR_STR
4310 NEIGHBOR_ADDR_STR2
4311 "Send Community attribute to this neighbor\n"
4312 "Send Standard and Extended Community attributes\n"
4313 "Send Standard, Large and Extended Community attributes\n"
4314 "Send Extended Community attributes\n"
4315 "Send Standard Community attributes\n"
4316 "Send Large Community attributes\n")
4317 {
4318 int idx_peer = 2;
4319 uint32_t flag = 0;
4320 const char *type = argv[argc - 1]->text;
4321
4322 if (strmatch(type, "standard")) {
4323 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4324 } else if (strmatch(type, "extended")) {
4325 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4326 } else if (strmatch(type, "large")) {
4327 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4328 } else if (strmatch(type, "both")) {
4329 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4330 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4331 } else { /* if (strmatch(type, "all")) */
4332 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4333 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4334 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4335 }
4336
4337 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4338 bgp_node_afi(vty), bgp_node_safi(vty),
4339 flag);
4340 }
4341
4342 ALIAS_HIDDEN(
4343 no_neighbor_send_community_type,
4344 no_neighbor_send_community_type_hidden_cmd,
4345 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4346 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4347 "Send Community attribute to this neighbor\n"
4348 "Send Standard and Extended Community attributes\n"
4349 "Send Standard, Large and Extended Community attributes\n"
4350 "Send Extended Community attributes\n"
4351 "Send Standard Community attributes\n"
4352 "Send Large Community attributes\n")
4353
4354 /* neighbor soft-reconfig. */
4355 DEFUN (neighbor_soft_reconfiguration,
4356 neighbor_soft_reconfiguration_cmd,
4357 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4358 NEIGHBOR_STR
4359 NEIGHBOR_ADDR_STR2
4360 "Per neighbor soft reconfiguration\n"
4361 "Allow inbound soft reconfiguration for this neighbor\n")
4362 {
4363 int idx_peer = 1;
4364 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4365 bgp_node_safi(vty),
4366 PEER_FLAG_SOFT_RECONFIG);
4367 }
4368
4369 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4370 neighbor_soft_reconfiguration_hidden_cmd,
4371 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4372 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4373 "Per neighbor soft reconfiguration\n"
4374 "Allow inbound soft reconfiguration for this neighbor\n")
4375
4376 DEFUN (no_neighbor_soft_reconfiguration,
4377 no_neighbor_soft_reconfiguration_cmd,
4378 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4379 NO_STR
4380 NEIGHBOR_STR
4381 NEIGHBOR_ADDR_STR2
4382 "Per neighbor soft reconfiguration\n"
4383 "Allow inbound soft reconfiguration for this neighbor\n")
4384 {
4385 int idx_peer = 2;
4386 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4387 bgp_node_afi(vty), bgp_node_safi(vty),
4388 PEER_FLAG_SOFT_RECONFIG);
4389 }
4390
4391 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4392 no_neighbor_soft_reconfiguration_hidden_cmd,
4393 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4394 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4395 "Per neighbor soft reconfiguration\n"
4396 "Allow inbound soft reconfiguration for this neighbor\n")
4397
4398 DEFUN (neighbor_route_reflector_client,
4399 neighbor_route_reflector_client_cmd,
4400 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4401 NEIGHBOR_STR
4402 NEIGHBOR_ADDR_STR2
4403 "Configure a neighbor as Route Reflector client\n")
4404 {
4405 int idx_peer = 1;
4406 struct peer *peer;
4407
4408
4409 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4410 if (!peer)
4411 return CMD_WARNING_CONFIG_FAILED;
4412
4413 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4414 bgp_node_safi(vty),
4415 PEER_FLAG_REFLECTOR_CLIENT);
4416 }
4417
4418 ALIAS_HIDDEN(neighbor_route_reflector_client,
4419 neighbor_route_reflector_client_hidden_cmd,
4420 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4421 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4422 "Configure a neighbor as Route Reflector client\n")
4423
4424 DEFUN (no_neighbor_route_reflector_client,
4425 no_neighbor_route_reflector_client_cmd,
4426 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4427 NO_STR
4428 NEIGHBOR_STR
4429 NEIGHBOR_ADDR_STR2
4430 "Configure a neighbor as Route Reflector client\n")
4431 {
4432 int idx_peer = 2;
4433 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4434 bgp_node_afi(vty), bgp_node_safi(vty),
4435 PEER_FLAG_REFLECTOR_CLIENT);
4436 }
4437
4438 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4439 no_neighbor_route_reflector_client_hidden_cmd,
4440 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4441 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4442 "Configure a neighbor as Route Reflector client\n")
4443
4444 /* neighbor route-server-client. */
4445 DEFUN (neighbor_route_server_client,
4446 neighbor_route_server_client_cmd,
4447 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4448 NEIGHBOR_STR
4449 NEIGHBOR_ADDR_STR2
4450 "Configure a neighbor as Route Server client\n")
4451 {
4452 int idx_peer = 1;
4453 struct peer *peer;
4454
4455 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4456 if (!peer)
4457 return CMD_WARNING_CONFIG_FAILED;
4458 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4459 bgp_node_safi(vty),
4460 PEER_FLAG_RSERVER_CLIENT);
4461 }
4462
4463 ALIAS_HIDDEN(neighbor_route_server_client,
4464 neighbor_route_server_client_hidden_cmd,
4465 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4466 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4467 "Configure a neighbor as Route Server client\n")
4468
4469 DEFUN (no_neighbor_route_server_client,
4470 no_neighbor_route_server_client_cmd,
4471 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4472 NO_STR
4473 NEIGHBOR_STR
4474 NEIGHBOR_ADDR_STR2
4475 "Configure a neighbor as Route Server client\n")
4476 {
4477 int idx_peer = 2;
4478 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4479 bgp_node_afi(vty), bgp_node_safi(vty),
4480 PEER_FLAG_RSERVER_CLIENT);
4481 }
4482
4483 ALIAS_HIDDEN(no_neighbor_route_server_client,
4484 no_neighbor_route_server_client_hidden_cmd,
4485 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4486 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4487 "Configure a neighbor as Route Server client\n")
4488
4489 DEFUN (neighbor_nexthop_local_unchanged,
4490 neighbor_nexthop_local_unchanged_cmd,
4491 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4492 NEIGHBOR_STR
4493 NEIGHBOR_ADDR_STR2
4494 "Configure treatment of outgoing link-local nexthop attribute\n"
4495 "Leave link-local nexthop unchanged for this peer\n")
4496 {
4497 int idx_peer = 1;
4498 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4499 bgp_node_safi(vty),
4500 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4501 }
4502
4503 DEFUN (no_neighbor_nexthop_local_unchanged,
4504 no_neighbor_nexthop_local_unchanged_cmd,
4505 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4506 NO_STR
4507 NEIGHBOR_STR
4508 NEIGHBOR_ADDR_STR2
4509 "Configure treatment of outgoing link-local-nexthop attribute\n"
4510 "Leave link-local nexthop unchanged for this peer\n")
4511 {
4512 int idx_peer = 2;
4513 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4514 bgp_node_afi(vty), bgp_node_safi(vty),
4515 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4516 }
4517
4518 DEFUN (neighbor_attr_unchanged,
4519 neighbor_attr_unchanged_cmd,
4520 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
4523 "BGP attribute is propagated unchanged to this neighbor\n"
4524 "As-path attribute\n"
4525 "Nexthop attribute\n"
4526 "Med attribute\n")
4527 {
4528 int idx = 0;
4529 char *peer_str = argv[1]->arg;
4530 struct peer *peer;
4531 uint16_t flags = 0;
4532 afi_t afi = bgp_node_afi(vty);
4533 safi_t safi = bgp_node_safi(vty);
4534
4535 peer = peer_and_group_lookup_vty(vty, peer_str);
4536 if (!peer)
4537 return CMD_WARNING_CONFIG_FAILED;
4538
4539 if (argv_find(argv, argc, "as-path", &idx))
4540 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4541 idx = 0;
4542 if (argv_find(argv, argc, "next-hop", &idx))
4543 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4544 idx = 0;
4545 if (argv_find(argv, argc, "med", &idx))
4546 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4547
4548 /* no flags means all of them! */
4549 if (!flags) {
4550 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4551 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4552 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4553 } else {
4554 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4555 && peer_af_flag_check(peer, afi, safi,
4556 PEER_FLAG_AS_PATH_UNCHANGED)) {
4557 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4558 PEER_FLAG_AS_PATH_UNCHANGED);
4559 }
4560
4561 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4562 && peer_af_flag_check(peer, afi, safi,
4563 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4564 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4565 PEER_FLAG_NEXTHOP_UNCHANGED);
4566 }
4567
4568 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4569 && peer_af_flag_check(peer, afi, safi,
4570 PEER_FLAG_MED_UNCHANGED)) {
4571 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4572 PEER_FLAG_MED_UNCHANGED);
4573 }
4574 }
4575
4576 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4577 }
4578
4579 ALIAS_HIDDEN(
4580 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4581 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4582 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4583 "BGP attribute is propagated unchanged to this neighbor\n"
4584 "As-path attribute\n"
4585 "Nexthop attribute\n"
4586 "Med attribute\n")
4587
4588 DEFUN (no_neighbor_attr_unchanged,
4589 no_neighbor_attr_unchanged_cmd,
4590 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4591 NO_STR
4592 NEIGHBOR_STR
4593 NEIGHBOR_ADDR_STR2
4594 "BGP attribute is propagated unchanged to this neighbor\n"
4595 "As-path attribute\n"
4596 "Nexthop attribute\n"
4597 "Med attribute\n")
4598 {
4599 int idx = 0;
4600 char *peer = argv[2]->arg;
4601 uint16_t flags = 0;
4602
4603 if (argv_find(argv, argc, "as-path", &idx))
4604 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4605 idx = 0;
4606 if (argv_find(argv, argc, "next-hop", &idx))
4607 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4608 idx = 0;
4609 if (argv_find(argv, argc, "med", &idx))
4610 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4611
4612 if (!flags) // no flags means all of them!
4613 {
4614 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4615 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4616 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4617 }
4618
4619 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4620 bgp_node_safi(vty), flags);
4621 }
4622
4623 ALIAS_HIDDEN(
4624 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4625 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4626 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4627 "BGP attribute is propagated unchanged to this neighbor\n"
4628 "As-path attribute\n"
4629 "Nexthop attribute\n"
4630 "Med attribute\n")
4631
4632 /* EBGP multihop configuration. */
4633 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4634 const char *ttl_str)
4635 {
4636 struct peer *peer;
4637 unsigned int ttl;
4638
4639 peer = peer_and_group_lookup_vty(vty, ip_str);
4640 if (!peer)
4641 return CMD_WARNING_CONFIG_FAILED;
4642
4643 if (peer->conf_if)
4644 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4645
4646 if (!ttl_str)
4647 ttl = MAXTTL;
4648 else
4649 ttl = strtoul(ttl_str, NULL, 10);
4650
4651 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4652 }
4653
4654 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4655 {
4656 struct peer *peer;
4657
4658 peer = peer_and_group_lookup_vty(vty, ip_str);
4659 if (!peer)
4660 return CMD_WARNING_CONFIG_FAILED;
4661
4662 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4663 }
4664
4665 /* neighbor ebgp-multihop. */
4666 DEFUN (neighbor_ebgp_multihop,
4667 neighbor_ebgp_multihop_cmd,
4668 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4669 NEIGHBOR_STR
4670 NEIGHBOR_ADDR_STR2
4671 "Allow EBGP neighbors not on directly connected networks\n")
4672 {
4673 int idx_peer = 1;
4674 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4675 }
4676
4677 DEFUN (neighbor_ebgp_multihop_ttl,
4678 neighbor_ebgp_multihop_ttl_cmd,
4679 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4680 NEIGHBOR_STR
4681 NEIGHBOR_ADDR_STR2
4682 "Allow EBGP neighbors not on directly connected networks\n"
4683 "maximum hop count\n")
4684 {
4685 int idx_peer = 1;
4686 int idx_number = 3;
4687 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4688 argv[idx_number]->arg);
4689 }
4690
4691 DEFUN (no_neighbor_ebgp_multihop,
4692 no_neighbor_ebgp_multihop_cmd,
4693 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4694 NO_STR
4695 NEIGHBOR_STR
4696 NEIGHBOR_ADDR_STR2
4697 "Allow EBGP neighbors not on directly connected networks\n"
4698 "maximum hop count\n")
4699 {
4700 int idx_peer = 2;
4701 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4702 }
4703
4704
4705 /* disable-connected-check */
4706 DEFUN (neighbor_disable_connected_check,
4707 neighbor_disable_connected_check_cmd,
4708 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
4711 "one-hop away EBGP peer using loopback address\n"
4712 "Enforce EBGP neighbors perform multihop\n")
4713 {
4714 int idx_peer = 1;
4715 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4716 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4717 }
4718
4719 DEFUN (no_neighbor_disable_connected_check,
4720 no_neighbor_disable_connected_check_cmd,
4721 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4722 NO_STR
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "one-hop away EBGP peer using loopback address\n"
4726 "Enforce EBGP neighbors perform multihop\n")
4727 {
4728 int idx_peer = 2;
4729 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4730 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4731 }
4732
4733
4734 /* enforce-first-as */
4735 DEFUN (neighbor_enforce_first_as,
4736 neighbor_enforce_first_as_cmd,
4737 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4738 NEIGHBOR_STR
4739 NEIGHBOR_ADDR_STR2
4740 "Enforce the first AS for EBGP routes\n")
4741 {
4742 int idx_peer = 1;
4743
4744 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4745 PEER_FLAG_ENFORCE_FIRST_AS);
4746 }
4747
4748 DEFUN (no_neighbor_enforce_first_as,
4749 no_neighbor_enforce_first_as_cmd,
4750 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4751 NO_STR
4752 NEIGHBOR_STR
4753 NEIGHBOR_ADDR_STR2
4754 "Enforce the first AS for EBGP routes\n")
4755 {
4756 int idx_peer = 2;
4757
4758 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4759 PEER_FLAG_ENFORCE_FIRST_AS);
4760 }
4761
4762
4763 DEFUN (neighbor_description,
4764 neighbor_description_cmd,
4765 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4766 NEIGHBOR_STR
4767 NEIGHBOR_ADDR_STR2
4768 "Neighbor specific description\n"
4769 "Up to 80 characters describing this neighbor\n")
4770 {
4771 int idx_peer = 1;
4772 int idx_line = 3;
4773 struct peer *peer;
4774 char *str;
4775
4776 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4777 if (!peer)
4778 return CMD_WARNING_CONFIG_FAILED;
4779
4780 str = argv_concat(argv, argc, idx_line);
4781
4782 peer_description_set(peer, str);
4783
4784 XFREE(MTYPE_TMP, str);
4785
4786 return CMD_SUCCESS;
4787 }
4788
4789 DEFUN (no_neighbor_description,
4790 no_neighbor_description_cmd,
4791 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4792 NO_STR
4793 NEIGHBOR_STR
4794 NEIGHBOR_ADDR_STR2
4795 "Neighbor specific description\n")
4796 {
4797 int idx_peer = 2;
4798 struct peer *peer;
4799
4800 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4801 if (!peer)
4802 return CMD_WARNING_CONFIG_FAILED;
4803
4804 peer_description_unset(peer);
4805
4806 return CMD_SUCCESS;
4807 }
4808
4809 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4810 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4811 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4812 "Neighbor specific description\n"
4813 "Up to 80 characters describing this neighbor\n")
4814
4815 /* Neighbor update-source. */
4816 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4817 const char *source_str)
4818 {
4819 struct peer *peer;
4820 struct prefix p;
4821 union sockunion su;
4822
4823 peer = peer_and_group_lookup_vty(vty, peer_str);
4824 if (!peer)
4825 return CMD_WARNING_CONFIG_FAILED;
4826
4827 if (peer->conf_if)
4828 return CMD_WARNING;
4829
4830 if (source_str) {
4831 if (str2sockunion(source_str, &su) == 0)
4832 peer_update_source_addr_set(peer, &su);
4833 else {
4834 if (str2prefix(source_str, &p)) {
4835 vty_out(vty,
4836 "%% Invalid update-source, remove prefix length \n");
4837 return CMD_WARNING_CONFIG_FAILED;
4838 } else
4839 peer_update_source_if_set(peer, source_str);
4840 }
4841 } else
4842 peer_update_source_unset(peer);
4843
4844 return CMD_SUCCESS;
4845 }
4846
4847 #define BGP_UPDATE_SOURCE_HELP_STR \
4848 "IPv4 address\n" \
4849 "IPv6 address\n" \
4850 "Interface name (requires zebra to be running)\n"
4851
4852 DEFUN (neighbor_update_source,
4853 neighbor_update_source_cmd,
4854 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4855 NEIGHBOR_STR
4856 NEIGHBOR_ADDR_STR2
4857 "Source of routing updates\n"
4858 BGP_UPDATE_SOURCE_HELP_STR)
4859 {
4860 int idx_peer = 1;
4861 int idx_peer_2 = 3;
4862 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4863 argv[idx_peer_2]->arg);
4864 }
4865
4866 DEFUN (no_neighbor_update_source,
4867 no_neighbor_update_source_cmd,
4868 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4869 NO_STR
4870 NEIGHBOR_STR
4871 NEIGHBOR_ADDR_STR2
4872 "Source of routing updates\n"
4873 BGP_UPDATE_SOURCE_HELP_STR)
4874 {
4875 int idx_peer = 2;
4876 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4877 }
4878
4879 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4880 afi_t afi, safi_t safi,
4881 const char *rmap, int set)
4882 {
4883 int ret;
4884 struct peer *peer;
4885 struct route_map *route_map;
4886
4887 peer = peer_and_group_lookup_vty(vty, peer_str);
4888 if (!peer)
4889 return CMD_WARNING_CONFIG_FAILED;
4890
4891 if (set) {
4892 route_map = route_map_lookup_warn_noexist(vty, rmap);
4893 ret = peer_default_originate_set(peer, afi, safi,
4894 rmap, route_map);
4895 } else
4896 ret = peer_default_originate_unset(peer, afi, safi);
4897
4898 return bgp_vty_return(vty, ret);
4899 }
4900
4901 /* neighbor default-originate. */
4902 DEFUN (neighbor_default_originate,
4903 neighbor_default_originate_cmd,
4904 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4905 NEIGHBOR_STR
4906 NEIGHBOR_ADDR_STR2
4907 "Originate default route to this neighbor\n")
4908 {
4909 int idx_peer = 1;
4910 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4911 bgp_node_afi(vty),
4912 bgp_node_safi(vty), NULL, 1);
4913 }
4914
4915 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4916 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4917 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4918 "Originate default route to this neighbor\n")
4919
4920 DEFUN (neighbor_default_originate_rmap,
4921 neighbor_default_originate_rmap_cmd,
4922 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4923 NEIGHBOR_STR
4924 NEIGHBOR_ADDR_STR2
4925 "Originate default route to this neighbor\n"
4926 "Route-map to specify criteria to originate default\n"
4927 "route-map name\n")
4928 {
4929 int idx_peer = 1;
4930 int idx_word = 4;
4931 return peer_default_originate_set_vty(
4932 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4933 argv[idx_word]->arg, 1);
4934 }
4935
4936 ALIAS_HIDDEN(
4937 neighbor_default_originate_rmap,
4938 neighbor_default_originate_rmap_hidden_cmd,
4939 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4941 "Originate default route to this neighbor\n"
4942 "Route-map to specify criteria to originate default\n"
4943 "route-map name\n")
4944
4945 DEFUN (no_neighbor_default_originate,
4946 no_neighbor_default_originate_cmd,
4947 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4948 NO_STR
4949 NEIGHBOR_STR
4950 NEIGHBOR_ADDR_STR2
4951 "Originate default route to this neighbor\n"
4952 "Route-map to specify criteria to originate default\n"
4953 "route-map name\n")
4954 {
4955 int idx_peer = 2;
4956 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4957 bgp_node_afi(vty),
4958 bgp_node_safi(vty), NULL, 0);
4959 }
4960
4961 ALIAS_HIDDEN(
4962 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4963 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4964 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4965 "Originate default route to this neighbor\n"
4966 "Route-map to specify criteria to originate default\n"
4967 "route-map name\n")
4968
4969
4970 /* Set neighbor's BGP port. */
4971 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4972 const char *port_str)
4973 {
4974 struct peer *peer;
4975 uint16_t port;
4976 struct servent *sp;
4977
4978 peer = peer_lookup_vty(vty, ip_str);
4979 if (!peer)
4980 return CMD_WARNING_CONFIG_FAILED;
4981
4982 if (!port_str) {
4983 sp = getservbyname("bgp", "tcp");
4984 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4985 } else {
4986 port = strtoul(port_str, NULL, 10);
4987 }
4988
4989 peer_port_set(peer, port);
4990
4991 return CMD_SUCCESS;
4992 }
4993
4994 /* Set specified peer's BGP port. */
4995 DEFUN (neighbor_port,
4996 neighbor_port_cmd,
4997 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4998 NEIGHBOR_STR
4999 NEIGHBOR_ADDR_STR
5000 "Neighbor's BGP port\n"
5001 "TCP port number\n")
5002 {
5003 int idx_ip = 1;
5004 int idx_number = 3;
5005 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5006 argv[idx_number]->arg);
5007 }
5008
5009 DEFUN (no_neighbor_port,
5010 no_neighbor_port_cmd,
5011 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5012 NO_STR
5013 NEIGHBOR_STR
5014 NEIGHBOR_ADDR_STR
5015 "Neighbor's BGP port\n"
5016 "TCP port number\n")
5017 {
5018 int idx_ip = 2;
5019 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5020 }
5021
5022
5023 /* neighbor weight. */
5024 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5025 safi_t safi, const char *weight_str)
5026 {
5027 int ret;
5028 struct peer *peer;
5029 unsigned long weight;
5030
5031 peer = peer_and_group_lookup_vty(vty, ip_str);
5032 if (!peer)
5033 return CMD_WARNING_CONFIG_FAILED;
5034
5035 weight = strtoul(weight_str, NULL, 10);
5036
5037 ret = peer_weight_set(peer, afi, safi, weight);
5038 return bgp_vty_return(vty, ret);
5039 }
5040
5041 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5042 safi_t safi)
5043 {
5044 int ret;
5045 struct peer *peer;
5046
5047 peer = peer_and_group_lookup_vty(vty, ip_str);
5048 if (!peer)
5049 return CMD_WARNING_CONFIG_FAILED;
5050
5051 ret = peer_weight_unset(peer, afi, safi);
5052 return bgp_vty_return(vty, ret);
5053 }
5054
5055 DEFUN (neighbor_weight,
5056 neighbor_weight_cmd,
5057 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5058 NEIGHBOR_STR
5059 NEIGHBOR_ADDR_STR2
5060 "Set default weight for routes from this neighbor\n"
5061 "default weight\n")
5062 {
5063 int idx_peer = 1;
5064 int idx_number = 3;
5065 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5066 bgp_node_safi(vty), argv[idx_number]->arg);
5067 }
5068
5069 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5070 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5071 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5072 "Set default weight for routes from this neighbor\n"
5073 "default weight\n")
5074
5075 DEFUN (no_neighbor_weight,
5076 no_neighbor_weight_cmd,
5077 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5078 NO_STR
5079 NEIGHBOR_STR
5080 NEIGHBOR_ADDR_STR2
5081 "Set default weight for routes from this neighbor\n"
5082 "default weight\n")
5083 {
5084 int idx_peer = 2;
5085 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5086 bgp_node_afi(vty), bgp_node_safi(vty));
5087 }
5088
5089 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5090 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5091 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5092 "Set default weight for routes from this neighbor\n"
5093 "default weight\n")
5094
5095
5096 /* Override capability negotiation. */
5097 DEFUN (neighbor_override_capability,
5098 neighbor_override_capability_cmd,
5099 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5100 NEIGHBOR_STR
5101 NEIGHBOR_ADDR_STR2
5102 "Override capability negotiation result\n")
5103 {
5104 int idx_peer = 1;
5105 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5106 PEER_FLAG_OVERRIDE_CAPABILITY);
5107 }
5108
5109 DEFUN (no_neighbor_override_capability,
5110 no_neighbor_override_capability_cmd,
5111 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5112 NO_STR
5113 NEIGHBOR_STR
5114 NEIGHBOR_ADDR_STR2
5115 "Override capability negotiation result\n")
5116 {
5117 int idx_peer = 2;
5118 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5119 PEER_FLAG_OVERRIDE_CAPABILITY);
5120 }
5121
5122 DEFUN (neighbor_strict_capability,
5123 neighbor_strict_capability_cmd,
5124 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5125 NEIGHBOR_STR
5126 NEIGHBOR_ADDR_STR2
5127 "Strict capability negotiation match\n")
5128 {
5129 int idx_peer = 1;
5130
5131 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5132 PEER_FLAG_STRICT_CAP_MATCH);
5133 }
5134
5135 DEFUN (no_neighbor_strict_capability,
5136 no_neighbor_strict_capability_cmd,
5137 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5138 NO_STR
5139 NEIGHBOR_STR
5140 NEIGHBOR_ADDR_STR2
5141 "Strict capability negotiation match\n")
5142 {
5143 int idx_peer = 2;
5144
5145 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5146 PEER_FLAG_STRICT_CAP_MATCH);
5147 }
5148
5149 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5150 const char *keep_str, const char *hold_str)
5151 {
5152 int ret;
5153 struct peer *peer;
5154 uint32_t keepalive;
5155 uint32_t holdtime;
5156
5157 peer = peer_and_group_lookup_vty(vty, ip_str);
5158 if (!peer)
5159 return CMD_WARNING_CONFIG_FAILED;
5160
5161 keepalive = strtoul(keep_str, NULL, 10);
5162 holdtime = strtoul(hold_str, NULL, 10);
5163
5164 ret = peer_timers_set(peer, keepalive, holdtime);
5165
5166 return bgp_vty_return(vty, ret);
5167 }
5168
5169 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5170 {
5171 int ret;
5172 struct peer *peer;
5173
5174 peer = peer_and_group_lookup_vty(vty, ip_str);
5175 if (!peer)
5176 return CMD_WARNING_CONFIG_FAILED;
5177
5178 ret = peer_timers_unset(peer);
5179
5180 return bgp_vty_return(vty, ret);
5181 }
5182
5183 DEFUN (neighbor_timers,
5184 neighbor_timers_cmd,
5185 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5186 NEIGHBOR_STR
5187 NEIGHBOR_ADDR_STR2
5188 "BGP per neighbor timers\n"
5189 "Keepalive interval\n"
5190 "Holdtime\n")
5191 {
5192 int idx_peer = 1;
5193 int idx_number = 3;
5194 int idx_number_2 = 4;
5195 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5196 argv[idx_number]->arg,
5197 argv[idx_number_2]->arg);
5198 }
5199
5200 DEFUN (no_neighbor_timers,
5201 no_neighbor_timers_cmd,
5202 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5203 NO_STR
5204 NEIGHBOR_STR
5205 NEIGHBOR_ADDR_STR2
5206 "BGP per neighbor timers\n"
5207 "Keepalive interval\n"
5208 "Holdtime\n")
5209 {
5210 int idx_peer = 2;
5211 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5212 }
5213
5214
5215 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5216 const char *time_str)
5217 {
5218 int ret;
5219 struct peer *peer;
5220 uint32_t connect;
5221
5222 peer = peer_and_group_lookup_vty(vty, ip_str);
5223 if (!peer)
5224 return CMD_WARNING_CONFIG_FAILED;
5225
5226 connect = strtoul(time_str, NULL, 10);
5227
5228 ret = peer_timers_connect_set(peer, connect);
5229
5230 return bgp_vty_return(vty, ret);
5231 }
5232
5233 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5234 {
5235 int ret;
5236 struct peer *peer;
5237
5238 peer = peer_and_group_lookup_vty(vty, ip_str);
5239 if (!peer)
5240 return CMD_WARNING_CONFIG_FAILED;
5241
5242 ret = peer_timers_connect_unset(peer);
5243
5244 return bgp_vty_return(vty, ret);
5245 }
5246
5247 DEFUN (neighbor_timers_connect,
5248 neighbor_timers_connect_cmd,
5249 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5250 NEIGHBOR_STR
5251 NEIGHBOR_ADDR_STR2
5252 "BGP per neighbor timers\n"
5253 "BGP connect timer\n"
5254 "Connect timer\n")
5255 {
5256 int idx_peer = 1;
5257 int idx_number = 4;
5258 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5259 argv[idx_number]->arg);
5260 }
5261
5262 DEFUN (no_neighbor_timers_connect,
5263 no_neighbor_timers_connect_cmd,
5264 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5265 NO_STR
5266 NEIGHBOR_STR
5267 NEIGHBOR_ADDR_STR2
5268 "BGP per neighbor timers\n"
5269 "BGP connect timer\n"
5270 "Connect timer\n")
5271 {
5272 int idx_peer = 2;
5273 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5274 }
5275
5276
5277 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5278 const char *time_str, int set)
5279 {
5280 int ret;
5281 struct peer *peer;
5282 uint32_t routeadv = 0;
5283
5284 peer = peer_and_group_lookup_vty(vty, ip_str);
5285 if (!peer)
5286 return CMD_WARNING_CONFIG_FAILED;
5287
5288 if (time_str)
5289 routeadv = strtoul(time_str, NULL, 10);
5290
5291 if (set)
5292 ret = peer_advertise_interval_set(peer, routeadv);
5293 else
5294 ret = peer_advertise_interval_unset(peer);
5295
5296 return bgp_vty_return(vty, ret);
5297 }
5298
5299 DEFUN (neighbor_advertise_interval,
5300 neighbor_advertise_interval_cmd,
5301 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5302 NEIGHBOR_STR
5303 NEIGHBOR_ADDR_STR2
5304 "Minimum interval between sending BGP routing updates\n"
5305 "time in seconds\n")
5306 {
5307 int idx_peer = 1;
5308 int idx_number = 3;
5309 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5310 argv[idx_number]->arg, 1);
5311 }
5312
5313 DEFUN (no_neighbor_advertise_interval,
5314 no_neighbor_advertise_interval_cmd,
5315 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5316 NO_STR
5317 NEIGHBOR_STR
5318 NEIGHBOR_ADDR_STR2
5319 "Minimum interval between sending BGP routing updates\n"
5320 "time in seconds\n")
5321 {
5322 int idx_peer = 2;
5323 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5324 }
5325
5326
5327 /* Time to wait before processing route-map updates */
5328 DEFUN (bgp_set_route_map_delay_timer,
5329 bgp_set_route_map_delay_timer_cmd,
5330 "bgp route-map delay-timer (0-600)",
5331 SET_STR
5332 "BGP route-map delay timer\n"
5333 "Time in secs to wait before processing route-map changes\n"
5334 "0 disables the timer, no route updates happen when route-maps change\n")
5335 {
5336 int idx_number = 3;
5337 uint32_t rmap_delay_timer;
5338
5339 if (argv[idx_number]->arg) {
5340 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5341 bm->rmap_update_timer = rmap_delay_timer;
5342
5343 /* if the dynamic update handling is being disabled, and a timer
5344 * is
5345 * running, stop the timer and act as if the timer has already
5346 * fired.
5347 */
5348 if (!rmap_delay_timer && bm->t_rmap_update) {
5349 BGP_TIMER_OFF(bm->t_rmap_update);
5350 thread_execute(bm->master, bgp_route_map_update_timer,
5351 NULL, 0);
5352 }
5353 return CMD_SUCCESS;
5354 } else {
5355 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5356 return CMD_WARNING_CONFIG_FAILED;
5357 }
5358 }
5359
5360 DEFUN (no_bgp_set_route_map_delay_timer,
5361 no_bgp_set_route_map_delay_timer_cmd,
5362 "no bgp route-map delay-timer [(0-600)]",
5363 NO_STR
5364 BGP_STR
5365 "Default BGP route-map delay timer\n"
5366 "Reset to default time to wait for processing route-map changes\n"
5367 "0 disables the timer, no route updates happen when route-maps change\n")
5368 {
5369
5370 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5371
5372 return CMD_SUCCESS;
5373 }
5374
5375
5376 /* neighbor interface */
5377 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5378 const char *str)
5379 {
5380 struct peer *peer;
5381
5382 peer = peer_lookup_vty(vty, ip_str);
5383 if (!peer || peer->conf_if) {
5384 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5385 return CMD_WARNING_CONFIG_FAILED;
5386 }
5387
5388 if (str)
5389 peer_interface_set(peer, str);
5390 else
5391 peer_interface_unset(peer);
5392
5393 return CMD_SUCCESS;
5394 }
5395
5396 DEFUN (neighbor_interface,
5397 neighbor_interface_cmd,
5398 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5399 NEIGHBOR_STR
5400 NEIGHBOR_ADDR_STR
5401 "Interface\n"
5402 "Interface name\n")
5403 {
5404 int idx_ip = 1;
5405 int idx_word = 3;
5406 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5407 }
5408
5409 DEFUN (no_neighbor_interface,
5410 no_neighbor_interface_cmd,
5411 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5412 NO_STR
5413 NEIGHBOR_STR
5414 NEIGHBOR_ADDR_STR2
5415 "Interface\n"
5416 "Interface name\n")
5417 {
5418 int idx_peer = 2;
5419 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5420 }
5421
5422 DEFUN (neighbor_distribute_list,
5423 neighbor_distribute_list_cmd,
5424 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5425 NEIGHBOR_STR
5426 NEIGHBOR_ADDR_STR2
5427 "Filter updates to/from this neighbor\n"
5428 "IP access-list number\n"
5429 "IP access-list number (expanded range)\n"
5430 "IP Access-list name\n"
5431 "Filter incoming updates\n"
5432 "Filter outgoing updates\n")
5433 {
5434 int idx_peer = 1;
5435 int idx_acl = 3;
5436 int direct, ret;
5437 struct peer *peer;
5438
5439 const char *pstr = argv[idx_peer]->arg;
5440 const char *acl = argv[idx_acl]->arg;
5441 const char *inout = argv[argc - 1]->text;
5442
5443 peer = peer_and_group_lookup_vty(vty, pstr);
5444 if (!peer)
5445 return CMD_WARNING_CONFIG_FAILED;
5446
5447 /* Check filter direction. */
5448 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5449 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5450 direct, acl);
5451
5452 return bgp_vty_return(vty, ret);
5453 }
5454
5455 ALIAS_HIDDEN(
5456 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5457 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5458 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5459 "Filter updates to/from this neighbor\n"
5460 "IP access-list number\n"
5461 "IP access-list number (expanded range)\n"
5462 "IP Access-list name\n"
5463 "Filter incoming updates\n"
5464 "Filter outgoing updates\n")
5465
5466 DEFUN (no_neighbor_distribute_list,
5467 no_neighbor_distribute_list_cmd,
5468 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5469 NO_STR
5470 NEIGHBOR_STR
5471 NEIGHBOR_ADDR_STR2
5472 "Filter updates to/from this neighbor\n"
5473 "IP access-list number\n"
5474 "IP access-list number (expanded range)\n"
5475 "IP Access-list name\n"
5476 "Filter incoming updates\n"
5477 "Filter outgoing updates\n")
5478 {
5479 int idx_peer = 2;
5480 int direct, ret;
5481 struct peer *peer;
5482
5483 const char *pstr = argv[idx_peer]->arg;
5484 const char *inout = argv[argc - 1]->text;
5485
5486 peer = peer_and_group_lookup_vty(vty, pstr);
5487 if (!peer)
5488 return CMD_WARNING_CONFIG_FAILED;
5489
5490 /* Check filter direction. */
5491 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5492 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5493 direct);
5494
5495 return bgp_vty_return(vty, ret);
5496 }
5497
5498 ALIAS_HIDDEN(
5499 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5500 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5501 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5502 "Filter updates to/from this neighbor\n"
5503 "IP access-list number\n"
5504 "IP access-list number (expanded range)\n"
5505 "IP Access-list name\n"
5506 "Filter incoming updates\n"
5507 "Filter outgoing updates\n")
5508
5509 /* Set prefix list to the peer. */
5510 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5511 afi_t afi, safi_t safi,
5512 const char *name_str,
5513 const char *direct_str)
5514 {
5515 int ret;
5516 int direct = FILTER_IN;
5517 struct peer *peer;
5518
5519 peer = peer_and_group_lookup_vty(vty, ip_str);
5520 if (!peer)
5521 return CMD_WARNING_CONFIG_FAILED;
5522
5523 /* Check filter direction. */
5524 if (strncmp(direct_str, "i", 1) == 0)
5525 direct = FILTER_IN;
5526 else if (strncmp(direct_str, "o", 1) == 0)
5527 direct = FILTER_OUT;
5528
5529 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5530
5531 return bgp_vty_return(vty, ret);
5532 }
5533
5534 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5535 afi_t afi, safi_t safi,
5536 const char *direct_str)
5537 {
5538 int ret;
5539 struct peer *peer;
5540 int direct = FILTER_IN;
5541
5542 peer = peer_and_group_lookup_vty(vty, ip_str);
5543 if (!peer)
5544 return CMD_WARNING_CONFIG_FAILED;
5545
5546 /* Check filter direction. */
5547 if (strncmp(direct_str, "i", 1) == 0)
5548 direct = FILTER_IN;
5549 else if (strncmp(direct_str, "o", 1) == 0)
5550 direct = FILTER_OUT;
5551
5552 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5553
5554 return bgp_vty_return(vty, ret);
5555 }
5556
5557 DEFUN (neighbor_prefix_list,
5558 neighbor_prefix_list_cmd,
5559 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5560 NEIGHBOR_STR
5561 NEIGHBOR_ADDR_STR2
5562 "Filter updates to/from this neighbor\n"
5563 "Name of a prefix list\n"
5564 "Filter incoming updates\n"
5565 "Filter outgoing updates\n")
5566 {
5567 int idx_peer = 1;
5568 int idx_word = 3;
5569 int idx_in_out = 4;
5570 return peer_prefix_list_set_vty(
5571 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5572 argv[idx_word]->arg, argv[idx_in_out]->arg);
5573 }
5574
5575 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5576 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5578 "Filter updates to/from this neighbor\n"
5579 "Name of a prefix list\n"
5580 "Filter incoming updates\n"
5581 "Filter outgoing updates\n")
5582
5583 DEFUN (no_neighbor_prefix_list,
5584 no_neighbor_prefix_list_cmd,
5585 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5586 NO_STR
5587 NEIGHBOR_STR
5588 NEIGHBOR_ADDR_STR2
5589 "Filter updates to/from this neighbor\n"
5590 "Name of a prefix list\n"
5591 "Filter incoming updates\n"
5592 "Filter outgoing updates\n")
5593 {
5594 int idx_peer = 2;
5595 int idx_in_out = 5;
5596 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5597 bgp_node_afi(vty), bgp_node_safi(vty),
5598 argv[idx_in_out]->arg);
5599 }
5600
5601 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5602 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5603 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5604 "Filter updates to/from this neighbor\n"
5605 "Name of a prefix list\n"
5606 "Filter incoming updates\n"
5607 "Filter outgoing updates\n")
5608
5609 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5610 safi_t safi, const char *name_str,
5611 const char *direct_str)
5612 {
5613 int ret;
5614 struct peer *peer;
5615 int direct = FILTER_IN;
5616
5617 peer = peer_and_group_lookup_vty(vty, ip_str);
5618 if (!peer)
5619 return CMD_WARNING_CONFIG_FAILED;
5620
5621 /* Check filter direction. */
5622 if (strncmp(direct_str, "i", 1) == 0)
5623 direct = FILTER_IN;
5624 else if (strncmp(direct_str, "o", 1) == 0)
5625 direct = FILTER_OUT;
5626
5627 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5628
5629 return bgp_vty_return(vty, ret);
5630 }
5631
5632 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5633 safi_t safi, const char *direct_str)
5634 {
5635 int ret;
5636 struct peer *peer;
5637 int direct = FILTER_IN;
5638
5639 peer = peer_and_group_lookup_vty(vty, ip_str);
5640 if (!peer)
5641 return CMD_WARNING_CONFIG_FAILED;
5642
5643 /* Check filter direction. */
5644 if (strncmp(direct_str, "i", 1) == 0)
5645 direct = FILTER_IN;
5646 else if (strncmp(direct_str, "o", 1) == 0)
5647 direct = FILTER_OUT;
5648
5649 ret = peer_aslist_unset(peer, afi, safi, direct);
5650
5651 return bgp_vty_return(vty, ret);
5652 }
5653
5654 DEFUN (neighbor_filter_list,
5655 neighbor_filter_list_cmd,
5656 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5657 NEIGHBOR_STR
5658 NEIGHBOR_ADDR_STR2
5659 "Establish BGP filters\n"
5660 "AS path access-list name\n"
5661 "Filter incoming routes\n"
5662 "Filter outgoing routes\n")
5663 {
5664 int idx_peer = 1;
5665 int idx_word = 3;
5666 int idx_in_out = 4;
5667 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5668 bgp_node_safi(vty), argv[idx_word]->arg,
5669 argv[idx_in_out]->arg);
5670 }
5671
5672 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5673 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5674 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5675 "Establish BGP filters\n"
5676 "AS path access-list name\n"
5677 "Filter incoming routes\n"
5678 "Filter outgoing routes\n")
5679
5680 DEFUN (no_neighbor_filter_list,
5681 no_neighbor_filter_list_cmd,
5682 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5683 NO_STR
5684 NEIGHBOR_STR
5685 NEIGHBOR_ADDR_STR2
5686 "Establish BGP filters\n"
5687 "AS path access-list name\n"
5688 "Filter incoming routes\n"
5689 "Filter outgoing routes\n")
5690 {
5691 int idx_peer = 2;
5692 int idx_in_out = 5;
5693 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5694 bgp_node_afi(vty), bgp_node_safi(vty),
5695 argv[idx_in_out]->arg);
5696 }
5697
5698 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5699 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5700 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5701 "Establish BGP filters\n"
5702 "AS path access-list name\n"
5703 "Filter incoming routes\n"
5704 "Filter outgoing routes\n")
5705
5706 /* Set route-map to the peer. */
5707 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5708 afi_t afi, safi_t safi, const char *name_str,
5709 const char *direct_str)
5710 {
5711 int ret;
5712 struct peer *peer;
5713 int direct = RMAP_IN;
5714 struct route_map *route_map;
5715
5716 peer = peer_and_group_lookup_vty(vty, ip_str);
5717 if (!peer)
5718 return CMD_WARNING_CONFIG_FAILED;
5719
5720 /* Check filter direction. */
5721 if (strncmp(direct_str, "in", 2) == 0)
5722 direct = RMAP_IN;
5723 else if (strncmp(direct_str, "o", 1) == 0)
5724 direct = RMAP_OUT;
5725
5726 route_map = route_map_lookup_warn_noexist(vty, name_str);
5727 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5728
5729 return bgp_vty_return(vty, ret);
5730 }
5731
5732 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5733 afi_t afi, safi_t safi,
5734 const char *direct_str)
5735 {
5736 int ret;
5737 struct peer *peer;
5738 int direct = RMAP_IN;
5739
5740 peer = peer_and_group_lookup_vty(vty, ip_str);
5741 if (!peer)
5742 return CMD_WARNING_CONFIG_FAILED;
5743
5744 /* Check filter direction. */
5745 if (strncmp(direct_str, "in", 2) == 0)
5746 direct = RMAP_IN;
5747 else if (strncmp(direct_str, "o", 1) == 0)
5748 direct = RMAP_OUT;
5749
5750 ret = peer_route_map_unset(peer, afi, safi, direct);
5751
5752 return bgp_vty_return(vty, ret);
5753 }
5754
5755 DEFUN (neighbor_route_map,
5756 neighbor_route_map_cmd,
5757 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5758 NEIGHBOR_STR
5759 NEIGHBOR_ADDR_STR2
5760 "Apply route map to neighbor\n"
5761 "Name of route map\n"
5762 "Apply map to incoming routes\n"
5763 "Apply map to outbound routes\n")
5764 {
5765 int idx_peer = 1;
5766 int idx_word = 3;
5767 int idx_in_out = 4;
5768 return peer_route_map_set_vty(
5769 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5770 argv[idx_word]->arg, argv[idx_in_out]->arg);
5771 }
5772
5773 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5774 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5775 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5776 "Apply route map to neighbor\n"
5777 "Name of route map\n"
5778 "Apply map to incoming routes\n"
5779 "Apply map to outbound routes\n")
5780
5781 DEFUN (no_neighbor_route_map,
5782 no_neighbor_route_map_cmd,
5783 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5784 NO_STR
5785 NEIGHBOR_STR
5786 NEIGHBOR_ADDR_STR2
5787 "Apply route map to neighbor\n"
5788 "Name of route map\n"
5789 "Apply map to incoming routes\n"
5790 "Apply map to outbound routes\n")
5791 {
5792 int idx_peer = 2;
5793 int idx_in_out = 5;
5794 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5795 bgp_node_afi(vty), bgp_node_safi(vty),
5796 argv[idx_in_out]->arg);
5797 }
5798
5799 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5800 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5801 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5802 "Apply route map to neighbor\n"
5803 "Name of route map\n"
5804 "Apply map to incoming routes\n"
5805 "Apply map to outbound routes\n")
5806
5807 /* Set unsuppress-map to the peer. */
5808 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5809 afi_t afi, safi_t safi,
5810 const char *name_str)
5811 {
5812 int ret;
5813 struct peer *peer;
5814 struct route_map *route_map;
5815
5816 peer = peer_and_group_lookup_vty(vty, ip_str);
5817 if (!peer)
5818 return CMD_WARNING_CONFIG_FAILED;
5819
5820 route_map = route_map_lookup_warn_noexist(vty, name_str);
5821 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5822
5823 return bgp_vty_return(vty, ret);
5824 }
5825
5826 /* Unset route-map from the peer. */
5827 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5828 afi_t afi, safi_t safi)
5829 {
5830 int ret;
5831 struct peer *peer;
5832
5833 peer = peer_and_group_lookup_vty(vty, ip_str);
5834 if (!peer)
5835 return CMD_WARNING_CONFIG_FAILED;
5836
5837 ret = peer_unsuppress_map_unset(peer, afi, safi);
5838
5839 return bgp_vty_return(vty, ret);
5840 }
5841
5842 DEFUN (neighbor_unsuppress_map,
5843 neighbor_unsuppress_map_cmd,
5844 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5845 NEIGHBOR_STR
5846 NEIGHBOR_ADDR_STR2
5847 "Route-map to selectively unsuppress suppressed routes\n"
5848 "Name of route map\n")
5849 {
5850 int idx_peer = 1;
5851 int idx_word = 3;
5852 return peer_unsuppress_map_set_vty(
5853 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5854 argv[idx_word]->arg);
5855 }
5856
5857 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5858 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5859 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5860 "Route-map to selectively unsuppress suppressed routes\n"
5861 "Name of route map\n")
5862
5863 DEFUN (no_neighbor_unsuppress_map,
5864 no_neighbor_unsuppress_map_cmd,
5865 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5866 NO_STR
5867 NEIGHBOR_STR
5868 NEIGHBOR_ADDR_STR2
5869 "Route-map to selectively unsuppress suppressed routes\n"
5870 "Name of route map\n")
5871 {
5872 int idx_peer = 2;
5873 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5874 bgp_node_afi(vty),
5875 bgp_node_safi(vty));
5876 }
5877
5878 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5879 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5880 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5881 "Route-map to selectively unsuppress suppressed routes\n"
5882 "Name of route map\n")
5883
5884 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5885 afi_t afi, safi_t safi,
5886 const char *num_str,
5887 const char *threshold_str, int warning,
5888 const char *restart_str)
5889 {
5890 int ret;
5891 struct peer *peer;
5892 uint32_t max;
5893 uint8_t threshold;
5894 uint16_t restart;
5895
5896 peer = peer_and_group_lookup_vty(vty, ip_str);
5897 if (!peer)
5898 return CMD_WARNING_CONFIG_FAILED;
5899
5900 max = strtoul(num_str, NULL, 10);
5901 if (threshold_str)
5902 threshold = atoi(threshold_str);
5903 else
5904 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5905
5906 if (restart_str)
5907 restart = atoi(restart_str);
5908 else
5909 restart = 0;
5910
5911 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5912 restart);
5913
5914 return bgp_vty_return(vty, ret);
5915 }
5916
5917 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5918 afi_t afi, safi_t safi)
5919 {
5920 int ret;
5921 struct peer *peer;
5922
5923 peer = peer_and_group_lookup_vty(vty, ip_str);
5924 if (!peer)
5925 return CMD_WARNING_CONFIG_FAILED;
5926
5927 ret = peer_maximum_prefix_unset(peer, afi, safi);
5928
5929 return bgp_vty_return(vty, ret);
5930 }
5931
5932 /* Maximum number of prefix configuration. prefix count is different
5933 for each peer configuration. So this configuration can be set for
5934 each peer configuration. */
5935 DEFUN (neighbor_maximum_prefix,
5936 neighbor_maximum_prefix_cmd,
5937 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5938 NEIGHBOR_STR
5939 NEIGHBOR_ADDR_STR2
5940 "Maximum number of prefix accept from this peer\n"
5941 "maximum no. of prefix limit\n")
5942 {
5943 int idx_peer = 1;
5944 int idx_number = 3;
5945 return peer_maximum_prefix_set_vty(
5946 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5947 argv[idx_number]->arg, NULL, 0, NULL);
5948 }
5949
5950 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5952 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5953 "Maximum number of prefix accept from this peer\n"
5954 "maximum no. of prefix limit\n")
5955
5956 DEFUN (neighbor_maximum_prefix_threshold,
5957 neighbor_maximum_prefix_threshold_cmd,
5958 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5959 NEIGHBOR_STR
5960 NEIGHBOR_ADDR_STR2
5961 "Maximum number of prefix accept from this peer\n"
5962 "maximum no. of prefix limit\n"
5963 "Threshold value (%) at which to generate a warning msg\n")
5964 {
5965 int idx_peer = 1;
5966 int idx_number = 3;
5967 int idx_number_2 = 4;
5968 return peer_maximum_prefix_set_vty(
5969 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5970 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5971 }
5972
5973 ALIAS_HIDDEN(
5974 neighbor_maximum_prefix_threshold,
5975 neighbor_maximum_prefix_threshold_hidden_cmd,
5976 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5977 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5978 "Maximum number of prefix accept from this peer\n"
5979 "maximum no. of prefix limit\n"
5980 "Threshold value (%) at which to generate a warning msg\n")
5981
5982 DEFUN (neighbor_maximum_prefix_warning,
5983 neighbor_maximum_prefix_warning_cmd,
5984 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5985 NEIGHBOR_STR
5986 NEIGHBOR_ADDR_STR2
5987 "Maximum number of prefix accept from this peer\n"
5988 "maximum no. of prefix limit\n"
5989 "Only give warning message when limit is exceeded\n")
5990 {
5991 int idx_peer = 1;
5992 int idx_number = 3;
5993 return peer_maximum_prefix_set_vty(
5994 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5995 argv[idx_number]->arg, NULL, 1, NULL);
5996 }
5997
5998 ALIAS_HIDDEN(
5999 neighbor_maximum_prefix_warning,
6000 neighbor_maximum_prefix_warning_hidden_cmd,
6001 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
6002 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6003 "Maximum number of prefix accept from this peer\n"
6004 "maximum no. of prefix limit\n"
6005 "Only give warning message when limit is exceeded\n")
6006
6007 DEFUN (neighbor_maximum_prefix_threshold_warning,
6008 neighbor_maximum_prefix_threshold_warning_cmd,
6009 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6010 NEIGHBOR_STR
6011 NEIGHBOR_ADDR_STR2
6012 "Maximum number of prefix accept from this peer\n"
6013 "maximum no. of prefix limit\n"
6014 "Threshold value (%) at which to generate a warning msg\n"
6015 "Only give warning message when limit is exceeded\n")
6016 {
6017 int idx_peer = 1;
6018 int idx_number = 3;
6019 int idx_number_2 = 4;
6020 return peer_maximum_prefix_set_vty(
6021 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6022 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6023 }
6024
6025 ALIAS_HIDDEN(
6026 neighbor_maximum_prefix_threshold_warning,
6027 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6028 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6030 "Maximum number of prefix accept from this peer\n"
6031 "maximum no. of prefix limit\n"
6032 "Threshold value (%) at which to generate a warning msg\n"
6033 "Only give warning message when limit is exceeded\n")
6034
6035 DEFUN (neighbor_maximum_prefix_restart,
6036 neighbor_maximum_prefix_restart_cmd,
6037 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6038 NEIGHBOR_STR
6039 NEIGHBOR_ADDR_STR2
6040 "Maximum number of prefix accept from this peer\n"
6041 "maximum no. of prefix limit\n"
6042 "Restart bgp connection after limit is exceeded\n"
6043 "Restart interval in minutes\n")
6044 {
6045 int idx_peer = 1;
6046 int idx_number = 3;
6047 int idx_number_2 = 5;
6048 return peer_maximum_prefix_set_vty(
6049 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6050 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6051 }
6052
6053 ALIAS_HIDDEN(
6054 neighbor_maximum_prefix_restart,
6055 neighbor_maximum_prefix_restart_hidden_cmd,
6056 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6057 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6058 "Maximum number of prefix accept from this peer\n"
6059 "maximum no. of prefix limit\n"
6060 "Restart bgp connection after limit is exceeded\n"
6061 "Restart interval in minutes\n")
6062
6063 DEFUN (neighbor_maximum_prefix_threshold_restart,
6064 neighbor_maximum_prefix_threshold_restart_cmd,
6065 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6066 NEIGHBOR_STR
6067 NEIGHBOR_ADDR_STR2
6068 "Maximum number of prefixes to accept from this peer\n"
6069 "maximum no. of prefix limit\n"
6070 "Threshold value (%) at which to generate a warning msg\n"
6071 "Restart bgp connection after limit is exceeded\n"
6072 "Restart interval in minutes\n")
6073 {
6074 int idx_peer = 1;
6075 int idx_number = 3;
6076 int idx_number_2 = 4;
6077 int idx_number_3 = 6;
6078 return peer_maximum_prefix_set_vty(
6079 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6080 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6081 argv[idx_number_3]->arg);
6082 }
6083
6084 ALIAS_HIDDEN(
6085 neighbor_maximum_prefix_threshold_restart,
6086 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6087 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6088 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6089 "Maximum number of prefixes to accept from this peer\n"
6090 "maximum no. of prefix limit\n"
6091 "Threshold value (%) at which to generate a warning msg\n"
6092 "Restart bgp connection after limit is exceeded\n"
6093 "Restart interval in minutes\n")
6094
6095 DEFUN (no_neighbor_maximum_prefix,
6096 no_neighbor_maximum_prefix_cmd,
6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6098 NO_STR
6099 NEIGHBOR_STR
6100 NEIGHBOR_ADDR_STR2
6101 "Maximum number of prefixes to accept from this peer\n"
6102 "maximum no. of prefix limit\n"
6103 "Threshold value (%) at which to generate a warning msg\n"
6104 "Restart bgp connection after limit is exceeded\n"
6105 "Restart interval in minutes\n"
6106 "Only give warning message when limit is exceeded\n")
6107 {
6108 int idx_peer = 2;
6109 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6110 bgp_node_afi(vty),
6111 bgp_node_safi(vty));
6112 }
6113
6114 ALIAS_HIDDEN(
6115 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6116 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6117 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6118 "Maximum number of prefixes to accept from this peer\n"
6119 "maximum no. of prefix limit\n"
6120 "Threshold value (%) at which to generate a warning msg\n"
6121 "Restart bgp connection after limit is exceeded\n"
6122 "Restart interval in minutes\n"
6123 "Only give warning message when limit is exceeded\n")
6124
6125
6126 /* "neighbor allowas-in" */
6127 DEFUN (neighbor_allowas_in,
6128 neighbor_allowas_in_cmd,
6129 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6130 NEIGHBOR_STR
6131 NEIGHBOR_ADDR_STR2
6132 "Accept as-path with my AS present in it\n"
6133 "Number of occurences of AS number\n"
6134 "Only accept my AS in the as-path if the route was originated in my AS\n")
6135 {
6136 int idx_peer = 1;
6137 int idx_number_origin = 3;
6138 int ret;
6139 int origin = 0;
6140 struct peer *peer;
6141 int allow_num = 0;
6142
6143 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6144 if (!peer)
6145 return CMD_WARNING_CONFIG_FAILED;
6146
6147 if (argc <= idx_number_origin)
6148 allow_num = 3;
6149 else {
6150 if (argv[idx_number_origin]->type == WORD_TKN)
6151 origin = 1;
6152 else
6153 allow_num = atoi(argv[idx_number_origin]->arg);
6154 }
6155
6156 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6157 allow_num, origin);
6158
6159 return bgp_vty_return(vty, ret);
6160 }
6161
6162 ALIAS_HIDDEN(
6163 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6164 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6165 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6166 "Accept as-path with my AS present in it\n"
6167 "Number of occurences of AS number\n"
6168 "Only accept my AS in the as-path if the route was originated in my AS\n")
6169
6170 DEFUN (no_neighbor_allowas_in,
6171 no_neighbor_allowas_in_cmd,
6172 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6173 NO_STR
6174 NEIGHBOR_STR
6175 NEIGHBOR_ADDR_STR2
6176 "allow local ASN appears in aspath attribute\n"
6177 "Number of occurences of AS number\n"
6178 "Only accept my AS in the as-path if the route was originated in my AS\n")
6179 {
6180 int idx_peer = 2;
6181 int ret;
6182 struct peer *peer;
6183
6184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6185 if (!peer)
6186 return CMD_WARNING_CONFIG_FAILED;
6187
6188 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6189 bgp_node_safi(vty));
6190
6191 return bgp_vty_return(vty, ret);
6192 }
6193
6194 ALIAS_HIDDEN(
6195 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6196 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6197 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6198 "allow local ASN appears in aspath attribute\n"
6199 "Number of occurences of AS number\n"
6200 "Only accept my AS in the as-path if the route was originated in my AS\n")
6201
6202 DEFUN (neighbor_ttl_security,
6203 neighbor_ttl_security_cmd,
6204 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6205 NEIGHBOR_STR
6206 NEIGHBOR_ADDR_STR2
6207 "BGP ttl-security parameters\n"
6208 "Specify the maximum number of hops to the BGP peer\n"
6209 "Number of hops to BGP peer\n")
6210 {
6211 int idx_peer = 1;
6212 int idx_number = 4;
6213 struct peer *peer;
6214 int gtsm_hops;
6215
6216 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6217 if (!peer)
6218 return CMD_WARNING_CONFIG_FAILED;
6219
6220 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6221
6222 /*
6223 * If 'neighbor swpX', then this is for directly connected peers,
6224 * we should not accept a ttl-security hops value greater than 1.
6225 */
6226 if (peer->conf_if && (gtsm_hops > 1)) {
6227 vty_out(vty,
6228 "%s is directly connected peer, hops cannot exceed 1\n",
6229 argv[idx_peer]->arg);
6230 return CMD_WARNING_CONFIG_FAILED;
6231 }
6232
6233 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6234 }
6235
6236 DEFUN (no_neighbor_ttl_security,
6237 no_neighbor_ttl_security_cmd,
6238 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6239 NO_STR
6240 NEIGHBOR_STR
6241 NEIGHBOR_ADDR_STR2
6242 "BGP ttl-security parameters\n"
6243 "Specify the maximum number of hops to the BGP peer\n"
6244 "Number of hops to BGP peer\n")
6245 {
6246 int idx_peer = 2;
6247 struct peer *peer;
6248
6249 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6250 if (!peer)
6251 return CMD_WARNING_CONFIG_FAILED;
6252
6253 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6254 }
6255
6256 DEFUN (neighbor_addpath_tx_all_paths,
6257 neighbor_addpath_tx_all_paths_cmd,
6258 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6259 NEIGHBOR_STR
6260 NEIGHBOR_ADDR_STR2
6261 "Use addpath to advertise all paths to a neighbor\n")
6262 {
6263 int idx_peer = 1;
6264 struct peer *peer;
6265
6266 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6267 if (!peer)
6268 return CMD_WARNING_CONFIG_FAILED;
6269
6270 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6271 BGP_ADDPATH_ALL);
6272 return CMD_SUCCESS;
6273 }
6274
6275 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6276 neighbor_addpath_tx_all_paths_hidden_cmd,
6277 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6278 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6279 "Use addpath to advertise all paths to a neighbor\n")
6280
6281 DEFUN (no_neighbor_addpath_tx_all_paths,
6282 no_neighbor_addpath_tx_all_paths_cmd,
6283 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6284 NO_STR
6285 NEIGHBOR_STR
6286 NEIGHBOR_ADDR_STR2
6287 "Use addpath to advertise all paths to a neighbor\n")
6288 {
6289 int idx_peer = 2;
6290 struct peer *peer;
6291
6292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6293 if (!peer)
6294 return CMD_WARNING_CONFIG_FAILED;
6295
6296 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6297 != BGP_ADDPATH_ALL) {
6298 vty_out(vty,
6299 "%% Peer not currently configured to transmit all paths.");
6300 return CMD_WARNING_CONFIG_FAILED;
6301 }
6302
6303 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6304 BGP_ADDPATH_NONE);
6305
6306 return CMD_SUCCESS;
6307 }
6308
6309 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6310 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6311 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6312 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6313 "Use addpath to advertise all paths to a neighbor\n")
6314
6315 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6316 neighbor_addpath_tx_bestpath_per_as_cmd,
6317 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6318 NEIGHBOR_STR
6319 NEIGHBOR_ADDR_STR2
6320 "Use addpath to advertise the bestpath per each neighboring AS\n")
6321 {
6322 int idx_peer = 1;
6323 struct peer *peer;
6324
6325 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6326 if (!peer)
6327 return CMD_WARNING_CONFIG_FAILED;
6328
6329 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6330 BGP_ADDPATH_BEST_PER_AS);
6331
6332 return CMD_SUCCESS;
6333 }
6334
6335 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6336 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6337 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6338 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6339 "Use addpath to advertise the bestpath per each neighboring AS\n")
6340
6341 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6342 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6343 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6344 NO_STR
6345 NEIGHBOR_STR
6346 NEIGHBOR_ADDR_STR2
6347 "Use addpath to advertise the bestpath per each neighboring AS\n")
6348 {
6349 int idx_peer = 2;
6350 struct peer *peer;
6351
6352 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6353 if (!peer)
6354 return CMD_WARNING_CONFIG_FAILED;
6355
6356 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6357 != BGP_ADDPATH_BEST_PER_AS) {
6358 vty_out(vty,
6359 "%% Peer not currently configured to transmit all best path per as.");
6360 return CMD_WARNING_CONFIG_FAILED;
6361 }
6362
6363 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6364 BGP_ADDPATH_NONE);
6365
6366 return CMD_SUCCESS;
6367 }
6368
6369 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6370 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6371 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6372 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6373 "Use addpath to advertise the bestpath per each neighboring AS\n")
6374
6375 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6376 struct ecommunity **list)
6377 {
6378 struct ecommunity *ecom = NULL;
6379 struct ecommunity *ecomadd;
6380
6381 for (; argc; --argc, ++argv) {
6382
6383 ecomadd = ecommunity_str2com(argv[0]->arg,
6384 ECOMMUNITY_ROUTE_TARGET, 0);
6385 if (!ecomadd) {
6386 vty_out(vty, "Malformed community-list value\n");
6387 if (ecom)
6388 ecommunity_free(&ecom);
6389 return CMD_WARNING_CONFIG_FAILED;
6390 }
6391
6392 if (ecom) {
6393 ecommunity_merge(ecom, ecomadd);
6394 ecommunity_free(&ecomadd);
6395 } else {
6396 ecom = ecomadd;
6397 }
6398 }
6399
6400 if (*list) {
6401 ecommunity_free(&*list);
6402 }
6403 *list = ecom;
6404
6405 return CMD_SUCCESS;
6406 }
6407
6408 /*
6409 * v2vimport is true if we are handling a `import vrf ...` command
6410 */
6411 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6412 {
6413 afi_t afi;
6414
6415 switch (vty->node) {
6416 case BGP_IPV4_NODE:
6417 afi = AFI_IP;
6418 break;
6419 case BGP_IPV6_NODE:
6420 afi = AFI_IP6;
6421 break;
6422 default:
6423 vty_out(vty,
6424 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6425 return AFI_MAX;
6426 }
6427
6428 if (!v2vimport) {
6429 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6430 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6431 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6432 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6433 vty_out(vty,
6434 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6435 return AFI_MAX;
6436 }
6437 } else {
6438 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6439 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6440 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6441 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6442 vty_out(vty,
6443 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6444 return AFI_MAX;
6445 }
6446 }
6447 return afi;
6448 }
6449
6450 DEFPY (af_rd_vpn_export,
6451 af_rd_vpn_export_cmd,
6452 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6453 NO_STR
6454 "Specify route distinguisher\n"
6455 "Between current address-family and vpn\n"
6456 "For routes leaked from current address-family to vpn\n"
6457 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6458 {
6459 VTY_DECLVAR_CONTEXT(bgp, bgp);
6460 struct prefix_rd prd;
6461 int ret;
6462 afi_t afi;
6463 int idx = 0;
6464 int yes = 1;
6465
6466 if (argv_find(argv, argc, "no", &idx))
6467 yes = 0;
6468
6469 if (yes) {
6470 ret = str2prefix_rd(rd_str, &prd);
6471 if (!ret) {
6472 vty_out(vty, "%% Malformed rd\n");
6473 return CMD_WARNING_CONFIG_FAILED;
6474 }
6475 }
6476
6477 afi = vpn_policy_getafi(vty, bgp, false);
6478 if (afi == AFI_MAX)
6479 return CMD_WARNING_CONFIG_FAILED;
6480
6481 /*
6482 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6483 */
6484 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6485 bgp_get_default(), bgp);
6486
6487 if (yes) {
6488 bgp->vpn_policy[afi].tovpn_rd = prd;
6489 SET_FLAG(bgp->vpn_policy[afi].flags,
6490 BGP_VPN_POLICY_TOVPN_RD_SET);
6491 } else {
6492 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6493 BGP_VPN_POLICY_TOVPN_RD_SET);
6494 }
6495
6496 /* post-change: re-export vpn routes */
6497 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6498 bgp_get_default(), bgp);
6499
6500 return CMD_SUCCESS;
6501 }
6502
6503 ALIAS (af_rd_vpn_export,
6504 af_no_rd_vpn_export_cmd,
6505 "no rd vpn export",
6506 NO_STR
6507 "Specify route distinguisher\n"
6508 "Between current address-family and vpn\n"
6509 "For routes leaked from current address-family to vpn\n")
6510
6511 DEFPY (af_label_vpn_export,
6512 af_label_vpn_export_cmd,
6513 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6514 NO_STR
6515 "label value for VRF\n"
6516 "Between current address-family and vpn\n"
6517 "For routes leaked from current address-family to vpn\n"
6518 "Label Value <0-1048575>\n"
6519 "Automatically assign a label\n")
6520 {
6521 VTY_DECLVAR_CONTEXT(bgp, bgp);
6522 mpls_label_t label = MPLS_LABEL_NONE;
6523 afi_t afi;
6524 int idx = 0;
6525 int yes = 1;
6526
6527 if (argv_find(argv, argc, "no", &idx))
6528 yes = 0;
6529
6530 /* If "no ...", squash trailing parameter */
6531 if (!yes)
6532 label_auto = NULL;
6533
6534 if (yes) {
6535 if (!label_auto)
6536 label = label_val; /* parser should force unsigned */
6537 }
6538
6539 afi = vpn_policy_getafi(vty, bgp, false);
6540 if (afi == AFI_MAX)
6541 return CMD_WARNING_CONFIG_FAILED;
6542
6543
6544 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6545 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6546 /* no change */
6547 return CMD_SUCCESS;
6548
6549 /*
6550 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6551 */
6552 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6553 bgp_get_default(), bgp);
6554
6555 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6556 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6557
6558 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6559
6560 /*
6561 * label has previously been automatically
6562 * assigned by labelpool: release it
6563 *
6564 * NB if tovpn_label == MPLS_LABEL_NONE it
6565 * means the automatic assignment is in flight
6566 * and therefore the labelpool callback must
6567 * detect that the auto label is not needed.
6568 */
6569
6570 bgp_lp_release(LP_TYPE_VRF,
6571 &bgp->vpn_policy[afi],
6572 bgp->vpn_policy[afi].tovpn_label);
6573 }
6574 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6575 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6576 }
6577
6578 bgp->vpn_policy[afi].tovpn_label = label;
6579 if (label_auto) {
6580 SET_FLAG(bgp->vpn_policy[afi].flags,
6581 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6582 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6583 vpn_leak_label_callback);
6584 }
6585
6586 /* post-change: re-export vpn routes */
6587 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6588 bgp_get_default(), bgp);
6589
6590 return CMD_SUCCESS;
6591 }
6592
6593 ALIAS (af_label_vpn_export,
6594 af_no_label_vpn_export_cmd,
6595 "no label vpn export",
6596 NO_STR
6597 "label value for VRF\n"
6598 "Between current address-family and vpn\n"
6599 "For routes leaked from current address-family to vpn\n")
6600
6601 DEFPY (af_nexthop_vpn_export,
6602 af_nexthop_vpn_export_cmd,
6603 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6604 NO_STR
6605 "Specify next hop to use for VRF advertised prefixes\n"
6606 "Between current address-family and vpn\n"
6607 "For routes leaked from current address-family to vpn\n"
6608 "IPv4 prefix\n"
6609 "IPv6 prefix\n")
6610 {
6611 VTY_DECLVAR_CONTEXT(bgp, bgp);
6612 afi_t afi;
6613 struct prefix p;
6614 int idx = 0;
6615 int yes = 1;
6616
6617 if (argv_find(argv, argc, "no", &idx))
6618 yes = 0;
6619
6620 if (yes) {
6621 if (!sockunion2hostprefix(nexthop_str, &p))
6622 return CMD_WARNING_CONFIG_FAILED;
6623 }
6624
6625 afi = vpn_policy_getafi(vty, bgp, false);
6626 if (afi == AFI_MAX)
6627 return CMD_WARNING_CONFIG_FAILED;
6628
6629 /*
6630 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6631 */
6632 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6633 bgp_get_default(), bgp);
6634
6635 if (yes) {
6636 bgp->vpn_policy[afi].tovpn_nexthop = p;
6637 SET_FLAG(bgp->vpn_policy[afi].flags,
6638 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6639 } else {
6640 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6641 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6642 }
6643
6644 /* post-change: re-export vpn routes */
6645 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6646 bgp_get_default(), bgp);
6647
6648 return CMD_SUCCESS;
6649 }
6650
6651 ALIAS (af_nexthop_vpn_export,
6652 af_no_nexthop_vpn_export_cmd,
6653 "no nexthop vpn export",
6654 NO_STR
6655 "Specify next hop to use for VRF advertised prefixes\n"
6656 "Between current address-family and vpn\n"
6657 "For routes leaked from current address-family to vpn\n")
6658
6659 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6660 {
6661 if (!strcmp(dstr, "import")) {
6662 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6663 } else if (!strcmp(dstr, "export")) {
6664 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6665 } else if (!strcmp(dstr, "both")) {
6666 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6667 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6668 } else {
6669 vty_out(vty, "%% direction parse error\n");
6670 return CMD_WARNING_CONFIG_FAILED;
6671 }
6672 return CMD_SUCCESS;
6673 }
6674
6675 DEFPY (af_rt_vpn_imexport,
6676 af_rt_vpn_imexport_cmd,
6677 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6678 NO_STR
6679 "Specify route target list\n"
6680 "Specify route target list\n"
6681 "Between current address-family and vpn\n"
6682 "For routes leaked from vpn to current address-family: match any\n"
6683 "For routes leaked from current address-family to vpn: set\n"
6684 "both import: match any and export: set\n"
6685 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6686 {
6687 VTY_DECLVAR_CONTEXT(bgp, bgp);
6688 int ret;
6689 struct ecommunity *ecom = NULL;
6690 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6691 vpn_policy_direction_t dir;
6692 afi_t afi;
6693 int idx = 0;
6694 int yes = 1;
6695
6696 if (argv_find(argv, argc, "no", &idx))
6697 yes = 0;
6698
6699 afi = vpn_policy_getafi(vty, bgp, false);
6700 if (afi == AFI_MAX)
6701 return CMD_WARNING_CONFIG_FAILED;
6702
6703 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6704 if (ret != CMD_SUCCESS)
6705 return ret;
6706
6707 if (yes) {
6708 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6709 vty_out(vty, "%% Missing RTLIST\n");
6710 return CMD_WARNING_CONFIG_FAILED;
6711 }
6712 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6713 if (ret != CMD_SUCCESS) {
6714 return ret;
6715 }
6716 }
6717
6718 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6719 if (!dodir[dir])
6720 continue;
6721
6722 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6723
6724 if (yes) {
6725 if (bgp->vpn_policy[afi].rtlist[dir])
6726 ecommunity_free(
6727 &bgp->vpn_policy[afi].rtlist[dir]);
6728 bgp->vpn_policy[afi].rtlist[dir] =
6729 ecommunity_dup(ecom);
6730 } else {
6731 if (bgp->vpn_policy[afi].rtlist[dir])
6732 ecommunity_free(
6733 &bgp->vpn_policy[afi].rtlist[dir]);
6734 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6735 }
6736
6737 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6738 }
6739
6740 if (ecom)
6741 ecommunity_free(&ecom);
6742
6743 return CMD_SUCCESS;
6744 }
6745
6746 ALIAS (af_rt_vpn_imexport,
6747 af_no_rt_vpn_imexport_cmd,
6748 "no <rt|route-target> vpn <import|export|both>$direction_str",
6749 NO_STR
6750 "Specify route target list\n"
6751 "Specify route target list\n"
6752 "Between current address-family and vpn\n"
6753 "For routes leaked from vpn to current address-family\n"
6754 "For routes leaked from current address-family to vpn\n"
6755 "both import and export\n")
6756
6757 DEFPY (af_route_map_vpn_imexport,
6758 af_route_map_vpn_imexport_cmd,
6759 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6760 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6761 NO_STR
6762 "Specify route map\n"
6763 "Between current address-family and vpn\n"
6764 "For routes leaked from vpn to current address-family\n"
6765 "For routes leaked from current address-family to vpn\n"
6766 "name of route-map\n")
6767 {
6768 VTY_DECLVAR_CONTEXT(bgp, bgp);
6769 int ret;
6770 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6771 vpn_policy_direction_t dir;
6772 afi_t afi;
6773 int idx = 0;
6774 int yes = 1;
6775
6776 if (argv_find(argv, argc, "no", &idx))
6777 yes = 0;
6778
6779 afi = vpn_policy_getafi(vty, bgp, false);
6780 if (afi == AFI_MAX)
6781 return CMD_WARNING_CONFIG_FAILED;
6782
6783 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6784 if (ret != CMD_SUCCESS)
6785 return ret;
6786
6787 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6788 if (!dodir[dir])
6789 continue;
6790
6791 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6792
6793 if (yes) {
6794 if (bgp->vpn_policy[afi].rmap_name[dir])
6795 XFREE(MTYPE_ROUTE_MAP_NAME,
6796 bgp->vpn_policy[afi].rmap_name[dir]);
6797 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6798 MTYPE_ROUTE_MAP_NAME, rmap_str);
6799 bgp->vpn_policy[afi].rmap[dir] =
6800 route_map_lookup_warn_noexist(vty, rmap_str);
6801 if (!bgp->vpn_policy[afi].rmap[dir])
6802 return CMD_SUCCESS;
6803 } else {
6804 if (bgp->vpn_policy[afi].rmap_name[dir])
6805 XFREE(MTYPE_ROUTE_MAP_NAME,
6806 bgp->vpn_policy[afi].rmap_name[dir]);
6807 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6808 bgp->vpn_policy[afi].rmap[dir] = NULL;
6809 }
6810
6811 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6812 }
6813
6814 return CMD_SUCCESS;
6815 }
6816
6817 ALIAS (af_route_map_vpn_imexport,
6818 af_no_route_map_vpn_imexport_cmd,
6819 "no route-map vpn <import|export>$direction_str",
6820 NO_STR
6821 "Specify route map\n"
6822 "Between current address-family and vpn\n"
6823 "For routes leaked from vpn to current address-family\n"
6824 "For routes leaked from current address-family to vpn\n")
6825
6826 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6827 "[no] import vrf route-map RMAP$rmap_str",
6828 NO_STR
6829 "Import routes from another VRF\n"
6830 "Vrf routes being filtered\n"
6831 "Specify route map\n"
6832 "name of route-map\n")
6833 {
6834 VTY_DECLVAR_CONTEXT(bgp, bgp);
6835 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6836 afi_t afi;
6837 int idx = 0;
6838 int yes = 1;
6839 struct bgp *bgp_default;
6840
6841 if (argv_find(argv, argc, "no", &idx))
6842 yes = 0;
6843
6844 afi = vpn_policy_getafi(vty, bgp, true);
6845 if (afi == AFI_MAX)
6846 return CMD_WARNING_CONFIG_FAILED;
6847
6848 bgp_default = bgp_get_default();
6849 if (!bgp_default) {
6850 int32_t ret;
6851 as_t as = bgp->as;
6852
6853 /* Auto-create assuming the same AS */
6854 ret = bgp_get(&bgp_default, &as, NULL,
6855 BGP_INSTANCE_TYPE_DEFAULT);
6856
6857 if (ret) {
6858 vty_out(vty,
6859 "VRF default is not configured as a bgp instance\n");
6860 return CMD_WARNING;
6861 }
6862 }
6863
6864 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6865
6866 if (yes) {
6867 if (bgp->vpn_policy[afi].rmap_name[dir])
6868 XFREE(MTYPE_ROUTE_MAP_NAME,
6869 bgp->vpn_policy[afi].rmap_name[dir]);
6870 bgp->vpn_policy[afi].rmap_name[dir] =
6871 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6872 bgp->vpn_policy[afi].rmap[dir] =
6873 route_map_lookup_warn_noexist(vty, rmap_str);
6874 if (!bgp->vpn_policy[afi].rmap[dir])
6875 return CMD_SUCCESS;
6876 } else {
6877 if (bgp->vpn_policy[afi].rmap_name[dir])
6878 XFREE(MTYPE_ROUTE_MAP_NAME,
6879 bgp->vpn_policy[afi].rmap_name[dir]);
6880 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6881 bgp->vpn_policy[afi].rmap[dir] = NULL;
6882 }
6883
6884 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6885
6886 return CMD_SUCCESS;
6887 }
6888
6889 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6890 "no import vrf route-map",
6891 NO_STR
6892 "Import routes from another VRF\n"
6893 "Vrf routes being filtered\n"
6894 "Specify route map\n")
6895
6896 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6897 "[no] import vrf VIEWVRFNAME$import_name",
6898 NO_STR
6899 "Import routes from another VRF\n"
6900 "VRF to import from\n"
6901 "The name of the VRF\n")
6902 {
6903 VTY_DECLVAR_CONTEXT(bgp, bgp);
6904 struct listnode *node;
6905 struct bgp *vrf_bgp, *bgp_default;
6906 int32_t ret = 0;
6907 as_t as = bgp->as;
6908 bool remove = false;
6909 int32_t idx = 0;
6910 char *vname;
6911 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6912 safi_t safi;
6913 afi_t afi;
6914
6915 if (import_name == NULL) {
6916 vty_out(vty, "%% Missing import name\n");
6917 return CMD_WARNING;
6918 }
6919
6920 if (argv_find(argv, argc, "no", &idx))
6921 remove = true;
6922
6923 afi = vpn_policy_getafi(vty, bgp, true);
6924 if (afi == AFI_MAX)
6925 return CMD_WARNING_CONFIG_FAILED;
6926
6927 safi = bgp_node_safi(vty);
6928
6929 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6930 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6931 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6932 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6933 remove ? "unimport" : "import", import_name);
6934 return CMD_WARNING;
6935 }
6936
6937 bgp_default = bgp_get_default();
6938 if (!bgp_default) {
6939 /* Auto-create assuming the same AS */
6940 ret = bgp_get(&bgp_default, &as, NULL,
6941 BGP_INSTANCE_TYPE_DEFAULT);
6942
6943 if (ret) {
6944 vty_out(vty,
6945 "VRF default is not configured as a bgp instance\n");
6946 return CMD_WARNING;
6947 }
6948 }
6949
6950 vrf_bgp = bgp_lookup_by_name(import_name);
6951 if (!vrf_bgp) {
6952 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6953 vrf_bgp = bgp_default;
6954 else
6955 /* Auto-create assuming the same AS */
6956 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6957
6958 if (ret) {
6959 vty_out(vty,
6960 "VRF %s is not configured as a bgp instance\n",
6961 import_name);
6962 return CMD_WARNING;
6963 }
6964 }
6965
6966 if (remove) {
6967 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6968 } else {
6969 /* Already importing from "import_vrf"? */
6970 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6971 vname)) {
6972 if (strcmp(vname, import_name) == 0)
6973 return CMD_WARNING;
6974 }
6975
6976 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6977 }
6978
6979 return CMD_SUCCESS;
6980 }
6981
6982 /* This command is valid only in a bgp vrf instance or the default instance */
6983 DEFPY (bgp_imexport_vpn,
6984 bgp_imexport_vpn_cmd,
6985 "[no] <import|export>$direction_str vpn",
6986 NO_STR
6987 "Import routes to this address-family\n"
6988 "Export routes from this address-family\n"
6989 "to/from default instance VPN RIB\n")
6990 {
6991 VTY_DECLVAR_CONTEXT(bgp, bgp);
6992 int previous_state;
6993 afi_t afi;
6994 safi_t safi;
6995 int idx = 0;
6996 int yes = 1;
6997 int flag;
6998 vpn_policy_direction_t dir;
6999
7000 if (argv_find(argv, argc, "no", &idx))
7001 yes = 0;
7002
7003 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
7004 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7005
7006 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7007 return CMD_WARNING_CONFIG_FAILED;
7008 }
7009
7010 afi = bgp_node_afi(vty);
7011 safi = bgp_node_safi(vty);
7012 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7013 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7014 return CMD_WARNING_CONFIG_FAILED;
7015 }
7016
7017 if (!strcmp(direction_str, "import")) {
7018 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7019 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7020 } else if (!strcmp(direction_str, "export")) {
7021 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7022 dir = BGP_VPN_POLICY_DIR_TOVPN;
7023 } else {
7024 vty_out(vty, "%% unknown direction %s\n", direction_str);
7025 return CMD_WARNING_CONFIG_FAILED;
7026 }
7027
7028 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7029
7030 if (yes) {
7031 SET_FLAG(bgp->af_flags[afi][safi], flag);
7032 if (!previous_state) {
7033 /* trigger export current vrf */
7034 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7035 }
7036 } else {
7037 if (previous_state) {
7038 /* trigger un-export current vrf */
7039 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7040 }
7041 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7042 }
7043
7044 return CMD_SUCCESS;
7045 }
7046
7047 DEFPY (af_routetarget_import,
7048 af_routetarget_import_cmd,
7049 "[no] <rt|route-target> redirect import RTLIST...",
7050 NO_STR
7051 "Specify route target list\n"
7052 "Specify route target list\n"
7053 "Flow-spec redirect type route target\n"
7054 "Import routes to this address-family\n"
7055 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7056 {
7057 VTY_DECLVAR_CONTEXT(bgp, bgp);
7058 int ret;
7059 struct ecommunity *ecom = NULL;
7060 afi_t afi;
7061 int idx = 0;
7062 int yes = 1;
7063
7064 if (argv_find(argv, argc, "no", &idx))
7065 yes = 0;
7066
7067 afi = vpn_policy_getafi(vty, bgp, false);
7068 if (afi == AFI_MAX)
7069 return CMD_WARNING_CONFIG_FAILED;
7070
7071 if (yes) {
7072 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7073 vty_out(vty, "%% Missing RTLIST\n");
7074 return CMD_WARNING_CONFIG_FAILED;
7075 }
7076 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7077 if (ret != CMD_SUCCESS)
7078 return ret;
7079 }
7080
7081 if (yes) {
7082 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7083 ecommunity_free(&bgp->vpn_policy[afi]
7084 .import_redirect_rtlist);
7085 bgp->vpn_policy[afi].import_redirect_rtlist =
7086 ecommunity_dup(ecom);
7087 } else {
7088 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7089 ecommunity_free(&bgp->vpn_policy[afi]
7090 .import_redirect_rtlist);
7091 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7092 }
7093
7094 if (ecom)
7095 ecommunity_free(&ecom);
7096
7097 return CMD_SUCCESS;
7098 }
7099
7100 DEFUN_NOSH (address_family_ipv4_safi,
7101 address_family_ipv4_safi_cmd,
7102 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7103 "Enter Address Family command mode\n"
7104 "Address Family\n"
7105 BGP_SAFI_WITH_LABEL_HELP_STR)
7106 {
7107
7108 if (argc == 3) {
7109 VTY_DECLVAR_CONTEXT(bgp, bgp);
7110 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7111 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7112 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7113 && safi != SAFI_EVPN) {
7114 vty_out(vty,
7115 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7116 return CMD_WARNING_CONFIG_FAILED;
7117 }
7118 vty->node = bgp_node_type(AFI_IP, safi);
7119 } else
7120 vty->node = BGP_IPV4_NODE;
7121
7122 return CMD_SUCCESS;
7123 }
7124
7125 DEFUN_NOSH (address_family_ipv6_safi,
7126 address_family_ipv6_safi_cmd,
7127 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7128 "Enter Address Family command mode\n"
7129 "Address Family\n"
7130 BGP_SAFI_WITH_LABEL_HELP_STR)
7131 {
7132 if (argc == 3) {
7133 VTY_DECLVAR_CONTEXT(bgp, bgp);
7134 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7135 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7136 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7137 && safi != SAFI_EVPN) {
7138 vty_out(vty,
7139 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7140 return CMD_WARNING_CONFIG_FAILED;
7141 }
7142 vty->node = bgp_node_type(AFI_IP6, safi);
7143 } else
7144 vty->node = BGP_IPV6_NODE;
7145
7146 return CMD_SUCCESS;
7147 }
7148
7149 #ifdef KEEP_OLD_VPN_COMMANDS
7150 DEFUN_NOSH (address_family_vpnv4,
7151 address_family_vpnv4_cmd,
7152 "address-family vpnv4 [unicast]",
7153 "Enter Address Family command mode\n"
7154 "Address Family\n"
7155 "Address Family modifier\n")
7156 {
7157 vty->node = BGP_VPNV4_NODE;
7158 return CMD_SUCCESS;
7159 }
7160
7161 DEFUN_NOSH (address_family_vpnv6,
7162 address_family_vpnv6_cmd,
7163 "address-family vpnv6 [unicast]",
7164 "Enter Address Family command mode\n"
7165 "Address Family\n"
7166 "Address Family modifier\n")
7167 {
7168 vty->node = BGP_VPNV6_NODE;
7169 return CMD_SUCCESS;
7170 }
7171 #endif /* KEEP_OLD_VPN_COMMANDS */
7172
7173 DEFUN_NOSH (address_family_evpn,
7174 address_family_evpn_cmd,
7175 "address-family l2vpn evpn",
7176 "Enter Address Family command mode\n"
7177 "Address Family\n"
7178 "Address Family modifier\n")
7179 {
7180 VTY_DECLVAR_CONTEXT(bgp, bgp);
7181 vty->node = BGP_EVPN_NODE;
7182 return CMD_SUCCESS;
7183 }
7184
7185 DEFUN_NOSH (exit_address_family,
7186 exit_address_family_cmd,
7187 "exit-address-family",
7188 "Exit from Address Family configuration mode\n")
7189 {
7190 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7191 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7192 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7193 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7194 || vty->node == BGP_EVPN_NODE
7195 || vty->node == BGP_FLOWSPECV4_NODE
7196 || vty->node == BGP_FLOWSPECV6_NODE)
7197 vty->node = BGP_NODE;
7198 return CMD_SUCCESS;
7199 }
7200
7201 /* Recalculate bestpath and re-advertise a prefix */
7202 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7203 const char *ip_str, afi_t afi, safi_t safi,
7204 struct prefix_rd *prd)
7205 {
7206 int ret;
7207 struct prefix match;
7208 struct bgp_node *rn;
7209 struct bgp_node *rm;
7210 struct bgp *bgp;
7211 struct bgp_table *table;
7212 struct bgp_table *rib;
7213
7214 /* BGP structure lookup. */
7215 if (view_name) {
7216 bgp = bgp_lookup_by_name(view_name);
7217 if (bgp == NULL) {
7218 vty_out(vty, "%% Can't find BGP instance %s\n",
7219 view_name);
7220 return CMD_WARNING;
7221 }
7222 } else {
7223 bgp = bgp_get_default();
7224 if (bgp == NULL) {
7225 vty_out(vty, "%% No BGP process is configured\n");
7226 return CMD_WARNING;
7227 }
7228 }
7229
7230 /* Check IP address argument. */
7231 ret = str2prefix(ip_str, &match);
7232 if (!ret) {
7233 vty_out(vty, "%% address is malformed\n");
7234 return CMD_WARNING;
7235 }
7236
7237 match.family = afi2family(afi);
7238 rib = bgp->rib[afi][safi];
7239
7240 if (safi == SAFI_MPLS_VPN) {
7241 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7242 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7243 continue;
7244
7245 table = bgp_node_get_bgp_table_info(rn);
7246 if (table != NULL) {
7247
7248 if ((rm = bgp_node_match(table, &match))
7249 != NULL) {
7250 if (rm->p.prefixlen
7251 == match.prefixlen) {
7252 SET_FLAG(rm->flags,
7253 BGP_NODE_USER_CLEAR);
7254 bgp_process(bgp, rm, afi, safi);
7255 }
7256 bgp_unlock_node(rm);
7257 }
7258 }
7259 }
7260 } else {
7261 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7262 if (rn->p.prefixlen == match.prefixlen) {
7263 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7264 bgp_process(bgp, rn, afi, safi);
7265 }
7266 bgp_unlock_node(rn);
7267 }
7268 }
7269
7270 return CMD_SUCCESS;
7271 }
7272
7273 /* one clear bgp command to rule them all */
7274 DEFUN (clear_ip_bgp_all,
7275 clear_ip_bgp_all_cmd,
7276 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
7277 CLEAR_STR
7278 IP_STR
7279 BGP_STR
7280 BGP_INSTANCE_HELP_STR
7281 BGP_AFI_HELP_STR
7282 "Address Family\n"
7283 BGP_SAFI_WITH_LABEL_HELP_STR
7284 "Address Family modifier\n"
7285 "Clear all peers\n"
7286 "BGP neighbor address to clear\n"
7287 "BGP IPv6 neighbor to clear\n"
7288 "BGP neighbor on interface to clear\n"
7289 "Clear peers with the AS number\n"
7290 "Clear all external peers\n"
7291 "Clear all members of peer-group\n"
7292 "BGP peer-group name\n"
7293 BGP_SOFT_STR
7294 BGP_SOFT_IN_STR
7295 BGP_SOFT_OUT_STR
7296 BGP_SOFT_IN_STR
7297 "Push out prefix-list ORF and do inbound soft reconfig\n"
7298 BGP_SOFT_OUT_STR)
7299 {
7300 char *vrf = NULL;
7301
7302 afi_t afi = AFI_IP6;
7303 safi_t safi = SAFI_UNICAST;
7304 enum clear_sort clr_sort = clear_peer;
7305 enum bgp_clear_type clr_type;
7306 char *clr_arg = NULL;
7307
7308 int idx = 0;
7309
7310 /* clear [ip] bgp */
7311 if (argv_find(argv, argc, "ip", &idx))
7312 afi = AFI_IP;
7313
7314 /* [<vrf> VIEWVRFNAME] */
7315 if (argv_find(argv, argc, "vrf", &idx)) {
7316 vrf = argv[idx + 1]->arg;
7317 idx += 2;
7318 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7319 vrf = NULL;
7320 } else if (argv_find(argv, argc, "view", &idx)) {
7321 /* [<view> VIEWVRFNAME] */
7322 vrf = argv[idx + 1]->arg;
7323 idx += 2;
7324 }
7325 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7326 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7327 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7328
7329 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7330 if (argv_find(argv, argc, "*", &idx)) {
7331 clr_sort = clear_all;
7332 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7333 clr_sort = clear_peer;
7334 clr_arg = argv[idx]->arg;
7335 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7336 clr_sort = clear_peer;
7337 clr_arg = argv[idx]->arg;
7338 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7339 clr_sort = clear_group;
7340 idx++;
7341 clr_arg = argv[idx]->arg;
7342 } else if (argv_find(argv, argc, "WORD", &idx)) {
7343 clr_sort = clear_peer;
7344 clr_arg = argv[idx]->arg;
7345 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7346 clr_sort = clear_as;
7347 clr_arg = argv[idx]->arg;
7348 } else if (argv_find(argv, argc, "external", &idx)) {
7349 clr_sort = clear_external;
7350 }
7351
7352 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7353 if (argv_find(argv, argc, "soft", &idx)) {
7354 if (argv_find(argv, argc, "in", &idx)
7355 || argv_find(argv, argc, "out", &idx))
7356 clr_type = strmatch(argv[idx]->text, "in")
7357 ? BGP_CLEAR_SOFT_IN
7358 : BGP_CLEAR_SOFT_OUT;
7359 else
7360 clr_type = BGP_CLEAR_SOFT_BOTH;
7361 } else if (argv_find(argv, argc, "in", &idx)) {
7362 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7363 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7364 : BGP_CLEAR_SOFT_IN;
7365 } else if (argv_find(argv, argc, "out", &idx)) {
7366 clr_type = BGP_CLEAR_SOFT_OUT;
7367 } else
7368 clr_type = BGP_CLEAR_SOFT_NONE;
7369
7370 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7371 }
7372
7373 DEFUN (clear_ip_bgp_prefix,
7374 clear_ip_bgp_prefix_cmd,
7375 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7376 CLEAR_STR
7377 IP_STR
7378 BGP_STR
7379 BGP_INSTANCE_HELP_STR
7380 "Clear bestpath and re-advertise\n"
7381 "IPv4 prefix\n")
7382 {
7383 char *vrf = NULL;
7384 char *prefix = NULL;
7385
7386 int idx = 0;
7387
7388 /* [<view|vrf> VIEWVRFNAME] */
7389 if (argv_find(argv, argc, "vrf", &idx)) {
7390 vrf = argv[idx + 1]->arg;
7391 idx += 2;
7392 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7393 vrf = NULL;
7394 } else if (argv_find(argv, argc, "view", &idx)) {
7395 /* [<view> VIEWVRFNAME] */
7396 vrf = argv[idx + 1]->arg;
7397 idx += 2;
7398 }
7399
7400 prefix = argv[argc - 1]->arg;
7401
7402 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7403 }
7404
7405 DEFUN (clear_bgp_ipv6_safi_prefix,
7406 clear_bgp_ipv6_safi_prefix_cmd,
7407 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7408 CLEAR_STR
7409 IP_STR
7410 BGP_STR
7411 "Address Family\n"
7412 BGP_SAFI_HELP_STR
7413 "Clear bestpath and re-advertise\n"
7414 "IPv6 prefix\n")
7415 {
7416 int idx_safi = 0;
7417 int idx_ipv6_prefix = 0;
7418 safi_t safi = SAFI_UNICAST;
7419 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7420 argv[idx_ipv6_prefix]->arg : NULL;
7421
7422 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7423 return bgp_clear_prefix(
7424 vty, NULL, prefix, AFI_IP6,
7425 safi, NULL);
7426 }
7427
7428 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7429 clear_bgp_instance_ipv6_safi_prefix_cmd,
7430 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7431 CLEAR_STR
7432 IP_STR
7433 BGP_STR
7434 BGP_INSTANCE_HELP_STR
7435 "Address Family\n"
7436 BGP_SAFI_HELP_STR
7437 "Clear bestpath and re-advertise\n"
7438 "IPv6 prefix\n")
7439 {
7440 int idx_safi = 0;
7441 int idx_vrfview = 0;
7442 int idx_ipv6_prefix = 0;
7443 safi_t safi = SAFI_UNICAST;
7444 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7445 argv[idx_ipv6_prefix]->arg : NULL;
7446 char *vrfview = NULL;
7447
7448 /* [<view|vrf> VIEWVRFNAME] */
7449 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7450 vrfview = argv[idx_vrfview + 1]->arg;
7451 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7452 vrfview = NULL;
7453 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7454 /* [<view> VIEWVRFNAME] */
7455 vrfview = argv[idx_vrfview + 1]->arg;
7456 }
7457 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7458
7459 return bgp_clear_prefix(
7460 vty, vrfview, prefix,
7461 AFI_IP6, safi, NULL);
7462 }
7463
7464 DEFUN (show_bgp_views,
7465 show_bgp_views_cmd,
7466 "show [ip] bgp views",
7467 SHOW_STR
7468 IP_STR
7469 BGP_STR
7470 "Show the defined BGP views\n")
7471 {
7472 struct list *inst = bm->bgp;
7473 struct listnode *node;
7474 struct bgp *bgp;
7475
7476 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7477 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7478 return CMD_WARNING;
7479 }
7480
7481 vty_out(vty, "Defined BGP views:\n");
7482 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7483 /* Skip VRFs. */
7484 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7485 continue;
7486 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7487 bgp->as);
7488 }
7489
7490 return CMD_SUCCESS;
7491 }
7492
7493 DEFUN (show_bgp_vrfs,
7494 show_bgp_vrfs_cmd,
7495 "show [ip] bgp vrfs [json]",
7496 SHOW_STR
7497 IP_STR
7498 BGP_STR
7499 "Show BGP VRFs\n"
7500 JSON_STR)
7501 {
7502 char buf[ETHER_ADDR_STRLEN];
7503 struct list *inst = bm->bgp;
7504 struct listnode *node;
7505 struct bgp *bgp;
7506 bool uj = use_json(argc, argv);
7507 json_object *json = NULL;
7508 json_object *json_vrfs = NULL;
7509 int count = 0;
7510
7511 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7512 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7513 return CMD_WARNING;
7514 }
7515
7516 if (uj) {
7517 json = json_object_new_object();
7518 json_vrfs = json_object_new_object();
7519 }
7520
7521 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7522 const char *name, *type;
7523 struct peer *peer;
7524 struct listnode *node2, *nnode2;
7525 int peers_cfg, peers_estb;
7526 json_object *json_vrf = NULL;
7527
7528 /* Skip Views. */
7529 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7530 continue;
7531
7532 count++;
7533 if (!uj && count == 1)
7534 vty_out(vty,
7535 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7536 "Type", "Id", "routerId", "#PeersVfg",
7537 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7538
7539 peers_cfg = peers_estb = 0;
7540 if (uj)
7541 json_vrf = json_object_new_object();
7542
7543
7544 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7545 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7546 continue;
7547 peers_cfg++;
7548 if (peer->status == Established)
7549 peers_estb++;
7550 }
7551
7552 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7553 name = VRF_DEFAULT_NAME;
7554 type = "DFLT";
7555 } else {
7556 name = bgp->name;
7557 type = "VRF";
7558 }
7559
7560
7561 if (uj) {
7562 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7563 ? -1
7564 : (int64_t)bgp->vrf_id;
7565 json_object_string_add(json_vrf, "type", type);
7566 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7567 json_object_string_add(json_vrf, "routerId",
7568 inet_ntoa(bgp->router_id));
7569 json_object_int_add(json_vrf, "numConfiguredPeers",
7570 peers_cfg);
7571 json_object_int_add(json_vrf, "numEstablishedPeers",
7572 peers_estb);
7573
7574 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7575 json_object_string_add(
7576 json_vrf, "rmac",
7577 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7578 json_object_object_add(json_vrfs, name, json_vrf);
7579 } else
7580 vty_out(vty,
7581 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7582 type,
7583 bgp->vrf_id == VRF_UNKNOWN ? -1
7584 : (int)bgp->vrf_id,
7585 inet_ntoa(bgp->router_id), peers_cfg,
7586 peers_estb, name, bgp->l3vni,
7587 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7588 }
7589
7590 if (uj) {
7591 json_object_object_add(json, "vrfs", json_vrfs);
7592
7593 json_object_int_add(json, "totalVrfs", count);
7594
7595 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7596 json, JSON_C_TO_STRING_PRETTY));
7597 json_object_free(json);
7598 } else {
7599 if (count)
7600 vty_out(vty,
7601 "\nTotal number of VRFs (including default): %d\n",
7602 count);
7603 }
7604
7605 return CMD_SUCCESS;
7606 }
7607
7608 DEFUN (show_bgp_mac_hash,
7609 show_bgp_mac_hash_cmd,
7610 "show bgp mac hash",
7611 SHOW_STR
7612 BGP_STR
7613 "Mac Address\n"
7614 "Mac Address database\n")
7615 {
7616 bgp_mac_dump_table(vty);
7617
7618 return CMD_SUCCESS;
7619 }
7620
7621 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7622 {
7623 struct vty *vty = (struct vty *)args;
7624 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7625
7626 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7627 tip->refcnt);
7628 }
7629
7630 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7631 {
7632 vty_out(vty, "self nexthop database:\n");
7633 bgp_nexthop_show_address_hash(vty, bgp);
7634
7635 vty_out(vty, "Tunnel-ip database:\n");
7636 hash_iterate(bgp->tip_hash,
7637 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7638 vty);
7639 }
7640
7641 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7642 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7643 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7644 "martian next-hops\n"
7645 "martian next-hop database\n")
7646 {
7647 struct bgp *bgp = NULL;
7648 int idx = 0;
7649 char *name = NULL;
7650
7651 /* [<vrf> VIEWVRFNAME] */
7652 if (argv_find(argv, argc, "vrf", &idx)) {
7653 name = argv[idx + 1]->arg;
7654 if (name && strmatch(name, VRF_DEFAULT_NAME))
7655 name = NULL;
7656 } else if (argv_find(argv, argc, "view", &idx))
7657 /* [<view> VIEWVRFNAME] */
7658 name = argv[idx + 1]->arg;
7659 if (name)
7660 bgp = bgp_lookup_by_name(name);
7661 else
7662 bgp = bgp_get_default();
7663
7664 if (!bgp) {
7665 vty_out(vty, "%% No BGP process is configured\n");
7666 return CMD_WARNING;
7667 }
7668 bgp_show_martian_nexthops(vty, bgp);
7669
7670 return CMD_SUCCESS;
7671 }
7672
7673 DEFUN (show_bgp_memory,
7674 show_bgp_memory_cmd,
7675 "show [ip] bgp memory",
7676 SHOW_STR
7677 IP_STR
7678 BGP_STR
7679 "Global BGP memory statistics\n")
7680 {
7681 char memstrbuf[MTYPE_MEMSTR_LEN];
7682 unsigned long count;
7683
7684 /* RIB related usage stats */
7685 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7686 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct bgp_node)));
7689
7690 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7691 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7692 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7693 count * sizeof(struct bgp_path_info)));
7694 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7695 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7696 count,
7697 mtype_memstr(
7698 memstrbuf, sizeof(memstrbuf),
7699 count * sizeof(struct bgp_path_info_extra)));
7700
7701 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7702 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7703 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7704 count * sizeof(struct bgp_static)));
7705
7706 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7707 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7708 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7709 count * sizeof(struct bpacket)));
7710
7711 /* Adj-In/Out */
7712 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7713 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7714 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7715 count * sizeof(struct bgp_adj_in)));
7716 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7717 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7718 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7719 count * sizeof(struct bgp_adj_out)));
7720
7721 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7722 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7723 count,
7724 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7725 count * sizeof(struct bgp_nexthop_cache)));
7726
7727 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7728 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7729 count,
7730 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7731 count * sizeof(struct bgp_damp_info)));
7732
7733 /* Attributes */
7734 count = attr_count();
7735 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7736 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7737 count * sizeof(struct attr)));
7738
7739 if ((count = attr_unknown_count()))
7740 vty_out(vty, "%ld unknown attributes\n", count);
7741
7742 /* AS_PATH attributes */
7743 count = aspath_count();
7744 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7745 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7746 count * sizeof(struct aspath)));
7747
7748 count = mtype_stats_alloc(MTYPE_AS_SEG);
7749 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7750 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7751 count * sizeof(struct assegment)));
7752
7753 /* Other attributes */
7754 if ((count = community_count()))
7755 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7756 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7757 count * sizeof(struct community)));
7758 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7759 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7760 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7761 count * sizeof(struct ecommunity)));
7762 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7763 vty_out(vty,
7764 "%ld BGP large-community entries, using %s of memory\n",
7765 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7766 count * sizeof(struct lcommunity)));
7767
7768 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7769 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7770 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7771 count * sizeof(struct cluster_list)));
7772
7773 /* Peer related usage */
7774 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7775 vty_out(vty, "%ld peers, using %s of memory\n", count,
7776 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7777 count * sizeof(struct peer)));
7778
7779 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7780 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7781 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7782 count * sizeof(struct peer_group)));
7783
7784 /* Other */
7785 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7786 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7787 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7788 count * sizeof(struct hash)));
7789 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7790 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7791 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7792 count * sizeof(struct hash_bucket)));
7793 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7794 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7795 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7796 count * sizeof(regex_t)));
7797 return CMD_SUCCESS;
7798 }
7799
7800 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7801 {
7802 json_object *bestpath = json_object_new_object();
7803
7804 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7805 json_object_string_add(bestpath, "asPath", "ignore");
7806
7807 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7808 json_object_string_add(bestpath, "asPath", "confed");
7809
7810 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7811 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7812 json_object_string_add(bestpath, "multiPathRelax",
7813 "as-set");
7814 else
7815 json_object_string_add(bestpath, "multiPathRelax",
7816 "true");
7817 } else
7818 json_object_string_add(bestpath, "multiPathRelax", "false");
7819
7820 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7821 json_object_string_add(bestpath, "compareRouterId", "true");
7822 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7823 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7824 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7825 json_object_string_add(bestpath, "med", "confed");
7826 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7827 json_object_string_add(bestpath, "med",
7828 "missing-as-worst");
7829 else
7830 json_object_string_add(bestpath, "med", "true");
7831 }
7832
7833 json_object_object_add(json, "bestPath", bestpath);
7834 }
7835
7836 /* Show BGP peer's summary information. */
7837 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7838 bool use_json, json_object *json)
7839 {
7840 struct peer *peer;
7841 struct listnode *node, *nnode;
7842 unsigned int count = 0, dn_count = 0;
7843 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7844 char neighbor_buf[VTY_BUFSIZ];
7845 int neighbor_col_default_width = 16;
7846 int len;
7847 int max_neighbor_width = 0;
7848 int pfx_rcd_safi;
7849 json_object *json_peer = NULL;
7850 json_object *json_peers = NULL;
7851 struct peer_af *paf;
7852
7853 /* labeled-unicast routes are installed in the unicast table so in order
7854 * to
7855 * display the correct PfxRcd value we must look at SAFI_UNICAST
7856 */
7857 if (safi == SAFI_LABELED_UNICAST)
7858 pfx_rcd_safi = SAFI_UNICAST;
7859 else
7860 pfx_rcd_safi = safi;
7861
7862 if (use_json) {
7863 if (json == NULL)
7864 json = json_object_new_object();
7865
7866 json_peers = json_object_new_object();
7867 } else {
7868 /* Loop over all neighbors that will be displayed to determine
7869 * how many
7870 * characters are needed for the Neighbor column
7871 */
7872 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7873 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7874 continue;
7875
7876 if (peer->afc[afi][safi]) {
7877 memset(dn_flag, '\0', sizeof(dn_flag));
7878 if (peer_dynamic_neighbor(peer))
7879 dn_flag[0] = '*';
7880
7881 if (peer->hostname
7882 && bgp_flag_check(bgp,
7883 BGP_FLAG_SHOW_HOSTNAME))
7884 sprintf(neighbor_buf, "%s%s(%s) ",
7885 dn_flag, peer->hostname,
7886 peer->host);
7887 else
7888 sprintf(neighbor_buf, "%s%s ", dn_flag,
7889 peer->host);
7890
7891 len = strlen(neighbor_buf);
7892
7893 if (len > max_neighbor_width)
7894 max_neighbor_width = len;
7895 }
7896 }
7897
7898 /* Originally we displayed the Neighbor column as 16
7899 * characters wide so make that the default
7900 */
7901 if (max_neighbor_width < neighbor_col_default_width)
7902 max_neighbor_width = neighbor_col_default_width;
7903 }
7904
7905 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7906 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7907 continue;
7908
7909 if (!peer->afc[afi][safi])
7910 continue;
7911
7912 if (!count) {
7913 unsigned long ents;
7914 char memstrbuf[MTYPE_MEMSTR_LEN];
7915 int64_t vrf_id_ui;
7916
7917 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7918 ? -1
7919 : (int64_t)bgp->vrf_id;
7920
7921 /* Usage summary and header */
7922 if (use_json) {
7923 json_object_string_add(
7924 json, "routerId",
7925 inet_ntoa(bgp->router_id));
7926 json_object_int_add(json, "as", bgp->as);
7927 json_object_int_add(json, "vrfId", vrf_id_ui);
7928 json_object_string_add(
7929 json, "vrfName",
7930 (bgp->inst_type
7931 == BGP_INSTANCE_TYPE_DEFAULT)
7932 ? VRF_DEFAULT_NAME
7933 : bgp->name);
7934 } else {
7935 vty_out(vty,
7936 "BGP router identifier %s, local AS number %u vrf-id %d",
7937 inet_ntoa(bgp->router_id), bgp->as,
7938 bgp->vrf_id == VRF_UNKNOWN
7939 ? -1
7940 : (int)bgp->vrf_id);
7941 vty_out(vty, "\n");
7942 }
7943
7944 if (bgp_update_delay_configured(bgp)) {
7945 if (use_json) {
7946 json_object_int_add(
7947 json, "updateDelayLimit",
7948 bgp->v_update_delay);
7949
7950 if (bgp->v_update_delay
7951 != bgp->v_establish_wait)
7952 json_object_int_add(
7953 json,
7954 "updateDelayEstablishWait",
7955 bgp->v_establish_wait);
7956
7957 if (bgp_update_delay_active(bgp)) {
7958 json_object_string_add(
7959 json,
7960 "updateDelayFirstNeighbor",
7961 bgp->update_delay_begin_time);
7962 json_object_boolean_true_add(
7963 json,
7964 "updateDelayInProgress");
7965 } else {
7966 if (bgp->update_delay_over) {
7967 json_object_string_add(
7968 json,
7969 "updateDelayFirstNeighbor",
7970 bgp->update_delay_begin_time);
7971 json_object_string_add(
7972 json,
7973 "updateDelayBestpathResumed",
7974 bgp->update_delay_end_time);
7975 json_object_string_add(
7976 json,
7977 "updateDelayZebraUpdateResume",
7978 bgp->update_delay_zebra_resume_time);
7979 json_object_string_add(
7980 json,
7981 "updateDelayPeerUpdateResume",
7982 bgp->update_delay_peers_resume_time);
7983 }
7984 }
7985 } else {
7986 vty_out(vty,
7987 "Read-only mode update-delay limit: %d seconds\n",
7988 bgp->v_update_delay);
7989 if (bgp->v_update_delay
7990 != bgp->v_establish_wait)
7991 vty_out(vty,
7992 " Establish wait: %d seconds\n",
7993 bgp->v_establish_wait);
7994
7995 if (bgp_update_delay_active(bgp)) {
7996 vty_out(vty,
7997 " First neighbor established: %s\n",
7998 bgp->update_delay_begin_time);
7999 vty_out(vty,
8000 " Delay in progress\n");
8001 } else {
8002 if (bgp->update_delay_over) {
8003 vty_out(vty,
8004 " First neighbor established: %s\n",
8005 bgp->update_delay_begin_time);
8006 vty_out(vty,
8007 " Best-paths resumed: %s\n",
8008 bgp->update_delay_end_time);
8009 vty_out(vty,
8010 " zebra update resumed: %s\n",
8011 bgp->update_delay_zebra_resume_time);
8012 vty_out(vty,
8013 " peers update resumed: %s\n",
8014 bgp->update_delay_peers_resume_time);
8015 }
8016 }
8017 }
8018 }
8019
8020 if (use_json) {
8021 if (bgp_maxmed_onstartup_configured(bgp)
8022 && bgp->maxmed_active)
8023 json_object_boolean_true_add(
8024 json, "maxMedOnStartup");
8025 if (bgp->v_maxmed_admin)
8026 json_object_boolean_true_add(
8027 json, "maxMedAdministrative");
8028
8029 json_object_int_add(
8030 json, "tableVersion",
8031 bgp_table_version(bgp->rib[afi][safi]));
8032
8033 ents = bgp_table_count(bgp->rib[afi][safi]);
8034 json_object_int_add(json, "ribCount", ents);
8035 json_object_int_add(
8036 json, "ribMemory",
8037 ents * sizeof(struct bgp_node));
8038
8039 ents = listcount(bgp->peer);
8040 json_object_int_add(json, "peerCount", ents);
8041 json_object_int_add(json, "peerMemory",
8042 ents * sizeof(struct peer));
8043
8044 if ((ents = listcount(bgp->group))) {
8045 json_object_int_add(
8046 json, "peerGroupCount", ents);
8047 json_object_int_add(
8048 json, "peerGroupMemory",
8049 ents * sizeof(struct
8050 peer_group));
8051 }
8052
8053 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8054 BGP_CONFIG_DAMPENING))
8055 json_object_boolean_true_add(
8056 json, "dampeningEnabled");
8057 } else {
8058 if (bgp_maxmed_onstartup_configured(bgp)
8059 && bgp->maxmed_active)
8060 vty_out(vty,
8061 "Max-med on-startup active\n");
8062 if (bgp->v_maxmed_admin)
8063 vty_out(vty,
8064 "Max-med administrative active\n");
8065
8066 vty_out(vty, "BGP table version %" PRIu64 "\n",
8067 bgp_table_version(bgp->rib[afi][safi]));
8068
8069 ents = bgp_table_count(bgp->rib[afi][safi]);
8070 vty_out(vty,
8071 "RIB entries %ld, using %s of memory\n",
8072 ents,
8073 mtype_memstr(memstrbuf,
8074 sizeof(memstrbuf),
8075 ents * sizeof(struct
8076 bgp_node)));
8077
8078 /* Peer related usage */
8079 ents = listcount(bgp->peer);
8080 vty_out(vty, "Peers %ld, using %s of memory\n",
8081 ents,
8082 mtype_memstr(
8083 memstrbuf, sizeof(memstrbuf),
8084 ents * sizeof(struct peer)));
8085
8086 if ((ents = listcount(bgp->group)))
8087 vty_out(vty,
8088 "Peer groups %ld, using %s of memory\n",
8089 ents,
8090 mtype_memstr(
8091 memstrbuf,
8092 sizeof(memstrbuf),
8093 ents * sizeof(struct
8094 peer_group)));
8095
8096 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8097 BGP_CONFIG_DAMPENING))
8098 vty_out(vty, "Dampening enabled.\n");
8099 vty_out(vty, "\n");
8100
8101 /* Subtract 8 here because 'Neighbor' is
8102 * 8 characters */
8103 vty_out(vty, "Neighbor");
8104 vty_out(vty, "%*s", max_neighbor_width - 8,
8105 " ");
8106 vty_out(vty,
8107 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8108 }
8109 }
8110
8111 count++;
8112
8113 if (use_json) {
8114 json_peer = json_object_new_object();
8115
8116 if (peer_dynamic_neighbor(peer)) {
8117 dn_count++;
8118 json_object_boolean_true_add(json_peer,
8119 "dynamicPeer");
8120 }
8121
8122 if (peer->hostname)
8123 json_object_string_add(json_peer, "hostname",
8124 peer->hostname);
8125
8126 if (peer->domainname)
8127 json_object_string_add(json_peer, "domainname",
8128 peer->domainname);
8129
8130 json_object_int_add(json_peer, "remoteAs", peer->as);
8131 json_object_int_add(json_peer, "version", 4);
8132 json_object_int_add(json_peer, "msgRcvd",
8133 PEER_TOTAL_RX(peer));
8134 json_object_int_add(json_peer, "msgSent",
8135 PEER_TOTAL_TX(peer));
8136
8137 json_object_int_add(json_peer, "tableVersion",
8138 peer->version[afi][safi]);
8139 json_object_int_add(json_peer, "outq",
8140 peer->obuf->count);
8141 json_object_int_add(json_peer, "inq", 0);
8142 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8143 use_json, json_peer);
8144
8145 /*
8146 * Adding "pfxRcd" field to match with the corresponding
8147 * CLI. "prefixReceivedCount" will be deprecated in
8148 * future.
8149 */
8150 json_object_int_add(json_peer, "prefixReceivedCount",
8151 peer->pcount[afi][pfx_rcd_safi]);
8152 json_object_int_add(json_peer, "pfxRcd",
8153 peer->pcount[afi][pfx_rcd_safi]);
8154
8155 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8156 if (paf && PAF_SUBGRP(paf))
8157 json_object_int_add(json_peer,
8158 "pfxSnt",
8159 (PAF_SUBGRP(paf))->scount);
8160
8161 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8162 json_object_string_add(json_peer, "state",
8163 "Idle (Admin)");
8164 else if (peer->afc_recv[afi][safi])
8165 json_object_string_add(
8166 json_peer, "state",
8167 lookup_msg(bgp_status_msg, peer->status,
8168 NULL));
8169 else if (CHECK_FLAG(peer->sflags,
8170 PEER_STATUS_PREFIX_OVERFLOW))
8171 json_object_string_add(json_peer, "state",
8172 "Idle (PfxCt)");
8173 else
8174 json_object_string_add(
8175 json_peer, "state",
8176 lookup_msg(bgp_status_msg, peer->status,
8177 NULL));
8178
8179 if (peer->conf_if)
8180 json_object_string_add(json_peer, "idType",
8181 "interface");
8182 else if (peer->su.sa.sa_family == AF_INET)
8183 json_object_string_add(json_peer, "idType",
8184 "ipv4");
8185 else if (peer->su.sa.sa_family == AF_INET6)
8186 json_object_string_add(json_peer, "idType",
8187 "ipv6");
8188
8189 json_object_object_add(json_peers, peer->host,
8190 json_peer);
8191 } else {
8192 memset(dn_flag, '\0', sizeof(dn_flag));
8193 if (peer_dynamic_neighbor(peer)) {
8194 dn_count++;
8195 dn_flag[0] = '*';
8196 }
8197
8198 if (peer->hostname
8199 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8200 len = vty_out(vty, "%s%s(%s)", dn_flag,
8201 peer->hostname, peer->host);
8202 else
8203 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8204
8205 /* pad the neighbor column with spaces */
8206 if (len < max_neighbor_width)
8207 vty_out(vty, "%*s", max_neighbor_width - len,
8208 " ");
8209
8210 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8211 peer->as, PEER_TOTAL_RX(peer),
8212 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8213 0, peer->obuf->count,
8214 peer_uptime(peer->uptime, timebuf,
8215 BGP_UPTIME_LEN, 0, NULL));
8216
8217 if (peer->status == Established)
8218 if (peer->afc_recv[afi][safi])
8219 vty_out(vty, " %12ld",
8220 peer->pcount[afi]
8221 [pfx_rcd_safi]);
8222 else
8223 vty_out(vty, " NoNeg");
8224 else {
8225 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8226 vty_out(vty, " Idle (Admin)");
8227 else if (CHECK_FLAG(
8228 peer->sflags,
8229 PEER_STATUS_PREFIX_OVERFLOW))
8230 vty_out(vty, " Idle (PfxCt)");
8231 else
8232 vty_out(vty, " %12s",
8233 lookup_msg(bgp_status_msg,
8234 peer->status, NULL));
8235 }
8236 vty_out(vty, "\n");
8237 }
8238 }
8239
8240 if (use_json) {
8241 json_object_object_add(json, "peers", json_peers);
8242
8243 json_object_int_add(json, "totalPeers", count);
8244 json_object_int_add(json, "dynamicPeers", dn_count);
8245
8246 bgp_show_bestpath_json(bgp, json);
8247
8248 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8249 json, JSON_C_TO_STRING_PRETTY));
8250 json_object_free(json);
8251 } else {
8252 if (count)
8253 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8254 else {
8255 vty_out(vty, "No %s neighbor is configured\n",
8256 afi_safi_print(afi, safi));
8257 }
8258
8259 if (dn_count) {
8260 vty_out(vty, "* - dynamic neighbor\n");
8261 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8262 dn_count, bgp->dynamic_neighbors_limit);
8263 }
8264 }
8265
8266 return CMD_SUCCESS;
8267 }
8268
8269 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8270 int safi, bool use_json,
8271 json_object *json)
8272 {
8273 int is_first = 1;
8274 int afi_wildcard = (afi == AFI_MAX);
8275 int safi_wildcard = (safi == SAFI_MAX);
8276 int is_wildcard = (afi_wildcard || safi_wildcard);
8277 bool nbr_output = false;
8278
8279 if (use_json && is_wildcard)
8280 vty_out(vty, "{\n");
8281 if (afi_wildcard)
8282 afi = 1; /* AFI_IP */
8283 while (afi < AFI_MAX) {
8284 if (safi_wildcard)
8285 safi = 1; /* SAFI_UNICAST */
8286 while (safi < SAFI_MAX) {
8287 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8288 nbr_output = true;
8289 if (is_wildcard) {
8290 /*
8291 * So limit output to those afi/safi
8292 * pairs that
8293 * actualy have something interesting in
8294 * them
8295 */
8296 if (use_json) {
8297 json = json_object_new_object();
8298
8299 if (!is_first)
8300 vty_out(vty, ",\n");
8301 else
8302 is_first = 0;
8303
8304 vty_out(vty, "\"%s\":",
8305 afi_safi_json(afi,
8306 safi));
8307 } else {
8308 vty_out(vty, "\n%s Summary:\n",
8309 afi_safi_print(afi,
8310 safi));
8311 }
8312 }
8313 bgp_show_summary(vty, bgp, afi, safi, use_json,
8314 json);
8315 }
8316 safi++;
8317 if (!safi_wildcard)
8318 safi = SAFI_MAX;
8319 }
8320 afi++;
8321 if (!afi_wildcard)
8322 afi = AFI_MAX;
8323 }
8324
8325 if (use_json && is_wildcard)
8326 vty_out(vty, "}\n");
8327 else if (!nbr_output) {
8328 if (use_json)
8329 vty_out(vty, "{}\n");
8330 else
8331 vty_out(vty, "%% No BGP neighbors found\n");
8332 }
8333 }
8334
8335 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8336 safi_t safi, bool use_json)
8337 {
8338 struct listnode *node, *nnode;
8339 struct bgp *bgp;
8340 json_object *json = NULL;
8341 int is_first = 1;
8342 bool nbr_output = false;
8343
8344 if (use_json)
8345 vty_out(vty, "{\n");
8346
8347 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8348 nbr_output = true;
8349 if (use_json) {
8350 json = json_object_new_object();
8351
8352 if (!is_first)
8353 vty_out(vty, ",\n");
8354 else
8355 is_first = 0;
8356
8357 vty_out(vty, "\"%s\":",
8358 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8359 ? VRF_DEFAULT_NAME
8360 : bgp->name);
8361 } else {
8362 vty_out(vty, "\nInstance %s:\n",
8363 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8364 ? VRF_DEFAULT_NAME
8365 : bgp->name);
8366 }
8367 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8368 }
8369
8370 if (use_json)
8371 vty_out(vty, "}\n");
8372 else if (!nbr_output)
8373 vty_out(vty, "%% BGP instance not found\n");
8374 }
8375
8376 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8377 safi_t safi, bool use_json)
8378 {
8379 struct bgp *bgp;
8380
8381 if (name) {
8382 if (strmatch(name, "all")) {
8383 bgp_show_all_instances_summary_vty(vty, afi, safi,
8384 use_json);
8385 return CMD_SUCCESS;
8386 } else {
8387 bgp = bgp_lookup_by_name(name);
8388
8389 if (!bgp) {
8390 if (use_json)
8391 vty_out(vty, "{}\n");
8392 else
8393 vty_out(vty,
8394 "%% BGP instance not found\n");
8395 return CMD_WARNING;
8396 }
8397
8398 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8399 NULL);
8400 return CMD_SUCCESS;
8401 }
8402 }
8403
8404 bgp = bgp_get_default();
8405
8406 if (bgp)
8407 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8408 else {
8409 if (use_json)
8410 vty_out(vty, "{}\n");
8411 else
8412 vty_out(vty, "%% BGP instance not found\n");
8413 return CMD_WARNING;
8414 }
8415
8416 return CMD_SUCCESS;
8417 }
8418
8419 /* `show [ip] bgp summary' commands. */
8420 DEFUN (show_ip_bgp_summary,
8421 show_ip_bgp_summary_cmd,
8422 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8423 SHOW_STR
8424 IP_STR
8425 BGP_STR
8426 BGP_INSTANCE_HELP_STR
8427 BGP_AFI_HELP_STR
8428 BGP_SAFI_WITH_LABEL_HELP_STR
8429 "Summary of BGP neighbor status\n"
8430 JSON_STR)
8431 {
8432 char *vrf = NULL;
8433 afi_t afi = AFI_MAX;
8434 safi_t safi = SAFI_MAX;
8435
8436 int idx = 0;
8437
8438 /* show [ip] bgp */
8439 if (argv_find(argv, argc, "ip", &idx))
8440 afi = AFI_IP;
8441 /* [<vrf> VIEWVRFNAME] */
8442 if (argv_find(argv, argc, "vrf", &idx)) {
8443 vrf = argv[idx + 1]->arg;
8444 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8445 vrf = NULL;
8446 } else if (argv_find(argv, argc, "view", &idx))
8447 /* [<view> VIEWVRFNAME] */
8448 vrf = argv[idx + 1]->arg;
8449 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8450 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8451 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8452 }
8453
8454 bool uj = use_json(argc, argv);
8455
8456 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8457 }
8458
8459 const char *afi_safi_print(afi_t afi, safi_t safi)
8460 {
8461 if (afi == AFI_IP && safi == SAFI_UNICAST)
8462 return "IPv4 Unicast";
8463 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8464 return "IPv4 Multicast";
8465 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8466 return "IPv4 Labeled Unicast";
8467 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8468 return "IPv4 VPN";
8469 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8470 return "IPv4 Encap";
8471 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8472 return "IPv4 Flowspec";
8473 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8474 return "IPv6 Unicast";
8475 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8476 return "IPv6 Multicast";
8477 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8478 return "IPv6 Labeled Unicast";
8479 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8480 return "IPv6 VPN";
8481 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8482 return "IPv6 Encap";
8483 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8484 return "IPv6 Flowspec";
8485 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8486 return "L2VPN EVPN";
8487 else
8488 return "Unknown";
8489 }
8490
8491 /*
8492 * Please note that we have intentionally camelCased
8493 * the return strings here. So if you want
8494 * to use this function, please ensure you
8495 * are doing this within json output
8496 */
8497 const char *afi_safi_json(afi_t afi, safi_t safi)
8498 {
8499 if (afi == AFI_IP && safi == SAFI_UNICAST)
8500 return "ipv4Unicast";
8501 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8502 return "ipv4Multicast";
8503 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8504 return "ipv4LabeledUnicast";
8505 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8506 return "ipv4Vpn";
8507 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8508 return "ipv4Encap";
8509 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8510 return "ipv4Flowspec";
8511 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8512 return "ipv6Unicast";
8513 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8514 return "ipv6Multicast";
8515 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8516 return "ipv6LabeledUnicast";
8517 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8518 return "ipv6Vpn";
8519 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8520 return "ipv6Encap";
8521 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8522 return "ipv6Flowspec";
8523 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8524 return "l2VpnEvpn";
8525 else
8526 return "Unknown";
8527 }
8528
8529 /* Show BGP peer's information. */
8530 enum show_type { show_all, show_peer };
8531
8532 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8533 afi_t afi, safi_t safi,
8534 uint16_t adv_smcap, uint16_t adv_rmcap,
8535 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8536 bool use_json, json_object *json_pref)
8537 {
8538 /* Send-Mode */
8539 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8540 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8541 if (use_json) {
8542 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8543 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8544 json_object_string_add(json_pref, "sendMode",
8545 "advertisedAndReceived");
8546 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8547 json_object_string_add(json_pref, "sendMode",
8548 "advertised");
8549 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8550 json_object_string_add(json_pref, "sendMode",
8551 "received");
8552 } else {
8553 vty_out(vty, " Send-mode: ");
8554 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8555 vty_out(vty, "advertised");
8556 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8557 vty_out(vty, "%sreceived",
8558 CHECK_FLAG(p->af_cap[afi][safi],
8559 adv_smcap)
8560 ? ", "
8561 : "");
8562 vty_out(vty, "\n");
8563 }
8564 }
8565
8566 /* Receive-Mode */
8567 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8568 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8569 if (use_json) {
8570 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8571 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8572 json_object_string_add(json_pref, "recvMode",
8573 "advertisedAndReceived");
8574 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8575 json_object_string_add(json_pref, "recvMode",
8576 "advertised");
8577 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8578 json_object_string_add(json_pref, "recvMode",
8579 "received");
8580 } else {
8581 vty_out(vty, " Receive-mode: ");
8582 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8583 vty_out(vty, "advertised");
8584 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8585 vty_out(vty, "%sreceived",
8586 CHECK_FLAG(p->af_cap[afi][safi],
8587 adv_rmcap)
8588 ? ", "
8589 : "");
8590 vty_out(vty, "\n");
8591 }
8592 }
8593 }
8594
8595 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8596 safi_t safi, bool use_json,
8597 json_object *json_neigh)
8598 {
8599 struct bgp_filter *filter;
8600 struct peer_af *paf;
8601 char orf_pfx_name[BUFSIZ];
8602 int orf_pfx_count;
8603 json_object *json_af = NULL;
8604 json_object *json_prefA = NULL;
8605 json_object *json_prefB = NULL;
8606 json_object *json_addr = NULL;
8607
8608 if (use_json) {
8609 json_addr = json_object_new_object();
8610 json_af = json_object_new_object();
8611 filter = &p->filter[afi][safi];
8612
8613 if (peer_group_active(p))
8614 json_object_string_add(json_addr, "peerGroupMember",
8615 p->group->name);
8616
8617 paf = peer_af_find(p, afi, safi);
8618 if (paf && PAF_SUBGRP(paf)) {
8619 json_object_int_add(json_addr, "updateGroupId",
8620 PAF_UPDGRP(paf)->id);
8621 json_object_int_add(json_addr, "subGroupId",
8622 PAF_SUBGRP(paf)->id);
8623 json_object_int_add(json_addr, "packetQueueLength",
8624 bpacket_queue_virtual_length(paf));
8625 }
8626
8627 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8628 || CHECK_FLAG(p->af_cap[afi][safi],
8629 PEER_CAP_ORF_PREFIX_SM_RCV)
8630 || CHECK_FLAG(p->af_cap[afi][safi],
8631 PEER_CAP_ORF_PREFIX_RM_ADV)
8632 || CHECK_FLAG(p->af_cap[afi][safi],
8633 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8634 json_object_int_add(json_af, "orfType",
8635 ORF_TYPE_PREFIX);
8636 json_prefA = json_object_new_object();
8637 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8638 PEER_CAP_ORF_PREFIX_SM_ADV,
8639 PEER_CAP_ORF_PREFIX_RM_ADV,
8640 PEER_CAP_ORF_PREFIX_SM_RCV,
8641 PEER_CAP_ORF_PREFIX_RM_RCV,
8642 use_json, json_prefA);
8643 json_object_object_add(json_af, "orfPrefixList",
8644 json_prefA);
8645 }
8646
8647 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8648 || CHECK_FLAG(p->af_cap[afi][safi],
8649 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8650 || CHECK_FLAG(p->af_cap[afi][safi],
8651 PEER_CAP_ORF_PREFIX_RM_ADV)
8652 || CHECK_FLAG(p->af_cap[afi][safi],
8653 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8654 json_object_int_add(json_af, "orfOldType",
8655 ORF_TYPE_PREFIX_OLD);
8656 json_prefB = json_object_new_object();
8657 bgp_show_peer_afi_orf_cap(
8658 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8659 PEER_CAP_ORF_PREFIX_RM_ADV,
8660 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8661 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8662 json_prefB);
8663 json_object_object_add(json_af, "orfOldPrefixList",
8664 json_prefB);
8665 }
8666
8667 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8668 || CHECK_FLAG(p->af_cap[afi][safi],
8669 PEER_CAP_ORF_PREFIX_SM_RCV)
8670 || CHECK_FLAG(p->af_cap[afi][safi],
8671 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8672 || CHECK_FLAG(p->af_cap[afi][safi],
8673 PEER_CAP_ORF_PREFIX_RM_ADV)
8674 || CHECK_FLAG(p->af_cap[afi][safi],
8675 PEER_CAP_ORF_PREFIX_RM_RCV)
8676 || CHECK_FLAG(p->af_cap[afi][safi],
8677 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8678 json_object_object_add(json_addr, "afDependentCap",
8679 json_af);
8680 else
8681 json_object_free(json_af);
8682
8683 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8684 orf_pfx_count = prefix_bgp_show_prefix_list(
8685 NULL, afi, orf_pfx_name, use_json);
8686
8687 if (CHECK_FLAG(p->af_sflags[afi][safi],
8688 PEER_STATUS_ORF_PREFIX_SEND)
8689 || orf_pfx_count) {
8690 if (CHECK_FLAG(p->af_sflags[afi][safi],
8691 PEER_STATUS_ORF_PREFIX_SEND))
8692 json_object_boolean_true_add(json_neigh,
8693 "orfSent");
8694 if (orf_pfx_count)
8695 json_object_int_add(json_addr, "orfRecvCounter",
8696 orf_pfx_count);
8697 }
8698 if (CHECK_FLAG(p->af_sflags[afi][safi],
8699 PEER_STATUS_ORF_WAIT_REFRESH))
8700 json_object_string_add(
8701 json_addr, "orfFirstUpdate",
8702 "deferredUntilORFOrRouteRefreshRecvd");
8703
8704 if (CHECK_FLAG(p->af_flags[afi][safi],
8705 PEER_FLAG_REFLECTOR_CLIENT))
8706 json_object_boolean_true_add(json_addr,
8707 "routeReflectorClient");
8708 if (CHECK_FLAG(p->af_flags[afi][safi],
8709 PEER_FLAG_RSERVER_CLIENT))
8710 json_object_boolean_true_add(json_addr,
8711 "routeServerClient");
8712 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8713 json_object_boolean_true_add(json_addr,
8714 "inboundSoftConfigPermit");
8715
8716 if (CHECK_FLAG(p->af_flags[afi][safi],
8717 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8718 json_object_boolean_true_add(
8719 json_addr,
8720 "privateAsNumsAllReplacedInUpdatesToNbr");
8721 else if (CHECK_FLAG(p->af_flags[afi][safi],
8722 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8723 json_object_boolean_true_add(
8724 json_addr,
8725 "privateAsNumsReplacedInUpdatesToNbr");
8726 else if (CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8728 json_object_boolean_true_add(
8729 json_addr,
8730 "privateAsNumsAllRemovedInUpdatesToNbr");
8731 else if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_REMOVE_PRIVATE_AS))
8733 json_object_boolean_true_add(
8734 json_addr,
8735 "privateAsNumsRemovedInUpdatesToNbr");
8736
8737 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8738 json_object_boolean_true_add(
8739 json_addr,
8740 bgp_addpath_names(p->addpath_type[afi][safi])
8741 ->type_json_name);
8742
8743 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8744 json_object_string_add(json_addr,
8745 "overrideASNsInOutboundUpdates",
8746 "ifAspathEqualRemoteAs");
8747
8748 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8749 || CHECK_FLAG(p->af_flags[afi][safi],
8750 PEER_FLAG_FORCE_NEXTHOP_SELF))
8751 json_object_boolean_true_add(json_addr,
8752 "routerAlwaysNextHop");
8753 if (CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_AS_PATH_UNCHANGED))
8755 json_object_boolean_true_add(
8756 json_addr, "unchangedAsPathPropogatedToNbr");
8757 if (CHECK_FLAG(p->af_flags[afi][safi],
8758 PEER_FLAG_NEXTHOP_UNCHANGED))
8759 json_object_boolean_true_add(
8760 json_addr, "unchangedNextHopPropogatedToNbr");
8761 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8762 json_object_boolean_true_add(
8763 json_addr, "unchangedMedPropogatedToNbr");
8764 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8765 || CHECK_FLAG(p->af_flags[afi][safi],
8766 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8767 if (CHECK_FLAG(p->af_flags[afi][safi],
8768 PEER_FLAG_SEND_COMMUNITY)
8769 && CHECK_FLAG(p->af_flags[afi][safi],
8770 PEER_FLAG_SEND_EXT_COMMUNITY))
8771 json_object_string_add(json_addr,
8772 "commAttriSentToNbr",
8773 "extendedAndStandard");
8774 else if (CHECK_FLAG(p->af_flags[afi][safi],
8775 PEER_FLAG_SEND_EXT_COMMUNITY))
8776 json_object_string_add(json_addr,
8777 "commAttriSentToNbr",
8778 "extended");
8779 else
8780 json_object_string_add(json_addr,
8781 "commAttriSentToNbr",
8782 "standard");
8783 }
8784 if (CHECK_FLAG(p->af_flags[afi][safi],
8785 PEER_FLAG_DEFAULT_ORIGINATE)) {
8786 if (p->default_rmap[afi][safi].name)
8787 json_object_string_add(
8788 json_addr, "defaultRouteMap",
8789 p->default_rmap[afi][safi].name);
8790
8791 if (paf && PAF_SUBGRP(paf)
8792 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8793 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8794 json_object_boolean_true_add(json_addr,
8795 "defaultSent");
8796 else
8797 json_object_boolean_true_add(json_addr,
8798 "defaultNotSent");
8799 }
8800
8801 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8802 if (is_evpn_enabled())
8803 json_object_boolean_true_add(
8804 json_addr, "advertiseAllVnis");
8805 }
8806
8807 if (filter->plist[FILTER_IN].name
8808 || filter->dlist[FILTER_IN].name
8809 || filter->aslist[FILTER_IN].name
8810 || filter->map[RMAP_IN].name)
8811 json_object_boolean_true_add(json_addr,
8812 "inboundPathPolicyConfig");
8813 if (filter->plist[FILTER_OUT].name
8814 || filter->dlist[FILTER_OUT].name
8815 || filter->aslist[FILTER_OUT].name
8816 || filter->map[RMAP_OUT].name || filter->usmap.name)
8817 json_object_boolean_true_add(
8818 json_addr, "outboundPathPolicyConfig");
8819
8820 /* prefix-list */
8821 if (filter->plist[FILTER_IN].name)
8822 json_object_string_add(json_addr,
8823 "incomingUpdatePrefixFilterList",
8824 filter->plist[FILTER_IN].name);
8825 if (filter->plist[FILTER_OUT].name)
8826 json_object_string_add(json_addr,
8827 "outgoingUpdatePrefixFilterList",
8828 filter->plist[FILTER_OUT].name);
8829
8830 /* distribute-list */
8831 if (filter->dlist[FILTER_IN].name)
8832 json_object_string_add(
8833 json_addr, "incomingUpdateNetworkFilterList",
8834 filter->dlist[FILTER_IN].name);
8835 if (filter->dlist[FILTER_OUT].name)
8836 json_object_string_add(
8837 json_addr, "outgoingUpdateNetworkFilterList",
8838 filter->dlist[FILTER_OUT].name);
8839
8840 /* filter-list. */
8841 if (filter->aslist[FILTER_IN].name)
8842 json_object_string_add(json_addr,
8843 "incomingUpdateAsPathFilterList",
8844 filter->aslist[FILTER_IN].name);
8845 if (filter->aslist[FILTER_OUT].name)
8846 json_object_string_add(json_addr,
8847 "outgoingUpdateAsPathFilterList",
8848 filter->aslist[FILTER_OUT].name);
8849
8850 /* route-map. */
8851 if (filter->map[RMAP_IN].name)
8852 json_object_string_add(
8853 json_addr, "routeMapForIncomingAdvertisements",
8854 filter->map[RMAP_IN].name);
8855 if (filter->map[RMAP_OUT].name)
8856 json_object_string_add(
8857 json_addr, "routeMapForOutgoingAdvertisements",
8858 filter->map[RMAP_OUT].name);
8859
8860 /* ebgp-requires-policy (inbound) */
8861 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8862 && !bgp_inbound_policy_exists(p, filter))
8863 json_object_string_add(
8864 json_addr, "inboundEbgpRequiresPolicy",
8865 "Inbound updates discarded due to missing policy");
8866
8867 /* ebgp-requires-policy (outbound) */
8868 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8869 && (!bgp_outbound_policy_exists(p, filter)))
8870 json_object_string_add(
8871 json_addr, "outboundEbgpRequiresPolicy",
8872 "Outbound updates discarded due to missing policy");
8873
8874 /* unsuppress-map */
8875 if (filter->usmap.name)
8876 json_object_string_add(json_addr,
8877 "selectiveUnsuppressRouteMap",
8878 filter->usmap.name);
8879
8880 /* Receive prefix count */
8881 json_object_int_add(json_addr, "acceptedPrefixCounter",
8882 p->pcount[afi][safi]);
8883 if (paf && PAF_SUBGRP(paf))
8884 json_object_int_add(json_addr, "sentPrefixCounter",
8885 (PAF_SUBGRP(paf))->scount);
8886
8887 /* Maximum prefix */
8888 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8889 json_object_int_add(json_addr, "prefixAllowedMax",
8890 p->pmax[afi][safi]);
8891 if (CHECK_FLAG(p->af_flags[afi][safi],
8892 PEER_FLAG_MAX_PREFIX_WARNING))
8893 json_object_boolean_true_add(
8894 json_addr, "prefixAllowedMaxWarning");
8895 json_object_int_add(json_addr,
8896 "prefixAllowedWarningThresh",
8897 p->pmax_threshold[afi][safi]);
8898 if (p->pmax_restart[afi][safi])
8899 json_object_int_add(
8900 json_addr,
8901 "prefixAllowedRestartIntervalMsecs",
8902 p->pmax_restart[afi][safi] * 60000);
8903 }
8904 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8905 json_addr);
8906
8907 } else {
8908 filter = &p->filter[afi][safi];
8909
8910 vty_out(vty, " For address family: %s\n",
8911 afi_safi_print(afi, safi));
8912
8913 if (peer_group_active(p))
8914 vty_out(vty, " %s peer-group member\n",
8915 p->group->name);
8916
8917 paf = peer_af_find(p, afi, safi);
8918 if (paf && PAF_SUBGRP(paf)) {
8919 vty_out(vty, " Update group %" PRIu64
8920 ", subgroup %" PRIu64 "\n",
8921 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8922 vty_out(vty, " Packet Queue length %d\n",
8923 bpacket_queue_virtual_length(paf));
8924 } else {
8925 vty_out(vty, " Not part of any update group\n");
8926 }
8927 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8928 || CHECK_FLAG(p->af_cap[afi][safi],
8929 PEER_CAP_ORF_PREFIX_SM_RCV)
8930 || CHECK_FLAG(p->af_cap[afi][safi],
8931 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8932 || CHECK_FLAG(p->af_cap[afi][safi],
8933 PEER_CAP_ORF_PREFIX_RM_ADV)
8934 || CHECK_FLAG(p->af_cap[afi][safi],
8935 PEER_CAP_ORF_PREFIX_RM_RCV)
8936 || CHECK_FLAG(p->af_cap[afi][safi],
8937 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8938 vty_out(vty, " AF-dependant capabilities:\n");
8939
8940 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8941 || CHECK_FLAG(p->af_cap[afi][safi],
8942 PEER_CAP_ORF_PREFIX_SM_RCV)
8943 || CHECK_FLAG(p->af_cap[afi][safi],
8944 PEER_CAP_ORF_PREFIX_RM_ADV)
8945 || CHECK_FLAG(p->af_cap[afi][safi],
8946 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8947 vty_out(vty,
8948 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8949 ORF_TYPE_PREFIX);
8950 bgp_show_peer_afi_orf_cap(
8951 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8952 PEER_CAP_ORF_PREFIX_RM_ADV,
8953 PEER_CAP_ORF_PREFIX_SM_RCV,
8954 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8955 }
8956 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8957 || CHECK_FLAG(p->af_cap[afi][safi],
8958 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8959 || CHECK_FLAG(p->af_cap[afi][safi],
8960 PEER_CAP_ORF_PREFIX_RM_ADV)
8961 || CHECK_FLAG(p->af_cap[afi][safi],
8962 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8963 vty_out(vty,
8964 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8965 ORF_TYPE_PREFIX_OLD);
8966 bgp_show_peer_afi_orf_cap(
8967 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8968 PEER_CAP_ORF_PREFIX_RM_ADV,
8969 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8970 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8971 }
8972
8973 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8974 orf_pfx_count = prefix_bgp_show_prefix_list(
8975 NULL, afi, orf_pfx_name, use_json);
8976
8977 if (CHECK_FLAG(p->af_sflags[afi][safi],
8978 PEER_STATUS_ORF_PREFIX_SEND)
8979 || orf_pfx_count) {
8980 vty_out(vty, " Outbound Route Filter (ORF):");
8981 if (CHECK_FLAG(p->af_sflags[afi][safi],
8982 PEER_STATUS_ORF_PREFIX_SEND))
8983 vty_out(vty, " sent;");
8984 if (orf_pfx_count)
8985 vty_out(vty, " received (%d entries)",
8986 orf_pfx_count);
8987 vty_out(vty, "\n");
8988 }
8989 if (CHECK_FLAG(p->af_sflags[afi][safi],
8990 PEER_STATUS_ORF_WAIT_REFRESH))
8991 vty_out(vty,
8992 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8993
8994 if (CHECK_FLAG(p->af_flags[afi][safi],
8995 PEER_FLAG_REFLECTOR_CLIENT))
8996 vty_out(vty, " Route-Reflector Client\n");
8997 if (CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_RSERVER_CLIENT))
8999 vty_out(vty, " Route-Server Client\n");
9000 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9001 vty_out(vty,
9002 " Inbound soft reconfiguration allowed\n");
9003
9004 if (CHECK_FLAG(p->af_flags[afi][safi],
9005 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9006 vty_out(vty,
9007 " Private AS numbers (all) replaced in updates to this neighbor\n");
9008 else if (CHECK_FLAG(p->af_flags[afi][safi],
9009 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9010 vty_out(vty,
9011 " Private AS numbers replaced in updates to this neighbor\n");
9012 else if (CHECK_FLAG(p->af_flags[afi][safi],
9013 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9014 vty_out(vty,
9015 " Private AS numbers (all) removed in updates to this neighbor\n");
9016 else if (CHECK_FLAG(p->af_flags[afi][safi],
9017 PEER_FLAG_REMOVE_PRIVATE_AS))
9018 vty_out(vty,
9019 " Private AS numbers removed in updates to this neighbor\n");
9020
9021 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9022 vty_out(vty, " %s\n",
9023 bgp_addpath_names(p->addpath_type[afi][safi])
9024 ->human_description);
9025
9026 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9027 vty_out(vty,
9028 " Override ASNs in outbound updates if aspath equals remote-as\n");
9029
9030 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9031 || CHECK_FLAG(p->af_flags[afi][safi],
9032 PEER_FLAG_FORCE_NEXTHOP_SELF))
9033 vty_out(vty, " NEXT_HOP is always this router\n");
9034 if (CHECK_FLAG(p->af_flags[afi][safi],
9035 PEER_FLAG_AS_PATH_UNCHANGED))
9036 vty_out(vty,
9037 " AS_PATH is propagated unchanged to this neighbor\n");
9038 if (CHECK_FLAG(p->af_flags[afi][safi],
9039 PEER_FLAG_NEXTHOP_UNCHANGED))
9040 vty_out(vty,
9041 " NEXT_HOP is propagated unchanged to this neighbor\n");
9042 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9043 vty_out(vty,
9044 " MED is propagated unchanged to this neighbor\n");
9045 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9046 || CHECK_FLAG(p->af_flags[afi][safi],
9047 PEER_FLAG_SEND_EXT_COMMUNITY)
9048 || CHECK_FLAG(p->af_flags[afi][safi],
9049 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9050 vty_out(vty,
9051 " Community attribute sent to this neighbor");
9052 if (CHECK_FLAG(p->af_flags[afi][safi],
9053 PEER_FLAG_SEND_COMMUNITY)
9054 && CHECK_FLAG(p->af_flags[afi][safi],
9055 PEER_FLAG_SEND_EXT_COMMUNITY)
9056 && CHECK_FLAG(p->af_flags[afi][safi],
9057 PEER_FLAG_SEND_LARGE_COMMUNITY))
9058 vty_out(vty, "(all)\n");
9059 else if (CHECK_FLAG(p->af_flags[afi][safi],
9060 PEER_FLAG_SEND_LARGE_COMMUNITY))
9061 vty_out(vty, "(large)\n");
9062 else if (CHECK_FLAG(p->af_flags[afi][safi],
9063 PEER_FLAG_SEND_EXT_COMMUNITY))
9064 vty_out(vty, "(extended)\n");
9065 else
9066 vty_out(vty, "(standard)\n");
9067 }
9068 if (CHECK_FLAG(p->af_flags[afi][safi],
9069 PEER_FLAG_DEFAULT_ORIGINATE)) {
9070 vty_out(vty, " Default information originate,");
9071
9072 if (p->default_rmap[afi][safi].name)
9073 vty_out(vty, " default route-map %s%s,",
9074 p->default_rmap[afi][safi].map ? "*"
9075 : "",
9076 p->default_rmap[afi][safi].name);
9077 if (paf && PAF_SUBGRP(paf)
9078 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9079 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9080 vty_out(vty, " default sent\n");
9081 else
9082 vty_out(vty, " default not sent\n");
9083 }
9084
9085 /* advertise-vni-all */
9086 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9087 if (is_evpn_enabled())
9088 vty_out(vty, " advertise-all-vni\n");
9089 }
9090
9091 if (filter->plist[FILTER_IN].name
9092 || filter->dlist[FILTER_IN].name
9093 || filter->aslist[FILTER_IN].name
9094 || filter->map[RMAP_IN].name)
9095 vty_out(vty, " Inbound path policy configured\n");
9096 if (filter->plist[FILTER_OUT].name
9097 || filter->dlist[FILTER_OUT].name
9098 || filter->aslist[FILTER_OUT].name
9099 || filter->map[RMAP_OUT].name || filter->usmap.name)
9100 vty_out(vty, " Outbound path policy configured\n");
9101
9102 /* prefix-list */
9103 if (filter->plist[FILTER_IN].name)
9104 vty_out(vty,
9105 " Incoming update prefix filter list is %s%s\n",
9106 filter->plist[FILTER_IN].plist ? "*" : "",
9107 filter->plist[FILTER_IN].name);
9108 if (filter->plist[FILTER_OUT].name)
9109 vty_out(vty,
9110 " Outgoing update prefix filter list is %s%s\n",
9111 filter->plist[FILTER_OUT].plist ? "*" : "",
9112 filter->plist[FILTER_OUT].name);
9113
9114 /* distribute-list */
9115 if (filter->dlist[FILTER_IN].name)
9116 vty_out(vty,
9117 " Incoming update network filter list is %s%s\n",
9118 filter->dlist[FILTER_IN].alist ? "*" : "",
9119 filter->dlist[FILTER_IN].name);
9120 if (filter->dlist[FILTER_OUT].name)
9121 vty_out(vty,
9122 " Outgoing update network filter list is %s%s\n",
9123 filter->dlist[FILTER_OUT].alist ? "*" : "",
9124 filter->dlist[FILTER_OUT].name);
9125
9126 /* filter-list. */
9127 if (filter->aslist[FILTER_IN].name)
9128 vty_out(vty,
9129 " Incoming update AS path filter list is %s%s\n",
9130 filter->aslist[FILTER_IN].aslist ? "*" : "",
9131 filter->aslist[FILTER_IN].name);
9132 if (filter->aslist[FILTER_OUT].name)
9133 vty_out(vty,
9134 " Outgoing update AS path filter list is %s%s\n",
9135 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9136 filter->aslist[FILTER_OUT].name);
9137
9138 /* route-map. */
9139 if (filter->map[RMAP_IN].name)
9140 vty_out(vty,
9141 " Route map for incoming advertisements is %s%s\n",
9142 filter->map[RMAP_IN].map ? "*" : "",
9143 filter->map[RMAP_IN].name);
9144 if (filter->map[RMAP_OUT].name)
9145 vty_out(vty,
9146 " Route map for outgoing advertisements is %s%s\n",
9147 filter->map[RMAP_OUT].map ? "*" : "",
9148 filter->map[RMAP_OUT].name);
9149
9150 /* ebgp-requires-policy (inbound) */
9151 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9152 && !bgp_inbound_policy_exists(p, filter))
9153 vty_out(vty,
9154 " Inbound updates discarded due to missing policy\n");
9155
9156 /* ebgp-requires-policy (outbound) */
9157 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9158 && !bgp_outbound_policy_exists(p, filter))
9159 vty_out(vty,
9160 " Outbound updates discarded due to missing policy\n");
9161
9162 /* unsuppress-map */
9163 if (filter->usmap.name)
9164 vty_out(vty,
9165 " Route map for selective unsuppress is %s%s\n",
9166 filter->usmap.map ? "*" : "",
9167 filter->usmap.name);
9168
9169 /* Receive prefix count */
9170 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9171
9172 /* Maximum prefix */
9173 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9174 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9175 p->pmax[afi][safi],
9176 CHECK_FLAG(p->af_flags[afi][safi],
9177 PEER_FLAG_MAX_PREFIX_WARNING)
9178 ? " (warning-only)"
9179 : "");
9180 vty_out(vty, " Threshold for warning message %d%%",
9181 p->pmax_threshold[afi][safi]);
9182 if (p->pmax_restart[afi][safi])
9183 vty_out(vty, ", restart interval %d min",
9184 p->pmax_restart[afi][safi]);
9185 vty_out(vty, "\n");
9186 }
9187
9188 vty_out(vty, "\n");
9189 }
9190 }
9191
9192 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9193 json_object *json)
9194 {
9195 struct bgp *bgp;
9196 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9197 char timebuf[BGP_UPTIME_LEN];
9198 char dn_flag[2];
9199 const char *subcode_str;
9200 const char *code_str;
9201 afi_t afi;
9202 safi_t safi;
9203 uint16_t i;
9204 uint8_t *msg;
9205 json_object *json_neigh = NULL;
9206 time_t epoch_tbuf;
9207
9208 bgp = p->bgp;
9209
9210 if (use_json)
9211 json_neigh = json_object_new_object();
9212
9213 memset(dn_flag, '\0', sizeof(dn_flag));
9214 if (!p->conf_if && peer_dynamic_neighbor(p))
9215 dn_flag[0] = '*';
9216
9217 if (!use_json) {
9218 if (p->conf_if) /* Configured interface name. */
9219 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9220 BGP_PEER_SU_UNSPEC(p)
9221 ? "None"
9222 : sockunion2str(&p->su, buf,
9223 SU_ADDRSTRLEN));
9224 else /* Configured IP address. */
9225 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9226 p->host);
9227 }
9228
9229 if (use_json) {
9230 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9231 json_object_string_add(json_neigh, "bgpNeighborAddr",
9232 "none");
9233 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9234 json_object_string_add(
9235 json_neigh, "bgpNeighborAddr",
9236 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9237
9238 json_object_int_add(json_neigh, "remoteAs", p->as);
9239
9240 if (p->change_local_as)
9241 json_object_int_add(json_neigh, "localAs",
9242 p->change_local_as);
9243 else
9244 json_object_int_add(json_neigh, "localAs", p->local_as);
9245
9246 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9247 json_object_boolean_true_add(json_neigh,
9248 "localAsNoPrepend");
9249
9250 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9251 json_object_boolean_true_add(json_neigh,
9252 "localAsReplaceAs");
9253 } else {
9254 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9255 || (p->as_type == AS_INTERNAL))
9256 vty_out(vty, "remote AS %u, ", p->as);
9257 else
9258 vty_out(vty, "remote AS Unspecified, ");
9259 vty_out(vty, "local AS %u%s%s, ",
9260 p->change_local_as ? p->change_local_as : p->local_as,
9261 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9262 ? " no-prepend"
9263 : "",
9264 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9265 ? " replace-as"
9266 : "");
9267 }
9268 /* peer type internal or confed-internal */
9269 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9270 if (use_json) {
9271 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9272 json_object_boolean_true_add(
9273 json_neigh, "nbrConfedInternalLink");
9274 else
9275 json_object_boolean_true_add(json_neigh,
9276 "nbrInternalLink");
9277 } else {
9278 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9279 vty_out(vty, "confed-internal link\n");
9280 else
9281 vty_out(vty, "internal link\n");
9282 }
9283 /* peer type external or confed-external */
9284 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9285 if (use_json) {
9286 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9287 json_object_boolean_true_add(
9288 json_neigh, "nbrConfedExternalLink");
9289 else
9290 json_object_boolean_true_add(json_neigh,
9291 "nbrExternalLink");
9292 } else {
9293 if (bgp_confederation_peers_check(bgp, p->as))
9294 vty_out(vty, "confed-external link\n");
9295 else
9296 vty_out(vty, "external link\n");
9297 }
9298 } else {
9299 if (use_json)
9300 json_object_boolean_true_add(json_neigh,
9301 "nbrUnspecifiedLink");
9302 else
9303 vty_out(vty, "unspecified link\n");
9304 }
9305
9306 /* Description. */
9307 if (p->desc) {
9308 if (use_json)
9309 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9310 else
9311 vty_out(vty, " Description: %s\n", p->desc);
9312 }
9313
9314 if (p->hostname) {
9315 if (use_json) {
9316 if (p->hostname)
9317 json_object_string_add(json_neigh, "hostname",
9318 p->hostname);
9319
9320 if (p->domainname)
9321 json_object_string_add(json_neigh, "domainname",
9322 p->domainname);
9323 } else {
9324 if (p->domainname && (p->domainname[0] != '\0'))
9325 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9326 p->domainname);
9327 else
9328 vty_out(vty, "Hostname: %s\n", p->hostname);
9329 }
9330 }
9331
9332 /* Peer-group */
9333 if (p->group) {
9334 if (use_json) {
9335 json_object_string_add(json_neigh, "peerGroup",
9336 p->group->name);
9337
9338 if (dn_flag[0]) {
9339 struct prefix prefix, *range = NULL;
9340
9341 sockunion2hostprefix(&(p->su), &prefix);
9342 range = peer_group_lookup_dynamic_neighbor_range(
9343 p->group, &prefix);
9344
9345 if (range) {
9346 prefix2str(range, buf1, sizeof(buf1));
9347 json_object_string_add(
9348 json_neigh,
9349 "peerSubnetRangeGroup", buf1);
9350 }
9351 }
9352 } else {
9353 vty_out(vty,
9354 " Member of peer-group %s for session parameters\n",
9355 p->group->name);
9356
9357 if (dn_flag[0]) {
9358 struct prefix prefix, *range = NULL;
9359
9360 sockunion2hostprefix(&(p->su), &prefix);
9361 range = peer_group_lookup_dynamic_neighbor_range(
9362 p->group, &prefix);
9363
9364 if (range) {
9365 prefix2str(range, buf1, sizeof(buf1));
9366 vty_out(vty,
9367 " Belongs to the subnet range group: %s\n",
9368 buf1);
9369 }
9370 }
9371 }
9372 }
9373
9374 if (use_json) {
9375 /* Administrative shutdown. */
9376 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9377 json_object_boolean_true_add(json_neigh,
9378 "adminShutDown");
9379
9380 /* BGP Version. */
9381 json_object_int_add(json_neigh, "bgpVersion", 4);
9382 json_object_string_add(
9383 json_neigh, "remoteRouterId",
9384 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9385 json_object_string_add(
9386 json_neigh, "localRouterId",
9387 inet_ntop(AF_INET, &bgp->router_id, buf1,
9388 sizeof(buf1)));
9389
9390 /* Confederation */
9391 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9392 && bgp_confederation_peers_check(bgp, p->as))
9393 json_object_boolean_true_add(json_neigh,
9394 "nbrCommonAdmin");
9395
9396 /* Status. */
9397 json_object_string_add(
9398 json_neigh, "bgpState",
9399 lookup_msg(bgp_status_msg, p->status, NULL));
9400
9401 if (p->status == Established) {
9402 time_t uptime;
9403
9404 uptime = bgp_clock();
9405 uptime -= p->uptime;
9406 epoch_tbuf = time(NULL) - uptime;
9407
9408 #if CONFDATE > 20200101
9409 CPP_NOTICE(
9410 "bgpTimerUp should be deprecated and can be removed now");
9411 #endif
9412 /*
9413 * bgpTimerUp was miliseconds that was accurate
9414 * up to 1 day, then the value returned
9415 * became garbage. So in order to provide
9416 * some level of backwards compatability,
9417 * we still provde the data, but now
9418 * we are returning the correct value
9419 * and also adding a new bgpTimerUpMsec
9420 * which will allow us to deprecate
9421 * this eventually
9422 */
9423 json_object_int_add(json_neigh, "bgpTimerUp",
9424 uptime * 1000);
9425 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9426 uptime * 1000);
9427 json_object_string_add(json_neigh, "bgpTimerUpString",
9428 peer_uptime(p->uptime, timebuf,
9429 BGP_UPTIME_LEN, 0,
9430 NULL));
9431 json_object_int_add(json_neigh,
9432 "bgpTimerUpEstablishedEpoch",
9433 epoch_tbuf);
9434 }
9435
9436 else if (p->status == Active) {
9437 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9438 json_object_string_add(json_neigh, "bgpStateIs",
9439 "passive");
9440 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9441 json_object_string_add(json_neigh, "bgpStateIs",
9442 "passiveNSF");
9443 }
9444
9445 /* read timer */
9446 time_t uptime;
9447 struct tm *tm;
9448
9449 uptime = bgp_clock();
9450 uptime -= p->readtime;
9451 tm = gmtime(&uptime);
9452 json_object_int_add(json_neigh, "bgpTimerLastRead",
9453 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9454 + (tm->tm_hour * 3600000));
9455
9456 uptime = bgp_clock();
9457 uptime -= p->last_write;
9458 tm = gmtime(&uptime);
9459 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9460 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9461 + (tm->tm_hour * 3600000));
9462
9463 uptime = bgp_clock();
9464 uptime -= p->update_time;
9465 tm = gmtime(&uptime);
9466 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9467 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9468 + (tm->tm_hour * 3600000));
9469
9470 /* Configured timer values. */
9471 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9472 p->v_holdtime * 1000);
9473 json_object_int_add(json_neigh,
9474 "bgpTimerKeepAliveIntervalMsecs",
9475 p->v_keepalive * 1000);
9476 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9477 json_object_int_add(json_neigh,
9478 "bgpTimerConfiguredHoldTimeMsecs",
9479 p->holdtime * 1000);
9480 json_object_int_add(
9481 json_neigh,
9482 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9483 p->keepalive * 1000);
9484 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9485 || (bgp->default_keepalive
9486 != BGP_DEFAULT_KEEPALIVE)) {
9487 json_object_int_add(json_neigh,
9488 "bgpTimerConfiguredHoldTimeMsecs",
9489 bgp->default_holdtime);
9490 json_object_int_add(
9491 json_neigh,
9492 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9493 bgp->default_keepalive);
9494 }
9495 } else {
9496 /* Administrative shutdown. */
9497 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9498 vty_out(vty, " Administratively shut down\n");
9499
9500 /* BGP Version. */
9501 vty_out(vty, " BGP version 4");
9502 vty_out(vty, ", remote router ID %s",
9503 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9504 vty_out(vty, ", local router ID %s\n",
9505 inet_ntop(AF_INET, &bgp->router_id, buf1,
9506 sizeof(buf1)));
9507
9508 /* Confederation */
9509 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9510 && bgp_confederation_peers_check(bgp, p->as))
9511 vty_out(vty,
9512 " Neighbor under common administration\n");
9513
9514 /* Status. */
9515 vty_out(vty, " BGP state = %s",
9516 lookup_msg(bgp_status_msg, p->status, NULL));
9517
9518 if (p->status == Established)
9519 vty_out(vty, ", up for %8s",
9520 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9521 0, NULL));
9522
9523 else if (p->status == Active) {
9524 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9525 vty_out(vty, " (passive)");
9526 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9527 vty_out(vty, " (NSF passive)");
9528 }
9529 vty_out(vty, "\n");
9530
9531 /* read timer */
9532 vty_out(vty, " Last read %s",
9533 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9534 NULL));
9535 vty_out(vty, ", Last write %s\n",
9536 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9537 NULL));
9538
9539 /* Configured timer values. */
9540 vty_out(vty,
9541 " Hold time is %d, keepalive interval is %d seconds\n",
9542 p->v_holdtime, p->v_keepalive);
9543 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9544 vty_out(vty, " Configured hold time is %d",
9545 p->holdtime);
9546 vty_out(vty, ", keepalive interval is %d seconds\n",
9547 p->keepalive);
9548 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9549 || (bgp->default_keepalive
9550 != BGP_DEFAULT_KEEPALIVE)) {
9551 vty_out(vty, " Configured hold time is %d",
9552 bgp->default_holdtime);
9553 vty_out(vty, ", keepalive interval is %d seconds\n",
9554 bgp->default_keepalive);
9555 }
9556 }
9557 /* Capability. */
9558 if (p->status == Established) {
9559 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9560 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9561 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9562 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9563 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9564 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9565 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9566 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9567 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9568 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9569 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9570 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9571 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9572 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9573 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9574 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9575 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9576 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9577 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9578 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9579 if (use_json) {
9580 json_object *json_cap = NULL;
9581
9582 json_cap = json_object_new_object();
9583
9584 /* AS4 */
9585 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9586 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9587 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9588 && CHECK_FLAG(p->cap,
9589 PEER_CAP_AS4_RCV))
9590 json_object_string_add(
9591 json_cap, "4byteAs",
9592 "advertisedAndReceived");
9593 else if (CHECK_FLAG(p->cap,
9594 PEER_CAP_AS4_ADV))
9595 json_object_string_add(
9596 json_cap, "4byteAs",
9597 "advertised");
9598 else if (CHECK_FLAG(p->cap,
9599 PEER_CAP_AS4_RCV))
9600 json_object_string_add(
9601 json_cap, "4byteAs",
9602 "received");
9603 }
9604
9605 /* AddPath */
9606 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9607 || CHECK_FLAG(p->cap,
9608 PEER_CAP_ADDPATH_ADV)) {
9609 json_object *json_add = NULL;
9610 const char *print_store;
9611
9612 json_add = json_object_new_object();
9613
9614 FOREACH_AFI_SAFI (afi, safi) {
9615 json_object *json_sub = NULL;
9616 json_sub =
9617 json_object_new_object();
9618 print_store = afi_safi_print(
9619 afi, safi);
9620
9621 if (CHECK_FLAG(
9622 p->af_cap[afi]
9623 [safi],
9624 PEER_CAP_ADDPATH_AF_TX_ADV)
9625 || CHECK_FLAG(
9626 p->af_cap[afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9629 if (CHECK_FLAG(
9630 p->af_cap
9631 [afi]
9632 [safi],
9633 PEER_CAP_ADDPATH_AF_TX_ADV)
9634 && CHECK_FLAG(
9635 p->af_cap
9636 [afi]
9637 [safi],
9638 PEER_CAP_ADDPATH_AF_TX_RCV))
9639 json_object_boolean_true_add(
9640 json_sub,
9641 "txAdvertisedAndReceived");
9642 else if (
9643 CHECK_FLAG(
9644 p->af_cap
9645 [afi]
9646 [safi],
9647 PEER_CAP_ADDPATH_AF_TX_ADV))
9648 json_object_boolean_true_add(
9649 json_sub,
9650 "txAdvertised");
9651 else if (
9652 CHECK_FLAG(
9653 p->af_cap
9654 [afi]
9655 [safi],
9656 PEER_CAP_ADDPATH_AF_TX_RCV))
9657 json_object_boolean_true_add(
9658 json_sub,
9659 "txReceived");
9660 }
9661
9662 if (CHECK_FLAG(
9663 p->af_cap[afi]
9664 [safi],
9665 PEER_CAP_ADDPATH_AF_RX_ADV)
9666 || CHECK_FLAG(
9667 p->af_cap[afi]
9668 [safi],
9669 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9670 if (CHECK_FLAG(
9671 p->af_cap
9672 [afi]
9673 [safi],
9674 PEER_CAP_ADDPATH_AF_RX_ADV)
9675 && CHECK_FLAG(
9676 p->af_cap
9677 [afi]
9678 [safi],
9679 PEER_CAP_ADDPATH_AF_RX_RCV))
9680 json_object_boolean_true_add(
9681 json_sub,
9682 "rxAdvertisedAndReceived");
9683 else if (
9684 CHECK_FLAG(
9685 p->af_cap
9686 [afi]
9687 [safi],
9688 PEER_CAP_ADDPATH_AF_RX_ADV))
9689 json_object_boolean_true_add(
9690 json_sub,
9691 "rxAdvertised");
9692 else if (
9693 CHECK_FLAG(
9694 p->af_cap
9695 [afi]
9696 [safi],
9697 PEER_CAP_ADDPATH_AF_RX_RCV))
9698 json_object_boolean_true_add(
9699 json_sub,
9700 "rxReceived");
9701 }
9702
9703 if (CHECK_FLAG(
9704 p->af_cap[afi]
9705 [safi],
9706 PEER_CAP_ADDPATH_AF_TX_ADV)
9707 || CHECK_FLAG(
9708 p->af_cap[afi]
9709 [safi],
9710 PEER_CAP_ADDPATH_AF_TX_RCV)
9711 || CHECK_FLAG(
9712 p->af_cap[afi]
9713 [safi],
9714 PEER_CAP_ADDPATH_AF_RX_ADV)
9715 || CHECK_FLAG(
9716 p->af_cap[afi]
9717 [safi],
9718 PEER_CAP_ADDPATH_AF_RX_RCV))
9719 json_object_object_add(
9720 json_add,
9721 print_store,
9722 json_sub);
9723 else
9724 json_object_free(
9725 json_sub);
9726 }
9727
9728 json_object_object_add(
9729 json_cap, "addPath", json_add);
9730 }
9731
9732 /* Dynamic */
9733 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9734 || CHECK_FLAG(p->cap,
9735 PEER_CAP_DYNAMIC_ADV)) {
9736 if (CHECK_FLAG(p->cap,
9737 PEER_CAP_DYNAMIC_ADV)
9738 && CHECK_FLAG(p->cap,
9739 PEER_CAP_DYNAMIC_RCV))
9740 json_object_string_add(
9741 json_cap, "dynamic",
9742 "advertisedAndReceived");
9743 else if (CHECK_FLAG(
9744 p->cap,
9745 PEER_CAP_DYNAMIC_ADV))
9746 json_object_string_add(
9747 json_cap, "dynamic",
9748 "advertised");
9749 else if (CHECK_FLAG(
9750 p->cap,
9751 PEER_CAP_DYNAMIC_RCV))
9752 json_object_string_add(
9753 json_cap, "dynamic",
9754 "received");
9755 }
9756
9757 /* Extended nexthop */
9758 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9759 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9760 json_object *json_nxt = NULL;
9761 const char *print_store;
9762
9763
9764 if (CHECK_FLAG(p->cap,
9765 PEER_CAP_ENHE_ADV)
9766 && CHECK_FLAG(p->cap,
9767 PEER_CAP_ENHE_RCV))
9768 json_object_string_add(
9769 json_cap,
9770 "extendedNexthop",
9771 "advertisedAndReceived");
9772 else if (CHECK_FLAG(p->cap,
9773 PEER_CAP_ENHE_ADV))
9774 json_object_string_add(
9775 json_cap,
9776 "extendedNexthop",
9777 "advertised");
9778 else if (CHECK_FLAG(p->cap,
9779 PEER_CAP_ENHE_RCV))
9780 json_object_string_add(
9781 json_cap,
9782 "extendedNexthop",
9783 "received");
9784
9785 if (CHECK_FLAG(p->cap,
9786 PEER_CAP_ENHE_RCV)) {
9787 json_nxt =
9788 json_object_new_object();
9789
9790 for (safi = SAFI_UNICAST;
9791 safi < SAFI_MAX; safi++) {
9792 if (CHECK_FLAG(
9793 p->af_cap
9794 [AFI_IP]
9795 [safi],
9796 PEER_CAP_ENHE_AF_RCV)) {
9797 print_store = afi_safi_print(
9798 AFI_IP,
9799 safi);
9800 json_object_string_add(
9801 json_nxt,
9802 print_store,
9803 "recieved"); /* misspelled for compatibility */
9804 }
9805 }
9806 json_object_object_add(
9807 json_cap,
9808 "extendedNexthopFamililesByPeer",
9809 json_nxt);
9810 }
9811 }
9812
9813 /* Route Refresh */
9814 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9815 || CHECK_FLAG(p->cap,
9816 PEER_CAP_REFRESH_NEW_RCV)
9817 || CHECK_FLAG(p->cap,
9818 PEER_CAP_REFRESH_OLD_RCV)) {
9819 if (CHECK_FLAG(p->cap,
9820 PEER_CAP_REFRESH_ADV)
9821 && (CHECK_FLAG(
9822 p->cap,
9823 PEER_CAP_REFRESH_NEW_RCV)
9824 || CHECK_FLAG(
9825 p->cap,
9826 PEER_CAP_REFRESH_OLD_RCV))) {
9827 if (CHECK_FLAG(
9828 p->cap,
9829 PEER_CAP_REFRESH_OLD_RCV)
9830 && CHECK_FLAG(
9831 p->cap,
9832 PEER_CAP_REFRESH_NEW_RCV))
9833 json_object_string_add(
9834 json_cap,
9835 "routeRefresh",
9836 "advertisedAndReceivedOldNew");
9837 else {
9838 if (CHECK_FLAG(
9839 p->cap,
9840 PEER_CAP_REFRESH_OLD_RCV))
9841 json_object_string_add(
9842 json_cap,
9843 "routeRefresh",
9844 "advertisedAndReceivedOld");
9845 else
9846 json_object_string_add(
9847 json_cap,
9848 "routeRefresh",
9849 "advertisedAndReceivedNew");
9850 }
9851 } else if (
9852 CHECK_FLAG(
9853 p->cap,
9854 PEER_CAP_REFRESH_ADV))
9855 json_object_string_add(
9856 json_cap,
9857 "routeRefresh",
9858 "advertised");
9859 else if (
9860 CHECK_FLAG(
9861 p->cap,
9862 PEER_CAP_REFRESH_NEW_RCV)
9863 || CHECK_FLAG(
9864 p->cap,
9865 PEER_CAP_REFRESH_OLD_RCV))
9866 json_object_string_add(
9867 json_cap,
9868 "routeRefresh",
9869 "received");
9870 }
9871
9872 /* Multiprotocol Extensions */
9873 json_object *json_multi = NULL;
9874 json_multi = json_object_new_object();
9875
9876 FOREACH_AFI_SAFI (afi, safi) {
9877 if (p->afc_adv[afi][safi]
9878 || p->afc_recv[afi][safi]) {
9879 json_object *json_exten = NULL;
9880 json_exten =
9881 json_object_new_object();
9882
9883 if (p->afc_adv[afi][safi]
9884 && p->afc_recv[afi][safi])
9885 json_object_boolean_true_add(
9886 json_exten,
9887 "advertisedAndReceived");
9888 else if (p->afc_adv[afi][safi])
9889 json_object_boolean_true_add(
9890 json_exten,
9891 "advertised");
9892 else if (p->afc_recv[afi][safi])
9893 json_object_boolean_true_add(
9894 json_exten,
9895 "received");
9896
9897 json_object_object_add(
9898 json_multi,
9899 afi_safi_print(afi,
9900 safi),
9901 json_exten);
9902 }
9903 }
9904 json_object_object_add(
9905 json_cap, "multiprotocolExtensions",
9906 json_multi);
9907
9908 /* Hostname capabilities */
9909 json_object *json_hname = NULL;
9910
9911 json_hname = json_object_new_object();
9912
9913 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9914 json_object_string_add(
9915 json_hname, "advHostName",
9916 bgp->peer_self->hostname
9917 ? bgp->peer_self
9918 ->hostname
9919 : "n/a");
9920 json_object_string_add(
9921 json_hname, "advDomainName",
9922 bgp->peer_self->domainname
9923 ? bgp->peer_self
9924 ->domainname
9925 : "n/a");
9926 }
9927
9928
9929 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9930 json_object_string_add(
9931 json_hname, "rcvHostName",
9932 p->hostname ? p->hostname
9933 : "n/a");
9934 json_object_string_add(
9935 json_hname, "rcvDomainName",
9936 p->domainname ? p->domainname
9937 : "n/a");
9938 }
9939
9940 json_object_object_add(json_cap, "hostName",
9941 json_hname);
9942
9943 /* Gracefull Restart */
9944 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9945 || CHECK_FLAG(p->cap,
9946 PEER_CAP_RESTART_ADV)) {
9947 if (CHECK_FLAG(p->cap,
9948 PEER_CAP_RESTART_ADV)
9949 && CHECK_FLAG(p->cap,
9950 PEER_CAP_RESTART_RCV))
9951 json_object_string_add(
9952 json_cap,
9953 "gracefulRestart",
9954 "advertisedAndReceived");
9955 else if (CHECK_FLAG(
9956 p->cap,
9957 PEER_CAP_RESTART_ADV))
9958 json_object_string_add(
9959 json_cap,
9960 "gracefulRestartCapability",
9961 "advertised");
9962 else if (CHECK_FLAG(
9963 p->cap,
9964 PEER_CAP_RESTART_RCV))
9965 json_object_string_add(
9966 json_cap,
9967 "gracefulRestartCapability",
9968 "received");
9969
9970 if (CHECK_FLAG(p->cap,
9971 PEER_CAP_RESTART_RCV)) {
9972 int restart_af_count = 0;
9973 json_object *json_restart =
9974 NULL;
9975 json_restart =
9976 json_object_new_object();
9977
9978 json_object_int_add(
9979 json_cap,
9980 "gracefulRestartRemoteTimerMsecs",
9981 p->v_gr_restart * 1000);
9982
9983 FOREACH_AFI_SAFI (afi, safi) {
9984 if (CHECK_FLAG(
9985 p->af_cap
9986 [afi]
9987 [safi],
9988 PEER_CAP_RESTART_AF_RCV)) {
9989 json_object *
9990 json_sub =
9991 NULL;
9992 json_sub =
9993 json_object_new_object();
9994
9995 if (CHECK_FLAG(
9996 p->af_cap
9997 [afi]
9998 [safi],
9999 PEER_CAP_RESTART_AF_PRESERVE_RCV))
10000 json_object_boolean_true_add(
10001 json_sub,
10002 "preserved");
10003 restart_af_count++;
10004 json_object_object_add(
10005 json_restart,
10006 afi_safi_print(
10007 afi,
10008 safi),
10009 json_sub);
10010 }
10011 }
10012 if (!restart_af_count) {
10013 json_object_string_add(
10014 json_cap,
10015 "addressFamiliesByPeer",
10016 "none");
10017 json_object_free(
10018 json_restart);
10019 } else
10020 json_object_object_add(
10021 json_cap,
10022 "addressFamiliesByPeer",
10023 json_restart);
10024 }
10025 }
10026 json_object_object_add(json_neigh,
10027 "neighborCapabilities",
10028 json_cap);
10029 } else {
10030 vty_out(vty, " Neighbor capabilities:\n");
10031
10032 /* AS4 */
10033 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10034 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10035 vty_out(vty, " 4 Byte AS:");
10036 if (CHECK_FLAG(p->cap,
10037 PEER_CAP_AS4_ADV))
10038 vty_out(vty, " advertised");
10039 if (CHECK_FLAG(p->cap,
10040 PEER_CAP_AS4_RCV))
10041 vty_out(vty, " %sreceived",
10042 CHECK_FLAG(
10043 p->cap,
10044 PEER_CAP_AS4_ADV)
10045 ? "and "
10046 : "");
10047 vty_out(vty, "\n");
10048 }
10049
10050 /* AddPath */
10051 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10052 || CHECK_FLAG(p->cap,
10053 PEER_CAP_ADDPATH_ADV)) {
10054 vty_out(vty, " AddPath:\n");
10055
10056 FOREACH_AFI_SAFI (afi, safi) {
10057 if (CHECK_FLAG(
10058 p->af_cap[afi]
10059 [safi],
10060 PEER_CAP_ADDPATH_AF_TX_ADV)
10061 || CHECK_FLAG(
10062 p->af_cap[afi]
10063 [safi],
10064 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10065 vty_out(vty,
10066 " %s: TX ",
10067 afi_safi_print(
10068 afi,
10069 safi));
10070
10071 if (CHECK_FLAG(
10072 p->af_cap
10073 [afi]
10074 [safi],
10075 PEER_CAP_ADDPATH_AF_TX_ADV))
10076 vty_out(vty,
10077 "advertised %s",
10078 afi_safi_print(
10079 afi,
10080 safi));
10081
10082 if (CHECK_FLAG(
10083 p->af_cap
10084 [afi]
10085 [safi],
10086 PEER_CAP_ADDPATH_AF_TX_RCV))
10087 vty_out(vty,
10088 "%sreceived",
10089 CHECK_FLAG(
10090 p->af_cap
10091 [afi]
10092 [safi],
10093 PEER_CAP_ADDPATH_AF_TX_ADV)
10094 ? " and "
10095 : "");
10096
10097 vty_out(vty, "\n");
10098 }
10099
10100 if (CHECK_FLAG(
10101 p->af_cap[afi]
10102 [safi],
10103 PEER_CAP_ADDPATH_AF_RX_ADV)
10104 || CHECK_FLAG(
10105 p->af_cap[afi]
10106 [safi],
10107 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10108 vty_out(vty,
10109 " %s: RX ",
10110 afi_safi_print(
10111 afi,
10112 safi));
10113
10114 if (CHECK_FLAG(
10115 p->af_cap
10116 [afi]
10117 [safi],
10118 PEER_CAP_ADDPATH_AF_RX_ADV))
10119 vty_out(vty,
10120 "advertised %s",
10121 afi_safi_print(
10122 afi,
10123 safi));
10124
10125 if (CHECK_FLAG(
10126 p->af_cap
10127 [afi]
10128 [safi],
10129 PEER_CAP_ADDPATH_AF_RX_RCV))
10130 vty_out(vty,
10131 "%sreceived",
10132 CHECK_FLAG(
10133 p->af_cap
10134 [afi]
10135 [safi],
10136 PEER_CAP_ADDPATH_AF_RX_ADV)
10137 ? " and "
10138 : "");
10139
10140 vty_out(vty, "\n");
10141 }
10142 }
10143 }
10144
10145 /* Dynamic */
10146 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10147 || CHECK_FLAG(p->cap,
10148 PEER_CAP_DYNAMIC_ADV)) {
10149 vty_out(vty, " Dynamic:");
10150 if (CHECK_FLAG(p->cap,
10151 PEER_CAP_DYNAMIC_ADV))
10152 vty_out(vty, " advertised");
10153 if (CHECK_FLAG(p->cap,
10154 PEER_CAP_DYNAMIC_RCV))
10155 vty_out(vty, " %sreceived",
10156 CHECK_FLAG(
10157 p->cap,
10158 PEER_CAP_DYNAMIC_ADV)
10159 ? "and "
10160 : "");
10161 vty_out(vty, "\n");
10162 }
10163
10164 /* Extended nexthop */
10165 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10166 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10167 vty_out(vty, " Extended nexthop:");
10168 if (CHECK_FLAG(p->cap,
10169 PEER_CAP_ENHE_ADV))
10170 vty_out(vty, " advertised");
10171 if (CHECK_FLAG(p->cap,
10172 PEER_CAP_ENHE_RCV))
10173 vty_out(vty, " %sreceived",
10174 CHECK_FLAG(
10175 p->cap,
10176 PEER_CAP_ENHE_ADV)
10177 ? "and "
10178 : "");
10179 vty_out(vty, "\n");
10180
10181 if (CHECK_FLAG(p->cap,
10182 PEER_CAP_ENHE_RCV)) {
10183 vty_out(vty,
10184 " Address families by peer:\n ");
10185 for (safi = SAFI_UNICAST;
10186 safi < SAFI_MAX; safi++)
10187 if (CHECK_FLAG(
10188 p->af_cap
10189 [AFI_IP]
10190 [safi],
10191 PEER_CAP_ENHE_AF_RCV))
10192 vty_out(vty,
10193 " %s\n",
10194 afi_safi_print(
10195 AFI_IP,
10196 safi));
10197 }
10198 }
10199
10200 /* Route Refresh */
10201 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10202 || CHECK_FLAG(p->cap,
10203 PEER_CAP_REFRESH_NEW_RCV)
10204 || CHECK_FLAG(p->cap,
10205 PEER_CAP_REFRESH_OLD_RCV)) {
10206 vty_out(vty, " Route refresh:");
10207 if (CHECK_FLAG(p->cap,
10208 PEER_CAP_REFRESH_ADV))
10209 vty_out(vty, " advertised");
10210 if (CHECK_FLAG(p->cap,
10211 PEER_CAP_REFRESH_NEW_RCV)
10212 || CHECK_FLAG(
10213 p->cap,
10214 PEER_CAP_REFRESH_OLD_RCV))
10215 vty_out(vty, " %sreceived(%s)",
10216 CHECK_FLAG(
10217 p->cap,
10218 PEER_CAP_REFRESH_ADV)
10219 ? "and "
10220 : "",
10221 (CHECK_FLAG(
10222 p->cap,
10223 PEER_CAP_REFRESH_OLD_RCV)
10224 && CHECK_FLAG(
10225 p->cap,
10226 PEER_CAP_REFRESH_NEW_RCV))
10227 ? "old & new"
10228 : CHECK_FLAG(
10229 p->cap,
10230 PEER_CAP_REFRESH_OLD_RCV)
10231 ? "old"
10232 : "new");
10233
10234 vty_out(vty, "\n");
10235 }
10236
10237 /* Multiprotocol Extensions */
10238 FOREACH_AFI_SAFI (afi, safi)
10239 if (p->afc_adv[afi][safi]
10240 || p->afc_recv[afi][safi]) {
10241 vty_out(vty,
10242 " Address Family %s:",
10243 afi_safi_print(afi,
10244 safi));
10245 if (p->afc_adv[afi][safi])
10246 vty_out(vty,
10247 " advertised");
10248 if (p->afc_recv[afi][safi])
10249 vty_out(vty,
10250 " %sreceived",
10251 p->afc_adv[afi]
10252 [safi]
10253 ? "and "
10254 : "");
10255 vty_out(vty, "\n");
10256 }
10257
10258 /* Hostname capability */
10259 vty_out(vty, " Hostname Capability:");
10260
10261 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10262 vty_out(vty,
10263 " advertised (name: %s,domain name: %s)",
10264 bgp->peer_self->hostname
10265 ? bgp->peer_self
10266 ->hostname
10267 : "n/a",
10268 bgp->peer_self->domainname
10269 ? bgp->peer_self
10270 ->domainname
10271 : "n/a");
10272 } else {
10273 vty_out(vty, " not advertised");
10274 }
10275
10276 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10277 vty_out(vty,
10278 " received (name: %s,domain name: %s)",
10279 p->hostname ? p->hostname
10280 : "n/a",
10281 p->domainname ? p->domainname
10282 : "n/a");
10283 } else {
10284 vty_out(vty, " not received");
10285 }
10286
10287 vty_out(vty, "\n");
10288
10289 /* Gracefull Restart */
10290 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10291 || CHECK_FLAG(p->cap,
10292 PEER_CAP_RESTART_ADV)) {
10293 vty_out(vty,
10294 " Graceful Restart Capabilty:");
10295 if (CHECK_FLAG(p->cap,
10296 PEER_CAP_RESTART_ADV))
10297 vty_out(vty, " advertised");
10298 if (CHECK_FLAG(p->cap,
10299 PEER_CAP_RESTART_RCV))
10300 vty_out(vty, " %sreceived",
10301 CHECK_FLAG(
10302 p->cap,
10303 PEER_CAP_RESTART_ADV)
10304 ? "and "
10305 : "");
10306 vty_out(vty, "\n");
10307
10308 if (CHECK_FLAG(p->cap,
10309 PEER_CAP_RESTART_RCV)) {
10310 int restart_af_count = 0;
10311
10312 vty_out(vty,
10313 " Remote Restart timer is %d seconds\n",
10314 p->v_gr_restart);
10315 vty_out(vty,
10316 " Address families by peer:\n ");
10317
10318 FOREACH_AFI_SAFI (afi, safi)
10319 if (CHECK_FLAG(
10320 p->af_cap
10321 [afi]
10322 [safi],
10323 PEER_CAP_RESTART_AF_RCV)) {
10324 vty_out(vty,
10325 "%s%s(%s)",
10326 restart_af_count
10327 ? ", "
10328 : "",
10329 afi_safi_print(
10330 afi,
10331 safi),
10332 CHECK_FLAG(
10333 p->af_cap
10334 [afi]
10335 [safi],
10336 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10337 ? "preserved"
10338 : "not preserved");
10339 restart_af_count++;
10340 }
10341 if (!restart_af_count)
10342 vty_out(vty, "none");
10343 vty_out(vty, "\n");
10344 }
10345 }
10346 }
10347 }
10348 }
10349
10350 /* graceful restart information */
10351 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10352 || p->t_gr_stale) {
10353 json_object *json_grace = NULL;
10354 json_object *json_grace_send = NULL;
10355 json_object *json_grace_recv = NULL;
10356 int eor_send_af_count = 0;
10357 int eor_receive_af_count = 0;
10358
10359 if (use_json) {
10360 json_grace = json_object_new_object();
10361 json_grace_send = json_object_new_object();
10362 json_grace_recv = json_object_new_object();
10363
10364 if (p->status == Established) {
10365 FOREACH_AFI_SAFI (afi, safi) {
10366 if (CHECK_FLAG(p->af_sflags[afi][safi],
10367 PEER_STATUS_EOR_SEND)) {
10368 json_object_boolean_true_add(
10369 json_grace_send,
10370 afi_safi_print(afi,
10371 safi));
10372 eor_send_af_count++;
10373 }
10374 }
10375 FOREACH_AFI_SAFI (afi, safi) {
10376 if (CHECK_FLAG(
10377 p->af_sflags[afi][safi],
10378 PEER_STATUS_EOR_RECEIVED)) {
10379 json_object_boolean_true_add(
10380 json_grace_recv,
10381 afi_safi_print(afi,
10382 safi));
10383 eor_receive_af_count++;
10384 }
10385 }
10386 }
10387
10388 json_object_object_add(json_grace, "endOfRibSend",
10389 json_grace_send);
10390 json_object_object_add(json_grace, "endOfRibRecv",
10391 json_grace_recv);
10392
10393 if (p->t_gr_restart)
10394 json_object_int_add(json_grace,
10395 "gracefulRestartTimerMsecs",
10396 thread_timer_remain_second(
10397 p->t_gr_restart)
10398 * 1000);
10399
10400 if (p->t_gr_stale)
10401 json_object_int_add(
10402 json_grace,
10403 "gracefulStalepathTimerMsecs",
10404 thread_timer_remain_second(
10405 p->t_gr_stale)
10406 * 1000);
10407
10408 json_object_object_add(
10409 json_neigh, "gracefulRestartInfo", json_grace);
10410 } else {
10411 vty_out(vty, " Graceful restart information:\n");
10412 if (p->status == Established) {
10413 vty_out(vty, " End-of-RIB send: ");
10414 FOREACH_AFI_SAFI (afi, safi) {
10415 if (CHECK_FLAG(p->af_sflags[afi][safi],
10416 PEER_STATUS_EOR_SEND)) {
10417 vty_out(vty, "%s%s",
10418 eor_send_af_count ? ", "
10419 : "",
10420 afi_safi_print(afi,
10421 safi));
10422 eor_send_af_count++;
10423 }
10424 }
10425 vty_out(vty, "\n");
10426 vty_out(vty, " End-of-RIB received: ");
10427 FOREACH_AFI_SAFI (afi, safi) {
10428 if (CHECK_FLAG(
10429 p->af_sflags[afi][safi],
10430 PEER_STATUS_EOR_RECEIVED)) {
10431 vty_out(vty, "%s%s",
10432 eor_receive_af_count
10433 ? ", "
10434 : "",
10435 afi_safi_print(afi,
10436 safi));
10437 eor_receive_af_count++;
10438 }
10439 }
10440 vty_out(vty, "\n");
10441 }
10442
10443 if (p->t_gr_restart)
10444 vty_out(vty,
10445 " The remaining time of restart timer is %ld\n",
10446 thread_timer_remain_second(
10447 p->t_gr_restart));
10448
10449 if (p->t_gr_stale)
10450 vty_out(vty,
10451 " The remaining time of stalepath timer is %ld\n",
10452 thread_timer_remain_second(
10453 p->t_gr_stale));
10454 }
10455 }
10456 if (use_json) {
10457 json_object *json_stat = NULL;
10458 json_stat = json_object_new_object();
10459 /* Packet counts. */
10460 json_object_int_add(json_stat, "depthInq", 0);
10461 json_object_int_add(json_stat, "depthOutq",
10462 (unsigned long)p->obuf->count);
10463 json_object_int_add(json_stat, "opensSent",
10464 atomic_load_explicit(&p->open_out,
10465 memory_order_relaxed));
10466 json_object_int_add(json_stat, "opensRecv",
10467 atomic_load_explicit(&p->open_in,
10468 memory_order_relaxed));
10469 json_object_int_add(json_stat, "notificationsSent",
10470 atomic_load_explicit(&p->notify_out,
10471 memory_order_relaxed));
10472 json_object_int_add(json_stat, "notificationsRecv",
10473 atomic_load_explicit(&p->notify_in,
10474 memory_order_relaxed));
10475 json_object_int_add(json_stat, "updatesSent",
10476 atomic_load_explicit(&p->update_out,
10477 memory_order_relaxed));
10478 json_object_int_add(json_stat, "updatesRecv",
10479 atomic_load_explicit(&p->update_in,
10480 memory_order_relaxed));
10481 json_object_int_add(json_stat, "keepalivesSent",
10482 atomic_load_explicit(&p->keepalive_out,
10483 memory_order_relaxed));
10484 json_object_int_add(json_stat, "keepalivesRecv",
10485 atomic_load_explicit(&p->keepalive_in,
10486 memory_order_relaxed));
10487 json_object_int_add(json_stat, "routeRefreshSent",
10488 atomic_load_explicit(&p->refresh_out,
10489 memory_order_relaxed));
10490 json_object_int_add(json_stat, "routeRefreshRecv",
10491 atomic_load_explicit(&p->refresh_in,
10492 memory_order_relaxed));
10493 json_object_int_add(json_stat, "capabilitySent",
10494 atomic_load_explicit(&p->dynamic_cap_out,
10495 memory_order_relaxed));
10496 json_object_int_add(json_stat, "capabilityRecv",
10497 atomic_load_explicit(&p->dynamic_cap_in,
10498 memory_order_relaxed));
10499 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10500 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10501 json_object_object_add(json_neigh, "messageStats", json_stat);
10502 } else {
10503 /* Packet counts. */
10504 vty_out(vty, " Message statistics:\n");
10505 vty_out(vty, " Inq depth is 0\n");
10506 vty_out(vty, " Outq depth is %lu\n",
10507 (unsigned long)p->obuf->count);
10508 vty_out(vty, " Sent Rcvd\n");
10509 vty_out(vty, " Opens: %10d %10d\n",
10510 atomic_load_explicit(&p->open_out,
10511 memory_order_relaxed),
10512 atomic_load_explicit(&p->open_in,
10513 memory_order_relaxed));
10514 vty_out(vty, " Notifications: %10d %10d\n",
10515 atomic_load_explicit(&p->notify_out,
10516 memory_order_relaxed),
10517 atomic_load_explicit(&p->notify_in,
10518 memory_order_relaxed));
10519 vty_out(vty, " Updates: %10d %10d\n",
10520 atomic_load_explicit(&p->update_out,
10521 memory_order_relaxed),
10522 atomic_load_explicit(&p->update_in,
10523 memory_order_relaxed));
10524 vty_out(vty, " Keepalives: %10d %10d\n",
10525 atomic_load_explicit(&p->keepalive_out,
10526 memory_order_relaxed),
10527 atomic_load_explicit(&p->keepalive_in,
10528 memory_order_relaxed));
10529 vty_out(vty, " Route Refresh: %10d %10d\n",
10530 atomic_load_explicit(&p->refresh_out,
10531 memory_order_relaxed),
10532 atomic_load_explicit(&p->refresh_in,
10533 memory_order_relaxed));
10534 vty_out(vty, " Capability: %10d %10d\n",
10535 atomic_load_explicit(&p->dynamic_cap_out,
10536 memory_order_relaxed),
10537 atomic_load_explicit(&p->dynamic_cap_in,
10538 memory_order_relaxed));
10539 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10540 PEER_TOTAL_RX(p));
10541 }
10542
10543 if (use_json) {
10544 /* advertisement-interval */
10545 json_object_int_add(json_neigh,
10546 "minBtwnAdvertisementRunsTimerMsecs",
10547 p->v_routeadv * 1000);
10548
10549 /* Update-source. */
10550 if (p->update_if || p->update_source) {
10551 if (p->update_if)
10552 json_object_string_add(json_neigh,
10553 "updateSource",
10554 p->update_if);
10555 else if (p->update_source)
10556 json_object_string_add(
10557 json_neigh, "updateSource",
10558 sockunion2str(p->update_source, buf1,
10559 SU_ADDRSTRLEN));
10560 }
10561 } else {
10562 /* advertisement-interval */
10563 vty_out(vty,
10564 " Minimum time between advertisement runs is %d seconds\n",
10565 p->v_routeadv);
10566
10567 /* Update-source. */
10568 if (p->update_if || p->update_source) {
10569 vty_out(vty, " Update source is ");
10570 if (p->update_if)
10571 vty_out(vty, "%s", p->update_if);
10572 else if (p->update_source)
10573 vty_out(vty, "%s",
10574 sockunion2str(p->update_source, buf1,
10575 SU_ADDRSTRLEN));
10576 vty_out(vty, "\n");
10577 }
10578
10579 vty_out(vty, "\n");
10580 }
10581
10582 /* Address Family Information */
10583 json_object *json_hold = NULL;
10584
10585 if (use_json)
10586 json_hold = json_object_new_object();
10587
10588 FOREACH_AFI_SAFI (afi, safi)
10589 if (p->afc[afi][safi])
10590 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10591 json_hold);
10592
10593 if (use_json) {
10594 json_object_object_add(json_neigh, "addressFamilyInfo",
10595 json_hold);
10596 json_object_int_add(json_neigh, "connectionsEstablished",
10597 p->established);
10598 json_object_int_add(json_neigh, "connectionsDropped",
10599 p->dropped);
10600 } else
10601 vty_out(vty, " Connections established %d; dropped %d\n",
10602 p->established, p->dropped);
10603
10604 if (!p->last_reset) {
10605 if (use_json)
10606 json_object_string_add(json_neigh, "lastReset",
10607 "never");
10608 else
10609 vty_out(vty, " Last reset never\n");
10610 } else {
10611 if (use_json) {
10612 time_t uptime;
10613 struct tm *tm;
10614
10615 uptime = bgp_clock();
10616 uptime -= p->resettime;
10617 tm = gmtime(&uptime);
10618 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10619 (tm->tm_sec * 1000)
10620 + (tm->tm_min * 60000)
10621 + (tm->tm_hour * 3600000));
10622 json_object_string_add(
10623 json_neigh, "lastResetDueTo",
10624 peer_down_str[(int)p->last_reset]);
10625 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10626 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10627 char errorcodesubcode_hexstr[5];
10628 char errorcodesubcode_str[256];
10629
10630 code_str = bgp_notify_code_str(p->notify.code);
10631 subcode_str = bgp_notify_subcode_str(
10632 p->notify.code, p->notify.subcode);
10633
10634 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10635 p->notify.code, p->notify.subcode);
10636 json_object_string_add(json_neigh,
10637 "lastErrorCodeSubcode",
10638 errorcodesubcode_hexstr);
10639 snprintf(errorcodesubcode_str, 255, "%s%s",
10640 code_str, subcode_str);
10641 json_object_string_add(json_neigh,
10642 "lastNotificationReason",
10643 errorcodesubcode_str);
10644 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10645 && p->notify.code == BGP_NOTIFY_CEASE
10646 && (p->notify.subcode
10647 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10648 || p->notify.subcode
10649 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10650 && p->notify.length) {
10651 char msgbuf[1024];
10652 const char *msg_str;
10653
10654 msg_str = bgp_notify_admin_message(
10655 msgbuf, sizeof(msgbuf),
10656 (uint8_t *)p->notify.data,
10657 p->notify.length);
10658 if (msg_str)
10659 json_object_string_add(
10660 json_neigh,
10661 "lastShutdownDescription",
10662 msg_str);
10663 }
10664 }
10665 } else {
10666 vty_out(vty, " Last reset %s, ",
10667 peer_uptime(p->resettime, timebuf,
10668 BGP_UPTIME_LEN, 0, NULL));
10669
10670 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10671 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10672 code_str = bgp_notify_code_str(p->notify.code);
10673 subcode_str = bgp_notify_subcode_str(
10674 p->notify.code, p->notify.subcode);
10675 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10676 p->last_reset == PEER_DOWN_NOTIFY_SEND
10677 ? "sent"
10678 : "received",
10679 code_str, subcode_str);
10680 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10681 && p->notify.code == BGP_NOTIFY_CEASE
10682 && (p->notify.subcode
10683 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10684 || p->notify.subcode
10685 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10686 && p->notify.length) {
10687 char msgbuf[1024];
10688 const char *msg_str;
10689
10690 msg_str = bgp_notify_admin_message(
10691 msgbuf, sizeof(msgbuf),
10692 (uint8_t *)p->notify.data,
10693 p->notify.length);
10694 if (msg_str)
10695 vty_out(vty,
10696 " Message: \"%s\"\n",
10697 msg_str);
10698 }
10699 } else {
10700 vty_out(vty, "due to %s\n",
10701 peer_down_str[(int)p->last_reset]);
10702 }
10703
10704 if (p->last_reset_cause_size) {
10705 msg = p->last_reset_cause;
10706 vty_out(vty,
10707 " Message received that caused BGP to send a NOTIFICATION:\n ");
10708 for (i = 1; i <= p->last_reset_cause_size;
10709 i++) {
10710 vty_out(vty, "%02X", *msg++);
10711
10712 if (i != p->last_reset_cause_size) {
10713 if (i % 16 == 0) {
10714 vty_out(vty, "\n ");
10715 } else if (i % 4 == 0) {
10716 vty_out(vty, " ");
10717 }
10718 }
10719 }
10720 vty_out(vty, "\n");
10721 }
10722 }
10723 }
10724
10725 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10726 if (use_json)
10727 json_object_boolean_true_add(json_neigh,
10728 "prefixesConfigExceedMax");
10729 else
10730 vty_out(vty,
10731 " Peer had exceeded the max. no. of prefixes configured.\n");
10732
10733 if (p->t_pmax_restart) {
10734 if (use_json) {
10735 json_object_boolean_true_add(
10736 json_neigh, "reducePrefixNumFrom");
10737 json_object_int_add(json_neigh,
10738 "restartInTimerMsec",
10739 thread_timer_remain_second(
10740 p->t_pmax_restart)
10741 * 1000);
10742 } else
10743 vty_out(vty,
10744 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10745 p->host, thread_timer_remain_second(
10746 p->t_pmax_restart));
10747 } else {
10748 if (use_json)
10749 json_object_boolean_true_add(
10750 json_neigh,
10751 "reducePrefixNumAndClearIpBgp");
10752 else
10753 vty_out(vty,
10754 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10755 p->host);
10756 }
10757 }
10758
10759 /* EBGP Multihop and GTSM */
10760 if (p->sort != BGP_PEER_IBGP) {
10761 if (use_json) {
10762 if (p->gtsm_hops > 0)
10763 json_object_int_add(json_neigh,
10764 "externalBgpNbrMaxHopsAway",
10765 p->gtsm_hops);
10766 else if (p->ttl > 1)
10767 json_object_int_add(json_neigh,
10768 "externalBgpNbrMaxHopsAway",
10769 p->ttl);
10770 } else {
10771 if (p->gtsm_hops > 0)
10772 vty_out(vty,
10773 " External BGP neighbor may be up to %d hops away.\n",
10774 p->gtsm_hops);
10775 else if (p->ttl > 1)
10776 vty_out(vty,
10777 " External BGP neighbor may be up to %d hops away.\n",
10778 p->ttl);
10779 }
10780 } else {
10781 if (p->gtsm_hops > 0) {
10782 if (use_json)
10783 json_object_int_add(json_neigh,
10784 "internalBgpNbrMaxHopsAway",
10785 p->gtsm_hops);
10786 else
10787 vty_out(vty,
10788 " Internal BGP neighbor may be up to %d hops away.\n",
10789 p->gtsm_hops);
10790 }
10791 }
10792
10793 /* Local address. */
10794 if (p->su_local) {
10795 if (use_json) {
10796 json_object_string_add(json_neigh, "hostLocal",
10797 sockunion2str(p->su_local, buf1,
10798 SU_ADDRSTRLEN));
10799 json_object_int_add(json_neigh, "portLocal",
10800 ntohs(p->su_local->sin.sin_port));
10801 } else
10802 vty_out(vty, "Local host: %s, Local port: %d\n",
10803 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10804 ntohs(p->su_local->sin.sin_port));
10805 }
10806
10807 /* Remote address. */
10808 if (p->su_remote) {
10809 if (use_json) {
10810 json_object_string_add(json_neigh, "hostForeign",
10811 sockunion2str(p->su_remote, buf1,
10812 SU_ADDRSTRLEN));
10813 json_object_int_add(json_neigh, "portForeign",
10814 ntohs(p->su_remote->sin.sin_port));
10815 } else
10816 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10817 sockunion2str(p->su_remote, buf1,
10818 SU_ADDRSTRLEN),
10819 ntohs(p->su_remote->sin.sin_port));
10820 }
10821
10822 /* Nexthop display. */
10823 if (p->su_local) {
10824 if (use_json) {
10825 json_object_string_add(json_neigh, "nexthop",
10826 inet_ntop(AF_INET,
10827 &p->nexthop.v4, buf1,
10828 sizeof(buf1)));
10829 json_object_string_add(json_neigh, "nexthopGlobal",
10830 inet_ntop(AF_INET6,
10831 &p->nexthop.v6_global,
10832 buf1, sizeof(buf1)));
10833 json_object_string_add(json_neigh, "nexthopLocal",
10834 inet_ntop(AF_INET6,
10835 &p->nexthop.v6_local,
10836 buf1, sizeof(buf1)));
10837 if (p->shared_network)
10838 json_object_string_add(json_neigh,
10839 "bgpConnection",
10840 "sharedNetwork");
10841 else
10842 json_object_string_add(json_neigh,
10843 "bgpConnection",
10844 "nonSharedNetwork");
10845 } else {
10846 vty_out(vty, "Nexthop: %s\n",
10847 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10848 sizeof(buf1)));
10849 vty_out(vty, "Nexthop global: %s\n",
10850 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10851 sizeof(buf1)));
10852 vty_out(vty, "Nexthop local: %s\n",
10853 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10854 sizeof(buf1)));
10855 vty_out(vty, "BGP connection: %s\n",
10856 p->shared_network ? "shared network"
10857 : "non shared network");
10858 }
10859 }
10860
10861 /* Timer information. */
10862 if (use_json) {
10863 json_object_int_add(json_neigh, "connectRetryTimer",
10864 p->v_connect);
10865 if (p->status == Established && p->rtt)
10866 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10867 p->rtt);
10868 if (p->t_start)
10869 json_object_int_add(
10870 json_neigh, "nextStartTimerDueInMsecs",
10871 thread_timer_remain_second(p->t_start) * 1000);
10872 if (p->t_connect)
10873 json_object_int_add(
10874 json_neigh, "nextConnectTimerDueInMsecs",
10875 thread_timer_remain_second(p->t_connect)
10876 * 1000);
10877 if (p->t_routeadv) {
10878 json_object_int_add(json_neigh, "mraiInterval",
10879 p->v_routeadv);
10880 json_object_int_add(
10881 json_neigh, "mraiTimerExpireInMsecs",
10882 thread_timer_remain_second(p->t_routeadv)
10883 * 1000);
10884 }
10885 if (p->password)
10886 json_object_int_add(json_neigh, "authenticationEnabled",
10887 1);
10888
10889 if (p->t_read)
10890 json_object_string_add(json_neigh, "readThread", "on");
10891 else
10892 json_object_string_add(json_neigh, "readThread", "off");
10893
10894 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10895 json_object_string_add(json_neigh, "writeThread", "on");
10896 else
10897 json_object_string_add(json_neigh, "writeThread",
10898 "off");
10899 } else {
10900 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10901 p->v_connect);
10902 if (p->status == Established && p->rtt)
10903 vty_out(vty, "Estimated round trip time: %d ms\n",
10904 p->rtt);
10905 if (p->t_start)
10906 vty_out(vty, "Next start timer due in %ld seconds\n",
10907 thread_timer_remain_second(p->t_start));
10908 if (p->t_connect)
10909 vty_out(vty, "Next connect timer due in %ld seconds\n",
10910 thread_timer_remain_second(p->t_connect));
10911 if (p->t_routeadv)
10912 vty_out(vty,
10913 "MRAI (interval %u) timer expires in %ld seconds\n",
10914 p->v_routeadv,
10915 thread_timer_remain_second(p->t_routeadv));
10916 if (p->password)
10917 vty_out(vty, "Peer Authentication Enabled\n");
10918
10919 vty_out(vty, "Read thread: %s Write thread: %s\n",
10920 p->t_read ? "on" : "off",
10921 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10922 ? "on"
10923 : "off");
10924 }
10925
10926 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10927 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10928 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10929
10930 if (!use_json)
10931 vty_out(vty, "\n");
10932
10933 /* BFD information. */
10934 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10935
10936 if (use_json) {
10937 if (p->conf_if) /* Configured interface name. */
10938 json_object_object_add(json, p->conf_if, json_neigh);
10939 else /* Configured IP address. */
10940 json_object_object_add(json, p->host, json_neigh);
10941 }
10942 }
10943
10944 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10945 enum show_type type, union sockunion *su,
10946 const char *conf_if, bool use_json,
10947 json_object *json)
10948 {
10949 struct listnode *node, *nnode;
10950 struct peer *peer;
10951 int find = 0;
10952 bool nbr_output = false;
10953
10954 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10955 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10956 continue;
10957
10958 switch (type) {
10959 case show_all:
10960 bgp_show_peer(vty, peer, use_json, json);
10961 nbr_output = true;
10962 break;
10963 case show_peer:
10964 if (conf_if) {
10965 if ((peer->conf_if
10966 && !strcmp(peer->conf_if, conf_if))
10967 || (peer->hostname
10968 && !strcmp(peer->hostname, conf_if))) {
10969 find = 1;
10970 bgp_show_peer(vty, peer, use_json,
10971 json);
10972 }
10973 } else {
10974 if (sockunion_same(&peer->su, su)) {
10975 find = 1;
10976 bgp_show_peer(vty, peer, use_json,
10977 json);
10978 }
10979 }
10980 break;
10981 }
10982 }
10983
10984 if (type == show_peer && !find) {
10985 if (use_json)
10986 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10987 else
10988 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10989 }
10990
10991 if (type != show_peer && !nbr_output && !use_json)
10992 vty_out(vty, "%% No BGP neighbors found\n");
10993
10994 if (use_json) {
10995 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10996 json, JSON_C_TO_STRING_PRETTY));
10997 } else {
10998 vty_out(vty, "\n");
10999 }
11000
11001 return CMD_SUCCESS;
11002 }
11003
11004 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11005 enum show_type type,
11006 const char *ip_str,
11007 bool use_json)
11008 {
11009 struct listnode *node, *nnode;
11010 struct bgp *bgp;
11011 union sockunion su;
11012 json_object *json = NULL;
11013 int ret, is_first = 1;
11014 bool nbr_output = false;
11015
11016 if (use_json)
11017 vty_out(vty, "{\n");
11018
11019 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11020 nbr_output = true;
11021 if (use_json) {
11022 if (!(json = json_object_new_object())) {
11023 flog_err(
11024 EC_BGP_JSON_MEM_ERROR,
11025 "Unable to allocate memory for JSON object");
11026 vty_out(vty,
11027 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11028 return;
11029 }
11030
11031 json_object_int_add(json, "vrfId",
11032 (bgp->vrf_id == VRF_UNKNOWN)
11033 ? -1
11034 : (int64_t)bgp->vrf_id);
11035 json_object_string_add(
11036 json, "vrfName",
11037 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11038 ? VRF_DEFAULT_NAME
11039 : bgp->name);
11040
11041 if (!is_first)
11042 vty_out(vty, ",\n");
11043 else
11044 is_first = 0;
11045
11046 vty_out(vty, "\"%s\":",
11047 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11048 ? VRF_DEFAULT_NAME
11049 : bgp->name);
11050 } else {
11051 vty_out(vty, "\nInstance %s:\n",
11052 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11053 ? VRF_DEFAULT_NAME
11054 : bgp->name);
11055 }
11056
11057 if (type == show_peer) {
11058 ret = str2sockunion(ip_str, &su);
11059 if (ret < 0)
11060 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11061 use_json, json);
11062 else
11063 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11064 use_json, json);
11065 } else {
11066 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
11067 use_json, json);
11068 }
11069 json_object_free(json);
11070 }
11071
11072 if (use_json) {
11073 vty_out(vty, "}\n");
11074 json_object_free(json);
11075 }
11076 else if (!nbr_output)
11077 vty_out(vty, "%% BGP instance not found\n");
11078 }
11079
11080 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11081 enum show_type type, const char *ip_str,
11082 bool use_json)
11083 {
11084 int ret;
11085 struct bgp *bgp;
11086 union sockunion su;
11087 json_object *json = NULL;
11088
11089 if (name) {
11090 if (strmatch(name, "all")) {
11091 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11092 use_json);
11093 return CMD_SUCCESS;
11094 } else {
11095 bgp = bgp_lookup_by_name(name);
11096 if (!bgp) {
11097 if (use_json) {
11098 json = json_object_new_object();
11099 vty_out(vty, "%s\n",
11100 json_object_to_json_string_ext(
11101 json,
11102 JSON_C_TO_STRING_PRETTY));
11103 json_object_free(json);
11104 } else
11105 vty_out(vty,
11106 "%% BGP instance not found\n");
11107
11108 return CMD_WARNING;
11109 }
11110 }
11111 } else {
11112 bgp = bgp_get_default();
11113 }
11114
11115 if (bgp) {
11116 json = json_object_new_object();
11117 if (ip_str) {
11118 ret = str2sockunion(ip_str, &su);
11119 if (ret < 0)
11120 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11121 use_json, json);
11122 else
11123 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11124 use_json, json);
11125 } else {
11126 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11127 json);
11128 }
11129 json_object_free(json);
11130 } else {
11131 if (use_json)
11132 vty_out(vty, "{}\n");
11133 else
11134 vty_out(vty, "%% BGP instance not found\n");
11135 }
11136
11137 return CMD_SUCCESS;
11138 }
11139
11140 /* "show [ip] bgp neighbors" commands. */
11141 DEFUN (show_ip_bgp_neighbors,
11142 show_ip_bgp_neighbors_cmd,
11143 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11144 SHOW_STR
11145 IP_STR
11146 BGP_STR
11147 BGP_INSTANCE_HELP_STR
11148 "Address Family\n"
11149 "Address Family\n"
11150 "Detailed information on TCP and BGP neighbor connections\n"
11151 "Neighbor to display information about\n"
11152 "Neighbor to display information about\n"
11153 "Neighbor on BGP configured interface\n"
11154 JSON_STR)
11155 {
11156 char *vrf = NULL;
11157 char *sh_arg = NULL;
11158 enum show_type sh_type;
11159
11160 bool uj = use_json(argc, argv);
11161
11162 int idx = 0;
11163
11164 /* [<vrf> VIEWVRFNAME] */
11165 if (argv_find(argv, argc, "vrf", &idx)) {
11166 vrf = argv[idx + 1]->arg;
11167 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11168 vrf = NULL;
11169 } else if (argv_find(argv, argc, "view", &idx))
11170 /* [<view> VIEWVRFNAME] */
11171 vrf = argv[idx + 1]->arg;
11172
11173 idx++;
11174 if (argv_find(argv, argc, "A.B.C.D", &idx)
11175 || argv_find(argv, argc, "X:X::X:X", &idx)
11176 || argv_find(argv, argc, "WORD", &idx)) {
11177 sh_type = show_peer;
11178 sh_arg = argv[idx]->arg;
11179 } else
11180 sh_type = show_all;
11181
11182 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11183 }
11184
11185 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11186 paths' and `show ip mbgp paths'. Those functions results are the
11187 same.*/
11188 DEFUN (show_ip_bgp_paths,
11189 show_ip_bgp_paths_cmd,
11190 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11191 SHOW_STR
11192 IP_STR
11193 BGP_STR
11194 BGP_SAFI_HELP_STR
11195 "Path information\n")
11196 {
11197 vty_out(vty, "Address Refcnt Path\n");
11198 aspath_print_all_vty(vty);
11199 return CMD_SUCCESS;
11200 }
11201
11202 #include "hash.h"
11203
11204 static void community_show_all_iterator(struct hash_bucket *bucket,
11205 struct vty *vty)
11206 {
11207 struct community *com;
11208
11209 com = (struct community *)bucket->data;
11210 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11211 community_str(com, false));
11212 }
11213
11214 /* Show BGP's community internal data. */
11215 DEFUN (show_ip_bgp_community_info,
11216 show_ip_bgp_community_info_cmd,
11217 "show [ip] bgp community-info",
11218 SHOW_STR
11219 IP_STR
11220 BGP_STR
11221 "List all bgp community information\n")
11222 {
11223 vty_out(vty, "Address Refcnt Community\n");
11224
11225 hash_iterate(community_hash(),
11226 (void (*)(struct hash_bucket *,
11227 void *))community_show_all_iterator,
11228 vty);
11229
11230 return CMD_SUCCESS;
11231 }
11232
11233 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11234 struct vty *vty)
11235 {
11236 struct lcommunity *lcom;
11237
11238 lcom = (struct lcommunity *)bucket->data;
11239 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11240 lcommunity_str(lcom, false));
11241 }
11242
11243 /* Show BGP's community internal data. */
11244 DEFUN (show_ip_bgp_lcommunity_info,
11245 show_ip_bgp_lcommunity_info_cmd,
11246 "show ip bgp large-community-info",
11247 SHOW_STR
11248 IP_STR
11249 BGP_STR
11250 "List all bgp large-community information\n")
11251 {
11252 vty_out(vty, "Address Refcnt Large-community\n");
11253
11254 hash_iterate(lcommunity_hash(),
11255 (void (*)(struct hash_bucket *,
11256 void *))lcommunity_show_all_iterator,
11257 vty);
11258
11259 return CMD_SUCCESS;
11260 }
11261
11262
11263 DEFUN (show_ip_bgp_attr_info,
11264 show_ip_bgp_attr_info_cmd,
11265 "show [ip] bgp attribute-info",
11266 SHOW_STR
11267 IP_STR
11268 BGP_STR
11269 "List all bgp attribute information\n")
11270 {
11271 attr_show_all(vty);
11272 return CMD_SUCCESS;
11273 }
11274
11275 static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11276 safi_t safi, bool use_json)
11277 {
11278 struct bgp *bgp;
11279 struct listnode *node;
11280 char *vname;
11281 char buf1[INET6_ADDRSTRLEN];
11282 char *ecom_str;
11283 vpn_policy_direction_t dir;
11284
11285 if (use_json) {
11286 json_object *json = NULL;
11287 json_object *json_import_vrfs = NULL;
11288 json_object *json_export_vrfs = NULL;
11289
11290 json = json_object_new_object();
11291
11292 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11293
11294 if (!bgp) {
11295 vty_out(vty, "%s\n",
11296 json_object_to_json_string_ext(
11297 json,
11298 JSON_C_TO_STRING_PRETTY));
11299 json_object_free(json);
11300
11301 return CMD_WARNING;
11302 }
11303
11304 /* Provide context for the block */
11305 json_object_string_add(json, "vrf", name ? name : "default");
11306 json_object_string_add(json, "afiSafi",
11307 afi_safi_print(afi, safi));
11308
11309 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11310 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11311 json_object_string_add(json, "importFromVrfs", "none");
11312 json_object_string_add(json, "importRts", "none");
11313 } else {
11314 json_import_vrfs = json_object_new_array();
11315
11316 for (ALL_LIST_ELEMENTS_RO(
11317 bgp->vpn_policy[afi].import_vrf,
11318 node, vname))
11319 json_object_array_add(json_import_vrfs,
11320 json_object_new_string(vname));
11321
11322 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11323 ecom_str = ecommunity_ecom2str(
11324 bgp->vpn_policy[afi].rtlist[dir],
11325 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11326 json_object_object_add(json, "importFromVrfs",
11327 json_import_vrfs);
11328 json_object_string_add(json, "importRts", ecom_str);
11329
11330 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11331 }
11332
11333 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11334 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11335 json_object_string_add(json, "exportToVrfs", "none");
11336 json_object_string_add(json, "routeDistinguisher",
11337 "none");
11338 json_object_string_add(json, "exportRts", "none");
11339 } else {
11340 json_export_vrfs = json_object_new_array();
11341
11342 for (ALL_LIST_ELEMENTS_RO(
11343 bgp->vpn_policy[afi].export_vrf,
11344 node, vname))
11345 json_object_array_add(json_export_vrfs,
11346 json_object_new_string(vname));
11347 json_object_object_add(json, "exportToVrfs",
11348 json_export_vrfs);
11349 json_object_string_add(json, "routeDistinguisher",
11350 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11351 buf1, RD_ADDRSTRLEN));
11352
11353 dir = BGP_VPN_POLICY_DIR_TOVPN;
11354 ecom_str = ecommunity_ecom2str(
11355 bgp->vpn_policy[afi].rtlist[dir],
11356 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11357 json_object_string_add(json, "exportRts", ecom_str);
11358
11359 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11360 }
11361
11362 vty_out(vty, "%s\n",
11363 json_object_to_json_string_ext(json,
11364 JSON_C_TO_STRING_PRETTY));
11365 json_object_free(json);
11366
11367 } else {
11368 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11369
11370 if (!bgp) {
11371 vty_out(vty, "%% No such BGP instance exist\n");
11372 return CMD_WARNING;
11373 }
11374
11375 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11376 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11377 vty_out(vty,
11378 "This VRF is not importing %s routes from any other VRF\n",
11379 afi_safi_print(afi, safi));
11380 else {
11381 vty_out(vty,
11382 "This VRF is importing %s routes from the following VRFs:\n",
11383 afi_safi_print(afi, safi));
11384
11385 for (ALL_LIST_ELEMENTS_RO(
11386 bgp->vpn_policy[afi].import_vrf,
11387 node, vname))
11388 vty_out(vty, " %s\n", vname);
11389
11390 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11391 ecom_str = ecommunity_ecom2str(
11392 bgp->vpn_policy[afi].rtlist[dir],
11393 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11394 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11395
11396 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11397 }
11398
11399 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11400 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11401 vty_out(vty,
11402 "This VRF is not exporting %s routes to any other VRF\n",
11403 afi_safi_print(afi, safi));
11404 else {
11405 vty_out(vty,
11406 "This VRF is exporting %s routes to the following VRFs:\n",
11407 afi_safi_print(afi, safi));
11408
11409 for (ALL_LIST_ELEMENTS_RO(
11410 bgp->vpn_policy[afi].export_vrf,
11411 node, vname))
11412 vty_out(vty, " %s\n", vname);
11413
11414 vty_out(vty, "RD: %s\n",
11415 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11416 buf1, RD_ADDRSTRLEN));
11417
11418 dir = BGP_VPN_POLICY_DIR_TOVPN;
11419 ecom_str = ecommunity_ecom2str(
11420 bgp->vpn_policy[afi].rtlist[dir],
11421 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11422 vty_out(vty, "Export RT: %s\n", ecom_str);
11423 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11424 }
11425 }
11426
11427 return CMD_SUCCESS;
11428 }
11429
11430 /* "show [ip] bgp route-leak" command. */
11431 DEFUN (show_ip_bgp_route_leak,
11432 show_ip_bgp_route_leak_cmd,
11433 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11434 SHOW_STR
11435 IP_STR
11436 BGP_STR
11437 BGP_INSTANCE_HELP_STR
11438 BGP_AFI_HELP_STR
11439 BGP_SAFI_HELP_STR
11440 "Route leaking information\n"
11441 JSON_STR)
11442 {
11443 char *vrf = NULL;
11444 afi_t afi = AFI_MAX;
11445 safi_t safi = SAFI_MAX;
11446
11447 bool uj = use_json(argc, argv);
11448 int idx = 0;
11449
11450 /* show [ip] bgp */
11451 if (argv_find(argv, argc, "ip", &idx)) {
11452 afi = AFI_IP;
11453 safi = SAFI_UNICAST;
11454 }
11455 /* [vrf VIEWVRFNAME] */
11456 if (argv_find(argv, argc, "view", &idx)) {
11457 vty_out(vty,
11458 "%% This command is not applicable to BGP views\n");
11459 return CMD_WARNING;
11460 }
11461
11462 if (argv_find(argv, argc, "vrf", &idx)) {
11463 vrf = argv[idx + 1]->arg;
11464 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11465 vrf = NULL;
11466 }
11467 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11468 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11469 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11470 }
11471
11472 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11473 vty_out(vty,
11474 "%% This command is applicable only for unicast ipv4|ipv6\n");
11475 return CMD_WARNING;
11476 }
11477
11478 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
11479 }
11480
11481 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11482 safi_t safi)
11483 {
11484 struct listnode *node, *nnode;
11485 struct bgp *bgp;
11486
11487 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11488 vty_out(vty, "\nInstance %s:\n",
11489 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11490 ? VRF_DEFAULT_NAME
11491 : bgp->name);
11492 update_group_show(bgp, afi, safi, vty, 0);
11493 }
11494 }
11495
11496 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11497 int safi, uint64_t subgrp_id)
11498 {
11499 struct bgp *bgp;
11500
11501 if (name) {
11502 if (strmatch(name, "all")) {
11503 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11504 return CMD_SUCCESS;
11505 } else {
11506 bgp = bgp_lookup_by_name(name);
11507 }
11508 } else {
11509 bgp = bgp_get_default();
11510 }
11511
11512 if (bgp)
11513 update_group_show(bgp, afi, safi, vty, subgrp_id);
11514 return CMD_SUCCESS;
11515 }
11516
11517 DEFUN (show_ip_bgp_updgrps,
11518 show_ip_bgp_updgrps_cmd,
11519 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11520 SHOW_STR
11521 IP_STR
11522 BGP_STR
11523 BGP_INSTANCE_HELP_STR
11524 BGP_AFI_HELP_STR
11525 BGP_SAFI_WITH_LABEL_HELP_STR
11526 "Detailed info about dynamic update groups\n"
11527 "Specific subgroup to display detailed info for\n")
11528 {
11529 char *vrf = NULL;
11530 afi_t afi = AFI_IP6;
11531 safi_t safi = SAFI_UNICAST;
11532 uint64_t subgrp_id = 0;
11533
11534 int idx = 0;
11535
11536 /* show [ip] bgp */
11537 if (argv_find(argv, argc, "ip", &idx))
11538 afi = AFI_IP;
11539 /* [<vrf> VIEWVRFNAME] */
11540 if (argv_find(argv, argc, "vrf", &idx)) {
11541 vrf = argv[idx + 1]->arg;
11542 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11543 vrf = NULL;
11544 } else if (argv_find(argv, argc, "view", &idx))
11545 /* [<view> VIEWVRFNAME] */
11546 vrf = argv[idx + 1]->arg;
11547 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11548 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11549 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11550 }
11551
11552 /* get subgroup id, if provided */
11553 idx = argc - 1;
11554 if (argv[idx]->type == VARIABLE_TKN)
11555 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11556
11557 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11558 }
11559
11560 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11561 show_bgp_instance_all_ipv6_updgrps_cmd,
11562 "show [ip] bgp <view|vrf> all update-groups",
11563 SHOW_STR
11564 IP_STR
11565 BGP_STR
11566 BGP_INSTANCE_ALL_HELP_STR
11567 "Detailed info about dynamic update groups\n")
11568 {
11569 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11570 return CMD_SUCCESS;
11571 }
11572
11573 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11574 show_bgp_l2vpn_evpn_updgrps_cmd,
11575 "show [ip] bgp l2vpn evpn update-groups",
11576 SHOW_STR
11577 IP_STR
11578 BGP_STR
11579 "l2vpn address family\n"
11580 "evpn sub-address family\n"
11581 "Detailed info about dynamic update groups\n")
11582 {
11583 char *vrf = NULL;
11584 uint64_t subgrp_id = 0;
11585
11586 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11587 return CMD_SUCCESS;
11588 }
11589
11590 DEFUN (show_bgp_updgrps_stats,
11591 show_bgp_updgrps_stats_cmd,
11592 "show [ip] bgp update-groups statistics",
11593 SHOW_STR
11594 IP_STR
11595 BGP_STR
11596 "Detailed info about dynamic update groups\n"
11597 "Statistics\n")
11598 {
11599 struct bgp *bgp;
11600
11601 bgp = bgp_get_default();
11602 if (bgp)
11603 update_group_show_stats(bgp, vty);
11604
11605 return CMD_SUCCESS;
11606 }
11607
11608 DEFUN (show_bgp_instance_updgrps_stats,
11609 show_bgp_instance_updgrps_stats_cmd,
11610 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11611 SHOW_STR
11612 IP_STR
11613 BGP_STR
11614 BGP_INSTANCE_HELP_STR
11615 "Detailed info about dynamic update groups\n"
11616 "Statistics\n")
11617 {
11618 int idx_word = 3;
11619 struct bgp *bgp;
11620
11621 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11622 if (bgp)
11623 update_group_show_stats(bgp, vty);
11624
11625 return CMD_SUCCESS;
11626 }
11627
11628 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11629 afi_t afi, safi_t safi,
11630 const char *what, uint64_t subgrp_id)
11631 {
11632 struct bgp *bgp;
11633
11634 if (name)
11635 bgp = bgp_lookup_by_name(name);
11636 else
11637 bgp = bgp_get_default();
11638
11639 if (bgp) {
11640 if (!strcmp(what, "advertise-queue"))
11641 update_group_show_adj_queue(bgp, afi, safi, vty,
11642 subgrp_id);
11643 else if (!strcmp(what, "advertised-routes"))
11644 update_group_show_advertised(bgp, afi, safi, vty,
11645 subgrp_id);
11646 else if (!strcmp(what, "packet-queue"))
11647 update_group_show_packet_queue(bgp, afi, safi, vty,
11648 subgrp_id);
11649 }
11650 }
11651
11652 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11653 show_ip_bgp_instance_updgrps_adj_s_cmd,
11654 "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",
11655 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11656 BGP_SAFI_HELP_STR
11657 "Detailed info about dynamic update groups\n"
11658 "Specific subgroup to display info for\n"
11659 "Advertisement queue\n"
11660 "Announced routes\n"
11661 "Packet queue\n")
11662 {
11663 uint64_t subgrp_id = 0;
11664 afi_t afiz;
11665 safi_t safiz;
11666 if (sgid)
11667 subgrp_id = strtoull(sgid, NULL, 10);
11668
11669 if (!ip && !afi)
11670 afiz = AFI_IP6;
11671 if (!ip && afi)
11672 afiz = bgp_vty_afi_from_str(afi);
11673 if (ip && !afi)
11674 afiz = AFI_IP;
11675 if (ip && afi) {
11676 afiz = bgp_vty_afi_from_str(afi);
11677 if (afiz != AFI_IP)
11678 vty_out(vty,
11679 "%% Cannot specify both 'ip' and 'ipv6'\n");
11680 return CMD_WARNING;
11681 }
11682
11683 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11684
11685 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11686 return CMD_SUCCESS;
11687 }
11688
11689 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11690 {
11691 struct listnode *node, *nnode;
11692 struct prefix *range;
11693 struct peer *conf;
11694 struct peer *peer;
11695 char buf[PREFIX2STR_BUFFER];
11696 afi_t afi;
11697 safi_t safi;
11698 const char *peer_status;
11699 const char *af_str;
11700 int lr_count;
11701 int dynamic;
11702 int af_cfgd;
11703
11704 conf = group->conf;
11705
11706 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11707 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11708 group->name, conf->as);
11709 } else if (conf->as_type == AS_INTERNAL) {
11710 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11711 group->name, group->bgp->as);
11712 } else {
11713 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11714 }
11715
11716 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11717 vty_out(vty, " Peer-group type is internal\n");
11718 else
11719 vty_out(vty, " Peer-group type is external\n");
11720
11721 /* Display AFs configured. */
11722 vty_out(vty, " Configured address-families:");
11723 FOREACH_AFI_SAFI (afi, safi) {
11724 if (conf->afc[afi][safi]) {
11725 af_cfgd = 1;
11726 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11727 }
11728 }
11729 if (!af_cfgd)
11730 vty_out(vty, " none\n");
11731 else
11732 vty_out(vty, "\n");
11733
11734 /* Display listen ranges (for dynamic neighbors), if any */
11735 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11736 if (afi == AFI_IP)
11737 af_str = "IPv4";
11738 else if (afi == AFI_IP6)
11739 af_str = "IPv6";
11740 else
11741 af_str = "???";
11742 lr_count = listcount(group->listen_range[afi]);
11743 if (lr_count) {
11744 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11745 af_str);
11746
11747
11748 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11749 nnode, range)) {
11750 prefix2str(range, buf, sizeof(buf));
11751 vty_out(vty, " %s\n", buf);
11752 }
11753 }
11754 }
11755
11756 /* Display group members and their status */
11757 if (listcount(group->peer)) {
11758 vty_out(vty, " Peer-group members:\n");
11759 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11760 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11761 peer_status = "Idle (Admin)";
11762 else if (CHECK_FLAG(peer->sflags,
11763 PEER_STATUS_PREFIX_OVERFLOW))
11764 peer_status = "Idle (PfxCt)";
11765 else
11766 peer_status = lookup_msg(bgp_status_msg,
11767 peer->status, NULL);
11768
11769 dynamic = peer_dynamic_neighbor(peer);
11770 vty_out(vty, " %s %s %s \n", peer->host,
11771 dynamic ? "(dynamic)" : "", peer_status);
11772 }
11773 }
11774
11775 return CMD_SUCCESS;
11776 }
11777
11778 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11779 const char *group_name)
11780 {
11781 struct bgp *bgp;
11782 struct listnode *node, *nnode;
11783 struct peer_group *group;
11784 bool found = false;
11785
11786 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11787
11788 if (!bgp) {
11789 vty_out(vty, "%% BGP instance not found\n");
11790 return CMD_WARNING;
11791 }
11792
11793 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11794 if (group_name) {
11795 if (strmatch(group->name, group_name)) {
11796 bgp_show_one_peer_group(vty, group);
11797 found = true;
11798 break;
11799 }
11800 } else {
11801 bgp_show_one_peer_group(vty, group);
11802 }
11803 }
11804
11805 if (group_name && !found)
11806 vty_out(vty, "%% No such peer-group\n");
11807
11808 return CMD_SUCCESS;
11809 }
11810
11811 DEFUN (show_ip_bgp_peer_groups,
11812 show_ip_bgp_peer_groups_cmd,
11813 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11814 SHOW_STR
11815 IP_STR
11816 BGP_STR
11817 BGP_INSTANCE_HELP_STR
11818 "Detailed information on BGP peer groups\n"
11819 "Peer group name\n")
11820 {
11821 char *vrf, *pg;
11822 int idx = 0;
11823
11824 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11825 : NULL;
11826 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11827
11828 return bgp_show_peer_group_vty(vty, vrf, pg);
11829 }
11830
11831
11832 /* Redistribute VTY commands. */
11833
11834 DEFUN (bgp_redistribute_ipv4,
11835 bgp_redistribute_ipv4_cmd,
11836 "redistribute " FRR_IP_REDIST_STR_BGPD,
11837 "Redistribute information from another routing protocol\n"
11838 FRR_IP_REDIST_HELP_STR_BGPD)
11839 {
11840 VTY_DECLVAR_CONTEXT(bgp, bgp);
11841 int idx_protocol = 1;
11842 int type;
11843
11844 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11845 if (type < 0) {
11846 vty_out(vty, "%% Invalid route type\n");
11847 return CMD_WARNING_CONFIG_FAILED;
11848 }
11849
11850 bgp_redist_add(bgp, AFI_IP, type, 0);
11851 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11852 }
11853
11854 ALIAS_HIDDEN(
11855 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11856 "redistribute " FRR_IP_REDIST_STR_BGPD,
11857 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11858
11859 DEFUN (bgp_redistribute_ipv4_rmap,
11860 bgp_redistribute_ipv4_rmap_cmd,
11861 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11862 "Redistribute information from another routing protocol\n"
11863 FRR_IP_REDIST_HELP_STR_BGPD
11864 "Route map reference\n"
11865 "Pointer to route-map entries\n")
11866 {
11867 VTY_DECLVAR_CONTEXT(bgp, bgp);
11868 int idx_protocol = 1;
11869 int idx_word = 3;
11870 int type;
11871 struct bgp_redist *red;
11872 bool changed;
11873 struct route_map *route_map = route_map_lookup_warn_noexist(
11874 vty, argv[idx_word]->arg);
11875
11876 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11877 if (type < 0) {
11878 vty_out(vty, "%% Invalid route type\n");
11879 return CMD_WARNING_CONFIG_FAILED;
11880 }
11881
11882 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11883 changed =
11884 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11885 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11886 }
11887
11888 ALIAS_HIDDEN(
11889 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11890 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11891 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11892 "Route map reference\n"
11893 "Pointer to route-map entries\n")
11894
11895 DEFUN (bgp_redistribute_ipv4_metric,
11896 bgp_redistribute_ipv4_metric_cmd,
11897 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11898 "Redistribute information from another routing protocol\n"
11899 FRR_IP_REDIST_HELP_STR_BGPD
11900 "Metric for redistributed routes\n"
11901 "Default metric\n")
11902 {
11903 VTY_DECLVAR_CONTEXT(bgp, bgp);
11904 int idx_protocol = 1;
11905 int idx_number = 3;
11906 int type;
11907 uint32_t metric;
11908 struct bgp_redist *red;
11909 bool changed;
11910
11911 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11912 if (type < 0) {
11913 vty_out(vty, "%% Invalid route type\n");
11914 return CMD_WARNING_CONFIG_FAILED;
11915 }
11916 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11917
11918 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11919 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11920 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11921 }
11922
11923 ALIAS_HIDDEN(
11924 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11925 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11926 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11927 "Metric for redistributed routes\n"
11928 "Default metric\n")
11929
11930 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11931 bgp_redistribute_ipv4_rmap_metric_cmd,
11932 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11933 "Redistribute information from another routing protocol\n"
11934 FRR_IP_REDIST_HELP_STR_BGPD
11935 "Route map reference\n"
11936 "Pointer to route-map entries\n"
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_word = 3;
11943 int idx_number = 5;
11944 int type;
11945 uint32_t metric;
11946 struct bgp_redist *red;
11947 bool changed;
11948 struct route_map *route_map =
11949 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11950
11951 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11952 if (type < 0) {
11953 vty_out(vty, "%% Invalid route type\n");
11954 return CMD_WARNING_CONFIG_FAILED;
11955 }
11956 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11957
11958 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11959 changed =
11960 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11961 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11962 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11963 }
11964
11965 ALIAS_HIDDEN(
11966 bgp_redistribute_ipv4_rmap_metric,
11967 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11968 "redistribute " FRR_IP_REDIST_STR_BGPD
11969 " route-map WORD metric (0-4294967295)",
11970 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11971 "Route map reference\n"
11972 "Pointer to route-map entries\n"
11973 "Metric for redistributed routes\n"
11974 "Default metric\n")
11975
11976 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11977 bgp_redistribute_ipv4_metric_rmap_cmd,
11978 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11979 "Redistribute information from another routing protocol\n"
11980 FRR_IP_REDIST_HELP_STR_BGPD
11981 "Metric for redistributed routes\n"
11982 "Default metric\n"
11983 "Route map reference\n"
11984 "Pointer to route-map entries\n")
11985 {
11986 VTY_DECLVAR_CONTEXT(bgp, bgp);
11987 int idx_protocol = 1;
11988 int idx_number = 3;
11989 int idx_word = 5;
11990 int type;
11991 uint32_t metric;
11992 struct bgp_redist *red;
11993 bool changed;
11994 struct route_map *route_map =
11995 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11996
11997 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11998 if (type < 0) {
11999 vty_out(vty, "%% Invalid route type\n");
12000 return CMD_WARNING_CONFIG_FAILED;
12001 }
12002 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12003
12004 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12005 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12006 changed |=
12007 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12008 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12009 }
12010
12011 ALIAS_HIDDEN(
12012 bgp_redistribute_ipv4_metric_rmap,
12013 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12014 "redistribute " FRR_IP_REDIST_STR_BGPD
12015 " metric (0-4294967295) route-map WORD",
12016 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12017 "Metric for redistributed routes\n"
12018 "Default metric\n"
12019 "Route map reference\n"
12020 "Pointer to route-map entries\n")
12021
12022 DEFUN (bgp_redistribute_ipv4_ospf,
12023 bgp_redistribute_ipv4_ospf_cmd,
12024 "redistribute <ospf|table> (1-65535)",
12025 "Redistribute information from another routing protocol\n"
12026 "Open Shortest Path First (OSPFv2)\n"
12027 "Non-main Kernel Routing Table\n"
12028 "Instance ID/Table ID\n")
12029 {
12030 VTY_DECLVAR_CONTEXT(bgp, bgp);
12031 int idx_ospf_table = 1;
12032 int idx_number = 2;
12033 unsigned short instance;
12034 unsigned short protocol;
12035
12036 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12037
12038 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12039 protocol = ZEBRA_ROUTE_OSPF;
12040 else
12041 protocol = ZEBRA_ROUTE_TABLE;
12042
12043 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12044 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12045 }
12046
12047 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12048 "redistribute <ospf|table> (1-65535)",
12049 "Redistribute information from another routing protocol\n"
12050 "Open Shortest Path First (OSPFv2)\n"
12051 "Non-main Kernel Routing Table\n"
12052 "Instance ID/Table ID\n")
12053
12054 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12055 bgp_redistribute_ipv4_ospf_rmap_cmd,
12056 "redistribute <ospf|table> (1-65535) route-map WORD",
12057 "Redistribute information from another routing protocol\n"
12058 "Open Shortest Path First (OSPFv2)\n"
12059 "Non-main Kernel Routing Table\n"
12060 "Instance ID/Table ID\n"
12061 "Route map reference\n"
12062 "Pointer to route-map entries\n")
12063 {
12064 VTY_DECLVAR_CONTEXT(bgp, bgp);
12065 int idx_ospf_table = 1;
12066 int idx_number = 2;
12067 int idx_word = 4;
12068 struct bgp_redist *red;
12069 unsigned short instance;
12070 int protocol;
12071 bool changed;
12072 struct route_map *route_map =
12073 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12074
12075 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12076 protocol = ZEBRA_ROUTE_OSPF;
12077 else
12078 protocol = ZEBRA_ROUTE_TABLE;
12079
12080 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12081 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12082 changed =
12083 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12084 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12085 }
12086
12087 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12088 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12089 "redistribute <ospf|table> (1-65535) route-map WORD",
12090 "Redistribute information from another routing protocol\n"
12091 "Open Shortest Path First (OSPFv2)\n"
12092 "Non-main Kernel Routing Table\n"
12093 "Instance ID/Table ID\n"
12094 "Route map reference\n"
12095 "Pointer to route-map entries\n")
12096
12097 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12098 bgp_redistribute_ipv4_ospf_metric_cmd,
12099 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12100 "Redistribute information from another routing protocol\n"
12101 "Open Shortest Path First (OSPFv2)\n"
12102 "Non-main Kernel Routing Table\n"
12103 "Instance ID/Table ID\n"
12104 "Metric for redistributed routes\n"
12105 "Default metric\n")
12106 {
12107 VTY_DECLVAR_CONTEXT(bgp, bgp);
12108 int idx_ospf_table = 1;
12109 int idx_number = 2;
12110 int idx_number_2 = 4;
12111 uint32_t metric;
12112 struct bgp_redist *red;
12113 unsigned short instance;
12114 int protocol;
12115 bool changed;
12116
12117 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12118 protocol = ZEBRA_ROUTE_OSPF;
12119 else
12120 protocol = ZEBRA_ROUTE_TABLE;
12121
12122 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12123 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12124
12125 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12126 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12127 metric);
12128 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12129 }
12130
12131 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12132 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12133 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12134 "Redistribute information from another routing protocol\n"
12135 "Open Shortest Path First (OSPFv2)\n"
12136 "Non-main Kernel Routing Table\n"
12137 "Instance ID/Table ID\n"
12138 "Metric for redistributed routes\n"
12139 "Default metric\n")
12140
12141 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12142 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12143 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12144 "Redistribute information from another routing protocol\n"
12145 "Open Shortest Path First (OSPFv2)\n"
12146 "Non-main Kernel Routing Table\n"
12147 "Instance ID/Table ID\n"
12148 "Route map reference\n"
12149 "Pointer to route-map entries\n"
12150 "Metric for redistributed routes\n"
12151 "Default metric\n")
12152 {
12153 VTY_DECLVAR_CONTEXT(bgp, bgp);
12154 int idx_ospf_table = 1;
12155 int idx_number = 2;
12156 int idx_word = 4;
12157 int idx_number_2 = 6;
12158 uint32_t metric;
12159 struct bgp_redist *red;
12160 unsigned short instance;
12161 int protocol;
12162 bool changed;
12163 struct route_map *route_map =
12164 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12165
12166 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12167 protocol = ZEBRA_ROUTE_OSPF;
12168 else
12169 protocol = ZEBRA_ROUTE_TABLE;
12170
12171 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12172 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12173
12174 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12175 changed =
12176 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12177 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12178 metric);
12179 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12180 }
12181
12182 ALIAS_HIDDEN(
12183 bgp_redistribute_ipv4_ospf_rmap_metric,
12184 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12185 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12186 "Redistribute information from another routing protocol\n"
12187 "Open Shortest Path First (OSPFv2)\n"
12188 "Non-main Kernel Routing Table\n"
12189 "Instance ID/Table ID\n"
12190 "Route map reference\n"
12191 "Pointer to route-map entries\n"
12192 "Metric for redistributed routes\n"
12193 "Default metric\n")
12194
12195 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12196 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12197 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12198 "Redistribute information from another routing protocol\n"
12199 "Open Shortest Path First (OSPFv2)\n"
12200 "Non-main Kernel Routing Table\n"
12201 "Instance ID/Table ID\n"
12202 "Metric for redistributed routes\n"
12203 "Default metric\n"
12204 "Route map reference\n"
12205 "Pointer to route-map entries\n")
12206 {
12207 VTY_DECLVAR_CONTEXT(bgp, bgp);
12208 int idx_ospf_table = 1;
12209 int idx_number = 2;
12210 int idx_number_2 = 4;
12211 int idx_word = 6;
12212 uint32_t metric;
12213 struct bgp_redist *red;
12214 unsigned short instance;
12215 int protocol;
12216 bool changed;
12217 struct route_map *route_map =
12218 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12219
12220 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12221 protocol = ZEBRA_ROUTE_OSPF;
12222 else
12223 protocol = ZEBRA_ROUTE_TABLE;
12224
12225 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12226 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12227
12228 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12229 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12230 metric);
12231 changed |=
12232 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12233 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12234 }
12235
12236 ALIAS_HIDDEN(
12237 bgp_redistribute_ipv4_ospf_metric_rmap,
12238 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12239 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12240 "Redistribute information from another routing protocol\n"
12241 "Open Shortest Path First (OSPFv2)\n"
12242 "Non-main Kernel Routing Table\n"
12243 "Instance ID/Table ID\n"
12244 "Metric for redistributed routes\n"
12245 "Default metric\n"
12246 "Route map reference\n"
12247 "Pointer to route-map entries\n")
12248
12249 DEFUN (no_bgp_redistribute_ipv4_ospf,
12250 no_bgp_redistribute_ipv4_ospf_cmd,
12251 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12252 NO_STR
12253 "Redistribute information from another routing protocol\n"
12254 "Open Shortest Path First (OSPFv2)\n"
12255 "Non-main Kernel Routing Table\n"
12256 "Instance ID/Table ID\n"
12257 "Metric for redistributed routes\n"
12258 "Default metric\n"
12259 "Route map reference\n"
12260 "Pointer to route-map entries\n")
12261 {
12262 VTY_DECLVAR_CONTEXT(bgp, bgp);
12263 int idx_ospf_table = 2;
12264 int idx_number = 3;
12265 unsigned short instance;
12266 int protocol;
12267
12268 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12269 protocol = ZEBRA_ROUTE_OSPF;
12270 else
12271 protocol = ZEBRA_ROUTE_TABLE;
12272
12273 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12274 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12275 }
12276
12277 ALIAS_HIDDEN(
12278 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12279 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12280 NO_STR
12281 "Redistribute information from another routing protocol\n"
12282 "Open Shortest Path First (OSPFv2)\n"
12283 "Non-main Kernel Routing Table\n"
12284 "Instance ID/Table ID\n"
12285 "Metric for redistributed routes\n"
12286 "Default metric\n"
12287 "Route map reference\n"
12288 "Pointer to route-map entries\n")
12289
12290 DEFUN (no_bgp_redistribute_ipv4,
12291 no_bgp_redistribute_ipv4_cmd,
12292 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12293 NO_STR
12294 "Redistribute information from another routing protocol\n"
12295 FRR_IP_REDIST_HELP_STR_BGPD
12296 "Metric for redistributed routes\n"
12297 "Default metric\n"
12298 "Route map reference\n"
12299 "Pointer to route-map entries\n")
12300 {
12301 VTY_DECLVAR_CONTEXT(bgp, bgp);
12302 int idx_protocol = 2;
12303 int type;
12304
12305 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12306 if (type < 0) {
12307 vty_out(vty, "%% Invalid route type\n");
12308 return CMD_WARNING_CONFIG_FAILED;
12309 }
12310 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12311 }
12312
12313 ALIAS_HIDDEN(
12314 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12315 "no redistribute " FRR_IP_REDIST_STR_BGPD
12316 " [metric (0-4294967295)] [route-map WORD]",
12317 NO_STR
12318 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12319 "Metric for redistributed routes\n"
12320 "Default metric\n"
12321 "Route map reference\n"
12322 "Pointer to route-map entries\n")
12323
12324 DEFUN (bgp_redistribute_ipv6,
12325 bgp_redistribute_ipv6_cmd,
12326 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12327 "Redistribute information from another routing protocol\n"
12328 FRR_IP6_REDIST_HELP_STR_BGPD)
12329 {
12330 VTY_DECLVAR_CONTEXT(bgp, bgp);
12331 int idx_protocol = 1;
12332 int type;
12333
12334 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12335 if (type < 0) {
12336 vty_out(vty, "%% Invalid route type\n");
12337 return CMD_WARNING_CONFIG_FAILED;
12338 }
12339
12340 bgp_redist_add(bgp, AFI_IP6, type, 0);
12341 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12342 }
12343
12344 DEFUN (bgp_redistribute_ipv6_rmap,
12345 bgp_redistribute_ipv6_rmap_cmd,
12346 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12347 "Redistribute information from another routing protocol\n"
12348 FRR_IP6_REDIST_HELP_STR_BGPD
12349 "Route map reference\n"
12350 "Pointer to route-map entries\n")
12351 {
12352 VTY_DECLVAR_CONTEXT(bgp, bgp);
12353 int idx_protocol = 1;
12354 int idx_word = 3;
12355 int type;
12356 struct bgp_redist *red;
12357 bool changed;
12358 struct route_map *route_map =
12359 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12360
12361 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12362 if (type < 0) {
12363 vty_out(vty, "%% Invalid route type\n");
12364 return CMD_WARNING_CONFIG_FAILED;
12365 }
12366
12367 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12368 changed =
12369 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12370 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12371 }
12372
12373 DEFUN (bgp_redistribute_ipv6_metric,
12374 bgp_redistribute_ipv6_metric_cmd,
12375 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12376 "Redistribute information from another routing protocol\n"
12377 FRR_IP6_REDIST_HELP_STR_BGPD
12378 "Metric for redistributed routes\n"
12379 "Default metric\n")
12380 {
12381 VTY_DECLVAR_CONTEXT(bgp, bgp);
12382 int idx_protocol = 1;
12383 int idx_number = 3;
12384 int type;
12385 uint32_t metric;
12386 struct bgp_redist *red;
12387 bool changed;
12388
12389 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12390 if (type < 0) {
12391 vty_out(vty, "%% Invalid route type\n");
12392 return CMD_WARNING_CONFIG_FAILED;
12393 }
12394 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12395
12396 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12397 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12398 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12399 }
12400
12401 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12402 bgp_redistribute_ipv6_rmap_metric_cmd,
12403 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12404 "Redistribute information from another routing protocol\n"
12405 FRR_IP6_REDIST_HELP_STR_BGPD
12406 "Route map reference\n"
12407 "Pointer to route-map entries\n"
12408 "Metric for redistributed routes\n"
12409 "Default metric\n")
12410 {
12411 VTY_DECLVAR_CONTEXT(bgp, bgp);
12412 int idx_protocol = 1;
12413 int idx_word = 3;
12414 int idx_number = 5;
12415 int type;
12416 uint32_t metric;
12417 struct bgp_redist *red;
12418 bool changed;
12419 struct route_map *route_map =
12420 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12421
12422 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12423 if (type < 0) {
12424 vty_out(vty, "%% Invalid route type\n");
12425 return CMD_WARNING_CONFIG_FAILED;
12426 }
12427 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12428
12429 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12430 changed =
12431 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12432 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12433 metric);
12434 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12435 }
12436
12437 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12438 bgp_redistribute_ipv6_metric_rmap_cmd,
12439 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12440 "Redistribute information from another routing protocol\n"
12441 FRR_IP6_REDIST_HELP_STR_BGPD
12442 "Metric for redistributed routes\n"
12443 "Default metric\n"
12444 "Route map reference\n"
12445 "Pointer to route-map entries\n")
12446 {
12447 VTY_DECLVAR_CONTEXT(bgp, bgp);
12448 int idx_protocol = 1;
12449 int idx_number = 3;
12450 int idx_word = 5;
12451 int type;
12452 uint32_t metric;
12453 struct bgp_redist *red;
12454 bool changed;
12455 struct route_map *route_map =
12456 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12457
12458 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12459 if (type < 0) {
12460 vty_out(vty, "%% Invalid route type\n");
12461 return CMD_WARNING_CONFIG_FAILED;
12462 }
12463 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12464
12465 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12466 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12467 metric);
12468 changed |=
12469 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12470 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12471 }
12472
12473 DEFUN (no_bgp_redistribute_ipv6,
12474 no_bgp_redistribute_ipv6_cmd,
12475 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12476 NO_STR
12477 "Redistribute information from another routing protocol\n"
12478 FRR_IP6_REDIST_HELP_STR_BGPD
12479 "Metric for redistributed routes\n"
12480 "Default metric\n"
12481 "Route map reference\n"
12482 "Pointer to route-map entries\n")
12483 {
12484 VTY_DECLVAR_CONTEXT(bgp, bgp);
12485 int idx_protocol = 2;
12486 int type;
12487
12488 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12489 if (type < 0) {
12490 vty_out(vty, "%% Invalid route type\n");
12491 return CMD_WARNING_CONFIG_FAILED;
12492 }
12493
12494 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12495 }
12496
12497 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12498 safi_t safi)
12499 {
12500 int i;
12501
12502 /* Unicast redistribution only. */
12503 if (safi != SAFI_UNICAST)
12504 return;
12505
12506 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12507 /* Redistribute BGP does not make sense. */
12508 if (i != ZEBRA_ROUTE_BGP) {
12509 struct list *red_list;
12510 struct listnode *node;
12511 struct bgp_redist *red;
12512
12513 red_list = bgp->redist[afi][i];
12514 if (!red_list)
12515 continue;
12516
12517 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12518 /* "redistribute" configuration. */
12519 vty_out(vty, " redistribute %s",
12520 zebra_route_string(i));
12521 if (red->instance)
12522 vty_out(vty, " %d", red->instance);
12523 if (red->redist_metric_flag)
12524 vty_out(vty, " metric %u",
12525 red->redist_metric);
12526 if (red->rmap.name)
12527 vty_out(vty, " route-map %s",
12528 red->rmap.name);
12529 vty_out(vty, "\n");
12530 }
12531 }
12532 }
12533 }
12534
12535 /* This is part of the address-family block (unicast only) */
12536 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12537 afi_t afi)
12538 {
12539 int indent = 2;
12540
12541 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12542 if (listcount(bgp->vpn_policy[afi].import_vrf))
12543 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12544 bgp->vpn_policy[afi]
12545 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12546 else
12547 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12548 bgp->vpn_policy[afi]
12549 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12550 }
12551 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12552 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12553 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12554 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12555 return;
12556
12557 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12558 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12559
12560 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12561
12562 } else {
12563 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12564 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12565 bgp->vpn_policy[afi].tovpn_label);
12566 }
12567 }
12568 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12569 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12570 char buf[RD_ADDRSTRLEN];
12571 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12572 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12573 sizeof(buf)));
12574 }
12575 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12576 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12577
12578 char buf[PREFIX_STRLEN];
12579 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12580 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12581 sizeof(buf))) {
12582
12583 vty_out(vty, "%*snexthop vpn export %s\n",
12584 indent, "", buf);
12585 }
12586 }
12587 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12588 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12589 && ecommunity_cmp(
12590 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12591 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12592
12593 char *b = ecommunity_ecom2str(
12594 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12595 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12596 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12597 XFREE(MTYPE_ECOMMUNITY_STR, b);
12598 } else {
12599 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12600 char *b = ecommunity_ecom2str(
12601 bgp->vpn_policy[afi]
12602 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12603 ECOMMUNITY_FORMAT_ROUTE_MAP,
12604 ECOMMUNITY_ROUTE_TARGET);
12605 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12606 XFREE(MTYPE_ECOMMUNITY_STR, b);
12607 }
12608 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12609 char *b = ecommunity_ecom2str(
12610 bgp->vpn_policy[afi]
12611 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12612 ECOMMUNITY_FORMAT_ROUTE_MAP,
12613 ECOMMUNITY_ROUTE_TARGET);
12614 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12615 XFREE(MTYPE_ECOMMUNITY_STR, b);
12616 }
12617 }
12618
12619 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12620 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12621 bgp->vpn_policy[afi]
12622 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12623
12624 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12625 char *b = ecommunity_ecom2str(
12626 bgp->vpn_policy[afi]
12627 .import_redirect_rtlist,
12628 ECOMMUNITY_FORMAT_ROUTE_MAP,
12629 ECOMMUNITY_ROUTE_TARGET);
12630
12631 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12632 XFREE(MTYPE_ECOMMUNITY_STR, b);
12633 }
12634 }
12635
12636
12637 /* BGP node structure. */
12638 static struct cmd_node bgp_node = {
12639 BGP_NODE, "%s(config-router)# ", 1,
12640 };
12641
12642 static struct cmd_node bgp_ipv4_unicast_node = {
12643 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12644 };
12645
12646 static struct cmd_node bgp_ipv4_multicast_node = {
12647 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12648 };
12649
12650 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12651 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12652 };
12653
12654 static struct cmd_node bgp_ipv6_unicast_node = {
12655 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12656 };
12657
12658 static struct cmd_node bgp_ipv6_multicast_node = {
12659 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12660 };
12661
12662 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12663 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12664 };
12665
12666 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12667 "%s(config-router-af)# ", 1};
12668
12669 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12670 "%s(config-router-af-vpnv6)# ", 1};
12671
12672 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12673 "%s(config-router-evpn)# ", 1};
12674
12675 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12676 "%s(config-router-af-vni)# ", 1};
12677
12678 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12679 "%s(config-router-af)# ", 1};
12680
12681 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12682 "%s(config-router-af-vpnv6)# ", 1};
12683
12684 static void community_list_vty(void);
12685
12686 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12687 {
12688 struct bgp *bgp;
12689 struct peer *peer;
12690 struct listnode *lnbgp, *lnpeer;
12691
12692 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12693 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12694 /* only provide suggestions on the appropriate input
12695 * token type,
12696 * they'll otherwise show up multiple times */
12697 enum cmd_token_type match_type;
12698 char *name = peer->host;
12699
12700 if (peer->conf_if) {
12701 match_type = VARIABLE_TKN;
12702 name = peer->conf_if;
12703 } else if (strchr(peer->host, ':'))
12704 match_type = IPV6_TKN;
12705 else
12706 match_type = IPV4_TKN;
12707
12708 if (token->type != match_type)
12709 continue;
12710
12711 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12712 }
12713 }
12714 }
12715
12716 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12717 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12718 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12719 {.varname = "peer", .completions = bgp_ac_neighbor},
12720 {.completions = NULL}};
12721
12722 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12723 {
12724 struct bgp *bgp;
12725 struct peer_group *group;
12726 struct listnode *lnbgp, *lnpeer;
12727
12728 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12729 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12730 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12731 group->name));
12732 }
12733 }
12734
12735 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12736 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12737 {.completions = NULL} };
12738
12739 void bgp_vty_init(void)
12740 {
12741 cmd_variable_handler_register(bgp_var_neighbor);
12742 cmd_variable_handler_register(bgp_var_peergroup);
12743
12744 /* Install bgp top node. */
12745 install_node(&bgp_node, bgp_config_write);
12746 install_node(&bgp_ipv4_unicast_node, NULL);
12747 install_node(&bgp_ipv4_multicast_node, NULL);
12748 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12749 install_node(&bgp_ipv6_unicast_node, NULL);
12750 install_node(&bgp_ipv6_multicast_node, NULL);
12751 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12752 install_node(&bgp_vpnv4_node, NULL);
12753 install_node(&bgp_vpnv6_node, NULL);
12754 install_node(&bgp_evpn_node, NULL);
12755 install_node(&bgp_evpn_vni_node, NULL);
12756 install_node(&bgp_flowspecv4_node, NULL);
12757 install_node(&bgp_flowspecv6_node, NULL);
12758
12759 /* Install default VTY commands to new nodes. */
12760 install_default(BGP_NODE);
12761 install_default(BGP_IPV4_NODE);
12762 install_default(BGP_IPV4M_NODE);
12763 install_default(BGP_IPV4L_NODE);
12764 install_default(BGP_IPV6_NODE);
12765 install_default(BGP_IPV6M_NODE);
12766 install_default(BGP_IPV6L_NODE);
12767 install_default(BGP_VPNV4_NODE);
12768 install_default(BGP_VPNV6_NODE);
12769 install_default(BGP_FLOWSPECV4_NODE);
12770 install_default(BGP_FLOWSPECV6_NODE);
12771 install_default(BGP_EVPN_NODE);
12772 install_default(BGP_EVPN_VNI_NODE);
12773
12774 /* "bgp multiple-instance" commands. */
12775 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12776 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12777
12778 /* "bgp config-type" commands. */
12779 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12780 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12781
12782 /* "bgp local-mac" hidden commands. */
12783 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12784 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12785
12786 /* bgp route-map delay-timer commands. */
12787 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12788 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12789
12790 /* Dummy commands (Currently not supported) */
12791 install_element(BGP_NODE, &no_synchronization_cmd);
12792 install_element(BGP_NODE, &no_auto_summary_cmd);
12793
12794 /* "router bgp" commands. */
12795 install_element(CONFIG_NODE, &router_bgp_cmd);
12796
12797 /* "no router bgp" commands. */
12798 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12799
12800 /* "bgp router-id" commands. */
12801 install_element(BGP_NODE, &bgp_router_id_cmd);
12802 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12803
12804 /* "bgp cluster-id" commands. */
12805 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12806 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12807
12808 /* "bgp confederation" commands. */
12809 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12810 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12811
12812 /* "bgp confederation peers" commands. */
12813 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12814 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12815
12816 /* bgp max-med command */
12817 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12818 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12819 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12820 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12821 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12822
12823 /* bgp disable-ebgp-connected-nh-check */
12824 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12825 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12826
12827 /* bgp update-delay command */
12828 install_element(BGP_NODE, &bgp_update_delay_cmd);
12829 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12830 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12831
12832 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12833 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12834 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12835 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12836
12837 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12838 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12839
12840 /* "maximum-paths" commands. */
12841 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12842 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12843 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12844 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12845 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12846 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12847 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12848 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12849 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12850 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12851 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12852 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12853 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12854 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12855 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12856
12857 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12858 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12859 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12860 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12861 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12862
12863 /* "timers bgp" commands. */
12864 install_element(BGP_NODE, &bgp_timers_cmd);
12865 install_element(BGP_NODE, &no_bgp_timers_cmd);
12866
12867 /* route-map delay-timer commands - per instance for backwards compat.
12868 */
12869 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12870 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12871
12872 /* "bgp client-to-client reflection" commands */
12873 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12874 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12875
12876 /* "bgp always-compare-med" commands */
12877 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12878 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12879
12880 /* bgp ebgp-requires-policy */
12881 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12882 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12883
12884 /* "bgp deterministic-med" commands */
12885 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12886 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12887
12888 /* "bgp graceful-restart" commands */
12889 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12890 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12891 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12892 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12893 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12894 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12895
12896 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12897 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12898
12899 /* "bgp graceful-shutdown" commands */
12900 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12901 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12902
12903 /* "bgp fast-external-failover" commands */
12904 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12905 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12906
12907 /* "bgp enforce-first-as" commands */
12908 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12909
12910 /* "bgp bestpath compare-routerid" commands */
12911 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12912 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12913
12914 /* "bgp bestpath as-path ignore" commands */
12915 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12916 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12917
12918 /* "bgp bestpath as-path confed" commands */
12919 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12920 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12921
12922 /* "bgp bestpath as-path multipath-relax" commands */
12923 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12924 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12925
12926 /* "bgp log-neighbor-changes" commands */
12927 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12928 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12929
12930 /* "bgp bestpath med" commands */
12931 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12932 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12933
12934 /* "no bgp default ipv4-unicast" commands. */
12935 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12936 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12937
12938 /* "bgp network import-check" commands. */
12939 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12940 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12941 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12942
12943 /* "bgp default local-preference" commands. */
12944 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12945 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12946
12947 /* bgp default show-hostname */
12948 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12949 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12950
12951 /* "bgp default subgroup-pkt-queue-max" commands. */
12952 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12953 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12954
12955 /* bgp ibgp-allow-policy-mods command */
12956 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12957 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12958
12959 /* "bgp listen limit" commands. */
12960 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12961 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12962
12963 /* "bgp listen range" commands. */
12964 install_element(BGP_NODE, &bgp_listen_range_cmd);
12965 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12966
12967 /* "bgp default shutdown" command */
12968 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12969
12970 /* "neighbor remote-as" commands. */
12971 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12972 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12973 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12974 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12975 install_element(BGP_NODE,
12976 &neighbor_interface_v6only_config_remote_as_cmd);
12977 install_element(BGP_NODE, &no_neighbor_cmd);
12978 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12979
12980 /* "neighbor peer-group" commands. */
12981 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12982 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12983 install_element(BGP_NODE,
12984 &no_neighbor_interface_peer_group_remote_as_cmd);
12985
12986 /* "neighbor local-as" commands. */
12987 install_element(BGP_NODE, &neighbor_local_as_cmd);
12988 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12989 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12990 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12991
12992 /* "neighbor solo" commands. */
12993 install_element(BGP_NODE, &neighbor_solo_cmd);
12994 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12995
12996 /* "neighbor password" commands. */
12997 install_element(BGP_NODE, &neighbor_password_cmd);
12998 install_element(BGP_NODE, &no_neighbor_password_cmd);
12999
13000 /* "neighbor activate" commands. */
13001 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
13002 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
13003 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
13004 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13005 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13006 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13007 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13008 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13009 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13010 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13011 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13012 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13013
13014 /* "no neighbor activate" commands. */
13015 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13016 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13017 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13018 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13019 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13020 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13021 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13022 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13023 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13024 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13025 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13026 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13027
13028 /* "neighbor peer-group" set commands. */
13029 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13030 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13031 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13032 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13033 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13034 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13035 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13036 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13037 install_element(BGP_FLOWSPECV4_NODE,
13038 &neighbor_set_peer_group_hidden_cmd);
13039 install_element(BGP_FLOWSPECV6_NODE,
13040 &neighbor_set_peer_group_hidden_cmd);
13041
13042 /* "no neighbor peer-group unset" commands. */
13043 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13044 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13045 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13046 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13047 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13048 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13049 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13050 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13051 install_element(BGP_FLOWSPECV4_NODE,
13052 &no_neighbor_set_peer_group_hidden_cmd);
13053 install_element(BGP_FLOWSPECV6_NODE,
13054 &no_neighbor_set_peer_group_hidden_cmd);
13055
13056 /* "neighbor softreconfiguration inbound" commands.*/
13057 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13058 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13059 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13060 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13061 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13062 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13063 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13064 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13065 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13066 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13067 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13068 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13069 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13070 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13071 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13072 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13073 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13074 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13075 install_element(BGP_FLOWSPECV4_NODE,
13076 &neighbor_soft_reconfiguration_cmd);
13077 install_element(BGP_FLOWSPECV4_NODE,
13078 &no_neighbor_soft_reconfiguration_cmd);
13079 install_element(BGP_FLOWSPECV6_NODE,
13080 &neighbor_soft_reconfiguration_cmd);
13081 install_element(BGP_FLOWSPECV6_NODE,
13082 &no_neighbor_soft_reconfiguration_cmd);
13083 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13084 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13085
13086 /* "neighbor attribute-unchanged" commands. */
13087 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13088 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13089 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13090 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13091 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13092 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13093 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13094 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13095 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13096 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13097 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13098 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13099 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13100 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13101 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13102 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13103 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13104 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13105
13106 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13107 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13108
13109 /* "nexthop-local unchanged" commands */
13110 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13111 install_element(BGP_IPV6_NODE,
13112 &no_neighbor_nexthop_local_unchanged_cmd);
13113
13114 /* "neighbor next-hop-self" commands. */
13115 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13116 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13117 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13118 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13119 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13120 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13121 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13122 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13123 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13124 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13125 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13126 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13127 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13128 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13129 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13130 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13131 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13132 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13133 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13134 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13135
13136 /* "neighbor next-hop-self force" commands. */
13137 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13138 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13139 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13140 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13141 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13142 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13143 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13144 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13145 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13146 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13147 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13148 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13149 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13150 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13151 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13152 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13153 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13154 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13155
13156 /* "neighbor as-override" commands. */
13157 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13158 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13159 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13160 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13161 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13162 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13163 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13164 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13165 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13166 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13167 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13168 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13169 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13170 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13171 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13172 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13173 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13174 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13175
13176 /* "neighbor remove-private-AS" commands. */
13177 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13178 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13179 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13180 install_element(BGP_NODE,
13181 &no_neighbor_remove_private_as_all_hidden_cmd);
13182 install_element(BGP_NODE,
13183 &neighbor_remove_private_as_replace_as_hidden_cmd);
13184 install_element(BGP_NODE,
13185 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13186 install_element(BGP_NODE,
13187 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13188 install_element(
13189 BGP_NODE,
13190 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13191 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13192 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13193 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13194 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13195 install_element(BGP_IPV4_NODE,
13196 &neighbor_remove_private_as_replace_as_cmd);
13197 install_element(BGP_IPV4_NODE,
13198 &no_neighbor_remove_private_as_replace_as_cmd);
13199 install_element(BGP_IPV4_NODE,
13200 &neighbor_remove_private_as_all_replace_as_cmd);
13201 install_element(BGP_IPV4_NODE,
13202 &no_neighbor_remove_private_as_all_replace_as_cmd);
13203 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13204 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13205 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13206 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13207 install_element(BGP_IPV4M_NODE,
13208 &neighbor_remove_private_as_replace_as_cmd);
13209 install_element(BGP_IPV4M_NODE,
13210 &no_neighbor_remove_private_as_replace_as_cmd);
13211 install_element(BGP_IPV4M_NODE,
13212 &neighbor_remove_private_as_all_replace_as_cmd);
13213 install_element(BGP_IPV4M_NODE,
13214 &no_neighbor_remove_private_as_all_replace_as_cmd);
13215 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13216 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13217 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13218 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13219 install_element(BGP_IPV4L_NODE,
13220 &neighbor_remove_private_as_replace_as_cmd);
13221 install_element(BGP_IPV4L_NODE,
13222 &no_neighbor_remove_private_as_replace_as_cmd);
13223 install_element(BGP_IPV4L_NODE,
13224 &neighbor_remove_private_as_all_replace_as_cmd);
13225 install_element(BGP_IPV4L_NODE,
13226 &no_neighbor_remove_private_as_all_replace_as_cmd);
13227 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13228 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13229 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13230 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13231 install_element(BGP_IPV6_NODE,
13232 &neighbor_remove_private_as_replace_as_cmd);
13233 install_element(BGP_IPV6_NODE,
13234 &no_neighbor_remove_private_as_replace_as_cmd);
13235 install_element(BGP_IPV6_NODE,
13236 &neighbor_remove_private_as_all_replace_as_cmd);
13237 install_element(BGP_IPV6_NODE,
13238 &no_neighbor_remove_private_as_all_replace_as_cmd);
13239 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13240 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13241 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13242 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13243 install_element(BGP_IPV6M_NODE,
13244 &neighbor_remove_private_as_replace_as_cmd);
13245 install_element(BGP_IPV6M_NODE,
13246 &no_neighbor_remove_private_as_replace_as_cmd);
13247 install_element(BGP_IPV6M_NODE,
13248 &neighbor_remove_private_as_all_replace_as_cmd);
13249 install_element(BGP_IPV6M_NODE,
13250 &no_neighbor_remove_private_as_all_replace_as_cmd);
13251 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13252 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13253 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13254 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13255 install_element(BGP_IPV6L_NODE,
13256 &neighbor_remove_private_as_replace_as_cmd);
13257 install_element(BGP_IPV6L_NODE,
13258 &no_neighbor_remove_private_as_replace_as_cmd);
13259 install_element(BGP_IPV6L_NODE,
13260 &neighbor_remove_private_as_all_replace_as_cmd);
13261 install_element(BGP_IPV6L_NODE,
13262 &no_neighbor_remove_private_as_all_replace_as_cmd);
13263 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13264 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13265 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13266 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13267 install_element(BGP_VPNV4_NODE,
13268 &neighbor_remove_private_as_replace_as_cmd);
13269 install_element(BGP_VPNV4_NODE,
13270 &no_neighbor_remove_private_as_replace_as_cmd);
13271 install_element(BGP_VPNV4_NODE,
13272 &neighbor_remove_private_as_all_replace_as_cmd);
13273 install_element(BGP_VPNV4_NODE,
13274 &no_neighbor_remove_private_as_all_replace_as_cmd);
13275 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13276 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13277 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13278 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13279 install_element(BGP_VPNV6_NODE,
13280 &neighbor_remove_private_as_replace_as_cmd);
13281 install_element(BGP_VPNV6_NODE,
13282 &no_neighbor_remove_private_as_replace_as_cmd);
13283 install_element(BGP_VPNV6_NODE,
13284 &neighbor_remove_private_as_all_replace_as_cmd);
13285 install_element(BGP_VPNV6_NODE,
13286 &no_neighbor_remove_private_as_all_replace_as_cmd);
13287
13288 /* "neighbor send-community" commands.*/
13289 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13290 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13291 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13292 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13293 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13294 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13295 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13296 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13297 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13298 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13299 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13300 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13301 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13302 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13303 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13304 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13305 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13306 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13307 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13308 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13309 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13310 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13311 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13312 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13313 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13314 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13315 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13316 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13317 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13318 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13319 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13320 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13321 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13322 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13323 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13324 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13325
13326 /* "neighbor route-reflector" commands.*/
13327 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13328 install_element(BGP_NODE,
13329 &no_neighbor_route_reflector_client_hidden_cmd);
13330 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13331 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13332 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13333 install_element(BGP_IPV4M_NODE,
13334 &no_neighbor_route_reflector_client_cmd);
13335 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13336 install_element(BGP_IPV4L_NODE,
13337 &no_neighbor_route_reflector_client_cmd);
13338 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13339 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13340 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13341 install_element(BGP_IPV6M_NODE,
13342 &no_neighbor_route_reflector_client_cmd);
13343 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13344 install_element(BGP_IPV6L_NODE,
13345 &no_neighbor_route_reflector_client_cmd);
13346 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13347 install_element(BGP_VPNV4_NODE,
13348 &no_neighbor_route_reflector_client_cmd);
13349 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13350 install_element(BGP_VPNV6_NODE,
13351 &no_neighbor_route_reflector_client_cmd);
13352 install_element(BGP_FLOWSPECV4_NODE,
13353 &neighbor_route_reflector_client_cmd);
13354 install_element(BGP_FLOWSPECV4_NODE,
13355 &no_neighbor_route_reflector_client_cmd);
13356 install_element(BGP_FLOWSPECV6_NODE,
13357 &neighbor_route_reflector_client_cmd);
13358 install_element(BGP_FLOWSPECV6_NODE,
13359 &no_neighbor_route_reflector_client_cmd);
13360 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13361 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13362
13363 /* "neighbor route-server" commands.*/
13364 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13365 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13366 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13367 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13368 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13369 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13370 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13371 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13372 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13373 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13374 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13375 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13376 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13377 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13378 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13379 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13380 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13381 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13382 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13383 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13384 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13385 install_element(BGP_FLOWSPECV4_NODE,
13386 &no_neighbor_route_server_client_cmd);
13387 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13388 install_element(BGP_FLOWSPECV6_NODE,
13389 &no_neighbor_route_server_client_cmd);
13390
13391 /* "neighbor addpath-tx-all-paths" commands.*/
13392 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13393 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13394 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13395 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13396 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13397 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13398 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13399 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13400 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13401 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13402 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13403 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13404 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13405 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13406 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13407 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13408 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13409 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13410
13411 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13412 install_element(BGP_NODE,
13413 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13414 install_element(BGP_NODE,
13415 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13416 install_element(BGP_IPV4_NODE,
13417 &neighbor_addpath_tx_bestpath_per_as_cmd);
13418 install_element(BGP_IPV4_NODE,
13419 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13420 install_element(BGP_IPV4M_NODE,
13421 &neighbor_addpath_tx_bestpath_per_as_cmd);
13422 install_element(BGP_IPV4M_NODE,
13423 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13424 install_element(BGP_IPV4L_NODE,
13425 &neighbor_addpath_tx_bestpath_per_as_cmd);
13426 install_element(BGP_IPV4L_NODE,
13427 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13428 install_element(BGP_IPV6_NODE,
13429 &neighbor_addpath_tx_bestpath_per_as_cmd);
13430 install_element(BGP_IPV6_NODE,
13431 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13432 install_element(BGP_IPV6M_NODE,
13433 &neighbor_addpath_tx_bestpath_per_as_cmd);
13434 install_element(BGP_IPV6M_NODE,
13435 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13436 install_element(BGP_IPV6L_NODE,
13437 &neighbor_addpath_tx_bestpath_per_as_cmd);
13438 install_element(BGP_IPV6L_NODE,
13439 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13440 install_element(BGP_VPNV4_NODE,
13441 &neighbor_addpath_tx_bestpath_per_as_cmd);
13442 install_element(BGP_VPNV4_NODE,
13443 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13444 install_element(BGP_VPNV6_NODE,
13445 &neighbor_addpath_tx_bestpath_per_as_cmd);
13446 install_element(BGP_VPNV6_NODE,
13447 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13448
13449 /* "neighbor passive" commands. */
13450 install_element(BGP_NODE, &neighbor_passive_cmd);
13451 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13452
13453
13454 /* "neighbor shutdown" commands. */
13455 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13456 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13457 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13458 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13459
13460 /* "neighbor capability extended-nexthop" commands.*/
13461 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13462 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13463
13464 /* "neighbor capability orf prefix-list" commands.*/
13465 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13466 install_element(BGP_NODE,
13467 &no_neighbor_capability_orf_prefix_hidden_cmd);
13468 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13469 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13470 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13471 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13472 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13473 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13474 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13475 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13476 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13477 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13478 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13479 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13480
13481 /* "neighbor capability dynamic" commands.*/
13482 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13483 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13484
13485 /* "neighbor dont-capability-negotiate" commands. */
13486 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13487 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13488
13489 /* "neighbor ebgp-multihop" commands. */
13490 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13491 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13492 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13493
13494 /* "neighbor disable-connected-check" commands. */
13495 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13496 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13497
13498 /* "neighbor enforce-first-as" commands. */
13499 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13500 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13501
13502 /* "neighbor description" commands. */
13503 install_element(BGP_NODE, &neighbor_description_cmd);
13504 install_element(BGP_NODE, &no_neighbor_description_cmd);
13505 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13506
13507 /* "neighbor update-source" commands. "*/
13508 install_element(BGP_NODE, &neighbor_update_source_cmd);
13509 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13510
13511 /* "neighbor default-originate" commands. */
13512 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13513 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13514 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13515 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13516 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13517 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13518 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13519 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13520 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13521 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13522 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13523 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13524 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13525 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13526 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13527 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13528 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13529 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13530 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13531 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13532 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13533
13534 /* "neighbor port" commands. */
13535 install_element(BGP_NODE, &neighbor_port_cmd);
13536 install_element(BGP_NODE, &no_neighbor_port_cmd);
13537
13538 /* "neighbor weight" commands. */
13539 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13540 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13541
13542 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13543 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13544 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13545 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13546 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13547 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13548 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13549 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13550 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13551 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13552 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13553 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13554 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13555 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13556 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13557 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13558
13559 /* "neighbor override-capability" commands. */
13560 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13561 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13562
13563 /* "neighbor strict-capability-match" commands. */
13564 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13565 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13566
13567 /* "neighbor timers" commands. */
13568 install_element(BGP_NODE, &neighbor_timers_cmd);
13569 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13570
13571 /* "neighbor timers connect" commands. */
13572 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13573 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13574
13575 /* "neighbor advertisement-interval" commands. */
13576 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13577 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13578
13579 /* "neighbor interface" commands. */
13580 install_element(BGP_NODE, &neighbor_interface_cmd);
13581 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13582
13583 /* "neighbor distribute" commands. */
13584 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13585 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13586 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13587 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13588 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13589 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13590 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13591 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13592 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13593 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13594 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13595 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13596 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13597 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13598 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13599 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13600 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13601 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13602
13603 /* "neighbor prefix-list" commands. */
13604 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13605 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13606 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13607 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13608 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13609 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13610 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13611 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13612 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13613 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13614 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13615 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13616 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13617 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13618 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13619 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13620 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13621 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13622 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13623 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13624 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13625 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13626
13627 /* "neighbor filter-list" commands. */
13628 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13629 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13630 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13631 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13632 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13633 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13634 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13635 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13636 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13637 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13638 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13639 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13640 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13641 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13642 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13643 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13644 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13645 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13646 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13647 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13648 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13649 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13650
13651 /* "neighbor route-map" commands. */
13652 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13653 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13654 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13655 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13656 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13657 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13658 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13659 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13660 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13661 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13662 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13663 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13664 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13665 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13666 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13667 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13668 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13669 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13670 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13671 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13672 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13673 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13674 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13675 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13676
13677 /* "neighbor unsuppress-map" commands. */
13678 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13679 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13680 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13681 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13682 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13683 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13684 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13685 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13686 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13687 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13688 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13689 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13690 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13691 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13692 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13693 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13694 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13695 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13696
13697 /* "neighbor maximum-prefix" commands. */
13698 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13699 install_element(BGP_NODE,
13700 &neighbor_maximum_prefix_threshold_hidden_cmd);
13701 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13702 install_element(BGP_NODE,
13703 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13704 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13705 install_element(BGP_NODE,
13706 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13707 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13708 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13709 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13710 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13711 install_element(BGP_IPV4_NODE,
13712 &neighbor_maximum_prefix_threshold_warning_cmd);
13713 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13714 install_element(BGP_IPV4_NODE,
13715 &neighbor_maximum_prefix_threshold_restart_cmd);
13716 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13717 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13718 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13719 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13720 install_element(BGP_IPV4M_NODE,
13721 &neighbor_maximum_prefix_threshold_warning_cmd);
13722 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13723 install_element(BGP_IPV4M_NODE,
13724 &neighbor_maximum_prefix_threshold_restart_cmd);
13725 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13726 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13727 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13728 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13729 install_element(BGP_IPV4L_NODE,
13730 &neighbor_maximum_prefix_threshold_warning_cmd);
13731 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13732 install_element(BGP_IPV4L_NODE,
13733 &neighbor_maximum_prefix_threshold_restart_cmd);
13734 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13735 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13736 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13737 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13738 install_element(BGP_IPV6_NODE,
13739 &neighbor_maximum_prefix_threshold_warning_cmd);
13740 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13741 install_element(BGP_IPV6_NODE,
13742 &neighbor_maximum_prefix_threshold_restart_cmd);
13743 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13744 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13745 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13746 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13747 install_element(BGP_IPV6M_NODE,
13748 &neighbor_maximum_prefix_threshold_warning_cmd);
13749 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13750 install_element(BGP_IPV6M_NODE,
13751 &neighbor_maximum_prefix_threshold_restart_cmd);
13752 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13753 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13754 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13755 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13756 install_element(BGP_IPV6L_NODE,
13757 &neighbor_maximum_prefix_threshold_warning_cmd);
13758 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13759 install_element(BGP_IPV6L_NODE,
13760 &neighbor_maximum_prefix_threshold_restart_cmd);
13761 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13762 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13763 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13764 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13765 install_element(BGP_VPNV4_NODE,
13766 &neighbor_maximum_prefix_threshold_warning_cmd);
13767 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13768 install_element(BGP_VPNV4_NODE,
13769 &neighbor_maximum_prefix_threshold_restart_cmd);
13770 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13771 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13772 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13773 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13774 install_element(BGP_VPNV6_NODE,
13775 &neighbor_maximum_prefix_threshold_warning_cmd);
13776 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13777 install_element(BGP_VPNV6_NODE,
13778 &neighbor_maximum_prefix_threshold_restart_cmd);
13779 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13780
13781 /* "neighbor allowas-in" */
13782 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13783 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13784 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13785 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13786 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13787 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13788 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13789 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13790 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13791 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13792 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13793 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13794 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13795 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13796 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13797 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13798 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13799 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13800 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13801 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13802
13803 /* address-family commands. */
13804 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13805 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13806 #ifdef KEEP_OLD_VPN_COMMANDS
13807 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13808 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13809 #endif /* KEEP_OLD_VPN_COMMANDS */
13810
13811 install_element(BGP_NODE, &address_family_evpn_cmd);
13812
13813 /* "exit-address-family" command. */
13814 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13815 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13816 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13817 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13818 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13819 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13820 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13821 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13822 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13823 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13824 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13825
13826 /* "clear ip bgp commands" */
13827 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13828
13829 /* clear ip bgp prefix */
13830 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13831 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13832 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13833
13834 /* "show [ip] bgp summary" commands. */
13835 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13836 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13837 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13838 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13839 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13840 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13841 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13842
13843 /* "show [ip] bgp neighbors" commands. */
13844 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13845
13846 /* "show [ip] bgp peer-group" commands. */
13847 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13848
13849 /* "show [ip] bgp paths" commands. */
13850 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13851
13852 /* "show [ip] bgp community" commands. */
13853 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13854
13855 /* "show ip bgp large-community" commands. */
13856 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13857 /* "show [ip] bgp attribute-info" commands. */
13858 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13859 /* "show [ip] bgp route-leak" command */
13860 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13861
13862 /* "redistribute" commands. */
13863 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13864 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13865 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13866 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13867 install_element(BGP_NODE,
13868 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13869 install_element(BGP_NODE,
13870 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13871 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13872 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13873 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13874 install_element(BGP_NODE,
13875 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13876 install_element(BGP_NODE,
13877 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13878 install_element(BGP_NODE,
13879 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13880 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13881 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13882 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13883 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13884 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13885 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13886 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13887 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13888 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13889 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13890 install_element(BGP_IPV4_NODE,
13891 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13892 install_element(BGP_IPV4_NODE,
13893 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13894 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13895 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13896 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13897 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13898 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13899 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13900
13901 /* import|export vpn [route-map WORD] */
13902 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13903 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13904
13905 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13906 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13907
13908 /* ttl_security commands */
13909 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13910 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13911
13912 /* "show [ip] bgp memory" commands. */
13913 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13914
13915 /* "show bgp martian next-hop" */
13916 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13917
13918 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
13919
13920 /* "show [ip] bgp views" commands. */
13921 install_element(VIEW_NODE, &show_bgp_views_cmd);
13922
13923 /* "show [ip] bgp vrfs" commands. */
13924 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13925
13926 /* Community-list. */
13927 community_list_vty();
13928
13929 /* vpn-policy commands */
13930 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13931 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13932 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13933 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13934 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13935 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13936 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13937 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13938 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13939 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13940 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13941 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13942
13943 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13944 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13945
13946 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13947 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13948 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13949 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13950 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13951 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13952 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13953 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13954 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13955 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13956 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13957 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13958 }
13959
13960 #include "memory.h"
13961 #include "bgp_regex.h"
13962 #include "bgp_clist.h"
13963 #include "bgp_ecommunity.h"
13964
13965 /* VTY functions. */
13966
13967 /* Direction value to string conversion. */
13968 static const char *community_direct_str(int direct)
13969 {
13970 switch (direct) {
13971 case COMMUNITY_DENY:
13972 return "deny";
13973 case COMMUNITY_PERMIT:
13974 return "permit";
13975 default:
13976 return "unknown";
13977 }
13978 }
13979
13980 /* Display error string. */
13981 static void community_list_perror(struct vty *vty, int ret)
13982 {
13983 switch (ret) {
13984 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13985 vty_out(vty, "%% Can't find community-list\n");
13986 break;
13987 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13988 vty_out(vty, "%% Malformed community-list value\n");
13989 break;
13990 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13991 vty_out(vty,
13992 "%% Community name conflict, previously defined as standard community\n");
13993 break;
13994 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13995 vty_out(vty,
13996 "%% Community name conflict, previously defined as expanded community\n");
13997 break;
13998 }
13999 }
14000
14001 /* "community-list" keyword help string. */
14002 #define COMMUNITY_LIST_STR "Add a community list entry\n"
14003
14004 /*community-list standard */
14005 DEFUN (community_list_standard,
14006 bgp_community_list_standard_cmd,
14007 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14008 BGP_STR
14009 COMMUNITY_LIST_STR
14010 "Community list number (standard)\n"
14011 "Add an standard community-list entry\n"
14012 "Community list name\n"
14013 "Specify community to reject\n"
14014 "Specify community to accept\n"
14015 COMMUNITY_VAL_STR)
14016 {
14017 char *cl_name_or_number = NULL;
14018 int direct = 0;
14019 int style = COMMUNITY_LIST_STANDARD;
14020
14021 int idx = 0;
14022
14023 if (argv_find(argv, argc, "ip", &idx)) {
14024 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14025 vty_out(vty, "if you are using this please migrate to the below command.\n");
14026 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14027 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14028 }
14029
14030 argv_find(argv, argc, "(1-99)", &idx);
14031 argv_find(argv, argc, "WORD", &idx);
14032 cl_name_or_number = argv[idx]->arg;
14033 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14034 : COMMUNITY_DENY;
14035 argv_find(argv, argc, "AA:NN", &idx);
14036 char *str = argv_concat(argv, argc, idx);
14037
14038 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14039 style);
14040
14041 XFREE(MTYPE_TMP, str);
14042
14043 if (ret < 0) {
14044 /* Display error string. */
14045 community_list_perror(vty, ret);
14046 return CMD_WARNING_CONFIG_FAILED;
14047 }
14048
14049 return CMD_SUCCESS;
14050 }
14051
14052 #if CONFDATE > 20191005
14053 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14054 #endif
14055 ALIAS (community_list_standard,
14056 ip_community_list_standard_cmd,
14057 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14058 IP_STR
14059 COMMUNITY_LIST_STR
14060 "Community list number (standard)\n"
14061 "Add an standard community-list entry\n"
14062 "Community list name\n"
14063 "Specify community to reject\n"
14064 "Specify community to accept\n"
14065 COMMUNITY_VAL_STR)
14066
14067 DEFUN (no_community_list_standard_all,
14068 no_bgp_community_list_standard_all_cmd,
14069 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14070 NO_STR
14071 BGP_STR
14072 COMMUNITY_LIST_STR
14073 "Community list number (standard)\n"
14074 "Add an standard community-list entry\n"
14075 "Community list name\n"
14076 "Specify community to reject\n"
14077 "Specify community to accept\n"
14078 COMMUNITY_VAL_STR)
14079 {
14080 char *cl_name_or_number = NULL;
14081 char *str = NULL;
14082 int direct = 0;
14083 int style = COMMUNITY_LIST_STANDARD;
14084
14085 int idx = 0;
14086
14087 if (argv_find(argv, argc, "ip", &idx)) {
14088 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14089 vty_out(vty, "if you are using this please migrate to the below command.\n");
14090 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14091 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14092 }
14093
14094 argv_find(argv, argc, "permit", &idx);
14095 argv_find(argv, argc, "deny", &idx);
14096
14097 if (idx) {
14098 direct = argv_find(argv, argc, "permit", &idx)
14099 ? COMMUNITY_PERMIT
14100 : COMMUNITY_DENY;
14101
14102 idx = 0;
14103 argv_find(argv, argc, "AA:NN", &idx);
14104 str = argv_concat(argv, argc, idx);
14105 }
14106
14107 idx = 0;
14108 argv_find(argv, argc, "(1-99)", &idx);
14109 argv_find(argv, argc, "WORD", &idx);
14110 cl_name_or_number = argv[idx]->arg;
14111
14112 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14113 direct, style);
14114
14115 XFREE(MTYPE_TMP, str);
14116
14117 if (ret < 0) {
14118 community_list_perror(vty, ret);
14119 return CMD_WARNING_CONFIG_FAILED;
14120 }
14121
14122 return CMD_SUCCESS;
14123 }
14124 ALIAS (no_community_list_standard_all,
14125 no_ip_community_list_standard_all_cmd,
14126 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14127 NO_STR
14128 IP_STR
14129 COMMUNITY_LIST_STR
14130 "Community list number (standard)\n"
14131 "Add an standard community-list entry\n"
14132 "Community list name\n"
14133 "Specify community to reject\n"
14134 "Specify community to accept\n"
14135 COMMUNITY_VAL_STR)
14136
14137 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14138 "no bgp community-list <(1-99)|standard WORD>",
14139 NO_STR BGP_STR COMMUNITY_LIST_STR
14140 "Community list number (standard)\n"
14141 "Add an standard community-list entry\n"
14142 "Community list name\n")
14143
14144 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14145 "no ip community-list <(1-99)|standard WORD>",
14146 NO_STR BGP_STR COMMUNITY_LIST_STR
14147 "Community list number (standard)\n"
14148 "Add an standard community-list entry\n"
14149 "Community list name\n")
14150
14151 /*community-list expanded */
14152 DEFUN (community_list_expanded_all,
14153 bgp_community_list_expanded_all_cmd,
14154 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14155 BGP_STR
14156 COMMUNITY_LIST_STR
14157 "Community list number (expanded)\n"
14158 "Add an expanded community-list entry\n"
14159 "Community list name\n"
14160 "Specify community to reject\n"
14161 "Specify community to accept\n"
14162 COMMUNITY_VAL_STR)
14163 {
14164 char *cl_name_or_number = NULL;
14165 int direct = 0;
14166 int style = COMMUNITY_LIST_EXPANDED;
14167
14168 int idx = 0;
14169 if (argv_find(argv, argc, "ip", &idx)) {
14170 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14171 vty_out(vty, "if you are using this please migrate to the below command.\n");
14172 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14173 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14174 }
14175 argv_find(argv, argc, "(100-500)", &idx);
14176 argv_find(argv, argc, "WORD", &idx);
14177 cl_name_or_number = argv[idx]->arg;
14178 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14179 : COMMUNITY_DENY;
14180 argv_find(argv, argc, "AA:NN", &idx);
14181 char *str = argv_concat(argv, argc, idx);
14182
14183 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14184 style);
14185
14186 XFREE(MTYPE_TMP, str);
14187
14188 if (ret < 0) {
14189 /* Display error string. */
14190 community_list_perror(vty, ret);
14191 return CMD_WARNING_CONFIG_FAILED;
14192 }
14193
14194 return CMD_SUCCESS;
14195 }
14196
14197 ALIAS (community_list_expanded_all,
14198 ip_community_list_expanded_all_cmd,
14199 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14200 IP_STR
14201 COMMUNITY_LIST_STR
14202 "Community list number (expanded)\n"
14203 "Add an expanded community-list entry\n"
14204 "Community list name\n"
14205 "Specify community to reject\n"
14206 "Specify community to accept\n"
14207 COMMUNITY_VAL_STR)
14208
14209 DEFUN (no_community_list_expanded_all,
14210 no_bgp_community_list_expanded_all_cmd,
14211 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14212 NO_STR
14213 BGP_STR
14214 COMMUNITY_LIST_STR
14215 "Community list number (expanded)\n"
14216 "Add an expanded community-list entry\n"
14217 "Community list name\n"
14218 "Specify community to reject\n"
14219 "Specify community to accept\n"
14220 COMMUNITY_VAL_STR)
14221 {
14222 char *cl_name_or_number = NULL;
14223 char *str = NULL;
14224 int direct = 0;
14225 int style = COMMUNITY_LIST_EXPANDED;
14226
14227 int idx = 0;
14228 if (argv_find(argv, argc, "ip", &idx)) {
14229 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14230 vty_out(vty, "if you are using this please migrate to the below command.\n");
14231 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14232 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14233 }
14234
14235 idx = 0;
14236 argv_find(argv, argc, "permit", &idx);
14237 argv_find(argv, argc, "deny", &idx);
14238
14239 if (idx) {
14240 direct = argv_find(argv, argc, "permit", &idx)
14241 ? COMMUNITY_PERMIT
14242 : COMMUNITY_DENY;
14243
14244 idx = 0;
14245 argv_find(argv, argc, "AA:NN", &idx);
14246 str = argv_concat(argv, argc, idx);
14247 }
14248
14249 idx = 0;
14250 argv_find(argv, argc, "(100-500)", &idx);
14251 argv_find(argv, argc, "WORD", &idx);
14252 cl_name_or_number = argv[idx]->arg;
14253
14254 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14255 direct, style);
14256
14257 XFREE(MTYPE_TMP, str);
14258
14259 if (ret < 0) {
14260 community_list_perror(vty, ret);
14261 return CMD_WARNING_CONFIG_FAILED;
14262 }
14263
14264 return CMD_SUCCESS;
14265 }
14266
14267 ALIAS (no_community_list_expanded_all,
14268 no_ip_community_list_expanded_all_cmd,
14269 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14270 NO_STR
14271 IP_STR
14272 COMMUNITY_LIST_STR
14273 "Community list number (expanded)\n"
14274 "Add an expanded community-list entry\n"
14275 "Community list name\n"
14276 "Specify community to reject\n"
14277 "Specify community to accept\n"
14278 COMMUNITY_VAL_STR)
14279
14280 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14281 "no bgp community-list <(100-500)|expanded WORD>",
14282 NO_STR IP_STR COMMUNITY_LIST_STR
14283 "Community list number (expanded)\n"
14284 "Add an expanded community-list entry\n"
14285 "Community list name\n")
14286
14287 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14288 "no ip community-list <(100-500)|expanded WORD>",
14289 NO_STR IP_STR COMMUNITY_LIST_STR
14290 "Community list number (expanded)\n"
14291 "Add an expanded community-list entry\n"
14292 "Community list name\n")
14293
14294 /* Return configuration string of community-list entry. */
14295 static const char *community_list_config_str(struct community_entry *entry)
14296 {
14297 const char *str;
14298
14299 if (entry->any)
14300 str = "";
14301 else {
14302 if (entry->style == COMMUNITY_LIST_STANDARD)
14303 str = community_str(entry->u.com, false);
14304 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14305 str = lcommunity_str(entry->u.lcom, false);
14306 else
14307 str = entry->config;
14308 }
14309 return str;
14310 }
14311
14312 static void community_list_show(struct vty *vty, struct community_list *list)
14313 {
14314 struct community_entry *entry;
14315
14316 for (entry = list->head; entry; entry = entry->next) {
14317 if (entry == list->head) {
14318 if (all_digit(list->name))
14319 vty_out(vty, "Community %s list %s\n",
14320 entry->style == COMMUNITY_LIST_STANDARD
14321 ? "standard"
14322 : "(expanded) access",
14323 list->name);
14324 else
14325 vty_out(vty, "Named Community %s list %s\n",
14326 entry->style == COMMUNITY_LIST_STANDARD
14327 ? "standard"
14328 : "expanded",
14329 list->name);
14330 }
14331 if (entry->any)
14332 vty_out(vty, " %s\n",
14333 community_direct_str(entry->direct));
14334 else
14335 vty_out(vty, " %s %s\n",
14336 community_direct_str(entry->direct),
14337 community_list_config_str(entry));
14338 }
14339 }
14340
14341 DEFUN (show_community_list,
14342 show_bgp_community_list_cmd,
14343 "show bgp community-list",
14344 SHOW_STR
14345 BGP_STR
14346 "List community-list\n")
14347 {
14348 struct community_list *list;
14349 struct community_list_master *cm;
14350
14351 int idx = 0;
14352 if (argv_find(argv, argc, "ip", &idx)) {
14353 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14354 vty_out(vty, "if you are using this please migrate to the below command.\n");
14355 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14356 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14357 }
14358 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14359 if (!cm)
14360 return CMD_SUCCESS;
14361
14362 for (list = cm->num.head; list; list = list->next)
14363 community_list_show(vty, list);
14364
14365 for (list = cm->str.head; list; list = list->next)
14366 community_list_show(vty, list);
14367
14368 return CMD_SUCCESS;
14369 }
14370
14371 ALIAS (show_community_list,
14372 show_ip_community_list_cmd,
14373 "show ip community-list",
14374 SHOW_STR
14375 IP_STR
14376 "List community-list\n")
14377
14378 DEFUN (show_community_list_arg,
14379 show_bgp_community_list_arg_cmd,
14380 "show bgp community-list <(1-500)|WORD>",
14381 SHOW_STR
14382 BGP_STR
14383 "List community-list\n"
14384 "Community-list number\n"
14385 "Community-list name\n")
14386 {
14387 int idx_comm_list = 3;
14388 struct community_list *list;
14389
14390 int idx = 0;
14391 if (argv_find(argv, argc, "ip", &idx)) {
14392 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14393 vty_out(vty, "if you are using this please migrate to the below command.\n");
14394 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14395 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14396 }
14397 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14398 COMMUNITY_LIST_MASTER);
14399 if (!list) {
14400 vty_out(vty, "%% Can't find community-list\n");
14401 return CMD_WARNING;
14402 }
14403
14404 community_list_show(vty, list);
14405
14406 return CMD_SUCCESS;
14407 }
14408
14409 ALIAS (show_community_list_arg,
14410 show_ip_community_list_arg_cmd,
14411 "show ip community-list <(1-500)|WORD>",
14412 SHOW_STR
14413 IP_STR
14414 "List community-list\n"
14415 "Community-list number\n"
14416 "Community-list name\n")
14417
14418 /*
14419 * Large Community code.
14420 */
14421 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14422 struct cmd_token **argv, int style,
14423 int reject_all_digit_name)
14424 {
14425 int ret;
14426 int direct;
14427 char *str;
14428 int idx = 0;
14429 char *cl_name;
14430
14431 if (argv_find(argv, argc, "ip", &idx)) {
14432 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14433 vty_out(vty, "if you are using this please migrate to the below command.\n");
14434 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14435 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14436 }
14437 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14438 : COMMUNITY_DENY;
14439
14440 /* All digit name check. */
14441 idx = 0;
14442 argv_find(argv, argc, "WORD", &idx);
14443 argv_find(argv, argc, "(1-99)", &idx);
14444 argv_find(argv, argc, "(100-500)", &idx);
14445 cl_name = argv[idx]->arg;
14446 if (reject_all_digit_name && all_digit(cl_name)) {
14447 vty_out(vty, "%% Community name cannot have all digits\n");
14448 return CMD_WARNING_CONFIG_FAILED;
14449 }
14450
14451 idx = 0;
14452 argv_find(argv, argc, "AA:BB:CC", &idx);
14453 argv_find(argv, argc, "LINE", &idx);
14454 /* Concat community string argument. */
14455 if (idx)
14456 str = argv_concat(argv, argc, idx);
14457 else
14458 str = NULL;
14459
14460 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14461
14462 /* Free temporary community list string allocated by
14463 argv_concat(). */
14464 if (str)
14465 XFREE(MTYPE_TMP, str);
14466
14467 if (ret < 0) {
14468 community_list_perror(vty, ret);
14469 return CMD_WARNING_CONFIG_FAILED;
14470 }
14471 return CMD_SUCCESS;
14472 }
14473
14474 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14475 struct cmd_token **argv, int style)
14476 {
14477 int ret;
14478 int direct = 0;
14479 char *str = NULL;
14480 int idx = 0;
14481
14482 if (argv_find(argv, argc, "ip", &idx)) {
14483 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14484 vty_out(vty, "if you are using this please migrate to the below command.\n");
14485 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14486 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14487 }
14488 argv_find(argv, argc, "permit", &idx);
14489 argv_find(argv, argc, "deny", &idx);
14490
14491 if (idx) {
14492 /* Check the list direct. */
14493 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14494 direct = COMMUNITY_PERMIT;
14495 else
14496 direct = COMMUNITY_DENY;
14497
14498 idx = 0;
14499 argv_find(argv, argc, "LINE", &idx);
14500 argv_find(argv, argc, "AA:AA:NN", &idx);
14501 /* Concat community string argument. */
14502 str = argv_concat(argv, argc, idx);
14503 }
14504
14505 idx = 0;
14506 argv_find(argv, argc, "(1-99)", &idx);
14507 argv_find(argv, argc, "(100-500)", &idx);
14508 argv_find(argv, argc, "WORD", &idx);
14509
14510 /* Unset community list. */
14511 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14512 style);
14513
14514 /* Free temporary community list string allocated by
14515 argv_concat(). */
14516 if (str)
14517 XFREE(MTYPE_TMP, str);
14518
14519 if (ret < 0) {
14520 community_list_perror(vty, ret);
14521 return CMD_WARNING_CONFIG_FAILED;
14522 }
14523
14524 return CMD_SUCCESS;
14525 }
14526
14527 /* "large-community-list" keyword help string. */
14528 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14529 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14530
14531 #if CONFDATE > 20191005
14532 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14533 #endif
14534 DEFUN (lcommunity_list_standard,
14535 bgp_lcommunity_list_standard_cmd,
14536 "bgp large-community-list (1-99) <deny|permit>",
14537 BGP_STR
14538 LCOMMUNITY_LIST_STR
14539 "Large Community list number (standard)\n"
14540 "Specify large community to reject\n"
14541 "Specify large community to accept\n")
14542 {
14543 return lcommunity_list_set_vty(vty, argc, argv,
14544 LARGE_COMMUNITY_LIST_STANDARD, 0);
14545 }
14546
14547 ALIAS (lcommunity_list_standard,
14548 ip_lcommunity_list_standard_cmd,
14549 "ip large-community-list (1-99) <deny|permit>",
14550 IP_STR
14551 LCOMMUNITY_LIST_STR
14552 "Large Community list number (standard)\n"
14553 "Specify large community to reject\n"
14554 "Specify large community to accept\n")
14555
14556 DEFUN (lcommunity_list_standard1,
14557 bgp_lcommunity_list_standard1_cmd,
14558 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14559 BGP_STR
14560 LCOMMUNITY_LIST_STR
14561 "Large Community list number (standard)\n"
14562 "Specify large community to reject\n"
14563 "Specify large community to accept\n"
14564 LCOMMUNITY_VAL_STR)
14565 {
14566 return lcommunity_list_set_vty(vty, argc, argv,
14567 LARGE_COMMUNITY_LIST_STANDARD, 0);
14568 }
14569
14570 ALIAS (lcommunity_list_standard1,
14571 ip_lcommunity_list_standard1_cmd,
14572 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14573 IP_STR
14574 LCOMMUNITY_LIST_STR
14575 "Large Community list number (standard)\n"
14576 "Specify large community to reject\n"
14577 "Specify large community to accept\n"
14578 LCOMMUNITY_VAL_STR)
14579
14580 DEFUN (lcommunity_list_expanded,
14581 bgp_lcommunity_list_expanded_cmd,
14582 "bgp large-community-list (100-500) <deny|permit> LINE...",
14583 BGP_STR
14584 LCOMMUNITY_LIST_STR
14585 "Large Community list number (expanded)\n"
14586 "Specify large community to reject\n"
14587 "Specify large community to accept\n"
14588 "An ordered list as a regular-expression\n")
14589 {
14590 return lcommunity_list_set_vty(vty, argc, argv,
14591 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14592 }
14593
14594 ALIAS (lcommunity_list_expanded,
14595 ip_lcommunity_list_expanded_cmd,
14596 "ip large-community-list (100-500) <deny|permit> LINE...",
14597 IP_STR
14598 LCOMMUNITY_LIST_STR
14599 "Large Community list number (expanded)\n"
14600 "Specify large community to reject\n"
14601 "Specify large community to accept\n"
14602 "An ordered list as a regular-expression\n")
14603
14604 DEFUN (lcommunity_list_name_standard,
14605 bgp_lcommunity_list_name_standard_cmd,
14606 "bgp large-community-list standard WORD <deny|permit>",
14607 BGP_STR
14608 LCOMMUNITY_LIST_STR
14609 "Specify standard large-community-list\n"
14610 "Large Community list name\n"
14611 "Specify large community to reject\n"
14612 "Specify large community to accept\n")
14613 {
14614 return lcommunity_list_set_vty(vty, argc, argv,
14615 LARGE_COMMUNITY_LIST_STANDARD, 1);
14616 }
14617
14618 ALIAS (lcommunity_list_name_standard,
14619 ip_lcommunity_list_name_standard_cmd,
14620 "ip large-community-list standard WORD <deny|permit>",
14621 IP_STR
14622 LCOMMUNITY_LIST_STR
14623 "Specify standard large-community-list\n"
14624 "Large Community list name\n"
14625 "Specify large community to reject\n"
14626 "Specify large community to accept\n")
14627
14628 DEFUN (lcommunity_list_name_standard1,
14629 bgp_lcommunity_list_name_standard1_cmd,
14630 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14631 BGP_STR
14632 LCOMMUNITY_LIST_STR
14633 "Specify standard large-community-list\n"
14634 "Large Community list name\n"
14635 "Specify large community to reject\n"
14636 "Specify large community to accept\n"
14637 LCOMMUNITY_VAL_STR)
14638 {
14639 return lcommunity_list_set_vty(vty, argc, argv,
14640 LARGE_COMMUNITY_LIST_STANDARD, 1);
14641 }
14642
14643 ALIAS (lcommunity_list_name_standard1,
14644 ip_lcommunity_list_name_standard1_cmd,
14645 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14646 IP_STR
14647 LCOMMUNITY_LIST_STR
14648 "Specify standard large-community-list\n"
14649 "Large Community list name\n"
14650 "Specify large community to reject\n"
14651 "Specify large community to accept\n"
14652 LCOMMUNITY_VAL_STR)
14653
14654 DEFUN (lcommunity_list_name_expanded,
14655 bgp_lcommunity_list_name_expanded_cmd,
14656 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14657 BGP_STR
14658 LCOMMUNITY_LIST_STR
14659 "Specify expanded large-community-list\n"
14660 "Large Community list name\n"
14661 "Specify large community to reject\n"
14662 "Specify large community to accept\n"
14663 "An ordered list as a regular-expression\n")
14664 {
14665 return lcommunity_list_set_vty(vty, argc, argv,
14666 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14667 }
14668
14669 ALIAS (lcommunity_list_name_expanded,
14670 ip_lcommunity_list_name_expanded_cmd,
14671 "ip large-community-list expanded WORD <deny|permit> LINE...",
14672 IP_STR
14673 LCOMMUNITY_LIST_STR
14674 "Specify expanded large-community-list\n"
14675 "Large Community list name\n"
14676 "Specify large community to reject\n"
14677 "Specify large community to accept\n"
14678 "An ordered list as a regular-expression\n")
14679
14680 DEFUN (no_lcommunity_list_standard_all,
14681 no_bgp_lcommunity_list_standard_all_cmd,
14682 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14683 NO_STR
14684 BGP_STR
14685 LCOMMUNITY_LIST_STR
14686 "Large Community list number (standard)\n"
14687 "Large Community list number (expanded)\n"
14688 "Large Community list name\n")
14689 {
14690 return lcommunity_list_unset_vty(vty, argc, argv,
14691 LARGE_COMMUNITY_LIST_STANDARD);
14692 }
14693
14694 ALIAS (no_lcommunity_list_standard_all,
14695 no_ip_lcommunity_list_standard_all_cmd,
14696 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14697 NO_STR
14698 IP_STR
14699 LCOMMUNITY_LIST_STR
14700 "Large Community list number (standard)\n"
14701 "Large Community list number (expanded)\n"
14702 "Large Community list name\n")
14703
14704 DEFUN (no_lcommunity_list_name_expanded_all,
14705 no_bgp_lcommunity_list_name_expanded_all_cmd,
14706 "no bgp large-community-list expanded WORD",
14707 NO_STR
14708 BGP_STR
14709 LCOMMUNITY_LIST_STR
14710 "Specify expanded large-community-list\n"
14711 "Large Community list name\n")
14712 {
14713 return lcommunity_list_unset_vty(vty, argc, argv,
14714 LARGE_COMMUNITY_LIST_EXPANDED);
14715 }
14716
14717 ALIAS (no_lcommunity_list_name_expanded_all,
14718 no_ip_lcommunity_list_name_expanded_all_cmd,
14719 "no ip large-community-list expanded WORD",
14720 NO_STR
14721 IP_STR
14722 LCOMMUNITY_LIST_STR
14723 "Specify expanded large-community-list\n"
14724 "Large Community list name\n")
14725
14726 DEFUN (no_lcommunity_list_standard,
14727 no_bgp_lcommunity_list_standard_cmd,
14728 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14729 NO_STR
14730 BGP_STR
14731 LCOMMUNITY_LIST_STR
14732 "Large Community list number (standard)\n"
14733 "Specify large community to reject\n"
14734 "Specify large community to accept\n"
14735 LCOMMUNITY_VAL_STR)
14736 {
14737 return lcommunity_list_unset_vty(vty, argc, argv,
14738 LARGE_COMMUNITY_LIST_STANDARD);
14739 }
14740
14741 ALIAS (no_lcommunity_list_standard,
14742 no_ip_lcommunity_list_standard_cmd,
14743 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14744 NO_STR
14745 IP_STR
14746 LCOMMUNITY_LIST_STR
14747 "Large Community list number (standard)\n"
14748 "Specify large community to reject\n"
14749 "Specify large community to accept\n"
14750 LCOMMUNITY_VAL_STR)
14751
14752 DEFUN (no_lcommunity_list_expanded,
14753 no_bgp_lcommunity_list_expanded_cmd,
14754 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14755 NO_STR
14756 BGP_STR
14757 LCOMMUNITY_LIST_STR
14758 "Large Community list number (expanded)\n"
14759 "Specify large community to reject\n"
14760 "Specify large community to accept\n"
14761 "An ordered list as a regular-expression\n")
14762 {
14763 return lcommunity_list_unset_vty(vty, argc, argv,
14764 LARGE_COMMUNITY_LIST_EXPANDED);
14765 }
14766
14767 ALIAS (no_lcommunity_list_expanded,
14768 no_ip_lcommunity_list_expanded_cmd,
14769 "no ip large-community-list (100-500) <deny|permit> LINE...",
14770 NO_STR
14771 IP_STR
14772 LCOMMUNITY_LIST_STR
14773 "Large Community list number (expanded)\n"
14774 "Specify large community to reject\n"
14775 "Specify large community to accept\n"
14776 "An ordered list as a regular-expression\n")
14777
14778 DEFUN (no_lcommunity_list_name_standard,
14779 no_bgp_lcommunity_list_name_standard_cmd,
14780 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14781 NO_STR
14782 BGP_STR
14783 LCOMMUNITY_LIST_STR
14784 "Specify standard large-community-list\n"
14785 "Large Community list name\n"
14786 "Specify large community to reject\n"
14787 "Specify large community to accept\n"
14788 LCOMMUNITY_VAL_STR)
14789 {
14790 return lcommunity_list_unset_vty(vty, argc, argv,
14791 LARGE_COMMUNITY_LIST_STANDARD);
14792 }
14793
14794 ALIAS (no_lcommunity_list_name_standard,
14795 no_ip_lcommunity_list_name_standard_cmd,
14796 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14797 NO_STR
14798 IP_STR
14799 LCOMMUNITY_LIST_STR
14800 "Specify standard large-community-list\n"
14801 "Large Community list name\n"
14802 "Specify large community to reject\n"
14803 "Specify large community to accept\n"
14804 LCOMMUNITY_VAL_STR)
14805
14806 DEFUN (no_lcommunity_list_name_expanded,
14807 no_bgp_lcommunity_list_name_expanded_cmd,
14808 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14809 NO_STR
14810 BGP_STR
14811 LCOMMUNITY_LIST_STR
14812 "Specify expanded large-community-list\n"
14813 "Large community list name\n"
14814 "Specify large community to reject\n"
14815 "Specify large community to accept\n"
14816 "An ordered list as a regular-expression\n")
14817 {
14818 return lcommunity_list_unset_vty(vty, argc, argv,
14819 LARGE_COMMUNITY_LIST_EXPANDED);
14820 }
14821
14822 ALIAS (no_lcommunity_list_name_expanded,
14823 no_ip_lcommunity_list_name_expanded_cmd,
14824 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14825 NO_STR
14826 IP_STR
14827 LCOMMUNITY_LIST_STR
14828 "Specify expanded large-community-list\n"
14829 "Large community list name\n"
14830 "Specify large community to reject\n"
14831 "Specify large community to accept\n"
14832 "An ordered list as a regular-expression\n")
14833
14834 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14835 {
14836 struct community_entry *entry;
14837
14838 for (entry = list->head; entry; entry = entry->next) {
14839 if (entry == list->head) {
14840 if (all_digit(list->name))
14841 vty_out(vty, "Large community %s list %s\n",
14842 entry->style == EXTCOMMUNITY_LIST_STANDARD
14843 ? "standard"
14844 : "(expanded) access",
14845 list->name);
14846 else
14847 vty_out(vty,
14848 "Named large community %s list %s\n",
14849 entry->style == EXTCOMMUNITY_LIST_STANDARD
14850 ? "standard"
14851 : "expanded",
14852 list->name);
14853 }
14854 if (entry->any)
14855 vty_out(vty, " %s\n",
14856 community_direct_str(entry->direct));
14857 else
14858 vty_out(vty, " %s %s\n",
14859 community_direct_str(entry->direct),
14860 community_list_config_str(entry));
14861 }
14862 }
14863
14864 DEFUN (show_lcommunity_list,
14865 show_bgp_lcommunity_list_cmd,
14866 "show bgp large-community-list",
14867 SHOW_STR
14868 BGP_STR
14869 "List large-community list\n")
14870 {
14871 struct community_list *list;
14872 struct community_list_master *cm;
14873 int idx = 0;
14874
14875 if (argv_find(argv, argc, "ip", &idx)) {
14876 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14877 vty_out(vty, "if you are using this please migrate to the below command.\n");
14878 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14879 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14880 }
14881
14882 cm = community_list_master_lookup(bgp_clist,
14883 LARGE_COMMUNITY_LIST_MASTER);
14884 if (!cm)
14885 return CMD_SUCCESS;
14886
14887 for (list = cm->num.head; list; list = list->next)
14888 lcommunity_list_show(vty, list);
14889
14890 for (list = cm->str.head; list; list = list->next)
14891 lcommunity_list_show(vty, list);
14892
14893 return CMD_SUCCESS;
14894 }
14895
14896 ALIAS (show_lcommunity_list,
14897 show_ip_lcommunity_list_cmd,
14898 "show ip large-community-list",
14899 SHOW_STR
14900 IP_STR
14901 "List large-community list\n")
14902
14903 DEFUN (show_lcommunity_list_arg,
14904 show_bgp_lcommunity_list_arg_cmd,
14905 "show bgp large-community-list <(1-500)|WORD>",
14906 SHOW_STR
14907 BGP_STR
14908 "List large-community list\n"
14909 "large-community-list number\n"
14910 "large-community-list name\n")
14911 {
14912 struct community_list *list;
14913 int idx = 0;
14914
14915 if (argv_find(argv, argc, "ip", &idx)) {
14916 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14917 vty_out(vty, "if you are using this please migrate to the below command.\n");
14918 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14919 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14920 }
14921
14922 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
14923 LARGE_COMMUNITY_LIST_MASTER);
14924 if (!list) {
14925 vty_out(vty, "%% Can't find extcommunity-list\n");
14926 return CMD_WARNING;
14927 }
14928
14929 lcommunity_list_show(vty, list);
14930
14931 return CMD_SUCCESS;
14932 }
14933
14934 ALIAS (show_lcommunity_list_arg,
14935 show_ip_lcommunity_list_arg_cmd,
14936 "show ip large-community-list <(1-500)|WORD>",
14937 SHOW_STR
14938 IP_STR
14939 "List large-community list\n"
14940 "large-community-list number\n"
14941 "large-community-list name\n")
14942
14943 /* "extcommunity-list" keyword help string. */
14944 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14945 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14946
14947 DEFUN (extcommunity_list_standard,
14948 bgp_extcommunity_list_standard_cmd,
14949 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14950 BGP_STR
14951 EXTCOMMUNITY_LIST_STR
14952 "Extended Community list number (standard)\n"
14953 "Specify standard extcommunity-list\n"
14954 "Community list name\n"
14955 "Specify community to reject\n"
14956 "Specify community to accept\n"
14957 EXTCOMMUNITY_VAL_STR)
14958 {
14959 int style = EXTCOMMUNITY_LIST_STANDARD;
14960 int direct = 0;
14961 char *cl_number_or_name = NULL;
14962
14963 int idx = 0;
14964 if (argv_find(argv, argc, "ip", &idx)) {
14965 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14966 vty_out(vty, "if you are using this please migrate to the below command.\n");
14967 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14968 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14969 }
14970 argv_find(argv, argc, "(1-99)", &idx);
14971 argv_find(argv, argc, "WORD", &idx);
14972 cl_number_or_name = argv[idx]->arg;
14973 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14974 : COMMUNITY_DENY;
14975 argv_find(argv, argc, "AA:NN", &idx);
14976 char *str = argv_concat(argv, argc, idx);
14977
14978 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14979 direct, style);
14980
14981 XFREE(MTYPE_TMP, str);
14982
14983 if (ret < 0) {
14984 community_list_perror(vty, ret);
14985 return CMD_WARNING_CONFIG_FAILED;
14986 }
14987
14988 return CMD_SUCCESS;
14989 }
14990
14991 #if CONFDATE > 20191005
14992 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14993 #endif
14994 ALIAS (extcommunity_list_standard,
14995 ip_extcommunity_list_standard_cmd,
14996 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14997 IP_STR
14998 EXTCOMMUNITY_LIST_STR
14999 "Extended Community list number (standard)\n"
15000 "Specify standard extcommunity-list\n"
15001 "Community list name\n"
15002 "Specify community to reject\n"
15003 "Specify community to accept\n"
15004 EXTCOMMUNITY_VAL_STR)
15005
15006 DEFUN (extcommunity_list_name_expanded,
15007 bgp_extcommunity_list_name_expanded_cmd,
15008 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15009 BGP_STR
15010 EXTCOMMUNITY_LIST_STR
15011 "Extended Community list number (expanded)\n"
15012 "Specify expanded extcommunity-list\n"
15013 "Extended Community list name\n"
15014 "Specify community to reject\n"
15015 "Specify community to accept\n"
15016 "An ordered list as a regular-expression\n")
15017 {
15018 int style = EXTCOMMUNITY_LIST_EXPANDED;
15019 int direct = 0;
15020 char *cl_number_or_name = NULL;
15021
15022 int idx = 0;
15023 if (argv_find(argv, argc, "ip", &idx)) {
15024 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15025 vty_out(vty, "if you are using this please migrate to the below command.\n");
15026 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15027 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15028 }
15029
15030 argv_find(argv, argc, "(100-500)", &idx);
15031 argv_find(argv, argc, "WORD", &idx);
15032 cl_number_or_name = argv[idx]->arg;
15033 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15034 : COMMUNITY_DENY;
15035 argv_find(argv, argc, "LINE", &idx);
15036 char *str = argv_concat(argv, argc, idx);
15037
15038 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15039 direct, style);
15040
15041 XFREE(MTYPE_TMP, str);
15042
15043 if (ret < 0) {
15044 community_list_perror(vty, ret);
15045 return CMD_WARNING_CONFIG_FAILED;
15046 }
15047
15048 return CMD_SUCCESS;
15049 }
15050
15051 ALIAS (extcommunity_list_name_expanded,
15052 ip_extcommunity_list_name_expanded_cmd,
15053 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15054 IP_STR
15055 EXTCOMMUNITY_LIST_STR
15056 "Extended Community list number (expanded)\n"
15057 "Specify expanded extcommunity-list\n"
15058 "Extended Community list name\n"
15059 "Specify community to reject\n"
15060 "Specify community to accept\n"
15061 "An ordered list as a regular-expression\n")
15062
15063 DEFUN (no_extcommunity_list_standard_all,
15064 no_bgp_extcommunity_list_standard_all_cmd,
15065 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15066 NO_STR
15067 BGP_STR
15068 EXTCOMMUNITY_LIST_STR
15069 "Extended Community list number (standard)\n"
15070 "Specify standard extcommunity-list\n"
15071 "Community list name\n"
15072 "Specify community to reject\n"
15073 "Specify community to accept\n"
15074 EXTCOMMUNITY_VAL_STR)
15075 {
15076 int style = EXTCOMMUNITY_LIST_STANDARD;
15077 int direct = 0;
15078 char *cl_number_or_name = NULL;
15079 char *str = NULL;
15080
15081 int idx = 0;
15082 if (argv_find(argv, argc, "ip", &idx)) {
15083 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15084 vty_out(vty, "if you are using this please migrate to the below command.\n");
15085 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15086 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15087 }
15088
15089 idx = 0;
15090 argv_find(argv, argc, "permit", &idx);
15091 argv_find(argv, argc, "deny", &idx);
15092
15093 if (idx) {
15094 direct = argv_find(argv, argc, "permit", &idx)
15095 ? COMMUNITY_PERMIT
15096 : COMMUNITY_DENY;
15097
15098 idx = 0;
15099 argv_find(argv, argc, "AA:NN", &idx);
15100 str = argv_concat(argv, argc, idx);
15101 }
15102
15103 idx = 0;
15104 argv_find(argv, argc, "(1-99)", &idx);
15105 argv_find(argv, argc, "WORD", &idx);
15106 cl_number_or_name = argv[idx]->arg;
15107
15108 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15109 direct, style);
15110
15111 XFREE(MTYPE_TMP, str);
15112
15113 if (ret < 0) {
15114 community_list_perror(vty, ret);
15115 return CMD_WARNING_CONFIG_FAILED;
15116 }
15117
15118 return CMD_SUCCESS;
15119 }
15120
15121 ALIAS (no_extcommunity_list_standard_all,
15122 no_ip_extcommunity_list_standard_all_cmd,
15123 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15124 NO_STR
15125 IP_STR
15126 EXTCOMMUNITY_LIST_STR
15127 "Extended Community list number (standard)\n"
15128 "Specify standard extcommunity-list\n"
15129 "Community list name\n"
15130 "Specify community to reject\n"
15131 "Specify community to accept\n"
15132 EXTCOMMUNITY_VAL_STR)
15133
15134 ALIAS(no_extcommunity_list_standard_all,
15135 no_bgp_extcommunity_list_standard_all_list_cmd,
15136 "no bgp extcommunity-list <(1-99)|standard WORD>",
15137 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15138 "Extended Community list number (standard)\n"
15139 "Specify standard extcommunity-list\n"
15140 "Community list name\n")
15141
15142 ALIAS(no_extcommunity_list_standard_all,
15143 no_ip_extcommunity_list_standard_all_list_cmd,
15144 "no ip extcommunity-list <(1-99)|standard WORD>",
15145 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15146 "Extended Community list number (standard)\n"
15147 "Specify standard extcommunity-list\n"
15148 "Community list name\n")
15149
15150 DEFUN (no_extcommunity_list_expanded_all,
15151 no_bgp_extcommunity_list_expanded_all_cmd,
15152 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15153 NO_STR
15154 BGP_STR
15155 EXTCOMMUNITY_LIST_STR
15156 "Extended Community list number (expanded)\n"
15157 "Specify expanded extcommunity-list\n"
15158 "Extended Community list name\n"
15159 "Specify community to reject\n"
15160 "Specify community to accept\n"
15161 "An ordered list as a regular-expression\n")
15162 {
15163 int style = EXTCOMMUNITY_LIST_EXPANDED;
15164 int direct = 0;
15165 char *cl_number_or_name = NULL;
15166 char *str = NULL;
15167
15168 int idx = 0;
15169 if (argv_find(argv, argc, "ip", &idx)) {
15170 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15171 vty_out(vty, "if you are using this please migrate to the below command.\n");
15172 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15173 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15174 }
15175
15176 idx = 0;
15177 argv_find(argv, argc, "permit", &idx);
15178 argv_find(argv, argc, "deny", &idx);
15179
15180 if (idx) {
15181 direct = argv_find(argv, argc, "permit", &idx)
15182 ? COMMUNITY_PERMIT
15183 : COMMUNITY_DENY;
15184
15185 idx = 0;
15186 argv_find(argv, argc, "LINE", &idx);
15187 str = argv_concat(argv, argc, idx);
15188 }
15189
15190 idx = 0;
15191 argv_find(argv, argc, "(100-500)", &idx);
15192 argv_find(argv, argc, "WORD", &idx);
15193 cl_number_or_name = argv[idx]->arg;
15194
15195 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15196 direct, style);
15197
15198 XFREE(MTYPE_TMP, str);
15199
15200 if (ret < 0) {
15201 community_list_perror(vty, ret);
15202 return CMD_WARNING_CONFIG_FAILED;
15203 }
15204
15205 return CMD_SUCCESS;
15206 }
15207
15208 ALIAS (no_extcommunity_list_expanded_all,
15209 no_ip_extcommunity_list_expanded_all_cmd,
15210 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15211 NO_STR
15212 IP_STR
15213 EXTCOMMUNITY_LIST_STR
15214 "Extended Community list number (expanded)\n"
15215 "Specify expanded extcommunity-list\n"
15216 "Extended Community list name\n"
15217 "Specify community to reject\n"
15218 "Specify community to accept\n"
15219 "An ordered list as a regular-expression\n")
15220
15221 ALIAS(no_extcommunity_list_expanded_all,
15222 no_ip_extcommunity_list_expanded_all_list_cmd,
15223 "no ip extcommunity-list <(100-500)|expanded WORD>",
15224 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15225 "Extended Community list number (expanded)\n"
15226 "Specify expanded extcommunity-list\n"
15227 "Extended Community list name\n")
15228
15229 ALIAS(no_extcommunity_list_expanded_all,
15230 no_bgp_extcommunity_list_expanded_all_list_cmd,
15231 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15232 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15233 "Extended Community list number (expanded)\n"
15234 "Specify expanded extcommunity-list\n"
15235 "Extended Community list name\n")
15236
15237 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15238 {
15239 struct community_entry *entry;
15240
15241 for (entry = list->head; entry; entry = entry->next) {
15242 if (entry == list->head) {
15243 if (all_digit(list->name))
15244 vty_out(vty, "Extended community %s list %s\n",
15245 entry->style == EXTCOMMUNITY_LIST_STANDARD
15246 ? "standard"
15247 : "(expanded) access",
15248 list->name);
15249 else
15250 vty_out(vty,
15251 "Named extended community %s list %s\n",
15252 entry->style == EXTCOMMUNITY_LIST_STANDARD
15253 ? "standard"
15254 : "expanded",
15255 list->name);
15256 }
15257 if (entry->any)
15258 vty_out(vty, " %s\n",
15259 community_direct_str(entry->direct));
15260 else
15261 vty_out(vty, " %s %s\n",
15262 community_direct_str(entry->direct),
15263 community_list_config_str(entry));
15264 }
15265 }
15266
15267 DEFUN (show_extcommunity_list,
15268 show_bgp_extcommunity_list_cmd,
15269 "show bgp extcommunity-list",
15270 SHOW_STR
15271 BGP_STR
15272 "List extended-community list\n")
15273 {
15274 struct community_list *list;
15275 struct community_list_master *cm;
15276 int idx = 0;
15277
15278 if (argv_find(argv, argc, "ip", &idx)) {
15279 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15280 vty_out(vty, "if you are using this please migrate to the below command.\n");
15281 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15282 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15283 }
15284 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15285 if (!cm)
15286 return CMD_SUCCESS;
15287
15288 for (list = cm->num.head; list; list = list->next)
15289 extcommunity_list_show(vty, list);
15290
15291 for (list = cm->str.head; list; list = list->next)
15292 extcommunity_list_show(vty, list);
15293
15294 return CMD_SUCCESS;
15295 }
15296
15297 ALIAS (show_extcommunity_list,
15298 show_ip_extcommunity_list_cmd,
15299 "show ip extcommunity-list",
15300 SHOW_STR
15301 IP_STR
15302 "List extended-community list\n")
15303
15304 DEFUN (show_extcommunity_list_arg,
15305 show_bgp_extcommunity_list_arg_cmd,
15306 "show bgp extcommunity-list <(1-500)|WORD>",
15307 SHOW_STR
15308 BGP_STR
15309 "List extended-community list\n"
15310 "Extcommunity-list number\n"
15311 "Extcommunity-list name\n")
15312 {
15313 int idx_comm_list = 3;
15314 struct community_list *list;
15315 int idx = 0;
15316
15317 if (argv_find(argv, argc, "ip", &idx)) {
15318 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15319 vty_out(vty, "if you are using this please migrate to the below command.\n");
15320 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15321 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15322 }
15323 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15324 EXTCOMMUNITY_LIST_MASTER);
15325 if (!list) {
15326 vty_out(vty, "%% Can't find extcommunity-list\n");
15327 return CMD_WARNING;
15328 }
15329
15330 extcommunity_list_show(vty, list);
15331
15332 return CMD_SUCCESS;
15333 }
15334
15335 ALIAS (show_extcommunity_list_arg,
15336 show_ip_extcommunity_list_arg_cmd,
15337 "show ip extcommunity-list <(1-500)|WORD>",
15338 SHOW_STR
15339 IP_STR
15340 "List extended-community list\n"
15341 "Extcommunity-list number\n"
15342 "Extcommunity-list name\n")
15343
15344 /* Display community-list and extcommunity-list configuration. */
15345 static int community_list_config_write(struct vty *vty)
15346 {
15347 struct community_list *list;
15348 struct community_entry *entry;
15349 struct community_list_master *cm;
15350 int write = 0;
15351
15352 /* Community-list. */
15353 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15354
15355 for (list = cm->num.head; list; list = list->next)
15356 for (entry = list->head; entry; entry = entry->next) {
15357 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15358 community_direct_str(entry->direct),
15359 community_list_config_str(entry));
15360 write++;
15361 }
15362 for (list = cm->str.head; list; list = list->next)
15363 for (entry = list->head; entry; entry = entry->next) {
15364 vty_out(vty, "bgp community-list %s %s %s %s\n",
15365 entry->style == COMMUNITY_LIST_STANDARD
15366 ? "standard"
15367 : "expanded",
15368 list->name, community_direct_str(entry->direct),
15369 community_list_config_str(entry));
15370 write++;
15371 }
15372
15373 /* Extcommunity-list. */
15374 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15375
15376 for (list = cm->num.head; list; list = list->next)
15377 for (entry = list->head; entry; entry = entry->next) {
15378 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15379 list->name, community_direct_str(entry->direct),
15380 community_list_config_str(entry));
15381 write++;
15382 }
15383 for (list = cm->str.head; list; list = list->next)
15384 for (entry = list->head; entry; entry = entry->next) {
15385 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15386 entry->style == EXTCOMMUNITY_LIST_STANDARD
15387 ? "standard"
15388 : "expanded",
15389 list->name, community_direct_str(entry->direct),
15390 community_list_config_str(entry));
15391 write++;
15392 }
15393
15394
15395 /* lcommunity-list. */
15396 cm = community_list_master_lookup(bgp_clist,
15397 LARGE_COMMUNITY_LIST_MASTER);
15398
15399 for (list = cm->num.head; list; list = list->next)
15400 for (entry = list->head; entry; entry = entry->next) {
15401 vty_out(vty, "bgp large-community-list %s %s %s\n",
15402 list->name, community_direct_str(entry->direct),
15403 community_list_config_str(entry));
15404 write++;
15405 }
15406 for (list = cm->str.head; list; list = list->next)
15407 for (entry = list->head; entry; entry = entry->next) {
15408 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15409 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15410 ? "standard"
15411 : "expanded",
15412 list->name, community_direct_str(entry->direct),
15413 community_list_config_str(entry));
15414 write++;
15415 }
15416
15417 return write;
15418 }
15419
15420 static struct cmd_node community_list_node = {
15421 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15422 };
15423
15424 static void community_list_vty(void)
15425 {
15426 install_node(&community_list_node, community_list_config_write);
15427
15428 /* Community-list. */
15429 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15430 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15431 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15432 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15433 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15434 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15435 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15436 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15437 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15438 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15439 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15440 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15441 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15442 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15443 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15444 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15445
15446 /* Extcommunity-list. */
15447 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15448 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15449 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15450 install_element(CONFIG_NODE,
15451 &no_bgp_extcommunity_list_standard_all_list_cmd);
15452 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15453 install_element(CONFIG_NODE,
15454 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15455 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15456 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15457 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15458 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15459 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15460 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15461 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15462 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15463 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15464 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15465
15466 /* Large Community List */
15467 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15468 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15469 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15470 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15471 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15472 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15473 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15474 install_element(CONFIG_NODE,
15475 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15476 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15477 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15478 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15479 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15480 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15481 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15482 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15483 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15484 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15485 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15486 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15487 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15488 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15489 install_element(CONFIG_NODE,
15490 &no_ip_lcommunity_list_name_expanded_all_cmd);
15491 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15492 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15493 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15494 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15495 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15496 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15497 }