OSDN Git Service

2009/12/15 l7directord問題対応
authormeguro <meguro@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Tue, 15 Dec 2009 08:58:48 +0000 (08:58 +0000)
committermeguro <meguro@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Tue, 15 Dec 2009 08:58:48 +0000 (08:58 +0000)
git-svn-id: http://10.144.169.20/repos/um/branches/l7vsd-3.x-ramiel@9153 1ed66053-1c2d-0410-8867-f7571e6e31d3

l7directord/l7directord
l7directord/t/32_getid.t

index 03665db..dfc0913 100644 (file)
@@ -3881,6 +3881,9 @@ sub get_ip_port {
     my ($host, $checkport) = @_;
     my $server = defined $host && defined $host->{server} && defined $host->{server}{ip}
                     ? $host->{server}{ip  } : q{};
+    if (is_ip6($server)) {
+        $server = sprintf "[%s]" , $server;
+    }
     my $port   = defined $checkport ? $checkport
                : defined $host && defined $host->{server} && defined $host->{server}{port}
                     ? $host->{server}{port} : q{};
index 2ab2b15..90715a4 100644 (file)
@@ -5,7 +5,7 @@ use lib qw(t/lib lib);
 use subs qw(print);
 use Cwd;
 use L7lib;
-use Test::More tests => 41;
+use Test::More tests => 46;
 
 L7lib::chdir();
 L7lib::comment_out();
@@ -51,6 +51,37 @@ override();
     my $got = get_ip_port($host, $checkport);
     is $got, '127.0.0.1:0', 'get_ip_port - get host ip and port zero';
 }
+####### IPv6
+{
+    my $host = { server => { ip => '[::]', port => undef } };
+    my $checkport = undef;
+    my $got = get_ip_port($host, $checkport);
+    is $got, '', 'get_ip_port - host port and checkport is undef';
+}
+{
+    my $host = { server => { ip => '[::1]', port => 80 } };
+    my $checkport = undef;
+    my $got = get_ip_port($host, $checkport);
+    is $got, '[::1]:80', 'get_ip_port - get host ip6 and port';
+}
+{
+    my $host = { server => { ip => '[::1]', port => 80 } };
+    my $checkport = 8080;
+    my $got = get_ip_port($host, $checkport);
+    is $got, '[::1]:8080', 'get_ip_port - get host ip6 and checkport';
+}
+{
+    my $host = { server => { ip => '[::1]', port => 0 } };
+    my $checkport = undef;
+    my $got = get_ip_port($host, $checkport);
+    is $got, '127.0.0.1:0', 'get_ip_port - get host ip6 and port zero';
+}
+{
+    my $host = { server => { ip => '[fe80::200:1aff:fe19:5534%eth0]', port => 0 } };
+    my $checkport = undef;
+    my $got = get_ip_port($host, $checkport);
+    is $got, '[fe80::200:1aff:fe19:5534%eth0]:0', 'get_ip_port - get host ip6(LinkLocal) and port zero';
+}
 #   - get_health_check_id_str
 {
     my $v = undef;