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 %opts = ( |
---|
16 | 'ssh_pubkey=s' => \$ssh_pubkey, |
---|
17 | 'tunnelip' => \$tunnelip, |
---|
18 | 'peer=s' => \$peer, |
---|
19 | 'use_file' => \$use_file, |
---|
20 | ); |
---|
21 | |
---|
22 | exit(20) unless GetOptions(%opts); |
---|
23 | |
---|
24 | if ($use_file) { |
---|
25 | gateway_lib::read_config(gateway_lib::config_filename(), \%opts) |
---|
26 | } |
---|
27 | |
---|
28 | my $uname = `uname`; |
---|
29 | chomp $uname; |
---|
30 | |
---|
31 | if ($uname =~ /Linux/) { |
---|
32 | # Right now the only gateway nodes that are Linux nodes are ProtoGENI |
---|
33 | # nodes. They need a bunch of custom updates to get into the 21st century, |
---|
34 | # but they are on the network. |
---|
35 | if ( -x '/usr/local/federation/bin/sshd' && |
---|
36 | -e '/usr/local/federation/etc/sshd_config') { |
---|
37 | # Start our modern sshd if one is there |
---|
38 | system("/usr/local/federation/bin/sshd -p 20200 -f " . |
---|
39 | "/usr/local/federation/etc/sshd_config"); |
---|
40 | } |
---|
41 | # fix yum.conf |
---|
42 | copy("/etc/yum.conf", "/etc/yum.conf.bak"); |
---|
43 | my $from = new IO::File("/etc/yum.conf.bak"); |
---|
44 | my $to = new IO::File(">/etc/yum.conf"); |
---|
45 | while (<$from>) { |
---|
46 | s/download.fedoralegacy.org/fedoralegacy.lsu.edu/g; |
---|
47 | print $to $_; |
---|
48 | } |
---|
49 | $from->close(); |
---|
50 | $to->close(); |
---|
51 | # Now, bridging |
---|
52 | system('/usr/bin/yum -y install bridge-utils'); |
---|
53 | #and keys |
---|
54 | gateway_lib::import_key($ssh_pubkey,'/root/.ssh/authorized_keys') |
---|
55 | if $ssh_pubkey; |
---|
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 | gateway_lib::add_route($peer, $router, 1, 60 *60) |
---|
80 | if $peer && $router; |
---|
81 | } |
---|
82 | |
---|
83 | exit(0); |
---|
84 | |
---|
85 | =pod |
---|
86 | |
---|
87 | =head1 NAME |
---|
88 | |
---|
89 | B<prep_tunnel.pl> - Prepare a tunnel node for use as either a service or connectivity gateway. |
---|
90 | |
---|
91 | =head1 OPTIONS |
---|
92 | |
---|
93 | =over 8 |
---|
94 | |
---|
95 | =item B<peer=>I<hostname> |
---|
96 | |
---|
97 | The other gateway providing forwarding. |
---|
98 | |
---|
99 | =item B<ssh_pubkey=>I<keyfile> |
---|
100 | |
---|
101 | A public to install as authorized. |
---|
102 | |
---|
103 | =item B<tunnelip> |
---|
104 | |
---|
105 | True if the testbed uses the DETER tunnelip extension to provide external |
---|
106 | connectivity information |
---|
107 | |
---|
108 | =item B<use_file> |
---|
109 | |
---|
110 | If given read additional parameters from the file in |
---|
111 | /proj/I<project>/exp/I<experiment/tmp/I<hostname>.gw/conf where those are the |
---|
112 | current testbed project and experiment and the hostname is before the first |
---|
113 | dot. The file is option: value. |
---|
114 | |
---|
115 | |
---|
116 | =back |
---|
117 | |
---|
118 | =head1 SYNOPSIS |
---|
119 | |
---|
120 | B<prep_gateway.pl> laods the necessary kernel modules for low-level bridging |
---|
121 | configures the local sshd to allow it, restarts that sshd, and installs the |
---|
122 | given key in root's authorized keys. |
---|
123 | |
---|
124 | If the gateway supports DETER gateway, it setablishes outside connectivity and |
---|
125 | adds a host rout to the given peer. |
---|
126 | |
---|
127 | =head1 AUTHORS |
---|
128 | |
---|
129 | Ted Faber <faber@isi.edu> |
---|
130 | |
---|
131 | =cut |
---|