]> git.proxmox.com Git - pve-firewall.git/blobdiff - src/PVE/Firewall.pm
ebtables: test layer2_protocols in an external chain
[pve-firewall.git] / src / PVE / Firewall.pm
index c8a430c71ba0cc2e47f8cb70cfcd1bdbfb145079..6ac303831a62f630d437ef0e0508decd2b72f5ac 100644 (file)
@@ -1049,12 +1049,13 @@ sub parse_port_name_number_or_range {
     my @elements = split(/,/, $str);
     die "extraneous commas in list\n" if $str ne join(',', @elements);
     foreach my $item (@elements) {
-       if ($item =~ m/^(\d+):(\d+)$/) {
+       if ($item =~ m/^([0-9]+):([0-9]+)$/) {
            $count += 2;
            my ($port1, $port2) = ($1, $2);
            die "invalid port '$port1'\n" if $port1 > 65535;
            die "invalid port '$port2'\n" if $port2 > 65535;
-       } elsif ($item =~ m/^(\d+)$/) {
+           die "backwards range '$port1:$port2' not allowed, did you mean '$port2:$port1'?\n" if $port1 > $port2;
+       } elsif ($item =~ m/^([0-9]+)$/) {
            $count += 1;
            my $port = $1;
            die "invalid port '$port'\n" if $port > 65535;
@@ -1180,6 +1181,12 @@ our $cluster_option_properties = {
        minimum => 0,
        optional => 1,
     },
+    ebtables => {
+       description => "Enable ebtables rules cluster wide.",
+       type => 'boolean',
+       default => 1,
+       optional => 1,
+    },
     policy_in => {
        description => "Input policy.",
        type => 'string',
@@ -1235,6 +1242,12 @@ our $host_option_properties = {
        type => 'boolean',
        optional => 1,
     },
+    nf_conntrack_allow_invalid => {
+       description => "Allow invalid packets on connection tracking.",
+       type => 'boolean',
+       default => 0,
+       optional => 1,
+    },
 };
 
 our $vm_option_properties = {
@@ -1711,6 +1724,12 @@ sub ipset_restore_cmdlist {
     run_command("/sbin/ipset restore", input => $cmdlist, errmsg => "ipset_restore_cmdlist");
 }
 
+sub ebtables_restore_cmdlist {
+    my ($cmdlist) = @_;
+
+    run_command("/sbin/ebtables-restore", input => $cmdlist, errmsg => "ebtables_restore_cmdlist");
+}
+
 sub iptables_get_chains {
     my ($iptablescmd) = @_;
 
@@ -1821,6 +1840,36 @@ sub ipset_get_chains {
     return $res;
 }
 
+sub ebtables_get_chains {
+
+    my $res = {};
+    my $chains = {};
+    my $parser = sub {
+       my $line = shift;
+       return if $line =~ m/^#/;
+       return if $line =~ m/^\s*$/;
+       if ($line =~ m/^:(\S+)\s\S+$/) {
+           # Make sure we know chains exist even if they're empty.
+           $chains->{$1} //= [];
+       } elsif ($line =~ m/^(?:\S+)\s(\S+)\s(?:\S+).*/) {
+           my $chain = $1;
+           $line =~ s/\s+$//;
+           push @{$chains->{$chain}}, $line;
+       } else {
+           # simply ignore the rest
+           return;
+       }
+    };
+
+    run_command("/sbin/ebtables-save", outfunc => $parser);
+    # compute digest for each chain and store rules as well
+    foreach my $chain (keys %$chains) {
+       $res->{$chain}->{rules} = $chains->{$chain};
+       $res->{$chain}->{sig} = iptables_chain_digest($chains->{$chain});
+    }
+    return $res;
+}
+
 # substitude action of rule according to action hash
 sub rule_substitude_action {
     my ($rule, $actions) = @_;
@@ -2023,7 +2072,9 @@ sub ruleset_addrule {
        my $logaction = get_log_rule_base($chain, $vmid, $logmsg, $log);
        push @{$ruleset->{$chain}}, "-A $chain $match $logaction";
    }
-   push @{$ruleset->{$chain}}, "-A $chain $match $action";
+   # for stable ebtables digests avoid double-spaces to match ebtables-save output
+   $match .= ' ' if length($match);
+   push @{$ruleset->{$chain}}, "-A $chain ${match}$action";
 }
 
 sub ruleset_insertrule {
@@ -2063,7 +2114,7 @@ sub ruleset_add_chain_policy {
     } elsif ($policy eq 'REJECT') {
        ruleset_addrule($ruleset, $chain, "", "-j PVEFW-Reject");
 
-       ruleset_addrule($ruleset, $chain, "", "-g PVEFW-reject", $loglevel, "policy $policy:", $vmid);
+       ruleset_addrule($ruleset, $chain, "", "-g PVEFW-reject", $loglevel, "policy $policy: ", $vmid);
     } else {
        # should not happen
        die "internal error: unknown policy '$policy'";
@@ -2083,9 +2134,11 @@ sub ruleset_chain_add_ndp {
 }
 
 sub ruleset_chain_add_conn_filters {
-    my ($ruleset, $chain, $accept) = @_;
+    my ($ruleset, $chain, $allow_invalid, $accept) = @_;
 
-    ruleset_addrule($ruleset, $chain, "-m conntrack --ctstate INVALID", "-j DROP");
+    if (!$allow_invalid) {
+       ruleset_addrule($ruleset, $chain, "-m conntrack --ctstate INVALID", "-j DROP");
+    }
     ruleset_addrule($ruleset, $chain, "-m conntrack --ctstate RELATED,ESTABLISHED", "-j $accept");
 }
 
@@ -2274,7 +2327,7 @@ sub generate_tap_rules_direction {
        if ($direction eq 'OUT') {
            $policy = $options->{policy_out} || 'ACCEPT'; # allow everything by default
        } else {
-       $policy = $options->{policy_in} || 'DROP'; # allow nothing by default
+           $policy = $options->{policy_in} || 'DROP'; # allow nothing by default
        }
 
        my $accept = generate_nfqueue($options);
@@ -2311,7 +2364,7 @@ sub enable_host_firewall {
 
     ruleset_addrule($ruleset, $chain, "-i lo", "-j ACCEPT");
 
-    ruleset_chain_add_conn_filters($ruleset, $chain, 'ACCEPT');
+    ruleset_chain_add_conn_filters($ruleset, $chain, 0, 'ACCEPT');
     ruleset_chain_add_ndp($ruleset, $chain, $ipversion, $options, 'IN', '-j RETURN');
     ruleset_chain_add_input_filters($ruleset, $chain, $ipversion, $options, $cluster_conf, $loglevel);
 
@@ -2369,7 +2422,7 @@ sub enable_host_firewall {
 
     ruleset_addrule($ruleset, $chain, "-o lo", "-j ACCEPT");
 
-    ruleset_chain_add_conn_filters($ruleset, $chain, 'ACCEPT');
+    ruleset_chain_add_conn_filters($ruleset, $chain, 0, 'ACCEPT');
 
     # we use RETURN because we may want to check other thigs later
     $accept_action = 'RETURN';
@@ -2548,6 +2601,14 @@ sub parse_fw_rule {
     return $rule;
 }
 
+sub verify_ethertype {
+    my ($value) = @_;
+    my $types = get_etc_ethertypes();
+    die "unknown ethernet protocol type: $value\n"
+       if !defined($types->{byname}->{$value}) &&
+          !defined($types->{byid}->{$value});
+}
+
 sub parse_vmfw_option {
     my ($line) = @_;
 
@@ -2567,6 +2628,10 @@ sub parse_vmfw_option {
     } elsif ($line =~ m/^(ips_queues):\s*((\d+)(:(\d+))?)\s*$/i) {
        $opt = lc($1);
        $value = $2;
+    } elsif ($line =~ m/^(layer2_protocols):\s*(((\S+)[,]?)+)\s*$/i) {
+       $opt = lc($1);
+       $value = $2;
+       verify_ethertype($_) foreach split(/\s*,\s*/, $value);
     } else {
        die "can't parse option '$line'\n"
     }
@@ -2581,7 +2646,7 @@ sub parse_hostfw_option {
 
     my $loglevels = "emerg|alert|crit|err|warning|notice|info|debug|nolog";
 
-    if ($line =~ m/^(enable|nosmurfs|tcpflags|ndp):\s*(0|1)\s*$/i) {
+    if ($line =~ m/^(enable|nosmurfs|tcpflags|ndp|log_nf_conntrack|nf_conntrack_allow_invalid):\s*(0|1)\s*$/i) {
        $opt = lc($1);
        $value = int($2);
     } elsif ($line =~ m/^(log_level_in|log_level_out|tcp_flags_log_level|smurf_log_level):\s*(($loglevels)\s*)?$/i) {
@@ -2608,6 +2673,9 @@ sub parse_clusterfw_option {
        if (($value > 1) && ((time() - $value) > 60)) {
            $value = 0
        }
+    } elsif ($line =~ m/^(ebtables):\s*(0|1)\s*$/i) {
+       $opt = lc($1);
+       $value = int($2);
     } elsif ($line =~ m/^(policy_(in|out)):\s*(ACCEPT|DROP|REJECT)\s*$/i) {
        $opt = lc($1);
        $value = uc($3);
@@ -3363,7 +3431,7 @@ sub compile {
        $vmfw_configs = read_vm_firewall_configs($cluster_conf, $vmdata, undef, $verbose);
     }
 
-    return ({},{},{}) if !$cluster_conf->{options}->{enable};
+    return ({},{},{},{}) if !$cluster_conf->{options}->{enable};
 
     my $localnet;
     if ($cluster_conf->{aliases}->{local_network}) {
@@ -3372,7 +3440,7 @@ sub compile {
        my $localnet_ver;
        ($localnet, $localnet_ver) = parse_ip_or_cidr(local_network() || '127.0.0.0/8');
 
-       $cluster_conf->{aliases}->{local_network} = { 
+       $cluster_conf->{aliases}->{local_network} = {
            name => 'local_network', cidr => $localnet, ipversion => $localnet_ver };
     }
 
@@ -3380,9 +3448,10 @@ sub compile {
 
     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 $ipset_ruleset = compile_ipsets($cluster_conf, $vmfw_configs, $vmdata);
 
-    return ($ruleset, $ipset_ruleset, $rulesetv6);
+    return ($ruleset, $ipset_ruleset, $rulesetv6, $ebtables_ruleset);
 }
 
 sub compile_iptables_filter {
@@ -3400,7 +3469,8 @@ sub compile_iptables_filter {
     # fixme: what log level should we use here?
     my $loglevel = get_option_log_level($hostfw_options, "log_level_out");
 
-    ruleset_chain_add_conn_filters($ruleset, "PVEFW-FORWARD", "ACCEPT");
+    my $conn_allow_invalid = $hostfw_options->{nf_conntrack_allow_invalid} // 0;
+    ruleset_chain_add_conn_filters($ruleset, "PVEFW-FORWARD", $conn_allow_invalid, "ACCEPT");
 
     ruleset_create_chain($ruleset, "PVEFW-FWBR-IN");
     ruleset_chain_add_input_filters($ruleset, "PVEFW-FWBR-IN", $ipversion, $hostfw_options, $cluster_conf, $loglevel);
@@ -3594,17 +3664,148 @@ sub compile_ipsets {
     return $ipset_ruleset;
 }
 
+sub compile_ebtables_filter {
+    my ($cluster_conf, $hostfw_conf, $vmfw_configs, $vmdata, $verbose) = @_;
+
+    if (!($cluster_conf->{options}->{ebtables} // 1)) {
+       return {};
+    }
+
+    my $ruleset = {};
+
+    ruleset_create_chain($ruleset, "PVEFW-FORWARD");
+
+    ruleset_create_chain($ruleset, "PVEFW-FWBR-OUT");
+    #for ipv4 and ipv6, check macaddress in iptables, so we use conntrack 'ESTABLISHED', to speedup rules
+    ruleset_addrule($ruleset, 'PVEFW-FORWARD', '-p IPv4', '-j ACCEPT');
+    ruleset_addrule($ruleset, 'PVEFW-FORWARD', '-p IPv6', '-j ACCEPT');
+    ruleset_addrule($ruleset, 'PVEFW-FORWARD', '-o fwln+', '-j PVEFW-FWBR-OUT');
+
+    # generate firewall rules for QEMU VMs
+    foreach my $vmid (sort keys %{$vmdata->{qemu}}) {
+       eval {
+           my $conf = $vmdata->{qemu}->{$vmid};
+           my $vmfw_conf = $vmfw_configs->{$vmid};
+           return if !$vmfw_conf;
+           my $ipsets = $vmfw_conf->{ipset};
+
+           foreach my $netid (sort keys %$conf) {
+               next if $netid !~ m/^net(\d+)$/;
+               my $net = PVE::QemuServer::parse_net($conf->{$netid});
+               next if !$net->{firewall};
+               my $iface = "tap${vmid}i$1";
+               my $macaddr = $net->{macaddr};
+               my $arpfilter = [];
+               if (defined(my $ipset = $ipsets->{"ipfilter-$netid"})) {
+                   foreach my $ipaddr (@$ipset) {
+                       my($ip, $version) = parse_ip_or_cidr($ipaddr->{cidr});
+                       next if !$ip || ($version && $version != 4);
+                       push(@$arpfilter, $ip);
+                   }
+               }
+               generate_tap_layer2filter($ruleset, $iface, $macaddr, $vmfw_conf, $vmid, $arpfilter);
+           }
+       };
+       warn $@ if $@; # just to be sure - should not happen
+    }
+
+    # generate firewall rules for LXC containers
+    foreach my $vmid (sort keys %{$vmdata->{lxc}}) {
+       eval {
+           my $conf = $vmdata->{lxc}->{$vmid};
+
+           my $vmfw_conf = $vmfw_configs->{$vmid};
+           return if !$vmfw_conf || !$vmfw_conf->{options}->{enable};
+           my $ipsets = $vmfw_conf->{ipset};
+
+           foreach my $netid (sort keys %$conf) {
+               next if $netid !~ m/^net(\d+)$/;
+               my $net = PVE::LXC::Config->parse_lxc_network($conf->{$netid});
+               next if !$net->{firewall};
+               my $iface = "veth${vmid}i$1";
+               my $macaddr = $net->{hwaddr};
+               my $arpfilter = [];
+               if (defined(my $ipset = $ipsets->{"ipfilter-$netid"})) {
+                   foreach my $ipaddr (@$ipset) {
+                       my($ip, $version) = parse_ip_or_cidr($ipaddr->{cidr});
+                       next if !$ip || ($version && $version != 4);
+                       push(@$arpfilter, $ip);
+                   }
+               }
+               push(@$arpfilter, $net->{ip}) if $net->{ip} && $vmfw_conf->{options}->{ipfilter};
+               generate_tap_layer2filter($ruleset, $iface, $macaddr, $vmfw_conf, $vmid, $arpfilter);
+           }
+       };
+       warn $@ if $@; # just to be sure - should not happen
+    }
+
+    return $ruleset;
+}
+
+sub generate_tap_layer2filter {
+    my ($ruleset, $iface, $macaddr, $vmfw_conf, $vmid, $arpfilter) = @_;
+    my $options = $vmfw_conf->{options};
+
+    my $tapchain = $iface."-OUT";
+
+    # ebtables remove zeros from mac pairs
+    $macaddr =~ s/0([0-9a-f])/$1/ig;
+    $macaddr = lc($macaddr);
+
+    ruleset_create_chain($ruleset, $tapchain);
+
+    if (defined($macaddr) && !(defined($options->{macfilter}) && $options->{macfilter} == 0)) {
+           ruleset_addrule($ruleset, $tapchain, "-s ! $macaddr", '-j DROP');
+    }
+
+    if (@$arpfilter){
+       my $arpchain = $tapchain."-ARP";
+       ruleset_addrule($ruleset, $tapchain, "-p ARP", "-j $arpchain");
+       ruleset_create_chain($ruleset, $arpchain);
+
+       foreach my $ip (@{$arpfilter}) {
+           ruleset_addrule($ruleset, $arpchain, "-p ARP --arp-ip-src $ip", '-j RETURN');
+       }
+       ruleset_addrule($ruleset, $arpchain, '', '-j DROP');
+    }
+
+    if (defined($options->{layer2_protocols})){
+       my $protochain = $tapchain."-PROTO";
+       ruleset_addrule($ruleset, $tapchain, '', "-j $protochain");
+       ruleset_create_chain($ruleset, $protochain);
+
+       foreach my $proto (split(/,/, $options->{layer2_protocols})) {
+           ruleset_addrule($ruleset, $protochain, "-p $proto", '-j RETURN');
+       }
+       ruleset_addrule($ruleset, $protochain, '', '-j DROP');
+    }
+
+    ruleset_addrule($ruleset, $tapchain, '', '-j ACCEPT');
+
+    ruleset_addrule($ruleset, 'PVEFW-FWBR-OUT', "-i $iface", "-j $tapchain");
+}
+
+# the parameter $change_only_regex changes two things if defined:
+# * all chains not matching it will be left intact
+# * 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) = @_;
+    my ($ruleset, $active_chains, $digest_fn, $verbose, $change_only_regex) = @_;
 
     my $statushash = {};
 
     foreach my $chain (sort keys %$ruleset) {
-       my $sig = &$digest_fn($ruleset->{$chain});
+       my $rules = $ruleset->{$chain};
+       my $sig = &$digest_fn($rules);
+       my $oldsig;
 
        $statushash->{$chain}->{sig} = $sig;
-
-       my $oldsig = $active_chains->{$chain};
+       if (defined($change_only_regex)) {
+           $oldsig = $active_chains->{$chain}->{sig};
+           $statushash->{$chain}->{rules} = $rules;
+       } else {
+           $oldsig = $active_chains->{$chain};
+       }
        if (!defined($oldsig)) {
            $statushash->{$chain}->{action} = 'create';
        } else {
@@ -3614,19 +3815,26 @@ sub get_ruleset_status {
                $statushash->{$chain}->{action} = 'update';
            }
        }
-       print "$statushash->{$chain}->{action} $chain ($sig)\n" if $verbose;
-       foreach my $cmd (@{$ruleset->{$chain}}) {
-           print "\t$cmd\n" if $verbose;
+       if ($verbose) {
+           print "$statushash->{$chain}->{action} $chain ($sig)\n";
+           foreach my $cmd (@{$rules}) {
+               print "\t$cmd\n";
+           }
        }
     }
 
     foreach my $chain (sort keys %$active_chains) {
-       if (!defined($ruleset->{$chain})) {
-           my $sig = $active_chains->{$chain};
-           $statushash->{$chain}->{action} = 'delete';
-           $statushash->{$chain}->{sig} = $sig;
-           print "delete $chain ($sig)\n" if $verbose;
+       next if defined($ruleset->{$chain});
+       my $action = 'delete';
+       my $sig = $active_chains->{$chain};
+       if (defined($change_only_regex)) {
+           $action = 'ignore' if ($chain !~ m/$change_only_regex/);
+           $statushash->{$chain}->{rules} = $active_chains->{$chain}->{rules};
+           $sig = $sig->{sig};
        }
+       $statushash->{$chain}->{action} = $action;
+       $statushash->{$chain}->{sig} = $sig;
+       print "$action $chain ($sig)\n" if $verbose;
     }
 
     return $statushash;
@@ -3701,6 +3909,46 @@ sub get_ruleset_cmdlist {
     return wantarray ? ($cmdlist, $changes) : $cmdlist;
 }
 
+my $pve_ebtables_chainname_regex = qr/PVEFW-\S+|(?:tap|veth)\d+i\d+-(?:IN|OUT)/;
+
+sub get_ebtables_cmdlist {
+    my ($ruleset, $verbose) = @_;
+
+    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,
+                                       $pve_ebtables_chainname_regex);
+
+    # create chains first and make sure PVE rules are evaluated if active
+    my $append_pve_to_forward = '-A FORWARD -j PVEFW-FORWARD';
+    my $pve_include = 0;
+    foreach my $chain (sort keys %$statushash) {
+       next if ($statushash->{$chain}->{action} eq 'delete');
+       $cmdlist .= ":$chain ACCEPT\n";
+       $pve_include = 1 if ($chain eq 'PVEFW-FORWARD');
+    }
+
+    foreach my $chain (sort keys %$statushash) {
+       my $stat = $statushash->{$chain};
+       next if ($stat->{action} eq 'delete');
+       $changes = 1 if ($stat->{action} !~ 'ignore|exists');
+
+       foreach my $cmd (@{$statushash->{$chain}->{'rules'}}) {
+           if ($chain eq 'FORWARD' && $cmd eq $append_pve_to_forward) {
+               next if ! $pve_include;
+               $pve_include = 0;
+           }
+           $cmdlist .= "$cmd\n";
+       }
+    }
+    $cmdlist .= "$append_pve_to_forward\n" if $pve_include;
+
+    return wantarray ? ($cmdlist, $changes) : $cmdlist;
+}
+
 sub get_ipset_cmdlist {
     my ($ruleset, $verbose) = @_;
 
@@ -3760,7 +4008,7 @@ sub get_ipset_cmdlist {
 }
 
 sub apply_ruleset {
-    my ($ruleset, $hostfw_conf, $ipset_ruleset, $rulesetv6, $verbose) = @_;
+    my ($ruleset, $hostfw_conf, $ipset_ruleset, $rulesetv6, $ebtables_ruleset, $verbose) = @_;
 
     enable_bridge_firewall();
 
@@ -3769,6 +4017,7 @@ sub apply_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);
 
     if ($verbose) {
        if ($ipset_changes) {
@@ -3786,6 +4035,11 @@ sub apply_ruleset {
            print "ip6tables changes:\n";
            print $cmdlistv6;
        }
+
+       if ($ebtables_changes) {
+           print "ebtables changes:\n";
+           print $ebtables_cmdlist;
+       }
     }
 
     my $tmpfile = "$pve_fw_status_dir/ipsetcmdlist1";
@@ -3808,6 +4062,11 @@ sub apply_ruleset {
 
     ipset_restore_cmdlist($ipset_delete_cmdlist) if $ipset_delete_cmdlist;
 
+    ebtables_restore_cmdlist($ebtables_cmdlist);
+
+    $tmpfile = "$pve_fw_status_dir/ebtablescmdlist";
+    PVE::Tools::file_set_contents($tmpfile, $ebtables_cmdlist || '');
+
     # 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);
@@ -3832,12 +4091,26 @@ 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);
+
+    foreach my $chain (sort keys %$ebtables_ruleset) {
+       my $stat = $ebtables_statushash->{$chain};
+       if ($stat->{action} ne 'exists') {
+           warn "ebtables : unable to update chain '$chain'\n";
+           $errors = 1;
+       }
+    }
+
     die "unable to apply firewall changes\n" if $errors;
 
     update_nf_conntrack_max($hostfw_conf);
 
     update_nf_conntrack_tcp_timeout_established($hostfw_conf);
 
+    update_nf_conntrack_logging($hostfw_conf);
 }
 
 sub update_nf_conntrack_max {
@@ -3874,6 +4147,23 @@ sub update_nf_conntrack_tcp_timeout_established {
     PVE::ProcFSTools::write_proc_entry("/proc/sys/net/netfilter/nf_conntrack_tcp_timeout_established", $value);
 }
 
+my $log_nf_conntrack_enabled = undef;
+sub update_nf_conntrack_logging {
+    my ($hostfw_conf) = @_;
+
+    my $options = $hostfw_conf->{options} || {};
+    my $value = $options->{log_nf_conntrack} || 0;
+    if (!defined($log_nf_conntrack_enabled)
+       || $value != $log_nf_conntrack_enabled)
+    {
+       my $tmpfile = "$pve_fw_status_dir/log_nf_conntrack";
+       PVE::Tools::file_set_contents($tmpfile, $value);
+
+       PVE::Tools::run_command([qw(systemctl try-reload-or-restart pvefw-logger.service)]);
+       $log_nf_conntrack_enabled = $value;
+    }
+}
+
 sub remove_pvefw_chains {
 
     PVE::Firewall::remove_pvefw_chains_iptables("iptables");
@@ -3947,9 +4237,9 @@ sub update {
 
        my $hostfw_conf = load_hostfw_conf($cluster_conf);
 
-       my ($ruleset, $ipset_ruleset, $rulesetv6) = compile($cluster_conf, $hostfw_conf);
+       my ($ruleset, $ipset_ruleset, $rulesetv6, $ebtables_ruleset) = compile($cluster_conf, $hostfw_conf);
 
-       apply_ruleset($ruleset, $hostfw_conf, $ipset_ruleset, $rulesetv6);
+       apply_ruleset($ruleset, $hostfw_conf, $ipset_ruleset, $rulesetv6, $ebtables_ruleset);
     };
 
     run_locked($code);