From patchwork Wed Oct 23 14:20:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 3909 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:6bd6:b0:5b9:581e:f939 with SMTP id c22csp431723max; Wed, 23 Oct 2024 07:20:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWgGEZWV5d8uxtKIRK86/zj66vQAWpjrzy7THUzyLw8ddQQ798VLGv66coTZrAQoUCvmtxiAPxayGg=@openvpn.net X-Google-Smtp-Source: AGHT+IEXmSdkPoYtuCU1kTlZvD3fZmnB8R1ps2w3cFGHeGuyHhvPNzAF8b+mhab+d86VQECLUiEY X-Received: by 2002:a05:6870:e40f:b0:277:fc10:3da4 with SMTP id 586e51a60fabf-28ccb694b4amr3109709fac.39.1729693254443; Wed, 23 Oct 2024 07:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729693254; cv=none; d=google.com; s=arc-20240605; b=bUYOVU3TG4R3oJpb9BFSEW5kJ2KTDXixM0wcl5MyuwGJt9DrDn/juUi6UdzEoZf/o/ hO4Ca1XAzEbOgY8j4qyjzlnwcpWZmsk1S9NqvuhNnaq85oZxsLOyOsGW33sfdqSixbtP Qwbl2DlMvyqtAtve7v7oLby38+9Bs+qQpg7cgg5oCXlU0VwiPo6STn0AmuYPh9g9jWbM tgXvLlcU6BZpmeIhRvfwqr0dK2s+pPhNvHvov4TP0uRCu8Bda2xTkFFTah9DM51wienK /mPPrPMGjvmSiSzmSSEOVd5dsHOv/QG7jIzfXILemDtnccNPX/SUEdkKp/xupgeGeLZw wu/Q== 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=z84fqwNCKYCq+PZtaVI7Ukjz3HZ3PWeJbhgcmWab1y8=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=O+hHOtw/swLaQAqdI7oG4vrXQ7Wxnbw5ip+fqS4Ei497J5UBbsAUrBpV9tewghjavw PbHECSg9+R8heXLK/jGvryhD+jHsqz+BX3WGmOu6IF/t6sBNcCuRQcT8sFwinmsG5eDA tQJult+aqJEacJM5lFmmZbFnHGdtbYdxaHiFBMeqBjWLqymfyZi2B+NYrWhEQDHqraBS EsVLUMJNRVx+Yj/EHlkQ2Rh8mInUaSB/4G5Ks8KGMW4WFsDjQysx8cHplaNT+/NcGr20 liuSGFI7/R4G+E3UdaD6AKi5Ui0Rv+ad7ER4GBMOPrZBx6EaqIerzT5DGVwoyUXWgHwG 6M5Q==; 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=JPIbc4hv; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=IjGdJgz+; 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 46e09a7af769-7182ebc67adsi4029397a34.187.2024.10.23.07.20.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Oct 2024 07:20:54 -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=JPIbc4hv; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=IjGdJgz+; 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-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1t3cE8-0002ab-Pl; Wed, 23 Oct 2024 14:20:45 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1t3cE7-0002aU-5A for openvpn-devel@lists.sourceforge.net; Wed, 23 Oct 2024 14:20:43 +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=YSqldq11H+94Tc7Qoj7c06Bia3Ecm6wdFL/B6Gwfc+U=; b=JPIbc4hvtPLm44QCr2KqhtYnUu GZt6pTpN/uo1Eyfl1T+n+DVWg3vNsnO+dmmysavbfRykpUAaE7/aw7etVfpQ7vSLrp8KfeWwx/kkO 2toGcbARWJxkTJIxnbB+AdzK4ht37O4YSEBUr7lqz8uZepegvuXZrg/A4JaF3l16vGgg=; 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=YSqldq11H+94Tc7Qoj7c06Bia3Ecm6wdFL/B6Gwfc+U=; b=IjGdJgz+of3kNZV7oVpYfpCW8j v4RmCVi3pVzpg++sZ+iAC8eV7YzMWdryEy4oDB7l+najDDDZQ23tskooMYw9KgPme6VxEomFffwru 1WoWosLaUG4wNXL2FmzGQPnn2jRqnmJ2bGPb80PJelUTioaPTk+QTecwLkv4tIzEvMZc=; 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 1t3cE6-0000mG-MD for openvpn-devel@lists.sourceforge.net; Wed, 23 Oct 2024 14:20:43 +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 49NEKV9i000742 for ; Wed, 23 Oct 2024 16:20:31 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 49NEKVoO000741 for openvpn-devel@lists.sourceforge.net; Wed, 23 Oct 2024 16:20:31 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Wed, 23 Oct 2024 16:20:30 +0200 Message-ID: <20241023142030.731-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-2.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.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1t3cE6-0000mG-MD Subject: [Openvpn-devel] [PATCH v6] 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: , 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?1813714834134456793?= 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 --- 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/+/760 This mail reflects revision 6 of this Change. Acked-by according to Gerrit (reflected above): 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 28f6e8e..a2841f0 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -60,7 +60,13 @@ #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; + unsigned int ret; + unsigned int tun; + unsigned int sock; +}; #ifdef ENABLE_DEBUG static const char * @@ -686,7 +692,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)