[asterisk-commits] mnicholson: branch 1.6.2 r315893 - in /branches/1.6.2: ./ channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 27 14:03:15 CDT 2011


Author: mnicholson
Date: Wed Apr 27 14:03:05 2011
New Revision: 315893

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=315893
Log:
Merged revisions 315891 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
  r315891 | mnicholson | 2011-04-27 13:57:56 -0500 (Wed, 27 Apr 2011) | 14 lines
  
  Fix our compliance with RFC 3261 section 18.2.2.
  
  This change optimizes the free_via() function and removes some redundant null
  checking. It also fixes compliance with RFC 3261 section 18.2.2 by always using
  the port specified in the Via header for routing responses (even when maddr is
  not set). Also the htons() function is now used when setting the port.
  Additional documentation comments have been added in various places to make the
  logic in the code clearer.
  
  (closes issue #18951)
  Reported by: jmls
  Patches:
        issue18951_set_proper_port_from_via.patch uploaded by wdoekes (license 717) (modified)
........

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/channels/chan_sip.c

Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: branches/1.6.2/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/channels/chan_sip.c?view=diff&rev=315893&r1=315892&r2=315893
==============================================================================
--- branches/1.6.2/channels/chan_sip.c (original)
+++ branches/1.6.2/channels/chan_sip.c Wed Apr 27 14:03:05 2011
@@ -7549,10 +7549,7 @@
 		return;
 	}
 
-	if (v->via) {
-		ast_free(v->via);
-	}
-
+	ast_free(v->via);
 	ast_free(v);
 }
 
@@ -7675,6 +7672,21 @@
 	return ((ntohl(addr->s_addr) & 0xf0000000) == 0xe0000000);
 }
 
+/*!
+ * \brief Process the Via header according to RFC 3261 section 18.2.2.
+ * \param p a sip_pvt structure that will be modified according to the received
+ * header
+ * \param req a sip request with a Via header to process
+ *
+ * This function will update the destination of the response according to the
+ * Via header in the request and RFC 3261 section 18.2.2. We do not have a
+ * transport layer so we ignore certain values like the 'received' param (we
+ * set the destination address to the addres the request came from in the
+ * respprep() function).
+ *
+ * \retval -1 error
+ * \retval 0 success
+ */
 static int process_via(struct sip_pvt *p, const struct sip_request *req)
 {
 	struct sip_via *via = parse_via(get_header(req, "Via"));
@@ -7699,16 +7711,12 @@
 		p->sa.sin_family = AF_INET;
 		memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr));
 
-		if (via->port) {
-			p->sa.sin_port = via->port;
-		} else {
-			p->sa.sin_port = STANDARD_SIP_PORT;
-		}
-
 		if (addr_is_multicast(&p->sa.sin_addr)) {
 			setsockopt(sipsock, IPPROTO_IP, IP_MULTICAST_TTL, &via->ttl, sizeof(via->ttl));
 		}
 	}
+
+	p->sa.sin_port = htons(via->port ? via->port : STANDARD_SIP_PORT);
 
 	free_via(via);
 	return 0;
@@ -9919,6 +9927,9 @@
 
 	/* default to routing the response to the address where the request
 	 * came from.  Since we don't have a transport layer, we do this here.
+	 * The process_via() function will update the port to either the port
+	 * specified in the via header or the default port later on (per RFC
+	 * 3261 section 18.2.2).
 	 */
 	p->sa = p->recv;
 




More information about the asterisk-commits mailing list