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 A798B5A005E for ; Sat, 8 Oct 2022 05:57:31 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Mkrwl5l2mz4xDn; Sat, 8 Oct 2022 14:57:27 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1665201447; bh=MLJ6I+ImUuQ3XKQgftQGGBSsmFWxn9cOlnOEueQKMcg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kNnnH9jluNCzVaa1GbpK1uCSkBP21xBr92zyRJhuCHbjgXbmH0HJzSHnm5AbaR9EE b/6uAL0f8PYF8r5Ytew51aRZUW8EhAtNSIi3oNqcgw5aG+YmC/ohgtWO+zqpCsr61e ehD+D+Das7e3zM31RBzC/g9ps2y8179iWKP5UuKo= Date: Sat, 8 Oct 2022 14:55:53 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] conf, tap: Add option to quit once the client closes the connection Message-ID: References: <20221007071641.1969102-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="qe12oUREfFOfauZJ" Content-Disposition: inline In-Reply-To: <20221007071641.1969102-1-sbrivio@redhat.com> Message-ID-Hash: EJPYG5NPPQBGMBVMHME2AFV72S3UF6M4 X-Message-ID-Hash: EJPYG5NPPQBGMBVMHME2AFV72S3UF6M4 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: --qe12oUREfFOfauZJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 07, 2022 at 09:16:41AM +0200, Stefano Brivio wrote: > This is practical to avoid explicit lifecycle management in users, > e.g. libvirtd, and is trivial to implement. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson I actually wonder if this should be the default/only behaviour. > --- > conf.c | 17 ++++++++++++++++- > passt.1 | 5 +++++ > passt.h | 1 + > tap.c | 5 +++++ > 4 files changed, 27 insertions(+), 1 deletion(-) >=20 > diff --git a/conf.c b/conf.c > index 4ec3153..53a8dcf 100644 > --- a/conf.c > +++ b/conf.c > @@ -712,6 +712,7 @@ static void usage(const char *name) > if (strstr(name, "pasta")) > goto pasta_opts; > =20 > + info( " -1, --one-off Quit after handling one single client"); > info( " -t, --tcp-ports SPEC TCP port forwarding to guest"); > info( " can be specified multiple times"); > info( " SPEC can be:"); > @@ -1024,6 +1025,7 @@ void conf(struct ctx *c, int argc, char **argv) > {"no-map-gw", no_argument, &c->no_map_gw, 1 }, > {"ipv4-only", no_argument, NULL, '4' }, > {"ipv6-only", no_argument, NULL, '6' }, > + {"one-off", no_argument, NULL, '1' }, > {"tcp-ports", required_argument, NULL, 't' }, > {"udp-ports", required_argument, NULL, 'u' }, > {"tcp-ns", required_argument, NULL, 'T' }, > @@ -1062,7 +1064,7 @@ void conf(struct ctx *c, int argc, char **argv) > c->no_dhcp_dns =3D c->no_dhcp_dns_search =3D 1; > optstring =3D "vdqfel:hI:p:P:m:a:n:M:g:i:D:S:46t:u:T:U:"; > } else { > - optstring =3D "vdqfel:hs:p:P:m:a:n:M:g:i:D:S:46t:u:"; > + optstring =3D "vdqfel:hs:p:P:m:a:n:M:g:i:D:S:461t:u:"; > } > =20 > c->tcp.fwd_in.mode =3D c->tcp.fwd_out.mode =3D 0; > @@ -1488,6 +1490,19 @@ void conf(struct ctx *c, int argc, char **argv) > case '6': > v6_only =3D true; > break; > + case '1': > + if (c->mode !=3D MODE_PASST) { > + err("--one-off is for passt mode only"); > + usage(argv[0]); > + } > + > + if (c->one_off) { > + err("Redundant --one-off option"); > + usage(argv[0]); > + } > + > + c->one_off =3D true; > + break; > case 't': > case 'u': > case 'T': > diff --git a/passt.1 b/passt.1 > index c63a439..41f8836 100644 > --- a/passt.1 > +++ b/passt.1 > @@ -302,6 +302,11 @@ Path for UNIX domain socket used by \fBqemu\fR(1) or= \fBqrap\fR(1) to connect to > Default is to probe a free socket, not accepting connections, starting f= rom > \fI/tmp/passt_1.socket\fR to \fI/tmp/passt_64.socket\fR. > =20 > +.TP > +.BR \-1 ", " \-\-one-off > +Quit after handling a single client connection, that is, once the client= closes > +the socket, or once we get a socket error. > + > .TP > .BR \-t ", " \-\-tcp-ports " " \fIspec > Configure TCP port forwarding to guest. \fIspec\fR can be one of: > diff --git a/passt.h b/passt.h > index de79e7b..67281db 100644 > --- a/passt.h > +++ b/passt.h > @@ -196,6 +196,7 @@ struct ctx { > char sock_path[UNIX_PATH_MAX]; > char pcap[PATH_MAX]; > char pid_file[PATH_MAX]; > + int one_off; > =20 > int pasta_netns_fd; > =20 > diff --git a/tap.c b/tap.c > index bdcc161..78de42c 100644 > --- a/tap.c > +++ b/tap.c > @@ -1011,5 +1011,10 @@ void tap_handler(struct ctx *c, int fd, uint32_t e= vents, > =20 > return; > reinit: > + if (c->one_off) { > + info("Client closed connection, exiting"); > + exit(EXIT_SUCCESS); > + } > + > tap_sock_init(c); > } --=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 --qe12oUREfFOfauZJ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmNA9L8ACgkQgypY4gEw YSLrRxAAgBYE03Y8kyD5Ttr6HtZR4e5mJt/y8ZawEbWs6vn/kPRvynL+CTTURmYb FKvZVzYdVarjjM6breAsAKL3uFWwCVnlFE4tNcGS8FCC4XvvrCNyedvLhxfK+NVG H77Q9rvez/x8m315dmTTyHplgDl8uAJOWIp1JcWAOUaoL+9mXPahQRTuAeWc6C9F KL9VDFV0mMH0/RsI/E1AD8vBmJrR5OXiSi4+hBGyYVo3SQAQx8ALkR24oIG5Gr5O iaB9SB2ZU0kwCdR5g7jSrekvA+4yAYXwHOCnS8fLI2fPqgI924ozYlU1f5e4hzCX eN2/ju3lvMnIXB5/R1iN3buirX5Pf5u7MjwlNDqmWOTYchkSdz3EtIc3jWUdJPMR CRBqYu//wO0kmXcPR0QUeN0GaLCCAE/zi5dtKzPVJ/J5i5ve4/nNoJfihgHn9dA0 LDoH20FYseDZir6sKamUDRCbKIr1AxLyS8l0sTcIiY3N6kP+GGbCbFeZ+pTfK98o QTSAScw0/Wut6gzOtH25Jnn9IwhnZsAtLhmm0WhyYHNGeVPZHyssPavwo3vdPsUA PuAEXg3IY4OWcA05pSeNwhG0qUeBLJggLIg8MQ3ueu7WOYYH7BqX3RQmlOZsq60k BqrmP1/v11WwjziciPOHTNytIn65csvvnAPZQQFWRmM49wPT4fM= =sUH5 -----END PGP SIGNATURE----- --qe12oUREfFOfauZJ--