Loading...
Searching...
No Matches
stun.h
Go to the documentation of this file.
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005-2006 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef STUN_H
#define STUN_H
#include <sofia-sip/stun_common.h>
#ifndef SU_WAIT_H
#include <sofia-sip/su_wait.h>
#endif
#ifndef SU_TAG_H
#include <sofia-sip/su_tag.h>
#endif
#include <sofia-sip/su_localinfo.h>
SOFIA_BEGIN_DECLS
typedef struct stun_handle_s stun_handle_t;
typedef struct stun_request_s stun_request_t;
typedef struct stun_discovery_s stun_discovery_t;
typedef struct stun_dns_lookup_s stun_dns_lookup_t;
typedef struct stun_mini_s stun_mini_t;
#ifndef STUN_MAGIC_T
#define STUN_MAGIC_T struct stun_magic_t
#endif
typedef STUN_MAGIC_T stun_magic_t;
#ifndef STUN_DISCOVERY_MAGIC_T
#define STUN_DISCOVERY_MAGIC_T struct stun_discovery_magic_t
#endif
typedef STUN_DISCOVERY_MAGIC_T stun_discovery_magic_t;
SOFIAPUBVAR char const stun_version[];
typedef enum stun_action_s {
stun_action_no_action = 1,
stun_action_tls_query = 2,
stun_action_binding_request = 4,
stun_action_keepalive = 8,
stun_action_test_nattype = 16,
stun_action_test_lifetime = 32,
} stun_action_t;
typedef enum stun_nattype_e {
stun_nat_unknown = 0,
/* no NAT between client and STUN server */
stun_open_internet,
/* UDP communication blocked by FW */
stun_udp_blocked,
/* No NAT, but a FW element is performing address and port
* restricted filtering. */
stun_sym_udp_fw,
/* Endpoint independent filtering (endpoint independent mapping)
* RFC3489 full cone NAT. */
stun_nat_full_cone,
/* Address restricted filtering (endpoint independent mapping),
* RFC3489 restricted cone NAT. */
stun_nat_res_cone,
/* Address and port restricted filtering (endpoint
* independent mapping), RFC3489 port restricted cone */
stun_nat_port_res_cone,
/* Endpoint independent filtering, endpoint dependent mapping. */
stun_nat_ei_filt_ad_map,
/* Address dependent filtering, endpoint dependent mapping. */
stun_nat_ad_filt_ad_map,
/* Address and port dependent filtering, endpoint dependent mapping
* RFC3489 symmetric NAT). */
stun_nat_adp_filt_ad_map,
} stun_nattype_t;
typedef enum stun_state_e {
stun_no_assigned_event,
/* TLS events; see stun_obtain_shared_request() */
stun_tls_connecting,
stun_tls_ssl_connecting,
stun_tls_writing,
stun_tls_closing,
stun_tls_reading,
stun_tls_done,
/* STUN discovery events */
stun_discovery_done,
/* STUN errors */
/* Do not change the order! Errors need to be after stun_error */
stun_error,
stun_tls_connection_timeout,
stun_tls_connection_failed,
stun_tls_ssl_connect_failed,
stun_discovery_error,
stun_discovery_timeout,
} stun_state_t;
/* -------------------------------------------------------------------
* Calback function prototypes (signals emitted by the stack) */
/* Per discovery */
typedef void (*stun_discovery_f)(stun_discovery_magic_t *magic,
stun_handle_t *sh,
stun_discovery_t *sd,
stun_action_t action,
stun_state_t event);
typedef int (*stun_send_callback)(stun_magic_t *magic,
stun_handle_t *sh,
int socket,
void *data,
unsigned len,
int only_a_keepalive);
typedef void (*stun_dns_lookup_f)(stun_dns_lookup_t *self,
stun_magic_t *magic);
/* -------------------------------------------------------------------
* Functions for managing STUN handles. */
SOFIAPUBFUN stun_handle_t *stun_handle_init(su_root_t *root,
tag_type_t, tag_value_t, ...);
SOFIAPUBFUN void stun_handle_destroy(stun_handle_t *sh);
SOFIAPUBFUN su_root_t *stun_root(stun_handle_t *sh);
SOFIAPUBFUN int stun_is_requested(tag_type_t tag, tag_value_t value, ...);
SOFIAPUBFUN char const *stun_str_state(stun_state_t state);
SOFIAPUBFUN su_addrinfo_t const *stun_server_address(stun_handle_t *sh);
SOFIAPUBFUN
int stun_process_message(stun_handle_t *sh, su_socket_t s,
su_sockaddr_t *sa, socklen_t salen,
void *data, isize_t len);
SOFIAPUBFUN
int stun_process_request(su_socket_t s, stun_msg_t *req,
int sid, su_sockaddr_t *from_addr,
socklen_t from_len);
/* -------------------------------------------------------------------
* Functions for 'Binding Discovery' usage (RFC3489/3489bis) */
SOFIAPUBFUN
int stun_obtain_shared_secret(stun_handle_t *sh, stun_discovery_f,
stun_discovery_magic_t *magic,
tag_type_t tag, tag_value_t value, ...);
SOFIAPUBFUN
int stun_bind(stun_handle_t *sh,
stun_discovery_f, stun_discovery_magic_t *magic,
tag_type_t tag, tag_value_t value, ...);
SOFIAPUBFUN
int stun_discovery_get_address(stun_discovery_t *sd,
void *addr,
socklen_t *return_addrlen);
SOFIAPUBFUN su_socket_t stun_discovery_get_socket(stun_discovery_t *sd);
SOFIAPUBFUN int stun_discovery_release_socket(stun_discovery_t *sd);
SOFIAPUBFUN
int stun_test_nattype(stun_handle_t *sh,
stun_discovery_f, stun_discovery_magic_t *magic,
tag_type_t tag, tag_value_t value, ...);
SOFIAPUBFUN char const *stun_nattype_str(stun_discovery_t *sd);
SOFIAPUBFUN stun_nattype_t stun_nattype(stun_discovery_t *sd);
SOFIAPUBFUN
int stun_test_lifetime(stun_handle_t *sh,
stun_discovery_f, stun_discovery_magic_t *magic,
tag_type_t tag, tag_value_t value, ...);
SOFIAPUBFUN int stun_lifetime(stun_discovery_t *sd);
/* -------------------------------------------------------------------
* Functions for 'Connectivity Check' and 'NAT Keepalives' usages (RFC3489bis) */
SOFIAPUBFUN
int stun_set_uname_pwd(stun_handle_t *sh,
const char *uname,
isize_t len_uname,
const char *pwd,
isize_t len_pwd);
SOFIAPUBFUN int stun_msg_is_keepalive(uint16_t data);
SOFIAPUBFUN int stun_message_length(void *data, isize_t len, int end_of_message);
/* Create a keepalive dispatcher for bound SIP sockets */
SOFIAPUBFUN
int stun_keepalive(stun_handle_t *sh,
su_sockaddr_t *sa,
tag_type_t tag, tag_value_t value,
...);
SOFIAPUBFUN int stun_keepalive_destroy(stun_handle_t *sh, su_socket_t s);
/* -------------------------------------------------------------------
* Functions for 'Short-Term password' usage (RFC3489bis) */
/* (not implemented, see stun_request_shared_secret()) */
/* -------------------------------------------------------------------
* Functions for STUN server discovery using DNS (RFC3489/3489bis) */
SOFIAPUBFUN
stun_dns_lookup_t *stun_dns_lookup(stun_magic_t *magic,
su_root_t *root,
stun_dns_lookup_f func,
const char *domain);
SOFIAPUBFUN void stun_dns_lookup_destroy(stun_dns_lookup_t *self);
SOFIAPUBFUN int stun_dns_lookup_udp_addr(stun_dns_lookup_t *,
const char **target, uint16_t *port);
SOFIAPUBFUN int stun_dns_lookup_tcp_addr(stun_dns_lookup_t *self,
const char **target, uint16_t *port);
SOFIAPUBFUN int stun_dns_lookup_stp_addr(stun_dns_lookup_t *self,
const char **target, uint16_t *port);
/* -------------------------------------------------------------------
* Functions for minimal STUN server */
SOFIAPUBFUN stun_mini_t *stun_mini_create(void);
SOFIAPUBFUN void stun_mini_destroy(stun_mini_t *);
SOFIAPUBFUN int stun_mini_add_socket(stun_mini_t *server,
su_socket_t socket);
SOFIAPUBFUN int stun_mini_remove_socket(stun_mini_t *server,
su_socket_t socket);
SOFIAPUBFUN void stun_mini_request(stun_mini_t *server, su_socket_t socket,
void *msg, ssize_t msglen,
void *addr, socklen_t addrlen);
SOFIA_END_DECLS
#endif /* !defined(STUN_H) */
stun_magic_t
STUN_MAGIC_T stun_magic_t
STUN server context.
Definition stun.h:63
stun_message_length
int stun_message_length(void *data, isize_t len, int end_of_message)
Determines length of STUN message (0 (-1?) if not stun).
Definition stun.c:2831
stun_nattype_e
stun_nattype_e
NAT types.
Definition stun.h:97
stun_discovery_magic_t
STUN_DISCOVERY_MAGIC_T stun_discovery_magic_t
STUN discovery_ context.
Definition stun.h:69
stun_process_message
int stun_process_message(stun_handle_t *sh, su_socket_t s, su_sockaddr_t *sa, socklen_t salen, void *data, isize_t len)
Process incoming message.
Definition stun.c:2854
stun_version
char const stun_version[]
Name and version of STUN software.
Definition stun.c:324
stun_obtain_shared_secret
int stun_obtain_shared_secret(stun_handle_t *sh, stun_discovery_f, stun_discovery_magic_t *magic, tag_type_t tag, tag_value_t value,...)
Performs shared secret request/response processing.
Definition stun.c:529
stun_action_s
stun_action_s
STUN Action types.
Definition stun.h:78
stun_mini_destroy
void stun_mini_destroy(stun_mini_t *)
Destroy a stun miniserver.
Definition stun_mini.c:87
stun_test_lifetime
int stun_test_lifetime(stun_handle_t *sh, stun_discovery_f, stun_discovery_magic_t *magic, tag_type_t tag, tag_value_t value,...)
Initiates STUN discovery process to find out NAT binding life-time settings.
Definition stun.c:2672
stun_keepalive
int stun_keepalive(stun_handle_t *sh, su_sockaddr_t *sa, tag_type_t tag, tag_value_t value,...)
Creates a keepalive dispatcher for bound SIP sockets.
Definition stun.c:2910
stun_discovery_get_socket
su_socket_t stun_discovery_get_socket(stun_discovery_t *sd)
Returns socket attached to the discovery object.
Definition stun.c:3123
stun_msg_is_keepalive
int stun_msg_is_keepalive(uint16_t data)
Determines if the message is STUN message (-1 if not stun).
Definition stun.c:2813
stun_mini_create
stun_mini_t * stun_mini_create(void)
Create a stun miniserver.
Definition stun_mini.c:81
stun_dns_lookup_stp_addr
int stun_dns_lookup_stp_addr(stun_dns_lookup_t *self, const char **target, uint16_t *port)
Fetches the results of a completed STUN DNS-SRV lookup for "_stun._udp" service (3489bis,...
Definition stun_dns.c:242
stun_mini_add_socket
int stun_mini_add_socket(stun_mini_t *server, su_socket_t socket)
Add a socket to stun miniserver.
Definition stun_mini.c:101
stun_bind
int stun_bind(stun_handle_t *sh, stun_discovery_f, stun_discovery_magic_t *magic, tag_type_t tag, tag_value_t value,...)
Performs a STUN Binding Discovery (see RFC3489/3489bis) process.
Definition stun.c:1026
stun_dns_lookup_destroy
void stun_dns_lookup_destroy(stun_dns_lookup_t *self)
Destroys the 'self' object created by stun_dns_lookup_destroy().
Definition stun_dns.c:177
stun_keepalive_destroy
int stun_keepalive_destroy(stun_handle_t *sh, su_socket_t s)
Destroys the keepalive dispatcher without touching the socket.
Definition stun.c:3004
stun_discovery_get_address
int stun_discovery_get_address(stun_discovery_t *sd, void *addr, socklen_t *return_addrlen)
Returns the address of the public binding allocated by the NAT.
Definition stun.c:1089
stun_action_t
enum stun_action_s stun_action_t
STUN Action types.
stun_set_uname_pwd
int stun_set_uname_pwd(stun_handle_t *sh, const char *uname, isize_t len_uname, const char *pwd, isize_t len_pwd)
Sets values for USERNAME and PASSWORD stun fields for the handle.
Definition stun.c:2560
stun_state_t
enum stun_state_e stun_state_t
States of the STUN client->server query process.
stun_dns_lookup_f
void(* stun_dns_lookup_f)(stun_dns_lookup_t *self, stun_magic_t *magic)
Callback for delivering DNS lookup results.
Definition stun.h:189
stun_nattype
stun_nattype_t stun_nattype(stun_discovery_t *sd)
Returns the detected NAT type.
Definition stun.c:301
stun_test_nattype
int stun_test_nattype(stun_handle_t *sh, stun_discovery_f, stun_discovery_magic_t *magic, tag_type_t tag, tag_value_t value,...)
Initiates STUN discovery process to find out NAT characteristics.
Definition stun.c:1183
stun_nattype_str
char const * stun_nattype_str(stun_discovery_t *sd)
Returns the NAT type attached to STUN discovery handle.
Definition stun.c:274
stun_dns_lookup_udp_addr
int stun_dns_lookup_udp_addr(stun_dns_lookup_t *, const char **target, uint16_t *port)
Fetches the results of a completed STUN DNS-SRV lookup for "_stun._udp" service (RFC3489/3489bis).
Definition stun_dns.c:196
stun_send_callback
int(* stun_send_callback)(stun_magic_t *magic, stun_handle_t *sh, int socket, void *data, unsigned len, int only_a_keepalive)
Callback invoked by stun handle when it has a message to send.
Definition stun.h:181
stun_handle_destroy
void stun_handle_destroy(stun_handle_t *sh)
Destroy a STUN client.
Definition stun.c:710
stun_nattype_t
enum stun_nattype_e stun_nattype_t
NAT types.
stun_root
su_root_t * stun_root(stun_handle_t *sh)
Return su_root_t assigned to stun_handle_t.
Definition stun.c:381
stun_mini_remove_socket
int stun_mini_remove_socket(stun_mini_t *server, su_socket_t socket)
Remove socket from stun miniserver.
Definition stun_mini.c:133
stun_dns_lookup
stun_dns_lookup_t * stun_dns_lookup(stun_magic_t *magic, su_root_t *root, stun_dns_lookup_f func, const char *domain)
Performs a DNS-SRV check for STUN 'stun' (tcp) and 'stun' (udp) services for 'domain'.
Definition stun_dns.c:133
stun_handle_init
stun_handle_t * stun_handle_init(su_root_t *root, tag_type_t, tag_value_t,...)
Creates a STUN handle.
Definition stun.c:439
stun_state_e
stun_state_e
States of the STUN client->server query process.
Definition stun.h:142
stun_tls_ssl_connect_failed
@ stun_tls_ssl_connect_failed
TLS/SSL handshake failed.
Definition stun.h:163
stun_tls_ssl_connecting
@ stun_tls_ssl_connecting
Started the TLS/SSL handshake.
Definition stun.h:148
stun_tls_closing
@ stun_tls_closing
Closing TLS connection.
Definition stun.h:150
stun_tls_connecting
@ stun_tls_connecting
Connecting to TLS port.
Definition stun.h:147
stun_error
@ stun_error
Generic error in discovery process.
Definition stun.h:160
stun_tls_connection_failed
@ stun_tls_connection_failed
No response from TLS/SSL server.
Definition stun.h:162
stun_discovery_timeout
@ stun_discovery_timeout
No response to discovery request.
Definition stun.h:166
stun_discovery_error
@ stun_discovery_error
Error in discovery process.
Definition stun.h:165
stun_tls_writing
@ stun_tls_writing
Next step: send request.
Definition stun.h:149
stun_discovery_done
@ stun_discovery_done
Discovery process done.
Definition stun.h:155
stun_tls_connection_timeout
@ stun_tls_connection_timeout
No response to connect attempt.
Definition stun.h:161
stun_tls_reading
@ stun_tls_reading
Request send, waiting for response.
Definition stun.h:151
stun_tls_done
@ stun_tls_done
Shared-secret acquired.
Definition stun.h:152
stun_dns_lookup_tcp_addr
int stun_dns_lookup_tcp_addr(stun_dns_lookup_t *self, const char **target, uint16_t *port)
Fetches the results of a completed STUN DNS-SRV lookup for "_stun._tcp" service (RFC3489).
Definition stun_dns.c:219
stun_is_requested
int stun_is_requested(tag_type_t tag, tag_value_t value,...)
Check if a STUN handle should be created.
Definition stun.c:400
stun_common.h
su_socket_t
int su_socket_t
su_addrinfo_t
struct addrinfo su_addrinfo_t
SOFIAPUBFUN
#define SOFIAPUBFUN
SOFIAPUBVAR
#define SOFIAPUBVAR
su_localinfo.h
su_tag.h
tag_value_t
intptr_t tag_value_t
tag_type_t
struct tag_type_s const * tag_type_t
uint16_t
SU_U16_T uint16_t
su_wait.h
su_root_t
struct su_root_t su_root_t

Sofia-SIP 1.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.