Commit 434135be authored by Pekka Pessi's avatar Pekka Pessi

Updated stun tags, fixed su_root handling (kv)

darcs-hash:20060215183551-65a35-6762bd54e1ce2bcca77297ef3fa35e80d53be861.gz
parent 10321b43
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
......
......@@ -177,8 +177,8 @@ struct stun_handle_s
stun_buffer_t sh_username;
stun_buffer_t sh_passwd;
int sh_use_msgint; /**< use message integrity? */
/* int sh_state; */ /**< Progress states */
int sh_use_msgint; /**< try message integrity (TLS) */
int sh_req_msgint; /**< require use of msg-int (TLS) */
};
......@@ -314,7 +314,8 @@ int stun_is_requested(tag_type_t tag, tag_value_t value, ...)
*
* @TAGS
* @TAG STUNTAG_SERVER() stun server hostname or dotted IPv4 address
* @TAG STUNTAG_INTEGRITY() true if msg integrity should be used
* @TAG STUNTAG_REQUIRE_INTEGRITY() true if msg integrity should be
* used enforced
*
*/
stun_handle_t *stun_handle_create(stun_magic_t *context,
......@@ -324,7 +325,7 @@ stun_handle_t *stun_handle_create(stun_magic_t *context,
{
stun_handle_t *stun = NULL;
char const *server = NULL;
int msg_integrity = 1;
int req_msg_integrity = 1;
int err;
ta_list ta;
......@@ -334,7 +335,7 @@ stun_handle_t *stun_handle_create(stun_magic_t *context,
tl_gets(ta_args(ta),
STUNTAG_SERVER_REF(server),
STUNTAG_INTEGRITY_REF(msg_integrity),
STUNTAG_REQUIRE_INTEGRITY_REF(req_msg_integrity),
TAG_END());
stun = su_home_clone(NULL, sizeof(*stun));
......@@ -375,7 +376,10 @@ stun_handle_t *stun_handle_create(stun_magic_t *context,
stun->sh_root = root;
stun->sh_context = context;
stun->sh_callback = cb;
stun->sh_use_msgint = msg_integrity;
/* always try TLS: */
stun->sh_use_msgint = 1;
/* whether use of shared-secret msgint is required */
stun->sh_req_msgint = req_msg_integrity;
stun->sh_max_retries = STUN_MAX_RETRX;
......@@ -570,8 +574,9 @@ void stun_handle_destroy(stun_handle_t *sh)
kill = sd;
sd = sd->sd_next;
/* Index has same value as sockfd, right? */
su_root_deregister(sh->sh_root, kill->sd_socket);
/* Index has same value as sockfd, right? ... or not? */
if (kill->sd_index != -1)
su_root_deregister(sh->sh_root, kill->sd_index);
if (kill->sd_action == stun_action_tls_query)
su_close(kill->sd_socket);
......@@ -690,6 +695,10 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s)
}
/**
* Helper function needed by Cygwin builds.
*/
#if defined (__CYGWIN__)
static int get_localinfo(su_localinfo_t *clientinfo)
{
su_localinfo_t hints[1] = {{ LI_CANONNAME | LI_NUMERIC }}, *li, *res = NULL;
......@@ -733,7 +742,7 @@ static int get_localinfo(su_localinfo_t *clientinfo)
return 0;
}
#endif
/** Bind a socket using STUN client.
*
......@@ -997,6 +1006,7 @@ int stun_tls_callback(su_root_magic_t *m, su_wait_t *w, su_wakeup_arg_t *arg)
if (one || events & SU_WAIT_ERR) {
su_wait_destroy(w);
su_root_deregister(self->sh_root, sd->sd_index);
sd->sd_index = -1; /* mark index as deregistered */
/* Destroy the timeout timer */
/* su_timer_destroy(sd->sd_connect_timer); */
......@@ -1071,6 +1081,7 @@ int stun_tls_callback(su_root_magic_t *m, su_wait_t *w, su_wakeup_arg_t *arg)
else if (z < 1) {
su_wait_destroy(w);
su_root_deregister(self->sh_root, sd->sd_index);
sd->sd_index = -1; /* mark index as deregistered */
stun_free_buffer(&msg_req->enc_buf);
sd->sd_state = stun_tls_connection_failed;
......@@ -1194,6 +1205,7 @@ int stun_tls_callback(su_root_magic_t *m, su_wait_t *w, su_wakeup_arg_t *arg)
su_wait_destroy(w);
su_root_deregister(self->sh_root, sd->sd_index);
sd->sd_index = -1; /* mark index as deregistered */
self->sh_use_msgint = 1;
sd->sd_state = stun_tls_done;
......@@ -1228,6 +1240,7 @@ void stun_tls_connect_timer_cb(su_root_magic_t *magic,
SU_DEBUG_7(("%s: connect() timeout.\n", __func__));
su_root_deregister(sh->sh_root, sd->sd_index);
sd->sd_index = -1; /* mark index as deregistered */
sd->sd_state = stun_tls_connection_timeout;
sh->sh_callback(sh->sh_context, sh, NULL, sd, sd->sd_action, sd->sd_state);
......@@ -2346,6 +2359,7 @@ int stun_handle_release(stun_handle_t *sh, su_socket_t s)
continue;
su_root_deregister(sh->sh_root, sd->sd_index);
sd->sd_index = -1; /* mark index as deregistered */
SU_DEBUG_3(("%s: socket deregistered from STUN \n", __func__));
return 0;
......@@ -2426,8 +2440,7 @@ void stun_keepalive_timer_cb(su_root_magic_t *magic,
{
stun_request_t *req = arg;
stun_handle_t *sh = req->sr_handle;
int s = -1, timeout = -1, err;
int sa_len;
int timeout = -1;
su_sockaddr_t *destination;
su_timer_t *keepalive_timer = NULL;
stun_discovery_t *sd = req->sr_discovery;
......@@ -2451,11 +2464,9 @@ void stun_keepalive_timer_cb(su_root_magic_t *magic,
int stun_keepalive_destroy(stun_handle_t *sh, su_socket_t s)
{
stun_discovery_t *sd, *tmp;
stun_discovery_t *sd;
stun_request_t *req;
stun_action_t action = stun_action_keepalive;
int i;
for (req = sh->sh_requests; req; req = req->sr_next) {
sd = req->sr_discovery;
......
......@@ -13,11 +13,15 @@ client library.
@section stun_usage Using Sofia STUN Library
To be written.
To be written. See torture_stun.c and tport/tport.c.
@section todo Todo
- rename some functions to be more attractive (added 20060118)
- implement full support for STUN_REQUIRE_INTEGRITY() - IOW,
always try TLS, but only in strict mode fail the discovery if
TLS is not available (added 20060209)
- add support for STUN_DOMAIN() tag (added 20060209); see
sffeat:1326013
- output a summary of results at the end of
stund_bind_test() (added 20051118)
- stun_bind_test does not detect, if the server does
......
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
* Copyright (C) 2005-2006 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
......@@ -25,6 +25,8 @@
/**@CFILE stun_tag.c Tags and tag lists for Offer/Answer Engine
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
* @author Martti Mela <Martti.Mela@nokia.com>
* @author Kai Vehmanen <Kai.Vehmanen@nokia.com>
*
* @date Created: Wed Aug 3 20:28:17 EEST 2005
*/
......@@ -41,9 +43,29 @@
*/
tag_typedef_t stuntag_any = NSTAG_TYPEDEF(*);
/**@def STUNTAG_DOMAIN(x)
*
* The domain to use in DNS-SRV based STUN server discovery.
* Note: this is commonly the domain part of a public SIP
* address (AOR). See sect 9.1 of RFC3489.
*
* @par Used with
* nua_set_params() \n
* nua_get_params() \n
* nua_invite() \n
* nua_respond()
*
* @par Parameter type
* char const *
*/
tag_typedef_t stuntag_domain = STRTAG_TYPEDEF(domain);
/**@def STUNTAG_SERVER(x)
*
* Pass media address.
* Fully qualified host name, or dotted IP address of the STUN server
* address. If defined, the DNS-SRV based discovery (@see STUNTAG_DOMAIN())
* will be skipped.
*
* @par Used with
* nua_set_params() \n
......@@ -62,9 +84,11 @@ tag_typedef_t stuntag_any = NSTAG_TYPEDEF(*);
*/
tag_typedef_t stuntag_server = STRTAG_TYPEDEF(server);
/**@def STUNTAG_INTEGRITY(x)
/**@def STUNTAG_REQUIRE_INTEGRITY(x)
*
* Enable integrity protection.
* Whether to require support for shared-secret based packet
* authentication and integrity checks (see sect 9.2 of RFC3489).
* If false, integrity checks are performed only when server supports it.
*
* @par Used with
* nua_create() \n
......@@ -78,7 +102,14 @@ tag_typedef_t stuntag_server = STRTAG_TYPEDEF(server);
*
* Corresponding tag taking reference parameter is STUNTAG_INTEGRITY_REF()
*/
tag_typedef_t stuntag_integrity = BOOLTAG_TYPEDEF(srtp_integrity);
tag_typedef_t stuntag_require_integrity = BOOLTAG_TYPEDEF(require_integrity);
/**@def STUNTAG_INTEGRITY(x)
*
* Note: use of this tag is deprecated, use
* STUNTAG_REQURIE_INTEGRITY() instead.
*/
tag_typedef_t stuntag_integrity = BOOLTAG_TYPEDEF(integrity);
/**@def STUNTAG_SOCKET(x)
*
......
......@@ -161,7 +161,7 @@ int main(int argc, char *argv[])
root,
stunc_callback,
STUNTAG_SERVER(argv[1]),
STUNTAG_INTEGRITY(msg_integrity),
STUNTAG_REQUIRE_INTEGRITY(msg_integrity),
TAG_NULL());
if (!sh) {
......
......@@ -226,7 +226,7 @@ int torture_test_init(su_root_t *root, char *server)
root,
torture_callback,
STUNTAG_SERVER(server),
STUNTAG_INTEGRITY(!bypass_msg_int),
STUNTAG_REQUIRE_INTEGRITY(!bypass_msg_int),
TAG_NULL());
TEST_1(se);
......
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