On 10/20/2011 02:35 PM, Steve Poole wrote:
On Thu, 2011-10-20 at 13:24 +0800, Jonathan Lu wrote:
On 10/19/2011 06:03 PM, Steve Poole wrote:
On Mon, 2011-10-17 at 15:14 +0800, Jonathan Lu wrote:
Hi net-devs,
I've got a problem on AIX operating system when IPv6 is enabled,which
can be easily reproduced by attached test case NetworkInterfaceTest.java.
On AIX paltform, the /proc file system behaves differently from Linux,
so we cannot just read required lines from /proc/net/if_inet6 but to
call ioctl to get needed information. A patch is available for OpenJDK8
code base, see attachment patch.diff.
Is anybody interested in this topic?
I'm quite aware of the fact that so far there's no publicly available
building scripts for OpenJDK8 on AIX operating system, but before
everything settles down, is anybody willing to review the patch? any
ideas about how to integrate it?
Best regards!
Hi Jonathan - can you add a copyright header to the testcase and see if
you can make the testcase fit into a jtreg test format?
Hi Steve,
Thanks for your suggestion.
I've updated the test case to fit into a jtreg format, see the
attachment NetworkInterfaceTest.java.
Cool - at a quick glance it looks fine - except your're missing the IBM
attribution comment. I'll send you the details.
- Jonathan
Thanks Steve, I've updated the test case and patch, see the attachments.
I've added IBM portions copyright comment to both headers.
- Jonathan
/*
* Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Portions Copyright (c) 2011 IBM Corporation
*/
import java.net.*;
import java.util.*;
/* @test NetworkInterfaceTest
* @summary java.net.NetworkInterface.getNetworkInterfaces() does not work properly on AIX with IPv6
*/
public class NetworkInterfaceTest {
java.net.NetworkInterface pnics;
java.util.Enumeration nics1;
NetworkInterfaceTest() throws Exception{
java.net.NetworkInterface jnic;
java.util.Enumeration<NetworkInterface> nics;
List lst = new ArrayList();
List lst1 = new ArrayList();
try {
nics = java.net.NetworkInterface.getNetworkInterfaces();
while (nics.hasMoreElements()) {
jnic = (java.net.NetworkInterface) nics.nextElement();
lst = jnic.getInterfaceAddresses();
nics1 = jnic.getInetAddresses();
while (nics1.hasMoreElements()) {
InetAddress addr1 = (InetAddress) nics1.nextElement();
if (!(lst1.contains(addr1))) {
lst1.add(addr1);
}
}
if(lst.size() != lst1.size()){
throw new Exception("NetworkInterfaceTest Failed");
}
lst1.clear();
}
} catch (java.lang.Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception{
new NetworkInterfaceTest();
}
}
diff -r 4788745572ef -r d7cd8c7c05af src/solaris/native/java/net/NetworkInterface.c
--- a/src/solaris/native/java/net/NetworkInterface.c Mon Oct 17 19:06:53 2011 -0700
+++ b/src/solaris/native/java/net/NetworkInterface.c Thu Oct 20 16:54:37 2011 +0800
@@ -23,6 +23,13 @@
* questions.
*/
+/*
+ * Portions Copyright (c) 2011 IBM Corporation
+ */
+
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+#define SIZE(p) MAX((p).sa_len, sizeof(p))
+
#include <errno.h>
#include <strings.h>
@@ -1095,12 +1102,96 @@
return ifs;
}
-
+#if defined(AF_INET6)
+#if defined(AIX)
+/*
+ * Enumerates and returns all IPv6 interfaces on AIX
+ */
+static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
+ struct ifconf ifc;
+ struct ifreq *ifreqP;
+ char *buf;
+ int numifs;
+ unsigned i;
+ unsigned bufsize;
+ char *cp, *cplimit;
+
+ /* use SIOCGSIZIFCONF to get size for SIOCGIFCONF */
+
+ ifc.ifc_buf = NULL;
+ if (ioctl(sock, SIOCGSIZIFCONF, &(ifc.ifc_len)) < 0) {
+ NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
+ "ioctl SIOCGSIZIFCONF failed");
+ return ifs;
+ }
+ bufsize = ifc.ifc_len;
+
+ buf = (char *)malloc(bufsize);
+ if (!buf) {
+ JNU_ThrowOutOfMemoryError(env, "Network interface native buffer allocation failed");
+ return ifs;
+ }
+ ifc.ifc_len = bufsize;
+ ifc.ifc_buf = buf;
+ if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
+ NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
+ "ioctl CSIOCGIFCONF failed");
+ (void) free(buf);
+ return ifs;
+ }
+
+ /*
+ * Iterate through each interface
+ */
+ ifreqP = ifc.ifc_req;
+ cp=(char *)ifc.ifc_req;
+ cplimit=cp+ifc.ifc_len;
+ for (;cp<cplimit;cp+=(sizeof(ifreqP->ifr_name) + SIZE(ifreqP->ifr_addr))){
+ ifreqP=(struct ifreq *)cp;
+ struct ifreq if2;
+
+ memset((char *)&if2, 0, sizeof(if2));
+ strcpy(if2.ifr_name, ifreqP->ifr_name);
+
+ /*
+ * Skip interface that aren't UP
+ */
+ if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) >= 0) {
+ if (!(if2.ifr_flags & IFF_UP)) {
+ continue;
+ }
+ }
+
+ if (ifreqP->ifr_addr.sa_family != AF_INET6)
+ continue;
+
+ /*
+ * Add to the list
+ */
+ ifs = addif(env, sock, ifreqP->ifr_name, ifs,
+ (struct sockaddr *)&(ifreqP->ifr_addr),
+ AF_INET6,0,-1);
+
+ /*
+ * If an exception occurred then free the list
+ */
+ if ((*env)->ExceptionOccurred(env)) {
+ free(buf);
+ freeif(ifs);
+ return NULL;
+ }
+ }
+
+ /*
+ * Free socket and buffer
+ */
+ free(buf);
+ return ifs;
+}
+#else
/*
* Enumerates and returns all IPv6 interfaces on Linux
*/
-
-#ifdef AF_INET6
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
FILE *f;
char addr6[40], devname[21];
@@ -1142,6 +1233,7 @@
return ifs;
}
#endif
+#endif
static int getIndex(int sock, const char *name){