<div dir="ltr">Hi Dietmar,<div><br></div><div>Here goes an v2 with you requested changes. Just tested it on briefly by rebooting nodes and migrating a couple of VMs from/to the nodes with this new changes applied.</div><div>
<br></div><div><pre style="color:rgb(0,0,0);word-wrap:break-word;white-space:pre-wrap">diff --git a/data/PVE/Network.pm b/data/PVE/Network.pm
index 9ad34f1..2fbb715 100644
--- a/data/PVE/Network.pm
+++ b/data/PVE/Network.pm
@@ -122,36 +122,10 @@ sub copy_bridge_config {
}
}
-sub activate_bridge_vlan {
- my ($bridge, $tag_param) = @_;
-
- die "bridge '$bridge' is not active\n" if ! -d "/sys/class/net/$bridge";
-
- return $bridge if !defined($tag_param); # no vlan, simply return
-
- my $tag = int($tag_param);
-
- die "got strange vlan tag '$tag_param'\n" if $tag < 1 || $tag > 4094;
-
- my $bridgevlan = "${bridge}v$tag";
-
- my $dir = "/sys/class/net/$bridge/brif";
-
- #check if we have an only one ethX or bondX interface in the bridge
-
- my $iface;
- PVE::Tools::dir_glob_foreach($dir, '((eth|bond)\d+)', sub {
- my ($slave) = @_;
-
- die "more then one physical interfaces on bridge '$bridge'\n" if $iface;
- $iface = $slave;
-
- });
-
- die "no physical interface on bridge '$bridge'\n" if !$iface;
-
+sub activate_bridge_vlan_slave {
+ my ($bridgevlan, $iface, $tag) = @_;
my $ifacevlan = "${iface}.$tag";
-
+
# create vlan on $iface is not already exist
if (! -d "/sys/class/net/$ifacevlan") {
system("/sbin/vconfig add $iface $tag") == 0 ||
@@ -166,30 +140,57 @@ sub activate_bridge_vlan {
my $path= "/sys/class/net/$ifacevlan/brport/bridge";
if (-l $path) {
my $tbridge = basename(readlink($path));
- if ($tbridge eq $bridgevlan) {
- # already member of bridge - assume setup is already done
- return $bridgevlan;
- } else {
+ if ($tbridge ne $bridgevlan) {
die "interface $ifacevlan already exist in bridge $tbridge\n";
+ } else {
+ # Port already attached to bridge: do nothing.
+ return;
}
}
+ # add $ifacevlan to the bridge
+ system("/sbin/brctl addif $bridgevlan $ifacevlan") == 0 ||
+ die "can't add interface $ifacevlan to bridge $bridgevlan\n";
+}
+
+sub activate_bridge_vlan {
+ my ($bridge, $tag_param) = @_;
+
+ die "bridge '$bridge' is not active\n" if ! -d "/sys/class/net/$bridge";
+
+ return $bridge if !defined($tag_param); # no vlan, simply return
+
+ my $tag = int($tag_param);
+
+ die "got strange vlan tag '$tag_param'\n" if $tag < 1 || $tag > 4094;
+
+ my $bridgevlan = "${bridge}v$tag";
+
+ my @ifaces = ();
+ my $dir = "/sys/class/net/$bridge/brif";
+ PVE::Tools::dir_glob_foreach($dir, '((eth|bond)\d+)', sub {
+ push(@ifaces, $_[0]);
+ });
+
+ die "no physical interface on bridge '$bridge'\n" if $ifcount == 0;
+
# add bridgevlan if it doesn't already exist
if (! -d "/sys/class/net/$bridgevlan") {
system("/sbin/brctl addbr $bridgevlan") == 0 ||
die "can't add bridge $bridgevlan\n";
}
+ # for each physical interface (eth or bridge) bind them to bridge vlan
+ foreach my $iface (@ifaces) {
+ activate_bridge_vlan_slave($bridgevlan, $iface, $tag);
+ }
+
#fixme: set other bridge flags
# be sure to have the bridge up
system("/sbin/ip link set $bridgevlan up") == 0 ||
die "can't up bridge $bridgevlan\n";
-
- # add $ifacevlan to the bridge
- system("/sbin/brctl addif $bridgevlan $ifacevlan") == 0 ||
- die "can't add interface $ifacevlan to bridge $bridgevlan\n";
-
+
return $bridgevlan;
}
</pre></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 12, 2014 at 8:10 AM, Dietmar Maurer <span dir="ltr"><<a href="mailto:dietmar@proxmox.com" target="_blank">dietmar@proxmox.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">see comment below:<br>
<div><div class="h5"><br>
> +sub activate_bridge_vlan {<br>
> + my ($bridge, $tag_param) = @_;<br>
> +<br>
> + die "bridge '$bridge' is not active\n" if ! -d "/sys/class/net/$bridge";<br>
> +<br>
> + return $bridge if !defined($tag_param); # no vlan, simply return<br>
> +<br>
> + my $tag = int($tag_param);<br>
> +<br>
> + die "got strange vlan tag '$tag_param'\n" if $tag < 1 || $tag > 4094;<br>
> +<br>
> + my $bridgevlan = "${bridge}v$tag";<br>
> +<br>
> # add bridgevlan if it doesn't already exist<br>
> if (! -d "/sys/class/net/$bridgevlan") {<br>
> system("/sbin/brctl addbr $bridgevlan") == 0 ||<br>
> die "can't add bridge $bridgevlan\n";<br>
> }<br>
><br>
> + # for each physical interface (eth or bridge) bind them to bridge vlan<br>
> + my $ifcount = 0;<br>
> + my $dir = "/sys/class/net/$bridge/brif";<br>
> + PVE::Tools::dir_glob_foreach($dir, '((eth|bond)\d+)', sub {<br>
> + my ($slave) = @_;<br>
> + activate_bridge_vlan_slave($bridgevlan, $slave, $tag);<br>
> + $ifcount++;<br>
> + });<br>
> +<br>
> + die "no physical interface on bridge '$bridge'\n" if $ifcount == 0;<br>
> +<br>
<br>
</div></div>This check should be done before we create the vlan bridge.<br>
<div class="HOEnZb"><div class="h5"><br>
> #fixme: set other bridge flags<br>
><br>
> # be sure to have the bridge up<br>
> system("/sbin/ip link set $bridgevlan up") == 0 ||<br>
> die "can't up bridge $bridgevlan\n";<br>
> -<br>
> - # add $ifacevlan to the bridge<br>
> - system("/sbin/brctl addif $bridgevlan $ifacevlan") == 0 ||<br>
> - die "can't add interface $ifacevlan to bridge $bridgevlan\n";<br>
> -<br>
> +<br>
> return $bridgevlan;<br>
> }<br>
<br>
</div></div></blockquote></div><br></div>