]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: --disable-bindlocal builds curl without local binding support
authorDaniel Stenberg <daniel@haxx.se>
Thu, 17 Aug 2023 12:36:30 +0000 (14:36 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 17 Aug 2023 15:17:59 +0000 (17:17 +0200)
configure.ac
docs/CURL-DISABLE.md
lib/cf-socket.c
lib/if2ip.c
lib/setopt.c
lib/url.c
lib/urldata.h
tests/server/disabled.c

index 0c57cde73bc0aebd41cdc3896904bf0256d58246..e551514b42690a780935a9254816939bc7f61e19 100644 (file)
@@ -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
index e3098e8623fc9d46212314544d86cfdb6c7a7761..83186ff5d2091e7cdc65811931989c0a1476e820 100644 (file)
@@ -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.
index db40f19120abe014f4e8cc25003f984723f2826a..860474190ae2c3f42d07682ba90fbf25cd9624d8 100644 (file)
@@ -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);
index 6bf0ce16f795a2e9ca8f7e06494a7915854ee374..5249f6cc7eb45c1e81bd382b1959423c42a509ae 100644 (file)
@@ -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 */
index d213b61b1fa39f79e96a46dab84b3f0be2978dc8..75e8cc4a3f816b9c15f4a1da0bf0d3d2a16dbe4d 100644 (file)
@@ -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
index 3c9bee1d73a9141b6cea39cefd32c476563142f6..32a64c81d2e4a76472f623fb873b9de7cf652e29 100644 (file)
--- 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 */
index 9a1afe106f2364c39174720f84d721f19885f400..6651147d20d06b10b066ce46becd6f0d9909e6b0 100644 (file)
@@ -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 */
index 635191a3eb6ae48f69f8d21fc66036459ab5128d..a04b355020bd2d740f15e474dd2f27dc5e53f011 100644 (file)
@@ -37,6 +37,9 @@
 #include <stdio.h>
 
 static const char *disabled[]={
+#ifdef CURL_DISABLE_BINDLOCAL
+  "bindlocal",
+#endif
 #ifdef CURL_DISABLE_COOKIES
   "cookies",
 #endif