[2edec46] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | |
---|
| 5 | use gateway_lib; |
---|
| 6 | |
---|
| 7 | use IO::File; |
---|
| 8 | |
---|
| 9 | use Getopt::Long; |
---|
| 10 | |
---|
| 11 | my $ssh_pubkey; |
---|
| 12 | my $ssh_privkey; |
---|
| 13 | my $tunnelip; |
---|
| 14 | my $peer; |
---|
| 15 | my $fedkit_dir= "/usr/local/federation"; |
---|
| 16 | my $perl = "/usr/bin/perl"; |
---|
[8d4e4fb] | 17 | my $iface_file = "/var/emulab/boot/ifmap"; |
---|
[2edec46] | 18 | my $ssh = "/usr/bin/ssh"; |
---|
[64e774d] | 19 | my $scp = "/usr/bin/scp"; |
---|
[f8fa72b] | 20 | my $ssh_port = 22; |
---|
[73e0a61] | 21 | my $use_file; |
---|
[2edec46] | 22 | |
---|
[8d4e4fb] | 23 | my %opts = ( |
---|
[2edec46] | 24 | 'ssh_pubkey=s' => \$ssh_pubkey, |
---|
| 25 | 'ssh_privkey=s' => \$ssh_privkey, |
---|
| 26 | 'tunnelip' => \$tunnelip, |
---|
| 27 | 'peer=s' => \$peer, |
---|
| 28 | 'fedkit=s' => \$fedkit_dir, |
---|
| 29 | 'perl=s' => \$perl, |
---|
| 30 | 'interfaces=s' => \$iface_file, |
---|
| 31 | 'ssh=s' => \$ssh, |
---|
[64e774d] | 32 | 'scp=s' => \$scp, |
---|
[f8fa72b] | 33 | 'ssh_port=s' => \$ssh_port, |
---|
[8d4e4fb] | 34 | 'use_file' => \$use_file, |
---|
[2edec46] | 35 | ); |
---|
| 36 | |
---|
[8d4e4fb] | 37 | exit(20) unless GetOptions(%opts); |
---|
| 38 | |
---|
[f8fa72b] | 39 | gateway_lib::read_config(gateway_lib::config_filename(), \%opts) |
---|
[8d4e4fb] | 40 | if $use_file; |
---|
[2edec46] | 41 | |
---|
| 42 | my $tunnelparam = $tunnelip ? '--tunnelip' : ''; |
---|
| 43 | |
---|
| 44 | system("$perl -I$fedkit_dir/lib $fedkit_dir/bin/prep_gateway.pl --peer=$peer " . |
---|
| 45 | "--ssh_pubkey=$ssh_pubkey $tunnelparam"); |
---|
| 46 | exit(20) if $?; |
---|
| 47 | |
---|
| 48 | |
---|
[1899afd] | 49 | print "Waiting for ssh on $peer\n"; |
---|
[87b1a06] | 50 | # XXX: should be $ssh_port? |
---|
[1899afd] | 51 | gateway_lib::wait_for_port($peer, 22, 60*60) || |
---|
| 52 | die "ssh never came up on $peer\n"; |
---|
[64e774d] | 53 | my $coord_fn = "$fedkit_dir/etc/prep_done"; |
---|
| 54 | print "Making sure ssh permissions are reset (fetching $coord_fn)\n"; |
---|
| 55 | gateway_lib::testcmd_repeat("$scp -o \"StrictHostKeyChecking no\" " . |
---|
| 56 | "-i $ssh_privkey $peer:$coord_fn /tmp", 5*60); |
---|
[1899afd] | 57 | |
---|
[55779d4] | 58 | if (my $f = new IO::File($iface_file)) { |
---|
| 59 | my $ifnum = 0; |
---|
| 60 | while (<$f>) { |
---|
| 61 | /([[:alnum:]]+)\s+([\d\.]+)/ && do { |
---|
| 62 | my ($iface, $addr) = ($1, $2); |
---|
| 63 | |
---|
[f8fa72b] | 64 | my $cmd = "$ssh -w $ifnum:$ifnum -p $ssh_port " . |
---|
| 65 | "-o \"Tunnel ethernet\" -o \"StrictHostKeyChecking no\" " . |
---|
| 66 | "-i $ssh_privkey $peer perl -I$fedkit_dir/lib ". |
---|
| 67 | "$fedkit_dir/bin/setup_bridge.pl --tapno=$ifnum --dest=$addr &"; |
---|
[55779d4] | 68 | system($cmd); |
---|
| 69 | die if $?; |
---|
| 70 | gateway_lib::bind_tap_to_iface($ifnum, $iface, $addr); |
---|
| 71 | $ifnum++; |
---|
| 72 | }; |
---|
| 73 | } |
---|
| 74 | $f->close(); |
---|
| 75 | } |
---|
| 76 | else { |
---|
| 77 | warn "Can't open $iface_file: $!\n"; |
---|
[2edec46] | 78 | } |
---|
| 79 | exit(0); |
---|
[2b35261] | 80 | |
---|
| 81 | =pod |
---|
| 82 | |
---|
| 83 | =head1 NAME |
---|
| 84 | |
---|
| 85 | B<active_config.pl> - Configure an active connectivity gateway under the DETER Federation Architecture |
---|
| 86 | |
---|
| 87 | =head1 OPTIONS |
---|
| 88 | |
---|
| 89 | =over 8 |
---|
| 90 | |
---|
| 91 | =item B<fedkit=>I<install_dir> |
---|
| 92 | |
---|
| 93 | Directory in which this software is installed. Generally not needed. |
---|
| 94 | |
---|
| 95 | =item B<interfaces=>I<interface table> |
---|
| 96 | |
---|
| 97 | A list of interfaces to forward data on of the form: |
---|
| 98 | |
---|
| 99 | =begin text |
---|
| 100 | |
---|
| 101 | iface ip_addr |
---|
| 102 | |
---|
| 103 | =end text |
---|
| 104 | |
---|
| 105 | The interface is the operating system name of the interface and the IP address |
---|
| 106 | is given in standard dotted decimal notation. Other characters on a line are |
---|
| 107 | ignored. |
---|
| 108 | |
---|
| 109 | =item B<peer=>I<hostname> |
---|
| 110 | |
---|
| 111 | The other gateway providing forwarding. |
---|
| 112 | |
---|
| 113 | =item B<perl=>I<perl_binary> |
---|
| 114 | |
---|
| 115 | Location of the perl binary. Usually unneeded. |
---|
| 116 | |
---|
| 117 | =item B<ssh=>I<ssh_binary> |
---|
| 118 | |
---|
| 119 | The pathname of the ssh binary. Unusally unnecessary. |
---|
| 120 | |
---|
| 121 | =item B<ssh_pubkey=>I<keyfile> |
---|
| 122 | |
---|
| 123 | A public to install as authorized. |
---|
| 124 | |
---|
| 125 | =item B<ssh_privkey=>I<identity_file> |
---|
| 126 | |
---|
| 127 | The identity to use for remote access |
---|
| 128 | |
---|
| 129 | =item B<tunnelip> |
---|
| 130 | |
---|
| 131 | True if the testbed uses the DETER tunnelip extension to provide external |
---|
| 132 | connectivity information |
---|
| 133 | |
---|
[8d4e4fb] | 134 | =item B<use_file> |
---|
| 135 | |
---|
| 136 | If given read additional parameters from the file in |
---|
[c6d6c43] | 137 | /proj/I<project>/exp/I<experiment>/tmp/I<hostname>.gw/conf where those are the |
---|
[8d4e4fb] | 138 | current testbed project and experiment and the hostname is before the first |
---|
| 139 | dot. The file is option: value. |
---|
| 140 | |
---|
| 141 | |
---|
[2b35261] | 142 | =back |
---|
| 143 | |
---|
| 144 | =head1 SYNOPSIS |
---|
| 145 | |
---|
| 146 | B<active_config.pl> initiates the active side of the connectivity connection, |
---|
| 147 | which is to say that it: |
---|
| 148 | |
---|
| 149 | =over 4 |
---|
| 150 | |
---|
| 151 | =item * |
---|
| 152 | |
---|
| 153 | Installs local keys and reconfigures that local ssh system to do link layer |
---|
| 154 | tunneling. |
---|
| 155 | |
---|
| 156 | =item * |
---|
| 157 | |
---|
| 158 | Starts a tunnel for each interface in the given interface table, both locally |
---|
| 159 | and remotely. |
---|
| 160 | |
---|
| 161 | =back |
---|
| 162 | |
---|
| 163 | =head1 AUTHORS |
---|
| 164 | |
---|
| 165 | Ted Faber <faber@isi.edu> |
---|
| 166 | |
---|
| 167 | =cut |
---|