Skip to content

Commit 0ace28a

Browse files
route: fix case statement complexity
1 parent b36e447 commit 0ace28a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

route/address.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ func marshalAddrs(b []byte, as []Addr) (uint, error) {
396396
func parseAddrs(attrs uint, fn func(int, []byte) (int, Addr, error), b []byte) ([]Addr, error) {
397397
var as [syscall.RTAX_MAX]Addr
398398
af := int(syscall.AF_UNSPEC)
399+
isInet := func(fam int) bool {
400+
return fam == syscall.AF_INET || fam == syscall.AF_INET6
401+
}
402+
isMask := func(addrType uint) bool {
403+
return addrType == syscall.RTAX_NETMASK || addrType == syscall.RTAX_GENMASK
404+
}
399405
for i := uint(0); i < syscall.RTAX_MAX && len(b) >= roundup(0); i++ {
400406
if attrs&(1<<i) == 0 {
401407
continue
@@ -413,8 +419,8 @@ func parseAddrs(attrs uint, fn func(int, []byte) (int, Addr, error), b []byte) (
413419
return nil, errMessageTooShort
414420
}
415421
b = b[l:]
416-
case ((b[1] == syscall.AF_INET || b[1] == syscall.AF_INET6) || ((i == syscall.RTAX_NETMASK || i == syscall.RTAX_GENMASK) && (af == syscall.AF_INET || af == syscall.AF_INET6))):
417-
if (i != syscall.RTAX_NETMASK && i != syscall.RTAX_GENMASK) {
422+
case isInet(int(b[1])) || (isMask(i) && isInet(af)):
423+
if !isMask(i){
418424
af = int(b[1])
419425
}
420426
a, err := parseInetAddr(af, b)

route/example_darwin_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package route_test
26

37
import (

0 commit comments

Comments
 (0)