summaryrefslogtreecommitdiff
path: root/bgpd
diff options
context:
space:
mode:
authorpaul <paul>2004-05-01 08:44:08 +0000
committerpaul <paul>2004-05-01 08:44:08 +0000
commiteb821189d2778a93069fc1fc2f104db529ec5a1e (patch)
treea623d680931ee722fb946f56476f23efd1f13685 /bgpd
parenteb3f463aab7f09e6c1041bf779fd5752b038f847 (diff)
2004-05-01 Paul Jakma <paul@dishone.st>
* Revert the attempted clean-up of the dummy peer hack, reverts patchsets 435 (see 2004-02-17 below) and 456.
Diffstat (limited to 'bgpd')
-rw-r--r--bgpd/ChangeLog5
-rw-r--r--bgpd/bgp_advertise.c2
-rw-r--r--bgpd/bgp_fsm.c51
-rw-r--r--bgpd/bgp_network.c56
-rw-r--r--bgpd/bgp_packet.c111
-rw-r--r--bgpd/bgp_route.c3
-rw-r--r--bgpd/bgpd.c104
-rw-r--r--bgpd/bgpd.h42
8 files changed, 215 insertions, 159 deletions
diff --git a/bgpd/ChangeLog b/bgpd/ChangeLog
index 1e7d8e06..1eaea4e3 100644
--- a/bgpd/ChangeLog
+++ b/bgpd/ChangeLog
@@ -1,3 +1,8 @@
+2004-05-01 Paul Jakma <paul@dishone.st>
+
+ * Revert the attempted clean-up of the dummy peer hack, reverts
+ patchsets 435 (see 2004-02-17 below) and 456.
+
2004-04-16 rivo nurges <rix@estpak.ee>
* bgpd.h, bgp_debug.c: update cease subcodes to
diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c
index fc1324ac..4778a977 100644
--- a/bgpd/bgp_advertise.c
+++ b/bgpd/bgp_advertise.c
@@ -292,7 +292,7 @@ bgp_adj_out_unset (struct bgp_node *rn, struct peer *peer, struct prefix *p,
FIFO_ADD (&peer->sync[afi][safi]->withdraw, &adv->fifo);
/* Schedule packet write. */
- BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
else
{
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index ac25f151..3d8e9576 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -292,7 +292,7 @@ bgp_routeadv_timer (struct thread *thread)
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,21 +307,6 @@ bgp_uptime_reset (struct peer *peer)
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)
@@ -382,8 +367,12 @@ bgp_stop (struct peer *peer)
stream_reset (peer->work);
stream_fifo_clean (peer->obuf);
- /* Close of connections. */
- bgp_connection_stop (peer);
+ /* Close of file descriptor. */
+ if (peer->fd >= 0)
+ {
+ close (peer->fd);
+ peer->fd = -1;
+ }
/* Connection information. */
if (peer->su_local)
@@ -397,7 +386,7 @@ bgp_stop (struct peer *peer)
XFREE (MTYPE_SOCKUNION, peer->su_remote);
peer->su_remote = NULL;
}
-
+
/* Clear remote router-id. */
peer->remote_id.s_addr = 0;
@@ -488,13 +477,13 @@ bgp_stop_with_error (struct peer *peer)
int
bgp_connect_success (struct peer *peer)
{
- if (peer->fd_local < 0)
+ if (peer->fd < 0)
{
zlog_err ("bgp_connect_success peer's fd is negative value %d",
- peer->fd_local);
+ peer->fd);
return -1;
}
- BGP_READ_ON (peer->t_read, bgp_read, peer->fd_local);
+ BGP_READ_ON (peer->t_read, bgp_read, peer->fd);
/* bgp_getsockname (peer); */
@@ -532,29 +521,29 @@ bgp_start (struct peer *peer)
{
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;
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index e03831d0..aa369bc1 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -46,6 +46,7 @@ bgp_accept (struct thread *thread)
int accept_sock;
union sockunion su;
struct peer *peer;
+ struct peer *peer1;
struct bgp *bgp;
char buf[SU_ADDRSTRLEN];
@@ -72,12 +73,12 @@ bgp_accept (struct thread *thread)
zlog_info ("[Event] BGP connection from host %s", inet_sutop (&su, buf));
/* Check remote IP address */
- peer = peer_lookup (bgp, &su);
- if (! peer || peer->status == Idle)
+ peer1 = peer_lookup (bgp, &su);
+ if (! peer1 || peer1->status == Idle)
{
if (BGP_DEBUG (events, EVENTS))
{
- if (! peer)
+ if (! peer1)
zlog_info ("[Event] BGP connection IP address %s is not configured",
inet_sutop (&su, buf));
else
@@ -89,13 +90,30 @@ bgp_accept (struct thread *thread)
}
/* In case of peer is EBGP, we should set TTL for this connection. */
- if (peer_sort (peer) == BGP_PEER_EBGP)
- sockopt_ttl (peer->su.sa.sa_family, bgp_sock, peer->ttl);
+ if (peer_sort (peer1) == BGP_PEER_EBGP)
+ sockopt_ttl (peer1->su.sa.sa_family, bgp_sock, peer1->ttl);
if (! bgp)
- bgp = peer->bgp;
+ bgp = peer1->bgp;
+
+ /* Make dummy peer until read Open packet. */
+ if (BGP_DEBUG (events, EVENTS))
+ zlog_info ("[Event] Make dummy peer structure until read Open packet");
+
+ {
+ char buf[SU_ADDRSTRLEN + 1];
+
+ peer = peer_create_accept (bgp);
+ SET_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER);
+ peer->su = su;
+ peer->fd = bgp_sock;
+ peer->status = Active;
+ peer->local_id = peer1->local_id;
- peer->fd_accept = bgp_sock;
+ /* Make peer's address string. */
+ sockunion2str (&su, buf, SU_ADDRSTRLEN);
+ peer->host = strdup (buf);
+ }
BGP_EVENT_ADD (peer, TCP_connection_open);
@@ -115,7 +133,7 @@ bgp_bind (struct peer *peer)
strncpy ((char *)&ifreq.ifr_name, peer->ifname, sizeof (ifreq.ifr_name));
- ret = setsockopt (*peer->fd, SOL_SOCKET, SO_BINDTODEVICE,
+ ret = setsockopt (peer->fd, SOL_SOCKET, SO_BINDTODEVICE,
&ifreq, sizeof (ifreq));
if (ret < 0)
{
@@ -189,12 +207,12 @@ bgp_update_source (struct peer *peer)
if (! addr)
return;
- bgp_bind_address (*peer->fd, addr);
+ bgp_bind_address (peer->fd, addr);
}
/* Source is specified with IP address. */
if (peer->update_source)
- sockunion_bind (*peer->fd, peer->update_source, 0, peer->update_source);
+ sockunion_bind (peer->fd, peer->update_source, 0, peer->update_source);
}
/* BGP try to connect to the peer. */
@@ -204,16 +222,16 @@ bgp_connect (struct peer *peer)
unsigned int ifindex = 0;
/* Make socket for the peer. */
- *peer->fd = sockunion_socket (&peer->su);
- if (*peer->fd < 0)
+ peer->fd = sockunion_socket (&peer->su);
+ if (peer->fd < 0)
return -1;
/* If we can get socket for the peer, adjest TTL and make connection. */
if (peer_sort (peer) == BGP_PEER_EBGP)
- sockopt_ttl (peer->su.sa.sa_family, *peer->fd, peer->ttl);
+ sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl);
- sockopt_reuseaddr (*peer->fd);
- sockopt_reuseport (*peer->fd);
+ sockopt_reuseaddr (peer->fd);
+ sockopt_reuseport (peer->fd);
/* Bind socket. */
bgp_bind (peer);
@@ -228,10 +246,10 @@ bgp_connect (struct peer *peer)
if (BGP_DEBUG (events, EVENTS))
plog_info (peer->log, "%s [Event] Connect start to %s fd %d",
- peer->host, peer->host, *peer->fd);
+ peer->host, peer->host, peer->fd);
/* Connect to the remote peer. */
- return sockunion_connect (*peer->fd, &peer->su, htons (peer->port), ifindex);
+ return sockunion_connect (peer->fd, &peer->su, htons (peer->port), ifindex);
}
/* After TCP connection is established. Get local address and port. */
@@ -250,8 +268,8 @@ bgp_getsockname (struct peer *peer)
peer->su_remote = NULL;
}
- peer->su_local = sockunion_getsockname (*peer->fd);
- peer->su_remote = sockunion_getpeername (*peer->fd);
+ peer->su_local = sockunion_getsockname (peer->fd);
+ peer->su_remote = sockunion_getpeername (peer->fd);
bgp_nexthop_set (peer->su_local, peer->su_remote, &peer->nexthop, peer);
}
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index 7d921bed..48879f35 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -133,7 +133,7 @@ bgp_connect_check (struct peer *peer)
/* Check file descriptor. */
slen = sizeof (status);
- ret = getsockopt(*peer->fd, SOL_SOCKET, SO_ERROR, (void *) &status, &slen);
+ ret = getsockopt(peer->fd, SOL_SOCKET, SO_ERROR, (void *) &status, &slen);
/* If getsockopt is fail, this is fatal error. */
if (ret < 0)
@@ -238,6 +238,7 @@ bgp_update_packet (struct peer *peer, afi_t afi, safi_t safi)
bgp_packet_set_size (s);
packet = bgp_packet_dup (s);
bgp_packet_add (peer, packet);
+ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
stream_reset (s);
return packet;
}
@@ -394,7 +395,7 @@ bgp_default_update_send (struct peer *peer, struct attr *attr,
/* Add packet to the peer. */
bgp_packet_add (peer, packet);
- BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
void
@@ -468,7 +469,7 @@ bgp_default_withdraw_send (struct peer *peer, afi_t afi, safi_t safi)
/* Add packet to the peer. */
bgp_packet_add (peer, packet);
- BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
/* Get next packet to be written. */
@@ -574,7 +575,7 @@ bgp_write (struct thread *thread)
writenum = stream_get_endp (s) - stream_get_getp (s);
/* Call write() system call. */
- num = write (*peer->fd, STREAM_PNT (s), writenum);
+ num = write (peer->fd, STREAM_PNT (s), writenum);
write_errno = errno;
if (num <= 0)
{
@@ -644,7 +645,7 @@ bgp_write (struct thread *thread)
}
if (bgp_write_proceed (peer))
- BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
return 0;
}
@@ -664,7 +665,7 @@ bgp_write_notify (struct peer *peer)
assert (stream_get_endp (s) >= BGP_HEADER_SIZE);
/* I'm not sure fd is writable. */
- ret = writen (*peer->fd, STREAM_DATA (s), stream_get_endp (s));
+ ret = writen (peer->fd, STREAM_DATA (s), stream_get_endp (s));
if (ret <= 0)
{
bgp_stop (peer);
@@ -724,7 +725,7 @@ bgp_keepalive_send (struct peer *peer)
/* Add packet to the peer. */
bgp_packet_add (peer, s);
- BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
/* Make open packet and send it to the peer. */
@@ -779,7 +780,7 @@ bgp_open_send (struct peer *peer)
/* Add packet to the peer. */
bgp_packet_add (peer, s);
- BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
/* Send BGP notify packet with data potion. */
@@ -980,7 +981,7 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi,
/* Add packet to the peer. */
bgp_packet_add (peer, packet);
- BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
/* Send capability message to the peer. */
@@ -1047,13 +1048,14 @@ bgp_capability_send (struct peer *peer, afi_t afi, safi_t safi,
zlog_info ("%s send message type %d, length (incl. header) %d",
peer->host, BGP_MSG_CAPABILITY, length);
- BGP_WRITE_ON (peer->t_write, bgp_write, *peer->fd);
+ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
/* RFC1771 6.8 Connection collision detection. */
int
-bgp_collision_detect (struct peer *peer, struct in_addr remote_id)
+bgp_collision_detect (struct peer *new, struct in_addr remote_id)
{
+ struct peer *peer;
struct listnode *nn;
struct bgp *bgp;
@@ -1074,10 +1076,11 @@ bgp_collision_detect (struct peer *peer, struct in_addr remote_id)
{
/* Under OpenConfirm status, local peer structure already hold
remote router ID. */
- if ((peer->status == OpenConfirm)
- && ( ntohl(peer->remote_id.s_addr) == ntohl(remote_id.s_addr) )
- )
- {
+
+ if (peer != new
+ && (peer->status == OpenConfirm || peer->status == OpenSent)
+ && sockunion_same (&peer->su, &new->su))
+ {
/* 1. The BGP Identifier of the local system is compared to
the BGP Identifier of the remote system (as specified in
the OPEN message). */
@@ -1090,16 +1093,8 @@ bgp_collision_detect (struct peer *peer, struct in_addr remote_id)
already in the OpenConfirm state), and accepts BGP
connection initiated by the remote system. */
- if (peer->fd_local >= 0)
- {
- BGP_WRITE_OFF (peer->t_write);
- BGP_READ_OFF (peer->t_read);
- close (peer->fd_local);
- }
- peer->fd_local = -1;
- peer->fd = &peer->fd_accept;
-
- BGP_READ_ON (peer->t_read, bgp_read, *peer->fd);
+ if (peer->fd >= 0)
+ bgp_notify_send (peer, BGP_NOTIFY_CEASE, 0);
return 1;
}
else
@@ -1110,15 +1105,12 @@ bgp_collision_detect (struct peer *peer, struct in_addr remote_id)
existing one (the one that is already in the
OpenConfirm state). */
- if (peer->fd_accept >= 0)
- {
- close (peer->fd_accept);
- peer->fd_accept = -1;
- }
+ if (new->fd >= 0)
+ bgp_notify_send (new, BGP_NOTIFY_CEASE, 0);
return -1;
}
- }
- }
+ }
+ }
return 0;
}
@@ -1195,6 +1187,51 @@ bgp_open_receive (struct peer *peer, bgp_size_t size)
if (ret < 0)
return ret;
+ /* Hack part. */
+ if (CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER))
+ {
+ if (ret == 0 && realpeer->status != Active
+ && realpeer->status != OpenSent
+ && realpeer->status != OpenConfirm)
+ {
+ if (BGP_DEBUG (events, EVENTS))
+ zlog_info ("%s [Event] peer's status is %s close connection",
+ realpeer->host, LOOKUP (bgp_status_msg, peer->status));
+ return -1;
+ }
+
+ if (BGP_DEBUG (events, EVENTS))
+ zlog_info ("%s [Event] Transfer temporary BGP peer to existing one",
+ peer->host);
+
+ bgp_stop (realpeer);
+
+ /* Transfer file descriptor. */
+ realpeer->fd = peer->fd;
+ peer->fd = -1;
+
+ /* Transfer input buffer. */
+ stream_free (realpeer->ibuf);
+ realpeer->ibuf = peer->ibuf;
+ realpeer->packet_size = peer->packet_size;
+ peer->ibuf = NULL;
+
+ /* Transfer status. */
+ realpeer->status = peer->status;
+ bgp_stop (peer);
+
+ /* peer pointer change. Open packet send to neighbor. */
+ peer = realpeer;
+ bgp_open_send (peer);
+ if (peer->fd < 0)
+ {
+ zlog_err ("bgp_open_receive peer's fd is negative value %d",
+ peer->fd);
+ return -1;
+ }
+ BGP_READ_ON (peer->t_read, bgp_read, peer->fd);
+ }
+
/* remote router-id check. */
if (remote_id.s_addr == 0
|| ntohl (remote_id.s_addr) >= 0xe0000000
@@ -1994,7 +2031,7 @@ bgp_read_packet (struct peer *peer)
return 0;
/* Read packet from fd. */
- nbytes = stream_read_unblock (peer->ibuf, *peer->fd, readsize);
+ nbytes = stream_read_unblock (peer->ibuf, peer->fd, readsize);
/* If read byte is smaller than zero then error occured. */
if (nbytes < 0)
@@ -2013,7 +2050,7 @@ bgp_read_packet (struct peer *peer)
{
if (BGP_DEBUG (events, EVENTS))
plog_info (peer->log, "%s [Event] BGP connection closed fd %d",
- peer->host, *peer->fd);
+ peer->host, peer->fd);
BGP_EVENT_ADD (peer, TCP_connection_closed);
return -1;
}
@@ -2060,12 +2097,12 @@ bgp_read (struct thread *thread)
}
else
{
- if (*peer->fd < 0)
+ if (peer->fd < 0)
{
- zlog_err ("bgp_read peer's fd is negative value %d", *peer->fd);
+ zlog_err ("bgp_read peer's fd is negative value %d", peer->fd);
return -1;
}
- BGP_READ_ON (peer->t_read, bgp_read, *peer->fd);
+ BGP_READ_ON (peer->t_read, bgp_read, peer->fd);
}
/* Read packet header to determine type of the packet */
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 7025a8ff..32227cbb 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -4202,8 +4202,7 @@ route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
vty_out (vty, " (inaccessible)");
else if (binfo->igpmetric)
vty_out (vty, " (metric %d)", binfo->igpmetric);
- vty_out (vty, " from %s",
- sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
+ vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
else
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index ae8af9f4..e9d81de1 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -504,10 +504,11 @@ bgp_default_local_preference_unset (struct bgp *bgp)
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
@@ -683,11 +684,8 @@ peer_new ()
peer = XMALLOC (MTYPE_BGP_PEER, sizeof (struct peer));
memset (peer, 0, sizeof (struct peer));
- peer->fd = &peer->fd_local;
-
/* Set default value. */
- peer->fd_local = -1;
- peer->fd_accept = -1;
+ peer->fd = -1;
peer->v_start = BGP_INIT_START_TIMER;
peer->v_connect = BGP_DEFAULT_CONNECT_RETRY;
peer->v_asorig = BGP_DEFAULT_ASORIGINATE;
@@ -771,6 +769,19 @@ peer_create (union sockunion *su, struct bgp *bgp, as_t local_as,
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)
@@ -1799,8 +1810,9 @@ peer_lookup (struct bgp *bgp, union sockunion *su)
LIST_LOOP (bgp->peer, peer, nn)
{
- if (sockunion_same (&peer->su, su))
- return peer;
+ if (sockunion_same (&peer->su, su)
+ && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER))
+ return peer;
}
return NULL;
}
@@ -1819,25 +1831,27 @@ peer_lookup_with_open (union sockunion *su, as_t remote_as,
LIST_LOOP (bgp->peer, peer, nn)
{
- 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;
- }
+ 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;
+ }
}
LIST_LOOP (bgp->peer, peer, nn)
{
- 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;
- }
+ 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;
+ }
}
return NULL;
}
@@ -2264,24 +2278,22 @@ peer_ebgp_multihop_set (struct peer *peer, int ttl)
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;
}
@@ -2302,24 +2314,22 @@ peer_ebgp_multihop_unset (struct peer *peer)
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;
-
- peer->ttl = 1;
-
- if (*peer->fd >= 0)
- sockopt_ttl (peer->su.sa.sa_family,
- *peer->fd, peer->ttl);
- }
+ {
+ 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);
+ }
}
return 0;
}
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 6f22e53d..b10e6b67 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -256,29 +256,27 @@ struct peer
int ostatus;
/* Peer information */
- int *fd; /* connection in use: -> local||accept */
- int ttl; /* TTL of TCP connection to the peer. */
- int fd_local; /* locally initiated connection */
- int fd_accept; /* remote initiated/accepted connection */
- char *desc; /* Description of the peer. */
- unsigned short port; /* Destination port for peer */
- char *host; /* Printable address of the peer. */
- union sockunion su; /* Sockunion address of the peer. */
- time_t uptime; /* Last Up/Down time */
- time_t readtime; /* Last read time */
- time_t resettime; /* Last reset time */
+ int fd; /* File descriptor */
+ int ttl; /* TTL of TCP connection to the peer. */
+ char *desc; /* Description of the peer. */
+ unsigned short port; /* Destination port for peer */
+ char *host; /* Printable address of the peer. */
+ union sockunion su; /* Sockunion address of the peer. */
+ time_t uptime; /* Last Up/Down time */
+ time_t readtime; /* Last read time */
+ time_t resettime; /* Last reset time */
- unsigned int ifindex; /* ifindex of the BGP connection. */
- char *ifname; /* bind interface name. */
- char *update_if; /* interface to send from */
- union sockunion *update_source; /* sockunion to send from */
- struct zlog *log; /* log socket */
- u_char version; /* Peer BGP version. */
-
- union sockunion *su_local; /* Sockunion of local address. */
- union sockunion *su_remote; /* Sockunion of remote address. */
- int shared_network; /* Is this peer shared same network. */
- struct bgp_nexthop nexthop; /* Nexthop */
+ unsigned int ifindex; /* ifindex of the BGP connection. */
+ char *ifname; /* bind interface name. */
+ char *update_if;
+ union sockunion *update_source;
+ struct zlog *log;
+ u_char version; /* Peer BGP version. */
+
+ union sockunion *su_local; /* Sockunion of local address. */
+ union sockunion *su_remote; /* Sockunion of remote address. */
+ int shared_network; /* Is this peer shared same network. */
+ struct bgp_nexthop nexthop; /* Nexthop */
/* Peer address family configuration. */
u_char afc[AFI_MAX][SAFI_MAX];