Skip to content

Commit 461887c

Browse files
authored
Configuring Stub Solver (#600)
* testing new method * implementing solver * testing stub solver * tested * configured new solver * fixing bug * implementing ip version check * setup the docs * add ref * english * updating the docs * [Gradle Release Plugin] - new version commit: '3.32.1-snapshot'.
1 parent 9ac46dd commit 461887c

File tree

17 files changed

+263
-17
lines changed

17 files changed

+263
-17
lines changed

RELEASE-NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.32.1
2+
* Configuring Stub Solver. #545
3+
14
## 3.32.0
25
* Implementing Stub Solver but not exposing. #545
36

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Stub Solver
3+
---
4+
5+
You can use stub solver to transform IPs into hostnames without need to create a
6+
configuration file as in Local DB Solver. Stub Solver was inspired in `nip.io` and `sslip.io`.
7+
8+
## Examples:
9+
10+
**Without a name:**
11+
12+
* `10.0.0.1.stub` => `10.0.0.1`
13+
* `192-168-1-250.stub` => `192.168.1.250`
14+
* `0a000803.stub` => `10.0.8.3`
15+
16+
**With a name:**
17+
18+
* `app.10.8.0.1.stub` => `10.8.0.1`
19+
* `app-116-203-255-68.stub` => `116.203.255.68`
20+
* `app-c0a801fc.stub` => `192.168.1.252`
21+
* `customer1.app.10.0.0.1.stub` => `10.0.0.1`
22+
* `customer2-app-127-0-0-1.stub` => `127.0.0.1`
23+
* `customer3-app-7f000101.stub` => `127.0.1.1`
24+
* `app.2a01-4f8-c17-b8f--2.stub` => `2a01:4f8:c17:b8f::2`
25+
26+
### Format Reference
27+
28+
```
29+
${name}[.-]${ip_address}.stub
30+
```
31+
32+
* `${name}` (optional): you can set a name to make it easier to recognize the IP
33+
* `${ip_address}`: The ip address which the DNS will answer it can be in 4 formats
34+
* dot notation: magic.127.0.0.1.stub
35+
* dash notation: magic-127-0-0-1.stub
36+
* hexadecimal notation: magic-7f000001.stub
37+
* Ipv6 notation: magic.2a01-4f8-c17-b8f--2.stub
38+
39+
### Customize the domain name
40+
41+
<tbd>
42+
43+
## Refs
44+
45+
* [Stub Solver #545][1]
46+
47+
48+
[1]: https://github.com/mageddo/dns-proxy-server/issues/545

docs/content/3-configuration/_index.en.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,17 @@ __Version 2__
192192
"dockerSolverHostMachineFallbackActive": true,
193193
"solverRemote" : {
194194
"circuitBreaker" : {
195-
"failureThreshold" : 3, // how many attempts before open the circuit?
196-
"failureThresholdCapacity" : 10, // how many attempts store to the stack?
197-
"successThreshold" : 5, // how many attempts before close the circuit?
198-
"testDelay" : "PT20S" // how many time to wait before test the circuit again?, see https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#toString-- for format explanation
195+
"failureThreshold" : 3,
196+
"failureThresholdCapacity" : 10,
197+
"successThreshold" : 5,
198+
"testDelay" : "PT20S"
199199
}
200200
}
201201
}
202202
```
203203

204+
* [Solver remote circuit breaker configuration][3]
205+
204206
## Environment variable configuration
205207

206208
Boolean values
@@ -221,3 +223,4 @@ $ docker run defreitas/dns-proxy-server --help
221223

222224
[1]: {{%relref "2-features/auto-configuration-as-default-dns/_index.md" %}}
223225
[2]: {{%relref "2-features/local-entries/_index.md" %}}
226+
[3]: {{%relref "2-features/remote-solver-circuitbreaker/_index.en.md" %}}

gradle.properties

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

src/main/java/com/mageddo/dns/Hostname.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ public String toString() {
4444
public static Hostname of(String hostname) {
4545
return new Hostname(hostname);
4646
}
47+
48+
public boolean endsWith(String name) {
49+
return this.value.endsWith(StringUtils.lowerCase(name));
50+
}
4751
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ public static Message withResponseCode(Message res, int rRode) {
269269
return res;
270270
}
271271

272-
static Message withDefaultResponseHeaders(Message res) {
272+
public static int getRCode(Message m){
273+
return m.getRcode();
274+
}
275+
276+
public static Message withDefaultResponseHeaders(Message res) {
273277
final var header = res.getHeader();
274278
header.setFlag(Flags.QR);
275279
header.setFlag(Flags.RA);
@@ -305,4 +309,8 @@ public static boolean isSuccess(Message res) {
305309
public static String findAnswerRawIP(Message res) {
306310
return findFirstAnswerRecord(res).rdataToString();
307311
}
312+
313+
public static boolean isNxDomain(Message m) {
314+
return m.getRcode() == Rcode.NXDOMAIN;
315+
}
308316
}

src/main/java/com/mageddo/dnsproxyserver/di/module/ModuleSolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.mageddo.dnsproxyserver.solver.SolverDocker;
1010
import com.mageddo.dnsproxyserver.solver.SolverLocalDB;
1111
import com.mageddo.dnsproxyserver.solver.SolverSystem;
12+
import com.mageddo.dnsproxyserver.solver.stub.SolverStub;
1213
import dagger.Module;
1314
import dagger.Provides;
1415
import dagger.multibindings.ElementsIntoSet;
@@ -24,9 +25,9 @@ public interface ModuleSolver {
2425
@Singleton
2526
@ElementsIntoSet
2627
static Set<Solver> solvers(
27-
SolverSystem o1, SolverDocker o2, SolverLocalDB o3, SolverCachedRemote o4
28+
SolverSystem o1, SolverDocker o2, SolverLocalDB o3, SolverCachedRemote o4, SolverStub o5
2829
) {
29-
return Set.of(o1, o2, o3, o4);
30+
return Set.of(o1, o2, o3, o4, o5);
3031
}
3132

3233
@Provides

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.NonNull;
66
import lombok.Value;
77
import org.xbill.DNS.Message;
8+
import org.xbill.DNS.Rcode;
89

910
import java.time.Duration;
1011
import java.time.LocalDateTime;
@@ -50,6 +51,9 @@ public static Response of(Message message, Duration dpsTtl) {
5051
}
5152

5253
public static Response nxDomain(Message message) {
54+
if (!Messages.isNxDomain(message)) {
55+
Messages.withResponseCode(message, Rcode.NXDOMAIN);
56+
}
5357
return of(message, DEFAULT_NXDOMAIN_TTL);
5458
}
5559

@@ -74,4 +78,8 @@ public Response withTTL(Duration ttl) {
7478
.dpsTtl(ttl)
7579
.build();
7680
}
81+
82+
public int getRCode() {
83+
return this.message.getRcode();
84+
}
7785
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.mageddo.dnsproxyserver.solver;
2+
3+
import com.mageddo.commons.lang.Objects;
4+
import com.mageddo.dns.utils.Messages;
5+
import com.mageddo.net.IP;
6+
import org.xbill.DNS.Message;
7+
8+
public class ResponseMapper {
9+
public static Response toDefaultSuccessAnswer(Message query, IP ip, IP.Version version) {
10+
return Response.of(
11+
Messages.answer(query, Objects.mapOrNull(ip, IP::toText), version),
12+
Messages.DEFAULT_TTL_DURATION
13+
);
14+
}
15+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class SolverProvider {
1717

1818
static final String[] solversOrder = {
1919
"SolverSystem",
20+
"SolverStub",
2021
"SolverDocker",
2122
SolverLocalDB.NAME,
2223
SolverCachedRemote.NAME

0 commit comments

Comments
 (0)