From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qEWrB3iv7GCphQAAgWs5BA (envelope-from ) for ; Mon, 12 Jul 2021 23:09:12 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 6J17A3iv7GA7EwAAB5/wlQ (envelope-from ) for ; Mon, 12 Jul 2021 21:09:12 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D1C261973F for ; Mon, 12 Jul 2021 23:09:11 +0200 (CEST) Received: from localhost ([::1]:38012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m33As-000887-VZ for larch@yhetil.org; Mon, 12 Jul 2021 17:09:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m33Ak-00087a-VI for guix-patches@gnu.org; Mon, 12 Jul 2021 17:09:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55655) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m33Ak-0006L8-O6 for guix-patches@gnu.org; Mon, 12 Jul 2021 17:09:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m33Ak-00021t-Kb for guix-patches@gnu.org; Mon, 12 Jul 2021 17:09:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49540] [PATCH 2/2] services: nftables: Make it extendable. Resent-From: Brice Waegeneire Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 12 Jul 2021 21:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49540 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49540@debbugs.gnu.org Cc: iyzsong@member.fsf.org, solene@perso.pw X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16261241187762 (code B ref -1); Mon, 12 Jul 2021 21:09:02 +0000 Received: (at submit) by debbugs.gnu.org; 12 Jul 2021 21:08:38 +0000 Received: from localhost ([127.0.0.1]:38967 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m33AM-000213-8K for submit@debbugs.gnu.org; Mon, 12 Jul 2021 17:08:38 -0400 Received: from lists.gnu.org ([209.51.188.17]:53672) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m33AG-00020k-H8 for submit@debbugs.gnu.org; Mon, 12 Jul 2021 17:08:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m33AG-00083X-7Z for guix-patches@gnu.org; Mon, 12 Jul 2021 17:08:32 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:48859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m33AD-0005yB-ND for guix-patches@gnu.org; Mon, 12 Jul 2021 17:08:31 -0400 Received: (Authenticated sender: brice@waegenei.re) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id CF855E0003; Mon, 12 Jul 2021 21:08:27 +0000 (UTC) From: Brice Waegeneire Date: Mon, 12 Jul 2021 23:08:23 +0200 Message-Id: <20210712210823.16987-2-brice@waegenei.re> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712210543.16598-1-brice@waegenei.re> References: <20210712210543.16598-1-brice@waegenei.re> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=217.70.183.196; envelope-from=brice@waegenei.re; helo=relay4-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1626124151; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=JpzKGnCFowXGi8bO3B2bmZ4LC01zy0dnBfaZoYdInJk=; b=SXDBSRDTzxvllnDLf1rpjcX0zlcj/0hB7cOC6e8vJqLfgVowI0NSbnwuKZNEEnRmjDqADP F/4m+ryCo/AAx5M1f+xUZ9BS+x/vReutPayvKpmGKrcaCIkTC9nAv+yUJ0Hr3UY6jQ5QXl MWEtNfZEvP6eIZf/23/PKPrWl9wKfI4L03SZVaPFQArdbC/D9AMmoyspvmX8BcCHFamc6w GsLntw3/dsYz/TKK+sB19YiBdKsDNQJpG20LVFksKtlDBnJB1vDkCo2D9lADQeqgSr6dDU uwchMGHCtn0QpSq8BCOJ5nwg50P/vTXnmgaLuXOZmauShUNNE4+Suu5ykgVsmQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626124151; a=rsa-sha256; cv=none; b=nrV6eBIH7FWxzF6GCDIEWcqQZixl6gPh/dvTd4zxrpnJW9OJG457K6Lz6RYklZlxnM/wye oDthRNBRYENW+wN/t+I0spI3ZPD9l1x8DxI72mhlqvayvl5mfsl2cI5V1p9DCiNA2GotVR YgDNg4epClRAeQGmIVS2GsSpx8etKx47kno2aGR2BR1hEFtapQAS5D+OoLz4E2FL5lGR4l uotZyGrnoilKqfjrGwhA8r+ed/MxqEbtFaVktSp55+OPb1ZDIIRzhqc+qVl74+dBkDeeTd znFh6nChViWlVqF5/jLmvUJ1bXq3kfYLUacRb5KVsebJbP4cBCqe0dQdV0WEww== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -1.40 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: D1C261973F X-Spam-Score: -1.40 X-Migadu-Scanner: scn0.migadu.com X-TUID: F2MhrgFoNCnJ * gnu/services/networking.scm (%default-nftables-rules): New variable… (define-record-type): …replace %default-nftables-ruleset with it. (%default-nftables-ruleset): Deprecate it. (nftables-ruleset): New procedure… (nftables-shepherd-service): …use it. (nftables-service-type): Make it extendable. --- gnu/services/networking.scm | 40 ++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 3058c14caf..53c06dcfed 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -1714,9 +1714,8 @@ COMMIT ;;; nftables ;;; -(define %default-nftables-ruleset - (plain-file "nftables.conf" - "# A simple and safe firewall +(define %default-nftables-rules + "# A simple and safe firewall # Start with our table clean of previous state add table inet guix @@ -1752,7 +1751,11 @@ table inet guix { type filter hook output priority 0; policy accept; } } -")) +") + +(define-deprecated %default-nftables-ruleset + %default-nftables-rules + (plain-file "nftables.conf" %default-nftables-rules)) (define-record-type* nftables-configuration @@ -1760,13 +1763,28 @@ table inet guix { nftables-configuration? (package nftables-configuration-package (default nftables)) - (ruleset nftables-configuration-ruleset ; file-like object - (default %default-nftables-ruleset))) + ; file-like object | list of strings and file-like objects + (ruleset nftables-configuration-ruleset + (default (list %default-nftables-rules)))) + +(define (nftables-ruleset ruleset) + (if (file-like? ruleset) + ruleset + (apply mixed-text-file + `("nftables.conf" + ,@(fold-right + (lambda (rule result) + (if (file-like? rule) + (append (list "include \"" rule "\"\n") result) + (append (list rule "\n") result))) + '() + ruleset))))) (define nftables-shepherd-service (match-lambda (($ package ruleset) - (let ((nft (file-append package "/sbin/nft"))) + (let ((nft (file-append package "/sbin/nft")) + (ruleset (nftables-ruleset ruleset))) (shepherd-service (documentation "Packet filtering and classification") (provision '(nftables)) @@ -1785,6 +1803,14 @@ table inet guix { (compose list nftables-shepherd-service)) (service-extension profile-service-type (compose list nftables-configuration-package)))) + (compose concatenate) + (extend (lambda (config additional-rules) + (let ((ruleset (nftables-configuration-ruleset config))) + (nftables-configuration + (inherit config) + (ruleset (if (list? ruleset) + (append ruleset additional-rules) + (cons* ruleset additional-rules))))))) (default-value (nftables-configuration)))) -- 2.31.1