From 0b34da48d6a741fd76a8df2a941a5e5729721222 Mon Sep 17 00:00:00 2001 From: chegar Date: Thu, 20 Sep 2012 09:36:55 -0400 Subject: [PATCH] 7193520: Removed references to Linux kernel version 2.2 Summary: Linux kernel version 2.2 isn't supported anymore. Reviewed-by: chegar, dsamersoff, alanb Contributed-by: John Zavgren --- .../net/AbstractPlainDatagramSocketImpl.java | 5 - .../native/java/net/Inet4AddressImpl.c | 14 +- .../native/java/net/Inet6AddressImpl.c | 20 +- .../native/java/net/NetworkInterface.c | 24 +- .../native/java/net/PlainDatagramSocketImpl.c | 330 +++--------------- src/solaris/native/java/net/PlainSocketImpl.c | 6 +- .../native/java/net/SocketInputStream.c | 4 +- src/solaris/native/java/net/bsd_close.c | 2 +- src/solaris/native/java/net/net_util_md.c | 47 +-- src/solaris/native/java/net/net_util_md.h | 1 - 10 files changed, 92 insertions(+), 361 deletions(-) diff --git a/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java b/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java index 32d1e7094..4999dfa5f 100644 --- a/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java +++ b/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java @@ -48,11 +48,6 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl protected InetAddress connectedAddress = null; private int connectedPort = -1; - /* cached socket options */ - private int multicastInterface = 0; - private boolean loopbackMode = true; - private int ttl = -1; - private static final String os = AccessController.doPrivileged( new sun.security.action.GetPropertyAction("os.name") ); diff --git a/src/solaris/native/java/net/Inet4AddressImpl.c b/src/solaris/native/java/net/Inet4AddressImpl.c index 84f739ed5..58798c7f8 100644 --- a/src/solaris/native/java/net/Inet4AddressImpl.c +++ b/src/solaris/native/java/net/Inet4AddressImpl.c @@ -647,9 +647,10 @@ ping4(JNIEnv *env, jint fd, struct sockaddr_in* him, jint timeout, #ifdef __linux__ if (errno != EINVAL && errno != EHOSTUNREACH) /* - * On some Linuxes, when bound to the loopback interface, sendto - * will fail and errno will be set to EINVAL or EHOSTUNREACH. - * When that happens, don't throw an exception, just return false. + * On some Linux versions, when a socket is bound to the loopback + * interface, sendto will fail and errno will be set to + * EINVAL or EHOSTUNREACH. When that happens, don't throw an + * exception, just return false. */ #endif /*__linux__ */ NET_ThrowNew(env, errno, "Can't send ICMP packet"); @@ -813,9 +814,10 @@ Java_java_net_Inet4AddressImpl_isReachable0(JNIEnv *env, jobject this, case EINVAL: case EHOSTUNREACH: /* - * On some Linuxes, when bound to the loopback interface, connect - * will fail and errno will be set to EINVAL or EHOSTUNREACH. - * When that happens, don't throw an exception, just return false. + * On some Linux versions, when a socket is bound to the loopback + * interface, connect will fail and errno will be set to EINVAL + * or EHOSTUNREACH. When that happens, don't throw an exception, + * just return false. */ #endif /* __linux__ */ close(fd); diff --git a/src/solaris/native/java/net/Inet6AddressImpl.c b/src/solaris/native/java/net/Inet6AddressImpl.c index 17be097e9..6b7e233d9 100644 --- a/src/solaris/native/java/net/Inet6AddressImpl.c +++ b/src/solaris/native/java/net/Inet6AddressImpl.c @@ -336,13 +336,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, } (*env)->SetByteArrayRegion(env, ipaddress, 0, 16, (jbyte *)&(((struct sockaddr_in6*)iterator->ai_addr)->sin6_addr)); -#ifdef __linux__ - if (!kernelIsV22()) { - scope = ((struct sockaddr_in6*)iterator->ai_addr)->sin6_scope_id; - } -#else scope = ((struct sockaddr_in6*)iterator->ai_addr)->sin6_scope_id; -#endif if (scope != 0) { /* zero is default value, no need to set */ (*env)->SetIntField(env, iaObj, ia6_scopeidID, scope); (*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE); @@ -507,8 +501,9 @@ ping6(JNIEnv *env, jint fd, struct sockaddr_in6* him, jint timeout, #ifdef __linux__ if (errno != EINVAL && errno != EHOSTUNREACH) /* - * On some Linuxes, when bound to the loopback interface, sendto - * will fail and errno will be set to EINVAL or EHOSTUNREACH. + * On some Linux versions, when a socket is bound to the + * loopback interface, sendto will fail and errno will be + * set to EINVAL or EHOSTUNREACH. * When that happens, don't throw an exception, just return false. */ #endif /*__linux__ */ @@ -623,7 +618,7 @@ Java_java_net_Inet6AddressImpl_isReachable0(JNIEnv *env, jobject this, * If we can create a RAW socket, then when can use the ICMP ECHO_REQUEST * otherwise we'll try a tcp socket to the Echo port (7). * Note that this is empiric, and not connecting could mean it's blocked - * or the echo servioe has been disabled. + * or the echo service has been disabled. */ fd = JVM_Socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); @@ -680,9 +675,10 @@ Java_java_net_Inet6AddressImpl_isReachable0(JNIEnv *env, jobject this, case EINVAL: case EHOSTUNREACH: /* - * On some Linuxes, when bound to the loopback interface, connect - * will fail and errno will be set to EINVAL or EHOSTUNREACH. - * When that happens, don't throw an exception, just return false. + * On some Linux versions, when a socket is bound to the + * loopback interface, connect will fail and errno will + * be set to EINVAL or EHOSTUNREACH. When that happens, + * don't throw an exception, just return false. */ #endif /* __linux__ */ close(fd); diff --git a/src/solaris/native/java/net/NetworkInterface.c b/src/solaris/native/java/net/NetworkInterface.c index 9ebea2bf5..1a9419e0d 100644 --- a/src/solaris/native/java/net/NetworkInterface.c +++ b/src/solaris/native/java/net/NetworkInterface.c @@ -769,14 +769,14 @@ static netif *enumInterfaces(JNIEnv *env) { return NULL; } - /* return partial list if exception occure in the middle of process ???*/ + /* return partial list if an exception occurs in the middle of process ???*/ /* * If IPv6 is available then enumerate IPv6 addresses. */ #ifdef AF_INET6 - /* User can disable ipv6 expicitly by -Djava.net.preferIPv4Stack=true, + /* User can disable ipv6 explicitly by -Djava.net.preferIPv4Stack=true, * so we have to call ipv6_available() */ if (ipv6_available()) { @@ -887,7 +887,7 @@ netif *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct soc addrP->next = 0; if (family == AF_INET) { /* - * Deal with brodcast addr & subnet mask + * Deal with broadcast addr & subnet mask */ struct sockaddr * brdcast_to = (struct sockaddr *) ((char *) addrP + sizeof(netaddr) + addr_size); addrP->brdcast = getBroadcast(env, sock, name, brdcast_to ); @@ -898,7 +898,7 @@ netif *addif(JNIEnv *env, int sock, const char * if_name, netif *ifs, struct soc } /** - * Deal with virtual interface with colon notaion e.g. eth0:1 + * Deal with virtual interface with colon notation e.g. eth0:1 */ name_colonP = strchr(name, ':'); if (name_colonP != NULL) { @@ -1327,13 +1327,13 @@ static int openSocketWithFallback(JNIEnv *env, const char *ifname){ } /** - * Solaris requires that we have IPv6 socket to query an - * interface without IPv4 address - check it here - * POSIX 1 require the kernell to return ENOTTY if the call is - * unappropriate for device e.g. NETMASK for device having IPv6 - * only address but not all devices follows the standart so - * fallback on any error. It's not an ecology friendly but more - * reliable. + * Solaris requires that we have an IPv6 socket to query an + * interface without an IPv4 address - check it here. + * POSIX 1 require the kernel to return ENOTTY if the call is + * inappropriate for a device e.g. the NETMASK for a device having IPv6 + * only address but not all devices follow the standard so + * fall back on any error. It's not an ecologically friendly gesture + * but more reliable. */ if (! alreadyV6 ){ @@ -1359,7 +1359,7 @@ static int openSocketWithFallback(JNIEnv *env, const char *ifname){ /* * Enumerates and returns all IPv4 interfaces - * (linux verison) + * (linux verision) */ static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) { diff --git a/src/solaris/native/java/net/PlainDatagramSocketImpl.c b/src/solaris/native/java/net/PlainDatagramSocketImpl.c index 19316fd46..40b375de5 100644 --- a/src/solaris/native/java/net/PlainDatagramSocketImpl.c +++ b/src/solaris/native/java/net/PlainDatagramSocketImpl.c @@ -73,16 +73,6 @@ static jfieldID pdsi_connected; static jfieldID pdsi_connectedAddress; static jfieldID pdsi_connectedPort; -#ifdef __linux__ -static jboolean isOldKernel; -#endif - -#if defined(__linux__) && defined(AF_INET6) -static jfieldID pdsi_multicastInterfaceID; -static jfieldID pdsi_loopbackID; -static jfieldID pdsi_ttlID; -#endif - extern void setDefaultScopeID(JNIEnv *env, struct sockaddr *him); extern int getDefaultScopeID(JNIEnv *env); @@ -174,41 +164,6 @@ Java_java_net_PlainDatagramSocketImpl_init(JNIEnv *env, jclass cls) { Java_java_net_Inet6Address_init(env, 0); Java_java_net_NetworkInterface_init(env, 0); -#ifdef __linux__ - /* - * We need to determine if this is a 2.2 kernel. - */ - if (uname(&sysinfo) == 0) { - sysinfo.release[3] = '\0'; - isOldKernel = (strcmp(sysinfo.release, "2.2") == 0); - } else { - /* - * uname failed - move to plan B and examine /proc/version - * If this fails assume that /proc has changed and that - * this must be new /proc format and hence new kernel. - */ - FILE *fP; - isOldKernel = JNI_FALSE; - if ((fP = fopen("/proc/version", "r")) != NULL) { - char ver[25]; - if (fgets(ver, sizeof(ver), fP) != NULL) { - isOldKernel = (strstr(ver, "2.2.") != NULL); - } - fclose(fP); - } - } - -#ifdef AF_INET6 - pdsi_multicastInterfaceID = (*env)->GetFieldID(env, cls, "multicastInterface", "I"); - CHECK_NULL(pdsi_multicastInterfaceID); - pdsi_loopbackID = (*env)->GetFieldID(env, cls, "loopbackMode", "Z"); - CHECK_NULL(pdsi_loopbackID); - pdsi_ttlID = (*env)->GetFieldID(env, cls, "ttl", "I"); - CHECK_NULL(pdsi_ttlID); -#endif - -#endif - } /* @@ -257,7 +212,7 @@ Java_java_net_PlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this, return; } - /* intialize the local port */ + /* initialize the local port */ if (localport == 0) { /* Now that we're a connected socket, let's extract the port number * that the system chose for us and store it in the Socket object. @@ -308,20 +263,14 @@ Java_java_net_PlainDatagramSocketImpl_connect0(JNIEnv *env, jobject this, return; } -#ifdef __linux__ - if (isOldKernel) { - int t = 0; - setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, (char*) &t, sizeof(int)); - } else -#endif setDefaultScopeID(env, (struct sockaddr *)&rmtaddr); - { - if (JVM_Connect(fd, (struct sockaddr *)&rmtaddr, len) == -1) { - NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException", - "Connect failed"); - return; - } + + if (JVM_Connect(fd, (struct sockaddr *)&rmtaddr, len) == -1) { + NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException", + "Connect failed"); + return; } + } /* @@ -347,12 +296,6 @@ Java_java_net_PlainDatagramSocketImpl_disconnect0(JNIEnv *env, jobject this, jin fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); #if defined(__linux__) || defined(_ALLBSD_SOURCE) -#ifdef __linux__ - if (isOldKernel) { - int t = 1; - setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, (char*) &t, sizeof(int)); - } else { -#endif /* __linux__ */ memset(&addr, 0, sizeof(addr)); #ifdef AF_INET6 if (ipv6_available()) { @@ -369,14 +312,10 @@ Java_java_net_PlainDatagramSocketImpl_disconnect0(JNIEnv *env, jobject this, jin JVM_Connect(fd, (struct sockaddr *)&addr, len); #ifdef __linux__ - // After disconnecting a UDP socket, Linux kernel will set - // local port to zero if the port number comes from implicit - // bind. Successive send/recv on the same socket will fail. - // So bind again with former port number here. int localPort = 0; - if (JVM_GetSockName(fd, (struct sockaddr *)&addr, &len) == -1) { + if (JVM_GetSockName(fd, (struct sockaddr *)&addr, &len) == -1) return; - } + localPort = NET_GetPortFromSockaddr((struct sockaddr *)&addr); if (localPort == 0) { localPort = (*env)->GetIntField(env, this, pdsi_localPortID); @@ -388,9 +327,10 @@ Java_java_net_PlainDatagramSocketImpl_disconnect0(JNIEnv *env, jobject this, jin { ((struct sockaddr_in*)&addr)->sin_port = htons(localPort); } + NET_Bind(fd, (struct sockaddr *)&addr, len); } - } + #endif #else JVM_Connect(fd, 0, 0); @@ -448,11 +388,7 @@ Java_java_net_PlainDatagramSocketImpl_send(JNIEnv *env, jobject this, packetBufferOffset = (*env)->GetIntField(env, packet, dp_offsetID); packetBufferLen = (*env)->GetIntField(env, packet, dp_lengthID); -#ifdef __linux__ - if (connected && !isOldKernel) { -#else if (connected) { -#endif /* arg to NET_Sendto () null in this case */ len = 0; rmtaddrP = 0; @@ -466,14 +402,14 @@ Java_java_net_PlainDatagramSocketImpl_send(JNIEnv *env, jobject this, if (packetBufferLen > MAX_BUFFER_LEN) { /* When JNI-ifying the JDK's IO routines, we turned - * read's and write's of byte arrays of size greater + * reads and writes of byte arrays of size greater * than 2048 bytes into several operations of size 2048. * This saves a malloc()/memcpy()/free() for big * buffers. This is OK for file IO and TCP, but that * strategy violates the semantics of a datagram protocol. * (one big send) != (several smaller sends). So here - * we *must* alloc the buffer. Note it needn't be bigger - * than 65,536 (0xFFFF) the max size of an IP packet. + * we *must* allocate the buffer. Note it needn't be bigger + * than 65,536 (0xFFFF), the max size of an IP packet. * Anything bigger should be truncated anyway. * * We may want to use a smarter allocation scheme at some @@ -621,7 +557,7 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this, #else family = AF_INET; #endif - if (family == AF_INET) { /* this api can't handle IPV6 addresses */ + if (family == AF_INET) { /* this API can't handle IPV6 addresses */ int address = (*env)->GetIntField(env, iaObj, ia_addressID); (*env)->SetIntField(env, addressObj, ia_addressID, address); } @@ -695,14 +631,14 @@ Java_java_net_PlainDatagramSocketImpl_peekData(JNIEnv *env, jobject this, if (packetBufferLen > MAX_BUFFER_LEN) { /* When JNI-ifying the JDK's IO routines, we turned - * read's and write's of byte arrays of size greater + * reads and writes of byte arrays of size greater * than 2048 bytes into several operations of size 2048. * This saves a malloc()/memcpy()/free() for big * buffers. This is OK for file IO and TCP, but that * strategy violates the semantics of a datagram protocol. * (one big send) != (several smaller sends). So here - * we *must* alloc the buffer. Note it needn't be bigger - * than 65,536 (0xFFFF) the max size of an IP packet. + * we *must* allocate the buffer. Note it needn't be bigger + * than 65,536 (0xFFFF), the max size of an IP packet. * anything bigger is truncated anyway. * * We may want to use a smarter allocation scheme at some @@ -855,14 +791,14 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this, if (packetBufferLen > MAX_BUFFER_LEN) { /* When JNI-ifying the JDK's IO routines, we turned - * read's and write's of byte arrays of size greater + * reads and writes of byte arrays of size greater * than 2048 bytes into several operations of size 2048. * This saves a malloc()/memcpy()/free() for big * buffers. This is OK for file IO and TCP, but that * strategy violates the semantics of a datagram protocol. * (one big send) != (several smaller sends). So here - * we *must* alloc the buffer. Note it needn't be bigger - * than 65,536 (0xFFFF) the max size of an IP packet. + * we *must* allocate the buffer. Note it needn't be bigger + * than 65,536 (0xFFFF) the max size of an IP packet, * anything bigger is truncated anyway. * * We may want to use a smarter allocation scheme at some @@ -883,24 +819,6 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this, fullPacket = &(BUF[0]); } -#ifdef __linux__ - /* - * On Linux with the 2.2 kernel we simulate connected datagrams by - * discarding packets - */ - if (isOldKernel) { - connected = (*env)->GetBooleanField(env, this, pdsi_connected); - if (connected) { - connectedAddress = (*env)->GetObjectField(env, this, pdsi_connectedAddress); - connectedPort = (*env)->GetIntField(env, this, pdsi_connectedPort); - - if (timeout) { - prevTime = JVM_CurrentTimeMillis(env, 0); - } - } - } -#endif - do { retry = JNI_FALSE; @@ -933,14 +851,6 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this, } } - /* - * Security Note: For Linux 2.2 with connected datagrams ensure that - * you receive into the stack/heap allocated buffer - do not attempt - * to receive directly into DatagramPacket's byte array. - * (ie: if the virtual machine support pinning don't use - * GetByteArrayElements or a JNI critical section and receive - * directly into the byte array) - */ len = SOCKADDR_LEN; n = NET_RecvFrom(fd, fullPacket, packetBufferLen, 0, (struct sockaddr *)&remote_addr, &len); @@ -970,47 +880,6 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this, int port; jobject packetAddress; - /* - * If we are connected then we know that the datagram that we have - * received is from the address that we are connected too. However - * on Linux with 2.2 kernel we have to simulate this behaviour by - * discarding any datagrams that aren't from the connected address. - */ -#ifdef __linux__ - if (isOldKernel && connected) { - - if (NET_GetPortFromSockaddr((struct sockaddr *)&remote_addr) != connectedPort || - !NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&remote_addr, connectedAddress)) { - - /* - * Discard the datagram as it's not from the connected - * address - */ - retry = JNI_TRUE; - - /* - * Adjust timeout if necessary to ensure that we adhere to - * timeout semantics. - */ - if (timeout) { - jlong newTime = JVM_CurrentTimeMillis(env, 0); - timeout -= (newTime - prevTime); - if (timeout <= 0) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", - "Receive timed out"); - if (mallocedPacket) { - free(fullPacket); - } - return; - } - prevTime = newTime; - } - - continue; - } - } -#endif - /* * success - fill in received address... * @@ -1112,27 +981,16 @@ Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env, setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char*) &t, sizeof(int)); -#ifdef __linux__ - if (isOldKernel) { - setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, (char*) &t, sizeof(int)); - } - -#ifdef AF_INET6 +#if defined (__linux__) && defined (AF_INET6) /* * On Linux for IPv6 sockets we must set the hop limit - * to 1 to be compatible with default ttl of 1 for IPv4 sockets. + * to 1 to be compatible with default TTL of 1 for IPv4 sockets. */ if (domain == AF_INET6) { int ttl = 1; setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&ttl, sizeof(ttl)); - - if (isOldKernel) { - (*env)->SetIntField(env, this, pdsi_ttlID, ttl); - } } -#endif - #endif /* __linux__ */ (*env)->SetIntField(env, fdObj, IO_fd_fdID, fd); @@ -1250,16 +1108,6 @@ static void mcast_set_if_by_if_v6(JNIEnv *env, jobject this, int fd, jobject val return; } -#ifdef __linux__ - /* - * Linux 2.2 kernel doesn't support IPV6_MULTICAST_IF socket - * option so record index for later retrival. - */ - if (isOldKernel) { - (*env)->SetIntField(env, this, pdsi_multicastInterfaceID, - (jint)index); - } -#endif } #endif /* AF_INET6 */ @@ -1326,8 +1174,6 @@ static void mcast_set_if_by_addr_v6(JNIEnv *env, jobject this, int fd, jobject v * InetAddress is bound * Set outgoing multicast interface using * IPPROTO_IPV6/IPV6_MULTICAST_IF - * On Linux 2.2 record interface index as can't - * query the multicast interface. * * SockOptions.IF_MULTICAST_IF2 :- * value is a NetworkInterface @@ -1338,8 +1184,6 @@ static void mcast_set_if_by_addr_v6(JNIEnv *env, jobject this, int fd, jobject v * IPv6: Obtain NetworkInterface.index * Set outgoing multicast interface using * IPPROTO_IPV6/IPV6_MULTICAST_IF - * On Linux 2.2 record interface index as can't - * query the multicast interface. * */ static void setMulticastInterface(JNIEnv *env, jobject this, int fd, @@ -1436,15 +1280,6 @@ static void mcast_set_loop_v6(JNIEnv *env, jobject this, int fd, jobject value) return; } -#ifdef __linux__ - /* - * Can't query IPV6_MULTICAST_LOOP on Linux 2.2 kernel so - * store it in impl so that we can simulate getsockopt. - */ - if (isOldKernel) { - (*env)->SetBooleanField(env, this, pdsi_loopbackID, on); - } -#endif } #endif /* AF_INET6 */ @@ -1507,7 +1342,7 @@ Java_java_net_PlainDatagramSocketImpl_socketSetOption(JNIEnv *env, } /* - * Setting the multicast interface handled seperately + * Setting the multicast interface handled separately */ if (opt == java_net_SocketOptions_IP_MULTICAST_IF || opt == java_net_SocketOptions_IP_MULTICAST_IF2) { @@ -1594,8 +1429,7 @@ Java_java_net_PlainDatagramSocketImpl_socketSetOption(JNIEnv *env, * Create InetAddress * IP_MULTICAST_IF returns struct ip_mreqn on 2.2 * kernel but struct in_addr on 2.4 kernel - * IPv6: Query IPPROTO_IPV6 / IPV6_MULTICAST_IF or - * obtain from impl is Linux 2.2 kernel + * IPv6: Query IPPROTO_IPV6 / IPV6_MULTICAST_IF * If index == 0 return InetAddress representing * anyLocalAddress. * If index > 0 query NetworkInterface by index @@ -1641,14 +1475,6 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) { struct in_addr *inP = ∈ int len = sizeof(struct in_addr); -#ifdef __linux__ - struct ip_mreqn mreqn; - if (isOldKernel) { - inP = (struct in_addr *)&mreqn; - len = sizeof(struct ip_mreqn); - } -#endif - if (JVM_GetSockOpt(fd, IPPROTO_IP, IP_MULTICAST_IF, (char *)inP, &len) < 0) { NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", @@ -1672,12 +1498,7 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) { addr = (*env)->NewObject(env, inet4_class, inet4_ctrID, 0); CHECK_NULL_RETURN(addr, NULL); -#ifdef __linux__ - (*env)->SetIntField(env, addr, inet4_addrID, - (isOldKernel ? ntohl(mreqn.imr_address.s_addr) : ntohl(in.s_addr)) ); -#else (*env)->SetIntField(env, addr, inet4_addrID, ntohl(in.s_addr)); -#endif /* * For IP_MULTICAST_IF return InetAddress @@ -1746,22 +1567,11 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) { jobject addr; jobject ni; -#ifdef __linux__ - /* - * Linux 2.2 kernel doesn't support IPV6_MULTICAST_IF socke option - * so use cached index. - */ - if (isOldKernel) { - index = (*env)->GetIntField(env, this, pdsi_multicastInterfaceID); - } else -#endif - { - if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, - (char*)&index, &len) < 0) { - NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", - "Error getting socket option"); - return NULL; - } + if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, + (char*)&index, &len) < 0) { + NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", + "Error getting socket option"); + return NULL; } if (ni_class == NULL) { @@ -1877,7 +1687,7 @@ Java_java_net_PlainDatagramSocketImpl_socketGetOption(JNIEnv *env, jobject this, } /* - * Handle IP_MULTICAST_IF seperately + * Handle IP_MULTICAST_IF separately */ if (opt == java_net_SocketOptions_IP_MULTICAST_IF || opt == java_net_SocketOptions_IP_MULTICAST_IF2) { @@ -1916,18 +1726,6 @@ Java_java_net_PlainDatagramSocketImpl_socketGetOption(JNIEnv *env, jobject this, return NULL; } - /* - * IP_MULTICAST_LOOP socket option isn't available on Linux 2.2 - * kernel with IPv6 so return value stored in impl. - */ -#if defined(AF_INET6) && defined(__linux__) - if (isOldKernel && opt == java_net_SocketOptions_IP_MULTICAST_LOOP && - level == IPPROTO_IPV6) { - int mode = (int)(*env)->GetBooleanField(env, this, pdsi_loopbackID); - return createBoolean(env, mode); - } -#endif - if (opt == java_net_SocketOptions_IP_MULTICAST_LOOP && level == IPPROTO_IP) { optlen = sizeof(optval.c); @@ -1961,7 +1759,7 @@ Java_java_net_PlainDatagramSocketImpl_socketGetOption(JNIEnv *env, jobject this, } - /* should never rearch here */ + /* should never reach here */ return NULL; } @@ -2025,15 +1823,12 @@ Java_java_net_PlainDatagramSocketImpl_setTimeToLive(JNIEnv *env, jobject this, } else { fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); } - /* setsockopt to be correct ttl */ + /* setsockopt to be correct TTL */ #ifdef AF_INET6 #ifdef __linux__ setTTL(env, fd, ttl); if (ipv6_available()) { setHopLimit(env, fd, ttl); - if (isOldKernel) { - (*env)->SetIntField(env, this, pdsi_ttlID, ttl); - } } #else /* __linux__ not defined */ if (ipv6_available()) { @@ -2076,21 +1871,12 @@ Java_java_net_PlainDatagramSocketImpl_getTimeToLive(JNIEnv *env, jobject this) { } else { fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); } - /* getsockopt of ttl */ + /* getsockopt of TTL */ #ifdef AF_INET6 if (ipv6_available()) { int ttl = 0; int len = sizeof(ttl); -#ifdef __linux__ - /* - * Linux 2.2 kernel doesn't support IPV6_MULTICAST_HOPS socket option - */ - if (isOldKernel) { - return (*env)->GetIntField(env, this, pdsi_ttlID); - } -#endif - if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char*)&ttl, &len) < 0) { NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", @@ -2258,14 +2044,10 @@ static void mcast_join_leave(JNIEnv *env, jobject this, int index; int len = sizeof(index); - if (isOldKernel) { - index = (*env)->GetIntField(env, this, pdsi_multicastInterfaceID); - } else { - if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, - (char*)&index, &len) < 0) { - NET_ThrowCurrent(env, "getsockopt IPV6_MULTICAST_IF failed"); - return; - } + if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, + (char*)&index, &len) < 0) { + NET_ThrowCurrent(env, "getsockopt IPV6_MULTICAST_IF failed"); + return; } mname.imr_multiaddr.s_addr = htonl((*env)->GetIntField(env, iaObj, ia_addressID)); @@ -2279,21 +2061,13 @@ static void mcast_join_leave(JNIEnv *env, jobject this, struct in_addr *inP = ∈ socklen_t len = sizeof(struct in_addr); -#ifdef __linux__ - struct ip_mreqn mreqn; - if (isOldKernel) { - inP = (struct in_addr *)&mreqn; - len = sizeof(struct ip_mreqn); - } -#endif if (getsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (char *)inP, &len) < 0) { NET_ThrowCurrent(env, "getsockopt IP_MULTICAST_IF failed"); return; } #ifdef __linux__ - mname.imr_address.s_addr = - (isOldKernel ? mreqn.imr_address.s_addr : in.s_addr); + mname.imr_address.s_addr = in.s_addr; #else mname.imr_interface.s_addr = in.s_addr; @@ -2314,10 +2088,10 @@ static void mcast_join_leave(JNIEnv *env, jobject this, * If IP_ADD_MEMBERSHIP returns ENOPROTOOPT on Linux and we've got * IPv6 enabled then it's possible that the kernel has been fixed * so we switch to IPV6_ADD_MEMBERSHIP socket option. - * As of 2.4.7 kernel IPV6_ADD_MEMERSHIP can't handle IPv4-mapped - * addresses so we have to use IP_ADD_MEMERSHIP for IPv4 multicast + * As of 2.4.7 kernel IPV6_ADD_MEMBERSHIP can't handle IPv4-mapped + * addresses so we have to use IP_ADD_MEMBERSHIP for IPv4 multicast * groups. However if the socket is an IPv6 socket then then setsockopt - * should reurn ENOPROTOOPT. We assume this will be fixed in Linux + * should return ENOPROTOOPT. We assume this will be fixed in Linux * at some stage. */ #if defined(__linux__) && defined(AF_INET6) @@ -2385,20 +2159,10 @@ static void mcast_join_leave(JNIEnv *env, jobject this, int index; int len = sizeof(index); -#ifdef __linux__ - /* - * 2.2 kernel doens't support IPV6_MULTICAST_IF socket option - */ - if (isOldKernel) { - index = (*env)->GetIntField(env, this, pdsi_multicastInterfaceID); - } else -#endif - { - if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, - (char*)&index, &len) < 0) { - NET_ThrowCurrent(env, "getsockopt IPV6_MULTICAST_IF failed"); - return; - } + if (JVM_GetSockOpt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, + (char*)&index, &len) < 0) { + NET_ThrowCurrent(env, "getsockopt IPV6_MULTICAST_IF failed"); + return; } #ifdef __linux__ @@ -2408,7 +2172,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this, * subsequent leave groups to fail as there is no match. Thus we * pick the interface if there is a matching route. */ - if (index == 0 && !isOldKernel) { + if (index == 0) { int rt_index = getDefaultIPv6Interface(&(mname6.ipv6mr_multiaddr)); if (rt_index > 0) { index = rt_index; diff --git a/src/solaris/native/java/net/PlainSocketImpl.c b/src/solaris/native/java/net/PlainSocketImpl.c index 82616f2a0..a284ab42d 100644 --- a/src/solaris/native/java/net/PlainSocketImpl.c +++ b/src/solaris/native/java/net/PlainSocketImpl.c @@ -128,7 +128,7 @@ static int getFD(JNIEnv *env, jobject this) { /* * The initroto function is called whenever PlainSocketImpl is - * loaded, to cache fieldIds for efficiency. This is called everytime + * loaded, to cache field IDs for efficiency. This is called every time * the Java class is loaded. * * Class: java_net_PlainSocketImpl @@ -589,7 +589,7 @@ Java_java_net_PlainSocketImpl_socketBind(JNIEnv *env, jobject this, /* set the address */ (*env)->SetObjectField(env, this, psi_addressID, iaObj); - /* intialize the local port */ + /* initialize the local port */ if (localport == 0) { /* Now that we're a connected socket, let's extract the port number * that the system chose for us and store it in the Socket object. @@ -909,7 +909,7 @@ Java_java_net_PlainSocketImpl_socketSetOption(JNIEnv *env, jobject this, } /* - * SO_TIMEOUT is a no-op on Solaris/Linux + * SO_TIMEOUT is a NOOP on Solaris/Linux */ if (cmd == java_net_SocketOptions_SO_TIMEOUT) { return; diff --git a/src/solaris/native/java/net/SocketInputStream.c b/src/solaris/native/java/net/SocketInputStream.c index 1e115cea9..6ae368e49 100644 --- a/src/solaris/native/java/net/SocketInputStream.c +++ b/src/solaris/native/java/net/SocketInputStream.c @@ -67,14 +67,14 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this, jint fd, nread; if (IS_NULL(fdObj)) { - /* should't this be a NullPointerException? -br */ + /* shouldn't this be a NullPointerException? -br */ JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); return -1; } else { fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); /* Bug 4086704 - If the Socket associated with this file descriptor - * was closed (sysCloseFD), the the file descriptor is set to -1. + * was closed (sysCloseFD), then the file descriptor is set to -1. */ if (fd == -1) { JNU_ThrowByName(env, "java/net/SocketException", "Socket closed"); diff --git a/src/solaris/native/java/net/bsd_close.c b/src/solaris/native/java/net/bsd_close.c index 594d42422..f1e24bd6d 100644 --- a/src/solaris/native/java/net/bsd_close.c +++ b/src/solaris/native/java/net/bsd_close.c @@ -68,7 +68,7 @@ static int fdCount; /* * This limit applies if getlimit() returns unlimited. - * Unfortunately, this means if someone wants a higher limt + * Unfortunately, this means if someone wants a higher limit * then they have to set an explicit limit, higher than this, * which is probably counter-intuitive. */ diff --git a/src/solaris/native/java/net/net_util_md.c b/src/solaris/native/java/net/net_util_md.c index e08de49eb..7df6f3e98 100644 --- a/src/solaris/native/java/net/net_util_md.c +++ b/src/solaris/native/java/net/net_util_md.c @@ -169,7 +169,7 @@ getParam(char *driver, char *param) * for Solaris versions that do not support the ioctl() in getParam(). * Ugly, but only called once (for each sotype). * - * As an optimisation, we make a guess using the default values for Solaris + * As an optimization, we make a guess using the default values for Solaris * assuming they haven't been modified with ndd. */ @@ -217,23 +217,7 @@ static int findMaxBuf(int fd, int opt, int sotype) { #endif #ifdef __linux__ -static int kernelV22 = 0; static int vinit = 0; - -int kernelIsV22 () { - if (!vinit) { - struct utsname sysinfo; - if (uname(&sysinfo) == 0) { - sysinfo.release[3] = '\0'; - if (strcmp(sysinfo.release, "2.2") == 0) { - kernelV22 = JNI_TRUE; - } - } - vinit = 1; - } - return kernelV22; -} - static int kernelV24 = 0; static int vinit24 = 0; @@ -253,17 +237,11 @@ int kernelIsV24 () { int getScopeID (struct sockaddr *him) { struct sockaddr_in6 *hext = (struct sockaddr_in6 *)him; - if (kernelIsV22()) { - return 0; - } return hext->sin6_scope_id; } int cmpScopeID (unsigned int scope, struct sockaddr *him) { struct sockaddr_in6 *hext = (struct sockaddr_in6 *)him; - if (kernelIsV22()) { - return 1; /* scope is ignored for comparison in 2.2 kernel */ - } return hext->sin6_scope_id == scope; } @@ -843,15 +821,14 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr * address needs to be routed via the loopback interface. In this case, * we override the specified value with that of the loopback interface. * If no cached value exists and no value was specified by user, then - * we try to determine a value ffrom the routing table. In all these + * we try to determine a value from the routing table. In all these * cases the used value is cached for further use. */ #ifdef __linux__ if (IN6_IS_ADDR_LINKLOCAL(&(him6->sin6_addr))) { int cached_scope_id = 0, scope_id = 0; - int old_kernel = kernelIsV22(); - if (ia6_cachedscopeidID && !old_kernel) { + if (ia6_cachedscopeidID) { cached_scope_id = (int)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID); /* if cached value exists then use it. Otherwise, check * if scope is set in the address. @@ -891,13 +868,11 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr * of sockaddr_in6. */ - if (!old_kernel) { - struct sockaddr_in6 *him6 = - (struct sockaddr_in6 *)him; - him6->sin6_scope_id = cached_scope_id != 0 ? - cached_scope_id : scope_id; - *len = sizeof(struct sockaddr_in6); - } + struct sockaddr_in6 *him6 = + (struct sockaddr_in6 *)him; + him6->sin6_scope_id = cached_scope_id != 0 ? + cached_scope_id : scope_id; + *len = sizeof(struct sockaddr_in6); } #else /* handle scope_id for solaris */ @@ -1208,7 +1183,7 @@ int getDefaultIPv6Interface(struct in6_addr *target_addr) { /* * Wrapper for getsockopt system routine - does any necessary - * pre/post processing to deal with OS specific oddies :- + * pre/post processing to deal with OS specific oddities :- * * IP_TOS is a no-op with IPv6 sockets as it's setup when * the connection is established. @@ -1287,7 +1262,7 @@ NET_GetSockOpt(int fd, int level, int opt, void *result, * * For IP_TOS socket option need to mask off bits as this * aren't automatically masked by the kernel and results in - * an error. In addition IP_TOS is a noop with IPv6 as it + * an error. In addition IP_TOS is a NOOP with IPv6 as it * should be setup as connection time. */ int @@ -1321,7 +1296,7 @@ NET_SetSockOpt(int fd, int level, int opt, const void *arg, /* * IPPROTO/IP_TOS :- - * 1. IPv6 on Solaris/Mac OS: no-op and will be set + * 1. IPv6 on Solaris/Mac OS: NOOP and will be set * in flowinfo field when connecting TCP socket, * or sending UDP packet. * 2. IPv6 on Linux: By default Linux ignores flowinfo diff --git a/src/solaris/native/java/net/net_util_md.h b/src/solaris/native/java/net/net_util_md.h index 8d835b25d..e905752ad 100644 --- a/src/solaris/native/java/net/net_util_md.h +++ b/src/solaris/native/java/net/net_util_md.h @@ -144,7 +144,6 @@ extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout); * Utilities */ #ifdef __linux__ -extern int kernelIsV22(); extern int kernelIsV24(); #endif -- GitLab