From: wessels <> Date: Sat, 26 May 2007 12:38:03 +0000 (+0000) Subject: Added 'clientside_tos' directive and feature. X-Git-Tag: SQUID_3_0_PRE7~235 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=057f5854eef7d96ae4e76460a885e13de9380f6c;p=thirdparty%2Fsquid.git Added 'clientside_tos' directive and feature. Much like 'tcp_outgoing_tos' except that this affect connections between Squid and its clients instead of server-side connections. --- diff --git a/src/ClientRequestContext.h b/src/ClientRequestContext.h index 64b57aff68..bc6bff53e6 100644 --- a/src/ClientRequestContext.h +++ b/src/ClientRequestContext.h @@ -38,6 +38,7 @@ public: bool redirect_done; bool no_cache_done; bool interpreted_req_hdrs; + bool clientside_tos_done; private: CBDATA_CLASS(ClientRequestContext); diff --git a/src/cf.data.pre b/src/cf.data.pre index 298ab8532d..fada4e4cb6 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.437 2007/05/22 17:12:38 rousskov Exp $ +# $Id: cf.data.pre,v 1.438 2007/05/26 06:38:03 wessels Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -2922,6 +2922,16 @@ DOC_START matching line. DOC_END +NAME: clientside_tos +TYPE: acl_tos +DEFAULT: none +LOC: Config.accessList.clientside_tos +DOC_START + Allows you to select a TOS/Diffserv value to mark client-side + connections with, based on the username or source address + making the request. +DOC_END + NAME: tcp_outgoing_address TYPE: acl_address DEFAULT: none diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 42cb7dae04..08d269c30d 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side_request.cc,v 1.87 2007/05/18 18:26:01 wessels Exp $ + * $Id: client_side_request.cc,v 1.88 2007/05/26 06:38:04 wessels Exp $ * * DEBUG: section 85 Client-side Request Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -999,6 +999,8 @@ ClientHttpRequest::loggingEntry(StoreEntry *newEntry) * the callout. This is strictly for convenience. */ +extern int aclMapTOS (acl_tos * head, ACLChecklist * ch); + void ClientHttpRequest::doCallouts() { @@ -1049,6 +1051,20 @@ ClientHttpRequest::doCallouts() } } + if (!calloutContext->clientside_tos_done) { + calloutContext->clientside_tos_done = true; + if (getConn() != NULL) { + ACLChecklist ch; + ch.src_addr = request->client_addr; + ch.my_addr = request->my_addr; + ch.my_port = request->my_port; + ch.request = HTTPMSGLOCK(request); + int tos = aclMapTOS(Config.accessList.clientside_tos, &ch); + if (tos) + comm_set_tos(getConn()->fd, tos); + } + } + cbdataReferenceDone(calloutContext->http); delete calloutContext; calloutContext = NULL; diff --git a/src/comm.cc b/src/comm.cc index c59ddae043..2dd4a58a33 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.430 2007/04/30 16:56:09 wessels Exp $ + * $Id: comm.cc,v 1.431 2007/05/26 06:38:04 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -822,6 +822,21 @@ limitError(int const anErrno) return anErrno == ENFILE || anErrno == EMFILE; } +int +comm_set_tos(int fd, int tos) +{ +#ifdef IP_TOS + int x = setsockopt(fd, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof(int)); + if (x < 0) + debugs(50, 1, "comm_set_tos: setsockopt(IP_TOS) on FD " << fd << ": " << xstrerror()); + return x; +#else + debugs(50, 0, "comm_set_tos: setsockopt(IP_TOS) not supported on this platform"); + return -1 +#endif +} + + /* Create a socket. Default is blocking, stream (TCP) socket. IO_TYPE * is OR of flags specified in defines.h:COMM_* */ int diff --git a/src/comm.h b/src/comm.h index ab42717262..e4dd0b3e86 100644 --- a/src/comm.h +++ b/src/comm.h @@ -53,6 +53,7 @@ SQUIDCEXTERN int comm_open(int, int, struct IN_ADDR, u_short port, int, const ch SQUIDCEXTERN int comm_openex(int, int, struct IN_ADDR, u_short, int, unsigned char TOS, const char *); SQUIDCEXTERN u_short comm_local_port(int fd); +SQUIDCEXTERN int comm_set_tos(int fd, int tos); SQUIDCEXTERN void commSetSelect(int, unsigned int, PF *, void *, time_t); diff --git a/src/forward.cc b/src/forward.cc index 40a943e8a6..2ad70f34d1 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -1,6 +1,6 @@ /* - * $Id: forward.cc,v 1.164 2007/05/11 13:20:57 rousskov Exp $ + * $Id: forward.cc,v 1.165 2007/05/26 06:38:04 wessels Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -1197,7 +1197,11 @@ static struct IN_ADDR return addr; } -static int +/* + * DPW 2007-05-19 + * Formerly static, but now used by client_side_request.cc + */ +int aclMapTOS(acl_tos * head, ACLChecklist * ch) { acl_tos *l; diff --git a/src/structs.h b/src/structs.h index a170e231a4..2817123724 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.556 2007/05/18 06:41:25 amosjeffries Exp $ + * $Id: structs.h,v 1.557 2007/05/26 06:38:05 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -584,6 +584,7 @@ struct _SquidConfig acl_access *reply; acl_address *outgoing_address; acl_tos *outgoing_tos; + acl_tos *clientside_tos; #if USE_HTCP acl_access *htcp;