Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."


Today's Topics:

   1. [PATCH] PacRunner:Domains are looked up to match the host
      (Atul Anand)
   2. Re: [PATCH] PacRunner:Domains are looked up to match the host
      (David Woodhouse)
   3. Re: [PATCH] PacRunner:Domains are looked up to match the host
      (Tomasz Bursztyka)


----------------------------------------------------------------------

Message: 1
Date: Mon,  6 Jun 2016 16:49:29 +0530
From: Atul Anand <[email protected]>
To: [email protected]
Cc: [email protected],        Atul Anand <[email protected]>
Subject: [PATCH] PacRunner:Domains are looked up to match the host
Message-ID: <[email protected]>

---

Hi, we have been working to put up a generic proxy mechanism. PacRunner comes 
in central role to which NM/ConnMan will be feeding proxy details for each 
connection along with domains for which that connection holds. Patch here fixes 
the answering mechanism to scan the domains and select the appropriate proxy 
config. It has been created with discussions and suggestions from David 
Woodhouse Sir. Thanks!

 
 pacrunner/src/manager.c   |   7 ++-
 pacrunner/src/pacrunner.h |   2 +
 pacrunner/src/proxy.c     | 126 ++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 126 insertions(+), 9 deletions(-)

diff --git a/pacrunner/src/manager.c b/pacrunner/src/manager.c
index 1676466..e194358 100644
--- a/pacrunner/src/manager.c
+++ b/pacrunner/src/manager.c
@@ -35,7 +35,6 @@ struct proxy_config {
        DBusConnection *conn;
        guint watch;
 
-       char **domains;
        char **nameservers;
 
        struct pacrunner_proxy *proxy;
@@ -58,7 +57,6 @@ static void destroy_config(gpointer data)
        if (config->watch > 0)
                g_dbus_remove_watch(config->conn, config->watch);
 
-       g_strfreev(config->domains);
        g_strfreev(config->nameservers);
 
        g_free(config->sender);
@@ -224,12 +222,13 @@ static DBusMessage *create_proxy_config(DBusConnection 
*conn,
                goto done;
        }
 
-       config->domains = domains;
        config->nameservers = nameservers;
 
-       domains = NULL;
        nameservers = NULL;
 
+       if (pacrunner_proxy_set_domains (config->proxy, domains) < 0)
+               pacrunner_error("Failed to set proxy domains");
+
        if (g_str_equal(method, "direct")) {
                if (pacrunner_proxy_set_direct(config->proxy) < 0)
                        pacrunner_error("Failed to set direct proxy");
diff --git a/pacrunner/src/pacrunner.h b/pacrunner/src/pacrunner.h
index 6731d7c..25e5349 100644
--- a/pacrunner/src/pacrunner.h
+++ b/pacrunner/src/pacrunner.h
@@ -63,6 +63,8 @@ void pacrunner_proxy_unref(struct pacrunner_proxy *proxy);
 const char *pacrunner_proxy_get_interface(struct pacrunner_proxy *proxy);
 const char *pacrunner_proxy_get_script(struct pacrunner_proxy *proxy);
 
+int pacrunner_proxy_set_domains (struct pacrunner_proxy *proxy,
+                                       char **domains);
 int pacrunner_proxy_set_direct(struct pacrunner_proxy *proxy);
 int pacrunner_proxy_set_manual(struct pacrunner_proxy *proxy,
                                        char **servers, char **excludes);
diff --git a/pacrunner/src/proxy.c b/pacrunner/src/proxy.c
index 8bb03af..493a0e6 100644
--- a/pacrunner/src/proxy.c
+++ b/pacrunner/src/proxy.c
@@ -23,6 +23,9 @@
 #include <config.h>
 #endif
 
+#include <string.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
 #include <errno.h>
 #include <pthread.h>
 
@@ -37,6 +40,17 @@ struct pacrunner_proxy {
        char *script;
        GList **servers;
        GList **excludes;
+       GPtrArray *domains;
+};
+
+struct Domain {
+       char *domain;
+       int proto;
+       union {
+               struct in_addr ip4_addr;
+               struct in6_addr ip6_addr;
+       } addr;
+       int mask;
 };
 
 static GList *proxy_list = NULL;
@@ -130,6 +144,90 @@ const char *pacrunner_proxy_get_script(struct 
pacrunner_proxy *proxy)
        return proxy->script;
 }
 
+static gboolean pacrunner_cmp_host_domain (struct in_addr *ip4_addr, struct 
in6_addr *ip6_addr,
+                                                                               
const char * host, struct Domain *data)
+{
+       int i, shift;
+       uint32_t mask4;
+
+       if (host) {
+               if (data->proto != 0)
+                       return FALSE;
+               if (g_str_has_suffix (host, data->domain)) {
+                       size_t hlen = strlen (host);
+                       size_t dlen = strlen (data->domain);
+
+                       if (hlen == dlen || host[hlen - dlen -1] == '.')
+                               return TRUE;
+               }
+       } else {
+               if (ip4_addr->s_addr) {
+                       if (data->proto != 4)
+                               return FALSE;
+
+                       mask4 = htonl(~(~(uint32_t)(0) >> data->mask));
+                       if ((ip4_addr->s_addr & mask4) == 
(data->addr.ip4_addr.s_addr & mask4))
+                               return TRUE;
+               } else {
+                       if (data->proto != 6)
+                               return FALSE;
+
+                       for (i = 0; i < (data->mask)/8; i++)
+                               if (ip6_addr->s6_addr[i] != 
data->addr.ip6_addr.s6_addr[i])
+                                       return FALSE;
+
+                       if ((data->mask) % 8) { 
+                               /* 1-7 bits left to compare */
+                               shift = 8 - (data->mask - (i*8));
+                               if ((ip6_addr->s6_addr[i] >> shift) == 
(data->addr.ip6_addr.s6_addr[i] >> shift))
+                                       return TRUE;
+                       } else
+                               return TRUE;
+               }
+       }
+       return FALSE;
+}
+
+int pacrunner_proxy_set_domains (struct pacrunner_proxy *proxy, char **domains)
+{
+       int len;
+       char **domain;
+       char ip[INET6_ADDRSTRLEN + 1];
+
+       DBG("proxy %p domains %p", proxy, domains);
+
+       if (!proxy)
+               return -EINVAL;
+
+       if (!domains)
+               return -EINVAL;
+
+       for (domain = (char **)domains; *domain; domain++) {
+               struct Domain data;
+               if (strchr (*domain, '/')) {
+                       len = strlen (*domain) - strlen (strchr (*domain, '/'));
+                       strncpy (ip, *domain, len);
+                       ip[len] = '\0';
+                       if (inet_pton (AF_INET, ip, &data.addr.ip4_addr) == 1) {
+                               data.domain = NULL;
+                               data.proto = 4;
+                               data.mask = atoi (strchr (*domain, '/') + 1);
+                               g_ptr_array_add (proxy->domains, &data);
+                       } else if (inet_pton (AF_INET6, ip, 
&data.addr.ip6_addr) == 1) {
+                               data.domain = NULL;
+                               data.proto = 6;
+                               data.mask = atoi (strchr (*domain, '/') + 1);
+                               g_ptr_array_add (proxy->domains, &data);
+                       }
+               } else {
+                       data.domain = g_strdup (*domain);
+                       data.proto = 0;
+                       g_ptr_array_add (proxy->domains, &data);
+               }
+       }
+       return 0;
+}
+
 static int set_method(struct pacrunner_proxy *proxy,
                                        enum pacrunner_proxy_method method)
 {
@@ -326,7 +424,11 @@ int pacrunner_proxy_disable(struct pacrunner_proxy *proxy)
 
 char *pacrunner_proxy_lookup(const char *url, const char *host)
 {
+       int i;
+       char *str = NULL;
        GList *list;
+       struct in_addr ip4_addr;
+       struct in6_addr ip6_addr;
        struct pacrunner_proxy *selected_proxy = NULL;
 
        DBG("url %s host %s", url, host);
@@ -340,17 +442,31 @@ char *pacrunner_proxy_lookup(const char *url, const char 
*host)
                return NULL;
        }
 
+       if (inet_pton (AF_INET, host, &ip4_addr) < 1) {
+               ip4_addr.s_addr = 0;
+               if (inet_pton (AF_INET6, host, &ip6_addr) < 1) {
+                       str = g_strdup (host);
+               }
+       }
+
        for (list = g_list_first(proxy_list); list; list = g_list_next(list)) {
                struct pacrunner_proxy *proxy = list->data;
 
-               if (proxy->method == PACRUNNER_PROXY_METHOD_MANUAL ||
-                               proxy->method == PACRUNNER_PROXY_METHOD_AUTO) {
-                       selected_proxy = proxy;
-                       break;
-               } else if (proxy->method == PACRUNNER_PROXY_METHOD_DIRECT)
+               if (proxy->domains) {
+                       for (i = 0; proxy->domains->len; i++) {
+                               struct Domain *data;
+                               data = g_ptr_array_index (proxy->domains, i);
+                               if (pacrunner_cmp_host_domain (&ip4_addr, 
&ip6_addr, str, data)) {
+                                       DBG ("Host matched");
+                                       selected_proxy = proxy;
+                                       goto found;
+                               }
+                       }
+               } else
                        selected_proxy = proxy;
        }
 
+found:
        pthread_mutex_unlock(&proxy_mutex);
 
        if (!selected_proxy)
-- 
2.5.5



------------------------------

Message: 2
Date: Mon, 06 Jun 2016 12:49:22 +0100
From: David Woodhouse <[email protected]>
To: Atul Anand <[email protected]>, [email protected]
Subject: Re: [PATCH] PacRunner:Domains are looked up to match the host
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

On Mon, 2016-06-06 at 16:49 +0530, Atul Anand wrote:
> ---
> 
> Hi, we have been working to put up a generic proxy mechanism.
> PacRunner comes in central role to which NM/ConnMan will be feeding
> proxy details for each connection along with domains for which that
> connection holds. Patch here fixes the answering mechanism to scan
> the domains and select the appropriate proxy config. It has been
> created with discussions and suggestions from David Woodhouse Sir.
> Thanks!

...

> +static gboolean pacrunner_cmp_host_domain (struct in_addr *ip4_addr, struct 
> in6_addr *ip6_addr,
> +                                                                             
> const char * host, struct Domain *data)
> +{
> +     int i, shift;
> +     uint32_t mask4;
> +
> +     if (host) {
> +             if (data->proto != 0)
> +                     return FALSE;
> +             if (g_str_has_suffix (host, data->domain)) {
> +                     size_t hlen = strlen (host);
> +                     size_t dlen = strlen (data->domain);
> +
> +                     if (hlen == dlen || host[hlen - dlen -1] == '.')
> +                             return TRUE;

Hm, I've just noticed the handling of 'excludes' in manual.c. Perhaps
the 'excludes' should be handled generically (why in $DEITY's name were
they not *already* working for PAC lookups as well as manual?) and the
'domains' (which we could think of as 'includes') should use the same
matching?

Perhaps 'excludes' should permit IP subnets too??

> +             }
> +     } else {
> +             if (ip4_addr->s_addr) {
> +                     if (data->proto != 4)
> +                             return FALSE;
> +
> +                     mask4 = htonl(~(~(uint32_t)(0) >> data->mask));
> +                     if ((ip4_addr->s_addr & mask4) == 
> (data->addr.ip4_addr.s_addr & mask4))
> +                             return TRUE;
> +             } else {
> +                     if (data->proto != 6)
> +                             return FALSE;
> +
> +                     for (i = 0; i < (data->mask)/8; i++)
> +                             if (ip6_addr->s6_addr[i] != 
> data->addr.ip6_addr.s6_addr[i])
> +                                     return FALSE;
> +
> +                     if ((data->mask) % 8) { 
> +                             /* 1-7 bits left to compare */
> +                             shift = 8 - (data->mask - (i*8));
> +                             if ((ip6_addr->s6_addr[i] >> shift) == 
> (data->addr.ip6_addr.s6_addr[i] >> shift))
> +                                     return TRUE;
> +                     } else
> +                             return TRUE;
> +             }

I'm still vaguely unhappy at pacrunner_cmp_host_domain() having three
completely *different* code paths which the caller *knows* are going to
act differently because it passes only one of the three
ip4_addr/ip6_addr/host arguments. Why not three separate functions?


> +     }
> +     return FALSE;
> +}
> +int pacrunner_proxy_set_domains (struct pacrunner_proxy *proxy, char 
> **domains)
> +{
> +     int len;
> +     char **domain;
> +     char ip[INET6_ADDRSTRLEN + 1];

Fixed-size strings like this always make me *expect* problems. It's
kind of tolerable here because OK if a string is too long to be a valid
IPv6 address then we don't need to bother with the inet_pton() bit...
but still, warning bells are ringing as I get to this line...

> +
> +     DBG("proxy %p domains %p", proxy, domains);
> +
> +     if (!proxy)
> +             return -EINVAL;
> +
> +     if (!domains)
> +             return -EINVAL;
> +
> +     for (domain = (char **)domains; *domain; domain++) {
> +             struct Domain data;
> +             if (strchr (*domain, '/')) {
> +                     len = strlen (*domain) - strlen (strchr (*domain, '/'));
> +                     strncpy (ip, *domain, len);

...and here we are. You didn't *check* that the string (up to the '/')
was small enough to fit into the 'ip' buffer, before you copied it.

And you still aren't handling the fact that IPv6 literals may appear
inside [] ? e.g. host == "[2001:8b0:10b:5::1]".

> +                     ip[len] = '\0';
> +                     if (inet_pton (AF_INET, ip, &data.addr.ip4_addr) == 1) {
> +                             data.domain = NULL;
> +                             data.proto = 4;
> +                             data.mask = atoi (strchr (*domain, '/') + 1);
> +                             g_ptr_array_add (proxy->domains, &data);
> +                     } else if (inet_pton (AF_INET6, ip, 
> &data.addr.ip6_addr) == 1) {
> +                             data.domain = NULL;
> +                             data.proto = 6;
> +                             data.mask = atoi (strchr (*domain, '/') + 1);
> +                             g_ptr_array_add (proxy->domains, &data);
> +                     }
> +             } else {
> +                     data.domain = g_strdup (*domain);
> +                     data.proto = 0;
> +                     g_ptr_array_add (proxy->domains, &data);
> +             }
> +     }
> +     return 0;
> +}
> +
> ?static int set_method(struct pacrunner_proxy *proxy,
> ?                                     enum pacrunner_proxy_method method)
> ?{
> @@ -326,7 +424,11 @@ int pacrunner_proxy_disable(struct pacrunner_proxy 
> *proxy)
> ?
> ?char *pacrunner_proxy_lookup(const char *url, const char *host)
> ?{
> +     int i;
> +     char *str = NULL;
> ?     GList *list;
> +     struct in_addr ip4_addr;
> +     struct in6_addr ip6_addr;
> ?     struct pacrunner_proxy *selected_proxy = NULL;
> ?
> ?     DBG("url %s host %s", url, host);
> @@ -340,17 +442,31 @@ char *pacrunner_proxy_lookup(const char *url, const 
> char *host)
> ?             return NULL;
> ?     }
> ?
> +     if (inet_pton (AF_INET, host, &ip4_addr) < 1) {
> +             ip4_addr.s_addr = 0;
> +             if (inet_pton (AF_INET6, host, &ip6_addr) < 1) {
> +                     str = g_strdup (host);

Do you ever free this? And why do you need to strdup it anyway? At this
point, couldn't you just set 'host = NULL' since you're never going to
use it again in the function? Or better still, if you've split
pacrunner_cmp_host_domain() into three functions, you only ever call
the *string* matching function neither ip4_addr nor ip6_addr are set.


> +             }
> +     }
> +
> ?     for (list = g_list_first(proxy_list); list; list = g_list_next(list)) {
> ?             struct pacrunner_proxy *proxy = list->data;
> ?
> -             if (proxy->method == PACRUNNER_PROXY_METHOD_MANUAL ||
> -                             proxy->method == PACRUNNER_PROXY_METHOD_AUTO) {
> -                     selected_proxy = proxy;
> -                     break;
> -             } else if (proxy->method == PACRUNNER_PROXY_METHOD_DIRECT)
> +             if (proxy->domains) {
> +                     for (i = 0; proxy->domains->len; i++) {
> +                             struct Domain *data;
> +                             data = g_ptr_array_index (proxy->domains, i);
> +                             if (pacrunner_cmp_host_domain (&ip4_addr, 
> &ip6_addr, str, data)) {
> +                                     DBG ("Host matched");
> +                                     selected_proxy = proxy;
> +                                     goto found;
> +                             }
> +                     }
> +             } else
> ?                     selected_proxy = proxy;

Hm, do we need to think about prioritisation? What if you have a
'catch-all' proxy first in the list, and then a more specific proxy
which is next, and *does* match the request? You're going to use the
catch-all proxy, which is probably wrong?

At the very least does the (!proxy->domains) case need to set a
'default_proxy' variable, which only gets used at the end if no more
specific match is found?

-- 
dwmw2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5760 bytes
Desc: not available
URL: 
<http://lists.01.org/pipermail/connman/attachments/20160606/77c5d217/attachment-0001.bin>

------------------------------

Message: 3
Date: Mon, 6 Jun 2016 14:04:12 +0200
From: Tomasz Bursztyka <[email protected]>
To: [email protected]
Subject: Re: [PATCH] PacRunner:Domains are looked up to match the host
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

Hi  Atul,

See my comments below

> ---
>
> Hi, we have been working to put up a generic proxy mechanism. PacRunner comes 
> in central role to which NM/ConnMan will be feeding proxy details for each 
> connection along with domains for which that connection holds. Patch here 
> fixes the answering mechanism to scan the domains and select the appropriate 
> proxy config. It has been created with discussions and suggestions from David 
> Woodhouse Sir. Thanks!
>
>   
>   pacrunner/src/manager.c   |   7 ++-
>   pacrunner/src/pacrunner.h |   2 +
>   pacrunner/src/proxy.c     | 126 
> ++++++++++++++++++++++++++++++++++++++++++++--
>   3 files changed, 126 insertions(+), 9 deletions(-)
>
> diff --git a/pacrunner/src/manager.c b/pacrunner/src/manager.c
> index 1676466..e194358 100644
> --- a/pacrunner/src/manager.c
> +++ b/pacrunner/src/manager.c
> @@ -35,7 +35,6 @@ struct proxy_config {
>       DBusConnection *conn;
>       guint watch;
>   
> -     char **domains;
>       char **nameservers;
>   
>       struct pacrunner_proxy *proxy;
> @@ -58,7 +57,6 @@ static void destroy_config(gpointer data)
>       if (config->watch > 0)
>               g_dbus_remove_watch(config->conn, config->watch);
>   
> -     g_strfreev(config->domains);
>       g_strfreev(config->nameservers);
>   
>       g_free(config->sender);
> @@ -224,12 +222,13 @@ static DBusMessage *create_proxy_config(DBusConnection 
> *conn,
>               goto done;
>       }
>   
> -     config->domains = domains;
>       config->nameservers = nameservers;
>   
> -     domains = NULL;
>       nameservers = NULL;
>   
> +     if (pacrunner_proxy_set_domains (config->proxy, domains) < 0)
> +             pacrunner_error("Failed to set proxy domains");
> +
>       if (g_str_equal(method, "direct")) {
>               if (pacrunner_proxy_set_direct(config->proxy) < 0)
>                       pacrunner_error("Failed to set direct proxy");
> diff --git a/pacrunner/src/pacrunner.h b/pacrunner/src/pacrunner.h
> index 6731d7c..25e5349 100644
> --- a/pacrunner/src/pacrunner.h
> +++ b/pacrunner/src/pacrunner.h
> @@ -63,6 +63,8 @@ void pacrunner_proxy_unref(struct pacrunner_proxy *proxy);
>   const char *pacrunner_proxy_get_interface(struct pacrunner_proxy *proxy);
>   const char *pacrunner_proxy_get_script(struct pacrunner_proxy *proxy);
>   
> +int pacrunner_proxy_set_domains (struct pacrunner_proxy *proxy,
> +                                     char **domains);
>   int pacrunner_proxy_set_direct(struct pacrunner_proxy *proxy);
>   int pacrunner_proxy_set_manual(struct pacrunner_proxy *proxy,
>                                       char **servers, char **excludes);
> diff --git a/pacrunner/src/proxy.c b/pacrunner/src/proxy.c
> index 8bb03af..493a0e6 100644
> --- a/pacrunner/src/proxy.c
> +++ b/pacrunner/src/proxy.c
> @@ -23,6 +23,9 @@
>   #include <config.h>
>   #endif
>   
> +#include <string.h>
> +#include <stdlib.h>
> +#include <arpa/inet.h>
>   #include <errno.h>
>   #include <pthread.h>
>   
> @@ -37,6 +40,17 @@ struct pacrunner_proxy {
>       char *script;
>       GList **servers;
>       GList **excludes;
> +     GPtrArray *domains;

Keep using a GList please.
Change your code relevantly

> +};
> +
> +struct Domain {
> +     char *domain;
> +     int proto;
> +     union {
> +             struct in_addr ip4_addr;
> +             struct in6_addr ip6_addr;

You could shorten these to ip4 and ip6, since they are already part of a 
union named addr.

> +     } addr;
> +     int mask;
>   };
>   
>   static GList *proxy_list = NULL;
> @@ -130,6 +144,90 @@ const char *pacrunner_proxy_get_script(struct 
> pacrunner_proxy *proxy)
>       return proxy->script;
>   }
>   
> +static gboolean pacrunner_cmp_host_domain (struct in_addr *ip4_addr, struct 
> in6_addr *ip6_addr,
> +                                                                             
> const char * host, struct Domain *data)

80 chars limit.

> +{
> +     int i, shift;
> +     uint32_t mask4;
> +
> +     if (host) {
> +             if (data->proto != 0)
> +                     return FALSE;
> +             if (g_str_has_suffix (host, data->domain)) {
> +                     size_t hlen = strlen (host);
> +                     size_t dlen = strlen (data->domain);
> +
> +                     if (hlen == dlen || host[hlen - dlen -1] == '.')
> +                             return TRUE;
> +             }

return false; here

Then no need of the below else statement. It will avoid to get too much 
if () { if () { for () {} }} imbrication.
> +     } else {
> +             if (ip4_addr->s_addr) {
> +                     if (data->proto != 4)
> +                             return FALSE;
> +
> +                     mask4 = htonl(~(~(uint32_t)(0) >> data->mask));
> +                     if ((ip4_addr->s_addr & mask4) == 
> (data->addr.ip4_addr.s_addr & mask4))
> +                             return TRUE;

Isn't there helpers to do the same, in netinet/in.h ?

> +             } else {
> +                     if (data->proto != 6)
> +                             return FALSE;
> +
Change this:

> +                     for (i = 0; i < (data->mask)/8; i++)
> +                             if (ip6_addr->s6_addr[i] != 
> data->addr.ip6_addr.s6_addr[i])
> +                                     return FALSE;

Same about generic helpers for comparing ipv6 addresses?

> +
> +                     if ((data->mask) % 8) { 
> +                             /* 1-7 bits left to compare */
> +                             shift = 8 - (data->mask - (i*8));
> +                             if ((ip6_addr->s6_addr[i] >> shift) == 
> (data->addr.ip6_addr.s6_addr[i] >> shift))

80 chars limit

And same about existing helpers I guess?

> +                                     return TRUE;
> +                     } else
> +                             return TRUE;
> +             }
> +     }
> +     return FALSE;
> +}
> +
> +int pacrunner_proxy_set_domains (struct pacrunner_proxy *proxy, char 
> **domains)
> +{
> +     int len;
> +     char **domain;
> +     char ip[INET6_ADDRSTRLEN + 1];
> +
> +     DBG("proxy %p domains %p", proxy, domains);
> +
> +     if (!proxy)
> +             return -EINVAL;
> +
> +     if (!domains)
> +             return -EINVAL;
> +
> +     for (domain = (char **)domains; *domain; domain++) {
> +             struct Domain data;

Give some space to the code, add a newline

> +             if (strchr (*domain, '/')) {
> +                     len = strlen (*domain) - strlen (strchr (*domain, '/'));
> +                     strncpy (ip, *domain, len);
> +                     ip[len] = '\0';
same
> +                     if (inet_pton (AF_INET, ip, &data.addr.ip4_addr) == 1) {
> +                             data.domain = NULL;
> +                             data.proto = 4;
> +                             data.mask = atoi (strchr (*domain, '/') + 1);
same
> +                             g_ptr_array_add (proxy->domains, &data);
> +                     } else if (inet_pton (AF_INET6, ip, 
> &data.addr.ip6_addr) == 1) {
> +                             data.domain = NULL;
> +                             data.proto = 6;
> +                             data.mask = atoi (strchr (*domain, '/') + 1);
same
> +                             g_ptr_array_add (proxy->domains, &data);
> +                     }
> +             } else {
> +                     data.domain = g_strdup (*domain);
> +                     data.proto = 0;
> +                     g_ptr_array_add (proxy->domains, &data);
> +             }
> +     }
same
> +     return 0;
> +}
> +

So you have a way to add domains to a proxy, and where do you remove them?
Looks like to me you are never freeing the memory you used for the 
proxy->domains

>   static int set_method(struct pacrunner_proxy *proxy,
>                                       enum pacrunner_proxy_method method)
>   {
> @@ -326,7 +424,11 @@ int pacrunner_proxy_disable(struct pacrunner_proxy 
> *proxy)
>   
>   char *pacrunner_proxy_lookup(const char *url, const char *host)
>   {
> +     int i;
> +     char *str = NULL;
>       GList *list;
> +     struct in_addr ip4_addr;
> +     struct in6_addr ip6_addr;
>       struct pacrunner_proxy *selected_proxy = NULL;
>   
>       DBG("url %s host %s", url, host);
> @@ -340,17 +442,31 @@ char *pacrunner_proxy_lookup(const char *url, const 
> char *host)
>               return NULL;
>       }
>   
> +     if (inet_pton (AF_INET, host, &ip4_addr) < 1) {
> +             ip4_addr.s_addr = 0;
> +             if (inet_pton (AF_INET6, host, &ip6_addr) < 1) {
> +                     str = g_strdup (host);

Which str you never free anywhere. Be sure you are memory leak safe. Run 
the code through valgrind.

> +             }
> +     }

No spaces after a function name and its parenthesis

> +
>       for (list = g_list_first(proxy_list); list; list = g_list_next(list)) {
>               struct pacrunner_proxy *proxy = list->data;
>   
> -             if (proxy->method == PACRUNNER_PROXY_METHOD_MANUAL ||
> -                             proxy->method == PACRUNNER_PROXY_METHOD_AUTO) {
> -                     selected_proxy = proxy;
> -                     break;
> -             } else if (proxy->method == PACRUNNER_PROXY_METHOD_DIRECT)
> +             if (proxy->domains) {
> +                     for (i = 0; proxy->domains->len; i++) {
> +                             struct Domain *data;
new line
> +                             data = g_ptr_array_index (proxy->domains, i);
> +                             if (pacrunner_cmp_host_domain (&ip4_addr, 
> &ip6_addr, str, data)) {
> +                                     DBG ("Host matched");
> +                                     selected_proxy = proxy;
> +                                     goto found;
> +                             }
> +                     }
> +             } else
>                       selected_proxy = proxy;
>       }
>   
> +found:
>       pthread_mutex_unlock(&proxy_mutex);
>   
>       if (!selected_proxy)

Tomasz


------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 8, Issue 6
*************************************

Reply via email to