From patchwork Wed Oct 23 08:08:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 3903 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:6bd6:b0:5b9:581e:f939 with SMTP id c22csp229645max; Wed, 23 Oct 2024 01:09:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVoEKNHQ8Q5o7TIYybKizcMrLGPNiAgjiUyVMyZLyefeq9+0b9ZmQlanSURuQ/XYi+Xm9kZs9tFqcg=@openvpn.net X-Google-Smtp-Source: AGHT+IHfUt90usZY6bDVZY2zLD+b06cdipb9rHP94J/5ctQnSth0Pjl2bMH+vG+rmB5K3ZIc170x X-Received: by 2002:a05:6602:6001:b0:82d:3c2:9118 with SMTP id ca18e2360f4ac-83af64136d7mr166579939f.16.1729670967734; Wed, 23 Oct 2024 01:09:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729670967; cv=none; d=google.com; s=arc-20240605; b=iVeBpuwSnOTgySWWgvJ4u1xFC0+ew7K9FXXI2tzVuuR83T1z7mnkMhv50Cm46tCK/m LlkZH4azG2+iaaR1SV69GOGpOsSdZhv87LFb1KdZzlCA6UfeB81edFSPk4Vx2rAPIxSh ezWv2tqapBNqhUGcY/+3Z89jHcOtgP8pPD22N07drj5SBte3ur7C8USP2J7TD8Rxyr7U oFzrebnFAyby01w4KILV8XwxzwX+7tpz+DSg8bbabzUU+qp7HNGhlRrtBeGLwuyw90JN 3FiUaunNx7QvCdHpWFXxtbYDHT/OFY6vWebFkaBgydchv9xLOWk0heEQVGv0Oawv6Q+c rGyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature; bh=QILayIup59by7KXI0EpsDmvDU8uRPhbwhGt14JFiqPU=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=SYm53J4e3NEIqastuCuidPn8AS3+YB7jZnXlAO2RZd94sNhsPxJAKogle2c63ynI0a 5QM4rw82CqxhJfXHA6y1WNxJE0xLlqN64RNWUK3Yr4TX8vc2b0YdjRMnqLhrwVXmh4bz OGckU/kYk9Fu9broSXsFC2eJmG1bE2A1/SYkYctWRK+LrwpPnzLLSTaM+cNKaPngsQjb +qxg2j2iyLuB3oosGzRv5n+Kaj95gMp+tIyhqR0hRkGNYvkz8bNh/Ops7jnHmwjGWzLT 4+46Yo9I6I2S6Bb1NEk6feMuq3xUGzZc8W97T0ffNHRIVWkF0ujxdm0est9NSns9f/Bs 6Gew==; 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=NZgDouFX; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=RYRZ3Zdb; 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=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 8926c6da1cb9f-4dc2a4ad7desi3517903173.50.2024.10.23.01.09.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Oct 2024 01:09:27 -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=NZgDouFX; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=RYRZ3Zdb; 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=muc.de 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 1t3WQZ-0007bL-J7; Wed, 23 Oct 2024 08:09:11 +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 1t3WQX-0007b4-GL for openvpn-devel@lists.sourceforge.net; Wed, 23 Oct 2024 08:09:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=zdi9oMr5Ti+AQpCYZtJE2YUqd5caOXfdk1v1z/rwzAM=; b=NZgDouFXCV39rs8WTUI6XRaKoI sQvbW4lGEIL5ZJ44C8f9TWw4sv0UMx74w0hDwwqirNxv9alofF+//0k+uMHT5hbeR6VZH89XeSBG2 66LL/93IEjy+lj/d3E5sCn41qh+TRqUI1Oku1mBFzVwkD8arS8TEXH0ZTQNS3FQW5sUw=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=zdi9oMr5Ti+AQpCYZtJE2YUqd5caOXfdk1v1z/rwzAM=; b=RYRZ3ZdbiI2PHFUUH/4UUCi0OD imXJK9RiBmBTtXkCAB/Z6+8/d+BRVtgXmZzpqf6OTkLLPImjM7V9O7mgaYyAXs9F1PozW91FNR/uU wyCplDSlj3dEea8GJKhlXy7MROsWd+fjkmiD7UqJNoaNWpB+wQDG9ZA87L7j1skaVEjM=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1t3WQT-0002RD-U3 for openvpn-devel@lists.sourceforge.net; Wed, 23 Oct 2024 08:09:09 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.17.1.9/8.17.1.9) with ESMTP id 49N88rcH003811 for ; Wed, 23 Oct 2024 10:08:53 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 49N88rpS003810 for openvpn-devel@lists.sourceforge.net; Wed, 23 Oct 2024 10:08:53 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Wed, 23 Oct 2024 10:08:52 +0200 Message-ID: <20241023080853.3710-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: -0.0 (/) 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: From: Antonio Quartulli 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 poked by an incoming conne [...] Content analysis details: (-0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-Headers-End: 1t3WQT-0002RD-U3 Subject: [Openvpn-devel] [PATCH v5] 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1812891637187632618?= X-GMAIL-MSGID: =?utf-8?q?1813691464225032235?= From: Antonio Quartulli 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 poked 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. Change-Id: Icd7f6a2ad350cdc2312b3e80fa0dbdd7e4311d2e Signed-off-by: Antonio Quartulli Signed-off-by: Gianmarco De Gregori Acked-by: Frank Lichtenheld --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/757 This mail reflects revision 5 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld 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..c002a38 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -54,7 +54,6 @@ /* * Special tags passed to event.[ch] functions */ -#define MTCP_SOCKET ((void *)1) #define MTCP_TUN ((void *)2) #define MTCP_SIG ((void *)3) /* Only on Windows */ #define MTCP_MANAGEMENT ((void *)4) @@ -253,7 +252,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 +262,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 +279,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 @@ -693,20 +692,43 @@ { struct event_set_return *e = &mtcp->esr[i]; - /* 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) + struct event_arg *ev_arg = (struct event_arg *)e->arg; + 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 @@ -731,18 +753,6 @@ multi_tcp_action(m, NULL, TA_TUN_READ, false); } } - /* new incoming TCP client attempting to connect? */ - else if (e->arg == MTCP_SOCKET) - { - struct multi_instance *mi; - 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); - } - } #if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD)) /* incoming data on DCO? */ else if (e->arg == MTCP_DCO) 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..1b99ef7 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -102,6 +102,12 @@ 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; /**< this struct will store a pointer to either mi or + * link_socket, depending on the event type, to keep + * it accessible it's placed within the same struct + * it points to. */ + struct gc_arena gc; bool halt; int refcount; diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 7b1e603..cf04090 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -1830,6 +1830,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 2e583af..c152ab0 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -178,6 +178,11 @@ { struct link_socket_info info; + struct event_arg ev_arg; /**< this struct will store a pointer to either mi or + * link_socket, depending on the event type, to keep + * it accessible it's placed within the same struct + * it points to. */ + socket_descriptor_t sd; socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */