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, jmaloy@redhat.com
Subject: Re: [PATCH v6 01/26] flow: Common address information for initiating side
Date: Wed, 26 Jun 2024 10:19:31 +1000	[thread overview]
Message-ID: <Zntek-AN5cRqbJDM@zatzit> (raw)
In-Reply-To: <20240626002328.74900b0d@elisabeth>

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

On Wed, Jun 26, 2024 at 12:23:28AM +0200, Stefano Brivio wrote:
> On Fri, 14 Jun 2024 16:13:23 +1000
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > Handling of each protocol needs some degree of tracking of the
> > addresses and ports at the end of each connection or flow.  Sometimes
> > that's explicit (as in the guest visible addresses for TCP
> > connections), sometimes implicit (the bound and connected addresses of
> > sockets).
> > 
> > To allow more consistent handling across protocols we want to
> > uniformly track the address and port at each end of the connection.
> > Furthermore, because we allow port remapping, and we sometimes need to
> > apply NAT, the addresses and ports can be different as seen by the
> > guest/namespace and as by the host.
> > 
> > Introduce 'struct flowside' to keep track of address and port
> > information related to one side of a flow. Store two of these in the
> > common fields of a flow to track that information for both sides.
> > 
> > For now we only populate the initiating side, requiring that
> > information be completed when a flows enter INI.  Later patches will
> > populate the target side.
> > 
> > For now this leaves some information redundantly recorded in both generic
> > and type specific fields.  We'll fix that in later patches.
> > 
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  flow.c       | 96 +++++++++++++++++++++++++++++++++++++++++++++++++---
> >  flow.h       | 16 +++++++++
> >  flow_table.h |  8 ++++-
> >  icmp.c       |  9 +++--
> >  passt.h      |  3 ++
> >  tcp.c        |  6 ++--
> >  6 files changed, 127 insertions(+), 11 deletions(-)
> > 
> > diff --git a/flow.c b/flow.c
> > index d05aa495..1819111d 100644
> > --- a/flow.c
> > +++ b/flow.c
> > @@ -108,6 +108,31 @@ static const union flow *flow_new_entry; /* = NULL */
> >  /* Last time the flow timers ran */
> >  static struct timespec flow_timer_run;
> >  
> > +/** flowside_from_af() - Initialise flowside from addresses
> > + * @fside:	flowside to initialise
> > + * @af:		Address family (AF_INET or AF_INET6)
> > + * @eaddr:	Endpoint address (pointer to in_addr or in6_addr)
> > + * @eport:	Endpoint port
> > + * @faddr:	Forwarding address (pointer to in_addr or in6_addr)
> > + * @fport:	Forwarding port
> > + */
> > +static void flowside_from_af(struct flowside *fside, sa_family_t af,
> > +			     const void *eaddr, in_port_t eport,
> > +			     const void *faddr, in_port_t fport)
> > +{
> > +	if (faddr)
> > +		inany_from_af(&fside->faddr, af, faddr);
> > +	else
> > +		fside->faddr = inany_any6;
> 
> I kind of wonder if, for clarity, we should perhaps:
> 
> #define inany_any		inany_any6
> 
> ?

That might be a good idea.

> And... I don't actually have in mind how IP versions are stored in the
> flow table for unspecified addresses, but I wonder if we're losing some
> information this way: if this is called with AF_INET as 'af', we're not
> saying anywhere in the flowside information that this is going to be an
> IPv4 flowside, right?

So, I've gone back and forth on this a bit, and it's not entirely
consistent in this version whether I always use :: for "blank", or
whether I use 0.0.0.0 for IPv4 cases.  Using :: everywhere does
technically lose some information, although you can generally tell
that a flowside is IPv4 from the other address.

The argument for using :: everywhere is that in many of the cases this
indicates "blank" or "missing" in a way that's not really dependent on
the IP version, and sometimes it's simpler to do this.  There are (or
may be in future) also some cases where an otherwise IPv4 flowside
might be routed through a dual-stack :: socket.

The argument for using 0.0.0.0 where accurate is that it makes for
more consistency across the flowside and makes matching up to
addresses from elswhere easier in some cases.

With the reworks for how I handle UDP, I'm going to need to revisit
this anyway, so I'll see where I land.

> > +	fside->fport = fport;
> > +
> > +	if (eaddr)
> > +		inany_from_af(&fside->eaddr, af, eaddr);
> > +	else
> > +		fside->eaddr = inany_any6;
> > +	fside->eport = eport;
> > +}
> > +
> >  /** flow_log_ - Log flow-related message
> >   * @f:		flow the message is related to
> >   * @pri:	Log priority
> > @@ -140,6 +165,8 @@ void flow_log_(const struct flow_common *f, int pri, const char *fmt, ...)
> >   */
> >  static void flow_set_state(struct flow_common *f, enum flow_state state)
> >  {
> > +	char estr[INANY_ADDRSTRLEN], fstr[INANY_ADDRSTRLEN];
> > +	const struct flowside *ini = &f->side[INISIDE];
> >  	uint8_t oldstate = f->state;
> >  
> >  	ASSERT(state < FLOW_NUM_STATES);
> > @@ -150,18 +177,28 @@ static void flow_set_state(struct flow_common *f, enum flow_state state)
> >  		  FLOW_STATE(f));
> >  
> >  	if (MAX(state, oldstate) >= FLOW_STATE_TGT)
> > -		flow_log_(f, LOG_DEBUG, "%s => %s", pif_name(f->pif[INISIDE]),
> > -			                            pif_name(f->pif[TGTSIDE]));
> > +		flow_log_(f, LOG_DEBUG, "%s [%s]:%hu -> [%s]:%hu => %s",
> > +			  pif_name(f->pif[INISIDE]),
> > +			  inany_ntop(&ini->eaddr, estr, sizeof(estr)),
> > +			  ini->eport,
> > +			  inany_ntop(&ini->faddr, fstr, sizeof(fstr)),
> > +			  ini->fport,
> > +			  pif_name(f->pif[TGTSIDE]));
> >  	else if (MAX(state, oldstate) >= FLOW_STATE_INI)
> > -		flow_log_(f, LOG_DEBUG, "%s => ?", pif_name(f->pif[INISIDE]));
> > +		flow_log_(f, LOG_DEBUG, "%s [%s]:%hu -> [%s]:%hu => ?",
> > +			  pif_name(f->pif[INISIDE]),
> > +			  inany_ntop(&ini->eaddr, estr, sizeof(estr)),
> > +			  ini->eport,
> > +			  inany_ntop(&ini->faddr, fstr, sizeof(fstr)),
> > +			  ini->fport);
> >  }
> >  
> >  /**
> > - * flow_initiate() - Move flow to INI, setting INISIDE details
> > + * flow_initiate_() - Move flow to INI, setting setting pif[INISIDE]
> 
> s/setting setting/setting/

Fixed.

-- 
David Gibson (he or they)	| 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:[~2024-06-26  0:34 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14  6:13 [PATCH v6 00/26] RFC: Unified flow table David Gibson
2024-06-14  6:13 ` [PATCH v6 01/26] flow: Common address information for initiating side David Gibson
2024-06-25 22:23   ` Stefano Brivio
2024-06-26  0:19     ` David Gibson [this message]
2024-06-14  6:13 ` [PATCH v6 02/26] flow: Common address information for target side David Gibson
2024-06-25 22:23   ` Stefano Brivio
2024-06-26  0:25     ` David Gibson
2024-06-14  6:13 ` [PATCH v6 03/26] tcp, flow: Remove redundant information, repack connection structures David Gibson
2024-06-25 22:25   ` Stefano Brivio
2024-06-26  0:23     ` David Gibson
2024-06-14  6:13 ` [PATCH v6 04/26] tcp: Obtain guest address from flowside David Gibson
2024-06-14  6:13 ` [PATCH v6 05/26] tcp: Manage outbound address via flow table David Gibson
2024-06-14  6:13 ` [PATCH v6 06/26] tcp: Simplify endpoint validation using flowside information David Gibson
2024-06-14  6:13 ` [PATCH v6 07/26] tcp_splice: Eliminate SPLICE_V6 flag David Gibson
2024-06-14  6:13 ` [PATCH v6 08/26] tcp, flow: Replace TCP specific hash function with general flow hash David Gibson
2024-06-14  6:13 ` [PATCH v6 09/26] flow, tcp: Generalise TCP hash table to general flow hash table David Gibson
2024-06-14  6:13 ` [PATCH v6 10/26] tcp: Re-use flow hash for initial sequence number generation David Gibson
2024-06-14  6:13 ` [PATCH v6 11/26] icmp: Remove redundant id field from flow table entry David Gibson
2024-06-14  6:13 ` [PATCH v6 12/26] icmp: Obtain destination addresses from the flowsides David Gibson
2024-06-14  6:13 ` [PATCH v6 13/26] icmp: Look up ping flows using flow hash David Gibson
2024-06-14  6:13 ` [PATCH v6 14/26] icmp: Eliminate icmp_id_map David Gibson
2024-06-14  6:13 ` [PATCH v6 15/26] icmp: Manage outbound socket address via flow table David Gibson
2024-06-14  6:13 ` [PATCH v6 16/26] flow, tcp: Flow based NAT and port forwarding for TCP David Gibson
2024-06-26 22:49   ` Stefano Brivio
2024-06-27  5:55     ` David Gibson
2024-06-14  6:13 ` [PATCH v6 17/26] flow, icmp: Use general flow forwarding rules for ICMP David Gibson
2024-06-14  6:13 ` [PATCH v6 18/26] fwd: Update flow forwarding logic for UDP David Gibson
2024-06-14  6:13 ` [PATCH v6 19/26] udp: Create flow table entries " David Gibson
2024-06-14  6:13 ` [PATCH v6 20/26] udp: Direct traffic from tap according to flow table David Gibson
2024-06-14  6:13 ` [PATCH v6 21/26] udp: Direct traffic from host to guest " David Gibson
2024-06-14  6:13 ` [PATCH v6 22/26] udp: Direct spliced traffic " David Gibson
2024-06-14  6:13 ` [PATCH v6 23/26] udp: Remove 'splicesrc' tracking David Gibson
2024-06-14  6:13 ` [PATCH v6 24/26] udp: Remove tap port flags field David Gibson
2024-06-14  6:13 ` [PATCH v6 25/26] udp: Remove rdelta port forwarding maps David Gibson
2024-06-14  6:13 ` [PATCH v6 26/26] udp: Eliminate 'splice' flag from epoll reference David Gibson

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=Zntek-AN5cRqbJDM@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=jmaloy@redhat.com \
    --cc=passt-dev@passt.top \
    --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).