]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/ConnMark.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / acl / ConnMark.cc
1 /*
2 * Copyright (C) 1996-2021 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
20 Acl::ConnMark::empty() const
21 {
22 return false;
23 }
24
25 void
26 Acl::ConnMark::parse()
27 {
28 while (const char *t = ConfigParser::strtokFile()) {
29 SBuf token(t);
30 Parser::Tokenizer tokenizer(token);
31 const auto mc = Ip::NfMarkConfig::Parse(token);
32 marks.push_back(mc);
33 debugs(28, 7, "added " << mc);
34 }
35
36 if (marks.empty()) {
37 throw TexcHere(ToSBuf("acl ", typeString(), " requires at least one mark"));
38 }
39 }
40
41 int
42 Acl::ConnMark::match(ACLChecklist *cl)
43 {
44 const auto *checklist = Filled(cl);
45 const auto conn = checklist->conn();
46
47 if (conn && conn->clientConnection) {
48 const auto connmark = conn->clientConnection->nfConnmark;
49
50 for (const auto &m : marks) {
51 if (m.matches(connmark)) {
52 debugs(28, 5, "found " << m << " matching " << asHex(connmark));
53 return 1;
54 }
55 debugs(28, 7, "skipped " << m << " mismatching " << asHex(connmark));
56 }
57 } else {
58 debugs(28, 7, "fails: no client connection");
59 }
60
61 return 0;
62 }
63
64 SBufList
65 Acl::ConnMark::dump() const
66 {
67 SBufList sl;
68 for (const auto &m : marks) {
69 sl.push_back(ToSBuf(m));
70 }
71 return sl;
72 }
73
74 char const *
75 Acl::ConnMark::typeString() const
76 {
77 return "client_connection_mark";
78 }
79