LVS
lvs-users
Google
 
Web LinuxVirtualServer.org

Re: [lvs-users] IPv6 vs IPv4 fwmark services

To: Sohgo Takeuchi <sohgo@xxxxxxxxxxxxxxxx>
Subject: Re: [lvs-users] IPv6 vs IPv4 fwmark services
Cc: lvs-users@xxxxxxxxxxxxxxxxxxxxxx, wferi@xxxxxxx
From: Simon Horman <horms@xxxxxxxxxxxx>
Date: Wed, 16 Feb 2011 16:54:49 +0900
On Wed, Feb 16, 2011 at 04:04:11PM +0900, Sohgo Takeuchi wrote:
> 
> From: Simon Horman <horms@xxxxxxxxxxxx>
> |
> > On Tue, Feb 15, 2011 at 05:44:32PM +0900, Sohgo Takeuchi wrote:
> >> 
> >> From: Ferenc Wagner <wferi@xxxxxxx>
> >> |
> >> > Sohgo Takeuchi <sohgo@xxxxxxxxxxxxxxxx> writes:
> >>
> >> I've found that another problem about an IPv6 fwmark of
> >> ldirectord. The ldirectord does not handle an output of the
> >> ipvsadm command when using an IPv6 fwmark.  I've made a
> >> patch. If you are interested in the patch, please try.
> > 
> > Takeuchi-san, let me know if you want this merged too.
> 
> Hi Simon,
> 
> Yes please. But, this patch had a bug. I attach a new one.

Thanks, I have queued up the following:

# HG changeset patch
# User Sohgo Takeuchi <sohgo@xxxxxxxxxxxxxxxx>
# Date 1297842827 -32400
# Node ID dac65bb8d73361cc546d5504e8cd7884d1fcc070
# Parent  8427c046434779da1972463718443452f9fefdc1
ldirectord: handle the output of ipvsadm when using an IPv6 fwmark

Signed-off-by: Simon Horman <horms@xxxxxxxxxxxx>

diff -r 8427c0464347 -r dac65bb8d733 ldirectord/ldirectord.in
--- a/ldirectord/ldirectord.in  Wed Feb 16 14:50:08 2011 +0900
+++ b/ldirectord/ldirectord.in  Wed Feb 16 16:53:47 2011 +0900
@@ -2411,15 +2411,15 @@
                if (not defined $line) {
                        last;
                }
-               if ($line =~ 
/^(\w+)\s+(\d+\.\d+\.\d+\.\d+\:\d+|\[[0-9A-Fa-f:]+\]:\d+|\d+)\s+(\w+)\s+persistent\s+(\d+)\s+mask\s+(.*)/)
 {
-                       $real_service = "$2 ".lc($1);
-                       $oldsrv{"$real_service"} = {"real"=>{}, 
"scheduler"=>$3, "persistent"=>$4, "netmask"=>$5};
-               } elsif ($line =~ 
/^(\w+)\s+(\d+\.\d+\.\d+\.\d+\:\d+|\[[0-9A-Fa-f:]+\]:\d+|\d+)\s+(\w+)\s+persistent\s+(\d+)/)
 {
-                       $real_service = "$2 ".lc($1);
-                       $oldsrv{"$real_service"} = {"real"=>{}, 
"scheduler"=>$3, "persistent"=>$4};
-               } elsif ($line =~ 
/^(\w+)\s+(\d+\.\d+\.\d+\.\d+\:\d+|\[[0-9A-Fa-f:]+\]:\d+|\d+)\s+(\w+)/) {
-                       $real_service = "$2 ".lc($1);
-                       $oldsrv{"$real_service"} = {"real"=>{}, 
"scheduler"=>$3};
+               if ($line =~ 
/^(\w+)\s+(\d+\.\d+\.\d+\.\d+\:\d+|\[[0-9A-Fa-f:]+\]:\d+|\d+)( 
IPv6)?\s+(\w+)\s+persistent\s+(\d+)\s+mask\s+(.*)/) {
+                       $real_service = &gen_real_service_str($2, $1, $3);
+                       $oldsrv{"$real_service"} = {"real"=>{}, 
"scheduler"=>$4, "persistent"=>$5, "netmask"=>$6};
+               } elsif ($line =~ 
/^(\w+)\s+(\d+\.\d+\.\d+\.\d+\:\d+|\[[0-9A-Fa-f:]+\]:\d+|\d+)( 
IPv6)?\s+(\w+)\s+persistent\s+(\d+)/) {
+                       $real_service = &gen_real_service_str($2, $1, $3);
+                       $oldsrv{"$real_service"} = {"real"=>{}, 
"scheduler"=>$4, "persistent"=>$5};
+               } elsif ($line =~ 
/^(\w+)\s+(\d+\.\d+\.\d+\.\d+\:\d+|\[[0-9A-Fa-f:]+\]:\d+|\d+)( IPv6)?\s+(\w+)/) 
{
+                       $real_service = &gen_real_service_str($2, $1, $3);
+                       $oldsrv{"$real_service"} = {"real"=>{}, 
"scheduler"=>$4};
                } elsif ($line =~ /^  
->\s+(\d+\.\d+\.\d+\.\d+\:\d+|\[[0-9A-Fa-f:]+\]:\d+)\s+(\w+)\s+(\d+)/) {
                        if (not defined( $real_service)) {
                                &ld_debug(2, "Real server read from ipvsadm " .
@@ -2446,6 +2446,20 @@
        return(\%oldsrv);
 }
 
+sub gen_real_service_str
+{
+       my ($service_address, $protocol, $v6flag) = @_;
+
+       return "$service_address ".lc($protocol).(defined($v6flag) ? "6" : "");
+}
+
+sub get_real_service_str
+{
+       my ($v) = (@_);
+
+       return &get_virtual($v) . " "  . $v->{protocol} . ($v->{addressfamily} 
== AF_INET6 ? "6" : "");
+}
+
 sub ld_start
 {
        my $oldsrv;
@@ -2459,7 +2473,7 @@
 
        # make sure virtual servers are up to date
        foreach $nv (@VIRTUAL) {
-               my $real_service = &get_virtual($nv) . " "  . $nv->{protocol};
+               my $real_service = &get_real_service_str($nv);
 
                if (exists($oldsrv->{"$real_service"})) {
                        # service exists, modify it
@@ -2476,7 +2490,7 @@
        # make sure real servers are up to date
        foreach $nv (@VIRTUAL) {
                my $nreal = $nv->{real};
-               my $ov = $oldsrv->{&get_virtual($nv) . " " . $nv->{protocol}};
+               my $ov = $oldsrv->{&get_real_service_str($nv)};
                my $or = $ov->{real};
                my $fallback = fallback_find($nv);
 
@@ -2506,7 +2520,7 @@
                        delete($$or{$k});
                }
 
-               delete($oldsrv->{&get_virtual($nv) . " " . $nv->{protocol}});
+               delete($oldsrv->{&get_real_service_str($nv)});
                &fallback_on($nv);
        }
 
@@ -2519,8 +2533,7 @@
 
        # remove remaining entries for virtual servers
        foreach $nv (@OLDVIRTUAL) {
-               if (! defined($oldsrv->{&get_virtual($nv) . " " .
-                                       $nv->{protocol}})) {
+               if (! defined($oldsrv->{&get_real_service_str($nv)})) {
                        next;
                }
                purge_virtual($nv, "start");
@@ -3755,7 +3768,7 @@
        $virtual_str = &get_virtual($v);
 
        $oldsrv=&ld_read_ipvsadm();
-       $ov=$oldsrv->{$virtual_str . " " . $v->{"protocol"}};
+       $ov=$oldsrv->{&get_real_service_str($v)};
        if(!defined($ov)){
                return;
        }
@@ -3875,7 +3888,7 @@
        #if the server exists then restore its weight
        # otherwise add the server
        $oldsrv=&ld_read_ipvsadm();
-       $ov=$oldsrv->{&get_virtual($v) . " " . $v->{"protocol"}};
+       $ov=$oldsrv->{&get_real_service_str($v)};
        if(defined($ov)){
                $or=$ov->{"real"}->{$rservice};
        }

_______________________________________________
Please read the documentation before posting - it's available at:
http://www.linuxvirtualserver.org/

LinuxVirtualServer.org mailing list - lvs-users@xxxxxxxxxxxxxxxxxxxxxx
Send requests to lvs-users-request@xxxxxxxxxxxxxxxxxxxxxx
or go to http://lists.graemef.net/mailman/listinfo/lvs-users

<Prev in Thread] Current Thread [Next in Thread>