context_storage.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 #include "squid.h"
10 #include "base/PackableStream.h"
11 #include "mgr/Registration.h"
12 #include "ssl/context_storage.h"
13 #include "Store.h"
14 
15 #include <limits>
16 #if HAVE_OPENSSL_SSL_H
17 #include <openssl/ssl.h>
18 #endif
19 
21  : Mgr::Action(aCmd)
22 {}
23 
26 {
27  return new CertificateStorageAction(aCmd);
28 }
29 
31 {
32  PackableStream stream(*sentry);
33  const char delimiter = '\t';
34  const char endString = '\n';
35  // Page title.
36  stream << "Cached ssl certificates statistic.\n";
37  // Title of statistic table.
38  stream << "Port" << delimiter << "Max mem(KB)" << delimiter << "Cert number" << delimiter << "KB/cert" << delimiter << "Mem used(KB)" << delimiter << "Mem free(KB)" << endString;
39 
40  // Add info for each port.
41  for (std::map<Ip::Address, LocalContextStorage *>::iterator i = TheGlobalContextStorage.storage.begin(); i != TheGlobalContextStorage.storage.end(); ++i) {
42  stream << i->first << delimiter;
43  LocalContextStorage & ssl_store_policy(*(i->second));
44  stream << ssl_store_policy.memLimit() / 1024 << delimiter;
45  stream << ssl_store_policy.entries() << delimiter;
46  stream << SSL_CTX_SIZE / 1024 << delimiter;
47  stream << ssl_store_policy.size() / 1024 << delimiter;
48  stream << ssl_store_policy.freeMem() / 1024 << endString;
49  }
50  stream << endString;
51  stream.flush();
52 }
53 
55 
58 {
59  RegisterAction("cached_ssl_cert", "Statistic of cached generated ssl certificates", &CertificateStorageAction::Create, 0, 1);
60 }
61 
63 {
64  for (std::map<Ip::Address, LocalContextStorage *>::iterator i = storage.begin(); i != storage.end(); ++i) {
65  delete i->second;
66  }
67 }
68 
69 void Ssl::GlobalContextStorage::addLocalStorage(Ip::Address const & address, size_t size_of_store)
70 {
72  configureStorage.insert(std::pair<Ip::Address, size_t>(address, size_of_store));
73 }
74 
76 {
77  reconfigureFinish();
78  std::map<Ip::Address, LocalContextStorage *>::iterator i = storage.find(address);
79 
80  if (i == storage.end())
81  return NULL;
82  else
83  return i->second;
84 }
85 
87 {
88  configureStorage.clear();
89  reconfiguring = true;
90 }
91 
93 {
94  if (reconfiguring) {
95  reconfiguring = false;
96 
97  // remove or change old local storages.
98  for (std::map<Ip::Address, LocalContextStorage *>::iterator i = storage.begin(); i != storage.end();) {
99  std::map<Ip::Address, size_t>::iterator conf_i = configureStorage.find(i->first);
100  if (conf_i == configureStorage.end() || conf_i->second <= 0) {
101  delete i->second;
102  storage.erase(i++);
103  } else {
104  i->second->setMemLimit(conf_i->second);
105  ++i;
106  }
107  }
108 
109  // add new local storages.
110  for (std::map<Ip::Address, size_t>::iterator conf_i = configureStorage.begin(); conf_i != configureStorage.end(); ++conf_i ) {
111  if (storage.find(conf_i->first) == storage.end() && conf_i->second > 0) {
112  storage.insert(std::pair<Ip::Address, LocalContextStorage *>(conf_i->first, new LocalContextStorage(-1, conf_i->second)));
113  }
114  }
115  }
116 }
117 
119 
#define assert(EX)
Definition: assert.h:17
int i
Definition: membanger.c:49
void reconfigureFinish()
Called by getLocalStorage method.
CertificateStorageAction(const Mgr::Command::Pointer &cmd)
#define true
Definition: GnuRegex.c:234
void RegisterAction(char const *action, char const *desc, OBJH *handler, int pw_req_flag, int atomic)
Definition: Registration.cc:16
GlobalContextStorage TheGlobalContextStorage
Global cache for store all SSL server certificates.
Class for storing/manipulating LocalContextStorage per local listening address/port.
#define SSL_CTX_SIZE
TODO: Replace on real size.
Definition: LruMap.h:17
void addLocalStorage(Ip::Address const &address, size_t size_of_store)
Create new SSL context storage for the local listening address/port.
int entries() const
The number of stored entries.
Definition: LruMap.h:58
static const char * delimiter
Definition: ldap_backend.cc:64
void reconfigureStart()
When reconfigring should be called this method.
size_t freeMem() const
The free space of the map.
Definition: LruMap.h:54
size_t memLimit() const
The available size for the map.
Definition: LruMap.h:52
size_t size() const
The current size of the map.
Definition: LruMap.h:56
LocalContextStorage * getLocalStorage(Ip::Address const &address)
Return the local storage for the given listening address/port.
static Pointer Create(const Mgr::Command::Pointer &cmd)
virtual void dump(StoreEntry *sentry)
std::map< Ip::Address, LocalContextStorage * > storage
Map for storing all local ip address and their local storages.
#define NULL
Definition: types.h:166
int reconfiguring

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors