-diff -r -c squid-2.4-200208212300/src/client_side.c squid-2.4-200208212300.fixed/src/client_side.c
-*** squid-2.4-200208212300/src/client_side.c Mon Jun 24 08:10:51 2002
---- squid-2.4-200208212300.fixed/src/client_side.c Mon Sep 2 12:56:23 2002
-***************
-*** 1765,1770 ****
---- 1765,1773 ----
- /* Avoid copying to MemBuf for non-range requests */
- /* Note, if we're here, then 'rep' is known to be NULL */
- http->out.offset += body_size;
-+ { int tos=isTcpHit(http->log_type) ? 0 : 8;
-+ setsockopt(fd,SOL_IP,IP_TOS,&tos,4);
-+ }
- comm_write(fd, buf, size, clientWriteBodyComplete, http, NULL);
- /* NULL because clientWriteBodyComplete frees it */
- return;
-***************
-*** 1817,1822 ****
---- 1820,1828 ----
- if (!http->request->range && http->request->method == METHOD_GET)
- assert(check_size == size);
- /* write */
-+ { int tos=isTcpHit(http->log_type) ? 0 : 8;
-+ setsockopt(fd,SOL_IP,IP_TOS,&tos,4);
-+ }
- comm_write_mbuf(fd, mb, clientWriteComplete, http);
- /* if we don't do it, who will? */
- memFree(buf, MEM_CLIENT_SOCK_BUF);
-diff -r -c squid-2.4-200208212300/src/defines.h squid-2.4-200208212300.fixed/src/defines.h
-*** squid-2.4-200208212300/src/defines.h Fri Jan 12 01:51:46 2001
---- squid-2.4-200208212300.fixed/src/defines.h Mon Sep 2 13:15:36 2002
-***************
-*** 38,43 ****
---- 38,45 ----
- #define FALSE 0
- #endif
-
-+ #define SQUID_TCP_RCVBUF SQUID_TCP_SO_RCVBUF
-+
- #define ACL_NAME_SZ 32
- #define BROWSERNAMELEN 128
-
-diff -r -c squid-2.4-200208212300/src/ftp.c squid-2.4-200208212300.fixed/src/ftp.c
-*** squid-2.4-200208212300/src/ftp.c Sun Jun 23 22:18:58 2002
---- squid-2.4-200208212300.fixed/src/ftp.c Mon Sep 2 14:15:11 2002
-***************
-*** 1116,1123 ****
- ftpState->ctrl.freefunc = memFree4K;
- ftpState->ctrl.size = 4096;
- ftpState->ctrl.offset = 0;
-! ftpState->data.buf = xmalloc(SQUID_TCP_SO_RCVBUF);
-! ftpState->data.size = SQUID_TCP_SO_RCVBUF;
- ftpState->data.freefunc = xfree;
- ftpScheduleReadControlReply(ftpState, 0);
- }
---- 1116,1123 ----
- ftpState->ctrl.freefunc = memFree4K;
- ftpState->ctrl.size = 4096;
- ftpState->ctrl.offset = 0;
-! ftpState->data.buf = xmalloc(SQUID_TCP_RCVBUF < SQUID_TCP_SO_RCVBUF ? SQUID_TCP_RCVBUF : SQUID_TCP_SO_RCVBUF);
-! ftpState->data.size = (SQUID_TCP_RCVBUF < SQUID_TCP_SO_RCVBUF ? SQUID_TCP_RCVBUF : SQUID_TCP_SO_RCVBUF);
- ftpState->data.freefunc = xfree;
- ftpScheduleReadControlReply(ftpState, 0);
- }
-diff -r -c squid-2.4-200208212300/src/http.c squid-2.4-200208212300.fixed/src/http.c
-*** squid-2.4-200208212300/src/http.c Fri Jun 28 01:32:46 2002
---- squid-2.4-200208212300.fixed/src/http.c Mon Sep 2 14:15:11 2002
-***************
-*** 456,462 ****
- httpReadReply(int fd, void *data)
- {
- HttpStateData *httpState = data;
-! LOCAL_ARRAY(char, buf, SQUID_TCP_SO_RCVBUF);
- StoreEntry *entry = httpState->entry;
- const request_t *request = httpState->request;
- int len;
---- 456,462 ----
- httpReadReply(int fd, void *data)
- {
- HttpStateData *httpState = data;
-! LOCAL_ARRAY(char, buf, SQUID_TCP_RCVBUF < SQUID_TCP_SO_RCVBUF ? SQUID_TCP_RCVBUF : SQUID_TCP_SO_RCVBUF);
- StoreEntry *entry = httpState->entry;
- const request_t *request = httpState->request;
- int len;
-***************
-*** 478,484 ****
- }
- /* check if we want to defer reading */
- errno = 0;
-! read_sz = SQUID_TCP_SO_RCVBUF;
- #if DELAY_POOLS
- read_sz = delayBytesWanted(delay_id, 1, read_sz);
- #endif
---- 478,484 ----
- }
- /* check if we want to defer reading */
- errno = 0;
-! read_sz = (SQUID_TCP_RCVBUF < SQUID_TCP_SO_RCVBUF ? SQUID_TCP_RCVBUF : SQUID_TCP_SO_RCVBUF);
- #if DELAY_POOLS
- read_sz = delayBytesWanted(delay_id, 1, read_sz);
- #endif
+diff -Nur squid-3.0.STABLE8/src/cf.data.pre squid-3.0.STABLE8-zph/src/cf.data.pre
+--- squid-3.0.STABLE8/src/cf.data.pre 2008-07-18 13:02:53.000000000 +0300
++++ squid-3.0.STABLE8-zph/src/cf.data.pre 2008-08-22 13:25:45.000000000 +0300
+@@ -1119,6 +1119,60 @@
+ making the request.
+ DOC_END
+
++NAME: zph_tos_local
++TYPE: int
++DEFAULT: 0
++LOC: Config.zph_tos_local
++DOC_START
++ Allows you to select a TOS/Diffserv value to mark local hits. Read above
++ (tcp_outgoing_tos) for details/requirements about TOS.
++ Default: 0 (disabled).
++DOC_END
++
++NAME: zph_tos_peer
++TYPE: int
++DEFAULT: 0
++LOC: Config.zph_tos_peer
++DOC_START
++ Allows you to select a TOS/Diffserv value to mark peer hits. Read above
++ (tcp_outgoing_tos) for details/requirements about TOS.
++ Default: 0 (disabled).
++DOC_END
++
++NAME: zph_tos_parent
++COMMENT: on|off
++TYPE: onoff
++LOC: Config.onoff.zph_tos_parent
++DEFAULT: on
++DOC_START
++ Set this to off if you want only sibling hits to be marked.
++ If set to on (default), parent hits are being marked too.
++DOC_END
++
++NAME: zph_preserve_miss_tos
++COMMENT: on|off
++TYPE: onoff
++LOC: Config.onoff.zph_preserve_miss_tos
++DEFAULT: on
++DOC_START
++ If set to on (default), any HTTP response towards clients will
++ have the TOS value of the response comming from the remote
++ server masked with the value of zph_preserve_miss_tos_mask.
++ For this to work correctly, you will need to patch your linux
++ kernel with the TOS preserving ZPH patch.
++DOC_END
++
++NAME: zph_preserve_miss_tos_mask
++TYPE: int
++DEFAULT: 255
++LOC: Config.zph_preserve_miss_tos_mask
++DOC_START
++ Allows you to mask certain bits in the TOS received from the
++ remote server, before copying the value to the TOS send towards
++ clients.
++ Default: 255 (TOS from server is not changed).
++DOC_END
++
+ NAME: tcp_outgoing_address
+ TYPE: acl_address
+ DEFAULT: none
+diff -Nur squid-3.0.STABLE8/src/client_side_reply.cc squid-3.0.STABLE8-zph/src/client_side_reply.cc
+--- squid-3.0.STABLE8/src/client_side_reply.cc 2008-07-18 13:02:54.000000000 +0300
++++ squid-3.0.STABLE8-zph/src/client_side_reply.cc 2008-08-22 13:25:54.000000000 +0300
+@@ -48,6 +48,7 @@
+ #include "ESI.h"
+ #endif
+ #include "MemObject.h"
++#include "fde.h"
+ #include "ACLChecklist.h"
+ #include "ACL.h"
+ #if DELAY_POOLS
+@@ -1548,6 +1549,11 @@
+ /* guarantee nothing has been sent yet! */
+ assert(http->out.size == 0);
+ assert(http->out.offset == 0);
++ if (Config.zph_tos_local)
++ {
++ debugs(33, 1, "ZPH hit hier.code=" << http->request->hier.code <<" TOS="<<Config.zph_tos_local);
++ comm_set_tos(http->getConn()->fd,Config.zph_tos_local);
++ }
+ tempBuffer.offset = reqofs;
+ tempBuffer.length = getNextNode()->readBuffer.length;
+ tempBuffer.data = getNextNode()->readBuffer.data;
+@@ -1827,6 +1833,24 @@
+ char *buf = next()->readBuffer.data;
+
+ char *body_buf = buf;
++
++ if (reqofs==0 && !logTypeIsATcpHit(http->logType))
++ {
++ int tos = 0;
++ if (Config.zph_tos_peer &&
++ (http->request->hier.code==SIBLING_HIT ||
++ Config.onoff.zph_tos_parent && http->request->hier.code==PARENT_HIT))
++ {
++ tos = Config.zph_tos_peer;
++ debugs(33, 1, "ZPH: Peer hit, TOS="<<tos<<" hier.code="<<http->request->hier.code);
++ }
++ else if (Config.onoff.zph_preserve_miss_tos && Config.zph_preserve_miss_tos_mask)
++ {
++ tos = fd_table[fd].upstreamTOS & Config.zph_preserve_miss_tos_mask;
++ debugs(33, 1, "ZPH: Preserving TOS on miss, TOS="<<tos);
++ }
++ comm_set_tos(fd,tos);
++ }
+
+ if (buf != result.data) {
+ /* we've got to copy some data */
+diff -Nur squid-3.0.STABLE8/src/fde.h squid-3.0.STABLE8-zph/src/fde.h
+--- squid-3.0.STABLE8/src/fde.h 2008-07-18 13:02:54.000000000 +0300
++++ squid-3.0.STABLE8-zph/src/fde.h 2008-08-22 13:26:05.000000000 +0300
+@@ -106,7 +106,7 @@
+ long handle;
+ } win32;
+ #endif
+-
++ unsigned char upstreamTOS; /* see FwdState::dispatch() */
+ };
+
+ #endif /* SQUID_FDE_H */
+diff -Nur squid-3.0.STABLE8/src/forward.cc squid-3.0.STABLE8-zph/src/forward.cc
+--- squid-3.0.STABLE8/src/forward.cc 2008-07-18 13:02:54.000000000 +0300
++++ squid-3.0.STABLE8-zph/src/forward.cc 2008-08-22 13:26:10.000000000 +0300
+@@ -964,6 +964,52 @@
+
+ netdbPingSite(request->host);
+
++ /* Retrieves remote server TOS value, and stores it as part of the
++ * original client request FD object. It is later used to forward
++ * remote server's TOS in the response to the client in case of a MISS.
++ */
++ fde * clientFde = &fd_table[client_fd];
++ if (clientFde)
++ {
++ int tos = 1;
++ int tos_len = sizeof(tos);
++ clientFde->upstreamTOS = 0;
++ if (setsockopt(server_fd,SOL_IP,IP_RECVTOS,&tos,tos_len)==0)
++ {
++ unsigned char buf[512];
++ int len = 512;
++ if (getsockopt(server_fd,SOL_IP,IP_PKTOPTIONS,buf,(socklen_t*)&len) == 0)
++ {
++ /* Parse the PKTOPTIONS structure to locate the TOS data message
++ * prepared in the kernel by the ZPH incoming TCP TOS preserving
++ * patch.
++ */
++ unsigned char * p = buf;
++ while (p-buf < len)
++ {
++ struct cmsghdr *o = (struct cmsghdr*)p;
++ if (o->cmsg_len<=0)
++ break;
++
++ if (o->cmsg_level == SOL_IP && o->cmsg_type == IP_TOS)
++ {
++ clientFde->upstreamTOS = (unsigned char)(*(int*)CMSG_DATA(o));
++ break;
++ }
++ p += CMSG_LEN(o->cmsg_len);
++ }
++ }
++ else
++ {
++ debugs(33, 1, "ZPH: error in getsockopt(IP_PKTOPTIONS) on FD "<<server_fd<<" "<<xstrerror());
++ }
++ }
++ else
++ {
++ debugs(33, 1, "ZPH: error in setsockopt(IP_RECVTOS) on FD "<<server_fd<<" "<<xstrerror());
++ }
++ }
++
+ if (servers && (p = servers->_peer)) {
+ p->stats.fetches++;
+ request->peer_login = p->login;
+diff -Nur squid-3.0.STABLE8/src/structs.h squid-3.0.STABLE8-zph/src/structs.h
+--- squid-3.0.STABLE8/src/structs.h 2008-07-18 13:02:54.000000000 +0300
++++ squid-3.0.STABLE8-zph/src/structs.h 2008-08-22 13:26:24.000000000 +0300
+@@ -553,6 +553,8 @@
+ int emailErrData;
+ int httpd_suppress_version_string;
+ int global_internal_static;
++ int zph_tos_parent;
++ int zph_preserve_miss_tos;
+ int debug_override_X;
+ int WIN32_IpAddrChangeMonitor;
+ }
+@@ -721,6 +723,9 @@
+ int sleep_after_fork; /* microseconds */
+ time_t minimum_expiry_time; /* seconds */
+ external_acl *externalAclHelperList;
++ int zph_tos_local;
++ int zph_tos_peer;
++ int zph_preserve_miss_tos_mask;
+ #if USE_SSL
+
+ struct