2011-08-23 07:47:04 +02:00
#!/usr/bin/perl -w
use strict;
use PVE::QemuServer;
use PVE::Tools qw(run_command);
2012-03-28 10:37:28 +02:00
use PVE::Network;
2011-08-23 07:47:04 +02:00
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";
2012-08-23 07:26:41 +02:00
my $migratedfrom = $ENV{PVE_MIGRATED_FROM};
my $conf = PVE::QemuServer::load_config($vmid, $migratedfrom);
2011-08-23 07:47:04 +02:00
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;
2012-09-28 10:58:26 +02:00
my $bridgemtu = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/mtu");
2012-12-06 07:56:11 +01:00
die "bridge '$bridge' does not exist\n" if !$bridgemtu;
2012-09-28 10:58:26 +02:00
system ("/sbin/ifconfig $iface 0.0.0.0 promisc up mtu $bridgemtu") == 0 ||
2011-08-23 07:47:04 +02:00
die "interface activation failed\n";
if ($net->{rate}) {
2012-03-28 10:37:28 +02:00
my $debug = 0;
2011-08-23 07:47:04 +02:00
my $rate = int($net->{rate}*1024*1024);
my $burst = 1024*1024;
2012-03-28 10:37:28 +02:00
PVE::Network::setup_tc_rate_limit($iface, $rate, $burst, $debug);
2012-03-19 09:39:21 +01:00
}
2012-03-28 10:37:28 +02:00
my $newbridge = PVE::Network::activate_bridge_vlan($bridge, $net->{tag});
PVE::Network::copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;
2012-03-19 09:39:21 +01:00
2012-03-28 10:37:28 +02:00
system ("/usr/sbin/brctl addif $newbridge $iface") == 0 ||
2011-08-23 07:47:04 +02:00
die "can't add interface to bridge\n";
exit 0;