]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
bbc27441 AJ |
3 | * |
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. | |
7 | */ | |
8 | ||
575cb927 AJ |
9 | #ifndef SQUID_QOSCONFIG_H |
10 | #define SQUID_QOSCONFIG_H | |
11 | ||
6f58d7d7 | 12 | #include "acl/forward.h" |
425de4c8 | 13 | #include "hier_code.h" |
b5523edc | 14 | #include "ip/forward.h" |
244da4ad | 15 | #include "ip/NfMarkConfig.h" |
575cb927 | 16 | |
425de4c8 AJ |
17 | #if HAVE_LIBNETFILTER_CONNTRACK_LIBNETFILTER_CONNTRACK_H |
18 | #include <libnetfilter_conntrack/libnetfilter_conntrack.h> | |
19 | #endif | |
425de4c8 AJ |
20 | #if HAVE_LIBNETFILTER_CONNTRACK_LIBNETFILTER_CONNTRACK_TCP_H |
21 | #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h> | |
22 | #endif | |
425de4c8 | 23 | #include <limits> |
425de4c8 | 24 | |
425de4c8 | 25 | class fde; |
575cb927 | 26 | |
b0b24108 | 27 | // TODO: move to new ACL framework |
e4a14600 A |
28 | class acl_tos |
29 | { | |
60019fea AJ |
30 | CBDATA_CLASS(acl_tos); |
31 | ||
b0b24108 | 32 | public: |
cc8c4af2 | 33 | acl_tos() : next(NULL), aclList(NULL), tos(0) {} |
60019fea AJ |
34 | ~acl_tos(); |
35 | ||
b0b24108 FC |
36 | acl_tos *next; |
37 | ACLList *aclList; | |
38 | tos_t tos; | |
39 | }; | |
60019fea | 40 | |
b0b24108 | 41 | // TODO: move to new ACL framework |
e4a14600 A |
42 | class acl_nfmark |
43 | { | |
60019fea AJ |
44 | CBDATA_CLASS(acl_nfmark); |
45 | ||
b0b24108 | 46 | public: |
244da4ad | 47 | acl_nfmark() : next(NULL), aclList(NULL) {} |
60019fea AJ |
48 | ~acl_nfmark(); |
49 | ||
b0b24108 FC |
50 | acl_nfmark *next; |
51 | ACLList *aclList; | |
244da4ad | 52 | Ip::NfMarkConfig markConfig; |
b0b24108 FC |
53 | }; |
54 | ||
63bd4bf7 A |
55 | namespace Ip |
56 | { | |
b7ac5457 | 57 | |
425de4c8 AJ |
58 | /** |
59 | * QOS namespace contains all the QOS functionality: global functions within | |
60 | * the namespace and the configuration parameters within a config class. | |
61 | */ | |
63bd4bf7 A |
62 | namespace Qos |
63 | { | |
b7ac5457 | 64 | |
653d9927 A |
65 | /// Possible Squid roles in connection handling |
66 | enum ConnectionDirection { | |
67 | dirAccepted, ///< accepted (from a client by Squid) | |
68 | dirOpened ///< opened (by Squid to an origin server or peer) | |
69 | }; | |
70 | ||
dc49061a A |
71 | /** |
72 | * Function to retrieve the TOS value of the inbound packet. | |
73 | * Called by FwdState::dispatch if QOS options are enabled. | |
74 | * Bug 2537: This part of ZPH only applies to patched Linux kernels | |
75 | * @param server Server side descriptor of connection to get TOS for | |
76 | * @param clientFde Pointer to client side fde instance to set tosFromServer in | |
77 | */ | |
78 | void getTosFromServer(const Comm::ConnectionPointer &server, fde *clientFde); | |
b5523edc | 79 | |
dc49061a | 80 | /** |
244da4ad | 81 | * Function to retrieve the netfilter CONNMARK value of the connection. |
653d9927 A |
82 | * Called by FwdState::dispatch if QOS options are enabled or by |
83 | * Comm::TcpAcceptor::acceptOne | |
84 | * | |
85 | * @param conn Pointer to connection to get mark for | |
86 | * @param connDir Specifies connection type (incoming or outgoing) | |
dc49061a | 87 | */ |
244da4ad | 88 | nfmark_t getNfConnmark(const Comm::ConnectionPointer &conn, const ConnectionDirection connDir); |
425de4c8 | 89 | |
dc49061a | 90 | /** |
244da4ad AG |
91 | * Function to set the netfilter CONNMARK value on the connection. |
92 | * Called by ClientHttpRequest::doCallouts. | |
93 | * | |
94 | * @param conn Pointer to connection to set mark on | |
95 | * @param connDir Specifies connection type (incoming or outgoing) | |
96 | * @cm Netfilter mark configuration (mark and mask) | |
dc49061a | 97 | */ |
244da4ad | 98 | bool setNfConnmark(Comm::ConnectionPointer &conn, const ConnectionDirection connDir, const NfMarkConfig &cm); |
425de4c8 | 99 | |
dc49061a A |
100 | /** |
101 | * Function to work out and then apply to the socket the appropriate | |
102 | * TOS value to set on packets when items have not been retrieved from | |
103 | * local cache. Called by clientReplyContext::sendMoreData if QOS is | |
104 | * enabled for TOS. | |
105 | * @param conn Descriptor of socket to set the TOS for | |
106 | * @param hierCode Hier code of request | |
107 | */ | |
108 | int doTosLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode); | |
b5523edc | 109 | |
dc49061a A |
110 | /** |
111 | * Function to work out and then apply to the socket the appropriate | |
112 | * netfilter mark value to set on packets when items have not been | |
113 | * retrieved from local cache. Called by clientReplyContext::sendMoreData | |
114 | * if QOS is enabled for TOS. | |
115 | * @param conn Descriptor of socket to set the mark for | |
116 | * @param hierCode Hier code of request | |
117 | */ | |
118 | int doNfmarkLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode); | |
b5523edc | 119 | |
dc49061a A |
120 | /** |
121 | * Function to work out and then apply to the socket the appropriate | |
122 | * TOS value to set on packets when items *have* been retrieved from | |
123 | * local cache. Called by clientReplyContext::doGetMoreData if QOS is | |
124 | * enabled for TOS. | |
125 | * @param conn Descriptor of socket to set the TOS for | |
126 | */ | |
127 | int doTosLocalHit(const Comm::ConnectionPointer &conn); | |
b5523edc | 128 | |
dc49061a A |
129 | /** |
130 | * Function to work out and then apply to the socket the appropriate | |
131 | * netfilter mark value to set on packets when items *have* been | |
132 | * retrieved from local cache. Called by clientReplyContext::doGetMoreData | |
133 | * if QOS is enabled for TOS. | |
134 | * @param conn Descriptor of socket to set the mark for | |
135 | */ | |
136 | int doNfmarkLocalHit(const Comm::ConnectionPointer &conn); | |
b5523edc | 137 | |
dc49061a A |
138 | /** |
139 | * Function to set the TOS value of packets. Sets the value on the socket | |
140 | * which then gets copied to the packets. | |
141 | * @param conn Descriptor of socket to set the TOS for | |
142 | */ | |
912864c2 | 143 | int setSockTos(const Comm::ConnectionPointer &conn, tos_t tos); |
b5523edc | 144 | |
c6f168c1 CT |
145 | /** |
146 | * The low level variant of setSockTos function to set TOS value of packets. | |
147 | * Avoid if you can use the Connection-based setSockTos(). | |
148 | * @param fd Descriptor of socket to set the TOS for | |
149 | * @param type The socket family, AF_INET or AF_INET6 | |
150 | */ | |
912864c2 | 151 | int setSockTos(const int fd, tos_t tos, int type); |
c6f168c1 | 152 | |
dc49061a A |
153 | /** |
154 | * Function to set the netfilter mark value of packets. Sets the value on the | |
155 | * socket which then gets copied to the packets. Called from Ip::Qos::doNfmarkLocalMiss | |
156 | * @param conn Descriptor of socket to set the mark for | |
157 | */ | |
912864c2 | 158 | int setSockNfmark(const Comm::ConnectionPointer &conn, nfmark_t mark); |
425de4c8 | 159 | |
c6f168c1 CT |
160 | /** |
161 | * The low level variant of setSockNfmark function to set the netfilter mark | |
162 | * value of packets. | |
163 | * Avoid if you can use the Connection-based setSockNfmark(). | |
164 | * @param fd Descriptor of socket to set the mark for | |
165 | */ | |
912864c2 | 166 | int setSockNfmark(const int fd, nfmark_t mark); |
c6f168c1 | 167 | |
425de4c8 AJ |
168 | /** |
169 | * QOS configuration class. Contains all the parameters for QOS functions as well | |
170 | * as functions to check whether either TOS or MARK QOS is enabled. | |
171 | */ | |
172 | class Config | |
575cb927 AJ |
173 | { |
174 | public: | |
575cb927 | 175 | |
425de4c8 | 176 | Config(); |
d6d0eb11 | 177 | ~Config() {} |
575cb927 AJ |
178 | |
179 | void parseConfigLine(); | |
425de4c8 AJ |
180 | |
181 | /** | |
182 | * Dump all the configuration values | |
183 | * | |
184 | * NOTE: Due to the low-level nature of the library these | |
185 | * objects are part of the dump function must be self-contained. | |
186 | * which means no StoreEntry references. Just a basic char* buffer. | |
187 | */ | |
dbe6f864 | 188 | void dumpConfigLine(char *entry, const char *name) const; |
425de4c8 AJ |
189 | |
190 | /// Whether we should modify TOS flags based on cache hits and misses. | |
912864c2 AJ |
191 | bool isHitTosActive() const { |
192 | return (tosLocalHit || tosSiblingHit || tosParentHit || tosMiss || preserveMissTos); | |
193 | } | |
ab745b44 | 194 | |
425de4c8 | 195 | /// Whether we should modify netfilter marks based on cache hits and misses. |
912864c2 AJ |
196 | bool isHitNfmarkActive() const { |
197 | return (markLocalHit || markSiblingHit || markParentHit || markMiss || preserveMissMark); | |
198 | } | |
425de4c8 AJ |
199 | |
200 | /** | |
201 | * Iterates through any outgoing_nfmark or clientside_nfmark configuration parameters | |
202 | * to find out if any Netfilter marking is required. | |
203 | * This function is used on initialisation to define capabilities required (Netfilter | |
204 | * marking requires CAP_NET_ADMIN). | |
b5523edc | 205 | */ |
912864c2 | 206 | bool isAclNfmarkActive() const; |
425de4c8 AJ |
207 | |
208 | /** | |
209 | * Iterates through any outgoing_tos or clientside_tos configuration parameters | |
210 | * to find out if packets should be marked with TOS flags. | |
211 | */ | |
912864c2 | 212 | bool isAclTosActive() const; |
425de4c8 AJ |
213 | |
214 | tos_t tosLocalHit; ///< TOS value to apply to local cache hits | |
215 | tos_t tosSiblingHit; ///< TOS value to apply to hits from siblings | |
216 | tos_t tosParentHit; ///< TOS value to apply to hits from parent | |
217 | tos_t tosMiss; ///< TOS value to apply to cache misses | |
a29d2a95 | 218 | tos_t tosMissMask; ///< Mask for TOS value to apply to cache misses. Applied to the tosMiss value. |
425de4c8 | 219 | bool preserveMissTos; ///< Whether to preserve the TOS value of the inbound packet for misses |
a29d2a95 | 220 | tos_t preserveMissTosMask; ///< The mask to apply when preserving the TOS of misses. Applies to preserved value from upstream. |
425de4c8 AJ |
221 | |
222 | nfmark_t markLocalHit; ///< Netfilter mark value to apply to local cache hits | |
223 | nfmark_t markSiblingHit; ///< Netfilter mark value to apply to hits from siblings | |
224 | nfmark_t markParentHit; ///< Netfilter mark value to apply to hits from parent | |
225 | nfmark_t markMiss; ///< Netfilter mark value to apply to cache misses | |
a29d2a95 | 226 | nfmark_t markMissMask; ///< Mask for netfilter mark value to apply to cache misses. Applied to the markMiss value. |
425de4c8 | 227 | bool preserveMissMark; ///< Whether to preserve netfilter mark value of inbound connection |
a29d2a95 | 228 | nfmark_t preserveMissMarkMask; ///< The mask to apply when preserving the netfilter mark of misses. Applied to preserved value from upstream. |
425de4c8 AJ |
229 | |
230 | acl_tos *tosToServer; ///< The TOS that packets to the web server should be marked with, based on ACL | |
231 | acl_tos *tosToClient; ///< The TOS that packets to the client should be marked with, based on ACL | |
232 | acl_nfmark *nfmarkToServer; ///< The MARK that packets to the web server should be marked with, based on ACL | |
233 | acl_nfmark *nfmarkToClient; ///< The MARK that packets to the client should be marked with, based on ACL | |
244da4ad | 234 | acl_nfmark *nfConnmarkToClient = nullptr; ///< The CONNMARK that the client connection should be marked with, based on ACL |
425de4c8 | 235 | |
575cb927 AJ |
236 | }; |
237 | ||
425de4c8 AJ |
238 | /// Globally available instance of Qos::Config |
239 | extern Config TheConfig; | |
b7ac5457 | 240 | |
575cb927 | 241 | /* legacy parser access wrappers */ |
f53969cc | 242 | #define parse_QosConfig(X) (X)->parseConfigLine() |
575cb927 | 243 | #define free_QosConfig(X) |
dbe6f864 | 244 | #define dump_QosConfig(e,n,X) do { \ |
f53969cc SM |
245 | char temp[256]; /* random number. change as needed. max config line length. */ \ |
246 | (X).dumpConfigLine(temp,n); \ | |
247 | storeAppendPrintf(e, "%s", temp); \ | |
248 | } while(0); | |
575cb927 | 249 | |
e5519212 | 250 | } // namespace Qos |
425de4c8 | 251 | |
e5519212 | 252 | } // namespace Ip |
b7ac5457 | 253 | |
575cb927 | 254 | #endif /* SQUID_QOSCONFIG_H */ |
f53969cc | 255 |