]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | exit 0 if $ENV{LXC_NAME} && $ENV{LXC_NAME} !~ /^\d+$/; | |
7 | ||
8 | use PVE::LXC; | |
9 | use PVE::Tools qw(run_command); | |
10 | use PVE::Network; | |
11 | use PVE::ProcFSTools; | |
12 | ||
13 | die "got unexpected argument count\n" if scalar(@ARGV) != 5; | |
14 | ||
15 | my ($vmid, $arg2, $arg3, $type, $iface) = @ARGV; | |
16 | ||
17 | die "got unexpected argument ($arg2 != net)\n" if $arg2 ne 'net'; | |
18 | die "got unexpected argument ($arg3 != up)\n" if $arg3 ne 'up'; | |
19 | ||
20 | die "got unexpected argument ($type != veth)\n" if $type ne 'veth'; | |
21 | ||
22 | die "got unexpected environment" if $vmid ne $ENV{LXC_NAME}; | |
23 | ||
24 | die "missing vmid parameter\n" if !$vmid; | |
25 | die "missing iface parameter\n" if !$iface; | |
26 | ||
27 | my $conf = PVE::LXC::load_config($vmid); | |
28 | ||
29 | my $netconf; | |
30 | if ($iface =~ m/^veth(\d+)i(\d+)$/) { | |
31 | die "got unexpected interface name '$iface'\n" if $1 ne $vmid; | |
32 | $netconf = $conf->{"net$2"}; | |
33 | } | |
34 | ||
35 | die "unable to find network definition for interface '$iface'\n" | |
36 | if !defined($netconf); | |
37 | ||
38 | my $net = PVE::LXC::parse_lxc_network($netconf); | |
39 | ||
40 | my $tag = $net->{tag}; | |
41 | my $firewall = $net->{firewall}; | |
42 | my $bridge = $net->{bridge}; | |
43 | my $trunks = $net->{trunks}; | |
44 | ||
45 | die "missing bridge configuration" if !$bridge; | |
46 | ||
47 | if (-d "/sys/class/net/$iface") { | |
48 | ||
49 | my $bridgemtu = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/mtu"); | |
50 | die "bridge '$bridge' does not exist\n" if !$bridgemtu; | |
51 | #avoid insecure dependency; | |
52 | ($bridgemtu) = $bridgemtu =~ /(\d+)/; | |
53 | ||
54 | PVE::Tools::run_command("/sbin/ip link set dev $iface up mtu $bridgemtu"); | |
55 | PVE::Tools::run_command("/sbin/ip addr add 0.0.0.0/0 dev $iface"); | |
56 | PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks); | |
57 | } | |
58 | ||
59 | exit 0; |