]> git.proxmox.com Git - pve-container.git/blob - src/lxcnetaddbr
d/control: bump versioned dependency for guest-common
[pve-container.git] / src / lxcnetaddbr
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 exit 0 if $ENV{LXC_NAME} && $ENV{LXC_NAME} !~ /^\d+$/;
7
8 use PVE::LXC;
9 use PVE::Tools qw(run_command);
10 use PVE::ProcFSTools;
11
12 die "got unexpected argument count\n" if scalar(@ARGV) != 5;
13
14 my ($vmid, $arg2, $arg3, $type, $iface) = @ARGV;
15
16 die "got unexpected argument ($arg2 != net)\n" if $arg2 ne 'net';
17 die "got unexpected argument ($arg3 != up)\n" if $arg3 ne 'up';
18
19 die "got unexpected argument ($type != veth)\n" if $type ne 'veth';
20
21 die "got unexpected environment" if $vmid ne $ENV{LXC_NAME};
22
23 die "missing vmid parameter\n" if !$vmid;
24 die "missing iface parameter\n" if !$iface;
25
26 my $conf = PVE::LXC::Config->load_config($vmid);
27
28 my $netconf;
29 if ($iface =~ m/^veth(\d+)i(\d+)$/) {
30 die "got unexpected interface name '$iface'\n" if $1 ne $vmid;
31 $netconf = $conf->{"net$2"};
32 }
33
34 die "unable to find network definition for interface '$iface'\n"
35 if !defined($netconf);
36
37 my $net = PVE::LXC::Config->parse_lxc_network($netconf);
38
39 my $bridge = $net->{bridge};
40 die "missing bridge configuration" if !$bridge;
41
42 if (-d "/sys/class/net/$iface") {
43
44 my $bridgemtu = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/mtu");
45 die "bridge '$bridge' does not exist\n" if !$bridgemtu;
46 #avoid insecure dependency;
47 ($bridgemtu) = $bridgemtu =~ /(\d+)/;
48
49 PVE::Tools::run_command("/sbin/ip link set dev $iface up mtu $bridgemtu");
50 PVE::Tools::run_command("/sbin/ip addr add 0.0.0.0/0 dev $iface");
51 PVE::LXC::net_tap_plug($iface, $net);
52 }
53
54 exit 0;