---------------------
PatchSet 10833 
Date: 2007/05/26 06:38:03
Author: wessels
Branch: HEAD
Tag: (none) 
Log:
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.

Members: 
	src/ClientRequestContext.h:1.3->1.4 
	src/cf.data.pre:1.437->1.438 
	src/client_side_request.cc:1.87->1.88 
	src/comm.cc:1.430->1.431 
	src/comm.h:1.28->1.29 
	src/forward.cc:1.164->1.165 
	src/structs.h:1.556->1.557 

Index: squid3/src/ClientRequestContext.h
===================================================================
RCS file: /cvsroot/squid/squid3/src/ClientRequestContext.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- squid3/src/ClientRequestContext.h	11 Jan 2006 21:14:33 -0000	1.3
+++ squid3/src/ClientRequestContext.h	26 May 2007 06:38:03 -0000	1.4
@@ -38,6 +38,7 @@
     bool redirect_done;
     bool no_cache_done;
     bool interpreted_req_hdrs;
+    bool clientside_tos_done;
 
 private:
     CBDATA_CLASS(ClientRequestContext);
Index: squid3/src/cf.data.pre
===================================================================
RCS file: /cvsroot/squid/squid3/src/cf.data.pre,v
retrieving revision 1.437
retrieving revision 1.438
diff -u -r1.437 -r1.438
--- squid3/src/cf.data.pre	22 May 2007 17:12:38 -0000	1.437
+++ squid3/src/cf.data.pre	26 May 2007 06:38:03 -0000	1.438
@@ -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 @@
 	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
Index: squid3/src/client_side_request.cc
===================================================================
RCS file: /cvsroot/squid/squid3/src/client_side_request.cc,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -r1.87 -r1.88
--- squid3/src/client_side_request.cc	18 May 2007 18:26:01 -0000	1.87
+++ squid3/src/client_side_request.cc	26 May 2007 06:38:04 -0000	1.88
@@ -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 @@
  * the callout.  This is strictly for convenience.
  */
 
+extern int aclMapTOS (acl_tos * head, ACLChecklist * ch);
+
 void
 ClientHttpRequest::doCallouts()
 {
@@ -1049,6 +1051,20 @@
         }
     }
 
+    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;
Index: squid3/src/comm.cc
===================================================================
RCS file: /cvsroot/squid/squid3/src/comm.cc,v
retrieving revision 1.430
retrieving revision 1.431
diff -u -r1.430 -r1.431
--- squid3/src/comm.cc	30 Apr 2007 16:56:09 -0000	1.430
+++ squid3/src/comm.cc	26 May 2007 06:38:04 -0000	1.431
@@ -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 @@
     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
Index: squid3/src/comm.h
===================================================================
RCS file: /cvsroot/squid/squid3/src/comm.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- squid3/src/comm.h	31 Oct 2006 23:30:57 -0000	1.28
+++ squid3/src/comm.h	26 May 2007 06:38:04 -0000	1.29
@@ -53,6 +53,7 @@
 
 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);
 
Index: squid3/src/forward.cc
===================================================================
RCS file: /cvsroot/squid/squid3/src/forward.cc,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -r1.164 -r1.165
--- squid3/src/forward.cc	11 May 2007 13:20:57 -0000	1.164
+++ squid3/src/forward.cc	26 May 2007 06:38:04 -0000	1.165
@@ -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 @@
     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;
Index: squid3/src/structs.h
===================================================================
RCS file: /cvsroot/squid/squid3/src/structs.h,v
retrieving revision 1.556
retrieving revision 1.557
diff -u -r1.556 -r1.557
--- squid3/src/structs.h	18 May 2007 06:41:25 -0000	1.556
+++ squid3/src/structs.h	26 May 2007 06:38:05 -0000	1.557
@@ -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 @@
         acl_access *reply;
         acl_address *outgoing_address;
         acl_tos *outgoing_tos;
+        acl_tos *clientside_tos;
 #if USE_HTCP
 
         acl_access *htcp;
