mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Plugin dnstap: add support for "extra" field in payload (#6226)
* dnstap: add 'extra' field Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: add setup_test for 'extra' field Signed-off-by: chenyuheng <chenyuheng99@qq.com> * udnstap: update document and test Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: update setup_test for more coverage Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: add TapMessageWithMetadata function to Dnstap Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: adapt dnstap and forward plugins to use TapMessageWithMetadata Signed-off-by: chenyuheng <chenyuheng99@qq.com> * change TapMessageWithMetadata function Signed-off-by: chenyuheng <chenyuheng99@qq.com> * tab inconsistency fix Signed-off-by: chenyuheng <chenyuheng99@qq.com> * fix replacer to support empty state Signed-off-by: chenyuheng <chenyuheng99@qq.com> * add replacer test for empty status parameter Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: update unit test for 'extra' field Signed-off-by: chenyuheng <chenyuheng99@qq.com> * clean up code Signed-off-by: chenyuheng <chenyuheng99@qq.com> * gofmt fix & static analysis fix Signed-off-by: chenyuheng <chenyuheng99@qq.com> * dnstap: refactor Signed-off-by: chenyuheng <chenyuheng99@qq.com> --------- Signed-off-by: chenyuheng <chenyuheng99@qq.com>
This commit is contained in:
@@ -59,31 +59,6 @@ var labels = map[string]struct{}{
|
||||
// appendValue appends the current value of label.
|
||||
func appendValue(b []byte, state request.Request, rr *dnstest.Recorder, label string) []byte {
|
||||
switch label {
|
||||
case "{type}":
|
||||
return append(b, state.Type()...)
|
||||
case "{name}":
|
||||
return append(b, state.Name()...)
|
||||
case "{class}":
|
||||
return append(b, state.Class()...)
|
||||
case "{proto}":
|
||||
return append(b, state.Proto()...)
|
||||
case "{size}":
|
||||
return strconv.AppendInt(b, int64(state.Req.Len()), 10)
|
||||
case "{remote}":
|
||||
return appendAddrToRFC3986(b, state.IP())
|
||||
case "{port}":
|
||||
return append(b, state.Port()...)
|
||||
case "{local}":
|
||||
return appendAddrToRFC3986(b, state.LocalIP())
|
||||
// Header placeholders (case-insensitive).
|
||||
case headerReplacer + "id}":
|
||||
return strconv.AppendInt(b, int64(state.Req.Id), 10)
|
||||
case headerReplacer + "opcode}":
|
||||
return strconv.AppendInt(b, int64(state.Req.Opcode), 10)
|
||||
case headerReplacer + "do}":
|
||||
return strconv.AppendBool(b, state.Do())
|
||||
case headerReplacer + "bufsize}":
|
||||
return strconv.AppendInt(b, int64(state.Size()), 10)
|
||||
// Recorded replacements.
|
||||
case "{rcode}":
|
||||
if rr == nil || rr.Msg == nil {
|
||||
@@ -109,6 +84,38 @@ func appendValue(b []byte, state request.Request, rr *dnstest.Recorder, label st
|
||||
return appendFlags(b, rr.Msg.MsgHdr)
|
||||
}
|
||||
return append(b, EmptyValue...)
|
||||
}
|
||||
|
||||
if (request.Request{}) == state {
|
||||
return append(b, EmptyValue...)
|
||||
}
|
||||
|
||||
switch label {
|
||||
case "{type}":
|
||||
return append(b, state.Type()...)
|
||||
case "{name}":
|
||||
return append(b, state.Name()...)
|
||||
case "{class}":
|
||||
return append(b, state.Class()...)
|
||||
case "{proto}":
|
||||
return append(b, state.Proto()...)
|
||||
case "{size}":
|
||||
return strconv.AppendInt(b, int64(state.Req.Len()), 10)
|
||||
case "{remote}":
|
||||
return appendAddrToRFC3986(b, state.IP())
|
||||
case "{port}":
|
||||
return append(b, state.Port()...)
|
||||
case "{local}":
|
||||
return appendAddrToRFC3986(b, state.LocalIP())
|
||||
// Header placeholders (case-insensitive).
|
||||
case headerReplacer + "id}":
|
||||
return strconv.AppendInt(b, int64(state.Req.Id), 10)
|
||||
case headerReplacer + "opcode}":
|
||||
return strconv.AppendInt(b, int64(state.Req.Opcode), 10)
|
||||
case headerReplacer + "do}":
|
||||
return strconv.AppendBool(b, state.Do())
|
||||
case headerReplacer + "bufsize}":
|
||||
return strconv.AppendInt(b, int64(state.Size()), 10)
|
||||
default:
|
||||
return append(b, EmptyValue...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user