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