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().
This commit is contained in:
paul 2004-02-17 19:45:10 +00:00
parent 5de5bbf107
commit 6ad23f05e3
7 changed files with 174 additions and 208 deletions

View File

@ -1,8 +1,25 @@
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().
2003-12-23 Krzysztof Oledzki <oleq@ans.pl> 2003-12-23 Krzysztof Oledzki <oleq@ans.pl>
* bgp_network.c: drop privs on error cases * bgp_network.c: drop privs on error cases
2003-08-11 kunihiro <kunihiro@zebra.org 2003-08-11 kunihiro <kunihiro@zebra.org>
* bgp_route{,map}.c: Extend 'set ip next-hop' in route-maps with * bgp_route{,map}.c: Extend 'set ip next-hop' in route-maps with
ability to specify 'peer-address' rather than IP. ability to specify 'peer-address' rather than IP.

View File

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

View File

@ -46,7 +46,6 @@ bgp_accept (struct thread *thread)
int accept_sock; int accept_sock;
union sockunion su; union sockunion su;
struct peer *peer; struct peer *peer;
struct peer *peer1;
struct bgp *bgp; struct bgp *bgp;
char buf[SU_ADDRSTRLEN]; char buf[SU_ADDRSTRLEN];
@ -73,12 +72,12 @@ bgp_accept (struct thread *thread)
zlog_info ("[Event] BGP connection from host %s", inet_sutop (&su, buf)); zlog_info ("[Event] BGP connection from host %s", inet_sutop (&su, buf));
/* Check remote IP address */ /* Check remote IP address */
peer1 = peer_lookup (bgp, &su); peer = peer_lookup (bgp, &su);
if (! peer1 || peer1->status == Idle) if (! peer || peer->status == Idle)
{ {
if (BGP_DEBUG (events, EVENTS)) if (BGP_DEBUG (events, EVENTS))
{ {
if (! peer1) if (! peer)
zlog_info ("[Event] BGP connection IP address %s is not configured", zlog_info ("[Event] BGP connection IP address %s is not configured",
inet_sutop (&su, buf)); inet_sutop (&su, buf));
else else
@ -90,30 +89,13 @@ bgp_accept (struct thread *thread)
} }
/* In case of peer is EBGP, we should set TTL for this connection. */ /* In case of peer is EBGP, we should set TTL for this connection. */
if (peer_sort (peer1) == BGP_PEER_EBGP) if (peer_sort (peer) == BGP_PEER_EBGP)
sockopt_ttl (peer1->su.sa.sa_family, bgp_sock, peer1->ttl); sockopt_ttl (peer->su.sa.sa_family, bgp_sock, peer->ttl);
if (! bgp) if (! bgp)
bgp = peer1->bgp; bgp = peer->bgp;
/* Make dummy peer until read Open packet. */ peer->fd_accept = bgp_sock;
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;
/* Make peer's address string. */
sockunion2str (&su, buf, SU_ADDRSTRLEN);
peer->host = strdup (buf);
}
BGP_EVENT_ADD (peer, TCP_connection_open); BGP_EVENT_ADD (peer, TCP_connection_open);
@ -133,7 +115,7 @@ bgp_bind (struct peer *peer)
strncpy ((char *)&ifreq.ifr_name, peer->ifname, sizeof (ifreq.ifr_name)); 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)); &ifreq, sizeof (ifreq));
if (ret < 0) if (ret < 0)
{ {
@ -207,12 +189,12 @@ bgp_update_source (struct peer *peer)
if (! addr) if (! addr)
return; return;
bgp_bind_address (peer->fd, addr); bgp_bind_address (*peer->fd, addr);
} }
/* Source is specified with IP address. */ /* Source is specified with IP address. */
if (peer->update_source) 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. */ /* BGP try to connect to the peer. */
@ -222,16 +204,16 @@ bgp_connect (struct peer *peer)
unsigned int ifindex = 0; unsigned int ifindex = 0;
/* Make socket for the peer. */ /* Make socket for the peer. */
peer->fd = sockunion_socket (&peer->su); *peer->fd = sockunion_socket (&peer->su);
if (peer->fd < 0) if (*peer->fd < 0)
return -1; return -1;
/* If we can get socket for the peer, adjest TTL and make connection. */ /* If we can get socket for the peer, adjest TTL and make connection. */
if (peer_sort (peer) == BGP_PEER_EBGP) 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_reuseaddr (*peer->fd);
sockopt_reuseport (peer->fd); sockopt_reuseport (*peer->fd);
/* Bind socket. */ /* Bind socket. */
bgp_bind (peer); bgp_bind (peer);
@ -246,10 +228,10 @@ bgp_connect (struct peer *peer)
if (BGP_DEBUG (events, EVENTS)) if (BGP_DEBUG (events, EVENTS))
plog_info (peer->log, "%s [Event] Connect start to %s fd %d", 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. */ /* 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. */ /* After TCP connection is established. Get local address and port. */
@ -268,8 +250,8 @@ bgp_getsockname (struct peer *peer)
peer->su_remote = NULL; peer->su_remote = NULL;
} }
peer->su_local = sockunion_getsockname (peer->fd); peer->su_local = sockunion_getsockname (*peer->fd);
peer->su_remote = sockunion_getpeername (peer->fd); peer->su_remote = sockunion_getpeername (*peer->fd);
bgp_nexthop_set (peer->su_local, peer->su_remote, &peer->nexthop, peer); bgp_nexthop_set (peer->su_local, peer->su_remote, &peer->nexthop, peer);
} }

View File

@ -133,7 +133,7 @@ bgp_connect_check (struct peer *peer)
/* Check file descriptor. */ /* Check file descriptor. */
slen = sizeof (status); 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 getsockopt is fail, this is fatal error. */
if (ret < 0) if (ret < 0)
@ -238,7 +238,6 @@ bgp_update_packet (struct peer *peer, afi_t afi, safi_t safi)
bgp_packet_set_size (s); bgp_packet_set_size (s);
packet = bgp_packet_dup (s); packet = bgp_packet_dup (s);
bgp_packet_add (peer, packet); bgp_packet_add (peer, packet);
BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
stream_reset (s); stream_reset (s);
return packet; return packet;
} }
@ -395,7 +394,7 @@ bgp_default_update_send (struct peer *peer, struct attr *attr,
/* Add packet to the peer. */ /* Add packet to the peer. */
bgp_packet_add (peer, packet); 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 void
@ -469,7 +468,7 @@ bgp_default_withdraw_send (struct peer *peer, afi_t afi, safi_t safi)
/* Add packet to the peer. */ /* Add packet to the peer. */
bgp_packet_add (peer, packet); 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. */ /* Get next packet to be written. */
@ -575,7 +574,7 @@ bgp_write (struct thread *thread)
writenum = stream_get_endp (s) - stream_get_getp (s); writenum = stream_get_endp (s) - stream_get_getp (s);
/* Call write() system call. */ /* Call write() system call. */
num = write (peer->fd, STREAM_PNT (s), writenum); num = write (*peer->fd, STREAM_PNT (s), writenum);
write_errno = errno; write_errno = errno;
if (num <= 0) if (num <= 0)
{ {
@ -645,7 +644,7 @@ bgp_write (struct thread *thread)
} }
if (bgp_write_proceed (peer)) 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; return 0;
} }
@ -665,7 +664,7 @@ bgp_write_notify (struct peer *peer)
assert (stream_get_endp (s) >= BGP_HEADER_SIZE); assert (stream_get_endp (s) >= BGP_HEADER_SIZE);
/* I'm not sure fd is writable. */ /* 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) if (ret <= 0)
{ {
bgp_stop (peer); bgp_stop (peer);
@ -725,7 +724,7 @@ bgp_keepalive_send (struct peer *peer)
/* Add packet to the peer. */ /* Add packet to the peer. */
bgp_packet_add (peer, s); 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. */ /* Make open packet and send it to the peer. */
@ -780,7 +779,7 @@ bgp_open_send (struct peer *peer)
/* Add packet to the peer. */ /* Add packet to the peer. */
bgp_packet_add (peer, s); 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. */ /* Send BGP notify packet with data potion. */
@ -981,7 +980,7 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi,
/* Add packet to the peer. */ /* Add packet to the peer. */
bgp_packet_add (peer, packet); 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. */ /* Send capability message to the peer. */
@ -1048,14 +1047,13 @@ bgp_capability_send (struct peer *peer, afi_t afi, safi_t safi,
zlog_info ("%s send message type %d, length (incl. header) %d", zlog_info ("%s send message type %d, length (incl. header) %d",
peer->host, BGP_MSG_CAPABILITY, length); 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. */ /* RFC1771 6.8 Connection collision detection. */
int int
bgp_collision_detect (struct peer *new, struct in_addr remote_id) bgp_collision_detect (struct peer *peer, struct in_addr remote_id)
{ {
struct peer *peer;
struct listnode *nn; struct listnode *nn;
struct bgp *bgp; struct bgp *bgp;
@ -1076,11 +1074,10 @@ bgp_collision_detect (struct peer *new, struct in_addr remote_id)
{ {
/* Under OpenConfirm status, local peer structure already hold /* Under OpenConfirm status, local peer structure already hold
remote router ID. */ remote router ID. */
if ((peer->status == OpenConfirm)
if (peer != new && ( ntohl(peer->remote_id.s_addr) == ntohl(remote_id.s_addr) )
&& (peer->status == OpenConfirm || peer->status == OpenSent) )
&& sockunion_same (&peer->su, &new->su)) {
{
/* 1. The BGP Identifier of the local system is compared to /* 1. The BGP Identifier of the local system is compared to
the BGP Identifier of the remote system (as specified in the BGP Identifier of the remote system (as specified in
the OPEN message). */ the OPEN message). */
@ -1093,8 +1090,16 @@ bgp_collision_detect (struct peer *new, struct in_addr remote_id)
already in the OpenConfirm state), and accepts BGP already in the OpenConfirm state), and accepts BGP
connection initiated by the remote system. */ connection initiated by the remote system. */
if (peer->fd >= 0) if (peer->fd_local >= 0)
bgp_notify_send (peer, BGP_NOTIFY_CEASE, 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);
return 1; return 1;
} }
else else
@ -1105,11 +1110,14 @@ bgp_collision_detect (struct peer *new, struct in_addr remote_id)
existing one (the one that is already in the existing one (the one that is already in the
OpenConfirm state). */ OpenConfirm state). */
if (new->fd >= 0) if (peer->fd_accept >= 0)
bgp_notify_send (new, BGP_NOTIFY_CEASE, 0); {
close (peer->fd_accept);
peer->fd_accept = -1;
}
return -1; return -1;
} }
} }
} }
return 0; return 0;
} }
@ -1187,51 +1195,6 @@ bgp_open_receive (struct peer *peer, bgp_size_t size)
if (ret < 0) if (ret < 0)
return ret; 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. */ /* remote router-id check. */
if (remote_id.s_addr == 0 if (remote_id.s_addr == 0
|| ntohl (remote_id.s_addr) >= 0xe0000000 || ntohl (remote_id.s_addr) >= 0xe0000000
@ -2031,7 +1994,7 @@ bgp_read_packet (struct peer *peer)
return 0; return 0;
/* Read packet from fd. */ /* 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 read byte is smaller than zero then error occured. */
if (nbytes < 0) if (nbytes < 0)
@ -2050,7 +2013,7 @@ bgp_read_packet (struct peer *peer)
{ {
if (BGP_DEBUG (events, EVENTS)) if (BGP_DEBUG (events, EVENTS))
plog_info (peer->log, "%s [Event] BGP connection closed fd %d", 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); BGP_EVENT_ADD (peer, TCP_connection_closed);
return -1; return -1;
} }
@ -2097,12 +2060,12 @@ bgp_read (struct thread *thread)
} }
else 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; 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 */ /* Read packet header to determine type of the packet */

View File

@ -4202,7 +4202,8 @@ route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
vty_out (vty, " (inaccessible)"); vty_out (vty, " (inaccessible)");
else if (binfo->igpmetric) else if (binfo->igpmetric)
vty_out (vty, " (metric %d)", 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)) if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
vty_out (vty, " (%s)", inet_ntoa (attr->originator_id)); vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
else else

View File

@ -504,7 +504,6 @@ bgp_default_local_preference_unset (struct bgp *bgp)
return 0; return 0;
} }
/* Peer comparison function for sorting. */
static int static int
peer_cmp (struct peer *p1, struct peer *p2) peer_cmp (struct peer *p1, struct peer *p2)
{ {
@ -684,8 +683,11 @@ peer_new ()
peer = XMALLOC (MTYPE_BGP_PEER, sizeof (struct peer)); peer = XMALLOC (MTYPE_BGP_PEER, sizeof (struct peer));
memset (peer, 0, sizeof (struct peer)); memset (peer, 0, sizeof (struct peer));
peer->fd = &peer->fd_local;
/* Set default value. */ /* Set default value. */
peer->fd = -1; peer->fd_local = -1;
peer->fd_accept = -1;
peer->v_start = BGP_INIT_START_TIMER; peer->v_start = BGP_INIT_START_TIMER;
peer->v_connect = BGP_DEFAULT_CONNECT_RETRY; peer->v_connect = BGP_DEFAULT_CONNECT_RETRY;
peer->v_asorig = BGP_DEFAULT_ASORIGINATE; peer->v_asorig = BGP_DEFAULT_ASORIGINATE;
@ -769,19 +771,6 @@ peer_create (union sockunion *su, struct bgp *bgp, as_t local_as,
return peer; 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. */ /* Change peer's AS number. */
void void
peer_as_change (struct peer *peer, as_t as) peer_as_change (struct peer *peer, as_t as)
@ -1810,9 +1799,8 @@ peer_lookup (struct bgp *bgp, union sockunion *su)
LIST_LOOP (bgp->peer, peer, nn) LIST_LOOP (bgp->peer, peer, nn)
{ {
if (sockunion_same (&peer->su, su) if (sockunion_same (&peer->su, su))
&& ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER)) return peer;
return peer;
} }
return NULL; return NULL;
} }
@ -1831,27 +1819,25 @@ peer_lookup_with_open (union sockunion *su, as_t remote_as,
LIST_LOOP (bgp->peer, peer, nn) LIST_LOOP (bgp->peer, peer, nn)
{ {
if (sockunion_same (&peer->su, su) if (sockunion_same (&peer->su, su))
&& ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER)) {
{ if (peer->as == remote_as
if (peer->as == remote_as && peer->remote_id.s_addr == remote_id->s_addr)
&& peer->remote_id.s_addr == remote_id->s_addr) return peer;
return peer; if (peer->as == remote_as)
if (peer->as == remote_as) *as = 1;
*as = 1; }
}
} }
LIST_LOOP (bgp->peer, peer, nn) LIST_LOOP (bgp->peer, peer, nn)
{ {
if (sockunion_same (&peer->su, su) if (sockunion_same (&peer->su, su))
&& ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER)) {
{ if (peer->as == remote_as
if (peer->as == remote_as && peer->remote_id.s_addr == 0)
&& peer->remote_id.s_addr == 0) return peer;
return peer; if (peer->as == remote_as)
if (peer->as == remote_as) *as = 1;
*as = 1; }
}
} }
return NULL; return NULL;
} }
@ -2278,22 +2264,24 @@ peer_ebgp_multihop_set (struct peer *peer, int ttl)
if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
{ {
if (peer->fd >= 0 && peer_sort (peer) != BGP_PEER_IBGP) if (*peer->fd >= 0 && peer_sort (peer) != BGP_PEER_IBGP)
sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl); sockopt_ttl (peer->su.sa.sa_family, *peer->fd,
peer->ttl);
} }
else else
{ {
group = peer->group; group = peer->group;
LIST_LOOP (group->peer, peer, nn) LIST_LOOP (group->peer, peer, nn)
{ {
if (peer_sort (peer) == BGP_PEER_IBGP) if (peer_sort (peer) == BGP_PEER_IBGP)
continue; continue;
peer->ttl = group->conf->ttl; peer->ttl = group->conf->ttl;
if (peer->fd >= 0) if (*peer->fd >= 0)
sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl); sockopt_ttl (peer->su.sa.sa_family,
} *peer->fd, peer->ttl);
}
} }
return 0; return 0;
} }
@ -2314,22 +2302,24 @@ peer_ebgp_multihop_unset (struct peer *peer)
if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
{ {
if (peer->fd >= 0 && peer_sort (peer) != BGP_PEER_IBGP) if (*peer->fd >= 0 && peer_sort (peer) != BGP_PEER_IBGP)
sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl); sockopt_ttl (peer->su.sa.sa_family,
*peer->fd, peer->ttl);
} }
else else
{ {
group = peer->group; group = peer->group;
LIST_LOOP (group->peer, peer, nn) LIST_LOOP (group->peer, peer, nn)
{ {
if (peer_sort (peer) == BGP_PEER_IBGP) if (peer_sort (peer) == BGP_PEER_IBGP)
continue; continue;
peer->ttl = 1; peer->ttl = 1;
if (peer->fd >= 0) if (*peer->fd >= 0)
sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl); sockopt_ttl (peer->su.sa.sa_family,
} *peer->fd, peer->ttl);
}
} }
return 0; return 0;
} }

View File

@ -256,27 +256,29 @@ struct peer
int ostatus; int ostatus;
/* Peer information */ /* Peer information */
int fd; /* File descriptor */ int *fd; /* connection in use: -> local||accept */
int ttl; /* TTL of TCP connection to the peer. */ int ttl; /* TTL of TCP connection to the peer. */
char *desc; /* Description of the peer. */ int fd_local; /* locally initiated connection */
unsigned short port; /* Destination port for peer */ int fd_accept; /* remote initiated/accepted connection */
char *host; /* Printable address of the peer. */ char *desc; /* Description of the peer. */
union sockunion su; /* Sockunion address of the peer. */ unsigned short port; /* Destination port for peer */
time_t uptime; /* Last Up/Down time */ char *host; /* Printable address of the peer. */
time_t readtime; /* Last read time */ union sockunion su; /* Sockunion address of the peer. */
time_t resettime; /* Last reset time */ 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. */ unsigned int ifindex; /* ifindex of the BGP connection. */
char *ifname; /* bind interface name. */ char *ifname; /* bind interface name. */
char *update_if; char *update_if; /* interface to send from */
union sockunion *update_source; union sockunion *update_source; /* sockunion to send from */
struct zlog *log; struct zlog *log; /* log socket */
u_char version; /* Peer BGP version. */ u_char version; /* Peer BGP version. */
union sockunion *su_local; /* Sockunion of local address. */ union sockunion *su_local; /* Sockunion of local address. */
union sockunion *su_remote; /* Sockunion of remote address. */ union sockunion *su_remote; /* Sockunion of remote address. */
int shared_network; /* Is this peer shared same network. */ int shared_network; /* Is this peer shared same network. */
struct bgp_nexthop nexthop; /* Nexthop */ struct bgp_nexthop nexthop; /* Nexthop */
/* Peer address family configuration. */ /* Peer address family configuration. */
u_char afc[AFI_MAX][SAFI_MAX]; u_char afc[AFI_MAX][SAFI_MAX];