]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Add the ability for ast_find_ourip to return IPv4, IPv6 or both.
authorPaul Belanger <paul.belanger@polybeacon.com>
Thu, 14 Oct 2010 15:15:12 +0000 (15:15 +0000)
committerPaul Belanger <paul.belanger@polybeacon.com>
Thu, 14 Oct 2010 15:15:12 +0000 (15:15 +0000)
While testing chan_gtalk I noticed jabber was using my IPv6 address
and not IPv4. When using bindaddr=0.0.0.0 it is possible for ast_find_ourip()
to return both IPv6 and IPv4 results.  Adding a family parameter gives you
the ablility to choose.

Since jabber/gtalk/h323 do not support IPv6, we should only return IPv4 results.

Review: https://reviewboard.asterisk.org/r/973/

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

channels/chan_gtalk.c
channels/chan_h323.c
channels/chan_jingle.c
channels/chan_sip.c
include/asterisk/acl.h
main/acl.c

index 326ea70359e3c0d7f63c38a49eaa8f8a2952ffa1..36ef90307d399a31a3eeed3421d05ea49ef2693f 100644 (file)
@@ -859,7 +859,7 @@ static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, ch
        ast_rtp_instance_get_local_address(p->rtp, &sin_tmp);
        ast_sockaddr_to_sin(&sin_tmp, &sin);
        ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
-       ast_find_ourip(&us, &bindaddr_tmp);
+       ast_find_ourip(&us, &bindaddr_tmp, AF_INET);
        if (!strcmp(ast_sockaddr_stringify_addr(&us), "127.0.0.1")) {
                ast_log(LOG_WARNING, "Found a loopback IP on the system, check your network configuration or set the bindaddr attribute.");
        }
@@ -2217,7 +2217,7 @@ static int load_module(void)
        }
 
        ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
-       if (ast_find_ourip(&ourip_tmp, &bindaddr_tmp)) {
+       if (ast_find_ourip(&ourip_tmp, &bindaddr_tmp, AF_INET)) {
                ast_log(LOG_WARNING, "Unable to get own IP address, Gtalk disabled\n");
                return 0;
        }
index 2362d9a49610d8f10f213099ea276e1c9dfa280c..89b452dbcf10fb042105b0431995bb5e325c21c6 100644 (file)
@@ -965,7 +965,7 @@ static int __oh323_rtp_create(struct oh323_pvt *pvt)
                struct ast_sockaddr tmp;
 
                ast_sockaddr_from_sin(&tmp, &bindaddr);
-               if (ast_find_ourip(&our_addr, &tmp)) {
+               if (ast_find_ourip(&our_addr, &tmp, AF_INET)) {
                        ast_mutex_unlock(&pvt->lock);
                        ast_log(LOG_ERROR, "Unable to locate local IP address for RTP stream\n");
                        return -1;
index 25b4d7e459d192a805423e06fba617d18ff8a88f..c12704835e46dbf33a44ee1a591fd5db1617e538 100644 (file)
@@ -623,7 +623,7 @@ static int jingle_create_candidates(struct jingle *client, struct jingle_pvt *p,
        ast_rtp_instance_get_local_address(p->rtp, &sin_tmp);
        ast_sockaddr_to_sin(&sin_tmp, &sin);
        ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
-       ast_find_ourip(&us_tmp, &bindaddr_tmp);
+       ast_find_ourip(&us_tmp, &bindaddr_tmp, AF_INET);
        us.s_addr = htonl(ast_sockaddr_ipv4(&us_tmp));
 
        /* Setup our first jingle candidate */
@@ -1904,15 +1904,17 @@ static int load_module(void)
        }
 
        sched = sched_context_create();
-       if (!sched) 
+       if (!sched) {
                ast_log(LOG_WARNING, "Unable to create schedule context\n");
+       }
 
        io = io_context_create();
-       if (!io) 
+       if (!io) {
                ast_log(LOG_WARNING, "Unable to create I/O context\n");
+       }
 
        ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
-       if (ast_find_ourip(&ourip_tmp, &bindaddr_tmp)) {
+       if (ast_find_ourip(&ourip_tmp, &bindaddr_tmp, AF_INET)) {
                ast_log(LOG_WARNING, "Unable to get own IP address, Jingle disabled\n");
                return 0;
        }
index 58e3f5c4f527e117144fe52e16e5ca91a7fbb519..302ca35a15432823658d5f3161a9ed0e79e0d108 100644 (file)
@@ -27086,7 +27086,7 @@ static int reload_config(enum channelreloadreason reason)
 
        /* Set UDP address and open socket */
        ast_sockaddr_copy(&internip, &bindaddr);
-       if (ast_find_ourip(&internip, &bindaddr)) {
+       if (ast_find_ourip(&internip, &bindaddr, 0)) {
                ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n");
                ast_config_destroy(cfg);
                return 0;
index a8c311cb25f316b6f35cf3baf135843c917940b6..86053f431c98d08c5bbed2cc95f731f998095144 100644 (file)
@@ -220,10 +220,12 @@ struct ast_ha *ast_duplicate_ha_list(struct ast_ha *original);
  * \param[out] ourip Our IP address is written here when it is found
  * \param bindaddr A hint used for finding our IP. See the steps above for
  * more details
+ * \param family Only addresses of the given family will be returned. Use 0
+ * or AST_SOCKADDR_UNSPEC to get addresses of all families.
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_find_ourip(struct ast_sockaddr *ourip, const struct ast_sockaddr *bindaddr);
+int ast_find_ourip(struct ast_sockaddr *ourip, const struct ast_sockaddr *bindaddr, int family);
 
 /*!
  * \brief Convert a string to the appropriate COS value
index 1ca0cc0bde4544bd9e5fd8af68630bc21465f06e..dcbc3a96599862b5196e0489568b8201ddeb1a34 100644 (file)
@@ -720,7 +720,7 @@ int ast_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us)
        return 0;
 }
 
-int ast_find_ourip(struct ast_sockaddr *ourip, const struct ast_sockaddr *bindaddr)
+int ast_find_ourip(struct ast_sockaddr *ourip, const struct ast_sockaddr *bindaddr, int family)
 {
        char ourhost[MAXHOSTNAMELEN] = "";
        struct ast_sockaddr root;
@@ -735,7 +735,7 @@ int ast_find_ourip(struct ast_sockaddr *ourip, const struct ast_sockaddr *bindad
        if (gethostname(ourhost, sizeof(ourhost) - 1)) {
                ast_log(LOG_WARNING, "Unable to get hostname\n");
        } else {
-               if (resolve_first(ourip, ourhost, PARSE_PORT_FORBID, 0) == 0) {
+               if (resolve_first(ourip, ourhost, PARSE_PORT_FORBID, family) == 0) {
                        return 0;
                }
        }