summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-12-20 17:59:36 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-12-20 18:44:04 -0800
commit76501f836662d9666ed4357de6bfcad61eb019cb (patch)
treea1b8be897fb646f047029bfeecd8f22f83cfbe2e
parentff9341d244073fec28e66ff10754f50e2ca084e5 (diff)
downloadvyatta-cfg-76501f836662d9666ed4357de6bfcad61eb019cb.tar.gz
vyatta-cfg-76501f836662d9666ed4357de6bfcad61eb019cb.zip
Handle IPv6 in is_local_address
Bug 6590 The code to check for local address has to be smarter to handle IPv6. Introduces dependency on Socket6 module.
-rw-r--r--debian/control1
-rwxr-xr-xlib/Vyatta/Misc.pm18
2 files changed, 17 insertions, 2 deletions
diff --git a/debian/control b/debian/control
index 1f62716..f603233 100644
--- a/debian/control
+++ b/debian/control
@@ -23,6 +23,7 @@ Depends: sed (>= 4.1.5),
ethtool,
iproute,
curl,
+ libsocket6-perl,
libvyatta-cfg1 (=${binary:Version}),
${perl:Depends}, ${shlibs:Depends}
Replaces: vyatta-cfg-firewall,
diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm
index 40c4602..c6a51c8 100755
--- a/lib/Vyatta/Misc.pm
+++ b/lib/Vyatta/Misc.pm
@@ -36,6 +36,8 @@ use Vyatta::Config;
use Vyatta::Interface;
use NetAddr::IP;
use Socket;
+use Socket6;
+
#
# returns a hash of ipaddrs => interface
#
@@ -151,11 +153,23 @@ sub getInterfaces {
# Linux will only allow binding to local addresses
sub is_local_address {
my $addr = shift;
+ my $ip = new NetAddr::IP $addr;
+ die "$addr: not a valid IP address"
+ unless $ip;
+
+ my ($pf, $sockaddr);
+ if ($ip->version() == 4) {
+ $pf = PF_INET;
+ $sockaddr = sockaddr_in(0, $ip->aton());
+ } else {
+ $pf = PF_INET6;
+ $sockaddr = sockaddr_in6(0, $ip->aton());
+ }
- socket( my $sock, PF_INET, SOCK_STREAM, 0)
+ socket( my $sock, $pf, SOCK_STREAM, 0)
or die "socket failed\n";
- return bind($sock, sockaddr_in(0, inet_aton($addr)));
+ return bind($sock, $sockaddr);
}
# get list of IPv4 and IPv6 addresses