]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ssl/context_storage.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / ssl / context_storage.cc
CommitLineData
bbc27441 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
bbc27441
AJ
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
f7f3304a 9#include "squid.h"
7e10ac87 10#include "base/PackableStream.h"
602d9612
A
11#include "mgr/Registration.h"
12#include "ssl/context_storage.h"
95d2589c 13#include "Store.h"
074d6a40 14
95d2589c 15#include <limits>
24b30fdc
EQ
16#if USE_OPENSSL
17#include "compat/openssl.h"
cb4f4424 18#if HAVE_OPENSSL_SSL_H
a011edee
FC
19#include <openssl/ssl.h>
20#endif
24b30fdc 21#endif
95d2589c 22
eb898410 23Ssl::CertificateStorageAction::CertificateStorageAction(const Mgr::Command::Pointer &aCmd)
f53969cc 24 : Mgr::Action(aCmd)
95d2589c
CT
25{}
26
27Ssl::CertificateStorageAction::Pointer
eb898410 28Ssl::CertificateStorageAction::Create(const Mgr::Command::Pointer &aCmd)
95d2589c 29{
eb898410 30 return new CertificateStorageAction(aCmd);
95d2589c
CT
31}
32
33void Ssl::CertificateStorageAction::dump (StoreEntry *sentry)
34{
7e10ac87 35 PackableStream stream(*sentry);
95d2589c
CT
36 const char delimiter = '\t';
37 const char endString = '\n';
38 // Page title.
39 stream << "Cached ssl certificates statistic.\n";
40 // Title of statistic table.
41 stream << "Port" << delimiter << "Max mem(KB)" << delimiter << "Cert number" << delimiter << "KB/cert" << delimiter << "Mem used(KB)" << delimiter << "Mem free(KB)" << endString;
42
43 // Add info for each port.
d7ae3534 44 for (std::map<Ip::Address, LocalContextStorage *>::iterator i = TheGlobalContextStorage.storage.begin(); i != TheGlobalContextStorage.storage.end(); ++i) {
95d2589c
CT
45 stream << i->first << delimiter;
46 LocalContextStorage & ssl_store_policy(*(i->second));
14798e73
CT
47 stream << ssl_store_policy.memLimit() / 1024 << delimiter;
48 stream << ssl_store_policy.entries() << delimiter;
95d2589c 49 stream << SSL_CTX_SIZE / 1024 << delimiter;
14798e73
CT
50 stream << ssl_store_policy.size() / 1024 << delimiter;
51 stream << ssl_store_policy.freeMem() / 1024 << endString;
95d2589c
CT
52 }
53 stream << endString;
54 stream.flush();
55}
56
95d2589c
CT
57///////////////////////////////////////////////////////
58
59Ssl::GlobalContextStorage::GlobalContextStorage()
f53969cc 60 : reconfiguring(true)
95d2589c
CT
61{
62 RegisterAction("cached_ssl_cert", "Statistic of cached generated ssl certificates", &CertificateStorageAction::Create, 0, 1);
63}
64
65Ssl::GlobalContextStorage::~GlobalContextStorage()
66{
d7ae3534 67 for (std::map<Ip::Address, LocalContextStorage *>::iterator i = storage.begin(); i != storage.end(); ++i) {
95d2589c
CT
68 delete i->second;
69 }
70}
71
72void Ssl::GlobalContextStorage::addLocalStorage(Ip::Address const & address, size_t size_of_store)
73{
74 assert(reconfiguring);
75 configureStorage.insert(std::pair<Ip::Address, size_t>(address, size_of_store));
76}
77
9873e378 78Ssl::LocalContextStorage *Ssl::GlobalContextStorage::getLocalStorage(Ip::Address const & address)
95d2589c
CT
79{
80 reconfigureFinish();
81 std::map<Ip::Address, LocalContextStorage *>::iterator i = storage.find(address);
9873e378
CT
82
83 if (i == storage.end())
84 return NULL;
85 else
86 return i->second;
95d2589c
CT
87}
88
89void Ssl::GlobalContextStorage::reconfigureStart()
90{
9873e378 91 configureStorage.clear();
95d2589c
CT
92 reconfiguring = true;
93}
94
95void Ssl::GlobalContextStorage::reconfigureFinish()
96{
97 if (reconfiguring) {
98 reconfiguring = false;
99
100 // remove or change old local storages.
b02a2ff8 101 for (std::map<Ip::Address, LocalContextStorage *>::iterator i = storage.begin(); i != storage.end();) {
95d2589c 102 std::map<Ip::Address, size_t>::iterator conf_i = configureStorage.find(i->first);
9873e378 103 if (conf_i == configureStorage.end() || conf_i->second <= 0) {
ea886ed6 104 delete i->second;
b02a2ff8 105 storage.erase(i++);
95d2589c 106 } else {
14798e73 107 i->second->setMemLimit(conf_i->second);
b02a2ff8 108 ++i;
95d2589c
CT
109 }
110 }
111
112 // add new local storages.
a38ec4b1 113 for (std::map<Ip::Address, size_t>::iterator conf_i = configureStorage.begin(); conf_i != configureStorage.end(); ++conf_i ) {
9873e378 114 if (storage.find(conf_i->first) == storage.end() && conf_i->second > 0) {
14798e73 115 storage.insert(std::pair<Ip::Address, LocalContextStorage *>(conf_i->first, new LocalContextStorage(-1, conf_i->second)));
95d2589c
CT
116 }
117 }
118 }
119}
120
121Ssl::GlobalContextStorage Ssl::TheGlobalContextStorage;
f53969cc 122