Sends every /24 block inside prefix to out. Anything already /24 or smaller collapses to the single /24 that covers it.
(prefix netip.Prefix, out chan<- netip.Prefix)
| 188 | // Sends every /24 block inside prefix to out. Anything already /24 or smaller |
| 189 | // collapses to the single /24 that covers it. |
| 190 | func processPrefix(prefix netip.Prefix, out chan<- netip.Prefix) { |
| 191 | bits := prefix.Bits() |
| 192 | if bits >= 24 { |
| 193 | out <- netip.PrefixFrom(prefix.Addr(), 24).Masked() |
| 194 | return |
| 195 | } |
| 196 | ip := prefix.Addr() |
| 197 | for i := 0; i < 1<<(24-bits); i++ { |
| 198 | out <- netip.PrefixFrom(ip, 24).Masked() |
| 199 | ip = incrementIP(ip, 256) |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // Returns ip advanced by increment, using plain IPv4 (uint32) math. |
| 204 | func incrementIP(ip netip.Addr, increment int) netip.Addr { |
no test coverage detected