From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 889285A0319 for ; Thu, 11 Jul 2024 03:54:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1720662836; bh=krwfyXeNROgnjEyzxp9y2pZM4vemwqbxZT6Pc+bn2P0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=niXlDDNDuTsn2nLDK8uymQuMcSR7KqBNW5I7qn44yE9Jatd9dPmSt63WKB4D9VRmH yNNWBpQ3KmPONKbq3ZfBqUotquJbpxPaqqHkP8Ld/GGTbk/Qyb14rpQM02KVotauZ6 48RVYiiXZ3++g7w6nxWJb4nEQhIb7D8C9A/d05pM+DRT5mUSdmzdv6vaIHbcpVTdmR j6hvOF2QjcdLLvpOhDQhqSIaNaiESS2biMmMQUQztaUPr65UCjyrUqyYPXEFWpY7qa UCxDotJ54jp2L9Xm+eP49194u22mrSbB9DYgwMVfxXUF3uLFkdOa5+lLQMF0WGTzz2 3zXKTWCU6yReg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WKHnw40gFz4wnx; Thu, 11 Jul 2024 11:53:56 +1000 (AEST) Date: Thu, 11 Jul 2024 10:21:59 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v7 15/27] flow: Helper to create sockets based on flowside Message-ID: References: <20240705020724.3447719-1-david@gibson.dropbear.id.au> <20240705020724.3447719-16-david@gibson.dropbear.id.au> <20240710233201.3a05342b@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pY9Xket+C7QcmOpW" Content-Disposition: inline In-Reply-To: <20240710233201.3a05342b@elisabeth> Message-ID-Hash: F4GGWKKFZJYH6QLGEGKIBZ2T765BKKIT X-Message-ID-Hash: F4GGWKKFZJYH6QLGEGKIBZ2T765BKKIT 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, jmaloy@redhat.com 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: --pY9Xket+C7QcmOpW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 10, 2024 at 11:32:01PM +0200, Stefano Brivio wrote: > On Fri, 5 Jul 2024 12:07:12 +1000 > David Gibson wrote: >=20 > > We have upcoming use cases where it's useful to create new bound socket > > based on information from the flow table. Add flowside_sock_l4() to do > > this for either PIF_HOST or PIF_SPLICE sockets. > >=20 > > Signed-off-by: David Gibson > > --- > > flow.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > flow.h | 3 ++ > > util.c | 6 ++-- > > util.h | 3 ++ > > 4 files changed, 101 insertions(+), 3 deletions(-) > >=20 > > diff --git a/flow.c b/flow.c > > index 6f09781a..2d0a8a32 100644 > > --- a/flow.c > > +++ b/flow.c > > @@ -5,9 +5,11 @@ > > * Tracking for logical "flows" of packets. > > */ > > =20 > > +#include > > #include > > #include > > #include > > +#include > > #include > > =20 > > #include "util.h" > > @@ -143,6 +145,96 @@ static void flowside_from_af(struct flowside *fsid= e, sa_family_t af, > > fside->eport =3D eport; > > } > > =20 > > +/** > > + * struct flowside_sock_args - Parameters for flowside_sock_splice() > > + * @c: Execution context > > + * @fd: Filled in with new socket fd > > + * @err: Filled in with errno if something failed > > + * @type: Socket epoll type > > + * @sa: Socket address > > + * @sl: Length of @sa > > + * @data: epoll reference data > > + */ > > +struct flowside_sock_args { > > + const struct ctx *c; > > + int fd; > > + int err; > > + enum epoll_type type; > > + const struct sockaddr *sa; > > + socklen_t sl; > > + const char *path; > > + uint32_t data; > > +}; > > + > > +/** flowside_sock_splice() - Create and bind socket for PIF_SPLICE bas= ed on flowside > > + * @arg: Argument as a struct flowside_sock_args > > + * > > + * Return: 0 > > + */ > > +static int flowside_sock_splice(void *arg) > > +{ > > + struct flowside_sock_args *a =3D arg; > > + > > + ns_enter(a->c); > > + > > + a->fd =3D sock_l4_sa(a->c, a->type, a->sa, a->sl, NULL, >=20 > Nit: assuming you wanted the extra whitespace here to align the > assignment with the one of a->err below, I'd rather write this > (at least for consistency) as "a->fd =3D ...". Actually, I think it was just a boring old typo. >=20 > > + a->sa->sa_family =3D=3D AF_INET6, a->data); > > + a->err =3D errno; >=20 >=20 > > + > > + return 0; > > +} > > + > > +/** flowside_sock_l4() - Create and bind socket based on flowside > > + * @c: Execution context > > + * @type: Socket epoll type > > + * @pif: Interface for this socket > > + * @tgt: Target flowside > > + * @data: epoll reference portion for protocol handlers > > + * > > + * Return: socket fd of protocol @proto bound to the forwarding addres= s and port > > + * from @tgt (if specified). > > + */ > > +/* cppcheck-suppress unusedFunction */ > > +int flowside_sock_l4(const struct ctx *c, enum epoll_type type, uint8_= t pif, > > + const struct flowside *tgt, uint32_t data) > > +{ > > + const char *ifname =3D NULL; > > + union sockaddr_inany sa; > > + socklen_t sl; > > + > > + ASSERT(pif_is_socket(pif)); > > + > > + pif_sockaddr(c, &sa, &sl, pif, &tgt->faddr, tgt->fport); > > + > > + switch (pif) { > > + case PIF_HOST: > > + if (inany_is_loopback(&tgt->faddr)) > > + ifname =3D NULL; > > + else if (sa.sa_family =3D=3D AF_INET) > > + ifname =3D c->ip4.ifname_out; > > + else if (sa.sa_family =3D=3D AF_INET6) > > + ifname =3D c->ip6.ifname_out; > > + > > + return sock_l4_sa(c, type, &sa, sl, ifname, > > + sa.sa_family =3D=3D AF_INET6, data); > > + > > + case PIF_SPLICE: { > > + struct flowside_sock_args args =3D { > > + .c =3D c, .type =3D type, > > + .sa =3D &sa.sa, .sl =3D sl, .data =3D data, > > + }; > > + NS_CALL(flowside_sock_splice, &args); > > + errno =3D args.err; > > + return args.fd; > > + } > > + > > + default: > > + /* If we add new socket pifs, they'll need to be implemented > > + * here */ >=20 > For consistency: >=20 > /* If we add new socket pifs, they'll need to be implemented > * here > */ Done. >=20 > there are a few occurrences in the next patches, not so important I > guess, I can also do a pass later at some point. >=20 > > + ASSERT(0); > > + } > > +} > > + > > /** flow_log_ - Log flow-related message > > * @f: flow the message is related to > > * @pri: Log priority > > diff --git a/flow.h b/flow.h > > index c3a15ca6..e27f99be 100644 > > --- a/flow.h > > +++ b/flow.h > > @@ -164,6 +164,9 @@ static inline bool flowside_eq(const struct flowsid= e *left, > > left->fport =3D=3D right->fport; > > } > > =20 > > +int flowside_sock_l4(const struct ctx *c, enum epoll_type type, uint8_= t pif, > > + const struct flowside *tgt, uint32_t data); > > + > > /** > > * struct flow_common - Common fields for packet flows > > * @state: State of the flow table entry > > diff --git a/util.c b/util.c > > index 9a73fbb9..f2994a79 100644 > > --- a/util.c > > +++ b/util.c > > @@ -44,9 +44,9 @@ > > * > > * Return: newly created socket, negative error code on failure > > */ > > -static int sock_l4_sa(const struct ctx *c, enum epoll_type type, > > - const void *sa, socklen_t sl, > > - const char *ifname, bool v6only, uint32_t data) > > +int sock_l4_sa(const struct ctx *c, enum epoll_type type, > > + const void *sa, socklen_t sl, > > + const char *ifname, bool v6only, uint32_t data) > > { > > sa_family_t af =3D ((const struct sockaddr *)sa)->sa_family; > > union epoll_ref ref =3D { .type =3D type, .data =3D data }; > > diff --git a/util.h b/util.h > > index d0150396..f2e4f8cf 100644 > > --- a/util.h > > +++ b/util.h > > @@ -144,6 +144,9 @@ struct ctx; > > =20 > > /* cppcheck-suppress funcArgNamesDifferent */ > > __attribute__ ((weak)) int ffsl(long int i) { return __builtin_ffsl(i)= ; } > > +int sock_l4_sa(const struct ctx *c, enum epoll_type type, > > + const void *sa, socklen_t sl, > > + const char *ifname, bool v6only, uint32_t data); > > int sock_l4(const struct ctx *c, sa_family_t af, enum epoll_type type, > > const void *bind_addr, const char *ifname, uint16_t port, > > uint32_t data); >=20 --=20 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 --pY9Xket+C7QcmOpW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmaPJacACgkQzQJF27ox 2GdOPA//XFLRbL67M0HK5tt9haH/WCePre9PpL5MkTSprUXGvGmRYWQCySoYxbek y7I5e4trYjnBAcfyDkgPWjEkOBXVm8xf3HwyMheGY0tpfQxSCwfVOy02p51Ozy3g fbIY4ftcuhm+mD3foFtZ+HqW1knSkBKW0x3T6E7+VuOhNUoSmlDnYCxN1Eed13sB qXaRnyqH5Lf1J4+FDbIRAxTp9ChFk9hNaLoCQiQscDOh8pLNbcq1YfVt1EZLqpMX gGfsTExiFvDGXQ1XrpszNpCrTxpF/BzwVa0h/17ciLF+y2fJ9n8JAfq2D+Vcfelq EQC1CfJSmo4asvagWdjs+0V+oTq/2w81HpL917CPgTstfH7vLf6FzBJklc57AW4N x4orfaqiXWT15kUKj/9hy0MqWQVfSUTO/NYFhm8MJlpOZ+w6mA2MC3Ejg1eoeRTP Q1/3vTdx/NIDp4Rmnqp1rov/ltH23lDodRhzr0dFes8Ugapi64VtYQhYNHQu0BAG lUIqfYX/VwywKwXxRjWHXqFh0g+s4sAUfLElCLWySzQ3mSvso6Vgd0sGVSy005iS 7tNoqsO0sMRCs4JmRgZ+eCnF7T0fFbWBkzLMqA4jpC3c8H/APFJkGkB0UAupmGIK c2m+7yVeAj0zRLs3OVcIohkL58NPtNxNKOh1lsGiNcYmk/PCPtg= =UHac -----END PGP SIGNATURE----- --pY9Xket+C7QcmOpW--