NfMarkConfig.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 #include "squid.h"
10 
11 #include "ConfigParser.h"
12 #include "ip/NfMarkConfig.h"
13 #include "parser/Tokenizer.h"
14 #include "sbuf/Stream.h"
15 
16 #include <limits>
17 
18 static nfmark_t
19 getNfmark(Parser::Tokenizer &tokenizer, const SBuf &token)
20 {
21  int64_t number;
22  if (!tokenizer.int64(number, 0, false))
23  throw TexcHere(ToSBuf("NfMarkConfig: invalid value '", tokenizer.buf(), "' in '", token, "'"));
24 
26  throw TexcHere(ToSBuf("NfMarkConfig: number, ", number, "in '", token, "' is too big"));
27 
28  return static_cast<nfmark_t>(number);
29 }
30 
33 {
34  Parser::Tokenizer tokenizer(token);
35 
36  const nfmark_t mark = getNfmark(tokenizer, token);
37  const nfmark_t mask = tokenizer.skip('/') ? getNfmark(tokenizer, token) : 0xffffffff;
38 
39  if (!tokenizer.atEnd())
40  throw TexcHere(ToSBuf("NfMarkConfig: trailing garbage in '", token, "'"));
41 
42  return Ip::NfMarkConfig(mark, mask);
43 }
44 
47 {
48  return (m & ~mask) | mark;
49 }
50 
51 std::ostream &
52 operator <<(std::ostream &os, const Ip::NfMarkConfig c)
53 {
54  os << asHex(c.mark);
55 
56  if (c.mask != 0xffffffff)
57  os << '/' << asHex(c.mask);
58 
59  return os;
60 }
61 
Definition: SBuf.h:86
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:124
A const & max(A const &lhs, A const &rhs)
a netfilter mark/mask pair
Definition: NfMarkConfig.h:20
static NfMarkConfig Parse(const SBuf &token)
parses a token and returns an object, expects a "mark[/mask]" format
Definition: NfMarkConfig.cc:32
static nfmark_t getNfmark(Parser::Tokenizer &tokenizer, const SBuf &token)
Definition: NfMarkConfig.cc:19
SBuf buf() const
yet unparsed data
Definition: Tokenizer.h:35
AsHex< Integer > asHex(const Integer n)
a helper to ease AsHex object creation
Definition: Debug.h:278
bool skip(const SBuf &tokenToSkip)
Definition: Tokenizer.cc:179
bool atEnd() const
whether the end of the buffer has been reached
Definition: Tokenizer.h:41
number
Definition: testStatHist.cc:16
std::ostream & operator<<(std::ostream &os, const Address &ipa)
Definition: Address.h:352
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
Definition: TextException.h:55
nfmark_t applyToMark(nfmark_t m) const
Definition: NfMarkConfig.cc:46
uint32_t nfmark_t
Definition: forward.h:25
bool int64(int64_t &result, int base=0, bool allowSign=true, SBuf::size_type limit=SBuf::npos)
Definition: Tokenizer.cc:228

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors