Asterisk - The Open Source Telephony Project GIT-master-b023714
Loading...
Searching...
No Matches
Macros | Functions | Variables
res_stun_monitor.c File Reference

STUN Network Monitor. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/sched.h"
#include "asterisk/config.h"
#include "asterisk/stun.h"
#include "asterisk/netsock2.h"
#include "asterisk/lock.h"
#include "asterisk/acl.h"
#include "asterisk/cli.h"
#include "asterisk/json.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_system.h"
#include "asterisk/astobj2.h"
#include <fcntl.h>
Include dependency graph for res_stun_monitor.c:

Go to the source code of this file.

Macros

#define DATALN   "%-25s %-5u %-7u %-8d %-7s %-16s %-d\n"
 
#define DEFAULT_MONITOR_REFRESH   30
 
#define DEFAULT_RETRIES   3
 
#define HEADER   "%-25s %-5s %-7s %-8s %-7s %-16s %-s\n"
 

Functions

static void __reg_module (void)
 
static int __reload (int startup)
 
static void __unreg_module (void)
 
static void _stun_show_status (int fd)
 Execute stun show status command.
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static char * handle_cli_stun_show_status (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int load_config (int startup)
 
static int load_module (void)
 
static int reload (void)
 
static int setup_stunaddr (const char *value, int reload)
 
static void stun_close_sock (void)
 
static int stun_monitor_request (const void *blarg)
 called by scheduler to send STUN request
 
static int stun_start_monitor (void)
 
static void stun_stop_monitor (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "STUN Network Monitor" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CHANNEL_DEPEND }
 
struct { 
 
   struct sockaddr_in   external_addr 
 
   unsigned int   external_addr_known:1 
 
   ast_mutex_t   lock 
 
   unsigned int   monitor_enabled:1 
 
   unsigned int   refresh 
 
   const char *   server_hostname 
 
   unsigned int   stun_poll_failed_gripe:1 
 
   unsigned int   stun_port 
 
   int   stun_sock 
 
args 
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_stun []
 
static struct ast_sched_contextsched
 
static const char stun_conf_file [] = "res_stun_monitor.conf"
 

Detailed Description

STUN Network Monitor.

Author
David Vossel dvoss.nosp@m.el@d.nosp@m.igium.nosp@m..com

Definition in file res_stun_monitor.c.

Macro Definition Documentation

◆ DATALN

#define DATALN   "%-25s %-5u %-7u %-8d %-7s %-16s %-d\n"

◆ DEFAULT_MONITOR_REFRESH

#define DEFAULT_MONITOR_REFRESH   30

Default refresh period in seconds

Definition at line 47 of file res_stun_monitor.c.

◆ DEFAULT_RETRIES

#define DEFAULT_RETRIES   3

retries shown in stun show status matching static retries in stun.c

Definition at line 49 of file res_stun_monitor.c.

◆ HEADER

#define HEADER   "%-25s %-5s %-7s %-8s %-7s %-16s %-s\n"

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 483 of file res_stun_monitor.c.

◆ __reload()

static int __reload ( int  startup)
static

Definition at line 429 of file res_stun_monitor.c.

430{
431 int res;
432
433 ast_mutex_lock(&args.lock);
434 if (!(res = load_config(startup)) && args.monitor_enabled) {
435 res = stun_start_monitor();
436 }
437 ast_mutex_unlock(&args.lock);
438
439 if (res < 0 || !args.monitor_enabled) {
441 }
442
443 return res;
444}
static int load_config(void)
#define ast_mutex_unlock(a)
Definition lock.h:197
#define ast_mutex_lock(a)
Definition lock.h:196
static void stun_stop_monitor(void)
static int stun_start_monitor(void)
static struct @519 args

References args, ast_mutex_lock, ast_mutex_unlock, load_config(), stun_start_monitor(), and stun_stop_monitor().

Referenced by load_module(), and reload().

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 483 of file res_stun_monitor.c.

◆ _stun_show_status()

static void _stun_show_status ( int  fd)
static

Execute stun show status command.

we only have one stun server, but start to play well with more

Definition at line 373 of file res_stun_monitor.c.

374{
375 const char *status;
376
377#define DATALN "%-25s %-5u %-7u %-8d %-7s %-16s %-d\n"
378#define HEADER "%-25s %-5s %-7s %-8s %-7s %-16s %-s\n"
379
380 /*! we only have one stun server, but start to play well with more */
381 ast_cli(fd, HEADER, "Hostname", "Port", "Period", "Retries", "Status", "ExternAddr", "ExternPort");
382
383 if (args.stun_poll_failed_gripe) {
384 status = "FAIL";
385 } else if (args.external_addr_known) {
386 status = "OK";
387 } else {
388 status = "INIT";
389 }
390 ast_cli( fd, DATALN,
391 args.server_hostname,
392 args.stun_port,
393 args.refresh,
395 status,
396 ast_inet_ntoa(args.external_addr.sin_addr),
397 ntohs(args.external_addr.sin_port)
398 );
399
400#undef HEADER
401#undef DATALN
402}
jack_status_t status
Definition app_jack.c:149
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition utils.c:964
#define DEFAULT_RETRIES
#define HEADER
#define DATALN

References args, ast_cli(), ast_inet_ntoa(), DATALN, DEFAULT_RETRIES, HEADER, and status.

Referenced by handle_cli_stun_show_status().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 483 of file res_stun_monitor.c.

◆ handle_cli_stun_show_status()

static char * handle_cli_stun_show_status ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 404 of file res_stun_monitor.c.

405{
406 switch (cmd) {
407 case CLI_INIT:
408 e->command = "stun show status";
409 e->usage =
410 "Usage: stun show status\n"
411 " List all known STUN servers and statuses.\n";
412 return NULL;
413 case CLI_GENERATE:
414 return NULL;
415 }
416
417 if (a->argc != 3) {
418 return CLI_SHOWUSAGE;
419 }
420
421 _stun_show_status(a->fd);
422 return CLI_SUCCESS;
423}
#define CLI_SHOWUSAGE
Definition cli.h:45
#define CLI_SUCCESS
Definition cli.h:44
@ CLI_INIT
Definition cli.h:152
@ CLI_GENERATE
Definition cli.h:153
static void _stun_show_status(int fd)
Execute stun show status command.
#define NULL
Definition resample.c:96
char * command
Definition cli.h:186
const char * usage
Definition cli.h:177
static struct test_val a

References _stun_show_status(), a, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, and ast_cli_entry::usage.

◆ load_config()

static int load_config ( int  startup)
static

Definition at line 323 of file res_stun_monitor.c.

324{
325 struct ast_flags config_flags = { 0, };
326 struct ast_config *cfg;
327 struct ast_variable *v;
328
329 if (!startup) {
331 }
332
333 cfg = ast_config_load2(stun_conf_file, "res_stun_monitor", config_flags);
334 if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
335 ast_log(LOG_WARNING, "Unable to load config %s\n", stun_conf_file);
336 return -1;
337 }
338 if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
339 return 0;
340 }
341
342 /* clean up any previous open socket */
344 args.stun_poll_failed_gripe = 0;
345
346 /* set defaults */
347 args.monitor_enabled = 0;
349
350 for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
351 if (!strcasecmp(v->name, "stunaddr")) {
352 if (setup_stunaddr(v->value, !startup)) {
353 ast_log(LOG_WARNING, "Invalid STUN server address: %s at line %d\n",
354 v->value, v->lineno);
355 }
356 } else if (!strcasecmp(v->name, "stunrefresh")) {
357 if ((sscanf(v->value, "%30u", &args.refresh) != 1) || !args.refresh) {
358 ast_log(LOG_WARNING, "Invalid stunrefresh value '%s', must be an integer > 0 at line %d\n", v->value, v->lineno);
360 }
361 } else {
362 ast_log(LOG_WARNING, "Invalid config option %s at line %d\n",
363 v->value, v->lineno);
364 }
365 }
366
368
369 return 0;
370}
#define ast_log
Definition astobj2.c:42
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition extconf.c:1287
@ CONFIG_FLAG_FILEUNCHANGED
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition extconf.c:1213
#define LOG_WARNING
#define DEFAULT_MONITOR_REFRESH
static void stun_close_sock(void)
static int setup_stunaddr(const char *value, int reload)
static const char stun_conf_file[]
Structure used to handle boolean flags.
Definition utils.h:217
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
#define ast_set_flag(p, flag)
Definition utils.h:70

References args, ast_config_destroy(), ast_config_load2(), ast_log, ast_set_flag, ast_variable_browse(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, DEFAULT_MONITOR_REFRESH, ast_variable::lineno, LOG_WARNING, ast_variable::name, ast_variable::next, setup_stunaddr(), stun_close_sock(), stun_conf_file, and ast_variable::value.

◆ load_module()

static int load_module ( void  )
static

Register CLI commands

Definition at line 462 of file res_stun_monitor.c.

463{
464 ast_mutex_init(&args.lock);
465 args.stun_sock = -1;
466 if (__reload(1)) {
467 ast_mutex_destroy(&args.lock);
469 }
470
471 /*! Register CLI commands */
472 ast_cli_register_multiple(cli_stun, sizeof(cli_stun) / sizeof(struct ast_cli_entry));
473
475}
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
#define ast_mutex_init(pmutex)
Definition lock.h:193
#define ast_mutex_destroy(a)
Definition lock.h:195
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
static int __reload(int startup)
static struct ast_cli_entry cli_stun[]
descriptor for a cli entry.
Definition cli.h:171

References __reload(), args, ast_cli_register_multiple, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_mutex_destroy, ast_mutex_init, and cli_stun.

◆ reload()

static int reload ( void  )
static

Definition at line 446 of file res_stun_monitor.c.

447{
448 return __reload(0);
449}

References __reload().

Referenced by setup_stunaddr().

◆ setup_stunaddr()

static int setup_stunaddr ( const char *  value,
int  reload 
)
static

Definition at line 269 of file res_stun_monitor.c.

270{
271 char *val;
272 char *host_str;
273 char *port_str;
274 unsigned int port;
275 struct ast_sockaddr stun_addr;
276
277 if (ast_strlen_zero(value)) {
278 /* Setting to an empty value disables STUN monitoring. */
279 args.monitor_enabled = 0;
280 return 0;
281 }
282
284 if (!ast_sockaddr_split_hostport(val, &host_str, &port_str, 0)
285 || ast_strlen_zero(host_str)) {
286 return -1;
287 }
288
289 /* Determine STUN port */
290 if (ast_strlen_zero(port_str)
291 || 1 != sscanf(port_str, "%30u", &port)) {
292 port = STANDARD_STUN_PORT;
293 }
294
295 host_str = ast_strdup(host_str);
296 if (!host_str) {
297 return -1;
298 }
299
300 /* Lookup STUN address. */
301 memset(&stun_addr, 0, sizeof(stun_addr));
302 stun_addr.ss.ss_family = AF_INET;
303 if (ast_get_ip(&stun_addr, host_str)) {
304 ast_log(LOG_WARNING, "Unable to lookup STUN server '%s'\n", host_str);
305
306 /* Only treat this as fatal if we are reloading */
307 if (reload) {
308 ast_free(host_str);
309 return -1;
310 }
311 }
312
313 /* Save STUN server information. */
314 ast_free((char *) args.server_hostname);
315 args.server_hostname = host_str;
316 args.stun_port = port;
317
318 /* Enable STUN monitor */
319 args.monitor_enabled = 1;
320 return 0;
321}
int ast_get_ip(struct ast_sockaddr *addr, const char *hostname)
Get the IP address given a hostname.
Definition acl.c:1016
#define ast_free(a)
Definition astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
Splits a string into its host and port components.
Definition netsock2.c:164
static int reload(void)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
Socket address structure.
Definition netsock2.h:97
static const int STANDARD_STUN_PORT
Definition stun.h:61
int value
Definition syslog.c:37

References args, ast_free, ast_get_ip(), ast_log, ast_sockaddr_split_hostport(), ast_strdup, ast_strdupa, ast_strlen_zero(), LOG_WARNING, reload(), STANDARD_STUN_PORT, and value.

Referenced by load_config().

◆ stun_close_sock()

static void stun_close_sock ( void  )
static

Definition at line 75 of file res_stun_monitor.c.

76{
77 if (0 <= args.stun_sock) {
78 close(args.stun_sock);
79 args.stun_sock = -1;
80 }
81}

References args.

Referenced by load_config(), stun_monitor_request(), stun_start_monitor(), and stun_stop_monitor().

◆ stun_monitor_request()

static int stun_monitor_request ( const void *  blarg)
static

called by scheduler to send STUN request

Definition at line 84 of file res_stun_monitor.c.

85{
86 int res;
87 struct sockaddr_in answer;
88 static const struct sockaddr_in no_addr = { 0, };
89
90 ast_mutex_lock(&args.lock);
91 if (!args.monitor_enabled) {
92 goto monitor_request_cleanup;
93 }
94
95 if (args.stun_sock < 0) {
97
98 /* STUN socket not open. Refresh the server DNS address resolution. */
99 if (!args.server_hostname) {
100 /* No STUN hostname? */
101 goto monitor_request_cleanup;
102 }
103
104 /* Lookup STUN address. */
105 memset(&stun_addr, 0, sizeof(stun_addr));
106 stun_addr.ss.ss_family = AF_INET;
107 if (ast_get_ip(&stun_addr, args.server_hostname)) {
108 /* Lookup failed. */
109 ast_log(LOG_WARNING, "Unable to lookup STUN server '%s'\n",
110 args.server_hostname);
111 goto monitor_request_cleanup;
112 }
114
115 /* open socket binding */
116 args.stun_sock = socket(AF_INET, SOCK_DGRAM, 0);
117 if (args.stun_sock < 0) {
118 ast_log(LOG_WARNING, "Unable to create STUN socket: %s\n", strerror(errno));
119 goto monitor_request_cleanup;
120 }
121 if (ast_connect(args.stun_sock, &stun_addr)) {
122 ast_log(LOG_WARNING, "STUN Failed to connect to %s: %s\n",
125 goto monitor_request_cleanup;
126 }
127 }
128
129 res = ast_stun_request(args.stun_sock, NULL, NULL, &answer);
130 if (res) {
131 /*
132 * STUN request timed out or errored.
133 *
134 * Refresh the server DNS address resolution next time around.
135 */
136 if (!args.stun_poll_failed_gripe) {
137 args.stun_poll_failed_gripe = 1;
138 ast_log(LOG_WARNING, "STUN poll %s. Re-evaluating STUN server address.\n",
139 res < 0 ? "failed" : "got no response");
140 }
142 } else {
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))) {
146 const char *newaddr = ast_strdupa(ast_inet_ntoa(answer.sin_addr));
147 int newport = ntohs(answer.sin_port);
148
149 ast_log(LOG_NOTICE, "Old external address/port %s:%d now seen as %s:%d.\n",
150 ast_inet_ntoa(args.external_addr.sin_addr),
151 ntohs(args.external_addr.sin_port), newaddr, newport);
152
153 args.external_addr = answer;
154
155 if (args.external_addr_known) {
156 RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
157 RAII_VAR(struct ast_json_payload *, json_payload, NULL, ao2_cleanup);
158 RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
159
161 goto publish_failure;
162 }
163
164 /* This json_object doesn't actually contain anything yet. We have to reference something
165 * for stasis, and this is useful for if we want to ever add data for any reason. */
166 json_object = ast_json_object_create();
167 if (!json_object) {
168 goto publish_failure;
169 }
170
171 if (!(json_payload = ast_json_payload_create(json_object))) {
172 goto publish_failure;
173 }
174
175 msg = stasis_message_create(ast_network_change_type(), json_payload);
176
177publish_failure:
178 if (msg) {
180 } else {
181 ast_log(LOG_ERROR, "Failed to issue network change message.\n");
182 }
183 } else {
184 /* this was the first external address we found, do not alert listeners
185 * until this address changes to something else. */
186 args.external_addr_known = 1;
187 }
188 }
189 }
190
191monitor_request_cleanup:
192 /* always refresh this scheduler item. It will be removed elsewhere when
193 * it is supposed to go away */
194 res = args.refresh * 1000;
195 ast_mutex_unlock(&args.lock);
196
197 return res;
198}
#define ao2_cleanup(obj)
Definition astobj2.h:1934
static int answer(void *data)
Definition chan_pjsip.c:687
#define LOG_ERROR
#define LOG_NOTICE
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition json.c:399
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.
Definition json.c:756
int errno
int ast_connect(int sockfd, const struct ast_sockaddr *addr)
Wrapper around connect(2) that uses struct ast_sockaddr.
Definition netsock2.c:595
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition netsock2.h:256
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition netsock2.h:532
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition stasis.c:1578
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes.
struct stasis_message_type * ast_network_change_type(void)
A stasis_message_type for network changes.
Abstract JSON element (object, array, string, int, ...).
int ast_stun_request(int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer)
Generic STUN request.
Definition stun.c:415
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:978

References answer(), ao2_cleanup, args, ast_connect(), ast_get_ip(), ast_inet_ntoa(), ast_json_object_create(), ast_json_payload_create(), ast_json_unref(), ast_log, ast_mutex_lock, ast_mutex_unlock, ast_network_change_type(), ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_strdupa, ast_stun_request(), ast_system_topic(), errno, LOG_ERROR, LOG_NOTICE, LOG_WARNING, NULL, RAII_VAR, stasis_message_create(), stasis_publish(), and stun_close_sock().

Referenced by stun_start_monitor().

◆ stun_start_monitor()

static int stun_start_monitor ( void  )
static

Definition at line 228 of file res_stun_monitor.c.

229{
230 /* if scheduler thread is not started, make sure to start it now */
231 if (sched) {
232 return 0; /* already started */
233 }
234
235 if (!(sched = ast_sched_context_create())) {
236 ast_log(LOG_ERROR, "Failed to create stun monitor scheduler context\n");
237 return -1;
238 }
239
242 sched = NULL;
244 return -1;
245 }
246
247 if (ast_sched_add_variable(sched, (args.refresh * 1000), stun_monitor_request, NULL, 1) < 0) {
248 ast_log(LOG_ERROR, "Unable to schedule STUN network monitor \n");
250 sched = NULL;
251 return -1;
252 }
253
254 ast_log(LOG_NOTICE, "STUN monitor started\n");
255
256 return 0;
257}
static int stun_monitor_request(const void *blarg)
called by scheduler to send STUN request
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
Definition sched.c:271
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
Definition sched.c:197
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.
Definition sched.c:526
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
Definition sched.c:238
Definition sched.c:76

References args, ast_log, ast_sched_add_variable(), ast_sched_context_create(), ast_sched_context_destroy(), ast_sched_start_thread(), LOG_ERROR, LOG_NOTICE, NULL, stun_close_sock(), and stun_monitor_request().

Referenced by __reload().

◆ stun_stop_monitor()

static void stun_stop_monitor ( void  )
static

Definition at line 206 of file res_stun_monitor.c.

207{
208 ast_mutex_lock(&args.lock);
209 args.monitor_enabled = 0;
210 ast_free((char *) args.server_hostname);
211 args.server_hostname = NULL;
213 ast_mutex_unlock(&args.lock);
214
215 if (sched) {
217 sched = NULL;
218 ast_log(LOG_NOTICE, "STUN monitor stopped\n");
219 }
220}

References args, ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_sched_context_destroy(), LOG_NOTICE, NULL, and stun_close_sock().

Referenced by __reload(), and unload_module().

◆ unload_module()

static int unload_module ( void  )
static

Unregister CLI commands

Definition at line 451 of file res_stun_monitor.c.

452{
454 ast_mutex_destroy(&args.lock);
455
456 /*! Unregister CLI commands */
458
459 return 0;
460}
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408
#define ARRAY_LEN(a)
Definition utils.h:703

References args, ARRAY_LEN, ast_cli_unregister_multiple(), ast_mutex_destroy, cli_stun, and stun_stop_monitor().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "STUN Network Monitor" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CHANNEL_DEPEND }
static

Definition at line 483 of file res_stun_monitor.c.

◆ [struct]

struct { ... } args
Examples
app_skel.c.

Referenced by __ast_pbx_run(), __ast_sorcery_object_field_register(), __reload(), _stun_show_status(), acf_abs_exec(), acf_channel_read(), acf_curl_exec(), acf_curl_helper(), acf_curl_write(), acf_jabberreceive_read(), acf_jabberstatus_read(), acf_max_exec(), acf_meetme_info(), acf_min_exec(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_strftime(), acf_strptime(), acf_transaction_read(), acf_transaction_write(), acf_version_exec(), acf_vm_info(), acf_vmcount_exec(), action_dialplan_exec(), add_action_to_menu_entry(), add_format_information_cb(), admin_exec(), adsi_process(), aelsub_exec(), aes_helper(), agent_function_read(), agent_login_exec(), agent_request_exec(), agi_exec_full(), answer_exec_enable(), answer_exec_run(), app_control_dial(), app_exec(), app_exec(), app_exec(), app_notify(), applicationmap_handler(), aqm_exec(), ast_app_expand_sub_args(), ast_app_parse_options(), ast_app_parse_options64(), ast_ari_applications_filter(), ast_ari_applications_filter_cb(), ast_ari_applications_get(), ast_ari_applications_get_cb(), ast_ari_applications_list_cb(), ast_ari_applications_subscribe(), ast_ari_applications_subscribe_cb(), ast_ari_applications_subscribe_parse_body(), ast_ari_applications_unsubscribe(), ast_ari_applications_unsubscribe_cb(), ast_ari_applications_unsubscribe_parse_body(), ast_ari_asterisk_add_log(), ast_ari_asterisk_add_log_cb(), ast_ari_asterisk_add_log_parse_body(), ast_ari_asterisk_delete_log(), ast_ari_asterisk_delete_log_cb(), ast_ari_asterisk_delete_object(), ast_ari_asterisk_delete_object_cb(), ast_ari_asterisk_get_global_var(), ast_ari_asterisk_get_global_var_cb(), ast_ari_asterisk_get_global_var_parse_body(), ast_ari_asterisk_get_info(), ast_ari_asterisk_get_info_cb(), ast_ari_asterisk_get_info_parse_body(), ast_ari_asterisk_get_module(), ast_ari_asterisk_get_module_cb(), ast_ari_asterisk_get_object(), ast_ari_asterisk_get_object_cb(), ast_ari_asterisk_list_log_channels_cb(), ast_ari_asterisk_list_modules_cb(), ast_ari_asterisk_load_module(), ast_ari_asterisk_load_module_cb(), ast_ari_asterisk_ping_cb(), ast_ari_asterisk_reload_module(), ast_ari_asterisk_reload_module_cb(), ast_ari_asterisk_rotate_log(), ast_ari_asterisk_rotate_log_cb(), ast_ari_asterisk_set_global_var(), ast_ari_asterisk_set_global_var_cb(), ast_ari_asterisk_set_global_var_parse_body(), ast_ari_asterisk_unload_module(), ast_ari_asterisk_unload_module_cb(), ast_ari_asterisk_update_object(), ast_ari_asterisk_update_object_cb(), ast_ari_bridges_add_channel(), ast_ari_bridges_add_channel_cb(), ast_ari_bridges_add_channel_parse_body(), ast_ari_bridges_clear_video_source(), ast_ari_bridges_clear_video_source_cb(), ast_ari_bridges_create(), ast_ari_bridges_create_cb(), ast_ari_bridges_create_parse_body(), ast_ari_bridges_create_with_id(), ast_ari_bridges_create_with_id_cb(), ast_ari_bridges_create_with_id_parse_body(), ast_ari_bridges_destroy(), ast_ari_bridges_destroy_cb(), ast_ari_bridges_get(), ast_ari_bridges_get_cb(), ast_ari_bridges_list_cb(), ast_ari_bridges_play(), ast_ari_bridges_play_cb(), ast_ari_bridges_play_parse_body(), ast_ari_bridges_play_with_id(), ast_ari_bridges_play_with_id_cb(), ast_ari_bridges_play_with_id_parse_body(), ast_ari_bridges_record(), ast_ari_bridges_record_cb(), ast_ari_bridges_record_parse_body(), ast_ari_bridges_remove_channel(), ast_ari_bridges_remove_channel_cb(), ast_ari_bridges_remove_channel_parse_body(), ast_ari_bridges_set_video_source(), ast_ari_bridges_set_video_source_cb(), ast_ari_bridges_start_moh(), ast_ari_bridges_start_moh_cb(), ast_ari_bridges_start_moh_parse_body(), ast_ari_bridges_stop_moh(), ast_ari_bridges_stop_moh_cb(), ast_ari_channels_answer(), ast_ari_channels_answer_cb(), ast_ari_channels_continue_in_dialplan(), ast_ari_channels_continue_in_dialplan_cb(), ast_ari_channels_continue_in_dialplan_parse_body(), ast_ari_channels_create(), ast_ari_channels_create_cb(), ast_ari_channels_create_parse_body(), ast_ari_channels_dial(), ast_ari_channels_dial_cb(), ast_ari_channels_dial_parse_body(), ast_ari_channels_external_media(), ast_ari_channels_external_media_cb(), ast_ari_channels_external_media_parse_body(), ast_ari_channels_get(), ast_ari_channels_get_cb(), ast_ari_channels_get_channel_var(), ast_ari_channels_get_channel_var_cb(), ast_ari_channels_get_channel_var_parse_body(), ast_ari_channels_hangup(), ast_ari_channels_hangup_cb(), ast_ari_channels_hangup_parse_body(), ast_ari_channels_hold(), ast_ari_channels_hold_cb(), ast_ari_channels_list_cb(), ast_ari_channels_move(), ast_ari_channels_move_cb(), ast_ari_channels_move_parse_body(), ast_ari_channels_mute(), ast_ari_channels_mute_cb(), ast_ari_channels_mute_parse_body(), ast_ari_channels_originate(), ast_ari_channels_originate_cb(), ast_ari_channels_originate_parse_body(), ast_ari_channels_originate_with_id(), ast_ari_channels_originate_with_id_cb(), ast_ari_channels_originate_with_id_parse_body(), ast_ari_channels_play(), ast_ari_channels_play_cb(), ast_ari_channels_play_parse_body(), ast_ari_channels_play_with_id(), ast_ari_channels_play_with_id_cb(), ast_ari_channels_play_with_id_parse_body(), ast_ari_channels_progress(), ast_ari_channels_progress_cb(), ast_ari_channels_record(), ast_ari_channels_record_cb(), ast_ari_channels_record_parse_body(), ast_ari_channels_redirect(), ast_ari_channels_redirect_cb(), ast_ari_channels_redirect_parse_body(), ast_ari_channels_ring(), ast_ari_channels_ring_cb(), ast_ari_channels_ring_stop(), ast_ari_channels_ring_stop_cb(), ast_ari_channels_rtpstatistics(), ast_ari_channels_rtpstatistics_cb(), ast_ari_channels_send_dtmf(), ast_ari_channels_send_dtmf_cb(), ast_ari_channels_send_dtmf_parse_body(), ast_ari_channels_set_channel_var(), ast_ari_channels_set_channel_var_cb(), ast_ari_channels_set_channel_var_parse_body(), ast_ari_channels_snoop_channel(), ast_ari_channels_snoop_channel_cb(), ast_ari_channels_snoop_channel_parse_body(), ast_ari_channels_snoop_channel_with_id(), ast_ari_channels_snoop_channel_with_id_cb(), ast_ari_channels_snoop_channel_with_id_parse_body(), ast_ari_channels_start_moh(), ast_ari_channels_start_moh_cb(), ast_ari_channels_start_moh_parse_body(), ast_ari_channels_start_silence(), ast_ari_channels_start_silence_cb(), ast_ari_channels_stop_moh(), ast_ari_channels_stop_moh_cb(), ast_ari_channels_stop_silence(), ast_ari_channels_stop_silence_cb(), ast_ari_channels_transfer_progress(), ast_ari_channels_transfer_progress_cb(), ast_ari_channels_transfer_progress_parse_body(), ast_ari_channels_unhold(), ast_ari_channels_unhold_cb(), ast_ari_channels_unmute(), ast_ari_channels_unmute_cb(), ast_ari_channels_unmute_parse_body(), ast_ari_device_states_delete(), ast_ari_device_states_delete_cb(), ast_ari_device_states_get(), ast_ari_device_states_get_cb(), ast_ari_device_states_list_cb(), ast_ari_device_states_update(), ast_ari_device_states_update_cb(), ast_ari_device_states_update_parse_body(), ast_ari_endpoints_get(), ast_ari_endpoints_get_cb(), ast_ari_endpoints_list_by_tech(), ast_ari_endpoints_list_by_tech_cb(), ast_ari_endpoints_list_cb(), ast_ari_endpoints_refer(), ast_ari_endpoints_refer_cb(), ast_ari_endpoints_refer_parse_body(), ast_ari_endpoints_refer_to_endpoint(), ast_ari_endpoints_refer_to_endpoint_cb(), ast_ari_endpoints_refer_to_endpoint_parse_body(), ast_ari_endpoints_send_message(), ast_ari_endpoints_send_message_cb(), ast_ari_endpoints_send_message_parse_body(), ast_ari_endpoints_send_message_to_endpoint(), ast_ari_endpoints_send_message_to_endpoint_cb(), ast_ari_endpoints_send_message_to_endpoint_parse_body(), ast_ari_events_user_event(), ast_ari_events_user_event_cb(), ast_ari_events_user_event_parse_body(), ast_ari_mailboxes_delete(), ast_ari_mailboxes_delete_cb(), ast_ari_mailboxes_get(), ast_ari_mailboxes_get_cb(), ast_ari_mailboxes_list_cb(), ast_ari_mailboxes_update(), ast_ari_mailboxes_update_cb(), ast_ari_mailboxes_update_parse_body(), ast_ari_playbacks_control(), ast_ari_playbacks_control_cb(), ast_ari_playbacks_control_parse_body(), ast_ari_playbacks_get(), ast_ari_playbacks_get_cb(), ast_ari_playbacks_stop(), ast_ari_playbacks_stop_cb(), ast_ari_recordings_cancel(), ast_ari_recordings_cancel_cb(), ast_ari_recordings_copy_stored(), ast_ari_recordings_copy_stored_cb(), ast_ari_recordings_copy_stored_parse_body(), ast_ari_recordings_delete_stored(), ast_ari_recordings_delete_stored_cb(), ast_ari_recordings_get_live(), ast_ari_recordings_get_live_cb(), ast_ari_recordings_get_stored(), ast_ari_recordings_get_stored_cb(), ast_ari_recordings_get_stored_file(), ast_ari_recordings_get_stored_file_cb(), ast_ari_recordings_list_stored_cb(), ast_ari_recordings_mute(), ast_ari_recordings_mute_cb(), ast_ari_recordings_pause(), ast_ari_recordings_pause_cb(), ast_ari_recordings_stop(), ast_ari_recordings_stop_cb(), ast_ari_recordings_unmute(), ast_ari_recordings_unmute_cb(), ast_ari_recordings_unpause(), ast_ari_recordings_unpause_cb(), ast_ari_sounds_get(), ast_ari_sounds_get_cb(), ast_ari_sounds_list(), ast_ari_sounds_list_cb(), ast_ari_sounds_list_parse_body(), ast_beep_start(), ast_cc_agent_callback(), ast_cc_agent_status_response(), ast_cli_command_full(), ast_eivr_senddtmf(), ast_func_read(), ast_func_read2(), ast_func_write(), ast_json_pack(), ast_json_stringf(), ast_json_vstringf(), ast_pbx_run_args(), ast_queue_log(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), asyncgoto_exec(), attended_transfer_exec(), audiosocket_exec(), audiosocket_request(), background_detect_exec(), blind_transfer_exec(), bool_handler_fn(), bridge_exec(), bridgewait_exec(), broadcast_exec(), build_profile(), calendar_query_exec(), calendar_query_result_exec(), callerid_read(), callerid_write(), cc_agent_callback_helper(), cc_do_state_change(), cc_failed(), cc_request_state_change(), cc_status_response(), cdr_prop_write_callback(), cdr_read_callback(), cdr_write(), cdr_write_callback(), celgenuserevent_exec(), chanavail_exec(), channel_admin_exec(), channel_set_debug(), chanspy_exec(), chararray_handler_fn(), checknoargs(), clearcbone(), cleardisplay(), clearflag(), cleartimer(), cli_aor_iterate(), cli_contact_iterate(), cli_endpoint_iterate(), cli_iterate(), cli_iterator(), cli_iterator(), cli_iterator(), cli_odbc_read(), cli_odbc_write(), cli_unid_iterate(), codec_handler_fn(), conf_exec(), confbridge_exec(), config_function_read(), confkick_exec(), connectedline_write(), control_dial_args_alloc(), control_dial_args_destroy(), controlplayback_exec(), count_exec(), create_sound_blob(), cut_internal(), dahdi_call(), dahdichan_helper(), detect_write(), determine_starting_point(), dial_exec_full(), dial_trunk(), dialgroup_write(), dictate_exec(), digitcollect(), digitdirect(), directory_exec(), disa_exec(), double_handler_fn(), dtmfstore_exec(), dundi_query_read(), dundi_result_read(), dundifunc_read(), eivr_comm(), enable_jack_hook(), enum_query_read(), enum_result_read(), exec_exec(), expand_gosub_args(), extenspy_exec(), external_media_audiosocket_tcp(), external_media_rtp_udp(), external_media_websocket(), festival_exec(), file_count_line(), file_read(), file_write(), filter(), find_by_name(), find_by_uniqueid(), find_conf(), findoption(), forkcdr_exec(), func_args(), func_confbridge_channels(), func_confbridge_helper(), func_confbridge_info(), func_export_write(), func_get_parkingslot_channel(), func_mixmonitor_read(), func_read(), func_read_header(), func_read_headers(), func_read_param(), func_response_read_header(), func_response_read_headers(), func_write_header(), func_write_param(), function_amiclient(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), function_enum(), function_fieldnum_helper(), function_fieldqty_helper(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_write(), function_txtcidname(), general_apply(), geoloc_profile_read(), geoloc_profile_write(), gosubif_exec(), goto_line(), goto_line_rel(), handle_cli_presencestate_change(), handle_core_set_debug_channel(), handle_gosub(), hangupcause_read(), hint_read(), hook_on(), iconv_read(), import_helper(), incoming_answer_codec_prefs_to_str(), incoming_offer_codec_prefs_to_str(), int_handler_fn(), isAnsweringMachine(), isexten_function_read(), jb_debug_output(), jb_error_output(), jb_helper(), jb_warning_output(), jingle_request(), json_decode_read(), listfilter(), load_channelvars(), load_config(), load_module(), log_exec(), main(), man_do_variable_value(), manager_mixmonitor(), math(), mbl_sendsms_exec(), mbl_status_exec(), mixmonitor_exec(), msg_send_exec(), multicast_rtp_request(), mute_mixmonitor_instance(), onevent(), originate_exec(), outgoing_answer_codec_prefs_to_str(), outgoing_offer_codec_prefs_to_str(), page_exec(), park_and_announce_app_exec(), park_app_parse_data(), parked_call_app_exec(), parse_options(), parse_uri_cb(), parseargs(), parsedoublearg(), parsefilearg(), parseintarg(), parseswitcharg(), parsetimearg(), parsevolarg(), pbx_builtin_answer(), pbx_builtin_background(), pbx_builtin_saycharacters_case(), pbx_builtin_setvar_multiple(), pbx_builtin_waitdigit(), pbx_builtin_waitexten(), peek_read(), pickupchan_exec(), pjsip_acf_channel_read(), pjsip_acf_dial_contacts_read(), pjsip_acf_parse_uri_read(), pjsip_aor_function_read(), pjsip_contact_function_read(), pjsip_endpoint_function_read(), play_moh_exec(), playback_exec(), pp_each_extension_helper(), pp_each_user_helper(), pqm_exec(), presence_read(), presence_write(), privacy_exec(), process_opcode(), process_returncode(), pvalAppCallWalkArgs(), pvalMacroCallWalkArgs(), ql_exec(), queue_exec(), queue_function_mem_read(), queue_function_mem_write(), queue_function_memberpenalty_read(), queue_function_memberpenalty_write(), queue_function_queuegetchannel(), queue_match(), qupd_exec(), realtime_sqlite3_load(), realtimefield_read(), receivefax_exec(), record_exec(), recordthread(), recvtext_exec(), redirecting_write(), regex(), reload_single_member(), replace(), request(), resetcdr_exec(), retrydial_exec(), rqm_exec(), run_station(), saycountedadj_exec(), saycountednoun_exec(), sayfile_exec(), sayunixtime_exec(), scan_exec(), scramble_write(), send_delay(), send_dtmf(), senddtmf_exec(), sendfax_exec(), sendmf_exec(), sendsf_exec(), set_state(), setflag(), setup_stunaddr(), shared_read(), shared_write(), shift_pop(), showdisplay(), showkeys(), signal_exec(), sla_handle_dial_state_event(), sla_station_exec(), sla_trunk_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sockaddr_handler_fn(), softhangup_exec(), sorcery_function_read(), speech_background(), speech_load(), srv_result_read(), stackpeek_read(), start_mixmonitor_callback(), start_moh_exec(), starttimer(), stasis_app_control_dial(), static_realtime_cb(), statsd_exec(), stop_mixmonitor_full(), strbetween(), stream_echo_exec(), stringfield_handler_fn(), strreplace(), stun_close_sock(), stun_monitor_request(), stun_start_monitor(), stun_stop_monitor(), subscript(), talk_detect_fn_write(), test_jb_debug_output(), test_jb_error_output(), test_jb_warn_output(), timeval_struct2str(), transfer_exec(), tryexec_exec(), uint_handler_fn(), unicast_rtp_request(), unload_module(), unshift_push(), upqm_exec(), user_chan_cb(), userevent_exec(), verbose_exec(), vm_exec(), vm_execmain(), vm_playmsgexec(), volume_read(), volume_write(), wait_exec(), waitfor_exec(), waitforcond_exec(), waitsignal_exec(), webchan_request(), websocket_client_args_create(), websocket_client_args_destroy(), xmpp_join_exec(), xmpp_leave_exec(), xmpp_send_exec(), xmpp_sendgroup_exec(), yesno_handler_fn(), and zapateller_exec().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 483 of file res_stun_monitor.c.

◆ cli_stun

struct ast_cli_entry cli_stun[]
static
Initial value:
= {
{ .handler = handle_cli_stun_show_status , .summary = "Show STUN servers and statuses" ,},
}
static char * handle_cli_stun_show_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)

Definition at line 425 of file res_stun_monitor.c.

425 {
426 AST_CLI_DEFINE(handle_cli_stun_show_status, "Show STUN servers and statuses"),
427};
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197

Referenced by load_module(), and unload_module().

◆ external_addr

struct sockaddr_in external_addr

Current perceived external address.

Definition at line 58 of file res_stun_monitor.c.

◆ external_addr_known

unsigned int external_addr_known

TRUE if the perceived external address is valid/known.

Definition at line 70 of file res_stun_monitor.c.

◆ lock

STUN monitor protection lock.

Definition at line 56 of file res_stun_monitor.c.

◆ monitor_enabled

unsigned int monitor_enabled

TRUE if the STUN monitor is enabled.

Definition at line 68 of file res_stun_monitor.c.

◆ refresh

unsigned int refresh

Number of seconds between polls to the STUN server for the external address.

Definition at line 64 of file res_stun_monitor.c.

Referenced by iax2_ack_registry(), and update_registry().

◆ sched

struct ast_sched_context* sched
static

Definition at line 52 of file res_stun_monitor.c.

◆ server_hostname

const char* server_hostname

STUN server host name.

Definition at line 60 of file res_stun_monitor.c.

◆ stun_conf_file

const char stun_conf_file[] = "res_stun_monitor.conf"
static

Definition at line 51 of file res_stun_monitor.c.

Referenced by load_config().

◆ stun_poll_failed_gripe

unsigned int stun_poll_failed_gripe

TRUE if we have already griped about a STUN poll failing.

Definition at line 72 of file res_stun_monitor.c.

◆ stun_port

unsigned int stun_port

Port of STUN server to use

Definition at line 62 of file res_stun_monitor.c.

◆ stun_sock

int stun_sock

Monitoring STUN socket.

Definition at line 66 of file res_stun_monitor.c.