Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Dec 2020 04:23:21 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r368751 - in head/contrib/unbound: services util
Message-ID:  <202012180423.0BI4NL9p000492@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Fri Dec 18 04:23:20 2020
New Revision: 368751
URL: https://svnweb.freebsd.org/changeset/base/368751

Log:
  MFV r368746:
  
  Apply upstream fix 08968baec1122a58bb90d8f97ad948a75f8a5d69:
  
  Fix error cases when udp-connect is set and send() returns an error
  
  Obtained from:	unbound git
  MFC after:	3 days

Modified:
  head/contrib/unbound/services/authzone.c
  head/contrib/unbound/services/outside_network.c
  head/contrib/unbound/util/netevent.c
  head/contrib/unbound/util/netevent.h
Directory Properties:
  head/contrib/unbound/   (props changed)

Modified: head/contrib/unbound/services/authzone.c
==============================================================================
--- head/contrib/unbound/services/authzone.c	Fri Dec 18 04:01:05 2020	(r368750)
+++ head/contrib/unbound/services/authzone.c	Fri Dec 18 04:23:20 2020	(r368751)
@@ -6093,7 +6093,7 @@ xfr_probe_send_probe(struct auth_xfer* xfr, struct mod
 
 	/* send udp packet */
 	if(!comm_point_send_udp_msg(xfr->task_probe->cp, env->scratch_buffer,
-		(struct sockaddr*)&addr, addrlen)) {
+		(struct sockaddr*)&addr, addrlen, 0)) {
 		char zname[255+1], as[256];
 		dname_str(xfr->name, zname);
 		addr_to_str(&addr, addrlen, as, sizeof(as));

Modified: head/contrib/unbound/services/outside_network.c
==============================================================================
--- head/contrib/unbound/services/outside_network.c	Fri Dec 18 04:01:05 2020	(r368750)
+++ head/contrib/unbound/services/outside_network.c	Fri Dec 18 04:23:20 2020	(r368751)
@@ -1870,17 +1870,10 @@ randomize_and_send_udp(struct pending* pend, sldns_buf
 	log_assert(pend->pc && pend->pc->cp);
 
 	/* send it over the commlink */
-	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;
-		}
+	if(!comm_point_send_udp_msg(pend->pc->cp, packet,
+		(struct sockaddr*)&pend->addr, pend->addrlen, outnet->udp_connect)) {
+		portcomm_loweruse(outnet, pend->pc);
+		return 0;
 	}
 
 	/* system calls to set timeout after sending UDP to make roundtrip

Modified: head/contrib/unbound/util/netevent.c
==============================================================================
--- head/contrib/unbound/util/netevent.c	Fri Dec 18 04:01:05 2020	(r368750)
+++ head/contrib/unbound/util/netevent.c	Fri Dec 18 04:23:20 2020	(r368751)
@@ -333,7 +333,7 @@ int tcp_connect_errno_needs_log(struct sockaddr* addr,
 /* send a UDP reply */
 int
 comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
-	struct sockaddr* addr, socklen_t addrlen) 
+	struct sockaddr* addr, socklen_t addrlen, int is_connected)
 {
 	ssize_t sent;
 	log_assert(c->fd != -1);
@@ -341,8 +341,8 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_bu
 	if(sldns_buffer_remaining(packet) == 0)
 		log_err("error: send empty UDP packet");
 #endif
-	if(addr) {
-		log_assert(addr && addrlen > 0);
+	log_assert(addr && addrlen > 0);
+	if(!is_connected) {
 		sent = sendto(c->fd, (void*)sldns_buffer_begin(packet),
 			sldns_buffer_remaining(packet), 0,
 			addr, addrlen);
@@ -367,9 +367,14 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_bu
 #endif
 			int e;
 			fd_set_block(c->fd);
-			sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), 
-				sldns_buffer_remaining(packet), 0,
-				addr, addrlen);
+			if (!is_connected) {
+				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);
+			}
 			e = errno;
 			fd_set_nonblock(c->fd);
 			errno = e;
@@ -378,8 +383,12 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_bu
 	if(sent == -1) {
 		if(!udp_send_errno_needs_log(addr, addrlen))
 			return 0;
-		verbose(VERB_OPS, "sendto failed: %s", sock_strerror(errno));
-		log_addr(VERB_OPS, "remote address is", 
+		if (!is_connected) {
+			verbose(VERB_OPS, "sendto failed: %s", sock_strerror(errno));
+		} else {
+			verbose(VERB_OPS, "send failed: %s", sock_strerror(errno));
+		}
+		log_addr(VERB_OPS, "remote address is",
 			(struct sockaddr_storage*)addr, addrlen);
 		return 0;
 	} else if((size_t)sent != sldns_buffer_remaining(packet)) {
@@ -754,7 +763,7 @@ comm_point_udp_callback(int fd, short event, void* arg
 			buffer = rep.c->buffer;
 #endif
 			(void)comm_point_send_udp_msg(rep.c, buffer,
-				(struct sockaddr*)&rep.addr, rep.addrlen);
+				(struct sockaddr*)&rep.addr, rep.addrlen, 0);
 		}
 		if(!rep.c || rep.c->fd != fd) /* commpoint closed to -1 or reused for
 		another UDP port. Note rep.c cannot be reused with TCP fd. */
@@ -3901,7 +3910,7 @@ comm_point_send_reply(struct comm_reply *repinfo)
 			repinfo->addrlen, repinfo);
 		else
 			comm_point_send_udp_msg(repinfo->c, buffer,
-			(struct sockaddr*)&repinfo->addr, repinfo->addrlen);
+			(struct sockaddr*)&repinfo->addr, repinfo->addrlen, 0);
 #ifdef USE_DNSTAP
 		if(repinfo->c->dtenv != NULL &&
 		   repinfo->c->dtenv->log_client_response_messages)

Modified: head/contrib/unbound/util/netevent.h
==============================================================================
--- head/contrib/unbound/util/netevent.h	Fri Dec 18 04:01:05 2020	(r368750)
+++ head/contrib/unbound/util/netevent.h	Fri Dec 18 04:23:20 2020	(r368751)
@@ -633,10 +633,11 @@ void comm_point_drop_reply(struct comm_reply* repinfo)
  * @param addr: where to send it to.   If NULL, send is performed,
  * 	for connected sockets, to the connected address.
  * @param addrlen: length of addr.
+ * @param is_connected: if the UDP socket is connect()ed.
  * @return: false on a failure.
  */
 int comm_point_send_udp_msg(struct comm_point* c, struct sldns_buffer* packet,
-	struct sockaddr* addr, socklen_t addrlen);
+	struct sockaddr* addr, socklen_t addrlen,int is_connected);
 
 /**
  * Stop listening for input on the commpoint. No callbacks will happen.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012180423.0BI4NL9p000492>