[ipv6] RFR: 8223532: Don't try creating IPv4 sockets in NetworkInterface.c if IPv4 is not supported

Chris Hegarty chris.hegarty at oracle.com
Fri May 10 10:56:27 UTC 2019


Arthur,

On 09/05/2019 21:05, Arthur Eubanks wrote:
> 
> ...
> New webrev:
> http://cr.openjdk.java.net/~aeubanks/8223532/webrev.02/index.html
> This also contains some changes from Mark's suggestions. That thread 
> appears to have been separated from this thread in my inbox for some reason.

Curve ball! Sorry.

There is much history in this native code, and how ipv6_available
evolved ( it is far from perfect! ). The use of ipv4_available ( as
Mark mentions ) is not quite a good fit here (SOCK_STREAM Vs.
SOCK_DGRAM).

After further thought, I have now convinced myself that, from the
perspective of the JDK's usage ( at least in NetworkInterface ), that
it would be better to effectively treat EPROTONOSUPPORT and EAFNOSUPPORT
the same, as "the specified protocol, domain, type, address family, is
not supported". This should not be controversial given the constant
values that are passed to socket(2).

Given this, then the changes can be minimal, direct, and localized.
Effectively:

   -      if (errno != EPROTONOSUPPORT) {
   ---
   +      if (!(errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)) {

And in enumInterfaces, something like:

     /* Enumerate IPv4 addresses */
     sock = openSocket(env, AF_INET);
     if (sock < 0 && (*env)->ExceptionOccurred(env)) {
         return NULL;
     }

     if (sock >= 0) {
         ifs = enumIPv4Interfaces(env, sock, NULL);
         close(sock);

         if ((*env)->ExceptionOccurred(env)) {
             freeif(ifs);
             return NULL;
         }
     }
     ...

         if (ipv6_available()) {
            sock = openSocket(env, AF_INET6);
            if (sock < 0 && (*env)->ExceptionOccurred(env)) {
                freeif(ifs);
                return NULL;
            }

            if (sock >= 0) {
                ifs = enumIPv6Interfaces(env, sock, ifs);
                close(sock);

                if ((*env)->ExceptionOccurred(env)) {
                    freeif(ifs);
                    return NULL;
                }
            }
        }
---

Let's keep this JIRA issue focused on the task in-hand ( ip6-only
support ). Other technical debt and behavioural issues ( beyond the most
trivial ) can be addressed separately.

-Chris.


More information about the net-dev mailing list