]> git.proxmox.com Git - qemu-server.git/blob - vm-network-scripts/pve-bridge
bump version to 8.2.1
[qemu-server.git] / vm-network-scripts / pve-bridge
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use PVE::QemuServer;
7 use PVE::Tools qw(run_command);
8 use PVE::Network;
9
10 my $have_sdn;
11 eval {
12 require PVE::Network::SDN::Zones;
13 $have_sdn = 1;
14 };
15
16 my $iface = shift;
17
18 my $hotplug = 0;
19 if ($iface eq '--hotplug') {
20 $hotplug = 1;
21 $iface = shift;
22 }
23
24 die "no interface specified\n" if !$iface;
25
26 die "got strange interface name '$iface'\n"
27 if $iface !~ m/^tap(\d+)i(\d+)$/;
28
29 my $vmid = $1;
30 my $netid = "net$2";
31
32 my $migratedfrom = $hotplug ? undef : $ENV{PVE_MIGRATED_FROM};
33
34 my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
35
36 my $netconf = $conf->{$netid};
37
38 $netconf = $conf->{pending}->{$netid} if !$migratedfrom && defined($conf->{pending}->{$netid});
39
40 die "unable to get network config '$netid'\n"
41 if !defined($netconf);
42
43 my $net = PVE::QemuServer::parse_net($netconf);
44 die "unable to parse network config '$netid'\n" if !$net;
45
46 if ($have_sdn) {
47 PVE::Network::SDN::Zones::tap_create($iface, $net->{bridge});
48 PVE::Network::SDN::Zones::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{rate});
49 } else {
50 PVE::Network::tap_create($iface, $net->{bridge});
51 PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{rate});
52 }
53
54 exit 0;