]> git.proxmox.com Git - pve-container.git/blob - src/lxcnetaddbr
don't set proxy_arp and forwarding on lxc veths
[pve-container.git] / src / lxcnetaddbr
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use PVE::LXC;
7 use PVE::Tools qw(run_command);
8 use PVE::Network;
9 use PVE::ProcFSTools;
10
11 die "got unexpected argument count\n" if scalar(@ARGV) != 5;
12
13 my ($vmid, $arg2, $arg3, $type, $iface) = @ARGV;
14
15 die "got unexpected argument ($arg2 != net)\n" if $arg2 ne 'net';
16 die "got unexpected argument ($arg3 != up)\n" if $arg3 ne 'up';
17
18 die "got unexpected argument ($type != veth)\n" if $type ne 'veth';
19
20 die "got unexpected environment" if $vmid ne $ENV{LXC_NAME};
21
22 die "missing vmid parameter\n" if !$vmid;
23 die "missing iface parameter\n" if !$iface;
24
25 my $conf = PVE::LXC::load_config($vmid);
26
27 my $netconf;
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"};
31 }
32
33 die "unable to find network definition for interface '$iface'\n"
34 if !defined($netconf);
35
36 my $net = PVE::LXC::parse_lxc_network($netconf);
37
38 my $tag = $net->{tag};
39 my $firewall = $net->{firewall};
40 my $bridge = $net->{bridge};
41
42 die "missing bridge configuration" if !$bridge;
43
44 if (-d "/sys/class/net/$iface") {
45
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+)/;
50
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::Network::tap_plug($iface, $bridge, $tag, $firewall);
54 }
55
56 exit 0;