Identity and version support for the dnstap plugin (#5555)

* Added identity and version support to dnstap plugin

Signed-off-by: Daniel Jolly <code@danieljolly.com>

* Added missing commas

Signed-off-by: Daniel Jolly <code@danieljolly.com>

* Moved byte slice conversions to setup rather than handler.
Fixed indentation issue.

Signed-off-by: Daniel Jolly <code@danieljolly.com>

* Improved setup config parsing and added tests to detect various configurations

Signed-off-by: Daniel Jolly <code@danieljolly.com>

Signed-off-by: Daniel Jolly <code@danieljolly.com>
Co-authored-by: Daniel Jolly <code@danieljolly.com>
This commit is contained in:
Daniel Jolly
2022-09-07 09:22:38 -04:00
committed by GitHub
parent a740ed7536
commit 0511ca2e4d
4 changed files with 67 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ package dnstap
import (
"net/url"
"os"
"strings"
"github.com/coredns/caddy"
@@ -19,10 +20,14 @@ func parseConfig(c *caddy.Controller) (Dnstap, error) {
d := Dnstap{}
endpoint := ""
if !c.Args(&endpoint) {
args := c.RemainingArgs()
if len(args) == 0 {
return d, c.ArgErr()
}
endpoint = args[0]
if strings.HasPrefix(endpoint, "tcp://") {
// remote network endpoint
endpointURL, err := url.Parse(endpoint)
@@ -37,7 +42,30 @@ func parseConfig(c *caddy.Controller) (Dnstap, error) {
d = Dnstap{io: dio}
}
d.IncludeRawMessage = c.NextArg() && c.Val() == "full"
d.IncludeRawMessage = len(args) == 2 && args[1] == "full"
hostname, _ := os.Hostname()
d.Identity = []byte(hostname)
d.Version = []byte(caddy.AppName + "-" + caddy.AppVersion)
for c.NextBlock() {
switch c.Val() {
case "identity":
{
if !c.NextArg() {
return d, c.ArgErr()
}
d.Identity = []byte(c.Val())
}
case "version":
{
if !c.NextArg() {
return d, c.ArgErr()
}
d.Version = []byte(c.Val())
}
}
}
return d, nil
}