DNS server that translates DNS requests to GNS. More...
#include "platform.h"
#include <gnunet_util_lib.h>
#include <gnunet_gns_service.h>
#include "gnunet_vpn_service.h"
Go to the source code of this file.
Data Structures | |
struct | VpnContext |
Closure for vpn_allocation_cb. More... | |
struct | Request |
Request we should make. More... | |
Macros | |
#define | TIMEOUT GNUNET_TIME_UNIT_MINUTES |
Timeout for DNS requests. More... | |
#define | VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) |
Default timeout for VPN redirections. More... | |
Functions | |
static void | do_shutdown (void *cls) |
Task run on shutdown. More... | |
static void | shuffle_answers (struct Request *request) |
Shuffle answers Fisher-Yates (aka Knuth) Shuffle. More... | |
static void | send_response (struct Request *request) |
Send the response for the given request and clean up. More... | |
static void | do_timeout (void *cls) |
Task run on timeout. More... | |
static void | dns_result_processor (void *cls, const struct GNUNET_TUN_DnsHeader *dns, size_t r) |
Iterator called on obtained result for a DNS lookup. More... | |
static void | vpn_allocation_cb (void *cls, int af, const void *vaddress) |
Callback invoked from the VPN service once a redirection is available. More... | |
static void | result_processor (void *cls, int was_gns, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd) |
Iterator called on obtained result for a GNS lookup. More... | |
static void | handle_request (struct GNUNET_NETWORK_Handle *lsock, const void *addr, size_t addr_len, const char *udp_msg, size_t udp_msg_size) |
Handle DNS request. More... | |
static void | read_dns4 (void *cls) |
Task to read IPv4 DNS packets. More... | |
static void | read_dns6 (void *cls) |
Task to read IPv6 DNS packets. More... | |
static void | run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
Main function that will be run. More... | |
int | main (int argc, char *const *argv) |
The main function for the dns2gns daemon. More... | |
Variables | |
static in_addr_t | address |
The address to bind to. More... | |
static struct in6_addr | address6 |
The IPv6 address to bind to. More... | |
struct GNUNET_GNS_Handle * | gns |
Handle to GNS resolver. More... | |
static struct GNUNET_VPN_Handle * | vpn_handle |
Our handle to the vpn service. More... | |
struct GNUNET_DNSSTUB_Context * | dns_stub |
Stub resolver. More... | |
static struct GNUNET_NETWORK_Handle * | listen_socket4 |
Listen socket for IPv4. More... | |
static struct GNUNET_NETWORK_Handle * | listen_socket6 |
Listen socket for IPv6. More... | |
static struct GNUNET_SCHEDULER_Task * | t4 |
Task for IPv4 socket. More... | |
static struct GNUNET_SCHEDULER_Task * | t6 |
Task for IPv6 socket. More... | |
static char * | dns_ip |
IP of DNS server. More... | |
static unsigned long long | listen_port = 53 |
UDP Port we listen on for inbound DNS requests. More... | |
static const struct GNUNET_CONFIGURATION_Handle * | cfg |
Configuration to use. More... | |
DNS server that translates DNS requests to GNS.
Definition in file gnunet-dns2gns.c.
#define TIMEOUT GNUNET_TIME_UNIT_MINUTES |
Timeout for DNS requests.
Definition at line 33 of file gnunet-dns2gns.c.
#define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) |
Default timeout for VPN redirections.
Definition at line 38 of file gnunet-dns2gns.c.
|
static |
Task run on shutdown.
Cleans up everything.
cls | unused |
Definition at line 207 of file gnunet-dns2gns.c.
References dns_stub, gns, GNUNET_DNSSTUB_stop(), GNUNET_GNS_disconnect(), GNUNET_NETWORK_socket_close(), GNUNET_SCHEDULER_cancel(), GNUNET_VPN_disconnect(), listen_socket4, listen_socket6, t4, t6, and vpn_handle.
Referenced by run().
|
static |
Shuffle answers Fisher-Yates (aka Knuth) Shuffle.
request | context for the request (with answers) |
Definition at line 255 of file gnunet-dns2gns.c.
References GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), and request.
Referenced by send_response().
|
static |
Send the response for the given request and clean up.
request | context for the request. |
Definition at line 281 of file gnunet-dns2gns.c.
References _, GNUNET_VPN_RedirectionRequest::addr, GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_pack(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_sendto(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, request, shuffle_answers(), and size.
Referenced by dns_result_processor(), result_processor(), and vpn_allocation_cb().
|
static |
Task run on timeout.
Cleans up request.
cls | struct Request * of the request to clean up |
Definition at line 323 of file gnunet-dns2gns.c.
References GNUNET_DNSPARSER_free_packet(), GNUNET_DNSSTUB_resolve_cancel(), GNUNET_free, GNUNET_GNS_lookup_with_tld_cancel(), GNUNET_VPN_cancel_request(), VpnContext::rd_data, request, and VpnContext::vpn_request.
Referenced by dns_result_processor(), and handle_request().
|
static |
Iterator called on obtained result for a DNS lookup.
cls | closure |
dns | the DNS udp payload |
r | size of the DNS payload |
Definition at line 353 of file gnunet-dns2gns.c.
References _, do_timeout(), GNUNET_DNSPARSER_parse(), GNUNET_DNSSTUB_resolve_cancel(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_TUN_DnsHeader::id, request, and send_response().
Referenced by result_processor().
|
static |
Callback invoked from the VPN service once a redirection is available.
Provides the IP address that can now be used to reach the requested destination. Replaces the "VPN" record with the respective A/AAAA record and continues processing.
cls | closure |
af | address family, AF_INET or AF_INET6; AF_UNSPEC on error; will match 'result_af' from the request |
address | IP address (struct in_addr or struct in_addr6, depending on 'af') that the VPN allocated for the redirection; traffic to this IP will now be redirected to the specified target peer; NULL on error |
Definition at line 401 of file gnunet-dns2gns.c.
References _, GNUNET_TIME_Absolute::abs_value_us, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_assert, GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_TYPE_VPN, GNUNET_log, GNUNET_OK, GNUNET_TIME_relative_to_absolute(), rd, rd_count, VpnContext::rd_count, VpnContext::rd_data, VpnContext::rd_data_size, GNUNET_GNSRECORD_Data::record_type, request, VpnContext::request, send_response(), Request::vpn_ctx, VpnContext::vpn_request, and VPN_TIMEOUT.
Referenced by result_processor().
|
static |
Iterator called on obtained result for a GNS lookup.
cls | closure |
was_gns | GNUNET_NO if the TLD is not configured for GNS |
rd_count | number of records in rd |
rd | the records in reply |
Definition at line 468 of file gnunet-dns2gns.c.
References GNUNET_TIME_Absolute::abs_value_us, GNUNET_DNSPARSER_Packet::answers, GNUNET_TUN_DnsFlags::authenticated_data, GNUNET_TUN_DnsFlags::authoritative_answer, GNUNET_TUN_DnsFlags::checking_disabled, data, GNUNET_DNSPARSER_RawRecord::data, GNUNET_DNSPARSER_Record::data, GNUNET_GNSRECORD_Data::data, GNUNET_DNSPARSER_RawRecord::data_len, data_size, GNUNET_GNSRECORD_Data::data_size, dns_ip, dns_result_processor(), dns_stub, GNUNET_DNSPARSER_Record::dns_traffic_class, GNUNET_DNSPARSER_Record::expiration_time, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_DNSPARSER_Packet::flags, GNUNET_array_append, GNUNET_assert, GNUNET_break_op, GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_DNSPARSER_TYPE_CNAME, GNUNET_DNSSTUB_resolve(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_GNSRECORD_TYPE_VPN, GNUNET_i2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_strdup, GNUNET_TIME_relative_to_absolute(), GNUNET_TUN_DNS_CLASS_INTERNET, GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR, GNUNET_TUN_service_name_to_hash(), GNUNET_VPN_redirect_to_peer(), GNUNET_DNSPARSER_Record::hostname, GNUNET_TUN_DnsFlags::message_truncated, GNUNET_DNSPARSER_Query::name, GNUNET_DNSPARSER_Record::name, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_TUN_GnsVpnRecord::peer, GNUNET_TUN_GnsVpnRecord::proto, GNUNET_DNSPARSER_Packet::queries, GNUNET_TUN_DnsFlags::query_or_response, GNUNET_DNSPARSER_Record::raw, rd, rd_count, VpnContext::rd_count, VpnContext::rd_data, VpnContext::rd_data_size, GNUNET_TUN_DnsFlags::recursion_available, request, VpnContext::request, GNUNET_TUN_DnsFlags::return_code, send_response(), GNUNET_DNSPARSER_Record::type, vpn_allocation_cb(), vpn_handle, VpnContext::vpn_request, VPN_TIMEOUT, and GNUNET_TUN_DnsFlags::zero.
Referenced by handle_request().
|
static |
Handle DNS request.
lsock | socket to use for sending the reply |
addr | address to use for sending the reply |
addr_len | number of bytes in addr |
udp_msg | DNS request payload |
udp_msg_size | number of bytes in udp_msg |
Definition at line 640 of file gnunet-dns2gns.c.
References _, GNUNET_VPN_RedirectionRequest::addr, do_timeout(), GNUNET_DNSPARSER_Packet::flags, gns, GNUNET_a2s(), GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_parse(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_GNS_LO_DEFAULT, GNUNET_GNS_lookup_with_tld(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_memdup, GNUNET_SCHEDULER_add_delayed(), GNUNET_DNSPARSER_Query::name, GNUNET_DNSPARSER_Packet::num_additional_records, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_DNSPARSER_Packet::num_authority_records, GNUNET_DNSPARSER_Packet::num_queries, GNUNET_DNSPARSER_Packet::queries, GNUNET_TUN_DnsFlags::query_or_response, request, result_processor(), TIMEOUT, and GNUNET_DNSPARSER_Query::type.
Referenced by read_dns4(), and read_dns6().
|
static |
Task to read IPv4 DNS packets.
cls | the 'listen_socket4' |
Definition at line 716 of file gnunet-dns2gns.c.
References GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_NETWORK_socket_recvfrom(), GNUNET_NETWORK_socket_recvfrom_amount(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, GNUNET_TIME_UNIT_FOREVER_REL, handle_request(), listen_socket4, read_dns4(), GNUNET_SCHEDULER_TaskContext::reason, size, t4, and tc.
Referenced by read_dns4(), and run().
|
static |
Task to read IPv6 DNS packets.
cls | the 'listen_socket6' |
Definition at line 769 of file gnunet-dns2gns.c.
References GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_NETWORK_socket_recvfrom(), GNUNET_NETWORK_socket_recvfrom_amount(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, GNUNET_TIME_UNIT_FOREVER_REL, handle_request(), listen_socket6, read_dns6(), GNUNET_SCHEDULER_TaskContext::reason, size, t6, and tc.
Referenced by read_dns6(), and run().
|
static |
Main function that will be run.
cls | closure |
args | remaining command-line arguments |
cfgfile | name of the configuration file used (for saving, can be NULL!) |
c | configuration |
Definition at line 825 of file gnunet-dns2gns.c.
References _, address, address6, consensus-simulation::args, cfg, dns_ip, dns_stub, do_shutdown(), gns, GNUNET_assert, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_DNSSTUB_add_dns_ip(), GNUNET_DNSSTUB_start(), GNUNET_DNSSTUB_stop(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNS_connect(), GNUNET_GNS_disconnect(), GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_VPN_connect(), GNUNET_VPN_disconnect(), listen_port, listen_socket4, listen_socket6, read_dns4(), read_dns6(), t4, t6, and vpn_handle.
Referenced by main().
int main | ( | int | argc, |
char *const * | argv | ||
) |
The main function for the dns2gns daemon.
argc | number of arguments from the command line |
argv | command line arguments |
Definition at line 991 of file gnunet-dns2gns.c.
References _, dns_ip, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_log_setup(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), options, ret, and run().
|
static |
|
static |
struct GNUNET_GNS_Handle* gns |
Handle to GNS resolver.
Definition at line 153 of file gnunet-dns2gns.c.
Referenced by do_shutdown(), handle_request(), and run().
|
static |
Our handle to the vpn service.
Definition at line 158 of file gnunet-dns2gns.c.
Referenced by do_shutdown(), result_processor(), and run().
struct GNUNET_DNSSTUB_Context* dns_stub |
Stub resolver.
Definition at line 163 of file gnunet-dns2gns.c.
Referenced by do_shutdown(), result_processor(), and run().
|
static |
Listen socket for IPv4.
Definition at line 168 of file gnunet-dns2gns.c.
Referenced by do_shutdown(), read_dns4(), and run().
|
static |
Listen socket for IPv6.
Definition at line 173 of file gnunet-dns2gns.c.
Referenced by do_shutdown(), read_dns6(), and run().
|
static |
Task for IPv4 socket.
Definition at line 178 of file gnunet-dns2gns.c.
Referenced by do_shutdown(), read_dns4(), and run().
|
static |
Task for IPv6 socket.
Definition at line 183 of file gnunet-dns2gns.c.
Referenced by do_shutdown(), read_dns6(), and run().
|
static |
IP of DNS server.
Definition at line 188 of file gnunet-dns2gns.c.
Referenced by GNUNET_DNSSTUB_add_dns_ip(), main(), result_processor(), and run().
|
static |
UDP Port we listen on for inbound DNS requests.
Definition at line 193 of file gnunet-dns2gns.c.
Referenced by run().
|
static |