[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.
This commit is contained in:
Willy Tarreau 2009-03-06 00:48:23 +01:00
parent 3a7d20781d
commit 604e83097f
3 changed files with 5 additions and 5 deletions

View 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) {

View 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) {

View 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;
}