33#define TIMEOUT GNUNET_TIME_UNIT_MINUTES
38#define VPN_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
257 unsigned int idx =
request->packet->num_answers;
266 tmp_answer =
request->packet->answers[idx];
267 memcpy (&
request->packet->answers[idx], &
request->packet->answers[r_idx],
269 memcpy (&
request->packet->answers[r_idx], &tmp_answer,
295 _ (
"Failed to pack DNS response into UDP packet!\n"));
305 (
size != (
size_t) sret))
332 if (NULL !=
request->dns_lookup)
335 if (NULL != (vpn_ctx =
request->vpn_ctx))
366 if (
request->original_request_id != dns->
id)
376 _ (
"Failed to parse DNS response!\n"));
402 const void *vaddress)
417 for (i = 0; i < vpn_ctx->
rd_count; i++)
450 _ (
"VPN returned empty result for `%s'\n"),
451 request->packet->queries[0].name);
487 "Using DNS resolver IP `%s' to resolve `%s'\n",
489 request->packet->queries[0].name);
510 for (uint32_t i = 0; i <
rd_count; i++)
513 switch (
rd[i].record_type)
571 vname = (
const char *) &vpn[1];
572 if (
'\0' != vname[
rd[i].
data_size - 1 -
sizeof(
struct
582 "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n",
586 (
int) ntohs (vpn->
proto));
653 _ (
"Cannot parse DNS request from %s\n"),
658 "Received request for `%s' with flags %u, #answers %d, #auth %d, #additional %d\n",
669 _ (
"Received malformed DNS request from %s\n"),
677 _ (
"Received unsupported DNS request from %s\n"),
691 request->udp_msg_size = udp_msg_size;
698 "Calling GNS on `%s'\n",
717 struct sockaddr_in v4;
740 addrlen =
sizeof(v4);
744 (
struct sockaddr *) &v4,
770 struct sockaddr_in6 v6;
793 addrlen =
sizeof(v6);
797 (
struct sockaddr *) &v6,
838 _ (
"No DNS server specified!\n"));
867 "Don't know what to bind to...\n");
872 if (1 != inet_pton (AF_INET, addr_str, &
address))
875 "Unable to parse address %s\n",
889 "Don't know what to bind6 to...\n");
894 if (1 != inet_pton (AF_INET6, addr_str, &
address6))
897 "Unable to parse IPv6 address %s\n",
915 struct sockaddr_in v4;
917 memset (&v4, 0,
sizeof(v4));
918 v4.sin_family = AF_INET;
920#if HAVE_SOCKADDR_IN_SIN_LEN
921 v4.sin_len =
sizeof(v4);
926 (
struct sockaddr *) &v4,
939 struct sockaddr_in6 v6;
941 memset (&v6, 0,
sizeof(v6));
942 v6.sin6_family = AF_INET6;
944#if HAVE_SOCKADDR_IN_SIN_LEN
945 v6.sin6_len =
sizeof(v6);
950 (
struct sockaddr *) &v6,
998 "IP of recursive DNS resolver to use (required)"),
1015 _ (
"GNUnet DNS-to-GNS proxy (a DNS server)"),
1017 &
run, NULL)) ? 0 : 1;
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
#define gettext_noop(String)
static int ret
Final status code.
static char * data
The data to insert into the dht.
struct GNUNET_GNS_Handle * gns
Handle to GNS resolver.
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.
static void read_dns6(void *cls)
Task to read IPv6 DNS packets.
static struct GNUNET_VPN_Handle * vpn_handle
Our handle to the vpn service.
static struct GNUNET_NETWORK_Handle * listen_socket6
Listen socket for IPv6.
static unsigned long long listen_port
UDP Port we listen on for inbound DNS requests.
static void do_timeout(void *cls)
Task run on timeout.
#define TIMEOUT
Timeout for DNS requests.
static char * dns_ip
IP of DNS server.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
static void shuffle_answers(struct Request *request)
Shuffle answers Fisher-Yates (aka Knuth) Shuffle.
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.
static struct in6_addr address6
The IPv6 address to bind to.
static void do_shutdown(void *cls)
Task run on shutdown.
static void vpn_allocation_cb(void *cls, int af, const void *vaddress)
Callback invoked from the VPN service once a redirection is available.
struct GNUNET_DNSSTUB_Context * dns_stub
Stub resolver.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
#define VPN_TIMEOUT
Default timeout for VPN redirections.
static void read_dns4(void *cls)
Task to read IPv4 DNS packets.
static struct GNUNET_NETWORK_Handle * listen_socket4
Listen socket for IPv4.
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.
int main(int argc, char *const *argv)
The main function for the dns2gns daemon.
static in_addr_t address
The address to bind to.
static void send_response(struct Request *request)
Send the response for the given request and clean up.
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static size_t data_size
Number of bytes in data.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
API to access the VPN service.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_CNAME
#define GNUNET_DNSPARSER_TYPE_AAAA
int GNUNET_DNSPARSER_pack(const struct GNUNET_DNSPARSER_Packet *p, uint16_t max, char **buf, size_t *buf_length)
Given a DNS packet p, generate the corresponding UDP payload.
struct GNUNET_DNSPARSER_Packet * GNUNET_DNSPARSER_parse(const char *udp_payload, size_t udp_payload_length)
Parse a UDP payload of a DNS packet in to a nice struct for further processing and manipulation.
struct GNUNET_DNSSTUB_Context * GNUNET_DNSSTUB_start(unsigned int num_sockets)
Start a DNS stub resolver.
int GNUNET_DNSSTUB_add_dns_ip(struct GNUNET_DNSSTUB_Context *ctx, const char *dns_ip)
Add nameserver for use by the DNSSTUB.
void GNUNET_DNSSTUB_stop(struct GNUNET_DNSSTUB_Context *ctx)
Cleanup DNSSTUB resolver.
struct GNUNET_DNSSTUB_RequestSocket * GNUNET_DNSSTUB_resolve(struct GNUNET_DNSSTUB_Context *ctx, const void *request, size_t request_len, GNUNET_DNSSTUB_ResultCallback rc, void *rc_cls)
Perform DNS resolution using our default IP from init.
void GNUNET_DNSSTUB_resolve_cancel(struct GNUNET_DNSSTUB_RequestSocket *rs)
Cancel DNS resolution.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
struct GNUNET_GNS_LookupWithTldRequest * GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, const char *name, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor2 proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS, determining the zone using the TLD of the given ...
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
@ GNUNET_GNS_LO_DEFAULT
Defaults, look in cache, then in DHT.
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
ssize_t GNUNET_NETWORK_socket_recvfrom_amount(const struct GNUNET_NETWORK_Handle *desc)
How much data is available to be read on this descriptor?
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
@ GNUNET_SCHEDULER_REASON_READ_READY
The reading socket is ready.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
#define GNUNET_TUN_DNS_CLASS_INTERNET
A few common DNS classes (ok, only one is common, but I list a couple more to make it clear what we'r...
void GNUNET_TUN_service_name_to_hash(const char *service_name, struct GNUNET_HashCode *hc)
Hash the service name of a hosted service to the hash code that is used to identify the service on th...
#define GNUNET_TUN_DNS_RETURN_CODE_NO_ERROR
RFC 1035 codes.
struct GNUNET_VPN_Handle * GNUNET_VPN_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the VPN service.
struct GNUNET_VPN_RedirectionRequest * GNUNET_VPN_redirect_to_peer(struct GNUNET_VPN_Handle *vh, int result_af, uint8_t protocol, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *serv, struct GNUNET_TIME_Absolute expiration_time, GNUNET_VPN_AllocationCallback cb, void *cb_cls)
Tell the VPN that a forwarding to a particular peer offering a particular service is requested.
void GNUNET_VPN_cancel_request(struct GNUNET_VPN_RedirectionRequest *rr)
Cancel redirection request with the service.
void GNUNET_VPN_disconnect(struct GNUNET_VPN_Handle *vh)
Disconnect from the VPN service.
static unsigned int size
Size of the "table".
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
#define GNUNET_GNSRECORD_TYPE_VPN
VPN resolution.
Easy-to-process, parsed version of a DNS packet.
struct GNUNET_DNSPARSER_Query * queries
Array of all queries in the packet, must contain "num_queries" entries.
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
struct GNUNET_TUN_DnsFlags flags
Bitfield of DNS flags.
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
unsigned int num_queries
Number of queries in the packet.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
char * name
Name of the record that the query is for (0-terminated).
void * data
Binary record data.
size_t data_len
Number of bytes in data.
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
struct GNUNET_TIME_Absolute expiration_time
When does the record expire?
char * name
Name of the record that the query is for (0-terminated).
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
union GNUNET_DNSPARSER_Record::@20 data
Payload of the record (which one of these is valid depends on the 'type').
Handle to the stub resolver.
UDP socket we are using for sending DNS requests to the Internet.
Definition of a command line option.
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Connection to the GNS service.
Handle to a lookup request.
Context information passed to each scheduler task.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
Entry in list of pending tasks.
uint64_t abs_value_us
The actual value.
unsigned int checking_disabled
See RFC 4035.
unsigned int zero
Always zero.
unsigned int message_truncated
Set to 1 if message is truncated.
unsigned int query_or_response
query:0, response:1
unsigned int return_code
See GNUNET_TUN_DNS_RETURN_CODE_ defines.
unsigned int recursion_available
Set to 1 if recursion is available (server -> client)
unsigned int authenticated_data
Response has been cryptographically verified, RFC 4035.
unsigned int authoritative_answer
Set to 1 if this is an authoritative answer.
Payload of GNS VPN record.
struct GNUNET_PeerIdentity peer
The peer to contact.
uint16_t proto
The protocol to use.
Opaque redirection request handle.
const void * addr
Target IP address for the redirection, or NULL for redirection to service.
struct GNUNET_NETWORK_Handle * lsock
Socket to use for sending the reply.
size_t udp_msg_size
Number of bytes in udp_msg.
struct GNUNET_SCHEDULER_Task * timeout_task
Task run on timeout or shutdown to clean up without response.
uint16_t original_request_id
ID of the original request.
struct GNUNET_DNSPARSER_Packet * packet
Initially, this is the DNS request, it will then be converted to the DNS response.
const void * addr
Destination address to use.
struct VpnContext * vpn_ctx
Vpn resolution context.
struct GNUNET_DNSSTUB_RequestSocket * dns_lookup
Our DNS request handle.
size_t addr_len
Number of bytes in addr.
struct GNUNET_GNS_LookupWithTldRequest * lookup
Our GNS request handle.
char * udp_msg
Original UDP request message.
Closure for vpn_allocation_cb.
struct GNUNET_VPN_RedirectionRequest * vpn_request
Handle to the VPN request that we were performing.
ssize_t rd_data_size
Number of bytes in rd_data.
struct Request * request
Which resolution process are we processing.
char * rd_data
Serialized records.
unsigned int rd_count
Number of records serialized in rd_data.