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
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
28 #include "sockunion.h"
37 #include "workqueue.h"
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_table.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_regex.h"
48 #include "bgpd/bgp_clist.h"
49 #include "bgpd/bgp_fsm.h"
50 #include "bgpd/bgp_packet.h"
51 #include "bgpd/bgp_zebra.h"
52 #include "bgpd/bgp_open.h"
53 #include "bgpd/bgp_filter.h"
54 #include "bgpd/bgp_nexthop.h"
55 #include "bgpd/bgp_damp.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_advertise.h"
58 #include "bgpd/bgp_network.h"
59 #include "bgpd/bgp_vty.h"
61 #include "bgpd/bgp_snmp.h"
62 #endif /* HAVE_SNMP */
64 /* BGP process wide configuration. */
65 static struct bgp_master bgp_master
;
67 extern struct in_addr router_id_zebra
;
69 /* BGP process wide configuration pointer to export. */
70 struct bgp_master
*bm
;
72 /* BGP community-list. */
73 struct community_list_handler
*bgp_clist
;
75 /* BGP global flag manipulation. */
77 bgp_option_set (int flag
)
82 case BGP_OPT_MULTIPLE_INSTANCE
:
83 case BGP_OPT_CONFIG_CISCO
:
84 SET_FLAG (bm
->options
, flag
);
87 return BGP_ERR_INVALID_FLAG
;
93 bgp_option_unset (int flag
)
97 case BGP_OPT_MULTIPLE_INSTANCE
:
98 if (listcount (bm
->bgp
) > 1)
99 return BGP_ERR_MULTIPLE_INSTANCE_USED
;
102 case BGP_OPT_CONFIG_CISCO
:
103 UNSET_FLAG (bm
->options
, flag
);
106 return BGP_ERR_INVALID_FLAG
;
112 bgp_option_check (int flag
)
114 return CHECK_FLAG (bm
->options
, flag
);
117 /* BGP flag manipulation. */
119 bgp_flag_set (struct bgp
*bgp
, int flag
)
121 SET_FLAG (bgp
->flags
, flag
);
126 bgp_flag_unset (struct bgp
*bgp
, int flag
)
128 UNSET_FLAG (bgp
->flags
, flag
);
133 bgp_flag_check (struct bgp
*bgp
, int flag
)
135 return CHECK_FLAG (bgp
->flags
, flag
);
138 /* Internal function to set BGP structure configureation flag. */
140 bgp_config_set (struct bgp
*bgp
, int config
)
142 SET_FLAG (bgp
->config
, config
);
146 bgp_config_unset (struct bgp
*bgp
, int config
)
148 UNSET_FLAG (bgp
->config
, config
);
152 bgp_config_check (struct bgp
*bgp
, int config
)
154 return CHECK_FLAG (bgp
->config
, config
);
157 /* Set BGP router identifier. */
159 bgp_router_id_set (struct bgp
*bgp
, struct in_addr
*id
)
162 struct listnode
*node
, *nnode
;
164 if (bgp_config_check (bgp
, BGP_CONFIG_ROUTER_ID
)
165 && IPV4_ADDR_SAME (&bgp
->router_id
, id
))
168 IPV4_ADDR_COPY (&bgp
->router_id
, id
);
169 bgp_config_set (bgp
, BGP_CONFIG_ROUTER_ID
);
171 /* Set all peer's local identifier with this value. */
172 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
174 IPV4_ADDR_COPY (&peer
->local_id
, id
);
176 if (peer
->status
== Established
)
178 peer
->last_reset
= PEER_DOWN_RID_CHANGE
;
179 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
180 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
186 /* BGP's cluster-id control. */
188 bgp_cluster_id_set (struct bgp
*bgp
, struct in_addr
*cluster_id
)
191 struct listnode
*node
, *nnode
;
193 if (bgp_config_check (bgp
, BGP_CONFIG_CLUSTER_ID
)
194 && IPV4_ADDR_SAME (&bgp
->cluster_id
, cluster_id
))
197 IPV4_ADDR_COPY (&bgp
->cluster_id
, cluster_id
);
198 bgp_config_set (bgp
, BGP_CONFIG_CLUSTER_ID
);
200 /* Clear all IBGP peer. */
201 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
203 if (peer_sort (peer
) != BGP_PEER_IBGP
)
206 if (peer
->status
== Established
)
208 peer
->last_reset
= PEER_DOWN_CLID_CHANGE
;
209 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
210 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
217 bgp_cluster_id_unset (struct bgp
*bgp
)
220 struct listnode
*node
, *nnode
;
222 if (! bgp_config_check (bgp
, BGP_CONFIG_CLUSTER_ID
))
225 bgp
->cluster_id
.s_addr
= 0;
226 bgp_config_unset (bgp
, BGP_CONFIG_CLUSTER_ID
);
228 /* Clear all IBGP peer. */
229 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
231 if (peer_sort (peer
) != BGP_PEER_IBGP
)
234 if (peer
->status
== Established
)
236 peer
->last_reset
= PEER_DOWN_CLID_CHANGE
;
237 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
238 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
244 /* BGP timer configuration. */
246 bgp_timers_set (struct bgp
*bgp
, u_int32_t keepalive
, u_int32_t holdtime
)
248 bgp
->default_keepalive
= (keepalive
< holdtime
/ 3
249 ? keepalive
: holdtime
/ 3);
250 bgp
->default_holdtime
= holdtime
;
256 bgp_timers_unset (struct bgp
*bgp
)
258 bgp
->default_keepalive
= BGP_DEFAULT_KEEPALIVE
;
259 bgp
->default_holdtime
= BGP_DEFAULT_HOLDTIME
;
264 /* BGP confederation configuration. */
266 bgp_confederation_id_set (struct bgp
*bgp
, as_t as
)
269 struct listnode
*node
, *nnode
;
273 return BGP_ERR_INVALID_AS
;
275 /* Remember - were we doing confederation before? */
276 already_confed
= bgp_config_check (bgp
, BGP_CONFIG_CONFEDERATION
);
278 bgp_config_set (bgp
, BGP_CONFIG_CONFEDERATION
);
280 /* If we were doing confederation already, this is just an external
281 AS change. Just Reset EBGP sessions, not CONFED sessions. If we
282 were not doing confederation before, reset all EBGP sessions. */
283 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
285 /* We're looking for peers who's AS is not local or part of our
289 if (peer_sort (peer
) == BGP_PEER_EBGP
)
292 if (peer
->status
== Established
)
294 peer
->last_reset
= PEER_DOWN_CONFED_ID_CHANGE
;
295 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
296 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
300 BGP_EVENT_ADD (peer
, BGP_Stop
);
305 /* Not doign confederation before, so reset every non-local
307 if (peer_sort (peer
) != BGP_PEER_IBGP
)
309 /* Reset the local_as to be our EBGP one */
310 if (peer_sort (peer
) == BGP_PEER_EBGP
)
312 if (peer
->status
== Established
)
314 peer
->last_reset
= PEER_DOWN_CONFED_ID_CHANGE
;
315 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
316 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
319 BGP_EVENT_ADD (peer
, BGP_Stop
);
327 bgp_confederation_id_unset (struct bgp
*bgp
)
330 struct listnode
*node
, *nnode
;
333 bgp_config_unset (bgp
, BGP_CONFIG_CONFEDERATION
);
335 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
337 /* We're looking for peers who's AS is not local */
338 if (peer_sort (peer
) != BGP_PEER_IBGP
)
340 peer
->local_as
= bgp
->as
;
341 if (peer
->status
== Established
)
343 peer
->last_reset
= PEER_DOWN_CONFED_ID_CHANGE
;
344 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
345 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
349 BGP_EVENT_ADD (peer
, BGP_Stop
);
355 /* Is an AS part of the confed or not? */
357 bgp_confederation_peers_check (struct bgp
*bgp
, as_t as
)
364 for (i
= 0; i
< bgp
->confed_peers_cnt
; i
++)
365 if (bgp
->confed_peers
[i
] == as
)
371 /* Add an AS to the confederation set. */
373 bgp_confederation_peers_add (struct bgp
*bgp
, as_t as
)
376 struct listnode
*node
, *nnode
;
379 return BGP_ERR_INVALID_BGP
;
382 return BGP_ERR_INVALID_AS
;
384 if (bgp_confederation_peers_check (bgp
, as
))
387 if (bgp
->confed_peers
)
388 bgp
->confed_peers
= XREALLOC (MTYPE_BGP_CONFED_LIST
,
390 (bgp
->confed_peers_cnt
+ 1) * sizeof (as_t
));
392 bgp
->confed_peers
= XMALLOC (MTYPE_BGP_CONFED_LIST
,
393 (bgp
->confed_peers_cnt
+ 1) * sizeof (as_t
));
395 bgp
->confed_peers
[bgp
->confed_peers_cnt
] = as
;
396 bgp
->confed_peers_cnt
++;
398 if (bgp_config_check (bgp
, BGP_CONFIG_CONFEDERATION
))
400 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
404 peer
->local_as
= bgp
->as
;
405 if (peer
->status
== Established
)
407 peer
->last_reset
= PEER_DOWN_CONFED_PEER_CHANGE
;
408 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
409 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
412 BGP_EVENT_ADD (peer
, BGP_Stop
);
419 /* Delete an AS from the confederation set. */
421 bgp_confederation_peers_remove (struct bgp
*bgp
, as_t as
)
426 struct listnode
*node
, *nnode
;
431 if (! bgp_confederation_peers_check (bgp
, as
))
434 for (i
= 0; i
< bgp
->confed_peers_cnt
; i
++)
435 if (bgp
->confed_peers
[i
] == as
)
436 for(j
= i
+ 1; j
< bgp
->confed_peers_cnt
; j
++)
437 bgp
->confed_peers
[j
- 1] = bgp
->confed_peers
[j
];
439 bgp
->confed_peers_cnt
--;
441 if (bgp
->confed_peers_cnt
== 0)
443 if (bgp
->confed_peers
)
444 XFREE (MTYPE_BGP_CONFED_LIST
, bgp
->confed_peers
);
445 bgp
->confed_peers
= NULL
;
448 bgp
->confed_peers
= XREALLOC (MTYPE_BGP_CONFED_LIST
,
450 bgp
->confed_peers_cnt
* sizeof (as_t
));
452 /* Now reset any peer who's remote AS has just been removed from the
454 if (bgp_config_check (bgp
, BGP_CONFIG_CONFEDERATION
))
456 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
460 peer
->local_as
= bgp
->confed_id
;
461 if (peer
->status
== Established
)
463 peer
->last_reset
= PEER_DOWN_CONFED_PEER_CHANGE
;
464 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
465 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
468 BGP_EVENT_ADD (peer
, BGP_Stop
);
476 /* Local preference configuration. */
478 bgp_default_local_preference_set (struct bgp
*bgp
, u_int32_t local_pref
)
483 bgp
->default_local_pref
= local_pref
;
489 bgp_default_local_preference_unset (struct bgp
*bgp
)
494 bgp
->default_local_pref
= BGP_DEFAULT_LOCAL_PREF
;
499 /* If peer is RSERVER_CLIENT in at least one address family and is not member
500 of a peer_group for that family, return 1.
501 Used to check wether the peer is included in list bgp->rsclient. */
503 peer_rsclient_active (struct peer
*peer
)
508 for (i
=AFI_IP
; i
< AFI_MAX
; i
++)
509 for (j
=SAFI_UNICAST
; j
< SAFI_MAX
; j
++)
510 if (CHECK_FLAG(peer
->af_flags
[i
][j
], PEER_FLAG_RSERVER_CLIENT
)
511 && ! peer
->af_group
[i
][j
])
516 /* Peer comparison function for sorting. */
518 peer_cmp (struct peer
*p1
, struct peer
*p2
)
520 return sockunion_cmp (&p1
->su
, &p2
->su
);
524 peer_af_flag_check (struct peer
*peer
, afi_t afi
, safi_t safi
, u_int32_t flag
)
526 return CHECK_FLAG (peer
->af_flags
[afi
][safi
], flag
);
529 /* Reset all address family specific configuration. */
531 peer_af_flag_reset (struct peer
*peer
, afi_t afi
, safi_t safi
)
534 struct bgp_filter
*filter
;
535 char orf_name
[BUFSIZ
];
537 filter
= &peer
->filter
[afi
][safi
];
539 /* Clear neighbor filter and route-map */
540 for (i
= FILTER_IN
; i
< FILTER_MAX
; i
++)
542 if (filter
->dlist
[i
].name
)
544 free (filter
->dlist
[i
].name
);
545 filter
->dlist
[i
].name
= NULL
;
547 if (filter
->plist
[i
].name
)
549 free (filter
->plist
[i
].name
);
550 filter
->plist
[i
].name
= NULL
;
552 if (filter
->aslist
[i
].name
)
554 free (filter
->aslist
[i
].name
);
555 filter
->aslist
[i
].name
= NULL
;
558 for (i
= RMAP_IN
; i
< RMAP_MAX
; i
++)
560 if (filter
->map
[i
].name
)
562 free (filter
->map
[i
].name
);
563 filter
->map
[i
].name
= NULL
;
567 /* Clear unsuppress map. */
568 if (filter
->usmap
.name
)
569 free (filter
->usmap
.name
);
570 filter
->usmap
.name
= NULL
;
571 filter
->usmap
.map
= NULL
;
573 /* Clear neighbor's all address family flags. */
574 peer
->af_flags
[afi
][safi
] = 0;
576 /* Clear neighbor's all address family sflags. */
577 peer
->af_sflags
[afi
][safi
] = 0;
579 /* Clear neighbor's all address family capabilities. */
580 peer
->af_cap
[afi
][safi
] = 0;
583 peer
->orf_plist
[afi
][safi
] = NULL
;
584 sprintf (orf_name
, "%s.%d.%d", peer
->host
, afi
, safi
);
585 prefix_bgp_orf_remove_all (orf_name
);
587 /* Set default neighbor send-community. */
588 if (! bgp_option_check (BGP_OPT_CONFIG_CISCO
))
590 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SEND_COMMUNITY
);
591 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SEND_EXT_COMMUNITY
);
594 /* Clear neighbor default_originate_rmap */
595 if (peer
->default_rmap
[afi
][safi
].name
)
596 free (peer
->default_rmap
[afi
][safi
].name
);
597 peer
->default_rmap
[afi
][safi
].name
= NULL
;
598 peer
->default_rmap
[afi
][safi
].map
= NULL
;
600 /* Clear neighbor maximum-prefix */
601 peer
->pmax
[afi
][safi
] = 0;
602 peer
->pmax_threshold
[afi
][safi
] = MAXIMUM_PREFIX_THRESHOLD_DEFAULT
;
605 /* peer global config reset */
607 peer_global_config_reset (struct peer
*peer
)
610 peer
->change_local_as
= 0;
611 peer
->ttl
= (peer_sort (peer
) == BGP_PEER_IBGP
? 255 : 1);
612 if (peer
->update_source
)
614 sockunion_free (peer
->update_source
);
615 peer
->update_source
= NULL
;
619 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
620 peer
->update_if
= NULL
;
623 if (peer_sort (peer
) == BGP_PEER_IBGP
)
624 peer
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
626 peer
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
633 peer
->v_connect
= BGP_DEFAULT_CONNECT_RETRY
;
636 /* Check peer's AS number and determin is this peer IBGP or EBGP */
638 peer_sort (struct peer
*peer
)
645 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
648 return (bgp
->as
== peer
->as
? BGP_PEER_IBGP
: BGP_PEER_EBGP
);
652 peer1
= listnode_head (peer
->group
->peer
);
654 return (peer1
->local_as
== peer1
->as
655 ? BGP_PEER_IBGP
: BGP_PEER_EBGP
);
657 return BGP_PEER_INTERNAL
;
661 if (bgp
&& CHECK_FLAG (bgp
->config
, BGP_CONFIG_CONFEDERATION
))
663 if (peer
->local_as
== 0)
664 return BGP_PEER_INTERNAL
;
666 if (peer
->local_as
== peer
->as
)
668 if (peer
->local_as
== bgp
->confed_id
)
669 return BGP_PEER_EBGP
;
671 return BGP_PEER_IBGP
;
674 if (bgp_confederation_peers_check (bgp
, peer
->as
))
675 return BGP_PEER_CONFED
;
677 return BGP_PEER_EBGP
;
681 return (peer
->local_as
== 0
682 ? BGP_PEER_INTERNAL
: peer
->local_as
== peer
->as
683 ? BGP_PEER_IBGP
: BGP_PEER_EBGP
);
688 peer_free (struct peer
*peer
)
691 XFREE (MTYPE_PEER_DESC
, peer
->desc
);
693 /* Free allocated host character. */
695 XFREE (MTYPE_BGP_PEER_HOST
, peer
->host
);
697 /* Update source configuration. */
698 if (peer
->update_source
)
699 sockunion_free (peer
->update_source
);
702 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
704 if (peer
->clear_node_queue
)
705 work_queue_free (peer
->clear_node_queue
);
707 memset (peer
, 0, sizeof (struct peer
));
709 XFREE (MTYPE_BGP_PEER
, peer
);
712 /* increase reference count on a struct peer */
714 peer_lock (struct peer
*peer
)
716 assert (peer
&& (peer
->lock
>= 0));
723 /* decrease reference count on a struct peer
724 * struct peer is freed and NULL returned if last reference
727 peer_unlock (struct peer
*peer
)
729 assert (peer
&& (peer
->lock
> 0));
736 zlog_debug ("unlocked and freeing");
737 zlog_backtrace (LOG_DEBUG
);
746 zlog_debug ("unlocked to 1");
747 zlog_backtrace (LOG_DEBUG
);
754 /* Allocate new peer object, implicitely locked. */
763 /* Allocate new peer. */
764 peer
= XMALLOC (MTYPE_BGP_PEER
, sizeof (struct peer
));
765 memset (peer
, 0, sizeof (struct peer
));
767 /* Set default value. */
770 peer
->v_start
= BGP_INIT_START_TIMER
;
771 peer
->v_connect
= BGP_DEFAULT_CONNECT_RETRY
;
772 peer
->v_asorig
= BGP_DEFAULT_ASORIGINATE
;
774 peer
->ostatus
= Idle
;
777 /* Set default flags. */
778 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
779 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
781 if (! bgp_option_check (BGP_OPT_CONFIG_CISCO
))
783 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SEND_COMMUNITY
);
784 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SEND_EXT_COMMUNITY
);
786 peer
->orf_plist
[afi
][safi
] = NULL
;
788 SET_FLAG (peer
->sflags
, PEER_STATUS_CAPABILITY_OPEN
);
790 /* Create buffers. */
791 peer
->ibuf
= stream_new (BGP_MAX_PACKET_SIZE
);
792 peer
->obuf
= stream_fifo_new ();
793 peer
->work
= stream_new (BGP_MAX_PACKET_SIZE
);
795 bgp_sync_init (peer
);
797 /* Get service port number. */
798 sp
= getservbyname ("bgp", "tcp");
799 peer
->port
= (sp
== NULL
) ? BGP_PORT_DEFAULT
: ntohs (sp
->s_port
);
804 /* Create new BGP peer. */
806 peer_create (union sockunion
*su
, struct bgp
*bgp
, as_t local_as
,
807 as_t remote_as
, afi_t afi
, safi_t safi
)
811 char buf
[SU_ADDRSTRLEN
];
816 peer
->local_as
= local_as
;
817 peer
->as
= remote_as
;
818 peer
->local_id
= bgp
->router_id
;
819 peer
->v_holdtime
= bgp
->default_holdtime
;
820 peer
->v_keepalive
= bgp
->default_keepalive
;
821 if (peer_sort (peer
) == BGP_PEER_IBGP
)
822 peer
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
824 peer
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
826 peer
= peer_lock (peer
); /* bgp peer list reference */
827 listnode_add_sort (bgp
->peer
, peer
);
829 active
= peer_active (peer
);
832 peer
->afc
[afi
][safi
] = 1;
834 /* Last read time set */
835 peer
->readtime
= time (NULL
);
837 /* Last reset time set */
838 peer
->resettime
= time (NULL
);
840 /* Default TTL set. */
841 peer
->ttl
= (peer_sort (peer
) == BGP_PEER_IBGP
? 255 : 1);
843 /* Make peer's address string. */
844 sockunion2str (su
, buf
, SU_ADDRSTRLEN
);
845 peer
->host
= XSTRDUP (MTYPE_BGP_PEER_HOST
, buf
);
847 /* Set up peer's events and timers. */
848 if (! active
&& peer_active (peer
))
849 bgp_timer_set (peer
);
854 /* Make accept BGP peer. Called from bgp_accept (). */
856 peer_create_accept (struct bgp
*bgp
)
863 peer
= peer_lock (peer
); /* bgp peer list reference */
864 listnode_add_sort (bgp
->peer
, peer
);
869 /* Change peer's AS number. */
871 peer_as_change (struct peer
*peer
, as_t as
)
876 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
878 if (peer
->status
== Established
)
880 peer
->last_reset
= PEER_DOWN_REMOTE_AS_CHANGE
;
881 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
882 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
885 BGP_EVENT_ADD (peer
, BGP_Stop
);
887 type
= peer_sort (peer
);
890 if (bgp_config_check (peer
->bgp
, BGP_CONFIG_CONFEDERATION
)
891 && ! bgp_confederation_peers_check (peer
->bgp
, as
)
892 && peer
->bgp
->as
!= as
)
893 peer
->local_as
= peer
->bgp
->confed_id
;
895 peer
->local_as
= peer
->bgp
->as
;
897 /* Advertisement-interval reset */
898 if (peer_sort (peer
) == BGP_PEER_IBGP
)
899 peer
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
901 peer
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
904 if (peer_sort (peer
) == BGP_PEER_IBGP
)
906 else if (type
== BGP_PEER_IBGP
)
909 /* reflector-client reset */
910 if (peer_sort (peer
) != BGP_PEER_IBGP
)
912 UNSET_FLAG (peer
->af_flags
[AFI_IP
][SAFI_UNICAST
],
913 PEER_FLAG_REFLECTOR_CLIENT
);
914 UNSET_FLAG (peer
->af_flags
[AFI_IP
][SAFI_MULTICAST
],
915 PEER_FLAG_REFLECTOR_CLIENT
);
916 UNSET_FLAG (peer
->af_flags
[AFI_IP
][SAFI_MPLS_VPN
],
917 PEER_FLAG_REFLECTOR_CLIENT
);
918 UNSET_FLAG (peer
->af_flags
[AFI_IP6
][SAFI_UNICAST
],
919 PEER_FLAG_REFLECTOR_CLIENT
);
920 UNSET_FLAG (peer
->af_flags
[AFI_IP6
][SAFI_MULTICAST
],
921 PEER_FLAG_REFLECTOR_CLIENT
);
925 if (peer_sort (peer
) != BGP_PEER_EBGP
)
927 peer
->change_local_as
= 0;
928 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
932 /* If peer does not exist, create new one. If peer already exists,
933 set AS number to the peer. */
935 peer_remote_as (struct bgp
*bgp
, union sockunion
*su
, as_t
*as
,
936 afi_t afi
, safi_t safi
)
941 peer
= peer_lookup (bgp
, su
);
945 /* When this peer is a member of peer-group. */
948 if (peer
->group
->conf
->as
)
950 /* Return peer group's AS number. */
951 *as
= peer
->group
->conf
->as
;
952 return BGP_ERR_PEER_GROUP_MEMBER
;
954 if (peer_sort (peer
->group
->conf
) == BGP_PEER_IBGP
)
959 return BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT
;
967 return BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT
;
972 /* Existing peer's AS number change. */
974 peer_as_change (peer
, *as
);
979 /* If the peer is not part of our confederation, and its not an
980 iBGP peer then spoof the source AS */
981 if (bgp_config_check (bgp
, BGP_CONFIG_CONFEDERATION
)
982 && ! bgp_confederation_peers_check (bgp
, *as
)
984 local_as
= bgp
->confed_id
;
988 /* If this is IPv4 unicast configuration and "no bgp default
989 ipv4-unicast" is specified. */
991 if (bgp_flag_check (bgp
, BGP_FLAG_NO_DEFAULT_IPV4
)
992 && afi
== AFI_IP
&& safi
== SAFI_UNICAST
)
993 peer
= peer_create (su
, bgp
, local_as
, *as
, 0, 0);
995 peer
= peer_create (su
, bgp
, local_as
, *as
, afi
, safi
);
1001 /* Activate the peer or peer group for specified AFI and SAFI. */
1003 peer_activate (struct peer
*peer
, afi_t afi
, safi_t safi
)
1007 if (peer
->afc
[afi
][safi
])
1010 /* Activate the address family configuration. */
1011 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
1012 peer
->afc
[afi
][safi
] = 1;
1015 active
= peer_active (peer
);
1017 peer
->afc
[afi
][safi
] = 1;
1019 if (! active
&& peer_active (peer
))
1020 bgp_timer_set (peer
);
1023 if (peer
->status
== Established
)
1025 if (CHECK_FLAG (peer
->cap
, PEER_CAP_DYNAMIC_RCV
))
1027 peer
->afc_adv
[afi
][safi
] = 1;
1028 bgp_capability_send (peer
, afi
, safi
,
1030 CAPABILITY_ACTION_SET
);
1031 if (peer
->afc_recv
[afi
][safi
])
1033 peer
->afc_nego
[afi
][safi
] = 1;
1034 bgp_announce_route (peer
, afi
, safi
);
1039 peer
->last_reset
= PEER_DOWN_AF_ACTIVATE
;
1040 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1041 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1050 peer_deactivate (struct peer
*peer
, afi_t afi
, safi_t safi
)
1052 struct peer_group
*group
;
1054 struct listnode
*node
, *nnode
;
1056 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
1058 group
= peer
->group
;
1060 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer1
))
1062 if (peer1
->af_group
[afi
][safi
])
1063 return BGP_ERR_PEER_GROUP_MEMBER_EXISTS
;
1068 if (peer
->af_group
[afi
][safi
])
1069 return BGP_ERR_PEER_BELONGS_TO_GROUP
;
1072 if (! peer
->afc
[afi
][safi
])
1075 /* De-activate the address family configuration. */
1076 peer
->afc
[afi
][safi
] = 0;
1077 peer_af_flag_reset (peer
, afi
, safi
);
1079 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
1081 if (peer
->status
== Established
)
1083 if (CHECK_FLAG (peer
->cap
, PEER_CAP_DYNAMIC_RCV
))
1085 peer
->afc_adv
[afi
][safi
] = 0;
1086 peer
->afc_nego
[afi
][safi
] = 0;
1088 if (peer_active_nego (peer
))
1090 bgp_capability_send (peer
, afi
, safi
,
1092 CAPABILITY_ACTION_UNSET
);
1093 bgp_clear_route (peer
, afi
, safi
);
1094 peer
->pcount
[afi
][safi
] = 0;
1098 peer
->last_reset
= PEER_DOWN_NEIGHBOR_DELETE
;
1099 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1100 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1105 peer
->last_reset
= PEER_DOWN_NEIGHBOR_DELETE
;
1106 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1107 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1115 peer_nsf_stop (struct peer
*peer
)
1120 UNSET_FLAG (peer
->sflags
, PEER_STATUS_NSF_WAIT
);
1121 UNSET_FLAG (peer
->sflags
, PEER_STATUS_NSF_MODE
);
1123 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1124 for (safi
= SAFI_UNICAST
; safi
< SAFI_UNICAST_MULTICAST
; safi
++)
1125 peer
->nsf
[afi
][safi
] = 0;
1127 if (peer
->t_gr_restart
)
1129 BGP_TIMER_OFF (peer
->t_gr_restart
);
1130 if (BGP_DEBUG (events
, EVENTS
))
1131 zlog_debug ("%s graceful restart timer stopped", peer
->host
);
1133 if (peer
->t_gr_stale
)
1135 BGP_TIMER_OFF (peer
->t_gr_stale
);
1136 if (BGP_DEBUG (events
, EVENTS
))
1137 zlog_debug ("%s graceful restart stalepath timer stopped", peer
->host
);
1139 bgp_clear_route_all (peer
);
1142 /* Delete peer from confguration. */
1144 peer_delete (struct peer
*peer
)
1150 struct bgp_filter
*filter
;
1154 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_NSF_WAIT
))
1155 peer_nsf_stop (peer
);
1157 /* If this peer belongs to peer group. Clearn up the
1161 peer
= peer_unlock (peer
); /* peer-group reference */
1162 listnode_delete (peer
->group
->peer
, peer
);
1166 /* Withdraw all information from routing table. We can not use
1167 * BGP_EVENT_ADD (peer, BGP_Stop) at here. Because the event is
1168 * executed after peer structure is deleted.
1170 peer
->last_reset
= PEER_DOWN_NEIGHBOR_DELETE
;
1172 bgp_fsm_change_status (peer
, Idle
); /* stops all timers */
1174 /* Stop all timers - should already have been done in bgp_stop */
1175 BGP_TIMER_OFF (peer
->t_start
);
1176 BGP_TIMER_OFF (peer
->t_connect
);
1177 BGP_TIMER_OFF (peer
->t_holdtime
);
1178 BGP_TIMER_OFF (peer
->t_keepalive
);
1179 BGP_TIMER_OFF (peer
->t_asorig
);
1180 BGP_TIMER_OFF (peer
->t_routeadv
);
1181 BGP_TIMER_OFF (peer
->t_pmax_restart
);
1182 BGP_TIMER_OFF (peer
->t_gr_restart
);
1183 BGP_TIMER_OFF (peer
->t_gr_stale
);
1185 /* Delete from all peer list. */
1186 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
1188 peer_unlock (peer
); /* bgp peer list reference */
1189 listnode_delete (bgp
->peer
, peer
);
1191 if (peer_rsclient_active (peer
))
1193 peer_unlock (peer
); /* rsclient list reference */
1194 listnode_delete (bgp
->rsclient
, peer
);
1198 /* Free RIB for any family in which peer is RSERVER_CLIENT, and is not
1199 member of a peer_group. */
1200 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1201 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
1202 if (peer
->rib
[afi
][safi
] && ! peer
->af_group
[afi
][safi
])
1203 bgp_table_finish (peer
->rib
[afi
][safi
]);
1207 stream_free (peer
->ibuf
);
1209 stream_fifo_free (peer
->obuf
);
1211 stream_free (peer
->work
);
1213 peer
->work
= peer
->ibuf
= NULL
;
1215 /* Local and remote addresses. */
1217 sockunion_free (peer
->su_local
);
1218 if (peer
->su_remote
)
1219 sockunion_free (peer
->su_remote
);
1220 peer
->su_local
= peer
->su_remote
= NULL
;
1222 bgp_sync_delete (peer
);
1224 /* Free filter related memory. */
1225 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1226 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
1228 filter
= &peer
->filter
[afi
][safi
];
1230 for (i
= FILTER_IN
; i
< FILTER_MAX
; i
++)
1232 if (filter
->dlist
[i
].name
)
1233 free (filter
->dlist
[i
].name
);
1234 if (filter
->plist
[i
].name
)
1235 free (filter
->plist
[i
].name
);
1236 if (filter
->aslist
[i
].name
)
1237 free (filter
->aslist
[i
].name
);
1239 filter
->dlist
[i
].name
= NULL
;
1240 filter
->plist
[i
].name
= NULL
;
1241 filter
->aslist
[i
].name
= NULL
;
1243 for (i
= RMAP_IN
; i
< RMAP_MAX
; i
++)
1245 if (filter
->map
[i
].name
)
1246 free (filter
->map
[i
].name
);
1247 filter
->map
[i
].name
= NULL
;
1250 if (filter
->usmap
.name
)
1251 free (filter
->usmap
.name
);
1253 if (peer
->default_rmap
[afi
][safi
].name
)
1254 free (peer
->default_rmap
[afi
][safi
].name
);
1256 filter
->usmap
.name
= NULL
;
1257 peer
->default_rmap
[afi
][safi
].name
= NULL
;
1260 peer_unlock (peer
); /* initial reference */
1266 peer_group_cmp (struct peer_group
*g1
, struct peer_group
*g2
)
1268 return strcmp (g1
->name
, g2
->name
);
1271 /* If peer is configured at least one address family return 1. */
1273 peer_group_active (struct peer
*peer
)
1275 if (peer
->af_group
[AFI_IP
][SAFI_UNICAST
]
1276 || peer
->af_group
[AFI_IP
][SAFI_MULTICAST
]
1277 || peer
->af_group
[AFI_IP
][SAFI_MPLS_VPN
]
1278 || peer
->af_group
[AFI_IP6
][SAFI_UNICAST
]
1279 || peer
->af_group
[AFI_IP6
][SAFI_MULTICAST
])
1284 /* Peer group cofiguration. */
1285 static struct peer_group
*
1288 return (struct peer_group
*) XCALLOC (MTYPE_PEER_GROUP
,
1289 sizeof (struct peer_group
));
1293 peer_group_free (struct peer_group
*group
)
1295 XFREE (MTYPE_PEER_GROUP
, group
);
1299 peer_group_lookup (struct bgp
*bgp
, const char *name
)
1301 struct peer_group
*group
;
1302 struct listnode
*node
, *nnode
;
1304 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
1306 if (strcmp (group
->name
, name
) == 0)
1313 peer_group_get (struct bgp
*bgp
, const char *name
)
1315 struct peer_group
*group
;
1317 group
= peer_group_lookup (bgp
, name
);
1321 group
= peer_group_new ();
1323 group
->name
= strdup (name
);
1324 group
->peer
= list_new ();
1325 group
->conf
= peer_new ();
1326 if (! bgp_flag_check (bgp
, BGP_FLAG_NO_DEFAULT_IPV4
))
1327 group
->conf
->afc
[AFI_IP
][SAFI_UNICAST
] = 1;
1328 group
->conf
->host
= strdup (name
);
1329 group
->conf
->bgp
= bgp
;
1330 group
->conf
->group
= group
;
1331 group
->conf
->as
= 0;
1332 group
->conf
->ttl
= 1;
1333 group
->conf
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
1334 UNSET_FLAG (group
->conf
->config
, PEER_CONFIG_TIMER
);
1335 UNSET_FLAG (group
->conf
->config
, PEER_CONFIG_CONNECT
);
1336 group
->conf
->keepalive
= 0;
1337 group
->conf
->holdtime
= 0;
1338 group
->conf
->connect
= 0;
1339 SET_FLAG (group
->conf
->sflags
, PEER_STATUS_GROUP
);
1340 listnode_add_sort (bgp
->group
, group
);
1346 peer_group2peer_config_copy (struct peer_group
*group
, struct peer
*peer
,
1347 afi_t afi
, safi_t safi
)
1350 int out
= FILTER_OUT
;
1352 struct bgp_filter
*pfilter
;
1353 struct bgp_filter
*gfilter
;
1356 pfilter
= &peer
->filter
[afi
][safi
];
1357 gfilter
= &conf
->filter
[afi
][safi
];
1361 peer
->as
= conf
->as
;
1364 if (conf
->change_local_as
)
1365 peer
->change_local_as
= conf
->change_local_as
;
1368 peer
->ttl
= conf
->ttl
;
1371 peer
->weight
= conf
->weight
;
1373 /* peer flags apply */
1374 peer
->flags
= conf
->flags
;
1375 /* peer af_flags apply */
1376 peer
->af_flags
[afi
][safi
] = conf
->af_flags
[afi
][safi
];
1377 /* peer config apply */
1378 peer
->config
= conf
->config
;
1380 /* peer timers apply */
1381 peer
->holdtime
= conf
->holdtime
;
1382 peer
->keepalive
= conf
->keepalive
;
1383 peer
->connect
= conf
->connect
;
1384 if (CHECK_FLAG (conf
->config
, PEER_CONFIG_CONNECT
))
1385 peer
->v_connect
= conf
->connect
;
1387 peer
->v_connect
= BGP_DEFAULT_CONNECT_RETRY
;
1389 /* advertisement-interval reset */
1390 if (peer_sort (peer
) == BGP_PEER_IBGP
)
1391 peer
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
1393 peer
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
1395 /* maximum-prefix */
1396 peer
->pmax
[afi
][safi
] = conf
->pmax
[afi
][safi
];
1397 peer
->pmax_threshold
[afi
][safi
] = conf
->pmax_threshold
[afi
][safi
];
1398 peer
->pmax_restart
[afi
][safi
] = conf
->pmax_restart
[afi
][safi
];
1401 peer
->allowas_in
[afi
][safi
] = conf
->allowas_in
[afi
][safi
];
1403 /* route-server-client */
1404 if (CHECK_FLAG(conf
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
))
1406 /* Make peer's RIB point to group's RIB. */
1407 peer
->rib
[afi
][safi
] = group
->conf
->rib
[afi
][safi
];
1409 /* Import policy. */
1410 if (pfilter
->map
[RMAP_IMPORT
].name
)
1411 free (pfilter
->map
[RMAP_IMPORT
].name
);
1412 if (gfilter
->map
[RMAP_IMPORT
].name
)
1414 pfilter
->map
[RMAP_IMPORT
].name
= strdup (gfilter
->map
[RMAP_IMPORT
].name
);
1415 pfilter
->map
[RMAP_IMPORT
].map
= gfilter
->map
[RMAP_IMPORT
].map
;
1419 pfilter
->map
[RMAP_IMPORT
].name
= NULL
;
1420 pfilter
->map
[RMAP_IMPORT
].map
= NULL
;
1423 /* Export policy. */
1424 if (gfilter
->map
[RMAP_EXPORT
].name
&& ! pfilter
->map
[RMAP_EXPORT
].name
)
1426 pfilter
->map
[RMAP_EXPORT
].name
= strdup (gfilter
->map
[RMAP_EXPORT
].name
);
1427 pfilter
->map
[RMAP_EXPORT
].map
= gfilter
->map
[RMAP_EXPORT
].map
;
1431 /* default-originate route-map */
1432 if (conf
->default_rmap
[afi
][safi
].name
)
1434 if (peer
->default_rmap
[afi
][safi
].name
)
1435 free (peer
->default_rmap
[afi
][safi
].name
);
1436 peer
->default_rmap
[afi
][safi
].name
= strdup (conf
->default_rmap
[afi
][safi
].name
);
1437 peer
->default_rmap
[afi
][safi
].map
= conf
->default_rmap
[afi
][safi
].map
;
1440 /* update-source apply */
1441 if (conf
->update_source
)
1443 if (peer
->update_source
)
1444 sockunion_free (peer
->update_source
);
1445 if (peer
->update_if
)
1447 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
1448 peer
->update_if
= NULL
;
1450 peer
->update_source
= sockunion_dup (conf
->update_source
);
1452 else if (conf
->update_if
)
1454 if (peer
->update_if
)
1455 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
1456 if (peer
->update_source
)
1458 sockunion_free (peer
->update_source
);
1459 peer
->update_source
= NULL
;
1461 peer
->update_if
= XSTRDUP (MTYPE_PEER_UPDATE_SOURCE
, conf
->update_if
);
1464 /* inbound filter apply */
1465 if (gfilter
->dlist
[in
].name
&& ! pfilter
->dlist
[in
].name
)
1467 if (pfilter
->dlist
[in
].name
)
1468 free (pfilter
->dlist
[in
].name
);
1469 pfilter
->dlist
[in
].name
= strdup (gfilter
->dlist
[in
].name
);
1470 pfilter
->dlist
[in
].alist
= gfilter
->dlist
[in
].alist
;
1472 if (gfilter
->plist
[in
].name
&& ! pfilter
->plist
[in
].name
)
1474 if (pfilter
->plist
[in
].name
)
1475 free (pfilter
->plist
[in
].name
);
1476 pfilter
->plist
[in
].name
= strdup (gfilter
->plist
[in
].name
);
1477 pfilter
->plist
[in
].plist
= gfilter
->plist
[in
].plist
;
1479 if (gfilter
->aslist
[in
].name
&& ! pfilter
->aslist
[in
].name
)
1481 if (pfilter
->aslist
[in
].name
)
1482 free (pfilter
->aslist
[in
].name
);
1483 pfilter
->aslist
[in
].name
= strdup (gfilter
->aslist
[in
].name
);
1484 pfilter
->aslist
[in
].aslist
= gfilter
->aslist
[in
].aslist
;
1486 if (gfilter
->map
[RMAP_IN
].name
&& ! pfilter
->map
[RMAP_IN
].name
)
1488 if (pfilter
->map
[RMAP_IN
].name
)
1489 free (pfilter
->map
[RMAP_IN
].name
);
1490 pfilter
->map
[RMAP_IN
].name
= strdup (gfilter
->map
[RMAP_IN
].name
);
1491 pfilter
->map
[RMAP_IN
].map
= gfilter
->map
[RMAP_IN
].map
;
1494 /* outbound filter apply */
1495 if (gfilter
->dlist
[out
].name
)
1497 if (pfilter
->dlist
[out
].name
)
1498 free (pfilter
->dlist
[out
].name
);
1499 pfilter
->dlist
[out
].name
= strdup (gfilter
->dlist
[out
].name
);
1500 pfilter
->dlist
[out
].alist
= gfilter
->dlist
[out
].alist
;
1504 if (pfilter
->dlist
[out
].name
)
1505 free (pfilter
->dlist
[out
].name
);
1506 pfilter
->dlist
[out
].name
= NULL
;
1507 pfilter
->dlist
[out
].alist
= NULL
;
1509 if (gfilter
->plist
[out
].name
)
1511 if (pfilter
->plist
[out
].name
)
1512 free (pfilter
->plist
[out
].name
);
1513 pfilter
->plist
[out
].name
= strdup (gfilter
->plist
[out
].name
);
1514 pfilter
->plist
[out
].plist
= gfilter
->plist
[out
].plist
;
1518 if (pfilter
->plist
[out
].name
)
1519 free (pfilter
->plist
[out
].name
);
1520 pfilter
->plist
[out
].name
= NULL
;
1521 pfilter
->plist
[out
].plist
= NULL
;
1523 if (gfilter
->aslist
[out
].name
)
1525 if (pfilter
->aslist
[out
].name
)
1526 free (pfilter
->aslist
[out
].name
);
1527 pfilter
->aslist
[out
].name
= strdup (gfilter
->aslist
[out
].name
);
1528 pfilter
->aslist
[out
].aslist
= gfilter
->aslist
[out
].aslist
;
1532 if (pfilter
->aslist
[out
].name
)
1533 free (pfilter
->aslist
[out
].name
);
1534 pfilter
->aslist
[out
].name
= NULL
;
1535 pfilter
->aslist
[out
].aslist
= NULL
;
1537 if (gfilter
->map
[RMAP_OUT
].name
)
1539 if (pfilter
->map
[RMAP_OUT
].name
)
1540 free (pfilter
->map
[RMAP_OUT
].name
);
1541 pfilter
->map
[RMAP_OUT
].name
= strdup (gfilter
->map
[RMAP_OUT
].name
);
1542 pfilter
->map
[RMAP_OUT
].map
= gfilter
->map
[RMAP_OUT
].map
;
1546 if (pfilter
->map
[RMAP_OUT
].name
)
1547 free (pfilter
->map
[RMAP_OUT
].name
);
1548 pfilter
->map
[RMAP_OUT
].name
= NULL
;
1549 pfilter
->map
[RMAP_OUT
].map
= NULL
;
1552 /* RS-client's import/export route-maps. */
1553 if (gfilter
->map
[RMAP_IMPORT
].name
)
1555 if (pfilter
->map
[RMAP_IMPORT
].name
)
1556 free (pfilter
->map
[RMAP_IMPORT
].name
);
1557 pfilter
->map
[RMAP_IMPORT
].name
= strdup (gfilter
->map
[RMAP_IMPORT
].name
);
1558 pfilter
->map
[RMAP_IMPORT
].map
= gfilter
->map
[RMAP_IMPORT
].map
;
1562 if (pfilter
->map
[RMAP_IMPORT
].name
)
1563 free (pfilter
->map
[RMAP_IMPORT
].name
);
1564 pfilter
->map
[RMAP_IMPORT
].name
= NULL
;
1565 pfilter
->map
[RMAP_IMPORT
].map
= NULL
;
1567 if (gfilter
->map
[RMAP_EXPORT
].name
&& ! pfilter
->map
[RMAP_EXPORT
].name
)
1569 if (pfilter
->map
[RMAP_EXPORT
].name
)
1570 free (pfilter
->map
[RMAP_EXPORT
].name
);
1571 pfilter
->map
[RMAP_EXPORT
].name
= strdup (gfilter
->map
[RMAP_EXPORT
].name
);
1572 pfilter
->map
[RMAP_EXPORT
].map
= gfilter
->map
[RMAP_EXPORT
].map
;
1575 if (gfilter
->usmap
.name
)
1577 if (pfilter
->usmap
.name
)
1578 free (pfilter
->usmap
.name
);
1579 pfilter
->usmap
.name
= strdup (gfilter
->usmap
.name
);
1580 pfilter
->usmap
.map
= gfilter
->usmap
.map
;
1584 if (pfilter
->usmap
.name
)
1585 free (pfilter
->usmap
.name
);
1586 pfilter
->usmap
.name
= NULL
;
1587 pfilter
->usmap
.map
= NULL
;
1591 /* Peer group's remote AS configuration. */
1593 peer_group_remote_as (struct bgp
*bgp
, const char *group_name
, as_t
*as
)
1595 struct peer_group
*group
;
1597 struct listnode
*node
, *nnode
;
1599 group
= peer_group_lookup (bgp
, group_name
);
1603 if (group
->conf
->as
== *as
)
1606 /* When we setup peer-group AS number all peer group member's AS
1607 number must be updated to same number. */
1608 peer_as_change (group
->conf
, *as
);
1610 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
1612 if (peer
->as
!= *as
)
1613 peer_as_change (peer
, *as
);
1620 peer_group_delete (struct peer_group
*group
)
1624 struct listnode
*node
, *nnode
;
1628 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
1633 list_delete (group
->peer
);
1638 group
->conf
->group
= NULL
;
1639 peer_delete (group
->conf
);
1641 /* Delete from all peer_group list. */
1642 listnode_delete (bgp
->group
, group
);
1644 peer_group_free (group
);
1650 peer_group_remote_as_delete (struct peer_group
*group
)
1653 struct listnode
*node
, *nnode
;
1655 if (! group
->conf
->as
)
1658 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
1663 list_delete_all_node (group
->peer
);
1665 group
->conf
->as
= 0;
1670 /* Bind specified peer to peer group. */
1672 peer_group_bind (struct bgp
*bgp
, union sockunion
*su
,
1673 struct peer_group
*group
, afi_t afi
, safi_t safi
, as_t
*as
)
1676 int first_member
= 0;
1678 /* Check peer group's address family. */
1679 if (! group
->conf
->afc
[afi
][safi
])
1680 return BGP_ERR_PEER_GROUP_AF_UNCONFIGURED
;
1682 /* Lookup the peer. */
1683 peer
= peer_lookup (bgp
, su
);
1685 /* Create a new peer. */
1688 if (! group
->conf
->as
)
1689 return BGP_ERR_PEER_GROUP_NO_REMOTE_AS
;
1691 peer
= peer_create (su
, bgp
, bgp
->as
, group
->conf
->as
, afi
, safi
);
1692 peer
->group
= group
;
1693 peer
->af_group
[afi
][safi
] = 1;
1695 peer
= peer_lock (peer
); /* peer-group group->peer reference */
1696 listnode_add (group
->peer
, peer
);
1697 peer_group2peer_config_copy (group
, peer
, afi
, safi
);
1702 /* When the peer already belongs to peer group, check the consistency. */
1703 if (peer
->af_group
[afi
][safi
])
1705 if (strcmp (peer
->group
->name
, group
->name
) != 0)
1706 return BGP_ERR_PEER_GROUP_CANT_CHANGE
;
1711 /* Check current peer group configuration. */
1712 if (peer_group_active (peer
)
1713 && strcmp (peer
->group
->name
, group
->name
) != 0)
1714 return BGP_ERR_PEER_GROUP_MISMATCH
;
1716 if (! group
->conf
->as
)
1718 if (peer_sort (group
->conf
) != BGP_PEER_INTERNAL
1719 && peer_sort (group
->conf
) != peer_sort (peer
))
1723 return BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT
;
1726 if (peer_sort (group
->conf
) == BGP_PEER_INTERNAL
)
1730 peer
->af_group
[afi
][safi
] = 1;
1731 peer
->afc
[afi
][safi
] = 1;
1734 peer
->group
= group
;
1736 peer
= peer_lock (peer
); /* peer-group group->peer reference */
1737 listnode_add (group
->peer
, peer
);
1742 /* Advertisement-interval reset */
1743 if (peer_sort (group
->conf
) == BGP_PEER_IBGP
)
1744 group
->conf
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
1746 group
->conf
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
1748 /* ebgp-multihop reset */
1749 if (peer_sort (group
->conf
) == BGP_PEER_IBGP
)
1750 group
->conf
->ttl
= 255;
1752 /* local-as reset */
1753 if (peer_sort (group
->conf
) != BGP_PEER_EBGP
)
1755 group
->conf
->change_local_as
= 0;
1756 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
1760 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
))
1762 /* If it's not configured as RSERVER_CLIENT in any other address
1763 family, without being member of a peer_group, remove it from
1764 list bgp->rsclient.*/
1765 if (! peer_rsclient_active (peer
))
1767 peer_unlock (peer
); /* peer rsclient reference */
1768 listnode_delete (bgp
->rsclient
, peer
);
1771 bgp_table_finish (peer
->rib
[afi
][safi
]);
1773 /* Import policy. */
1774 if (peer
->filter
[afi
][safi
].map
[RMAP_IMPORT
].name
)
1776 free (peer
->filter
[afi
][safi
].map
[RMAP_IMPORT
].name
);
1777 peer
->filter
[afi
][safi
].map
[RMAP_IMPORT
].name
= NULL
;
1778 peer
->filter
[afi
][safi
].map
[RMAP_IMPORT
].map
= NULL
;
1781 /* Export policy. */
1782 if (! CHECK_FLAG(group
->conf
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
)
1783 && peer
->filter
[afi
][safi
].map
[RMAP_EXPORT
].name
)
1785 free (peer
->filter
[afi
][safi
].map
[RMAP_EXPORT
].name
);
1786 peer
->filter
[afi
][safi
].map
[RMAP_EXPORT
].name
= NULL
;
1787 peer
->filter
[afi
][safi
].map
[RMAP_EXPORT
].map
= NULL
;
1791 peer_group2peer_config_copy (group
, peer
, afi
, safi
);
1793 if (peer
->status
== Established
)
1795 peer
->last_reset
= PEER_DOWN_RMAP_BIND
;
1796 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1797 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1800 BGP_EVENT_ADD (peer
, BGP_Stop
);
1806 peer_group_unbind (struct bgp
*bgp
, struct peer
*peer
,
1807 struct peer_group
*group
, afi_t afi
, safi_t safi
)
1809 if (! peer
->af_group
[afi
][safi
])
1812 if (group
!= peer
->group
)
1813 return BGP_ERR_PEER_GROUP_MISMATCH
;
1815 peer
->af_group
[afi
][safi
] = 0;
1816 peer
->afc
[afi
][safi
] = 0;
1817 peer_af_flag_reset (peer
, afi
, safi
);
1819 if (peer
->rib
[afi
][safi
])
1820 peer
->rib
[afi
][safi
] = NULL
;
1822 if (! peer_group_active (peer
))
1824 peer_unlock (peer
); /* peer group list reference */
1825 listnode_delete (group
->peer
, peer
);
1827 if (group
->conf
->as
)
1832 peer_global_config_reset (peer
);
1835 if (peer
->status
== Established
)
1837 peer
->last_reset
= PEER_DOWN_RMAP_UNBIND
;
1838 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1839 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1842 BGP_EVENT_ADD (peer
, BGP_Stop
);
1847 /* BGP instance creation by `router bgp' commands. */
1849 bgp_create (as_t
*as
, const char *name
)
1855 if ( (bgp
= XCALLOC (MTYPE_BGP
, sizeof (struct bgp
))) == NULL
)
1858 bgp
->peer_self
= peer_new ();
1859 bgp
->peer_self
->host
= strdup ("Static announcement");
1861 bgp
->peer
= list_new ();
1862 bgp
->peer
->cmp
= (int (*)(void *, void *)) peer_cmp
;
1864 bgp
->group
= list_new ();
1865 bgp
->group
->cmp
= (int (*)(void *, void *)) peer_group_cmp
;
1867 bgp
->rsclient
= list_new ();
1868 bgp
->rsclient
->cmp
= (int (*)(void*, void*)) peer_cmp
;
1870 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1871 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
1873 bgp
->route
[afi
][safi
] = bgp_table_init (afi
, safi
);
1874 bgp
->aggregate
[afi
][safi
] = bgp_table_init (afi
, safi
);
1875 bgp
->rib
[afi
][safi
] = bgp_table_init (afi
, safi
);
1878 bgp
->default_local_pref
= BGP_DEFAULT_LOCAL_PREF
;
1879 bgp
->default_holdtime
= BGP_DEFAULT_HOLDTIME
;
1880 bgp
->default_keepalive
= BGP_DEFAULT_KEEPALIVE
;
1881 bgp
->restart_time
= BGP_DEFAULT_RESTART_TIME
;
1882 bgp
->stalepath_time
= BGP_DEFAULT_STALEPATH_TIME
;
1887 bgp
->name
= strdup (name
);
1892 /* Return first entry of BGP. */
1894 bgp_get_default (void)
1897 return (listgetdata (listhead (bm
->bgp
)));
1901 /* Lookup BGP entry. */
1903 bgp_lookup (as_t as
, const char *name
)
1906 struct listnode
*node
, *nnode
;
1908 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
1910 && ((bgp
->name
== NULL
&& name
== NULL
)
1911 || (bgp
->name
&& name
&& strcmp (bgp
->name
, name
) == 0)))
1916 /* Lookup BGP structure by view name. */
1918 bgp_lookup_by_name (const char *name
)
1921 struct listnode
*node
, *nnode
;
1923 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
1924 if ((bgp
->name
== NULL
&& name
== NULL
)
1925 || (bgp
->name
&& name
&& strcmp (bgp
->name
, name
) == 0))
1930 /* Called from VTY commands. */
1932 bgp_get (struct bgp
**bgp_val
, as_t
*as
, const char *name
)
1936 /* Multiple instance check. */
1937 if (bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE
))
1940 bgp
= bgp_lookup_by_name (name
);
1942 bgp
= bgp_get_default ();
1944 /* Already exists. */
1950 return BGP_ERR_INSTANCE_MISMATCH
;
1958 /* BGP instance name can not be specified for single instance. */
1960 return BGP_ERR_MULTIPLE_INSTANCE_NOT_SET
;
1962 /* Get default BGP structure if exists. */
1963 bgp
= bgp_get_default ();
1970 return BGP_ERR_AS_MISMATCH
;
1977 bgp
= bgp_create (as
, name
);
1978 listnode_add (bm
->bgp
, bgp
);
1979 bgp_router_id_set(bgp
, &router_id_zebra
);
1985 /* Delete BGP instance. */
1987 bgp_delete (struct bgp
*bgp
)
1990 struct peer_group
*group
;
1991 struct listnode
*node
;
1992 struct listnode
*next
;
1997 /* Delete static route. */
1998 bgp_static_delete (bgp
);
2000 /* Unset redistribution. */
2001 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2002 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2003 if (i
!= ZEBRA_ROUTE_BGP
)
2004 bgp_redistribute_unset (bgp
, afi
, i
);
2006 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, next
, group
))
2007 peer_group_delete (group
);
2008 list_delete (bgp
->group
);
2010 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, next
, peer
))
2012 list_delete (bgp
->peer
);
2014 for (ALL_LIST_ELEMENTS (bgp
->rsclient
, node
, next
, peer
))
2016 list_delete (bgp
->rsclient
);
2018 listnode_delete (bm
->bgp
, bgp
);
2023 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2024 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2026 if (bgp
->route
[afi
][safi
])
2027 XFREE (MTYPE_ROUTE_TABLE
, bgp
->route
[afi
][safi
]);
2028 if (bgp
->aggregate
[afi
][safi
])
2029 XFREE (MTYPE_ROUTE_TABLE
,bgp
->aggregate
[afi
][safi
]) ;
2030 if (bgp
->rib
[afi
][safi
])
2031 XFREE (MTYPE_ROUTE_TABLE
,bgp
->rib
[afi
][safi
]);
2033 XFREE (MTYPE_BGP
, bgp
);
2039 peer_lookup (struct bgp
*bgp
, union sockunion
*su
)
2042 struct listnode
*node
, *nnode
;
2045 bgp
= bgp_get_default ();
2050 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2052 if (sockunion_same (&peer
->su
, su
)
2053 && ! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
2060 peer_lookup_with_open (union sockunion
*su
, as_t remote_as
,
2061 struct in_addr
*remote_id
, int *as
)
2064 struct listnode
*node
, *nnode
;
2067 bgp
= bgp_get_default ();
2071 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2073 if (sockunion_same (&peer
->su
, su
)
2074 && ! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
2076 if (peer
->as
== remote_as
2077 && peer
->remote_id
.s_addr
== remote_id
->s_addr
)
2079 if (peer
->as
== remote_as
)
2083 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2085 if (sockunion_same (&peer
->su
, su
)
2086 && ! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
2088 if (peer
->as
== remote_as
2089 && peer
->remote_id
.s_addr
== 0)
2091 if (peer
->as
== remote_as
)
2098 /* If peer is configured at least one address family return 1. */
2100 peer_active (struct peer
*peer
)
2102 if (peer
->afc
[AFI_IP
][SAFI_UNICAST
]
2103 || peer
->afc
[AFI_IP
][SAFI_MULTICAST
]
2104 || peer
->afc
[AFI_IP
][SAFI_MPLS_VPN
]
2105 || peer
->afc
[AFI_IP6
][SAFI_UNICAST
]
2106 || peer
->afc
[AFI_IP6
][SAFI_MULTICAST
])
2111 /* If peer is negotiated at least one address family return 1. */
2113 peer_active_nego (struct peer
*peer
)
2115 if (peer
->afc_nego
[AFI_IP
][SAFI_UNICAST
]
2116 || peer
->afc_nego
[AFI_IP
][SAFI_MULTICAST
]
2117 || peer
->afc_nego
[AFI_IP
][SAFI_MPLS_VPN
]
2118 || peer
->afc_nego
[AFI_IP6
][SAFI_UNICAST
]
2119 || peer
->afc_nego
[AFI_IP6
][SAFI_MULTICAST
])
2124 /* peer_flag_change_type. */
2125 enum peer_change_type
2129 peer_change_reset_in
,
2130 peer_change_reset_out
,
2134 peer_change_action (struct peer
*peer
, afi_t afi
, safi_t safi
,
2135 enum peer_change_type type
)
2137 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2140 if (type
== peer_change_reset
)
2141 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2142 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2143 else if (type
== peer_change_reset_in
)
2145 if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2146 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
2147 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
2149 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2150 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2152 else if (type
== peer_change_reset_out
)
2153 bgp_announce_route (peer
, afi
, safi
);
2156 struct peer_flag_action
2161 /* This flag can be set for peer-group member. */
2162 u_char not_for_member
;
2164 /* Action when the flag is changed. */
2165 enum peer_change_type type
;
2167 /* Peer down cause */
2171 struct peer_flag_action peer_flag_action_list
[] =
2173 { PEER_FLAG_PASSIVE
, 0, peer_change_reset
},
2174 { PEER_FLAG_SHUTDOWN
, 0, peer_change_reset
},
2175 { PEER_FLAG_DONT_CAPABILITY
, 0, peer_change_none
},
2176 { PEER_FLAG_OVERRIDE_CAPABILITY
, 0, peer_change_none
},
2177 { PEER_FLAG_STRICT_CAP_MATCH
, 0, peer_change_none
},
2178 { PEER_FLAG_DYNAMIC_CAPABILITY
, 0, peer_change_reset
},
2179 { PEER_FLAG_DISABLE_CONNECTED_CHECK
, 0, peer_change_reset
},
2183 struct peer_flag_action peer_af_flag_action_list
[] =
2185 { PEER_FLAG_NEXTHOP_SELF
, 1, peer_change_reset_out
},
2186 { PEER_FLAG_SEND_COMMUNITY
, 1, peer_change_reset_out
},
2187 { PEER_FLAG_SEND_EXT_COMMUNITY
, 1, peer_change_reset_out
},
2188 { PEER_FLAG_SOFT_RECONFIG
, 0, peer_change_reset_in
},
2189 { PEER_FLAG_REFLECTOR_CLIENT
, 1, peer_change_reset
},
2190 { PEER_FLAG_RSERVER_CLIENT
, 1, peer_change_reset
},
2191 { PEER_FLAG_AS_PATH_UNCHANGED
, 1, peer_change_reset_out
},
2192 { PEER_FLAG_NEXTHOP_UNCHANGED
, 1, peer_change_reset_out
},
2193 { PEER_FLAG_MED_UNCHANGED
, 1, peer_change_reset_out
},
2194 { PEER_FLAG_REMOVE_PRIVATE_AS
, 1, peer_change_reset_out
},
2195 { PEER_FLAG_ALLOWAS_IN
, 0, peer_change_reset_in
},
2196 { PEER_FLAG_ORF_PREFIX_SM
, 1, peer_change_reset
},
2197 { PEER_FLAG_ORF_PREFIX_RM
, 1, peer_change_reset
},
2198 { PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED
, 0, peer_change_reset_out
},
2202 /* Proper action set. */
2204 peer_flag_action_set (struct peer_flag_action
*action_list
, int size
,
2205 struct peer_flag_action
*action
, u_int32_t flag
)
2211 struct peer_flag_action
*match
= NULL
;
2213 /* Check peer's frag action. */
2214 for (i
= 0; i
< size
; i
++)
2216 match
= &action_list
[i
];
2218 if (match
->flag
== 0)
2221 if (match
->flag
& flag
)
2225 if (match
->type
== peer_change_reset_in
)
2227 if (match
->type
== peer_change_reset_out
)
2229 if (match
->type
== peer_change_reset
)
2234 if (match
->not_for_member
)
2235 action
->not_for_member
= 1;
2239 /* Set peer clear type. */
2240 if (reset_in
&& reset_out
)
2241 action
->type
= peer_change_reset
;
2243 action
->type
= peer_change_reset_in
;
2245 action
->type
= peer_change_reset_out
;
2247 action
->type
= peer_change_none
;
2253 peer_flag_modify_action (struct peer
*peer
, u_int32_t flag
)
2255 if (flag
== PEER_FLAG_SHUTDOWN
)
2257 if (CHECK_FLAG (peer
->flags
, flag
))
2259 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_NSF_WAIT
))
2260 peer_nsf_stop (peer
);
2262 UNSET_FLAG (peer
->sflags
, PEER_STATUS_PREFIX_OVERFLOW
);
2263 if (peer
->t_pmax_restart
)
2265 BGP_TIMER_OFF (peer
->t_pmax_restart
);
2266 if (BGP_DEBUG (events
, EVENTS
))
2267 zlog_debug ("%s Maximum-prefix restart timer canceled",
2271 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_NSF_WAIT
))
2272 peer_nsf_stop (peer
);
2274 if (peer
->status
== Established
)
2275 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2276 BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
);
2278 BGP_EVENT_ADD (peer
, BGP_Stop
);
2282 peer
->v_start
= BGP_INIT_START_TIMER
;
2283 BGP_EVENT_ADD (peer
, BGP_Stop
);
2286 else if (peer
->status
== Established
)
2288 if (flag
== PEER_FLAG_DYNAMIC_CAPABILITY
)
2289 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2290 else if (flag
== PEER_FLAG_PASSIVE
)
2291 peer
->last_reset
= PEER_DOWN_PASSIVE_CHANGE
;
2292 else if (flag
== PEER_FLAG_DISABLE_CONNECTED_CHECK
)
2293 peer
->last_reset
= PEER_DOWN_MULTIHOP_CHANGE
;
2295 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2296 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2299 BGP_EVENT_ADD (peer
, BGP_Stop
);
2302 /* Change specified peer flag. */
2304 peer_flag_modify (struct peer
*peer
, u_int32_t flag
, int set
)
2308 struct peer_group
*group
;
2309 struct listnode
*node
, *nnode
;
2310 struct peer_flag_action action
;
2312 memset (&action
, 0, sizeof (struct peer_flag_action
));
2313 size
= sizeof peer_flag_action_list
/ sizeof (struct peer_flag_action
);
2315 found
= peer_flag_action_set (peer_flag_action_list
, size
, &action
, flag
);
2317 /* No flag action is found. */
2319 return BGP_ERR_INVALID_FLAG
;
2321 /* Not for peer-group member. */
2322 if (action
.not_for_member
&& peer_group_active (peer
))
2323 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
2325 /* When unset the peer-group member's flag we have to check
2326 peer-group configuration. */
2327 if (! set
&& peer_group_active (peer
))
2328 if (CHECK_FLAG (peer
->group
->conf
->flags
, flag
))
2330 if (flag
== PEER_FLAG_SHUTDOWN
)
2331 return BGP_ERR_PEER_GROUP_SHUTDOWN
;
2333 return BGP_ERR_PEER_GROUP_HAS_THE_FLAG
;
2336 /* Flag conflict check. */
2338 && CHECK_FLAG (peer
->flags
| flag
, PEER_FLAG_STRICT_CAP_MATCH
)
2339 && CHECK_FLAG (peer
->flags
| flag
, PEER_FLAG_OVERRIDE_CAPABILITY
))
2340 return BGP_ERR_PEER_FLAG_CONFLICT
;
2342 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2344 if (set
&& CHECK_FLAG (peer
->flags
, flag
) == flag
)
2346 if (! set
&& ! CHECK_FLAG (peer
->flags
, flag
))
2351 SET_FLAG (peer
->flags
, flag
);
2353 UNSET_FLAG (peer
->flags
, flag
);
2355 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2357 if (action
.type
== peer_change_reset
)
2358 peer_flag_modify_action (peer
, flag
);
2363 /* peer-group member updates. */
2364 group
= peer
->group
;
2366 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2368 if (set
&& CHECK_FLAG (peer
->flags
, flag
) == flag
)
2371 if (! set
&& ! CHECK_FLAG (peer
->flags
, flag
))
2375 SET_FLAG (peer
->flags
, flag
);
2377 UNSET_FLAG (peer
->flags
, flag
);
2379 if (action
.type
== peer_change_reset
)
2380 peer_flag_modify_action (peer
, flag
);
2386 peer_flag_set (struct peer
*peer
, u_int32_t flag
)
2388 return peer_flag_modify (peer
, flag
, 1);
2392 peer_flag_unset (struct peer
*peer
, u_int32_t flag
)
2394 return peer_flag_modify (peer
, flag
, 0);
2398 peer_is_group_member (struct peer
*peer
, afi_t afi
, safi_t safi
)
2400 if (peer
->af_group
[afi
][safi
])
2406 peer_af_flag_modify (struct peer
*peer
, afi_t afi
, safi_t safi
, u_int32_t flag
,
2411 struct listnode
*node
, *nnode
;
2412 struct peer_group
*group
;
2413 struct peer_flag_action action
;
2415 memset (&action
, 0, sizeof (struct peer_flag_action
));
2416 size
= sizeof peer_af_flag_action_list
/ sizeof (struct peer_flag_action
);
2418 found
= peer_flag_action_set (peer_af_flag_action_list
, size
, &action
, flag
);
2420 /* No flag action is found. */
2422 return BGP_ERR_INVALID_FLAG
;
2424 /* Adress family must be activated. */
2425 if (! peer
->afc
[afi
][safi
])
2426 return BGP_ERR_PEER_INACTIVE
;
2428 /* Not for peer-group member. */
2429 if (action
.not_for_member
&& peer_is_group_member (peer
, afi
, safi
))
2430 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
2432 /* Spcecial check for reflector client. */
2433 if (flag
& PEER_FLAG_REFLECTOR_CLIENT
2434 && peer_sort (peer
) != BGP_PEER_IBGP
)
2435 return BGP_ERR_NOT_INTERNAL_PEER
;
2437 /* Spcecial check for remove-private-AS. */
2438 if (flag
& PEER_FLAG_REMOVE_PRIVATE_AS
2439 && peer_sort (peer
) == BGP_PEER_IBGP
)
2440 return BGP_ERR_REMOVE_PRIVATE_AS
;
2442 /* When unset the peer-group member's flag we have to check
2443 peer-group configuration. */
2444 if (! set
&& peer
->af_group
[afi
][safi
])
2445 if (CHECK_FLAG (peer
->group
->conf
->af_flags
[afi
][safi
], flag
))
2446 return BGP_ERR_PEER_GROUP_HAS_THE_FLAG
;
2448 /* When current flag configuration is same as requested one. */
2449 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2451 if (set
&& CHECK_FLAG (peer
->af_flags
[afi
][safi
], flag
) == flag
)
2453 if (! set
&& ! CHECK_FLAG (peer
->af_flags
[afi
][safi
], flag
))
2458 SET_FLAG (peer
->af_flags
[afi
][safi
], flag
);
2460 UNSET_FLAG (peer
->af_flags
[afi
][safi
], flag
);
2462 /* Execute action when peer is established. */
2463 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
)
2464 && peer
->status
== Established
)
2466 if (! set
&& flag
== PEER_FLAG_SOFT_RECONFIG
)
2467 bgp_clear_adj_in (peer
, afi
, safi
);
2470 if (flag
== PEER_FLAG_REFLECTOR_CLIENT
)
2471 peer
->last_reset
= PEER_DOWN_RR_CLIENT_CHANGE
;
2472 else if (flag
== PEER_FLAG_RSERVER_CLIENT
)
2473 peer
->last_reset
= PEER_DOWN_RS_CLIENT_CHANGE
;
2474 else if (flag
== PEER_FLAG_ORF_PREFIX_SM
)
2475 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2476 else if (flag
== PEER_FLAG_ORF_PREFIX_RM
)
2477 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2479 peer_change_action (peer
, afi
, safi
, action
.type
);
2484 /* Peer group member updates. */
2485 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2487 group
= peer
->group
;
2489 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2491 if (! peer
->af_group
[afi
][safi
])
2494 if (set
&& CHECK_FLAG (peer
->af_flags
[afi
][safi
], flag
) == flag
)
2497 if (! set
&& ! CHECK_FLAG (peer
->af_flags
[afi
][safi
], flag
))
2501 SET_FLAG (peer
->af_flags
[afi
][safi
], flag
);
2503 UNSET_FLAG (peer
->af_flags
[afi
][safi
], flag
);
2505 if (peer
->status
== Established
)
2507 if (! set
&& flag
== PEER_FLAG_SOFT_RECONFIG
)
2508 bgp_clear_adj_in (peer
, afi
, safi
);
2511 if (flag
== PEER_FLAG_REFLECTOR_CLIENT
)
2512 peer
->last_reset
= PEER_DOWN_RR_CLIENT_CHANGE
;
2513 else if (flag
== PEER_FLAG_RSERVER_CLIENT
)
2514 peer
->last_reset
= PEER_DOWN_RS_CLIENT_CHANGE
;
2515 else if (flag
== PEER_FLAG_ORF_PREFIX_SM
)
2516 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2517 else if (flag
== PEER_FLAG_ORF_PREFIX_RM
)
2518 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2520 peer_change_action (peer
, afi
, safi
, action
.type
);
2529 peer_af_flag_set (struct peer
*peer
, afi_t afi
, safi_t safi
, u_int32_t flag
)
2531 return peer_af_flag_modify (peer
, afi
, safi
, flag
, 1);
2535 peer_af_flag_unset (struct peer
*peer
, afi_t afi
, safi_t safi
, u_int32_t flag
)
2537 return peer_af_flag_modify (peer
, afi
, safi
, flag
, 0);
2540 /* EBGP multihop configuration. */
2542 peer_ebgp_multihop_set (struct peer
*peer
, int ttl
)
2544 struct peer_group
*group
;
2545 struct listnode
*node
, *nnode
;
2547 if (peer_sort (peer
) == BGP_PEER_IBGP
)
2552 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2554 if (peer
->fd
>= 0 && peer_sort (peer
) != BGP_PEER_IBGP
)
2555 sockopt_ttl (peer
->su
.sa
.sa_family
, peer
->fd
, peer
->ttl
);
2559 group
= peer
->group
;
2560 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2562 if (peer_sort (peer
) == BGP_PEER_IBGP
)
2565 peer
->ttl
= group
->conf
->ttl
;
2568 sockopt_ttl (peer
->su
.sa
.sa_family
, peer
->fd
, peer
->ttl
);
2575 peer_ebgp_multihop_unset (struct peer
*peer
)
2577 struct peer_group
*group
;
2578 struct listnode
*node
, *nnode
;
2580 if (peer_sort (peer
) == BGP_PEER_IBGP
)
2583 if (peer_group_active (peer
))
2584 peer
->ttl
= peer
->group
->conf
->ttl
;
2588 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2590 if (peer
->fd
>= 0 && peer_sort (peer
) != BGP_PEER_IBGP
)
2591 sockopt_ttl (peer
->su
.sa
.sa_family
, peer
->fd
, peer
->ttl
);
2595 group
= peer
->group
;
2596 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2598 if (peer_sort (peer
) == BGP_PEER_IBGP
)
2604 sockopt_ttl (peer
->su
.sa
.sa_family
, peer
->fd
, peer
->ttl
);
2610 /* Neighbor description. */
2612 peer_description_set (struct peer
*peer
, char *desc
)
2615 XFREE (MTYPE_PEER_DESC
, peer
->desc
);
2617 peer
->desc
= XSTRDUP (MTYPE_PEER_DESC
, desc
);
2623 peer_description_unset (struct peer
*peer
)
2626 XFREE (MTYPE_PEER_DESC
, peer
->desc
);
2633 /* Neighbor update-source. */
2635 peer_update_source_if_set (struct peer
*peer
, const char *ifname
)
2637 struct peer_group
*group
;
2638 struct listnode
*node
, *nnode
;
2640 if (peer
->update_if
)
2642 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
)
2643 && strcmp (peer
->update_if
, ifname
) == 0)
2646 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2647 peer
->update_if
= NULL
;
2650 if (peer
->update_source
)
2652 sockunion_free (peer
->update_source
);
2653 peer
->update_source
= NULL
;
2656 peer
->update_if
= XSTRDUP (MTYPE_PEER_UPDATE_SOURCE
, ifname
);
2658 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2660 if (peer
->status
== Established
)
2662 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2663 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2664 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2667 BGP_EVENT_ADD (peer
, BGP_Stop
);
2671 /* peer-group member updates. */
2672 group
= peer
->group
;
2673 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2675 if (peer
->update_if
)
2677 if (strcmp (peer
->update_if
, ifname
) == 0)
2680 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2681 peer
->update_if
= NULL
;
2684 if (peer
->update_source
)
2686 sockunion_free (peer
->update_source
);
2687 peer
->update_source
= NULL
;
2690 peer
->update_if
= XSTRDUP (MTYPE_PEER_UPDATE_SOURCE
, ifname
);
2692 if (peer
->status
== Established
)
2694 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2695 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2696 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2699 BGP_EVENT_ADD (peer
, BGP_Stop
);
2705 peer_update_source_addr_set (struct peer
*peer
, union sockunion
*su
)
2707 struct peer_group
*group
;
2708 struct listnode
*node
, *nnode
;
2710 if (peer
->update_source
)
2712 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
)
2713 && sockunion_cmp (peer
->update_source
, su
) == 0)
2715 sockunion_free (peer
->update_source
);
2716 peer
->update_source
= NULL
;
2719 if (peer
->update_if
)
2721 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2722 peer
->update_if
= NULL
;
2725 peer
->update_source
= sockunion_dup (su
);
2727 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2729 if (peer
->status
== Established
)
2731 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2732 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2733 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2736 BGP_EVENT_ADD (peer
, BGP_Stop
);
2740 /* peer-group member updates. */
2741 group
= peer
->group
;
2742 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2744 if (peer
->update_source
)
2746 if (sockunion_cmp (peer
->update_source
, su
) == 0)
2748 sockunion_free (peer
->update_source
);
2749 peer
->update_source
= NULL
;
2752 if (peer
->update_if
)
2754 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2755 peer
->update_if
= NULL
;
2758 peer
->update_source
= sockunion_dup (su
);
2760 if (peer
->status
== Established
)
2762 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2763 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2764 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2767 BGP_EVENT_ADD (peer
, BGP_Stop
);
2773 peer_update_source_unset (struct peer
*peer
)
2775 union sockunion
*su
;
2776 struct peer_group
*group
;
2777 struct listnode
*node
, *nnode
;
2779 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
)
2780 && ! peer
->update_source
2781 && ! peer
->update_if
)
2784 if (peer
->update_source
)
2786 sockunion_free (peer
->update_source
);
2787 peer
->update_source
= NULL
;
2789 if (peer
->update_if
)
2791 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2792 peer
->update_if
= NULL
;
2795 if (peer_group_active (peer
))
2797 group
= peer
->group
;
2799 if (group
->conf
->update_source
)
2801 su
= sockunion_dup (group
->conf
->update_source
);
2802 peer
->update_source
= su
;
2804 else if (group
->conf
->update_if
)
2806 XSTRDUP (MTYPE_PEER_UPDATE_SOURCE
, group
->conf
->update_if
);
2809 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2811 if (peer
->status
== Established
)
2813 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2814 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2815 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2818 BGP_EVENT_ADD (peer
, BGP_Stop
);
2822 /* peer-group member updates. */
2823 group
= peer
->group
;
2824 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2826 if (! peer
->update_source
&& ! peer
->update_if
)
2829 if (peer
->update_source
)
2831 sockunion_free (peer
->update_source
);
2832 peer
->update_source
= NULL
;
2835 if (peer
->update_if
)
2837 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2838 peer
->update_if
= NULL
;
2841 if (peer
->status
== Established
)
2843 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2844 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2845 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2848 BGP_EVENT_ADD (peer
, BGP_Stop
);
2854 peer_default_originate_set (struct peer
*peer
, afi_t afi
, safi_t safi
,
2857 struct peer_group
*group
;
2858 struct listnode
*node
, *nnode
;
2860 /* Adress family must be activated. */
2861 if (! peer
->afc
[afi
][safi
])
2862 return BGP_ERR_PEER_INACTIVE
;
2864 /* Default originate can't be used for peer group memeber. */
2865 if (peer_is_group_member (peer
, afi
, safi
))
2866 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
2868 if (! CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
)
2869 || (rmap
&& ! peer
->default_rmap
[afi
][safi
].name
)
2870 || (rmap
&& strcmp (rmap
, peer
->default_rmap
[afi
][safi
].name
) != 0))
2872 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
);
2876 if (peer
->default_rmap
[afi
][safi
].name
)
2877 free (peer
->default_rmap
[afi
][safi
].name
);
2878 peer
->default_rmap
[afi
][safi
].name
= strdup (rmap
);
2879 peer
->default_rmap
[afi
][safi
].map
= route_map_lookup_by_name (rmap
);
2883 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2885 if (peer
->status
== Established
&& peer
->afc_nego
[afi
][safi
])
2886 bgp_default_originate (peer
, afi
, safi
, 0);
2890 /* peer-group member updates. */
2891 group
= peer
->group
;
2892 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2894 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
);
2898 if (peer
->default_rmap
[afi
][safi
].name
)
2899 free (peer
->default_rmap
[afi
][safi
].name
);
2900 peer
->default_rmap
[afi
][safi
].name
= strdup (rmap
);
2901 peer
->default_rmap
[afi
][safi
].map
= route_map_lookup_by_name (rmap
);
2904 if (peer
->status
== Established
&& peer
->afc_nego
[afi
][safi
])
2905 bgp_default_originate (peer
, afi
, safi
, 0);
2911 peer_default_originate_unset (struct peer
*peer
, afi_t afi
, safi_t safi
)
2913 struct peer_group
*group
;
2914 struct listnode
*node
, *nnode
;
2916 /* Adress family must be activated. */
2917 if (! peer
->afc
[afi
][safi
])
2918 return BGP_ERR_PEER_INACTIVE
;
2920 /* Default originate can't be used for peer group memeber. */
2921 if (peer_is_group_member (peer
, afi
, safi
))
2922 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
2924 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
))
2926 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
);
2928 if (peer
->default_rmap
[afi
][safi
].name
)
2929 free (peer
->default_rmap
[afi
][safi
].name
);
2930 peer
->default_rmap
[afi
][safi
].name
= NULL
;
2931 peer
->default_rmap
[afi
][safi
].map
= NULL
;
2934 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2936 if (peer
->status
== Established
&& peer
->afc_nego
[afi
][safi
])
2937 bgp_default_originate (peer
, afi
, safi
, 1);
2941 /* peer-group member updates. */
2942 group
= peer
->group
;
2943 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2945 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
);
2947 if (peer
->default_rmap
[afi
][safi
].name
)
2948 free (peer
->default_rmap
[afi
][safi
].name
);
2949 peer
->default_rmap
[afi
][safi
].name
= NULL
;
2950 peer
->default_rmap
[afi
][safi
].map
= NULL
;
2952 if (peer
->status
== Established
&& peer
->afc_nego
[afi
][safi
])
2953 bgp_default_originate (peer
, afi
, safi
, 1);
2959 peer_port_set (struct peer
*peer
, u_int16_t port
)
2966 peer_port_unset (struct peer
*peer
)
2968 peer
->port
= BGP_PORT_DEFAULT
;
2972 /* neighbor weight. */
2974 peer_weight_set (struct peer
*peer
, u_int16_t weight
)
2976 struct peer_group
*group
;
2977 struct listnode
*node
, *nnode
;
2979 SET_FLAG (peer
->config
, PEER_CONFIG_WEIGHT
);
2980 peer
->weight
= weight
;
2982 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2985 /* peer-group member updates. */
2986 group
= peer
->group
;
2987 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2989 peer
->weight
= group
->conf
->weight
;
2995 peer_weight_unset (struct peer
*peer
)
2997 struct peer_group
*group
;
2998 struct listnode
*node
, *nnode
;
3000 /* Set default weight. */
3001 if (peer_group_active (peer
))
3002 peer
->weight
= peer
->group
->conf
->weight
;
3006 UNSET_FLAG (peer
->config
, PEER_CONFIG_WEIGHT
);
3008 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3011 /* peer-group member updates. */
3012 group
= peer
->group
;
3013 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3021 peer_timers_set (struct peer
*peer
, u_int32_t keepalive
, u_int32_t holdtime
)
3023 struct peer_group
*group
;
3024 struct listnode
*node
, *nnode
;
3026 /* Not for peer group memeber. */
3027 if (peer_group_active (peer
))
3028 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3030 /* keepalive value check. */
3031 if (keepalive
> 65535)
3032 return BGP_ERR_INVALID_VALUE
;
3034 /* Holdtime value check. */
3035 if (holdtime
> 65535)
3036 return BGP_ERR_INVALID_VALUE
;
3038 /* Holdtime value must be either 0 or greater than 3. */
3039 if (holdtime
< 3 && holdtime
!= 0)
3040 return BGP_ERR_INVALID_VALUE
;
3042 /* Set value to the configuration. */
3043 SET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
3044 peer
->holdtime
= holdtime
;
3045 peer
->keepalive
= (keepalive
< holdtime
/ 3 ? keepalive
: holdtime
/ 3);
3047 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3050 /* peer-group member updates. */
3051 group
= peer
->group
;
3052 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3054 SET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
3055 peer
->holdtime
= group
->conf
->holdtime
;
3056 peer
->keepalive
= group
->conf
->keepalive
;
3062 peer_timers_unset (struct peer
*peer
)
3064 struct peer_group
*group
;
3065 struct listnode
*node
, *nnode
;
3067 if (peer_group_active (peer
))
3068 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3070 /* Clear configuration. */
3071 UNSET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
3072 peer
->keepalive
= 0;
3075 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3078 /* peer-group member updates. */
3079 group
= peer
->group
;
3080 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3082 UNSET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
3084 peer
->keepalive
= 0;
3091 peer_timers_connect_set (struct peer
*peer
, u_int32_t connect
)
3093 if (peer_group_active (peer
))
3094 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3096 if (connect
> 65535)
3097 return BGP_ERR_INVALID_VALUE
;
3099 /* Set value to the configuration. */
3100 SET_FLAG (peer
->config
, PEER_CONFIG_CONNECT
);
3101 peer
->connect
= connect
;
3103 /* Set value to timer setting. */
3104 peer
->v_connect
= connect
;
3110 peer_timers_connect_unset (struct peer
*peer
)
3112 if (peer_group_active (peer
))
3113 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3115 /* Clear configuration. */
3116 UNSET_FLAG (peer
->config
, PEER_CONFIG_CONNECT
);
3119 /* Set timer setting to default value. */
3120 peer
->v_connect
= BGP_DEFAULT_CONNECT_RETRY
;
3126 peer_advertise_interval_set (struct peer
*peer
, u_int32_t routeadv
)
3128 if (peer_group_active (peer
))
3129 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3132 return BGP_ERR_INVALID_VALUE
;
3134 SET_FLAG (peer
->config
, PEER_CONFIG_ROUTEADV
);
3135 peer
->routeadv
= routeadv
;
3136 peer
->v_routeadv
= routeadv
;
3142 peer_advertise_interval_unset (struct peer
*peer
)
3144 if (peer_group_active (peer
))
3145 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3147 UNSET_FLAG (peer
->config
, PEER_CONFIG_ROUTEADV
);
3150 if (peer_sort (peer
) == BGP_PEER_IBGP
)
3151 peer
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
3153 peer
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
3158 /* neighbor interface */
3160 peer_interface_set (struct peer
*peer
, const char *str
)
3163 free (peer
->ifname
);
3164 peer
->ifname
= strdup (str
);
3170 peer_interface_unset (struct peer
*peer
)
3173 free (peer
->ifname
);
3174 peer
->ifname
= NULL
;
3181 peer_allowas_in_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int allow_num
)
3183 struct peer_group
*group
;
3184 struct listnode
*node
, *nnode
;
3186 if (allow_num
< 1 || allow_num
> 10)
3187 return BGP_ERR_INVALID_VALUE
;
3189 if (peer
->allowas_in
[afi
][safi
] != allow_num
)
3191 peer
->allowas_in
[afi
][safi
] = allow_num
;
3192 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ALLOWAS_IN
);
3193 peer_change_action (peer
, afi
, safi
, peer_change_reset_in
);
3196 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3199 group
= peer
->group
;
3200 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3202 if (peer
->allowas_in
[afi
][safi
] != allow_num
)
3204 peer
->allowas_in
[afi
][safi
] = allow_num
;
3205 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ALLOWAS_IN
);
3206 peer_change_action (peer
, afi
, safi
, peer_change_reset_in
);
3214 peer_allowas_in_unset (struct peer
*peer
, afi_t afi
, safi_t safi
)
3216 struct peer_group
*group
;
3217 struct listnode
*node
, *nnode
;
3219 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ALLOWAS_IN
))
3221 peer
->allowas_in
[afi
][safi
] = 0;
3222 peer_af_flag_unset (peer
, afi
, safi
, PEER_FLAG_ALLOWAS_IN
);
3225 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3228 group
= peer
->group
;
3229 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3231 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ALLOWAS_IN
))
3233 peer
->allowas_in
[afi
][safi
] = 0;
3234 peer_af_flag_unset (peer
, afi
, safi
, PEER_FLAG_ALLOWAS_IN
);
3241 peer_local_as_set (struct peer
*peer
, as_t as
, int no_prepend
)
3243 struct bgp
*bgp
= peer
->bgp
;
3244 struct peer_group
*group
;
3245 struct listnode
*node
, *nnode
;
3247 if (peer_sort (peer
) != BGP_PEER_EBGP
3248 && peer_sort (peer
) != BGP_PEER_INTERNAL
)
3249 return BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP
;
3252 return BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS
;
3254 if (peer_group_active (peer
))
3255 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3257 if (peer
->change_local_as
== as
&&
3258 ((CHECK_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
) && no_prepend
)
3259 || (! CHECK_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
) && ! no_prepend
)))
3262 peer
->change_local_as
= as
;
3264 SET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3266 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3268 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3270 if (peer
->status
== Established
)
3272 peer
->last_reset
= PEER_DOWN_LOCAL_AS_CHANGE
;
3273 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
3274 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3277 BGP_EVENT_ADD (peer
, BGP_Stop
);
3282 group
= peer
->group
;
3283 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3285 peer
->change_local_as
= as
;
3287 SET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3289 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3291 if (peer
->status
== Established
)
3293 peer
->last_reset
= PEER_DOWN_LOCAL_AS_CHANGE
;
3294 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
3295 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3298 BGP_EVENT_ADD (peer
, BGP_Stop
);
3305 peer_local_as_unset (struct peer
*peer
)
3307 struct peer_group
*group
;
3308 struct listnode
*node
, *nnode
;
3310 if (peer_group_active (peer
))
3311 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3313 if (! peer
->change_local_as
)
3316 peer
->change_local_as
= 0;
3317 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3319 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3321 if (peer
->status
== Established
)
3323 peer
->last_reset
= PEER_DOWN_LOCAL_AS_CHANGE
;
3324 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
3325 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3328 BGP_EVENT_ADD (peer
, BGP_Stop
);
3333 group
= peer
->group
;
3334 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3336 peer
->change_local_as
= 0;
3337 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3339 if (peer
->status
== Established
)
3341 peer
->last_reset
= PEER_DOWN_LOCAL_AS_CHANGE
;
3342 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
3343 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3346 BGP_EVENT_ADD (peer
, BGP_Stop
);
3351 /* Set distribute list to the peer. */
3353 peer_distribute_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
,
3356 struct bgp_filter
*filter
;
3357 struct peer_group
*group
;
3358 struct listnode
*node
, *nnode
;
3360 if (! peer
->afc
[afi
][safi
])
3361 return BGP_ERR_PEER_INACTIVE
;
3363 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3364 return BGP_ERR_INVALID_VALUE
;
3366 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3367 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3369 filter
= &peer
->filter
[afi
][safi
];
3371 if (filter
->plist
[direct
].name
)
3372 return BGP_ERR_PEER_FILTER_CONFLICT
;
3374 if (filter
->dlist
[direct
].name
)
3375 free (filter
->dlist
[direct
].name
);
3376 filter
->dlist
[direct
].name
= strdup (name
);
3377 filter
->dlist
[direct
].alist
= access_list_lookup (afi
, name
);
3379 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3382 group
= peer
->group
;
3383 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3385 filter
= &peer
->filter
[afi
][safi
];
3387 if (! peer
->af_group
[afi
][safi
])
3390 if (filter
->dlist
[direct
].name
)
3391 free (filter
->dlist
[direct
].name
);
3392 filter
->dlist
[direct
].name
= strdup (name
);
3393 filter
->dlist
[direct
].alist
= access_list_lookup (afi
, name
);
3400 peer_distribute_unset (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
)
3402 struct bgp_filter
*filter
;
3403 struct bgp_filter
*gfilter
;
3404 struct peer_group
*group
;
3405 struct listnode
*node
, *nnode
;
3407 if (! peer
->afc
[afi
][safi
])
3408 return BGP_ERR_PEER_INACTIVE
;
3410 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3411 return BGP_ERR_INVALID_VALUE
;
3413 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3414 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3416 filter
= &peer
->filter
[afi
][safi
];
3418 /* apply peer-group filter */
3419 if (peer
->af_group
[afi
][safi
])
3421 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
3423 if (gfilter
->dlist
[direct
].name
)
3425 if (filter
->dlist
[direct
].name
)
3426 free (filter
->dlist
[direct
].name
);
3427 filter
->dlist
[direct
].name
= strdup (gfilter
->dlist
[direct
].name
);
3428 filter
->dlist
[direct
].alist
= gfilter
->dlist
[direct
].alist
;
3433 if (filter
->dlist
[direct
].name
)
3434 free (filter
->dlist
[direct
].name
);
3435 filter
->dlist
[direct
].name
= NULL
;
3436 filter
->dlist
[direct
].alist
= NULL
;
3438 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3441 group
= peer
->group
;
3442 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3444 filter
= &peer
->filter
[afi
][safi
];
3446 if (! peer
->af_group
[afi
][safi
])
3449 if (filter
->dlist
[direct
].name
)
3450 free (filter
->dlist
[direct
].name
);
3451 filter
->dlist
[direct
].name
= NULL
;
3452 filter
->dlist
[direct
].alist
= NULL
;
3458 /* Update distribute list. */
3460 peer_distribute_update (struct access_list
*access
)
3465 struct listnode
*mnode
, *mnnode
;
3466 struct listnode
*node
, *nnode
;
3469 struct peer_group
*group
;
3470 struct bgp_filter
*filter
;
3472 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
3474 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
3476 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3477 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3479 filter
= &peer
->filter
[afi
][safi
];
3481 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3483 if (filter
->dlist
[direct
].name
)
3484 filter
->dlist
[direct
].alist
=
3485 access_list_lookup (afi
, filter
->dlist
[direct
].name
);
3487 filter
->dlist
[direct
].alist
= NULL
;
3491 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
3493 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3494 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3496 filter
= &group
->conf
->filter
[afi
][safi
];
3498 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3500 if (filter
->dlist
[direct
].name
)
3501 filter
->dlist
[direct
].alist
=
3502 access_list_lookup (afi
, filter
->dlist
[direct
].name
);
3504 filter
->dlist
[direct
].alist
= NULL
;
3511 /* Set prefix list to the peer. */
3513 peer_prefix_list_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
,
3516 struct bgp_filter
*filter
;
3517 struct peer_group
*group
;
3518 struct listnode
*node
, *nnode
;
3520 if (! peer
->afc
[afi
][safi
])
3521 return BGP_ERR_PEER_INACTIVE
;
3523 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3524 return BGP_ERR_INVALID_VALUE
;
3526 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3527 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3529 filter
= &peer
->filter
[afi
][safi
];
3531 if (filter
->dlist
[direct
].name
)
3532 return BGP_ERR_PEER_FILTER_CONFLICT
;
3534 if (filter
->plist
[direct
].name
)
3535 free (filter
->plist
[direct
].name
);
3536 filter
->plist
[direct
].name
= strdup (name
);
3537 filter
->plist
[direct
].plist
= prefix_list_lookup (afi
, name
);
3539 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3542 group
= peer
->group
;
3543 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3545 filter
= &peer
->filter
[afi
][safi
];
3547 if (! peer
->af_group
[afi
][safi
])
3550 if (filter
->plist
[direct
].name
)
3551 free (filter
->plist
[direct
].name
);
3552 filter
->plist
[direct
].name
= strdup (name
);
3553 filter
->plist
[direct
].plist
= prefix_list_lookup (afi
, name
);
3559 peer_prefix_list_unset (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
)
3561 struct bgp_filter
*filter
;
3562 struct bgp_filter
*gfilter
;
3563 struct peer_group
*group
;
3564 struct listnode
*node
, *nnode
;
3566 if (! peer
->afc
[afi
][safi
])
3567 return BGP_ERR_PEER_INACTIVE
;
3569 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3570 return BGP_ERR_INVALID_VALUE
;
3572 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3573 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3575 filter
= &peer
->filter
[afi
][safi
];
3577 /* apply peer-group filter */
3578 if (peer
->af_group
[afi
][safi
])
3580 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
3582 if (gfilter
->plist
[direct
].name
)
3584 if (filter
->plist
[direct
].name
)
3585 free (filter
->plist
[direct
].name
);
3586 filter
->plist
[direct
].name
= strdup (gfilter
->plist
[direct
].name
);
3587 filter
->plist
[direct
].plist
= gfilter
->plist
[direct
].plist
;
3592 if (filter
->plist
[direct
].name
)
3593 free (filter
->plist
[direct
].name
);
3594 filter
->plist
[direct
].name
= NULL
;
3595 filter
->plist
[direct
].plist
= NULL
;
3597 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3600 group
= peer
->group
;
3601 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3603 filter
= &peer
->filter
[afi
][safi
];
3605 if (! peer
->af_group
[afi
][safi
])
3608 if (filter
->plist
[direct
].name
)
3609 free (filter
->plist
[direct
].name
);
3610 filter
->plist
[direct
].name
= NULL
;
3611 filter
->plist
[direct
].plist
= NULL
;
3617 /* Update prefix-list list. */
3619 peer_prefix_list_update (struct prefix_list
*plist
)
3621 struct listnode
*mnode
, *mnnode
;
3622 struct listnode
*node
, *nnode
;
3625 struct peer_group
*group
;
3626 struct bgp_filter
*filter
;
3631 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
3633 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
3635 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3636 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3638 filter
= &peer
->filter
[afi
][safi
];
3640 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3642 if (filter
->plist
[direct
].name
)
3643 filter
->plist
[direct
].plist
=
3644 prefix_list_lookup (afi
, filter
->plist
[direct
].name
);
3646 filter
->plist
[direct
].plist
= NULL
;
3650 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
3652 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3653 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3655 filter
= &group
->conf
->filter
[afi
][safi
];
3657 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3659 if (filter
->plist
[direct
].name
)
3660 filter
->plist
[direct
].plist
=
3661 prefix_list_lookup (afi
, filter
->plist
[direct
].name
);
3663 filter
->plist
[direct
].plist
= NULL
;
3671 peer_aslist_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
,
3674 struct bgp_filter
*filter
;
3675 struct peer_group
*group
;
3676 struct listnode
*node
, *nnode
;
3678 if (! peer
->afc
[afi
][safi
])
3679 return BGP_ERR_PEER_INACTIVE
;
3681 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3682 return BGP_ERR_INVALID_VALUE
;
3684 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3685 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3687 filter
= &peer
->filter
[afi
][safi
];
3689 if (filter
->aslist
[direct
].name
)
3690 free (filter
->aslist
[direct
].name
);
3691 filter
->aslist
[direct
].name
= strdup (name
);
3692 filter
->aslist
[direct
].aslist
= as_list_lookup (name
);
3694 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3697 group
= peer
->group
;
3698 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3700 filter
= &peer
->filter
[afi
][safi
];
3702 if (! peer
->af_group
[afi
][safi
])
3705 if (filter
->aslist
[direct
].name
)
3706 free (filter
->aslist
[direct
].name
);
3707 filter
->aslist
[direct
].name
= strdup (name
);
3708 filter
->aslist
[direct
].aslist
= as_list_lookup (name
);
3714 peer_aslist_unset (struct peer
*peer
,afi_t afi
, safi_t safi
, int direct
)
3716 struct bgp_filter
*filter
;
3717 struct bgp_filter
*gfilter
;
3718 struct peer_group
*group
;
3719 struct listnode
*node
, *nnode
;
3721 if (! peer
->afc
[afi
][safi
])
3722 return BGP_ERR_PEER_INACTIVE
;
3724 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3725 return BGP_ERR_INVALID_VALUE
;
3727 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3728 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3730 filter
= &peer
->filter
[afi
][safi
];
3732 /* apply peer-group filter */
3733 if (peer
->af_group
[afi
][safi
])
3735 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
3737 if (gfilter
->aslist
[direct
].name
)
3739 if (filter
->aslist
[direct
].name
)
3740 free (filter
->aslist
[direct
].name
);
3741 filter
->aslist
[direct
].name
= strdup (gfilter
->aslist
[direct
].name
);
3742 filter
->aslist
[direct
].aslist
= gfilter
->aslist
[direct
].aslist
;
3747 if (filter
->aslist
[direct
].name
)
3748 free (filter
->aslist
[direct
].name
);
3749 filter
->aslist
[direct
].name
= NULL
;
3750 filter
->aslist
[direct
].aslist
= NULL
;
3752 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3755 group
= peer
->group
;
3756 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3758 filter
= &peer
->filter
[afi
][safi
];
3760 if (! peer
->af_group
[afi
][safi
])
3763 if (filter
->aslist
[direct
].name
)
3764 free (filter
->aslist
[direct
].name
);
3765 filter
->aslist
[direct
].name
= NULL
;
3766 filter
->aslist
[direct
].aslist
= NULL
;
3773 peer_aslist_update ()
3778 struct listnode
*mnode
, *mnnode
;
3779 struct listnode
*node
, *nnode
;
3782 struct peer_group
*group
;
3783 struct bgp_filter
*filter
;
3785 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
3787 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
3789 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3790 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3792 filter
= &peer
->filter
[afi
][safi
];
3794 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3796 if (filter
->aslist
[direct
].name
)
3797 filter
->aslist
[direct
].aslist
=
3798 as_list_lookup (filter
->aslist
[direct
].name
);
3800 filter
->aslist
[direct
].aslist
= NULL
;
3804 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
3806 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3807 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3809 filter
= &group
->conf
->filter
[afi
][safi
];
3811 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3813 if (filter
->aslist
[direct
].name
)
3814 filter
->aslist
[direct
].aslist
=
3815 as_list_lookup (filter
->aslist
[direct
].name
);
3817 filter
->aslist
[direct
].aslist
= NULL
;
3824 /* Set route-map to the peer. */
3826 peer_route_map_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
,
3829 struct bgp_filter
*filter
;
3830 struct peer_group
*group
;
3831 struct listnode
*node
, *nnode
;
3833 if (! peer
->afc
[afi
][safi
])
3834 return BGP_ERR_PEER_INACTIVE
;
3836 if (direct
!= RMAP_IN
&& direct
!= RMAP_OUT
&&
3837 direct
!= RMAP_IMPORT
&& direct
!= RMAP_EXPORT
)
3838 return BGP_ERR_INVALID_VALUE
;
3840 if ( (direct
== RMAP_OUT
|| direct
== RMAP_IMPORT
)
3841 && peer_is_group_member (peer
, afi
, safi
))
3842 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3844 filter
= &peer
->filter
[afi
][safi
];
3846 if (filter
->map
[direct
].name
)
3847 free (filter
->map
[direct
].name
);
3849 filter
->map
[direct
].name
= strdup (name
);
3850 filter
->map
[direct
].map
= route_map_lookup_by_name (name
);
3852 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3855 group
= peer
->group
;
3856 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3858 filter
= &peer
->filter
[afi
][safi
];
3860 if (! peer
->af_group
[afi
][safi
])
3863 if (filter
->map
[direct
].name
)
3864 free (filter
->map
[direct
].name
);
3865 filter
->map
[direct
].name
= strdup (name
);
3866 filter
->map
[direct
].map
= route_map_lookup_by_name (name
);
3871 /* Unset route-map from the peer. */
3873 peer_route_map_unset (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
)
3875 struct bgp_filter
*filter
;
3876 struct bgp_filter
*gfilter
;
3877 struct peer_group
*group
;
3878 struct listnode
*node
, *nnode
;
3880 if (! peer
->afc
[afi
][safi
])
3881 return BGP_ERR_PEER_INACTIVE
;
3883 if (direct
!= RMAP_IN
&& direct
!= RMAP_OUT
&&
3884 direct
!= RMAP_IMPORT
&& direct
!= RMAP_EXPORT
)
3885 return BGP_ERR_INVALID_VALUE
;
3887 if ( (direct
== RMAP_OUT
|| direct
== RMAP_IMPORT
)
3888 && peer_is_group_member (peer
, afi
, safi
))
3889 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3891 filter
= &peer
->filter
[afi
][safi
];
3893 /* apply peer-group filter */
3894 if (peer
->af_group
[afi
][safi
])
3896 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
3898 if (gfilter
->map
[direct
].name
)
3900 if (filter
->map
[direct
].name
)
3901 free (filter
->map
[direct
].name
);
3902 filter
->map
[direct
].name
= strdup (gfilter
->map
[direct
].name
);
3903 filter
->map
[direct
].map
= gfilter
->map
[direct
].map
;
3908 if (filter
->map
[direct
].name
)
3909 free (filter
->map
[direct
].name
);
3910 filter
->map
[direct
].name
= NULL
;
3911 filter
->map
[direct
].map
= NULL
;
3913 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3916 group
= peer
->group
;
3917 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3919 filter
= &peer
->filter
[afi
][safi
];
3921 if (! peer
->af_group
[afi
][safi
])
3924 if (filter
->map
[direct
].name
)
3925 free (filter
->map
[direct
].name
);
3926 filter
->map
[direct
].name
= NULL
;
3927 filter
->map
[direct
].map
= NULL
;
3932 /* Set unsuppress-map to the peer. */
3934 peer_unsuppress_map_set (struct peer
*peer
, afi_t afi
, safi_t safi
,
3937 struct bgp_filter
*filter
;
3938 struct peer_group
*group
;
3939 struct listnode
*node
, *nnode
;
3941 if (! peer
->afc
[afi
][safi
])
3942 return BGP_ERR_PEER_INACTIVE
;
3944 if (peer_is_group_member (peer
, afi
, safi
))
3945 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3947 filter
= &peer
->filter
[afi
][safi
];
3949 if (filter
->usmap
.name
)
3950 free (filter
->usmap
.name
);
3952 filter
->usmap
.name
= strdup (name
);
3953 filter
->usmap
.map
= route_map_lookup_by_name (name
);
3955 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3958 group
= peer
->group
;
3959 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3961 filter
= &peer
->filter
[afi
][safi
];
3963 if (! peer
->af_group
[afi
][safi
])
3966 if (filter
->usmap
.name
)
3967 free (filter
->usmap
.name
);
3968 filter
->usmap
.name
= strdup (name
);
3969 filter
->usmap
.map
= route_map_lookup_by_name (name
);
3974 /* Unset route-map from the peer. */
3976 peer_unsuppress_map_unset (struct peer
*peer
, afi_t afi
, safi_t safi
)
3978 struct bgp_filter
*filter
;
3979 struct peer_group
*group
;
3980 struct listnode
*node
, *nnode
;
3982 if (! peer
->afc
[afi
][safi
])
3983 return BGP_ERR_PEER_INACTIVE
;
3985 if (peer_is_group_member (peer
, afi
, safi
))
3986 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3988 filter
= &peer
->filter
[afi
][safi
];
3990 if (filter
->usmap
.name
)
3991 free (filter
->usmap
.name
);
3992 filter
->usmap
.name
= NULL
;
3993 filter
->usmap
.map
= NULL
;
3995 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3998 group
= peer
->group
;
3999 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
4001 filter
= &peer
->filter
[afi
][safi
];
4003 if (! peer
->af_group
[afi
][safi
])
4006 if (filter
->usmap
.name
)
4007 free (filter
->usmap
.name
);
4008 filter
->usmap
.name
= NULL
;
4009 filter
->usmap
.map
= NULL
;
4015 peer_maximum_prefix_set (struct peer
*peer
, afi_t afi
, safi_t safi
,
4016 u_int32_t max
, u_char threshold
,
4017 int warning
, u_int16_t restart
)
4019 struct peer_group
*group
;
4020 struct listnode
*node
, *nnode
;
4022 if (! peer
->afc
[afi
][safi
])
4023 return BGP_ERR_PEER_INACTIVE
;
4025 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4026 peer
->pmax
[afi
][safi
] = max
;
4027 peer
->pmax_threshold
[afi
][safi
] = threshold
;
4028 peer
->pmax_restart
[afi
][safi
] = restart
;
4030 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4032 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4034 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4037 group
= peer
->group
;
4038 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
4040 if (! peer
->af_group
[afi
][safi
])
4043 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4044 peer
->pmax
[afi
][safi
] = max
;
4045 peer
->pmax_threshold
[afi
][safi
] = threshold
;
4046 peer
->pmax_restart
[afi
][safi
] = restart
;
4048 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4050 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4056 peer_maximum_prefix_unset (struct peer
*peer
, afi_t afi
, safi_t safi
)
4058 struct peer_group
*group
;
4059 struct listnode
*node
, *nnode
;
4061 if (! peer
->afc
[afi
][safi
])
4062 return BGP_ERR_PEER_INACTIVE
;
4064 /* apply peer-group config */
4065 if (peer
->af_group
[afi
][safi
])
4067 if (CHECK_FLAG (peer
->group
->conf
->af_flags
[afi
][safi
],
4068 PEER_FLAG_MAX_PREFIX
))
4069 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4071 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4073 if (CHECK_FLAG (peer
->group
->conf
->af_flags
[afi
][safi
],
4074 PEER_FLAG_MAX_PREFIX_WARNING
))
4075 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4077 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4079 peer
->pmax
[afi
][safi
] = peer
->group
->conf
->pmax
[afi
][safi
];
4080 peer
->pmax_threshold
[afi
][safi
] = peer
->group
->conf
->pmax_threshold
[afi
][safi
];
4081 peer
->pmax_restart
[afi
][safi
] = peer
->group
->conf
->pmax_restart
[afi
][safi
];
4085 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4086 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4087 peer
->pmax
[afi
][safi
] = 0;
4088 peer
->pmax_threshold
[afi
][safi
] = 0;
4089 peer
->pmax_restart
[afi
][safi
] = 0;
4091 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4094 group
= peer
->group
;
4095 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
4097 if (! peer
->af_group
[afi
][safi
])
4100 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4101 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4102 peer
->pmax
[afi
][safi
] = 0;
4103 peer
->pmax_threshold
[afi
][safi
] = 0;
4104 peer
->pmax_restart
[afi
][safi
] = 0;
4110 peer_clear (struct peer
*peer
)
4112 if (! CHECK_FLAG (peer
->flags
, PEER_FLAG_SHUTDOWN
))
4114 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_PREFIX_OVERFLOW
))
4116 UNSET_FLAG (peer
->sflags
, PEER_STATUS_PREFIX_OVERFLOW
);
4117 if (peer
->t_pmax_restart
)
4119 BGP_TIMER_OFF (peer
->t_pmax_restart
);
4120 if (BGP_DEBUG (events
, EVENTS
))
4121 zlog_debug ("%s Maximum-prefix restart timer canceled",
4124 BGP_EVENT_ADD (peer
, BGP_Start
);
4128 peer
->v_start
= BGP_INIT_START_TIMER
;
4129 if (peer
->status
== Established
)
4130 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
4131 BGP_NOTIFY_CEASE_ADMIN_RESET
);
4133 BGP_EVENT_ADD (peer
, BGP_Stop
);
4139 peer_clear_soft (struct peer
*peer
, afi_t afi
, safi_t safi
,
4140 enum bgp_clear_type stype
)
4142 if (peer
->status
!= Established
)
4145 if (! peer
->afc
[afi
][safi
])
4146 return BGP_ERR_AF_UNCONFIGURED
;
4148 if (stype
== BGP_CLEAR_SOFT_RSCLIENT
)
4150 if (! CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
))
4152 bgp_check_local_routes_rsclient (peer
, afi
, safi
);
4153 bgp_soft_reconfig_rsclient (peer
, afi
, safi
);
4156 if (stype
== BGP_CLEAR_SOFT_OUT
|| stype
== BGP_CLEAR_SOFT_BOTH
)
4157 bgp_announce_route (peer
, afi
, safi
);
4159 if (stype
== BGP_CLEAR_SOFT_IN_ORF_PREFIX
)
4161 if (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_SM_ADV
)
4162 && (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_RM_RCV
)
4163 || CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_RM_OLD_RCV
)))
4165 struct bgp_filter
*filter
= &peer
->filter
[afi
][safi
];
4168 if (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_RM_RCV
))
4169 prefix_type
= ORF_TYPE_PREFIX
;
4171 prefix_type
= ORF_TYPE_PREFIX_OLD
;
4173 if (filter
->plist
[FILTER_IN
].plist
)
4175 if (CHECK_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_ORF_PREFIX_SEND
))
4176 bgp_route_refresh_send (peer
, afi
, safi
,
4177 prefix_type
, REFRESH_DEFER
, 1);
4178 bgp_route_refresh_send (peer
, afi
, safi
, prefix_type
,
4179 REFRESH_IMMEDIATE
, 0);
4183 if (CHECK_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_ORF_PREFIX_SEND
))
4184 bgp_route_refresh_send (peer
, afi
, safi
,
4185 prefix_type
, REFRESH_IMMEDIATE
, 1);
4187 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
4193 if (stype
== BGP_CLEAR_SOFT_IN
|| stype
== BGP_CLEAR_SOFT_BOTH
4194 || stype
== BGP_CLEAR_SOFT_IN_ORF_PREFIX
)
4196 /* If neighbor has soft reconfiguration inbound flag.
4197 Use Adj-RIB-In database. */
4198 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SOFT_RECONFIG
))
4199 bgp_soft_reconfig_in (peer
, afi
, safi
);
4202 /* If neighbor has route refresh capability, send route refresh
4203 message to the peer. */
4204 if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
4205 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
4206 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
4208 return BGP_ERR_SOFT_RECONFIG_UNCONFIGURED
;
4214 /* Display peer uptime.*/
4215 /* XXX: why does this function return char * when it takes buffer? */
4217 peer_uptime (time_t uptime2
, char *buf
, size_t len
)
4222 /* Check buffer length. */
4223 if (len
< BGP_UPTIME_LEN
)
4225 /* XXX: warning: long int format, size_t arg (arg 2) */
4226 zlog_warn ("peer_uptime (): buffer shortage %ld", len
);
4227 /* XXX: should return status instead of buf... */
4228 snprintf (buf
, len
, "<error> ");
4232 /* If there is no connection has been done before print `never'. */
4235 snprintf (buf
, len
, "never ");
4239 /* Get current time. */
4240 uptime1
= time (NULL
);
4242 tm
= gmtime (&uptime1
);
4244 /* Making formatted timer strings. */
4245 #define ONE_DAY_SECOND 60*60*24
4246 #define ONE_WEEK_SECOND 60*60*24*7
4248 if (uptime1
< ONE_DAY_SECOND
)
4249 snprintf (buf
, len
, "%02d:%02d:%02d",
4250 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
4251 else if (uptime1
< ONE_WEEK_SECOND
)
4252 snprintf (buf
, len
, "%dd%02dh%02dm",
4253 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
4255 snprintf (buf
, len
, "%02dw%dd%02dh",
4256 tm
->tm_yday
/7, tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
4261 bgp_config_write_filter (struct vty
*vty
, struct peer
*peer
,
4262 afi_t afi
, safi_t safi
)
4264 struct bgp_filter
*filter
;
4265 struct bgp_filter
*gfilter
= NULL
;
4268 int out
= FILTER_OUT
;
4271 filter
= &peer
->filter
[afi
][safi
];
4272 if (peer
->af_group
[afi
][safi
])
4273 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
4275 /* distribute-list. */
4276 if (filter
->dlist
[in
].name
)
4277 if (! gfilter
|| ! gfilter
->dlist
[in
].name
4278 || strcmp (filter
->dlist
[in
].name
, gfilter
->dlist
[in
].name
) != 0)
4279 vty_out (vty
, " neighbor %s distribute-list %s in%s", addr
,
4280 filter
->dlist
[in
].name
, VTY_NEWLINE
);
4281 if (filter
->dlist
[out
].name
&& ! gfilter
)
4282 vty_out (vty
, " neighbor %s distribute-list %s out%s", addr
,
4283 filter
->dlist
[out
].name
, VTY_NEWLINE
);
4286 if (filter
->plist
[in
].name
)
4287 if (! gfilter
|| ! gfilter
->plist
[in
].name
4288 || strcmp (filter
->plist
[in
].name
, gfilter
->plist
[in
].name
) != 0)
4289 vty_out (vty
, " neighbor %s prefix-list %s in%s", addr
,
4290 filter
->plist
[in
].name
, VTY_NEWLINE
);
4291 if (filter
->plist
[out
].name
&& ! gfilter
)
4292 vty_out (vty
, " neighbor %s prefix-list %s out%s", addr
,
4293 filter
->plist
[out
].name
, VTY_NEWLINE
);
4296 if (filter
->map
[RMAP_IN
].name
)
4297 if (! gfilter
|| ! gfilter
->map
[RMAP_IN
].name
4298 || strcmp (filter
->map
[RMAP_IN
].name
, gfilter
->map
[RMAP_IN
].name
) != 0)
4299 vty_out (vty
, " neighbor %s route-map %s in%s", addr
,
4300 filter
->map
[RMAP_IN
].name
, VTY_NEWLINE
);
4301 if (filter
->map
[RMAP_OUT
].name
&& ! gfilter
)
4302 vty_out (vty
, " neighbor %s route-map %s out%s", addr
,
4303 filter
->map
[RMAP_OUT
].name
, VTY_NEWLINE
);
4304 if (filter
->map
[RMAP_IMPORT
].name
&& ! gfilter
)
4305 vty_out (vty
, " neighbor %s route-map %s import%s", addr
,
4306 filter
->map
[RMAP_IMPORT
].name
, VTY_NEWLINE
);
4307 if (filter
->map
[RMAP_EXPORT
].name
)
4308 if (! gfilter
|| ! gfilter
->map
[RMAP_EXPORT
].name
4309 || strcmp (filter
->map
[RMAP_EXPORT
].name
,
4310 gfilter
->map
[RMAP_EXPORT
].name
) != 0)
4311 vty_out (vty
, " neighbor %s route-map %s export%s", addr
,
4312 filter
->map
[RMAP_EXPORT
].name
, VTY_NEWLINE
);
4314 /* unsuppress-map */
4315 if (filter
->usmap
.name
&& ! gfilter
)
4316 vty_out (vty
, " neighbor %s unsuppress-map %s%s", addr
,
4317 filter
->usmap
.name
, VTY_NEWLINE
);
4320 if (filter
->aslist
[in
].name
)
4321 if (! gfilter
|| ! gfilter
->aslist
[in
].name
4322 || strcmp (filter
->aslist
[in
].name
, gfilter
->aslist
[in
].name
) != 0)
4323 vty_out (vty
, " neighbor %s filter-list %s in%s", addr
,
4324 filter
->aslist
[in
].name
, VTY_NEWLINE
);
4325 if (filter
->aslist
[out
].name
&& ! gfilter
)
4326 vty_out (vty
, " neighbor %s filter-list %s out%s", addr
,
4327 filter
->aslist
[out
].name
, VTY_NEWLINE
);
4330 /* BGP peer configuration display function. */
4332 bgp_config_write_peer (struct vty
*vty
, struct bgp
*bgp
,
4333 struct peer
*peer
, afi_t afi
, safi_t safi
)
4335 struct bgp_filter
*filter
;
4336 struct peer
*g_peer
= NULL
;
4337 char buf
[SU_ADDRSTRLEN
];
4340 filter
= &peer
->filter
[afi
][safi
];
4342 if (peer_group_active (peer
))
4343 g_peer
= peer
->group
->conf
;
4345 /************************************
4346 ****** Global to the neighbor ******
4347 ************************************/
4348 if (afi
== AFI_IP
&& safi
== SAFI_UNICAST
)
4351 if (! peer_group_active (peer
))
4353 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4354 vty_out (vty
, " neighbor %s peer-group%s", addr
,
4357 vty_out (vty
, " neighbor %s remote-as %d%s", addr
, peer
->as
,
4363 vty_out (vty
, " neighbor %s remote-as %d%s", addr
, peer
->as
,
4365 if (peer
->af_group
[AFI_IP
][SAFI_UNICAST
])
4366 vty_out (vty
, " neighbor %s peer-group %s%s", addr
,
4367 peer
->group
->name
, VTY_NEWLINE
);
4371 if (peer
->change_local_as
)
4372 if (! peer_group_active (peer
))
4373 vty_out (vty
, " neighbor %s local-as %d%s%s", addr
,
4374 peer
->change_local_as
,
4375 CHECK_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
) ?
4376 " no-prepend" : "", VTY_NEWLINE
);
4380 vty_out (vty
, " neighbor %s description %s%s", addr
, peer
->desc
,
4384 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_SHUTDOWN
))
4385 if (! peer_group_active (peer
) ||
4386 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_SHUTDOWN
))
4387 vty_out (vty
, " neighbor %s shutdown%s", addr
, VTY_NEWLINE
);
4390 if (peer
->port
!= BGP_PORT_DEFAULT
)
4391 vty_out (vty
, " neighbor %s port %d%s", addr
, peer
->port
,
4394 /* Local interface name. */
4396 vty_out (vty
, " neighbor %s interface %s%s", addr
, peer
->ifname
,
4400 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_PASSIVE
))
4401 if (! peer_group_active (peer
) ||
4402 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_PASSIVE
))
4403 vty_out (vty
, " neighbor %s passive%s", addr
, VTY_NEWLINE
);
4405 /* EBGP multihop. */
4406 if (peer_sort (peer
) != BGP_PEER_IBGP
&& peer
->ttl
!= 1)
4407 if (! peer_group_active (peer
) ||
4408 g_peer
->ttl
!= peer
->ttl
)
4409 vty_out (vty
, " neighbor %s ebgp-multihop %d%s", addr
, peer
->ttl
,
4412 /* disable-connected-check. */
4413 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
))
4414 if (! peer_group_active (peer
) ||
4415 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
))
4416 vty_out (vty
, " neighbor %s disable-connected-check%s", addr
, VTY_NEWLINE
);
4418 /* Update-source. */
4419 if (peer
->update_if
)
4420 if (! peer_group_active (peer
) || ! g_peer
->update_if
4421 || strcmp (g_peer
->update_if
, peer
->update_if
) != 0)
4422 vty_out (vty
, " neighbor %s update-source %s%s", addr
,
4423 peer
->update_if
, VTY_NEWLINE
);
4424 if (peer
->update_source
)
4425 if (! peer_group_active (peer
) || ! g_peer
->update_source
4426 || sockunion_cmp (g_peer
->update_source
,
4427 peer
->update_source
) != 0)
4428 vty_out (vty
, " neighbor %s update-source %s%s", addr
,
4429 sockunion2str (peer
->update_source
, buf
, SU_ADDRSTRLEN
),
4432 /* advertisement-interval */
4433 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_ROUTEADV
))
4434 vty_out (vty
, " neighbor %s advertisement-interval %d%s",
4435 addr
, peer
->v_routeadv
, VTY_NEWLINE
);
4438 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_TIMER
)
4439 && ! peer_group_active (peer
))
4440 vty_out (vty
, " neighbor %s timers %d %d%s", addr
,
4441 peer
->keepalive
, peer
->holdtime
, VTY_NEWLINE
);
4443 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_CONNECT
))
4444 vty_out (vty
, " neighbor %s timers connect %d%s", addr
,
4445 peer
->connect
, VTY_NEWLINE
);
4447 /* Default weight. */
4448 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_WEIGHT
))
4449 if (! peer_group_active (peer
) ||
4450 g_peer
->weight
!= peer
->weight
)
4451 vty_out (vty
, " neighbor %s weight %d%s", addr
, peer
->weight
,
4454 /* Dynamic capability. */
4455 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_DYNAMIC_CAPABILITY
))
4456 if (! peer_group_active (peer
) ||
4457 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_DYNAMIC_CAPABILITY
))
4458 vty_out (vty
, " neighbor %s capability dynamic%s", addr
,
4461 /* dont capability negotiation. */
4462 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_DONT_CAPABILITY
))
4463 if (! peer_group_active (peer
) ||
4464 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_DONT_CAPABILITY
))
4465 vty_out (vty
, " neighbor %s dont-capability-negotiate%s", addr
,
4468 /* override capability negotiation. */
4469 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_OVERRIDE_CAPABILITY
))
4470 if (! peer_group_active (peer
) ||
4471 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_OVERRIDE_CAPABILITY
))
4472 vty_out (vty
, " neighbor %s override-capability%s", addr
,
4475 /* strict capability negotiation. */
4476 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_STRICT_CAP_MATCH
))
4477 if (! peer_group_active (peer
) ||
4478 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_STRICT_CAP_MATCH
))
4479 vty_out (vty
, " neighbor %s strict-capability-match%s", addr
,
4482 if (! peer_group_active (peer
))
4484 if (bgp_flag_check (bgp
, BGP_FLAG_NO_DEFAULT_IPV4
))
4486 if (peer
->afc
[AFI_IP
][SAFI_UNICAST
])
4487 vty_out (vty
, " neighbor %s activate%s", addr
, VTY_NEWLINE
);
4491 if (! peer
->afc
[AFI_IP
][SAFI_UNICAST
])
4492 vty_out (vty
, " no neighbor %s activate%s", addr
, VTY_NEWLINE
);
4498 /************************************
4499 ****** Per AF to the neighbor ******
4500 ************************************/
4502 if (! (afi
== AFI_IP
&& safi
== SAFI_UNICAST
))
4504 if (peer
->af_group
[afi
][safi
])
4505 vty_out (vty
, " neighbor %s peer-group %s%s", addr
,
4506 peer
->group
->name
, VTY_NEWLINE
);
4508 vty_out (vty
, " neighbor %s activate%s", addr
, VTY_NEWLINE
);
4511 /* ORF capability. */
4512 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
)
4513 || CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_RM
))
4514 if (! peer
->af_group
[afi
][safi
])
4516 vty_out (vty
, " neighbor %s capability orf prefix-list", addr
);
4518 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
)
4519 && CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_RM
))
4520 vty_out (vty
, " both");
4521 else if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
))
4522 vty_out (vty
, " send");
4524 vty_out (vty
, " receive");
4525 vty_out (vty
, "%s", VTY_NEWLINE
);
4528 /* Route reflector client. */
4529 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REFLECTOR_CLIENT
)
4530 && ! peer
->af_group
[afi
][safi
])
4531 vty_out (vty
, " neighbor %s route-reflector-client%s", addr
,
4535 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_NEXTHOP_SELF
)
4536 && ! peer
->af_group
[afi
][safi
])
4537 vty_out (vty
, " neighbor %s next-hop-self%s", addr
, VTY_NEWLINE
);
4539 /* Remove private AS. */
4540 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS
)
4541 && ! peer
->af_group
[afi
][safi
])
4542 vty_out (vty
, " neighbor %s remove-private-AS%s",
4545 /* send-community print. */
4546 if (! peer
->af_group
[afi
][safi
])
4548 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
))
4550 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_COMMUNITY
)
4551 && peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_EXT_COMMUNITY
))
4552 vty_out (vty
, " neighbor %s send-community both%s", addr
, VTY_NEWLINE
);
4553 else if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_EXT_COMMUNITY
))
4554 vty_out (vty
, " neighbor %s send-community extended%s",
4556 else if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_COMMUNITY
))
4557 vty_out (vty
, " neighbor %s send-community%s", addr
, VTY_NEWLINE
);
4561 if (! peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_COMMUNITY
)
4562 && ! peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_EXT_COMMUNITY
))
4563 vty_out (vty
, " no neighbor %s send-community both%s",
4565 else if (! peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_EXT_COMMUNITY
))
4566 vty_out (vty
, " no neighbor %s send-community extended%s",
4568 else if (! peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_COMMUNITY
))
4569 vty_out (vty
, " no neighbor %s send-community%s",
4574 /* Default information */
4575 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_DEFAULT_ORIGINATE
)
4576 && ! peer
->af_group
[afi
][safi
])
4578 vty_out (vty
, " neighbor %s default-originate", addr
);
4579 if (peer
->default_rmap
[afi
][safi
].name
)
4580 vty_out (vty
, " route-map %s", peer
->default_rmap
[afi
][safi
].name
);
4581 vty_out (vty
, "%s", VTY_NEWLINE
);
4584 /* Soft reconfiguration inbound. */
4585 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SOFT_RECONFIG
))
4586 if (! peer
->af_group
[afi
][safi
] ||
4587 ! CHECK_FLAG (g_peer
->af_flags
[afi
][safi
], PEER_FLAG_SOFT_RECONFIG
))
4588 vty_out (vty
, " neighbor %s soft-reconfiguration inbound%s", addr
,
4591 /* maximum-prefix. */
4592 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
))
4593 if (! peer
->af_group
[afi
][safi
]
4594 || g_peer
->pmax
[afi
][safi
] != peer
->pmax
[afi
][safi
]
4595 || g_peer
->pmax_threshold
[afi
][safi
] != peer
->pmax_threshold
[afi
][safi
]
4596 || CHECK_FLAG (g_peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
)
4597 != CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
))
4599 vty_out (vty
, " neighbor %s maximum-prefix %ld", addr
, peer
->pmax
[afi
][safi
]);
4600 if (peer
->pmax_threshold
[afi
][safi
] != MAXIMUM_PREFIX_THRESHOLD_DEFAULT
)
4601 vty_out (vty
, " %d", peer
->pmax_threshold
[afi
][safi
]);
4602 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
))
4603 vty_out (vty
, " warning-only");
4604 if (peer
->pmax_restart
[afi
][safi
])
4605 vty_out (vty
, " restart %d", peer
->pmax_restart
[afi
][safi
]);
4606 vty_out (vty
, "%s", VTY_NEWLINE
);
4609 /* Route server client. */
4610 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
)
4611 && ! peer
->af_group
[afi
][safi
])
4612 vty_out (vty
, " neighbor %s route-server-client%s", addr
, VTY_NEWLINE
);
4615 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_ALLOWAS_IN
))
4616 if (! peer_group_active (peer
)
4617 || ! peer_af_flag_check (g_peer
, afi
, safi
, PEER_FLAG_ALLOWAS_IN
)
4618 || peer
->allowas_in
[afi
][safi
] != g_peer
->allowas_in
[afi
][safi
])
4620 if (peer
->allowas_in
[afi
][safi
] == 3)
4621 vty_out (vty
, " neighbor %s allowas-in%s", addr
, VTY_NEWLINE
);
4623 vty_out (vty
, " neighbor %s allowas-in %d%s", addr
,
4624 peer
->allowas_in
[afi
][safi
], VTY_NEWLINE
);
4628 bgp_config_write_filter (vty
, peer
, afi
, safi
);
4630 /* atribute-unchanged. */
4631 if ((CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_AS_PATH_UNCHANGED
)
4632 || CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_NEXTHOP_UNCHANGED
)
4633 || CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MED_UNCHANGED
))
4634 && ! peer
->af_group
[afi
][safi
])
4636 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_AS_PATH_UNCHANGED
)
4637 && CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_NEXTHOP_UNCHANGED
)
4638 && CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MED_UNCHANGED
))
4639 vty_out (vty
, " neighbor %s attribute-unchanged%s", addr
, VTY_NEWLINE
);
4641 vty_out (vty
, " neighbor %s attribute-unchanged%s%s%s%s", addr
,
4642 (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_AS_PATH_UNCHANGED
)) ?
4644 (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_NEXTHOP_UNCHANGED
)) ?
4646 (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MED_UNCHANGED
)) ?
4647 " med" : "", VTY_NEWLINE
);
4651 /* Display "address-family" configuration header. */
4653 bgp_config_write_family_header (struct vty
*vty
, afi_t afi
, safi_t safi
,
4659 if (afi
== AFI_IP
&& safi
== SAFI_UNICAST
)
4662 vty_out (vty
, "!%s address-family ", VTY_NEWLINE
);
4666 if (safi
== SAFI_MULTICAST
)
4667 vty_out (vty
, "ipv4 multicast");
4668 else if (safi
== SAFI_MPLS_VPN
)
4669 vty_out (vty
, "vpnv4 unicast");
4671 else if (afi
== AFI_IP6
)
4672 vty_out (vty
, "ipv6");
4674 vty_out (vty
, "%s", VTY_NEWLINE
);
4679 /* Address family based peer configuration display. */
4681 bgp_config_write_family (struct vty
*vty
, struct bgp
*bgp
, afi_t afi
,
4686 struct peer_group
*group
;
4687 struct listnode
*node
, *nnode
;
4689 bgp_config_write_network (vty
, bgp
, afi
, safi
, &write
);
4691 bgp_config_write_redistribute (vty
, bgp
, afi
, safi
, &write
);
4693 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
4695 if (group
->conf
->afc
[afi
][safi
])
4697 bgp_config_write_family_header (vty
, afi
, safi
, &write
);
4698 bgp_config_write_peer (vty
, bgp
, group
->conf
, afi
, safi
);
4701 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
4703 if (peer
->afc
[afi
][safi
])
4705 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
4707 bgp_config_write_family_header (vty
, afi
, safi
, &write
);
4708 bgp_config_write_peer (vty
, bgp
, peer
, afi
, safi
);
4713 vty_out (vty
, " exit-address-family%s", VTY_NEWLINE
);
4719 bgp_config_write (struct vty
*vty
)
4723 struct peer_group
*group
;
4725 struct listnode
*node
, *nnode
;
4726 struct listnode
*mnode
, *mnnode
;
4728 /* BGP Multiple instance. */
4729 if (bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE
))
4731 vty_out (vty
, "bgp multiple-instance%s", VTY_NEWLINE
);
4735 /* BGP Config type. */
4736 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
))
4738 vty_out (vty
, "bgp config-type cisco%s", VTY_NEWLINE
);
4742 /* BGP configuration. */
4743 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
4746 vty_out (vty
, "!%s", VTY_NEWLINE
);
4748 /* Router bgp ASN */
4749 vty_out (vty
, "router bgp %d", bgp
->as
);
4751 if (bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE
))
4754 vty_out (vty
, " view %s", bgp
->name
);
4756 vty_out (vty
, "%s", VTY_NEWLINE
);
4758 /* No Synchronization */
4759 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
))
4760 vty_out (vty
, " no synchronization%s", VTY_NEWLINE
);
4762 /* BGP fast-external-failover. */
4763 if (CHECK_FLAG (bgp
->flags
, BGP_FLAG_NO_FAST_EXT_FAILOVER
))
4764 vty_out (vty
, " no bgp fast-external-failover%s", VTY_NEWLINE
);
4766 /* BGP router ID. */
4767 if (CHECK_FLAG (bgp
->config
, BGP_CONFIG_ROUTER_ID
))
4768 vty_out (vty
, " bgp router-id %s%s", inet_ntoa (bgp
->router_id
),
4771 /* BGP log-neighbor-changes. */
4772 if (bgp_flag_check (bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
))
4773 vty_out (vty
, " bgp log-neighbor-changes%s", VTY_NEWLINE
);
4775 /* BGP configuration. */
4776 if (bgp_flag_check (bgp
, BGP_FLAG_ALWAYS_COMPARE_MED
))
4777 vty_out (vty
, " bgp always-compare-med%s", VTY_NEWLINE
);
4779 /* BGP default ipv4-unicast. */
4780 if (bgp_flag_check (bgp
, BGP_FLAG_NO_DEFAULT_IPV4
))
4781 vty_out (vty
, " no bgp default ipv4-unicast%s", VTY_NEWLINE
);
4783 /* BGP default local-preference. */
4784 if (bgp
->default_local_pref
!= BGP_DEFAULT_LOCAL_PREF
)
4785 vty_out (vty
, " bgp default local-preference %d%s",
4786 bgp
->default_local_pref
, VTY_NEWLINE
);
4788 /* BGP client-to-client reflection. */
4789 if (bgp_flag_check (bgp
, BGP_FLAG_NO_CLIENT_TO_CLIENT
))
4790 vty_out (vty
, " no bgp client-to-client reflection%s", VTY_NEWLINE
);
4792 /* BGP cluster ID. */
4793 if (CHECK_FLAG (bgp
->config
, BGP_CONFIG_CLUSTER_ID
))
4794 vty_out (vty
, " bgp cluster-id %s%s", inet_ntoa (bgp
->cluster_id
),
4797 /* Confederation identifier*/
4798 if (CHECK_FLAG (bgp
->config
, BGP_CONFIG_CONFEDERATION
))
4799 vty_out (vty
, " bgp confederation identifier %i%s", bgp
->confed_id
,
4802 /* Confederation peer */
4803 if (bgp
->confed_peers_cnt
> 0)
4807 vty_out (vty
, " bgp confederation peers");
4809 for (i
= 0; i
< bgp
->confed_peers_cnt
; i
++)
4810 vty_out(vty
, " %d", bgp
->confed_peers
[i
]);
4812 vty_out (vty
, "%s", VTY_NEWLINE
);
4815 /* BGP enforce-first-as. */
4816 if (bgp_flag_check (bgp
, BGP_FLAG_ENFORCE_FIRST_AS
))
4817 vty_out (vty
, " bgp enforce-first-as%s", VTY_NEWLINE
);
4819 /* BGP deterministic-med. */
4820 if (bgp_flag_check (bgp
, BGP_FLAG_DETERMINISTIC_MED
))
4821 vty_out (vty
, " bgp deterministic-med%s", VTY_NEWLINE
);
4823 /* BGP graceful-restart. */
4824 if (bgp
->stalepath_time
!= BGP_DEFAULT_STALEPATH_TIME
)
4825 vty_out (vty
, " bgp graceful-restart stalepath-time %d%s",
4826 bgp
->stalepath_time
, VTY_NEWLINE
);
4827 if (bgp_flag_check (bgp
, BGP_FLAG_GRACEFUL_RESTART
))
4828 vty_out (vty
, " bgp graceful-restart%s", VTY_NEWLINE
);
4830 /* BGP bestpath method. */
4831 if (bgp_flag_check (bgp
, BGP_FLAG_ASPATH_IGNORE
))
4832 vty_out (vty
, " bgp bestpath as-path ignore%s", VTY_NEWLINE
);
4833 if (bgp_flag_check (bgp
, BGP_FLAG_ASPATH_CONFED
))
4834 vty_out (vty
, " bgp bestpath as-path confed%s", VTY_NEWLINE
);
4835 if (bgp_flag_check (bgp
, BGP_FLAG_COMPARE_ROUTER_ID
))
4836 vty_out (vty
, " bgp bestpath compare-routerid%s", VTY_NEWLINE
);
4837 if (bgp_flag_check (bgp
, BGP_FLAG_MED_CONFED
)
4838 || bgp_flag_check (bgp
, BGP_FLAG_MED_MISSING_AS_WORST
))
4840 vty_out (vty
, " bgp bestpath med");
4841 if (bgp_flag_check (bgp
, BGP_FLAG_MED_CONFED
))
4842 vty_out (vty
, " confed");
4843 if (bgp_flag_check (bgp
, BGP_FLAG_MED_MISSING_AS_WORST
))
4844 vty_out (vty
, " missing-as-worst");
4845 vty_out (vty
, "%s", VTY_NEWLINE
);
4848 /* BGP network import check. */
4849 if (bgp_flag_check (bgp
, BGP_FLAG_IMPORT_CHECK
))
4850 vty_out (vty
, " bgp network import-check%s", VTY_NEWLINE
);
4852 /* BGP scan interval. */
4853 bgp_config_write_scan_time (vty
);
4855 /* BGP flag dampening. */
4856 if (CHECK_FLAG (bgp
->af_flags
[AFI_IP
][SAFI_UNICAST
],
4857 BGP_CONFIG_DAMPENING
))
4858 bgp_config_write_damp (vty
);
4860 /* BGP static route configuration. */
4861 bgp_config_write_network (vty
, bgp
, AFI_IP
, SAFI_UNICAST
, &write
);
4863 /* BGP redistribute configuration. */
4864 bgp_config_write_redistribute (vty
, bgp
, AFI_IP
, SAFI_UNICAST
, &write
);
4866 /* BGP timers configuration. */
4867 if (bgp
->default_keepalive
!= BGP_DEFAULT_KEEPALIVE
4868 && bgp
->default_holdtime
!= BGP_DEFAULT_HOLDTIME
)
4869 vty_out (vty
, " timers bgp %d %d%s", bgp
->default_keepalive
,
4870 bgp
->default_holdtime
, VTY_NEWLINE
);
4873 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
4875 bgp_config_write_peer (vty
, bgp
, group
->conf
, AFI_IP
, SAFI_UNICAST
);
4878 /* Normal neighbor configuration. */
4879 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
4881 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
4882 bgp_config_write_peer (vty
, bgp
, peer
, AFI_IP
, SAFI_UNICAST
);
4885 /* Distance configuration. */
4886 bgp_config_write_distance (vty
, bgp
);
4888 /* No auto-summary */
4889 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
))
4890 vty_out (vty
, " no auto-summary%s", VTY_NEWLINE
);
4892 /* IPv4 multicast configuration. */
4893 write
+= bgp_config_write_family (vty
, bgp
, AFI_IP
, SAFI_MULTICAST
);
4895 /* IPv4 VPN configuration. */
4896 write
+= bgp_config_write_family (vty
, bgp
, AFI_IP
, SAFI_MPLS_VPN
);
4898 /* IPv6 unicast configuration. */
4899 write
+= bgp_config_write_family (vty
, bgp
, AFI_IP6
, SAFI_UNICAST
);
4907 bgp_master_init (void)
4909 memset (&bgp_master
, 0, sizeof (struct bgp_master
));
4912 bm
->bgp
= list_new ();
4913 bm
->port
= BGP_PORT_DEFAULT
;
4914 bm
->master
= thread_master_create ();
4915 bm
->start_time
= time (NULL
);
4922 /* BGP VTY commands installation. */
4925 /* Create BGP server socket. */
4926 bgp_socket (NULL
, bm
->port
);
4936 bgp_route_map_init ();
4938 bgp_mplsvpn_init ();
4940 /* Access list initialize. */
4941 access_list_init ();
4942 access_list_add_hook (peer_distribute_update
);
4943 access_list_delete_hook (peer_distribute_update
);
4945 /* Filter list initialize. */
4947 as_list_add_hook (peer_aslist_update
);
4948 as_list_delete_hook (peer_aslist_update
);
4950 /* Prefix list initialize.*/
4951 prefix_list_init ();
4952 prefix_list_add_hook (peer_prefix_list_update
);
4953 prefix_list_delete_hook (peer_prefix_list_update
);
4955 /* Community list initialize. */
4956 bgp_clist
= community_list_init ();
4960 #endif /* HAVE_SNMP */
4968 struct listnode
*node
, *nnode
;
4969 struct listnode
*mnode
, *mnnode
;
4971 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
4972 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
4973 if (peer
->status
== Established
)
4974 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
4975 BGP_NOTIFY_CEASE_PEER_UNCONFIG
);
4977 bgp_cleanup_routes ();
4978 if (bm
->process_main_queue
)
4979 work_queue_free (bm
->process_main_queue
);
4980 if (bm
->process_rsclient_queue
)
4981 work_queue_free (bm
->process_rsclient_queue
);