2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_QOSCONFIG_H
10 #define SQUID_QOSCONFIG_H
12 #include "acl/forward.h"
13 #include "hier_code.h"
14 #include "ip/forward.h"
16 #if HAVE_LIBNETFILTER_CONNTRACK_LIBNETFILTER_CONNTRACK_H
17 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
19 #if HAVE_LIBNETFILTER_CONNTRACK_LIBNETFILTER_CONNTRACK_TCP_H
20 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
26 // TODO: move to new ACL framework
29 CBDATA_CLASS(acl_tos
);
32 acl_tos() : next(NULL
), aclList(NULL
), tos(0) {}
40 // TODO: move to new ACL framework
43 CBDATA_CLASS(acl_nfmark
);
46 acl_nfmark() : next(NULL
), aclList(NULL
), nfmark(0) {}
58 * QOS namespace contains all the QOS functionality: global functions within
59 * the namespace and the configuration parameters within a config class.
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
71 void getTosFromServer(const Comm::ConnectionPointer
&server
, fde
*clientFde
);
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
80 void getNfmarkFromServer(const Comm::ConnectionPointer
&server
, const fde
*clientFde
);
82 #if USE_LIBNETFILTERCONNTRACK
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
92 int getNfMarkCallback(enum nf_conntrack_msg_type type
, struct nf_conntrack
*ct
, void *clientFde
);
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
100 * @param conn Descriptor of socket to set the TOS for
101 * @param hierCode Hier code of request
103 int doTosLocalMiss(const Comm::ConnectionPointer
&conn
, const hier_code hierCode
);
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
113 int doNfmarkLocalMiss(const Comm::ConnectionPointer
&conn
, const hier_code hierCode
);
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
120 * @param conn Descriptor of socket to set the TOS for
122 int doTosLocalHit(const Comm::ConnectionPointer
&conn
);
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
131 int doNfmarkLocalHit(const Comm::ConnectionPointer
&conn
);
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
138 _SQUID_INLINE_
int setSockTos(const Comm::ConnectionPointer
&conn
, tos_t tos
);
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
146 _SQUID_INLINE_
int setSockTos(const int fd
, tos_t tos
, int type
);
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
153 _SQUID_INLINE_
int setSockNfmark(const Comm::ConnectionPointer
&conn
, nfmark_t mark
);
156 * The low level variant of setSockNfmark function to set the netfilter mark
158 * Avoid if you can use the Connection-based setSockNfmark().
159 * @param fd Descriptor of socket to set the mark for
161 _SQUID_INLINE_
int setSockNfmark(const int fd
, nfmark_t mark
);
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.
174 void parseConfigLine();
177 * Dump all the configuration values
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.
183 void dumpConfigLine(char *entry
, const char *name
) const;
185 /// Whether we should modify TOS flags based on cache hits and misses.
186 _SQUID_INLINE_
bool isHitTosActive() const;
188 /// Whether we should modify netfilter marks based on cache hits and misses.
189 _SQUID_INLINE_
bool isHitNfmarkActive() const;
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).
197 _SQUID_INLINE_
bool isAclNfmarkActive() const;
200 * Iterates through any outgoing_tos or clientside_tos configuration parameters
201 * to find out if packets should be marked with TOS flags.
203 _SQUID_INLINE_
bool isAclTosActive() const;
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.
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.
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
228 /// Globally available instance of Qos::Config
229 extern Config TheConfig
;
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); \
248 #endif /* SQUID_QOSCONFIG_H */