From 634d9504f07f6dec17bab76375e60c1a30ab12eb Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 31 May 2010 16:03:43 +0000 Subject: [PATCH] --- src/transport/plugin_transport_http.c | 39 +++++++++++++++++++--- src/transport/test_plugin_transport_http.c | 29 ++++++++++++++-- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 1b5f5ed11..8828e3438 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -1199,11 +1199,42 @@ static int http_plugin_address_suggested (void *cls, void *addr, size_t addrlen) { - /* struct Plugin *plugin = cls; */ + struct IPv4HttpAddress *v4; + struct IPv6HttpAddress *v6; - /* check if the address is plausible; if so, - add it to our list! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: http_plugin_address_suggested\n"); + if ((addrlen != sizeof (struct IPv4HttpAddress)) && + (addrlen != sizeof (struct IPv6HttpAddress))) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + if (addrlen == sizeof (struct IPv4HttpAddress)) + { + v4 = (struct IPv4HttpAddress *) addr; + + v4->u_port = ntohs (v4->u_port); + if (v4->u_port != plugin->port_inbound) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + } + else + { + v6 = (struct IPv6HttpAddress *) addr; + if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + v6->u6_port = ntohs (v6->u6_port); + if (v6->u6_port != plugin->port_inbound) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + + } return GNUNET_OK; } diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index 728ab7db3..9eb952348 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c @@ -394,7 +394,7 @@ static void pretty_printer_cb (void *cls, { if (NULL==address) return; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returned: `%s'\n",address); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returnedp pretty address: `%s'\n",address); fail_pretty_printer_count++; } @@ -421,6 +421,7 @@ run (void *cls, struct Plugin_Address * tmp; const char * addr_str; unsigned int count_str_addr; + unsigned int suggest_res; fail_pretty_printer = GNUNET_YES; fail_notify_address = GNUNET_YES; @@ -485,8 +486,11 @@ run (void *cls, { cur = addr_head; - api->address_pretty_printer(NULL,"http",cur->addr,cur->addrlen,GNUNET_NO,TEST_TIMEOUT,&pretty_printer_cb,NULL); - addr_str = api->address_to_string(NULL,cur->addr,cur->addrlen); + api->address_pretty_printer (NULL,"http",cur->addr,cur->addrlen,GNUNET_NO,TEST_TIMEOUT,&pretty_printer_cb,NULL); + addr_str = api->address_to_string (NULL,cur->addr,cur->addrlen); + suggest_res = api->check_address (NULL,cur->addr,cur->addrlen); + + GNUNET_assert (GNUNET_OK == suggest_res); GNUNET_assert (NULL != addr_str); count_str_addr++; @@ -501,6 +505,25 @@ run (void *cls, fail_pretty_printer=GNUNET_NO; fail_addr_to_str=GNUNET_NO; + /* Suggesting addresses with wrong port*/ + struct IPv4HttpAddress failing_addr; + failing_addr.ipv4_addr = INADDR_LOOPBACK; + failing_addr.u_port = 0; + suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv4HttpAddress)); + GNUNET_assert (GNUNET_SYSERR == suggest_res); + + /* Suggesting addresses with wrong size*/ + failing_addr.ipv4_addr = INADDR_LOOPBACK; + failing_addr.u_port = 0; + suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv6HttpAddress)); + GNUNET_assert (GNUNET_SYSERR == suggest_res); + + /* Suggesting addresses with wrong address*/ + failing_addr.ipv4_addr = 0; + failing_addr.u_port = 12389; + suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv4HttpAddress)); + GNUNET_assert (GNUNET_SYSERR == suggest_res); + /* testing finished, shutting down */ if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) ) fail = 0; -- 2.25.1