]>
git.proxmox.com Git - pve-container.git/blob - src/lxcnetaddbr
6 exit 0 if $ENV{LXC_NAME
} && $ENV{LXC_NAME
} !~ /^\d+$/;
9 use PVE
::Tools
qw(run_command);
14 require PVE
::Network
::SDN
::Zones
;
18 die "got unexpected argument count\n" if scalar(@ARGV) != 5;
20 my ($vmid, $arg2, $arg3, $type, $iface) = @ARGV;
22 die "got unexpected argument ($arg2 != net)\n" if $arg2 ne 'net';
23 die "got unexpected argument ($arg3 != up)\n" if $arg3 ne 'up';
25 die "got unexpected argument ($type != veth)\n" if $type ne 'veth';
27 die "got unexpected environment" if $vmid ne $ENV{LXC_NAME
};
29 die "missing vmid parameter\n" if !$vmid;
30 die "missing iface parameter\n" if !$iface;
32 my $conf = PVE
::LXC
::Config-
>load_config($vmid);
35 if ($iface =~ m/^veth(\d+)i(\d+)$/) {
36 die "got unexpected interface name '$iface'\n" if $1 ne $vmid;
37 $netconf = $conf->{"net$2"};
40 die "unable to find network definition for interface '$iface'\n"
41 if !defined($netconf);
43 my $net = PVE
::LXC
::Config-
>parse_lxc_network($netconf);
45 my $tag = $net->{tag
};
46 my $firewall = $net->{firewall
};
47 my $bridge = $net->{bridge
};
48 my $trunks = $net->{trunks
};
49 my $rate = $net->{rate
};
51 die "missing bridge configuration" if !$bridge;
53 if (-d
"/sys/class/net/$iface") {
56 ($bridge, undef) = PVE
::Network
::SDN
::Zones
::get_bridge_vlan
($bridge);
59 my $bridgemtu = PVE
::Tools
::file_read_firstline
("/sys/class/net/$bridge/mtu");
60 die "bridge '$bridge' does not exist\n" if !$bridgemtu;
61 #avoid insecure dependency;
62 ($bridgemtu) = $bridgemtu =~ /(\d+)/;
64 PVE
::Tools
::run_command
("/sbin/ip link set dev $iface up mtu $bridgemtu");
65 PVE
::Tools
::run_command
("/sbin/ip addr add 0.0.0.0/0 dev $iface");
68 PVE
::Network
::SDN
::Zones
::tap_plug
($iface, $net->{bridge
}, $tag, $firewall, $trunks, $rate);
70 PVE
::Network
::tap_plug
($iface, $bridge, $tag, $firewall, $trunks, $rate);