From nobody Tue Feb 10 04:58:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1732310354397715.6495943876954; Fri, 22 Nov 2024 13:19:14 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id CC24711B1; Fri, 22 Nov 2024 16:19:13 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 90A16162C; Fri, 22 Nov 2024 16:17:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9F9A81544; Fri, 22 Nov 2024 16:16:57 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 1BDBD152B for ; Fri, 22 Nov 2024 16:16:50 -0500 (EST) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-404-EvBDCYXTPL-VIIHvsFymOg-1; Fri, 22 Nov 2024 16:16:48 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AADA219560B0 for ; Fri, 22 Nov 2024 21:16:47 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.88.88]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 87CB030000DF; Fri, 22 Nov 2024 21:16:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732310209; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=wGBEM9Jg0lJMGzrBRJfqym6xFE3nDe5AWMui4sF03G8=; b=WFijybuYw28lE4z/g19oDsqcuGEtJUOwXnBC7I9DNQiltNuq3tHuPYk/MGuuwYFBYlD3N1 RxSzNNLMvl+Wle42XmxYBT0B6PYIpSicbFE5j5YYaXCFy4WEANv0rCjq+fLThfP84hTftW wkWUAOIEtqKviww2Zi0+T/aiRHkz5Lg= X-MC-Unique: EvBDCYXTPL-VIIHvsFymOg-1 X-Mimecast-MFC-AGG-ID: EvBDCYXTPL-VIIHvsFymOg From: Laine Stump To: devel@lists.libvirt.org Subject: [PATCH 4/5] util: add new "raw" layer for virFirewallCmd objects Date: Fri, 22 Nov 2024 16:16:38 -0500 Message-ID: <20241122211639.615518-5-laine@redhat.com> In-Reply-To: <20241122211639.615518-1-laine@redhat.com> References: <20241122211639.615518-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: yyxFpQ5V6TX0oTL4UBkN2apf2dOlk_Uu8MB4U2ec0ZE_1732310207 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FBHUQFUI2JNR4ERKSDKT42Q2PB6YGMCM X-Message-ID-Hash: FBHUQFUI2JNR4ERKSDKT42Q2PB6YGMCM X-MailFrom: laine@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: mprivozn@redhat.com, psutter@redhat.com, abologna@redhat.com, egarver@redhat.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732310357420116600 Content-Type: text/plain; charset="utf-8"; x-default="true" If the layer of a FirewallCmd is "raw", then the first arg is the name of an arbitrary binary to exec, and the rest are the arguments to that binary. raw layer doesn't support auto-rollback command creation (any rollback needs to be added manually with virFirewallAddRollbackCmd()), and also raw layer isn't supported by the iptables backend (it would have been straightforward to add, but the iptables backend doesn't need it, and I didn't want to take the chance of causing a regression in that code for no good reason). Signed-off-by: Laine Stump --- src/network/network_nftables.c | 1 + src/util/virfirewall.c | 74 +++++++++++++++++++++------------- src/util/virfirewall.h | 1 + src/util/virfirewalld.c | 1 + 4 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/network/network_nftables.c b/src/network/network_nftables.c index f8b5ab665d..e7ee3cd856 100644 --- a/src/network/network_nftables.c +++ b/src/network/network_nftables.c @@ -71,6 +71,7 @@ VIR_ENUM_DECL(nftablesLayer); VIR_ENUM_IMPL(nftablesLayer, VIR_FIREWALL_LAYER_LAST, "", + "", "ip", "ip6", ); diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index 811b787ecc..48b83715d0 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -44,6 +44,7 @@ VIR_ENUM_IMPL(virFirewallBackend, VIR_ENUM_DECL(virFirewallLayer); VIR_ENUM_IMPL(virFirewallLayer, VIR_FIREWALL_LAYER_LAST, + "raw", "ethernet", "ipv4", "ipv6", @@ -54,6 +55,7 @@ typedef struct _virFirewallGroup virFirewallGroup; VIR_ENUM_DECL(virFirewallLayerCommand); VIR_ENUM_IMPL(virFirewallLayerCommand, VIR_FIREWALL_LAYER_LAST, + "", EBTABLES, IPTABLES, IP6TABLES, @@ -591,6 +593,7 @@ virFirewallCmdIptablesApply(virFirewall *firewall, case VIR_FIREWALL_LAYER_IPV6: virCommandAddArg(cmd, "-w"); break; + case VIR_FIREWALL_LAYER_RAW: case VIR_FIREWALL_LAYER_LAST: break; } @@ -672,43 +675,58 @@ virFirewallCmdNftablesApply(virFirewall *firewall G_G= NUC_UNUSED, size_t i; int status; =20 - cmd =3D virCommandNew(NFT); + if (fwCmd->layer =3D=3D VIR_FIREWALL_LAYER_RAW) { =20 - if ((virFirewallTransactionGetFlags(firewall) & VIR_FIREWALL_TRANSACTI= ON_AUTO_ROLLBACK) && - fwCmd->argsLen > 1) { - /* skip any leading options to get to command verb */ - for (i =3D 0; i < fwCmd->argsLen - 1; i++) { - if (fwCmd->args[i][0] !=3D '-') - break; - } + /* for VIR_FIREWALL_LAYER_RAW, args[0] is the binary name + * and the rest are the args to that command + */ + cmd =3D virCommandNew(fwCmd->args[0]); =20 - if (i + 1 < fwCmd->argsLen && - VIR_NFTABLES_ARG_IS_CREATE(fwCmd->args[i])) { + /* NB: RAW commands don't support auto-rollback command creation */ =20 - cmdIdx =3D i; - objectType =3D fwCmd->args[i + 1]; + for (i =3D 1; i < fwCmd->argsLen; i++) + virCommandAddArg(cmd, fwCmd->args[i]); =20 - /* we currently only handle auto-rollback for rules, - * chains, and tables, and those all can be "rolled - * back" by a delete command using the handle that is - * returned when "-ae" is added to the add/insert - * command. - */ - if (STREQ_NULLABLE(objectType, "rule") || - STREQ_NULLABLE(objectType, "chain") || - STREQ_NULLABLE(objectType, "table")) { + } else { + + cmd =3D virCommandNew(NFT); + + if ((virFirewallTransactionGetFlags(firewall) & VIR_FIREWALL_TRANS= ACTION_AUTO_ROLLBACK) && + fwCmd->argsLen > 1) { + /* skip any leading options to get to command verb */ + for (i =3D 0; i < fwCmd->argsLen - 1; i++) { + if (fwCmd->args[i][0] !=3D '-') + break; + } + + if (i + 1 < fwCmd->argsLen && + VIR_NFTABLES_ARG_IS_CREATE(fwCmd->args[i])) { =20 - needRollback =3D true; - /* this option to nft instructs it to add the - * "handle" of the created object to stdout + cmdIdx =3D i; + objectType =3D fwCmd->args[i + 1]; + + /* we currently only handle auto-rollback for rules, + * chains, and tables, and those all can be "rolled + * back" by a delete command using the handle that is + * returned when "-ae" is added to the add/insert + * command. */ - virCommandAddArg(cmd, "-ae"); + if (STREQ_NULLABLE(objectType, "rule") || + STREQ_NULLABLE(objectType, "chain") || + STREQ_NULLABLE(objectType, "table")) { + + needRollback =3D true; + /* this option to nft instructs it to add the + * "handle" of the created object to stdout + */ + virCommandAddArg(cmd, "-ae"); + } } } - } =20 - for (i =3D 0; i < fwCmd->argsLen; i++) - virCommandAddArg(cmd, fwCmd->args[i]); + for (i =3D 0; i < fwCmd->argsLen; i++) + virCommandAddArg(cmd, fwCmd->args[i]); + } =20 cmdStr =3D virCommandToString(cmd, false); VIR_INFO("Applying '%s'", NULLSTR(cmdStr)); diff --git a/src/util/virfirewall.h b/src/util/virfirewall.h index bce51259d2..636337e13e 100644 --- a/src/util/virfirewall.h +++ b/src/util/virfirewall.h @@ -36,6 +36,7 @@ typedef struct _virFirewall virFirewall; typedef struct _virFirewallCmd virFirewallCmd; =20 typedef enum { + VIR_FIREWALL_LAYER_RAW, VIR_FIREWALL_LAYER_ETHERNET, VIR_FIREWALL_LAYER_IPV4, VIR_FIREWALL_LAYER_IPV6, diff --git a/src/util/virfirewalld.c b/src/util/virfirewalld.c index 0a886780ad..21a9e02061 100644 --- a/src/util/virfirewalld.c +++ b/src/util/virfirewalld.c @@ -43,6 +43,7 @@ VIR_LOG_INIT("util.firewalld"); VIR_ENUM_DECL(virFirewallLayerFirewallD); VIR_ENUM_IMPL(virFirewallLayerFirewallD, VIR_FIREWALL_LAYER_LAST, + "", "eb", "ipv4", "ipv6", --=20 2.47.0