]>
Commit | Line | Data |
---|---|---|
7fe1577d AD |
1 | #!/usr/bin/perl |
2 | use strict; | |
3 | use warnings; | |
4 | use PVE::OpenVZ; | |
5 | use PVE::Tools qw(run_command); | |
6 | use PVE::Network; | |
7 | use PVE::ProcFSTools; | |
8 | ||
9 | my $vmid = $ENV{VEID}; | |
10 | die "missing vmid parameter" if !$vmid; | |
11 | ||
12 | my $iface = $ARGV[2]; | |
13 | die "missing iface parameter" if !$iface; | |
14 | ||
15 | my $bridgevlanf = $ARGV[3]; | |
16 | die "missing bridge parameter" if !$bridgevlanf; | |
17 | ||
18 | my $conf = PVE::OpenVZ::load_config($vmid); | |
19 | ||
20 | my $ifaces = {}; | |
21 | if (defined ($conf->{netif}) && $conf->{netif}->{value}) { | |
22 | $ifaces = PVE::OpenVZ::parse_netif($conf->{netif}->{value}, $vmid); | |
23 | } | |
24 | ||
25 | my $oldbridgevlanf = undef; | |
26 | ||
27 | #read oldbridge value | |
28 | foreach my $ifname (sort keys %$ifaces) { | |
29 | ||
30 | if($ifaces->{$ifname}->{host_ifname} eq $iface){ | |
31 | $oldbridgevlanf = $ifaces->{$ifname}->{bridge}; | |
32 | ||
33 | } | |
34 | } | |
35 | ||
36 | my $tag = undef; | |
37 | my $firewall = undef; | |
38 | my $bridge = undef; | |
39 | ||
40 | if($bridgevlanf =~ m/(vmbr(\d+))(v(\d+))?(f)?/){ | |
41 | $bridge = $1; | |
42 | $tag = $4 if $4; | |
43 | $firewall = $5 if $5; | |
44 | } | |
45 | ||
46 | die "missing bridge parameter" if !$bridge; | |
47 | ||
48 | ||
49 | if($bridgevlanf ne $oldbridgevlanf){ | |
50 | ||
51 | PVE::Network::tap_unplug($iface); | |
52 | } | |
53 | ||
54 | if (-d "/sys/class/net/$iface") { | |
55 | ||
56 | my $bridgemtu = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/mtu"); | |
57 | die "bridge '$bridge' does not exist\n" if !$bridgemtu; | |
58 | #avoid insecure dependency; | |
59 | ($bridgemtu) = $bridgemtu =~ /(\d+)/; | |
60 | ||
61 | PVE::Tools::run_command("/sbin/ip link set dev $iface up mtu $bridgemtu"); | |
62 | PVE::Tools::run_command("/sbin/ip addr add 0.0.0.0/0 dev $iface"); | |
63 | PVE::ProcFSTools::write_proc_entry("/proc/sys/net/ipv4/conf/$iface/proxy_arp", "1"); | |
64 | PVE::ProcFSTools::write_proc_entry("/proc/sys/net/ipv4/conf/$iface/forwarding", "1"); | |
65 | PVE::Network::tap_plug($iface, $bridge, $tag, $firewall); | |
66 | ||
67 | } | |
68 | ||
69 | exit 0; |