X-Git-Url: https://git.proxmox.com/?p=qemu-server.git;a=blobdiff_plain;f=pve-bridge;h=64490b0a9b70278fc22e4a22c4c8007758457663;hp=2d826cfbda8f81a502aa96966a73c56a34d4e21e;hb=2254ffcf8792a9b29957594945c181d2f38c17e7;hpb=1e3baf05f2b5e795f99f5c4bb7bdb118c72b8b50 diff --git a/pve-bridge b/pve-bridge index 2d826cf..64490b0 100755 --- a/pve-bridge +++ b/pve-bridge @@ -1,11 +1,19 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl use strict; +use warnings; use PVE::QemuServer; use PVE::Tools qw(run_command); +use PVE::Network; my $iface = shift; +my $hotplug = 0; +if ($iface eq '--hotplug') { + $hotplug = 1; + $iface = shift; +} + die "no interface specified\n" if !$iface; die "got strange interface name '$iface'\n" @@ -14,55 +22,22 @@ die "got strange interface name '$iface'\n" my $vmid = $1; my $netid = "net$2"; -my $conf = PVE::QemuServer::load_config ($vmid); - -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; - -my $bridge = $net->{bridge}; -die "unable to get bridge setting\n" if !$bridge; +my $migratedfrom = $hotplug ? undef : $ENV{PVE_MIGRATED_FROM}; -system ("/sbin/ifconfig $iface 0.0.0.0 promisc up") == 0 || - die "interface activation failed\n"; +my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom); -if ($net->{rate}) { +my $netconf = $conf->{$netid}; - my $rate = int($net->{rate}*1024*1024); - my $burst = 1024*1024; - - system("/sbin/tc qdisc del dev $iface ingres >/dev/null 2>&1"); - system("/sbin/tc qdisc del dev $iface root >/dev/null 2>&1"); - - run_command("/sbin/tc qdisc add dev $iface handle ffff: ingress"); - - # this does not work wit virtio - don't know why - #run_command("/sbin/tc filter add dev $iface parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate ${rate}bps burst ${burst}b drop flowid :1"); - # so we use avrate instead - run_command("/sbin/tc filter add dev $iface parent ffff: " . - "protocol ip prio 50 estimator 1sec 8sec " . - "u32 match ip src 0.0.0.0/0 police avrate ${rate}bps drop flowid :1"); - - # tbf does not work for unknown reason - #$TC qdisc add dev $DEV root tbf rate $RATE latency 100ms burst $BURST - # so we use htb instead - run_command("/sbin/tc qdisc add dev $iface root handle 1: htb default 1"); - run_command("/sbin/tc class add dev $iface parent 1: classid 1:1 " . - "htb rate ${rate}bps burst ${burst}b"); +$netconf = $conf->{pending}->{$netid} if !$migratedfrom && defined($conf->{pending}->{$netid}); + +die "unable to get network config '$netid'\n" + if !defined($netconf); - # enable this to debug tc - if (0) { - print "DEBUG tc settings\n"; - system("/sbin/tc qdisc ls dev $iface"); - system("/sbin/tc class ls dev $iface"); - system("/sbin/tc filter ls dev $iface parent ffff:"); - } +my $net = PVE::QemuServer::parse_net($netconf); +die "unable to parse network config '$netid'\n" if !$net; -} +PVE::Network::tap_create($iface, $net->{bridge}); -system ("/usr/sbin/brctl addif $bridge $iface") == 0 || - die "can't add interface to bridge\n"; +PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{rate}); exit 0;