From ecfd00ad31f6f49013e7f4b756e4129db2bb60d1 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 23 Nov 2011 14:17:47 +0000 Subject: [PATCH] Adding UDP IPv6 peer discovery support using the GNUnet IPv6 multicast address with site-local scope FF05::13B assigned by IANA --- src/transport/plugin_transport_udp.c | 53 ++++++++++++++++--- .../test_transport_api_udp_peer1.conf | 5 +- src/transport/transport.conf | 4 +- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 84c7ce661..9ad97449c 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -2253,7 +2253,7 @@ libgnunet_plugin_transport_udp_init (void *cls) if (plugin->sockv6 != NULL) { memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6)); - GNUNET_assert (1 == inet_pton(AF_INET6, "ff02::1", &plugin->ipv6_multicast_address.sin6_addr)); + GNUNET_assert (1 == inet_pton(AF_INET6, "FF05::13B", &plugin->ipv6_multicast_address.sin6_addr)); plugin->ipv6_multicast_address.sin6_family = AF_INET6; plugin->ipv6_multicast_address.sin6_port = htons(plugin->port); @@ -2261,12 +2261,34 @@ libgnunet_plugin_transport_udp_init (void *cls) plugin->broadcast_ipv6_mst = GNUNET_SERVER_mst_create (broadcast_ipv6_mst_cb, plugin); - LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 Broadcasting running\n"); - + /* Create IPv6 multicast request */ + struct ipv6_mreq multicastRequest; + multicastRequest.ipv6mr_multiaddr = plugin->ipv6_multicast_address.sin6_addr; + /* TODO: 0 selects the "best" interface, tweak to use all interfaces + * + * http://tools.ietf.org/html/rfc2553#section-5.2: + * + * IPV6_JOIN_GROUP + * + * Join a multicast group on a specified local interface. If the + * interface index is specified as 0, the kernel chooses the local + * interface. For example, some kernels look up the multicast + * group in the normal IPv6 routing table and using the resulting + * interface. + * */ + multicastRequest.ipv6mr_interface = 0; + + /* Join the multicast group */ + if ( GNUNET_NETWORK_socket_setsockopt( plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP, (char*) &multicastRequest, sizeof(multicastRequest)) == GNUNET_OK ) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 broadcasting running\n"); - plugin->send_ipv6_broadcast_task = - GNUNET_SCHEDULER_add_now (&udp_ipv6_broadcast_send, plugin); - plugin->broadcast_ipv6 = GNUNET_YES; + plugin->send_ipv6_broadcast_task = + GNUNET_SCHEDULER_add_now (&udp_ipv6_broadcast_send, plugin); + plugin->broadcast_ipv6 = GNUNET_YES; + } + else + LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 broadcasting not running\n"); } } @@ -2277,7 +2299,6 @@ libgnunet_plugin_transport_udp_init (void *cls) (const struct sockaddr **) addrs, addrlens, &udp_nat_port_map_callback, NULL, plugin); return api; - udp_ipv6_broadcast_send(NULL, NULL); } /** @@ -2347,12 +2368,28 @@ libgnunet_plugin_transport_udp_done (void *cls) if (plugin->broadcast_ipv6) { + /* Create IPv6 multicast request */ + struct ipv6_mreq multicastRequest; + multicastRequest.ipv6mr_multiaddr = plugin->ipv6_multicast_address.sin6_addr; + multicastRequest.ipv6mr_interface = 0; + + /* Join the multicast address */ + if ( GNUNET_NETWORK_socket_setsockopt( plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP, (char*) &multicastRequest, sizeof(multicastRequest)) == 0 ) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 Broadcasting stopped\n"); + + plugin->send_ipv6_broadcast_task = + GNUNET_SCHEDULER_add_now (&udp_ipv6_broadcast_send, plugin); + plugin->broadcast_ipv6 = GNUNET_YES; + } + else + GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, setsockopt); + if (plugin->send_ipv6_broadcast_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (plugin->send_ipv6_broadcast_task); plugin->send_ipv6_broadcast_task = GNUNET_SCHEDULER_NO_TASK; } - if (plugin->broadcast_ipv6_mst != NULL) GNUNET_SERVER_mst_destroy (plugin->broadcast_ipv6_mst); } diff --git a/src/transport/test_transport_api_udp_peer1.conf b/src/transport/test_transport_api_udp_peer1.conf index a1413679f..f8b0ae47c 100644 --- a/src/transport/test_transport_api_udp_peer1.conf +++ b/src/transport/test_transport_api_udp_peer1.conf @@ -5,9 +5,8 @@ DEFAULTCONFIG = test_transport_api_udp_peer1.conf [transport-udp] PORT = 12040 -#BROADCAST = YES -BROADCAST_PORT = 20089 -#BROADCAST_INTERVAL = 30000 +BROADCAST = YES +BROADCAST_INTERVAL = 30000 MAX_BPS = 50000000 [arm] diff --git a/src/transport/transport.conf b/src/transport/transport.conf index ddcf83e55..7fe3d9532 100644 --- a/src/transport/transport.conf +++ b/src/transport/transport.conf @@ -42,8 +42,8 @@ MAX_CONNECTIONS = 128 [transport-udp] PORT = 2086 -#BROADCAST = YES -#BROADCAST_INTERVAL = 30000 +BROADCAST = YES +BROADCAST_INTERVAL = 30000 MAX_BPS = 1000000 [transport-http] -- 2.25.1