From f2b473bf4b904635b48489203540a644082aada5 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 29 Jan 2008 15:10:59 -0800 Subject: allow full IP specification (IP/prefix/interface/broadcast) for cluster resource (service). --- scripts/VyattaClusterConfig.pm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'scripts/VyattaClusterConfig.pm') diff --git a/scripts/VyattaClusterConfig.pm b/scripts/VyattaClusterConfig.pm index affb3e8..292a7f6 100644 --- a/scripts/VyattaClusterConfig.pm +++ b/scripts/VyattaClusterConfig.pm @@ -229,6 +229,27 @@ EOS return ($str, undef); } +sub isValidIPSpec { + my $str = shift; + my @comps = split /\//, $str; + return 0 if ($#comps > 3); + return 0 if (!isValidIPv4($comps[0])); + # check optional prefix len + if (defined($comps[1])) { + return 0 if (!($comps[1] =~ m/^\d+$/)); + return 0 if (($comps[1] > 32) || ($comps[1] < 0)); + } + # check optional interface + if (defined($comps[2])) { + return 0 if (defined(check_interfaces($comps[2]))); + } + # check optional broadcast addr + if (defined($comps[3])) { + return 0 if (!isValidIPv4($comps[3])); + } + return 1; +} + sub isValidIPv4 { my $str = shift; return 0 if (!($str =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)); @@ -263,7 +284,7 @@ sub haresources { my @init_services = (); my @ip_addresses = (); foreach (@{$hashref->{_service}}) { - if (!isValidIPv4($_)) { + if (!isValidIPSpec($_)) { if (isValidService($_)) { push @init_services, $_; } else { -- cgit v1.2.3