Skip to content

Commit

Permalink
new length-unit attribute #478 (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard authored Dec 3, 2023
1 parent 30b91d3 commit 4b16f8a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ global:
# - id: dns id
# - family: ip protocol version INET or INET6
# - protocol: protocol UDP, TCP
# - length: the length of the query or reply
# - length: the length of the query or reply in bytes
# - length-unit: the length of the query or reply in bytes with unit
# - qtype: dns qtype
# - qname: dns qname
# - latency: computed latency between queries and replies
Expand All @@ -56,7 +57,7 @@ global:
# - edns-csubnet: client subnet
# - df: ip defragmentation flag
# - tr: tcp reassembled flag
text-format: "timestamp-rfc3339ns identity operation rcode queryip queryport family protocol length qname qtype latency"
text-format: "timestamp-rfc3339ns identity operation rcode queryip queryport family protocol length-unit qname qtype latency"
# default text field delimiter
text-format-delimiter: " "
# default text field boundary
Expand Down
2 changes: 1 addition & 1 deletion dnsutils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ type Config struct {

func (c *Config) SetDefault() {
// global config
c.Global.TextFormat = "timestamp identity operation rcode queryip queryport family protocol length qname qtype latency"
c.Global.TextFormat = "timestamp identity operation rcode queryip queryport family protocol length-unit qname qtype latency"
c.Global.TextFormatDelimiter = " "
c.Global.TextFormatBoundary = "\""

Expand Down
4 changes: 3 additions & 1 deletion dnsutils/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,10 @@ func (dm *DNSMessage) Bytes(format []string, fieldDelimiter string, fieldBoundar
s.WriteString(dm.NetworkInfo.Family)
case directive == "protocol":
s.WriteString(dm.NetworkInfo.Protocol)
case directive == "length":
case directive == "length-unit":
s.WriteString(strconv.Itoa(dm.DNS.Length) + "b")
case directive == "length":
s.WriteString(strconv.Itoa(dm.DNS.Length))
case directive == "qname":
if len(dm.DNS.Qname) == 0 {
s.WriteString(".")
Expand Down
5 changes: 5 additions & 0 deletions dnsutils/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ func TestDnsMessage_TextFormat_DefaultDirectives(t *testing.T) {
{
format: "length",
dm: DNSMessage{DNS: DNS{Length: 42}},
expected: "42",
},
{
format: "length-unit",
dm: DNSMessage{DNS: DNS{Length: 42}},
expected: "42b",
},
{
Expand Down
5 changes: 3 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Default directives:
- `id`: dns id
- `family`: ip protocol version INET or INET6
- `protocol`: protocol UDP, TCP
- `length`: the length of the query or reply
- `length`: the length of the query or reply in bytes
- `length-unit`: the length of the query or reply in bytes with unit (`b`)
- `qtype`: dns qtype
- `qname`: dns qname
- `latency`: computed latency between queries and replies
Expand All @@ -101,7 +102,7 @@ Default directives:

```yaml
global:
text-format: "timestamp-rfc3339ns identity qr operation rcode queryip queryport family protocol length qname qtype latency ttl"
text-format: "timestamp-rfc3339ns identity qr operation rcode queryip queryport family protocol length-unit qname qtype latency ttl"
text-format-delimiter: " "
text-format-boundary: "\""
```
Expand Down

0 comments on commit 4b16f8a

Please sign in to comment.