[svn-commits] rizzo: branch rizzo/astobj2 r76219 - /team/rizzo/astobj2/channels/chan_sip.c
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Jul 20 18:38:39 CDT 2007
Author: rizzo
Date: Fri Jul 20 18:38:38 2007
New Revision: 76219
URL: http://svn.digium.com/view/asterisk?view=rev&rev=76219
Log:
improve documentation related to externip/stun handling
Modified:
team/rizzo/astobj2/channels/chan_sip.c
Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=76219&r1=76218&r2=76219
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Fri Jul 20 18:38:38 2007
@@ -1394,8 +1394,8 @@
* bound to fail anyways, so we just live with this event and let
* the protocol handle this above us.
*/
-
static volatile int sipsock = -1; /*!< Main socket for SIP network communication */
+
static struct sockaddr_in bindaddr; /*!< The address we bind to */
/*! \brief our (internal) default address/port to put in SIP/SDP messages
@@ -1422,6 +1422,7 @@
* to the specified server, and store the result in externip.
*/
static struct sockaddr_in externip; /*!< External IP address if we are behind NAT */
+
static char externhost[MAXHOSTNAMELEN]; /*!< External host name */
static time_t externexpire; /*!< Expiration counter for re-resolving external host name in dynamic DNS */
static int externrefresh = 10;
@@ -1433,7 +1434,7 @@
* AST_SENSE_DENY for 'local' addresses, and AST_SENSE_ALLOW for 'non local'
* (i.e. presumably public) addresses.
*/
-static struct ast_ha *localaddr;
+static struct ast_ha *localaddr; /*!< List of local networks, on the same side of NAT as this Asterisk */
static struct sockaddr_in debugaddr;
@@ -2210,37 +2211,33 @@
static void ast_sip_ouraddrfor(struct in_addr *them, struct sockaddr_in *us)
{
struct sockaddr_in theirs;
- /* Set want_remap to non-zero if we want to remap 'us'.
- * Conditions are that we have a localaddr list,
- * either stunaddr or externip is set,
- * the remote address does not match any of the 'localaddr' entries,
- * and (cheched later) some other condition on 'us'.
+ /* Set want_remap to non-zero if we want to remap 'us' to an externally
+ * reachable IP address and port. This is done if:
+ * 1. we have a localaddr list (containing 'internal' addresses marked
+ * as 'deny', so ast_apply_ha() will return AST_SENSE_DENY on them,
+ * and AST_SENSE_ALLOW on 'external' ones);
+ * 2. either stunaddr or externip is set, so we know what to use as the
+ * externally visible address;
+ * 3. the remote address, 'them', is external;
+ * 4. the address returned by ast_ouraddrfor() is 'internal' (AST_SENSE_DENY
+ * when passed to ast_apply_ha() so it does need to be remapped.
+ * This fourth condition is checked later.
*/
int want_remap = localaddr &&
(externip.sin_addr.s_addr || stunaddr.sin_addr.s_addr) &&
ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW ;
- /* localaddr contains 'internal' addresses marked as 'deny',
- * so 'external' addresses will return AST_SENSE_ALLOW.
- * In the following, we check if we need to remap the system-supplied
- * address to an externally visible one, and use some appropriate
- * mechanism to do that.
- */
-
- *us = internip; /* start from something reasonable */
- /* Start from the address that the system would use */
+ *us = internip; /* starting guess for the internal address */
+ /* now ask the system what would it use to talk to 'them' */
ast_ouraddrfor(them, &us->sin_addr);
theirs.sin_addr = *them;
- if (want_remap
- && (!global_matchexterniplocally || !ast_apply_ha(localaddr, us)) /* we want to remap */
- ) {
+ if (want_remap &&
+ (!global_matchexterniplocally || !ast_apply_ha(localaddr, us)) ) {
/* if we used externhost or stun, see if it is time to refresh the info */
if (externexpire && time(NULL) >= externexpire) {
if (stunaddr.sin_addr.s_addr) {
ast_stun_request(sipsock, &stunaddr, NULL, &externip);
- ast_log(LOG_WARNING, "stun(2) sees us at %s:%d\n",
- ast_inet_ntoa(externip.sin_addr) , ntohs(externip.sin_port));
} else {
if (ast_parse_arg(externhost, PARSE_INADDR, &externip))
ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
@@ -2254,9 +2251,7 @@
ast_debug(1, "Target address %s is not local, substituting externip\n",
ast_inet_ntoa(*(struct in_addr *)&them->s_addr));
} else if (bindaddr.sin_addr.s_addr) {
- /* remapping is not allowed, but we bind to
- * a specific address, so use it.
- */
+ /* no remapping, but we bind to a specific address, so use it. */
*us = bindaddr;
}
}
@@ -4925,8 +4920,9 @@
if (intended_method != SIP_OPTIONS) /* Peerpoke has it's own system */
p->timer_t1 = SIP_TIMER_T1; /* Default SIP retransmission timer T1 (RFC 3261) */
- p->ourip = internip;
- if (sin) {
+ if (!sin)
+ p->ourip = internip;
+ else {
p->sa = *sin;
ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip);
}
@@ -6612,8 +6608,9 @@
/* Initialize the bare minimum */
p->method = intended_method;
- p->ourip = internip;
- if (sin) {
+ if (!sin)
+ p->ourip = internip;
+ else {
p->sa = *sin;
ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip);
}
More information about the svn-commits
mailing list