2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

doio_recv was not catching a ECONNRESET error. Fixed this and added code to catch other possible errors. Miscellaneous errno handling cleanup [RT #1745]

This commit is contained in:
Danny Mayer 2001-09-16 06:19:22 +00:00
parent e6f17474cb
commit 8423b244ec

View File

@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: socket.c,v 1.5 2001/07/17 20:29:31 gson Exp $ */ /* $Id: socket.c,v 1.6 2001/09/16 06:19:22 mayer Exp $ */
#define MAKE_EXTERNAL 1 #define MAKE_EXTERNAL 1
@ -27,6 +27,8 @@
#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */ #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
#endif #endif
#include "errno2result.h"
#include <errno.h> #include <errno.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@ -69,8 +71,8 @@
* work around it here. * work around it here.
*/ */
#define SOFT_ERROR(e) ((e) == EAGAIN || \ #define SOFT_ERROR(e) ((e) == EAGAIN || \
(e) == EWOULDBLOCK || \ (e) == WSAEWOULDBLOCK || \
(e) == EINTR || \ (e) == WSAEINTR || \
(e) == 0) (e) == 0)
#define DLVL(x) ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(x) #define DLVL(x) ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(x)
@ -317,14 +319,7 @@ internal_sendmsg(int sock, const struct msghdr *msg, int flags) {
BytesSent = -1; BytesSent = -1;
/* There is an error... */ /* There is an error... */
Error = WSAGetLastError(); Error = WSAGetLastError();
if (Error == WSAEWOULDBLOCK) { if (Error == WSA_IO_PENDING) {
/*
* WSAEWOULDBLOCK means we have to wait for an FD_WRITE
* before we can send.
*/
errno = EWOULDBLOCK;
} else if (Error == WSA_IO_PENDING) {
/* Overlapped send successfully initiated. */ /* Overlapped send successfully initiated. */
errno = EAGAIN; errno = EAGAIN;
} else { } else {
@ -997,7 +992,7 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) {
ISC_MSG_DOIORECV, ISC_MSG_DOIORECV,
"doio_recv: internal_recvmsg(%d) %d bytes, " "doio_recv: internal_recvmsg(%d) %d bytes, "
"err %d/%s", "err %d/%s",
sock->fd, cc, errno, strerror(errno)); sock->fd, cc, errno, NTstrerror(errno));
#define SOFT_OR_HARD(_system, _isc) \ #define SOFT_OR_HARD(_system, _isc) \
if (errno == _system) { \ if (errno == _system) { \
@ -1013,10 +1008,14 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) {
return (DOIO_HARD); \ return (DOIO_HARD); \
} }
SOFT_OR_HARD(ECONNREFUSED, ISC_R_CONNREFUSED); SOFT_OR_HARD(WSAECONNREFUSED, ISC_R_CONNREFUSED);
SOFT_OR_HARD(ENETUNREACH, ISC_R_NETUNREACH); SOFT_OR_HARD(WSAENETUNREACH, ISC_R_NETUNREACH);
SOFT_OR_HARD(EHOSTUNREACH, ISC_R_HOSTUNREACH); SOFT_OR_HARD(WSAEHOSTUNREACH, ISC_R_HOSTUNREACH);
ALWAYS_HARD(ENOBUFS, ISC_R_NORESOURCES); SOFT_OR_HARD(WSAECONNRESET, ISC_R_CONNECTIONRESET);
SOFT_OR_HARD(WSAENETRESET, ISC_R_CONNECTIONRESET);
SOFT_OR_HARD(WSAEDISCON, ISC_R_CONNECTIONRESET);
SOFT_OR_HARD(WSAENETDOWN, ISC_R_NETDOWN);
ALWAYS_HARD(WSAENOBUFS, ISC_R_NORESOURCES);
#undef SOFT_OR_HARD #undef SOFT_OR_HARD
#undef ALWAYS_HARD #undef ALWAYS_HARD
@ -1147,16 +1146,18 @@ doio_send(isc_socket_t *sock, isc_socketevent_t *dev) {
return (DOIO_HARD); \ return (DOIO_HARD); \
} }
SOFT_OR_HARD(EACCES, ISC_R_NOPERM); SOFT_OR_HARD(WSAEACCES, ISC_R_NOPERM);
SOFT_OR_HARD(EAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); SOFT_OR_HARD(WSAEAFNOSUPPORT, ISC_R_ADDRNOTAVAIL);
SOFT_OR_HARD(ECONNREFUSED, ISC_R_CONNREFUSED); SOFT_OR_HARD(WSAECONNREFUSED, ISC_R_CONNREFUSED);
ALWAYS_HARD(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); SOFT_OR_HARD(WSAECONNRESET, ISC_R_CONNECTIONRESET);
ALWAYS_HARD(EHOSTUNREACH, ISC_R_HOSTUNREACH); SOFT_OR_HARD(WSAENETRESET, ISC_R_CONNECTIONRESET);
#ifdef EHOSTDOWN SOFT_OR_HARD(WSAEDISCON, ISC_R_CONNECTIONRESET);
ALWAYS_HARD(EHOSTDOWN, ISC_R_HOSTUNREACH); SOFT_OR_HARD(WSAENETDOWN, ISC_R_NETDOWN);
#endif ALWAYS_HARD(WSAEADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL);
ALWAYS_HARD(ENETUNREACH, ISC_R_NETUNREACH); ALWAYS_HARD(WSAEHOSTUNREACH, ISC_R_HOSTUNREACH);
ALWAYS_HARD(ENOBUFS, ISC_R_NORESOURCES); ALWAYS_HARD(WSAEHOSTDOWN, ISC_R_HOSTUNREACH);
ALWAYS_HARD(WSAENETUNREACH, ISC_R_NETUNREACH);
ALWAYS_HARD(WSAENOBUFS, ISC_R_NORESOURCES);
ALWAYS_HARD(EPERM, ISC_R_HOSTUNREACH); ALWAYS_HARD(EPERM, ISC_R_HOSTUNREACH);
ALWAYS_HARD(EPIPE, ISC_R_NOTCONNECTED); ALWAYS_HARD(EPIPE, ISC_R_NOTCONNECTED);
@ -1391,13 +1392,6 @@ isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type,
case EPROTONOSUPPORT: case EPROTONOSUPPORT:
case EPFNOSUPPORT: case EPFNOSUPPORT:
case EAFNOSUPPORT: case EAFNOSUPPORT:
#ifdef LINUX
/*
* Linux 2.2 (and maybe others) return EINVAL instead of
* EAFNOSUPPORT.
*/
case EINVAL:
#endif
return (ISC_R_FAMILYNOSUPPORT); return (ISC_R_FAMILYNOSUPPORT);
default: default:
@ -2914,16 +2908,14 @@ isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr,
switch (errno) { switch (errno) {
#define ERROR_MATCH(a, b) case a: dev->result = b; goto err_exit; #define ERROR_MATCH(a, b) case a: dev->result = b; goto err_exit;
ERROR_MATCH(EACCES, ISC_R_NOPERM); ERROR_MATCH(WSAEACCES, ISC_R_NOPERM);
ERROR_MATCH(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); ERROR_MATCH(WSAEADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL);
ERROR_MATCH(EAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); ERROR_MATCH(WSAEAFNOSUPPORT, ISC_R_ADDRNOTAVAIL);
ERROR_MATCH(ECONNREFUSED, ISC_R_CONNREFUSED); ERROR_MATCH(WSAECONNREFUSED, ISC_R_CONNREFUSED);
ERROR_MATCH(EHOSTUNREACH, ISC_R_HOSTUNREACH); ERROR_MATCH(WSAEHOSTUNREACH, ISC_R_HOSTUNREACH);
#ifdef EHOSTDOWN ERROR_MATCH(WSAEHOSTDOWN, ISC_R_HOSTUNREACH);
ERROR_MATCH(EHOSTDOWN, ISC_R_HOSTUNREACH); ERROR_MATCH(WSAENETUNREACH, ISC_R_NETUNREACH);
#endif ERROR_MATCH(WSAENOBUFS, ISC_R_NORESOURCES);
ERROR_MATCH(ENETUNREACH, ISC_R_NETUNREACH);
ERROR_MATCH(ENOBUFS, ISC_R_NORESOURCES);
ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH); ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH);
ERROR_MATCH(EPIPE, ISC_R_NOTCONNECTED); ERROR_MATCH(EPIPE, ISC_R_NOTCONNECTED);
#undef ERROR_MATCH #undef ERROR_MATCH
@ -3057,19 +3049,17 @@ internal_connect(isc_task_t *me, isc_event_t *ev) {
*/ */
switch (errno) { switch (errno) {
#define ERROR_MATCH(a, b) case a: dev->result = b; break; #define ERROR_MATCH(a, b) case a: dev->result = b; break;
ERROR_MATCH(EACCES, ISC_R_NOPERM); ERROR_MATCH(WSAEACCES, ISC_R_NOPERM);
ERROR_MATCH(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); ERROR_MATCH(WSAEADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL);
ERROR_MATCH(EAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); ERROR_MATCH(WSAEAFNOSUPPORT, ISC_R_ADDRNOTAVAIL);
ERROR_MATCH(ECONNREFUSED, ISC_R_CONNREFUSED); ERROR_MATCH(WSAECONNREFUSED, ISC_R_CONNREFUSED);
ERROR_MATCH(EHOSTUNREACH, ISC_R_HOSTUNREACH); ERROR_MATCH(WSAEHOSTUNREACH, ISC_R_HOSTUNREACH);
#ifdef EHOSTDOWN ERROR_MATCH(WSAEHOSTDOWN, ISC_R_HOSTUNREACH);
ERROR_MATCH(EHOSTDOWN, ISC_R_HOSTUNREACH); ERROR_MATCH(WSAENETUNREACH, ISC_R_NETUNREACH);
#endif ERROR_MATCH(WSAENOBUFS, ISC_R_NORESOURCES);
ERROR_MATCH(ENETUNREACH, ISC_R_NETUNREACH);
ERROR_MATCH(ENOBUFS, ISC_R_NORESOURCES);
ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH); ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH);
ERROR_MATCH(EPIPE, ISC_R_NOTCONNECTED); ERROR_MATCH(EPIPE, ISC_R_NOTCONNECTED);
ERROR_MATCH(ETIMEDOUT, ISC_R_TIMEDOUT); ERROR_MATCH(WSAETIMEDOUT, ISC_R_TIMEDOUT);
#undef ERROR_MATCH #undef ERROR_MATCH
default: default:
dev->result = ISC_R_UNEXPECTED; dev->result = ISC_R_UNEXPECTED;