MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hostname.h
1 /* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef HOSTNAME_INCLUDED
17 #define HOSTNAME_INCLUDED
18 
19 #include "my_global.h" /* uint */
20 #include "my_net.h"
21 #include "hash_filo.h"
22 
24 {
25 public:
26  Host_errors();
27  ~Host_errors();
28 
29  void reset();
30  void aggregate(const Host_errors *errors);
31 
33  ulong m_connect;
34 
42  ulong m_format;
48  ulong m_FCrDNS;
50  ulong m_host_acl;
56  ulong m_handshake;
58  ulong m_proxy_user;
64  ulong m_ssl;
74  ulong m_local;
75 
76  bool has_error() const
77  {
78  return ((m_host_blocked != 0)
79  || (m_nameinfo_transient != 0)
80  || (m_nameinfo_permanent != 0)
81  || (m_format != 0)
82  || (m_addrinfo_transient != 0)
83  || (m_addrinfo_permanent != 0)
84  || (m_FCrDNS != 0)
85  || (m_host_acl != 0)
86  || (m_no_auth_plugin != 0)
87  || (m_auth_plugin != 0)
88  || (m_handshake != 0)
89  || (m_proxy_user != 0)
90  || (m_proxy_user_acl != 0)
91  || (m_authentication != 0)
92  || (m_ssl != 0)
93  || (m_max_user_connection != 0)
95  || (m_default_database != 0)
96  || (m_init_connect != 0)
97  || (m_local != 0));
98  }
99 
100  void sum_connect_errors()
101  {
102  /* Current (historical) behavior: */
104  }
105 
106  void clear_connect_errors()
107  {
108  m_connect= 0;
109  }
110 };
111 
113 #define HOST_ENTRY_KEY_SIZE INET6_ADDRSTRLEN
114 
126 {
127 public:
128  Host_entry *next()
129  { return (Host_entry*) hash_filo_element::next(); }
130 
139  char ip_key[HOST_ENTRY_KEY_SIZE];
140 
144  char m_hostname[HOSTNAME_LENGTH + 1];
149  ulonglong m_first_seen;
150  ulonglong m_last_seen;
151  ulonglong m_first_error_seen;
152  ulonglong m_last_error_seen;
155 
156  void set_error_timestamps(ulonglong now)
157  {
158  if (m_first_error_seen == 0)
159  m_first_error_seen= now;
160  m_last_error_seen= now;
161  }
162 };
163 
165 extern ulong host_cache_size;
166 
167 #define RC_OK 0
168 #define RC_BLOCKED_HOST 1
169 int ip_to_hostname(struct sockaddr_storage *ip_storage,
170  const char *ip_string,
171  char **hostname, uint *connect_errors);
172 
173 void inc_host_errors(const char *ip_string, Host_errors *errors);
174 void reset_host_connect_errors(const char *ip_string);
175 bool hostname_cache_init();
176 void hostname_cache_free();
177 void hostname_cache_refresh(void);
178 uint hostname_cache_size();
179 void hostname_cache_resize(uint size);
180 void hostname_cache_lock();
181 void hostname_cache_unlock();
182 Host_entry *hostname_cache_first();
183 
184 #endif /* HOSTNAME_INCLUDED */