From nobody Sun Dec 14 02:00:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558528325; cv=none; d=zoho.com; s=zohoarc; b=S6RU75fzVLuMaEhAiq2yhuH7Fz3eru/f9bIYG2nNsABQxpc3o2ASe+9IYqN6lbEUOWflSq0AYTe+zFVskXzKUH7sxStlps7FRAJP2bKyyaojym/NbPlN3vMZqnHQc6+fuzcunUmSuRvSCUzJJFerzC2kEFvmcPBfqB16WiqoPA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558528325; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=8yW4iye26Uuybeo/j+gHz3+TrxDDWzICgwRDtijAMAE=; b=iIuJyVeXH1tQUVpNsB5/ZrTRh1T0YF6Y7g+UPsyvpm3cpiOQsby/aqpqA/J3uTi2IraoA8wyjrZ+pH458C6/hS97c7I1n4LjQ4WMhaUj7jhGo2jFgjED1qM7Vq163+TOPpRHtR1hZ9q2Y1ARqv7V1oevWvjHxm0Mz2PSDhT6AiM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1558528325084577.2226089367726; Wed, 22 May 2019 05:32:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD96C301E12F; Wed, 22 May 2019 12:31:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07FEA2D1AB; Wed, 22 May 2019 12:31:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B226E5B425; Wed, 22 May 2019 12:31:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4MCTAcp021308 for ; Wed, 22 May 2019 08:29:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9A19B648D9; Wed, 22 May 2019 12:29:10 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 197CC66066; Wed, 22 May 2019 12:29:07 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 22 May 2019 13:29:01 +0100 Message-Id: <20190522122903.18763-2-berrange@redhat.com> In-Reply-To: <20190522122903.18763-1-berrange@redhat.com> References: <20190522122903.18763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] network: pull global chain init into separate method X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 22 May 2019 12:31:59 +0000 (UTC) Pull the logic for creating global iptables chains into a separate method and protect its invokation with virOnce, to make it possible to reuse it in non-startup paths. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jim Fehlig --- src/network/bridge_driver_linux.c | 39 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_= linux.c index f2827543ca..0d849173b2 100644 --- a/src/network/bridge_driver_linux.c +++ b/src/network/bridge_driver_linux.c @@ -35,22 +35,18 @@ VIR_LOG_INIT("network.bridge_driver_linux"); =20 #define PROC_NET_ROUTE "/proc/net/route" =20 +static virOnceControl createdOnce; +static bool createdChains; static virErrorPtr errInitV4; static virErrorPtr errInitV6; =20 -void networkPreReloadFirewallRules(bool startup) +/* Only call via virOnce */ +static void networkSetupPrivateChains(void) { - bool created =3D false; int rc; =20 - /* We create global rules upfront as we don't want - * the perf hit of conditionally figuring out whether - * to create them each time a network is started. - * - * Any errors here are saved to be reported at time - * of starting the network though as that makes them - * more likely to be seen by a human - */ + createdChains =3D false; + rc =3D iptablesSetupPrivateChains(VIR_FIREWALL_LAYER_IPV4); if (rc < 0) { errInitV4 =3D virSaveLastError(); @@ -58,9 +54,9 @@ void networkPreReloadFirewallRules(bool startup) } else { virFreeError(errInitV4); errInitV4 =3D NULL; + if (rc) + createdChains =3D true; } - if (rc) - created =3D true; =20 rc =3D iptablesSetupPrivateChains(VIR_FIREWALL_LAYER_IPV6); if (rc < 0) { @@ -69,9 +65,22 @@ void networkPreReloadFirewallRules(bool startup) } else { virFreeError(errInitV6); errInitV6 =3D NULL; + if (rc) + createdChains =3D true; } - if (rc) - created =3D true; +} + +void networkPreReloadFirewallRules(bool startup) +{ + /* We create global rules upfront as we don't want + * the perf hit of conditionally figuring out whether + * to create them each time a network is started. + * + * Any errors here are saved to be reported at time + * of starting the network though as that makes them + * more likely to be seen by a human + */ + ignore_value(virOnce(&createdOnce, networkSetupPrivateChains)); =20 /* * If this is initial startup, and we just created the @@ -86,7 +95,7 @@ void networkPreReloadFirewallRules(bool startup) * rules will be present. Thus we can safely just tell it * to always delete from the builin chain */ - if (startup && created) + if (startup && createdChains) iptablesSetDeletePrivate(false); } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list