]>
git.proxmox.com Git - pve-container.git/blob - src/lxcnetaddbr
7 use PVE
::Tools
qw(run_command);
11 die "got unexpected argument count\n" if scalar(@ARGV) != 5;
13 my ($vmid, $arg2, $arg3, $type, $iface) = @ARGV;
15 die "got unexpected argument ($arg2 != net)\n" if $arg2 ne 'net';
16 die "got unexpected argument ($arg3 != up)\n" if $arg3 ne 'up';
18 die "got unexpected argument ($type != veth)\n" if $type ne 'veth';
20 die "got unexpected environment" if $vmid ne $ENV{LXC_NAME
};
22 die "missing vmid parameter\n" if !$vmid;
23 die "missing iface parameter\n" if !$iface;
25 my $conf = PVE
::LXC
::load_config
($vmid);
28 if ($iface =~ m/^veth(\d+)i(\d+)$/) {
29 die "got unexpected interface name '$iface'\n" if $1 ne $vmid;
30 $netconf = $conf->{"net$2"};
33 die "unable to find network definition for interface '$iface'\n"
34 if !defined($netconf);
36 my $net = PVE
::LXC
::parse_lxc_network
($netconf);
38 my $tag = $net->{tag
};
39 my $firewall = $net->{firewall
};
40 my $bridge = $net->{bridge
};
42 die "missing bridge configuration" if !$bridge;
44 if (-d
"/sys/class/net/$iface") {
46 my $bridgemtu = PVE
::Tools
::file_read_firstline
("/sys/class/net/$bridge/mtu");
47 die "bridge '$bridge' does not exist\n" if !$bridgemtu;
48 #avoid insecure dependency;
49 ($bridgemtu) = $bridgemtu =~ /(\d+)/;
51 PVE
::Tools
::run_command
("/sbin/ip link set dev $iface up mtu $bridgemtu");
52 PVE
::Tools
::run_command
("/sbin/ip addr add 0.0.0.0/0 dev $iface");
53 PVE
::ProcFSTools
::write_proc_entry
("/proc/sys/net/ipv4/conf/$iface/proxy_arp", "1");
54 PVE
::ProcFSTools
::write_proc_entry
("/proc/sys/net/ipv4/conf/$iface/forwarding", "1");
55 PVE
::Network
::tap_plug
($iface, $bridge, $tag, $firewall);