Browse Source

[Project] Rdns: Add more functions for TCP based requests

tags/3.2
Vsevolod Stakhov 2 years ago
parent
commit
be5153fa1b

+ 3
- 1
contrib/librdns/dns_private.h View File

@@ -34,7 +34,7 @@

static const int dns_port = 53;
static const int default_io_cnt = 8;
static const int default_tcp_io_cnt = 2;
static const int default_tcp_io_cnt = 1;

#define UDP_PACKET_SIZE (4096 * 2)

@@ -174,10 +174,12 @@ struct rdns_tcp_channel {
};

KHASH_DECLARE(rdns_requests_hash, int, struct rdns_request *);
#define RDNS_IO_CHANNEL_TAG UINT64_C(0xe190a5ba12f094c8)
/**
* IO channel for a specific DNS server
*/
struct rdns_io_channel {
uint64_t struct_magic; /**< tag for this structure */
struct rdns_server *srv;
struct rdns_resolver *resolver;
struct sockaddr *saddr;

+ 1
- 1
contrib/librdns/rdns.h View File

@@ -480,7 +480,7 @@ bool rdns_format_dns_name (struct rdns_resolver *resolver,

void rdns_process_read (int fd, void *arg);
void rdns_process_timer (void *arg);
void rdns_process_retransmit (int fd, void *arg);
void rdns_process_write (int fd, void *arg);

#ifdef __cplusplus
}

+ 1
- 1
contrib/librdns/rdns_ev.h View File

@@ -88,7 +88,7 @@ rdns_libev_read_event (struct ev_loop *loop, ev_io *ev, int revents)
static void
rdns_libev_write_event (struct ev_loop *loop, ev_io *ev, int revents)
{
rdns_process_retransmit (ev->fd, ev->data);
rdns_process_write(ev->fd, ev->data);
}

static void

+ 1
- 1
contrib/librdns/rdns_event.h View File

@@ -85,7 +85,7 @@ rdns_libevent_read_event (int fd, short what, void *ud)
static void
rdns_libevent_write_event (int fd, short what, void *ud)
{
rdns_process_retransmit (fd, ud);
rdns_process_write (fd, ud);
}

static void

+ 44
- 5
contrib/librdns/resolver.c View File

@@ -562,10 +562,9 @@ rdns_process_ioc_refresh (void *arg)
}
}

void
rdns_process_retransmit (int fd, void *arg)
static void
rdns_process_udp_retransmit (int fd, struct rdns_request *req)
{
struct rdns_request *req = (struct rdns_request *)arg;
struct rdns_resolver *resolver;
struct rdns_reply *rep;
int r;
@@ -589,7 +588,7 @@ rdns_process_retransmit (int fd, void *arg)
if (r == 0) {
/* Retransmit one more time */
req->async_event = req->async->add_write (req->async->data,
fd, req);
fd, req);
req->state = RDNS_REQUEST_WAIT_SEND;
}
else if (r == -1) {
@@ -608,11 +607,50 @@ rdns_process_retransmit (int fd, void *arg)
}
else {
req->async_event = req->async->add_timer (req->async->data,
req->timeout, req);
req->timeout, req);
req->state = RDNS_REQUEST_WAIT_REPLY;
}
}

static void
rdns_process_tcp_write (int fd, struct rdns_io_channel *ioc)
{

}

void
rdns_process_write (int fd, void *arg)
{
/*
* We first need to dispatch *arg to understand what has caused the write
* readiness event.
* The one possibility is that it was a UDP retransmit request, so our
* arg will be struct rdns_request *
* Another possibility is that write event was triggered by some TCP related
* stuff. In this case the only possibility is that our arg is struct rdns_io_channel *
* To distinguish these two cases (due to flaws in the rdns architecture in the first
* place) we compare the first 8 bytes with RDNS_IO_CHANNEL_TAG
*/
uint64_t tag;

memcpy (&tag, arg, sizeof(tag));

if (tag == RDNS_IO_CHANNEL_TAG) {
struct rdns_io_channel *ioc = (struct rdns_io_channel *) arg;

if (IS_CHANNEL_CONNECTED(ioc)) {
rdns_process_tcp_write(fd, ioc);
}
else {
rdns_process_tcp_connect(fd, ioc);
}
}
else {
struct rdns_request *req = (struct rdns_request *) arg;
rdns_process_udp_retransmit(fd, req);
}
}

struct rdns_server *
rdns_select_request_upstream (struct rdns_resolver *resolver,
struct rdns_request *req,
@@ -1116,6 +1154,7 @@ rdns_resolver_free (struct rdns_resolver *resolver)
}
UPSTREAM_DEL (resolver->servers, serv);
free (serv->io_channels);
free (serv->tcp_io_channels);
free (serv->name);
free (serv);
}

+ 1
- 0
contrib/librdns/util.c View File

@@ -540,6 +540,7 @@ rdns_ioc_new (struct rdns_server *serv,
return NULL;
}

nioc->struct_magic = RDNS_IO_CHANNEL_TAG;
nioc->sock = rdns_make_client_socket (serv->name, serv->port,
is_tcp ? SOCK_STREAM : SOCK_DGRAM, &nioc->saddr, &nioc->slen);
if (nioc->sock == -1) {

Loading…
Cancel
Save