summaryrefslogtreecommitdiff
path: root/res/res_stun_monitor.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2012-07-05 21:36:41 +0000
committerMatthew Jordan <mjordan@digium.com>2012-07-05 21:36:41 +0000
commit3044aa3e38042aab43a96f31bdce54cf5f200e4c (patch)
treed8208a7cae9c70b3f722748dddd80e8124e32d4c /res/res_stun_monitor.c
parent6a1ec1c20822e4fd2f32ed37c6351dfea18c8565 (diff)
Add 'stun show status' command
This patch adds a new CLI command, 'stun show status'. This command will show a table describing all known STUN servers and statuses. (closes issue ASTERISK-18046) Reported by: Jeremy Kister Tested by: Jeremy Kister patches: (stun-show-status-v4-trunk.patch license #6232 uploaded by Jeremy Kister) Review: https://reviewboard.asterisk.org/r/2001 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@369681 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_stun_monitor.c')
-rw-r--r--res/res_stun_monitor.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/res/res_stun_monitor.c b/res/res_stun_monitor.c
index b9854e60f..553083904 100644
--- a/res/res_stun_monitor.c
+++ b/res/res_stun_monitor.c
@@ -39,9 +39,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/netsock2.h"
#include "asterisk/lock.h"
#include "asterisk/acl.h"
+#include "asterisk/cli.h"
+
#include <fcntl.h>
#define DEFAULT_MONITOR_REFRESH 30 /*!< Default refresh period in seconds */
+#define DEFAULT_RETRIES 3 /*!< retries shown in stun show status
+ matching static retries in stun.c */
static const char stun_conf_file[] = "res_stun_monitor.conf";
static struct ast_sched_context *sched;
@@ -349,6 +353,63 @@ static int load_config(int startup)
return 0;
}
+/*! \brief Execute stun show status command */
+static void _stun_show_status(int fd)
+{
+ const char *status;
+
+#define DATALN "%-25s %-5d %-7d %-8d %-7s %-16s %-d\n"
+#define HEADER "%-25s %-5s %-7s %-8s %-7s %-16s %-s\n"
+
+ /*! we only have one stun server, but start to play well with more */
+ ast_cli(fd, HEADER, "Hostname", "Port", "Period", "Retries", "Status", "ExternAddr", "ExternPort");
+
+ if (args.stun_poll_failed_gripe) {
+ status = "FAIL";
+ } else if (args.external_addr_known) {
+ status = "OK";
+ } else {
+ status = "INIT";
+ }
+ ast_cli( fd, DATALN,
+ args.server_hostname,
+ args.stun_port,
+ args.refresh,
+ DEFAULT_RETRIES,
+ status,
+ ast_inet_ntoa(args.external_addr.sin_addr),
+ ntohs(args.external_addr.sin_port)
+ );
+
+#undef HEADER
+#undef DATALN
+}
+
+static char *handle_cli_stun_show_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "stun show status";
+ e->usage =
+ "Usage: stun show status\n"
+ " List all known STUN servers and statuses.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 3) {
+ return CLI_SHOWUSAGE;
+ }
+
+ _stun_show_status(a->fd);
+ return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_stun[] = {
+ AST_CLI_DEFINE(handle_cli_stun_show_status, "Show STUN servers and statuses"),
+};
+
static int __reload(int startup)
{
int res;
@@ -375,6 +436,10 @@ static int unload_module(void)
{
stun_stop_monitor();
ast_mutex_destroy(&args.lock);
+
+ /*! Unregister CLI commands */
+ ast_cli_unregister_multiple(cli_stun, ARRAY_LEN(cli_stun));
+
return 0;
}
@@ -387,6 +452,9 @@ static int load_module(void)
return AST_MODULE_LOAD_DECLINE;
}
+ /*! Register CLI commands */
+ ast_cli_register_multiple(cli_stun, sizeof(cli_stun) / sizeof(struct ast_cli_entry));
+
return AST_MODULE_LOAD_SUCCESS;
}