arrfab / rpms / httpd

Forked from rpms/httpd 5 years ago
Clone
59234c
diff --git a/include/ap_listen.h b/include/ap_listen.h
59234c
index 58c2574..1a53292 100644
59234c
--- a/include/ap_listen.h
59234c
+++ b/include/ap_listen.h
59234c
@@ -137,6 +137,9 @@ AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd, void *dummy
59234c
 AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd, void *dummy, const char *arg);
59234c
 AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
59234c
                                                 int argc, char *const argv[]);
59234c
+AP_DECLARE_NONSTD(const char *) ap_set_freelistener(cmd_parms *cmd, void *dummy,
59234c
+                                                    int argc, char *const argv[]);
59234c
+
59234c
 AP_DECLARE_NONSTD(const char *) ap_set_send_buffer_size(cmd_parms *cmd, void *dummy,
59234c
                                                         const char *arg);
59234c
 AP_DECLARE_NONSTD(const char *) ap_set_receive_buffer_size(cmd_parms *cmd,
59234c
@@ -150,6 +153,8 @@ AP_INIT_TAKE1("ListenCoresBucketsRatio", ap_set_listencbratio, NULL, RSRC_CONF,
59234c
   "Ratio between the number of CPU cores (online) and the number of listeners buckets"), \
59234c
 AP_INIT_TAKE_ARGV("Listen", ap_set_listener, NULL, RSRC_CONF, \
59234c
   "A port number or a numeric IP address and a port number, and an optional protocol"), \
59234c
+AP_INIT_TAKE_ARGV("ListenFree", ap_set_freelistener, NULL, RSRC_CONF, \
59234c
+  "A port number or a numeric IP address and a port number, and an optional protocol"), \
59234c
 AP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \
59234c
   "Send buffer size in bytes"), \
59234c
 AP_INIT_TAKE1("ReceiveBufferSize", ap_set_receive_buffer_size, NULL, \
59234c
diff --git a/server/listen.c b/server/listen.c
59234c
index 1a6c1d3..d375fee 100644
59234c
--- a/server/listen.c
59234c
+++ b/server/listen.c
59234c
@@ -63,6 +63,7 @@ static int ap_listenbacklog;
59234c
 static int ap_listencbratio;
59234c
 static int send_buffer_size;
59234c
 static int receive_buffer_size;
59234c
+static int ap_listenfreebind;
59234c
 #ifdef HAVE_SYSTEMD
59234c
 static int use_systemd = -1;
59234c
 #endif
59234c
@@ -162,6 +163,21 @@ static apr_status_t make_sock(apr_pool_t *p, ap_listen_rec *server, int do_bind_
59234c
     }
59234c
 #endif
59234c
 
59234c
+
59234c
+#if defined(APR_SO_FREEBIND)
59234c
+    if (ap_listenfreebind) {
59234c
+        if (apr_socket_opt_set(s, APR_SO_FREEBIND, one) < 0) {
59234c
+            stat = apr_get_netos_error();
59234c
+            ap_log_perror(APLOG_MARK, APLOG_CRIT, stat, p, APLOGNO(02182)
59234c
+                          "make_sock: apr_socket_opt_set: "
59234c
+                          "error setting APR_SO_FREEBIND");
59234c
+            apr_socket_close(s);
59234c
+            return stat;
59234c
+       }
59234c
+   }
59234c
+#endif
59234c
+
59234c
+
59234c
     if (do_bind_listen) {
59234c
 #if APR_HAVE_IPV6
59234c
         if (server->bind_addr->family == APR_INET6) {
59234c
@@ -956,6 +972,7 @@ AP_DECLARE(void) ap_listen_pre_config(void)
59234c
     }
59234c
 }
59234c
 
59234c
+
59234c
 AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
59234c
                                                 int argc, char *const argv[])
59234c
 {
59234c
@@ -1016,6 +1033,14 @@ AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
59234c
     return alloc_listener(cmd->server->process, host, port, proto, NULL);
59234c
 }
59234c
 
59234c
+AP_DECLARE_NONSTD(const char *) ap_set_freelistener(cmd_parms *cmd, void *dummy,
59234c
+                                                    int argc,
59234c
+                                                    char *const argv[])
59234c
+{
59234c
+    ap_listenfreebind = 1;
59234c
+    return ap_set_listener(cmd, dummy, argc, argv);
59234c
+}
59234c
+
59234c
 AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd,
59234c
                                                      void *dummy,
59234c
                                                      const char *arg)
59234c
diff --git a/docs/manual/mod/mpm_common.html.en b/docs/manual/mod/mpm_common.html.en
59234c
index 5d688e4..eb66c19 100644
59234c
--- a/docs/manual/mod/mpm_common.html.en
59234c
+++ b/docs/manual/mod/mpm_common.html.en
59234c
@@ -42,6 +42,7 @@ more than one multi-processing module (MPM)
59234c
 
  • EnableExceptionHook
  • 59234c
     
  • GracefulShutdownTimeout
  • 59234c
     
  • Listen
  • 59234c
    +
  • ListenFree
  • 59234c
     
  • ListenBackLog
  • 59234c
     
  • ListenCoresBucketsRatio
  • 59234c
     
  • MaxConnectionsPerChild
  • 59234c
    @@ -233,6 +234,31 @@ discussion of the Address already in use error message,
    59234c
     including other causes.
    59234c
     
    59234c
     
    59234c
    +
    59234c
    +
    top
    59234c
    +
    59234c
    +
    59234c
    +Description:IP addresses and ports that the server
    59234c
    +listens to. Doesn't require IP address to be up
    59234c
    +Syntax:ListenFree [IP-address:]portnumber [protocol]
    59234c
    +Context:server config
    59234c
    +Status:MPM
    59234c
    +Module:event, worker, prefork, mpm_winnt, mpm_netware, mpmt_os2
    59234c
    +Compatibility:This directive is currently available only in Red Hat Enterprise Linux
    59234c
    +
    59234c
    +    

    The ListenFree directive is

    59234c
    +    identical to the Listen directive. 
    59234c
    +    The only difference is in the usage of the IP_FREEBIND socket 
    59234c
    +    option, which is enabled by default with ListenFree. 
    59234c
    +    If IP_FREEBIND is enabled, it allows httpd to bind to an IP
    59234c
    +    address that is nonlocal or does not (yet) exist. This allows httpd to 
    59234c
    +    listen on a socket without requiring the underlying network interface
    59234c
    +    or the specified dynamic IP address to be up at the time when httpd
    59234c
    +    is trying to bind to it.
    59234c
    +    

    59234c
    +
    59234c
    +
    59234c
    +
    59234c
     
    top
    59234c
     
    59234c
     
    59234c