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