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