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