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. Re: [PATCH] [Pacrunner]: Domains are looked up to match host
      of URL. (David Woodhouse)
   2. Re: [PATCH] [Pacrunner]: Domains are looked up to match host
      of URL. (Patrik Flykt)
   3. Re: [PATCH] [Pacrunner]: Domains are looked up to match host
      of URL. (Atul Anand)
   4. Re: [PATCH] [Pacrunner]: Domains are looked up to match host
      of URL. (Atul Anand)


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

Message: 1
Date: Tue, 14 Jun 2016 22:56:57 +0100
From: David Woodhouse <[email protected]>
To: Patrik Flykt <[email protected]>, Atul Anand
        <[email protected]>,  [email protected]
Subject: Re: [PATCH] [Pacrunner]: Domains are looked up to match host
        of URL.
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

On Tue, 2016-06-14 at 16:28 +0300, Patrik Flykt wrote:
> > +static void proxy_domain_destroy(struct proxy_domain *domain)
?...
> > +
> > +   if (proxy->domains) {
> > +           g_list_free_full(proxy->domains,
> > +                           (GDestroyNotify) proxy_domain_destroy);
> 
> Please don't cast here, if needed do necessary casts in
> proxy_domain_destroy() instead.

Just to clarify that request:

static void proxy_domain_destroy(gpointer _domain)
{
        struct proxy_domain *domain = _domain;
... means that you no longer need the cast in the g_list_free_full()
invocation because proxy_domain_destroy() already has the correct type.

That isn't the idiom we see in most glib code, FWIW. But if that's what
you prefer then that's fine :)


> > +static int compare_host_in_domain(const char *host, struct proxy_domain 
> > *match)
> > +{
> > +   if (g_str_has_suffix(host, match->domain)) {
> 
> g_str_has_suffix() appears starting from glib 2.2. Currently only 2.16
> is required, so either do a string comparison for the last bytes or
> update glib requirement to >= 2.2. It is possible some embedded
> developers might still be upset with the latter, though.

Since we're already working out the length of both strings, it's hardly
difficult to turn this into a
        hlen >= dlen && strcmp(host + (dlen - hlen), domain);

> 
> > +           size_t hlen = strlen(host);
> > +           size_t dlen = strlen(match->domain);
> > +
> > +           if (hlen == dlen || host[hlen - dlen - 1] == '.')
> 
> Can the following happen: hlen("foo"), dlen("myverylongdomain") ->
> host[3 - 16 - 1] == host[-14] which is indexed outside the array?

That can't happen because the the suffix didn't match. The suffix can
only match if hlen >= dlen (which I've explicitly coded just above...)


> proxy_set_domains() above seems not to be able to handle an IPv6
> address written as [2002:dead:beef::1]. Should the host and the domains
> allow for the same formatting? AF_INET and AF_INET6 may look nicer to
> some eyes (but that may introduce unnecessary glitches in the code, so
> it can stay as is).

There's no need for it. An IPv6 literal in a URL should be encoded in
[] and we *expect* that form to be in the 'host' string. In fact it's
probably invalid for it *not* to have the []. But there's no reason for
the net/mask to have the []. They are different formats.

-- 
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
-------------- 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/20160614/af1bd00d/attachment-0001.bin>

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

Message: 2
Date: Wed, 15 Jun 2016 10:03:39 +0300
From: Patrik Flykt <[email protected]>
To: David Woodhouse <[email protected]>, Atul Anand
        <[email protected]>,  [email protected]
Subject: Re: [PATCH] [Pacrunner]: Domains are looked up to match host
        of URL.
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"

On Tue, 2016-06-14 at 22:56 +0100, David Woodhouse wrote:
> > > +???????????if (hlen == dlen || host[hlen - dlen - 1] == '.')
> >?
> > Can the following happen: hlen("foo"), dlen("myverylongdomain") ->
> > host[3 - 16 - 1] == host[-14] which is indexed outside the array?
> 
> That can't happen because the the suffix didn't match. The suffix can
> only match if hlen >= dlen (which I've explicitly coded just
> above...)

Yes, while driving to work I was thinking that this must have been the
case. And indeed it was. Case closed!

> > proxy_set_domains() above seems not to be able to handle an IPv6
> > address written as [2002:dead:beef::1]. Should the host and the
> domains
> > allow for the same formatting? AF_INET and AF_INET6 may look nicer
> to
> > some eyes (but that may introduce unnecessary glitches in the code,
> so
> > it can stay as is).
> 
> There's no need for it. An IPv6 literal in a URL should be encoded in
> [] and we *expect* that form to be in the 'host' string. In fact it's
> probably invalid for it *not* to have the []. But there's no reason
> for the net/mask to have the []. They are different formats.

Ok. Just document the net/mask or domain format properly. When doing
lookups, almost everything will eventually be supplied by programs so
let's have that as robust as possible.

Cheers,

        Patrik



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

Message: 3
Date: Wed, 15 Jun 2016 15:37:44 +0530
From: Atul Anand <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: David Woodhouse <[email protected]>, [email protected]
Subject: Re: [PATCH] [Pacrunner]: Domains are looked up to match host
        of URL.
Message-ID:
        <cabywktkwsnb-+qmfpqsjmb9khgofp2q+8zgmsjgx3xakzkx...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

>From 901b9e3891b0243c964ced6fdb4104ad44e195f5 Mon Sep 17 00:00:00 2001
From: Atul Anand <[email protected]>
Date: Tue, 14 Jun 2016 23:48:05 +0530
Subject: [PATCH 1/3] Docs edited to point out the usage of Domains

---
 doc/manager-api.txt | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index ab2f6b9..9e6209d 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -62,7 +62,10 @@ Methods        object CreateProxyConfiguration(dict settings)

             array{string} Domains [optional]

-                Domain names for which the URL is valid.
+                Domain names and IP range for which this proxy
+                configuration shall be valid. IP range should
+                be in CIDR format. eg:"192.168.1.0/12" for IPv4
+                and similarly for IPv6.

             array{string} Nameservers [optional]

-- 
2.5.5


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

Message: 4
Date: Wed, 15 Jun 2016 15:39:17 +0530
From: Atul Anand <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: David Woodhouse <[email protected]>, [email protected]
Subject: Re: [PATCH] [Pacrunner]: Domains are looked up to match host
        of URL.
Message-ID:
        <CABYWKt=ij9e3k1qmguyji63+x7e-s0oxvv9+akcumn5w-wk...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

>From f3daf3188e1e7748eec73570a66bc571e2978cce Mon Sep 17 00:00:00 2001
From: Atul Anand <[email protected]>
Date: Wed, 15 Jun 2016 10:20:38 +0530
Subject: [PATCH 2/3] unit: Tests added for proxy lookup using domains

---
 unit/suite/manual_basic.test   |  2 +
 unit/suite/manual_exclude.test |  2 +
 unit/suite/pac_basic.test      |  2 +
 unit/suite/pac_direct.test     |  2 +
 unit/suite/proxy_domain.test   | 37 ++++++++++++++++++
 unit/suite/stub.test           |  3 ++
 unit/test-pacrunner.c          | 86 ++++++++++++++++++++++++++++++++++++++++--
 7 files changed, 130 insertions(+), 4 deletions(-)
 create mode 100644 unit/suite/proxy_domain.test

diff --git a/unit/suite/manual_basic.test b/unit/suite/manual_basic.test
index a5ec3a1..4406d9c 100644
--- a/unit/suite/manual_basic.test
+++ b/unit/suite/manual_basic.test
@@ -10,6 +10,8 @@ socks4://sockproxy.internal.com

 [excludes]

+[domains]
+
 [config]
 VALID

diff --git a/unit/suite/manual_exclude.test b/unit/suite/manual_exclude.test
index c155743..211ae16 100644
--- a/unit/suite/manual_exclude.test
+++ b/unit/suite/manual_exclude.test
@@ -15,6 +15,8 @@ ftp://
 *net
 tri*

+[domains]
+
 [config]
 VALID

diff --git a/unit/suite/pac_basic.test b/unit/suite/pac_basic.test
index 58af200..c63757e 100644
--- a/unit/suite/pac_basic.test
+++ b/unit/suite/pac_basic.test
@@ -17,6 +17,8 @@ function FindProxyForURL(url, host)

 [excludes]

+[domains]
+
 [config]
 VALID

diff --git a/unit/suite/pac_direct.test b/unit/suite/pac_direct.test
index 3164872..b820abc 100644
--- a/unit/suite/pac_direct.test
+++ b/unit/suite/pac_direct.test
@@ -11,6 +11,8 @@ function FindProxyForURL(url, host)

 [excludes]

+[domains]
+
 [config]
 VALID

diff --git a/unit/suite/proxy_domain.test b/unit/suite/proxy_domain.test
new file mode 100644
index 0000000..8c2c5e4
--- /dev/null
+++ b/unit/suite/proxy_domain.test
@@ -0,0 +1,37 @@
+[title]
+Proxy Domain lookup
+
+[pac]
+
+[servers]
+http://proxy.suite.com
+
+[excludes]
+
+[domains]
+suite.com
+test.suite.com
+172.132.231.6/24
+
+[config]
+VALID
+
+[tests]
+http://foo.suite.com foo.suite.com
+PROXY proxy.suite.com
+http://172.132.231.101/search=?true 172.132.231.101
+PROXY proxy.suite.com
+http://111.121.131.141/page1 111.121.131.141
+DIRECT
+http://notintel.com notintel.com
+DIRECT
+http://intel.com intel.com
+PROXY proxy2.com; PROXY secproxy2.com
+https://bar.domain2.com bar.domain2.com
+PROXY secproxy2.com; PROXY proxy2.com
+http://192.168.4.4/index.html 192.168.4.4
+PROXY proxy2.com; PROXY secproxy2.com
+socks4://baz.domain3.com/xyz baz.domain3.com
+SOCKS4 sockproxy3.com; PROXY proxy3.com
+http://[fe80:96db:12ce::43ef]/ip6.mp4 [fe80:96db:12ce::43ef]
+PROXY proxy3.com; SOCKS4 sockproxy3.com
diff --git a/unit/suite/stub.test b/unit/suite/stub.test
index 12a0426..cde0aeb 100644
--- a/unit/suite/stub.test
+++ b/unit/suite/stub.test
@@ -11,6 +11,9 @@ Stub suite file
 [excludes]
 # If so, optional exlusion rules can be written here

+[domains]
+# List of domains are here
+
 [config]
 # Result of the configuration: VALID or INVALID

diff --git a/unit/test-pacrunner.c b/unit/test-pacrunner.c
index f234a35..0c4ac69 100644
--- a/unit/test-pacrunner.c
+++ b/unit/test-pacrunner.c
@@ -42,9 +42,10 @@ enum test_suite_part {
     SUITE_PAC      = 1,
     SUITE_SERVERS  = 2,
     SUITE_EXCLUDES = 3,
-    SUITE_CONFIG   = 4,
-    SUITE_TESTS    = 5,
-    SUITE_NOTHING  = 6,
+    SUITE_DOMAINS  = 4,
+    SUITE_CONFIG   = 5,
+    SUITE_TESTS    = 6,
+    SUITE_NOTHING  = 7,
 };

 enum cu_test_mode {
@@ -58,6 +59,7 @@ struct pacrunner_test_suite {
     gchar *pac;
     gchar **servers;
     gchar **excludes;
+    gchar **domains;

     bool config_result;

@@ -67,7 +69,7 @@ struct pacrunner_test_suite {
 static struct pacrunner_test_suite *test_suite;
 static bool verbose = false;

-static struct pacrunner_proxy *proxy;
+static struct pacrunner_proxy *proxy, *proxy2 = NULL, *proxy3 = NULL;
 static bool test_config;

 static void free_pacrunner_test_suite(struct pacrunner_test_suite *suite)
@@ -79,6 +81,7 @@ static void free_pacrunner_test_suite(struct
pacrunner_test_suite *suite)
     g_free(suite->pac);
     g_strfreev(suite->servers);
     g_strfreev(suite->excludes);
+    g_strfreev(suite->domains);
     g_strfreev(suite->tests);

     g_free(suite);
@@ -142,6 +145,13 @@ static void print_test_suite(struct
pacrunner_test_suite *suite)
     } else
         printf("(none)\n");

+    printf("\nDomains:\n");
+    if (suite->domains) {
+        for (line = suite->domains; *line; line++)
+            printf("%s\n", *line);
+    } else
+        printf("(none)\n");
+
     printf("\nConfig result: %s\n",
             suite->config_result ? "Valid" : "Invalid");

@@ -240,6 +250,15 @@ static struct pacrunner_test_suite
*read_test_suite(const char *path)
                 suite->excludes = array;

                 break;
+            case SUITE_DOMAINS:
+                array = _g_strappendv(suite->domains, *line);
+                if (!array)
+                    goto error;
+
+                g_free(suite->domains);
+                suite->domains = array;
+
+                break;
             case SUITE_CONFIG:
                 if (strncmp(*line, "VALID", 5) == 0)
                     suite->config_result = true;
@@ -272,6 +291,8 @@ static struct pacrunner_test_suite
*read_test_suite(const char *path)
             part = SUITE_SERVERS;
         else if (strncmp(*line, "[excludes]", 10) == 0)
             part = SUITE_EXCLUDES;
+        else if (strncmp(*line, "[domains]", 9) == 0)
+            part = SUITE_DOMAINS;
         else if (strncmp(*line, "[config]", 8) == 0)
             part = SUITE_CONFIG;
         else if (strncmp(*line, "[tests]", 7) == 0)
@@ -338,6 +359,54 @@ static void test_manual_config(void)
     CU_ASSERT_TRUE(test_suite->config_result == test_config);
 }

+static void test_proxy_domain(void)
+{
+    int val = 0;
+
+    if (pacrunner_proxy_set_domains(proxy, test_suite->domains) != 0)
+        val = -1;
+
+    proxy2 = pacrunner_proxy_create("eth1");
+    if (proxy2) {
+        char *servers[] = {
+            "http://proxy2.com";,
+            "https://secproxy2.com";,
+            NULL};
+        char *domains[] = {
+            "intel.com",
+            "domain2.com",
+            "192.168.4.0/16",
+            NULL};
+
+        if (pacrunner_proxy_set_manual(proxy2, servers, NULL) != 0)
+            val = -1;
+
+        if (pacrunner_proxy_set_domains(proxy2, domains) != 0)
+            val = -1;
+    }
+
+    proxy3 = pacrunner_proxy_create("wl0");
+    if (proxy3) {
+        char *servers[] = {
+            "http://proxy3.com";,
+            "socks4://sockproxy3.com",
+            NULL};
+        char *domains[] = {
+            "redhat.com",
+            "domain3.com",
+            "fe80:96db::/32",
+            NULL};
+
+        if (pacrunner_proxy_set_manual(proxy3, servers, NULL) != 0)
+            val = -1;
+
+        if (pacrunner_proxy_set_domains(proxy3, domains) != 0)
+            val = -1;
+    }
+
+    CU_ASSERT_TRUE(val == 0);
+}
+
 static void test_proxy_requests(void)
 {
     gchar **test_strings;
@@ -430,12 +499,21 @@ static void run_test_suite(const char
*test_file_path, enum cu_test_mode mode)
         CU_add_test(cu_suite, "Manual config test",
                         test_manual_config);

+    if (test_suite->domains)
+        CU_add_test(cu_suite, "Proxy domain test",
+                        test_proxy_domain);
+
     if (test_suite->config_result && test_suite->tests)
         CU_add_test(cu_suite, "Proxy requests test",
                         test_proxy_requests);

     test_config = false;

+    if (test_suite->domains) {
+        pacrunner_proxy_unref(proxy2);
+        pacrunner_proxy_unref(proxy3);
+    }
+
     switch (mode) {
     case CU_MODE_BASIC:
         CU_basic_set_mode(CU_BRM_VERBOSE);
-- 
2.5.5


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

Subject: Digest Footer

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


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

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

Reply via email to