From patchwork Wed Nov 15 13:45:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "ralf_lici (Code Review)" X-Patchwork-Id: 3441 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:3c06:b0:f2:62eb:61c1 with SMTP id e6csp2926272dys; Wed, 15 Nov 2023 05:46:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGX9MyT1ZUymu8muJ2hVXN+LUwMTCKp4K2Epau/6MQDdi917XHyPyo9nBVMZDo94UoToh36 X-Received: by 2002:a05:6a20:7d8a:b0:171:737:dfaf with SMTP id v10-20020a056a207d8a00b001710737dfafmr2781275pzj.5.1700055973982; Wed, 15 Nov 2023 05:46:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700055973; cv=none; d=google.com; s=arc-20160816; b=N6+0qRtiKjJyzZVOK8s/pAkr7QG8uF90DetF2b7vmZKhwPEs6b3kFbyGWOd8NNnlxn hl4PDxwlbBu7DBVvA/drcE3KP3nQeoaL7n4s53agrl3FLWFFf5hBbGLeUwvqCyU4V1ry vIS8+yQNqXsM2Kxo5JW5A+vUyCEt30ukgc6nK1NRVY/1J/Jn0j0E8vdlMwOV7rdb32mX U/65vQB6jgGbR5AC5qGAOwN+XSpl29Qs2nDRFfS0Pli6ARQiZZfbpS9lI//AxREKxl4n On6DNgG/9qWhLb3iyZIW8qrLbgYd8D7YZHlk5EtyES0hkCNpWRIyN5yN/QEyFBmK6EDu b8PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=9ii4mWjBJzds9jQsOl0DO5LOYoG1cGLiVq+JBPiOoeY=; fh=U7wEyxtwz2o5+UdevFSA47vNeG9knhWH0KV//QhD5a0=; b=lTZ9rCwnob7gnnC17Ns8Oo4vPMuqbKjL6V9H9neGV07qr62c+6U60VYBDYEOsOeDbt fcwMDZ4V4kxXrOE47DG3S9GNK2peQHgdJtJVKhQraPQT12vjLosmMSQ7L2wjpkAqwAhm 0pAIyTw+JCmoaTM2RU22AR1eJO2r56OukF9dc1Euzjg4Tqetg1nJYYgX3wPRaIv+/3c7 DtYSwBNg7jc1oyqEqT9YaHmiplQzm6F+GYbok/lQsPTjBWRuKeY5DChN+pT9WQ6ifnSP urKqkneASNEh4ld8ZLCZ4D5YERb++olS559lR1HOg6vfo4d+Xhx/pqS8HK3X9bZ1Gh7j nvfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=ki+P3eP0; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=l03JToOJ; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=AqC4dhf8; 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 Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id j3-20020a056a00174300b006c1222c5eaasi10484422pfc.175.2023.11.15.05.46.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Nov 2023 05:46:13 -0800 (PST) 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=ki+P3eP0; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=l03JToOJ; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=AqC4dhf8; 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 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 1r3GCo-0000Q6-Rs; Wed, 15 Nov 2023 13:45:23 +0000 Received: from [172.30.20.202] (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 1r3GCl-0000Pm-73 for openvpn-devel@lists.sourceforge.net; Wed, 15 Nov 2023 13:45:19 +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=qANJBCi2KAwu94L8jEA+2a3s5hxSmhv8xXO9kLdiu3Q=; b=ki+P3eP0eWtR+O+amzywNAUAf4 rM/XnaCLMC5t88UKTBxFGw+NeQHimD0Ymbq18+IoIYv1z0plLmbqkmw3dx46R2hMZidSwMdOmdEag 7h5jOKac+/rU65Hki0OBrJjdgpZfmCIk8NnU1XwdB337kepleUOl4vl1tXswuWQz8uOc=; 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=qANJBCi2KAwu94L8jEA+2a3s5hxSmhv8xXO9kLdiu3Q=; b=l 03JToOJs7Qj9A97KbSMrW08vGJE1fDHT3XYWjxw5RcYnYHxSCjpb/yiQf8WiOal98/fLxnXM2OV25 V0AjoEF2Dgu9kYXTnd/9xt+BvqSvoSZMMrSxle5btdL5Co2/OedZsW2Jm2HImYNvHSWvJ7jH1Ttm4 wcjlxzrsZdkaQ2b8=; Received: from mail-lf1-f43.google.com ([209.85.167.43]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1r3GCf-0000Nc-7R for openvpn-devel@lists.sourceforge.net; Wed, 15 Nov 2023 13:45:19 +0000 Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5079f6efd64so9036244e87.2 for ; Wed, 15 Nov 2023 05:45:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1700055906; x=1700660706; 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=qANJBCi2KAwu94L8jEA+2a3s5hxSmhv8xXO9kLdiu3Q=; b=AqC4dhf8k76B8F96dqMMhGu+GYNSPyQHtV79DACBvzwdFV1fAOvClIqDWOUZerIX/i 9kJOW96dnGqPiJ0VWZ2Aro+vZS3P5wXzjNcNKDGJMh3P40RepioBfKRQwVYwWDeYTi6d owYBLf8wns/qKqKEN/KHRT9QJpFVSogJOpFV3C+Io52E5QlMGs0O1Ic8csmkeD9S20H3 L0b9fJDALgtiI538Scqc00iQEK5zulMkIppxqjmBHTeP0GVfG4ns6HwazqWHkBt8vDqO JR30piMLjzMgb1rfoLWUgluVHzQ2uf3yDrF6qudRx9chGjTBEijJZvpyX1yDYY6hkv/0 Qb1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700055906; x=1700660706; 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=qANJBCi2KAwu94L8jEA+2a3s5hxSmhv8xXO9kLdiu3Q=; b=WVHaND7BM9bY7CHJLjp6L+1CwP8tXOw3ZTx2eHhzBXvcF+SEFd3nljMkXvm/HqzHdW 44I/BwybdVC1NxTAxgqKBpokpqvkKF743gYJrt7mGGlRSD2auEIDQBBJG49ghiYiWLbu XARI8e4GZ4nIdX1RM4wCvca4wq83h1JlG3jbNY+hqwFDNFZFNNvRuNqYGb5Qkj1Gpado hDUBSJLhBWN8reKGNpFWN6lqoRV3JHaV2BAGgopVOgyDbc9ZfYgd5JyxxCDwIiJuKD62 94f46VNFrhFXhSy1AVQHCzUmCFbr4ZVeVzr5cGGcI40CYyoSF1YrQjVtMCIqsTL0ram+ StJg== X-Gm-Message-State: AOJu0YxE8YswHyX2CC8qYt8awrqRs/Jbxzn6SP1JJ7SaN9uDDLKhEmWp A2K6WD5eB5SjX+uh6pLncGaWww== X-Received: by 2002:ac2:454c:0:b0:507:b935:9f60 with SMTP id j12-20020ac2454c000000b00507b9359f60mr7538762lfm.57.1700055906405; Wed, 15 Nov 2023 05:45:06 -0800 (PST) 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 b11-20020a05600010cb00b0032f9688ea48sm10643962wrx.10.2023.11.15.05.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 05:45:05 -0800 (PST) From: "ordex (Code Review)" X-Google-Original-From: "ordex (Code Review)" X-Gerrit-PatchSet: 1 Date: Wed, 15 Nov 2023 13:45:05 +0000 To: plaisthos , flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: If11e901c26fc5aafdcfd59a214d70c6e6a548f40 X-Gerrit-Change-Number: 430 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: f1cbb631c891a31e97c0fbf7a5d4c1eed7f97b99 References: Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -0.2 (/) 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, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.167.43 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.167.43 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message 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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1r3GCf-0000Nc-7R 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: a@unstable.cc, arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1782637893244399205?= X-GMAIL-MSGID: =?utf-8?q?1782637893244399205?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/430?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: If11e901c26fc5aafdcfd59a214d70c6e6a548f40 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, 58 insertions(+), 13 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/30/430/1 diff --git a/src/openvpn/event.h b/src/openvpn/event.h index 6282873..23a6799 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 62eb14b..9d383af 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); } } @@ -264,7 +264,8 @@ { 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)) @@ -692,21 +693,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 8b490ed..af04dc8 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 6b1c68d..7656bac 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 903f98b..8ee14df 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 bfc1253..39e30b8 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 */