Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
STUN Support. More...
#include "asterisk.h"
#include "asterisk/logger.h"
#include "asterisk/logger_category.h"
#include "asterisk/_private.h"
#include "asterisk/stun.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/channel.h"
Go to the source code of this file.
Data Structures | |
struct | stun_addr |
struct | stun_attr |
struct | stun_header |
struct | stun_state |
here we store credentials extracted from a message More... | |
struct | stun_trans_id |
STUN support code. More... | |
Macros | |
#define | STUN_BINDERR 0x0111 |
#define | STUN_BINDREQ 0x0001 |
STUN message types 'BIND' refers to transactions used to determine the externally visible addresses. 'SEC' refers to transactions used to establish a session key for subsequent requests. 'SEC' functionality is not supported here. More... | |
#define | STUN_BINDRESP 0x0101 |
#define | STUN_CHANGE_REQUEST 0x0003 |
#define | STUN_CHANGED_ADDRESS 0x0005 |
#define | STUN_ERROR_CODE 0x0009 |
#define | STUN_MAPPED_ADDRESS 0x0001 |
Basic attribute types in stun messages. Messages can also contain custom attributes (codes above 0x7fff) More... | |
#define | STUN_MAX_RETRIES 3 |
#define | STUN_MESSAGE_INTEGRITY 0x0008 |
#define | STUN_PASSWORD 0x0007 |
#define | STUN_REFLECTED_FROM 0x000b |
#define | STUN_RESPONSE_ADDRESS 0x0002 |
#define | STUN_SECERR 0x0112 |
#define | STUN_SECREQ 0x0002 |
#define | STUN_SECRESP 0x0102 |
#define | STUN_SOURCE_ADDRESS 0x0004 |
#define | STUN_UNKNOWN_ATTRIBUTES 0x000a |
#define | STUN_USERNAME 0x0006 |
Functions | |
static void | append_attr_address (struct stun_attr **attr, int attrval, struct sockaddr_in *sin, int *len, int *left) |
append an address to an STUN message More... | |
static void | append_attr_string (struct stun_attr **attr, int attrval, const char *s, int *len, int *left) |
append a string to an STUN message More... | |
uintmax_t | ast_debug_category_stun_id (void) |
uintmax_t | ast_debug_category_stun_packet_id (void) |
int | ast_stun_handle_packet (int s, struct sockaddr_in *src, unsigned char *data, size_t len, stun_cb_f *stun_cb, void *arg) |
handle an incoming STUN message. More... | |
void | ast_stun_init (void) |
Initialize the STUN system in Asterisk. More... | |
int | ast_stun_request (int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer) |
Generic STUN request. More... | |
static char * | handle_cli_stun_set_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static void | handle_stun_timeout (int retry, struct sockaddr_in *dst) |
static const char * | stun_attr2str (int msg) |
helper function to print attribute names More... | |
static int | stun_get_mapped (struct stun_attr *attr, void *arg) |
Extract the STUN_MAPPED_ADDRESS from the stun response. This is used as a callback for stun_handle_response when called from ast_stun_request. More... | |
static int | stun_id_cmp (stun_trans_id *left, stun_trans_id *right) |
static const char * | stun_msg2str (int msg) |
helper function to print message names More... | |
static int | stun_process_attr (struct stun_state *state, struct stun_attr *attr) |
static void | stun_req_id (struct stun_header *req) |
helper function to generate a random request id More... | |
static int | stun_send (int s, struct sockaddr_in *dst, struct stun_header *resp) |
wrapper to send an STUN message More... | |
static void | stun_shutdown (void) |
Variables | |
static struct ast_cli_entry | cli_stun [] |
static uintmax_t | debug_category_stun_id |
static uintmax_t | debug_category_stun_packet_id |
#define STUN_BINDREQ 0x0001 |
#define STUN_MAPPED_ADDRESS 0x0001 |
|
static |
append an address to an STUN message
Definition at line 222 of file stun.c.
References stun_addr::addr, and len().
Referenced by ast_stun_handle_packet().
|
static |
append a string to an STUN message
Definition at line 205 of file stun.c.
References len().
Referenced by ast_stun_handle_packet(), and ast_stun_request().
uintmax_t ast_debug_category_stun_id | ( | void | ) |
uintmax_t ast_debug_category_stun_packet_id | ( | void | ) |
int ast_stun_handle_packet | ( | int | s, |
struct sockaddr_in * | src, | ||
unsigned char * | data, | ||
size_t | len, | ||
stun_cb_f * | stun_cb, | ||
void * | arg | ||
) |
handle an incoming STUN message.
s | Socket to send any response to. |
src | Address where packet came from. |
data | STUN packet buffer to process. |
len | Length of packet |
stun_cb | If not NULL, callback for each STUN attribute. |
arg | Arg to pass to callback. |
Do some basic sanity checks on packet size and content, try to extract a bit of information, and possibly reply. At the moment this only processes BIND requests, and returns the externally visible address of the request. If a callback is specified, invoke it with the attribute.
AST_STUN_ACCEPT | if responed to a STUN request |
AST_STUN_IGNORE | |
-1 | on error |
Definition at line 293 of file stun.c.
References append_attr_address(), append_attr_string(), ast_debug_stun, ast_debug_stun_packet_is_allowed, AST_STUN_ACCEPT, AST_STUN_IGNORE, ast_stun_request(), ast_verbose(), stun_attr::attr, stun_header::id, stun_header::ies, len(), stun_header::msglen, stun_header::msgtype, NULL, stun_attr2str(), STUN_BINDREQ, STUN_BINDRESP, STUN_MAPPED_ADDRESS, stun_msg2str(), stun_process_attr(), stun_send(), STUN_USERNAME, and stun_state::username.
Referenced by ast_rtcp_read(), ast_rtp_read(), and ast_stun_request().
void ast_stun_init | ( | void | ) |
Initialize the STUN system in Asterisk.
Provided by stun.c
Definition at line 576 of file stun.c.
References ast_cli_register_multiple, ast_debug_category_register(), AST_LOG_CATEGORY_STUN, AST_LOG_CATEGORY_STUN_PACKET, ast_register_atexit(), cli_stun, debug_category_stun_id, debug_category_stun_packet_id, and stun_shutdown().
Referenced by asterisk_daemon().
int ast_stun_request | ( | int | s, |
struct sockaddr_in * | dst, | ||
const char * | username, | ||
struct sockaddr_in * | answer | ||
) |
Generic STUN request.
s | The socket used to send the request. |
dst | If non null, the address of the STUN server. Only needed if the socket is not bound or connected. |
username | If non null, add the username in the request. |
answer | If non null, the function waits for a response and puts here the externally visible address. |
Send a generic STUN request to the server specified, possibly waiting for a reply and filling the answer parameter with the externally visible address. Note that in this case the request will be blocking.
0 | on success. |
<0 | on error. |
>0 | on timeout. |
Definition at line 415 of file stun.c.
References answer(), append_attr_string(), ast_debug_stun, ast_poll, ast_remaining_ms(), ast_stun_handle_packet(), ast_tvnow(), stun_attr::attr, errno, handle_stun_timeout(), stun_header::id, stun_header::ies, if(), stun_header::msglen, stun_header::msgtype, STUN_BINDERR, STUN_BINDREQ, STUN_BINDRESP, stun_get_mapped(), stun_id_cmp(), STUN_MAX_RETRIES, stun_req_id(), stun_send(), and STUN_USERNAME.
Referenced by ast_rtp_stun_request(), ast_stun_handle_packet(), and stun_monitor_request().
|
static |
Definition at line 521 of file stun.c.
References a, ast_cli_entry::args, ast_cli(), ast_debug_category_set_sublevel(), ast_debug_stun_packet_is_allowed, AST_LOG_CATEGORY_DISABLED, AST_LOG_CATEGORY_ENABLED, AST_LOG_CATEGORY_STUN_PACKET, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 240 of file stun.c.
References ast_asprintf, ast_free, ast_inet_ntoa(), ast_log, LOG_NOTICE, LOG_WARNING, and STUN_MAX_RETRIES.
Referenced by ast_stun_request().
|
static |
helper function to print attribute names
Definition at line 146 of file stun.c.
References STUN_CHANGE_REQUEST, STUN_CHANGED_ADDRESS, STUN_ERROR_CODE, STUN_MAPPED_ADDRESS, STUN_MESSAGE_INTEGRITY, STUN_PASSWORD, STUN_REFLECTED_FROM, STUN_RESPONSE_ADDRESS, STUN_SOURCE_ADDRESS, STUN_UNKNOWN_ATTRIBUTES, and STUN_USERNAME.
Referenced by ast_stun_handle_packet(), and stun_process_attr().
|
static |
Extract the STUN_MAPPED_ADDRESS from the stun response. This is used as a callback for stun_handle_response when called from ast_stun_request.
Definition at line 403 of file stun.c.
References stun_addr::addr, stun_attr::attr, stun_attr::len, stun_addr::port, and STUN_MAPPED_ADDRESS.
Referenced by ast_stun_request().
|
static |
Definition at line 280 of file stun.c.
Referenced by ast_stun_request().
|
static |
helper function to print message names
Definition at line 126 of file stun.c.
References STUN_BINDERR, STUN_BINDREQ, STUN_BINDRESP, STUN_SECERR, STUN_SECREQ, and STUN_SECRESP.
Referenced by ast_stun_handle_packet().
|
static |
Definition at line 181 of file stun.c.
References ast_debug_stun_packet_is_allowed, ast_verbose(), stun_attr::attr, stun_attr::len, stun_attr2str(), STUN_PASSWORD, STUN_USERNAME, and stun_attr::value.
Referenced by ast_stun_handle_packet().
|
static |
helper function to generate a random request id
Definition at line 286 of file stun.c.
References ast_random(), stun_trans_id::id, and stun_header::id.
Referenced by ast_stun_request().
|
static |
wrapper to send an STUN message
Definition at line 264 of file stun.c.
References stun_header::msglen.
Referenced by ast_stun_handle_packet(), and ast_stun_request().
|
static |
Definition at line 567 of file stun.c.
References ast_cli_unregister_multiple(), ast_debug_category_unregister(), AST_LOG_CATEGORY_STUN, AST_LOG_CATEGORY_STUN_PACKET, and cli_stun.
Referenced by ast_stun_init().
|
static |
Definition at line 549 of file stun.c.
Referenced by ast_stun_init(), and stun_shutdown().
|
static |
Definition at line 553 of file stun.c.
Referenced by ast_debug_category_stun_id(), and ast_stun_init().
|
static |
Definition at line 560 of file stun.c.
Referenced by ast_debug_category_stun_packet_id(), and ast_stun_init().