Asterisk - The Open Source Telephony Project  21.4.1
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>

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. More...
 
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 = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .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

#define DEFAULT_MONITOR_REFRESH   30

Default refresh period in seconds

Definition at line 47 of file res_stun_monitor.c.

#define DEFAULT_RETRIES   3

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

Definition at line 48 of file res_stun_monitor.c.

Referenced by _stun_show_status().

Function Documentation

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 374 of file res_stun_monitor.c.

References ast_inet_ntoa(), and DEFAULT_RETRIES.

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 }
403 
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: utils.c:928
#define DEFAULT_RETRIES
static int load_module ( void  )
static

Register CLI commands

Definition at line 463 of file res_stun_monitor.c.

References ast_cli_entry::args, ast_cli_register_multiple, AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.

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 }
476 
descriptor for a cli entry.
Definition: cli.h:171
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int unload_module ( void  )
static

Unregister CLI commands

Definition at line 452 of file res_stun_monitor.c.

References ast_cli_entry::args, and ast_cli_unregister_multiple().

452 {
453  stun_stop_monitor();
454  ast_mutex_destroy(&args.lock);
455 
456  /*! Unregister CLI commands */
457  ast_cli_unregister_multiple(cli_stun, ARRAY_LEN(cli_stun));
458 
459  return 0;
460 }
461 
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30

Variable Documentation

struct ast_cli_entry cli_stun[]
static
Initial value:
= {
{ .handler = handle_cli_stun_show_status , .summary = "Show STUN servers and statuses" ,},
}

Definition at line 426 of file res_stun_monitor.c.

struct sockaddr_in external_addr

Current perceived external address.

Definition at line 59 of file res_stun_monitor.c.

unsigned int external_addr_known

TRUE if the perceived external address is valid/known.

Definition at line 71 of file res_stun_monitor.c.

STUN monitor protection lock.

Definition at line 57 of file res_stun_monitor.c.

Referenced by __ast_bucket_scheme_register(), __ast_format_interface_register(), ast_aeap_connect(), ast_ari_add_handler(), ast_bridge_basic_set_flags(), ast_bridge_read_after_goto(), ast_bridge_transfer_attended(), ast_bridge_transfer_blind(), ast_cdr_fork(), ast_channel_move(), ast_clear_mixmonitor_methods(), ast_config_engine_deregister(), ast_config_engine_register(), ast_endpoint_snapshot_create(), ast_format_cache_set(), ast_get_extension_for_mime_type(), ast_get_format_for_file_ext(), ast_realtime_is_mapping_defined(), ast_set_mixmonitor_methods(), ast_start_mixmonitor(), ast_stop_mixmonitor(), ast_taskprocessor_set_local(), ast_unreal_channel_push_to_bridge(), bridge_basic_change_personality(), bucket_file_wizard_retrieve(), bucket_wizard_retrieve(), clear_stimulus_queue(), conf_announce_channel_push(), event_session_shutdown(), find_engine(), get_park_common_datastore_copy(), load_task(), message_sink_cb(), one_protocol(), prometheus_callback_register(), prometheus_callback_unregister(), prometheus_last_scrape_time_get(), prometheus_metric_register(), prometheus_metric_registered_count(), prometheus_metric_unregister(), remove_hooks_on_personality_change(), report_fax_status(), report_receive_fax_status(), report_send_fax_status(), rtp_ioqueue_thread_get_or_create(), rtp_reload(), snoop_determine_format(), stasis_app_control_record(), stasis_app_playback_get_state(), stasis_app_playback_operation(), stasis_app_recording_operation(), stasis_message_sink_should_stay(), stasis_message_sink_wait_for(), stasis_message_sink_wait_for_count(), task(), and task_wait().

unsigned int monitor_enabled

TRUE if the STUN monitor is enabled.

Definition at line 69 of file res_stun_monitor.c.

unsigned int refresh

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

Definition at line 65 of file res_stun_monitor.c.

Referenced by iax2_ack_registry(), and update_registry().

const char* server_hostname

STUN server host name.

Definition at line 61 of file res_stun_monitor.c.

unsigned int stun_poll_failed_gripe

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

Definition at line 73 of file res_stun_monitor.c.

unsigned int stun_port

Port of STUN server to use

Definition at line 63 of file res_stun_monitor.c.

int stun_sock

Monitoring STUN socket.

Definition at line 67 of file res_stun_monitor.c.