From patchwork Mon Sep 23 13:41:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "flichtenheld (Code Review)" X-Patchwork-Id: 3854 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:10cd:b0:5b9:581e:f939 with SMTP id j13csp2171898mae; Mon, 23 Sep 2024 06:41:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXeoF56nvgGSQk/NXXMnQ9MX4iYTxSSWBmCgNNISlnupAUYTUqSoXl9Iomxa/4DsQK6ZrcmC/bYiFg=@openvpn.net X-Google-Smtp-Source: AGHT+IF/iqYqo5C7VDFyV1Sp2pifRLV3SDx9B7yif7Gsvt40PIuB3KdKBmrnemxhrrrUCfDkCZrc X-Received: by 2002:a05:6602:6b86:b0:82c:d794:4695 with SMTP id ca18e2360f4ac-8320b29648fmr810421739f.7.1727098892737; Mon, 23 Sep 2024 06:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727098892; cv=none; d=google.com; s=arc-20240605; b=ENSNGcmndSwp5+y5NvdOe2EUgMCpU3Th+RzPPihGE3XGaAWfd+zh5NQmOBRMc9vv8r WBkGcFK9+jUIiVNz9UYxCJ/Cfv/B7dy4kOMdeKB/HrnkBBsD9W55V60PbPJfkUGK4d7U /PRYEcHHhKIfiMKcsVM3nHatiZmw0k6s10VuAhZDhuXVW8tHqwuMfpN4MSIu2od6/ZQ4 TfhA7Ipv3XSUUQEsCXTaGN1L5NkqE8y5vPjuZIZrlnKTB2REiONGcNjpqA0r19LxokAf HP2A4LIx5qVd0vM8p35YfRSvbrEbdodjhu2KlAYv8DL0uL1cVLvm4oXS972GCM3iYw2E Ywwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :mime-version:message-id:references:auto-submitted:to:date:from :dkim-signature:dkim-signature:dkim-signature; bh=bBhH7KJKi3snO8O913nYbljg6/aI7uBQHrGPwbMEuFs=; fh=U7wEyxtwz2o5+UdevFSA47vNeG9knhWH0KV//QhD5a0=; b=f2J7KJUiKXND2Hp8wLOqAQ04HiS0NvvH8hXyrus9G8NZlW0izWFPOmjr5453cp8rEq nVRGGFN/G5fop4A/sxVvBLY5h5qri/oEIEzPNo6k0R+SCyEttAtdAwLGJFwdbuhfzXvJ 3wBQyyKH1S3lmY9vyQqMAAWAKlsUV40LRXQvlseMzA/ZqzaGivqigoORPqEcR+Cj4qtT yZHVfne9/QiCZGgOppAyC9vKdfd4TK2JRtFs64b6aCijB2v0lx1U0tyHuWneIzqhtXXX +3u5wHv6R+Oh4OvM1PD2wI5SKKXChAA+kjaLTE+rTFZwwW5RUtG81QhM2pBUmrdWc+8b BcoA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=aqyenR2Z; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="YhACx5v/"; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=bZZZxM58; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net; dara=fail header.i=@openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id ca18e2360f4ac-82d49350245si914594239f.134.2024.09.23.06.41.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Sep 2024 06:41:32 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=aqyenR2Z; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="YhACx5v/"; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=bZZZxM58; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net; dara=fail header.i=@openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1ssjJh-0004Hb-5z; Mon, 23 Sep 2024 13:41:29 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ssjJe-0004HK-JH for openvpn-devel@lists.sourceforge.net; Mon, 23 Sep 2024 13:41:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:To:Date: From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OdiKnkZ1ZyHE7GgOVG0z7WpQAlRT8fNoucmBT3txIz8=; b=aqyenR2Z0MawuZtKzJhbPzbypY JF87Ee/DMEFRJ/BAJsaeJNpMOIlZCDgaA9KY7BzWiEy0zDEwKNOUhn1xWyZ16RHFvRFWXE0nBQBF/ jT3ksz/ZVOun61MNjeFYTDts/yFcqhzYrjB9y1aZlCskV9qkcl2Zzp52KFl+mhh0rt38=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:To:Date:From:Sender:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=OdiKnkZ1ZyHE7GgOVG0z7WpQAlRT8fNoucmBT3txIz8=; b=Y hACx5v/C6ZJGnIkAC5LuznG/ZKQYA0gUJ6lXqfqEb8apNoPQkCNkH6ZB+Phbw25D/aiv2ydNn9dM1 FwcoZ+YE8uXLU2GaML0UGfhQknl5dPHAC1Z9G01z4z6w7EQ543oiwbMbURZ+bHVcPDvoQIUkhGVFy rTOyfVMt+giGvnao=; Received: from mail-wr1-f48.google.com ([209.85.221.48]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1ssjJd-0006pp-AD for openvpn-devel@lists.sourceforge.net; Mon, 23 Sep 2024 13:41:26 +0000 Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-378f90ad32dso2698541f8f.0 for ; Mon, 23 Sep 2024 06:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1727098879; x=1727703679; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=OdiKnkZ1ZyHE7GgOVG0z7WpQAlRT8fNoucmBT3txIz8=; b=bZZZxM58JNgpRmP+ANz4YoqbSY7Z5dCwHf0ycceqxQoBbF4uAdyVCmpHykEWZ4bTt7 LMNQTFo4O7jEsPuXlO2oyPhgXWaV4x136pDLNBaSU6bAguLqXRhVPcvmUnpSh6vI0w3u qdjyDR5Xw/bNyW8HZdDPtPQZ3XMqFb+m83zqKoLobILE+mb/kHRhsqtTR/IJ0S35XHDX /otNE46aOyq+ksPKuZMkSaUuKAt6ZEK4FOZAsgfnnJPgWuoQSclBpOybWocd7WBoShbV TEMsLZCTSPKq45iV83e8jLebGPGsWV71JRabSLvU6gWsuFTkw1B9w5Htz3e26g3gT7hk 3Wfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727098879; x=1727703679; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OdiKnkZ1ZyHE7GgOVG0z7WpQAlRT8fNoucmBT3txIz8=; b=k2Jqi4GsuDj9+fVD5Hfnk4mSdD/8rlAH6mIqxSFGRZSfQwro4BfgMnF+jlfG+sTR3k Hdj2gYNedBU+EUGyk+moreBS5uKbexMQouaNHKqgWjt0UcdeDdVxAs71Oe0LBe50JJWq kQscnjChQXwCMx70dUivZPBZJ4KnSRT9HIkmXbsFbxHkR4D67uPyTe4xL92sFIH/4/QX XKyKeezWDIFhzmn7g/uNivvW4lRRbrvbtaUlgv6xvpyHEfUi7XnF8uB4jZSDoj+O/faS TCoVtmycjirR/yOWrkwuLv09hMutsTnjNJ10rmPNQ+0IaXcUMc5T2wLbG8p2spcd11Q5 6rjA== X-Gm-Message-State: AOJu0Yy7jTcxxpQWAO9SgueDzQtK8x4Amlm6ZTTpyNOkhGhFB4bzqImo oL+Laxs2ayMR0Q5Q4jTpSuATTATWDQye0xg+icoIIa0vaenG5SLG6lQ5vCmMqm7+UVAvsErUq1B J X-Received: by 2002:a05:6000:1003:b0:374:c23a:2ce8 with SMTP id ffacd0b85a97d-37a431a6f8fmr7210051f8f.52.1727098878561; Mon, 23 Sep 2024 06:41:18 -0700 (PDT) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e71f062esm24714420f8f.7.2024.09.23.06.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 06:41:18 -0700 (PDT) From: "its_Giaan (Code Review)" X-Google-Original-From: "its_Giaan (Code Review)" X-Gerrit-PatchSet: 1 Date: Mon, 23 Sep 2024 13:41:17 +0000 To: plaisthos , flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e X-Gerrit-Change-Number: 757 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 198bbd73f83b6d72d1dbf342d3b3ecd2c6115ebc References: Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -1.1 (-) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Attention is currently required from: flichtenheld, ordex, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-1.1 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.221.48 listed in list.dnswl.org] -0.9 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.221.48 listed in wl.mailspike.net] 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML X-Headers-End: 1ssjJd-0006pp-AD Subject: [Openvpn-devel] [M] Change in openvpn[master]: event/multi: add event_arg object to make event handling more generic X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: gianmarco@mandelbit.com, arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com, a@unstable.cc Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1810994448563953933?= X-GMAIL-MSGID: =?utf-8?q?1810994448563953933?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld, ordex, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/757?usp=email to review the following change. Change subject: event/multi: add event_arg object to make event handling more generic ...................................................................... event/multi: add event_arg object to make event handling more generic In order to prepare the event handling code to deal with multiple listening sockets, we have to make sure that it is possible to distinguish which of these sockets have been pocked by an incoming connection request. To achieve that, this patch changes the object being passed as event handler argument, from a "partly integer evaluated variable" to a full struct with a proper type attribute. This struct will allow the code to carry around the particular listening socket where the connection is being established. This change affects the TCP server code path only as UDP servers use only one socket to handle all clients i/o. Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e Signed-off-by: Antonio Quartulli --- M src/openvpn/event.h M src/openvpn/mtcp.c M src/openvpn/multi.c M src/openvpn/multi.h M src/openvpn/socket.c M src/openvpn/socket.h 6 files changed, 59 insertions(+), 15 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/757/1 diff --git a/src/openvpn/event.h b/src/openvpn/event.h index 856551a..844ea7b 100644 --- a/src/openvpn/event.h +++ b/src/openvpn/event.h @@ -126,6 +126,20 @@ struct event_set_functions func; }; +typedef enum { + EVENT_ARG_MULTI_INSTANCE = 0, + EVENT_ARG_LINK_SOCKET, +} event_arg_t; + +/* generic event argument object to pass to event_ctl() */ +struct event_arg +{ + event_arg_t type; + union { + struct multi_instance *mi; /* if type = EVENT_ARG_MULTI_INSTANCE */ + } u; +}; + /* * maxevents on input: desired max number of event_t descriptors * simultaneously set with event_ctl diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c index 96408d1..e47712a 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -253,7 +253,7 @@ socket_set(mi->context.c2.link_socket, m->mtcp->es, mbuf_defined(mi->tcp_link_out_deferred) ? EVENT_WRITE : EVENT_READ, - mi, + &mi->ev_arg, &mi->tcp_rwflags); } } @@ -263,8 +263,8 @@ struct multi_tcp *mtcp) { int status; - unsigned int *persistent = &mtcp->tun_rwflags; - socket_set_listen_persistent(c->c2.link_socket, mtcp->es, MTCP_SOCKET); + socket_set_listen_persistent(c->c2.link_socket, mtcp->es, + &c->c2.link_socket->ev_arg); #ifdef _WIN32 if (tuntap_is_wintun(c->c1.tuntap)) @@ -280,7 +280,7 @@ persistent = NULL; } #endif - tun_set(c->c1.tuntap, mtcp->es, EVENT_READ, MTCP_TUN, persistent); + tun_set(c->c1.tuntap, mtcp->es, EVENT_READ, MTCP_TUN, &mtcp->tun_rwflags); #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) dco_event_set(&c->c1.tuntap->dco, mtcp->es, MTCP_DCO); #endif @@ -692,21 +692,43 @@ for (i = 0; i < mtcp->n_esr; ++i) { struct event_set_return *e = &mtcp->esr[i]; + struct event_arg *ev_arg = (struct event_arg *)e->arg; - /* incoming data for instance? */ + /* incoming data for instance or listening socket? */ if (e->arg >= MTCP_N) { - struct multi_instance *mi = (struct multi_instance *) e->arg; - if (mi) + switch (ev_arg->type) { - if (e->rwflags & EVENT_WRITE) - { - multi_tcp_action(m, mi, TA_SOCKET_WRITE_READY, false); - } - else if (e->rwflags & EVENT_READ) - { - multi_tcp_action(m, mi, TA_SOCKET_READ, false); - } + struct multi_instance *mi; + + /* react to event on child instance */ + case EVENT_ARG_MULTI_INSTANCE: + if (!ev_arg->u.mi) + { + msg(D_MULTI_ERRORS, "MULTI: mtcp_proc_io: null minstance"); + break; + } + + mi = ev_arg->u.mi; + if (e->rwflags & EVENT_WRITE) + { + multi_tcp_action(m, mi, TA_SOCKET_WRITE_READY, false); + } + else if (e->rwflags & EVENT_READ) + { + multi_tcp_action(m, mi, TA_SOCKET_READ, false); + } + break; + /* new incoming TCP client attempting to connect? */ + case EVENT_ARG_LINK_SOCKET: + ASSERT(m->top.c2.link_socket); + socket_reset_listen_persistent(m->top.c2.link_socket); + mi = multi_create_instance_tcp(m); + if (mi) + { + multi_tcp_action(m, mi, TA_INITIAL, false); + } + break; } } else diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 0509911..45b3cfa 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -823,6 +823,9 @@ goto err; } + mi->ev_arg.type = EVENT_ARG_MULTI_INSTANCE; + mi->ev_arg.u.mi = mi; + perf_pop(); gc_free(&gc); return mi; diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 7167639..e403989 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -102,6 +102,7 @@ struct schedule_entry se; /* this must be the first element of the structure, * We cast between this and schedule_entry so the * beginning of the struct must be identical */ + struct event_arg ev_arg; struct gc_arena gc; bool halt; int refcount; diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 6c790a0..924e30c 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -1827,6 +1827,8 @@ ALLOC_OBJ_CLEAR(sock, struct link_socket); sock->sd = SOCKET_UNDEFINED; sock->ctrl_sd = SOCKET_UNDEFINED; + sock->ev_arg.type = EVENT_ARG_LINK_SOCKET; + return sock; } diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index bbdabfb..6857202 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -166,6 +166,8 @@ { struct link_socket_info info; + struct event_arg ev_arg; + socket_descriptor_t sd; socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */