My Project
|
00001 /* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; version 2 of the License. 00006 00007 This program is distributed in the hope that it will be useful, 00008 but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 GNU General Public License for more details. 00011 00012 You should have received a copy of the GNU General Public License 00013 along with this program; if not, write to the Free Software 00014 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00015 00016 #ifndef HOSTNAME_INCLUDED 00017 #define HOSTNAME_INCLUDED 00018 00019 #include "my_global.h" /* uint */ 00020 #include "my_net.h" 00021 #include "hash_filo.h" 00022 00023 struct Host_errors 00024 { 00025 public: 00026 Host_errors(); 00027 ~Host_errors(); 00028 00029 void reset(); 00030 void aggregate(const Host_errors *errors); 00031 00033 ulong m_connect; 00034 00036 ulong m_host_blocked; 00038 ulong m_nameinfo_transient; 00040 ulong m_nameinfo_permanent; 00042 ulong m_format; 00044 ulong m_addrinfo_transient; 00046 ulong m_addrinfo_permanent; 00048 ulong m_FCrDNS; 00050 ulong m_host_acl; 00052 ulong m_no_auth_plugin; 00054 ulong m_auth_plugin; 00056 ulong m_handshake; 00058 ulong m_proxy_user; 00060 ulong m_proxy_user_acl; 00062 ulong m_authentication; 00064 ulong m_ssl; 00066 ulong m_max_user_connection; 00068 ulong m_max_user_connection_per_hour; 00070 ulong m_default_database; 00072 ulong m_init_connect; 00074 ulong m_local; 00075 00076 bool has_error() const 00077 { 00078 return ((m_host_blocked != 0) 00079 || (m_nameinfo_transient != 0) 00080 || (m_nameinfo_permanent != 0) 00081 || (m_format != 0) 00082 || (m_addrinfo_transient != 0) 00083 || (m_addrinfo_permanent != 0) 00084 || (m_FCrDNS != 0) 00085 || (m_host_acl != 0) 00086 || (m_no_auth_plugin != 0) 00087 || (m_auth_plugin != 0) 00088 || (m_handshake != 0) 00089 || (m_proxy_user != 0) 00090 || (m_proxy_user_acl != 0) 00091 || (m_authentication != 0) 00092 || (m_ssl != 0) 00093 || (m_max_user_connection != 0) 00094 || (m_max_user_connection_per_hour != 0) 00095 || (m_default_database != 0) 00096 || (m_init_connect != 0) 00097 || (m_local != 0)); 00098 } 00099 00100 void sum_connect_errors() 00101 { 00102 /* Current (historical) behavior: */ 00103 m_connect= m_handshake; 00104 } 00105 00106 void clear_connect_errors() 00107 { 00108 m_connect= 0; 00109 } 00110 }; 00111 00113 #define HOST_ENTRY_KEY_SIZE INET6_ADDRSTRLEN 00114 00125 class Host_entry : public hash_filo_element 00126 { 00127 public: 00128 Host_entry *next() 00129 { return (Host_entry*) hash_filo_element::next(); } 00130 00139 char ip_key[HOST_ENTRY_KEY_SIZE]; 00140 00144 char m_hostname[HOSTNAME_LENGTH + 1]; 00146 uint m_hostname_length; 00148 bool m_host_validated; 00149 ulonglong m_first_seen; 00150 ulonglong m_last_seen; 00151 ulonglong m_first_error_seen; 00152 ulonglong m_last_error_seen; 00154 Host_errors m_errors; 00155 00156 void set_error_timestamps(ulonglong now) 00157 { 00158 if (m_first_error_seen == 0) 00159 m_first_error_seen= now; 00160 m_last_error_seen= now; 00161 } 00162 }; 00163 00164 #define RC_OK 0 00165 #define RC_BLOCKED_HOST 1 00166 int ip_to_hostname(struct sockaddr_storage *ip_storage, 00167 const char *ip_string, 00168 char **hostname, uint *connect_errors); 00169 00170 void inc_host_errors(const char *ip_string, Host_errors *errors); 00171 void reset_host_connect_errors(const char *ip_string); 00172 bool hostname_cache_init(uint size); 00173 void hostname_cache_free(); 00174 void hostname_cache_refresh(void); 00175 uint hostname_cache_size(); 00176 void hostname_cache_resize(uint size); 00177 void hostname_cache_lock(); 00178 void hostname_cache_unlock(); 00179 Host_entry *hostname_cache_first(); 00180 00181 #endif /* HOSTNAME_INCLUDED */