]> git.proxmox.com Git - pve-container.git/blame - src/PVE/LXC/Setup/Alpine.pm
setup: fix alpine ipv6-slaac configuration
[pve-container.git] / src / PVE / LXC / Setup / Alpine.pm
CommitLineData
a8700492
JV
1package PVE::LXC::Setup::Alpine;
2
3use strict;
4use warnings;
5
a8700492
JV
6use PVE::LXC;
7use PVE::Network;
8use File::Path;
9
10use PVE::LXC::Setup::Base;
d93a2739 11use PVE::LXC::Setup::Debian;
a8700492
JV
12
13use base qw(PVE::LXC::Setup::Base);
14
15sub new {
16 my ($class, $conf, $rootdir) = @_;
b46d6081
WB
17
18 my $version = PVE::Tools::file_read_firstline("$rootdir/etc/alpine-release");
19
20 my $self = { conf => $conf, rootdir => $rootdir, version => $version };
a8700492
JV
21 $conf->{ostype} = "alpine";
22 return bless $self, $class;
23}
24
5e84bdc8
DM
25# Alpine doesn't support the /dev/lxc/ subdirectory.
26sub devttydir {
27 return '';
28}
29
a8700492
JV
30sub template_fixup {
31 my ($self, $conf) = @_;
855b0646 32
a8700492
JV
33 # enable networking service
34 $self->ct_symlink('/etc/init.d/networking',
35 '/etc/runlevels/boot/networking');
36 # fixup any symlinks
37 $self->ct_symlink('/etc/init.d/bootmisc',
38 '/etc/runlevels/boot/bootmisc');
39 $self->ct_symlink('/etc/init.d/hostname',
e9076752
WB
40 '/etc/runlevels/boot/hostname');
41 # fix stop system
a8700492 42 $self->ct_symlink('/etc/init.d/killprocs',
e9076752 43 '/etc/runlevels/shutdown/killprocs');
a8700492 44 $self->ct_symlink('/etc/init.d/savecache',
e9076752 45 '/etc/runlevels/shutdown/savecache');
6077b5dd 46
5e84bdc8 47 $self->setup_securetty($conf);
a8700492
JV
48}
49
50sub setup_init {
0c63baec
TL
51 my ($self, $conf) = @_;
52
53 my $filename = "/etc/inittab";
54 return if !$self->ct_file_exists($filename);
55
56 my $ttycount = PVE::LXC::Config->get_tty_count($conf);
57 my $inittab = $self->ct_file_get_contents($filename);
58
59 my @lines = grep {
60 # remove getty lines
f4cd6178 61 !/^\s*tty\d+:\d*:[^:]*:.*getty/
0c63baec
TL
62 } split(/\n/, $inittab);
63
64 $inittab = join("\n", @lines) . "\n";
65
66 for (my $id = 1; $id <= $ttycount; $id++) {
67 next if $id == 7; # reserved for X11
68 $inittab .= "tty$id\::respawn:/sbin/getty 38400 tty$id\n";
69 }
70
71 $self->ct_file_set_contents($filename, $inittab);
a8700492
JV
72}
73
74sub setup_network {
d93a2739
WB
75 # Network is debian compatible, but busybox' udhcpc6 is unfinished
76 my ($self, $conf) = @_;
77
78 # XXX: udhcpc6 in busybox is broken; once a working alpine release comes
79 # we can remove this bit.
80 #
81 # Filter out ipv6 dhcp and turn it into 'manual' so they see what's up.
c09b2996
SI
82 #
83 # XXX: slaac works different from debian - busybox has no 'auto'
84 # configuration type - https://wiki.alpinelinux.org/wiki/Configure_Networking#IPv6_Stateless_Autoconfiguration
85 # the suggested configuration sadly does not take the interface up, but
86 # at least with the workaround the networking starts and if an ipv4 is
87 # configured slaac for ipv6 works (unless accept_ra = 0 in the node)
88
d93a2739
WB
89 my $netconf = {};
90 my $networks = {};
91 foreach my $k (keys %$conf) {
92 next if $k !~ m/^net(\d+)$/;
93 my $netstring = $conf->{$k};
94 # check for dhcp6:
1b4cf758 95 my $d = PVE::LXC::Config->parse_lxc_network($netstring);
c09b2996 96 if (defined($d->{ip6}) && ($d->{ip6} eq 'dhcp' || $d->{ip6} eq 'auto')) {
d93a2739 97 $d->{ip6} = 'manual';
1b4cf758 98 $netstring = PVE::LXC::Config->print_lxc_network($d);
d93a2739
WB
99 }
100 $netconf->{$k} = $netstring;
101 }
102
103 PVE::LXC::Setup::Debian::setup_network($self, $netconf);
a8700492
JV
104}
105
1061;