Browse Source

lib: --disable-bindlocal builds curl without local binding support

Daniel Stenberg 8 months ago
parent
commit
e67718eef7
8 changed files with 39 additions and 0 deletions
  1. 18 0
      configure.ac
  2. 4 0
      docs/CURL-DISABLE.md
  3. 4 0
      lib/cf-socket.c
  4. 4 0
      lib/if2ip.c
  5. 2 0
      lib/setopt.c
  6. 2 0
      lib/url.c
  7. 2 0
      lib/urldata.h
  8. 3 0
      tests/server/disabled.c

+ 18 - 0
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

+ 4 - 0
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.

+ 4 - 0
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);

+ 4 - 0
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 */

+ 2 - 0
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

+ 2 - 0
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 */

+ 2 - 0
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 */

+ 3 - 0
tests/server/disabled.c

@@ -37,6 +37,9 @@
 #include <stdio.h>
 
 static const char *disabled[]={
+#ifdef CURL_DISABLE_BINDLOCAL
+  "bindlocal",
+#endif
 #ifdef CURL_DISABLE_COOKIES
   "cookies",
 #endif