[BUG] interface binding: length must include the trailing zero
The interface length passed to the setsockopt(SO_BINDTODEVICE) must
include the trailing \0. Otherwise it will randomly fail.
diff --git a/src/backend.c b/src/backend.c
index d386805..f511b77 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -1723,7 +1723,7 @@
#ifdef SO_BINDTODEVICE
/* Note: this might fail if not CAP_NET_RAW */
if (s->srv->iface_name)
- setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, s->srv->iface_name, s->srv->iface_len);
+ setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, s->srv->iface_name, s->srv->iface_len + 1);
#endif
ret = tcpv4_bind_socket(fd, flags, &s->srv->source_addr, remote);
if (ret) {
@@ -1767,7 +1767,7 @@
#ifdef SO_BINDTODEVICE
/* Note: this might fail if not CAP_NET_RAW */
if (s->be->iface_name)
- setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, s->be->iface_name, s->be->iface_len);
+ setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, s->be->iface_name, s->be->iface_len + 1);
#endif
ret = tcpv4_bind_socket(fd, flags, &s->be->source_addr, remote);
if (ret) {
diff --git a/src/checks.c b/src/checks.c
index 1acff0d..37e0c29 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -594,7 +594,7 @@
/* Note: this might fail if not CAP_NET_RAW */
if (s->iface_name)
setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
- s->iface_name, s->iface_len);
+ s->iface_name, s->iface_len + 1);
#endif
ret = tcpv4_bind_socket(fd, flags, &s->source_addr, remote);
if (ret) {
@@ -625,7 +625,7 @@
/* Note: this might fail if not CAP_NET_RAW */
if (s->proxy->iface_name)
setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
- s->proxy->iface_name, s->proxy->iface_len);
+ s->proxy->iface_name, s->proxy->iface_len + 1);
#endif
ret = tcpv4_bind_socket(fd, flags, &s->proxy->source_addr, remote);
if (ret) {
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 78f63fc..2fb6a85 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -245,7 +245,7 @@
/* Note: this might fail if not CAP_NET_RAW */
if (listener->interface) {
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
- listener->interface, strlen(listener->interface)) == -1) {
+ listener->interface, strlen(listener->interface) + 1) == -1) {
msg = "cannot bind listener to device";
err |= ERR_WARN;
}