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 18F5E5A0306 for ; Tue, 28 May 2024 09:24:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1716881069; bh=5eQMwPozePWGDd05d+il675FjcNawPLYHA4E/4C+BuQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ae6KezSoCQsB6uZjBqVJx/P8giKd5SoyhIw5DhbqAkzVUUzWKLv5cMQFyfpR07Pwh 6/PdDTDEgWEXcGPUjmIRKtsoW8V2DxmDkIbJN7sfGifQPtucpogr8ympaUUjBh7UL1 bqkOWls+wWO01mAJaPJYWUey402ruBnw+u7Eydl8YpsYSLFj7sA12MOdB8sfIOIl7A Ng9fmGWZnGQJFjU4IivhB683Je+xaJb6lrRT24frSPuyAF8ll2t3P5mMHV8U3LREOj csQ77mz65aEUj6ekDxmyK/OpypXGDdJ7UKZBukqUkSPARRCbqaB/kyEgkGJReQEf5c Kh/f5xcCtm3tg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4VpPCd64Ksz4wcJ; Tue, 28 May 2024 17:24:29 +1000 (AEST) Date: Tue, 28 May 2024 17:01:21 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 4/8] tap: Split tap_sock_unix_init() into opening and listening parts Message-ID: References: <20240522205911.261325-1-sbrivio@redhat.com> <20240522205911.261325-5-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="GN2YbZV85bF0Hlf2" Content-Disposition: inline In-Reply-To: <20240522205911.261325-5-sbrivio@redhat.com> Message-ID-Hash: AEKH4X3G6YXYH3FGJHNRTTXEAHJHG5NL X-Message-ID-Hash: AEKH4X3G6YXYH3FGJHNRTTXEAHJHG5NL 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, "'Richard W . M . Jones'" , Minxi Hou 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: --GN2YbZV85bF0Hlf2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 22, 2024 at 10:59:07PM +0200, Stefano Brivio wrote: > We'll need to open and bind the socket a while before listening to it, > so split that into two different functions. No functional changes > intended. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > tap.c | 39 +++++++++++++++++++++++++++------------ > 1 file changed, 27 insertions(+), 12 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index cb6df5a..c9f580e 100644 > --- a/tap.c > +++ b/tap.c > @@ -1095,14 +1095,14 @@ restart: > } > =20 > /** > - * tap_sock_unix_init() - Create and bind AF_UNIX socket, listen for con= nection > - * @c: Execution context > + * tap_sock_unix_open() - Create and bind AF_UNIX socket > + * @sock_path: Socket path. If empty, set on return (UNIX_SOCK_PATH as p= refix) > + * > + * Return: socket descriptor on success, won't return on failure > */ > -static void tap_sock_unix_init(struct ctx *c) > +static int tap_sock_unix_open(char *sock_path) > { > int fd =3D socket(AF_UNIX, SOCK_STREAM, 0); > - union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TAP_LISTEN }; > - struct epoll_event ev =3D { 0 }; > struct sockaddr_un addr =3D { > .sun_family =3D AF_UNIX, > }; > @@ -1115,8 +1115,8 @@ static void tap_sock_unix_init(struct ctx *c) > char *path =3D addr.sun_path; > int ex, ret; > =20 > - if (*c->sock_path) > - memcpy(path, c->sock_path, UNIX_PATH_MAX); > + if (*sock_path) > + memcpy(path, sock_path, UNIX_PATH_MAX); > else > snprintf(path, UNIX_PATH_MAX - 1, UNIX_SOCK_PATH, i); > =20 > @@ -1127,7 +1127,7 @@ static void tap_sock_unix_init(struct ctx *c) > ret =3D connect(ex, (const struct sockaddr *)&addr, sizeof(addr)); > if (!ret || (errno !=3D ENOENT && errno !=3D ECONNREFUSED && > errno !=3D EACCES)) { > - if (*c->sock_path) > + if (*sock_path) > die("Socket path %s already in use", path); > =20 > close(ex); > @@ -1137,7 +1137,7 @@ static void tap_sock_unix_init(struct ctx *c) > =20 > unlink(path); > if (!bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) || > - *c->sock_path) > + *sock_path) > break; > } > =20 > @@ -1145,17 +1145,31 @@ static void tap_sock_unix_init(struct ctx *c) > die("UNIX socket bind: %s", strerror(errno)); > =20 > info("UNIX domain socket bound at %s\n", addr.sun_path); > + if (!*sock_path) > + memcpy(sock_path, addr.sun_path, UNIX_PATH_MAX); > + > + return fd; > +} > + > +/** > + * tap_sock_unix_init() - Start listening for connections on AF_UNIX soc= ket > + * @c: Execution context > + */ > +static void tap_sock_unix_init(struct ctx *c) > +{ > + union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TAP_LISTEN }; > + struct epoll_event ev =3D { 0 }; > =20 > - listen(fd, 0); > + listen(c->fd_tap_listen, 0); > =20 > - ref.fd =3D c->fd_tap_listen =3D fd; > + ref.fd =3D c->fd_tap_listen; > ev.events =3D EPOLLIN | EPOLLET; > ev.data.u64 =3D ref.u64; > epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap_listen, &ev); > =20 > info("You can now start qemu (>=3D 7.2, with commit 13c6be96618c):"); > info(" kvm ... -device virtio-net-pci,netdev=3Ds -netdev stream,id= =3Ds,server=3Doff,addr.type=3Dunix,addr.path=3D%s", > - addr.sun_path); > + c->sock_path); > info("or qrap, for earlier qemu versions:"); > info(" ./qrap 5 kvm ... -net socket,fd=3D5 -net nic,model=3Dvirtio"); > } > @@ -1304,6 +1318,7 @@ void tap_sock_init(struct ctx *c) > } > =20 > if (c->mode =3D=3D MODE_PASST) { > + c->fd_tap_listen =3D tap_sock_unix_open(c->sock_path); > tap_sock_unix_init(c); > =20 > /* In passt mode, we don't know the guest's MAC address until it --=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 --GN2YbZV85bF0Hlf2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZVgUAACgkQzQJF27ox 2Gd1mxAAk4Z8DWlcftGX2JQg9v8Iu4/LnL546nxs121qhERMQz35eHVOfIuUxgIO sfiuwfQR2poXPx12HEOOp4O+P3wRI4PBg+6K8gmlceo4ZYhZxwq9a44tNtBG8pLG qfVlNQGes+3M8CAXSSGc12yDa11G/dSjQkc4cHUYKIZlQ1fXdNZ1AX4Ml4QG2bwk Zp/FqRNqVZ6XB7ocpYS1ZeWZ3+hl14KPrX48l1NObjIOYr0c5N/pP4K22/9eAOZl NHbCo+YMP2U6067u6tclcp4JaiP4w68JfoBch7AbM91DZwBMgHP9IUahzf5QE+u3 +urtec/0eTIKIvFum/XBotcXWMhBWPi20NZlgIk67VRWgkdd7uBvJiU537HFSDnE 9z4sKZLdsr7Gn29wYotCyPBryOArfT7di9RRrXab9dPKcWzJA0fFU3yhwTUL1cQV Aet+978e2864To8D+0VeP7V6GWduZWsAZE0igZV05N+pC5WldJFlDmDb0KLIJJIF H2rsFFFqzsf8GV6AXsUrZnBe+Mz30PYONOYevLAH0vXJ8Jc8qqJpUi7gqbaoDf0L 3roakeXkyteTRTI2PGMw/TfiM+cTy2r2oYdWVdpialdRFiMsVAVMa/IFElm5DbUI +RnZHJiW/dhLb5ud294GiizNVOeG+Kx2R4vsEk6bs5j+ZFmP/Ew= =5o89 -----END PGP SIGNATURE----- --GN2YbZV85bF0Hlf2--