From e8fdeec3948ba5376e22d5683ad5ce3a536962e2 Mon Sep 17 00:00:00 2001 From: Richard Aas Date: Mon, 17 Jan 2011 15:24:55 +0000 Subject: [PATCH] natbd segfault and debug fixes --- src/natbd/lifetime.c | 14 ++++++++++---- src/natbd/mapping.c | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/natbd/lifetime.c b/src/natbd/lifetime.c index 2eaa9be..9dc6065 100644 --- a/src/natbd/lifetime.c +++ b/src/natbd/lifetime.c @@ -35,6 +35,8 @@ /** Defines a NAT Binding Lifetime Discovery session */ struct nat_lifetime { struct stun *stun; /**< STUN Client */ + struct stun_ctrans *ctx; /**< STUN Transaction 1 */ + struct stun_ctrans *cty; /**< STUN Transaction 2 */ struct udp_sock *us_x; /**< First UDP socket */ struct udp_sock *us_y; /**< Second UDP socket */ struct sa srv; /**< Server IP-address/port */ @@ -181,8 +183,9 @@ static int start_test(struct nat_lifetime *nl) tmr_cancel(&nl->tmr); - return stun_request(NULL, nl->stun, IPPROTO_UDP, nl->us_x, &nl->srv, 0, - STUN_METHOD_BINDING, NULL, 0, false, + nl->ctx = mem_deref(nl->ctx); + return stun_request(&nl->ctx, nl->stun, IPPROTO_UDP, nl->us_x, + &nl->srv, 0, STUN_METHOD_BINDING, NULL, 0, false, stun_response_handler_x, nl, 1, STUN_ATTR_SOFTWARE, stun_software); } @@ -196,8 +199,9 @@ static void timeout(void *arg) nl->probing = true; - err = stun_request(NULL, nl->stun, IPPROTO_UDP, nl->us_y, &nl->srv, 0, - STUN_METHOD_BINDING, NULL, 0, false, + nl->cty = mem_deref(nl->cty); + err = stun_request(&nl->cty, nl->stun, IPPROTO_UDP, nl->us_y, + &nl->srv, 0, STUN_METHOD_BINDING, NULL, 0, false, stun_response_handler_y, nl, 2, STUN_ATTR_RESP_PORT, &rp, STUN_ATTR_SOFTWARE, stun_software); @@ -250,6 +254,8 @@ static void lifetime_destructor(void *data) tmr_cancel(&nl->tmr); + mem_deref(nl->ctx); + mem_deref(nl->cty); mem_deref(nl->us_x); mem_deref(nl->us_y); mem_deref(nl->stun); diff --git a/src/natbd/mapping.c b/src/natbd/mapping.c index c907f8a..105ed54 100644 --- a/src/natbd/mapping.c +++ b/src/natbd/mapping.c @@ -84,7 +84,9 @@ static void stun_response_handler(int err, uint16_t scode, const char *reason, map = stun_msg_attr(msg, STUN_ATTR_MAPPED_ADDR); if (!map || !other) { - DEBUG_WARNING("mapped- or other-addr attr missing\n"); + DEBUG_WARNING("missing attributes: %s %s\n", + map ? "" : "MAPPED-ADDR", + other ? "" : "OTHER-ADDR"); nm->mh(EPROTO, NAT_TYPE_UNKNOWN, nm->arg); return; }