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