From patchwork Mon Oct 14 12:29:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3893 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:1757:b0:5b9:581e:f939 with SMTP id c23csp1878955maw; Mon, 14 Oct 2024 05:29:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV3NMIn0cGbvgCWq2M5TkiG4fw/isEcFyHscte8zyHOBm1rISVTCberpxXIymHZVoLfq9qgsW5CUjs=@openvpn.net X-Google-Smtp-Source: AGHT+IGRIANrQK7F05v1BlBXv2JVjDktssa99SAnXzqCW0ZqkUL2jsnGU7aMt8Jm3woz4OiZcQsL X-Received: by 2002:a05:6808:1641:b0:3e4:d4ca:2774 with SMTP id 5614622812f47-3e5d2218636mr2971383b6e.20.1728908971084; Mon, 14 Oct 2024 05:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728908971; cv=none; d=google.com; s=arc-20240605; b=D/NHZl5QNlENT5zQUrXmDbCjTBTWs0JME/J47Gil5Mlyt/n5EQzwa3RvhCfzD1A1wI WjTt7jta2O5g1L+um0PC4YUjwainm0e3+IPFJekff1AptdgnEC2EJ/e6Vvm3xMPOHZLo UdE19VTG0oBffGbyVoR1wLhx5UGy8O2QmLYkjzyl2MaQA3SXQyvpiBfLuwjkUO8nQ1N0 CP43pgo+XubquKUMv5PPwLLAve99W6vKMq17NJY91GBLBXPIeoB+dE90KqpMzQwXgA6z KfweuGadnool5VrRFK+v7s/zp27BWLqRemmm8OZo1lPKuBUKBXlCT4XjlpJP9025FCVN NKAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:cc: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:dkim-signature; bh=+3kHZ10uHret+JerEmXMKciyocK8DZ92wOzE7wtxoRk=; fh=yXAbqwSLX4AZy2IfjuXV6xw9sEGAlDO35mmlrsbkSnM=; b=BWuhOB73xhBWBlh2glxC2a04LnBtzXvDl+RPWIxyCb4JBCs2KjAqTmFdrXZh4u7fTn Qa6WN6r4rsjqsoieBUX4rIssiI96zhcRsQasbaF71pDbP3B7lyDHEAtN3//G0ZdZERNt CH+p9fJ7Y7fSP2H6QlqWpD0lt4lDaJpMSqS6PDgYhqIov0J2iB4+HvlfjMCEX7GV8uuS jBQZk5sOT6NCHtRReFq0vvfEEBi5T4c+04QiTmu3qAO+V2nKN4mCxYBsNtz9uhjokOGi gw1GkP6whDOe24swRQx5CkFjJwQCZBE3FfJ7qxCmGpZ25F3Wpuamqnl/D9jdm6IkLH4B yevw==; 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=fKFWrdxi; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=ZinGkVlc; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=hP6lfZTh; 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 Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-3e515021241si4443377b6e.233.2024.10.14.05.29.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Oct 2024 05:29:31 -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=fKFWrdxi; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=ZinGkVlc; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=hP6lfZTh; 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 Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1t0KCS-0002PZ-Mr; Mon, 14 Oct 2024 12:29:24 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1t0KCS-0002PS-9N for openvpn-devel@lists.sourceforge.net; Mon, 14 Oct 2024 12:29:23 +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:Cc:To:From:Sender:Reply-To: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=suPs6OLING7z0Thbgpt1KHbBT+p8Yy58ahsvALwTS64=; b=fKFWrdxijBg7/AJjiRGIu4cDB0 8cpYSenFfm6RLXj62eE8hPzGmjponR41Nu05YBTmQ3ili/wv8hwOsy8AwVXWNGUsBsj/VOoEmrWrb nB8BPG1jIfY3L6fkzpElREafpwKVFANw2y6AdhTnnI7Xv7f5YTflv4kLHR+KLibou/ok=; 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:Cc:To:From:Sender:Reply-To: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=suPs6OLING7z0Thbgpt1KHbBT+p8Yy58ahsvALwTS64=; b=ZinGkVlcw8xe4hv5qUol+KrqWO YDoDGHMKMhTkmLoarBGCILGTanltTGXUIiRoeOoU+X0MlY14DQ/UWitKJBYMBAxnSAvgekNS78vcN 6n3v1ObLuI0sR7O08dRC4EnwU88Mg3sMbGjZBh7gzKEIvlIxlEvbJesJO5JCOIYflWrg=; Received: from mout-p-201.mailbox.org ([80.241.56.171]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1t0KCQ-0005bK-Ob for openvpn-devel@lists.sourceforge.net; Mon, 14 Oct 2024 12:29:23 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4XRxP12m1Bz9smn; Mon, 14 Oct 2024 14:29:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1728908949; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=suPs6OLING7z0Thbgpt1KHbBT+p8Yy58ahsvALwTS64=; b=hP6lfZTh2GRBdLNaQDVhVF821wwAug96EMoUjxmj6Fc+q7fC4c82Kyy+uZk5CohjtO83uY mpmWN0knPwSpaIoD1I1xShd7HFYZx0X73L7vsQXdI/wXtM+cmJVQepVGmqQ1kiaS/H7ni1 s2HzNyjlFTABbpkGWP6uvSf3FOY4IDmDg2QhY1eZV/COMco8XfluNodoeYYPy3cX5XEykQ cMPJAnynsBsZPV+DcZ4kgZ6YsXh8SqibPE/1ZSbvGsgNobbz1kkvo3keHTmP2nrB/JtGPk 3/kZk+5emCqAc357XQlKCvE75L6Ig437MryEIXxpkexL0uIhk/ep1bYFkrTlaw== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Mon, 14 Oct 2024 14:29:08 +0200 Message-Id: <20241014122908.38342-1-frank@lichtenheld.com> In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4XRxP12m1Bz9smn X-Spam-Score: -0.9 (/) 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 allow the code to work with multiple listening sockets it is essential to allow the generic multi_io event handler to distinguish between the various socket objects. Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.171 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1t0KCQ-0005bK-Ob Subject: [Openvpn-devel] [PATCH v4] io_work: pass event_arg object to event handler in case of socket event 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: , Cc: Antonio Quartulli Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1812892453712329906?= X-GMAIL-MSGID: =?utf-8?q?1812892453712329906?= From: Antonio Quartulli In order to allow the code to work with multiple listening sockets it is essential to allow the generic multi_io event handler to distinguish between the various socket objects. This can be achieved by passing an event_arg object that contains a pointer to the link_socket. This code path is used on clients as well as UDP servers. Change-Id: I7ebf0d4fb2a23278e16003b2e35598178155d658 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. Manually added Signed-off-by for Giaan Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/760 This mail reflects revision 4 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 b3ba183..c212e07 100644 --- a/src/openvpn/event.h +++ b/src/openvpn/event.h @@ -82,6 +82,12 @@ #define EVENT_METHOD_US_TIMEOUT (1<<0) #define EVENT_METHOD_FAST (1<<1) +/* + * The following constant is used as boundary between integer value + * and real addresses when passing arguments to event handlers as (void *) + */ +#define MULTI_N ((void *)16) /* upper bound on MTCP_x */ + #ifdef _WIN32 typedef const struct rw_handle *event_t; diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 66e5be1..d50b24c 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -2183,7 +2183,8 @@ /* * Configure event wait based on socket, tuntap flags. */ - socket_set(c->c2.link_socket, c->c2.event_set, socket, (void *)socket_shift, NULL); + socket_set(c->c2.link_socket, c->c2.event_set, socket, + &c->c2.link_socket->ev_arg, NULL); tun_set(c->c1.tuntap, c->c2.event_set, tuntap, (void *)tun_shift, NULL); #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) if (socket & EVENT_READ && c->c2.did_open_tun) @@ -2246,7 +2247,27 @@ for (i = 0; i < status; ++i) { const struct event_set_return *e = &esr[i]; - c->c2.event_set_status |= ((e->rwflags & 3) << (uintptr_t)e->arg); + uintptr_t shift; + + if (e->arg >= MULTI_N) + { + struct event_arg *ev_arg = (struct event_arg *)e->arg; + if (ev_arg->type != EVENT_ARG_LINK_SOCKET) + { + c->c2.event_set_status = ES_ERROR; + msg(D_LINK_ERRORS, + "io_work: non socket event delivered"); + return; + } + + shift = socket_shift; + } + else + { + shift = (uintptr_t)e->arg; + } + + c->c2.event_set_status |= ((e->rwflags & 3) << shift); } } else if (status == 0) diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c index 1b956f4..e89ddba 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -60,8 +60,6 @@ #define MTCP_FILE_CLOSE_WRITE ((void *)5) #define MTCP_DCO ((void *)6) -#define MTCP_N ((void *)16) /* upper bound on MTCP_x */ - struct ta_iow_flags { unsigned int flags; @@ -693,7 +691,7 @@ struct event_set_return *e = &mtcp->esr[i]; /* incoming data for instance or listening socket? */ - if (e->arg >= MTCP_N) + if (e->arg >= MULTI_N) { struct event_arg *ev_arg = (struct event_arg *)e->arg; switch (ev_arg->type)