Skip to content

Commit

Permalink
Merge pull request #21 from FMotalleb/fix-raw-multiresponse
Browse files Browse the repository at this point in the history
[Fix]<RawResponse>
  • Loading branch information
FMotalleb authored Sep 19, 2023
2 parents e4b44ae + 1b1a34d commit c6a105b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
9 changes: 9 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,12 @@ rules:
- (.*\.)?bard\.google\.com
resolvers: "shecan"
resolverParams: ea.com.

- name: Test
matcher: regex
matcherParams:
- (.*\.)?test.domain.com
raw:
A: |
test.domain.com 60 IN CNAME google.403.
google.403. 60 IN A 127.0.0.1
23 changes: 15 additions & 8 deletions lib/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,23 @@ func handleRawResponse(requestHostname string, r *rule.Rule, req *dns.Msg, w dns
log.Error().Msgf("%s not supported in the config, continue using default handler", dns.TypeToString[req.Question[0].Qtype])
return false
}
msg, err := dns.NewRR(formatString(*raw, mapper))
if err != nil {
log.Debug().Msgf("cannot parse raw response: %v", err)
return false
result := make([]dns.RR, 0)
rawList := strings.Split(*raw, "\n")
for _, value := range rawList {
msg, err := dns.NewRR(formatString(value, mapper))
if err != nil {
log.Debug().Msgf("cannot parse raw response: %v", err)
return false
}

if msg != nil {

result = append(result, msg)

}
}
if msg != nil {
result := make([]dns.RR, 0)
result = append(result, msg)
if len(result) > 0 {
req.Answer = result
log.Info().Msgf("cannot parse raw response: %v", req)
_ = w.WriteMsg(req)
return true
}
Expand Down

0 comments on commit c6a105b

Please sign in to comment.