]>
Commit | Line | Data |
---|---|---|
990fc5e2 | 1 | #!/usr/bin/perl |
1e3baf05 DM |
2 | |
3 | use strict; | |
990fc5e2 | 4 | use warnings; |
28e129cc | 5 | |
1e3baf05 DM |
6 | use PVE::QemuServer; |
7 | use PVE::Tools qw(run_command); | |
9f03d50d | 8 | use PVE::Network; |
29728dbf | 9 | use PVE::Firewall; |
1e3baf05 | 10 | |
28e129cc AD |
11 | my $have_sdn; |
12 | eval { | |
13 | require PVE::Network::SDN::Zones; | |
6a6b668c | 14 | require PVE::Network::SDN::Vnets; |
28e129cc AD |
15 | $have_sdn = 1; |
16 | }; | |
17 | ||
1e3baf05 DM |
18 | my $iface = shift; |
19 | ||
50669ed5 WB |
20 | my $hotplug = 0; |
21 | if ($iface eq '--hotplug') { | |
22 | $hotplug = 1; | |
23 | $iface = shift; | |
24 | } | |
25 | ||
1e3baf05 DM |
26 | die "no interface specified\n" if !$iface; |
27 | ||
28 | die "got strange interface name '$iface'\n" | |
29 | if $iface !~ m/^tap(\d+)i(\d+)$/; | |
30 | ||
31 | my $vmid = $1; | |
32 | my $netid = "net$2"; | |
33 | ||
50669ed5 | 34 | my $migratedfrom = $hotplug ? undef : $ENV{PVE_MIGRATED_FROM}; |
d691e6d3 | 35 | |
ffda963f | 36 | my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom); |
1e3baf05 | 37 | |
3eec5767 DM |
38 | my $netconf = $conf->{$netid}; |
39 | ||
40 | $netconf = $conf->{pending}->{$netid} if !$migratedfrom && defined($conf->{pending}->{$netid}); | |
0b034c15 | 41 | |
1e3baf05 | 42 | die "unable to get network config '$netid'\n" |
3eec5767 | 43 | if !defined($netconf); |
1e3baf05 | 44 | |
3eec5767 | 45 | my $net = PVE::QemuServer::parse_net($netconf); |
1e3baf05 DM |
46 | die "unable to parse network config '$netid'\n" if !$net; |
47 | ||
29728dbf SH |
48 | # The nftable-based implementation from the newer proxmox-firewall does not requires FW bridges |
49 | my $create_firewall_bridges = $net->{firewall} && !PVE::Firewall::is_nftables(); | |
50 | ||
28e129cc | 51 | if ($have_sdn) { |
0b034c15 | 52 | PVE::Network::SDN::Vnets::add_dhcp_mapping($net->{bridge}, $net->{macaddr}, $vmid, $conf->{name}); |
28e129cc | 53 | PVE::Network::SDN::Zones::tap_create($iface, $net->{bridge}); |
29728dbf | 54 | PVE::Network::SDN::Zones::tap_plug($iface, $net->{bridge}, $net->{tag}, $create_firewall_bridges, $net->{trunks}, $net->{rate}); |
28e129cc AD |
55 | } else { |
56 | PVE::Network::tap_create($iface, $net->{bridge}); | |
29728dbf | 57 | PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $create_firewall_bridges, $net->{trunks}, $net->{rate}); |
28e129cc | 58 | } |
a279a03d | 59 | |
1e3baf05 | 60 | exit 0; |