From: Wouter Wijngaards Date: Wed, 30 Jan 2008 14:46:01 +0000 (+0000) Subject: logging nicer, removal of reply_iov. X-Git-Tag: release-0.9~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b4ef794b950d5246cb3d2a5b3e46c2d46e75949;p=thirdparty%2Funbound.git logging nicer, removal of reply_iov. git-svn-id: file:///svn/unbound/trunk@911 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/config.h.in b/config.h.in index 19988afa8..e4b7ff8a0 100644 --- a/config.h.in +++ b/config.h.in @@ -185,9 +185,6 @@ /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS -/* Define to 'int' or type of struct msghdr.msg_iovlen. */ -#undef TYPE_MSGIOVLEN - /* use statistics for allocs and frees, for debug use */ #undef UNBOUND_ALLOC_STATS diff --git a/configure b/configure index 4df0f2f29..a36978e17 100755 --- a/configure +++ b/configure @@ -20547,72 +20547,6 @@ _ACEOF fi -# Check the type of struct msghdr msg_iovlen. -{ echo "$as_me:$LINENO: checking sign of struct msghdr.msg_iovlen" >&5 -echo $ECHO_N "checking sign of struct msghdr.msg_iovlen... $ECHO_C" >&6; } -if test "$cross_compiling" = yes; then - # when cross compiling - cv_msgiovlen_type="int" -else - cat >conftest.$ac_ext <<_ACEOF - -#include -#include -#include -int main() -{ - struct msghdr h; - h.msg_iovlen = -1; - if(10/h.msg_iovlen == 0) return 0; /* unsigned */ - return 1; /* signed */ -} - -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - -# if compiled and exit status 0 -cv_msgiovlen_type="unsigned" -else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) - -# not compiled or bad exit status -cv_msgiovlen_type="int" -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -{ echo "$as_me:$LINENO: result: $cv_msgiovlen_type" >&5 -echo "${ECHO_T}$cv_msgiovlen_type" >&6; } - -cat >>confdefs.h <<_ACEOF -#define TYPE_MSGIOVLEN $cv_msgiovlen_type -_ACEOF - - # Check for yyunput { echo "$as_me:$LINENO: checking whether lex can not generate yyunput" >&5 diff --git a/configure.ac b/configure.ac index bdc0df5a7..0fa55dca8 100644 --- a/configure.ac +++ b/configure.ac @@ -395,29 +395,6 @@ AC_INCLUDES_DEFAULT #endif ]) -# Check the type of struct msghdr msg_iovlen. -AC_MSG_CHECKING([sign of struct msghdr.msg_iovlen]) -AC_RUN_IFELSE([ -#include -#include -#include -int main() -{ - struct msghdr h; - h.msg_iovlen = -1; - if(10/h.msg_iovlen == 0) return 0; /* unsigned */ - return 1; /* signed */ -} -], [ -# if compiled and exit status 0 -cv_msgiovlen_type="unsigned" ], [ -# not compiled or bad exit status -cv_msgiovlen_type="int" ], -# when cross compiling -[ cv_msgiovlen_type="int" ]) -AC_MSG_RESULT($cv_msgiovlen_type) -AC_DEFINE_UNQUOTED([TYPE_MSGIOVLEN], $cv_msgiovlen_type, [Define to 'int' or type of struct msghdr.msg_iovlen.]) - # Check for yyunput AC_DEFUN([CHECK_YYUNPUT], [AC_MSG_CHECKING(whether lex can not generate yyunput) diff --git a/doc/Changelog b/doc/Changelog index 2d1abab25..63573bee4 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,10 @@ 29 January 2008: Wouter - check trailing / on chrootdir in checkconf. - check if root hints and anchor files are in chrootdir. + - no route to host tcp error is verbosity level 2. + - removed unused send_reply_iov. and its configure check. + - added prints of 'remote address is 1.2.3.4 port 53' to errors + from netevent; the basic socket errors. 28 January 2008: Wouter - fixup uninit use of buffer by libunbound (query id, flags) for diff --git a/services/outside_network.c b/services/outside_network.c index 2e7fad850..7789bf47f 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -1062,7 +1062,7 @@ serviced_tcp_initiate(struct outside_network* outnet, { serviced_encode(sq, buff, sq->status == serviced_query_TCP_EDNS); sq->pending = pending_tcp_query(outnet, buff, &sq->addr, - sq->addrlen, TCP_QUERY_TIMEOUT, serviced_tcp_callback, + sq->addrlen, TCP_AUTH_QUERY_TIMEOUT, serviced_tcp_callback, sq, outnet->rnd); if(!sq->pending) { /* delete from tree so that a retry by above layer does not @@ -1100,7 +1100,7 @@ serviced_udp_callback(struct comm_point* c, void* arg, int error, } return 0; } - if(rto >= RTT_MAX_TIMEOUT) { + if(1 || /* @@@ DEBUG */ rto >= RTT_MAX_TIMEOUT) { fallback_tcp = 1; /* UDP does not work, fallback to TCP below */ } else { diff --git a/testcode/fake_event.c b/testcode/fake_event.c index d63102ad6..fa2a907bb 100644 --- a/testcode/fake_event.c +++ b/testcode/fake_event.c @@ -662,15 +662,6 @@ comm_point_send_reply(struct comm_reply* repinfo) log_pkt("reply pkt: ", ans->pkt); } -void -comm_point_send_reply_iov(struct comm_reply* repinfo, struct iovec* iov, - size_t iovlen) -{ - /* skip tcp len at [0]. */ - write_iov_buffer(repinfo->c->buffer, iov+1, iovlen-1); - comm_point_send_reply(repinfo); -} - void comm_point_drop_reply(struct comm_reply* repinfo) { @@ -863,7 +854,7 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet, pend->addrlen = addrlen; pend->callback = callback; pend->cb_arg = callback_arg; - pend->timeout = UDP_QUERY_TIMEOUT; + pend->timeout = UDP_AUTH_QUERY_TIMEOUT; pend->transport = transport_udp; /* pretend UDP */ pend->pkt = NULL; pend->runtime = runtime; diff --git a/util/net_help.c b/util/net_help.c index 3d6cb5e95..438772e47 100644 --- a/util/net_help.c +++ b/util/net_help.c @@ -169,8 +169,10 @@ log_addr(enum verbosity_value v, const char* str, } dest[sizeof(dest)-1] = 0; port = ntohs(((struct sockaddr_in*)addr)->sin_port); - log_info("%s %s %s %d (len %d)", str, family, dest, (int)port, - (int)addrlen); + if(verbosity >= 4) + log_info("%s %s %s port %d (len %d)", str, family, dest, + (int)port, (int)addrlen); + else log_info("%s %s port %d", str, dest, (int)port); } int diff --git a/util/net_help.h b/util/net_help.h index a34be2484..6bbcde01c 100644 --- a/util/net_help.h +++ b/util/net_help.h @@ -70,9 +70,9 @@ #define FLAGS_SET_RCODE(f, r) (f = (((f) & 0xfff0) | (r))) /** timeout in seconds for UDP queries to auth servers. */ -#define UDP_QUERY_TIMEOUT 4 +#define UDP_AUTH_QUERY_TIMEOUT 4 /** timeout in seconds for TCP queries to auth servers. */ -#define TCP_QUERY_TIMEOUT 30 +#define TCP_AUTH_QUERY_TIMEOUT 30 /** Advertised version of EDNS capabilities */ #define EDNS_ADVERTISED_VERSION 0 /** Advertised size of EDNS capabilities */ diff --git a/util/netevent.c b/util/netevent.c index 1ca747506..87a72e106 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -41,6 +41,7 @@ #include "util/netevent.h" #include "util/log.h" +#include "util/net_help.h" #include "util/fptr_wlist.h" /* -------- Start of local definitions -------- */ @@ -169,6 +170,8 @@ comm_point_send_udp_msg(struct comm_point *c, ldns_buffer* packet, addr, addrlen); if(sent == -1) { verbose(VERB_OPS, "sendto failed: %s", strerror(errno)); + log_addr(VERB_OPS, "remote address is", + (struct sockaddr_storage*)addr, addrlen); return 0; } else if((size_t)sent != ldns_buffer_remaining(packet)) { log_err("sent %d in place of %d bytes", @@ -294,6 +297,8 @@ comm_point_send_udp_msg_if(struct comm_point *c, ldns_buffer* packet, sent = sendmsg(c->fd, &msg, 0); if(sent == -1) { verbose(VERB_OPS, "sendmsg failed: %s", strerror(errno)); + log_addr(VERB_OPS, "remote address is", + (struct sockaddr_storage*)addr, addrlen); return 0; } else if((size_t)sent != ldns_buffer_remaining(packet)) { log_err("sent %d in place of %d bytes", @@ -473,6 +478,8 @@ comm_point_tcp_accept_callback(int fd, short event, void* arg) ) return; log_err("accept failed: %s", strerror(errno)); + log_addr(0, "remote address is", &c_hdl->repinfo.addr, + c_hdl->repinfo.addrlen); return; } /* grab the tcp handler buffers */ @@ -561,6 +568,8 @@ comm_point_tcp_handle_read(int fd, struct comm_point* c, int short_ok) if(errno == ECONNRESET && verbosity < 2) return 0; /* silence reset by peer */ log_err("read (in tcp s): %s", strerror(errno)); + log_addr(0, "remote address is", &c->repinfo.addr, + c->repinfo.addrlen); return 0; } c->tcp_byte_count += r; @@ -591,6 +600,8 @@ comm_point_tcp_handle_read(int fd, struct comm_point* c, int short_ok) if(errno == EINTR || errno == EAGAIN) return 1; log_err("read (in tcp r): %s", strerror(errno)); + log_addr(0, "remote address is", &c->repinfo.addr, + c->repinfo.addrlen); return 0; } ldns_buffer_skip(c->buffer, r); @@ -624,10 +635,18 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c) } if(error == EINPROGRESS || error == EWOULDBLOCK) return 1; /* try again later */ - if(error == ECONNREFUSED && verbosity < 2) - return 0; /* silence 'connection refused' */ - if(error != 0) { +#ifdef ECONNREFUSED + else if(error == ECONNREFUSED && verbosity < 2) + return 0; /* silence 'connection refused' */ +#endif +#ifdef EHOSTUNREACH + else if(error == EHOSTUNREACH && verbosity < 2) + return 0; /* silence 'no route to host' */ +#endif + else if(error != 0) { log_err("tcp connect: %s", strerror(error)); + log_addr(0, "remote address is", &c->repinfo.addr, + c->repinfo.addrlen); return 0; } } @@ -646,6 +665,8 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c) if(errno == EINTR || errno == EAGAIN) return 1; log_err("tcp writev: %s", strerror(errno)); + log_addr(0, "remote address is", &c->repinfo.addr, + c->repinfo.addrlen); return 0; } c->tcp_byte_count += r; @@ -665,6 +686,8 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c) if(errno == EINTR || errno == EAGAIN) return 1; log_err("tcp write: %s", strerror(errno)); + log_addr(0, "remote address is", &c->repinfo.addr, + c->repinfo.addrlen); return 0; } ldns_buffer_skip(c->buffer, r); @@ -1163,69 +1186,6 @@ comm_point_send_reply(struct comm_reply *repinfo) } } -void -comm_point_send_reply_iov(struct comm_reply* repinfo, struct iovec* iov, - size_t iovlen) -{ - log_assert(repinfo && repinfo->c); - log_assert(repinfo->c->fd != -1); - log_assert(repinfo->addrlen > 0); - if(repinfo->c->type == comm_udp) { - struct msghdr hdr; - memset(&hdr, 0, sizeof(hdr)); - hdr.msg_name = &repinfo->addr; - hdr.msg_namelen = repinfo->addrlen; - hdr.msg_iov = iov + 1; - hdr.msg_iovlen = (TYPE_MSGIOVLEN)(iovlen - 1); - /* note that number of characters sent is not checked. */ - if(sendmsg(repinfo->c->fd, &hdr, 0) == -1) - log_err("sendmsg: %s", strerror(errno)); - } else { - /* try if it can be sent in writev right now */ - size_t i; - uint16_t len = 0; - ssize_t done; - for(i=1; ic->fd, iov, (int)iovlen)) == -1) { -#ifdef S_SPLINT_S - /* don't complain about returning stack references */ - iov[0].iov_base = NULL; -#endif - if(errno != EINTR && errno != EAGAIN) { - log_err("writev: %s", strerror(errno)); - comm_point_drop_reply(repinfo); - return; - } - done = 0; - } -#ifdef S_SPLINT_S - /* don't complain about returning stack references */ - iov[0].iov_base = NULL; -#endif - if((size_t)done == ntohs(len) + sizeof(uint16_t)) { - /* done in one call */ - comm_point_drop_reply(repinfo); - } else { - /* sending remaining bytes */ - ldns_buffer_clear(repinfo->c->buffer); - repinfo->c->tcp_byte_count = (size_t)done; - for(i=1; ic->buffer, - iov[i].iov_base, iov[i].iov_len); - ldns_buffer_flip(repinfo->c->buffer); - if((size_t)done >= sizeof(uint16_t)) - ldns_buffer_set_position(repinfo->c->buffer, - (size_t)done - sizeof(uint16_t)); - comm_point_start_listening(repinfo->c, -1, - TCP_QUERY_TIMEOUT); - } - } -} - void comm_point_drop_reply(struct comm_reply* repinfo) { diff --git a/util/netevent.h b/util/netevent.h index fb77eb9e9..c45ee4814 100644 --- a/util/netevent.h +++ b/util/netevent.h @@ -391,18 +391,6 @@ void comm_point_set_cb_arg(struct comm_point* c, void* arg); */ void comm_point_send_reply(struct comm_reply* repinfo); -/** - * Send reply. Message is not put into commpoint buffer, but in iovec. - * If it cannot be sent immediately (TCP) the message is copied to the buffer. - * @param repinfo: reply info copied from commpoint callback call. - * @param iov: iovector, array of base, len parts to send out. - * caller must keep entry 0 free for use by tcp handler. Start at entry 1. - * @param iovlen: number of iov items to concatenate and send out. - * this includes the entry 0, which is not filled in by caller. - */ -void comm_point_send_reply_iov(struct comm_reply* repinfo, struct iovec* iov, - size_t iovlen); - /** * Drop reply. Cleans up. * @param repinfo: The reply info copied from a commpoint callback call.