From: Alexander Nozdrin Date: April 8 2011 9:27am Subject: bzr commit into mysql-5.5 branch (alexander.nozdrin:3429) Bug#12325375 List-Archive: http://lists.mysql.com/commits/135037 X-Bug: 12325375 Message-Id: <201104080927.p389RmFp017536@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2978292523603263247==" --===============2978292523603263247== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline #At file:///home/alik/MySQL/bzr/00/bug12325375/mysql-5.5-bug12325375/ based on revid:gleb.shchepa@stripped 3429 Alexander Nozdrin 2011-04-08 A patch for Bug#12325375: THE SERVER ON WINXP DOES NOT ALLOW CONNECTIONS IF NO DNS-SERVER AVAILABLE. The thing is that on Windows XP getnameinfo() returns WSANO_DATA when hostname-lookup is not available. The problem was that this error code was treated as serious error and the client connection got rejected. The fix is to treat all errors from getnameinfo() as not ciritical, but add IP-address to the host cache only for EAI_NONAME (or WSANO_DATA). modified: include/violite.h sql/hostname.cc vio/viosocket.c === modified file 'include/violite.h' --- a/include/violite.h 2010-06-07 14:01:39 +0000 +++ b/include/violite.h 2011-04-08 09:27:38 +0000 @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -93,6 +93,8 @@ ssize_t vio_pending(Vio *vio); my_bool vio_get_normalized_ip_string(const struct sockaddr *addr, int addr_length, char *ip_string, size_t ip_string_size); +my_bool vio_is_no_name_error(int err_code); + int vio_getnameinfo(const struct sockaddr *sa, char *hostname, size_t hostname_size, char *port, size_t port_size, === modified file 'sql/hostname.cc' --- a/sql/hostname.cc 2010-07-23 20:17:55 +0000 +++ b/sql/hostname.cc 2011-04-08 09:27:38 +0000 @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc +/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -366,41 +366,33 @@ bool ip_to_hostname(struct sockaddr_stor err_code= vio_getnameinfo(ip, hostname_buffer, NI_MAXHOST, NULL, 0, NI_NAMEREQD); - if (err_code == EAI_NONAME) + if (err_code) { - /* - There is no reverse address mapping for the IP address. A host name - can not be resolved. - */ - - DBUG_PRINT("error", ("IP address '%s' could not be resolved: " - "no reverse address mapping.", - (const char *) ip_key)); - - sql_print_warning("IP address '%s' could not be resolved: " - "no reverse address mapping.", - (const char *) ip_key); + DBUG_PRINT("error", ("IP address '%s' could not be resolved: %s.", + (const char *) ip_key, + (const char *) gai_strerror(err_code))); - err_status= add_hostname(ip_key, NULL); + sql_print_warning("IP address '%s' could not be resolved: %s.", + (const char *) ip_key, + (const char *) gai_strerror(err_code)); - *hostname= NULL; - *connect_errors= 0; /* New IP added to the cache. */ + if (vio_is_no_name_error(err_code)) + { + /* + The no-name error means that there is no reverse address mapping + for the IP address. A host name can not be resolved. + + If it is not the no-name error, we should not cache the hostname + (or rather its absence), because the failure might be transient. + */ - DBUG_RETURN(err_status); - } - else if (err_code) - { - DBUG_PRINT("error", ("IP address '%s' could not be resolved: " - "getnameinfo() returned %d.", - (const char *) ip_key, - (int) err_code)); + add_hostname(ip_key, NULL); - sql_print_warning("IP address '%s' could not be resolved: " - "getnameinfo() returned error (code: %d).", - (const char *) ip_key, - (int) err_code); + *hostname= NULL; + *connect_errors= 0; /* New IP added to the cache. */ + } - DBUG_RETURN(TRUE); + DBUG_RETURN(FALSE); } DBUG_PRINT("info", ("IP '%s' resolved to '%s'.", === modified file 'vio/viosocket.c' --- a/vio/viosocket.c 2010-08-16 12:50:27 +0000 +++ b/vio/viosocket.c 2011-04-08 09:27:38 +0000 @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1059,6 +1059,34 @@ ssize_t vio_pending(Vio *vio) } +/** + Checks if the error code, returned by vio_getnameinfo(), means it was the + "No-name" error. + + Windows-specific note: getnameinfo() returns WSANO_DATA instead of + EAI_NODATA or EAI_NONAME when no reverse mapping is available at the host + (i.e. Windows can't get hostname by IP-address). This error should be + treated as EAI_NONAME. + + @return if the error code is actually EAI_NONAME. + @retval true if the error code is EAI_NONAME. + @retval false otherwise. +*/ + +my_bool vio_is_no_name_error(int err_code) +{ +#ifdef _WIN32 + + return err_code == WSANO_DATA || err_code == EAI_NONAME; + +#else + + return err_code == EAI_NONAME; + +#endif +} + + /** This is a wrapper for the system getnameinfo(), because different OS differ in the getnameinfo() implementation: --===============2978292523603263247== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/alexander.nozdrin@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: alexander.nozdrin@stripped\ # 7ywl2h3rqwftppqv # target_branch: file:///home/alik/MySQL/bzr/00/bug12325375/mysql-5.5-\ # bug12325375/ # testament_sha1: 9ffded763eb0ee33fd1e6347a127ac238c13245f # timestamp: 2011-04-08 13:27:44 +0400 # base_revision_id: gleb.shchepa@stripped\ # zlg0p10qkmax9gt8 # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWSloHu8AA+n/gFQQEgBa9/// f+ffwL////5gCWydja+s3qiqzrVcwNu3Npga6tXq5uCSUZQwiMyNNCeUaJk8mGpPSDQMgNGgaaaC SRFPRmhoEyFNHkNRoANADIGIAADRNMQgpp6o/RIbUMR6j0J6jBGJpiYRkD9U0YJERCaaZE0o81PV Mwoe0obRManknqb1QaNAB6mnqHGjJkYRiAYTQYBNBoGTJoyZDCAwkkJiAmmRoyTKZoCmTEyaNA0D QaADRaSXjUzE0y91DiNwZ2nwvZnD27av2d7QcWaXPvf6Qrq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