From: Alexander Nozdrin Date: April 8 2011 10:23am Subject: bzr commit into mysql-5.5 branch (alexander.nozdrin:3429) Bug#12325375 List-Archive: http://lists.mysql.com/commits/135042 X-Bug: 12325375 Message-Id: <201104081023.p38ANj1T001404@acsmt358.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7548809635323018761==" --===============7548809635323018761== 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 10:23:36 +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 10:23:36 +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,35 @@ 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. - */ + // NOTE: gai_strerror() returns a string ending by a dot. - DBUG_PRINT("error", ("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))); - sql_print_warning("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: %s", + (const char *) ip_key, + (const char *) gai_strerror(err_code)); - err_status= add_hostname(ip_key, NULL); + 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. + */ - *hostname= NULL; - *connect_errors= 0; /* New IP added to the cache. */ + add_hostname(ip_key, NULL); - 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)); - - 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 10:23:36 +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: --===============7548809635323018761== 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\ # ho3jrxz2r5nfinrj # target_branch: file:///home/alik/MySQL/bzr/00/bug12325375/mysql-5.5-\ # bug12325375/ # testament_sha1: cff2323e09352f686e793e0d0d44ed729c4aabd6 # timestamp: 2011-04-08 14:23:41 +0400 # base_revision_id: gleb.shchepa@stripped\ # zlg0p10qkmax9gt8 # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWdDgIfsAA/N/gFQQEgBa9/// f+ffwL////5gCYyXTPveetyh2d617p6Dl0rezQMq3uudwYkRNGkwm1PEnqntKenqR7VPTRppoQ0z KepoDIaPU0EkhBGaGk0yjQjT1NGgZoEABoGgAAZJpo0U00ZBMUPSA/VG1GgABoB6gB6gBIimhJ6F PEMk9Ez1EaaBk0NBkAAAaZNDjRkyMIxAMJoMAmg0DJk0ZMhhAYSSJpoaCMJplNGmmp6Jk1DRG0ZN ARtRoMI9IQAPOnfZh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XPHcxbxO8tnxz3CN+1bjTkdhmDVFwlchoKch3is09 QOVMyZyAcLJP+2xIoVhOo2qHZuHULjW9dW11/MlXWroVvoYApbsOxcjRfNaIIDBNWP6+ynjGIVdx vNp9W3cRtJUjXuaQ80GUEhtDbinCcuScFOJlJxKpgYBgTxytJ5dBEyRrZB4Y1Eb2LguTAdyR10CK QuUR9zDIZkzCZTamm0wTgceyfkIgbOEwTqnPrQnbcblFTqE4gnmS4OeF3AnOJSJ+3BHlTOaDIP8g LxPTy16joSJCybXAdXonkNNOsaEjegdCyyQct02pWa2TIbgKQpu4cC85mXhN2l9XdZbdfasaOlXp I9sDNYq7cUElQwmYHMCchSaIjJB6VMkivC+izogoVIHJwtwTHXYGGMvFwU55J6iCownwzEbE1ytZ sHJ0aO2x+Ig1rSFcNOyA1RErFoLoxmh2y05xwXdeu2otdqgiqEVh/gFolhmN1XKtiEsJBFls8uzU 5tU2JoO4yF1QcJlcttis1GNi6F3GZma0m55kpyIznOAuFWrXcOUsylNCOArQQIw4VztOSIiyVG0j kMq4SPbBSrXVEk08IEdzlHYLVkk9qG575ppcMSV9gDBUvAeLYvqmB4PdSG5VkoImqqSuGNDFcjHr nq5/brkHS6rDTOXYkrZNXUezQgGV40y5ZimbPwsvkbKC5nF9Aj1nV43WSXg3Gu07blaC4M2I9Lai IruGc6DjulBlm1ElWTUR1pEKi8FeFpioluHBj+3uf/xdyRThQkNDgIfs --===============7548809635323018761==--