From 0d271e8c1e5014989326b9f84b025c08552df95a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 7 Jan 2017 15:32:32 +0100 Subject: [PATCH] migrate UDP plugin to new NAT logic --- src/transport/Makefile.am | 2 +- src/transport/plugin_transport_udp.c | 31 ++++++++++++++++------------ src/transport/plugin_transport_udp.h | 1 - 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 9fb451383..99ed900c5 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -347,7 +347,7 @@ libgnunet_plugin_transport_udp_la_LIBADD = \ $(top_builddir)/src/fragmentation/libgnunetfragmentation.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ - $(top_builddir)/src/nat/libgnunetnat.la \ + $(top_builddir)/src/nat/libgnunetnatnew.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(LTLIBINTL) libgnunet_plugin_transport_udp_la_LDFLAGS = \ diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 35ae92460..c9fb754c1 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - Copyright (C) 2010-2015 GNUnet e.V. + Copyright (C) 2010-2017 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -30,7 +30,7 @@ #include "gnunet_hello_lib.h" #include "gnunet_util_lib.h" #include "gnunet_fragmentation_lib.h" -#include "gnunet_nat_lib.h" +#include "gnunet_nat_service.h" #include "gnunet_protocols.h" #include "gnunet_resolver_service.h" #include "gnunet_signatures.h" @@ -1287,12 +1287,14 @@ udp_plugin_check_address (void *cls, * @param cls closure, the `struct Plugin` * @param add_remove #GNUNET_YES to mean the new public IP address, * #GNUNET_NO to mean the previous (now invalid) one + * @param ac address class the address belongs to * @param addr either the previous or the new public IP address * @param addrlen actual length of the @a addr */ static void udp_nat_port_map_callback (void *cls, int add_remove, + enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen) { @@ -1359,6 +1361,7 @@ udp_nat_port_map_callback (void *cls, return; } /* modify our published address list */ + /* TODO: use 'ac' here in the future... */ address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, PLUGIN_NAME, arg, @@ -3082,7 +3085,7 @@ udp_select_read (struct Plugin *plugin, sizeof(addr)); size = GNUNET_NETWORK_socket_recvfrom (rsock, buf, - sizeof(buf), + sizeof (buf), (struct sockaddr *) &addr, &fromlen); sa = (const struct sockaddr *) &addr; @@ -3111,9 +3114,12 @@ udp_select_read (struct Plugin *plugin, } /* Check if this is a STUN packet */ - if (GNUNET_NAT_is_valid_stun_packet (plugin->nat, - (uint8_t *)buf, - size)) + if (GNUNET_NO != + GNUNET_NAT_stun_handle_packet (plugin->nat, + (const struct sockaddr *) &addr, + fromlen, + buf, + size)) return; /* was STUN, do not process further */ if (size < sizeof(struct GNUNET_MessageHeader)) @@ -3572,13 +3578,13 @@ udp_plugin_select_v6 (void *cls) * @param bind_v4 IPv4 address to bind to (can be NULL, for 'any') * @return number of sockets that were successfully bound */ -static int +static unsigned int setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, const struct sockaddr_in *bind_v4) { int tries; - int sockets_created = 0; + unsigned int sockets_created = 0; struct sockaddr_in6 server_addrv6; struct sockaddr_in server_addrv4; const struct sockaddr *server_addr; @@ -3788,15 +3794,14 @@ setup_sockets (struct Plugin *plugin, schedule_select_v4 (plugin); schedule_select_v6 (plugin); plugin->nat = GNUNET_NAT_register (plugin->env->cfg, - GNUNET_NO, - plugin->port, + "transport-udp", + IPPROTO_UDP, sockets_created, addrs, addrlens, &udp_nat_port_map_callback, NULL, - plugin, - plugin->sockv4); + plugin); return sockets_created; } @@ -3825,7 +3830,7 @@ libgnunet_plugin_transport_udp_init (void *cls) struct GNUNET_TIME_Relative interval; struct sockaddr_in server_addrv4; struct sockaddr_in6 server_addrv6; - int res; + unsigned int res; int have_bind4; int have_bind6; diff --git a/src/transport/plugin_transport_udp.h b/src/transport/plugin_transport_udp.h index c6799ba74..152b16099 100644 --- a/src/transport/plugin_transport_udp.h +++ b/src/transport/plugin_transport_udp.h @@ -32,7 +32,6 @@ #include "gnunet_hello_lib.h" #include "gnunet_util_lib.h" #include "gnunet_fragmentation_lib.h" -#include "gnunet_nat_lib.h" #include "gnunet_protocols.h" #include "gnunet_resolver_service.h" #include "gnunet_signatures.h" -- 2.25.1