]>
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);
15 require PVE
::Network
::SDN
::Zones
;
19 die "got unexpected argument count\n" if scalar(@ARGV) != 5;
21 my ($vmid, $arg2, $arg3, $type, $iface) = @ARGV;
23 die "got unexpected argument ($arg2 != net)\n" if $arg2 ne 'net';
24 die "got unexpected argument ($arg3 != up)\n" if $arg3 ne 'up';
26 die "got unexpected argument ($type != veth)\n" if $type ne 'veth';
28 die "got unexpected environment" if $vmid ne $ENV{LXC_NAME
};
30 die "missing vmid parameter\n" if !$vmid;
31 die "missing iface parameter\n" if !$iface;
33 my $conf = PVE
::LXC
::Config-
>load_config($vmid);
36 if ($iface =~ m/^veth(\d+)i(\d+)$/) {
37 die "got unexpected interface name '$iface'\n" if $1 ne $vmid;
38 $netconf = $conf->{"net$2"};
41 die "unable to find network definition for interface '$iface'\n"
42 if !defined($netconf);
44 my $net = PVE
::LXC
::Config-
>parse_lxc_network($netconf);
46 my $tag = $net->{tag
};
47 my $firewall = $net->{firewall
};
48 my $bridge = $net->{bridge
};
49 my $trunks = $net->{trunks
};
50 my $rate = $net->{rate
};
52 die "missing bridge configuration" if !$bridge;
54 if (-d
"/sys/class/net/$iface") {
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+)/;
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");
65 PVE
::Network
::SDN
::Zones
::tap_plug
($iface, $bridge, $tag, $firewall, $trunks, $rate);
66 PVE
::Network
::SDN
::Zones
::add_bridge_fdb
($iface, $net->{hwaddr
}, $bridge, $firewall);
68 PVE
::Network
::tap_plug
($iface, $bridge, $tag, $firewall, $trunks, $rate, { mac
=> $net->{hwaddr
}});