mirror of
https://git.zx2c4.com/wireguard-go
synced 2025-10-06 00:57:23 +08:00
conn: fix StdNetBind fallback on Windows
If RIO is unavailable, NewWinRingBind() falls back to StdNetBind. StdNetBind uses x/net/ipv{4,6}.PacketConn for sending and receiving datagrams, specifically via the {Read,Write}Batch methods. These methods are unimplemented on Windows and will return runtime errors as a result. Additionally, only Linux benefits from these x/net types for reading and writing, so we update StdNetBind to fall back to the standard library net package for all platforms other than Linux. Reviewed-by: James Tucker <james@tailscale.com> Signed-off-by: Jordan Whited <jordan@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:

committed by
Jason A. Donenfeld

parent
dbd949307e
commit
2fcdaf9799
22
conn/bind_std_test.go
Normal file
22
conn/bind_std_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package conn
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStdNetBindReceiveFuncAfterClose(t *testing.T) {
|
||||
bind := NewStdNetBind().(*StdNetBind)
|
||||
fns, _, err := bind.Open(0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bind.Close()
|
||||
buffs := make([][]byte, 1)
|
||||
buffs[0] = make([]byte, 1)
|
||||
sizes := make([]int, 1)
|
||||
eps := make([]Endpoint, 1)
|
||||
for _, fn := range fns {
|
||||
// The ReceiveFuncs must not access conn-related fields on StdNetBind
|
||||
// unguarded. Close() nils the conn-related fields resulting in a panic
|
||||
// if they violate the mutex.
|
||||
fn(buffs, sizes, eps)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user