MaxConnection.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
class SquidConfig Config
Definition: SquidConfig.cc:12
virtual bool valid() const
virtual char const * typeString() const
char const * class_
Definition: MaxConnection.h:32
virtual void parse()
parses node representation in squid.conf; dies on failures
virtual SBufList dump() const
virtual bool empty() const
ACLMaxConnection(char const *)
virtual void prepareForUse()
virtual int match(ACLChecklist *checklist)
Matches the actual data in checklist against this ACL.
char name[ACL_NAME_SZ]
Definition: Acl.h:81
static char * strtokFile()
Definition: ConfigParser.cc:64
Definition: SBuf.h:94
SBuf & Printf(const char *fmt,...)
Definition: SBuf.cc:214
struct SquidConfig::@110 onoff
int clientdbEstablished(const Ip::Address &addr, int delta)
Definition: client_db.cc:182
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
#define DBG_CRITICAL
Definition: Stream.h:40
std::list< SBuf > SBufList
Definition: forward.h:22

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors