Mailing List Archive

svn commit: r1893497 - in /httpd/httpd/trunk: include/ap_mmn.h include/http_connection.h server/connection.c server/core.c server/mpm/event/event.c
Author: rpluem
Date: Tue Sep 21 20:03:52 2021
New Revision: 1893497

URL: http://svn.apache.org/viewvc?rev=1893497&view=rev
Log:
In case one of the pre_connection hooks causes the hook run to stop by an error
the pre_connection hook of the core module maybe did not run
(it is APR_HOOK_REALLY_LAST) and hence we missed to

- Put the socket in c->conn_config
- Setup core output and input filters
- Set socket options and timeouts

For calls of ap_run_pre_connection where this matters create a wrapper named
ap_pre_connection that ensures that this happens.

* include/ap_mmn.h: Bump minor version as we added new ap_pre_connection
function.

* include/http_connection.h: Declare ap_pre_connection prototype.

* server/connection.c: Make use of ap_pre_connection in ap_process_connection.

* server/core.c: Implement ap_pre_connection.

* server/mpm/event/event.c: Make use of ap_pre_connection.

Modified:
httpd/httpd/trunk/include/ap_mmn.h
httpd/httpd/trunk/include/http_connection.h
httpd/httpd/trunk/server/connection.c
httpd/httpd/trunk/server/core.c
httpd/httpd/trunk/server/mpm/event/event.c

Modified: httpd/httpd/trunk/include/ap_mmn.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_mmn.h?rev=1893497&r1=1893496&r2=1893497&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_mmn.h (original)
+++ httpd/httpd/trunk/include/ap_mmn.h Tue Sep 21 20:03:52 2021
@@ -680,6 +680,7 @@
* 20210531.3 (2.5.1-dev) Add hook child_stopping to get informed that a child
* is being shut down.
* 20210531.4 (2.5.1-dev) Add ap_create_connection
+ * 20210531.5 (2.5.1-dev) Add ap_pre_connection
*/

#define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
@@ -687,7 +688,7 @@
#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20210531
#endif
-#define MODULE_MAGIC_NUMBER_MINOR 4 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 5 /* 0...n */

/**
* Determine if the server's current MODULE_MAGIC_NUMBER is at least a

Modified: httpd/httpd/trunk/include/http_connection.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/http_connection.h?rev=1893497&r1=1893496&r2=1893497&view=diff
==============================================================================
--- httpd/httpd/trunk/include/http_connection.h (original)
+++ httpd/httpd/trunk/include/http_connection.h Tue Sep 21 20:03:52 2021
@@ -136,6 +136,21 @@ AP_DECLARE_HOOK(int,process_connection,(
AP_DECLARE_HOOK(int,pre_close_connection,(conn_rec *c))

/**
+ * This is a wrapper around ap_run_pre_connection. In case that
+ * ap_run_pre_connection returns an error it marks the connection as
+ * aborted and ensures that the basic connection setup normally done
+ * by the core module is done in case it was not done so far.
+ * @param c The connection on which the request has been received.
+ * Same as for the pre_connection hook.
+ * @param csd The mechanism on which this connection is to be read.
+ * Most times this will be a socket, but it is up to the module
+ * that accepts the request to determine the exact type.
+ * Same as for the pre_connection hook.
+ * @return The result of ap_run_pre_connection
+ */
+AP_DECLARE(int) ap_pre_connection(conn_rec *c, void *csd);
+
+/**
* Create a new server/incoming or client/outgoing/proxy connection
* @param p The pool from which to allocate the connection record
* @param server The server record to create the connection too.

Modified: httpd/httpd/trunk/server/connection.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/connection.c?rev=1893497&r1=1893496&r2=1893497&view=diff
==============================================================================
--- httpd/httpd/trunk/server/connection.c (original)
+++ httpd/httpd/trunk/server/connection.c Tue Sep 21 20:03:52 2021
@@ -225,13 +225,9 @@ AP_DECLARE(void) ap_lingering_close(conn

AP_CORE_DECLARE(void) ap_process_connection(conn_rec *c, void *csd)
{
- int rc;
ap_update_vhost_given_ip(c);

- rc = ap_run_pre_connection(c, csd);
- if (rc != OK && rc != DONE) {
- c->aborted = 1;
- }
+ ap_pre_connection(c, csd);

if (!c->aborted) {
ap_run_process_connection(c);

Modified: httpd/httpd/trunk/server/core.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/core.c?rev=1893497&r1=1893496&r2=1893497&view=diff
==============================================================================
--- httpd/httpd/trunk/server/core.c (original)
+++ httpd/httpd/trunk/server/core.c Tue Sep 21 20:03:52 2021
@@ -5557,6 +5557,31 @@ static int core_pre_connection(conn_rec
return DONE;
}

+AP_DECLARE(int) ap_pre_connection(conn_rec *c, void *csd)
+{
+ int rc = OK;
+
+ rc = ap_run_pre_connection(c, csd);
+ if (rc != OK && rc != DONE) {
+ c->aborted = 1;
+ /*
+ * In case we errored, the pre_connection hook of the core
+ * module maybe did not run (it is APR_HOOK_REALLY_LAST) and
+ * hence we missed to
+ *
+ * - Put the socket in c->conn_config
+ * - Setup core output and input filters
+ * - Set socket options and timeouts
+ *
+ * Hence call it in this case.
+ */
+ if (!ap_get_conn_socket(c)) {
+ core_pre_connection(c, csd);
+ }
+ }
+ return rc;
+}
+
AP_CORE_DECLARE(conn_rec *) ap_create_slave_connection(conn_rec *c)
{
apr_pool_t *pool;

Modified: httpd/httpd/trunk/server/mpm/event/event.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/event/event.c?rev=1893497&r1=1893496&r2=1893497&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/event/event.c (original)
+++ httpd/httpd/trunk/server/mpm/event/event.c Tue Sep 21 20:03:52 2021
@@ -1037,11 +1037,10 @@ static void process_socket(apr_thread_t

ap_update_vhost_given_ip(c);

- rc = ap_run_pre_connection(c, sock);
+ rc = ap_pre_connection(c, sock);
if (rc != OK && rc != DONE) {
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(00469)
"process_socket: connection aborted");
- c->aborted = 1;
}

/**