public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-firewall 6/7] firewall: drop the traffic of guest network devices without MAC address
Date: Tue, 24 Nov 2026 18:57:16 +0100	[thread overview]
Message-ID: <20261124175718.512428-7-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261124175718.512428-1-s.hanreich@proxmox.com>

A guest network device can lack a MAC address, for example after a
manual edit of the config. qemu-server and pve-container then use a
random one, which the firewall cannot know.

With the MAC filter enabled, drop all traffic of such a device, as the
MAC filter drops the traffic from any MAC address that is not the one
of the device. So far, the rule was skipped without a MAC address.
Likewise, leave the link-local address out of the default IP filter,
which then drops traffic from link-local addresses of the device.

This changes nothing yet, as the parsers of the guest configs always
generate a MAC address so far.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 src/PVE/Firewall.pm | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm
index 93af383..053b289 100644
--- a/src/PVE/Firewall.pm
+++ b/src/PVE/Firewall.pm
@@ -2839,8 +2839,9 @@ sub ruleset_create_vm_chain {
     }
 
     if ($direction eq 'OUT') {
-        if (defined($macaddr) && !(defined($options->{macfilter}) && $options->{macfilter} == 0)) {
-            ruleset_addrule($ruleset, $chain, "-m mac ! --mac-source $macaddr", "-j DROP");
+        if (!(defined($options->{macfilter}) && $options->{macfilter} == 0)) {
+            my $match = defined($macaddr) ? "-m mac ! --mac-source $macaddr" : '';
+            ruleset_addrule($ruleset, $chain, $match, "-j DROP");
         }
         if ($ipversion == 6 && !$options->{radv}) {
             ruleset_addrule(
@@ -4817,10 +4818,9 @@ sub compile_ipsets {
                 }
 
                 my $macaddr = $net->{macaddr};
-                my $linklocal = mac_to_linklocal($macaddr);
-                $device_ips->{$netid} = [
-                    { cidr => $linklocal }, { cidr => 'fe80::/10', nomatch => 1 },
-                ];
+                my $set = $device_ips->{$netid} = [{ cidr => 'fe80::/10', nomatch => 1 }];
+                # without a MAC address, the filter drops traffic from link-local addresses
+                push @$set, { cidr => mac_to_linklocal($macaddr) } if defined($macaddr);
             }
 
             generate_ipset_chains(
@@ -4871,10 +4871,9 @@ sub compile_ipsets {
                 }
 
                 my $macaddr = $net->{hwaddr};
-                my $linklocal = mac_to_linklocal($macaddr);
-                my $set = $device_ips->{$netid} = [
-                    { cidr => $linklocal }, { cidr => 'fe80::/10', nomatch => 1 },
-                ];
+                my $set = $device_ips->{$netid} = [{ cidr => 'fe80::/10', nomatch => 1 }];
+                # without a MAC address, the filter drops traffic from link-local addresses
+                push @$set, { cidr => mac_to_linklocal($macaddr) } if defined($macaddr);
                 if (defined($net->{ip}) && $net->{ip} =~ m!^($IPV4RE)(?:/\d+)?\z!) {
                     my $address = $1;
                     pve_verify_ip_or_cidr($net->{ip});
@@ -5042,14 +5041,17 @@ sub generate_tap_layer2filter {
 
     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 (!(defined($options->{macfilter}) && $options->{macfilter} == 0)) {
+        if (defined($macaddr)) {
+            # ebtables remove zeros from mac pairs
+            $macaddr =~ s/0([0-9a-f])/$1/ig;
+            $macaddr = lc($macaddr);
+            ruleset_addrule($ruleset, $tapchain, "-s ! $macaddr", '-j DROP');
+        } else {
+            ruleset_addrule($ruleset, $tapchain, '', '-j DROP');
+        }
     }
 
     if (defined($arpfilter)) {
-- 
2.47.3





  parent reply	other threads:[~2026-11-24 17:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 17:57 [PATCH firewall/proxmox{-ve-rs,-firewall} 0/7] firewall: handle guest network devices without a MAC address Stefan Hanreich
2026-11-24 17:57 ` [PATCH proxmox-ve-rs 1/7] ve-config: guest: require the name of container network devices Stefan Hanreich
2026-11-24 17:57 ` [PATCH proxmox-ve-rs 2/7] ve-config: guest: default the type of container network devices to veth Stefan Hanreich
2026-11-24 17:57 ` [PATCH proxmox-ve-rs 3/7] ve-config: guest: accept network devices without a MAC address Stefan Hanreich
2026-11-24 17:57 ` [PATCH proxmox-firewall 4/7] firewall: guest: handle " Stefan Hanreich
2026-11-25  7:28   ` Arthur Bied-Charreton
2026-11-24 17:57 ` [PATCH proxmox-firewall 5/7] tests: add network devices without " Stefan Hanreich
2026-11-24 17:57 ` Stefan Hanreich [this message]
2026-11-24 17:57 ` [PATCH pve-firewall 7/7] firewall: do not generate MAC addresses for guest network devices Stefan Hanreich
2026-11-25  7:14 ` [PATCH firewall/proxmox{-ve-rs,-firewall} 0/7] firewall: handle guest network devices without a MAC address Arthur Bied-Charreton

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=20261124175718.512428-7-s.hanreich@proxmox.com \
    --to=s.hanreich@proxmox.com \
    --cc=pve-devel@lists.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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal