source: fedkit/active_config.pl @ 51d3aa0

Last change on this file since 51d3aa0 was 87b1a06, checked in by Ted Faber <faber@…>, 12 years ago

Some minimal changes for nat_portal

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