aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-05-19 11:37:08 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-05-19 11:37:08 +0000
commit730f86ac0e726c33a8819f7249b16c46fedc7ce3 (patch)
tree85f1fa56f947e70d1bd0aafd75b25187b1f1e126 /src/transport/plugin_transport_http.c
parent7c0a27c527bb8fc6534568b1e8fca7445c283edf (diff)
downloadgnunet-730f86ac0e726c33a8819f7249b16c46fedc7ce3.tar.gz
gnunet-730f86ac0e726c33a8819f7249b16c46fedc7ce3.zip
NEW: local addresses are filtered
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r--src/transport/plugin_transport_http.c152
1 files changed, 106 insertions, 46 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 0c859cdbf..362851796 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -464,6 +464,11 @@ struct Plugin
464 int use_ipv4; 464 int use_ipv4;
465 465
466 /** 466 /**
467 * use local addresses?
468 */
469 int use_localaddresses;
470
471 /**
467 * Closure passed by MHD to the mhd_logger function 472 * Closure passed by MHD to the mhd_logger function
468 */ 473 */
469 void * mhd_log; 474 void * mhd_log;
@@ -726,6 +731,44 @@ remove_session (struct HTTP_PeerContext * pc,
726 return GNUNET_OK; 731 return GNUNET_OK;
727} 732}
728 733
734static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
735{
736 uint32_t res = 0;
737 int local = GNUNET_NO;
738 int af = addr->sa_family;
739 switch (af)
740 {
741 case AF_INET:
742 {
743 uint32_t netmask = 0x7F000000;
744 uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr);
745 res = (address >> 24) ^ (netmask >> 24);
746 if (res != 0)
747 local = GNUNET_NO;
748 else
749 local = GNUNET_YES;
750#if DEBUG_HTTP
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global");
753#endif
754 break;
755 }
756 case AF_INET6:
757 {
758 if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) ||
759 IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
760 local = GNUNET_YES;
761 else
762 local = GNUNET_NO;
763#if DEBUG_HTTP
764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
765 "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global");
766#endif
767 break;
768 }
769 }
770 return local;
771}
729 772
730/** 773/**
731 * Add the IP of our network interface to the list of 774 * Add the IP of our network interface to the list of
@@ -749,40 +792,50 @@ process_interfaces (void *cls,
749 struct IPv6HttpAddress * t6; 792 struct IPv6HttpAddress * t6;
750 int af; 793 int af;
751 794
795 if (plugin->use_localaddresses == GNUNET_NO)
796 {
797 if (GNUNET_YES == check_localaddress (addr, addrlen))
798 {
799#if DEBUG_HTTP
800 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
801 PROTOCOL_PREFIX,
802 "Not notifying transport of address `%s' (local address)\n",
803 GNUNET_a2s (addr, addrlen));
804#endif
805 return GNUNET_OK;
806 }
807 }
808
752 809
753 GNUNET_assert(cls !=NULL); 810 GNUNET_assert(cls !=NULL);
754 af = addr->sa_family; 811 af = addr->sa_family;
755 if ( (af == AF_INET) && 812 if ((af == AF_INET) &&
756 (plugin->use_ipv4 == GNUNET_YES) && 813 (plugin->use_ipv4 == GNUNET_YES) &&
757 (plugin->bind6_address == NULL) ) 814 (plugin->bind6_address == NULL) ) {
758 { 815
759 struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr; 816 struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr;
760 t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress)); 817 t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress));
761 /* Not skipping loopback addresses 818 // Not skipping loopback addresses
762 if (INADDR_LOOPBACK == ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr)) 819
763 {
764 820
765 return GNUNET_OK;
766 }
767 */
768 t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 821 t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
769 t4->u_port = htons (plugin->port_inbound); 822 t4->u_port = htons (plugin->port_inbound);
770 if (plugin->bind4_address != NULL) 823 if (plugin->bind4_address != NULL) {
771 {
772 if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr))) 824 if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr)))
773 { 825 {
774 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,t4); 826 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head,
775 plugin->env->notify_address(plugin->env->cls, 827 plugin->ipv4_addr_tail,t4);
776 PROTOCOL_PREFIX, 828 plugin->env->notify_address(plugin->env->cls,
777 t4, sizeof (struct IPv4HttpAddress), 829 PROTOCOL_PREFIX,
778 GNUNET_TIME_UNIT_FOREVER_REL); 830 t4, sizeof (struct IPv4HttpAddress),
779 return GNUNET_OK; 831 GNUNET_TIME_UNIT_FOREVER_REL);
780 } 832 return GNUNET_OK;
781 GNUNET_free (t4); 833 }
782 return GNUNET_OK; 834 GNUNET_free (t4);
783 } 835 return GNUNET_OK;
836 }
784 else 837 else
785 { 838 {
786 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, 839 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
787 plugin->ipv4_addr_tail, 840 plugin->ipv4_addr_tail,
788 t4); 841 t4);
@@ -791,25 +844,21 @@ process_interfaces (void *cls,
791 t4, sizeof (struct IPv4HttpAddress), 844 t4, sizeof (struct IPv4HttpAddress),
792 GNUNET_TIME_UNIT_FOREVER_REL); 845 GNUNET_TIME_UNIT_FOREVER_REL);
793 return GNUNET_OK; 846 return GNUNET_OK;
794 } 847 }
795 } 848 }
796 else if ( (af == AF_INET6) && 849 if ((af == AF_INET6) &&
797 (plugin->use_ipv6 == GNUNET_YES) && 850 (plugin->use_ipv6 == GNUNET_YES) &&
798 (plugin->bind4_address == NULL) ) 851 (plugin->bind4_address == NULL) ) {
799 { 852
800 struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr; 853 struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr;
801 if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) 854
802 {
803 return GNUNET_OK;
804 }
805 t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress)); 855 t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress));
806 GNUNET_assert(t6 != NULL); 856 GNUNET_assert(t6 != NULL);
807 if (plugin->bind6_address != NULL) 857
808 { 858 if (plugin->bind6_address != NULL) {
809 if (0 == memcmp(&plugin->bind6_address->sin6_addr, 859 if (0 == memcmp(&plugin->bind6_address->sin6_addr,
810 &bnd_cmp6, 860 &bnd_cmp6,
811 sizeof (struct in6_addr))) 861 sizeof (struct in6_addr))) {
812 {
813 memcpy (&t6->ipv6_addr, 862 memcpy (&t6->ipv6_addr,
814 &((struct sockaddr_in6 *) addr)->sin6_addr, 863 &((struct sockaddr_in6 *) addr)->sin6_addr,
815 sizeof (struct in6_addr)); 864 sizeof (struct in6_addr));
@@ -821,21 +870,21 @@ process_interfaces (void *cls,
821 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head, 870 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,
822 plugin->ipv6_addr_tail, 871 plugin->ipv6_addr_tail,
823 t6); 872 t6);
824 return GNUNET_OK; 873 return GNUNET_OK;
825 } 874 }
826 GNUNET_free (t6); 875 GNUNET_free (t6);
827 return GNUNET_OK; 876 return GNUNET_OK;
828 } 877 }
829 memcpy (&t6->ipv6_addr, 878 memcpy (&t6->ipv6_addr,
830 &((struct sockaddr_in6 *) addr)->sin6_addr, 879 &((struct sockaddr_in6 *) addr)->sin6_addr,
831 sizeof (struct in6_addr)); 880 sizeof (struct in6_addr));
832 t6->u6_port = htons (plugin->port_inbound); 881 t6->u6_port = htons (plugin->port_inbound);
833 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6); 882 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6);
834 plugin->env->notify_address(plugin->env->cls, 883 plugin->env->notify_address(plugin->env->cls,
835 PROTOCOL_PREFIX, 884 PROTOCOL_PREFIX,
836 t6, sizeof (struct IPv6HttpAddress), 885 t6, sizeof (struct IPv6HttpAddress),
837 GNUNET_TIME_UNIT_FOREVER_REL); 886 GNUNET_TIME_UNIT_FOREVER_REL);
838 } 887 }
839 return GNUNET_OK; 888 return GNUNET_OK;
840} 889}
841 890
@@ -2962,8 +3011,10 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2962 plugin->env = env; 3011 plugin->env = env;
2963 plugin->peers = NULL; 3012 plugin->peers = NULL;
2964 plugin->bind4_address = NULL; 3013 plugin->bind4_address = NULL;
3014 plugin->bind6_address = NULL;
2965 plugin->use_ipv6 = GNUNET_YES; 3015 plugin->use_ipv6 = GNUNET_YES;
2966 plugin->use_ipv4 = GNUNET_YES; 3016 plugin->use_ipv4 = GNUNET_YES;
3017 plugin->use_localaddresses = GNUNET_NO;
2967 3018
2968 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 3019 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2969 api->cls = plugin; 3020 api->cls = plugin;
@@ -2992,6 +3043,15 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2992 plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3043 plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
2993 component_name,"USE_IPv4"); 3044 component_name,"USE_IPv4");
2994 } 3045 }
3046 /* use local addresses? */
3047
3048 if (GNUNET_CONFIGURATION_have_value (env->cfg,
3049 component_name, "USE_LOCALADDR"))
3050 {
3051 plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3052 component_name,
3053 "USE_LOCALADDR");
3054 }
2995 /* Reading port number from config file */ 3055 /* Reading port number from config file */
2996 if ((GNUNET_OK != 3056 if ((GNUNET_OK !=
2997 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3057 GNUNET_CONFIGURATION_get_value_number (env->cfg,