From: W.C.A. Wijngaards Date: Wed, 25 Nov 2020 08:55:01 +0000 (+0100) Subject: - Fix udp-connect on FreeBSD, do send calls on connected UDP socket. X-Git-Tag: release-1.13.0rc2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15e8f5c6d4f85c3858c7ad8927ee50f2da8a8a54;p=thirdparty%2Funbound.git - Fix udp-connect on FreeBSD, do send calls on connected UDP socket. --- diff --git a/doc/Changelog b/doc/Changelog index 0f46a3694..0ceba16b4 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ 25 November 2020: Wouter - with udp-connect ignore connection refused with UDP timeouts. + - Fix udp-connect on FreeBSD, do send calls on connected UDP socket. 24 November 2020: Wouter - Merge PR #283 : Stream reuse. This implements upstream stream diff --git a/services/outside_network.c b/services/outside_network.c index a55cc1cd3..724550632 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -1854,10 +1854,17 @@ randomize_and_send_udp(struct pending* pend, sldns_buffer* packet, int timeout) log_assert(pend->pc && pend->pc->cp); /* send it over the commlink */ - if(!comm_point_send_udp_msg(pend->pc->cp, packet, - (struct sockaddr*)&pend->addr, pend->addrlen)) { - portcomm_loweruse(outnet, pend->pc); - return 0; + if(outnet->udp_connect) { + if(!comm_point_send_udp_msg(pend->pc->cp, packet, NULL, 0)) { + portcomm_loweruse(outnet, pend->pc); + return 0; + } + } else { + if(!comm_point_send_udp_msg(pend->pc->cp, packet, + (struct sockaddr*)&pend->addr, pend->addrlen)) { + portcomm_loweruse(outnet, pend->pc); + return 0; + } } /* system calls to set timeout after sending UDP to make roundtrip diff --git a/util/netevent.c b/util/netevent.c index 7999e2c3f..814ab6f0a 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -341,10 +341,15 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, if(sldns_buffer_remaining(packet) == 0) log_err("error: send empty UDP packet"); #endif - log_assert(addr && addrlen > 0); - sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), - sldns_buffer_remaining(packet), 0, - addr, addrlen); + if(addr) { + log_assert(addr && addrlen > 0); + sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), + sldns_buffer_remaining(packet), 0, + addr, addrlen); + } else { + sent = send(c->fd, (void*)sldns_buffer_begin(packet), + sldns_buffer_remaining(packet), 0); + } if(sent == -1) { /* try again and block, waiting for IO to complete, * we want to send the answer, and we will wait for diff --git a/util/netevent.h b/util/netevent.h index ce07b7500..75baf2177 100644 --- a/util/netevent.h +++ b/util/netevent.h @@ -620,7 +620,8 @@ void comm_point_drop_reply(struct comm_reply* repinfo); * Send an udp message over a commpoint. * @param c: commpoint to send it from. * @param packet: what to send. - * @param addr: where to send it to. + * @param addr: where to send it to. If NULL, send is performed, + * for connected sockets, to the connected address. * @param addrlen: length of addr. * @return: false on a failure. */