Commit f5436f49 authored by Martti Mela's avatar Martti Mela

stun: initial keepalive support

darcs-hash:20060220135136-1b897-e141387b40a6a8fd42305a06f07732e39140a243.gz
parent 98174a01
......@@ -9816,3 +9816,13 @@ nta_compartment_decref(struct sigcomp_compartment **pcc)
}
#endif
/** Initiate STUN keepalive controller to TPORT */
int nta_tport_keepalive(nta_outgoing_t *orq)
{
tport_t *tp;
assert(orq);
return tport_keepalive(orq->orq_tport, orq->orq_tpn);
}
......@@ -227,6 +227,8 @@ nta_leg_t *nta_leg_by_dialog(nta_agent_t const *agent,
url_t const *to_url);
int nta_tport_keepalive(nta_outgoing_t *orq);
/* ----------------------------------------------------------------------
* 6) Prototypes for incoming transactions
*/
......
......@@ -3446,6 +3446,10 @@ int process_response_to_register(nua_handle_t *nh,
nua->nua_service_route = NULL;
/* process_response() takes care of removing the dialog usage */
}
else {
nta_tport_keepalive(orq);
}
}
else if (status >= 300) {
if (crequest_check_restart(nh, cr, orq, sip, restart_register))
......
v v v v v v v
2006-01-26 Martti Mela <martti.mela@nokia.com>
* STUN: initial keepalive dispatcher
M ./libsofia-sip-ua/stun/stun.c -28 +149
M ./libsofia-sip-ua/stun/stun.h +9
M ./libsofia-sip-ua/stun/stun_tag.c +16
M ./libsofia-sip-ua/stun/stun_tag.h +6
M ./libsofia-sip-ua/stun/stunc.c +6
*************
2006-02-09 Kai Vehmanen <kai.vehmanen@nokia.com>
* stun_tag.h: Added STUN_DOMAIN() and STUN_REQUIRE_INTEGRITY().
Deprecated STUN_INTEGRITY.
* stun.c: Mark wait entries as deregistered after
su_root_deregister().
2006-01-26 Martti Mela <martti.mela@nokia.com>
* STUN: initial keepalive dispatcher
M ./libsofia-sip-ua/stun/stun.c -28 +149
M ./libsofia-sip-ua/stun/stun.h +9
M ./libsofia-sip-ua/stun/stun_tag.c +16
M ./libsofia-sip-ua/stun/stun_tag.h +6
M ./libsofia-sip-ua/stun/stunc.c +6
^ ^ ^ ^ ^ ^ ^
2006-01-19 Martti Mela <martti.mela@nokia.com>
* stun.c: assign_socket() now takes care of socket registering and
......
......@@ -180,14 +180,24 @@ int stun_handle_set_uname_pwd(stun_handle_t *sh,
su_sockaddr_t *stun_discovery_get_address(stun_discovery_t *sd);
/** Determine if the message is STUN message (-1 if not stun). */
int stun_msg_is_keepalive(uint16_t data);
/** Determine length of STUN message (0 if not stun). */
int stun_message_length(void *data, int len, int end_of_message);
/** Process incoming message */
int stun_handle_process_message(stun_handle_t *sh, void *data, int len);
int stun_handle_process_message(stun_handle_t *sh, su_socket_t s,
su_sockaddr_t *sa, socklen_t salen,
void *data, int len);
int stun_process_request(su_socket_t s, stun_msg_t *req,
int sid, su_sockaddr_t *from_addr,
int from_len);
/* Create a keepalive dispatcher for bound SIP sockets */
int stun_keepalive(stun_handle_t *sh,
su_sockaddr_t *sa,
tag_type_t tag, tag_value_t value,
...);
......
This diff is collapsed.
......@@ -78,7 +78,6 @@ extern char const STUN_DEBUG[]; /* dummy declaration for Doxygen */
SU_DEBUG_5(("%s: %s: %s\n", __func__, #what, su_strerror(err))); \
}
int stun_is_requested(tag_type_t tag, tag_value_t value, ...);
/** other functions */
......
......@@ -323,6 +323,9 @@ int tport_convert_addr(su_home_t *home,
char *tport_hostport(char buf[], int bufsize,
su_sockaddr_t const *su, int with_port);
/** Initialize STUN keepalives. */
int tport_keepalive(tport_t *tp, tp_name_t *tpn);
/* ---------------------------------------------------------------------- */
/* SigComp-related functions */
......
......@@ -258,6 +258,7 @@ struct tport_s {
stun_socket_t *tp_stun_socket;
#endif
su_socket_t tp_stun_socket;
int tp_has_keepalive;
#endif
/* ==== Receive queue ================================================== */
......@@ -3012,6 +3013,8 @@ static void tport_recv_event(tport_t *self, int event)
su_strerror(EAGAIN), EAGAIN));
}
}
else if (again == 1) /* STUN keepalive */
return;
self->tp_time = su_time_ms(now);
......@@ -3215,6 +3218,7 @@ tport_delivered_using_udvm(tport_t *tp, msg_t const *msg,
static int tport_recv_stream(tport_t *self);
static int tport_recv_dgram(tport_t *self);
static int tport_recv_dgram_r(tport_t const *self, msg_t **mmsg, int N);
static int tport_recv_try_stun_dgram(tport_t const *self);
#if HAVE_TLS
static int tport_recv_tls(tport_t *self);
......@@ -3388,6 +3392,14 @@ int tport_recv_dgram_r(tport_t const *self, msg_t **mmsg, int N)
assert(*mmsg == NULL);
#if HAVE_SOFIA_STUN
{
/* Check always if incoming data is STUN keepalive */
if (tport_recv_try_stun_dgram(self) >= 0)
return 1;
}
#endif
veclen = tport_recv_iovec(self, mmsg, iovec, N, 1);
if (veclen < 0)
return -1;
......@@ -3414,6 +3426,83 @@ int tport_recv_dgram_r(tport_t const *self, msg_t **mmsg, int N)
return 0;
}
#if HAVE_SOFIA_STUN
/** Initialize STUN keepalives.
*
*@retval 0
*/
int tport_keepalive(tport_t *tp, tp_name_t *tpn)
{
int err;
tport_master_t *mr = tp->tp_master;
stun_handle_t *sh = mr->mr_nat->stun;
su_sockaddr_t sa[1] = {{ 0 }};
if (tp->tp_has_keepalive == 1)
return 0;
inet_pton(AF_INET, tpn->tpn_host, (void *) &sa->su_sin.sin_addr.s_addr);
sa->su_port = htons(atoi(tpn->tpn_port));
sa->su_family = AF_INET;
/*XXX -- remove me after it's working */
memcpy(sa, tp->tp_addr, sizeof(*sa));
err = stun_keepalive(sh, sa,
STUNTAG_SOCKET(tp->tp_socket),
STUNTAG_TIMEOUT(10000),
TAG_NULL());
if (err < 0)
return -1;
tp->tp_has_keepalive = 1;
return 0;
}
/** Receive STUN datagram.
*
* @retval -1 error
* @retval 0 end-of-stream
*/
static
int tport_recv_try_stun_dgram(tport_t const *self)
{
int n, len;
su_sockaddr_t from[1];
socklen_t fromlen = sizeof(su_sockaddr_t);
/* char *buf = NULL; */
char dgram[50] = { 0 }; /* XXX - max size of STUN msg, please. */
stun_msg_t msg;
char sample[2];
recv(self->tp_socket, &sample, sizeof(sample), MSG_PEEK);
len = stun_message_length(sample, sizeof(sample), 0);
/* message is not a STUN message */
if (len < 0)
return len;
memset(from, 0, sizeof(su_sockaddr_t));
n = recvfrom(self->tp_socket, &dgram, sizeof(dgram), 0, &from->su_sa,
&fromlen);
if (n == SOCKET_ERROR) {
int error = su_errno();
su_seterrno(error);
return -1;
}
stun_handle_process_message(self->tp_master->mr_nat->stun, self->tp_socket,
from, fromlen, dgram, n);
return 0;
}
#endif /* HAVE_SOFIA_STUN */
/** Receive from stream.
*
* @retval -1 error
......@@ -6930,7 +7019,7 @@ tport_nat_initialize_nat_traversal(tport_master_t *mr,
for (i = 0; stun_transports[i]; i++) {
if ((strcmp(tpn->tpn_proto, "*") == 0 ||
strcasecmp(tpn->tpn_proto, stun_transports[i]) == 0)) {
SU_DEBUG_5(("%s(%p) starting STUN engine\n", __func__, mr));
SU_DEBUG_5(("%s(%p) creating STUN handle\n", __func__, mr));
nat->stun = stun_handle_create(mr,
mr->mr_root,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment