]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ip/Qos.cci
Merged from trunk
[thirdparty/squid.git] / src / ip / Qos.cci
1 /* Inline QOS functions */
2 #include "comm/Connection.h"
3 #include "Debug.h"
4
5 int
6 Ip::Qos::setSockTos(const Comm::ConnectionPointer &conn, tos_t tos)
7 {
8 // Bug 3731: FreeBSD produces 'invalid option'
9 // unless we pass it a 32-bit variable storing 8-bits of data.
10 // NP: it is documented as 'int' for all systems, even those like Linux which accept 8-bit char
11 // so we convert to a int before setting.
12 int bTos = tos;
13
14 if (conn->remote.isIPv4()) {
15 #if defined(IP_TOS)
16 int x = setsockopt(conn->fd, IPPROTO_IP, IP_TOS, &bTos, sizeof(bTos));
17 if (x < 0)
18 debugs(50, 2, "Ip::Qos::setSockTos: setsockopt(IP_TOS) on " << conn << ": " << xstrerror());
19 else
20 conn->tos = tos;
21 return x;
22 #else
23 debugs(50, DBG_IMPORTANT, "WARNING: setsockopt(IP_TOS) not supported on this platform");
24 return -1;
25 #endif
26
27 } else { // if (conn->remote.isIPv6()) {
28 #if defined(IPV6_TCLASS)
29 int x = setsockopt(conn->fd, IPPROTO_IPV6, IPV6_TCLASS, &bTos, sizeof(bTos));
30 if (x < 0)
31 debugs(50, 2, "Ip::Qos::setSockTos: setsockopt(IPV6_TCLASS) on " << conn << ": " << xstrerror());
32 else
33 conn->tos = tos;
34 return x;
35 #else
36 debugs(50, DBG_IMPORTANT, "WARNING: setsockopt(IPV6_TCLASS) not supported on this platform");
37 return -1;
38 #endif
39 }
40
41 /* CANNOT REACH HERE */
42 }
43
44 int
45 Ip::Qos::setSockNfmark(const Comm::ConnectionPointer &conn, nfmark_t mark)
46 {
47 #if SO_MARK && USE_LIBCAP
48 int x = setsockopt(conn->fd, SOL_SOCKET, SO_MARK, &mark, sizeof(nfmark_t));
49 if (x < 0)
50 debugs(50, 2, "setSockNfmark: setsockopt(SO_MARK) on " << conn << ": " << xstrerror());
51 else
52 conn->nfmark = mark;
53 return x;
54 #elif USE_LIBCAP
55 debugs(50, DBG_IMPORTANT, "WARNING: setsockopt(SO_MARK) not supported on this platform");
56 return -1;
57 #else
58 debugs(50, DBG_IMPORTANT, "WARNING: Netfilter marking disabled (netfilter marking requires build with LIBCAP)");
59 return -1;
60 #endif
61 }
62
63 bool
64 Ip::Qos::Config::isHitTosActive() const
65 {
66 return (tosLocalHit || tosSiblingHit || tosParentHit || tosMiss || preserveMissTos);
67 }
68
69 bool
70 Ip::Qos::Config::isHitNfmarkActive() const
71 {
72 return (markLocalHit || markSiblingHit || markParentHit || markMiss || preserveMissMark);
73 }
74
75 bool
76 Ip::Qos::Config::isAclNfmarkActive() const
77 {
78 acl_nfmark * nfmarkAcls [] = { nfmarkToServer, nfmarkToClient };
79
80 for (int i=0; i<2; ++i) {
81 while (nfmarkAcls[i]) {
82 acl_nfmark *l = nfmarkAcls[i];
83 if (l->nfmark > 0)
84 return true;
85 nfmarkAcls[i] = l->next;
86 }
87 }
88
89 return false;
90 }
91
92 bool
93 Ip::Qos::Config::isAclTosActive() const
94 {
95 acl_tos * tosAcls [] = { tosToServer, tosToClient };
96
97 for (int i=0; i<2; ++i) {
98 while (tosAcls[i]) {
99 acl_tos *l = tosAcls[i];
100 if (l->tos > 0)
101 return true;
102 tosAcls[i] = l->next;
103 }
104 }
105
106 return false;
107 }