summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil.baturin@vyatta.com>2012-03-29 03:01:29 +0700
committerDaniil Baturin <daniil.baturin@vyatta.com>2012-03-29 03:01:29 +0700
commit6746df51d7ac8e2f487dd74ca8b23c74fb4f28c1 (patch)
tree3c6692f7cce7e80fc3c6771053d034155dfeb7af
parent9f41b8563b7fc261b31d9ad2732a303a8459fccf (diff)
downloadvyatta-cfg-vpn-6746df51d7ac8e2f487dd74ca8b23c74fb4f28c1.tar.gz
vyatta-cfg-vpn-6746df51d7ac8e2f487dd74ca8b23c74fb4f28c1.zip
Add a script for validating single IPv4 or IPv6 address with no prefix
length.
-rw-r--r--Makefile.am1
-rwxr-xr-xscripts/is_valid_address.pl15
2 files changed, 16 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 6726ac1..ca5db1a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,6 +11,7 @@ sbin_SCRIPTS =
sbin_SCRIPTS += scripts/vpn-config.pl
sbin_SCRIPTS += scripts/vyatta-vpn-ppp-updown.pl
+sbin_SCRIPTS += scripts/is_valid_address.pl
bin_sudo_users_SCRIPTS = scripts/vyatta-ipsec-dhcp.pl
share_perl5_DATA = lib/Vyatta/VPN/Util.pm
diff --git a/scripts/is_valid_address.pl b/scripts/is_valid_address.pl
new file mode 100755
index 0000000..2860cc2
--- /dev/null
+++ b/scripts/is_valid_address.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+# Check a single IPv4 or IPv6 address
+
+use NetAddr::IP;
+
+$ip = $ARGV[0];
+
+if( !defined($ip) ||
+ $ip =~ "/" || # Ensure it doesn't have prefix length
+ !($addr = new NetAddr::IP $ip)
+ ) {
+ exit 1;
+}
+
+exit 0;