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
)
690 assert (peer
->status
== Deleted
);
692 bgp_unlock(peer
->bgp
);
694 /* this /ought/ to have been done already through bgp_stop earlier,
695 * but just to be sure..
697 bgp_timer_set (peer
);
698 BGP_READ_OFF (peer
->t_read
);
699 BGP_WRITE_OFF (peer
->t_write
);
700 BGP_EVENT_FLUSH (peer
);
703 XFREE (MTYPE_PEER_DESC
, peer
->desc
);
705 /* Free allocated host character. */
707 XFREE (MTYPE_BGP_PEER_HOST
, peer
->host
);
709 /* Update source configuration. */
710 if (peer
->update_source
)
711 sockunion_free (peer
->update_source
);
714 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
716 if (peer
->clear_node_queue
)
717 work_queue_free (peer
->clear_node_queue
);
719 bgp_sync_delete (peer
);
720 memset (peer
, 0, sizeof (struct peer
));
722 XFREE (MTYPE_BGP_PEER
, peer
);
725 /* increase reference count on a struct peer */
727 peer_lock (struct peer
*peer
)
729 assert (peer
&& (peer
->lock
>= 0));
736 /* decrease reference count on a struct peer
737 * struct peer is freed and NULL returned if last reference
740 peer_unlock (struct peer
*peer
)
742 assert (peer
&& (peer
->lock
> 0));
749 zlog_debug ("unlocked and freeing");
750 zlog_backtrace (LOG_DEBUG
);
759 zlog_debug ("unlocked to 1");
760 zlog_backtrace (LOG_DEBUG
);
767 /* Allocate new peer object, implicitely locked. */
769 peer_new (struct bgp
*bgp
)
776 /* bgp argument is absolutely required */
781 /* Allocate new peer. */
782 peer
= XCALLOC (MTYPE_BGP_PEER
, sizeof (struct peer
));
784 /* Set default value. */
786 peer
->v_start
= BGP_INIT_START_TIMER
;
787 peer
->v_connect
= BGP_DEFAULT_CONNECT_RETRY
;
788 peer
->v_asorig
= BGP_DEFAULT_ASORIGINATE
;
790 peer
->ostatus
= Idle
;
792 peer
->password
= NULL
;
794 peer
= peer_lock (peer
); /* initial reference */
797 /* Set default flags. */
798 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
799 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
801 if (! bgp_option_check (BGP_OPT_CONFIG_CISCO
))
803 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SEND_COMMUNITY
);
804 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SEND_EXT_COMMUNITY
);
806 peer
->orf_plist
[afi
][safi
] = NULL
;
808 SET_FLAG (peer
->sflags
, PEER_STATUS_CAPABILITY_OPEN
);
810 /* Create buffers. */
811 peer
->ibuf
= stream_new (BGP_MAX_PACKET_SIZE
);
812 peer
->obuf
= stream_fifo_new ();
813 peer
->work
= stream_new (BGP_MAX_PACKET_SIZE
);
815 bgp_sync_init (peer
);
817 /* Get service port number. */
818 sp
= getservbyname ("bgp", "tcp");
819 peer
->port
= (sp
== NULL
) ? BGP_PORT_DEFAULT
: ntohs (sp
->s_port
);
824 /* Create new BGP peer. */
826 peer_create (union sockunion
*su
, struct bgp
*bgp
, as_t local_as
,
827 as_t remote_as
, afi_t afi
, safi_t safi
)
831 char buf
[SU_ADDRSTRLEN
];
833 peer
= peer_new (bgp
);
835 peer
->local_as
= local_as
;
836 peer
->as
= remote_as
;
837 peer
->local_id
= bgp
->router_id
;
838 peer
->v_holdtime
= bgp
->default_holdtime
;
839 peer
->v_keepalive
= bgp
->default_keepalive
;
840 if (peer_sort (peer
) == BGP_PEER_IBGP
)
841 peer
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
843 peer
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
845 peer
= peer_lock (peer
); /* bgp peer list reference */
846 listnode_add_sort (bgp
->peer
, peer
);
848 active
= peer_active (peer
);
851 peer
->afc
[afi
][safi
] = 1;
853 /* Last read time set */
854 peer
->readtime
= time (NULL
);
856 /* Last reset time set */
857 peer
->resettime
= time (NULL
);
859 /* Default TTL set. */
860 peer
->ttl
= (peer_sort (peer
) == BGP_PEER_IBGP
? 255 : 1);
862 /* Make peer's address string. */
863 sockunion2str (su
, buf
, SU_ADDRSTRLEN
);
864 peer
->host
= XSTRDUP (MTYPE_BGP_PEER_HOST
, buf
);
866 /* Set up peer's events and timers. */
867 if (! active
&& peer_active (peer
))
868 bgp_timer_set (peer
);
873 /* Make accept BGP peer. Called from bgp_accept (). */
875 peer_create_accept (struct bgp
*bgp
)
879 peer
= peer_new (bgp
);
881 peer
= peer_lock (peer
); /* bgp peer list reference */
882 listnode_add_sort (bgp
->peer
, peer
);
887 /* Change peer's AS number. */
889 peer_as_change (struct peer
*peer
, as_t as
)
894 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
896 if (peer
->status
== Established
)
898 peer
->last_reset
= PEER_DOWN_REMOTE_AS_CHANGE
;
899 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
900 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
903 BGP_EVENT_ADD (peer
, BGP_Stop
);
905 type
= peer_sort (peer
);
908 if (bgp_config_check (peer
->bgp
, BGP_CONFIG_CONFEDERATION
)
909 && ! bgp_confederation_peers_check (peer
->bgp
, as
)
910 && peer
->bgp
->as
!= as
)
911 peer
->local_as
= peer
->bgp
->confed_id
;
913 peer
->local_as
= peer
->bgp
->as
;
915 /* Advertisement-interval reset */
916 if (peer_sort (peer
) == BGP_PEER_IBGP
)
917 peer
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
919 peer
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
922 if (peer_sort (peer
) == BGP_PEER_IBGP
)
924 else if (type
== BGP_PEER_IBGP
)
927 /* reflector-client reset */
928 if (peer_sort (peer
) != BGP_PEER_IBGP
)
930 UNSET_FLAG (peer
->af_flags
[AFI_IP
][SAFI_UNICAST
],
931 PEER_FLAG_REFLECTOR_CLIENT
);
932 UNSET_FLAG (peer
->af_flags
[AFI_IP
][SAFI_MULTICAST
],
933 PEER_FLAG_REFLECTOR_CLIENT
);
934 UNSET_FLAG (peer
->af_flags
[AFI_IP
][SAFI_MPLS_VPN
],
935 PEER_FLAG_REFLECTOR_CLIENT
);
936 UNSET_FLAG (peer
->af_flags
[AFI_IP6
][SAFI_UNICAST
],
937 PEER_FLAG_REFLECTOR_CLIENT
);
938 UNSET_FLAG (peer
->af_flags
[AFI_IP6
][SAFI_MULTICAST
],
939 PEER_FLAG_REFLECTOR_CLIENT
);
943 if (peer_sort (peer
) != BGP_PEER_EBGP
)
945 peer
->change_local_as
= 0;
946 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
950 /* If peer does not exist, create new one. If peer already exists,
951 set AS number to the peer. */
953 peer_remote_as (struct bgp
*bgp
, union sockunion
*su
, as_t
*as
,
954 afi_t afi
, safi_t safi
)
959 peer
= peer_lookup (bgp
, su
);
963 /* When this peer is a member of peer-group. */
966 if (peer
->group
->conf
->as
)
968 /* Return peer group's AS number. */
969 *as
= peer
->group
->conf
->as
;
970 return BGP_ERR_PEER_GROUP_MEMBER
;
972 if (peer_sort (peer
->group
->conf
) == BGP_PEER_IBGP
)
977 return BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT
;
985 return BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT
;
990 /* Existing peer's AS number change. */
992 peer_as_change (peer
, *as
);
997 /* If the peer is not part of our confederation, and its not an
998 iBGP peer then spoof the source AS */
999 if (bgp_config_check (bgp
, BGP_CONFIG_CONFEDERATION
)
1000 && ! bgp_confederation_peers_check (bgp
, *as
)
1002 local_as
= bgp
->confed_id
;
1006 /* If this is IPv4 unicast configuration and "no bgp default
1007 ipv4-unicast" is specified. */
1009 if (bgp_flag_check (bgp
, BGP_FLAG_NO_DEFAULT_IPV4
)
1010 && afi
== AFI_IP
&& safi
== SAFI_UNICAST
)
1011 peer
= peer_create (su
, bgp
, local_as
, *as
, 0, 0);
1013 peer
= peer_create (su
, bgp
, local_as
, *as
, afi
, safi
);
1019 /* Activate the peer or peer group for specified AFI and SAFI. */
1021 peer_activate (struct peer
*peer
, afi_t afi
, safi_t safi
)
1025 if (peer
->afc
[afi
][safi
])
1028 /* Activate the address family configuration. */
1029 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
1030 peer
->afc
[afi
][safi
] = 1;
1033 active
= peer_active (peer
);
1035 peer
->afc
[afi
][safi
] = 1;
1037 if (! active
&& peer_active (peer
))
1038 bgp_timer_set (peer
);
1041 if (peer
->status
== Established
)
1043 if (CHECK_FLAG (peer
->cap
, PEER_CAP_DYNAMIC_RCV
))
1045 peer
->afc_adv
[afi
][safi
] = 1;
1046 bgp_capability_send (peer
, afi
, safi
,
1048 CAPABILITY_ACTION_SET
);
1049 if (peer
->afc_recv
[afi
][safi
])
1051 peer
->afc_nego
[afi
][safi
] = 1;
1052 bgp_announce_route (peer
, afi
, safi
);
1057 peer
->last_reset
= PEER_DOWN_AF_ACTIVATE
;
1058 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1059 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1068 peer_deactivate (struct peer
*peer
, afi_t afi
, safi_t safi
)
1070 struct peer_group
*group
;
1072 struct listnode
*node
, *nnode
;
1074 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
1076 group
= peer
->group
;
1078 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer1
))
1080 if (peer1
->af_group
[afi
][safi
])
1081 return BGP_ERR_PEER_GROUP_MEMBER_EXISTS
;
1086 if (peer
->af_group
[afi
][safi
])
1087 return BGP_ERR_PEER_BELONGS_TO_GROUP
;
1090 if (! peer
->afc
[afi
][safi
])
1093 /* De-activate the address family configuration. */
1094 peer
->afc
[afi
][safi
] = 0;
1095 peer_af_flag_reset (peer
, afi
, safi
);
1097 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
1099 if (peer
->status
== Established
)
1101 if (CHECK_FLAG (peer
->cap
, PEER_CAP_DYNAMIC_RCV
))
1103 peer
->afc_adv
[afi
][safi
] = 0;
1104 peer
->afc_nego
[afi
][safi
] = 0;
1106 if (peer_active_nego (peer
))
1108 bgp_capability_send (peer
, afi
, safi
,
1110 CAPABILITY_ACTION_UNSET
);
1111 bgp_clear_route (peer
, afi
, safi
, BGP_CLEAR_ROUTE_NORMAL
);
1112 peer
->pcount
[afi
][safi
] = 0;
1116 peer
->last_reset
= PEER_DOWN_NEIGHBOR_DELETE
;
1117 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1118 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1123 peer
->last_reset
= PEER_DOWN_NEIGHBOR_DELETE
;
1124 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1125 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1133 peer_nsf_stop (struct peer
*peer
)
1138 UNSET_FLAG (peer
->sflags
, PEER_STATUS_NSF_WAIT
);
1139 UNSET_FLAG (peer
->sflags
, PEER_STATUS_NSF_MODE
);
1141 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1142 for (safi
= SAFI_UNICAST
; safi
< SAFI_UNICAST_MULTICAST
; safi
++)
1143 peer
->nsf
[afi
][safi
] = 0;
1145 if (peer
->t_gr_restart
)
1147 BGP_TIMER_OFF (peer
->t_gr_restart
);
1148 if (BGP_DEBUG (events
, EVENTS
))
1149 zlog_debug ("%s graceful restart timer stopped", peer
->host
);
1151 if (peer
->t_gr_stale
)
1153 BGP_TIMER_OFF (peer
->t_gr_stale
);
1154 if (BGP_DEBUG (events
, EVENTS
))
1155 zlog_debug ("%s graceful restart stalepath timer stopped", peer
->host
);
1157 bgp_clear_route_all (peer
);
1160 /* Delete peer from confguration.
1162 * The peer is moved to a dead-end "Deleted" neighbour-state, to allow
1163 * it to "cool off" and refcounts to hit 0, at which state it is freed.
1165 * This function /should/ take care to be idempotent, to guard against
1166 * it being called multiple times through stray events that come in
1167 * that happen to result in this function being called again. That
1168 * said, getting here for a "Deleted" peer is a bug in the neighbour
1172 peer_delete (struct peer
*peer
)
1178 struct bgp_filter
*filter
;
1179 struct listnode
*pn
;
1181 assert (peer
->status
!= Deleted
);
1185 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_NSF_WAIT
))
1186 peer_nsf_stop (peer
);
1188 /* If this peer belongs to peer group, clear up the
1192 if ((pn
= listnode_lookup (peer
->group
->peer
, peer
)))
1194 peer
= peer_unlock (peer
); /* group->peer list reference */
1195 list_delete_node (peer
->group
->peer
, pn
);
1200 /* Withdraw all information from routing table. We can not use
1201 * BGP_EVENT_ADD (peer, BGP_Stop) at here. Because the event is
1202 * executed after peer structure is deleted.
1204 peer
->last_reset
= PEER_DOWN_NEIGHBOR_DELETE
;
1206 bgp_fsm_change_status (peer
, Deleted
);
1208 /* Password configuration */
1211 XFREE (MTYPE_PEER_PASSWORD
, peer
->password
);
1212 peer
->password
= NULL
;
1214 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
1218 bgp_timer_set (peer
); /* stops all timers for Deleted */
1220 /* Delete from all peer list. */
1221 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
)
1222 && (pn
= listnode_lookup (bgp
->peer
, peer
)))
1224 peer_unlock (peer
); /* bgp peer list reference */
1225 list_delete_node (bgp
->peer
, pn
);
1228 if (peer_rsclient_active (peer
)
1229 && (pn
= listnode_lookup (bgp
->rsclient
, peer
)))
1231 peer_unlock (peer
); /* rsclient list reference */
1232 list_delete_node (bgp
->rsclient
, pn
);
1234 /* Clear our own rsclient ribs. */
1235 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1236 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
1237 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
1238 PEER_FLAG_RSERVER_CLIENT
))
1239 bgp_clear_route (peer
, afi
, safi
, BGP_CLEAR_ROUTE_MY_RSCLIENT
);
1242 /* Free RIB for any family in which peer is RSERVER_CLIENT, and is not
1243 member of a peer_group. */
1244 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1245 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
1246 if (peer
->rib
[afi
][safi
] && ! peer
->af_group
[afi
][safi
])
1247 bgp_table_finish (&peer
->rib
[afi
][safi
]);
1251 stream_free (peer
->ibuf
);
1253 stream_fifo_free (peer
->obuf
);
1255 stream_free (peer
->work
);
1257 peer
->work
= peer
->ibuf
= NULL
;
1259 /* Local and remote addresses. */
1261 sockunion_free (peer
->su_local
);
1262 if (peer
->su_remote
)
1263 sockunion_free (peer
->su_remote
);
1264 peer
->su_local
= peer
->su_remote
= NULL
;
1266 /* Free filter related memory. */
1267 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1268 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
1270 filter
= &peer
->filter
[afi
][safi
];
1272 for (i
= FILTER_IN
; i
< FILTER_MAX
; i
++)
1274 if (filter
->dlist
[i
].name
)
1275 free (filter
->dlist
[i
].name
);
1276 if (filter
->plist
[i
].name
)
1277 free (filter
->plist
[i
].name
);
1278 if (filter
->aslist
[i
].name
)
1279 free (filter
->aslist
[i
].name
);
1281 filter
->dlist
[i
].name
= NULL
;
1282 filter
->plist
[i
].name
= NULL
;
1283 filter
->aslist
[i
].name
= NULL
;
1285 for (i
= RMAP_IN
; i
< RMAP_MAX
; i
++)
1287 if (filter
->map
[i
].name
)
1288 free (filter
->map
[i
].name
);
1289 filter
->map
[i
].name
= NULL
;
1292 if (filter
->usmap
.name
)
1293 free (filter
->usmap
.name
);
1295 if (peer
->default_rmap
[afi
][safi
].name
)
1296 free (peer
->default_rmap
[afi
][safi
].name
);
1298 filter
->usmap
.name
= NULL
;
1299 peer
->default_rmap
[afi
][safi
].name
= NULL
;
1302 peer_unlock (peer
); /* initial reference */
1308 peer_group_cmp (struct peer_group
*g1
, struct peer_group
*g2
)
1310 return strcmp (g1
->name
, g2
->name
);
1313 /* If peer is configured at least one address family return 1. */
1315 peer_group_active (struct peer
*peer
)
1317 if (peer
->af_group
[AFI_IP
][SAFI_UNICAST
]
1318 || peer
->af_group
[AFI_IP
][SAFI_MULTICAST
]
1319 || peer
->af_group
[AFI_IP
][SAFI_MPLS_VPN
]
1320 || peer
->af_group
[AFI_IP6
][SAFI_UNICAST
]
1321 || peer
->af_group
[AFI_IP6
][SAFI_MULTICAST
])
1326 /* Peer group cofiguration. */
1327 static struct peer_group
*
1328 peer_group_new (void)
1330 return (struct peer_group
*) XCALLOC (MTYPE_PEER_GROUP
,
1331 sizeof (struct peer_group
));
1335 peer_group_free (struct peer_group
*group
)
1337 XFREE (MTYPE_PEER_GROUP
, group
);
1341 peer_group_lookup (struct bgp
*bgp
, const char *name
)
1343 struct peer_group
*group
;
1344 struct listnode
*node
, *nnode
;
1346 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
1348 if (strcmp (group
->name
, name
) == 0)
1355 peer_group_get (struct bgp
*bgp
, const char *name
)
1357 struct peer_group
*group
;
1359 group
= peer_group_lookup (bgp
, name
);
1363 group
= peer_group_new ();
1365 group
->name
= strdup (name
);
1366 group
->peer
= list_new ();
1367 group
->conf
= peer_new (bgp
);
1368 if (! bgp_flag_check (bgp
, BGP_FLAG_NO_DEFAULT_IPV4
))
1369 group
->conf
->afc
[AFI_IP
][SAFI_UNICAST
] = 1;
1370 group
->conf
->host
= XSTRDUP (MTYPE_BGP_PEER_HOST
, name
);
1371 group
->conf
->group
= group
;
1372 group
->conf
->as
= 0;
1373 group
->conf
->ttl
= 1;
1374 group
->conf
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
1375 UNSET_FLAG (group
->conf
->config
, PEER_CONFIG_TIMER
);
1376 UNSET_FLAG (group
->conf
->config
, PEER_CONFIG_CONNECT
);
1377 group
->conf
->keepalive
= 0;
1378 group
->conf
->holdtime
= 0;
1379 group
->conf
->connect
= 0;
1380 SET_FLAG (group
->conf
->sflags
, PEER_STATUS_GROUP
);
1381 listnode_add_sort (bgp
->group
, group
);
1387 peer_group2peer_config_copy (struct peer_group
*group
, struct peer
*peer
,
1388 afi_t afi
, safi_t safi
)
1391 int out
= FILTER_OUT
;
1393 struct bgp_filter
*pfilter
;
1394 struct bgp_filter
*gfilter
;
1397 pfilter
= &peer
->filter
[afi
][safi
];
1398 gfilter
= &conf
->filter
[afi
][safi
];
1402 peer
->as
= conf
->as
;
1405 if (conf
->change_local_as
)
1406 peer
->change_local_as
= conf
->change_local_as
;
1409 peer
->ttl
= conf
->ttl
;
1412 peer
->weight
= conf
->weight
;
1414 /* peer flags apply */
1415 peer
->flags
= conf
->flags
;
1416 /* peer af_flags apply */
1417 peer
->af_flags
[afi
][safi
] = conf
->af_flags
[afi
][safi
];
1418 /* peer config apply */
1419 peer
->config
= conf
->config
;
1421 /* peer timers apply */
1422 peer
->holdtime
= conf
->holdtime
;
1423 peer
->keepalive
= conf
->keepalive
;
1424 peer
->connect
= conf
->connect
;
1425 if (CHECK_FLAG (conf
->config
, PEER_CONFIG_CONNECT
))
1426 peer
->v_connect
= conf
->connect
;
1428 peer
->v_connect
= BGP_DEFAULT_CONNECT_RETRY
;
1430 /* advertisement-interval reset */
1431 if (peer_sort (peer
) == BGP_PEER_IBGP
)
1432 peer
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
1434 peer
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
1436 /* password apply */
1438 XFREE (MTYPE_PEER_PASSWORD
, peer
->password
);
1441 peer
->password
= XSTRDUP (MTYPE_PEER_PASSWORD
, conf
->password
);
1443 peer
->password
= NULL
;
1447 /* maximum-prefix */
1448 peer
->pmax
[afi
][safi
] = conf
->pmax
[afi
][safi
];
1449 peer
->pmax_threshold
[afi
][safi
] = conf
->pmax_threshold
[afi
][safi
];
1450 peer
->pmax_restart
[afi
][safi
] = conf
->pmax_restart
[afi
][safi
];
1453 peer
->allowas_in
[afi
][safi
] = conf
->allowas_in
[afi
][safi
];
1455 /* route-server-client */
1456 if (CHECK_FLAG(conf
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
))
1458 /* Make peer's RIB point to group's RIB. */
1459 peer
->rib
[afi
][safi
] = group
->conf
->rib
[afi
][safi
];
1461 /* Import policy. */
1462 if (pfilter
->map
[RMAP_IMPORT
].name
)
1463 free (pfilter
->map
[RMAP_IMPORT
].name
);
1464 if (gfilter
->map
[RMAP_IMPORT
].name
)
1466 pfilter
->map
[RMAP_IMPORT
].name
= strdup (gfilter
->map
[RMAP_IMPORT
].name
);
1467 pfilter
->map
[RMAP_IMPORT
].map
= gfilter
->map
[RMAP_IMPORT
].map
;
1471 pfilter
->map
[RMAP_IMPORT
].name
= NULL
;
1472 pfilter
->map
[RMAP_IMPORT
].map
= NULL
;
1475 /* Export policy. */
1476 if (gfilter
->map
[RMAP_EXPORT
].name
&& ! pfilter
->map
[RMAP_EXPORT
].name
)
1478 pfilter
->map
[RMAP_EXPORT
].name
= strdup (gfilter
->map
[RMAP_EXPORT
].name
);
1479 pfilter
->map
[RMAP_EXPORT
].map
= gfilter
->map
[RMAP_EXPORT
].map
;
1483 /* default-originate route-map */
1484 if (conf
->default_rmap
[afi
][safi
].name
)
1486 if (peer
->default_rmap
[afi
][safi
].name
)
1487 free (peer
->default_rmap
[afi
][safi
].name
);
1488 peer
->default_rmap
[afi
][safi
].name
= strdup (conf
->default_rmap
[afi
][safi
].name
);
1489 peer
->default_rmap
[afi
][safi
].map
= conf
->default_rmap
[afi
][safi
].map
;
1492 /* update-source apply */
1493 if (conf
->update_source
)
1495 if (peer
->update_source
)
1496 sockunion_free (peer
->update_source
);
1497 if (peer
->update_if
)
1499 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
1500 peer
->update_if
= NULL
;
1502 peer
->update_source
= sockunion_dup (conf
->update_source
);
1504 else if (conf
->update_if
)
1506 if (peer
->update_if
)
1507 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
1508 if (peer
->update_source
)
1510 sockunion_free (peer
->update_source
);
1511 peer
->update_source
= NULL
;
1513 peer
->update_if
= XSTRDUP (MTYPE_PEER_UPDATE_SOURCE
, conf
->update_if
);
1516 /* inbound filter apply */
1517 if (gfilter
->dlist
[in
].name
&& ! pfilter
->dlist
[in
].name
)
1519 if (pfilter
->dlist
[in
].name
)
1520 free (pfilter
->dlist
[in
].name
);
1521 pfilter
->dlist
[in
].name
= strdup (gfilter
->dlist
[in
].name
);
1522 pfilter
->dlist
[in
].alist
= gfilter
->dlist
[in
].alist
;
1524 if (gfilter
->plist
[in
].name
&& ! pfilter
->plist
[in
].name
)
1526 if (pfilter
->plist
[in
].name
)
1527 free (pfilter
->plist
[in
].name
);
1528 pfilter
->plist
[in
].name
= strdup (gfilter
->plist
[in
].name
);
1529 pfilter
->plist
[in
].plist
= gfilter
->plist
[in
].plist
;
1531 if (gfilter
->aslist
[in
].name
&& ! pfilter
->aslist
[in
].name
)
1533 if (pfilter
->aslist
[in
].name
)
1534 free (pfilter
->aslist
[in
].name
);
1535 pfilter
->aslist
[in
].name
= strdup (gfilter
->aslist
[in
].name
);
1536 pfilter
->aslist
[in
].aslist
= gfilter
->aslist
[in
].aslist
;
1538 if (gfilter
->map
[RMAP_IN
].name
&& ! pfilter
->map
[RMAP_IN
].name
)
1540 if (pfilter
->map
[RMAP_IN
].name
)
1541 free (pfilter
->map
[RMAP_IN
].name
);
1542 pfilter
->map
[RMAP_IN
].name
= strdup (gfilter
->map
[RMAP_IN
].name
);
1543 pfilter
->map
[RMAP_IN
].map
= gfilter
->map
[RMAP_IN
].map
;
1546 /* outbound filter apply */
1547 if (gfilter
->dlist
[out
].name
)
1549 if (pfilter
->dlist
[out
].name
)
1550 free (pfilter
->dlist
[out
].name
);
1551 pfilter
->dlist
[out
].name
= strdup (gfilter
->dlist
[out
].name
);
1552 pfilter
->dlist
[out
].alist
= gfilter
->dlist
[out
].alist
;
1556 if (pfilter
->dlist
[out
].name
)
1557 free (pfilter
->dlist
[out
].name
);
1558 pfilter
->dlist
[out
].name
= NULL
;
1559 pfilter
->dlist
[out
].alist
= NULL
;
1561 if (gfilter
->plist
[out
].name
)
1563 if (pfilter
->plist
[out
].name
)
1564 free (pfilter
->plist
[out
].name
);
1565 pfilter
->plist
[out
].name
= strdup (gfilter
->plist
[out
].name
);
1566 pfilter
->plist
[out
].plist
= gfilter
->plist
[out
].plist
;
1570 if (pfilter
->plist
[out
].name
)
1571 free (pfilter
->plist
[out
].name
);
1572 pfilter
->plist
[out
].name
= NULL
;
1573 pfilter
->plist
[out
].plist
= NULL
;
1575 if (gfilter
->aslist
[out
].name
)
1577 if (pfilter
->aslist
[out
].name
)
1578 free (pfilter
->aslist
[out
].name
);
1579 pfilter
->aslist
[out
].name
= strdup (gfilter
->aslist
[out
].name
);
1580 pfilter
->aslist
[out
].aslist
= gfilter
->aslist
[out
].aslist
;
1584 if (pfilter
->aslist
[out
].name
)
1585 free (pfilter
->aslist
[out
].name
);
1586 pfilter
->aslist
[out
].name
= NULL
;
1587 pfilter
->aslist
[out
].aslist
= NULL
;
1589 if (gfilter
->map
[RMAP_OUT
].name
)
1591 if (pfilter
->map
[RMAP_OUT
].name
)
1592 free (pfilter
->map
[RMAP_OUT
].name
);
1593 pfilter
->map
[RMAP_OUT
].name
= strdup (gfilter
->map
[RMAP_OUT
].name
);
1594 pfilter
->map
[RMAP_OUT
].map
= gfilter
->map
[RMAP_OUT
].map
;
1598 if (pfilter
->map
[RMAP_OUT
].name
)
1599 free (pfilter
->map
[RMAP_OUT
].name
);
1600 pfilter
->map
[RMAP_OUT
].name
= NULL
;
1601 pfilter
->map
[RMAP_OUT
].map
= NULL
;
1604 /* RS-client's import/export route-maps. */
1605 if (gfilter
->map
[RMAP_IMPORT
].name
)
1607 if (pfilter
->map
[RMAP_IMPORT
].name
)
1608 free (pfilter
->map
[RMAP_IMPORT
].name
);
1609 pfilter
->map
[RMAP_IMPORT
].name
= strdup (gfilter
->map
[RMAP_IMPORT
].name
);
1610 pfilter
->map
[RMAP_IMPORT
].map
= gfilter
->map
[RMAP_IMPORT
].map
;
1614 if (pfilter
->map
[RMAP_IMPORT
].name
)
1615 free (pfilter
->map
[RMAP_IMPORT
].name
);
1616 pfilter
->map
[RMAP_IMPORT
].name
= NULL
;
1617 pfilter
->map
[RMAP_IMPORT
].map
= NULL
;
1619 if (gfilter
->map
[RMAP_EXPORT
].name
&& ! pfilter
->map
[RMAP_EXPORT
].name
)
1621 if (pfilter
->map
[RMAP_EXPORT
].name
)
1622 free (pfilter
->map
[RMAP_EXPORT
].name
);
1623 pfilter
->map
[RMAP_EXPORT
].name
= strdup (gfilter
->map
[RMAP_EXPORT
].name
);
1624 pfilter
->map
[RMAP_EXPORT
].map
= gfilter
->map
[RMAP_EXPORT
].map
;
1627 if (gfilter
->usmap
.name
)
1629 if (pfilter
->usmap
.name
)
1630 free (pfilter
->usmap
.name
);
1631 pfilter
->usmap
.name
= strdup (gfilter
->usmap
.name
);
1632 pfilter
->usmap
.map
= gfilter
->usmap
.map
;
1636 if (pfilter
->usmap
.name
)
1637 free (pfilter
->usmap
.name
);
1638 pfilter
->usmap
.name
= NULL
;
1639 pfilter
->usmap
.map
= NULL
;
1643 /* Peer group's remote AS configuration. */
1645 peer_group_remote_as (struct bgp
*bgp
, const char *group_name
, as_t
*as
)
1647 struct peer_group
*group
;
1649 struct listnode
*node
, *nnode
;
1651 group
= peer_group_lookup (bgp
, group_name
);
1655 if (group
->conf
->as
== *as
)
1658 /* When we setup peer-group AS number all peer group member's AS
1659 number must be updated to same number. */
1660 peer_as_change (group
->conf
, *as
);
1662 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
1664 if (peer
->as
!= *as
)
1665 peer_as_change (peer
, *as
);
1672 peer_group_delete (struct peer_group
*group
)
1676 struct listnode
*node
, *nnode
;
1680 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
1685 list_delete (group
->peer
);
1690 group
->conf
->group
= NULL
;
1691 peer_delete (group
->conf
);
1693 /* Delete from all peer_group list. */
1694 listnode_delete (bgp
->group
, group
);
1696 peer_group_free (group
);
1702 peer_group_remote_as_delete (struct peer_group
*group
)
1705 struct listnode
*node
, *nnode
;
1707 if (! group
->conf
->as
)
1710 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
1715 list_delete_all_node (group
->peer
);
1717 group
->conf
->as
= 0;
1722 /* Bind specified peer to peer group. */
1724 peer_group_bind (struct bgp
*bgp
, union sockunion
*su
,
1725 struct peer_group
*group
, afi_t afi
, safi_t safi
, as_t
*as
)
1728 int first_member
= 0;
1730 /* Check peer group's address family. */
1731 if (! group
->conf
->afc
[afi
][safi
])
1732 return BGP_ERR_PEER_GROUP_AF_UNCONFIGURED
;
1734 /* Lookup the peer. */
1735 peer
= peer_lookup (bgp
, su
);
1737 /* Create a new peer. */
1740 if (! group
->conf
->as
)
1741 return BGP_ERR_PEER_GROUP_NO_REMOTE_AS
;
1743 peer
= peer_create (su
, bgp
, bgp
->as
, group
->conf
->as
, afi
, safi
);
1744 peer
->group
= group
;
1745 peer
->af_group
[afi
][safi
] = 1;
1747 peer
= peer_lock (peer
); /* group->peer list reference */
1748 listnode_add (group
->peer
, peer
);
1749 peer_group2peer_config_copy (group
, peer
, afi
, safi
);
1754 /* When the peer already belongs to peer group, check the consistency. */
1755 if (peer
->af_group
[afi
][safi
])
1757 if (strcmp (peer
->group
->name
, group
->name
) != 0)
1758 return BGP_ERR_PEER_GROUP_CANT_CHANGE
;
1763 /* Check current peer group configuration. */
1764 if (peer_group_active (peer
)
1765 && strcmp (peer
->group
->name
, group
->name
) != 0)
1766 return BGP_ERR_PEER_GROUP_MISMATCH
;
1768 if (! group
->conf
->as
)
1770 if (peer_sort (group
->conf
) != BGP_PEER_INTERNAL
1771 && peer_sort (group
->conf
) != peer_sort (peer
))
1775 return BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT
;
1778 if (peer_sort (group
->conf
) == BGP_PEER_INTERNAL
)
1782 peer
->af_group
[afi
][safi
] = 1;
1783 peer
->afc
[afi
][safi
] = 1;
1786 peer
->group
= group
;
1788 peer
= peer_lock (peer
); /* group->peer list reference */
1789 listnode_add (group
->peer
, peer
);
1792 assert (group
&& peer
->group
== group
);
1796 /* Advertisement-interval reset */
1797 if (peer_sort (group
->conf
) == BGP_PEER_IBGP
)
1798 group
->conf
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
1800 group
->conf
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
1802 /* ebgp-multihop reset */
1803 if (peer_sort (group
->conf
) == BGP_PEER_IBGP
)
1804 group
->conf
->ttl
= 255;
1806 /* local-as reset */
1807 if (peer_sort (group
->conf
) != BGP_PEER_EBGP
)
1809 group
->conf
->change_local_as
= 0;
1810 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
1814 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
))
1816 struct listnode
*pn
;
1818 /* If it's not configured as RSERVER_CLIENT in any other address
1819 family, without being member of a peer_group, remove it from
1820 list bgp->rsclient.*/
1821 if (! peer_rsclient_active (peer
)
1822 && (pn
= listnode_lookup (bgp
->rsclient
, peer
)))
1824 peer_unlock (peer
); /* peer rsclient reference */
1825 list_delete_node (bgp
->rsclient
, pn
);
1827 /* Clear our own rsclient rib for this afi/safi. */
1828 bgp_clear_route (peer
, afi
, safi
, BGP_CLEAR_ROUTE_MY_RSCLIENT
);
1831 bgp_table_finish (&peer
->rib
[afi
][safi
]);
1833 /* Import policy. */
1834 if (peer
->filter
[afi
][safi
].map
[RMAP_IMPORT
].name
)
1836 free (peer
->filter
[afi
][safi
].map
[RMAP_IMPORT
].name
);
1837 peer
->filter
[afi
][safi
].map
[RMAP_IMPORT
].name
= NULL
;
1838 peer
->filter
[afi
][safi
].map
[RMAP_IMPORT
].map
= NULL
;
1841 /* Export policy. */
1842 if (! CHECK_FLAG(group
->conf
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
)
1843 && peer
->filter
[afi
][safi
].map
[RMAP_EXPORT
].name
)
1845 free (peer
->filter
[afi
][safi
].map
[RMAP_EXPORT
].name
);
1846 peer
->filter
[afi
][safi
].map
[RMAP_EXPORT
].name
= NULL
;
1847 peer
->filter
[afi
][safi
].map
[RMAP_EXPORT
].map
= NULL
;
1851 peer_group2peer_config_copy (group
, peer
, afi
, safi
);
1853 if (peer
->status
== Established
)
1855 peer
->last_reset
= PEER_DOWN_RMAP_BIND
;
1856 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1857 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1860 BGP_EVENT_ADD (peer
, BGP_Stop
);
1866 peer_group_unbind (struct bgp
*bgp
, struct peer
*peer
,
1867 struct peer_group
*group
, afi_t afi
, safi_t safi
)
1869 if (! peer
->af_group
[afi
][safi
])
1872 if (group
!= peer
->group
)
1873 return BGP_ERR_PEER_GROUP_MISMATCH
;
1875 peer
->af_group
[afi
][safi
] = 0;
1876 peer
->afc
[afi
][safi
] = 0;
1877 peer_af_flag_reset (peer
, afi
, safi
);
1879 if (peer
->rib
[afi
][safi
])
1880 peer
->rib
[afi
][safi
] = NULL
;
1882 if (! peer_group_active (peer
))
1884 assert (listnode_lookup (group
->peer
, peer
));
1885 peer_unlock (peer
); /* peer group list reference */
1886 listnode_delete (group
->peer
, peer
);
1888 if (group
->conf
->as
)
1893 peer_global_config_reset (peer
);
1896 if (peer
->status
== Established
)
1898 peer
->last_reset
= PEER_DOWN_RMAP_UNBIND
;
1899 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
1900 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
1903 BGP_EVENT_ADD (peer
, BGP_Stop
);
1908 /* BGP instance creation by `router bgp' commands. */
1910 bgp_create (as_t
*as
, const char *name
)
1916 if ( (bgp
= XCALLOC (MTYPE_BGP
, sizeof (struct bgp
))) == NULL
)
1920 bgp
->peer_self
= peer_new (bgp
);
1921 bgp
->peer_self
->host
= XSTRDUP (MTYPE_BGP_PEER_HOST
, "Static announcement");
1923 bgp
->peer
= list_new ();
1924 bgp
->peer
->cmp
= (int (*)(void *, void *)) peer_cmp
;
1926 bgp
->group
= list_new ();
1927 bgp
->group
->cmp
= (int (*)(void *, void *)) peer_group_cmp
;
1929 bgp
->rsclient
= list_new ();
1930 bgp
->rsclient
->cmp
= (int (*)(void*, void*)) peer_cmp
;
1932 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1933 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
1935 bgp
->route
[afi
][safi
] = bgp_table_init (afi
, safi
);
1936 bgp
->aggregate
[afi
][safi
] = bgp_table_init (afi
, safi
);
1937 bgp
->rib
[afi
][safi
] = bgp_table_init (afi
, safi
);
1940 bgp
->default_local_pref
= BGP_DEFAULT_LOCAL_PREF
;
1941 bgp
->default_holdtime
= BGP_DEFAULT_HOLDTIME
;
1942 bgp
->default_keepalive
= BGP_DEFAULT_KEEPALIVE
;
1943 bgp
->restart_time
= BGP_DEFAULT_RESTART_TIME
;
1944 bgp
->stalepath_time
= BGP_DEFAULT_STALEPATH_TIME
;
1949 bgp
->name
= strdup (name
);
1954 /* Return first entry of BGP. */
1956 bgp_get_default (void)
1959 return (listgetdata (listhead (bm
->bgp
)));
1963 /* Lookup BGP entry. */
1965 bgp_lookup (as_t as
, const char *name
)
1968 struct listnode
*node
, *nnode
;
1970 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
1972 && ((bgp
->name
== NULL
&& name
== NULL
)
1973 || (bgp
->name
&& name
&& strcmp (bgp
->name
, name
) == 0)))
1978 /* Lookup BGP structure by view name. */
1980 bgp_lookup_by_name (const char *name
)
1983 struct listnode
*node
, *nnode
;
1985 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
1986 if ((bgp
->name
== NULL
&& name
== NULL
)
1987 || (bgp
->name
&& name
&& strcmp (bgp
->name
, name
) == 0))
1992 /* Called from VTY commands. */
1994 bgp_get (struct bgp
**bgp_val
, as_t
*as
, const char *name
)
1998 /* Multiple instance check. */
1999 if (bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE
))
2002 bgp
= bgp_lookup_by_name (name
);
2004 bgp
= bgp_get_default ();
2006 /* Already exists. */
2012 return BGP_ERR_INSTANCE_MISMATCH
;
2020 /* BGP instance name can not be specified for single instance. */
2022 return BGP_ERR_MULTIPLE_INSTANCE_NOT_SET
;
2024 /* Get default BGP structure if exists. */
2025 bgp
= bgp_get_default ();
2032 return BGP_ERR_AS_MISMATCH
;
2039 /* Create BGP server socket, if first instance. */
2040 if (list_isempty(bm
->bgp
))
2042 if (bgp_socket (bm
->port
, bm
->address
) < 0)
2043 return BGP_ERR_INVALID_VALUE
;
2046 bgp
= bgp_create (as
, name
);
2047 listnode_add (bm
->bgp
, bgp
);
2048 bgp_router_id_set(bgp
, &router_id_zebra
);
2054 /* Delete BGP instance. */
2056 bgp_delete (struct bgp
*bgp
)
2059 struct peer_group
*group
;
2060 struct listnode
*node
;
2061 struct listnode
*next
;
2065 /* Delete static route. */
2066 bgp_static_delete (bgp
);
2068 /* Unset redistribution. */
2069 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2070 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2071 if (i
!= ZEBRA_ROUTE_BGP
)
2072 bgp_redistribute_unset (bgp
, afi
, i
);
2074 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, next
, peer
))
2077 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, next
, group
))
2078 peer_group_delete (group
);
2080 assert (listcount (bgp
->rsclient
) == 0);
2082 if (bgp
->peer_self
) {
2083 peer_delete(bgp
->peer_self
);
2084 bgp
->peer_self
= NULL
;
2087 /* Remove visibility via the master list - there may however still be
2088 * routes to be processed still referencing the struct bgp.
2090 listnode_delete (bm
->bgp
, bgp
);
2091 if (list_isempty(bm
->bgp
))
2094 bgp_unlock(bgp
); /* initial reference */
2099 static void bgp_free (struct bgp
*);
2102 bgp_lock (struct bgp
*bgp
)
2108 bgp_unlock(struct bgp
*bgp
)
2110 assert(bgp
->lock
> 0);
2111 if (--bgp
->lock
== 0)
2116 bgp_free (struct bgp
*bgp
)
2121 list_delete (bgp
->group
);
2122 list_delete (bgp
->peer
);
2123 list_delete (bgp
->rsclient
);
2128 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2129 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2131 if (bgp
->route
[afi
][safi
])
2132 bgp_table_finish (&bgp
->route
[afi
][safi
]);
2133 if (bgp
->aggregate
[afi
][safi
])
2134 bgp_table_finish (&bgp
->aggregate
[afi
][safi
]) ;
2135 if (bgp
->rib
[afi
][safi
])
2136 bgp_table_finish (&bgp
->rib
[afi
][safi
]);
2138 XFREE (MTYPE_BGP
, bgp
);
2142 peer_lookup (struct bgp
*bgp
, union sockunion
*su
)
2145 struct listnode
*node
, *nnode
;
2149 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2150 if (sockunion_same (&peer
->su
, su
)
2151 && ! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
2154 else if (bm
->bgp
!= NULL
)
2156 struct listnode
*bgpnode
, *nbgpnode
;
2158 for (ALL_LIST_ELEMENTS (bm
->bgp
, bgpnode
, nbgpnode
, bgp
))
2159 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2160 if (sockunion_same (&peer
->su
, su
)
2161 && ! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
2168 peer_lookup_with_open (union sockunion
*su
, as_t remote_as
,
2169 struct in_addr
*remote_id
, int *as
)
2172 struct listnode
*node
;
2173 struct listnode
*bgpnode
;
2179 for (ALL_LIST_ELEMENTS_RO (bm
->bgp
, bgpnode
, bgp
))
2181 for (ALL_LIST_ELEMENTS_RO (bgp
->peer
, node
, peer
))
2183 if (sockunion_same (&peer
->su
, su
)
2184 && ! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
2186 if (peer
->as
== remote_as
2187 && peer
->remote_id
.s_addr
== remote_id
->s_addr
)
2189 if (peer
->as
== remote_as
)
2194 for (ALL_LIST_ELEMENTS_RO (bgp
->peer
, node
, peer
))
2196 if (sockunion_same (&peer
->su
, su
)
2197 && ! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
2199 if (peer
->as
== remote_as
2200 && peer
->remote_id
.s_addr
== 0)
2202 if (peer
->as
== remote_as
)
2210 /* If peer is configured at least one address family return 1. */
2212 peer_active (struct peer
*peer
)
2214 if (peer
->afc
[AFI_IP
][SAFI_UNICAST
]
2215 || peer
->afc
[AFI_IP
][SAFI_MULTICAST
]
2216 || peer
->afc
[AFI_IP
][SAFI_MPLS_VPN
]
2217 || peer
->afc
[AFI_IP6
][SAFI_UNICAST
]
2218 || peer
->afc
[AFI_IP6
][SAFI_MULTICAST
])
2223 /* If peer is negotiated at least one address family return 1. */
2225 peer_active_nego (struct peer
*peer
)
2227 if (peer
->afc_nego
[AFI_IP
][SAFI_UNICAST
]
2228 || peer
->afc_nego
[AFI_IP
][SAFI_MULTICAST
]
2229 || peer
->afc_nego
[AFI_IP
][SAFI_MPLS_VPN
]
2230 || peer
->afc_nego
[AFI_IP6
][SAFI_UNICAST
]
2231 || peer
->afc_nego
[AFI_IP6
][SAFI_MULTICAST
])
2236 /* peer_flag_change_type. */
2237 enum peer_change_type
2241 peer_change_reset_in
,
2242 peer_change_reset_out
,
2246 peer_change_action (struct peer
*peer
, afi_t afi
, safi_t safi
,
2247 enum peer_change_type type
)
2249 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2252 if (type
== peer_change_reset
)
2253 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2254 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2255 else if (type
== peer_change_reset_in
)
2257 if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2258 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
2259 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
2261 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2262 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2264 else if (type
== peer_change_reset_out
)
2265 bgp_announce_route (peer
, afi
, safi
);
2268 struct peer_flag_action
2273 /* This flag can be set for peer-group member. */
2274 u_char not_for_member
;
2276 /* Action when the flag is changed. */
2277 enum peer_change_type type
;
2279 /* Peer down cause */
2283 static const struct peer_flag_action peer_flag_action_list
[] =
2285 { PEER_FLAG_PASSIVE
, 0, peer_change_reset
},
2286 { PEER_FLAG_SHUTDOWN
, 0, peer_change_reset
},
2287 { PEER_FLAG_DONT_CAPABILITY
, 0, peer_change_none
},
2288 { PEER_FLAG_OVERRIDE_CAPABILITY
, 0, peer_change_none
},
2289 { PEER_FLAG_STRICT_CAP_MATCH
, 0, peer_change_none
},
2290 { PEER_FLAG_DYNAMIC_CAPABILITY
, 0, peer_change_reset
},
2291 { PEER_FLAG_DISABLE_CONNECTED_CHECK
, 0, peer_change_reset
},
2295 static const struct peer_flag_action peer_af_flag_action_list
[] =
2297 { PEER_FLAG_NEXTHOP_SELF
, 1, peer_change_reset_out
},
2298 { PEER_FLAG_SEND_COMMUNITY
, 1, peer_change_reset_out
},
2299 { PEER_FLAG_SEND_EXT_COMMUNITY
, 1, peer_change_reset_out
},
2300 { PEER_FLAG_SOFT_RECONFIG
, 0, peer_change_reset_in
},
2301 { PEER_FLAG_REFLECTOR_CLIENT
, 1, peer_change_reset
},
2302 { PEER_FLAG_RSERVER_CLIENT
, 1, peer_change_reset
},
2303 { PEER_FLAG_AS_PATH_UNCHANGED
, 1, peer_change_reset_out
},
2304 { PEER_FLAG_NEXTHOP_UNCHANGED
, 1, peer_change_reset_out
},
2305 { PEER_FLAG_MED_UNCHANGED
, 1, peer_change_reset_out
},
2306 { PEER_FLAG_REMOVE_PRIVATE_AS
, 1, peer_change_reset_out
},
2307 { PEER_FLAG_ALLOWAS_IN
, 0, peer_change_reset_in
},
2308 { PEER_FLAG_ORF_PREFIX_SM
, 1, peer_change_reset
},
2309 { PEER_FLAG_ORF_PREFIX_RM
, 1, peer_change_reset
},
2310 { PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED
, 0, peer_change_reset_out
},
2314 /* Proper action set. */
2316 peer_flag_action_set (const struct peer_flag_action
*action_list
, int size
,
2317 struct peer_flag_action
*action
, u_int32_t flag
)
2323 const struct peer_flag_action
*match
= NULL
;
2325 /* Check peer's frag action. */
2326 for (i
= 0; i
< size
; i
++)
2328 match
= &action_list
[i
];
2330 if (match
->flag
== 0)
2333 if (match
->flag
& flag
)
2337 if (match
->type
== peer_change_reset_in
)
2339 if (match
->type
== peer_change_reset_out
)
2341 if (match
->type
== peer_change_reset
)
2346 if (match
->not_for_member
)
2347 action
->not_for_member
= 1;
2351 /* Set peer clear type. */
2352 if (reset_in
&& reset_out
)
2353 action
->type
= peer_change_reset
;
2355 action
->type
= peer_change_reset_in
;
2357 action
->type
= peer_change_reset_out
;
2359 action
->type
= peer_change_none
;
2365 peer_flag_modify_action (struct peer
*peer
, u_int32_t flag
)
2367 if (flag
== PEER_FLAG_SHUTDOWN
)
2369 if (CHECK_FLAG (peer
->flags
, flag
))
2371 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_NSF_WAIT
))
2372 peer_nsf_stop (peer
);
2374 UNSET_FLAG (peer
->sflags
, PEER_STATUS_PREFIX_OVERFLOW
);
2375 if (peer
->t_pmax_restart
)
2377 BGP_TIMER_OFF (peer
->t_pmax_restart
);
2378 if (BGP_DEBUG (events
, EVENTS
))
2379 zlog_debug ("%s Maximum-prefix restart timer canceled",
2383 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_NSF_WAIT
))
2384 peer_nsf_stop (peer
);
2386 if (peer
->status
== Established
)
2387 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2388 BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
);
2390 BGP_EVENT_ADD (peer
, BGP_Stop
);
2394 peer
->v_start
= BGP_INIT_START_TIMER
;
2395 BGP_EVENT_ADD (peer
, BGP_Stop
);
2398 else if (peer
->status
== Established
)
2400 if (flag
== PEER_FLAG_DYNAMIC_CAPABILITY
)
2401 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2402 else if (flag
== PEER_FLAG_PASSIVE
)
2403 peer
->last_reset
= PEER_DOWN_PASSIVE_CHANGE
;
2404 else if (flag
== PEER_FLAG_DISABLE_CONNECTED_CHECK
)
2405 peer
->last_reset
= PEER_DOWN_MULTIHOP_CHANGE
;
2407 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2408 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2411 BGP_EVENT_ADD (peer
, BGP_Stop
);
2414 /* Change specified peer flag. */
2416 peer_flag_modify (struct peer
*peer
, u_int32_t flag
, int set
)
2420 struct peer_group
*group
;
2421 struct listnode
*node
, *nnode
;
2422 struct peer_flag_action action
;
2424 memset (&action
, 0, sizeof (struct peer_flag_action
));
2425 size
= sizeof peer_flag_action_list
/ sizeof (struct peer_flag_action
);
2427 found
= peer_flag_action_set (peer_flag_action_list
, size
, &action
, flag
);
2429 /* No flag action is found. */
2431 return BGP_ERR_INVALID_FLAG
;
2433 /* Not for peer-group member. */
2434 if (action
.not_for_member
&& peer_group_active (peer
))
2435 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
2437 /* When unset the peer-group member's flag we have to check
2438 peer-group configuration. */
2439 if (! set
&& peer_group_active (peer
))
2440 if (CHECK_FLAG (peer
->group
->conf
->flags
, flag
))
2442 if (flag
== PEER_FLAG_SHUTDOWN
)
2443 return BGP_ERR_PEER_GROUP_SHUTDOWN
;
2445 return BGP_ERR_PEER_GROUP_HAS_THE_FLAG
;
2448 /* Flag conflict check. */
2450 && CHECK_FLAG (peer
->flags
| flag
, PEER_FLAG_STRICT_CAP_MATCH
)
2451 && CHECK_FLAG (peer
->flags
| flag
, PEER_FLAG_OVERRIDE_CAPABILITY
))
2452 return BGP_ERR_PEER_FLAG_CONFLICT
;
2454 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2456 if (set
&& CHECK_FLAG (peer
->flags
, flag
) == flag
)
2458 if (! set
&& ! CHECK_FLAG (peer
->flags
, flag
))
2463 SET_FLAG (peer
->flags
, flag
);
2465 UNSET_FLAG (peer
->flags
, flag
);
2467 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2469 if (action
.type
== peer_change_reset
)
2470 peer_flag_modify_action (peer
, flag
);
2475 /* peer-group member updates. */
2476 group
= peer
->group
;
2478 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2480 if (set
&& CHECK_FLAG (peer
->flags
, flag
) == flag
)
2483 if (! set
&& ! CHECK_FLAG (peer
->flags
, flag
))
2487 SET_FLAG (peer
->flags
, flag
);
2489 UNSET_FLAG (peer
->flags
, flag
);
2491 if (action
.type
== peer_change_reset
)
2492 peer_flag_modify_action (peer
, flag
);
2498 peer_flag_set (struct peer
*peer
, u_int32_t flag
)
2500 return peer_flag_modify (peer
, flag
, 1);
2504 peer_flag_unset (struct peer
*peer
, u_int32_t flag
)
2506 return peer_flag_modify (peer
, flag
, 0);
2510 peer_is_group_member (struct peer
*peer
, afi_t afi
, safi_t safi
)
2512 if (peer
->af_group
[afi
][safi
])
2518 peer_af_flag_modify (struct peer
*peer
, afi_t afi
, safi_t safi
, u_int32_t flag
,
2523 struct listnode
*node
, *nnode
;
2524 struct peer_group
*group
;
2525 struct peer_flag_action action
;
2527 memset (&action
, 0, sizeof (struct peer_flag_action
));
2528 size
= sizeof peer_af_flag_action_list
/ sizeof (struct peer_flag_action
);
2530 found
= peer_flag_action_set (peer_af_flag_action_list
, size
, &action
, flag
);
2532 /* No flag action is found. */
2534 return BGP_ERR_INVALID_FLAG
;
2536 /* Adress family must be activated. */
2537 if (! peer
->afc
[afi
][safi
])
2538 return BGP_ERR_PEER_INACTIVE
;
2540 /* Not for peer-group member. */
2541 if (action
.not_for_member
&& peer_is_group_member (peer
, afi
, safi
))
2542 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
2544 /* Spcecial check for reflector client. */
2545 if (flag
& PEER_FLAG_REFLECTOR_CLIENT
2546 && peer_sort (peer
) != BGP_PEER_IBGP
)
2547 return BGP_ERR_NOT_INTERNAL_PEER
;
2549 /* Spcecial check for remove-private-AS. */
2550 if (flag
& PEER_FLAG_REMOVE_PRIVATE_AS
2551 && peer_sort (peer
) == BGP_PEER_IBGP
)
2552 return BGP_ERR_REMOVE_PRIVATE_AS
;
2554 /* When unset the peer-group member's flag we have to check
2555 peer-group configuration. */
2556 if (! set
&& peer
->af_group
[afi
][safi
])
2557 if (CHECK_FLAG (peer
->group
->conf
->af_flags
[afi
][safi
], flag
))
2558 return BGP_ERR_PEER_GROUP_HAS_THE_FLAG
;
2560 /* When current flag configuration is same as requested one. */
2561 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2563 if (set
&& CHECK_FLAG (peer
->af_flags
[afi
][safi
], flag
) == flag
)
2565 if (! set
&& ! CHECK_FLAG (peer
->af_flags
[afi
][safi
], flag
))
2570 SET_FLAG (peer
->af_flags
[afi
][safi
], flag
);
2572 UNSET_FLAG (peer
->af_flags
[afi
][safi
], flag
);
2574 /* Execute action when peer is established. */
2575 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
)
2576 && peer
->status
== Established
)
2578 if (! set
&& flag
== PEER_FLAG_SOFT_RECONFIG
)
2579 bgp_clear_adj_in (peer
, afi
, safi
);
2582 if (flag
== PEER_FLAG_REFLECTOR_CLIENT
)
2583 peer
->last_reset
= PEER_DOWN_RR_CLIENT_CHANGE
;
2584 else if (flag
== PEER_FLAG_RSERVER_CLIENT
)
2585 peer
->last_reset
= PEER_DOWN_RS_CLIENT_CHANGE
;
2586 else if (flag
== PEER_FLAG_ORF_PREFIX_SM
)
2587 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2588 else if (flag
== PEER_FLAG_ORF_PREFIX_RM
)
2589 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2591 peer_change_action (peer
, afi
, safi
, action
.type
);
2596 /* Peer group member updates. */
2597 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2599 group
= peer
->group
;
2601 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2603 if (! peer
->af_group
[afi
][safi
])
2606 if (set
&& CHECK_FLAG (peer
->af_flags
[afi
][safi
], flag
) == flag
)
2609 if (! set
&& ! CHECK_FLAG (peer
->af_flags
[afi
][safi
], flag
))
2613 SET_FLAG (peer
->af_flags
[afi
][safi
], flag
);
2615 UNSET_FLAG (peer
->af_flags
[afi
][safi
], flag
);
2617 if (peer
->status
== Established
)
2619 if (! set
&& flag
== PEER_FLAG_SOFT_RECONFIG
)
2620 bgp_clear_adj_in (peer
, afi
, safi
);
2623 if (flag
== PEER_FLAG_REFLECTOR_CLIENT
)
2624 peer
->last_reset
= PEER_DOWN_RR_CLIENT_CHANGE
;
2625 else if (flag
== PEER_FLAG_RSERVER_CLIENT
)
2626 peer
->last_reset
= PEER_DOWN_RS_CLIENT_CHANGE
;
2627 else if (flag
== PEER_FLAG_ORF_PREFIX_SM
)
2628 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2629 else if (flag
== PEER_FLAG_ORF_PREFIX_RM
)
2630 peer
->last_reset
= PEER_DOWN_CAPABILITY_CHANGE
;
2632 peer_change_action (peer
, afi
, safi
, action
.type
);
2641 peer_af_flag_set (struct peer
*peer
, afi_t afi
, safi_t safi
, u_int32_t flag
)
2643 return peer_af_flag_modify (peer
, afi
, safi
, flag
, 1);
2647 peer_af_flag_unset (struct peer
*peer
, afi_t afi
, safi_t safi
, u_int32_t flag
)
2649 return peer_af_flag_modify (peer
, afi
, safi
, flag
, 0);
2652 /* EBGP multihop configuration. */
2654 peer_ebgp_multihop_set (struct peer
*peer
, int ttl
)
2656 struct peer_group
*group
;
2657 struct listnode
*node
, *nnode
;
2659 if (peer_sort (peer
) == BGP_PEER_IBGP
)
2664 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2666 if (peer
->fd
>= 0 && peer_sort (peer
) != BGP_PEER_IBGP
)
2667 sockopt_ttl (peer
->su
.sa
.sa_family
, peer
->fd
, peer
->ttl
);
2671 group
= peer
->group
;
2672 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2674 if (peer_sort (peer
) == BGP_PEER_IBGP
)
2677 peer
->ttl
= group
->conf
->ttl
;
2680 sockopt_ttl (peer
->su
.sa
.sa_family
, peer
->fd
, peer
->ttl
);
2687 peer_ebgp_multihop_unset (struct peer
*peer
)
2689 struct peer_group
*group
;
2690 struct listnode
*node
, *nnode
;
2692 if (peer_sort (peer
) == BGP_PEER_IBGP
)
2695 if (peer_group_active (peer
))
2696 peer
->ttl
= peer
->group
->conf
->ttl
;
2700 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2702 if (peer
->fd
>= 0 && peer_sort (peer
) != BGP_PEER_IBGP
)
2703 sockopt_ttl (peer
->su
.sa
.sa_family
, peer
->fd
, peer
->ttl
);
2707 group
= peer
->group
;
2708 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2710 if (peer_sort (peer
) == BGP_PEER_IBGP
)
2716 sockopt_ttl (peer
->su
.sa
.sa_family
, peer
->fd
, peer
->ttl
);
2722 /* Neighbor description. */
2724 peer_description_set (struct peer
*peer
, char *desc
)
2727 XFREE (MTYPE_PEER_DESC
, peer
->desc
);
2729 peer
->desc
= XSTRDUP (MTYPE_PEER_DESC
, desc
);
2735 peer_description_unset (struct peer
*peer
)
2738 XFREE (MTYPE_PEER_DESC
, peer
->desc
);
2745 /* Neighbor update-source. */
2747 peer_update_source_if_set (struct peer
*peer
, const char *ifname
)
2749 struct peer_group
*group
;
2750 struct listnode
*node
, *nnode
;
2752 if (peer
->update_if
)
2754 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
)
2755 && strcmp (peer
->update_if
, ifname
) == 0)
2758 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2759 peer
->update_if
= NULL
;
2762 if (peer
->update_source
)
2764 sockunion_free (peer
->update_source
);
2765 peer
->update_source
= NULL
;
2768 peer
->update_if
= XSTRDUP (MTYPE_PEER_UPDATE_SOURCE
, ifname
);
2770 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2772 if (peer
->status
== Established
)
2774 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2775 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2776 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2779 BGP_EVENT_ADD (peer
, BGP_Stop
);
2783 /* peer-group member updates. */
2784 group
= peer
->group
;
2785 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2787 if (peer
->update_if
)
2789 if (strcmp (peer
->update_if
, ifname
) == 0)
2792 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2793 peer
->update_if
= NULL
;
2796 if (peer
->update_source
)
2798 sockunion_free (peer
->update_source
);
2799 peer
->update_source
= NULL
;
2802 peer
->update_if
= XSTRDUP (MTYPE_PEER_UPDATE_SOURCE
, ifname
);
2804 if (peer
->status
== Established
)
2806 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2807 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2808 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2811 BGP_EVENT_ADD (peer
, BGP_Stop
);
2817 peer_update_source_addr_set (struct peer
*peer
, union sockunion
*su
)
2819 struct peer_group
*group
;
2820 struct listnode
*node
, *nnode
;
2822 if (peer
->update_source
)
2824 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
)
2825 && sockunion_cmp (peer
->update_source
, su
) == 0)
2827 sockunion_free (peer
->update_source
);
2828 peer
->update_source
= NULL
;
2831 if (peer
->update_if
)
2833 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2834 peer
->update_if
= NULL
;
2837 peer
->update_source
= sockunion_dup (su
);
2839 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
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
);
2852 /* peer-group member updates. */
2853 group
= peer
->group
;
2854 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2856 if (peer
->update_source
)
2858 if (sockunion_cmp (peer
->update_source
, su
) == 0)
2860 sockunion_free (peer
->update_source
);
2861 peer
->update_source
= NULL
;
2864 if (peer
->update_if
)
2866 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2867 peer
->update_if
= NULL
;
2870 peer
->update_source
= sockunion_dup (su
);
2872 if (peer
->status
== Established
)
2874 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2875 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2876 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2879 BGP_EVENT_ADD (peer
, BGP_Stop
);
2885 peer_update_source_unset (struct peer
*peer
)
2887 union sockunion
*su
;
2888 struct peer_group
*group
;
2889 struct listnode
*node
, *nnode
;
2891 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
)
2892 && ! peer
->update_source
2893 && ! peer
->update_if
)
2896 if (peer
->update_source
)
2898 sockunion_free (peer
->update_source
);
2899 peer
->update_source
= NULL
;
2901 if (peer
->update_if
)
2903 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2904 peer
->update_if
= NULL
;
2907 if (peer_group_active (peer
))
2909 group
= peer
->group
;
2911 if (group
->conf
->update_source
)
2913 su
= sockunion_dup (group
->conf
->update_source
);
2914 peer
->update_source
= su
;
2916 else if (group
->conf
->update_if
)
2918 XSTRDUP (MTYPE_PEER_UPDATE_SOURCE
, group
->conf
->update_if
);
2921 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2923 if (peer
->status
== Established
)
2925 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2926 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2927 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2930 BGP_EVENT_ADD (peer
, BGP_Stop
);
2934 /* peer-group member updates. */
2935 group
= peer
->group
;
2936 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
2938 if (! peer
->update_source
&& ! peer
->update_if
)
2941 if (peer
->update_source
)
2943 sockunion_free (peer
->update_source
);
2944 peer
->update_source
= NULL
;
2947 if (peer
->update_if
)
2949 XFREE (MTYPE_PEER_UPDATE_SOURCE
, peer
->update_if
);
2950 peer
->update_if
= NULL
;
2953 if (peer
->status
== Established
)
2955 peer
->last_reset
= PEER_DOWN_UPDATE_SOURCE_CHANGE
;
2956 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
2957 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
2960 BGP_EVENT_ADD (peer
, BGP_Stop
);
2966 peer_default_originate_set (struct peer
*peer
, afi_t afi
, safi_t safi
,
2969 struct peer_group
*group
;
2970 struct listnode
*node
, *nnode
;
2972 /* Adress family must be activated. */
2973 if (! peer
->afc
[afi
][safi
])
2974 return BGP_ERR_PEER_INACTIVE
;
2976 /* Default originate can't be used for peer group memeber. */
2977 if (peer_is_group_member (peer
, afi
, safi
))
2978 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
2980 if (! CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
)
2981 || (rmap
&& ! peer
->default_rmap
[afi
][safi
].name
)
2982 || (rmap
&& strcmp (rmap
, peer
->default_rmap
[afi
][safi
].name
) != 0))
2984 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
);
2988 if (peer
->default_rmap
[afi
][safi
].name
)
2989 free (peer
->default_rmap
[afi
][safi
].name
);
2990 peer
->default_rmap
[afi
][safi
].name
= strdup (rmap
);
2991 peer
->default_rmap
[afi
][safi
].map
= route_map_lookup_by_name (rmap
);
2995 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
2997 if (peer
->status
== Established
&& peer
->afc_nego
[afi
][safi
])
2998 bgp_default_originate (peer
, afi
, safi
, 0);
3002 /* peer-group member updates. */
3003 group
= peer
->group
;
3004 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3006 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
);
3010 if (peer
->default_rmap
[afi
][safi
].name
)
3011 free (peer
->default_rmap
[afi
][safi
].name
);
3012 peer
->default_rmap
[afi
][safi
].name
= strdup (rmap
);
3013 peer
->default_rmap
[afi
][safi
].map
= route_map_lookup_by_name (rmap
);
3016 if (peer
->status
== Established
&& peer
->afc_nego
[afi
][safi
])
3017 bgp_default_originate (peer
, afi
, safi
, 0);
3023 peer_default_originate_unset (struct peer
*peer
, afi_t afi
, safi_t safi
)
3025 struct peer_group
*group
;
3026 struct listnode
*node
, *nnode
;
3028 /* Adress family must be activated. */
3029 if (! peer
->afc
[afi
][safi
])
3030 return BGP_ERR_PEER_INACTIVE
;
3032 /* Default originate can't be used for peer group memeber. */
3033 if (peer_is_group_member (peer
, afi
, safi
))
3034 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3036 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
))
3038 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
);
3040 if (peer
->default_rmap
[afi
][safi
].name
)
3041 free (peer
->default_rmap
[afi
][safi
].name
);
3042 peer
->default_rmap
[afi
][safi
].name
= NULL
;
3043 peer
->default_rmap
[afi
][safi
].map
= NULL
;
3046 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3048 if (peer
->status
== Established
&& peer
->afc_nego
[afi
][safi
])
3049 bgp_default_originate (peer
, afi
, safi
, 1);
3053 /* peer-group member updates. */
3054 group
= peer
->group
;
3055 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3057 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_DEFAULT_ORIGINATE
);
3059 if (peer
->default_rmap
[afi
][safi
].name
)
3060 free (peer
->default_rmap
[afi
][safi
].name
);
3061 peer
->default_rmap
[afi
][safi
].name
= NULL
;
3062 peer
->default_rmap
[afi
][safi
].map
= NULL
;
3064 if (peer
->status
== Established
&& peer
->afc_nego
[afi
][safi
])
3065 bgp_default_originate (peer
, afi
, safi
, 1);
3071 peer_port_set (struct peer
*peer
, u_int16_t port
)
3078 peer_port_unset (struct peer
*peer
)
3080 peer
->port
= BGP_PORT_DEFAULT
;
3084 /* neighbor weight. */
3086 peer_weight_set (struct peer
*peer
, u_int16_t weight
)
3088 struct peer_group
*group
;
3089 struct listnode
*node
, *nnode
;
3091 SET_FLAG (peer
->config
, PEER_CONFIG_WEIGHT
);
3092 peer
->weight
= weight
;
3094 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3097 /* peer-group member updates. */
3098 group
= peer
->group
;
3099 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3101 peer
->weight
= group
->conf
->weight
;
3107 peer_weight_unset (struct peer
*peer
)
3109 struct peer_group
*group
;
3110 struct listnode
*node
, *nnode
;
3112 /* Set default weight. */
3113 if (peer_group_active (peer
))
3114 peer
->weight
= peer
->group
->conf
->weight
;
3118 UNSET_FLAG (peer
->config
, PEER_CONFIG_WEIGHT
);
3120 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3123 /* peer-group member updates. */
3124 group
= peer
->group
;
3125 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3133 peer_timers_set (struct peer
*peer
, u_int32_t keepalive
, u_int32_t holdtime
)
3135 struct peer_group
*group
;
3136 struct listnode
*node
, *nnode
;
3138 /* Not for peer group memeber. */
3139 if (peer_group_active (peer
))
3140 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3142 /* keepalive value check. */
3143 if (keepalive
> 65535)
3144 return BGP_ERR_INVALID_VALUE
;
3146 /* Holdtime value check. */
3147 if (holdtime
> 65535)
3148 return BGP_ERR_INVALID_VALUE
;
3150 /* Holdtime value must be either 0 or greater than 3. */
3151 if (holdtime
< 3 && holdtime
!= 0)
3152 return BGP_ERR_INVALID_VALUE
;
3154 /* Set value to the configuration. */
3155 SET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
3156 peer
->holdtime
= holdtime
;
3157 peer
->keepalive
= (keepalive
< holdtime
/ 3 ? keepalive
: holdtime
/ 3);
3159 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3162 /* peer-group member updates. */
3163 group
= peer
->group
;
3164 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3166 SET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
3167 peer
->holdtime
= group
->conf
->holdtime
;
3168 peer
->keepalive
= group
->conf
->keepalive
;
3174 peer_timers_unset (struct peer
*peer
)
3176 struct peer_group
*group
;
3177 struct listnode
*node
, *nnode
;
3179 if (peer_group_active (peer
))
3180 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3182 /* Clear configuration. */
3183 UNSET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
3184 peer
->keepalive
= 0;
3187 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3190 /* peer-group member updates. */
3191 group
= peer
->group
;
3192 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3194 UNSET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
3196 peer
->keepalive
= 0;
3203 peer_timers_connect_set (struct peer
*peer
, u_int32_t connect
)
3205 if (peer_group_active (peer
))
3206 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3208 if (connect
> 65535)
3209 return BGP_ERR_INVALID_VALUE
;
3211 /* Set value to the configuration. */
3212 SET_FLAG (peer
->config
, PEER_CONFIG_CONNECT
);
3213 peer
->connect
= connect
;
3215 /* Set value to timer setting. */
3216 peer
->v_connect
= connect
;
3222 peer_timers_connect_unset (struct peer
*peer
)
3224 if (peer_group_active (peer
))
3225 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3227 /* Clear configuration. */
3228 UNSET_FLAG (peer
->config
, PEER_CONFIG_CONNECT
);
3231 /* Set timer setting to default value. */
3232 peer
->v_connect
= BGP_DEFAULT_CONNECT_RETRY
;
3238 peer_advertise_interval_set (struct peer
*peer
, u_int32_t routeadv
)
3240 if (peer_group_active (peer
))
3241 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3244 return BGP_ERR_INVALID_VALUE
;
3246 SET_FLAG (peer
->config
, PEER_CONFIG_ROUTEADV
);
3247 peer
->routeadv
= routeadv
;
3248 peer
->v_routeadv
= routeadv
;
3254 peer_advertise_interval_unset (struct peer
*peer
)
3256 if (peer_group_active (peer
))
3257 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3259 UNSET_FLAG (peer
->config
, PEER_CONFIG_ROUTEADV
);
3262 if (peer_sort (peer
) == BGP_PEER_IBGP
)
3263 peer
->v_routeadv
= BGP_DEFAULT_IBGP_ROUTEADV
;
3265 peer
->v_routeadv
= BGP_DEFAULT_EBGP_ROUTEADV
;
3270 /* neighbor interface */
3272 peer_interface_set (struct peer
*peer
, const char *str
)
3275 free (peer
->ifname
);
3276 peer
->ifname
= strdup (str
);
3282 peer_interface_unset (struct peer
*peer
)
3285 free (peer
->ifname
);
3286 peer
->ifname
= NULL
;
3293 peer_allowas_in_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int allow_num
)
3295 struct peer_group
*group
;
3296 struct listnode
*node
, *nnode
;
3298 if (allow_num
< 1 || allow_num
> 10)
3299 return BGP_ERR_INVALID_VALUE
;
3301 if (peer
->allowas_in
[afi
][safi
] != allow_num
)
3303 peer
->allowas_in
[afi
][safi
] = allow_num
;
3304 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ALLOWAS_IN
);
3305 peer_change_action (peer
, afi
, safi
, peer_change_reset_in
);
3308 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3311 group
= peer
->group
;
3312 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3314 if (peer
->allowas_in
[afi
][safi
] != allow_num
)
3316 peer
->allowas_in
[afi
][safi
] = allow_num
;
3317 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ALLOWAS_IN
);
3318 peer_change_action (peer
, afi
, safi
, peer_change_reset_in
);
3326 peer_allowas_in_unset (struct peer
*peer
, afi_t afi
, safi_t safi
)
3328 struct peer_group
*group
;
3329 struct listnode
*node
, *nnode
;
3331 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ALLOWAS_IN
))
3333 peer
->allowas_in
[afi
][safi
] = 0;
3334 peer_af_flag_unset (peer
, afi
, safi
, PEER_FLAG_ALLOWAS_IN
);
3337 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3340 group
= peer
->group
;
3341 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3343 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ALLOWAS_IN
))
3345 peer
->allowas_in
[afi
][safi
] = 0;
3346 peer_af_flag_unset (peer
, afi
, safi
, PEER_FLAG_ALLOWAS_IN
);
3353 peer_local_as_set (struct peer
*peer
, as_t as
, int no_prepend
)
3355 struct bgp
*bgp
= peer
->bgp
;
3356 struct peer_group
*group
;
3357 struct listnode
*node
, *nnode
;
3359 if (peer_sort (peer
) != BGP_PEER_EBGP
3360 && peer_sort (peer
) != BGP_PEER_INTERNAL
)
3361 return BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP
;
3364 return BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS
;
3366 if (peer_group_active (peer
))
3367 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3369 if (peer
->change_local_as
== as
&&
3370 ((CHECK_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
) && no_prepend
)
3371 || (! CHECK_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
) && ! no_prepend
)))
3374 peer
->change_local_as
= as
;
3376 SET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3378 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3380 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3382 if (peer
->status
== Established
)
3384 peer
->last_reset
= PEER_DOWN_LOCAL_AS_CHANGE
;
3385 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
3386 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3389 BGP_EVENT_ADD (peer
, BGP_Stop
);
3394 group
= peer
->group
;
3395 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3397 peer
->change_local_as
= as
;
3399 SET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3401 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3403 if (peer
->status
== Established
)
3405 peer
->last_reset
= PEER_DOWN_LOCAL_AS_CHANGE
;
3406 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
3407 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3410 BGP_EVENT_ADD (peer
, BGP_Stop
);
3417 peer_local_as_unset (struct peer
*peer
)
3419 struct peer_group
*group
;
3420 struct listnode
*node
, *nnode
;
3422 if (peer_group_active (peer
))
3423 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3425 if (! peer
->change_local_as
)
3428 peer
->change_local_as
= 0;
3429 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3431 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3433 if (peer
->status
== Established
)
3435 peer
->last_reset
= PEER_DOWN_LOCAL_AS_CHANGE
;
3436 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
3437 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3440 BGP_EVENT_ADD (peer
, BGP_Stop
);
3445 group
= peer
->group
;
3446 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3448 peer
->change_local_as
= 0;
3449 UNSET_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
);
3451 if (peer
->status
== Established
)
3453 peer
->last_reset
= PEER_DOWN_LOCAL_AS_CHANGE
;
3454 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
3455 BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3458 BGP_EVENT_ADD (peer
, BGP_Stop
);
3463 /* Set password for authenticating with the peer. */
3465 peer_password_set (struct peer
*peer
, const char *password
)
3467 struct listnode
*nn
, *nnode
;
3468 int len
= password
? strlen(password
) : 0;
3469 int ret
= BGP_SUCCESS
;
3471 if ((len
< PEER_PASSWORD_MINLEN
) || (len
> PEER_PASSWORD_MAXLEN
))
3472 return BGP_ERR_INVALID_VALUE
;
3474 if (peer
->password
&& strcmp (peer
->password
, password
) == 0
3475 && ! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3479 XFREE (MTYPE_PEER_PASSWORD
, peer
->password
);
3481 peer
->password
= XSTRDUP (MTYPE_PEER_PASSWORD
, password
);
3483 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3485 if (peer
->status
== Established
)
3486 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3488 BGP_EVENT_ADD (peer
, BGP_Stop
);
3490 return (bgp_md5_set (peer
) >= 0) ? BGP_SUCCESS
: BGP_ERR_TCPSIG_FAILED
;
3493 for (ALL_LIST_ELEMENTS (peer
->group
->peer
, nn
, nnode
, peer
))
3495 if (peer
->password
&& strcmp (peer
->password
, password
) == 0)
3499 XFREE (MTYPE_PEER_PASSWORD
, peer
->password
);
3501 peer
->password
= XSTRDUP(MTYPE_PEER_PASSWORD
, password
);
3503 if (peer
->status
== Established
)
3504 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3506 BGP_EVENT_ADD (peer
, BGP_Stop
);
3508 if (bgp_md5_set (peer
) < 0)
3509 ret
= BGP_ERR_TCPSIG_FAILED
;
3516 peer_password_unset (struct peer
*peer
)
3518 struct listnode
*nn
, *nnode
;
3521 && !CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3524 if (!CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3526 if (peer_group_active (peer
)
3527 && peer
->group
->conf
->password
3528 && strcmp (peer
->group
->conf
->password
, peer
->password
) == 0)
3529 return BGP_ERR_PEER_GROUP_HAS_THE_FLAG
;
3531 if (peer
->status
== Established
)
3532 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3534 BGP_EVENT_ADD (peer
, BGP_Stop
);
3537 XFREE (MTYPE_PEER_PASSWORD
, peer
->password
);
3539 peer
->password
= NULL
;
3546 XFREE (MTYPE_PEER_PASSWORD
, peer
->password
);
3547 peer
->password
= NULL
;
3549 for (ALL_LIST_ELEMENTS (peer
->group
->peer
, nn
, nnode
, peer
))
3551 if (!peer
->password
)
3554 if (peer
->status
== Established
)
3555 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, BGP_NOTIFY_CEASE_CONFIG_CHANGE
);
3557 BGP_EVENT_ADD (peer
, BGP_Stop
);
3559 XFREE (MTYPE_PEER_PASSWORD
, peer
->password
);
3560 peer
->password
= NULL
;
3568 /* Set distribute list to the peer. */
3570 peer_distribute_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
,
3573 struct bgp_filter
*filter
;
3574 struct peer_group
*group
;
3575 struct listnode
*node
, *nnode
;
3577 if (! peer
->afc
[afi
][safi
])
3578 return BGP_ERR_PEER_INACTIVE
;
3580 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3581 return BGP_ERR_INVALID_VALUE
;
3583 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3584 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3586 filter
= &peer
->filter
[afi
][safi
];
3588 if (filter
->plist
[direct
].name
)
3589 return BGP_ERR_PEER_FILTER_CONFLICT
;
3591 if (filter
->dlist
[direct
].name
)
3592 free (filter
->dlist
[direct
].name
);
3593 filter
->dlist
[direct
].name
= strdup (name
);
3594 filter
->dlist
[direct
].alist
= access_list_lookup (afi
, name
);
3596 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3599 group
= peer
->group
;
3600 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3602 filter
= &peer
->filter
[afi
][safi
];
3604 if (! peer
->af_group
[afi
][safi
])
3607 if (filter
->dlist
[direct
].name
)
3608 free (filter
->dlist
[direct
].name
);
3609 filter
->dlist
[direct
].name
= strdup (name
);
3610 filter
->dlist
[direct
].alist
= access_list_lookup (afi
, name
);
3617 peer_distribute_unset (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
)
3619 struct bgp_filter
*filter
;
3620 struct bgp_filter
*gfilter
;
3621 struct peer_group
*group
;
3622 struct listnode
*node
, *nnode
;
3624 if (! peer
->afc
[afi
][safi
])
3625 return BGP_ERR_PEER_INACTIVE
;
3627 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3628 return BGP_ERR_INVALID_VALUE
;
3630 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3631 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3633 filter
= &peer
->filter
[afi
][safi
];
3635 /* apply peer-group filter */
3636 if (peer
->af_group
[afi
][safi
])
3638 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
3640 if (gfilter
->dlist
[direct
].name
)
3642 if (filter
->dlist
[direct
].name
)
3643 free (filter
->dlist
[direct
].name
);
3644 filter
->dlist
[direct
].name
= strdup (gfilter
->dlist
[direct
].name
);
3645 filter
->dlist
[direct
].alist
= gfilter
->dlist
[direct
].alist
;
3650 if (filter
->dlist
[direct
].name
)
3651 free (filter
->dlist
[direct
].name
);
3652 filter
->dlist
[direct
].name
= NULL
;
3653 filter
->dlist
[direct
].alist
= NULL
;
3655 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3658 group
= peer
->group
;
3659 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3661 filter
= &peer
->filter
[afi
][safi
];
3663 if (! peer
->af_group
[afi
][safi
])
3666 if (filter
->dlist
[direct
].name
)
3667 free (filter
->dlist
[direct
].name
);
3668 filter
->dlist
[direct
].name
= NULL
;
3669 filter
->dlist
[direct
].alist
= NULL
;
3675 /* Update distribute list. */
3677 peer_distribute_update (struct access_list
*access
)
3682 struct listnode
*mnode
, *mnnode
;
3683 struct listnode
*node
, *nnode
;
3686 struct peer_group
*group
;
3687 struct bgp_filter
*filter
;
3689 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
3691 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
3693 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3694 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3696 filter
= &peer
->filter
[afi
][safi
];
3698 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3700 if (filter
->dlist
[direct
].name
)
3701 filter
->dlist
[direct
].alist
=
3702 access_list_lookup (afi
, filter
->dlist
[direct
].name
);
3704 filter
->dlist
[direct
].alist
= NULL
;
3708 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
3710 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3711 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3713 filter
= &group
->conf
->filter
[afi
][safi
];
3715 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3717 if (filter
->dlist
[direct
].name
)
3718 filter
->dlist
[direct
].alist
=
3719 access_list_lookup (afi
, filter
->dlist
[direct
].name
);
3721 filter
->dlist
[direct
].alist
= NULL
;
3728 /* Set prefix list to the peer. */
3730 peer_prefix_list_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
,
3733 struct bgp_filter
*filter
;
3734 struct peer_group
*group
;
3735 struct listnode
*node
, *nnode
;
3737 if (! peer
->afc
[afi
][safi
])
3738 return BGP_ERR_PEER_INACTIVE
;
3740 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3741 return BGP_ERR_INVALID_VALUE
;
3743 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3744 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3746 filter
= &peer
->filter
[afi
][safi
];
3748 if (filter
->dlist
[direct
].name
)
3749 return BGP_ERR_PEER_FILTER_CONFLICT
;
3751 if (filter
->plist
[direct
].name
)
3752 free (filter
->plist
[direct
].name
);
3753 filter
->plist
[direct
].name
= strdup (name
);
3754 filter
->plist
[direct
].plist
= prefix_list_lookup (afi
, name
);
3756 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3759 group
= peer
->group
;
3760 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3762 filter
= &peer
->filter
[afi
][safi
];
3764 if (! peer
->af_group
[afi
][safi
])
3767 if (filter
->plist
[direct
].name
)
3768 free (filter
->plist
[direct
].name
);
3769 filter
->plist
[direct
].name
= strdup (name
);
3770 filter
->plist
[direct
].plist
= prefix_list_lookup (afi
, name
);
3776 peer_prefix_list_unset (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
)
3778 struct bgp_filter
*filter
;
3779 struct bgp_filter
*gfilter
;
3780 struct peer_group
*group
;
3781 struct listnode
*node
, *nnode
;
3783 if (! peer
->afc
[afi
][safi
])
3784 return BGP_ERR_PEER_INACTIVE
;
3786 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3787 return BGP_ERR_INVALID_VALUE
;
3789 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3790 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3792 filter
= &peer
->filter
[afi
][safi
];
3794 /* apply peer-group filter */
3795 if (peer
->af_group
[afi
][safi
])
3797 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
3799 if (gfilter
->plist
[direct
].name
)
3801 if (filter
->plist
[direct
].name
)
3802 free (filter
->plist
[direct
].name
);
3803 filter
->plist
[direct
].name
= strdup (gfilter
->plist
[direct
].name
);
3804 filter
->plist
[direct
].plist
= gfilter
->plist
[direct
].plist
;
3809 if (filter
->plist
[direct
].name
)
3810 free (filter
->plist
[direct
].name
);
3811 filter
->plist
[direct
].name
= NULL
;
3812 filter
->plist
[direct
].plist
= NULL
;
3814 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3817 group
= peer
->group
;
3818 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3820 filter
= &peer
->filter
[afi
][safi
];
3822 if (! peer
->af_group
[afi
][safi
])
3825 if (filter
->plist
[direct
].name
)
3826 free (filter
->plist
[direct
].name
);
3827 filter
->plist
[direct
].name
= NULL
;
3828 filter
->plist
[direct
].plist
= NULL
;
3834 /* Update prefix-list list. */
3836 peer_prefix_list_update (struct prefix_list
*plist
)
3838 struct listnode
*mnode
, *mnnode
;
3839 struct listnode
*node
, *nnode
;
3842 struct peer_group
*group
;
3843 struct bgp_filter
*filter
;
3848 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
3850 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
3852 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3853 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3855 filter
= &peer
->filter
[afi
][safi
];
3857 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3859 if (filter
->plist
[direct
].name
)
3860 filter
->plist
[direct
].plist
=
3861 prefix_list_lookup (afi
, filter
->plist
[direct
].name
);
3863 filter
->plist
[direct
].plist
= NULL
;
3867 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
3869 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3870 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3872 filter
= &group
->conf
->filter
[afi
][safi
];
3874 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
3876 if (filter
->plist
[direct
].name
)
3877 filter
->plist
[direct
].plist
=
3878 prefix_list_lookup (afi
, filter
->plist
[direct
].name
);
3880 filter
->plist
[direct
].plist
= NULL
;
3888 peer_aslist_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
,
3891 struct bgp_filter
*filter
;
3892 struct peer_group
*group
;
3893 struct listnode
*node
, *nnode
;
3895 if (! peer
->afc
[afi
][safi
])
3896 return BGP_ERR_PEER_INACTIVE
;
3898 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3899 return BGP_ERR_INVALID_VALUE
;
3901 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3902 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3904 filter
= &peer
->filter
[afi
][safi
];
3906 if (filter
->aslist
[direct
].name
)
3907 free (filter
->aslist
[direct
].name
);
3908 filter
->aslist
[direct
].name
= strdup (name
);
3909 filter
->aslist
[direct
].aslist
= as_list_lookup (name
);
3911 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3914 group
= peer
->group
;
3915 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3917 filter
= &peer
->filter
[afi
][safi
];
3919 if (! peer
->af_group
[afi
][safi
])
3922 if (filter
->aslist
[direct
].name
)
3923 free (filter
->aslist
[direct
].name
);
3924 filter
->aslist
[direct
].name
= strdup (name
);
3925 filter
->aslist
[direct
].aslist
= as_list_lookup (name
);
3931 peer_aslist_unset (struct peer
*peer
,afi_t afi
, safi_t safi
, int direct
)
3933 struct bgp_filter
*filter
;
3934 struct bgp_filter
*gfilter
;
3935 struct peer_group
*group
;
3936 struct listnode
*node
, *nnode
;
3938 if (! peer
->afc
[afi
][safi
])
3939 return BGP_ERR_PEER_INACTIVE
;
3941 if (direct
!= FILTER_IN
&& direct
!= FILTER_OUT
)
3942 return BGP_ERR_INVALID_VALUE
;
3944 if (direct
== FILTER_OUT
&& peer_is_group_member (peer
, afi
, safi
))
3945 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
3947 filter
= &peer
->filter
[afi
][safi
];
3949 /* apply peer-group filter */
3950 if (peer
->af_group
[afi
][safi
])
3952 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
3954 if (gfilter
->aslist
[direct
].name
)
3956 if (filter
->aslist
[direct
].name
)
3957 free (filter
->aslist
[direct
].name
);
3958 filter
->aslist
[direct
].name
= strdup (gfilter
->aslist
[direct
].name
);
3959 filter
->aslist
[direct
].aslist
= gfilter
->aslist
[direct
].aslist
;
3964 if (filter
->aslist
[direct
].name
)
3965 free (filter
->aslist
[direct
].name
);
3966 filter
->aslist
[direct
].name
= NULL
;
3967 filter
->aslist
[direct
].aslist
= NULL
;
3969 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
3972 group
= peer
->group
;
3973 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
3975 filter
= &peer
->filter
[afi
][safi
];
3977 if (! peer
->af_group
[afi
][safi
])
3980 if (filter
->aslist
[direct
].name
)
3981 free (filter
->aslist
[direct
].name
);
3982 filter
->aslist
[direct
].name
= NULL
;
3983 filter
->aslist
[direct
].aslist
= NULL
;
3990 peer_aslist_update (void)
3995 struct listnode
*mnode
, *mnnode
;
3996 struct listnode
*node
, *nnode
;
3999 struct peer_group
*group
;
4000 struct bgp_filter
*filter
;
4002 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
4004 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
4006 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4007 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
4009 filter
= &peer
->filter
[afi
][safi
];
4011 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
4013 if (filter
->aslist
[direct
].name
)
4014 filter
->aslist
[direct
].aslist
=
4015 as_list_lookup (filter
->aslist
[direct
].name
);
4017 filter
->aslist
[direct
].aslist
= NULL
;
4021 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
4023 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4024 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
4026 filter
= &group
->conf
->filter
[afi
][safi
];
4028 for (direct
= FILTER_IN
; direct
< FILTER_MAX
; direct
++)
4030 if (filter
->aslist
[direct
].name
)
4031 filter
->aslist
[direct
].aslist
=
4032 as_list_lookup (filter
->aslist
[direct
].name
);
4034 filter
->aslist
[direct
].aslist
= NULL
;
4041 /* Set route-map to the peer. */
4043 peer_route_map_set (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
,
4046 struct bgp_filter
*filter
;
4047 struct peer_group
*group
;
4048 struct listnode
*node
, *nnode
;
4050 if (! peer
->afc
[afi
][safi
])
4051 return BGP_ERR_PEER_INACTIVE
;
4053 if (direct
!= RMAP_IN
&& direct
!= RMAP_OUT
&&
4054 direct
!= RMAP_IMPORT
&& direct
!= RMAP_EXPORT
)
4055 return BGP_ERR_INVALID_VALUE
;
4057 if ( (direct
== RMAP_OUT
|| direct
== RMAP_IMPORT
)
4058 && peer_is_group_member (peer
, afi
, safi
))
4059 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
4061 filter
= &peer
->filter
[afi
][safi
];
4063 if (filter
->map
[direct
].name
)
4064 free (filter
->map
[direct
].name
);
4066 filter
->map
[direct
].name
= strdup (name
);
4067 filter
->map
[direct
].map
= route_map_lookup_by_name (name
);
4069 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4072 group
= peer
->group
;
4073 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
4075 filter
= &peer
->filter
[afi
][safi
];
4077 if (! peer
->af_group
[afi
][safi
])
4080 if (filter
->map
[direct
].name
)
4081 free (filter
->map
[direct
].name
);
4082 filter
->map
[direct
].name
= strdup (name
);
4083 filter
->map
[direct
].map
= route_map_lookup_by_name (name
);
4088 /* Unset route-map from the peer. */
4090 peer_route_map_unset (struct peer
*peer
, afi_t afi
, safi_t safi
, int direct
)
4092 struct bgp_filter
*filter
;
4093 struct bgp_filter
*gfilter
;
4094 struct peer_group
*group
;
4095 struct listnode
*node
, *nnode
;
4097 if (! peer
->afc
[afi
][safi
])
4098 return BGP_ERR_PEER_INACTIVE
;
4100 if (direct
!= RMAP_IN
&& direct
!= RMAP_OUT
&&
4101 direct
!= RMAP_IMPORT
&& direct
!= RMAP_EXPORT
)
4102 return BGP_ERR_INVALID_VALUE
;
4104 if ( (direct
== RMAP_OUT
|| direct
== RMAP_IMPORT
)
4105 && peer_is_group_member (peer
, afi
, safi
))
4106 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
4108 filter
= &peer
->filter
[afi
][safi
];
4110 /* apply peer-group filter */
4111 if (peer
->af_group
[afi
][safi
])
4113 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
4115 if (gfilter
->map
[direct
].name
)
4117 if (filter
->map
[direct
].name
)
4118 free (filter
->map
[direct
].name
);
4119 filter
->map
[direct
].name
= strdup (gfilter
->map
[direct
].name
);
4120 filter
->map
[direct
].map
= gfilter
->map
[direct
].map
;
4125 if (filter
->map
[direct
].name
)
4126 free (filter
->map
[direct
].name
);
4127 filter
->map
[direct
].name
= NULL
;
4128 filter
->map
[direct
].map
= NULL
;
4130 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4133 group
= peer
->group
;
4134 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
4136 filter
= &peer
->filter
[afi
][safi
];
4138 if (! peer
->af_group
[afi
][safi
])
4141 if (filter
->map
[direct
].name
)
4142 free (filter
->map
[direct
].name
);
4143 filter
->map
[direct
].name
= NULL
;
4144 filter
->map
[direct
].map
= NULL
;
4149 /* Set unsuppress-map to the peer. */
4151 peer_unsuppress_map_set (struct peer
*peer
, afi_t afi
, safi_t safi
,
4154 struct bgp_filter
*filter
;
4155 struct peer_group
*group
;
4156 struct listnode
*node
, *nnode
;
4158 if (! peer
->afc
[afi
][safi
])
4159 return BGP_ERR_PEER_INACTIVE
;
4161 if (peer_is_group_member (peer
, afi
, safi
))
4162 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
4164 filter
= &peer
->filter
[afi
][safi
];
4166 if (filter
->usmap
.name
)
4167 free (filter
->usmap
.name
);
4169 filter
->usmap
.name
= strdup (name
);
4170 filter
->usmap
.map
= route_map_lookup_by_name (name
);
4172 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4175 group
= peer
->group
;
4176 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
4178 filter
= &peer
->filter
[afi
][safi
];
4180 if (! peer
->af_group
[afi
][safi
])
4183 if (filter
->usmap
.name
)
4184 free (filter
->usmap
.name
);
4185 filter
->usmap
.name
= strdup (name
);
4186 filter
->usmap
.map
= route_map_lookup_by_name (name
);
4191 /* Unset route-map from the peer. */
4193 peer_unsuppress_map_unset (struct peer
*peer
, afi_t afi
, safi_t safi
)
4195 struct bgp_filter
*filter
;
4196 struct peer_group
*group
;
4197 struct listnode
*node
, *nnode
;
4199 if (! peer
->afc
[afi
][safi
])
4200 return BGP_ERR_PEER_INACTIVE
;
4202 if (peer_is_group_member (peer
, afi
, safi
))
4203 return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER
;
4205 filter
= &peer
->filter
[afi
][safi
];
4207 if (filter
->usmap
.name
)
4208 free (filter
->usmap
.name
);
4209 filter
->usmap
.name
= NULL
;
4210 filter
->usmap
.map
= NULL
;
4212 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4215 group
= peer
->group
;
4216 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
4218 filter
= &peer
->filter
[afi
][safi
];
4220 if (! peer
->af_group
[afi
][safi
])
4223 if (filter
->usmap
.name
)
4224 free (filter
->usmap
.name
);
4225 filter
->usmap
.name
= NULL
;
4226 filter
->usmap
.map
= NULL
;
4232 peer_maximum_prefix_set (struct peer
*peer
, afi_t afi
, safi_t safi
,
4233 u_int32_t max
, u_char threshold
,
4234 int warning
, u_int16_t restart
)
4236 struct peer_group
*group
;
4237 struct listnode
*node
, *nnode
;
4239 if (! peer
->afc
[afi
][safi
])
4240 return BGP_ERR_PEER_INACTIVE
;
4242 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4243 peer
->pmax
[afi
][safi
] = max
;
4244 peer
->pmax_threshold
[afi
][safi
] = threshold
;
4245 peer
->pmax_restart
[afi
][safi
] = restart
;
4247 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4249 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4251 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4254 group
= peer
->group
;
4255 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
4257 if (! peer
->af_group
[afi
][safi
])
4260 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4261 peer
->pmax
[afi
][safi
] = max
;
4262 peer
->pmax_threshold
[afi
][safi
] = threshold
;
4263 peer
->pmax_restart
[afi
][safi
] = restart
;
4265 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4267 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4273 peer_maximum_prefix_unset (struct peer
*peer
, afi_t afi
, safi_t safi
)
4275 struct peer_group
*group
;
4276 struct listnode
*node
, *nnode
;
4278 if (! peer
->afc
[afi
][safi
])
4279 return BGP_ERR_PEER_INACTIVE
;
4281 /* apply peer-group config */
4282 if (peer
->af_group
[afi
][safi
])
4284 if (CHECK_FLAG (peer
->group
->conf
->af_flags
[afi
][safi
],
4285 PEER_FLAG_MAX_PREFIX
))
4286 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4288 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4290 if (CHECK_FLAG (peer
->group
->conf
->af_flags
[afi
][safi
],
4291 PEER_FLAG_MAX_PREFIX_WARNING
))
4292 SET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4294 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4296 peer
->pmax
[afi
][safi
] = peer
->group
->conf
->pmax
[afi
][safi
];
4297 peer
->pmax_threshold
[afi
][safi
] = peer
->group
->conf
->pmax_threshold
[afi
][safi
];
4298 peer
->pmax_restart
[afi
][safi
] = peer
->group
->conf
->pmax_restart
[afi
][safi
];
4302 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4303 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4304 peer
->pmax
[afi
][safi
] = 0;
4305 peer
->pmax_threshold
[afi
][safi
] = 0;
4306 peer
->pmax_restart
[afi
][safi
] = 0;
4308 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4311 group
= peer
->group
;
4312 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
4314 if (! peer
->af_group
[afi
][safi
])
4317 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
);
4318 UNSET_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
);
4319 peer
->pmax
[afi
][safi
] = 0;
4320 peer
->pmax_threshold
[afi
][safi
] = 0;
4321 peer
->pmax_restart
[afi
][safi
] = 0;
4327 peer_clear (struct peer
*peer
)
4329 if (! CHECK_FLAG (peer
->flags
, PEER_FLAG_SHUTDOWN
))
4331 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_PREFIX_OVERFLOW
))
4333 UNSET_FLAG (peer
->sflags
, PEER_STATUS_PREFIX_OVERFLOW
);
4334 if (peer
->t_pmax_restart
)
4336 BGP_TIMER_OFF (peer
->t_pmax_restart
);
4337 if (BGP_DEBUG (events
, EVENTS
))
4338 zlog_debug ("%s Maximum-prefix restart timer canceled",
4341 BGP_EVENT_ADD (peer
, BGP_Start
);
4345 peer
->v_start
= BGP_INIT_START_TIMER
;
4346 if (peer
->status
== Established
)
4347 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
4348 BGP_NOTIFY_CEASE_ADMIN_RESET
);
4350 BGP_EVENT_ADD (peer
, BGP_Stop
);
4356 peer_clear_soft (struct peer
*peer
, afi_t afi
, safi_t safi
,
4357 enum bgp_clear_type stype
)
4359 if (peer
->status
!= Established
)
4362 if (! peer
->afc
[afi
][safi
])
4363 return BGP_ERR_AF_UNCONFIGURED
;
4365 if (stype
== BGP_CLEAR_SOFT_RSCLIENT
)
4367 if (! CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
))
4369 bgp_check_local_routes_rsclient (peer
, afi
, safi
);
4370 bgp_soft_reconfig_rsclient (peer
, afi
, safi
);
4373 if (stype
== BGP_CLEAR_SOFT_OUT
|| stype
== BGP_CLEAR_SOFT_BOTH
)
4374 bgp_announce_route (peer
, afi
, safi
);
4376 if (stype
== BGP_CLEAR_SOFT_IN_ORF_PREFIX
)
4378 if (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_SM_ADV
)
4379 && (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_RM_RCV
)
4380 || CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_RM_OLD_RCV
)))
4382 struct bgp_filter
*filter
= &peer
->filter
[afi
][safi
];
4385 if (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_RM_RCV
))
4386 prefix_type
= ORF_TYPE_PREFIX
;
4388 prefix_type
= ORF_TYPE_PREFIX_OLD
;
4390 if (filter
->plist
[FILTER_IN
].plist
)
4392 if (CHECK_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_ORF_PREFIX_SEND
))
4393 bgp_route_refresh_send (peer
, afi
, safi
,
4394 prefix_type
, REFRESH_DEFER
, 1);
4395 bgp_route_refresh_send (peer
, afi
, safi
, prefix_type
,
4396 REFRESH_IMMEDIATE
, 0);
4400 if (CHECK_FLAG (peer
->af_sflags
[afi
][safi
], PEER_STATUS_ORF_PREFIX_SEND
))
4401 bgp_route_refresh_send (peer
, afi
, safi
,
4402 prefix_type
, REFRESH_IMMEDIATE
, 1);
4404 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
4410 if (stype
== BGP_CLEAR_SOFT_IN
|| stype
== BGP_CLEAR_SOFT_BOTH
4411 || stype
== BGP_CLEAR_SOFT_IN_ORF_PREFIX
)
4413 /* If neighbor has soft reconfiguration inbound flag.
4414 Use Adj-RIB-In database. */
4415 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SOFT_RECONFIG
))
4416 bgp_soft_reconfig_in (peer
, afi
, safi
);
4419 /* If neighbor has route refresh capability, send route refresh
4420 message to the peer. */
4421 if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
4422 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
4423 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
4425 return BGP_ERR_SOFT_RECONFIG_UNCONFIGURED
;
4431 /* Display peer uptime.*/
4432 /* XXX: why does this function return char * when it takes buffer? */
4434 peer_uptime (time_t uptime2
, char *buf
, size_t len
)
4439 /* Check buffer length. */
4440 if (len
< BGP_UPTIME_LEN
)
4442 zlog_warn ("peer_uptime (): buffer shortage %lu", (u_long
)len
);
4443 /* XXX: should return status instead of buf... */
4444 snprintf (buf
, len
, "<error> ");
4448 /* If there is no connection has been done before print `never'. */
4451 snprintf (buf
, len
, "never ");
4455 /* Get current time. */
4456 uptime1
= time (NULL
);
4458 tm
= gmtime (&uptime1
);
4460 /* Making formatted timer strings. */
4461 #define ONE_DAY_SECOND 60*60*24
4462 #define ONE_WEEK_SECOND 60*60*24*7
4464 if (uptime1
< ONE_DAY_SECOND
)
4465 snprintf (buf
, len
, "%02d:%02d:%02d",
4466 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
4467 else if (uptime1
< ONE_WEEK_SECOND
)
4468 snprintf (buf
, len
, "%dd%02dh%02dm",
4469 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
4471 snprintf (buf
, len
, "%02dw%dd%02dh",
4472 tm
->tm_yday
/7, tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
4477 bgp_config_write_filter (struct vty
*vty
, struct peer
*peer
,
4478 afi_t afi
, safi_t safi
)
4480 struct bgp_filter
*filter
;
4481 struct bgp_filter
*gfilter
= NULL
;
4484 int out
= FILTER_OUT
;
4487 filter
= &peer
->filter
[afi
][safi
];
4488 if (peer
->af_group
[afi
][safi
])
4489 gfilter
= &peer
->group
->conf
->filter
[afi
][safi
];
4491 /* distribute-list. */
4492 if (filter
->dlist
[in
].name
)
4493 if (! gfilter
|| ! gfilter
->dlist
[in
].name
4494 || strcmp (filter
->dlist
[in
].name
, gfilter
->dlist
[in
].name
) != 0)
4495 vty_out (vty
, " neighbor %s distribute-list %s in%s", addr
,
4496 filter
->dlist
[in
].name
, VTY_NEWLINE
);
4497 if (filter
->dlist
[out
].name
&& ! gfilter
)
4498 vty_out (vty
, " neighbor %s distribute-list %s out%s", addr
,
4499 filter
->dlist
[out
].name
, VTY_NEWLINE
);
4502 if (filter
->plist
[in
].name
)
4503 if (! gfilter
|| ! gfilter
->plist
[in
].name
4504 || strcmp (filter
->plist
[in
].name
, gfilter
->plist
[in
].name
) != 0)
4505 vty_out (vty
, " neighbor %s prefix-list %s in%s", addr
,
4506 filter
->plist
[in
].name
, VTY_NEWLINE
);
4507 if (filter
->plist
[out
].name
&& ! gfilter
)
4508 vty_out (vty
, " neighbor %s prefix-list %s out%s", addr
,
4509 filter
->plist
[out
].name
, VTY_NEWLINE
);
4512 if (filter
->map
[RMAP_IN
].name
)
4513 if (! gfilter
|| ! gfilter
->map
[RMAP_IN
].name
4514 || strcmp (filter
->map
[RMAP_IN
].name
, gfilter
->map
[RMAP_IN
].name
) != 0)
4515 vty_out (vty
, " neighbor %s route-map %s in%s", addr
,
4516 filter
->map
[RMAP_IN
].name
, VTY_NEWLINE
);
4517 if (filter
->map
[RMAP_OUT
].name
&& ! gfilter
)
4518 vty_out (vty
, " neighbor %s route-map %s out%s", addr
,
4519 filter
->map
[RMAP_OUT
].name
, VTY_NEWLINE
);
4520 if (filter
->map
[RMAP_IMPORT
].name
&& ! gfilter
)
4521 vty_out (vty
, " neighbor %s route-map %s import%s", addr
,
4522 filter
->map
[RMAP_IMPORT
].name
, VTY_NEWLINE
);
4523 if (filter
->map
[RMAP_EXPORT
].name
)
4524 if (! gfilter
|| ! gfilter
->map
[RMAP_EXPORT
].name
4525 || strcmp (filter
->map
[RMAP_EXPORT
].name
,
4526 gfilter
->map
[RMAP_EXPORT
].name
) != 0)
4527 vty_out (vty
, " neighbor %s route-map %s export%s", addr
,
4528 filter
->map
[RMAP_EXPORT
].name
, VTY_NEWLINE
);
4530 /* unsuppress-map */
4531 if (filter
->usmap
.name
&& ! gfilter
)
4532 vty_out (vty
, " neighbor %s unsuppress-map %s%s", addr
,
4533 filter
->usmap
.name
, VTY_NEWLINE
);
4536 if (filter
->aslist
[in
].name
)
4537 if (! gfilter
|| ! gfilter
->aslist
[in
].name
4538 || strcmp (filter
->aslist
[in
].name
, gfilter
->aslist
[in
].name
) != 0)
4539 vty_out (vty
, " neighbor %s filter-list %s in%s", addr
,
4540 filter
->aslist
[in
].name
, VTY_NEWLINE
);
4541 if (filter
->aslist
[out
].name
&& ! gfilter
)
4542 vty_out (vty
, " neighbor %s filter-list %s out%s", addr
,
4543 filter
->aslist
[out
].name
, VTY_NEWLINE
);
4546 /* BGP peer configuration display function. */
4548 bgp_config_write_peer (struct vty
*vty
, struct bgp
*bgp
,
4549 struct peer
*peer
, afi_t afi
, safi_t safi
)
4551 struct bgp_filter
*filter
;
4552 struct peer
*g_peer
= NULL
;
4553 char buf
[SU_ADDRSTRLEN
];
4556 filter
= &peer
->filter
[afi
][safi
];
4558 if (peer_group_active (peer
))
4559 g_peer
= peer
->group
->conf
;
4561 /************************************
4562 ****** Global to the neighbor ******
4563 ************************************/
4564 if (afi
== AFI_IP
&& safi
== SAFI_UNICAST
)
4567 if (! peer_group_active (peer
))
4569 if (CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
4570 vty_out (vty
, " neighbor %s peer-group%s", addr
,
4573 vty_out (vty
, " neighbor %s remote-as %u%s", addr
, peer
->as
,
4579 vty_out (vty
, " neighbor %s remote-as %u%s", addr
, peer
->as
,
4581 if (peer
->af_group
[AFI_IP
][SAFI_UNICAST
])
4582 vty_out (vty
, " neighbor %s peer-group %s%s", addr
,
4583 peer
->group
->name
, VTY_NEWLINE
);
4587 if (peer
->change_local_as
)
4588 if (! peer_group_active (peer
))
4589 vty_out (vty
, " neighbor %s local-as %u%s%s", addr
,
4590 peer
->change_local_as
,
4591 CHECK_FLAG (peer
->flags
, PEER_FLAG_LOCAL_AS_NO_PREPEND
) ?
4592 " no-prepend" : "", VTY_NEWLINE
);
4596 vty_out (vty
, " neighbor %s description %s%s", addr
, peer
->desc
,
4600 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_SHUTDOWN
))
4601 if (! peer_group_active (peer
) ||
4602 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_SHUTDOWN
))
4603 vty_out (vty
, " neighbor %s shutdown%s", addr
, VTY_NEWLINE
);
4607 if (!peer_group_active (peer
)
4608 || ! g_peer
->password
4609 || strcmp (peer
->password
, g_peer
->password
) != 0)
4610 vty_out (vty
, " neighbor %s password %s%s", addr
, peer
->password
,
4614 if (peer
->port
!= BGP_PORT_DEFAULT
)
4615 vty_out (vty
, " neighbor %s port %d%s", addr
, peer
->port
,
4618 /* Local interface name. */
4620 vty_out (vty
, " neighbor %s interface %s%s", addr
, peer
->ifname
,
4624 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_PASSIVE
))
4625 if (! peer_group_active (peer
) ||
4626 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_PASSIVE
))
4627 vty_out (vty
, " neighbor %s passive%s", addr
, VTY_NEWLINE
);
4629 /* EBGP multihop. */
4630 if (peer_sort (peer
) != BGP_PEER_IBGP
&& peer
->ttl
!= 1)
4631 if (! peer_group_active (peer
) ||
4632 g_peer
->ttl
!= peer
->ttl
)
4633 vty_out (vty
, " neighbor %s ebgp-multihop %d%s", addr
, peer
->ttl
,
4636 /* disable-connected-check. */
4637 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
))
4638 if (! peer_group_active (peer
) ||
4639 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
))
4640 vty_out (vty
, " neighbor %s disable-connected-check%s", addr
, VTY_NEWLINE
);
4642 /* Update-source. */
4643 if (peer
->update_if
)
4644 if (! peer_group_active (peer
) || ! g_peer
->update_if
4645 || strcmp (g_peer
->update_if
, peer
->update_if
) != 0)
4646 vty_out (vty
, " neighbor %s update-source %s%s", addr
,
4647 peer
->update_if
, VTY_NEWLINE
);
4648 if (peer
->update_source
)
4649 if (! peer_group_active (peer
) || ! g_peer
->update_source
4650 || sockunion_cmp (g_peer
->update_source
,
4651 peer
->update_source
) != 0)
4652 vty_out (vty
, " neighbor %s update-source %s%s", addr
,
4653 sockunion2str (peer
->update_source
, buf
, SU_ADDRSTRLEN
),
4656 /* advertisement-interval */
4657 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_ROUTEADV
))
4658 vty_out (vty
, " neighbor %s advertisement-interval %d%s",
4659 addr
, peer
->v_routeadv
, VTY_NEWLINE
);
4662 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_TIMER
)
4663 && ! peer_group_active (peer
))
4664 vty_out (vty
, " neighbor %s timers %d %d%s", addr
,
4665 peer
->keepalive
, peer
->holdtime
, VTY_NEWLINE
);
4667 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_CONNECT
))
4668 vty_out (vty
, " neighbor %s timers connect %d%s", addr
,
4669 peer
->connect
, VTY_NEWLINE
);
4671 /* Default weight. */
4672 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_WEIGHT
))
4673 if (! peer_group_active (peer
) ||
4674 g_peer
->weight
!= peer
->weight
)
4675 vty_out (vty
, " neighbor %s weight %d%s", addr
, peer
->weight
,
4678 /* Dynamic capability. */
4679 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_DYNAMIC_CAPABILITY
))
4680 if (! peer_group_active (peer
) ||
4681 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_DYNAMIC_CAPABILITY
))
4682 vty_out (vty
, " neighbor %s capability dynamic%s", addr
,
4685 /* dont capability negotiation. */
4686 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_DONT_CAPABILITY
))
4687 if (! peer_group_active (peer
) ||
4688 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_DONT_CAPABILITY
))
4689 vty_out (vty
, " neighbor %s dont-capability-negotiate%s", addr
,
4692 /* override capability negotiation. */
4693 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_OVERRIDE_CAPABILITY
))
4694 if (! peer_group_active (peer
) ||
4695 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_OVERRIDE_CAPABILITY
))
4696 vty_out (vty
, " neighbor %s override-capability%s", addr
,
4699 /* strict capability negotiation. */
4700 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_STRICT_CAP_MATCH
))
4701 if (! peer_group_active (peer
) ||
4702 ! CHECK_FLAG (g_peer
->flags
, PEER_FLAG_STRICT_CAP_MATCH
))
4703 vty_out (vty
, " neighbor %s strict-capability-match%s", addr
,
4706 if (! peer_group_active (peer
))
4708 if (bgp_flag_check (bgp
, BGP_FLAG_NO_DEFAULT_IPV4
))
4710 if (peer
->afc
[AFI_IP
][SAFI_UNICAST
])
4711 vty_out (vty
, " neighbor %s activate%s", addr
, VTY_NEWLINE
);
4715 if (! peer
->afc
[AFI_IP
][SAFI_UNICAST
])
4716 vty_out (vty
, " no neighbor %s activate%s", addr
, VTY_NEWLINE
);
4722 /************************************
4723 ****** Per AF to the neighbor ******
4724 ************************************/
4726 if (! (afi
== AFI_IP
&& safi
== SAFI_UNICAST
))
4728 if (peer
->af_group
[afi
][safi
])
4729 vty_out (vty
, " neighbor %s peer-group %s%s", addr
,
4730 peer
->group
->name
, VTY_NEWLINE
);
4732 vty_out (vty
, " neighbor %s activate%s", addr
, VTY_NEWLINE
);
4735 /* ORF capability. */
4736 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
)
4737 || CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_RM
))
4738 if (! peer
->af_group
[afi
][safi
])
4740 vty_out (vty
, " neighbor %s capability orf prefix-list", addr
);
4742 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
)
4743 && CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_RM
))
4744 vty_out (vty
, " both");
4745 else if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
))
4746 vty_out (vty
, " send");
4748 vty_out (vty
, " receive");
4749 vty_out (vty
, "%s", VTY_NEWLINE
);
4752 /* Route reflector client. */
4753 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REFLECTOR_CLIENT
)
4754 && ! peer
->af_group
[afi
][safi
])
4755 vty_out (vty
, " neighbor %s route-reflector-client%s", addr
,
4759 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_NEXTHOP_SELF
)
4760 && ! peer
->af_group
[afi
][safi
])
4761 vty_out (vty
, " neighbor %s next-hop-self%s", addr
, VTY_NEWLINE
);
4763 /* Remove private AS. */
4764 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_REMOVE_PRIVATE_AS
)
4765 && ! peer
->af_group
[afi
][safi
])
4766 vty_out (vty
, " neighbor %s remove-private-AS%s",
4769 /* send-community print. */
4770 if (! peer
->af_group
[afi
][safi
])
4772 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
))
4774 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_COMMUNITY
)
4775 && peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_EXT_COMMUNITY
))
4776 vty_out (vty
, " neighbor %s send-community both%s", addr
, VTY_NEWLINE
);
4777 else if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_EXT_COMMUNITY
))
4778 vty_out (vty
, " neighbor %s send-community extended%s",
4780 else if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_COMMUNITY
))
4781 vty_out (vty
, " neighbor %s send-community%s", addr
, VTY_NEWLINE
);
4785 if (! peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_COMMUNITY
)
4786 && ! peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_EXT_COMMUNITY
))
4787 vty_out (vty
, " no neighbor %s send-community both%s",
4789 else if (! peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_EXT_COMMUNITY
))
4790 vty_out (vty
, " no neighbor %s send-community extended%s",
4792 else if (! peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_SEND_COMMUNITY
))
4793 vty_out (vty
, " no neighbor %s send-community%s",
4798 /* Default information */
4799 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_DEFAULT_ORIGINATE
)
4800 && ! peer
->af_group
[afi
][safi
])
4802 vty_out (vty
, " neighbor %s default-originate", addr
);
4803 if (peer
->default_rmap
[afi
][safi
].name
)
4804 vty_out (vty
, " route-map %s", peer
->default_rmap
[afi
][safi
].name
);
4805 vty_out (vty
, "%s", VTY_NEWLINE
);
4808 /* Soft reconfiguration inbound. */
4809 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_SOFT_RECONFIG
))
4810 if (! peer
->af_group
[afi
][safi
] ||
4811 ! CHECK_FLAG (g_peer
->af_flags
[afi
][safi
], PEER_FLAG_SOFT_RECONFIG
))
4812 vty_out (vty
, " neighbor %s soft-reconfiguration inbound%s", addr
,
4815 /* maximum-prefix. */
4816 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX
))
4817 if (! peer
->af_group
[afi
][safi
]
4818 || g_peer
->pmax
[afi
][safi
] != peer
->pmax
[afi
][safi
]
4819 || g_peer
->pmax_threshold
[afi
][safi
] != peer
->pmax_threshold
[afi
][safi
]
4820 || CHECK_FLAG (g_peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
)
4821 != CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
))
4823 vty_out (vty
, " neighbor %s maximum-prefix %ld", addr
, peer
->pmax
[afi
][safi
]);
4824 if (peer
->pmax_threshold
[afi
][safi
] != MAXIMUM_PREFIX_THRESHOLD_DEFAULT
)
4825 vty_out (vty
, " %d", peer
->pmax_threshold
[afi
][safi
]);
4826 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_WARNING
))
4827 vty_out (vty
, " warning-only");
4828 if (peer
->pmax_restart
[afi
][safi
])
4829 vty_out (vty
, " restart %d", peer
->pmax_restart
[afi
][safi
]);
4830 vty_out (vty
, "%s", VTY_NEWLINE
);
4833 /* Route server client. */
4834 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_RSERVER_CLIENT
)
4835 && ! peer
->af_group
[afi
][safi
])
4836 vty_out (vty
, " neighbor %s route-server-client%s", addr
, VTY_NEWLINE
);
4839 if (peer_af_flag_check (peer
, afi
, safi
, PEER_FLAG_ALLOWAS_IN
))
4840 if (! peer_group_active (peer
)
4841 || ! peer_af_flag_check (g_peer
, afi
, safi
, PEER_FLAG_ALLOWAS_IN
)
4842 || peer
->allowas_in
[afi
][safi
] != g_peer
->allowas_in
[afi
][safi
])
4844 if (peer
->allowas_in
[afi
][safi
] == 3)
4845 vty_out (vty
, " neighbor %s allowas-in%s", addr
, VTY_NEWLINE
);
4847 vty_out (vty
, " neighbor %s allowas-in %d%s", addr
,
4848 peer
->allowas_in
[afi
][safi
], VTY_NEWLINE
);
4852 bgp_config_write_filter (vty
, peer
, afi
, safi
);
4854 /* atribute-unchanged. */
4855 if ((CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_AS_PATH_UNCHANGED
)
4856 || CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_NEXTHOP_UNCHANGED
)
4857 || CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MED_UNCHANGED
))
4858 && ! peer
->af_group
[afi
][safi
])
4860 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_AS_PATH_UNCHANGED
)
4861 && CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_NEXTHOP_UNCHANGED
)
4862 && CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MED_UNCHANGED
))
4863 vty_out (vty
, " neighbor %s attribute-unchanged%s", addr
, VTY_NEWLINE
);
4865 vty_out (vty
, " neighbor %s attribute-unchanged%s%s%s%s", addr
,
4866 (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_AS_PATH_UNCHANGED
)) ?
4868 (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_NEXTHOP_UNCHANGED
)) ?
4870 (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_MED_UNCHANGED
)) ?
4871 " med" : "", VTY_NEWLINE
);
4875 /* Display "address-family" configuration header. */
4877 bgp_config_write_family_header (struct vty
*vty
, afi_t afi
, safi_t safi
,
4883 if (afi
== AFI_IP
&& safi
== SAFI_UNICAST
)
4886 vty_out (vty
, "!%s address-family ", VTY_NEWLINE
);
4890 if (safi
== SAFI_MULTICAST
)
4891 vty_out (vty
, "ipv4 multicast");
4892 else if (safi
== SAFI_MPLS_VPN
)
4893 vty_out (vty
, "vpnv4 unicast");
4895 else if (afi
== AFI_IP6
)
4897 vty_out (vty
, "ipv6");
4899 if (safi
== SAFI_MULTICAST
)
4900 vty_out (vty
, " multicast");
4903 vty_out (vty
, "%s", VTY_NEWLINE
);
4908 /* Address family based peer configuration display. */
4910 bgp_config_write_family (struct vty
*vty
, struct bgp
*bgp
, afi_t afi
,
4915 struct peer_group
*group
;
4916 struct listnode
*node
, *nnode
;
4918 bgp_config_write_network (vty
, bgp
, afi
, safi
, &write
);
4920 bgp_config_write_redistribute (vty
, bgp
, afi
, safi
, &write
);
4922 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
4924 if (group
->conf
->afc
[afi
][safi
])
4926 bgp_config_write_family_header (vty
, afi
, safi
, &write
);
4927 bgp_config_write_peer (vty
, bgp
, group
->conf
, afi
, safi
);
4930 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
4932 if (peer
->afc
[afi
][safi
])
4934 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
4936 bgp_config_write_family_header (vty
, afi
, safi
, &write
);
4937 bgp_config_write_peer (vty
, bgp
, peer
, afi
, safi
);
4942 vty_out (vty
, " exit-address-family%s", VTY_NEWLINE
);
4948 bgp_config_write (struct vty
*vty
)
4952 struct peer_group
*group
;
4954 struct listnode
*node
, *nnode
;
4955 struct listnode
*mnode
, *mnnode
;
4957 /* BGP Multiple instance. */
4958 if (bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE
))
4960 vty_out (vty
, "bgp multiple-instance%s", VTY_NEWLINE
);
4964 /* BGP Config type. */
4965 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
))
4967 vty_out (vty
, "bgp config-type cisco%s", VTY_NEWLINE
);
4971 /* BGP configuration. */
4972 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
4975 vty_out (vty
, "!%s", VTY_NEWLINE
);
4977 /* Router bgp ASN */
4978 vty_out (vty
, "router bgp %u", bgp
->as
);
4980 if (bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE
))
4983 vty_out (vty
, " view %s", bgp
->name
);
4985 vty_out (vty
, "%s", VTY_NEWLINE
);
4987 /* No Synchronization */
4988 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
))
4989 vty_out (vty
, " no synchronization%s", VTY_NEWLINE
);
4991 /* BGP fast-external-failover. */
4992 if (CHECK_FLAG (bgp
->flags
, BGP_FLAG_NO_FAST_EXT_FAILOVER
))
4993 vty_out (vty
, " no bgp fast-external-failover%s", VTY_NEWLINE
);
4995 /* BGP router ID. */
4996 if (CHECK_FLAG (bgp
->config
, BGP_CONFIG_ROUTER_ID
))
4997 vty_out (vty
, " bgp router-id %s%s", inet_ntoa (bgp
->router_id
),
5000 /* BGP log-neighbor-changes. */
5001 if (bgp_flag_check (bgp
, BGP_FLAG_LOG_NEIGHBOR_CHANGES
))
5002 vty_out (vty
, " bgp log-neighbor-changes%s", VTY_NEWLINE
);
5004 /* BGP configuration. */
5005 if (bgp_flag_check (bgp
, BGP_FLAG_ALWAYS_COMPARE_MED
))
5006 vty_out (vty
, " bgp always-compare-med%s", VTY_NEWLINE
);
5008 /* BGP default ipv4-unicast. */
5009 if (bgp_flag_check (bgp
, BGP_FLAG_NO_DEFAULT_IPV4
))
5010 vty_out (vty
, " no bgp default ipv4-unicast%s", VTY_NEWLINE
);
5012 /* BGP default local-preference. */
5013 if (bgp
->default_local_pref
!= BGP_DEFAULT_LOCAL_PREF
)
5014 vty_out (vty
, " bgp default local-preference %d%s",
5015 bgp
->default_local_pref
, VTY_NEWLINE
);
5017 /* BGP client-to-client reflection. */
5018 if (bgp_flag_check (bgp
, BGP_FLAG_NO_CLIENT_TO_CLIENT
))
5019 vty_out (vty
, " no bgp client-to-client reflection%s", VTY_NEWLINE
);
5021 /* BGP cluster ID. */
5022 if (CHECK_FLAG (bgp
->config
, BGP_CONFIG_CLUSTER_ID
))
5023 vty_out (vty
, " bgp cluster-id %s%s", inet_ntoa (bgp
->cluster_id
),
5026 /* Confederation identifier*/
5027 if (CHECK_FLAG (bgp
->config
, BGP_CONFIG_CONFEDERATION
))
5028 vty_out (vty
, " bgp confederation identifier %i%s", bgp
->confed_id
,
5031 /* Confederation peer */
5032 if (bgp
->confed_peers_cnt
> 0)
5036 vty_out (vty
, " bgp confederation peers");
5038 for (i
= 0; i
< bgp
->confed_peers_cnt
; i
++)
5039 vty_out(vty
, " %u", bgp
->confed_peers
[i
]);
5041 vty_out (vty
, "%s", VTY_NEWLINE
);
5044 /* BGP enforce-first-as. */
5045 if (bgp_flag_check (bgp
, BGP_FLAG_ENFORCE_FIRST_AS
))
5046 vty_out (vty
, " bgp enforce-first-as%s", VTY_NEWLINE
);
5048 /* BGP deterministic-med. */
5049 if (bgp_flag_check (bgp
, BGP_FLAG_DETERMINISTIC_MED
))
5050 vty_out (vty
, " bgp deterministic-med%s", VTY_NEWLINE
);
5052 /* BGP graceful-restart. */
5053 if (bgp
->stalepath_time
!= BGP_DEFAULT_STALEPATH_TIME
)
5054 vty_out (vty
, " bgp graceful-restart stalepath-time %d%s",
5055 bgp
->stalepath_time
, VTY_NEWLINE
);
5056 if (bgp_flag_check (bgp
, BGP_FLAG_GRACEFUL_RESTART
))
5057 vty_out (vty
, " bgp graceful-restart%s", VTY_NEWLINE
);
5059 /* BGP bestpath method. */
5060 if (bgp_flag_check (bgp
, BGP_FLAG_ASPATH_IGNORE
))
5061 vty_out (vty
, " bgp bestpath as-path ignore%s", VTY_NEWLINE
);
5062 if (bgp_flag_check (bgp
, BGP_FLAG_ASPATH_CONFED
))
5063 vty_out (vty
, " bgp bestpath as-path confed%s", VTY_NEWLINE
);
5064 if (bgp_flag_check (bgp
, BGP_FLAG_COMPARE_ROUTER_ID
))
5065 vty_out (vty
, " bgp bestpath compare-routerid%s", VTY_NEWLINE
);
5066 if (bgp_flag_check (bgp
, BGP_FLAG_MED_CONFED
)
5067 || bgp_flag_check (bgp
, BGP_FLAG_MED_MISSING_AS_WORST
))
5069 vty_out (vty
, " bgp bestpath med");
5070 if (bgp_flag_check (bgp
, BGP_FLAG_MED_CONFED
))
5071 vty_out (vty
, " confed");
5072 if (bgp_flag_check (bgp
, BGP_FLAG_MED_MISSING_AS_WORST
))
5073 vty_out (vty
, " missing-as-worst");
5074 vty_out (vty
, "%s", VTY_NEWLINE
);
5077 /* BGP network import check. */
5078 if (bgp_flag_check (bgp
, BGP_FLAG_IMPORT_CHECK
))
5079 vty_out (vty
, " bgp network import-check%s", VTY_NEWLINE
);
5081 /* BGP scan interval. */
5082 bgp_config_write_scan_time (vty
);
5084 /* BGP flag dampening. */
5085 if (CHECK_FLAG (bgp
->af_flags
[AFI_IP
][SAFI_UNICAST
],
5086 BGP_CONFIG_DAMPENING
))
5087 bgp_config_write_damp (vty
);
5089 /* BGP static route configuration. */
5090 bgp_config_write_network (vty
, bgp
, AFI_IP
, SAFI_UNICAST
, &write
);
5092 /* BGP redistribute configuration. */
5093 bgp_config_write_redistribute (vty
, bgp
, AFI_IP
, SAFI_UNICAST
, &write
);
5095 /* BGP timers configuration. */
5096 if (bgp
->default_keepalive
!= BGP_DEFAULT_KEEPALIVE
5097 && bgp
->default_holdtime
!= BGP_DEFAULT_HOLDTIME
)
5098 vty_out (vty
, " timers bgp %d %d%s", bgp
->default_keepalive
,
5099 bgp
->default_holdtime
, VTY_NEWLINE
);
5102 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
5104 bgp_config_write_peer (vty
, bgp
, group
->conf
, AFI_IP
, SAFI_UNICAST
);
5107 /* Normal neighbor configuration. */
5108 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
5110 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_ACCEPT_PEER
))
5111 bgp_config_write_peer (vty
, bgp
, peer
, AFI_IP
, SAFI_UNICAST
);
5114 /* Distance configuration. */
5115 bgp_config_write_distance (vty
, bgp
);
5117 /* No auto-summary */
5118 if (bgp_option_check (BGP_OPT_CONFIG_CISCO
))
5119 vty_out (vty
, " no auto-summary%s", VTY_NEWLINE
);
5121 /* IPv4 multicast configuration. */
5122 write
+= bgp_config_write_family (vty
, bgp
, AFI_IP
, SAFI_MULTICAST
);
5124 /* IPv4 VPN configuration. */
5125 write
+= bgp_config_write_family (vty
, bgp
, AFI_IP
, SAFI_MPLS_VPN
);
5127 /* IPv6 unicast configuration. */
5128 write
+= bgp_config_write_family (vty
, bgp
, AFI_IP6
, SAFI_UNICAST
);
5130 /* IPv6 multicast configuration. */
5131 write
+= bgp_config_write_family (vty
, bgp
, AFI_IP6
, SAFI_MULTICAST
);
5139 bgp_master_init (void)
5141 memset (&bgp_master
, 0, sizeof (struct bgp_master
));
5144 bm
->bgp
= list_new ();
5145 bm
->listen_sockets
= list_new ();
5146 bm
->port
= BGP_PORT_DEFAULT
;
5147 bm
->master
= thread_master_create ();
5148 bm
->start_time
= time (NULL
);
5155 /* BGP VTY commands installation. */
5166 bgp_route_map_init ();
5168 bgp_mplsvpn_init ();
5170 /* Access list initialize. */
5171 access_list_init ();
5172 access_list_add_hook (peer_distribute_update
);
5173 access_list_delete_hook (peer_distribute_update
);
5175 /* Filter list initialize. */
5177 as_list_add_hook (peer_aslist_update
);
5178 as_list_delete_hook (peer_aslist_update
);
5180 /* Prefix list initialize.*/
5181 prefix_list_init ();
5182 prefix_list_add_hook (peer_prefix_list_update
);
5183 prefix_list_delete_hook (peer_prefix_list_update
);
5185 /* Community list initialize. */
5186 bgp_clist
= community_list_init ();
5190 #endif /* HAVE_SNMP */
5194 bgp_terminate (void)
5198 struct listnode
*node
, *nnode
;
5199 struct listnode
*mnode
, *mnnode
;
5201 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
5202 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
5203 if (peer
->status
== Established
)
5204 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
,
5205 BGP_NOTIFY_CEASE_PEER_UNCONFIG
);
5207 bgp_cleanup_routes ();
5209 if (bm
->process_main_queue
)
5211 work_queue_free (bm
->process_main_queue
);
5212 bm
->process_main_queue
= NULL
;
5214 if (bm
->process_rsclient_queue
)
5216 work_queue_free (bm
->process_rsclient_queue
);
5217 bm
->process_rsclient_queue
= NULL
;