From patchwork Tue Mar 22 03:47:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Heading X-Patchwork-Id: 5377 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KMyCd3KGrz3xlr for ; Tue, 22 Mar 2022 03:49:17 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KMyBT383Rz1Wd; Tue, 22 Mar 2022 03:48:17 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KMyBT226tz2yrp; Tue, 22 Mar 2022 03:48:17 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KMyBR1DZ6z2x9p for ; Tue, 22 Mar 2022 03:48:15 +0000 (UTC) Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4KMyBQ1Sd9z1TN for ; Tue, 22 Mar 2022 03:48:14 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 9D855320112B; Mon, 21 Mar 2022 23:48:12 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 21 Mar 2022 23:48:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ajrh.net; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=mesmtp; bh=UPoEvzcPSzaI+zQQGyyNMvist9mVwWrGH2CvoTWH6rE=; b=UZ bBTroJPWzRQWzZpz0wS581bm9Gd8h8EiLzIVG95qFJ5ddn65yozGaBfjN3EtPpZq +alio6IqMHd9wbe/t2rRjhcE4jVZDf4Aj7ZMPE3MVnVUaHTglXmjmANPsOqdt7eB wBsZ7xhC1BnpOy0onfkoiOSBFJd/wyNYKoUlwXt3c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=UPoEvzcPSzaI+zQQGyyNMvist9mVw WrGH2CvoTWH6rE=; b=bnKMbhybjJT51EEhY0XCXPOMAwnv4ZIg37+IO5xFOYziN ID33/1m4p71QVqwtKxf1ioUi21bswGZaiyt+jXBFC8/myRakwiIKolHnS6DO3Bi+ dOyyDZB+3LQ4gLC6UBo00eoT1TP7LHHAdZO+GD2TS27NGQ/gzzx3CdPOaazrWxyT 8/WsX/TkUGavafhbnZcxlbUdzd6njq23UWc/uW9pHoPGwohclirlpbZ7RTmP/nXR gY00h2zHPZovasOaa8Xez8oUi/YXIv2+reMfDRkStqwfVN3ItW5bBHifjo9tXOBc 5ZSLW+VymIwKeuQed/0QhaEGB/aQZlTEFd1N9ScWw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeggedgieduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgggfestdekredtre dttdenucfhrhhomheptehnthhhohhnhicujfgvrgguihhnghcuoegrjhhrhhesrghjrhhh rdhnvghtqeenucggtffrrghtthgvrhhnpeeghedvgeejueffvdevveejfeefgeefieduue fgleegvdeufefhhfejvdfgtdehieenucffohhmrghinheptghonhhsthgrnhhtshdrihhn necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghjrh hhsegrjhhrhhdrnhgvth X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Mar 2022 23:48:11 -0400 (EDT) From: Anthony Heading To: development@lists.ipfire.org Subject: [PATCH 1/3] unbound-dhcp-leases-bridge : fix bug 12694 - DHCP hosts not reliably propagated to DNS Date: Mon, 21 Mar 2022 23:47:54 -0400 Message-Id: <20220322034756.36327-1-ajrh@ajrh.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Status: RO Lines: 90 ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1647920894; a=rsa-sha256; cv=none; b=mUAEO94OENMi4Ab2OQZQwn3TT4quwGuW8Nfs/uy50jG5nDL1ZfCJb7NBKSxPltb2tIOPU0 MFPKcvNjOIWVl1MWD8RDLq8L0CNQYATCT4jBVADNxgW5IZLr3WmUEBV1mmyCTfALgxGqJX s1AWLfxaq1n/WdTafCIYmlckmHfyaaWAQg2/89ObvRKIlBBKmFcW+G0v8DM5MZZ6VSf1rq zFCaC0ER92/v3Ytw2JQpaOZpSqCwY48HvDTIAVLlRb1kkE+ANjaJUUy+Jr136h2piuD8k3 DIQU2ugYI1IlRm30oZxNeAvmscXF7gdyi73CUXwDrXun+suWaLfiRkfZcrpmHQ== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=ajrh.net header.s=mesmtp header.b="UZ bBTro"; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=bnKMbhyb; dmarc=none; spf=pass (mail01.ipfire.org: domain of ajrh@ajrh.net designates 64.147.123.25 as permitted sender) smtp.mailfrom=ajrh@ajrh.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1647920894; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:dkim-signature; bh=UPoEvzcPSzaI+zQQGyyNMvist9mVwWrGH2CvoTWH6rE=; b=FNnvl4HnOuYJeTmnDMT4siod3OIL2cU5CfJQBZsElnweYpicSVFULF/SxD7hTOvLbq5SQ6 weuLbD/rPlI/vn0re4DvwvMKFDOfPp9iWjO/h5ObQwTAnRC1vwzK8aImGLKRdDwKm1qz7S 5FzKrf4f8S4jeZCB4taZm5I7VsGipgXPYiqfZZCG1onltHs/7V4e0C0LulUQ5iAgb6u+Mz wcoaPaMeblmTCaHAgQkqK3LqsimbYTvSayDjUeL9tGitLblN45VlH+j15oK/XiNCqRrOUn Zw5RQjaw6E9o9Goa4S1MPm1AqC4/4cm3y1hOFJ9p483OxkcQ1JqhJwLHEw7m+g== Authentication-Results: mail01.ipfire.org; dkim=pass header.d=ajrh.net header.s=mesmtp header.b="UZ bBTro"; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=bnKMbhyb; dmarc=none; spf=pass (mail01.ipfire.org: domain of ajrh@ajrh.net designates 64.147.123.25 as permitted sender) smtp.mailfrom=ajrh@ajrh.net X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-4.12 / 11.00]; BAYES_HAM(-3.00)[99.98%]; MID_CONTAINS_FROM(1.00)[]; DWL_DNSWL_LOW(-1.00)[messagingengine.com:dkim]; NEURAL_HAM(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_SPF_ALLOW(-0.20)[+ip4:64.147.123.25:c]; R_DKIM_ALLOW(-0.20)[ajrh.net:s=mesmtp,messagingengine.com:s=fm3]; RCVD_IN_DNSWL_LOW(-0.10)[64.147.123.25:from]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; IP_REPUTATION_HAM(-0.01)[asn: 29838(0.00), country: US(-0.01), ip: 64.147.123.25(0.00)]; FROM_HAS_DN(0.00)[]; DMARC_NA(0.00)[ajrh.net]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; TO_DN_SOME(0.00)[]; ASN(0.00)[asn:29838, ipnet:64.147.123.0/24, country:US]; RWL_MAILSPIKE_EXCELLENT(0.00)[64.147.123.25:from]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[ajrh.net:+,messagingengine.com:+]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 4KMyBQ1Sd9z1TN X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Switch from inotify watching individual files to monitoring the containing directories, as because dhcpd renames its leases file into a backup, monitoring the single inode does not work well. Additionally, python appears to have a bug with replacing expired inotify watches on single files. --- unbound-dhcp-leases-bridge | 47 +++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git unbound-dhcp-leases-bridge unbound-dhcp-leases-bridge index a2df5f1..6e22066 100644 --- unbound-dhcp-leases-bridge +++ unbound-dhcp-leases-bridge @@ -72,6 +72,15 @@ class UnboundDHCPLeasesBridge(object): self.fix_leases_file = fix_leases_file self.hosts_file = hosts_file + # base mask for a completed file change + mask = inotify.constants.IN_CLOSE_WRITE | inotify.constants.IN_MOVED_TO + # IN_MODIFY since dhcpd appends lease updates to an open file + self.watches = { + self.leases_file: mask | inotify.constants.IN_MODIFY, + self.fix_leases_file: mask, + self.hosts_file: mask + } + self.unbound = UnboundConfigWriter(unbound_leases_file) self.running = False @@ -80,36 +89,42 @@ class UnboundDHCPLeasesBridge(object): self.running = True # Initial setup - self.hosts = self.read_static_hosts() - self.update_dhcp_leases() + update_hosts = True + update_leases = True + + i = inotify.adapters.Inotify() - i = inotify.adapters.Inotify([ - self.leases_file, - self.fix_leases_file, - self.hosts_file, - ]) + for f in self.watches: + i.add_watch(os.path.dirname(f), self.watches[f]) for event in i.event_gen(): # End if we are requested to terminate if not self.running: break + # Make pending updates once inotify queue is empty if event is None: + if update_hosts: + self.hosts = self.read_static_hosts() + update_hosts = False + if update_leases: + self.update_dhcp_leases() + update_leases = False continue header, type_names, watch_path, filename = event - # Update leases after leases file has been modified - if "IN_MODIFY" in type_names: - # Reload hosts - if watch_path == self.hosts_file: - self.hosts = self.read_static_hosts() + file = os.path.join(watch_path, filename) + + if not file in self.watches: + continue + + log.debug("Inotify %s: %s", file, " ".join(type_names)) - self.update_dhcp_leases() + update_leases = True - # If the file is deleted, we re-add the watcher - if "IN_IGNORED" in type_names: - i.add_watch(watch_path) + if file == self.hosts_file: + update_hosts = True log.info("Unbound DHCP Leases Bridge terminated") From patchwork Tue Mar 22 03:47:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Heading X-Patchwork-Id: 5378 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KMyCy2tVHz3xlr for ; Tue, 22 Mar 2022 03:49:34 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KMyBT5GC5z5R7; Tue, 22 Mar 2022 03:48:17 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KMyBT2fPFz2ysd; Tue, 22 Mar 2022 03:48:17 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KMyBR4Dwtz2x9p for ; Tue, 22 Mar 2022 03:48:15 +0000 (UTC) Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4KMyBR2Vk3z1TN for ; Tue, 22 Mar 2022 03:48:15 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id C13D13200F81; Mon, 21 Mar 2022 23:48:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 21 Mar 2022 23:48:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ajrh.net; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=mesmtp; bh=BUOKFysE9wR37aLBoPADIYhVVTJ HxNWXc2qEs3HQi3Y=; b=iASI/KQILTzdl3+350LKsjABtpZsZCqWRpEcG053qfd YqYpQKNf1lfmyMWgyn2VY0SCnU6zMqP8ZggpWKYp8kQ7pUCPjhdBqkb67V+l4EFq b4ZkxK6lbEtbxOP7DQ60+Q+ErxNxTW1PPHrtgeKDTChfMhg7Nt8Qpsg5Kg8mvV3c = DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=BUOKFy sE9wR37aLBoPADIYhVVTJHxNWXc2qEs3HQi3Y=; b=W0CfZAaxCLmK1Is5fn6pMf GwcNaHwtdlHNJz9u1C8R+abXqR1Q3vjkR+BrvTsy9c35c3LhqLEWGdSoVbhOSH38 hkRF2g8Bqv9P4Gr98CkFfmv05rXYmsHjjXxDinWszK8qZhvhlb4lqBh1qYK3Cqz+ fdVUwQ7PWWNF2YQPcEWhdoosNnoOIMAsJoV6va9UJ54Hnr5axJysDK1nX8lPBUYn U+hiH2ctQsfsRi9ouiiJtaN8lJyFCD/p70ZBNxSmUm1Itcj/JvBejr18cjkgoXGH 4/rQUuWNfpo43pNaF8EYX5+iVYW1L+VsUDO//GNuBoU0+vQ15S1aYAzNzdtEB3KA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeggedgiedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomheptehnthhhohhnhicujfgvrgguihhnghcuoegrjhhrhhesrghj rhhhrdhnvghtqeenucggtffrrghtthgvrhhnpefhhedvuddtgffhffduheelleehheegge duuefftdelkeevgffhuefggfduhefgteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpegrjhhrhhesrghjrhhhrdhnvght X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Mar 2022 23:48:13 -0400 (EDT) From: Anthony Heading To: development@lists.ipfire.org Subject: [PATCH 2/3] unbound-dhcp-leases-bridge : read settings less enthusiastically Date: Mon, 21 Mar 2022 23:47:55 -0400 Message-Id: <20220322034756.36327-2-ajrh@ajrh.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220322034756.36327-1-ajrh@ajrh.net> References: <20220322034756.36327-1-ajrh@ajrh.net> MIME-Version: 1.0 ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1647920895; a=rsa-sha256; cv=none; b=q/8QIXubuq0vFH+3C4BJ6r7EGCCiYCqcLubs3W1QyaBz42wpicOzrfkRA/1GFH0FNx1XbG SqkKyBXeXALkfa8kdcQunYxynzW4PJ7oC3t/ykzP63+fxZQF/ALIq40g4CtWZ5sqGiIMfP iJsjYpDqwOXhVm+fh78ZVsNG7bYHtI3YllvCGoUBF214DWZp3BCpVGhxUmuUcQB4ij7MLY C0dma0DJ5FLC8i5L0j0bm4QW6slTgTtiBmDavVoor6hHSGHCj6mxj/wZWW8RnMjjHi0Ji7 2M42IOpjslaSiz2mrdyTI981dtmp0UZBg2fdH6GN7UiLWFnwwnXtqluVVRfI1Q== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=ajrh.net header.s=mesmtp header.b="iASI/KQI"; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=W0CfZAax; dmarc=none; spf=pass (mail01.ipfire.org: domain of ajrh@ajrh.net designates 64.147.123.25 as permitted sender) smtp.mailfrom=ajrh@ajrh.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1647920895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BUOKFysE9wR37aLBoPADIYhVVTJHxNWXc2qEs3HQi3Y=; b=aWJXd3J0nyMW+V7ThCZ/rs1i6y30HXyBxiCo3vSPwKj0Iy13wCVbr617LWLLxBdBfymZVg L6pR+5S03u9qH1MLilcDjQNP0iCKfV8Ml89YXrF0aMVF8DPBHMewc7hxW7u/tFoFDwcsCE zOs6Xb+1b0uk1rA1tILkE/AveehLf1jSGv5NnAMs9oes/Rd3GFiEwibzt0cwEqO3ZCl+0q Ws4tqO/0YboeEPu6pFxIOosYGz+V03RE6SOmlk+HHZMVCaZh5oM1K0WbXVe/61EVkWLa2L 28TVmdesMJM+RjqYEon82UJJtk6XxosY0JpU2kcn0KuihryXy3lQeeEkukhz5g== Authentication-Results: mail01.ipfire.org; dkim=pass header.d=ajrh.net header.s=mesmtp header.b="iASI/KQI"; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=W0CfZAax; dmarc=none; spf=pass (mail01.ipfire.org: domain of ajrh@ajrh.net designates 64.147.123.25 as permitted sender) smtp.mailfrom=ajrh@ajrh.net X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-4.11 / 11.00]; BAYES_HAM(-3.00)[99.98%]; MID_CONTAINS_FROM(1.00)[]; DWL_DNSWL_LOW(-1.00)[messagingengine.com:dkim]; NEURAL_HAM(-1.00)[-0.999]; R_MISSING_CHARSET(0.50)[]; R_SPF_ALLOW(-0.20)[+ip4:64.147.123.25:c]; R_DKIM_ALLOW(-0.20)[ajrh.net:s=mesmtp,messagingengine.com:s=fm3]; RCVD_IN_DNSWL_LOW(-0.10)[64.147.123.25:from]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; IP_REPUTATION_HAM(-0.01)[asn: 29838(0.00), country: US(-0.01), ip: 64.147.123.25(0.00)]; FROM_HAS_DN(0.00)[]; DMARC_NA(0.00)[ajrh.net]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; TO_DN_SOME(0.00)[]; ASN(0.00)[asn:29838, ipnet:64.147.123.0/24, country:US]; RWL_MAILSPIKE_EXCELLENT(0.00)[64.147.123.25:from]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[ajrh.net:+,messagingengine.com:+]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 4KMyBR2Vk3z1TN X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" The script is rereading the ethernet and dhcp settings files for every lease in every update. Since dhcpd does not have a reload mechanism and is just restarted for settings changes, and so this bridge is restarted too, it seems fine just to read these at startup. --- unbound-dhcp-leases-bridge | 69 ++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 33 deletions(-) diff --git unbound-dhcp-leases-bridge unbound-dhcp-leases-bridge index 6e22066..814cf0c 100644 --- unbound-dhcp-leases-bridge +++ unbound-dhcp-leases-bridge @@ -329,6 +329,42 @@ class FixLeases(object): return leases +def read_settings(filename): + settings = {} + + with open(filename) as f: + for line in f.readlines(): + # Remove line-breaks + line = line.rstrip() + + k, v = line.split("=", 1) + settings[k] = v + + return settings + +def load_subnets(): + # Load ethernet settings + ethernet_settings = read_settings("/var/ipfire/ethernet/settings") + + # Load DHCP settings + dhcp_settings = read_settings("/var/ipfire/dhcp/settings") + + subnets = {} + for zone in ("GREEN", "BLUE"): + if not dhcp_settings.get("ENABLE_%s" % zone) == "on": + continue + + netaddr = ethernet_settings.get("%s_NETADDRESS" % zone) + submask = ethernet_settings.get("%s_NETMASK" % zone) + + subnet = ipaddress.ip_network("%s/%s" % (netaddr, submask)) + domain = dhcp_settings.get("DOMAIN_NAME_%s" % zone) + + subnets[subnet] = domain + + return subnets + +subnets = load_subnets() class Lease(object): def __init__(self, ipaddr, properties): @@ -396,25 +432,6 @@ class Lease(object): @property def domain(self): - # Load ethernet settings - ethernet_settings = self.read_settings("/var/ipfire/ethernet/settings") - - # Load DHCP settings - dhcp_settings = self.read_settings("/var/ipfire/dhcp/settings") - - subnets = {} - for zone in ("GREEN", "BLUE"): - if not dhcp_settings.get("ENABLE_%s" % zone) == "on": - continue - - netaddr = ethernet_settings.get("%s_NETADDRESS" % zone) - submask = ethernet_settings.get("%s_NETMASK" % zone) - - subnet = ipaddress.ip_network("%s/%s" % (netaddr, submask)) - domain = dhcp_settings.get("DOMAIN_NAME_%s" % zone) - - subnets[subnet] = domain - address = ipaddress.ip_address(self.ipaddr) for subnet in subnets: @@ -424,20 +441,6 @@ class Lease(object): # Fall back to localdomain if no match could be found return "localdomain" - @staticmethod - def read_settings(filename): - settings = {} - - with open(filename) as f: - for line in f.readlines(): - # Remove line-breaks - line = line.rstrip() - - k, v = line.split("=", 1) - settings[k] = v - - return settings - @property def fqdn(self): if self.hostname: From patchwork Tue Mar 22 03:47:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Heading X-Patchwork-Id: 5379 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KMyCz41JGz3xqb for ; Tue, 22 Mar 2022 03:49:35 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KMyCV5r6lz5Vh; Tue, 22 Mar 2022 03:49:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KMyBW3L3Sz2yTV; Tue, 22 Mar 2022 03:48:19 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KMyBS4xqBz2yTV for ; Tue, 22 Mar 2022 03:48:16 +0000 (UTC) Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4KMyBS3FMrz1TN for ; Tue, 22 Mar 2022 03:48:16 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id DDC1C3200973; Mon, 21 Mar 2022 23:48:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 21 Mar 2022 23:48:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ajrh.net; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=mesmtp; bh=CjdEPJ6Q9ykHcaJ8/n4aBZ2yhhe 7ZCOs37Gbdx8iHxY=; b=jF4inFk2mUvBwL5VugK976myBuWUJvz7YSbpI5x5jL+ DbVvxzks4ftow1dT4SqiLVC55c16EOdO/219wMFDWrRF2aTIEi4tahmGi3rxznLT +V9yOIKgfUw7bFTxqcVyg2vYTS1GJ82dw9htrGL1H/7mTrX3ztuwIPAFK9Ds7HEQ = DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=CjdEPJ 6Q9ykHcaJ8/n4aBZ2yhhe7ZCOs37Gbdx8iHxY=; b=bKGPQrgJAQ563wTQRO7KB1 yK13LypoMKO/B+Ts/ZJMQzzKhwmvd5llxhtZZorLnr90zLdgnD6aGD4hA8UfIfH7 Lt+XCdqrC3O1aBzPO0aRrUbSUvs3ye7DSLEe/XCSIVlo9inlHFq/yATCCN/0wphK dY32xeAg12EomXtLhOvGCmLywQp1Ln+iiJX7FY5Xnx2V8pNBQ8NbeD9oUyRzME8K pVoJyBdP7eOFZPVG37ikJA1lpXKfw6/vy8a42wEDjcJsFtUVBAU0Uk55Rpf2Y0D+ 1Wdxormgt7YzGKe1MupVifIWJOJRNbjtNuXhL1mCm1N2ozvBDVaP5XeChvPxrXRQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeggedgieduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomheptehnthhhohhnhicujfgvrgguihhnghcuoegrjhhrhhesrghj rhhhrdhnvghtqeenucggtffrrghtthgvrhhnpeehgfdvueetheelueevfefhueejkeeuvd ehudffveegfffhvdefudfftdehheefgeenucffohhmrghinhepshhplhhithdrphgrrhht shenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrjh hrhhesrghjrhhhrdhnvght X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Mar 2022 23:48:14 -0400 (EDT) From: Anthony Heading To: development@lists.ipfire.org Subject: [PATCH 3/3] unbound-dhcp-leases-bridge : minor logging improvements Date: Mon, 21 Mar 2022 23:47:56 -0400 Message-Id: <20220322034756.36327-3-ajrh@ajrh.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220322034756.36327-1-ajrh@ajrh.net> References: <20220322034756.36327-1-ajrh@ajrh.net> MIME-Version: 1.0 ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1647920896; a=rsa-sha256; cv=none; b=UY/V+9SbnLuWYKL9k25FSq9nLV0w2nC5kCtz7plvyJy5x2mgV1HbbwuQCcekx0TX8KpZzI KUsutnMBZmVxI1n31PatQuN1BiK1dtLOxUyBwr/a+UXslyozDO0xLNiOeEWbxOy7f/TCP7 KhX5XfLuYV2IZko+19Y7cf4lfrsjQDZ266xQTfm1YcTDjfqvvL5G9qhORK5Xn0VvUUt9Ca PAIQ3RoOeYC2C3H7kKAQWMOtzDbiuKsDCGaR4NLr9lmU9CrA+5GN+BVc76V2n3CucIOZry eLEP+zHJfA8lzWQMmtiKB+IPGxZyxWOl3fboY8hBU9nRTcuCwWfYHYHi/jB9TQ== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=ajrh.net header.s=mesmtp header.b=jF4inFk2; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=bKGPQrgJ; dmarc=none; spf=pass (mail01.ipfire.org: domain of ajrh@ajrh.net designates 64.147.123.25 as permitted sender) smtp.mailfrom=ajrh@ajrh.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1647920896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CjdEPJ6Q9ykHcaJ8/n4aBZ2yhhe7ZCOs37Gbdx8iHxY=; b=sTk7QaXuiEhYD1IpPWnqFpnVPMyinuhqFKNsQf6mI57anQ2rbp+6AyHcX1ZeFuYHk78n0T Yu111t785qIyYhVWAvom8y6ekLXuuF/ftY+OilpypFBe31zATLoh9OE6fKgX40Lr3IJCf3 RJxBam7RzamfV5geMscJ4Gp5E6x206V7HSJe5gVV2gmpW15GQuFZwU2cH7KXM7SK1p+x1B dmgBQphvEXTROEFn/ogRUA5/k0pmZdXxJPQ0/lP4FLRy+pVwRKihaflJdowzlbmK/+dyTe nPusb46pyqMezGFNvTwQ0IUJQ3i405hwqEG6DE6wXBpPxY8u8X72mfAWzDZBbA== Authentication-Results: mail01.ipfire.org; dkim=pass header.d=ajrh.net header.s=mesmtp header.b=jF4inFk2; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=bKGPQrgJ; dmarc=none; spf=pass (mail01.ipfire.org: domain of ajrh@ajrh.net designates 64.147.123.25 as permitted sender) smtp.mailfrom=ajrh@ajrh.net X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-4.12 / 11.00]; BAYES_HAM(-3.00)[99.98%]; MID_CONTAINS_FROM(1.00)[]; DWL_DNSWL_LOW(-1.00)[messagingengine.com:dkim]; NEURAL_HAM(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_SPF_ALLOW(-0.20)[+ip4:64.147.123.25:c]; R_DKIM_ALLOW(-0.20)[ajrh.net:s=mesmtp,messagingengine.com:s=fm3]; RCVD_IN_DNSWL_LOW(-0.10)[64.147.123.25:from]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; IP_REPUTATION_HAM(-0.01)[asn: 29838(0.00), country: US(-0.01), ip: 64.147.123.25(0.00)]; FROM_HAS_DN(0.00)[]; DMARC_NA(0.00)[ajrh.net]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; TO_DN_SOME(0.00)[]; ASN(0.00)[asn:29838, ipnet:64.147.123.0/24, country:US]; RWL_MAILSPIKE_EXCELLENT(0.00)[64.147.123.25:from]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[ajrh.net:+,messagingengine.com:+]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 4KMyBS3FMrz1TN X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Minor tweaks to logging which were helpful while debugging, including logging to stderr when running in foreground. --- unbound-dhcp-leases-bridge | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git unbound-dhcp-leases-bridge unbound-dhcp-leases-bridge index 814cf0c..17a00f6 100644 --- unbound-dhcp-leases-bridge +++ unbound-dhcp-leases-bridge @@ -26,6 +26,7 @@ import ipaddress import logging import logging.handlers import os +import sys import re import signal import stat @@ -36,22 +37,21 @@ import inotify.adapters LOCAL_TTL = 60 +log = logging.getLogger("dhcp-bridge") + def setup_logging(loglevel=logging.INFO): - log = logging.getLogger("dhcp") log.setLevel(loglevel) - - handler = logging.handlers.SysLogHandler(address="/dev/log", facility="daemon") + if args.daemon: + handler = logging.handlers.SysLogHandler(address="/dev/log", facility="daemon") + else: + handler = logging.StreamHandler(sys.stderr) handler.setLevel(loglevel) - formatter = logging.Formatter("%(name)s[%(process)d]: %(message)s") + formatter = logging.Formatter("%(name)s: %(message)s") handler.setFormatter(formatter) log.addHandler(handler) - return log - -log = logging.getLogger("dhcp") - def ip_address_to_reverse_pointer(address): parts = address.split(".") parts.reverse() @@ -602,7 +602,7 @@ if __name__ == "__main__": bridge = UnboundDHCPLeasesBridge(args.dhcp_leases, args.fix_leases, args.unbound_leases, args.hosts) - ctx = daemon.DaemonContext(detach_process=args.daemon) + ctx = daemon.DaemonContext(detach_process=args.daemon, stderr=(None if args.daemon else sys.stderr)) ctx.signal_map = { signal.SIGHUP : bridge.update_dhcp_leases, signal.SIGTERM : bridge.terminate,