mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-06 17:54:31 +02:00
utility iterator for ipset
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
7891378f57
commit
1dd50c6916
@ -2,6 +2,7 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"iter"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -111,3 +112,16 @@ func StringToIPPrefix(prefixes []string) ([]netip.Prefix, error) {
|
|||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IPSetAddrIter returns a function that iterates over all the IPs in the IPSet.
|
||||||
|
func IPSetAddrIter(ipSet *netipx.IPSet) iter.Seq[netip.Addr] {
|
||||||
|
return func(yield func(netip.Addr) bool) {
|
||||||
|
for _, rng := range ipSet.Ranges() {
|
||||||
|
for ip := rng.From(); ip.Compare(rng.To()) <= 0; ip = ip.Next() {
|
||||||
|
if !yield(ip) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user