Skip to content

Commit

Permalink
Search Domains and DNS Resolver on Windows (#13022)
Browse files Browse the repository at this point in the history
Motivation:
On Windows with JDK 9+ the search domain and dns servers are missing.

Modification:

This PR uses JNI to fetch the DNS Servers from the operating system.

Result:

Fixes #12712 #11885. 

Co-authored-by: Norman Maurer <norman_maurer@apple.com>
  • Loading branch information
flx5 and normanmaurer committed Jan 27, 2023
1 parent 27b21ad commit 9426e14
Show file tree
Hide file tree
Showing 14 changed files with 973 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci-pr.yml
Expand Up @@ -60,6 +60,9 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/java/io/netty/util/internal/Hidden.java
Expand Up @@ -154,6 +154,10 @@ public void applyTo(BlockHound.Builder builder) {
"io.netty.resolver.dns.UnixResolverDnsServerAddressStreamProvider",
"parseEtcResolverOptions");

builder.allowBlockingCallsInside(
"io.netty.resolver.dns.windows.WindowsAdapterInfo",
"loadNativeLibrary");

builder.allowBlockingCallsInside(
"io.netty.resolver.HostsFileEntriesProvider$ParserImpl",
"parse");
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -645,6 +645,7 @@
<module>resolver-dns</module>
<module>resolver-dns-classes-macos</module>
<module>resolver-dns-native-macos</module>
<module>resolver-dns-native-windows</module>
<module>transport</module>
<module>transport-native-unix-common-tests</module>
<module>transport-native-unix-common</module>
Expand Down
179 changes: 179 additions & 0 deletions resolver-dns-native-windows/pom.xml
@@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2023 The Netty Project
~
~ The Netty Project licenses this file to you under the Apache License,
~ version 2.0 (the "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at:
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
~ License for the specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.netty</groupId>
<artifactId>netty-parent</artifactId>
<version>4.1.88.Final-SNAPSHOT</version>
</parent>
<artifactId>netty-resolver-dns-native-windows</artifactId>

<name>Netty/Resolver/DNS/Native/Windows</name>
<packaging>jar</packaging>

<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<skipTests>false</skipTests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<!-- unpack netty-jni-util files -->
<execution>
<id>unpack</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>io.netty</includeGroupIds>
<includeArtifactIds>netty-jni-util</includeArtifactIds>
<classifier>sources</classifier>
<outputDirectory>${combinedSources}</outputDirectory>
<includes>**.h,**.c</includes>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.fusesource.hawtjni</groupId>
<artifactId>hawtjni-maven-plugin</artifactId>
<executions>
<execution>
<id>build-native-lib</id>
<phase>compile</phase>
<configuration>
<name>netty_resolver_dns_native_windows_${os.detected.arch}</name>
<nativeSourceDirectory>${combinedSources}</nativeSourceDirectory>
<libDirectory>${project.build.directory}/native-build</libDirectory>
<windowsBuildTool>msbuild</windowsBuildTool>
<windowsPlatformToolset>v142</windowsPlatformToolset>
<windowsTargetPlatformVersion>10.0.19041.0</windowsTargetPlatformVersion>
</configuration>
<goals>
<goal>generate</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${combinedSources}</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/c/src</directory>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-windows-dll</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/META-INF/native/</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/native-build/META-INF/native/windows${os.detected.bitness}</directory>
<includes>
<include>netty_resolver_dns_native_windows_${os.detected.arch}.dll</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<!-- Generate the JAR that contains the native library in it. -->
<execution>
<id>native-jar</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Bundle-NativeCode>META-INF/native/netty_resolver_dns_native_windows_${os.detected.arch}.dll; osname=Windows; processor=${os.detected.arch}</Bundle-NativeCode>
<Fragment-Host>io.netty.resolver-dns-classes-windows</Fragment-Host>
<Automatic-Module-Name>${javaModuleName}</Automatic-Module-Name>
</manifestEntries>
<index>true</index>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<classifier>${jni.classifier}</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<properties>
<javaModuleNameClassifier>${os.detected.name}.${os.detected.arch}</javaModuleNameClassifier>
<javaModuleName>io.netty.resolver.dns.windows.${javaModuleNameClassifier}</javaModuleName>
<combinedSources>${project.build.directory}/native-src</combinedSources>
</properties>

<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-jni-util</artifactId>
<classifier>sources</classifier>
<optional>true</optional>
</dependency>
</dependencies>
</project>

0 comments on commit 9426e14

Please sign in to comment.