]>
Commit | Line | Data |
---|---|---|
244da4ad AG |
1 | /* |
2 | * Copyright (C) 1996-2018 The Squid Software Foundation and contributors | |
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 | ||
9 | #ifndef SQUID_NFMARKCONFIG_H | |
10 | #define SQUID_NFMARKCONFIG_H | |
11 | ||
12 | #include "ip/forward.h" | |
13 | ||
14 | class SBuf; | |
15 | ||
16 | namespace Ip | |
17 | { | |
18 | ||
19 | /// a netfilter mark/mask pair | |
20 | class NfMarkConfig | |
21 | { | |
22 | public: | |
23 | /// creates an empty object | |
24 | NfMarkConfig() {} | |
25 | /// creates an object with specified mark and mask | |
26 | NfMarkConfig(nfmark_t mark_val, nfmark_t mask_val): mark(mark_val), mask(mask_val) {} | |
27 | ||
28 | /// parses a token and returns an object, expects a "mark[/mask]" format | |
29 | static NfMarkConfig Parse(const SBuf &token); | |
30 | /// whether the 'm' matches the configured mark/mask | |
31 | bool matches(const nfmark_t m) const { return (m & mask) == mark; } | |
32 | /// whether the netfilter mark is unset | |
33 | bool isEmpty() const { return mark == 0; } | |
34 | /// whether the mask is set | |
35 | bool hasMask() const { return mask != 0xffffffff; } | |
36 | /// Applies configured mark/mask to previously set mark (m). | |
37 | /// m is ANDed with the negated mask and then ORed with the configured mark. | |
38 | /// \returns new mark. This is similar to what iptables --set-mark does. | |
39 | nfmark_t applyToMark(nfmark_t m) const; | |
40 | ||
41 | nfmark_t mark = 0; | |
42 | nfmark_t mask = 0xffffffff; | |
43 | }; | |
44 | ||
45 | } // namespace Ip | |
46 | ||
47 | std::ostream &operator <<(std::ostream &os, const Ip::NfMarkConfig connmark); | |
48 | ||
49 | #endif // SQUID_NFMARKCONFIG_H |