<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="margin: 0px; font-size: 11px; font-family: Menlo;">Signed-off-by: Johannes Ernst <<a href="mailto:info@filemedia.de">info@filemedia.de</a>></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">---</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> data/PVE/Network.pm | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++---</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> 1 file changed, 78 insertions(+), 4 deletions(-)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"><br></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">diff --git a/data/PVE/Network.pm b/data/PVE/Network.pm</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">index 9ad34f1..7eeb0d2 100644</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">--- a/data/PVE/Network.pm</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+++ b/data/PVE/Network.pm</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">@@ -6,6 +6,7 @@ use PVE::Tools qw(run_command);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> use PVE::ProcFSTools;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> use PVE::INotify;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> use File::Basename;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+use PVE::Cluster;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"> <br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> # host network related utility functions</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"> <br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">@@ -74,10 +75,20 @@ sub tap_plug {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> eval {run_command("/usr/bin/ovs-vsctl del-port $iface", outfunc => sub {}, errfunc => sub {}) };</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"> <br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> if (-d "/sys/class/net/$bridge/bridge") {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">-<span class="Apple-tab-span" style="white-space: pre;"> </span>my $newbridge = activate_bridge_vlan($bridge, $tag);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">-<span class="Apple-tab-span" style="white-space: pre;"> </span>copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">-</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">-<span class="Apple-tab-span" style="white-space: pre;"> </span>system("/sbin/brctl addif $newbridge $iface") == 0 ||</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span># get config for virtual vmbr tag</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>my $datacenterconf = PVE::Cluster::cfs_read_file('datacenter.cfg');</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>#check if virtual vlan tag</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>if ($datacenterconf->{virtual_tagging}) {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span>my $newbridge = activate_bridge_vlan_virtual($bridge, $tag);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>} else {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>my $newbridge = activate_bridge_vlan($bridge, $tag);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>system("/sbin/brctl addif $newbridge $iface") == 0 ||</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> <span class="Apple-tab-span" style="white-space: pre;"> </span> die "can't add interface to bridge\n";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> } else {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> <span class="Apple-tab-span" style="white-space: pre;"> </span>my $cmd = "/usr/bin/ovs-vsctl add-port $bridge $iface";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">@@ -193,4 +204,67 @@ sub activate_bridge_vlan {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> return $bridgevlan;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"> <br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+sub activate_bridge_vlan_virtual {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ my ($bridge, $tag_param) = @_;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ die "bridge '$bridge' is not active\n" if ! -d "/sys/class/net/$bridge";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ return $bridge if !defined($tag_param); # no vlan, simply return</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ my $tag = int($tag_param);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ die "got strange vlan tag '$tag_param'\n" if $tag < 1 || $tag > 4094;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ my $bridgevlan = "${bridge}v$tag";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ my $dir = "/sys/class/net/$bridge/brif";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>#set the bridge as interface</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>my $iface = "$bridge";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>#vlan construct: bridge -> bridge.tag -> bridgevtag -> VM</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ my $ifacevlan = "${iface}.$tag";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ # create vlan on $iface is not already exist</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ if (! -d "/sys/class/net/$ifacevlan") {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>system("/sbin/vconfig add $iface $tag") == 0 ||</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span> die "can't add vlan tag $tag to interface $iface\n";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ # be sure to have the $ifacevlan up</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ system("/sbin/ip link set $ifacevlan up") == 0 ||</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ die "can't up interface $ifacevlan\n";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ # test if $vlaniface is already enslaved in another bridge</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ my $path= "/sys/class/net/$ifacevlan/brport/bridge";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ if (-l $path) {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ my $tbridge = basename(readlink($path));</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>if ($tbridge eq $bridgevlan) {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span> # already member of bridge - assume setup is already done</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span> return $bridgevlan;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>} else {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span> die "interface $ifacevlan already exist in bridge $tbridge\n";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ # add bridgevlan if it doesn't already exist</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ if (! -d "/sys/class/net/$bridgevlan") {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ system("/sbin/brctl addbr $bridgevlan") == 0 ||</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ die "can't add bridge $bridgevlan\n";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ #fixme: set other bridge flags</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ # be sure to have the bridge up</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ system("/sbin/ip link set $bridgevlan up") == 0 ||</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ die "can't up bridge $bridgevlan\n";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ # add $ifacevlan to the bridge</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ system("/sbin/brctl addif $bridgevlan $ifacevlan") == 0 ||</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+<span class="Apple-tab-span" style="white-space: pre;"> </span>die "can't add interface $ifacevlan to bridge $bridgevlan\n";</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ </div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+ return $bridgevlan;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+}</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">+</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;"> 1;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">-- </div><div style="margin: 0px; font-size: 11px; font-family: Menlo;">1.8.3.4 (Apple Git-47)</div><div><br></div></body></html>