ConnMark.cc
Go to the documentation of this file.
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 /* DEBUG: section 28 Access Control */
10 
11 #include "squid.h"
12 #include "acl/ConnMark.h"
13 #include "acl/FilledChecklist.h"
14 #include "client_side.h"
15 #include "Debug.h"
16 #include "http/Stream.h"
17 #include "sbuf/Stream.h"
18 
19 bool
21 {
22  return false;
23 }
24 
25 static std::ostream &
26 operator <<(std::ostream &os, const Acl::ConnMark::ConnMarkQuery connmark)
27 {
28  os << asHex(connmark.first);
29  if (connmark.second != 0xffffffff) {
30  os << '/' << asHex(connmark.second);
31  }
32  return os;
33 }
34 
36 Acl::ConnMark::getNumber(Parser::Tokenizer &tokenizer, const SBuf &token) const
37 {
38  int64_t number;
39  if (!tokenizer.int64(number, 0, false)) {
40  throw TexcHere(ToSBuf("acl ", typeString(), ": invalid value '", tokenizer.buf(), "' in ", token));
41  }
42 
43  if (number > std::numeric_limits<nfmark_t>::max()) {
44  throw TexcHere(ToSBuf("acl ", typeString(), ": number ", number, " in ", token, " is too big"));
45  }
46  return static_cast<nfmark_t>(number);
47 }
48 
49 void
51 {
52  while (const char *t = ConfigParser::strtokFile()) {
53  SBuf token(t);
54  Parser::Tokenizer tokenizer(token);
55 
56  const auto mark = getNumber(tokenizer, token);
57  const auto mask = tokenizer.skip('/') ? getNumber(tokenizer, token) : 0xffffffff;
58 
59  if (!tokenizer.atEnd()) {
60  throw TexcHere(ToSBuf("acl ", typeString(), ": trailing garbage in ", token));
61  }
62 
63  const ConnMarkQuery connmark(mark, mask);
64  marks.push_back(connmark);
65  debugs(28, 7, "added " << connmark);
66  }
67 
68  if (marks.empty()) {
69  throw TexcHere(ToSBuf("acl ", typeString(), " requires at least one mark"));
70  }
71 }
72 
73 int
75 {
76  const auto *checklist = Filled(cl);
77  const auto connmark = checklist->conn()->clientConnection->nfmark;
78 
79  for (const auto &m : marks) {
80  if ((connmark & m.second) == m.first) {
81  debugs(28, 5, "found " << m << " matching " << asHex(connmark));
82  return 1;
83  }
84  debugs(28, 7, "skipped " << m << " mismatching " << asHex(connmark));
85  }
86  return 0;
87 }
88 
91 {
92  SBufList sl;
93  for (const auto &m : marks) {
94  sl.push_back(ToSBuf(m));
95  }
96  return sl;
97 }
98 
99 char const *
101 {
102  return "clientside_mark";
103 }
104 
virtual void parse() override
parses node represenation in squid.conf; dies on failures
Definition: ConnMark.cc:50
Definition: SBuf.h:87
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
virtual int match(ACLChecklist *checklist) override
Matches the actual data in checklist against this ACL.
Definition: ConnMark.cc:74
A const & max(A const &lhs, A const &rhs)
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:121
virtual char const * typeString() const override
Definition: ConnMark.cc:100
bool atEnd() const
whether the end of the buffer has been reached
Definition: Tokenizer.h:41
nfmark_t getNumber(Parser::Tokenizer &tokenizer, const SBuf &token) const
Definition: ConnMark.cc:36
AsHex< Integer > asHex(const Integer n)
a helper to ease AsHex object creation
Definition: Debug.h:268
std::list< SBuf > SBufList
Definition: forward.h:22
bool skip(const SBuf &tokenToSkip)
Definition: Tokenizer.cc:160
static std::ostream & operator<<(std::ostream &os, const Acl::ConnMark::ConnMarkQuery connmark)
Definition: ConnMark.cc:26
number
Definition: testStatHist.cc:16
SBuf ToSBuf(Args &&...args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:124
static char * strtokFile()
Definition: ConfigParser.cc:82
virtual bool empty() const override
Definition: ConnMark.cc:20
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
Definition: TextException.h:55
virtual SBufList dump() const override
Definition: ConnMark.cc:90
std::pair< nfmark_t, nfmark_t > ConnMarkQuery
a mark/mask pair for matching CONNMARKs
Definition: ConnMark.h:33
uint32_t nfmark_t
Definition: forward.h:25
SBuf buf() const
yet unparsed data
Definition: Tokenizer.h:35
bool int64(int64_t &result, int base=0, bool allowSign=true, SBuf::size_type limit=SBuf::npos)
Definition: Tokenizer.cc:209

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors