MySQL 8.4.0
Source Code Documentation
blocked_endpoints.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTING_BLOCKED_ENDPOINT_INCLUDED
27#define ROUTING_BLOCKED_ENDPOINT_INCLUDED
28
29#include <map>
30
33
35 public:
38
39 uint64_t max_connect_errors() const { return max_connect_errors_; }
40
41 /**
42 * increments the error count of an endpoint.
43 *
44 * @param endpoint endpoint increment error counter for.
45 * @returns new error count value.
46 */
47 uint64_t increment_error_count(const net::ip::tcp::endpoint &endpoint);
48
49 /**
50 * resets error counter for an endpoint.
51 *
52 * @sa increment_error_counter()
53 *
54 * @param endpoint endpoint
55 * @returns previous value.
56 */
57 uint64_t reset_error_count(const net::ip::tcp::endpoint &endpoint);
58
59 bool is_blocked(const net::ip::tcp::endpoint &endpoint) const;
60
61 uint64_t error_count(const net::ip::tcp::endpoint &endpoint) const;
62
63#ifdef NET_TS_HAS_UNIX_SOCKET
65 return 0;
66 }
67
69 return 0;
70 }
71
73 return false;
74 }
75
76 uint64_t error_count(const local::stream_protocol::endpoint &) const {
77 return 0;
78 }
79#endif
80
81 /**
82 * Returns list of blocked client hosts.
83 */
84 std::vector<std::string> get_blocked_client_hosts() const;
85
86 private:
87 mutable std::mutex mutex_conn_errors_;
88
89 /** Max connect errors blocking hosts when handshake not completed. */
90 const uint64_t max_connect_errors_;
91
92 /** Connection error counters for IPv4 hosts. */
93 std::map<net::ip::address_v4, uint64_t> conn_error_counters_v4_;
94
95 /** Connection error counters for IPv4 hosts. */
96 std::map<net::ip::address_v6, uint64_t> conn_error_counters_v6_;
97};
98
99#endif
Definition: blocked_endpoints.h:34
uint64_t increment_error_count(const net::ip::tcp::endpoint &endpoint)
increments the error count of an endpoint.
Definition: blocked_endpoints.cc:45
const uint64_t max_connect_errors_
Max connect errors blocking hosts when handshake not completed.
Definition: blocked_endpoints.h:90
std::map< net::ip::address_v4, uint64_t > conn_error_counters_v4_
Connection error counters for IPv4 hosts.
Definition: blocked_endpoints.h:93
BlockedEndpoints(uint64_t max_connect_errors)
Definition: blocked_endpoints.h:36
uint64_t max_connect_errors() const
Definition: blocked_endpoints.h:39
bool is_blocked(const net::ip::tcp::endpoint &endpoint) const
Definition: blocked_endpoints.cc:75
std::mutex mutex_conn_errors_
Definition: blocked_endpoints.h:87
std::map< net::ip::address_v6, uint64_t > conn_error_counters_v6_
Connection error counters for IPv4 hosts.
Definition: blocked_endpoints.h:96
uint64_t error_count(const net::ip::tcp::endpoint &endpoint) const
Definition: blocked_endpoints.cc:30
std::vector< std::string > get_blocked_client_hosts() const
Returns list of blocked client hosts.
Definition: blocked_endpoints.cc:80
uint64_t reset_error_count(const net::ip::tcp::endpoint &endpoint)
resets error counter for an endpoint.
Definition: blocked_endpoints.cc:58
Definition: internet.h:678