]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ip/QosConfig.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ip / QosConfig.h
CommitLineData
bbc27441 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
bbc27441
AJ
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
575cb927
AJ
9#ifndef SQUID_QOSCONFIG_H
10#define SQUID_QOSCONFIG_H
11
6f58d7d7 12#include "acl/forward.h"
425de4c8 13#include "hier_code.h"
b5523edc 14#include "ip/forward.h"
575cb927 15
425de4c8
AJ
16#if HAVE_LIBNETFILTER_CONNTRACK_LIBNETFILTER_CONNTRACK_H
17#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
18#endif
425de4c8
AJ
19#if HAVE_LIBNETFILTER_CONNTRACK_LIBNETFILTER_CONNTRACK_TCP_H
20#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
21#endif
425de4c8 22#include <limits>
425de4c8 23
425de4c8 24class fde;
575cb927 25
b0b24108 26// TODO: move to new ACL framework
e4a14600
A
27class acl_tos
28{
60019fea
AJ
29 CBDATA_CLASS(acl_tos);
30
b0b24108 31public:
cc8c4af2 32 acl_tos() : next(NULL), aclList(NULL), tos(0) {}
60019fea
AJ
33 ~acl_tos();
34
b0b24108
FC
35 acl_tos *next;
36 ACLList *aclList;
37 tos_t tos;
38};
60019fea 39
b0b24108 40// TODO: move to new ACL framework
e4a14600
A
41class acl_nfmark
42{
60019fea
AJ
43 CBDATA_CLASS(acl_nfmark);
44
b0b24108 45public:
cc8c4af2 46 acl_nfmark() : next(NULL), aclList(NULL), nfmark(0) {}
60019fea
AJ
47 ~acl_nfmark();
48
b0b24108
FC
49 acl_nfmark *next;
50 ACLList *aclList;
51 nfmark_t nfmark;
52};
53
63bd4bf7
A
54namespace Ip
55{
b7ac5457 56
425de4c8
AJ
57/**
58 * QOS namespace contains all the QOS functionality: global functions within
59 * the namespace and the configuration parameters within a config class.
60 */
63bd4bf7
A
61namespace Qos
62{
b7ac5457 63
dc49061a
A
64/**
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
70*/
71void getTosFromServer(const Comm::ConnectionPointer &server, fde *clientFde);
b5523edc 72
dc49061a
A
73/**
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
79*/
80void getNfmarkFromServer(const Comm::ConnectionPointer &server, const fde *clientFde);
425de4c8
AJ
81
82#if USE_LIBNETFILTERCONNTRACK
dc49061a
A
83/**
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
91*/
92int getNfMarkCallback(enum nf_conntrack_msg_type type, struct nf_conntrack *ct, void *clientFde);
425de4c8
AJ
93#endif
94
dc49061a
A
95/**
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
99* enabled for TOS.
100* @param conn Descriptor of socket to set the TOS for
101* @param hierCode Hier code of request
102*/
103int doTosLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode);
b5523edc 104
dc49061a
A
105/**
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
112*/
113int doNfmarkLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode);
b5523edc 114
dc49061a
A
115/**
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
119* enabled for TOS.
120* @param conn Descriptor of socket to set the TOS for
121*/
122int doTosLocalHit(const Comm::ConnectionPointer &conn);
b5523edc 123
dc49061a
A
124/**
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
130*/
131int doNfmarkLocalHit(const Comm::ConnectionPointer &conn);
b5523edc 132
dc49061a
A
133/**
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
137*/
138_SQUID_INLINE_ int setSockTos(const Comm::ConnectionPointer &conn, tos_t tos);
b5523edc 139
c6f168c1
CT
140/**
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
145*/
146_SQUID_INLINE_ int setSockTos(const int fd, tos_t tos, int type);
147
dc49061a
A
148/**
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
152*/
153_SQUID_INLINE_ int setSockNfmark(const Comm::ConnectionPointer &conn, nfmark_t mark);
425de4c8 154
c6f168c1
CT
155/**
156* The low level variant of setSockNfmark function to set the netfilter mark
157* value of packets.
158* Avoid if you can use the Connection-based setSockNfmark().
159* @param fd Descriptor of socket to set the mark for
160*/
161_SQUID_INLINE_ int setSockNfmark(const int fd, nfmark_t mark);
162
425de4c8
AJ
163/**
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.
166 */
167class Config
575cb927
AJ
168{
169public:
575cb927 170
425de4c8 171 Config();
d6d0eb11 172 ~Config() {}
575cb927
AJ
173
174 void parseConfigLine();
425de4c8
AJ
175
176 /**
177 * Dump all the configuration values
178 *
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.
182 */
dbe6f864 183 void dumpConfigLine(char *entry, const char *name) const;
425de4c8
AJ
184
185 /// Whether we should modify TOS flags based on cache hits and misses.
186 _SQUID_INLINE_ bool isHitTosActive() const;
ab745b44 187
425de4c8
AJ
188 /// Whether we should modify netfilter marks based on cache hits and misses.
189 _SQUID_INLINE_ bool isHitNfmarkActive() const;
190
191 /**
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).
b5523edc 196 */
425de4c8
AJ
197 _SQUID_INLINE_ bool isAclNfmarkActive() const;
198
199 /**
200 * Iterates through any outgoing_tos or clientside_tos configuration parameters
201 * to find out if packets should be marked with TOS flags.
202 */
203 _SQUID_INLINE_ bool isAclTosActive() const;
204
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
a29d2a95 209 tos_t tosMissMask; ///< Mask for TOS value to apply to cache misses. Applied to the tosMiss value.
425de4c8 210 bool preserveMissTos; ///< Whether to preserve the TOS value of the inbound packet for misses
a29d2a95 211 tos_t preserveMissTosMask; ///< The mask to apply when preserving the TOS of misses. Applies to preserved value from upstream.
425de4c8
AJ
212
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
a29d2a95 217 nfmark_t markMissMask; ///< Mask for netfilter mark value to apply to cache misses. Applied to the markMiss value.
425de4c8 218 bool preserveMissMark; ///< Whether to preserve netfilter mark value of inbound connection
a29d2a95 219 nfmark_t preserveMissMarkMask; ///< The mask to apply when preserving the netfilter mark of misses. Applied to preserved value from upstream.
425de4c8
AJ
220
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
225
575cb927
AJ
226};
227
425de4c8
AJ
228/// Globally available instance of Qos::Config
229extern Config TheConfig;
b7ac5457 230
575cb927 231/* legacy parser access wrappers */
f53969cc 232#define parse_QosConfig(X) (X)->parseConfigLine()
575cb927 233#define free_QosConfig(X)
dbe6f864 234#define dump_QosConfig(e,n,X) do { \
f53969cc
SM
235 char temp[256]; /* random number. change as needed. max config line length. */ \
236 (X).dumpConfigLine(temp,n); \
237 storeAppendPrintf(e, "%s", temp); \
238 } while(0);
575cb927 239
e5519212 240} // namespace Qos
425de4c8 241
e5519212 242} // namespace Ip
b7ac5457 243
425de4c8
AJ
244#if _USE_INLINE_
245#include "Qos.cci"
246#endif
247
575cb927 248#endif /* SQUID_QOSCONFIG_H */
f53969cc 249