logging nicer, removal of reply_iov.
git-svn-id: https://unbound.nlnetlabs.nl/svn/trunk@911 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
0e6c6e9734
commit
d64c4d8e4c
@ -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
|
||||
|
||||
|
66
configure
vendored
66
configure
vendored
@ -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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
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
|
||||
|
23
configure.ac
23
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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
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)
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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; i<iovlen; i++)
|
||||
len += iov[i].iov_len;
|
||||
len = htons(len);
|
||||
iov[0].iov_base = (void*)&len;
|
||||
iov[0].iov_len = sizeof(uint16_t);
|
||||
if((done=writev(repinfo->c->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; i<iovlen; i++)
|
||||
ldns_buffer_write(repinfo->c->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)
|
||||
{
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user