mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-30 02:43:05 +00:00
lint and nolint tailscale borrowed func
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
ecd62fb785
commit
10320a5f1f
1 changed files with 8 additions and 10 deletions
18
acls.go
18
acls.go
|
@ -830,6 +830,7 @@ var (
|
||||||
// around, and ultimately use a new version of IPSet.ContainsFunc like
|
// around, and ultimately use a new version of IPSet.ContainsFunc like
|
||||||
// Contains16Func that works in [16]byte address, so we we can match
|
// Contains16Func that works in [16]byte address, so we we can match
|
||||||
// at runtime without allocating?
|
// at runtime without allocating?
|
||||||
|
// nolint
|
||||||
func parseIPSet(arg string, bits *int) ([]netip.Prefix, error) {
|
func parseIPSet(arg string, bits *int) ([]netip.Prefix, error) {
|
||||||
if arg == "*" {
|
if arg == "*" {
|
||||||
// User explicitly requested wildcard.
|
// User explicitly requested wildcard.
|
||||||
|
@ -846,22 +847,27 @@ func parseIPSet(arg string, bits *int) ([]netip.Prefix, error) {
|
||||||
if pfx != pfx.Masked() {
|
if pfx != pfx.Masked() {
|
||||||
return nil, fmt.Errorf("%v contains non-network bits set", pfx)
|
return nil, fmt.Errorf("%v contains non-network bits set", pfx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return []netip.Prefix{pfx}, nil
|
return []netip.Prefix{pfx}, nil
|
||||||
}
|
}
|
||||||
if strings.Count(arg, "-") == 1 {
|
if strings.Count(arg, "-") == 1 {
|
||||||
ip1s, ip2s, _ := strings.Cut(arg, "-")
|
ip1s, ip2s, _ := strings.Cut(arg, "-")
|
||||||
|
|
||||||
ip1, err := netip.ParseAddr(ip1s)
|
ip1, err := netip.ParseAddr(ip1s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ip2, err := netip.ParseAddr(ip2s)
|
ip2, err := netip.ParseAddr(ip2s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r := netipx.IPRangeFrom(ip1, ip2)
|
r := netipx.IPRangeFrom(ip1, ip2)
|
||||||
if !r.Valid() {
|
if !r.IsValid() {
|
||||||
return nil, fmt.Errorf("invalid IP range %q", arg)
|
return nil, fmt.Errorf("invalid IP range %q", arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.Prefixes(), nil
|
return r.Prefixes(), nil
|
||||||
}
|
}
|
||||||
ip, err := netip.ParseAddr(arg)
|
ip, err := netip.ParseAddr(arg)
|
||||||
|
@ -875,16 +881,8 @@ func parseIPSet(arg string, bits *int) ([]netip.Prefix, error) {
|
||||||
}
|
}
|
||||||
bits8 = uint8(*bits)
|
bits8 = uint8(*bits)
|
||||||
}
|
}
|
||||||
return []netip.Prefix{netip.PrefixFrom(ip, int(bits8))}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ipInPrefixList(ip netip.Addr, netlist []netip.Prefix) bool {
|
return []netip.Prefix{netip.PrefixFrom(ip, int(bits8))}, nil
|
||||||
for _, net := range netlist {
|
|
||||||
if net.Contains(ip) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Match struct {
|
type Match struct {
|
||||||
|
|
Loading…
Reference in a new issue