dnsserv.c File Reference

Implements client-side DNS proxy server code. More...

#include "core/or/or.h"
#include "feature/client/dnsserv.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "feature/control/control_events.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/netstatus.h"
#include "core/or/policies.h"
#include "feature/control/control_connection_st.h"
#include "core/or/entry_connection_st.h"
#include "core/or/listener_connection_st.h"
#include "core/or/socks_request_st.h"
#include "lib/evloop/compat_libevent.h"
#include <event2/dns.h>
#include <event2/dns_compat.h>
#include <event2/dns_struct.h>

Go to the source code of this file.


static void evdns_server_callback (struct evdns_server_request *req, void *data_)
int dnsserv_launch_request (const char *name, int reverse, control_connection_t *control_conn)
void dnsserv_reject_request (entry_connection_t *conn)
static const char * evdns_get_orig_address (const struct evdns_server_request *req, int rtype, const char *addr)
void dnsserv_resolved (entry_connection_t *conn, int answer_type, size_t answer_len, const char *answer, int ttl)
void dnsserv_configure_listener (connection_t *conn)
void dnsserv_close_listener (connection_t *conn)

Detailed Description

Implements client-side DNS proxy server code.

When a user enables the DNSPort configuration option to have their local Tor client handle DNS requests, this module handles it. It functions as a "DNS Server" on the client side, which client applications use.

Inbound DNS requests are represented as entry_connection_t here (since that's how Tor represents client-side streams), which are kept associated with an evdns_server_request structure as exposed by Libevent's evdns code.

Upon receiving a DNS request, libevent calls our evdns_server_callback() function here, which causes this module to create an entry_connection_t request as appropriate. Later, when that request is answered, connection_edge.c calls dnsserv_resolved() so we can finish up and tell the DNS client.

Definition in file dnsserv.c.

Function Documentation

◆ dnsserv_close_listener()

void dnsserv_close_listener ( connection_t conn)

Free the evdns server port for conn, which must be an AP_DNS_LISTENER.

Definition at line 407 of file dnsserv.c.

◆ dnsserv_configure_listener()

void dnsserv_configure_listener ( connection_t conn)

Set up the evdns server port for the UDP socket on conn, which must be an AP_DNS_LISTENER

Definition at line 391 of file dnsserv.c.

◆ dnsserv_launch_request()

int dnsserv_launch_request ( const char *  name,
int  reverse,
control_connection_t control_conn 

Helper function: called whenever the client sends a resolve request to our controller. We need to eventually answer the request req. Returns 0 if the controller will be getting (or has gotten) an event in response; -1 if we couldn't launch the request.

Definition at line 210 of file dnsserv.c.

◆ dnsserv_reject_request()

void dnsserv_reject_request ( entry_connection_t conn)

If there is a pending request on conn that's waiting for an answer, send back an error and free the request.

Definition at line 289 of file dnsserv.c.

◆ dnsserv_resolved()

void dnsserv_resolved ( entry_connection_t conn,
int  answer_type,
size_t  answer_len,
const char *  answer,
int  ttl 

Tell the dns request waiting for an answer on conn that we have an answer of type answer_type (RESOLVE_TYPE_IPV4/IPV6/ERR), of length answer_len, in answer, with TTL ttl. Doesn't do any caching; that's handled elsewhere.

Definition at line 339 of file dnsserv.c.

◆ evdns_get_orig_address()

static const char* evdns_get_orig_address ( const struct evdns_server_request *  req,
int  rtype,
const char *  addr 

Look up the original name that corresponds to 'addr' in req. We use this to preserve case in order to facilitate clients using 0x20-hacks to avoid DNS poisoning.

Definition at line 302 of file dnsserv.c.

Referenced by dnsserv_resolved().

◆ evdns_server_callback()

static void evdns_server_callback ( struct evdns_server_request *  req,
void *  data_ 

Helper function: called by evdns whenever the client sends a request to our DNSPort. We need to eventually answer the request req.

Definition at line 49 of file dnsserv.c.