[pve-devel] [PATCH] "netargsN" parameter is added in vm.conf

Igor Perminov igor.perminov at inbox.ru
Fri Nov 9 11:40:11 CET 2012


It would be useful to have a possibility to pass arbitrary extra parameters to KVM
for a network device in "-netdev" option via vm.conf. This patch adds new parameter
"netargsN" to do that, where N is 0, 1, etc, the same as for "netN".

For example, to specify port forwarding in KVM's user mode networking ("NAT" mode
in Proxmox VE) you can write in vmXXX.conf:

net0: rtl8139=D2:12:3F:91:78:3A
netargs0: hostfwd=tcp::2222-:22,hostfwd=tcp::2280-:80


Signed-off-by: Igor Perminov <igor.perminov at inbox.ru>
---
 PVE/QemuServer.pm |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 1fc144f..6208d5e 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -473,8 +473,20 @@ EODESCR
 };
 PVE::JSONSchema::register_standard_option("pve-qm-net", $netdesc);
 
+my $netargsdesc = {
+    optional => 1,
+    type => 'string',
+    description => <<EODESCR,
+Note: this option is for experts only. It allows you to pass arbitrary extra parameters for the network device, for example:
+
+netargs0: hostfwd=tcp:10.1.1.1:2222-:22
+EODESCR
+};
+PVE::JSONSchema::register_standard_option("pve-qm-netargs", $netargsdesc);
+
 for (my $i = 0; $i < $MAX_NETS; $i++)  {
     $confdesc->{"net$i"} = $netdesc;
+    $confdesc->{"netargs$i"} = $netargsdesc;
 }
 
 my $drivename_hash;
@@ -1146,10 +1158,15 @@ sub print_netdev_full {
 
     my $vmname = $conf->{name} || "vm$vmid";
 
+    my $netargs = $conf->{"netargs$i"};
+
+    my $xnetargs = "";
+    $xnetargs = "," . "$netargs" if $netargs;
+
     if ($net->{bridge}) {
-        return "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/pve-bridge$vhostparam";
+        return "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/pve-bridge$vhostparam$xnetargs";
     } else {
-        return "type=user,id=$netid,hostname=$vmname";
+        return "type=user,id=$netid,hostname=$vmname$xnetargs";
     }
 }
 
-- 
1.7.0.4






More information about the pve-devel mailing list