1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | |
---|
5 | use gateway_lib; |
---|
6 | |
---|
7 | use Getopt::Long; |
---|
8 | use File::Copy; |
---|
9 | use IO::File; |
---|
10 | |
---|
11 | my $ssh_pubkey; |
---|
12 | my $tunnelip; |
---|
13 | my $peer; |
---|
14 | my $use_file; |
---|
15 | my $fed_dir = "/usr/local/federation/"; |
---|
16 | my %opts = ( |
---|
17 | 'ssh_pubkey=s' => \$ssh_pubkey, |
---|
18 | 'tunnelip' => \$tunnelip, |
---|
19 | 'peer=s' => \$peer, |
---|
20 | 'use_file' => \$use_file, |
---|
21 | ); |
---|
22 | |
---|
23 | exit(20) unless GetOptions(%opts); |
---|
24 | |
---|
25 | if ($use_file) { |
---|
26 | gateway_lib::read_config(gateway_lib::config_filename(), \%opts) |
---|
27 | } |
---|
28 | |
---|
29 | my $uname = `uname`; |
---|
30 | chomp $uname; |
---|
31 | |
---|
32 | # on portals make sure client.conf is in the override position (in fed_dir). |
---|
33 | my $client_conf = gateway_lib::client_conf_filename(); |
---|
34 | |
---|
35 | copy($client_conf, "$fed_dir/etc/client.conf") |
---|
36 | unless $client_conf =~ /^$fed_dir/; |
---|
37 | |
---|
38 | if ($uname =~ /Linux/) { |
---|
39 | # Restart sshd with tunnel params |
---|
40 | gateway_lib::set_sshd_params( |
---|
41 | { 'GatewayPorts' => 'yes', 'PermitTunnel' => 'yes' } ); |
---|
42 | system("/etc/init.d/sshd restart"); |
---|
43 | gateway_lib::import_key($ssh_pubkey,'/root/.ssh/authorized_keys') |
---|
44 | if $ssh_pubkey; |
---|
45 | # Install bridging software if not present |
---|
46 | if ( -x '/usr/bin/yum' ) { |
---|
47 | system('/usr/bin/yum -y install bridge-utils'); |
---|
48 | } |
---|
49 | elsif (-x '/usr/bin/apt-get') { |
---|
50 | system('/usr/bin/apt-get -y update'); |
---|
51 | system('/usr/bin/apt-get -y install bridge-utils'); |
---|
52 | } |
---|
53 | else { |
---|
54 | print "Cannot install bridge utils, hope they're here.\n" |
---|
55 | } |
---|
56 | } |
---|
57 | elsif ($uname =~ /FreeBSD/ ){ |
---|
58 | gateway_lib::set_sshd_params( |
---|
59 | { 'GatewayPorts' => 'yes', 'PermitTunnel' => 'yes' } ); |
---|
60 | system("/etc/rc.d/sshd restart"); |
---|
61 | |
---|
62 | gateway_lib::import_key($ssh_pubkey,'/root/.ssh/authorized_keys') |
---|
63 | if $ssh_pubkey; |
---|
64 | |
---|
65 | # Need these to make the Ethernet tap and bridge work. |
---|
66 | system("kldload /boot/kernel/bridgestp.ko") |
---|
67 | if -r "/boot/kernel/bridgestp.ko"; |
---|
68 | system("kldload /boot/kernel/if_bridge.ko"); |
---|
69 | system("kldload /boot/kernel/if_tap.ko"); |
---|
70 | } |
---|
71 | |
---|
72 | if ( $tunnelip ) { |
---|
73 | my ($interface, $ip, $netmask, $mac, $router) = |
---|
74 | gateway_lib::deter_tunnelip(); |
---|
75 | |
---|
76 | gateway_lib::configure_outgoing_iface($interface, $ip, $netmask); |
---|
77 | # Add the route to a peer. Wait up to an hour for the peer's IP address to |
---|
78 | # appear in the DNS. |
---|
79 | foreach my $p (split(/\s*,\s*/, $peer)) { |
---|
80 | gateway_lib::add_route($p, $router, 1, 60 *60) |
---|
81 | if $p && $router; |
---|
82 | } |
---|
83 | } |
---|
84 | my $coord_fn = "$fed_dir/etc/prep_done"; |
---|
85 | my $coord_file = new IO::File(">$coord_fn") || die "Cannot open $coord_fn"; |
---|
86 | |
---|
87 | print $coord_file `date`; |
---|
88 | $coord_file->close(); |
---|
89 | |
---|
90 | exit(0); |
---|
91 | |
---|
92 | =pod |
---|
93 | |
---|
94 | =head1 NAME |
---|
95 | |
---|
96 | B<prep_tunnel.pl> - Prepare a tunnel node for use as either a service or connectivity gateway. |
---|
97 | |
---|
98 | =head1 OPTIONS |
---|
99 | |
---|
100 | =over 8 |
---|
101 | |
---|
102 | =item B<peer=>I<hostname> |
---|
103 | |
---|
104 | The other gateway providing forwarding. |
---|
105 | |
---|
106 | =item B<ssh_pubkey=>I<keyfile> |
---|
107 | |
---|
108 | A public to install as authorized. |
---|
109 | |
---|
110 | =item B<tunnelip> |
---|
111 | |
---|
112 | True if the testbed uses the DETER tunnelip extension to provide external |
---|
113 | connectivity information |
---|
114 | |
---|
115 | =item B<use_file> |
---|
116 | |
---|
117 | If given read additional parameters from the file in |
---|
118 | /proj/I<project>/exp/I<experiment>/tmp/I<hostname>.gw/conf where those are the |
---|
119 | current testbed project and experiment and the hostname is before the first |
---|
120 | dot. The file is option: value. |
---|
121 | |
---|
122 | |
---|
123 | =back |
---|
124 | |
---|
125 | =head1 SYNOPSIS |
---|
126 | |
---|
127 | B<prep_gateway.pl> laods the necessary kernel modules for low-level bridging |
---|
128 | configures the local sshd to allow it, restarts that sshd, and installs the |
---|
129 | given key in root's authorized keys. |
---|
130 | |
---|
131 | If the gateway supports DETER gateway, it setablishes outside connectivity and |
---|
132 | adds a host rout to the given peer. |
---|
133 | |
---|
134 | =head1 AUTHORS |
---|
135 | |
---|
136 | Ted Faber <faber@isi.edu> |
---|
137 | |
---|
138 | =cut |
---|