From f9d740dfdc2bf74ea225624c1b462e293bbb864e Mon Sep 17 00:00:00 2001 From: Yorgos Thessalonikefs Date: Tue, 8 Apr 2025 15:34:51 +0200 Subject: [PATCH 1/6] - Update to the manpage for the fast_reload part. --- doc/unbound-control.8.in | 105 +++++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 26 deletions(-) diff --git a/doc/unbound-control.8.in b/doc/unbound-control.8.in index 8f0d125a7..8adaf7d6d 100644 --- a/doc/unbound-control.8.in +++ b/doc/unbound-control.8.in @@ -77,32 +77,85 @@ values and new ones while trying to fast_reload. Zones loaded from disk (authority zones and RPZ zones) are included in such memory needs. .IP -Not all options are changed, but it changes like forwards, stubs and -local zones. Also access-control and interface-action and similar options, -also tcp-connection-limits, views. It can reload some define-tag changes. -It does not work with interface, outgoing-interface changes, also not with -remote-control, outgoing-port-permit, outgoing-port-avoid, msg-buffer-size, -slabs options and statistics-interval changes. +Options that can be changed are for +forwards, +stubs, +views, +authority zones, +RPZ zones and +local zones. .IP -The fast reload also works on the options: insecure-lan-zones, domain-insecure, -trust-anchor-file, trust-anchor, trusted-key-file, auto-trust-anchor-file, -auth-zone and its options, rpz and its options, edns-strings, respip_set, -view and its options, access-control options, tcp-connection-limit, -log-identity, infra-cache-numhosts, msg-cache-size, rrset-cache-size, -key-cache-size, ratelimit-size, neg-cache-size, num-queries-per-thread, -jostle-timeout, use-caps-for-id, unwanted-reply-threshold, tls-use-sni, -outgoing-tcp-mss, ip-dscp, max-reuse-tcp-queries, tcp-reuse-timeout, -tcp-auth-query-timeout, delay-close. +Also +access-control and similar options, +interface-action and similar options and +tcp-connection-limit. +It can reload some +define-tag +changes, more on that below. +Further options include +insecure-lan-zones, +domain-insecure, +trust-anchor-file, +trust-anchor, +trusted-keys-file, +auto-trust-anchor-file, +edns-client-string, +ipset, +log-identity, +infra-cache-numhosts, +msg-cache-size, +rrset-cache-size, +key-cache-size, +ratelimit-size, +neg-cache-size, +num-queries-per-thread, +jostle-timeout, +use-caps-for-id, +unwanted-reply-threshold, +tls-use-sni, +outgoing-tcp-mss, +ip-dscp, +max-reuse-tcp-queries, +tcp-reuse-timeout, +tcp-auth-query-timeout, +delay-close. .IP -For dnstap, the options can be changed: dnstap-log-resolver-query-messages, -dnstap-log-resolver-response-messages, dnstap-log-client-query-messages, -dnstap-log-client-response-messages, dnstap-log-forwarder-query-messages -and dnstap-log-forwarder-response-messages. It does not work with -these options: dnstap-enable, dnstap-bidirectional, dnstap-socket-path, -dnstap-ip, dnstap-tls, dnstap-tls-server-name, dnstap-tls-cert-bundle, -dnstap-tls-client-key-file and dnstap-tls-client-cert-file. The options -dnstap-send-identity, dnstap-send-version, dnstap-identity, and -dnstap-version can be loaded when '+p' is not used. +It does not work with +interface and +outgoing-interface changes, +also not with +remote control, +outgoing-port-permit, +outgoing-port-avoid, +msg-buffer-size, +any **\*-slabs** options and +statistics-interval changes. +.IP +For dnstap these options can be changed: +dnstap-log-resolver-query-messages, +dnstap-log-resolver-response-messages, +dnstap-log-client-query-messages, +dnstap-log-client-response-messages, +dnstap-log-forwarder-query-messages and +dnstap-log-forwarder-response-messages. +.IP +It does not work with these options: +dnstap-enable, +dnstap-bidirectional, +dnstap-socket-path, +dnstap-ip, +dnstap-tls, +dnstap-tls-server-name, +dnstap-tls-cert-bundle, +dnstap-tls-client-key-file and +dnstap-tls-client-cert-file. +.IP +The options +dnstap-send-identity, +dnstap-send-version, +dnstap-identity, and +dnstap-version can be loaded +when ``+p`` is not used. .IP The '+v' option makes the output verbose which includes the time it took to do the reload. @@ -128,7 +181,7 @@ worker thread. .IP With the nopause option, the reload does not work to reload some options, that fast reload works on without the nopause option: val-bogus-ttl, -val-date-override, val-sig-key-min, val-sig-skew-max, val-max-restart, +val-override-date, val-sig-skew-min, val-sig-skew-max, val-max-restart, val-nsec3-keysize-iterations, target-fetch-policy, outbound-msg-retry, max-sent-count, max-query-restarts, do-not-query-address, do-not-query-localhost, private-address, private-domain, caps-exempt, @@ -142,7 +195,7 @@ so that users keep getting answers for those queries that are currently processed. The drop makes it so that queries during the life time of the query processing see only old, or only new config options. .IP -When there are changes to the config tags, from \fBdefine\-tag\fR config, +When there are changes to the config tags, from the \fBdefine\-tag\fR option, then the '+d' option is implicitly turned on with a warning printout, and queries are dropped. This is to stop references to the old tag information, by the old From 922c5c3ab39746e2d573c8e5f0a5f1cc53900827 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Tue, 8 Apr 2025 15:42:56 +0200 Subject: [PATCH 2/6] - Fix fast_reload to print chroot with config file name. --- daemon/remote.c | 10 ++++++++-- doc/Changelog | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 50bdefd68..72c634513 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -4262,7 +4262,10 @@ fr_read_config(struct fast_reload_thread* fr, struct config_file** newcfg) if(!config_read(*newcfg, fr->worker->daemon->cfgfile, fr->worker->daemon->chroot)) { config_delete(*newcfg); - if(!fr_output_printf(fr, "config_read %s failed: %s\n", + if(!fr_output_printf(fr, "config_read %s%s%s%s failed: %s\n", + (fr->worker->daemon->chroot?"worker->daemon->chroot?fr->worker->daemon->chroot:""), + (fr->worker->daemon->chroot?"> ":""), fr->worker->daemon->cfgfile, strerror(errno))) return 0; fr_send_notification(fr, fast_reload_notification_printout); @@ -4271,7 +4274,10 @@ fr_read_config(struct fast_reload_thread* fr, struct config_file** newcfg) if(fr_poll_for_quit(fr)) return 1; if(fr->fr_verb >= 1) { - if(!fr_output_printf(fr, "done read config file %s\n", + if(!fr_output_printf(fr, "done read config file %s%s%s%s\n", + (fr->worker->daemon->chroot?"worker->daemon->chroot?fr->worker->daemon->chroot:""), + (fr->worker->daemon->chroot?"> ":""), fr->worker->daemon->cfgfile)) return 0; fr_send_notification(fr, fast_reload_notification_printout); diff --git a/doc/Changelog b/doc/Changelog index 7d3ea168b..88ee61312 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ 8 April 2025: Wouter - Tag for 1.23.0rc1. + - Fix fast_reload to print chroot with config file name. 7 April 2025: Yorgos - Merge #902: DNS Error Reporting (RFC 9567). Introduces new From fca3ae05354dad6e00ca89baff33b7f7d1dca602 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Wed, 9 Apr 2025 11:06:25 +0200 Subject: [PATCH 3/6] - Fix to detect if atomic_store links in configure. --- config.h.in | 3 +++ configure | 42 ++++++++++++++++++++++++++++++++++++++++++ configure.ac | 19 +++++++++++++++++++ daemon/remote.c | 10 +++++----- doc/Changelog | 3 +++ 5 files changed, 72 insertions(+), 5 deletions(-) diff --git a/config.h.in b/config.h.in index 246f06c2f..f2dc8c8b9 100644 --- a/config.h.in +++ b/config.h.in @@ -378,6 +378,9 @@ /* Define if we have LibreSSL */ #undef HAVE_LIBRESSL +/* If we have atomic_store */ +#undef HAVE_LINK_ATOMIC_STORE + /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_NET_TSTAMP_H diff --git a/configure b/configure index 2225dba1f..0b78d97b1 100755 --- a/configure +++ b/configure @@ -23530,6 +23530,48 @@ if echo $host_os | grep darwin8 > /dev/null; then printf "%s\n" "#define DARWIN_BROKEN_SETREUID 1" >>confdefs.h fi + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for atomic_store" >&5 +printf %s "checking for atomic_store... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_includes_default +#ifdef HAVE_STDATOMIC_H +#include +#endif + +int +main (void) +{ + + int newvar = 5, var = 0; + atomic_store((_Atomic int*)&var, newvar); + newvar = 0; + /* condition to use the variables. */ + if(var == newvar) return 1; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + +printf "%s\n" "#define HAVE_LINK_ATOMIC_STORE 1" >>confdefs.h + + +else $as_nop + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + ac_fn_check_decl "$LINENO" "inet_pton" "ac_cv_have_decl_inet_pton" " $ac_includes_default #ifdef HAVE_NETINET_IN_H diff --git a/configure.ac b/configure.ac index 2383934f8..76239c099 100644 --- a/configure.ac +++ b/configure.ac @@ -1818,6 +1818,25 @@ AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])]) if echo $host_os | grep darwin8 > /dev/null; then AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work]) fi + +AC_MSG_CHECKING([for atomic_store]) +AC_LINK_IFELSE([AC_LANG_PROGRAM(AC_INCLUDES_DEFAULT [[ +#ifdef HAVE_STDATOMIC_H +#include +#endif +]], [[ + int newvar = 5, var = 0; + atomic_store((_Atomic int*)&var, newvar); + newvar = 0; + /* condition to use the variables. */ + if(var == newvar) return 1; +]])], [ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_LINK_ATOMIC_STORE, 1, [If we have atomic_store]) +], [ + AC_MSG_RESULT([no]) +]) + AC_CHECK_DECLS([inet_pton,inet_ntop], [], [], [ AC_INCLUDES_DEFAULT #ifdef HAVE_NETINET_IN_H diff --git a/daemon/remote.c b/daemon/remote.c index 72c634513..3cf795a69 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -5450,7 +5450,7 @@ auth_zones_swap(struct auth_zones* az, struct auth_zones* data) * the xfer elements can continue to be their callbacks. */ } -#ifdef ATOMIC_POINTER_LOCK_FREE +#if defined(ATOMIC_POINTER_LOCK_FREE) && defined(HAVE_LINK_ATOMIC_STORE) /** Fast reload thread, if atomics are available, copy the config items * one by one with atomic store operations. */ static void @@ -5819,7 +5819,7 @@ fr_atomic_copy_cfg(struct config_file* oldcfg, struct config_file* cfg, #endif COPY_VAR_int(ede); } -#endif /* ATOMIC_POINTER_LOCK_FREE */ +#endif /* ATOMIC_POINTER_LOCK_FREE && HAVE_LINK_ATOMIC_STORE */ /** fast reload thread, adjust the cache sizes */ static void @@ -5997,7 +5997,7 @@ fr_reload_config(struct fast_reload_thread* fr, struct config_file* newcfg, lock_basic_lock(&env->anchors->lock); } -#ifdef ATOMIC_POINTER_LOCK_FREE +#if defined(ATOMIC_POINTER_LOCK_FREE) && defined(HAVE_LINK_ATOMIC_STORE) if(fr->fr_nopause) { fr_atomic_copy_cfg(ct->oldcfg, env->cfg, newcfg); } else { @@ -6006,7 +6006,7 @@ fr_reload_config(struct fast_reload_thread* fr, struct config_file* newcfg, *ct->oldcfg = *env->cfg; /* Insert new config elements. */ *env->cfg = *newcfg; -#ifdef ATOMIC_POINTER_LOCK_FREE +#if defined(ATOMIC_POINTER_LOCK_FREE) && defined(HAVE_LINK_ATOMIC_STORE) } #endif @@ -6015,7 +6015,7 @@ fr_reload_config(struct fast_reload_thread* fr, struct config_file* newcfg, log_ident_set_or_default(env->cfg->log_identity); } /* the newcfg elements are in env->cfg, so should not be freed here. */ -#ifdef ATOMIC_POINTER_LOCK_FREE +#if defined(ATOMIC_POINTER_LOCK_FREE) && defined(HAVE_LINK_ATOMIC_STORE) /* if used, the routine that copies the config has zeroed items. */ if(!fr->fr_nopause) #endif diff --git a/doc/Changelog b/doc/Changelog index 88ee61312..d37b0cd02 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +9 April 2025: Wouter + - Fix to detect if atomic_store links in configure. + 8 April 2025: Wouter - Tag for 1.23.0rc1. - Fix fast_reload to print chroot with config file name. From 16ee7cf944aac2acf53baba31e71f4b44cb7bb58 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Thu, 10 Apr 2025 09:33:51 +0200 Subject: [PATCH 4/6] - Fix for print of connection type in log-replies for dot and doh. --- daemon/worker.c | 4 ++-- doc/Changelog | 3 +++ services/mesh.c | 2 +- util/data/msgreply.c | 8 ++++---- util/data/msgreply.h | 4 +++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/daemon/worker.c b/daemon/worker.c index 54ba2d76c..ead20938e 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -2055,13 +2055,13 @@ send_reply_rc: &repinfo->client_addr, repinfo->client_addrlen, tv, 1, c->buffer, (worker->env.cfg->log_destaddr?(void*)repinfo->c->socket->addr:NULL), - c->type); + c->type, c->ssl); } else { log_reply_info(NO_VERBOSE, &qinfo, &repinfo->client_addr, repinfo->client_addrlen, tv, 1, c->buffer, (worker->env.cfg->log_destaddr?(void*)repinfo->c->socket->addr:NULL), - c->type); + c->type, c->ssl); } } #ifdef USE_DNSCRYPT diff --git a/doc/Changelog b/doc/Changelog index 08f6c09f4..f8e2a7000 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +10 April 2025: Wouter + - Fix for print of connection type in log-replies for dot and doh. + 9 April 2025: Wouter - Fix to detect if atomic_store links in configure. - Fix #1264: unbound 1.22.0 leaks memory when doing DoH. diff --git a/services/mesh.c b/services/mesh.c index 1d19e7c7d..8a52fe4a6 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -1579,7 +1579,7 @@ mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep, &r->query_reply.client_addr, r->query_reply.client_addrlen, duration, 0, r_buffer, (m->s.env->cfg->log_destaddr?(void*)r->query_reply.c->socket->addr:NULL), - r->query_reply.c->type); + r->query_reply.c->type, r->query_reply.c->ssl); } } diff --git a/util/data/msgreply.c b/util/data/msgreply.c index 530eee701..e98dce133 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -965,7 +965,7 @@ void log_reply_info(enum verbosity_value v, struct query_info *qinf, struct sockaddr_storage *addr, socklen_t addrlen, struct timeval dur, int cached, struct sldns_buffer *rmsg, struct sockaddr_storage* daddr, - enum comm_point_type tp) + enum comm_point_type tp, void* ssl) { char clientip_buf[128]; char rcode_buf[16]; @@ -1000,9 +1000,9 @@ log_reply_info(enum verbosity_value v, struct query_info *qinf, (int)daddr->ss_family); } comm = "udp"; - if(tp == comm_tcp) comm = "tcp"; - else if(tp == comm_tcp_accept) comm = "tcp"; - else if(tp == comm_http) comm = "dot"; + if(tp == comm_tcp) comm = (ssl?"dot":"tcp"); + else if(tp == comm_tcp_accept) comm = (ssl?"dot":"tcp"); + else if(tp == comm_http) comm = "doh"; else if(tp == comm_local) comm = "unix"; else if(tp == comm_raw) comm = "raw"; snprintf(dest_buf, sizeof(dest_buf), " on %s %s %d", diff --git a/util/data/msgreply.h b/util/data/msgreply.h index d1c2bfa4b..9c701f07d 100644 --- a/util/data/msgreply.h +++ b/util/data/msgreply.h @@ -554,11 +554,13 @@ void log_dns_msg(const char* str, struct query_info* qinfo, * @param rmsg: sldns buffer packet. * @param daddr: if not NULL, the destination address and port are logged. * @param tp: type of the comm point for logging destination connection type. + * @param ssl: the SSL pointer of the connection, to see if the connection + * type is tcp or dot. */ void log_reply_info(enum verbosity_value v, struct query_info *qinf, struct sockaddr_storage *addr, socklen_t addrlen, struct timeval dur, int cached, struct sldns_buffer *rmsg, struct sockaddr_storage* daddr, - enum comm_point_type tp); + enum comm_point_type tp, void* ssl); /** * Print string with neat domain name, type, class from query info. From d6e8ac12890d4f8b18a0b9bbdf90da7f0d3a82c1 Mon Sep 17 00:00:00 2001 From: Yorgos Thessalonikefs Date: Fri, 11 Apr 2025 15:05:52 +0200 Subject: [PATCH 5/6] Fix WSAPoll (#1265) * Fix calling WSAPoll. * fast_reload: explicitly set tcp_wouldblock on Windows when there is no command to read from the fast_reload thread. * For poll(), also check for ENOMEM (Linux). * Remove ifdefs for ENOMEM. * Some systems return EAGAIN for poll. --- daemon/remote.c | 45 +++++++++++++++++++++++++++---------- util/netevent.c | 60 +++++++++++++++++++++++++------------------------ 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 3cf795a69..89134efc9 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -3899,6 +3899,7 @@ sock_poll_timeout(int fd, int timeout, int pollin, int pollout, int* event) { int loopcount = 0; /* Loop if the system call returns an errno to do so, like EINTR. */ + log_assert(pollin || pollout); while(1) { struct pollfd p, *fds; int nfds, ret; @@ -3916,11 +3917,11 @@ sock_poll_timeout(int fd, int timeout, int pollin, int pollout, int* event) nfds = 1; memset(&p, 0, sizeof(p)); p.fd = fd; - p.events = POLLERR #ifndef USE_WINSOCK + p.events = POLLERR | POLLHUP -#endif ; +#endif if(pollin) p.events |= POLLIN; if(pollout) @@ -3937,19 +3938,20 @@ sock_poll_timeout(int fd, int timeout, int pollin, int pollout, int* event) } #endif if(ret == -1) { - if( #ifndef USE_WINSOCK + if( errno == EINTR || errno == EAGAIN # ifdef EWOULDBLOCK || errno == EWOULDBLOCK # endif -#else - WSAGetLastError() == WSAEINTR || - WSAGetLastError() == WSAEINPROGRESS || - WSAGetLastError() == WSAEWOULDBLOCK + ) continue; /* Try again. */ #endif - ) - continue; /* Try again. */ + /* For WSAPoll we only get errors here: + * o WSAENETDOWN + * o WSAEFAULT + * o WSAEINVAL + * o WSAENOBUFS + */ log_err("poll: %s", sock_strerror(errno)); if(event) *event = 0; @@ -7398,11 +7400,17 @@ fr_main_handle_cmd(struct fast_reload_thread* fr) # endif #else WSAGetLastError() == WSAEINTR || - WSAGetLastError() == WSAEINPROGRESS || - WSAGetLastError() == WSAEWOULDBLOCK + WSAGetLastError() == WSAEINPROGRESS #endif ) return; /* Continue later. */ +#ifdef USE_WINSOCK + if(WSAGetLastError() == WSAEWOULDBLOCK) { + ub_winsock_tcp_wouldblock(fr->service_event, + UB_EV_READ); + return; /* Continue later. */ + } +#endif log_err("read cmd from fast reload thread, recv: %s", sock_strerror(errno)); return; @@ -7434,10 +7442,23 @@ fr_check_cmd_from_thread(struct fast_reload_thread* fr) if(!sock_poll_timeout(fr->commpair[0], 0, 1, 0, &inevent)) { log_err("check for cmd from fast reload thread: " "poll failed"); +#ifdef USE_WINSOCK + if(worker->daemon->fast_reload_thread) + ub_winsock_tcp_wouldblock(worker->daemon-> + fast_reload_thread->service_event, + UB_EV_READ); +#endif return; } - if(!inevent) + if(!inevent) { +#ifdef USE_WINSOCK + if(worker->daemon->fast_reload_thread) + ub_winsock_tcp_wouldblock(worker->daemon-> + fast_reload_thread->service_event, + UB_EV_READ); +#endif return; + } fr_main_handle_cmd(fr); } } diff --git a/util/netevent.c b/util/netevent.c index f9dff1f9a..0d0fff429 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -456,9 +456,9 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, int pret; memset(&p, 0, sizeof(p)); p.fd = c->fd; - p.events = POLLOUT | POLLERR + p.events = POLLOUT #ifndef USE_WINSOCK - | POLLHUP + | POLLERR | POLLHUP #endif ; # ifndef USE_WINSOCK @@ -483,7 +483,7 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, # ifdef EWOULDBLOCK errno != EWOULDBLOCK && # endif - errno != ENOBUFS + errno != ENOMEM && errno != ENOBUFS #else WSAGetLastError() != WSAEINPROGRESS && WSAGetLastError() != WSAEINTR && @@ -496,15 +496,19 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, return 0; } else if((pret < 0 && #ifndef USE_WINSOCK - errno == ENOBUFS + ( errno == ENOBUFS /* Maybe some systems */ + || errno == ENOMEM /* Linux */ + || errno == EAGAIN) /* Macos, solaris, openbsd */ #else WSAGetLastError() == WSAENOBUFS #endif ) || (send_nobufs && retries > 0)) { - /* ENOBUFS, and poll returned without + /* ENOBUFS/ENOMEM/EAGAIN, and poll + * returned without * a timeout. Or the retried send call - * returned ENOBUFS. It is good to - * wait a bit for the error to clear. */ + * returned ENOBUFS/ENOMEM/EAGAIN. + * It is good to wait a bit for the + * error to clear. */ /* The timeout is 20*(2^(retries+1)), * it increases exponentially, starting * at 40 msec. After 5 tries, 1240 msec @@ -517,18 +521,15 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, Sleep((SEND_BLOCKED_WAIT_TIMEOUT/10)<<(retries+1)); pret = 0; #endif - if(pret < 0 && + if(pret < 0 #ifndef USE_WINSOCK - errno != EAGAIN && errno != EINTR && + && errno != EAGAIN && errno != EINTR && # ifdef EWOULDBLOCK errno != EWOULDBLOCK && # endif - errno != ENOBUFS + errno != ENOMEM && errno != ENOBUFS #else - WSAGetLastError() != WSAEINPROGRESS && - WSAGetLastError() != WSAEINTR && - WSAGetLastError() != WSAENOBUFS && - WSAGetLastError() != WSAEWOULDBLOCK + /* Sleep does not error */ #endif ) { log_err("poll udp out timer failed: %s", @@ -770,9 +771,9 @@ comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet, int pret; memset(&p, 0, sizeof(p)); p.fd = c->fd; - p.events = POLLOUT | POLLERR + p.events = POLLOUT #ifndef USE_WINSOCK - | POLLHUP + | POLLERR | POLLHUP #endif ; # ifndef USE_WINSOCK @@ -797,7 +798,7 @@ comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet, # ifdef EWOULDBLOCK errno != EWOULDBLOCK && # endif - errno != ENOBUFS + errno != ENOMEM && errno != ENOBUFS #else WSAGetLastError() != WSAEINPROGRESS && WSAGetLastError() != WSAEINTR && @@ -810,15 +811,19 @@ comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet, return 0; } else if((pret < 0 && #ifndef USE_WINSOCK - errno == ENOBUFS + ( errno == ENOBUFS /* Maybe some systems */ + || errno == ENOMEM /* Linux */ + || errno == EAGAIN) /* Macos, solaris, openbsd */ #else WSAGetLastError() == WSAENOBUFS #endif ) || (send_nobufs && retries > 0)) { - /* ENOBUFS, and poll returned without + /* ENOBUFS/ENOMEM/EAGAIN, and poll + * returned without * a timeout. Or the retried send call - * returned ENOBUFS. It is good to - * wait a bit for the error to clear. */ + * returned ENOBUFS/ENOMEM/EAGAIN. + * It is good to wait a bit for the + * error to clear. */ /* The timeout is 20*(2^(retries+1)), * it increases exponentially, starting * at 40 msec. After 5 tries, 1240 msec @@ -831,18 +836,15 @@ comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet, Sleep((SEND_BLOCKED_WAIT_TIMEOUT/10)<<(retries+1)); pret = 0; #endif - if(pret < 0 && + if(pret < 0 #ifndef USE_WINSOCK - errno != EAGAIN && errno != EINTR && + && errno != EAGAIN && errno != EINTR && # ifdef EWOULDBLOCK errno != EWOULDBLOCK && # endif - errno != ENOBUFS -#else - WSAGetLastError() != WSAEINPROGRESS && - WSAGetLastError() != WSAEINTR && - WSAGetLastError() != WSAENOBUFS && - WSAGetLastError() != WSAEWOULDBLOCK + errno != ENOMEM && errno != ENOBUFS +#else /* USE_WINSOCK */ + /* Sleep does not error */ #endif ) { log_err("poll udp out timer failed: %s", From 30c13d0351abd2edc3d6dc76365f576c87b9736e Mon Sep 17 00:00:00 2001 From: Yorgos Thessalonikefs Date: Fri, 11 Apr 2025 15:07:25 +0200 Subject: [PATCH 6/6] Changelog entry for #1265: - Merge #1265: Fix WSAPoll. --- doc/Changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/Changelog b/doc/Changelog index f8e2a7000..9668a6364 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +11 April 2025: Yorgos + - Merge #1265: Fix WSAPoll. + 10 April 2025: Wouter - Fix for print of connection type in log-replies for dot and doh.