From patchwork Tue Nov 20 23:10:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 618 X-Patchwork-Delegate: a@unstable.cc Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id YFI8Fn1Q9VuJCwAAIUCqbw for ; Wed, 21 Nov 2018 07:33:01 -0500 Received: from proxy1.mail.ord1d.rsapps.net ([172.30.191.6]) by director11.mail.ord1d.rsapps.net with LMTP id UNv1FX1Q9VtGMQAAvGGmqA ; Wed, 21 Nov 2018 07:33:01 -0500 Received: from smtp2.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy1.mail.ord1d.rsapps.net with LMTP id qIK1FX1Q9VtHRQAAasrz9Q ; Wed, 21 Nov 2018 07:33:01 -0500 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: smtp2.gate.ord1d.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=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: 9505f702-ed89-11e8-a269-5254004a0287-1-1 Received: from [216.105.38.7] ([216.105.38.7:55155] helo=lists.sourceforge.net) by smtp2.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id D0/56-06426-C7055FB5; Wed, 21 Nov 2018 07:33:00 -0500 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.90_1) (envelope-from ) id 1gPRfz-0004Wm-5x; Wed, 21 Nov 2018 12:32:15 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1gPRfy-0004Wa-8k for openvpn-devel@lists.sourceforge.NET; Wed, 21 Nov 2018 12:32:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:To: From:Sender:Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=2Aw8tW3Nd86R5FSH0uRrQXy3F1Xe1sK12+2mIJogAOg=; b=OlIrNOPRUQCm9ONBYyOuX2iPFi 1Qi8jnBBd7OskT7LVRymK4Y7IFpT7EPIku7e9M0GpNugpDnZNtg1hc2R3ESCQQcTWF25u4C+wBxBI 9yZ0aB3thTYEXHfXMPNKCJYmHv5ZtHuOPDZczlI1X5zNzbwG7wtnAm0nnAjG0yVOfzX4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc :MIME-Version:Content-Type:Content-Transfer-Encoding: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=2Aw8tW3Nd86R5FSH0uRrQXy3F1Xe1sK12+2mIJogAOg=; b=XjbGjFBWf7BloouYRqs1Qco61M gGmhMzDLAKq6mJIKUYsYLfzxq6R0C4Ymn9ZtP36236818+9y/dKdVGsA8ATVHMkubM7zZVA3fbvBV mmlfbFhMzHMWfRWMGdgEoY37dL+1ySZyDGdfvNl1wn8UJc2HG5vHsoVAgDibGysHKrzQ=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1gPRfw-008sMu-NY for openvpn-devel@lists.sourceforge.NET; Wed, 21 Nov 2018 12:32:14 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.91 (FreeBSD)) (envelope-from ) id 1gPPSe-000GWS-Gw for openvpn-devel@lists.sourceforge.net; Wed, 21 Nov 2018 11:10:20 +0100 Received: (nullmailer pid 1864 invoked by uid 10006); Wed, 21 Nov 2018 10:10:20 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Wed, 21 Nov 2018 11:10:12 +0100 Message-Id: <20181121101019.1801-7-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181121101019.1801-1-arne@rfc2549.org> References: <20181121101019.1801-1-arne@rfc2549.org> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different X-Headers-End: 1gPRfw-008sMu-NY Subject: [Openvpn-devel] [PATCH v4 06/13] client-connect: Change connection_established_flag from bool to enum 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: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox This prepares from the yes/no logic to a tristate logic with defered being the third state. This deviates from Fabian's original patch that that used a pointer being NULL or non NULL as implicit third state. Signed-off-by: Arne Schwabe --- src/openvpn/multi.c | 14 ++++++++------ src/openvpn/multi.h | 14 ++++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 18a1313e..1093d8aa 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -574,7 +574,8 @@ static void multi_client_disconnect_script(struct multi_context *m, struct multi_instance *mi) { - if ((mi->context.c2.context_auth == CAS_SUCCEEDED && mi->connection_established_flag) + if ((mi->context.c2.context_auth == CAS_SUCCEEDED + && mi->client_connect_status == CC_STATUS_ESTABLISHED) || mi->context.c2.context_auth == CAS_PARTIAL) { multi_client_disconnect_setenv(m, mi); @@ -2051,7 +2052,7 @@ multi_client_connect_early_setup(struct multi_context *m, * Try to source a dynamic config file from the * --client-config-dir directory. */ -enum client_connect_return +static enum client_connect_return multi_client_connect_source_ccd(struct multi_context *m, struct multi_instance *mi, unsigned int *option_types_found) @@ -2196,7 +2197,7 @@ multi_connection_established(struct multi_context *m, struct multi_instance *mi) } /* set flag so we don't get called again */ - mi->connection_established_flag = true; + mi->client_connect_status = CC_STATUS_ESTABLISHED; /* increment number of current authenticated clients */ ++m->n_clients; @@ -2479,7 +2480,8 @@ multi_process_post(struct multi_context *m, struct multi_instance *mi, const uns { /* connection is "established" when SSL/TLS key negotiation succeeds * and (if specified) auth user/pass succeeds */ - if (!mi->connection_established_flag && CONNECTION_ESTABLISHED(&mi->context)) + if (mi->client_connect_status != CC_STATUS_ESTABLISHED + && CONNECTION_ESTABLISHED(&mi->context)) { multi_connection_established(m, mi); } @@ -3385,7 +3387,7 @@ management_client_auth(void *arg, { if (auth) { - if (!mi->connection_established_flag) + if (mi->client_connect_status == CC_STATUS_NOT_ESTABLISHED) { set_cc_config(mi, cc_config); cc_config_owned = false; @@ -3397,7 +3399,7 @@ management_client_auth(void *arg, { msg(D_MULTI_LOW, "MULTI: connection rejected: %s, CLI:%s", reason, np(client_reason)); } - if (mi->connection_established_flag) + if (mi->client_connect_status == CC_STATUS_ESTABLISHED) { send_auth_failed(&mi->context, client_reason); /* mid-session reauth failed */ multi_schedule_context_wakeup(m, mi); diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 0a1ab2c3..bd4882ea 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -63,6 +63,12 @@ struct deferred_signal_schedule_entry struct timeval wakeup; }; +enum client_connect_status +{ + CC_STATUS_NOT_ESTABLISHED, + CC_STATUS_ESTABLISHED +}; + /** * Server-mode state structure for one single VPN tunnel. * @@ -105,7 +111,7 @@ struct multi_instance { bool did_cid_hash; struct buffer_list *cc_config; #endif - bool connection_established_flag; + enum client_connect_status client_connect_status; bool did_iroutes; int n_clients_delta; /* added to multi_context.n_clients when instance is closed */ @@ -196,9 +202,9 @@ struct multi_context { */ enum client_connect_return { - CC_RET_FAILED, - CC_RET_SUCCEEDED, - CC_RET_SKIPPED + CC_RET_FAILED, + CC_RET_SUCCEEDED, + CC_RET_SKIPPED }; /*