2017-06-27 21:31:48 +00:00
|
|
|
From b38575cb49041e586b0732d759a06801e587bb90 Mon Sep 17 00:00:00 2001
|
2017-06-27 18:23:48 +00:00
|
|
|
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
|
Date: Tue, 27 Jun 2017 14:20:00 -0400
|
|
|
|
Subject: [PATCH] resolved: do not allocate packets with minimum size
|
|
|
|
|
|
|
|
dns_packet_new() is sometimes called with mtu == 0, and in that case we should
|
|
|
|
allocate more than the absolute minimum (which is the dns packet header size),
|
|
|
|
otherwise we have to resize immediately again after appending the first data to
|
|
|
|
the packet.
|
|
|
|
|
|
|
|
This partially reverts the previous commit.
|
2017-06-27 21:31:48 +00:00
|
|
|
|
|
|
|
(cherry picked from commit 88795538726a5bbfd9efc13d441cb05e1d7fc139)
|
2017-06-27 18:23:48 +00:00
|
|
|
---
|
2017-06-27 21:31:48 +00:00
|
|
|
src/resolve/resolved-dns-packet.c | 12 +++++++++++-
|
|
|
|
1 file changed, 11 insertions(+), 1 deletion(-)
|
2017-06-27 18:23:48 +00:00
|
|
|
|
|
|
|
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
|
2017-06-27 21:31:48 +00:00
|
|
|
index 821b66e266..d1f0f760a4 100644
|
2017-06-27 18:23:48 +00:00
|
|
|
--- a/src/resolve/resolved-dns-packet.c
|
|
|
|
+++ b/src/resolve/resolved-dns-packet.c
|
|
|
|
@@ -28,6 +28,9 @@
|
|
|
|
|
|
|
|
#define EDNS0_OPT_DO (1<<15)
|
|
|
|
|
|
|
|
+#define DNS_PACKET_SIZE_START 512
|
|
|
|
+assert_cc(DNS_PACKET_SIZE_START > UDP_PACKET_HEADER_SIZE)
|
|
|
|
+
|
|
|
|
typedef struct DnsPacketRewinder {
|
|
|
|
DnsPacket *packet;
|
|
|
|
size_t saved_rindex;
|
2017-06-27 21:31:48 +00:00
|
|
|
@@ -47,7 +50,14 @@ int dns_packet_new(DnsPacket **ret, DnsProtocol protocol, size_t mtu) {
|
2017-06-27 18:23:48 +00:00
|
|
|
|
|
|
|
assert(ret);
|
|
|
|
|
|
|
|
- a = MAX(mtu, DNS_PACKET_HEADER_SIZE);
|
2017-06-27 21:31:48 +00:00
|
|
|
+ /* When dns_packet_new() is called with mtu == 0, allocate more than the
|
|
|
|
+ * absolute minimum (which is the dns packet header size), to avoid
|
|
|
|
+ * resizing immediately again after appending the first data to the packet.
|
|
|
|
+ */
|
2017-06-27 18:23:48 +00:00
|
|
|
+ if (mtu < UDP_PACKET_HEADER_SIZE)
|
|
|
|
+ a = DNS_PACKET_SIZE_START;
|
|
|
|
+ else
|
|
|
|
+ a = MAX(mtu, DNS_PACKET_HEADER_SIZE);
|
|
|
|
|
|
|
|
/* round up to next page size */
|
|
|
|
a = PAGE_ALIGN(ALIGN(sizeof(DnsPacket)) + a) - ALIGN(sizeof(DnsPacket));
|
|
|
|
--
|
|
|
|
2.13.0
|
|
|
|
|