From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 2237C5A031A for ; Wed, 24 Jul 2024 08:21:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1721802060; bh=qaVVt2Ch1iJADKXWU7i/9aWKjDJ++LpKjUAJH6tTN+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hHzU87fPQnnRCwmuiy8ggdqs9SMHxW112nM2TJxHsRuAwlSgM8brXLPh15sfKtYHt FiHR26LkQONwuO9/OKxvIMMPVYjl5znl8nFGBLH7XSjuECtn5YiNLkJUrG85ZM+S7B bd3Mbp1jfkrO3JidoOtVtkDK8JsTTYcbyikLkkVyKWAS+itQaXXZOXCrMBWw8PQL+9 HY7y0SxxNJu6dCrBqhLiSUYD0+0u003WnFRwAEJwX3tqrIr3FlnBg/WBSJrXfP4CxF 5VuLxzyV3se5f22V2stViXwY9zn9BqR5xgtUAinFchOnEIzSpjaMPWbROyIylBV0H5 +AGpshp240PZA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WTP642WR9z4x0t; Wed, 24 Jul 2024 16:21:00 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/2] fwd: Broaden what we consider for DNS specific forwarding rules Date: Wed, 24 Jul 2024 16:20:58 +1000 Message-ID: <20240724062058.1259033-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240724062058.1259033-1-david@gibson.dropbear.id.au> References: <20240724062058.1259033-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 3J75PNZLEUYVC4DFQP2T3EY65BJV6NUV X-Message-ID-Hash: 3J75PNZLEUYVC4DFQP2T3EY65BJV6NUV X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: passt/pasta has options to redirect DNS requests from the guest to a different server address on the host side. Currently, however, only UDP packets to port 53 are considered "DNS requests". This ignores DNS requests over TCP - less common, but certainly possible. It also ignores encrypted DNS requests on port 853. Extend the DNS forwarding logic to handle both of those cases. Link: https://github.com/containers/podman/issues/23239 Signed-off-by: David Gibson --- fwd.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/fwd.c b/fwd.c index bd16ac42..3f864f85 100644 --- a/fwd.c +++ b/fwd.c @@ -156,6 +156,20 @@ void fwd_scan_ports_init(struct ctx *c) } } +/** + * is_dns_flow() - Determine if flow appears to be a DNS request + * @proto: Protocol (IP L4 protocol number) + * @ini: Flow address information of the initiating side + * + * Return: true if the flow appears to be directed at a dns server, that is a + * TCP or UDP flow to port 53 (domain) or port 853 (domain-s) + */ +static bool is_dns_flow(uint8_t proto, const struct flowside *ini) +{ + return ((proto == IPPROTO_UDP) || (proto == IPPROTO_TCP)) && + ((ini->fport == 53) || (ini->fport == 853)); +} + /** * fwd_nat_from_tap() - Determine to forward a flow from the tap interface * @c: Execution context @@ -169,10 +183,10 @@ void fwd_scan_ports_init(struct ctx *c) uint8_t fwd_nat_from_tap(const struct ctx *c, uint8_t proto, const struct flowside *ini, struct flowside *tgt) { - if (proto == IPPROTO_UDP && ini->fport == 53 && + if (is_dns_flow(proto, ini) && inany_equals4(&ini->faddr, &c->ip4.dns_match)) { tgt->eaddr = inany_from_v4(c->ip4.dns_host); - } else if (proto == IPPROTO_UDP && ini->fport == 53 && + } else if (is_dns_flow(proto, ini) && inany_equals6(&ini->faddr, &c->ip6.dns_match)) { tgt->eaddr.a6 = c->ip6.dns_host; } else if (!c->no_map_gw && inany_equals4(&ini->faddr, &c->ip4.gw)) { -- 2.45.2