Skip to content

Commit

Permalink
simplify the buildup of suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kelchy committed Feb 24, 2021
1 parent 957f65a commit 37bb9c4
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions matchrelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ func (mr *MatchRelay) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns
state := request.Request{W: w, Req: r}

if len(mr.domains) > 0 {
// state.Name() will always have a trailing .
sArr := strings.Split(state.Name(), ".")
l := len(sArr)
if l > 2 {
base := sArr[l - 3] + "." + sArr[l - 2] + "."
for i := l - 3; i > 0; i = i - 1 {
str := sArr[i - 1] + "." + base
if _, ok := mr.domains[str]; ok {
mr.fwd.ServeDNS(ctx, w, r)
return 0, nil
}
base = str
if len(sArr) > 0 {
// state.Name() will always have a trailing .
// remove last element
sArr = sArr[:len(sArr)-1]
}
base := sArr[len(sArr) - 1]
for i := len(sArr) - 2; i >= 0; i = i - 1 {
str := sArr[i] + "." + base
if _, ok := mr.domains[str]; ok {
mr.fwd.ServeDNS(ctx, w, r)
return 0, nil
}
base = str
}
}

Expand Down

0 comments on commit 37bb9c4

Please sign in to comment.