0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-03-22 06:17:04 +00:00

Socket: error hook is called from a function

This commit is contained in:
Maria Matejka 2024-09-23 14:17:02 +02:00
parent 9f27bfc6fc
commit d8df9c5d62

View File

@ -892,6 +892,12 @@ sk_setup(sock *s)
return 0; return 0;
} }
static void
sk_err_hook(sock *s, int e)
{
s->err_hook(s, e);
}
static int static int
sk_connect(sock *s) sk_connect(sock *s)
{ {
@ -936,7 +942,7 @@ sk_passive_connected(sock *s, int type)
if (fd < 0) if (fd < 0)
{ {
if ((errno != EINTR) && (errno != EAGAIN)) if ((errno != EINTR) && (errno != EAGAIN))
s->err_hook(s, errno); sk_err_hook(s, errno);
return 0; return 0;
} }
@ -1559,7 +1565,7 @@ sk_maybe_write(sock *s)
{ {
reset_tx_buffer(s); reset_tx_buffer(s);
/* EPIPE is just a connection close notification during TX */ /* EPIPE is just a connection close notification during TX */
s->err_hook(s, (errno != EPIPE) ? errno : 0); sk_err_hook(s, (errno != EPIPE) ? errno : 0);
return -1; return -1;
} }
return 0; return 0;
@ -1578,11 +1584,11 @@ sk_maybe_write(sock *s)
if (e < 0) if (e < 0)
{ {
s->err = ssh_get_error(s->ssh->session); s->err = ssh_get_error(s->ssh->session);
s->err_hook(s, ssh_get_error_code(s->ssh->session)); sk_err_hook(s, ssh_get_error_code(s->ssh->session));
reset_tx_buffer(s); reset_tx_buffer(s);
/* EPIPE is just a connection close notification during TX */ /* EPIPE is just a connection close notification during TX */
s->err_hook(s, (errno != EPIPE) ? errno : 0); sk_err_hook(s, (errno != EPIPE) ? errno : 0);
return -1; return -1;
} }
s->ttx += e; s->ttx += e;
@ -1604,7 +1610,7 @@ sk_maybe_write(sock *s)
if (errno != EINTR && errno != EAGAIN) if (errno != EINTR && errno != EAGAIN)
{ {
reset_tx_buffer(s); reset_tx_buffer(s);
s->err_hook(s, errno); sk_err_hook(s, errno);
return -1; return -1;
} }
@ -1724,7 +1730,7 @@ sk_read_ssh(sock *s)
if (ssh_channel_is_eof(s->ssh->channel) != 0) if (ssh_channel_is_eof(s->ssh->channel) != 0)
{ {
/* The remote side is closing the connection */ /* The remote side is closing the connection */
s->err_hook(s, 0); sk_err_hook(s, 0);
return 0; return 0;
} }
@ -1745,13 +1751,13 @@ sk_read_ssh(sock *s)
if (ssh_channel_is_eof(s->ssh->channel) != 0) if (ssh_channel_is_eof(s->ssh->channel) != 0)
{ {
/* The remote side is closing the connection */ /* The remote side is closing the connection */
s->err_hook(s, 0); sk_err_hook(s, 0);
} }
} }
else else
{ {
s->err = ssh_get_error(s->ssh->session); s->err = ssh_get_error(s->ssh->session);
s->err_hook(s, ssh_get_error_code(s->ssh->session)); sk_err_hook(s, ssh_get_error_code(s->ssh->session));
} }
return 0; /* No data is available on the socket */ return 0; /* No data is available on the socket */
@ -1779,15 +1785,15 @@ sk_read_noflush(sock *s, int revents)
if (c < 0) if (c < 0)
{ {
if (errno != EINTR && errno != EAGAIN) if (errno != EINTR && errno != EAGAIN)
s->err_hook(s, errno); sk_err_hook(s, errno);
else if (errno == EAGAIN && !(revents & POLLIN)) else if (errno == EAGAIN && !(revents & POLLIN))
{ {
log(L_ERR "Got EAGAIN from read when revents=%x (without POLLIN)", revents); log(L_ERR "Got EAGAIN from read when revents=%x (without POLLIN)", revents);
s->err_hook(s, 0); sk_err_hook(s, 0);
} }
} }
else if (!c) else if (!c)
s->err_hook(s, 0); sk_err_hook(s, 0);
else else
{ {
s->rpos += c; s->rpos += c;
@ -1812,7 +1818,7 @@ sk_read_noflush(sock *s, int revents)
if (e < 0) if (e < 0)
{ {
if (errno != EINTR && errno != EAGAIN) if (errno != EINTR && errno != EAGAIN)
s->err_hook(s, errno); sk_err_hook(s, errno);
return 0; return 0;
} }
@ -1841,7 +1847,7 @@ sk_write_noflush(sock *s)
if (sk_connect(s) >= 0 || errno == EISCONN) if (sk_connect(s) >= 0 || errno == EISCONN)
sk_tcp_connected(s); sk_tcp_connected(s);
else if (errno != EINTR && errno != EAGAIN && errno != EINPROGRESS) else if (errno != EINTR && errno != EAGAIN && errno != EINPROGRESS)
s->err_hook(s, errno); sk_err_hook(s, errno);
return 0; return 0;
} }
@ -1859,7 +1865,7 @@ sk_write_noflush(sock *s)
case SSH_ERROR: case SSH_ERROR:
s->err = ssh_get_error(s->ssh->session); s->err = ssh_get_error(s->ssh->session);
s->err_hook(s, ssh_get_error_code(s->ssh->session)); sk_err_hook(s, ssh_get_error_code(s->ssh->session));
break; break;
} }
return 0; return 0;
@ -1902,7 +1908,7 @@ sk_err(sock *s, int revents)
se = 0; se = 0;
} }
s->err_hook(s, se); sk_err_hook(s, se);
tmp_flush(); tmp_flush();
} }