-#!/usr/bin/perl -w
-# vim:ft=perl
-
-die "l2tpns requires RedHat 7.3 or above" if i_isa("SOE_linux_rh6");
-
-my $restart = 0;
-
-my %conf = ();
-for my $c (i_isa_fetchall('L2tpns_config')) {
- foreach my $opt (keys %$c) {
- if (ref $conf{$opt} and ref $conf{$opt} eq 'ARRAY') {
- $c->{$opt} = [ $c->{$opt} ] unless ref $c->{$opt};
- push @{$conf{$opt}}, @{$c->{$opt}};
- } elsif (ref $c->{$opt} and ref $c->{$opt} eq 'ARRAY') {
- # Make sure to copy to avoid changing /etc/machine
- $conf{$opt} = [ $conf{$opt} ] if $conf{$opt};
- $conf{$opt} ||= [];
- push @{$conf{$opt}}, @{$c->{$opt}};
- } else {
- $conf{$opt} = $c->{$opt};
- }
- }
-}
-
-$conf{Address_pool} ||= i_isa("Address_pool"); # backwards compat
-
-unless (i_isa("No_throttle")) {
- chomp(my $kernel = `uname -r`);
- print "WARN: l2tpns requires kernel 2.4.18-187OIE1. This is included in $_path/rpm/kernel-2.4.18-187OIE1.i386.rpm\n"
- unless ($kernel eq '2.4.18-187OIE1' || $kernel =~ /^2\.4\.2\d/);
-}
-
-# Recompile the server if needed
-if ((stat("src/l2tpns.c"))[9] > (stat("src/l2tpns"))[9]) {
- chdir("src");
- command("make clean");
- command("make");
- chdir("..");
- $restart++;
-}
-
-command("mkdir /dev/net") and ++$restart unless -d "/dev/net";
-command("mknod /dev/net/tun c 10 200") and ++$restart unless -c "/dev/net/tun";
-
-my $cluster = i_isa('Gateway_cluster');
-my $cluster_name = $cluster->{master} || $cluster->{slave} || die 'Not a master or a slave' if $cluster;
-my $master = $cluster && $cluster->{master};
-my $command = $master ? "cluster_master" : "l2tpns";
-push @{$m{$_class}->{Monitor}->{process}->{tests}}, $command;
-
-
-if ($cluster) {
- $conf{'save state'} ||= 'no';
- if (!$master && !$cluster->{bind_address}) {
- die 'No bind address for cluster slave';
- }
- $conf{'bind address'} ||= $cluster->{bind_address} unless $master;
- my $cluster_master;
- my @cluster_slaves = ();
- my @cluster_slave_addresses = ();
- foreach my $host (type_list('Gateway_cluster')) {
- my $host_conf = OIE::Conform::i_isa(\%m, $host, 'Gateway_cluster');
- if ($host_conf->{master} eq $cluster_name) {
- $cluster_master = $host;
- } elsif ($host_conf->{slave} eq $cluster_name) {
- push @cluster_slaves, $host;
- push @{$conf{Address_pool}}, map { "$host_conf->{bind_address}:$_" } @{$m{$host}->{L2tpns_config}->{Address_pool}} if $master;
- push @cluster_slave_addresses, $m{$host}->{int_eth0}->{ip};
- }
- }
-
- if ($master) {
- push @{$m{$_class}->{inittab_include}},
- "$_path/src/cluster_master $m{$iam}->{int_eth0}->{ip}";
- push @{$m{$_class}->{inittab_disable}},
- "$_path/src/l2tpns";
- $m{$_class}->{Firewall}->{$_} = '32792:udp'
- foreach @cluster_slave_addresses;
- }
- $conf{'cluster master'} ||= $m{$cluster_master}->{int_eth0}->{ip};
-}
-
-# Build up address pool
-my $pool = $conf{Address_pool};
-if ($pool) {
- my $address_pool = "";
-
- foreach (@$pool) {
- $address_pool .= "$_\n";
- }
-
- text_install("$_path/etc/ip_pool.txt", $address_pool) and $restart++;
-} else {
- print "WARN: No Address_pool defined in machines.\n";
-}
-delete $conf{"Address_pool"}; # Don't add it to the conf file
-
-my $servicenet = $conf{"servicenet"};
-if ($servicenet) {
- $conf{'servicenet'} = 'yes';
- push @{$conf{plugin}}, 'servicenet' unless grep /^servicenet$/, @{$conf{plugin}};
- file_install("/etc/rc.d/rc.firewall.INPUT.servicenet", "$_path/etc/rc.firewall.INPUT.servicenet", undef, undef,
- "s/#SERVICENET#/$servicenet/g")
- and queue_command("/etc/rc.d/rc.firewall");
-} else {
- $conf{'servicenet'} = 'no';
- # Uninstall
- if (-f "/etc/rc.d/rc.firewall.INPUT.servicenet") {
- unlink "/etc/rc.d/rc.firewall.INPUT.servicenet";
- command("iptables -F snet");
- }
-}
-
-# Note that we don't file_install the config file, but instead modify it
-# in place
-
-my $config = slurp_file("$_path/etc/l2tpns.cfg");
-
-# plugins need to go first, else they won't pick up params
-foreach my $p (@{$conf{plugin}}) {
- $config =~ s/^#?\s*plugin\s+=\s+\Q$p\E$/plugin = $p/mg or
- $config = "plugin = $p\n\n$config";
-}
-delete $conf{plugin};
-
-foreach my $c (keys %conf) {
- $config =~ s/^#?\s*\Q$c\E\s+=\s+.*$/$c = $conf{$c}/mg or
- $config .= "$c = $conf{$c}\n\n";
-}
-
-file_install("/etc/rc.d/rc.firewall.INPUT.l2tpns", "$_path/etc/rc.firewall.INPUT.l2tpns")
- and queue_command("/etc/rc.d/rc.firewall");
-
-text_install("$_path/etc/l2tpns.cfg", $config) and $restart++;
-
-queue_command("killall $command") if $restart;
-