Skip to content

Commit

Permalink
go.d dnsmasqdhcp: simplify parseDHCPRangeValue (netdata#18401)
Browse files Browse the repository at this point in the history
(cherry picked from commit f02adc9)
  • Loading branch information
ilyam8 authored and stelfrag committed Sep 6, 2024
1 parent 86da19d commit b0c7c50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/go/plugin/go.d/modules/dnsmasq_dhcp/dhcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func TestDnsmasqDHCP_parseDHCPRangeValue(t *testing.T) {
wantFail: true,
input: "1234::,ra-stateless",
},
"invalid": {
wantFail: true,
input: "192.168.0.0",
},
}

for name, test := range tests {
Expand Down
10 changes: 4 additions & 6 deletions src/go/plugin/go.d/modules/dnsmasq_dhcp/parse_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ func parseDHCPRangeValue(s string) (r string) {
var start, end net.IP
parts := strings.Split(s, ",")

for i, v := range parts {
if start = net.ParseIP(strings.TrimSpace(v)); start == nil {
for _, v := range parts {
if start == nil {
start = net.ParseIP(v)
continue
}
if len(parts) < i+1 {
return ""
}
if end = net.ParseIP(parts[i+1]); end == nil || iprange.New(start, end) == nil {
if end = net.ParseIP(v); end == nil || iprange.New(start, end) == nil {
return ""
}
return fmt.Sprintf("%s-%s", start, end)
Expand Down

0 comments on commit b0c7c50

Please sign in to comment.