Skip to content

Commit d26a623

Browse files
EmericBrwtarreau
authored andcommitted
MEDIUM: resolvers: split resolving and dns message exchange layers.
This patch splits recv and send functions in two layers. the lowest is responsible of DNS message transactions over the network. Doing this we could use DNS message layer for something else than resolving. Load balancing for instance. This patch also re-works the way to init a nameserver and introduce the new struct dns_dgram_server to prepare the arrival of dns_stream_server and the support of DNS over TCP. The way to retry a send failure of a request because of EAGAIN was re-worked. Previously there was no control and all "pending" queries were re-played each time it reaches a EAGAIN. This patch introduce a ring to stack messages in case of sent failure. This patch is emptied if poller shows that the socket is ready again to push messages.
1 parent d3b4495 commit d26a623

File tree

3 files changed

+365
-186
lines changed

3 files changed

+365
-186
lines changed

include/haproxy/dns-t.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ extern struct pool_head *resolv_requester_pool;
9595
/* DNS header size */
9696
#define DNS_HEADER_SIZE ((int)sizeof(struct dns_header))
9797

98+
#define DNS_TCP_MSG_MAX_SIZE 65535
99+
#define DNS_TCP_MSG_RING_MAX_SIZE (1 + 1 + 3 + DNS_TCP_MSG_MAX_SIZE) // varint_bytes(DNS_TCP_MSG_MAX_SIZE) == 3
100+
98101
/* DNS request or response header structure */
99102
struct dns_header {
100103
uint16_t id;
@@ -196,6 +199,12 @@ struct resolvers {
196199
} conf; /* config information */
197200
};
198201

202+
struct dns_dgram_server {
203+
struct dgram_conn conn; /* transport layer */
204+
struct ring *ring_req;
205+
size_t ofs_req; // ring buffer reader offset
206+
};
207+
199208
/* Structure describing a name server used during name resolution.
200209
* A name server belongs to a resolvers section.
201210
*/
@@ -207,8 +216,8 @@ struct dns_nameserver {
207216
int line; /* line where the section appears */
208217
} conf; /* config information */
209218

210-
struct dgram_conn *dgram; /* transport layer */
211-
struct sockaddr_storage addr; /* IP address */
219+
int (*process_responses)(struct dns_nameserver *ns); /* callback used to process responses */
220+
struct dns_dgram_server *dgram; /* used for dgram dns */
212221

213222
EXTRA_COUNTERS(extra_counters);
214223
struct dns_counters *counters;

include/haproxy/dns.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ int stats_dump_resolvers(struct stream_interface *si,
5353
struct list *stat_modules);
5454
void resolv_stats_clear_counters(int clrall, struct list *stat_modules);
5555
int resolv_allocate_counters(struct list *stat_modules);
56+
int dns_dgram_init(struct dns_nameserver *ns, struct sockaddr_storage *sk);
5657

5758
#endif // _HAPROXY_DNS_H

0 commit comments

Comments
 (0)