source: fedkit/config_from_tunnelip.pl @ e26c240

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

This encapsulates the process of configuring an interface from tunnelip data

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use IO::File;
5use IO::Pipe;
6use Getopt::Long;
7
8my $TMCC = "/usr/local/etc/emulab/tmcc";
9my $FINDIF = "/usr/local/etc/emulab/findif";
10my $IFCONFIG = "/sbin/ifconfig";
11my $ROUTE = "/sbin/route";
12
13my $tmcc = new IO::Pipe || die "Can't create tmcc pipe: $!\n";
14my $interface;
15my $ip;
16my $mac;
17my $netmask ="255.255.255.0";
18my $router;
19my $routedest;
20
21my $os = `uname`;
22chomp $os;
23
24GetOptions('destination=s' => \$routedest);
25
26$tmcc->reader("$TMCC tunnelip");
27while (<$tmcc>) {
28    chomp;
29    /TUNNELIP=([\d\.]*)/ && do { $ip = $1; };
30    /TUNNELMASK=([\d\.]*)/ && do { $netmask = $1; };
31    /TUNNELMAC=([[:xdigit:]]*)/ && do { $mac = $1; };
32    /TUNNELROUTER=([\d\.]*)/ && do { $router = $1; };
33}
34$tmcc->close();
35
36die "No MAC information for tunnel.\n" unless $mac;
37
38$interface = `$FINDIF $mac`;
39chomp $interface;
40die "Can't get interface for mac address $mac: $?" if $? || !$interface;
41
42my @ifconfig = ($IFCONFIG, $interface, $ip);
43push(@ifconfig, 'netmask', $netmask) if $netmask;
44
45system(@ifconfig);
46die join(" ", @ifconfig) . " failed: $!\n" if $?;
47
48if ($routedest ) {
49    if ($router) {
50        my @cmd;
51
52        if ( $os =~ /^Linux/ ) { 
53            @cmd = ($ROUTE, 'add', $routedest, 'gw', $router);
54        }
55        elsif ( $os =~ /^FreeBSD/ ) {
56            @cmd = ($ROUTE, 'add', $routedest, $router);
57        }
58        else {
59            die "Unknown OS: $os\n";
60        }
61        system(@cmd);
62        die join(" ", @cmd) . " failed: $?\n" if $?;
63    }
64    else { die "Destination but no router\n"; }
65}
66exit(0);
Note: See TracBrowser for help on using the repository browser.