From d2fd2f8c575f8dba627d808a4ba3ff42d9610f0f Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 11 Nov 2020 09:09:27 +0100 Subject: [PATCH] Add a few comments as suggested by Habbie --- pdns/iputils.cc | 3 ++- pdns/pdns_recursor.cc | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pdns/iputils.cc b/pdns/iputils.cc index 17aa12c74e..92d74c4e5b 100644 --- a/pdns/iputils.cc +++ b/pdns/iputils.cc @@ -242,7 +242,8 @@ int sendOnNBSocket(int fd, const struct msghdr *msgh) { int sendErr = 0; #ifdef __OpenBSD__ - for (int i = 0; i < 10; i++) { + // OpenBSD can and does return EAGIN on non-blocking datagram sockets + for (int i = 0; i < 10; i++) { // Arbitrary upper bound if (sendmsg(fd, msgh, 0) != -1) { sendErr = 0; break; diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 1ed48cb1f7..c53c704e52 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -587,16 +587,18 @@ private: throw PDNSException("Making a socket for resolver (family = " + std::to_string(family) + "): " + stringerror()); } -#ifndef __OpenBSD__ + // The loop below runs the body with [tries-1 tries-2 ... 1]. Last iteration with tries == 1 is special: it uses a kernel + // allocated UDP port. +#if !defined( __OpenBSD__) int tries = 10; #else - int tries = 2; // hit the reliable kernel random case for OpenBSD, using sysctl net.inet.udp.baddynamic to exclude ports + int tries = 2; // hit the reliable kernel random case for OpenBSD immediately, using sysctl net.inet.udp.baddynamic to exclude ports #endif ComboAddress sin; while (--tries) { in_port_t port; - if (tries == 1) { // fall back to kernel 'random' + if (tries == 1) { // last iteration: fall back to kernel 'random' port = 0; } else { do { -- 2.47.2