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