Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add RD flag handling in text format directive #893

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p align="center">
<img src="https://goreportcard.com/badge/github.com/dmachard/go-dns-collector" alt="Go Report"/>
<img src="https://img.shields.io/badge/go%20version-min%201.21-green" alt="Go version"/>
<img src="https://img.shields.io/badge/go%20tests-510-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20tests-513-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20bench-21-green" alt="Go bench"/>
<img src="https://img.shields.io/badge/go%20lines-31977-green" alt="Go lines"/>
<img src="https://img.shields.io/badge/go%20lines-32126-green" alt="Go lines"/>
</p>

<p align="center">
Expand Down
6 changes: 6 additions & 0 deletions dnsutils/dnsmessage_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ func (dm *DNSMessage) ToTextLine(format []string, fieldDelimiter string, fieldBo
} else {
s.WriteByte('-')
}
case directive == "rd":
if flags.RD {
s.WriteString("RD")
} else {
s.WriteByte('-')
}
case directive == "ttl":
if len(an) > 0 {
s.WriteString(strconv.Itoa(an[0].TTL))
Expand Down
10 changes: 10 additions & 0 deletions dnsutils/dnsmessage_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ func TestDnsMessage_TextFormat_DefaultDirectives(t *testing.T) {
dm: DNSMessage{DNS: DNS{Flags: DNSFlags{TC: true, AA: true, RA: true, AD: true}}},
expected: "TC AA RA AD",
},
{
format: "rd",
dm: DNSMessage{DNS: DNS{Flags: DNSFlags{RD: true}}},
expected: "RD",
},
{
format: "tc aa ra ad rd",
dm: DNSMessage{DNS: DNS{Flags: DNSFlags{TC: false, AA: false, RA: false, AD: false, RD: false}}},
expected: "- - - - -",
},
{
format: "df tr",
dm: DNSMessage{NetworkInfo: DNSNetInfo{IPDefragmented: true, TCPReassembled: true}},
Expand Down
15 changes: 8 additions & 7 deletions docs/dnsconversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ The text format can be customized using the following directives.
- `ttl`: answer ttl, only the first one
- `answer`: rdata answer, only the first one, prefer to use the JSON format if you wamt all answers
- `malformed`: malformed dns packet, integer value 1/0
- `qr`: query or reply flag, string value Q/R
- `tc`: flag truncated response
- `aa`: flag authoritative answer
- `ra`: flag recursion available
- `ad`: flag authenticated data
- `df`: flag when ip defragmented occured
- `tr`: flag when tcp reassembled occured
- `qr`: Query or reply flag, indicating the type of message. Possible values: `Q` (query) or `R` (reply).
- `tc`: Truncated response flag, indicates whether the response was truncated. Value is `TC` for enabled, `-` for disabled.
- `aa`: Authoritative answer flag, indicates if the answer comes from an authoritative source. Value is `AA` for enabled, `-` for disabled.
- `ra`: Recursion available flag, indicates if recursion is supported by the server. Value is `RA` for enabled, `-` for disabled.
- `rd`: Recursion desired flag, indicates if recursion was requested. Value is `RD` for enabled, `-` for disabled.
- `ad`: Authenticated data flag, indicates that the response has been verified. Value is `AD` for enabled, `-` for disabled.
- `df`: Defragmentation flag, indicates that IP defragmentation occurred. Value is `DF` for enabled, `-` for disabled.
- `tr`: TCP reassembly flag, indicates that TCP reassembly occurred. Value is `TR` for enabled, `-` for disabled.
- `edns-csubnet`: display client subnet info

The default text format can be set in the global configuration or individually for each logger. Here’s the default format:
Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The File Logger allows you to log DNS traffic to a file in various formats, with

* `text-format` (string)
> output text format, please refer to the default text format to see all
> available directives, use this parameter if you want a specific format.
> available [text directives](../dnsconversions.md#text-format-inline), use this parameter if you want a specific format.

* `jinja-format` (string)
> jinja template, please refer [Jinja templating](../dnsconversions.md#jinja-templating) to see all available directives
Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_kafka.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Options:
> Specifies the output format for Kafka messages. Output format: `text`, `json`, or `flat-json`.

* `text-format` (string)
> output text format, please refer to the default text format to see all available [directives](../configuration.md#custom-text-format), use this parameter if you want a specific format
> output text format, please refer to the default text format to see all available [text directives](../dnsconversions.md#text-format-inline), use this parameter if you want a specific format

* `buffer-size` (integer)
> Specifies the size of the bulk for DNS messages before they are sent to Kafka.
Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_loki.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Options:
> interval in second between before to retry to send batch

* `text-format` (string)
> output text format, please refer to the default text format to see all available [directives](../configuration.md#custom-text-format), use this parameter if you want a specific format
> output text format, please refer to the default text format to see all available [text directives](../dnsconversions.md#text-format-inline), use this parameter if you want a specific format

* `proxy-url` (string)
> Proxy URL
Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_scalyr.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Options:
> batch size for log entries in bytes

* `text-format` (string)
> output text format, please refer to the default text format to see all available directives, use this parameter if you want a specific format
> output text format, please refer to the default text format to see all available [text directives](../dnsconversions.md#text-format-inline), use this parameter if you want a specific format

* `proxy-url` (string)
> Proxy URL
Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_stdout.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Options:
> output format: `text`, `jinja`, `json`, `flat-json` or `pcap`

* `text-format` (string)
> output text format, please refer to the default text format to see all available [directives](../configuration.md#custom-text-format), use this parameter if you want a specific format
> output text format, please refer to the default text format to see all available [text directives](../dnsconversions.md#text-format-inline) use this parameter if you want a specific format

* `jinja-format` (string)
> jinja template, please refer [Jinja templating](../dnsconversions.md#jinja-templating) to see all available directives
Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_syslog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Options:
> output format: `text`, `json`, or `flat-json`

* `text-format` (string)
> output text format, please refer to the default text format to see all available [directives](../configuration.md#custom-text-format), use this parameter if you want a specific format
> output text format, please refer to the default text format to see all available [text directives](../dnsconversions.md#text-format-inline), use this parameter if you want a specific format

* `tls-insecure` (boolean)
> If set to true, skip verification of server certificate.
Expand Down
2 changes: 1 addition & 1 deletion docs/loggers/logger_tcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Options:
> Output format: `text`, `json`, or `flat-json`

* `text-format` (string)
> output text format, please refer to the default text format to see all available [directives](../configuration.md#custom-text-format), use this parameter if you want a specific format
> output text format, please refer to the default text format to see all available [text directives](../dnsconversions.md#text-format-inline), use this parameter if you want a specific format

* `buffer-size` (integer)
> how many DNS messages will be buffered before being sent
Expand Down
Loading