The DNS code defines separate maximum message sizes for datagram and
stream processing, but both are the DNS protocol limit of 65535 bytes.
The duplicate names make common response buffers look transport-specific
and could allow the values to diverge.
Replace them with DNS_MAX_MSG_SIZE. This does not change any limit or
runtime behavior.
---
include/haproxy/dns-t.h | 4 ++--
include/haproxy/resolvers-t.h | 5 ++---
src/dns.c | 16 ++++++++--------
src/resolvers.c | 6 +++---
4 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/include/haproxy/dns-t.h b/include/haproxy/dns-t.h
index 10175cfdf..c00075572 100644
--- a/include/haproxy/dns-t.h
+++ b/include/haproxy/dns-t.h
@@ -39,8 +39,8 @@
/* max pending requests per stream */
#define DNS_STREAM_MAX_PIPELINED_REQ 4
-#define DNS_TCP_MSG_MAX_SIZE 65535
-#define DNS_TCP_MSG_RING_MAX_SIZE (1 + 1 + 3 + DNS_TCP_MSG_MAX_SIZE) //
varint_bytes(DNS_TCP_MSG_MAX_SIZE) == 3
+#define DNS_MAX_MSG_SIZE 65535
+#define DNS_TCP_MSG_RING_MAX_SIZE (1 + 1 + 3 + DNS_MAX_MSG_SIZE) //
varint_bytes(DNS_MAX_MSG_SIZE) == 3
/* threshold to consider that the link to dns server is failing
* and we should stop creating new sessions
diff --git a/include/haproxy/resolvers-t.h b/include/haproxy/resolvers-t.h
index f0c92084c..4b7213a0a 100644
--- a/include/haproxy/resolvers-t.h
+++ b/include/haproxy/resolvers-t.h
@@ -40,7 +40,6 @@ extern struct pool_head *resolv_requester_pool;
*/
#define DNS_MAX_LABEL_SIZE 63
#define DNS_MAX_NAME_SIZE 255
-#define DNS_MAX_UDP_MESSAGE 65535
/* DNS minimum record size: 1 char + 1 NULL + type + class */
#define DNS_MIN_RECORD_SIZE (1 + 1 + 2 + 2)
@@ -53,13 +52,13 @@ extern struct pool_head *resolv_requester_pool;
#define DNS_MAX_QUERY_RECORDS 1
/* maximum number of answer record in a DNS response */
-#define DNS_MAX_ANSWER_RECORDS ((DNS_MAX_UDP_MESSAGE - DNS_HEADER_SIZE) /
DNS_MIN_RECORD_SIZE)
+#define DNS_MAX_ANSWER_RECORDS ((DNS_MAX_MSG_SIZE - DNS_HEADER_SIZE) /
DNS_MIN_RECORD_SIZE)
/* size of dns_buffer used to store responses from the buffer
* dns_buffer is used to store data collected from records found in a response.
* Before using it, caller will always check that there is at least
DNS_MAX_NAME_SIZE bytes
* available */
-#define DNS_ANALYZE_BUFFER_SIZE DNS_MAX_UDP_MESSAGE + DNS_MAX_NAME_SIZE
+#define DNS_ANALYZE_BUFFER_SIZE (DNS_MAX_MSG_SIZE + DNS_MAX_NAME_SIZE)
/* DNS error messages */
#define DNS_TOO_LONG_FQDN "hostname too long"
diff --git a/src/dns.c b/src/dns.c
index 53e71de0e..460af2def 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -171,7 +171,7 @@ int dns_send_nameserver(struct dns_nameserver *ns, void
*buf, size_t len)
struct ist myist;
myist = ist2(buf, len);
- ret = dns_ring_write(ns->dgram->ring_req,
DNS_TCP_MSG_MAX_SIZE, NULL, 0, &myist, 1);
+ ret = dns_ring_write(ns->dgram->ring_req,
DNS_MAX_MSG_SIZE, NULL, 0, &myist, 1);
if (!ret) {
ns->counters->snd_error++;
HA_SPIN_UNLOCK(DNS_LOCK, &dgram->lock);
@@ -194,7 +194,7 @@ int dns_send_nameserver(struct dns_nameserver *ns, void
*buf, size_t len)
struct ist myist;
myist = ist2(buf, len);
- ret = dns_ring_write(ns->stream->ring_req,
DNS_TCP_MSG_MAX_SIZE, NULL, 0, &myist, 1);
+ ret = dns_ring_write(ns->stream->ring_req, DNS_MAX_MSG_SIZE,
NULL, 0, &myist, 1);
if (!ret) {
ns->counters->snd_error++;
return -1;
@@ -420,7 +420,7 @@ static void dns_resolve_send(struct dgram_conn *dgram)
break;
cnt += len;
BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf));
- if (unlikely(msg_len > DNS_TCP_MSG_MAX_SIZE)) {
+ if (unlikely(msg_len > DNS_MAX_MSG_SIZE)) {
/* too large a message to ever fit, let's skip it */
ofs += cnt + msg_len;
continue;
@@ -1244,7 +1244,7 @@ static struct task *dns_process_req(struct task *t, void
*context, unsigned int
break;
cnt += len;
BUG_ON(msg_len + ofs + cnt + 1 > b_data(buf));
- if (unlikely(msg_len > DNS_TCP_MSG_MAX_SIZE)) {
+ if (unlikely(msg_len > DNS_MAX_MSG_SIZE)) {
/* too large a message to ever fit, let's skip it */
ofs += cnt + msg_len;
continue;
@@ -1259,7 +1259,7 @@ static struct task *dns_process_req(struct task *t, void
*context, unsigned int
if (!LIST_ISEMPTY(&dss->free_sess)) {
ds = LIST_NEXT(&dss->free_sess, struct dns_session *,
list);
- if (dns_ring_write(&ds->ring, DNS_TCP_MSG_MAX_SIZE,
NULL, 0, &myist, 1) > 0) {
+ if (dns_ring_write(&ds->ring, DNS_MAX_MSG_SIZE, NULL,
0, &myist, 1) > 0) {
ds->nb_queries++;
if (ds->nb_queries >=
DNS_STREAM_MAX_PIPELINED_REQ)
LIST_DEL_INIT(&ds->list);
@@ -1280,7 +1280,7 @@ static struct task *dns_process_req(struct task *t, void
*context, unsigned int
ds = LIST_NEXT(&dss->idle_sess, struct
dns_session *, list);
/* ring is empty so this dns_ring_write should
never fail */
- dns_ring_write(&ds->ring, DNS_TCP_MSG_MAX_SIZE,
NULL, 0, &myist, 1);
+ dns_ring_write(&ds->ring, DNS_MAX_MSG_SIZE,
NULL, 0, &myist, 1);
ds->nb_queries++;
LIST_DEL_INIT(&ds->list);
@@ -1305,7 +1305,7 @@ static struct task *dns_process_req(struct task *t, void
*context, unsigned int
ads = dns_session_new(dss);
if (ads) {
/* ring is empty so this dns_ring_write should
never fail */
- dns_ring_write(&ads->ring,
DNS_TCP_MSG_MAX_SIZE, NULL, 0, &myist, 1);
+ dns_ring_write(&ads->ring, DNS_MAX_MSG_SIZE,
NULL, 0, &myist, 1);
ads->nb_queries++;
LIST_INSERT(&dss->free_sess, &ads->list);
}
@@ -1438,7 +1438,7 @@ void dns_nameserver_deinit(struct dns_nameserver *ns)
int init_dns_buffers()
{
- dns_msg_trash = malloc(DNS_TCP_MSG_MAX_SIZE);
+ dns_msg_trash = malloc(DNS_MAX_MSG_SIZE);
if (!dns_msg_trash)
return 0;
diff --git a/src/resolvers.c b/src/resolvers.c
index 9f4e5fc0d..6700bdeaf 100644
--- a/src/resolvers.c
+++ b/src/resolvers.c
@@ -2325,7 +2325,7 @@ static int resolv_process_responses(struct dns_nameserver
*ns)
struct dns_counters *tmpcounters;
struct resolvers *resolvers;
struct resolv_resolution *res;
- unsigned char buf[DNS_MAX_UDP_MESSAGE + 1];
+ unsigned char buf[DNS_MAX_MSG_SIZE + 1];
unsigned char *bufend;
int buflen, dns_resp;
int max_answer_records;
@@ -3924,9 +3924,9 @@ int cfg_parse_resolvers(const char *file, int linenum,
char **args, int kwm)
}
i = atoi(args[1]);
- if (i < DNS_HEADER_SIZE || i > DNS_MAX_UDP_MESSAGE) {
+ if (i < DNS_HEADER_SIZE || i > DNS_MAX_MSG_SIZE) {
ha_alert("parsing [%s:%d] : '%s' must be between %d and
%d inclusive (was %s).\n",
- file, linenum, args[0], DNS_HEADER_SIZE,
DNS_MAX_UDP_MESSAGE, args[1]);
+ file, linenum, args[0], DNS_HEADER_SIZE,
DNS_MAX_MSG_SIZE, args[1]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
--
2.55.0