diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2014-03-16 11:43:30 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2014-03-16 11:43:30 +0000 |
commit | 7b728622ba1fcfa0d3d95dcd5c6b4292f2fb53a6 (patch) | |
tree | a5c775a0acfe707fe9c73cee547a8fa6a1738c19 /usr.sbin/unbound/util | |
parent | 7f886fc9bd17d6d96c9cb192fc436d09a1549d77 (diff) |
merge conflicts, remove old libldns files
Diffstat (limited to 'usr.sbin/unbound/util')
-rw-r--r-- | usr.sbin/unbound/util/fptr_wlist.c | 22 | ||||
-rw-r--r-- | usr.sbin/unbound/util/fptr_wlist.h | 20 | ||||
-rw-r--r-- | usr.sbin/unbound/util/netevent.c | 219 | ||||
-rw-r--r-- | usr.sbin/unbound/util/netevent.h | 45 |
4 files changed, 178 insertions, 128 deletions
diff --git a/usr.sbin/unbound/util/fptr_wlist.c b/usr.sbin/unbound/util/fptr_wlist.c index 6bb95a5318b..c8d3e5e9f35 100644 --- a/usr.sbin/unbound/util/fptr_wlist.c +++ b/usr.sbin/unbound/util/fptr_wlist.c @@ -21,16 +21,16 @@ * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @@ -104,6 +104,7 @@ fptr_whitelist_comm_timer(void (*fptr)(void*)) { if(fptr == &pending_udp_timer_cb) return 1; else if(fptr == &outnet_tcptimer) return 1; + else if(fptr == &pending_udp_timer_delay_cb) return 1; else if(fptr == &worker_stat_timer_cb) return 1; else if(fptr == &worker_probe_timer_cb) return 1; #ifdef UB_ON_WINDOWS @@ -388,6 +389,7 @@ int fptr_whitelist_mesh_cb(mesh_cb_func_t fptr) { if(fptr == &libworker_fg_done_cb) return 1; else if(fptr == &libworker_bg_done_cb) return 1; + else if(fptr == &libworker_event_done_cb) return 1; else if(fptr == &probe_answer_cb) return 1; return 0; } diff --git a/usr.sbin/unbound/util/fptr_wlist.h b/usr.sbin/unbound/util/fptr_wlist.h index d204e923884..b2925d6755d 100644 --- a/usr.sbin/unbound/util/fptr_wlist.h +++ b/usr.sbin/unbound/util/fptr_wlist.h @@ -21,16 +21,16 @@ * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** diff --git a/usr.sbin/unbound/util/netevent.c b/usr.sbin/unbound/util/netevent.c index 193fa8714a7..189aaa4e4ea 100644 --- a/usr.sbin/unbound/util/netevent.c +++ b/usr.sbin/unbound/util/netevent.c @@ -21,16 +21,16 @@ * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @@ -39,11 +39,12 @@ * This file contains event notification functions. */ #include "config.h" -#include <ldns/wire2host.h> #include "util/netevent.h" #include "util/log.h" #include "util/net_help.h" #include "util/fptr_wlist.h" +#include "ldns/pkthdr.h" +#include "ldns/sbuffer.h" #ifdef HAVE_OPENSSL_SSL_H #include <openssl/ssl.h> #endif @@ -234,6 +235,23 @@ comm_base_create(int sigs) return b; } +struct comm_base* +comm_base_create_event(struct event_base* base) +{ + struct comm_base* b = (struct comm_base*)calloc(1, + sizeof(struct comm_base)); + if(!b) + return NULL; + b->eb = (struct internal_base*)calloc(1, sizeof(struct internal_base)); + if(!b->eb) { + free(b); + return NULL; + } + b->eb->base = base; + comm_base_now(b); + return b; +} + void comm_base_delete(struct comm_base* b) { @@ -258,6 +276,21 @@ comm_base_delete(struct comm_base* b) } void +comm_base_delete_no_base(struct comm_base* b) +{ + if(!b) + return; + if(b->eb->slow_accept_enabled) { + if(event_del(&b->eb->slow_accept) != 0) { + log_err("could not event_del slow_accept"); + } + } + b->eb->base = NULL; + free(b->eb); + free(b); +} + +void comm_base_timept(struct comm_base* b, time_t** tt, struct timeval** tv) { *tt = &b->eb->secs; @@ -346,18 +379,18 @@ int tcp_connect_errno_needs_log(struct sockaddr* addr, socklen_t addrlen) /* send a UDP reply */ int -comm_point_send_udp_msg(struct comm_point *c, ldns_buffer* packet, +comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet, struct sockaddr* addr, socklen_t addrlen) { ssize_t sent; log_assert(c->fd != -1); #ifdef UNBOUND_DEBUG - if(ldns_buffer_remaining(packet) == 0) + if(sldns_buffer_remaining(packet) == 0) log_err("error: send empty UDP packet"); #endif log_assert(addr && addrlen > 0); - sent = sendto(c->fd, (void*)ldns_buffer_begin(packet), - ldns_buffer_remaining(packet), 0, + sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), + sldns_buffer_remaining(packet), 0, addr, addrlen); if(sent == -1) { if(!udp_send_errno_needs_log(addr, addrlen)) @@ -371,9 +404,9 @@ comm_point_send_udp_msg(struct comm_point *c, ldns_buffer* packet, log_addr(VERB_OPS, "remote address is", (struct sockaddr_storage*)addr, addrlen); return 0; - } else if((size_t)sent != ldns_buffer_remaining(packet)) { + } else if((size_t)sent != sldns_buffer_remaining(packet)) { log_err("sent %d in place of %d bytes", - (int)sent, (int)ldns_buffer_remaining(packet)); + (int)sent, (int)sldns_buffer_remaining(packet)); return 0; } return 1; @@ -391,7 +424,7 @@ static void p_ancil(const char* str, struct comm_reply* r) char buf[1024]; if(inet_ntop(AF_INET6, &r->pktinfo.v6info.ipi6_addr, buf, (socklen_t)sizeof(buf)) == 0) { - strncpy(buf, "(inet_ntop error)", sizeof(buf)); + (void)strlcpy(buf, "(inet_ntop error)", sizeof(buf)); } buf[sizeof(buf)-1]=0; log_info("%s: %s %d", str, buf, r->pktinfo.v6info.ipi6_ifindex); @@ -400,13 +433,13 @@ static void p_ancil(const char* str, struct comm_reply* r) char buf1[1024], buf2[1024]; if(inet_ntop(AF_INET, &r->pktinfo.v4info.ipi_addr, buf1, (socklen_t)sizeof(buf1)) == 0) { - strncpy(buf1, "(inet_ntop error)", sizeof(buf1)); + (void)strlcpy(buf1, "(inet_ntop error)", sizeof(buf1)); } buf1[sizeof(buf1)-1]=0; #ifdef HAVE_STRUCT_IN_PKTINFO_IPI_SPEC_DST if(inet_ntop(AF_INET, &r->pktinfo.v4info.ipi_spec_dst, buf2, (socklen_t)sizeof(buf2)) == 0) { - strncpy(buf2, "(inet_ntop error)", sizeof(buf2)); + (void)strlcpy(buf2, "(inet_ntop error)", sizeof(buf2)); } buf2[sizeof(buf2)-1]=0; #else @@ -418,7 +451,7 @@ static void p_ancil(const char* str, struct comm_reply* r) char buf1[1024]; if(inet_ntop(AF_INET, &r->pktinfo.v4addr, buf1, (socklen_t)sizeof(buf1)) == 0) { - strncpy(buf1, "(inet_ntop error)", sizeof(buf1)); + (void)strlcpy(buf1, "(inet_ntop error)", sizeof(buf1)); } buf1[sizeof(buf1)-1]=0; log_info("%s: %s", str, buf1); @@ -429,7 +462,7 @@ static void p_ancil(const char* str, struct comm_reply* r) /** send a UDP reply over specified interface*/ static int -comm_point_send_udp_msg_if(struct comm_point *c, ldns_buffer* packet, +comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet, struct sockaddr* addr, socklen_t addrlen, struct comm_reply* r) { #if defined(AF_INET6) && defined(IPV6_PKTINFO) && defined(HAVE_SENDMSG) @@ -443,15 +476,15 @@ comm_point_send_udp_msg_if(struct comm_point *c, ldns_buffer* packet, log_assert(c->fd != -1); #ifdef UNBOUND_DEBUG - if(ldns_buffer_remaining(packet) == 0) + if(sldns_buffer_remaining(packet) == 0) log_err("error: send empty UDP packet"); #endif log_assert(addr && addrlen > 0); msg.msg_name = addr; msg.msg_namelen = addrlen; - iov[0].iov_base = ldns_buffer_begin(packet); - iov[0].iov_len = ldns_buffer_remaining(packet); + iov[0].iov_base = sldns_buffer_begin(packet); + iov[0].iov_len = sldns_buffer_remaining(packet); msg.msg_iov = iov; msg.msg_iovlen = 1; msg.msg_control = control; @@ -511,9 +544,9 @@ comm_point_send_udp_msg_if(struct comm_point *c, ldns_buffer* packet, log_addr(VERB_OPS, "remote address is", (struct sockaddr_storage*)addr, addrlen); return 0; - } else if((size_t)sent != ldns_buffer_remaining(packet)) { + } else if((size_t)sent != sldns_buffer_remaining(packet)) { log_err("sent %d in place of %d bytes", - (int)sent, (int)ldns_buffer_remaining(packet)); + (int)sent, (int)sldns_buffer_remaining(packet)); return 0; } return 1; @@ -550,14 +583,14 @@ comm_point_udp_ancil_callback(int fd, short event, void* arg) log_assert(rep.c && rep.c->buffer && rep.c->fd == fd); comm_base_now(rep.c->ev->base); for(i=0; i<NUM_UDP_PER_SELECT; i++) { - ldns_buffer_clear(rep.c->buffer); + sldns_buffer_clear(rep.c->buffer); rep.addrlen = (socklen_t)sizeof(rep.addr); log_assert(fd != -1); - log_assert(ldns_buffer_remaining(rep.c->buffer) > 0); + log_assert(sldns_buffer_remaining(rep.c->buffer) > 0); msg.msg_name = &rep.addr; msg.msg_namelen = (socklen_t)sizeof(rep.addr); - iov[0].iov_base = ldns_buffer_begin(rep.c->buffer); - iov[0].iov_len = ldns_buffer_remaining(rep.c->buffer); + iov[0].iov_base = sldns_buffer_begin(rep.c->buffer); + iov[0].iov_len = sldns_buffer_remaining(rep.c->buffer); msg.msg_iov = iov; msg.msg_iovlen = 1; msg.msg_control = ancil; @@ -573,8 +606,8 @@ comm_point_udp_ancil_callback(int fd, short event, void* arg) return; } rep.addrlen = msg.msg_namelen; - ldns_buffer_skip(rep.c->buffer, rcv); - ldns_buffer_flip(rep.c->buffer); + sldns_buffer_skip(rep.c->buffer, rcv); + sldns_buffer_flip(rep.c->buffer); rep.srctype = 0; #ifndef S_SPLINT_S for(cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; @@ -638,12 +671,12 @@ comm_point_udp_callback(int fd, short event, void* arg) log_assert(rep.c && rep.c->buffer && rep.c->fd == fd); comm_base_now(rep.c->ev->base); for(i=0; i<NUM_UDP_PER_SELECT; i++) { - ldns_buffer_clear(rep.c->buffer); + sldns_buffer_clear(rep.c->buffer); rep.addrlen = (socklen_t)sizeof(rep.addr); log_assert(fd != -1); - log_assert(ldns_buffer_remaining(rep.c->buffer) > 0); - rcv = recvfrom(fd, (void*)ldns_buffer_begin(rep.c->buffer), - ldns_buffer_remaining(rep.c->buffer), 0, + log_assert(sldns_buffer_remaining(rep.c->buffer) > 0); + rcv = recvfrom(fd, (void*)sldns_buffer_begin(rep.c->buffer), + sldns_buffer_remaining(rep.c->buffer), 0, (struct sockaddr*)&rep.addr, &rep.addrlen); if(rcv == -1) { #ifndef USE_WINSOCK @@ -659,8 +692,8 @@ comm_point_udp_callback(int fd, short event, void* arg) #endif return; } - ldns_buffer_skip(rep.c->buffer, rcv); - ldns_buffer_flip(rep.c->buffer); + sldns_buffer_skip(rep.c->buffer, rcv); + sldns_buffer_flip(rep.c->buffer); rep.srctype = 0; fptr_ok(fptr_whitelist_comm_point(rep.c->callback)); if((*rep.c->callback)(rep.c, rep.c->cb_arg, NETEVENT_NOERROR, &rep)) { @@ -680,7 +713,7 @@ setup_tcp_handler(struct comm_point* c, int fd) { log_assert(c->type == comm_tcp); log_assert(c->fd == -1); - ldns_buffer_clear(c->buffer); + sldns_buffer_clear(c->buffer); c->tcp_is_reading = 1; c->tcp_byte_count = 0; comm_point_start_listening(c, fd, TCP_QUERY_TIMEOUT); @@ -882,7 +915,7 @@ static void tcp_callback_writer(struct comm_point* c) { log_assert(c->type == comm_tcp); - ldns_buffer_clear(c->buffer); + sldns_buffer_clear(c->buffer); if(c->tcp_do_toggle_rw) c->tcp_is_reading = 1; c->tcp_byte_count = 0; @@ -896,7 +929,7 @@ static void tcp_callback_reader(struct comm_point* c) { log_assert(c->type == comm_tcp || c->type == comm_local); - ldns_buffer_flip(c->buffer); + sldns_buffer_flip(c->buffer); if(c->tcp_do_toggle_rw) c->tcp_is_reading = 0; c->tcp_byte_count = 0; @@ -989,7 +1022,7 @@ ssl_handle_read(struct comm_point* c) if(c->tcp_byte_count < sizeof(uint16_t)) { /* read length bytes */ ERR_clear_error(); - if((r=SSL_read(c->ssl, (void*)ldns_buffer_at(c->buffer, + if((r=SSL_read(c->ssl, (void*)sldns_buffer_at(c->buffer, c->tcp_byte_count), (int)(sizeof(uint16_t) - c->tcp_byte_count))) <= 0) { int want = SSL_get_error(c->ssl, r); @@ -1013,24 +1046,24 @@ ssl_handle_read(struct comm_point* c) c->tcp_byte_count += r; if(c->tcp_byte_count != sizeof(uint16_t)) return 1; - if(ldns_buffer_read_u16_at(c->buffer, 0) > - ldns_buffer_capacity(c->buffer)) { + if(sldns_buffer_read_u16_at(c->buffer, 0) > + sldns_buffer_capacity(c->buffer)) { verbose(VERB_QUERY, "ssl: dropped larger than buffer"); return 0; } - ldns_buffer_set_limit(c->buffer, - ldns_buffer_read_u16_at(c->buffer, 0)); - if(ldns_buffer_limit(c->buffer) < LDNS_HEADER_SIZE) { + sldns_buffer_set_limit(c->buffer, + sldns_buffer_read_u16_at(c->buffer, 0)); + if(sldns_buffer_limit(c->buffer) < LDNS_HEADER_SIZE) { verbose(VERB_QUERY, "ssl: dropped bogus too short."); return 0; } verbose(VERB_ALGO, "Reading ssl tcp query of length %d", - (int)ldns_buffer_limit(c->buffer)); + (int)sldns_buffer_limit(c->buffer)); } - log_assert(ldns_buffer_remaining(c->buffer) > 0); + log_assert(sldns_buffer_remaining(c->buffer) > 0); ERR_clear_error(); - r = SSL_read(c->ssl, (void*)ldns_buffer_current(c->buffer), - (int)ldns_buffer_remaining(c->buffer)); + r = SSL_read(c->ssl, (void*)sldns_buffer_current(c->buffer), + (int)sldns_buffer_remaining(c->buffer)); if(r <= 0) { int want = SSL_get_error(c->ssl, r); if(want == SSL_ERROR_ZERO_RETURN) { @@ -1050,8 +1083,8 @@ ssl_handle_read(struct comm_point* c) log_crypto_err("could not SSL_read"); return 0; } - ldns_buffer_skip(c->buffer, (ssize_t)r); - if(ldns_buffer_remaining(c->buffer) <= 0) { + sldns_buffer_skip(c->buffer, (ssize_t)r); + if(sldns_buffer_remaining(c->buffer) <= 0) { tcp_callback_reader(c); } return 1; @@ -1076,7 +1109,7 @@ ssl_handle_write(struct comm_point* c) /* ignore return, if fails we may simply block */ (void)SSL_set_mode(c->ssl, SSL_MODE_ENABLE_PARTIAL_WRITE); if(c->tcp_byte_count < sizeof(uint16_t)) { - uint16_t len = htons(ldns_buffer_limit(c->buffer)); + uint16_t len = htons(sldns_buffer_limit(c->buffer)); ERR_clear_error(); r = SSL_write(c->ssl, (void*)(((uint8_t*)&len)+c->tcp_byte_count), @@ -1103,17 +1136,17 @@ ssl_handle_write(struct comm_point* c) c->tcp_byte_count += r; if(c->tcp_byte_count < sizeof(uint16_t)) return 1; - ldns_buffer_set_position(c->buffer, c->tcp_byte_count - + sldns_buffer_set_position(c->buffer, c->tcp_byte_count - sizeof(uint16_t)); - if(ldns_buffer_remaining(c->buffer) == 0) { + if(sldns_buffer_remaining(c->buffer) == 0) { tcp_callback_writer(c); return 1; } } - log_assert(ldns_buffer_remaining(c->buffer) > 0); + log_assert(sldns_buffer_remaining(c->buffer) > 0); ERR_clear_error(); - r = SSL_write(c->ssl, (void*)ldns_buffer_current(c->buffer), - (int)ldns_buffer_remaining(c->buffer)); + r = SSL_write(c->ssl, (void*)sldns_buffer_current(c->buffer), + (int)sldns_buffer_remaining(c->buffer)); if(r <= 0) { int want = SSL_get_error(c->ssl, r); if(want == SSL_ERROR_ZERO_RETURN) { @@ -1133,9 +1166,9 @@ ssl_handle_write(struct comm_point* c) log_crypto_err("could not SSL_write"); return 0; } - ldns_buffer_skip(c->buffer, (ssize_t)r); + sldns_buffer_skip(c->buffer, (ssize_t)r); - if(ldns_buffer_remaining(c->buffer) == 0) { + if(sldns_buffer_remaining(c->buffer) == 0) { tcp_callback_writer(c); } return 1; @@ -1173,7 +1206,7 @@ comm_point_tcp_handle_read(int fd, struct comm_point* c, int short_ok) log_assert(fd != -1); if(c->tcp_byte_count < sizeof(uint16_t)) { /* read length bytes */ - r = recv(fd,(void*)ldns_buffer_at(c->buffer,c->tcp_byte_count), + r = recv(fd,(void*)sldns_buffer_at(c->buffer,c->tcp_byte_count), sizeof(uint16_t)-c->tcp_byte_count, 0); if(r == 0) return 0; @@ -1205,25 +1238,25 @@ comm_point_tcp_handle_read(int fd, struct comm_point* c, int short_ok) c->tcp_byte_count += r; if(c->tcp_byte_count != sizeof(uint16_t)) return 1; - if(ldns_buffer_read_u16_at(c->buffer, 0) > - ldns_buffer_capacity(c->buffer)) { + if(sldns_buffer_read_u16_at(c->buffer, 0) > + sldns_buffer_capacity(c->buffer)) { verbose(VERB_QUERY, "tcp: dropped larger than buffer"); return 0; } - ldns_buffer_set_limit(c->buffer, - ldns_buffer_read_u16_at(c->buffer, 0)); + sldns_buffer_set_limit(c->buffer, + sldns_buffer_read_u16_at(c->buffer, 0)); if(!short_ok && - ldns_buffer_limit(c->buffer) < LDNS_HEADER_SIZE) { + sldns_buffer_limit(c->buffer) < LDNS_HEADER_SIZE) { verbose(VERB_QUERY, "tcp: dropped bogus too short."); return 0; } verbose(VERB_ALGO, "Reading tcp query of length %d", - (int)ldns_buffer_limit(c->buffer)); + (int)sldns_buffer_limit(c->buffer)); } - log_assert(ldns_buffer_remaining(c->buffer) > 0); - r = recv(fd, (void*)ldns_buffer_current(c->buffer), - ldns_buffer_remaining(c->buffer), 0); + log_assert(sldns_buffer_remaining(c->buffer) > 0); + r = recv(fd, (void*)sldns_buffer_current(c->buffer), + sldns_buffer_remaining(c->buffer), 0); if(r == 0) { return 0; } else if(r == -1) { @@ -1247,8 +1280,8 @@ comm_point_tcp_handle_read(int fd, struct comm_point* c, int short_ok) c->repinfo.addrlen); return 0; } - ldns_buffer_skip(c->buffer, r); - if(ldns_buffer_remaining(c->buffer) <= 0) { + sldns_buffer_skip(c->buffer, r); + if(sldns_buffer_remaining(c->buffer) <= 0) { tcp_callback_reader(c); } return 1; @@ -1312,13 +1345,13 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c) return ssl_handle_it(c); if(c->tcp_byte_count < sizeof(uint16_t)) { - uint16_t len = htons(ldns_buffer_limit(c->buffer)); + uint16_t len = htons(sldns_buffer_limit(c->buffer)); #ifdef HAVE_WRITEV struct iovec iov[2]; iov[0].iov_base = (uint8_t*)&len + c->tcp_byte_count; iov[0].iov_len = sizeof(uint16_t) - c->tcp_byte_count; - iov[1].iov_base = ldns_buffer_begin(c->buffer); - iov[1].iov_len = ldns_buffer_limit(c->buffer); + iov[1].iov_base = sldns_buffer_begin(c->buffer); + iov[1].iov_len = sldns_buffer_limit(c->buffer); log_assert(iov[0].iov_len > 0); log_assert(iov[1].iov_len > 0); r = writev(fd, iov, 2); @@ -1354,16 +1387,16 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c) c->tcp_byte_count += r; if(c->tcp_byte_count < sizeof(uint16_t)) return 1; - ldns_buffer_set_position(c->buffer, c->tcp_byte_count - + sldns_buffer_set_position(c->buffer, c->tcp_byte_count - sizeof(uint16_t)); - if(ldns_buffer_remaining(c->buffer) == 0) { + if(sldns_buffer_remaining(c->buffer) == 0) { tcp_callback_writer(c); return 1; } } - log_assert(ldns_buffer_remaining(c->buffer) > 0); - r = send(fd, (void*)ldns_buffer_current(c->buffer), - ldns_buffer_remaining(c->buffer), 0); + log_assert(sldns_buffer_remaining(c->buffer) > 0); + r = send(fd, (void*)sldns_buffer_current(c->buffer), + sldns_buffer_remaining(c->buffer), 0); if(r == -1) { #ifndef USE_WINSOCK if(errno == EINTR || errno == EAGAIN) @@ -1383,9 +1416,9 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c) c->repinfo.addrlen); return 0; } - ldns_buffer_skip(c->buffer, r); + sldns_buffer_skip(c->buffer, r); - if(ldns_buffer_remaining(c->buffer) == 0) { + if(sldns_buffer_remaining(c->buffer) == 0) { tcp_callback_writer(c); } @@ -1468,7 +1501,7 @@ void comm_point_raw_handle_callback(int ATTR_UNUSED(fd), } struct comm_point* -comm_point_create_udp(struct comm_base *base, int fd, ldns_buffer* buffer, +comm_point_create_udp(struct comm_base *base, int fd, sldns_buffer* buffer, comm_point_callback_t* callback, void* callback_arg) { struct comm_point* c = (struct comm_point*)calloc(1, @@ -1518,7 +1551,7 @@ comm_point_create_udp(struct comm_base *base, int fd, ldns_buffer* buffer, struct comm_point* comm_point_create_udp_ancil(struct comm_base *base, int fd, - ldns_buffer* buffer, + sldns_buffer* buffer, comm_point_callback_t* callback, void* callback_arg) { struct comm_point* c = (struct comm_point*)calloc(1, @@ -1584,7 +1617,7 @@ comm_point_create_tcp_handler(struct comm_base *base, } c->ev->base = base; c->fd = -1; - c->buffer = ldns_buffer_new(bufsize); + c->buffer = sldns_buffer_new(bufsize); if(!c->buffer) { free(c->ev); free(c); @@ -1592,7 +1625,7 @@ comm_point_create_tcp_handler(struct comm_base *base, } c->timeout = (struct timeval*)malloc(sizeof(struct timeval)); if(!c->timeout) { - ldns_buffer_free(c->buffer); + sldns_buffer_free(c->buffer); free(c->ev); free(c); return NULL; @@ -1709,7 +1742,7 @@ comm_point_create_tcp_out(struct comm_base *base, size_t bufsize, } c->ev->base = base; c->fd = -1; - c->buffer = ldns_buffer_new(bufsize); + c->buffer = sldns_buffer_new(bufsize); if(!c->buffer) { free(c->ev); free(c); @@ -1735,7 +1768,7 @@ comm_point_create_tcp_out(struct comm_base *base, size_t bufsize, if(event_base_set(base->eb->base, &c->ev->ev) != 0) { log_err("could not basetset tcpout event"); - ldns_buffer_free(c->buffer); + sldns_buffer_free(c->buffer); free(c->ev); free(c); return NULL; @@ -1761,7 +1794,7 @@ comm_point_create_local(struct comm_base *base, int fd, size_t bufsize, } c->ev->base = base; c->fd = fd; - c->buffer = ldns_buffer_new(bufsize); + c->buffer = sldns_buffer_new(bufsize); if(!c->buffer) { free(c->ev); free(c); @@ -1886,7 +1919,7 @@ comm_point_delete(struct comm_point* c) } free(c->timeout); if(c->type == comm_tcp || c->type == comm_local) - ldns_buffer_free(c->buffer); + sldns_buffer_free(c->buffer); free(c->ev); free(c); } @@ -1998,7 +2031,7 @@ size_t comm_point_get_mem(struct comm_point* c) if(c->timeout) s += sizeof(*c->timeout); if(c->type == comm_tcp || c->type == comm_local) - s += sizeof(*c->buffer) + ldns_buffer_capacity(c->buffer); + s += sizeof(*c->buffer) + sldns_buffer_capacity(c->buffer); if(c->type == comm_tcp_accept) { int i; for(i=0; i<c->max_tcp_count; i++) diff --git a/usr.sbin/unbound/util/netevent.h b/usr.sbin/unbound/util/netevent.h index 86fa28569c7..fe28ca5dd75 100644 --- a/usr.sbin/unbound/util/netevent.h +++ b/usr.sbin/unbound/util/netevent.h @@ -21,16 +21,16 @@ * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @@ -60,7 +60,7 @@ #ifndef NET_EVENT_H #define NET_EVENT_H -#include <ldns/buffer.h> +struct sldns_buffer; struct comm_point; struct comm_reply; struct event_base; @@ -149,7 +149,7 @@ struct comm_point { struct timeval* timeout; /** buffer pointer. Either to perthread, or own buffer or NULL */ - ldns_buffer* buffer; + struct sldns_buffer* buffer; /* -------- TCP Handler -------- */ /** Read/Write state for TCP */ @@ -295,6 +295,21 @@ struct comm_signal { struct comm_base* comm_base_create(int sigs); /** + * Create comm base that uses the given event_base (underlying event + * mechanism pointer). + * @param base: underlying lib event base. + * @return: the new comm base. NULL on error. + */ +struct comm_base* comm_base_create_event(struct event_base* base); + +/** + * Delete comm base structure but not the underlying lib event base. + * All comm points must have been deleted. + * @param b: the base to delete. + */ +void comm_base_delete_no_base(struct comm_base* b); + +/** * Destroy a comm base. * All comm points must have been deleted. * @param b: the base to delete. @@ -352,7 +367,7 @@ struct event_base* comm_base_internal(struct comm_base* b); * Sets timeout to NULL. Turns off TCP options. */ struct comm_point* comm_point_create_udp(struct comm_base* base, - int fd, ldns_buffer* buffer, + int fd, struct sldns_buffer* buffer, comm_point_callback_t* callback, void* callback_arg); /** @@ -368,7 +383,7 @@ struct comm_point* comm_point_create_udp(struct comm_base* base, * Sets timeout to NULL. Turns off TCP options. */ struct comm_point* comm_point_create_udp_ancil(struct comm_base* base, - int fd, ldns_buffer* buffer, + int fd, struct sldns_buffer* buffer, comm_point_callback_t* callback, void* callback_arg); /** @@ -462,7 +477,7 @@ void comm_point_drop_reply(struct comm_reply* repinfo); * @param addrlen: length of addr. * @return: false on a failure. */ -int comm_point_send_udp_msg(struct comm_point* c, ldns_buffer* packet, +int comm_point_send_udp_msg(struct comm_point* c, struct sldns_buffer* packet, struct sockaddr* addr, socklen_t addrlen); /** |