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