This file is part of GNUnet.
Copyright (C) 2012-2013 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
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
* @file gnunet-dns2gns.c
* Number of bytes in @e udp_msg.
*/
size_t udp_msg_size;
+
+ /**
+ * ID of the original request.
+ */
+ uint16_t original_request_id;
};
+/**
+ * The address to bind to
+ */
+static in_addr_t address;
+
+/**
+ * The IPv6 address to bind to
+ */
+static struct in6_addr address6;
+
+
/**
* Handle to GNS resolver.
* Iterator called on obtained result for a DNS lookup
*
* @param cls closure
- * @param rs the request socket
* @param dns the DNS udp payload
* @param r size of the DNS payload
*/
static void
dns_result_processor (void *cls,
- struct GNUNET_DNSSTUB_RequestSocket *rs,
const struct GNUNET_TUN_DnsHeader *dns,
size_t r)
{
struct Request *request = cls;
- (void) rs;
+ if (NULL == dns)
+ {
+ /* DNSSTUB gave up, so we trigger timeout early */
+ GNUNET_SCHEDULER_cancel (request->timeout_task);
+ do_timeout (request);
+ return;
+ }
+ if (request->original_request_id != dns->id)
+ {
+ /* for a another query, ignore */
+ return;
+ }
request->packet = GNUNET_DNSPARSER_parse ((char*)dns,
r);
+ GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup);
send_response (request);
}
{
struct Request *request = cls;
struct GNUNET_DNSPARSER_Packet *packet;
- uint32_t i;
struct GNUNET_DNSPARSER_Record rec;
request->lookup = NULL;
"Using DNS resolver IP `%s' to resolve `%s'\n",
dns_ip,
request->packet->queries[0].name);
+ request->original_request_id = request->packet->id;
GNUNET_DNSPARSER_free_packet (request->packet);
request->packet = NULL;
- request->dns_lookup = GNUNET_DNSSTUB_resolve2 (dns_stub,
- request->udp_msg,
- request->udp_msg_size,
- &dns_result_processor,
- request);
+ request->dns_lookup = GNUNET_DNSSTUB_resolve (dns_stub,
+ request->udp_msg,
+ request->udp_msg_size,
+ &dns_result_processor,
+ request);
return;
- }
+ }
packet = request->packet;
packet->flags.query_or_response = 1;
packet->flags.return_code = GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR;
packet->flags.message_truncated = 0;
packet->flags.authoritative_answer = 0;
//packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ???
- for (i=0;i<rd_count;i++)
+ for (uint32_t i=0;i<rd_count;i++)
{
// FIXME: do we need to hanlde #GNUNET_GNSRECORD_RF_SHADOW_RECORD
// here? Or should we do this in libgnunetgns?
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
+ char *addr_str;
(void) cls;
(void) args;
(void) cfgfile;
NULL);
if (NULL == (gns = GNUNET_GNS_connect (cfg)))
return;
- if (NULL == (dns_stub = GNUNET_DNSSTUB_start (dns_ip)))
+ GNUNET_assert (NULL != (dns_stub = GNUNET_DNSSTUB_start (128)));
+ if (GNUNET_OK !=
+ GNUNET_DNSSTUB_add_dns_ip (dns_stub,
+ dns_ip))
{
+ GNUNET_DNSSTUB_stop (dns_stub);
GNUNET_GNS_disconnect (gns);
gns = NULL;
return;
}
+
+ /* Get address to bind to */
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "dns2gns",
+ "BIND_TO",
+ &addr_str))
+ {
+ //No address specified
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Don't know what to bind to...\n");
+ GNUNET_free (addr_str);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (1 != inet_pton (AF_INET, addr_str, &address))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unable to parse address %s\n",
+ addr_str);
+ GNUNET_free (addr_str);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_free (addr_str);
+ /* Get address to bind to */
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "dns2gns",
+ "BIND_TO6",
+ &addr_str))
+ {
+ //No address specified
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Don't know what to bind6 to...\n");
+ GNUNET_free (addr_str);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (1 != inet_pton (AF_INET6, addr_str, &address6))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unable to parse IPv6 address %s\n",
+ addr_str);
+ GNUNET_free (addr_str);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_free (addr_str);
+
listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET,
SOCK_DGRAM,
IPPROTO_UDP);
memset (&v4, 0, sizeof (v4));
v4.sin_family = AF_INET;
+ v4.sin_addr.s_addr = address;
#if HAVE_SOCKADDR_IN_SIN_LEN
v4.sin_len = sizeof (v4);
#endif
memset (&v6, 0, sizeof (v6));
v6.sin6_family = AF_INET6;
+ v6.sin6_addr = address6;
#if HAVE_SOCKADDR_IN_SIN_LEN
v6.sin6_len = sizeof (v6);
#endif