]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge remote-tracking branch 'origin/master' into evpn_plus_struct_attr
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "prefix.h"
26 #include "plist.h"
27 #include "buffer.h"
28 #include "linklist.h"
29 #include "stream.h"
30 #include "thread.h"
31 #include "log.h"
32 #include "memory.h"
33 #include "memory_vty.h"
34 #include "hash.h"
35 #include "queue.h"
36 #include "filter.h"
37
38 #include "bgpd/bgpd.h"
39 #include "bgpd/bgp_advertise.h"
40 #include "bgpd/bgp_attr.h"
41 #include "bgpd/bgp_aspath.h"
42 #include "bgpd/bgp_community.h"
43 #include "bgpd/bgp_ecommunity.h"
44 #include "bgpd/bgp_lcommunity.h"
45 #include "bgpd/bgp_damp.h"
46 #include "bgpd/bgp_debug.h"
47 #include "bgpd/bgp_fsm.h"
48 #include "bgpd/bgp_nexthop.h"
49 #include "bgpd/bgp_open.h"
50 #include "bgpd/bgp_regex.h"
51 #include "bgpd/bgp_route.h"
52 #include "bgpd/bgp_mplsvpn.h"
53 #include "bgpd/bgp_zebra.h"
54 #include "bgpd/bgp_table.h"
55 #include "bgpd/bgp_vty.h"
56 #include "bgpd/bgp_mpath.h"
57 #include "bgpd/bgp_packet.h"
58 #include "bgpd/bgp_updgrp.h"
59 #include "bgpd/bgp_bfd.h"
60
61 static struct peer_group *
62 listen_range_exists (struct bgp *bgp, struct prefix *range, int exact);
63
64 static enum node_type
65 bgp_node_type (afi_t afi, safi_t safi)
66 {
67 switch (afi)
68 {
69 case AFI_IP:
70 switch (safi)
71 {
72 case SAFI_UNICAST:
73 return BGP_IPV4_NODE;
74 break;
75 case SAFI_MULTICAST:
76 return BGP_IPV4M_NODE;
77 break;
78 case SAFI_LABELED_UNICAST:
79 return BGP_IPV4L_NODE;
80 break;
81 case SAFI_MPLS_VPN:
82 return BGP_VPNV4_NODE;
83 break;
84 }
85 break;
86 case AFI_IP6:
87 switch (safi)
88 {
89 case SAFI_UNICAST:
90 return BGP_IPV6_NODE;
91 break;
92 case SAFI_MULTICAST:
93 return BGP_IPV6M_NODE;
94 break;
95 case SAFI_LABELED_UNICAST:
96 return BGP_IPV6L_NODE;
97 break;
98 case SAFI_MPLS_VPN:
99 return BGP_VPNV6_NODE;
100 break;
101 }
102 break;
103 case AFI_L2VPN:
104 return BGP_EVPN_NODE;
105 break;
106 case AFI_MAX:
107 // We should never be here but to clarify the switch statement..
108 return BGP_IPV4_NODE;
109 break;
110 }
111
112 // Impossible to happen
113 return BGP_IPV4_NODE;
114 }
115
116 /* Utility function to get address family from current node. */
117 afi_t
118 bgp_node_afi (struct vty *vty)
119 {
120 afi_t afi;
121 switch (vty->node)
122 {
123 case BGP_IPV6_NODE:
124 case BGP_IPV6M_NODE:
125 case BGP_IPV6L_NODE:
126 case BGP_VPNV6_NODE:
127 afi = AFI_IP6;
128 break;
129 case BGP_EVPN_NODE:
130 afi = AFI_L2VPN;
131 break;
132 default:
133 afi = AFI_IP;
134 break;
135 }
136 return afi;
137 }
138
139 /* Utility function to get subsequent address family from current
140 node. */
141 safi_t
142 bgp_node_safi (struct vty *vty)
143 {
144 safi_t safi;
145 switch (vty->node)
146 {
147 case BGP_VPNV4_NODE:
148 case BGP_VPNV6_NODE:
149 safi = SAFI_MPLS_VPN;
150 break;
151 case BGP_IPV4M_NODE:
152 case BGP_IPV6M_NODE:
153 safi = SAFI_MULTICAST;
154 break;
155 case BGP_EVPN_NODE:
156 safi = SAFI_EVPN;
157 break;
158 case BGP_IPV4L_NODE:
159 case BGP_IPV6L_NODE:
160 safi = SAFI_LABELED_UNICAST;
161 break;
162 default:
163 safi = SAFI_UNICAST;
164 break;
165 }
166 return safi;
167 }
168
169 /**
170 * Converts an AFI in string form to afi_t
171 *
172 * @param afi string, one of
173 * - "ipv4"
174 * - "ipv6"
175 * @return the corresponding afi_t
176 */
177 afi_t
178 bgp_vty_afi_from_str(const char *afi_str)
179 {
180 afi_t afi = AFI_MAX; /* unknown */
181 if (strmatch(afi_str, "ipv4"))
182 afi = AFI_IP;
183 else if (strmatch(afi_str, "ipv6"))
184 afi = AFI_IP6;
185 return afi;
186 }
187
188 int
189 argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index, afi_t *afi)
190 {
191 int ret = 0;
192 if (argv_find (argv, argc, "ipv4", index))
193 {
194 ret = 1;
195 if (afi)
196 *afi = AFI_IP;
197 }
198 else if (argv_find (argv, argc, "ipv6", index))
199 {
200 ret = 1;
201 if (afi)
202 *afi = AFI_IP6;
203 }
204 return ret;
205 }
206
207 /* supports <unicast|multicast|vpn|labeled-unicast> */
208 safi_t
209 bgp_vty_safi_from_str(const char *safi_str)
210 {
211 safi_t safi = SAFI_MAX; /* unknown */
212 if (strmatch (safi_str, "multicast"))
213 safi = SAFI_MULTICAST;
214 else if (strmatch (safi_str, "unicast"))
215 safi = SAFI_UNICAST;
216 else if (strmatch (safi_str, "vpn"))
217 safi = SAFI_MPLS_VPN;
218 else if (strmatch (safi_str, "labeled-unicast"))
219 safi = SAFI_LABELED_UNICAST;
220 return safi;
221 }
222
223 int
224 argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t *safi)
225 {
226 int ret = 0;
227 if (argv_find (argv, argc, "unicast", index))
228 {
229 ret = 1;
230 if (safi)
231 *safi = SAFI_UNICAST;
232 }
233 else if (argv_find (argv, argc, "multicast", index))
234 {
235 ret = 1;
236 if (safi)
237 *safi = SAFI_MULTICAST;
238 }
239 else if (argv_find (argv, argc, "labeled-unicast", index))
240 {
241 ret = 1;
242 if (safi)
243 *safi = SAFI_LABELED_UNICAST;
244 }
245 else if (argv_find (argv, argc, "vpn", index))
246 {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_MPLS_VPN;
250 }
251 return ret;
252 }
253
254 /*
255 * bgp_vty_find_and_parse_afi_safi_bgp
256 *
257 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
258 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
259 * to appropriate values for the calling function. This is to allow the
260 * calling function to make decisions appropriate for the show command
261 * that is being parsed.
262 *
263 * The show commands are generally of the form:
264 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] ..."
265 *
266 * Since we use argv_find if the show command in particular doesn't have:
267 * [ip]
268 * [<view|vrf> VIEWVRFNAME]
269 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
270 * The command parsing should still be ok.
271 *
272 * vty -> The vty for the command so we can output some useful data in
273 * the event of a parse error in the vrf.
274 * argv -> The command tokens
275 * argc -> How many command tokens we have
276 * idx -> The current place in the command, generally should be 0 for this function
277 * afi -> The parsed afi if it was included in the show command, returned here
278 * safi -> The parsed safi if it was included in the show command, returned here
279 * bgp -> Pointer to the bgp data structure we need to fill in.
280 *
281 * The function returns the correct location in the parse tree for the
282 * last token found.
283 *
284 * Returns 0 for failure to parse correctly, else the idx position of where
285 * it found the last token.
286 */
287 int
288 bgp_vty_find_and_parse_afi_safi_bgp (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
289 afi_t *afi, safi_t *safi, struct bgp **bgp)
290 {
291 char *vrf_name = NULL;
292
293 assert (afi);
294 assert (safi);
295 assert (bgp);
296
297 if (argv_find (argv, argc, "ip", idx))
298 *afi = AFI_IP;
299
300 if (argv_find (argv, argc, "view", idx) || argv_find (argv, argc, "vrf", idx))
301 {
302 vrf_name = argv[*idx + 1]->arg;
303
304 if (strmatch (vrf_name, "all"))
305 *bgp = NULL;
306 else
307 {
308 *bgp = bgp_lookup_by_name (vrf_name);
309 if (!*bgp)
310 {
311 vty_out (vty, "View/Vrf specified is unknown: %s%s", vrf_name, VTYNL);
312 *idx = 0;
313 return 0;
314 }
315 }
316 }
317 else
318 {
319 *bgp = bgp_get_default ();
320 if (!*bgp)
321 {
322 vty_out (vty, "Unable to find default BGP instance%s", VTYNL);
323 *idx = 0;
324 return 0;
325 }
326 }
327
328 if (argv_find_and_parse_afi (argv, argc, idx, afi))
329 argv_find_and_parse_safi (argv, argc, idx, safi);
330
331 *idx += 1;
332 return *idx;
333 }
334
335 static int
336 peer_address_self_check (struct bgp *bgp, union sockunion *su)
337 {
338 struct interface *ifp = NULL;
339
340 if (su->sa.sa_family == AF_INET)
341 ifp = if_lookup_by_ipv4_exact (&su->sin.sin_addr, bgp->vrf_id);
342 else if (su->sa.sa_family == AF_INET6)
343 ifp = if_lookup_by_ipv6_exact (&su->sin6.sin6_addr,
344 su->sin6.sin6_scope_id, bgp->vrf_id);
345
346 if (ifp)
347 return 1;
348
349 return 0;
350 }
351
352 /* Utility function for looking up peer from VTY. */
353 /* This is used only for configuration, so disallow if attempted on
354 * a dynamic neighbor.
355 */
356 static struct peer *
357 peer_lookup_vty (struct vty *vty, const char *ip_str)
358 {
359 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
360 int ret;
361 union sockunion su;
362 struct peer *peer;
363
364 if (!bgp) {
365 return NULL;
366 }
367
368 ret = str2sockunion (ip_str, &su);
369 if (ret < 0)
370 {
371 peer = peer_lookup_by_conf_if (bgp, ip_str);
372 if (!peer)
373 {
374 if ((peer = peer_lookup_by_hostname(bgp, ip_str)) == NULL)
375 {
376 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTYNL);
377 return NULL;
378 }
379 }
380 }
381 else
382 {
383 peer = peer_lookup (bgp, &su);
384 if (! peer)
385 {
386 vty_out (vty, "%% Specify remote-as or peer-group commands first%s",
387 VTYNL);
388 return NULL;
389 }
390 if (peer_dynamic_neighbor (peer))
391 {
392 vty_out (vty, "%% Operation not allowed on a dynamic neighbor%s",
393 VTYNL);
394 return NULL;
395 }
396
397 }
398 return peer;
399 }
400
401 /* Utility function for looking up peer or peer group. */
402 /* This is used only for configuration, so disallow if attempted on
403 * a dynamic neighbor.
404 */
405 struct peer *
406 peer_and_group_lookup_vty (struct vty *vty, const char *peer_str)
407 {
408 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
409 int ret;
410 union sockunion su;
411 struct peer *peer = NULL;
412 struct peer_group *group = NULL;
413
414 if (!bgp) {
415 return NULL;
416 }
417
418 ret = str2sockunion (peer_str, &su);
419 if (ret == 0)
420 {
421 /* IP address, locate peer. */
422 peer = peer_lookup (bgp, &su);
423 }
424 else
425 {
426 /* Not IP, could match either peer configured on interface or a group. */
427 peer = peer_lookup_by_conf_if (bgp, peer_str);
428 if (!peer)
429 group = peer_group_lookup (bgp, peer_str);
430 }
431
432 if (peer)
433 {
434 if (peer_dynamic_neighbor (peer))
435 {
436 vty_out (vty, "%% Operation not allowed on a dynamic neighbor%s",
437 VTYNL);
438 return NULL;
439 }
440
441 return peer;
442 }
443
444 if (group)
445 return group->conf;
446
447 vty_out (vty, "%% Specify remote-as or peer-group commands first%s",
448 VTYNL);
449
450 return NULL;
451 }
452
453 int
454 bgp_vty_return (struct vty *vty, int ret)
455 {
456 const char *str = NULL;
457
458 switch (ret)
459 {
460 case BGP_ERR_INVALID_VALUE:
461 str = "Invalid value";
462 break;
463 case BGP_ERR_INVALID_FLAG:
464 str = "Invalid flag";
465 break;
466 case BGP_ERR_PEER_GROUP_SHUTDOWN:
467 str = "Peer-group has been shutdown. Activate the peer-group first";
468 break;
469 case BGP_ERR_PEER_FLAG_CONFLICT:
470 str = "Can't set override-capability and strict-capability-match at the same time";
471 break;
472 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
473 str = "Specify remote-as or peer-group remote AS first";
474 break;
475 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
476 str = "Cannot change the peer-group. Deconfigure first";
477 break;
478 case BGP_ERR_PEER_GROUP_MISMATCH:
479 str = "Peer is not a member of this peer-group";
480 break;
481 case BGP_ERR_PEER_FILTER_CONFLICT:
482 str = "Prefix/distribute list can not co-exist";
483 break;
484 case BGP_ERR_NOT_INTERNAL_PEER:
485 str = "Invalid command. Not an internal neighbor";
486 break;
487 case BGP_ERR_REMOVE_PRIVATE_AS:
488 str = "remove-private-AS cannot be configured for IBGP peers";
489 break;
490 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
491 str = "Local-AS allowed only for EBGP peers";
492 break;
493 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
494 str = "Cannot have local-as same as BGP AS number";
495 break;
496 case BGP_ERR_TCPSIG_FAILED:
497 str = "Error while applying TCP-Sig to session(s)";
498 break;
499 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
500 str = "ebgp-multihop and ttl-security cannot be configured together";
501 break;
502 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
503 str = "ttl-security only allowed for EBGP peers";
504 break;
505 case BGP_ERR_AS_OVERRIDE:
506 str = "as-override cannot be configured for IBGP peers";
507 break;
508 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
509 str = "Invalid limit for number of dynamic neighbors";
510 break;
511 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
512 str = "Dynamic neighbor listen range already exists";
513 break;
514 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
515 str = "Operation not allowed on a dynamic neighbor";
516 break;
517 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
518 str = "Operation not allowed on a directly connected neighbor";
519 break;
520 case BGP_ERR_PEER_SAFI_CONFLICT:
521 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
522 break;
523 }
524 if (str)
525 {
526 vty_out (vty, "%% %s%s", str, VTYNL);
527 return CMD_WARNING_CONFIG_FAILED;
528 }
529 return CMD_SUCCESS;
530 }
531
532 /* BGP clear sort. */
533 enum clear_sort
534 {
535 clear_all,
536 clear_peer,
537 clear_group,
538 clear_external,
539 clear_as
540 };
541
542 static void
543 bgp_clear_vty_error (struct vty *vty, struct peer *peer, afi_t afi,
544 safi_t safi, int error)
545 {
546 switch (error)
547 {
548 case BGP_ERR_AF_UNCONFIGURED:
549 vty_out (vty,
550 "%%BGP: Enable %s address family for the neighbor %s%s",
551 afi_safi_print(afi, safi), peer->host, VTYNL);
552 break;
553 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
554 vty_out (vty, "%%BGP: Inbound soft reconfig for %s not possible as it%s has neither refresh capability, nor inbound soft reconfig%s", peer->host, VTYNL, VTYNL);
555 break;
556 default:
557 break;
558 }
559 }
560
561 /* `clear ip bgp' functions. */
562 static int
563 bgp_clear (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
564 enum clear_sort sort,enum bgp_clear_type stype, const char *arg)
565 {
566 int ret;
567 struct peer *peer;
568 struct listnode *node, *nnode;
569
570 /* Clear all neighbors. */
571 /*
572 * Pass along pointer to next node to peer_clear() when walking all nodes
573 * on the BGP instance as that may get freed if it is a doppelganger
574 */
575 if (sort == clear_all)
576 {
577 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
578 {
579 if (stype == BGP_CLEAR_SOFT_NONE)
580 ret = peer_clear (peer, &nnode);
581 else if (peer->afc[afi][safi])
582 ret = peer_clear_soft (peer, afi, safi, stype);
583 else
584 ret = 0;
585
586 if (ret < 0)
587 bgp_clear_vty_error (vty, peer, afi, safi, ret);
588 }
589
590 /* This is to apply read-only mode on this clear. */
591 if (stype == BGP_CLEAR_SOFT_NONE)
592 bgp->update_delay_over = 0;
593
594 return CMD_SUCCESS;
595 }
596
597 /* Clear specified neighbors. */
598 if (sort == clear_peer)
599 {
600 union sockunion su;
601 int ret;
602
603 /* Make sockunion for lookup. */
604 ret = str2sockunion (arg, &su);
605 if (ret < 0)
606 {
607 peer = peer_lookup_by_conf_if (bgp, arg);
608 if (!peer)
609 {
610 peer = peer_lookup_by_hostname(bgp, arg);
611 if (!peer)
612 {
613 vty_out (vty, "Malformed address or name: %s%s", arg, VTYNL);
614 return CMD_WARNING;
615 }
616 }
617 }
618 else
619 {
620 peer = peer_lookup (bgp, &su);
621 if (! peer)
622 {
623 vty_out (vty, "%%BGP: Unknown neighbor - \"%s\"%s", arg, VTYNL);
624 return CMD_WARNING;
625 }
626 }
627
628 if (stype == BGP_CLEAR_SOFT_NONE)
629 ret = peer_clear (peer, NULL);
630 else
631 ret = peer_clear_soft (peer, afi, safi, stype);
632
633 if (ret < 0)
634 bgp_clear_vty_error (vty, peer, afi, safi, ret);
635
636 return CMD_SUCCESS;
637 }
638
639 /* Clear all peer-group members. */
640 if (sort == clear_group)
641 {
642 struct peer_group *group;
643
644 group = peer_group_lookup (bgp, arg);
645 if (! group)
646 {
647 vty_out (vty, "%%BGP: No such peer-group %s%s", arg, VTYNL);
648 return CMD_WARNING;
649 }
650
651 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
652 {
653 if (stype == BGP_CLEAR_SOFT_NONE)
654 {
655 peer_clear (peer, NULL);
656 continue;
657 }
658
659 if (! peer->afc[afi][safi])
660 continue;
661
662 ret = peer_clear_soft (peer, afi, safi, stype);
663
664 if (ret < 0)
665 bgp_clear_vty_error (vty, peer, afi, safi, ret);
666 }
667 return CMD_SUCCESS;
668 }
669
670 if (sort == clear_external)
671 {
672 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
673 {
674 if (peer->sort == BGP_PEER_IBGP)
675 continue;
676
677 if (stype == BGP_CLEAR_SOFT_NONE)
678 ret = peer_clear (peer, &nnode);
679 else
680 ret = peer_clear_soft (peer, afi, safi, stype);
681
682 if (ret < 0)
683 bgp_clear_vty_error (vty, peer, afi, safi, ret);
684 }
685 return CMD_SUCCESS;
686 }
687
688 if (sort == clear_as)
689 {
690 as_t as;
691 int find = 0;
692
693 as = strtoul(arg, NULL, 10);
694
695 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
696 {
697 if (peer->as != as)
698 continue;
699
700 find = 1;
701 if (stype == BGP_CLEAR_SOFT_NONE)
702 ret = peer_clear (peer, &nnode);
703 else
704 ret = peer_clear_soft (peer, afi, safi, stype);
705
706 if (ret < 0)
707 bgp_clear_vty_error (vty, peer, afi, safi, ret);
708 }
709 if (! find)
710 vty_out (vty, "%%BGP: No peer is configured with AS %s%s", arg,
711 VTYNL);
712 return CMD_SUCCESS;
713 }
714
715 return CMD_SUCCESS;
716 }
717
718 static int
719 bgp_clear_vty (struct vty *vty, const char *name, afi_t afi, safi_t safi,
720 enum clear_sort sort, enum bgp_clear_type stype,
721 const char *arg)
722 {
723 struct bgp *bgp;
724
725 /* BGP structure lookup. */
726 if (name)
727 {
728 bgp = bgp_lookup_by_name (name);
729 if (bgp == NULL)
730 {
731 vty_out (vty, "Can't find BGP instance %s%s", name, VTYNL);
732 return CMD_WARNING;
733 }
734 }
735 else
736 {
737 bgp = bgp_get_default ();
738 if (bgp == NULL)
739 {
740 vty_out (vty, "No BGP process is configured%s", VTYNL);
741 return CMD_WARNING;
742 }
743 }
744
745 return bgp_clear (vty, bgp, afi, safi, sort, stype, arg);
746 }
747
748 /* clear soft inbound */
749 static void
750 bgp_clear_star_soft_in (struct vty *vty, const char *name)
751 {
752 bgp_clear_vty (vty, name, AFI_IP, SAFI_UNICAST, clear_all,
753 BGP_CLEAR_SOFT_IN, NULL);
754 bgp_clear_vty (vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
755 BGP_CLEAR_SOFT_IN, NULL);
756 }
757
758 /* clear soft outbound */
759 static void
760 bgp_clear_star_soft_out (struct vty *vty, const char *name)
761 {
762 bgp_clear_vty (vty, name, AFI_IP, SAFI_UNICAST, clear_all,
763 BGP_CLEAR_SOFT_OUT, NULL);
764 bgp_clear_vty (vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
765 BGP_CLEAR_SOFT_OUT, NULL);
766 }
767
768
769 #ifndef VTYSH_EXTRACT_PL
770 #include "bgp_vty_clippy.c"
771 #endif
772
773 /* BGP global configuration. */
774
775 DEFUN (bgp_multiple_instance_func,
776 bgp_multiple_instance_cmd,
777 "bgp multiple-instance",
778 BGP_STR
779 "Enable bgp multiple instance\n")
780 {
781 bgp_option_set (BGP_OPT_MULTIPLE_INSTANCE);
782 return CMD_SUCCESS;
783 }
784
785 DEFUN (no_bgp_multiple_instance,
786 no_bgp_multiple_instance_cmd,
787 "no bgp multiple-instance",
788 NO_STR
789 BGP_STR
790 "BGP multiple instance\n")
791 {
792 int ret;
793
794 ret = bgp_option_unset (BGP_OPT_MULTIPLE_INSTANCE);
795 if (ret < 0)
796 {
797 vty_out (vty, "%% There are more than two BGP instances%s", VTYNL);
798 return CMD_WARNING_CONFIG_FAILED;
799 }
800 return CMD_SUCCESS;
801 }
802
803 DEFUN (bgp_config_type,
804 bgp_config_type_cmd,
805 "bgp config-type <cisco|zebra>",
806 BGP_STR
807 "Configuration type\n"
808 "cisco\n"
809 "zebra\n")
810 {
811 int idx = 0;
812 if (argv_find (argv, argc, "cisco", &idx))
813 bgp_option_set (BGP_OPT_CONFIG_CISCO);
814 else
815 bgp_option_unset (BGP_OPT_CONFIG_CISCO);
816
817 return CMD_SUCCESS;
818 }
819
820 DEFUN (no_bgp_config_type,
821 no_bgp_config_type_cmd,
822 "no bgp config-type [<cisco|zebra>]",
823 NO_STR
824 BGP_STR
825 "Display configuration type\n"
826 "cisco\n"
827 "zebra\n")
828 {
829 bgp_option_unset (BGP_OPT_CONFIG_CISCO);
830 return CMD_SUCCESS;
831 }
832
833
834 DEFUN (no_synchronization,
835 no_synchronization_cmd,
836 "no synchronization",
837 NO_STR
838 "Perform IGP synchronization\n")
839 {
840 return CMD_SUCCESS;
841 }
842
843 DEFUN (no_auto_summary,
844 no_auto_summary_cmd,
845 "no auto-summary",
846 NO_STR
847 "Enable automatic network number summarization\n")
848 {
849 return CMD_SUCCESS;
850 }
851
852 /* "router bgp" commands. */
853 DEFUN_NOSH (router_bgp,
854 router_bgp_cmd,
855 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
856 ROUTER_STR
857 BGP_STR
858 AS_STR
859 BGP_INSTANCE_HELP_STR)
860 {
861 int idx_asn = 2;
862 int idx_view_vrf = 3;
863 int idx_vrf = 4;
864 int ret;
865 as_t as;
866 struct bgp *bgp;
867 const char *name = NULL;
868 enum bgp_instance_type inst_type;
869
870 // "router bgp" without an ASN
871 if (argc == 2)
872 {
873 //Pending: Make VRF option available for ASN less config
874 bgp = bgp_get_default();
875
876 if (bgp == NULL)
877 {
878 vty_out (vty, "%% No BGP process is configured%s", VTYNL);
879 return CMD_WARNING_CONFIG_FAILED;
880 }
881
882 if (listcount(bm->bgp) > 1)
883 {
884 vty_out (vty, "%% Multiple BGP processes are configured%s", VTYNL);
885 return CMD_WARNING_CONFIG_FAILED;
886 }
887 }
888
889 // "router bgp X"
890 else
891 {
892 as = strtoul (argv[idx_asn]->arg, NULL, 10);
893
894 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
895 if (argc > 3)
896 {
897 name = argv[idx_vrf]->arg;
898
899 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
900 inst_type = BGP_INSTANCE_TYPE_VRF;
901 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
902 inst_type = BGP_INSTANCE_TYPE_VIEW;
903 }
904
905 ret = bgp_get (&bgp, &as, name, inst_type);
906 switch (ret)
907 {
908 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
909 vty_out (vty, "Please specify 'bgp multiple-instance' first%s",
910 VTYNL);
911 return CMD_WARNING_CONFIG_FAILED;
912 case BGP_ERR_AS_MISMATCH:
913 vty_out (vty, "BGP is already running; AS is %u%s", as, VTYNL);
914 return CMD_WARNING_CONFIG_FAILED;
915 case BGP_ERR_INSTANCE_MISMATCH:
916 vty_out (vty, "BGP instance name and AS number mismatch%s", VTYNL);
917 vty_out (vty, "BGP instance is already running; AS is %u%s",
918 as, VTYNL);
919 return CMD_WARNING_CONFIG_FAILED;
920 }
921
922 /* Pending: handle when user tries to change a view to vrf n vv. */
923 }
924
925 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
926
927 return CMD_SUCCESS;
928 }
929
930 /* "no router bgp" commands. */
931 DEFUN (no_router_bgp,
932 no_router_bgp_cmd,
933 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
934 NO_STR
935 ROUTER_STR
936 BGP_STR
937 AS_STR
938 BGP_INSTANCE_HELP_STR)
939 {
940 int idx_asn = 3;
941 int idx_vrf = 5;
942 as_t as;
943 struct bgp *bgp;
944 const char *name = NULL;
945
946 // "no router bgp" without an ASN
947 if (argc == 3)
948 {
949 //Pending: Make VRF option available for ASN less config
950 bgp = bgp_get_default();
951
952 if (bgp == NULL)
953 {
954 vty_out (vty, "%% No BGP process is configured%s", VTYNL);
955 return CMD_WARNING_CONFIG_FAILED;
956 }
957
958 if (listcount(bm->bgp) > 1)
959 {
960 vty_out (vty, "%% Multiple BGP processes are configured%s", VTYNL);
961 return CMD_WARNING_CONFIG_FAILED;
962 }
963 }
964 else
965 {
966 as = strtoul(argv[idx_asn]->arg, NULL, 10);
967
968 if (argc > 4)
969 name = argv[idx_vrf]->arg;
970
971 /* Lookup bgp structure. */
972 bgp = bgp_lookup (as, name);
973 if (! bgp)
974 {
975 vty_out (vty, "%% Can't find BGP instance%s", VTYNL);
976 return CMD_WARNING_CONFIG_FAILED;
977 }
978 }
979
980 bgp_delete (bgp);
981
982 return CMD_SUCCESS;
983 }
984
985
986
987 /* BGP router-id. */
988
989 DEFPY (bgp_router_id,
990 bgp_router_id_cmd,
991 "bgp router-id A.B.C.D",
992 BGP_STR
993 "Override configured router identifier\n"
994 "Manually configured router identifier\n")
995 {
996 VTY_DECLVAR_CONTEXT(bgp, bgp);
997 bgp_router_id_static_set (bgp, router_id);
998 return CMD_SUCCESS;
999 }
1000
1001 DEFPY (no_bgp_router_id,
1002 no_bgp_router_id_cmd,
1003 "no bgp router-id [A.B.C.D]",
1004 NO_STR
1005 BGP_STR
1006 "Override configured router identifier\n"
1007 "Manually configured router identifier\n")
1008 {
1009 VTY_DECLVAR_CONTEXT(bgp, bgp);
1010
1011 if (router_id_str)
1012 {
1013 if (! IPV4_ADDR_SAME (&bgp->router_id_static, &router_id))
1014 {
1015 vty_outln (vty, "%% BGP router-id doesn't match");
1016 return CMD_WARNING_CONFIG_FAILED;
1017 }
1018 }
1019
1020 router_id.s_addr = 0;
1021 bgp_router_id_static_set (bgp, router_id);
1022
1023 return CMD_SUCCESS;
1024 }
1025
1026
1027 /* BGP Cluster ID. */
1028 DEFUN (bgp_cluster_id,
1029 bgp_cluster_id_cmd,
1030 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1031 BGP_STR
1032 "Configure Route-Reflector Cluster-id\n"
1033 "Route-Reflector Cluster-id in IP address format\n"
1034 "Route-Reflector Cluster-id as 32 bit quantity\n")
1035 {
1036 VTY_DECLVAR_CONTEXT(bgp, bgp);
1037 int idx_ipv4 = 2;
1038 int ret;
1039 struct in_addr cluster;
1040
1041 ret = inet_aton (argv[idx_ipv4]->arg, &cluster);
1042 if (! ret)
1043 {
1044 vty_out (vty, "%% Malformed bgp cluster identifier%s", VTYNL);
1045 return CMD_WARNING_CONFIG_FAILED;
1046 }
1047
1048 bgp_cluster_id_set (bgp, &cluster);
1049 bgp_clear_star_soft_out (vty, bgp->name);
1050
1051 return CMD_SUCCESS;
1052 }
1053
1054 DEFUN (no_bgp_cluster_id,
1055 no_bgp_cluster_id_cmd,
1056 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1057 NO_STR
1058 BGP_STR
1059 "Configure Route-Reflector Cluster-id\n"
1060 "Route-Reflector Cluster-id in IP address format\n"
1061 "Route-Reflector Cluster-id as 32 bit quantity\n")
1062 {
1063 VTY_DECLVAR_CONTEXT(bgp, bgp);
1064 bgp_cluster_id_unset (bgp);
1065 bgp_clear_star_soft_out (vty, bgp->name);
1066
1067 return CMD_SUCCESS;
1068 }
1069
1070 DEFUN (bgp_confederation_identifier,
1071 bgp_confederation_identifier_cmd,
1072 "bgp confederation identifier (1-4294967295)",
1073 "BGP specific commands\n"
1074 "AS confederation parameters\n"
1075 "AS number\n"
1076 "Set routing domain confederation AS\n")
1077 {
1078 VTY_DECLVAR_CONTEXT(bgp, bgp);
1079 int idx_number = 3;
1080 as_t as;
1081
1082 as = strtoul(argv[idx_number]->arg, NULL, 10);
1083
1084 bgp_confederation_id_set (bgp, as);
1085
1086 return CMD_SUCCESS;
1087 }
1088
1089 DEFUN (no_bgp_confederation_identifier,
1090 no_bgp_confederation_identifier_cmd,
1091 "no bgp confederation identifier [(1-4294967295)]",
1092 NO_STR
1093 "BGP specific commands\n"
1094 "AS confederation parameters\n"
1095 "AS number\n"
1096 "Set routing domain confederation AS\n")
1097 {
1098 VTY_DECLVAR_CONTEXT(bgp, bgp);
1099 bgp_confederation_id_unset (bgp);
1100
1101 return CMD_SUCCESS;
1102 }
1103
1104 DEFUN (bgp_confederation_peers,
1105 bgp_confederation_peers_cmd,
1106 "bgp confederation peers (1-4294967295)...",
1107 "BGP specific commands\n"
1108 "AS confederation parameters\n"
1109 "Peer ASs in BGP confederation\n"
1110 AS_STR)
1111 {
1112 VTY_DECLVAR_CONTEXT(bgp, bgp);
1113 int idx_asn = 3;
1114 as_t as;
1115 int i;
1116
1117 for (i = idx_asn; i < argc; i++)
1118 {
1119 as = strtoul(argv[i]->arg, NULL, 10);
1120
1121 if (bgp->as == as)
1122 {
1123 vty_out (vty, "%% Local member-AS not allowed in confed peer list%s",
1124 VTYNL);
1125 continue;
1126 }
1127
1128 bgp_confederation_peers_add (bgp, as);
1129 }
1130 return CMD_SUCCESS;
1131 }
1132
1133 DEFUN (no_bgp_confederation_peers,
1134 no_bgp_confederation_peers_cmd,
1135 "no bgp confederation peers (1-4294967295)...",
1136 NO_STR
1137 "BGP specific commands\n"
1138 "AS confederation parameters\n"
1139 "Peer ASs in BGP confederation\n"
1140 AS_STR)
1141 {
1142 VTY_DECLVAR_CONTEXT(bgp, bgp);
1143 int idx_asn = 4;
1144 as_t as;
1145 int i;
1146
1147 for (i = idx_asn; i < argc; i++)
1148 {
1149 as = strtoul(argv[i]->arg, NULL, 10);
1150
1151 bgp_confederation_peers_remove (bgp, as);
1152 }
1153 return CMD_SUCCESS;
1154 }
1155
1156 /**
1157 * Central routine for maximum-paths configuration.
1158 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1159 * @set: 1 for setting values, 0 for removing the max-paths config.
1160 */
1161 static int
1162 bgp_maxpaths_config_vty (struct vty *vty, int peer_type, const char *mpaths,
1163 u_int16_t options, int set)
1164 {
1165 VTY_DECLVAR_CONTEXT(bgp, bgp);
1166 u_int16_t maxpaths = 0;
1167 int ret;
1168 afi_t afi;
1169 safi_t safi;
1170
1171 afi = bgp_node_afi (vty);
1172 safi = bgp_node_safi (vty);
1173
1174 if (set)
1175 {
1176 maxpaths = strtol(mpaths, NULL, 10);
1177 if (maxpaths > multipath_num)
1178 {
1179 vty_out (vty,
1180 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1181 maxpaths, multipath_num);
1182 return CMD_WARNING_CONFIG_FAILED;
1183 }
1184 ret = bgp_maximum_paths_set (bgp, afi, safi, peer_type, maxpaths, options);
1185 }
1186 else
1187 ret = bgp_maximum_paths_unset (bgp, afi, safi, peer_type);
1188
1189 if (ret < 0)
1190 {
1191 vty_out (vty,
1192 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u%s",
1193 (set == 1) ? "" : "un",
1194 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1195 maxpaths, afi, safi, VTYNL);
1196 return CMD_WARNING_CONFIG_FAILED;
1197 }
1198
1199 bgp_recalculate_all_bestpaths (bgp);
1200
1201 return CMD_SUCCESS;
1202 }
1203
1204 DEFUN (bgp_maxmed_admin,
1205 bgp_maxmed_admin_cmd,
1206 "bgp max-med administrative ",
1207 BGP_STR
1208 "Advertise routes with max-med\n"
1209 "Administratively applied, for an indefinite period\n")
1210 {
1211 VTY_DECLVAR_CONTEXT(bgp, bgp);
1212
1213 bgp->v_maxmed_admin = 1;
1214 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1215
1216 bgp_maxmed_update(bgp);
1217
1218 return CMD_SUCCESS;
1219 }
1220
1221 DEFUN (bgp_maxmed_admin_medv,
1222 bgp_maxmed_admin_medv_cmd,
1223 "bgp max-med administrative (0-4294967295)",
1224 BGP_STR
1225 "Advertise routes with max-med\n"
1226 "Administratively applied, for an indefinite period\n"
1227 "Max MED value to be used\n")
1228 {
1229 VTY_DECLVAR_CONTEXT(bgp, bgp);
1230 int idx_number = 3;
1231
1232 bgp->v_maxmed_admin = 1;
1233 bgp->maxmed_admin_value = strtoul (argv[idx_number]->arg, NULL, 10);
1234
1235 bgp_maxmed_update(bgp);
1236
1237 return CMD_SUCCESS;
1238 }
1239
1240 DEFUN (no_bgp_maxmed_admin,
1241 no_bgp_maxmed_admin_cmd,
1242 "no bgp max-med administrative [(0-4294967295)]",
1243 NO_STR
1244 BGP_STR
1245 "Advertise routes with max-med\n"
1246 "Administratively applied, for an indefinite period\n"
1247 "Max MED value to be used\n")
1248 {
1249 VTY_DECLVAR_CONTEXT(bgp, bgp);
1250 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1251 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1252 bgp_maxmed_update(bgp);
1253
1254 return CMD_SUCCESS;
1255 }
1256
1257 DEFUN (bgp_maxmed_onstartup,
1258 bgp_maxmed_onstartup_cmd,
1259 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1260 BGP_STR
1261 "Advertise routes with max-med\n"
1262 "Effective on a startup\n"
1263 "Time (seconds) period for max-med\n"
1264 "Max MED value to be used\n")
1265 {
1266 VTY_DECLVAR_CONTEXT(bgp, bgp);
1267 int idx = 0;
1268
1269 argv_find (argv, argc, "(5-86400)", &idx);
1270 bgp->v_maxmed_onstartup = strtoul (argv[idx]->arg, NULL, 10);
1271 if (argv_find (argv, argc, "(0-4294967295)", &idx))
1272 bgp->maxmed_onstartup_value = strtoul (argv[idx]->arg, NULL, 10);
1273 else
1274 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1275
1276 bgp_maxmed_update(bgp);
1277
1278 return CMD_SUCCESS;
1279 }
1280
1281 DEFUN (no_bgp_maxmed_onstartup,
1282 no_bgp_maxmed_onstartup_cmd,
1283 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1284 NO_STR
1285 BGP_STR
1286 "Advertise routes with max-med\n"
1287 "Effective on a startup\n"
1288 "Time (seconds) period for max-med\n"
1289 "Max MED value to be used\n")
1290 {
1291 VTY_DECLVAR_CONTEXT(bgp, bgp);
1292
1293 /* Cancel max-med onstartup if its on */
1294 if (bgp->t_maxmed_onstartup)
1295 {
1296 THREAD_TIMER_OFF (bgp->t_maxmed_onstartup);
1297 bgp->maxmed_onstartup_over = 1;
1298 }
1299
1300 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1301 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1302
1303 bgp_maxmed_update(bgp);
1304
1305 return CMD_SUCCESS;
1306 }
1307
1308 static int
1309 bgp_update_delay_config_vty (struct vty *vty, const char *delay,
1310 const char *wait)
1311 {
1312 VTY_DECLVAR_CONTEXT(bgp, bgp);
1313 u_int16_t update_delay;
1314 u_int16_t establish_wait;
1315
1316 update_delay = strtoul(delay, NULL, 10);
1317
1318 if (!wait) /* update-delay <delay> */
1319 {
1320 bgp->v_update_delay = update_delay;
1321 bgp->v_establish_wait = bgp->v_update_delay;
1322 return CMD_SUCCESS;
1323 }
1324
1325 /* update-delay <delay> <establish-wait> */
1326 establish_wait = atoi (wait);
1327 if (update_delay < establish_wait)
1328 {
1329 vty_out (vty, "%%Failed: update-delay less than the establish-wait!%s",
1330 VTYNL);
1331 return CMD_WARNING_CONFIG_FAILED;
1332 }
1333
1334 bgp->v_update_delay = update_delay;
1335 bgp->v_establish_wait = establish_wait;
1336
1337 return CMD_SUCCESS;
1338 }
1339
1340 static int
1341 bgp_update_delay_deconfig_vty (struct vty *vty)
1342 {
1343 VTY_DECLVAR_CONTEXT(bgp, bgp);
1344
1345 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1346 bgp->v_establish_wait = bgp->v_update_delay;
1347
1348 return CMD_SUCCESS;
1349 }
1350
1351 int
1352 bgp_config_write_update_delay (struct vty *vty, struct bgp *bgp)
1353 {
1354 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF)
1355 {
1356 vty_out (vty, " update-delay %d", bgp->v_update_delay);
1357 if (bgp->v_update_delay != bgp->v_establish_wait)
1358 vty_out (vty, " %d", bgp->v_establish_wait);
1359 vty_out (vty, "%s", VTYNL);
1360 }
1361
1362 return 0;
1363 }
1364
1365
1366 /* Update-delay configuration */
1367 DEFUN (bgp_update_delay,
1368 bgp_update_delay_cmd,
1369 "update-delay (0-3600)",
1370 "Force initial delay for best-path and updates\n"
1371 "Seconds\n")
1372 {
1373 int idx_number = 1;
1374 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1375 }
1376
1377 DEFUN (bgp_update_delay_establish_wait,
1378 bgp_update_delay_establish_wait_cmd,
1379 "update-delay (0-3600) (1-3600)",
1380 "Force initial delay for best-path and updates\n"
1381 "Seconds\n"
1382 "Seconds\n")
1383 {
1384 int idx_number = 1;
1385 int idx_number_2 = 2;
1386 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, argv[idx_number_2]->arg);
1387 }
1388
1389 /* Update-delay deconfiguration */
1390 DEFUN (no_bgp_update_delay,
1391 no_bgp_update_delay_cmd,
1392 "no update-delay [(0-3600) [(1-3600)]]",
1393 NO_STR
1394 "Force initial delay for best-path and updates\n"
1395 "Seconds\n"
1396 "Seconds\n")
1397 {
1398 return bgp_update_delay_deconfig_vty(vty);
1399 }
1400
1401
1402 static int
1403 bgp_wpkt_quanta_config_vty (struct vty *vty, const char *num, char set)
1404 {
1405 VTY_DECLVAR_CONTEXT(bgp, bgp);
1406
1407 if (set)
1408 bgp->wpkt_quanta = strtoul(num, NULL, 10);
1409 else
1410 bgp->wpkt_quanta = BGP_WRITE_PACKET_MAX;
1411
1412 return CMD_SUCCESS;
1413 }
1414
1415 int
1416 bgp_config_write_wpkt_quanta (struct vty *vty, struct bgp *bgp)
1417 {
1418 if (bgp->wpkt_quanta != BGP_WRITE_PACKET_MAX)
1419 vty_out (vty, " write-quanta %d%s",
1420 bgp->wpkt_quanta, VTYNL);
1421
1422 return 0;
1423 }
1424
1425
1426 /* Update-delay configuration */
1427 DEFUN (bgp_wpkt_quanta,
1428 bgp_wpkt_quanta_cmd,
1429 "write-quanta (1-10000)",
1430 "How many packets to write to peer socket per run\n"
1431 "Number of packets\n")
1432 {
1433 int idx_number = 1;
1434 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1435 }
1436
1437 /* Update-delay deconfiguration */
1438 DEFUN (no_bgp_wpkt_quanta,
1439 no_bgp_wpkt_quanta_cmd,
1440 "no write-quanta (1-10000)",
1441 NO_STR
1442 "How many packets to write to peer socket per run\n"
1443 "Number of packets\n")
1444 {
1445 int idx_number = 2;
1446 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1447 }
1448
1449 int
1450 bgp_config_write_coalesce_time (struct vty *vty, struct bgp *bgp)
1451 {
1452 if (bgp->coalesce_time != BGP_DEFAULT_SUBGROUP_COALESCE_TIME)
1453 vty_out (vty, " coalesce-time %u%s",
1454 bgp->coalesce_time, VTYNL);
1455
1456 return 0;
1457 }
1458
1459
1460 DEFUN (bgp_coalesce_time,
1461 bgp_coalesce_time_cmd,
1462 "coalesce-time (0-4294967295)",
1463 "Subgroup coalesce timer\n"
1464 "Subgroup coalesce timer value (in ms)\n")
1465 {
1466 VTY_DECLVAR_CONTEXT(bgp, bgp);
1467
1468 int idx = 0;
1469 argv_find (argv, argc, "(0-4294967295)", &idx);
1470 bgp->coalesce_time = strtoul (argv[idx]->arg, NULL, 10);
1471 return CMD_SUCCESS;
1472 }
1473
1474 DEFUN (no_bgp_coalesce_time,
1475 no_bgp_coalesce_time_cmd,
1476 "no coalesce-time (0-4294967295)",
1477 NO_STR
1478 "Subgroup coalesce timer\n"
1479 "Subgroup coalesce timer value (in ms)\n")
1480 {
1481 VTY_DECLVAR_CONTEXT(bgp, bgp);
1482
1483 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1484 return CMD_SUCCESS;
1485 }
1486
1487 /* Maximum-paths configuration */
1488 DEFUN (bgp_maxpaths,
1489 bgp_maxpaths_cmd,
1490 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1491 "Forward packets over multiple paths\n"
1492 "Number of paths\n")
1493 {
1494 int idx_number = 1;
1495 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, argv[idx_number]->arg, 0, 1);
1496 }
1497
1498 ALIAS_HIDDEN (bgp_maxpaths,
1499 bgp_maxpaths_hidden_cmd,
1500 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1501 "Forward packets over multiple paths\n"
1502 "Number of paths\n")
1503
1504 DEFUN (bgp_maxpaths_ibgp,
1505 bgp_maxpaths_ibgp_cmd,
1506 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1507 "Forward packets over multiple paths\n"
1508 "iBGP-multipath\n"
1509 "Number of paths\n")
1510 {
1511 int idx_number = 2;
1512 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, argv[idx_number]->arg, 0, 1);
1513 }
1514
1515 ALIAS_HIDDEN (bgp_maxpaths_ibgp,
1516 bgp_maxpaths_ibgp_hidden_cmd,
1517 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1518 "Forward packets over multiple paths\n"
1519 "iBGP-multipath\n"
1520 "Number of paths\n")
1521
1522 DEFUN (bgp_maxpaths_ibgp_cluster,
1523 bgp_maxpaths_ibgp_cluster_cmd,
1524 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1525 "Forward packets over multiple paths\n"
1526 "iBGP-multipath\n"
1527 "Number of paths\n"
1528 "Match the cluster length\n")
1529 {
1530 int idx_number = 2;
1531 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1532 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1533 }
1534
1535 ALIAS_HIDDEN (bgp_maxpaths_ibgp_cluster,
1536 bgp_maxpaths_ibgp_cluster_hidden_cmd,
1537 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1538 "Forward packets over multiple paths\n"
1539 "iBGP-multipath\n"
1540 "Number of paths\n"
1541 "Match the cluster length\n")
1542
1543 DEFUN (no_bgp_maxpaths,
1544 no_bgp_maxpaths_cmd,
1545 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1546 NO_STR
1547 "Forward packets over multiple paths\n"
1548 "Number of paths\n")
1549 {
1550 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1551 }
1552
1553 ALIAS_HIDDEN (no_bgp_maxpaths,
1554 no_bgp_maxpaths_hidden_cmd,
1555 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1556 NO_STR
1557 "Forward packets over multiple paths\n"
1558 "Number of paths\n")
1559
1560 DEFUN (no_bgp_maxpaths_ibgp,
1561 no_bgp_maxpaths_ibgp_cmd,
1562 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1563 NO_STR
1564 "Forward packets over multiple paths\n"
1565 "iBGP-multipath\n"
1566 "Number of paths\n"
1567 "Match the cluster length\n")
1568 {
1569 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1570 }
1571
1572 ALIAS_HIDDEN (no_bgp_maxpaths_ibgp,
1573 no_bgp_maxpaths_ibgp_hidden_cmd,
1574 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1575 NO_STR
1576 "Forward packets over multiple paths\n"
1577 "iBGP-multipath\n"
1578 "Number of paths\n"
1579 "Match the cluster length\n")
1580
1581 int
1582 bgp_config_write_maxpaths (struct vty *vty, struct bgp *bgp, afi_t afi,
1583 safi_t safi, int *write)
1584 {
1585 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM)
1586 {
1587 bgp_config_write_family_header (vty, afi, safi, write);
1588 vty_out (vty, " maximum-paths %d%s",
1589 bgp->maxpaths[afi][safi].maxpaths_ebgp, VTYNL);
1590 }
1591
1592 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM)
1593 {
1594 bgp_config_write_family_header (vty, afi, safi, write);
1595 vty_out (vty, " maximum-paths ibgp %d",
1596 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1597 if (CHECK_FLAG (bgp->maxpaths[afi][safi].ibgp_flags,
1598 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1599 vty_out (vty, " equal-cluster-length");
1600 vty_out (vty, "%s", VTYNL);
1601 }
1602
1603 return 0;
1604 }
1605
1606 /* BGP timers. */
1607
1608 DEFUN (bgp_timers,
1609 bgp_timers_cmd,
1610 "timers bgp (0-65535) (0-65535)",
1611 "Adjust routing timers\n"
1612 "BGP timers\n"
1613 "Keepalive interval\n"
1614 "Holdtime\n")
1615 {
1616 VTY_DECLVAR_CONTEXT(bgp, bgp);
1617 int idx_number = 2;
1618 int idx_number_2 = 3;
1619 unsigned long keepalive = 0;
1620 unsigned long holdtime = 0;
1621
1622 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1623 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1624
1625 /* Holdtime value check. */
1626 if (holdtime < 3 && holdtime != 0)
1627 {
1628 vty_out (vty, "%% hold time value must be either 0 or greater than 3%s",
1629 VTYNL);
1630 return CMD_WARNING_CONFIG_FAILED;
1631 }
1632
1633 bgp_timers_set (bgp, keepalive, holdtime);
1634
1635 return CMD_SUCCESS;
1636 }
1637
1638 DEFUN (no_bgp_timers,
1639 no_bgp_timers_cmd,
1640 "no timers bgp [(0-65535) (0-65535)]",
1641 NO_STR
1642 "Adjust routing timers\n"
1643 "BGP timers\n"
1644 "Keepalive interval\n"
1645 "Holdtime\n")
1646 {
1647 VTY_DECLVAR_CONTEXT(bgp, bgp);
1648 bgp_timers_unset (bgp);
1649
1650 return CMD_SUCCESS;
1651 }
1652
1653
1654 DEFUN (bgp_client_to_client_reflection,
1655 bgp_client_to_client_reflection_cmd,
1656 "bgp client-to-client reflection",
1657 "BGP specific commands\n"
1658 "Configure client to client route reflection\n"
1659 "reflection of routes allowed\n")
1660 {
1661 VTY_DECLVAR_CONTEXT(bgp, bgp);
1662 bgp_flag_unset (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1663 bgp_clear_star_soft_out (vty, bgp->name);
1664
1665 return CMD_SUCCESS;
1666 }
1667
1668 DEFUN (no_bgp_client_to_client_reflection,
1669 no_bgp_client_to_client_reflection_cmd,
1670 "no bgp client-to-client reflection",
1671 NO_STR
1672 "BGP specific commands\n"
1673 "Configure client to client route reflection\n"
1674 "reflection of routes allowed\n")
1675 {
1676 VTY_DECLVAR_CONTEXT(bgp, bgp);
1677 bgp_flag_set (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1678 bgp_clear_star_soft_out (vty, bgp->name);
1679
1680 return CMD_SUCCESS;
1681 }
1682
1683 /* "bgp always-compare-med" configuration. */
1684 DEFUN (bgp_always_compare_med,
1685 bgp_always_compare_med_cmd,
1686 "bgp always-compare-med",
1687 "BGP specific commands\n"
1688 "Allow comparing MED from different neighbors\n")
1689 {
1690 VTY_DECLVAR_CONTEXT(bgp, bgp);
1691 bgp_flag_set (bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1692 bgp_recalculate_all_bestpaths (bgp);
1693
1694 return CMD_SUCCESS;
1695 }
1696
1697 DEFUN (no_bgp_always_compare_med,
1698 no_bgp_always_compare_med_cmd,
1699 "no bgp always-compare-med",
1700 NO_STR
1701 "BGP specific commands\n"
1702 "Allow comparing MED from different neighbors\n")
1703 {
1704 VTY_DECLVAR_CONTEXT(bgp, bgp);
1705 bgp_flag_unset (bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1706 bgp_recalculate_all_bestpaths (bgp);
1707
1708 return CMD_SUCCESS;
1709 }
1710
1711 /* "bgp deterministic-med" configuration. */
1712 DEFUN (bgp_deterministic_med,
1713 bgp_deterministic_med_cmd,
1714 "bgp deterministic-med",
1715 "BGP specific commands\n"
1716 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1717 {
1718 VTY_DECLVAR_CONTEXT(bgp, bgp);
1719
1720 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED))
1721 {
1722 bgp_flag_set (bgp, BGP_FLAG_DETERMINISTIC_MED);
1723 bgp_recalculate_all_bestpaths (bgp);
1724 }
1725
1726 return CMD_SUCCESS;
1727 }
1728
1729 DEFUN (no_bgp_deterministic_med,
1730 no_bgp_deterministic_med_cmd,
1731 "no bgp deterministic-med",
1732 NO_STR
1733 "BGP specific commands\n"
1734 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1735 {
1736 VTY_DECLVAR_CONTEXT(bgp, bgp);
1737 int bestpath_per_as_used;
1738 afi_t afi;
1739 safi_t safi;
1740 struct peer *peer;
1741 struct listnode *node, *nnode;
1742
1743 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED))
1744 {
1745 bestpath_per_as_used = 0;
1746
1747 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1748 {
1749 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1750 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1751 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
1752 {
1753 bestpath_per_as_used = 1;
1754 break;
1755 }
1756
1757 if (bestpath_per_as_used)
1758 break;
1759 }
1760
1761 if (bestpath_per_as_used)
1762 {
1763 vty_out (vty, "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use%s",
1764 VTYNL);
1765 return CMD_WARNING_CONFIG_FAILED;
1766 }
1767 else
1768 {
1769 bgp_flag_unset (bgp, BGP_FLAG_DETERMINISTIC_MED);
1770 bgp_recalculate_all_bestpaths (bgp);
1771 }
1772 }
1773
1774 return CMD_SUCCESS;
1775 }
1776
1777 /* "bgp graceful-restart" configuration. */
1778 DEFUN (bgp_graceful_restart,
1779 bgp_graceful_restart_cmd,
1780 "bgp graceful-restart",
1781 "BGP specific commands\n"
1782 "Graceful restart capability parameters\n")
1783 {
1784 VTY_DECLVAR_CONTEXT(bgp, bgp);
1785 bgp_flag_set (bgp, BGP_FLAG_GRACEFUL_RESTART);
1786 return CMD_SUCCESS;
1787 }
1788
1789 DEFUN (no_bgp_graceful_restart,
1790 no_bgp_graceful_restart_cmd,
1791 "no bgp graceful-restart",
1792 NO_STR
1793 "BGP specific commands\n"
1794 "Graceful restart capability parameters\n")
1795 {
1796 VTY_DECLVAR_CONTEXT(bgp, bgp);
1797 bgp_flag_unset (bgp, BGP_FLAG_GRACEFUL_RESTART);
1798 return CMD_SUCCESS;
1799 }
1800
1801 DEFUN (bgp_graceful_restart_stalepath_time,
1802 bgp_graceful_restart_stalepath_time_cmd,
1803 "bgp graceful-restart stalepath-time (1-3600)",
1804 "BGP specific commands\n"
1805 "Graceful restart capability parameters\n"
1806 "Set the max time to hold onto restarting peer's stale paths\n"
1807 "Delay value (seconds)\n")
1808 {
1809 VTY_DECLVAR_CONTEXT(bgp, bgp);
1810 int idx_number = 3;
1811 u_int32_t stalepath;
1812
1813 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1814 bgp->stalepath_time = stalepath;
1815 return CMD_SUCCESS;
1816 }
1817
1818 DEFUN (bgp_graceful_restart_restart_time,
1819 bgp_graceful_restart_restart_time_cmd,
1820 "bgp graceful-restart restart-time (1-3600)",
1821 "BGP specific commands\n"
1822 "Graceful restart capability parameters\n"
1823 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1824 "Delay value (seconds)\n")
1825 {
1826 VTY_DECLVAR_CONTEXT(bgp, bgp);
1827 int idx_number = 3;
1828 u_int32_t restart;
1829
1830 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1831 bgp->restart_time = restart;
1832 return CMD_SUCCESS;
1833 }
1834
1835 DEFUN (no_bgp_graceful_restart_stalepath_time,
1836 no_bgp_graceful_restart_stalepath_time_cmd,
1837 "no bgp graceful-restart stalepath-time [(1-3600)]",
1838 NO_STR
1839 "BGP specific commands\n"
1840 "Graceful restart capability parameters\n"
1841 "Set the max time to hold onto restarting peer's stale paths\n"
1842 "Delay value (seconds)\n")
1843 {
1844 VTY_DECLVAR_CONTEXT(bgp, bgp);
1845
1846 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1847 return CMD_SUCCESS;
1848 }
1849
1850 DEFUN (no_bgp_graceful_restart_restart_time,
1851 no_bgp_graceful_restart_restart_time_cmd,
1852 "no bgp graceful-restart restart-time [(1-3600)]",
1853 NO_STR
1854 "BGP specific commands\n"
1855 "Graceful restart capability parameters\n"
1856 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1857 "Delay value (seconds)\n")
1858 {
1859 VTY_DECLVAR_CONTEXT(bgp, bgp);
1860
1861 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1862 return CMD_SUCCESS;
1863 }
1864
1865 DEFUN (bgp_graceful_restart_preserve_fw,
1866 bgp_graceful_restart_preserve_fw_cmd,
1867 "bgp graceful-restart preserve-fw-state",
1868 "BGP specific commands\n"
1869 "Graceful restart capability parameters\n"
1870 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1871 {
1872 VTY_DECLVAR_CONTEXT(bgp, bgp);
1873 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1874 return CMD_SUCCESS;
1875 }
1876
1877 DEFUN (no_bgp_graceful_restart_preserve_fw,
1878 no_bgp_graceful_restart_preserve_fw_cmd,
1879 "no bgp graceful-restart preserve-fw-state",
1880 NO_STR
1881 "BGP specific commands\n"
1882 "Graceful restart capability parameters\n"
1883 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1884 {
1885 VTY_DECLVAR_CONTEXT(bgp, bgp);
1886 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1887 return CMD_SUCCESS;
1888 }
1889
1890 /* "bgp fast-external-failover" configuration. */
1891 DEFUN (bgp_fast_external_failover,
1892 bgp_fast_external_failover_cmd,
1893 "bgp fast-external-failover",
1894 BGP_STR
1895 "Immediately reset session if a link to a directly connected external peer goes down\n")
1896 {
1897 VTY_DECLVAR_CONTEXT(bgp, bgp);
1898 bgp_flag_unset (bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1899 return CMD_SUCCESS;
1900 }
1901
1902 DEFUN (no_bgp_fast_external_failover,
1903 no_bgp_fast_external_failover_cmd,
1904 "no bgp fast-external-failover",
1905 NO_STR
1906 BGP_STR
1907 "Immediately reset session if a link to a directly connected external peer goes down\n")
1908 {
1909 VTY_DECLVAR_CONTEXT(bgp, bgp);
1910 bgp_flag_set (bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1911 return CMD_SUCCESS;
1912 }
1913
1914 /* "bgp enforce-first-as" configuration. */
1915 DEFUN (bgp_enforce_first_as,
1916 bgp_enforce_first_as_cmd,
1917 "bgp enforce-first-as",
1918 BGP_STR
1919 "Enforce the first AS for EBGP routes\n")
1920 {
1921 VTY_DECLVAR_CONTEXT(bgp, bgp);
1922 bgp_flag_set (bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1923 bgp_clear_star_soft_in (vty, bgp->name);
1924
1925 return CMD_SUCCESS;
1926 }
1927
1928 DEFUN (no_bgp_enforce_first_as,
1929 no_bgp_enforce_first_as_cmd,
1930 "no bgp enforce-first-as",
1931 NO_STR
1932 BGP_STR
1933 "Enforce the first AS for EBGP routes\n")
1934 {
1935 VTY_DECLVAR_CONTEXT(bgp, bgp);
1936 bgp_flag_unset (bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1937 bgp_clear_star_soft_in (vty, bgp->name);
1938
1939 return CMD_SUCCESS;
1940 }
1941
1942 /* "bgp bestpath compare-routerid" configuration. */
1943 DEFUN (bgp_bestpath_compare_router_id,
1944 bgp_bestpath_compare_router_id_cmd,
1945 "bgp bestpath compare-routerid",
1946 "BGP specific commands\n"
1947 "Change the default bestpath selection\n"
1948 "Compare router-id for identical EBGP paths\n")
1949 {
1950 VTY_DECLVAR_CONTEXT(bgp, bgp);
1951 bgp_flag_set (bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1952 bgp_recalculate_all_bestpaths (bgp);
1953
1954 return CMD_SUCCESS;
1955 }
1956
1957 DEFUN (no_bgp_bestpath_compare_router_id,
1958 no_bgp_bestpath_compare_router_id_cmd,
1959 "no bgp bestpath compare-routerid",
1960 NO_STR
1961 "BGP specific commands\n"
1962 "Change the default bestpath selection\n"
1963 "Compare router-id for identical EBGP paths\n")
1964 {
1965 VTY_DECLVAR_CONTEXT(bgp, bgp);
1966 bgp_flag_unset (bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1967 bgp_recalculate_all_bestpaths (bgp);
1968
1969 return CMD_SUCCESS;
1970 }
1971
1972 /* "bgp bestpath as-path ignore" configuration. */
1973 DEFUN (bgp_bestpath_aspath_ignore,
1974 bgp_bestpath_aspath_ignore_cmd,
1975 "bgp bestpath as-path ignore",
1976 "BGP specific commands\n"
1977 "Change the default bestpath selection\n"
1978 "AS-path attribute\n"
1979 "Ignore as-path length in selecting a route\n")
1980 {
1981 VTY_DECLVAR_CONTEXT(bgp, bgp);
1982 bgp_flag_set (bgp, BGP_FLAG_ASPATH_IGNORE);
1983 bgp_recalculate_all_bestpaths (bgp);
1984
1985 return CMD_SUCCESS;
1986 }
1987
1988 DEFUN (no_bgp_bestpath_aspath_ignore,
1989 no_bgp_bestpath_aspath_ignore_cmd,
1990 "no bgp bestpath as-path ignore",
1991 NO_STR
1992 "BGP specific commands\n"
1993 "Change the default bestpath selection\n"
1994 "AS-path attribute\n"
1995 "Ignore as-path length in selecting a route\n")
1996 {
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998 bgp_flag_unset (bgp, BGP_FLAG_ASPATH_IGNORE);
1999 bgp_recalculate_all_bestpaths (bgp);
2000
2001 return CMD_SUCCESS;
2002 }
2003
2004 /* "bgp bestpath as-path confed" configuration. */
2005 DEFUN (bgp_bestpath_aspath_confed,
2006 bgp_bestpath_aspath_confed_cmd,
2007 "bgp bestpath as-path confed",
2008 "BGP specific commands\n"
2009 "Change the default bestpath selection\n"
2010 "AS-path attribute\n"
2011 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2012 {
2013 VTY_DECLVAR_CONTEXT(bgp, bgp);
2014 bgp_flag_set (bgp, BGP_FLAG_ASPATH_CONFED);
2015 bgp_recalculate_all_bestpaths (bgp);
2016
2017 return CMD_SUCCESS;
2018 }
2019
2020 DEFUN (no_bgp_bestpath_aspath_confed,
2021 no_bgp_bestpath_aspath_confed_cmd,
2022 "no bgp bestpath as-path confed",
2023 NO_STR
2024 "BGP specific commands\n"
2025 "Change the default bestpath selection\n"
2026 "AS-path attribute\n"
2027 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2028 {
2029 VTY_DECLVAR_CONTEXT(bgp, bgp);
2030 bgp_flag_unset (bgp, BGP_FLAG_ASPATH_CONFED);
2031 bgp_recalculate_all_bestpaths (bgp);
2032
2033 return CMD_SUCCESS;
2034 }
2035
2036 /* "bgp bestpath as-path multipath-relax" configuration. */
2037 DEFUN (bgp_bestpath_aspath_multipath_relax,
2038 bgp_bestpath_aspath_multipath_relax_cmd,
2039 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2040 "BGP specific commands\n"
2041 "Change the default bestpath selection\n"
2042 "AS-path attribute\n"
2043 "Allow load sharing across routes that have different AS paths (but same length)\n"
2044 "Generate an AS_SET\n"
2045 "Do not generate an AS_SET\n")
2046 {
2047 VTY_DECLVAR_CONTEXT(bgp, bgp);
2048 int idx = 0;
2049 bgp_flag_set (bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2050
2051 /* no-as-set is now the default behavior so we can silently
2052 * ignore it */
2053 if (argv_find (argv, argc, "as-set", &idx))
2054 bgp_flag_set (bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2055 else
2056 bgp_flag_unset (bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET) ;
2057
2058 bgp_recalculate_all_bestpaths (bgp);
2059
2060 return CMD_SUCCESS;
2061 }
2062
2063 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2064 no_bgp_bestpath_aspath_multipath_relax_cmd,
2065 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2066 NO_STR
2067 "BGP specific commands\n"
2068 "Change the default bestpath selection\n"
2069 "AS-path attribute\n"
2070 "Allow load sharing across routes that have different AS paths (but same length)\n"
2071 "Generate an AS_SET\n"
2072 "Do not generate an AS_SET\n")
2073 {
2074 VTY_DECLVAR_CONTEXT(bgp, bgp);
2075 bgp_flag_unset (bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2076 bgp_flag_unset (bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2077 bgp_recalculate_all_bestpaths (bgp);
2078
2079 return CMD_SUCCESS;
2080 }
2081
2082 /* "bgp log-neighbor-changes" configuration. */
2083 DEFUN (bgp_log_neighbor_changes,
2084 bgp_log_neighbor_changes_cmd,
2085 "bgp log-neighbor-changes",
2086 "BGP specific commands\n"
2087 "Log neighbor up/down and reset reason\n")
2088 {
2089 VTY_DECLVAR_CONTEXT(bgp, bgp);
2090 bgp_flag_set (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2091 return CMD_SUCCESS;
2092 }
2093
2094 DEFUN (no_bgp_log_neighbor_changes,
2095 no_bgp_log_neighbor_changes_cmd,
2096 "no bgp log-neighbor-changes",
2097 NO_STR
2098 "BGP specific commands\n"
2099 "Log neighbor up/down and reset reason\n")
2100 {
2101 VTY_DECLVAR_CONTEXT(bgp, bgp);
2102 bgp_flag_unset (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2103 return CMD_SUCCESS;
2104 }
2105
2106 /* "bgp bestpath med" configuration. */
2107 DEFUN (bgp_bestpath_med,
2108 bgp_bestpath_med_cmd,
2109 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2110 "BGP specific commands\n"
2111 "Change the default bestpath selection\n"
2112 "MED attribute\n"
2113 "Compare MED among confederation paths\n"
2114 "Treat missing MED as the least preferred one\n"
2115 "Treat missing MED as the least preferred one\n"
2116 "Compare MED among confederation paths\n")
2117 {
2118 VTY_DECLVAR_CONTEXT(bgp, bgp);
2119
2120 int idx = 0;
2121 if (argv_find (argv, argc, "confed", &idx))
2122 bgp_flag_set (bgp, BGP_FLAG_MED_CONFED);
2123 idx = 0;
2124 if (argv_find (argv, argc, "missing-as-worst", &idx))
2125 bgp_flag_set (bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2126
2127 bgp_recalculate_all_bestpaths (bgp);
2128
2129 return CMD_SUCCESS;
2130 }
2131
2132 DEFUN (no_bgp_bestpath_med,
2133 no_bgp_bestpath_med_cmd,
2134 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2135 NO_STR
2136 "BGP specific commands\n"
2137 "Change the default bestpath selection\n"
2138 "MED attribute\n"
2139 "Compare MED among confederation paths\n"
2140 "Treat missing MED as the least preferred one\n"
2141 "Treat missing MED as the least preferred one\n"
2142 "Compare MED among confederation paths\n")
2143 {
2144 VTY_DECLVAR_CONTEXT(bgp, bgp);
2145
2146 int idx = 0;
2147 if (argv_find (argv, argc, "confed", &idx))
2148 bgp_flag_unset (bgp, BGP_FLAG_MED_CONFED);
2149 idx = 0;
2150 if (argv_find (argv, argc, "missing-as-worst", &idx))
2151 bgp_flag_unset (bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2152
2153 bgp_recalculate_all_bestpaths (bgp);
2154
2155 return CMD_SUCCESS;
2156 }
2157
2158 /* "no bgp default ipv4-unicast". */
2159 DEFUN (no_bgp_default_ipv4_unicast,
2160 no_bgp_default_ipv4_unicast_cmd,
2161 "no bgp default ipv4-unicast",
2162 NO_STR
2163 "BGP specific commands\n"
2164 "Configure BGP defaults\n"
2165 "Activate ipv4-unicast for a peer by default\n")
2166 {
2167 VTY_DECLVAR_CONTEXT(bgp, bgp);
2168 bgp_flag_set (bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2169 return CMD_SUCCESS;
2170 }
2171
2172 DEFUN (bgp_default_ipv4_unicast,
2173 bgp_default_ipv4_unicast_cmd,
2174 "bgp default ipv4-unicast",
2175 "BGP specific commands\n"
2176 "Configure BGP defaults\n"
2177 "Activate ipv4-unicast for a peer by default\n")
2178 {
2179 VTY_DECLVAR_CONTEXT(bgp, bgp);
2180 bgp_flag_unset (bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2181 return CMD_SUCCESS;
2182 }
2183
2184 /* Display hostname in certain command outputs */
2185 DEFUN (bgp_default_show_hostname,
2186 bgp_default_show_hostname_cmd,
2187 "bgp default show-hostname",
2188 "BGP specific commands\n"
2189 "Configure BGP defaults\n"
2190 "Show hostname in certain command ouputs\n")
2191 {
2192 VTY_DECLVAR_CONTEXT(bgp, bgp);
2193 bgp_flag_set (bgp, BGP_FLAG_SHOW_HOSTNAME);
2194 return CMD_SUCCESS;
2195 }
2196
2197 DEFUN (no_bgp_default_show_hostname,
2198 no_bgp_default_show_hostname_cmd,
2199 "no bgp default show-hostname",
2200 NO_STR
2201 "BGP specific commands\n"
2202 "Configure BGP defaults\n"
2203 "Show hostname in certain command ouputs\n")
2204 {
2205 VTY_DECLVAR_CONTEXT(bgp, bgp);
2206 bgp_flag_unset (bgp, BGP_FLAG_SHOW_HOSTNAME);
2207 return CMD_SUCCESS;
2208 }
2209
2210 /* "bgp network import-check" configuration. */
2211 DEFUN (bgp_network_import_check,
2212 bgp_network_import_check_cmd,
2213 "bgp network import-check",
2214 "BGP specific commands\n"
2215 "BGP network command\n"
2216 "Check BGP network route exists in IGP\n")
2217 {
2218 VTY_DECLVAR_CONTEXT(bgp, bgp);
2219 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK))
2220 {
2221 bgp_flag_set (bgp, BGP_FLAG_IMPORT_CHECK);
2222 bgp_static_redo_import_check(bgp);
2223 }
2224
2225 return CMD_SUCCESS;
2226 }
2227
2228 ALIAS_HIDDEN (bgp_network_import_check,
2229 bgp_network_import_check_exact_cmd,
2230 "bgp network import-check exact",
2231 "BGP specific commands\n"
2232 "BGP network command\n"
2233 "Check BGP network route exists in IGP\n"
2234 "Match route precisely\n")
2235
2236 DEFUN (no_bgp_network_import_check,
2237 no_bgp_network_import_check_cmd,
2238 "no bgp network import-check",
2239 NO_STR
2240 "BGP specific commands\n"
2241 "BGP network command\n"
2242 "Check BGP network route exists in IGP\n")
2243 {
2244 VTY_DECLVAR_CONTEXT(bgp, bgp);
2245 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK))
2246 {
2247 bgp_flag_unset (bgp, BGP_FLAG_IMPORT_CHECK);
2248 bgp_static_redo_import_check(bgp);
2249 }
2250
2251 return CMD_SUCCESS;
2252 }
2253
2254 DEFUN (bgp_default_local_preference,
2255 bgp_default_local_preference_cmd,
2256 "bgp default local-preference (0-4294967295)",
2257 "BGP specific commands\n"
2258 "Configure BGP defaults\n"
2259 "local preference (higher=more preferred)\n"
2260 "Configure default local preference value\n")
2261 {
2262 VTY_DECLVAR_CONTEXT(bgp, bgp);
2263 int idx_number = 3;
2264 u_int32_t local_pref;
2265
2266 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2267
2268 bgp_default_local_preference_set (bgp, local_pref);
2269 bgp_clear_star_soft_in (vty, bgp->name);
2270
2271 return CMD_SUCCESS;
2272 }
2273
2274 DEFUN (no_bgp_default_local_preference,
2275 no_bgp_default_local_preference_cmd,
2276 "no bgp default local-preference [(0-4294967295)]",
2277 NO_STR
2278 "BGP specific commands\n"
2279 "Configure BGP defaults\n"
2280 "local preference (higher=more preferred)\n"
2281 "Configure default local preference value\n")
2282 {
2283 VTY_DECLVAR_CONTEXT(bgp, bgp);
2284 bgp_default_local_preference_unset (bgp);
2285 bgp_clear_star_soft_in (vty, bgp->name);
2286
2287 return CMD_SUCCESS;
2288 }
2289
2290
2291 DEFUN (bgp_default_subgroup_pkt_queue_max,
2292 bgp_default_subgroup_pkt_queue_max_cmd,
2293 "bgp default subgroup-pkt-queue-max (20-100)",
2294 "BGP specific commands\n"
2295 "Configure BGP defaults\n"
2296 "subgroup-pkt-queue-max\n"
2297 "Configure subgroup packet queue max\n")
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 int idx_number = 3;
2301 u_int32_t max_size;
2302
2303 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2304
2305 bgp_default_subgroup_pkt_queue_max_set (bgp, max_size);
2306
2307 return CMD_SUCCESS;
2308 }
2309
2310 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2311 no_bgp_default_subgroup_pkt_queue_max_cmd,
2312 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2313 NO_STR
2314 "BGP specific commands\n"
2315 "Configure BGP defaults\n"
2316 "subgroup-pkt-queue-max\n"
2317 "Configure subgroup packet queue max\n")
2318 {
2319 VTY_DECLVAR_CONTEXT(bgp, bgp);
2320 bgp_default_subgroup_pkt_queue_max_unset (bgp);
2321 return CMD_SUCCESS;
2322 }
2323
2324
2325 DEFUN (bgp_rr_allow_outbound_policy,
2326 bgp_rr_allow_outbound_policy_cmd,
2327 "bgp route-reflector allow-outbound-policy",
2328 "BGP specific commands\n"
2329 "Allow modifications made by out route-map\n"
2330 "on ibgp neighbors\n")
2331 {
2332 VTY_DECLVAR_CONTEXT(bgp, bgp);
2333
2334 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
2335 {
2336 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2337 update_group_announce_rrclients(bgp);
2338 bgp_clear_star_soft_out (vty, bgp->name);
2339 }
2340
2341 return CMD_SUCCESS;
2342 }
2343
2344 DEFUN (no_bgp_rr_allow_outbound_policy,
2345 no_bgp_rr_allow_outbound_policy_cmd,
2346 "no bgp route-reflector allow-outbound-policy",
2347 NO_STR
2348 "BGP specific commands\n"
2349 "Allow modifications made by out route-map\n"
2350 "on ibgp neighbors\n")
2351 {
2352 VTY_DECLVAR_CONTEXT(bgp, bgp);
2353
2354 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
2355 {
2356 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2357 update_group_announce_rrclients(bgp);
2358 bgp_clear_star_soft_out (vty, bgp->name);
2359 }
2360
2361 return CMD_SUCCESS;
2362 }
2363
2364 DEFUN (bgp_listen_limit,
2365 bgp_listen_limit_cmd,
2366 "bgp listen limit (1-5000)",
2367 "BGP specific commands\n"
2368 "Configure BGP defaults\n"
2369 "maximum number of BGP Dynamic Neighbors that can be created\n"
2370 "Configure Dynamic Neighbors listen limit value\n")
2371 {
2372 VTY_DECLVAR_CONTEXT(bgp, bgp);
2373 int idx_number = 3;
2374 int listen_limit;
2375
2376 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2377
2378 bgp_listen_limit_set (bgp, listen_limit);
2379
2380 return CMD_SUCCESS;
2381 }
2382
2383 DEFUN (no_bgp_listen_limit,
2384 no_bgp_listen_limit_cmd,
2385 "no bgp listen limit [(1-5000)]",
2386 "BGP specific commands\n"
2387 "Configure BGP defaults\n"
2388 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2389 "Configure Dynamic Neighbors listen limit value to default\n"
2390 "Configure Dynamic Neighbors listen limit value\n")
2391 {
2392 VTY_DECLVAR_CONTEXT(bgp, bgp);
2393 bgp_listen_limit_unset (bgp);
2394 return CMD_SUCCESS;
2395 }
2396
2397
2398 /*
2399 * Check if this listen range is already configured. Check for exact
2400 * match or overlap based on input.
2401 */
2402 static struct peer_group *
2403 listen_range_exists (struct bgp *bgp, struct prefix *range, int exact)
2404 {
2405 struct listnode *node, *nnode;
2406 struct listnode *node1, *nnode1;
2407 struct peer_group *group;
2408 struct prefix *lr;
2409 afi_t afi;
2410 int match;
2411
2412 afi = family2afi(range->family);
2413 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
2414 {
2415 for (ALL_LIST_ELEMENTS (group->listen_range[afi], node1,
2416 nnode1, lr))
2417 {
2418 if (exact)
2419 match = prefix_same (range, lr);
2420 else
2421 match = (prefix_match (range, lr) || prefix_match (lr, range));
2422 if (match)
2423 return group;
2424 }
2425 }
2426
2427 return NULL;
2428 }
2429
2430 DEFUN (bgp_listen_range,
2431 bgp_listen_range_cmd,
2432 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2433 "BGP specific commands\n"
2434 "Configure BGP dynamic neighbors listen range\n"
2435 "Configure BGP dynamic neighbors listen range\n"
2436 NEIGHBOR_ADDR_STR
2437 "Member of the peer-group\n"
2438 "Peer-group name\n")
2439 {
2440 VTY_DECLVAR_CONTEXT(bgp, bgp);
2441 struct prefix range;
2442 struct peer_group *group, *existing_group;
2443 afi_t afi;
2444 int ret;
2445 int idx = 0;
2446
2447 argv_find (argv, argc, "A.B.C.D/M", &idx);
2448 argv_find (argv, argc, "X:X::X:X/M", &idx);
2449 char *prefix = argv[idx]->arg;
2450 argv_find (argv, argc, "WORD", &idx);
2451 char *peergroup = argv[idx]->arg;
2452
2453 /* Convert IP prefix string to struct prefix. */
2454 ret = str2prefix (prefix, &range);
2455 if (! ret)
2456 {
2457 vty_out (vty, "%% Malformed listen range%s", VTYNL);
2458 return CMD_WARNING_CONFIG_FAILED;
2459 }
2460
2461 afi = family2afi(range.family);
2462
2463 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&range.u.prefix6))
2464 {
2465 vty_out (vty, "%% Malformed listen range (link-local address)%s",
2466 VTYNL);
2467 return CMD_WARNING_CONFIG_FAILED;
2468 }
2469
2470 apply_mask (&range);
2471
2472 /* Check if same listen range is already configured. */
2473 existing_group = listen_range_exists (bgp, &range, 1);
2474 if (existing_group)
2475 {
2476 if (strcmp (existing_group->name, peergroup) == 0)
2477 return CMD_SUCCESS;
2478 else
2479 {
2480 vty_out (vty, "%% Same listen range is attached to peer-group %s%s",
2481 existing_group->name, VTYNL);
2482 return CMD_WARNING_CONFIG_FAILED;
2483 }
2484 }
2485
2486 /* Check if an overlapping listen range exists. */
2487 if (listen_range_exists (bgp, &range, 0))
2488 {
2489 vty_out (vty, "%% Listen range overlaps with existing listen range%s",
2490 VTYNL);
2491 return CMD_WARNING_CONFIG_FAILED;
2492 }
2493
2494 group = peer_group_lookup (bgp, peergroup);
2495 if (! group)
2496 {
2497 vty_out (vty, "%% Configure the peer-group first%s", VTYNL);
2498 return CMD_WARNING_CONFIG_FAILED;
2499 }
2500
2501 ret = peer_group_listen_range_add(group, &range);
2502 return bgp_vty_return (vty, ret);
2503 }
2504
2505 DEFUN (no_bgp_listen_range,
2506 no_bgp_listen_range_cmd,
2507 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2508 NO_STR
2509 "BGP specific commands\n"
2510 "Unconfigure BGP dynamic neighbors listen range\n"
2511 "Unconfigure BGP dynamic neighbors listen range\n"
2512 NEIGHBOR_ADDR_STR
2513 "Member of the peer-group\n"
2514 "Peer-group name\n")
2515 {
2516 VTY_DECLVAR_CONTEXT(bgp, bgp);
2517 struct prefix range;
2518 struct peer_group *group;
2519 afi_t afi;
2520 int ret;
2521 int idx = 0;
2522
2523 argv_find (argv, argc, "A.B.C.D/M", &idx);
2524 argv_find (argv, argc, "X:X::X:X/M", &idx);
2525 char *prefix = argv[idx]->arg;
2526 argv_find (argv, argc, "WORD", &idx);
2527 char *peergroup = argv[idx]->arg;
2528
2529 /* Convert IP prefix string to struct prefix. */
2530 ret = str2prefix (prefix, &range);
2531 if (! ret)
2532 {
2533 vty_out (vty, "%% Malformed listen range%s", VTYNL);
2534 return CMD_WARNING_CONFIG_FAILED;
2535 }
2536
2537 afi = family2afi(range.family);
2538
2539 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&range.u.prefix6))
2540 {
2541 vty_out (vty, "%% Malformed listen range (link-local address)%s",
2542 VTYNL);
2543 return CMD_WARNING_CONFIG_FAILED;
2544 }
2545
2546 apply_mask (&range);
2547
2548 group = peer_group_lookup (bgp, peergroup);
2549 if (! group)
2550 {
2551 vty_out (vty, "%% Peer-group does not exist%s", VTYNL);
2552 return CMD_WARNING_CONFIG_FAILED;
2553 }
2554
2555 ret = peer_group_listen_range_del(group, &range);
2556 return bgp_vty_return (vty, ret);
2557 }
2558
2559 int
2560 bgp_config_write_listen (struct vty *vty, struct bgp *bgp)
2561 {
2562 struct peer_group *group;
2563 struct listnode *node, *nnode, *rnode, *nrnode;
2564 struct prefix *range;
2565 afi_t afi;
2566 char buf[PREFIX2STR_BUFFER];
2567
2568 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2569 vty_out (vty, " bgp listen limit %d%s",
2570 bgp->dynamic_neighbors_limit, VTYNL);
2571
2572 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
2573 {
2574 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2575 {
2576 for (ALL_LIST_ELEMENTS (group->listen_range[afi], rnode, nrnode, range))
2577 {
2578 prefix2str(range, buf, sizeof(buf));
2579 vty_out(vty, " bgp listen range %s peer-group %s%s",
2580 buf, group->name, VTYNL);
2581 }
2582 }
2583 }
2584
2585 return 0;
2586 }
2587
2588
2589 DEFUN (bgp_disable_connected_route_check,
2590 bgp_disable_connected_route_check_cmd,
2591 "bgp disable-ebgp-connected-route-check",
2592 "BGP specific commands\n"
2593 "Disable checking if nexthop is connected on ebgp sessions\n")
2594 {
2595 VTY_DECLVAR_CONTEXT(bgp, bgp);
2596 bgp_flag_set (bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2597 bgp_clear_star_soft_in (vty, bgp->name);
2598
2599 return CMD_SUCCESS;
2600 }
2601
2602 DEFUN (no_bgp_disable_connected_route_check,
2603 no_bgp_disable_connected_route_check_cmd,
2604 "no bgp disable-ebgp-connected-route-check",
2605 NO_STR
2606 "BGP specific commands\n"
2607 "Disable checking if nexthop is connected on ebgp sessions\n")
2608 {
2609 VTY_DECLVAR_CONTEXT(bgp, bgp);
2610 bgp_flag_unset (bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2611 bgp_clear_star_soft_in (vty, bgp->name);
2612
2613 return CMD_SUCCESS;
2614 }
2615
2616
2617 static int
2618 peer_remote_as_vty (struct vty *vty, const char *peer_str,
2619 const char *as_str, afi_t afi, safi_t safi)
2620 {
2621 VTY_DECLVAR_CONTEXT(bgp, bgp);
2622 int ret;
2623 as_t as;
2624 int as_type = AS_SPECIFIED;
2625 union sockunion su;
2626
2627 if (as_str[0] == 'i')
2628 {
2629 as = 0;
2630 as_type = AS_INTERNAL;
2631 }
2632 else if (as_str[0] == 'e')
2633 {
2634 as = 0;
2635 as_type = AS_EXTERNAL;
2636 }
2637 else
2638 {
2639 /* Get AS number. */
2640 as = strtoul(as_str, NULL, 10);
2641 }
2642
2643 /* If peer is peer group, call proper function. */
2644 ret = str2sockunion (peer_str, &su);
2645 if (ret < 0)
2646 {
2647 /* Check for peer by interface */
2648 ret = peer_remote_as (bgp, NULL, peer_str, &as, as_type, afi, safi);
2649 if (ret < 0)
2650 {
2651 ret = peer_group_remote_as (bgp, peer_str, &as, as_type);
2652 if (ret < 0)
2653 {
2654 vty_out (vty, "%% Create the peer-group or interface first%s",
2655 VTYNL);
2656 return CMD_WARNING_CONFIG_FAILED;
2657 }
2658 return CMD_SUCCESS;
2659 }
2660 }
2661 else
2662 {
2663 if (peer_address_self_check (bgp, &su))
2664 {
2665 vty_out (vty, "%% Can not configure the local system as neighbor%s",
2666 VTYNL);
2667 return CMD_WARNING_CONFIG_FAILED;
2668 }
2669 ret = peer_remote_as (bgp, &su, NULL, &as, as_type, afi, safi);
2670 }
2671
2672 /* This peer belongs to peer group. */
2673 switch (ret)
2674 {
2675 case BGP_ERR_PEER_GROUP_MEMBER:
2676 vty_out (vty, "%% Peer-group AS %u. Cannot configure remote-as for member%s", as, VTYNL);
2677 return CMD_WARNING_CONFIG_FAILED;
2678 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2679 vty_out (vty, "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external%s", as, as_str, VTYNL);
2680 return CMD_WARNING_CONFIG_FAILED;
2681 }
2682 return bgp_vty_return (vty, ret);
2683 }
2684
2685 DEFUN (neighbor_remote_as,
2686 neighbor_remote_as_cmd,
2687 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2688 NEIGHBOR_STR
2689 NEIGHBOR_ADDR_STR2
2690 "Specify a BGP neighbor\n"
2691 AS_STR
2692 "Internal BGP peer\n"
2693 "External BGP peer\n")
2694 {
2695 int idx_peer = 1;
2696 int idx_remote_as = 3;
2697 return peer_remote_as_vty (vty, argv[idx_peer]->arg, argv[idx_remote_as]->arg, AFI_IP, SAFI_UNICAST);
2698 }
2699
2700 static int
2701 peer_conf_interface_get (struct vty *vty, const char *conf_if, afi_t afi,
2702 safi_t safi, int v6only, const char *peer_group_name,
2703 const char *as_str)
2704 {
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706 as_t as = 0;
2707 int as_type = AS_UNSPECIFIED;
2708 struct peer *peer;
2709 struct peer_group *group;
2710 int ret = 0;
2711 union sockunion su;
2712
2713 group = peer_group_lookup (bgp, conf_if);
2714
2715 if (group)
2716 {
2717 vty_out (vty, "%% Name conflict with peer-group %s", VTYNL);
2718 return CMD_WARNING_CONFIG_FAILED;
2719 }
2720
2721 if (as_str)
2722 {
2723 if (as_str[0] == 'i')
2724 {
2725 as_type = AS_INTERNAL;
2726 }
2727 else if (as_str[0] == 'e')
2728 {
2729 as_type = AS_EXTERNAL;
2730 }
2731 else
2732 {
2733 /* Get AS number. */
2734 as = strtoul(as_str, NULL, 10);
2735 as_type = AS_SPECIFIED;
2736 }
2737 }
2738
2739 peer = peer_lookup_by_conf_if (bgp, conf_if);
2740 if (peer)
2741 {
2742 if (as_str)
2743 ret = peer_remote_as (bgp, &su, conf_if, &as, as_type, afi, safi);
2744 }
2745 else
2746 {
2747 if (bgp_flag_check (bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2748 && afi == AFI_IP && safi == SAFI_UNICAST)
2749 peer = peer_create (NULL, conf_if, bgp, bgp->as, as, as_type, 0, 0,
2750 NULL);
2751 else
2752 peer = peer_create (NULL, conf_if, bgp, bgp->as, as, as_type, afi, safi,
2753 NULL);
2754
2755 if (!peer)
2756 {
2757 vty_outln (vty, "%% BGP failed to create peer");
2758 return CMD_WARNING_CONFIG_FAILED;
2759 }
2760
2761 if (v6only)
2762 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2763
2764 /* Request zebra to initiate IPv6 RAs on this interface. We do this
2765 * any unnumbered peer in order to not worry about run-time transitions
2766 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31 address
2767 * gets deleted later etc.)
2768 */
2769 if (peer->ifp)
2770 bgp_zebra_initiate_radv (bgp, peer);
2771 }
2772
2773 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) ||
2774 (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)))
2775 {
2776 if (v6only)
2777 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2778 else
2779 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2780
2781 /* v6only flag changed. Reset bgp seesion */
2782 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status))
2783 {
2784 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2785 bgp_notify_send (peer, BGP_NOTIFY_CEASE,
2786 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2787 }
2788 else
2789 bgp_session_reset(peer);
2790 }
2791
2792 if (!CHECK_FLAG (peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2793 peer_flag_set (peer, PEER_FLAG_CAPABILITY_ENHE);
2794
2795 if (peer_group_name)
2796 {
2797 group = peer_group_lookup (bgp, peer_group_name);
2798 if (! group)
2799 {
2800 vty_out (vty, "%% Configure the peer-group first%s", VTYNL);
2801 return CMD_WARNING_CONFIG_FAILED;
2802 }
2803
2804 ret = peer_group_bind (bgp, &su, peer, group, &as);
2805 }
2806
2807 return bgp_vty_return (vty, ret);
2808 }
2809
2810 DEFUN (neighbor_interface_config,
2811 neighbor_interface_config_cmd,
2812 "neighbor WORD interface [peer-group WORD]",
2813 NEIGHBOR_STR
2814 "Interface name or neighbor tag\n"
2815 "Enable BGP on interface\n"
2816 "Member of the peer-group\n"
2817 "Peer-group name\n")
2818 {
2819 int idx_word = 1;
2820 int idx_peer_group_word = 4;
2821
2822 if (argc > idx_peer_group_word)
2823 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2824 argv[idx_peer_group_word]->arg, NULL);
2825 else
2826 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2827 NULL, NULL);
2828 }
2829
2830 DEFUN (neighbor_interface_config_v6only,
2831 neighbor_interface_config_v6only_cmd,
2832 "neighbor WORD interface v6only [peer-group WORD]",
2833 NEIGHBOR_STR
2834 "Interface name or neighbor tag\n"
2835 "Enable BGP on interface\n"
2836 "Enable BGP with v6 link-local only\n"
2837 "Member of the peer-group\n"
2838 "Peer-group name\n")
2839 {
2840 int idx_word = 1;
2841 int idx_peer_group_word = 5;
2842
2843 if (argc > idx_peer_group_word)
2844 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2845 argv[idx_peer_group_word]->arg, NULL);
2846
2847 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2848 NULL, NULL);
2849 }
2850
2851
2852 DEFUN (neighbor_interface_config_remote_as,
2853 neighbor_interface_config_remote_as_cmd,
2854 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2855 NEIGHBOR_STR
2856 "Interface name or neighbor tag\n"
2857 "Enable BGP on interface\n"
2858 "Specify a BGP neighbor\n"
2859 AS_STR
2860 "Internal BGP peer\n"
2861 "External BGP peer\n")
2862 {
2863 int idx_word = 1;
2864 int idx_remote_as = 4;
2865 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2866 NULL, argv[idx_remote_as]->arg);
2867 }
2868
2869 DEFUN (neighbor_interface_v6only_config_remote_as,
2870 neighbor_interface_v6only_config_remote_as_cmd,
2871 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2872 NEIGHBOR_STR
2873 "Interface name or neighbor tag\n"
2874 "Enable BGP with v6 link-local only\n"
2875 "Enable BGP on interface\n"
2876 "Specify a BGP neighbor\n"
2877 AS_STR
2878 "Internal BGP peer\n"
2879 "External BGP peer\n")
2880 {
2881 int idx_word = 1;
2882 int idx_remote_as = 5;
2883 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2884 NULL, argv[idx_remote_as]->arg);
2885 }
2886
2887 DEFUN (neighbor_peer_group,
2888 neighbor_peer_group_cmd,
2889 "neighbor WORD peer-group",
2890 NEIGHBOR_STR
2891 "Interface name or neighbor tag\n"
2892 "Configure peer-group\n")
2893 {
2894 VTY_DECLVAR_CONTEXT(bgp, bgp);
2895 int idx_word = 1;
2896 struct peer *peer;
2897 struct peer_group *group;
2898
2899 peer = peer_lookup_by_conf_if (bgp, argv[idx_word]->arg);
2900 if (peer)
2901 {
2902 vty_out (vty, "%% Name conflict with interface: %s", VTYNL);
2903 return CMD_WARNING_CONFIG_FAILED;
2904 }
2905
2906 group = peer_group_get (bgp, argv[idx_word]->arg);
2907 if (! group)
2908 {
2909 vty_outln (vty, "%% BGP failed to find or create peer-group");
2910 return CMD_WARNING_CONFIG_FAILED;
2911 }
2912
2913 return CMD_SUCCESS;
2914 }
2915
2916 DEFUN (no_neighbor,
2917 no_neighbor_cmd,
2918 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
2919 NO_STR
2920 NEIGHBOR_STR
2921 NEIGHBOR_ADDR_STR2
2922 "Specify a BGP neighbor\n"
2923 AS_STR
2924 "Internal BGP peer\n"
2925 "External BGP peer\n")
2926 {
2927 VTY_DECLVAR_CONTEXT(bgp, bgp);
2928 int idx_peer = 2;
2929 int ret;
2930 union sockunion su;
2931 struct peer_group *group;
2932 struct peer *peer;
2933 struct peer *other;
2934
2935 ret = str2sockunion (argv[idx_peer]->arg, &su);
2936 if (ret < 0)
2937 {
2938 /* look up for neighbor by interface name config. */
2939 peer = peer_lookup_by_conf_if (bgp, argv[idx_peer]->arg);
2940 if (peer)
2941 {
2942 /* Request zebra to terminate IPv6 RAs on this interface. */
2943 if (peer->ifp)
2944 bgp_zebra_terminate_radv (peer->bgp, peer);
2945 peer_delete (peer);
2946 return CMD_SUCCESS;
2947 }
2948
2949 group = peer_group_lookup (bgp, argv[idx_peer]->arg);
2950 if (group)
2951 peer_group_delete (group);
2952 else
2953 {
2954 vty_out (vty, "%% Create the peer-group first%s", VTYNL);
2955 return CMD_WARNING_CONFIG_FAILED;
2956 }
2957 }
2958 else
2959 {
2960 peer = peer_lookup (bgp, &su);
2961 if (peer)
2962 {
2963 if (peer_dynamic_neighbor (peer))
2964 {
2965 vty_out (vty, "%% Operation not allowed on a dynamic neighbor%s",
2966 VTYNL);
2967 return CMD_WARNING_CONFIG_FAILED;
2968 }
2969
2970 other = peer->doppelganger;
2971 peer_delete (peer);
2972 if (other && other->status != Deleted)
2973 peer_delete(other);
2974 }
2975 }
2976
2977 return CMD_SUCCESS;
2978 }
2979
2980 DEFUN (no_neighbor_interface_config,
2981 no_neighbor_interface_config_cmd,
2982 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
2983 NO_STR
2984 NEIGHBOR_STR
2985 "Interface name\n"
2986 "Configure BGP on interface\n"
2987 "Enable BGP with v6 link-local only\n"
2988 "Member of the peer-group\n"
2989 "Peer-group name\n"
2990 "Specify a BGP neighbor\n"
2991 AS_STR
2992 "Internal BGP peer\n"
2993 "External BGP peer\n")
2994 {
2995 VTY_DECLVAR_CONTEXT(bgp, bgp);
2996 int idx_word = 2;
2997 struct peer *peer;
2998
2999 /* look up for neighbor by interface name config. */
3000 peer = peer_lookup_by_conf_if (bgp, argv[idx_word]->arg);
3001 if (peer)
3002 {
3003 /* Request zebra to terminate IPv6 RAs on this interface. */
3004 if (peer->ifp)
3005 bgp_zebra_terminate_radv (peer->bgp, peer);
3006 peer_delete (peer);
3007 }
3008 else
3009 {
3010 vty_out (vty, "%% Create the bgp interface first%s", VTYNL);
3011 return CMD_WARNING_CONFIG_FAILED;
3012 }
3013 return CMD_SUCCESS;
3014 }
3015
3016 DEFUN (no_neighbor_peer_group,
3017 no_neighbor_peer_group_cmd,
3018 "no neighbor WORD peer-group",
3019 NO_STR
3020 NEIGHBOR_STR
3021 "Neighbor tag\n"
3022 "Configure peer-group\n")
3023 {
3024 VTY_DECLVAR_CONTEXT(bgp, bgp);
3025 int idx_word = 2;
3026 struct peer_group *group;
3027
3028 group = peer_group_lookup (bgp, argv[idx_word]->arg);
3029 if (group)
3030 peer_group_delete (group);
3031 else
3032 {
3033 vty_out (vty, "%% Create the peer-group first%s", VTYNL);
3034 return CMD_WARNING_CONFIG_FAILED;
3035 }
3036 return CMD_SUCCESS;
3037 }
3038
3039 DEFUN (no_neighbor_interface_peer_group_remote_as,
3040 no_neighbor_interface_peer_group_remote_as_cmd,
3041 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3042 NO_STR
3043 NEIGHBOR_STR
3044 "Interface name or neighbor tag\n"
3045 "Specify a BGP neighbor\n"
3046 AS_STR
3047 "Internal BGP peer\n"
3048 "External BGP peer\n")
3049 {
3050 VTY_DECLVAR_CONTEXT(bgp, bgp);
3051 int idx_word = 2;
3052 struct peer_group *group;
3053 struct peer *peer;
3054
3055 /* look up for neighbor by interface name config. */
3056 peer = peer_lookup_by_conf_if (bgp, argv[idx_word]->arg);
3057 if (peer)
3058 {
3059 peer_as_change (peer, 0, AS_SPECIFIED);
3060 return CMD_SUCCESS;
3061 }
3062
3063 group = peer_group_lookup (bgp, argv[idx_word]->arg);
3064 if (group)
3065 peer_group_remote_as_delete (group);
3066 else
3067 {
3068 vty_out (vty, "%% Create the peer-group or interface first%s", VTYNL);
3069 return CMD_WARNING_CONFIG_FAILED;
3070 }
3071 return CMD_SUCCESS;
3072 }
3073
3074 DEFUN (neighbor_local_as,
3075 neighbor_local_as_cmd,
3076 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3077 NEIGHBOR_STR
3078 NEIGHBOR_ADDR_STR2
3079 "Specify a local-as number\n"
3080 "AS number used as local AS\n")
3081 {
3082 int idx_peer = 1;
3083 int idx_number = 3;
3084 struct peer *peer;
3085 int ret;
3086 as_t as;
3087
3088 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3089 if (! peer)
3090 return CMD_WARNING_CONFIG_FAILED;
3091
3092 as = strtoul(argv[idx_number]->arg, NULL, 10);
3093 ret = peer_local_as_set (peer, as, 0, 0);
3094 return bgp_vty_return (vty, ret);
3095 }
3096
3097 DEFUN (neighbor_local_as_no_prepend,
3098 neighbor_local_as_no_prepend_cmd,
3099 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3100 NEIGHBOR_STR
3101 NEIGHBOR_ADDR_STR2
3102 "Specify a local-as number\n"
3103 "AS number used as local AS\n"
3104 "Do not prepend local-as to updates from ebgp peers\n")
3105 {
3106 int idx_peer = 1;
3107 int idx_number = 3;
3108 struct peer *peer;
3109 int ret;
3110 as_t as;
3111
3112 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3113 if (! peer)
3114 return CMD_WARNING_CONFIG_FAILED;
3115
3116 as = strtoul(argv[idx_number]->arg, NULL, 10);
3117 ret = peer_local_as_set (peer, as, 1, 0);
3118 return bgp_vty_return (vty, ret);
3119 }
3120
3121 DEFUN (neighbor_local_as_no_prepend_replace_as,
3122 neighbor_local_as_no_prepend_replace_as_cmd,
3123 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3124 NEIGHBOR_STR
3125 NEIGHBOR_ADDR_STR2
3126 "Specify a local-as number\n"
3127 "AS number used as local AS\n"
3128 "Do not prepend local-as to updates from ebgp peers\n"
3129 "Do not prepend local-as to updates from ibgp peers\n")
3130 {
3131 int idx_peer = 1;
3132 int idx_number = 3;
3133 struct peer *peer;
3134 int ret;
3135 as_t as;
3136
3137 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3138 if (! peer)
3139 return CMD_WARNING_CONFIG_FAILED;
3140
3141 as = strtoul(argv[idx_number]->arg, NULL, 10);
3142 ret = peer_local_as_set (peer, as, 1, 1);
3143 return bgp_vty_return (vty, ret);
3144 }
3145
3146 DEFUN (no_neighbor_local_as,
3147 no_neighbor_local_as_cmd,
3148 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3149 NO_STR
3150 NEIGHBOR_STR
3151 NEIGHBOR_ADDR_STR2
3152 "Specify a local-as number\n"
3153 "AS number used as local AS\n"
3154 "Do not prepend local-as to updates from ebgp peers\n"
3155 "Do not prepend local-as to updates from ibgp peers\n")
3156 {
3157 int idx_peer = 2;
3158 struct peer *peer;
3159 int ret;
3160
3161 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3162 if (! peer)
3163 return CMD_WARNING_CONFIG_FAILED;
3164
3165 ret = peer_local_as_unset (peer);
3166 return bgp_vty_return (vty, ret);
3167 }
3168
3169
3170
3171
3172 DEFUN (neighbor_solo,
3173 neighbor_solo_cmd,
3174 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3175 NEIGHBOR_STR
3176 NEIGHBOR_ADDR_STR2
3177 "Solo peer - part of its own update group\n")
3178 {
3179 int idx_peer = 1;
3180 struct peer *peer;
3181 int ret;
3182
3183 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3184 if (! peer)
3185 return CMD_WARNING_CONFIG_FAILED;
3186
3187 ret = update_group_adjust_soloness(peer, 1);
3188 return bgp_vty_return (vty, ret);
3189 }
3190
3191 DEFUN (no_neighbor_solo,
3192 no_neighbor_solo_cmd,
3193 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3194 NO_STR
3195 NEIGHBOR_STR
3196 NEIGHBOR_ADDR_STR2
3197 "Solo peer - part of its own update group\n")
3198 {
3199 int idx_peer = 2;
3200 struct peer *peer;
3201 int ret;
3202
3203 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3204 if (! peer)
3205 return CMD_WARNING_CONFIG_FAILED;
3206
3207 ret = update_group_adjust_soloness(peer, 0);
3208 return bgp_vty_return (vty, ret);
3209 }
3210
3211 DEFUN (neighbor_password,
3212 neighbor_password_cmd,
3213 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3214 NEIGHBOR_STR
3215 NEIGHBOR_ADDR_STR2
3216 "Set a password\n"
3217 "The password\n")
3218 {
3219 int idx_peer = 1;
3220 int idx_line = 3;
3221 struct peer *peer;
3222 int ret;
3223
3224 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3225 if (! peer)
3226 return CMD_WARNING_CONFIG_FAILED;
3227
3228 ret = peer_password_set (peer, argv[idx_line]->arg);
3229 return bgp_vty_return (vty, ret);
3230 }
3231
3232 DEFUN (no_neighbor_password,
3233 no_neighbor_password_cmd,
3234 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3235 NO_STR
3236 NEIGHBOR_STR
3237 NEIGHBOR_ADDR_STR2
3238 "Set a password\n"
3239 "The password\n")
3240 {
3241 int idx_peer = 2;
3242 struct peer *peer;
3243 int ret;
3244
3245 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3246 if (! peer)
3247 return CMD_WARNING_CONFIG_FAILED;
3248
3249 ret = peer_password_unset (peer);
3250 return bgp_vty_return (vty, ret);
3251 }
3252
3253
3254 DEFUN (neighbor_activate,
3255 neighbor_activate_cmd,
3256 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3257 NEIGHBOR_STR
3258 NEIGHBOR_ADDR_STR2
3259 "Enable the Address Family for this Neighbor\n")
3260 {
3261 int idx_peer = 1;
3262 int ret;
3263 struct peer *peer;
3264
3265 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3266 if (! peer)
3267 return CMD_WARNING_CONFIG_FAILED;
3268
3269 ret = peer_activate (peer, bgp_node_afi (vty), bgp_node_safi (vty));
3270 return bgp_vty_return (vty, ret);
3271 }
3272
3273 ALIAS_HIDDEN (neighbor_activate,
3274 neighbor_activate_hidden_cmd,
3275 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3276 NEIGHBOR_STR
3277 NEIGHBOR_ADDR_STR2
3278 "Enable the Address Family for this Neighbor\n")
3279
3280 DEFUN (no_neighbor_activate,
3281 no_neighbor_activate_cmd,
3282 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3283 NO_STR
3284 NEIGHBOR_STR
3285 NEIGHBOR_ADDR_STR2
3286 "Enable the Address Family for this Neighbor\n")
3287 {
3288 int idx_peer = 2;
3289 int ret;
3290 struct peer *peer;
3291
3292 /* Lookup peer. */
3293 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3294 if (! peer)
3295 return CMD_WARNING_CONFIG_FAILED;
3296
3297 ret = peer_deactivate (peer, bgp_node_afi (vty), bgp_node_safi (vty));
3298 return bgp_vty_return (vty, ret);
3299 }
3300
3301 ALIAS_HIDDEN (no_neighbor_activate,
3302 no_neighbor_activate_hidden_cmd,
3303 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3304 NO_STR
3305 NEIGHBOR_STR
3306 NEIGHBOR_ADDR_STR2
3307 "Enable the Address Family for this Neighbor\n")
3308
3309 DEFUN (neighbor_set_peer_group,
3310 neighbor_set_peer_group_cmd,
3311 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3312 NEIGHBOR_STR
3313 NEIGHBOR_ADDR_STR2
3314 "Member of the peer-group\n"
3315 "Peer-group name\n")
3316 {
3317 VTY_DECLVAR_CONTEXT(bgp, bgp);
3318 int idx_peer = 1;
3319 int idx_word = 3;
3320 int ret;
3321 as_t as;
3322 union sockunion su;
3323 struct peer *peer;
3324 struct peer_group *group;
3325
3326 peer = NULL;
3327
3328 ret = str2sockunion (argv[idx_peer]->arg, &su);
3329 if (ret < 0)
3330 {
3331 peer = peer_lookup_by_conf_if (bgp, argv[idx_peer]->arg);
3332 if (!peer)
3333 {
3334 vty_out (vty, "%% Malformed address or name: %s%s", argv[idx_peer]->arg, VTYNL);
3335 return CMD_WARNING_CONFIG_FAILED;
3336 }
3337 }
3338 else
3339 {
3340 if (peer_address_self_check (bgp, &su))
3341 {
3342 vty_out (vty, "%% Can not configure the local system as neighbor%s",
3343 VTYNL);
3344 return CMD_WARNING_CONFIG_FAILED;
3345 }
3346
3347 /* Disallow for dynamic neighbor. */
3348 peer = peer_lookup (bgp, &su);
3349 if (peer && peer_dynamic_neighbor (peer))
3350 {
3351 vty_out (vty, "%% Operation not allowed on a dynamic neighbor%s",
3352 VTYNL);
3353 return CMD_WARNING_CONFIG_FAILED;
3354 }
3355 }
3356
3357 group = peer_group_lookup (bgp, argv[idx_word]->arg);
3358 if (! group)
3359 {
3360 vty_out (vty, "%% Configure the peer-group first%s", VTYNL);
3361 return CMD_WARNING_CONFIG_FAILED;
3362 }
3363
3364 ret = peer_group_bind (bgp, &su, peer, group, &as);
3365
3366 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT)
3367 {
3368 vty_out (vty, "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external%s", as, VTYNL);
3369 return CMD_WARNING_CONFIG_FAILED;
3370 }
3371
3372 return bgp_vty_return (vty, ret);
3373 }
3374
3375 ALIAS_HIDDEN (neighbor_set_peer_group,
3376 neighbor_set_peer_group_hidden_cmd,
3377 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3378 NEIGHBOR_STR
3379 NEIGHBOR_ADDR_STR2
3380 "Member of the peer-group\n"
3381 "Peer-group name\n")
3382
3383 DEFUN (no_neighbor_set_peer_group,
3384 no_neighbor_set_peer_group_cmd,
3385 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3386 NO_STR
3387 NEIGHBOR_STR
3388 NEIGHBOR_ADDR_STR2
3389 "Member of the peer-group\n"
3390 "Peer-group name\n")
3391 {
3392 VTY_DECLVAR_CONTEXT(bgp, bgp);
3393 int idx_peer = 2;
3394 int idx_word = 4;
3395 int ret;
3396 struct peer *peer;
3397 struct peer_group *group;
3398
3399 peer = peer_lookup_vty (vty, argv[idx_peer]->arg);
3400 if (! peer)
3401 return CMD_WARNING_CONFIG_FAILED;
3402
3403 group = peer_group_lookup (bgp, argv[idx_word]->arg);
3404 if (! group)
3405 {
3406 vty_out (vty, "%% Configure the peer-group first%s", VTYNL);
3407 return CMD_WARNING_CONFIG_FAILED;
3408 }
3409
3410 ret = peer_group_unbind (bgp, peer, group);
3411
3412 return bgp_vty_return (vty, ret);
3413 }
3414
3415 ALIAS_HIDDEN (no_neighbor_set_peer_group,
3416 no_neighbor_set_peer_group_hidden_cmd,
3417 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3418 NO_STR
3419 NEIGHBOR_STR
3420 NEIGHBOR_ADDR_STR2
3421 "Member of the peer-group\n"
3422 "Peer-group name\n")
3423
3424 static int
3425 peer_flag_modify_vty (struct vty *vty, const char *ip_str,
3426 u_int16_t flag, int set)
3427 {
3428 int ret;
3429 struct peer *peer;
3430
3431 peer = peer_and_group_lookup_vty (vty, ip_str);
3432 if (! peer)
3433 return CMD_WARNING_CONFIG_FAILED;
3434
3435 /*
3436 * If 'neighbor <interface>', then this is for directly connected peers,
3437 * we should not accept disable-connected-check.
3438 */
3439 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3440 vty_out (vty, "%s is directly connected peer, cannot accept disable-"
3441 "connected-check%s", ip_str, VTYNL);
3442 return CMD_WARNING_CONFIG_FAILED;
3443 }
3444
3445 if (!set && flag == PEER_FLAG_SHUTDOWN)
3446 peer_tx_shutdown_message_unset (peer);
3447
3448 if (set)
3449 ret = peer_flag_set (peer, flag);
3450 else
3451 ret = peer_flag_unset (peer, flag);
3452
3453 return bgp_vty_return (vty, ret);
3454 }
3455
3456 static int
3457 peer_flag_set_vty (struct vty *vty, const char *ip_str, u_int16_t flag)
3458 {
3459 return peer_flag_modify_vty (vty, ip_str, flag, 1);
3460 }
3461
3462 static int
3463 peer_flag_unset_vty (struct vty *vty, const char *ip_str, u_int16_t flag)
3464 {
3465 return peer_flag_modify_vty (vty, ip_str, flag, 0);
3466 }
3467
3468 /* neighbor passive. */
3469 DEFUN (neighbor_passive,
3470 neighbor_passive_cmd,
3471 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3472 NEIGHBOR_STR
3473 NEIGHBOR_ADDR_STR2
3474 "Don't send open messages to this neighbor\n")
3475 {
3476 int idx_peer = 1;
3477 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3478 }
3479
3480 DEFUN (no_neighbor_passive,
3481 no_neighbor_passive_cmd,
3482 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3483 NO_STR
3484 NEIGHBOR_STR
3485 NEIGHBOR_ADDR_STR2
3486 "Don't send open messages to this neighbor\n")
3487 {
3488 int idx_peer = 2;
3489 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3490 }
3491
3492 /* neighbor shutdown. */
3493 DEFUN (neighbor_shutdown_msg,
3494 neighbor_shutdown_msg_cmd,
3495 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3496 NEIGHBOR_STR
3497 NEIGHBOR_ADDR_STR2
3498 "Administratively shut down this neighbor\n"
3499 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3500 "Shutdown message\n")
3501 {
3502 int idx_peer = 1;
3503
3504 if (argc >= 5)
3505 {
3506 struct peer *peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3507 char *message;
3508
3509 if (!peer)
3510 return CMD_WARNING_CONFIG_FAILED;
3511 message = argv_concat (argv, argc, 4);
3512 peer_tx_shutdown_message_set (peer, message);
3513 XFREE (MTYPE_TMP, message);
3514 }
3515
3516 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3517 }
3518
3519 ALIAS (neighbor_shutdown_msg,
3520 neighbor_shutdown_cmd,
3521 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3522 NEIGHBOR_STR
3523 NEIGHBOR_ADDR_STR2
3524 "Administratively shut down this neighbor\n")
3525
3526 DEFUN (no_neighbor_shutdown_msg,
3527 no_neighbor_shutdown_msg_cmd,
3528 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3529 NO_STR
3530 NEIGHBOR_STR
3531 NEIGHBOR_ADDR_STR2
3532 "Administratively shut down this neighbor\n"
3533 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3534 "Shutdown message\n")
3535 {
3536 int idx_peer = 2;
3537
3538 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3539 }
3540
3541 ALIAS (no_neighbor_shutdown_msg,
3542 no_neighbor_shutdown_cmd,
3543 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3544 NO_STR
3545 NEIGHBOR_STR
3546 NEIGHBOR_ADDR_STR2
3547 "Administratively shut down this neighbor\n")
3548
3549 /* neighbor capability dynamic. */
3550 DEFUN (neighbor_capability_dynamic,
3551 neighbor_capability_dynamic_cmd,
3552 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3553 NEIGHBOR_STR
3554 NEIGHBOR_ADDR_STR2
3555 "Advertise capability to the peer\n"
3556 "Advertise dynamic capability to this neighbor\n")
3557 {
3558 int idx_peer = 1;
3559 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DYNAMIC_CAPABILITY);
3560 }
3561
3562 DEFUN (no_neighbor_capability_dynamic,
3563 no_neighbor_capability_dynamic_cmd,
3564 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3565 NO_STR
3566 NEIGHBOR_STR
3567 NEIGHBOR_ADDR_STR2
3568 "Advertise capability to the peer\n"
3569 "Advertise dynamic capability to this neighbor\n")
3570 {
3571 int idx_peer = 2;
3572 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DYNAMIC_CAPABILITY);
3573 }
3574
3575 /* neighbor dont-capability-negotiate */
3576 DEFUN (neighbor_dont_capability_negotiate,
3577 neighbor_dont_capability_negotiate_cmd,
3578 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3579 NEIGHBOR_STR
3580 NEIGHBOR_ADDR_STR2
3581 "Do not perform capability negotiation\n")
3582 {
3583 int idx_peer = 1;
3584 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DONT_CAPABILITY);
3585 }
3586
3587 DEFUN (no_neighbor_dont_capability_negotiate,
3588 no_neighbor_dont_capability_negotiate_cmd,
3589 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3590 NO_STR
3591 NEIGHBOR_STR
3592 NEIGHBOR_ADDR_STR2
3593 "Do not perform capability negotiation\n")
3594 {
3595 int idx_peer = 2;
3596 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DONT_CAPABILITY);
3597 }
3598
3599 /* neighbor capability extended next hop encoding */
3600 DEFUN (neighbor_capability_enhe,
3601 neighbor_capability_enhe_cmd,
3602 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3603 NEIGHBOR_STR
3604 NEIGHBOR_ADDR_STR2
3605 "Advertise capability to the peer\n"
3606 "Advertise extended next-hop capability to the peer\n")
3607 {
3608 int idx_peer = 1;
3609 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_CAPABILITY_ENHE);
3610 }
3611
3612 DEFUN (no_neighbor_capability_enhe,
3613 no_neighbor_capability_enhe_cmd,
3614 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3615 NO_STR
3616 NEIGHBOR_STR
3617 NEIGHBOR_ADDR_STR2
3618 "Advertise capability to the peer\n"
3619 "Advertise extended next-hop capability to the peer\n")
3620 {
3621 int idx_peer = 2;
3622 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_CAPABILITY_ENHE);
3623 }
3624
3625 static int
3626 peer_af_flag_modify_vty (struct vty *vty, const char *peer_str, afi_t afi,
3627 safi_t safi, u_int32_t flag, int set)
3628 {
3629 int ret;
3630 struct peer *peer;
3631
3632 peer = peer_and_group_lookup_vty (vty, peer_str);
3633 if (! peer)
3634 return CMD_WARNING_CONFIG_FAILED;
3635
3636 if (set)
3637 ret = peer_af_flag_set (peer, afi, safi, flag);
3638 else
3639 ret = peer_af_flag_unset (peer, afi, safi, flag);
3640
3641 return bgp_vty_return (vty, ret);
3642 }
3643
3644 static int
3645 peer_af_flag_set_vty (struct vty *vty, const char *peer_str, afi_t afi,
3646 safi_t safi, u_int32_t flag)
3647 {
3648 return peer_af_flag_modify_vty (vty, peer_str, afi, safi, flag, 1);
3649 }
3650
3651 static int
3652 peer_af_flag_unset_vty (struct vty *vty, const char *peer_str, afi_t afi,
3653 safi_t safi, u_int32_t flag)
3654 {
3655 return peer_af_flag_modify_vty (vty, peer_str, afi, safi, flag, 0);
3656 }
3657
3658 /* neighbor capability orf prefix-list. */
3659 DEFUN (neighbor_capability_orf_prefix,
3660 neighbor_capability_orf_prefix_cmd,
3661 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3662 NEIGHBOR_STR
3663 NEIGHBOR_ADDR_STR2
3664 "Advertise capability to the peer\n"
3665 "Advertise ORF capability to the peer\n"
3666 "Advertise prefixlist ORF capability to this neighbor\n"
3667 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3668 "Capability to RECEIVE the ORF from this neighbor\n"
3669 "Capability to SEND the ORF to this neighbor\n")
3670 {
3671 int idx_peer = 1;
3672 int idx_send_recv = 5;
3673 u_int16_t flag = 0;
3674
3675 if (strmatch (argv[idx_send_recv]->text, "send"))
3676 flag = PEER_FLAG_ORF_PREFIX_SM;
3677 else if (strmatch (argv[idx_send_recv]->text, "receive"))
3678 flag = PEER_FLAG_ORF_PREFIX_RM;
3679 else if (strmatch (argv[idx_send_recv]->text, "both"))
3680 flag = PEER_FLAG_ORF_PREFIX_SM|PEER_FLAG_ORF_PREFIX_RM;
3681 else
3682 {
3683 vty_outln (vty, "%% BGP invalid orf prefix-list option");
3684 return CMD_WARNING_CONFIG_FAILED;
3685 }
3686
3687 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3688 bgp_node_safi (vty), flag);
3689 }
3690
3691 ALIAS_HIDDEN (neighbor_capability_orf_prefix,
3692 neighbor_capability_orf_prefix_hidden_cmd,
3693 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3694 NEIGHBOR_STR
3695 NEIGHBOR_ADDR_STR2
3696 "Advertise capability to the peer\n"
3697 "Advertise ORF capability to the peer\n"
3698 "Advertise prefixlist ORF capability to this neighbor\n"
3699 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3700 "Capability to RECEIVE the ORF from this neighbor\n"
3701 "Capability to SEND the ORF to this neighbor\n")
3702
3703 DEFUN (no_neighbor_capability_orf_prefix,
3704 no_neighbor_capability_orf_prefix_cmd,
3705 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3706 NO_STR
3707 NEIGHBOR_STR
3708 NEIGHBOR_ADDR_STR2
3709 "Advertise capability to the peer\n"
3710 "Advertise ORF capability to the peer\n"
3711 "Advertise prefixlist ORF capability to this neighbor\n"
3712 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3713 "Capability to RECEIVE the ORF from this neighbor\n"
3714 "Capability to SEND the ORF to this neighbor\n")
3715 {
3716 int idx_peer = 2;
3717 int idx_send_recv = 6;
3718 u_int16_t flag = 0;
3719
3720 if (strmatch (argv[idx_send_recv]->text, "send"))
3721 flag = PEER_FLAG_ORF_PREFIX_SM;
3722 else if (strmatch (argv[idx_send_recv]->text, "receive"))
3723 flag = PEER_FLAG_ORF_PREFIX_RM;
3724 else if (strmatch (argv[idx_send_recv]->text, "both"))
3725 flag = PEER_FLAG_ORF_PREFIX_SM|PEER_FLAG_ORF_PREFIX_RM;
3726 else
3727 {
3728 vty_outln (vty, "%% BGP invalid orf prefix-list option");
3729 return CMD_WARNING_CONFIG_FAILED;
3730 }
3731
3732 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3733 bgp_node_safi (vty), flag);
3734 }
3735
3736 ALIAS_HIDDEN (no_neighbor_capability_orf_prefix,
3737 no_neighbor_capability_orf_prefix_hidden_cmd,
3738 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3739 NO_STR
3740 NEIGHBOR_STR
3741 NEIGHBOR_ADDR_STR2
3742 "Advertise capability to the peer\n"
3743 "Advertise ORF capability to the peer\n"
3744 "Advertise prefixlist ORF capability to this neighbor\n"
3745 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3746 "Capability to RECEIVE the ORF from this neighbor\n"
3747 "Capability to SEND the ORF to this neighbor\n")
3748
3749 /* neighbor next-hop-self. */
3750 DEFUN (neighbor_nexthop_self,
3751 neighbor_nexthop_self_cmd,
3752 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3753 NEIGHBOR_STR
3754 NEIGHBOR_ADDR_STR2
3755 "Disable the next hop calculation for this neighbor\n")
3756 {
3757 int idx_peer = 1;
3758 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3759 bgp_node_safi (vty), PEER_FLAG_NEXTHOP_SELF);
3760 }
3761
3762 ALIAS_HIDDEN (neighbor_nexthop_self,
3763 neighbor_nexthop_self_hidden_cmd,
3764 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3765 NEIGHBOR_STR
3766 NEIGHBOR_ADDR_STR2
3767 "Disable the next hop calculation for this neighbor\n")
3768
3769 /* neighbor next-hop-self. */
3770 DEFUN (neighbor_nexthop_self_force,
3771 neighbor_nexthop_self_force_cmd,
3772 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3773 NEIGHBOR_STR
3774 NEIGHBOR_ADDR_STR2
3775 "Disable the next hop calculation for this neighbor\n"
3776 "Set the next hop to self for reflected routes\n")
3777 {
3778 int idx_peer = 1;
3779 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3780 bgp_node_safi (vty),
3781 PEER_FLAG_FORCE_NEXTHOP_SELF);
3782 }
3783
3784 ALIAS_HIDDEN (neighbor_nexthop_self_force,
3785 neighbor_nexthop_self_force_hidden_cmd,
3786 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3787 NEIGHBOR_STR
3788 NEIGHBOR_ADDR_STR2
3789 "Disable the next hop calculation for this neighbor\n"
3790 "Set the next hop to self for reflected routes\n")
3791
3792 DEFUN (no_neighbor_nexthop_self,
3793 no_neighbor_nexthop_self_cmd,
3794 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3795 NO_STR
3796 NEIGHBOR_STR
3797 NEIGHBOR_ADDR_STR2
3798 "Disable the next hop calculation for this neighbor\n")
3799 {
3800 int idx_peer = 2;
3801 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3802 bgp_node_safi (vty),
3803 PEER_FLAG_NEXTHOP_SELF);
3804 }
3805
3806 ALIAS_HIDDEN (no_neighbor_nexthop_self,
3807 no_neighbor_nexthop_self_hidden_cmd,
3808 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3809 NO_STR
3810 NEIGHBOR_STR
3811 NEIGHBOR_ADDR_STR2
3812 "Disable the next hop calculation for this neighbor\n")
3813
3814 DEFUN (no_neighbor_nexthop_self_force,
3815 no_neighbor_nexthop_self_force_cmd,
3816 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3817 NO_STR
3818 NEIGHBOR_STR
3819 NEIGHBOR_ADDR_STR2
3820 "Disable the next hop calculation for this neighbor\n"
3821 "Set the next hop to self for reflected routes\n")
3822 {
3823 int idx_peer = 2;
3824 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3825 bgp_node_safi (vty),
3826 PEER_FLAG_FORCE_NEXTHOP_SELF);
3827 }
3828
3829 ALIAS_HIDDEN (no_neighbor_nexthop_self_force,
3830 no_neighbor_nexthop_self_force_hidden_cmd,
3831 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3832 NO_STR
3833 NEIGHBOR_STR
3834 NEIGHBOR_ADDR_STR2
3835 "Disable the next hop calculation for this neighbor\n"
3836 "Set the next hop to self for reflected routes\n")
3837
3838 /* neighbor as-override */
3839 DEFUN (neighbor_as_override,
3840 neighbor_as_override_cmd,
3841 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3842 NEIGHBOR_STR
3843 NEIGHBOR_ADDR_STR2
3844 "Override ASNs in outbound updates if aspath equals remote-as\n")
3845 {
3846 int idx_peer = 1;
3847 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3848 bgp_node_safi (vty),
3849 PEER_FLAG_AS_OVERRIDE);
3850 }
3851
3852 ALIAS_HIDDEN (neighbor_as_override,
3853 neighbor_as_override_hidden_cmd,
3854 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3855 NEIGHBOR_STR
3856 NEIGHBOR_ADDR_STR2
3857 "Override ASNs in outbound updates if aspath equals remote-as\n")
3858
3859 DEFUN (no_neighbor_as_override,
3860 no_neighbor_as_override_cmd,
3861 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3862 NO_STR
3863 NEIGHBOR_STR
3864 NEIGHBOR_ADDR_STR2
3865 "Override ASNs in outbound updates if aspath equals remote-as\n")
3866 {
3867 int idx_peer = 2;
3868 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3869 bgp_node_safi (vty),
3870 PEER_FLAG_AS_OVERRIDE);
3871 }
3872
3873 ALIAS_HIDDEN (no_neighbor_as_override,
3874 no_neighbor_as_override_hidden_cmd,
3875 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3876 NO_STR
3877 NEIGHBOR_STR
3878 NEIGHBOR_ADDR_STR2
3879 "Override ASNs in outbound updates if aspath equals remote-as\n")
3880
3881 /* neighbor remove-private-AS. */
3882 DEFUN (neighbor_remove_private_as,
3883 neighbor_remove_private_as_cmd,
3884 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3885 NEIGHBOR_STR
3886 NEIGHBOR_ADDR_STR2
3887 "Remove private ASNs in outbound updates\n")
3888 {
3889 int idx_peer = 1;
3890 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3891 bgp_node_safi (vty),
3892 PEER_FLAG_REMOVE_PRIVATE_AS);
3893 }
3894
3895 ALIAS_HIDDEN (neighbor_remove_private_as,
3896 neighbor_remove_private_as_hidden_cmd,
3897 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3898 NEIGHBOR_STR
3899 NEIGHBOR_ADDR_STR2
3900 "Remove private ASNs in outbound updates\n")
3901
3902 DEFUN (neighbor_remove_private_as_all,
3903 neighbor_remove_private_as_all_cmd,
3904 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3905 NEIGHBOR_STR
3906 NEIGHBOR_ADDR_STR2
3907 "Remove private ASNs in outbound updates\n"
3908 "Apply to all AS numbers")
3909 {
3910 int idx_peer = 1;
3911 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3912 bgp_node_safi (vty),
3913 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3914 }
3915
3916 ALIAS_HIDDEN (neighbor_remove_private_as_all,
3917 neighbor_remove_private_as_all_hidden_cmd,
3918 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3919 NEIGHBOR_STR
3920 NEIGHBOR_ADDR_STR2
3921 "Remove private ASNs in outbound updates\n"
3922 "Apply to all AS numbers")
3923
3924 DEFUN (neighbor_remove_private_as_replace_as,
3925 neighbor_remove_private_as_replace_as_cmd,
3926 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3927 NEIGHBOR_STR
3928 NEIGHBOR_ADDR_STR2
3929 "Remove private ASNs in outbound updates\n"
3930 "Replace private ASNs with our ASN in outbound updates\n")
3931 {
3932 int idx_peer = 1;
3933 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3934 bgp_node_safi (vty),
3935 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3936 }
3937
3938 ALIAS_HIDDEN (neighbor_remove_private_as_replace_as,
3939 neighbor_remove_private_as_replace_as_hidden_cmd,
3940 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3941 NEIGHBOR_STR
3942 NEIGHBOR_ADDR_STR2
3943 "Remove private ASNs in outbound updates\n"
3944 "Replace private ASNs with our ASN in outbound updates\n")
3945
3946 DEFUN (neighbor_remove_private_as_all_replace_as,
3947 neighbor_remove_private_as_all_replace_as_cmd,
3948 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3949 NEIGHBOR_STR
3950 NEIGHBOR_ADDR_STR2
3951 "Remove private ASNs in outbound updates\n"
3952 "Apply to all AS numbers\n"
3953 "Replace private ASNs with our ASN in outbound updates\n")
3954 {
3955 int idx_peer = 1;
3956 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3957 bgp_node_safi (vty),
3958 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3959 }
3960
3961 ALIAS_HIDDEN (neighbor_remove_private_as_all_replace_as,
3962 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3963 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3964 NEIGHBOR_STR
3965 NEIGHBOR_ADDR_STR2
3966 "Remove private ASNs in outbound updates\n"
3967 "Apply to all AS numbers\n"
3968 "Replace private ASNs with our ASN in outbound updates\n")
3969
3970 DEFUN (no_neighbor_remove_private_as,
3971 no_neighbor_remove_private_as_cmd,
3972 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3973 NO_STR
3974 NEIGHBOR_STR
3975 NEIGHBOR_ADDR_STR2
3976 "Remove private ASNs in outbound updates\n")
3977 {
3978 int idx_peer = 2;
3979 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3980 bgp_node_safi (vty),
3981 PEER_FLAG_REMOVE_PRIVATE_AS);
3982 }
3983
3984 ALIAS_HIDDEN (no_neighbor_remove_private_as,
3985 no_neighbor_remove_private_as_hidden_cmd,
3986 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3987 NO_STR
3988 NEIGHBOR_STR
3989 NEIGHBOR_ADDR_STR2
3990 "Remove private ASNs in outbound updates\n")
3991
3992 DEFUN (no_neighbor_remove_private_as_all,
3993 no_neighbor_remove_private_as_all_cmd,
3994 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3995 NO_STR
3996 NEIGHBOR_STR
3997 NEIGHBOR_ADDR_STR2
3998 "Remove private ASNs in outbound updates\n"
3999 "Apply to all AS numbers\n")
4000 {
4001 int idx_peer = 2;
4002 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4003 bgp_node_safi (vty),
4004 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4005 }
4006
4007 ALIAS_HIDDEN (no_neighbor_remove_private_as_all,
4008 no_neighbor_remove_private_as_all_hidden_cmd,
4009 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4010 NO_STR
4011 NEIGHBOR_STR
4012 NEIGHBOR_ADDR_STR2
4013 "Remove private ASNs in outbound updates\n"
4014 "Apply to all AS numbers\n")
4015
4016 DEFUN (no_neighbor_remove_private_as_replace_as,
4017 no_neighbor_remove_private_as_replace_as_cmd,
4018 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4019 NO_STR
4020 NEIGHBOR_STR
4021 NEIGHBOR_ADDR_STR2
4022 "Remove private ASNs in outbound updates\n"
4023 "Replace private ASNs with our ASN in outbound updates\n")
4024 {
4025 int idx_peer = 2;
4026 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4027 bgp_node_safi (vty),
4028 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4029 }
4030
4031 ALIAS_HIDDEN (no_neighbor_remove_private_as_replace_as,
4032 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4033 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4034 NO_STR
4035 NEIGHBOR_STR
4036 NEIGHBOR_ADDR_STR2
4037 "Remove private ASNs in outbound updates\n"
4038 "Replace private ASNs with our ASN in outbound updates\n")
4039
4040 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4041 no_neighbor_remove_private_as_all_replace_as_cmd,
4042 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4043 NO_STR
4044 NEIGHBOR_STR
4045 NEIGHBOR_ADDR_STR2
4046 "Remove private ASNs in outbound updates\n"
4047 "Apply to all AS numbers\n"
4048 "Replace private ASNs with our ASN in outbound updates\n")
4049 {
4050 int idx_peer = 2;
4051 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4052 bgp_node_safi (vty),
4053 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4054 }
4055
4056 ALIAS_HIDDEN (no_neighbor_remove_private_as_all_replace_as,
4057 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4058 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4059 NO_STR
4060 NEIGHBOR_STR
4061 NEIGHBOR_ADDR_STR2
4062 "Remove private ASNs in outbound updates\n"
4063 "Apply to all AS numbers\n"
4064 "Replace private ASNs with our ASN in outbound updates\n")
4065
4066
4067 /* neighbor send-community. */
4068 DEFUN (neighbor_send_community,
4069 neighbor_send_community_cmd,
4070 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4071 NEIGHBOR_STR
4072 NEIGHBOR_ADDR_STR2
4073 "Send Community attribute to this neighbor\n")
4074 {
4075 int idx_peer = 1;
4076 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4077 bgp_node_safi (vty),
4078 PEER_FLAG_SEND_COMMUNITY);
4079 }
4080
4081 ALIAS_HIDDEN (neighbor_send_community,
4082 neighbor_send_community_hidden_cmd,
4083 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4084 NEIGHBOR_STR
4085 NEIGHBOR_ADDR_STR2
4086 "Send Community attribute to this neighbor\n")
4087
4088 DEFUN (no_neighbor_send_community,
4089 no_neighbor_send_community_cmd,
4090 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4091 NO_STR
4092 NEIGHBOR_STR
4093 NEIGHBOR_ADDR_STR2
4094 "Send Community attribute to this neighbor\n")
4095 {
4096 int idx_peer = 2;
4097 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4098 bgp_node_safi (vty),
4099 PEER_FLAG_SEND_COMMUNITY);
4100 }
4101
4102 ALIAS_HIDDEN (no_neighbor_send_community,
4103 no_neighbor_send_community_hidden_cmd,
4104 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4105 NO_STR
4106 NEIGHBOR_STR
4107 NEIGHBOR_ADDR_STR2
4108 "Send Community attribute to this neighbor\n")
4109
4110 /* neighbor send-community extended. */
4111 DEFUN (neighbor_send_community_type,
4112 neighbor_send_community_type_cmd,
4113 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4114 NEIGHBOR_STR
4115 NEIGHBOR_ADDR_STR2
4116 "Send Community attribute to this neighbor\n"
4117 "Send Standard and Extended Community attributes\n"
4118 "Send Standard, Large and Extended Community attributes\n"
4119 "Send Extended Community attributes\n"
4120 "Send Standard Community attributes\n"
4121 "Send Large Community attributes\n")
4122 {
4123 int idx = 0;
4124 u_int32_t flag = 0;
4125
4126 char *peer = argv[1]->arg;
4127
4128 if (argv_find (argv, argc, "standard", &idx))
4129 SET_FLAG (flag, PEER_FLAG_SEND_COMMUNITY);
4130 else if (argv_find (argv, argc, "extended", &idx))
4131 SET_FLAG (flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4132 else if (argv_find (argv, argc, "large", &idx))
4133 SET_FLAG (flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4134 else if (argv_find (argv, argc, "both", &idx))
4135 {
4136 SET_FLAG (flag, PEER_FLAG_SEND_COMMUNITY);
4137 SET_FLAG (flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4138 }
4139 else
4140 {
4141 SET_FLAG (flag, PEER_FLAG_SEND_COMMUNITY);
4142 SET_FLAG (flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4143 SET_FLAG (flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4144 }
4145
4146 return peer_af_flag_set_vty (vty, peer, bgp_node_afi (vty), bgp_node_safi (vty), flag);
4147 }
4148
4149 ALIAS_HIDDEN (neighbor_send_community_type,
4150 neighbor_send_community_type_hidden_cmd,
4151 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4152 NEIGHBOR_STR
4153 NEIGHBOR_ADDR_STR2
4154 "Send Community attribute to this neighbor\n"
4155 "Send Standard and Extended Community attributes\n"
4156 "Send Standard, Large and Extended Community attributes\n"
4157 "Send Extended Community attributes\n"
4158 "Send Standard Community attributes\n"
4159 "Send Large Community attributes\n")
4160
4161 DEFUN (no_neighbor_send_community_type,
4162 no_neighbor_send_community_type_cmd,
4163 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4164 NO_STR
4165 NEIGHBOR_STR
4166 NEIGHBOR_ADDR_STR2
4167 "Send Community attribute to this neighbor\n"
4168 "Send Standard and Extended Community attributes\n"
4169 "Send Standard, Large and Extended Community attributes\n"
4170 "Send Extended Community attributes\n"
4171 "Send Standard Community attributes\n"
4172 "Send Large Community attributes\n")
4173 {
4174 int idx_peer = 2;
4175
4176 const char *type = argv[argc - 1]->text;
4177
4178 if (strmatch (type, "standard"))
4179 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4180 bgp_node_safi (vty),
4181 PEER_FLAG_SEND_COMMUNITY);
4182 if (strmatch (type, "extended"))
4183 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4184 bgp_node_safi (vty),
4185 PEER_FLAG_SEND_EXT_COMMUNITY);
4186 if (strmatch (type, "large"))
4187 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4188 bgp_node_safi (vty),
4189 PEER_FLAG_SEND_LARGE_COMMUNITY);
4190 if (strmatch (type, "both"))
4191 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4192 bgp_node_safi (vty),
4193 PEER_FLAG_SEND_COMMUNITY |
4194 PEER_FLAG_SEND_EXT_COMMUNITY);
4195
4196 /* if (strmatch (type, "all")) */
4197 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4198 bgp_node_safi (vty),
4199 (PEER_FLAG_SEND_COMMUNITY |
4200 PEER_FLAG_SEND_EXT_COMMUNITY|
4201 PEER_FLAG_SEND_LARGE_COMMUNITY));
4202 }
4203
4204 ALIAS_HIDDEN (no_neighbor_send_community_type,
4205 no_neighbor_send_community_type_hidden_cmd,
4206 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4207 NO_STR
4208 NEIGHBOR_STR
4209 NEIGHBOR_ADDR_STR2
4210 "Send Community attribute to this neighbor\n"
4211 "Send Standard and Extended Community attributes\n"
4212 "Send Standard, Large and Extended Community attributes\n"
4213 "Send Extended Community attributes\n"
4214 "Send Standard Community attributes\n"
4215 "Send Large Community attributes\n")
4216
4217 /* neighbor soft-reconfig. */
4218 DEFUN (neighbor_soft_reconfiguration,
4219 neighbor_soft_reconfiguration_cmd,
4220 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4221 NEIGHBOR_STR
4222 NEIGHBOR_ADDR_STR2
4223 "Per neighbor soft reconfiguration\n"
4224 "Allow inbound soft reconfiguration for this neighbor\n")
4225 {
4226 int idx_peer = 1;
4227 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg,
4228 bgp_node_afi (vty), bgp_node_safi (vty),
4229 PEER_FLAG_SOFT_RECONFIG);
4230 }
4231
4232 ALIAS_HIDDEN (neighbor_soft_reconfiguration,
4233 neighbor_soft_reconfiguration_hidden_cmd,
4234 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4235 NEIGHBOR_STR
4236 NEIGHBOR_ADDR_STR2
4237 "Per neighbor soft reconfiguration\n"
4238 "Allow inbound soft reconfiguration for this neighbor\n")
4239
4240 DEFUN (no_neighbor_soft_reconfiguration,
4241 no_neighbor_soft_reconfiguration_cmd,
4242 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4243 NO_STR
4244 NEIGHBOR_STR
4245 NEIGHBOR_ADDR_STR2
4246 "Per neighbor soft reconfiguration\n"
4247 "Allow inbound soft reconfiguration for this neighbor\n")
4248 {
4249 int idx_peer = 2;
4250 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg,
4251 bgp_node_afi (vty), bgp_node_safi (vty),
4252 PEER_FLAG_SOFT_RECONFIG);
4253 }
4254
4255 ALIAS_HIDDEN (no_neighbor_soft_reconfiguration,
4256 no_neighbor_soft_reconfiguration_hidden_cmd,
4257 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4258 NO_STR
4259 NEIGHBOR_STR
4260 NEIGHBOR_ADDR_STR2
4261 "Per neighbor soft reconfiguration\n"
4262 "Allow inbound soft reconfiguration for this neighbor\n")
4263
4264 DEFUN (neighbor_route_reflector_client,
4265 neighbor_route_reflector_client_cmd,
4266 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4267 NEIGHBOR_STR
4268 NEIGHBOR_ADDR_STR2
4269 "Configure a neighbor as Route Reflector client\n")
4270 {
4271 int idx_peer = 1;
4272 struct peer *peer;
4273
4274
4275 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
4276 if (! peer)
4277 return CMD_WARNING_CONFIG_FAILED;
4278
4279 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4280 bgp_node_safi (vty),
4281 PEER_FLAG_REFLECTOR_CLIENT);
4282 }
4283
4284 ALIAS_HIDDEN (neighbor_route_reflector_client,
4285 neighbor_route_reflector_client_hidden_cmd,
4286 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4287 NEIGHBOR_STR
4288 NEIGHBOR_ADDR_STR2
4289 "Configure a neighbor as Route Reflector client\n")
4290
4291 DEFUN (no_neighbor_route_reflector_client,
4292 no_neighbor_route_reflector_client_cmd,
4293 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4294 NO_STR
4295 NEIGHBOR_STR
4296 NEIGHBOR_ADDR_STR2
4297 "Configure a neighbor as Route Reflector client\n")
4298 {
4299 int idx_peer = 2;
4300 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4301 bgp_node_safi (vty),
4302 PEER_FLAG_REFLECTOR_CLIENT);
4303 }
4304
4305 ALIAS_HIDDEN (no_neighbor_route_reflector_client,
4306 no_neighbor_route_reflector_client_hidden_cmd,
4307 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4308 NO_STR
4309 NEIGHBOR_STR
4310 NEIGHBOR_ADDR_STR2
4311 "Configure a neighbor as Route Reflector client\n")
4312
4313 /* neighbor route-server-client. */
4314 DEFUN (neighbor_route_server_client,
4315 neighbor_route_server_client_cmd,
4316 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4317 NEIGHBOR_STR
4318 NEIGHBOR_ADDR_STR2
4319 "Configure a neighbor as Route Server client\n")
4320 {
4321 int idx_peer = 1;
4322 struct peer *peer;
4323
4324 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
4325 if (! peer)
4326 return CMD_WARNING_CONFIG_FAILED;
4327 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4328 bgp_node_safi (vty),
4329 PEER_FLAG_RSERVER_CLIENT);
4330 }
4331
4332 ALIAS_HIDDEN (neighbor_route_server_client,
4333 neighbor_route_server_client_hidden_cmd,
4334 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4335 NEIGHBOR_STR
4336 NEIGHBOR_ADDR_STR2
4337 "Configure a neighbor as Route Server client\n")
4338
4339 DEFUN (no_neighbor_route_server_client,
4340 no_neighbor_route_server_client_cmd,
4341 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4342 NO_STR
4343 NEIGHBOR_STR
4344 NEIGHBOR_ADDR_STR2
4345 "Configure a neighbor as Route Server client\n")
4346 {
4347 int idx_peer = 2;
4348 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4349 bgp_node_safi (vty),
4350 PEER_FLAG_RSERVER_CLIENT);
4351 }
4352
4353 ALIAS_HIDDEN (no_neighbor_route_server_client,
4354 no_neighbor_route_server_client_hidden_cmd,
4355 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4356 NO_STR
4357 NEIGHBOR_STR
4358 NEIGHBOR_ADDR_STR2
4359 "Configure a neighbor as Route Server client\n")
4360
4361 DEFUN (neighbor_nexthop_local_unchanged,
4362 neighbor_nexthop_local_unchanged_cmd,
4363 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4364 NEIGHBOR_STR
4365 NEIGHBOR_ADDR_STR2
4366 "Configure treatment of outgoing link-local nexthop attribute\n"
4367 "Leave link-local nexthop unchanged for this peer\n")
4368 {
4369 int idx_peer = 1;
4370 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4371 bgp_node_safi (vty),
4372 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED );
4373 }
4374
4375 DEFUN (no_neighbor_nexthop_local_unchanged,
4376 no_neighbor_nexthop_local_unchanged_cmd,
4377 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4378 NO_STR
4379 NEIGHBOR_STR
4380 NEIGHBOR_ADDR_STR2
4381 "Configure treatment of outgoing link-local-nexthop attribute\n"
4382 "Leave link-local nexthop unchanged for this peer\n")
4383 {
4384 int idx_peer = 2;
4385 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4386 bgp_node_safi (vty),
4387 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED );
4388 }
4389
4390 DEFUN (neighbor_attr_unchanged,
4391 neighbor_attr_unchanged_cmd,
4392 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4393 NEIGHBOR_STR
4394 NEIGHBOR_ADDR_STR2
4395 "BGP attribute is propagated unchanged to this neighbor\n"
4396 "As-path attribute\n"
4397 "Nexthop attribute\n"
4398 "Med attribute\n")
4399 {
4400 int idx = 0;
4401 char *peer = argv[1]->arg;
4402 u_int16_t flags = 0;
4403
4404 if (argv_find (argv, argc, "as-path", &idx))
4405 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
4406 idx = 0;
4407 if (argv_find (argv, argc, "next-hop", &idx))
4408 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4409 idx = 0;
4410 if (argv_find (argv, argc, "med", &idx))
4411 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4412
4413 if (!flags) // no flags means all of them!
4414 {
4415 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
4416 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4417 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4418 }
4419
4420 return peer_af_flag_set_vty (vty, peer, bgp_node_afi (vty), bgp_node_safi (vty), flags);
4421 }
4422
4423 ALIAS_HIDDEN (neighbor_attr_unchanged,
4424 neighbor_attr_unchanged_hidden_cmd,
4425 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4426 NEIGHBOR_STR
4427 NEIGHBOR_ADDR_STR2
4428 "BGP attribute is propagated unchanged to this neighbor\n"
4429 "As-path attribute\n"
4430 "Nexthop attribute\n"
4431 "Med attribute\n")
4432
4433 DEFUN (no_neighbor_attr_unchanged,
4434 no_neighbor_attr_unchanged_cmd,
4435 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4436 NO_STR
4437 NEIGHBOR_STR
4438 NEIGHBOR_ADDR_STR2
4439 "BGP attribute is propagated unchanged to this neighbor\n"
4440 "As-path attribute\n"
4441 "Nexthop attribute\n"
4442 "Med attribute\n")
4443 {
4444 int idx = 0;
4445 char *peer = argv[2]->arg;
4446 u_int16_t flags = 0;
4447
4448 if (argv_find (argv, argc, "as-path", &idx))
4449 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
4450 idx = 0;
4451 if (argv_find (argv, argc, "next-hop", &idx))
4452 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4453 idx = 0;
4454 if (argv_find (argv, argc, "med", &idx))
4455 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4456
4457 if (!flags) // no flags means all of them!
4458 {
4459 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
4460 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4461 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4462 }
4463
4464 return peer_af_flag_unset_vty (vty, peer, bgp_node_afi (vty), bgp_node_safi (vty), flags);
4465 }
4466
4467 ALIAS_HIDDEN (no_neighbor_attr_unchanged,
4468 no_neighbor_attr_unchanged_hidden_cmd,
4469 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4470 NO_STR
4471 NEIGHBOR_STR
4472 NEIGHBOR_ADDR_STR2
4473 "BGP attribute is propagated unchanged to this neighbor\n"
4474 "As-path attribute\n"
4475 "Nexthop attribute\n"
4476 "Med attribute\n")
4477
4478 /* EBGP multihop configuration. */
4479 static int
4480 peer_ebgp_multihop_set_vty (struct vty *vty, const char *ip_str,
4481 const char *ttl_str)
4482 {
4483 struct peer *peer;
4484 unsigned int ttl;
4485
4486 peer = peer_and_group_lookup_vty (vty, ip_str);
4487 if (! peer)
4488 return CMD_WARNING_CONFIG_FAILED;
4489
4490 if (peer->conf_if)
4491 return bgp_vty_return (vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4492
4493 if (! ttl_str)
4494 ttl = MAXTTL;
4495 else
4496 ttl = strtoul(ttl_str, NULL, 10);
4497
4498 return bgp_vty_return (vty, peer_ebgp_multihop_set (peer, ttl));
4499 }
4500
4501 static int
4502 peer_ebgp_multihop_unset_vty (struct vty *vty, const char *ip_str)
4503 {
4504 struct peer *peer;
4505
4506 peer = peer_and_group_lookup_vty (vty, ip_str);
4507 if (! peer)
4508 return CMD_WARNING_CONFIG_FAILED;
4509
4510 return bgp_vty_return (vty, peer_ebgp_multihop_unset (peer));
4511 }
4512
4513 /* neighbor ebgp-multihop. */
4514 DEFUN (neighbor_ebgp_multihop,
4515 neighbor_ebgp_multihop_cmd,
4516 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4517 NEIGHBOR_STR
4518 NEIGHBOR_ADDR_STR2
4519 "Allow EBGP neighbors not on directly connected networks\n")
4520 {
4521 int idx_peer = 1;
4522 return peer_ebgp_multihop_set_vty (vty, argv[idx_peer]->arg, NULL);
4523 }
4524
4525 DEFUN (neighbor_ebgp_multihop_ttl,
4526 neighbor_ebgp_multihop_ttl_cmd,
4527 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4528 NEIGHBOR_STR
4529 NEIGHBOR_ADDR_STR2
4530 "Allow EBGP neighbors not on directly connected networks\n"
4531 "maximum hop count\n")
4532 {
4533 int idx_peer = 1;
4534 int idx_number = 3;
4535 return peer_ebgp_multihop_set_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg);
4536 }
4537
4538 DEFUN (no_neighbor_ebgp_multihop,
4539 no_neighbor_ebgp_multihop_cmd,
4540 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4541 NO_STR
4542 NEIGHBOR_STR
4543 NEIGHBOR_ADDR_STR2
4544 "Allow EBGP neighbors not on directly connected networks\n"
4545 "maximum hop count\n")
4546 {
4547 int idx_peer = 2;
4548 return peer_ebgp_multihop_unset_vty (vty, argv[idx_peer]->arg);
4549 }
4550
4551
4552 /* disable-connected-check */
4553 DEFUN (neighbor_disable_connected_check,
4554 neighbor_disable_connected_check_cmd,
4555 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4556 NEIGHBOR_STR
4557 NEIGHBOR_ADDR_STR2
4558 "one-hop away EBGP peer using loopback address\n"
4559 "Enforce EBGP neighbors perform multihop\n")
4560 {
4561 int idx_peer = 1;
4562 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DISABLE_CONNECTED_CHECK);
4563 }
4564
4565 DEFUN (no_neighbor_disable_connected_check,
4566 no_neighbor_disable_connected_check_cmd,
4567 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4568 NO_STR
4569 NEIGHBOR_STR
4570 NEIGHBOR_ADDR_STR2
4571 "one-hop away EBGP peer using loopback address\n"
4572 "Enforce EBGP neighbors perform multihop\n")
4573 {
4574 int idx_peer = 2;
4575 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DISABLE_CONNECTED_CHECK);
4576 }
4577
4578 DEFUN (neighbor_description,
4579 neighbor_description_cmd,
4580 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4581 NEIGHBOR_STR
4582 NEIGHBOR_ADDR_STR2
4583 "Neighbor specific description\n"
4584 "Up to 80 characters describing this neighbor\n")
4585 {
4586 int idx_peer = 1;
4587 int idx_line = 3;
4588 struct peer *peer;
4589 char *str;
4590
4591 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
4592 if (! peer)
4593 return CMD_WARNING_CONFIG_FAILED;
4594
4595 str = argv_concat(argv, argc, idx_line);
4596
4597 peer_description_set (peer, str);
4598
4599 XFREE (MTYPE_TMP, str);
4600
4601 return CMD_SUCCESS;
4602 }
4603
4604 DEFUN (no_neighbor_description,
4605 no_neighbor_description_cmd,
4606 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
4607 NO_STR
4608 NEIGHBOR_STR
4609 NEIGHBOR_ADDR_STR2
4610 "Neighbor specific description\n"
4611 "Up to 80 characters describing this neighbor\n")
4612 {
4613 int idx_peer = 2;
4614 struct peer *peer;
4615
4616 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
4617 if (! peer)
4618 return CMD_WARNING_CONFIG_FAILED;
4619
4620 peer_description_unset (peer);
4621
4622 return CMD_SUCCESS;
4623 }
4624
4625
4626 /* Neighbor update-source. */
4627 static int
4628 peer_update_source_vty (struct vty *vty, const char *peer_str,
4629 const char *source_str)
4630 {
4631 struct peer *peer;
4632 struct prefix p;
4633
4634 peer = peer_and_group_lookup_vty (vty, peer_str);
4635 if (! peer)
4636 return CMD_WARNING_CONFIG_FAILED;
4637
4638 if (peer->conf_if)
4639 return CMD_WARNING;
4640
4641 if (source_str)
4642 {
4643 union sockunion su;
4644 int ret = str2sockunion (source_str, &su);
4645
4646 if (ret == 0)
4647 peer_update_source_addr_set (peer, &su);
4648 else
4649 {
4650 if (str2prefix (source_str, &p))
4651 {
4652 vty_out (vty, "%% Invalid update-source, remove prefix length %s",
4653 VTYNL);
4654 return CMD_WARNING_CONFIG_FAILED;
4655 }
4656 else
4657 peer_update_source_if_set (peer, source_str);
4658 }
4659 }
4660 else
4661 peer_update_source_unset (peer);
4662
4663 return CMD_SUCCESS;
4664 }
4665
4666 #define BGP_UPDATE_SOURCE_HELP_STR \
4667 "IPv4 address\n" \
4668 "IPv6 address\n" \
4669 "Interface name (requires zebra to be running)\n"
4670
4671 DEFUN (neighbor_update_source,
4672 neighbor_update_source_cmd,
4673 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4674 NEIGHBOR_STR
4675 NEIGHBOR_ADDR_STR2
4676 "Source of routing updates\n"
4677 BGP_UPDATE_SOURCE_HELP_STR)
4678 {
4679 int idx_peer = 1;
4680 int idx_peer_2 = 3;
4681 return peer_update_source_vty (vty, argv[idx_peer]->arg, argv[idx_peer_2]->arg);
4682 }
4683
4684 DEFUN (no_neighbor_update_source,
4685 no_neighbor_update_source_cmd,
4686 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4687 NO_STR
4688 NEIGHBOR_STR
4689 NEIGHBOR_ADDR_STR2
4690 "Source of routing updates\n"
4691 BGP_UPDATE_SOURCE_HELP_STR)
4692 {
4693 int idx_peer = 2;
4694 return peer_update_source_vty (vty, argv[idx_peer]->arg, NULL);
4695 }
4696
4697 static int
4698 peer_default_originate_set_vty (struct vty *vty, const char *peer_str,
4699 afi_t afi, safi_t safi,
4700 const char *rmap, int set)
4701 {
4702 int ret;
4703 struct peer *peer;
4704
4705 peer = peer_and_group_lookup_vty (vty, peer_str);
4706 if (! peer)
4707 return CMD_WARNING_CONFIG_FAILED;
4708
4709 if (set)
4710 ret = peer_default_originate_set (peer, afi, safi, rmap);
4711 else
4712 ret = peer_default_originate_unset (peer, afi, safi);
4713
4714 return bgp_vty_return (vty, ret);
4715 }
4716
4717 /* neighbor default-originate. */
4718 DEFUN (neighbor_default_originate,
4719 neighbor_default_originate_cmd,
4720 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4721 NEIGHBOR_STR
4722 NEIGHBOR_ADDR_STR2
4723 "Originate default route to this neighbor\n")
4724 {
4725 int idx_peer = 1;
4726 return peer_default_originate_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4727 bgp_node_safi (vty), NULL, 1);
4728 }
4729
4730 ALIAS_HIDDEN (neighbor_default_originate,
4731 neighbor_default_originate_hidden_cmd,
4732 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4733 NEIGHBOR_STR
4734 NEIGHBOR_ADDR_STR2
4735 "Originate default route to this neighbor\n")
4736
4737 DEFUN (neighbor_default_originate_rmap,
4738 neighbor_default_originate_rmap_cmd,
4739 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4740 NEIGHBOR_STR
4741 NEIGHBOR_ADDR_STR2
4742 "Originate default route to this neighbor\n"
4743 "Route-map to specify criteria to originate default\n"
4744 "route-map name\n")
4745 {
4746 int idx_peer = 1;
4747 int idx_word = 4;
4748 return peer_default_originate_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4749 bgp_node_safi (vty), argv[idx_word]->arg, 1);
4750 }
4751
4752 ALIAS_HIDDEN (neighbor_default_originate_rmap,
4753 neighbor_default_originate_rmap_hidden_cmd,
4754 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4755 NEIGHBOR_STR
4756 NEIGHBOR_ADDR_STR2
4757 "Originate default route to this neighbor\n"
4758 "Route-map to specify criteria to originate default\n"
4759 "route-map name\n")
4760
4761 DEFUN (no_neighbor_default_originate,
4762 no_neighbor_default_originate_cmd,
4763 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4764 NO_STR
4765 NEIGHBOR_STR
4766 NEIGHBOR_ADDR_STR2
4767 "Originate default route to this neighbor\n"
4768 "Route-map to specify criteria to originate default\n"
4769 "route-map name\n")
4770 {
4771 int idx_peer = 2;
4772 return peer_default_originate_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4773 bgp_node_safi (vty), NULL, 0);
4774 }
4775
4776 ALIAS_HIDDEN (no_neighbor_default_originate,
4777 no_neighbor_default_originate_hidden_cmd,
4778 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4779 NO_STR
4780 NEIGHBOR_STR
4781 NEIGHBOR_ADDR_STR2
4782 "Originate default route to this neighbor\n"
4783 "Route-map to specify criteria to originate default\n"
4784 "route-map name\n")
4785
4786
4787 /* Set neighbor's BGP port. */
4788 static int
4789 peer_port_vty (struct vty *vty, const char *ip_str, int afi,
4790 const char *port_str)
4791 {
4792 struct peer *peer;
4793 u_int16_t port;
4794 struct servent *sp;
4795
4796 peer = peer_lookup_vty (vty, ip_str);
4797 if (! peer)
4798 return CMD_WARNING_CONFIG_FAILED;
4799
4800 if (! port_str)
4801 {
4802 sp = getservbyname ("bgp", "tcp");
4803 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs (sp->s_port);
4804 }
4805 else
4806 {
4807 port = strtoul(port_str, NULL, 10);
4808 }
4809
4810 peer_port_set (peer, port);
4811
4812 return CMD_SUCCESS;
4813 }
4814
4815 /* Set specified peer's BGP port. */
4816 DEFUN (neighbor_port,
4817 neighbor_port_cmd,
4818 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4819 NEIGHBOR_STR
4820 NEIGHBOR_ADDR_STR
4821 "Neighbor's BGP port\n"
4822 "TCP port number\n")
4823 {
4824 int idx_ip = 1;
4825 int idx_number = 3;
4826 return peer_port_vty (vty, argv[idx_ip]->arg, AFI_IP, argv[idx_number]->arg);
4827 }
4828
4829 DEFUN (no_neighbor_port,
4830 no_neighbor_port_cmd,
4831 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4832 NO_STR
4833 NEIGHBOR_STR
4834 NEIGHBOR_ADDR_STR
4835 "Neighbor's BGP port\n"
4836 "TCP port number\n")
4837 {
4838 int idx_ip = 2;
4839 return peer_port_vty (vty, argv[idx_ip]->arg, AFI_IP, NULL);
4840 }
4841
4842
4843 /* neighbor weight. */
4844 static int
4845 peer_weight_set_vty (struct vty *vty, const char *ip_str,
4846 afi_t afi, safi_t safi,
4847 const char *weight_str)
4848 {
4849 int ret;
4850 struct peer *peer;
4851 unsigned long weight;
4852
4853 peer = peer_and_group_lookup_vty (vty, ip_str);
4854 if (! peer)
4855 return CMD_WARNING_CONFIG_FAILED;
4856
4857 weight = strtoul(weight_str, NULL, 10);
4858
4859 ret = peer_weight_set (peer, afi, safi, weight);
4860 return bgp_vty_return (vty, ret);
4861 }
4862
4863 static int
4864 peer_weight_unset_vty (struct vty *vty, const char *ip_str,
4865 afi_t afi, safi_t safi)
4866 {
4867 int ret;
4868 struct peer *peer;
4869
4870 peer = peer_and_group_lookup_vty (vty, ip_str);
4871 if (! peer)
4872 return CMD_WARNING_CONFIG_FAILED;
4873
4874 ret = peer_weight_unset (peer, afi, safi);
4875 return bgp_vty_return (vty, ret);
4876 }
4877
4878 DEFUN (neighbor_weight,
4879 neighbor_weight_cmd,
4880 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4881 NEIGHBOR_STR
4882 NEIGHBOR_ADDR_STR2
4883 "Set default weight for routes from this neighbor\n"
4884 "default weight\n")
4885 {
4886 int idx_peer = 1;
4887 int idx_number = 3;
4888 return peer_weight_set_vty (vty,
4889 argv[idx_peer]->arg,
4890 bgp_node_afi (vty),
4891 bgp_node_safi (vty),
4892 argv[idx_number]->arg);
4893 }
4894
4895 ALIAS_HIDDEN (neighbor_weight,
4896 neighbor_weight_hidden_cmd,
4897 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4898 NEIGHBOR_STR
4899 NEIGHBOR_ADDR_STR2
4900 "Set default weight for routes from this neighbor\n"
4901 "default weight\n")
4902
4903 DEFUN (no_neighbor_weight,
4904 no_neighbor_weight_cmd,
4905 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4906 NO_STR
4907 NEIGHBOR_STR
4908 NEIGHBOR_ADDR_STR2
4909 "Set default weight for routes from this neighbor\n"
4910 "default weight\n")
4911 {
4912 int idx_peer = 2;
4913 return peer_weight_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty), bgp_node_safi (vty));
4914 }
4915
4916 ALIAS_HIDDEN (no_neighbor_weight,
4917 no_neighbor_weight_hidden_cmd,
4918 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4919 NO_STR
4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
4922 "Set default weight for routes from this neighbor\n"
4923 "default weight\n")
4924
4925
4926 /* Override capability negotiation. */
4927 DEFUN (neighbor_override_capability,
4928 neighbor_override_capability_cmd,
4929 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4930 NEIGHBOR_STR
4931 NEIGHBOR_ADDR_STR2
4932 "Override capability negotiation result\n")
4933 {
4934 int idx_peer = 1;
4935 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_OVERRIDE_CAPABILITY);
4936 }
4937
4938 DEFUN (no_neighbor_override_capability,
4939 no_neighbor_override_capability_cmd,
4940 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4941 NO_STR
4942 NEIGHBOR_STR
4943 NEIGHBOR_ADDR_STR2
4944 "Override capability negotiation result\n")
4945 {
4946 int idx_peer = 2;
4947 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_OVERRIDE_CAPABILITY);
4948 }
4949
4950 DEFUN (neighbor_strict_capability,
4951 neighbor_strict_capability_cmd,
4952 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4953 NEIGHBOR_STR
4954 NEIGHBOR_ADDR_STR
4955 "Strict capability negotiation match\n")
4956 {
4957 int idx_ip = 1;
4958 return peer_flag_set_vty (vty, argv[idx_ip]->arg, PEER_FLAG_STRICT_CAP_MATCH);
4959 }
4960
4961 DEFUN (no_neighbor_strict_capability,
4962 no_neighbor_strict_capability_cmd,
4963 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4964 NO_STR
4965 NEIGHBOR_STR
4966 NEIGHBOR_ADDR_STR
4967 "Strict capability negotiation match\n")
4968 {
4969 int idx_ip = 2;
4970 return peer_flag_unset_vty (vty, argv[idx_ip]->arg, PEER_FLAG_STRICT_CAP_MATCH);
4971 }
4972
4973 static int
4974 peer_timers_set_vty (struct vty *vty, const char *ip_str,
4975 const char *keep_str, const char *hold_str)
4976 {
4977 int ret;
4978 struct peer *peer;
4979 u_int32_t keepalive;
4980 u_int32_t holdtime;
4981
4982 peer = peer_and_group_lookup_vty (vty, ip_str);
4983 if (! peer)
4984 return CMD_WARNING_CONFIG_FAILED;
4985
4986 keepalive = strtoul(keep_str, NULL, 10);
4987 holdtime = strtoul(hold_str, NULL, 10);
4988
4989 ret = peer_timers_set (peer, keepalive, holdtime);
4990
4991 return bgp_vty_return (vty, ret);
4992 }
4993
4994 static int
4995 peer_timers_unset_vty (struct vty *vty, const char *ip_str)
4996 {
4997 int ret;
4998 struct peer *peer;
4999
5000 peer = peer_and_group_lookup_vty (vty, ip_str);
5001 if (! peer)
5002 return CMD_WARNING_CONFIG_FAILED;
5003
5004 ret = peer_timers_unset (peer);
5005
5006 return bgp_vty_return (vty, ret);
5007 }
5008
5009 DEFUN (neighbor_timers,
5010 neighbor_timers_cmd,
5011 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5012 NEIGHBOR_STR
5013 NEIGHBOR_ADDR_STR2
5014 "BGP per neighbor timers\n"
5015 "Keepalive interval\n"
5016 "Holdtime\n")
5017 {
5018 int idx_peer = 1;
5019 int idx_number = 3;
5020 int idx_number_2 = 4;
5021 return peer_timers_set_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg, argv[idx_number_2]->arg);
5022 }
5023
5024 DEFUN (no_neighbor_timers,
5025 no_neighbor_timers_cmd,
5026 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5027 NO_STR
5028 NEIGHBOR_STR
5029 NEIGHBOR_ADDR_STR2
5030 "BGP per neighbor timers\n"
5031 "Keepalive interval\n"
5032 "Holdtime\n")
5033 {
5034 int idx_peer = 2;
5035 return peer_timers_unset_vty (vty, argv[idx_peer]->arg);
5036 }
5037
5038
5039 static int
5040 peer_timers_connect_set_vty (struct vty *vty, const char *ip_str,
5041 const char *time_str)
5042 {
5043 int ret;
5044 struct peer *peer;
5045 u_int32_t connect;
5046
5047 peer = peer_and_group_lookup_vty (vty, ip_str);
5048 if (! peer)
5049 return CMD_WARNING_CONFIG_FAILED;
5050
5051 connect = strtoul(time_str, NULL, 10);
5052
5053 ret = peer_timers_connect_set (peer, connect);
5054
5055 return bgp_vty_return (vty, ret);
5056 }
5057
5058 static int
5059 peer_timers_connect_unset_vty (struct vty *vty, const char *ip_str)
5060 {
5061 int ret;
5062 struct peer *peer;
5063
5064 peer = peer_and_group_lookup_vty (vty, ip_str);
5065 if (! peer)
5066 return CMD_WARNING_CONFIG_FAILED;
5067
5068 ret = peer_timers_connect_unset (peer);
5069
5070 return bgp_vty_return (vty, ret);
5071 }
5072
5073 DEFUN (neighbor_timers_connect,
5074 neighbor_timers_connect_cmd,
5075 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5076 NEIGHBOR_STR
5077 NEIGHBOR_ADDR_STR2
5078 "BGP per neighbor timers\n"
5079 "BGP connect timer\n"
5080 "Connect timer\n")
5081 {
5082 int idx_peer = 1;
5083 int idx_number = 4;
5084 return peer_timers_connect_set_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg);
5085 }
5086
5087 DEFUN (no_neighbor_timers_connect,
5088 no_neighbor_timers_connect_cmd,
5089 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5090 NO_STR
5091 NEIGHBOR_STR
5092 NEIGHBOR_ADDR_STR2
5093 "BGP per neighbor timers\n"
5094 "BGP connect timer\n"
5095 "Connect timer\n")
5096 {
5097 int idx_peer = 2;
5098 return peer_timers_connect_unset_vty (vty, argv[idx_peer]->arg);
5099 }
5100
5101
5102 static int
5103 peer_advertise_interval_vty (struct vty *vty, const char *ip_str,
5104 const char *time_str, int set)
5105 {
5106 int ret;
5107 struct peer *peer;
5108 u_int32_t routeadv = 0;
5109
5110 peer = peer_and_group_lookup_vty (vty, ip_str);
5111 if (! peer)
5112 return CMD_WARNING_CONFIG_FAILED;
5113
5114 if (time_str)
5115 routeadv = strtoul(time_str, NULL, 10);
5116
5117 if (set)
5118 ret = peer_advertise_interval_set (peer, routeadv);
5119 else
5120 ret = peer_advertise_interval_unset (peer);
5121
5122 return bgp_vty_return (vty, ret);
5123 }
5124
5125 DEFUN (neighbor_advertise_interval,
5126 neighbor_advertise_interval_cmd,
5127 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5128 NEIGHBOR_STR
5129 NEIGHBOR_ADDR_STR2
5130 "Minimum interval between sending BGP routing updates\n"
5131 "time in seconds\n")
5132 {
5133 int idx_peer = 1;
5134 int idx_number = 3;
5135 return peer_advertise_interval_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg, 1);
5136 }
5137
5138 DEFUN (no_neighbor_advertise_interval,
5139 no_neighbor_advertise_interval_cmd,
5140 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5141 NO_STR
5142 NEIGHBOR_STR
5143 NEIGHBOR_ADDR_STR2
5144 "Minimum interval between sending BGP routing updates\n"
5145 "time in seconds\n")
5146 {
5147 int idx_peer = 2;
5148 return peer_advertise_interval_vty (vty, argv[idx_peer]->arg, NULL, 0);
5149 }
5150
5151
5152 /* Time to wait before processing route-map updates */
5153 DEFUN (bgp_set_route_map_delay_timer,
5154 bgp_set_route_map_delay_timer_cmd,
5155 "bgp route-map delay-timer (0-600)",
5156 SET_STR
5157 "BGP route-map delay timer\n"
5158 "Time in secs to wait before processing route-map changes\n"
5159 "0 disables the timer, no route updates happen when route-maps change\n")
5160 {
5161 int idx_number = 3;
5162 u_int32_t rmap_delay_timer;
5163
5164 if (argv[idx_number]->arg)
5165 {
5166 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5167 bm->rmap_update_timer = rmap_delay_timer;
5168
5169 /* if the dynamic update handling is being disabled, and a timer is
5170 * running, stop the timer and act as if the timer has already fired.
5171 */
5172 if (!rmap_delay_timer && bm->t_rmap_update )
5173 {
5174 BGP_TIMER_OFF(bm->t_rmap_update);
5175 thread_execute (bm->master, bgp_route_map_update_timer, NULL, 0);
5176 }
5177 return CMD_SUCCESS;
5178 }
5179 else
5180 {
5181 vty_outln (vty, "%% BGP invalid route-map delay-timer");
5182 return CMD_WARNING_CONFIG_FAILED;
5183 }
5184 }
5185
5186 DEFUN (no_bgp_set_route_map_delay_timer,
5187 no_bgp_set_route_map_delay_timer_cmd,
5188 "no bgp route-map delay-timer [(0-600)]",
5189 NO_STR
5190 BGP_STR
5191 "Default BGP route-map delay timer\n"
5192 "Reset to default time to wait for processing route-map changes\n"
5193 "0 disables the timer, no route updates happen when route-maps change\n")
5194 {
5195
5196 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5197
5198 return CMD_SUCCESS;
5199 }
5200
5201
5202 /* neighbor interface */
5203 static int
5204 peer_interface_vty (struct vty *vty, const char *ip_str, const char *str)
5205 {
5206 struct peer *peer;
5207
5208 peer = peer_lookup_vty (vty, ip_str);
5209 if (! peer || peer->conf_if)
5210 {
5211 vty_outln (vty, "%% BGP invalid peer %s", ip_str);
5212 return CMD_WARNING_CONFIG_FAILED;
5213 }
5214
5215 if (str)
5216 peer_interface_set (peer, str);
5217 else
5218 peer_interface_unset (peer);
5219
5220 return CMD_SUCCESS;
5221 }
5222
5223 DEFUN (neighbor_interface,
5224 neighbor_interface_cmd,
5225 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5226 NEIGHBOR_STR
5227 NEIGHBOR_ADDR_STR
5228 "Interface\n"
5229 "Interface name\n")
5230 {
5231 int idx_ip = 1;
5232 int idx_word = 3;
5233 return peer_interface_vty (vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5234 }
5235
5236 DEFUN (no_neighbor_interface,
5237 no_neighbor_interface_cmd,
5238 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5239 NO_STR
5240 NEIGHBOR_STR
5241 NEIGHBOR_ADDR_STR2
5242 "Interface\n"
5243 "Interface name\n")
5244 {
5245 int idx_peer = 2;
5246 return peer_interface_vty (vty, argv[idx_peer]->arg, NULL);
5247 }
5248
5249 DEFUN (neighbor_distribute_list,
5250 neighbor_distribute_list_cmd,
5251 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5252 NEIGHBOR_STR
5253 NEIGHBOR_ADDR_STR2
5254 "Filter updates to/from this neighbor\n"
5255 "IP access-list number\n"
5256 "IP access-list number (expanded range)\n"
5257 "IP Access-list name\n"
5258 "Filter incoming updates\n"
5259 "Filter outgoing updates\n")
5260 {
5261 int idx_peer = 1;
5262 int idx_acl = 3;
5263 int direct, ret;
5264 struct peer *peer;
5265
5266 const char *pstr = argv[idx_peer]->arg;
5267 const char *acl = argv[idx_acl]->arg;
5268 const char *inout = argv[argc-1]->text;
5269
5270 peer = peer_and_group_lookup_vty (vty, pstr);
5271 if (! peer)
5272 return CMD_WARNING_CONFIG_FAILED;
5273
5274 /* Check filter direction. */
5275 direct = strmatch (inout, "in") ? FILTER_IN : FILTER_OUT;
5276 ret = peer_distribute_set (peer, bgp_node_afi (vty), bgp_node_safi (vty), direct, acl);
5277
5278 return bgp_vty_return (vty, ret);
5279 }
5280
5281 ALIAS_HIDDEN (neighbor_distribute_list,
5282 neighbor_distribute_list_hidden_cmd,
5283 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5284 NEIGHBOR_STR
5285 NEIGHBOR_ADDR_STR2
5286 "Filter updates to/from this neighbor\n"
5287 "IP access-list number\n"
5288 "IP access-list number (expanded range)\n"
5289 "IP Access-list name\n"
5290 "Filter incoming updates\n"
5291 "Filter outgoing updates\n")
5292
5293 DEFUN (no_neighbor_distribute_list,
5294 no_neighbor_distribute_list_cmd,
5295 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5296 NO_STR
5297 NEIGHBOR_STR
5298 NEIGHBOR_ADDR_STR2
5299 "Filter updates to/from this neighbor\n"
5300 "IP access-list number\n"
5301 "IP access-list number (expanded range)\n"
5302 "IP Access-list name\n"
5303 "Filter incoming updates\n"
5304 "Filter outgoing updates\n")
5305 {
5306 int idx_peer = 2;
5307 int direct, ret;
5308 struct peer *peer;
5309
5310 const char *pstr = argv[idx_peer]->arg;
5311 const char *inout = argv[argc-1]->text;
5312
5313 peer = peer_and_group_lookup_vty (vty, pstr);
5314 if (! peer)
5315 return CMD_WARNING_CONFIG_FAILED;
5316
5317 /* Check filter direction. */
5318 direct = strmatch (inout, "in") ? FILTER_IN : FILTER_OUT;
5319 ret = peer_distribute_unset (peer, bgp_node_afi (vty), bgp_node_safi (vty), direct);
5320
5321 return bgp_vty_return (vty, ret);
5322 }
5323
5324 ALIAS_HIDDEN (no_neighbor_distribute_list,
5325 no_neighbor_distribute_list_hidden_cmd,
5326 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5327 NO_STR
5328 NEIGHBOR_STR
5329 NEIGHBOR_ADDR_STR2
5330 "Filter updates to/from this neighbor\n"
5331 "IP access-list number\n"
5332 "IP access-list number (expanded range)\n"
5333 "IP Access-list name\n"
5334 "Filter incoming updates\n"
5335 "Filter outgoing updates\n")
5336
5337 /* Set prefix list to the peer. */
5338 static int
5339 peer_prefix_list_set_vty (struct vty *vty, const char *ip_str, afi_t afi,
5340 safi_t safi, const char *name_str,
5341 const char *direct_str)
5342 {
5343 int ret;
5344 struct peer *peer;
5345 int direct = FILTER_IN;
5346
5347 peer = peer_and_group_lookup_vty (vty, ip_str);
5348 if (! peer)
5349 return CMD_WARNING_CONFIG_FAILED;
5350
5351 /* Check filter direction. */
5352 if (strncmp (direct_str, "i", 1) == 0)
5353 direct = FILTER_IN;
5354 else if (strncmp (direct_str, "o", 1) == 0)
5355 direct = FILTER_OUT;
5356
5357 ret = peer_prefix_list_set (peer, afi, safi, direct, name_str);
5358
5359 return bgp_vty_return (vty, ret);
5360 }
5361
5362 static int
5363 peer_prefix_list_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5364 safi_t safi, const char *direct_str)
5365 {
5366 int ret;
5367 struct peer *peer;
5368 int direct = FILTER_IN;
5369
5370 peer = peer_and_group_lookup_vty (vty, ip_str);
5371 if (! peer)
5372 return CMD_WARNING_CONFIG_FAILED;
5373
5374 /* Check filter direction. */
5375 if (strncmp (direct_str, "i", 1) == 0)
5376 direct = FILTER_IN;
5377 else if (strncmp (direct_str, "o", 1) == 0)
5378 direct = FILTER_OUT;
5379
5380 ret = peer_prefix_list_unset (peer, afi, safi, direct);
5381
5382 return bgp_vty_return (vty, ret);
5383 }
5384
5385 DEFUN (neighbor_prefix_list,
5386 neighbor_prefix_list_cmd,
5387 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5388 NEIGHBOR_STR
5389 NEIGHBOR_ADDR_STR2
5390 "Filter updates to/from this neighbor\n"
5391 "Name of a prefix list\n"
5392 "Filter incoming updates\n"
5393 "Filter outgoing updates\n")
5394 {
5395 int idx_peer = 1;
5396 int idx_word = 3;
5397 int idx_in_out = 4;
5398 return peer_prefix_list_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5399 bgp_node_safi (vty), argv[idx_word]->arg, argv[idx_in_out]->arg);
5400 }
5401
5402 ALIAS_HIDDEN (neighbor_prefix_list,
5403 neighbor_prefix_list_hidden_cmd,
5404 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5405 NEIGHBOR_STR
5406 NEIGHBOR_ADDR_STR2
5407 "Filter updates to/from this neighbor\n"
5408 "Name of a prefix list\n"
5409 "Filter incoming updates\n"
5410 "Filter outgoing updates\n")
5411
5412 DEFUN (no_neighbor_prefix_list,
5413 no_neighbor_prefix_list_cmd,
5414 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5415 NO_STR
5416 NEIGHBOR_STR
5417 NEIGHBOR_ADDR_STR2
5418 "Filter updates to/from this neighbor\n"
5419 "Name of a prefix list\n"
5420 "Filter incoming updates\n"
5421 "Filter outgoing updates\n")
5422 {
5423 int idx_peer = 2;
5424 int idx_in_out = 5;
5425 return peer_prefix_list_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5426 bgp_node_safi (vty), argv[idx_in_out]->arg);
5427 }
5428
5429 ALIAS_HIDDEN (no_neighbor_prefix_list,
5430 no_neighbor_prefix_list_hidden_cmd,
5431 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5432 NO_STR
5433 NEIGHBOR_STR
5434 NEIGHBOR_ADDR_STR2
5435 "Filter updates to/from this neighbor\n"
5436 "Name of a prefix list\n"
5437 "Filter incoming updates\n"
5438 "Filter outgoing updates\n")
5439
5440 static int
5441 peer_aslist_set_vty (struct vty *vty, const char *ip_str,
5442 afi_t afi, safi_t safi,
5443 const char *name_str, const char *direct_str)
5444 {
5445 int ret;
5446 struct peer *peer;
5447 int direct = FILTER_IN;
5448
5449 peer = peer_and_group_lookup_vty (vty, ip_str);
5450 if (! peer)
5451 return CMD_WARNING_CONFIG_FAILED;
5452
5453 /* Check filter direction. */
5454 if (strncmp (direct_str, "i", 1) == 0)
5455 direct = FILTER_IN;
5456 else if (strncmp (direct_str, "o", 1) == 0)
5457 direct = FILTER_OUT;
5458
5459 ret = peer_aslist_set (peer, afi, safi, direct, name_str);
5460
5461 return bgp_vty_return (vty, ret);
5462 }
5463
5464 static int
5465 peer_aslist_unset_vty (struct vty *vty, const char *ip_str,
5466 afi_t afi, safi_t safi,
5467 const char *direct_str)
5468 {
5469 int ret;
5470 struct peer *peer;
5471 int direct = FILTER_IN;
5472
5473 peer = peer_and_group_lookup_vty (vty, ip_str);
5474 if (! peer)
5475 return CMD_WARNING_CONFIG_FAILED;
5476
5477 /* Check filter direction. */
5478 if (strncmp (direct_str, "i", 1) == 0)
5479 direct = FILTER_IN;
5480 else if (strncmp (direct_str, "o", 1) == 0)
5481 direct = FILTER_OUT;
5482
5483 ret = peer_aslist_unset (peer, afi, safi, direct);
5484
5485 return bgp_vty_return (vty, ret);
5486 }
5487
5488 DEFUN (neighbor_filter_list,
5489 neighbor_filter_list_cmd,
5490 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5491 NEIGHBOR_STR
5492 NEIGHBOR_ADDR_STR2
5493 "Establish BGP filters\n"
5494 "AS path access-list name\n"
5495 "Filter incoming routes\n"
5496 "Filter outgoing routes\n")
5497 {
5498 int idx_peer = 1;
5499 int idx_word = 3;
5500 int idx_in_out = 4;
5501 return peer_aslist_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5502 bgp_node_safi (vty), argv[idx_word]->arg, argv[idx_in_out]->arg);
5503 }
5504
5505 ALIAS_HIDDEN (neighbor_filter_list,
5506 neighbor_filter_list_hidden_cmd,
5507 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5508 NEIGHBOR_STR
5509 NEIGHBOR_ADDR_STR2
5510 "Establish BGP filters\n"
5511 "AS path access-list name\n"
5512 "Filter incoming routes\n"
5513 "Filter outgoing routes\n")
5514
5515 DEFUN (no_neighbor_filter_list,
5516 no_neighbor_filter_list_cmd,
5517 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5518 NO_STR
5519 NEIGHBOR_STR
5520 NEIGHBOR_ADDR_STR2
5521 "Establish BGP filters\n"
5522 "AS path access-list name\n"
5523 "Filter incoming routes\n"
5524 "Filter outgoing routes\n")
5525 {
5526 int idx_peer = 2;
5527 int idx_in_out = 5;
5528 return peer_aslist_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5529 bgp_node_safi (vty), argv[idx_in_out]->arg);
5530 }
5531
5532 ALIAS_HIDDEN (no_neighbor_filter_list,
5533 no_neighbor_filter_list_hidden_cmd,
5534 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5535 NO_STR
5536 NEIGHBOR_STR
5537 NEIGHBOR_ADDR_STR2
5538 "Establish BGP filters\n"
5539 "AS path access-list name\n"
5540 "Filter incoming routes\n"
5541 "Filter outgoing routes\n")
5542
5543 /* Set route-map to the peer. */
5544 static int
5545 peer_route_map_set_vty (struct vty *vty, const char *ip_str,
5546 afi_t afi, safi_t safi,
5547 const char *name_str, const char *direct_str)
5548 {
5549 int ret;
5550 struct peer *peer;
5551 int direct = RMAP_IN;
5552
5553 peer = peer_and_group_lookup_vty (vty, ip_str);
5554 if (! peer)
5555 return CMD_WARNING_CONFIG_FAILED;
5556
5557 /* Check filter direction. */
5558 if (strncmp (direct_str, "in", 2) == 0)
5559 direct = RMAP_IN;
5560 else if (strncmp (direct_str, "o", 1) == 0)
5561 direct = RMAP_OUT;
5562
5563 ret = peer_route_map_set (peer, afi, safi, direct, name_str);
5564
5565 return bgp_vty_return (vty, ret);
5566 }
5567
5568 static int
5569 peer_route_map_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5570 safi_t safi, const char *direct_str)
5571 {
5572 int ret;
5573 struct peer *peer;
5574 int direct = RMAP_IN;
5575
5576 peer = peer_and_group_lookup_vty (vty, ip_str);
5577 if (! peer)
5578 return CMD_WARNING_CONFIG_FAILED;
5579
5580 /* Check filter direction. */
5581 if (strncmp (direct_str, "in", 2) == 0)
5582 direct = RMAP_IN;
5583 else if (strncmp (direct_str, "o", 1) == 0)
5584 direct = RMAP_OUT;
5585
5586 ret = peer_route_map_unset (peer, afi, safi, direct);
5587
5588 return bgp_vty_return (vty, ret);
5589 }
5590
5591 DEFUN (neighbor_route_map,
5592 neighbor_route_map_cmd,
5593 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5594 NEIGHBOR_STR
5595 NEIGHBOR_ADDR_STR2
5596 "Apply route map to neighbor\n"
5597 "Name of route map\n"
5598 "Apply map to incoming routes\n"
5599 "Apply map to outbound routes\n")
5600 {
5601 int idx_peer = 1;
5602 int idx_word = 3;
5603 int idx_in_out = 4;
5604 return peer_route_map_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5605 bgp_node_safi (vty), argv[idx_word]->arg, argv[idx_in_out]->arg);
5606 }
5607
5608 ALIAS_HIDDEN (neighbor_route_map,
5609 neighbor_route_map_hidden_cmd,
5610 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5611 NEIGHBOR_STR
5612 NEIGHBOR_ADDR_STR2
5613 "Apply route map to neighbor\n"
5614 "Name of route map\n"
5615 "Apply map to incoming routes\n"
5616 "Apply map to outbound routes\n")
5617
5618 DEFUN (no_neighbor_route_map,
5619 no_neighbor_route_map_cmd,
5620 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5621 NO_STR
5622 NEIGHBOR_STR
5623 NEIGHBOR_ADDR_STR2
5624 "Apply route map to neighbor\n"
5625 "Name of route map\n"
5626 "Apply map to incoming routes\n"
5627 "Apply map to outbound routes\n")
5628 {
5629 int idx_peer = 2;
5630 int idx_in_out = 5;
5631 return peer_route_map_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5632 bgp_node_safi (vty), argv[idx_in_out]->arg);
5633 }
5634
5635 ALIAS_HIDDEN (no_neighbor_route_map,
5636 no_neighbor_route_map_hidden_cmd,
5637 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5638 NO_STR
5639 NEIGHBOR_STR
5640 NEIGHBOR_ADDR_STR2
5641 "Apply route map to neighbor\n"
5642 "Name of route map\n"
5643 "Apply map to incoming routes\n"
5644 "Apply map to outbound routes\n")
5645
5646 /* Set unsuppress-map to the peer. */
5647 static int
5648 peer_unsuppress_map_set_vty (struct vty *vty, const char *ip_str, afi_t afi,
5649 safi_t safi, const char *name_str)
5650 {
5651 int ret;
5652 struct peer *peer;
5653
5654 peer = peer_and_group_lookup_vty (vty, ip_str);
5655 if (! peer)
5656 return CMD_WARNING_CONFIG_FAILED;
5657
5658 ret = peer_unsuppress_map_set (peer, afi, safi, name_str);
5659
5660 return bgp_vty_return (vty, ret);
5661 }
5662
5663 /* Unset route-map from the peer. */
5664 static int
5665 peer_unsuppress_map_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5666 safi_t safi)
5667 {
5668 int ret;
5669 struct peer *peer;
5670
5671 peer = peer_and_group_lookup_vty (vty, ip_str);
5672 if (! peer)
5673 return CMD_WARNING_CONFIG_FAILED;
5674
5675 ret = peer_unsuppress_map_unset (peer, afi, safi);
5676
5677 return bgp_vty_return (vty, ret);
5678 }
5679
5680 DEFUN (neighbor_unsuppress_map,
5681 neighbor_unsuppress_map_cmd,
5682 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5683 NEIGHBOR_STR
5684 NEIGHBOR_ADDR_STR2
5685 "Route-map to selectively unsuppress suppressed routes\n"
5686 "Name of route map\n")
5687 {
5688 int idx_peer = 1;
5689 int idx_word = 3;
5690 return peer_unsuppress_map_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5691 bgp_node_safi (vty), argv[idx_word]->arg);
5692 }
5693
5694 ALIAS_HIDDEN (neighbor_unsuppress_map,
5695 neighbor_unsuppress_map_hidden_cmd,
5696 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5697 NEIGHBOR_STR
5698 NEIGHBOR_ADDR_STR2
5699 "Route-map to selectively unsuppress suppressed routes\n"
5700 "Name of route map\n")
5701
5702 DEFUN (no_neighbor_unsuppress_map,
5703 no_neighbor_unsuppress_map_cmd,
5704 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5705 NO_STR
5706 NEIGHBOR_STR
5707 NEIGHBOR_ADDR_STR2
5708 "Route-map to selectively unsuppress suppressed routes\n"
5709 "Name of route map\n")
5710 {
5711 int idx_peer = 2;
5712 return peer_unsuppress_map_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5713 bgp_node_safi (vty));
5714 }
5715
5716 ALIAS_HIDDEN (no_neighbor_unsuppress_map,
5717 no_neighbor_unsuppress_map_hidden_cmd,
5718 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5719 NO_STR
5720 NEIGHBOR_STR
5721 NEIGHBOR_ADDR_STR2
5722 "Route-map to selectively unsuppress suppressed routes\n"
5723 "Name of route map\n")
5724
5725 static int
5726 peer_maximum_prefix_set_vty (struct vty *vty, const char *ip_str, afi_t afi,
5727 safi_t safi, const char *num_str,
5728 const char *threshold_str, int warning,
5729 const char *restart_str)
5730 {
5731 int ret;
5732 struct peer *peer;
5733 u_int32_t max;
5734 u_char threshold;
5735 u_int16_t restart;
5736
5737 peer = peer_and_group_lookup_vty (vty, ip_str);
5738 if (! peer)
5739 return CMD_WARNING_CONFIG_FAILED;
5740
5741 max = strtoul(num_str, NULL, 10);
5742 if (threshold_str)
5743 threshold = atoi (threshold_str);
5744 else
5745 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5746
5747 if (restart_str)
5748 restart = atoi (restart_str);
5749 else
5750 restart = 0;
5751
5752 ret = peer_maximum_prefix_set (peer, afi, safi, max, threshold, warning, restart);
5753
5754 return bgp_vty_return (vty, ret);
5755 }
5756
5757 static int
5758 peer_maximum_prefix_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5759 safi_t safi)
5760 {
5761 int ret;
5762 struct peer *peer;
5763
5764 peer = peer_and_group_lookup_vty (vty, ip_str);
5765 if (! peer)
5766 return CMD_WARNING_CONFIG_FAILED;
5767
5768 ret = peer_maximum_prefix_unset (peer, afi, safi);
5769
5770 return bgp_vty_return (vty, ret);
5771 }
5772
5773 /* Maximum number of prefix configuration. prefix count is different
5774 for each peer configuration. So this configuration can be set for
5775 each peer configuration. */
5776 DEFUN (neighbor_maximum_prefix,
5777 neighbor_maximum_prefix_cmd,
5778 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5779 NEIGHBOR_STR
5780 NEIGHBOR_ADDR_STR2
5781 "Maximum number of prefix accept from this peer\n"
5782 "maximum no. of prefix limit\n")
5783 {
5784 int idx_peer = 1;
5785 int idx_number = 3;
5786 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5787 bgp_node_safi (vty), argv[idx_number]->arg, NULL, 0,
5788 NULL);
5789 }
5790
5791 ALIAS_HIDDEN (neighbor_maximum_prefix,
5792 neighbor_maximum_prefix_hidden_cmd,
5793 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5794 NEIGHBOR_STR
5795 NEIGHBOR_ADDR_STR2
5796 "Maximum number of prefix accept from this peer\n"
5797 "maximum no. of prefix limit\n")
5798
5799 DEFUN (neighbor_maximum_prefix_threshold,
5800 neighbor_maximum_prefix_threshold_cmd,
5801 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5802 NEIGHBOR_STR
5803 NEIGHBOR_ADDR_STR2
5804 "Maximum number of prefix accept from this peer\n"
5805 "maximum no. of prefix limit\n"
5806 "Threshold value (%) at which to generate a warning msg\n")
5807 {
5808 int idx_peer = 1;
5809 int idx_number = 3;
5810 int idx_number_2 = 4;
5811 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5812 bgp_node_safi (vty), argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5813 NULL);
5814 }
5815
5816 ALIAS_HIDDEN (neighbor_maximum_prefix_threshold,
5817 neighbor_maximum_prefix_threshold_hidden_cmd,
5818 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5819 NEIGHBOR_STR
5820 NEIGHBOR_ADDR_STR2
5821 "Maximum number of prefix accept from this peer\n"
5822 "maximum no. of prefix limit\n"
5823 "Threshold value (%) at which to generate a warning msg\n")
5824
5825 DEFUN (neighbor_maximum_prefix_warning,
5826 neighbor_maximum_prefix_warning_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5828 NEIGHBOR_STR
5829 NEIGHBOR_ADDR_STR2
5830 "Maximum number of prefix accept from this peer\n"
5831 "maximum no. of prefix limit\n"
5832 "Only give warning message when limit is exceeded\n")
5833 {
5834 int idx_peer = 1;
5835 int idx_number = 3;
5836 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5837 bgp_node_safi (vty), argv[idx_number]->arg, NULL, 1,
5838 NULL);
5839 }
5840
5841 ALIAS_HIDDEN (neighbor_maximum_prefix_warning,
5842 neighbor_maximum_prefix_warning_hidden_cmd,
5843 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5844 NEIGHBOR_STR
5845 NEIGHBOR_ADDR_STR2
5846 "Maximum number of prefix accept from this peer\n"
5847 "maximum no. of prefix limit\n"
5848 "Only give warning message when limit is exceeded\n")
5849
5850 DEFUN (neighbor_maximum_prefix_threshold_warning,
5851 neighbor_maximum_prefix_threshold_warning_cmd,
5852 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5853 NEIGHBOR_STR
5854 NEIGHBOR_ADDR_STR2
5855 "Maximum number of prefix accept from this peer\n"
5856 "maximum no. of prefix limit\n"
5857 "Threshold value (%) at which to generate a warning msg\n"
5858 "Only give warning message when limit is exceeded\n")
5859 {
5860 int idx_peer = 1;
5861 int idx_number = 3;
5862 int idx_number_2 = 4;
5863 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5864 bgp_node_safi (vty), argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5865 }
5866
5867 ALIAS_HIDDEN (neighbor_maximum_prefix_threshold_warning,
5868 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5869 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Maximum number of prefix accept from this peer\n"
5873 "maximum no. of prefix limit\n"
5874 "Threshold value (%) at which to generate a warning msg\n"
5875 "Only give warning message when limit is exceeded\n")
5876
5877 DEFUN (neighbor_maximum_prefix_restart,
5878 neighbor_maximum_prefix_restart_cmd,
5879 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5880 NEIGHBOR_STR
5881 NEIGHBOR_ADDR_STR2
5882 "Maximum number of prefix accept from this peer\n"
5883 "maximum no. of prefix limit\n"
5884 "Restart bgp connection after limit is exceeded\n"
5885 "Restart interval in minutes")
5886 {
5887 int idx_peer = 1;
5888 int idx_number = 3;
5889 int idx_number_2 = 5;
5890 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5891 bgp_node_safi (vty), argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5892 }
5893
5894 ALIAS_HIDDEN (neighbor_maximum_prefix_restart,
5895 neighbor_maximum_prefix_restart_hidden_cmd,
5896 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5897 NEIGHBOR_STR
5898 NEIGHBOR_ADDR_STR2
5899 "Maximum number of prefix accept from this peer\n"
5900 "maximum no. of prefix limit\n"
5901 "Restart bgp connection after limit is exceeded\n"
5902 "Restart interval in minutes")
5903
5904 DEFUN (neighbor_maximum_prefix_threshold_restart,
5905 neighbor_maximum_prefix_threshold_restart_cmd,
5906 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5907 NEIGHBOR_STR
5908 NEIGHBOR_ADDR_STR2
5909 "Maximum number of prefixes to accept from this peer\n"
5910 "maximum no. of prefix limit\n"
5911 "Threshold value (%) at which to generate a warning msg\n"
5912 "Restart bgp connection after limit is exceeded\n"
5913 "Restart interval in minutes\n")
5914 {
5915 int idx_peer = 1;
5916 int idx_number = 3;
5917 int idx_number_2 = 4;
5918 int idx_number_3 = 6;
5919 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5920 bgp_node_safi (vty), argv[idx_number]->arg, argv[idx_number_2]->arg, 0, argv[idx_number_3]->arg);
5921 }
5922
5923 ALIAS_HIDDEN (neighbor_maximum_prefix_threshold_restart,
5924 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5925 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5926 NEIGHBOR_STR
5927 NEIGHBOR_ADDR_STR2
5928 "Maximum number of prefixes to accept from this peer\n"
5929 "maximum no. of prefix limit\n"
5930 "Threshold value (%) at which to generate a warning msg\n"
5931 "Restart bgp connection after limit is exceeded\n"
5932 "Restart interval in minutes\n")
5933
5934 DEFUN (no_neighbor_maximum_prefix,
5935 no_neighbor_maximum_prefix_cmd,
5936 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5937 NO_STR
5938 NEIGHBOR_STR
5939 NEIGHBOR_ADDR_STR2
5940 "Maximum number of prefixes to accept from this peer\n"
5941 "maximum no. of prefix limit\n"
5942 "Threshold value (%) at which to generate a warning msg\n"
5943 "Restart bgp connection after limit is exceeded\n"
5944 "Restart interval in minutes\n"
5945 "Only give warning message when limit is exceeded\n")
5946 {
5947 int idx_peer = 2;
5948 return peer_maximum_prefix_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5949 bgp_node_safi (vty));
5950 }
5951
5952 ALIAS_HIDDEN (no_neighbor_maximum_prefix,
5953 no_neighbor_maximum_prefix_hidden_cmd,
5954 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5955 NO_STR
5956 NEIGHBOR_STR
5957 NEIGHBOR_ADDR_STR2
5958 "Maximum number of prefixes to accept from this peer\n"
5959 "maximum no. of prefix limit\n"
5960 "Threshold value (%) at which to generate a warning msg\n"
5961 "Restart bgp connection after limit is exceeded\n"
5962 "Restart interval in minutes\n"
5963 "Only give warning message when limit is exceeded\n")
5964
5965
5966 /* "neighbor allowas-in" */
5967 DEFUN (neighbor_allowas_in,
5968 neighbor_allowas_in_cmd,
5969 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5970 NEIGHBOR_STR
5971 NEIGHBOR_ADDR_STR2
5972 "Accept as-path with my AS present in it\n"
5973 "Number of occurances of AS number\n"
5974 "Only accept my AS in the as-path if the route was originated in my AS\n")
5975 {
5976 int idx_peer = 1;
5977 int idx_number_origin = 3;
5978 int ret;
5979 int origin = 0;
5980 struct peer *peer;
5981 int allow_num = 0;
5982
5983 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
5984 if (! peer)
5985 return CMD_WARNING_CONFIG_FAILED;
5986
5987 if (argc <= idx_number_origin)
5988 allow_num = 3;
5989 else
5990 {
5991 if (argv[idx_number_origin]->type == WORD_TKN)
5992 origin = 1;
5993 else
5994 allow_num = atoi (argv[idx_number_origin]->arg);
5995 }
5996
5997 ret = peer_allowas_in_set (peer, bgp_node_afi (vty), bgp_node_safi (vty),
5998 allow_num, origin);
5999
6000 return bgp_vty_return (vty, ret);
6001 }
6002
6003 ALIAS_HIDDEN (neighbor_allowas_in,
6004 neighbor_allowas_in_hidden_cmd,
6005 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6006 NEIGHBOR_STR
6007 NEIGHBOR_ADDR_STR2
6008 "Accept as-path with my AS present in it\n"
6009 "Number of occurances of AS number\n"
6010 "Only accept my AS in the as-path if the route was originated in my AS\n")
6011
6012 DEFUN (no_neighbor_allowas_in,
6013 no_neighbor_allowas_in_cmd,
6014 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6015 NO_STR
6016 NEIGHBOR_STR
6017 NEIGHBOR_ADDR_STR2
6018 "allow local ASN appears in aspath attribute\n"
6019 "Number of occurances of AS number\n"
6020 "Only accept my AS in the as-path if the route was originated in my AS\n")
6021 {
6022 int idx_peer = 2;
6023 int ret;
6024 struct peer *peer;
6025
6026 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
6027 if (! peer)
6028 return CMD_WARNING_CONFIG_FAILED;
6029
6030 ret = peer_allowas_in_unset (peer, bgp_node_afi (vty), bgp_node_safi (vty));
6031
6032 return bgp_vty_return (vty, ret);
6033 }
6034
6035 ALIAS_HIDDEN (no_neighbor_allowas_in,
6036 no_neighbor_allowas_in_hidden_cmd,
6037 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6038 NO_STR
6039 NEIGHBOR_STR
6040 NEIGHBOR_ADDR_STR2
6041 "allow local ASN appears in aspath attribute\n"
6042 "Number of occurances of AS number\n"
6043 "Only accept my AS in the as-path if the route was originated in my AS\n")
6044
6045 DEFUN (neighbor_ttl_security,
6046 neighbor_ttl_security_cmd,
6047 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6048 NEIGHBOR_STR
6049 NEIGHBOR_ADDR_STR2
6050 "BGP ttl-security parameters\n"
6051 "Specify the maximum number of hops to the BGP peer\n"
6052 "Number of hops to BGP peer\n")
6053 {
6054 int idx_peer = 1;
6055 int idx_number = 4;
6056 struct peer *peer;
6057 int gtsm_hops;
6058
6059 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
6060 if (! peer)
6061 return CMD_WARNING_CONFIG_FAILED;
6062
6063 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6064
6065 /*
6066 * If 'neighbor swpX', then this is for directly connected peers,
6067 * we should not accept a ttl-security hops value greater than 1.
6068 */
6069 if (peer->conf_if && (gtsm_hops > 1)) {
6070 vty_out (vty, "%s is directly connected peer, hops cannot exceed 1%s",
6071 argv[idx_peer]->arg, VTYNL);
6072 return CMD_WARNING_CONFIG_FAILED;
6073 }
6074
6075 return bgp_vty_return (vty, peer_ttl_security_hops_set (peer, gtsm_hops));
6076 }
6077
6078 DEFUN (no_neighbor_ttl_security,
6079 no_neighbor_ttl_security_cmd,
6080 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6081 NO_STR
6082 NEIGHBOR_STR
6083 NEIGHBOR_ADDR_STR2
6084 "BGP ttl-security parameters\n"
6085 "Specify the maximum number of hops to the BGP peer\n"
6086 "Number of hops to BGP peer\n")
6087 {
6088 int idx_peer = 2;
6089 struct peer *peer;
6090
6091 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
6092 if (! peer)
6093 return CMD_WARNING_CONFIG_FAILED;
6094
6095 return bgp_vty_return (vty, peer_ttl_security_hops_unset (peer));
6096 }
6097
6098 DEFUN (neighbor_addpath_tx_all_paths,
6099 neighbor_addpath_tx_all_paths_cmd,
6100 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
6103 "Use addpath to advertise all paths to a neighbor\n")
6104 {
6105 int idx_peer = 1;
6106 struct peer *peer;
6107
6108 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
6109 if (! peer)
6110 return CMD_WARNING_CONFIG_FAILED;
6111
6112 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
6113 bgp_node_safi (vty),
6114 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6115 }
6116
6117 ALIAS_HIDDEN (neighbor_addpath_tx_all_paths,
6118 neighbor_addpath_tx_all_paths_hidden_cmd,
6119 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6120 NEIGHBOR_STR
6121 NEIGHBOR_ADDR_STR2
6122 "Use addpath to advertise all paths to a neighbor\n")
6123
6124 DEFUN (no_neighbor_addpath_tx_all_paths,
6125 no_neighbor_addpath_tx_all_paths_cmd,
6126 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6127 NO_STR
6128 NEIGHBOR_STR
6129 NEIGHBOR_ADDR_STR2
6130 "Use addpath to advertise all paths to a neighbor\n")
6131 {
6132 int idx_peer = 2;
6133 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
6134 bgp_node_safi (vty),
6135 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6136 }
6137
6138 ALIAS_HIDDEN (no_neighbor_addpath_tx_all_paths,
6139 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6140 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6141 NO_STR
6142 NEIGHBOR_STR
6143 NEIGHBOR_ADDR_STR2
6144 "Use addpath to advertise all paths to a neighbor\n")
6145
6146 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6147 neighbor_addpath_tx_bestpath_per_as_cmd,
6148 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6149 NEIGHBOR_STR
6150 NEIGHBOR_ADDR_STR2
6151 "Use addpath to advertise the bestpath per each neighboring AS\n")
6152 {
6153 int idx_peer = 1;
6154 struct peer *peer;
6155
6156 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
6157 if (! peer)
6158 return CMD_WARNING_CONFIG_FAILED;
6159
6160 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
6161 bgp_node_safi (vty),
6162 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6163 }
6164
6165 ALIAS_HIDDEN (neighbor_addpath_tx_bestpath_per_as,
6166 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6167 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6168 NEIGHBOR_STR
6169 NEIGHBOR_ADDR_STR2
6170 "Use addpath to advertise the bestpath per each neighboring AS\n")
6171
6172 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6173 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6174 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6175 NO_STR
6176 NEIGHBOR_STR
6177 NEIGHBOR_ADDR_STR2
6178 "Use addpath to advertise the bestpath per each neighboring AS\n")
6179 {
6180 int idx_peer = 2;
6181 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
6182 bgp_node_safi (vty),
6183 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6184 }
6185
6186 ALIAS_HIDDEN (no_neighbor_addpath_tx_bestpath_per_as,
6187 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6188 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6189 NO_STR
6190 NEIGHBOR_STR
6191 NEIGHBOR_ADDR_STR2
6192 "Use addpath to advertise the bestpath per each neighboring AS\n")
6193
6194 DEFUN_NOSH (address_family_ipv4_safi,
6195 address_family_ipv4_safi_cmd,
6196 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
6197 "Enter Address Family command mode\n"
6198 "Address Family\n"
6199 BGP_SAFI_WITH_LABEL_HELP_STR)
6200 {
6201
6202 if (argc == 3)
6203 {
6204 safi_t safi = bgp_vty_safi_from_str (argv[2]->text);
6205 vty->node = bgp_node_type(AFI_IP, safi);
6206 }
6207 else
6208 vty->node = BGP_IPV4_NODE;
6209
6210 return CMD_SUCCESS;
6211 }
6212
6213 DEFUN_NOSH (address_family_ipv6_safi,
6214 address_family_ipv6_safi_cmd,
6215 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
6216 "Enter Address Family command mode\n"
6217 "Address Family\n"
6218 BGP_SAFI_WITH_LABEL_HELP_STR)
6219 {
6220 if (argc == 3)
6221 {
6222 safi_t safi = bgp_vty_safi_from_str (argv[2]->text);
6223 vty->node = bgp_node_type(AFI_IP6, safi);
6224 }
6225 else
6226 vty->node = BGP_IPV6_NODE;
6227
6228 return CMD_SUCCESS;
6229 }
6230
6231 #ifdef KEEP_OLD_VPN_COMMANDS
6232 DEFUN_NOSH (address_family_vpnv4,
6233 address_family_vpnv4_cmd,
6234 "address-family vpnv4 [unicast]",
6235 "Enter Address Family command mode\n"
6236 "Address Family\n"
6237 "Address Family modifier\n")
6238 {
6239 vty->node = BGP_VPNV4_NODE;
6240 return CMD_SUCCESS;
6241 }
6242
6243 DEFUN_NOSH (address_family_vpnv6,
6244 address_family_vpnv6_cmd,
6245 "address-family vpnv6 [unicast]",
6246 "Enter Address Family command mode\n"
6247 "Address Family\n"
6248 "Address Family modifier\n")
6249 {
6250 vty->node = BGP_VPNV6_NODE;
6251 return CMD_SUCCESS;
6252 }
6253 #endif
6254
6255 DEFUN_NOSH (address_family_evpn,
6256 address_family_evpn_cmd,
6257 "address-family l2vpn evpn",
6258 "Enter Address Family command mode\n"
6259 "Address Family\n"
6260 "Address Family modifier\n")
6261 {
6262 vty->node = BGP_EVPN_NODE;
6263 return CMD_SUCCESS;
6264 }
6265
6266 DEFUN_NOSH (exit_address_family,
6267 exit_address_family_cmd,
6268 "exit-address-family",
6269 "Exit from Address Family configuration mode\n")
6270 {
6271 if (vty->node == BGP_IPV4_NODE
6272 || vty->node == BGP_IPV4M_NODE
6273 || vty->node == BGP_IPV4L_NODE
6274 || vty->node == BGP_VPNV4_NODE
6275 || vty->node == BGP_IPV6_NODE
6276 || vty->node == BGP_IPV6M_NODE
6277 || vty->node == BGP_IPV6L_NODE
6278 || vty->node == BGP_VPNV6_NODE
6279 || vty->node == BGP_EVPN_NODE)
6280 vty->node = BGP_NODE;
6281 return CMD_SUCCESS;
6282 }
6283
6284 /* Recalculate bestpath and re-advertise a prefix */
6285 static int
6286 bgp_clear_prefix (struct vty *vty, const char *view_name, const char *ip_str,
6287 afi_t afi, safi_t safi, struct prefix_rd *prd)
6288 {
6289 int ret;
6290 struct prefix match;
6291 struct bgp_node *rn;
6292 struct bgp_node *rm;
6293 struct bgp *bgp;
6294 struct bgp_table *table;
6295 struct bgp_table *rib;
6296
6297 /* BGP structure lookup. */
6298 if (view_name)
6299 {
6300 bgp = bgp_lookup_by_name (view_name);
6301 if (bgp == NULL)
6302 {
6303 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTYNL);
6304 return CMD_WARNING;
6305 }
6306 }
6307 else
6308 {
6309 bgp = bgp_get_default ();
6310 if (bgp == NULL)
6311 {
6312 vty_out (vty, "%% No BGP process is configured%s", VTYNL);
6313 return CMD_WARNING;
6314 }
6315 }
6316
6317 /* Check IP address argument. */
6318 ret = str2prefix (ip_str, &match);
6319 if (! ret)
6320 {
6321 vty_out (vty, "%% address is malformed%s", VTYNL);
6322 return CMD_WARNING;
6323 }
6324
6325 match.family = afi2family (afi);
6326 rib = bgp->rib[afi][safi];
6327
6328 if (safi == SAFI_MPLS_VPN)
6329 {
6330 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
6331 {
6332 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6333 continue;
6334
6335 if ((table = rn->info) != NULL)
6336 {
6337 if ((rm = bgp_node_match (table, &match)) != NULL)
6338 {
6339 if (rm->p.prefixlen == match.prefixlen)
6340 {
6341 SET_FLAG (rn->flags, BGP_NODE_USER_CLEAR);
6342 bgp_process (bgp, rm, afi, safi);
6343 }
6344 bgp_unlock_node (rm);
6345 }
6346 }
6347 }
6348 }
6349 else
6350 {
6351 if ((rn = bgp_node_match (rib, &match)) != NULL)
6352 {
6353 if (rn->p.prefixlen == match.prefixlen)
6354 {
6355 SET_FLAG (rn->flags, BGP_NODE_USER_CLEAR);
6356 bgp_process (bgp, rn, afi, safi);
6357 }
6358 bgp_unlock_node (rn);
6359 }
6360 }
6361
6362 return CMD_SUCCESS;
6363 }
6364
6365 /* one clear bgp command to rule them all */
6366 DEFUN (clear_ip_bgp_all,
6367 clear_ip_bgp_all_cmd,
6368 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
6369 CLEAR_STR
6370 IP_STR
6371 BGP_STR
6372 BGP_INSTANCE_HELP_STR
6373 "Clear all peers\n"
6374 "BGP neighbor address to clear\n"
6375 "BGP IPv6 neighbor to clear\n"
6376 "BGP neighbor on interface to clear\n"
6377 "Clear peers with the AS number\n"
6378 "Clear all external peers\n"
6379 "Clear all members of peer-group\n"
6380 "BGP peer-group name\n"
6381 BGP_AFI_HELP_STR
6382 BGP_SAFI_WITH_LABEL_HELP_STR
6383 BGP_SOFT_STR
6384 BGP_SOFT_IN_STR
6385 BGP_SOFT_OUT_STR
6386 BGP_SOFT_IN_STR
6387 "Push out prefix-list ORF and do inbound soft reconfig\n"
6388 BGP_SOFT_OUT_STR)
6389 {
6390 char *vrf = NULL;
6391
6392 afi_t afi = AFI_IP6;
6393 safi_t safi = SAFI_UNICAST;
6394 enum clear_sort clr_sort = clear_peer;
6395 enum bgp_clear_type clr_type;
6396 char *clr_arg = NULL;
6397
6398 int idx = 0;
6399
6400 /* clear [ip] bgp */
6401 if (argv_find (argv, argc, "ip", &idx))
6402 afi = AFI_IP;
6403
6404 /* [<view|vrf> VIEWVRFNAME] */
6405 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
6406 {
6407 vrf = argv[idx + 1]->arg;
6408 idx += 2;
6409 }
6410
6411 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6412 if (argv_find_and_parse_afi (argv, argc, &idx, &afi))
6413 argv_find_and_parse_safi (argv, argc, &idx, &safi);
6414
6415 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6416 if (argv_find (argv, argc, "*", &idx))
6417 {
6418 clr_sort = clear_all;
6419 }
6420 else if (argv_find (argv, argc, "A.B.C.D", &idx))
6421 {
6422 clr_sort = clear_peer;
6423 clr_arg = argv[idx]->arg;
6424 }
6425 else if (argv_find (argv, argc, "X:X::X:X", &idx))
6426 {
6427 clr_sort = clear_peer;
6428 clr_arg = argv[idx]->arg;
6429 }
6430 else if (argv_find (argv, argc, "peer-group", &idx))
6431 {
6432 clr_sort = clear_group;
6433 idx++;
6434 clr_arg = argv[idx]->arg;
6435 }
6436 else if (argv_find (argv, argc, "WORD", &idx))
6437 {
6438 clr_sort = clear_peer;
6439 clr_arg = argv[idx]->arg;
6440 }
6441 else if (argv_find (argv, argc, "(1-4294967295)", &idx))
6442 {
6443 clr_sort = clear_as;
6444 clr_arg = argv[idx]->arg;
6445 }
6446 else if (argv_find (argv, argc, "external", &idx))
6447 {
6448 clr_sort = clear_external;
6449 }
6450
6451 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6452 if (argv_find (argv, argc, "soft", &idx))
6453 {
6454 if (argv_find (argv, argc, "in", &idx) || argv_find (argv, argc, "out", &idx))
6455 clr_type = strmatch (argv[idx]->text, "in") ? BGP_CLEAR_SOFT_IN : BGP_CLEAR_SOFT_OUT;
6456 else
6457 clr_type = BGP_CLEAR_SOFT_BOTH;
6458 }
6459 else if (argv_find (argv, argc, "in", &idx))
6460 {
6461 clr_type = argv_find (argv, argc, "prefix-filter", &idx) ? BGP_CLEAR_SOFT_IN_ORF_PREFIX : BGP_CLEAR_SOFT_IN;
6462 }
6463 else if (argv_find (argv, argc, "out", &idx))
6464 {
6465 clr_type = BGP_CLEAR_SOFT_OUT;
6466 }
6467 else
6468 clr_type = BGP_CLEAR_SOFT_NONE;
6469
6470 return bgp_clear_vty (vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
6471 }
6472
6473 DEFUN (clear_ip_bgp_prefix,
6474 clear_ip_bgp_prefix_cmd,
6475 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
6476 CLEAR_STR
6477 IP_STR
6478 BGP_STR
6479 BGP_INSTANCE_HELP_STR
6480 "Clear bestpath and re-advertise\n"
6481 "IPv4 prefix\n")
6482 {
6483 char *vrf = NULL;
6484 char *prefix = NULL;
6485
6486 int idx = 0;
6487
6488 /* [<view|vrf> VIEWVRFNAME] */
6489 if (argv_find (argv, argc, "WORD", &idx))
6490 vrf = argv[idx]->arg;
6491
6492 prefix = argv[argc-1]->arg;
6493
6494 return bgp_clear_prefix (vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
6495 }
6496
6497 DEFUN (clear_bgp_ipv6_safi_prefix,
6498 clear_bgp_ipv6_safi_prefix_cmd,
6499 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
6500 CLEAR_STR
6501 IP_STR
6502 BGP_STR
6503 "Address Family\n"
6504 BGP_SAFI_HELP_STR
6505 "Clear bestpath and re-advertise\n"
6506 "IPv6 prefix\n")
6507 {
6508 int idx_safi = 3;
6509 int idx_ipv6_prefixlen = 5;
6510 return bgp_clear_prefix (vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6511 bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
6512 }
6513
6514 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6515 clear_bgp_instance_ipv6_safi_prefix_cmd,
6516 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
6517 CLEAR_STR
6518 IP_STR
6519 BGP_STR
6520 BGP_INSTANCE_HELP_STR
6521 "Address Family\n"
6522 BGP_SAFI_HELP_STR
6523 "Clear bestpath and re-advertise\n"
6524 "IPv6 prefix\n")
6525 {
6526 int idx_word = 3;
6527 int idx_safi = 5;
6528 int idx_ipv6_prefixlen = 7;
6529 return bgp_clear_prefix (vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6530 bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
6531 }
6532
6533 DEFUN (show_bgp_views,
6534 show_bgp_views_cmd,
6535 "show [ip] bgp views",
6536 SHOW_STR
6537 IP_STR
6538 BGP_STR
6539 "Show the defined BGP views\n")
6540 {
6541 struct list *inst = bm->bgp;
6542 struct listnode *node;
6543 struct bgp *bgp;
6544
6545 if (!bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE))
6546 {
6547 vty_out (vty, "BGP Multiple Instance is not enabled%s", VTYNL);
6548 return CMD_WARNING;
6549 }
6550
6551 vty_out (vty, "Defined BGP views:%s", VTYNL);
6552 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp))
6553 {
6554 /* Skip VRFs. */
6555 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6556 continue;
6557 vty_out (vty, "\t%s (AS%u)%s",
6558 bgp->name ? bgp->name : "(null)",
6559 bgp->as, VTYNL);
6560 }
6561
6562 return CMD_SUCCESS;
6563 }
6564
6565 DEFUN (show_bgp_vrfs,
6566 show_bgp_vrfs_cmd,
6567 "show [ip] bgp vrfs [json]",
6568 SHOW_STR
6569 IP_STR
6570 BGP_STR
6571 "Show BGP VRFs\n"
6572 JSON_STR)
6573 {
6574 struct list *inst = bm->bgp;
6575 struct listnode *node;
6576 struct bgp *bgp;
6577 u_char uj = use_json(argc, argv);
6578 json_object *json = NULL;
6579 json_object *json_vrfs = NULL;
6580 int count = 0;
6581 static char header[] = "Type Id RouterId #PeersCfg #PeersEstb Name";
6582
6583 if (!bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE))
6584 {
6585 vty_out (vty, "BGP Multiple Instance is not enabled%s", VTYNL);
6586 return CMD_WARNING;
6587 }
6588
6589 if (uj)
6590 {
6591 json = json_object_new_object();
6592 json_vrfs = json_object_new_object();
6593 }
6594
6595 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp))
6596 {
6597 const char *name, *type;
6598 struct peer *peer;
6599 struct listnode *node, *nnode;
6600 int peers_cfg, peers_estb;
6601 json_object *json_vrf = NULL;
6602 int vrf_id_ui;
6603
6604 /* Skip Views. */
6605 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6606 continue;
6607
6608 count++;
6609 if (!uj && count == 1)
6610 vty_out (vty, "%s%s", header, VTYNL);
6611
6612 peers_cfg = peers_estb = 0;
6613 if (uj)
6614 json_vrf = json_object_new_object();
6615
6616
6617 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6618 {
6619 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6620 continue;
6621 peers_cfg++;
6622 if (peer->status == Established)
6623 peers_estb++;
6624 }
6625
6626 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6627 {
6628 name = "Default";
6629 type = "DFLT";
6630 }
6631 else
6632 {
6633 name = bgp->name;
6634 type = "VRF";
6635 }
6636
6637 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
6638 if (uj)
6639 {
6640 json_object_string_add(json_vrf, "type", type);
6641 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
6642 json_object_string_add(json_vrf, "routerId", inet_ntoa (bgp->router_id));
6643 json_object_int_add(json_vrf, "numConfiguredPeers", peers_cfg);
6644 json_object_int_add(json_vrf, "numEstablishedPeers", peers_estb);
6645
6646 json_object_object_add(json_vrfs, name, json_vrf);
6647 }
6648 else
6649 vty_out (vty, "%4s %-5d %-16s %9u %10u %s%s",
6650 type, vrf_id_ui, inet_ntoa (bgp->router_id),
6651 peers_cfg, peers_estb, name,
6652 VTYNL);
6653 }
6654
6655 if (uj)
6656 {
6657 json_object_object_add(json, "vrfs", json_vrfs);
6658
6659 json_object_int_add(json, "totalVrfs", count);
6660
6661 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTYNL);
6662 json_object_free(json);
6663 }
6664 else
6665 {
6666 if (count)
6667 vty_out (vty, "%sTotal number of VRFs (including default): %d%s",
6668 VTYNL, count, VTYNL);
6669 }
6670
6671 return CMD_SUCCESS;
6672 }
6673
6674 DEFUN (show_bgp_memory,
6675 show_bgp_memory_cmd,
6676 "show [ip] bgp memory",
6677 SHOW_STR
6678 IP_STR
6679 BGP_STR
6680 "Global BGP memory statistics\n")
6681 {
6682 char memstrbuf[MTYPE_MEMSTR_LEN];
6683 unsigned long count;
6684
6685 /* RIB related usage stats */
6686 count = mtype_stats_alloc (MTYPE_BGP_NODE);
6687 vty_out (vty, "%ld RIB nodes, using %s of memory%s", count,
6688 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6689 count * sizeof (struct bgp_node)),
6690 VTYNL);
6691
6692 count = mtype_stats_alloc (MTYPE_BGP_ROUTE);
6693 vty_out (vty, "%ld BGP routes, using %s of memory%s", count,
6694 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6695 count * sizeof (struct bgp_info)),
6696 VTYNL);
6697 if ((count = mtype_stats_alloc (MTYPE_BGP_ROUTE_EXTRA)))
6698 vty_out (vty, "%ld BGP route ancillaries, using %s of memory%s", count,
6699 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6700 count * sizeof (struct bgp_info_extra)),
6701 VTYNL);
6702
6703 if ((count = mtype_stats_alloc (MTYPE_BGP_STATIC)))
6704 vty_out (vty, "%ld Static routes, using %s of memory%s", count,
6705 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6706 count * sizeof (struct bgp_static)),
6707 VTYNL);
6708
6709 if ((count = mtype_stats_alloc (MTYPE_BGP_PACKET)))
6710 vty_out (vty, "%ld Packets, using %s of memory%s", count,
6711 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6712 count * sizeof (struct bpacket)),
6713 VTYNL);
6714
6715 /* Adj-In/Out */
6716 if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_IN)))
6717 vty_out (vty, "%ld Adj-In entries, using %s of memory%s", count,
6718 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6719 count * sizeof (struct bgp_adj_in)),
6720 VTYNL);
6721 if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_OUT)))
6722 vty_out (vty, "%ld Adj-Out entries, using %s of memory%s", count,
6723 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6724 count * sizeof (struct bgp_adj_out)),
6725 VTYNL);
6726
6727 if ((count = mtype_stats_alloc (MTYPE_BGP_NEXTHOP_CACHE)))
6728 vty_out (vty, "%ld Nexthop cache entries, using %s of memory%s", count,
6729 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6730 count * sizeof (struct bgp_nexthop_cache)),
6731 VTYNL);
6732
6733 if ((count = mtype_stats_alloc (MTYPE_BGP_DAMP_INFO)))
6734 vty_out (vty, "%ld Dampening entries, using %s of memory%s", count,
6735 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6736 count * sizeof (struct bgp_damp_info)),
6737 VTYNL);
6738
6739 /* Attributes */
6740 count = attr_count();
6741 vty_out (vty, "%ld BGP attributes, using %s of memory%s", count,
6742 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6743 count * sizeof(struct attr)),
6744 VTYNL);
6745
6746 if ((count = attr_unknown_count()))
6747 vty_out (vty, "%ld unknown attributes%s", count, VTYNL);
6748
6749 /* AS_PATH attributes */
6750 count = aspath_count ();
6751 vty_out (vty, "%ld BGP AS-PATH entries, using %s of memory%s", count,
6752 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6753 count * sizeof (struct aspath)),
6754 VTYNL);
6755
6756 count = mtype_stats_alloc (MTYPE_AS_SEG);
6757 vty_out (vty, "%ld BGP AS-PATH segments, using %s of memory%s", count,
6758 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6759 count * sizeof (struct assegment)),
6760 VTYNL);
6761
6762 /* Other attributes */
6763 if ((count = community_count ()))
6764 vty_out (vty, "%ld BGP community entries, using %s of memory%s", count,
6765 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6766 count * sizeof (struct community)),
6767 VTYNL);
6768 if ((count = mtype_stats_alloc (MTYPE_ECOMMUNITY)))
6769 vty_out (vty, "%ld BGP community entries, using %s of memory%s", count,
6770 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6771 count * sizeof (struct ecommunity)),
6772 VTYNL);
6773 if ((count = mtype_stats_alloc (MTYPE_LCOMMUNITY)))
6774 vty_out (vty, "%ld BGP large-community entries, using %s of memory%s",
6775 count,
6776 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6777 count * sizeof (struct lcommunity)),
6778 VTYNL);
6779
6780 if ((count = mtype_stats_alloc (MTYPE_CLUSTER)))
6781 vty_out (vty, "%ld Cluster lists, using %s of memory%s", count,
6782 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6783 count * sizeof (struct cluster_list)),
6784 VTYNL);
6785
6786 /* Peer related usage */
6787 count = mtype_stats_alloc (MTYPE_BGP_PEER);
6788 vty_out (vty, "%ld peers, using %s of memory%s", count,
6789 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6790 count * sizeof (struct peer)),
6791 VTYNL);
6792
6793 if ((count = mtype_stats_alloc (MTYPE_PEER_GROUP)))
6794 vty_out (vty, "%ld peer groups, using %s of memory%s", count,
6795 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6796 count * sizeof (struct peer_group)),
6797 VTYNL);
6798
6799 /* Other */
6800 if ((count = mtype_stats_alloc (MTYPE_HASH)))
6801 vty_out (vty, "%ld hash tables, using %s of memory%s", count,
6802 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6803 count * sizeof (struct hash)),
6804 VTYNL);
6805 if ((count = mtype_stats_alloc (MTYPE_HASH_BACKET)))
6806 vty_out (vty, "%ld hash buckets, using %s of memory%s", count,
6807 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6808 count * sizeof (struct hash_backet)),
6809 VTYNL);
6810 if ((count = mtype_stats_alloc (MTYPE_BGP_REGEXP)))
6811 vty_out (vty, "%ld compiled regexes, using %s of memory%s", count,
6812 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6813 count * sizeof (regex_t)),
6814 VTYNL);
6815 return CMD_SUCCESS;
6816 }
6817
6818 /* Show BGP peer's summary information. */
6819 static int
6820 bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi,
6821 u_char use_json, json_object *json)
6822 {
6823 struct peer *peer;
6824 struct listnode *node, *nnode;
6825 unsigned int count = 0, dn_count = 0;
6826 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
6827 char neighbor_buf[VTY_BUFSIZ];
6828 int neighbor_col_default_width = 16;
6829 int len;
6830 int max_neighbor_width = 0;
6831 int pfx_rcd_safi;
6832 json_object *json_peer = NULL;
6833 json_object *json_peers = NULL;
6834
6835 /* labeled-unicast routes are installed in the unicast table so in order to
6836 * display the correct PfxRcd value we must look at SAFI_UNICAST
6837 */
6838 if (safi == SAFI_LABELED_UNICAST)
6839 pfx_rcd_safi = SAFI_UNICAST;
6840 else
6841 pfx_rcd_safi = safi;
6842
6843 if (use_json)
6844 {
6845 if (json == NULL)
6846 json = json_object_new_object();
6847
6848 json_peers = json_object_new_object();
6849 }
6850 else
6851 {
6852 /* Loop over all neighbors that will be displayed to determine how many
6853 * characters are needed for the Neighbor column
6854 */
6855 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6856 {
6857 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6858 continue;
6859
6860 if (peer->afc[afi][safi])
6861 {
6862 memset(dn_flag, '\0', sizeof(dn_flag));
6863 if (peer_dynamic_neighbor(peer))
6864 dn_flag[0] = '*';
6865
6866 if (peer->hostname && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
6867 sprintf(neighbor_buf, "%s%s(%s) ", dn_flag, peer->hostname, peer->host);
6868 else
6869 sprintf(neighbor_buf, "%s%s ", dn_flag, peer->host);
6870
6871 len = strlen(neighbor_buf);
6872
6873 if (len > max_neighbor_width)
6874 max_neighbor_width = len;
6875 }
6876 }
6877
6878 /* Originally we displayed the Neighbor column as 16
6879 * characters wide so make that the default
6880 */
6881 if (max_neighbor_width < neighbor_col_default_width)
6882 max_neighbor_width = neighbor_col_default_width;
6883 }
6884
6885 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6886 {
6887 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6888 continue;
6889
6890 if (peer->afc[afi][safi])
6891 {
6892 if (!count)
6893 {
6894 unsigned long ents;
6895 char memstrbuf[MTYPE_MEMSTR_LEN];
6896 int vrf_id_ui;
6897
6898 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
6899
6900 /* Usage summary and header */
6901 if (use_json)
6902 {
6903 json_object_string_add(json, "routerId", inet_ntoa (bgp->router_id));
6904 json_object_int_add(json, "as", bgp->as);
6905 json_object_int_add(json, "vrfId", vrf_id_ui);
6906 json_object_string_add(json, "vrfName",
6907 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6908 ? "Default" : bgp->name);
6909 }
6910 else
6911 {
6912 vty_out (vty,
6913 "BGP router identifier %s, local AS number %u vrf-id %d",
6914 inet_ntoa (bgp->router_id), bgp->as, vrf_id_ui);
6915 vty_out (vty, "%s", VTYNL);
6916 }
6917
6918 if (bgp_update_delay_configured(bgp))
6919 {
6920 if (use_json)
6921 {
6922 json_object_int_add(json, "updateDelayLimit", bgp->v_update_delay);
6923
6924 if (bgp->v_update_delay != bgp->v_establish_wait)
6925 json_object_int_add(json, "updateDelayEstablishWait", bgp->v_establish_wait);
6926
6927 if (bgp_update_delay_active(bgp))
6928 {
6929 json_object_string_add(json, "updateDelayFirstNeighbor", bgp->update_delay_begin_time);
6930 json_object_boolean_true_add(json, "updateDelayInProgress");
6931 }
6932 else
6933 {
6934 if (bgp->update_delay_over)
6935 {
6936 json_object_string_add(json, "updateDelayFirstNeighbor",
6937 bgp->update_delay_begin_time);
6938 json_object_string_add(json, "updateDelayBestpathResumed",
6939 bgp->update_delay_end_time);
6940 json_object_string_add(json, "updateDelayZebraUpdateResume",
6941 bgp->update_delay_zebra_resume_time);
6942 json_object_string_add(json, "updateDelayPeerUpdateResume",
6943 bgp->update_delay_peers_resume_time);
6944 }
6945 }
6946 }
6947 else
6948 {
6949 vty_out (vty, "Read-only mode update-delay limit: %d seconds%s",
6950 bgp->v_update_delay, VTYNL);
6951 if (bgp->v_update_delay != bgp->v_establish_wait)
6952 vty_out (vty, " Establish wait: %d seconds%s",
6953 bgp->v_establish_wait, VTYNL);
6954
6955 if (bgp_update_delay_active(bgp))
6956 {
6957 vty_out (vty, " First neighbor established: %s%s",
6958 bgp->update_delay_begin_time, VTYNL);
6959 vty_out (vty, " Delay in progress%s", VTYNL);
6960 }
6961 else
6962 {
6963 if (bgp->update_delay_over)
6964 {
6965 vty_out (vty, " First neighbor established: %s%s",
6966 bgp->update_delay_begin_time, VTYNL);
6967 vty_out (vty, " Best-paths resumed: %s%s",
6968 bgp->update_delay_end_time, VTYNL);
6969 vty_out (vty, " zebra update resumed: %s%s",
6970 bgp->update_delay_zebra_resume_time, VTYNL);
6971 vty_out (vty, " peers update resumed: %s%s",
6972 bgp->update_delay_peers_resume_time, VTYNL);
6973 }
6974 }
6975 }
6976 }
6977
6978 if (use_json)
6979 {
6980 if (bgp_maxmed_onstartup_configured(bgp) && bgp->maxmed_active)
6981 json_object_boolean_true_add(json, "maxMedOnStartup");
6982 if (bgp->v_maxmed_admin)
6983 json_object_boolean_true_add(json, "maxMedAdministrative");
6984
6985 json_object_int_add(json, "tableVersion", bgp_table_version(bgp->rib[afi][safi]));
6986
6987 ents = bgp_table_count (bgp->rib[afi][safi]);
6988 json_object_int_add(json, "ribCount", ents);
6989 json_object_int_add(json, "ribMemory", ents * sizeof (struct bgp_node));
6990
6991 ents = listcount (bgp->peer);
6992 json_object_int_add(json, "peerCount", ents);
6993 json_object_int_add(json, "peerMemory", ents * sizeof (struct peer));
6994
6995 if ((ents = listcount (bgp->group)))
6996 {
6997 json_object_int_add(json, "peerGroupCount", ents);
6998 json_object_int_add(json, "peerGroupMemory", ents * sizeof (struct peer_group));
6999 }
7000
7001 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
7002 json_object_boolean_true_add(json, "dampeningEnabled");
7003 }
7004 else
7005 {
7006 if (bgp_maxmed_onstartup_configured(bgp) && bgp->maxmed_active)
7007 vty_out (vty, "Max-med on-startup active%s", VTYNL);
7008 if (bgp->v_maxmed_admin)
7009 vty_out (vty, "Max-med administrative active%s", VTYNL);
7010
7011 vty_out(vty, "BGP table version %" PRIu64 "%s",
7012 bgp_table_version(bgp->rib[afi][safi]), VTYNL);
7013
7014 ents = bgp_table_count (bgp->rib[afi][safi]);
7015 vty_out (vty, "RIB entries %ld, using %s of memory%s", ents,
7016 mtype_memstr (memstrbuf, sizeof (memstrbuf),
7017 ents * sizeof (struct bgp_node)),
7018 VTYNL);
7019
7020 /* Peer related usage */
7021 ents = listcount (bgp->peer);
7022 vty_out (vty, "Peers %ld, using %s of memory%s",
7023 ents,
7024 mtype_memstr (memstrbuf, sizeof (memstrbuf),
7025 ents * sizeof (struct peer)),
7026 VTYNL);
7027
7028 if ((ents = listcount (bgp->group)))
7029 vty_out (vty, "Peer groups %ld, using %s of memory%s", ents,
7030 mtype_memstr (memstrbuf, sizeof (memstrbuf),
7031 ents * sizeof (struct peer_group)),
7032 VTYNL);
7033
7034 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
7035 vty_out (vty, "Dampening enabled.%s", VTYNL);
7036 vty_out (vty, "%s", VTYNL);
7037
7038 /* Subtract 8 here because 'Neighbor' is 8 characters */
7039 vty_out (vty, "Neighbor");
7040 vty_out (vty, "%*s", max_neighbor_width - 8, " ");
7041 vty_out (vty, "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd%s", VTYNL);
7042 }
7043 }
7044
7045 count++;
7046
7047 if (use_json)
7048 {
7049 json_peer = json_object_new_object();
7050
7051 if (peer_dynamic_neighbor(peer))
7052 json_object_boolean_true_add(json_peer, "dynamicPeer");
7053
7054 if (peer->hostname)
7055 json_object_string_add(json_peer, "hostname", peer->hostname);
7056
7057 if (peer->domainname)
7058 json_object_string_add(json_peer, "domainname", peer->domainname);
7059
7060 json_object_int_add(json_peer, "remoteAs", peer->as);
7061 json_object_int_add(json_peer, "version", 4);
7062 json_object_int_add(json_peer, "msgRcvd",
7063 peer->open_in + peer->update_in + peer->keepalive_in
7064 + peer->notify_in + peer->refresh_in
7065 + peer->dynamic_cap_in);
7066 json_object_int_add(json_peer, "msgSent",
7067 peer->open_out + peer->update_out + peer->keepalive_out
7068 + peer->notify_out + peer->refresh_out
7069 + peer->dynamic_cap_out);
7070
7071 json_object_int_add(json_peer, "tableVersion", peer->version[afi][safi]);
7072 json_object_int_add(json_peer, "outq", peer->obuf->count);
7073 json_object_int_add(json_peer, "inq", 0);
7074 peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN, use_json, json_peer);
7075 json_object_int_add(json_peer, "prefixReceivedCount", peer->pcount[afi][pfx_rcd_safi]);
7076
7077 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
7078 json_object_string_add(json_peer, "state", "Idle (Admin)");
7079 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
7080 json_object_string_add(json_peer, "state", "Idle (PfxCt)");
7081 else
7082 json_object_string_add(json_peer, "state", lookup_msg(bgp_status_msg, peer->status, NULL));
7083
7084 if (peer->conf_if)
7085 json_object_string_add(json_peer, "idType", "interface");
7086 else if (peer->su.sa.sa_family == AF_INET)
7087 json_object_string_add(json_peer, "idType", "ipv4");
7088 else if (peer->su.sa.sa_family == AF_INET6)
7089 json_object_string_add(json_peer, "idType", "ipv6");
7090
7091 json_object_object_add(json_peers, peer->host, json_peer);
7092 }
7093 else
7094 {
7095 memset(dn_flag, '\0', sizeof(dn_flag));
7096 if (peer_dynamic_neighbor(peer))
7097 {
7098 dn_count++;
7099 dn_flag[0] = '*';
7100 }
7101
7102 if (peer->hostname && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7103 len = vty_out (vty, "%s%s(%s)", dn_flag, peer->hostname,
7104 peer->host);
7105 else
7106 len = vty_out (vty, "%s%s", dn_flag, peer->host);
7107
7108 /* pad the neighbor column with spaces */
7109 if (len < max_neighbor_width)
7110 vty_out (vty, "%*s", max_neighbor_width - len, " ");
7111
7112 vty_out (vty, "4 %10u %7d %7d %8" PRIu64 " %4d %4zd %8s",
7113 peer->as,
7114 peer->open_in + peer->update_in + peer->keepalive_in
7115 + peer->notify_in + peer->refresh_in
7116 + peer->dynamic_cap_in,
7117 peer->open_out + peer->update_out + peer->keepalive_out
7118 + peer->notify_out + peer->refresh_out
7119 + peer->dynamic_cap_out,
7120 peer->version[afi][safi],
7121 0,
7122 peer->obuf->count,
7123 peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
7124
7125 if (peer->status == Established)
7126 vty_out (vty, " %12ld", peer->pcount[afi][pfx_rcd_safi]);
7127 else
7128 {
7129 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
7130 vty_out (vty, " Idle (Admin)");
7131 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
7132 vty_out (vty, " Idle (PfxCt)");
7133 else
7134 vty_out (vty, " %12s", lookup_msg(bgp_status_msg, peer->status, NULL));
7135 }
7136 vty_out (vty, "%s", VTYNL);
7137 }
7138 }
7139 }
7140
7141 if (use_json)
7142 {
7143 json_object_object_add(json, "peers", json_peers);
7144
7145 json_object_int_add(json, "totalPeers", count);
7146 json_object_int_add(json, "dynamicPeers", dn_count);
7147
7148 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTYNL);
7149 json_object_free(json);
7150 }
7151 else
7152 {
7153 if (count)
7154 vty_out (vty, "%sTotal number of neighbors %d%s", VTYNL,
7155 count, VTYNL);
7156 else
7157 {
7158 if (use_json)
7159 vty_out(vty, "{\"error\": {\"message\": \"No %s neighbor configured\"}}%s",
7160 afi_safi_print(afi, safi), VTYNL);
7161 else
7162 vty_out (vty, "No %s neighbor is configured%s",
7163 afi_safi_print(afi, safi), VTYNL);
7164 }
7165
7166 if (dn_count && ! use_json)
7167 {
7168 vty_out(vty, "* - dynamic neighbor%s", VTYNL);
7169 vty_out(vty,
7170 "%d dynamic neighbor(s), limit %d%s",
7171 dn_count, bgp->dynamic_neighbors_limit, VTYNL);
7172 }
7173 }
7174
7175 return CMD_SUCCESS;
7176 }
7177
7178 /*
7179 * Return if we have a peer configured to use this afi/safi
7180 */
7181 static int
7182 bgp_show_summary_afi_safi_peer_exists (struct bgp *bgp, int afi, int safi)
7183 {
7184 struct listnode *node;
7185 struct peer *peer;
7186
7187 for (ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer))
7188 {
7189 if (!CHECK_FLAG (peer->flags, PEER_FLAG_CONFIG_NODE))
7190 continue;
7191
7192 if (peer->afc[afi][safi])
7193 return 1;
7194 }
7195
7196 return 0;
7197 }
7198
7199 static void
7200 bgp_show_summary_afi_safi (struct vty *vty, struct bgp *bgp, int afi, int safi,
7201 u_char use_json, json_object *json)
7202 {
7203 int is_first = 1;
7204 int afi_wildcard = (afi == AFI_MAX);
7205 int safi_wildcard = (safi == SAFI_MAX);
7206 int is_wildcard = (afi_wildcard || safi_wildcard);
7207 bool json_output = false;
7208
7209 if (use_json && is_wildcard)
7210 vty_out (vty, "{%s", VTYNL);
7211 if (afi_wildcard)
7212 afi = 1; /* AFI_IP */
7213 while (afi < AFI_MAX)
7214 {
7215 if (safi_wildcard)
7216 safi = 1; /* SAFI_UNICAST */
7217 while (safi < SAFI_MAX)
7218 {
7219 if (bgp_show_summary_afi_safi_peer_exists (bgp, afi, safi))
7220 {
7221 json_output = true;
7222 if (is_wildcard)
7223 {
7224 /*
7225 * So limit output to those afi/safi pairs that
7226 * actualy have something interesting in them
7227 */
7228 if (use_json)
7229 {
7230 json = json_object_new_object();
7231
7232 if (! is_first)
7233 vty_out (vty, ",%s", VTYNL);
7234 else
7235 is_first = 0;
7236
7237 vty_out(vty, "\"%s\":", afi_safi_json(afi, safi));
7238 }
7239 else
7240 {
7241 vty_out (vty, "%s%s Summary:%s",
7242 VTYNL, afi_safi_print(afi, safi), VTYNL);
7243 }
7244 }
7245 bgp_show_summary (vty, bgp, afi, safi, use_json, json);
7246 }
7247 safi++;
7248 if (safi == SAFI_RESERVED_4 ||
7249 safi == SAFI_RESERVED_5) /* handle special cases to match zebra.h */
7250 safi++;
7251 if (! safi_wildcard)
7252 safi = SAFI_MAX;
7253 }
7254 afi++;
7255 if (! afi_wildcard ||
7256 afi == AFI_L2VPN) /* special case, not handled yet */
7257 afi = AFI_MAX;
7258 }
7259
7260 if (use_json && is_wildcard)
7261 vty_out (vty, "}%s", VTYNL);
7262 else if (use_json && !json_output)
7263 vty_out (vty, "{}%s", VTYNL);
7264 }
7265
7266 static void
7267 bgp_show_all_instances_summary_vty (struct vty *vty, afi_t afi, safi_t safi,
7268 u_char use_json)
7269 {
7270 struct listnode *node, *nnode;
7271 struct bgp *bgp;
7272 json_object *json = NULL;
7273 int is_first = 1;
7274
7275 if (use_json)
7276 vty_out (vty, "{%s", VTYNL);
7277
7278 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7279 {
7280 if (use_json)
7281 {
7282 json = json_object_new_object();
7283
7284 if (! is_first)
7285 vty_out (vty, ",%s", VTYNL);
7286 else
7287 is_first = 0;
7288
7289 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7290 ? "Default" : bgp->name);
7291 }
7292 else
7293 {
7294 vty_out (vty, "%sInstance %s:%s",
7295 VTYNL,
7296 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7297 ? "Default" : bgp->name, VTYNL);
7298 }
7299 bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, json);
7300 }
7301
7302 if (use_json)
7303 vty_out (vty, "}%s", VTYNL);
7304
7305 }
7306
7307 int
7308 bgp_show_summary_vty (struct vty *vty, const char *name,
7309 afi_t afi, safi_t safi, u_char use_json)
7310 {
7311 struct bgp *bgp;
7312
7313 if (name)
7314 {
7315 if (strmatch(name, "all"))
7316 {
7317 bgp_show_all_instances_summary_vty (vty, afi, safi, use_json);
7318 return CMD_SUCCESS;
7319 }
7320 else
7321 {
7322 bgp = bgp_lookup_by_name (name);
7323
7324 if (! bgp)
7325 {
7326 if (use_json)
7327 vty_out (vty, "{}%s", VTYNL);
7328 else
7329 vty_out (vty, "%% No such BGP instance exist%s", VTYNL);
7330 return CMD_WARNING;
7331 }
7332
7333 bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL);
7334 return CMD_SUCCESS;
7335 }
7336 }
7337
7338 bgp = bgp_get_default ();
7339
7340 if (bgp)
7341 bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL);
7342
7343 return CMD_SUCCESS;
7344 }
7345
7346 /* `show [ip] bgp summary' commands. */
7347 DEFUN (show_ip_bgp_summary,
7348 show_ip_bgp_summary_cmd,
7349 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
7350 SHOW_STR
7351 IP_STR
7352 BGP_STR
7353 BGP_INSTANCE_HELP_STR
7354 BGP_AFI_HELP_STR
7355 BGP_SAFI_WITH_LABEL_HELP_STR
7356 "Summary of BGP neighbor status\n"
7357 JSON_STR)
7358 {
7359 char *vrf = NULL;
7360 afi_t afi = AFI_MAX;
7361 safi_t safi = SAFI_MAX;
7362
7363 int idx = 0;
7364
7365 /* show [ip] bgp */
7366 if (argv_find (argv, argc, "ip", &idx))
7367 afi = AFI_IP;
7368 /* [<view|vrf> VIEWVRFNAME] */
7369 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
7370 vrf = argv[++idx]->arg;
7371 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7372 if (argv_find_and_parse_afi (argv, argc, &idx, &afi))
7373 {
7374 argv_find_and_parse_safi (argv, argc, &idx, &safi);
7375 }
7376
7377 int uj = use_json (argc, argv);
7378
7379 return bgp_show_summary_vty (vty, vrf, afi, safi, uj);
7380 }
7381
7382 const char *
7383 afi_safi_print (afi_t afi, safi_t safi)
7384 {
7385 if (afi == AFI_IP && safi == SAFI_UNICAST)
7386 return "IPv4 Unicast";
7387 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7388 return "IPv4 Multicast";
7389 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7390 return "IPv4 Labeled Unicast";
7391 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7392 return "IPv4 VPN";
7393 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7394 return "IPv4 Encap";
7395 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7396 return "IPv6 Unicast";
7397 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7398 return "IPv6 Multicast";
7399 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7400 return "IPv6 Labeled Unicast";
7401 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7402 return "IPv6 VPN";
7403 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7404 return "IPv6 Encap";
7405 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7406 return "L2VPN EVPN";
7407 else
7408 return "Unknown";
7409 }
7410
7411 /*
7412 * Please note that we have intentionally camelCased
7413 * the return strings here. So if you want
7414 * to use this function, please ensure you
7415 * are doing this within json output
7416 */
7417 const char *
7418 afi_safi_json (afi_t afi, safi_t safi)
7419 {
7420 if (afi == AFI_IP && safi == SAFI_UNICAST)
7421 return "ipv4Unicast";
7422 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7423 return "ipv4Multicast";
7424 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7425 return "ipv4LabeledUnicast";
7426 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7427 return "ipv4Vpn";
7428 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7429 return "ipv4Encap";
7430 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7431 return "ipv6Unicast";
7432 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7433 return "ipv6Multicast";
7434 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7435 return "ipv6LabeledUnicast";
7436 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7437 return "ipv6Vpn";
7438 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7439 return "ipv6Encap";
7440 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7441 return "l2VpnEvpn";
7442 else
7443 return "Unknown";
7444 }
7445
7446 /* Show BGP peer's information. */
7447 enum show_type
7448 {
7449 show_all,
7450 show_peer
7451 };
7452
7453 static void
7454 bgp_show_peer_afi_orf_cap (struct vty *vty, struct peer *p, afi_t afi, safi_t safi,
7455 u_int16_t adv_smcap, u_int16_t adv_rmcap, u_int16_t rcv_smcap,
7456 u_int16_t rcv_rmcap, u_char use_json, json_object *json_pref)
7457 {
7458 /* Send-Mode */
7459 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap)
7460 || CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
7461 {
7462 if (use_json)
7463 {
7464 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap) && CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
7465 json_object_string_add(json_pref, "sendMode", "advertisedAndReceived");
7466 else if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap))
7467 json_object_string_add(json_pref, "sendMode", "advertised");
7468 else if (CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
7469 json_object_string_add(json_pref, "sendMode", "received");
7470 }
7471 else
7472 {
7473 vty_out (vty, " Send-mode: ");
7474 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap))
7475 vty_out (vty, "advertised");
7476 if (CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
7477 vty_out (vty, "%sreceived",
7478 CHECK_FLAG (p->af_cap[afi][safi], adv_smcap) ?
7479 ", " : "");
7480 vty_out (vty, "%s", VTYNL);
7481 }
7482 }
7483
7484 /* Receive-Mode */
7485 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap)
7486 || CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
7487 {
7488 if (use_json)
7489 {
7490 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap) && CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
7491 json_object_string_add(json_pref, "recvMode", "advertisedAndReceived");
7492 else if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap))
7493 json_object_string_add(json_pref, "recvMode", "advertised");
7494 else if (CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
7495 json_object_string_add(json_pref, "recvMode", "received");
7496 }
7497 else
7498 {
7499 vty_out (vty, " Receive-mode: ");
7500 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap))
7501 vty_out (vty, "advertised");
7502 if (CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
7503 vty_out (vty, "%sreceived",
7504 CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap) ?
7505 ", " : "");
7506 vty_out (vty, "%s", VTYNL);
7507 }
7508 }
7509 }
7510
7511 static void
7512 bgp_show_peer_afi (struct vty *vty, struct peer *p, afi_t afi, safi_t safi,
7513 u_char use_json, json_object *json_neigh)
7514 {
7515 struct bgp_filter *filter;
7516 struct peer_af *paf;
7517 char orf_pfx_name[BUFSIZ];
7518 int orf_pfx_count;
7519 json_object *json_af = NULL;
7520 json_object *json_prefA = NULL;
7521 json_object *json_prefB = NULL;
7522 json_object *json_addr = NULL;
7523
7524 if (use_json)
7525 {
7526 json_addr = json_object_new_object();
7527 json_af = json_object_new_object();
7528 filter = &p->filter[afi][safi];
7529
7530 if (peer_group_active(p))
7531 json_object_string_add(json_addr, "peerGroupMember", p->group->name);
7532
7533 paf = peer_af_find(p, afi, safi);
7534 if (paf && PAF_SUBGRP(paf))
7535 {
7536 json_object_int_add(json_addr, "updateGroupId", PAF_UPDGRP(paf)->id);
7537 json_object_int_add(json_addr, "subGroupId", PAF_SUBGRP(paf)->id);
7538 json_object_int_add(json_addr, "packetQueueLength", bpacket_queue_virtual_length(paf));
7539 }
7540
7541 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7542 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7543 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7544 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV))
7545 {
7546 json_object_int_add(json_af, "orfType", ORF_TYPE_PREFIX);
7547 json_prefA = json_object_new_object();
7548 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7549 PEER_CAP_ORF_PREFIX_SM_ADV,
7550 PEER_CAP_ORF_PREFIX_RM_ADV,
7551 PEER_CAP_ORF_PREFIX_SM_RCV,
7552 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, json_prefA);
7553 json_object_object_add(json_af, "orfPrefixList", json_prefA);
7554 }
7555
7556 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7557 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7558 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7559 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7560 {
7561 json_object_int_add(json_af, "orfOldType", ORF_TYPE_PREFIX_OLD);
7562 json_prefB = json_object_new_object();
7563 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7564 PEER_CAP_ORF_PREFIX_SM_ADV,
7565 PEER_CAP_ORF_PREFIX_RM_ADV,
7566 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7567 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, json_prefB);
7568 json_object_object_add(json_af, "orfOldPrefixList", json_prefB);
7569 }
7570
7571 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7572 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7573 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7574 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7575 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)
7576 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7577 json_object_object_add(json_addr, "afDependentCap", json_af);
7578 else
7579 json_object_free(json_af);
7580
7581 sprintf (orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7582 orf_pfx_count = prefix_bgp_show_prefix_list (NULL, afi, orf_pfx_name, use_json);
7583
7584 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND)
7585 || orf_pfx_count)
7586 {
7587 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND))
7588 json_object_boolean_true_add(json_neigh, "orfSent");
7589 if (orf_pfx_count)
7590 json_object_int_add(json_addr, "orfRecvCounter", orf_pfx_count);
7591 }
7592 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
7593 json_object_string_add(json_addr, "orfFirstUpdate", "deferredUntilORFOrRouteRefreshRecvd");
7594
7595 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
7596 json_object_boolean_true_add(json_addr, "routeReflectorClient");
7597 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
7598 json_object_boolean_true_add(json_addr, "routeServerClient");
7599 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7600 json_object_boolean_true_add(json_addr, "inboundSoftConfigPermit");
7601
7602 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7603 json_object_boolean_true_add(json_addr, "privateAsNumsAllReplacedInUpdatesToNbr");
7604 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7605 json_object_boolean_true_add(json_addr, "privateAsNumsReplacedInUpdatesToNbr");
7606 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7607 json_object_boolean_true_add(json_addr, "privateAsNumsAllRemovedInUpdatesToNbr");
7608 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS))
7609 json_object_boolean_true_add(json_addr, "privateAsNumsRemovedInUpdatesToNbr");
7610
7611 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7612 json_object_boolean_true_add(json_addr, "addpathTxAllPaths");
7613
7614 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7615 json_object_boolean_true_add(json_addr, "addpathTxBestpathPerAS");
7616
7617 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7618 json_object_string_add(json_addr, "overrideASNsInOutboundUpdates", "ifAspathEqualRemoteAs");
7619
7620 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
7621 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
7622 json_object_boolean_true_add(json_addr, "routerAlwaysNextHop");
7623 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_PATH_UNCHANGED))
7624 json_object_boolean_true_add(json_addr, "unchangedAsPathPropogatedToNbr");
7625 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
7626 json_object_boolean_true_add(json_addr, "unchangedNextHopPropogatedToNbr");
7627 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7628 json_object_boolean_true_add(json_addr, "unchangedMedPropogatedToNbr");
7629 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7630 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7631 {
7632 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7633 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7634 json_object_string_add(json_addr, "commAttriSentToNbr", "extendedAndStandard");
7635 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7636 json_object_string_add(json_addr, "commAttriSentToNbr", "extended");
7637 else
7638 json_object_string_add(json_addr, "commAttriSentToNbr", "standard");
7639 }
7640 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
7641 {
7642 if (p->default_rmap[afi][safi].name)
7643 json_object_string_add(json_addr, "defaultRouteMap", p->default_rmap[afi][safi].name);
7644
7645 if (paf && PAF_SUBGRP(paf) && CHECK_FLAG(PAF_SUBGRP(paf)->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
7646 json_object_boolean_true_add(json_addr, "defaultSent");
7647 else
7648 json_object_boolean_true_add(json_addr, "defaultNotSent");
7649 }
7650
7651 if (filter->plist[FILTER_IN].name
7652 || filter->dlist[FILTER_IN].name
7653 || filter->aslist[FILTER_IN].name
7654 || filter->map[RMAP_IN].name)
7655 json_object_boolean_true_add(json_addr, "inboundPathPolicyConfig");
7656 if (filter->plist[FILTER_OUT].name
7657 || filter->dlist[FILTER_OUT].name
7658 || filter->aslist[FILTER_OUT].name
7659 || filter->map[RMAP_OUT].name
7660 || filter->usmap.name)
7661 json_object_boolean_true_add(json_addr, "outboundPathPolicyConfig");
7662
7663 /* prefix-list */
7664 if (filter->plist[FILTER_IN].name)
7665 json_object_string_add(json_addr, "incomingUpdatePrefixFilterList", filter->plist[FILTER_IN].name);
7666 if (filter->plist[FILTER_OUT].name)
7667 json_object_string_add(json_addr, "outgoingUpdatePrefixFilterList", filter->plist[FILTER_OUT].name);
7668
7669 /* distribute-list */
7670 if (filter->dlist[FILTER_IN].name)
7671 json_object_string_add(json_addr, "incomingUpdateNetworkFilterList", filter->dlist[FILTER_IN].name);
7672 if (filter->dlist[FILTER_OUT].name)
7673 json_object_string_add(json_addr, "outgoingUpdateNetworkFilterList", filter->dlist[FILTER_OUT].name);
7674
7675 /* filter-list. */
7676 if (filter->aslist[FILTER_IN].name)
7677 json_object_string_add(json_addr, "incomingUpdateAsPathFilterList", filter->aslist[FILTER_IN].name);
7678 if (filter->aslist[FILTER_OUT].name)
7679 json_object_string_add(json_addr, "outgoingUpdateAsPathFilterList", filter->aslist[FILTER_OUT].name);
7680
7681 /* route-map. */
7682 if (filter->map[RMAP_IN].name)
7683 json_object_string_add(json_addr, "routeMapForIncomingAdvertisements", filter->map[RMAP_IN].name);
7684 if (filter->map[RMAP_OUT].name)
7685 json_object_string_add(json_addr, "routeMapForOutgoingAdvertisements", filter->map[RMAP_OUT].name);
7686
7687 /* unsuppress-map */
7688 if (filter->usmap.name)
7689 json_object_string_add(json_addr, "selectiveUnsuppressRouteMap", filter->usmap.name);
7690
7691 /* Receive prefix count */
7692 json_object_int_add(json_addr, "acceptedPrefixCounter", p->pcount[afi][safi]);
7693
7694 /* Maximum prefix */
7695 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
7696 {
7697 json_object_int_add(json_addr, "prefixAllowedMax", p->pmax[afi][safi]);
7698 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
7699 json_object_boolean_true_add(json_addr, "prefixAllowedMaxWarning");
7700 json_object_int_add(json_addr, "prefixAllowedWarningThresh", p->pmax_threshold[afi][safi]);
7701 if (p->pmax_restart[afi][safi])
7702 json_object_int_add(json_addr, "prefixAllowedRestartIntervalMsecs", p->pmax_restart[afi][safi] * 60000);
7703 }
7704 json_object_object_add(json_neigh, afi_safi_print (afi, safi), json_addr);
7705
7706 }
7707 else
7708 {
7709 filter = &p->filter[afi][safi];
7710
7711 vty_out (vty, " For address family: %s%s", afi_safi_print (afi, safi),
7712 VTYNL);
7713
7714 if (peer_group_active(p))
7715 vty_out (vty, " %s peer-group member%s", p->group->name, VTYNL);
7716
7717 paf = peer_af_find(p, afi, safi);
7718 if (paf && PAF_SUBGRP(paf))
7719 {
7720 vty_out (vty, " Update group %" PRIu64 ", subgroup %" PRIu64 "%s",
7721 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id, VTYNL);
7722 vty_out (vty, " Packet Queue length %d%s",
7723 bpacket_queue_virtual_length(paf), VTYNL);
7724 }
7725 else
7726 {
7727 vty_out(vty, " Not part of any update group%s", VTYNL);
7728 }
7729 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7730 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7731 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7732 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7733 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)
7734 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7735 vty_out (vty, " AF-dependant capabilities:%s", VTYNL);
7736
7737 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7738 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7739 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7740 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV))
7741 {
7742 vty_out (vty, " Outbound Route Filter (ORF) type (%d) Prefix-list:%s",
7743 ORF_TYPE_PREFIX, VTYNL);
7744 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7745 PEER_CAP_ORF_PREFIX_SM_ADV,
7746 PEER_CAP_ORF_PREFIX_RM_ADV,
7747 PEER_CAP_ORF_PREFIX_SM_RCV,
7748 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7749 }
7750 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7751 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7752 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7753 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7754 {
7755 vty_out (vty, " Outbound Route Filter (ORF) type (%d) Prefix-list:%s",
7756 ORF_TYPE_PREFIX_OLD, VTYNL);
7757 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7758 PEER_CAP_ORF_PREFIX_SM_ADV,
7759 PEER_CAP_ORF_PREFIX_RM_ADV,
7760 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7761 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7762 }
7763
7764 sprintf (orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7765 orf_pfx_count = prefix_bgp_show_prefix_list (NULL, afi, orf_pfx_name, use_json);
7766
7767 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND)
7768 || orf_pfx_count)
7769 {
7770 vty_out (vty, " Outbound Route Filter (ORF):");
7771 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND))
7772 vty_out (vty, " sent;");
7773 if (orf_pfx_count)
7774 vty_out (vty, " received (%d entries)", orf_pfx_count);
7775 vty_out (vty, "%s", VTYNL);
7776 }
7777 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
7778 vty_out (vty, " First update is deferred until ORF or ROUTE-REFRESH is received%s", VTYNL);
7779
7780 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
7781 vty_out (vty, " Route-Reflector Client%s", VTYNL);
7782 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
7783 vty_out (vty, " Route-Server Client%s", VTYNL);
7784 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7785 vty_out (vty, " Inbound soft reconfiguration allowed%s", VTYNL);
7786
7787 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7788 vty_out (vty, " Private AS numbers (all) replaced in updates to this neighbor%s", VTYNL);
7789 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7790 vty_out (vty, " Private AS numbers replaced in updates to this neighbor%s", VTYNL);
7791 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7792 vty_out (vty, " Private AS numbers (all) removed in updates to this neighbor%s", VTYNL);
7793 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS))
7794 vty_out (vty, " Private AS numbers removed in updates to this neighbor%s", VTYNL);
7795
7796 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7797 vty_out (vty, " Advertise all paths via addpath%s", VTYNL);
7798
7799 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7800 vty_out (vty, " Advertise bestpath per AS via addpath%s", VTYNL);
7801
7802 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7803 vty_out (vty, " Override ASNs in outbound updates if aspath equals remote-as%s", VTYNL);
7804
7805 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
7806 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
7807 vty_out (vty, " NEXT_HOP is always this router%s", VTYNL);
7808 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_PATH_UNCHANGED))
7809 vty_out (vty, " AS_PATH is propagated unchanged to this neighbor%s", VTYNL);
7810 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
7811 vty_out (vty, " NEXT_HOP is propagated unchanged to this neighbor%s", VTYNL);
7812 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7813 vty_out (vty, " MED is propagated unchanged to this neighbor%s", VTYNL);
7814 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7815 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY)
7816 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY))
7817 {
7818 vty_out (vty, " Community attribute sent to this neighbor");
7819 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7820 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY)
7821 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY))
7822 vty_out (vty, "(all)%s", VTYNL);
7823 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY))
7824 vty_out (vty, "(large)%s", VTYNL);
7825 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7826 vty_out (vty, "(extended)%s", VTYNL);
7827 else
7828 vty_out (vty, "(standard)%s", VTYNL);
7829 }
7830 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
7831 {
7832 vty_out (vty, " Default information originate,");
7833
7834 if (p->default_rmap[afi][safi].name)
7835 vty_out (vty, " default route-map %s%s,",
7836 p->default_rmap[afi][safi].map ? "*" : "",
7837 p->default_rmap[afi][safi].name);
7838 if (paf && PAF_SUBGRP(paf) && CHECK_FLAG(PAF_SUBGRP(paf)->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
7839 vty_out (vty, " default sent%s", VTYNL);
7840 else
7841 vty_out (vty, " default not sent%s", VTYNL);
7842 }
7843
7844 if (filter->plist[FILTER_IN].name
7845 || filter->dlist[FILTER_IN].name
7846 || filter->aslist[FILTER_IN].name
7847 || filter->map[RMAP_IN].name)
7848 vty_out (vty, " Inbound path policy configured%s", VTYNL);
7849 if (filter->plist[FILTER_OUT].name
7850 || filter->dlist[FILTER_OUT].name
7851 || filter->aslist[FILTER_OUT].name
7852 || filter->map[RMAP_OUT].name
7853 || filter->usmap.name)
7854 vty_out (vty, " Outbound path policy configured%s", VTYNL);
7855
7856 /* prefix-list */
7857 if (filter->plist[FILTER_IN].name)
7858 vty_out (vty, " Incoming update prefix filter list is %s%s%s",
7859 filter->plist[FILTER_IN].plist ? "*" : "",
7860 filter->plist[FILTER_IN].name,
7861 VTYNL);
7862 if (filter->plist[FILTER_OUT].name)
7863 vty_out (vty, " Outgoing update prefix filter list is %s%s%s",
7864 filter->plist[FILTER_OUT].plist ? "*" : "",
7865 filter->plist[FILTER_OUT].name,
7866 VTYNL);
7867
7868 /* distribute-list */
7869 if (filter->dlist[FILTER_IN].name)
7870 vty_out (vty, " Incoming update network filter list is %s%s%s",
7871 filter->dlist[FILTER_IN].alist ? "*" : "",
7872 filter->dlist[FILTER_IN].name,
7873 VTYNL);
7874 if (filter->dlist[FILTER_OUT].name)
7875 vty_out (vty, " Outgoing update network filter list is %s%s%s",
7876 filter->dlist[FILTER_OUT].alist ? "*" : "",
7877 filter->dlist[FILTER_OUT].name,
7878 VTYNL);
7879
7880 /* filter-list. */
7881 if (filter->aslist[FILTER_IN].name)
7882 vty_out (vty, " Incoming update AS path filter list is %s%s%s",
7883 filter->aslist[FILTER_IN].aslist ? "*" : "",
7884 filter->aslist[FILTER_IN].name,
7885 VTYNL);
7886 if (filter->aslist[FILTER_OUT].name)
7887 vty_out (vty, " Outgoing update AS path filter list is %s%s%s",
7888 filter->aslist[FILTER_OUT].aslist ? "*" : "",
7889 filter->aslist[FILTER_OUT].name,
7890 VTYNL);
7891
7892 /* route-map. */
7893 if (filter->map[RMAP_IN].name)
7894 vty_out (vty, " Route map for incoming advertisements is %s%s%s",
7895 filter->map[RMAP_IN].map ? "*" : "",
7896 filter->map[RMAP_IN].name,
7897 VTYNL);
7898 if (filter->map[RMAP_OUT].name)
7899 vty_out (vty, " Route map for outgoing advertisements is %s%s%s",
7900 filter->map[RMAP_OUT].map ? "*" : "",
7901 filter->map[RMAP_OUT].name,
7902 VTYNL);
7903
7904 /* unsuppress-map */
7905 if (filter->usmap.name)
7906 vty_out (vty, " Route map for selective unsuppress is %s%s%s",
7907 filter->usmap.map ? "*" : "",
7908 filter->usmap.name, VTYNL);
7909
7910 /* Receive prefix count */
7911 vty_out (vty, " %ld accepted prefixes%s", p->pcount[afi][safi], VTYNL);
7912
7913 /* Maximum prefix */
7914 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
7915 {
7916 vty_out (vty, " Maximum prefixes allowed %ld%s%s", p->pmax[afi][safi],
7917 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING)
7918 ? " (warning-only)" : "", VTYNL);
7919 vty_out (vty, " Threshold for warning message %d%%",
7920 p->pmax_threshold[afi][safi]);
7921 if (p->pmax_restart[afi][safi])
7922 vty_out (vty, ", restart interval %d min", p->pmax_restart[afi][safi]);
7923 vty_out (vty, "%s", VTYNL);
7924 }
7925
7926 vty_out (vty, "%s", VTYNL);
7927 }
7928 }
7929
7930 static void
7931 bgp_show_peer (struct vty *vty, struct peer *p, u_char use_json, json_object *json)
7932 {
7933 struct bgp *bgp;
7934 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
7935 char timebuf[BGP_UPTIME_LEN];
7936 char dn_flag[2];
7937 const char *subcode_str;
7938 const char *code_str;
7939 afi_t afi;
7940 safi_t safi;
7941 u_int16_t i;
7942 u_char *msg;
7943 json_object *json_neigh = NULL;
7944 time_t epoch_tbuf;
7945
7946 bgp = p->bgp;
7947
7948 if (use_json)
7949 json_neigh = json_object_new_object();
7950
7951 memset (dn_flag, '\0', sizeof (dn_flag));
7952 if (!p->conf_if && peer_dynamic_neighbor (p))
7953 dn_flag[0] = '*';
7954
7955 if (!use_json)
7956 {
7957 if (p->conf_if) /* Configured interface name. */
7958 vty_out (vty, "BGP neighbor on %s: %s, ", p->conf_if,
7959 BGP_PEER_SU_UNSPEC(p) ? "None" :
7960 sockunion2str (&p->su, buf, SU_ADDRSTRLEN));
7961 else /* Configured IP address. */
7962 vty_out (vty, "BGP neighbor is %s%s, ", dn_flag, p->host);
7963 }
7964
7965 if (use_json)
7966 {
7967 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
7968 json_object_string_add(json_neigh, "bgpNeighborAddr", "none");
7969 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
7970 json_object_string_add(json_neigh, "bgpNeighborAddr", sockunion2str (&p->su, buf, SU_ADDRSTRLEN));
7971
7972 json_object_int_add(json_neigh, "remoteAs", p->as);
7973
7974 if (p->change_local_as)
7975 json_object_int_add(json_neigh, "localAs", p->change_local_as);
7976 else
7977 json_object_int_add(json_neigh, "localAs", p->local_as);
7978
7979 if (CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
7980 json_object_boolean_true_add(json_neigh, "localAsNoPrepend");
7981
7982 if (CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
7983 json_object_boolean_true_add(json_neigh, "localAsReplaceAs");
7984 }
7985 else
7986 {
7987 if ((p->as_type == AS_SPECIFIED) ||
7988 (p->as_type == AS_EXTERNAL) ||
7989 (p->as_type == AS_INTERNAL))
7990 vty_out (vty, "remote AS %u, ", p->as);
7991 else
7992 vty_out (vty, "remote AS Unspecified, ");
7993 vty_out (vty, "local AS %u%s%s, ",
7994 p->change_local_as ? p->change_local_as : p->local_as,
7995 CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND) ?
7996 " no-prepend" : "",
7997 CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS) ?
7998 " replace-as" : "");
7999 }
8000 /* peer type internal, external, confed-internal or confed-external */
8001 if (p->as == p->local_as)
8002 {
8003 if (use_json)
8004 {
8005 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8006 json_object_boolean_true_add(json_neigh, "nbrConfedInternalLink");
8007 else
8008 json_object_boolean_true_add(json_neigh, "nbrInternalLink");
8009 }
8010 else
8011 {
8012 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8013 vty_out (vty, "confed-internal link%s", VTYNL);
8014 else
8015 vty_out (vty, "internal link%s", VTYNL);
8016 }
8017 }
8018 else
8019 {
8020 if (use_json)
8021 {
8022 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8023 json_object_boolean_true_add(json_neigh, "nbrConfedExternalLink");
8024 else
8025 json_object_boolean_true_add(json_neigh, "nbrExternalLink");
8026 }
8027 else
8028 {
8029 if (bgp_confederation_peers_check(bgp, p->as))
8030 vty_out (vty, "confed-external link%s", VTYNL);
8031 else
8032 vty_out (vty, "external link%s", VTYNL);
8033 }
8034 }
8035
8036 /* Description. */
8037 if (p->desc)
8038 {
8039 if (use_json)
8040 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8041 else
8042 vty_out (vty, " Description: %s%s", p->desc, VTYNL);
8043 }
8044
8045 if (p->hostname)
8046 {
8047 if (use_json)
8048 {
8049 if (p->hostname)
8050 json_object_string_add(json_neigh, "hostname", p->hostname);
8051
8052 if (p->domainname)
8053 json_object_string_add(json_neigh, "domainname", p->domainname);
8054 }
8055 else
8056 {
8057 if (p->domainname && (p->domainname[0] != '\0'))
8058 vty_out(vty, "Hostname: %s.%s%s", p->hostname, p->domainname,
8059 VTYNL);
8060 else
8061 vty_out(vty, "Hostname: %s%s", p->hostname, VTYNL);
8062 }
8063
8064 }
8065
8066 /* Peer-group */
8067 if (p->group)
8068 {
8069 if (use_json)
8070 {
8071 json_object_string_add(json_neigh, "peerGroup", p->group->name);
8072
8073 if (dn_flag[0])
8074 {
8075 struct prefix prefix, *range = NULL;
8076
8077 sockunion2hostprefix(&(p->su), &prefix);
8078 range = peer_group_lookup_dynamic_neighbor_range (p->group, &prefix);
8079
8080 if (range)
8081 {
8082 prefix2str(range, buf1, sizeof(buf1));
8083 json_object_string_add(json_neigh, "peerSubnetRangeGroup", buf1);
8084 }
8085 }
8086 }
8087 else
8088 {
8089 vty_out (vty, " Member of peer-group %s for session parameters%s",
8090 p->group->name, VTYNL);
8091
8092 if (dn_flag[0])
8093 {
8094 struct prefix prefix, *range = NULL;
8095
8096 sockunion2hostprefix(&(p->su), &prefix);
8097 range = peer_group_lookup_dynamic_neighbor_range (p->group, &prefix);
8098
8099 if (range)
8100 {
8101 prefix2str(range, buf1, sizeof(buf1));
8102 vty_out (vty, " Belongs to the subnet range group: %s%s", buf1, VTYNL);
8103 }
8104 }
8105 }
8106 }
8107
8108 if (use_json)
8109 {
8110 /* Administrative shutdown. */
8111 if (CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN))
8112 json_object_boolean_true_add(json_neigh, "adminShutDown");
8113
8114 /* BGP Version. */
8115 json_object_int_add(json_neigh, "bgpVersion", 4);
8116 json_object_string_add(json_neigh, "remoteRouterId",
8117 inet_ntop (AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8118
8119 /* Confederation */
8120 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION) && bgp_confederation_peers_check (bgp, p->as))
8121 json_object_boolean_true_add(json_neigh, "nbrCommonAdmin");
8122
8123 /* Status. */
8124 json_object_string_add(json_neigh, "bgpState", lookup_msg(bgp_status_msg, p->status, NULL));
8125
8126 if (p->status == Established)
8127 {
8128 time_t uptime;
8129 struct tm *tm;
8130
8131 uptime = bgp_clock();
8132 uptime -= p->uptime;
8133 tm = gmtime(&uptime);
8134 epoch_tbuf = time(NULL) - uptime;
8135
8136 json_object_int_add(json_neigh, "bgpTimerUp", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8137 json_object_string_add(json_neigh, "bgpTimerUpString", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
8138 json_object_int_add(json_neigh, "bgpTimerUpEstablishedEpoch", epoch_tbuf);
8139 }
8140
8141 else if (p->status == Active)
8142 {
8143 if (CHECK_FLAG (p->flags, PEER_FLAG_PASSIVE))
8144 json_object_string_add(json_neigh, "bgpStateIs", "passive");
8145 else if (CHECK_FLAG (p->sflags, PEER_STATUS_NSF_WAIT))
8146 json_object_string_add(json_neigh, "bgpStateIs", "passiveNSF");
8147 }
8148
8149 /* read timer */
8150 time_t uptime;
8151 struct tm *tm;
8152
8153 uptime = bgp_clock();
8154 uptime -= p->readtime;
8155 tm = gmtime(&uptime);
8156 json_object_int_add(json_neigh, "bgpTimerLastRead", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8157
8158 uptime = bgp_clock();
8159 uptime -= p->last_write;
8160 tm = gmtime(&uptime);
8161 json_object_int_add(json_neigh, "bgpTimerLastWrite", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8162
8163 uptime = bgp_clock();
8164 uptime -= p->update_time;
8165 tm = gmtime(&uptime);
8166 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8167 (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8168
8169 /* Configured timer values. */
8170 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs", p->v_holdtime * 1000);
8171 json_object_int_add(json_neigh, "bgpTimerKeepAliveIntervalMsecs", p->v_keepalive * 1000);
8172
8173 if (CHECK_FLAG (p->config, PEER_CONFIG_TIMER))
8174 {
8175 json_object_int_add(json_neigh, "bgpTimerConfiguredHoldTimeMsecs", p->holdtime * 1000);
8176 json_object_int_add(json_neigh, "bgpTimerConfiguredKeepAliveIntervalMsecs", p->keepalive * 1000);
8177 }
8178 }
8179 else
8180 {
8181 /* Administrative shutdown. */
8182 if (CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN))
8183 vty_out (vty, " Administratively shut down%s", VTYNL);
8184
8185 /* BGP Version. */
8186 vty_out (vty, " BGP version 4");
8187 vty_out (vty, ", remote router ID %s%s",
8188 inet_ntop (AF_INET, &p->remote_id, buf1, sizeof(buf1)),
8189 VTYNL);
8190
8191 /* Confederation */
8192 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION)
8193 && bgp_confederation_peers_check (bgp, p->as))
8194 vty_out (vty, " Neighbor under common administration%s", VTYNL);
8195
8196 /* Status. */
8197 vty_out (vty, " BGP state = %s", lookup_msg(bgp_status_msg, p->status, NULL));
8198
8199 if (p->status == Established)
8200 vty_out (vty, ", up for %8s", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
8201
8202 else if (p->status == Active)
8203 {
8204 if (CHECK_FLAG (p->flags, PEER_FLAG_PASSIVE))
8205 vty_out (vty, " (passive)");
8206 else if (CHECK_FLAG (p->sflags, PEER_STATUS_NSF_WAIT))
8207 vty_out (vty, " (NSF passive)");
8208 }
8209 vty_out (vty, "%s", VTYNL);
8210
8211 /* read timer */
8212 vty_out (vty, " Last read %s", peer_uptime (p->readtime, timebuf, BGP_UPTIME_LEN, 0, NULL));
8213 vty_out (vty, ", Last write %s%s",
8214 peer_uptime (p->last_write, timebuf, BGP_UPTIME_LEN, 0, NULL), VTYNL);
8215
8216 /* Configured timer values. */
8217 vty_out (vty, " Hold time is %d, keepalive interval is %d seconds%s",
8218 p->v_holdtime, p->v_keepalive, VTYNL);
8219 if (CHECK_FLAG (p->config, PEER_CONFIG_TIMER))
8220 {
8221 vty_out (vty, " Configured hold time is %d", p->holdtime);
8222 vty_out (vty, ", keepalive interval is %d seconds%s",
8223 p->keepalive, VTYNL);
8224 }
8225 }
8226 /* Capability. */
8227 if (p->status == Established)
8228 {
8229 if (p->cap
8230 || p->afc_adv[AFI_IP][SAFI_UNICAST]
8231 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8232 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8233 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8234 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8235 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8236 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8237 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8238 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8239 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8240 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8241 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8242 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8243 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8244 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8245 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN])
8246 {
8247 if (use_json)
8248 {
8249 json_object *json_cap = NULL;
8250
8251 json_cap = json_object_new_object();
8252
8253 /* AS4 */
8254 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV)
8255 || CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
8256 {
8257 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV) && CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
8258 json_object_string_add(json_cap, "4byteAs", "advertisedAndReceived");
8259 else if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
8260 json_object_string_add(json_cap, "4byteAs", "advertised");
8261 else if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
8262 json_object_string_add(json_cap, "4byteAs", "received");
8263 }
8264
8265 /* AddPath */
8266 if (CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_RCV)
8267 || CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_ADV))
8268 {
8269 json_object *json_add = NULL;
8270 const char *print_store;
8271
8272 json_add = json_object_new_object();
8273
8274 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8275 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8276 {
8277 json_object *json_sub = NULL;
8278 json_sub = json_object_new_object();
8279 print_store = afi_safi_print (afi, safi);
8280
8281 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
8282 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
8283 {
8284 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) && CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
8285 json_object_boolean_true_add(json_sub, "txAdvertisedAndReceived");
8286 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV))
8287 json_object_boolean_true_add(json_sub, "txAdvertised");
8288 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
8289 json_object_boolean_true_add(json_sub, "txReceived");
8290 }
8291
8292 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
8293 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8294 {
8295 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) && CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8296 json_object_boolean_true_add(json_sub, "rxAdvertisedAndReceived");
8297 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV))
8298 json_object_boolean_true_add(json_sub, "rxAdvertised");
8299 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8300 json_object_boolean_true_add(json_sub, "rxReceived");
8301 }
8302
8303 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
8304 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV) ||
8305 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
8306 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8307 json_object_object_add(json_add, print_store, json_sub);
8308 else
8309 json_object_free(json_sub);
8310 }
8311
8312 json_object_object_add(json_cap, "addPath", json_add);
8313 }
8314
8315 /* Dynamic */
8316 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV)
8317 || CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
8318 {
8319 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV) && CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
8320 json_object_string_add(json_cap, "dynamic", "advertisedAndReceived");
8321 else if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
8322 json_object_string_add(json_cap, "dynamic", "advertised");
8323 else if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
8324 json_object_string_add(json_cap, "dynamic", "received");
8325 }
8326
8327 /* Extended nexthop */
8328 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV)
8329 || CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8330 {
8331 json_object *json_nxt = NULL;
8332 const char *print_store;
8333
8334
8335 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV) && CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8336 json_object_string_add(json_cap, "extendedNexthop", "advertisedAndReceived");
8337 else if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8338 json_object_string_add(json_cap, "extendedNexthop", "advertised");
8339 else if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8340 json_object_string_add(json_cap, "extendedNexthop", "received");
8341
8342 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8343 {
8344 json_nxt = json_object_new_object();
8345
8346 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8347 {
8348 if (CHECK_FLAG (p->af_cap[AFI_IP][safi], PEER_CAP_ENHE_AF_RCV))
8349 {
8350 print_store = afi_safi_print (AFI_IP, safi);
8351 json_object_string_add(json_nxt, print_store, "recieved");
8352 }
8353 }
8354 json_object_object_add(json_cap, "extendedNexthopFamililesByPeer", json_nxt);
8355 }
8356 }
8357
8358 /* Route Refresh */
8359 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV)
8360 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
8361 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8362 {
8363 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV) && (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV) || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV)))
8364 {
8365 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV) && CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV))
8366 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedOldNew");
8367 else
8368 {
8369 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8370 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedOld");
8371 else
8372 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedNew");
8373 }
8374 }
8375 else if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV))
8376 json_object_string_add(json_cap, "routeRefresh", "advertised");
8377 else if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV) || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8378 json_object_string_add(json_cap, "routeRefresh", "received");
8379 }
8380
8381 /* Multiprotocol Extensions */
8382 json_object *json_multi = NULL;
8383 json_multi = json_object_new_object();
8384
8385 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8386 {
8387 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8388 {
8389 if (p->afc_adv[afi][safi] || p->afc_recv[afi][safi])
8390 {
8391 json_object *json_exten = NULL;
8392 json_exten = json_object_new_object();
8393
8394 if (p->afc_adv[afi][safi] && p->afc_recv[afi][safi])
8395 json_object_boolean_true_add(json_exten, "advertisedAndReceived");
8396 else if (p->afc_adv[afi][safi])
8397 json_object_boolean_true_add(json_exten, "advertised");
8398 else if (p->afc_recv[afi][safi])
8399 json_object_boolean_true_add(json_exten, "received");
8400
8401 json_object_object_add(json_multi, afi_safi_print (afi, safi), json_exten);
8402 }
8403 }
8404 }
8405 json_object_object_add(json_cap, "multiprotocolExtensions", json_multi);
8406
8407 /* Gracefull Restart */
8408 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
8409 || CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
8410 {
8411 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV) && CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8412 json_object_string_add(json_cap, "gracefulRestart", "advertisedAndReceived");
8413 else if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
8414 json_object_string_add(json_cap, "gracefulRestartCapability", "advertised");
8415 else if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8416 json_object_string_add(json_cap, "gracefulRestartCapability", "received");
8417
8418 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8419 {
8420 int restart_af_count = 0;
8421 json_object *json_restart = NULL;
8422 json_restart = json_object_new_object();
8423
8424 json_object_int_add(json_cap, "gracefulRestartRemoteTimerMsecs", p->v_gr_restart * 1000);
8425
8426 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8427 {
8428 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8429 {
8430 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_RCV))
8431 {
8432 json_object *json_sub = NULL;
8433 json_sub = json_object_new_object();
8434
8435 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_PRESERVE_RCV))
8436 json_object_boolean_true_add(json_sub, "preserved");
8437 restart_af_count++;
8438 json_object_object_add(json_restart, afi_safi_print (afi, safi), json_sub);
8439 }
8440 }
8441 }
8442 if (! restart_af_count)
8443 {
8444 json_object_string_add(json_cap, "addressFamiliesByPeer", "none");
8445 json_object_free(json_restart);
8446 }
8447 else
8448 json_object_object_add(json_cap, "addressFamiliesByPeer", json_restart);
8449 }
8450 }
8451 json_object_object_add(json_neigh, "neighborCapabilities", json_cap);
8452 }
8453 else
8454 {
8455 vty_out (vty, " Neighbor capabilities:%s", VTYNL);
8456
8457 /* AS4 */
8458 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV)
8459 || CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
8460 {
8461 vty_out (vty, " 4 Byte AS:");
8462 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
8463 vty_out (vty, " advertised");
8464 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
8465 vty_out (vty, " %sreceived",
8466 CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV) ? "and " : "");
8467 vty_out (vty, "%s", VTYNL);
8468 }
8469
8470 /* AddPath */
8471 if (CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_RCV)
8472 || CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_ADV))
8473 {
8474 vty_out (vty, " AddPath:%s", VTYNL);
8475
8476 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8477 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8478 {
8479 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
8480 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
8481 {
8482 vty_out (vty, " %s: TX ", afi_safi_print (afi, safi));
8483
8484 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV))
8485 vty_out (vty, "advertised %s", afi_safi_print (afi, safi));
8486
8487 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
8488 vty_out (vty, "%sreceived", CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ? " and " : "" );
8489
8490 vty_out (vty, "%s", VTYNL);
8491 }
8492
8493 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
8494 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8495 {
8496 vty_out (vty, " %s: RX ", afi_safi_print (afi, safi));
8497
8498 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV))
8499 vty_out (vty, "advertised %s", afi_safi_print (afi, safi));
8500
8501 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8502 vty_out (vty, "%sreceived", CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ? " and " : "" );
8503
8504 vty_out (vty, "%s", VTYNL);
8505 }
8506 }
8507 }
8508
8509 /* Dynamic */
8510 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV)
8511 || CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
8512 {
8513 vty_out (vty, " Dynamic:");
8514 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
8515 vty_out (vty, " advertised");
8516 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
8517 vty_out (vty, " %sreceived",
8518 CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV) ? "and " : "");
8519 vty_out (vty, "%s", VTYNL);
8520 }
8521
8522 /* Extended nexthop */
8523 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV)
8524 || CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8525 {
8526 vty_out (vty, " Extended nexthop:");
8527 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8528 vty_out (vty, " advertised");
8529 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8530 vty_out (vty, " %sreceived",
8531 CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV) ? "and " : "");
8532 vty_out (vty, "%s", VTYNL);
8533
8534 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8535 {
8536 vty_out (vty, " Address families by peer:%s ", VTYNL);
8537 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8538 if (CHECK_FLAG (p->af_cap[AFI_IP][safi], PEER_CAP_ENHE_AF_RCV))
8539 vty_out (vty, " %s%s",
8540 afi_safi_print (AFI_IP, safi), VTYNL);
8541 }
8542 }
8543
8544 /* Route Refresh */
8545 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV)
8546 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
8547 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8548 {
8549 vty_out (vty, " Route refresh:");
8550 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV))
8551 vty_out (vty, " advertised");
8552 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
8553 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8554 vty_out (vty, " %sreceived(%s)",
8555 CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV) ? "and " : "",
8556 (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV)
8557 && CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)) ?
8558 "old & new" : CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV) ? "old" : "new");
8559
8560 vty_out (vty, "%s", VTYNL);
8561 }
8562
8563 /* Multiprotocol Extensions */
8564 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8565 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8566 if (p->afc_adv[afi][safi] || p->afc_recv[afi][safi])
8567 {
8568 vty_out (vty, " Address Family %s:", afi_safi_print (afi, safi));
8569 if (p->afc_adv[afi][safi])
8570 vty_out (vty, " advertised");
8571 if (p->afc_recv[afi][safi])
8572 vty_out (vty, " %sreceived", p->afc_adv[afi][safi] ? "and " : "");
8573 vty_out (vty, "%s", VTYNL);
8574 }
8575
8576 /* Hostname capability */
8577 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV) ||
8578 CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV))
8579 {
8580 vty_out (vty, " Hostname Capability:");
8581 if (CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_ADV))
8582 vty_out (vty, " advertised");
8583 if (CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_RCV))
8584 vty_out (vty, " %sreceived",
8585 CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_ADV) ? "and " : "");
8586 vty_out (vty, "%s", VTYNL);
8587 }
8588
8589 /* Gracefull Restart */
8590 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
8591 || CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
8592 {
8593 vty_out (vty, " Graceful Restart Capabilty:");
8594 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
8595 vty_out (vty, " advertised");
8596 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8597 vty_out (vty, " %sreceived",
8598 CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV) ? "and " : "");
8599 vty_out (vty, "%s", VTYNL);
8600
8601 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8602 {
8603 int restart_af_count = 0;
8604
8605 vty_out (vty, " Remote Restart timer is %d seconds%s",
8606 p->v_gr_restart, VTYNL);
8607 vty_out (vty, " Address families by peer:%s ", VTYNL);
8608
8609 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8610 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8611 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_RCV))
8612 {
8613 vty_out (vty, "%s%s(%s)", restart_af_count ? ", " : "",
8614 afi_safi_print (afi, safi),
8615 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_PRESERVE_RCV) ?
8616 "preserved" : "not preserved");
8617 restart_af_count++;
8618 }
8619 if (! restart_af_count)
8620 vty_out (vty, "none");
8621 vty_out (vty, "%s", VTYNL);
8622 }
8623 }
8624 }
8625 }
8626 }
8627
8628 /* graceful restart information */
8629 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
8630 || p->t_gr_restart
8631 || p->t_gr_stale)
8632 {
8633 json_object *json_grace = NULL;
8634 json_object *json_grace_send = NULL;
8635 json_object *json_grace_recv = NULL;
8636 int eor_send_af_count = 0;
8637 int eor_receive_af_count = 0;
8638
8639 if (use_json)
8640 {
8641 json_grace = json_object_new_object();
8642 json_grace_send = json_object_new_object();
8643 json_grace_recv = json_object_new_object();
8644
8645 if (p->status == Established)
8646 {
8647 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8648 {
8649 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8650 {
8651 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_SEND))
8652 {
8653 json_object_boolean_true_add(json_grace_send, afi_safi_print (afi, safi));
8654 eor_send_af_count++;
8655 }
8656 }
8657 }
8658 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8659 {
8660 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8661 {
8662 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_RECEIVED))
8663 {
8664 json_object_boolean_true_add(json_grace_recv, afi_safi_print (afi, safi));
8665 eor_receive_af_count++;
8666 }
8667 }
8668 }
8669 }
8670
8671 json_object_object_add(json_grace, "endOfRibSend", json_grace_send);
8672 json_object_object_add(json_grace, "endOfRibRecv", json_grace_recv);
8673
8674 if (p->t_gr_restart)
8675 json_object_int_add(json_grace, "gracefulRestartTimerMsecs", thread_timer_remain_second (p->t_gr_restart) * 1000);
8676
8677 if (p->t_gr_stale)
8678 json_object_int_add(json_grace, "gracefulStalepathTimerMsecs", thread_timer_remain_second (p->t_gr_stale) * 1000);
8679
8680 json_object_object_add(json_neigh, "gracefulRestartInfo", json_grace);
8681 }
8682 else
8683 {
8684 vty_out (vty, " Graceful restart informations:%s", VTYNL);
8685 if (p->status == Established)
8686 {
8687 vty_out (vty, " End-of-RIB send: ");
8688 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8689 {
8690 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8691 {
8692 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_SEND))
8693 {
8694 vty_out (vty, "%s%s", eor_send_af_count ? ", " : "",
8695 afi_safi_print (afi, safi));
8696 eor_send_af_count++;
8697 }
8698 }
8699 }
8700 vty_out (vty, "%s", VTYNL);
8701 vty_out (vty, " End-of-RIB received: ");
8702 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8703 {
8704 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8705 {
8706 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_RECEIVED))
8707 {
8708 vty_out (vty, "%s%s", eor_receive_af_count ? ", " : "",
8709 afi_safi_print (afi, safi));
8710 eor_receive_af_count++;
8711 }
8712 }
8713 }
8714 vty_out (vty, "%s", VTYNL);
8715 }
8716
8717 if (p->t_gr_restart)
8718 vty_out (vty, " The remaining time of restart timer is %ld%s",
8719 thread_timer_remain_second (p->t_gr_restart), VTYNL);
8720
8721 if (p->t_gr_stale)
8722 vty_out (vty, " The remaining time of stalepath timer is %ld%s",
8723 thread_timer_remain_second (p->t_gr_stale), VTYNL);
8724 }
8725 }
8726 if (use_json)
8727 {
8728 json_object *json_stat = NULL;
8729 json_stat = json_object_new_object();
8730 /* Packet counts. */
8731 json_object_int_add(json_stat, "depthInq", 0);
8732 json_object_int_add(json_stat, "depthOutq", (unsigned long) p->obuf->count);
8733 json_object_int_add(json_stat, "opensSent", p->open_out);
8734 json_object_int_add(json_stat, "opensRecv", p->open_in);
8735 json_object_int_add(json_stat, "notificationsSent", p->notify_out);
8736 json_object_int_add(json_stat, "notificationsRecv", p->notify_in);
8737 json_object_int_add(json_stat, "updatesSent", p->update_out);
8738 json_object_int_add(json_stat, "updatesRecv", p->update_in);
8739 json_object_int_add(json_stat, "keepalivesSent", p->keepalive_out);
8740 json_object_int_add(json_stat, "keepalivesRecv", p->keepalive_in);
8741 json_object_int_add(json_stat, "routeRefreshSent", p->refresh_out);
8742 json_object_int_add(json_stat, "routeRefreshRecv", p->refresh_in);
8743 json_object_int_add(json_stat, "capabilitySent", p->dynamic_cap_out);
8744 json_object_int_add(json_stat, "capabilityRecv", p->dynamic_cap_in);
8745 json_object_int_add(json_stat, "totalSent", p->open_out + p->notify_out + p->update_out + p->keepalive_out + p->refresh_out + p->dynamic_cap_out);
8746 json_object_int_add(json_stat, "totalRecv", p->open_in + p->notify_in + p->update_in + p->keepalive_in + p->refresh_in + p->dynamic_cap_in);
8747 json_object_object_add(json_neigh, "messageStats", json_stat);
8748 }
8749 else
8750 {
8751 /* Packet counts. */
8752 vty_out (vty, " Message statistics:%s", VTYNL);
8753 vty_out (vty, " Inq depth is 0%s", VTYNL);
8754 vty_out (vty, " Outq depth is %lu%s", (unsigned long) p->obuf->count, VTYNL);
8755 vty_out (vty, " Sent Rcvd%s", VTYNL);
8756 vty_out (vty, " Opens: %10d %10d%s", p->open_out, p->open_in, VTYNL);
8757 vty_out (vty, " Notifications: %10d %10d%s", p->notify_out, p->notify_in, VTYNL);
8758 vty_out (vty, " Updates: %10d %10d%s", p->update_out, p->update_in, VTYNL);
8759 vty_out (vty, " Keepalives: %10d %10d%s", p->keepalive_out, p->keepalive_in, VTYNL);
8760 vty_out (vty, " Route Refresh: %10d %10d%s", p->refresh_out, p->refresh_in, VTYNL);
8761 vty_out (vty, " Capability: %10d %10d%s", p->dynamic_cap_out, p->dynamic_cap_in, VTYNL);
8762 vty_out (vty, " Total: %10d %10d%s", p->open_out + p->notify_out +
8763 p->update_out + p->keepalive_out + p->refresh_out + p->dynamic_cap_out,
8764 p->open_in + p->notify_in + p->update_in + p->keepalive_in + p->refresh_in +
8765 p->dynamic_cap_in, VTYNL);
8766 }
8767
8768 if (use_json)
8769 {
8770 /* advertisement-interval */
8771 json_object_int_add(json_neigh, "minBtwnAdvertisementRunsTimerMsecs", p->v_routeadv * 1000);
8772
8773 /* Update-source. */
8774 if (p->update_if || p->update_source)
8775 {
8776 if (p->update_if)
8777 json_object_string_add(json_neigh, "updateSource", p->update_if);
8778 else if (p->update_source)
8779 json_object_string_add(json_neigh, "updateSource", sockunion2str (p->update_source, buf1, SU_ADDRSTRLEN));
8780 }
8781 }
8782 else
8783 {
8784 /* advertisement-interval */
8785 vty_out (vty, " Minimum time between advertisement runs is %d seconds%s",
8786 p->v_routeadv, VTYNL);
8787
8788 /* Update-source. */
8789 if (p->update_if || p->update_source)
8790 {
8791 vty_out (vty, " Update source is ");
8792 if (p->update_if)
8793 vty_out (vty, "%s", p->update_if);
8794 else if (p->update_source)
8795 vty_out (vty, "%s", sockunion2str (p->update_source, buf1, SU_ADDRSTRLEN));
8796 vty_out (vty, "%s", VTYNL);
8797 }
8798
8799 vty_out (vty, "%s", VTYNL);
8800 }
8801
8802 /* Address Family Information */
8803 json_object *json_hold = NULL;
8804
8805 if (use_json)
8806 json_hold = json_object_new_object();
8807
8808 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8809 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8810 if (p->afc[afi][safi])
8811 bgp_show_peer_afi (vty, p, afi, safi, use_json, json_hold);
8812
8813 if (use_json)
8814 {
8815 json_object_object_add(json_neigh, "addressFamilyInfo", json_hold);
8816 json_object_int_add(json_neigh, "connectionsEstablished", p->established);
8817 json_object_int_add(json_neigh, "connectionsDropped", p->dropped);
8818 }
8819 else
8820 vty_out (vty, " Connections established %d; dropped %d%s", p->established, p->dropped,
8821 VTYNL);
8822
8823 if (! p->last_reset)
8824 {
8825 if (use_json)
8826 json_object_string_add(json_neigh, "lastReset", "never");
8827 else
8828 vty_out (vty, " Last reset never%s", VTYNL);
8829 }
8830 else
8831 {
8832 if (use_json)
8833 {
8834 time_t uptime;
8835 struct tm *tm;
8836
8837 uptime = bgp_clock();
8838 uptime -= p->resettime;
8839 tm = gmtime(&uptime);
8840 json_object_int_add(json_neigh, "lastResetTimerMsecs", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8841 json_object_string_add(json_neigh, "lastResetDueTo", peer_down_str[(int) p->last_reset]);
8842 if (p->last_reset == PEER_DOWN_NOTIFY_SEND ||
8843 p->last_reset == PEER_DOWN_NOTIFY_RECEIVED)
8844 {
8845 char errorcodesubcode_hexstr[5];
8846 char errorcodesubcode_str[256];
8847
8848 code_str = bgp_notify_code_str(p->notify.code);
8849 subcode_str = bgp_notify_subcode_str(p->notify.code, p->notify.subcode);
8850
8851 sprintf(errorcodesubcode_hexstr, "%02X%02X", p->notify.code, p->notify.subcode);
8852 json_object_string_add(json_neigh, "lastErrorCodeSubcode", errorcodesubcode_hexstr);
8853 snprintf(errorcodesubcode_str, 255, "%s%s", code_str, subcode_str);
8854 json_object_string_add(json_neigh, "lastNotificationReason", errorcodesubcode_str);
8855 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8856 && p->notify.code == BGP_NOTIFY_CEASE
8857 && (p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8858 || p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_RESET)
8859 && p->notify.length)
8860 {
8861 char msgbuf[1024];
8862 const char *msg_str;
8863
8864 msg_str = bgp_notify_admin_message(msgbuf, sizeof(msgbuf),
8865 (u_char*)p->notify.data, p->notify.length);
8866 if (msg_str)
8867 json_object_string_add(json_neigh, "lastShutdownDescription", msg_str);
8868 }
8869 }
8870 }
8871 else
8872 {
8873 vty_out (vty, " Last reset %s, ",
8874 peer_uptime (p->resettime, timebuf, BGP_UPTIME_LEN, 0, NULL));
8875
8876 if (p->last_reset == PEER_DOWN_NOTIFY_SEND ||
8877 p->last_reset == PEER_DOWN_NOTIFY_RECEIVED)
8878 {
8879 code_str = bgp_notify_code_str(p->notify.code);
8880 subcode_str = bgp_notify_subcode_str(p->notify.code, p->notify.subcode);
8881 vty_out (vty, "due to NOTIFICATION %s (%s%s)%s",
8882 p->last_reset == PEER_DOWN_NOTIFY_SEND ? "sent" : "received",
8883 code_str, subcode_str, VTYNL);
8884 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8885 && p->notify.code == BGP_NOTIFY_CEASE
8886 && (p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8887 || p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_RESET)
8888 && p->notify.length)
8889 {
8890 char msgbuf[1024];
8891 const char *msg_str;
8892
8893 msg_str = bgp_notify_admin_message(msgbuf, sizeof(msgbuf),
8894 (u_char*)p->notify.data, p->notify.length);
8895 if (msg_str)
8896 vty_out (vty, " Message: \"%s\"%s", msg_str, VTYNL);
8897 }
8898 }
8899 else
8900 {
8901 vty_out (vty, "due to %s%s",
8902 peer_down_str[(int) p->last_reset], VTYNL);
8903 }
8904
8905 if (p->last_reset_cause_size)
8906 {
8907 msg = p->last_reset_cause;
8908 vty_out(vty, " Message received that caused BGP to send a NOTIFICATION:%s ", VTYNL);
8909 for (i = 1; i <= p->last_reset_cause_size; i++)
8910 {
8911 vty_out(vty, "%02X", *msg++);
8912
8913 if (i != p->last_reset_cause_size)
8914 {
8915 if (i % 16 == 0)
8916 {
8917 vty_out(vty, "%s ", VTYNL);
8918 }
8919 else if (i % 4 == 0)
8920 {
8921 vty_out(vty, " ");
8922 }
8923 }
8924 }
8925 vty_out(vty, "%s", VTYNL);
8926 }
8927 }
8928 }
8929
8930 if (CHECK_FLAG (p->sflags, PEER_STATUS_PREFIX_OVERFLOW))
8931 {
8932 if (use_json)
8933 json_object_boolean_true_add(json_neigh, "prefixesConfigExceedMax");
8934 else
8935 vty_out (vty, " Peer had exceeded the max. no. of prefixes configured.%s", VTYNL);
8936
8937 if (p->t_pmax_restart)
8938 {
8939 if (use_json)
8940 {
8941 json_object_boolean_true_add(json_neigh, "reducePrefixNumFrom");
8942 json_object_int_add(json_neigh, "restartInTimerMsec", thread_timer_remain_second (p->t_pmax_restart) * 1000);
8943 }
8944 else
8945 vty_out (vty, " Reduce the no. of prefix from %s, will restart in %ld seconds%s",
8946 p->host, thread_timer_remain_second (p->t_pmax_restart),
8947 VTYNL);
8948 }
8949 else
8950 {
8951 if (use_json)
8952 json_object_boolean_true_add(json_neigh, "reducePrefixNumAndClearIpBgp");
8953 else
8954 vty_out (vty, " Reduce the no. of prefix and clear ip bgp %s to restore peering%s",
8955 p->host, VTYNL);
8956 }
8957 }
8958
8959 /* EBGP Multihop and GTSM */
8960 if (p->sort != BGP_PEER_IBGP)
8961 {
8962 if (use_json)
8963 {
8964 if (p->gtsm_hops > 0)
8965 json_object_int_add(json_neigh, "externalBgpNbrMaxHopsAway", p->gtsm_hops);
8966 else if (p->ttl > 1)
8967 json_object_int_add(json_neigh, "externalBgpNbrMaxHopsAway", p->ttl);
8968 }
8969 else
8970 {
8971 if (p->gtsm_hops > 0)
8972 vty_out (vty, " External BGP neighbor may be up to %d hops away.%s",
8973 p->gtsm_hops, VTYNL);
8974 else if (p->ttl > 1)
8975 vty_out (vty, " External BGP neighbor may be up to %d hops away.%s",
8976 p->ttl, VTYNL);
8977 }
8978 }
8979 else
8980 {
8981 if (p->gtsm_hops > 0)
8982 {
8983 if (use_json)
8984 json_object_int_add(json_neigh, "internalBgpNbrMaxHopsAway", p->gtsm_hops);
8985 else
8986 vty_out (vty, " Internal BGP neighbor may be up to %d hops away.%s",
8987 p->gtsm_hops, VTYNL);
8988 }
8989 }
8990
8991 /* Local address. */
8992 if (p->su_local)
8993 {
8994 if (use_json)
8995 {
8996 json_object_string_add(json_neigh, "hostLocal", sockunion2str (p->su_local, buf1, SU_ADDRSTRLEN));
8997 json_object_int_add(json_neigh, "portLocal", ntohs (p->su_local->sin.sin_port));
8998 }
8999 else
9000 vty_out (vty, "Local host: %s, Local port: %d%s",
9001 sockunion2str (p->su_local, buf1, SU_ADDRSTRLEN),
9002 ntohs (p->su_local->sin.sin_port),
9003 VTYNL);
9004 }
9005
9006 /* Remote address. */
9007 if (p->su_remote)
9008 {
9009 if (use_json)
9010 {
9011 json_object_string_add(json_neigh, "hostForeign", sockunion2str (p->su_remote, buf1, SU_ADDRSTRLEN));
9012 json_object_int_add(json_neigh, "portForeign", ntohs (p->su_remote->sin.sin_port));
9013 }
9014 else
9015 vty_out (vty, "Foreign host: %s, Foreign port: %d%s",
9016 sockunion2str (p->su_remote, buf1, SU_ADDRSTRLEN),
9017 ntohs (p->su_remote->sin.sin_port),
9018 VTYNL);
9019 }
9020
9021 /* Nexthop display. */
9022 if (p->su_local)
9023 {
9024 if (use_json)
9025 {
9026 json_object_string_add(json_neigh, "nexthop",
9027 inet_ntop (AF_INET, &p->nexthop.v4, buf1, sizeof(buf1)));
9028 json_object_string_add(json_neigh, "nexthopGlobal",
9029 inet_ntop (AF_INET6, &p->nexthop.v6_global, buf1, sizeof(buf1)));
9030 json_object_string_add(json_neigh, "nexthopLocal",
9031 inet_ntop (AF_INET6, &p->nexthop.v6_local, buf1, sizeof(buf1)));
9032 if (p->shared_network)
9033 json_object_string_add(json_neigh, "bgpConnection", "sharedNetwork");
9034 else
9035 json_object_string_add(json_neigh, "bgpConnection", "nonSharedNetwork");
9036 }
9037 else
9038 {
9039 vty_out (vty, "Nexthop: %s%s",
9040 inet_ntop (AF_INET, &p->nexthop.v4, buf1, sizeof(buf1)),
9041 VTYNL);
9042 vty_out (vty, "Nexthop global: %s%s",
9043 inet_ntop (AF_INET6, &p->nexthop.v6_global, buf1, sizeof(buf1)),
9044 VTYNL);
9045 vty_out (vty, "Nexthop local: %s%s",
9046 inet_ntop (AF_INET6, &p->nexthop.v6_local, buf1, sizeof(buf1)),
9047 VTYNL);
9048 vty_out (vty, "BGP connection: %s%s",
9049 p->shared_network ? "shared network" : "non shared network",
9050 VTYNL);
9051 }
9052 }
9053
9054 /* Timer information. */
9055 if (use_json)
9056 {
9057 json_object_int_add(json_neigh, "connectRetryTimer", p->v_connect);
9058 if (p->status == Established && p->rtt)
9059 json_object_int_add(json_neigh, "estimatedRttInMsecs", p->rtt);
9060 if (p->t_start)
9061 json_object_int_add(json_neigh, "nextStartTimerDueInMsecs", thread_timer_remain_second (p->t_start) * 1000);
9062 if (p->t_connect)
9063 json_object_int_add(json_neigh, "nextConnectTimerDueInMsecs", thread_timer_remain_second (p->t_connect) * 1000);
9064 if (p->t_routeadv)
9065 {
9066 json_object_int_add(json_neigh, "mraiInterval", p->v_routeadv);
9067 json_object_int_add(json_neigh, "mraiTimerExpireInMsecs", thread_timer_remain_second (p->t_routeadv) * 1000);
9068 }
9069 if (p->password)
9070 json_object_int_add(json_neigh, "authenticationEnabled", 1);
9071
9072 if (p->t_read)
9073 json_object_string_add(json_neigh, "readThread", "on");
9074 else
9075 json_object_string_add(json_neigh, "readThread", "off");
9076 if (p->t_write)
9077 json_object_string_add(json_neigh, "writeThread", "on");
9078 else
9079 json_object_string_add(json_neigh, "writeThread", "off");
9080 }
9081 else
9082 {
9083 vty_out (vty, "BGP Connect Retry Timer in Seconds: %d%s",
9084 p->v_connect, VTYNL);
9085 if (p->status == Established && p->rtt)
9086 vty_out (vty, "Estimated round trip time: %d ms%s",
9087 p->rtt, VTYNL);
9088 if (p->t_start)
9089 vty_out (vty, "Next start timer due in %ld seconds%s",
9090 thread_timer_remain_second (p->t_start), VTYNL);
9091 if (p->t_connect)
9092 vty_out (vty, "Next connect timer due in %ld seconds%s",
9093 thread_timer_remain_second (p->t_connect), VTYNL);
9094 if (p->t_routeadv)
9095 vty_out (vty, "MRAI (interval %u) timer expires in %ld seconds%s",
9096 p->v_routeadv, thread_timer_remain_second (p->t_routeadv),
9097 VTYNL);
9098 if (p->password)
9099 vty_out (vty, "Peer Authentication Enabled%s", VTYNL);
9100
9101 vty_out (vty, "Read thread: %s Write thread: %s%s",
9102 p->t_read ? "on" : "off",
9103 p->t_write ? "on" : "off",
9104 VTYNL);
9105 }
9106
9107 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
9108 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
9109 bgp_capability_vty_out (vty, p, use_json, json_neigh);
9110
9111 if (!use_json)
9112 vty_out (vty, "%s", VTYNL);
9113
9114 /* BFD information. */
9115 bgp_bfd_show_info(vty, p, use_json, json_neigh);
9116
9117 if (use_json)
9118 {
9119 if (p->conf_if) /* Configured interface name. */
9120 json_object_object_add(json, p->conf_if, json_neigh);
9121 else /* Configured IP address. */
9122 json_object_object_add(json, p->host, json_neigh);
9123 }
9124 }
9125
9126 static int
9127 bgp_show_neighbor (struct vty *vty, struct bgp *bgp, enum show_type type,
9128 union sockunion *su, const char *conf_if, u_char use_json, json_object *json)
9129 {
9130 struct listnode *node, *nnode;
9131 struct peer *peer;
9132 int find = 0;
9133
9134 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
9135 {
9136 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9137 continue;
9138
9139 switch (type)
9140 {
9141 case show_all:
9142 bgp_show_peer (vty, peer, use_json, json);
9143 break;
9144 case show_peer:
9145 if (conf_if)
9146 {
9147 if ((peer->conf_if && !strcmp(peer->conf_if, conf_if)) ||
9148 (peer->hostname && !strcmp(peer->hostname, conf_if)))
9149 {
9150 find = 1;
9151 bgp_show_peer (vty, peer, use_json, json);
9152 }
9153 }
9154 else
9155 {
9156 if (sockunion_same (&peer->su, su))
9157 {
9158 find = 1;
9159 bgp_show_peer (vty, peer, use_json, json);
9160 }
9161 }
9162 break;
9163 }
9164 }
9165
9166 if (type == show_peer && ! find)
9167 {
9168 if (use_json)
9169 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
9170 else
9171 vty_out (vty, "%% No such neighbor%s", VTYNL);
9172 }
9173
9174 if (use_json)
9175 {
9176 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTYNL);
9177 json_object_free(json);
9178 }
9179 else
9180 {
9181 vty_out (vty, "%s", VTYNL);
9182 }
9183
9184 return CMD_SUCCESS;
9185 }
9186
9187 static void
9188 bgp_show_all_instances_neighbors_vty (struct vty *vty, u_char use_json)
9189 {
9190 struct listnode *node, *nnode;
9191 struct bgp *bgp;
9192 json_object *json = NULL;
9193 int is_first = 1;
9194
9195 if (use_json)
9196 vty_out (vty, "{%s", VTYNL);
9197
9198 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
9199 {
9200 if (use_json)
9201 {
9202 if (!(json = json_object_new_object()))
9203 {
9204 zlog_err("Unable to allocate memory for JSON object");
9205 vty_out (vty,
9206 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
9207 VTYNL);
9208 return;
9209 }
9210
9211 json_object_int_add(json, "vrfId",
9212 (bgp->vrf_id == VRF_UNKNOWN)
9213 ? -1 : bgp->vrf_id);
9214 json_object_string_add(json, "vrfName",
9215 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9216 ? "Default" : bgp->name);
9217
9218 if (! is_first)
9219 vty_out (vty, ",%s", VTYNL);
9220 else
9221 is_first = 0;
9222
9223 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9224 ? "Default" : bgp->name);
9225 }
9226 else
9227 {
9228 vty_out (vty, "%sInstance %s:%s",
9229 VTYNL,
9230 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9231 ? "Default" : bgp->name,
9232 VTYNL);
9233 }
9234 bgp_show_neighbor (vty, bgp, show_all, NULL, NULL, use_json, json);
9235 }
9236
9237 if (use_json)
9238 vty_out (vty, "}%s", VTYNL);
9239 }
9240
9241 static int
9242 bgp_show_neighbor_vty (struct vty *vty, const char *name,
9243 enum show_type type, const char *ip_str, u_char use_json)
9244 {
9245 int ret;
9246 struct bgp *bgp;
9247 union sockunion su;
9248 json_object *json = NULL;
9249
9250 if (name)
9251 {
9252 if (strmatch(name, "all"))
9253 {
9254 bgp_show_all_instances_neighbors_vty (vty, use_json);
9255 return CMD_SUCCESS;
9256 }
9257 else
9258 {
9259 bgp = bgp_lookup_by_name (name);
9260 if (! bgp)
9261 {
9262 if (use_json)
9263 {
9264 json = json_object_new_object();
9265 json_object_boolean_true_add(json, "bgpNoSuchInstance");
9266 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTYNL);
9267 json_object_free(json);
9268 }
9269 else
9270 vty_out (vty, "%% No such BGP instance exist%s", VTYNL);
9271
9272 return CMD_WARNING;
9273 }
9274 }
9275 }
9276 else
9277 {
9278 bgp = bgp_get_default ();
9279 }
9280
9281 if (bgp)
9282 {
9283 json = json_object_new_object();
9284 if (ip_str)
9285 {
9286 ret = str2sockunion (ip_str, &su);
9287 if (ret < 0)
9288 bgp_show_neighbor (vty, bgp, type, NULL, ip_str, use_json, json);
9289 else
9290 bgp_show_neighbor (vty, bgp, type, &su, NULL, use_json, json);
9291 }
9292 else
9293 {
9294 bgp_show_neighbor (vty, bgp, type, NULL, NULL, use_json, json);
9295 }
9296 json_object_free (json);
9297 }
9298
9299 return CMD_SUCCESS;
9300 }
9301
9302 /* "show [ip] bgp neighbors" commands. */
9303 DEFUN (show_ip_bgp_neighbors,
9304 show_ip_bgp_neighbors_cmd,
9305 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|vpnv4 <all|rd ASN:nn_or_IP-address:nn>>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
9306 SHOW_STR
9307 IP_STR
9308 BGP_STR
9309 BGP_INSTANCE_HELP_STR
9310 "Address Family\n"
9311 "Address Family\n"
9312 "Address Family\n"
9313 "Display information about all VPNv4 NLRIs\n"
9314 "Display information for a route distinguisher\n"
9315 "VPN Route Distinguisher\n"
9316 "Detailed information on TCP and BGP neighbor connections\n"
9317 "Neighbor to display information about\n"
9318 "Neighbor to display information about\n"
9319 "Neighbor on BGP configured interface\n"
9320 JSON_STR)
9321 {
9322 char *vrf = NULL;
9323 char *sh_arg = NULL;
9324 enum show_type sh_type;
9325
9326 u_char uj = use_json(argc, argv);
9327
9328 int idx = 0;
9329
9330 if (argv_find (argv, argc, "view", &idx) ||
9331 argv_find (argv, argc, "vrf", &idx))
9332 vrf = argv[idx+1]->arg;
9333
9334 idx++;
9335 if (argv_find (argv, argc, "A.B.C.D", &idx) ||
9336 argv_find (argv, argc, "X:X::X:X", &idx) ||
9337 argv_find (argv, argc, "WORD", &idx))
9338 {
9339 sh_type = show_peer;
9340 sh_arg = argv[idx]->arg;
9341 }
9342 else
9343 sh_type = show_all;
9344
9345 return bgp_show_neighbor_vty (vty, vrf, sh_type, sh_arg, uj);
9346 }
9347
9348 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
9349 paths' and `show ip mbgp paths'. Those functions results are the
9350 same.*/
9351 DEFUN (show_ip_bgp_paths,
9352 show_ip_bgp_paths_cmd,
9353 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
9354 SHOW_STR
9355 IP_STR
9356 BGP_STR
9357 BGP_SAFI_HELP_STR
9358 "Path information\n")
9359 {
9360 vty_out (vty, "Address Refcnt Path%s", VTYNL);
9361 aspath_print_all_vty (vty);
9362 return CMD_SUCCESS;
9363 }
9364
9365 #include "hash.h"
9366
9367 static void
9368 community_show_all_iterator (struct hash_backet *backet, struct vty *vty)
9369 {
9370 struct community *com;
9371
9372 com = (struct community *) backet->data;
9373 vty_out (vty, "[%p] (%ld) %s%s", (void *)backet, com->refcnt,
9374 community_str (com), VTYNL);
9375 }
9376
9377 /* Show BGP's community internal data. */
9378 DEFUN (show_ip_bgp_community_info,
9379 show_ip_bgp_community_info_cmd,
9380 "show [ip] bgp community-info",
9381 SHOW_STR
9382 IP_STR
9383 BGP_STR
9384 "List all bgp community information\n")
9385 {
9386 vty_out (vty, "Address Refcnt Community%s", VTYNL);
9387
9388 hash_iterate (community_hash (),
9389 (void (*) (struct hash_backet *, void *))
9390 community_show_all_iterator,
9391 vty);
9392
9393 return CMD_SUCCESS;
9394 }
9395
9396 static void
9397 lcommunity_show_all_iterator (struct hash_backet *backet, struct vty *vty)
9398 {
9399 struct lcommunity *lcom;
9400
9401 lcom = (struct lcommunity *) backet->data;
9402 vty_out (vty, "[%p] (%ld) %s%s", (void *)backet, lcom->refcnt,
9403 lcommunity_str (lcom), VTYNL);
9404 }
9405
9406 /* Show BGP's community internal data. */
9407 DEFUN (show_ip_bgp_lcommunity_info,
9408 show_ip_bgp_lcommunity_info_cmd,
9409 "show ip bgp large-community-info",
9410 SHOW_STR
9411 IP_STR
9412 BGP_STR
9413 "List all bgp large-community information\n")
9414 {
9415 vty_out (vty, "Address Refcnt Large-community%s", VTYNL);
9416
9417 hash_iterate (lcommunity_hash (),
9418 (void (*) (struct hash_backet *, void *))
9419 lcommunity_show_all_iterator,
9420 vty);
9421
9422 return CMD_SUCCESS;
9423 }
9424
9425
9426 DEFUN (show_ip_bgp_attr_info,
9427 show_ip_bgp_attr_info_cmd,
9428 "show [ip] bgp attribute-info",
9429 SHOW_STR
9430 IP_STR
9431 BGP_STR
9432 "List all bgp attribute information\n")
9433 {
9434 attr_show_all (vty);
9435 return CMD_SUCCESS;
9436 }
9437
9438 static void
9439 bgp_show_all_instances_updgrps_vty (struct vty *vty, afi_t afi, safi_t safi)
9440 {
9441 struct listnode *node, *nnode;
9442 struct bgp *bgp;
9443
9444 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
9445 {
9446 vty_out (vty, "%sInstance %s:%s",
9447 VTYNL,
9448 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) ? "Default" : bgp->name,
9449 VTYNL);
9450 update_group_show(bgp, afi, safi, vty, 0);
9451 }
9452 }
9453
9454 static int
9455 bgp_show_update_groups(struct vty *vty, const char *name,
9456 int afi, int safi,
9457 uint64_t subgrp_id)
9458 {
9459 struct bgp *bgp;
9460
9461 if (name)
9462 {
9463 if (strmatch (name, "all"))
9464 {
9465 bgp_show_all_instances_updgrps_vty (vty, afi, safi);
9466 return CMD_SUCCESS;
9467 }
9468 else
9469 {
9470 bgp = bgp_lookup_by_name (name);
9471 }
9472 }
9473 else
9474 {
9475 bgp = bgp_get_default ();
9476 }
9477
9478 if (bgp)
9479 update_group_show(bgp, afi, safi, vty, subgrp_id);
9480 return CMD_SUCCESS;
9481 }
9482
9483 DEFUN (show_ip_bgp_updgrps,
9484 show_ip_bgp_updgrps_cmd,
9485 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
9486 SHOW_STR
9487 IP_STR
9488 BGP_STR
9489 BGP_INSTANCE_HELP_STR
9490 BGP_AFI_HELP_STR
9491 BGP_SAFI_WITH_LABEL_HELP_STR
9492 "Detailed info about dynamic update groups\n"
9493 "Specific subgroup to display detailed info for\n")
9494 {
9495 char *vrf = NULL;
9496 afi_t afi = AFI_IP6;
9497 safi_t safi = SAFI_UNICAST;
9498 uint64_t subgrp_id = 0;
9499
9500 int idx = 0;
9501
9502 /* show [ip] bgp */
9503 if (argv_find (argv, argc, "ip", &idx))
9504 afi = AFI_IP;
9505 /* [<view|vrf> VIEWVRFNAME] */
9506 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
9507 vrf = argv[++idx]->arg;
9508 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9509 if (argv_find_and_parse_afi (argv, argc, &idx, &afi))
9510 {
9511 argv_find_and_parse_safi (argv, argc, &idx, &safi);
9512 }
9513
9514 /* get subgroup id, if provided */
9515 idx = argc - 1;
9516 if (argv[idx]->type == VARIABLE_TKN)
9517 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
9518
9519 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
9520 }
9521
9522 DEFUN (show_bgp_instance_all_ipv6_updgrps,
9523 show_bgp_instance_all_ipv6_updgrps_cmd,
9524 "show [ip] bgp <view|vrf> all update-groups",
9525 SHOW_STR
9526 IP_STR
9527 BGP_STR
9528 BGP_INSTANCE_ALL_HELP_STR
9529 "Detailed info about dynamic update groups\n")
9530 {
9531 bgp_show_all_instances_updgrps_vty (vty, AFI_IP6, SAFI_UNICAST);
9532 return CMD_SUCCESS;
9533 }
9534
9535 DEFUN (show_bgp_updgrps_stats,
9536 show_bgp_updgrps_stats_cmd,
9537 "show [ip] bgp update-groups statistics",
9538 SHOW_STR
9539 IP_STR
9540 BGP_STR
9541 "Detailed info about dynamic update groups\n"
9542 "Statistics\n")
9543 {
9544 struct bgp *bgp;
9545
9546 bgp = bgp_get_default();
9547 if (bgp)
9548 update_group_show_stats(bgp, vty);
9549
9550 return CMD_SUCCESS;
9551 }
9552
9553 DEFUN (show_bgp_instance_updgrps_stats,
9554 show_bgp_instance_updgrps_stats_cmd,
9555 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
9556 SHOW_STR
9557 IP_STR
9558 BGP_STR
9559 BGP_INSTANCE_HELP_STR
9560 "Detailed info about dynamic update groups\n"
9561 "Statistics\n")
9562 {
9563 int idx_word = 3;
9564 struct bgp *bgp;
9565
9566 bgp = bgp_lookup_by_name (argv[idx_word]->arg);
9567 if (bgp)
9568 update_group_show_stats(bgp, vty);
9569
9570 return CMD_SUCCESS;
9571 }
9572
9573 static void
9574 show_bgp_updgrps_adj_info_aux (struct vty *vty, const char *name,
9575 afi_t afi, safi_t safi,
9576 const char *what, uint64_t subgrp_id)
9577 {
9578 struct bgp *bgp;
9579
9580 if (name)
9581 bgp = bgp_lookup_by_name (name);
9582 else
9583 bgp = bgp_get_default ();
9584
9585 if (bgp)
9586 {
9587 if (!strcmp(what, "advertise-queue"))
9588 update_group_show_adj_queue(bgp, afi, safi, vty, subgrp_id);
9589 else if (!strcmp(what, "advertised-routes"))
9590 update_group_show_advertised(bgp, afi, safi, vty, subgrp_id);
9591 else if (!strcmp(what, "packet-queue"))
9592 update_group_show_packet_queue(bgp, afi, safi, vty, subgrp_id);
9593 }
9594 }
9595
9596 DEFUN (show_ip_bgp_updgrps_adj,
9597 show_ip_bgp_updgrps_adj_cmd,
9598 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
9599 SHOW_STR
9600 IP_STR
9601 BGP_STR
9602 "Detailed info about dynamic update groups\n"
9603 "Advertisement queue\n"
9604 "Announced routes\n"
9605 "Packet queue\n")
9606
9607 {
9608 int idx_type = 4;
9609 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, 0);
9610 return CMD_SUCCESS;
9611 }
9612
9613 DEFUN (show_ip_bgp_instance_updgrps_adj,
9614 show_ip_bgp_instance_updgrps_adj_cmd,
9615 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
9616 SHOW_STR
9617 IP_STR
9618 BGP_STR
9619 BGP_INSTANCE_HELP_STR
9620 "Detailed info about dynamic update groups\n"
9621 "Advertisement queue\n"
9622 "Announced routes\n"
9623 "Packet queue\n")
9624
9625 {
9626 int idx_word = 4;
9627 int idx_type = 6;
9628 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, 0);
9629 return CMD_SUCCESS;
9630 }
9631
9632 DEFUN (show_bgp_updgrps_afi_adj,
9633 show_bgp_updgrps_afi_adj_cmd,
9634 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
9635 SHOW_STR
9636 IP_STR
9637 BGP_STR
9638 BGP_AFI_SAFI_HELP_STR
9639 "Detailed info about dynamic update groups\n"
9640 "Advertisement queue\n"
9641 "Announced routes\n"
9642 "Packet queue\n")
9643 {
9644 int idx_afi = 2;
9645 int idx_safi = 3;
9646 int idx_type = 5;
9647 show_bgp_updgrps_adj_info_aux(vty, NULL,
9648 bgp_vty_afi_from_str(argv[idx_afi]->text),
9649 bgp_vty_safi_from_str(argv[idx_safi]->text),
9650 argv[idx_type]->arg, 0);
9651 return CMD_SUCCESS;
9652 }
9653
9654 DEFUN (show_bgp_updgrps_adj,
9655 show_bgp_updgrps_adj_cmd,
9656 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
9657 SHOW_STR
9658 IP_STR
9659 BGP_STR
9660 "Detailed info about dynamic update groups\n"
9661 "Advertisement queue\n"
9662 "Announced routes\n"
9663 "Packet queue\n")
9664 {
9665 int idx_type = 3;
9666 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, 0);
9667 return CMD_SUCCESS;
9668 }
9669
9670 DEFUN (show_bgp_instance_updgrps_adj,
9671 show_bgp_instance_updgrps_adj_cmd,
9672 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
9673 SHOW_STR
9674 IP_STR
9675 BGP_STR
9676 BGP_INSTANCE_HELP_STR
9677 "Detailed info about dynamic update groups\n"
9678 "Advertisement queue\n"
9679 "Announced routes\n"
9680 "Packet queue\n")
9681 {
9682 int idx_word = 3;
9683 int idx_type = 5;
9684 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, 0);
9685 return CMD_SUCCESS;
9686 }
9687
9688 DEFUN (show_ip_bgp_updgrps_adj_s,
9689 show_ip_bgp_updgrps_adj_s_cmd,
9690 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9691 SHOW_STR
9692 IP_STR
9693 BGP_STR
9694 "Detailed info about dynamic update groups\n"
9695 "Specific subgroup to display info for\n"
9696 "Advertisement queue\n"
9697 "Announced routes\n"
9698 "Packet queue\n")
9699
9700 {
9701 int idx_subgroup_id = 4;
9702 int idx_type = 5;
9703 uint64_t subgrp_id;
9704
9705 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
9706
9707 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
9708 return CMD_SUCCESS;
9709 }
9710
9711 DEFUN (show_ip_bgp_instance_updgrps_adj_s,
9712 show_ip_bgp_instance_updgrps_adj_s_cmd,
9713 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9714 SHOW_STR
9715 IP_STR
9716 BGP_STR
9717 BGP_INSTANCE_HELP_STR
9718 "Detailed info about dynamic update groups\n"
9719 "Specific subgroup to display info for\n"
9720 "Advertisement queue\n"
9721 "Announced routes\n"
9722 "Packet queue\n")
9723
9724 {
9725 int idx_vrf = 4;
9726 int idx_subgroup_id = 6;
9727 int idx_type = 7;
9728 uint64_t subgrp_id;
9729
9730 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
9731
9732 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
9733 return CMD_SUCCESS;
9734 }
9735
9736 DEFUN (show_bgp_updgrps_afi_adj_s,
9737 show_bgp_updgrps_afi_adj_s_cmd,
9738 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9739 SHOW_STR
9740 IP_STR
9741 BGP_STR
9742 BGP_AFI_SAFI_HELP_STR
9743 "Detailed info about dynamic update groups\n"
9744 "Specific subgroup to display info for\n"
9745 "Advertisement queue\n"
9746 "Announced routes\n"
9747 "Packet queue\n")
9748 {
9749 int idx_afi = 2;
9750 int idx_safi = 3;
9751 int idx_subgroup_id = 5;
9752 int idx_type = 6;
9753 uint64_t subgrp_id;
9754
9755 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
9756
9757 show_bgp_updgrps_adj_info_aux(vty, NULL,
9758 bgp_vty_afi_from_str(argv[idx_afi]->text),
9759 bgp_vty_safi_from_str(argv[idx_safi]->text),
9760 argv[idx_type]->arg, subgrp_id);
9761 return CMD_SUCCESS;
9762 }
9763
9764 DEFUN (show_bgp_updgrps_adj_s,
9765 show_bgp_updgrps_adj_s_cmd,
9766 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9767 SHOW_STR
9768 IP_STR
9769 BGP_STR
9770 "Detailed info about dynamic update groups\n"
9771 "Specific subgroup to display info for\n"
9772 "Advertisement queue\n"
9773 "Announced routes\n"
9774 "Packet queue\n")
9775 {
9776 int idx_subgroup_id = 3;
9777 int idx_type = 4;
9778 uint64_t subgrp_id;
9779
9780 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
9781
9782 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
9783 return CMD_SUCCESS;
9784 }
9785
9786 DEFUN (show_bgp_instance_updgrps_adj_s,
9787 show_bgp_instance_updgrps_adj_s_cmd,
9788 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9789 SHOW_STR
9790 IP_STR
9791 BGP_STR
9792 BGP_INSTANCE_HELP_STR
9793 "Detailed info about dynamic update groups\n"
9794 "Specific subgroup to display info for\n"
9795 "Advertisement queue\n"
9796 "Announced routes\n"
9797 "Packet queue\n")
9798 {
9799 int idx_vrf = 3;
9800 int idx_subgroup_id = 5;
9801 int idx_type = 6;
9802 uint64_t subgrp_id;
9803
9804 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
9805
9806 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
9807 return CMD_SUCCESS;
9808 }
9809
9810
9811
9812 static int
9813 bgp_show_one_peer_group (struct vty *vty, struct peer_group *group)
9814 {
9815 struct listnode *node, *nnode;
9816 struct prefix *range;
9817 struct peer *conf;
9818 struct peer *peer;
9819 char buf[PREFIX2STR_BUFFER];
9820 afi_t afi;
9821 safi_t safi;
9822 const char *peer_status;
9823 const char *af_str;
9824 int lr_count;
9825 int dynamic;
9826 int af_cfgd;
9827
9828 conf = group->conf;
9829
9830 if (conf->as_type == AS_SPECIFIED ||
9831 conf->as_type == AS_EXTERNAL) {
9832 vty_out (vty, "%sBGP peer-group %s, remote AS %d%s",
9833 VTYNL, group->name, conf->as, VTYNL);
9834 } else if (conf->as_type == AS_INTERNAL) {
9835 vty_out (vty, "%sBGP peer-group %s, remote AS %d%s",
9836 VTYNL, group->name, group->bgp->as, VTYNL);
9837 } else {
9838 vty_out (vty, "%sBGP peer-group %s%s",
9839 VTYNL, group->name, VTYNL);
9840 }
9841
9842 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
9843 vty_out (vty, " Peer-group type is internal%s", VTYNL);
9844 else
9845 vty_out (vty, " Peer-group type is external%s", VTYNL);
9846
9847 /* Display AFs configured. */
9848 vty_out (vty, " Configured address-families:");
9849 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9850 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
9851 {
9852 if (conf->afc[afi][safi])
9853 {
9854 af_cfgd = 1;
9855 vty_out (vty, " %s;", afi_safi_print(afi, safi));
9856 }
9857 }
9858 if (!af_cfgd)
9859 vty_out (vty, " none%s", VTYNL);
9860 else
9861 vty_out (vty, "%s", VTYNL);
9862
9863 /* Display listen ranges (for dynamic neighbors), if any */
9864 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9865 {
9866 if (afi == AFI_IP)
9867 af_str = "IPv4";
9868 else if (afi == AFI_IP6)
9869 af_str = "IPv6";
9870 else
9871 af_str = "???";
9872 lr_count = listcount(group->listen_range[afi]);
9873 if (lr_count)
9874 {
9875 vty_out(vty,
9876 " %d %s listen range(s)%s",
9877 lr_count, af_str, VTYNL);
9878
9879
9880 for (ALL_LIST_ELEMENTS (group->listen_range[afi], node,
9881 nnode, range))
9882 {
9883 prefix2str(range, buf, sizeof(buf));
9884 vty_out(vty, " %s%s", buf, VTYNL);
9885 }
9886 }
9887 }
9888
9889 /* Display group members and their status */
9890 if (listcount(group->peer))
9891 {
9892 vty_out (vty, " Peer-group members:%s", VTYNL);
9893 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
9894 {
9895 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
9896 peer_status = "Idle (Admin)";
9897 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
9898 peer_status = "Idle (PfxCt)";
9899 else
9900 peer_status = lookup_msg(bgp_status_msg, peer->status, NULL);
9901
9902 dynamic = peer_dynamic_neighbor(peer);
9903 vty_out (vty, " %s %s %s %s",
9904 peer->host, dynamic ? "(dynamic)" : "",
9905 peer_status, VTYNL);
9906 }
9907 }
9908
9909 return CMD_SUCCESS;
9910 }
9911
9912 /* Show BGP peer group's information. */
9913 enum show_group_type
9914 {
9915 show_all_groups,
9916 show_peer_group
9917 };
9918
9919 static int
9920 bgp_show_peer_group (struct vty *vty, struct bgp *bgp,
9921 enum show_group_type type, const char *group_name)
9922 {
9923 struct listnode *node, *nnode;
9924 struct peer_group *group;
9925 int find = 0;
9926
9927 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
9928 {
9929 switch (type)
9930 {
9931 case show_all_groups:
9932 bgp_show_one_peer_group (vty, group);
9933 break;
9934 case show_peer_group:
9935 if (group_name && (strcmp(group->name, group_name) == 0))
9936 {
9937 find = 1;
9938 bgp_show_one_peer_group (vty, group);
9939 }
9940 break;
9941 }
9942 }
9943
9944 if (type == show_peer_group && ! find)
9945 vty_out (vty, "%% No such peer-group%s", VTYNL);
9946
9947 return CMD_SUCCESS;
9948 }
9949
9950 static int
9951 bgp_show_peer_group_vty (struct vty *vty, const char *name,
9952 enum show_group_type type, const char *group_name)
9953 {
9954 struct bgp *bgp;
9955 int ret = CMD_SUCCESS;
9956
9957 if (name)
9958 bgp = bgp_lookup_by_name (name);
9959 else
9960 bgp = bgp_get_default ();
9961
9962 if (! bgp)
9963 {
9964 vty_out (vty, "%% No such BGP instance exist%s", VTYNL);
9965 return CMD_WARNING;
9966 }
9967
9968 ret = bgp_show_peer_group (vty, bgp, type, group_name);
9969
9970 return ret;
9971 }
9972
9973 DEFUN (show_ip_bgp_peer_groups,
9974 show_ip_bgp_peer_groups_cmd,
9975 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
9976 SHOW_STR
9977 IP_STR
9978 BGP_STR
9979 BGP_INSTANCE_HELP_STR
9980 "Detailed information on BGP peer groups\n"
9981 "Peer group name\n")
9982 {
9983 char *vrf, *pg;
9984 vrf = pg = NULL;
9985 int idx = 0;
9986
9987 vrf = argv_find (argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
9988 pg = argv_find (argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
9989
9990 return bgp_show_peer_group_vty (vty, vrf, show_all_groups, pg);
9991 }
9992
9993
9994 /* Redistribute VTY commands. */
9995
9996 DEFUN (bgp_redistribute_ipv4,
9997 bgp_redistribute_ipv4_cmd,
9998 "redistribute " FRR_IP_REDIST_STR_BGPD,
9999 "Redistribute information from another routing protocol\n"
10000 FRR_IP_REDIST_HELP_STR_BGPD)
10001 {
10002 VTY_DECLVAR_CONTEXT(bgp, bgp);
10003 int idx_protocol = 1;
10004 int type;
10005
10006 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10007 if (type < 0)
10008 {
10009 vty_out (vty, "%% Invalid route type%s", VTYNL);
10010 return CMD_WARNING_CONFIG_FAILED;
10011 }
10012 bgp_redist_add(bgp, AFI_IP, type, 0);
10013 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
10014 }
10015
10016 ALIAS_HIDDEN (bgp_redistribute_ipv4,
10017 bgp_redistribute_ipv4_hidden_cmd,
10018 "redistribute " FRR_IP_REDIST_STR_BGPD,
10019 "Redistribute information from another routing protocol\n"
10020 FRR_IP_REDIST_HELP_STR_BGPD)
10021
10022 DEFUN (bgp_redistribute_ipv4_rmap,
10023 bgp_redistribute_ipv4_rmap_cmd,
10024 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10025 "Redistribute information from another routing protocol\n"
10026 FRR_IP_REDIST_HELP_STR_BGPD
10027 "Route map reference\n"
10028 "Pointer to route-map entries\n")
10029 {
10030 VTY_DECLVAR_CONTEXT(bgp, bgp);
10031 int idx_protocol = 1;
10032 int idx_word = 3;
10033 int type;
10034 struct bgp_redist *red;
10035
10036 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10037 if (type < 0)
10038 {
10039 vty_out (vty, "%% Invalid route type%s", VTYNL);
10040 return CMD_WARNING_CONFIG_FAILED;
10041 }
10042
10043 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10044 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
10045 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
10046 }
10047
10048 ALIAS_HIDDEN (bgp_redistribute_ipv4_rmap,
10049 bgp_redistribute_ipv4_rmap_hidden_cmd,
10050 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10051 "Redistribute information from another routing protocol\n"
10052 FRR_IP_REDIST_HELP_STR_BGPD
10053 "Route map reference\n"
10054 "Pointer to route-map entries\n")
10055
10056 DEFUN (bgp_redistribute_ipv4_metric,
10057 bgp_redistribute_ipv4_metric_cmd,
10058 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10059 "Redistribute information from another routing protocol\n"
10060 FRR_IP_REDIST_HELP_STR_BGPD
10061 "Metric for redistributed routes\n"
10062 "Default metric\n")
10063 {
10064 VTY_DECLVAR_CONTEXT(bgp, bgp);
10065 int idx_protocol = 1;
10066 int idx_number = 3;
10067 int type;
10068 u_int32_t metric;
10069 struct bgp_redist *red;
10070
10071 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10072 if (type < 0)
10073 {
10074 vty_out (vty, "%% Invalid route type%s", VTYNL);
10075 return CMD_WARNING_CONFIG_FAILED;
10076 }
10077 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10078
10079 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10080 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10081 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
10082 }
10083
10084 ALIAS_HIDDEN (bgp_redistribute_ipv4_metric,
10085 bgp_redistribute_ipv4_metric_hidden_cmd,
10086 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10087 "Redistribute information from another routing protocol\n"
10088 FRR_IP_REDIST_HELP_STR_BGPD
10089 "Metric for redistributed routes\n"
10090 "Default metric\n")
10091
10092 DEFUN (bgp_redistribute_ipv4_rmap_metric,
10093 bgp_redistribute_ipv4_rmap_metric_cmd,
10094 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
10095 "Redistribute information from another routing protocol\n"
10096 FRR_IP_REDIST_HELP_STR_BGPD
10097 "Route map reference\n"
10098 "Pointer to route-map entries\n"
10099 "Metric for redistributed routes\n"
10100 "Default metric\n")
10101 {
10102 VTY_DECLVAR_CONTEXT(bgp, bgp);
10103 int idx_protocol = 1;
10104 int idx_word = 3;
10105 int idx_number = 5;
10106 int type;
10107 u_int32_t metric;
10108 struct bgp_redist *red;
10109
10110 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10111 if (type < 0)
10112 {
10113 vty_out (vty, "%% Invalid route type%s", VTYNL);
10114 return CMD_WARNING_CONFIG_FAILED;
10115 }
10116 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10117
10118 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10119 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
10120 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10121 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
10122 }
10123
10124 ALIAS_HIDDEN (bgp_redistribute_ipv4_rmap_metric,
10125 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
10126 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
10127 "Redistribute information from another routing protocol\n"
10128 FRR_IP_REDIST_HELP_STR_BGPD
10129 "Route map reference\n"
10130 "Pointer to route-map entries\n"
10131 "Metric for redistributed routes\n"
10132 "Default metric\n")
10133
10134 DEFUN (bgp_redistribute_ipv4_metric_rmap,
10135 bgp_redistribute_ipv4_metric_rmap_cmd,
10136 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
10137 "Redistribute information from another routing protocol\n"
10138 FRR_IP_REDIST_HELP_STR_BGPD
10139 "Metric for redistributed routes\n"
10140 "Default metric\n"
10141 "Route map reference\n"
10142 "Pointer to route-map entries\n")
10143 {
10144 VTY_DECLVAR_CONTEXT(bgp, bgp);
10145 int idx_protocol = 1;
10146 int idx_number = 3;
10147 int idx_word = 5;
10148 int type;
10149 u_int32_t metric;
10150 struct bgp_redist *red;
10151
10152 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10153 if (type < 0)
10154 {
10155 vty_out (vty, "%% Invalid route type%s", VTYNL);
10156 return CMD_WARNING_CONFIG_FAILED;
10157 }
10158 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10159
10160 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10161 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10162 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
10163 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
10164 }
10165
10166 ALIAS_HIDDEN (bgp_redistribute_ipv4_metric_rmap,
10167 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
10168 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
10169 "Redistribute information from another routing protocol\n"
10170 FRR_IP_REDIST_HELP_STR_BGPD
10171 "Metric for redistributed routes\n"
10172 "Default metric\n"
10173 "Route map reference\n"
10174 "Pointer to route-map entries\n")
10175
10176 DEFUN (bgp_redistribute_ipv4_ospf,
10177 bgp_redistribute_ipv4_ospf_cmd,
10178 "redistribute <ospf|table> (1-65535)",
10179 "Redistribute information from another routing protocol\n"
10180 "Open Shortest Path First (OSPFv2)\n"
10181 "Non-main Kernel Routing Table\n"
10182 "Instance ID/Table ID\n")
10183 {
10184 VTY_DECLVAR_CONTEXT(bgp, bgp);
10185 int idx_ospf_table = 1;
10186 int idx_number = 2;
10187 u_short instance;
10188 u_short protocol;
10189
10190 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10191
10192 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10193 protocol = ZEBRA_ROUTE_OSPF;
10194 else
10195 protocol = ZEBRA_ROUTE_TABLE;
10196
10197 bgp_redist_add(bgp, AFI_IP, protocol, instance);
10198 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
10199 }
10200
10201 ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf,
10202 bgp_redistribute_ipv4_ospf_hidden_cmd,
10203 "redistribute <ospf|table> (1-65535)",
10204 "Redistribute information from another routing protocol\n"
10205 "Open Shortest Path First (OSPFv2)\n"
10206 "Non-main Kernel Routing Table\n"
10207 "Instance ID/Table ID\n")
10208
10209 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
10210 bgp_redistribute_ipv4_ospf_rmap_cmd,
10211 "redistribute <ospf|table> (1-65535) route-map WORD",
10212 "Redistribute information from another routing protocol\n"
10213 "Open Shortest Path First (OSPFv2)\n"
10214 "Non-main Kernel Routing Table\n"
10215 "Instance ID/Table ID\n"
10216 "Route map reference\n"
10217 "Pointer to route-map entries\n")
10218 {
10219 VTY_DECLVAR_CONTEXT(bgp, bgp);
10220 int idx_ospf_table = 1;
10221 int idx_number = 2;
10222 int idx_word = 4;
10223 struct bgp_redist *red;
10224 u_short instance;
10225 int protocol;
10226
10227 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10228 protocol = ZEBRA_ROUTE_OSPF;
10229 else
10230 protocol = ZEBRA_ROUTE_TABLE;
10231
10232 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10233 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10234 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
10235 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
10236 }
10237
10238 ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf_rmap,
10239 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
10240 "redistribute <ospf|table> (1-65535) route-map WORD",
10241 "Redistribute information from another routing protocol\n"
10242 "Open Shortest Path First (OSPFv2)\n"
10243 "Non-main Kernel Routing Table\n"
10244 "Instance ID/Table ID\n"
10245 "Route map reference\n"
10246 "Pointer to route-map entries\n")
10247
10248 DEFUN (bgp_redistribute_ipv4_ospf_metric,
10249 bgp_redistribute_ipv4_ospf_metric_cmd,
10250 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10251 "Redistribute information from another routing protocol\n"
10252 "Open Shortest Path First (OSPFv2)\n"
10253 "Non-main Kernel Routing Table\n"
10254 "Instance ID/Table ID\n"
10255 "Metric for redistributed routes\n"
10256 "Default metric\n")
10257 {
10258 VTY_DECLVAR_CONTEXT(bgp, bgp);
10259 int idx_ospf_table = 1;
10260 int idx_number = 2;
10261 int idx_number_2 = 4;
10262 u_int32_t metric;
10263 struct bgp_redist *red;
10264 u_short instance;
10265 int protocol;
10266
10267 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10268 protocol = ZEBRA_ROUTE_OSPF;
10269 else
10270 protocol = ZEBRA_ROUTE_TABLE;
10271
10272 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10273 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10274
10275 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10276 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10277 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
10278 }
10279
10280 ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf_metric,
10281 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
10282 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10283 "Redistribute information from another routing protocol\n"
10284 "Open Shortest Path First (OSPFv2)\n"
10285 "Non-main Kernel Routing Table\n"
10286 "Instance ID/Table ID\n"
10287 "Metric for redistributed routes\n"
10288 "Default metric\n")
10289
10290 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
10291 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
10292 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10293 "Redistribute information from another routing protocol\n"
10294 "Open Shortest Path First (OSPFv2)\n"
10295 "Non-main Kernel Routing Table\n"
10296 "Instance ID/Table ID\n"
10297 "Route map reference\n"
10298 "Pointer to route-map entries\n"
10299 "Metric for redistributed routes\n"
10300 "Default metric\n")
10301 {
10302 VTY_DECLVAR_CONTEXT(bgp, bgp);
10303 int idx_ospf_table = 1;
10304 int idx_number = 2;
10305 int idx_word = 4;
10306 int idx_number_2 = 6;
10307 u_int32_t metric;
10308 struct bgp_redist *red;
10309 u_short instance;
10310 int protocol;
10311
10312 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10313 protocol = ZEBRA_ROUTE_OSPF;
10314 else
10315 protocol = ZEBRA_ROUTE_TABLE;
10316
10317 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10318 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10319
10320 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10321 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
10322 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10323 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
10324 }
10325
10326 ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf_rmap_metric,
10327 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
10328 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10329 "Redistribute information from another routing protocol\n"
10330 "Open Shortest Path First (OSPFv2)\n"
10331 "Non-main Kernel Routing Table\n"
10332 "Instance ID/Table ID\n"
10333 "Route map reference\n"
10334 "Pointer to route-map entries\n"
10335 "Metric for redistributed routes\n"
10336 "Default metric\n")
10337
10338 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
10339 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
10340 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
10341 "Redistribute information from another routing protocol\n"
10342 "Open Shortest Path First (OSPFv2)\n"
10343 "Non-main Kernel Routing Table\n"
10344 "Instance ID/Table ID\n"
10345 "Metric for redistributed routes\n"
10346 "Default metric\n"
10347 "Route map reference\n"
10348 "Pointer to route-map entries\n")
10349 {
10350 VTY_DECLVAR_CONTEXT(bgp, bgp);
10351 int idx_ospf_table = 1;
10352 int idx_number = 2;
10353 int idx_number_2 = 4;
10354 int idx_word = 6;
10355 u_int32_t metric;
10356 struct bgp_redist *red;
10357 u_short instance;
10358 int protocol;
10359
10360 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10361 protocol = ZEBRA_ROUTE_OSPF;
10362 else
10363 protocol = ZEBRA_ROUTE_TABLE;
10364
10365 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10366 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10367
10368 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10369 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10370 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
10371 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
10372 }
10373
10374 ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf_metric_rmap,
10375 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
10376 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
10377 "Redistribute information from another routing protocol\n"
10378 "Open Shortest Path First (OSPFv2)\n"
10379 "Non-main Kernel Routing Table\n"
10380 "Instance ID/Table ID\n"
10381 "Metric for redistributed routes\n"
10382 "Default metric\n"
10383 "Route map reference\n"
10384 "Pointer to route-map entries\n")
10385
10386 DEFUN (no_bgp_redistribute_ipv4_ospf,
10387 no_bgp_redistribute_ipv4_ospf_cmd,
10388 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
10389 NO_STR
10390 "Redistribute information from another routing protocol\n"
10391 "Open Shortest Path First (OSPFv2)\n"
10392 "Non-main Kernel Routing Table\n"
10393 "Instance ID/Table ID\n"
10394 "Metric for redistributed routes\n"
10395 "Default metric\n"
10396 "Route map reference\n"
10397 "Pointer to route-map entries\n")
10398 {
10399 VTY_DECLVAR_CONTEXT(bgp, bgp);
10400 int idx_ospf_table = 2;
10401 int idx_number = 3;
10402 u_short instance;
10403 int protocol;
10404
10405 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10406 protocol = ZEBRA_ROUTE_OSPF;
10407 else
10408 protocol = ZEBRA_ROUTE_TABLE;
10409
10410 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10411 return bgp_redistribute_unset (bgp, AFI_IP, protocol, instance);
10412 }
10413
10414 ALIAS_HIDDEN (no_bgp_redistribute_ipv4_ospf,
10415 no_bgp_redistribute_ipv4_ospf_hidden_cmd,
10416 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
10417 NO_STR
10418 "Redistribute information from another routing protocol\n"
10419 "Open Shortest Path First (OSPFv2)\n"
10420 "Non-main Kernel Routing Table\n"
10421 "Instance ID/Table ID\n"
10422 "Metric for redistributed routes\n"
10423 "Default metric\n"
10424 "Route map reference\n"
10425 "Pointer to route-map entries\n")
10426
10427 DEFUN (no_bgp_redistribute_ipv4,
10428 no_bgp_redistribute_ipv4_cmd,
10429 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
10430 NO_STR
10431 "Redistribute information from another routing protocol\n"
10432 FRR_IP_REDIST_HELP_STR_BGPD
10433 "Metric for redistributed routes\n"
10434 "Default metric\n"
10435 "Route map reference\n"
10436 "Pointer to route-map entries\n")
10437 {
10438 VTY_DECLVAR_CONTEXT(bgp, bgp);
10439 int idx_protocol = 2;
10440 int type;
10441
10442 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10443 if (type < 0)
10444 {
10445 vty_out (vty, "%% Invalid route type%s", VTYNL);
10446 return CMD_WARNING_CONFIG_FAILED;
10447 }
10448 return bgp_redistribute_unset (bgp, AFI_IP, type, 0);
10449 }
10450
10451 ALIAS_HIDDEN (no_bgp_redistribute_ipv4,
10452 no_bgp_redistribute_ipv4_hidden_cmd,
10453 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
10454 NO_STR
10455 "Redistribute information from another routing protocol\n"
10456 FRR_IP_REDIST_HELP_STR_BGPD
10457 "Metric for redistributed routes\n"
10458 "Default metric\n"
10459 "Route map reference\n"
10460 "Pointer to route-map entries\n")
10461
10462 DEFUN (bgp_redistribute_ipv6,
10463 bgp_redistribute_ipv6_cmd,
10464 "redistribute " FRR_IP6_REDIST_STR_BGPD,
10465 "Redistribute information from another routing protocol\n"
10466 FRR_IP6_REDIST_HELP_STR_BGPD)
10467 {
10468 VTY_DECLVAR_CONTEXT(bgp, bgp);
10469 int idx_protocol = 1;
10470 int type;
10471
10472 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10473 if (type < 0)
10474 {
10475 vty_out (vty, "%% Invalid route type%s", VTYNL);
10476 return CMD_WARNING_CONFIG_FAILED;
10477 }
10478
10479 bgp_redist_add(bgp, AFI_IP6, type, 0);
10480 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
10481 }
10482
10483 DEFUN (bgp_redistribute_ipv6_rmap,
10484 bgp_redistribute_ipv6_rmap_cmd,
10485 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
10486 "Redistribute information from another routing protocol\n"
10487 FRR_IP6_REDIST_HELP_STR_BGPD
10488 "Route map reference\n"
10489 "Pointer to route-map entries\n")
10490 {
10491 VTY_DECLVAR_CONTEXT(bgp, bgp);
10492 int idx_protocol = 1;
10493 int idx_word = 3;
10494 int type;
10495 struct bgp_redist *red;
10496
10497 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10498 if (type < 0)
10499 {
10500 vty_out (vty, "%% Invalid route type%s", VTYNL);
10501 return CMD_WARNING_CONFIG_FAILED;
10502 }
10503
10504 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
10505 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
10506 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
10507 }
10508
10509 DEFUN (bgp_redistribute_ipv6_metric,
10510 bgp_redistribute_ipv6_metric_cmd,
10511 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
10512 "Redistribute information from another routing protocol\n"
10513 FRR_IP6_REDIST_HELP_STR_BGPD
10514 "Metric for redistributed routes\n"
10515 "Default metric\n")
10516 {
10517 VTY_DECLVAR_CONTEXT(bgp, bgp);
10518 int idx_protocol = 1;
10519 int idx_number = 3;
10520 int type;
10521 u_int32_t metric;
10522 struct bgp_redist *red;
10523
10524 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10525 if (type < 0)
10526 {
10527 vty_out (vty, "%% Invalid route type%s", VTYNL);
10528 return CMD_WARNING_CONFIG_FAILED;
10529 }
10530 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10531
10532 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
10533 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
10534 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
10535 }
10536
10537 DEFUN (bgp_redistribute_ipv6_rmap_metric,
10538 bgp_redistribute_ipv6_rmap_metric_cmd,
10539 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
10540 "Redistribute information from another routing protocol\n"
10541 FRR_IP6_REDIST_HELP_STR_BGPD
10542 "Route map reference\n"
10543 "Pointer to route-map entries\n"
10544 "Metric for redistributed routes\n"
10545 "Default metric\n")
10546 {
10547 VTY_DECLVAR_CONTEXT(bgp, bgp);
10548 int idx_protocol = 1;
10549 int idx_word = 3;
10550 int idx_number = 5;
10551 int type;
10552 u_int32_t metric;
10553 struct bgp_redist *red;
10554
10555 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10556 if (type < 0)
10557 {
10558 vty_out (vty, "%% Invalid route type%s", VTYNL);
10559 return CMD_WARNING_CONFIG_FAILED;
10560 }
10561 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10562
10563 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
10564 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
10565 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
10566 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
10567 }
10568
10569 DEFUN (bgp_redistribute_ipv6_metric_rmap,
10570 bgp_redistribute_ipv6_metric_rmap_cmd,
10571 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
10572 "Redistribute information from another routing protocol\n"
10573 FRR_IP6_REDIST_HELP_STR_BGPD
10574 "Metric for redistributed routes\n"
10575 "Default metric\n"
10576 "Route map reference\n"
10577 "Pointer to route-map entries\n")
10578 {
10579 VTY_DECLVAR_CONTEXT(bgp, bgp);
10580 int idx_protocol = 1;
10581 int idx_number = 3;
10582 int idx_word = 5;
10583 int type;
10584 u_int32_t metric;
10585 struct bgp_redist *red;
10586
10587 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10588 if (type < 0)
10589 {
10590 vty_out (vty, "%% Invalid route type%s", VTYNL);
10591 return CMD_WARNING_CONFIG_FAILED;
10592 }
10593 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10594
10595 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
10596 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
10597 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
10598 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
10599 }
10600
10601 DEFUN (no_bgp_redistribute_ipv6,
10602 no_bgp_redistribute_ipv6_cmd,
10603 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
10604 NO_STR
10605 "Redistribute information from another routing protocol\n"
10606 FRR_IP6_REDIST_HELP_STR_BGPD
10607 "Metric for redistributed routes\n"
10608 "Default metric\n"
10609 "Route map reference\n"
10610 "Pointer to route-map entries\n")
10611 {
10612 VTY_DECLVAR_CONTEXT(bgp, bgp);
10613 int idx_protocol = 2;
10614 int type;
10615
10616 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10617 if (type < 0)
10618 {
10619 vty_out (vty, "%% Invalid route type%s", VTYNL);
10620 return CMD_WARNING_CONFIG_FAILED;
10621 }
10622
10623 return bgp_redistribute_unset (bgp, AFI_IP6, type, 0);
10624 }
10625
10626 int
10627 bgp_config_write_redistribute (struct vty *vty, struct bgp *bgp, afi_t afi,
10628 safi_t safi, int *write)
10629 {
10630 int i;
10631
10632 /* Unicast redistribution only. */
10633 if (safi != SAFI_UNICAST)
10634 return 0;
10635
10636 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
10637 {
10638 /* Redistribute BGP does not make sense. */
10639 if (i != ZEBRA_ROUTE_BGP)
10640 {
10641 struct list *red_list;
10642 struct listnode *node;
10643 struct bgp_redist *red;
10644
10645 red_list = bgp->redist[afi][i];
10646 if (!red_list)
10647 continue;
10648
10649 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
10650 {
10651 /* Display "address-family" when it is not yet diplayed. */
10652 bgp_config_write_family_header (vty, afi, safi, write);
10653
10654 /* "redistribute" configuration. */
10655 vty_out (vty, " redistribute %s", zebra_route_string(i));
10656 if (red->instance)
10657 vty_out (vty, " %d", red->instance);
10658 if (red->redist_metric_flag)
10659 vty_out (vty, " metric %u", red->redist_metric);
10660 if (red->rmap.name)
10661 vty_out (vty, " route-map %s", red->rmap.name);
10662 vty_out (vty, "%s", VTYNL);
10663 }
10664 }
10665 }
10666 return *write;
10667 }
10668
10669 /* BGP node structure. */
10670 static struct cmd_node bgp_node =
10671 {
10672 BGP_NODE,
10673 "%s(config-router)# ",
10674 1,
10675 };
10676
10677 static struct cmd_node bgp_ipv4_unicast_node =
10678 {
10679 BGP_IPV4_NODE,
10680 "%s(config-router-af)# ",
10681 1,
10682 };
10683
10684 static struct cmd_node bgp_ipv4_multicast_node =
10685 {
10686 BGP_IPV4M_NODE,
10687 "%s(config-router-af)# ",
10688 1,
10689 };
10690
10691 static struct cmd_node bgp_ipv4_labeled_unicast_node =
10692 {
10693 BGP_IPV4L_NODE,
10694 "%s(config-router-af)# ",
10695 1,
10696 };
10697
10698 static struct cmd_node bgp_ipv6_unicast_node =
10699 {
10700 BGP_IPV6_NODE,
10701 "%s(config-router-af)# ",
10702 1,
10703 };
10704
10705 static struct cmd_node bgp_ipv6_multicast_node =
10706 {
10707 BGP_IPV6M_NODE,
10708 "%s(config-router-af)# ",
10709 1,
10710 };
10711
10712 static struct cmd_node bgp_ipv6_labeled_unicast_node =
10713 {
10714 BGP_IPV6L_NODE,
10715 "%s(config-router-af)# ",
10716 1,
10717 };
10718
10719 static struct cmd_node bgp_vpnv4_node =
10720 {
10721 BGP_VPNV4_NODE,
10722 "%s(config-router-af)# ",
10723 1
10724 };
10725
10726 static struct cmd_node bgp_vpnv6_node =
10727 {
10728 BGP_VPNV6_NODE,
10729 "%s(config-router-af-vpnv6)# ",
10730 1
10731 };
10732
10733 static struct cmd_node bgp_evpn_node =
10734 {
10735 BGP_EVPN_NODE,
10736 "%s(config-router-evpn)# ",
10737 1
10738 };
10739
10740 static struct cmd_node bgp_evpn_vni_node =
10741 {
10742 BGP_EVPN_VNI_NODE,
10743 "%s(config-router-af-vni)# ",
10744 1
10745 };
10746
10747 static void community_list_vty (void);
10748
10749 static void
10750 bgp_ac_neighbor (vector comps, struct cmd_token *token)
10751 {
10752 struct bgp *bgp;
10753 struct peer *peer;
10754 struct peer_group *group;
10755 struct listnode *lnbgp, *lnpeer;
10756
10757 for (ALL_LIST_ELEMENTS_RO (bm->bgp, lnbgp, bgp))
10758 {
10759 for (ALL_LIST_ELEMENTS_RO (bgp->peer, lnpeer, peer))
10760 {
10761 /* only provide suggestions on the appropriate input token type,
10762 * they'll otherwise show up multiple times */
10763 enum cmd_token_type match_type;
10764 char *name = peer->host;
10765
10766 if (peer->conf_if)
10767 {
10768 match_type = VARIABLE_TKN;
10769 name = peer->conf_if;
10770 }
10771 else if (strchr(peer->host, ':'))
10772 match_type = IPV6_TKN;
10773 else
10774 match_type = IPV4_TKN;
10775
10776 if (token->type != match_type)
10777 continue;
10778
10779 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
10780 }
10781
10782 if (token->type == VARIABLE_TKN)
10783 for (ALL_LIST_ELEMENTS_RO (bgp->group, lnpeer, group))
10784 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, group->name));
10785 }
10786 }
10787
10788 static const struct cmd_variable_handler bgp_var_neighbor[] = {
10789 {
10790 .varname = "neighbor",
10791 .completions = bgp_ac_neighbor
10792 }, {
10793 .varname = "neighbors",
10794 .completions = bgp_ac_neighbor
10795 }, {
10796 .completions = NULL
10797 }
10798 };
10799
10800 void
10801 bgp_vty_init (void)
10802 {
10803 cmd_variable_handler_register(bgp_var_neighbor);
10804
10805 /* Install bgp top node. */
10806 install_node (&bgp_node, bgp_config_write);
10807 install_node (&bgp_ipv4_unicast_node, NULL);
10808 install_node (&bgp_ipv4_multicast_node, NULL);
10809 install_node (&bgp_ipv4_labeled_unicast_node, NULL);
10810 install_node (&bgp_ipv6_unicast_node, NULL);
10811 install_node (&bgp_ipv6_multicast_node, NULL);
10812 install_node (&bgp_ipv6_labeled_unicast_node, NULL);
10813 install_node (&bgp_vpnv4_node, NULL);
10814 install_node (&bgp_vpnv6_node, NULL);
10815 install_node (&bgp_evpn_node, NULL);
10816 install_node (&bgp_evpn_vni_node, NULL);
10817
10818 /* Install default VTY commands to new nodes. */
10819 install_default (BGP_NODE);
10820 install_default (BGP_IPV4_NODE);
10821 install_default (BGP_IPV4M_NODE);
10822 install_default (BGP_IPV4L_NODE);
10823 install_default (BGP_IPV6_NODE);
10824 install_default (BGP_IPV6M_NODE);
10825 install_default (BGP_IPV6L_NODE);
10826 install_default (BGP_VPNV4_NODE);
10827 install_default (BGP_VPNV6_NODE);
10828 install_default (BGP_EVPN_NODE);
10829 install_default (BGP_EVPN_VNI_NODE);
10830
10831 /* "bgp multiple-instance" commands. */
10832 install_element (CONFIG_NODE, &bgp_multiple_instance_cmd);
10833 install_element (CONFIG_NODE, &no_bgp_multiple_instance_cmd);
10834
10835 /* "bgp config-type" commands. */
10836 install_element (CONFIG_NODE, &bgp_config_type_cmd);
10837 install_element (CONFIG_NODE, &no_bgp_config_type_cmd);
10838
10839 /* bgp route-map delay-timer commands. */
10840 install_element (CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
10841 install_element (CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
10842
10843 /* Dummy commands (Currently not supported) */
10844 install_element (BGP_NODE, &no_synchronization_cmd);
10845 install_element (BGP_NODE, &no_auto_summary_cmd);
10846
10847 /* "router bgp" commands. */
10848 install_element (CONFIG_NODE, &router_bgp_cmd);
10849
10850 /* "no router bgp" commands. */
10851 install_element (CONFIG_NODE, &no_router_bgp_cmd);
10852
10853 /* "bgp router-id" commands. */
10854 install_element (BGP_NODE, &bgp_router_id_cmd);
10855 install_element (BGP_NODE, &no_bgp_router_id_cmd);
10856
10857 /* "bgp cluster-id" commands. */
10858 install_element (BGP_NODE, &bgp_cluster_id_cmd);
10859 install_element (BGP_NODE, &no_bgp_cluster_id_cmd);
10860
10861 /* "bgp confederation" commands. */
10862 install_element (BGP_NODE, &bgp_confederation_identifier_cmd);
10863 install_element (BGP_NODE, &no_bgp_confederation_identifier_cmd);
10864
10865 /* "bgp confederation peers" commands. */
10866 install_element (BGP_NODE, &bgp_confederation_peers_cmd);
10867 install_element (BGP_NODE, &no_bgp_confederation_peers_cmd);
10868
10869 /* bgp max-med command */
10870 install_element (BGP_NODE, &bgp_maxmed_admin_cmd);
10871 install_element (BGP_NODE, &no_bgp_maxmed_admin_cmd);
10872 install_element (BGP_NODE, &bgp_maxmed_admin_medv_cmd);
10873 install_element (BGP_NODE, &bgp_maxmed_onstartup_cmd);
10874 install_element (BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
10875
10876 /* bgp disable-ebgp-connected-nh-check */
10877 install_element (BGP_NODE, &bgp_disable_connected_route_check_cmd);
10878 install_element (BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
10879
10880 /* bgp update-delay command */
10881 install_element (BGP_NODE, &bgp_update_delay_cmd);
10882 install_element (BGP_NODE, &no_bgp_update_delay_cmd);
10883 install_element (BGP_NODE, &bgp_update_delay_establish_wait_cmd);
10884
10885 install_element (BGP_NODE, &bgp_wpkt_quanta_cmd);
10886 install_element (BGP_NODE, &no_bgp_wpkt_quanta_cmd);
10887
10888 install_element (BGP_NODE, &bgp_coalesce_time_cmd);
10889 install_element (BGP_NODE, &no_bgp_coalesce_time_cmd);
10890
10891 /* "maximum-paths" commands. */
10892 install_element (BGP_NODE, &bgp_maxpaths_hidden_cmd);
10893 install_element (BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
10894 install_element (BGP_IPV4_NODE, &bgp_maxpaths_cmd);
10895 install_element (BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
10896 install_element (BGP_IPV6_NODE, &bgp_maxpaths_cmd);
10897 install_element (BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
10898 install_element (BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
10899 install_element (BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
10900 install_element (BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
10901 install_element (BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
10902 install_element (BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
10903 install_element (BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
10904 install_element (BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
10905 install_element (BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
10906 install_element (BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
10907
10908 install_element (BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
10909 install_element (BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
10910 install_element (BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
10911 install_element (BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
10912 install_element (BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
10913
10914 /* "timers bgp" commands. */
10915 install_element (BGP_NODE, &bgp_timers_cmd);
10916 install_element (BGP_NODE, &no_bgp_timers_cmd);
10917
10918 /* route-map delay-timer commands - per instance for backwards compat. */
10919 install_element (BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
10920 install_element (BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
10921
10922 /* "bgp client-to-client reflection" commands */
10923 install_element (BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
10924 install_element (BGP_NODE, &bgp_client_to_client_reflection_cmd);
10925
10926 /* "bgp always-compare-med" commands */
10927 install_element (BGP_NODE, &bgp_always_compare_med_cmd);
10928 install_element (BGP_NODE, &no_bgp_always_compare_med_cmd);
10929
10930 /* "bgp deterministic-med" commands */
10931 install_element (BGP_NODE, &bgp_deterministic_med_cmd);
10932 install_element (BGP_NODE, &no_bgp_deterministic_med_cmd);
10933
10934 /* "bgp graceful-restart" commands */
10935 install_element (BGP_NODE, &bgp_graceful_restart_cmd);
10936 install_element (BGP_NODE, &no_bgp_graceful_restart_cmd);
10937 install_element (BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
10938 install_element (BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
10939 install_element (BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
10940 install_element (BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
10941
10942 install_element (BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
10943 install_element (BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
10944
10945 /* "bgp fast-external-failover" commands */
10946 install_element (BGP_NODE, &bgp_fast_external_failover_cmd);
10947 install_element (BGP_NODE, &no_bgp_fast_external_failover_cmd);
10948
10949 /* "bgp enforce-first-as" commands */
10950 install_element (BGP_NODE, &bgp_enforce_first_as_cmd);
10951 install_element (BGP_NODE, &no_bgp_enforce_first_as_cmd);
10952
10953 /* "bgp bestpath compare-routerid" commands */
10954 install_element (BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
10955 install_element (BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
10956
10957 /* "bgp bestpath as-path ignore" commands */
10958 install_element (BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
10959 install_element (BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
10960
10961 /* "bgp bestpath as-path confed" commands */
10962 install_element (BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
10963 install_element (BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
10964
10965 /* "bgp bestpath as-path multipath-relax" commands */
10966 install_element (BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
10967 install_element (BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
10968
10969 /* "bgp log-neighbor-changes" commands */
10970 install_element (BGP_NODE, &bgp_log_neighbor_changes_cmd);
10971 install_element (BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
10972
10973 /* "bgp bestpath med" commands */
10974 install_element (BGP_NODE, &bgp_bestpath_med_cmd);
10975 install_element (BGP_NODE, &no_bgp_bestpath_med_cmd);
10976
10977 /* "no bgp default ipv4-unicast" commands. */
10978 install_element (BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
10979 install_element (BGP_NODE, &bgp_default_ipv4_unicast_cmd);
10980
10981 /* "bgp network import-check" commands. */
10982 install_element (BGP_NODE, &bgp_network_import_check_cmd);
10983 install_element (BGP_NODE, &bgp_network_import_check_exact_cmd);
10984 install_element (BGP_NODE, &no_bgp_network_import_check_cmd);
10985
10986 /* "bgp default local-preference" commands. */
10987 install_element (BGP_NODE, &bgp_default_local_preference_cmd);
10988 install_element (BGP_NODE, &no_bgp_default_local_preference_cmd);
10989
10990 /* bgp default show-hostname */
10991 install_element (BGP_NODE, &bgp_default_show_hostname_cmd);
10992 install_element (BGP_NODE, &no_bgp_default_show_hostname_cmd);
10993
10994 /* "bgp default subgroup-pkt-queue-max" commands. */
10995 install_element (BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
10996 install_element (BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
10997
10998 /* bgp ibgp-allow-policy-mods command */
10999 install_element (BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11000 install_element (BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11001
11002 /* "bgp listen limit" commands. */
11003 install_element (BGP_NODE, &bgp_listen_limit_cmd);
11004 install_element (BGP_NODE, &no_bgp_listen_limit_cmd);
11005
11006 /* "bgp listen range" commands. */
11007 install_element (BGP_NODE, &bgp_listen_range_cmd);
11008 install_element (BGP_NODE, &no_bgp_listen_range_cmd);
11009
11010 /* "neighbor remote-as" commands. */
11011 install_element (BGP_NODE, &neighbor_remote_as_cmd);
11012 install_element (BGP_NODE, &neighbor_interface_config_cmd);
11013 install_element (BGP_NODE, &neighbor_interface_config_v6only_cmd);
11014 install_element (BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11015 install_element (BGP_NODE, &neighbor_interface_v6only_config_remote_as_cmd);
11016 install_element (BGP_NODE, &no_neighbor_cmd);
11017 install_element (BGP_NODE, &no_neighbor_interface_config_cmd);
11018
11019 /* "neighbor peer-group" commands. */
11020 install_element (BGP_NODE, &neighbor_peer_group_cmd);
11021 install_element (BGP_NODE, &no_neighbor_peer_group_cmd);
11022 install_element (BGP_NODE, &no_neighbor_interface_peer_group_remote_as_cmd);
11023
11024 /* "neighbor local-as" commands. */
11025 install_element (BGP_NODE, &neighbor_local_as_cmd);
11026 install_element (BGP_NODE, &neighbor_local_as_no_prepend_cmd);
11027 install_element (BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
11028 install_element (BGP_NODE, &no_neighbor_local_as_cmd);
11029
11030 /* "neighbor solo" commands. */
11031 install_element (BGP_NODE, &neighbor_solo_cmd);
11032 install_element (BGP_NODE, &no_neighbor_solo_cmd);
11033
11034 /* "neighbor password" commands. */
11035 install_element (BGP_NODE, &neighbor_password_cmd);
11036 install_element (BGP_NODE, &no_neighbor_password_cmd);
11037
11038 /* "neighbor activate" commands. */
11039 install_element (BGP_NODE, &neighbor_activate_hidden_cmd);
11040 install_element (BGP_IPV4_NODE, &neighbor_activate_cmd);
11041 install_element (BGP_IPV4M_NODE, &neighbor_activate_cmd);
11042 install_element (BGP_IPV4L_NODE, &neighbor_activate_cmd);
11043 install_element (BGP_IPV6_NODE, &neighbor_activate_cmd);
11044 install_element (BGP_IPV6M_NODE, &neighbor_activate_cmd);
11045 install_element (BGP_IPV6L_NODE, &neighbor_activate_cmd);
11046 install_element (BGP_VPNV4_NODE, &neighbor_activate_cmd);
11047 install_element (BGP_VPNV6_NODE, &neighbor_activate_cmd);
11048 install_element (BGP_EVPN_NODE, &neighbor_activate_cmd);
11049
11050 /* "no neighbor activate" commands. */
11051 install_element (BGP_NODE, &no_neighbor_activate_hidden_cmd);
11052 install_element (BGP_IPV4_NODE, &no_neighbor_activate_cmd);
11053 install_element (BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
11054 install_element (BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
11055 install_element (BGP_IPV6_NODE, &no_neighbor_activate_cmd);
11056 install_element (BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
11057 install_element (BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
11058 install_element (BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
11059 install_element (BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
11060 install_element (BGP_EVPN_NODE, &no_neighbor_activate_cmd);
11061
11062 /* "neighbor peer-group" set commands. */
11063 install_element (BGP_NODE, &neighbor_set_peer_group_cmd);
11064 install_element (BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11065 install_element (BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
11066 install_element (BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11067 install_element (BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
11068 install_element (BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
11069 install_element (BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11070 install_element (BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11071
11072 /* "no neighbor peer-group unset" commands. */
11073 install_element (BGP_NODE, &no_neighbor_set_peer_group_cmd);
11074 install_element (BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11075 install_element (BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11076 install_element (BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11077 install_element (BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11078 install_element (BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11079 install_element (BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11080 install_element (BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11081
11082 /* "neighbor softreconfiguration inbound" commands.*/
11083 install_element (BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
11084 install_element (BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
11085 install_element (BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
11086 install_element (BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11087 install_element (BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
11088 install_element (BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11089 install_element (BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
11090 install_element (BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11091 install_element (BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
11092 install_element (BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11093 install_element (BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
11094 install_element (BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11095 install_element (BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
11096 install_element (BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11097 install_element (BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
11098 install_element (BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11099 install_element (BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
11100 install_element (BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11101
11102 /* "neighbor attribute-unchanged" commands. */
11103 install_element (BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
11104 install_element (BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
11105 install_element (BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
11106 install_element (BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
11107 install_element (BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
11108 install_element (BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
11109 install_element (BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
11110 install_element (BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
11111 install_element (BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
11112 install_element (BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
11113 install_element (BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
11114 install_element (BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
11115 install_element (BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
11116 install_element (BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
11117 install_element (BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
11118 install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
11119 install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
11120 install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
11121
11122 install_element (BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
11123 install_element (BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
11124
11125 /* "nexthop-local unchanged" commands */
11126 install_element (BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
11127 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_local_unchanged_cmd);
11128
11129 /* "neighbor next-hop-self" commands. */
11130 install_element (BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
11131 install_element (BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
11132 install_element (BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
11133 install_element (BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
11134 install_element (BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
11135 install_element (BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
11136 install_element (BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
11137 install_element (BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
11138 install_element (BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
11139 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
11140 install_element (BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
11141 install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
11142 install_element (BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
11143 install_element (BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
11144 install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
11145 install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
11146 install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
11147 install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
11148
11149 /* "neighbor next-hop-self force" commands. */
11150 install_element (BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
11151 install_element (BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
11152 install_element (BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
11153 install_element (BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11154 install_element (BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
11155 install_element (BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
11156 install_element (BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
11157 install_element (BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
11158 install_element (BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
11159 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11160 install_element (BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
11161 install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
11162 install_element (BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
11163 install_element (BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
11164 install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
11165 install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11166 install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
11167 install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11168
11169 /* "neighbor as-override" commands. */
11170 install_element (BGP_NODE, &neighbor_as_override_hidden_cmd);
11171 install_element (BGP_NODE, &no_neighbor_as_override_hidden_cmd);
11172 install_element (BGP_IPV4_NODE, &neighbor_as_override_cmd);
11173 install_element (BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
11174 install_element (BGP_IPV4M_NODE, &neighbor_as_override_cmd);
11175 install_element (BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
11176 install_element (BGP_IPV4L_NODE, &neighbor_as_override_cmd);
11177 install_element (BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
11178 install_element (BGP_IPV6_NODE, &neighbor_as_override_cmd);
11179 install_element (BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
11180 install_element (BGP_IPV6M_NODE, &neighbor_as_override_cmd);
11181 install_element (BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
11182 install_element (BGP_IPV6L_NODE, &neighbor_as_override_cmd);
11183 install_element (BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
11184 install_element (BGP_VPNV4_NODE, &neighbor_as_override_cmd);
11185 install_element (BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
11186 install_element (BGP_VPNV6_NODE, &neighbor_as_override_cmd);
11187 install_element (BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
11188
11189 /* "neighbor remove-private-AS" commands. */
11190 install_element (BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
11191 install_element (BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
11192 install_element (BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
11193 install_element (BGP_NODE, &no_neighbor_remove_private_as_all_hidden_cmd);
11194 install_element (BGP_NODE, &neighbor_remove_private_as_replace_as_hidden_cmd);
11195 install_element (BGP_NODE, &no_neighbor_remove_private_as_replace_as_hidden_cmd);
11196 install_element (BGP_NODE, &neighbor_remove_private_as_all_replace_as_hidden_cmd);
11197 install_element (BGP_NODE, &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
11198 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
11199 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
11200 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
11201 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11202 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_replace_as_cmd);
11203 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11204 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11205 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
11206 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
11207 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
11208 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
11209 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
11210 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_replace_as_cmd);
11211 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11212 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11213 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
11214 install_element (BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
11215 install_element (BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
11216 install_element (BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
11217 install_element (BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
11218 install_element (BGP_IPV4L_NODE, &neighbor_remove_private_as_replace_as_cmd);
11219 install_element (BGP_IPV4L_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11220 install_element (BGP_IPV4L_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11221 install_element (BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
11222 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
11223 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
11224 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
11225 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11226 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_replace_as_cmd);
11227 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11228 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11229 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
11230 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
11231 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
11232 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
11233 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
11234 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_replace_as_cmd);
11235 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11236 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11237 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
11238 install_element (BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
11239 install_element (BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
11240 install_element (BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
11241 install_element (BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
11242 install_element (BGP_IPV6L_NODE, &neighbor_remove_private_as_replace_as_cmd);
11243 install_element (BGP_IPV6L_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11244 install_element (BGP_IPV6L_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11245 install_element (BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
11246 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
11247 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
11248 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
11249 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11250 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_replace_as_cmd);
11251 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11252 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11253 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
11254 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
11255 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
11256 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
11257 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11258 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_replace_as_cmd);
11259 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11260 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11261 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
11262
11263 /* "neighbor send-community" commands.*/
11264 install_element (BGP_NODE, &neighbor_send_community_hidden_cmd);
11265 install_element (BGP_NODE, &neighbor_send_community_type_hidden_cmd);
11266 install_element (BGP_NODE, &no_neighbor_send_community_hidden_cmd);
11267 install_element (BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
11268 install_element (BGP_IPV4_NODE, &neighbor_send_community_cmd);
11269 install_element (BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
11270 install_element (BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
11271 install_element (BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
11272 install_element (BGP_IPV4M_NODE, &neighbor_send_community_cmd);
11273 install_element (BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
11274 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
11275 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
11276 install_element (BGP_IPV4L_NODE, &neighbor_send_community_cmd);
11277 install_element (BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
11278 install_element (BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
11279 install_element (BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
11280 install_element (BGP_IPV6_NODE, &neighbor_send_community_cmd);
11281 install_element (BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
11282 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
11283 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
11284 install_element (BGP_IPV6M_NODE, &neighbor_send_community_cmd);
11285 install_element (BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
11286 install_element (BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
11287 install_element (BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
11288 install_element (BGP_IPV6L_NODE, &neighbor_send_community_cmd);
11289 install_element (BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
11290 install_element (BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
11291 install_element (BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
11292 install_element (BGP_VPNV4_NODE, &neighbor_send_community_cmd);
11293 install_element (BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
11294 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
11295 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
11296 install_element (BGP_VPNV6_NODE, &neighbor_send_community_cmd);
11297 install_element (BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
11298 install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
11299 install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
11300
11301 /* "neighbor route-reflector" commands.*/
11302 install_element (BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
11303 install_element (BGP_NODE, &no_neighbor_route_reflector_client_hidden_cmd);
11304 install_element (BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
11305 install_element (BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
11306 install_element (BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
11307 install_element (BGP_IPV4M_NODE, &no_neighbor_route_reflector_client_cmd);
11308 install_element (BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
11309 install_element (BGP_IPV4L_NODE, &no_neighbor_route_reflector_client_cmd);
11310 install_element (BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
11311 install_element (BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
11312 install_element (BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
11313 install_element (BGP_IPV6M_NODE, &no_neighbor_route_reflector_client_cmd);
11314 install_element (BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
11315 install_element (BGP_IPV6L_NODE, &no_neighbor_route_reflector_client_cmd);
11316 install_element (BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
11317 install_element (BGP_VPNV4_NODE, &no_neighbor_route_reflector_client_cmd);
11318 install_element (BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
11319 install_element (BGP_VPNV6_NODE, &no_neighbor_route_reflector_client_cmd);
11320 install_element (BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
11321 install_element (BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
11322
11323 /* "neighbor route-server" commands.*/
11324 install_element (BGP_NODE, &neighbor_route_server_client_hidden_cmd);
11325 install_element (BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
11326 install_element (BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
11327 install_element (BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
11328 install_element (BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
11329 install_element (BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
11330 install_element (BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
11331 install_element (BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
11332 install_element (BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
11333 install_element (BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
11334 install_element (BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
11335 install_element (BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
11336 install_element (BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
11337 install_element (BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
11338 install_element (BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
11339 install_element (BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
11340 install_element (BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
11341 install_element (BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
11342
11343 /* "neighbor addpath-tx-all-paths" commands.*/
11344 install_element (BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
11345 install_element (BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
11346 install_element (BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11347 install_element (BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11348 install_element (BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11349 install_element (BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11350 install_element (BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11351 install_element (BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11352 install_element (BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11353 install_element (BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11354 install_element (BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11355 install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11356 install_element (BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11357 install_element (BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11358 install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11359 install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11360 install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11361 install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11362
11363 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
11364 install_element (BGP_NODE, &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11365 install_element (BGP_NODE, &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11366 install_element (BGP_IPV4_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11367 install_element (BGP_IPV4_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11368 install_element (BGP_IPV4M_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11369 install_element (BGP_IPV4M_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11370 install_element (BGP_IPV4L_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11371 install_element (BGP_IPV4L_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11372 install_element (BGP_IPV6_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11373 install_element (BGP_IPV6_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11374 install_element (BGP_IPV6M_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11375 install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11376 install_element (BGP_IPV6L_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11377 install_element (BGP_IPV6L_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11378 install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11379 install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11380 install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11381 install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11382
11383 /* "neighbor passive" commands. */
11384 install_element (BGP_NODE, &neighbor_passive_cmd);
11385 install_element (BGP_NODE, &no_neighbor_passive_cmd);
11386
11387
11388 /* "neighbor shutdown" commands. */
11389 install_element (BGP_NODE, &neighbor_shutdown_cmd);
11390 install_element (BGP_NODE, &no_neighbor_shutdown_cmd);
11391 install_element (BGP_NODE, &neighbor_shutdown_msg_cmd);
11392 install_element (BGP_NODE, &no_neighbor_shutdown_msg_cmd);
11393
11394 /* "neighbor capability extended-nexthop" commands.*/
11395 install_element (BGP_NODE, &neighbor_capability_enhe_cmd);
11396 install_element (BGP_NODE, &no_neighbor_capability_enhe_cmd);
11397
11398 /* "neighbor capability orf prefix-list" commands.*/
11399 install_element (BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
11400 install_element (BGP_NODE, &no_neighbor_capability_orf_prefix_hidden_cmd);
11401 install_element (BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
11402 install_element (BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
11403 install_element (BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
11404 install_element (BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
11405 install_element (BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
11406 install_element (BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
11407 install_element (BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
11408 install_element (BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
11409 install_element (BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
11410 install_element (BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
11411 install_element (BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
11412 install_element (BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
11413
11414 /* "neighbor capability dynamic" commands.*/
11415 install_element (BGP_NODE, &neighbor_capability_dynamic_cmd);
11416 install_element (BGP_NODE, &no_neighbor_capability_dynamic_cmd);
11417
11418 /* "neighbor dont-capability-negotiate" commands. */
11419 install_element (BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
11420 install_element (BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
11421
11422 /* "neighbor ebgp-multihop" commands. */
11423 install_element (BGP_NODE, &neighbor_ebgp_multihop_cmd);
11424 install_element (BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
11425 install_element (BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
11426
11427 /* "neighbor disable-connected-check" commands. */
11428 install_element (BGP_NODE, &neighbor_disable_connected_check_cmd);
11429 install_element (BGP_NODE, &no_neighbor_disable_connected_check_cmd);
11430
11431 /* "neighbor description" commands. */
11432 install_element (BGP_NODE, &neighbor_description_cmd);
11433 install_element (BGP_NODE, &no_neighbor_description_cmd);
11434
11435 /* "neighbor update-source" commands. "*/
11436 install_element (BGP_NODE, &neighbor_update_source_cmd);
11437 install_element (BGP_NODE, &no_neighbor_update_source_cmd);
11438
11439 /* "neighbor default-originate" commands. */
11440 install_element (BGP_NODE, &neighbor_default_originate_hidden_cmd);
11441 install_element (BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
11442 install_element (BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
11443 install_element (BGP_IPV4_NODE, &neighbor_default_originate_cmd);
11444 install_element (BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
11445 install_element (BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
11446 install_element (BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
11447 install_element (BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
11448 install_element (BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
11449 install_element (BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
11450 install_element (BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
11451 install_element (BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
11452 install_element (BGP_IPV6_NODE, &neighbor_default_originate_cmd);
11453 install_element (BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
11454 install_element (BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
11455 install_element (BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
11456 install_element (BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
11457 install_element (BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
11458 install_element (BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
11459 install_element (BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
11460 install_element (BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
11461
11462 /* "neighbor port" commands. */
11463 install_element (BGP_NODE, &neighbor_port_cmd);
11464 install_element (BGP_NODE, &no_neighbor_port_cmd);
11465
11466 /* "neighbor weight" commands. */
11467 install_element (BGP_NODE, &neighbor_weight_hidden_cmd);
11468 install_element (BGP_NODE, &no_neighbor_weight_hidden_cmd);
11469
11470 install_element (BGP_IPV4_NODE, &neighbor_weight_cmd);
11471 install_element (BGP_IPV4_NODE, &no_neighbor_weight_cmd);
11472 install_element (BGP_IPV4M_NODE, &neighbor_weight_cmd);
11473 install_element (BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
11474 install_element (BGP_IPV4L_NODE, &neighbor_weight_cmd);
11475 install_element (BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
11476 install_element (BGP_IPV6_NODE, &neighbor_weight_cmd);
11477 install_element (BGP_IPV6_NODE, &no_neighbor_weight_cmd);
11478 install_element (BGP_IPV6M_NODE, &neighbor_weight_cmd);
11479 install_element (BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
11480 install_element (BGP_IPV6L_NODE, &neighbor_weight_cmd);
11481 install_element (BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
11482 install_element (BGP_VPNV4_NODE, &neighbor_weight_cmd);
11483 install_element (BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
11484 install_element (BGP_VPNV6_NODE, &neighbor_weight_cmd);
11485 install_element (BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
11486
11487 /* "neighbor override-capability" commands. */
11488 install_element (BGP_NODE, &neighbor_override_capability_cmd);
11489 install_element (BGP_NODE, &no_neighbor_override_capability_cmd);
11490
11491 /* "neighbor strict-capability-match" commands. */
11492 install_element (BGP_NODE, &neighbor_strict_capability_cmd);
11493 install_element (BGP_NODE, &no_neighbor_strict_capability_cmd);
11494
11495 /* "neighbor timers" commands. */
11496 install_element (BGP_NODE, &neighbor_timers_cmd);
11497 install_element (BGP_NODE, &no_neighbor_timers_cmd);
11498
11499 /* "neighbor timers connect" commands. */
11500 install_element (BGP_NODE, &neighbor_timers_connect_cmd);
11501 install_element (BGP_NODE, &no_neighbor_timers_connect_cmd);
11502
11503 /* "neighbor advertisement-interval" commands. */
11504 install_element (BGP_NODE, &neighbor_advertise_interval_cmd);
11505 install_element (BGP_NODE, &no_neighbor_advertise_interval_cmd);
11506
11507 /* "neighbor interface" commands. */
11508 install_element (BGP_NODE, &neighbor_interface_cmd);
11509 install_element (BGP_NODE, &no_neighbor_interface_cmd);
11510
11511 /* "neighbor distribute" commands. */
11512 install_element (BGP_NODE, &neighbor_distribute_list_hidden_cmd);
11513 install_element (BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
11514 install_element (BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
11515 install_element (BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
11516 install_element (BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
11517 install_element (BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
11518 install_element (BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
11519 install_element (BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
11520 install_element (BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
11521 install_element (BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
11522 install_element (BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
11523 install_element (BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
11524 install_element (BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
11525 install_element (BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
11526 install_element (BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
11527 install_element (BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
11528 install_element (BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
11529 install_element (BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
11530
11531 /* "neighbor prefix-list" commands. */
11532 install_element (BGP_NODE, &neighbor_prefix_list_hidden_cmd);
11533 install_element (BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
11534 install_element (BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
11535 install_element (BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
11536 install_element (BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
11537 install_element (BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
11538 install_element (BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
11539 install_element (BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
11540 install_element (BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
11541 install_element (BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
11542 install_element (BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
11543 install_element (BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
11544 install_element (BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
11545 install_element (BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
11546 install_element (BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
11547 install_element (BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
11548 install_element (BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
11549 install_element (BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
11550
11551 /* "neighbor filter-list" commands. */
11552 install_element (BGP_NODE, &neighbor_filter_list_hidden_cmd);
11553 install_element (BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
11554 install_element (BGP_IPV4_NODE, &neighbor_filter_list_cmd);
11555 install_element (BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
11556 install_element (BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
11557 install_element (BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
11558 install_element (BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
11559 install_element (BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
11560 install_element (BGP_IPV6_NODE, &neighbor_filter_list_cmd);
11561 install_element (BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
11562 install_element (BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
11563 install_element (BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
11564 install_element (BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
11565 install_element (BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
11566 install_element (BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
11567 install_element (BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
11568 install_element (BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
11569 install_element (BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
11570
11571 /* "neighbor route-map" commands. */
11572 install_element (BGP_NODE, &neighbor_route_map_hidden_cmd);
11573 install_element (BGP_NODE, &no_neighbor_route_map_hidden_cmd);
11574 install_element (BGP_IPV4_NODE, &neighbor_route_map_cmd);
11575 install_element (BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
11576 install_element (BGP_IPV4M_NODE, &neighbor_route_map_cmd);
11577 install_element (BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
11578 install_element (BGP_IPV4L_NODE, &neighbor_route_map_cmd);
11579 install_element (BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
11580 install_element (BGP_IPV6_NODE, &neighbor_route_map_cmd);
11581 install_element (BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
11582 install_element (BGP_IPV6M_NODE, &neighbor_route_map_cmd);
11583 install_element (BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
11584 install_element (BGP_IPV6L_NODE, &neighbor_route_map_cmd);
11585 install_element (BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
11586 install_element (BGP_VPNV4_NODE, &neighbor_route_map_cmd);
11587 install_element (BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
11588 install_element (BGP_VPNV6_NODE, &neighbor_route_map_cmd);
11589 install_element (BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
11590
11591 /* "neighbor unsuppress-map" commands. */
11592 install_element (BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
11593 install_element (BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
11594 install_element (BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
11595 install_element (BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
11596 install_element (BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
11597 install_element (BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
11598 install_element (BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
11599 install_element (BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
11600 install_element (BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
11601 install_element (BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
11602 install_element (BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
11603 install_element (BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
11604 install_element (BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
11605 install_element (BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
11606 install_element (BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
11607 install_element (BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
11608 install_element (BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
11609 install_element (BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
11610
11611 /* "neighbor maximum-prefix" commands. */
11612 install_element (BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
11613 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_hidden_cmd);
11614 install_element (BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
11615 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
11616 install_element (BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
11617 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
11618 install_element (BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
11619 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
11620 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
11621 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
11622 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11623 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
11624 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11625 install_element (BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
11626 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
11627 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
11628 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
11629 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11630 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
11631 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11632 install_element (BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
11633 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
11634 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
11635 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
11636 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11637 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
11638 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11639 install_element (BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
11640 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
11641 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
11642 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
11643 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11644 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
11645 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11646 install_element (BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
11647 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
11648 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
11649 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
11650 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11651 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
11652 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11653 install_element (BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
11654 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
11655 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
11656 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
11657 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11658 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
11659 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11660 install_element (BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
11661 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
11662 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
11663 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
11664 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11665 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
11666 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11667 install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
11668 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
11669 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
11670 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
11671 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11672 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
11673 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11674 install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
11675
11676 /* "neighbor allowas-in" */
11677 install_element (BGP_NODE, &neighbor_allowas_in_hidden_cmd);
11678 install_element (BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
11679 install_element (BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
11680 install_element (BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
11681 install_element (BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
11682 install_element (BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
11683 install_element (BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
11684 install_element (BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
11685 install_element (BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
11686 install_element (BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
11687 install_element (BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
11688 install_element (BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
11689 install_element (BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
11690 install_element (BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
11691 install_element (BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
11692 install_element (BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
11693 install_element (BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
11694 install_element (BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
11695 install_element (BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
11696 install_element (BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
11697
11698 /* address-family commands. */
11699 install_element (BGP_NODE, &address_family_ipv4_safi_cmd);
11700 install_element (BGP_NODE, &address_family_ipv6_safi_cmd);
11701 #ifdef KEEP_OLD_VPN_COMMANDS
11702 install_element (BGP_NODE, &address_family_vpnv4_cmd);
11703 install_element (BGP_NODE, &address_family_vpnv6_cmd);
11704 #endif /* KEEP_OLD_VPN_COMMANDS */
11705
11706 install_element (BGP_NODE, &address_family_evpn_cmd);
11707
11708 /* "exit-address-family" command. */
11709 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
11710 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
11711 install_element (BGP_IPV4L_NODE, &exit_address_family_cmd);
11712 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
11713 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
11714 install_element (BGP_IPV6L_NODE, &exit_address_family_cmd);
11715 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
11716 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
11717 install_element (BGP_EVPN_NODE, &exit_address_family_cmd);
11718
11719 /* "clear ip bgp commands" */
11720 install_element (ENABLE_NODE, &clear_ip_bgp_all_cmd);
11721
11722 /* clear ip bgp prefix */
11723 install_element (ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
11724 install_element (ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
11725 install_element (ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
11726
11727 /* "show [ip] bgp summary" commands. */
11728 install_element (VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
11729 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
11730 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
11731 install_element (VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
11732 install_element (VIEW_NODE, &show_bgp_updgrps_adj_cmd);
11733 install_element (VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
11734 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
11735 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
11736 install_element (VIEW_NODE, &show_bgp_updgrps_stats_cmd);
11737 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
11738 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
11739 install_element (VIEW_NODE, &show_ip_bgp_summary_cmd);
11740 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
11741 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
11742 install_element (VIEW_NODE, &show_ip_bgp_updgrps_cmd);
11743
11744 /* "show [ip] bgp neighbors" commands. */
11745 install_element (VIEW_NODE, &show_ip_bgp_neighbors_cmd);
11746
11747 /* "show [ip] bgp peer-group" commands. */
11748 install_element (VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
11749
11750 /* "show [ip] bgp paths" commands. */
11751 install_element (VIEW_NODE, &show_ip_bgp_paths_cmd);
11752
11753 /* "show [ip] bgp community" commands. */
11754 install_element (VIEW_NODE, &show_ip_bgp_community_info_cmd);
11755
11756 /* "show ip bgp large-community" commands. */
11757 install_element (VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
11758 /* "show [ip] bgp attribute-info" commands. */
11759 install_element (VIEW_NODE, &show_ip_bgp_attr_info_cmd);
11760
11761 /* "redistribute" commands. */
11762 install_element (BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
11763 install_element (BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
11764 install_element (BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
11765 install_element (BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
11766 install_element (BGP_NODE, &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
11767 install_element (BGP_NODE, &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
11768 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
11769 install_element (BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
11770 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
11771 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
11772 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
11773 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
11774 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
11775 install_element (BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
11776 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
11777 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
11778 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
11779 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
11780 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
11781 install_element (BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
11782 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
11783 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
11784 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
11785 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
11786 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
11787 install_element (BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
11788 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
11789 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
11790 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
11791 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
11792
11793 /* ttl_security commands */
11794 install_element (BGP_NODE, &neighbor_ttl_security_cmd);
11795 install_element (BGP_NODE, &no_neighbor_ttl_security_cmd);
11796
11797 /* "show [ip] bgp memory" commands. */
11798 install_element (VIEW_NODE, &show_bgp_memory_cmd);
11799
11800 /* "show [ip] bgp views" commands. */
11801 install_element (VIEW_NODE, &show_bgp_views_cmd);
11802
11803 /* "show [ip] bgp vrfs" commands. */
11804 install_element (VIEW_NODE, &show_bgp_vrfs_cmd);
11805
11806 /* Community-list. */
11807 community_list_vty ();
11808 }
11809
11810 #include "memory.h"
11811 #include "bgp_regex.h"
11812 #include "bgp_clist.h"
11813 #include "bgp_ecommunity.h"
11814
11815 /* VTY functions. */
11816
11817 /* Direction value to string conversion. */
11818 static const char *
11819 community_direct_str (int direct)
11820 {
11821 switch (direct)
11822 {
11823 case COMMUNITY_DENY:
11824 return "deny";
11825 case COMMUNITY_PERMIT:
11826 return "permit";
11827 default:
11828 return "unknown";
11829 }
11830 }
11831
11832 /* Display error string. */
11833 static void
11834 community_list_perror (struct vty *vty, int ret)
11835 {
11836 switch (ret)
11837 {
11838 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
11839 vty_out (vty, "%% Can't find community-list%s", VTYNL);
11840 break;
11841 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
11842 vty_out (vty, "%% Malformed community-list value%s", VTYNL);
11843 break;
11844 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
11845 vty_out (vty, "%% Community name conflict, previously defined as standard community%s", VTYNL);
11846 break;
11847 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
11848 vty_out (vty, "%% Community name conflict, previously defined as expanded community%s", VTYNL);
11849 break;
11850 }
11851 }
11852
11853 /* "community-list" keyword help string. */
11854 #define COMMUNITY_LIST_STR "Add a community list entry\n"
11855
11856
11857 /* ip community-list standard */
11858 DEFUN (ip_community_list_standard,
11859 ip_community_list_standard_cmd,
11860 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
11861 IP_STR
11862 COMMUNITY_LIST_STR
11863 "Community list number (standard)\n"
11864 "Add an standard community-list entry\n"
11865 "Community list name\n"
11866 "Specify community to reject\n"
11867 "Specify community to accept\n"
11868 COMMUNITY_VAL_STR)
11869 {
11870 char *cl_name_or_number = NULL;
11871 int direct = 0;
11872 int style = COMMUNITY_LIST_STANDARD;
11873
11874 int idx = 0;
11875 argv_find (argv, argc, "(1-99)", &idx);
11876 argv_find (argv, argc, "WORD", &idx);
11877 cl_name_or_number = argv[idx]->arg;
11878 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11879 argv_find (argv, argc, "AA:NN", &idx);
11880 char *str = argv_concat (argv, argc, idx);
11881
11882 int ret = community_list_set (bgp_clist, cl_name_or_number, str, direct, style);
11883
11884 XFREE (MTYPE_TMP, str);
11885
11886 if (ret < 0)
11887 {
11888 /* Display error string. */
11889 community_list_perror (vty, ret);
11890 return CMD_WARNING_CONFIG_FAILED;
11891 }
11892
11893 return CMD_SUCCESS;
11894 }
11895
11896 DEFUN (no_ip_community_list_standard_all,
11897 no_ip_community_list_standard_all_cmd,
11898 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
11899 NO_STR
11900 IP_STR
11901 COMMUNITY_LIST_STR
11902 "Community list number (standard)\n"
11903 "Add an standard community-list entry\n"
11904 "Community list name\n"
11905 "Specify community to reject\n"
11906 "Specify community to accept\n"
11907 COMMUNITY_VAL_STR)
11908 {
11909 int delete_all = 0;
11910
11911 char *cl_name_or_number = NULL;
11912 int direct = 0;
11913 int style = COMMUNITY_LIST_STANDARD;
11914
11915 int idx = 0;
11916 argv_find (argv, argc, "(1-99)", &idx);
11917 argv_find (argv, argc, "WORD", &idx);
11918 cl_name_or_number = argv[idx]->arg;
11919 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11920 argv_find (argv, argc, "AA:NN", &idx);
11921 char *str = argv_concat (argv, argc, idx);
11922
11923 int ret = community_list_unset (bgp_clist, cl_name_or_number, str, direct, style, delete_all);
11924
11925 XFREE (MTYPE_TMP, str);
11926
11927 if (ret < 0)
11928 {
11929 community_list_perror (vty, ret);
11930 return CMD_WARNING_CONFIG_FAILED;
11931 }
11932
11933 return CMD_SUCCESS;
11934 }
11935
11936 /* ip community-list expanded */
11937 DEFUN (ip_community_list_expanded_all,
11938 ip_community_list_expanded_all_cmd,
11939 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
11940 IP_STR
11941 COMMUNITY_LIST_STR
11942 "Community list number (expanded)\n"
11943 "Add an expanded community-list entry\n"
11944 "Community list name\n"
11945 "Specify community to reject\n"
11946 "Specify community to accept\n"
11947 COMMUNITY_VAL_STR)
11948 {
11949 char *cl_name_or_number = NULL;
11950 int direct = 0;
11951 int style = COMMUNITY_LIST_EXPANDED;
11952
11953 int idx = 0;
11954 argv_find (argv, argc, "(100-500)", &idx);
11955 argv_find (argv, argc, "WORD", &idx);
11956 cl_name_or_number = argv[idx]->arg;
11957 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11958 argv_find (argv, argc, "AA:NN", &idx);
11959 char *str = argv_concat (argv, argc, idx);
11960
11961 int ret = community_list_set (bgp_clist, cl_name_or_number, str, direct, style);
11962
11963 XFREE (MTYPE_TMP, str);
11964
11965 if (ret < 0)
11966 {
11967 /* Display error string. */
11968 community_list_perror (vty, ret);
11969 return CMD_WARNING_CONFIG_FAILED;
11970 }
11971
11972 return CMD_SUCCESS;
11973 }
11974
11975 DEFUN (no_ip_community_list_expanded_all,
11976 no_ip_community_list_expanded_all_cmd,
11977 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
11978 NO_STR
11979 IP_STR
11980 COMMUNITY_LIST_STR
11981 "Community list number (expanded)\n"
11982 "Add an expanded community-list entry\n"
11983 "Community list name\n"
11984 "Specify community to reject\n"
11985 "Specify community to accept\n"
11986 COMMUNITY_VAL_STR)
11987 {
11988 int delete_all = 0;
11989
11990 char *cl_name_or_number = NULL;
11991 int direct = 0;
11992 int style = COMMUNITY_LIST_EXPANDED;
11993
11994 int idx = 0;
11995 argv_find (argv, argc, "(100-500)", &idx);
11996 argv_find (argv, argc, "WORD", &idx);
11997 cl_name_or_number = argv[idx]->arg;
11998 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11999 argv_find (argv, argc, "AA:NN", &idx);
12000 char *str = argv_concat (argv, argc, idx);
12001
12002 int ret = community_list_unset (bgp_clist, cl_name_or_number, str, direct, style, delete_all);
12003
12004 XFREE (MTYPE_TMP, str);
12005
12006 if (ret < 0)
12007 {
12008 community_list_perror (vty, ret);
12009 return CMD_WARNING_CONFIG_FAILED;
12010 }
12011
12012 return CMD_SUCCESS;
12013 }
12014
12015 static void
12016 community_list_show (struct vty *vty, struct community_list *list)
12017 {
12018 struct community_entry *entry;
12019
12020 for (entry = list->head; entry; entry = entry->next)
12021 {
12022 if (entry == list->head)
12023 {
12024 if (all_digit (list->name))
12025 vty_out (vty, "Community %s list %s%s",
12026 entry->style == COMMUNITY_LIST_STANDARD ?
12027 "standard" : "(expanded) access",
12028 list->name, VTYNL);
12029 else
12030 vty_out (vty, "Named Community %s list %s%s",
12031 entry->style == COMMUNITY_LIST_STANDARD ?
12032 "standard" : "expanded",
12033 list->name, VTYNL);
12034 }
12035 if (entry->any)
12036 vty_out (vty, " %s%s",
12037 community_direct_str (entry->direct), VTYNL);
12038 else
12039 vty_out (vty, " %s %s%s",
12040 community_direct_str (entry->direct),
12041 entry->style == COMMUNITY_LIST_STANDARD
12042 ? community_str (entry->u.com) : entry->config,
12043 VTYNL);
12044 }
12045 }
12046
12047 DEFUN (show_ip_community_list,
12048 show_ip_community_list_cmd,
12049 "show ip community-list",
12050 SHOW_STR
12051 IP_STR
12052 "List community-list\n")
12053 {
12054 struct community_list *list;
12055 struct community_list_master *cm;
12056
12057 cm = community_list_master_lookup (bgp_clist, COMMUNITY_LIST_MASTER);
12058 if (! cm)
12059 return CMD_SUCCESS;
12060
12061 for (list = cm->num.head; list; list = list->next)
12062 community_list_show (vty, list);
12063
12064 for (list = cm->str.head; list; list = list->next)
12065 community_list_show (vty, list);
12066
12067 return CMD_SUCCESS;
12068 }
12069
12070 DEFUN (show_ip_community_list_arg,
12071 show_ip_community_list_arg_cmd,
12072 "show ip community-list <(1-500)|WORD>",
12073 SHOW_STR
12074 IP_STR
12075 "List community-list\n"
12076 "Community-list number\n"
12077 "Community-list name\n")
12078 {
12079 int idx_comm_list = 3;
12080 struct community_list *list;
12081
12082 list = community_list_lookup (bgp_clist, argv[idx_comm_list]->arg, COMMUNITY_LIST_MASTER);
12083 if (! list)
12084 {
12085 vty_out (vty, "%% Can't find community-list%s", VTYNL);
12086 return CMD_WARNING;
12087 }
12088
12089 community_list_show (vty, list);
12090
12091 return CMD_SUCCESS;
12092 }
12093
12094 /*
12095 * Large Community code.
12096 */
12097 static int
12098 lcommunity_list_set_vty (struct vty *vty, int argc, struct cmd_token **argv,
12099 int style, int reject_all_digit_name)
12100 {
12101 int ret;
12102 int direct;
12103 char *str;
12104 int idx = 0;
12105 char *cl_name;
12106
12107 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12108
12109 /* All digit name check. */
12110 idx = 0;
12111 argv_find (argv, argc, "WORD", &idx);
12112 argv_find (argv, argc, "(1-99)", &idx);
12113 argv_find (argv, argc, "(100-500)", &idx);
12114 cl_name = argv[idx]->arg;
12115 if (reject_all_digit_name && all_digit (cl_name))
12116 {
12117 vty_out (vty, "%% Community name cannot have all digits%s", VTYNL);
12118 return CMD_WARNING_CONFIG_FAILED;
12119 }
12120
12121 idx = 0;
12122 argv_find (argv, argc, "AA:BB:CC", &idx);
12123 argv_find (argv, argc, "LINE", &idx);
12124 /* Concat community string argument. */
12125 if (idx)
12126 str = argv_concat (argv, argc, idx);
12127 else
12128 str = NULL;
12129
12130 ret = lcommunity_list_set (bgp_clist, cl_name, str, direct, style);
12131
12132 /* Free temporary community list string allocated by
12133 argv_concat(). */
12134 if (str)
12135 XFREE (MTYPE_TMP, str);
12136
12137 if (ret < 0)
12138 {
12139 community_list_perror (vty, ret);
12140 return CMD_WARNING_CONFIG_FAILED;
12141 }
12142 return CMD_SUCCESS;
12143 }
12144
12145 static int
12146 lcommunity_list_unset_vty (struct vty *vty, int argc, struct cmd_token **argv,
12147 int style)
12148 {
12149 int ret;
12150 int direct = 0;
12151 char *str = NULL;
12152 int idx = 0;
12153
12154 argv_find (argv, argc, "permit", &idx);
12155 argv_find (argv, argc, "deny", &idx);
12156
12157 if (idx)
12158 {
12159 /* Check the list direct. */
12160 if (strncmp (argv[idx]->arg, "p", 1) == 0)
12161 direct = COMMUNITY_PERMIT;
12162 else
12163 direct = COMMUNITY_DENY;
12164
12165 idx = 0;
12166 argv_find (argv, argc, "LINE", &idx);
12167 argv_find (argv, argc, "AA:AA:NN", &idx);
12168 /* Concat community string argument. */
12169 str = argv_concat (argv, argc, idx);
12170 }
12171
12172 idx = 0;
12173 argv_find (argv, argc, "(1-99)", &idx);
12174 argv_find (argv, argc, "(100-500)", &idx);
12175 argv_find (argv, argc, "WORD", &idx);
12176
12177 /* Unset community list. */
12178 ret = lcommunity_list_unset (bgp_clist, argv[idx]->arg, str, direct, style);
12179
12180 /* Free temporary community list string allocated by
12181 argv_concat(). */
12182 if (str)
12183 XFREE (MTYPE_TMP, str);
12184
12185 if (ret < 0)
12186 {
12187 community_list_perror (vty, ret);
12188 return CMD_WARNING_CONFIG_FAILED;
12189 }
12190
12191 return CMD_SUCCESS;
12192 }
12193
12194 /* "large-community-list" keyword help string. */
12195 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
12196 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
12197
12198 DEFUN (ip_lcommunity_list_standard,
12199 ip_lcommunity_list_standard_cmd,
12200 "ip large-community-list (1-99) <deny|permit>",
12201 IP_STR
12202 LCOMMUNITY_LIST_STR
12203 "Large Community list number (standard)\n"
12204 "Specify large community to reject\n"
12205 "Specify large community to accept\n")
12206 {
12207 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 0);
12208 }
12209
12210 DEFUN (ip_lcommunity_list_standard1,
12211 ip_lcommunity_list_standard1_cmd,
12212 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
12213 IP_STR
12214 LCOMMUNITY_LIST_STR
12215 "Large Community list number (standard)\n"
12216 "Specify large community to reject\n"
12217 "Specify large community to accept\n"
12218 LCOMMUNITY_VAL_STR)
12219 {
12220 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 0);
12221 }
12222
12223 DEFUN (ip_lcommunity_list_expanded,
12224 ip_lcommunity_list_expanded_cmd,
12225 "ip large-community-list (100-500) <deny|permit> LINE...",
12226 IP_STR
12227 LCOMMUNITY_LIST_STR
12228 "Large Community list number (expanded)\n"
12229 "Specify large community to reject\n"
12230 "Specify large community to accept\n"
12231 "An ordered list as a regular-expression\n")
12232 {
12233 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED, 0);
12234 }
12235
12236 DEFUN (ip_lcommunity_list_name_standard,
12237 ip_lcommunity_list_name_standard_cmd,
12238 "ip large-community-list standard WORD <deny|permit>",
12239 IP_STR
12240 LCOMMUNITY_LIST_STR
12241 "Specify standard large-community-list\n"
12242 "Large Community list name\n"
12243 "Specify large community to reject\n"
12244 "Specify large community to accept\n")
12245 {
12246 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 1);
12247 }
12248
12249 DEFUN (ip_lcommunity_list_name_standard1,
12250 ip_lcommunity_list_name_standard1_cmd,
12251 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
12252 IP_STR
12253 LCOMMUNITY_LIST_STR
12254 "Specify standard large-community-list\n"
12255 "Large Community list name\n"
12256 "Specify large community to reject\n"
12257 "Specify large community to accept\n"
12258 LCOMMUNITY_VAL_STR)
12259 {
12260 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 1);
12261 }
12262
12263 DEFUN (ip_lcommunity_list_name_expanded,
12264 ip_lcommunity_list_name_expanded_cmd,
12265 "ip large-community-list expanded WORD <deny|permit> LINE...",
12266 IP_STR
12267 LCOMMUNITY_LIST_STR
12268 "Specify expanded large-community-list\n"
12269 "Large Community list name\n"
12270 "Specify large community to reject\n"
12271 "Specify large community to accept\n"
12272 "An ordered list as a regular-expression\n")
12273 {
12274 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED, 1);
12275 }
12276
12277 DEFUN (no_ip_lcommunity_list_standard_all,
12278 no_ip_lcommunity_list_standard_all_cmd,
12279 "no ip large-community-list <(1-99)|(100-500)|WORD>",
12280 NO_STR
12281 IP_STR
12282 LCOMMUNITY_LIST_STR
12283 "Large Community list number (standard)\n"
12284 "Large Community list number (expanded)\n"
12285 "Large Community list name\n")
12286 {
12287 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD);
12288 }
12289
12290 DEFUN (no_ip_lcommunity_list_name_expanded_all,
12291 no_ip_lcommunity_list_name_expanded_all_cmd,
12292 "no ip large-community-list expanded WORD",
12293 NO_STR
12294 IP_STR
12295 LCOMMUNITY_LIST_STR
12296 "Specify expanded large-community-list\n"
12297 "Large Community list name\n")
12298 {
12299 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED);
12300 }
12301
12302 DEFUN (no_ip_lcommunity_list_standard,
12303 no_ip_lcommunity_list_standard_cmd,
12304 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
12305 NO_STR
12306 IP_STR
12307 LCOMMUNITY_LIST_STR
12308 "Large Community list number (standard)\n"
12309 "Specify large community to reject\n"
12310 "Specify large community to accept\n"
12311 LCOMMUNITY_VAL_STR)
12312 {
12313 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD);
12314 }
12315
12316 DEFUN (no_ip_lcommunity_list_expanded,
12317 no_ip_lcommunity_list_expanded_cmd,
12318 "no ip large-community-list (100-500) <deny|permit> LINE...",
12319 NO_STR
12320 IP_STR
12321 LCOMMUNITY_LIST_STR
12322 "Large Community list number (expanded)\n"
12323 "Specify large community to reject\n"
12324 "Specify large community to accept\n"
12325 "An ordered list as a regular-expression\n")
12326 {
12327 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED);
12328 }
12329
12330 DEFUN (no_ip_lcommunity_list_name_standard,
12331 no_ip_lcommunity_list_name_standard_cmd,
12332 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
12333 NO_STR
12334 IP_STR
12335 LCOMMUNITY_LIST_STR
12336 "Specify standard large-community-list\n"
12337 "Large Community list name\n"
12338 "Specify large community to reject\n"
12339 "Specify large community to accept\n"
12340 LCOMMUNITY_VAL_STR)
12341 {
12342 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD);
12343 }
12344
12345 DEFUN (no_ip_lcommunity_list_name_expanded,
12346 no_ip_lcommunity_list_name_expanded_cmd,
12347 "no ip large-community-list expanded WORD <deny|permit> LINE...",
12348 NO_STR
12349 IP_STR
12350 LCOMMUNITY_LIST_STR
12351 "Specify expanded large-community-list\n"
12352 "Large community list name\n"
12353 "Specify large community to reject\n"
12354 "Specify large community to accept\n"
12355 "An ordered list as a regular-expression\n")
12356 {
12357 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED);
12358 }
12359
12360 static void
12361 lcommunity_list_show (struct vty *vty, struct community_list *list)
12362 {
12363 struct community_entry *entry;
12364
12365 for (entry = list->head; entry; entry = entry->next)
12366 {
12367 if (entry == list->head)
12368 {
12369 if (all_digit (list->name))
12370 vty_out (vty, "Large community %s list %s%s",
12371 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12372 "standard" : "(expanded) access",
12373 list->name, VTYNL);
12374 else
12375 vty_out (vty, "Named large community %s list %s%s",
12376 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12377 "standard" : "expanded",
12378 list->name, VTYNL);
12379 }
12380 if (entry->any)
12381 vty_out (vty, " %s%s",
12382 community_direct_str (entry->direct), VTYNL);
12383 else
12384 vty_out (vty, " %s %s%s",
12385 community_direct_str (entry->direct),
12386 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12387 entry->u.ecom->str : entry->config,
12388 VTYNL);
12389 }
12390 }
12391
12392 DEFUN (show_ip_lcommunity_list,
12393 show_ip_lcommunity_list_cmd,
12394 "show ip large-community-list",
12395 SHOW_STR
12396 IP_STR
12397 "List large-community list\n")
12398 {
12399 struct community_list *list;
12400 struct community_list_master *cm;
12401
12402 cm = community_list_master_lookup (bgp_clist, LARGE_COMMUNITY_LIST_MASTER);
12403 if (! cm)
12404 return CMD_SUCCESS;
12405
12406 for (list = cm->num.head; list; list = list->next)
12407 lcommunity_list_show (vty, list);
12408
12409 for (list = cm->str.head; list; list = list->next)
12410 lcommunity_list_show (vty, list);
12411
12412 return CMD_SUCCESS;
12413 }
12414
12415 DEFUN (show_ip_lcommunity_list_arg,
12416 show_ip_lcommunity_list_arg_cmd,
12417 "show ip large-community-list <(1-500)|WORD>",
12418 SHOW_STR
12419 IP_STR
12420 "List large-community list\n"
12421 "large-community-list number\n"
12422 "large-community-list name\n")
12423 {
12424 struct community_list *list;
12425
12426 list = community_list_lookup (bgp_clist, argv[3]->arg, LARGE_COMMUNITY_LIST_MASTER);
12427 if (! list)
12428 {
12429 vty_out (vty, "%% Can't find extcommunity-list%s", VTYNL);
12430 return CMD_WARNING;
12431 }
12432
12433 lcommunity_list_show (vty, list);
12434
12435 return CMD_SUCCESS;
12436 }
12437
12438 /* "extcommunity-list" keyword help string. */
12439 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
12440 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
12441
12442 DEFUN (ip_extcommunity_list_standard,
12443 ip_extcommunity_list_standard_cmd,
12444 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
12445 IP_STR
12446 EXTCOMMUNITY_LIST_STR
12447 "Extended Community list number (standard)\n"
12448 "Specify standard extcommunity-list\n"
12449 "Community list name\n"
12450 "Specify community to reject\n"
12451 "Specify community to accept\n"
12452 EXTCOMMUNITY_VAL_STR)
12453 {
12454 int style = EXTCOMMUNITY_LIST_STANDARD;
12455 int direct = 0;
12456 char *cl_number_or_name = NULL;
12457
12458 int idx = 0;
12459 argv_find (argv, argc, "(1-99)", &idx);
12460 argv_find (argv, argc, "WORD", &idx);
12461 cl_number_or_name = argv[idx]->arg;
12462 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12463 argv_find (argv, argc, "AA:NN", &idx);
12464 char *str = argv_concat (argv, argc, idx);
12465
12466 int ret = extcommunity_list_set (bgp_clist, cl_number_or_name, str, direct, style);
12467
12468 XFREE (MTYPE_TMP, str);
12469
12470 if (ret < 0)
12471 {
12472 community_list_perror (vty, ret);
12473 return CMD_WARNING_CONFIG_FAILED;
12474 }
12475
12476 return CMD_SUCCESS;
12477 }
12478
12479 DEFUN (ip_extcommunity_list_name_expanded,
12480 ip_extcommunity_list_name_expanded_cmd,
12481 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
12482 IP_STR
12483 EXTCOMMUNITY_LIST_STR
12484 "Extended Community list number (expanded)\n"
12485 "Specify expanded extcommunity-list\n"
12486 "Extended Community list name\n"
12487 "Specify community to reject\n"
12488 "Specify community to accept\n"
12489 "An ordered list as a regular-expression\n")
12490 {
12491 int style = EXTCOMMUNITY_LIST_EXPANDED;
12492 int direct = 0;
12493 char *cl_number_or_name = NULL;
12494
12495 int idx = 0;
12496 argv_find (argv, argc, "(100-500)", &idx);
12497 argv_find (argv, argc, "WORD", &idx);
12498 cl_number_or_name = argv[idx]->arg;
12499 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12500 argv_find (argv, argc, "LINE", &idx);
12501 char *str = argv_concat (argv, argc, idx);
12502
12503 int ret = extcommunity_list_set (bgp_clist, cl_number_or_name, str, direct, style);
12504
12505 XFREE (MTYPE_TMP, str);
12506
12507 if (ret < 0)
12508 {
12509 community_list_perror (vty, ret);
12510 return CMD_WARNING_CONFIG_FAILED;
12511 }
12512
12513 return CMD_SUCCESS;
12514 }
12515
12516 DEFUN (no_ip_extcommunity_list_standard_all,
12517 no_ip_extcommunity_list_standard_all_cmd,
12518 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
12519 NO_STR
12520 IP_STR
12521 EXTCOMMUNITY_LIST_STR
12522 "Extended Community list number (standard)\n"
12523 "Specify standard extcommunity-list\n"
12524 "Community list name\n"
12525 "Specify community to reject\n"
12526 "Specify community to accept\n"
12527 EXTCOMMUNITY_VAL_STR)
12528 {
12529 int deleteall = 0;
12530
12531 int style = EXTCOMMUNITY_LIST_STANDARD;
12532 int direct = 0;
12533 char *cl_number_or_name = NULL;
12534
12535 int idx = 0;
12536 argv_find (argv, argc, "(1-99)", &idx);
12537 argv_find (argv, argc, "WORD", &idx);
12538 cl_number_or_name = argv[idx]->arg;
12539 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12540 argv_find (argv, argc, "AA:NN", &idx);
12541 char *str = argv_concat (argv, argc, idx);
12542
12543 int ret = extcommunity_list_unset (bgp_clist, cl_number_or_name, str, direct, style, deleteall);
12544
12545 XFREE (MTYPE_TMP, str);
12546
12547 if (ret < 0)
12548 {
12549 community_list_perror (vty, ret);
12550 return CMD_WARNING_CONFIG_FAILED;
12551 }
12552
12553 return CMD_SUCCESS;
12554 }
12555
12556 DEFUN (no_ip_extcommunity_list_expanded_all,
12557 no_ip_extcommunity_list_expanded_all_cmd,
12558 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
12559 NO_STR
12560 IP_STR
12561 EXTCOMMUNITY_LIST_STR
12562 "Extended Community list number (expanded)\n"
12563 "Specify expanded extcommunity-list\n"
12564 "Extended Community list name\n"
12565 "Specify community to reject\n"
12566 "Specify community to accept\n"
12567 "An ordered list as a regular-expression\n")
12568 {
12569 int deleteall = 0;
12570
12571 int style = EXTCOMMUNITY_LIST_EXPANDED;
12572 int direct = 0;
12573 char *cl_number_or_name = NULL;
12574
12575 int idx = 0;
12576 argv_find (argv, argc, "(100-500)", &idx);
12577 argv_find (argv, argc, "WORD", &idx);
12578 cl_number_or_name = argv[idx]->arg;
12579 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12580 argv_find (argv, argc, "LINE", &idx);
12581 char *str = argv_concat (argv, argc, idx);
12582
12583 int ret = extcommunity_list_unset (bgp_clist, cl_number_or_name, str, direct, style, deleteall);
12584
12585 XFREE (MTYPE_TMP, str);
12586
12587 if (ret < 0)
12588 {
12589 community_list_perror (vty, ret);
12590 return CMD_WARNING_CONFIG_FAILED;
12591 }
12592
12593 return CMD_SUCCESS;
12594 }
12595
12596 static void
12597 extcommunity_list_show (struct vty *vty, struct community_list *list)
12598 {
12599 struct community_entry *entry;
12600
12601 for (entry = list->head; entry; entry = entry->next)
12602 {
12603 if (entry == list->head)
12604 {
12605 if (all_digit (list->name))
12606 vty_out (vty, "Extended community %s list %s%s",
12607 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12608 "standard" : "(expanded) access",
12609 list->name, VTYNL);
12610 else
12611 vty_out (vty, "Named extended community %s list %s%s",
12612 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12613 "standard" : "expanded",
12614 list->name, VTYNL);
12615 }
12616 if (entry->any)
12617 vty_out (vty, " %s%s",
12618 community_direct_str (entry->direct), VTYNL);
12619 else
12620 vty_out (vty, " %s %s%s",
12621 community_direct_str (entry->direct),
12622 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12623 entry->u.ecom->str : entry->config,
12624 VTYNL);
12625 }
12626 }
12627
12628 DEFUN (show_ip_extcommunity_list,
12629 show_ip_extcommunity_list_cmd,
12630 "show ip extcommunity-list",
12631 SHOW_STR
12632 IP_STR
12633 "List extended-community list\n")
12634 {
12635 struct community_list *list;
12636 struct community_list_master *cm;
12637
12638 cm = community_list_master_lookup (bgp_clist, EXTCOMMUNITY_LIST_MASTER);
12639 if (! cm)
12640 return CMD_SUCCESS;
12641
12642 for (list = cm->num.head; list; list = list->next)
12643 extcommunity_list_show (vty, list);
12644
12645 for (list = cm->str.head; list; list = list->next)
12646 extcommunity_list_show (vty, list);
12647
12648 return CMD_SUCCESS;
12649 }
12650
12651 DEFUN (show_ip_extcommunity_list_arg,
12652 show_ip_extcommunity_list_arg_cmd,
12653 "show ip extcommunity-list <(1-500)|WORD>",
12654 SHOW_STR
12655 IP_STR
12656 "List extended-community list\n"
12657 "Extcommunity-list number\n"
12658 "Extcommunity-list name\n")
12659 {
12660 int idx_comm_list = 3;
12661 struct community_list *list;
12662
12663 list = community_list_lookup (bgp_clist, argv[idx_comm_list]->arg, EXTCOMMUNITY_LIST_MASTER);
12664 if (! list)
12665 {
12666 vty_out (vty, "%% Can't find extcommunity-list%s", VTYNL);
12667 return CMD_WARNING;
12668 }
12669
12670 extcommunity_list_show (vty, list);
12671
12672 return CMD_SUCCESS;
12673 }
12674
12675 /* Return configuration string of community-list entry. */
12676 static const char *
12677 community_list_config_str (struct community_entry *entry)
12678 {
12679 const char *str;
12680
12681 if (entry->any)
12682 str = "";
12683 else
12684 {
12685 if (entry->style == COMMUNITY_LIST_STANDARD)
12686 str = community_str (entry->u.com);
12687 else
12688 str = entry->config;
12689 }
12690 return str;
12691 }
12692
12693 /* Display community-list and extcommunity-list configuration. */
12694 static int
12695 community_list_config_write (struct vty *vty)
12696 {
12697 struct community_list *list;
12698 struct community_entry *entry;
12699 struct community_list_master *cm;
12700 int write = 0;
12701
12702 /* Community-list. */
12703 cm = community_list_master_lookup (bgp_clist, COMMUNITY_LIST_MASTER);
12704
12705 for (list = cm->num.head; list; list = list->next)
12706 for (entry = list->head; entry; entry = entry->next)
12707 {
12708 vty_out (vty, "ip community-list %s %s %s%s",
12709 list->name, community_direct_str (entry->direct),
12710 community_list_config_str (entry),
12711 VTYNL);
12712 write++;
12713 }
12714 for (list = cm->str.head; list; list = list->next)
12715 for (entry = list->head; entry; entry = entry->next)
12716 {
12717 vty_out (vty, "ip community-list %s %s %s %s%s",
12718 entry->style == COMMUNITY_LIST_STANDARD
12719 ? "standard" : "expanded",
12720 list->name, community_direct_str (entry->direct),
12721 community_list_config_str (entry),
12722 VTYNL);
12723 write++;
12724 }
12725
12726 /* Extcommunity-list. */
12727 cm = community_list_master_lookup (bgp_clist, EXTCOMMUNITY_LIST_MASTER);
12728
12729 for (list = cm->num.head; list; list = list->next)
12730 for (entry = list->head; entry; entry = entry->next)
12731 {
12732 vty_out (vty, "ip extcommunity-list %s %s %s%s",
12733 list->name, community_direct_str (entry->direct),
12734 community_list_config_str (entry), VTYNL);
12735 write++;
12736 }
12737 for (list = cm->str.head; list; list = list->next)
12738 for (entry = list->head; entry; entry = entry->next)
12739 {
12740 vty_out (vty, "ip extcommunity-list %s %s %s %s%s",
12741 entry->style == EXTCOMMUNITY_LIST_STANDARD
12742 ? "standard" : "expanded",
12743 list->name, community_direct_str (entry->direct),
12744 community_list_config_str (entry), VTYNL);
12745 write++;
12746 }
12747
12748
12749 /* lcommunity-list. */
12750 cm = community_list_master_lookup (bgp_clist, LARGE_COMMUNITY_LIST_MASTER);
12751
12752 for (list = cm->num.head; list; list = list->next)
12753 for (entry = list->head; entry; entry = entry->next)
12754 {
12755 vty_out (vty, "ip large-community-list %s %s %s%s",
12756 list->name, community_direct_str (entry->direct),
12757 community_list_config_str (entry), VTYNL);
12758 write++;
12759 }
12760 for (list = cm->str.head; list; list = list->next)
12761 for (entry = list->head; entry; entry = entry->next)
12762 {
12763 vty_out (vty, "ip large-community-list %s %s %s %s%s",
12764 entry->style == LARGE_COMMUNITY_LIST_STANDARD
12765 ? "standard" : "expanded",
12766 list->name, community_direct_str (entry->direct),
12767 community_list_config_str (entry), VTYNL);
12768 write++;
12769 }
12770
12771 return write;
12772 }
12773
12774 static struct cmd_node community_list_node =
12775 {
12776 COMMUNITY_LIST_NODE,
12777 "",
12778 1 /* Export to vtysh. */
12779 };
12780
12781 static void
12782 community_list_vty (void)
12783 {
12784 install_node (&community_list_node, community_list_config_write);
12785
12786 /* Community-list. */
12787 install_element (CONFIG_NODE, &ip_community_list_standard_cmd);
12788 install_element (CONFIG_NODE, &ip_community_list_expanded_all_cmd);
12789 install_element (CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
12790 install_element (CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
12791 install_element (VIEW_NODE, &show_ip_community_list_cmd);
12792 install_element (VIEW_NODE, &show_ip_community_list_arg_cmd);
12793
12794 /* Extcommunity-list. */
12795 install_element (CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
12796 install_element (CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
12797 install_element (CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
12798 install_element (CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
12799 install_element (VIEW_NODE, &show_ip_extcommunity_list_cmd);
12800 install_element (VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
12801
12802 /* Large Community List */
12803 install_element (CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
12804 install_element (CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
12805 install_element (CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
12806 install_element (CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
12807 install_element (CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
12808 install_element (CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
12809 install_element (CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
12810 install_element (CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_all_cmd);
12811 install_element (CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
12812 install_element (CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
12813 install_element (CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
12814 install_element (CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
12815 install_element (VIEW_NODE, &show_ip_lcommunity_list_cmd);
12816 install_element (VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
12817 }