From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 6AAE95A0265 for ; Thu, 3 Nov 2022 07:44:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667457842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v9ElWJedcHVzJOQiNOyliFWgPtFx+I5BxjuoSa6M09g=; b=hNf3bMl56a0cZpMS2uhzNvrX5IGe4zAZrwl3QffkqPxdFV5rQ+d4wOPdYtvzD5mDAUy1Ob 7L6CXbqBdwfK+WLjifxh1YecuwakGlz8glRiL4CBu4ap9jNNWsnhq4hjvDNAzF57iKATlG +xaRK0Xkfd3FAAUmZ2m1X8tZCH/H8zc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-323-WJgM34LMNAa6EPw3ZktbAQ-1; Thu, 03 Nov 2022 02:44:01 -0400 X-MC-Unique: WJgM34LMNAa6EPw3ZktbAQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D5E1885543D; Thu, 3 Nov 2022 06:44:00 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-31.brq.redhat.com [10.40.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70EE8140EBF5; Thu, 3 Nov 2022 06:44:00 +0000 (UTC) Date: Thu, 3 Nov 2022 07:42:44 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/3] conf: Split the notions of read DNS addresses and offered ones Message-ID: <20221103074244.1da10350@elisabeth> In-Reply-To: References: <20221102230443.377446-1-sbrivio@redhat.com> <20221102230443.377446-3-sbrivio@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: WODJR4ZI36BV53TZMLJOQCJUI3SXFKFB X-Message-ID-Hash: WODJR4ZI36BV53TZMLJOQCJUI3SXFKFB X-MailFrom: sbrivio@redhat.com 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: passt-dev@passt.top, Paul Holzinger X-Mailman-Version: 3.3.3 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: On Thu, 3 Nov 2022 14:37:18 +1100 David Gibson wrote: > On Thu, Nov 03, 2022 at 12:04:42AM +0100, Stefano Brivio wrote: > > With --dns-forward, if the host has a loopback address configured as > > DNS server, we should actually use it to forward queries, but, if > > --no-map-gw is passed, we shouldn't offer the same address via DHCP, > > NDP and DHCPv6, because it's not going to be reachable. > > > > Problematic configuration: systemd-resolved configuring the usual > > 127.0.0.53 on the host, and --dns-forward specified with an unrelated > > address. We still want to forward queries to 127.0.0.53, so we can't > > drop it from the addresses in IPv4 and IPv6 context, > > I'm not entirely sure what you mean by that. Hopefully clarified enough in v2. > > but we shouldn't > > offer that address either. > > > > With this change, I'm only covering the case of automatically > > configured DNS servers from /etc/resolv.conf. We could extend this to > > addresses configured with command-line options, but I don't really > > see a likely use case at this point. > > > > Signed-off-by: Stefano Brivio > > --- > > conf.c | 50 ++++++++++++++++++++++++++++++++++---------------- > > dhcp.c | 5 +++-- > > dhcpv6.c | 5 +++-- > > ndp.c | 6 +++--- > > passt.h | 8 ++++++-- > > 5 files changed, 49 insertions(+), 25 deletions(-) > > > > diff --git a/conf.c b/conf.c > > index 5b88547..c4e1030 100644 > > --- a/conf.c > > +++ b/conf.c > > @@ -355,10 +355,11 @@ overlap: > > */ > > static void get_dns(struct ctx *c) > > { > > + uint32_t *dns4 = &c->ip4.dns[0], *dns4_send = &c->ip4.dns_send[0]; > > + struct in6_addr *dns6_send = &c->ip6.dns_send[0]; > > int dns4_set, dns6_set, dnss_set, dns_set, fd; > > struct in6_addr *dns6 = &c->ip6.dns[0]; > > struct fqdn *s = c->dns_search; > > - uint32_t *dns4 = &c->ip4.dns[0]; > > struct lineread resolvconf; > > int line_len; > > char *line, *p, *end; > > @@ -388,30 +389,45 @@ static void get_dns(struct ctx *c) > > if (!dns4_set && > > dns4 - &c->ip4.dns[0] < ARRAY_SIZE(c->ip4.dns) - 1 && > > inet_pton(AF_INET, p + 1, dns4)) { > > - /* We can only access local addresses via the gw redirect */ > > - if (ntohl(*dns4) >> IN_CLASSA_NSHIFT == IN_LOOPBACKNET) { > > - if (c->no_map_gw) { > > - *dns4 = 0; > > + /* Guest or container can only access local > > + * addresses via local redirect > > + */ > > + if (IPV4_IS_LOOPBACK(ntohl(*dns4))) { > > + if (c->no_map_gw) > > continue; > > In this case shouldn't you still be recording the local address in the > dns[] array (but not dns_send[]) since it's a valid nameserver for the > host. In which case you'd need to advance the dns4 pointer. Oops, right, fixed in v2. > If I'm mistaken and you don't want to record it in the dns[] array, > then shouldn't you clear it (because otherwise you will record it if > this is the last "nameserver" line). > > > - } > > - *dns4 = c->ip4.gw; > > + > > + *dns4_send = c->ip4.gw; > > + } else { > > + *dns4_send = *dns4; > > } > > I think it would be clearer to update *dns4 if necessary, then > set *dns4_send = *dns4 outside the if statement. Probably not relevant now that I fixed the case you mentioned above. -- Stefano