[2edec46] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | |
---|
| 5 | use gateway_lib; |
---|
| 6 | |
---|
| 7 | use Getopt::Long; |
---|
[f8fa72b] | 8 | use File::Copy; |
---|
| 9 | use IO::File; |
---|
[2edec46] | 10 | |
---|
| 11 | my $ssh_pubkey; |
---|
| 12 | my $tunnelip; |
---|
| 13 | my $peer; |
---|
[8d4e4fb] | 14 | my $use_file; |
---|
[4e9719b] | 15 | my $fed_dir = "/usr/local/federation/"; |
---|
[8d4e4fb] | 16 | my %opts = ( |
---|
| 17 | 'ssh_pubkey=s' => \$ssh_pubkey, |
---|
[2edec46] | 18 | 'tunnelip' => \$tunnelip, |
---|
| 19 | 'peer=s' => \$peer, |
---|
[8d4e4fb] | 20 | 'use_file' => \$use_file, |
---|
[2edec46] | 21 | ); |
---|
| 22 | |
---|
[8d4e4fb] | 23 | exit(20) unless GetOptions(%opts); |
---|
| 24 | |
---|
[f8fa72b] | 25 | if ($use_file) { |
---|
| 26 | gateway_lib::read_config(gateway_lib::config_filename(), \%opts) |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | my $uname = `uname`; |
---|
| 30 | chomp $uname; |
---|
[8d4e4fb] | 31 | |
---|
[4e9719b] | 32 | # on portals make sure client.conf is in the override position (in fed_dir). |
---|
| 33 | my $client_conf = gateway_lib::client_conf_filename(); |
---|
| 34 | |
---|
| 35 | copy($client_conf, "$fed_dir/etc/client.conf") |
---|
| 36 | unless $client_conf =~ /^$fed_dir/; |
---|
| 37 | |
---|
[f8fa72b] | 38 | if ($uname =~ /Linux/) { |
---|
[1d91791f] | 39 | # Install bridging software if not present |
---|
| 40 | system('/usr/bin/yum -y install bridge-utils'); |
---|
| 41 | # Restart sshd with tunnel params |
---|
| 42 | gateway_lib::set_sshd_params( |
---|
| 43 | { 'GatewayPorts' => 'yes', 'PermitTunnel' => 'yes' } ); |
---|
| 44 | system("/etc/init.d/sshd restart"); |
---|
[f8fa72b] | 45 | gateway_lib::import_key($ssh_pubkey,'/root/.ssh/authorized_keys') |
---|
| 46 | if $ssh_pubkey; |
---|
| 47 | } |
---|
| 48 | elsif ($uname =~ /FreeBSD/ ){ |
---|
| 49 | gateway_lib::set_sshd_params( |
---|
| 50 | { 'GatewayPorts' => 'yes', 'PermitTunnel' => 'yes' } ); |
---|
| 51 | system("/etc/rc.d/sshd restart"); |
---|
[2edec46] | 52 | |
---|
[f8fa72b] | 53 | gateway_lib::import_key($ssh_pubkey,'/root/.ssh/authorized_keys') |
---|
| 54 | if $ssh_pubkey; |
---|
[2edec46] | 55 | |
---|
[f8fa72b] | 56 | # Need these to make the Ethernet tap and bridge work. |
---|
| 57 | system("kldload /boot/kernel/bridgestp.ko") |
---|
| 58 | if -r "/boot/kernel/bridgestp.ko"; |
---|
| 59 | system("kldload /boot/kernel/if_bridge.ko"); |
---|
| 60 | system("kldload /boot/kernel/if_tap.ko"); |
---|
| 61 | } |
---|
[2edec46] | 62 | |
---|
| 63 | if ( $tunnelip ) { |
---|
| 64 | my ($interface, $ip, $netmask, $mac, $router) = |
---|
| 65 | gateway_lib::deter_tunnelip(); |
---|
| 66 | |
---|
[2b35261] | 67 | gateway_lib::configure_outgoing_iface($interface, $ip, $netmask); |
---|
[2edec46] | 68 | # Add the route to a peer. Wait up to an hour for the peer's IP address to |
---|
| 69 | # appear in the DNS. |
---|
[55779d4] | 70 | gateway_lib::add_route($peer, $router, 1, 60 *60) |
---|
| 71 | if $peer && $router; |
---|
[2edec46] | 72 | } |
---|
| 73 | |
---|
| 74 | exit(0); |
---|
[2b35261] | 75 | |
---|
| 76 | =pod |
---|
| 77 | |
---|
| 78 | =head1 NAME |
---|
| 79 | |
---|
| 80 | B<prep_tunnel.pl> - Prepare a tunnel node for use as either a service or connectivity gateway. |
---|
| 81 | |
---|
| 82 | =head1 OPTIONS |
---|
| 83 | |
---|
| 84 | =over 8 |
---|
| 85 | |
---|
| 86 | =item B<peer=>I<hostname> |
---|
| 87 | |
---|
| 88 | The other gateway providing forwarding. |
---|
| 89 | |
---|
| 90 | =item B<ssh_pubkey=>I<keyfile> |
---|
| 91 | |
---|
| 92 | A public to install as authorized. |
---|
| 93 | |
---|
| 94 | =item B<tunnelip> |
---|
| 95 | |
---|
| 96 | True if the testbed uses the DETER tunnelip extension to provide external |
---|
| 97 | connectivity information |
---|
| 98 | |
---|
[8d4e4fb] | 99 | =item B<use_file> |
---|
| 100 | |
---|
| 101 | If given read additional parameters from the file in |
---|
| 102 | /proj/I<project>/exp/I<experiment/tmp/I<hostname>.gw/conf where those are the |
---|
| 103 | current testbed project and experiment and the hostname is before the first |
---|
| 104 | dot. The file is option: value. |
---|
| 105 | |
---|
| 106 | |
---|
[2b35261] | 107 | =back |
---|
| 108 | |
---|
| 109 | =head1 SYNOPSIS |
---|
| 110 | |
---|
| 111 | B<prep_gateway.pl> laods the necessary kernel modules for low-level bridging |
---|
| 112 | configures the local sshd to allow it, restarts that sshd, and installs the |
---|
| 113 | given key in root's authorized keys. |
---|
| 114 | |
---|
| 115 | If the gateway supports DETER gateway, it setablishes outside connectivity and |
---|
| 116 | adds a host rout to the given peer. |
---|
| 117 | |
---|
| 118 | =head1 AUTHORS |
---|
| 119 | |
---|
| 120 | Ted Faber <faber@isi.edu> |
---|
| 121 | |
---|
| 122 | =cut |
---|