From patchwork Sun Jul 9 23:19:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Fleischman X-Patchwork-Id: 3279 X-Patchwork-Delegate: davids@openvpn.net Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:1496:b0:d7:3b0f:3938 with SMTP id b22csp2600228dyh; Sun, 9 Jul 2023 16:20:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlGLb5FFzWNNFAm+yF5iKKA9orslMCuMfLxXRhG2sSsmfQ+sGXnpX44FHZtYHkpnC96hB0QN X-Received: by 2002:a17:902:cecf:b0:1b6:93e8:3ddb with SMTP id d15-20020a170902cecf00b001b693e83ddbmr10468004plg.6.1688944814037; Sun, 09 Jul 2023 16:20:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688944814; cv=none; d=google.com; s=arc-20160816; b=DfWeANcs/bqtBKMsnBB0VWXZsPQphkDBHZNknHM2e1EUbcVWIBzF+/2tgRedjen6GW SzVyubpMHUkv2wz2kirk1VP7s00cup8ac/zM3MQCZE2xLcltHRzHwtYlhCV2Bi5G1wce gsyH+DGYeFeeDZo4evOKOnnYUUByTi9zRJ9SrzLzsPrVf1Wa5ElcCNNEUzOyQAufalpW 515GfZ8PYeILx/Nx2IJsBk01jl0to62FscBgGn9WtboAY/h/Bdy1mitcieVNLfzqzPxe 0sKA2BQ30r78jWcAPhvdVxRCsoNscEK0nGuCZy82dJj4/uYCfffi81O39fj/zeq+BiHF Yrrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:date:to:from:dkim-signature:dkim-signature :dkim-signature; bh=oMuF5n9lfnaJ/DcWTE+rq3bkaRlhiXMYCH4Ssnldf94=; fh=ot82lPePRBGsqqamW6hLuRGPH/N2GgCXDW6rwwQKQ+A=; b=m2MUX4Bi0WMPqXZ3OJWIOot7fWiGj7CjvPsOxOC1lI5WXr1YxOsh++jSZOxO4tl+yO ZPpLUmYVP2tvtxfZ/8SgkTMBulnXAUpShNcH1cTQHgazmg55ZqjdQj2d9yUFTObMmX/B Z0KE/eOb8ptuYFgSZE0mzIXdwGAq7nM3w958sN5b24oDBSpsfG+9kW9ARodIJ1yETcWP KJ8JMpqblQGAL2kBC36Tz1agEU7OrOp5xWSqBJ4WeN8tzpi19poaXHpZ9k29QZiN6D4n uTvytJg7obNscwwSQo5AxF9shuwumq1Sabng32016WwtBujimG0AXA4PRuqN31tjX2bl opDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=CFQU1tFN; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=bQYiRw9f; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=Bg+oNTQZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id lc16-20020a170902fa9000b001b85ca73574si7225177plb.285.2023.07.09.16.20.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jul 2023 16:20:14 -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=CFQU1tFN; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=bQYiRw9f; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=Bg+oNTQZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qIdgs-00012x-Mg; Sun, 09 Jul 2023 23:19:43 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qIdgq-00012r-2a for openvpn-devel@lists.sourceforge.net; Sun, 09 Jul 2023 23:19:41 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xNvp25Mt39EKZUucfVNSMTRVeBylkkHqrGeXW6wAM0I=; b=CFQU1tFN09yi72TtLDkBMaVQmc gYFSUkNMMewA/3t4gVLuPqmEyUJC6LASBTIofrcKSJfiK2BPttPHKEZignBvLIiGGnwXFQggWDA35 XPVrD3tWbsJuXpxXju1C/2MDr2wA1QiP8c8tdTzYdDJNdH5ssa5SN6tmVOdyZLLp7ioY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=xNvp25Mt39EKZUucfVNSMTRVeBylkkHqrGeXW6wAM0I=; b=b QYiRw9fKwRr7/f0h1zlbeoS6xx/ns82khIFfxplG/ULkGGEmftOZ2bVrhqGa0KVjA2WiotAtGFODr 62mfRcW+hD1DDM77fmi2fzH7XGQOQrRRyCNWADVCISxibjSxEsJKo/rjReiiOocK/wYWqFMNGJCM8 Y0smBOlAxu87KYOg=; Received: from mail-yb1-f171.google.com ([209.85.219.171]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qIdgq-00088U-4b for openvpn-devel@lists.sourceforge.net; Sun, 09 Jul 2023 23:19:39 +0000 Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-bfe6ea01ff5so4822012276.3 for ; Sun, 09 Jul 2023 16:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688944772; x=1691536772; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xNvp25Mt39EKZUucfVNSMTRVeBylkkHqrGeXW6wAM0I=; b=Bg+oNTQZW29oDWOO9PTyFmpct3wT7XrFpVIkGNVVCQXvzJoBL+qDkwguwj6UVt4WcB 1jBpj3dvLPSgguDUgGIE/sgkOtww1f0wiVvVkjLbXUAqrcqOUnt/ByH4kRqHaOo8P2Gl WHu/QfDgaNhE8JYPdUR1Jpj2MkB3LXZ6P/GYr01sR6ef2kRmMXG21u0x1L4gfT7+SdzQ 4HklLPTc1WoSGktabOdZXDnhejeXBRa/X3KpKNCMNW8pw+uiPbvH0QDlNsdUYMYw2/PJ bkDCNbjzrTVR/kFZBFE/jfUsEm2l7MpQRjVW8SoAC91odFVhc8f9U4sjpMVJXFCRP5pg z/lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688944772; x=1691536772; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xNvp25Mt39EKZUucfVNSMTRVeBylkkHqrGeXW6wAM0I=; b=EIvIgBOzDM9OURzbSKnqol/Klx322S3aVKrPOObHkQUcIaq5i/fTYq6oGEIAkHCfSO baHCfa4V4SEZbA52xS2KqvBFJXDc9+n0Wf+Ys8VgVaxp24lH7o3I95XXZpD7nIMKjSTq z2lElk3YHKah9Rm0Im5u1QBw/d9uyU1JIwl8ar0YPCGy2GL6o8iw55/k7L95eBy8oN7M ULOdq2Dp3x5KUBl1OjhJxatBCEviRqlrP0owRZ0Wu2H3EkHuas3yYGO/l6is6LxMVvT8 Hv4qgMulZyZSBv1LHQ9Oeq9NLk7HtIJcd0DlJYkY3FaGUUtlam7XEuffJC7KToH+agFI y+Mw== X-Gm-Message-State: ABy/qLbOJOZVsomoamhAgWqCMRvG62mn8deiXAGYdLJUvY9ysABVCcyU 4W4nvb22Y6GOTNDfu8ZBolFI80ucTnA= X-Received: by 2002:a25:ea4b:0:b0:c7a:5a6c:5ee1 with SMTP id o11-20020a25ea4b000000b00c7a5a6c5ee1mr3079273ybe.62.1688944772143; Sun, 09 Jul 2023 16:19:32 -0700 (PDT) Received: from pattern.lan ([2600:1700:a41a:381f:c30e:cea6:f817:e2c1]) by smtp.gmail.com with ESMTPSA id b8-20020a5b0088000000b00c6135ffd2fcsm2298079ybp.15.2023.07.09.16.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 16:19:31 -0700 (PDT) From: Jeremy Fleischman To: openvpn-devel@lists.sourceforge.net Date: Sun, 9 Jul 2023 16:19:26 -0700 Message-ID: <20230709231929.195048-1-jeremyfleischman@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Score: -0.2 (/) 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: `StatusChangeCallback` requires that LogForward be enabled, which previously only happened in `LogCallback`. Now both of them do it, which requires a bit of bookkeeping. This fixes https://github.com/ [...] Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [jeremyfleischman[at]gmail.com] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.219.171 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.219.171 listed in list.dnswl.org] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1qIdgq-00088U-4b Subject: [Openvpn-devel] [PATCH] Fix StatusChangeCallback so it works without a LogCallback 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?1770986997296112149?= X-GMAIL-MSGID: =?utf-8?q?1770986997296112149?= `StatusChangeCallback` requires that LogForward be enabled, which previously only happened in `LogCallback`. Now both of them do it, which requires a bit of bookkeeping. This fixes https://github.com/OpenVPN/openvpn3-linux/issues/197 Notes: 1. I'm not sure if this would place nicely with a multithreaded program or not. Hopefully that's not something we care to support? 2. To keep the bookkeeping accurate, I opted to explictly remove any preexisting callbacks before registering a new one. This means that when you're clobbering an existing LogCallback (for example), you'll actually end disabling LogForward right before you re-enable it. I don't think this is a big deal, but just wanted to call it out. Signed-off-by: Jeremy Fleischman --- src/python/openvpn3/SessionManager.py | 63 ++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/src/python/openvpn3/SessionManager.py b/src/python/openvpn3/SessionManager.py index 3632790..05126aa 100644 --- a/src/python/openvpn3/SessionManager.py +++ b/src/python/openvpn3/SessionManager.py @@ -114,6 +114,7 @@ def __init__(self, dbuscon, objpath): self.__log_callback = None self.__status_callback = None self.__deleted = False + self.__LogForward_receiver_count = 0 def __del__(self): @@ -285,22 +286,24 @@ def GetFormattedStatistics(self, prefix='Connection statistics:\n', format_str=' # def LogCallback(self, cbfnc): if cbfnc is not None: + # Remove the existing callback if there is one. + if self.__log_callback is not None: + self.LogCallback(None) + self.__log_callback = cbfnc self.__dbuscon.add_signal_receiver(cbfnc, signal_name='Log', dbus_interface='net.openvpn.v3.backends', bus_name='net.openvpn.v3.log', path=self.__session_path) - self.__session_intf.LogForward(True) + self.__add_LogForward_receiver() else: - try: - self.__session_intf.LogForward(False) - except dbus.exceptions.DBusException: - # If this fails, the session is typically already removed - pass - self.__dbuscon.remove_signal_receiver(self.__log_callback, 'Log') - self.__log_callback = None - + # Only remove the callback if there actually *is* a callback + # currently. + if self.__log_callback is not None: + self.__remove_LogForward_receiver() + self.__dbuscon.remove_signal_receiver(self.__log_callback, 'Log') + self.__log_callback = None ## # Subscribes to the StatusChange signals for this session and register @@ -311,16 +314,25 @@ def LogCallback(self, cbfnc): # def StatusChangeCallback(self, cbfnc): if cbfnc is not None: + # Remove the existing callback if there is one. + if self.__status_callback is not None: + self.StatusChangeCallback(None) + self.__status_callback = cbfnc self.__dbuscon.add_signal_receiver(cbfnc, signal_name='StatusChange', dbus_interface='net.openvpn.v3.backends', bus_name='net.openvpn.v3.log', path=self.__session_path) + self.__add_LogForward_receiver() else: - self.__dbuscon.remove_signal_receiver(self.__status_callback, - 'StatusChange') - self.__status_callback = None + # Only remove the callback if there actually *is* a callback + # currently. + if self.__status_callback is not None: + self.__remove_LogForward_receiver() + self.__dbuscon.remove_signal_receiver(self.__status_callback, + 'StatusChange') + self.__status_callback = None @@ -417,6 +429,33 @@ def GetDCO(self): def SetDCO(self, dco): self.__prop_intf.Set('net.openvpn.v3.sessions', 'dco', dco) + ## + # Internal method to increase the count of how many signal receivers need + # LogForward. Turns on LogForward if this is the first receiver. + # + def __add_LogForward_receiver(self): + # This is our first need for LogForward. Turn it on. + if self.__LogForward_receiver_count == 0: + self.__session_intf.LogForward(True) + + self.__LogForward_receiver_count += 1 + + ## + # Internal method track to reduce the count of how many signal receivers + # need LogForward. Turns off LogForward if this was the last receiver. + # + def __remove_LogForward_receiver(self): + assert self.__LogForward_receiver_count > 0 + self.__LogForward_receiver_count -= 1 + + # No receivers are left in need of LogForward. Turn it off. + if self.__LogForward_receiver_count == 0: + try: + self.__session_intf.LogForward(False) + except dbus.exceptions.DBusException: + # If this fails, the session is typically already removed + pass + ##