summaryrefslogtreecommitdiffstats
path: root/bgpd/bgpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'bgpd/bgpd.c')
-rw-r--r--bgpd/bgpd.c138
1 files changed, 39 insertions, 99 deletions
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 1712c719..4157a8d6 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -114,46 +114,6 @@ bgp_option_check (int flag)
return CHECK_FLAG (bm->options, flag);
}
-/* BGP flag manipulation. */
-int
-bgp_flag_set (struct bgp *bgp, int flag)
-{
- SET_FLAG (bgp->flags, flag);
- return 0;
-}
-
-int
-bgp_flag_unset (struct bgp *bgp, int flag)
-{
- UNSET_FLAG (bgp->flags, flag);
- return 0;
-}
-
-int
-bgp_flag_check (struct bgp *bgp, int flag)
-{
- return CHECK_FLAG (bgp->flags, flag);
-}
-
-/* Internal function to set BGP structure configureation flag. */
-static void
-bgp_config_set (struct bgp *bgp, int config)
-{
- SET_FLAG (bgp->config, config);
-}
-
-static void
-bgp_config_unset (struct bgp *bgp, int config)
-{
- UNSET_FLAG (bgp->config, config);
-}
-
-static int
-bgp_config_check (struct bgp *bgp, int config)
-{
- return CHECK_FLAG (bgp->config, config);
-}
-
/* Set BGP router identifier. */
int
bgp_router_id_set (struct bgp *bgp, struct in_addr *id)
@@ -684,11 +644,13 @@ peer_sort (struct peer *peer)
}
}
-static inline void
+void
peer_free (struct peer *peer)
{
assert (peer->status == Deleted);
-
+
+ bgp_unlock(peer->bgp);
+
/* this /ought/ to have been done already through bgp_stop earlier,
* but just to be sure..
*/
@@ -719,49 +681,6 @@ peer_free (struct peer *peer)
XFREE (MTYPE_BGP_PEER, peer);
}
-
-/* increase reference count on a struct peer */
-struct peer *
-peer_lock (struct peer *peer)
-{
- assert (peer && (peer->lock >= 0));
- assert (peer->status != Deleted);
-
- peer->lock++;
-
- return peer;
-}
-
-/* decrease reference count on a struct peer
- * struct peer is freed and NULL returned if last reference
- */
-struct peer *
-peer_unlock (struct peer *peer)
-{
- assert (peer && (peer->lock > 0));
-
- peer->lock--;
-
- if (peer->lock == 0)
- {
-#if 0
- zlog_debug ("unlocked and freeing");
- zlog_backtrace (LOG_DEBUG);
-#endif
- peer_free (peer);
- return NULL;
- }
-
-#if 0
- if (peer->lock == 1)
- {
- zlog_debug ("unlocked to 1");
- zlog_backtrace (LOG_DEBUG);
- }
-#endif
-
- return peer;
-}
/* Allocate new peer object, implicitely locked. */
static struct peer *
@@ -791,6 +710,7 @@ peer_new (struct bgp *bgp)
peer->password = NULL;
peer->bgp = bgp;
peer = peer_lock (peer); /* initial reference */
+ bgp_lock (bgp);
/* Set default flags. */
for (afi = AFI_IP; afi < AFI_MAX; afi++)
@@ -1127,7 +1047,7 @@ peer_deactivate (struct peer *peer, afi_t afi, safi_t safi)
return 0;
}
-void
+static void
peer_nsf_stop (struct peer *peer)
{
afi_t afi;
@@ -1190,7 +1110,7 @@ peer_delete (struct peer *peer)
if ((pn = listnode_lookup (peer->group->peer, peer)))
{
- peer = peer_unlock (peer); /* group->peer list reference */
+ peer_unlock (peer); /* group->peer list reference */
list_delete_node (peer->group->peer, pn);
}
peer->group = NULL;
@@ -1321,7 +1241,7 @@ peer_group_active (struct peer *peer)
/* Peer group cofiguration. */
static struct peer_group *
-peer_group_new ()
+peer_group_new (void)
{
return (struct peer_group *) XCALLOC (MTYPE_PEER_GROUP,
sizeof (struct peer_group));
@@ -1909,6 +1829,7 @@ bgp_create (as_t *as, const char *name)
if ( (bgp = XCALLOC (MTYPE_BGP, sizeof (struct bgp))) == NULL)
return NULL;
+ bgp_lock (bgp);
bgp->peer_self = peer_new (bgp);
bgp->peer_self->host = strdup ("Static announcement");
@@ -1940,6 +1861,9 @@ bgp_create (as_t *as, const char *name)
if (name)
bgp->name = strdup (name);
+ if (bgp_option_check (BGP_OPT_IMPORT_CHECK))
+ bgp_flag_set (bgp, BGP_FLAG_IMPORT_CHECK);
+
return bgp;
}
@@ -2045,7 +1969,6 @@ bgp_delete (struct bgp *bgp)
struct listnode *node;
struct listnode *next;
afi_t afi;
- safi_t safi;
int i;
/* Delete static route. */
@@ -2059,14 +1982,31 @@ bgp_delete (struct bgp *bgp)
for (ALL_LIST_ELEMENTS (bgp->group, node, next, group))
peer_group_delete (group);
- list_delete (bgp->group);
for (ALL_LIST_ELEMENTS (bgp->peer, node, next, peer))
peer_delete (peer);
- list_delete (bgp->peer);
for (ALL_LIST_ELEMENTS (bgp->rsclient, node, next, peer))
peer_delete (peer);
+
+ if (bgp->peer_self) {
+ peer_delete(bgp->peer_self);
+ bgp->peer_self = NULL;
+ }
+
+ bgp_unlock(bgp); /* initial reference */
+
+ return 0;
+}
+
+void
+bgp_free(struct bgp *bgp)
+{
+ afi_t afi;
+ safi_t safi;
+
+ list_delete (bgp->group);
+ list_delete (bgp->peer);
list_delete (bgp->rsclient);
listnode_delete (bm->bgp, bgp);
@@ -2085,8 +2025,6 @@ bgp_delete (struct bgp *bgp)
XFREE (MTYPE_ROUTE_TABLE,bgp->rib[afi][safi]);
}
XFREE (MTYPE_BGP, bgp);
-
- return 0;
}
struct peer *
@@ -2222,7 +2160,7 @@ struct peer_flag_action
u_char peer_down;
};
-struct peer_flag_action peer_flag_action_list[] =
+static const struct peer_flag_action peer_flag_action_list[] =
{
{ PEER_FLAG_PASSIVE, 0, peer_change_reset },
{ PEER_FLAG_SHUTDOWN, 0, peer_change_reset },
@@ -2234,7 +2172,7 @@ struct peer_flag_action peer_flag_action_list[] =
{ 0, 0, 0 }
};
-struct peer_flag_action peer_af_flag_action_list[] =
+static const struct peer_flag_action peer_af_flag_action_list[] =
{
{ PEER_FLAG_NEXTHOP_SELF, 1, peer_change_reset_out },
{ PEER_FLAG_SEND_COMMUNITY, 1, peer_change_reset_out },
@@ -2255,14 +2193,14 @@ struct peer_flag_action peer_af_flag_action_list[] =
/* Proper action set. */
static int
-peer_flag_action_set (struct peer_flag_action *action_list, int size,
+peer_flag_action_set (const struct peer_flag_action *action_list, int size,
struct peer_flag_action *action, u_int32_t flag)
{
int i;
int found = 0;
int reset_in = 0;
int reset_out = 0;
- struct peer_flag_action *match = NULL;
+ const struct peer_flag_action *match = NULL;
/* Check peer's frag action. */
for (i = 0; i < size; i++)
@@ -3016,12 +2954,14 @@ peer_port_set (struct peer *peer, u_int16_t port)
return 0;
}
+#ifdef unused
int
peer_port_unset (struct peer *peer)
{
peer->port = BGP_PORT_DEFAULT;
return 0;
}
+#endif
/* neighbor weight. */
int
@@ -3929,7 +3869,7 @@ peer_aslist_unset (struct peer *peer,afi_t afi, safi_t safi, int direct)
}
static void
-peer_aslist_update ()
+peer_aslist_update (void)
{
afi_t afi;
safi_t safi;
@@ -5136,7 +5076,7 @@ bgp_init (void)
}
void
-bgp_terminate ()
+bgp_terminate (void)
{
struct bgp *bgp;
struct peer *peer;