diff --git a/configure.ac b/configure.ac index 0c57cde73b..e551514b42 100644 --- a/configure.ac +++ b/configure.ac @@ -4124,6 +4124,24 @@ AS_HELP_STRING([--disable-mime],[Disable mime API support]), AC_MSG_RESULT(yes) ) +dnl ************************************************************ +dnl disable bindlocal +dnl +AC_MSG_CHECKING([whether to support binding connections locally]) +AC_ARG_ENABLE(bindlocal, +AS_HELP_STRING([--enable-bindlocal],[Enable local binding support]) +AS_HELP_STRING([--disable-bindlocal],[Disable local binding support]), +[ case "$enableval" in + no) + AC_MSG_RESULT(no) + AC_DEFINE(CURL_DISABLE_BINDLOCAL, 1, [disable local binding support]) + ;; + *) AC_MSG_RESULT(yes) + ;; + esac ], + AC_MSG_RESULT(yes) +) + dnl ************************************************************ dnl disable form API support dnl diff --git a/docs/CURL-DISABLE.md b/docs/CURL-DISABLE.md index e3098e8623..83186ff5d2 100644 --- a/docs/CURL-DISABLE.md +++ b/docs/CURL-DISABLE.md @@ -4,6 +4,10 @@ Disable support for Alt-Svc: HTTP headers. +## `CURL_DISABLE_BINDLOCAL` + +Disable support for binding the local end of connections. + ## `CURL_DISABLE_COOKIES` Disable support for HTTP cookies. diff --git a/lib/cf-socket.c b/lib/cf-socket.c index db40f19120..860474190a 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -390,6 +390,7 @@ void Curl_sndbufset(curl_socket_t sockfd) } #endif +#ifndef CURL_DISABLE_BINDLOCAL static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, curl_socket_t sockfd, int af, unsigned int scope) { @@ -648,6 +649,7 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn, return CURLE_INTERFACE_FAILED; } +#endif /* * verifyconnect() returns TRUE if the connect really has happened. @@ -1018,6 +1020,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, } } +#ifndef CURL_DISABLE_BINDLOCAL /* possibly bind the local end to an IP, interface or port */ if(ctx->addr.family == AF_INET #ifdef ENABLE_IPV6 @@ -1035,6 +1038,7 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf, goto out; } } +#endif /* set socket non-blocking */ (void)curlx_nonblock(ctx->sock, TRUE); diff --git a/lib/if2ip.c b/lib/if2ip.c index 6bf0ce16f7..5249f6cc7e 100644 --- a/lib/if2ip.c +++ b/lib/if2ip.c @@ -92,6 +92,8 @@ unsigned int Curl_ipv6_scope(const struct sockaddr *sa) } #endif +#ifndef CURL_DISABLE_BINDLOCAL + #if defined(HAVE_GETIFADDRS) if2ip_result_t Curl_if2ip(int af, @@ -254,3 +256,5 @@ if2ip_result_t Curl_if2ip(int af, } #endif + +#endif /* CURL_DISABLE_BINDLOCAL */ diff --git a/lib/setopt.c b/lib/setopt.c index d213b61b1f..75e8cc4a3f 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -1886,6 +1886,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) result = Curl_setstropt(&data->set.str[STRING_DEVICE], va_arg(param, char *)); break; +#ifndef CURL_DISABLE_BINDLOCAL case CURLOPT_LOCALPORT: /* * Set what local port to bind the socket to when performing an operation. @@ -1904,6 +1905,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) return CURLE_BAD_FUNCTION_ARGUMENT; data->set.localportrange = curlx_sltous(arg); break; +#endif case CURLOPT_GSSAPI_DELEGATION: /* * GSS-API credential delegation bitmask diff --git a/lib/url.c b/lib/url.c index 3c9bee1d73..32a64c81d2 100644 --- a/lib/url.c +++ b/lib/url.c @@ -1590,8 +1590,10 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) if(!conn->localdev) goto error; } +#ifndef CURL_DISABLE_BINDLOCAL conn->localportrange = data->set.localportrange; conn->localport = data->set.localport; +#endif /* the close socket stuff needs to be copied to the connection struct as it may live on without (this specific) Curl_easy */ diff --git a/lib/urldata.h b/lib/urldata.h index 9a1afe106f..6651147d20 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -1639,10 +1639,12 @@ struct UserDefined { curl_off_t postfieldsize; /* if POST, this might have a size to use instead of strlen(), and then the data *may* be binary (contain zero bytes) */ +#ifndef CURL_DISABLE_BINDLOCAL unsigned short localport; /* local port number to bind to */ unsigned short localportrange; /* number of additional port numbers to test in case the 'localport' one can't be bind()ed */ +#endif curl_write_callback fwrite_func; /* function that stores the output */ curl_write_callback fwrite_header; /* function that stores headers */ curl_write_callback fwrite_rtp; /* function that stores interleaved RTP */ diff --git a/tests/server/disabled.c b/tests/server/disabled.c index 635191a3eb..a04b355020 100644 --- a/tests/server/disabled.c +++ b/tests/server/disabled.c @@ -37,6 +37,9 @@ #include static const char *disabled[]={ +#ifdef CURL_DISABLE_BINDLOCAL + "bindlocal", +#endif #ifdef CURL_DISABLE_COOKIES "cookies", #endif