From: Christian Grothoff Date: Sat, 7 Jan 2017 16:58:36 +0000 (+0100) Subject: fix calls to test_address, expects a struct sockaddr, not an in_addr X-Git-Tag: taler-0.2.1~508 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c3b77fea0f652b7d8f0641696f3a3418864ab135;p=oweals%2Fgnunet.git fix calls to test_address, expects a struct sockaddr, not an in_addr --- diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c index 261b901a9..826dbd57a 100644 --- a/src/nat/nat_api.c +++ b/src/nat/nat_api.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2007-2016 GNUnet e.V. + Copyright (C) 2007-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 diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 605579c18..eca62a8ca 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -2412,27 +2412,6 @@ tcp_plugin_address_pretty_printer (void *cls, } -/** - * Check if the given port is plausible (must be either our listen - * port or our advertised port), or any port if we are behind NAT - * and do not have a port open. If it is neither, we return - * #GNUNET_SYSERR. - * - * @param plugin global variables - * @param in_port port number to check - * @return #GNUNET_OK if port is either open_port or adv_port - */ -static int -check_port (struct Plugin *plugin, - uint16_t in_port) -{ - if ( (in_port == plugin->adv_port) || - (in_port == plugin->open_port) ) - return GNUNET_OK; - return GNUNET_SYSERR; -} - - /** * Function that will be called to check if a binary address for this * plugin is well-formed and corresponds to an address for THIS peer @@ -2466,6 +2445,8 @@ tcp_plugin_check_address (void *cls, if (addrlen == sizeof(struct IPv4TcpAddress)) { + struct sockaddr_in s4; + v4 = (const struct IPv4TcpAddress *) addr; if (0 != memcmp (&v4->options, &plugin->myoptions, @@ -2474,17 +2455,24 @@ tcp_plugin_check_address (void *cls, GNUNET_break (0); return GNUNET_SYSERR; } - if (GNUNET_OK != check_port (plugin, - ntohs (v4->t4_port))) - return GNUNET_SYSERR; + memset (&s4, 0, sizeof (s4)); + s4.sin_family = AF_INET; +#if HAVE_SOCKADDR_IN_SIN_LEN + s4.sin_len = sizeof (s4); +#endif + s4.sin_port = v4->t4_port; + s4.sin_addr.s_addr = v4->ipv4_addr; + if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, - &v4->ipv4_addr, - sizeof (struct in_addr))) + &s4, + sizeof (struct sockaddr_in))) return GNUNET_SYSERR; } else { + struct sockaddr_in6 s6; + v6 = (const struct IPv6TcpAddress *) addr; if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) { @@ -2498,13 +2486,18 @@ tcp_plugin_check_address (void *cls, GNUNET_break (0); return GNUNET_SYSERR; } - if (GNUNET_OK != check_port (plugin, - ntohs (v6->t6_port))) - return GNUNET_SYSERR; + memset (&s6, 0, sizeof (s6)); + s6.sin6_family = AF_INET6; +#if HAVE_SOCKADDR_IN_SIN_LEN + s6.sin6_len = sizeof (s6); +#endif + s6.sin6_port = v6->t6_port; + s6.sin6_addr = v6->ipv6_addr; + if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, - &v6->ipv6_addr, - sizeof(struct in6_addr))) + &s6, + sizeof(struct sockaddr_in6))) return GNUNET_SYSERR; } return GNUNET_OK; diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index c9fb754c1..8281e48c5 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -1245,31 +1245,48 @@ udp_plugin_check_address (void *cls, if (sizeof(struct IPv4UdpAddress) == addrlen) { + struct sockaddr_in s4; + v4 = (const struct IPv4UdpAddress *) addr; if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) return GNUNET_SYSERR; + memset (&s4, 0, sizeof (s4)); + s4.sin_family = AF_INET; +#if HAVE_SOCKADDR_IN_SIN_LEN + s4.sin_len = sizeof (s4); +#endif + s4.sin_port = v4->u4_port; + s4.sin_addr.s_addr = v4->ipv4_addr; + if (GNUNET_OK != - GNUNET_NAT_test_address (plugin->nat, - &v4->ipv4_addr, - sizeof (struct in_addr))) + GNUNET_NAT_test_address (plugin->nat, + &s4, + sizeof (struct sockaddr_in))) return GNUNET_SYSERR; } else if (sizeof(struct IPv6UdpAddress) == addrlen) { + struct sockaddr_in6 s6; + v6 = (const struct IPv6UdpAddress *) addr; if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) { GNUNET_break_op (0); return GNUNET_SYSERR; } - if (GNUNET_OK != check_port (plugin, - ntohs (v6->u6_port))) - return GNUNET_SYSERR; + memset (&s6, 0, sizeof (s6)); + s6.sin6_family = AF_INET6; +#if HAVE_SOCKADDR_IN_SIN_LEN + s6.sin6_len = sizeof (s6); +#endif + s6.sin6_port = v6->u6_port; + s6.sin6_addr = v6->ipv6_addr; + if (GNUNET_OK != - GNUNET_NAT_test_address (plugin->nat, - &v6->ipv6_addr, - sizeof (struct in6_addr))) + GNUNET_NAT_test_address (plugin->nat, + &s6, + sizeof(struct sockaddr_in6))) return GNUNET_SYSERR; } else