[asterisk-commits] oej: branch oej/libmidcom-new r48344 -
/team/oej/libmidcom-new/res_netsec.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Dec 7 00:57:34 MST 2006
Author: oej
Date: Thu Dec 7 01:57:33 2006
New Revision: 48344
URL: http://svn.digium.com/view/asterisk?view=rev&rev=48344
Log:
- Add comments
- Add to todo-list
- Remove ERROR if midcom not activated
Modified:
team/oej/libmidcom-new/res_netsec.c
Modified: team/oej/libmidcom-new/res_netsec.c
URL: http://svn.digium.com/view/asterisk/team/oej/libmidcom-new/res_netsec.c?view=diff&rev=48344&r1=48343&r2=48344
==============================================================================
--- team/oej/libmidcom-new/res_netsec.c (original)
+++ team/oej/libmidcom-new/res_netsec.c Thu Dec 7 01:57:33 2006
@@ -32,6 +32,9 @@
* - Clear up operations
* - Make source code follow coding guidelines
* - Check licensing
+ * - Fix proper reload function
+ - How does this affect midcom connections to a device?
+ * - fix autoconfigure to set MIDCOM_EXISTS flag if libmidcom is installed
*/
@@ -68,7 +71,7 @@
#define FAREND 2
static const char version[] = "Libmidcom version 0.2.0";
-static const char desc[] = "MiddleBox Communication Module (MIDCOM)";
+static const char desc[] = "MiddleBox Communication Module (MIDCOM/SIMCO)";
static unsigned int midcomnat = NO_MIDCOM;
static char cert[512];
static char* config = "midcom.conf";
@@ -87,23 +90,30 @@
static timer_task_context_t *timer_context_create(void);
static void timer_context_delete(timer_task_context_t *ttc);
+/*! Midcom ruleset, one per session (pvt)
+ \note this structure needs a pointer in the channel's
+ pvt structure
+*/
static struct midcom_rule {
- int enable_rtcp;
+ int enable_rtcp; /* There's one RTCP per RTP stream that needs to go through*/
struct in_addr midbox_addr;
char username[256];
int nat_done;
int firewall_done;
int bye_done;
- int novideo;
+ int novideo; /* This might need redesign */
int con;
- int ruleid;
- struct sockaddr_in our_internal_addr;
- struct sockaddr_in our_natted_addr;
+ int ruleid; /* Audio rule ID */
+ struct sockaddr_in our_internal_addr; /* Audio */
+ struct sockaddr_in our_natted_addr; /* Audio */
struct sockaddr_in redirip_nat; /* Peer NAT */
- int vruleid;
- struct sockaddr_in our_internal_vaddr;
- struct sockaddr_in our_natted_vaddr;
- struct sockaddr_in vredirip_nat;
+ int vruleid; /* Video */
+ struct sockaddr_in our_internal_vaddr; /* Video */
+ struct sockaddr_in our_natted_vaddr; /* Video */
+ struct sockaddr_in vredirip_nat; /* Video */
+ /* For Asterisk svn trunk, we will need t.140 text support here as well
+ It's another RTP stream
+ */
void *channel; /* farend */
struct sockaddr_in remote_addr; /* farend */
struct sockaddr_in remote_vaddr; /* farend */
@@ -111,10 +121,11 @@
int is_cached;
int invalid;
timer_id_t timer_handle;
- void *p;
+ void *p; /* ???? */
struct midcom_rule *next;
} *midcom_rule_head = NULL;
+/*! \brief midcom connection to the remote device */
static struct connection {
struct in_addr ipaddress;
char name[256];
@@ -128,9 +139,10 @@
struct connection *next;
} *connl = NULL;
-/* Protect the midcom rule list */
+/*! \brief Protection of the midcom rule list */
AST_MUTEX_DEFINE_STATIC(mclock);
+/*---------- Forward declarations -------------------*/
static int midcom_config_reload(void);
static int get_lb_midbox_ip(struct in_addr *ip);
@@ -180,10 +192,11 @@
static struct midcom_rule *get_peer_rule(struct midcom_rule *r);
-static struct ast_sip_helper_cb *sip_cb = NULL;
+static struct ast_sip_helper_cb *channel_cb = NULL;
struct ast_sip_hook_cb *midcom_cb = NULL; /*move this to the core asterisk files */
+/*------- CLI help texts -------------------------*/
static char enable_firewall_usage[] =
"Usage: midcom enable firewall\n"
" Enable the midcom communication between Asterisk and middlebox.\n";
@@ -217,7 +230,9 @@
{ { "midcom", "show", "version", NULL }, midcom_show_version, "Display the current version of the midcom communication module", show_version_usage }
};
-/*--- midcom_sip: Interface structure with callbacks used to connect to sip module --*/
+/*! \brief Interface structure with callbacks used to connect to sip module
+ \note Can this be made less SIPpy?
+*/
static struct ast_sip_hook_cb sip_hook = {
handle_request_invite_hook: midcom_handle_request_invite_hook,
handle_response_invite_hook: midcom_handle_response_invite_hook,
@@ -234,17 +249,22 @@
ast_sip_helper_unregister: midcom_sip_helper_unregister,
};
+/*! \brief Register callback function */
static void midcom_sip_helper_register(struct ast_sip_helper_cb *cb)
{
- sip_cb = cb;
-}
-
+ channel_cb = cb;
+}
+
+/*! \brief Unregister callback function
+ \note can't this just be midcom_sip_helper_register(NULL)
+*/
static void midcom_sip_helper_unregister(void)
{
- sip_cb = NULL;
-}
-
-int load_module(void)
+ channel_cb = NULL;
+}
+
+/*! \brief PBX Interface module */
+static int load_module(void)
{
if (midcom_config_reload()) {
ast_log(LOG_ERROR, "Unable to read conf file. Not loading MIDCOM support\n");
@@ -252,10 +272,11 @@
}
fflush(stdout); /* XXXX Why is this needed ????? */
+
if (!mc_init(cert)) {
ast_log(LOG_ERROR, "Unable to initialize MIDCOM module\n");
- /* We should possibly release some allocated memory here,
- if we've allocated during config load */
+ /*! |BUG We should possibly release some allocated memory here,
+ if we've allocated during config load */
return -1;
}
@@ -282,7 +303,8 @@
return 0;
}
-int unload_module(void)
+/*! \brief Unload module, PBX interface */
+static int unload_module(void)
{
struct midcom_rule *r;
struct connection *c;
@@ -291,15 +313,14 @@
/* Hangup all interfaces if they have an owner */
r = midcom_rule_head;
while (r) {
- if (sip_cb)
- sip_cb->ast_softhangup_helper(r->p);
- r = r->next;
+ if (channel_cb)
+ channel_cb->ast_softhangup_helper(r->p);
+ r = r->next;
}
midcom_rule_head = NULL;
ast_mutex_unlock(&mclock);
- } else {
+ } else
ast_log(LOG_WARNING, "Unable to lock the midcom rule list\n");
- }
c = connl;
while (c) {
@@ -338,7 +359,7 @@
return (char *) desc;
}
-/*--- midcom_enable_firewall: Turn on Midcom firewall (CLI command) */
+/*! \brief Turn on Midcom firewall (CLI command) */
static int midcom_enable_firewall(int fd, int argc, char *argv[])
{
int oldflag = midcom_enabled;
@@ -352,7 +373,7 @@
return RESULT_SUCCESS;
}
-/*--- midcom_disable_firewall: Turn off Midcom firewall (CLI command) */
+/*! \brief Turn off Midcom firewall (CLI command) */
static int midcom_disable_firewall(int fd, int argc, char *argv[])
{
if (argc != 3)
@@ -362,7 +383,7 @@
return RESULT_SUCCESS;
}
-/*--- midcom_show_firewall: Show Midcom firewall rules (CLI command) */
+/*! \brief Show Midcom firewall rules (CLI command) */
static int midcom_show_firewall(int fd, int argc, char *argv[])
{
regex_t regexbuf;
@@ -416,9 +437,9 @@
else
strncpy(status, "Firewalled", sizeof(status));
- peer_chan = sip_cb->ast_bridged_channel_helper(r->p);
+ peer_chan = channel_cb->ast_bridged_channel_helper(r->p);
if (peer_chan && peer_chan->tech_pvt) {
- peer_rule = sip_cb->ast_get_hook_struct(peer_chan->tech_pvt);
+ peer_rule = channel_cb->ast_get_hook_struct(peer_chan->tech_pvt);
if (peer_rule)
peer_ip = peer_rule->our_natted_addr;
}
@@ -487,7 +508,7 @@
}
-/*--- midcom_disable_debug: Disable debug prints on the Midcom module */
+/*! \brief Disable debug prints on the Midcom module */
static int midcom_disable_debug(int fd, int argc, char *argv[])
{
@@ -609,10 +630,10 @@
return NULL;
}
memset(r, 0, sizeof(struct midcom_rule));
- r->novideo = sip_cb->ast_get_flag_novideo(p);
- sip_cb->ast_rtp_get_peer_audio_helper(p, &r->our_internal_addr);
+ r->novideo = channel_cb->ast_get_flag_novideo(p);
+ channel_cb->ast_rtp_get_peer_audio_helper(p, &r->our_internal_addr);
if (!r->novideo)
- sip_cb->ast_rtp_get_peer_video_helper(p, &r->our_internal_vaddr);
+ channel_cb->ast_rtp_get_peer_video_helper(p, &r->our_internal_vaddr);
return r;
}
@@ -623,31 +644,32 @@
struct midcom_rule *r = NULL;
if (!midcom_enabled) {
- ast_log(LOG_ERROR, "Midcom: Module not enabled\n");
+ if (option_debug > 1)
+ ast_log(LOG_DEBUG, "Midcom: Module not enabled\n");
if (option_verbose > 1)
ast_verbose("Midcom: Module currently disabled\n");
return 1;
}
- if (!sip_cb) {
+ if (!channel_cb) {
ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
if (option_verbose > 1)
ast_verbose("Midcom: Error!! - Module not initialized\n");
return 0;
}
- if ((r = sip_cb->ast_get_hook_struct(p)))
+ if ((r = channel_cb->ast_get_hook_struct(p)))
return 1;
if (is_nearend_nat()) {
- sip_cb->ast_rtp_get_peer_audio_helper(p, &caller);
-
- if (sip_cb->ast_cmp_sa_addr(p, &caller)) { /* not forwarded from another softswitch */
+ channel_cb->ast_rtp_get_peer_audio_helper(p, &caller);
+
+ if (channel_cb->ast_cmp_sa_addr(p, &caller)) { /* not forwarded from another softswitch */
r = midcom_rule_alloc(p);
if (r == NULL)
return 0;
- /* sip_cb->ast_get_recv_addr(p, &r->midbox_addr); */
+ /* channel_cb->ast_get_recv_addr(p, &r->midbox_addr); */
if ( get_lb_midbox_ip(&r->midbox_addr) == -1)
return 0;
@@ -679,7 +701,7 @@
ast_mutex_unlock(&usecnt_lock);
ast_update_use_count();
- sip_cb->ast_map_hook_struct(p, (void *)r);
+ channel_cb->ast_map_hook_struct(p, (void *)r);
r->p = p;
r->next = midcom_rule_head;
midcom_rule_head = r;
@@ -708,7 +730,7 @@
return 1;
}
- if (!sip_cb) {
+ if (!channel_cb) {
ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
if (option_verbose > 1)
ast_verbose("Midcom: Error!! - Module not initialized\n");
@@ -716,7 +738,7 @@
}
- if ((r = sip_cb->ast_get_hook_struct(p)))
+ if ((r = channel_cb->ast_get_hook_struct(p)))
return 1;
r = midcom_rule_alloc(p);
@@ -724,13 +746,13 @@
return 0;
if (!r->username[0])
- strncpy(r->username, sip_cb->ast_get_username(p), 256);
+ strncpy(r->username, channel_cb->ast_get_username(p), 256);
if (option_verbose > 1)
ast_verbose("Midcom: Allocating new midcom rule for phone: %s\n", r->username);
- /* sip_cb->ast_get_recv_addr(p, &r->midbox_addr); */
+ /* channel_cb->ast_get_recv_addr(p, &r->midbox_addr); */
if ( get_lb_midbox_ip(&r->midbox_addr) == -1)
return 0;
@@ -768,11 +790,11 @@
int codec = 0;
if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
- sip_cb->ast_rtp_get_us_audio_helper(p, &sin);
+ channel_cb->ast_rtp_get_us_audio_helper(p, &sin);
if (!r->novideo)
- sip_cb->ast_rtp_get_us_video_helper(p, &vsin);
+ channel_cb->ast_rtp_get_us_video_helper(p, &vsin);
- codec = sip_cb->ast_get_capability_helper(p);
+ codec = channel_cb->ast_get_capability_helper(p);
if (midcom_open_firewall(r->con, &r->ruleid, &r->our_internal_addr, &sin, &r->lifetime, (codec & 0x0000FFFF)) != 0) {
free(r);
r = NULL;
@@ -803,7 +825,7 @@
ast_mutex_unlock(&usecnt_lock);
ast_update_use_count();
- sip_cb->ast_map_hook_struct(p, (void *)r);
+ channel_cb->ast_map_hook_struct(p, (void *)r);
r->p = p;
r->next = midcom_rule_head;
midcom_rule_head = r;
@@ -826,14 +848,14 @@
return 1;
}
- if (!sip_cb) {
+ if (!channel_cb) {
ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
if (option_verbose > 1)
ast_verbose("Midcom: Error!! - Module not initialized\n");
return 0;
}
- if ((r = sip_cb->ast_get_hook_struct(p)))
+ if ((r = channel_cb->ast_get_hook_struct(p)))
return 1;
if (is_farend_nat())
@@ -843,21 +865,21 @@
return 0;
if (!r->username[0])
- strncpy(r->username, sip_cb->ast_get_username(p), 256);
+ strncpy(r->username, channel_cb->ast_get_username(p), 256);
if (option_verbose > 1)
ast_verbose("Midcom: Allocating new rule for phone: %s\n", r->username);
- /* sip_cb->ast_get_recv_addr(p, &r->midbox_addr); */
+ /* channel_cb->ast_get_recv_addr(p, &r->midbox_addr); */
if ( get_lb_midbox_ip(&r->midbox_addr) == -1)
return 0;
if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
- sip_cb->ast_rtp_get_us_audio_helper(p, &sin);
+ channel_cb->ast_rtp_get_us_audio_helper(p, &sin);
if (!r->novideo)
- sip_cb->ast_rtp_get_us_video_helper(p, &vsin);
+ channel_cb->ast_rtp_get_us_video_helper(p, &vsin);
- codec = sip_cb->ast_get_capability_helper(p);
+ codec = channel_cb->ast_get_capability_helper(p);
if (midcom_open_firewall(r->con, &r->ruleid, &r->our_internal_addr, &sin, &r->lifetime, (codec & 0x0000FFFF)) != 0) {
if (option_verbose > 1)
ast_verbose("Midcom: Failed to open dynamic pinhole for Audio stream from phone: %s\n", r->username);
@@ -889,7 +911,7 @@
ast_mutex_unlock(&usecnt_lock);
ast_update_use_count();
- sip_cb->ast_map_hook_struct(p, (void *)r);
+ channel_cb->ast_map_hook_struct(p, (void *)r);
r->p = p;
r->next = midcom_rule_head;
midcom_rule_head = r;
@@ -915,16 +937,16 @@
return 1;
}
- if (!sip_cb) {
+ if (!channel_cb) {
ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
if (option_verbose > 1)
ast_verbose("Midcom: Error!! - Module not initialized\n");
return 0;
}
- if (!(r = sip_cb->ast_get_hook_struct(p))) {
-
- username = sip_cb->ast_get_username(p);
+ if (!(r = channel_cb->ast_get_hook_struct(p))) {
+
+ username = channel_cb->ast_get_username(p);
ast_log(LOG_ERROR, "Midcom: Unable to retrieve Midcom Rule for phone: %s\n", username);
if (option_verbose > 1)
ast_verbose("Midcom: Error!! - Unable to retrieve Midcom Rule for phone: %s\n", username);
@@ -948,8 +970,8 @@
midcom_delete_rule(r->con, r->vruleid);
r->firewall_done = 0;
- r->channel = sip_cb->ast_channel_helper(p);
- bridgepeer = sip_cb->ast_bridged_channel_helper(p);
+ r->channel = channel_cb->ast_channel_helper(p);
+ bridgepeer = channel_cb->ast_bridged_channel_helper(p);
first_phone = get_midbox_ip(bridgepeer, &r->midbox_addr, &r->remote_addr, &r->remote_vaddr);
if (first_phone == -1) {
return 0;
@@ -1010,7 +1032,7 @@
}
if (!r->username[0])
- strncpy(r->username, sip_cb->ast_get_username(p), 256);
+ strncpy(r->username, channel_cb->ast_get_username(p), 256);
if (!r->firewall_done)
{
@@ -1018,7 +1040,7 @@
if ((r->midbox_addr.s_addr) && (r->con != -1))
{
- codec = sip_cb->ast_get_capability_helper(p);
+ codec = channel_cb->ast_get_capability_helper(p);
if (is_farend)
res = midcom_bridge_firewall(r->con, r->ruleid, &r->our_natted_addr, &r->remote_addr, &r->lifetime, (codec & 0x0000FFFF));
else
@@ -1084,16 +1106,16 @@
return 1;
}
- if (!sip_cb) {
+ if (!channel_cb) {
ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
if (option_verbose > 1)
ast_verbose("Midcom: Error!! - Module not initialized\n");
return 0;
}
- if (!(s = sip_cb->ast_get_hook_struct(p))) {
-
- username = sip_cb->ast_get_username(p);
+ if (!(s = channel_cb->ast_get_hook_struct(p))) {
+
+ username = channel_cb->ast_get_username(p);
if (username && username[0]) {
ast_log(LOG_ERROR, "Midcom: Unable to retrieve Midcom Rule for phone: %s\n", username);
if (option_verbose > 1)
@@ -1636,9 +1658,15 @@
if (r && r->p) { /* pure paranoia */
- peer_chan = sip_cb->ast_bridged_channel_helper(r->p);
+ peer_chan = channel_cb->ast_bridged_channel_helper(r->p);
if (peer_chan && peer_chan->tech_pvt)
- peer_rule = sip_cb->ast_get_hook_struct(peer_chan->tech_pvt);
+ peer_rule = channel_cb->ast_get_hook_struct(peer_chan->tech_pvt);
}
return peer_rule;
}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "MIDCOM module for Asterisk",
+ .load = load_module,
+ .unload = unload_module,
+ /* .reload = reload, */
+ );
More information about the asterisk-commits
mailing list