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=Yvf/AlUJ; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id EF2635A004E for ; Tue, 10 Dec 2024 15:36:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733841379; 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: in-reply-to:in-reply-to:references:references; bh=lWA0h0qjdfC0USCJVN94kltzESD0ndfSkRzzlPT3Xds=; b=Yvf/AlUJOYd8tzb/BVHqFm1vd4O6Y4cl2siC+geiqnjJYqG5Y55VTWJAjr4kP5nwbZOL1Y 2hf7uXnz5AAY3mGh98gZwNFXrQwklSpGCskIXjDE1rJWc5EjYviOiBgD7zphaCF1ZpuAEr ltPiQbmqsVpTv6A98EeHYnLkhwFLhS4= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-196-Oq9phHlENzuTMCGYXKI_nQ-1; Tue, 10 Dec 2024 09:36:15 -0500 X-MC-Unique: Oq9phHlENzuTMCGYXKI_nQ-1 X-Mimecast-MFC-AGG-ID: Oq9phHlENzuTMCGYXKI_nQ Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385f0829430so3869266f8f.1 for ; Tue, 10 Dec 2024 06:36:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733841373; x=1734446173; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lWA0h0qjdfC0USCJVN94kltzESD0ndfSkRzzlPT3Xds=; b=m92GoZMiqyZO3ZzwcWVFbtiMFFnVo8JAd7GCTkejuCMbXpxs1zHftB1Ss3lgezGJH+ jSNLqYr4L/fQvCF+knp5SDS5sYIf0hIvPsS+7L9MDKJyfTaMx5b3mQC30cqZ3WZHp3zL Rf4tHd/SWXI0VLhX8AccmnAVuSvjMpxm4XIh0FKj39A2K8RNbAC2rpyhdNabg6Aii+pU nqJQEHR5KJ7CHh8Pg1gMp5PlEg7pYhEYjkM8hOuhY76AcWyUtIVf3kMu4ryEZbxIAcgV c93fadu6DB/NX6dbm3FJZp686cxHFPxZOV+TEKRDq7wQlonVeJaDEghaYFrg++mefQfJ uttg== X-Gm-Message-State: AOJu0Yw3xK4CzQevkXAgplp5BsnehZY9OVJfn5s6odMOwtTD3RTGzZlH PV+JYSoCJS2rb/PQ37LJIO+saElQK7khJtEM/YQW1XaHCYtRoNV6fiIp3NC8LTlUvwFpKUXL+c8 QDS8SZ28molhCEpGCYRnB/fXdCHf020Ky3kLoPsgD3FMvK2NK1GLjZt18JA== X-Gm-Gg: ASbGncuW1PP6jCgmMWJLj87DgoE11VXvs2z8u2rLdf4PUOc14bg+cKrgxQ7WHEHss7v MJxRVRgt90S851nJ5o2cEE6t8Sg5WEeu7MJtQJY2xk90XqgfQAN8s45EIIOGSvtSCHVZAaisy/e /OA9imGsfUissaD/bLRlmBWSJbHAXoGZhBOGXdeCjBcRFf4JjEu1hpMQddzABMuZ4SZxeuoiPr+ OgnMltmI4A2CV0ixEHMEHjsMKQNLIc+c5ikBCfaq7lJsyeocvETdxePJLiBuyYSbwyeOIdSNbpD f0DWjvY= X-Received: by 2002:a05:6000:2b05:b0:385:fe66:9f32 with SMTP id ffacd0b85a97d-386453fd699mr3299382f8f.52.1733841373521; Tue, 10 Dec 2024 06:36:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXz7FgNzxo+IhY9JpGipvjFXY9XHezFTgMnRCSlVv6zCHCvDnlRGrtE1TxaWzb8y1bxlTKjg== X-Received: by 2002:a05:6000:2b05:b0:385:fe66:9f32 with SMTP id ffacd0b85a97d-386453fd699mr3299364f8f.52.1733841373157; Tue, 10 Dec 2024 06:36:13 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-386355d4df3sm10603558f8f.103.2024.12.10.06.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 06:36:11 -0800 (PST) Date: Tue, 10 Dec 2024 15:36:10 +0100 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH 1/2] tap: Use a common function to start a new connection Message-ID: <20241210153610.3e2917b3@elisabeth> In-Reply-To: <20241209165450.2314060-1-lvivier@redhat.com> References: <20241209165450.2314060-1-lvivier@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wijHxs95V8d4W5jG_MW5iJA45L7rlOes0cVvYQNLHA4_1733841374 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 2H6IUOH34OIUBO3H7DFZ6AO2NIKQ5RRI X-Message-ID-Hash: 2H6IUOH34OIUBO3H7DFZ6AO2NIKQ5RRI X-MailFrom: sbrivio@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: passt-dev@passt.top, David Gibson 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: On Mon, 9 Dec 2024 17:54:49 +0100 Laurent Vivier wrote: > 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; > } >