[PATCH] ipcpd: Wait for buffer when writing to ETH device

  • From: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Fri, 7 Dec 2018 19:26:27 +0100

This will cause the Ethernet IPCP to wait for a free buffer when using
raw sockets to avoid packet drops when the network is congested.

Signed-off-by: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
---
 src/ipcpd/eth/eth.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/ipcpd/eth/eth.c b/src/ipcpd/eth/eth.c
index 3a749cf..ed7106d 100644
--- a/src/ipcpd/eth/eth.c
+++ b/src/ipcpd/eth/eth.c
@@ -380,6 +380,11 @@ static int eth_ipcp_send_frame(const uint8_t * dst_addr,
         uint8_t            cf = 0x03;
 #endif
         struct eth_frame * e_frame;
+#ifdef HAVE_RAW_SOCKETS
+        fd_set             fds;
+
+        FD_ZERO(&fds);
+#endif
 
         assert(frame);
 
@@ -424,13 +429,19 @@ static int eth_ipcp_send_frame(const uint8_t * dst_addr,
         }
 
 #elif defined(HAVE_RAW_SOCKETS)
+        FD_SET(eth_data.s_fd, &fds);
+        if (select(eth_data.s_fd + 1, NULL, &fds, NULL, NULL) < 0) {
+                log_dbg("Select() failed: %s.", strerror(errno));
+                return -1;
+        }
+        assert(FD_ISSET(eth_data.s_fd, &fds));
         if (sendto(eth_data.s_fd,
                    frame,
                    frame_len,
                    0,
                    (struct sockaddr *) &eth_data.device,
                    sizeof(eth_data.device)) <= 0) {
-                log_dbg("Failed to send message.");
+                log_dbg("Failed to send message: %s.", strerror(errno));
                 return -1;
         }
 #endif /* HAVE_NETMAP */
-- 
2.19.2


Other related posts:

  • » [PATCH] ipcpd: Wait for buffer when writing to ETH device - Dimitri Staessens