Re: [jgroups-dev] JGroups preference for IPv6

Bela Ban <[email protected]>
Newsgroups gmane.comp.java.javagroups.devel
Message-ID <[email protected]>
The attached patch shows a simple fix to convert an IPv4 multicast 
address into an IPv6 multicast address, in an IPv6 stack.

Unless someone disagrees, I'd like to commit this change.

Brian Stansberry wrote:
> 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.

-- 
Bela Ban
Lead JGroups / Clustering Team
JBoss

------------------------------------------------------------------------------
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
ns.patch (text/plain, 1.4 KB)
Index: src/org/jgroups/conf/PropertyConverters.java
===================================================================
--- src/org/jgroups/conf/PropertyConverters.java	(revision 1.17)
+++ src/org/jgroups/conf/PropertyConverters.java	Mon Apr 12 10:14:23 CEST 2010
@@ -6,12 +6,10 @@
 import org.jgroups.stack.Configurator;
 import org.jgroups.stack.Protocol;
 import org.jgroups.util.Util;
+import org.jgroups.util.StackType;
 
 import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.Inet6Address;
-import java.net.SocketException;
+import java.net.*;
 import java.util.List;
 import java.util.Enumeration;
 import java.util.ArrayList;
@@ -179,6 +177,14 @@
                 return Float.parseFloat(propertyValue);
             } else if(InetAddress.class.equals(propertyFieldType)) {
                 InetAddress retval=InetAddress.getByName(propertyValue);
+
+                if(retval instanceof Inet4Address && retval.isMulticastAddress() && Util.getIpStackType() == StackType.IPv6) {
+                    String tmp="FF0e::" + propertyValue;
+                    retval=InetAddress.getByName(tmp);
+                    return retval;
+                }
+
+
                 if(check_scope && retval instanceof Inet6Address && retval.isLinkLocalAddress()) {
                     // check scope
                     Inet6Address addr=(Inet6Address)retval;
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.