From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: Stefan Hanreich <s.hanreich@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: Re: [PATCH pve-firewall v2 03/12] firewall: dump configs locally after applying
Date: Wed, 2 Dec 2026 15:13:55 +0100 [thread overview]
Message-ID: <v4dbiknr5vilb4s7j2emexmdkduirffpfbjgwwkcnxb6pwte7e@suzcod7mj5br> (raw)
In-Reply-To: <179206832307.200960.4312066992851317571.b4-review@b4>
On Thu, Oct 15, 2026 at 02:45:23PM +0200, Stefan Hanreich wrote:
> > ... and remove them when the firewall is disabled in the config or the
> > daemon is stopped.
> >
> > The firewall config lives on pmxcfs, which is only available once
> > pve-cluster is up, i.e. well after the network. To be able to restore
> > rules before that, dump the config files needed to recompile the ruleset
> > (cluster.fw, host.fw and the SDN config as sdn.json) to a local
> > directory after every successful apply. The guest configs are not
> > dumped, since pve-guests does not start until the actual firewall daemon
> > is running.
> >
> > The last dumped content is cached per file, so the daemon only writes
> > when something changed since the last dump, or if the dump file does not
> > exist at all.
> >
> > Ownership of the dumps is keyed on the nftables option in the host
> > config. If the firewall is disabled cluster-wide, the dumps are removed.
> > If nftables is enabled, they are left in place, since proxmox-firewall
> > owns them in that case.
> >
> > The dumps are also removed when the daemon is stopped, to prevent a
> > ruleset restored at boot from living forever if no daemon starts
> > afterwards.
> >
[snip]
> > my $clusterfw_conf_filename = "$pvefw_conf_dir/cluster.fw";
> > my $vnetfw_conf_dir = "/etc/pve/sdn/firewall";
> >
> > +my $dump_dir = '/var/lib/pve/firewall';
>
> We moved from using those abbreviations in names / paths to just
> proxmox in general. E.g. the firewall binary is located in
> /usr/libexec/proxmox.
>
ack
[snip]
> > sub update {
> > my $code = sub {
> > + my $cfw_dump_path = "$dump_dir/cluster.fw";
> > + my $hfw_dump_path = "$dump_dir/host.fw";
> > + my $sdn_dump_path = "$dump_dir/sdn.json";
> >
> > my $cluster_conf = load_clusterfw_conf();
> > my $hostfw_conf = load_hostfw_conf($cluster_conf);
> >
> > if (!is_enabled_and_not_nftables($cluster_conf, $hostfw_conf)) {
> > PVE::Firewall::remove_pvefw_chains();
> > + $dump_cache = {};
> > + # disabled in config: drop stale dumps so the pre-network restore does not resurrect a
> > + # disabled ruleset. leave them in nftables mode, since in that case proxmox-firewall
> > + # owns the dump directory.
> > + delete_dumps() if !$cluster_conf->{options}->{enable};
> > return;
> > }
> >
> > + # compile() rewrites rule actions in-place. snapshot the untouched configs now for the
> > + # post-apply boot-time dump.
> > + my ($cfw_dump, $hfw_dump) = (dclone($cluster_conf), dclone($hostfw_conf));
> > +
> > my ($ruleset, $ipset_ruleset, $rulesetv6, $ebtables_ruleset) =
> > compile($cluster_conf, $hostfw_conf);
> >
> > apply_ruleset($ruleset, $hostfw_conf, $ipset_ruleset, $rulesetv6, $ebtables_ruleset);
> > +
> > + eval {
> > + mkdir($dump_dir);
>
> mkdir takes a mode parameter directly, use make_path here as well as
> we do in the network interface pinning? This also prevents us from
> changing the permissions every update cycle...
>
ack
> > + chmod(0700, $dump_dir);
> > + dump_if_changed($cfw_dump_path, serialize_clusterfw_conf($cfw_dump));
> > + dump_if_changed($hfw_dump_path, serialize_hostfw_conf($hfw_dump));
> > + dump_if_changed($sdn_dump_path, JSON->new->utf8->canonical->encode($cfw_dump->{sdn}));
>
> Did you check the performance impact of serializing and comparing the
> whole configuration file? It shouldn't matter too much afaict, but a
> quick check wouldn't hurt...
>
good point, just benchmarked with different combinations of
* large ipsets (few thousand members) with ipv4, ipv6 and alias members
* large amounts (10000+) of rules with alias and/or ipset references,
ipv4 & ipv6 literals
with ~10k rules each in cluster.fw and host.fw e.g., the dclone +
serialization and comparison add ~60ms per update cycle against ~1100ms for
parsing and ~300ms for compiling on my machine (not counting
apply_ruleset). will include these results in v3.
> --
> Stefan Hanreich <s.hanreich@proxmox.com>
--
Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
next prev parent reply other threads:[~2026-12-02 14:20 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 12:26 [RFC firewall/manager/proxmox{,-firewall} v2 00/12] fix #5759: keep firewall rules up across boot and shutdown Arthur Bied-Charreton
2026-10-01 12:26 ` [PATCH pve-manager v2 01/12] network interface pinning: write new firewall config to local dir Arthur Bied-Charreton
2026-10-01 12:26 ` [PATCH pve-firewall v2 02/12] firewall: config: sort OPTIONS when serializing Arthur Bied-Charreton
2026-10-15 12:45 ` Stefan Hanreich
2026-10-01 12:26 ` [PATCH pve-firewall v2 03/12] firewall: dump configs locally after applying Arthur Bied-Charreton
2026-10-15 12:45 ` Stefan Hanreich
2026-12-02 14:13 ` Arthur Bied-Charreton [this message]
2026-10-01 12:26 ` [PATCH pve-firewall v2 04/12] fix #5759: firewall: do not remove chains when host is shutting down Arthur Bied-Charreton
2026-10-15 12:45 ` Stefan Hanreich
2026-11-27 15:09 ` Arthur Bied-Charreton
2026-10-01 12:26 ` [PATCH pve-firewall v2 05/12] firewall: add restore command Arthur Bied-Charreton
2026-10-15 12:45 ` Stefan Hanreich
2026-10-01 12:26 ` [PATCH pve-firewall v2 06/12] fix #5759: firewall: restore from dumped config before network-pre Arthur Bied-Charreton
2026-10-15 12:45 ` Stefan Hanreich
2026-10-01 12:26 ` [PATCH proxmox v2 07/12] systemd: systemctl: add is-system-running helper Arthur Bied-Charreton
2026-10-01 12:26 ` [PATCH proxmox-firewall v2 08/12] firewall: fix clippy warnings Arthur Bied-Charreton
2026-10-15 12:44 ` Stefan Hanreich
2026-10-01 12:26 ` [PATCH proxmox-firewall v2 09/12] fix #5759: firewall: do not clear rules on system shutdown Arthur Bied-Charreton
2026-10-01 12:26 ` [PATCH proxmox-firewall v2 10/12] firewall: dump config to local directory after apply Arthur Bied-Charreton
2026-10-15 12:44 ` Stefan Hanreich
2026-10-01 12:26 ` [PATCH proxmox-firewall v2 11/12] firewall: add restore command Arthur Bied-Charreton
2026-10-15 12:44 ` Stefan Hanreich
2026-10-01 12:26 ` [PATCH proxmox-firewall v2 12/12] fix #5759: firewall: restore from dumped config before network-pre Arthur Bied-Charreton
2026-10-15 12:45 ` [RFC firewall/manager/proxmox{,-firewall} v2 00/12] fix #5759: keep firewall rules up across boot and shutdown Stefan Hanreich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=v4dbiknr5vilb4s7j2emexmdkduirffpfbjgwwkcnxb6pwte7e@suzcod7mj5br \
--to=a.bied-charreton@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
--cc=s.hanreich@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox