From 933aa5ab479732d84b3331ef4638dd9be07695b2 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Fri, 7 Dec 2018 19:26:27 +0100 Subject: ipcpd: Wait for buffer when writing to Eth device 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 Signed-off-by: Sander Vrijders --- src/ipcpd/eth/eth.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/ipcpd/eth/eth.c') diff --git a/src/ipcpd/eth/eth.c b/src/ipcpd/eth/eth.c index 3a749cf7..f9691626 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,20 @@ 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 *) ð_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 */ -- cgit v1.2.3