]> git.proxmox.com Git - pve-firewall.git/blobdiff - src/PVE/Firewall.pm
ebtables: remove PVE chains properly
[pve-firewall.git] / src / PVE / Firewall.pm
index 48e630004bf424c2db578aad3e60eb61db42f8e6..3b67186ed35c18ca7ed62c0f2001c5dbb0e649bb 100644 (file)
@@ -2,27 +2,28 @@ package PVE::Firewall;
 
 use warnings;
 use strict;
-use POSIX;
-use Data::Dumper;
+
 use Digest::SHA;
-use Socket qw(AF_INET6 inet_ntop inet_pton);
-use PVE::INotify;
-use PVE::Exception qw(raise raise_param_exc);
-use PVE::JSONSchema qw(register_standard_option get_standard_option);
-use PVE::Cluster;
-use PVE::ProcFSTools;
-use PVE::Tools qw($IPV4RE $IPV6RE);
-use PVE::Network;
-use PVE::SafeSyslog;
+use Encode;
 use File::Basename;
 use File::Path;
 use IO::File;
 use Net::IP;
-use PVE::Tools qw(run_command lock_file dir_glob_foreach);
-use Encode;
+use POSIX;
+use Socket qw(AF_INET AF_INET6 inet_ntop inet_pton);
 use Storable qw(dclone);
 
-my $hostfw_conf_filename = "/etc/pve/local/host.fw";
+use PVE::Cluster;
+use PVE::Corosync;
+use PVE::Exception qw(raise raise_param_exc);
+use PVE::INotify;
+use PVE::JSONSchema qw(register_standard_option get_standard_option);
+use PVE::Network;
+use PVE::ProcFSTools;
+use PVE::SafeSyslog;
+use PVE::Tools qw($IPV4RE $IPV6RE);
+use PVE::Tools qw(run_command lock_file dir_glob_foreach);
+
 my $pvefw_conf_dir = "/etc/pve/firewall";
 my $clusterfw_conf_filename = "$pvefw_conf_dir/cluster.fw";
 
@@ -41,7 +42,6 @@ eval {
     $have_lxc = 1;
 };
 
-
 my $pve_fw_status_dir = "/var/lib/pve-firewall";
 
 mkdir $pve_fw_status_dir; # make sure this exists
@@ -127,11 +127,11 @@ eval  {
 };
 
 my $nodename = PVE::INotify::nodename();
+my $hostfw_conf_filename = "/etc/pve/nodes/$nodename/host.fw";
 
 my $pve_fw_lock_filename = "/var/lock/pvefw.lck";
 
 my $default_log_level = 'nolog'; # avoid logs by default
-
 my $global_log_ratelimit = '--limit 1/sec';
 
 my $log_level_hash = {
@@ -145,6 +145,11 @@ my $log_level_hash = {
     emerg => 0,
 };
 
+my $verbose = 0;
+sub set_verbose {
+    $verbose = shift;
+}
+
 # %rule
 #
 # name => optional
@@ -662,14 +667,10 @@ $pve_std_chains_conf->{6} = {
        #{ action => 'DROP', dest => '224.0.0.0/4' },
     ],
     'PVEFW-reject' => [
-       # same as shorewall 'reject'
-       #{ action => 'DROP', dsttype => 'BROADCAST' },
-       #{ action => 'DROP', source => '224.0.0.0/4' },
        { action => 'DROP', proto => 'icmpv6' },
        { match => '-p tcp', target => '-j REJECT --reject-with tcp-reset' },
-       #"-p udp -j REJECT --reject-with icmp-port-unreachable",
-       #"-p icmp -j REJECT --reject-with icmp-host-unreachable",
-       #"-j REJECT --reject-with icmp-host-prohibited",
+       { match => '-p udp', target => '-j REJECT --reject-with icmp6-port-unreachable' },
+       { target => '-j REJECT --reject-with icmp6-adm-prohibited' },
     ],
     'PVEFW-Drop' => [
        # same as shorewall 'Drop', which is equal to DROP,
@@ -2387,21 +2388,40 @@ sub generate_tap_rules_direction {
     # plug the tap chain to bridge chain
     if ($direction eq 'IN') {
        ruleset_addrule($ruleset, "PVEFW-FWBR-IN",
-                       "-m physdev --physdev-is-bridged --physdev-out $iface", "-j $tapchain", $loglevel, 'FWBR-IN: ', $vmid);
+                       "-m physdev --physdev-is-bridged --physdev-out $iface", "-j $tapchain");
     } else {
        ruleset_addrule($ruleset, "PVEFW-FWBR-OUT",
-                       "-m physdev --physdev-is-bridged --physdev-in $iface", "-j $tapchain", $loglevel, 'FWBR-OUT: ', $vmid);
+                       "-m physdev --physdev-is-bridged --physdev-in $iface", "-j $tapchain");
     }
 }
 
 sub enable_host_firewall {
-    my ($ruleset, $hostfw_conf, $cluster_conf, $ipversion) = @_;
+    my ($ruleset, $hostfw_conf, $cluster_conf, $ipversion, $corosync_conf) = @_;
 
     my $options = $hostfw_conf->{options};
     my $cluster_options = $cluster_conf->{options};
     my $rules = $hostfw_conf->{rules};
     my $cluster_rules = $cluster_conf->{rules};
 
+    # corosync preparation
+    my $corosync_rule = "-p udp --dport 5404:5405";
+    my $corosync_local_addresses = {};
+    my $multicast_enabled;
+    my $local_hostname = PVE::INotify::nodename();
+    if (defined($corosync_conf)) {
+       PVE::Corosync::for_all_corosync_addresses($corosync_conf, $ipversion, sub {
+           my ($node_name, $node_ip, $node_ipversion, $key) = @_;
+
+           if ($node_name eq $local_hostname) {
+               $corosync_local_addresses->{$key} = $node_ip;
+           }
+       });
+
+       # allow multicast only if enabled in config
+       my $corosync_transport = $corosync_conf->{main}->{totem}->{transport};
+       $multicast_enabled = defined($corosync_transport) && $corosync_transport eq 'udp';
+    }
+
     # host inbound firewall
     my $chain = "PVEFW-HOST-IN";
     ruleset_create_chain($ruleset, $chain);
@@ -2446,14 +2466,20 @@ sub enable_host_firewall {
     ruleset_addrule($ruleset, $chain, "$mngmntsrc -p tcp --dport 3128", "-j $accept_action");  # SPICE Proxy
     ruleset_addrule($ruleset, $chain, "$mngmntsrc -p tcp --dport 22", "-j $accept_action");  # SSH
 
-    my $localnet = $cluster_conf->{aliases}->{local_network}->{cidr};
-    my $localnet_ver = $cluster_conf->{aliases}->{local_network}->{ipversion};
+    # corosync inbound rules
+    if (defined($corosync_conf)) {
+       ruleset_addrule($ruleset, $chain, "-m addrtype --dst-type MULTICAST $corosync_rule", "-j $accept_action")
+           if $multicast_enabled;
 
-    # corosync
-    if ($localnet && ($ipversion == $localnet_ver)) {
-       my $corosync_rule = "-p udp --dport 5404:5405";
-       ruleset_addrule($ruleset, $chain, "-s $localnet -d $localnet $corosync_rule", "-j $accept_action");
-       ruleset_addrule($ruleset, $chain, "-s $localnet -m addrtype --dst-type MULTICAST $corosync_rule", "-j $accept_action");
+       PVE::Corosync::for_all_corosync_addresses($corosync_conf, $ipversion, sub {
+           my ($node_name, $node_ip, $node_ipversion, $key) = @_;
+           my $destination = $corosync_local_addresses->{$key};
+
+           if ($node_name ne $local_hostname && defined($destination)) {
+               # accept only traffic on same ring
+               ruleset_addrule($ruleset, $chain, "-d $destination -s $node_ip $corosync_rule", "-j $accept_action");
+           }
+       });
     }
 
     # implement input policy
@@ -2496,15 +2522,30 @@ sub enable_host_firewall {
     }
 
     # allow standard traffic on cluster network
+    my $localnet = $cluster_conf->{aliases}->{local_network}->{cidr};
+    my $localnet_ver = $cluster_conf->{aliases}->{local_network}->{ipversion};
+
     if ($localnet && ($ipversion == $localnet_ver)) {
        ruleset_addrule($ruleset, $chain, "-d $localnet -p tcp --dport 8006", "-j $accept_action");  # PVE API
        ruleset_addrule($ruleset, $chain, "-d $localnet -p tcp --dport 22", "-j $accept_action");  # SSH
        ruleset_addrule($ruleset, $chain, "-d $localnet -p tcp --dport 5900:5999", "-j $accept_action");  # PVE VNC Console
        ruleset_addrule($ruleset, $chain, "-d $localnet -p tcp --dport 3128", "-j $accept_action");  # SPICE Proxy
+    }
 
-       my $corosync_rule = "-p udp --dport 5404:5405";
-       ruleset_addrule($ruleset, $chain, "-d $localnet $corosync_rule", "-j $accept_action");
-       ruleset_addrule($ruleset, $chain, "-m addrtype --dst-type MULTICAST $corosync_rule", "-j $accept_action");
+    # corosync outbound rules
+    if (defined($corosync_conf)) {
+       ruleset_addrule($ruleset, $chain, "-m addrtype --dst-type MULTICAST $corosync_rule", "-j $accept_action")
+           if $multicast_enabled;
+
+       PVE::Corosync::for_all_corosync_addresses($corosync_conf, $ipversion, sub {
+           my ($node_name, $node_ip, $node_ipversion, $key) = @_;
+           my $source = $corosync_local_addresses->{$key};
+
+           if ($node_name ne $local_hostname && defined($source)) {
+               # accept only traffic on same ring
+               ruleset_addrule($ruleset, $chain, "-s $source -d $node_ip $corosync_rule", "-j $accept_action");
+           }
+       });
     }
 
     # implement output policy
@@ -2569,7 +2610,7 @@ sub get_mark_values {
 }
 
 sub parse_fw_rule {
-    my ($prefix, $line, $cluster_conf, $fw_conf, $rule_env, $verbose) = @_;
+    my ($prefix, $line, $cluster_conf, $fw_conf, $rule_env) = @_;
 
     my $orig_line = $line;
 
@@ -2795,20 +2836,29 @@ sub parse_alias {
 }
 
 sub generic_fw_config_parser {
-    my ($filename, $fh, $verbose, $cluster_conf, $empty_conf, $rule_env) = @_;
+    my ($filename, $cluster_conf, $empty_conf, $rule_env) = @_;
 
     my $section;
     my $group;
 
     my $res = $empty_conf;
 
-    while (defined(my $line = <$fh>)) {
+    my $raw;
+    if ($filename =~ m!^/etc/pve/(.*)$!) {
+       $raw = PVE::Cluster::get_config($1);
+    } else {
+       $raw = eval { PVE::Tools::file_get_contents($filename) }; # ignore errors
+    }
+    return {} if !$raw;
+
+    my $linenr = 0;
+    while ($raw =~ /^\h*(.*?)\h*$/gm) {
+       my $line = $1;
+       $linenr++;
        next if $line =~ m/^#/;
        next if $line =~ m/^\s*$/;
-
        chomp $line;
 
-       my $linenr = $fh->input_line_number();
        my $prefix = "$filename (line $linenr)";
 
        if ($empty_conf->{options} && ($line =~ m/^\[options\]$/i)) {
@@ -2892,7 +2942,7 @@ sub generic_fw_config_parser {
            warn "$prefix: $@" if $@;
        } elsif ($section eq 'rules') {
            my $rule;
-           eval { $rule = parse_fw_rule($prefix, $line, $cluster_conf, $res, $rule_env, $verbose); };
+           eval { $rule = parse_fw_rule($prefix, $line, $cluster_conf, $res, $rule_env); };
            if (my $err = $@) {
                warn "$prefix: $err";
                next;
@@ -2900,7 +2950,7 @@ sub generic_fw_config_parser {
            push @{$res->{$section}}, $rule;
        } elsif ($section eq 'groups') {
            my $rule;
-           eval { $rule = parse_fw_rule($prefix, $line, $cluster_conf, undef, 'group', $verbose); };
+           eval { $rule = parse_fw_rule($prefix, $line, $cluster_conf, undef, 'group'); };
            if (my $err = $@) {
                warn "$prefix: $err";
                next;
@@ -2957,47 +3007,6 @@ sub generic_fw_config_parser {
     return $res;
 }
 
-sub parse_hostfw_config {
-    my ($filename, $fh, $cluster_conf, $verbose) = @_;
-
-    my $empty_conf = { rules => [], options => {}};
-
-    return generic_fw_config_parser($filename, $fh, $verbose, $cluster_conf, $empty_conf, 'host');
-}
-
-sub parse_vmfw_config {
-    my ($filename, $fh, $cluster_conf, $rule_env, $verbose) = @_;
-
-    my $empty_conf = {
-       rules => [],
-       options => {},
-       aliases => {},
-       ipset => {} ,
-       ipset_comments => {},
-    };
-
-    return generic_fw_config_parser($filename, $fh, $verbose, $cluster_conf, $empty_conf, $rule_env);
-}
-
-sub parse_clusterfw_config {
-    my ($filename, $fh, $verbose) = @_;
-
-    my $section;
-    my $group;
-
-    my $empty_conf = {
-       rules => [],
-       options => {},
-       aliases => {},
-       groups => {},
-       group_comments => {},
-       ipset => {} ,
-       ipset_comments => {},
-    };
-
-    return generic_fw_config_parser($filename, $fh, $verbose, $empty_conf, $empty_conf, 'cluster');
-}
-
 sub run_locked {
     my ($code, @param) = @_;
 
@@ -3047,17 +3056,21 @@ sub read_local_vm_config {
 };
 
 sub load_vmfw_conf {
-    my ($cluster_conf, $rule_env, $vmid, $dir, $verbose) = @_;
-
-    my $vmfw_conf = {};
+    my ($cluster_conf, $rule_env, $vmid, $dir) = @_;
 
     $dir = $pvefw_conf_dir if !defined($dir);
-
     my $filename = "$dir/$vmid.fw";
-    if (my $fh = IO::File->new($filename, O_RDONLY)) {
-       $vmfw_conf = parse_vmfw_config($filename, $fh, $cluster_conf, $rule_env, $verbose);
-       $vmfw_conf->{vmid} = $vmid;
-    }
+
+    my $empty_conf = {
+       rules => [],
+       options => {},
+       aliases => {},
+       ipset => {} ,
+       ipset_comments => {},
+    };
+
+    my $vmfw_conf = generic_fw_config_parser($filename, $cluster_conf, $empty_conf, $rule_env);
+    $vmfw_conf->{vmid} = $vmid;
 
     return $vmfw_conf;
 }
@@ -3219,17 +3232,17 @@ sub clone_vmfw_conf {
 }
 
 sub read_vm_firewall_configs {
-    my ($cluster_conf, $vmdata, $dir, $verbose) = @_;
+    my ($cluster_conf, $vmdata, $dir) = @_;
 
     my $vmfw_configs = {};
 
     foreach my $vmid (keys %{$vmdata->{qemu}}) {
-       my $vmfw_conf = load_vmfw_conf($cluster_conf, 'vm', $vmid, $dir, $verbose);
+       my $vmfw_conf = load_vmfw_conf($cluster_conf, 'vm', $vmid, $dir);
        next if !$vmfw_conf->{options}; # skip if file does not exists
        $vmfw_configs->{$vmid} = $vmfw_conf;
     }
     foreach my $vmid (keys %{$vmdata->{lxc}}) {
-        my $vmfw_conf = load_vmfw_conf($cluster_conf, 'ct', $vmid, $dir, $verbose);
+        my $vmfw_conf = load_vmfw_conf($cluster_conf, 'ct', $vmid, $dir);
         next if !$vmfw_conf->{options}; # skip if file does not exists
         $vmfw_configs->{$vmid} = $vmfw_conf;
     }
@@ -3390,16 +3403,21 @@ my $set_global_log_ratelimit = sub {
 };
 
 sub load_clusterfw_conf {
-    my ($filename, $verbose) = @_;
+    my ($filename) = @_;
 
     $filename = $clusterfw_conf_filename if !defined($filename);
+    my $empty_conf = {
+       rules => [],
+       options => {},
+       aliases => {},
+       groups => {},
+       group_comments => {},
+       ipset => {} ,
+       ipset_comments => {},
+    };
 
-    my $cluster_conf = {};
-    if (my $fh = IO::File->new($filename, O_RDONLY)) {
-       $cluster_conf = parse_clusterfw_config($filename, $fh, $verbose);
-
-       $set_global_log_ratelimit->($cluster_conf->{options});
-    }
+    my $cluster_conf = generic_fw_config_parser($filename, $empty_conf, $empty_conf, 'cluster');
+    $set_global_log_ratelimit->($cluster_conf->{options});
 
     return $cluster_conf;
 }
@@ -3448,15 +3466,12 @@ sub save_clusterfw_conf {
 }
 
 sub load_hostfw_conf {
-    my ($cluster_conf, $filename, $verbose) = @_;
+    my ($cluster_conf, $filename) = @_;
 
     $filename = $hostfw_conf_filename if !defined($filename);
 
-    my $hostfw_conf = {};
-    if (my $fh = IO::File->new($filename, O_RDONLY)) {
-       $hostfw_conf = parse_hostfw_config($filename, $fh, $cluster_conf, $verbose);
-    }
-    return $hostfw_conf;
+    my $empty_conf = { rules => [], options => {}};
+    return generic_fw_config_parser($filename, $cluster_conf, $empty_conf, 'host');
 }
 
 sub save_hostfw_conf {
@@ -3482,7 +3497,7 @@ sub save_hostfw_conf {
 }
 
 sub compile {
-    my ($cluster_conf, $hostfw_conf, $vmdata, $verbose) = @_;
+    my ($cluster_conf, $hostfw_conf, $vmdata, $corosync_conf) = @_;
 
     my $vmfw_configs;
 
@@ -3492,19 +3507,23 @@ sub compile {
     if ($vmdata) { # test mode
        my $testdir = $vmdata->{testdir} || die "no test directory specified";
        my $filename = "$testdir/cluster.fw";
-       $cluster_conf = load_clusterfw_conf($filename, $verbose);
+       $cluster_conf = load_clusterfw_conf($filename);
 
        $filename = "$testdir/host.fw";
-       $hostfw_conf = load_hostfw_conf($cluster_conf, $filename, $verbose);
+       $hostfw_conf = load_hostfw_conf($cluster_conf, $filename);
 
-       $vmfw_configs = read_vm_firewall_configs($cluster_conf, $vmdata, $testdir, $verbose);
+       $vmfw_configs = read_vm_firewall_configs($cluster_conf, $vmdata, $testdir);
     } else { # normal operation
-       $cluster_conf = load_clusterfw_conf(undef, $verbose) if !$cluster_conf;
+       $cluster_conf = load_clusterfw_conf(undef) if !$cluster_conf;
+
+       $hostfw_conf = load_hostfw_conf($cluster_conf, undef) if !$hostfw_conf;
 
-       $hostfw_conf = load_hostfw_conf($cluster_conf, undef, $verbose) if !$hostfw_conf;
+       # cfs_update is handled by daemon or API
+       $corosync_conf = PVE::Cluster::cfs_read_file("corosync.conf")
+           if !defined($corosync_conf) && PVE::Corosync::check_conf_exists(1);
 
        $vmdata = read_local_vm_config();
-       $vmfw_configs = read_vm_firewall_configs($cluster_conf, $vmdata, undef, $verbose);
+       $vmfw_configs = read_vm_firewall_configs($cluster_conf, $vmdata, undef);
     }
 
     return ({},{},{},{}) if !$cluster_conf->{options}->{enable};
@@ -3522,16 +3541,16 @@ sub compile {
 
     push @{$cluster_conf->{ipset}->{management}}, { cidr => $localnet };
 
-    my $ruleset = compile_iptables_filter($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, 4, $verbose);
-    my $rulesetv6 = compile_iptables_filter($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, 6, $verbose);
-    my $ebtables_ruleset = compile_ebtables_filter($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, $verbose);
+    my $ruleset = compile_iptables_filter($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, $corosync_conf, 4);
+    my $rulesetv6 = compile_iptables_filter($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, $corosync_conf, 6);
+    my $ebtables_ruleset = compile_ebtables_filter($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata);
     my $ipset_ruleset = compile_ipsets($cluster_conf, $vmfw_configs, $vmdata);
 
     return ($ruleset, $ipset_ruleset, $rulesetv6, $ebtables_ruleset);
 }
 
 sub compile_iptables_filter {
-    my ($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, $ipversion, $verbose) = @_;
+    my ($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, $corosync_conf, $ipversion) = @_;
 
     my $ruleset = {};
 
@@ -3561,7 +3580,7 @@ sub compile_iptables_filter {
     my $hostfw_enable = !(defined($hostfw_options->{enable}) && ($hostfw_options->{enable} == 0));
 
     if ($hostfw_enable) {
-       eval { enable_host_firewall($ruleset, $hostfw_conf, $cluster_conf, $ipversion); };
+       eval { enable_host_firewall($ruleset, $hostfw_conf, $cluster_conf, $ipversion, $corosync_conf); };
        warn $@ if $@; # just to be sure - should not happen
     }
 
@@ -3741,7 +3760,7 @@ sub compile_ipsets {
 }
 
 sub compile_ebtables_filter {
-    my ($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, $verbose) = @_;
+    my ($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata) = @_;
 
     if (!($cluster_conf->{options}->{ebtables} // 1)) {
        return {};
@@ -3808,7 +3827,12 @@ sub compile_ebtables_filter {
                        push(@$arpfilter, $ip);
                    }
                }
-               push(@$arpfilter, $net->{ip}) if $net->{ip} && $vmfw_conf->{options}->{ipfilter};
+               if (defined(my $ip = $net->{ip}) && $vmfw_conf->{options}->{ipfilter}) {
+                   # ebtables changes this to a .0/MASK network but we just
+                   # want the address here, no network - see #2193
+                   $ip =~ s|/(\d+)$||;
+                   push @$arpfilter, $ip;
+               }
                generate_tap_layer2filter($ruleset, $iface, $macaddr, $vmfw_conf, $vmid, $arpfilter);
            }
        };
@@ -3866,7 +3890,7 @@ sub generate_tap_layer2filter {
 # * both the $active_chains hash and the returned status_hash have different
 #   structure (they contain a key named 'rules').
 sub get_ruleset_status {
-    my ($ruleset, $active_chains, $digest_fn, $verbose, $change_only_regex) = @_;
+    my ($ruleset, $active_chains, $digest_fn, $change_only_regex) = @_;
 
     my $statushash = {};
 
@@ -3924,12 +3948,12 @@ sub print_sig_rule {
 }
 
 sub get_ruleset_cmdlist {
-    my ($ruleset, $verbose, $iptablescmd) = @_;
+    my ($ruleset, $iptablescmd) = @_;
 
     my $cmdlist = "*filter\n"; # we pass this to iptables-restore;
 
     my ($active_chains, $hooks) = iptables_get_chains($iptablescmd);
-    my $statushash = get_ruleset_status($ruleset, $active_chains, \&iptables_chain_digest, $verbose);
+    my $statushash = get_ruleset_status($ruleset, $active_chains, \&iptables_chain_digest);
 
     # create missing chains first
     foreach my $chain (sort keys %$ruleset) {
@@ -3988,14 +4012,14 @@ sub get_ruleset_cmdlist {
 my $pve_ebtables_chainname_regex = qr/PVEFW-\S+|(?:tap|veth)\d+i\d+-(?:IN|OUT)/;
 
 sub get_ebtables_cmdlist {
-    my ($ruleset, $verbose) = @_;
+    my ($ruleset) = @_;
 
     my $changes = 0;
     my $cmdlist = "*filter\n";
 
     my $active_chains = ebtables_get_chains();
     my $statushash = get_ruleset_status($ruleset, $active_chains,
-                                       \&iptables_chain_digest, $verbose,
+                                       \&iptables_chain_digest,
                                        $pve_ebtables_chainname_regex);
 
     # create chains first and make sure PVE rules are evaluated if active
@@ -4026,14 +4050,14 @@ sub get_ebtables_cmdlist {
 }
 
 sub get_ipset_cmdlist {
-    my ($ruleset, $verbose) = @_;
+    my ($ruleset) = @_;
 
     my $cmdlist = "";
 
     my $delete_cmdlist = "";
 
     my $active_chains = ipset_get_chains();
-    my $statushash = get_ruleset_status($ruleset, $active_chains, \&ipset_chain_digest, $verbose);
+    my $statushash = get_ruleset_status($ruleset, $active_chains, \&ipset_chain_digest);
 
     # remove stale _swap chains
     foreach my $chain (keys %$active_chains) {
@@ -4084,16 +4108,16 @@ sub get_ipset_cmdlist {
 }
 
 sub apply_ruleset {
-    my ($ruleset, $hostfw_conf, $ipset_ruleset, $rulesetv6, $ebtables_ruleset, $verbose) = @_;
+    my ($ruleset, $hostfw_conf, $ipset_ruleset, $rulesetv6, $ebtables_ruleset) = @_;
 
     enable_bridge_firewall();
 
     my ($ipset_create_cmdlist, $ipset_delete_cmdlist, $ipset_changes) =
-       get_ipset_cmdlist($ipset_ruleset, $verbose);
+       get_ipset_cmdlist($ipset_ruleset);
 
-    my ($cmdlist, $changes) = get_ruleset_cmdlist($ruleset, $verbose);
-    my ($cmdlistv6, $changesv6) = get_ruleset_cmdlist($rulesetv6, $verbose, "ip6tables");
-    my ($ebtables_cmdlist, $ebtables_changes) = get_ebtables_cmdlist($ebtables_ruleset, $verbose);
+    my ($cmdlist, $changes) = get_ruleset_cmdlist($ruleset);
+    my ($cmdlistv6, $changesv6) = get_ruleset_cmdlist($rulesetv6, "ip6tables");
+    my ($ebtables_cmdlist, $ebtables_changes) = get_ebtables_cmdlist($ebtables_ruleset);
 
     if ($verbose) {
        if ($ipset_changes) {
@@ -4145,7 +4169,7 @@ sub apply_ruleset {
 
     # test: re-read status and check if everything is up to date
     my $active_chains = iptables_get_chains();
-    my $statushash = get_ruleset_status($ruleset, $active_chains, \&iptables_chain_digest, 0);
+    my $statushash = get_ruleset_status($ruleset, $active_chains, \&iptables_chain_digest);
 
     my $errors;
     foreach my $chain (sort keys %$ruleset) {
@@ -4157,7 +4181,7 @@ sub apply_ruleset {
     }
 
     my $active_chainsv6 = iptables_get_chains("ip6tables");
-    my $statushashv6 = get_ruleset_status($rulesetv6, $active_chainsv6, \&iptables_chain_digest, 0);
+    my $statushashv6 = get_ruleset_status($rulesetv6, $active_chainsv6, \&iptables_chain_digest);
 
     foreach my $chain (sort keys %$rulesetv6) {
        my $stat = $statushashv6->{$chain};
@@ -4170,7 +4194,7 @@ sub apply_ruleset {
     my $active_ebtables_chains = ebtables_get_chains();
     my $ebtables_statushash = get_ruleset_status($ebtables_ruleset,
                                $active_ebtables_chains, \&iptables_chain_digest,
-                               0, $pve_ebtables_chainname_regex);
+                               $pve_ebtables_chainname_regex);
 
     foreach my $chain (sort keys %$ebtables_ruleset) {
        my $stat = $ebtables_statushash->{$chain};
@@ -4245,6 +4269,7 @@ sub remove_pvefw_chains {
     PVE::Firewall::remove_pvefw_chains_iptables("iptables");
     PVE::Firewall::remove_pvefw_chains_iptables("ip6tables");
     PVE::Firewall::remove_pvefw_chains_ipset();
+    PVE::Firewall::remove_pvefw_chains_ebtables();
 
 }
 
@@ -4290,6 +4315,11 @@ sub remove_pvefw_chains_ipset {
     ipset_restore_cmdlist($cmdlist) if $cmdlist;
 }
 
+sub remove_pvefw_chains_ebtables {
+    # apply empty ruleset = remove all our chains
+    ebtables_restore_cmdlist(get_ebtables_cmdlist({}));
+}
+
 sub init {
     my $cluster_conf = load_clusterfw_conf();
     my $cluster_options = $cluster_conf->{options};