source: fedkit/config_from_tunnelip.pl @ dc803a7

axis_examplecompt_changesinfo-opsversion-3.01version-3.02
Last change on this file since dc803a7 was dc803a7, checked in by Ted Faber <faber@…>, 15 years ago

Set up all routing daemons from the fedkit and note interfaces we've added in a way that SEER's federated testbed will grok them.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use IO::File;
5use IO::Pipe;
6use Getopt::Long;
7
8# Commands to use below.  These all seem to be in the same place on FreeBSD and
9# Lunix
10my $TMCC = "/usr/local/etc/emulab/tmcc";
11my $FINDIF = "/usr/local/etc/emulab/findif";
12my $IFCONFIG = "/sbin/ifconfig";
13my $ROUTE = "/sbin/route";
14
15my $tmcc = new IO::Pipe || die "Can't create tmcc pipe: $!\n";  # To parse tmcc
16my $interface;                  # Interface with external address
17my $ip;                         # IP address of external interface
18my $mac;                        # MAC address
19my $netmask;                    # Netmask
20my $router;                     # Router for the internet
21my $routedest;                  # Add host route to this address (if given)
22my $recordfile;                 # Record interfaces
23
24# Linux and FreeBSD use slightly different route syntax, so get the OS
25my $os = `uname`;
26chomp $os;
27
28# Option parsing, --destination sets $routedest
29GetOptions('destination=s' => \$routedest, "record=s" => \$recordfile);
30
31# Parse out the info about tunnelips
32$tmcc->reader("$TMCC tunnelip");
33while (<$tmcc>) {
34    chomp;
35    /TUNNELIP=([\d\.]*)/ && do { $ip = $1; };
36    /TUNNELMASK=([\d\.]*)/ && do { $netmask = $1; };
37    /TUNNELMAC=([[:xdigit:]]*)/ && do { $mac = $1; };
38    /TUNNELROUTER=([\d\.]*)/ && do { $router = $1; };
39}
40$tmcc->close();
41
42die "No MAC information for tunnel.\n" unless $mac;
43
44# Use the emulab findif command to get the right interface to configure
45$interface = `$FINDIF $mac`;
46chomp $interface;
47die "Can't get interface for mac address $mac: $?" if $? || !$interface;
48
49# Do the ifconfig
50my @ifconfig = ($IFCONFIG, $interface, $ip);
51push(@ifconfig, 'netmask', $netmask) if $netmask;
52
53system(@ifconfig);
54die join(" ", @ifconfig) . " failed: $!\n" if $?;
55
56# Add the host route, if needed
57if ($router) {
58    if ($routedest ) {
59        my @cmd;
60
61        if ( $os =~ /^Linux/ ) { 
62            @cmd = ($ROUTE, 'add', $routedest, 'gw', $router);
63        }
64        elsif ( $os =~ /^FreeBSD/ ) {
65            @cmd = ($ROUTE, 'add', $routedest, $router);
66        }
67        else {
68            die "Unknown OS: $os\n";
69        }
70        system(@cmd);
71        die join(" ", @cmd) . " failed: $?\n" if $?;
72    }
73}
74else { warn "Destination but no router\n" if $routedest; }
75if ($recordfile) {
76    $netmask = "255.255.255.0" unless $netmask;
77    my $rf = new IO::File(">>$recordfile") || 
78        die "Can't open $recordfile:$!\n";
79    print $rf "$ip:$interface:$mac:$netmask\n";
80    $rf->close();
81}
82exit(0);
Note: See TracBrowser for help on using the repository browser.