mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 03:27:25 +00:00
bgpd: leave peer socket in non-blocking mode (mostly)
* bgpd: Rather than toggling socket in/out of non-block mode, just leave it in nonblocking mode. One exception is in bgp_notify which only happens just before close.
This commit is contained in:
parent
2c9fd7e072
commit
35398589cf
@ -150,6 +150,7 @@ bgp_accept (struct thread *thread)
|
|||||||
zlog_err ("[Error] BGP socket accept failed (%s)", safe_strerror (errno));
|
zlog_err ("[Error] BGP socket accept failed (%s)", safe_strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
set_nonblocking (bgp_sock);
|
||||||
|
|
||||||
if (BGP_DEBUG (events, EVENTS))
|
if (BGP_DEBUG (events, EVENTS))
|
||||||
zlog_debug ("[Event] BGP connection from host %s", inet_sutop (&su, buf));
|
zlog_debug ("[Event] BGP connection from host %s", inet_sutop (&su, buf));
|
||||||
|
@ -598,7 +598,6 @@ bgp_write (struct thread *thread)
|
|||||||
struct stream *s;
|
struct stream *s;
|
||||||
int num;
|
int num;
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
int write_errno;
|
|
||||||
|
|
||||||
/* Yes first of all get peer pointer. */
|
/* Yes first of all get peer pointer. */
|
||||||
peer = THREAD_ARG (thread);
|
peer = THREAD_ARG (thread);
|
||||||
@ -621,35 +620,23 @@ bgp_write (struct thread *thread)
|
|||||||
if (! s)
|
if (! s)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* XXX: FIXME, the socket should be NONBLOCK from the start
|
|
||||||
* status shouldnt need to be toggled on each write
|
|
||||||
*/
|
|
||||||
val = fcntl (peer->fd, F_GETFL, 0);
|
|
||||||
fcntl (peer->fd, F_SETFL, val|O_NONBLOCK);
|
|
||||||
|
|
||||||
/* Number of bytes to be sent. */
|
/* Number of bytes to be sent. */
|
||||||
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;
|
if (num < 0)
|
||||||
fcntl (peer->fd, F_SETFL, val);
|
|
||||||
if (num <= 0)
|
|
||||||
{
|
{
|
||||||
/* Partial write. */
|
/* need to try again */
|
||||||
if (write_errno == EWOULDBLOCK || write_errno == EAGAIN)
|
if (!ERRNO_IO_RETRY(errno))
|
||||||
break;
|
|
||||||
|
|
||||||
BGP_EVENT_ADD (peer, TCP_fatal_error);
|
BGP_EVENT_ADD (peer, TCP_fatal_error);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num != writenum)
|
if (num != writenum)
|
||||||
{
|
{
|
||||||
|
/* Partial write */
|
||||||
stream_forward_getp (s, num);
|
stream_forward_getp (s, num);
|
||||||
|
|
||||||
if (write_errno == EAGAIN)
|
|
||||||
break;
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -706,7 +693,7 @@ bgp_write (struct thread *thread)
|
|||||||
static int
|
static int
|
||||||
bgp_write_notify (struct peer *peer)
|
bgp_write_notify (struct peer *peer)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret, val;
|
||||||
u_char type;
|
u_char type;
|
||||||
struct stream *s;
|
struct stream *s;
|
||||||
|
|
||||||
@ -716,7 +703,10 @@ bgp_write_notify (struct peer *peer)
|
|||||||
return 0;
|
return 0;
|
||||||
assert (stream_get_endp (s) >= BGP_HEADER_SIZE);
|
assert (stream_get_endp (s) >= BGP_HEADER_SIZE);
|
||||||
|
|
||||||
/* I'm not sure fd is writable. */
|
/* Put socket in blocking mode. */
|
||||||
|
val = fcntl (peer->fd, F_GETFL, 0);
|
||||||
|
fcntl (peer->fd, F_SETFL, val & ~O_NONBLOCK);
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -2263,12 +2253,13 @@ 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_try (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)
|
||||||
{
|
{
|
||||||
if (errno == EAGAIN)
|
/* Transient error should retry */
|
||||||
|
if (nbytes == -2)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
plog_err (peer->log, "%s [Error] bgp_read_packet error: %s",
|
plog_err (peer->log, "%s [Error] bgp_read_packet error: %s",
|
||||||
|
Loading…
Reference in New Issue
Block a user