From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hSGB0bth; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id BA1E15A026F for ; Mon, 09 Dec 2024 17:54:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733763295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QuOfBKdfVbvFlC7gW2eWRcfC4ZNF5hzl8aJNWN5h4w4=; b=hSGB0bthsvR+ifr9wmG+re1dbQCBHk5iUT9/pL6UXihS5TUIUaRv9E1gJ2ECA8omN7zoXm a9cPP4kHCLfJLXrLAtXs9tFHfkMs0hvJR9YKPJ4CF1wqwXpGk8yV39nLVoyK9eL0AlaM2k F0Ax6z8KD7mB1QsOS6n1M5StCil/dms= Received: from mx-prod-mc-05.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-401-qMsWmVidNPKtOK4cR6r8Sw-1; Mon, 09 Dec 2024 11:54:53 -0500 X-MC-Unique: qMsWmVidNPKtOK4cR6r8Sw-1 X-Mimecast-MFC-AGG-ID: qMsWmVidNPKtOK4cR6r8Sw Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1507A19560A3 for ; Mon, 9 Dec 2024 16:54:53 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.39.192.141]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 11A67300019E; Mon, 9 Dec 2024 16:54:51 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 1/2] tap: Use a common function to start a new connection Date: Mon, 9 Dec 2024 17:54:49 +0100 Message-ID: <20241209165450.2314060-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 7RRI9ewvop56bMyZLVUWU7TeZYTc74Cw_Bjbj2fl4e4_1733763293 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: UNIDX5JGLNUKKOCU6VNCTHYQJMIUOVHS X-Message-ID-Hash: UNIDX5JGLNUKKOCU6VNCTHYQJMIUOVHS X-MailFrom: lvivier@redhat.com 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: Laurent Vivier 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: Merge code from tap_backend_init(), tap_sock_tun_init() and tap_listen_handler() to set epoll_ref entry and to add it to epollfd. No functionality change Signed-off-by: Laurent Vivier --- tap.c | 66 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/tap.c b/tap.c index c4180643bd0a..b2d30456e8dc 100644 --- a/tap.c +++ b/tap.c @@ -1255,6 +1255,33 @@ static void tap_sock_unix_init(const struct ctx *c) epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap_listen, &ev); } +/** + * tap_start_connection() - start a new connection + * @c: Execution context + */ +static void tap_start_connection(const struct ctx *c) +{ + struct epoll_event ev = { 0 }; + union epoll_ref ref = { 0 }; + + ref.fd = c->fd_tap; + switch (c->mode) { + case MODE_PASST: + ref.type = EPOLL_TYPE_TAP_PASST; + break; + case MODE_PASTA: + ref.type = EPOLL_TYPE_TAP_PASTA; + break; + case MODE_VU: + ref.type = EPOLL_TYPE_VHOST_CMD; + break; + } + + ev.events = EPOLLIN | EPOLLRDHUP; + ev.data.u64 = ref.u64; + epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); +} + /** * tap_listen_handler() - Handle new connection on listening socket * @c: Execution context @@ -1262,8 +1289,6 @@ static void tap_sock_unix_init(const struct ctx *c) */ void tap_listen_handler(struct ctx *c, uint32_t events) { - struct epoll_event ev = { 0 }; - union epoll_ref ref = { 0 }; int v = INT_MAX / 2; struct ucred ucred; socklen_t len; @@ -1302,14 +1327,7 @@ void tap_listen_handler(struct ctx *c, uint32_t events) setsockopt(c->fd_tap, SOL_SOCKET, SO_SNDBUF, &v, sizeof(v))) trace("tap: failed to set SO_SNDBUF to %i", v); - ref.fd = c->fd_tap; - if (c->mode == MODE_VU) - ref.type = EPOLL_TYPE_VHOST_CMD; - else - ref.type = EPOLL_TYPE_TAP_PASST; - ev.events = EPOLLIN | EPOLLRDHUP; - ev.data.u64 = ref.u64; - epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); + tap_start_connection(c); } /** @@ -1353,19 +1371,13 @@ static int tap_ns_tun(void *arg) */ static void tap_sock_tun_init(struct ctx *c) { - union epoll_ref ref = { .type = EPOLL_TYPE_TAP_PASTA }; - struct epoll_event ev = { 0 }; - NS_CALL(tap_ns_tun, c); if (c->fd_tap == -1) die("Failed to set up tap device in namespace"); pasta_ns_conf(c); - ref.fd = c->fd_tap; - ev.events = EPOLLIN | EPOLLRDHUP; - ev.data.u64 = ref.u64; - epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); + tap_start_connection(c); } /** @@ -1399,26 +1411,8 @@ void tap_backend_init(struct ctx *c) tap_sock_update_pool(pkt_buf, sizeof(pkt_buf)); if (c->fd_tap != -1) { /* Passed as --fd */ - struct epoll_event ev = { 0 }; - union epoll_ref ref; - ASSERT(c->one_off); - ref.fd = c->fd_tap; - switch (c->mode) { - case MODE_PASST: - ref.type = EPOLL_TYPE_TAP_PASST; - break; - case MODE_PASTA: - ref.type = EPOLL_TYPE_TAP_PASTA; - break; - case MODE_VU: - ref.type = EPOLL_TYPE_VHOST_CMD; - break; - } - - ev.events = EPOLLIN | EPOLLRDHUP; - ev.data.u64 = ref.u64; - epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); + tap_start_connection(c); return; } -- 2.47.1