47 #define DEFAULT_MONITOR_REFRESH 30 48 #define DEFAULT_RETRIES 3 77 if (0 <=
args.stun_sock) {
78 close(
args.stun_sock);
87 struct sockaddr_in answer;
88 static const struct sockaddr_in no_addr = { 0, };
91 if (!
args.monitor_enabled) {
92 goto monitor_request_cleanup;
95 if (
args.stun_sock < 0) {
99 if (!
args.server_hostname) {
101 goto monitor_request_cleanup;
105 memset(&stun_addr, 0,
sizeof(stun_addr));
106 stun_addr.
ss.ss_family = AF_INET;
110 args.server_hostname);
111 goto monitor_request_cleanup;
116 args.stun_sock = socket(AF_INET, SOCK_DGRAM, 0);
117 if (
args.stun_sock < 0) {
119 goto monitor_request_cleanup;
125 goto monitor_request_cleanup;
136 if (!
args.stun_poll_failed_gripe) {
137 args.stun_poll_failed_gripe = 1;
139 res < 0 ?
"failed" :
"got no response");
143 args.stun_poll_failed_gripe = 0;
144 if (memcmp(&no_addr, &answer,
sizeof(no_addr))
145 && memcmp(&
args.external_addr, &answer,
sizeof(
args.external_addr))) {
147 int newport = ntohs(answer.sin_port);
151 ntohs(
args.external_addr.sin_port), newaddr, newport);
155 if (
args.external_addr_known) {
161 goto publish_failure;
168 goto publish_failure;
172 goto publish_failure;
186 args.external_addr_known = 1;
191 monitor_request_cleanup:
194 res =
args.refresh * 1000;
211 args.monitor_enabled = 0;
282 args.monitor_enabled = 0;
294 || 1 != sscanf(port_str,
"%30u", &port)) {
304 memset(&stun_addr, 0,
sizeof(stun_addr));
305 stun_addr.
ss.ss_family = AF_INET;
318 args.server_hostname = host_str;
319 args.stun_port = port;
322 args.monitor_enabled = 1;
347 args.stun_poll_failed_gripe = 0;
350 args.monitor_enabled = 0;
354 if (!strcasecmp(v->
name,
"stunaddr")) {
359 }
else if (!strcasecmp(v->
name,
"stunrefresh")) {
360 if ((sscanf(v->
value,
"%30u", &
args.refresh) != 1) || !
args.refresh) {
380 #define DATALN "%-25s %-5u %-7u %-8d %-7s %-16s %-d\n" 381 #define HEADER "%-25s %-5s %-7s %-8s %-7s %-16s %-s\n" 384 ast_cli(fd,
HEADER,
"Hostname",
"Port",
"Period",
"Retries",
"Status",
"ExternAddr",
"ExternPort");
386 if (
args.stun_poll_failed_gripe) {
388 }
else if (
args.external_addr_known) {
394 args.server_hostname,
400 ntohs(
args.external_addr.sin_port)
411 e->
command =
"stun show status";
413 "Usage: stun show status\n" 414 " List all known STUN servers and statuses.\n";
442 if (res < 0 || !
args.monitor_enabled) {
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
struct ast_variable * next
struct sockaddr_storage ss
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define DEFAULT_MONITOR_REFRESH
static int stun_monitor_request(const void *blarg)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
static int __reload(int startup)
static void _stun_show_status(int fd)
Execute stun show status command.
struct ast_json_payload * ast_json_payload_create(struct ast_json *json)
Create an ao2 object to pass json blobs as data payloads for stasis.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
#define ast_set_flag(p, flag)
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
descriptor for a cli entry.
static int setup_stunaddr(const char *value, int reload)
#define CONFIG_STATUS_FILEINVALID
struct stasis_message_type * ast_network_change_type(void)
A stasis_message_type for network changes.
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Structure for variables, used for configurations and for channel variables.
static struct ast_sched_context * sched
int ast_sched_add_variable(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
Adds a scheduled event with rescheduling support.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
#define ast_mutex_lock(a)
#define ast_strdup(str)
A wrapper for strdup()
void ast_cli(int fd, const char *fmt,...)
Socket address structure.
#define ast_strlen_zero(foo)
static char * handle_cli_stun_show_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Configuration File Parser.
struct sockaddr_in external_addr
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
Splits a string into its host and port components.
Asterisk JSON abstraction layer.
static const int STANDARD_STUN_PORT
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
int ast_stun_request(int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer)
Generic STUN request.
Access Control of various sorts.
Scheduler Routines (derived from cheops)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
static int load_config(int startup)
#define ast_strdupa(s)
duplicate a string in memory from the stack
static int stun_start_monitor(void)
static int answer(void *data)
#define CONFIG_STATUS_FILEUNCHANGED
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
static int load_module(void)
int ast_get_ip(struct ast_sockaddr *addr, const char *hostname)
Get the IP address given a hostname.
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes. ...
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
static const char stun_conf_file[]
static void stun_close_sock(void)
Module has failed to load, may be in an inconsistent state.
Structure used to handle boolean flags.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
unsigned int monitor_enabled
const char * server_hostname
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Standard Command Line Interface.
unsigned int stun_poll_failed_gripe
Abstract JSON element (object, array, string, int, ...).
#define ast_mutex_init(pmutex)
static int unload_module(void)
#define ast_mutex_destroy(a)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
int ast_connect(int sockfd, const struct ast_sockaddr *addr)
Wrapper around connect(2) that uses struct ast_sockaddr.
Structure for mutex and tracking information.
unsigned int external_addr_known
#define ast_mutex_unlock(a)
static void stun_stop_monitor(void)