]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ip/QosConfig.h
Fix tcp outgoing tos bugs
[thirdparty/squid.git] / src / ip / QosConfig.h
1 #ifndef SQUID_QOSCONFIG_H
2 #define SQUID_QOSCONFIG_H
3
4 #include "acl/forward.h"
5 #include "hier_code.h"
6 #include "ip/forward.h"
7
8 #if HAVE_LIBNETFILTER_CONNTRACK_LIBNETFILTER_CONNTRACK_H
9 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
10 #endif
11 #if HAVE_LIBNETFILTER_CONNTRACK_LIBNETFILTER_CONNTRACK_TCP_H
12 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
13 #endif
14 #include <limits>
15
16 class fde;
17
18 // TODO: move to new ACL framework
19 // not integrated in namespace, as this class uses a strange CBDATA definition
20 // POD
21 class acl_tos
22 {
23 public:
24 acl_tos *next;
25 ACLList *aclList;
26 tos_t tos;
27 };
28 // TODO: move to new ACL framework
29 // not integrated in namespace, as this class uses a strange CBDATA definition
30 // POD
31 class acl_nfmark
32 {
33 public:
34 acl_nfmark *next;
35 ACLList *aclList;
36 nfmark_t nfmark;
37 };
38
39 namespace Ip
40 {
41
42 /**
43 * QOS namespace contains all the QOS functionality: global functions within
44 * the namespace and the configuration parameters within a config class.
45 */
46 namespace Qos
47 {
48
49 /**
50 * Function to retrieve the TOS value of the inbound packet.
51 * Called by FwdState::dispatch if QOS options are enabled.
52 * Bug 2537: This part of ZPH only applies to patched Linux kernels
53 * @param server Server side descriptor of connection to get TOS for
54 * @param clientFde Pointer to client side fde instance to set tosFromServer in
55 */
56 void getTosFromServer(const Comm::ConnectionPointer &server, fde *clientFde);
57
58 /**
59 * Function to retrieve the netfilter mark value of the connection
60 * to the upstream server. Called by FwdState::dispatch if QOS
61 * options are enabled.
62 * @param server Server side descriptor of connection to get mark for
63 * @param clientFde Pointer to client side fde instance to set nfmarkFromServer in
64 */
65 void getNfmarkFromServer(const Comm::ConnectionPointer &server, const fde *clientFde);
66
67 #if USE_LIBNETFILTERCONNTRACK
68 /**
69 * Callback function to mark connection once it's been found.
70 * This function is called by the libnetfilter_conntrack
71 * libraries, during nfct_query in Ip::Qos::getNfmarkFromServer.
72 * nfct_callback_register is used to register this function.
73 * @param nf_conntrack_msg_type Type of conntrack message
74 * @param nf_conntrack Pointer to the conntrack structure
75 * @param clientFde Pointer to client side fde instance to set nfmarkFromServer in
76 */
77 int getNfMarkCallback(enum nf_conntrack_msg_type type, struct nf_conntrack *ct, void *clientFde);
78 #endif
79
80 /**
81 * Function to work out and then apply to the socket the appropriate
82 * TOS value to set on packets when items have not been retrieved from
83 * local cache. Called by clientReplyContext::sendMoreData if QOS is
84 * enabled for TOS.
85 * @param conn Descriptor of socket to set the TOS for
86 * @param hierCode Hier code of request
87 */
88 int doTosLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode);
89
90 /**
91 * Function to work out and then apply to the socket the appropriate
92 * netfilter mark value to set on packets when items have not been
93 * retrieved from local cache. Called by clientReplyContext::sendMoreData
94 * if QOS is enabled for TOS.
95 * @param conn Descriptor of socket to set the mark for
96 * @param hierCode Hier code of request
97 */
98 int doNfmarkLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode);
99
100 /**
101 * Function to work out and then apply to the socket the appropriate
102 * TOS value to set on packets when items *have* been retrieved from
103 * local cache. Called by clientReplyContext::doGetMoreData if QOS is
104 * enabled for TOS.
105 * @param conn Descriptor of socket to set the TOS for
106 */
107 int doTosLocalHit(const Comm::ConnectionPointer &conn);
108
109 /**
110 * Function to work out and then apply to the socket the appropriate
111 * netfilter mark value to set on packets when items *have* been
112 * retrieved from local cache. Called by clientReplyContext::doGetMoreData
113 * if QOS is enabled for TOS.
114 * @param conn Descriptor of socket to set the mark for
115 */
116 int doNfmarkLocalHit(const Comm::ConnectionPointer &conn);
117
118 /**
119 * Function to set the TOS value of packets. Sets the value on the socket
120 * which then gets copied to the packets.
121 * @param conn Descriptor of socket to set the TOS for
122 */
123 _SQUID_INLINE_ int setSockTos(const Comm::ConnectionPointer &conn, tos_t tos);
124
125 /**
126 * The low level variant of setSockTos function to set TOS value of packets.
127 * Avoid if you can use the Connection-based setSockTos().
128 * @param fd Descriptor of socket to set the TOS for
129 * @param type The socket family, AF_INET or AF_INET6
130 */
131 _SQUID_INLINE_ int setSockTos(const int fd, tos_t tos, int type);
132
133 /**
134 * Function to set the netfilter mark value of packets. Sets the value on the
135 * socket which then gets copied to the packets. Called from Ip::Qos::doNfmarkLocalMiss
136 * @param conn Descriptor of socket to set the mark for
137 */
138 _SQUID_INLINE_ int setSockNfmark(const Comm::ConnectionPointer &conn, nfmark_t mark);
139
140 /**
141 * The low level variant of setSockNfmark function to set the netfilter mark
142 * value of packets.
143 * Avoid if you can use the Connection-based setSockNfmark().
144 * @param fd Descriptor of socket to set the mark for
145 */
146 _SQUID_INLINE_ int setSockNfmark(const int fd, nfmark_t mark);
147
148 /**
149 * QOS configuration class. Contains all the parameters for QOS functions as well
150 * as functions to check whether either TOS or MARK QOS is enabled.
151 */
152 class Config
153 {
154 public:
155
156 Config();
157 ~Config() {}
158
159 void parseConfigLine();
160
161 /**
162 * Dump all the configuration values
163 *
164 * NOTE: Due to the low-level nature of the library these
165 * objects are part of the dump function must be self-contained.
166 * which means no StoreEntry references. Just a basic char* buffer.
167 */
168 void dumpConfigLine(char *entry, const char *name) const;
169
170 /// Whether we should modify TOS flags based on cache hits and misses.
171 _SQUID_INLINE_ bool isHitTosActive() const;
172
173 /// Whether we should modify netfilter marks based on cache hits and misses.
174 _SQUID_INLINE_ bool isHitNfmarkActive() const;
175
176 /**
177 * Iterates through any outgoing_nfmark or clientside_nfmark configuration parameters
178 * to find out if any Netfilter marking is required.
179 * This function is used on initialisation to define capabilities required (Netfilter
180 * marking requires CAP_NET_ADMIN).
181 */
182 _SQUID_INLINE_ bool isAclNfmarkActive() const;
183
184 /**
185 * Iterates through any outgoing_tos or clientside_tos configuration parameters
186 * to find out if packets should be marked with TOS flags.
187 */
188 _SQUID_INLINE_ bool isAclTosActive() const;
189
190 tos_t tosLocalHit; ///< TOS value to apply to local cache hits
191 tos_t tosSiblingHit; ///< TOS value to apply to hits from siblings
192 tos_t tosParentHit; ///< TOS value to apply to hits from parent
193 tos_t tosMiss; ///< TOS value to apply to cache misses
194 tos_t tosMissMask; ///< Mask for TOS value to apply to cache misses. Applied to the tosMiss value.
195 bool preserveMissTos; ///< Whether to preserve the TOS value of the inbound packet for misses
196 tos_t preserveMissTosMask; ///< The mask to apply when preserving the TOS of misses. Applies to preserved value from upstream.
197
198 nfmark_t markLocalHit; ///< Netfilter mark value to apply to local cache hits
199 nfmark_t markSiblingHit; ///< Netfilter mark value to apply to hits from siblings
200 nfmark_t markParentHit; ///< Netfilter mark value to apply to hits from parent
201 nfmark_t markMiss; ///< Netfilter mark value to apply to cache misses
202 nfmark_t markMissMask; ///< Mask for netfilter mark value to apply to cache misses. Applied to the markMiss value.
203 bool preserveMissMark; ///< Whether to preserve netfilter mark value of inbound connection
204 nfmark_t preserveMissMarkMask; ///< The mask to apply when preserving the netfilter mark of misses. Applied to preserved value from upstream.
205
206 acl_tos *tosToServer; ///< The TOS that packets to the web server should be marked with, based on ACL
207 acl_tos *tosToClient; ///< The TOS that packets to the client should be marked with, based on ACL
208 acl_nfmark *nfmarkToServer; ///< The MARK that packets to the web server should be marked with, based on ACL
209 acl_nfmark *nfmarkToClient; ///< The MARK that packets to the client should be marked with, based on ACL
210
211 };
212
213 /// Globally available instance of Qos::Config
214 extern Config TheConfig;
215
216 /* legacy parser access wrappers */
217 #define parse_QosConfig(X) (X)->parseConfigLine()
218 #define free_QosConfig(X)
219 #define dump_QosConfig(e,n,X) do { \
220 char temp[256]; /* random number. change as needed. max config line length. */ \
221 (X).dumpConfigLine(temp,n); \
222 storeAppendPrintf(e, "%s", temp); \
223 } while(0);
224
225 } // namespace Qos
226
227 } // namespace Ip
228
229 #if _USE_INLINE_
230 #include "Qos.cci"
231 #endif
232
233 #endif /* SQUID_QOSCONFIG_H */