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(inputs.powerdns_recursor): Support for new PowerDNS recursor control protocol #9633

Merged
merged 26 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ca539ea
Add support for new PowerDNS recursor control protocol
OrfeasZ Aug 16, 2021
efd2dda
style: fix coding style of powerdns_recursor code
OrfeasZ Aug 16, 2021
2a0609d
Merge branch 'master' into master
powersj Jan 6, 2022
76e65fb
fix: switch to using require instead of assert for pdns recursor test
OrfeasZ Jan 6, 2022
b1a728a
fix: resolve lint errors in pdns recursor plugin readme
OrfeasZ Jan 6, 2022
dc16fd1
fix: ignore unneeded lint check in pdns recursor plugin test
OrfeasZ Jan 6, 2022
62e2faf
Merge remote-tracking branch 'upstream/master'
OrfeasZ Jul 9, 2022
fd322d0
Add support for the new PowerDNS Recursor control protocol
OrfeasZ Jul 11, 2022
4c6868a
Try to silence the linter
OrfeasZ Jul 11, 2022
7c52f21
Provide additional safety against misuse
OrfeasZ Jul 11, 2022
778c5e6
Merge remote-tracking branch 'upstream/master'
OrfeasZ Aug 12, 2022
02c50f4
Refactor powerdns recursor plugin based on PR feedback
OrfeasZ Aug 12, 2022
3b1be25
Apply suggestions from code review
OrfeasZ Nov 17, 2022
9f506d2
Merge branch 'influxdata:master' into master
OrfeasZ Nov 17, 2022
6506d93
Update powerdns recursor plugin readme
OrfeasZ Nov 17, 2022
7649148
Update powerdns recursor versions in sample config
OrfeasZ Nov 17, 2022
f680797
Remove unneeded return value from writeNativeUIntToConn
OrfeasZ Nov 17, 2022
eb30430
Remove trailing readme spaces
OrfeasZ Nov 17, 2022
a553d66
Remove trailing space
OrfeasZ Nov 17, 2022
974511a
Add length check to powerdns response parsing
OrfeasZ Nov 25, 2022
9da0a14
Add trailing newline to powerdns recursor sample config
OrfeasZ Nov 25, 2022
6b103a5
Update docs
OrfeasZ Nov 25, 2022
5f4233c
Reformat code
OrfeasZ Nov 25, 2022
e9fe9c9
Merge branch 'influxdata:master' into master
OrfeasZ Dec 10, 2022
03f6624
Switch to internal host endianness variable
OrfeasZ Dec 10, 2022
b8a4e6c
Refactor if block into switch case
OrfeasZ Dec 12, 2022
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
Prev Previous commit
Next Next commit
Provide additional safety against misuse
  • Loading branch information
OrfeasZ committed Jul 11, 2022
commit 7c52f214aa3c7167a641bf0ef798b268e2e4128f
10 changes: 5 additions & 5 deletions plugins/inputs/powerdns_recursor/protocol_commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func parseResponse(metrics string) map[string]interface{} {
// depending on the platform the program is being run on.
// At the time of writing, the Go type `uint` has the same
// behavior, where its size and endianness are platform
// dependent. This means that we can do an unsafe cast to
// grab the data representing the length, and know that in
// most cases it'll be what we need. In all other cases,
// we still handle all error cases gracefully, so the plugin
// will just fail to gather data.
// dependent. Using the unsafe method below, and the known
// integer size, we can "recreate" the corresponding C
// behavior in an effort to maintain compatibility. Of course
// in cases where one program is compiled for i386 and the
// other for amd64 (and similar), this method will fail.

const UIntSizeInBytes = strconv.IntSize / 8
OrfeasZ marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/powerdns_recursor/protocol_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (p *PowerdnsRecursor) gatherFromV1Server(address string, acc telegraf.Accum
}

// Read the response data.
buf := make([]byte, 16384)
buf := make([]byte, 16_384)
n, err := conn.Read(buf)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/powerdns_recursor/protocol_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// Unix datagram socket
// Synchronous request / response, individual datagrams
// Datagram 1 => status: uint32
// Datagram 2 => data: byte[] (max 16384 bytes)
// Datagram 2 => data: byte[] (max 16_384 bytes)
func (p *PowerdnsRecursor) gatherFromV2Server(address string, acc telegraf.Accumulator) error {
randomNumber := rand.Int63()
recvSocket := filepath.Join("/", "var", "run", fmt.Sprintf("pdns_recursor_telegraf%d", randomNumber))
Expand Down Expand Up @@ -75,7 +75,7 @@ func (p *PowerdnsRecursor) gatherFromV2Server(address string, acc telegraf.Accum
}

// Read the response data.
buf := make([]byte, 16384)
buf := make([]byte, 16_384)
n, err = conn.Read(buf)
if err != nil {
return err
Expand Down
10 changes: 9 additions & 1 deletion plugins/inputs/powerdns_recursor/protocol_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ func (p *PowerdnsRecursor) gatherFromV3Server(address string, acc telegraf.Accum
return err
}
if responseLength == 0 {
return fmt.Errorf("received data length was 0")
return fmt.Errorf("received data length was '0'")
}

// Don't allow more than 64kb of data to prevent DOS / issues
// with architecture mismatch. V2 protocol allowed for up to
// 16kb, so 64kb should give us a pretty good margin for anything
// that has been added since.
if responseLength > 64*1024 {
return fmt.Errorf("received data length was '%v', we only allow up to '%v'", responseLength, 64*1024)
OrfeasZ marked this conversation as resolved.
Show resolved Hide resolved
}

data := make([]byte, responseLength)
Expand Down