]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/Network.pm
extract PVE::Format from PVE::CLIFormatter for reuse
[pve-common.git] / src / PVE / Network.pm
index ac49536c27646602c0e60f239beb1dfecf567940..12536c7609e9cc58182e97e8672ccd00e12ade72 100644 (file)
@@ -115,7 +115,7 @@ sub tap_rate_limit {
     setup_tc_rate_limit($iface, $rate, $burst);
 }
 
-my $read_bridge_mtu = sub {
+sub read_bridge_mtu {
     my ($bridge) = @_;
 
     my $mtu = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/mtu");
@@ -216,27 +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) {
-       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;
-       } else {
-           eval { run_command(['/sbin/bridge', 'vlan', 'add', 'dev', $iface, 'vid', '2-4094']) };
-           die "unable to add default vlan tags to interface $iface - $@\n"
-               if $@ && !$trunks;
-       }
-
-       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 $@;
    }
 };
 
@@ -275,7 +272,7 @@ sub tap_create {
 
     die "unable to get bridge setting\n" if !$bridge;
 
-    my $bridgemtu = &$read_bridge_mtu($bridge);
+    my $bridgemtu = read_bridge_mtu($bridge);
 
     eval {
        disable_ipv6($iface);
@@ -289,7 +286,7 @@ sub veth_create {
 
     die "unable to get bridge setting\n" if !$bridge;
 
-    my $bridgemtu = &$read_bridge_mtu($bridge);
+    my $bridgemtu = read_bridge_mtu($bridge);
 
     # create veth pair
     if (! -d "/sys/class/net/$veth") {
@@ -347,7 +344,7 @@ my $create_firewall_bridge_ovs = sub {
     my ($vmid, $devid) = &$parse_tap_device_name($iface);
     my ($fwbr, undef, undef, $ovsintport) = &$compute_fwbr_names($vmid, $devid);
 
-    my $bridgemtu = &$read_bridge_mtu($bridge);
+    my $bridgemtu = read_bridge_mtu($bridge);
 
     &$cond_create_bridge($fwbr);
     &$activate_interface($fwbr);