]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/MaxConnection.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / MaxConnection.cc
1 /*
2 * Copyright (C) 1996-2017 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/FilledChecklist.h"
13 #include "acl/MaxConnection.h"
14 #include "client_db.h"
15 #include "Debug.h"
16 #include "SquidConfig.h"
17
18 ACL *
19 ACLMaxConnection::clone() const
20 {
21 return new ACLMaxConnection(*this);
22 }
23
24 ACLMaxConnection::ACLMaxConnection (char const *theClass) : class_ (theClass), limit(-1)
25 {}
26
27 ACLMaxConnection::ACLMaxConnection (ACLMaxConnection const & old) :class_ (old.class_), limit (old.limit)
28 {}
29
30 ACLMaxConnection::~ACLMaxConnection()
31 {}
32
33 char const *
34 ACLMaxConnection::typeString() const
35 {
36 return class_;
37 }
38
39 bool
40 ACLMaxConnection::empty () const
41 {
42 return false;
43 }
44
45 bool
46 ACLMaxConnection::valid () const
47 {
48 return limit > 0;
49 }
50
51 void
52 ACLMaxConnection::parse()
53 {
54 char *t = ConfigParser::strtokFile();
55
56 if (!t)
57 return;
58
59 limit = (atoi (t));
60
61 /* suck out file contents */
62 // ignore comments
63 bool ignore = false;
64 while ((t = ConfigParser::strtokFile())) {
65 ignore |= (*t != '#');
66
67 if (ignore)
68 continue;
69
70 debugs(89, DBG_CRITICAL, "WARNING: max_conn only accepts a single limit value.");
71 limit = 0;
72 }
73 }
74
75 int
76 ACLMaxConnection::match(ACLChecklist *checklist)
77 {
78 return clientdbEstablished(Filled(checklist)->src_addr, 0) > limit ? 1 : 0;
79 }
80
81 SBufList
82 ACLMaxConnection::dump() const
83 {
84 SBufList sl;
85 if (!limit)
86 return sl;
87
88 SBuf s;
89 s.Printf("%d", limit);
90 sl.push_back(s);
91 return sl;
92 }
93
94 void
95 ACLMaxConnection::prepareForUse()
96 {
97 if (0 != Config.onoff.client_db)
98 return;
99
100 debugs(22, DBG_CRITICAL, "WARNING: 'maxconn' ACL (" << name << ") won't work with client_db disabled");
101 }
102