]> git.proxmox.com Git - qemu-server.git/blob - pve-bridge
use new network setup code from PVE::Network (libpve-common-perl)
[qemu-server.git] / pve-bridge
1 #!/usr/bin/perl -w
2
3 use strict;
4 use PVE::QemuServer;
5 use PVE::Tools qw(run_command);
6 use PVE::Network;
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
34 my $debug = 0;
35 my $rate = int($net->{rate}*1024*1024);
36 my $burst = 1024*1024;
37
38 PVE::Network::setup_tc_rate_limit($iface, $rate, $burst, $debug);
39 }
40
41 my $newbridge = PVE::Network::activate_bridge_vlan($bridge, $net->{tag});
42 PVE::Network::copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;
43
44 system ("/usr/sbin/brctl addif $newbridge $iface") == 0 ||
45 die "can't add interface to bridge\n";
46
47 exit 0;