2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* Inline QOS functions */
10 #include "comm/Connection.h"
14 Ip::Qos::setSockTos(const int fd, tos_t tos, int type)
16 // Bug 3731: FreeBSD produces 'invalid option'
17 // unless we pass it a 32-bit variable storing 8-bits of data.
18 // NP: it is documented as 'int' for all systems, even those like Linux which accept 8-bit char
19 // so we convert to a int before setting.
22 if (type == AF_INET) {
24 const int x = setsockopt(fd, IPPROTO_IP, IP_TOS, &bTos, sizeof(bTos));
26 debugs(50, 2, "Ip::Qos::setSockTos: setsockopt(IP_TOS) on " << fd << ": " << xstrerror());
29 debugs(50, DBG_IMPORTANT, "WARNING: setsockopt(IP_TOS) not supported on this platform");
32 } else { // type == AF_INET6
33 #if defined(IPV6_TCLASS)
34 const int x = setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &bTos, sizeof(bTos));
36 debugs(50, 2, "Ip::Qos::setSockTos: setsockopt(IPV6_TCLASS) on " << fd << ": " << xstrerror());
39 debugs(50, DBG_IMPORTANT, "WARNING: setsockopt(IPV6_TCLASS) not supported on this platform");
44 /* CANNOT REACH HERE */
48 Ip::Qos::setSockTos(const Comm::ConnectionPointer &conn, tos_t tos)
50 const int x = Ip::Qos::setSockTos(conn->fd, tos, conn->remote.isIPv4() ? AF_INET : AF_INET6);
58 Ip::Qos::setSockNfmark(const int fd, nfmark_t mark)
60 #if SO_MARK && USE_LIBCAP
61 const int x = setsockopt(fd, SOL_SOCKET, SO_MARK, &mark, sizeof(nfmark_t));
63 debugs(50, 2, "setSockNfmark: setsockopt(SO_MARK) on " << fd << ": " << xstrerror());
66 debugs(50, DBG_IMPORTANT, "WARNING: setsockopt(SO_MARK) not supported on this platform");
69 debugs(50, DBG_IMPORTANT, "WARNING: Netfilter marking disabled (netfilter marking requires build with LIBCAP)");
75 Ip::Qos::setSockNfmark(const Comm::ConnectionPointer &conn, nfmark_t mark)
77 const int x = Ip::Qos::setSockNfmark(conn->fd, mark);
84 Ip::Qos::Config::isHitTosActive() const
86 return (tosLocalHit || tosSiblingHit || tosParentHit || tosMiss || preserveMissTos);
90 Ip::Qos::Config::isHitNfmarkActive() const
92 return (markLocalHit || markSiblingHit || markParentHit || markMiss || preserveMissMark);
96 Ip::Qos::Config::isAclNfmarkActive() const
98 acl_nfmark * nfmarkAcls [] = { nfmarkToServer, nfmarkToClient };
100 for (int i=0; i<2; ++i) {
101 while (nfmarkAcls[i]) {
102 acl_nfmark *l = nfmarkAcls[i];
105 nfmarkAcls[i] = l->next;
113 Ip::Qos::Config::isAclTosActive() const
115 acl_tos * tosAcls [] = { tosToServer, tosToClient };
117 for (int i=0; i<2; ++i) {
119 acl_tos *l = tosAcls[i];
122 tosAcls[i] = l->next;