View | Details | Raw Unified | Return to bug 251821
Collapse All | Expand All

(-)dns/unbound/Makefile (+1 lines)
Lines 3-8 Link Here
3
3
4
PORTNAME=	unbound
4
PORTNAME=	unbound
5
PORTVERSION=	1.13.0
5
PORTVERSION=	1.13.0
6
PORTREVISION=	1
6
CATEGORIES=	dns
7
CATEGORIES=	dns
7
MASTER_SITES=	https://www.nlnetlabs.nl/downloads/unbound/ \
8
MASTER_SITES=	https://www.nlnetlabs.nl/downloads/unbound/ \
8
		https://distfiles.crux.guru/
9
		https://distfiles.crux.guru/
(-)dns/unbound/files/patch-Issue376 (+156 lines)
Line 0 Link Here
1
diff --git a/doc/Changelog b/doc/Changelog
2
index 07a8e6ea4..3b831fea1 100644
3
--- doc/Changelog.orig
4
+++ doc/Changelog
5
@@ -1,3 +1,7 @@
6
+16 December 2020: George
7
+	- Fix error cases when udp-connect is set and send() returns an error
8
+	  (modified patch from Xin Li @delphij).
9
+
10
 30 November 2020: Wouter
11
 	- Fix assertion failure on double callback when iterator loses
12
 	  interest in query at head of line that then has the tcp stream
13
diff --git a/services/authzone.c b/services/authzone.c
14
index 15be5d60c..e59548fc3 100644
15
--- services/authzone.c.orig
16
+++ services/authzone.c
17
@@ -6093,7 +6093,7 @@ xfr_probe_send_probe(struct auth_xfer* xfr, struct module_env* env,
18
 
19
 	/* send udp packet */
20
 	if(!comm_point_send_udp_msg(xfr->task_probe->cp, env->scratch_buffer,
21
-		(struct sockaddr*)&addr, addrlen)) {
22
+		(struct sockaddr*)&addr, addrlen, 0)) {
23
 		char zname[255+1], as[256];
24
 		dname_str(xfr->name, zname);
25
 		addr_to_str(&addr, addrlen, as, sizeof(as));
26
diff --git a/services/outside_network.c b/services/outside_network.c
27
index 0886907f7..d8f9874e6 100644
28
--- services/outside_network.c.orig
29
+++ services/outside_network.c
30
@@ -1899,17 +1899,10 @@ randomize_and_send_udp(struct pending* pend, sldns_buffer* packet, int timeout)
31
 	log_assert(pend->pc && pend->pc->cp);
32
 
33
 	/* send it over the commlink */
34
-	if(outnet->udp_connect) {
35
-		if(!comm_point_send_udp_msg(pend->pc->cp, packet, NULL, 0)) {
36
-			portcomm_loweruse(outnet, pend->pc);
37
-			return 0;
38
-		}
39
-	} else {
40
-		if(!comm_point_send_udp_msg(pend->pc->cp, packet,
41
-			(struct sockaddr*)&pend->addr, pend->addrlen)) {
42
-			portcomm_loweruse(outnet, pend->pc);
43
-			return 0;
44
-		}
45
+	if(!comm_point_send_udp_msg(pend->pc->cp, packet,
46
+		(struct sockaddr*)&pend->addr, pend->addrlen, outnet->udp_connect)) {
47
+		portcomm_loweruse(outnet, pend->pc);
48
+		return 0;
49
 	}
50
 
51
 	/* system calls to set timeout after sending UDP to make roundtrip
52
diff --git a/testcode/fake_event.c b/testcode/fake_event.c
53
index 75a6b8db9..5164332c0 100644
54
--- testcode/fake_event.c.orig
55
+++ testcode/fake_event.c
56
@@ -1766,7 +1766,7 @@ struct comm_point* outnet_comm_point_for_http(struct outside_network* outnet,
57
 }
58
 
59
 int comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
60
-	struct sockaddr* addr, socklen_t addrlen) 
61
+	struct sockaddr* addr, socklen_t addrlen, int ATTR_UNUSED(is_connected))
62
 {
63
 	struct fake_commpoint* fc = (struct fake_commpoint*)c;
64
 	struct replay_runtime* runtime = fc->runtime;
65
diff --git a/util/netevent.c b/util/netevent.c
66
index 7c6da50be..88be007e7 100644
67
--- util/netevent.c.orig
68
+++ util/netevent.c
69
@@ -333,7 +333,7 @@ int tcp_connect_errno_needs_log(struct sockaddr* addr, socklen_t addrlen)
70
 /* send a UDP reply */
71
 int
72
 comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
73
-	struct sockaddr* addr, socklen_t addrlen) 
74
+	struct sockaddr* addr, socklen_t addrlen, int is_connected)
75
 {
76
 	ssize_t sent;
77
 	log_assert(c->fd != -1);
78
@@ -341,8 +341,8 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
79
 	if(sldns_buffer_remaining(packet) == 0)
80
 		log_err("error: send empty UDP packet");
81
 #endif
82
-	if(addr) {
83
-		log_assert(addr && addrlen > 0);
84
+	log_assert(addr && addrlen > 0);
85
+	if(!is_connected) {
86
 		sent = sendto(c->fd, (void*)sldns_buffer_begin(packet),
87
 			sldns_buffer_remaining(packet), 0,
88
 			addr, addrlen);
89
@@ -367,9 +367,14 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
90
 #endif
91
 			int e;
92
 			fd_set_block(c->fd);
93
-			sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), 
94
-				sldns_buffer_remaining(packet), 0,
95
-				addr, addrlen);
96
+			if (!is_connected) {
97
+				sent = sendto(c->fd, (void*)sldns_buffer_begin(packet),
98
+					sldns_buffer_remaining(packet), 0,
99
+					addr, addrlen);
100
+			} else {
101
+				sent = send(c->fd, (void*)sldns_buffer_begin(packet),
102
+					sldns_buffer_remaining(packet), 0);
103
+			}
104
 			e = errno;
105
 			fd_set_nonblock(c->fd);
106
 			errno = e;
107
@@ -378,8 +383,12 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
108
 	if(sent == -1) {
109
 		if(!udp_send_errno_needs_log(addr, addrlen))
110
 			return 0;
111
-		verbose(VERB_OPS, "sendto failed: %s", sock_strerror(errno));
112
-		log_addr(VERB_OPS, "remote address is", 
113
+		if (!is_connected) {
114
+			verbose(VERB_OPS, "sendto failed: %s", sock_strerror(errno));
115
+		} else {
116
+			verbose(VERB_OPS, "send failed: %s", sock_strerror(errno));
117
+		}
118
+		log_addr(VERB_OPS, "remote address is",
119
 			(struct sockaddr_storage*)addr, addrlen);
120
 		return 0;
121
 	} else if((size_t)sent != sldns_buffer_remaining(packet)) {
122
@@ -764,7 +773,7 @@ comm_point_udp_callback(int fd, short event, void* arg)
123
 			buffer = rep.c->buffer;
124
 #endif
125
 			(void)comm_point_send_udp_msg(rep.c, buffer,
126
-				(struct sockaddr*)&rep.addr, rep.addrlen);
127
+				(struct sockaddr*)&rep.addr, rep.addrlen, 0);
128
 		}
129
 		if(!rep.c || rep.c->fd != fd) /* commpoint closed to -1 or reused for
130
 		another UDP port. Note rep.c cannot be reused with TCP fd. */
131
@@ -3944,7 +3953,7 @@ comm_point_send_reply(struct comm_reply *repinfo)
132
 			repinfo->addrlen, repinfo);
133
 		else
134
 			comm_point_send_udp_msg(repinfo->c, buffer,
135
-			(struct sockaddr*)&repinfo->addr, repinfo->addrlen);
136
+			(struct sockaddr*)&repinfo->addr, repinfo->addrlen, 0);
137
 #ifdef USE_DNSTAP
138
 		if(repinfo->c->dtenv != NULL &&
139
 		   repinfo->c->dtenv->log_client_response_messages)
140
diff --git a/util/netevent.h b/util/netevent.h
141
index 266a74ff3..810190683 100644
142
--- util/netevent.h.orig
143
+++ util/netevent.h
144
@@ -633,10 +633,11 @@ void comm_point_drop_reply(struct comm_reply* repinfo);
145
  * @param addr: where to send it to.   If NULL, send is performed,
146
  * 	for connected sockets, to the connected address.
147
  * @param addrlen: length of addr.
148
+ * @param is_connected: if the UDP socket is connect()ed.
149
  * @return: false on a failure.
150
  */
151
 int comm_point_send_udp_msg(struct comm_point* c, struct sldns_buffer* packet,
152
-	struct sockaddr* addr, socklen_t addrlen);
153
+	struct sockaddr* addr, socklen_t addrlen,int is_connected);
154
 
155
 /**
156
  * Stop listening for input on the commpoint. No callbacks will happen.

Return to bug 251821