]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ip/NfMarkConfig.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / ip / NfMarkConfig.h
CommitLineData
244da4ad 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
244da4ad
AG
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
14class SBuf;
15
16namespace Ip
17{
18
19/// a netfilter mark/mask pair
20class NfMarkConfig
21{
22public:
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
47std::ostream &operator <<(std::ostream &os, const Ip::NfMarkConfig connmark);
48
49#endif // SQUID_NFMARKCONFIG_H
45e49ce3 50