]> git.proxmox.com Git - vzctl.git/commitdiff
vznetaddbr perl version
authorAlexandre Derumier <aderumier@odiso.com>
Fri, 23 May 2014 13:11:37 +0000 (15:11 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 3 Jun 2014 04:27:18 +0000 (06:27 +0200)
this replace the default vznetaddbr script,
using perl code.

This allow to use vlan tag, firewall bridge and openvswitch bridge
like for qemu

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
debian/patches/fix-config-path.diff
debian/patches/series
debian/rules
debian/vznetaddbr [new file with mode: 0755]

index 8a17ad93c94c513cfb8af3274e3285f6bd185840..fa50f56f059c4a395c5f9f8bddd0e14bb1198f39 100644 (file)
@@ -24,19 +24,6 @@ Index: new/paths.am
  distconfdir = $(pkgconfdir)/dists
  namesdir    = $(pkgconfdir)/names
  
-Index: new/bin/vznetaddbr.in
-===================================================================
---- new.orig/bin/vznetaddbr.in 2012-09-28 09:05:45.000000000 +0200
-+++ new/bin/vznetaddbr.in      2012-09-28 09:39:27.000000000 +0200
-@@ -2,7 +2,7 @@
- #
- # Add virtual network interfaces (veth's) in a container to a bridge on CT0
--CONFIGFILE=@PKGCONFDIR@/conf/$VEID.conf
-+CONFIGFILE=@VPSCONFDIR@/$VEID.conf
- . $CONFIGFILE
- NETIFLIST=$(printf %s "$NETIF" |tr ';' '\n')
 Index: new/etc/init.d/vz-redhat.in
 ===================================================================
 --- new.orig/etc/init.d/vz-redhat.in   2012-09-28 09:05:45.000000000 +0200
index 1153d99b42a608cc40c30851c525e23e85c9cf18..9dab92cef4f7112fc53f7e6697432c702342a44e 100644 (file)
@@ -7,6 +7,6 @@ no-backup-on-destroy.diff
 fix-init.d-depends.diff
 allow-abs-ostemplate-path.diff
 always-create-dev-console.patch
-keep-bridge-MTU.patch
+#keep-bridge-MTU.patch
 fix-vzifup-post-error.patch
 pass-bridge-value-as-argument-to-VZNETCFG.patch
index 1a4bc81e69b1eebc1773f796654e0f2ace8fd14a..c9805fd7f2b9c013e8683d180dd4d527dbae4897 100644 (file)
@@ -95,6 +95,9 @@ install: build
        rm -rf $(CURDIR)/debian/vzctl/etc/vz/conf
        # we create the symlink to /etc/pve/openvz inside the preinst script
 
+       # install perl vznetaddbr version
+       install -m 644 $(CURDIR)/debian/vznetaddbr $(CURDIR)/debian/vzctl/usr/sbin/vznetaddbr
+
 
 
 # Build architecture-independent files here.
diff --git a/debian/vznetaddbr b/debian/vznetaddbr
new file mode 100755 (executable)
index 0000000..7c394a2
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use PVE::OpenVZ;
+use PVE::Tools qw(run_command);
+use PVE::Network;
+use PVE::ProcFSTools;
+
+my $vmid = $ENV{VEID};
+die "missing vmid parameter" if !$vmid;
+
+my $iface = $ARGV[2];
+die "missing iface parameter" if !$iface;
+
+my $bridgevlanf = $ARGV[3];
+die "missing bridge parameter" if !$bridgevlanf;
+
+my $conf = PVE::OpenVZ::load_config($vmid);
+
+my $ifaces = {};
+if (defined ($conf->{netif}) && $conf->{netif}->{value}) {
+       $ifaces = PVE::OpenVZ::parse_netif($conf->{netif}->{value}, $vmid);
+}
+
+my $oldbridgevlanf = undef;
+
+#read oldbridge value
+foreach my $ifname (sort keys %$ifaces) {
+
+    if($ifaces->{$ifname}->{host_ifname} eq $iface){
+       $oldbridgevlanf = $ifaces->{$ifname}->{bridge};
+
+    }
+}
+
+my $tag = undef;
+my $firewall = undef;
+my $bridge = undef;
+
+if($bridgevlanf =~ m/(vmbr(\d+))(v(\d+))?(f)?/){
+    $bridge = $1;
+    $tag = $4 if $4;
+    $firewall = $5 if $5;
+} 
+
+die "missing bridge parameter" if !$bridge;
+
+
+if($bridgevlanf ne $oldbridgevlanf){
+
+    PVE::Network::tap_unplug($iface);
+}
+
+if (-d "/sys/class/net/$iface") {
+
+    my $bridgemtu = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/mtu");
+    die "bridge '$bridge' does not exist\n" if !$bridgemtu;
+    #avoid insecure dependency;
+    ($bridgemtu) = $bridgemtu =~ /(\d+)/;
+
+    PVE::Tools::run_command("/sbin/ip link set dev $iface up mtu $bridgemtu");
+    PVE::Tools::run_command("/sbin/ip addr add 0.0.0.0/0 dev $iface");
+    PVE::ProcFSTools::write_proc_entry("/proc/sys/net/ipv4/conf/$iface/proxy_arp", "1");
+    PVE::ProcFSTools::write_proc_entry("/proc/sys/net/ipv4/conf/$iface/forwarding", "1");
+    PVE::Network::tap_plug($iface, $bridge, $tag, $firewall);
+
+}
+
+exit 0;