[asterisk-commits] dvossel: branch dvossel/stun_monitor r281866 - in /team/dvossel/stun_monitor:...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 11 14:23:21 CDT 2010
Author: dvossel
Date: Wed Aug 11 14:23:17 2010
New Revision: 281866
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281866
Log:
addresses reviewboard comments
Modified:
team/dvossel/stun_monitor/channels/chan_iax2.c
team/dvossel/stun_monitor/channels/chan_sip.c
team/dvossel/stun_monitor/configs/iax.conf.sample
team/dvossel/stun_monitor/configs/sip.conf.sample
team/dvossel/stun_monitor/res/res_stun_monitor.c
Modified: team/dvossel/stun_monitor/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/channels/chan_iax2.c?view=diff&rev=281866&r1=281865&r2=281866
==============================================================================
--- team/dvossel/stun_monitor/channels/chan_iax2.c (original)
+++ team/dvossel/stun_monitor/channels/chan_iax2.c Wed Aug 11 14:23:17 2010
@@ -268,7 +268,7 @@
static char language[MAX_LANGUAGE] = "";
static char regcontext[AST_MAX_CONTEXT] = "";
-static struct ast_event_sub *network_change_event_subscription = NULL; /*!< subscription id for network change events */
+static struct ast_event_sub *network_change_event_subscription; /*!< subscription id for network change events */
static int maxauthreq = 3;
static int max_retries = 4;
@@ -1239,17 +1239,18 @@
* is time to send MWI, since it is only sent with a REGACK. */
}
-static inline void network_change_event_subscribe(void)
+static void network_change_event_subscribe(void)
{
if (!network_change_event_subscription) {
network_change_event_subscription = ast_event_subscribe(AST_EVENT_NETWORK_CHANGE,
network_change_event_cb,
"SIP Network Change ",
- NULL);
- }
-}
-
-static inline void network_change_event_unsubscribe(void)
+ NULL,
+ AST_EVENT_IE_END);
+ }
+}
+
+static void network_change_event_unsubscribe(void)
{
if (network_change_event_subscription) {
network_change_event_subscription = ast_event_unsubscribe(network_change_event_subscription);
@@ -1259,12 +1260,11 @@
static void network_change_event_cb(const struct ast_event *event, void *userdata)
{
struct iax2_registry *reg;
- if (option_debug) {
- ast_log(LOG_DEBUG, "IAX, got a network change event, renewing all IAX registrations.\n");
- }
+ ast_debug(1, "IAX, got a network change event, renewing all IAX registrations.\n");
AST_LIST_LOCK(®istrations);
- AST_LIST_TRAVERSE(®istrations, reg, entry)
+ AST_LIST_TRAVERSE(®istrations, reg, entry) {
iax2_do_register(reg);
+ }
AST_LIST_UNLOCK(®istrations);
}
@@ -12811,7 +12811,8 @@
int format;
int portno = IAX_DEFAULT_PORTNO;
int x;
- int mtuv;
+ int mtuv;
+ int subscribe_network_change = 1;
struct iax2_user *user;
struct iax2_peer *peer;
struct ast_netsock *ns;
@@ -13131,9 +13132,9 @@
}
} else if (!strcasecmp(v->name, "subscribe_network_change_event")) {
if (ast_true(v->value)) {
- network_change_event_subscribe();
+ subscribe_network_change = 1;
} else if (ast_false(v->value)) {
- network_change_event_unsubscribe();
+ subscribe_network_change = 0;
} else {
ast_log(LOG_WARNING, "subscribe_network_change_event value %s is not valid at line %d.\n", v->value, v->lineno);
}
@@ -13149,7 +13150,13 @@
/* ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
v = v->next;
}
-
+
+ if (subscribe_network_change) {
+ network_change_event_subscribe();
+ } else {
+ network_change_event_unsubscribe();
+ }
+
if (defaultsockfd < 0) {
if (!(ns = ast_netsock_bind(netsock, io, "0.0.0.0", portno, qos.tos, qos.cos, socket_read, NULL))) {
ast_log(LOG_ERROR, "Unable to create network socket: %s\n", strerror(errno));
Modified: team/dvossel/stun_monitor/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/channels/chan_sip.c?view=diff&rev=281866&r1=281865&r2=281866
==============================================================================
--- team/dvossel/stun_monitor/channels/chan_sip.c (original)
+++ team/dvossel/stun_monitor/channels/chan_sip.c Wed Aug 11 14:23:17 2010
@@ -762,7 +762,7 @@
static struct ast_flags global_flags[3] = {{0}}; /*!< global SIP_ flags */
static int global_t38_maxdatagram; /*!< global T.38 FaxMaxDatagram override */
-static struct ast_event_sub *network_change_event_subscription = NULL; /*!< subscription id for network change events */
+static struct ast_event_sub *network_change_event_subscription; /*!< subscription id for network change events */
static char used_context[AST_MAX_CONTEXT]; /*!< name of automatically created context for unloading */
@@ -13435,17 +13435,17 @@
ao2_unlock(peer);
}
-static inline void network_change_event_subscribe(void)
+static void network_change_event_subscribe(void)
{
if (!network_change_event_subscription) {
network_change_event_subscription = ast_event_subscribe(AST_EVENT_NETWORK_CHANGE,
network_change_event_cb,
"SIP Network Change ",
- NULL);
- }
-}
-
-static inline void network_change_event_unsubscribe(void)
+ NULL, AST_EVENT_IE_END);
+ }
+}
+
+static void network_change_event_unsubscribe(void)
{
if (network_change_event_subscription) {
network_change_event_subscription = ast_event_unsubscribe(network_change_event_subscription);
@@ -13454,9 +13454,7 @@
static void network_change_event_cb(const struct ast_event *event, void *userdata)
{
- if (option_debug) {
- ast_log(LOG_DEBUG, "SIP, got a network change event, renewing all SIP registrations.\n");
- }
+ ast_debug(1, "SIP, got a network change event, renewing all SIP registrations.\n");
sip_send_all_registers();
}
@@ -26178,6 +26176,7 @@
int auto_sip_domains = FALSE;
struct ast_sockaddr old_bindaddr = bindaddr;
int registry_count = 0, peer_count = 0, timerb_set = 0, timert1_set = 0;
+ int subscribe_network_change = 1;
time_t run_start, run_end;
struct sockaddr_in externaddr_sin;
int bindport = 0;
@@ -26883,15 +26882,21 @@
}
} else if (!strcasecmp(v->name, "subscribe_network_change_event")) {
if (ast_true(v->value)) {
- network_change_event_subscribe();
+ subscribe_network_change = 1;
} else if (ast_false(v->value)) {
- network_change_event_unsubscribe();
+ subscribe_network_change = 0;
} else {
ast_log(LOG_WARNING, "subscribe_network_change_event value %s is not valid at line %d.\n", v->value, v->lineno);
}
} else if (!strcasecmp(v->name, "snom_aoc_enabled")) {
ast_set2_flag(&global_flags[2], ast_true(v->value), SIP_PAGE3_SNOM_AOC);
}
+ }
+
+ if (subscribe_network_change) {
+ network_change_event_subscribe();
+ } else {
+ network_change_event_unsubscribe();
}
if (global_t1 < global_t1min) {
Modified: team/dvossel/stun_monitor/configs/iax.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/configs/iax.conf.sample?view=diff&rev=281866&r1=281865&r2=281866
==============================================================================
--- team/dvossel/stun_monitor/configs/iax.conf.sample (original)
+++ team/dvossel/stun_monitor/configs/iax.conf.sample Wed Aug 11 14:23:17 2010
@@ -245,9 +245,9 @@
;register => FWDNumber:passwd at iax.fwdnet.net
;
; Through the use of the res_stun_monitor module, Asterisk has the ability to detect when the
-; perceived external network address has changed. This change generates an event which
-; chan_iax subscribes to. Upon receiving this event chan_iax will renew all outbound
-; registrations. By default this option is enabled, but only takes affect once
+; perceived external network address has changed. When the stun_monitor is installed and
+; configured, chan_iax will renew all outbound registrations when the monitor detects any sort
+; of network change has occurred. By default this option is enabled, but only takes effect once
; res_stun_monitor is configured. If res_stun_monitor is enabled and you wish to not
; generate all outbound registrations on a network change, use the option below to disable
; this feature.
Modified: team/dvossel/stun_monitor/configs/sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/configs/sip.conf.sample?view=diff&rev=281866&r1=281865&r2=281866
==============================================================================
--- team/dvossel/stun_monitor/configs/sip.conf.sample (original)
+++ team/dvossel/stun_monitor/configs/sip.conf.sample Wed Aug 11 14:23:17 2010
@@ -785,9 +785,9 @@
; media_address = 172.16.42.1
;
; Through the use of the res_stun_monitor module, Asterisk has the ability to detect when the
-; perceived external network address has changed. This change generates an event which
-; chan_sip subscribes to. Upon receiving this event chan_sip will renew all outbound
-; registrations. By default this option is enabled, but only takes affect once
+; perceived external network address has changed. When the stun_monitor is installed and
+; configured, chan_sip will renew all outbound registrations when the monitor detects any sort
+; of network change has occurred. By default this option is enabled, but only takes effect once
; res_stun_monitor is configured. If res_stun_monitor is enabled and you wish to not
; generate all outbound registrations on a network change, use the option below to disable
; this feature.
Modified: team/dvossel/stun_monitor/res/res_stun_monitor.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/res/res_stun_monitor.c?view=diff&rev=281866&r1=281865&r2=281866
==============================================================================
--- team/dvossel/stun_monitor/res/res_stun_monitor.c (original)
+++ team/dvossel/stun_monitor/res/res_stun_monitor.c Wed Aug 11 14:23:17 2010
@@ -1,7 +1,7 @@
/*
* Asterisk -- An open source telephony toolkit.
*
- * Copyright (C) 2009-2010, Digium, Inc.
+ * Copyright (C) 2010, Digium, Inc.
*
* David Vossel <dvossel at digium.com>
*
@@ -38,23 +38,23 @@
#define STANDARD_STUN_PORT 3478
#define DEFAULT_MONITOR_REFRESH 30
-static const char *stun_conf_file = "res_stun_monitor.conf";
+static const char stun_conf_file[] = "res_stun_monitor.conf";
static struct ast_sched_thread *sched;
-static struct stun_monitor_args {
+static struct {
struct ast_sockaddr stunbindaddr; /*!< The stun addres we bind to */
struct sockaddr_in stunaddr; /*!< The stun address we send requests to*/
struct sockaddr_in externaladdr; /*!< current perceived external address. */
- int externaladdr_known;
+ ast_mutex_t lock;
unsigned int refresh;
int stunsock;
- int monitor_enabled;
- ast_mutex_t lock;
+ unsigned int monitor_enabled:1;
+ unsigned int externaladdr_known:1;
} args;
static inline void stun_close_sock(void)
{
- if (args.stunsock < 0) {
+ if (args.stunsock != -1) {
close(args.stunsock);
args.stunsock = -1;
}
@@ -228,6 +228,8 @@
} else {
ast_log(LOG_NOTICE, "STUN Monitor set to refresh every %d seconds\n", args.refresh);
}
+ } else {
+ ast_log(LOG_WARNING, "SIP STUN: invalid config option %s at line %d\n", v->value, v->lineno);
}
}
@@ -274,9 +276,10 @@
args.externaladdr_known = 0;
sched = NULL;
if (__reload(1)) {
+ stun_stop_monitor();
+ ast_mutex_destroy(&args.lock);
return AST_MODULE_LOAD_FAILURE;
}
- ast_log(LOG_NOTICE, "Loaded STUN monitor\n");
return AST_MODULE_LOAD_SUCCESS;
}
More information about the asterisk-commits
mailing list