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/bgp_fsm.c b/bgpd/bgp_fsm.c
index 3d8e957..ac25f15 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -292,7 +292,7 @@
peer->synctime = time (NULL);
- BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
BGP_TIMER_ON (peer->t_routeadv, bgp_routeadv_timer,
peer->v_routeadv);
@@ -307,6 +307,21 @@
peer->uptime = time (NULL);
}
+void
+bgp_connection_stop (struct peer *peer)
+{
+ if (peer->fd_local >= 0)
+ {
+ close (peer->fd_local);
+ peer->fd_local = -1;
+ }
+ if (peer->fd_accept >= 0)
+ {
+ close (peer->fd_accept);
+ peer->fd_accept = -1;
+ }
+}
+
/* Administrative BGP peer stop event. */
int
bgp_stop (struct peer *peer)
@@ -367,12 +382,8 @@
stream_reset (peer->work);
stream_fifo_clean (peer->obuf);
- /* Close of file descriptor. */
- if (peer->fd >= 0)
- {
- close (peer->fd);
- peer->fd = -1;
- }
+ /* Close of connections. */
+ bgp_connection_stop (peer);
/* Connection information. */
if (peer->su_local)
@@ -386,7 +397,7 @@
XFREE (MTYPE_SOCKUNION, peer->su_remote);
peer->su_remote = NULL;
}
-
+
/* Clear remote router-id. */
peer->remote_id.s_addr = 0;
@@ -477,13 +488,13 @@
int
bgp_connect_success (struct peer *peer)
{
- if (peer->fd < 0)
+ if (peer->fd_local < 0)
{
zlog_err ("bgp_connect_success peer's fd is negative value %d",
- peer->fd);
+ peer->fd_local);
return -1;
}
- BGP_READ_ON (peer->t_read, bgp_read, peer->fd);
+ BGP_READ_ON (peer->t_read, bgp_read, peer->fd_local);
/* bgp_getsockname (peer); */
@@ -521,29 +532,29 @@
{
case connect_error:
if (BGP_DEBUG (fsm, FSM))
- plog_info (peer->log, "%s [FSM] Connect error", peer->host);
+ plog_info (peer->log, "%s [FSM] Connect error", peer->host);
BGP_EVENT_ADD (peer, TCP_connection_open_failed);
break;
case connect_success:
if (BGP_DEBUG (fsm, FSM))
- plog_info (peer->log, "%s [FSM] Connect immediately success",
- peer->host);
+ plog_info (peer->log, "%s [FSM] Connect immediately success",
+ peer->host);
BGP_EVENT_ADD (peer, TCP_connection_open);
break;
case connect_in_progress:
/* To check nonblocking connect, we wait until socket is
readable or writable. */
if (BGP_DEBUG (fsm, FSM))
- plog_info (peer->log, "%s [FSM] Non blocking connect waiting result",
- peer->host);
- if (peer->fd < 0)
+ plog_info (peer->log, "%s [FSM] Non blocking connect waiting result",
+ peer->host);
+ if (*peer->fd < 0)
{
zlog_err ("bgp_start peer's fd is negative value %d",
- peer->fd);
+ *peer->fd);
return -1;
}
- BGP_READ_ON (peer->t_read, bgp_read, peer->fd);
- BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
+ BGP_READ_ON (peer->t_read, bgp_read, *peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
break;
}
return 0;