@@ -5,6 +5,7 @@ package wglinux
55
66import (
77 "net"
8+ "net/netip"
89 "testing"
910 "time"
1011 "unsafe"
@@ -45,9 +46,9 @@ func TestLinuxClientConfigureDevice(t *testing.T) {
4546 name : "bad peer allowed IP" ,
4647 cfg : wgtypes.Config {
4748 Peers : []wgtypes.PeerConfig {{
48- AllowedIPs : []net. IPNet { {
49- IP : net. IP { 0xff },
50- }} ,
49+ AllowedIPs : []netip. Prefix {
50+ { },
51+ },
5152 }},
5253 },
5354 },
@@ -71,8 +72,8 @@ func TestLinuxClientConfigureDevice(t *testing.T) {
7172 PresharedKey : keyPtr (wgtest .MustHexKey ("188515093e952f5f22e865cef3012e72f8b5f0b598ac0309d5dacce3b70fcf52" )),
7273 Endpoint : wgtest .MustUDPAddr ("[abcd:23::33%2]:51820" ),
7374 ReplaceAllowedIPs : true ,
74- AllowedIPs : []net. IPNet {
75- wgtest . MustCIDR ("192.168.4.4/32" ),
75+ AllowedIPs : []netip. Prefix {
76+ netip . MustParsePrefix ("192.168.4.4/32" ),
7677 },
7778 },
7879 {
@@ -81,17 +82,17 @@ func TestLinuxClientConfigureDevice(t *testing.T) {
8182 Endpoint : wgtest .MustUDPAddr ("182.122.22.19:3233" ),
8283 PersistentKeepaliveInterval : durPtr (111 * time .Second ),
8384 ReplaceAllowedIPs : true ,
84- AllowedIPs : []net. IPNet {
85- wgtest . MustCIDR ("192.168.4.6/32" ),
85+ AllowedIPs : []netip. Prefix {
86+ netip . MustParsePrefix ("192.168.4.6/32" ),
8687 },
8788 },
8889 {
8990 PublicKey : wgtest .MustHexKey ("662e14fd594556f522604703340351258903b64f35553763f19426ab2a515c58" ),
9091 Endpoint : wgtest .MustUDPAddr ("5.152.198.39:51820" ),
9192 ReplaceAllowedIPs : true ,
92- AllowedIPs : []net. IPNet {
93- wgtest . MustCIDR ("192.168.4.10/32" ),
94- wgtest . MustCIDR ("192.168.4.11/32" ),
93+ AllowedIPs : []netip. Prefix {
94+ netip . MustParsePrefix ("192.168.4.10/32" ),
95+ netip . MustParsePrefix ("192.168.4.11/32" ),
9596 },
9697 },
9798 {
@@ -151,8 +152,8 @@ func TestLinuxClientConfigureDevice(t *testing.T) {
151152 },
152153 {
153154 Type : netlink .Nested | unix .WGPEER_A_ALLOWEDIPS ,
154- Data : mustAllowedIPs ([]net. IPNet {
155- wgtest . MustCIDR ("192.168.4.4/32" ),
155+ Data : mustAllowedIPs ([]netip. Prefix {
156+ netip . MustParsePrefix ("192.168.4.4/32" ),
156157 }),
157158 },
158159 }... ),
@@ -182,8 +183,8 @@ func TestLinuxClientConfigureDevice(t *testing.T) {
182183 },
183184 {
184185 Type : netlink .Nested | unix .WGPEER_A_ALLOWEDIPS ,
185- Data : mustAllowedIPs ([]net. IPNet {
186- wgtest . MustCIDR ("192.168.4.6/32" ),
186+ Data : mustAllowedIPs ([]netip. Prefix {
187+ netip . MustParsePrefix ("192.168.4.6/32" ),
187188 }),
188189 },
189190 }... ),
@@ -209,9 +210,9 @@ func TestLinuxClientConfigureDevice(t *testing.T) {
209210 },
210211 {
211212 Type : netlink .Nested | unix .WGPEER_A_ALLOWEDIPS ,
212- Data : mustAllowedIPs ([]net. IPNet {
213- wgtest . MustCIDR ("192.168.4.10/32" ),
214- wgtest . MustCIDR ("192.168.4.11/32" ),
213+ Data : mustAllowedIPs ([]netip. Prefix {
214+ netip . MustParsePrefix ("192.168.4.10/32" ),
215+ netip . MustParsePrefix ("192.168.4.11/32" ),
215216 }),
216217 },
217218 }... ),
@@ -513,23 +514,25 @@ func keyBytes(s string) []byte {
513514 return k [:]
514515}
515516
516- func generateIPs (n int ) []net. IPNet {
517+ func generateIPs (n int ) []netip. Prefix {
517518 cur , err := ipaddr .Parse ("2001:db8::/64" )
518519 if err != nil {
519520 panicf ("failed to create cursor: %v" , err )
520521 }
521522
522- ips := make ([]net. IPNet , 0 , n )
523+ ips := make ([]netip. Prefix , 0 , n )
523524 for i := 0 ; i < n ; i ++ {
524525 pos := cur .Next ()
525526 if pos == nil {
526527 panic ("hit nil IP during IP generation" )
527528 }
528529
529- ips = append (ips , net.IPNet {
530- IP : pos .IP ,
531- Mask : net .CIDRMask (128 , 128 ),
532- })
530+ addr , ok := netip .AddrFromSlice (pos .IP )
531+ if ! ok {
532+ panicf ("failed to convert net.IP to netip.Addr: %s" , pos .IP )
533+ }
534+
535+ ips = append (ips , netip .PrefixFrom (addr , 128 ))
533536 }
534537
535538 return ips
0 commit comments