Tomato 1.28
[tomato.git] / release / src / router / zebra / bgpd / bgpd.c
bloba37f78f1952c5a85cc21bf60d0a7d94f3f1eb910
1 /* BGP-4, BGP-4+ daemon program
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
22 #include <zebra.h>
24 #include "prefix.h"
25 #include "thread.h"
26 #include "buffer.h"
27 #include "stream.h"
28 #include "table.h"
29 #include "command.h"
30 #include "sockunion.h"
31 #include "network.h"
32 #include "memory.h"
33 #include "filter.h"
34 #include "routemap.h"
35 #include "str.h"
36 #include "log.h"
37 #include "plist.h"
38 #include "linklist.h"
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_aspath.h"
42 #include "bgpd/bgp_route.h"
43 #include "bgpd/bgp_dump.h"
44 #include "bgpd/bgp_debug.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_clist.h"
48 #include "bgpd/bgp_fsm.h"
49 #include "bgpd/bgp_packet.h"
50 #include "bgpd/bgp_zebra.h"
51 #include "bgpd/bgp_open.h"
52 #include "bgpd/bgp_filter.h"
53 #include "bgpd/bgp_nexthop.h"
54 #include "bgpd/bgp_damp.h"
55 #include "bgpd/bgp_mplsvpn.h"
57 #define min(a, b) ((a) < (b) ? (a) : (b))
59 /* All BGP instance. */
60 struct list *bgp_list;
62 /* All peer instance. */
63 struct list *peer_list;
65 /* BGP multiple instance flag. */
66 int bgp_multiple_instance;
68 /* Enable BGP mutliple instance configuration. */
69 DEFUN (bgp_multiple_instance_func,
70 bgp_multiple_instance_cmd,
71 "bgp multiple-instance",
72 "BGP specific commands\n"
73 "Enable bgp multiple instance\n")
75 bgp_multiple_instance = 1;
76 return CMD_SUCCESS;
79 /* Disable BGP multiple instance. */
80 DEFUN (no_bgp_multiple_instance,
81 no_bgp_multiple_instance_cmd,
82 "no bgp multiple-instance",
83 NO_STR
84 "BGP specific commands\n"
85 "BGP multiple instance\n")
87 if (bgp_list->count > 1)
89 vty_out (vty, "There are more than two BGP instances%s",
90 VTY_NEWLINE);
91 return CMD_WARNING;
93 bgp_multiple_instance = 0;
94 return CMD_SUCCESS;
97 /* Peer group cofiguration. */
98 struct peer_group *
99 peer_group_new ()
101 struct peer_group *group;
103 group = XMALLOC (MTYPE_PEER_GROUP, sizeof (struct peer_group));
104 memset (group, 0, sizeof (struct peer_group));
105 return group;
108 void
109 peer_group_free (struct peer_group *group)
111 XFREE (MTYPE_PEER_GROUP, group);
114 struct peer_group *
115 peer_group_lookup (struct list *glist, char *name)
117 struct peer_group *group;
118 struct listnode *nn;
120 LIST_LOOP (glist, group, nn)
122 if (strcmp(group->name, name) == 0)
123 return group;
125 return NULL;
129 peer_group_get (struct vty *vty, char *name, int afi, int safi)
131 struct bgp *bgp;
132 struct peer_group *group;
134 bgp = vty->index;
135 group = peer_group_lookup (bgp->peer_group, name);
137 if (group)
139 vty_out (vty, "Same name peer-group already exists%s", VTY_NEWLINE);
140 return CMD_WARNING;
143 group = peer_group_new ();
144 group->name = strdup (name);
145 group->peer_conf = list_new ();
146 listnode_add (bgp->peer_group, group);
148 return CMD_SUCCESS;
152 peer_conf_peer_group (struct vty *vty, char *peer_str, char *group_str)
154 struct bgp *bgp;
155 struct peer_group *group;
157 bgp = vty->index;
159 group = peer_group_lookup (bgp->peer_group, group_str);
161 return CMD_SUCCESS;
164 DEFUN (neighbor_peer_group,
165 neighbor_peer_group_cmd,
166 "neighbor WORD peer-group",
167 NEIGHBOR_STR
168 "Neighbor tag\n"
169 "Configure peer-group\n")
171 return peer_group_get (vty, argv[0], 0, 0);
174 DEFUN (neighbor_peer_group_remote_as,
175 neighbor_peer_group_remote_as_cmd,
176 "neighbor WORD remote-as <1-65535>",
177 NEIGHBOR_STR
178 "Neighbor tag\n"
179 "Specify a BGP neighbor\n"
180 "AS of remote neighbor\n")
182 struct bgp *bgp;
183 struct peer_group *group;
184 char *endptr = NULL;
185 as_t as;
187 bgp = vty->index;
188 group = peer_group_lookup (bgp->peer_group, argv[0]);
190 if (!group)
192 vty_out (vty, "Please configure peer-group first%s", VTY_NEWLINE);
193 return CMD_WARNING;
195 if (group->peer_conf->count)
197 vty_out (vty, "Can't configure AS number for existance peer%s",
198 VTY_NEWLINE);
199 return CMD_WARNING;
202 /* Convert string to number. */
203 as = strtoul (argv[1], &endptr, 10);
204 if (as == ULONG_MAX || *endptr != '\0' || as < 1 || as > 65535)
206 vty_out (vty, "AS value error%s", VTY_NEWLINE);
207 return CMD_WARNING;
209 group->as = as;
211 return CMD_SUCCESS;
214 DEFUN (neighbor_set_peer_group,
215 neighbor_set_peer_group_cmd,
216 NEIGHBOR_CMD "peer-group WORD",
217 NEIGHBOR_STR
218 NEIGHBOR_ADDR_STR
219 "Member of the peer-group"
220 "peer-group name\n")
222 return peer_conf_peer_group (vty, argv[0], argv[1]);
225 /* Set BGP's router identifier. */
227 bgp_router_id_set (struct vty *vty, char *id_str)
229 struct bgp *bgp;
230 struct in_addr id;
231 int ret;
232 struct peer_conf *conf;
233 struct listnode *nn;
235 ret = inet_aton (id_str, &id);
236 if (!ret)
238 vty_out (vty, "Malformed bgp router identifier%s", VTY_NEWLINE);
239 return CMD_WARNING;
242 /* Set identifier to BGP structure. */
243 bgp = vty->index;
245 if (CHECK_FLAG (bgp->config, BGP_CONFIG_ROUTER_ID)
246 && bgp->id.s_addr == id.s_addr)
247 return CMD_SUCCESS;
249 bgp->id = id;
250 SET_FLAG (bgp->config, BGP_CONFIG_ROUTER_ID);
252 /* Set all peer's local identifier with this value. */
253 LIST_LOOP (bgp->peer_conf, conf, nn)
255 conf->peer->local_id = id;
256 /* Reset all BGP sessions */
257 BGP_EVENT_ADD (conf->peer, BGP_Stop);
260 return CMD_SUCCESS;
263 /* Unset BGP router identifier. */
265 bgp_router_id_unset (struct vty *vty, char *id_str)
267 int ret;
268 struct bgp *bgp;
269 struct in_addr id;
270 struct peer_conf *conf;
271 struct listnode *nn;
273 bgp = vty->index;
275 if (id_str)
277 ret = inet_aton (id_str, &id);
278 if (!ret)
280 vty_out (vty, "Malformed bgp router identifier%s", VTY_NEWLINE);
281 return CMD_WARNING;
284 if (!IPV4_ADDR_SAME (&bgp->id, &id))
286 vty_out (vty, "bgp router-id doesn't match%s", VTY_NEWLINE);
287 return CMD_WARNING;
291 if (! CHECK_FLAG (bgp->config, BGP_CONFIG_ROUTER_ID))
292 return CMD_SUCCESS;
294 bgp->id.s_addr = 0;
295 UNSET_FLAG (bgp->config, BGP_CONFIG_ROUTER_ID);
297 LIST_LOOP (bgp->peer_conf, conf, nn)
299 conf->peer->local_id.s_addr = 0;
302 /* Set router-id from interface's address. */
303 bgp_if_update_all ();
305 /* Reset all BGP sessions */
306 LIST_LOOP (bgp->peer_conf, conf, nn)
308 BGP_EVENT_ADD (conf->peer, BGP_Stop);
311 return CMD_SUCCESS;
314 DEFUN (bgp_router_id, bgp_router_id_cmd,
315 "bgp router-id A.B.C.D",
316 "BGP specific commands\n"
317 "Override configured router identifier\n"
318 "Manually configured router identifier\n")
320 return bgp_router_id_set (vty, argv[0]);
323 DEFUN (no_bgp_router_id, no_bgp_router_id_cmd,
324 "no bgp router-id",
325 NO_STR
326 "BGP specific commands\n"
327 "Override configured router identifier\n")
329 if (argc == 0)
330 return bgp_router_id_unset (vty, NULL);
332 return bgp_router_id_unset (vty, argv[0]);
335 ALIAS (no_bgp_router_id, no_bgp_router_id_val_cmd,
336 "no bgp router-id A.B.C.D",
337 NO_STR
338 "BGP specific commands\n"
339 "Override configured router identifier\n"
340 "Manually configured router identifier\n")
342 /* Set BGP's global timers. */
344 bgp_timers_set (struct vty *vty, char *keep_str, char *hold_str, int set)
346 struct bgp *bgp;
347 struct peer_conf *conf;
348 struct listnode *nn;
349 unsigned long keepalive = 0;
350 unsigned long holdtime = 0;
351 char *endptr = NULL;
353 if (set)
355 /* keepalive value check. */
356 keepalive = strtoul (keep_str, &endptr, 10);
358 if (keepalive == ULONG_MAX || *endptr != '\0')
360 vty_out (vty, "%% keepalive time value must be positive integer%s",
361 VTY_NEWLINE);
362 return CMD_WARNING;
364 if (keepalive > 65535)
366 vty_out (vty, "%% keepalive time value must be <0-65535>%s", VTY_NEWLINE);
367 return CMD_WARNING;
370 /* Holdtime value check. */
371 holdtime = strtoul (hold_str, &endptr, 10);
373 if (holdtime == ULONG_MAX || *endptr != '\0')
375 vty_out (vty, "%% hold time value must be positive integer%s", VTY_NEWLINE);
376 return CMD_WARNING;
378 if (holdtime > 65535)
380 vty_out (vty, "%% hold time value must be <0,3-65535>%s", VTY_NEWLINE);
381 return CMD_WARNING;
383 if (holdtime < 3 && holdtime != 0)
385 vty_out (vty, "%% hold time value must be either 0 or greater than 3%s",
386 VTY_NEWLINE);
387 return CMD_WARNING;
391 /* Set identifier to BGP structure. */
392 bgp = vty->index;
394 /* Set value to the configuration. */
395 if (set)
397 bgp->default_holdtime = holdtime;
398 bgp->default_keepalive = (keepalive < holdtime / 3 ? keepalive : holdtime / 3);
400 else
402 bgp->default_holdtime = BGP_DEFAULT_HOLDTIME;
403 bgp->default_keepalive = BGP_DEFAULT_KEEPALIVE;
406 /* Set all peer's global timers with this value. */
407 LIST_LOOP (bgp->peer_conf, conf, nn)
409 conf->peer->global_holdtime = bgp->default_holdtime;
410 conf->peer->global_keepalive = bgp->default_keepalive;
413 return CMD_SUCCESS;
416 DEFUN (bgp_timers, bgp_timers_cmd,
417 "timers bgp <0-65535> <0-65535>",
418 "Adjust routing timers\n"
419 "BGP timers\n"
420 "Keepalive interval\n"
421 "Holdtime\n")
423 return bgp_timers_set (vty, argv[0], argv[1], 1);
426 DEFUN (no_bgp_timers, no_bgp_timers_cmd,
427 "no timers bgp",
428 NO_STR
429 "Adjust routing timers\n"
430 "BGP timers\n")
432 return bgp_timers_set (vty, NULL, NULL, 0);
435 /* BGP's cluster-id control. */
437 bgp_cluster_id_set (struct vty *vty, char *cluster_str)
439 int ret;
440 struct bgp *bgp;
441 struct in_addr cluster;
443 ret = inet_aton (cluster_str, &cluster);
444 if (!ret)
446 vty_out (vty, "Malformed bgp cluster identifier%s", VTY_NEWLINE);
447 return CMD_WARNING;
449 bgp = vty->index;
450 bgp->cluster = cluster;
451 bgp->config |= BGP_CONFIG_CLUSTER_ID;
453 return CMD_SUCCESS;
457 bgp_cluster_id_unset (struct vty *vty, char *cluster_str)
459 int ret;
460 struct bgp *bgp;
461 struct in_addr cluster;
463 bgp = vty->index;
465 if (cluster_str)
467 ret = inet_aton (cluster_str, &cluster);
468 if (!ret)
470 vty_out (vty, "Malformed bgp cluster identifier%s", VTY_NEWLINE);
471 return CMD_WARNING;
473 if (! IPV4_ADDR_SAME (&bgp->cluster, &cluster))
475 vty_out (vty, "bgp cluster-id doesn't match%s", VTY_NEWLINE);
476 return CMD_WARNING;
479 bgp->cluster.s_addr = 0;
480 bgp->config &= ~BGP_CONFIG_CLUSTER_ID;
482 return CMD_SUCCESS;
485 DEFUN (bgp_cluster_id, bgp_cluster_id_cmd,
486 "bgp cluster-id A.B.C.D",
487 "BGP specific commands\n"
488 "Configure Route-Reflector Cluster-id\n"
489 "Route-Reflector Cluster-id in IP address format\n")
491 return bgp_cluster_id_set (vty, argv[0]);
494 ALIAS (bgp_cluster_id, bgp_cluster_id32_cmd,
495 "bgp cluster-id <1-4294967295>",
496 "BGP specific commands\n"
497 "Configure Route-Reflector Cluster-id\n"
498 "Route-Reflector Cluster-id as 32 bit quantity\n")
500 DEFUN (no_bgp_cluster_id, no_bgp_cluster_id_cmd,
501 "no bgp cluster-id",
502 NO_STR
503 "BGP specific commands\n"
504 "Configure Route-Reflector Cluster-id\n")
506 if (argc == 0)
507 return bgp_cluster_id_unset (vty, NULL);
509 return bgp_cluster_id_unset (vty, argv[0]);
512 ALIAS (no_bgp_cluster_id, no_bgp_cluster_id_val_cmd,
513 "no bgp cluster-id A.B.C.D",
514 NO_STR
515 "BGP specific commands\n"
516 "Configure Route-Reflector Cluster-id\n"
517 "Route-Reflector Cluster-id in IP address format\n")
520 bgp_confederation_id_set (struct vty *vty, char *id_str)
522 struct bgp *bgp;
523 as_t as = 0;
524 char *endptr = NULL;
525 struct peer *peer;
526 struct listnode *nn;
527 int old_confed_flag; /* Old Confederations status */
529 bgp = vty->index;
531 if (id_str)
533 as = strtoul (id_str, &endptr, 10);
534 if (as == ULONG_MAX || *endptr != '\0' || as < 1 || as > 65535)
536 vty_out (vty, "AS value error%s", VTY_NEWLINE);
537 return CMD_WARNING;
540 /* Remember - were we doing CONFEDs before? */
541 old_confed_flag = CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION);
542 bgp->confederation_id = as;
543 SET_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION);
546 * how to handle already setup peers?
547 * Answer - If we were doing CONFEDs already
548 * - this is just an external AS change
549 * - just Reset EBGP sessions, not CONFED sessions
550 * If we were not doing CONFEDs before
551 * - Reset all EBGP sessions
553 LIST_LOOP (peer_list, peer, nn)
555 /* We're looking for peers who's AS is not local or part of
556 our CONFED*/
557 if(old_confed_flag)
559 if (peer_sort (peer) == BGP_PEER_EBGP)
561 peer->local_as = as;
562 BGP_EVENT_ADD (peer, BGP_Stop);
565 else
567 /* Not doign CONFEDs before, so reset every non-local
568 session */
569 if (peer_sort (peer) != BGP_PEER_IBGP)
571 /* Reset the local_as to be our EBGP one */
572 if (peer_sort (peer) == BGP_PEER_EBGP)
573 peer->local_as = as;
574 BGP_EVENT_ADD (peer, BGP_Stop);
578 return CMD_SUCCESS;
580 else
582 vty_out (vty, "No AS Number provided%s", VTY_NEWLINE);
583 return CMD_WARNING;
585 return CMD_WARNING;
589 bgp_confederation_id_unset (struct vty *vty, char *id_str)
591 struct bgp *bgp;
592 as_t as;
593 char *endptr = NULL;
594 struct peer *peer;
595 struct listnode *nn;
597 bgp = vty->index;
599 if (id_str)
601 as = strtoul (id_str, &endptr, 10);
602 if (as == ULONG_MAX || *endptr != '\0' || as < 1 || as > 65535)
604 vty_out (vty, "%% AS value error%s", VTY_NEWLINE);
605 return CMD_WARNING;
608 if (bgp->confederation_id != as)
610 vty_out (vty, "%% AS value does not match%s", VTY_NEWLINE);
611 return CMD_WARNING;
614 bgp->confederation_id = 0;
615 UNSET_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION);
618 * How do we handle all EBGP peers if we have no external AS?
619 * Assumption - No Confed ID == no CONFEDERATIONS, so
620 * clear all EBGP *AND* CONFED peers and bring up with no spoofing.
622 LIST_LOOP (peer_list, peer, nn)
624 /* We're looking for peers who's AS is not local */
625 if (peer_sort (peer) != BGP_PEER_IBGP)
627 peer->local_as = bgp->as;
628 BGP_EVENT_ADD (peer, BGP_Stop);
631 return CMD_SUCCESS;
633 else
635 vty_out (vty, "%% No AS Number provided%s", VTY_NEWLINE);
636 return CMD_WARNING;
638 return CMD_WARNING;
641 /* Is an AS part of the confed or not? */
643 bgp_confederation_peers_check (struct bgp *bgp, as_t as)
645 int i;
647 if (bgp == NULL)
648 return 0;
650 for(i = 0; i < bgp->confederation_peers_cnt; i++)
652 if (bgp->confederation_peers[i] == as)
653 return 1;
656 return 0;
659 /* Add an AS to the CONFED set */
660 void
661 bgp_confederation_peers_add (struct bgp *bgp, as_t as)
663 bgp->confederation_peers = XREALLOC (MTYPE_BGP_CONFED_LIST,
664 bgp->confederation_peers,
665 bgp->confederation_peers_cnt + 1);
666 bgp->confederation_peers[bgp->confederation_peers_cnt] = as;
667 bgp->confederation_peers_cnt++;
670 void
671 bgp_confederation_peers_remove (struct bgp *bgp, as_t as)
673 int i;
674 int j;
676 for(i = 0; i < bgp->confederation_peers_cnt; i++)
678 if(bgp->confederation_peers[i] == as)
680 /* Remove this entry */
681 for(j = i+1; j < bgp->confederation_peers_cnt; j++)
683 bgp->confederation_peers[j-1] = bgp->confederation_peers[j];
688 bgp->confederation_peers_cnt--;
690 if (bgp->confederation_peers_cnt == 0)
692 bgp->confederation_peers = NULL;
694 else
696 bgp->confederation_peers = XREALLOC(MTYPE_BGP_CONFED_LIST,
697 bgp->confederation_peers,
698 bgp->confederation_peers_cnt);
703 bgp_confederation_peers_set (struct vty *vty, int argc, char *argv[])
705 struct bgp *bgp;
706 as_t as;
707 int i;
708 char *endptr = NULL;
710 bgp = vty->index;
712 for(i = 0; i < argc; i++)
714 as = strtoul (argv[i], &endptr, 10);
715 if (as == ULONG_MAX || as < 1 || as > 65535)
717 vty_out (vty, "AS Value error (%s), ignoring%s",
718 argv[i], VTY_NEWLINE);
720 else
722 if (bgp->as == as)
724 vty_out (vty, "%% Local member-AS not allowed in confed peer list%s",
725 VTY_NEWLINE);
726 continue;
728 if (! bgp_confederation_peers_check (bgp, as))
730 struct peer *peer;
731 struct listnode *nn;
733 /* Its not there already, so add it */
734 bgp_confederation_peers_add (bgp, as);
736 /* Now reset any peer who's remote AS has just joined
737 the CONFED unless its an iBGP peer */
738 LIST_LOOP (peer_list, peer, nn)
740 if (peer->as == as)
742 /* If the AS added to the list */
743 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION))
745 peer->local_as = bgp->as;
746 BGP_EVENT_ADD (peer, BGP_Stop);
751 else
753 /* Silently ignore repeated ASs */
757 return CMD_SUCCESS;
761 bgp_confederation_peers_unset (struct vty *vty, int argc, char *argv[])
763 struct bgp *bgp;
764 as_t as;
765 int i;
766 char *endptr = NULL;
768 bgp = vty->index;
770 for(i = 0; i < argc; i++)
772 as = strtoul (argv[i], &endptr, 10);
774 if (as == ULONG_MAX || as < 1 || as > 65535)
775 continue;
777 if (! bgp_confederation_peers_check(bgp, as))
779 /* Its not there already, so silently ignore this*/
781 else
783 struct peer *peer;
784 struct listnode *nn;
786 /* Its there - we need to remove it */
787 bgp_confederation_peers_remove (bgp, as);
789 /* Now reset any peer who's remote AS has just been
790 removed from the CONFED */
791 LIST_LOOP (peer_list, peer, nn)
793 if (peer->as == as)
795 /* Set the peer's local-as correctly */
796 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION))
798 peer->local_as = bgp->confederation_id;
799 BGP_EVENT_ADD (peer, BGP_Stop);
805 return CMD_SUCCESS;
808 void
809 bgp_confederation_peers_print (struct vty *vty, struct bgp *bgp)
811 int i;
813 for(i = 0; i < bgp->confederation_peers_cnt; i++)
815 vty_out(vty, " ");
817 vty_out(vty, "%d", bgp->confederation_peers[i]);
821 DEFUN (bgp_confederation_peers, bgp_confederation_peers_cmd,
822 "bgp confederation peers .<1-65535>",
823 "BGP specific commands\n"
824 "AS confederation parameters\n"
825 "Peer ASs in BGP confederation\n"
826 AS_STR)
828 return bgp_confederation_peers_set(vty, argc, argv);
831 DEFUN (bgp_confederation_identifier, bgp_confederation_identifier_cmd,
832 "bgp confederation identifier <1-65535>",
833 "BGP specific commands\n"
834 "AS confederation parameters\n"
835 "AS number\n"
836 "Set routing domain confederation AS\n")
838 return bgp_confederation_id_set(vty, argv[0]);
841 DEFUN (no_bgp_confederation_peers, no_bgp_confederation_peers_cmd,
842 "no bgp confederation peers .<1-65535>",
843 NO_STR
844 "BGP specific commands\n"
845 "AS confederation parameters\n"
846 "Peer ASs in BGP confederation\n"
847 AS_STR)
849 return bgp_confederation_peers_unset(vty, argc, argv);
852 DEFUN (no_bgp_confederation_identifier, no_bgp_confederation_identifier_cmd,
853 "no bgp confederation identifier <1-65535>",
854 NO_STR
855 "BGP specific commands\n"
856 "AS confederation parameters\n"
857 "AS number\n"
858 "Set routing domain confederation AS\n")
860 return bgp_confederation_id_unset(vty, argv[0]);
863 /* "no bgp client-to-client reflection" configuration. */
864 DEFUN (no_bgp_client_to_client_reflection,
865 no_bgp_client_to_client_reflection_cmd,
866 "no bgp client-to-client reflection",
867 NO_STR
868 "BGP specific commands\n"
869 "Configure client to client route reflection\n"
870 "reflection of routes allowed\n")
872 struct bgp *bgp;
874 bgp = vty->index;
875 SET_FLAG (bgp->config, BGP_CONFIG_NO_CLIENT_TO_CLIENT);
876 return CMD_SUCCESS;
879 DEFUN (bgp_client_to_client_reflection,
880 bgp_client_to_client_reflection_cmd,
881 "bgp client-to-client reflection",
882 "BGP specific commands\n"
883 "Configure client to client route reflection\n"
884 "reflection of routes allowed\n")
886 struct bgp *bgp;
888 bgp = vty->index;
889 UNSET_FLAG (bgp->config, BGP_CONFIG_NO_CLIENT_TO_CLIENT);
890 return CMD_SUCCESS;
893 /* "bgp always-compare-med" configuration. */
894 DEFUN (bgp_always_compare_med,
895 bgp_always_compare_med_cmd,
896 "bgp always-compare-med",
897 "BGP specific commands\n"
898 "Allow comparing MED from different neighbors\n")
900 struct bgp *bgp;
902 bgp = vty->index;
903 SET_FLAG (bgp->config, BGP_CONFIG_ALWAYS_COMPARE_MED);
904 return CMD_SUCCESS;
907 DEFUN (no_bgp_always_compare_med,
908 no_bgp_always_compare_med_cmd,
909 "no bgp always-compare-med",
910 NO_STR
911 "BGP specific commands\n"
912 "Allow comparing MED from different neighbors\n")
914 struct bgp *bgp;
916 bgp = vty->index;
917 UNSET_FLAG (bgp->config, BGP_CONFIG_ALWAYS_COMPARE_MED);
918 return CMD_SUCCESS;
921 /* "bgp deterministic-med" configuration. */
922 DEFUN (bgp_deterministic_med,
923 bgp_deterministic_med_cmd,
924 "bgp deterministic-med",
925 "BGP specific commands\n"
926 "Pick the best-MED path among paths advertised from the neighboring AS\n")
928 struct bgp *bgp;
930 bgp = vty->index;
931 SET_FLAG (bgp->config, BGP_CONFIG_DETERMINISTIC_MED);
932 return CMD_SUCCESS;
935 DEFUN (no_bgp_deterministic_med,
936 no_bgp_deterministic_med_cmd,
937 "no bgp deterministic-med",
938 NO_STR
939 "BGP specific commands\n"
940 "Pick the best-MED path among paths advertised from the neighboring AS\n")
942 struct bgp *bgp;
944 bgp = vty->index;
945 UNSET_FLAG (bgp->config, BGP_CONFIG_DETERMINISTIC_MED);
946 return CMD_SUCCESS;
949 /* "bgp enforce-first-as" configuration. */
950 DEFUN (bgp_enforce_first_as,
951 bgp_enforce_first_as_cmd,
952 "bgp enforce-first-as",
953 BGP_STR
954 "Enforce the first AS for EBGP routes\n")
956 struct bgp *bgp;
958 bgp = vty->index;
959 SET_FLAG (bgp->config, BGP_CONFIG_ENFORCE_FIRST_AS);
960 return CMD_SUCCESS;
963 DEFUN (no_bgp_enforce_first_as,
964 no_bgp_enforce_first_as_cmd,
965 "no bgp enforce-first-as",
966 NO_STR
967 BGP_STR
968 "Enforce the first AS for EBGP routes\n")
970 struct bgp *bgp;
972 bgp = vty->index;
973 UNSET_FLAG (bgp->config, BGP_CONFIG_ENFORCE_FIRST_AS);
974 return CMD_SUCCESS;
977 /* "bgp bestpath compare-routerid" configuration. */
978 DEFUN (bgp_bestpath_compare_router_id,
979 bgp_bestpath_compare_router_id_cmd,
980 "bgp bestpath compare-routerid",
981 "BGP specific commands\n"
982 "Change the default bestpath selection\n"
983 "Compare router-id for identical EBGP paths\n")
985 struct bgp *bgp;
987 bgp = vty->index;
988 SET_FLAG (bgp->config, BGP_CONFIG_COMPARE_ROUTER_ID);
989 return CMD_SUCCESS;
992 DEFUN (no_bgp_bestpath_compare_router_id,
993 no_bgp_bestpath_compare_router_id_cmd,
994 "no bgp bestpath compare-routerid",
995 NO_STR
996 "BGP specific commands\n"
997 "Change the default bestpath selection\n"
998 "Compare router-id for identical EBGP paths\n")
1000 struct bgp *bgp;
1002 bgp = vty->index;
1003 UNSET_FLAG (bgp->config, BGP_CONFIG_COMPARE_ROUTER_ID);
1004 return CMD_SUCCESS;
1007 /* "bgp bestpath as-path ignore" configuration. */
1008 DEFUN (bgp_bestpath_aspath_ignore,
1009 bgp_bestpath_aspath_ignore_cmd,
1010 "bgp bestpath as-path ignore",
1011 "BGP specific commands\n"
1012 "Change the default bestpath selection\n"
1013 "AS-path attribute\n"
1014 "Ignore as-path length in selecting a route\n")
1016 struct bgp *bgp;
1018 bgp = vty->index;
1019 SET_FLAG (bgp->config, BGP_CONFIG_ASPATH_IGNORE);
1020 return CMD_SUCCESS;
1023 DEFUN (no_bgp_bestpath_aspath_ignore,
1024 no_bgp_bestpath_aspath_ignore_cmd,
1025 "no bgp bestpath as-path ignore",
1026 NO_STR
1027 "BGP specific commands\n"
1028 "Change the default bestpath selection\n"
1029 "AS-path attribute\n"
1030 "Ignore as-path length in selecting a route\n")
1032 struct bgp *bgp;
1034 bgp = vty->index;
1035 UNSET_FLAG (bgp->config, BGP_CONFIG_ASPATH_IGNORE);
1036 return CMD_SUCCESS;
1040 /* "bgp bestpath med" configuration. */
1041 DEFUN (bgp_bestpath_med,
1042 bgp_bestpath_med_cmd,
1043 "bgp bestpath med (confed|missing-as-worst)",
1044 "BGP specific commands\n"
1045 "Change the default bestpath selection\n"
1046 "MED attribute\n"
1047 "Compare MED among confederation paths\n"
1048 "Treat missing MED as the least preferred one\n")
1050 struct bgp *bgp;
1052 bgp = vty->index;
1054 if (strcmp (argv[0], "confed") == 0)
1055 SET_FLAG (bgp->config, BGP_CONFIG_MED_CONFED);
1056 else
1057 SET_FLAG (bgp->config, BGP_CONFIG_MED_MISSING_AS_WORST);
1059 return CMD_SUCCESS;
1062 DEFUN (bgp_bestpath_med2,
1063 bgp_bestpath_med2_cmd,
1064 "bgp bestpath med confed missing-as-worst",
1065 "BGP specific commands\n"
1066 "Change the default bestpath selection\n"
1067 "MED attribute\n"
1068 "Compare MED among confederation paths\n"
1069 "Treat missing MED as the least preferred one\n")
1071 struct bgp *bgp;
1073 bgp = vty->index;
1074 SET_FLAG (bgp->config, BGP_CONFIG_MED_CONFED);
1075 SET_FLAG (bgp->config, BGP_CONFIG_MED_MISSING_AS_WORST);
1076 return CMD_SUCCESS;
1079 ALIAS (bgp_bestpath_med2,
1080 bgp_bestpath_med3_cmd,
1081 "bgp bestpath med missing-as-worst confed",
1082 "BGP specific commands\n"
1083 "Change the default bestpath selection\n"
1084 "MED attribute\n"
1085 "Treat missing MED as the least preferred one\n"
1086 "Compare MED among confederation paths\n")
1088 DEFUN (no_bgp_bestpath_med,
1089 no_bgp_bestpath_med_cmd,
1090 "no bgp bestpath med (confed|missing-as-worst)",
1091 NO_STR
1092 "BGP specific commands\n"
1093 "Change the default bestpath selection\n"
1094 "MED attribute\n"
1095 "Compare MED among confederation paths\n"
1096 "Treat missing MED as the least preferred one\n")
1098 struct bgp *bgp;
1100 bgp = vty->index;
1102 if (strcmp (argv[0], "confed") == 0)
1103 UNSET_FLAG (bgp->config, BGP_CONFIG_MED_CONFED);
1104 else
1105 UNSET_FLAG (bgp->config, BGP_CONFIG_MED_MISSING_AS_WORST);
1107 return CMD_SUCCESS;
1110 DEFUN (no_bgp_bestpath_med2,
1111 no_bgp_bestpath_med2_cmd,
1112 "no bgp bestpath med confed missing-as-worst",
1113 NO_STR
1114 "BGP specific commands\n"
1115 "Change the default bestpath selection\n"
1116 "MED attribute\n"
1117 "Compare MED among confederation paths\n"
1118 "Treat missing MED as the least preferred one\n")
1120 struct bgp *bgp;
1122 bgp = vty->index;
1123 UNSET_FLAG (bgp->config, BGP_CONFIG_MED_CONFED);
1124 UNSET_FLAG (bgp->config, BGP_CONFIG_MED_MISSING_AS_WORST);
1125 return CMD_SUCCESS;
1128 ALIAS (no_bgp_bestpath_med2,
1129 no_bgp_bestpath_med3_cmd,
1130 "no bgp bestpath med missing-as-worst confed",
1131 NO_STR
1132 "BGP specific commands\n"
1133 "Change the default bestpath selection\n"
1134 "MED attribute\n"
1135 "Treat missing MED as the least preferred one\n"
1136 "Compare MED among confederation paths\n")
1138 DEFUN (no_bgp_default_ipv4_unicast,
1139 no_bgp_default_ipv4_unicast_cmd,
1140 "no bgp default ipv4-unicast",
1141 NO_STR
1142 "BGP specific commands\n"
1143 "Configure BGP defaults\n"
1144 "Activate ipv4-unicast for a peer by default\n")
1146 struct bgp *bgp;
1148 bgp = vty->index;
1149 SET_FLAG (bgp->config, BGP_CONFIG_NO_DEFAULT_IPV4);
1150 return CMD_SUCCESS;
1153 DEFUN (bgp_default_ipv4_unicast,
1154 bgp_default_ipv4_unicast_cmd,
1155 "bgp default ipv4-unicast",
1156 "BGP specific commands\n"
1157 "Configure BGP defaults\n"
1158 "Activate ipv4-unicast for a peer by default\n")
1160 struct bgp *bgp;
1162 bgp = vty->index;
1163 UNSET_FLAG (bgp->config, BGP_CONFIG_NO_DEFAULT_IPV4);
1164 return CMD_SUCCESS;
1167 /* "bgp import-check" configuration. */
1168 DEFUN (bgp_network_import_check,
1169 bgp_network_import_check_cmd,
1170 "bgp network import-check",
1171 "BGP specific commands\n"
1172 "BGP network command\n"
1173 "Check BGP network route exists in IGP\n")
1175 struct bgp *bgp;
1177 bgp = vty->index;
1178 SET_FLAG (bgp->config, BGP_CONFIG_IMPORT_CHECK);
1179 return CMD_SUCCESS;
1182 DEFUN (no_bgp_network_import_check,
1183 no_bgp_network_import_check_cmd,
1184 "no bgp network import-check",
1185 NO_STR
1186 "BGP specific commands\n"
1187 "BGP network command\n"
1188 "Check BGP network route exists in IGP\n")
1190 struct bgp *bgp;
1192 bgp = vty->index;
1193 UNSET_FLAG (bgp->config, BGP_CONFIG_IMPORT_CHECK);
1194 return CMD_SUCCESS;
1197 DEFUN (bgp_default_local_preference,
1198 bgp_default_local_preference_cmd,
1199 "bgp default local-preference <0-4294967295>",
1200 "BGP specific commands\n"
1201 "Configure BGP defaults\n"
1202 "local preference (higher=more preferred)\n"
1203 "Configure default local preference value\n")
1205 struct bgp *bgp;
1207 bgp = vty->index;
1208 bgp->default_local_pref = atoi(argv[0]);
1209 return CMD_SUCCESS;
1212 DEFUN (no_bgp_default_local_preference,
1213 no_bgp_default_local_preference_cmd,
1214 "no bgp default local-preference",
1215 NO_STR
1216 "BGP specific commands\n"
1217 "Configure BGP defaults\n"
1218 "local preference (higher=more preferred)\n")
1220 struct bgp *bgp;
1222 bgp = vty->index;
1223 bgp->default_local_pref = BGP_DEFAULT_LOCAL_PREF;
1224 return CMD_SUCCESS;
1227 ALIAS (no_bgp_default_local_preference,
1228 no_bgp_default_local_preference_val_cmd,
1229 "no bgp default local-preference <0-4294967295>",
1230 NO_STR
1231 "BGP specific commands\n"
1232 "Configure BGP defaults\n"
1233 "local preference (higher=more preferred)\n"
1234 "Configure default local preference value\n")
1236 /* allocate new peer object */
1237 struct peer *
1238 peer_new ()
1240 struct peer *peer;
1241 struct servent *sp;
1243 /* Allocate new peer. */
1244 peer = XMALLOC (MTYPE_BGP_PEER, sizeof (struct peer));
1245 memset (peer, 0, sizeof (struct peer));
1247 /* Set default value. */
1248 peer->fd = -1;
1249 peer->v_start = BGP_INIT_START_TIMER;
1250 peer->v_connect = BGP_DEFAULT_CONNECT_RETRY;
1251 peer->v_holdtime = BGP_DEFAULT_HOLDTIME;
1252 peer->v_keepalive = BGP_DEFAULT_KEEPALIVE;
1253 peer->v_asorig = BGP_DEFAULT_ASORIGINATE;
1254 peer->v_routeadv = BGP_DEFAULT_ROUTEADV;
1255 peer->status = Idle;
1256 peer->ostatus = Idle;
1257 peer->version = BGP_VERSION_4;
1258 peer->weight = 0;
1259 peer->translate_update = 0;
1260 SET_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST], PEER_FLAG_SEND_COMMUNITY);
1261 SET_FLAG (peer->af_flags[AFI_IP][SAFI_MULTICAST], PEER_FLAG_SEND_COMMUNITY);
1262 SET_FLAG (peer->af_flags[AFI_IP][SAFI_MPLS_VPN], PEER_FLAG_SEND_COMMUNITY);
1263 SET_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST], PEER_FLAG_SEND_COMMUNITY);
1264 SET_FLAG (peer->af_flags[AFI_IP6][SAFI_MULTICAST], PEER_FLAG_SEND_COMMUNITY);
1265 SET_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST], PEER_FLAG_SEND_EXT_COMMUNITY);
1266 SET_FLAG (peer->af_flags[AFI_IP][SAFI_MULTICAST], PEER_FLAG_SEND_EXT_COMMUNITY);
1267 SET_FLAG (peer->af_flags[AFI_IP][SAFI_MPLS_VPN], PEER_FLAG_SEND_EXT_COMMUNITY);
1268 SET_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST], PEER_FLAG_SEND_EXT_COMMUNITY);
1269 SET_FLAG (peer->af_flags[AFI_IP6][SAFI_MULTICAST], PEER_FLAG_SEND_EXT_COMMUNITY);
1270 SET_FLAG (peer->flags, PEER_FLAG_CAPABILITY_ROUTE_REFRESH);
1271 SET_FLAG (peer->sflags, PEER_STATUS_CAPABILITY_OPEN);
1273 peer->ibuf = stream_new (BGP_MAX_PACKET_SIZE);
1274 peer->obuf = stream_fifo_new ();
1275 peer->conf = list_new ();
1277 peer->adj_in[AFI_IP][SAFI_UNICAST] = route_table_init ();
1278 peer->adj_in[AFI_IP][SAFI_MULTICAST] = route_table_init ();
1279 peer->adj_in[AFI_IP6][SAFI_UNICAST] = route_table_init ();
1280 peer->adj_in[AFI_IP6][SAFI_MULTICAST] = route_table_init ();
1282 peer->adj_out[AFI_IP][SAFI_UNICAST] = route_table_init ();
1283 peer->adj_out[AFI_IP][SAFI_MULTICAST] = route_table_init ();
1284 peer->adj_out[AFI_IP][SAFI_MPLS_VPN] = route_table_init ();
1285 peer->adj_out[AFI_IP6][SAFI_UNICAST] = route_table_init ();
1286 peer->adj_out[AFI_IP6][SAFI_MULTICAST] = route_table_init ();
1288 /* Get service port number. */
1289 sp = getservbyname ("bgp", "tcp");
1290 peer->port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
1292 return peer;
1295 /* Check peer's AS number and determin is this peer IBPG or EBGP */
1297 peer_sort (struct peer *peer)
1299 /* Find the relevant BGP structure */
1300 struct bgp *bgp;
1301 struct peer_conf *conf;
1302 struct listnode *nn;
1304 /* This becomes slightly more complicated as we have to find the
1305 CONFEDERATION list, so we can see if this is a BGP_PEER_CONFED */
1306 bgp = NULL;
1307 LIST_LOOP (peer->conf, conf, nn)
1309 bgp = conf->bgp;
1312 if(bgp && CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
1314 if (peer->local_as == 0)
1315 return BGP_PEER_INTERNAL;
1317 if (peer->local_as == peer->as)
1319 if (peer->local_as == bgp->confederation_id)
1320 return BGP_PEER_EBGP;
1321 else
1322 return BGP_PEER_IBGP;
1325 if (bgp_confederation_peers_check(bgp, peer->as))
1326 return BGP_PEER_CONFED;
1328 return BGP_PEER_EBGP;
1330 else
1332 return (peer->local_as == 0
1333 ? BGP_PEER_INTERNAL : peer->local_as == peer->as
1334 ? BGP_PEER_IBGP : BGP_PEER_EBGP);
1339 peer_list_cmp (struct peer *p1, struct peer *p2)
1341 return sockunion_cmp (&p1->su, &p2->su);
1345 peer_conf_cmp (struct peer_conf *p1, struct peer_conf *p2)
1347 return sockunion_cmp (&p1->peer->su, &p2->peer->su);
1350 struct peer_conf *
1351 peer_conf_new()
1353 struct peer_conf *pconf;
1355 pconf = XMALLOC (MTYPE_PEER_CONF, sizeof (struct peer_conf));
1356 memset (pconf, 0, sizeof (struct peer_conf));
1357 return pconf;
1360 void
1361 peer_conf_free (struct peer_conf *pconf)
1363 XFREE (MTYPE_PEER_CONF, pconf);
1366 void
1367 peer_conf_delete (struct peer_conf *conf)
1369 int i;
1370 afi_t afi;
1371 safi_t safi;
1372 struct bgp_filter *filter;
1374 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1375 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1377 filter = &conf->filter[afi][safi];
1379 for (i = FILTER_IN; i < FILTER_MAX; i++)
1381 if (filter->dlist[i].name)
1382 free (filter->dlist[i].name);
1383 if (filter->plist[i].name)
1384 free (filter->plist[i].name);
1385 if (filter->aslist[i].name)
1386 free (filter->aslist[i].name);
1387 if (filter->map[i].name)
1388 free (filter->map[i].name);
1391 peer_conf_free (conf);
1394 /* BGP instance creation by `router bgp' commands. */
1395 struct bgp *
1396 bgp_create ()
1398 struct bgp *bgp;
1399 afi_t afi;
1400 safi_t safi;
1402 bgp = XMALLOC (MTYPE_BGP, sizeof (struct bgp));
1403 memset (bgp, 0, sizeof (struct bgp));
1405 bgp->peer_group = list_new ();
1406 bgp->peer_conf = list_new ();
1407 bgp->peer_conf->cmp = (int (*)(void *, void *)) peer_conf_cmp;
1409 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1410 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1412 bgp->route[afi][safi] = route_table_init ();
1413 bgp->aggregate[afi][safi] = route_table_init ();
1414 bgp->rib[afi][safi] = route_table_init ();
1417 bgp->default_local_pref = BGP_DEFAULT_LOCAL_PREF;
1418 bgp->default_holdtime = BGP_DEFAULT_HOLDTIME;
1419 bgp->default_keepalive = BGP_DEFAULT_KEEPALIVE;
1421 return bgp;
1424 /* Return first entry of BGP. */
1425 struct bgp *
1426 bgp_get_default ()
1428 if (bgp_list->head)
1429 return bgp_list->head->data;
1430 return NULL;
1433 /* Lookup BGP entry. */
1434 struct bgp *
1435 bgp_lookup (as_t as, char *name)
1437 struct bgp *bgp;
1438 struct listnode *nn;
1440 LIST_LOOP (bgp_list, bgp, nn)
1441 if (bgp->as == as
1442 && ((bgp->name == NULL && name == NULL)
1443 || (bgp->name && name && strcmp (bgp->name, name) == 0)))
1444 return bgp;
1445 return NULL;
1448 /* Lookup BGP structure by view name. */
1449 struct bgp *
1450 bgp_lookup_by_name (char *name)
1452 struct bgp *bgp;
1453 struct listnode *nn;
1455 LIST_LOOP (bgp_list, bgp, nn)
1456 if ((bgp->name == NULL && name == NULL)
1457 || (bgp->name && name && strcmp (bgp->name, name) == 0))
1458 return bgp;
1459 return NULL;
1462 /* Called from VTY commands. */
1464 bgp_get (struct vty *vty, as_t as, char *name)
1466 struct bgp *bgp;
1468 /* Multiple instance check. */
1469 if (! bgp_multiple_instance)
1471 if (name)
1473 vty_out (vty, "Please specify 'bgp multiple-instance' first%s",
1474 VTY_NEWLINE);
1475 return CMD_WARNING;
1478 /* Get first BGP structure if exists. */
1479 bgp = bgp_get_default ();
1481 if (bgp)
1483 if (bgp->as != as)
1485 vty_out (vty, "BGP is already running; AS is %d%s", bgp->as,
1486 VTY_NEWLINE);
1487 return CMD_WARNING;
1489 vty->node = BGP_NODE;
1490 vty->index = bgp;
1491 return CMD_SUCCESS;
1494 bgp = bgp_create ();
1495 bgp->as = as;
1496 listnode_add (bgp_list, bgp);
1497 bgp_if_update_all ();
1498 vty->node = BGP_NODE;
1499 vty->index = bgp;
1500 return CMD_SUCCESS;
1502 else
1504 bgp = bgp_lookup (as, name);
1506 if (bgp)
1508 vty->node = BGP_NODE;
1509 vty->index = bgp;
1510 return CMD_SUCCESS;
1513 bgp = bgp_create ();
1514 bgp->as = as;
1515 if (name)
1516 bgp->name = strdup (name);
1517 listnode_add (bgp_list, bgp);
1518 bgp_if_update_all ();
1519 vty->node = BGP_NODE;
1520 vty->index = bgp;
1522 return CMD_SUCCESS;
1524 return CMD_SUCCESS;
1528 bgp_get_by_str (struct vty *vty, char *as_str, char *name)
1530 char *endptr = NULL;
1531 as_t as;
1533 /* Convert string to number. */
1534 as = strtoul (as_str, &endptr, 10);
1535 if (as == ULONG_MAX || *endptr != '\0' || as < 1 || as > 65535)
1537 vty_out (vty, "AS value error%s", VTY_NEWLINE);
1538 return CMD_WARNING;
1540 return bgp_get (vty, as, name);
1543 /* Delete BGP instance. */
1544 void
1545 bgp_delete (struct bgp *bgp)
1547 struct peer_conf *conf;
1548 struct listnode *nn;
1549 struct listnode *next;
1550 afi_t afi;
1551 safi_t safi;
1553 /* Delete static route. */
1554 bgp_static_delete (bgp);
1556 bgp->peer_group->del = (void (*)(void *)) peer_group_free;
1558 list_delete (bgp->peer_group);
1560 for (nn = bgp->peer_conf->head; nn; nn = next)
1562 conf = nn->data;
1563 next = nn->next;
1564 peer_delete (conf->peer);
1567 /* Clear peer_conf */
1568 list_delete (bgp->peer_conf);
1570 listnode_delete (bgp_list, bgp);
1572 if (bgp->name)
1573 free (bgp->name);
1575 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1576 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1578 if (bgp->route[afi][safi])
1579 XFREE (MTYPE_ROUTE_TABLE, bgp->route[afi][safi]);
1580 if (bgp->aggregate[afi][safi])
1581 XFREE (MTYPE_ROUTE_TABLE,bgp->aggregate[afi][safi]) ;
1582 if (bgp->rib[afi][safi])
1583 XFREE (MTYPE_ROUTE_TABLE,bgp->rib[afi][safi]);
1586 XFREE (MTYPE_BGP, bgp);
1589 /* This function is called from VTY command. Act as a wrapper of
1590 bgp_delte (). */
1592 bgp_destroy (struct vty *vty, char *as_str, char *name)
1594 struct bgp *bgp;
1595 char *endptr = NULL;
1596 as_t as;
1597 /* struct in_addr id; */
1599 /* Convert string to number. */
1600 as = strtoul (as_str, &endptr, 10);
1601 if (as == ULONG_MAX || *endptr != '\0' || as < 1 || as > 65535)
1603 vty_out (vty, "AS value error%s", VTY_NEWLINE);
1604 return CMD_WARNING;
1607 /* Lookup bgp structure. */
1608 bgp = bgp_lookup (as, name);
1610 if (!bgp)
1612 vty_out (vty, "Can't find BGP instance%s", VTY_NEWLINE);
1613 return CMD_WARNING;
1616 bgp_delete (bgp);
1618 return CMD_SUCCESS;
1621 /* `router bgp' commands. */
1622 DEFUN (router_bgp,
1623 router_bgp_cmd,
1624 "router bgp <1-65535>",
1625 ROUTER_STR
1626 BGP_STR
1627 AS_STR)
1629 return bgp_get_by_str (vty, argv[0], NULL);
1632 DEFUN (router_bgp_view,
1633 router_bgp_view_cmd,
1634 "router bgp <1-65535> view WORD",
1635 ROUTER_STR
1636 BGP_STR
1637 AS_STR
1638 "BGP view\n"
1639 "view name\n")
1641 return bgp_get_by_str (vty, argv[0], argv[1]);
1644 /* `no router bgp' commands. */
1645 DEFUN (no_router_bgp,
1646 no_router_bgp_cmd,
1647 "no router bgp <1-65535>",
1648 NO_STR
1649 ROUTER_STR
1650 BGP_STR
1651 AS_STR)
1653 return bgp_destroy (vty, argv[0], NULL);
1656 DEFUN (no_router_bgp_view,
1657 no_router_bgp_view_cmd,
1658 "no router bgp <1-65535> view WORD",
1659 NO_STR
1660 ROUTER_STR
1661 BGP_STR
1662 AS_STR
1663 "BGP view\n"
1664 "view name\n")
1666 return bgp_destroy (vty, argv[0], argv[1]);
1669 /* Peer identification.
1671 Peer structure is identified by it's IP address, local AS number,
1672 remote AS number and local router-id. Normally, local router-id
1673 identification is used only for Merit MRT like route server
1674 configuration.
1676 When user configure the peer under specific BGP instance node, only
1677 IP address and local AS number are used for looking up. If the
1678 peer's remote AS number and user configuration AS number is
1679 different, the peer's AS number is changed. */
1681 struct peer *
1682 peer_lookup_with_local_as (union sockunion *su, as_t local_as)
1684 struct peer *peer;
1685 struct listnode *nn;
1687 LIST_LOOP (peer_list, peer, nn)
1689 if (sockunion_same (&peer->su, su)
1690 && peer->local_as == local_as)
1691 return peer;
1693 return NULL;
1696 /* Accepting remote BGP connection, at least remote connection's
1697 source IP address is configured as a peer. This function check the
1698 existance of the IP address. */
1700 struct peer *
1701 peer_lookup_by_su (union sockunion *su)
1703 struct peer *peer;
1704 struct listnode *nn;
1706 LIST_LOOP (peer_list, peer, nn)
1708 if (sockunion_same (&peer->su, su)
1709 && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER))
1710 return peer;
1712 return NULL;
1715 /* BGP Open packet includes remote router's AS number and router-id.
1716 We lookup local peer with those information. First loop check
1717 exact match peer including remote router-id. Second loop check
1718 anonymous router-id peer. */
1720 struct peer *
1721 peer_lookup_with_open (union sockunion *su, as_t remote_as,
1722 struct in_addr *remote_id, int *as)
1724 struct peer *peer;
1725 struct listnode *nn;
1727 LIST_LOOP (peer_list, peer, nn)
1729 if (sockunion_same (&peer->su, su)
1730 && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER))
1732 if (peer->as == remote_as
1733 && peer->remote_id.s_addr == remote_id->s_addr)
1734 return peer;
1735 if (peer->as == remote_as)
1736 *as = 1;
1739 LIST_LOOP (peer_list, peer, nn)
1741 if (sockunion_same (&peer->su, su)
1742 && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER))
1744 if (peer->as == remote_as
1745 && peer->remote_id.s_addr == 0)
1746 return peer;
1747 if (peer->as == remote_as)
1748 *as = 1;
1751 return NULL;
1754 struct peer_conf *
1755 peer_conf_lookup (struct bgp *bgp, union sockunion *su, int afi)
1757 struct listnode *nn;
1758 struct peer_conf *conf;
1760 LIST_LOOP (bgp->peer_conf, conf, nn)
1762 if (sockunion_same (&conf->peer->su, su))
1763 return conf;
1765 return NULL;
1768 /* Utility function for lookup peer from VTY commands. */
1769 struct peer_conf *
1770 peer_conf_lookup_vty (struct vty *vty, char *ip_str, int afi)
1772 int ret;
1773 struct bgp *bgp;
1774 union sockunion su;
1775 struct peer_conf *conf;
1777 bgp = vty->index;
1779 ret = str2sockunion (ip_str, &su);
1780 if (ret < 0)
1782 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
1783 return NULL;
1786 conf = peer_conf_lookup (bgp, &su, afi);
1787 if (! conf)
1789 vty_out (vty, "Can't find peer: %s%s", ip_str, VTY_NEWLINE);
1790 return NULL;
1792 return conf;
1795 struct peer_conf *
1796 peer_conf_lookup_existing (struct bgp *bgp, union sockunion *su)
1798 struct listnode *nn;
1799 struct peer_conf *conf;
1801 LIST_LOOP (bgp->peer_conf, conf, nn)
1803 if (sockunion_same (&conf->peer->su, su))
1804 return conf;
1806 return NULL;
1809 #define BGP_UPTIME_LEN 25
1811 /* Display peer uptime. */
1812 char *
1813 peer_uptime (time_t uptime2, char *buf, size_t len)
1815 time_t uptime1;
1816 struct tm *tm;
1818 /* Check buffer length. */
1819 if (len < BGP_UPTIME_LEN)
1821 zlog_warn ("peer_uptime (): buffer shortage %d", len);
1822 return "";
1825 /* If there is no connection has been done before print `never'. */
1826 if (uptime2 == 0)
1828 snprintf (buf, len, "never ");
1829 return buf;
1832 /* Get current time. */
1833 uptime1 = time (NULL);
1834 uptime1 -= uptime2;
1835 tm = gmtime (&uptime1);
1837 /* Making formatted timer strings. */
1838 #define ONE_DAY_SECOND 60*60*24
1839 #define ONE_WEEK_SECOND 60*60*24*7
1841 if (uptime1 < ONE_DAY_SECOND)
1842 snprintf (buf, len, "%02d:%02d:%02d",
1843 tm->tm_hour, tm->tm_min, tm->tm_sec);
1844 else if (uptime1 < ONE_WEEK_SECOND)
1845 snprintf (buf, len, "%dd%02dh%02dm",
1846 tm->tm_yday, tm->tm_hour, tm->tm_min);
1847 else
1848 snprintf (buf, len, "%02dw%dd%02dh",
1849 tm->tm_yday/7, tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1850 return buf;
1853 /* If peer is configured at least one address family return 1. */
1855 peer_active (struct peer *peer)
1857 if (peer->afc[AFI_IP][SAFI_UNICAST]
1858 || peer->afc[AFI_IP][SAFI_MULTICAST]
1859 || peer->afc[AFI_IP][SAFI_MPLS_VPN]
1860 || peer->afc[AFI_IP6][SAFI_UNICAST]
1861 || peer->afc[AFI_IP6][SAFI_MULTICAST])
1862 return 1;
1863 return 0;
1866 struct peer *
1867 peer_create (union sockunion *su, as_t local_as, struct in_addr id,
1868 as_t remote_as, u_int32_t holdtime, u_int32_t keepalive)
1870 struct peer *peer;
1871 char buf[SU_ADDRSTRLEN];
1873 peer = peer_new ();
1874 peer->su = *su;
1875 peer->local_as = local_as;
1876 peer->as = remote_as;
1877 peer->local_id = id;
1878 peer->global_holdtime = holdtime;
1879 peer->global_keepalive = keepalive;
1880 listnode_add_sort (peer_list, peer);
1882 /* Last read time set */
1883 peer->readtime = time(NULL);
1885 /* Default TTL set. */
1886 peer->ttl = (peer_sort (peer) == BGP_PEER_IBGP ? 255 : 1);
1888 /* Make peer's address string. */
1889 sockunion2str (su, buf, SU_ADDRSTRLEN);
1890 peer->host = strdup (buf);
1892 /* Set up peer's events and timers. */
1893 bgp_timer_set (peer);
1895 return peer;
1898 /* Make accept BGP peer. Called from bgp_accept (). */
1899 struct peer *
1900 peer_create_accept ()
1902 struct peer *peer;
1904 peer = peer_new ();
1905 listnode_add_sort (peer_list, peer);
1907 return peer;
1910 /* Change peer's AS number */
1912 peer_as_change (struct peer *peer, as_t as)
1914 /* Stop peer. */
1915 bgp_stop (peer);
1917 peer->as = as;
1919 /* ebgp-multihop reset. */
1921 return CMD_SUCCESS;
1924 void
1925 peer_af_flag_reset (afi_t afi, safi_t safi, struct peer_conf *conf)
1927 struct peer *peer;
1928 struct bgp_filter *filter;
1929 int i;
1931 peer = conf->peer;
1932 filter = &conf->filter[afi][safi];
1934 /* Clear neighbor filter and route-map */
1935 for (i = FILTER_IN; i < FILTER_MAX; i++)
1937 if (filter->dlist[i].name)
1939 free (filter->dlist[i].name);
1940 filter->dlist[i].name = NULL;
1942 if (filter->plist[i].name)
1944 free (filter->plist[i].name);
1945 filter->plist[i].name = NULL;
1947 if (filter->aslist[i].name)
1949 free (filter->aslist[i].name);
1950 filter->aslist[i].name = NULL;
1952 if (filter->map[i].name)
1954 free (filter->map[i].name);
1955 filter->map[i].name = NULL;
1959 /* Clear neighbor next-hop-self */
1960 UNSET_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF);
1962 /* Clear neighbor send-community */
1963 SET_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY);
1964 SET_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY);
1966 /* Clear neighbor route-reflector-client */
1967 UNSET_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT);
1969 /* Clear neighbor route-server-client */
1970 UNSET_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT);
1972 /* Clear neighbor soft-reconfiguration inbound */
1973 UNSET_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG);
1975 /* Clear neighbor maximum-prefix */
1976 conf->pmax[afi][safi] = 0;
1977 conf->pmax_warning[afi][safi] = 0;
1980 struct peer_conf *
1981 peer_conf_create (int afi, int safi, struct peer *peer)
1983 struct peer_conf *conf;
1984 int active;
1986 /* Make new peer configuration then link it to the peer. */
1987 conf = peer_conf_new ();
1988 conf->peer = peer;
1989 listnode_add_sort (peer->conf, conf);
1991 /* Store peer's active status. */
1992 active = peer_active (peer);
1994 if (safi & SAFI_UNICAST)
1996 conf->afc[afi][SAFI_UNICAST] = 1;
1997 peer->afc[afi][SAFI_UNICAST]++;
1999 if (safi & SAFI_MULTICAST)
2001 conf->afc[afi][SAFI_MULTICAST] = 1;
2002 peer->afc[afi][SAFI_MULTICAST]++;
2004 if (safi == SAFI_MPLS_VPN)
2006 conf->afc[afi][safi] = 1;
2007 peer->afc[afi][safi]++;
2010 /* If this configuration activate the peer, set start timer. */
2011 if (! active && peer_active (peer))
2012 bgp_timer_set (peer);
2014 return conf;
2017 void
2018 peer_conf_active (int afi, int safi, struct peer_conf *conf)
2020 int active;
2021 struct peer *peer;
2023 peer = conf->peer;
2024 active = peer_active (peer);
2026 conf->afc[afi][safi] = 1;
2027 conf->peer->afc[afi][safi]++;
2029 /* If this configuration activate the peer, set start timer. */
2030 if (! active && peer_active (peer))
2031 bgp_timer_set (peer);
2032 else
2033 BGP_EVENT_ADD (peer, BGP_Stop);
2036 void
2037 peer_conf_deactive (int afi, int safi, struct peer_conf *conf)
2039 struct peer *peer;
2041 peer = conf->peer;
2043 /* Must be configured. */
2044 if (! conf->afc[afi][safi])
2045 return;
2047 conf->afc[afi][safi] = 0;
2048 peer->afc[afi][safi]--;
2050 /* Clear peer Per AF configuration */
2051 peer_af_flag_reset (afi, safi, conf);
2053 BGP_EVENT_ADD (peer, BGP_Stop);
2056 /* Make or change remote peer's AS number. */
2058 peer_remote_as (struct vty *vty, char *ip_str, char *as_str, int afi, int safi)
2060 int ret;
2061 struct bgp *bgp;
2062 char *endptr = NULL;
2063 as_t as;
2064 union sockunion su;
2065 struct peer *peer;
2066 struct peer_conf *conf;
2068 ret = str2sockunion (ip_str, &su);
2069 if (ret < 0)
2071 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
2072 return CMD_WARNING;
2075 as = strtoul (as_str, &endptr, 10);
2076 if (as == ULONG_MAX || *endptr != '\0' || as < 1 || as > 65535)
2078 vty_out (vty, "AS value error: %s%s", as_str, VTY_NEWLINE);
2079 return CMD_WARNING;
2082 bgp = vty->index;
2084 peer = peer_lookup_with_local_as (&su, bgp->as);
2085 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION) && ! peer)
2087 peer = peer_lookup_with_local_as (&su, bgp->confederation_id);
2090 if (peer)
2092 /* Lookup peer_conf */
2093 conf = peer_conf_lookup (bgp, &su, afi);
2095 if (! conf)
2097 /* New peer configuration. */
2098 conf = peer_conf_create (afi, safi, peer);
2099 conf->bgp = bgp;
2100 listnode_add_sort (bgp->peer_conf, conf);
2103 /* Existing peer's AS number change. */
2104 if (peer->as != as)
2105 peer_as_change (peer, as);
2107 /* Existing peer's SAFI change. */
2108 /* XXXX need code here. */;
2110 else
2112 /* Real peer creation. */
2114 /* If the peer is not part of our CONFED, and its not an iBGP peer then
2115 spoof the source AS */
2116 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION)
2117 && ! bgp_confederation_peers_check(bgp, as)
2118 && bgp->as != as)
2120 peer = peer_create (&su, bgp->confederation_id,
2121 bgp->id, as, bgp->default_holdtime,
2122 bgp->default_keepalive);
2124 else
2126 peer = peer_create (&su, bgp->as, bgp->id, as,
2127 bgp->default_holdtime,
2128 bgp->default_keepalive);
2131 /* If this is IPv4 unicast configuration and "no bgp default
2132 ipv4-unicast" is specified. */
2133 if (CHECK_FLAG (bgp->config, BGP_CONFIG_NO_DEFAULT_IPV4)
2134 && afi == AFI_IP && safi == SAFI_UNICAST)
2135 conf = peer_conf_create (0, 0, peer);
2136 else
2137 conf = peer_conf_create (afi, safi, peer);
2139 conf->bgp = bgp;
2140 listnode_add_sort (bgp->peer_conf, conf);
2143 return CMD_SUCCESS;
2147 peer_activate (struct vty *vty, char *ip_str, int afi, int safi)
2149 int ret;
2150 union sockunion su;
2151 struct bgp *bgp;
2152 struct peer_conf *conf;
2154 bgp = vty->index;
2156 /* Lookup peer. */
2157 ret = str2sockunion (ip_str, &su);
2158 if (ret < 0)
2160 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
2161 return CMD_WARNING;
2164 conf = peer_conf_lookup_existing (bgp, &su);
2165 if (! conf)
2167 vty_out (vty, "%% Specify remote-as or peer-group commands first%s",
2168 VTY_NEWLINE);
2169 return CMD_WARNING;
2172 /* Activate the address family configuration. */
2173 if (! conf->afc[afi][safi])
2174 peer_conf_active (afi, safi, conf);
2176 return CMD_SUCCESS;
2180 peer_deactivate (struct vty *vty, char *ip_str, int afi, int safi)
2182 int ret;
2183 union sockunion su;
2184 struct bgp *bgp;
2185 struct peer_conf *conf;
2187 bgp = vty->index;
2189 /* Lookup peer. */
2190 ret = str2sockunion (ip_str, &su);
2191 if (ret < 0)
2193 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
2194 return CMD_WARNING;
2197 conf = peer_conf_lookup_existing (bgp, &su);
2198 if (! conf)
2200 vty_out (vty, "%% Specify remote-as or peer-group commands first%s",
2201 VTY_NEWLINE);
2202 return CMD_WARNING;
2205 /* De-activate the address family configuration. */
2206 if (conf->afc[afi][safi])
2207 peer_conf_deactive (afi, safi, conf);
2209 return CMD_SUCCESS;
2212 /* Delete peer from confguration. */
2213 void
2214 peer_delete (struct peer *peer)
2216 struct peer_conf *conf;
2217 struct listnode *nn;
2219 /* Withdraw all information from routing table. We can not use
2220 BGP_EVENT_ADD (peer, BGP_Stop) at here. Because the event is
2221 executed after peer structure is deleted. */
2222 bgp_stop (peer);
2223 fsm_change_status (peer, Idle);
2225 /* Delete peer_conf link from BGP structure. */
2226 LIST_LOOP (peer->conf, conf, nn)
2228 listnode_delete (conf->bgp->peer_conf, conf);
2231 /* Free peer_conf structure. */
2232 peer->conf->del = (void (*) (void *)) peer_conf_delete;
2233 list_delete (peer->conf);
2234 peer->conf = NULL;
2236 /* Stop all timers. */
2237 BGP_TIMER_OFF (peer->t_start);
2238 BGP_TIMER_OFF (peer->t_keepalive);
2239 BGP_TIMER_OFF (peer->t_holdtime);
2240 BGP_TIMER_OFF (peer->t_connect);
2241 BGP_TIMER_OFF (peer->t_asorig);
2242 BGP_TIMER_OFF (peer->t_routeadv);
2244 /* Delete from all peer list. */
2245 listnode_delete (peer_list, peer);
2247 if (peer->ibuf)
2248 stream_free (peer->ibuf);
2250 if (peer->obuf)
2251 stream_fifo_free (peer->obuf);
2253 /* Free allocated host character. */
2254 if (peer->host)
2255 free (peer->host);
2257 /* Local and remote addresses. */
2258 if (peer->su_local)
2259 XFREE (MTYPE_TMP, peer->su_local);
2260 if (peer->su_remote)
2261 XFREE (MTYPE_TMP, peer->su_remote);
2263 if (peer->adj_in[AFI_IP][SAFI_UNICAST])
2264 XFREE (MTYPE_ROUTE_TABLE,peer->adj_in [AFI_IP][SAFI_UNICAST] );
2265 if (peer->adj_in[AFI_IP][SAFI_MULTICAST])
2266 XFREE (MTYPE_ROUTE_TABLE,peer->adj_in [AFI_IP][SAFI_MULTICAST] );
2267 if (peer->adj_in[AFI_IP6][SAFI_UNICAST])
2268 XFREE (MTYPE_ROUTE_TABLE,peer->adj_in [AFI_IP6][SAFI_UNICAST] );
2269 if (peer->adj_in[AFI_IP6][SAFI_MULTICAST])
2270 XFREE (MTYPE_ROUTE_TABLE,peer->adj_in [AFI_IP6][SAFI_MULTICAST]);
2271 if (peer->adj_out[AFI_IP][SAFI_UNICAST])
2272 XFREE (MTYPE_ROUTE_TABLE,peer->adj_out[AFI_IP][SAFI_UNICAST] );
2273 if (peer->adj_out[AFI_IP][SAFI_MULTICAST])
2274 XFREE (MTYPE_ROUTE_TABLE,peer->adj_out[AFI_IP][SAFI_MULTICAST] );
2275 if (peer->adj_out[AFI_IP][SAFI_MPLS_VPN])
2276 XFREE (MTYPE_ROUTE_TABLE,peer->adj_out[AFI_IP][SAFI_MPLS_VPN] );
2277 if (peer->adj_out[AFI_IP6][SAFI_UNICAST])
2278 XFREE (MTYPE_ROUTE_TABLE,peer->adj_out[AFI_IP6][SAFI_UNICAST] );
2279 if (peer->adj_out[AFI_IP6][SAFI_MULTICAST])
2280 XFREE (MTYPE_ROUTE_TABLE,peer->adj_out[AFI_IP6][SAFI_MULTICAST]);
2282 /* Free peer structure. */
2283 XFREE (MTYPE_BGP_PEER, peer);
2287 peer_destroy (struct vty *vty, char *ip_str, char *as_str, int afi, int safi)
2289 int ret;
2290 struct bgp *bgp;
2291 char *endptr = NULL;
2292 as_t as = 0;
2293 union sockunion su;
2294 struct peer *peer;
2296 ret = str2sockunion (ip_str, &su);
2297 if (ret < 0)
2299 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
2300 return CMD_WARNING;
2303 if (as_str)
2305 as = strtoul (as_str, &endptr, 10);
2306 if (as == ULONG_MAX || *endptr != '\0' || as < 1 || as > 65535)
2308 vty_out (vty, "AS value error: %s%s", as_str, VTY_NEWLINE);
2309 return CMD_WARNING;
2313 bgp = vty->index;
2315 peer = peer_lookup_with_local_as (&su, bgp->as);
2316 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION) && !peer)
2318 peer = peer_lookup_with_local_as (&su, bgp->confederation_id);
2321 if (! peer)
2323 vty_out (vty, "Can't find peer: %s%s", ip_str, VTY_NEWLINE);
2324 return CMD_WARNING;
2326 if (as_str && peer->as != as)
2328 vty_out (vty, "AS mismatch%s", VTY_NEWLINE);
2329 return CMD_WARNING;
2332 peer_delete (peer);
2334 return CMD_SUCCESS;
2337 /* peer_flag_change_type. */
2338 enum flag_change_type
2340 flag_change_set,
2341 flag_change_set_reset,
2342 flag_change_unset,
2343 flag_change_unset_reset
2346 /* Change specified peer flag. */
2348 peer_change_af_flag (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
2349 u_int16_t flag, enum flag_change_type type)
2351 struct peer *peer;
2352 struct peer_conf *conf;
2354 conf = peer_conf_lookup_vty (vty, ip_str, afi);
2355 if (! conf)
2356 return CMD_WARNING;
2357 if (! conf->afc[afi][safi])
2359 vty_out (vty, "%% Activate the neighbor for the address family first%s",
2360 VTY_NEWLINE);
2361 return CMD_WARNING;
2364 peer = conf->peer;
2366 if (type == flag_change_set
2367 || type == flag_change_set_reset)
2369 if (CHECK_FLAG (peer->af_flags[afi][safi], flag))
2370 return CMD_WARNING;
2372 SET_FLAG (peer->af_flags[afi][safi], flag);
2373 if (type == flag_change_set_reset)
2374 BGP_EVENT_ADD (peer, BGP_Stop);
2376 else
2378 if (! CHECK_FLAG (peer->af_flags[afi][safi], flag))
2379 return CMD_WARNING;
2381 UNSET_FLAG (peer->af_flags[afi][safi], flag);
2382 if (type == flag_change_unset_reset)
2383 BGP_EVENT_ADD (peer, BGP_Stop);
2386 return CMD_SUCCESS;
2389 /* Change specified peer flag. */
2391 peer_change_flag (struct vty *vty, char *ip_str, int afi, u_int16_t flag,
2392 int set)
2394 struct peer *peer;
2395 struct peer_conf *conf;
2397 conf = peer_conf_lookup_vty (vty, ip_str, afi);
2398 if (! conf)
2399 return CMD_WARNING;
2400 peer = conf->peer;
2402 if (set)
2403 SET_FLAG (peer->flags, flag);
2404 else
2405 UNSET_FLAG (peer->flags, flag);
2406 return CMD_SUCCESS;
2409 /* Change specified peer flag with resetting the connection. If the
2410 flag is not changed nothing occur. */
2412 peer_change_flag_with_reset (struct vty *vty, char *ip_str, int afi,
2413 u_int16_t flag, int set)
2415 struct peer *peer;
2416 struct peer_conf *conf;
2418 conf = peer_conf_lookup_vty (vty, ip_str, afi);
2419 if (! conf)
2420 return CMD_WARNING;
2421 peer = conf->peer;
2423 if (set)
2425 if (! CHECK_FLAG (peer->flags, flag))
2427 SET_FLAG (peer->flags, flag);
2428 BGP_EVENT_ADD (peer, BGP_Stop);
2431 else
2433 if (CHECK_FLAG (peer->flags, flag))
2435 UNSET_FLAG (peer->flags, flag);
2436 BGP_EVENT_ADD (peer, BGP_Stop);
2439 return CMD_SUCCESS;
2442 DEFUN (neighbor_remote_as,
2443 neighbor_remote_as_cmd,
2444 NEIGHBOR_CMD "remote-as <1-65535>",
2445 NEIGHBOR_STR
2446 NEIGHBOR_ADDR_STR
2447 "Specify a BGP neighbor\n"
2448 AS_STR)
2450 return peer_remote_as (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST);
2453 DEFUN (neighbor_remote_as_unicast,
2454 neighbor_remote_as_unicast_cmd,
2455 NEIGHBOR_CMD "remote-as <1-65535> nlri unicast",
2456 NEIGHBOR_STR
2457 NEIGHBOR_ADDR_STR
2458 "Specify a BGP neighbor\n"
2459 AS_STR
2460 "Network Layer Reachable Information\n"
2461 "Configure for unicast routes\n")
2463 return peer_remote_as (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST);
2466 DEFUN (neighbor_remote_as_multicast,
2467 neighbor_remote_as_multicast_cmd,
2468 NEIGHBOR_CMD "remote-as <1-65535> nlri multicast",
2469 NEIGHBOR_STR
2470 NEIGHBOR_ADDR_STR
2471 "Specify a BGP neighbor\n"
2472 AS_STR
2473 "Network Layer Reachable Information\n"
2474 "Configure for multicast routes\n")
2476 return peer_remote_as (vty, argv[0], argv[1], AFI_IP, SAFI_MULTICAST);
2479 DEFUN (neighbor_remote_as_unicast_multicast,
2480 neighbor_remote_as_unicast_multicast_cmd,
2481 NEIGHBOR_CMD "remote-as <1-65535> nlri unicast multicast",
2482 NEIGHBOR_STR
2483 NEIGHBOR_ADDR_STR
2484 "Specify a BGP neighbor\n"
2485 AS_STR
2486 "Network Layer Reachable Information\n"
2487 "Configure for unicast routes\n"
2488 "Configure for multicast routes\n")
2490 return peer_remote_as (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST_MULTICAST);
2493 DEFUN (neighbor_activate,
2494 neighbor_activate_cmd,
2495 NEIGHBOR_CMD "activate",
2496 NEIGHBOR_STR
2497 NEIGHBOR_ADDR_STR
2498 "Enable the Address Family for this Neighbor\n")
2500 return peer_activate (vty, argv[0], bgp_node_afi (vty),
2501 bgp_node_safi (vty));
2504 DEFUN (no_neighbor_activate,
2505 no_neighbor_activate_cmd,
2506 NO_NEIGHBOR_CMD "activate",
2507 NO_STR
2508 NEIGHBOR_STR
2509 NEIGHBOR_ADDR_STR
2510 "Enable the Address Family for this Neighbor\n")
2512 return peer_deactivate (vty, argv[0], bgp_node_afi (vty),
2513 bgp_node_safi (vty));
2516 #ifdef HAVE_IPV6
2517 DEFUN (ipv6_bgp_neighbor_remote_as,
2518 ipv6_bgp_neighbor_remote_as_cmd,
2519 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) remote-as <1-65535>",
2520 IPV6_STR
2521 BGP_STR
2522 NEIGHBOR_STR
2523 "IP address\n"
2524 "IPv6 address\n"
2525 "Specify a BGP neighbor\n"
2526 AS_STR)
2528 return peer_remote_as (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST);
2531 DEFUN (ipv6_bgp_neighbor_remote_as_unicast,
2532 ipv6_bgp_neighbor_remote_as_unicast_cmd,
2533 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) remote-as <1-65535> nlri unicast",
2534 IPV6_STR
2535 BGP_STR
2536 NEIGHBOR_STR
2537 "IP address\n"
2538 "IPv6 address\n"
2539 "Specify a BGP neighbor\n"
2540 AS_STR
2541 "Network Layer Reachable Information\n"
2542 "Configure for unicast routes\n")
2544 return peer_remote_as (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST);
2547 DEFUN (ipv6_bgp_neighbor_remote_as_multicast,
2548 ipv6_bgp_neighbor_remote_as_multicast_cmd,
2549 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) remote-as <1-65535> nlri multicast",
2550 IPV6_STR
2551 BGP_STR
2552 NEIGHBOR_STR
2553 "IP address\n"
2554 "IPv6 address\n"
2555 "Specify a BGP neighbor\n"
2556 AS_STR
2557 "Network Layer Reachable Information\n"
2558 "Configure for multicast routes\n")
2560 return peer_remote_as (vty, argv[0], argv[1], AFI_IP6, SAFI_MULTICAST);
2563 DEFUN (ipv6_bgp_neighbor_remote_as_unicast_multicast,
2564 ipv6_bgp_neighbor_remote_as_unicast_multicast_cmd,
2565 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) remote-as <1-65535> nlri unicast multicast",
2566 IPV6_STR
2567 BGP_STR
2568 NEIGHBOR_STR
2569 "IP address\n"
2570 "IPv6 address\n"
2571 "Specify a BGP neighbor\n"
2572 AS_STR
2573 "Network Layer Reachable Information\n"
2574 "Configure for unicast routes\n"
2575 "Configure for multicast routes\n")
2577 return peer_remote_as (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST_MULTICAST);
2580 #endif /* HAVE_IPV6 */
2582 DEFUN (no_neighbor,
2583 no_neighbor_cmd,
2584 NO_NEIGHBOR_CMD,
2585 NO_STR
2586 NEIGHBOR_STR
2587 NEIGHBOR_ADDR_STR)
2589 return peer_destroy (vty, argv[0], NULL, AFI_IP, SAFI_UNICAST);
2592 DEFUN (no_neighbor_remote_as,
2593 no_neighbor_remote_as_cmd,
2594 NO_NEIGHBOR_CMD "remote-as <1-65535>",
2595 NO_STR
2596 NEIGHBOR_STR
2597 NEIGHBOR_ADDR_STR
2598 "Specify a BGP neighbor\n"
2599 AS_STR)
2601 return peer_destroy (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST);
2604 DEFUN (no_ipv6_bgp_neighbor,
2605 no_ipv6_bgp_neighbor_cmd,
2606 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X)",
2607 NO_STR
2608 IPV6_STR
2609 BGP_STR
2610 NEIGHBOR_STR
2611 "IP Address\n"
2612 "IPv6 Address\n")
2614 return peer_destroy (vty, argv[0], NULL, AFI_IP6, SAFI_UNICAST);
2617 DEFUN (no_ipv6_bgp_neighbor_remote_as,
2618 no_ipv6_bgp_neighbor_remote_as_cmd,
2619 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) remote-as <1-65535>",
2620 NO_STR
2621 IPV6_STR
2622 BGP_STR
2623 NEIGHBOR_STR
2624 "IP Address\n"
2625 "IPv6 Address\n"
2626 "Specify a BGP neighbor\n"
2627 AS_STR)
2629 return peer_destroy (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST);
2632 /* router-id set. */
2634 peer_router_id (struct vty *vty, char *ip_str, int afi, char *id_str)
2636 struct peer *peer;
2637 struct peer_conf *conf;
2638 struct in_addr id;
2639 int ret;
2641 conf = peer_conf_lookup_vty (vty, ip_str, afi);
2642 if (! conf)
2643 return CMD_WARNING;
2645 peer = conf->peer;
2647 if (id_str)
2649 ret = inet_aton (id_str, &id);
2650 if (! ret)
2652 vty_out (vty, "Malformed router identifier: %s%s", id_str,
2653 VTY_NEWLINE);
2654 return CMD_WARNING;
2656 peer->remote_id = id;
2658 else
2660 peer->remote_id.s_addr = 0;
2663 return CMD_SUCCESS;
2666 DEFUN (neighbor_router_id,
2667 neighbor_router_id_cmd,
2668 NEIGHBOR_CMD "router-id A.B.C.D",
2669 NEIGHBOR_STR
2670 NEIGHBOR_ADDR_STR
2671 "Set neighbor's special router-id value\n"
2672 "IP address\n")
2674 return peer_router_id (vty, argv[0], AFI_IP, argv[1]);
2677 DEFUN (no_neighbor_router_id,
2678 no_neighbor_router_id_cmd,
2679 NO_NEIGHBOR_CMD "router-id A.B.C.D",
2680 NO_STR
2681 NEIGHBOR_STR
2682 NEIGHBOR_ADDR_STR
2683 "Set neighbor's special router-id value\n"
2684 "IP address\n")
2686 return peer_router_id (vty, argv[0], AFI_IP, NULL);
2689 /* neighbor passive. */
2690 DEFUN (neighbor_passive,
2691 neighbor_passive_cmd,
2692 NEIGHBOR_CMD "passive",
2693 NEIGHBOR_STR
2694 NEIGHBOR_ADDR_STR
2695 "Don't send open messages to this neighbor\n")
2697 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
2698 PEER_FLAG_PASSIVE, 1);
2701 DEFUN (no_neighbor_passive,
2702 no_neighbor_passive_cmd,
2703 NO_NEIGHBOR_CMD "passive",
2704 NO_STR
2705 NEIGHBOR_STR
2706 NEIGHBOR_ADDR_STR
2707 "Don't send open messages to this neighbor\n")
2709 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
2710 PEER_FLAG_PASSIVE, 0);
2713 DEFUN (ipv6_bgp_neighbor_passive,
2714 ipv6_bgp_neighbor_passive_cmd,
2715 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) passive",
2716 IPV6_STR
2717 BGP_STR
2718 NEIGHBOR_STR
2719 "IP address\n"
2720 "IPv6 address\n"
2721 "Don't send open messages to this neighbor\n")
2723 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
2724 PEER_FLAG_PASSIVE, 1);
2727 DEFUN (no_ipv6_bgp_neighbor_passive,
2728 no_ipv6_bgp_neighbor_passive_cmd,
2729 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) passive",
2730 NO_STR
2731 IPV6_STR
2732 BGP_STR
2733 NEIGHBOR_STR
2734 "IP address\n"
2735 "IPv6 address\n"
2736 "Don't send open messages to this neighbor\n")
2738 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
2739 PEER_FLAG_PASSIVE, 0);
2742 /* neighbor shutdown. */
2743 DEFUN (neighbor_shutdown,
2744 neighbor_shutdown_cmd,
2745 NEIGHBOR_CMD "shutdown",
2746 NEIGHBOR_STR
2747 NEIGHBOR_ADDR_STR
2748 "Administratively shut down this neighbor\n")
2750 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
2751 PEER_FLAG_SHUTDOWN, 1);
2754 DEFUN (no_neighbor_shutdown,
2755 no_neighbor_shutdown_cmd,
2756 NO_NEIGHBOR_CMD "shutdown",
2757 NO_STR
2758 NEIGHBOR_STR
2759 NEIGHBOR_ADDR_STR
2760 "Administratively shut down this neighbor\n")
2762 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
2763 PEER_FLAG_SHUTDOWN, 0);
2766 DEFUN (ipv6_bgp_neighbor_shutdown,
2767 ipv6_bgp_neighbor_shutdown_cmd,
2768 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) shutdown",
2769 IPV6_STR
2770 BGP_STR
2771 NEIGHBOR_STR
2772 "IP address\n"
2773 "IPv6 address\n"
2774 "Administratively shut down this neighbor\n")
2776 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
2777 PEER_FLAG_SHUTDOWN, 1);
2780 DEFUN (no_ipv6_bgp_neighbor_shutdown,
2781 no_ipv6_bgp_neighbor_shutdown_cmd,
2782 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) shutdown",
2783 NO_STR
2784 IPV6_STR
2785 BGP_STR
2786 NEIGHBOR_STR
2787 "IP address\n"
2788 "IPv6 address\n"
2789 "Administratively shut down this neighbor\n")
2791 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
2792 PEER_FLAG_SHUTDOWN, 0);
2795 /* neighbor ebgp-multihop. */
2797 peer_ebgp_multihop_set (struct vty *vty, char *ip_str, char *ttl_str, int afi)
2799 struct peer *peer;
2800 struct peer_conf *conf;
2801 int ttl = TTL_MAX;
2803 conf = peer_conf_lookup_vty (vty, ip_str, afi);
2804 if (! conf)
2805 return CMD_WARNING;
2807 if (ttl_str)
2808 ttl = atoi (ttl_str);
2810 if (ttl == 0)
2812 vty_out (vty, "TTL value error: %s%s", ttl_str, VTY_NEWLINE);
2813 return CMD_WARNING;
2816 peer = conf->peer;
2817 if (peer_sort (peer) == BGP_PEER_IBGP)
2819 vty_out (vty, "peer is IBGP peer%s", VTY_NEWLINE);
2820 return CMD_WARNING;
2823 peer->ttl = ttl;
2825 /* Set runnning connection's ttl. */
2826 if (peer->fd >= 0)
2827 sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl);
2829 return CMD_SUCCESS;
2833 peer_ebgp_multihop_unset (struct vty *vty, char *ip_str, char *ttl_str,
2834 int afi)
2836 struct peer *peer;
2837 struct peer_conf *conf;
2838 int ttl = TTL_MAX;
2840 conf = peer_conf_lookup_vty (vty, ip_str, afi);
2841 if (! conf)
2842 return CMD_WARNING;
2844 if (ttl_str)
2845 ttl = atoi (ttl_str);
2847 if (ttl == 0)
2849 vty_out (vty, "TTL value error: %s%s", ttl_str, VTY_NEWLINE);
2850 return CMD_WARNING;
2853 peer = conf->peer;
2854 if (peer_sort (peer) == BGP_PEER_IBGP)
2856 vty_out (vty, "peer is IBGP peer%s", VTY_NEWLINE);
2857 return CMD_WARNING;
2860 /* Set default EBGP TTL. */
2861 peer->ttl = 1;
2863 /* Set runnning connection's ttl. */
2864 if (peer->fd >= 0)
2865 sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl);
2867 return CMD_SUCCESS;
2870 /* neighbor ebgp-multihop. */
2871 DEFUN (neighbor_ebgp_multihop,
2872 neighbor_ebgp_multihop_cmd,
2873 NEIGHBOR_CMD "ebgp-multihop",
2874 NEIGHBOR_STR
2875 NEIGHBOR_ADDR_STR
2876 "Allow EBGP neighbors not on directly connected networks\n")
2878 return peer_ebgp_multihop_set (vty, argv[0], NULL, AFI_IP);
2881 DEFUN (neighbor_ebgp_multihop_ttl,
2882 neighbor_ebgp_multihop_ttl_cmd,
2883 NEIGHBOR_CMD "ebgp-multihop <1-255>",
2884 NEIGHBOR_STR
2885 NEIGHBOR_ADDR_STR
2886 "Allow EBGP neighbors not on directly connected networks\n"
2887 "maximum hop count\n")
2889 return peer_ebgp_multihop_set (vty, argv[0], argv[1], AFI_IP);
2892 DEFUN (no_neighbor_ebgp_multihop,
2893 no_neighbor_ebgp_multihop_cmd,
2894 NO_NEIGHBOR_CMD "ebgp-multihop",
2895 NO_STR
2896 NEIGHBOR_STR
2897 NEIGHBOR_ADDR_STR
2898 "Allow EBGP neighbors not on directly connected networks\n")
2900 return peer_ebgp_multihop_unset (vty, argv[0], NULL, AFI_IP);
2903 DEFUN (no_neighbor_ebgp_multihop_ttl,
2904 no_neighbor_ebgp_multihop_ttl_cmd,
2905 NO_NEIGHBOR_CMD "ebgp-multihop <1-255>",
2906 NO_STR
2907 NEIGHBOR_STR
2908 NEIGHBOR_ADDR_STR
2909 "Allow EBGP neighbors not on directly connected networks\n"
2910 "maximum hop count\n")
2912 return peer_ebgp_multihop_unset (vty, argv[0], argv[1], AFI_IP);
2915 DEFUN (ipv6_bgp_neighbor_ebgp_multihop,
2916 ipv6_bgp_neighbor_ebgp_multihop_cmd,
2917 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) ebgp-multihop",
2918 IPV6_STR
2919 BGP_STR
2920 NEIGHBOR_STR
2921 "IP address\n"
2922 "IPv6 address\n"
2923 "Allow EBGP neighbors not on directly connected networks\n")
2925 return peer_ebgp_multihop_set (vty, argv[0], NULL, AFI_IP6);
2928 DEFUN (ipv6_bgp_neighbor_ebgp_multihop_ttl,
2929 ipv6_bgp_neighbor_ebgp_multihop_ttl_cmd,
2930 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) ebgp-multihop <1-255>",
2931 IPV6_STR
2932 BGP_STR
2933 NEIGHBOR_STR
2934 "IP address\n"
2935 "IPv6 address\n"
2936 "Allow EBGP neighbors not on directly connected networks\n"
2937 "maximum hop count\n")
2939 return peer_ebgp_multihop_set (vty, argv[0], argv[1], AFI_IP6);
2942 DEFUN (no_ipv6_bgp_neighbor_ebgp_multihop,
2943 no_ipv6_bgp_neighbor_ebgp_multihop_cmd,
2944 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) ebgp-multihop",
2945 NO_STR
2946 IPV6_STR
2947 BGP_STR
2948 NEIGHBOR_STR
2949 "IP address\n"
2950 "IPv6 address\n"
2951 "Allow EBGP neighbors not on directly connected networks\n")
2953 return peer_ebgp_multihop_unset (vty, argv[0], NULL, AFI_IP6);
2956 DEFUN (no_ipv6_bgp_neighbor_ebgp_multihop_ttl,
2957 no_ipv6_bgp_neighbor_ebgp_multihop_ttl_cmd,
2958 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) ebgp-multihop <1-255>",
2959 NO_STR
2960 IPV6_STR
2961 BGP_STR
2962 NEIGHBOR_STR
2963 "IP address\n"
2964 "IPv6 address\n"
2965 "Allow EBGP neighbors not on directly connected networks\n"
2966 "maximum hop count\n")
2968 return peer_ebgp_multihop_unset (vty, argv[0], argv[1], AFI_IP6);
2971 /* neighbor description. */
2973 peer_description_set (struct vty *vty, char *ip_str, int afi, char *str)
2975 struct peer *peer;
2976 struct peer_conf *conf;
2978 conf = peer_conf_lookup_vty (vty, ip_str, afi);
2979 if (! conf)
2980 return CMD_WARNING;
2981 peer = conf->peer;
2983 if (peer->desc)
2984 XFREE (MTYPE_TMP, peer->desc);
2985 peer->desc = str;
2986 return CMD_SUCCESS;
2990 peer_description_unset (struct vty *vty, char *ip_str, int afi)
2992 struct peer *peer;
2993 struct peer_conf *conf;
2995 conf = peer_conf_lookup_vty (vty, ip_str, afi);
2996 if (! conf)
2997 return CMD_WARNING;
2998 peer = conf->peer;
3000 if (peer->desc)
3001 XFREE (MTYPE_TMP, peer->desc);
3002 peer->desc = NULL;
3003 return CMD_SUCCESS;
3006 DEFUN (neighbor_description,
3007 neighbor_description_cmd,
3008 NEIGHBOR_CMD "description .LINE",
3009 NEIGHBOR_STR
3010 NEIGHBOR_ADDR_STR
3011 "Neighbor specific description\n"
3012 "Up to 80 characters describing this neighbor\n")
3014 int i;
3015 struct buffer *b;
3016 char *str;
3018 if (argc == 1)
3019 return CMD_SUCCESS;
3021 /* Make string from buffer. This function should be provided by
3022 buffer.c. */
3023 b = buffer_new (1024);
3024 for (i = 1; i < argc; i++)
3026 buffer_putstr (b, (u_char *)argv[i]);
3027 buffer_putc (b, ' ');
3029 buffer_putc (b, '\0');
3030 str = buffer_getstr (b);
3031 buffer_free (b);
3033 return peer_description_set (vty, argv[0], AFI_IP, str);
3036 DEFUN (no_neighbor_description,
3037 no_neighbor_description_cmd,
3038 NO_NEIGHBOR_CMD "description",
3039 NO_STR
3040 NEIGHBOR_STR
3041 NEIGHBOR_ADDR_STR
3042 "Neighbor specific description\n")
3044 return peer_description_unset (vty, argv[0], AFI_IP);
3047 ALIAS (no_neighbor_description,
3048 no_neighbor_description_val_cmd,
3049 NO_NEIGHBOR_CMD "description .LINE",
3050 NO_STR
3051 NEIGHBOR_STR
3052 NEIGHBOR_ADDR_STR
3053 "Neighbor specific description\n"
3054 "Up to 80 characters describing this neighbor\n")
3056 DEFUN (ipv6_bgp_neighbor_description,
3057 ipv6_bgp_neighbor_description_cmd,
3058 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) description .LINE",
3059 IPV6_STR
3060 BGP_STR
3061 NEIGHBOR_STR
3062 "IP address\n"
3063 "IPv6 address\n"
3064 "Neighbor specific description\n"
3065 "Up to 80 characters describing this neighbor\n")
3067 int i;
3068 struct buffer *b;
3069 char *str;
3071 if (argc == 1)
3072 return CMD_SUCCESS;
3074 b = buffer_new (1024);
3075 for (i = 1; i < argc; i++)
3077 buffer_putstr (b, (u_char *)argv[i]);
3078 buffer_putc (b, ' ');
3080 buffer_putc (b, '\0');
3081 str = buffer_getstr (b);
3082 buffer_free (b);
3084 return peer_description_set (vty, argv[0], AFI_IP6, str);
3087 DEFUN (no_ipv6_bgp_neighbor_description,
3088 no_ipv6_bgp_neighbor_description_cmd,
3089 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) description",
3090 NO_STR
3091 IPV6_STR
3092 BGP_STR
3093 NEIGHBOR_STR
3094 "IP address\n"
3095 "IPv6 address\n"
3096 "Neighbor specific description\n")
3098 return peer_description_unset (vty, argv[0], AFI_IP6);
3101 ALIAS (no_ipv6_bgp_neighbor_description,
3102 no_ipv6_bgp_neighbor_description_val_cmd,
3103 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) description .LINE",
3104 NO_STR
3105 IPV6_STR
3106 BGP_STR
3107 NEIGHBOR_STR
3108 "IP address\n"
3109 "IPv6 address\n"
3110 "Neighbor specific description\n"
3111 "Up to 80 characters describing this neighbor\n")
3113 /* neighbor next-hop-self. */
3114 DEFUN (neighbor_nexthop_self,
3115 neighbor_nexthop_self_cmd,
3116 NEIGHBOR_CMD "next-hop-self",
3117 NEIGHBOR_STR
3118 NEIGHBOR_ADDR_STR
3119 "Disable the next hop calculation for this neighbor\n")
3121 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty),
3122 bgp_node_safi (vty), PEER_FLAG_NEXTHOP_SELF,
3123 flag_change_set);
3126 DEFUN (no_neighbor_nexthop_self,
3127 no_neighbor_nexthop_self_cmd,
3128 NO_NEIGHBOR_CMD "next-hop-self",
3129 NO_STR
3130 NEIGHBOR_STR
3131 NEIGHBOR_ADDR_STR
3132 "Disable the next hop calculation for this neighbor\n")
3134 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty),
3135 bgp_node_safi (vty), PEER_FLAG_NEXTHOP_SELF,
3136 flag_change_unset);
3139 DEFUN (ipv6_bgp_neighbor_nexthop_self,
3140 ipv6_bgp_neighbor_nexthop_self_cmd,
3141 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) next-hop-self",
3142 IPV6_STR
3143 BGP_STR
3144 NEIGHBOR_STR
3145 "IP address\n"
3146 "IPv6 address\n"
3147 "Disable the next hop calculation for this neighbor\n")
3149 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3150 PEER_FLAG_NEXTHOP_SELF, flag_change_set);
3153 DEFUN (no_ipv6_bgp_neighbor_nexthop_self,
3154 no_ipv6_bgp_neighbor_nexthop_self_cmd,
3155 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) next-hop-self",
3156 NO_STR
3157 IPV6_STR
3158 BGP_STR
3159 NEIGHBOR_STR
3160 "IP address\n"
3161 "IPv6 address\n"
3162 "Disable the next hop calculation for this neighbor\n")
3164 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3165 PEER_FLAG_NEXTHOP_SELF, flag_change_unset);
3168 /* neighbor update-source. */
3170 peer_update_source_set (struct vty *vty, char *ip_str, int afi,
3171 char *source_str)
3173 struct peer *peer;
3174 struct peer_conf *conf;
3176 conf = peer_conf_lookup_vty (vty, ip_str, afi);
3177 if (! conf)
3178 return CMD_WARNING;
3179 peer = conf->peer;
3181 if (peer->update_source)
3183 XFREE (MTYPE_SOCKUNION, peer->update_source);
3184 peer->update_source = NULL;
3186 if (peer->update_if)
3188 free (peer->update_if);
3189 peer->update_if = NULL;
3192 peer->update_source = sockunion_str2su (source_str);
3194 if (peer->update_source == NULL)
3195 peer->update_if = strdup (source_str);
3197 return CMD_SUCCESS;
3201 peer_update_source_unset (struct vty *vty, char *ip_str, int afi)
3203 struct peer *peer;
3204 struct peer_conf *conf;
3206 conf = peer_conf_lookup_vty (vty, ip_str, afi);
3207 if (! conf)
3208 return CMD_WARNING;
3209 peer = conf->peer;
3211 if (peer->update_source)
3213 XFREE (MTYPE_SOCKUNION, peer->update_source);
3214 peer->update_source = NULL;
3216 if (peer->update_if)
3218 free (peer->update_if);
3219 peer->update_if = NULL;
3222 return CMD_SUCCESS;
3225 DEFUN (neighbor_update_source,
3226 neighbor_update_source_cmd,
3227 NEIGHBOR_CMD "update-source WORD",
3228 NEIGHBOR_STR
3229 NEIGHBOR_ADDR_STR
3230 "Source of routing updates\n"
3231 "Interface name\n")
3233 return peer_update_source_set (vty, argv[0], AFI_IP, argv[1]);
3236 DEFUN (no_neighbor_update_source,
3237 no_neighbor_update_source_cmd,
3238 NO_NEIGHBOR_CMD "update-source",
3239 NO_STR
3240 NEIGHBOR_STR
3241 NEIGHBOR_ADDR_STR
3242 "Source of routing updates\n"
3243 "Interface name\n")
3245 return peer_update_source_unset (vty, argv[0], AFI_IP);
3248 DEFUN (ipv6_bgp_neighbor_update_source,
3249 ipv6_bgp_neighbor_update_source_cmd,
3250 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) update-source WORD",
3251 IPV6_STR
3252 BGP_STR
3253 NEIGHBOR_STR
3254 "IP address\n"
3255 "IPv6 address\n"
3256 "Source of routing updates\n"
3257 "Interface name\n")
3259 return peer_update_source_set (vty, argv[0], AFI_IP6, argv[1]);
3262 DEFUN (no_ipv6_bgp_neighbor_update_source,
3263 no_ipv6_bgp_neighbor_update_source_cmd,
3264 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) update-source",
3265 NO_STR
3266 IPV6_STR
3267 BGP_STR
3268 NEIGHBOR_STR
3269 "IP address\n"
3270 "IPv6 address\n"
3271 "Source of routing updates\n"
3272 "Interface name\n")
3274 return peer_update_source_unset (vty, argv[0], AFI_IP6);
3277 /* neighbor default-originate. */
3278 DEFUN (neighbor_default_originate,
3279 neighbor_default_originate_cmd,
3280 NEIGHBOR_CMD "default-originate",
3281 NEIGHBOR_STR
3282 NEIGHBOR_ADDR_STR
3283 "Originate default route to this neighbor\n")
3285 return peer_change_flag (vty, argv[0], AFI_IP, PEER_FLAG_DEFAULT_ORIGINATE, 1);
3288 DEFUN (no_neighbor_default_originate,
3289 no_neighbor_default_originate_cmd,
3290 NO_NEIGHBOR_CMD "default-originate",
3291 NO_STR
3292 NEIGHBOR_STR
3293 NEIGHBOR_ADDR_STR
3294 "Originate default route to this neighbor\n")
3296 return peer_change_flag (vty, argv[0], AFI_IP, PEER_FLAG_DEFAULT_ORIGINATE, 0);
3299 DEFUN (ipv6_bgp_neighbor_default_originate,
3300 ipv6_bgp_neighbor_default_originate_cmd,
3301 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) default-originate",
3302 IPV6_STR
3303 BGP_STR
3304 NEIGHBOR_STR
3305 "IP address\n"
3306 "IPv6 address\n"
3307 "Originate default route to this neighbor\n")
3309 return peer_change_flag (vty, argv[0], AFI_IP6, PEER_FLAG_DEFAULT_ORIGINATE, 1);
3312 DEFUN (no_ipv6_bgp_neighbor_default_originate,
3313 no_ipv6_bgp_neighbor_default_originate_cmd,
3314 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) default-originate",
3315 NO_STR
3316 IPV6_STR
3317 BGP_STR
3318 NEIGHBOR_STR
3319 "IP address\n"
3320 "IPv6 address\n"
3321 "Originate default route to this neighbor\n")
3323 return peer_change_flag (vty, argv[0], AFI_IP6, PEER_FLAG_DEFAULT_ORIGINATE, 0);
3326 /* neighbor port. */
3328 peer_port (struct vty *vty, char *ip_str, int afi, char *port_str)
3330 struct peer *peer;
3331 struct peer_conf *conf;
3332 unsigned long port = 0;
3333 char *endptr = NULL;
3334 struct servent *sp;
3336 conf = peer_conf_lookup_vty (vty, ip_str, afi);
3337 if (! conf)
3338 return CMD_WARNING;
3339 peer = conf->peer;
3341 if (port_str == NULL)
3343 sp = getservbyname ("bgp", "tcp");
3344 peer->port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs (sp->s_port);
3346 else
3348 port = strtoul (port_str, &endptr, 10);
3349 if (port == ULONG_MAX || *endptr != '\0')
3351 vty_out (vty, "port value error%s", VTY_NEWLINE);
3352 return CMD_WARNING;
3354 if (port > 65535)
3356 vty_out (vty, "port value error%s", VTY_NEWLINE);
3357 return CMD_WARNING;
3360 /* Set peer port. */
3361 peer->port = port;
3363 return CMD_SUCCESS;
3366 /* Set specified peer's BGP version. */
3367 DEFUN (neighbor_port,
3368 neighbor_port_cmd,
3369 NEIGHBOR_CMD "port <0-65535>",
3370 NEIGHBOR_STR
3371 NEIGHBOR_ADDR_STR
3372 "Neighbor's BGP port\n"
3373 "TCP port number\n")
3375 return peer_port (vty, argv[0], AFI_IP, argv[1]);
3378 DEFUN (no_neighbor_port,
3379 no_neighbor_port_cmd,
3380 NO_NEIGHBOR_CMD "port",
3381 NO_STR
3382 NEIGHBOR_STR
3383 NEIGHBOR_ADDR_STR
3384 "Neighbor's BGP port\n")
3386 return peer_port (vty, argv[0], AFI_IP, NULL);
3389 ALIAS (no_neighbor_port,
3390 no_neighbor_port_val_cmd,
3391 NO_NEIGHBOR_CMD "port <0-65535>",
3392 NO_STR
3393 NEIGHBOR_STR
3394 NEIGHBOR_ADDR_STR
3395 "Neighbor's BGP port\n"
3396 "TCP port number\n")
3398 DEFUN (ipv6_bgp_neighbor_port,
3399 ipv6_bgp_neighbor_port_cmd,
3400 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) port <0-65535>",
3401 IPV6_STR
3402 BGP_STR
3403 NEIGHBOR_STR
3404 "IP address\n"
3405 "IPv6 address\n"
3406 "Neighbor's BGP port\n"
3407 "TCP port number\n")
3409 return peer_port (vty, argv[0], AFI_IP6, argv[1]);
3412 DEFUN (no_ipv6_bgp_neighbor_port,
3413 no_ipv6_bgp_neighbor_port_cmd,
3414 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) port",
3415 NO_STR
3416 IPV6_STR
3417 BGP_STR
3418 NEIGHBOR_STR
3419 "IP address\n"
3420 "IPv6 address\n"
3421 "Neighbor's BGP port\n")
3423 return peer_port (vty, argv[0], AFI_IP6, NULL);
3426 ALIAS (no_ipv6_bgp_neighbor_port,
3427 no_ipv6_bgp_neighbor_port_val_cmd,
3428 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) port <0-65535>",
3429 NO_STR
3430 IPV6_STR
3431 BGP_STR
3432 NEIGHBOR_STR
3433 "IP address\n"
3434 "IPv6 address\n"
3435 "Neighbor's BGP port\n"
3436 "TCP port number\n")
3438 /* neighbor send-community. */
3439 DEFUN (neighbor_send_community,
3440 neighbor_send_community_cmd,
3441 NEIGHBOR_CMD "send-community",
3442 NEIGHBOR_STR
3443 NEIGHBOR_ADDR_STR
3444 "Send Community attribute to this neighbor (default enable)\n")
3446 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3447 PEER_FLAG_SEND_COMMUNITY, flag_change_set);
3450 DEFUN (no_neighbor_send_community,
3451 no_neighbor_send_community_cmd,
3452 NO_NEIGHBOR_CMD "send-community",
3453 NO_STR
3454 NEIGHBOR_STR
3455 NEIGHBOR_ADDR_STR
3456 "Send Community attribute to this neighbor (default enable)\n")
3458 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3459 PEER_FLAG_SEND_COMMUNITY, flag_change_unset);
3462 DEFUN (ipv6_bgp_neighbor_send_community,
3463 ipv6_bgp_neighbor_send_community_cmd,
3464 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) send-community",
3465 IPV6_STR
3466 BGP_STR
3467 NEIGHBOR_STR
3468 "IP address\n"
3469 "IPv6 address\n"
3470 "Send Community attribute to this neighbor (default enable)\n")
3472 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3473 PEER_FLAG_SEND_COMMUNITY, flag_change_set);
3476 DEFUN (no_ipv6_bgp_neighbor_send_community,
3477 no_ipv6_bgp_neighbor_send_community_cmd,
3478 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) send-community",
3479 NO_STR
3480 IPV6_STR
3481 BGP_STR
3482 NEIGHBOR_STR
3483 "IP address\n"
3484 "IPv6 address\n"
3485 "Send Community attribute to this neighbor (default enable)\n")
3487 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3488 PEER_FLAG_SEND_COMMUNITY, flag_change_unset);
3491 /* neighbor send-community extended. */
3492 DEFUN (neighbor_send_community_type,
3493 neighbor_send_community_type_cmd,
3494 NEIGHBOR_CMD "send-community (both|extended|standard)",
3495 NEIGHBOR_STR
3496 NEIGHBOR_ADDR_STR
3497 "Send Community attribute to this neighbor (default enable)\n"
3498 "Send Standard and Extended Community attributes\n"
3499 "Send Extended Community attributes\n"
3500 "Send Standard Community attributes\n")
3502 int ret;
3504 if (strncmp (argv[1], "s", 1) == 0)
3505 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3506 PEER_FLAG_SEND_COMMUNITY, flag_change_set);
3507 if (strncmp (argv[1], "e", 1) == 0)
3508 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3509 PEER_FLAG_SEND_EXT_COMMUNITY, flag_change_set);
3511 ret = peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3512 PEER_FLAG_SEND_COMMUNITY, flag_change_set);
3513 if (ret == CMD_WARNING)
3514 return CMD_WARNING;
3515 ret = peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3516 PEER_FLAG_SEND_EXT_COMMUNITY, flag_change_set);
3517 if (ret == CMD_WARNING)
3518 return CMD_WARNING;
3520 return CMD_SUCCESS;
3523 DEFUN (no_neighbor_send_community_type,
3524 no_neighbor_send_community_type_cmd,
3525 NO_NEIGHBOR_CMD "send-community (both|extended|standard)",
3526 NO_STR
3527 NEIGHBOR_STR
3528 NEIGHBOR_ADDR_STR
3529 "Send Community attribute to this neighbor (default enable)\n"
3530 "Send Standard and Extended Community attributes\n"
3531 "Send Extended Community attributes\n"
3532 "Send Standard Community attributes\n")
3534 int ret;
3536 if (strncmp (argv[1], "s", 1) == 0)
3537 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3538 PEER_FLAG_SEND_COMMUNITY, flag_change_unset);
3539 if (strncmp (argv[1], "e", 1) == 0)
3540 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3541 PEER_FLAG_SEND_EXT_COMMUNITY, flag_change_unset);
3543 ret = peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3544 PEER_FLAG_SEND_COMMUNITY, flag_change_unset);
3545 if (ret == CMD_WARNING)
3546 return CMD_WARNING;
3547 ret = peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3548 PEER_FLAG_SEND_EXT_COMMUNITY, flag_change_unset);
3549 if (ret == CMD_WARNING)
3550 return CMD_WARNING;
3552 return CMD_SUCCESS;
3555 DEFUN (ipv6_bgp_neighbor_send_community_extended,
3556 ipv6_bgp_neighbor_send_community_extended_cmd,
3557 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) send-community extended",
3558 IPV6_STR
3559 BGP_STR
3560 NEIGHBOR_STR
3561 "IP address\n"
3562 "IPv6 address\n"
3563 "Send Community attribute to this neighbor (default enable)\n"
3564 "Extended Community\n")
3566 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3567 PEER_FLAG_SEND_EXT_COMMUNITY, flag_change_set);
3570 DEFUN (no_ipv6_bgp_neighbor_send_community_extended,
3571 no_ipv6_bgp_neighbor_send_community_extended_cmd,
3572 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) send-community extended",
3573 NO_STR
3574 IPV6_STR
3575 BGP_STR
3576 NEIGHBOR_STR
3577 "IP address\n"
3578 "IPv6 address\n"
3579 "Send Community attribute to this neighbor (default enable)\n"
3580 "Extended Community\n")
3582 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3583 PEER_FLAG_SEND_EXT_COMMUNITY, flag_change_unset);
3586 /* neighbor weight. */
3588 peer_weight_set (struct vty *vty, char *ip_str, int afi, char *weight_str)
3590 struct peer *peer;
3591 struct peer_conf *conf;
3592 unsigned long weight;
3593 char *endptr = NULL;
3595 conf = peer_conf_lookup_vty (vty, ip_str, afi);
3596 if (! conf)
3597 return CMD_WARNING;
3598 peer = conf->peer;
3600 weight = strtoul (weight_str, &endptr, 10);
3601 if (weight == ULONG_MAX || *endptr != '\0')
3603 vty_out (vty, "weight value error%s", VTY_NEWLINE);
3604 return CMD_WARNING;
3606 if (weight > 65535)
3608 vty_out (vty, "weight value error%s", VTY_NEWLINE);
3609 return CMD_WARNING;
3612 /* Set weight flag to peer configure. */
3613 peer->weight = weight;
3615 return CMD_SUCCESS;
3619 peer_weight_unset (struct vty *vty, char *ip_str, int afi)
3621 struct peer *peer;
3622 struct peer_conf *conf;
3624 conf = peer_conf_lookup_vty (vty, ip_str, afi);
3625 if (! conf)
3626 return CMD_WARNING;
3627 peer = conf->peer;
3628 peer->weight = 0;
3630 return CMD_SUCCESS;
3633 DEFUN (neighbor_weight,
3634 neighbor_weight_cmd,
3635 NEIGHBOR_CMD "weight <0-65535>",
3636 NEIGHBOR_STR
3637 NEIGHBOR_ADDR_STR
3638 "Set default weight for routes from this neighbor\n"
3639 "default weight\n")
3641 return peer_weight_set (vty, argv[0], AFI_IP, argv[1]);
3644 DEFUN (no_neighbor_weight,
3645 no_neighbor_weight_cmd,
3646 NO_NEIGHBOR_CMD "weight",
3647 NO_STR
3648 NEIGHBOR_STR
3649 NEIGHBOR_ADDR_STR
3650 "Set default weight for routes from this neighbor\n")
3652 return peer_weight_unset (vty, argv[0], AFI_IP);
3655 ALIAS (no_neighbor_weight,
3656 no_neighbor_weight_val_cmd,
3657 NO_NEIGHBOR_CMD "weight <0-65535>",
3658 NO_STR
3659 NEIGHBOR_STR
3660 NEIGHBOR_ADDR_STR
3661 "Set default weight for routes from this neighbor\n"
3662 "default weight\n")
3664 DEFUN (ipv6_bgp_neighbor_weight,
3665 ipv6_bgp_neighbor_weight_cmd,
3666 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) weight <0-65535>",
3667 IPV6_STR
3668 BGP_STR
3669 NEIGHBOR_STR
3670 "IP address\n"
3671 "IPv6 address\n"
3672 "Set default weight for routes from this neighbor\n"
3673 "default weight\n")
3675 return peer_weight_set (vty, argv[0], AFI_IP6, argv[1]);
3678 DEFUN (no_ipv6_bgp_neighbor_weight,
3679 no_ipv6_bgp_neighbor_weight_cmd,
3680 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) weight",
3681 NO_STR
3682 IPV6_STR
3683 BGP_STR
3684 NEIGHBOR_STR
3685 "IP address\n"
3686 "IPv6 address\n"
3687 "Set default weight for routes from this neighbor\n")
3689 return peer_weight_unset (vty, argv[0], AFI_IP6);
3692 ALIAS (no_ipv6_bgp_neighbor_weight,
3693 no_ipv6_bgp_neighbor_weight_val_cmd,
3694 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) weight <0-65535>",
3695 NO_STR
3696 IPV6_STR
3697 BGP_STR
3698 NEIGHBOR_STR
3699 "IP address\n"
3700 "IPv6 address\n"
3701 "Set default weight for routes from this neighbor\n"
3702 "default weight\n")
3704 /* neighbor soft-reconfig. */
3705 DEFUN (neighbor_soft_reconfiguration,
3706 neighbor_soft_reconfiguration_cmd,
3707 NEIGHBOR_CMD "soft-reconfiguration inbound",
3708 NEIGHBOR_STR
3709 NEIGHBOR_ADDR_STR
3710 "Per neighbor soft reconfiguration\n"
3711 "Allow inbound soft reconfiguration for this neighbor\n")
3713 int ret;
3714 struct peer *peer;
3715 struct peer_conf *conf;
3717 conf = peer_conf_lookup_vty (vty, argv[0], bgp_node_afi (vty));
3718 if (! conf)
3719 return CMD_WARNING;
3721 peer = conf->peer;
3723 ret = peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3724 PEER_FLAG_SOFT_RECONFIG, flag_change_set);
3726 if (ret == CMD_SUCCESS)
3728 if (peer->status == Established
3729 && (peer->refresh_nego_old || peer->refresh_nego_new))
3730 bgp_route_refresh_send (peer, bgp_node_afi (vty), bgp_node_safi (vty));
3731 else
3732 BGP_EVENT_ADD (peer, BGP_Stop);
3735 return CMD_SUCCESS;
3738 DEFUN (no_neighbor_soft_reconfiguration,
3739 no_neighbor_soft_reconfiguration_cmd,
3740 NO_NEIGHBOR_CMD "soft-reconfiguration inbound",
3741 NO_STR
3742 NEIGHBOR_STR
3743 NEIGHBOR_ADDR_STR
3744 "Per neighbor soft reconfiguration\n"
3745 "Allow inbound soft reconfiguration for this neighbor\n")
3747 int ret;
3748 struct peer *peer;
3749 struct peer_conf *conf;
3751 conf = peer_conf_lookup_vty (vty, argv[0], bgp_node_afi (vty));
3752 if (! conf)
3753 return CMD_WARNING;
3755 peer = conf->peer;
3757 ret = peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3758 PEER_FLAG_SOFT_RECONFIG, flag_change_unset);
3760 if (ret == CMD_SUCCESS)
3761 bgp_adj_clear (peer->adj_in[bgp_node_afi (vty)][bgp_node_safi (vty)],
3762 bgp_node_safi (vty));
3764 return CMD_SUCCESS;
3767 DEFUN (ipv6_bgp_neighbor_soft_reconfiguration,
3768 ipv6_bgp_neighbor_soft_reconfiguration_cmd,
3769 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) soft-reconfiguration inbound",
3770 IPV6_STR
3771 BGP_STR
3772 NEIGHBOR_STR
3773 "IP address\n"
3774 "IPv6 address\n"
3775 "Per neighbor soft reconfiguration\n"
3776 "Allow inbound soft reconfiguration for this neighbor\n")
3778 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3779 PEER_FLAG_SOFT_RECONFIG, flag_change_set_reset);
3782 DEFUN (no_ipv6_bgp_neighbor_soft_reconfiguration,
3783 no_ipv6_bgp_neighbor_soft_reconfiguration_cmd,
3784 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) soft-reconfiguration inbound",
3785 NO_STR
3786 IPV6_STR
3787 BGP_STR
3788 NEIGHBOR_STR
3789 "IP address\n"
3790 "IPv6 address\n"
3791 "Per neighbor soft reconfiguration\n"
3792 "Allow inbound soft reconfiguration for this neighbor\n")
3794 int ret;
3795 struct peer *peer;
3796 struct peer_conf *conf;
3798 conf = peer_conf_lookup_vty (vty, argv[0], AFI_IP6);
3799 if (! conf)
3800 return CMD_WARNING;
3802 peer = conf->peer;
3804 ret = peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3805 PEER_FLAG_SOFT_RECONFIG, flag_change_unset);
3807 if (ret == CMD_SUCCESS)
3808 bgp_adj_clear (peer->adj_in[AFI_IP6][SAFI_UNICAST],
3809 SAFI_UNICAST);
3811 return CMD_SUCCESS;
3815 DEFUN (neighbor_route_reflector_client,
3816 neighbor_route_reflector_client_cmd,
3817 NEIGHBOR_CMD "route-reflector-client",
3818 NEIGHBOR_STR
3819 NEIGHBOR_ADDR_STR
3820 "Configure a neighbor as Route Reflector client\n")
3822 struct peer *peer;
3823 struct peer_conf *conf;
3825 conf = peer_conf_lookup_vty (vty, argv[0], bgp_node_afi (vty));
3826 if (! conf)
3827 return CMD_WARNING;
3829 peer = conf->peer;
3831 if (peer_sort (peer) != BGP_PEER_IBGP)
3833 vty_out (vty, "%% Invalid command. Not an internal neighbor%s",
3834 VTY_NEWLINE);
3835 return CMD_WARNING;
3838 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3839 PEER_FLAG_REFLECTOR_CLIENT, flag_change_set_reset);
3842 DEFUN (no_neighbor_route_reflector_client,
3843 no_neighbor_route_reflector_client_cmd,
3844 NO_NEIGHBOR_CMD "route-reflector-client",
3845 NO_STR
3846 NEIGHBOR_STR
3847 NEIGHBOR_ADDR_STR
3848 "Configure a neighbor as Route Reflector client\n")
3850 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3851 PEER_FLAG_REFLECTOR_CLIENT, flag_change_unset_reset);
3854 DEFUN (ipv6_bgp_neighbor_route_reflector_client,
3855 ipv6_bgp_neighbor_route_reflector_client_cmd,
3856 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) route-reflector-client",
3857 IPV6_STR
3858 BGP_STR
3859 NEIGHBOR_STR
3860 "IP address\n"
3861 "IPv6 address\n"
3862 "Configure a neighbor as Route Reflector client\n")
3864 struct peer *peer;
3865 struct peer_conf *conf;
3867 conf = peer_conf_lookup_vty (vty, argv[0], bgp_node_afi (vty));
3868 if (! conf)
3869 return CMD_WARNING;
3871 peer = conf->peer;
3873 if (peer_sort (peer) != BGP_PEER_IBGP)
3875 vty_out (vty, "%% Invalid command. Not an internal neighbor%s",
3876 VTY_NEWLINE);
3877 return CMD_WARNING;
3880 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3881 PEER_FLAG_REFLECTOR_CLIENT, flag_change_set_reset);
3884 DEFUN (no_ipv6_bgp_neighbor_route_reflector_client,
3885 no_ipv6_bgp_neighbor_route_reflector_client_cmd,
3886 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) route-reflector-client",
3887 NO_STR
3888 IPV6_STR
3889 BGP_STR
3890 NEIGHBOR_STR
3891 "IP address\n"
3892 "IPv6 address\n"
3893 "Configure a neighbor as Route Reflector client\n")
3895 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3896 PEER_FLAG_REFLECTOR_CLIENT, flag_change_unset_reset);
3899 /* neighbor route-server-client. */
3900 DEFUN (neighbor_route_server_client,
3901 neighbor_route_server_client_cmd,
3902 NEIGHBOR_CMD "route-server-client",
3903 NEIGHBOR_STR
3904 NEIGHBOR_ADDR_STR
3905 "Configure a neighbor as Route Server client\n")
3907 struct peer *peer;
3908 struct peer_conf *conf;
3910 conf = peer_conf_lookup_vty (vty, argv[0], bgp_node_afi (vty));
3911 if (! conf)
3912 return CMD_WARNING;
3914 peer = conf->peer;
3916 if (peer_sort (peer) != BGP_PEER_EBGP)
3918 vty_out (vty, "%% Invalid command. Not an external neighbor%s",
3919 VTY_NEWLINE);
3920 return CMD_WARNING;
3923 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3924 PEER_FLAG_RSERVER_CLIENT, flag_change_set_reset);
3927 DEFUN (no_neighbor_route_server_client,
3928 no_neighbor_route_server_client_cmd,
3929 NO_NEIGHBOR_CMD "route-server-client",
3930 NO_STR
3931 NEIGHBOR_STR
3932 NEIGHBOR_ADDR_STR
3933 "Configure a neighbor as Route Server client\n")
3935 return peer_change_af_flag (vty, argv[0], bgp_node_afi (vty), bgp_node_safi (vty),
3936 PEER_FLAG_RSERVER_CLIENT, flag_change_unset_reset);
3939 DEFUN (ipv6_bgp_neighbor_route_server_client,
3940 ipv6_bgp_neighbor_route_server_client_cmd,
3941 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) route-server-client",
3942 IPV6_STR
3943 BGP_STR
3944 NEIGHBOR_STR
3945 "IP address\n"
3946 "IPv6 address\n"
3947 "Configure a neighbor as Route Server client\n")
3949 struct peer *peer;
3950 struct peer_conf *conf;
3952 conf = peer_conf_lookup_vty (vty, argv[0], AFI_IP6);
3953 if (! conf)
3954 return CMD_WARNING;
3956 peer = conf->peer;
3958 if (peer_sort (peer) != BGP_PEER_EBGP)
3960 vty_out (vty, "%% Invalid command. Not an external neighbor%s",
3961 VTY_NEWLINE);
3962 return CMD_WARNING;
3964 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3965 PEER_FLAG_RSERVER_CLIENT, flag_change_set_reset);
3968 DEFUN (no_ipv6_bgp_neighbor_route_server_client,
3969 no_ipv6_bgp_neighbor_route_server_client_cmd,
3970 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) route-server-client",
3971 NO_STR
3972 IPV6_STR
3973 BGP_STR
3974 NEIGHBOR_STR
3975 "IP address\n"
3976 "IPv6 address\n"
3977 "Configure a neighbor as Route Server client\n")
3979 return peer_change_af_flag (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3980 PEER_FLAG_RSERVER_CLIENT, flag_change_unset_reset);
3983 /* neighbor capability route-refresh. */
3984 DEFUN (neighbor_capability_route_refresh,
3985 neighbor_capability_route_refresh_cmd,
3986 NEIGHBOR_CMD "capability route-refresh",
3987 NEIGHBOR_STR
3988 NEIGHBOR_ADDR_STR
3989 "Outbound capability configuration\n"
3990 "Advertise route-refresh capability to this neighbor\n")
3992 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
3993 PEER_FLAG_CAPABILITY_ROUTE_REFRESH, 1);
3996 DEFUN (no_neighbor_capability_route_refresh,
3997 no_neighbor_capability_route_refresh_cmd,
3998 NO_NEIGHBOR_CMD "capability route-refresh",
3999 NO_STR
4000 NEIGHBOR_STR
4001 NEIGHBOR_ADDR_STR
4002 "Outbound capability configuration\n"
4003 "Advertise route-refresh capability to this neighbor\n")
4005 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
4006 PEER_FLAG_CAPABILITY_ROUTE_REFRESH, 0);
4009 DEFUN (ipv6_bgp_neighbor_capability_route_refresh,
4010 ipv6_bgp_neighbor_capability_route_refresh_cmd,
4011 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) capability route-refresh",
4012 IPV6_STR
4013 BGP_STR
4014 NEIGHBOR_STR
4015 "IP address\n"
4016 "IPv6 address\n"
4017 "Outbound capability configuration\n"
4018 "Advertise route-refresh capability to this neighbor\n")
4020 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
4021 PEER_FLAG_CAPABILITY_ROUTE_REFRESH, 1);
4024 DEFUN (no_ipv6_bgp_neighbor_capability_route_refresh,
4025 no_ipv6_bgp_neighbor_capability_route_refresh_cmd,
4026 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) capability route-refresh",
4027 NO_STR
4028 IPV6_STR
4029 BGP_STR
4030 NEIGHBOR_STR
4031 "IP address\n"
4032 "IPv6 address\n"
4033 "Outbound capability configuration\n"
4034 "Advertise route-refresh capability to this neighbor\n")
4036 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
4037 PEER_FLAG_CAPABILITY_ROUTE_REFRESH, 0);
4040 /* neighbor transparent-as */
4041 DEFUN (neighbor_transparent_as,
4042 neighbor_transparent_as_cmd,
4043 NEIGHBOR_CMD "transparent-as",
4044 NEIGHBOR_STR
4045 NEIGHBOR_ADDR_STR
4046 "Do not append my AS number even peer is EBGP peer\n")
4048 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
4049 PEER_FLAG_TRANSPARENT_AS, 1);
4052 DEFUN (no_neighbor_transparent_as,
4053 no_neighbor_transparent_as_cmd,
4054 NO_NEIGHBOR_CMD "transparent-as",
4055 NO_STR
4056 NEIGHBOR_STR
4057 NEIGHBOR_ADDR_STR
4058 "Do not append my AS number even peer is EBGP peer\n")
4060 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
4061 PEER_FLAG_TRANSPARENT_AS, 0);
4064 DEFUN (ipv6_bgp_neighbor_transparent_as,
4065 ipv6_bgp_neighbor_transparent_as_cmd,
4066 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) transparent-as",
4067 IPV6_STR
4068 BGP_STR
4069 NEIGHBOR_STR
4070 "IP address\n"
4071 "IPv6 address\n"
4072 "Do not append my AS number even peer is EBGP peer\n")
4074 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
4075 PEER_FLAG_TRANSPARENT_AS, 1);
4078 DEFUN (no_ipv6_bgp_neighbor_transparent_as,
4079 no_ipv6_bgp_neighbor_transparent_as_cmd,
4080 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) transparent-as",
4081 NO_STR
4082 IPV6_STR
4083 BGP_STR
4084 NEIGHBOR_STR
4085 "IP address\n"
4086 "IPv6 address\n"
4087 "Do not append my AS number even peer is EBGP peer\n")
4089 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
4090 PEER_FLAG_TRANSPARENT_AS, 0);
4093 /* neighbor transparent-nexthop */
4094 DEFUN (neighbor_transparent_nexthop,
4095 neighbor_transparent_nexthop_cmd,
4096 NEIGHBOR_CMD "transparent-nexthop",
4097 NEIGHBOR_STR
4098 NEIGHBOR_ADDR_STR
4099 "Do not change nexthop even peer is EBGP peer\n")
4101 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
4102 PEER_FLAG_TRANSPARENT_NEXTHOP, 1);
4105 DEFUN (no_neighbor_transparent_nexthop,
4106 no_neighbor_transparent_nexthop_cmd,
4107 NO_NEIGHBOR_CMD "transparent-nexthop",
4108 NO_STR
4109 NEIGHBOR_STR
4110 NEIGHBOR_ADDR_STR
4111 "Do not change nexthop even peer is EBGP peer\n")
4113 return peer_change_flag_with_reset (vty, argv[0], AFI_IP,
4114 PEER_FLAG_TRANSPARENT_NEXTHOP, 0);
4117 DEFUN (ipv6_bgp_neighbor_transparent_nexthop,
4118 ipv6_bgp_neighbor_transparent_nexthop_cmd,
4119 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) transparent-nexthop",
4120 IPV6_STR
4121 BGP_STR
4122 NEIGHBOR_STR
4123 "IP address\n"
4124 "IPv6 address\n"
4125 "Do not change nexthop even peer is EBGP peer\n")
4127 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
4128 PEER_FLAG_TRANSPARENT_NEXTHOP, 1);
4131 DEFUN (no_ipv6_bgp_neighbor_transparent_nexthop,
4132 no_ipv6_bgp_neighbor_transparent_nexthop_cmd,
4133 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) transparent-nexthop",
4134 NO_STR
4135 IPV6_STR
4136 BGP_STR
4137 NEIGHBOR_STR
4138 "IP address\n"
4139 "IPv6 address\n"
4140 "Do not change nexthop even peer is EBGP peer\n")
4142 return peer_change_flag_with_reset (vty, argv[0], AFI_IP6,
4143 PEER_FLAG_TRANSPARENT_NEXTHOP, 0);
4146 /* neighbor translate-update. */
4148 peer_translate_update (struct vty *vty, char *ip_str, int afi, int safi)
4150 struct peer *peer;
4151 struct peer_conf *conf;
4153 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4154 if (! conf)
4155 return CMD_WARNING;
4157 peer = conf->peer;
4158 peer->translate_update = safi;
4159 return CMD_SUCCESS;
4162 DEFUN (neighbor_translate_update_multicast,
4163 neighbor_translate_update_multicast_cmd,
4164 NEIGHBOR_CMD "translate-update nlri multicast",
4165 NEIGHBOR_STR
4166 NEIGHBOR_ADDR_STR
4167 "Translate bgp updates\n"
4168 "Network Layer Reachable Information\n"
4169 "multicast information\n")
4171 return peer_translate_update (vty, argv[0], AFI_IP, SAFI_MULTICAST);
4174 DEFUN (neighbor_translate_update_unimulti,
4175 neighbor_translate_update_unimulti_cmd,
4176 NEIGHBOR_CMD "translate-update nlri unicast multicast",
4177 NEIGHBOR_STR
4178 NEIGHBOR_ADDR_STR
4179 "Translate bgp updates\n"
4180 "Network Layer Reachable Information\n"
4181 "unicast information\n"
4182 "multicast inforamtion\n")
4184 return peer_translate_update (vty, argv[0], AFI_IP, SAFI_UNICAST_MULTICAST);
4187 DEFUN (no_neighbor_translate_update,
4188 no_neighbor_translate_update_cmd,
4189 NO_NEIGHBOR_CMD "translate-update",
4190 NO_STR
4191 NEIGHBOR_STR
4192 NEIGHBOR_ADDR_STR
4193 "Translate bgp updates\n")
4195 return peer_translate_update (vty, argv[0], AFI_IP, 0);
4198 DEFUN (no_neighbor_translate_update_multicast,
4199 no_neighbor_translate_update_multicast_cmd,
4200 NO_NEIGHBOR_CMD "translate-update nlri multicast",
4201 NO_STR
4202 NEIGHBOR_STR
4203 NEIGHBOR_ADDR_STR
4204 "Translate bgp updates\n"
4205 "Network Layer Reachable Information\n"
4206 "multicast information\n")
4208 return peer_translate_update (vty, argv[0], AFI_IP, 0);
4211 DEFUN (no_neighbor_translate_update_unimulti,
4212 no_neighbor_translate_update_unimulti_cmd,
4213 NO_NEIGHBOR_CMD "translate-update nlri unicast multicast",
4214 NO_STR
4215 NEIGHBOR_STR
4216 NEIGHBOR_ADDR_STR
4217 "Translate bgp updates\n"
4218 "Network Layer Reachable Information\n"
4219 "unicast information\n"
4220 "multicast inforamtion\n")
4222 return peer_translate_update (vty, argv[0], AFI_IP, 0);
4225 /* neighbor dont-capability-negotiate */
4226 DEFUN (neighbor_dont_capability_negotiate,
4227 neighbor_dont_capability_negotiate_cmd,
4228 NEIGHBOR_CMD "dont-capability-negotiate",
4229 NEIGHBOR_STR
4230 NEIGHBOR_ADDR_STR
4231 "Do not perform capability negotiation\n")
4233 return peer_change_flag (vty, argv[0], AFI_IP,
4234 PEER_FLAG_DONT_CAPABILITY, 1);
4237 DEFUN (no_neighbor_dont_capability_negotiate,
4238 no_neighbor_dont_capability_negotiate_cmd,
4239 NO_NEIGHBOR_CMD "dont-capability-negotiate",
4240 NO_STR
4241 NEIGHBOR_STR
4242 NEIGHBOR_ADDR_STR
4243 "Do not perform capability negotiation\n")
4245 return peer_change_flag (vty, argv[0], AFI_IP,
4246 PEER_FLAG_DONT_CAPABILITY, 0);
4249 DEFUN (ipv6_neighbor_dont_capability_negotiate,
4250 ipv6_neighbor_dont_capability_negotiate_cmd,
4251 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) dont-capability-negotiate",
4252 IPV6_STR
4253 BGP_STR
4254 NEIGHBOR_STR
4255 "IP address\n"
4256 "IPv6 address\n"
4257 "Do not perform capability negotiation\n")
4259 return peer_change_flag (vty, argv[0], AFI_IP6,
4260 PEER_FLAG_DONT_CAPABILITY, 1);
4263 DEFUN (no_ipv6_neighbor_dont_capability_negotiate,
4264 no_ipv6_neighbor_dont_capability_negotiate_cmd,
4265 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) dont-capability-negotiate",
4266 NO_STR
4267 IPV6_STR
4268 BGP_STR
4269 NEIGHBOR_STR
4270 "IP address\n"
4271 "IPv6 address\n"
4272 "Do not perform capability negotiation\n")
4274 return peer_change_flag (vty, argv[0], AFI_IP6,
4275 PEER_FLAG_DONT_CAPABILITY, 0);
4278 /* Override capability negotiation. */
4280 peer_override_capability (struct vty *vty, char *ip_str, int afi, int set)
4282 struct peer *peer;
4283 struct peer_conf *conf;
4285 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4286 if (! conf)
4287 return CMD_WARNING;
4288 peer = conf->peer;
4290 if (set)
4292 if (CHECK_FLAG (peer->flags, PEER_FLAG_STRICT_CAP_MATCH))
4294 vty_out (vty, "Can't set override-capability and strict-capability-match at the same time%s", VTY_NEWLINE);
4295 return CMD_WARNING;
4297 SET_FLAG (peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY);
4299 else
4300 UNSET_FLAG (peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY);
4301 return CMD_SUCCESS;
4304 /* Override capability negotiation. */
4305 DEFUN (neighbor_override_capability,
4306 neighbor_override_capability_cmd,
4307 NEIGHBOR_CMD "override-capability",
4308 NEIGHBOR_STR
4309 NEIGHBOR_ADDR_STR
4310 "Override capability negotiation result\n")
4312 return peer_override_capability (vty, argv[0], AFI_IP, 1);
4315 DEFUN (no_neighbor_override_capability,
4316 no_neighbor_override_capability_cmd,
4317 NO_NEIGHBOR_CMD "override-capability",
4318 NO_STR
4319 NEIGHBOR_STR
4320 NEIGHBOR_ADDR_STR
4321 "Override capability negotiation result\n")
4323 return peer_override_capability (vty, argv[0], AFI_IP, 0);
4326 DEFUN (ipv6_neighbor_override_capability,
4327 ipv6_neighbor_override_capability_cmd,
4328 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) override-capability",
4329 IPV6_STR
4330 BGP_STR
4331 NEIGHBOR_STR
4332 "IP address\n"
4333 "IPv6 address\n"
4334 "Override capability negotiation result\n")
4336 return peer_override_capability (vty, argv[0], AFI_IP6, 1);
4339 DEFUN (no_ipv6_neighbor_override_capability,
4340 no_ipv6_neighbor_override_capability_cmd,
4341 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) override-capability",
4342 NO_STR
4343 IPV6_STR
4344 BGP_STR
4345 NEIGHBOR_STR
4346 "IP address\n"
4347 "IPv6 address\n"
4348 "Override capability negotiation result\n")
4350 return peer_override_capability (vty, argv[0], AFI_IP6, 0);
4353 /* Strict capability match. */
4355 peer_strict_capability (struct vty *vty, char *ip_str, int afi, int set)
4357 struct peer *peer;
4358 struct peer_conf *conf;
4360 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4361 if (! conf)
4362 return CMD_WARNING;
4363 peer = conf->peer;
4365 if (set)
4367 if (CHECK_FLAG (peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY))
4369 vty_out (vty, "Can't set override-capability and strict-capability-match at the same time%s", VTY_NEWLINE);
4370 return CMD_WARNING;
4372 SET_FLAG (peer->flags, PEER_FLAG_STRICT_CAP_MATCH);
4374 else
4375 UNSET_FLAG (peer->flags, PEER_FLAG_STRICT_CAP_MATCH);
4376 return CMD_SUCCESS;
4379 DEFUN (neighbor_strict_capability,
4380 neighbor_strict_capability_cmd,
4381 NEIGHBOR_CMD "strict-capability-match",
4382 NEIGHBOR_STR
4383 NEIGHBOR_ADDR_STR
4384 "Strict capability negotiation match\n")
4386 return peer_strict_capability (vty, argv[0], AFI_IP, 1);
4389 DEFUN (no_neighbor_strict_capability,
4390 no_neighbor_strict_capability_cmd,
4391 NO_NEIGHBOR_CMD "strict-capability-match",
4392 NO_STR
4393 NEIGHBOR_STR
4394 NEIGHBOR_ADDR_STR
4395 "Strict capability negotiation match\n")
4397 return peer_strict_capability (vty, argv[0], AFI_IP, 0);
4400 DEFUN (ipv6_neighbor_strict_capability,
4401 ipv6_neighbor_strict_capability_cmd,
4402 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) strict-capability-match",
4403 IPV6_STR
4404 BGP_STR
4405 NEIGHBOR_STR
4406 "IP address\n"
4407 "IPv6 address\n"
4408 "Strict capability negotiation match\n")
4410 return peer_strict_capability (vty, argv[0], AFI_IP6, 1);
4413 DEFUN (no_ipv6_neighbor_strict_capability,
4414 no_ipv6_neighbor_strict_capability_cmd,
4415 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) strict-capability-match",
4416 NO_STR
4417 IPV6_STR
4418 BGP_STR
4419 NEIGHBOR_STR
4420 "IP address\n"
4421 "IPv6 address\n"
4422 "Strict capability negotiation match\n")
4424 return peer_strict_capability (vty, argv[0], AFI_IP6, 0);
4428 peer_timers_set (struct vty *vty, char *ip_str, int afi,
4429 char *keep_str, char *hold_str)
4431 struct peer *peer;
4432 struct peer_conf *conf;
4433 unsigned long keepalive;
4434 unsigned long holdtime;
4435 char *endptr = NULL;
4437 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4438 if (! conf)
4439 return CMD_WARNING;
4441 peer = conf->peer;
4443 /* keepalive value check. */
4444 keepalive = strtoul (keep_str, &endptr, 10);
4446 if (keepalive == ULONG_MAX || *endptr != '\0')
4448 vty_out (vty, "%% keepalive time value must be positive integer%s",
4449 VTY_NEWLINE);
4450 return CMD_WARNING;
4452 if (keepalive > 65535)
4454 vty_out (vty, "%% keepalive time value must be <0-65535>%s", VTY_NEWLINE);
4455 return CMD_WARNING;
4458 /* Holdtime value check. */
4459 holdtime = strtoul (hold_str, &endptr, 10);
4461 if (holdtime == ULONG_MAX || *endptr != '\0')
4463 vty_out (vty, "%% hold time value must be positive integer%s", VTY_NEWLINE);
4464 return CMD_WARNING;
4466 if (holdtime > 65535)
4468 vty_out (vty, "%% hold time value must be <0,3-65535>%s", VTY_NEWLINE);
4469 return CMD_WARNING;
4471 if (holdtime < 3 && holdtime != 0)
4473 vty_out (vty, "%% hold time value must be either 0 or greater than 3%s",
4474 VTY_NEWLINE);
4475 return CMD_WARNING;
4478 /* Set value to the configuration. */
4479 peer->config |= PEER_CONFIG_TIMER;
4480 peer->holdtime = holdtime;
4481 peer->keepalive = (keepalive < holdtime / 3 ? keepalive : holdtime / 3);
4483 return CMD_SUCCESS;
4487 peer_timers_unset (struct vty *vty, char *ip_str, int afi)
4489 struct peer *peer;
4490 struct peer_conf *conf;
4492 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4493 if (! conf)
4494 return CMD_WARNING;
4496 peer = conf->peer;
4498 /* Clear configuration. */
4499 peer->config &= ~PEER_CONFIG_TIMER;
4500 peer->keepalive = 0;
4501 peer->holdtime = 0;
4503 return CMD_SUCCESS;
4506 DEFUN (neighbor_timers,
4507 neighbor_timers_cmd,
4508 NEIGHBOR_CMD "timers <0-65535> <0-65535>",
4509 NEIGHBOR_STR
4510 NEIGHBOR_ADDR_STR
4511 "BGP per neighbor timers\n"
4512 "Keepalive interval\n"
4513 "Holdtime\n")
4515 return peer_timers_set (vty, argv[0], AFI_IP, argv[1], argv[2]);
4518 DEFUN (no_neighbor_timers,
4519 no_neighbor_timers_cmd,
4520 NO_NEIGHBOR_CMD "timers",
4521 NO_STR
4522 NEIGHBOR_STR
4523 NEIGHBOR_ADDR_STR
4524 "BGP per neighbor timers\n")
4526 return peer_timers_unset (vty, argv[0], AFI_IP);
4529 DEFUN (ipv6_bgp_neighbor_timers,
4530 ipv6_bgp_neighbor_timers_cmd,
4531 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) timers <0-65535> <0-65535>",
4532 IPV6_STR
4533 BGP_STR
4534 NEIGHBOR_STR
4535 "IP address\n"
4536 "IPv6 address\n"
4537 "BGP per neighbor timers\n"
4538 "Keepalive interval\n"
4539 "Holdtime\n")
4541 return peer_timers_set (vty, argv[0], AFI_IP6, argv[1], argv[2]);
4544 DEFUN (no_ipv6_bgp_neighbor_timers,
4545 no_ipv6_bgp_neighbor_timers_cmd,
4546 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) timers",
4547 NO_STR
4548 IPV6_STR
4549 BGP_STR
4550 NEIGHBOR_STR
4551 "IP address\n"
4552 "IPv6 address\n"
4553 "BGP per neighbor timers\n")
4555 return peer_timers_unset (vty, argv[0], AFI_IP6);
4559 peer_timers_connect_set (struct vty *vty, char *ip_str, int afi,
4560 char *time_str)
4562 struct peer *peer;
4563 struct peer_conf *conf;
4564 unsigned long connect;
4565 char *endptr = NULL;
4567 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4568 if (! conf)
4569 return CMD_WARNING;
4571 peer = conf->peer;
4573 /* Hold time value check. */
4574 connect = strtoul (time_str, &endptr, 10);
4576 if (connect == ULONG_MAX || *endptr != '\0')
4578 vty_out (vty, "connect time value must be positive integer%s",
4579 VTY_NEWLINE);
4580 return CMD_WARNING;
4582 if (connect > 65535)
4584 vty_out (vty, "connect time value must be <0-65535>%s", VTY_NEWLINE);
4585 return CMD_WARNING;
4588 /* Set value to the configuration. */
4589 peer->config |= PEER_CONFIG_CONNECT;
4590 peer->connect = connect;
4592 /* Set value to timer setting. */
4593 peer->v_connect = connect;
4595 return CMD_SUCCESS;
4599 peer_timers_connect_unset (struct vty *vty, char *ip_str, int afi)
4601 struct peer *peer;
4602 struct peer_conf *conf;
4604 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4605 if (! conf)
4606 return CMD_WARNING;
4607 peer = conf->peer;
4609 /* Clear configuration. */
4610 UNSET_FLAG (peer->config, PEER_CONFIG_CONNECT);
4611 peer->connect = 0;
4613 /* Set timer setting to default value. */
4614 peer->v_connect = BGP_DEFAULT_CONNECT_RETRY;
4616 return CMD_SUCCESS;
4619 DEFUN (neighbor_timers_connect,
4620 neighbor_timers_connect_cmd,
4621 NEIGHBOR_CMD "timers connect <0-65535>",
4622 NEIGHBOR_STR
4623 NEIGHBOR_ADDR_STR
4624 "BGP per neighbor timers\n"
4625 "BGP connect timer\n"
4626 "Connect timer\n")
4628 return peer_timers_connect_set (vty, argv[0], AFI_IP, argv[1]);
4631 DEFUN (no_neighbor_timers_connect,
4632 no_neighbor_timers_connect_cmd,
4633 NO_NEIGHBOR_CMD "timers connect [TIMER]",
4634 NO_STR
4635 NEIGHBOR_STR
4636 NEIGHBOR_ADDR_STR
4637 "BGP per neighbor timers\n"
4638 "BGP connect timer\n"
4639 "Connect timer\n")
4641 return peer_timers_connect_unset (vty, argv[0], AFI_IP);
4644 DEFUN (ipv6_bgp_neighbor_timers_connect,
4645 ipv6_bgp_neighbor_timers_connect_cmd,
4646 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) timers connect <0-65535>",
4647 IPV6_STR
4648 BGP_STR
4649 NEIGHBOR_STR
4650 "IP address\n"
4651 "IPv6 address\n"
4652 "BGP per neighbor timers\n"
4653 "BGP connect timer\n"
4654 "Connect timer\n")
4656 return peer_timers_connect_set (vty, argv[0], AFI_IP6, argv[1]);
4659 DEFUN (no_ipv6_bgp_neighbor_timers_connect,
4660 no_ipv6_bgp_neighbor_timers_connect_cmd,
4661 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) timers connect [TIMER]",
4662 NO_STR
4663 IPV6_STR
4664 BGP_STR
4665 NEIGHBOR_STR
4666 "IP address\n"
4667 "IPv6 address\n"
4668 "BGP per neighbor timers\n"
4669 "BGP connect timer\n"
4670 "Connect timer\n")
4672 return peer_timers_connect_unset (vty, argv[0], AFI_IP6);
4676 peer_version (struct vty *vty, char *ip_str, int afi, char *str)
4678 struct peer *peer;
4679 struct peer_conf *conf;
4681 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4682 if (! conf)
4683 return CMD_WARNING;
4684 peer = conf->peer;
4686 /* BGP version string check. */
4687 if (str)
4689 if (strcmp (str, "4") == 0)
4690 peer->version = BGP_VERSION_4;
4691 else if (strcmp (str, "4-") == 0)
4692 peer->version = BGP_VERSION_MP_4_DRAFT_00;
4693 else
4694 vty_out (vty, "BGP version malformed!%s", VTY_NEWLINE);
4696 else
4697 peer->version = BGP_VERSION_4;
4699 return CMD_SUCCESS;
4702 DEFUN (neighbor_version,
4703 neighbor_version_cmd,
4704 NEIGHBOR_CMD "version (4|4-)",
4705 NEIGHBOR_STR
4706 NEIGHBOR_ADDR_STR
4707 "Neighbor's BGP version\n"
4708 "Border Gateway Protocol 4\n"
4709 "Multiprotocol Extensions for BGP-4(Old Draft)\n")
4711 return peer_version (vty, argv[0], AFI_IP, argv[1]);
4714 DEFUN (no_neighbor_version,
4715 no_neighbor_version_cmd,
4716 NO_NEIGHBOR_CMD "version",
4717 NO_STR
4718 NEIGHBOR_STR
4719 NEIGHBOR_ADDR_STR
4720 "Neighbor's BGP version\n")
4722 return peer_version (vty, argv[0], AFI_IP, NULL);
4725 DEFUN (ipv6_bgp_neighbor_version,
4726 ipv6_bgp_neighbor_version_cmd,
4727 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) version (4|4-)",
4728 IPV6_STR
4729 BGP_STR
4730 NEIGHBOR_STR
4731 "IP address\n"
4732 "IPv6 address\n"
4733 "Neighbor's BGP version\n"
4734 "Border Gateway Protocol 4\n"
4735 "Multiprotocol Extensions for BGP-4(Old Draft)\n")
4737 return peer_version (vty, argv[0], AFI_IP6, argv[1]);
4740 DEFUN (no_ipv6_bgp_neighbor_version,
4741 no_ipv6_bgp_neighbor_version_cmd,
4742 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) version",
4743 NO_STR
4744 IPV6_STR
4745 BGP_STR
4746 NEIGHBOR_STR
4747 "IP address\n"
4748 "IPv6 address\n"
4749 "Neighbor's BGP version\n")
4751 return peer_version (vty, argv[0], AFI_IP6, NULL);
4754 /* neighbor interface */
4756 peer_interface (struct vty *vty, char *ip_str, int afi, char *str)
4758 struct peer *peer;
4759 struct peer_conf *conf;
4761 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4762 if (! conf)
4763 return CMD_WARNING;
4764 peer = conf->peer;
4766 if (str)
4768 if (peer->ifname)
4769 free (peer->ifname);
4770 peer->ifname = strdup (str);
4772 else
4774 if (peer->ifname)
4775 free (peer->ifname);
4776 peer->ifname = NULL;
4778 return CMD_SUCCESS;
4781 DEFUN (neighbor_interface,
4782 neighbor_interface_cmd,
4783 NEIGHBOR_CMD "interface WORD",
4784 NEIGHBOR_STR
4785 NEIGHBOR_ADDR_STR
4786 "Interface\n"
4787 "Interface name\n")
4789 return peer_interface (vty, argv[0], AFI_IP, argv[1]);
4792 DEFUN (no_neighbor_interface,
4793 no_neighbor_interface_cmd,
4794 NO_NEIGHBOR_CMD "interface WORD",
4795 NO_STR
4796 NEIGHBOR_STR
4797 NEIGHBOR_ADDR_STR
4798 "Interface\n"
4799 "Interface name\n")
4801 return peer_interface (vty, argv[0], AFI_IP, NULL);
4804 DEFUN (ipv6_bgp_neighbor_interface,
4805 ipv6_bgp_neighbor_interface_cmd,
4806 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) interface WORD",
4807 IPV6_STR
4808 BGP_STR
4809 NEIGHBOR_STR
4810 "IP address\n"
4811 "IPv6 address\n"
4812 "Interface\n"
4813 "Interface name\n")
4815 return peer_interface (vty, argv[0], AFI_IP6, argv[1]);
4818 DEFUN (no_ipv6_bgp_neighbor_interface,
4819 no_ipv6_bgp_neighbor_interface_cmd,
4820 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) interface WORD",
4821 NO_STR
4822 IPV6_STR
4823 BGP_STR
4824 NEIGHBOR_STR
4825 "IP address\n"
4826 "IPv6 address\n"
4827 "Interface\n"
4828 "Interface name\n")
4830 return peer_interface (vty, argv[0], AFI_IP6, NULL);
4833 /* Set distribute list to the peer. */
4834 static int
4835 bgp_distribute_set (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
4836 char *name_str, char *direct_str)
4838 struct peer_conf *conf;
4839 struct bgp_filter *filter;
4840 int direct;
4842 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4843 if (! conf)
4844 return CMD_WARNING;
4845 if (! conf->afc[afi][safi])
4847 vty_out (vty, "%% Activate the neighbor for the address family first%s",
4848 VTY_NEWLINE);
4849 return CMD_WARNING;
4852 /* Check filter direction. */
4853 if (strncmp (direct_str, "i", 1) == 0)
4854 direct = FILTER_IN;
4855 else if (strncmp (direct_str, "o", 1) == 0)
4856 direct = FILTER_OUT;
4857 else
4859 vty_out (vty, "filter direction must be [in|out]%s", VTY_NEWLINE);
4860 return CMD_WARNING;
4863 filter = &conf->filter[afi][safi];
4865 if (filter->dlist[direct].name)
4866 free (filter->dlist[direct].name);
4868 filter->dlist[direct].name = strdup (name_str);
4869 filter->dlist[direct].alist = access_list_lookup (afi, name_str);
4871 return CMD_SUCCESS;
4874 static int
4875 bgp_distribute_unset (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
4876 char *name_str, char *direct_str)
4878 struct peer_conf *conf;
4879 struct bgp_filter *filter;
4880 int direct;
4882 conf = peer_conf_lookup_vty (vty, ip_str, afi);
4883 if (! conf)
4884 return CMD_WARNING;
4885 if (! conf->afc[afi][safi])
4887 vty_out (vty, "%% Activate the neighbor for the address family first%s",
4888 VTY_NEWLINE);
4889 return CMD_WARNING;
4892 /* Check filter direction. */
4893 if (strncmp (direct_str, "i", 1) == 0)
4894 direct = FILTER_IN;
4895 else if (strncmp (direct_str, "o", 1) == 0)
4896 direct = FILTER_OUT;
4897 else
4899 vty_out (vty, "distribute direction must be [in|out]%s", VTY_NEWLINE);
4900 return CMD_WARNING;
4903 filter = &conf->filter[afi][safi];
4905 if (! filter->dlist[direct].name)
4907 vty_out (vty, "%% There is no such filter: %s%s", name_str, VTY_NEWLINE);
4908 return CMD_WARNING;
4910 if (strcmp (filter->dlist[direct].name, name_str) != 0)
4912 vty_out (vty, "%% There is no such filter: %s%s", name_str, VTY_NEWLINE);
4913 return CMD_WARNING;
4915 free (filter->dlist[direct].name);
4916 filter->dlist[direct].name = NULL;
4917 filter->dlist[direct].alist = NULL;
4919 return CMD_SUCCESS;
4922 /* Update distribute list. */
4923 void
4924 bgp_distribute_update (struct access_list *access)
4926 afi_t afi;
4927 safi_t safi;
4928 int direct;
4929 struct listnode *nn, *nm;
4930 struct bgp *bgp;
4931 struct peer_conf *conf;
4932 struct bgp_filter *filter;
4934 LIST_LOOP (bgp_list, bgp, nn)
4936 LIST_LOOP (bgp->peer_conf, conf, nm)
4938 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4939 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4941 filter = &conf->filter[afi][safi];
4943 for (direct = FILTER_IN; direct < FILTER_MAX; direct++)
4945 if (filter->dlist[direct].name)
4946 filter->dlist[direct].alist =
4947 access_list_lookup (afi, filter->dlist[direct].name);
4948 else
4949 filter->dlist[direct].alist = NULL;
4956 DEFUN (neighbor_distribute_list,
4957 neighbor_distribute_list_cmd,
4958 NEIGHBOR_CMD "distribute-list WORD (in|out)",
4959 NEIGHBOR_STR
4960 NEIGHBOR_ADDR_STR
4961 "Filter updates to/from this neighbor\n"
4962 "IP Access-list name\n"
4963 "Filter incoming updates\n"
4964 "Filter outgoing updates\n")
4966 return bgp_distribute_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4967 argv[1], argv[2]);
4970 DEFUN (no_neighbor_distribute_list,
4971 no_neighbor_distribute_list_cmd,
4972 NO_NEIGHBOR_CMD "distribute-list WORD (in|out)",
4973 NO_STR
4974 NEIGHBOR_STR
4975 NEIGHBOR_ADDR_STR
4976 "Filter updates to/from this neighbor\n"
4977 "IP Access-list name\n"
4978 "Filter incoming updates\n"
4979 "Filter outgoing updates\n")
4981 return bgp_distribute_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4982 argv[1], argv[2]);
4985 DEFUN (ipv6_bgp_neighbor_distribute_list,
4986 ipv6_bgp_neighbor_distribute_list_cmd,
4987 NEIGHBOR_CMD "distribute-list WORD (in|out)",
4988 NEIGHBOR_STR
4989 NEIGHBOR_ADDR_STR
4990 "Filter updates to/from this neighbor\n"
4991 "IPv6 Access-list name\n"
4992 "Filter incoming updates\n"
4993 "Filter outgoing updates\n")
4995 return bgp_distribute_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4996 argv[1], argv[2]);
4999 DEFUN (no_ipv6_bgp_neighbor_distribute_list,
5000 no_ipv6_bgp_neighbor_distribute_list_cmd,
5001 NO_NEIGHBOR_CMD "distribute-list WORD (in|out)",
5002 NO_STR
5003 NEIGHBOR_STR
5004 NEIGHBOR_ADDR_STR
5005 "Filter updates to/from this neighbor\n"
5006 "IPv6 Access-list name\n"
5007 "Filter incoming updates\n"
5008 "Filter outgoing updates\n")
5010 return bgp_distribute_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5011 argv[1], argv[2]);
5014 ALIAS (ipv6_bgp_neighbor_distribute_list,
5015 old_ipv6_bgp_neighbor_distribute_list_cmd,
5016 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) distribute-list WORD (in|out)",
5017 IPV6_STR
5018 BGP_STR
5019 NEIGHBOR_STR
5020 "IP address\n"
5021 "IPv6 address\n"
5022 "Filter updates to/from this neighbor\n"
5023 "IPv6 Access-list name\n"
5024 "Filter incoming updates\n"
5025 "Filter outgoing updates\n")
5027 ALIAS (no_ipv6_bgp_neighbor_distribute_list,
5028 old_no_ipv6_bgp_neighbor_distribute_list_cmd,
5029 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) distribute-list WORD (in|out)",
5030 NO_STR
5031 IPV6_STR
5032 BGP_STR
5033 NEIGHBOR_STR
5034 "IP address\n"
5035 "IPv6 address\n"
5036 "Filter updates to/from this neighbor\n"
5037 "IPv6 Access-list name\n"
5038 "Filter incoming updates\n"
5039 "Filter outgoing updates\n")
5041 /* Set prefix list to the peer. */
5042 static int
5043 bgp_prefix_list_set (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
5044 char *name_str, char *direct_str)
5046 struct peer_conf *conf;
5047 int direct;
5048 struct bgp_filter *filter;
5050 conf = peer_conf_lookup_vty (vty, ip_str, afi);
5051 if (! conf)
5052 return CMD_WARNING;
5053 if (! conf->afc[afi][safi])
5055 vty_out (vty, "%% Activate the neighbor for the address family first%s",
5056 VTY_NEWLINE);
5057 return CMD_WARNING;
5060 /* Check filter direction. */
5061 if (strncmp (direct_str, "i", 1) == 0)
5062 direct = FILTER_IN;
5063 else if (strncmp (direct_str, "o", 1) == 0)
5064 direct = FILTER_OUT;
5065 else
5067 vty_out (vty, "vty, filter direction must be [in|out]%s", VTY_NEWLINE);
5068 return CMD_WARNING;
5071 filter = &conf->filter[afi][safi];
5073 if (filter->plist[direct].name)
5074 free (filter->plist[direct].name);
5075 filter->plist[direct].name = strdup (name_str);
5076 filter->plist[direct].plist = prefix_list_lookup (afi, name_str);
5078 return CMD_SUCCESS;
5081 static int
5082 bgp_prefix_list_unset (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
5083 char *name_str, char *direct_str)
5085 struct peer_conf *conf;
5086 int direct;
5087 struct bgp_filter *filter;
5089 conf = peer_conf_lookup_vty (vty, ip_str, afi);
5090 if (! conf)
5091 return CMD_WARNING;
5093 /* Check filter direction. */
5094 if (strncmp (direct_str, "i", 1) == 0)
5095 direct = FILTER_IN;
5096 else if (strncmp (direct_str, "o", 1) == 0)
5097 direct = FILTER_OUT;
5098 else
5100 vty_out (vty, "filter direction must be [in|out]%s", VTY_NEWLINE);
5101 return CMD_WARNING;
5104 filter = &conf->filter[afi][safi];
5106 if (! filter->plist[direct].name)
5108 vty_out (vty, "There is no such filter: %s%s", name_str, VTY_NEWLINE);
5109 return CMD_WARNING;
5111 if (strcmp (filter->plist[direct].name, name_str) != 0)
5113 vty_out (vty, "There is no such filter: %s%s", name_str, VTY_NEWLINE);
5114 return CMD_WARNING;
5116 free (filter->plist[direct].name);
5117 filter->plist[direct].name = NULL;
5118 filter->plist[direct].plist = NULL;
5120 return CMD_SUCCESS;
5123 /* Update prefix-list list. */
5124 void
5125 bgp_prefix_list_update ()
5127 struct listnode *nn, *nm;
5128 struct bgp *bgp;
5129 struct peer_conf *conf;
5130 struct bgp_filter *filter;
5131 afi_t afi;
5132 safi_t safi;
5133 int direct;
5135 LIST_LOOP (bgp_list, bgp, nn)
5137 LIST_LOOP (bgp->peer_conf, conf, nm)
5139 for (afi = AFI_IP; afi < AFI_MAX; afi++)
5140 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
5142 filter = &conf->filter[afi][safi];
5144 for (direct = FILTER_IN; direct < FILTER_MAX; direct++)
5146 if (filter->plist[direct].name)
5147 filter->plist[direct].plist =
5148 prefix_list_lookup (afi, filter->plist[direct].name);
5149 else
5150 filter->plist[direct].plist = NULL;
5157 DEFUN (neighbor_prefix_list,
5158 neighbor_prefix_list_cmd,
5159 NEIGHBOR_CMD "prefix-list WORD (in|out)",
5160 NEIGHBOR_STR
5161 NEIGHBOR_ADDR_STR
5162 "Filter updates to/from this neighbor\n"
5163 "Name of a prefix list\n"
5164 "Filter incoming updates\n"
5165 "Filter outgoing updates\n")
5167 return bgp_prefix_list_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5168 argv[1], argv[2]);
5171 DEFUN (no_neighbor_prefix_list,
5172 no_neighbor_prefix_list_cmd,
5173 NO_NEIGHBOR_CMD "prefix-list WORD (in|out)",
5174 NO_STR
5175 NEIGHBOR_STR
5176 NEIGHBOR_ADDR_STR
5177 "Filter updates to/from this neighbor\n"
5178 "Name of a prefix list\n"
5179 "Filter incoming updates\n"
5180 "Filter outgoing updates\n")
5182 return bgp_prefix_list_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5183 argv[1], argv[2]);
5186 DEFUN (ipv6_bgp_neighbor_prefix_list,
5187 ipv6_bgp_neighbor_prefix_list_cmd,
5188 NEIGHBOR_CMD "prefix-list WORD (in|out)",
5189 NEIGHBOR_STR
5190 NEIGHBOR_ADDR_STR
5191 "Filter updates to/from this neighbor\n"
5192 "Name of a prefix list\n"
5193 "Filter incoming updates\n"
5194 "Filter outgoing updates\n")
5196 return bgp_prefix_list_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5197 argv[1], argv[2]);
5200 DEFUN (no_ipv6_bgp_neighbor_prefix_list,
5201 no_ipv6_bgp_neighbor_prefix_list_cmd,
5202 NO_NEIGHBOR_CMD "prefix-list WORD (in|out)",
5203 NO_STR
5204 NEIGHBOR_STR
5205 NEIGHBOR_ADDR_STR
5206 "Filter updates to/from this neighbor\n"
5207 "Name of a prefix list\n"
5208 "Filter incoming updates\n"
5209 "Filter outgoing updates\n")
5211 return bgp_prefix_list_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5212 argv[1], argv[2]);
5215 ALIAS (ipv6_bgp_neighbor_prefix_list,
5216 old_ipv6_bgp_neighbor_prefix_list_cmd,
5217 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) prefix-list WORD (in|out)",
5218 IPV6_STR
5219 BGP_STR
5220 NEIGHBOR_STR
5221 "IP address\n"
5222 "IPv6 address\n"
5223 "Filter updates to/from this neighbor\n"
5224 "Name of a prefix list\n"
5225 "Filter incoming updates\n"
5226 "Filter outgoing updates\n")
5228 ALIAS (no_ipv6_bgp_neighbor_prefix_list,
5229 old_no_ipv6_bgp_neighbor_prefix_list_cmd,
5230 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) prefix-list WORD (in|out)",
5231 NO_STR
5232 IPV6_STR
5233 BGP_STR
5234 NEIGHBOR_STR
5235 "IP address\n"
5236 "IPv6 address\n"
5237 "Filter updates to/from this neighbor\n"
5238 "Name of a prefix list\n"
5239 "Filter incoming updates\n"
5240 "Filter outgoing updates\n")
5242 static int
5243 bgp_aslist_set (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
5244 char *name_str, char *direct_str)
5246 struct as_list *as_list_lookup (char *name);
5247 struct peer_conf *conf;
5248 int direct;
5249 struct bgp_filter *filter;
5251 conf = peer_conf_lookup_vty (vty, ip_str, afi);
5252 if (! conf)
5253 return CMD_WARNING;
5254 if (! conf->afc[afi][safi])
5256 vty_out (vty, "%% Activate the neighbor for the address family first%s",
5257 VTY_NEWLINE);
5258 return CMD_WARNING;
5261 /* Check filter direction. */
5262 if (strncmp (direct_str, "i", 1) == 0)
5263 direct = FILTER_IN;
5264 else if (strncmp (direct_str, "o", 1) == 0)
5265 direct = FILTER_OUT;
5266 else
5268 vty_out (vty, "filter direction must be [in|out]%s", VTY_NEWLINE);
5269 return CMD_WARNING;
5272 filter = &conf->filter[afi][safi];
5274 if (filter->aslist[direct].name)
5275 free (filter->aslist[direct].name);
5277 filter->aslist[direct].name = strdup (name_str);
5278 filter->aslist[direct].aslist = as_list_lookup (name_str);
5280 return CMD_SUCCESS;
5283 static int
5284 bgp_aslist_unset (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
5285 char *name_str, char *direct_str)
5287 struct peer_conf *conf;
5288 int direct;
5289 struct bgp_filter *filter;
5291 conf = peer_conf_lookup_vty (vty, ip_str, afi);
5292 if (! conf)
5293 return CMD_WARNING;
5294 if (! conf->afc[afi][safi])
5296 vty_out (vty, "%% Activate the neighbor for the address family first%s",
5297 VTY_NEWLINE);
5298 return CMD_WARNING;
5301 /* Check filter direction. */
5302 if (strncmp (direct_str, "i", 1) == 0)
5303 direct = FILTER_IN;
5304 else if (strncmp (direct_str, "o", 1) == 0)
5305 direct = FILTER_OUT;
5306 else
5308 vty_out (vty, "filter direction must be [in|out]%s", VTY_NEWLINE);
5309 return CMD_WARNING;
5312 filter = &conf->filter[afi][safi];
5314 if (! filter->aslist[direct].name)
5316 vty_out (vty, "There is no such filter: %s%s", name_str, VTY_NEWLINE);
5317 return CMD_WARNING;
5319 if (strcmp (filter->aslist[direct].name, name_str) != 0)
5321 vty_out (vty, "There is no such filter: %s%s", name_str, VTY_NEWLINE);
5322 return CMD_WARNING;
5324 free (filter->aslist[direct].name);
5325 filter->aslist[direct].name = NULL;
5326 filter->aslist[direct].aslist = NULL;
5328 return CMD_SUCCESS;
5331 void
5332 bgp_aslist_update ()
5334 afi_t afi;
5335 safi_t safi;
5336 int direct;
5337 struct listnode *nn, *nm;
5338 struct bgp *bgp;
5339 struct peer_conf *conf;
5340 struct bgp_filter *filter;
5342 LIST_LOOP (bgp_list, bgp, nn)
5344 LIST_LOOP (bgp->peer_conf, conf, nm)
5346 for (afi = AFI_IP; afi < AFI_MAX; afi++)
5347 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
5349 filter = &conf->filter[afi][safi];
5351 for (direct = FILTER_IN; direct < FILTER_MAX; direct++)
5353 if (filter->aslist[direct].name)
5354 filter->aslist[direct].aslist =
5355 as_list_lookup (filter->aslist[direct].name);
5356 else
5357 filter->aslist[direct].aslist = NULL;
5364 DEFUN (neighbor_filter_list,
5365 neighbor_filter_list_cmd,
5366 NEIGHBOR_CMD "filter-list WORD (in|out)",
5367 NEIGHBOR_STR
5368 NEIGHBOR_ADDR_STR
5369 "Establish BGP filters\n"
5370 "AS path access-list name\n"
5371 "Filter incoming routes\n"
5372 "Filter outgoing routes\n")
5374 return bgp_aslist_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5375 argv[1], argv[2]);
5378 DEFUN (no_neighbor_filter_list,
5379 no_neighbor_filter_list_cmd,
5380 NO_NEIGHBOR_CMD "filter-list WORD (in|out)",
5381 NO_STR
5382 NEIGHBOR_STR
5383 NEIGHBOR_ADDR_STR
5384 "Establish BGP filters\n"
5385 "AS path access-list name\n"
5386 "Filter incoming routes\n"
5387 "Filter outgoing routes\n")
5389 return bgp_aslist_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5390 argv[1], argv[2]);
5393 DEFUN (ipv6_bgp_neighbor_filter_list,
5394 ipv6_bgp_neighbor_filter_list_cmd,
5395 NEIGHBOR_CMD "filter-list WORD (in|out)",
5396 NEIGHBOR_STR
5397 NEIGHBOR_ADDR_STR
5398 "Establish BGP filters\n"
5399 "AS path access-list name\n"
5400 "Filter incoming routes\n"
5401 "Filter outgoing routes\n")
5403 return bgp_aslist_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, argv[1], argv[2]);
5406 DEFUN (no_ipv6_bgp_neighbor_filter_list,
5407 no_ipv6_bgp_neighbor_filter_list_cmd,
5408 NO_NEIGHBOR_CMD "filter-list WORD (in|out)",
5409 NO_STR
5410 NEIGHBOR_STR
5411 NEIGHBOR_ADDR_STR
5412 "Establish BGP filters\n"
5413 "AS path access-list name\n"
5414 "Filter incoming routes\n"
5415 "Filter outgoing routes\n")
5417 return bgp_aslist_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST, argv[1], argv[2]);
5420 ALIAS (ipv6_bgp_neighbor_filter_list,
5421 old_ipv6_bgp_neighbor_filter_list_cmd,
5422 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) filter-list WORD (in|out)",
5423 IPV6_STR
5424 BGP_STR
5425 NEIGHBOR_STR
5426 "IP address\n"
5427 "IPv6 address\n"
5428 "Establish BGP filters\n"
5429 "AS path access-list name\n"
5430 "Filter incoming routes\n"
5431 "Filter outgoing routes\n")
5433 ALIAS (no_ipv6_bgp_neighbor_filter_list,
5434 old_no_ipv6_bgp_neighbor_filter_list_cmd,
5435 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) filter-list WORD (in|out)",
5436 NO_STR
5437 IPV6_STR
5438 BGP_STR
5439 NEIGHBOR_STR
5440 "IP address\n"
5441 "IPv6 address\n"
5442 "Establish BGP filters\n"
5443 "AS path access-list name\n"
5444 "Filter incoming routes\n"
5445 "Filter outgoing routes\n")
5447 /* Set route-map to the peer. */
5448 static int
5449 bgp_route_map_set (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
5450 char *name_str, char *direct_str)
5452 struct peer_conf *conf;
5453 int direct;
5454 struct bgp_filter *filter;
5456 conf = peer_conf_lookup_vty (vty, ip_str, afi);
5457 if (! conf)
5458 return CMD_WARNING;
5459 if (! conf->afc[afi][safi])
5461 vty_out (vty, "%% Activate the neighbor for the address family first%s",
5462 VTY_NEWLINE);
5463 return CMD_WARNING;
5466 /* Check filter direction. */
5467 if (strncmp (direct_str, "i", 1) == 0)
5468 direct = FILTER_IN;
5469 else if (strncmp (direct_str, "o", 1) == 0)
5470 direct = FILTER_OUT;
5471 else
5473 vty_out (vty, "filter direction must be [in|out]%s", VTY_NEWLINE);
5474 return CMD_WARNING;
5477 filter = &conf->filter[afi][safi];
5479 if (filter->map[direct].name)
5480 free (filter->map[direct].name);
5482 filter->map[direct].name = strdup (name_str);
5483 filter->map[direct].map = route_map_lookup_by_name (name_str);
5485 return CMD_SUCCESS;
5488 /* Unset route-map from the peer. */
5489 static int
5490 bgp_route_map_unset (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
5491 char *name_str, char *direct_str)
5493 struct peer_conf *conf;
5494 int direct;
5495 struct bgp_filter *filter;
5497 conf = peer_conf_lookup_vty (vty, ip_str, afi);
5498 if (! conf)
5499 return CMD_WARNING;
5500 if (! conf->afc[afi][safi])
5502 vty_out (vty, "%% Activate the neighbor for the address family first%s",
5503 VTY_NEWLINE);
5504 return CMD_WARNING;
5507 /* Check filter direction. */
5508 if (strncmp (direct_str, "i", 1) == 0)
5509 direct = FILTER_IN;
5510 else if (strncmp (direct_str, "o", 1) == 0)
5511 direct = FILTER_OUT;
5512 else
5514 vty_out (vty, "filter direction must be [in|out]%s", VTY_NEWLINE);
5515 return CMD_WARNING;
5518 filter = &conf->filter[afi][safi];
5520 if (! filter->map[direct].name)
5522 vty_out (vty, "There is no such filter: %s%s", name_str, VTY_NEWLINE);
5523 return CMD_WARNING;
5525 if (strcmp (filter->map[direct].name, name_str) != 0)
5527 vty_out (vty, "There is no such filter: %s%s", name_str, VTY_NEWLINE);
5528 return CMD_WARNING;
5531 free (filter->map[direct].name);
5532 filter->map[direct].name = NULL;
5533 filter->map[direct].map = NULL;
5535 return CMD_SUCCESS;
5538 DEFUN (neighbor_route_map,
5539 neighbor_route_map_cmd,
5540 NEIGHBOR_CMD "route-map WORD (in|out)",
5541 NEIGHBOR_STR
5542 NEIGHBOR_ADDR_STR
5543 "Apply route map to neighbor\n"
5544 "Name of route map\n"
5545 "Apply map to incoming routes\n"
5546 "Apply map to outbound routes\n")
5548 return bgp_route_map_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5549 argv[1], argv[2]);
5552 DEFUN (no_neighbor_route_map,
5553 no_neighbor_route_map_cmd,
5554 NO_NEIGHBOR_CMD "route-map WORD (in|out)",
5555 NO_STR
5556 NEIGHBOR_STR
5557 NEIGHBOR_ADDR_STR
5558 "Apply route map to neighbor\n"
5559 "Name of route map\n"
5560 "Apply map to incoming routes\n"
5561 "Apply map to outbound routes\n")
5563 return bgp_route_map_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5564 argv[1], argv[2]);
5567 DEFUN (ipv6_bgp_neighbor_route_map,
5568 ipv6_bgp_neighbor_route_map_cmd,
5569 NEIGHBOR_CMD "route-map WORD (in|out)",
5570 NEIGHBOR_STR
5571 NEIGHBOR_ADDR_STR
5572 "Apply route map to neighbor\n"
5573 "Name of route map\n"
5574 "Apply map to incoming routes\n"
5575 "Apply map to outbound routes\n")
5577 return bgp_route_map_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5578 argv[1], argv[2]);
5581 DEFUN (no_ipv6_bgp_neighbor_route_map,
5582 no_ipv6_bgp_neighbor_route_map_cmd,
5583 NO_NEIGHBOR_CMD "route-map WORD (in|out)",
5584 NO_STR
5585 NEIGHBOR_STR
5586 NEIGHBOR_ADDR_STR
5587 "Apply route map to neighbor\n"
5588 "Name of route map\n"
5589 "Apply map to incoming routes\n"
5590 "Apply map to outbound routes\n")
5592 return bgp_route_map_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5593 argv[1], argv[2]);
5596 ALIAS (ipv6_bgp_neighbor_route_map,
5597 old_ipv6_bgp_neighbor_route_map_cmd,
5598 "ipv6 bgp neighbor (A.B.C.D|X:X::X:X) route-map WORD (in|out)",
5599 IPV6_STR
5600 BGP_STR
5601 NEIGHBOR_STR
5602 "IP address\n"
5603 "IPv6 address\n"
5604 "Apply route map to neighbor\n"
5605 "Name of route map\n"
5606 "Apply map to incoming routes\n"
5607 "Apply map to outbound routes\n")
5609 ALIAS (no_ipv6_bgp_neighbor_route_map,
5610 old_no_ipv6_bgp_neighbor_route_map_cmd,
5611 "no ipv6 bgp neighbor (A.B.C.D|X:X::X:X) route-map WORD (in|out)",
5612 NO_STR
5613 IPV6_STR
5614 BGP_STR
5615 NEIGHBOR_STR
5616 "IP address\n"
5617 "IPv6 address\n"
5618 "Apply route map to neighbor\n"
5619 "Name of route map\n"
5620 "Apply map to incoming routes\n"
5621 "Apply map to outbound routes\n")
5624 bgp_maximum_prefix_set (struct vty *vty, char *ip_str, afi_t afi, safi_t safi,
5625 char *num_str, int warning)
5627 struct peer_conf *conf;
5628 unsigned long num;
5629 char *endptr = NULL;
5631 /* Lookup peer configuration. */
5632 conf = peer_conf_lookup_vty (vty, ip_str, afi);
5633 if (! conf)
5634 return CMD_WARNING;
5635 if (! conf->afc[afi][safi])
5637 vty_out (vty, "%% Activate the neighbor for the address family first%s",
5638 VTY_NEWLINE);
5639 return CMD_WARNING;
5642 /* Convert string to unsigned long. */
5643 num = strtoul (num_str, &endptr, 10);
5644 if (num == ULONG_MAX || *endptr != '\0')
5646 vty_out (vty, "%% maximum-prefix count must be positive integer%s",
5647 VTY_NEWLINE);
5648 return CMD_WARNING;
5651 /* Set maximum prefix value. */
5652 conf->pmax[afi][safi] = num;
5653 conf->pmax_warning[afi][safi] = (warning ? 1 : 0);
5655 return CMD_SUCCESS;
5659 bgp_maximum_prefix_unset (struct vty *vty, char *ip_str,
5660 afi_t afi, safi_t safi)
5662 struct peer_conf *conf;
5664 /* Lookup peer configuration. */
5665 conf = peer_conf_lookup_vty (vty, ip_str, afi);
5666 if (! conf)
5667 return CMD_WARNING;
5668 if (! conf->afc[afi][safi])
5670 vty_out (vty, "%% Activate the neighbor for the address family first%s",
5671 VTY_NEWLINE);
5672 return CMD_WARNING;
5675 conf->pmax[afi][safi] = 0;
5676 conf->pmax_warning[afi][safi] = 0;
5678 return CMD_SUCCESS;
5681 /* Maximum number of prefix configuration. prefix count is different
5682 for each peer configuration. So this configuration can be set for
5683 each peer configuration. */
5684 DEFUN (neighbor_maximum_prefix,
5685 neighbor_maximum_prefix_cmd,
5686 NEIGHBOR_CMD "maximum-prefix <1-4294967295>",
5687 NEIGHBOR_STR
5688 NEIGHBOR_ADDR_STR
5689 "Maximum number of prefix accept from this peer\n"
5690 "maximum no. of prefix limit\n")
5692 return bgp_maximum_prefix_set (vty, argv[0], bgp_node_afi (vty),
5693 bgp_node_safi (vty), argv[1], 0);
5696 DEFUN (neighbor_maximum_prefix_warning,
5697 neighbor_maximum_prefix_warning_cmd,
5698 NEIGHBOR_CMD "maximum-prefix <1-4294967295> warning-only",
5699 NEIGHBOR_STR
5700 NEIGHBOR_ADDR_STR
5701 "Maximum number of prefix accept from this peer\n"
5702 "maximum no. of prefix limit\n"
5703 "Only give warning message when limit is exceeded\n")
5705 return bgp_maximum_prefix_set (vty, argv[0], bgp_node_afi (vty),
5706 bgp_node_safi (vty), argv[1], 1);
5709 DEFUN (no_neighbor_maximum_prefix,
5710 no_neighbor_maximum_prefix_cmd,
5711 NO_NEIGHBOR_CMD "maximum-prefix",
5712 NO_STR
5713 NEIGHBOR_STR
5714 NEIGHBOR_ADDR_STR
5715 "Maximum number of prefix accept from this peer\n")
5717 return bgp_maximum_prefix_unset (vty, argv[0], bgp_node_afi (vty),
5718 bgp_node_safi (vty));
5721 ALIAS (no_neighbor_maximum_prefix,
5722 no_neighbor_maximum_prefix_val_cmd,
5723 NO_NEIGHBOR_CMD "maximum-prefix <1-4294967295>",
5724 NO_STR
5725 NEIGHBOR_STR
5726 NEIGHBOR_ADDR_STR
5727 "Maximum number of prefix accept from this peer\n"
5728 "maximum no. of prefix limit\n")
5730 ALIAS (no_neighbor_maximum_prefix,
5731 no_neighbor_maximum_prefix_val2_cmd,
5732 NO_NEIGHBOR_CMD "maximum-prefix <1-4294967295> warning-only",
5733 NO_STR
5734 NEIGHBOR_STR
5735 NEIGHBOR_ADDR_STR
5736 "Maximum number of prefix accept from this peer\n"
5737 "maximum no. of prefix limit\n"
5738 "Only give warning message when limit is exceeded\n")
5740 /* Address family configuration. */
5741 DEFUN (address_family_ipv4_multicast,
5742 address_family_ipv4_multicast_cmd,
5743 "address-family ipv4 multicast",
5744 "Enter Address Family command mode\n"
5745 "Address family\n"
5746 "Multicast\n")
5748 vty->node = BGP_IPV4M_NODE;
5749 return CMD_SUCCESS;
5752 DEFUN (address_family_ipv6_unicast,
5753 address_family_ipv6_unicast_cmd,
5754 "address-family ipv6 unicast",
5755 "Enter Address Family command mode\n"
5756 "Address family\n"
5757 "unicast\n")
5759 vty->node = BGP_IPV6_NODE;
5760 return CMD_SUCCESS;
5763 ALIAS (address_family_ipv6_unicast,
5764 address_family_ipv6_cmd,
5765 "address-family ipv6",
5766 "Enter Address Family command mode\n"
5767 "Address family\n")
5769 DEFUN (exit_address_family,
5770 exit_address_family_cmd,
5771 "exit-address-family",
5772 "Exit from Address Family configuration mode\n")
5774 if (vty->node == BGP_IPV4M_NODE
5775 || vty->node == BGP_VPNV4_NODE
5776 || vty->node == BGP_IPV6_NODE)
5777 vty->node = BGP_NODE;
5778 return CMD_SUCCESS;
5781 /* BGP clear types. */
5782 enum clear_type
5784 clear_all,
5785 clear_peer,
5786 clear_peer_group,
5787 clear_as
5791 peer_have_afi (struct peer *peer, int afi)
5793 return ((afi == AFI_IP && (peer->afc[AFI_IP][SAFI_UNICAST]
5794 || peer->afc[AFI_IP][SAFI_MULTICAST]
5795 || peer->afc[AFI_IP][SAFI_MPLS_VPN]))
5796 || (afi == AFI_IP6 && (peer->afc[AFI_IP6][SAFI_UNICAST]
5797 || peer->afc[AFI_IP6][SAFI_MULTICAST]
5798 || peer->afc[AFI_IP6][SAFI_MPLS_VPN])));
5801 /* `clear ip bgp' functions. */
5803 clear_bgp (struct vty *vty, int afi, enum clear_type type, char *arg)
5805 int cleared;
5806 struct peer *peer;
5807 struct listnode *nn;
5808 as_t as;
5809 unsigned long as_ul;
5810 char *endptr = NULL;
5811 union sockunion su;
5812 int ret;
5814 /* Clear all bgp neighbors. */
5815 if (type == clear_all)
5817 LIST_LOOP (peer_list, peer, nn)
5819 if (peer_have_afi (peer, afi))
5821 if (! CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
5823 UNSET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
5824 peer->v_start = BGP_INIT_START_TIMER;
5825 BGP_EVENT_ADD (peer, BGP_Stop);
5829 vty_out (vty, "All bgp neighbors cleared%s", VTY_NEWLINE);
5831 return CMD_SUCCESS;
5833 /* Clear specified peer. Arg is string of the peer. */
5834 else if (type == clear_peer)
5836 cleared = 0;
5838 /* Make sockunion for lookup. */
5839 ret = str2sockunion (arg, &su);
5840 if (ret < 0)
5842 vty_out (vty, "Malformed address: %s%s", arg, VTY_NEWLINE);
5843 return CMD_WARNING;
5846 LIST_LOOP (peer_list, peer, nn)
5848 if (peer_have_afi (peer, afi) && sockunion_same (&peer->su, &su))
5850 if (! CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
5852 UNSET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
5853 peer->v_start = BGP_INIT_START_TIMER;
5854 BGP_EVENT_ADD (peer, BGP_Stop);
5856 cleared = 1;
5860 if (cleared)
5861 vty_out (vty, "neighbor %s is cleared%s", arg, VTY_NEWLINE);
5862 else
5863 vty_out (vty, "%%BGP: Unknown neighbor - \"%s\"%s", arg, VTY_NEWLINE);
5865 return CMD_SUCCESS;
5867 /* AS based clear. */
5868 else if (type == clear_as)
5870 cleared = 0;
5872 as_ul = strtoul(arg, &endptr, 10);
5874 if ((as_ul == ULONG_MAX) || (*endptr != '\0') || (as_ul > USHRT_MAX))
5876 vty_out (vty, "Invalid neighbor specifier: %s%s", arg,
5877 VTY_NEWLINE);
5878 return CMD_SUCCESS;
5881 as = (as_t) as_ul;
5883 LIST_LOOP (peer_list, peer, nn)
5885 if (peer_have_afi (peer, afi) && peer->as == as)
5887 if (! CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
5889 UNSET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
5890 peer->v_start = BGP_INIT_START_TIMER;
5891 BGP_EVENT_ADD (peer, BGP_Stop);
5893 cleared = 1;
5896 if (cleared)
5897 vty_out (vty, "All neighbors which AS is %s cleared%s", arg,
5898 VTY_NEWLINE);
5899 else
5900 vty_out (vty, "%%BGP: No peer is configured with AS %s%s", arg,
5901 VTY_NEWLINE);
5903 return CMD_SUCCESS;
5906 /* Not reached. */
5907 return CMD_SUCCESS;
5910 DEFUN (clear_ip_bgp_all,
5911 clear_ip_bgp_all_cmd,
5912 "clear ip bgp *",
5913 CLEAR_STR
5914 IP_STR
5915 BGP_STR
5916 "Clear all peers\n")
5918 return clear_bgp (vty, AFI_IP, clear_all, NULL);
5921 DEFUN (clear_ip_bgp_peer,
5922 clear_ip_bgp_peer_cmd,
5923 "clear ip bgp (A.B.C.D|X:X::X:X)",
5924 CLEAR_STR
5925 IP_STR
5926 BGP_STR
5927 "BGP neighbor IP address to clear\n"
5928 "BGP neighbor IPv6 address to clear\n")
5930 return clear_bgp (vty, AFI_IP, clear_peer, argv[0]);
5933 DEFUN (clear_ip_bgp_peer_group,
5934 clear_ip_bgp_peer_group_cmd,
5935 "clear ip bgp peer-group WORD",
5936 CLEAR_STR
5937 IP_STR
5938 BGP_STR
5939 "Clear all members of peer-group\n"
5940 "BGP peer-group name\n")
5942 return clear_bgp (vty, AFI_IP, clear_peer_group, argv[0]);
5945 DEFUN (clear_ip_bgp_as,
5946 clear_ip_bgp_as_cmd,
5947 "clear ip bgp <1-65535>",
5948 CLEAR_STR
5949 IP_STR
5950 BGP_STR
5951 "Clear peers with the AS number\n")
5953 return clear_bgp (vty, AFI_IP, clear_as, argv[0]);
5956 #ifdef HAVE_IPV6
5957 DEFUN (clear_bgp_all,
5958 clear_bgp_all_cmd,
5959 "clear bgp *",
5960 CLEAR_STR
5961 BGP_STR
5962 "Clear all peers\n")
5964 return clear_bgp (vty, AFI_IP6, clear_all, NULL);
5967 ALIAS (clear_bgp_all,
5968 clear_bgp_ipv6_all_cmd,
5969 "clear bgp ipv6 *",
5970 CLEAR_STR
5971 BGP_STR
5972 "Address family\n"
5973 "Clear all peers\n")
5975 DEFUN (clear_bgp_peer,
5976 clear_bgp_peer_cmd,
5977 "clear bgp (A.B.C.D|X:X::X:X)",
5978 CLEAR_STR
5979 BGP_STR
5980 "BGP neighbor address to clear\n"
5981 "BGP IPv6 neighbor to clear\n")
5983 return clear_bgp (vty, AFI_IP6, clear_peer, argv[0]);
5986 ALIAS (clear_bgp_peer,
5987 clear_bgp_ipv6_peer_cmd,
5988 "clear bgp ipv6 (A.B.C.D|X:X::X:X)",
5989 CLEAR_STR
5990 BGP_STR
5991 "Address family\n"
5992 "BGP neighbor address to clear\n"
5993 "BGP IPv6 neighbor to clear\n")
5995 DEFUN (clear_bgp_peer_group,
5996 clear_bgp_peer_group_cmd,
5997 "clear bgp peer-group WORD",
5998 CLEAR_STR
5999 BGP_STR
6000 "Clear all members of peer-group\n"
6001 "BGP peer-group name\n")
6003 return clear_bgp (vty, AFI_IP6, clear_peer_group, argv[0]);
6006 ALIAS (clear_bgp_peer_group,
6007 clear_bgp_ipv6_peer_group_cmd,
6008 "clear bgp ipv6 peer-group WORD",
6009 CLEAR_STR
6010 BGP_STR
6011 "Address family\n"
6012 "Clear all members of peer-group\n"
6013 "BGP peer-group name\n")
6015 DEFUN (clear_bgp_as,
6016 clear_bgp_as_cmd,
6017 "clear bgp <1-65535>",
6018 CLEAR_STR
6019 BGP_STR
6020 "Clear peers with the AS number\n")
6022 return clear_bgp (vty, AFI_IP6, clear_as, argv[0]);
6025 ALIAS (clear_bgp_as,
6026 clear_bgp_ipv6_as_cmd,
6027 "clear bgp ipv6 <1-65535>",
6028 CLEAR_STR
6029 BGP_STR
6030 "Address family\n"
6031 "Clear peers with the AS number\n")
6032 #endif /* HAVE_IPV6 */
6034 /* Clear ip bgp neighbor soft in. */
6036 clear_bgp_soft_in (struct vty *vty, afi_t afi, safi_t safi, enum clear_type type, char *arg, int soft)
6038 int ret;
6039 union sockunion su;
6040 struct peer *peer;
6041 struct listnode *nn;
6042 as_t as = 0;
6043 unsigned long as_ul;
6044 char *endptr = NULL;
6045 int find = 0;
6047 if (type == clear_peer)
6049 /* Looking up peer with IP address string. */
6050 ret = str2sockunion (arg, &su);
6051 if (ret < 0)
6053 vty_out (vty, "Malformed address: %s%s", arg, VTY_NEWLINE);
6054 return CMD_WARNING;
6058 if (type == clear_as)
6060 as_ul = strtoul(arg, &endptr, 10);
6061 if ((as_ul == ULONG_MAX) || (*endptr != '\0') || (as_ul > USHRT_MAX))
6063 vty_out (vty, "Invalid neighbor specifier: %s%s", arg, VTY_NEWLINE);
6064 return CMD_WARNING;
6066 as = (as_t) as_ul;
6069 LIST_LOOP (peer_list, peer, nn)
6071 if ((type == clear_peer && sockunion_same (&peer->su, &su))
6072 || (type == clear_as && peer->as == as)
6073 || type == clear_all)
6075 find = 1;
6076 if (peer->afc[afi][safi])
6078 if (peer->status == Established)
6080 if (soft)
6082 /* If neighbor has soft reconfiguration inbound flag.
6083 Use Adj-RIB-In database. */
6084 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
6086 if (safi == SAFI_MPLS_VPN)
6088 vty_out (vty, "%%BGP: Soft-reconfiguration inbound is not supported for vpnv4%s", VTY_NEWLINE);
6089 return CMD_WARNING;
6091 bgp_soft_reconfig_in (peer, afi, safi);
6092 vty_out (vty, "neighbor %s is inbound cleared (s)%s",
6093 peer->host, VTY_NEWLINE);
6095 else
6097 /* If neighbor has route refresh capability, send route refresh
6098 message to the peer. */
6099 if (peer->refresh_nego_old || peer->refresh_nego_new)
6101 bgp_route_refresh_send (peer, afi, safi);
6102 vty_out (vty, "neighbor %s is inbound cleared (r)%s",
6103 peer->host, VTY_NEWLINE);
6105 else
6106 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);
6109 else
6111 /* If neighbor has route refresh capability, send route refresh
6112 message to the peer. */
6113 if (peer->refresh_nego_old || peer->refresh_nego_new)
6115 bgp_route_refresh_send (peer, afi, safi);
6116 vty_out (vty, "neighbor %s is inbound cleared (r)%s",
6117 peer->host, VTY_NEWLINE);
6119 else
6121 /* If neighbor has soft reconfiguration inbound flag.
6122 Use Adj-RIB-In database. */
6123 if (CHECK_FLAG (peer->flags, PEER_FLAG_SOFT_RECONFIG))
6125 if (safi == SAFI_MPLS_VPN)
6127 vty_out (vty, "%%BGP: Soft-reconfiguration inbound is not supported for vpnv4%s", VTY_NEWLINE);
6128 return CMD_WARNING;
6130 bgp_soft_reconfig_in (peer, afi, safi);
6131 vty_out (vty, "neighbor %s is inbound cleared (s)%s",
6132 peer->host, VTY_NEWLINE);
6134 else
6135 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);
6140 else if (type == clear_peer || type == clear_as)
6141 vty_out (vty, "%%BGP: Enable %s %s address family for the neighbor %s%s",
6142 afi == AFI_IP6 ? "IPv6" : safi == SAFI_MPLS_VPN ? "VPNv4" : "IPv4",
6143 safi == SAFI_MULTICAST ? "Multicast" : "Unicast",
6144 peer->host, VTY_NEWLINE);
6148 if (! find && type == clear_peer)
6150 vty_out (vty, "%%BGP: Unknown neighbor - \"%s\"%s", arg, VTY_NEWLINE);
6151 return CMD_WARNING;
6153 if (! find && type == clear_as)
6155 vty_out (vty, "%%BGP: No peer is configured with AS %s%s", arg, VTY_NEWLINE);
6156 return CMD_WARNING;
6159 return CMD_SUCCESS;
6162 DEFUN (clear_ip_bgp_peer_soft_in,
6163 clear_ip_bgp_peer_soft_in_cmd,
6164 "clear ip bgp A.B.C.D soft in",
6165 CLEAR_STR
6166 IP_STR
6167 BGP_STR
6168 "BGP neighbor address to clear\n"
6169 "Soft reconfig\n"
6170 "Soft reconfig inbound update\n")
6172 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0], 1);
6175 DEFUN (clear_ip_bgp_peer_in,
6176 clear_ip_bgp_peer_in_cmd,
6177 "clear ip bgp A.B.C.D in",
6178 CLEAR_STR
6179 IP_STR
6180 BGP_STR
6181 "BGP neighbor address to clear\n"
6182 "Soft reconfig inbound update\n")
6184 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0], 0);
6187 DEFUN (clear_ip_bgp_peer_ipv4_soft_in,
6188 clear_ip_bgp_peer_ipv4_soft_in_cmd,
6189 "clear ip bgp A.B.C.D ipv4 (unicast|multicast) soft in",
6190 CLEAR_STR
6191 IP_STR
6192 BGP_STR
6193 "BGP neighbor address to clear\n"
6194 "Address family\n"
6195 "Address Family modifier\n"
6196 "Address Family modifier\n"
6197 "Soft reconfig\n"
6198 "Soft reconfig inbound update\n")
6200 if (strncmp (argv[1], "m", 1) == 0)
6201 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MULTICAST, clear_peer, argv[0], 1);
6203 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0], 1);
6206 DEFUN (clear_ip_bgp_peer_ipv4_in,
6207 clear_ip_bgp_peer_ipv4_in_cmd,
6208 "clear ip bgp A.B.C.D ipv4 (unicast|multicast) in",
6209 CLEAR_STR
6210 IP_STR
6211 BGP_STR
6212 "BGP neighbor address to clear\n"
6213 "Address family\n"
6214 "Address Family modifier\n"
6215 "Address Family modifier\n"
6216 "Soft reconfig inbound update\n")
6218 if (strncmp (argv[1], "m", 1) == 0)
6219 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MULTICAST, clear_peer, argv[0], 0);
6221 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0], 0);
6224 DEFUN (clear_ip_bgp_as_soft_in,
6225 clear_ip_bgp_as_soft_in_cmd,
6226 "clear ip bgp <1-65535> soft in",
6227 CLEAR_STR
6228 IP_STR
6229 BGP_STR
6230 "Clear peers with the AS number\n"
6231 "Soft reconfig\n"
6232 "Soft reconfig inbound update\n")
6234 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0], 1);
6237 DEFUN (clear_ip_bgp_as_in,
6238 clear_ip_bgp_as_in_cmd,
6239 "clear ip bgp <1-65535> in",
6240 CLEAR_STR
6241 IP_STR
6242 BGP_STR
6243 "Clear peers with the AS number\n"
6244 "Soft reconfig inbound update\n")
6246 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0], 0);
6249 DEFUN (clear_ip_bgp_as_ipv4_soft_in,
6250 clear_ip_bgp_as_ipv4_soft_in_cmd,
6251 "clear ip bgp <1-65535> ipv4 (unicast|multicast) soft in",
6252 CLEAR_STR
6253 IP_STR
6254 BGP_STR
6255 "Clear peers with the AS number\n"
6256 "Address family\n"
6257 "Address Family modifier\n"
6258 "Address Family modifier\n"
6259 "Soft reconfig\n"
6260 "Soft reconfig inbound update\n")
6262 if (strncmp (argv[1], "m", 1) == 0)
6263 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MULTICAST, clear_as, argv[0], 1);
6265 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0], 1);
6268 DEFUN (clear_ip_bgp_as_ipv4_in,
6269 clear_ip_bgp_as_ipv4_in_cmd,
6270 "clear ip bgp <1-65535> ipv4 (unicast|multicast) in",
6271 CLEAR_STR
6272 IP_STR
6273 BGP_STR
6274 "Clear peers with the AS number\n"
6275 "Address family\n"
6276 "Address Family modifier\n"
6277 "Address Family modifier\n"
6278 "Soft reconfig inbound update\n")
6280 if (strncmp (argv[1], "m", 1) == 0)
6281 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MULTICAST, clear_as, argv[0], 0);
6283 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0], 0);
6286 DEFUN (clear_ip_bgp_all_soft_in,
6287 clear_ip_bgp_all_soft_in_cmd,
6288 "clear ip bgp * soft in",
6289 CLEAR_STR
6290 IP_STR
6291 BGP_STR
6292 "Clear all peers\n"
6293 "Soft reconfig\n"
6294 "Soft reconfig inbound update\n")
6296 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL, 1);
6299 DEFUN (clear_ip_bgp_all_in,
6300 clear_ip_bgp_all_in_cmd,
6301 "clear ip bgp * in",
6302 CLEAR_STR
6303 IP_STR
6304 BGP_STR
6305 "Clear all peers\n"
6306 "Soft reconfig inbound update\n")
6308 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL, 0);
6311 DEFUN (clear_ip_bgp_all_ipv4_soft_in,
6312 clear_ip_bgp_all_ipv4_soft_in_cmd,
6313 "clear ip bgp * ipv4 (unicast|multicast) soft in",
6314 CLEAR_STR
6315 IP_STR
6316 BGP_STR
6317 "Clear all peers\n"
6318 "Address family\n"
6319 "Address Family modifier\n"
6320 "Address Family modifier\n"
6321 "Soft reconfig\n"
6322 "Soft reconfig inbound update\n")
6324 if (strncmp (argv[0], "m", 1) == 0)
6325 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MULTICAST, clear_all, NULL, 1);
6327 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL, 1);
6330 DEFUN (clear_ip_bgp_all_ipv4_in,
6331 clear_ip_bgp_all_ipv4_in_cmd,
6332 "clear ip bgp * ipv4 (unicast|multicast) in",
6333 CLEAR_STR
6334 IP_STR
6335 BGP_STR
6336 "Clear all peers\n"
6337 "Address family\n"
6338 "Address Family modifier\n"
6339 "Address Family modifier\n"
6340 "Soft reconfig inbound update\n")
6342 if (strncmp (argv[0], "m", 1) == 0)
6343 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MULTICAST, clear_all, NULL, 0);
6345 return clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL, 0);
6349 DEFUN (clear_ip_bgp_peer_vpnv4_soft_in,
6350 clear_ip_bgp_peer_vpnv4_soft_in_cmd,
6351 "clear ip bgp A.B.C.D vpnv4 unicast soft in",
6352 CLEAR_STR
6353 IP_STR
6354 BGP_STR
6355 "BGP neighbor address to clear\n"
6356 "Address family\n"
6357 "Address Family Modifier\n"
6358 "Soft reconfig\n"
6359 "Soft reconfig inbound update\n")
6361 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MPLS_VPN, clear_peer, argv[0], 0);
6364 DEFUN (clear_ip_bgp_peer_vpnv4_in,
6365 clear_ip_bgp_peer_vpnv4_in_cmd,
6366 "clear ip bgp A.B.C.D vpnv4 unicast in",
6367 CLEAR_STR
6368 IP_STR
6369 BGP_STR
6370 "BGP neighbor address to clear\n"
6371 "Address family\n"
6372 "Address Family Modifier\n"
6373 "Soft reconfig inbound update\n")
6375 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MPLS_VPN, clear_peer, argv[0], 0);
6378 DEFUN (clear_ip_bgp_as_vpnv4_soft_in,
6379 clear_ip_bgp_as_vpnv4_soft_in_cmd,
6380 "clear ip bgp <1-65535> vpnv4 unicast soft in",
6381 CLEAR_STR
6382 IP_STR
6383 BGP_STR
6384 "Clear peers with the AS number\n"
6385 "Address family\n"
6386 "Address Family modifier\n"
6387 "Soft reconfig\n"
6388 "Soft reconfig inbound update\n")
6390 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MPLS_VPN, clear_as, argv[0], 0);
6393 DEFUN (clear_ip_bgp_as_vpnv4_in,
6394 clear_ip_bgp_as_vpnv4_in_cmd,
6395 "clear ip bgp <1-65535> vpnv4 unicast in",
6396 CLEAR_STR
6397 IP_STR
6398 BGP_STR
6399 "Clear peers with the AS number\n"
6400 "Address family\n"
6401 "Address Family modifier\n"
6402 "Soft reconfig inbound update\n")
6404 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MPLS_VPN, clear_as, argv[0], 0);
6407 DEFUN (clear_ip_bgp_all_vpnv4_soft_in,
6408 clear_ip_bgp_all_vpnv4_soft_in_cmd,
6409 "clear ip bgp * vpnv4 unicast soft in",
6410 CLEAR_STR
6411 IP_STR
6412 BGP_STR
6413 "Clear all peers\n"
6414 "Address family\n"
6415 "Address Family Modifier\n"
6416 "Soft reconfig\n"
6417 "Soft reconfig inbound update\n")
6419 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MPLS_VPN, clear_all, NULL, 0);
6422 DEFUN (clear_ip_bgp_all_vpnv4_in,
6423 clear_ip_bgp_all_vpnv4_in_cmd,
6424 "clear ip bgp * vpnv4 unicast in",
6425 CLEAR_STR
6426 IP_STR
6427 BGP_STR
6428 "Clear all peers\n"
6429 "Address family\n"
6430 "Address Family Modifier\n"
6431 "Soft reconfig inbound update\n")
6433 return clear_bgp_soft_in (vty, AFI_IP, SAFI_MPLS_VPN, clear_all, NULL, 0);
6436 /* Clear ip bgp neighbor soft out. */
6438 clear_bgp_soft_out (struct vty *vty, afi_t afi, safi_t safi, enum clear_type type, char *arg)
6440 int ret;
6441 union sockunion su;
6442 struct peer *peer;
6443 struct listnode *nn;
6444 as_t as = 0;
6445 unsigned long as_ul;
6446 char *endptr = NULL;
6447 int find = 0;
6449 if (type == clear_peer)
6451 /* Looking up peer with IP address string. */
6452 ret = str2sockunion (arg, &su);
6453 if (ret < 0)
6455 vty_out (vty, "Malformed address: %s%s", arg, VTY_NEWLINE);
6456 return CMD_WARNING;
6460 if (type == clear_as)
6462 as_ul = strtoul(arg, &endptr, 10);
6463 if ((as_ul == ULONG_MAX) || (*endptr != '\0') || (as_ul > USHRT_MAX))
6465 vty_out (vty, "Invalid neighbor specifier: %s%s", arg, VTY_NEWLINE);
6466 return CMD_WARNING;
6468 as = (as_t) as_ul;
6471 LIST_LOOP (peer_list, peer, nn)
6473 if ((type == clear_peer && sockunion_same (&peer->su, &su))
6474 || (type == clear_as && peer->as == as)
6475 || type == clear_all)
6477 find = 1;
6478 if (peer->afc[afi][safi])
6480 if (peer->status == Established)
6482 /* Performing soft out is same as receiving route
6483 refresh. */
6484 bgp_refresh_table (peer, afi, safi);
6485 vty_out (vty, "neighbor %s is outbound cleared%s",
6486 peer->host, VTY_NEWLINE);
6489 else if (type == clear_peer || type == clear_as)
6490 vty_out (vty, "%%BGP: Enable %s %s address family for the neighbor %s%s",
6491 afi == AFI_IP6 ? "IPv6" : safi == SAFI_MPLS_VPN ? "VPNv4" : "IPv4",
6492 safi == SAFI_MULTICAST ? "Multicast" : "Unicast",
6493 peer->host, VTY_NEWLINE);
6497 if (! find && type == clear_peer)
6499 vty_out (vty, "%%BGP: Unknown neighbor - \"%s\"%s", arg, VTY_NEWLINE);
6500 return CMD_WARNING;
6502 if (! find && type == clear_as)
6504 vty_out (vty, "%%BGP: No peer is configured with AS %s%s", arg, VTY_NEWLINE);
6505 return CMD_WARNING;
6508 return CMD_SUCCESS;
6511 DEFUN (clear_ip_bgp_peer_soft_out,
6512 clear_ip_bgp_peer_soft_out_cmd,
6513 "clear ip bgp A.B.C.D soft out",
6514 CLEAR_STR
6515 IP_STR
6516 BGP_STR
6517 "BGP neighbor address to clear\n"
6518 "Soft reconfig\n"
6519 "Soft reconfig outbound update\n")
6521 return clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0]);
6524 ALIAS (clear_ip_bgp_peer_soft_out,
6525 clear_ip_bgp_peer_out_cmd,
6526 "clear ip bgp A.B.C.D out",
6527 CLEAR_STR
6528 IP_STR
6529 BGP_STR
6530 "BGP neighbor address to clear\n"
6531 "Soft reconfig outbound update\n")
6533 DEFUN (clear_ip_bgp_peer_ipv4_soft_out,
6534 clear_ip_bgp_peer_ipv4_soft_out_cmd,
6535 "clear ip bgp A.B.C.D ipv4 (unicast|multicast) soft out",
6536 CLEAR_STR
6537 IP_STR
6538 BGP_STR
6539 "BGP neighbor address to clear\n"
6540 "Address family\n"
6541 "Address Family modifier\n"
6542 "Address Family modifier\n"
6543 "Soft reconfig\n"
6544 "Soft reconfig outbound update\n")
6546 if (strncmp (argv[1], "m", 1) == 0)
6547 return clear_bgp_soft_out (vty, AFI_IP, SAFI_MULTICAST, clear_peer, argv[0]);
6549 return clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0]);
6552 ALIAS (clear_ip_bgp_peer_ipv4_soft_out,
6553 clear_ip_bgp_peer_ipv4_out_cmd,
6554 "clear ip bgp A.B.C.D ipv4 (unicast|multicast) out",
6555 CLEAR_STR
6556 IP_STR
6557 BGP_STR
6558 "BGP neighbor address to clear\n"
6559 "Address family\n"
6560 "Address Family modifier\n"
6561 "Address Family modifier\n"
6562 "Soft reconfig outbound update\n")
6564 DEFUN (clear_ip_bgp_as_soft_out,
6565 clear_ip_bgp_as_soft_out_cmd,
6566 "clear ip bgp <1-65535> soft out",
6567 CLEAR_STR
6568 IP_STR
6569 BGP_STR
6570 "Clear peers with the AS number\n"
6571 "Soft reconfig\n"
6572 "Soft reconfig outbound update\n")
6574 return clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0]);
6577 ALIAS (clear_ip_bgp_as_soft_out,
6578 clear_ip_bgp_as_out_cmd,
6579 "clear ip bgp <1-65535> out",
6580 CLEAR_STR
6581 IP_STR
6582 BGP_STR
6583 "Clear peers with the AS number\n"
6584 "Soft reconfig outbound update\n")
6586 DEFUN (clear_ip_bgp_as_ipv4_soft_out,
6587 clear_ip_bgp_as_ipv4_soft_out_cmd,
6588 "clear ip bgp <1-65535> ipv4 (unicast|multicast) soft out",
6589 CLEAR_STR
6590 IP_STR
6591 BGP_STR
6592 "Clear peers with the AS number\n"
6593 "Address family\n"
6594 "Address Family modifier\n"
6595 "Address Family modifier\n"
6596 "Soft reconfig\n"
6597 "Soft reconfig outbound update\n")
6599 if (strncmp (argv[1], "m", 1) == 0)
6600 return clear_bgp_soft_out (vty, AFI_IP, SAFI_MULTICAST, clear_as, argv[0]);
6602 return clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0]);
6605 ALIAS (clear_ip_bgp_as_ipv4_soft_out,
6606 clear_ip_bgp_as_ipv4_out_cmd,
6607 "clear ip bgp <1-65535> ipv4 (unicast|multicast) out",
6608 CLEAR_STR
6609 IP_STR
6610 BGP_STR
6611 "Clear peers with the AS number\n"
6612 "Address family\n"
6613 "Address Family modifier\n"
6614 "Address Family modifier\n"
6615 "Soft reconfig outbound update\n")
6617 DEFUN (clear_ip_bgp_all_soft_out,
6618 clear_ip_bgp_all_soft_out_cmd,
6619 "clear ip bgp * soft out",
6620 CLEAR_STR
6621 IP_STR
6622 BGP_STR
6623 "Clear all peers\n"
6624 "Soft reconfig\n"
6625 "Soft reconfig outbound update\n")
6627 return clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL);
6630 ALIAS (clear_ip_bgp_all_soft_out,
6631 clear_ip_bgp_all_out_cmd,
6632 "clear ip bgp * out",
6633 CLEAR_STR
6634 IP_STR
6635 BGP_STR
6636 "Clear all peers\n"
6637 "Soft reconfig outbound update\n")
6639 DEFUN (clear_ip_bgp_all_ipv4_soft_out,
6640 clear_ip_bgp_all_ipv4_soft_out_cmd,
6641 "clear ip bgp * ipv4 (unicast|multicast) soft out",
6642 CLEAR_STR
6643 IP_STR
6644 BGP_STR
6645 "Clear all peers\n"
6646 "Address family\n"
6647 "Address Family modifier\n"
6648 "Address Family modifier\n"
6649 "Soft reconfig\n"
6650 "Soft reconfig outbound update\n")
6652 if (strncmp (argv[0], "m", 1) == 0)
6653 return clear_bgp_soft_out (vty, AFI_IP, SAFI_MULTICAST, clear_all, NULL);
6655 return clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL);
6658 ALIAS (clear_ip_bgp_all_ipv4_soft_out,
6659 clear_ip_bgp_all_ipv4_out_cmd,
6660 "clear ip bgp * ipv4 (unicast|multicast) out",
6661 CLEAR_STR
6662 IP_STR
6663 BGP_STR
6664 "Clear all peers\n"
6665 "Address family\n"
6666 "Address Family modifier\n"
6667 "Address Family modifier\n"
6668 "Soft reconfig outbound update\n")
6670 DEFUN (clear_ip_bgp_peer_vpnv4_soft_out,
6671 clear_ip_bgp_peer_vpnv4_soft_out_cmd,
6672 "clear ip bgp A.B.C.D vpnv4 unicast soft out",
6673 CLEAR_STR
6674 IP_STR
6675 BGP_STR
6676 "BGP neighbor address to clear\n"
6677 "Address family\n"
6678 "Address Family Modifier\n"
6679 "Soft reconfig\n"
6680 "Soft reconfig outbound update\n")
6682 return clear_bgp_soft_out (vty, AFI_IP, SAFI_MPLS_VPN, clear_peer, argv[0]);
6685 ALIAS (clear_ip_bgp_peer_vpnv4_soft_out,
6686 clear_ip_bgp_peer_vpnv4_out_cmd,
6687 "clear ip bgp A.B.C.D vpnv4 unicast out",
6688 CLEAR_STR
6689 IP_STR
6690 BGP_STR
6691 "BGP neighbor address to clear\n"
6692 "Address family\n"
6693 "Address Family Modifier\n"
6694 "Soft reconfig outbound update\n")
6696 DEFUN (clear_ip_bgp_as_vpnv4_soft_out,
6697 clear_ip_bgp_as_vpnv4_soft_out_cmd,
6698 "clear ip bgp <1-65535> vpnv4 unicast soft out",
6699 CLEAR_STR
6700 IP_STR
6701 BGP_STR
6702 "Clear peers with the AS number\n"
6703 "Address family\n"
6704 "Address Family modifier\n"
6705 "Soft reconfig\n"
6706 "Soft reconfig outbound update\n")
6708 return clear_bgp_soft_out (vty, AFI_IP, SAFI_MPLS_VPN, clear_as, argv[0]);
6711 ALIAS (clear_ip_bgp_as_vpnv4_soft_out,
6712 clear_ip_bgp_as_vpnv4_out_cmd,
6713 "clear ip bgp <1-65535> vpnv4 unicast out",
6714 CLEAR_STR
6715 IP_STR
6716 BGP_STR
6717 "Clear peers with the AS number\n"
6718 "Address family\n"
6719 "Address Family modifier\n"
6720 "Soft reconfig outbound update\n")
6722 DEFUN (clear_ip_bgp_all_vpnv4_soft_out,
6723 clear_ip_bgp_all_vpnv4_soft_out_cmd,
6724 "clear ip bgp * vpnv4 unicast soft out",
6725 CLEAR_STR
6726 IP_STR
6727 BGP_STR
6728 "Clear all peers\n"
6729 "Address family\n"
6730 "Address Family Modifier\n"
6731 "Soft reconfig\n"
6732 "Soft reconfig outbound update\n")
6734 return clear_bgp_soft_out (vty, AFI_IP, SAFI_MPLS_VPN, clear_all, NULL);
6737 ALIAS (clear_ip_bgp_all_vpnv4_soft_out,
6738 clear_ip_bgp_all_vpnv4_out_cmd,
6739 "clear ip bgp * vpnv4 unicast out",
6740 CLEAR_STR
6741 IP_STR
6742 BGP_STR
6743 "Clear all peers\n"
6744 "Address family\n"
6745 "Address Family Modifier\n"
6746 "Soft reconfig outbound update\n")
6748 /* soft reset both inbound and outbound */
6749 DEFUN (clear_ip_bgp_peer_soft,
6750 clear_ip_bgp_peer_soft_cmd,
6751 "clear ip bgp A.B.C.D soft",
6752 CLEAR_STR
6753 IP_STR
6754 BGP_STR
6755 "BGP neighbor address to clear\n"
6756 "Soft reconfig\n")
6758 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0]) == CMD_SUCCESS)
6759 clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0], 0);
6761 return CMD_SUCCESS;
6764 DEFUN (clear_ip_bgp_peer_ipv4_soft,
6765 clear_ip_bgp_peer_ipv4_soft_cmd,
6766 "clear ip bgp A.B.C.D ipv4 (unicast|multicast) soft",
6767 CLEAR_STR
6768 IP_STR
6769 BGP_STR
6770 "BGP neighbor address to clear\n"
6771 "Address family\n"
6772 "Address Family Modifier\n"
6773 "Address Family Modifier\n"
6774 "Soft reconfig\n")
6776 if (strncmp (argv[1], "m", 1) == 0)
6778 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_MULTICAST, clear_peer, argv[0]) == CMD_SUCCESS)
6779 clear_bgp_soft_in (vty, AFI_IP, SAFI_MULTICAST, clear_peer, argv[0], 0);
6781 else
6782 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0]) == CMD_SUCCESS)
6783 clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_peer, argv[0], 0);
6785 return CMD_SUCCESS;
6788 DEFUN (clear_ip_bgp_as_soft,
6789 clear_ip_bgp_as_soft_cmd,
6790 "clear ip bgp <1-65535> soft",
6791 CLEAR_STR
6792 IP_STR
6793 BGP_STR
6794 "Clear peers with the AS number\n"
6795 "Soft reconfig\n")
6797 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0]) == CMD_SUCCESS)
6798 clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0], 0);
6800 return CMD_SUCCESS;
6803 DEFUN (clear_ip_bgp_as_ipv4_soft,
6804 clear_ip_bgp_as_ipv4_soft_cmd,
6805 "clear ip bgp <1-65535> ipv4 (unicast|multicast) soft",
6806 CLEAR_STR
6807 IP_STR
6808 BGP_STR
6809 "Clear peers with the AS number\n"
6810 "Address family\n"
6811 "Address Family Modifier\n"
6812 "Address Family Modifier\n"
6813 "Soft reconfig\n")
6815 if (strncmp (argv[1], "m", 1) == 0)
6817 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_MULTICAST, clear_as, argv[0]) == CMD_SUCCESS)
6818 clear_bgp_soft_in (vty, AFI_IP, SAFI_MULTICAST, clear_as, argv[0], 0);
6820 else
6821 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0]) == CMD_SUCCESS)
6822 clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_as, argv[0], 0);
6824 return CMD_SUCCESS;
6827 DEFUN (clear_ip_bgp_all_soft,
6828 clear_ip_bgp_all_soft_cmd,
6829 "clear ip bgp * soft",
6830 CLEAR_STR
6831 IP_STR
6832 BGP_STR
6833 "Clear all peers\n"
6834 "Soft reconfig\n")
6836 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL) == CMD_SUCCESS)
6837 clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL, 0);
6839 return CMD_SUCCESS;
6842 DEFUN (clear_ip_bgp_all_ipv4_soft,
6843 clear_ip_bgp_all_ipv4_soft_cmd,
6844 "clear ip bgp * ipv4 (unicast|multicast) soft",
6845 CLEAR_STR
6846 IP_STR
6847 BGP_STR
6848 "Clear all peers\n"
6849 "Address family\n"
6850 "Address Family Modifier\n"
6851 "Address Family Modifier\n"
6852 "Soft reconfig\n")
6854 if (strncmp (argv[0], "m", 1) == 0)
6856 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_MULTICAST, clear_all, NULL) == CMD_SUCCESS)
6857 clear_bgp_soft_in (vty, AFI_IP, SAFI_MULTICAST, clear_all, NULL, 0);
6859 else
6860 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL) == CMD_SUCCESS)
6861 clear_bgp_soft_in (vty, AFI_IP, SAFI_UNICAST, clear_all, NULL, 0);
6863 return CMD_SUCCESS;
6866 DEFUN (clear_ip_bgp_peer_vpnv4_soft,
6867 clear_ip_bgp_peer_vpnv4_soft_cmd,
6868 "clear ip bgp A.B.C.D vpnv4 unicast soft",
6869 CLEAR_STR
6870 IP_STR
6871 BGP_STR
6872 "BGP neighbor address to clear\n"
6873 "Address family\n"
6874 "Address Family Modifier\n"
6875 "Soft reconfig\n")
6877 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_MPLS_VPN, clear_peer, argv[0]) == CMD_SUCCESS)
6878 clear_bgp_soft_in (vty, AFI_IP, SAFI_MPLS_VPN, clear_peer, argv[0], 0);
6880 return CMD_SUCCESS;
6883 DEFUN (clear_ip_bgp_as_vpnv4_soft,
6884 clear_ip_bgp_as_vpnv4_soft_cmd,
6885 "clear ip bgp <1-65535> vpnv4 unicast soft",
6886 CLEAR_STR
6887 IP_STR
6888 BGP_STR
6889 "Clear peers with the AS number\n"
6890 "Address family\n"
6891 "Address Family Modifier\n"
6892 "Soft reconfig\n")
6894 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_MPLS_VPN, clear_as, argv[0]) == CMD_SUCCESS)
6895 clear_bgp_soft_in (vty, AFI_IP, SAFI_MPLS_VPN, clear_as, argv[0], 0);
6897 return CMD_SUCCESS;
6900 DEFUN (clear_ip_bgp_all_vpnv4_soft,
6901 clear_ip_bgp_all_vpnv4_soft_cmd,
6902 "clear ip bgp * vpnv4 unicast soft",
6903 CLEAR_STR
6904 IP_STR
6905 BGP_STR
6906 "Clear all peers\n"
6907 "Address family\n"
6908 "Address Family Modifier\n"
6909 "Soft reconfig\n")
6911 if (clear_bgp_soft_out (vty, AFI_IP, SAFI_MPLS_VPN, clear_all, NULL) == CMD_SUCCESS)
6912 clear_bgp_soft_in (vty, AFI_IP, SAFI_MPLS_VPN, clear_all, NULL, 0);
6914 return CMD_SUCCESS;
6916 #ifdef HAVE_IPV6
6917 DEFUN (clear_bgp_peer_soft_in,
6918 clear_bgp_peer_soft_in_cmd,
6919 "clear bgp (A.B.C.D|X:X::X:X) soft in",
6920 CLEAR_STR
6921 BGP_STR
6922 "BGP neighbor address to clear\n"
6923 "BGP IPv6 neighbor to clear\n"
6924 "Soft reconfig\n"
6925 "Soft reconfig inbound update\n")
6927 return clear_bgp_soft_in (vty, AFI_IP6, SAFI_UNICAST, clear_peer, argv[0], 1);
6930 ALIAS (clear_bgp_peer_soft_in,
6931 clear_bgp_ipv6_peer_soft_in_cmd,
6932 "clear bgp ipv6 (A.B.C.D|X:X::X:X) soft in",
6933 CLEAR_STR
6934 BGP_STR
6935 "Address family\n"
6936 "BGP neighbor address to clear\n"
6937 "BGP IPv6 neighbor to clear\n"
6938 "Soft reconfig\n"
6939 "Soft reconfig inbound update\n")
6941 DEFUN (clear_bgp_peer_in,
6942 clear_bgp_peer_in_cmd,
6943 "clear bgp (A.B.C.D|X:X::X:X) in",
6944 CLEAR_STR
6945 BGP_STR
6946 "BGP neighbor address to clear\n"
6947 "BGP IPv6 neighbor to clear\n"
6948 "Soft reconfig inbound update\n")
6950 return clear_bgp_soft_in (vty, AFI_IP6, SAFI_UNICAST, clear_peer, argv[0], 0);
6953 ALIAS (clear_bgp_peer_in,
6954 clear_bgp_ipv6_peer_in_cmd,
6955 "clear bgp ipv6 (A.B.C.D|X:X::X:X) in",
6956 CLEAR_STR
6957 BGP_STR
6958 "Address family\n"
6959 "BGP neighbor address to clear\n"
6960 "BGP IPv6 neighbor to clear\n"
6961 "Soft reconfig inbound update\n")
6963 DEFUN (clear_bgp_as_soft_in,
6964 clear_bgp_as_soft_in_cmd,
6965 "clear bgp <1-65535> soft in",
6966 CLEAR_STR
6967 BGP_STR
6968 "Clear peers with the AS number\n"
6969 "Soft reconfig\n"
6970 "Soft reconfig inbound update\n")
6972 return clear_bgp_soft_in (vty, AFI_IP6, SAFI_UNICAST, clear_as, argv[0], 1);
6975 ALIAS (clear_bgp_as_soft_in,
6976 clear_bgp_ipv6_as_soft_in_cmd,
6977 "clear bgp ipv6 <1-65535> soft in",
6978 CLEAR_STR
6979 BGP_STR
6980 "Address family\n"
6981 "Clear peers with the AS number\n"
6982 "Soft reconfig\n"
6983 "Soft reconfig inbound update\n")
6985 DEFUN (clear_bgp_as_in,
6986 clear_bgp_as_in_cmd,
6987 "clear bgp <1-65535> in",
6988 CLEAR_STR
6989 BGP_STR
6990 "Clear peers with the AS number\n"
6991 "Soft reconfig inbound update\n")
6993 return clear_bgp_soft_in (vty, AFI_IP6, SAFI_UNICAST, clear_as, argv[0], 0);
6996 ALIAS (clear_bgp_as_in,
6997 clear_bgp_ipv6_as_in_cmd,
6998 "clear bgp ipv6 <1-65535> in",
6999 CLEAR_STR
7000 BGP_STR
7001 "Address family\n"
7002 "Clear peers with the AS number\n"
7003 "Soft reconfig inbound update\n")
7005 DEFUN (clear_bgp_all_soft_in,
7006 clear_bgp_all_soft_in_cmd,
7007 "clear bgp * soft in",
7008 CLEAR_STR
7009 BGP_STR
7010 "Clear all peers\n"
7011 "Soft reconfig\n"
7012 "Soft reconfig inbound update\n")
7014 return clear_bgp_soft_in (vty, AFI_IP6, SAFI_UNICAST, clear_all, NULL, 1);
7017 ALIAS (clear_bgp_all_soft_in,
7018 clear_bgp_ipv6_all_soft_in_cmd,
7019 "clear bgp ipv6 * soft in",
7020 CLEAR_STR
7021 BGP_STR
7022 "Address family\n"
7023 "Clear all peers\n"
7024 "Soft reconfig\n"
7025 "Soft reconfig inbound update\n")
7027 DEFUN (clear_bgp_all_in,
7028 clear_bgp_all_in_cmd,
7029 "clear bgp * in",
7030 CLEAR_STR
7031 BGP_STR
7032 "Clear all peers\n"
7033 "Soft reconfig inbound update\n")
7035 return clear_bgp_soft_in (vty, AFI_IP6, SAFI_UNICAST, clear_all, NULL, 0);
7038 ALIAS (clear_bgp_all_in,
7039 clear_bgp_ipv6_all_in_cmd,
7040 "clear bgp ipv6 * in",
7041 CLEAR_STR
7042 BGP_STR
7043 "Address family\n"
7044 "Clear all peers\n"
7045 "Soft reconfig inbound update\n")
7047 DEFUN (clear_bgp_peer_soft_out,
7048 clear_bgp_peer_soft_out_cmd,
7049 "clear bgp (A.B.C.D|X:X::X:X) soft out",
7050 CLEAR_STR
7051 BGP_STR
7052 "BGP neighbor address to clear\n"
7053 "BGP IPv6 neighbor to clear\n"
7054 "Soft reconfig\n"
7055 "Soft reconfig outbound update\n")
7057 return clear_bgp_soft_out (vty, AFI_IP6, SAFI_UNICAST, clear_peer, argv[0]);
7060 ALIAS (clear_bgp_peer_soft_out,
7061 clear_bgp_ipv6_peer_soft_out_cmd,
7062 "clear bgp ipv6 (A.B.C.D|X:X::X:X) soft out",
7063 CLEAR_STR
7064 BGP_STR
7065 "Address family\n"
7066 "BGP neighbor address to clear\n"
7067 "BGP IPv6 neighbor to clear\n"
7068 "Soft reconfig\n"
7069 "Soft reconfig outbound update\n")
7071 ALIAS (clear_bgp_peer_soft_out,
7072 clear_bgp_peer_out_cmd,
7073 "clear bgp (A.B.C.D|X:X::X:X) out",
7074 CLEAR_STR
7075 BGP_STR
7076 "BGP neighbor address to clear\n"
7077 "BGP IPv6 neighbor to clear\n"
7078 "Soft reconfig outbound update\n")
7080 ALIAS (clear_bgp_peer_soft_out,
7081 clear_bgp_ipv6_peer_out_cmd,
7082 "clear bgp ipv6 (A.B.C.D|X:X::X:X) out",
7083 CLEAR_STR
7084 BGP_STR
7085 "Address family\n"
7086 "BGP neighbor address to clear\n"
7087 "BGP IPv6 neighbor to clear\n"
7088 "Soft reconfig outbound update\n")
7090 DEFUN (clear_bgp_as_soft_out,
7091 clear_bgp_as_soft_out_cmd,
7092 "clear bgp <1-65535> soft out",
7093 CLEAR_STR
7094 BGP_STR
7095 "Clear peers with the AS number\n"
7096 "Soft reconfig\n"
7097 "Soft reconfig outbound update\n")
7099 return clear_bgp_soft_out (vty, AFI_IP6, SAFI_UNICAST, clear_as, argv[0]);
7102 ALIAS (clear_bgp_as_soft_out,
7103 clear_bgp_ipv6_as_soft_out_cmd,
7104 "clear bgp ipv6 <1-65535> soft out",
7105 CLEAR_STR
7106 BGP_STR
7107 "Address family\n"
7108 "Clear peers with the AS number\n"
7109 "Soft reconfig\n"
7110 "Soft reconfig outbound update\n")
7112 ALIAS (clear_bgp_as_soft_out,
7113 clear_bgp_as_out_cmd,
7114 "clear bgp <1-65535> out",
7115 CLEAR_STR
7116 BGP_STR
7117 "Clear peers with the AS number\n"
7118 "Soft reconfig outbound update\n")
7120 ALIAS (clear_bgp_as_soft_out,
7121 clear_bgp_ipv6_as_out_cmd,
7122 "clear bgp ipv6 <1-65535> out",
7123 CLEAR_STR
7124 BGP_STR
7125 "Address family\n"
7126 "Clear peers with the AS number\n"
7127 "Soft reconfig outbound update\n")
7129 DEFUN (clear_bgp_all_soft_out,
7130 clear_bgp_all_soft_out_cmd,
7131 "clear bgp * soft out",
7132 CLEAR_STR
7133 BGP_STR
7134 "Clear all peers\n"
7135 "Soft reconfig\n"
7136 "Soft reconfig outbound update\n")
7138 return clear_bgp_soft_out (vty, AFI_IP6, SAFI_UNICAST, clear_all, NULL);
7141 ALIAS (clear_bgp_all_soft_out,
7142 clear_bgp_ipv6_all_soft_out_cmd,
7143 "clear bgp ipv6 * soft out",
7144 CLEAR_STR
7145 BGP_STR
7146 "Address family\n"
7147 "Clear all peers\n"
7148 "Soft reconfig\n"
7149 "Soft reconfig outbound update\n")
7151 ALIAS (clear_bgp_all_soft_out,
7152 clear_bgp_all_out_cmd,
7153 "clear bgp * out",
7154 CLEAR_STR
7155 BGP_STR
7156 "Clear all peers\n"
7157 "Soft reconfig outbound update\n")
7159 ALIAS (clear_bgp_all_soft_out,
7160 clear_bgp_ipv6_all_out_cmd,
7161 "clear bgp ipv6 * out",
7162 CLEAR_STR
7163 BGP_STR
7164 "Address family\n"
7165 "Clear all peers\n"
7166 "Soft reconfig outbound update\n")
7168 DEFUN (clear_bgp_peer_soft,
7169 clear_bgp_peer_soft_cmd,
7170 "clear bgp (A.B.C.D|X:X::X:X) soft",
7171 CLEAR_STR
7172 BGP_STR
7173 "BGP neighbor address to clear\n"
7174 "BGP IPv6 neighbor to clear\n"
7175 "Soft reconfig\n")
7177 if (clear_bgp_soft_out (vty, AFI_IP6, SAFI_UNICAST, clear_peer, argv[0]) == CMD_SUCCESS)
7178 clear_bgp_soft_in (vty, AFI_IP6, SAFI_UNICAST, clear_peer, argv[0], 0);
7180 return CMD_SUCCESS;
7183 ALIAS (clear_bgp_peer_soft,
7184 clear_bgp_ipv6_peer_soft_cmd,
7185 "clear bgp ipv6 (A.B.C.D|X:X::X:X) soft",
7186 CLEAR_STR
7187 BGP_STR
7188 "Address family\n"
7189 "BGP neighbor address to clear\n"
7190 "BGP IPv6 neighbor to clear\n"
7191 "Soft reconfig\n")
7193 DEFUN (clear_bgp_as_soft,
7194 clear_bgp_as_soft_cmd,
7195 "clear bgp <1-65535> soft",
7196 CLEAR_STR
7197 BGP_STR
7198 "Clear peers with the AS number\n"
7199 "Soft reconfig\n")
7201 if (clear_bgp_soft_out (vty, AFI_IP6, SAFI_UNICAST, clear_as, argv[0]) == CMD_SUCCESS)
7202 clear_bgp_soft_in (vty, AFI_IP6, SAFI_UNICAST, clear_as, argv[0], 0);
7204 return CMD_SUCCESS;
7207 ALIAS (clear_bgp_as_soft,
7208 clear_bgp_ipv6_as_soft_cmd,
7209 "clear bgp ipv6 <1-65535> soft",
7210 CLEAR_STR
7211 BGP_STR
7212 "Address family\n"
7213 "Clear peers with the AS number\n"
7214 "Soft reconfig\n")
7216 DEFUN (clear_bgp_all_soft,
7217 clear_bgp_all_soft_cmd,
7218 "clear bgp * soft",
7219 CLEAR_STR
7220 BGP_STR
7221 "Clear all peers\n"
7222 "Soft reconfig\n")
7224 if (clear_bgp_soft_out (vty, AFI_IP6, SAFI_UNICAST, clear_all, NULL) == CMD_SUCCESS)
7225 clear_bgp_soft_in (vty, AFI_IP6, SAFI_UNICAST, clear_all, NULL, 0);
7227 return CMD_SUCCESS;
7230 ALIAS (clear_bgp_all_soft,
7231 clear_bgp_ipv6_all_soft_cmd,
7232 "clear bgp ipv6 * soft",
7233 CLEAR_STR
7234 BGP_STR
7235 "Address family\n"
7236 "Clear all peers\n"
7237 "Soft reconfig\n")
7238 #endif /* HAVE_IPV6 */
7240 /* Show BGP peer's summary information. */
7242 bgp_show_summary (struct vty *vty, int afi, int safi)
7244 struct bgp *bgp;
7245 struct peer *peer;
7246 struct peer_conf *conf;
7247 struct listnode *nn;
7248 struct listnode *nm;
7249 int count = 0;
7250 char timebuf[BGP_UPTIME_LEN];
7251 int len;
7253 /* Header string for each address family. */
7254 static char header[] = "Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd";
7256 LIST_LOOP (bgp_list, bgp, nn)
7258 LIST_LOOP (bgp->peer_conf, conf, nm)
7260 peer = conf->peer;
7262 if (conf->afc[afi][safi])
7264 if (! count)
7266 vty_out (vty,
7267 "BGP router identifier %s, local AS number %d%s",
7268 inet_ntoa (bgp->id), bgp->as, VTY_NEWLINE);
7269 vty_out (vty,
7270 "%ld BGP AS-PATH entries%s", aspath_count (),
7271 VTY_NEWLINE);
7272 vty_out (vty,
7273 "%ld BGP community entries%s", community_count (),
7274 VTY_NEWLINE);
7276 if (CHECK_FLAG(bgp->config, BGP_CONFIG_DAMPENING))
7277 vty_out (vty, "Dampening enabled.%s", VTY_NEWLINE);
7278 vty_out (vty, "%s", VTY_NEWLINE);
7279 vty_out (vty, "%s%s", header, VTY_NEWLINE);
7281 count++;
7283 len = vty_out (vty, "%s", peer->host);
7284 len = 16 - len;
7285 if (len < 1)
7286 vty_out (vty, "%s%*s", VTY_NEWLINE, 16, " ");
7287 else
7288 vty_out (vty, "%*s", len, " ");
7290 switch (peer->version)
7292 case BGP_VERSION_4:
7293 vty_out (vty, "4 ");
7294 break;
7295 case BGP_VERSION_MP_4_DRAFT_00:
7296 vty_out (vty, "4-");
7297 break;
7300 vty_out (vty, "%5d %7d %7d %8d %4d %4ld ",
7301 peer->as,
7302 peer->open_in + peer->update_in +
7303 peer->keepalive_in + peer->notify_in + peer->refresh_in,
7304 peer->open_out + peer->update_out +
7305 peer->keepalive_out + peer->notify_out + peer->refresh_out,
7306 0, 0, peer->obuf->count);
7308 vty_out (vty, "%8s",
7309 peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN));
7311 if (peer->status == Established)
7313 vty_out (vty, " %8ld", conf->pcount[afi][safi]);
7315 else
7317 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
7318 vty_out (vty, " Idle (Admin)");
7319 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
7320 vty_out (vty, " Idle (PfxCt)");
7321 else
7322 vty_out (vty, " %-11s", LOOKUP(bgp_status_msg, peer->status));
7325 vty_out (vty, "%s", VTY_NEWLINE);
7330 if (count)
7331 vty_out (vty, "%sTotal number of neighbors %d%s", VTY_NEWLINE,
7332 count, VTY_NEWLINE);
7333 else
7334 vty_out (vty, "No %s neighbor is configured%s",
7335 afi == AFI_IP ? "IPv4" : "IPv6", VTY_NEWLINE);
7336 return CMD_SUCCESS;
7339 /* `show ip bgp summary' commands. */
7340 DEFUN (show_ip_bgp_summary,
7341 show_ip_bgp_summary_cmd,
7342 "show ip bgp summary",
7343 SHOW_STR
7344 IP_STR
7345 BGP_STR
7346 "Summary of BGP neighbor status\n")
7348 return bgp_show_summary (vty, AFI_IP, SAFI_UNICAST);
7351 DEFUN (show_ip_bgp_ipv4_summary,
7352 show_ip_bgp_ipv4_summary_cmd,
7353 "show ip bgp ipv4 (unicast|multicast) summary",
7354 SHOW_STR
7355 IP_STR
7356 BGP_STR
7357 "Address family\n"
7358 "Address Family modifier\n"
7359 "Address Family modifier\n"
7360 "Summary of BGP neighbor status\n")
7362 if (strncmp (argv[0], "m", 1) == 0)
7363 return bgp_show_summary (vty, AFI_IP, SAFI_MULTICAST);
7365 return bgp_show_summary (vty, AFI_IP, SAFI_UNICAST);
7368 DEFUN (show_ip_bgp_vpnv4_all_summary,
7369 show_ip_bgp_vpnv4_all_summary_cmd,
7370 "show ip bgp vpnv4 all summary",
7371 SHOW_STR
7372 IP_STR
7373 BGP_STR
7374 "Display VPNv4 NLRI specific information\n"
7375 "Display information about all VPNv4 NLRIs\n"
7376 "Summary of BGP neighbor status\n")
7378 return bgp_show_summary (vty, AFI_IP, SAFI_MPLS_VPN);
7381 DEFUN (show_ip_bgp_vpnv4_rd_summary,
7382 show_ip_bgp_vpnv4_rd_summary_cmd,
7383 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn summary",
7384 SHOW_STR
7385 IP_STR
7386 BGP_STR
7387 "Display VPNv4 NLRI specific information\n"
7388 "Display information for a route distinguisher\n"
7389 "VPN Route Distinguisher\n"
7390 "Summary of BGP neighbor status\n")
7392 int ret;
7393 struct prefix_rd prd;
7395 ret = str2prefix_rd (argv[0], &prd);
7396 if (! ret)
7398 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7399 return CMD_WARNING;
7402 return bgp_show_summary (vty, AFI_IP, SAFI_MPLS_VPN);
7405 #ifdef HAVE_IPV6
7406 DEFUN (show_bgp_summary,
7407 show_bgp_summary_cmd,
7408 "show bgp summary",
7409 SHOW_STR
7410 BGP_STR
7411 "Summary of BGP neighbor status\n")
7413 return bgp_show_summary (vty, AFI_IP6, SAFI_UNICAST);
7416 ALIAS (show_bgp_summary,
7417 show_bgp_ipv6_summary_cmd,
7418 "show bgp ipv6 summary",
7419 SHOW_STR
7420 BGP_STR
7421 "Address family\n"
7422 "Summary of BGP neighbor status\n")
7424 /* old command */
7425 DEFUN (show_ipv6_bgp_summary,
7426 show_ipv6_bgp_summary_cmd,
7427 "show ipv6 bgp summary",
7428 SHOW_STR
7429 IPV6_STR
7430 BGP_STR
7431 "Summary of BGP neighbor status\n")
7433 return bgp_show_summary (vty, AFI_IP6, SAFI_UNICAST);
7436 /* old command */
7437 DEFUN (show_ipv6_mbgp_summary,
7438 show_ipv6_mbgp_summary_cmd,
7439 "show ipv6 mbgp summary",
7440 SHOW_STR
7441 IPV6_STR
7442 MBGP_STR
7443 "Summary of BGP neighbor status\n")
7445 return bgp_show_summary (vty, AFI_IP6, SAFI_MULTICAST);
7447 #endif /* HAVE_IPV6 */
7449 /* Show BGP peer's information. */
7450 enum show_type
7452 show_all,
7453 show_peer
7456 /* Return next event time. */
7458 bgp_next_timer (struct thread *thread)
7460 struct timeval timer_now;
7461 gettimeofday (&timer_now, NULL);
7462 return thread->u.sands.tv_sec - timer_now.tv_sec;
7465 void
7466 bgp_show_peer_afi (struct vty *vty, struct peer_conf *conf, afi_t afi, safi_t safi)
7468 struct bgp_filter *filter;
7469 struct peer *p;
7471 p = conf->peer;
7472 filter = &conf->filter[afi][safi];
7474 vty_out (vty, " For address family: %s %s%s",
7475 afi == AFI_IP6 ? "IPv6" :
7476 safi == SAFI_MPLS_VPN ? "VPNv4" : "IPv4",
7477 safi == SAFI_MULTICAST ? "Multicast" : "Unicast",
7478 VTY_NEWLINE);
7479 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
7480 vty_out (vty, " Route-Reflector Client%s", VTY_NEWLINE);
7481 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
7482 vty_out (vty, " Route-Server Client%s", VTY_NEWLINE);
7483 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7484 vty_out (vty, " Inbound soft reconfiguration allowed%s", VTY_NEWLINE);
7485 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF))
7486 vty_out (vty, " NEXT_HOP is always this router%s", VTY_NEWLINE);
7487 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7488 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7490 vty_out (vty, " Community attribute sent to this neighbor");
7491 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7492 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7493 vty_out (vty, " (both)%s", VTY_NEWLINE);
7494 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7495 vty_out (vty, " (extended)%s", VTY_NEWLINE);
7496 else
7497 vty_out (vty, " (standard)%s", VTY_NEWLINE);
7499 if (filter->plist[FILTER_IN].name ||
7500 filter->dlist[FILTER_IN].name ||
7501 filter->aslist[FILTER_IN].name ||
7502 filter->map[FILTER_IN].name)
7503 vty_out (vty, " Inbound path policy configured%s", VTY_NEWLINE);
7504 if (filter->plist[FILTER_OUT].name ||
7505 filter->dlist[FILTER_OUT].name ||
7506 filter->aslist[FILTER_OUT].name ||
7507 filter->map[FILTER_OUT].name)
7508 vty_out (vty, " Outbound path policy configured%s", VTY_NEWLINE);
7510 /* prefix-list */
7511 if (filter->plist[FILTER_IN].name)
7512 vty_out (vty, " Incoming update prefix filter list is %s%s%s",
7513 filter->plist[FILTER_IN].plist ? "*" : "",
7514 filter->plist[FILTER_IN].name,
7515 VTY_NEWLINE);
7516 if (filter->plist[FILTER_OUT].name)
7517 vty_out (vty, " Outgoing update prefix filter list is %s%s%s",
7518 filter->plist[FILTER_OUT].plist ? "*" : "",
7519 filter->plist[FILTER_OUT].name,
7520 VTY_NEWLINE);
7522 /* distribute-list */
7523 if (filter->dlist[FILTER_IN].name)
7524 vty_out (vty, " Incoming update network filter list is %s%s%s",
7525 filter->dlist[FILTER_IN].alist ? "*" : "",
7526 filter->dlist[FILTER_IN].name,
7527 VTY_NEWLINE);
7528 if (filter->dlist[FILTER_OUT].name)
7529 vty_out (vty, " Outgoing update network filter list is %s%s%s",
7530 filter->dlist[FILTER_OUT].alist ? "*" : "",
7531 filter->dlist[FILTER_OUT].name,
7532 VTY_NEWLINE);
7534 /* filter-list. */
7535 if (filter->aslist[FILTER_IN].name)
7536 vty_out (vty, " Incoming update AS path filter list is %s%s%s",
7537 filter->aslist[FILTER_IN].aslist ? "*" : "",
7538 filter->aslist[FILTER_IN].name,
7539 VTY_NEWLINE);
7540 if (filter->aslist[FILTER_OUT].name)
7541 vty_out (vty, " Outgoing update AS path filter list is %s%s%s",
7542 filter->aslist[FILTER_OUT].aslist ? "*" : "",
7543 filter->aslist[FILTER_OUT].name,
7544 VTY_NEWLINE);
7546 /* route-map. */
7547 if (filter->map[FILTER_IN].name)
7548 vty_out (vty, " Route map for incoming advertisements is %s%s%s",
7549 filter->map[FILTER_IN].map ? "*" : "",
7550 filter->map[FILTER_IN].name,
7551 VTY_NEWLINE);
7552 if (filter->map[FILTER_OUT].name)
7553 vty_out (vty, " Route map for outgoing advertisements is %s%s%s",
7554 filter->map[FILTER_OUT].map ? "*" : "",
7555 filter->map[FILTER_OUT].name,
7556 VTY_NEWLINE);
7558 vty_out (vty, " %ld accepted prefixes",
7559 conf->pcount[afi][safi]);
7560 if (conf->pmax[afi][safi])
7562 vty_out (vty, ", maximum limit %ld%s",
7563 conf->pmax[afi][safi],
7564 conf->pmax_warning[afi][safi] ? " (warning-only)" : "");
7566 vty_out (vty, "%s", VTY_NEWLINE);
7568 vty_out (vty, "%s", VTY_NEWLINE);
7571 void
7572 bgp_show_peer (struct vty *vty, struct peer_conf *conf, afi_t afi, safi_t safi)
7574 char buf1[BUFSIZ];
7575 char timebuf[BGP_UPTIME_LEN];
7576 struct peer *p;
7578 p = conf->peer;
7580 /* Configured IP address. */
7581 vty_out (vty, "BGP neighbor is %s, ", p->host);
7582 vty_out (vty, "remote AS %d, ", p->as);
7583 vty_out (vty, "local AS %d, ", p->local_as);
7584 vty_out (vty, "%s link%s",
7585 p->as == p->local_as ? "internal" : "external",
7586 VTY_NEWLINE);
7588 /* Description. */
7589 if (p->desc)
7590 vty_out (vty, " Description: %s%s", p->desc, VTY_NEWLINE);
7592 /* Administrative shutdown. */
7593 if (CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN))
7594 vty_out (vty, " Administratively shut down%s", VTY_NEWLINE);
7596 /* BGP Version. */
7597 vty_out (vty, " BGP version 4");
7598 if (p->version == BGP_VERSION_MP_4_DRAFT_00)
7599 vty_out (vty, "(with draft-00 verion of multiporotocol extension)");
7600 vty_out (vty, ", remote router ID %s%s",
7601 inet_ntop (AF_INET, &p->remote_id, buf1, BUFSIZ),
7602 VTY_NEWLINE);
7604 /* Confederation */
7605 if (bgp_confederation_peers_check (conf->bgp, p->as))
7606 vty_out (vty, " Neighbor under common administration%s", VTY_NEWLINE);
7608 /* Status. */
7609 vty_out (vty, " BGP state = %s",
7610 CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN)
7611 ? "Idle" : LOOKUP(bgp_status_msg, p->status));
7612 if (p->status == Established)
7613 vty_out (vty, ", up for %8s",
7614 peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN));
7615 vty_out (vty, "%s", VTY_NEWLINE);
7617 /* read timer */
7618 vty_out (vty, " Last read %s", peer_uptime (p->readtime, timebuf, BGP_UPTIME_LEN));
7620 /* Configured timer values. */
7621 vty_out (vty, ", hold time is %d, keepalive interval is %d seconds%s",
7622 p->v_holdtime, p->v_keepalive, VTY_NEWLINE);
7623 if (p->config & PEER_CONFIG_TIMER)
7625 vty_out (vty, " Configured hold time is %d", p->holdtime);
7626 vty_out (vty, ", keepalive interval is %d seconds%s",
7627 p->keepalive, VTY_NEWLINE);
7630 /* Capability. */
7631 if (p->status == Established)
7633 if ((p->refresh_adv || p->refresh_nego_old || p->refresh_nego_new)
7634 || (p->afc_adv[AFI_IP][SAFI_UNICAST] || p->afc_recv[AFI_IP][SAFI_UNICAST])
7635 || (p->afc_adv[AFI_IP][SAFI_MULTICAST] || p->afc_recv[AFI_IP][SAFI_MULTICAST])
7636 #ifdef HAVE_IPV6
7637 || (p->afc_adv[AFI_IP6][SAFI_UNICAST] || p->afc_recv[AFI_IP6][SAFI_UNICAST])
7638 || (p->afc_adv[AFI_IP6][SAFI_MULTICAST] || p->afc_recv[AFI_IP6][SAFI_MULTICAST])
7639 #endif /* HAVE_IPV6 */
7640 || (p->afc_adv[AFI_IP][SAFI_MPLS_VPN] || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]))
7642 vty_out (vty, " Neighbor capabilities:%s", VTY_NEWLINE);
7644 /* Route Refresh */
7645 if (p->refresh_adv || p->refresh_nego_old || p->refresh_nego_new)
7647 vty_out (vty, " Route refresh:");
7648 if (p->refresh_adv)
7649 vty_out (vty, " advertised");
7650 if (p->refresh_nego_old || p->refresh_nego_new)
7652 if (p->refresh_adv)
7653 vty_out (vty, " and");
7654 vty_out (vty, " received");
7655 if (p->refresh_nego_old && p->refresh_nego_new)
7656 vty_out (vty, " (old and new)");
7657 else if (p->refresh_nego_old)
7658 vty_out (vty, " (old)");
7659 else
7660 vty_out (vty, " (new)");
7662 vty_out (vty, "%s", VTY_NEWLINE);
7665 /* IPv4 */
7666 if (p->afc_adv[AFI_IP][SAFI_UNICAST] || p->afc_recv[AFI_IP][SAFI_UNICAST])
7668 vty_out (vty, " Address family IPv4 Unicast:");
7669 if (p->afc_adv[AFI_IP][SAFI_UNICAST])
7670 vty_out (vty, " advertised");
7671 if (p->afc_recv[AFI_IP][SAFI_UNICAST])
7673 if (p->afc_adv[AFI_IP][SAFI_UNICAST])
7674 vty_out (vty, " and");
7675 vty_out (vty, " received");
7677 vty_out (vty, "%s", VTY_NEWLINE);
7679 if (p->afc_adv[AFI_IP][SAFI_MULTICAST] || p->afc_recv[AFI_IP][SAFI_MULTICAST])
7681 vty_out (vty, " Address family IPv4 Multicast:");
7682 if (p->afc_adv[AFI_IP][SAFI_MULTICAST])
7683 vty_out (vty, " advertised");
7684 if (p->afc_recv[AFI_IP][SAFI_MULTICAST])
7686 if (p->afc_adv[AFI_IP][SAFI_MULTICAST])
7687 vty_out (vty, " and");
7688 vty_out (vty, " received");
7690 vty_out (vty, "%s", VTY_NEWLINE);
7692 if (p->afc_adv[AFI_IP][SAFI_MPLS_VPN] || p->afc_recv[AFI_IP][SAFI_MPLS_VPN])
7694 vty_out (vty, " Address family VPNv4 Unicast:");
7695 if (p->afc_adv[AFI_IP][SAFI_MPLS_VPN])
7696 vty_out (vty, " advertised");
7697 if (p->afc_recv[AFI_IP][SAFI_MPLS_VPN])
7699 if (p->afc_adv[AFI_IP][SAFI_MPLS_VPN])
7700 vty_out (vty, " and");
7701 vty_out (vty, " received");
7703 vty_out (vty, "%s", VTY_NEWLINE);
7705 /* IPv6 */
7706 #ifdef HAVE_IPV6
7707 if (p->afc_adv[AFI_IP6][SAFI_UNICAST] || p->afc_recv[AFI_IP6][SAFI_UNICAST])
7709 vty_out (vty, " Address family IPv6 Unicast:");
7710 if (p->afc_adv[AFI_IP6][SAFI_UNICAST])
7711 vty_out (vty, " advertised");
7712 if (p->afc_recv[AFI_IP6][SAFI_UNICAST])
7714 if (p->afc_adv[AFI_IP6][SAFI_UNICAST])
7715 vty_out (vty, " and");
7716 vty_out (vty, " received");
7718 vty_out (vty, "%s", VTY_NEWLINE);
7720 if (p->afc_adv[AFI_IP6][SAFI_MULTICAST] || p->afc_recv[AFI_IP6][SAFI_MULTICAST])
7722 vty_out (vty, " Address family IPv6 Multicast:");
7723 if (p->afc_adv[AFI_IP6][SAFI_MULTICAST])
7724 vty_out (vty, " advertised");
7725 if (p->afc_recv[AFI_IP6][SAFI_MULTICAST])
7727 if (p->afc_adv[AFI_IP6][SAFI_MULTICAST])
7728 vty_out (vty, " and");
7729 vty_out (vty, " received");
7731 vty_out (vty, "%s", VTY_NEWLINE);
7733 #endif /* HAVE_IPV6 */
7737 /* Packet counts. */
7738 vty_out(vty, " Received %d messages, %d notifications, %d in queue%s",
7739 p->open_in + p->update_in + p->keepalive_in,
7740 p->notify_in, 0, VTY_NEWLINE);
7741 vty_out(vty, " Sent %d messages, %d notifications, %ld in queue%s",
7742 p->open_out + p->update_out + p->keepalive_out,
7743 p->notify_out, p->obuf->count, VTY_NEWLINE);
7744 vty_out(vty, " Route refresh request: received %d, sent %d%s",
7745 p->refresh_in, p->refresh_out, VTY_NEWLINE);
7747 /* advertisement-interval (Current not supported)*/
7748 vty_out (vty, " Minimum time between advertisement runs is 0 seconds%s",
7749 VTY_NEWLINE);
7751 /* Default weight */
7752 if (p->weight)
7753 vty_out (vty, " Default weight %d%s", p->weight,
7754 VTY_NEWLINE);
7756 vty_out (vty, "%s", VTY_NEWLINE);
7758 /* Address Family Information */
7759 if (p->afc[AFI_IP][SAFI_UNICAST])
7760 bgp_show_peer_afi (vty, conf, AFI_IP, SAFI_UNICAST);
7761 if (p->afc[AFI_IP][SAFI_MULTICAST])
7762 bgp_show_peer_afi (vty, conf, AFI_IP, SAFI_MULTICAST);
7763 if (p->afc[AFI_IP][SAFI_MPLS_VPN])
7764 bgp_show_peer_afi (vty, conf, AFI_IP, SAFI_MPLS_VPN);
7765 #ifdef HAVE_IPV6
7766 if (p->afc[AFI_IP6][SAFI_UNICAST])
7767 bgp_show_peer_afi (vty, conf, AFI_IP6, SAFI_UNICAST);
7768 if (p->afc[AFI_IP6][SAFI_MULTICAST])
7769 bgp_show_peer_afi (vty, conf, AFI_IP6, SAFI_MULTICAST);
7770 #endif /* HAVE_IPV6 */
7772 vty_out (vty, " Connections established %d; dropped %d%s",
7773 p->established, p->dropped,
7774 VTY_NEWLINE);
7776 if (CHECK_FLAG (p->sflags, PEER_STATUS_PREFIX_OVERFLOW))
7778 vty_out (vty, " Peer had exceeded the max. no. of prefixes configured.%s", VTY_NEWLINE);
7779 vty_out (vty, " Reduce the no. of prefix and clear ip bgp %s to restore peering%s",
7780 p->host, VTY_NEWLINE);
7783 /* EBGP Multihop */
7784 if (peer_sort (p) == BGP_PEER_EBGP && p->ttl > 1)
7785 vty_out (vty, " External BGP neighbor may be up to %d hops away.%s",
7786 p->ttl, VTY_NEWLINE);
7788 /* Local address. */
7789 if (p->su_local)
7791 vty_out (vty, "Local host: %s, Local port: %d%s",
7792 sockunion2str (p->su_local, buf1, SU_ADDRSTRLEN),
7793 ntohs (p->su_local->sin.sin_port),
7794 VTY_NEWLINE);
7797 /* Remote address. */
7798 if (p->su_remote)
7800 vty_out (vty, "Foreign host: %s, Foreign port: %d%s",
7801 sockunion2str (p->su_remote, buf1, SU_ADDRSTRLEN),
7802 ntohs (p->su_remote->sin.sin_port),
7803 VTY_NEWLINE);
7806 /* Nexthop display. */
7807 if (p->su_local)
7809 vty_out (vty, "Nexthop: %s%s",
7810 inet_ntop (AF_INET, &p->nexthop.v4, buf1, BUFSIZ),
7811 VTY_NEWLINE);
7812 #ifdef HAVE_IPV6
7813 vty_out (vty, "Nexthop global: %s%s",
7814 inet_ntop (AF_INET6, &p->nexthop.v6_global, buf1, BUFSIZ),
7815 VTY_NEWLINE);
7816 vty_out (vty, "Nexthop local: %s%s",
7817 inet_ntop (AF_INET6, &p->nexthop.v6_local, buf1, BUFSIZ),
7818 VTY_NEWLINE);
7819 vty_out (vty, "BGP connection: %s%s",
7820 p->shared_network ? "shared network" : "non shared network",
7821 VTY_NEWLINE);
7822 #endif /* HAVE_IPV6 */
7825 /* Timer information. */
7826 if (p->t_start)
7827 vty_out (vty, "Next start timer due in %d seconds%s",
7828 bgp_next_timer (p->t_start), VTY_NEWLINE);
7829 if (p->t_connect)
7830 vty_out (vty, "Next connect timer due in %d seconds%s",
7831 bgp_next_timer (p->t_connect), VTY_NEWLINE);
7833 vty_out (vty, "Read thread: %s Write thread: %s%s",
7834 p->t_read ? "on" : "off",
7835 p->t_write ? "on" : "off",
7836 VTY_NEWLINE);
7838 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
7839 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
7840 bgp_capability_vty_out (vty, p);
7842 vty_out (vty, "%s", VTY_NEWLINE);
7846 bgp_show_neighbor (struct vty *vty, int afi, int safi, enum show_type type,
7847 char *ip_str)
7849 struct listnode *nn, *nm;
7850 struct bgp *bgp;
7851 struct peer_conf *conf;
7852 union sockunion su;
7853 int ret;
7854 int find = 0;
7856 if (ip_str)
7858 ret = str2sockunion (ip_str, &su);
7859 if (ret < 0)
7861 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
7862 return CMD_WARNING;
7866 LIST_LOOP (bgp_list, bgp, nn)
7868 LIST_LOOP (bgp->peer_conf, conf, nm)
7870 switch (type)
7872 case show_all:
7873 if (conf->afc[afi][safi])
7874 bgp_show_peer (vty, conf, afi, safi);
7875 break;
7876 case show_peer:
7877 if (conf->afc[afi][safi]
7878 && sockunion_same (&conf->peer->su, &su))
7880 find = 1;
7881 bgp_show_peer (vty, conf, afi, safi);
7883 break;
7888 if (type == show_peer && ! find)
7889 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
7891 return CMD_SUCCESS;
7894 DEFUN (show_ip_bgp_neighbors,
7895 show_ip_bgp_neighbors_cmd,
7896 "show ip bgp neighbors",
7897 SHOW_STR
7898 IP_STR
7899 BGP_STR
7900 "Detailed information on TCP and BGP neighbor connections\n")
7902 return bgp_show_neighbor (vty, AFI_IP, SAFI_UNICAST, show_all, NULL);
7905 DEFUN (show_ip_bgp_ipv4_neighbors,
7906 show_ip_bgp_ipv4_neighbors_cmd,
7907 "show ip bgp ipv4 (unicast|multicast) neighbors",
7908 SHOW_STR
7909 IP_STR
7910 BGP_STR
7911 "Address family\n"
7912 "Address Family modifier\n"
7913 "Address Family modifier\n"
7914 "Detailed information on TCP and BGP neighbor connections\n")
7916 if (strncmp (argv[0], "m", 1) == 0)
7917 return bgp_show_neighbor (vty, AFI_IP, SAFI_MULTICAST, show_all, NULL);
7919 return bgp_show_neighbor (vty, AFI_IP, SAFI_UNICAST, show_all, NULL);
7922 DEFUN (show_ip_bgp_neighbors_peer,
7923 show_ip_bgp_neighbors_peer_cmd,
7924 "show ip bgp neighbors (A.B.C.D|X:X::X:X)",
7925 SHOW_STR
7926 IP_STR
7927 BGP_STR
7928 "Detailed information on TCP and BGP neighbor connections\n"
7929 "Neighbor to display information about\n"
7930 "Neighbor to display information about\n")
7932 return bgp_show_neighbor (vty, AFI_IP, SAFI_UNICAST, show_peer, argv[0]);
7935 DEFUN (show_ip_bgp_ipv4_neighbors_peer,
7936 show_ip_bgp_ipv4_neighbors_peer_cmd,
7937 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X)",
7938 SHOW_STR
7939 IP_STR
7940 BGP_STR
7941 "Address family\n"
7942 "Address Family modifier\n"
7943 "Address Family modifier\n"
7944 "Detailed information on TCP and BGP neighbor connections\n"
7945 "Neighbor to display information about\n"
7946 "Neighbor to display information about\n")
7948 if (strncmp (argv[0], "m", 1) == 0)
7949 return bgp_show_neighbor (vty, AFI_IP, SAFI_MULTICAST, show_peer, argv[1]);
7951 return bgp_show_neighbor (vty, AFI_IP, SAFI_UNICAST, show_peer, argv[1]);
7954 DEFUN (show_ip_bgp_vpnv4_all_neighbors,
7955 show_ip_bgp_vpnv4_all_neighbors_cmd,
7956 "show ip bgp vpnv4 all neighbors",
7957 SHOW_STR
7958 IP_STR
7959 BGP_STR
7960 "Display VPNv4 NLRI specific information\n"
7961 "Display information about all VPNv4 NLRIs\n"
7962 "Detailed information on TCP and BGP neighbor connections\n")
7964 return bgp_show_neighbor (vty, AFI_IP, SAFI_MPLS_VPN, show_all, NULL);
7967 DEFUN (show_ip_bgp_vpnv4_rd_neighbors,
7968 show_ip_bgp_vpnv4_rd_neighbors_cmd,
7969 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors",
7970 SHOW_STR
7971 IP_STR
7972 BGP_STR
7973 "Display VPNv4 NLRI specific information\n"
7974 "Display information for a route distinguisher\n"
7975 "VPN Route Distinguisher\n"
7976 "Detailed information on TCP and BGP neighbor connections\n")
7978 int ret;
7979 struct prefix_rd prd;
7981 ret = str2prefix_rd (argv[0], &prd);
7982 if (! ret)
7984 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7985 return CMD_WARNING;
7988 return bgp_show_neighbor (vty, AFI_IP, SAFI_MPLS_VPN, show_all, NULL);
7991 DEFUN (show_ip_bgp_vpnv4_all_neighbors_peer,
7992 show_ip_bgp_vpnv4_all_neighbors_peer_cmd,
7993 "show ip bgp vpnv4 all neighbors A.B.C.D",
7994 SHOW_STR
7995 IP_STR
7996 BGP_STR
7997 "Display VPNv4 NLRI specific information\n"
7998 "Display information about all VPNv4 NLRIs\n"
7999 "Detailed information on TCP and BGP neighbor connections\n"
8000 "Neighbor to display information about\n")
8002 return bgp_show_neighbor (vty, AFI_IP, SAFI_MPLS_VPN, show_peer, argv[0]);
8005 DEFUN (show_ip_bgp_vpnv4_rd_neighbors_peer,
8006 show_ip_bgp_vpnv4_rd_neighbors_peer_cmd,
8007 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D",
8008 SHOW_STR
8009 IP_STR
8010 BGP_STR
8011 "Display VPNv4 NLRI specific information\n"
8012 "Display information about all VPNv4 NLRIs\n"
8013 "Detailed information on TCP and BGP neighbor connections\n"
8014 "Neighbor to display information about\n")
8016 int ret;
8017 struct prefix_rd prd;
8019 ret = str2prefix_rd (argv[0], &prd);
8020 if (! ret)
8022 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
8023 return CMD_WARNING;
8026 return bgp_show_neighbor (vty, AFI_IP, SAFI_MPLS_VPN, show_peer, argv[1]);
8029 #ifdef HAVE_IPV6
8030 DEFUN (show_bgp_neighbors,
8031 show_bgp_neighbors_cmd,
8032 "show bgp neighbors",
8033 SHOW_STR
8034 BGP_STR
8035 "Detailed information on TCP and BGP neighbor connections\n")
8037 return bgp_show_neighbor (vty, AFI_IP6, SAFI_UNICAST, show_all, NULL);
8040 ALIAS (show_bgp_neighbors,
8041 show_bgp_ipv6_neighbors_cmd,
8042 "show bgp ipv6 neighbors",
8043 SHOW_STR
8044 BGP_STR
8045 "Address family\n"
8046 "Detailed information on TCP and BGP neighbor connections\n")
8048 /* old command */
8049 DEFUN (show_ipv6_bgp_neighbors,
8050 show_ipv6_bgp_neighbors_cmd,
8051 "show ipv6 bgp neighbors",
8052 SHOW_STR
8053 IPV6_STR
8054 BGP_STR
8055 "Detailed information on TCP and BGP neighbor connections\n")
8057 return bgp_show_neighbor (vty, AFI_IP6, SAFI_UNICAST, show_all, NULL);
8060 DEFUN (show_bgp_neighbors_peer,
8061 show_bgp_neighbors_peer_cmd,
8062 "show bgp neighbors (A.B.C.D|X:X::X:X)",
8063 SHOW_STR
8064 BGP_STR
8065 "Detailed information on TCP and BGP neighbor connections\n"
8066 "Neighbor to display information about\n"
8067 "Neighbor to display information about\n")
8069 return bgp_show_neighbor (vty, AFI_IP6, SAFI_UNICAST, show_peer, argv[0]);
8072 ALIAS (show_bgp_neighbors_peer,
8073 show_bgp_ipv6_neighbors_peer_cmd,
8074 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X)",
8075 SHOW_STR
8076 BGP_STR
8077 "Address family\n"
8078 "Detailed information on TCP and BGP neighbor connections\n"
8079 "Neighbor to display information about\n"
8080 "Neighbor to display information about\n")
8082 /* old command */
8083 DEFUN (show_ipv6_bgp_neighbors_peer,
8084 show_ipv6_bgp_neighbors_peer_cmd,
8085 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X)",
8086 SHOW_STR
8087 IPV6_STR
8088 BGP_STR
8089 "Detailed information on TCP and BGP neighbor connections\n"
8090 "Neighbor to display information about\n"
8091 "Neighbor to display information about\n")
8093 return bgp_show_neighbor (vty, AFI_IP6, SAFI_UNICAST, show_peer, argv[0]);
8096 /* old command */
8097 DEFUN (show_ipv6_mbgp_neighbors,
8098 show_ipv6_mbgp_neighbors_cmd,
8099 "show ipv6 mbgp neighbors",
8100 SHOW_STR
8101 IPV6_STR
8102 MBGP_STR
8103 "Detailed information on TCP and BGP neighbor connections\n")
8105 return bgp_show_neighbor (vty, AFI_IP6, SAFI_MULTICAST, show_all, NULL);
8108 /* old command */
8109 DEFUN (show_ipv6_mbgp_neighbors_peer,
8110 show_ipv6_mbgp_neighbors_peer_cmd,
8111 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X)",
8112 SHOW_STR
8113 IPV6_STR
8114 MBGP_STR
8115 "Detailed information on TCP and BGP neighbor connections\n"
8116 "Neighbor to display information about\n"
8117 "Neighbor to display information about\n")
8119 return bgp_show_neighbor (vty, AFI_IP6, SAFI_MULTICAST, show_peer, argv[0]);
8121 #endif /* HAVE_IPV6 */
8123 /* Show BGP's AS paths internal data. There are both `show ip bgp
8124 paths' and `show ip mbgp paths'. Those functions results are the
8125 same.*/
8126 DEFUN (show_ip_bgp_paths,
8127 show_ip_bgp_paths_cmd,
8128 "show ip bgp paths",
8129 SHOW_STR
8130 IP_STR
8131 BGP_STR
8132 "Path information\n")
8134 vty_out (vty, "Address Refcnt Path%s", VTY_NEWLINE);
8135 aspath_print_all_vty (vty);
8136 return CMD_SUCCESS;
8139 DEFUN (show_ip_bgp_ipv4_paths,
8140 show_ip_bgp_ipv4_paths_cmd,
8141 "show ip bgp ipv4 (unicast|multicast) paths",
8142 SHOW_STR
8143 IP_STR
8144 BGP_STR
8145 "Address family\n"
8146 "Address Family modifier\n"
8147 "Address Family modifier\n"
8148 "Path information\n")
8150 vty_out (vty, "Address Refcnt Path\r\n");
8151 aspath_print_all_vty (vty);
8153 return CMD_SUCCESS;
8156 /* Show BGP's community internal data. */
8157 DEFUN (show_ip_bgp_community_info,
8158 show_ip_bgp_community_info_cmd,
8159 "show ip bgp community-info",
8160 SHOW_STR
8161 IP_STR
8162 BGP_STR
8163 "List all bgp community information\n")
8165 vty_out (vty, "Address Refcnt Community%s", VTY_NEWLINE);
8166 community_print_all_vty (vty);
8167 return CMD_SUCCESS;
8170 DEFUN (show_ip_bgp_attr_info,
8171 show_ip_bgp_attr_info_cmd,
8172 "show ip bgp attribute-info",
8173 SHOW_STR
8174 IP_STR
8175 BGP_STR
8176 "List all bgp attribute information\n")
8178 void attrhash_dump (struct vty *);
8180 attrhash_dump (vty);
8181 return CMD_SUCCESS;
8184 void
8185 bgp_config_write_filter (struct vty *vty, struct bgp_filter *filter,
8186 char *addr)
8188 /* distribute-list. */
8189 if (filter->dlist[FILTER_IN].name)
8190 vty_out (vty, " neighbor %s distribute-list %s in%s", addr,
8191 filter->dlist[FILTER_IN].name, VTY_NEWLINE);
8192 if (filter->dlist[FILTER_OUT].name)
8193 vty_out (vty, " neighbor %s distribute-list %s out%s", addr,
8194 filter->dlist[FILTER_OUT].name, VTY_NEWLINE);
8196 /* prefix-list. */
8197 if (filter->plist[FILTER_IN].name)
8198 vty_out (vty, " neighbor %s prefix-list %s in%s", addr,
8199 filter->plist[FILTER_IN].name, VTY_NEWLINE);
8200 if (filter->plist[FILTER_OUT].name)
8201 vty_out (vty, " neighbor %s prefix-list %s out%s", addr,
8202 filter->plist[FILTER_OUT].name, VTY_NEWLINE);
8204 /* filter-list. */
8205 if (filter->aslist[FILTER_IN].name)
8206 vty_out (vty, " neighbor %s filter-list %s in%s", addr,
8207 filter->aslist[FILTER_IN].name, VTY_NEWLINE);
8208 if (filter->aslist[FILTER_OUT].name)
8209 vty_out (vty, " neighbor %s filter-list %s out%s", addr,
8210 filter->aslist[FILTER_OUT].name, VTY_NEWLINE);
8212 /* route-map. */
8213 if (filter->map[FILTER_IN].name)
8214 vty_out (vty, " neighbor %s route-map %s in%s", addr,
8215 filter->map[FILTER_IN].name, VTY_NEWLINE);
8216 if (filter->map[FILTER_OUT].name)
8217 vty_out (vty, " neighbor %s route-map %s out%s", addr,
8218 filter->map[FILTER_OUT].name, VTY_NEWLINE);
8221 /* BGP peer configuration display function. */
8222 void
8223 bgp_config_write_peer (struct vty *vty, struct bgp *bgp,
8224 struct peer_conf *conf, afi_t afi, safi_t safi)
8226 struct peer *peer;
8227 char addr[SU_ADDRSTRLEN];
8228 char buf[SU_ADDRSTRLEN];
8229 struct bgp_filter *filter;
8231 peer = conf->peer;
8232 filter = &conf->filter[afi][safi];
8233 sockunion2str (&peer->su, addr, SU_ADDRSTRLEN);
8235 /************************************
8236 ****** Global to the neighbor ******
8237 ************************************/
8238 if (afi == AFI_IP && safi == SAFI_UNICAST)
8240 /* remote-as. */
8241 vty_out (vty, " neighbor %s remote-as %d%s", addr, peer->as,
8242 VTY_NEWLINE);
8244 /* Description. */
8245 if (peer->desc)
8246 vty_out (vty, " neighbor %s description %s%s", addr, peer->desc,
8247 VTY_NEWLINE);
8249 /* Shutdown. */
8250 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
8251 vty_out (vty, " neighbor %s shutdown%s", addr, VTY_NEWLINE);
8253 /* BGP port. */
8254 if (peer->port != BGP_PORT_DEFAULT)
8255 vty_out (vty, " neighbor %s port %d%s", addr, peer->port,
8256 VTY_NEWLINE);
8258 /* Local interface name. */
8259 if (peer->ifname)
8260 vty_out (vty, " neighbor %s interface %s%s", addr, peer->ifname,
8261 VTY_NEWLINE);
8263 /* Passive. */
8264 if (CHECK_FLAG (peer->flags, PEER_FLAG_PASSIVE))
8265 vty_out (vty, " neighbor %s passive%s", addr, VTY_NEWLINE);
8267 /* ebgp-multihop print. */
8268 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
8269 vty_out (vty, " neighbor %s ebgp-multihop %d%s", addr, peer->ttl,
8270 VTY_NEWLINE);
8272 /* Update-source. */
8273 if (peer->update_if)
8274 vty_out (vty, " neighbor %s update-source %s%s", addr,
8275 peer->update_if, VTY_NEWLINE);
8276 if (peer->update_source)
8277 vty_out (vty, " neighbor %s update-source %s%s", addr,
8278 sockunion2str (peer->update_source, buf, SU_ADDRSTRLEN),
8279 VTY_NEWLINE);
8281 /* BGP version print. */
8282 if (peer->version == BGP_VERSION_MP_4_DRAFT_00)
8283 vty_out (vty, " neighbor %s version %s%s",
8284 addr,"4-", VTY_NEWLINE);
8286 /* timers. */
8287 if (peer->config & PEER_CONFIG_TIMER)
8288 vty_out (vty, " neighbor %s timers %d %d%s", addr,
8289 peer->keepalive, peer->holdtime, VTY_NEWLINE);
8290 if (peer->config & PEER_CONFIG_CONNECT)
8291 vty_out (vty, " neighbor %s timers connect %d%s", addr,
8292 peer->connect, VTY_NEWLINE);
8294 /* Default weight. */
8295 if (peer->weight)
8296 vty_out (vty, " neighbor %s weight %d%s", addr, peer->weight,
8297 VTY_NEWLINE);
8299 /* Route refresh. */
8300 if (! CHECK_FLAG (peer->flags, PEER_FLAG_CAPABILITY_ROUTE_REFRESH))
8301 vty_out (vty, " no neighbor %s capability route-refresh%s", addr,
8302 VTY_NEWLINE);
8304 /* dont capability negotiation. */
8305 if (CHECK_FLAG (peer->flags, PEER_FLAG_DONT_CAPABILITY))
8306 vty_out (vty, " neighbor %s dont-capability-negotiate%s", addr,
8307 VTY_NEWLINE);
8309 /* override capability negotiation. */
8310 if (CHECK_FLAG (peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY))
8311 vty_out (vty, " neighbor %s override-capability%s", addr,
8312 VTY_NEWLINE);
8314 /* strict capability negotiation. */
8315 if (CHECK_FLAG (peer->flags, PEER_FLAG_STRICT_CAP_MATCH))
8316 vty_out (vty, " neighbor %s strict-capability-match%s", addr,
8317 VTY_NEWLINE);
8319 if (CHECK_FLAG (bgp->config, BGP_CONFIG_NO_DEFAULT_IPV4))
8321 if (conf->afc[AFI_IP][SAFI_UNICAST])
8322 vty_out (vty, " neighbor %s activate%s", addr, VTY_NEWLINE);
8324 else
8326 if (! conf->afc[AFI_IP][SAFI_UNICAST])
8327 vty_out (vty, " no neighbor %s activate%s", addr, VTY_NEWLINE);
8332 /************************************
8333 ****** Per AF to the neighbor ******
8334 ************************************/
8336 if (! (afi == AFI_IP && safi == SAFI_UNICAST))
8337 vty_out (vty, " neighbor %s activate%s", addr, VTY_NEWLINE);
8339 /* Route reflector client. */
8340 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
8341 vty_out (vty, " neighbor %s route-reflector-client%s", addr, VTY_NEWLINE);
8343 /* Nexthop self. */
8344 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF))
8345 vty_out (vty, " neighbor %s next-hop-self%s", addr, VTY_NEWLINE);
8347 /* send-community print. */
8348 if (! (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8349 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY)))
8351 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8352 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
8353 vty_out (vty, " no neighbor %s send-community both%s",
8354 addr, VTY_NEWLINE);
8355 else if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
8356 vty_out (vty, " no neighbor %s send-community extended%s",
8357 addr, VTY_NEWLINE);
8358 else
8359 vty_out (vty, " no neighbor %s send-community%s",
8360 addr, VTY_NEWLINE);
8363 /* Default information */
8364 if (CHECK_FLAG (peer->flags, PEER_FLAG_DEFAULT_ORIGINATE)
8365 && (afi == AFI_IP && safi == SAFI_UNICAST))
8366 vty_out (vty, " neighbor %s default-originate%s", addr, VTY_NEWLINE);
8368 /* Soft reconfiguration inbound. */
8369 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8370 vty_out (vty, " neighbor %s soft-reconfiguration inbound%s", addr,
8371 VTY_NEWLINE);
8373 /* maximum-prefix. */
8374 if (conf->pmax[afi][safi])
8375 vty_out (vty, " neighbor %s maximum-prefix %ld%s%s",
8376 addr, conf->pmax[afi][safi],
8377 conf->pmax_warning[afi][safi] ? " warning-only" : "",
8378 VTY_NEWLINE);
8380 /* Route server client. */
8381 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
8382 vty_out (vty, " neighbor %s route-server-client%s", addr, VTY_NEWLINE);
8384 /* translate-update. */
8385 if (peer->translate_update
8386 && (afi == AFI_IP && safi == SAFI_UNICAST))
8388 vty_out (vty, " neighbor %s", addr);
8390 if (peer->translate_update == SAFI_UNICAST_MULTICAST)
8391 vty_out (vty, " translate-update nlri unicast multicast%s",
8392 VTY_NEWLINE);
8393 else if (peer->translate_update == SAFI_MULTICAST)
8394 vty_out (vty, " translate-update nlri multicast%s",
8395 VTY_NEWLINE);
8398 /* Filter. */
8399 bgp_config_write_filter (vty, filter, addr);
8401 /* transparent-as. */
8402 if (CHECK_FLAG (peer->flags, PEER_FLAG_TRANSPARENT_AS)
8403 && (afi == AFI_IP && safi == SAFI_UNICAST))
8404 vty_out (vty, " neighbor %s transparent-as%s", addr, VTY_NEWLINE);
8406 /* transparent-nexthop. */
8407 if (CHECK_FLAG (peer->flags, PEER_FLAG_TRANSPARENT_NEXTHOP)
8408 && (afi == AFI_IP && safi == SAFI_UNICAST))
8409 vty_out (vty, " neighbor %s transparent-nexthop%s", addr,
8410 VTY_NEWLINE);
8413 /* Display "address-family" configuration header. */
8414 void
8415 bgp_config_write_family_header (struct vty *vty, afi_t afi, safi_t safi,
8416 int *write)
8418 if (*write)
8419 return;
8421 if (afi == AFI_IP && safi == SAFI_UNICAST)
8422 return;
8424 vty_out (vty, "!%s address-family ", VTY_NEWLINE);
8426 if (afi == AFI_IP)
8428 if (safi == SAFI_MULTICAST)
8429 vty_out (vty, "ipv4 multicast");
8430 else if (safi == SAFI_MPLS_VPN)
8431 vty_out (vty, "vpnv4 unicast");
8433 else if (afi == AFI_IP6)
8434 vty_out (vty, "ipv6");
8436 vty_out (vty, "%s", VTY_NEWLINE);
8438 *write = 1;
8441 /* Address family based peer configuration display. */
8443 bgp_config_write_family (struct vty *vty, struct bgp *bgp, afi_t afi,
8444 safi_t safi)
8446 int write = 0;
8447 struct peer_conf *conf;
8448 struct listnode *nn;
8450 bgp_config_write_network (vty, bgp, afi, safi, &write);
8452 bgp_config_write_redistribute (vty, bgp, afi, safi, &write);
8454 LIST_LOOP (bgp->peer_conf, conf, nn)
8456 if (conf->afc[afi][safi])
8458 bgp_config_write_family_header (vty, afi, safi, &write);
8459 bgp_config_write_peer (vty, bgp, conf, afi, safi);
8462 if (write)
8463 vty_out (vty, " exit-address-family%s", VTY_NEWLINE);
8465 return write;
8469 bgp_config_write (struct vty *vty)
8471 int write = 0;
8472 struct bgp *bgp;
8473 struct peer_group *group;
8474 struct peer_conf *conf;
8475 struct listnode *nn, *nm, *no;
8477 /* BGP Multiple instance. */
8478 if (bgp_multiple_instance)
8480 vty_out (vty, "bgp multiple-instance%s", VTY_NEWLINE);
8481 vty_out (vty, "!%s", VTY_NEWLINE);
8484 /* BGP configuration. */
8485 LIST_LOOP (bgp_list, bgp, nn)
8487 if (write)
8488 vty_out (vty, "!%s", VTY_NEWLINE);
8490 /* Router bgp ASN */
8491 vty_out (vty, "router bgp %d", bgp->as);
8493 if (bgp_multiple_instance)
8495 if (bgp->name)
8496 vty_out (vty, " view %s", bgp->name);
8498 vty_out (vty, "%s", VTY_NEWLINE);
8500 /* BGP router ID. */
8501 if (CHECK_FLAG (bgp->config, BGP_CONFIG_ROUTER_ID))
8502 vty_out (vty, " bgp router-id %s%s", inet_ntoa (bgp->id),
8503 VTY_NEWLINE);
8505 /* BGP configuration. */
8506 if (CHECK_FLAG (bgp->config, BGP_CONFIG_ALWAYS_COMPARE_MED))
8507 vty_out (vty, " bgp always-compare-med%s", VTY_NEWLINE);
8509 /* BGP default ipv4-unicast. */
8510 if (CHECK_FLAG (bgp->config, BGP_CONFIG_NO_DEFAULT_IPV4))
8511 vty_out (vty, " no bgp default ipv4-unicast%s", VTY_NEWLINE);
8513 /* BGP default local-preference. */
8514 if (bgp->default_local_pref != BGP_DEFAULT_LOCAL_PREF)
8515 vty_out (vty, " bgp default local-preference %d%s",
8516 bgp->default_local_pref,
8517 VTY_NEWLINE);
8519 /* BGP client-to-client reflection. */
8520 if (CHECK_FLAG (bgp->config, BGP_CONFIG_NO_CLIENT_TO_CLIENT))
8521 vty_out (vty, " no bgp client-to-client reflection%s", VTY_NEWLINE);
8523 /* BGP cluster ID. */
8524 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CLUSTER_ID))
8525 vty_out (vty, " bgp cluster-id %s%s", inet_ntoa (bgp->cluster),
8526 VTY_NEWLINE);
8528 /* Confederation Information */
8529 if(CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8531 vty_out(vty, " bgp confederation identifier %i%s",
8532 bgp->confederation_id,
8533 VTY_NEWLINE);
8534 if(bgp->confederation_peers_cnt > 0)
8536 vty_out(vty, " bgp confederation peers");
8537 bgp_confederation_peers_print(vty, bgp);
8538 vty_out(vty, "%s", VTY_NEWLINE);
8542 /* BGP enforce-first-as. */
8543 if (CHECK_FLAG (bgp->config, BGP_CONFIG_ENFORCE_FIRST_AS))
8544 vty_out (vty, " bgp enforce-first-as%s", VTY_NEWLINE);
8546 /* BGP deterministic-med. */
8547 if (CHECK_FLAG (bgp->config, BGP_CONFIG_DETERMINISTIC_MED))
8548 vty_out (vty, " bgp deterministic-med%s", VTY_NEWLINE);
8550 /* BGP bestpath method. */
8551 if (CHECK_FLAG (bgp->config, BGP_CONFIG_ASPATH_IGNORE))
8552 vty_out (vty, " bgp bestpath as-path ignore%s", VTY_NEWLINE);
8553 if (CHECK_FLAG (bgp->config, BGP_CONFIG_COMPARE_ROUTER_ID))
8554 vty_out (vty, " bgp bestpath compare-routerid%s", VTY_NEWLINE);
8555 if (CHECK_FLAG (bgp->config, BGP_CONFIG_MED_CONFED)
8556 || CHECK_FLAG (bgp->config, BGP_CONFIG_MED_MISSING_AS_WORST))
8558 vty_out (vty, " bgp bestpath med");
8559 if (CHECK_FLAG (bgp->config, BGP_CONFIG_MED_CONFED))
8560 vty_out (vty, " confed");
8561 if (CHECK_FLAG (bgp->config, BGP_CONFIG_MED_MISSING_AS_WORST))
8562 vty_out (vty, " missing-as-worst");
8563 vty_out (vty, "%s", VTY_NEWLINE);
8566 /* BGP network import check. */
8567 if (CHECK_FLAG (bgp->config, BGP_CONFIG_IMPORT_CHECK))
8568 vty_out (vty, " bgp network import-check%s", VTY_NEWLINE);
8570 /* BGP scan interval. */
8571 bgp_config_write_scan_time (vty);
8573 /* BGP flag dampening. */
8574 bgp_config_write_damp (vty);
8576 /* BGP static route configuration. */
8577 bgp_config_write_network (vty, bgp, AFI_IP, SAFI_UNICAST, &write);
8579 /* BGP redistribute configuration. */
8580 bgp_config_write_redistribute (vty, bgp, AFI_IP, SAFI_UNICAST, &write);
8582 /* BGP timers configuration. */
8583 if (bgp->default_keepalive != BGP_DEFAULT_KEEPALIVE
8584 && bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
8585 vty_out (vty, " timers bgp %d %d%s", bgp->default_keepalive,
8586 bgp->default_holdtime, VTY_NEWLINE);
8588 /* peer-group */
8589 LIST_LOOP (bgp->peer_group, group, nm)
8591 vty_out (vty, " neighbor %s peer-group", group->name);
8592 vty_out (vty, "%s", VTY_NEWLINE);
8594 if (group->as)
8595 vty_out (vty, " remote-as %d%s", group->as, VTY_NEWLINE);
8598 /* Normal neighbor configuration. */
8599 LIST_LOOP (bgp->peer_conf, conf, no)
8601 bgp_config_write_peer (vty, bgp, conf, AFI_IP, SAFI_UNICAST);
8604 /* Distance configuration. */
8605 bgp_config_write_distance (vty, bgp);
8607 /* IPv4 multicast configuration. */
8608 write += bgp_config_write_family (vty, bgp, AFI_IP, SAFI_MULTICAST);
8610 /* IPv4 VPN configuration. */
8611 write += bgp_config_write_family (vty, bgp, AFI_IP, SAFI_MPLS_VPN);
8613 /* IPv6 unicast configuration. */
8614 write += bgp_config_write_family (vty, bgp, AFI_IP6, SAFI_UNICAST);
8616 write++;
8618 return write;
8621 /* BGP node structure. */
8622 struct cmd_node bgp_node =
8624 BGP_NODE,
8625 "%s(config-router)# ",
8629 struct cmd_node bgp_ipv4_multicast_node =
8631 BGP_IPV4M_NODE,
8632 "%s(config-router-af)# ",
8636 struct cmd_node bgp_ipv6_unicast_node =
8638 BGP_IPV6_NODE,
8639 "%s(config-router-af)# ",
8643 /* Install bgp related commands. */
8644 void
8645 bgp_init ()
8647 /* Install bgp top node. */
8648 install_node (&bgp_node, bgp_config_write);
8649 install_node (&bgp_ipv4_multicast_node, NULL);
8650 install_node (&bgp_ipv6_unicast_node, NULL);
8652 install_default (BGP_NODE);
8653 install_default (BGP_IPV4M_NODE);
8654 install_default (BGP_IPV6_NODE);
8656 /* "bgp multiple-instance" commands. */
8657 install_element (CONFIG_NODE, &bgp_multiple_instance_cmd);
8658 install_element (CONFIG_NODE, &no_bgp_multiple_instance_cmd);
8660 /* "bgp router-id" commands. */
8661 install_element (BGP_NODE, &bgp_router_id_cmd);
8662 install_element (BGP_NODE, &no_bgp_router_id_cmd);
8663 install_element (BGP_NODE, &no_bgp_router_id_val_cmd);
8665 /* "timers bgp" commands. */
8666 install_element (BGP_NODE, &bgp_timers_cmd);
8667 install_element (BGP_NODE, &no_bgp_timers_cmd);
8669 /* "bgp cluster-id" commands. */
8670 install_element (BGP_NODE, &bgp_cluster_id_cmd);
8671 install_element (BGP_NODE, &bgp_cluster_id32_cmd);
8672 install_element (BGP_NODE, &no_bgp_cluster_id_cmd);
8673 install_element (BGP_NODE, &no_bgp_cluster_id_val_cmd);
8675 /* "bgp client-to-client reflection" commands */
8676 install_element (BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
8677 install_element (BGP_NODE, &bgp_client_to_client_reflection_cmd);
8679 /* "bgp always-compare-med" commands */
8680 install_element (BGP_NODE, &bgp_always_compare_med_cmd);
8681 install_element (BGP_NODE, &no_bgp_always_compare_med_cmd);
8683 /* "bgp deterministic-med" commands */
8684 install_element (BGP_NODE, &bgp_deterministic_med_cmd);
8685 install_element (BGP_NODE, &no_bgp_deterministic_med_cmd);
8687 /* "bgp enforce-first-as" commands */
8688 install_element (BGP_NODE, &bgp_enforce_first_as_cmd);
8689 install_element (BGP_NODE, &no_bgp_enforce_first_as_cmd);
8691 /* "bgp bestpath compare-routerid" commands */
8692 install_element (BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
8693 install_element (BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
8695 /* "bgp bestpath as-path ignore" commands */
8696 install_element (BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
8697 install_element (BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
8699 /* "bgp bestpath med" commands */
8700 install_element (BGP_NODE, &bgp_bestpath_med_cmd);
8701 install_element (BGP_NODE, &bgp_bestpath_med2_cmd);
8702 install_element (BGP_NODE, &bgp_bestpath_med3_cmd);
8703 install_element (BGP_NODE, &no_bgp_bestpath_med_cmd);
8704 install_element (BGP_NODE, &no_bgp_bestpath_med2_cmd);
8705 install_element (BGP_NODE, &no_bgp_bestpath_med3_cmd);
8707 /* "bgp network import-check" commands. */
8708 install_element (BGP_NODE, &bgp_network_import_check_cmd);
8709 install_element (BGP_NODE, &no_bgp_network_import_check_cmd);
8711 /* "no bgp default ipv4-unicast" commands. */
8712 install_element (BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
8713 install_element (BGP_NODE, &bgp_default_ipv4_unicast_cmd);
8715 /* "bgp default local-preference" commands. */
8716 install_element (BGP_NODE, &bgp_default_local_preference_cmd);
8717 install_element (BGP_NODE, &no_bgp_default_local_preference_cmd);
8718 install_element (BGP_NODE, &no_bgp_default_local_preference_val_cmd);
8720 /* "router bgp" commands. */
8721 install_element (CONFIG_NODE, &router_bgp_cmd);
8722 install_element (CONFIG_NODE, &router_bgp_view_cmd);
8724 /* "no router bgp" commands. */
8725 install_element (CONFIG_NODE, &no_router_bgp_cmd);
8726 install_element (CONFIG_NODE, &no_router_bgp_view_cmd);
8728 /* "neighbor remote-as" commands. */
8729 install_element (BGP_NODE, &neighbor_remote_as_cmd);
8730 install_element (BGP_NODE, &neighbor_remote_as_unicast_cmd);
8731 install_element (BGP_NODE, &neighbor_remote_as_multicast_cmd);
8732 install_element (BGP_NODE, &neighbor_remote_as_unicast_multicast_cmd);
8734 install_element (BGP_NODE, &neighbor_activate_cmd);
8735 install_element (BGP_NODE, &no_neighbor_activate_cmd);
8736 install_element (BGP_IPV4M_NODE, &neighbor_activate_cmd);
8737 install_element (BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
8738 install_element (BGP_IPV6_NODE, &neighbor_activate_cmd);
8739 install_element (BGP_IPV6_NODE, &no_neighbor_activate_cmd);
8741 /* "no neighbor remote-as" commands. */
8742 install_element (BGP_NODE, &no_neighbor_cmd);
8743 install_element (BGP_NODE, &no_neighbor_remote_as_cmd);
8745 /* "neighbor passive" commands. */
8746 install_element (BGP_NODE, &neighbor_passive_cmd);
8747 install_element (BGP_NODE, &no_neighbor_passive_cmd);
8749 /* "neighbor shutdown" commands. */
8750 install_element (BGP_NODE, &neighbor_shutdown_cmd);
8751 install_element (BGP_NODE, &no_neighbor_shutdown_cmd);
8753 /* "neighbor ebgp-multihop" commands. */
8754 install_element (BGP_NODE, &neighbor_ebgp_multihop_cmd);
8755 install_element (BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
8756 install_element (BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
8757 install_element (BGP_NODE, &no_neighbor_ebgp_multihop_ttl_cmd);
8759 /* "neighbor description" commands. */
8760 install_element (BGP_NODE, &neighbor_description_cmd);
8761 install_element (BGP_NODE, &no_neighbor_description_cmd);
8762 install_element (BGP_NODE, &no_neighbor_description_val_cmd);
8764 /* "neighbor version" commands. */
8765 install_element (BGP_NODE, &neighbor_version_cmd);
8766 install_element (BGP_NODE, &no_neighbor_version_cmd);
8768 /* "neighbor interface" commands. */
8769 install_element (BGP_NODE, &neighbor_interface_cmd);
8770 install_element (BGP_NODE, &no_neighbor_interface_cmd);
8772 /* "neighbor next-hop-self" commands. */
8773 install_element (BGP_NODE, &neighbor_nexthop_self_cmd);
8774 install_element (BGP_NODE, &no_neighbor_nexthop_self_cmd);
8775 install_element (BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
8776 install_element (BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
8777 install_element (BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
8778 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
8780 /* "neighbor update-source" commands. "*/
8781 install_element (BGP_NODE, &neighbor_update_source_cmd);
8782 install_element (BGP_NODE, &no_neighbor_update_source_cmd);
8784 /* "neighbor default-originate" commands. */
8785 install_element (BGP_NODE, &neighbor_default_originate_cmd);
8786 install_element (BGP_NODE, &no_neighbor_default_originate_cmd);
8788 /* "neighbor port" commands. */
8789 install_element (BGP_NODE, &neighbor_port_cmd);
8790 install_element (BGP_NODE, &no_neighbor_port_cmd);
8791 install_element (BGP_NODE, &no_neighbor_port_val_cmd);
8793 /* "neighbor send-community" commands.*/
8794 install_element (BGP_NODE, &neighbor_send_community_cmd);
8795 install_element (BGP_NODE, &neighbor_send_community_type_cmd);
8796 install_element (BGP_NODE, &no_neighbor_send_community_cmd);
8797 install_element (BGP_NODE, &no_neighbor_send_community_type_cmd);
8798 install_element (BGP_IPV4M_NODE, &neighbor_send_community_cmd);
8799 install_element (BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
8800 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
8801 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
8802 install_element (BGP_IPV6_NODE, &neighbor_send_community_cmd);
8803 install_element (BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
8804 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
8805 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
8807 /* "neighbor weight" commands. */
8808 install_element (BGP_NODE, &neighbor_weight_cmd);
8809 install_element (BGP_NODE, &no_neighbor_weight_cmd);
8810 install_element (BGP_NODE, &no_neighbor_weight_val_cmd);
8812 /* "neighbor softreconfiguration inbound" commands.*/
8813 install_element (BGP_NODE, &neighbor_soft_reconfiguration_cmd);
8814 install_element (BGP_NODE, &no_neighbor_soft_reconfiguration_cmd);
8815 install_element (BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
8816 install_element (BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
8817 install_element (BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
8818 install_element (BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
8820 /* "neighbor route-reflector" commands.*/
8821 install_element (BGP_NODE, &neighbor_route_reflector_client_cmd);
8822 install_element (BGP_NODE, &no_neighbor_route_reflector_client_cmd);
8823 install_element (BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
8824 install_element (BGP_IPV4M_NODE, &no_neighbor_route_reflector_client_cmd);
8825 install_element (BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
8826 install_element (BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
8828 /* "neighbor route-server" commands.*/
8829 install_element (BGP_NODE, &neighbor_route_server_client_cmd);
8830 install_element (BGP_NODE, &no_neighbor_route_server_client_cmd);
8831 install_element (BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
8832 install_element (BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
8833 install_element (BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
8834 install_element (BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
8836 /* "neighbor capability route-refresh" commands.*/
8837 install_element (BGP_NODE, &neighbor_capability_route_refresh_cmd);
8838 install_element (BGP_NODE, &no_neighbor_capability_route_refresh_cmd);
8840 /* "neighbor translate-update" commands. */
8841 install_element (BGP_NODE, &neighbor_translate_update_multicast_cmd);
8842 install_element (BGP_NODE, &neighbor_translate_update_unimulti_cmd);
8843 install_element (BGP_NODE, &no_neighbor_translate_update_cmd);
8844 install_element (BGP_NODE, &no_neighbor_translate_update_multicast_cmd);
8845 install_element (BGP_NODE, &no_neighbor_translate_update_unimulti_cmd);
8847 /* "neighbor dont-capability-negotiate" commands. */
8848 install_element (BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
8849 install_element (BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
8851 /* "neighbor override-capability" commands. */
8852 install_element (BGP_NODE, &neighbor_override_capability_cmd);
8853 install_element (BGP_NODE, &no_neighbor_override_capability_cmd);
8855 /* "neighbor strict-capability-match" commands. */
8856 install_element (BGP_NODE, &neighbor_strict_capability_cmd);
8857 install_element (BGP_NODE, &no_neighbor_strict_capability_cmd);
8859 /* "neighbor timers" commands. */
8860 install_element (BGP_NODE, &neighbor_timers_cmd);
8861 install_element (BGP_NODE, &no_neighbor_timers_cmd);
8863 /* "neighbor timers connect" commands. */
8864 install_element (BGP_NODE, &neighbor_timers_connect_cmd);
8865 install_element (BGP_NODE, &no_neighbor_timers_connect_cmd);
8867 /* Filters */
8868 install_element (BGP_NODE, &neighbor_distribute_list_cmd);
8869 install_element (BGP_NODE, &no_neighbor_distribute_list_cmd);
8870 install_element (BGP_NODE, &neighbor_prefix_list_cmd);
8871 install_element (BGP_NODE, &no_neighbor_prefix_list_cmd);
8872 install_element (BGP_NODE, &neighbor_filter_list_cmd);
8873 install_element (BGP_NODE, &no_neighbor_filter_list_cmd);
8874 install_element (BGP_NODE, &neighbor_route_map_cmd);
8875 install_element (BGP_NODE, &no_neighbor_route_map_cmd);
8876 install_element (BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
8877 install_element (BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
8878 install_element (BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
8879 install_element (BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
8880 install_element (BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
8881 install_element (BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
8882 install_element (BGP_IPV4M_NODE, &neighbor_route_map_cmd);
8883 install_element (BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
8884 #if 0
8885 install_element (BGP_NODE, &neighbor_peer_group_cmd);
8886 install_element (BGP_NODE, &neighbor_peer_group_remote_as_cmd);
8887 #endif /* 0 */
8889 /* "neighbor maximum-prefix" commands. */
8890 install_element (BGP_NODE, &neighbor_maximum_prefix_cmd);
8891 install_element (BGP_NODE, &neighbor_maximum_prefix_warning_cmd);
8892 install_element (BGP_NODE, &no_neighbor_maximum_prefix_cmd);
8893 install_element (BGP_NODE, &no_neighbor_maximum_prefix_val_cmd);
8894 install_element (BGP_NODE, &no_neighbor_maximum_prefix_val2_cmd);
8895 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
8896 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
8897 install_element (BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
8898 install_element (BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_val_cmd);
8899 install_element (BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_val2_cmd);
8900 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
8901 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
8902 install_element (BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
8903 install_element (BGP_IPV6_NODE, &no_neighbor_maximum_prefix_val_cmd);
8904 install_element (BGP_IPV6_NODE, &no_neighbor_maximum_prefix_val2_cmd);
8906 /* "bgp confederation" commands. */
8907 install_element (BGP_NODE, &bgp_confederation_identifier_cmd);
8908 install_element (BGP_NODE, &bgp_confederation_peers_cmd);
8909 install_element (BGP_NODE, &no_bgp_confederation_identifier_cmd);
8910 install_element (BGP_NODE, &no_bgp_confederation_peers_cmd);
8912 /* "transparent-as" commands. */
8913 install_element (BGP_NODE, &neighbor_transparent_as_cmd);
8914 install_element (BGP_NODE, &no_neighbor_transparent_as_cmd);
8916 /* "transparent-nexthop" commands. */
8917 install_element (BGP_NODE, &neighbor_transparent_nexthop_cmd);
8918 install_element (BGP_NODE, &no_neighbor_transparent_nexthop_cmd);
8920 /* "show ip bgp summary" commands. */
8921 install_element (VIEW_NODE, &show_ip_bgp_summary_cmd);
8922 install_element (VIEW_NODE, &show_ip_bgp_ipv4_summary_cmd);
8923 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_summary_cmd);
8924 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_summary_cmd);
8926 install_element (ENABLE_NODE, &show_ip_bgp_summary_cmd);
8927 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_summary_cmd);
8928 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_summary_cmd);
8929 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_summary_cmd);
8931 /* "show ip bgp neighbors" commands. */
8932 install_element (VIEW_NODE, &show_ip_bgp_neighbors_cmd);
8933 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbors_cmd);
8934 install_element (VIEW_NODE, &show_ip_bgp_neighbors_peer_cmd);
8935 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbors_peer_cmd);
8936 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbors_cmd);
8937 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbors_cmd);
8938 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbors_peer_cmd);
8939 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbors_peer_cmd);
8941 install_element (ENABLE_NODE, &show_ip_bgp_neighbors_cmd);
8942 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbors_cmd);
8943 install_element (ENABLE_NODE, &show_ip_bgp_neighbors_peer_cmd);
8944 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbors_peer_cmd);
8945 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbors_cmd);
8946 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbors_cmd);
8947 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbors_peer_cmd);
8948 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbors_peer_cmd);
8950 /* "show ip bgp paths" commands. */
8951 install_element (VIEW_NODE, &show_ip_bgp_paths_cmd);
8952 install_element (VIEW_NODE, &show_ip_bgp_ipv4_paths_cmd);
8953 install_element (ENABLE_NODE, &show_ip_bgp_paths_cmd);
8954 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_paths_cmd);
8956 /* "show ip bgp community" commands. */
8957 install_element (VIEW_NODE, &show_ip_bgp_community_info_cmd);
8958 install_element (ENABLE_NODE, &show_ip_bgp_community_info_cmd);
8960 /* "show ip bgp attribute-info" commands. */
8961 install_element (VIEW_NODE, &show_ip_bgp_attr_info_cmd);
8962 install_element (ENABLE_NODE, &show_ip_bgp_attr_info_cmd);
8964 /* "clear ip bgp commands" */
8965 install_element (ENABLE_NODE, &clear_ip_bgp_all_cmd);
8966 install_element (ENABLE_NODE, &clear_ip_bgp_as_cmd);
8967 install_element (ENABLE_NODE, &clear_ip_bgp_peer_cmd);
8968 #if 0
8969 install_element (ENABLE_NODE, &clear_ip_bgp_peer_group_cmd);
8970 #endif /* 0 */
8972 /* "clear ip bgp neighbor soft in" */
8973 install_element (ENABLE_NODE, &clear_ip_bgp_peer_soft_in_cmd);
8974 install_element (ENABLE_NODE, &clear_ip_bgp_peer_in_cmd);
8975 install_element (ENABLE_NODE, &clear_ip_bgp_peer_ipv4_soft_in_cmd);
8976 install_element (ENABLE_NODE, &clear_ip_bgp_peer_ipv4_in_cmd);
8977 install_element (ENABLE_NODE, &clear_ip_bgp_as_soft_in_cmd);
8978 install_element (ENABLE_NODE, &clear_ip_bgp_as_in_cmd);
8979 install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_soft_in_cmd);
8980 install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_in_cmd);
8981 install_element (ENABLE_NODE, &clear_ip_bgp_all_soft_in_cmd);
8982 install_element (ENABLE_NODE, &clear_ip_bgp_all_in_cmd);
8983 install_element (ENABLE_NODE, &clear_ip_bgp_all_ipv4_soft_in_cmd);
8984 install_element (ENABLE_NODE, &clear_ip_bgp_all_ipv4_in_cmd);
8986 /* "clear ip bgp neighbor soft out" */
8987 install_element (ENABLE_NODE, &clear_ip_bgp_peer_soft_out_cmd);
8988 install_element (ENABLE_NODE, &clear_ip_bgp_peer_out_cmd);
8989 install_element (ENABLE_NODE, &clear_ip_bgp_peer_ipv4_soft_out_cmd);
8990 install_element (ENABLE_NODE, &clear_ip_bgp_peer_ipv4_out_cmd);
8991 install_element (ENABLE_NODE, &clear_ip_bgp_as_soft_out_cmd);
8992 install_element (ENABLE_NODE, &clear_ip_bgp_as_out_cmd);
8993 install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_soft_out_cmd);
8994 install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_out_cmd);
8995 install_element (ENABLE_NODE, &clear_ip_bgp_all_soft_out_cmd);
8996 install_element (ENABLE_NODE, &clear_ip_bgp_all_out_cmd);
8997 install_element (ENABLE_NODE, &clear_ip_bgp_all_ipv4_soft_out_cmd);
8998 install_element (ENABLE_NODE, &clear_ip_bgp_all_ipv4_out_cmd);
9000 /* "clear ip bgp neighbor soft" */
9001 install_element (ENABLE_NODE, &clear_ip_bgp_peer_soft_cmd);
9002 install_element (ENABLE_NODE, &clear_ip_bgp_peer_ipv4_soft_cmd);
9003 install_element (ENABLE_NODE, &clear_ip_bgp_as_soft_cmd);
9004 install_element (ENABLE_NODE, &clear_ip_bgp_as_ipv4_soft_cmd);
9005 install_element (ENABLE_NODE, &clear_ip_bgp_all_soft_cmd);
9006 install_element (ENABLE_NODE, &clear_ip_bgp_all_ipv4_soft_cmd);
9009 /* "clear ip bgp vpnv4 soft in" */
9010 install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_in_cmd);
9011 install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_in_cmd);
9012 install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_in_cmd);
9013 install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_in_cmd);
9014 install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_in_cmd);
9015 install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_in_cmd);
9017 /* "clear ip bgp vpnv4 soft out" */
9018 install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_out_cmd);
9019 install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_out_cmd);
9020 install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_out_cmd);
9021 install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_out_cmd);
9022 install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_out_cmd);
9023 install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_out_cmd);
9025 /* "clear ip bgp vpnv4 soft" */
9026 install_element (ENABLE_NODE, &clear_ip_bgp_peer_vpnv4_soft_cmd);
9027 install_element (ENABLE_NODE, &clear_ip_bgp_as_vpnv4_soft_cmd);
9028 install_element (ENABLE_NODE, &clear_ip_bgp_all_vpnv4_soft_cmd);
9030 #ifdef HAVE_IPV6
9031 /* BGP-MP for IPv6 unicast. */
9032 install_element (BGP_NODE, &address_family_ipv6_cmd);
9033 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
9034 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
9036 install_element (BGP_NODE, &ipv6_bgp_neighbor_remote_as_cmd);
9037 install_element (BGP_NODE, &ipv6_bgp_neighbor_remote_as_unicast_cmd);
9038 install_element (BGP_NODE, &ipv6_bgp_neighbor_remote_as_multicast_cmd);
9039 install_element (BGP_NODE, &ipv6_bgp_neighbor_remote_as_unicast_multicast_cmd);
9041 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_cmd);
9042 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_remote_as_cmd);
9044 /* "IPv6 neighbor passive" commands. */
9045 install_element (BGP_NODE, &ipv6_bgp_neighbor_passive_cmd);
9046 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_passive_cmd);
9048 install_element (BGP_NODE, &ipv6_bgp_neighbor_shutdown_cmd);
9049 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_shutdown_cmd);
9051 install_element (BGP_NODE, &ipv6_bgp_neighbor_ebgp_multihop_cmd);
9052 install_element (BGP_NODE, &ipv6_bgp_neighbor_ebgp_multihop_ttl_cmd);
9053 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_ebgp_multihop_cmd);
9054 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_ebgp_multihop_ttl_cmd);
9056 install_element (BGP_NODE, &ipv6_bgp_neighbor_description_cmd);
9057 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_description_cmd);
9058 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_description_val_cmd);
9060 install_element (BGP_NODE, &ipv6_bgp_neighbor_version_cmd);
9061 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_version_cmd);
9063 install_element (BGP_NODE, &ipv6_bgp_neighbor_interface_cmd);
9064 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_interface_cmd);
9066 install_element (BGP_NODE, &ipv6_bgp_neighbor_nexthop_self_cmd);
9067 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_nexthop_self_cmd);
9069 install_element (BGP_NODE, &ipv6_bgp_neighbor_update_source_cmd);
9070 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_update_source_cmd);
9072 install_element (BGP_NODE, &ipv6_bgp_neighbor_default_originate_cmd);
9073 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_default_originate_cmd);
9075 install_element (BGP_NODE, &ipv6_bgp_neighbor_port_cmd);
9076 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_port_cmd);
9077 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_port_val_cmd);
9079 install_element (BGP_NODE, &ipv6_bgp_neighbor_send_community_cmd);
9080 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_send_community_cmd);
9082 install_element (BGP_NODE, &ipv6_bgp_neighbor_send_community_extended_cmd);
9083 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_send_community_extended_cmd);
9085 install_element (BGP_NODE, &ipv6_bgp_neighbor_weight_cmd);
9086 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_weight_cmd);
9087 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_weight_val_cmd);
9089 install_element (BGP_NODE, &ipv6_bgp_neighbor_soft_reconfiguration_cmd);
9090 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_soft_reconfiguration_cmd);
9092 install_element (BGP_NODE, &ipv6_bgp_neighbor_route_reflector_client_cmd);
9093 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_route_reflector_client_cmd);
9095 install_element (BGP_NODE, &ipv6_bgp_neighbor_route_server_client_cmd);
9096 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_route_server_client_cmd);
9098 install_element (BGP_NODE, &ipv6_bgp_neighbor_capability_route_refresh_cmd);
9099 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_capability_route_refresh_cmd);
9101 install_element (BGP_NODE, &ipv6_neighbor_dont_capability_negotiate_cmd);
9102 install_element (BGP_NODE, &no_ipv6_neighbor_dont_capability_negotiate_cmd);
9104 install_element (BGP_NODE, &ipv6_neighbor_override_capability_cmd);
9105 install_element (BGP_NODE, &no_ipv6_neighbor_override_capability_cmd);
9107 install_element (BGP_NODE, &ipv6_neighbor_strict_capability_cmd);
9108 install_element (BGP_NODE, &no_ipv6_neighbor_strict_capability_cmd);
9110 install_element (BGP_NODE, &ipv6_bgp_neighbor_timers_cmd);
9111 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_timers_cmd);
9113 install_element (BGP_NODE, &ipv6_bgp_neighbor_timers_connect_cmd);
9114 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_timers_connect_cmd);
9116 install_element (BGP_IPV6_NODE, &ipv6_bgp_neighbor_distribute_list_cmd);
9117 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_neighbor_distribute_list_cmd);
9118 install_element (BGP_IPV6_NODE, &ipv6_bgp_neighbor_prefix_list_cmd);
9119 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_neighbor_prefix_list_cmd);
9120 install_element (BGP_IPV6_NODE, &ipv6_bgp_neighbor_filter_list_cmd);
9121 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_neighbor_filter_list_cmd);
9122 install_element (BGP_IPV6_NODE, &ipv6_bgp_neighbor_route_map_cmd);
9123 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_neighbor_route_map_cmd);
9125 install_element (BGP_NODE, &old_ipv6_bgp_neighbor_distribute_list_cmd);
9126 install_element (BGP_NODE, &old_no_ipv6_bgp_neighbor_distribute_list_cmd);
9127 install_element (BGP_NODE, &old_ipv6_bgp_neighbor_prefix_list_cmd);
9128 install_element (BGP_NODE, &old_no_ipv6_bgp_neighbor_prefix_list_cmd);
9129 install_element (BGP_NODE, &old_ipv6_bgp_neighbor_filter_list_cmd);
9130 install_element (BGP_NODE, &old_no_ipv6_bgp_neighbor_filter_list_cmd);
9131 install_element (BGP_NODE, &old_ipv6_bgp_neighbor_route_map_cmd);
9132 install_element (BGP_NODE, &old_no_ipv6_bgp_neighbor_route_map_cmd);
9134 install_element (BGP_NODE, &ipv6_bgp_neighbor_transparent_as_cmd);
9135 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_transparent_as_cmd);
9137 install_element (BGP_NODE, &ipv6_bgp_neighbor_transparent_nexthop_cmd);
9138 install_element (BGP_NODE, &no_ipv6_bgp_neighbor_transparent_nexthop_cmd);
9140 install_element (VIEW_NODE, &show_bgp_summary_cmd);
9141 install_element (VIEW_NODE, &show_bgp_ipv6_summary_cmd);
9142 install_element (VIEW_NODE, &show_bgp_neighbors_cmd);
9143 install_element (VIEW_NODE, &show_bgp_ipv6_neighbors_cmd);
9144 install_element (VIEW_NODE, &show_bgp_neighbors_peer_cmd);
9145 install_element (VIEW_NODE, &show_bgp_ipv6_neighbors_peer_cmd);
9147 install_element (ENABLE_NODE, &show_bgp_summary_cmd);
9148 install_element (ENABLE_NODE, &show_bgp_ipv6_summary_cmd);
9149 install_element (ENABLE_NODE, &show_bgp_neighbors_cmd);
9150 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbors_cmd);
9151 install_element (ENABLE_NODE, &show_bgp_neighbors_peer_cmd);
9152 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbors_peer_cmd);
9154 /* old commad */
9155 install_element (VIEW_NODE, &show_ipv6_bgp_summary_cmd);
9156 install_element (VIEW_NODE, &show_ipv6_mbgp_summary_cmd);
9158 /* old commad */
9159 install_element (ENABLE_NODE, &show_ipv6_bgp_summary_cmd);
9160 install_element (ENABLE_NODE, &show_ipv6_mbgp_summary_cmd);
9162 /* old commad */
9163 install_element (VIEW_NODE, &show_ipv6_bgp_neighbors_cmd);
9164 install_element (VIEW_NODE, &show_ipv6_bgp_neighbors_peer_cmd);
9165 install_element (VIEW_NODE, &show_ipv6_mbgp_neighbors_cmd);
9166 install_element (VIEW_NODE, &show_ipv6_mbgp_neighbors_peer_cmd);
9168 /* old commad */
9169 install_element (ENABLE_NODE, &show_ipv6_bgp_neighbors_cmd);
9170 install_element (ENABLE_NODE, &show_ipv6_bgp_neighbors_peer_cmd);
9171 install_element (ENABLE_NODE, &show_ipv6_mbgp_neighbors_cmd);
9172 install_element (ENABLE_NODE, &show_ipv6_mbgp_neighbors_peer_cmd);
9174 install_element (ENABLE_NODE, &clear_bgp_all_cmd);
9175 install_element (ENABLE_NODE, &clear_bgp_ipv6_all_cmd);
9176 install_element (ENABLE_NODE, &clear_bgp_peer_cmd);
9177 install_element (ENABLE_NODE, &clear_bgp_ipv6_peer_cmd);
9178 #if 0
9179 install_element (ENABLE_NODE, &clear_bgp_peer_group_cmd);
9180 install_element (ENABLE_NODE, &clear_bgp_ipv6_peer_group_cmd);
9181 #endif /* 0 */
9182 install_element (ENABLE_NODE, &clear_bgp_as_cmd);
9183 install_element (ENABLE_NODE, &clear_bgp_ipv6_as_cmd);
9185 install_element (ENABLE_NODE, &clear_bgp_peer_soft_in_cmd);
9186 install_element (ENABLE_NODE, &clear_bgp_ipv6_peer_soft_in_cmd);
9187 install_element (ENABLE_NODE, &clear_bgp_peer_in_cmd);
9188 install_element (ENABLE_NODE, &clear_bgp_ipv6_peer_in_cmd);
9189 install_element (ENABLE_NODE, &clear_bgp_as_soft_in_cmd);
9190 install_element (ENABLE_NODE, &clear_bgp_ipv6_as_soft_in_cmd);
9191 install_element (ENABLE_NODE, &clear_bgp_as_in_cmd);
9192 install_element (ENABLE_NODE, &clear_bgp_ipv6_as_in_cmd);
9193 install_element (ENABLE_NODE, &clear_bgp_all_soft_in_cmd);
9194 install_element (ENABLE_NODE, &clear_bgp_ipv6_all_soft_in_cmd);
9195 install_element (ENABLE_NODE, &clear_bgp_all_in_cmd);
9196 install_element (ENABLE_NODE, &clear_bgp_ipv6_all_in_cmd);
9198 install_element (ENABLE_NODE, &clear_bgp_peer_soft_out_cmd);
9199 install_element (ENABLE_NODE, &clear_bgp_ipv6_peer_soft_out_cmd);
9200 install_element (ENABLE_NODE, &clear_bgp_peer_out_cmd);
9201 install_element (ENABLE_NODE, &clear_bgp_ipv6_peer_out_cmd);
9202 install_element (ENABLE_NODE, &clear_bgp_as_soft_out_cmd);
9203 install_element (ENABLE_NODE, &clear_bgp_ipv6_as_soft_out_cmd);
9204 install_element (ENABLE_NODE, &clear_bgp_as_out_cmd);
9205 install_element (ENABLE_NODE, &clear_bgp_ipv6_as_out_cmd);
9206 install_element (ENABLE_NODE, &clear_bgp_all_soft_out_cmd);
9207 install_element (ENABLE_NODE, &clear_bgp_ipv6_all_soft_out_cmd);
9208 install_element (ENABLE_NODE, &clear_bgp_all_out_cmd);
9209 install_element (ENABLE_NODE, &clear_bgp_ipv6_all_out_cmd);
9211 install_element (ENABLE_NODE, &clear_bgp_peer_soft_cmd);
9212 install_element (ENABLE_NODE, &clear_bgp_ipv6_peer_soft_cmd);
9213 install_element (ENABLE_NODE, &clear_bgp_as_soft_cmd);
9214 install_element (ENABLE_NODE, &clear_bgp_ipv6_as_soft_cmd);
9215 install_element (ENABLE_NODE, &clear_bgp_all_soft_cmd);
9216 install_element (ENABLE_NODE, &clear_bgp_ipv6_all_soft_cmd);
9217 #endif /* HAVE_IPV6 */
9219 /* BGP-MP for IPv4 multicast. */
9220 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
9221 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
9223 /* Make global lists. */
9224 bgp_list = list_new ();
9225 peer_list = list_new ();
9226 peer_list->cmp = (int (*)(void *, void *)) peer_list_cmp;
9228 /* BGP multiple instance. */
9229 bgp_multiple_instance = 0;
9231 /* Init zebra. */
9232 zebra_init ();
9234 /* BGP inits. */
9235 bgp_attr_init ();
9236 bgp_debug_init ();
9237 bgp_dump_init ();
9238 bgp_route_init ();
9239 bgp_route_map_init ();
9240 bgp_scan_init ();
9242 /* Access list initialize. */
9243 access_list_init ();
9244 access_list_add_hook (bgp_distribute_update);
9245 access_list_delete_hook (bgp_distribute_update);
9247 /* Filter list initialize. */
9248 bgp_filter_init ();
9249 as_list_add_hook (bgp_aslist_update);
9250 as_list_delete_hook (bgp_aslist_update);
9252 /* Prefix list initialize.*/
9253 prefix_list_init ();
9254 prefix_list_add_hook (bgp_prefix_list_update);
9255 prefix_list_delete_hook (bgp_prefix_list_update);
9257 /* Community list initialize. */
9258 community_list_init ();
9260 #ifdef HAVE_SNMP
9261 bgp_snmp_init ();
9262 #endif /* HAVE_SNMP */
9264 bgp_damp_disable (NULL);