]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ssl/context_storage.cc
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
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.
10 #include "base/PackableStream.h"
11 #include "mgr/Registration.h"
12 #include "ssl/context_storage.h"
17 #include "compat/openssl.h"
18 #if HAVE_OPENSSL_SSL_H
19 #include <openssl/ssl.h>
23 Ssl::CertificateStorageAction::CertificateStorageAction(const Mgr::Command::Pointer
&aCmd
)
27 Ssl::CertificateStorageAction::Pointer
28 Ssl::CertificateStorageAction::Create(const Mgr::Command::Pointer
&aCmd
)
30 return new CertificateStorageAction(aCmd
);
33 void Ssl::CertificateStorageAction::dump (StoreEntry
*sentry
)
35 PackableStream
stream(*sentry
);
36 const char delimiter
= '\t';
37 const char endString
= '\n';
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
;
43 // Add info for each port.
44 for (std::map
<Ip::Address
, LocalContextStorage
*>::iterator i
= TheGlobalContextStorage
.storage
.begin(); i
!= TheGlobalContextStorage
.storage
.end(); ++i
) {
45 stream
<< i
->first
<< delimiter
;
46 LocalContextStorage
& ssl_store_policy(*(i
->second
));
47 const auto memoryPerEntry
= ssl_store_policy
.entries() ?
48 ssl_store_policy
.memoryUsed() / ssl_store_policy
.entries() : 0;
49 stream
<< ssl_store_policy
.memLimit() / 1024 << delimiter
;
50 stream
<< ssl_store_policy
.entries() << delimiter
;
51 stream
<< memoryPerEntry
/ 1024 << delimiter
;
52 stream
<< ssl_store_policy
.memoryUsed() / 1024 << delimiter
;
53 stream
<< ssl_store_policy
.freeMem() / 1024 << endString
;
59 ///////////////////////////////////////////////////////
61 Ssl::GlobalContextStorage::GlobalContextStorage()
64 RegisterAction("cached_ssl_cert", "Statistic of cached generated ssl certificates", &CertificateStorageAction::Create
, 0, 1);
67 Ssl::GlobalContextStorage::~GlobalContextStorage()
69 for (std::map
<Ip::Address
, LocalContextStorage
*>::iterator i
= storage
.begin(); i
!= storage
.end(); ++i
) {
74 void Ssl::GlobalContextStorage::addLocalStorage(Ip::Address
const & address
, size_t size_of_store
)
76 assert(reconfiguring
);
77 configureStorage
.insert(std::pair
<Ip::Address
, size_t>(address
, size_of_store
));
80 Ssl::LocalContextStorage
*Ssl::GlobalContextStorage::getLocalStorage(Ip::Address
const & address
)
83 std::map
<Ip::Address
, LocalContextStorage
*>::iterator i
= storage
.find(address
);
85 if (i
== storage
.end())
91 void Ssl::GlobalContextStorage::reconfigureStart()
93 configureStorage
.clear();
97 void Ssl::GlobalContextStorage::reconfigureFinish()
100 reconfiguring
= false;
102 // remove or change old local storages.
103 for (std::map
<Ip::Address
, LocalContextStorage
*>::iterator i
= storage
.begin(); i
!= storage
.end();) {
104 std::map
<Ip::Address
, size_t>::iterator conf_i
= configureStorage
.find(i
->first
);
105 if (conf_i
== configureStorage
.end() || conf_i
->second
<= 0) {
109 i
->second
->setMemLimit(conf_i
->second
);
114 // add new local storages.
115 for (std::map
<Ip::Address
, size_t>::iterator conf_i
= configureStorage
.begin(); conf_i
!= configureStorage
.end(); ++conf_i
) {
116 if (storage
.find(conf_i
->first
) == storage
.end() && conf_i
->second
> 0) {
117 storage
.insert(std::pair
<Ip::Address
, LocalContextStorage
*>(conf_i
->first
, new LocalContextStorage(conf_i
->second
)));
123 Ssl::GlobalContextStorage
Ssl::TheGlobalContextStorage
;