]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Merged revisions 315894 via svnmerge from
authorMatthew Nicholson <mnicholson@digium.com>
Wed, 27 Apr 2011 19:15:49 +0000 (19:15 +0000)
committerMatthew Nicholson <mnicholson@digium.com>
Wed, 27 Apr 2011 19:15:49 +0000 (19:15 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
  r315894 | mnicholson | 2011-04-27 14:14:27 -0500 (Wed, 27 Apr 2011) | 28 lines

  Merged revisions 315893 via svnmerge from
  https://origsvn.digium.com/svn/asterisk/branches/1.6.2

  ................
    r315893 | mnicholson | 2011-04-27 14:03:05 -0500 (Wed, 27 Apr 2011) | 21 lines

    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)
    ........
  ................
................

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@315895 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c
channels/sip/reqresp_parser.c

index ba96ffec510a75ca05ae43fe2380018703bbbc3a..473cdce6ff51f04c586d6bd5229b6ecf6c6212c5 100644 (file)
@@ -7438,6 +7438,21 @@ struct sip_pvt *sip_alloc(ast_string_field callid, struct ast_sockaddr *addr,
        return p;
 }
 
+/*!
+ * \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"));
@@ -7455,17 +7470,13 @@ static int process_via(struct sip_pvt *p, const struct sip_request *req)
                        return -1;
                }
 
-               if (via->port) {
-                       ast_sockaddr_set_port(&p->sa, via->port);
-               } else {
-                       ast_sockaddr_set_port(&p->sa, STANDARD_SIP_PORT);
-               }
-
                if (ast_sockaddr_is_ipv4_multicast(&p->sa)) {
                        setsockopt(sipsock, IPPROTO_IP, IP_MULTICAST_TTL, &via->ttl, sizeof(via->ttl));
                }
        }
 
+       ast_sockaddr_set_port(&p->sa, via->port ? via->port : STANDARD_SIP_PORT);
+
        free_via(via);
        return 0;
 }
@@ -10012,6 +10023,9 @@ static int respprep(struct sip_request *resp, struct sip_pvt *p, const char *msg
 
        /* 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;
 
index 594bcfad95f347e69b4357bbf7d5a96dff2c453c..9edf5bd451b63f82f2178a094d0a631762590f1e 100644 (file)
@@ -2253,10 +2253,7 @@ void free_via(struct sip_via *v)
                return;
        }
 
-       if (v->via) {
-               ast_free(v->via);
-       }
-
+       ast_free(v->via);
        ast_free(v);
 }