initfwvars.pl.in 2.79 KB
Newer Older
1 2 3
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2005, 2008 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
# All rights reserved.
#

#CREATE TABLE firewall_vars (
#  name varchar(255) NOT NULL default '',
#  value text,
#  PRIMARY KEY  (name)
#) TYPE=MyISAM;

my $doit = 1;

use English;
use Socket;

use lib "@prefix@/lib";
use libdb;

my $CONTROL_NETWORK    = "@CONTROL_NETWORK@";
my $CONTROL_NETMASK    = "@CONTROL_NETMASK@";
my $BOSSNODE_IP        = "@BOSSNODE_IP@";
my $FRISBEE_MCASTADDR  = "@FRISEBEEMCASTADDR@";
my $FRISBEE_MCASTPORT  = "@FRISEBEEMCASTPORT@";

#
# Untaint the path
# 
$ENV{'PATH'} = '/bin:/usr/bin:/usr/sbin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

# Simple is good. I stole this out of a google search.
my @NETMASKS =
    (0x10000000,                                             # 0
     0x80000000, 0xC0000000, 0xE0000000, 0xF0000000,         #  1 -  4
     0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000,         #  5 -  8
     0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000,         #  9 - 12
     0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,         # 13 - 16
     0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000,         # 17 - 20
     0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00,         # 21 - 24
     0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0,         # 25 - 28
     0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF          # 29 - 32
);

my $CIDRMASK = "24";
for (my $i = 0; $i < scalar(@NETMASKS); $i++) {
    my $foo = pack("N", $NETMASKS[$i]);

    if ($CONTROL_NETMASK eq inet_ntoa($foo)) {
	$CIDRMASK = "$i";
	last;
    }
}

my $str;

# Use boss IP as "ns" since that is what we assume everywhere else
$str = "replace into default_firewall_vars values ('EMULAB_NS', '$BOSSNODE_IP')";
print "$str\n"
    if (!$doit);
DBQueryFatal($str)
    if ($doit);

# Add the control net in CIDR notation
$str = "replace into default_firewall_vars values ('EMULAB_CNET', '$CONTROL_NETWORK/$CIDRMASK')";
print "$str\n"
    if (!$doit);
DBQueryFatal($str)
    if ($doit);

73 74
#
# Frisbee multicast info
75 76 77
# XXX assumptions, assumptions (as of 9/05).  We could allow up to a /8 network
# but we assign a unique port as well as address and a port is only 16 bits,
# so use a /16.
78 79 80
# XXX assumptions II (as of 2/08).  frisbeelauncher ticks up the MC address
# all the way to /8 (it wraps the port number as needed), so lets make it
# so here.
81 82
#
my @mcaddr = split /\./, $FRISBEE_MCASTADDR, 4;
83
$FRISBEE_MCASTADDR = $mcaddr[0] . ".0.0.0/8";
84
$FRISBEE_MCASTPORT = $FRISBEE_MCASTPORT . "-65535";
85 86 87 88 89 90 91 92 93 94 95 96 97 98

$str = "replace into default_firewall_vars values ('EMULAB_MCADDR', '$FRISBEE_MCASTADDR')";
print "$str\n"
    if (!$doit);
DBQueryFatal($str)
    if ($doit);

$str = "replace into default_firewall_vars values ('EMULAB_MCPORT', '$FRISBEE_MCASTPORT')";
print "$str\n"
    if (!$doit);
DBQueryFatal($str)
    if ($doit);

exit(0);