[pve-devel] [PATCH] add routed network mode
Dietmar Maurer
dietmar at proxmox.com
Mon Aug 26 13:43:34 CEST 2013
---
Makefile | 3 ++-
PVE/QemuServer.pm | 16 +++++++++++++---
pve-routed | 46 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 4 deletions(-)
create mode 100755 pve-routed
diff --git a/Makefile b/Makefile
index 94de359..dea6726 100644
--- a/Makefile
+++ b/Makefile
@@ -60,7 +60,7 @@ qmrestore.1.pod: qmrestore
vm.conf.5.pod: gen-vmconf-pod.pl PVE/QemuServer.pm
perl -I. ./gen-vmconf-pod.pl >$@
-PKGSOURCES=qm qm.1.gz qm.1.pod qmrestore qmrestore.1.pod qmrestore.1.gz qmextract sparsecp vmtar qemu.init.d qmupdate control vm.conf.5.pod vm.conf.5.gz
+PKGSOURCES=qm qm.1.gz qm.1.pod qmrestore qmrestore.1.pod qmrestore.1.gz qmextract sparsecp vmtar qemu.init.d qmupdate control vm.conf.5.pod vm.conf.5.gz pve-bridge pve-routed
.PHONY: install
install: ${PKGSOURCES}
@@ -79,6 +79,7 @@ install: ${PKGSOURCES}
install -D -m 0755 qmupdate ${DESTDIR}${VARLIBDIR}/qmupdate
install -D -m 0755 qemu.init.d ${DESTDIR}/etc/init.d/${PACKAGE}
install -m 0755 pve-bridge ${DESTDIR}${VARLIBDIR}/pve-bridge
+ install -m 0755 pve-routed ${DESTDIR}${VARLIBDIR}/pve-routed
install -s -m 0755 vmtar ${DESTDIR}${LIBDIR}
install -s -m 0755 sparsecp ${DESTDIR}${LIBDIR}
install -m 0755 qmextract ${DESTDIR}${LIBDIR}
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 4d90484..37817f9 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1180,7 +1180,9 @@ sub print_netdev_full {
my $vmname = $conf->{name} || "vm$vmid";
- if ($net->{bridge}) {
+ if ($net->{ip}) {
+ return "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/pve-routed$vhostparam";
+ } elsif ($net->{bridge}) {
return "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/pve-bridge$vhostparam";
} else {
return "type=user,id=$netid,hostname=$vmname";
@@ -1229,6 +1231,8 @@ sub parse_net {
$res->{rate} = $1;
} elsif ($kvp =~ m/^tag=(\d+)$/) {
$res->{tag} = $1;
+ } elsif ($kvp =~ m/^ip=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/) {
+ $res->{ip} = $1;
} else {
return undef;
}
@@ -1245,9 +1249,15 @@ sub print_net {
my $res = "$net->{model}";
$res .= "=$net->{macaddr}" if $net->{macaddr};
- $res .= ",bridge=$net->{bridge}" if $net->{bridge};
+
$res .= ",rate=$net->{rate}" if $net->{rate};
- $res .= ",tag=$net->{tag}" if $net->{tag};
+
+ if ($net->{ip}) {
+ $res .= ",ip=$net->{ip}";
+ } else {
+ $res .= ",bridge=$net->{bridge}" if $net->{bridge};
+ $res .= ",tag=$net->{tag}" if $net->{tag};
+ }
return $res;
}
diff --git a/pve-routed b/pve-routed
new file mode 100755
index 0000000..5d66291
--- /dev/null
+++ b/pve-routed
@@ -0,0 +1,46 @@
+#!/usr/bin/perl -w
+
+use strict;
+use PVE::QemuServer;
+use PVE::Tools qw(run_command);
+use PVE::Network;
+
+my $iface = shift;
+
+die "no interface specified\n" if !$iface;
+
+die "got strange interface name '$iface'\n"
+ if $iface !~ m/^tap(\d+)i(\d+)$/;
+
+my $vmid = $1;
+my $netid = "net$2";
+
+my $migratedfrom = $ENV{PVE_MIGRATED_FROM};
+
+my $conf = PVE::QemuServer::load_config($vmid, $migratedfrom);
+
+die "unable to get network config '$netid'\n"
+ if !$conf->{$netid};
+
+my $net = PVE::QemuServer::parse_net($conf->{$netid});
+die "unable to parse network config '$netid'\n" if !$net;
+
+die "missing ip address\n" if !$net->{ip};
+
+sub enable_proxyarp {
+ my ($ifname) = @_;
+
+ PVE::Tools::run_command("echo 1 > /proc/sys/net/ipv4/conf/$ifname/proxy_arp");
+}
+
+PVE::Tools::run_command("ifconfig $iface up");
+enable_proxyarp($iface);
+
+my $external_iface = 'vmbr0'; # fixme: autotetect?
+enable_proxyarp($iface);
+
+PVE::Tools::run_command("route add -net $net->{ip} netmask 255.255.255.255 dev $iface");
+
+PVE::Network::tap_rate_limit($iface, $net->{rate}) if $net->{rate};
+
+exit 0;
--
1.7.10.4
More information about the pve-devel
mailing list