From patchwork Mon Aug 10 04:37:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1362 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id SKBeMdFbMV/IBgAAIUCqbw for ; Mon, 10 Aug 2020 10:38:09 -0400 Received: from proxy14.mail.ord1d.rsapps.net ([172.30.191.6]) by director8.mail.ord1d.rsapps.net with LMTP id GD8xMdFbMV+UXwAAfY0hYg (envelope-from ) for ; Mon, 10 Aug 2020 10:38:09 -0400 Received: from smtp5.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy14.mail.ord1d.rsapps.net with LMTP id OLTsMNFbMV+WIwAAtEH5vw ; Mon, 10 Aug 2020 10:38:09 -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: smtp5.gate.ord1c.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: 1b7188f2-db17-11ea-8980-a4badb0b200d-1-1 Received: from [216.105.38.7] ([216.105.38.7:59054] helo=lists.sourceforge.net) by smtp5.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 5B/37-09162-0DB513F5; Mon, 10 Aug 2020 10:38:08 -0400 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 1k58vf-0007Hn-KF; Mon, 10 Aug 2020 14:37:35 +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 1k58vS-0007G4-G6 for openvpn-devel@lists.sourceforge.net; Mon, 10 Aug 2020 14:37:22 +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=2Ob1qihhX3rzSidDFZW0aNS+fAzIouO8fo1rMRnDbr0=; b=KsZjMJHmO4E95x9islJccf/ZxF BjbybPlv/7Y1l0p6qNMYWqU/T/HYYI95Ut6Lt07AL8Y5wpU9ErXnPHuFicLD3Z+dt8ddsJiXXR0RM 2gcBOJqBoH1+VcsgauxcqvMD9ejVBzkr6ln1Acm/fHQr9+4Ra80RLMPgiFlH0sNs1kGU=; 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=2Ob1qihhX3rzSidDFZW0aNS+fAzIouO8fo1rMRnDbr0=; b=ep7eJLYHpDSnRhg92TCeFkmNJW ebuUQ+r+UVZXPvhpxSv54ddCk6MDuOqFVKJMtf/+CSzJXk9Rkaxq2N2jQ+t1NoKMqSkqwgO9rh2ZL Ofmu6y+AFr91I5QN19x6wYnwG3gcGmZA6gfvwMoFaJTcPcJBExVTloTQcKV3fgf+PR/8=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1k58vR-002taX-Cd for openvpn-devel@lists.sourceforge.net; Mon, 10 Aug 2020 14:37:22 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1k58vF-000OSa-7k for openvpn-devel@lists.sourceforge.net; Mon, 10 Aug 2020 16:37:09 +0200 Received: (nullmailer pid 5928 invoked by uid 10006); Mon, 10 Aug 2020 14:37:09 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Mon, 10 Aug 2020 16:37:06 +0200 Message-Id: <20200810143707.5834-17-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200810143707.5834-1-arne@rfc2549.org> References: <20200810143707.5834-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 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Headers-End: 1k58vR-002taX-Cd Subject: [Openvpn-devel] [PATCH 16/17] Move parsing IV_PROTO to separate function 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 Signed-off-by: Arne Schwabe Acked-by: Gert Doering --- src/openvpn/multi.c | 49 +++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index b7b7e32f..13738180 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -1771,6 +1771,28 @@ multi_client_connect_setenv(struct multi_context *m, gc_free(&gc); } +/** + * Extracts the IV_PROTO variable and returns its value or 0 + * if it cannot be extracted. + * + */ +static unsigned int +extract_iv_proto(const char *peer_info) +{ + + const char *optstr = peer_info ? strstr(peer_info, "IV_PROTO=") : NULL; + if (optstr) + { + int proto = 0; + int r = sscanf(optstr, "IV_PROTO=%d", &proto); + if (r == 1 && proto > 0) + { + return proto; + } + } + return 0; +} + /** * Calculates the options that depend on the client capabilities * based on local options and available peer info @@ -1780,30 +1802,19 @@ multi_client_connect_setenv(struct multi_context *m, static bool multi_client_set_protocol_options(struct context *c) { - - const char *optstr = NULL; struct tls_multi *tls_multi = c->c2.tls_multi; const char *const peer_info = tls_multi->peer_info; struct options *o = &c->options; - /* Send peer-id if client supports it */ - optstr = peer_info ? strstr(peer_info, "IV_PROTO=") : NULL; - if (optstr) - { - int proto = 0; - int r = sscanf(optstr, "IV_PROTO=%d", &proto); - if (r == 1) - { - if (proto & IV_PROTO_DATA_V2) - { - tls_multi->use_peer_id = true; - } - if (proto & IV_PROTO_REQUEST_PUSH) - { - c->c2.push_request_received = true; - } - } + unsigned int proto = extract_iv_proto(peer_info); + if (proto & IV_PROTO_DATA_V2) + { + tls_multi->use_peer_id = true; + } + if (proto & IV_PROTO_REQUEST_PUSH) + { + c->c2.push_request_received = true; } /* Select cipher if client supports Negotiable Crypto Parameters */