public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, Paul Holzinger <pholzing@redhat.com>
Subject: Re: [PATCH 3/3] udp: Check for answers to forwarded DNS queries before handling local redirects
Date: Tue, 8 Nov 2022 16:51:35 +1100	[thread overview]
Message-ID: <Y2nuZ3Ybf8fDK2Gk@yekko> (raw)
In-Reply-To: <20221107105121.37735a0b@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 5183 bytes --]

On Mon, Nov 07, 2022 at 10:51:21AM +0100, Stefano Brivio wrote:
> On Mon, 7 Nov 2022 12:08:59 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > On Sat, Nov 05, 2022 at 08:22:23AM +0100, Stefano Brivio wrote:
> > > On Sat, 5 Nov 2022 12:19:55 +1100
> > > David Gibson <david@gibson.dropbear.id.au> wrote:
> > >   
> > > > On Thu, Nov 03, 2022 at 07:42:51AM +0100, Stefano Brivio wrote:  
> > > > > On Thu, 3 Nov 2022 14:42:13 +1100
> > > > > David Gibson <david@gibson.dropbear.id.au> wrote:
> > > > >     
> > > > > > On Thu, Nov 03, 2022 at 12:04:43AM +0100, Stefano Brivio wrote:    
> > > > > > > Now that we allow loopback DNS addresses to be used as targets for
> > > > > > > forwarding, we need to check if DNS answers come from those targets,
> > > > > > > before deciding to eventually remap traffic for local redirects.
> > > > > > > 
> > > > > > > Otherwise, the source address won't match the one configured as
> > > > > > > forwarder, which means that the guest or the container will refuse
> > > > > > > those responses.
> > > > > > > 
> > > > > > > Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
> > > > > > > ---
> > > > > > >  udp.c | 17 ++++++++---------
> > > > > > >  1 file changed, 8 insertions(+), 9 deletions(-)
> > > > > > > 
> > > > > > > diff --git a/udp.c b/udp.c
> > > > > > > index 4b201d3..7c77e09 100644
> > > > > > > --- a/udp.c
> > > > > > > +++ b/udp.c
> > > > > > > @@ -680,8 +680,10 @@ static void udp_sock_fill_data_v4(const struct ctx *c, int n,
> > > > > > >  	src = ntohl(b->s_in.sin_addr.s_addr);
> > > > > > >  	src_port = ntohs(b->s_in.sin_port);
> > > > > > >  
> > > > > > > -	if (src >> IN_CLASSA_NSHIFT == IN_LOOPBACKNET ||
> > > > > > > -	    src == INADDR_ANY || src == ntohl(c->ip4.addr_seen)) {
> > > > > > > +	if (c->ip4.dns_fwd && src == htonl(c->ip4.dns[0]) && src_port == 53) {      
> > > > > > 
> > > > > > I guess this is not a newly introduced bug, but for the case of
> > > > > > multiple host nameservers, don't you need to check against everything
> > > > > > in the ip4.dns[] array, not just entry 0?    
> > > > > 
> > > > > No, because that's the only one we're using as target for forwarded
> > > > > queries -- and DNS answers we want to check here are only the forwarded
> > > > > ones.    
> > > > 
> > > > *thinks*  .. ok, that makes sense.  But if that's the case, won't
> > > > ip4.dns[0] be the only entry in ip4.dns[] we use for anything at all?
> > > > Can we drop the table and just keep one entry?  
> > > 
> > > Now that we have ip{4,6}.dns_send[], yes.  
> > 
> > Right, that's what I meant.
> > 
> > > We could rename .dns_send[] back to .dns[] and change the current  
> > 
> > Right, I think dns[] is a better name for it.
> > 
> > > .dns[] to .own_dns, or .fwd_dns_target, something like that. Other naming
> > > ideas welcome.  
> > 
> > Yeah, I find the current dns_fwd name not very illuminating either.
> > 
> > *thinks*  does it even make sense for dns_fwd not to be in dns_send?
> > We're intercepting queries the guest sends to @dns_fwd, so surely we
> > should also be advertising it to the guest.
> 
> I wouldn't be so sure of that "surely". In the Podman test case where I
> hit this issue, I use Podman to write to /etc/resolv.conf directly, no
> DHCP/NDP/DHCPv6 involved, and things work.
> 
> That doesn't automatically imply a use case for *not* advertising it,
> but we have several ways this can work without advertising anything, so
> there are also chances somebody might not want to advertise that in some
> obscure use case.

Right, but only the case for not advertising it matters here, and I
don't see one.  @dns_fwd (or @dns_match, as we discussed calling it
instead) is explicitly a virtual DNS server available to the guest.
Whatever method the guest does use to configure itself, we should
allow it to discover this via DHCP (or DHCPv6 or NDP).

> > So what about:
> > 
> >    @dns:	Primary DNS server advertised to guest - may be a fake
> > 		address we'll intercept
> >    @dns_extra[]:Additional DNS servers advertised to guest.  Must be
> > 		real servers the guest can address without translation
> >    @host_dns:	Host side DNS server (may be localhost or another
> > 		address that's not guest accessible)
> > 
> > The DHCP code advertises both @dns and @dns_extra, and that's the
> > *only* place @dns_extra is used.
> 
> Also NDP and DHCPv6 use that, and checking one item plus one array in
> three places (difficult to share that code path) is uglier than just the
> array.
> 
> > UDP intercepts outbound packets for @dns and redirects them to
> > @host_dns, likewise masquerading inbound packets from @host_dns to
> > appear to have come from @dns.
> 
> I see the general point, but we would still need a flag to allow users
> to disable the redirection.
> 
> Given that, I'd rather go with dns, host_dns, and fwd_dns, it looks
> simpler.


-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-11-08  5:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02 23:04 [PATCH 0/3] Fixes and workarounds for pasta with Podman in Google Cloud Stefano Brivio
2022-11-02 23:04 ` [PATCH 1/3] conf: Consistency check between configured IPv4 netmask and gateway Stefano Brivio
2022-11-03  3:17   ` David Gibson
2022-11-03  6:39     ` Stefano Brivio
2022-11-02 23:04 ` [PATCH 2/3] conf: Split the notions of read DNS addresses and offered ones Stefano Brivio
2022-11-03  3:37   ` David Gibson
2022-11-03  6:42     ` Stefano Brivio
2022-11-02 23:04 ` [PATCH 3/3] udp: Check for answers to forwarded DNS queries before handling local redirects Stefano Brivio
2022-11-03  3:42   ` David Gibson
2022-11-03  6:42     ` Stefano Brivio
2022-11-05  1:19       ` David Gibson
2022-11-06 22:22         ` Stefano Brivio
2022-11-07  1:08           ` David Gibson
2022-11-07  9:51             ` Stefano Brivio
2022-11-08  5:51               ` David Gibson [this message]
2022-11-08  6:22                 ` Stefano Brivio
2022-11-10  4:30                   ` David Gibson
2022-11-03  3:13 ` [PATCH 0/3] Fixes and workarounds for pasta with Podman in Google Cloud David Gibson
2022-11-03  6:36   ` Stefano Brivio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2nuZ3Ybf8fDK2Gk@yekko \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=pholzing@redhat.com \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).