aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/replacer/replacer.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/pkg/replacer/replacer.go')
-rw-r--r--plugin/pkg/replacer/replacer.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/plugin/pkg/replacer/replacer.go b/plugin/pkg/replacer/replacer.go
index c10022f79..1775f7c24 100644
--- a/plugin/pkg/replacer/replacer.go
+++ b/plugin/pkg/replacer/replacer.go
@@ -43,7 +43,7 @@ func New(r *dns.Msg, rr *dnstest.Recorder, emptyValue string) Replacer {
return time.Now().Format(timeFormat)
}(),
"{size}": strconv.Itoa(req.Len()),
- "{remote}": req.IP(),
+ "{remote}": addrToRFC3986(req.IP()),
"{port}": req.Port(),
},
emptyValue: emptyValue,
@@ -155,6 +155,14 @@ func flagsToString(h dns.MsgHdr) string {
return strings.Join(flags[:i], ",")
}
+// addrToRFC3986 will add brackets to the address if it is an IPv6 address.
+func addrToRFC3986(addr string) string {
+ if strings.Contains(addr, ":") {
+ return "[" + addr + "]"
+ }
+ return addr
+}
+
const (
timeFormat = "02/Jan/2006:15:04:05 -0700"
headerReplacer = "{>"