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