Skip to content

Commit

Permalink
filebeat/input/{tcp,udp}: use correct address list in udp (#35996)
Browse files Browse the repository at this point in the history
Also add a check in the common path to check that the addr slice is the
same length as the undefined addr slice, returning an error on mismatch
rather than allowing the panic.

(cherry picked from commit e741a6d)
  • Loading branch information
efd6 authored and mergify[bot] committed Jul 10, 2023
1 parent 6c64a37 commit 64658e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Expand Up @@ -144,6 +144,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Fix metric collection in GCPPubSub input. {pull}35773[35773]
- Fix end point deregistration in http_endpoint input. {issue}35899[35899] {pull}35903[35903]
- Fix duplicate ID panic in filestream metrics. {issue}35964[35964] {pull}35972[35972]
- Improve error reporting and fix IPv6 handling of TCP and UDP metric collection. {pull}35996[35996]

*Heartbeat*

Expand Down
3 changes: 3 additions & 0 deletions filebeat/input/tcp/input.go
Expand Up @@ -338,6 +338,9 @@ func procNetTCP(path string, addr []string, hasUnspecified bool, addrIsUnspecifi
if len(addr) == 0 {
return 0, nil
}
if len(addr) != len(addrIsUnspecified) {
return 0, errors.New("mismatched address/unspecified lists: please report this")
}
b, err := os.ReadFile(path)
if err != nil {
return 0, err
Expand Down
7 changes: 5 additions & 2 deletions filebeat/input/udp/input.go
Expand Up @@ -272,7 +272,7 @@ func (m *inputMetrics) poll(addr, addr6 []string, each time.Duration, log *logp.
if err != nil {
log.Warnf("failed to get initial udp stats from /proc: %v", err)
}
rx6, drops6, err := procNetUDP("/proc/net/udp6", addr, hasUnspecified6, addrIsUnspecified6)
rx6, drops6, err := procNetUDP("/proc/net/udp6", addr6, hasUnspecified6, addrIsUnspecified6)
if err != nil {
log.Warnf("failed to get initial udp6 stats from /proc: %v", err)
}
Expand All @@ -288,7 +288,7 @@ func (m *inputMetrics) poll(addr, addr6 []string, each time.Duration, log *logp.
log.Warnf("failed to get udp stats from /proc: %v", err)
continue
}
rx6, drops6, err := procNetUDP("/proc/net/udp6", addr, hasUnspecified6, addrIsUnspecified6)
rx6, drops6, err := procNetUDP("/proc/net/udp6", addr6, hasUnspecified6, addrIsUnspecified6)
if err != nil {
log.Warnf("failed to get udp6 stats from /proc: %v", err)
continue
Expand Down Expand Up @@ -333,6 +333,9 @@ func procNetUDP(path string, addr []string, hasUnspecified bool, addrIsUnspecifi
if len(addr) == 0 {
return 0, 0, nil
}
if len(addr) != len(addrIsUnspecified) {
return 0, 0, errors.New("mismatched address/unspecified lists: please report this")
}
b, err := os.ReadFile(path)
if err != nil {
return 0, 0, err
Expand Down

0 comments on commit 64658e0

Please sign in to comment.