-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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'.
- Loading branch information
Showing
17 changed files
with
263 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
## 3.32.1 | ||
* Configuring Stub Solver. #545 | ||
|
||
## 3.32.0 | ||
* Implementing Stub Solver but not exposing. #545 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: Stub Solver | ||
--- | ||
|
||
You can use stub solver to transform IPs into hostnames without need to create a | ||
configuration file as in Local DB Solver. Stub Solver was inspired in `nip.io` and `sslip.io`. | ||
|
||
## Examples: | ||
|
||
**Without a name:** | ||
|
||
* `10.0.0.1.stub` => `10.0.0.1` | ||
* `192-168-1-250.stub` => `192.168.1.250` | ||
* `0a000803.stub` => `10.0.8.3` | ||
|
||
**With a name:** | ||
|
||
* `app.10.8.0.1.stub` => `10.8.0.1` | ||
* `app-116-203-255-68.stub` => `116.203.255.68` | ||
* `app-c0a801fc.stub` => `192.168.1.252` | ||
* `customer1.app.10.0.0.1.stub` => `10.0.0.1` | ||
* `customer2-app-127-0-0-1.stub` => `127.0.0.1` | ||
* `customer3-app-7f000101.stub` => `127.0.1.1` | ||
* `app.2a01-4f8-c17-b8f--2.stub` => `2a01:4f8:c17:b8f::2` | ||
|
||
### Format Reference | ||
|
||
``` | ||
${name}[.-]${ip_address}.stub | ||
``` | ||
|
||
* `${name}` (optional): you can set a name to make it easier to recognize the IP | ||
* `${ip_address}`: The ip address which the DNS will answer it can be in 4 formats | ||
* dot notation: magic.127.0.0.1.stub | ||
* dash notation: magic-127-0-0-1.stub | ||
* hexadecimal notation: magic-7f000001.stub | ||
* Ipv6 notation: magic.2a01-4f8-c17-b8f--2.stub | ||
|
||
### Customize the domain name | ||
|
||
<tbd> | ||
|
||
## Refs | ||
|
||
* [Stub Solver #545][1] | ||
|
||
|
||
[1]: https://github.com/mageddo/dns-proxy-server/issues/545 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=3.32.0-snapshot | ||
version=3.32.1-snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/mageddo/dnsproxyserver/solver/ResponseMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.mageddo.dnsproxyserver.solver; | ||
|
||
import com.mageddo.commons.lang.Objects; | ||
import com.mageddo.dns.utils.Messages; | ||
import com.mageddo.net.IP; | ||
import org.xbill.DNS.Message; | ||
|
||
public class ResponseMapper { | ||
public static Response toDefaultSuccessAnswer(Message query, IP ip, IP.Version version) { | ||
return Response.of( | ||
Messages.answer(query, Objects.mapOrNull(ip, IP::toText), version), | ||
Messages.DEFAULT_TTL_DURATION | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/mageddo/dnsproxyserver/solver/stub/HostnameIpExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 41 additions & 1 deletion
42
src/main/java/com/mageddo/dnsproxyserver/solver/stub/SolverStub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,56 @@ | ||
package com.mageddo.dnsproxyserver.solver.stub; | ||
|
||
import com.mageddo.dns.utils.Messages; | ||
import com.mageddo.dnsproxyserver.config.Config; | ||
import com.mageddo.dnsproxyserver.config.ConfigEntryTypes; | ||
import com.mageddo.dnsproxyserver.solver.Response; | ||
import com.mageddo.dnsproxyserver.solver.ResponseMapper; | ||
import com.mageddo.dnsproxyserver.solver.Solver; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.xbill.DNS.Message; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import static com.mageddo.dns.utils.Messages.findQuestionTypeCode; | ||
|
||
/** | ||
* Extract the address from the hostname then answer. | ||
* Inspired at nip.io and sslip.io, see #545. | ||
*/ | ||
|
||
@Slf4j | ||
@Singleton | ||
@AllArgsConstructor(onConstructor = @__({@Inject})) | ||
public class SolverStub implements Solver { | ||
|
||
public static final String DOMAIN_NAME = "stub"; | ||
|
||
@Override | ||
public Response handle(Message query) { | ||
return null; | ||
final var questionType = Messages.findQuestionType(query); | ||
if (ConfigEntryTypes.isNot(questionType, Config.Entry.Type.A, Config.Entry.Type.AAAA)) { | ||
log.debug("status=unsupportedType, type={}, query={}", findQuestionTypeCode(query), Messages.simplePrint(query)); | ||
return null; | ||
} | ||
|
||
final var hostname = Messages.findQuestionHostname(query); | ||
if (!hostname.endsWith(DOMAIN_NAME)) { | ||
log.debug("status=hostnameDoesntMatchRequiredDomain, hostname={}", hostname); | ||
return null; | ||
} | ||
|
||
final var foundIp = HostnameIpExtractor.safeExtract(hostname, DOMAIN_NAME); | ||
if (foundIp == null) { | ||
log.debug("status=notSolved, hostname={}", hostname); | ||
return null; | ||
} | ||
if (!foundIp.isVersionEqualsTo(questionType.toVersion())) { | ||
log.debug("status=incompatibleIpAndQueryType, hostname={}, questionType={}", hostname, questionType); | ||
return Response.nxDomain(query); | ||
} | ||
log.debug("status=solved, host={}, ip={}", hostname, foundIp); | ||
return ResponseMapper.toDefaultSuccessAnswer(query, foundIp, questionType.toVersion()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mageddo.dns; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import testing.templates.HostnameTemplates; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class HostnameTest { | ||
|
||
@Test | ||
void mustEndsWith(){ | ||
final var hostname = Hostname.of(HostnameTemplates.NGINX_COM_BR); | ||
assertTrue(hostname.endsWith(".com.br")); | ||
} | ||
|
||
@Test | ||
void mustNotEndsWith(){ | ||
final var hostname = Hostname.of(HostnameTemplates.NGINX_COM_BR); | ||
assertFalse(hostname.endsWith(".com")); | ||
} | ||
} |
Oops, something went wrong.