pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/41714?usp=email )
Change subject: gsmtap_util: Set sink_fd RCVBUF and SNDBUF to minimum ......................................................................
gsmtap_util: Set sink_fd RCVBUF and SNDBUF to minimum
We never transmit anything over the socket, nor are interested in reading from it. We are only interested in having the socket open to avoid ICMP errors. Hence, set the buffers to the minimum to save some memory which we won't ever need/use.
Change-Id: Icfbc24ff679898496666d224d49e1ff06ddffda8 --- M src/core/gsmtap_util.c 1 file changed, 9 insertions(+), 3 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve fixeria: Looks good to me, approved Jenkins Builder: Verified
diff --git a/src/core/gsmtap_util.c b/src/core/gsmtap_util.c index b21de74..3fab7ac 100644 --- a/src/core/gsmtap_util.c +++ b/src/core/gsmtap_util.c @@ -325,12 +325,18 @@ return rc;
if (osmo_sockaddr_is_local((struct sockaddr *)&ss, ss_len) == 1) { - rc = osmo_sock_init_sa((struct sockaddr *)&ss, SOCK_DGRAM, + int zero = 0; + int fd = osmo_sock_init_sa((struct sockaddr *)&ss, SOCK_DGRAM, IPPROTO_UDP, OSMO_SOCK_F_BIND | OSMO_SOCK_F_UDP_REUSEADDR); - if (rc >= 0) - return rc; + if (fd < 0) + return fd; + /* We never read nor write from this socket, so tell the kernel + * to set the RCVBUF/SNDBUF to the minimum possible value */ + setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero)); + setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &zero, sizeof(zero)); + return fd; }
return -ENODEV;