Skip to content

Commit

Permalink
add network-prefix support
Browse files Browse the repository at this point in the history
  • Loading branch information
donald authored and mariux committed May 30, 2012
1 parent 7926423 commit e40b2d1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mxstartup2mxconfig
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ sub parse_ips {
my %ports = ();
my $ip = "-";
my $_todest = undef;
my $addressprefix;

if(/\{(\S+)\}(\S+)/) { # extract device "{device}ip[d:t][..]"
$device = $1;
Expand All @@ -126,25 +127,31 @@ sub parse_ips {
if($_ =~ /(\S+)\:(\S+)/) {
$_todest = $2;
$_ = $1;
}

if (/(\S+)\/(\S+)/) {
$_=$1;
$addressprefix=$2;
} else {
$_todest = $_;
$addressprefix=20;
}

if("$_" eq "-") {
$_ = $fullhostname;
}

if("$_todest" eq "-") {
$_todest = $fullhostname;
unless (defined $_todest) {
$_todest=$_;
}


# printf "ip = $_\n";
# printf "todest = $_todest\n";

$ip = inet_ntoa(scalar gethostbyname($_));
$_todest = inet_ntoa(scalar gethostbyname($_todest));

$H->{$ip} = { device => $device, ports => {%ports}, todest => $_todest } unless($ip eq "-");
$H->{$ip} = { device => $device, addressprefix => $addressprefix, ports => {%ports}, todest => $_todest };
}

return $H;
Expand Down Expand Up @@ -195,7 +202,7 @@ sub print_ips_cfg {
if("$ip" ne "$hostip") {
print SCRIPT qq(# ip $i\n);
print SCRIPT qq(MX_IP_ADDRESS[$i]="$ip"\n);
print SCRIPT qq(MX_IP_ADDRESSPREFIX[$i]="20"\n);
print SCRIPT qq(MX_IP_ADDRESSPREFIX[$i]="$H->{$ip}->{addressprefix}"\n);
print SCRIPT qq(MX_IP_BROADCAST[$i]="141.14.31.255"\n);
print SCRIPT qq(MX_IP_DEVICE[$i]="$H->{$ip}->{device}"\n);
$i++;
Expand Down

0 comments on commit e40b2d1

Please sign in to comment.