[jgroups-dev] JGroups preference for IPv6

Brian Stansberry <[email protected]>
Newsgroups gmane.comp.java.javagroups.devel
Message-ID <[email protected]>
This is somewhat related to previous discussion at [1] and related 
JGRP-1152 [2].

Since we've upgraded JBoss AS trunk to JGroups 2.10.0.Alpha3, it will no 
longer start on a machine that supports both IPv4 and IPv6. This is 
because we don't specify java.net.preferIPv4Stack in our startup 
scripts, so Util.getIpStackType() returns StackType.IPv6. But we 
configure IPv4 multicast addresses by default so the JGRP-1152 check 
fails the startup.

Since we're specifying IPv4 addresses by default, perhaps our startup 
scripts could set -Djava.net.preferIPv4Stack=true. Jason can comment if 
he likes; it may be necessary although I don't really like it (yet 
another config in an obscure location).

I'm wondering if JGroups can handle this situation more flexibly. I've 
attached an *untested* patch that shows what I was thinking:

1) Add a new StackType.Either which Util.getIpStackType() returns if the 
OS supports both stack types and no java.net.preferXXX property is set.

2) Configurator.setupProtocolStack() recognizes StackType.Either and 
when it's analyzing the InetAddresses it's seeing, it uses the first one 
it sees to switch to either StackType.IPv4 or StackType.IPv6. So in this 
case the users choice of addresses controls the behavior.

3) Thereafter, the normal JGRP-1152 checks apply, so illegal 
inconsistencies are caught and rejected.

I checked for other uses of Util.getIpStackType() and tweaked the one 
that needed it to deal with a return value of StackType.Either. I 
haven't checked *all* uses of StackType though; wanted to get some 
feedback first.


-- 
Brian Stansberry
Lead, AS Clustering
JBoss by Red Hat


[1] 
http://old.nabble.com/Protocol-stack-issue-on-dual-stack-%28IPv4-and-v6%29-machines-td27544685.html

[2] https://jira.jboss.org/jira/browse/JGRP-1152

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

_______________________________________________
Javagroups-development mailing list
StackType.Either.patch (text/plain, 3.4 KB)
### Eclipse Workspace Patch 1.0
#P JGroups
Index: src/org/jgroups/util/StackType.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/util/StackType.java,v
retrieving revision 1.1
diff -u -r1.1 StackType.java
--- src/org/jgroups/util/StackType.java	26 Oct 2009 14:09:47 -0000	1.1
+++ src/org/jgroups/util/StackType.java	9 Apr 2010 19:56:33 -0000
@@ -5,5 +5,5 @@
  * @version $Id: StackType.java,v 1.1 2009/10/26 14:09:47 belaban Exp $
  */
 public enum StackType {
-    IPv4, IPv6, Unknown
+    IPv4, IPv6, Unknown, Either;
 }
Index: src/org/jgroups/util/Util.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/util/Util.java,v
retrieving revision 1.259
diff -u -r1.259 Util.java
--- src/org/jgroups/util/Util.java	25 Mar 2010 17:03:20 -0000	1.259
+++ src/org/jgroups/util/Util.java	9 Apr 2010 19:56:33 -0000
@@ -3327,8 +3327,8 @@
                 InetAddress address = (InetAddress) addresses.nextElement() ;
 
                 // check if we find an address of correct version
-                if ((address instanceof Inet4Address && (ip_version == StackType.IPv4)) ||
-                        (address instanceof Inet6Address && (ip_version == StackType.IPv6))) {
+                if ((address instanceof Inet4Address && (ip_version == StackType.IPv4 || ip_version == StackType.Either)) ||
+                        (address instanceof Inet6Address && (ip_version == StackType.IPv6 || ip_version == StackType.Either))) {
                     supportsVersion = true ;
                     break ;
                 }
@@ -3365,7 +3365,7 @@
                 return StackType.IPv4;
             if(Boolean.getBoolean(Global.IPv6))
                 return StackType.IPv6;
-            return StackType.IPv6;
+            return StackType.Either;
 		}
 		return StackType.Unknown;
     }
Index: src/org/jgroups/stack/Configurator.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/stack/Configurator.java,v
retrieving revision 1.79
diff -u -r1.79 Configurator.java
--- src/org/jgroups/stack/Configurator.java	5 Mar 2010 08:49:19 -0000	1.79
+++ src/org/jgroups/stack/Configurator.java	9 Apr 2010 19:56:33 -0000
@@ -106,10 +106,15 @@
             // Else pass
 
             for(InetAddress addr: addrs) {
-                if(addr instanceof Inet6Address && ip_version == StackType.IPv4)
-                    throw new IllegalArgumentException("found IPv6 address " + addr + " in an IPv4 stack");
-                if(addr instanceof Inet4Address && addr.isMulticastAddress() && ip_version == StackType.IPv6)
-                    throw new Exception("found IPv4 multicast address " + addr + " in an IPv6 stack");
+                if (ip_version == StackType.Unknown) {
+                   ip_version = (addr instanceof Inet6Address) ? StackType.IPv6 : StackType.IPv4;
+                }
+                else {
+                    if(addr instanceof Inet6Address && ip_version == StackType.IPv4)
+                        throw new IllegalArgumentException("found IPv6 address " + addr + " in an IPv4 stack");
+                    if(addr instanceof Inet4Address && addr.isMulticastAddress() && ip_version == StackType.IPv6)
+                        throw new Exception("found IPv4 multicast address " + addr + " in an IPv6 stack");
+                }
             }
         }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.