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