]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] session: make session_shutdown() an independant function
authorWilly Tarreau <w@1wt.eu>
Wed, 7 Sep 2011 21:01:56 +0000 (23:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Sep 2011 21:01:56 +0000 (23:01 +0200)
We already had the ability to kill a connection, but it was only
for the checks. Now we can do this for any session, and for this we
add a specific flag "K" to the logs.

doc/configuration.txt
include/proto/session.h
include/types/session.h
src/checks.c
src/log.c
src/session.c

index 2e2493e9f36ea70da9e3e99f73975699babea435..a8647467bb54236976611e02d097810d863617ba 100644 (file)
@@ -8872,6 +8872,8 @@ each of which has a special meaning :
         D : the session was killed by haproxy because the server was detected
             as down and was configured to kill all connections when going down.
 
+        K : the session was actively killed by an admin operating on haproxy.
+
         c : the client-side timeout expired while waiting for the client to
             send or receive data.
 
index 78a22226b5185199d96c59b51597cca3fd32bdf9..fb2b6a6605668b9afac34faecf4fbbe1fadeb0ba 100644 (file)
@@ -36,6 +36,8 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr);
 /* perform minimal intializations, report 0 in case of error, 1 if OK. */
 int init_session();
 
+/* kill a session and set the termination flags to <why> (one of SN_ERR_*) */
+void session_shutdown(struct session *session, int why);
 
 void session_process_counters(struct session *s);
 void sess_change_server(struct session *sess, struct server *newsrv);
index 605492489ccbb71456a6444c2986804ec1d5cd4a..a707aa52e145ef81cbddbc4fbde6f779d95b20cb 100644 (file)
@@ -56,7 +56,7 @@
 #define SN_REDIRECTABLE        0x00000400      /* set if this session is redirectable (GET or HEAD) */
 #define SN_TUNNEL      0x00000800      /* tunnel-mode session, nothing to catch after data */
 
-/* session termination conditions, bits values 0x1000 to 0x7000 (0-7 shift 12) */
+/* session termination conditions, bits values 0x1000 to 0x7000 (0-9 shift 12) */
 #define SN_ERR_NONE     0x00000000
 #define SN_ERR_CLITO   0x00001000      /* client time-out */
 #define SN_ERR_CLICL   0x00002000      /* client closed (read/write error) */
@@ -66,6 +66,7 @@
 #define SN_ERR_RESOURCE        0x00006000      /* the proxy encountered a lack of a local resources (fd, mem, ...) */
 #define SN_ERR_INTERNAL        0x00007000      /* the proxy encountered an internal error */
 #define SN_ERR_DOWN    0x00008000      /* the proxy killed a session because the backend became unavailable */
+#define SN_ERR_KILLED  0x00009000      /* the proxy killed a session because it was asked to do so */
 #define SN_ERR_MASK    0x0000f000      /* mask to get only session error flags */
 #define SN_ERR_SHIFT   12              /* bit shift */
 
index 6a102dfd4cdb39803748eeca83634fe62f8807a2..f0338d7cfc12e3925b1e5bc0883fda4fad72d686 100644 (file)
@@ -364,18 +364,9 @@ static void shutdown_sessions(struct server *srv)
 {
        struct session *session, *session_bck;
 
-       list_for_each_entry_safe(session, session_bck,
-                                &srv->actconns, by_srv) {
-               if (session->srv_conn == srv &&
-                   !(session->req->flags & (BF_SHUTW|BF_SHUTW_NOW))) {
-                               buffer_shutw_now(session->req);
-                               buffer_shutr_now(session->rep);
-                               session->task->nice = 1024;
-                               if (!(session->flags & SN_ERR_MASK))
-                                       session->flags |= SN_ERR_DOWN;
-                               task_wakeup(session->task, TASK_WOKEN_OTHER);
-               }
-       }
+       list_for_each_entry_safe(session, session_bck, &srv->actconns, by_srv)
+               if (session->srv_conn == srv)
+                       session_shutdown(session, SN_ERR_DOWN);
 }
 
 /* Sets server <s> down, notifies by all available means, recounts the
index d750349409b14698a1c1771c86b3b155af14fd8c..b62eedae7704878c781bb5f84a6f750105ed7c16 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -52,7 +52,7 @@ const char *monthname[12] = {
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 
-const char sess_term_cond[9]  = "-cCsSPRID";   /* normal, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down */
+const char sess_term_cond[10] = "-cCsSPRIDK";  /* normal, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed */
 const char sess_fin_state[8]  = "-RCHDLQT";    /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */
 
 /*
index 5032d889bb2327e1dec61c9dc2cf471334d2b0d3..d39da99655c6a68265bd04d4bcf8b912e2a85980 100644 (file)
@@ -2214,6 +2214,19 @@ void default_srv_error(struct session *s, struct stream_interface *si)
                s->flags |= fin;
 }
 
+/* kill a session and set the termination flags to <why> (one of SN_ERR_*) */
+void session_shutdown(struct session *session, int why)
+{
+       if (session->req->flags & (BF_SHUTW|BF_SHUTW_NOW))
+               return;
+
+       buffer_shutw_now(session->req);
+       buffer_shutr_now(session->rep);
+       session->task->nice = 1024;
+       if (!(session->flags & SN_ERR_MASK))
+               session->flags |= why;
+       task_wakeup(session->task, TASK_WOKEN_OTHER);
+}
 
 /************************************************************************/
 /*           All supported ACL keywords must be declared here.          */