|
8 | 8 | "encoding/binary" |
9 | 9 | "fmt" |
10 | 10 | "net" |
| 11 | + "net/netip" |
11 | 12 | "os" |
12 | 13 | "runtime" |
13 | 14 | "time" |
@@ -201,7 +202,7 @@ func parseDevice(name string, ifio *wgh.WGInterfaceIO) (*wgtypes.Device, error) |
201 | 202 |
|
202 | 203 | // Same idea, we know how many allowed IPs we need to account for, so |
203 | 204 | // reserve the space and advance the pointer through each WGAIP structure. |
204 | | - p.AllowedIPs = make([]net.IPNet, 0, peer.Aips_count) |
| 205 | + p.AllowedIPs = make([]netip.Prefix, 0, peer.Aips_count) |
205 | 206 | for j := uintptr(0); j < uintptr(peer.Aips_count); j++ { |
206 | 207 | aip := (*wgh.WGAIPIO)(unsafe.Pointer( |
207 | 208 | uintptr(unsafe.Pointer(peer)) + wgh.SizeofWGPeerIO + j*wgh.SizeofWGAIPIO, |
@@ -283,21 +284,15 @@ func parsePeer(pio *wgh.WGPeerIO) wgtypes.Peer { |
283 | 284 | } |
284 | 285 |
|
285 | 286 | // parseAllowedIP unpacks a net.IPNet from a WGAIP structure. |
286 | | -func parseAllowedIP(aip *wgh.WGAIPIO) net.IPNet { |
| 287 | +func parseAllowedIP(aip *wgh.WGAIPIO) netip.Prefix { |
287 | 288 | switch aip.Af { |
288 | 289 | case unix.AF_INET: |
289 | | - return net.IPNet{ |
290 | | - IP: net.IP(aip.Addr[:net.IPv4len]), |
291 | | - Mask: net.CIDRMask(int(aip.Cidr), 32), |
292 | | - } |
| 290 | + return netip.PrefixFrom(netip.AddrFrom4([4]byte(aip.Addr[:4])), int(aip.Cidr)) |
293 | 291 | case unix.AF_INET6: |
294 | | - return net.IPNet{ |
295 | | - IP: net.IP(aip.Addr[:]), |
296 | | - Mask: net.CIDRMask(int(aip.Cidr), 128), |
297 | | - } |
| 292 | + return netip.PrefixFrom(netip.AddrFrom16(aip.Addr), int(aip.Cidr)) |
298 | 293 | default: |
299 | 294 | panicf("wgopenbsd: invalid address family for allowed IP: %+v", aip) |
300 | | - return net.IPNet{} |
| 295 | + return netip.Prefix{} |
301 | 296 | } |
302 | 297 | } |
303 | 298 |
|
|
0 commit comments