aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-10-04 15:25:12 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-10-04 15:25:12 +0000
commit225ea6ae752bb7428c37f8743611c3dd2bff1c05 (patch)
tree4efd8400bcae6b51f2002e71b8b69f435a950def /src/transport
parenta82188f859826f98b209f265531d1fa63f2b6ae2 (diff)
downloadgnunet-225ea6ae752bb7428c37f8743611c3dd2bff1c05.tar.gz
gnunet-225ea6ae752bb7428c37f8743611c3dd2bff1c05.zip
stricter suggested address checking
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/plugin_transport_http.c104
-rw-r--r--src/transport/test_plugin_transport_http.c9
-rw-r--r--src/transport/test_plugin_transport_https.c12
3 files changed, 117 insertions, 8 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 0238746bc..f45dac171 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -96,6 +96,16 @@
96struct IPv4HttpAddress 96struct IPv4HttpAddress
97{ 97{
98 /** 98 /**
99 * Linked list next
100 */
101 struct IPv4HttpAddress * next;
102
103 /**
104 * Linked list previous
105 */
106 struct IPv4HttpAddress * prev;
107
108 /**
99 * IPv4 address, in network byte order. 109 * IPv4 address, in network byte order.
100 */ 110 */
101 uint32_t ipv4_addr GNUNET_PACKED; 111 uint32_t ipv4_addr GNUNET_PACKED;
@@ -114,6 +124,16 @@ struct IPv4HttpAddress
114struct IPv6HttpAddress 124struct IPv6HttpAddress
115{ 125{
116 /** 126 /**
127 * Linked list next
128 */
129 struct IPv6HttpAddress * next;
130
131 /**
132 * Linked list previous
133 */
134 struct IPv6HttpAddress * prev;
135
136 /**
117 * IPv6 address. 137 * IPv6 address.
118 */ 138 */
119 struct in6_addr ipv6_addr GNUNET_PACKED; 139 struct in6_addr ipv6_addr GNUNET_PACKED;
@@ -382,6 +402,26 @@ struct Plugin
382 CURLM * multi_handle; 402 CURLM * multi_handle;
383 403
384 /** 404 /**
405 * ipv4 DLL head
406 */
407 struct IPv4HttpAddress * ipv4_addr_head;
408
409 /**
410 * ipv4 DLL tail
411 */
412 struct IPv4HttpAddress * ipv4_addr_tail;
413
414 /**
415 * ipv6 DLL head
416 */
417 struct IPv6HttpAddress * ipv6_addr_head;
418
419 /**
420 * ipv6 DLL tail
421 */
422 struct IPv6HttpAddress * ipv6_addr_tail;
423
424 /**
385 * Our ASCII encoded, hashed peer identity 425 * Our ASCII encoded, hashed peer identity
386 * This string is used to distinguish between connections and is added to the urls 426 * This string is used to distinguish between connections and is added to the urls
387 */ 427 */
@@ -674,14 +714,16 @@ process_interfaces (void *cls,
674 { 714 {
675 if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr))) 715 if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr)))
676 { 716 {
717 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,t4);
677 plugin->env->notify_address(plugin->env->cls,PROTOCOL_PREFIX,t4, sizeof (struct IPv4HttpAddress), GNUNET_TIME_UNIT_FOREVER_REL); 718 plugin->env->notify_address(plugin->env->cls,PROTOCOL_PREFIX,t4, sizeof (struct IPv4HttpAddress), GNUNET_TIME_UNIT_FOREVER_REL);
678 } 719 }
679 } 720 }
680 else 721 else
681 { 722 {
723 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,t4);
682 plugin->env->notify_address(plugin->env->cls,PROTOCOL_PREFIX,t4, sizeof (struct IPv4HttpAddress), GNUNET_TIME_UNIT_FOREVER_REL); 724 plugin->env->notify_address(plugin->env->cls,PROTOCOL_PREFIX,t4, sizeof (struct IPv4HttpAddress), GNUNET_TIME_UNIT_FOREVER_REL);
683 } 725 }
684 GNUNET_free (t4); 726
685 } 727 }
686 else if ((af == AF_INET6) && (plugin->use_ipv6 == GNUNET_YES) && (plugin->bind4_address == NULL)) 728 else if ((af == AF_INET6) && (plugin->use_ipv6 == GNUNET_YES) && (plugin->bind4_address == NULL))
687 { 729 {
@@ -701,6 +743,7 @@ process_interfaces (void *cls,
701 sizeof (struct in6_addr)); 743 sizeof (struct in6_addr));
702 t6->u6_port = htons (plugin->port_inbound); 744 t6->u6_port = htons (plugin->port_inbound);
703 plugin->env->notify_address(plugin->env->cls,PROTOCOL_PREFIX,t6,sizeof (struct IPv6HttpAddress) , GNUNET_TIME_UNIT_FOREVER_REL); 745 plugin->env->notify_address(plugin->env->cls,PROTOCOL_PREFIX,t6,sizeof (struct IPv6HttpAddress) , GNUNET_TIME_UNIT_FOREVER_REL);
746 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6);
704 } 747 }
705 } 748 }
706 else 749 else
@@ -709,9 +752,9 @@ process_interfaces (void *cls,
709 &((struct sockaddr_in6 *) addr)->sin6_addr, 752 &((struct sockaddr_in6 *) addr)->sin6_addr,
710 sizeof (struct in6_addr)); 753 sizeof (struct in6_addr));
711 t6->u6_port = htons (plugin->port_inbound); 754 t6->u6_port = htons (plugin->port_inbound);
755 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6);
712 plugin->env->notify_address(plugin->env->cls,PROTOCOL_PREFIX,t6,sizeof (struct IPv6HttpAddress) , GNUNET_TIME_UNIT_FOREVER_REL); 756 plugin->env->notify_address(plugin->env->cls,PROTOCOL_PREFIX,t6,sizeof (struct IPv6HttpAddress) , GNUNET_TIME_UNIT_FOREVER_REL);
713 } 757 }
714 GNUNET_free (t6);
715 } 758 }
716 return GNUNET_OK; 759 return GNUNET_OK;
717} 760}
@@ -2393,6 +2436,10 @@ http_plugin_address_suggested (void *cls,
2393 struct Plugin *plugin = cls; 2436 struct Plugin *plugin = cls;
2394 struct IPv4HttpAddress *v4; 2437 struct IPv4HttpAddress *v4;
2395 struct IPv6HttpAddress *v6; 2438 struct IPv6HttpAddress *v6;
2439
2440 struct IPv4HttpAddress *tv4 = plugin->ipv4_addr_head;
2441 struct IPv6HttpAddress *tv6 = plugin->ipv6_addr_head;
2442 int res;
2396 unsigned int port; 2443 unsigned int port;
2397 2444
2398 GNUNET_assert(cls !=NULL); 2445 GNUNET_assert(cls !=NULL);
@@ -2409,6 +2456,23 @@ http_plugin_address_suggested (void *cls,
2409 { 2456 {
2410 return GNUNET_SYSERR; 2457 return GNUNET_SYSERR;
2411 } */ 2458 } */
2459
2460 if (plugin->bind4_address!=NULL)
2461 {
2462 res = memcmp (&plugin->bind4_address->sin_addr, &v4->ipv4_addr, sizeof(uint32_t));
2463 if ((res==0) && (ntohs (v4->u_port) == plugin->port_inbound))
2464 return GNUNET_OK;
2465 else
2466 return GNUNET_SYSERR;
2467 }
2468
2469 while (tv4!=NULL)
2470 {
2471 res = memcmp (&tv4->ipv4_addr, &v4->ipv4_addr, sizeof(uint32_t));
2472 if ((res==0) && (v4->u_port == tv4->u_port) && (ntohs (v4->u_port) == plugin->port_inbound))
2473 return GNUNET_OK;
2474 tv4 = tv4->next;
2475 }
2412 port = ntohs (v4->u_port); 2476 port = ntohs (v4->u_port);
2413 if (port != plugin->port_inbound) 2477 if (port != plugin->port_inbound)
2414 { 2478 {
@@ -2422,14 +2486,26 @@ http_plugin_address_suggested (void *cls,
2422 { 2486 {
2423 return GNUNET_SYSERR; 2487 return GNUNET_SYSERR;
2424 } 2488 }
2425 port = ntohs (v6->u6_port); 2489
2426 if (port != plugin->port_inbound) 2490 if (plugin->bind6_address!=NULL)
2427 { 2491 {
2428 return GNUNET_SYSERR; 2492 res = memcmp (&plugin->bind6_address->sin6_addr, &v6->ipv6_addr, sizeof(struct in6_addr));
2493 if ((res==0) && (ntohs (v6->u6_port) == plugin->port_inbound))
2494 return GNUNET_OK;
2495 else
2496 return GNUNET_SYSERR;
2497 }
2498
2499 while (tv6!=NULL)
2500 {
2501 res = memcmp (&tv6->ipv6_addr, &v6->ipv6_addr, sizeof(struct in6_addr));
2502 if ((res==0) && (v6->u6_port == tv6->u6_port) && (ntohs (v6->u6_port) == plugin->port_inbound))
2503 return GNUNET_OK;
2504 tv6 = tv6->next;
2429 } 2505 }
2430 } 2506 }
2431 2507
2432 return GNUNET_OK; 2508 return GNUNET_SYSERR;
2433} 2509}
2434 2510
2435 2511
@@ -2495,6 +2571,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2495 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2571 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2496 struct Plugin *plugin = api->cls; 2572 struct Plugin *plugin = api->cls;
2497 CURLMcode mret; 2573 CURLMcode mret;
2574 struct IPv4HttpAddress * ipv4addr;
2575 struct IPv6HttpAddress * ipv6addr;
2498 GNUNET_assert(cls !=NULL); 2576 GNUNET_assert(cls !=NULL);
2499 2577
2500 if (plugin->http_server_daemon_v4 != NULL) 2578 if (plugin->http_server_daemon_v4 != NULL)
@@ -2520,6 +2598,20 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2520 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; 2598 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
2521 } 2599 }
2522 2600
2601 while (plugin->ipv4_addr_head!=NULL)
2602 {
2603 ipv4addr = plugin->ipv4_addr_head;
2604 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,ipv4addr);
2605 GNUNET_free(ipv4addr);
2606 }
2607
2608 while (plugin->ipv6_addr_head!=NULL)
2609 {
2610 ipv6addr = plugin->ipv6_addr_head;
2611 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,ipv6addr);
2612 GNUNET_free(ipv6addr);
2613 }
2614
2523 /* free all peer information */ 2615 /* free all peer information */
2524 if (plugin->peers!=NULL) 2616 if (plugin->peers!=NULL)
2525 { 2617 {
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index e8b8bd4ce..fea71b3d3 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -162,6 +162,10 @@ struct HTTP_Transfer
162 */ 162 */
163struct IPv4HttpAddress 163struct IPv4HttpAddress
164{ 164{
165 struct IPv4HttpAddress * next;
166
167 struct IPv4HttpAddress * prev;
168
165 /** 169 /**
166 * IPv4 address, in network byte order. 170 * IPv4 address, in network byte order.
167 */ 171 */
@@ -180,6 +184,10 @@ struct IPv4HttpAddress
180 */ 184 */
181struct IPv6HttpAddress 185struct IPv6HttpAddress
182{ 186{
187 struct IPv6HttpAddress * next;
188
189 struct IPv6HttpAddress * prev;
190
183 /** 191 /**
184 * IPv6 address. 192 * IPv6 address.
185 */ 193 */
@@ -192,6 +200,7 @@ struct IPv6HttpAddress
192 200
193}; 201};
194 202
203
195/** 204/**
196 * Our public key. 205 * Our public key.
197 */ 206 */
diff --git a/src/transport/test_plugin_transport_https.c b/src/transport/test_plugin_transport_https.c
index a0aaee78d..7eb60d46c 100644
--- a/src/transport/test_plugin_transport_https.c
+++ b/src/transport/test_plugin_transport_https.c
@@ -162,6 +162,10 @@ struct HTTP_Transfer
162 */ 162 */
163struct IPv4HttpAddress 163struct IPv4HttpAddress
164{ 164{
165 struct IPv4HttpAddress * next;
166
167 struct IPv4HttpAddress * prev;
168
165 /** 169 /**
166 * IPv4 address, in network byte order. 170 * IPv4 address, in network byte order.
167 */ 171 */
@@ -180,6 +184,10 @@ struct IPv4HttpAddress
180 */ 184 */
181struct IPv6HttpAddress 185struct IPv6HttpAddress
182{ 186{
187 struct IPv6HttpAddress * next;
188
189 struct IPv6HttpAddress * prev;
190
183 /** 191 /**
184 * IPv6 address. 192 * IPv6 address.
185 */ 193 */
@@ -458,8 +466,8 @@ shutdown_clean ()
458 } 466 }
459 467
460 GNUNET_free(test_addr); 468 GNUNET_free(test_addr);
461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n"); 469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading https plugin\n");
462 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http", api)); 470 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_https", api));
463 471
464 GNUNET_SCHEDULER_shutdown(sched); 472 GNUNET_SCHEDULER_shutdown(sched);
465 GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http"); 473 GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");