MaxConnection.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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/Stream.h"
16 #include "SquidConfig.h"
17 
18 ACLMaxConnection::ACLMaxConnection (char const *theClass) : class_ (theClass), limit(-1)
19 {}
20 
22 {}
23 
24 char const *
26 {
27  return class_;
28 }
29 
30 bool
32 {
33  return false;
34 }
35 
36 bool
38 {
39  return limit > 0;
40 }
41 
42 void
44 {
45  char *t = ConfigParser::strtokFile();
46 
47  if (!t)
48  return;
49 
50  limit = (atoi (t));
51 
52  /* suck out file contents */
53  // ignore comments
54  bool ignore = false;
55  while ((t = ConfigParser::strtokFile())) {
56  ignore |= (*t != '#');
57 
58  if (ignore)
59  continue;
60 
61  debugs(89, DBG_CRITICAL, "WARNING: max_conn only accepts a single limit value.");
62  limit = 0;
63  }
64 }
65 
66 int
68 {
69  return clientdbEstablished(Filled(checklist)->src_addr, 0) > limit ? 1 : 0;
70 }
71 
74 {
75  SBufList sl;
76  if (!limit)
77  return sl;
78 
79  SBuf s;
80  s.Printf("%d", limit);
81  sl.push_back(s);
82  return sl;
83 }
84 
85 void
87 {
88  if (0 != Config.onoff.client_db)
89  return;
90 
91  debugs(22, DBG_CRITICAL, "WARNING: 'maxconn' ACL (" << name << ") won't work with client_db disabled");
92 }
93 
SBufList dump() const override
void push_back(char)
Append a single character. The character may be NUL (\0).
Definition: SBuf.cc:208
#define DBG_CRITICAL
Definition: Stream.h:37
static char * strtokFile()
Definition: ConfigParser.cc:65
bool empty() const override
std::list< SBuf > SBufList
Definition: forward.h:22
Definition: SBuf.h:93
ACLMaxConnection(char const *)
int clientdbEstablished(const Ip::Address &addr, int delta)
Definition: client_db.cc:182
struct SquidConfig::@97 onoff
void prepareForUse() override
void parse() override
parses node representation in squid.conf; dies on failures
const char * typeString() const override
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
SBuf & Printf(const char *fmt,...) PRINTF_FORMAT_ARG2
Definition: SBuf.cc:214
bool valid() const override
~ACLMaxConnection() override
const char * class_
Definition: MaxConnection.h:32
int match(ACLChecklist *checklist) override
Matches the actual data in checklist against this Acl::Node.
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
class SquidConfig Config
Definition: SquidConfig.cc:12
SBuf name
Definition: Node.h:81

 

Introduction

Documentation

Support

Miscellaneous