Skip to content

Commit b28b98e

Browse files
authored
Fixing Bug: Getting NXDOMAIN when not expected (#668)
1 parent e6785a6 commit b28b98e

File tree

13 files changed

+62
-19
lines changed

13 files changed

+62
-19
lines changed

RELEASE-NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 5.6.1
2+
* Fixing Getting NXDOMAIN when not expected, see #668.
3+
14
## 5.6.0
25
* Releasing JRE Docker Image Version
36
* Enabling DPS to run on any JRE 21+

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=5.6.0-snapshot
1+
version=5.6.1-snapshot

src/main/java/com/mageddo/dns/utils/Messages.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,8 @@ public static String findAnswerRawIP(Message res) {
329329
public static boolean isNxDomain(Message m) {
330330
return m.getRcode() == Rcode.NXDOMAIN;
331331
}
332+
333+
public static Message noData(Message query) {
334+
return withResponseCode(query.clone(), Rcode.NOERROR);
335+
}
332336
}

src/main/java/com/mageddo/dnsproxyserver/solver/Response.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,5 @@ public Response withTTL(Duration ttl) {
8787
public int getRCode() {
8888
return this.message.getRcode();
8989
}
90+
9091
}

src/main/java/com/mageddo/dnsproxyserver/solver/SolverSystem.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ public Response handle(Message query) {
2929

3030
final var questionType = Messages.findQuestionType(query);
3131
if (ConfigEntryTypes.isNot(questionType, Type.A, Type.AAAA)) {
32-
log.debug("status=unsupportedType, type={}, query={}", findQuestionTypeCode(query),
33-
Messages.simplePrint(query)
32+
log.debug(
33+
"status=unsupportedType, type={}, query={}",
34+
findQuestionTypeCode(query), Messages.simplePrint(query)
3435
);
3536
return null;
3637
}
3738
final var config = Configs.getInstance();
38-
if (hostname.isEqualTo(
39-
config.getHostMachineHostname())) { // fixme fazer case com hostname + search domain
39+
// fixme fazer case com hostname + search domain
40+
if (hostname.isEqualTo(config.getHostMachineHostname())) {
4041
final var ip = this.machineService.findHostMachineIP(questionType.toVersion());
4142
log.debug("status=solvingHostMachineName, host={}, ip={}", hostname, ip);
4243
return ResponseMapper.toDefaultSuccessAnswer(query, ip, questionType.toVersion());

src/main/java/com/mageddo/dnsproxyserver/solver/docker/Entry.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@ public class Entry {
1616
public String getIpText() {
1717
return this.ip != null ? this.ip.toText() : null;
1818
}
19+
20+
public boolean isHostNameNotMatched() {
21+
return !this.hostnameMatched;
22+
}
23+
24+
public boolean hasNotIP() {
25+
return this.ip == null;
26+
}
27+
28+
public boolean hasIp() {
29+
return this.ip != null;
30+
}
1931
}

src/main/java/com/mageddo/dnsproxyserver/solver/docker/application/ContainerSolvingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Entry findBestMatch(HostnameQuery query) {
4646
.filter(Objects::nonNull)
4747
.findFirst()
4848
.orElse(null);
49-
final var hostnameMatched = !matchedContainers.isEmpty() && foundIp != null;
49+
final var hostnameMatched = !matchedContainers.isEmpty();
5050
log.trace(
5151
"status=findDone, query={}, found={}, hostnameMatched={}, time={}",
5252
query, foundIp, hostnameMatched, stopWatch.getTime()

src/main/java/com/mageddo/dnsproxyserver/solver/docker/dataprovider/ContainerHostnameMatcher.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public static Predicate<InspectContainerResponse> buildPredicate(final HostnameQ
2323
return buildPredicate(host, Configs.getInstance());
2424
}
2525

26-
static Predicate<InspectContainerResponse> buildPredicate(final HostnameQuery host,
27-
final Config config) {
26+
static Predicate<InspectContainerResponse> buildPredicate(
27+
final HostnameQuery host, final Config config
28+
) {
2829
return container -> {
2930

3031
final List<Predicate<InspectContainerResponse>> predicates = List.of(
@@ -49,17 +50,19 @@ public static boolean hostnameMatches(InspectContainerResponse c, HostnameQuery
4950
return host.matches(Docker.findContainerHostname(c.getConfig()));
5051
}
5152

52-
public static boolean hostnamesEnvMatches(InspectContainerResponse c,
53-
HostnameQuery hostnameQuery) {
53+
public static boolean hostnamesEnvMatches(
54+
InspectContainerResponse c, HostnameQuery hostnameQuery
55+
) {
5456
return findHostnamesFromEnv(c.getConfig()
5557
.getEnv())
5658
.stream()
5759
.anyMatch(hostnameQuery::matches)
5860
;
5961
}
6062

61-
public static boolean serviceOrContainerNameMatches(InspectContainerResponse c,
62-
HostnameQuery hostQuery, Config config) {
63+
public static boolean serviceOrContainerNameMatches(
64+
InspectContainerResponse c, HostnameQuery hostQuery, Config config
65+
) {
6366
return isRegisterContainerNames(config)
6467
&& Docker.buildHostnamesFromServiceOrContainerNames(c, config.getDockerDomain())
6568
.stream()

src/main/java/com/mageddo/dnsproxyserver/solver/remote/CircuitStatus.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ public enum CircuitStatus {
88
public static boolean isOpen(CircuitStatus status) {
99
return OPEN == status;
1010
}
11+
12+
public static boolean isNotOpen(CircuitStatus status) {
13+
return !isOpen(status);
14+
}
1115
}

src/main/java/com/mageddo/dnsproxyserver/solver/remote/circuitbreaker/canaryratethreshold/CircuitBreakerDelegateSelfObservable.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ private boolean shouldRun() {
6868

6969
private void healthCheckWhenInOpenState() {
7070
final var status = this.findStatus();
71-
final var notInOpenStatus = !CircuitStatus.isOpen(status);
72-
log.trace("status=checking, statusBefore={}, notInOpenStatus={}, circuit={}", status,
73-
notInOpenStatus, this
71+
final var notInOpenStatus = CircuitStatus.isNotOpen(status);
72+
log.trace(
73+
"status=checking, statusBefore={}, notInOpenStatus={}, circuit={}",
74+
status, notInOpenStatus, this
7475
);
7576
if (notInOpenStatus) {
7677
return;
@@ -88,7 +89,7 @@ private boolean isHealthy() {
8889
}
8990

9091
@Override
91-
public void close() throws Exception {
92+
public void close() {
9293
this.open = false;
9394
}
9495

0 commit comments

Comments
 (0)