From: Alexander Nozdrin Date: April 5 2011 6:51pm Subject: bzr commit into mysql-5.5 branch (alexander.nozdrin:3421) Bug#12325375 List-Archive: http://lists.mysql.com/commits/134741 X-Bug: 12325375 Message-Id: <201104051851.p35IpRRW009153@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4534070780124382434==" --===============4534070780124382434== 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:georgi.kodinov@stripped 3421 Alexander Nozdrin 2011-04-05 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-05 18:51:21 +0000 @@ -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-05 18:51:21 +0000 @@ -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: %s.", + (const char *) ip_key, + (const char *) gai_strerror(err_code))); - 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: %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); + 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. - err_status= add_hostname(ip_key, NULL); + 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-05 18:51:21 +0000 @@ -1060,6 +1060,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 __WIN__ + + 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: - Solaris 10 requires that the 2nd argument (salen) must match the --===============4534070780124382434== 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\ # 00a2f7i9rybavkw9 # target_branch: file:///home/alik/MySQL/bzr/00/bug12325375/mysql-5.5-\ # bug12325375/ # testament_sha1: 5e16bbbf6e6b4080c1a2bf624e5f7898913b46e2 # timestamp: 2011-04-05 22:51:25 +0400 # base_revision_id: georgi.kodinov@stripped\ # 9olq0qtkpdgm4rqu # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWXpixrkAA8p/gFQQEgBa9/// f+ffwL////5gCTd11qx9dvTQF113HsHe9yNtaBTuvd5YSSEBNAmZAVPyp+FT9TaaYk0jJ+TU8qfp T1A9QD1NBJKGiT9JtATJqnphqnogDTQANABoAyAaJkE1TBGnpkR6gZAHqbUAAAaAGmgEpop6mRNA IamQaNNPRAMgBoAABk0DjRkyMIxAMJoMAmg0DJk0ZMhhAYSSCZGhME0aKabRpGRTTTxTAjAmT1DI wElSX+2MxbavV55B8hiat9+EzNGTNz7ej97zdur/ryPbJXQ61aVm+GK+eW241/GNpFuRzCj3BwUu pi5KGpMNjQ2ipeHpI1Z1XKRoVYU1rWeQIE8ERHtDGLLVr76Yxbn1ixFSySSGSP1x/Ybbw1bNYRq3 pocaJfc6MXpJrlLJoUlGRUrs69afSLr5ugYz2vHtR6w6as0muezn0XD8rJLJTFbi0sZthtKeunWp tmEGeyIHLHZ7Q85/sZJbaJCWvldID5u4zdYEPu1crRFJuTNRkmY5RUeSCcM0LhvmRj5SbWUMfBnO 89s41WrREWO2Qv0HjKhirSBoCLL8bW32O4auDFik0piWD69ELOvhpfhucVEwdVejUWGM18XsAJ3a LaEOZBP8F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