diff --git a/socket.c b/socket.c index 74549b7c..9b778d7e 100644 --- a/socket.c +++ b/socket.c @@ -500,6 +500,17 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) { uwsgi_nuclear_blast(); } +#ifdef __linux__ +#ifdef IP_FREEBIND + if (uwsgi.freebind) { + if (setsockopt(serverfd, SOL_IP, IP_FREEBIND, (const void *) &uwsgi.freebind, sizeof(int)) < 0) { + uwsgi_error("setsockopt()"); + uwsgi_nuclear_blast(); + } + } +#endif +#endif + if (uwsgi.reuse_port) { #ifdef SO_REUSEPORT if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEPORT, (const void *) &uwsgi.reuse_port, sizeof(int)) < 0) { diff --git a/uwsgi.c b/uwsgi.c index 3cf38ce2..02eb87fb 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -57,6 +57,9 @@ static struct option long_base_options[] = { {"abstract-socket", no_argument, 0, 'a'}, {"chmod-socket", optional_argument, 0, 'C'}, {"chown-socket", required_argument, 0, LONG_ARGS_CHOWN_SOCKET}, +#ifdef __linux__ + {"freebind", no_argument, &uwsgi.freebind, 1}, +#endif {"map-socket", required_argument, 0, LONG_ARGS_MAP_SOCKET}, {"chmod", optional_argument, 0, 'C'}, #ifdef UWSGI_THREADING diff --git a/uwsgi.h b/uwsgi.h index afc73ab2..1570da20 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1095,6 +1095,10 @@ struct uwsgi_server { struct timeval start_tv; int abstract_socket; +#ifdef __linux__ + int freebind; +#endif + int chmod_socket; char *chown_socket; mode_t chmod_socket_value;