Skip to content

Commit 3a9e753

Browse files
committed
conn: disable sticky sockets on Android
We can't have the netlink listener socket, so it's not possible to support it. Plus, android networking stack complexity makes it a bit tricky anyway, so best to leave it disabled. Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent cc20c08 commit 3a9e753

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

conn/controlfns_linux.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package conn
77

88
import (
99
"fmt"
10+
"runtime"
1011
"syscall"
1112

1213
"golang.org/x/sys/unix"
@@ -36,14 +37,18 @@ func init() {
3637
var err error
3738
switch network {
3839
case "udp4":
39-
c.Control(func(fd uintptr) {
40-
err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_PKTINFO, 1)
41-
})
40+
if runtime.GOOS != "android" {
41+
c.Control(func(fd uintptr) {
42+
err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_PKTINFO, 1)
43+
})
44+
}
4245
case "udp6":
4346
c.Control(func(fd uintptr) {
44-
err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_RECVPKTINFO, 1)
45-
if err != nil {
46-
return
47+
if runtime.GOOS != "android" {
48+
err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_RECVPKTINFO, 1)
49+
if err != nil {
50+
return
51+
}
4752
}
4853
err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_V6ONLY, 1)
4954
})

conn/sticky_default.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !linux
1+
//go:build !linux || android
22

33
/* SPDX-License-Identifier: MIT
44
*
@@ -23,3 +23,5 @@ func setSrcControl(control *[]byte, ep *StdNetEndpoint) {
2323
// srcControlSize returns the recommended buffer size for pooling sticky control
2424
// data.
2525
const srcControlSize = 0
26+
27+
const StdNetSupportsStickySockets = false

conn/sticky_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build linux && !android
2+
13
/* SPDX-License-Identifier: MIT
24
*
35
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
@@ -111,3 +113,5 @@ func setSrcControl(control *[]byte, ep *StdNetEndpoint) {
111113
}
112114

113115
var srcControlSize = unix.CmsgSpace(unix.SizeofInet6Pktinfo)
116+
117+
const StdNetSupportsStickySockets = true

conn/sticky_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux
1+
//go:build linux && !android
22

33
/* SPDX-License-Identifier: MIT
44
*

device/sticky_linux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525
)
2626

2727
func (device *Device) startRouteListener(bind conn.Bind) (*rwcancel.RWCancel, error) {
28+
if !conn.StdNetSupportsStickySockets {
29+
return nil, nil
30+
}
2831
if _, ok := bind.(*conn.StdNetBind); !ok {
2932
return nil, nil
3033
}

0 commit comments

Comments
 (0)