]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra,fpm: fix input handling
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Fri, 17 Jul 2020 17:37:55 +0000 (14:37 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 28 Jul 2020 15:34:12 +0000 (12:34 -0300)
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>
zebra/dplane_fpm_nl.c

index 47d359149f91dcd9d8dbd5b578828504b295357e..e5a0ebfd46a77e331281331693dbeda319a188b1 100644 (file)
@@ -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);