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