summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2020-07-17 14:37:55 -0300
committerRafael Zalamena <rzalamena@opensourcerouting.org>2020-07-28 12:34:12 -0300
commite1afb97fddcda0b19e684759fc239b1b0ae8517a (patch)
tree21dac975596171e5a05ab7306bf4e7e46017937e
parenta2032324643e70aa10e57c6de9a4cf9357d51592 (diff)
zebra,fpm: fix input handling
Two important fixes: * `stream_read_try` does a dirty trick and converts the `-1` return to `-2` when errno is `EAGAIN`, `EWOULDBLOCK` or `EINTR`. * Don't enable reads until the connection is complete. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
-rw-r--r--zebra/dplane_fpm_nl.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c
index 47d359149f..e5a0ebfd46 100644
--- a/zebra/dplane_fpm_nl.c
+++ b/zebra/dplane_fpm_nl.c
@@ -475,6 +475,13 @@ static int fpm_read(struct thread *t)
/* Let's ignore the input at the moment. */
rv = stream_read_try(fnc->ibuf, fnc->socket,
STREAM_WRITEABLE(fnc->ibuf));
+ /* We've got an interruption. */
+ if (rv == -2) {
+ /* Schedule next read. */
+ thread_add_read(fnc->fthread->master, fpm_read, fnc,
+ fnc->socket, &fnc->t_read);
+ return 0;
+ }
if (rv == 0) {
atomic_fetch_add_explicit(&fnc->counters.connection_closes, 1,
memory_order_relaxed);
@@ -486,10 +493,6 @@ static int fpm_read(struct thread *t)
return 0;
}
if (rv == -1) {
- if (errno == EAGAIN || errno == EWOULDBLOCK
- || errno == EINTR)
- return 0;
-
atomic_fetch_add_explicit(&fnc->counters.connection_errors, 1,
memory_order_relaxed);
zlog_warn("%s: connection failure: %s", __func__,
@@ -541,6 +544,10 @@ static int fpm_write(struct thread *t)
fnc->connecting = false;
+ /* Permit receiving messages now. */
+ thread_add_read(fnc->fthread->master, fpm_read, fnc,
+ fnc->socket, &fnc->t_read);
+
/*
* Walk the route tables to send old information before starting
* to send updated information.
@@ -672,8 +679,9 @@ static int fpm_connect(struct thread *t)
fnc->connecting = (errno == EINPROGRESS);
fnc->socket = sock;
- thread_add_read(fnc->fthread->master, fpm_read, fnc, sock,
- &fnc->t_read);
+ if (!fnc->connecting)
+ thread_add_read(fnc->fthread->master, fpm_read, fnc, sock,
+ &fnc->t_read);
thread_add_write(fnc->fthread->master, fpm_write, fnc, sock,
&fnc->t_write);