mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-02 13:47:00 +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 (
|
||||
"fmt"
|
||||
"iter"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
@ -111,3 +112,16 @@ func StringToIPPrefix(prefixes []string) ([]netip.Prefix, error) {
|
||||
|
||||
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