]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] cleanup set_session_backend by using pre-computed analysers
authorWilly Tarreau <w@1wt.eu>
Sun, 16 Aug 2009 20:37:44 +0000 (22:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 16 Aug 2009 20:37:44 +0000 (22:37 +0200)
Analyser bitmaps are now stored in the frontend and backend, and
combined at configuration time. That way, set_session_backend()
does not need to perform any protocol-specific combinations.

include/types/proxy.h
src/cfgparse.c
src/client.c
src/proxy.c

index 19d1b044b894c2aa6d78f21388b01274376bb6f1..69505e605995315eff4367e0b6786fbe3ad22078 100644 (file)
@@ -150,6 +150,7 @@ struct proxy {
        int state;                              /* proxy state */
        int options;                            /* PR_O_REDISP, PR_O_TRANSP, ... */
        int options2;                           /* PR_O2_* */
+       unsigned int fe_req_ana, be_req_ana;    /* bitmap of common request protocol analysers for the frontend and backend */
        int mode;                               /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */
        struct sockaddr_in dispatch_addr;       /* the default address to connect to */
        union {
index 996ddc1bff48cb7783c8970c52cb3056165b6524..cddca1e845b2130b867981d3e05cb0f0778cb0a3 100644 (file)
@@ -4139,6 +4139,29 @@ int check_config_validity()
                        newsrv = newsrv->next;
                }
 
+               if (curproxy->cap & PR_CAP_FE) {
+                       if (curproxy->tcp_req.inspect_delay ||
+                           !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
+                               curproxy->fe_req_ana |= AN_REQ_INSPECT;
+
+                       if (curproxy->mode == PR_MODE_HTTP)
+                               curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE;
+
+                       /* both TCP and HTTP must check switching rules */
+                       curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES;
+               }
+
+               if (curproxy->cap & PR_CAP_BE) {
+                       if (curproxy->mode == PR_MODE_HTTP)
+                               curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
+
+                       /* If the backend does requires RDP cookie persistence, we have to
+                        * enable the corresponding analyser.
+                        */
+                       if (curproxy->options2 & PR_O2_RDPC_PRST)
+                               curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE;
+               }
+
                /* adjust this proxy's listeners */
                listener = curproxy->listen;
                while (listener) {
@@ -4150,11 +4173,7 @@ int check_config_validity()
                        listener->accept = event_accept;
                        listener->private = curproxy;
                        listener->handler = process_session;
-                       /* both TCP and HTTP must check switching rules */
-                       listener->analysers |= AN_REQ_SWITCHING_RULES;
-
-                       if (curproxy->mode == PR_MODE_HTTP)
-                               listener->analysers |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE;
+                       listener->analysers |= curproxy->fe_req_ana;
 
                        /* smart accept mode is automatic in HTTP mode */
                        if ((curproxy->options2 & PR_O2_SMARTACC) ||
@@ -4162,10 +4181,6 @@ int check_config_validity()
                             !(curproxy->no_options2 & PR_O2_SMARTACC)))
                                listener->options |= LI_O_NOQUICKACK;
 
-                       if (curproxy->tcp_req.inspect_delay ||
-                           !LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules))
-                               listener->analysers |= AN_REQ_INSPECT;
-
                        /* We want the use_backend and default_backend rules to apply */
                        listener = listener->next;
                }
index b2e7d782a30cfdbce93b18e68fd90eba165e487d..c4891686acdf872e164022ff6d3238a996930871 100644 (file)
@@ -401,6 +401,7 @@ int event_accept(int fd) {
                /* activate default analysers enabled for this listener */
                s->req->analysers = l->analysers;
 
+               /* note: this should not happen anymore since there's always at least the switching rules */
                if (!s->req->analysers)
                        buffer_write_ena(s->req);  /* don't wait to establish connection */
 
index 4e75b59b40615675ebf5c3e6e98de30f8978a838..7dce8c8352e141bff7d9e78c82c5e3e53b3c682f 100644 (file)
@@ -667,21 +667,12 @@ int session_set_backend(struct session *s, struct proxy *be)
                hdr_idx_init(&s->txn.hdr_idx);
        }
 
-       /* If we're switching from TCP mode to HTTP mode, we need to
-        * enable several analysers on the backend.
+       /* We want to enable the backend-specific analysers except those which
+        * were already run as part of the frontend/listener. Note that it would
+        * be more reliable to store the list of analysers that have been run,
+        * but what we do here is OK for now.
         */
-       if (unlikely(s->fe->mode != PR_MODE_HTTP && s->be->mode == PR_MODE_HTTP)) {
-               /* We want to wait for a complete HTTP request and process the
-                * backend parts.
-                */
-               s->req->analysers |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_BE | AN_REQ_HTTP_INNER;
-       }
-
-       /* If the backend does requires RDP cookie persistence, we have to
-        * enable the corresponding analyser.
-        */
-       if (s->be->options2 & PR_O2_RDPC_PRST)
-               s->req->analysers |= AN_REQ_PRST_RDP_COOKIE;
+       s->req->analysers |= be->be_req_ana & ~(s->listener->analysers);
 
        return 1;
 }