[MINOR] tarpit: close the connection if the client closes.

There's no point at maintaining an open tarpitted connection
if the client has left.
This commit is contained in:
Willy Tarreau 2006-09-03 10:47:37 +02:00
parent 2272dc14bb
commit 08fa2e37fd
3 changed files with 26 additions and 12 deletions

View File

@ -1742,7 +1742,7 @@ HTTP, each of which has a special meaning :
server had already finished. server had already finished.
T : the request was tarpitted. It has been held open on with the client T : the request was tarpitted. It has been held open on with the client
during the whole contimeout duration. during the whole contimeout duration or untill the client closed.
- : normal session completion after end of data transfer. - : normal session completion after end of data transfer.
@ -1826,6 +1826,8 @@ The most common termination flags combinations are indicated here.
servers were saturated or the assigned server taking too long to servers were saturated or the assigned server taking too long to
respond. respond.
CT The client aborted while its session was tarpitted.
sQ The session spent too much time in queue and has been expired. sQ The session spent too much time in queue and has been expired.
SH The server aborted before sending its full headers, or it crashed. SH The server aborted before sending its full headers, or it crashed.
@ -2073,10 +2075,11 @@ Notes :
- a denied request will generate an "HTTP 403 forbidden" response, while a - a denied request will generate an "HTTP 403 forbidden" response, while a
denied response will generate an "HTTP 502 Bad gateway" response. denied response will generate an "HTTP 502 Bad gateway" response.
- a tarpitted request will be held open on the client side for a duration - a tarpitted request will be held open on the client side for a duration
defined in the contimeout parameter. Nothing will be sent to any server. defined in the contimeout parameter, or untill the client aborts. Nothing
When the timeout is reached, the proxy will reply with a 500 server error will be sent to any server. When the timeout is reached, the proxy will
response so that the attacker does not suspect it has been tarpitted. The reply with a 500 server error response so that the attacker does not
logs will report the 500, but the termination flags will indicate 'PT'. suspect it has been tarpitted. The logs may report the 500, but the
termination flags will indicate 'PT' in this case.
Examples : Examples :

View File

@ -1798,7 +1798,8 @@ une signification pr
alors que le serveur a déjà fini. alors que le serveur a déjà fini.
T : requête bloquée en mode "tarpit" par le proxy. Elle a été maintenue T : requête bloquée en mode "tarpit" par le proxy. Elle a été maintenue
ouverte vers le client pendant toute la durée du contimeout. ouverte vers le client pendant toute la durée du contimeout ou
jusqu'à l'abandon de la part du client.
- : terminaison normale, après fin de transfert des données. - : terminaison normale, après fin de transfert des données.
@ -1894,6 +1895,9 @@ Les combinaisons d'indicateurs les plus fr
serveurs étaient saturés, soit que le serveur assigné a mis trop de serveurs étaient saturés, soit que le serveur assigné a mis trop de
temps à répondre. temps à répondre.
CT Le client a abandonné alors que sa session était bloquée en mode
tarpit.
sQ La session a attendu trop longtemps en file d'attente et a été sQ La session a attendu trop longtemps en file d'attente et a été
expirée. expirée.
@ -2152,11 +2156,11 @@ Remarques :
- une requête bloquée produira une réponse "HTTP 403 forbidden" tandis qu'une - une requête bloquée produira une réponse "HTTP 403 forbidden" tandis qu'une
réponse bloquée produira une réponse "HTTP 502 Bad gateway". réponse bloquée produira une réponse "HTTP 502 Bad gateway".
- une requête bloquée par 'reqtarpit' sera maintenue pendant une durée égale - une requête bloquée par 'reqtarpit' sera maintenue pendant une durée égale
au paramètre 'contimeout'. Rien ne sera envoyé au serveur. Lorsque le temps au paramètre 'contimeout', ou jusqu'à l'abandon du client. Rien ne sera
alloué expire, le proxy répondra avec une réponse "500 server error" de envoyé au serveur. Lorsque le temps alloué expire, le proxy répondra avec
sorte que l'attaquant ne suspecte pas qu'il ait été bloqué. Les logs une réponse "500 server error" de sorte que l'attaquant ne suspecte pas
rapporteront aussi ce code 500, mais les flags de terminaison indiqueront qu'il ait été bloqué. Les logs rapporteront aussi ce code 500, mais les
"PT". flags de terminaison indiqueront "PT".
Exemples : Exemples :
---------- ----------

View File

@ -458,6 +458,10 @@ int process_cli(struct session *t)
* to expire at one moment. * to expire at one moment.
*/ */
if (t->flags & SN_CLTARPIT) { if (t->flags & SN_CLTARPIT) {
t->req->l = 0;
/* flush the request so that we can drop the connection early
* if the client closes first.
*/
tv_delayfrom(&req->cex, &now, tv_delayfrom(&req->cex, &now,
t->proxy->contimeout ? t->proxy->contimeout : 0); t->proxy->contimeout ? t->proxy->contimeout : 0);
} }
@ -1348,6 +1352,9 @@ int process_srv(struct session *t)
/* note that this must not return any error because it would be able to /* note that this must not return any error because it would be able to
* overwrite the client_retnclose() output. * overwrite the client_retnclose() output.
*/ */
if (t->flags & SN_CLTARPIT)
srv_close_with_err(t, SN_ERR_CLICL, SN_FINST_T, 0, 0, NULL);
else
srv_close_with_err(t, SN_ERR_CLICL, t->pend_pos ? SN_FINST_Q : SN_FINST_C, 0, 0, NULL); srv_close_with_err(t, SN_ERR_CLICL, t->pend_pos ? SN_FINST_Q : SN_FINST_C, 0, 0, NULL);
return 1; return 1;