]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[BUG] interface binding: length must include the trailing zero
authorWilly Tarreau <w@1wt.eu>
Thu, 5 Mar 2009 23:48:23 +0000 (00:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 5 Mar 2009 23:48:23 +0000 (00:48 +0100)
The interface length passed to the setsockopt(SO_BINDTODEVICE) must
include the trailing \0. Otherwise it will randomly fail.

src/backend.c
src/checks.c
src/proto_tcp.c

index d386805ebb8956690ec86280e3d42f8fa819bf0e..f511b7799e2881f15e63b4ea34d8a322a7507076 100644 (file)
@@ -1723,7 +1723,7 @@ int connect_server(struct session *s)
 #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 @@ int connect_server(struct session *s)
 #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) {
index 1acff0d840199f52abfb7df0fec5a6ca3e7e7dda..37e0c296163222471baac6e7e4abc8c780aa1d31 100644 (file)
@@ -594,7 +594,7 @@ void process_chk(struct task *t, int *next)
                                        /* 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 @@ void process_chk(struct task *t, int *next)
                                        /* 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) {
index 78f63fcea422d7cedc45611eb8873d65f35091ba..2fb6a85c70e84c0eee3a88d2e86911036d140ec0 100644 (file)
@@ -245,7 +245,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
        /* 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;
                }