[PATCH] ipcpd: Filter fqueue events in packet handlers

  • From: Dimitri Staessens <dimitri@ouroboros.rocks>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Sat, 25 Jan 2020 12:38:38 +0100

The eth, udp and local IPCPs were not filtering out the event types
from the flow, causing some reads when there are no packets in the
queue. The types are now also organized as flags so they can be
filtered more quickly if needed.

Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
---
 include/ouroboros/fqueue.h | 10 +++++-----
 src/ipcpd/eth/eth.c        |  3 +++
 src/ipcpd/local/main.c     |  3 +++
 src/ipcpd/udp/main.c       |  4 ++++
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/include/ouroboros/fqueue.h b/include/ouroboros/fqueue.h
index 793ff25..797e3af 100644
--- a/include/ouroboros/fqueue.h
+++ b/include/ouroboros/fqueue.h
@@ -29,11 +29,11 @@
 #include <time.h>
 
 enum fqtype {
-        FLOW_PKT = 0,
-        FLOW_DOWN,
-        FLOW_UP,
-        FLOW_ALLOC,
-        FLOW_DEALLOC
+        FLOW_PKT     = (1 << 0),
+        FLOW_DOWN    = (1 << 1),
+        FLOW_UP      = (1 << 2),
+        FLOW_ALLOC   = (1 << 3),
+        FLOW_DEALLOC = (1 << 4)
 };
 
 struct flow_set;
diff --git a/src/ipcpd/eth/eth.c b/src/ipcpd/eth/eth.c
index 9cc1184..daeb9be 100644
--- a/src/ipcpd/eth/eth.c
+++ b/src/ipcpd/eth/eth.c
@@ -1035,6 +1035,9 @@ static void * eth_ipcp_packet_writer(void * o)
         while (true) {
                 fevent(eth_data.np1_flows, fq, NULL);
                 while ((fd = fqueue_next(fq)) >= 0) {
+                        if (fqueue_type(fq) != FLOW_PKT)
+                                continue
+;
                         if (ipcp_flow_read(fd, &sdb)) {
                                 log_dbg("Bad read from fd %d.", fd);
                                 continue;
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c
index 28a7c32..009a3fd 100644
--- a/src/ipcpd/local/main.c
+++ b/src/ipcpd/local/main.c
@@ -110,6 +110,9 @@ static void * ipcp_local_packet_loop(void * o)
                 fevent(local_data.flows, local_data.fq, NULL);
 
                 while ((fd = fqueue_next(local_data.fq)) >= 0) {
+                        if (fqueue_type(local_data.fq) != FLOW_PKT)
+                                continue;
+
                         idx = local_flow_read(fd);
                         if (idx < 0)
                                 continue;
diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c
index a444e95..1f0bebf 100644
--- a/src/ipcpd/udp/main.c
+++ b/src/ipcpd/udp/main.c
@@ -520,6 +520,10 @@ static void * ipcp_udp_packet_writer(void * o)
                         struct shm_du_buff * sdb;
                         uint8_t *            buf;
                         uint16_t             len;
+
+                        if (fqueue_type(fq) != FLOW_PKT)
+                                continue;
+
                         if (ipcp_flow_read(fd, &sdb)) {
                                 log_dbg("Bad read from fd %d.", fd);
                                 continue;
-- 
2.25.0


Other related posts:

  • » [PATCH] ipcpd: Filter fqueue events in packet handlers - Dimitri Staessens