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