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