]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #3866 from donaldsharp/ospf_allow_vrf_starup
[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, call proper function. */
2845 ret = str2sockunion(peer_str, &su);
2846 if (ret < 0) {
2847 /* Check for peer by interface */
2848 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2849 safi);
2850 if (ret < 0) {
2851 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2852 if (ret < 0) {
2853 vty_out(vty,
2854 "%% Create the peer-group or interface first or specify \"interface\" keyword\n");
2855 vty_out(vty, "%% if using an unnumbered interface neighbor\n");
2856 return CMD_WARNING_CONFIG_FAILED;
2857 }
2858 return CMD_SUCCESS;
2859 }
2860 } else {
2861 if (peer_address_self_check(bgp, &su)) {
2862 vty_out(vty,
2863 "%% Can not configure the local system as neighbor\n");
2864 return CMD_WARNING_CONFIG_FAILED;
2865 }
2866 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2867 }
2868
2869 /* This peer belongs to peer group. */
2870 switch (ret) {
2871 case BGP_ERR_PEER_GROUP_MEMBER:
2872 vty_out(vty,
2873 "%% Peer-group member cannot override remote-as of peer-group\n");
2874 return CMD_WARNING_CONFIG_FAILED;
2875 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2876 vty_out(vty,
2877 "%% Peer-group members must be all internal or all external\n");
2878 return CMD_WARNING_CONFIG_FAILED;
2879 }
2880 return bgp_vty_return(vty, ret);
2881 }
2882
2883 DEFUN (bgp_default_shutdown,
2884 bgp_default_shutdown_cmd,
2885 "[no] bgp default shutdown",
2886 NO_STR
2887 BGP_STR
2888 "Configure BGP defaults\n"
2889 "Apply administrative shutdown to newly configured peers\n")
2890 {
2891 VTY_DECLVAR_CONTEXT(bgp, bgp);
2892 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2893 return CMD_SUCCESS;
2894 }
2895
2896 DEFUN (neighbor_remote_as,
2897 neighbor_remote_as_cmd,
2898 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2899 NEIGHBOR_STR
2900 NEIGHBOR_ADDR_STR2
2901 "Specify a BGP neighbor\n"
2902 AS_STR
2903 "Internal BGP peer\n"
2904 "External BGP peer\n")
2905 {
2906 int idx_peer = 1;
2907 int idx_remote_as = 3;
2908 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2909 argv[idx_remote_as]->arg, AFI_IP,
2910 SAFI_UNICAST);
2911 }
2912
2913 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2914 afi_t afi, safi_t safi, int v6only,
2915 const char *peer_group_name,
2916 const char *as_str)
2917 {
2918 VTY_DECLVAR_CONTEXT(bgp, bgp);
2919 as_t as = 0;
2920 int as_type = AS_UNSPECIFIED;
2921 struct peer *peer;
2922 struct peer_group *group;
2923 int ret = 0;
2924 union sockunion su;
2925
2926 group = peer_group_lookup(bgp, conf_if);
2927
2928 if (group) {
2929 vty_out(vty, "%% Name conflict with peer-group \n");
2930 return CMD_WARNING_CONFIG_FAILED;
2931 }
2932
2933 if (as_str) {
2934 if (as_str[0] == 'i') {
2935 as_type = AS_INTERNAL;
2936 } else if (as_str[0] == 'e') {
2937 as_type = AS_EXTERNAL;
2938 } else {
2939 /* Get AS number. */
2940 as = strtoul(as_str, NULL, 10);
2941 as_type = AS_SPECIFIED;
2942 }
2943 }
2944
2945 peer = peer_lookup_by_conf_if(bgp, conf_if);
2946 if (peer) {
2947 if (as_str)
2948 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2949 afi, safi);
2950 } else {
2951 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2952 && afi == AFI_IP && safi == SAFI_UNICAST)
2953 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2954 as_type, 0, 0, NULL);
2955 else
2956 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2957 as_type, afi, safi, NULL);
2958
2959 if (!peer) {
2960 vty_out(vty, "%% BGP failed to create peer\n");
2961 return CMD_WARNING_CONFIG_FAILED;
2962 }
2963
2964 if (v6only)
2965 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2966
2967 /* Request zebra to initiate IPv6 RAs on this interface. We do
2968 * this
2969 * any unnumbered peer in order to not worry about run-time
2970 * transitions
2971 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2972 * address
2973 * gets deleted later etc.)
2974 */
2975 if (peer->ifp)
2976 bgp_zebra_initiate_radv(bgp, peer);
2977 }
2978
2979 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2980 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2981 if (v6only)
2982 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2983 else
2984 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2985
2986 /* v6only flag changed. Reset bgp seesion */
2987 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2988 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2989 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2990 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2991 } else
2992 bgp_session_reset(peer);
2993 }
2994
2995 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2996 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2997 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2998 SET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2999 }
3000
3001 if (peer_group_name) {
3002 group = peer_group_lookup(bgp, peer_group_name);
3003 if (!group) {
3004 vty_out(vty, "%% Configure the peer-group first\n");
3005 return CMD_WARNING_CONFIG_FAILED;
3006 }
3007
3008 ret = peer_group_bind(bgp, &su, peer, group, &as);
3009 }
3010
3011 return bgp_vty_return(vty, ret);
3012 }
3013
3014 DEFUN (neighbor_interface_config,
3015 neighbor_interface_config_cmd,
3016 "neighbor WORD interface [peer-group WORD]",
3017 NEIGHBOR_STR
3018 "Interface name or neighbor tag\n"
3019 "Enable BGP on interface\n"
3020 "Member of the peer-group\n"
3021 "Peer-group name\n")
3022 {
3023 int idx_word = 1;
3024 int idx_peer_group_word = 4;
3025
3026 if (argc > idx_peer_group_word)
3027 return peer_conf_interface_get(
3028 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3029 argv[idx_peer_group_word]->arg, NULL);
3030 else
3031 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3032 SAFI_UNICAST, 0, NULL, NULL);
3033 }
3034
3035 DEFUN (neighbor_interface_config_v6only,
3036 neighbor_interface_config_v6only_cmd,
3037 "neighbor WORD interface v6only [peer-group WORD]",
3038 NEIGHBOR_STR
3039 "Interface name or neighbor tag\n"
3040 "Enable BGP on interface\n"
3041 "Enable BGP with v6 link-local only\n"
3042 "Member of the peer-group\n"
3043 "Peer-group name\n")
3044 {
3045 int idx_word = 1;
3046 int idx_peer_group_word = 5;
3047
3048 if (argc > idx_peer_group_word)
3049 return peer_conf_interface_get(
3050 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3051 argv[idx_peer_group_word]->arg, NULL);
3052
3053 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3054 SAFI_UNICAST, 1, NULL, NULL);
3055 }
3056
3057
3058 DEFUN (neighbor_interface_config_remote_as,
3059 neighbor_interface_config_remote_as_cmd,
3060 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3061 NEIGHBOR_STR
3062 "Interface name or neighbor tag\n"
3063 "Enable BGP on interface\n"
3064 "Specify a BGP neighbor\n"
3065 AS_STR
3066 "Internal BGP peer\n"
3067 "External BGP peer\n")
3068 {
3069 int idx_word = 1;
3070 int idx_remote_as = 4;
3071 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3072 SAFI_UNICAST, 0, NULL,
3073 argv[idx_remote_as]->arg);
3074 }
3075
3076 DEFUN (neighbor_interface_v6only_config_remote_as,
3077 neighbor_interface_v6only_config_remote_as_cmd,
3078 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3079 NEIGHBOR_STR
3080 "Interface name or neighbor tag\n"
3081 "Enable BGP with v6 link-local only\n"
3082 "Enable BGP on interface\n"
3083 "Specify a BGP neighbor\n"
3084 AS_STR
3085 "Internal BGP peer\n"
3086 "External BGP peer\n")
3087 {
3088 int idx_word = 1;
3089 int idx_remote_as = 5;
3090 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3091 SAFI_UNICAST, 1, NULL,
3092 argv[idx_remote_as]->arg);
3093 }
3094
3095 DEFUN (neighbor_peer_group,
3096 neighbor_peer_group_cmd,
3097 "neighbor WORD peer-group",
3098 NEIGHBOR_STR
3099 "Interface name or neighbor tag\n"
3100 "Configure peer-group\n")
3101 {
3102 VTY_DECLVAR_CONTEXT(bgp, bgp);
3103 int idx_word = 1;
3104 struct peer *peer;
3105 struct peer_group *group;
3106
3107 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3108 if (peer) {
3109 vty_out(vty, "%% Name conflict with interface: \n");
3110 return CMD_WARNING_CONFIG_FAILED;
3111 }
3112
3113 group = peer_group_get(bgp, argv[idx_word]->arg);
3114 if (!group) {
3115 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3116 return CMD_WARNING_CONFIG_FAILED;
3117 }
3118
3119 return CMD_SUCCESS;
3120 }
3121
3122 DEFUN (no_neighbor,
3123 no_neighbor_cmd,
3124 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3125 NO_STR
3126 NEIGHBOR_STR
3127 NEIGHBOR_ADDR_STR2
3128 "Specify a BGP neighbor\n"
3129 AS_STR
3130 "Internal BGP peer\n"
3131 "External BGP peer\n")
3132 {
3133 VTY_DECLVAR_CONTEXT(bgp, bgp);
3134 int idx_peer = 2;
3135 int ret;
3136 union sockunion su;
3137 struct peer_group *group;
3138 struct peer *peer;
3139 struct peer *other;
3140
3141 ret = str2sockunion(argv[idx_peer]->arg, &su);
3142 if (ret < 0) {
3143 /* look up for neighbor by interface name config. */
3144 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3145 if (peer) {
3146 /* Request zebra to terminate IPv6 RAs on this
3147 * interface. */
3148 if (peer->ifp)
3149 bgp_zebra_terminate_radv(peer->bgp, peer);
3150 peer_delete(peer);
3151 return CMD_SUCCESS;
3152 }
3153
3154 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3155 if (group)
3156 peer_group_delete(group);
3157 else {
3158 vty_out(vty, "%% Create the peer-group first\n");
3159 return CMD_WARNING_CONFIG_FAILED;
3160 }
3161 } else {
3162 peer = peer_lookup(bgp, &su);
3163 if (peer) {
3164 if (peer_dynamic_neighbor(peer)) {
3165 vty_out(vty,
3166 "%% Operation not allowed on a dynamic neighbor\n");
3167 return CMD_WARNING_CONFIG_FAILED;
3168 }
3169
3170 other = peer->doppelganger;
3171 peer_delete(peer);
3172 if (other && other->status != Deleted)
3173 peer_delete(other);
3174 }
3175 }
3176
3177 return CMD_SUCCESS;
3178 }
3179
3180 DEFUN (no_neighbor_interface_config,
3181 no_neighbor_interface_config_cmd,
3182 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3183 NO_STR
3184 NEIGHBOR_STR
3185 "Interface name\n"
3186 "Configure BGP on interface\n"
3187 "Enable BGP with v6 link-local only\n"
3188 "Member of the peer-group\n"
3189 "Peer-group name\n"
3190 "Specify a BGP neighbor\n"
3191 AS_STR
3192 "Internal BGP peer\n"
3193 "External BGP peer\n")
3194 {
3195 VTY_DECLVAR_CONTEXT(bgp, bgp);
3196 int idx_word = 2;
3197 struct peer *peer;
3198
3199 /* look up for neighbor by interface name config. */
3200 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3201 if (peer) {
3202 /* Request zebra to terminate IPv6 RAs on this interface. */
3203 if (peer->ifp)
3204 bgp_zebra_terminate_radv(peer->bgp, peer);
3205 peer_delete(peer);
3206 } else {
3207 vty_out(vty, "%% Create the bgp interface first\n");
3208 return CMD_WARNING_CONFIG_FAILED;
3209 }
3210 return CMD_SUCCESS;
3211 }
3212
3213 DEFUN (no_neighbor_peer_group,
3214 no_neighbor_peer_group_cmd,
3215 "no neighbor WORD peer-group",
3216 NO_STR
3217 NEIGHBOR_STR
3218 "Neighbor tag\n"
3219 "Configure peer-group\n")
3220 {
3221 VTY_DECLVAR_CONTEXT(bgp, bgp);
3222 int idx_word = 2;
3223 struct peer_group *group;
3224
3225 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3226 if (group)
3227 peer_group_delete(group);
3228 else {
3229 vty_out(vty, "%% Create the peer-group first\n");
3230 return CMD_WARNING_CONFIG_FAILED;
3231 }
3232 return CMD_SUCCESS;
3233 }
3234
3235 DEFUN (no_neighbor_interface_peer_group_remote_as,
3236 no_neighbor_interface_peer_group_remote_as_cmd,
3237 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3238 NO_STR
3239 NEIGHBOR_STR
3240 "Interface name or neighbor tag\n"
3241 "Specify a BGP neighbor\n"
3242 AS_STR
3243 "Internal BGP peer\n"
3244 "External BGP peer\n")
3245 {
3246 VTY_DECLVAR_CONTEXT(bgp, bgp);
3247 int idx_word = 2;
3248 struct peer_group *group;
3249 struct peer *peer;
3250
3251 /* look up for neighbor by interface name config. */
3252 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3253 if (peer) {
3254 peer_as_change(peer, 0, AS_SPECIFIED);
3255 return CMD_SUCCESS;
3256 }
3257
3258 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3259 if (group)
3260 peer_group_remote_as_delete(group);
3261 else {
3262 vty_out(vty, "%% Create the peer-group or interface first\n");
3263 return CMD_WARNING_CONFIG_FAILED;
3264 }
3265 return CMD_SUCCESS;
3266 }
3267
3268 DEFUN (neighbor_local_as,
3269 neighbor_local_as_cmd,
3270 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3271 NEIGHBOR_STR
3272 NEIGHBOR_ADDR_STR2
3273 "Specify a local-as number\n"
3274 "AS number used as local AS\n")
3275 {
3276 int idx_peer = 1;
3277 int idx_number = 3;
3278 struct peer *peer;
3279 int ret;
3280 as_t as;
3281
3282 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3283 if (!peer)
3284 return CMD_WARNING_CONFIG_FAILED;
3285
3286 as = strtoul(argv[idx_number]->arg, NULL, 10);
3287 ret = peer_local_as_set(peer, as, 0, 0);
3288 return bgp_vty_return(vty, ret);
3289 }
3290
3291 DEFUN (neighbor_local_as_no_prepend,
3292 neighbor_local_as_no_prepend_cmd,
3293 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3294 NEIGHBOR_STR
3295 NEIGHBOR_ADDR_STR2
3296 "Specify a local-as number\n"
3297 "AS number used as local AS\n"
3298 "Do not prepend local-as to updates from ebgp peers\n")
3299 {
3300 int idx_peer = 1;
3301 int idx_number = 3;
3302 struct peer *peer;
3303 int ret;
3304 as_t as;
3305
3306 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3307 if (!peer)
3308 return CMD_WARNING_CONFIG_FAILED;
3309
3310 as = strtoul(argv[idx_number]->arg, NULL, 10);
3311 ret = peer_local_as_set(peer, as, 1, 0);
3312 return bgp_vty_return(vty, ret);
3313 }
3314
3315 DEFUN (neighbor_local_as_no_prepend_replace_as,
3316 neighbor_local_as_no_prepend_replace_as_cmd,
3317 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3318 NEIGHBOR_STR
3319 NEIGHBOR_ADDR_STR2
3320 "Specify a local-as number\n"
3321 "AS number used as local AS\n"
3322 "Do not prepend local-as to updates from ebgp peers\n"
3323 "Do not prepend local-as to updates from ibgp peers\n")
3324 {
3325 int idx_peer = 1;
3326 int idx_number = 3;
3327 struct peer *peer;
3328 int ret;
3329 as_t as;
3330
3331 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3332 if (!peer)
3333 return CMD_WARNING_CONFIG_FAILED;
3334
3335 as = strtoul(argv[idx_number]->arg, NULL, 10);
3336 ret = peer_local_as_set(peer, as, 1, 1);
3337 return bgp_vty_return(vty, ret);
3338 }
3339
3340 DEFUN (no_neighbor_local_as,
3341 no_neighbor_local_as_cmd,
3342 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3343 NO_STR
3344 NEIGHBOR_STR
3345 NEIGHBOR_ADDR_STR2
3346 "Specify a local-as number\n"
3347 "AS number used as local AS\n"
3348 "Do not prepend local-as to updates from ebgp peers\n"
3349 "Do not prepend local-as to updates from ibgp peers\n")
3350 {
3351 int idx_peer = 2;
3352 struct peer *peer;
3353 int ret;
3354
3355 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3356 if (!peer)
3357 return CMD_WARNING_CONFIG_FAILED;
3358
3359 ret = peer_local_as_unset(peer);
3360 return bgp_vty_return(vty, ret);
3361 }
3362
3363
3364 DEFUN (neighbor_solo,
3365 neighbor_solo_cmd,
3366 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3367 NEIGHBOR_STR
3368 NEIGHBOR_ADDR_STR2
3369 "Solo peer - part of its own update group\n")
3370 {
3371 int idx_peer = 1;
3372 struct peer *peer;
3373 int ret;
3374
3375 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3376 if (!peer)
3377 return CMD_WARNING_CONFIG_FAILED;
3378
3379 ret = update_group_adjust_soloness(peer, 1);
3380 return bgp_vty_return(vty, ret);
3381 }
3382
3383 DEFUN (no_neighbor_solo,
3384 no_neighbor_solo_cmd,
3385 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3386 NO_STR
3387 NEIGHBOR_STR
3388 NEIGHBOR_ADDR_STR2
3389 "Solo peer - part of its own update group\n")
3390 {
3391 int idx_peer = 2;
3392 struct peer *peer;
3393 int ret;
3394
3395 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3396 if (!peer)
3397 return CMD_WARNING_CONFIG_FAILED;
3398
3399 ret = update_group_adjust_soloness(peer, 0);
3400 return bgp_vty_return(vty, ret);
3401 }
3402
3403 DEFUN (neighbor_password,
3404 neighbor_password_cmd,
3405 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3406 NEIGHBOR_STR
3407 NEIGHBOR_ADDR_STR2
3408 "Set a password\n"
3409 "The password\n")
3410 {
3411 int idx_peer = 1;
3412 int idx_line = 3;
3413 struct peer *peer;
3414 int ret;
3415
3416 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3417 if (!peer)
3418 return CMD_WARNING_CONFIG_FAILED;
3419
3420 ret = peer_password_set(peer, argv[idx_line]->arg);
3421 return bgp_vty_return(vty, ret);
3422 }
3423
3424 DEFUN (no_neighbor_password,
3425 no_neighbor_password_cmd,
3426 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3427 NO_STR
3428 NEIGHBOR_STR
3429 NEIGHBOR_ADDR_STR2
3430 "Set a password\n"
3431 "The password\n")
3432 {
3433 int idx_peer = 2;
3434 struct peer *peer;
3435 int ret;
3436
3437 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3438 if (!peer)
3439 return CMD_WARNING_CONFIG_FAILED;
3440
3441 ret = peer_password_unset(peer);
3442 return bgp_vty_return(vty, ret);
3443 }
3444
3445 DEFUN (neighbor_activate,
3446 neighbor_activate_cmd,
3447 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3448 NEIGHBOR_STR
3449 NEIGHBOR_ADDR_STR2
3450 "Enable the Address Family for this Neighbor\n")
3451 {
3452 int idx_peer = 1;
3453 int ret;
3454 struct peer *peer;
3455
3456 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3457 if (!peer)
3458 return CMD_WARNING_CONFIG_FAILED;
3459
3460 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3461 return bgp_vty_return(vty, ret);
3462 }
3463
3464 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3465 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3466 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3467 "Enable the Address Family for this Neighbor\n")
3468
3469 DEFUN (no_neighbor_activate,
3470 no_neighbor_activate_cmd,
3471 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3472 NO_STR
3473 NEIGHBOR_STR
3474 NEIGHBOR_ADDR_STR2
3475 "Enable the Address Family for this Neighbor\n")
3476 {
3477 int idx_peer = 2;
3478 int ret;
3479 struct peer *peer;
3480
3481 /* Lookup peer. */
3482 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3483 if (!peer)
3484 return CMD_WARNING_CONFIG_FAILED;
3485
3486 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3487 return bgp_vty_return(vty, ret);
3488 }
3489
3490 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3491 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3492 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3493 "Enable the Address Family for this Neighbor\n")
3494
3495 DEFUN (neighbor_set_peer_group,
3496 neighbor_set_peer_group_cmd,
3497 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3498 NEIGHBOR_STR
3499 NEIGHBOR_ADDR_STR2
3500 "Member of the peer-group\n"
3501 "Peer-group name\n")
3502 {
3503 VTY_DECLVAR_CONTEXT(bgp, bgp);
3504 int idx_peer = 1;
3505 int idx_word = 3;
3506 int ret;
3507 as_t as;
3508 union sockunion su;
3509 struct peer *peer;
3510 struct peer_group *group;
3511
3512 ret = str2sockunion(argv[idx_peer]->arg, &su);
3513 if (ret < 0) {
3514 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3515 if (!peer) {
3516 vty_out(vty, "%% Malformed address or name: %s\n",
3517 argv[idx_peer]->arg);
3518 return CMD_WARNING_CONFIG_FAILED;
3519 }
3520 } else {
3521 if (peer_address_self_check(bgp, &su)) {
3522 vty_out(vty,
3523 "%% Can not configure the local system as neighbor\n");
3524 return CMD_WARNING_CONFIG_FAILED;
3525 }
3526
3527 /* Disallow for dynamic neighbor. */
3528 peer = peer_lookup(bgp, &su);
3529 if (peer && peer_dynamic_neighbor(peer)) {
3530 vty_out(vty,
3531 "%% Operation not allowed on a dynamic neighbor\n");
3532 return CMD_WARNING_CONFIG_FAILED;
3533 }
3534 }
3535
3536 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3537 if (!group) {
3538 vty_out(vty, "%% Configure the peer-group first\n");
3539 return CMD_WARNING_CONFIG_FAILED;
3540 }
3541
3542 ret = peer_group_bind(bgp, &su, peer, group, &as);
3543
3544 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3545 vty_out(vty,
3546 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3547 as);
3548 return CMD_WARNING_CONFIG_FAILED;
3549 }
3550
3551 return bgp_vty_return(vty, ret);
3552 }
3553
3554 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3555 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3556 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3557 "Member of the peer-group\n"
3558 "Peer-group name\n")
3559
3560 DEFUN (no_neighbor_set_peer_group,
3561 no_neighbor_set_peer_group_cmd,
3562 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3563 NO_STR
3564 NEIGHBOR_STR
3565 NEIGHBOR_ADDR_STR2
3566 "Member of the peer-group\n"
3567 "Peer-group name\n")
3568 {
3569 VTY_DECLVAR_CONTEXT(bgp, bgp);
3570 int idx_peer = 2;
3571 int idx_word = 4;
3572 int ret;
3573 struct peer *peer;
3574 struct peer_group *group;
3575
3576 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3577 if (!peer)
3578 return CMD_WARNING_CONFIG_FAILED;
3579
3580 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3581 if (!group) {
3582 vty_out(vty, "%% Configure the peer-group first\n");
3583 return CMD_WARNING_CONFIG_FAILED;
3584 }
3585
3586 ret = peer_delete(peer);
3587
3588 return bgp_vty_return(vty, ret);
3589 }
3590
3591 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3592 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3593 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3594 "Member of the peer-group\n"
3595 "Peer-group name\n")
3596
3597 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3598 uint32_t flag, int set)
3599 {
3600 int ret;
3601 struct peer *peer;
3602
3603 peer = peer_and_group_lookup_vty(vty, ip_str);
3604 if (!peer)
3605 return CMD_WARNING_CONFIG_FAILED;
3606
3607 /*
3608 * If 'neighbor <interface>', then this is for directly connected peers,
3609 * we should not accept disable-connected-check.
3610 */
3611 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3612 vty_out(vty,
3613 "%s is directly connected peer, cannot accept disable-"
3614 "connected-check\n",
3615 ip_str);
3616 return CMD_WARNING_CONFIG_FAILED;
3617 }
3618
3619 if (!set && flag == PEER_FLAG_SHUTDOWN)
3620 peer_tx_shutdown_message_unset(peer);
3621
3622 if (set)
3623 ret = peer_flag_set(peer, flag);
3624 else
3625 ret = peer_flag_unset(peer, flag);
3626
3627 return bgp_vty_return(vty, ret);
3628 }
3629
3630 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3631 {
3632 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3633 }
3634
3635 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3636 uint32_t flag)
3637 {
3638 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3639 }
3640
3641 /* neighbor passive. */
3642 DEFUN (neighbor_passive,
3643 neighbor_passive_cmd,
3644 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3645 NEIGHBOR_STR
3646 NEIGHBOR_ADDR_STR2
3647 "Don't send open messages to this neighbor\n")
3648 {
3649 int idx_peer = 1;
3650 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3651 }
3652
3653 DEFUN (no_neighbor_passive,
3654 no_neighbor_passive_cmd,
3655 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3656 NO_STR
3657 NEIGHBOR_STR
3658 NEIGHBOR_ADDR_STR2
3659 "Don't send open messages to this neighbor\n")
3660 {
3661 int idx_peer = 2;
3662 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3663 }
3664
3665 /* neighbor shutdown. */
3666 DEFUN (neighbor_shutdown_msg,
3667 neighbor_shutdown_msg_cmd,
3668 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3669 NEIGHBOR_STR
3670 NEIGHBOR_ADDR_STR2
3671 "Administratively shut down this neighbor\n"
3672 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3673 "Shutdown message\n")
3674 {
3675 int idx_peer = 1;
3676
3677 if (argc >= 5) {
3678 struct peer *peer =
3679 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3680 char *message;
3681
3682 if (!peer)
3683 return CMD_WARNING_CONFIG_FAILED;
3684 message = argv_concat(argv, argc, 4);
3685 peer_tx_shutdown_message_set(peer, message);
3686 XFREE(MTYPE_TMP, message);
3687 }
3688
3689 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3690 }
3691
3692 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3693 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3694 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3695 "Administratively shut down this neighbor\n")
3696
3697 DEFUN (no_neighbor_shutdown_msg,
3698 no_neighbor_shutdown_msg_cmd,
3699 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3700 NO_STR
3701 NEIGHBOR_STR
3702 NEIGHBOR_ADDR_STR2
3703 "Administratively shut down this neighbor\n"
3704 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3705 "Shutdown message\n")
3706 {
3707 int idx_peer = 2;
3708
3709 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3710 PEER_FLAG_SHUTDOWN);
3711 }
3712
3713 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3714 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3715 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3716 "Administratively shut down this neighbor\n")
3717
3718 /* neighbor capability dynamic. */
3719 DEFUN (neighbor_capability_dynamic,
3720 neighbor_capability_dynamic_cmd,
3721 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3722 NEIGHBOR_STR
3723 NEIGHBOR_ADDR_STR2
3724 "Advertise capability to the peer\n"
3725 "Advertise dynamic capability to this neighbor\n")
3726 {
3727 int idx_peer = 1;
3728 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3729 PEER_FLAG_DYNAMIC_CAPABILITY);
3730 }
3731
3732 DEFUN (no_neighbor_capability_dynamic,
3733 no_neighbor_capability_dynamic_cmd,
3734 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3735 NO_STR
3736 NEIGHBOR_STR
3737 NEIGHBOR_ADDR_STR2
3738 "Advertise capability to the peer\n"
3739 "Advertise dynamic capability to this neighbor\n")
3740 {
3741 int idx_peer = 2;
3742 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3743 PEER_FLAG_DYNAMIC_CAPABILITY);
3744 }
3745
3746 /* neighbor dont-capability-negotiate */
3747 DEFUN (neighbor_dont_capability_negotiate,
3748 neighbor_dont_capability_negotiate_cmd,
3749 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3750 NEIGHBOR_STR
3751 NEIGHBOR_ADDR_STR2
3752 "Do not perform capability negotiation\n")
3753 {
3754 int idx_peer = 1;
3755 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3756 PEER_FLAG_DONT_CAPABILITY);
3757 }
3758
3759 DEFUN (no_neighbor_dont_capability_negotiate,
3760 no_neighbor_dont_capability_negotiate_cmd,
3761 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3762 NO_STR
3763 NEIGHBOR_STR
3764 NEIGHBOR_ADDR_STR2
3765 "Do not perform capability negotiation\n")
3766 {
3767 int idx_peer = 2;
3768 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3769 PEER_FLAG_DONT_CAPABILITY);
3770 }
3771
3772 /* neighbor capability extended next hop encoding */
3773 DEFUN (neighbor_capability_enhe,
3774 neighbor_capability_enhe_cmd,
3775 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3776 NEIGHBOR_STR
3777 NEIGHBOR_ADDR_STR2
3778 "Advertise capability to the peer\n"
3779 "Advertise extended next-hop capability to the peer\n")
3780 {
3781 int idx_peer = 1;
3782 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3783 PEER_FLAG_CAPABILITY_ENHE);
3784 }
3785
3786 DEFUN (no_neighbor_capability_enhe,
3787 no_neighbor_capability_enhe_cmd,
3788 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3789 NO_STR
3790 NEIGHBOR_STR
3791 NEIGHBOR_ADDR_STR2
3792 "Advertise capability to the peer\n"
3793 "Advertise extended next-hop capability to the peer\n")
3794 {
3795 int idx_peer = 2;
3796 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3797 PEER_FLAG_CAPABILITY_ENHE);
3798 }
3799
3800 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3801 afi_t afi, safi_t safi, uint32_t flag,
3802 int set)
3803 {
3804 int ret;
3805 struct peer *peer;
3806
3807 peer = peer_and_group_lookup_vty(vty, peer_str);
3808 if (!peer)
3809 return CMD_WARNING_CONFIG_FAILED;
3810
3811 if (set)
3812 ret = peer_af_flag_set(peer, afi, safi, flag);
3813 else
3814 ret = peer_af_flag_unset(peer, afi, safi, flag);
3815
3816 return bgp_vty_return(vty, ret);
3817 }
3818
3819 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3820 afi_t afi, safi_t safi, uint32_t flag)
3821 {
3822 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3823 }
3824
3825 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3826 afi_t afi, safi_t safi, uint32_t flag)
3827 {
3828 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3829 }
3830
3831 /* neighbor capability orf prefix-list. */
3832 DEFUN (neighbor_capability_orf_prefix,
3833 neighbor_capability_orf_prefix_cmd,
3834 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3835 NEIGHBOR_STR
3836 NEIGHBOR_ADDR_STR2
3837 "Advertise capability to the peer\n"
3838 "Advertise ORF capability to the peer\n"
3839 "Advertise prefixlist ORF capability to this neighbor\n"
3840 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3841 "Capability to RECEIVE the ORF from this neighbor\n"
3842 "Capability to SEND the ORF to this neighbor\n")
3843 {
3844 int idx_peer = 1;
3845 int idx_send_recv = 5;
3846 uint16_t flag = 0;
3847
3848 if (strmatch(argv[idx_send_recv]->text, "send"))
3849 flag = PEER_FLAG_ORF_PREFIX_SM;
3850 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3851 flag = PEER_FLAG_ORF_PREFIX_RM;
3852 else if (strmatch(argv[idx_send_recv]->text, "both"))
3853 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3854 else {
3855 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3856 return CMD_WARNING_CONFIG_FAILED;
3857 }
3858
3859 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3860 bgp_node_safi(vty), flag);
3861 }
3862
3863 ALIAS_HIDDEN(
3864 neighbor_capability_orf_prefix,
3865 neighbor_capability_orf_prefix_hidden_cmd,
3866 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3867 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3868 "Advertise capability to the peer\n"
3869 "Advertise ORF capability to the peer\n"
3870 "Advertise prefixlist ORF capability to this neighbor\n"
3871 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3872 "Capability to RECEIVE the ORF from this neighbor\n"
3873 "Capability to SEND the ORF to this neighbor\n")
3874
3875 DEFUN (no_neighbor_capability_orf_prefix,
3876 no_neighbor_capability_orf_prefix_cmd,
3877 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3878 NO_STR
3879 NEIGHBOR_STR
3880 NEIGHBOR_ADDR_STR2
3881 "Advertise capability to the peer\n"
3882 "Advertise ORF capability to the peer\n"
3883 "Advertise prefixlist ORF capability to this neighbor\n"
3884 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3885 "Capability to RECEIVE the ORF from this neighbor\n"
3886 "Capability to SEND the ORF to this neighbor\n")
3887 {
3888 int idx_peer = 2;
3889 int idx_send_recv = 6;
3890 uint16_t flag = 0;
3891
3892 if (strmatch(argv[idx_send_recv]->text, "send"))
3893 flag = PEER_FLAG_ORF_PREFIX_SM;
3894 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3895 flag = PEER_FLAG_ORF_PREFIX_RM;
3896 else if (strmatch(argv[idx_send_recv]->text, "both"))
3897 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3898 else {
3899 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3900 return CMD_WARNING_CONFIG_FAILED;
3901 }
3902
3903 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3904 bgp_node_afi(vty), bgp_node_safi(vty),
3905 flag);
3906 }
3907
3908 ALIAS_HIDDEN(
3909 no_neighbor_capability_orf_prefix,
3910 no_neighbor_capability_orf_prefix_hidden_cmd,
3911 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3912 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3913 "Advertise capability to the peer\n"
3914 "Advertise ORF capability to the peer\n"
3915 "Advertise prefixlist ORF capability to this neighbor\n"
3916 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3917 "Capability to RECEIVE the ORF from this neighbor\n"
3918 "Capability to SEND the ORF to this neighbor\n")
3919
3920 /* neighbor next-hop-self. */
3921 DEFUN (neighbor_nexthop_self,
3922 neighbor_nexthop_self_cmd,
3923 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3924 NEIGHBOR_STR
3925 NEIGHBOR_ADDR_STR2
3926 "Disable the next hop calculation for this neighbor\n")
3927 {
3928 int idx_peer = 1;
3929 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3930 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3931 }
3932
3933 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3934 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3935 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3936 "Disable the next hop calculation for this neighbor\n")
3937
3938 /* neighbor next-hop-self. */
3939 DEFUN (neighbor_nexthop_self_force,
3940 neighbor_nexthop_self_force_cmd,
3941 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3942 NEIGHBOR_STR
3943 NEIGHBOR_ADDR_STR2
3944 "Disable the next hop calculation for this neighbor\n"
3945 "Set the next hop to self for reflected routes\n")
3946 {
3947 int idx_peer = 1;
3948 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3949 bgp_node_safi(vty),
3950 PEER_FLAG_FORCE_NEXTHOP_SELF);
3951 }
3952
3953 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3954 neighbor_nexthop_self_force_hidden_cmd,
3955 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3956 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3957 "Disable the next hop calculation for this neighbor\n"
3958 "Set the next hop to self for reflected routes\n")
3959
3960 DEFUN (no_neighbor_nexthop_self,
3961 no_neighbor_nexthop_self_cmd,
3962 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3963 NO_STR
3964 NEIGHBOR_STR
3965 NEIGHBOR_ADDR_STR2
3966 "Disable the next hop calculation for this neighbor\n")
3967 {
3968 int idx_peer = 2;
3969 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3970 bgp_node_afi(vty), bgp_node_safi(vty),
3971 PEER_FLAG_NEXTHOP_SELF);
3972 }
3973
3974 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3975 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3976 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3977 "Disable the next hop calculation for this neighbor\n")
3978
3979 DEFUN (no_neighbor_nexthop_self_force,
3980 no_neighbor_nexthop_self_force_cmd,
3981 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3982 NO_STR
3983 NEIGHBOR_STR
3984 NEIGHBOR_ADDR_STR2
3985 "Disable the next hop calculation for this neighbor\n"
3986 "Set the next hop to self for reflected routes\n")
3987 {
3988 int idx_peer = 2;
3989 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3990 bgp_node_afi(vty), bgp_node_safi(vty),
3991 PEER_FLAG_FORCE_NEXTHOP_SELF);
3992 }
3993
3994 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3995 no_neighbor_nexthop_self_force_hidden_cmd,
3996 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3997 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3998 "Disable the next hop calculation for this neighbor\n"
3999 "Set the next hop to self for reflected routes\n")
4000
4001 /* neighbor as-override */
4002 DEFUN (neighbor_as_override,
4003 neighbor_as_override_cmd,
4004 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4005 NEIGHBOR_STR
4006 NEIGHBOR_ADDR_STR2
4007 "Override ASNs in outbound updates if aspath equals remote-as\n")
4008 {
4009 int idx_peer = 1;
4010 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4011 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
4012 }
4013
4014 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
4015 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4016 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4017 "Override ASNs in outbound updates if aspath equals remote-as\n")
4018
4019 DEFUN (no_neighbor_as_override,
4020 no_neighbor_as_override_cmd,
4021 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4022 NO_STR
4023 NEIGHBOR_STR
4024 NEIGHBOR_ADDR_STR2
4025 "Override ASNs in outbound updates if aspath equals remote-as\n")
4026 {
4027 int idx_peer = 2;
4028 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4029 bgp_node_afi(vty), bgp_node_safi(vty),
4030 PEER_FLAG_AS_OVERRIDE);
4031 }
4032
4033 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4034 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4035 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4036 "Override ASNs in outbound updates if aspath equals remote-as\n")
4037
4038 /* neighbor remove-private-AS. */
4039 DEFUN (neighbor_remove_private_as,
4040 neighbor_remove_private_as_cmd,
4041 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4042 NEIGHBOR_STR
4043 NEIGHBOR_ADDR_STR2
4044 "Remove private ASNs in outbound updates\n")
4045 {
4046 int idx_peer = 1;
4047 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4048 bgp_node_safi(vty),
4049 PEER_FLAG_REMOVE_PRIVATE_AS);
4050 }
4051
4052 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4053 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4054 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4055 "Remove private ASNs in outbound updates\n")
4056
4057 DEFUN (neighbor_remove_private_as_all,
4058 neighbor_remove_private_as_all_cmd,
4059 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4060 NEIGHBOR_STR
4061 NEIGHBOR_ADDR_STR2
4062 "Remove private ASNs in outbound updates\n"
4063 "Apply to all AS numbers\n")
4064 {
4065 int idx_peer = 1;
4066 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4067 bgp_node_safi(vty),
4068 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4069 }
4070
4071 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4072 neighbor_remove_private_as_all_hidden_cmd,
4073 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4074 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4075 "Remove private ASNs in outbound updates\n"
4076 "Apply to all AS numbers")
4077
4078 DEFUN (neighbor_remove_private_as_replace_as,
4079 neighbor_remove_private_as_replace_as_cmd,
4080 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4081 NEIGHBOR_STR
4082 NEIGHBOR_ADDR_STR2
4083 "Remove private ASNs in outbound updates\n"
4084 "Replace private ASNs with our ASN in outbound updates\n")
4085 {
4086 int idx_peer = 1;
4087 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4088 bgp_node_safi(vty),
4089 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4090 }
4091
4092 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4093 neighbor_remove_private_as_replace_as_hidden_cmd,
4094 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4096 "Remove private ASNs in outbound updates\n"
4097 "Replace private ASNs with our ASN in outbound updates\n")
4098
4099 DEFUN (neighbor_remove_private_as_all_replace_as,
4100 neighbor_remove_private_as_all_replace_as_cmd,
4101 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4102 NEIGHBOR_STR
4103 NEIGHBOR_ADDR_STR2
4104 "Remove private ASNs in outbound updates\n"
4105 "Apply to all AS numbers\n"
4106 "Replace private ASNs with our ASN in outbound updates\n")
4107 {
4108 int idx_peer = 1;
4109 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4110 bgp_node_safi(vty),
4111 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4112 }
4113
4114 ALIAS_HIDDEN(
4115 neighbor_remove_private_as_all_replace_as,
4116 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4117 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4118 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4119 "Remove private ASNs in outbound updates\n"
4120 "Apply to all AS numbers\n"
4121 "Replace private ASNs with our ASN in outbound updates\n")
4122
4123 DEFUN (no_neighbor_remove_private_as,
4124 no_neighbor_remove_private_as_cmd,
4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4126 NO_STR
4127 NEIGHBOR_STR
4128 NEIGHBOR_ADDR_STR2
4129 "Remove private ASNs in outbound updates\n")
4130 {
4131 int idx_peer = 2;
4132 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4133 bgp_node_afi(vty), bgp_node_safi(vty),
4134 PEER_FLAG_REMOVE_PRIVATE_AS);
4135 }
4136
4137 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4138 no_neighbor_remove_private_as_hidden_cmd,
4139 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4140 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4141 "Remove private ASNs in outbound updates\n")
4142
4143 DEFUN (no_neighbor_remove_private_as_all,
4144 no_neighbor_remove_private_as_all_cmd,
4145 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4146 NO_STR
4147 NEIGHBOR_STR
4148 NEIGHBOR_ADDR_STR2
4149 "Remove private ASNs in outbound updates\n"
4150 "Apply to all AS numbers\n")
4151 {
4152 int idx_peer = 2;
4153 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4154 bgp_node_afi(vty), bgp_node_safi(vty),
4155 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4156 }
4157
4158 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4159 no_neighbor_remove_private_as_all_hidden_cmd,
4160 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4161 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4162 "Remove private ASNs in outbound updates\n"
4163 "Apply to all AS numbers\n")
4164
4165 DEFUN (no_neighbor_remove_private_as_replace_as,
4166 no_neighbor_remove_private_as_replace_as_cmd,
4167 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4168 NO_STR
4169 NEIGHBOR_STR
4170 NEIGHBOR_ADDR_STR2
4171 "Remove private ASNs in outbound updates\n"
4172 "Replace private ASNs with our ASN in outbound updates\n")
4173 {
4174 int idx_peer = 2;
4175 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4176 bgp_node_afi(vty), bgp_node_safi(vty),
4177 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4178 }
4179
4180 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4181 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4182 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4183 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4184 "Remove private ASNs in outbound updates\n"
4185 "Replace private ASNs with our ASN in outbound updates\n")
4186
4187 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4188 no_neighbor_remove_private_as_all_replace_as_cmd,
4189 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4190 NO_STR
4191 NEIGHBOR_STR
4192 NEIGHBOR_ADDR_STR2
4193 "Remove private ASNs in outbound updates\n"
4194 "Apply to all AS numbers\n"
4195 "Replace private ASNs with our ASN in outbound updates\n")
4196 {
4197 int idx_peer = 2;
4198 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4199 bgp_node_afi(vty), bgp_node_safi(vty),
4200 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4201 }
4202
4203 ALIAS_HIDDEN(
4204 no_neighbor_remove_private_as_all_replace_as,
4205 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4206 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4208 "Remove private ASNs in outbound updates\n"
4209 "Apply to all AS numbers\n"
4210 "Replace private ASNs with our ASN in outbound updates\n")
4211
4212
4213 /* neighbor send-community. */
4214 DEFUN (neighbor_send_community,
4215 neighbor_send_community_cmd,
4216 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4217 NEIGHBOR_STR
4218 NEIGHBOR_ADDR_STR2
4219 "Send Community attribute to this neighbor\n")
4220 {
4221 int idx_peer = 1;
4222
4223 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4224 bgp_node_safi(vty),
4225 PEER_FLAG_SEND_COMMUNITY);
4226 }
4227
4228 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4229 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4230 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4231 "Send Community attribute to this neighbor\n")
4232
4233 DEFUN (no_neighbor_send_community,
4234 no_neighbor_send_community_cmd,
4235 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4236 NO_STR
4237 NEIGHBOR_STR
4238 NEIGHBOR_ADDR_STR2
4239 "Send Community attribute to this neighbor\n")
4240 {
4241 int idx_peer = 2;
4242
4243 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4244 bgp_node_afi(vty), bgp_node_safi(vty),
4245 PEER_FLAG_SEND_COMMUNITY);
4246 }
4247
4248 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4249 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4250 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4251 "Send Community attribute to this neighbor\n")
4252
4253 /* neighbor send-community extended. */
4254 DEFUN (neighbor_send_community_type,
4255 neighbor_send_community_type_cmd,
4256 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4257 NEIGHBOR_STR
4258 NEIGHBOR_ADDR_STR2
4259 "Send Community attribute to this neighbor\n"
4260 "Send Standard and Extended Community attributes\n"
4261 "Send Standard, Large and Extended Community attributes\n"
4262 "Send Extended Community attributes\n"
4263 "Send Standard Community attributes\n"
4264 "Send Large Community attributes\n")
4265 {
4266 int idx_peer = 1;
4267 uint32_t flag = 0;
4268 const char *type = argv[argc - 1]->text;
4269
4270 if (strmatch(type, "standard")) {
4271 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4272 } else if (strmatch(type, "extended")) {
4273 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4274 } else if (strmatch(type, "large")) {
4275 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4276 } else if (strmatch(type, "both")) {
4277 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4278 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4279 } else { /* if (strmatch(type, "all")) */
4280 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4281 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4282 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4283 }
4284
4285 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4286 bgp_node_safi(vty), flag);
4287 }
4288
4289 ALIAS_HIDDEN(
4290 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4291 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4292 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4293 "Send Community attribute to this neighbor\n"
4294 "Send Standard and Extended Community attributes\n"
4295 "Send Standard, Large and Extended Community attributes\n"
4296 "Send Extended Community attributes\n"
4297 "Send Standard Community attributes\n"
4298 "Send Large Community attributes\n")
4299
4300 DEFUN (no_neighbor_send_community_type,
4301 no_neighbor_send_community_type_cmd,
4302 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4303 NO_STR
4304 NEIGHBOR_STR
4305 NEIGHBOR_ADDR_STR2
4306 "Send Community attribute to this neighbor\n"
4307 "Send Standard and Extended Community attributes\n"
4308 "Send Standard, Large and Extended Community attributes\n"
4309 "Send Extended Community attributes\n"
4310 "Send Standard Community attributes\n"
4311 "Send Large Community attributes\n")
4312 {
4313 int idx_peer = 2;
4314 uint32_t flag = 0;
4315 const char *type = argv[argc - 1]->text;
4316
4317 if (strmatch(type, "standard")) {
4318 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4319 } else if (strmatch(type, "extended")) {
4320 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4321 } else if (strmatch(type, "large")) {
4322 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4323 } else if (strmatch(type, "both")) {
4324 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4325 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4326 } else { /* if (strmatch(type, "all")) */
4327 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4328 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4329 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4330 }
4331
4332 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4333 bgp_node_afi(vty), bgp_node_safi(vty),
4334 flag);
4335 }
4336
4337 ALIAS_HIDDEN(
4338 no_neighbor_send_community_type,
4339 no_neighbor_send_community_type_hidden_cmd,
4340 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4341 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4342 "Send Community attribute to this neighbor\n"
4343 "Send Standard and Extended Community attributes\n"
4344 "Send Standard, Large and Extended Community attributes\n"
4345 "Send Extended Community attributes\n"
4346 "Send Standard Community attributes\n"
4347 "Send Large Community attributes\n")
4348
4349 /* neighbor soft-reconfig. */
4350 DEFUN (neighbor_soft_reconfiguration,
4351 neighbor_soft_reconfiguration_cmd,
4352 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4353 NEIGHBOR_STR
4354 NEIGHBOR_ADDR_STR2
4355 "Per neighbor soft reconfiguration\n"
4356 "Allow inbound soft reconfiguration for this neighbor\n")
4357 {
4358 int idx_peer = 1;
4359 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4360 bgp_node_safi(vty),
4361 PEER_FLAG_SOFT_RECONFIG);
4362 }
4363
4364 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4365 neighbor_soft_reconfiguration_hidden_cmd,
4366 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4367 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4368 "Per neighbor soft reconfiguration\n"
4369 "Allow inbound soft reconfiguration for this neighbor\n")
4370
4371 DEFUN (no_neighbor_soft_reconfiguration,
4372 no_neighbor_soft_reconfiguration_cmd,
4373 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4374 NO_STR
4375 NEIGHBOR_STR
4376 NEIGHBOR_ADDR_STR2
4377 "Per neighbor soft reconfiguration\n"
4378 "Allow inbound soft reconfiguration for this neighbor\n")
4379 {
4380 int idx_peer = 2;
4381 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4382 bgp_node_afi(vty), bgp_node_safi(vty),
4383 PEER_FLAG_SOFT_RECONFIG);
4384 }
4385
4386 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4387 no_neighbor_soft_reconfiguration_hidden_cmd,
4388 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4389 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4390 "Per neighbor soft reconfiguration\n"
4391 "Allow inbound soft reconfiguration for this neighbor\n")
4392
4393 DEFUN (neighbor_route_reflector_client,
4394 neighbor_route_reflector_client_cmd,
4395 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4396 NEIGHBOR_STR
4397 NEIGHBOR_ADDR_STR2
4398 "Configure a neighbor as Route Reflector client\n")
4399 {
4400 int idx_peer = 1;
4401 struct peer *peer;
4402
4403
4404 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4405 if (!peer)
4406 return CMD_WARNING_CONFIG_FAILED;
4407
4408 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4409 bgp_node_safi(vty),
4410 PEER_FLAG_REFLECTOR_CLIENT);
4411 }
4412
4413 ALIAS_HIDDEN(neighbor_route_reflector_client,
4414 neighbor_route_reflector_client_hidden_cmd,
4415 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4416 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4417 "Configure a neighbor as Route Reflector client\n")
4418
4419 DEFUN (no_neighbor_route_reflector_client,
4420 no_neighbor_route_reflector_client_cmd,
4421 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4422 NO_STR
4423 NEIGHBOR_STR
4424 NEIGHBOR_ADDR_STR2
4425 "Configure a neighbor as Route Reflector client\n")
4426 {
4427 int idx_peer = 2;
4428 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4429 bgp_node_afi(vty), bgp_node_safi(vty),
4430 PEER_FLAG_REFLECTOR_CLIENT);
4431 }
4432
4433 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4434 no_neighbor_route_reflector_client_hidden_cmd,
4435 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4436 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4437 "Configure a neighbor as Route Reflector client\n")
4438
4439 /* neighbor route-server-client. */
4440 DEFUN (neighbor_route_server_client,
4441 neighbor_route_server_client_cmd,
4442 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4443 NEIGHBOR_STR
4444 NEIGHBOR_ADDR_STR2
4445 "Configure a neighbor as Route Server client\n")
4446 {
4447 int idx_peer = 1;
4448 struct peer *peer;
4449
4450 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4451 if (!peer)
4452 return CMD_WARNING_CONFIG_FAILED;
4453 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4454 bgp_node_safi(vty),
4455 PEER_FLAG_RSERVER_CLIENT);
4456 }
4457
4458 ALIAS_HIDDEN(neighbor_route_server_client,
4459 neighbor_route_server_client_hidden_cmd,
4460 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4461 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4462 "Configure a neighbor as Route Server client\n")
4463
4464 DEFUN (no_neighbor_route_server_client,
4465 no_neighbor_route_server_client_cmd,
4466 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4467 NO_STR
4468 NEIGHBOR_STR
4469 NEIGHBOR_ADDR_STR2
4470 "Configure a neighbor as Route Server client\n")
4471 {
4472 int idx_peer = 2;
4473 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4474 bgp_node_afi(vty), bgp_node_safi(vty),
4475 PEER_FLAG_RSERVER_CLIENT);
4476 }
4477
4478 ALIAS_HIDDEN(no_neighbor_route_server_client,
4479 no_neighbor_route_server_client_hidden_cmd,
4480 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4481 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4482 "Configure a neighbor as Route Server client\n")
4483
4484 DEFUN (neighbor_nexthop_local_unchanged,
4485 neighbor_nexthop_local_unchanged_cmd,
4486 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4487 NEIGHBOR_STR
4488 NEIGHBOR_ADDR_STR2
4489 "Configure treatment of outgoing link-local nexthop attribute\n"
4490 "Leave link-local nexthop unchanged for this peer\n")
4491 {
4492 int idx_peer = 1;
4493 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4494 bgp_node_safi(vty),
4495 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4496 }
4497
4498 DEFUN (no_neighbor_nexthop_local_unchanged,
4499 no_neighbor_nexthop_local_unchanged_cmd,
4500 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4501 NO_STR
4502 NEIGHBOR_STR
4503 NEIGHBOR_ADDR_STR2
4504 "Configure treatment of outgoing link-local-nexthop attribute\n"
4505 "Leave link-local nexthop unchanged for this peer\n")
4506 {
4507 int idx_peer = 2;
4508 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4509 bgp_node_afi(vty), bgp_node_safi(vty),
4510 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4511 }
4512
4513 DEFUN (neighbor_attr_unchanged,
4514 neighbor_attr_unchanged_cmd,
4515 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4516 NEIGHBOR_STR
4517 NEIGHBOR_ADDR_STR2
4518 "BGP attribute is propagated unchanged to this neighbor\n"
4519 "As-path attribute\n"
4520 "Nexthop attribute\n"
4521 "Med attribute\n")
4522 {
4523 int idx = 0;
4524 char *peer_str = argv[1]->arg;
4525 struct peer *peer;
4526 uint16_t flags = 0;
4527 afi_t afi = bgp_node_afi(vty);
4528 safi_t safi = bgp_node_safi(vty);
4529
4530 peer = peer_and_group_lookup_vty(vty, peer_str);
4531 if (!peer)
4532 return CMD_WARNING_CONFIG_FAILED;
4533
4534 if (argv_find(argv, argc, "as-path", &idx))
4535 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4536 idx = 0;
4537 if (argv_find(argv, argc, "next-hop", &idx))
4538 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4539 idx = 0;
4540 if (argv_find(argv, argc, "med", &idx))
4541 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4542
4543 /* no flags means all of them! */
4544 if (!flags) {
4545 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4546 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4547 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4548 } else {
4549 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4550 && peer_af_flag_check(peer, afi, safi,
4551 PEER_FLAG_AS_PATH_UNCHANGED)) {
4552 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4553 PEER_FLAG_AS_PATH_UNCHANGED);
4554 }
4555
4556 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4557 && peer_af_flag_check(peer, afi, safi,
4558 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4559 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4560 PEER_FLAG_NEXTHOP_UNCHANGED);
4561 }
4562
4563 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4564 && peer_af_flag_check(peer, afi, safi,
4565 PEER_FLAG_MED_UNCHANGED)) {
4566 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4567 PEER_FLAG_MED_UNCHANGED);
4568 }
4569 }
4570
4571 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4572 }
4573
4574 ALIAS_HIDDEN(
4575 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4576 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4577 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4578 "BGP attribute is propagated unchanged to this neighbor\n"
4579 "As-path attribute\n"
4580 "Nexthop attribute\n"
4581 "Med attribute\n")
4582
4583 DEFUN (no_neighbor_attr_unchanged,
4584 no_neighbor_attr_unchanged_cmd,
4585 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4586 NO_STR
4587 NEIGHBOR_STR
4588 NEIGHBOR_ADDR_STR2
4589 "BGP attribute is propagated unchanged to this neighbor\n"
4590 "As-path attribute\n"
4591 "Nexthop attribute\n"
4592 "Med attribute\n")
4593 {
4594 int idx = 0;
4595 char *peer = argv[2]->arg;
4596 uint16_t flags = 0;
4597
4598 if (argv_find(argv, argc, "as-path", &idx))
4599 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4600 idx = 0;
4601 if (argv_find(argv, argc, "next-hop", &idx))
4602 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4603 idx = 0;
4604 if (argv_find(argv, argc, "med", &idx))
4605 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4606
4607 if (!flags) // no flags means all of them!
4608 {
4609 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4610 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4611 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4612 }
4613
4614 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4615 bgp_node_safi(vty), flags);
4616 }
4617
4618 ALIAS_HIDDEN(
4619 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4620 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4621 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4622 "BGP attribute is propagated unchanged to this neighbor\n"
4623 "As-path attribute\n"
4624 "Nexthop attribute\n"
4625 "Med attribute\n")
4626
4627 /* EBGP multihop configuration. */
4628 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4629 const char *ttl_str)
4630 {
4631 struct peer *peer;
4632 unsigned int ttl;
4633
4634 peer = peer_and_group_lookup_vty(vty, ip_str);
4635 if (!peer)
4636 return CMD_WARNING_CONFIG_FAILED;
4637
4638 if (peer->conf_if)
4639 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4640
4641 if (!ttl_str)
4642 ttl = MAXTTL;
4643 else
4644 ttl = strtoul(ttl_str, NULL, 10);
4645
4646 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4647 }
4648
4649 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4650 {
4651 struct peer *peer;
4652
4653 peer = peer_and_group_lookup_vty(vty, ip_str);
4654 if (!peer)
4655 return CMD_WARNING_CONFIG_FAILED;
4656
4657 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4658 }
4659
4660 /* neighbor ebgp-multihop. */
4661 DEFUN (neighbor_ebgp_multihop,
4662 neighbor_ebgp_multihop_cmd,
4663 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4664 NEIGHBOR_STR
4665 NEIGHBOR_ADDR_STR2
4666 "Allow EBGP neighbors not on directly connected networks\n")
4667 {
4668 int idx_peer = 1;
4669 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4670 }
4671
4672 DEFUN (neighbor_ebgp_multihop_ttl,
4673 neighbor_ebgp_multihop_ttl_cmd,
4674 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4675 NEIGHBOR_STR
4676 NEIGHBOR_ADDR_STR2
4677 "Allow EBGP neighbors not on directly connected networks\n"
4678 "maximum hop count\n")
4679 {
4680 int idx_peer = 1;
4681 int idx_number = 3;
4682 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4683 argv[idx_number]->arg);
4684 }
4685
4686 DEFUN (no_neighbor_ebgp_multihop,
4687 no_neighbor_ebgp_multihop_cmd,
4688 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4689 NO_STR
4690 NEIGHBOR_STR
4691 NEIGHBOR_ADDR_STR2
4692 "Allow EBGP neighbors not on directly connected networks\n"
4693 "maximum hop count\n")
4694 {
4695 int idx_peer = 2;
4696 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4697 }
4698
4699
4700 /* disable-connected-check */
4701 DEFUN (neighbor_disable_connected_check,
4702 neighbor_disable_connected_check_cmd,
4703 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4704 NEIGHBOR_STR
4705 NEIGHBOR_ADDR_STR2
4706 "one-hop away EBGP peer using loopback address\n"
4707 "Enforce EBGP neighbors perform multihop\n")
4708 {
4709 int idx_peer = 1;
4710 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4711 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4712 }
4713
4714 DEFUN (no_neighbor_disable_connected_check,
4715 no_neighbor_disable_connected_check_cmd,
4716 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4717 NO_STR
4718 NEIGHBOR_STR
4719 NEIGHBOR_ADDR_STR2
4720 "one-hop away EBGP peer using loopback address\n"
4721 "Enforce EBGP neighbors perform multihop\n")
4722 {
4723 int idx_peer = 2;
4724 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4725 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4726 }
4727
4728
4729 /* enforce-first-as */
4730 DEFUN (neighbor_enforce_first_as,
4731 neighbor_enforce_first_as_cmd,
4732 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4733 NEIGHBOR_STR
4734 NEIGHBOR_ADDR_STR2
4735 "Enforce the first AS for EBGP routes\n")
4736 {
4737 int idx_peer = 1;
4738
4739 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4740 PEER_FLAG_ENFORCE_FIRST_AS);
4741 }
4742
4743 DEFUN (no_neighbor_enforce_first_as,
4744 no_neighbor_enforce_first_as_cmd,
4745 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4746 NO_STR
4747 NEIGHBOR_STR
4748 NEIGHBOR_ADDR_STR2
4749 "Enforce the first AS for EBGP routes\n")
4750 {
4751 int idx_peer = 2;
4752
4753 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4754 PEER_FLAG_ENFORCE_FIRST_AS);
4755 }
4756
4757
4758 DEFUN (neighbor_description,
4759 neighbor_description_cmd,
4760 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4761 NEIGHBOR_STR
4762 NEIGHBOR_ADDR_STR2
4763 "Neighbor specific description\n"
4764 "Up to 80 characters describing this neighbor\n")
4765 {
4766 int idx_peer = 1;
4767 int idx_line = 3;
4768 struct peer *peer;
4769 char *str;
4770
4771 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4772 if (!peer)
4773 return CMD_WARNING_CONFIG_FAILED;
4774
4775 str = argv_concat(argv, argc, idx_line);
4776
4777 peer_description_set(peer, str);
4778
4779 XFREE(MTYPE_TMP, str);
4780
4781 return CMD_SUCCESS;
4782 }
4783
4784 DEFUN (no_neighbor_description,
4785 no_neighbor_description_cmd,
4786 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4787 NO_STR
4788 NEIGHBOR_STR
4789 NEIGHBOR_ADDR_STR2
4790 "Neighbor specific description\n")
4791 {
4792 int idx_peer = 2;
4793 struct peer *peer;
4794
4795 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4796 if (!peer)
4797 return CMD_WARNING_CONFIG_FAILED;
4798
4799 peer_description_unset(peer);
4800
4801 return CMD_SUCCESS;
4802 }
4803
4804 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4805 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4806 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4807 "Neighbor specific description\n"
4808 "Up to 80 characters describing this neighbor\n")
4809
4810 /* Neighbor update-source. */
4811 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4812 const char *source_str)
4813 {
4814 struct peer *peer;
4815 struct prefix p;
4816 union sockunion su;
4817
4818 peer = peer_and_group_lookup_vty(vty, peer_str);
4819 if (!peer)
4820 return CMD_WARNING_CONFIG_FAILED;
4821
4822 if (peer->conf_if)
4823 return CMD_WARNING;
4824
4825 if (source_str) {
4826 if (str2sockunion(source_str, &su) == 0)
4827 peer_update_source_addr_set(peer, &su);
4828 else {
4829 if (str2prefix(source_str, &p)) {
4830 vty_out(vty,
4831 "%% Invalid update-source, remove prefix length \n");
4832 return CMD_WARNING_CONFIG_FAILED;
4833 } else
4834 peer_update_source_if_set(peer, source_str);
4835 }
4836 } else
4837 peer_update_source_unset(peer);
4838
4839 return CMD_SUCCESS;
4840 }
4841
4842 #define BGP_UPDATE_SOURCE_HELP_STR \
4843 "IPv4 address\n" \
4844 "IPv6 address\n" \
4845 "Interface name (requires zebra to be running)\n"
4846
4847 DEFUN (neighbor_update_source,
4848 neighbor_update_source_cmd,
4849 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4850 NEIGHBOR_STR
4851 NEIGHBOR_ADDR_STR2
4852 "Source of routing updates\n"
4853 BGP_UPDATE_SOURCE_HELP_STR)
4854 {
4855 int idx_peer = 1;
4856 int idx_peer_2 = 3;
4857 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4858 argv[idx_peer_2]->arg);
4859 }
4860
4861 DEFUN (no_neighbor_update_source,
4862 no_neighbor_update_source_cmd,
4863 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4864 NO_STR
4865 NEIGHBOR_STR
4866 NEIGHBOR_ADDR_STR2
4867 "Source of routing updates\n"
4868 BGP_UPDATE_SOURCE_HELP_STR)
4869 {
4870 int idx_peer = 2;
4871 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4872 }
4873
4874 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4875 afi_t afi, safi_t safi,
4876 const char *rmap, int set)
4877 {
4878 int ret;
4879 struct peer *peer;
4880 struct route_map *route_map;
4881
4882 peer = peer_and_group_lookup_vty(vty, peer_str);
4883 if (!peer)
4884 return CMD_WARNING_CONFIG_FAILED;
4885
4886 if (set) {
4887 route_map = route_map_lookup_warn_noexist(vty, rmap);
4888 ret = peer_default_originate_set(peer, afi, safi,
4889 rmap, route_map);
4890 } else
4891 ret = peer_default_originate_unset(peer, afi, safi);
4892
4893 return bgp_vty_return(vty, ret);
4894 }
4895
4896 /* neighbor default-originate. */
4897 DEFUN (neighbor_default_originate,
4898 neighbor_default_originate_cmd,
4899 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4900 NEIGHBOR_STR
4901 NEIGHBOR_ADDR_STR2
4902 "Originate default route to this neighbor\n")
4903 {
4904 int idx_peer = 1;
4905 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4906 bgp_node_afi(vty),
4907 bgp_node_safi(vty), NULL, 1);
4908 }
4909
4910 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4911 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4912 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4913 "Originate default route to this neighbor\n")
4914
4915 DEFUN (neighbor_default_originate_rmap,
4916 neighbor_default_originate_rmap_cmd,
4917 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4918 NEIGHBOR_STR
4919 NEIGHBOR_ADDR_STR2
4920 "Originate default route to this neighbor\n"
4921 "Route-map to specify criteria to originate default\n"
4922 "route-map name\n")
4923 {
4924 int idx_peer = 1;
4925 int idx_word = 4;
4926 return peer_default_originate_set_vty(
4927 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4928 argv[idx_word]->arg, 1);
4929 }
4930
4931 ALIAS_HIDDEN(
4932 neighbor_default_originate_rmap,
4933 neighbor_default_originate_rmap_hidden_cmd,
4934 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4935 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4936 "Originate default route to this neighbor\n"
4937 "Route-map to specify criteria to originate default\n"
4938 "route-map name\n")
4939
4940 DEFUN (no_neighbor_default_originate,
4941 no_neighbor_default_originate_cmd,
4942 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4943 NO_STR
4944 NEIGHBOR_STR
4945 NEIGHBOR_ADDR_STR2
4946 "Originate default route to this neighbor\n"
4947 "Route-map to specify criteria to originate default\n"
4948 "route-map name\n")
4949 {
4950 int idx_peer = 2;
4951 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4952 bgp_node_afi(vty),
4953 bgp_node_safi(vty), NULL, 0);
4954 }
4955
4956 ALIAS_HIDDEN(
4957 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4958 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4959 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4960 "Originate default route to this neighbor\n"
4961 "Route-map to specify criteria to originate default\n"
4962 "route-map name\n")
4963
4964
4965 /* Set neighbor's BGP port. */
4966 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4967 const char *port_str)
4968 {
4969 struct peer *peer;
4970 uint16_t port;
4971 struct servent *sp;
4972
4973 peer = peer_lookup_vty(vty, ip_str);
4974 if (!peer)
4975 return CMD_WARNING_CONFIG_FAILED;
4976
4977 if (!port_str) {
4978 sp = getservbyname("bgp", "tcp");
4979 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4980 } else {
4981 port = strtoul(port_str, NULL, 10);
4982 }
4983
4984 peer_port_set(peer, port);
4985
4986 return CMD_SUCCESS;
4987 }
4988
4989 /* Set specified peer's BGP port. */
4990 DEFUN (neighbor_port,
4991 neighbor_port_cmd,
4992 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4993 NEIGHBOR_STR
4994 NEIGHBOR_ADDR_STR
4995 "Neighbor's BGP port\n"
4996 "TCP port number\n")
4997 {
4998 int idx_ip = 1;
4999 int idx_number = 3;
5000 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
5001 argv[idx_number]->arg);
5002 }
5003
5004 DEFUN (no_neighbor_port,
5005 no_neighbor_port_cmd,
5006 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
5007 NO_STR
5008 NEIGHBOR_STR
5009 NEIGHBOR_ADDR_STR
5010 "Neighbor's BGP port\n"
5011 "TCP port number\n")
5012 {
5013 int idx_ip = 2;
5014 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
5015 }
5016
5017
5018 /* neighbor weight. */
5019 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5020 safi_t safi, const char *weight_str)
5021 {
5022 int ret;
5023 struct peer *peer;
5024 unsigned long weight;
5025
5026 peer = peer_and_group_lookup_vty(vty, ip_str);
5027 if (!peer)
5028 return CMD_WARNING_CONFIG_FAILED;
5029
5030 weight = strtoul(weight_str, NULL, 10);
5031
5032 ret = peer_weight_set(peer, afi, safi, weight);
5033 return bgp_vty_return(vty, ret);
5034 }
5035
5036 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5037 safi_t safi)
5038 {
5039 int ret;
5040 struct peer *peer;
5041
5042 peer = peer_and_group_lookup_vty(vty, ip_str);
5043 if (!peer)
5044 return CMD_WARNING_CONFIG_FAILED;
5045
5046 ret = peer_weight_unset(peer, afi, safi);
5047 return bgp_vty_return(vty, ret);
5048 }
5049
5050 DEFUN (neighbor_weight,
5051 neighbor_weight_cmd,
5052 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5053 NEIGHBOR_STR
5054 NEIGHBOR_ADDR_STR2
5055 "Set default weight for routes from this neighbor\n"
5056 "default weight\n")
5057 {
5058 int idx_peer = 1;
5059 int idx_number = 3;
5060 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5061 bgp_node_safi(vty), argv[idx_number]->arg);
5062 }
5063
5064 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5065 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5066 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5067 "Set default weight for routes from this neighbor\n"
5068 "default weight\n")
5069
5070 DEFUN (no_neighbor_weight,
5071 no_neighbor_weight_cmd,
5072 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5073 NO_STR
5074 NEIGHBOR_STR
5075 NEIGHBOR_ADDR_STR2
5076 "Set default weight for routes from this neighbor\n"
5077 "default weight\n")
5078 {
5079 int idx_peer = 2;
5080 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5081 bgp_node_afi(vty), bgp_node_safi(vty));
5082 }
5083
5084 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5085 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5086 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5087 "Set default weight for routes from this neighbor\n"
5088 "default weight\n")
5089
5090
5091 /* Override capability negotiation. */
5092 DEFUN (neighbor_override_capability,
5093 neighbor_override_capability_cmd,
5094 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5095 NEIGHBOR_STR
5096 NEIGHBOR_ADDR_STR2
5097 "Override capability negotiation result\n")
5098 {
5099 int idx_peer = 1;
5100 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5101 PEER_FLAG_OVERRIDE_CAPABILITY);
5102 }
5103
5104 DEFUN (no_neighbor_override_capability,
5105 no_neighbor_override_capability_cmd,
5106 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5107 NO_STR
5108 NEIGHBOR_STR
5109 NEIGHBOR_ADDR_STR2
5110 "Override capability negotiation result\n")
5111 {
5112 int idx_peer = 2;
5113 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5114 PEER_FLAG_OVERRIDE_CAPABILITY);
5115 }
5116
5117 DEFUN (neighbor_strict_capability,
5118 neighbor_strict_capability_cmd,
5119 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5120 NEIGHBOR_STR
5121 NEIGHBOR_ADDR_STR2
5122 "Strict capability negotiation match\n")
5123 {
5124 int idx_peer = 1;
5125
5126 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5127 PEER_FLAG_STRICT_CAP_MATCH);
5128 }
5129
5130 DEFUN (no_neighbor_strict_capability,
5131 no_neighbor_strict_capability_cmd,
5132 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5133 NO_STR
5134 NEIGHBOR_STR
5135 NEIGHBOR_ADDR_STR2
5136 "Strict capability negotiation match\n")
5137 {
5138 int idx_peer = 2;
5139
5140 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5141 PEER_FLAG_STRICT_CAP_MATCH);
5142 }
5143
5144 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5145 const char *keep_str, const char *hold_str)
5146 {
5147 int ret;
5148 struct peer *peer;
5149 uint32_t keepalive;
5150 uint32_t holdtime;
5151
5152 peer = peer_and_group_lookup_vty(vty, ip_str);
5153 if (!peer)
5154 return CMD_WARNING_CONFIG_FAILED;
5155
5156 keepalive = strtoul(keep_str, NULL, 10);
5157 holdtime = strtoul(hold_str, NULL, 10);
5158
5159 ret = peer_timers_set(peer, keepalive, holdtime);
5160
5161 return bgp_vty_return(vty, ret);
5162 }
5163
5164 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5165 {
5166 int ret;
5167 struct peer *peer;
5168
5169 peer = peer_and_group_lookup_vty(vty, ip_str);
5170 if (!peer)
5171 return CMD_WARNING_CONFIG_FAILED;
5172
5173 ret = peer_timers_unset(peer);
5174
5175 return bgp_vty_return(vty, ret);
5176 }
5177
5178 DEFUN (neighbor_timers,
5179 neighbor_timers_cmd,
5180 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5181 NEIGHBOR_STR
5182 NEIGHBOR_ADDR_STR2
5183 "BGP per neighbor timers\n"
5184 "Keepalive interval\n"
5185 "Holdtime\n")
5186 {
5187 int idx_peer = 1;
5188 int idx_number = 3;
5189 int idx_number_2 = 4;
5190 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5191 argv[idx_number]->arg,
5192 argv[idx_number_2]->arg);
5193 }
5194
5195 DEFUN (no_neighbor_timers,
5196 no_neighbor_timers_cmd,
5197 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5198 NO_STR
5199 NEIGHBOR_STR
5200 NEIGHBOR_ADDR_STR2
5201 "BGP per neighbor timers\n"
5202 "Keepalive interval\n"
5203 "Holdtime\n")
5204 {
5205 int idx_peer = 2;
5206 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5207 }
5208
5209
5210 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5211 const char *time_str)
5212 {
5213 int ret;
5214 struct peer *peer;
5215 uint32_t connect;
5216
5217 peer = peer_and_group_lookup_vty(vty, ip_str);
5218 if (!peer)
5219 return CMD_WARNING_CONFIG_FAILED;
5220
5221 connect = strtoul(time_str, NULL, 10);
5222
5223 ret = peer_timers_connect_set(peer, connect);
5224
5225 return bgp_vty_return(vty, ret);
5226 }
5227
5228 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5229 {
5230 int ret;
5231 struct peer *peer;
5232
5233 peer = peer_and_group_lookup_vty(vty, ip_str);
5234 if (!peer)
5235 return CMD_WARNING_CONFIG_FAILED;
5236
5237 ret = peer_timers_connect_unset(peer);
5238
5239 return bgp_vty_return(vty, ret);
5240 }
5241
5242 DEFUN (neighbor_timers_connect,
5243 neighbor_timers_connect_cmd,
5244 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5245 NEIGHBOR_STR
5246 NEIGHBOR_ADDR_STR2
5247 "BGP per neighbor timers\n"
5248 "BGP connect timer\n"
5249 "Connect timer\n")
5250 {
5251 int idx_peer = 1;
5252 int idx_number = 4;
5253 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5254 argv[idx_number]->arg);
5255 }
5256
5257 DEFUN (no_neighbor_timers_connect,
5258 no_neighbor_timers_connect_cmd,
5259 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5260 NO_STR
5261 NEIGHBOR_STR
5262 NEIGHBOR_ADDR_STR2
5263 "BGP per neighbor timers\n"
5264 "BGP connect timer\n"
5265 "Connect timer\n")
5266 {
5267 int idx_peer = 2;
5268 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5269 }
5270
5271
5272 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5273 const char *time_str, int set)
5274 {
5275 int ret;
5276 struct peer *peer;
5277 uint32_t routeadv = 0;
5278
5279 peer = peer_and_group_lookup_vty(vty, ip_str);
5280 if (!peer)
5281 return CMD_WARNING_CONFIG_FAILED;
5282
5283 if (time_str)
5284 routeadv = strtoul(time_str, NULL, 10);
5285
5286 if (set)
5287 ret = peer_advertise_interval_set(peer, routeadv);
5288 else
5289 ret = peer_advertise_interval_unset(peer);
5290
5291 return bgp_vty_return(vty, ret);
5292 }
5293
5294 DEFUN (neighbor_advertise_interval,
5295 neighbor_advertise_interval_cmd,
5296 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Minimum interval between sending BGP routing updates\n"
5300 "time in seconds\n")
5301 {
5302 int idx_peer = 1;
5303 int idx_number = 3;
5304 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5305 argv[idx_number]->arg, 1);
5306 }
5307
5308 DEFUN (no_neighbor_advertise_interval,
5309 no_neighbor_advertise_interval_cmd,
5310 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5311 NO_STR
5312 NEIGHBOR_STR
5313 NEIGHBOR_ADDR_STR2
5314 "Minimum interval between sending BGP routing updates\n"
5315 "time in seconds\n")
5316 {
5317 int idx_peer = 2;
5318 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5319 }
5320
5321
5322 /* Time to wait before processing route-map updates */
5323 DEFUN (bgp_set_route_map_delay_timer,
5324 bgp_set_route_map_delay_timer_cmd,
5325 "bgp route-map delay-timer (0-600)",
5326 SET_STR
5327 "BGP route-map delay timer\n"
5328 "Time in secs to wait before processing route-map changes\n"
5329 "0 disables the timer, no route updates happen when route-maps change\n")
5330 {
5331 int idx_number = 3;
5332 uint32_t rmap_delay_timer;
5333
5334 if (argv[idx_number]->arg) {
5335 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5336 bm->rmap_update_timer = rmap_delay_timer;
5337
5338 /* if the dynamic update handling is being disabled, and a timer
5339 * is
5340 * running, stop the timer and act as if the timer has already
5341 * fired.
5342 */
5343 if (!rmap_delay_timer && bm->t_rmap_update) {
5344 BGP_TIMER_OFF(bm->t_rmap_update);
5345 thread_execute(bm->master, bgp_route_map_update_timer,
5346 NULL, 0);
5347 }
5348 return CMD_SUCCESS;
5349 } else {
5350 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5351 return CMD_WARNING_CONFIG_FAILED;
5352 }
5353 }
5354
5355 DEFUN (no_bgp_set_route_map_delay_timer,
5356 no_bgp_set_route_map_delay_timer_cmd,
5357 "no bgp route-map delay-timer [(0-600)]",
5358 NO_STR
5359 BGP_STR
5360 "Default BGP route-map delay timer\n"
5361 "Reset to default time to wait for processing route-map changes\n"
5362 "0 disables the timer, no route updates happen when route-maps change\n")
5363 {
5364
5365 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5366
5367 return CMD_SUCCESS;
5368 }
5369
5370
5371 /* neighbor interface */
5372 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5373 const char *str)
5374 {
5375 struct peer *peer;
5376
5377 peer = peer_lookup_vty(vty, ip_str);
5378 if (!peer || peer->conf_if) {
5379 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5380 return CMD_WARNING_CONFIG_FAILED;
5381 }
5382
5383 if (str)
5384 peer_interface_set(peer, str);
5385 else
5386 peer_interface_unset(peer);
5387
5388 return CMD_SUCCESS;
5389 }
5390
5391 DEFUN (neighbor_interface,
5392 neighbor_interface_cmd,
5393 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5394 NEIGHBOR_STR
5395 NEIGHBOR_ADDR_STR
5396 "Interface\n"
5397 "Interface name\n")
5398 {
5399 int idx_ip = 1;
5400 int idx_word = 3;
5401 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5402 }
5403
5404 DEFUN (no_neighbor_interface,
5405 no_neighbor_interface_cmd,
5406 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5407 NO_STR
5408 NEIGHBOR_STR
5409 NEIGHBOR_ADDR_STR2
5410 "Interface\n"
5411 "Interface name\n")
5412 {
5413 int idx_peer = 2;
5414 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5415 }
5416
5417 DEFUN (neighbor_distribute_list,
5418 neighbor_distribute_list_cmd,
5419 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5420 NEIGHBOR_STR
5421 NEIGHBOR_ADDR_STR2
5422 "Filter updates to/from this neighbor\n"
5423 "IP access-list number\n"
5424 "IP access-list number (expanded range)\n"
5425 "IP Access-list name\n"
5426 "Filter incoming updates\n"
5427 "Filter outgoing updates\n")
5428 {
5429 int idx_peer = 1;
5430 int idx_acl = 3;
5431 int direct, ret;
5432 struct peer *peer;
5433
5434 const char *pstr = argv[idx_peer]->arg;
5435 const char *acl = argv[idx_acl]->arg;
5436 const char *inout = argv[argc - 1]->text;
5437
5438 peer = peer_and_group_lookup_vty(vty, pstr);
5439 if (!peer)
5440 return CMD_WARNING_CONFIG_FAILED;
5441
5442 /* Check filter direction. */
5443 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5444 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5445 direct, acl);
5446
5447 return bgp_vty_return(vty, ret);
5448 }
5449
5450 ALIAS_HIDDEN(
5451 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5452 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5453 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5454 "Filter updates to/from this neighbor\n"
5455 "IP access-list number\n"
5456 "IP access-list number (expanded range)\n"
5457 "IP Access-list name\n"
5458 "Filter incoming updates\n"
5459 "Filter outgoing updates\n")
5460
5461 DEFUN (no_neighbor_distribute_list,
5462 no_neighbor_distribute_list_cmd,
5463 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5464 NO_STR
5465 NEIGHBOR_STR
5466 NEIGHBOR_ADDR_STR2
5467 "Filter updates to/from this neighbor\n"
5468 "IP access-list number\n"
5469 "IP access-list number (expanded range)\n"
5470 "IP Access-list name\n"
5471 "Filter incoming updates\n"
5472 "Filter outgoing updates\n")
5473 {
5474 int idx_peer = 2;
5475 int direct, ret;
5476 struct peer *peer;
5477
5478 const char *pstr = argv[idx_peer]->arg;
5479 const char *inout = argv[argc - 1]->text;
5480
5481 peer = peer_and_group_lookup_vty(vty, pstr);
5482 if (!peer)
5483 return CMD_WARNING_CONFIG_FAILED;
5484
5485 /* Check filter direction. */
5486 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5487 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5488 direct);
5489
5490 return bgp_vty_return(vty, ret);
5491 }
5492
5493 ALIAS_HIDDEN(
5494 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5495 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5496 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5497 "Filter updates to/from this neighbor\n"
5498 "IP access-list number\n"
5499 "IP access-list number (expanded range)\n"
5500 "IP Access-list name\n"
5501 "Filter incoming updates\n"
5502 "Filter outgoing updates\n")
5503
5504 /* Set prefix list to the peer. */
5505 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5506 afi_t afi, safi_t safi,
5507 const char *name_str,
5508 const char *direct_str)
5509 {
5510 int ret;
5511 int direct = FILTER_IN;
5512 struct peer *peer;
5513
5514 peer = peer_and_group_lookup_vty(vty, ip_str);
5515 if (!peer)
5516 return CMD_WARNING_CONFIG_FAILED;
5517
5518 /* Check filter direction. */
5519 if (strncmp(direct_str, "i", 1) == 0)
5520 direct = FILTER_IN;
5521 else if (strncmp(direct_str, "o", 1) == 0)
5522 direct = FILTER_OUT;
5523
5524 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5525
5526 return bgp_vty_return(vty, ret);
5527 }
5528
5529 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5530 afi_t afi, safi_t safi,
5531 const char *direct_str)
5532 {
5533 int ret;
5534 struct peer *peer;
5535 int direct = FILTER_IN;
5536
5537 peer = peer_and_group_lookup_vty(vty, ip_str);
5538 if (!peer)
5539 return CMD_WARNING_CONFIG_FAILED;
5540
5541 /* Check filter direction. */
5542 if (strncmp(direct_str, "i", 1) == 0)
5543 direct = FILTER_IN;
5544 else if (strncmp(direct_str, "o", 1) == 0)
5545 direct = FILTER_OUT;
5546
5547 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5548
5549 return bgp_vty_return(vty, ret);
5550 }
5551
5552 DEFUN (neighbor_prefix_list,
5553 neighbor_prefix_list_cmd,
5554 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5555 NEIGHBOR_STR
5556 NEIGHBOR_ADDR_STR2
5557 "Filter updates to/from this neighbor\n"
5558 "Name of a prefix list\n"
5559 "Filter incoming updates\n"
5560 "Filter outgoing updates\n")
5561 {
5562 int idx_peer = 1;
5563 int idx_word = 3;
5564 int idx_in_out = 4;
5565 return peer_prefix_list_set_vty(
5566 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5567 argv[idx_word]->arg, argv[idx_in_out]->arg);
5568 }
5569
5570 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5571 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5572 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5573 "Filter updates to/from this neighbor\n"
5574 "Name of a prefix list\n"
5575 "Filter incoming updates\n"
5576 "Filter outgoing updates\n")
5577
5578 DEFUN (no_neighbor_prefix_list,
5579 no_neighbor_prefix_list_cmd,
5580 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5581 NO_STR
5582 NEIGHBOR_STR
5583 NEIGHBOR_ADDR_STR2
5584 "Filter updates to/from this neighbor\n"
5585 "Name of a prefix list\n"
5586 "Filter incoming updates\n"
5587 "Filter outgoing updates\n")
5588 {
5589 int idx_peer = 2;
5590 int idx_in_out = 5;
5591 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5592 bgp_node_afi(vty), bgp_node_safi(vty),
5593 argv[idx_in_out]->arg);
5594 }
5595
5596 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5597 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5598 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5599 "Filter updates to/from this neighbor\n"
5600 "Name of a prefix list\n"
5601 "Filter incoming updates\n"
5602 "Filter outgoing updates\n")
5603
5604 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5605 safi_t safi, const char *name_str,
5606 const char *direct_str)
5607 {
5608 int ret;
5609 struct peer *peer;
5610 int direct = FILTER_IN;
5611
5612 peer = peer_and_group_lookup_vty(vty, ip_str);
5613 if (!peer)
5614 return CMD_WARNING_CONFIG_FAILED;
5615
5616 /* Check filter direction. */
5617 if (strncmp(direct_str, "i", 1) == 0)
5618 direct = FILTER_IN;
5619 else if (strncmp(direct_str, "o", 1) == 0)
5620 direct = FILTER_OUT;
5621
5622 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5623
5624 return bgp_vty_return(vty, ret);
5625 }
5626
5627 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5628 safi_t safi, const char *direct_str)
5629 {
5630 int ret;
5631 struct peer *peer;
5632 int direct = FILTER_IN;
5633
5634 peer = peer_and_group_lookup_vty(vty, ip_str);
5635 if (!peer)
5636 return CMD_WARNING_CONFIG_FAILED;
5637
5638 /* Check filter direction. */
5639 if (strncmp(direct_str, "i", 1) == 0)
5640 direct = FILTER_IN;
5641 else if (strncmp(direct_str, "o", 1) == 0)
5642 direct = FILTER_OUT;
5643
5644 ret = peer_aslist_unset(peer, afi, safi, direct);
5645
5646 return bgp_vty_return(vty, ret);
5647 }
5648
5649 DEFUN (neighbor_filter_list,
5650 neighbor_filter_list_cmd,
5651 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5652 NEIGHBOR_STR
5653 NEIGHBOR_ADDR_STR2
5654 "Establish BGP filters\n"
5655 "AS path access-list name\n"
5656 "Filter incoming routes\n"
5657 "Filter outgoing routes\n")
5658 {
5659 int idx_peer = 1;
5660 int idx_word = 3;
5661 int idx_in_out = 4;
5662 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5663 bgp_node_safi(vty), argv[idx_word]->arg,
5664 argv[idx_in_out]->arg);
5665 }
5666
5667 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5668 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5669 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5670 "Establish BGP filters\n"
5671 "AS path access-list name\n"
5672 "Filter incoming routes\n"
5673 "Filter outgoing routes\n")
5674
5675 DEFUN (no_neighbor_filter_list,
5676 no_neighbor_filter_list_cmd,
5677 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5678 NO_STR
5679 NEIGHBOR_STR
5680 NEIGHBOR_ADDR_STR2
5681 "Establish BGP filters\n"
5682 "AS path access-list name\n"
5683 "Filter incoming routes\n"
5684 "Filter outgoing routes\n")
5685 {
5686 int idx_peer = 2;
5687 int idx_in_out = 5;
5688 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5689 bgp_node_afi(vty), bgp_node_safi(vty),
5690 argv[idx_in_out]->arg);
5691 }
5692
5693 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5694 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5695 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5696 "Establish BGP filters\n"
5697 "AS path access-list name\n"
5698 "Filter incoming routes\n"
5699 "Filter outgoing routes\n")
5700
5701 /* Set route-map to the peer. */
5702 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5703 afi_t afi, safi_t safi, const char *name_str,
5704 const char *direct_str)
5705 {
5706 int ret;
5707 struct peer *peer;
5708 int direct = RMAP_IN;
5709 struct route_map *route_map;
5710
5711 peer = peer_and_group_lookup_vty(vty, ip_str);
5712 if (!peer)
5713 return CMD_WARNING_CONFIG_FAILED;
5714
5715 /* Check filter direction. */
5716 if (strncmp(direct_str, "in", 2) == 0)
5717 direct = RMAP_IN;
5718 else if (strncmp(direct_str, "o", 1) == 0)
5719 direct = RMAP_OUT;
5720
5721 route_map = route_map_lookup_warn_noexist(vty, name_str);
5722 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5723
5724 return bgp_vty_return(vty, ret);
5725 }
5726
5727 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5728 afi_t afi, safi_t safi,
5729 const char *direct_str)
5730 {
5731 int ret;
5732 struct peer *peer;
5733 int direct = RMAP_IN;
5734
5735 peer = peer_and_group_lookup_vty(vty, ip_str);
5736 if (!peer)
5737 return CMD_WARNING_CONFIG_FAILED;
5738
5739 /* Check filter direction. */
5740 if (strncmp(direct_str, "in", 2) == 0)
5741 direct = RMAP_IN;
5742 else if (strncmp(direct_str, "o", 1) == 0)
5743 direct = RMAP_OUT;
5744
5745 ret = peer_route_map_unset(peer, afi, safi, direct);
5746
5747 return bgp_vty_return(vty, ret);
5748 }
5749
5750 DEFUN (neighbor_route_map,
5751 neighbor_route_map_cmd,
5752 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5753 NEIGHBOR_STR
5754 NEIGHBOR_ADDR_STR2
5755 "Apply route map to neighbor\n"
5756 "Name of route map\n"
5757 "Apply map to incoming routes\n"
5758 "Apply map to outbound routes\n")
5759 {
5760 int idx_peer = 1;
5761 int idx_word = 3;
5762 int idx_in_out = 4;
5763 return peer_route_map_set_vty(
5764 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5765 argv[idx_word]->arg, argv[idx_in_out]->arg);
5766 }
5767
5768 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5769 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5770 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5771 "Apply route map to neighbor\n"
5772 "Name of route map\n"
5773 "Apply map to incoming routes\n"
5774 "Apply map to outbound routes\n")
5775
5776 DEFUN (no_neighbor_route_map,
5777 no_neighbor_route_map_cmd,
5778 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5779 NO_STR
5780 NEIGHBOR_STR
5781 NEIGHBOR_ADDR_STR2
5782 "Apply route map to neighbor\n"
5783 "Name of route map\n"
5784 "Apply map to incoming routes\n"
5785 "Apply map to outbound routes\n")
5786 {
5787 int idx_peer = 2;
5788 int idx_in_out = 5;
5789 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5790 bgp_node_afi(vty), bgp_node_safi(vty),
5791 argv[idx_in_out]->arg);
5792 }
5793
5794 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5795 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5796 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5797 "Apply route map to neighbor\n"
5798 "Name of route map\n"
5799 "Apply map to incoming routes\n"
5800 "Apply map to outbound routes\n")
5801
5802 /* Set unsuppress-map to the peer. */
5803 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5804 afi_t afi, safi_t safi,
5805 const char *name_str)
5806 {
5807 int ret;
5808 struct peer *peer;
5809 struct route_map *route_map;
5810
5811 peer = peer_and_group_lookup_vty(vty, ip_str);
5812 if (!peer)
5813 return CMD_WARNING_CONFIG_FAILED;
5814
5815 route_map = route_map_lookup_warn_noexist(vty, name_str);
5816 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5817
5818 return bgp_vty_return(vty, ret);
5819 }
5820
5821 /* Unset route-map from the peer. */
5822 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5823 afi_t afi, safi_t safi)
5824 {
5825 int ret;
5826 struct peer *peer;
5827
5828 peer = peer_and_group_lookup_vty(vty, ip_str);
5829 if (!peer)
5830 return CMD_WARNING_CONFIG_FAILED;
5831
5832 ret = peer_unsuppress_map_unset(peer, afi, safi);
5833
5834 return bgp_vty_return(vty, ret);
5835 }
5836
5837 DEFUN (neighbor_unsuppress_map,
5838 neighbor_unsuppress_map_cmd,
5839 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5840 NEIGHBOR_STR
5841 NEIGHBOR_ADDR_STR2
5842 "Route-map to selectively unsuppress suppressed routes\n"
5843 "Name of route map\n")
5844 {
5845 int idx_peer = 1;
5846 int idx_word = 3;
5847 return peer_unsuppress_map_set_vty(
5848 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5849 argv[idx_word]->arg);
5850 }
5851
5852 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5853 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5854 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5855 "Route-map to selectively unsuppress suppressed routes\n"
5856 "Name of route map\n")
5857
5858 DEFUN (no_neighbor_unsuppress_map,
5859 no_neighbor_unsuppress_map_cmd,
5860 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5861 NO_STR
5862 NEIGHBOR_STR
5863 NEIGHBOR_ADDR_STR2
5864 "Route-map to selectively unsuppress suppressed routes\n"
5865 "Name of route map\n")
5866 {
5867 int idx_peer = 2;
5868 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5869 bgp_node_afi(vty),
5870 bgp_node_safi(vty));
5871 }
5872
5873 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5874 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5875 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5876 "Route-map to selectively unsuppress suppressed routes\n"
5877 "Name of route map\n")
5878
5879 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5880 afi_t afi, safi_t safi,
5881 const char *num_str,
5882 const char *threshold_str, int warning,
5883 const char *restart_str)
5884 {
5885 int ret;
5886 struct peer *peer;
5887 uint32_t max;
5888 uint8_t threshold;
5889 uint16_t restart;
5890
5891 peer = peer_and_group_lookup_vty(vty, ip_str);
5892 if (!peer)
5893 return CMD_WARNING_CONFIG_FAILED;
5894
5895 max = strtoul(num_str, NULL, 10);
5896 if (threshold_str)
5897 threshold = atoi(threshold_str);
5898 else
5899 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5900
5901 if (restart_str)
5902 restart = atoi(restart_str);
5903 else
5904 restart = 0;
5905
5906 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5907 restart);
5908
5909 return bgp_vty_return(vty, ret);
5910 }
5911
5912 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5913 afi_t afi, safi_t safi)
5914 {
5915 int ret;
5916 struct peer *peer;
5917
5918 peer = peer_and_group_lookup_vty(vty, ip_str);
5919 if (!peer)
5920 return CMD_WARNING_CONFIG_FAILED;
5921
5922 ret = peer_maximum_prefix_unset(peer, afi, safi);
5923
5924 return bgp_vty_return(vty, ret);
5925 }
5926
5927 /* Maximum number of prefix configuration. prefix count is different
5928 for each peer configuration. So this configuration can be set for
5929 each peer configuration. */
5930 DEFUN (neighbor_maximum_prefix,
5931 neighbor_maximum_prefix_cmd,
5932 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5933 NEIGHBOR_STR
5934 NEIGHBOR_ADDR_STR2
5935 "Maximum number of prefix accept from this peer\n"
5936 "maximum no. of prefix limit\n")
5937 {
5938 int idx_peer = 1;
5939 int idx_number = 3;
5940 return peer_maximum_prefix_set_vty(
5941 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5942 argv[idx_number]->arg, NULL, 0, NULL);
5943 }
5944
5945 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5946 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5947 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5948 "Maximum number of prefix accept from this peer\n"
5949 "maximum no. of prefix limit\n")
5950
5951 DEFUN (neighbor_maximum_prefix_threshold,
5952 neighbor_maximum_prefix_threshold_cmd,
5953 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5954 NEIGHBOR_STR
5955 NEIGHBOR_ADDR_STR2
5956 "Maximum number of prefix accept from this peer\n"
5957 "maximum no. of prefix limit\n"
5958 "Threshold value (%) at which to generate a warning msg\n")
5959 {
5960 int idx_peer = 1;
5961 int idx_number = 3;
5962 int idx_number_2 = 4;
5963 return peer_maximum_prefix_set_vty(
5964 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5965 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5966 }
5967
5968 ALIAS_HIDDEN(
5969 neighbor_maximum_prefix_threshold,
5970 neighbor_maximum_prefix_threshold_hidden_cmd,
5971 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5972 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5973 "Maximum number of prefix accept from this peer\n"
5974 "maximum no. of prefix limit\n"
5975 "Threshold value (%) at which to generate a warning msg\n")
5976
5977 DEFUN (neighbor_maximum_prefix_warning,
5978 neighbor_maximum_prefix_warning_cmd,
5979 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5980 NEIGHBOR_STR
5981 NEIGHBOR_ADDR_STR2
5982 "Maximum number of prefix accept from this peer\n"
5983 "maximum no. of prefix limit\n"
5984 "Only give warning message when limit is exceeded\n")
5985 {
5986 int idx_peer = 1;
5987 int idx_number = 3;
5988 return peer_maximum_prefix_set_vty(
5989 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5990 argv[idx_number]->arg, NULL, 1, NULL);
5991 }
5992
5993 ALIAS_HIDDEN(
5994 neighbor_maximum_prefix_warning,
5995 neighbor_maximum_prefix_warning_hidden_cmd,
5996 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5997 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5998 "Maximum number of prefix accept from this peer\n"
5999 "maximum no. of prefix limit\n"
6000 "Only give warning message when limit is exceeded\n")
6001
6002 DEFUN (neighbor_maximum_prefix_threshold_warning,
6003 neighbor_maximum_prefix_threshold_warning_cmd,
6004 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
6007 "Maximum number of prefix accept from this peer\n"
6008 "maximum no. of prefix limit\n"
6009 "Threshold value (%) at which to generate a warning msg\n"
6010 "Only give warning message when limit is exceeded\n")
6011 {
6012 int idx_peer = 1;
6013 int idx_number = 3;
6014 int idx_number_2 = 4;
6015 return peer_maximum_prefix_set_vty(
6016 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6017 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
6018 }
6019
6020 ALIAS_HIDDEN(
6021 neighbor_maximum_prefix_threshold_warning,
6022 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6023 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6024 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6025 "Maximum number of prefix accept from this peer\n"
6026 "maximum no. of prefix limit\n"
6027 "Threshold value (%) at which to generate a warning msg\n"
6028 "Only give warning message when limit is exceeded\n")
6029
6030 DEFUN (neighbor_maximum_prefix_restart,
6031 neighbor_maximum_prefix_restart_cmd,
6032 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "Maximum number of prefix accept from this peer\n"
6036 "maximum no. of prefix limit\n"
6037 "Restart bgp connection after limit is exceeded\n"
6038 "Restart interval in minutes\n")
6039 {
6040 int idx_peer = 1;
6041 int idx_number = 3;
6042 int idx_number_2 = 5;
6043 return peer_maximum_prefix_set_vty(
6044 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6045 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6046 }
6047
6048 ALIAS_HIDDEN(
6049 neighbor_maximum_prefix_restart,
6050 neighbor_maximum_prefix_restart_hidden_cmd,
6051 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6052 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6053 "Maximum number of prefix accept from this peer\n"
6054 "maximum no. of prefix limit\n"
6055 "Restart bgp connection after limit is exceeded\n"
6056 "Restart interval in minutes\n")
6057
6058 DEFUN (neighbor_maximum_prefix_threshold_restart,
6059 neighbor_maximum_prefix_threshold_restart_cmd,
6060 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6061 NEIGHBOR_STR
6062 NEIGHBOR_ADDR_STR2
6063 "Maximum number of prefixes to accept from this peer\n"
6064 "maximum no. of prefix limit\n"
6065 "Threshold value (%) at which to generate a warning msg\n"
6066 "Restart bgp connection after limit is exceeded\n"
6067 "Restart interval in minutes\n")
6068 {
6069 int idx_peer = 1;
6070 int idx_number = 3;
6071 int idx_number_2 = 4;
6072 int idx_number_3 = 6;
6073 return peer_maximum_prefix_set_vty(
6074 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6075 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6076 argv[idx_number_3]->arg);
6077 }
6078
6079 ALIAS_HIDDEN(
6080 neighbor_maximum_prefix_threshold_restart,
6081 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6082 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6083 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6084 "Maximum number of prefixes to accept from this peer\n"
6085 "maximum no. of prefix limit\n"
6086 "Threshold value (%) at which to generate a warning msg\n"
6087 "Restart bgp connection after limit is exceeded\n"
6088 "Restart interval in minutes\n")
6089
6090 DEFUN (no_neighbor_maximum_prefix,
6091 no_neighbor_maximum_prefix_cmd,
6092 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6093 NO_STR
6094 NEIGHBOR_STR
6095 NEIGHBOR_ADDR_STR2
6096 "Maximum number of prefixes to accept from this peer\n"
6097 "maximum no. of prefix limit\n"
6098 "Threshold value (%) at which to generate a warning msg\n"
6099 "Restart bgp connection after limit is exceeded\n"
6100 "Restart interval in minutes\n"
6101 "Only give warning message when limit is exceeded\n")
6102 {
6103 int idx_peer = 2;
6104 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6105 bgp_node_afi(vty),
6106 bgp_node_safi(vty));
6107 }
6108
6109 ALIAS_HIDDEN(
6110 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6111 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6112 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6113 "Maximum number of prefixes to accept from this peer\n"
6114 "maximum no. of prefix limit\n"
6115 "Threshold value (%) at which to generate a warning msg\n"
6116 "Restart bgp connection after limit is exceeded\n"
6117 "Restart interval in minutes\n"
6118 "Only give warning message when limit is exceeded\n")
6119
6120
6121 /* "neighbor allowas-in" */
6122 DEFUN (neighbor_allowas_in,
6123 neighbor_allowas_in_cmd,
6124 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6125 NEIGHBOR_STR
6126 NEIGHBOR_ADDR_STR2
6127 "Accept as-path with my AS present in it\n"
6128 "Number of occurences of AS number\n"
6129 "Only accept my AS in the as-path if the route was originated in my AS\n")
6130 {
6131 int idx_peer = 1;
6132 int idx_number_origin = 3;
6133 int ret;
6134 int origin = 0;
6135 struct peer *peer;
6136 int allow_num = 0;
6137
6138 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6139 if (!peer)
6140 return CMD_WARNING_CONFIG_FAILED;
6141
6142 if (argc <= idx_number_origin)
6143 allow_num = 3;
6144 else {
6145 if (argv[idx_number_origin]->type == WORD_TKN)
6146 origin = 1;
6147 else
6148 allow_num = atoi(argv[idx_number_origin]->arg);
6149 }
6150
6151 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6152 allow_num, origin);
6153
6154 return bgp_vty_return(vty, ret);
6155 }
6156
6157 ALIAS_HIDDEN(
6158 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6159 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6160 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6161 "Accept as-path with my AS present in it\n"
6162 "Number of occurences of AS number\n"
6163 "Only accept my AS in the as-path if the route was originated in my AS\n")
6164
6165 DEFUN (no_neighbor_allowas_in,
6166 no_neighbor_allowas_in_cmd,
6167 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6168 NO_STR
6169 NEIGHBOR_STR
6170 NEIGHBOR_ADDR_STR2
6171 "allow local ASN appears in aspath attribute\n"
6172 "Number of occurences of AS number\n"
6173 "Only accept my AS in the as-path if the route was originated in my AS\n")
6174 {
6175 int idx_peer = 2;
6176 int ret;
6177 struct peer *peer;
6178
6179 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6180 if (!peer)
6181 return CMD_WARNING_CONFIG_FAILED;
6182
6183 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6184 bgp_node_safi(vty));
6185
6186 return bgp_vty_return(vty, ret);
6187 }
6188
6189 ALIAS_HIDDEN(
6190 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6191 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6192 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6193 "allow local ASN appears in aspath attribute\n"
6194 "Number of occurences of AS number\n"
6195 "Only accept my AS in the as-path if the route was originated in my AS\n")
6196
6197 DEFUN (neighbor_ttl_security,
6198 neighbor_ttl_security_cmd,
6199 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6200 NEIGHBOR_STR
6201 NEIGHBOR_ADDR_STR2
6202 "BGP ttl-security parameters\n"
6203 "Specify the maximum number of hops to the BGP peer\n"
6204 "Number of hops to BGP peer\n")
6205 {
6206 int idx_peer = 1;
6207 int idx_number = 4;
6208 struct peer *peer;
6209 int gtsm_hops;
6210
6211 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6212 if (!peer)
6213 return CMD_WARNING_CONFIG_FAILED;
6214
6215 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6216
6217 /*
6218 * If 'neighbor swpX', then this is for directly connected peers,
6219 * we should not accept a ttl-security hops value greater than 1.
6220 */
6221 if (peer->conf_if && (gtsm_hops > 1)) {
6222 vty_out(vty,
6223 "%s is directly connected peer, hops cannot exceed 1\n",
6224 argv[idx_peer]->arg);
6225 return CMD_WARNING_CONFIG_FAILED;
6226 }
6227
6228 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6229 }
6230
6231 DEFUN (no_neighbor_ttl_security,
6232 no_neighbor_ttl_security_cmd,
6233 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6234 NO_STR
6235 NEIGHBOR_STR
6236 NEIGHBOR_ADDR_STR2
6237 "BGP ttl-security parameters\n"
6238 "Specify the maximum number of hops to the BGP peer\n"
6239 "Number of hops to BGP peer\n")
6240 {
6241 int idx_peer = 2;
6242 struct peer *peer;
6243
6244 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6245 if (!peer)
6246 return CMD_WARNING_CONFIG_FAILED;
6247
6248 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6249 }
6250
6251 DEFUN (neighbor_addpath_tx_all_paths,
6252 neighbor_addpath_tx_all_paths_cmd,
6253 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6254 NEIGHBOR_STR
6255 NEIGHBOR_ADDR_STR2
6256 "Use addpath to advertise all paths to a neighbor\n")
6257 {
6258 int idx_peer = 1;
6259 struct peer *peer;
6260
6261 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6262 if (!peer)
6263 return CMD_WARNING_CONFIG_FAILED;
6264
6265 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6266 BGP_ADDPATH_ALL);
6267 return CMD_SUCCESS;
6268 }
6269
6270 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6271 neighbor_addpath_tx_all_paths_hidden_cmd,
6272 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6273 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6274 "Use addpath to advertise all paths to a neighbor\n")
6275
6276 DEFUN (no_neighbor_addpath_tx_all_paths,
6277 no_neighbor_addpath_tx_all_paths_cmd,
6278 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6279 NO_STR
6280 NEIGHBOR_STR
6281 NEIGHBOR_ADDR_STR2
6282 "Use addpath to advertise all paths to a neighbor\n")
6283 {
6284 int idx_peer = 2;
6285 struct peer *peer;
6286
6287 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6288 if (!peer)
6289 return CMD_WARNING_CONFIG_FAILED;
6290
6291 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6292 != BGP_ADDPATH_ALL) {
6293 vty_out(vty,
6294 "%% Peer not currently configured to transmit all paths.");
6295 return CMD_WARNING_CONFIG_FAILED;
6296 }
6297
6298 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6299 BGP_ADDPATH_NONE);
6300
6301 return CMD_SUCCESS;
6302 }
6303
6304 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6305 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6306 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6307 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6308 "Use addpath to advertise all paths to a neighbor\n")
6309
6310 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6311 neighbor_addpath_tx_bestpath_per_as_cmd,
6312 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6313 NEIGHBOR_STR
6314 NEIGHBOR_ADDR_STR2
6315 "Use addpath to advertise the bestpath per each neighboring AS\n")
6316 {
6317 int idx_peer = 1;
6318 struct peer *peer;
6319
6320 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6321 if (!peer)
6322 return CMD_WARNING_CONFIG_FAILED;
6323
6324 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6325 BGP_ADDPATH_BEST_PER_AS);
6326
6327 return CMD_SUCCESS;
6328 }
6329
6330 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6331 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6332 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6333 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6334 "Use addpath to advertise the bestpath per each neighboring AS\n")
6335
6336 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6337 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6338 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6339 NO_STR
6340 NEIGHBOR_STR
6341 NEIGHBOR_ADDR_STR2
6342 "Use addpath to advertise the bestpath per each neighboring AS\n")
6343 {
6344 int idx_peer = 2;
6345 struct peer *peer;
6346
6347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6348 if (!peer)
6349 return CMD_WARNING_CONFIG_FAILED;
6350
6351 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6352 != BGP_ADDPATH_BEST_PER_AS) {
6353 vty_out(vty,
6354 "%% Peer not currently configured to transmit all best path per as.");
6355 return CMD_WARNING_CONFIG_FAILED;
6356 }
6357
6358 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6359 BGP_ADDPATH_NONE);
6360
6361 return CMD_SUCCESS;
6362 }
6363
6364 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6365 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6366 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6367 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6368 "Use addpath to advertise the bestpath per each neighboring AS\n")
6369
6370 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6371 struct ecommunity **list)
6372 {
6373 struct ecommunity *ecom = NULL;
6374 struct ecommunity *ecomadd;
6375
6376 for (; argc; --argc, ++argv) {
6377
6378 ecomadd = ecommunity_str2com(argv[0]->arg,
6379 ECOMMUNITY_ROUTE_TARGET, 0);
6380 if (!ecomadd) {
6381 vty_out(vty, "Malformed community-list value\n");
6382 if (ecom)
6383 ecommunity_free(&ecom);
6384 return CMD_WARNING_CONFIG_FAILED;
6385 }
6386
6387 if (ecom) {
6388 ecommunity_merge(ecom, ecomadd);
6389 ecommunity_free(&ecomadd);
6390 } else {
6391 ecom = ecomadd;
6392 }
6393 }
6394
6395 if (*list) {
6396 ecommunity_free(&*list);
6397 }
6398 *list = ecom;
6399
6400 return CMD_SUCCESS;
6401 }
6402
6403 /*
6404 * v2vimport is true if we are handling a `import vrf ...` command
6405 */
6406 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6407 {
6408 afi_t afi;
6409
6410 switch (vty->node) {
6411 case BGP_IPV4_NODE:
6412 afi = AFI_IP;
6413 break;
6414 case BGP_IPV6_NODE:
6415 afi = AFI_IP6;
6416 break;
6417 default:
6418 vty_out(vty,
6419 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6420 return AFI_MAX;
6421 }
6422
6423 if (!v2vimport) {
6424 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6425 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6426 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6427 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6428 vty_out(vty,
6429 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6430 return AFI_MAX;
6431 }
6432 } else {
6433 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6434 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6435 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6436 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6437 vty_out(vty,
6438 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6439 return AFI_MAX;
6440 }
6441 }
6442 return afi;
6443 }
6444
6445 DEFPY (af_rd_vpn_export,
6446 af_rd_vpn_export_cmd,
6447 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6448 NO_STR
6449 "Specify route distinguisher\n"
6450 "Between current address-family and vpn\n"
6451 "For routes leaked from current address-family to vpn\n"
6452 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6453 {
6454 VTY_DECLVAR_CONTEXT(bgp, bgp);
6455 struct prefix_rd prd;
6456 int ret;
6457 afi_t afi;
6458 int idx = 0;
6459 int yes = 1;
6460
6461 if (argv_find(argv, argc, "no", &idx))
6462 yes = 0;
6463
6464 if (yes) {
6465 ret = str2prefix_rd(rd_str, &prd);
6466 if (!ret) {
6467 vty_out(vty, "%% Malformed rd\n");
6468 return CMD_WARNING_CONFIG_FAILED;
6469 }
6470 }
6471
6472 afi = vpn_policy_getafi(vty, bgp, false);
6473 if (afi == AFI_MAX)
6474 return CMD_WARNING_CONFIG_FAILED;
6475
6476 /*
6477 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6478 */
6479 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6480 bgp_get_default(), bgp);
6481
6482 if (yes) {
6483 bgp->vpn_policy[afi].tovpn_rd = prd;
6484 SET_FLAG(bgp->vpn_policy[afi].flags,
6485 BGP_VPN_POLICY_TOVPN_RD_SET);
6486 } else {
6487 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6488 BGP_VPN_POLICY_TOVPN_RD_SET);
6489 }
6490
6491 /* post-change: re-export vpn routes */
6492 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6493 bgp_get_default(), bgp);
6494
6495 return CMD_SUCCESS;
6496 }
6497
6498 ALIAS (af_rd_vpn_export,
6499 af_no_rd_vpn_export_cmd,
6500 "no rd vpn export",
6501 NO_STR
6502 "Specify route distinguisher\n"
6503 "Between current address-family and vpn\n"
6504 "For routes leaked from current address-family to vpn\n")
6505
6506 DEFPY (af_label_vpn_export,
6507 af_label_vpn_export_cmd,
6508 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6509 NO_STR
6510 "label value for VRF\n"
6511 "Between current address-family and vpn\n"
6512 "For routes leaked from current address-family to vpn\n"
6513 "Label Value <0-1048575>\n"
6514 "Automatically assign a label\n")
6515 {
6516 VTY_DECLVAR_CONTEXT(bgp, bgp);
6517 mpls_label_t label = MPLS_LABEL_NONE;
6518 afi_t afi;
6519 int idx = 0;
6520 int yes = 1;
6521
6522 if (argv_find(argv, argc, "no", &idx))
6523 yes = 0;
6524
6525 /* If "no ...", squash trailing parameter */
6526 if (!yes)
6527 label_auto = NULL;
6528
6529 if (yes) {
6530 if (!label_auto)
6531 label = label_val; /* parser should force unsigned */
6532 }
6533
6534 afi = vpn_policy_getafi(vty, bgp, false);
6535 if (afi == AFI_MAX)
6536 return CMD_WARNING_CONFIG_FAILED;
6537
6538
6539 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6540 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6541 /* no change */
6542 return CMD_SUCCESS;
6543
6544 /*
6545 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6546 */
6547 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6548 bgp_get_default(), bgp);
6549
6550 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6551 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6552
6553 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6554
6555 /*
6556 * label has previously been automatically
6557 * assigned by labelpool: release it
6558 *
6559 * NB if tovpn_label == MPLS_LABEL_NONE it
6560 * means the automatic assignment is in flight
6561 * and therefore the labelpool callback must
6562 * detect that the auto label is not needed.
6563 */
6564
6565 bgp_lp_release(LP_TYPE_VRF,
6566 &bgp->vpn_policy[afi],
6567 bgp->vpn_policy[afi].tovpn_label);
6568 }
6569 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6570 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6571 }
6572
6573 bgp->vpn_policy[afi].tovpn_label = label;
6574 if (label_auto) {
6575 SET_FLAG(bgp->vpn_policy[afi].flags,
6576 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6577 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6578 vpn_leak_label_callback);
6579 }
6580
6581 /* post-change: re-export vpn routes */
6582 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6583 bgp_get_default(), bgp);
6584
6585 return CMD_SUCCESS;
6586 }
6587
6588 ALIAS (af_label_vpn_export,
6589 af_no_label_vpn_export_cmd,
6590 "no label vpn export",
6591 NO_STR
6592 "label value for VRF\n"
6593 "Between current address-family and vpn\n"
6594 "For routes leaked from current address-family to vpn\n")
6595
6596 DEFPY (af_nexthop_vpn_export,
6597 af_nexthop_vpn_export_cmd,
6598 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6599 NO_STR
6600 "Specify next hop to use for VRF advertised prefixes\n"
6601 "Between current address-family and vpn\n"
6602 "For routes leaked from current address-family to vpn\n"
6603 "IPv4 prefix\n"
6604 "IPv6 prefix\n")
6605 {
6606 VTY_DECLVAR_CONTEXT(bgp, bgp);
6607 afi_t afi;
6608 struct prefix p;
6609 int idx = 0;
6610 int yes = 1;
6611
6612 if (argv_find(argv, argc, "no", &idx))
6613 yes = 0;
6614
6615 if (yes) {
6616 if (!sockunion2hostprefix(nexthop_str, &p))
6617 return CMD_WARNING_CONFIG_FAILED;
6618 }
6619
6620 afi = vpn_policy_getafi(vty, bgp, false);
6621 if (afi == AFI_MAX)
6622 return CMD_WARNING_CONFIG_FAILED;
6623
6624 /*
6625 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6626 */
6627 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6628 bgp_get_default(), bgp);
6629
6630 if (yes) {
6631 bgp->vpn_policy[afi].tovpn_nexthop = p;
6632 SET_FLAG(bgp->vpn_policy[afi].flags,
6633 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6634 } else {
6635 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6636 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6637 }
6638
6639 /* post-change: re-export vpn routes */
6640 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6641 bgp_get_default(), bgp);
6642
6643 return CMD_SUCCESS;
6644 }
6645
6646 ALIAS (af_nexthop_vpn_export,
6647 af_no_nexthop_vpn_export_cmd,
6648 "no nexthop vpn export",
6649 NO_STR
6650 "Specify next hop to use for VRF advertised prefixes\n"
6651 "Between current address-family and vpn\n"
6652 "For routes leaked from current address-family to vpn\n")
6653
6654 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6655 {
6656 if (!strcmp(dstr, "import")) {
6657 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6658 } else if (!strcmp(dstr, "export")) {
6659 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6660 } else if (!strcmp(dstr, "both")) {
6661 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6662 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6663 } else {
6664 vty_out(vty, "%% direction parse error\n");
6665 return CMD_WARNING_CONFIG_FAILED;
6666 }
6667 return CMD_SUCCESS;
6668 }
6669
6670 DEFPY (af_rt_vpn_imexport,
6671 af_rt_vpn_imexport_cmd,
6672 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6673 NO_STR
6674 "Specify route target list\n"
6675 "Specify route target list\n"
6676 "Between current address-family and vpn\n"
6677 "For routes leaked from vpn to current address-family: match any\n"
6678 "For routes leaked from current address-family to vpn: set\n"
6679 "both import: match any and export: set\n"
6680 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6681 {
6682 VTY_DECLVAR_CONTEXT(bgp, bgp);
6683 int ret;
6684 struct ecommunity *ecom = NULL;
6685 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6686 vpn_policy_direction_t dir;
6687 afi_t afi;
6688 int idx = 0;
6689 int yes = 1;
6690
6691 if (argv_find(argv, argc, "no", &idx))
6692 yes = 0;
6693
6694 afi = vpn_policy_getafi(vty, bgp, false);
6695 if (afi == AFI_MAX)
6696 return CMD_WARNING_CONFIG_FAILED;
6697
6698 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6699 if (ret != CMD_SUCCESS)
6700 return ret;
6701
6702 if (yes) {
6703 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6704 vty_out(vty, "%% Missing RTLIST\n");
6705 return CMD_WARNING_CONFIG_FAILED;
6706 }
6707 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6708 if (ret != CMD_SUCCESS) {
6709 return ret;
6710 }
6711 }
6712
6713 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6714 if (!dodir[dir])
6715 continue;
6716
6717 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6718
6719 if (yes) {
6720 if (bgp->vpn_policy[afi].rtlist[dir])
6721 ecommunity_free(
6722 &bgp->vpn_policy[afi].rtlist[dir]);
6723 bgp->vpn_policy[afi].rtlist[dir] =
6724 ecommunity_dup(ecom);
6725 } else {
6726 if (bgp->vpn_policy[afi].rtlist[dir])
6727 ecommunity_free(
6728 &bgp->vpn_policy[afi].rtlist[dir]);
6729 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6730 }
6731
6732 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6733 }
6734
6735 if (ecom)
6736 ecommunity_free(&ecom);
6737
6738 return CMD_SUCCESS;
6739 }
6740
6741 ALIAS (af_rt_vpn_imexport,
6742 af_no_rt_vpn_imexport_cmd,
6743 "no <rt|route-target> vpn <import|export|both>$direction_str",
6744 NO_STR
6745 "Specify route target list\n"
6746 "Specify route target list\n"
6747 "Between current address-family and vpn\n"
6748 "For routes leaked from vpn to current address-family\n"
6749 "For routes leaked from current address-family to vpn\n"
6750 "both import and export\n")
6751
6752 DEFPY (af_route_map_vpn_imexport,
6753 af_route_map_vpn_imexport_cmd,
6754 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6755 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6756 NO_STR
6757 "Specify route map\n"
6758 "Between current address-family and vpn\n"
6759 "For routes leaked from vpn to current address-family\n"
6760 "For routes leaked from current address-family to vpn\n"
6761 "name of route-map\n")
6762 {
6763 VTY_DECLVAR_CONTEXT(bgp, bgp);
6764 int ret;
6765 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6766 vpn_policy_direction_t dir;
6767 afi_t afi;
6768 int idx = 0;
6769 int yes = 1;
6770
6771 if (argv_find(argv, argc, "no", &idx))
6772 yes = 0;
6773
6774 afi = vpn_policy_getafi(vty, bgp, false);
6775 if (afi == AFI_MAX)
6776 return CMD_WARNING_CONFIG_FAILED;
6777
6778 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6779 if (ret != CMD_SUCCESS)
6780 return ret;
6781
6782 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6783 if (!dodir[dir])
6784 continue;
6785
6786 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6787
6788 if (yes) {
6789 if (bgp->vpn_policy[afi].rmap_name[dir])
6790 XFREE(MTYPE_ROUTE_MAP_NAME,
6791 bgp->vpn_policy[afi].rmap_name[dir]);
6792 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6793 MTYPE_ROUTE_MAP_NAME, rmap_str);
6794 bgp->vpn_policy[afi].rmap[dir] =
6795 route_map_lookup_warn_noexist(vty, rmap_str);
6796 if (!bgp->vpn_policy[afi].rmap[dir])
6797 return CMD_SUCCESS;
6798 } else {
6799 if (bgp->vpn_policy[afi].rmap_name[dir])
6800 XFREE(MTYPE_ROUTE_MAP_NAME,
6801 bgp->vpn_policy[afi].rmap_name[dir]);
6802 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6803 bgp->vpn_policy[afi].rmap[dir] = NULL;
6804 }
6805
6806 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6807 }
6808
6809 return CMD_SUCCESS;
6810 }
6811
6812 ALIAS (af_route_map_vpn_imexport,
6813 af_no_route_map_vpn_imexport_cmd,
6814 "no route-map vpn <import|export>$direction_str",
6815 NO_STR
6816 "Specify route map\n"
6817 "Between current address-family and vpn\n"
6818 "For routes leaked from vpn to current address-family\n"
6819 "For routes leaked from current address-family to vpn\n")
6820
6821 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6822 "[no] import vrf route-map RMAP$rmap_str",
6823 NO_STR
6824 "Import routes from another VRF\n"
6825 "Vrf routes being filtered\n"
6826 "Specify route map\n"
6827 "name of route-map\n")
6828 {
6829 VTY_DECLVAR_CONTEXT(bgp, bgp);
6830 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6831 afi_t afi;
6832 int idx = 0;
6833 int yes = 1;
6834 struct bgp *bgp_default;
6835
6836 if (argv_find(argv, argc, "no", &idx))
6837 yes = 0;
6838
6839 afi = vpn_policy_getafi(vty, bgp, true);
6840 if (afi == AFI_MAX)
6841 return CMD_WARNING_CONFIG_FAILED;
6842
6843 bgp_default = bgp_get_default();
6844 if (!bgp_default) {
6845 int32_t ret;
6846 as_t as = bgp->as;
6847
6848 /* Auto-create assuming the same AS */
6849 ret = bgp_get(&bgp_default, &as, NULL,
6850 BGP_INSTANCE_TYPE_DEFAULT);
6851
6852 if (ret) {
6853 vty_out(vty,
6854 "VRF default is not configured as a bgp instance\n");
6855 return CMD_WARNING;
6856 }
6857 }
6858
6859 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6860
6861 if (yes) {
6862 if (bgp->vpn_policy[afi].rmap_name[dir])
6863 XFREE(MTYPE_ROUTE_MAP_NAME,
6864 bgp->vpn_policy[afi].rmap_name[dir]);
6865 bgp->vpn_policy[afi].rmap_name[dir] =
6866 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6867 bgp->vpn_policy[afi].rmap[dir] =
6868 route_map_lookup_warn_noexist(vty, rmap_str);
6869 if (!bgp->vpn_policy[afi].rmap[dir])
6870 return CMD_SUCCESS;
6871 } else {
6872 if (bgp->vpn_policy[afi].rmap_name[dir])
6873 XFREE(MTYPE_ROUTE_MAP_NAME,
6874 bgp->vpn_policy[afi].rmap_name[dir]);
6875 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6876 bgp->vpn_policy[afi].rmap[dir] = NULL;
6877 }
6878
6879 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6880
6881 return CMD_SUCCESS;
6882 }
6883
6884 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6885 "no import vrf route-map",
6886 NO_STR
6887 "Import routes from another VRF\n"
6888 "Vrf routes being filtered\n"
6889 "Specify route map\n")
6890
6891 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6892 "[no] import vrf VIEWVRFNAME$import_name",
6893 NO_STR
6894 "Import routes from another VRF\n"
6895 "VRF to import from\n"
6896 "The name of the VRF\n")
6897 {
6898 VTY_DECLVAR_CONTEXT(bgp, bgp);
6899 struct listnode *node;
6900 struct bgp *vrf_bgp, *bgp_default;
6901 int32_t ret = 0;
6902 as_t as = bgp->as;
6903 bool remove = false;
6904 int32_t idx = 0;
6905 char *vname;
6906 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6907 safi_t safi;
6908 afi_t afi;
6909
6910 if (import_name == NULL) {
6911 vty_out(vty, "%% Missing import name\n");
6912 return CMD_WARNING;
6913 }
6914
6915 if (argv_find(argv, argc, "no", &idx))
6916 remove = true;
6917
6918 afi = vpn_policy_getafi(vty, bgp, true);
6919 if (afi == AFI_MAX)
6920 return CMD_WARNING_CONFIG_FAILED;
6921
6922 safi = bgp_node_safi(vty);
6923
6924 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6925 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6926 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6927 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6928 remove ? "unimport" : "import", import_name);
6929 return CMD_WARNING;
6930 }
6931
6932 bgp_default = bgp_get_default();
6933 if (!bgp_default) {
6934 /* Auto-create assuming the same AS */
6935 ret = bgp_get(&bgp_default, &as, NULL,
6936 BGP_INSTANCE_TYPE_DEFAULT);
6937
6938 if (ret) {
6939 vty_out(vty,
6940 "VRF default is not configured as a bgp instance\n");
6941 return CMD_WARNING;
6942 }
6943 }
6944
6945 vrf_bgp = bgp_lookup_by_name(import_name);
6946 if (!vrf_bgp) {
6947 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6948 vrf_bgp = bgp_default;
6949 else
6950 /* Auto-create assuming the same AS */
6951 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6952
6953 if (ret) {
6954 vty_out(vty,
6955 "VRF %s is not configured as a bgp instance\n",
6956 import_name);
6957 return CMD_WARNING;
6958 }
6959 }
6960
6961 if (remove) {
6962 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6963 } else {
6964 /* Already importing from "import_vrf"? */
6965 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6966 vname)) {
6967 if (strcmp(vname, import_name) == 0)
6968 return CMD_WARNING;
6969 }
6970
6971 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6972 }
6973
6974 return CMD_SUCCESS;
6975 }
6976
6977 /* This command is valid only in a bgp vrf instance or the default instance */
6978 DEFPY (bgp_imexport_vpn,
6979 bgp_imexport_vpn_cmd,
6980 "[no] <import|export>$direction_str vpn",
6981 NO_STR
6982 "Import routes to this address-family\n"
6983 "Export routes from this address-family\n"
6984 "to/from default instance VPN RIB\n")
6985 {
6986 VTY_DECLVAR_CONTEXT(bgp, bgp);
6987 int previous_state;
6988 afi_t afi;
6989 safi_t safi;
6990 int idx = 0;
6991 int yes = 1;
6992 int flag;
6993 vpn_policy_direction_t dir;
6994
6995 if (argv_find(argv, argc, "no", &idx))
6996 yes = 0;
6997
6998 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6999 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
7000
7001 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
7002 return CMD_WARNING_CONFIG_FAILED;
7003 }
7004
7005 afi = bgp_node_afi(vty);
7006 safi = bgp_node_safi(vty);
7007 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
7008 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
7009 return CMD_WARNING_CONFIG_FAILED;
7010 }
7011
7012 if (!strcmp(direction_str, "import")) {
7013 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
7014 dir = BGP_VPN_POLICY_DIR_FROMVPN;
7015 } else if (!strcmp(direction_str, "export")) {
7016 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
7017 dir = BGP_VPN_POLICY_DIR_TOVPN;
7018 } else {
7019 vty_out(vty, "%% unknown direction %s\n", direction_str);
7020 return CMD_WARNING_CONFIG_FAILED;
7021 }
7022
7023 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7024
7025 if (yes) {
7026 SET_FLAG(bgp->af_flags[afi][safi], flag);
7027 if (!previous_state) {
7028 /* trigger export current vrf */
7029 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7030 }
7031 } else {
7032 if (previous_state) {
7033 /* trigger un-export current vrf */
7034 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7035 }
7036 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7037 }
7038
7039 return CMD_SUCCESS;
7040 }
7041
7042 DEFPY (af_routetarget_import,
7043 af_routetarget_import_cmd,
7044 "[no] <rt|route-target> redirect import RTLIST...",
7045 NO_STR
7046 "Specify route target list\n"
7047 "Specify route target list\n"
7048 "Flow-spec redirect type route target\n"
7049 "Import routes to this address-family\n"
7050 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7051 {
7052 VTY_DECLVAR_CONTEXT(bgp, bgp);
7053 int ret;
7054 struct ecommunity *ecom = NULL;
7055 afi_t afi;
7056 int idx = 0;
7057 int yes = 1;
7058
7059 if (argv_find(argv, argc, "no", &idx))
7060 yes = 0;
7061
7062 afi = vpn_policy_getafi(vty, bgp, false);
7063 if (afi == AFI_MAX)
7064 return CMD_WARNING_CONFIG_FAILED;
7065
7066 if (yes) {
7067 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7068 vty_out(vty, "%% Missing RTLIST\n");
7069 return CMD_WARNING_CONFIG_FAILED;
7070 }
7071 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7072 if (ret != CMD_SUCCESS)
7073 return ret;
7074 }
7075
7076 if (yes) {
7077 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7078 ecommunity_free(&bgp->vpn_policy[afi]
7079 .import_redirect_rtlist);
7080 bgp->vpn_policy[afi].import_redirect_rtlist =
7081 ecommunity_dup(ecom);
7082 } else {
7083 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7084 ecommunity_free(&bgp->vpn_policy[afi]
7085 .import_redirect_rtlist);
7086 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7087 }
7088
7089 if (ecom)
7090 ecommunity_free(&ecom);
7091
7092 return CMD_SUCCESS;
7093 }
7094
7095 DEFUN_NOSH (address_family_ipv4_safi,
7096 address_family_ipv4_safi_cmd,
7097 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7098 "Enter Address Family command mode\n"
7099 "Address Family\n"
7100 BGP_SAFI_WITH_LABEL_HELP_STR)
7101 {
7102
7103 if (argc == 3) {
7104 VTY_DECLVAR_CONTEXT(bgp, bgp);
7105 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7106 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7107 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7108 && safi != SAFI_EVPN) {
7109 vty_out(vty,
7110 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7111 return CMD_WARNING_CONFIG_FAILED;
7112 }
7113 vty->node = bgp_node_type(AFI_IP, safi);
7114 } else
7115 vty->node = BGP_IPV4_NODE;
7116
7117 return CMD_SUCCESS;
7118 }
7119
7120 DEFUN_NOSH (address_family_ipv6_safi,
7121 address_family_ipv6_safi_cmd,
7122 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7123 "Enter Address Family command mode\n"
7124 "Address Family\n"
7125 BGP_SAFI_WITH_LABEL_HELP_STR)
7126 {
7127 if (argc == 3) {
7128 VTY_DECLVAR_CONTEXT(bgp, bgp);
7129 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7130 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7131 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7132 && safi != SAFI_EVPN) {
7133 vty_out(vty,
7134 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7135 return CMD_WARNING_CONFIG_FAILED;
7136 }
7137 vty->node = bgp_node_type(AFI_IP6, safi);
7138 } else
7139 vty->node = BGP_IPV6_NODE;
7140
7141 return CMD_SUCCESS;
7142 }
7143
7144 #ifdef KEEP_OLD_VPN_COMMANDS
7145 DEFUN_NOSH (address_family_vpnv4,
7146 address_family_vpnv4_cmd,
7147 "address-family vpnv4 [unicast]",
7148 "Enter Address Family command mode\n"
7149 "Address Family\n"
7150 "Address Family modifier\n")
7151 {
7152 vty->node = BGP_VPNV4_NODE;
7153 return CMD_SUCCESS;
7154 }
7155
7156 DEFUN_NOSH (address_family_vpnv6,
7157 address_family_vpnv6_cmd,
7158 "address-family vpnv6 [unicast]",
7159 "Enter Address Family command mode\n"
7160 "Address Family\n"
7161 "Address Family modifier\n")
7162 {
7163 vty->node = BGP_VPNV6_NODE;
7164 return CMD_SUCCESS;
7165 }
7166 #endif
7167
7168 DEFUN_NOSH (address_family_evpn,
7169 address_family_evpn_cmd,
7170 "address-family l2vpn evpn",
7171 "Enter Address Family command mode\n"
7172 "Address Family\n"
7173 "Address Family modifier\n")
7174 {
7175 VTY_DECLVAR_CONTEXT(bgp, bgp);
7176 vty->node = BGP_EVPN_NODE;
7177 return CMD_SUCCESS;
7178 }
7179
7180 DEFUN_NOSH (exit_address_family,
7181 exit_address_family_cmd,
7182 "exit-address-family",
7183 "Exit from Address Family configuration mode\n")
7184 {
7185 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7186 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7187 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7188 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7189 || vty->node == BGP_EVPN_NODE
7190 || vty->node == BGP_FLOWSPECV4_NODE
7191 || vty->node == BGP_FLOWSPECV6_NODE)
7192 vty->node = BGP_NODE;
7193 return CMD_SUCCESS;
7194 }
7195
7196 /* Recalculate bestpath and re-advertise a prefix */
7197 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7198 const char *ip_str, afi_t afi, safi_t safi,
7199 struct prefix_rd *prd)
7200 {
7201 int ret;
7202 struct prefix match;
7203 struct bgp_node *rn;
7204 struct bgp_node *rm;
7205 struct bgp *bgp;
7206 struct bgp_table *table;
7207 struct bgp_table *rib;
7208
7209 /* BGP structure lookup. */
7210 if (view_name) {
7211 bgp = bgp_lookup_by_name(view_name);
7212 if (bgp == NULL) {
7213 vty_out(vty, "%% Can't find BGP instance %s\n",
7214 view_name);
7215 return CMD_WARNING;
7216 }
7217 } else {
7218 bgp = bgp_get_default();
7219 if (bgp == NULL) {
7220 vty_out(vty, "%% No BGP process is configured\n");
7221 return CMD_WARNING;
7222 }
7223 }
7224
7225 /* Check IP address argument. */
7226 ret = str2prefix(ip_str, &match);
7227 if (!ret) {
7228 vty_out(vty, "%% address is malformed\n");
7229 return CMD_WARNING;
7230 }
7231
7232 match.family = afi2family(afi);
7233 rib = bgp->rib[afi][safi];
7234
7235 if (safi == SAFI_MPLS_VPN) {
7236 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7237 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7238 continue;
7239
7240 table = bgp_node_get_bgp_table_info(rn);
7241 if (table != NULL) {
7242
7243 if ((rm = bgp_node_match(table, &match))
7244 != NULL) {
7245 if (rm->p.prefixlen
7246 == match.prefixlen) {
7247 SET_FLAG(rm->flags,
7248 BGP_NODE_USER_CLEAR);
7249 bgp_process(bgp, rm, afi, safi);
7250 }
7251 bgp_unlock_node(rm);
7252 }
7253 }
7254 }
7255 } else {
7256 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7257 if (rn->p.prefixlen == match.prefixlen) {
7258 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7259 bgp_process(bgp, rn, afi, safi);
7260 }
7261 bgp_unlock_node(rn);
7262 }
7263 }
7264
7265 return CMD_SUCCESS;
7266 }
7267
7268 /* one clear bgp command to rule them all */
7269 DEFUN (clear_ip_bgp_all,
7270 clear_ip_bgp_all_cmd,
7271 "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>]",
7272 CLEAR_STR
7273 IP_STR
7274 BGP_STR
7275 BGP_INSTANCE_HELP_STR
7276 BGP_AFI_HELP_STR
7277 "Address Family\n"
7278 BGP_SAFI_WITH_LABEL_HELP_STR
7279 "Address Family modifier\n"
7280 "Clear all peers\n"
7281 "BGP neighbor address to clear\n"
7282 "BGP IPv6 neighbor to clear\n"
7283 "BGP neighbor on interface to clear\n"
7284 "Clear peers with the AS number\n"
7285 "Clear all external peers\n"
7286 "Clear all members of peer-group\n"
7287 "BGP peer-group name\n"
7288 BGP_SOFT_STR
7289 BGP_SOFT_IN_STR
7290 BGP_SOFT_OUT_STR
7291 BGP_SOFT_IN_STR
7292 "Push out prefix-list ORF and do inbound soft reconfig\n"
7293 BGP_SOFT_OUT_STR)
7294 {
7295 char *vrf = NULL;
7296
7297 afi_t afi = AFI_IP6;
7298 safi_t safi = SAFI_UNICAST;
7299 enum clear_sort clr_sort = clear_peer;
7300 enum bgp_clear_type clr_type;
7301 char *clr_arg = NULL;
7302
7303 int idx = 0;
7304
7305 /* clear [ip] bgp */
7306 if (argv_find(argv, argc, "ip", &idx))
7307 afi = AFI_IP;
7308
7309 /* [<vrf> VIEWVRFNAME] */
7310 if (argv_find(argv, argc, "vrf", &idx)) {
7311 vrf = argv[idx + 1]->arg;
7312 idx += 2;
7313 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7314 vrf = NULL;
7315 } else if (argv_find(argv, argc, "view", &idx)) {
7316 /* [<view> VIEWVRFNAME] */
7317 vrf = argv[idx + 1]->arg;
7318 idx += 2;
7319 }
7320 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7321 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7322 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7323
7324 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7325 if (argv_find(argv, argc, "*", &idx)) {
7326 clr_sort = clear_all;
7327 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7328 clr_sort = clear_peer;
7329 clr_arg = argv[idx]->arg;
7330 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7331 clr_sort = clear_peer;
7332 clr_arg = argv[idx]->arg;
7333 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7334 clr_sort = clear_group;
7335 idx++;
7336 clr_arg = argv[idx]->arg;
7337 } else if (argv_find(argv, argc, "WORD", &idx)) {
7338 clr_sort = clear_peer;
7339 clr_arg = argv[idx]->arg;
7340 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7341 clr_sort = clear_as;
7342 clr_arg = argv[idx]->arg;
7343 } else if (argv_find(argv, argc, "external", &idx)) {
7344 clr_sort = clear_external;
7345 }
7346
7347 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7348 if (argv_find(argv, argc, "soft", &idx)) {
7349 if (argv_find(argv, argc, "in", &idx)
7350 || argv_find(argv, argc, "out", &idx))
7351 clr_type = strmatch(argv[idx]->text, "in")
7352 ? BGP_CLEAR_SOFT_IN
7353 : BGP_CLEAR_SOFT_OUT;
7354 else
7355 clr_type = BGP_CLEAR_SOFT_BOTH;
7356 } else if (argv_find(argv, argc, "in", &idx)) {
7357 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7358 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7359 : BGP_CLEAR_SOFT_IN;
7360 } else if (argv_find(argv, argc, "out", &idx)) {
7361 clr_type = BGP_CLEAR_SOFT_OUT;
7362 } else
7363 clr_type = BGP_CLEAR_SOFT_NONE;
7364
7365 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7366 }
7367
7368 DEFUN (clear_ip_bgp_prefix,
7369 clear_ip_bgp_prefix_cmd,
7370 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7371 CLEAR_STR
7372 IP_STR
7373 BGP_STR
7374 BGP_INSTANCE_HELP_STR
7375 "Clear bestpath and re-advertise\n"
7376 "IPv4 prefix\n")
7377 {
7378 char *vrf = NULL;
7379 char *prefix = NULL;
7380
7381 int idx = 0;
7382
7383 /* [<view|vrf> VIEWVRFNAME] */
7384 if (argv_find(argv, argc, "vrf", &idx)) {
7385 vrf = argv[idx + 1]->arg;
7386 idx += 2;
7387 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7388 vrf = NULL;
7389 } else if (argv_find(argv, argc, "view", &idx)) {
7390 /* [<view> VIEWVRFNAME] */
7391 vrf = argv[idx + 1]->arg;
7392 idx += 2;
7393 }
7394
7395 prefix = argv[argc - 1]->arg;
7396
7397 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7398 }
7399
7400 DEFUN (clear_bgp_ipv6_safi_prefix,
7401 clear_bgp_ipv6_safi_prefix_cmd,
7402 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7403 CLEAR_STR
7404 IP_STR
7405 BGP_STR
7406 "Address Family\n"
7407 BGP_SAFI_HELP_STR
7408 "Clear bestpath and re-advertise\n"
7409 "IPv6 prefix\n")
7410 {
7411 int idx_safi = 0;
7412 int idx_ipv6_prefix = 0;
7413 safi_t safi = SAFI_UNICAST;
7414 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7415 argv[idx_ipv6_prefix]->arg : NULL;
7416
7417 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7418 return bgp_clear_prefix(
7419 vty, NULL, prefix, AFI_IP6,
7420 safi, NULL);
7421 }
7422
7423 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7424 clear_bgp_instance_ipv6_safi_prefix_cmd,
7425 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7426 CLEAR_STR
7427 IP_STR
7428 BGP_STR
7429 BGP_INSTANCE_HELP_STR
7430 "Address Family\n"
7431 BGP_SAFI_HELP_STR
7432 "Clear bestpath and re-advertise\n"
7433 "IPv6 prefix\n")
7434 {
7435 int idx_safi = 0;
7436 int idx_vrfview = 0;
7437 int idx_ipv6_prefix = 0;
7438 safi_t safi = SAFI_UNICAST;
7439 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7440 argv[idx_ipv6_prefix]->arg : NULL;
7441 char *vrfview = NULL;
7442
7443 /* [<view|vrf> VIEWVRFNAME] */
7444 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7445 vrfview = argv[idx_vrfview + 1]->arg;
7446 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7447 vrfview = NULL;
7448 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7449 /* [<view> VIEWVRFNAME] */
7450 vrfview = argv[idx_vrfview + 1]->arg;
7451 }
7452 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7453
7454 return bgp_clear_prefix(
7455 vty, vrfview, prefix,
7456 AFI_IP6, safi, NULL);
7457 }
7458
7459 DEFUN (show_bgp_views,
7460 show_bgp_views_cmd,
7461 "show [ip] bgp views",
7462 SHOW_STR
7463 IP_STR
7464 BGP_STR
7465 "Show the defined BGP views\n")
7466 {
7467 struct list *inst = bm->bgp;
7468 struct listnode *node;
7469 struct bgp *bgp;
7470
7471 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7472 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7473 return CMD_WARNING;
7474 }
7475
7476 vty_out(vty, "Defined BGP views:\n");
7477 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7478 /* Skip VRFs. */
7479 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7480 continue;
7481 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7482 bgp->as);
7483 }
7484
7485 return CMD_SUCCESS;
7486 }
7487
7488 DEFUN (show_bgp_vrfs,
7489 show_bgp_vrfs_cmd,
7490 "show [ip] bgp vrfs [json]",
7491 SHOW_STR
7492 IP_STR
7493 BGP_STR
7494 "Show BGP VRFs\n"
7495 JSON_STR)
7496 {
7497 char buf[ETHER_ADDR_STRLEN];
7498 struct list *inst = bm->bgp;
7499 struct listnode *node;
7500 struct bgp *bgp;
7501 bool uj = use_json(argc, argv);
7502 json_object *json = NULL;
7503 json_object *json_vrfs = NULL;
7504 int count = 0;
7505
7506 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7507 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7508 return CMD_WARNING;
7509 }
7510
7511 if (uj) {
7512 json = json_object_new_object();
7513 json_vrfs = json_object_new_object();
7514 }
7515
7516 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7517 const char *name, *type;
7518 struct peer *peer;
7519 struct listnode *node2, *nnode2;
7520 int peers_cfg, peers_estb;
7521 json_object *json_vrf = NULL;
7522
7523 /* Skip Views. */
7524 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7525 continue;
7526
7527 count++;
7528 if (!uj && count == 1)
7529 vty_out(vty,
7530 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7531 "Type", "Id", "routerId", "#PeersVfg",
7532 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7533
7534 peers_cfg = peers_estb = 0;
7535 if (uj)
7536 json_vrf = json_object_new_object();
7537
7538
7539 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7540 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7541 continue;
7542 peers_cfg++;
7543 if (peer->status == Established)
7544 peers_estb++;
7545 }
7546
7547 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7548 name = VRF_DEFAULT_NAME;
7549 type = "DFLT";
7550 } else {
7551 name = bgp->name;
7552 type = "VRF";
7553 }
7554
7555
7556 if (uj) {
7557 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7558 ? -1
7559 : (int64_t)bgp->vrf_id;
7560 json_object_string_add(json_vrf, "type", type);
7561 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7562 json_object_string_add(json_vrf, "routerId",
7563 inet_ntoa(bgp->router_id));
7564 json_object_int_add(json_vrf, "numConfiguredPeers",
7565 peers_cfg);
7566 json_object_int_add(json_vrf, "numEstablishedPeers",
7567 peers_estb);
7568
7569 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7570 json_object_string_add(
7571 json_vrf, "rmac",
7572 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7573 json_object_object_add(json_vrfs, name, json_vrf);
7574 } else
7575 vty_out(vty,
7576 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7577 type,
7578 bgp->vrf_id == VRF_UNKNOWN ? -1
7579 : (int)bgp->vrf_id,
7580 inet_ntoa(bgp->router_id), peers_cfg,
7581 peers_estb, name, bgp->l3vni,
7582 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7583 }
7584
7585 if (uj) {
7586 json_object_object_add(json, "vrfs", json_vrfs);
7587
7588 json_object_int_add(json, "totalVrfs", count);
7589
7590 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7591 json, JSON_C_TO_STRING_PRETTY));
7592 json_object_free(json);
7593 } else {
7594 if (count)
7595 vty_out(vty,
7596 "\nTotal number of VRFs (including default): %d\n",
7597 count);
7598 }
7599
7600 return CMD_SUCCESS;
7601 }
7602
7603 DEFUN (show_bgp_mac_hash,
7604 show_bgp_mac_hash_cmd,
7605 "show bgp mac hash",
7606 SHOW_STR
7607 BGP_STR
7608 "Mac Address\n"
7609 "Mac Address database\n")
7610 {
7611 bgp_mac_dump_table(vty);
7612
7613 return CMD_SUCCESS;
7614 }
7615
7616 static void show_tip_entry(struct hash_bucket *bucket, void *args)
7617 {
7618 struct vty *vty = (struct vty *)args;
7619 struct tip_addr *tip = (struct tip_addr *)bucket->data;
7620
7621 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7622 tip->refcnt);
7623 }
7624
7625 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7626 {
7627 vty_out(vty, "self nexthop database:\n");
7628 bgp_nexthop_show_address_hash(vty, bgp);
7629
7630 vty_out(vty, "Tunnel-ip database:\n");
7631 hash_iterate(bgp->tip_hash,
7632 (void (*)(struct hash_bucket *, void *))show_tip_entry,
7633 vty);
7634 }
7635
7636 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7637 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7638 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7639 "martian next-hops\n"
7640 "martian next-hop database\n")
7641 {
7642 struct bgp *bgp = NULL;
7643 int idx = 0;
7644 char *name = NULL;
7645
7646 /* [<vrf> VIEWVRFNAME] */
7647 if (argv_find(argv, argc, "vrf", &idx)) {
7648 name = argv[idx + 1]->arg;
7649 if (name && strmatch(name, VRF_DEFAULT_NAME))
7650 name = NULL;
7651 } else if (argv_find(argv, argc, "view", &idx))
7652 /* [<view> VIEWVRFNAME] */
7653 name = argv[idx + 1]->arg;
7654 if (name)
7655 bgp = bgp_lookup_by_name(name);
7656 else
7657 bgp = bgp_get_default();
7658
7659 if (!bgp) {
7660 vty_out(vty, "%% No BGP process is configured\n");
7661 return CMD_WARNING;
7662 }
7663 bgp_show_martian_nexthops(vty, bgp);
7664
7665 return CMD_SUCCESS;
7666 }
7667
7668 DEFUN (show_bgp_memory,
7669 show_bgp_memory_cmd,
7670 "show [ip] bgp memory",
7671 SHOW_STR
7672 IP_STR
7673 BGP_STR
7674 "Global BGP memory statistics\n")
7675 {
7676 char memstrbuf[MTYPE_MEMSTR_LEN];
7677 unsigned long count;
7678
7679 /* RIB related usage stats */
7680 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7681 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7682 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7683 count * sizeof(struct bgp_node)));
7684
7685 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7686 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct bgp_path_info)));
7689 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7690 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7691 count,
7692 mtype_memstr(
7693 memstrbuf, sizeof(memstrbuf),
7694 count * sizeof(struct bgp_path_info_extra)));
7695
7696 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7697 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7698 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7699 count * sizeof(struct bgp_static)));
7700
7701 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7702 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7703 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7704 count * sizeof(struct bpacket)));
7705
7706 /* Adj-In/Out */
7707 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7708 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7709 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7710 count * sizeof(struct bgp_adj_in)));
7711 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7712 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7713 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct bgp_adj_out)));
7715
7716 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7717 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7718 count,
7719 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7720 count * sizeof(struct bgp_nexthop_cache)));
7721
7722 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7723 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7724 count,
7725 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7726 count * sizeof(struct bgp_damp_info)));
7727
7728 /* Attributes */
7729 count = attr_count();
7730 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7732 count * sizeof(struct attr)));
7733
7734 if ((count = attr_unknown_count()))
7735 vty_out(vty, "%ld unknown attributes\n", count);
7736
7737 /* AS_PATH attributes */
7738 count = aspath_count();
7739 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7740 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7741 count * sizeof(struct aspath)));
7742
7743 count = mtype_stats_alloc(MTYPE_AS_SEG);
7744 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7745 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7746 count * sizeof(struct assegment)));
7747
7748 /* Other attributes */
7749 if ((count = community_count()))
7750 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7751 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7752 count * sizeof(struct community)));
7753 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7754 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7755 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7756 count * sizeof(struct ecommunity)));
7757 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7758 vty_out(vty,
7759 "%ld BGP large-community entries, using %s of memory\n",
7760 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7761 count * sizeof(struct lcommunity)));
7762
7763 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7764 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7765 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7766 count * sizeof(struct cluster_list)));
7767
7768 /* Peer related usage */
7769 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7770 vty_out(vty, "%ld peers, using %s of memory\n", count,
7771 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7772 count * sizeof(struct peer)));
7773
7774 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7775 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7776 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7777 count * sizeof(struct peer_group)));
7778
7779 /* Other */
7780 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7781 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7782 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7783 count * sizeof(struct hash)));
7784 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7785 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7786 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7787 count * sizeof(struct hash_bucket)));
7788 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7789 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7790 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7791 count * sizeof(regex_t)));
7792 return CMD_SUCCESS;
7793 }
7794
7795 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7796 {
7797 json_object *bestpath = json_object_new_object();
7798
7799 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7800 json_object_string_add(bestpath, "asPath", "ignore");
7801
7802 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7803 json_object_string_add(bestpath, "asPath", "confed");
7804
7805 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7806 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7807 json_object_string_add(bestpath, "multiPathRelax",
7808 "as-set");
7809 else
7810 json_object_string_add(bestpath, "multiPathRelax",
7811 "true");
7812 } else
7813 json_object_string_add(bestpath, "multiPathRelax", "false");
7814
7815 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7816 json_object_string_add(bestpath, "compareRouterId", "true");
7817 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7818 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7819 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7820 json_object_string_add(bestpath, "med", "confed");
7821 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7822 json_object_string_add(bestpath, "med",
7823 "missing-as-worst");
7824 else
7825 json_object_string_add(bestpath, "med", "true");
7826 }
7827
7828 json_object_object_add(json, "bestPath", bestpath);
7829 }
7830
7831 /* Show BGP peer's summary information. */
7832 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7833 bool use_json, json_object *json)
7834 {
7835 struct peer *peer;
7836 struct listnode *node, *nnode;
7837 unsigned int count = 0, dn_count = 0;
7838 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7839 char neighbor_buf[VTY_BUFSIZ];
7840 int neighbor_col_default_width = 16;
7841 int len;
7842 int max_neighbor_width = 0;
7843 int pfx_rcd_safi;
7844 json_object *json_peer = NULL;
7845 json_object *json_peers = NULL;
7846 struct peer_af *paf;
7847
7848 /* labeled-unicast routes are installed in the unicast table so in order
7849 * to
7850 * display the correct PfxRcd value we must look at SAFI_UNICAST
7851 */
7852 if (safi == SAFI_LABELED_UNICAST)
7853 pfx_rcd_safi = SAFI_UNICAST;
7854 else
7855 pfx_rcd_safi = safi;
7856
7857 if (use_json) {
7858 if (json == NULL)
7859 json = json_object_new_object();
7860
7861 json_peers = json_object_new_object();
7862 } else {
7863 /* Loop over all neighbors that will be displayed to determine
7864 * how many
7865 * characters are needed for the Neighbor column
7866 */
7867 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7868 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7869 continue;
7870
7871 if (peer->afc[afi][safi]) {
7872 memset(dn_flag, '\0', sizeof(dn_flag));
7873 if (peer_dynamic_neighbor(peer))
7874 dn_flag[0] = '*';
7875
7876 if (peer->hostname
7877 && bgp_flag_check(bgp,
7878 BGP_FLAG_SHOW_HOSTNAME))
7879 sprintf(neighbor_buf, "%s%s(%s) ",
7880 dn_flag, peer->hostname,
7881 peer->host);
7882 else
7883 sprintf(neighbor_buf, "%s%s ", dn_flag,
7884 peer->host);
7885
7886 len = strlen(neighbor_buf);
7887
7888 if (len > max_neighbor_width)
7889 max_neighbor_width = len;
7890 }
7891 }
7892
7893 /* Originally we displayed the Neighbor column as 16
7894 * characters wide so make that the default
7895 */
7896 if (max_neighbor_width < neighbor_col_default_width)
7897 max_neighbor_width = neighbor_col_default_width;
7898 }
7899
7900 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7901 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7902 continue;
7903
7904 if (!peer->afc[afi][safi])
7905 continue;
7906
7907 if (!count) {
7908 unsigned long ents;
7909 char memstrbuf[MTYPE_MEMSTR_LEN];
7910 int64_t vrf_id_ui;
7911
7912 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7913 ? -1
7914 : (int64_t)bgp->vrf_id;
7915
7916 /* Usage summary and header */
7917 if (use_json) {
7918 json_object_string_add(
7919 json, "routerId",
7920 inet_ntoa(bgp->router_id));
7921 json_object_int_add(json, "as", bgp->as);
7922 json_object_int_add(json, "vrfId", vrf_id_ui);
7923 json_object_string_add(
7924 json, "vrfName",
7925 (bgp->inst_type
7926 == BGP_INSTANCE_TYPE_DEFAULT)
7927 ? VRF_DEFAULT_NAME
7928 : bgp->name);
7929 } else {
7930 vty_out(vty,
7931 "BGP router identifier %s, local AS number %u vrf-id %d",
7932 inet_ntoa(bgp->router_id), bgp->as,
7933 bgp->vrf_id == VRF_UNKNOWN
7934 ? -1
7935 : (int)bgp->vrf_id);
7936 vty_out(vty, "\n");
7937 }
7938
7939 if (bgp_update_delay_configured(bgp)) {
7940 if (use_json) {
7941 json_object_int_add(
7942 json, "updateDelayLimit",
7943 bgp->v_update_delay);
7944
7945 if (bgp->v_update_delay
7946 != bgp->v_establish_wait)
7947 json_object_int_add(
7948 json,
7949 "updateDelayEstablishWait",
7950 bgp->v_establish_wait);
7951
7952 if (bgp_update_delay_active(bgp)) {
7953 json_object_string_add(
7954 json,
7955 "updateDelayFirstNeighbor",
7956 bgp->update_delay_begin_time);
7957 json_object_boolean_true_add(
7958 json,
7959 "updateDelayInProgress");
7960 } else {
7961 if (bgp->update_delay_over) {
7962 json_object_string_add(
7963 json,
7964 "updateDelayFirstNeighbor",
7965 bgp->update_delay_begin_time);
7966 json_object_string_add(
7967 json,
7968 "updateDelayBestpathResumed",
7969 bgp->update_delay_end_time);
7970 json_object_string_add(
7971 json,
7972 "updateDelayZebraUpdateResume",
7973 bgp->update_delay_zebra_resume_time);
7974 json_object_string_add(
7975 json,
7976 "updateDelayPeerUpdateResume",
7977 bgp->update_delay_peers_resume_time);
7978 }
7979 }
7980 } else {
7981 vty_out(vty,
7982 "Read-only mode update-delay limit: %d seconds\n",
7983 bgp->v_update_delay);
7984 if (bgp->v_update_delay
7985 != bgp->v_establish_wait)
7986 vty_out(vty,
7987 " Establish wait: %d seconds\n",
7988 bgp->v_establish_wait);
7989
7990 if (bgp_update_delay_active(bgp)) {
7991 vty_out(vty,
7992 " First neighbor established: %s\n",
7993 bgp->update_delay_begin_time);
7994 vty_out(vty,
7995 " Delay in progress\n");
7996 } else {
7997 if (bgp->update_delay_over) {
7998 vty_out(vty,
7999 " First neighbor established: %s\n",
8000 bgp->update_delay_begin_time);
8001 vty_out(vty,
8002 " Best-paths resumed: %s\n",
8003 bgp->update_delay_end_time);
8004 vty_out(vty,
8005 " zebra update resumed: %s\n",
8006 bgp->update_delay_zebra_resume_time);
8007 vty_out(vty,
8008 " peers update resumed: %s\n",
8009 bgp->update_delay_peers_resume_time);
8010 }
8011 }
8012 }
8013 }
8014
8015 if (use_json) {
8016 if (bgp_maxmed_onstartup_configured(bgp)
8017 && bgp->maxmed_active)
8018 json_object_boolean_true_add(
8019 json, "maxMedOnStartup");
8020 if (bgp->v_maxmed_admin)
8021 json_object_boolean_true_add(
8022 json, "maxMedAdministrative");
8023
8024 json_object_int_add(
8025 json, "tableVersion",
8026 bgp_table_version(bgp->rib[afi][safi]));
8027
8028 ents = bgp_table_count(bgp->rib[afi][safi]);
8029 json_object_int_add(json, "ribCount", ents);
8030 json_object_int_add(
8031 json, "ribMemory",
8032 ents * sizeof(struct bgp_node));
8033
8034 ents = listcount(bgp->peer);
8035 json_object_int_add(json, "peerCount", ents);
8036 json_object_int_add(json, "peerMemory",
8037 ents * sizeof(struct peer));
8038
8039 if ((ents = listcount(bgp->group))) {
8040 json_object_int_add(
8041 json, "peerGroupCount", ents);
8042 json_object_int_add(
8043 json, "peerGroupMemory",
8044 ents * sizeof(struct
8045 peer_group));
8046 }
8047
8048 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8049 BGP_CONFIG_DAMPENING))
8050 json_object_boolean_true_add(
8051 json, "dampeningEnabled");
8052 } else {
8053 if (bgp_maxmed_onstartup_configured(bgp)
8054 && bgp->maxmed_active)
8055 vty_out(vty,
8056 "Max-med on-startup active\n");
8057 if (bgp->v_maxmed_admin)
8058 vty_out(vty,
8059 "Max-med administrative active\n");
8060
8061 vty_out(vty, "BGP table version %" PRIu64 "\n",
8062 bgp_table_version(bgp->rib[afi][safi]));
8063
8064 ents = bgp_table_count(bgp->rib[afi][safi]);
8065 vty_out(vty,
8066 "RIB entries %ld, using %s of memory\n",
8067 ents,
8068 mtype_memstr(memstrbuf,
8069 sizeof(memstrbuf),
8070 ents * sizeof(struct
8071 bgp_node)));
8072
8073 /* Peer related usage */
8074 ents = listcount(bgp->peer);
8075 vty_out(vty, "Peers %ld, using %s of memory\n",
8076 ents,
8077 mtype_memstr(
8078 memstrbuf, sizeof(memstrbuf),
8079 ents * sizeof(struct peer)));
8080
8081 if ((ents = listcount(bgp->group)))
8082 vty_out(vty,
8083 "Peer groups %ld, using %s of memory\n",
8084 ents,
8085 mtype_memstr(
8086 memstrbuf,
8087 sizeof(memstrbuf),
8088 ents * sizeof(struct
8089 peer_group)));
8090
8091 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8092 BGP_CONFIG_DAMPENING))
8093 vty_out(vty, "Dampening enabled.\n");
8094 vty_out(vty, "\n");
8095
8096 /* Subtract 8 here because 'Neighbor' is
8097 * 8 characters */
8098 vty_out(vty, "Neighbor");
8099 vty_out(vty, "%*s", max_neighbor_width - 8,
8100 " ");
8101 vty_out(vty,
8102 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8103 }
8104 }
8105
8106 count++;
8107
8108 if (use_json) {
8109 json_peer = json_object_new_object();
8110
8111 if (peer_dynamic_neighbor(peer)) {
8112 dn_count++;
8113 json_object_boolean_true_add(json_peer,
8114 "dynamicPeer");
8115 }
8116
8117 if (peer->hostname)
8118 json_object_string_add(json_peer, "hostname",
8119 peer->hostname);
8120
8121 if (peer->domainname)
8122 json_object_string_add(json_peer, "domainname",
8123 peer->domainname);
8124
8125 json_object_int_add(json_peer, "remoteAs", peer->as);
8126 json_object_int_add(json_peer, "version", 4);
8127 json_object_int_add(json_peer, "msgRcvd",
8128 PEER_TOTAL_RX(peer));
8129 json_object_int_add(json_peer, "msgSent",
8130 PEER_TOTAL_TX(peer));
8131
8132 json_object_int_add(json_peer, "tableVersion",
8133 peer->version[afi][safi]);
8134 json_object_int_add(json_peer, "outq",
8135 peer->obuf->count);
8136 json_object_int_add(json_peer, "inq", 0);
8137 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8138 use_json, json_peer);
8139
8140 /*
8141 * Adding "pfxRcd" field to match with the corresponding
8142 * CLI. "prefixReceivedCount" will be deprecated in
8143 * future.
8144 */
8145 json_object_int_add(json_peer, "prefixReceivedCount",
8146 peer->pcount[afi][pfx_rcd_safi]);
8147 json_object_int_add(json_peer, "pfxRcd",
8148 peer->pcount[afi][pfx_rcd_safi]);
8149
8150 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8151 if (paf && PAF_SUBGRP(paf))
8152 json_object_int_add(json_peer,
8153 "pfxSnt",
8154 (PAF_SUBGRP(paf))->scount);
8155
8156 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8157 json_object_string_add(json_peer, "state",
8158 "Idle (Admin)");
8159 else if (peer->afc_recv[afi][safi])
8160 json_object_string_add(
8161 json_peer, "state",
8162 lookup_msg(bgp_status_msg, peer->status,
8163 NULL));
8164 else if (CHECK_FLAG(peer->sflags,
8165 PEER_STATUS_PREFIX_OVERFLOW))
8166 json_object_string_add(json_peer, "state",
8167 "Idle (PfxCt)");
8168 else
8169 json_object_string_add(
8170 json_peer, "state",
8171 lookup_msg(bgp_status_msg, peer->status,
8172 NULL));
8173
8174 if (peer->conf_if)
8175 json_object_string_add(json_peer, "idType",
8176 "interface");
8177 else if (peer->su.sa.sa_family == AF_INET)
8178 json_object_string_add(json_peer, "idType",
8179 "ipv4");
8180 else if (peer->su.sa.sa_family == AF_INET6)
8181 json_object_string_add(json_peer, "idType",
8182 "ipv6");
8183
8184 json_object_object_add(json_peers, peer->host,
8185 json_peer);
8186 } else {
8187 memset(dn_flag, '\0', sizeof(dn_flag));
8188 if (peer_dynamic_neighbor(peer)) {
8189 dn_count++;
8190 dn_flag[0] = '*';
8191 }
8192
8193 if (peer->hostname
8194 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8195 len = vty_out(vty, "%s%s(%s)", dn_flag,
8196 peer->hostname, peer->host);
8197 else
8198 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8199
8200 /* pad the neighbor column with spaces */
8201 if (len < max_neighbor_width)
8202 vty_out(vty, "%*s", max_neighbor_width - len,
8203 " ");
8204
8205 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8206 peer->as, PEER_TOTAL_RX(peer),
8207 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8208 0, peer->obuf->count,
8209 peer_uptime(peer->uptime, timebuf,
8210 BGP_UPTIME_LEN, 0, NULL));
8211
8212 if (peer->status == Established)
8213 if (peer->afc_recv[afi][safi])
8214 vty_out(vty, " %12ld",
8215 peer->pcount[afi]
8216 [pfx_rcd_safi]);
8217 else
8218 vty_out(vty, " NoNeg");
8219 else {
8220 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8221 vty_out(vty, " Idle (Admin)");
8222 else if (CHECK_FLAG(
8223 peer->sflags,
8224 PEER_STATUS_PREFIX_OVERFLOW))
8225 vty_out(vty, " Idle (PfxCt)");
8226 else
8227 vty_out(vty, " %12s",
8228 lookup_msg(bgp_status_msg,
8229 peer->status, NULL));
8230 }
8231 vty_out(vty, "\n");
8232 }
8233 }
8234
8235 if (use_json) {
8236 json_object_object_add(json, "peers", json_peers);
8237
8238 json_object_int_add(json, "totalPeers", count);
8239 json_object_int_add(json, "dynamicPeers", dn_count);
8240
8241 bgp_show_bestpath_json(bgp, json);
8242
8243 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8244 json, JSON_C_TO_STRING_PRETTY));
8245 json_object_free(json);
8246 } else {
8247 if (count)
8248 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8249 else {
8250 vty_out(vty, "No %s neighbor is configured\n",
8251 afi_safi_print(afi, safi));
8252 }
8253
8254 if (dn_count) {
8255 vty_out(vty, "* - dynamic neighbor\n");
8256 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8257 dn_count, bgp->dynamic_neighbors_limit);
8258 }
8259 }
8260
8261 return CMD_SUCCESS;
8262 }
8263
8264 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8265 int safi, bool use_json,
8266 json_object *json)
8267 {
8268 int is_first = 1;
8269 int afi_wildcard = (afi == AFI_MAX);
8270 int safi_wildcard = (safi == SAFI_MAX);
8271 int is_wildcard = (afi_wildcard || safi_wildcard);
8272 bool nbr_output = false;
8273
8274 if (use_json && is_wildcard)
8275 vty_out(vty, "{\n");
8276 if (afi_wildcard)
8277 afi = 1; /* AFI_IP */
8278 while (afi < AFI_MAX) {
8279 if (safi_wildcard)
8280 safi = 1; /* SAFI_UNICAST */
8281 while (safi < SAFI_MAX) {
8282 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8283 nbr_output = true;
8284 if (is_wildcard) {
8285 /*
8286 * So limit output to those afi/safi
8287 * pairs that
8288 * actualy have something interesting in
8289 * them
8290 */
8291 if (use_json) {
8292 json = json_object_new_object();
8293
8294 if (!is_first)
8295 vty_out(vty, ",\n");
8296 else
8297 is_first = 0;
8298
8299 vty_out(vty, "\"%s\":",
8300 afi_safi_json(afi,
8301 safi));
8302 } else {
8303 vty_out(vty, "\n%s Summary:\n",
8304 afi_safi_print(afi,
8305 safi));
8306 }
8307 }
8308 bgp_show_summary(vty, bgp, afi, safi, use_json,
8309 json);
8310 }
8311 safi++;
8312 if (!safi_wildcard)
8313 safi = SAFI_MAX;
8314 }
8315 afi++;
8316 if (!afi_wildcard)
8317 afi = AFI_MAX;
8318 }
8319
8320 if (use_json && is_wildcard)
8321 vty_out(vty, "}\n");
8322 else if (!nbr_output) {
8323 if (use_json)
8324 vty_out(vty, "{}\n");
8325 else
8326 vty_out(vty, "%% No BGP neighbors found\n");
8327 }
8328 }
8329
8330 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8331 safi_t safi, bool use_json)
8332 {
8333 struct listnode *node, *nnode;
8334 struct bgp *bgp;
8335 json_object *json = NULL;
8336 int is_first = 1;
8337 bool nbr_output = false;
8338
8339 if (use_json)
8340 vty_out(vty, "{\n");
8341
8342 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8343 nbr_output = true;
8344 if (use_json) {
8345 json = json_object_new_object();
8346
8347 if (!is_first)
8348 vty_out(vty, ",\n");
8349 else
8350 is_first = 0;
8351
8352 vty_out(vty, "\"%s\":",
8353 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8354 ? VRF_DEFAULT_NAME
8355 : bgp->name);
8356 } else {
8357 vty_out(vty, "\nInstance %s:\n",
8358 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8359 ? VRF_DEFAULT_NAME
8360 : bgp->name);
8361 }
8362 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8363 }
8364
8365 if (use_json)
8366 vty_out(vty, "}\n");
8367 else if (!nbr_output)
8368 vty_out(vty, "%% BGP instance not found\n");
8369 }
8370
8371 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8372 safi_t safi, bool use_json)
8373 {
8374 struct bgp *bgp;
8375
8376 if (name) {
8377 if (strmatch(name, "all")) {
8378 bgp_show_all_instances_summary_vty(vty, afi, safi,
8379 use_json);
8380 return CMD_SUCCESS;
8381 } else {
8382 bgp = bgp_lookup_by_name(name);
8383
8384 if (!bgp) {
8385 if (use_json)
8386 vty_out(vty, "{}\n");
8387 else
8388 vty_out(vty,
8389 "%% BGP instance not found\n");
8390 return CMD_WARNING;
8391 }
8392
8393 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8394 NULL);
8395 return CMD_SUCCESS;
8396 }
8397 }
8398
8399 bgp = bgp_get_default();
8400
8401 if (bgp)
8402 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8403 else {
8404 if (use_json)
8405 vty_out(vty, "{}\n");
8406 else
8407 vty_out(vty, "%% BGP instance not found\n");
8408 return CMD_WARNING;
8409 }
8410
8411 return CMD_SUCCESS;
8412 }
8413
8414 /* `show [ip] bgp summary' commands. */
8415 DEFUN (show_ip_bgp_summary,
8416 show_ip_bgp_summary_cmd,
8417 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8418 SHOW_STR
8419 IP_STR
8420 BGP_STR
8421 BGP_INSTANCE_HELP_STR
8422 BGP_AFI_HELP_STR
8423 BGP_SAFI_WITH_LABEL_HELP_STR
8424 "Summary of BGP neighbor status\n"
8425 JSON_STR)
8426 {
8427 char *vrf = NULL;
8428 afi_t afi = AFI_MAX;
8429 safi_t safi = SAFI_MAX;
8430
8431 int idx = 0;
8432
8433 /* show [ip] bgp */
8434 if (argv_find(argv, argc, "ip", &idx))
8435 afi = AFI_IP;
8436 /* [<vrf> VIEWVRFNAME] */
8437 if (argv_find(argv, argc, "vrf", &idx)) {
8438 vrf = argv[idx + 1]->arg;
8439 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8440 vrf = NULL;
8441 } else if (argv_find(argv, argc, "view", &idx))
8442 /* [<view> VIEWVRFNAME] */
8443 vrf = argv[idx + 1]->arg;
8444 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8445 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8446 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8447 }
8448
8449 bool uj = use_json(argc, argv);
8450
8451 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8452 }
8453
8454 const char *afi_safi_print(afi_t afi, safi_t safi)
8455 {
8456 if (afi == AFI_IP && safi == SAFI_UNICAST)
8457 return "IPv4 Unicast";
8458 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8459 return "IPv4 Multicast";
8460 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8461 return "IPv4 Labeled Unicast";
8462 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8463 return "IPv4 VPN";
8464 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8465 return "IPv4 Encap";
8466 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8467 return "IPv4 Flowspec";
8468 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8469 return "IPv6 Unicast";
8470 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8471 return "IPv6 Multicast";
8472 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8473 return "IPv6 Labeled Unicast";
8474 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8475 return "IPv6 VPN";
8476 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8477 return "IPv6 Encap";
8478 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8479 return "IPv6 Flowspec";
8480 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8481 return "L2VPN EVPN";
8482 else
8483 return "Unknown";
8484 }
8485
8486 /*
8487 * Please note that we have intentionally camelCased
8488 * the return strings here. So if you want
8489 * to use this function, please ensure you
8490 * are doing this within json output
8491 */
8492 const char *afi_safi_json(afi_t afi, safi_t safi)
8493 {
8494 if (afi == AFI_IP && safi == SAFI_UNICAST)
8495 return "ipv4Unicast";
8496 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8497 return "ipv4Multicast";
8498 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8499 return "ipv4LabeledUnicast";
8500 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8501 return "ipv4Vpn";
8502 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8503 return "ipv4Encap";
8504 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8505 return "ipv4Flowspec";
8506 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8507 return "ipv6Unicast";
8508 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8509 return "ipv6Multicast";
8510 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8511 return "ipv6LabeledUnicast";
8512 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8513 return "ipv6Vpn";
8514 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8515 return "ipv6Encap";
8516 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8517 return "ipv6Flowspec";
8518 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8519 return "l2VpnEvpn";
8520 else
8521 return "Unknown";
8522 }
8523
8524 /* Show BGP peer's information. */
8525 enum show_type { show_all, show_peer };
8526
8527 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8528 afi_t afi, safi_t safi,
8529 uint16_t adv_smcap, uint16_t adv_rmcap,
8530 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8531 bool use_json, json_object *json_pref)
8532 {
8533 /* Send-Mode */
8534 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8535 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8536 if (use_json) {
8537 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8538 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8539 json_object_string_add(json_pref, "sendMode",
8540 "advertisedAndReceived");
8541 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8542 json_object_string_add(json_pref, "sendMode",
8543 "advertised");
8544 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8545 json_object_string_add(json_pref, "sendMode",
8546 "received");
8547 } else {
8548 vty_out(vty, " Send-mode: ");
8549 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8550 vty_out(vty, "advertised");
8551 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8552 vty_out(vty, "%sreceived",
8553 CHECK_FLAG(p->af_cap[afi][safi],
8554 adv_smcap)
8555 ? ", "
8556 : "");
8557 vty_out(vty, "\n");
8558 }
8559 }
8560
8561 /* Receive-Mode */
8562 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8563 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8564 if (use_json) {
8565 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8566 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8567 json_object_string_add(json_pref, "recvMode",
8568 "advertisedAndReceived");
8569 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8570 json_object_string_add(json_pref, "recvMode",
8571 "advertised");
8572 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8573 json_object_string_add(json_pref, "recvMode",
8574 "received");
8575 } else {
8576 vty_out(vty, " Receive-mode: ");
8577 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8578 vty_out(vty, "advertised");
8579 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8580 vty_out(vty, "%sreceived",
8581 CHECK_FLAG(p->af_cap[afi][safi],
8582 adv_rmcap)
8583 ? ", "
8584 : "");
8585 vty_out(vty, "\n");
8586 }
8587 }
8588 }
8589
8590 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8591 safi_t safi, bool use_json,
8592 json_object *json_neigh)
8593 {
8594 struct bgp_filter *filter;
8595 struct peer_af *paf;
8596 char orf_pfx_name[BUFSIZ];
8597 int orf_pfx_count;
8598 json_object *json_af = NULL;
8599 json_object *json_prefA = NULL;
8600 json_object *json_prefB = NULL;
8601 json_object *json_addr = NULL;
8602
8603 if (use_json) {
8604 json_addr = json_object_new_object();
8605 json_af = json_object_new_object();
8606 filter = &p->filter[afi][safi];
8607
8608 if (peer_group_active(p))
8609 json_object_string_add(json_addr, "peerGroupMember",
8610 p->group->name);
8611
8612 paf = peer_af_find(p, afi, safi);
8613 if (paf && PAF_SUBGRP(paf)) {
8614 json_object_int_add(json_addr, "updateGroupId",
8615 PAF_UPDGRP(paf)->id);
8616 json_object_int_add(json_addr, "subGroupId",
8617 PAF_SUBGRP(paf)->id);
8618 json_object_int_add(json_addr, "packetQueueLength",
8619 bpacket_queue_virtual_length(paf));
8620 }
8621
8622 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8623 || CHECK_FLAG(p->af_cap[afi][safi],
8624 PEER_CAP_ORF_PREFIX_SM_RCV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_RM_ADV)
8627 || CHECK_FLAG(p->af_cap[afi][safi],
8628 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8629 json_object_int_add(json_af, "orfType",
8630 ORF_TYPE_PREFIX);
8631 json_prefA = json_object_new_object();
8632 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8633 PEER_CAP_ORF_PREFIX_SM_ADV,
8634 PEER_CAP_ORF_PREFIX_RM_ADV,
8635 PEER_CAP_ORF_PREFIX_SM_RCV,
8636 PEER_CAP_ORF_PREFIX_RM_RCV,
8637 use_json, json_prefA);
8638 json_object_object_add(json_af, "orfPrefixList",
8639 json_prefA);
8640 }
8641
8642 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8643 || CHECK_FLAG(p->af_cap[afi][safi],
8644 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8645 || CHECK_FLAG(p->af_cap[afi][safi],
8646 PEER_CAP_ORF_PREFIX_RM_ADV)
8647 || CHECK_FLAG(p->af_cap[afi][safi],
8648 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8649 json_object_int_add(json_af, "orfOldType",
8650 ORF_TYPE_PREFIX_OLD);
8651 json_prefB = json_object_new_object();
8652 bgp_show_peer_afi_orf_cap(
8653 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8654 PEER_CAP_ORF_PREFIX_RM_ADV,
8655 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8656 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8657 json_prefB);
8658 json_object_object_add(json_af, "orfOldPrefixList",
8659 json_prefB);
8660 }
8661
8662 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8663 || CHECK_FLAG(p->af_cap[afi][safi],
8664 PEER_CAP_ORF_PREFIX_SM_RCV)
8665 || CHECK_FLAG(p->af_cap[afi][safi],
8666 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8667 || CHECK_FLAG(p->af_cap[afi][safi],
8668 PEER_CAP_ORF_PREFIX_RM_ADV)
8669 || CHECK_FLAG(p->af_cap[afi][safi],
8670 PEER_CAP_ORF_PREFIX_RM_RCV)
8671 || CHECK_FLAG(p->af_cap[afi][safi],
8672 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8673 json_object_object_add(json_addr, "afDependentCap",
8674 json_af);
8675 else
8676 json_object_free(json_af);
8677
8678 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8679 orf_pfx_count = prefix_bgp_show_prefix_list(
8680 NULL, afi, orf_pfx_name, use_json);
8681
8682 if (CHECK_FLAG(p->af_sflags[afi][safi],
8683 PEER_STATUS_ORF_PREFIX_SEND)
8684 || orf_pfx_count) {
8685 if (CHECK_FLAG(p->af_sflags[afi][safi],
8686 PEER_STATUS_ORF_PREFIX_SEND))
8687 json_object_boolean_true_add(json_neigh,
8688 "orfSent");
8689 if (orf_pfx_count)
8690 json_object_int_add(json_addr, "orfRecvCounter",
8691 orf_pfx_count);
8692 }
8693 if (CHECK_FLAG(p->af_sflags[afi][safi],
8694 PEER_STATUS_ORF_WAIT_REFRESH))
8695 json_object_string_add(
8696 json_addr, "orfFirstUpdate",
8697 "deferredUntilORFOrRouteRefreshRecvd");
8698
8699 if (CHECK_FLAG(p->af_flags[afi][safi],
8700 PEER_FLAG_REFLECTOR_CLIENT))
8701 json_object_boolean_true_add(json_addr,
8702 "routeReflectorClient");
8703 if (CHECK_FLAG(p->af_flags[afi][safi],
8704 PEER_FLAG_RSERVER_CLIENT))
8705 json_object_boolean_true_add(json_addr,
8706 "routeServerClient");
8707 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8708 json_object_boolean_true_add(json_addr,
8709 "inboundSoftConfigPermit");
8710
8711 if (CHECK_FLAG(p->af_flags[afi][safi],
8712 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8713 json_object_boolean_true_add(
8714 json_addr,
8715 "privateAsNumsAllReplacedInUpdatesToNbr");
8716 else if (CHECK_FLAG(p->af_flags[afi][safi],
8717 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8718 json_object_boolean_true_add(
8719 json_addr,
8720 "privateAsNumsReplacedInUpdatesToNbr");
8721 else if (CHECK_FLAG(p->af_flags[afi][safi],
8722 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8723 json_object_boolean_true_add(
8724 json_addr,
8725 "privateAsNumsAllRemovedInUpdatesToNbr");
8726 else if (CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_REMOVE_PRIVATE_AS))
8728 json_object_boolean_true_add(
8729 json_addr,
8730 "privateAsNumsRemovedInUpdatesToNbr");
8731
8732 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8733 json_object_boolean_true_add(
8734 json_addr,
8735 bgp_addpath_names(p->addpath_type[afi][safi])
8736 ->type_json_name);
8737
8738 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8739 json_object_string_add(json_addr,
8740 "overrideASNsInOutboundUpdates",
8741 "ifAspathEqualRemoteAs");
8742
8743 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8744 || CHECK_FLAG(p->af_flags[afi][safi],
8745 PEER_FLAG_FORCE_NEXTHOP_SELF))
8746 json_object_boolean_true_add(json_addr,
8747 "routerAlwaysNextHop");
8748 if (CHECK_FLAG(p->af_flags[afi][safi],
8749 PEER_FLAG_AS_PATH_UNCHANGED))
8750 json_object_boolean_true_add(
8751 json_addr, "unchangedAsPathPropogatedToNbr");
8752 if (CHECK_FLAG(p->af_flags[afi][safi],
8753 PEER_FLAG_NEXTHOP_UNCHANGED))
8754 json_object_boolean_true_add(
8755 json_addr, "unchangedNextHopPropogatedToNbr");
8756 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8757 json_object_boolean_true_add(
8758 json_addr, "unchangedMedPropogatedToNbr");
8759 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8760 || CHECK_FLAG(p->af_flags[afi][safi],
8761 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8762 if (CHECK_FLAG(p->af_flags[afi][safi],
8763 PEER_FLAG_SEND_COMMUNITY)
8764 && CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_SEND_EXT_COMMUNITY))
8766 json_object_string_add(json_addr,
8767 "commAttriSentToNbr",
8768 "extendedAndStandard");
8769 else if (CHECK_FLAG(p->af_flags[afi][safi],
8770 PEER_FLAG_SEND_EXT_COMMUNITY))
8771 json_object_string_add(json_addr,
8772 "commAttriSentToNbr",
8773 "extended");
8774 else
8775 json_object_string_add(json_addr,
8776 "commAttriSentToNbr",
8777 "standard");
8778 }
8779 if (CHECK_FLAG(p->af_flags[afi][safi],
8780 PEER_FLAG_DEFAULT_ORIGINATE)) {
8781 if (p->default_rmap[afi][safi].name)
8782 json_object_string_add(
8783 json_addr, "defaultRouteMap",
8784 p->default_rmap[afi][safi].name);
8785
8786 if (paf && PAF_SUBGRP(paf)
8787 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8788 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8789 json_object_boolean_true_add(json_addr,
8790 "defaultSent");
8791 else
8792 json_object_boolean_true_add(json_addr,
8793 "defaultNotSent");
8794 }
8795
8796 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8797 if (is_evpn_enabled())
8798 json_object_boolean_true_add(
8799 json_addr, "advertiseAllVnis");
8800 }
8801
8802 if (filter->plist[FILTER_IN].name
8803 || filter->dlist[FILTER_IN].name
8804 || filter->aslist[FILTER_IN].name
8805 || filter->map[RMAP_IN].name)
8806 json_object_boolean_true_add(json_addr,
8807 "inboundPathPolicyConfig");
8808 if (filter->plist[FILTER_OUT].name
8809 || filter->dlist[FILTER_OUT].name
8810 || filter->aslist[FILTER_OUT].name
8811 || filter->map[RMAP_OUT].name || filter->usmap.name)
8812 json_object_boolean_true_add(
8813 json_addr, "outboundPathPolicyConfig");
8814
8815 /* prefix-list */
8816 if (filter->plist[FILTER_IN].name)
8817 json_object_string_add(json_addr,
8818 "incomingUpdatePrefixFilterList",
8819 filter->plist[FILTER_IN].name);
8820 if (filter->plist[FILTER_OUT].name)
8821 json_object_string_add(json_addr,
8822 "outgoingUpdatePrefixFilterList",
8823 filter->plist[FILTER_OUT].name);
8824
8825 /* distribute-list */
8826 if (filter->dlist[FILTER_IN].name)
8827 json_object_string_add(
8828 json_addr, "incomingUpdateNetworkFilterList",
8829 filter->dlist[FILTER_IN].name);
8830 if (filter->dlist[FILTER_OUT].name)
8831 json_object_string_add(
8832 json_addr, "outgoingUpdateNetworkFilterList",
8833 filter->dlist[FILTER_OUT].name);
8834
8835 /* filter-list. */
8836 if (filter->aslist[FILTER_IN].name)
8837 json_object_string_add(json_addr,
8838 "incomingUpdateAsPathFilterList",
8839 filter->aslist[FILTER_IN].name);
8840 if (filter->aslist[FILTER_OUT].name)
8841 json_object_string_add(json_addr,
8842 "outgoingUpdateAsPathFilterList",
8843 filter->aslist[FILTER_OUT].name);
8844
8845 /* route-map. */
8846 if (filter->map[RMAP_IN].name)
8847 json_object_string_add(
8848 json_addr, "routeMapForIncomingAdvertisements",
8849 filter->map[RMAP_IN].name);
8850 if (filter->map[RMAP_OUT].name)
8851 json_object_string_add(
8852 json_addr, "routeMapForOutgoingAdvertisements",
8853 filter->map[RMAP_OUT].name);
8854
8855 /* ebgp-requires-policy (inbound) */
8856 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8857 && !bgp_inbound_policy_exists(p, filter))
8858 json_object_string_add(
8859 json_addr, "inboundEbgpRequiresPolicy",
8860 "Inbound updates discarded due to missing policy");
8861
8862 /* ebgp-requires-policy (outbound) */
8863 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
8864 && (!bgp_outbound_policy_exists(p, filter)))
8865 json_object_string_add(
8866 json_addr, "outboundEbgpRequiresPolicy",
8867 "Outbound updates discarded due to missing policy");
8868
8869 /* unsuppress-map */
8870 if (filter->usmap.name)
8871 json_object_string_add(json_addr,
8872 "selectiveUnsuppressRouteMap",
8873 filter->usmap.name);
8874
8875 /* Receive prefix count */
8876 json_object_int_add(json_addr, "acceptedPrefixCounter",
8877 p->pcount[afi][safi]);
8878 if (paf && PAF_SUBGRP(paf))
8879 json_object_int_add(json_addr, "sentPrefixCounter",
8880 (PAF_SUBGRP(paf))->scount);
8881
8882 /* Maximum prefix */
8883 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8884 json_object_int_add(json_addr, "prefixAllowedMax",
8885 p->pmax[afi][safi]);
8886 if (CHECK_FLAG(p->af_flags[afi][safi],
8887 PEER_FLAG_MAX_PREFIX_WARNING))
8888 json_object_boolean_true_add(
8889 json_addr, "prefixAllowedMaxWarning");
8890 json_object_int_add(json_addr,
8891 "prefixAllowedWarningThresh",
8892 p->pmax_threshold[afi][safi]);
8893 if (p->pmax_restart[afi][safi])
8894 json_object_int_add(
8895 json_addr,
8896 "prefixAllowedRestartIntervalMsecs",
8897 p->pmax_restart[afi][safi] * 60000);
8898 }
8899 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8900 json_addr);
8901
8902 } else {
8903 filter = &p->filter[afi][safi];
8904
8905 vty_out(vty, " For address family: %s\n",
8906 afi_safi_print(afi, safi));
8907
8908 if (peer_group_active(p))
8909 vty_out(vty, " %s peer-group member\n",
8910 p->group->name);
8911
8912 paf = peer_af_find(p, afi, safi);
8913 if (paf && PAF_SUBGRP(paf)) {
8914 vty_out(vty, " Update group %" PRIu64
8915 ", subgroup %" PRIu64 "\n",
8916 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8917 vty_out(vty, " Packet Queue length %d\n",
8918 bpacket_queue_virtual_length(paf));
8919 } else {
8920 vty_out(vty, " Not part of any update group\n");
8921 }
8922 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8923 || CHECK_FLAG(p->af_cap[afi][safi],
8924 PEER_CAP_ORF_PREFIX_SM_RCV)
8925 || CHECK_FLAG(p->af_cap[afi][safi],
8926 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8927 || CHECK_FLAG(p->af_cap[afi][safi],
8928 PEER_CAP_ORF_PREFIX_RM_ADV)
8929 || CHECK_FLAG(p->af_cap[afi][safi],
8930 PEER_CAP_ORF_PREFIX_RM_RCV)
8931 || CHECK_FLAG(p->af_cap[afi][safi],
8932 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8933 vty_out(vty, " AF-dependant capabilities:\n");
8934
8935 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8936 || CHECK_FLAG(p->af_cap[afi][safi],
8937 PEER_CAP_ORF_PREFIX_SM_RCV)
8938 || CHECK_FLAG(p->af_cap[afi][safi],
8939 PEER_CAP_ORF_PREFIX_RM_ADV)
8940 || CHECK_FLAG(p->af_cap[afi][safi],
8941 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8942 vty_out(vty,
8943 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8944 ORF_TYPE_PREFIX);
8945 bgp_show_peer_afi_orf_cap(
8946 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8947 PEER_CAP_ORF_PREFIX_RM_ADV,
8948 PEER_CAP_ORF_PREFIX_SM_RCV,
8949 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8950 }
8951 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8952 || CHECK_FLAG(p->af_cap[afi][safi],
8953 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8954 || CHECK_FLAG(p->af_cap[afi][safi],
8955 PEER_CAP_ORF_PREFIX_RM_ADV)
8956 || CHECK_FLAG(p->af_cap[afi][safi],
8957 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8958 vty_out(vty,
8959 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8960 ORF_TYPE_PREFIX_OLD);
8961 bgp_show_peer_afi_orf_cap(
8962 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8963 PEER_CAP_ORF_PREFIX_RM_ADV,
8964 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8965 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8966 }
8967
8968 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8969 orf_pfx_count = prefix_bgp_show_prefix_list(
8970 NULL, afi, orf_pfx_name, use_json);
8971
8972 if (CHECK_FLAG(p->af_sflags[afi][safi],
8973 PEER_STATUS_ORF_PREFIX_SEND)
8974 || orf_pfx_count) {
8975 vty_out(vty, " Outbound Route Filter (ORF):");
8976 if (CHECK_FLAG(p->af_sflags[afi][safi],
8977 PEER_STATUS_ORF_PREFIX_SEND))
8978 vty_out(vty, " sent;");
8979 if (orf_pfx_count)
8980 vty_out(vty, " received (%d entries)",
8981 orf_pfx_count);
8982 vty_out(vty, "\n");
8983 }
8984 if (CHECK_FLAG(p->af_sflags[afi][safi],
8985 PEER_STATUS_ORF_WAIT_REFRESH))
8986 vty_out(vty,
8987 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8988
8989 if (CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_REFLECTOR_CLIENT))
8991 vty_out(vty, " Route-Reflector Client\n");
8992 if (CHECK_FLAG(p->af_flags[afi][safi],
8993 PEER_FLAG_RSERVER_CLIENT))
8994 vty_out(vty, " Route-Server Client\n");
8995 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8996 vty_out(vty,
8997 " Inbound soft reconfiguration allowed\n");
8998
8999 if (CHECK_FLAG(p->af_flags[afi][safi],
9000 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
9001 vty_out(vty,
9002 " Private AS numbers (all) replaced in updates to this neighbor\n");
9003 else if (CHECK_FLAG(p->af_flags[afi][safi],
9004 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
9005 vty_out(vty,
9006 " Private AS numbers replaced in updates to this neighbor\n");
9007 else if (CHECK_FLAG(p->af_flags[afi][safi],
9008 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
9009 vty_out(vty,
9010 " Private AS numbers (all) removed in updates to this neighbor\n");
9011 else if (CHECK_FLAG(p->af_flags[afi][safi],
9012 PEER_FLAG_REMOVE_PRIVATE_AS))
9013 vty_out(vty,
9014 " Private AS numbers removed in updates to this neighbor\n");
9015
9016 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
9017 vty_out(vty, " %s\n",
9018 bgp_addpath_names(p->addpath_type[afi][safi])
9019 ->human_description);
9020
9021 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
9022 vty_out(vty,
9023 " Override ASNs in outbound updates if aspath equals remote-as\n");
9024
9025 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
9026 || CHECK_FLAG(p->af_flags[afi][safi],
9027 PEER_FLAG_FORCE_NEXTHOP_SELF))
9028 vty_out(vty, " NEXT_HOP is always this router\n");
9029 if (CHECK_FLAG(p->af_flags[afi][safi],
9030 PEER_FLAG_AS_PATH_UNCHANGED))
9031 vty_out(vty,
9032 " AS_PATH is propagated unchanged to this neighbor\n");
9033 if (CHECK_FLAG(p->af_flags[afi][safi],
9034 PEER_FLAG_NEXTHOP_UNCHANGED))
9035 vty_out(vty,
9036 " NEXT_HOP is propagated unchanged to this neighbor\n");
9037 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
9038 vty_out(vty,
9039 " MED is propagated unchanged to this neighbor\n");
9040 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
9041 || CHECK_FLAG(p->af_flags[afi][safi],
9042 PEER_FLAG_SEND_EXT_COMMUNITY)
9043 || CHECK_FLAG(p->af_flags[afi][safi],
9044 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
9045 vty_out(vty,
9046 " Community attribute sent to this neighbor");
9047 if (CHECK_FLAG(p->af_flags[afi][safi],
9048 PEER_FLAG_SEND_COMMUNITY)
9049 && CHECK_FLAG(p->af_flags[afi][safi],
9050 PEER_FLAG_SEND_EXT_COMMUNITY)
9051 && CHECK_FLAG(p->af_flags[afi][safi],
9052 PEER_FLAG_SEND_LARGE_COMMUNITY))
9053 vty_out(vty, "(all)\n");
9054 else if (CHECK_FLAG(p->af_flags[afi][safi],
9055 PEER_FLAG_SEND_LARGE_COMMUNITY))
9056 vty_out(vty, "(large)\n");
9057 else if (CHECK_FLAG(p->af_flags[afi][safi],
9058 PEER_FLAG_SEND_EXT_COMMUNITY))
9059 vty_out(vty, "(extended)\n");
9060 else
9061 vty_out(vty, "(standard)\n");
9062 }
9063 if (CHECK_FLAG(p->af_flags[afi][safi],
9064 PEER_FLAG_DEFAULT_ORIGINATE)) {
9065 vty_out(vty, " Default information originate,");
9066
9067 if (p->default_rmap[afi][safi].name)
9068 vty_out(vty, " default route-map %s%s,",
9069 p->default_rmap[afi][safi].map ? "*"
9070 : "",
9071 p->default_rmap[afi][safi].name);
9072 if (paf && PAF_SUBGRP(paf)
9073 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9074 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9075 vty_out(vty, " default sent\n");
9076 else
9077 vty_out(vty, " default not sent\n");
9078 }
9079
9080 /* advertise-vni-all */
9081 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9082 if (is_evpn_enabled())
9083 vty_out(vty, " advertise-all-vni\n");
9084 }
9085
9086 if (filter->plist[FILTER_IN].name
9087 || filter->dlist[FILTER_IN].name
9088 || filter->aslist[FILTER_IN].name
9089 || filter->map[RMAP_IN].name)
9090 vty_out(vty, " Inbound path policy configured\n");
9091 if (filter->plist[FILTER_OUT].name
9092 || filter->dlist[FILTER_OUT].name
9093 || filter->aslist[FILTER_OUT].name
9094 || filter->map[RMAP_OUT].name || filter->usmap.name)
9095 vty_out(vty, " Outbound path policy configured\n");
9096
9097 /* prefix-list */
9098 if (filter->plist[FILTER_IN].name)
9099 vty_out(vty,
9100 " Incoming update prefix filter list is %s%s\n",
9101 filter->plist[FILTER_IN].plist ? "*" : "",
9102 filter->plist[FILTER_IN].name);
9103 if (filter->plist[FILTER_OUT].name)
9104 vty_out(vty,
9105 " Outgoing update prefix filter list is %s%s\n",
9106 filter->plist[FILTER_OUT].plist ? "*" : "",
9107 filter->plist[FILTER_OUT].name);
9108
9109 /* distribute-list */
9110 if (filter->dlist[FILTER_IN].name)
9111 vty_out(vty,
9112 " Incoming update network filter list is %s%s\n",
9113 filter->dlist[FILTER_IN].alist ? "*" : "",
9114 filter->dlist[FILTER_IN].name);
9115 if (filter->dlist[FILTER_OUT].name)
9116 vty_out(vty,
9117 " Outgoing update network filter list is %s%s\n",
9118 filter->dlist[FILTER_OUT].alist ? "*" : "",
9119 filter->dlist[FILTER_OUT].name);
9120
9121 /* filter-list. */
9122 if (filter->aslist[FILTER_IN].name)
9123 vty_out(vty,
9124 " Incoming update AS path filter list is %s%s\n",
9125 filter->aslist[FILTER_IN].aslist ? "*" : "",
9126 filter->aslist[FILTER_IN].name);
9127 if (filter->aslist[FILTER_OUT].name)
9128 vty_out(vty,
9129 " Outgoing update AS path filter list is %s%s\n",
9130 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9131 filter->aslist[FILTER_OUT].name);
9132
9133 /* route-map. */
9134 if (filter->map[RMAP_IN].name)
9135 vty_out(vty,
9136 " Route map for incoming advertisements is %s%s\n",
9137 filter->map[RMAP_IN].map ? "*" : "",
9138 filter->map[RMAP_IN].name);
9139 if (filter->map[RMAP_OUT].name)
9140 vty_out(vty,
9141 " Route map for outgoing advertisements is %s%s\n",
9142 filter->map[RMAP_OUT].map ? "*" : "",
9143 filter->map[RMAP_OUT].name);
9144
9145 /* ebgp-requires-policy (inbound) */
9146 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9147 && !bgp_inbound_policy_exists(p, filter))
9148 vty_out(vty,
9149 " Inbound updates discarded due to missing policy\n");
9150
9151 /* ebgp-requires-policy (outbound) */
9152 if (p->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED
9153 && !bgp_outbound_policy_exists(p, filter))
9154 vty_out(vty,
9155 " Outbound updates discarded due to missing policy\n");
9156
9157 /* unsuppress-map */
9158 if (filter->usmap.name)
9159 vty_out(vty,
9160 " Route map for selective unsuppress is %s%s\n",
9161 filter->usmap.map ? "*" : "",
9162 filter->usmap.name);
9163
9164 /* Receive prefix count */
9165 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9166
9167 /* Maximum prefix */
9168 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9169 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9170 p->pmax[afi][safi],
9171 CHECK_FLAG(p->af_flags[afi][safi],
9172 PEER_FLAG_MAX_PREFIX_WARNING)
9173 ? " (warning-only)"
9174 : "");
9175 vty_out(vty, " Threshold for warning message %d%%",
9176 p->pmax_threshold[afi][safi]);
9177 if (p->pmax_restart[afi][safi])
9178 vty_out(vty, ", restart interval %d min",
9179 p->pmax_restart[afi][safi]);
9180 vty_out(vty, "\n");
9181 }
9182
9183 vty_out(vty, "\n");
9184 }
9185 }
9186
9187 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9188 json_object *json)
9189 {
9190 struct bgp *bgp;
9191 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9192 char timebuf[BGP_UPTIME_LEN];
9193 char dn_flag[2];
9194 const char *subcode_str;
9195 const char *code_str;
9196 afi_t afi;
9197 safi_t safi;
9198 uint16_t i;
9199 uint8_t *msg;
9200 json_object *json_neigh = NULL;
9201 time_t epoch_tbuf;
9202
9203 bgp = p->bgp;
9204
9205 if (use_json)
9206 json_neigh = json_object_new_object();
9207
9208 memset(dn_flag, '\0', sizeof(dn_flag));
9209 if (!p->conf_if && peer_dynamic_neighbor(p))
9210 dn_flag[0] = '*';
9211
9212 if (!use_json) {
9213 if (p->conf_if) /* Configured interface name. */
9214 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9215 BGP_PEER_SU_UNSPEC(p)
9216 ? "None"
9217 : sockunion2str(&p->su, buf,
9218 SU_ADDRSTRLEN));
9219 else /* Configured IP address. */
9220 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9221 p->host);
9222 }
9223
9224 if (use_json) {
9225 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9226 json_object_string_add(json_neigh, "bgpNeighborAddr",
9227 "none");
9228 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9229 json_object_string_add(
9230 json_neigh, "bgpNeighborAddr",
9231 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9232
9233 json_object_int_add(json_neigh, "remoteAs", p->as);
9234
9235 if (p->change_local_as)
9236 json_object_int_add(json_neigh, "localAs",
9237 p->change_local_as);
9238 else
9239 json_object_int_add(json_neigh, "localAs", p->local_as);
9240
9241 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9242 json_object_boolean_true_add(json_neigh,
9243 "localAsNoPrepend");
9244
9245 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9246 json_object_boolean_true_add(json_neigh,
9247 "localAsReplaceAs");
9248 } else {
9249 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9250 || (p->as_type == AS_INTERNAL))
9251 vty_out(vty, "remote AS %u, ", p->as);
9252 else
9253 vty_out(vty, "remote AS Unspecified, ");
9254 vty_out(vty, "local AS %u%s%s, ",
9255 p->change_local_as ? p->change_local_as : p->local_as,
9256 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9257 ? " no-prepend"
9258 : "",
9259 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9260 ? " replace-as"
9261 : "");
9262 }
9263 /* peer type internal or confed-internal */
9264 if ((p->as == p->local_as) || (p->as_type == AS_INTERNAL)) {
9265 if (use_json) {
9266 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9267 json_object_boolean_true_add(
9268 json_neigh, "nbrConfedInternalLink");
9269 else
9270 json_object_boolean_true_add(json_neigh,
9271 "nbrInternalLink");
9272 } else {
9273 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9274 vty_out(vty, "confed-internal link\n");
9275 else
9276 vty_out(vty, "internal link\n");
9277 }
9278 /* peer type external or confed-external */
9279 } else if (p->as || (p->as_type == AS_EXTERNAL)) {
9280 if (use_json) {
9281 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9282 json_object_boolean_true_add(
9283 json_neigh, "nbrConfedExternalLink");
9284 else
9285 json_object_boolean_true_add(json_neigh,
9286 "nbrExternalLink");
9287 } else {
9288 if (bgp_confederation_peers_check(bgp, p->as))
9289 vty_out(vty, "confed-external link\n");
9290 else
9291 vty_out(vty, "external link\n");
9292 }
9293 } else {
9294 if (use_json)
9295 json_object_boolean_true_add(json_neigh,
9296 "nbrUnspecifiedLink");
9297 else
9298 vty_out(vty, "unspecified link\n");
9299 }
9300
9301 /* Description. */
9302 if (p->desc) {
9303 if (use_json)
9304 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9305 else
9306 vty_out(vty, " Description: %s\n", p->desc);
9307 }
9308
9309 if (p->hostname) {
9310 if (use_json) {
9311 if (p->hostname)
9312 json_object_string_add(json_neigh, "hostname",
9313 p->hostname);
9314
9315 if (p->domainname)
9316 json_object_string_add(json_neigh, "domainname",
9317 p->domainname);
9318 } else {
9319 if (p->domainname && (p->domainname[0] != '\0'))
9320 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9321 p->domainname);
9322 else
9323 vty_out(vty, "Hostname: %s\n", p->hostname);
9324 }
9325 }
9326
9327 /* Peer-group */
9328 if (p->group) {
9329 if (use_json) {
9330 json_object_string_add(json_neigh, "peerGroup",
9331 p->group->name);
9332
9333 if (dn_flag[0]) {
9334 struct prefix prefix, *range = NULL;
9335
9336 sockunion2hostprefix(&(p->su), &prefix);
9337 range = peer_group_lookup_dynamic_neighbor_range(
9338 p->group, &prefix);
9339
9340 if (range) {
9341 prefix2str(range, buf1, sizeof(buf1));
9342 json_object_string_add(
9343 json_neigh,
9344 "peerSubnetRangeGroup", buf1);
9345 }
9346 }
9347 } else {
9348 vty_out(vty,
9349 " Member of peer-group %s for session parameters\n",
9350 p->group->name);
9351
9352 if (dn_flag[0]) {
9353 struct prefix prefix, *range = NULL;
9354
9355 sockunion2hostprefix(&(p->su), &prefix);
9356 range = peer_group_lookup_dynamic_neighbor_range(
9357 p->group, &prefix);
9358
9359 if (range) {
9360 prefix2str(range, buf1, sizeof(buf1));
9361 vty_out(vty,
9362 " Belongs to the subnet range group: %s\n",
9363 buf1);
9364 }
9365 }
9366 }
9367 }
9368
9369 if (use_json) {
9370 /* Administrative shutdown. */
9371 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9372 json_object_boolean_true_add(json_neigh,
9373 "adminShutDown");
9374
9375 /* BGP Version. */
9376 json_object_int_add(json_neigh, "bgpVersion", 4);
9377 json_object_string_add(
9378 json_neigh, "remoteRouterId",
9379 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9380 json_object_string_add(
9381 json_neigh, "localRouterId",
9382 inet_ntop(AF_INET, &bgp->router_id, buf1,
9383 sizeof(buf1)));
9384
9385 /* Confederation */
9386 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9387 && bgp_confederation_peers_check(bgp, p->as))
9388 json_object_boolean_true_add(json_neigh,
9389 "nbrCommonAdmin");
9390
9391 /* Status. */
9392 json_object_string_add(
9393 json_neigh, "bgpState",
9394 lookup_msg(bgp_status_msg, p->status, NULL));
9395
9396 if (p->status == Established) {
9397 time_t uptime;
9398
9399 uptime = bgp_clock();
9400 uptime -= p->uptime;
9401 epoch_tbuf = time(NULL) - uptime;
9402
9403 #if CONFDATE > 20200101
9404 CPP_NOTICE(
9405 "bgpTimerUp should be deprecated and can be removed now");
9406 #endif
9407 /*
9408 * bgpTimerUp was miliseconds that was accurate
9409 * up to 1 day, then the value returned
9410 * became garbage. So in order to provide
9411 * some level of backwards compatability,
9412 * we still provde the data, but now
9413 * we are returning the correct value
9414 * and also adding a new bgpTimerUpMsec
9415 * which will allow us to deprecate
9416 * this eventually
9417 */
9418 json_object_int_add(json_neigh, "bgpTimerUp",
9419 uptime * 1000);
9420 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9421 uptime * 1000);
9422 json_object_string_add(json_neigh, "bgpTimerUpString",
9423 peer_uptime(p->uptime, timebuf,
9424 BGP_UPTIME_LEN, 0,
9425 NULL));
9426 json_object_int_add(json_neigh,
9427 "bgpTimerUpEstablishedEpoch",
9428 epoch_tbuf);
9429 }
9430
9431 else if (p->status == Active) {
9432 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9433 json_object_string_add(json_neigh, "bgpStateIs",
9434 "passive");
9435 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9436 json_object_string_add(json_neigh, "bgpStateIs",
9437 "passiveNSF");
9438 }
9439
9440 /* read timer */
9441 time_t uptime;
9442 struct tm *tm;
9443
9444 uptime = bgp_clock();
9445 uptime -= p->readtime;
9446 tm = gmtime(&uptime);
9447 json_object_int_add(json_neigh, "bgpTimerLastRead",
9448 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9449 + (tm->tm_hour * 3600000));
9450
9451 uptime = bgp_clock();
9452 uptime -= p->last_write;
9453 tm = gmtime(&uptime);
9454 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9455 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9456 + (tm->tm_hour * 3600000));
9457
9458 uptime = bgp_clock();
9459 uptime -= p->update_time;
9460 tm = gmtime(&uptime);
9461 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9462 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9463 + (tm->tm_hour * 3600000));
9464
9465 /* Configured timer values. */
9466 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9467 p->v_holdtime * 1000);
9468 json_object_int_add(json_neigh,
9469 "bgpTimerKeepAliveIntervalMsecs",
9470 p->v_keepalive * 1000);
9471 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9472 json_object_int_add(json_neigh,
9473 "bgpTimerConfiguredHoldTimeMsecs",
9474 p->holdtime * 1000);
9475 json_object_int_add(
9476 json_neigh,
9477 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9478 p->keepalive * 1000);
9479 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9480 || (bgp->default_keepalive
9481 != BGP_DEFAULT_KEEPALIVE)) {
9482 json_object_int_add(json_neigh,
9483 "bgpTimerConfiguredHoldTimeMsecs",
9484 bgp->default_holdtime);
9485 json_object_int_add(
9486 json_neigh,
9487 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9488 bgp->default_keepalive);
9489 }
9490 } else {
9491 /* Administrative shutdown. */
9492 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9493 vty_out(vty, " Administratively shut down\n");
9494
9495 /* BGP Version. */
9496 vty_out(vty, " BGP version 4");
9497 vty_out(vty, ", remote router ID %s",
9498 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9499 vty_out(vty, ", local router ID %s\n",
9500 inet_ntop(AF_INET, &bgp->router_id, buf1,
9501 sizeof(buf1)));
9502
9503 /* Confederation */
9504 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9505 && bgp_confederation_peers_check(bgp, p->as))
9506 vty_out(vty,
9507 " Neighbor under common administration\n");
9508
9509 /* Status. */
9510 vty_out(vty, " BGP state = %s",
9511 lookup_msg(bgp_status_msg, p->status, NULL));
9512
9513 if (p->status == Established)
9514 vty_out(vty, ", up for %8s",
9515 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9516 0, NULL));
9517
9518 else if (p->status == Active) {
9519 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9520 vty_out(vty, " (passive)");
9521 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9522 vty_out(vty, " (NSF passive)");
9523 }
9524 vty_out(vty, "\n");
9525
9526 /* read timer */
9527 vty_out(vty, " Last read %s",
9528 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9529 NULL));
9530 vty_out(vty, ", Last write %s\n",
9531 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9532 NULL));
9533
9534 /* Configured timer values. */
9535 vty_out(vty,
9536 " Hold time is %d, keepalive interval is %d seconds\n",
9537 p->v_holdtime, p->v_keepalive);
9538 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9539 vty_out(vty, " Configured hold time is %d",
9540 p->holdtime);
9541 vty_out(vty, ", keepalive interval is %d seconds\n",
9542 p->keepalive);
9543 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9544 || (bgp->default_keepalive
9545 != BGP_DEFAULT_KEEPALIVE)) {
9546 vty_out(vty, " Configured hold time is %d",
9547 bgp->default_holdtime);
9548 vty_out(vty, ", keepalive interval is %d seconds\n",
9549 bgp->default_keepalive);
9550 }
9551 }
9552 /* Capability. */
9553 if (p->status == Established) {
9554 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9555 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9556 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9557 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9558 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9559 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9560 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9561 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9562 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9563 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9564 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9565 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9566 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9567 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9568 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9569 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9570 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9571 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9572 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9573 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9574 if (use_json) {
9575 json_object *json_cap = NULL;
9576
9577 json_cap = json_object_new_object();
9578
9579 /* AS4 */
9580 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9581 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9582 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9583 && CHECK_FLAG(p->cap,
9584 PEER_CAP_AS4_RCV))
9585 json_object_string_add(
9586 json_cap, "4byteAs",
9587 "advertisedAndReceived");
9588 else if (CHECK_FLAG(p->cap,
9589 PEER_CAP_AS4_ADV))
9590 json_object_string_add(
9591 json_cap, "4byteAs",
9592 "advertised");
9593 else if (CHECK_FLAG(p->cap,
9594 PEER_CAP_AS4_RCV))
9595 json_object_string_add(
9596 json_cap, "4byteAs",
9597 "received");
9598 }
9599
9600 /* AddPath */
9601 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9602 || CHECK_FLAG(p->cap,
9603 PEER_CAP_ADDPATH_ADV)) {
9604 json_object *json_add = NULL;
9605 const char *print_store;
9606
9607 json_add = json_object_new_object();
9608
9609 FOREACH_AFI_SAFI (afi, safi) {
9610 json_object *json_sub = NULL;
9611 json_sub =
9612 json_object_new_object();
9613 print_store = afi_safi_print(
9614 afi, safi);
9615
9616 if (CHECK_FLAG(
9617 p->af_cap[afi]
9618 [safi],
9619 PEER_CAP_ADDPATH_AF_TX_ADV)
9620 || CHECK_FLAG(
9621 p->af_cap[afi]
9622 [safi],
9623 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9624 if (CHECK_FLAG(
9625 p->af_cap
9626 [afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_TX_ADV)
9629 && CHECK_FLAG(
9630 p->af_cap
9631 [afi]
9632 [safi],
9633 PEER_CAP_ADDPATH_AF_TX_RCV))
9634 json_object_boolean_true_add(
9635 json_sub,
9636 "txAdvertisedAndReceived");
9637 else if (
9638 CHECK_FLAG(
9639 p->af_cap
9640 [afi]
9641 [safi],
9642 PEER_CAP_ADDPATH_AF_TX_ADV))
9643 json_object_boolean_true_add(
9644 json_sub,
9645 "txAdvertised");
9646 else if (
9647 CHECK_FLAG(
9648 p->af_cap
9649 [afi]
9650 [safi],
9651 PEER_CAP_ADDPATH_AF_TX_RCV))
9652 json_object_boolean_true_add(
9653 json_sub,
9654 "txReceived");
9655 }
9656
9657 if (CHECK_FLAG(
9658 p->af_cap[afi]
9659 [safi],
9660 PEER_CAP_ADDPATH_AF_RX_ADV)
9661 || CHECK_FLAG(
9662 p->af_cap[afi]
9663 [safi],
9664 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9665 if (CHECK_FLAG(
9666 p->af_cap
9667 [afi]
9668 [safi],
9669 PEER_CAP_ADDPATH_AF_RX_ADV)
9670 && CHECK_FLAG(
9671 p->af_cap
9672 [afi]
9673 [safi],
9674 PEER_CAP_ADDPATH_AF_RX_RCV))
9675 json_object_boolean_true_add(
9676 json_sub,
9677 "rxAdvertisedAndReceived");
9678 else if (
9679 CHECK_FLAG(
9680 p->af_cap
9681 [afi]
9682 [safi],
9683 PEER_CAP_ADDPATH_AF_RX_ADV))
9684 json_object_boolean_true_add(
9685 json_sub,
9686 "rxAdvertised");
9687 else if (
9688 CHECK_FLAG(
9689 p->af_cap
9690 [afi]
9691 [safi],
9692 PEER_CAP_ADDPATH_AF_RX_RCV))
9693 json_object_boolean_true_add(
9694 json_sub,
9695 "rxReceived");
9696 }
9697
9698 if (CHECK_FLAG(
9699 p->af_cap[afi]
9700 [safi],
9701 PEER_CAP_ADDPATH_AF_TX_ADV)
9702 || CHECK_FLAG(
9703 p->af_cap[afi]
9704 [safi],
9705 PEER_CAP_ADDPATH_AF_TX_RCV)
9706 || CHECK_FLAG(
9707 p->af_cap[afi]
9708 [safi],
9709 PEER_CAP_ADDPATH_AF_RX_ADV)
9710 || CHECK_FLAG(
9711 p->af_cap[afi]
9712 [safi],
9713 PEER_CAP_ADDPATH_AF_RX_RCV))
9714 json_object_object_add(
9715 json_add,
9716 print_store,
9717 json_sub);
9718 else
9719 json_object_free(
9720 json_sub);
9721 }
9722
9723 json_object_object_add(
9724 json_cap, "addPath", json_add);
9725 }
9726
9727 /* Dynamic */
9728 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9729 || CHECK_FLAG(p->cap,
9730 PEER_CAP_DYNAMIC_ADV)) {
9731 if (CHECK_FLAG(p->cap,
9732 PEER_CAP_DYNAMIC_ADV)
9733 && CHECK_FLAG(p->cap,
9734 PEER_CAP_DYNAMIC_RCV))
9735 json_object_string_add(
9736 json_cap, "dynamic",
9737 "advertisedAndReceived");
9738 else if (CHECK_FLAG(
9739 p->cap,
9740 PEER_CAP_DYNAMIC_ADV))
9741 json_object_string_add(
9742 json_cap, "dynamic",
9743 "advertised");
9744 else if (CHECK_FLAG(
9745 p->cap,
9746 PEER_CAP_DYNAMIC_RCV))
9747 json_object_string_add(
9748 json_cap, "dynamic",
9749 "received");
9750 }
9751
9752 /* Extended nexthop */
9753 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9754 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9755 json_object *json_nxt = NULL;
9756 const char *print_store;
9757
9758
9759 if (CHECK_FLAG(p->cap,
9760 PEER_CAP_ENHE_ADV)
9761 && CHECK_FLAG(p->cap,
9762 PEER_CAP_ENHE_RCV))
9763 json_object_string_add(
9764 json_cap,
9765 "extendedNexthop",
9766 "advertisedAndReceived");
9767 else if (CHECK_FLAG(p->cap,
9768 PEER_CAP_ENHE_ADV))
9769 json_object_string_add(
9770 json_cap,
9771 "extendedNexthop",
9772 "advertised");
9773 else if (CHECK_FLAG(p->cap,
9774 PEER_CAP_ENHE_RCV))
9775 json_object_string_add(
9776 json_cap,
9777 "extendedNexthop",
9778 "received");
9779
9780 if (CHECK_FLAG(p->cap,
9781 PEER_CAP_ENHE_RCV)) {
9782 json_nxt =
9783 json_object_new_object();
9784
9785 for (safi = SAFI_UNICAST;
9786 safi < SAFI_MAX; safi++) {
9787 if (CHECK_FLAG(
9788 p->af_cap
9789 [AFI_IP]
9790 [safi],
9791 PEER_CAP_ENHE_AF_RCV)) {
9792 print_store = afi_safi_print(
9793 AFI_IP,
9794 safi);
9795 json_object_string_add(
9796 json_nxt,
9797 print_store,
9798 "recieved"); /* misspelled for compatibility */
9799 }
9800 }
9801 json_object_object_add(
9802 json_cap,
9803 "extendedNexthopFamililesByPeer",
9804 json_nxt);
9805 }
9806 }
9807
9808 /* Route Refresh */
9809 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9810 || CHECK_FLAG(p->cap,
9811 PEER_CAP_REFRESH_NEW_RCV)
9812 || CHECK_FLAG(p->cap,
9813 PEER_CAP_REFRESH_OLD_RCV)) {
9814 if (CHECK_FLAG(p->cap,
9815 PEER_CAP_REFRESH_ADV)
9816 && (CHECK_FLAG(
9817 p->cap,
9818 PEER_CAP_REFRESH_NEW_RCV)
9819 || CHECK_FLAG(
9820 p->cap,
9821 PEER_CAP_REFRESH_OLD_RCV))) {
9822 if (CHECK_FLAG(
9823 p->cap,
9824 PEER_CAP_REFRESH_OLD_RCV)
9825 && CHECK_FLAG(
9826 p->cap,
9827 PEER_CAP_REFRESH_NEW_RCV))
9828 json_object_string_add(
9829 json_cap,
9830 "routeRefresh",
9831 "advertisedAndReceivedOldNew");
9832 else {
9833 if (CHECK_FLAG(
9834 p->cap,
9835 PEER_CAP_REFRESH_OLD_RCV))
9836 json_object_string_add(
9837 json_cap,
9838 "routeRefresh",
9839 "advertisedAndReceivedOld");
9840 else
9841 json_object_string_add(
9842 json_cap,
9843 "routeRefresh",
9844 "advertisedAndReceivedNew");
9845 }
9846 } else if (
9847 CHECK_FLAG(
9848 p->cap,
9849 PEER_CAP_REFRESH_ADV))
9850 json_object_string_add(
9851 json_cap,
9852 "routeRefresh",
9853 "advertised");
9854 else if (
9855 CHECK_FLAG(
9856 p->cap,
9857 PEER_CAP_REFRESH_NEW_RCV)
9858 || CHECK_FLAG(
9859 p->cap,
9860 PEER_CAP_REFRESH_OLD_RCV))
9861 json_object_string_add(
9862 json_cap,
9863 "routeRefresh",
9864 "received");
9865 }
9866
9867 /* Multiprotocol Extensions */
9868 json_object *json_multi = NULL;
9869 json_multi = json_object_new_object();
9870
9871 FOREACH_AFI_SAFI (afi, safi) {
9872 if (p->afc_adv[afi][safi]
9873 || p->afc_recv[afi][safi]) {
9874 json_object *json_exten = NULL;
9875 json_exten =
9876 json_object_new_object();
9877
9878 if (p->afc_adv[afi][safi]
9879 && p->afc_recv[afi][safi])
9880 json_object_boolean_true_add(
9881 json_exten,
9882 "advertisedAndReceived");
9883 else if (p->afc_adv[afi][safi])
9884 json_object_boolean_true_add(
9885 json_exten,
9886 "advertised");
9887 else if (p->afc_recv[afi][safi])
9888 json_object_boolean_true_add(
9889 json_exten,
9890 "received");
9891
9892 json_object_object_add(
9893 json_multi,
9894 afi_safi_print(afi,
9895 safi),
9896 json_exten);
9897 }
9898 }
9899 json_object_object_add(
9900 json_cap, "multiprotocolExtensions",
9901 json_multi);
9902
9903 /* Hostname capabilities */
9904 json_object *json_hname = NULL;
9905
9906 json_hname = json_object_new_object();
9907
9908 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9909 json_object_string_add(
9910 json_hname, "advHostName",
9911 bgp->peer_self->hostname
9912 ? bgp->peer_self
9913 ->hostname
9914 : "n/a");
9915 json_object_string_add(
9916 json_hname, "advDomainName",
9917 bgp->peer_self->domainname
9918 ? bgp->peer_self
9919 ->domainname
9920 : "n/a");
9921 }
9922
9923
9924 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9925 json_object_string_add(
9926 json_hname, "rcvHostName",
9927 p->hostname ? p->hostname
9928 : "n/a");
9929 json_object_string_add(
9930 json_hname, "rcvDomainName",
9931 p->domainname ? p->domainname
9932 : "n/a");
9933 }
9934
9935 json_object_object_add(json_cap, "hostName",
9936 json_hname);
9937
9938 /* Gracefull Restart */
9939 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9940 || CHECK_FLAG(p->cap,
9941 PEER_CAP_RESTART_ADV)) {
9942 if (CHECK_FLAG(p->cap,
9943 PEER_CAP_RESTART_ADV)
9944 && CHECK_FLAG(p->cap,
9945 PEER_CAP_RESTART_RCV))
9946 json_object_string_add(
9947 json_cap,
9948 "gracefulRestart",
9949 "advertisedAndReceived");
9950 else if (CHECK_FLAG(
9951 p->cap,
9952 PEER_CAP_RESTART_ADV))
9953 json_object_string_add(
9954 json_cap,
9955 "gracefulRestartCapability",
9956 "advertised");
9957 else if (CHECK_FLAG(
9958 p->cap,
9959 PEER_CAP_RESTART_RCV))
9960 json_object_string_add(
9961 json_cap,
9962 "gracefulRestartCapability",
9963 "received");
9964
9965 if (CHECK_FLAG(p->cap,
9966 PEER_CAP_RESTART_RCV)) {
9967 int restart_af_count = 0;
9968 json_object *json_restart =
9969 NULL;
9970 json_restart =
9971 json_object_new_object();
9972
9973 json_object_int_add(
9974 json_cap,
9975 "gracefulRestartRemoteTimerMsecs",
9976 p->v_gr_restart * 1000);
9977
9978 FOREACH_AFI_SAFI (afi, safi) {
9979 if (CHECK_FLAG(
9980 p->af_cap
9981 [afi]
9982 [safi],
9983 PEER_CAP_RESTART_AF_RCV)) {
9984 json_object *
9985 json_sub =
9986 NULL;
9987 json_sub =
9988 json_object_new_object();
9989
9990 if (CHECK_FLAG(
9991 p->af_cap
9992 [afi]
9993 [safi],
9994 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9995 json_object_boolean_true_add(
9996 json_sub,
9997 "preserved");
9998 restart_af_count++;
9999 json_object_object_add(
10000 json_restart,
10001 afi_safi_print(
10002 afi,
10003 safi),
10004 json_sub);
10005 }
10006 }
10007 if (!restart_af_count) {
10008 json_object_string_add(
10009 json_cap,
10010 "addressFamiliesByPeer",
10011 "none");
10012 json_object_free(
10013 json_restart);
10014 } else
10015 json_object_object_add(
10016 json_cap,
10017 "addressFamiliesByPeer",
10018 json_restart);
10019 }
10020 }
10021 json_object_object_add(json_neigh,
10022 "neighborCapabilities",
10023 json_cap);
10024 } else {
10025 vty_out(vty, " Neighbor capabilities:\n");
10026
10027 /* AS4 */
10028 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
10029 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
10030 vty_out(vty, " 4 Byte AS:");
10031 if (CHECK_FLAG(p->cap,
10032 PEER_CAP_AS4_ADV))
10033 vty_out(vty, " advertised");
10034 if (CHECK_FLAG(p->cap,
10035 PEER_CAP_AS4_RCV))
10036 vty_out(vty, " %sreceived",
10037 CHECK_FLAG(
10038 p->cap,
10039 PEER_CAP_AS4_ADV)
10040 ? "and "
10041 : "");
10042 vty_out(vty, "\n");
10043 }
10044
10045 /* AddPath */
10046 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
10047 || CHECK_FLAG(p->cap,
10048 PEER_CAP_ADDPATH_ADV)) {
10049 vty_out(vty, " AddPath:\n");
10050
10051 FOREACH_AFI_SAFI (afi, safi) {
10052 if (CHECK_FLAG(
10053 p->af_cap[afi]
10054 [safi],
10055 PEER_CAP_ADDPATH_AF_TX_ADV)
10056 || CHECK_FLAG(
10057 p->af_cap[afi]
10058 [safi],
10059 PEER_CAP_ADDPATH_AF_TX_RCV)) {
10060 vty_out(vty,
10061 " %s: TX ",
10062 afi_safi_print(
10063 afi,
10064 safi));
10065
10066 if (CHECK_FLAG(
10067 p->af_cap
10068 [afi]
10069 [safi],
10070 PEER_CAP_ADDPATH_AF_TX_ADV))
10071 vty_out(vty,
10072 "advertised %s",
10073 afi_safi_print(
10074 afi,
10075 safi));
10076
10077 if (CHECK_FLAG(
10078 p->af_cap
10079 [afi]
10080 [safi],
10081 PEER_CAP_ADDPATH_AF_TX_RCV))
10082 vty_out(vty,
10083 "%sreceived",
10084 CHECK_FLAG(
10085 p->af_cap
10086 [afi]
10087 [safi],
10088 PEER_CAP_ADDPATH_AF_TX_ADV)
10089 ? " and "
10090 : "");
10091
10092 vty_out(vty, "\n");
10093 }
10094
10095 if (CHECK_FLAG(
10096 p->af_cap[afi]
10097 [safi],
10098 PEER_CAP_ADDPATH_AF_RX_ADV)
10099 || CHECK_FLAG(
10100 p->af_cap[afi]
10101 [safi],
10102 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10103 vty_out(vty,
10104 " %s: RX ",
10105 afi_safi_print(
10106 afi,
10107 safi));
10108
10109 if (CHECK_FLAG(
10110 p->af_cap
10111 [afi]
10112 [safi],
10113 PEER_CAP_ADDPATH_AF_RX_ADV))
10114 vty_out(vty,
10115 "advertised %s",
10116 afi_safi_print(
10117 afi,
10118 safi));
10119
10120 if (CHECK_FLAG(
10121 p->af_cap
10122 [afi]
10123 [safi],
10124 PEER_CAP_ADDPATH_AF_RX_RCV))
10125 vty_out(vty,
10126 "%sreceived",
10127 CHECK_FLAG(
10128 p->af_cap
10129 [afi]
10130 [safi],
10131 PEER_CAP_ADDPATH_AF_RX_ADV)
10132 ? " and "
10133 : "");
10134
10135 vty_out(vty, "\n");
10136 }
10137 }
10138 }
10139
10140 /* Dynamic */
10141 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10142 || CHECK_FLAG(p->cap,
10143 PEER_CAP_DYNAMIC_ADV)) {
10144 vty_out(vty, " Dynamic:");
10145 if (CHECK_FLAG(p->cap,
10146 PEER_CAP_DYNAMIC_ADV))
10147 vty_out(vty, " advertised");
10148 if (CHECK_FLAG(p->cap,
10149 PEER_CAP_DYNAMIC_RCV))
10150 vty_out(vty, " %sreceived",
10151 CHECK_FLAG(
10152 p->cap,
10153 PEER_CAP_DYNAMIC_ADV)
10154 ? "and "
10155 : "");
10156 vty_out(vty, "\n");
10157 }
10158
10159 /* Extended nexthop */
10160 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10161 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10162 vty_out(vty, " Extended nexthop:");
10163 if (CHECK_FLAG(p->cap,
10164 PEER_CAP_ENHE_ADV))
10165 vty_out(vty, " advertised");
10166 if (CHECK_FLAG(p->cap,
10167 PEER_CAP_ENHE_RCV))
10168 vty_out(vty, " %sreceived",
10169 CHECK_FLAG(
10170 p->cap,
10171 PEER_CAP_ENHE_ADV)
10172 ? "and "
10173 : "");
10174 vty_out(vty, "\n");
10175
10176 if (CHECK_FLAG(p->cap,
10177 PEER_CAP_ENHE_RCV)) {
10178 vty_out(vty,
10179 " Address families by peer:\n ");
10180 for (safi = SAFI_UNICAST;
10181 safi < SAFI_MAX; safi++)
10182 if (CHECK_FLAG(
10183 p->af_cap
10184 [AFI_IP]
10185 [safi],
10186 PEER_CAP_ENHE_AF_RCV))
10187 vty_out(vty,
10188 " %s\n",
10189 afi_safi_print(
10190 AFI_IP,
10191 safi));
10192 }
10193 }
10194
10195 /* Route Refresh */
10196 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10197 || CHECK_FLAG(p->cap,
10198 PEER_CAP_REFRESH_NEW_RCV)
10199 || CHECK_FLAG(p->cap,
10200 PEER_CAP_REFRESH_OLD_RCV)) {
10201 vty_out(vty, " Route refresh:");
10202 if (CHECK_FLAG(p->cap,
10203 PEER_CAP_REFRESH_ADV))
10204 vty_out(vty, " advertised");
10205 if (CHECK_FLAG(p->cap,
10206 PEER_CAP_REFRESH_NEW_RCV)
10207 || CHECK_FLAG(
10208 p->cap,
10209 PEER_CAP_REFRESH_OLD_RCV))
10210 vty_out(vty, " %sreceived(%s)",
10211 CHECK_FLAG(
10212 p->cap,
10213 PEER_CAP_REFRESH_ADV)
10214 ? "and "
10215 : "",
10216 (CHECK_FLAG(
10217 p->cap,
10218 PEER_CAP_REFRESH_OLD_RCV)
10219 && CHECK_FLAG(
10220 p->cap,
10221 PEER_CAP_REFRESH_NEW_RCV))
10222 ? "old & new"
10223 : CHECK_FLAG(
10224 p->cap,
10225 PEER_CAP_REFRESH_OLD_RCV)
10226 ? "old"
10227 : "new");
10228
10229 vty_out(vty, "\n");
10230 }
10231
10232 /* Multiprotocol Extensions */
10233 FOREACH_AFI_SAFI (afi, safi)
10234 if (p->afc_adv[afi][safi]
10235 || p->afc_recv[afi][safi]) {
10236 vty_out(vty,
10237 " Address Family %s:",
10238 afi_safi_print(afi,
10239 safi));
10240 if (p->afc_adv[afi][safi])
10241 vty_out(vty,
10242 " advertised");
10243 if (p->afc_recv[afi][safi])
10244 vty_out(vty,
10245 " %sreceived",
10246 p->afc_adv[afi]
10247 [safi]
10248 ? "and "
10249 : "");
10250 vty_out(vty, "\n");
10251 }
10252
10253 /* Hostname capability */
10254 vty_out(vty, " Hostname Capability:");
10255
10256 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10257 vty_out(vty,
10258 " advertised (name: %s,domain name: %s)",
10259 bgp->peer_self->hostname
10260 ? bgp->peer_self
10261 ->hostname
10262 : "n/a",
10263 bgp->peer_self->domainname
10264 ? bgp->peer_self
10265 ->domainname
10266 : "n/a");
10267 } else {
10268 vty_out(vty, " not advertised");
10269 }
10270
10271 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10272 vty_out(vty,
10273 " received (name: %s,domain name: %s)",
10274 p->hostname ? p->hostname
10275 : "n/a",
10276 p->domainname ? p->domainname
10277 : "n/a");
10278 } else {
10279 vty_out(vty, " not received");
10280 }
10281
10282 vty_out(vty, "\n");
10283
10284 /* Gracefull Restart */
10285 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10286 || CHECK_FLAG(p->cap,
10287 PEER_CAP_RESTART_ADV)) {
10288 vty_out(vty,
10289 " Graceful Restart Capabilty:");
10290 if (CHECK_FLAG(p->cap,
10291 PEER_CAP_RESTART_ADV))
10292 vty_out(vty, " advertised");
10293 if (CHECK_FLAG(p->cap,
10294 PEER_CAP_RESTART_RCV))
10295 vty_out(vty, " %sreceived",
10296 CHECK_FLAG(
10297 p->cap,
10298 PEER_CAP_RESTART_ADV)
10299 ? "and "
10300 : "");
10301 vty_out(vty, "\n");
10302
10303 if (CHECK_FLAG(p->cap,
10304 PEER_CAP_RESTART_RCV)) {
10305 int restart_af_count = 0;
10306
10307 vty_out(vty,
10308 " Remote Restart timer is %d seconds\n",
10309 p->v_gr_restart);
10310 vty_out(vty,
10311 " Address families by peer:\n ");
10312
10313 FOREACH_AFI_SAFI (afi, safi)
10314 if (CHECK_FLAG(
10315 p->af_cap
10316 [afi]
10317 [safi],
10318 PEER_CAP_RESTART_AF_RCV)) {
10319 vty_out(vty,
10320 "%s%s(%s)",
10321 restart_af_count
10322 ? ", "
10323 : "",
10324 afi_safi_print(
10325 afi,
10326 safi),
10327 CHECK_FLAG(
10328 p->af_cap
10329 [afi]
10330 [safi],
10331 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10332 ? "preserved"
10333 : "not preserved");
10334 restart_af_count++;
10335 }
10336 if (!restart_af_count)
10337 vty_out(vty, "none");
10338 vty_out(vty, "\n");
10339 }
10340 }
10341 }
10342 }
10343 }
10344
10345 /* graceful restart information */
10346 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10347 || p->t_gr_stale) {
10348 json_object *json_grace = NULL;
10349 json_object *json_grace_send = NULL;
10350 json_object *json_grace_recv = NULL;
10351 int eor_send_af_count = 0;
10352 int eor_receive_af_count = 0;
10353
10354 if (use_json) {
10355 json_grace = json_object_new_object();
10356 json_grace_send = json_object_new_object();
10357 json_grace_recv = json_object_new_object();
10358
10359 if (p->status == Established) {
10360 FOREACH_AFI_SAFI (afi, safi) {
10361 if (CHECK_FLAG(p->af_sflags[afi][safi],
10362 PEER_STATUS_EOR_SEND)) {
10363 json_object_boolean_true_add(
10364 json_grace_send,
10365 afi_safi_print(afi,
10366 safi));
10367 eor_send_af_count++;
10368 }
10369 }
10370 FOREACH_AFI_SAFI (afi, safi) {
10371 if (CHECK_FLAG(
10372 p->af_sflags[afi][safi],
10373 PEER_STATUS_EOR_RECEIVED)) {
10374 json_object_boolean_true_add(
10375 json_grace_recv,
10376 afi_safi_print(afi,
10377 safi));
10378 eor_receive_af_count++;
10379 }
10380 }
10381 }
10382
10383 json_object_object_add(json_grace, "endOfRibSend",
10384 json_grace_send);
10385 json_object_object_add(json_grace, "endOfRibRecv",
10386 json_grace_recv);
10387
10388 if (p->t_gr_restart)
10389 json_object_int_add(json_grace,
10390 "gracefulRestartTimerMsecs",
10391 thread_timer_remain_second(
10392 p->t_gr_restart)
10393 * 1000);
10394
10395 if (p->t_gr_stale)
10396 json_object_int_add(
10397 json_grace,
10398 "gracefulStalepathTimerMsecs",
10399 thread_timer_remain_second(
10400 p->t_gr_stale)
10401 * 1000);
10402
10403 json_object_object_add(
10404 json_neigh, "gracefulRestartInfo", json_grace);
10405 } else {
10406 vty_out(vty, " Graceful restart information:\n");
10407 if (p->status == Established) {
10408 vty_out(vty, " End-of-RIB send: ");
10409 FOREACH_AFI_SAFI (afi, safi) {
10410 if (CHECK_FLAG(p->af_sflags[afi][safi],
10411 PEER_STATUS_EOR_SEND)) {
10412 vty_out(vty, "%s%s",
10413 eor_send_af_count ? ", "
10414 : "",
10415 afi_safi_print(afi,
10416 safi));
10417 eor_send_af_count++;
10418 }
10419 }
10420 vty_out(vty, "\n");
10421 vty_out(vty, " End-of-RIB received: ");
10422 FOREACH_AFI_SAFI (afi, safi) {
10423 if (CHECK_FLAG(
10424 p->af_sflags[afi][safi],
10425 PEER_STATUS_EOR_RECEIVED)) {
10426 vty_out(vty, "%s%s",
10427 eor_receive_af_count
10428 ? ", "
10429 : "",
10430 afi_safi_print(afi,
10431 safi));
10432 eor_receive_af_count++;
10433 }
10434 }
10435 vty_out(vty, "\n");
10436 }
10437
10438 if (p->t_gr_restart)
10439 vty_out(vty,
10440 " The remaining time of restart timer is %ld\n",
10441 thread_timer_remain_second(
10442 p->t_gr_restart));
10443
10444 if (p->t_gr_stale)
10445 vty_out(vty,
10446 " The remaining time of stalepath timer is %ld\n",
10447 thread_timer_remain_second(
10448 p->t_gr_stale));
10449 }
10450 }
10451 if (use_json) {
10452 json_object *json_stat = NULL;
10453 json_stat = json_object_new_object();
10454 /* Packet counts. */
10455 json_object_int_add(json_stat, "depthInq", 0);
10456 json_object_int_add(json_stat, "depthOutq",
10457 (unsigned long)p->obuf->count);
10458 json_object_int_add(json_stat, "opensSent",
10459 atomic_load_explicit(&p->open_out,
10460 memory_order_relaxed));
10461 json_object_int_add(json_stat, "opensRecv",
10462 atomic_load_explicit(&p->open_in,
10463 memory_order_relaxed));
10464 json_object_int_add(json_stat, "notificationsSent",
10465 atomic_load_explicit(&p->notify_out,
10466 memory_order_relaxed));
10467 json_object_int_add(json_stat, "notificationsRecv",
10468 atomic_load_explicit(&p->notify_in,
10469 memory_order_relaxed));
10470 json_object_int_add(json_stat, "updatesSent",
10471 atomic_load_explicit(&p->update_out,
10472 memory_order_relaxed));
10473 json_object_int_add(json_stat, "updatesRecv",
10474 atomic_load_explicit(&p->update_in,
10475 memory_order_relaxed));
10476 json_object_int_add(json_stat, "keepalivesSent",
10477 atomic_load_explicit(&p->keepalive_out,
10478 memory_order_relaxed));
10479 json_object_int_add(json_stat, "keepalivesRecv",
10480 atomic_load_explicit(&p->keepalive_in,
10481 memory_order_relaxed));
10482 json_object_int_add(json_stat, "routeRefreshSent",
10483 atomic_load_explicit(&p->refresh_out,
10484 memory_order_relaxed));
10485 json_object_int_add(json_stat, "routeRefreshRecv",
10486 atomic_load_explicit(&p->refresh_in,
10487 memory_order_relaxed));
10488 json_object_int_add(json_stat, "capabilitySent",
10489 atomic_load_explicit(&p->dynamic_cap_out,
10490 memory_order_relaxed));
10491 json_object_int_add(json_stat, "capabilityRecv",
10492 atomic_load_explicit(&p->dynamic_cap_in,
10493 memory_order_relaxed));
10494 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10495 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10496 json_object_object_add(json_neigh, "messageStats", json_stat);
10497 } else {
10498 /* Packet counts. */
10499 vty_out(vty, " Message statistics:\n");
10500 vty_out(vty, " Inq depth is 0\n");
10501 vty_out(vty, " Outq depth is %lu\n",
10502 (unsigned long)p->obuf->count);
10503 vty_out(vty, " Sent Rcvd\n");
10504 vty_out(vty, " Opens: %10d %10d\n",
10505 atomic_load_explicit(&p->open_out,
10506 memory_order_relaxed),
10507 atomic_load_explicit(&p->open_in,
10508 memory_order_relaxed));
10509 vty_out(vty, " Notifications: %10d %10d\n",
10510 atomic_load_explicit(&p->notify_out,
10511 memory_order_relaxed),
10512 atomic_load_explicit(&p->notify_in,
10513 memory_order_relaxed));
10514 vty_out(vty, " Updates: %10d %10d\n",
10515 atomic_load_explicit(&p->update_out,
10516 memory_order_relaxed),
10517 atomic_load_explicit(&p->update_in,
10518 memory_order_relaxed));
10519 vty_out(vty, " Keepalives: %10d %10d\n",
10520 atomic_load_explicit(&p->keepalive_out,
10521 memory_order_relaxed),
10522 atomic_load_explicit(&p->keepalive_in,
10523 memory_order_relaxed));
10524 vty_out(vty, " Route Refresh: %10d %10d\n",
10525 atomic_load_explicit(&p->refresh_out,
10526 memory_order_relaxed),
10527 atomic_load_explicit(&p->refresh_in,
10528 memory_order_relaxed));
10529 vty_out(vty, " Capability: %10d %10d\n",
10530 atomic_load_explicit(&p->dynamic_cap_out,
10531 memory_order_relaxed),
10532 atomic_load_explicit(&p->dynamic_cap_in,
10533 memory_order_relaxed));
10534 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10535 PEER_TOTAL_RX(p));
10536 }
10537
10538 if (use_json) {
10539 /* advertisement-interval */
10540 json_object_int_add(json_neigh,
10541 "minBtwnAdvertisementRunsTimerMsecs",
10542 p->v_routeadv * 1000);
10543
10544 /* Update-source. */
10545 if (p->update_if || p->update_source) {
10546 if (p->update_if)
10547 json_object_string_add(json_neigh,
10548 "updateSource",
10549 p->update_if);
10550 else if (p->update_source)
10551 json_object_string_add(
10552 json_neigh, "updateSource",
10553 sockunion2str(p->update_source, buf1,
10554 SU_ADDRSTRLEN));
10555 }
10556 } else {
10557 /* advertisement-interval */
10558 vty_out(vty,
10559 " Minimum time between advertisement runs is %d seconds\n",
10560 p->v_routeadv);
10561
10562 /* Update-source. */
10563 if (p->update_if || p->update_source) {
10564 vty_out(vty, " Update source is ");
10565 if (p->update_if)
10566 vty_out(vty, "%s", p->update_if);
10567 else if (p->update_source)
10568 vty_out(vty, "%s",
10569 sockunion2str(p->update_source, buf1,
10570 SU_ADDRSTRLEN));
10571 vty_out(vty, "\n");
10572 }
10573
10574 vty_out(vty, "\n");
10575 }
10576
10577 /* Address Family Information */
10578 json_object *json_hold = NULL;
10579
10580 if (use_json)
10581 json_hold = json_object_new_object();
10582
10583 FOREACH_AFI_SAFI (afi, safi)
10584 if (p->afc[afi][safi])
10585 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10586 json_hold);
10587
10588 if (use_json) {
10589 json_object_object_add(json_neigh, "addressFamilyInfo",
10590 json_hold);
10591 json_object_int_add(json_neigh, "connectionsEstablished",
10592 p->established);
10593 json_object_int_add(json_neigh, "connectionsDropped",
10594 p->dropped);
10595 } else
10596 vty_out(vty, " Connections established %d; dropped %d\n",
10597 p->established, p->dropped);
10598
10599 if (!p->last_reset) {
10600 if (use_json)
10601 json_object_string_add(json_neigh, "lastReset",
10602 "never");
10603 else
10604 vty_out(vty, " Last reset never\n");
10605 } else {
10606 if (use_json) {
10607 time_t uptime;
10608 struct tm *tm;
10609
10610 uptime = bgp_clock();
10611 uptime -= p->resettime;
10612 tm = gmtime(&uptime);
10613 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10614 (tm->tm_sec * 1000)
10615 + (tm->tm_min * 60000)
10616 + (tm->tm_hour * 3600000));
10617 json_object_string_add(
10618 json_neigh, "lastResetDueTo",
10619 peer_down_str[(int)p->last_reset]);
10620 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10621 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10622 char errorcodesubcode_hexstr[5];
10623 char errorcodesubcode_str[256];
10624
10625 code_str = bgp_notify_code_str(p->notify.code);
10626 subcode_str = bgp_notify_subcode_str(
10627 p->notify.code, p->notify.subcode);
10628
10629 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10630 p->notify.code, p->notify.subcode);
10631 json_object_string_add(json_neigh,
10632 "lastErrorCodeSubcode",
10633 errorcodesubcode_hexstr);
10634 snprintf(errorcodesubcode_str, 255, "%s%s",
10635 code_str, subcode_str);
10636 json_object_string_add(json_neigh,
10637 "lastNotificationReason",
10638 errorcodesubcode_str);
10639 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10640 && p->notify.code == BGP_NOTIFY_CEASE
10641 && (p->notify.subcode
10642 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10643 || p->notify.subcode
10644 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10645 && p->notify.length) {
10646 char msgbuf[1024];
10647 const char *msg_str;
10648
10649 msg_str = bgp_notify_admin_message(
10650 msgbuf, sizeof(msgbuf),
10651 (uint8_t *)p->notify.data,
10652 p->notify.length);
10653 if (msg_str)
10654 json_object_string_add(
10655 json_neigh,
10656 "lastShutdownDescription",
10657 msg_str);
10658 }
10659 }
10660 } else {
10661 vty_out(vty, " Last reset %s, ",
10662 peer_uptime(p->resettime, timebuf,
10663 BGP_UPTIME_LEN, 0, NULL));
10664
10665 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10666 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10667 code_str = bgp_notify_code_str(p->notify.code);
10668 subcode_str = bgp_notify_subcode_str(
10669 p->notify.code, p->notify.subcode);
10670 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10671 p->last_reset == PEER_DOWN_NOTIFY_SEND
10672 ? "sent"
10673 : "received",
10674 code_str, subcode_str);
10675 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10676 && p->notify.code == BGP_NOTIFY_CEASE
10677 && (p->notify.subcode
10678 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10679 || p->notify.subcode
10680 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10681 && p->notify.length) {
10682 char msgbuf[1024];
10683 const char *msg_str;
10684
10685 msg_str = bgp_notify_admin_message(
10686 msgbuf, sizeof(msgbuf),
10687 (uint8_t *)p->notify.data,
10688 p->notify.length);
10689 if (msg_str)
10690 vty_out(vty,
10691 " Message: \"%s\"\n",
10692 msg_str);
10693 }
10694 } else {
10695 vty_out(vty, "due to %s\n",
10696 peer_down_str[(int)p->last_reset]);
10697 }
10698
10699 if (p->last_reset_cause_size) {
10700 msg = p->last_reset_cause;
10701 vty_out(vty,
10702 " Message received that caused BGP to send a NOTIFICATION:\n ");
10703 for (i = 1; i <= p->last_reset_cause_size;
10704 i++) {
10705 vty_out(vty, "%02X", *msg++);
10706
10707 if (i != p->last_reset_cause_size) {
10708 if (i % 16 == 0) {
10709 vty_out(vty, "\n ");
10710 } else if (i % 4 == 0) {
10711 vty_out(vty, " ");
10712 }
10713 }
10714 }
10715 vty_out(vty, "\n");
10716 }
10717 }
10718 }
10719
10720 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10721 if (use_json)
10722 json_object_boolean_true_add(json_neigh,
10723 "prefixesConfigExceedMax");
10724 else
10725 vty_out(vty,
10726 " Peer had exceeded the max. no. of prefixes configured.\n");
10727
10728 if (p->t_pmax_restart) {
10729 if (use_json) {
10730 json_object_boolean_true_add(
10731 json_neigh, "reducePrefixNumFrom");
10732 json_object_int_add(json_neigh,
10733 "restartInTimerMsec",
10734 thread_timer_remain_second(
10735 p->t_pmax_restart)
10736 * 1000);
10737 } else
10738 vty_out(vty,
10739 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10740 p->host, thread_timer_remain_second(
10741 p->t_pmax_restart));
10742 } else {
10743 if (use_json)
10744 json_object_boolean_true_add(
10745 json_neigh,
10746 "reducePrefixNumAndClearIpBgp");
10747 else
10748 vty_out(vty,
10749 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10750 p->host);
10751 }
10752 }
10753
10754 /* EBGP Multihop and GTSM */
10755 if (p->sort != BGP_PEER_IBGP) {
10756 if (use_json) {
10757 if (p->gtsm_hops > 0)
10758 json_object_int_add(json_neigh,
10759 "externalBgpNbrMaxHopsAway",
10760 p->gtsm_hops);
10761 else if (p->ttl > 1)
10762 json_object_int_add(json_neigh,
10763 "externalBgpNbrMaxHopsAway",
10764 p->ttl);
10765 } else {
10766 if (p->gtsm_hops > 0)
10767 vty_out(vty,
10768 " External BGP neighbor may be up to %d hops away.\n",
10769 p->gtsm_hops);
10770 else if (p->ttl > 1)
10771 vty_out(vty,
10772 " External BGP neighbor may be up to %d hops away.\n",
10773 p->ttl);
10774 }
10775 } else {
10776 if (p->gtsm_hops > 0) {
10777 if (use_json)
10778 json_object_int_add(json_neigh,
10779 "internalBgpNbrMaxHopsAway",
10780 p->gtsm_hops);
10781 else
10782 vty_out(vty,
10783 " Internal BGP neighbor may be up to %d hops away.\n",
10784 p->gtsm_hops);
10785 }
10786 }
10787
10788 /* Local address. */
10789 if (p->su_local) {
10790 if (use_json) {
10791 json_object_string_add(json_neigh, "hostLocal",
10792 sockunion2str(p->su_local, buf1,
10793 SU_ADDRSTRLEN));
10794 json_object_int_add(json_neigh, "portLocal",
10795 ntohs(p->su_local->sin.sin_port));
10796 } else
10797 vty_out(vty, "Local host: %s, Local port: %d\n",
10798 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10799 ntohs(p->su_local->sin.sin_port));
10800 }
10801
10802 /* Remote address. */
10803 if (p->su_remote) {
10804 if (use_json) {
10805 json_object_string_add(json_neigh, "hostForeign",
10806 sockunion2str(p->su_remote, buf1,
10807 SU_ADDRSTRLEN));
10808 json_object_int_add(json_neigh, "portForeign",
10809 ntohs(p->su_remote->sin.sin_port));
10810 } else
10811 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10812 sockunion2str(p->su_remote, buf1,
10813 SU_ADDRSTRLEN),
10814 ntohs(p->su_remote->sin.sin_port));
10815 }
10816
10817 /* Nexthop display. */
10818 if (p->su_local) {
10819 if (use_json) {
10820 json_object_string_add(json_neigh, "nexthop",
10821 inet_ntop(AF_INET,
10822 &p->nexthop.v4, buf1,
10823 sizeof(buf1)));
10824 json_object_string_add(json_neigh, "nexthopGlobal",
10825 inet_ntop(AF_INET6,
10826 &p->nexthop.v6_global,
10827 buf1, sizeof(buf1)));
10828 json_object_string_add(json_neigh, "nexthopLocal",
10829 inet_ntop(AF_INET6,
10830 &p->nexthop.v6_local,
10831 buf1, sizeof(buf1)));
10832 if (p->shared_network)
10833 json_object_string_add(json_neigh,
10834 "bgpConnection",
10835 "sharedNetwork");
10836 else
10837 json_object_string_add(json_neigh,
10838 "bgpConnection",
10839 "nonSharedNetwork");
10840 } else {
10841 vty_out(vty, "Nexthop: %s\n",
10842 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10843 sizeof(buf1)));
10844 vty_out(vty, "Nexthop global: %s\n",
10845 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10846 sizeof(buf1)));
10847 vty_out(vty, "Nexthop local: %s\n",
10848 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10849 sizeof(buf1)));
10850 vty_out(vty, "BGP connection: %s\n",
10851 p->shared_network ? "shared network"
10852 : "non shared network");
10853 }
10854 }
10855
10856 /* Timer information. */
10857 if (use_json) {
10858 json_object_int_add(json_neigh, "connectRetryTimer",
10859 p->v_connect);
10860 if (p->status == Established && p->rtt)
10861 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10862 p->rtt);
10863 if (p->t_start)
10864 json_object_int_add(
10865 json_neigh, "nextStartTimerDueInMsecs",
10866 thread_timer_remain_second(p->t_start) * 1000);
10867 if (p->t_connect)
10868 json_object_int_add(
10869 json_neigh, "nextConnectTimerDueInMsecs",
10870 thread_timer_remain_second(p->t_connect)
10871 * 1000);
10872 if (p->t_routeadv) {
10873 json_object_int_add(json_neigh, "mraiInterval",
10874 p->v_routeadv);
10875 json_object_int_add(
10876 json_neigh, "mraiTimerExpireInMsecs",
10877 thread_timer_remain_second(p->t_routeadv)
10878 * 1000);
10879 }
10880 if (p->password)
10881 json_object_int_add(json_neigh, "authenticationEnabled",
10882 1);
10883
10884 if (p->t_read)
10885 json_object_string_add(json_neigh, "readThread", "on");
10886 else
10887 json_object_string_add(json_neigh, "readThread", "off");
10888
10889 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10890 json_object_string_add(json_neigh, "writeThread", "on");
10891 else
10892 json_object_string_add(json_neigh, "writeThread",
10893 "off");
10894 } else {
10895 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10896 p->v_connect);
10897 if (p->status == Established && p->rtt)
10898 vty_out(vty, "Estimated round trip time: %d ms\n",
10899 p->rtt);
10900 if (p->t_start)
10901 vty_out(vty, "Next start timer due in %ld seconds\n",
10902 thread_timer_remain_second(p->t_start));
10903 if (p->t_connect)
10904 vty_out(vty, "Next connect timer due in %ld seconds\n",
10905 thread_timer_remain_second(p->t_connect));
10906 if (p->t_routeadv)
10907 vty_out(vty,
10908 "MRAI (interval %u) timer expires in %ld seconds\n",
10909 p->v_routeadv,
10910 thread_timer_remain_second(p->t_routeadv));
10911 if (p->password)
10912 vty_out(vty, "Peer Authentication Enabled\n");
10913
10914 vty_out(vty, "Read thread: %s Write thread: %s\n",
10915 p->t_read ? "on" : "off",
10916 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10917 ? "on"
10918 : "off");
10919 }
10920
10921 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10922 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10923 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10924
10925 if (!use_json)
10926 vty_out(vty, "\n");
10927
10928 /* BFD information. */
10929 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10930
10931 if (use_json) {
10932 if (p->conf_if) /* Configured interface name. */
10933 json_object_object_add(json, p->conf_if, json_neigh);
10934 else /* Configured IP address. */
10935 json_object_object_add(json, p->host, json_neigh);
10936 }
10937 }
10938
10939 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10940 enum show_type type, union sockunion *su,
10941 const char *conf_if, bool use_json,
10942 json_object *json)
10943 {
10944 struct listnode *node, *nnode;
10945 struct peer *peer;
10946 int find = 0;
10947 bool nbr_output = false;
10948
10949 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10950 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10951 continue;
10952
10953 switch (type) {
10954 case show_all:
10955 bgp_show_peer(vty, peer, use_json, json);
10956 nbr_output = true;
10957 break;
10958 case show_peer:
10959 if (conf_if) {
10960 if ((peer->conf_if
10961 && !strcmp(peer->conf_if, conf_if))
10962 || (peer->hostname
10963 && !strcmp(peer->hostname, conf_if))) {
10964 find = 1;
10965 bgp_show_peer(vty, peer, use_json,
10966 json);
10967 }
10968 } else {
10969 if (sockunion_same(&peer->su, su)) {
10970 find = 1;
10971 bgp_show_peer(vty, peer, use_json,
10972 json);
10973 }
10974 }
10975 break;
10976 }
10977 }
10978
10979 if (type == show_peer && !find) {
10980 if (use_json)
10981 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10982 else
10983 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10984 }
10985
10986 if (type != show_peer && !nbr_output && !use_json)
10987 vty_out(vty, "%% No BGP neighbors found\n");
10988
10989 if (use_json) {
10990 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10991 json, JSON_C_TO_STRING_PRETTY));
10992 } else {
10993 vty_out(vty, "\n");
10994 }
10995
10996 return CMD_SUCCESS;
10997 }
10998
10999 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
11000 enum show_type type,
11001 const char *ip_str,
11002 bool use_json)
11003 {
11004 struct listnode *node, *nnode;
11005 struct bgp *bgp;
11006 union sockunion su;
11007 json_object *json = NULL;
11008 int ret, is_first = 1;
11009 bool nbr_output = false;
11010
11011 if (use_json)
11012 vty_out(vty, "{\n");
11013
11014 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11015 nbr_output = true;
11016 if (use_json) {
11017 if (!(json = json_object_new_object())) {
11018 flog_err(
11019 EC_BGP_JSON_MEM_ERROR,
11020 "Unable to allocate memory for JSON object");
11021 vty_out(vty,
11022 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
11023 return;
11024 }
11025
11026 json_object_int_add(json, "vrfId",
11027 (bgp->vrf_id == VRF_UNKNOWN)
11028 ? -1
11029 : (int64_t)bgp->vrf_id);
11030 json_object_string_add(
11031 json, "vrfName",
11032 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11033 ? VRF_DEFAULT_NAME
11034 : bgp->name);
11035
11036 if (!is_first)
11037 vty_out(vty, ",\n");
11038 else
11039 is_first = 0;
11040
11041 vty_out(vty, "\"%s\":",
11042 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11043 ? VRF_DEFAULT_NAME
11044 : bgp->name);
11045 } else {
11046 vty_out(vty, "\nInstance %s:\n",
11047 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11048 ? VRF_DEFAULT_NAME
11049 : bgp->name);
11050 }
11051
11052 if (type == show_peer) {
11053 ret = str2sockunion(ip_str, &su);
11054 if (ret < 0)
11055 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11056 use_json, json);
11057 else
11058 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11059 use_json, json);
11060 } else {
11061 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
11062 use_json, json);
11063 }
11064 json_object_free(json);
11065 }
11066
11067 if (use_json) {
11068 vty_out(vty, "}\n");
11069 json_object_free(json);
11070 }
11071 else if (!nbr_output)
11072 vty_out(vty, "%% BGP instance not found\n");
11073 }
11074
11075 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11076 enum show_type type, const char *ip_str,
11077 bool use_json)
11078 {
11079 int ret;
11080 struct bgp *bgp;
11081 union sockunion su;
11082 json_object *json = NULL;
11083
11084 if (name) {
11085 if (strmatch(name, "all")) {
11086 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11087 use_json);
11088 return CMD_SUCCESS;
11089 } else {
11090 bgp = bgp_lookup_by_name(name);
11091 if (!bgp) {
11092 if (use_json) {
11093 json = json_object_new_object();
11094 vty_out(vty, "%s\n",
11095 json_object_to_json_string_ext(
11096 json,
11097 JSON_C_TO_STRING_PRETTY));
11098 json_object_free(json);
11099 } else
11100 vty_out(vty,
11101 "%% BGP instance not found\n");
11102
11103 return CMD_WARNING;
11104 }
11105 }
11106 } else {
11107 bgp = bgp_get_default();
11108 }
11109
11110 if (bgp) {
11111 json = json_object_new_object();
11112 if (ip_str) {
11113 ret = str2sockunion(ip_str, &su);
11114 if (ret < 0)
11115 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11116 use_json, json);
11117 else
11118 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11119 use_json, json);
11120 } else {
11121 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11122 json);
11123 }
11124 json_object_free(json);
11125 } else {
11126 if (use_json)
11127 vty_out(vty, "{}\n");
11128 else
11129 vty_out(vty, "%% BGP instance not found\n");
11130 }
11131
11132 return CMD_SUCCESS;
11133 }
11134
11135 /* "show [ip] bgp neighbors" commands. */
11136 DEFUN (show_ip_bgp_neighbors,
11137 show_ip_bgp_neighbors_cmd,
11138 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11139 SHOW_STR
11140 IP_STR
11141 BGP_STR
11142 BGP_INSTANCE_HELP_STR
11143 "Address Family\n"
11144 "Address Family\n"
11145 "Detailed information on TCP and BGP neighbor connections\n"
11146 "Neighbor to display information about\n"
11147 "Neighbor to display information about\n"
11148 "Neighbor on BGP configured interface\n"
11149 JSON_STR)
11150 {
11151 char *vrf = NULL;
11152 char *sh_arg = NULL;
11153 enum show_type sh_type;
11154
11155 bool uj = use_json(argc, argv);
11156
11157 int idx = 0;
11158
11159 /* [<vrf> VIEWVRFNAME] */
11160 if (argv_find(argv, argc, "vrf", &idx)) {
11161 vrf = argv[idx + 1]->arg;
11162 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11163 vrf = NULL;
11164 } else if (argv_find(argv, argc, "view", &idx))
11165 /* [<view> VIEWVRFNAME] */
11166 vrf = argv[idx + 1]->arg;
11167
11168 idx++;
11169 if (argv_find(argv, argc, "A.B.C.D", &idx)
11170 || argv_find(argv, argc, "X:X::X:X", &idx)
11171 || argv_find(argv, argc, "WORD", &idx)) {
11172 sh_type = show_peer;
11173 sh_arg = argv[idx]->arg;
11174 } else
11175 sh_type = show_all;
11176
11177 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11178 }
11179
11180 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11181 paths' and `show ip mbgp paths'. Those functions results are the
11182 same.*/
11183 DEFUN (show_ip_bgp_paths,
11184 show_ip_bgp_paths_cmd,
11185 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11186 SHOW_STR
11187 IP_STR
11188 BGP_STR
11189 BGP_SAFI_HELP_STR
11190 "Path information\n")
11191 {
11192 vty_out(vty, "Address Refcnt Path\n");
11193 aspath_print_all_vty(vty);
11194 return CMD_SUCCESS;
11195 }
11196
11197 #include "hash.h"
11198
11199 static void community_show_all_iterator(struct hash_bucket *bucket,
11200 struct vty *vty)
11201 {
11202 struct community *com;
11203
11204 com = (struct community *)bucket->data;
11205 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11206 community_str(com, false));
11207 }
11208
11209 /* Show BGP's community internal data. */
11210 DEFUN (show_ip_bgp_community_info,
11211 show_ip_bgp_community_info_cmd,
11212 "show [ip] bgp community-info",
11213 SHOW_STR
11214 IP_STR
11215 BGP_STR
11216 "List all bgp community information\n")
11217 {
11218 vty_out(vty, "Address Refcnt Community\n");
11219
11220 hash_iterate(community_hash(),
11221 (void (*)(struct hash_bucket *,
11222 void *))community_show_all_iterator,
11223 vty);
11224
11225 return CMD_SUCCESS;
11226 }
11227
11228 static void lcommunity_show_all_iterator(struct hash_bucket *bucket,
11229 struct vty *vty)
11230 {
11231 struct lcommunity *lcom;
11232
11233 lcom = (struct lcommunity *)bucket->data;
11234 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11235 lcommunity_str(lcom, false));
11236 }
11237
11238 /* Show BGP's community internal data. */
11239 DEFUN (show_ip_bgp_lcommunity_info,
11240 show_ip_bgp_lcommunity_info_cmd,
11241 "show ip bgp large-community-info",
11242 SHOW_STR
11243 IP_STR
11244 BGP_STR
11245 "List all bgp large-community information\n")
11246 {
11247 vty_out(vty, "Address Refcnt Large-community\n");
11248
11249 hash_iterate(lcommunity_hash(),
11250 (void (*)(struct hash_bucket *,
11251 void *))lcommunity_show_all_iterator,
11252 vty);
11253
11254 return CMD_SUCCESS;
11255 }
11256
11257
11258 DEFUN (show_ip_bgp_attr_info,
11259 show_ip_bgp_attr_info_cmd,
11260 "show [ip] bgp attribute-info",
11261 SHOW_STR
11262 IP_STR
11263 BGP_STR
11264 "List all bgp attribute information\n")
11265 {
11266 attr_show_all(vty);
11267 return CMD_SUCCESS;
11268 }
11269
11270 static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11271 safi_t safi, bool use_json)
11272 {
11273 struct bgp *bgp;
11274 struct listnode *node;
11275 char *vname;
11276 char buf1[INET6_ADDRSTRLEN];
11277 char *ecom_str;
11278 vpn_policy_direction_t dir;
11279
11280 if (use_json) {
11281 json_object *json = NULL;
11282 json_object *json_import_vrfs = NULL;
11283 json_object *json_export_vrfs = NULL;
11284
11285 json = json_object_new_object();
11286
11287 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11288
11289 if (!bgp) {
11290 vty_out(vty, "%s\n",
11291 json_object_to_json_string_ext(
11292 json,
11293 JSON_C_TO_STRING_PRETTY));
11294 json_object_free(json);
11295
11296 return CMD_WARNING;
11297 }
11298
11299 /* Provide context for the block */
11300 json_object_string_add(json, "vrf", name ? name : "default");
11301 json_object_string_add(json, "afiSafi",
11302 afi_safi_print(afi, safi));
11303
11304 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11305 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11306 json_object_string_add(json, "importFromVrfs", "none");
11307 json_object_string_add(json, "importRts", "none");
11308 } else {
11309 json_import_vrfs = json_object_new_array();
11310
11311 for (ALL_LIST_ELEMENTS_RO(
11312 bgp->vpn_policy[afi].import_vrf,
11313 node, vname))
11314 json_object_array_add(json_import_vrfs,
11315 json_object_new_string(vname));
11316
11317 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11318 ecom_str = ecommunity_ecom2str(
11319 bgp->vpn_policy[afi].rtlist[dir],
11320 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11321 json_object_object_add(json, "importFromVrfs",
11322 json_import_vrfs);
11323 json_object_string_add(json, "importRts", ecom_str);
11324
11325 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11326 }
11327
11328 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11329 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11330 json_object_string_add(json, "exportToVrfs", "none");
11331 json_object_string_add(json, "routeDistinguisher",
11332 "none");
11333 json_object_string_add(json, "exportRts", "none");
11334 } else {
11335 json_export_vrfs = json_object_new_array();
11336
11337 for (ALL_LIST_ELEMENTS_RO(
11338 bgp->vpn_policy[afi].export_vrf,
11339 node, vname))
11340 json_object_array_add(json_export_vrfs,
11341 json_object_new_string(vname));
11342 json_object_object_add(json, "exportToVrfs",
11343 json_export_vrfs);
11344 json_object_string_add(json, "routeDistinguisher",
11345 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11346 buf1, RD_ADDRSTRLEN));
11347
11348 dir = BGP_VPN_POLICY_DIR_TOVPN;
11349 ecom_str = ecommunity_ecom2str(
11350 bgp->vpn_policy[afi].rtlist[dir],
11351 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11352 json_object_string_add(json, "exportRts", ecom_str);
11353
11354 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11355 }
11356
11357 vty_out(vty, "%s\n",
11358 json_object_to_json_string_ext(json,
11359 JSON_C_TO_STRING_PRETTY));
11360 json_object_free(json);
11361
11362 } else {
11363 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11364
11365 if (!bgp) {
11366 vty_out(vty, "%% No such BGP instance exist\n");
11367 return CMD_WARNING;
11368 }
11369
11370 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11371 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11372 vty_out(vty,
11373 "This VRF is not importing %s routes from any other VRF\n",
11374 afi_safi_print(afi, safi));
11375 else {
11376 vty_out(vty,
11377 "This VRF is importing %s routes from the following VRFs:\n",
11378 afi_safi_print(afi, safi));
11379
11380 for (ALL_LIST_ELEMENTS_RO(
11381 bgp->vpn_policy[afi].import_vrf,
11382 node, vname))
11383 vty_out(vty, " %s\n", vname);
11384
11385 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11386 ecom_str = ecommunity_ecom2str(
11387 bgp->vpn_policy[afi].rtlist[dir],
11388 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11389 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11390
11391 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11392 }
11393
11394 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11395 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11396 vty_out(vty,
11397 "This VRF is not exporting %s routes to any other VRF\n",
11398 afi_safi_print(afi, safi));
11399 else {
11400 vty_out(vty,
11401 "This VRF is exporting %s routes to the following VRFs:\n",
11402 afi_safi_print(afi, safi));
11403
11404 for (ALL_LIST_ELEMENTS_RO(
11405 bgp->vpn_policy[afi].export_vrf,
11406 node, vname))
11407 vty_out(vty, " %s\n", vname);
11408
11409 vty_out(vty, "RD: %s\n",
11410 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11411 buf1, RD_ADDRSTRLEN));
11412
11413 dir = BGP_VPN_POLICY_DIR_TOVPN;
11414 ecom_str = ecommunity_ecom2str(
11415 bgp->vpn_policy[afi].rtlist[dir],
11416 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11417 vty_out(vty, "Export RT: %s\n", ecom_str);
11418 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11419 }
11420 }
11421
11422 return CMD_SUCCESS;
11423 }
11424
11425 /* "show [ip] bgp route-leak" command. */
11426 DEFUN (show_ip_bgp_route_leak,
11427 show_ip_bgp_route_leak_cmd,
11428 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11429 SHOW_STR
11430 IP_STR
11431 BGP_STR
11432 BGP_INSTANCE_HELP_STR
11433 BGP_AFI_HELP_STR
11434 BGP_SAFI_HELP_STR
11435 "Route leaking information\n"
11436 JSON_STR)
11437 {
11438 char *vrf = NULL;
11439 afi_t afi = AFI_MAX;
11440 safi_t safi = SAFI_MAX;
11441
11442 bool uj = use_json(argc, argv);
11443 int idx = 0;
11444
11445 /* show [ip] bgp */
11446 if (argv_find(argv, argc, "ip", &idx)) {
11447 afi = AFI_IP;
11448 safi = SAFI_UNICAST;
11449 }
11450 /* [vrf VIEWVRFNAME] */
11451 if (argv_find(argv, argc, "view", &idx)) {
11452 vty_out(vty,
11453 "%% This command is not applicable to BGP views\n");
11454 return CMD_WARNING;
11455 }
11456
11457 if (argv_find(argv, argc, "vrf", &idx)) {
11458 vrf = argv[idx + 1]->arg;
11459 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11460 vrf = NULL;
11461 }
11462 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11463 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11464 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11465 }
11466
11467 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11468 vty_out(vty,
11469 "%% This command is applicable only for unicast ipv4|ipv6\n");
11470 return CMD_WARNING;
11471 }
11472
11473 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
11474 }
11475
11476 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11477 safi_t safi)
11478 {
11479 struct listnode *node, *nnode;
11480 struct bgp *bgp;
11481
11482 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11483 vty_out(vty, "\nInstance %s:\n",
11484 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11485 ? VRF_DEFAULT_NAME
11486 : bgp->name);
11487 update_group_show(bgp, afi, safi, vty, 0);
11488 }
11489 }
11490
11491 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11492 int safi, uint64_t subgrp_id)
11493 {
11494 struct bgp *bgp;
11495
11496 if (name) {
11497 if (strmatch(name, "all")) {
11498 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11499 return CMD_SUCCESS;
11500 } else {
11501 bgp = bgp_lookup_by_name(name);
11502 }
11503 } else {
11504 bgp = bgp_get_default();
11505 }
11506
11507 if (bgp)
11508 update_group_show(bgp, afi, safi, vty, subgrp_id);
11509 return CMD_SUCCESS;
11510 }
11511
11512 DEFUN (show_ip_bgp_updgrps,
11513 show_ip_bgp_updgrps_cmd,
11514 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11515 SHOW_STR
11516 IP_STR
11517 BGP_STR
11518 BGP_INSTANCE_HELP_STR
11519 BGP_AFI_HELP_STR
11520 BGP_SAFI_WITH_LABEL_HELP_STR
11521 "Detailed info about dynamic update groups\n"
11522 "Specific subgroup to display detailed info for\n")
11523 {
11524 char *vrf = NULL;
11525 afi_t afi = AFI_IP6;
11526 safi_t safi = SAFI_UNICAST;
11527 uint64_t subgrp_id = 0;
11528
11529 int idx = 0;
11530
11531 /* show [ip] bgp */
11532 if (argv_find(argv, argc, "ip", &idx))
11533 afi = AFI_IP;
11534 /* [<vrf> VIEWVRFNAME] */
11535 if (argv_find(argv, argc, "vrf", &idx)) {
11536 vrf = argv[idx + 1]->arg;
11537 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11538 vrf = NULL;
11539 } else if (argv_find(argv, argc, "view", &idx))
11540 /* [<view> VIEWVRFNAME] */
11541 vrf = argv[idx + 1]->arg;
11542 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11543 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11544 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11545 }
11546
11547 /* get subgroup id, if provided */
11548 idx = argc - 1;
11549 if (argv[idx]->type == VARIABLE_TKN)
11550 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11551
11552 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11553 }
11554
11555 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11556 show_bgp_instance_all_ipv6_updgrps_cmd,
11557 "show [ip] bgp <view|vrf> all update-groups",
11558 SHOW_STR
11559 IP_STR
11560 BGP_STR
11561 BGP_INSTANCE_ALL_HELP_STR
11562 "Detailed info about dynamic update groups\n")
11563 {
11564 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11565 return CMD_SUCCESS;
11566 }
11567
11568 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11569 show_bgp_l2vpn_evpn_updgrps_cmd,
11570 "show [ip] bgp l2vpn evpn update-groups",
11571 SHOW_STR
11572 IP_STR
11573 BGP_STR
11574 "l2vpn address family\n"
11575 "evpn sub-address family\n"
11576 "Detailed info about dynamic update groups\n")
11577 {
11578 char *vrf = NULL;
11579 uint64_t subgrp_id = 0;
11580
11581 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11582 return CMD_SUCCESS;
11583 }
11584
11585 DEFUN (show_bgp_updgrps_stats,
11586 show_bgp_updgrps_stats_cmd,
11587 "show [ip] bgp update-groups statistics",
11588 SHOW_STR
11589 IP_STR
11590 BGP_STR
11591 "Detailed info about dynamic update groups\n"
11592 "Statistics\n")
11593 {
11594 struct bgp *bgp;
11595
11596 bgp = bgp_get_default();
11597 if (bgp)
11598 update_group_show_stats(bgp, vty);
11599
11600 return CMD_SUCCESS;
11601 }
11602
11603 DEFUN (show_bgp_instance_updgrps_stats,
11604 show_bgp_instance_updgrps_stats_cmd,
11605 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11606 SHOW_STR
11607 IP_STR
11608 BGP_STR
11609 BGP_INSTANCE_HELP_STR
11610 "Detailed info about dynamic update groups\n"
11611 "Statistics\n")
11612 {
11613 int idx_word = 3;
11614 struct bgp *bgp;
11615
11616 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11617 if (bgp)
11618 update_group_show_stats(bgp, vty);
11619
11620 return CMD_SUCCESS;
11621 }
11622
11623 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11624 afi_t afi, safi_t safi,
11625 const char *what, uint64_t subgrp_id)
11626 {
11627 struct bgp *bgp;
11628
11629 if (name)
11630 bgp = bgp_lookup_by_name(name);
11631 else
11632 bgp = bgp_get_default();
11633
11634 if (bgp) {
11635 if (!strcmp(what, "advertise-queue"))
11636 update_group_show_adj_queue(bgp, afi, safi, vty,
11637 subgrp_id);
11638 else if (!strcmp(what, "advertised-routes"))
11639 update_group_show_advertised(bgp, afi, safi, vty,
11640 subgrp_id);
11641 else if (!strcmp(what, "packet-queue"))
11642 update_group_show_packet_queue(bgp, afi, safi, vty,
11643 subgrp_id);
11644 }
11645 }
11646
11647 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11648 show_ip_bgp_instance_updgrps_adj_s_cmd,
11649 "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",
11650 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11651 BGP_SAFI_HELP_STR
11652 "Detailed info about dynamic update groups\n"
11653 "Specific subgroup to display info for\n"
11654 "Advertisement queue\n"
11655 "Announced routes\n"
11656 "Packet queue\n")
11657 {
11658 uint64_t subgrp_id = 0;
11659 afi_t afiz;
11660 safi_t safiz;
11661 if (sgid)
11662 subgrp_id = strtoull(sgid, NULL, 10);
11663
11664 if (!ip && !afi)
11665 afiz = AFI_IP6;
11666 if (!ip && afi)
11667 afiz = bgp_vty_afi_from_str(afi);
11668 if (ip && !afi)
11669 afiz = AFI_IP;
11670 if (ip && afi) {
11671 afiz = bgp_vty_afi_from_str(afi);
11672 if (afiz != AFI_IP)
11673 vty_out(vty,
11674 "%% Cannot specify both 'ip' and 'ipv6'\n");
11675 return CMD_WARNING;
11676 }
11677
11678 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11679
11680 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11681 return CMD_SUCCESS;
11682 }
11683
11684 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11685 {
11686 struct listnode *node, *nnode;
11687 struct prefix *range;
11688 struct peer *conf;
11689 struct peer *peer;
11690 char buf[PREFIX2STR_BUFFER];
11691 afi_t afi;
11692 safi_t safi;
11693 const char *peer_status;
11694 const char *af_str;
11695 int lr_count;
11696 int dynamic;
11697 int af_cfgd;
11698
11699 conf = group->conf;
11700
11701 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11702 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11703 group->name, conf->as);
11704 } else if (conf->as_type == AS_INTERNAL) {
11705 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11706 group->name, group->bgp->as);
11707 } else {
11708 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11709 }
11710
11711 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11712 vty_out(vty, " Peer-group type is internal\n");
11713 else
11714 vty_out(vty, " Peer-group type is external\n");
11715
11716 /* Display AFs configured. */
11717 vty_out(vty, " Configured address-families:");
11718 FOREACH_AFI_SAFI (afi, safi) {
11719 if (conf->afc[afi][safi]) {
11720 af_cfgd = 1;
11721 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11722 }
11723 }
11724 if (!af_cfgd)
11725 vty_out(vty, " none\n");
11726 else
11727 vty_out(vty, "\n");
11728
11729 /* Display listen ranges (for dynamic neighbors), if any */
11730 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11731 if (afi == AFI_IP)
11732 af_str = "IPv4";
11733 else if (afi == AFI_IP6)
11734 af_str = "IPv6";
11735 else
11736 af_str = "???";
11737 lr_count = listcount(group->listen_range[afi]);
11738 if (lr_count) {
11739 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11740 af_str);
11741
11742
11743 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11744 nnode, range)) {
11745 prefix2str(range, buf, sizeof(buf));
11746 vty_out(vty, " %s\n", buf);
11747 }
11748 }
11749 }
11750
11751 /* Display group members and their status */
11752 if (listcount(group->peer)) {
11753 vty_out(vty, " Peer-group members:\n");
11754 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11755 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11756 peer_status = "Idle (Admin)";
11757 else if (CHECK_FLAG(peer->sflags,
11758 PEER_STATUS_PREFIX_OVERFLOW))
11759 peer_status = "Idle (PfxCt)";
11760 else
11761 peer_status = lookup_msg(bgp_status_msg,
11762 peer->status, NULL);
11763
11764 dynamic = peer_dynamic_neighbor(peer);
11765 vty_out(vty, " %s %s %s \n", peer->host,
11766 dynamic ? "(dynamic)" : "", peer_status);
11767 }
11768 }
11769
11770 return CMD_SUCCESS;
11771 }
11772
11773 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11774 const char *group_name)
11775 {
11776 struct bgp *bgp;
11777 struct listnode *node, *nnode;
11778 struct peer_group *group;
11779 bool found = false;
11780
11781 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11782
11783 if (!bgp) {
11784 vty_out(vty, "%% BGP instance not found\n");
11785 return CMD_WARNING;
11786 }
11787
11788 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11789 if (group_name) {
11790 if (strmatch(group->name, group_name)) {
11791 bgp_show_one_peer_group(vty, group);
11792 found = true;
11793 break;
11794 }
11795 } else {
11796 bgp_show_one_peer_group(vty, group);
11797 }
11798 }
11799
11800 if (group_name && !found)
11801 vty_out(vty, "%% No such peer-group\n");
11802
11803 return CMD_SUCCESS;
11804 }
11805
11806 DEFUN (show_ip_bgp_peer_groups,
11807 show_ip_bgp_peer_groups_cmd,
11808 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11809 SHOW_STR
11810 IP_STR
11811 BGP_STR
11812 BGP_INSTANCE_HELP_STR
11813 "Detailed information on BGP peer groups\n"
11814 "Peer group name\n")
11815 {
11816 char *vrf, *pg;
11817 int idx = 0;
11818
11819 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11820 : NULL;
11821 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11822
11823 return bgp_show_peer_group_vty(vty, vrf, pg);
11824 }
11825
11826
11827 /* Redistribute VTY commands. */
11828
11829 DEFUN (bgp_redistribute_ipv4,
11830 bgp_redistribute_ipv4_cmd,
11831 "redistribute " FRR_IP_REDIST_STR_BGPD,
11832 "Redistribute information from another routing protocol\n"
11833 FRR_IP_REDIST_HELP_STR_BGPD)
11834 {
11835 VTY_DECLVAR_CONTEXT(bgp, bgp);
11836 int idx_protocol = 1;
11837 int type;
11838
11839 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11840 if (type < 0) {
11841 vty_out(vty, "%% Invalid route type\n");
11842 return CMD_WARNING_CONFIG_FAILED;
11843 }
11844
11845 bgp_redist_add(bgp, AFI_IP, type, 0);
11846 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11847 }
11848
11849 ALIAS_HIDDEN(
11850 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11851 "redistribute " FRR_IP_REDIST_STR_BGPD,
11852 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11853
11854 DEFUN (bgp_redistribute_ipv4_rmap,
11855 bgp_redistribute_ipv4_rmap_cmd,
11856 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11857 "Redistribute information from another routing protocol\n"
11858 FRR_IP_REDIST_HELP_STR_BGPD
11859 "Route map reference\n"
11860 "Pointer to route-map entries\n")
11861 {
11862 VTY_DECLVAR_CONTEXT(bgp, bgp);
11863 int idx_protocol = 1;
11864 int idx_word = 3;
11865 int type;
11866 struct bgp_redist *red;
11867 bool changed;
11868 struct route_map *route_map = route_map_lookup_warn_noexist(
11869 vty, argv[idx_word]->arg);
11870
11871 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11872 if (type < 0) {
11873 vty_out(vty, "%% Invalid route type\n");
11874 return CMD_WARNING_CONFIG_FAILED;
11875 }
11876
11877 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11878 changed =
11879 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11880 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11881 }
11882
11883 ALIAS_HIDDEN(
11884 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11885 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11886 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11887 "Route map reference\n"
11888 "Pointer to route-map entries\n")
11889
11890 DEFUN (bgp_redistribute_ipv4_metric,
11891 bgp_redistribute_ipv4_metric_cmd,
11892 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11893 "Redistribute information from another routing protocol\n"
11894 FRR_IP_REDIST_HELP_STR_BGPD
11895 "Metric for redistributed routes\n"
11896 "Default metric\n")
11897 {
11898 VTY_DECLVAR_CONTEXT(bgp, bgp);
11899 int idx_protocol = 1;
11900 int idx_number = 3;
11901 int type;
11902 uint32_t metric;
11903 struct bgp_redist *red;
11904 bool changed;
11905
11906 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11907 if (type < 0) {
11908 vty_out(vty, "%% Invalid route type\n");
11909 return CMD_WARNING_CONFIG_FAILED;
11910 }
11911 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11912
11913 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11914 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11915 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11916 }
11917
11918 ALIAS_HIDDEN(
11919 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11920 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11921 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11922 "Metric for redistributed routes\n"
11923 "Default metric\n")
11924
11925 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11926 bgp_redistribute_ipv4_rmap_metric_cmd,
11927 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11928 "Redistribute information from another routing protocol\n"
11929 FRR_IP_REDIST_HELP_STR_BGPD
11930 "Route map reference\n"
11931 "Pointer to route-map entries\n"
11932 "Metric for redistributed routes\n"
11933 "Default metric\n")
11934 {
11935 VTY_DECLVAR_CONTEXT(bgp, bgp);
11936 int idx_protocol = 1;
11937 int idx_word = 3;
11938 int idx_number = 5;
11939 int type;
11940 uint32_t metric;
11941 struct bgp_redist *red;
11942 bool changed;
11943 struct route_map *route_map =
11944 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11945
11946 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11947 if (type < 0) {
11948 vty_out(vty, "%% Invalid route type\n");
11949 return CMD_WARNING_CONFIG_FAILED;
11950 }
11951 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11952
11953 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11954 changed =
11955 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11956 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11957 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11958 }
11959
11960 ALIAS_HIDDEN(
11961 bgp_redistribute_ipv4_rmap_metric,
11962 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11963 "redistribute " FRR_IP_REDIST_STR_BGPD
11964 " route-map WORD metric (0-4294967295)",
11965 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11966 "Route map reference\n"
11967 "Pointer to route-map entries\n"
11968 "Metric for redistributed routes\n"
11969 "Default metric\n")
11970
11971 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11972 bgp_redistribute_ipv4_metric_rmap_cmd,
11973 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11974 "Redistribute information from another routing protocol\n"
11975 FRR_IP_REDIST_HELP_STR_BGPD
11976 "Metric for redistributed routes\n"
11977 "Default metric\n"
11978 "Route map reference\n"
11979 "Pointer to route-map entries\n")
11980 {
11981 VTY_DECLVAR_CONTEXT(bgp, bgp);
11982 int idx_protocol = 1;
11983 int idx_number = 3;
11984 int idx_word = 5;
11985 int type;
11986 uint32_t metric;
11987 struct bgp_redist *red;
11988 bool changed;
11989 struct route_map *route_map =
11990 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11991
11992 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11993 if (type < 0) {
11994 vty_out(vty, "%% Invalid route type\n");
11995 return CMD_WARNING_CONFIG_FAILED;
11996 }
11997 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11998
11999 red = bgp_redist_add(bgp, AFI_IP, type, 0);
12000 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
12001 changed |=
12002 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12003 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
12004 }
12005
12006 ALIAS_HIDDEN(
12007 bgp_redistribute_ipv4_metric_rmap,
12008 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
12009 "redistribute " FRR_IP_REDIST_STR_BGPD
12010 " metric (0-4294967295) route-map WORD",
12011 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12012 "Metric for redistributed routes\n"
12013 "Default metric\n"
12014 "Route map reference\n"
12015 "Pointer to route-map entries\n")
12016
12017 DEFUN (bgp_redistribute_ipv4_ospf,
12018 bgp_redistribute_ipv4_ospf_cmd,
12019 "redistribute <ospf|table> (1-65535)",
12020 "Redistribute information from another routing protocol\n"
12021 "Open Shortest Path First (OSPFv2)\n"
12022 "Non-main Kernel Routing Table\n"
12023 "Instance ID/Table ID\n")
12024 {
12025 VTY_DECLVAR_CONTEXT(bgp, bgp);
12026 int idx_ospf_table = 1;
12027 int idx_number = 2;
12028 unsigned short instance;
12029 unsigned short protocol;
12030
12031 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12032
12033 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12034 protocol = ZEBRA_ROUTE_OSPF;
12035 else
12036 protocol = ZEBRA_ROUTE_TABLE;
12037
12038 bgp_redist_add(bgp, AFI_IP, protocol, instance);
12039 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
12040 }
12041
12042 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
12043 "redistribute <ospf|table> (1-65535)",
12044 "Redistribute information from another routing protocol\n"
12045 "Open Shortest Path First (OSPFv2)\n"
12046 "Non-main Kernel Routing Table\n"
12047 "Instance ID/Table ID\n")
12048
12049 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
12050 bgp_redistribute_ipv4_ospf_rmap_cmd,
12051 "redistribute <ospf|table> (1-65535) route-map WORD",
12052 "Redistribute information from another routing protocol\n"
12053 "Open Shortest Path First (OSPFv2)\n"
12054 "Non-main Kernel Routing Table\n"
12055 "Instance ID/Table ID\n"
12056 "Route map reference\n"
12057 "Pointer to route-map entries\n")
12058 {
12059 VTY_DECLVAR_CONTEXT(bgp, bgp);
12060 int idx_ospf_table = 1;
12061 int idx_number = 2;
12062 int idx_word = 4;
12063 struct bgp_redist *red;
12064 unsigned short instance;
12065 int protocol;
12066 bool changed;
12067 struct route_map *route_map =
12068 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12069
12070 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12071 protocol = ZEBRA_ROUTE_OSPF;
12072 else
12073 protocol = ZEBRA_ROUTE_TABLE;
12074
12075 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12076 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12077 changed =
12078 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12079 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12080 }
12081
12082 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12083 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12084 "redistribute <ospf|table> (1-65535) route-map WORD",
12085 "Redistribute information from another routing protocol\n"
12086 "Open Shortest Path First (OSPFv2)\n"
12087 "Non-main Kernel Routing Table\n"
12088 "Instance ID/Table ID\n"
12089 "Route map reference\n"
12090 "Pointer to route-map entries\n")
12091
12092 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12093 bgp_redistribute_ipv4_ospf_metric_cmd,
12094 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12095 "Redistribute information from another routing protocol\n"
12096 "Open Shortest Path First (OSPFv2)\n"
12097 "Non-main Kernel Routing Table\n"
12098 "Instance ID/Table ID\n"
12099 "Metric for redistributed routes\n"
12100 "Default metric\n")
12101 {
12102 VTY_DECLVAR_CONTEXT(bgp, bgp);
12103 int idx_ospf_table = 1;
12104 int idx_number = 2;
12105 int idx_number_2 = 4;
12106 uint32_t metric;
12107 struct bgp_redist *red;
12108 unsigned short instance;
12109 int protocol;
12110 bool changed;
12111
12112 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12113 protocol = ZEBRA_ROUTE_OSPF;
12114 else
12115 protocol = ZEBRA_ROUTE_TABLE;
12116
12117 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12118 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12119
12120 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12121 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12122 metric);
12123 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12124 }
12125
12126 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12127 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12128 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12129 "Redistribute information from another routing protocol\n"
12130 "Open Shortest Path First (OSPFv2)\n"
12131 "Non-main Kernel Routing Table\n"
12132 "Instance ID/Table ID\n"
12133 "Metric for redistributed routes\n"
12134 "Default metric\n")
12135
12136 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12137 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12138 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12139 "Redistribute information from another routing protocol\n"
12140 "Open Shortest Path First (OSPFv2)\n"
12141 "Non-main Kernel Routing Table\n"
12142 "Instance ID/Table ID\n"
12143 "Route map reference\n"
12144 "Pointer to route-map entries\n"
12145 "Metric for redistributed routes\n"
12146 "Default metric\n")
12147 {
12148 VTY_DECLVAR_CONTEXT(bgp, bgp);
12149 int idx_ospf_table = 1;
12150 int idx_number = 2;
12151 int idx_word = 4;
12152 int idx_number_2 = 6;
12153 uint32_t metric;
12154 struct bgp_redist *red;
12155 unsigned short instance;
12156 int protocol;
12157 bool changed;
12158 struct route_map *route_map =
12159 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12160
12161 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12162 protocol = ZEBRA_ROUTE_OSPF;
12163 else
12164 protocol = ZEBRA_ROUTE_TABLE;
12165
12166 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12167 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12168
12169 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12170 changed =
12171 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12172 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12173 metric);
12174 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12175 }
12176
12177 ALIAS_HIDDEN(
12178 bgp_redistribute_ipv4_ospf_rmap_metric,
12179 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12180 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12181 "Redistribute information from another routing protocol\n"
12182 "Open Shortest Path First (OSPFv2)\n"
12183 "Non-main Kernel Routing Table\n"
12184 "Instance ID/Table ID\n"
12185 "Route map reference\n"
12186 "Pointer to route-map entries\n"
12187 "Metric for redistributed routes\n"
12188 "Default metric\n")
12189
12190 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12191 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12192 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12193 "Redistribute information from another routing protocol\n"
12194 "Open Shortest Path First (OSPFv2)\n"
12195 "Non-main Kernel Routing Table\n"
12196 "Instance ID/Table ID\n"
12197 "Metric for redistributed routes\n"
12198 "Default metric\n"
12199 "Route map reference\n"
12200 "Pointer to route-map entries\n")
12201 {
12202 VTY_DECLVAR_CONTEXT(bgp, bgp);
12203 int idx_ospf_table = 1;
12204 int idx_number = 2;
12205 int idx_number_2 = 4;
12206 int idx_word = 6;
12207 uint32_t metric;
12208 struct bgp_redist *red;
12209 unsigned short instance;
12210 int protocol;
12211 bool changed;
12212 struct route_map *route_map =
12213 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12214
12215 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12216 protocol = ZEBRA_ROUTE_OSPF;
12217 else
12218 protocol = ZEBRA_ROUTE_TABLE;
12219
12220 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12221 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12222
12223 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12224 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12225 metric);
12226 changed |=
12227 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12228 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12229 }
12230
12231 ALIAS_HIDDEN(
12232 bgp_redistribute_ipv4_ospf_metric_rmap,
12233 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12234 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12235 "Redistribute information from another routing protocol\n"
12236 "Open Shortest Path First (OSPFv2)\n"
12237 "Non-main Kernel Routing Table\n"
12238 "Instance ID/Table ID\n"
12239 "Metric for redistributed routes\n"
12240 "Default metric\n"
12241 "Route map reference\n"
12242 "Pointer to route-map entries\n")
12243
12244 DEFUN (no_bgp_redistribute_ipv4_ospf,
12245 no_bgp_redistribute_ipv4_ospf_cmd,
12246 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12247 NO_STR
12248 "Redistribute information from another routing protocol\n"
12249 "Open Shortest Path First (OSPFv2)\n"
12250 "Non-main Kernel Routing Table\n"
12251 "Instance ID/Table ID\n"
12252 "Metric for redistributed routes\n"
12253 "Default metric\n"
12254 "Route map reference\n"
12255 "Pointer to route-map entries\n")
12256 {
12257 VTY_DECLVAR_CONTEXT(bgp, bgp);
12258 int idx_ospf_table = 2;
12259 int idx_number = 3;
12260 unsigned short instance;
12261 int protocol;
12262
12263 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12264 protocol = ZEBRA_ROUTE_OSPF;
12265 else
12266 protocol = ZEBRA_ROUTE_TABLE;
12267
12268 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12269 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12270 }
12271
12272 ALIAS_HIDDEN(
12273 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12274 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12275 NO_STR
12276 "Redistribute information from another routing protocol\n"
12277 "Open Shortest Path First (OSPFv2)\n"
12278 "Non-main Kernel Routing Table\n"
12279 "Instance ID/Table ID\n"
12280 "Metric for redistributed routes\n"
12281 "Default metric\n"
12282 "Route map reference\n"
12283 "Pointer to route-map entries\n")
12284
12285 DEFUN (no_bgp_redistribute_ipv4,
12286 no_bgp_redistribute_ipv4_cmd,
12287 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12288 NO_STR
12289 "Redistribute information from another routing protocol\n"
12290 FRR_IP_REDIST_HELP_STR_BGPD
12291 "Metric for redistributed routes\n"
12292 "Default metric\n"
12293 "Route map reference\n"
12294 "Pointer to route-map entries\n")
12295 {
12296 VTY_DECLVAR_CONTEXT(bgp, bgp);
12297 int idx_protocol = 2;
12298 int type;
12299
12300 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12301 if (type < 0) {
12302 vty_out(vty, "%% Invalid route type\n");
12303 return CMD_WARNING_CONFIG_FAILED;
12304 }
12305 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12306 }
12307
12308 ALIAS_HIDDEN(
12309 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12310 "no redistribute " FRR_IP_REDIST_STR_BGPD
12311 " [metric (0-4294967295)] [route-map WORD]",
12312 NO_STR
12313 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12314 "Metric for redistributed routes\n"
12315 "Default metric\n"
12316 "Route map reference\n"
12317 "Pointer to route-map entries\n")
12318
12319 DEFUN (bgp_redistribute_ipv6,
12320 bgp_redistribute_ipv6_cmd,
12321 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12322 "Redistribute information from another routing protocol\n"
12323 FRR_IP6_REDIST_HELP_STR_BGPD)
12324 {
12325 VTY_DECLVAR_CONTEXT(bgp, bgp);
12326 int idx_protocol = 1;
12327 int type;
12328
12329 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12330 if (type < 0) {
12331 vty_out(vty, "%% Invalid route type\n");
12332 return CMD_WARNING_CONFIG_FAILED;
12333 }
12334
12335 bgp_redist_add(bgp, AFI_IP6, type, 0);
12336 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12337 }
12338
12339 DEFUN (bgp_redistribute_ipv6_rmap,
12340 bgp_redistribute_ipv6_rmap_cmd,
12341 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12342 "Redistribute information from another routing protocol\n"
12343 FRR_IP6_REDIST_HELP_STR_BGPD
12344 "Route map reference\n"
12345 "Pointer to route-map entries\n")
12346 {
12347 VTY_DECLVAR_CONTEXT(bgp, bgp);
12348 int idx_protocol = 1;
12349 int idx_word = 3;
12350 int type;
12351 struct bgp_redist *red;
12352 bool changed;
12353 struct route_map *route_map =
12354 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12355
12356 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12357 if (type < 0) {
12358 vty_out(vty, "%% Invalid route type\n");
12359 return CMD_WARNING_CONFIG_FAILED;
12360 }
12361
12362 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12363 changed =
12364 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12365 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12366 }
12367
12368 DEFUN (bgp_redistribute_ipv6_metric,
12369 bgp_redistribute_ipv6_metric_cmd,
12370 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12371 "Redistribute information from another routing protocol\n"
12372 FRR_IP6_REDIST_HELP_STR_BGPD
12373 "Metric for redistributed routes\n"
12374 "Default metric\n")
12375 {
12376 VTY_DECLVAR_CONTEXT(bgp, bgp);
12377 int idx_protocol = 1;
12378 int idx_number = 3;
12379 int type;
12380 uint32_t metric;
12381 struct bgp_redist *red;
12382 bool changed;
12383
12384 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12385 if (type < 0) {
12386 vty_out(vty, "%% Invalid route type\n");
12387 return CMD_WARNING_CONFIG_FAILED;
12388 }
12389 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12390
12391 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12392 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12393 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12394 }
12395
12396 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12397 bgp_redistribute_ipv6_rmap_metric_cmd,
12398 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12399 "Redistribute information from another routing protocol\n"
12400 FRR_IP6_REDIST_HELP_STR_BGPD
12401 "Route map reference\n"
12402 "Pointer to route-map entries\n"
12403 "Metric for redistributed routes\n"
12404 "Default metric\n")
12405 {
12406 VTY_DECLVAR_CONTEXT(bgp, bgp);
12407 int idx_protocol = 1;
12408 int idx_word = 3;
12409 int idx_number = 5;
12410 int type;
12411 uint32_t metric;
12412 struct bgp_redist *red;
12413 bool changed;
12414 struct route_map *route_map =
12415 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12416
12417 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12418 if (type < 0) {
12419 vty_out(vty, "%% Invalid route type\n");
12420 return CMD_WARNING_CONFIG_FAILED;
12421 }
12422 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12423
12424 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12425 changed =
12426 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12427 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12428 metric);
12429 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12430 }
12431
12432 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12433 bgp_redistribute_ipv6_metric_rmap_cmd,
12434 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12435 "Redistribute information from another routing protocol\n"
12436 FRR_IP6_REDIST_HELP_STR_BGPD
12437 "Metric for redistributed routes\n"
12438 "Default metric\n"
12439 "Route map reference\n"
12440 "Pointer to route-map entries\n")
12441 {
12442 VTY_DECLVAR_CONTEXT(bgp, bgp);
12443 int idx_protocol = 1;
12444 int idx_number = 3;
12445 int idx_word = 5;
12446 int type;
12447 uint32_t metric;
12448 struct bgp_redist *red;
12449 bool changed;
12450 struct route_map *route_map =
12451 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12452
12453 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12454 if (type < 0) {
12455 vty_out(vty, "%% Invalid route type\n");
12456 return CMD_WARNING_CONFIG_FAILED;
12457 }
12458 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12459
12460 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12461 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12462 metric);
12463 changed |=
12464 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12465 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12466 }
12467
12468 DEFUN (no_bgp_redistribute_ipv6,
12469 no_bgp_redistribute_ipv6_cmd,
12470 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12471 NO_STR
12472 "Redistribute information from another routing protocol\n"
12473 FRR_IP6_REDIST_HELP_STR_BGPD
12474 "Metric for redistributed routes\n"
12475 "Default metric\n"
12476 "Route map reference\n"
12477 "Pointer to route-map entries\n")
12478 {
12479 VTY_DECLVAR_CONTEXT(bgp, bgp);
12480 int idx_protocol = 2;
12481 int type;
12482
12483 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12484 if (type < 0) {
12485 vty_out(vty, "%% Invalid route type\n");
12486 return CMD_WARNING_CONFIG_FAILED;
12487 }
12488
12489 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12490 }
12491
12492 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12493 safi_t safi)
12494 {
12495 int i;
12496
12497 /* Unicast redistribution only. */
12498 if (safi != SAFI_UNICAST)
12499 return;
12500
12501 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12502 /* Redistribute BGP does not make sense. */
12503 if (i != ZEBRA_ROUTE_BGP) {
12504 struct list *red_list;
12505 struct listnode *node;
12506 struct bgp_redist *red;
12507
12508 red_list = bgp->redist[afi][i];
12509 if (!red_list)
12510 continue;
12511
12512 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12513 /* "redistribute" configuration. */
12514 vty_out(vty, " redistribute %s",
12515 zebra_route_string(i));
12516 if (red->instance)
12517 vty_out(vty, " %d", red->instance);
12518 if (red->redist_metric_flag)
12519 vty_out(vty, " metric %u",
12520 red->redist_metric);
12521 if (red->rmap.name)
12522 vty_out(vty, " route-map %s",
12523 red->rmap.name);
12524 vty_out(vty, "\n");
12525 }
12526 }
12527 }
12528 }
12529
12530 /* This is part of the address-family block (unicast only) */
12531 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12532 afi_t afi)
12533 {
12534 int indent = 2;
12535
12536 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12537 if (listcount(bgp->vpn_policy[afi].import_vrf))
12538 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12539 bgp->vpn_policy[afi]
12540 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12541 else
12542 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12543 bgp->vpn_policy[afi]
12544 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12545 }
12546 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12547 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12548 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12549 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12550 return;
12551
12552 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12553 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12554
12555 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12556
12557 } else {
12558 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12559 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12560 bgp->vpn_policy[afi].tovpn_label);
12561 }
12562 }
12563 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12564 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12565 char buf[RD_ADDRSTRLEN];
12566 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12567 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12568 sizeof(buf)));
12569 }
12570 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12571 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12572
12573 char buf[PREFIX_STRLEN];
12574 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12575 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12576 sizeof(buf))) {
12577
12578 vty_out(vty, "%*snexthop vpn export %s\n",
12579 indent, "", buf);
12580 }
12581 }
12582 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12583 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12584 && ecommunity_cmp(
12585 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12586 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12587
12588 char *b = ecommunity_ecom2str(
12589 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12590 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12591 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12592 XFREE(MTYPE_ECOMMUNITY_STR, b);
12593 } else {
12594 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12595 char *b = ecommunity_ecom2str(
12596 bgp->vpn_policy[afi]
12597 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12598 ECOMMUNITY_FORMAT_ROUTE_MAP,
12599 ECOMMUNITY_ROUTE_TARGET);
12600 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12601 XFREE(MTYPE_ECOMMUNITY_STR, b);
12602 }
12603 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12604 char *b = ecommunity_ecom2str(
12605 bgp->vpn_policy[afi]
12606 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12607 ECOMMUNITY_FORMAT_ROUTE_MAP,
12608 ECOMMUNITY_ROUTE_TARGET);
12609 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12610 XFREE(MTYPE_ECOMMUNITY_STR, b);
12611 }
12612 }
12613
12614 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12615 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12616 bgp->vpn_policy[afi]
12617 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12618
12619 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12620 char *b = ecommunity_ecom2str(
12621 bgp->vpn_policy[afi]
12622 .import_redirect_rtlist,
12623 ECOMMUNITY_FORMAT_ROUTE_MAP,
12624 ECOMMUNITY_ROUTE_TARGET);
12625
12626 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12627 XFREE(MTYPE_ECOMMUNITY_STR, b);
12628 }
12629 }
12630
12631
12632 /* BGP node structure. */
12633 static struct cmd_node bgp_node = {
12634 BGP_NODE, "%s(config-router)# ", 1,
12635 };
12636
12637 static struct cmd_node bgp_ipv4_unicast_node = {
12638 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12639 };
12640
12641 static struct cmd_node bgp_ipv4_multicast_node = {
12642 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12643 };
12644
12645 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12646 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12647 };
12648
12649 static struct cmd_node bgp_ipv6_unicast_node = {
12650 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12651 };
12652
12653 static struct cmd_node bgp_ipv6_multicast_node = {
12654 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12655 };
12656
12657 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12658 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12659 };
12660
12661 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12662 "%s(config-router-af)# ", 1};
12663
12664 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12665 "%s(config-router-af-vpnv6)# ", 1};
12666
12667 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12668 "%s(config-router-evpn)# ", 1};
12669
12670 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12671 "%s(config-router-af-vni)# ", 1};
12672
12673 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12674 "%s(config-router-af)# ", 1};
12675
12676 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12677 "%s(config-router-af-vpnv6)# ", 1};
12678
12679 static void community_list_vty(void);
12680
12681 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12682 {
12683 struct bgp *bgp;
12684 struct peer *peer;
12685 struct listnode *lnbgp, *lnpeer;
12686
12687 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12688 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12689 /* only provide suggestions on the appropriate input
12690 * token type,
12691 * they'll otherwise show up multiple times */
12692 enum cmd_token_type match_type;
12693 char *name = peer->host;
12694
12695 if (peer->conf_if) {
12696 match_type = VARIABLE_TKN;
12697 name = peer->conf_if;
12698 } else if (strchr(peer->host, ':'))
12699 match_type = IPV6_TKN;
12700 else
12701 match_type = IPV4_TKN;
12702
12703 if (token->type != match_type)
12704 continue;
12705
12706 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12707 }
12708 }
12709 }
12710
12711 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12712 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12713 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12714 {.varname = "peer", .completions = bgp_ac_neighbor},
12715 {.completions = NULL}};
12716
12717 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12718 {
12719 struct bgp *bgp;
12720 struct peer_group *group;
12721 struct listnode *lnbgp, *lnpeer;
12722
12723 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12724 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12725 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12726 group->name));
12727 }
12728 }
12729
12730 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12731 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12732 {.completions = NULL} };
12733
12734 void bgp_vty_init(void)
12735 {
12736 cmd_variable_handler_register(bgp_var_neighbor);
12737 cmd_variable_handler_register(bgp_var_peergroup);
12738
12739 /* Install bgp top node. */
12740 install_node(&bgp_node, bgp_config_write);
12741 install_node(&bgp_ipv4_unicast_node, NULL);
12742 install_node(&bgp_ipv4_multicast_node, NULL);
12743 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12744 install_node(&bgp_ipv6_unicast_node, NULL);
12745 install_node(&bgp_ipv6_multicast_node, NULL);
12746 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12747 install_node(&bgp_vpnv4_node, NULL);
12748 install_node(&bgp_vpnv6_node, NULL);
12749 install_node(&bgp_evpn_node, NULL);
12750 install_node(&bgp_evpn_vni_node, NULL);
12751 install_node(&bgp_flowspecv4_node, NULL);
12752 install_node(&bgp_flowspecv6_node, NULL);
12753
12754 /* Install default VTY commands to new nodes. */
12755 install_default(BGP_NODE);
12756 install_default(BGP_IPV4_NODE);
12757 install_default(BGP_IPV4M_NODE);
12758 install_default(BGP_IPV4L_NODE);
12759 install_default(BGP_IPV6_NODE);
12760 install_default(BGP_IPV6M_NODE);
12761 install_default(BGP_IPV6L_NODE);
12762 install_default(BGP_VPNV4_NODE);
12763 install_default(BGP_VPNV6_NODE);
12764 install_default(BGP_FLOWSPECV4_NODE);
12765 install_default(BGP_FLOWSPECV6_NODE);
12766 install_default(BGP_EVPN_NODE);
12767 install_default(BGP_EVPN_VNI_NODE);
12768
12769 /* "bgp multiple-instance" commands. */
12770 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12771 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12772
12773 /* "bgp config-type" commands. */
12774 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12775 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12776
12777 /* "bgp local-mac" hidden commands. */
12778 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12779 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12780
12781 /* bgp route-map delay-timer commands. */
12782 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12783 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12784
12785 /* Dummy commands (Currently not supported) */
12786 install_element(BGP_NODE, &no_synchronization_cmd);
12787 install_element(BGP_NODE, &no_auto_summary_cmd);
12788
12789 /* "router bgp" commands. */
12790 install_element(CONFIG_NODE, &router_bgp_cmd);
12791
12792 /* "no router bgp" commands. */
12793 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12794
12795 /* "bgp router-id" commands. */
12796 install_element(BGP_NODE, &bgp_router_id_cmd);
12797 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12798
12799 /* "bgp cluster-id" commands. */
12800 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12801 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12802
12803 /* "bgp confederation" commands. */
12804 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12805 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12806
12807 /* "bgp confederation peers" commands. */
12808 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12809 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12810
12811 /* bgp max-med command */
12812 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12813 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12814 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12815 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12816 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12817
12818 /* bgp disable-ebgp-connected-nh-check */
12819 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12820 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12821
12822 /* bgp update-delay command */
12823 install_element(BGP_NODE, &bgp_update_delay_cmd);
12824 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12825 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12826
12827 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12828 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12829 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12830 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12831
12832 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12833 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12834
12835 /* "maximum-paths" commands. */
12836 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12837 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12838 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12839 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12840 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12841 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12842 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12843 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12844 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12845 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12846 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12847 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12848 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12849 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12850 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12851
12852 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12853 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12854 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12855 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12856 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12857
12858 /* "timers bgp" commands. */
12859 install_element(BGP_NODE, &bgp_timers_cmd);
12860 install_element(BGP_NODE, &no_bgp_timers_cmd);
12861
12862 /* route-map delay-timer commands - per instance for backwards compat.
12863 */
12864 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12865 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12866
12867 /* "bgp client-to-client reflection" commands */
12868 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12869 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12870
12871 /* "bgp always-compare-med" commands */
12872 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12873 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12874
12875 /* bgp ebgp-requires-policy */
12876 install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
12877 install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
12878
12879 /* "bgp deterministic-med" commands */
12880 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12881 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12882
12883 /* "bgp graceful-restart" commands */
12884 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12885 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12886 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12887 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12888 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12889 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12890
12891 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12892 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12893
12894 /* "bgp graceful-shutdown" commands */
12895 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12896 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12897
12898 /* "bgp fast-external-failover" commands */
12899 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12900 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12901
12902 /* "bgp enforce-first-as" commands */
12903 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12904
12905 /* "bgp bestpath compare-routerid" commands */
12906 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12907 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12908
12909 /* "bgp bestpath as-path ignore" commands */
12910 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12911 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12912
12913 /* "bgp bestpath as-path confed" commands */
12914 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12915 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12916
12917 /* "bgp bestpath as-path multipath-relax" commands */
12918 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12919 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12920
12921 /* "bgp log-neighbor-changes" commands */
12922 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12923 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12924
12925 /* "bgp bestpath med" commands */
12926 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12927 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12928
12929 /* "no bgp default ipv4-unicast" commands. */
12930 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12931 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12932
12933 /* "bgp network import-check" commands. */
12934 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12935 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12936 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12937
12938 /* "bgp default local-preference" commands. */
12939 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12940 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12941
12942 /* bgp default show-hostname */
12943 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12944 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12945
12946 /* "bgp default subgroup-pkt-queue-max" commands. */
12947 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12948 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12949
12950 /* bgp ibgp-allow-policy-mods command */
12951 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12952 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12953
12954 /* "bgp listen limit" commands. */
12955 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12956 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12957
12958 /* "bgp listen range" commands. */
12959 install_element(BGP_NODE, &bgp_listen_range_cmd);
12960 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12961
12962 /* "bgp default shutdown" command */
12963 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12964
12965 /* "neighbor remote-as" commands. */
12966 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12967 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12968 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12969 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12970 install_element(BGP_NODE,
12971 &neighbor_interface_v6only_config_remote_as_cmd);
12972 install_element(BGP_NODE, &no_neighbor_cmd);
12973 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12974
12975 /* "neighbor peer-group" commands. */
12976 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12977 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12978 install_element(BGP_NODE,
12979 &no_neighbor_interface_peer_group_remote_as_cmd);
12980
12981 /* "neighbor local-as" commands. */
12982 install_element(BGP_NODE, &neighbor_local_as_cmd);
12983 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12984 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12985 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12986
12987 /* "neighbor solo" commands. */
12988 install_element(BGP_NODE, &neighbor_solo_cmd);
12989 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12990
12991 /* "neighbor password" commands. */
12992 install_element(BGP_NODE, &neighbor_password_cmd);
12993 install_element(BGP_NODE, &no_neighbor_password_cmd);
12994
12995 /* "neighbor activate" commands. */
12996 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12997 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12998 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12999 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
13000 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
13001 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
13002 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
13003 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
13004 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
13005 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
13006 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
13007 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
13008
13009 /* "no neighbor activate" commands. */
13010 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
13011 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
13012 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
13013 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
13014 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
13015 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
13016 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
13017 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
13018 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
13019 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
13020 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
13021 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
13022
13023 /* "neighbor peer-group" set commands. */
13024 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
13025 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13026 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
13027 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13028 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
13029 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
13030 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
13031 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
13032 install_element(BGP_FLOWSPECV4_NODE,
13033 &neighbor_set_peer_group_hidden_cmd);
13034 install_element(BGP_FLOWSPECV6_NODE,
13035 &neighbor_set_peer_group_hidden_cmd);
13036
13037 /* "no neighbor peer-group unset" commands. */
13038 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
13039 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13040 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13041 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13042 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13043 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13044 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13045 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
13046 install_element(BGP_FLOWSPECV4_NODE,
13047 &no_neighbor_set_peer_group_hidden_cmd);
13048 install_element(BGP_FLOWSPECV6_NODE,
13049 &no_neighbor_set_peer_group_hidden_cmd);
13050
13051 /* "neighbor softreconfiguration inbound" commands.*/
13052 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
13053 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
13054 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
13055 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13056 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
13057 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13058 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
13059 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13060 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
13061 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13062 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
13063 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
13064 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
13065 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
13066 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
13067 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
13068 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
13069 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
13070 install_element(BGP_FLOWSPECV4_NODE,
13071 &neighbor_soft_reconfiguration_cmd);
13072 install_element(BGP_FLOWSPECV4_NODE,
13073 &no_neighbor_soft_reconfiguration_cmd);
13074 install_element(BGP_FLOWSPECV6_NODE,
13075 &neighbor_soft_reconfiguration_cmd);
13076 install_element(BGP_FLOWSPECV6_NODE,
13077 &no_neighbor_soft_reconfiguration_cmd);
13078 install_element(BGP_EVPN_NODE, &neighbor_soft_reconfiguration_cmd);
13079 install_element(BGP_EVPN_NODE, &no_neighbor_soft_reconfiguration_cmd);
13080
13081 /* "neighbor attribute-unchanged" commands. */
13082 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13083 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13084 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13085 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13086 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13087 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13088 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13089 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13090 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13091 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13092 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13093 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13094 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13095 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13096 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13097 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13098 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13099 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13100
13101 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13102 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13103
13104 /* "nexthop-local unchanged" commands */
13105 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13106 install_element(BGP_IPV6_NODE,
13107 &no_neighbor_nexthop_local_unchanged_cmd);
13108
13109 /* "neighbor next-hop-self" commands. */
13110 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13111 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13112 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13113 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13114 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13115 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13116 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13117 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13118 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13119 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13120 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13121 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13122 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13123 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13124 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13125 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13126 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13127 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13128 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13129 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13130
13131 /* "neighbor next-hop-self force" commands. */
13132 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13133 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13134 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13135 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13136 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13137 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13138 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13139 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13140 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13141 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13142 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13143 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13144 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13145 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13146 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13147 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13148 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13149 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13150
13151 /* "neighbor as-override" commands. */
13152 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13153 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13154 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13155 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13156 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13157 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13158 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13159 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13160 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13161 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13162 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13163 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13164 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13165 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13166 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13167 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13168 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13169 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13170
13171 /* "neighbor remove-private-AS" commands. */
13172 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13173 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13174 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13175 install_element(BGP_NODE,
13176 &no_neighbor_remove_private_as_all_hidden_cmd);
13177 install_element(BGP_NODE,
13178 &neighbor_remove_private_as_replace_as_hidden_cmd);
13179 install_element(BGP_NODE,
13180 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13181 install_element(BGP_NODE,
13182 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13183 install_element(
13184 BGP_NODE,
13185 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13186 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13187 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13188 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13189 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13190 install_element(BGP_IPV4_NODE,
13191 &neighbor_remove_private_as_replace_as_cmd);
13192 install_element(BGP_IPV4_NODE,
13193 &no_neighbor_remove_private_as_replace_as_cmd);
13194 install_element(BGP_IPV4_NODE,
13195 &neighbor_remove_private_as_all_replace_as_cmd);
13196 install_element(BGP_IPV4_NODE,
13197 &no_neighbor_remove_private_as_all_replace_as_cmd);
13198 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13199 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13200 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13201 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13202 install_element(BGP_IPV4M_NODE,
13203 &neighbor_remove_private_as_replace_as_cmd);
13204 install_element(BGP_IPV4M_NODE,
13205 &no_neighbor_remove_private_as_replace_as_cmd);
13206 install_element(BGP_IPV4M_NODE,
13207 &neighbor_remove_private_as_all_replace_as_cmd);
13208 install_element(BGP_IPV4M_NODE,
13209 &no_neighbor_remove_private_as_all_replace_as_cmd);
13210 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13211 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13212 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13213 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13214 install_element(BGP_IPV4L_NODE,
13215 &neighbor_remove_private_as_replace_as_cmd);
13216 install_element(BGP_IPV4L_NODE,
13217 &no_neighbor_remove_private_as_replace_as_cmd);
13218 install_element(BGP_IPV4L_NODE,
13219 &neighbor_remove_private_as_all_replace_as_cmd);
13220 install_element(BGP_IPV4L_NODE,
13221 &no_neighbor_remove_private_as_all_replace_as_cmd);
13222 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13223 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13224 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13225 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13226 install_element(BGP_IPV6_NODE,
13227 &neighbor_remove_private_as_replace_as_cmd);
13228 install_element(BGP_IPV6_NODE,
13229 &no_neighbor_remove_private_as_replace_as_cmd);
13230 install_element(BGP_IPV6_NODE,
13231 &neighbor_remove_private_as_all_replace_as_cmd);
13232 install_element(BGP_IPV6_NODE,
13233 &no_neighbor_remove_private_as_all_replace_as_cmd);
13234 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13235 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13236 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13237 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13238 install_element(BGP_IPV6M_NODE,
13239 &neighbor_remove_private_as_replace_as_cmd);
13240 install_element(BGP_IPV6M_NODE,
13241 &no_neighbor_remove_private_as_replace_as_cmd);
13242 install_element(BGP_IPV6M_NODE,
13243 &neighbor_remove_private_as_all_replace_as_cmd);
13244 install_element(BGP_IPV6M_NODE,
13245 &no_neighbor_remove_private_as_all_replace_as_cmd);
13246 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13247 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13248 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13249 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13250 install_element(BGP_IPV6L_NODE,
13251 &neighbor_remove_private_as_replace_as_cmd);
13252 install_element(BGP_IPV6L_NODE,
13253 &no_neighbor_remove_private_as_replace_as_cmd);
13254 install_element(BGP_IPV6L_NODE,
13255 &neighbor_remove_private_as_all_replace_as_cmd);
13256 install_element(BGP_IPV6L_NODE,
13257 &no_neighbor_remove_private_as_all_replace_as_cmd);
13258 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13259 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13260 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13261 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13262 install_element(BGP_VPNV4_NODE,
13263 &neighbor_remove_private_as_replace_as_cmd);
13264 install_element(BGP_VPNV4_NODE,
13265 &no_neighbor_remove_private_as_replace_as_cmd);
13266 install_element(BGP_VPNV4_NODE,
13267 &neighbor_remove_private_as_all_replace_as_cmd);
13268 install_element(BGP_VPNV4_NODE,
13269 &no_neighbor_remove_private_as_all_replace_as_cmd);
13270 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13271 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13272 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13273 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13274 install_element(BGP_VPNV6_NODE,
13275 &neighbor_remove_private_as_replace_as_cmd);
13276 install_element(BGP_VPNV6_NODE,
13277 &no_neighbor_remove_private_as_replace_as_cmd);
13278 install_element(BGP_VPNV6_NODE,
13279 &neighbor_remove_private_as_all_replace_as_cmd);
13280 install_element(BGP_VPNV6_NODE,
13281 &no_neighbor_remove_private_as_all_replace_as_cmd);
13282
13283 /* "neighbor send-community" commands.*/
13284 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13285 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13286 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13287 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13288 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13289 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13290 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13291 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13292 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13293 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13294 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13295 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13296 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13297 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13298 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13299 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13300 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13301 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13302 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13303 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13304 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13305 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13306 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13307 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13308 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13309 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13310 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13311 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13312 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13313 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13314 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13315 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13316 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13317 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13318 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13319 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13320
13321 /* "neighbor route-reflector" commands.*/
13322 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13323 install_element(BGP_NODE,
13324 &no_neighbor_route_reflector_client_hidden_cmd);
13325 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13326 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13327 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13328 install_element(BGP_IPV4M_NODE,
13329 &no_neighbor_route_reflector_client_cmd);
13330 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13331 install_element(BGP_IPV4L_NODE,
13332 &no_neighbor_route_reflector_client_cmd);
13333 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13334 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13335 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13336 install_element(BGP_IPV6M_NODE,
13337 &no_neighbor_route_reflector_client_cmd);
13338 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13339 install_element(BGP_IPV6L_NODE,
13340 &no_neighbor_route_reflector_client_cmd);
13341 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13342 install_element(BGP_VPNV4_NODE,
13343 &no_neighbor_route_reflector_client_cmd);
13344 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13345 install_element(BGP_VPNV6_NODE,
13346 &no_neighbor_route_reflector_client_cmd);
13347 install_element(BGP_FLOWSPECV4_NODE,
13348 &neighbor_route_reflector_client_cmd);
13349 install_element(BGP_FLOWSPECV4_NODE,
13350 &no_neighbor_route_reflector_client_cmd);
13351 install_element(BGP_FLOWSPECV6_NODE,
13352 &neighbor_route_reflector_client_cmd);
13353 install_element(BGP_FLOWSPECV6_NODE,
13354 &no_neighbor_route_reflector_client_cmd);
13355 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13356 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13357
13358 /* "neighbor route-server" commands.*/
13359 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13360 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13361 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13362 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13363 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13364 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13365 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13366 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13367 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13368 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13369 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13370 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13371 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13372 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13373 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13374 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13375 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13376 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13377 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13378 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13379 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13380 install_element(BGP_FLOWSPECV4_NODE,
13381 &no_neighbor_route_server_client_cmd);
13382 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13383 install_element(BGP_FLOWSPECV6_NODE,
13384 &no_neighbor_route_server_client_cmd);
13385
13386 /* "neighbor addpath-tx-all-paths" commands.*/
13387 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13388 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13389 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13390 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13391 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13392 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13393 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13394 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13395 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13396 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13397 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13398 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13399 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13400 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13401 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13402 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13403 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13404 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13405
13406 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13407 install_element(BGP_NODE,
13408 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13409 install_element(BGP_NODE,
13410 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13411 install_element(BGP_IPV4_NODE,
13412 &neighbor_addpath_tx_bestpath_per_as_cmd);
13413 install_element(BGP_IPV4_NODE,
13414 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13415 install_element(BGP_IPV4M_NODE,
13416 &neighbor_addpath_tx_bestpath_per_as_cmd);
13417 install_element(BGP_IPV4M_NODE,
13418 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13419 install_element(BGP_IPV4L_NODE,
13420 &neighbor_addpath_tx_bestpath_per_as_cmd);
13421 install_element(BGP_IPV4L_NODE,
13422 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13423 install_element(BGP_IPV6_NODE,
13424 &neighbor_addpath_tx_bestpath_per_as_cmd);
13425 install_element(BGP_IPV6_NODE,
13426 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13427 install_element(BGP_IPV6M_NODE,
13428 &neighbor_addpath_tx_bestpath_per_as_cmd);
13429 install_element(BGP_IPV6M_NODE,
13430 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13431 install_element(BGP_IPV6L_NODE,
13432 &neighbor_addpath_tx_bestpath_per_as_cmd);
13433 install_element(BGP_IPV6L_NODE,
13434 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13435 install_element(BGP_VPNV4_NODE,
13436 &neighbor_addpath_tx_bestpath_per_as_cmd);
13437 install_element(BGP_VPNV4_NODE,
13438 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13439 install_element(BGP_VPNV6_NODE,
13440 &neighbor_addpath_tx_bestpath_per_as_cmd);
13441 install_element(BGP_VPNV6_NODE,
13442 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13443
13444 /* "neighbor passive" commands. */
13445 install_element(BGP_NODE, &neighbor_passive_cmd);
13446 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13447
13448
13449 /* "neighbor shutdown" commands. */
13450 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13451 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13452 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13453 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13454
13455 /* "neighbor capability extended-nexthop" commands.*/
13456 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13457 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13458
13459 /* "neighbor capability orf prefix-list" commands.*/
13460 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13461 install_element(BGP_NODE,
13462 &no_neighbor_capability_orf_prefix_hidden_cmd);
13463 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13464 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13465 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13466 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13467 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13468 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13469 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13470 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13471 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13472 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13473 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13474 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13475
13476 /* "neighbor capability dynamic" commands.*/
13477 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13478 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13479
13480 /* "neighbor dont-capability-negotiate" commands. */
13481 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13482 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13483
13484 /* "neighbor ebgp-multihop" commands. */
13485 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13486 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13487 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13488
13489 /* "neighbor disable-connected-check" commands. */
13490 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13491 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13492
13493 /* "neighbor enforce-first-as" commands. */
13494 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13495 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13496
13497 /* "neighbor description" commands. */
13498 install_element(BGP_NODE, &neighbor_description_cmd);
13499 install_element(BGP_NODE, &no_neighbor_description_cmd);
13500 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13501
13502 /* "neighbor update-source" commands. "*/
13503 install_element(BGP_NODE, &neighbor_update_source_cmd);
13504 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13505
13506 /* "neighbor default-originate" commands. */
13507 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13508 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13509 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13510 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13511 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13512 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13513 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13514 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13515 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13516 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13517 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13518 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13519 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13520 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13521 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13522 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13523 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13524 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13525 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13526 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13527 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13528
13529 /* "neighbor port" commands. */
13530 install_element(BGP_NODE, &neighbor_port_cmd);
13531 install_element(BGP_NODE, &no_neighbor_port_cmd);
13532
13533 /* "neighbor weight" commands. */
13534 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13535 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13536
13537 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13538 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13539 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13540 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13541 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13542 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13543 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13544 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13545 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13546 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13547 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13548 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13549 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13550 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13551 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13552 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13553
13554 /* "neighbor override-capability" commands. */
13555 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13556 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13557
13558 /* "neighbor strict-capability-match" commands. */
13559 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13560 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13561
13562 /* "neighbor timers" commands. */
13563 install_element(BGP_NODE, &neighbor_timers_cmd);
13564 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13565
13566 /* "neighbor timers connect" commands. */
13567 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13568 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13569
13570 /* "neighbor advertisement-interval" commands. */
13571 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13572 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13573
13574 /* "neighbor interface" commands. */
13575 install_element(BGP_NODE, &neighbor_interface_cmd);
13576 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13577
13578 /* "neighbor distribute" commands. */
13579 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13580 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13581 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13582 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13583 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13584 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13585 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13586 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13587 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13588 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13589 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13590 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13591 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13592 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13593 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13594 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13595 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13596 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13597
13598 /* "neighbor prefix-list" commands. */
13599 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13600 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13601 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13602 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13603 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13604 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13605 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13606 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13607 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13608 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13609 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13610 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13611 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13612 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13613 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13614 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13615 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13616 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13617 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13618 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13619 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13620 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13621
13622 /* "neighbor filter-list" commands. */
13623 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13624 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13625 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13626 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13627 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13628 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13629 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13630 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13631 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13632 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13633 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13634 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13635 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13636 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13637 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13638 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13639 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13640 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13641 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13642 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13643 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13644 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13645
13646 /* "neighbor route-map" commands. */
13647 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13648 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13649 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13650 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13651 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13652 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13653 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13654 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13655 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13656 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13657 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13658 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13659 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13660 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13661 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13662 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13663 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13664 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13665 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13666 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13667 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13668 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13669 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13670 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13671
13672 /* "neighbor unsuppress-map" commands. */
13673 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13674 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13675 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13676 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13677 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13678 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13679 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13680 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13681 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13682 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13683 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13684 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13685 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13686 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13687 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13688 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13689 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13690 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13691
13692 /* "neighbor maximum-prefix" commands. */
13693 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13694 install_element(BGP_NODE,
13695 &neighbor_maximum_prefix_threshold_hidden_cmd);
13696 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13697 install_element(BGP_NODE,
13698 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13699 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13700 install_element(BGP_NODE,
13701 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13702 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13703 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13704 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13705 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13706 install_element(BGP_IPV4_NODE,
13707 &neighbor_maximum_prefix_threshold_warning_cmd);
13708 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13709 install_element(BGP_IPV4_NODE,
13710 &neighbor_maximum_prefix_threshold_restart_cmd);
13711 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13712 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13713 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13714 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13715 install_element(BGP_IPV4M_NODE,
13716 &neighbor_maximum_prefix_threshold_warning_cmd);
13717 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13718 install_element(BGP_IPV4M_NODE,
13719 &neighbor_maximum_prefix_threshold_restart_cmd);
13720 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13721 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13722 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13723 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13724 install_element(BGP_IPV4L_NODE,
13725 &neighbor_maximum_prefix_threshold_warning_cmd);
13726 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13727 install_element(BGP_IPV4L_NODE,
13728 &neighbor_maximum_prefix_threshold_restart_cmd);
13729 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13730 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13731 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13732 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13733 install_element(BGP_IPV6_NODE,
13734 &neighbor_maximum_prefix_threshold_warning_cmd);
13735 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13736 install_element(BGP_IPV6_NODE,
13737 &neighbor_maximum_prefix_threshold_restart_cmd);
13738 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13739 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13740 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13741 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13742 install_element(BGP_IPV6M_NODE,
13743 &neighbor_maximum_prefix_threshold_warning_cmd);
13744 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13745 install_element(BGP_IPV6M_NODE,
13746 &neighbor_maximum_prefix_threshold_restart_cmd);
13747 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13748 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13749 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13750 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13751 install_element(BGP_IPV6L_NODE,
13752 &neighbor_maximum_prefix_threshold_warning_cmd);
13753 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13754 install_element(BGP_IPV6L_NODE,
13755 &neighbor_maximum_prefix_threshold_restart_cmd);
13756 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13757 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13758 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13759 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13760 install_element(BGP_VPNV4_NODE,
13761 &neighbor_maximum_prefix_threshold_warning_cmd);
13762 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13763 install_element(BGP_VPNV4_NODE,
13764 &neighbor_maximum_prefix_threshold_restart_cmd);
13765 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13766 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13767 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13768 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13769 install_element(BGP_VPNV6_NODE,
13770 &neighbor_maximum_prefix_threshold_warning_cmd);
13771 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13772 install_element(BGP_VPNV6_NODE,
13773 &neighbor_maximum_prefix_threshold_restart_cmd);
13774 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13775
13776 /* "neighbor allowas-in" */
13777 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13778 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13779 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13780 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13781 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13782 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13783 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13784 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13785 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13786 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13787 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13788 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13789 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13790 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13791 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13792 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13793 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13794 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13795 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13796 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13797
13798 /* address-family commands. */
13799 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13800 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13801 #ifdef KEEP_OLD_VPN_COMMANDS
13802 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13803 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13804 #endif /* KEEP_OLD_VPN_COMMANDS */
13805
13806 install_element(BGP_NODE, &address_family_evpn_cmd);
13807
13808 /* "exit-address-family" command. */
13809 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13810 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13811 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13812 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13813 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13814 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13815 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13816 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13817 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13818 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13819 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13820
13821 /* "clear ip bgp commands" */
13822 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13823
13824 /* clear ip bgp prefix */
13825 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13826 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13827 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13828
13829 /* "show [ip] bgp summary" commands. */
13830 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13831 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13832 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13833 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13834 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13835 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13836 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13837
13838 /* "show [ip] bgp neighbors" commands. */
13839 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13840
13841 /* "show [ip] bgp peer-group" commands. */
13842 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13843
13844 /* "show [ip] bgp paths" commands. */
13845 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13846
13847 /* "show [ip] bgp community" commands. */
13848 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13849
13850 /* "show ip bgp large-community" commands. */
13851 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13852 /* "show [ip] bgp attribute-info" commands. */
13853 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13854 /* "show [ip] bgp route-leak" command */
13855 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13856
13857 /* "redistribute" commands. */
13858 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13859 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13860 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13861 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13862 install_element(BGP_NODE,
13863 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13864 install_element(BGP_NODE,
13865 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13866 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13867 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13868 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13869 install_element(BGP_NODE,
13870 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13871 install_element(BGP_NODE,
13872 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13873 install_element(BGP_NODE,
13874 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13875 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13876 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13877 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13878 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13879 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13880 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13881 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13882 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13883 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13884 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13885 install_element(BGP_IPV4_NODE,
13886 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13887 install_element(BGP_IPV4_NODE,
13888 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13889 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13890 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13891 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13892 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13893 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13894 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13895
13896 /* import|export vpn [route-map WORD] */
13897 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13898 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13899
13900 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13901 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13902
13903 /* ttl_security commands */
13904 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13905 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13906
13907 /* "show [ip] bgp memory" commands. */
13908 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13909
13910 /* "show bgp martian next-hop" */
13911 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13912
13913 install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
13914
13915 /* "show [ip] bgp views" commands. */
13916 install_element(VIEW_NODE, &show_bgp_views_cmd);
13917
13918 /* "show [ip] bgp vrfs" commands. */
13919 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13920
13921 /* Community-list. */
13922 community_list_vty();
13923
13924 /* vpn-policy commands */
13925 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13926 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13927 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13928 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13929 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13930 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13931 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13932 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13933 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13934 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13935 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13936 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13937
13938 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13939 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13940
13941 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13942 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13943 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13944 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13945 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13946 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13947 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13948 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13949 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13950 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13951 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13952 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13953 }
13954
13955 #include "memory.h"
13956 #include "bgp_regex.h"
13957 #include "bgp_clist.h"
13958 #include "bgp_ecommunity.h"
13959
13960 /* VTY functions. */
13961
13962 /* Direction value to string conversion. */
13963 static const char *community_direct_str(int direct)
13964 {
13965 switch (direct) {
13966 case COMMUNITY_DENY:
13967 return "deny";
13968 case COMMUNITY_PERMIT:
13969 return "permit";
13970 default:
13971 return "unknown";
13972 }
13973 }
13974
13975 /* Display error string. */
13976 static void community_list_perror(struct vty *vty, int ret)
13977 {
13978 switch (ret) {
13979 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13980 vty_out(vty, "%% Can't find community-list\n");
13981 break;
13982 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13983 vty_out(vty, "%% Malformed community-list value\n");
13984 break;
13985 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13986 vty_out(vty,
13987 "%% Community name conflict, previously defined as standard community\n");
13988 break;
13989 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13990 vty_out(vty,
13991 "%% Community name conflict, previously defined as expanded community\n");
13992 break;
13993 }
13994 }
13995
13996 /* "community-list" keyword help string. */
13997 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13998
13999 /*community-list standard */
14000 DEFUN (community_list_standard,
14001 bgp_community_list_standard_cmd,
14002 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14003 BGP_STR
14004 COMMUNITY_LIST_STR
14005 "Community list number (standard)\n"
14006 "Add an standard community-list entry\n"
14007 "Community list name\n"
14008 "Specify community to reject\n"
14009 "Specify community to accept\n"
14010 COMMUNITY_VAL_STR)
14011 {
14012 char *cl_name_or_number = NULL;
14013 int direct = 0;
14014 int style = COMMUNITY_LIST_STANDARD;
14015
14016 int idx = 0;
14017
14018 if (argv_find(argv, argc, "ip", &idx)) {
14019 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14020 vty_out(vty, "if you are using this please migrate to the below command.\n");
14021 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14022 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14023 }
14024
14025 argv_find(argv, argc, "(1-99)", &idx);
14026 argv_find(argv, argc, "WORD", &idx);
14027 cl_name_or_number = argv[idx]->arg;
14028 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14029 : COMMUNITY_DENY;
14030 argv_find(argv, argc, "AA:NN", &idx);
14031 char *str = argv_concat(argv, argc, idx);
14032
14033 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14034 style);
14035
14036 XFREE(MTYPE_TMP, str);
14037
14038 if (ret < 0) {
14039 /* Display error string. */
14040 community_list_perror(vty, ret);
14041 return CMD_WARNING_CONFIG_FAILED;
14042 }
14043
14044 return CMD_SUCCESS;
14045 }
14046
14047 #if CONFDATE > 20191005
14048 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
14049 #endif
14050 ALIAS (community_list_standard,
14051 ip_community_list_standard_cmd,
14052 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14053 IP_STR
14054 COMMUNITY_LIST_STR
14055 "Community list number (standard)\n"
14056 "Add an standard community-list entry\n"
14057 "Community list name\n"
14058 "Specify community to reject\n"
14059 "Specify community to accept\n"
14060 COMMUNITY_VAL_STR)
14061
14062 DEFUN (no_community_list_standard_all,
14063 no_bgp_community_list_standard_all_cmd,
14064 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14065 NO_STR
14066 BGP_STR
14067 COMMUNITY_LIST_STR
14068 "Community list number (standard)\n"
14069 "Add an standard community-list entry\n"
14070 "Community list name\n"
14071 "Specify community to reject\n"
14072 "Specify community to accept\n"
14073 COMMUNITY_VAL_STR)
14074 {
14075 char *cl_name_or_number = NULL;
14076 char *str = NULL;
14077 int direct = 0;
14078 int style = COMMUNITY_LIST_STANDARD;
14079
14080 int idx = 0;
14081
14082 if (argv_find(argv, argc, "ip", &idx)) {
14083 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14084 vty_out(vty, "if you are using this please migrate to the below command.\n");
14085 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14086 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14087 }
14088
14089 argv_find(argv, argc, "permit", &idx);
14090 argv_find(argv, argc, "deny", &idx);
14091
14092 if (idx) {
14093 direct = argv_find(argv, argc, "permit", &idx)
14094 ? COMMUNITY_PERMIT
14095 : COMMUNITY_DENY;
14096
14097 idx = 0;
14098 argv_find(argv, argc, "AA:NN", &idx);
14099 str = argv_concat(argv, argc, idx);
14100 }
14101
14102 idx = 0;
14103 argv_find(argv, argc, "(1-99)", &idx);
14104 argv_find(argv, argc, "WORD", &idx);
14105 cl_name_or_number = argv[idx]->arg;
14106
14107 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14108 direct, style);
14109
14110 XFREE(MTYPE_TMP, str);
14111
14112 if (ret < 0) {
14113 community_list_perror(vty, ret);
14114 return CMD_WARNING_CONFIG_FAILED;
14115 }
14116
14117 return CMD_SUCCESS;
14118 }
14119 ALIAS (no_community_list_standard_all,
14120 no_ip_community_list_standard_all_cmd,
14121 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14122 NO_STR
14123 IP_STR
14124 COMMUNITY_LIST_STR
14125 "Community list number (standard)\n"
14126 "Add an standard community-list entry\n"
14127 "Community list name\n"
14128 "Specify community to reject\n"
14129 "Specify community to accept\n"
14130 COMMUNITY_VAL_STR)
14131
14132 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14133 "no bgp community-list <(1-99)|standard WORD>",
14134 NO_STR BGP_STR COMMUNITY_LIST_STR
14135 "Community list number (standard)\n"
14136 "Add an standard community-list entry\n"
14137 "Community list name\n")
14138
14139 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14140 "no ip community-list <(1-99)|standard WORD>",
14141 NO_STR BGP_STR COMMUNITY_LIST_STR
14142 "Community list number (standard)\n"
14143 "Add an standard community-list entry\n"
14144 "Community list name\n")
14145
14146 /*community-list expanded */
14147 DEFUN (community_list_expanded_all,
14148 bgp_community_list_expanded_all_cmd,
14149 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14150 BGP_STR
14151 COMMUNITY_LIST_STR
14152 "Community list number (expanded)\n"
14153 "Add an expanded community-list entry\n"
14154 "Community list name\n"
14155 "Specify community to reject\n"
14156 "Specify community to accept\n"
14157 COMMUNITY_VAL_STR)
14158 {
14159 char *cl_name_or_number = NULL;
14160 int direct = 0;
14161 int style = COMMUNITY_LIST_EXPANDED;
14162
14163 int idx = 0;
14164 if (argv_find(argv, argc, "ip", &idx)) {
14165 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14166 vty_out(vty, "if you are using this please migrate to the below command.\n");
14167 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14168 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14169 }
14170 argv_find(argv, argc, "(100-500)", &idx);
14171 argv_find(argv, argc, "WORD", &idx);
14172 cl_name_or_number = argv[idx]->arg;
14173 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14174 : COMMUNITY_DENY;
14175 argv_find(argv, argc, "AA:NN", &idx);
14176 char *str = argv_concat(argv, argc, idx);
14177
14178 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14179 style);
14180
14181 XFREE(MTYPE_TMP, str);
14182
14183 if (ret < 0) {
14184 /* Display error string. */
14185 community_list_perror(vty, ret);
14186 return CMD_WARNING_CONFIG_FAILED;
14187 }
14188
14189 return CMD_SUCCESS;
14190 }
14191
14192 ALIAS (community_list_expanded_all,
14193 ip_community_list_expanded_all_cmd,
14194 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14195 IP_STR
14196 COMMUNITY_LIST_STR
14197 "Community list number (expanded)\n"
14198 "Add an expanded community-list entry\n"
14199 "Community list name\n"
14200 "Specify community to reject\n"
14201 "Specify community to accept\n"
14202 COMMUNITY_VAL_STR)
14203
14204 DEFUN (no_community_list_expanded_all,
14205 no_bgp_community_list_expanded_all_cmd,
14206 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14207 NO_STR
14208 BGP_STR
14209 COMMUNITY_LIST_STR
14210 "Community list number (expanded)\n"
14211 "Add an expanded community-list entry\n"
14212 "Community list name\n"
14213 "Specify community to reject\n"
14214 "Specify community to accept\n"
14215 COMMUNITY_VAL_STR)
14216 {
14217 char *cl_name_or_number = NULL;
14218 char *str = NULL;
14219 int direct = 0;
14220 int style = COMMUNITY_LIST_EXPANDED;
14221
14222 int idx = 0;
14223 if (argv_find(argv, argc, "ip", &idx)) {
14224 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14225 vty_out(vty, "if you are using this please migrate to the below command.\n");
14226 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14227 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14228 }
14229
14230 idx = 0;
14231 argv_find(argv, argc, "permit", &idx);
14232 argv_find(argv, argc, "deny", &idx);
14233
14234 if (idx) {
14235 direct = argv_find(argv, argc, "permit", &idx)
14236 ? COMMUNITY_PERMIT
14237 : COMMUNITY_DENY;
14238
14239 idx = 0;
14240 argv_find(argv, argc, "AA:NN", &idx);
14241 str = argv_concat(argv, argc, idx);
14242 }
14243
14244 idx = 0;
14245 argv_find(argv, argc, "(100-500)", &idx);
14246 argv_find(argv, argc, "WORD", &idx);
14247 cl_name_or_number = argv[idx]->arg;
14248
14249 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14250 direct, style);
14251
14252 XFREE(MTYPE_TMP, str);
14253
14254 if (ret < 0) {
14255 community_list_perror(vty, ret);
14256 return CMD_WARNING_CONFIG_FAILED;
14257 }
14258
14259 return CMD_SUCCESS;
14260 }
14261
14262 ALIAS (no_community_list_expanded_all,
14263 no_ip_community_list_expanded_all_cmd,
14264 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14265 NO_STR
14266 IP_STR
14267 COMMUNITY_LIST_STR
14268 "Community list number (expanded)\n"
14269 "Add an expanded community-list entry\n"
14270 "Community list name\n"
14271 "Specify community to reject\n"
14272 "Specify community to accept\n"
14273 COMMUNITY_VAL_STR)
14274
14275 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14276 "no bgp community-list <(100-500)|expanded WORD>",
14277 NO_STR IP_STR COMMUNITY_LIST_STR
14278 "Community list number (expanded)\n"
14279 "Add an expanded community-list entry\n"
14280 "Community list name\n")
14281
14282 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14283 "no ip community-list <(100-500)|expanded WORD>",
14284 NO_STR IP_STR COMMUNITY_LIST_STR
14285 "Community list number (expanded)\n"
14286 "Add an expanded community-list entry\n"
14287 "Community list name\n")
14288
14289 /* Return configuration string of community-list entry. */
14290 static const char *community_list_config_str(struct community_entry *entry)
14291 {
14292 const char *str;
14293
14294 if (entry->any)
14295 str = "";
14296 else {
14297 if (entry->style == COMMUNITY_LIST_STANDARD)
14298 str = community_str(entry->u.com, false);
14299 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14300 str = lcommunity_str(entry->u.lcom, false);
14301 else
14302 str = entry->config;
14303 }
14304 return str;
14305 }
14306
14307 static void community_list_show(struct vty *vty, struct community_list *list)
14308 {
14309 struct community_entry *entry;
14310
14311 for (entry = list->head; entry; entry = entry->next) {
14312 if (entry == list->head) {
14313 if (all_digit(list->name))
14314 vty_out(vty, "Community %s list %s\n",
14315 entry->style == COMMUNITY_LIST_STANDARD
14316 ? "standard"
14317 : "(expanded) access",
14318 list->name);
14319 else
14320 vty_out(vty, "Named Community %s list %s\n",
14321 entry->style == COMMUNITY_LIST_STANDARD
14322 ? "standard"
14323 : "expanded",
14324 list->name);
14325 }
14326 if (entry->any)
14327 vty_out(vty, " %s\n",
14328 community_direct_str(entry->direct));
14329 else
14330 vty_out(vty, " %s %s\n",
14331 community_direct_str(entry->direct),
14332 community_list_config_str(entry));
14333 }
14334 }
14335
14336 DEFUN (show_community_list,
14337 show_bgp_community_list_cmd,
14338 "show bgp community-list",
14339 SHOW_STR
14340 BGP_STR
14341 "List community-list\n")
14342 {
14343 struct community_list *list;
14344 struct community_list_master *cm;
14345
14346 int idx = 0;
14347 if (argv_find(argv, argc, "ip", &idx)) {
14348 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14349 vty_out(vty, "if you are using this please migrate to the below command.\n");
14350 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14351 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14352 }
14353 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14354 if (!cm)
14355 return CMD_SUCCESS;
14356
14357 for (list = cm->num.head; list; list = list->next)
14358 community_list_show(vty, list);
14359
14360 for (list = cm->str.head; list; list = list->next)
14361 community_list_show(vty, list);
14362
14363 return CMD_SUCCESS;
14364 }
14365
14366 ALIAS (show_community_list,
14367 show_ip_community_list_cmd,
14368 "show ip community-list",
14369 SHOW_STR
14370 IP_STR
14371 "List community-list\n")
14372
14373 DEFUN (show_community_list_arg,
14374 show_bgp_community_list_arg_cmd,
14375 "show bgp community-list <(1-500)|WORD>",
14376 SHOW_STR
14377 BGP_STR
14378 "List community-list\n"
14379 "Community-list number\n"
14380 "Community-list name\n")
14381 {
14382 int idx_comm_list = 3;
14383 struct community_list *list;
14384
14385 int idx = 0;
14386 if (argv_find(argv, argc, "ip", &idx)) {
14387 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14388 vty_out(vty, "if you are using this please migrate to the below command.\n");
14389 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14390 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14391 }
14392 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
14393 COMMUNITY_LIST_MASTER);
14394 if (!list) {
14395 vty_out(vty, "%% Can't find community-list\n");
14396 return CMD_WARNING;
14397 }
14398
14399 community_list_show(vty, list);
14400
14401 return CMD_SUCCESS;
14402 }
14403
14404 ALIAS (show_community_list_arg,
14405 show_ip_community_list_arg_cmd,
14406 "show ip community-list <(1-500)|WORD>",
14407 SHOW_STR
14408 IP_STR
14409 "List community-list\n"
14410 "Community-list number\n"
14411 "Community-list name\n")
14412
14413 /*
14414 * Large Community code.
14415 */
14416 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14417 struct cmd_token **argv, int style,
14418 int reject_all_digit_name)
14419 {
14420 int ret;
14421 int direct;
14422 char *str;
14423 int idx = 0;
14424 char *cl_name;
14425
14426 if (argv_find(argv, argc, "ip", &idx)) {
14427 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14428 vty_out(vty, "if you are using this please migrate to the below command.\n");
14429 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14430 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14431 }
14432 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14433 : COMMUNITY_DENY;
14434
14435 /* All digit name check. */
14436 idx = 0;
14437 argv_find(argv, argc, "WORD", &idx);
14438 argv_find(argv, argc, "(1-99)", &idx);
14439 argv_find(argv, argc, "(100-500)", &idx);
14440 cl_name = argv[idx]->arg;
14441 if (reject_all_digit_name && all_digit(cl_name)) {
14442 vty_out(vty, "%% Community name cannot have all digits\n");
14443 return CMD_WARNING_CONFIG_FAILED;
14444 }
14445
14446 idx = 0;
14447 argv_find(argv, argc, "AA:BB:CC", &idx);
14448 argv_find(argv, argc, "LINE", &idx);
14449 /* Concat community string argument. */
14450 if (idx)
14451 str = argv_concat(argv, argc, idx);
14452 else
14453 str = NULL;
14454
14455 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14456
14457 /* Free temporary community list string allocated by
14458 argv_concat(). */
14459 if (str)
14460 XFREE(MTYPE_TMP, str);
14461
14462 if (ret < 0) {
14463 community_list_perror(vty, ret);
14464 return CMD_WARNING_CONFIG_FAILED;
14465 }
14466 return CMD_SUCCESS;
14467 }
14468
14469 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14470 struct cmd_token **argv, int style)
14471 {
14472 int ret;
14473 int direct = 0;
14474 char *str = NULL;
14475 int idx = 0;
14476
14477 if (argv_find(argv, argc, "ip", &idx)) {
14478 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14479 vty_out(vty, "if you are using this please migrate to the below command.\n");
14480 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14481 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14482 }
14483 argv_find(argv, argc, "permit", &idx);
14484 argv_find(argv, argc, "deny", &idx);
14485
14486 if (idx) {
14487 /* Check the list direct. */
14488 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14489 direct = COMMUNITY_PERMIT;
14490 else
14491 direct = COMMUNITY_DENY;
14492
14493 idx = 0;
14494 argv_find(argv, argc, "LINE", &idx);
14495 argv_find(argv, argc, "AA:AA:NN", &idx);
14496 /* Concat community string argument. */
14497 str = argv_concat(argv, argc, idx);
14498 }
14499
14500 idx = 0;
14501 argv_find(argv, argc, "(1-99)", &idx);
14502 argv_find(argv, argc, "(100-500)", &idx);
14503 argv_find(argv, argc, "WORD", &idx);
14504
14505 /* Unset community list. */
14506 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14507 style);
14508
14509 /* Free temporary community list string allocated by
14510 argv_concat(). */
14511 if (str)
14512 XFREE(MTYPE_TMP, str);
14513
14514 if (ret < 0) {
14515 community_list_perror(vty, ret);
14516 return CMD_WARNING_CONFIG_FAILED;
14517 }
14518
14519 return CMD_SUCCESS;
14520 }
14521
14522 /* "large-community-list" keyword help string. */
14523 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14524 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14525
14526 #if CONFDATE > 20191005
14527 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14528 #endif
14529 DEFUN (lcommunity_list_standard,
14530 bgp_lcommunity_list_standard_cmd,
14531 "bgp large-community-list (1-99) <deny|permit>",
14532 BGP_STR
14533 LCOMMUNITY_LIST_STR
14534 "Large Community list number (standard)\n"
14535 "Specify large community to reject\n"
14536 "Specify large community to accept\n")
14537 {
14538 return lcommunity_list_set_vty(vty, argc, argv,
14539 LARGE_COMMUNITY_LIST_STANDARD, 0);
14540 }
14541
14542 ALIAS (lcommunity_list_standard,
14543 ip_lcommunity_list_standard_cmd,
14544 "ip large-community-list (1-99) <deny|permit>",
14545 IP_STR
14546 LCOMMUNITY_LIST_STR
14547 "Large Community list number (standard)\n"
14548 "Specify large community to reject\n"
14549 "Specify large community to accept\n")
14550
14551 DEFUN (lcommunity_list_standard1,
14552 bgp_lcommunity_list_standard1_cmd,
14553 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14554 BGP_STR
14555 LCOMMUNITY_LIST_STR
14556 "Large Community list number (standard)\n"
14557 "Specify large community to reject\n"
14558 "Specify large community to accept\n"
14559 LCOMMUNITY_VAL_STR)
14560 {
14561 return lcommunity_list_set_vty(vty, argc, argv,
14562 LARGE_COMMUNITY_LIST_STANDARD, 0);
14563 }
14564
14565 ALIAS (lcommunity_list_standard1,
14566 ip_lcommunity_list_standard1_cmd,
14567 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14568 IP_STR
14569 LCOMMUNITY_LIST_STR
14570 "Large Community list number (standard)\n"
14571 "Specify large community to reject\n"
14572 "Specify large community to accept\n"
14573 LCOMMUNITY_VAL_STR)
14574
14575 DEFUN (lcommunity_list_expanded,
14576 bgp_lcommunity_list_expanded_cmd,
14577 "bgp large-community-list (100-500) <deny|permit> LINE...",
14578 BGP_STR
14579 LCOMMUNITY_LIST_STR
14580 "Large Community list number (expanded)\n"
14581 "Specify large community to reject\n"
14582 "Specify large community to accept\n"
14583 "An ordered list as a regular-expression\n")
14584 {
14585 return lcommunity_list_set_vty(vty, argc, argv,
14586 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14587 }
14588
14589 ALIAS (lcommunity_list_expanded,
14590 ip_lcommunity_list_expanded_cmd,
14591 "ip large-community-list (100-500) <deny|permit> LINE...",
14592 IP_STR
14593 LCOMMUNITY_LIST_STR
14594 "Large Community list number (expanded)\n"
14595 "Specify large community to reject\n"
14596 "Specify large community to accept\n"
14597 "An ordered list as a regular-expression\n")
14598
14599 DEFUN (lcommunity_list_name_standard,
14600 bgp_lcommunity_list_name_standard_cmd,
14601 "bgp large-community-list standard WORD <deny|permit>",
14602 BGP_STR
14603 LCOMMUNITY_LIST_STR
14604 "Specify standard large-community-list\n"
14605 "Large Community list name\n"
14606 "Specify large community to reject\n"
14607 "Specify large community to accept\n")
14608 {
14609 return lcommunity_list_set_vty(vty, argc, argv,
14610 LARGE_COMMUNITY_LIST_STANDARD, 1);
14611 }
14612
14613 ALIAS (lcommunity_list_name_standard,
14614 ip_lcommunity_list_name_standard_cmd,
14615 "ip large-community-list standard WORD <deny|permit>",
14616 IP_STR
14617 LCOMMUNITY_LIST_STR
14618 "Specify standard large-community-list\n"
14619 "Large Community list name\n"
14620 "Specify large community to reject\n"
14621 "Specify large community to accept\n")
14622
14623 DEFUN (lcommunity_list_name_standard1,
14624 bgp_lcommunity_list_name_standard1_cmd,
14625 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14626 BGP_STR
14627 LCOMMUNITY_LIST_STR
14628 "Specify standard large-community-list\n"
14629 "Large Community list name\n"
14630 "Specify large community to reject\n"
14631 "Specify large community to accept\n"
14632 LCOMMUNITY_VAL_STR)
14633 {
14634 return lcommunity_list_set_vty(vty, argc, argv,
14635 LARGE_COMMUNITY_LIST_STANDARD, 1);
14636 }
14637
14638 ALIAS (lcommunity_list_name_standard1,
14639 ip_lcommunity_list_name_standard1_cmd,
14640 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14641 IP_STR
14642 LCOMMUNITY_LIST_STR
14643 "Specify standard large-community-list\n"
14644 "Large Community list name\n"
14645 "Specify large community to reject\n"
14646 "Specify large community to accept\n"
14647 LCOMMUNITY_VAL_STR)
14648
14649 DEFUN (lcommunity_list_name_expanded,
14650 bgp_lcommunity_list_name_expanded_cmd,
14651 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14652 BGP_STR
14653 LCOMMUNITY_LIST_STR
14654 "Specify expanded large-community-list\n"
14655 "Large Community list name\n"
14656 "Specify large community to reject\n"
14657 "Specify large community to accept\n"
14658 "An ordered list as a regular-expression\n")
14659 {
14660 return lcommunity_list_set_vty(vty, argc, argv,
14661 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14662 }
14663
14664 ALIAS (lcommunity_list_name_expanded,
14665 ip_lcommunity_list_name_expanded_cmd,
14666 "ip large-community-list expanded WORD <deny|permit> LINE...",
14667 IP_STR
14668 LCOMMUNITY_LIST_STR
14669 "Specify expanded large-community-list\n"
14670 "Large Community list name\n"
14671 "Specify large community to reject\n"
14672 "Specify large community to accept\n"
14673 "An ordered list as a regular-expression\n")
14674
14675 DEFUN (no_lcommunity_list_standard_all,
14676 no_bgp_lcommunity_list_standard_all_cmd,
14677 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14678 NO_STR
14679 BGP_STR
14680 LCOMMUNITY_LIST_STR
14681 "Large Community list number (standard)\n"
14682 "Large Community list number (expanded)\n"
14683 "Large Community list name\n")
14684 {
14685 return lcommunity_list_unset_vty(vty, argc, argv,
14686 LARGE_COMMUNITY_LIST_STANDARD);
14687 }
14688
14689 ALIAS (no_lcommunity_list_standard_all,
14690 no_ip_lcommunity_list_standard_all_cmd,
14691 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14692 NO_STR
14693 IP_STR
14694 LCOMMUNITY_LIST_STR
14695 "Large Community list number (standard)\n"
14696 "Large Community list number (expanded)\n"
14697 "Large Community list name\n")
14698
14699 DEFUN (no_lcommunity_list_name_expanded_all,
14700 no_bgp_lcommunity_list_name_expanded_all_cmd,
14701 "no bgp large-community-list expanded WORD",
14702 NO_STR
14703 BGP_STR
14704 LCOMMUNITY_LIST_STR
14705 "Specify expanded large-community-list\n"
14706 "Large Community list name\n")
14707 {
14708 return lcommunity_list_unset_vty(vty, argc, argv,
14709 LARGE_COMMUNITY_LIST_EXPANDED);
14710 }
14711
14712 ALIAS (no_lcommunity_list_name_expanded_all,
14713 no_ip_lcommunity_list_name_expanded_all_cmd,
14714 "no ip large-community-list expanded WORD",
14715 NO_STR
14716 IP_STR
14717 LCOMMUNITY_LIST_STR
14718 "Specify expanded large-community-list\n"
14719 "Large Community list name\n")
14720
14721 DEFUN (no_lcommunity_list_standard,
14722 no_bgp_lcommunity_list_standard_cmd,
14723 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14724 NO_STR
14725 BGP_STR
14726 LCOMMUNITY_LIST_STR
14727 "Large Community list number (standard)\n"
14728 "Specify large community to reject\n"
14729 "Specify large community to accept\n"
14730 LCOMMUNITY_VAL_STR)
14731 {
14732 return lcommunity_list_unset_vty(vty, argc, argv,
14733 LARGE_COMMUNITY_LIST_STANDARD);
14734 }
14735
14736 ALIAS (no_lcommunity_list_standard,
14737 no_ip_lcommunity_list_standard_cmd,
14738 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14739 NO_STR
14740 IP_STR
14741 LCOMMUNITY_LIST_STR
14742 "Large Community list number (standard)\n"
14743 "Specify large community to reject\n"
14744 "Specify large community to accept\n"
14745 LCOMMUNITY_VAL_STR)
14746
14747 DEFUN (no_lcommunity_list_expanded,
14748 no_bgp_lcommunity_list_expanded_cmd,
14749 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14750 NO_STR
14751 BGP_STR
14752 LCOMMUNITY_LIST_STR
14753 "Large Community list number (expanded)\n"
14754 "Specify large community to reject\n"
14755 "Specify large community to accept\n"
14756 "An ordered list as a regular-expression\n")
14757 {
14758 return lcommunity_list_unset_vty(vty, argc, argv,
14759 LARGE_COMMUNITY_LIST_EXPANDED);
14760 }
14761
14762 ALIAS (no_lcommunity_list_expanded,
14763 no_ip_lcommunity_list_expanded_cmd,
14764 "no ip large-community-list (100-500) <deny|permit> LINE...",
14765 NO_STR
14766 IP_STR
14767 LCOMMUNITY_LIST_STR
14768 "Large Community list number (expanded)\n"
14769 "Specify large community to reject\n"
14770 "Specify large community to accept\n"
14771 "An ordered list as a regular-expression\n")
14772
14773 DEFUN (no_lcommunity_list_name_standard,
14774 no_bgp_lcommunity_list_name_standard_cmd,
14775 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14776 NO_STR
14777 BGP_STR
14778 LCOMMUNITY_LIST_STR
14779 "Specify standard large-community-list\n"
14780 "Large Community list name\n"
14781 "Specify large community to reject\n"
14782 "Specify large community to accept\n"
14783 LCOMMUNITY_VAL_STR)
14784 {
14785 return lcommunity_list_unset_vty(vty, argc, argv,
14786 LARGE_COMMUNITY_LIST_STANDARD);
14787 }
14788
14789 ALIAS (no_lcommunity_list_name_standard,
14790 no_ip_lcommunity_list_name_standard_cmd,
14791 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14792 NO_STR
14793 IP_STR
14794 LCOMMUNITY_LIST_STR
14795 "Specify standard large-community-list\n"
14796 "Large Community list name\n"
14797 "Specify large community to reject\n"
14798 "Specify large community to accept\n"
14799 LCOMMUNITY_VAL_STR)
14800
14801 DEFUN (no_lcommunity_list_name_expanded,
14802 no_bgp_lcommunity_list_name_expanded_cmd,
14803 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14804 NO_STR
14805 BGP_STR
14806 LCOMMUNITY_LIST_STR
14807 "Specify expanded large-community-list\n"
14808 "Large community list name\n"
14809 "Specify large community to reject\n"
14810 "Specify large community to accept\n"
14811 "An ordered list as a regular-expression\n")
14812 {
14813 return lcommunity_list_unset_vty(vty, argc, argv,
14814 LARGE_COMMUNITY_LIST_EXPANDED);
14815 }
14816
14817 ALIAS (no_lcommunity_list_name_expanded,
14818 no_ip_lcommunity_list_name_expanded_cmd,
14819 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14820 NO_STR
14821 IP_STR
14822 LCOMMUNITY_LIST_STR
14823 "Specify expanded large-community-list\n"
14824 "Large community list name\n"
14825 "Specify large community to reject\n"
14826 "Specify large community to accept\n"
14827 "An ordered list as a regular-expression\n")
14828
14829 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14830 {
14831 struct community_entry *entry;
14832
14833 for (entry = list->head; entry; entry = entry->next) {
14834 if (entry == list->head) {
14835 if (all_digit(list->name))
14836 vty_out(vty, "Large community %s list %s\n",
14837 entry->style == EXTCOMMUNITY_LIST_STANDARD
14838 ? "standard"
14839 : "(expanded) access",
14840 list->name);
14841 else
14842 vty_out(vty,
14843 "Named large community %s list %s\n",
14844 entry->style == EXTCOMMUNITY_LIST_STANDARD
14845 ? "standard"
14846 : "expanded",
14847 list->name);
14848 }
14849 if (entry->any)
14850 vty_out(vty, " %s\n",
14851 community_direct_str(entry->direct));
14852 else
14853 vty_out(vty, " %s %s\n",
14854 community_direct_str(entry->direct),
14855 community_list_config_str(entry));
14856 }
14857 }
14858
14859 DEFUN (show_lcommunity_list,
14860 show_bgp_lcommunity_list_cmd,
14861 "show bgp large-community-list",
14862 SHOW_STR
14863 BGP_STR
14864 "List large-community list\n")
14865 {
14866 struct community_list *list;
14867 struct community_list_master *cm;
14868 int idx = 0;
14869
14870 if (argv_find(argv, argc, "ip", &idx)) {
14871 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14872 vty_out(vty, "if you are using this please migrate to the below command.\n");
14873 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14874 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14875 }
14876
14877 cm = community_list_master_lookup(bgp_clist,
14878 LARGE_COMMUNITY_LIST_MASTER);
14879 if (!cm)
14880 return CMD_SUCCESS;
14881
14882 for (list = cm->num.head; list; list = list->next)
14883 lcommunity_list_show(vty, list);
14884
14885 for (list = cm->str.head; list; list = list->next)
14886 lcommunity_list_show(vty, list);
14887
14888 return CMD_SUCCESS;
14889 }
14890
14891 ALIAS (show_lcommunity_list,
14892 show_ip_lcommunity_list_cmd,
14893 "show ip large-community-list",
14894 SHOW_STR
14895 IP_STR
14896 "List large-community list\n")
14897
14898 DEFUN (show_lcommunity_list_arg,
14899 show_bgp_lcommunity_list_arg_cmd,
14900 "show bgp large-community-list <(1-500)|WORD>",
14901 SHOW_STR
14902 BGP_STR
14903 "List large-community list\n"
14904 "large-community-list number\n"
14905 "large-community-list name\n")
14906 {
14907 struct community_list *list;
14908 int idx = 0;
14909
14910 if (argv_find(argv, argc, "ip", &idx)) {
14911 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14912 vty_out(vty, "if you are using this please migrate to the below command.\n");
14913 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14914 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14915 }
14916
14917 list = community_list_lookup(bgp_clist, argv[3]->arg, 0,
14918 LARGE_COMMUNITY_LIST_MASTER);
14919 if (!list) {
14920 vty_out(vty, "%% Can't find extcommunity-list\n");
14921 return CMD_WARNING;
14922 }
14923
14924 lcommunity_list_show(vty, list);
14925
14926 return CMD_SUCCESS;
14927 }
14928
14929 ALIAS (show_lcommunity_list_arg,
14930 show_ip_lcommunity_list_arg_cmd,
14931 "show ip large-community-list <(1-500)|WORD>",
14932 SHOW_STR
14933 IP_STR
14934 "List large-community list\n"
14935 "large-community-list number\n"
14936 "large-community-list name\n")
14937
14938 /* "extcommunity-list" keyword help string. */
14939 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14940 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14941
14942 DEFUN (extcommunity_list_standard,
14943 bgp_extcommunity_list_standard_cmd,
14944 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14945 BGP_STR
14946 EXTCOMMUNITY_LIST_STR
14947 "Extended Community list number (standard)\n"
14948 "Specify standard extcommunity-list\n"
14949 "Community list name\n"
14950 "Specify community to reject\n"
14951 "Specify community to accept\n"
14952 EXTCOMMUNITY_VAL_STR)
14953 {
14954 int style = EXTCOMMUNITY_LIST_STANDARD;
14955 int direct = 0;
14956 char *cl_number_or_name = NULL;
14957
14958 int idx = 0;
14959 if (argv_find(argv, argc, "ip", &idx)) {
14960 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14961 vty_out(vty, "if you are using this please migrate to the below command.\n");
14962 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14963 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14964 }
14965 argv_find(argv, argc, "(1-99)", &idx);
14966 argv_find(argv, argc, "WORD", &idx);
14967 cl_number_or_name = argv[idx]->arg;
14968 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14969 : COMMUNITY_DENY;
14970 argv_find(argv, argc, "AA:NN", &idx);
14971 char *str = argv_concat(argv, argc, idx);
14972
14973 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14974 direct, style);
14975
14976 XFREE(MTYPE_TMP, str);
14977
14978 if (ret < 0) {
14979 community_list_perror(vty, ret);
14980 return CMD_WARNING_CONFIG_FAILED;
14981 }
14982
14983 return CMD_SUCCESS;
14984 }
14985
14986 #if CONFDATE > 20191005
14987 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14988 #endif
14989 ALIAS (extcommunity_list_standard,
14990 ip_extcommunity_list_standard_cmd,
14991 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14992 IP_STR
14993 EXTCOMMUNITY_LIST_STR
14994 "Extended Community list number (standard)\n"
14995 "Specify standard extcommunity-list\n"
14996 "Community list name\n"
14997 "Specify community to reject\n"
14998 "Specify community to accept\n"
14999 EXTCOMMUNITY_VAL_STR)
15000
15001 DEFUN (extcommunity_list_name_expanded,
15002 bgp_extcommunity_list_name_expanded_cmd,
15003 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15004 BGP_STR
15005 EXTCOMMUNITY_LIST_STR
15006 "Extended Community list number (expanded)\n"
15007 "Specify expanded extcommunity-list\n"
15008 "Extended Community list name\n"
15009 "Specify community to reject\n"
15010 "Specify community to accept\n"
15011 "An ordered list as a regular-expression\n")
15012 {
15013 int style = EXTCOMMUNITY_LIST_EXPANDED;
15014 int direct = 0;
15015 char *cl_number_or_name = NULL;
15016
15017 int idx = 0;
15018 if (argv_find(argv, argc, "ip", &idx)) {
15019 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15020 vty_out(vty, "if you are using this please migrate to the below command.\n");
15021 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15022 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15023 }
15024
15025 argv_find(argv, argc, "(100-500)", &idx);
15026 argv_find(argv, argc, "WORD", &idx);
15027 cl_number_or_name = argv[idx]->arg;
15028 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15029 : COMMUNITY_DENY;
15030 argv_find(argv, argc, "LINE", &idx);
15031 char *str = argv_concat(argv, argc, idx);
15032
15033 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
15034 direct, style);
15035
15036 XFREE(MTYPE_TMP, str);
15037
15038 if (ret < 0) {
15039 community_list_perror(vty, ret);
15040 return CMD_WARNING_CONFIG_FAILED;
15041 }
15042
15043 return CMD_SUCCESS;
15044 }
15045
15046 ALIAS (extcommunity_list_name_expanded,
15047 ip_extcommunity_list_name_expanded_cmd,
15048 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15049 IP_STR
15050 EXTCOMMUNITY_LIST_STR
15051 "Extended Community list number (expanded)\n"
15052 "Specify expanded extcommunity-list\n"
15053 "Extended Community list name\n"
15054 "Specify community to reject\n"
15055 "Specify community to accept\n"
15056 "An ordered list as a regular-expression\n")
15057
15058 DEFUN (no_extcommunity_list_standard_all,
15059 no_bgp_extcommunity_list_standard_all_cmd,
15060 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15061 NO_STR
15062 BGP_STR
15063 EXTCOMMUNITY_LIST_STR
15064 "Extended Community list number (standard)\n"
15065 "Specify standard extcommunity-list\n"
15066 "Community list name\n"
15067 "Specify community to reject\n"
15068 "Specify community to accept\n"
15069 EXTCOMMUNITY_VAL_STR)
15070 {
15071 int style = EXTCOMMUNITY_LIST_STANDARD;
15072 int direct = 0;
15073 char *cl_number_or_name = NULL;
15074 char *str = NULL;
15075
15076 int idx = 0;
15077 if (argv_find(argv, argc, "ip", &idx)) {
15078 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15079 vty_out(vty, "if you are using this please migrate to the below command.\n");
15080 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15081 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15082 }
15083
15084 idx = 0;
15085 argv_find(argv, argc, "permit", &idx);
15086 argv_find(argv, argc, "deny", &idx);
15087
15088 if (idx) {
15089 direct = argv_find(argv, argc, "permit", &idx)
15090 ? COMMUNITY_PERMIT
15091 : COMMUNITY_DENY;
15092
15093 idx = 0;
15094 argv_find(argv, argc, "AA:NN", &idx);
15095 str = argv_concat(argv, argc, idx);
15096 }
15097
15098 idx = 0;
15099 argv_find(argv, argc, "(1-99)", &idx);
15100 argv_find(argv, argc, "WORD", &idx);
15101 cl_number_or_name = argv[idx]->arg;
15102
15103 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15104 direct, style);
15105
15106 XFREE(MTYPE_TMP, str);
15107
15108 if (ret < 0) {
15109 community_list_perror(vty, ret);
15110 return CMD_WARNING_CONFIG_FAILED;
15111 }
15112
15113 return CMD_SUCCESS;
15114 }
15115
15116 ALIAS (no_extcommunity_list_standard_all,
15117 no_ip_extcommunity_list_standard_all_cmd,
15118 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15119 NO_STR
15120 IP_STR
15121 EXTCOMMUNITY_LIST_STR
15122 "Extended Community list number (standard)\n"
15123 "Specify standard extcommunity-list\n"
15124 "Community list name\n"
15125 "Specify community to reject\n"
15126 "Specify community to accept\n"
15127 EXTCOMMUNITY_VAL_STR)
15128
15129 ALIAS(no_extcommunity_list_standard_all,
15130 no_bgp_extcommunity_list_standard_all_list_cmd,
15131 "no bgp extcommunity-list <(1-99)|standard WORD>",
15132 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15133 "Extended Community list number (standard)\n"
15134 "Specify standard extcommunity-list\n"
15135 "Community list name\n")
15136
15137 ALIAS(no_extcommunity_list_standard_all,
15138 no_ip_extcommunity_list_standard_all_list_cmd,
15139 "no ip extcommunity-list <(1-99)|standard WORD>",
15140 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15141 "Extended Community list number (standard)\n"
15142 "Specify standard extcommunity-list\n"
15143 "Community list name\n")
15144
15145 DEFUN (no_extcommunity_list_expanded_all,
15146 no_bgp_extcommunity_list_expanded_all_cmd,
15147 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15148 NO_STR
15149 BGP_STR
15150 EXTCOMMUNITY_LIST_STR
15151 "Extended Community list number (expanded)\n"
15152 "Specify expanded extcommunity-list\n"
15153 "Extended Community list name\n"
15154 "Specify community to reject\n"
15155 "Specify community to accept\n"
15156 "An ordered list as a regular-expression\n")
15157 {
15158 int style = EXTCOMMUNITY_LIST_EXPANDED;
15159 int direct = 0;
15160 char *cl_number_or_name = NULL;
15161 char *str = NULL;
15162
15163 int idx = 0;
15164 if (argv_find(argv, argc, "ip", &idx)) {
15165 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15166 vty_out(vty, "if you are using this please migrate to the below command.\n");
15167 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15168 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15169 }
15170
15171 idx = 0;
15172 argv_find(argv, argc, "permit", &idx);
15173 argv_find(argv, argc, "deny", &idx);
15174
15175 if (idx) {
15176 direct = argv_find(argv, argc, "permit", &idx)
15177 ? COMMUNITY_PERMIT
15178 : COMMUNITY_DENY;
15179
15180 idx = 0;
15181 argv_find(argv, argc, "LINE", &idx);
15182 str = argv_concat(argv, argc, idx);
15183 }
15184
15185 idx = 0;
15186 argv_find(argv, argc, "(100-500)", &idx);
15187 argv_find(argv, argc, "WORD", &idx);
15188 cl_number_or_name = argv[idx]->arg;
15189
15190 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15191 direct, style);
15192
15193 XFREE(MTYPE_TMP, str);
15194
15195 if (ret < 0) {
15196 community_list_perror(vty, ret);
15197 return CMD_WARNING_CONFIG_FAILED;
15198 }
15199
15200 return CMD_SUCCESS;
15201 }
15202
15203 ALIAS (no_extcommunity_list_expanded_all,
15204 no_ip_extcommunity_list_expanded_all_cmd,
15205 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15206 NO_STR
15207 IP_STR
15208 EXTCOMMUNITY_LIST_STR
15209 "Extended Community list number (expanded)\n"
15210 "Specify expanded extcommunity-list\n"
15211 "Extended Community list name\n"
15212 "Specify community to reject\n"
15213 "Specify community to accept\n"
15214 "An ordered list as a regular-expression\n")
15215
15216 ALIAS(no_extcommunity_list_expanded_all,
15217 no_ip_extcommunity_list_expanded_all_list_cmd,
15218 "no ip extcommunity-list <(100-500)|expanded WORD>",
15219 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15220 "Extended Community list number (expanded)\n"
15221 "Specify expanded extcommunity-list\n"
15222 "Extended Community list name\n")
15223
15224 ALIAS(no_extcommunity_list_expanded_all,
15225 no_bgp_extcommunity_list_expanded_all_list_cmd,
15226 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15227 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15228 "Extended Community list number (expanded)\n"
15229 "Specify expanded extcommunity-list\n"
15230 "Extended Community list name\n")
15231
15232 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15233 {
15234 struct community_entry *entry;
15235
15236 for (entry = list->head; entry; entry = entry->next) {
15237 if (entry == list->head) {
15238 if (all_digit(list->name))
15239 vty_out(vty, "Extended community %s list %s\n",
15240 entry->style == EXTCOMMUNITY_LIST_STANDARD
15241 ? "standard"
15242 : "(expanded) access",
15243 list->name);
15244 else
15245 vty_out(vty,
15246 "Named extended community %s list %s\n",
15247 entry->style == EXTCOMMUNITY_LIST_STANDARD
15248 ? "standard"
15249 : "expanded",
15250 list->name);
15251 }
15252 if (entry->any)
15253 vty_out(vty, " %s\n",
15254 community_direct_str(entry->direct));
15255 else
15256 vty_out(vty, " %s %s\n",
15257 community_direct_str(entry->direct),
15258 community_list_config_str(entry));
15259 }
15260 }
15261
15262 DEFUN (show_extcommunity_list,
15263 show_bgp_extcommunity_list_cmd,
15264 "show bgp extcommunity-list",
15265 SHOW_STR
15266 BGP_STR
15267 "List extended-community list\n")
15268 {
15269 struct community_list *list;
15270 struct community_list_master *cm;
15271 int idx = 0;
15272
15273 if (argv_find(argv, argc, "ip", &idx)) {
15274 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15275 vty_out(vty, "if you are using this please migrate to the below command.\n");
15276 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15277 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15278 }
15279 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15280 if (!cm)
15281 return CMD_SUCCESS;
15282
15283 for (list = cm->num.head; list; list = list->next)
15284 extcommunity_list_show(vty, list);
15285
15286 for (list = cm->str.head; list; list = list->next)
15287 extcommunity_list_show(vty, list);
15288
15289 return CMD_SUCCESS;
15290 }
15291
15292 ALIAS (show_extcommunity_list,
15293 show_ip_extcommunity_list_cmd,
15294 "show ip extcommunity-list",
15295 SHOW_STR
15296 IP_STR
15297 "List extended-community list\n")
15298
15299 DEFUN (show_extcommunity_list_arg,
15300 show_bgp_extcommunity_list_arg_cmd,
15301 "show bgp extcommunity-list <(1-500)|WORD>",
15302 SHOW_STR
15303 BGP_STR
15304 "List extended-community list\n"
15305 "Extcommunity-list number\n"
15306 "Extcommunity-list name\n")
15307 {
15308 int idx_comm_list = 3;
15309 struct community_list *list;
15310 int idx = 0;
15311
15312 if (argv_find(argv, argc, "ip", &idx)) {
15313 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15314 vty_out(vty, "if you are using this please migrate to the below command.\n");
15315 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15316 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15317 }
15318 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg, 0,
15319 EXTCOMMUNITY_LIST_MASTER);
15320 if (!list) {
15321 vty_out(vty, "%% Can't find extcommunity-list\n");
15322 return CMD_WARNING;
15323 }
15324
15325 extcommunity_list_show(vty, list);
15326
15327 return CMD_SUCCESS;
15328 }
15329
15330 ALIAS (show_extcommunity_list_arg,
15331 show_ip_extcommunity_list_arg_cmd,
15332 "show ip extcommunity-list <(1-500)|WORD>",
15333 SHOW_STR
15334 IP_STR
15335 "List extended-community list\n"
15336 "Extcommunity-list number\n"
15337 "Extcommunity-list name\n")
15338
15339 /* Display community-list and extcommunity-list configuration. */
15340 static int community_list_config_write(struct vty *vty)
15341 {
15342 struct community_list *list;
15343 struct community_entry *entry;
15344 struct community_list_master *cm;
15345 int write = 0;
15346
15347 /* Community-list. */
15348 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15349
15350 for (list = cm->num.head; list; list = list->next)
15351 for (entry = list->head; entry; entry = entry->next) {
15352 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15353 community_direct_str(entry->direct),
15354 community_list_config_str(entry));
15355 write++;
15356 }
15357 for (list = cm->str.head; list; list = list->next)
15358 for (entry = list->head; entry; entry = entry->next) {
15359 vty_out(vty, "bgp community-list %s %s %s %s\n",
15360 entry->style == COMMUNITY_LIST_STANDARD
15361 ? "standard"
15362 : "expanded",
15363 list->name, community_direct_str(entry->direct),
15364 community_list_config_str(entry));
15365 write++;
15366 }
15367
15368 /* Extcommunity-list. */
15369 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15370
15371 for (list = cm->num.head; list; list = list->next)
15372 for (entry = list->head; entry; entry = entry->next) {
15373 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15374 list->name, community_direct_str(entry->direct),
15375 community_list_config_str(entry));
15376 write++;
15377 }
15378 for (list = cm->str.head; list; list = list->next)
15379 for (entry = list->head; entry; entry = entry->next) {
15380 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15381 entry->style == EXTCOMMUNITY_LIST_STANDARD
15382 ? "standard"
15383 : "expanded",
15384 list->name, community_direct_str(entry->direct),
15385 community_list_config_str(entry));
15386 write++;
15387 }
15388
15389
15390 /* lcommunity-list. */
15391 cm = community_list_master_lookup(bgp_clist,
15392 LARGE_COMMUNITY_LIST_MASTER);
15393
15394 for (list = cm->num.head; list; list = list->next)
15395 for (entry = list->head; entry; entry = entry->next) {
15396 vty_out(vty, "bgp large-community-list %s %s %s\n",
15397 list->name, community_direct_str(entry->direct),
15398 community_list_config_str(entry));
15399 write++;
15400 }
15401 for (list = cm->str.head; list; list = list->next)
15402 for (entry = list->head; entry; entry = entry->next) {
15403 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15404 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15405 ? "standard"
15406 : "expanded",
15407 list->name, community_direct_str(entry->direct),
15408 community_list_config_str(entry));
15409 write++;
15410 }
15411
15412 return write;
15413 }
15414
15415 static struct cmd_node community_list_node = {
15416 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15417 };
15418
15419 static void community_list_vty(void)
15420 {
15421 install_node(&community_list_node, community_list_config_write);
15422
15423 /* Community-list. */
15424 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15425 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15426 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15427 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15428 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15429 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15430 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15431 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15432 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15433 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15434 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15435 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15436 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15437 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15438 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15439 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15440
15441 /* Extcommunity-list. */
15442 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15443 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15444 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15445 install_element(CONFIG_NODE,
15446 &no_bgp_extcommunity_list_standard_all_list_cmd);
15447 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15448 install_element(CONFIG_NODE,
15449 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15450 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15451 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15452 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15453 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15454 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15455 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15456 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15457 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15458 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15459 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15460
15461 /* Large Community List */
15462 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15463 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15464 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15465 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15466 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15467 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15468 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15469 install_element(CONFIG_NODE,
15470 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15471 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15472 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15473 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15474 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15475 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15476 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15477 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15478 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15479 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15480 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15481 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15482 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15483 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15484 install_element(CONFIG_NODE,
15485 &no_ip_lcommunity_list_name_expanded_all_cmd);
15486 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15487 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15488 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15489 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15490 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15491 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15492 }