--------------------- PatchSet 1803 Date: 2001/04/01 10:34:09 Author: rvenning Branch: rvenning_tosaddracl Tag: (none) Log: OK, this implements the outgoing addr selection as per the mail sent to the list on 1 April 2001, evening Australian time. Will no proceed to put the TOS stuff back in, and have both acl_map2_tos & acl_map2_outgoing. Members: src/acl.c:1.28->1.28.2.1 src/cf.data.pre:1.24->1.24.2.1 src/comm.c:1.11->1.11.2.1 src/forward.c:1.12->1.12.2.1 src/protos.h:1.23->1.23.2.1 src/structs.h:1.28->1.28.2.1 Index: squid/src/acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/acl.c,v retrieving revision 1.28 retrieving revision 1.28.2.1 diff -u -r1.28 -r1.28.2.1 --- squid/src/acl.c 30 Mar 2001 22:29:38 -0000 1.28 +++ squid/src/acl.c 1 Apr 2001 10:34:09 -0000 1.28.2.1 @@ -1,6 +1,6 @@ /* - * $Id: acl.c,v 1.28 2001/03/30 22:29:38 squidadm Exp $ + * $Id: acl.c,v 1.28.2.1 2001/04/01 10:34:09 rvenning Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -994,11 +994,24 @@ debug(28, 3) ("aclParseAccessLine: looking for ACL name '%s'\n", t); a = aclFindByName(t); if (a == NULL) { - debug(28, 0) ("%s line %d: %s\n", - cfg_filename, config_lineno, config_input_line); - debug(28, 0) ("aclParseAccessLine: ACL name '%s' not found.\n", t); - memFree(L, MEM_ACL_LIST); - continue; + int trailer; + /* maybe it is a permissible trailing integer - in which case there + is nothing left on the line */ + if (!strtok(NULL, w_space) && /* OK to discard, trust me */ + (sscanf(t, "0x%x", &trailer) || sscanf(t, "%d", &trailer) || + safe_inet_addr(t, (struct in_addr *)&trailer))) { + /* we really do have a int on the end of the line, in 0x1234 + or plain 1234 format */ + A->trailer = trailer; + memFree(L, MEM_ACL_LIST); /* mistakenly allocated */ + continue; + } else { + debug(28, 0) ("%s line %d: %s\n", + cfg_filename, config_lineno, config_input_line); + debug(28, 0) ("aclParseAccessLine: ACL name '%s' not found.\n", t); + memFree(L, MEM_ACL_LIST); + continue; + } } L->acl = a; *Tail = L; @@ -1717,8 +1730,14 @@ debug(28, 5) ("aclCheckFast: list: %p\n", A); while (A) { allow = A->allow; - if (aclMatchAclList(A->acl_list, checklist)) - return allow == ACCESS_ALLOWED; + if (aclMatchAclList(A->acl_list, checklist)) { + if (allow == ACCESS_ALLOWED && A->trailer) { + return A->trailer; /* trailing int non-zero, return + still holds the same meaning */ + } else { + return allow == ACCESS_ALLOWED; + } + } A = A->next; } debug(28, 5) ("aclCheckFast: no matches, returning: %d\n", allow == ACCESS_DENIED); Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cf.data.pre,v retrieving revision 1.24 retrieving revision 1.24.2.1 diff -u -r1.24 -r1.24.2.1 --- squid/src/cf.data.pre 30 Mar 2001 22:29:38 -0000 1.24 +++ squid/src/cf.data.pre 1 Apr 2001 10:34:09 -0000 1.24.2.1 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.24 2001/03/30 22:29:38 squidadm Exp $ +# $Id: cf.data.pre,v 1.24.2.1 2001/04/01 10:34:09 rvenning Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -2072,6 +2072,27 @@ the configure script. DOC_END +NAME: acl_map2_tos +TYPE: acl_access +DEFAULT: none +DEFAULT_IF_NONE: deny all 0x00 +LOC: Config.accessList.tosacl +DOC_START + A list of ACL elements followed by a TOS byte that applies if + matched. For example you might like to provide different TOS + marking, dependant on the client network: + + acl normal_service_net src 10.0.0.0/255.255.255.0 + acl good_service_net src 10.0.1.0/255.255.255.0 + acl_map2_tos normal_service_net 0x00 + acl_map2_tos good_service_net 0x20 + + TOS/DSCP values really only have local significance - so you should + know what you're specifying. For more, see RFC 2474 + + The TOS/DSCP byte must be exactly that - a byte, value 0 - 255 + Processing proceeds in the order specifies, and stops at first match. +DOC_END COMMENT_START ADMINISTRATIVE PARAMETERS Index: squid/src/comm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm.c,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -u -r1.11 -r1.11.2.1 --- squid/src/comm.c 30 Mar 2001 22:29:38 -0000 1.11 +++ squid/src/comm.c 1 Apr 2001 10:34:10 -0000 1.11.2.1 @@ -1,6 +1,6 @@ /* - * $Id: comm.c,v 1.11 2001/03/30 22:29:38 squidadm Exp $ + * $Id: comm.c,v 1.11.2.1 2001/04/01 10:34:10 rvenning Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -145,16 +145,31 @@ } /* Create a socket. Default is blocking, stream (TCP) socket. IO_TYPE - * is OR of flags specified in comm.h. */ -int + * is OR of flags specified in comm.h. Defaults TOS */ +inline int comm_open(int sock_type, int proto, struct in_addr addr, u_short port, int flags, + const char *note) { + return comm_openex(sock_type, proto, addr, port, flags, 0, note); +} + + +/* Create a socket. Default is blocking, stream (TCP) socket. IO_TYPE + * is OR of flags specified in defines.h:COMM_* */ +int +comm_openex(int sock_type, + int proto, + struct in_addr addr, + u_short port, + int flags, + unsigned char TOS, const char *note) { int new_socket; + int tos; fde *F = NULL; /* Create socket for accepting new connections. */ @@ -174,6 +189,15 @@ } return -1; } + + /* set TOS if needed */ + if (TOS) { + tos = TOS; + if (setsockopt(new_socket, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof(int)) < 0) + debug(50, 1) ("comm_open: setsockopt(IP_TOS) on FD %d: %s\n", + new_socket, xstrerror()); + } + /* update fdstat */ debug(5, 5) ("comm_open: FD %d is a new socket\n", new_socket); fd_open(new_socket, FD_SOCKET, note); Index: squid/src/forward.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/forward.c,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -r1.12 -r1.12.2.1 --- squid/src/forward.c 30 Mar 2001 22:29:38 -0000 1.12 +++ squid/src/forward.c 1 Apr 2001 10:34:10 -0000 1.12.2.1 @@ -1,6 +1,6 @@ /* - * $Id: forward.c,v 1.12 2001/03/30 22:29:38 squidadm Exp $ + * $Id: forward.c,v 1.12.2.1 2001/04/01 10:34:10 rvenning Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -277,6 +277,8 @@ const char *host; unsigned short port; time_t ctimeout; + aclCheck_t ch; + struct in_addr outgoing; assert(fs); assert(fwdState->server_fd == -1); debug(17, 3) ("fwdConnectStart: %s\n", url); @@ -306,9 +308,22 @@ #if URL_CHECKSUM_DEBUG assert(fwdState->entry->mem_obj->chksum == url_checksum(url)); #endif + /* find the desired tos (for the request that sparked this connection */ + memset(&ch, '\0', sizeof(aclCheck_t)); + ch.src_addr = fwdState->request->client_addr; /* is it right to */ + debug(17,1) ("fwdConnectStart: src addr %s\n", inet_ntoa(ch.src_addr)); + ch.my_addr = fwdState->request->my_addr; /* pull out the */ + debug(17,1) ("fwdConnectStart: my addr %s\n", inet_ntoa(ch.my_addr)); + ch.my_port = fwdState->request->my_port; /* data like this? */ + ch.request = fwdState->request; + outgoing.s_addr = (unsigned short)aclCheckFast(Config.accessList.tosacl, &ch); + if(!outgoing.s_addr) + outgoing = Config.Addrs.tcp_outgoing; + + debug(17,3) ("fwdConnectStart: got addr %s\n", outgoing); fd = comm_open(SOCK_STREAM, 0, - Config.Addrs.tcp_outgoing, + outgoing, 0, COMM_NONBLOCKING, url); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.23 retrieving revision 1.23.2.1 diff -u -r1.23 -r1.23.2.1 --- squid/src/protos.h 30 Mar 2001 22:29:38 -0000 1.23 +++ squid/src/protos.h 1 Apr 2001 10:34:10 -0000 1.23.2.1 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.23 2001/03/30 22:29:38 squidadm Exp $ + * $Id: protos.h,v 1.23.2.1 2001/04/01 10:34:10 rvenning Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -149,6 +149,7 @@ extern void comm_init(void); extern int comm_listen(int sock); extern int comm_open(int, int, struct in_addr, u_short port, int, const char *note); +extern int comm_openex(int, int, struct in_addr, u_short, int, unsigned char TOS, const char *); extern u_short comm_local_port(int fd); extern void commSetSelect(int, unsigned int, PF *, void *, time_t); Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.28 retrieving revision 1.28.2.1 diff -u -r1.28 -r1.28.2.1 --- squid/src/structs.h 30 Mar 2001 22:29:38 -0000 1.28 +++ squid/src/structs.h 1 Apr 2001 10:34:10 -0000 1.28.2.1 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.28 2001/03/30 22:29:38 squidadm Exp $ + * $Id: structs.h,v 1.28.2.1 2001/04/01 10:34:10 rvenning Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -235,6 +235,7 @@ struct _acl_access { int allow; + int trailer; acl_list *acl_list; char *cfgline; acl_access *next; @@ -556,6 +557,7 @@ #endif acl_access *redirector; acl_access *reply; + acl_access *tosacl; } accessList; acl_deny_info_list *denyInfoList; struct _authConfig {