Asterisk - The Open Source Telephony Project
21.4.1
|
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. | |
#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) | |
#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 | |
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 | |
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 | |
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. | |
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 | |
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 | |
static int | stun_send (int s, struct sockaddr_in *dst, struct stun_header *resp) |
wrapper to send an STUN message | |
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 |
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_stun_request(), stun_attr2str(), STUN_BINDREQ, STUN_MAPPED_ADDRESS, stun_msg2str(), and stun_send().
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, and ast_register_atexit().
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 append_attr_string(), ast_debug_stun, ast_remaining_ms(), ast_stun_handle_packet(), ast_tvnow(), STUN_BINDREQ, stun_get_mapped(), stun_req_id(), and stun_send().
Referenced by ast_rtp_stun_request(), ast_stun_handle_packet(), rtp_add_candidates_to_ice(), and stun_monitor_request().
|
static |