| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: socket.c,v 1.20.6.1 2017/06/21 18:03:47 snj Exp $ */ | | 1 | /* $NetBSD: socket.c,v 1.20.6.2 2018/08/13 12:05:25 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (C) 2004-2016 Internet Systems Consortium, Inc. ("ISC") | | 4 | * Copyright (C) 2004-2016 Internet Systems Consortium, Inc. ("ISC") |
5 | * Copyright (C) 1998-2003 Internet Software Consortium. | | 5 | * Copyright (C) 1998-2003 Internet Software Consortium. |
6 | * | | 6 | * |
7 | * Permission to use, copy, modify, and/or distribute this software for any | | 7 | * Permission to use, copy, modify, and/or distribute this software for any |
8 | * purpose with or without fee is hereby granted, provided that the above | | 8 | * purpose with or without fee is hereby granted, provided that the above |
9 | * copyright notice and this permission notice appear in all copies. | | 9 | * copyright notice and this permission notice appear in all copies. |
10 | * | | 10 | * |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH | | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH |
12 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | | 12 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
13 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, | | 13 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, |
14 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | | 14 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| @@ -247,26 +247,27 @@ typedef enum { poll_idle, poll_active, p | | | @@ -247,26 +247,27 @@ typedef enum { poll_idle, poll_active, p |
247 | #endif | | 247 | #endif |
248 | | | 248 | |
249 | /*% | | 249 | /*% |
250 | * Define what the possible "soft" errors can be. These are non-fatal returns | | 250 | * Define what the possible "soft" errors can be. These are non-fatal returns |
251 | * of various network related functions, like recv() and so on. | | 251 | * of various network related functions, like recv() and so on. |
252 | * | | 252 | * |
253 | * For some reason, BSDI (and perhaps others) will sometimes return <0 | | 253 | * For some reason, BSDI (and perhaps others) will sometimes return <0 |
254 | * from recv() but will have errno==0. This is broken, but we have to | | 254 | * from recv() but will have errno==0. This is broken, but we have to |
255 | * work around it here. | | 255 | * work around it here. |
256 | */ | | 256 | */ |
257 | #define SOFT_ERROR(e) ((e) == EAGAIN || \ | | 257 | #define SOFT_ERROR(e) ((e) == EAGAIN || \ |
258 | (e) == EWOULDBLOCK || \ | | 258 | (e) == EWOULDBLOCK || \ |
259 | (e) == EINTR || \ | | 259 | (e) == EINTR || \ |
| | | 260 | (e) == ENOBUFS || \ |
260 | (e) == 0) | | 261 | (e) == 0) |
261 | | | 262 | |
262 | #define DLVL(x) ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(x) | | 263 | #define DLVL(x) ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(x) |
263 | | | 264 | |
264 | /*!< | | 265 | /*!< |
265 | * DLVL(90) -- Function entry/exit and other tracing. | | 266 | * DLVL(90) -- Function entry/exit and other tracing. |
266 | * DLVL(70) -- Socket "correctness" -- including returning of events, etc. | | 267 | * DLVL(70) -- Socket "correctness" -- including returning of events, etc. |
267 | * DLVL(60) -- Socket data send/receive | | 268 | * DLVL(60) -- Socket data send/receive |
268 | * DLVL(50) -- Event tracing, including receiving/sending completion events. | | 269 | * DLVL(50) -- Event tracing, including receiving/sending completion events. |
269 | * DLVL(20) -- Socket creation/destruction. | | 270 | * DLVL(20) -- Socket creation/destruction. |
270 | */ | | 271 | */ |
271 | #define TRACE_LEVEL 90 | | 272 | #define TRACE_LEVEL 90 |
272 | #define CORRECTNESS_LEVEL 70 | | 273 | #define CORRECTNESS_LEVEL 70 |
| @@ -1906,27 +1907,27 @@ doio_recv(isc__socket_t *sock, isc_socke | | | @@ -1906,27 +1907,27 @@ doio_recv(isc__socket_t *sock, isc_socke |
1906 | if (recv_errno == _system) { \ | | 1907 | if (recv_errno == _system) { \ |
1907 | dev->result = _isc; \ | | 1908 | dev->result = _isc; \ |
1908 | inc_stats(sock->manager->stats, \ | | 1909 | inc_stats(sock->manager->stats, \ |
1909 | sock->statsindex[STATID_RECVFAIL]); \ | | 1910 | sock->statsindex[STATID_RECVFAIL]); \ |
1910 | return (DOIO_HARD); \ | | 1911 | return (DOIO_HARD); \ |
1911 | } | | 1912 | } |
1912 | | | 1913 | |
1913 | SOFT_OR_HARD(ECONNREFUSED, ISC_R_CONNREFUSED); | | 1914 | SOFT_OR_HARD(ECONNREFUSED, ISC_R_CONNREFUSED); |
1914 | SOFT_OR_HARD(ENETUNREACH, ISC_R_NETUNREACH); | | 1915 | SOFT_OR_HARD(ENETUNREACH, ISC_R_NETUNREACH); |
1915 | SOFT_OR_HARD(EHOSTUNREACH, ISC_R_HOSTUNREACH); | | 1916 | SOFT_OR_HARD(EHOSTUNREACH, ISC_R_HOSTUNREACH); |
1916 | SOFT_OR_HARD(EHOSTDOWN, ISC_R_HOSTDOWN); | | 1917 | SOFT_OR_HARD(EHOSTDOWN, ISC_R_HOSTDOWN); |
1917 | /* HPUX 11.11 can return EADDRNOTAVAIL. */ | | 1918 | /* HPUX 11.11 can return EADDRNOTAVAIL. */ |
1918 | SOFT_OR_HARD(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); | | 1919 | SOFT_OR_HARD(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); |
1919 | ALWAYS_HARD(ENOBUFS, ISC_R_NORESOURCES); | | 1920 | SOFT_OR_HARD(ENOBUFS, ISC_R_NORESOURCES); |
1920 | /* Should never get this one but it was seen. */ | | 1921 | /* Should never get this one but it was seen. */ |
1921 | #ifdef ENOPROTOOPT | | 1922 | #ifdef ENOPROTOOPT |
1922 | SOFT_OR_HARD(ENOPROTOOPT, ISC_R_HOSTUNREACH); | | 1923 | SOFT_OR_HARD(ENOPROTOOPT, ISC_R_HOSTUNREACH); |
1923 | #endif | | 1924 | #endif |
1924 | /* | | 1925 | /* |
1925 | * HPUX returns EPROTO and EINVAL on receiving some ICMP/ICMPv6 | | 1926 | * HPUX returns EPROTO and EINVAL on receiving some ICMP/ICMPv6 |
1926 | * errors. | | 1927 | * errors. |
1927 | */ | | 1928 | */ |
1928 | #ifdef EPROTO | | 1929 | #ifdef EPROTO |
1929 | SOFT_OR_HARD(EPROTO, ISC_R_HOSTUNREACH); | | 1930 | SOFT_OR_HARD(EPROTO, ISC_R_HOSTUNREACH); |
1930 | #endif | | 1931 | #endif |
1931 | SOFT_OR_HARD(EINVAL, ISC_R_HOSTUNREACH); | | 1932 | SOFT_OR_HARD(EINVAL, ISC_R_HOSTUNREACH); |
1932 | | | 1933 | |
| @@ -2102,27 +2103,27 @@ doio_send(isc__socket_t *sock, isc_socke | | | @@ -2102,27 +2103,27 @@ doio_send(isc__socket_t *sock, isc_socke |
2102 | sock->statsindex[STATID_SENDFAIL]); \ | | 2103 | sock->statsindex[STATID_SENDFAIL]); \ |
2103 | return (DOIO_HARD); \ | | 2104 | return (DOIO_HARD); \ |
2104 | } | | 2105 | } |
2105 | | | 2106 | |
2106 | SOFT_OR_HARD(ECONNREFUSED, ISC_R_CONNREFUSED); | | 2107 | SOFT_OR_HARD(ECONNREFUSED, ISC_R_CONNREFUSED); |
2107 | ALWAYS_HARD(EACCES, ISC_R_NOPERM); | | 2108 | ALWAYS_HARD(EACCES, ISC_R_NOPERM); |
2108 | ALWAYS_HARD(EAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); | | 2109 | ALWAYS_HARD(EAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); |
2109 | ALWAYS_HARD(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); | | 2110 | ALWAYS_HARD(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); |
2110 | ALWAYS_HARD(EHOSTUNREACH, ISC_R_HOSTUNREACH); | | 2111 | ALWAYS_HARD(EHOSTUNREACH, ISC_R_HOSTUNREACH); |
2111 | #ifdef EHOSTDOWN | | 2112 | #ifdef EHOSTDOWN |
2112 | ALWAYS_HARD(EHOSTDOWN, ISC_R_HOSTUNREACH); | | 2113 | ALWAYS_HARD(EHOSTDOWN, ISC_R_HOSTUNREACH); |
2113 | #endif | | 2114 | #endif |
2114 | ALWAYS_HARD(ENETUNREACH, ISC_R_NETUNREACH); | | 2115 | ALWAYS_HARD(ENETUNREACH, ISC_R_NETUNREACH); |
2115 | ALWAYS_HARD(ENOBUFS, ISC_R_NORESOURCES); | | 2116 | SOFT_OR_HARD(ENOBUFS, ISC_R_NORESOURCES); |
2116 | ALWAYS_HARD(EPERM, ISC_R_HOSTUNREACH); | | 2117 | ALWAYS_HARD(EPERM, ISC_R_HOSTUNREACH); |
2117 | ALWAYS_HARD(EPIPE, ISC_R_NOTCONNECTED); | | 2118 | ALWAYS_HARD(EPIPE, ISC_R_NOTCONNECTED); |
2118 | ALWAYS_HARD(ECONNRESET, ISC_R_CONNECTIONRESET); | | 2119 | ALWAYS_HARD(ECONNRESET, ISC_R_CONNECTIONRESET); |
2119 | | | 2120 | |
2120 | #undef SOFT_OR_HARD | | 2121 | #undef SOFT_OR_HARD |
2121 | #undef ALWAYS_HARD | | 2122 | #undef ALWAYS_HARD |
2122 | | | 2123 | |
2123 | /* | | 2124 | /* |
2124 | * The other error types depend on whether or not the | | 2125 | * The other error types depend on whether or not the |
2125 | * socket is UDP or TCP. If it is UDP, some errors | | 2126 | * socket is UDP or TCP. If it is UDP, some errors |
2126 | * that we expect to be fatal under TCP are merely | | 2127 | * that we expect to be fatal under TCP are merely |
2127 | * annoying, and are really soft errors. | | 2128 | * annoying, and are really soft errors. |
2128 | * | | 2129 | * |