]> git.proxmox.com Git - pve-common.git/commitdiff
network: vlan-aware bridge: fix pvid when trunks is defined
authorAlexandre Derumier <aderumier@odiso.com>
Mon, 25 May 2020 11:05:08 +0000 (13:05 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 3 Jun 2020 12:38:17 +0000 (14:38 +0200)
Currently, when a trunks is defined, the vlan tag is not used
for pvid with vlan-aware bridge. (It's ok with ovs switch)

example:

net0: e1000=BA:90:68:B8:CF:F5,bridge=vmbr1,tag=2,trunks=2-11

before
------
tap100i0  2-11

after
-----
tap100i0  2 PVID Egress Untagged
 3-11

No regression for other configurations:

net0: e1000=BA:90:68:B8:CF:F5,bridge=vmbr1

before
------
tap100i0  1 PVID Egress Untagged
 2-4094

after
-----
tap100i0  1 PVID Egress Untagged
 2-4094

net0: e1000=BA:90:68:B8:CF:F5,bridge=vmbr1,tag=2

before
------
tap100i0  2 PVID Egress Untagged

after
-----
tap100i0  2 PVID Egress Untagged

net0: e1000=BA:90:68:B8:CF:F5,bridge=vmbr1,trunks=2-11

before
------
tap100i0  1 PVID Egress Untagged
 2-11

after
-----
tap100i0  1 PVID Egress Untagged
 2-11

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
src/PVE/Network.pm

index b5d3777cc4a5cef1016d5adbfc05a2be1841bc29..12536c7609e9cc58182e97e8672ccd00e12ade72 100644 (file)
@@ -216,26 +216,24 @@ my $bridge_add_interface = sub {
    my $vlan_aware = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering");
 
    if ($vlan_aware) {
    my $vlan_aware = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering");
 
    if ($vlan_aware) {
-       if ($tag) {
-           eval { run_command(['/sbin/bridge', 'vlan', 'del', 'dev', $iface, 'vid', '1-4094']) };
-           die "failed to remove default vlan tags of $iface - $@\n" if $@;
 
 
-           eval { run_command(['/sbin/bridge', 'vlan', 'add', 'dev', $iface, 'vid', $tag, 'pvid', 'untagged']) };
-           die "unable to add vlan $tag to interface $iface - $@\n" if $@;
-
-           warn "Caution: Setting VLAN ID 1 on a VLAN aware bridge may be dangerous\n" if $tag == 1;
-       } elsif (!$trunks) {
-           eval { run_command(['/sbin/bridge', 'vlan', 'add', 'dev', $iface, 'vid', '2-4094']) };
-           die "unable to add default vlan tags to interface $iface - $@\n" if $@;
-       }
-
-       if ($trunks) {
-           my @trunks_array = split /;/, $trunks;
-           foreach my $trunk (@trunks_array) {
-               eval { run_command(['/sbin/bridge', 'vlan', 'add', 'dev', $iface, 'vid', $trunk]) };
-               die "unable to add vlan $trunk to interface $iface - $@\n" if $@;
-           }
-       }
+        eval { run_command(['/sbin/bridge', 'vlan', 'del', 'dev', $iface, 'vid', '1-4094']) };
+        die "failed to remove default vlan tags of $iface - $@\n" if $@;
+
+        if ($trunks) {
+            my @trunks_array = split /;/, $trunks;
+            foreach my $trunk (@trunks_array) {
+                eval { run_command(['/sbin/bridge', 'vlan', 'add', 'dev', $iface, 'vid', $trunk]) };
+                die "unable to add vlan $trunk to interface $iface - $@\n" if $@;
+            }
+        } elsif (!$tag) {
+            eval { run_command(['/sbin/bridge', 'vlan', 'add', 'dev', $iface, 'vid', '2-4094']) };
+            die "unable to add default vlan tags to interface $iface - $@\n" if $@;
+        }
+
+        $tag = 1 if !$tag;
+        eval { run_command(['/sbin/bridge', 'vlan', 'add', 'dev', $iface, 'vid', $tag, 'pvid', 'untagged']) };
+        die "unable to add vlan $tag to interface $iface - $@\n" if $@;
    }
 };
 
    }
 };