From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from imap.gmail.com [173.194.76.109] by localhost with POP3 (fetchmail-6.3.26) for (single-drop); Wed, 22 May 2024 22:59:38 +0200 (CEST) Received: by 2002:a05:6a11:2489:b0:55f:c3c0:ed08 with SMTP id sg9csp910648pxb; Wed, 22 May 2024 13:59:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWArOTAaCvSCr+Ua7li8U7x7bbXR7aC+0Vccgk/l8/doc7dBm5igqTfFJtWKpxkn4IZ9gdg+hrbkUsLidOwUecjBJEiDjhpcNM= X-Google-Smtp-Source: AGHT+IFjG5h0KArYNpZ66jQtOXY1pN+AoOVmzGlT9no7GkJnOS6U89S4c+K8N5p1gu9Ba6Fgw5CP X-Received: by 2002:a05:6214:2a85:b0:6ab:74dd:d6ac with SMTP id 6a1803df08f44-6ab8f328320mr8283276d6.3.1716411566516; Wed, 22 May 2024 13:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716411566; cv=none; d=google.com; s=arc-20160816; b=TBqWSBO7pVPaG0flFO0H0C4BUmmBkIHH82vWgGf4L3kVXcBdaLL298mzvjUVbP1tjv CV4Z80oOLHIK+XgfjuMi5/Fyfcl6YUHDrwhlh+GbxEJF7RuuVcjsQNFk9s+XUCi1s8i4 tNxyMnKHpkc1CALvpx5QbsG1poWQBBhLkDXWCrDS/GWAHGgKjJbbCS0qVP2E7q9aW0XA zaOs3wOVxOt8lQqvY/dhIS+AKV/CZwJnHLe/hKg7I3j3VbvEJMZUj75X/XTya1OG1cT4 3oxd81amK4oX3z/yXDnZg+yrKyVzPD1CFgoC8Imgt7q3fK2De1D5HSjIZJodjwx9yXZo spdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:list-unsubscribe:list-subscribe:list-post :list-owner:list-help:list-archive:list-archive:archived-at :archived-at:list-id:precedence:cc:message-id-hash:mime-version :references:in-reply-to:message-id:date:subject:to:from:delivered-to; bh=cQzfg9OjxmDysUq6WHayUvbDSdYq/9AmzIzdaOEGIKE=; fh=Sda5+ix8pPMDNzAK4mfqRvxwOV3J+P0OHYKuDzXzUCA=; b=KjCQXe5td7V4l/WMTjlsxW7HTkc3NMHm8EwNgyvLc5VwOrADJ45FMLAG7fKcckCrU6 4VWD4UC8w4yjUdxAxyY5FehUcCpr+eCwm+nRiyUXghM3TDlWdpdnGwfQhqdf+dbYezqF Ko8qYfapUGu2TCqfJ6CU8asw38l65yfk6jBX6wGGePPbZhb41LLeAF53v7SrKQ9431O2 79o4e4WtjzHQN0FH0qXDE4+eixzeKBFreMMMlYB8/48Cpd4r/JeRRZkPfjmjS+Ju/T9g TWm4ctaPC9GM1elZffrHlAwhfTI67sazaOy7w8CAvikJ07/Q+FGKDA0ITX6imgyKo8Hj 7a9w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of passt-dev-bounces@passt.top designates 88.198.0.164 as permitted sender) smtp.mailfrom=passt-dev-bounces@passt.top Return-Path: Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com. [205.139.110.120]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f1d6eb3si325081796d6.75.2024.05.22.13.59.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 13:59:26 -0700 (PDT) Received-SPF: pass (google.com: domain of passt-dev-bounces@passt.top designates 88.198.0.164 as permitted sender) client-ip=88.198.0.164; Authentication-Results: mx.google.com; spf=pass (google.com: domain of passt-dev-bounces@passt.top designates 88.198.0.164 as permitted sender) smtp.mailfrom=passt-dev-bounces@passt.top Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-96-r4v6Z3tBMOG9Ia3rq7MAYw-1; Wed, 22 May 2024 16:59:24 -0400 X-MC-Unique: r4v6Z3tBMOG9Ia3rq7MAYw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A4D3195608A for ; Wed, 22 May 2024 20:59:24 +0000 (UTC) Received: by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) id 0B148197F039; Wed, 22 May 2024 20:59:24 +0000 (UTC) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.58]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 08B2F197F037 for ; Wed, 22 May 2024 20:59:24 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [170.10.128.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ABC161955E85 for ; Wed, 22 May 2024 20:59:23 +0000 (UTC) Received: from passt.top (passt.top [88.198.0.164]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-JCX9zqS6Mta_9cskLMsI1w-1; Wed, 22 May 2024 16:59:21 -0400 X-MC-Unique: JCX9zqS6Mta_9cskLMsI1w-1 Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by passt.top (Postfix) with ESMTP id DAD1E5A0315; Wed, 22 May 2024 22:59:14 +0200 (CEST) Received: by passt.top (Postfix, from userid 1000) id BCA5E5A0309; Wed, 22 May 2024 22:59:11 +0200 (CEST) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 4/8] tap: Split tap_sock_unix_init() into opening and listening parts Date: Wed, 22 May 2024 22:59:07 +0200 Message-ID: <20240522205911.261325-5-sbrivio@redhat.com> In-Reply-To: <20240522205911.261325-1-sbrivio@redhat.com> References: <20240522205911.261325-1-sbrivio@redhat.com> MIME-Version: 1.0 Message-ID-Hash: COZU6LYUKXLALNSNA5XXIKWXXG3AOOYA X-Message-ID-Hash: COZU6LYUKXLALNSNA5XXIKWXXG3AOOYA X-MailFrom: sbrivio@passt.top 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: David Gibson , "'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: X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition;Similar Internal Domain=false;Similar Monitored External Domain=false;Custom External Domain=false;Mimecast External Domain=false;Newly Observed Domain=false;Internal User Name=false;Custom Display Name List=false;Reply-to Address Mismatch=false;Targeted Threat Dictionary=false;Mimecast Threat Dictionary=false;Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="US-ASCII"; x-default=true 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. Signed-off-by: Stefano Brivio --- tap.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) 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 conne= ction - * @c:=09=09Execution context + * tap_sock_unix_open() - Create and bind AF_UNIX socket + * @sock_path:=09Socket 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) { =09int fd =3D socket(AF_UNIX, SOCK_STREAM, 0); -=09union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TAP_LISTEN }; -=09struct epoll_event ev =3D { 0 }; =09struct sockaddr_un addr =3D { =09=09.sun_family =3D AF_UNIX, =09}; @@ -1115,8 +1115,8 @@ static void tap_sock_unix_init(struct ctx *c) =09=09char *path =3D addr.sun_path; =09=09int ex, ret; =20 -=09=09if (*c->sock_path) -=09=09=09memcpy(path, c->sock_path, UNIX_PATH_MAX); +=09=09if (*sock_path) +=09=09=09memcpy(path, sock_path, UNIX_PATH_MAX); =09=09else =09=09=09snprintf(path, UNIX_PATH_MAX - 1, UNIX_SOCK_PATH, i); =20 @@ -1127,7 +1127,7 @@ static void tap_sock_unix_init(struct ctx *c) =09=09ret =3D connect(ex, (const struct sockaddr *)&addr, sizeof(addr)); =09=09if (!ret || (errno !=3D ENOENT && errno !=3D ECONNREFUSED && =09=09=09 errno !=3D EACCES)) { -=09=09=09if (*c->sock_path) +=09=09=09if (*sock_path) =09=09=09=09die("Socket path %s already in use", path); =20 =09=09=09close(ex); @@ -1137,7 +1137,7 @@ static void tap_sock_unix_init(struct ctx *c) =20 =09=09unlink(path); =09=09if (!bind(fd, (const struct sockaddr *)&addr, sizeof(addr)) || -=09=09 *c->sock_path) +=09=09 *sock_path) =09=09=09break; =09} =20 @@ -1145,17 +1145,31 @@ static void tap_sock_unix_init(struct ctx *c) =09=09die("UNIX socket bind: %s", strerror(errno)); =20 =09info("UNIX domain socket bound at %s\n", addr.sun_path); +=09if (!*sock_path) +=09=09memcpy(sock_path, addr.sun_path, UNIX_PATH_MAX); + +=09return fd; +} + +/** + * tap_sock_unix_init() - Start listening for connections on AF_UNIX socke= t + * @c:=09=09Execution context + */ +static void tap_sock_unix_init(struct ctx *c) +{ +=09union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TAP_LISTEN }; +=09struct epoll_event ev =3D { 0 }; =20 -=09listen(fd, 0); +=09listen(c->fd_tap_listen, 0); =20 -=09ref.fd =3D c->fd_tap_listen =3D fd; +=09ref.fd =3D c->fd_tap_listen; =09ev.events =3D EPOLLIN | EPOLLET; =09ev.data.u64 =3D ref.u64; =09epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap_listen, &ev); =20 =09info("You can now start qemu (>=3D 7.2, with commit 13c6be96618c):"); =09info(" kvm ... -device virtio-net-pci,netdev=3Ds -netdev stream,id= =3Ds,server=3Doff,addr.type=3Dunix,addr.path=3D%s", -=09 addr.sun_path); +=09 c->sock_path); =09info("or qrap, for earlier qemu versions:"); =09info(" ./qrap 5 kvm ... -net socket,fd=3D5 -net nic,model=3Dvirtio")= ; } @@ -1304,6 +1318,7 @@ void tap_sock_init(struct ctx *c) =09} =20 =09if (c->mode =3D=3D MODE_PASST) { +=09=09c->fd_tap_listen =3D tap_sock_unix_open(c->sock_path); =09=09tap_sock_unix_init(c); =20 =09=09/* In passt mode, we don't know the guest's MAC address until it --=20 2.43.0