From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id A69EC5A026A for ; Tue, 18 Oct 2022 14:08:14 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4MsCLH4sTQz4xGp; Tue, 18 Oct 2022 23:08:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1666094887; bh=iaCjW+PqzbuL9WG2k01L1pFwDNRgi6G7j1NYTv/LUUU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XH5KR+0O2MAwyZoa4gZ77kOrvUXc8oxNJJnQX1RwabYTp81wP+X0gKhzKA3lDYBhM msgeOdYf5TwgwvqzPHOj/c97G/qbgyNrUH4I3vz4CVMA7gtMbsCQe/uO21Z8+l/j6v y64LRMBHb3o5l+HeFTgdilcBl1j6qFjabbmq7fvg= Date: Tue, 18 Oct 2022 23:07:16 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 06/14] Add helpers for normal inbound packet destination addresses Message-ID: References: <20221017085807.473470-1-david@gibson.dropbear.id.au> <20221017085807.473470-7-david@gibson.dropbear.id.au> <20221018050441.0d92c3d7@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="X0gfnTJ2lhUXtJEp" Content-Disposition: inline In-Reply-To: <20221018050441.0d92c3d7@elisabeth> Message-ID-Hash: IQZWME5FHKILZNXJ4X4IHZKIZWPCK7F5 X-Message-ID-Hash: IQZWME5FHKILZNXJ4X4IHZKIZWPCK7F5 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: passt-dev@passt.top 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: --X0gfnTJ2lhUXtJEp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 18, 2022 at 05:04:41AM +0200, Stefano Brivio wrote: 11;rgb:ffff/ffff/ffff> On Mon, 17 Oct 2022 19:57:59 +1100 > David Gibson wrote: >=20 > > tap_ip_send() doesn't take a destination address, because it's specific= ally > > for inbound packets, and the IP addresses of the guest/namespace are > > already known to us. Rather than open-coding this destination address > > logic, make helper functions for it which will enable some later cleanu= ps. > >=20 > > Signed-off-by: David Gibson > > --- > > tap.c | 29 ++++++++++++++++++++++++----- > > tap.h | 3 +++ > > 2 files changed, 27 insertions(+), 5 deletions(-) > >=20 > > diff --git a/tap.c b/tap.c > > index de02c56..41e8ff2 100644 > > --- a/tap.c > > +++ b/tap.c > > @@ -96,6 +96,28 @@ int tap_send(const struct ctx *c, const void *data, = size_t len, int vnet_pre) > > return write(c->fd_tap, (char *)data + (vnet_pre ? 4 : 0), len); > > } > > =20 > > +/** > > + * tap_ip4_daddr() - Normal IPv4 destination address for inbound packe= ts > > + * @c: Execution context >=20 > Given that the address is returned in network order, I think this would > be relevant here: >=20 > * Return: IPv4 address, network order Done. > > + */ > > +in_addr_t tap_ip4_daddr(const struct ctx *c) > > +{ > > + return c->ip4.addr_seen; > > +} > > + > > +/** > > + * tap_ip6_daddr() - Normal IPv4 destination address for inbound packe= ts > > + * @c: Execution context > > + * @src: Source address >=20 > * Return: pointer to IPv6 address Done. > > + */ > > +const struct in6_addr *tap_ip6_daddr(const struct ctx *c, > > + const struct in6_addr *src) > > +{ > > + if (IN6_IS_ADDR_LINKLOCAL(src)) > > + return &c->ip6.addr_ll_seen; > > + return &c->ip6.addr_seen; > > +} > > + > > /** > > * tap_ip_send() - Send IP packet, with L2 headers, calculating L3/L4 = checksums > > * @c: Execution context > > @@ -132,7 +154,7 @@ void tap_ip_send(const struct ctx *c, const struct = in6_addr *src, uint8_t proto, > > iph->frag_off =3D 0; > > iph->ttl =3D 255; > > iph->protocol =3D proto; > > - iph->daddr =3D c->ip4.addr_seen; > > + iph->daddr =3D tap_ip4_daddr(c); > > memcpy(&iph->saddr, &src->s6_addr[12], 4); > > =20 > > csum_ip4_header(iph); > > @@ -163,10 +185,7 @@ void tap_ip_send(const struct ctx *c, const struct= in6_addr *src, uint8_t proto, > > ip6h->priority =3D 0; > > =20 > > ip6h->saddr =3D *src; > > - if (IN6_IS_ADDR_LINKLOCAL(src)) > > - ip6h->daddr =3D c->ip6.addr_ll_seen; > > - else > > - ip6h->daddr =3D c->ip6.addr_seen; > > + ip6h->daddr =3D *tap_ip6_daddr(c, src); > > =20 > > memcpy(data, in, len); > > =20 > > diff --git a/tap.h b/tap.h > > index df3aec0..a6764b4 100644 > > --- a/tap.h > > +++ b/tap.h > > @@ -6,6 +6,9 @@ > > #ifndef TAP_H > > #define TAP_H > > =20 > > +in_addr_t tap_ip4_daddr(const struct ctx *c); > > +const struct in6_addr *tap_ip6_daddr(const struct ctx *c, > > + const struct in6_addr *src); > > void tap_ip_send(const struct ctx *c, const struct in6_addr *src, uint= 8_t proto, > > const char *in, size_t len, uint32_t flow); > > int tap_send(const struct ctx *c, const void *data, size_t len, int vn= et_pre); >=20 --=20 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 --X0gfnTJ2lhUXtJEp Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmNOlu0ACgkQgypY4gEw YSLBwA//WOTF0a+PR8K8ID7HrEszdSCzYK1yTAy7hZEHpQT6rZtqcW9bDV1xFu1R kjUPwd2G0TJpzfncEMXrcLrb6Y7yJW5fMd0fU9XQxuexYwpda9X626UlY2od6fkl ndWmrG+16oKEzklTjCnzDPX7aZApR+ct267tLGpbqzZxzRTvSRaHNtf4BtKja45H 53tgxrheALYTW6k8EhiEB9Pl26xba644r2XDGi4xPurRpuzDnjdRkrAjyYL25dlb pQBaWLTBrPpCDFZBXk49l6dCMAT1771hKH/0eiBjokRnWb76FJ6s5FYVJxnQ/nwf J/H3qF/yCK2BAwNOLOugrBghoMVe2L13rOyF/Kq0WYwXfqN+3hpQEnGrlWmjXJ0y PbWCbohe9994PqFqVPOIdiHVTtEy6bIX468seAeMAIvv1CowcUEw3iXGlHoiWifY soMy08popGWPYgdSXFT8w9PEDFoOdgKeqwO1b33FNrQ3hDBdfv2e1ssUwkREelJ3 HNr0lUFwsV+/Amg7ka+5YCV/FbonAACvhvlcq4TXBfJkcAvT4bb8TWjRbhJ70B9t EqsXlgz5JezFPvmVDjegsVC/UiAAhP5qLtvXDstg0xHisOH/4tf36dEEErbJXh0O NOIxDt9nyKwqr44jdLVb7l843Nl+dWYZWw81so6qX27b8jL5KUE= =BCkh -----END PGP SIGNATURE----- --X0gfnTJ2lhUXtJEp--