2 * Copyright (C) 1996-2017 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 debugs(50, 3, "for FD " << fd << " to " << bTos);
24 if (type == AF_INET) {
26 const int x = setsockopt(fd, IPPROTO_IP, IP_TOS, &bTos, sizeof(bTos));
29 debugs(50, 2, "setsockopt(IP_TOS) on " << fd << ": " << xstrerr(xerrno));
33 debugs(50, DBG_IMPORTANT, "WARNING: setsockopt(IP_TOS) not supported on this platform");
36 } else { // type == AF_INET6
37 #if defined(IPV6_TCLASS)
38 const int x = setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &bTos, sizeof(bTos));
41 debugs(50, 2, "setsockopt(IPV6_TCLASS) on " << fd << ": " << xstrerr(xerrno));
45 debugs(50, DBG_IMPORTANT, "WARNING: setsockopt(IPV6_TCLASS) not supported on this platform");
50 /* CANNOT REACH HERE */
54 Ip::Qos::setSockTos(const Comm::ConnectionPointer &conn, tos_t tos)
56 const int x = Ip::Qos::setSockTos(conn->fd, tos, conn->remote.isIPv4() ? AF_INET : AF_INET6);
57 conn->tos = (x >= 0) ? tos : 0;
62 Ip::Qos::setSockNfmark(const int fd, nfmark_t mark)
64 #if SO_MARK && USE_LIBCAP
65 debugs(50, 3, "for FD " << fd << " to " << mark);
66 const int x = setsockopt(fd, SOL_SOCKET, SO_MARK, &mark, sizeof(nfmark_t));
69 debugs(50, 2, "setsockopt(SO_MARK) on " << fd << ": " << xstrerr(xerrno));
73 debugs(50, DBG_IMPORTANT, "WARNING: setsockopt(SO_MARK) not supported on this platform");
76 debugs(50, DBG_IMPORTANT, "WARNING: Netfilter marking disabled (netfilter marking requires build with LIBCAP)");
82 Ip::Qos::setSockNfmark(const Comm::ConnectionPointer &conn, nfmark_t mark)
84 const int x = Ip::Qos::setSockNfmark(conn->fd, mark);
85 conn->nfmark = (x >= 0) ? mark : 0;
90 Ip::Qos::Config::isHitTosActive() const
92 return (tosLocalHit || tosSiblingHit || tosParentHit || tosMiss || preserveMissTos);
96 Ip::Qos::Config::isHitNfmarkActive() const
98 return (markLocalHit || markSiblingHit || markParentHit || markMiss || preserveMissMark);
102 Ip::Qos::Config::isAclNfmarkActive() const
104 acl_nfmark * nfmarkAcls [] = { nfmarkToServer, nfmarkToClient };
106 for (int i=0; i<2; ++i) {
107 while (nfmarkAcls[i]) {
108 acl_nfmark *l = nfmarkAcls[i];
111 nfmarkAcls[i] = l->next;
119 Ip::Qos::Config::isAclTosActive() const
121 acl_tos * tosAcls [] = { tosToServer, tosToClient };
123 for (int i=0; i<2; ++i) {
125 acl_tos *l = tosAcls[i];
128 tosAcls[i] = l->next;