]>
Commit | Line | Data |
---|---|---|
1e3baf05 DM |
1 | #!/usr/bin/perl -w |
2 | ||
3 | use strict; | |
4 | use PVE::QemuServer; | |
5 | use PVE::Tools qw(run_command); | |
9f03d50d | 6 | use PVE::Network; |
1e3baf05 DM |
7 | |
8 | my $iface = shift; | |
9 | ||
10 | die "no interface specified\n" if !$iface; | |
11 | ||
12 | die "got strange interface name '$iface'\n" | |
13 | if $iface !~ m/^tap(\d+)i(\d+)$/; | |
14 | ||
15 | my $vmid = $1; | |
16 | my $netid = "net$2"; | |
17 | ||
d691e6d3 DM |
18 | my $migratedfrom = $ENV{PVE_MIGRATED_FROM}; |
19 | ||
20 | my $conf = PVE::QemuServer::load_config($vmid, $migratedfrom); | |
1e3baf05 DM |
21 | |
22 | die "unable to get network config '$netid'\n" | |
23 | if !$conf->{$netid}; | |
24 | ||
25 | my $net = PVE::QemuServer::parse_net($conf->{$netid}); | |
26 | die "unable to parse network config '$netid'\n" if !$net; | |
27 | ||
28 | my $bridge = $net->{bridge}; | |
29 | die "unable to get bridge setting\n" if !$bridge; | |
30 | ||
ff166084 | 31 | my $bridgemtu = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/mtu"); |
8afd0c62 | 32 | die "bridge '$bridge' does not exist\n" if !$bridgemtu; |
ff166084 AD |
33 | |
34 | system ("/sbin/ifconfig $iface 0.0.0.0 promisc up mtu $bridgemtu") == 0 || | |
1e3baf05 DM |
35 | die "interface activation failed\n"; |
36 | ||
37 | if ($net->{rate}) { | |
38 | ||
9f03d50d | 39 | my $debug = 0; |
1e3baf05 DM |
40 | my $rate = int($net->{rate}*1024*1024); |
41 | my $burst = 1024*1024; | |
42 | ||
9f03d50d | 43 | PVE::Network::setup_tc_rate_limit($iface, $rate, $burst, $debug); |
3c720aea DA |
44 | } |
45 | ||
9f03d50d DM |
46 | my $newbridge = PVE::Network::activate_bridge_vlan($bridge, $net->{tag}); |
47 | PVE::Network::copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge; | |
3c720aea | 48 | |
9f03d50d | 49 | system ("/usr/sbin/brctl addif $newbridge $iface") == 0 || |
1e3baf05 DM |
50 | die "can't add interface to bridge\n"; |
51 | ||
52 | exit 0; |