]>
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 | ||
18 | my $conf = PVE::QemuServer::load_config ($vmid); | |
19 | ||
20 | die "unable to get network config '$netid'\n" | |
21 | if !$conf->{$netid}; | |
22 | ||
23 | my $net = PVE::QemuServer::parse_net($conf->{$netid}); | |
24 | die "unable to parse network config '$netid'\n" if !$net; | |
25 | ||
26 | my $bridge = $net->{bridge}; | |
27 | die "unable to get bridge setting\n" if !$bridge; | |
28 | ||
29 | system ("/sbin/ifconfig $iface 0.0.0.0 promisc up") == 0 || | |
30 | die "interface activation failed\n"; | |
31 | ||
32 | if ($net->{rate}) { | |
33 | ||
9f03d50d | 34 | my $debug = 0; |
1e3baf05 DM |
35 | my $rate = int($net->{rate}*1024*1024); |
36 | my $burst = 1024*1024; | |
37 | ||
9f03d50d | 38 | PVE::Network::setup_tc_rate_limit($iface, $rate, $burst, $debug); |
3c720aea DA |
39 | } |
40 | ||
9f03d50d DM |
41 | my $newbridge = PVE::Network::activate_bridge_vlan($bridge, $net->{tag}); |
42 | PVE::Network::copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge; | |
3c720aea | 43 | |
9f03d50d | 44 | system ("/usr/sbin/brctl addif $newbridge $iface") == 0 || |
1e3baf05 DM |
45 | die "can't add interface to bridge\n"; |
46 | ||
47 | exit 0; |