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