From patchwork Tue Apr 27 09:13:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 1778 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id yLpwL4diiGBDJAAAIUCqbw (envelope-from ) for ; Tue, 27 Apr 2021 15:14:15 -0400 Received: from proxy11.mail.iad3b.rsapps.net ([172.31.255.6]) by director12.mail.ord1d.rsapps.net with LMTP id yHEUL4diiGBtSAAAIasKDg (envelope-from ) for ; Tue, 27 Apr 2021 15:14:15 -0400 Received: from smtp12.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy11.mail.iad3b.rsapps.net with LMTPS id EFWjKYdiiGCJegAARNREpw (envelope-from ) for ; Tue, 27 Apr 2021 15:14:15 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp12.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=unstable.cc X-Suspicious-Flag: YES X-Classification-ID: c13fdf80-a78c-11eb-ae49-525400ae1f9d-1-1 Received: from [216.105.38.7] ([216.105.38.7:37406] helo=lists.sourceforge.net) by smtp12.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 9E/72-07417-78268806; Tue, 27 Apr 2021 15:14:15 -0400 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.90_1) (envelope-from ) id 1lbT98-0001a0-L3; Tue, 27 Apr 2021 19:13:22 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbT97-0001Zg-8e for openvpn-devel@lists.sourceforge.net; Tue, 27 Apr 2021 19:13:21 +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=AHlJzQitFiw66STEaLQXr4SB2XwWsXXABpKN4NGu3nY=; b=SoSdQhrgF3mOOtVT4aYCTiBzSC u59W4h1AgXgyBbZaSQGWEXAsM0WyGzWb0s9zSEMaUdMsI/X6A9M16t6zrLDP6BlCuPo/A1Z5+JwDO qixTQwmYejFqM53KesbCglW5A5imyAk0eYAbFgDqW9aNIWGJlFC2Ip3b1Z01O8eqKiUg=; 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=AHlJzQitFiw66STEaLQXr4SB2XwWsXXABpKN4NGu3nY=; b=OkAf2A4/M0yEYSVftRASqx7qpy SWsyCojbEY2g7UOvQ9uHoTo1pHThWpdc80bD6C+QjBeVtBBpTtU4XHojTcB/7eLzvtpXwdUfWMBSF wW3rl+RU7hoBGmfUj3E049fXgdr55cjRi23fh/fc7ea8ql6CKMrh7tzv3p86qlBSD/TM=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1lbT8y-000835-2g for openvpn-devel@lists.sourceforge.net; Tue, 27 Apr 2021 19:13:21 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Tue, 27 Apr 2021 21:13:14 +0200 Message-Id: <20210427191314.21317-1-a@unstable.cc> In-Reply-To: <20210426152914.18314-1-a@unstable.cc> References: <20210426152914.18314-1-a@unstable.cc> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: openvpn.net] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1lbT8y-000835-2g Subject: [Openvpn-devel] [PATCH v5] Add documentation on EVENT_READ/EVENT_WRITE constants 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 From: Antonio Quartulli Changes from v4: - get rid of the overly complex EVENT_SHIFT() macro Changes from v3: - re-introduce READ/WRITE_SHIFT because they are different from EVENT_READ/WRITE - define also EVENT_READ/WRITE using READ/WRITE_SHIFT Changes from v2: - moved event definitions to event.h - removed READ/WRITE_SHIFT and use EVENT_READ/WRITE - removed ifdefs around *_SHIFTS definitions in event.h Changes from v1: - fixed typ0s - extended comment - moved *_SHIFT definition to openvpn.h - made READ/WRITE events dependant on _SHIFT definition with a macro Signed-off-by: Antonio Quartulli Acked-By: Arne Schwabe --- src/openvpn/event.h | 44 ++++++++++++++++++++++++++++++++++++++++--- src/openvpn/forward.c | 14 ++++++++------ src/openvpn/openvpn.h | 12 +----------- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/openvpn/event.h b/src/openvpn/event.h index 4af6371e..ce9c31a2 100644 --- a/src/openvpn/event.h +++ b/src/openvpn/event.h @@ -32,9 +32,47 @@ * rwflags passed to event_ctl and returned by * struct event_set_return. */ -#define EVENT_UNDEF 4 -#define EVENT_READ (1<<0) -#define EVENT_WRITE (1<<1) +#define READ_SHIFT 0 +#define WRITE_SHIFT 1 + +#define EVENT_UNDEF 4 +#define EVENT_READ (1 << READ_SHIFT) +#define EVENT_WRITE (1 << WRITE_SHIFT) + +/* event flags returned by io_wait. + * + * All these events are defined as bits in a bitfield. + * Each event 'type' owns two bits in the bitfield: one for the READ + * event and one for the WRITE event. + * + * For this reason, the specific event bit is calculated by adding + * the event type identifier (always a multiple of 2, as defined + * below) to 0 for READ and 1 for WRITE. + * + * E.g. + * MANAGEMENT_SHIFT = 6; <---- event type identifier + * MANAGEMENT_READ = (1 << (6 + 0)), <---- READ event + * MANAGEMENT_WRITE = (1 << (6 + 1)) <---- WRITE event + * + * 'error' and 'file_close' are special and use read/write for different + * signals. + */ + +#define SOCKET_SHIFT 0 +#define SOCKET_READ (1 << (SOCKET_SHIFT + READ_SHIFT)) +#define SOCKET_WRITE (1 << (SOCKET_SHIFT + WRITE_SHIFT)) +#define TUN_SHIFT 2 +#define TUN_READ (1 << (TUN_SHIFT + READ_SHIFT)) +#define TUN_WRITE (1 << (TUN_SHIFT + WRITE_SHIFT)) +#define ERR_SHIFT 4 +#define ES_ERROR (1 << (ERR_SHIFT + READ_SHIFT)) +#define ES_TIMEOUT (1 << (ERR_SHIFT + WRITE_SHIFT)) +#define MANAGEMENT_SHIFT 6 +#define MANAGEMENT_READ (1 << (MANAGEMENT_SHIFT + READ_SHIFT)) +#define MANAGEMENT_WRITE (1 << (MANAGEMENT_SHIFT + WRITE_SHIFT)) +#define FILE_SHIFT 8 +#define FILE_CLOSED (1 << (FILE_SHIFT + READ_SHIFT)) + /* * Initialization flags passed to event_set_init */ diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index df96d048..e302d8e0 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1867,15 +1867,17 @@ io_wait_dowork(struct context *c, const unsigned int flags) unsigned int tuntap = 0; struct event_set_return esr[4]; - /* These shifts all depend on EVENT_READ and EVENT_WRITE */ - static int socket_shift = 0; /* depends on SOCKET_READ and SOCKET_WRITE */ - static int tun_shift = 2; /* depends on TUN_READ and TUN_WRITE */ - static int err_shift = 4; /* depends on ES_ERROR */ + /* These shifts all depend on EVENT_READ (=1) and EVENT_WRITE (=2) + * and are added to the shift. Check openvpn.h for more details. + */ + static int socket_shift = SOCKET_SHIFT; + static int tun_shift = TUN_SHIFT; + static int err_shift = ERR_SHIFT; #ifdef ENABLE_MANAGEMENT - static int management_shift = 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */ + static int management_shift = MANAGEMENT_SHIFT; #endif #ifdef ENABLE_ASYNC_PUSH - static int file_shift = 8; /* listening inotify events */ + static int file_shift = FILE_SHIFT; #endif /* diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h index a15ff08d..6e4651cf 100644 --- a/src/openvpn/openvpn.h +++ b/src/openvpn/openvpn.h @@ -232,17 +232,7 @@ struct context_2 int event_set_max; bool event_set_owned; - /* event flags returned by io_wait */ -#define SOCKET_READ (1<<0) -#define SOCKET_WRITE (1<<1) -#define TUN_READ (1<<2) -#define TUN_WRITE (1<<3) -#define ES_ERROR (1<<4) -#define ES_TIMEOUT (1<<5) -#define MANAGEMENT_READ (1<<6) -#define MANAGEMENT_WRITE (1<<7) -#define FILE_CLOSED (1<<8) - + /* bitmask for event status. Check event.h for possible values */ unsigned int event_set_status; struct link_socket *link_socket; /* socket used for TCP/UDP connection to remote */