From: wessels <> Date: Mon, 1 Apr 2002 13:02:15 +0000 (+0000) Subject: This patch was posted to squid-users some time ago. It allows the admin X-Git-Tag: SQUID_3_0_PRE1~1148 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=98264874b31263b8c74c28aca55799b70b2a4d3b;p=thirdparty%2Fsquid.git This patch was posted to squid-users some time ago. It allows the admin to make Squid send TCP resets for certain error pages. --- diff --git a/src/client_side.cc b/src/client_side.cc index 52ba2f1d90..acdd173323 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.566 2002/04/01 05:59:50 wessels Exp $ + * $Id: client_side.cc,v 1.567 2002/04/01 06:02:15 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1531,6 +1531,9 @@ clientSendMoreData(void *data, char *retbuf, ssize_t retsize) /* there is another object in progress, defer this one */ debug(33, 2) ("clientSendMoreData: Deferring %s\n", storeUrl(entry)); return; + } else if (http->request->flags.reset_tcp) { + comm_reset_close(fd); + return; } else if (entry && EBIT_TEST(entry->flags, ENTRY_ABORTED)) { /* call clientWriteComplete so the client socket gets closed */ clientWriteComplete(fd, NULL, 0, COMM_OK, http); diff --git a/src/comm.cc b/src/comm.cc index 31fbe9e3b6..4cda13a42b 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.327 2002/04/01 05:59:50 wessels Exp $ + * $Id: comm.cc,v 1.328 2002/04/01 06:02:15 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -614,6 +614,21 @@ comm_lingering_close(int fd) } #endif +/* + * enable linger with time of 0 so that when the socket is + * closed, TCP generates a RESET + */ +void +comm_reset_close(int fd) +{ + struct linger L; + L.l_onoff = 1; + L.l_linger = 0; + if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &L, sizeof(L)) < 0) + debug(50, 0) ("commResetTCPClose: FD %d: %s\n", fd, xstrerror()); + comm_close(fd); +} + void comm_close(int fd) { diff --git a/src/errorpage.cc b/src/errorpage.cc index 641439aa5b..757f43ab2c 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -1,6 +1,6 @@ /* - * $Id: errorpage.cc,v 1.168 2002/01/01 21:24:25 hno Exp $ + * $Id: errorpage.cc,v 1.169 2002/04/01 06:02:15 wessels Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -274,6 +274,12 @@ errorAppendEntry(StoreEntry * entry, ErrorState * err) errorStateFree(err); return; } + if (0 == strncmp(error_text[err->page_id], "reset", 5)) { + if (err->request) { + debug(0, 0) ("RSTing this reply\n"); + err->request->flags.reset_tcp = 1; + } + } storeLockObject(entry); storeBuffer(entry); rep = errorBuildReply(err); diff --git a/src/protos.h b/src/protos.h index 3ee2c37968..564b496d75 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.429 2002/04/01 05:59:50 wessels Exp $ + * $Id: protos.h,v 1.430 2002/04/01 06:02:16 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -148,6 +148,7 @@ extern int commUnsetNonBlocking(int fd); extern void commSetCloseOnExec(int fd); extern int comm_accept(int fd, struct sockaddr_in *, struct sockaddr_in *); extern void comm_close(int fd); +extern void comm_reset_close(int fd); #if LINGERING_CLOSE extern void comm_lingering_close(int fd); #endif diff --git a/src/structs.h b/src/structs.h index 396e886feb..6d6042716e 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.411 2002/04/01 05:59:50 wessels Exp $ + * $Id: structs.h,v 1.412 2002/04/01 06:02:16 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1607,6 +1607,7 @@ struct _request_flags { unsigned int accelerated:1; unsigned int internal:1; unsigned int body_sent:1; + unsigned int reset_tcp:1; }; struct _link_list {