2004-02-17 Paul Jakma <paul@dishone.st>
* bgpd.h: (bgp_peer) add fd_local and fd_accept
file descriptor's, fd becomes a pointer to one of these.
* bgpd.c: (global) adjust for fact that fd is now a pointer.
(peer_create_accept) removed.
* bgp_route.c: (global) adjust for change of peer fd to pointer
* bgp_packet.c: (bgp_collision_detect) adjust and remove the
"replace with other peer" hack.
* bgp_network.c: (bgp_accept) Remove the dummy peer hack.
Update peer->fd_accept instead.
(global) Adjust fd references - now a pointer.
* bgp_fsm.c: (global) adjust peer fd to pointer.
(bgp_connection_stop) new function, to stop connection.
(global) adjust everything which closed peer fd to use
bgp_connection_stop().
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 3a12a27..f4c8f76 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -504,11 +504,10 @@
return 0;
}
-/* Peer comparison function for sorting. */
static int
peer_cmp (struct peer *p1, struct peer *p2)
{
- return sockunion_cmp (&p1->su, &p2->su);
+ return sockunion_cmp (&p1->su, &p2->su);
}
int
@@ -684,8 +683,11 @@
peer = XMALLOC (MTYPE_BGP_PEER, sizeof (struct peer));
memset (peer, 0, sizeof (struct peer));
+ peer->fd = &peer->fd_local;
+
/* Set default value. */
- peer->fd = -1;
+ peer->fd_local = -1;
+ peer->fd_accept = -1;
peer->v_start = BGP_INIT_START_TIMER;
peer->v_connect = BGP_DEFAULT_CONNECT_RETRY;
peer->v_asorig = BGP_DEFAULT_ASORIGINATE;
@@ -769,19 +771,6 @@
return peer;
}
-/* Make accept BGP peer. Called from bgp_accept (). */
-struct peer *
-peer_create_accept (struct bgp *bgp)
-{
- struct peer *peer;
-
- peer = peer_new ();
- peer->bgp = bgp;
- listnode_add_sort (bgp->peer, peer);
-
- return peer;
-}
-
/* Change peer's AS number. */
void
peer_as_change (struct peer *peer, as_t as)
@@ -1810,9 +1799,8 @@
LIST_LOOP (bgp->peer, peer, nn)
{
- if (sockunion_same (&peer->su, su)
- && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER))
- return peer;
+ if (sockunion_same (&peer->su, su))
+ return peer;
}
return NULL;
}
@@ -1831,27 +1819,25 @@
LIST_LOOP (bgp->peer, peer, nn)
{
- if (sockunion_same (&peer->su, su)
- && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER))
- {
- if (peer->as == remote_as
- && peer->remote_id.s_addr == remote_id->s_addr)
- return peer;
- if (peer->as == remote_as)
- *as = 1;
- }
+ if (sockunion_same (&peer->su, su))
+ {
+ if (peer->as == remote_as
+ && peer->remote_id.s_addr == remote_id->s_addr)
+ return peer;
+ if (peer->as == remote_as)
+ *as = 1;
+ }
}
LIST_LOOP (bgp->peer, peer, nn)
{
- if (sockunion_same (&peer->su, su)
- && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER))
- {
- if (peer->as == remote_as
- && peer->remote_id.s_addr == 0)
- return peer;
- if (peer->as == remote_as)
- *as = 1;
- }
+ if (sockunion_same (&peer->su, su))
+ {
+ if (peer->as == remote_as
+ && peer->remote_id.s_addr == 0)
+ return peer;
+ if (peer->as == remote_as)
+ *as = 1;
+ }
}
return NULL;
}
@@ -2278,22 +2264,24 @@
if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
{
- if (peer->fd >= 0 && peer_sort (peer) != BGP_PEER_IBGP)
- sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl);
+ if (*peer->fd >= 0 && peer_sort (peer) != BGP_PEER_IBGP)
+ sockopt_ttl (peer->su.sa.sa_family, *peer->fd,
+ peer->ttl);
}
else
{
group = peer->group;
LIST_LOOP (group->peer, peer, nn)
- {
- if (peer_sort (peer) == BGP_PEER_IBGP)
- continue;
+ {
+ if (peer_sort (peer) == BGP_PEER_IBGP)
+ continue;
- peer->ttl = group->conf->ttl;
+ peer->ttl = group->conf->ttl;
- if (peer->fd >= 0)
- sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl);
- }
+ if (*peer->fd >= 0)
+ sockopt_ttl (peer->su.sa.sa_family,
+ *peer->fd, peer->ttl);
+ }
}
return 0;
}
@@ -2314,22 +2302,24 @@
if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
{
- if (peer->fd >= 0 && peer_sort (peer) != BGP_PEER_IBGP)
- sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl);
+ if (*peer->fd >= 0 && peer_sort (peer) != BGP_PEER_IBGP)
+ sockopt_ttl (peer->su.sa.sa_family,
+ *peer->fd, peer->ttl);
}
else
{
group = peer->group;
LIST_LOOP (group->peer, peer, nn)
- {
- if (peer_sort (peer) == BGP_PEER_IBGP)
- continue;
+ {
+ if (peer_sort (peer) == BGP_PEER_IBGP)
+ continue;
- peer->ttl = 1;
-
- if (peer->fd >= 0)
- sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl);
- }
+ peer->ttl = 1;
+
+ if (*peer->fd >= 0)
+ sockopt_ttl (peer->su.sa.sa_family,
+ *peer->fd, peer->ttl);
+ }
}
return 0;
}