MaxConnection.cc
Go to the documentation of this file.
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 *
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 
31 {}
32 
33 char const *
35 {
36  return class_;
37 }
38 
39 bool
41 {
42  return false;
43 }
44 
45 bool
47 {
48  return limit > 0;
49 }
50 
51 void
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
77 {
78  return clientdbEstablished(Filled(checklist)->src_addr, 0) > limit ? 1 : 0;
79 }
80 
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
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 
virtual bool valid() const
char const * class_
Definition: MaxConnection.h:35
virtual ACL * clone() const
virtual void prepareForUse()
Definition: SBuf.h:87
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
Definition: Acl.h:39
int clientdbEstablished(const Ip::Address &addr, int delta)
Definition: client_db.cc:183
#define DBG_CRITICAL
Definition: Debug.h:44
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
virtual bool empty() const
ACLMaxConnection(char const *)
SBuf & Printf(const char *fmt,...)
Definition: SBuf.cc:236
std::list< SBuf > SBufList
Definition: forward.h:26
struct SquidConfig::@112 onoff
virtual void parse()
parses node represenation in squid.conf; dies on failures
virtual char const * typeString() const
static char * strtokFile()
Definition: ConfigParser.cc:82
virtual int match(ACLChecklist *checklist)
Matches the actual data in checklist against this ACL.
virtual SBufList dump() const
char name[ACL_NAME_SZ]
Definition: Acl.h:83
class SquidConfig Config
Definition: SquidConfig.cc:12

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors