]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
conn: disable sticky sockets on Android
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 23 Mar 2023 17:38:34 +0000 (18:38 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 23 Mar 2023 17:39:00 +0000 (18:39 +0100)
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 <Jason@zx2c4.com>
conn/controlfns_linux.go
conn/sticky_default.go
conn/sticky_linux.go
conn/sticky_linux_test.go
device/sticky_linux.go

index aff62456f38647b269d4940e79ba779b34eae285..a2396fe899c6bbeef424d1dd3e6fb72160a0fbdc 100644 (file)
@@ -7,6 +7,7 @@ package conn
 
 import (
        "fmt"
+       "runtime"
        "syscall"
 
        "golang.org/x/sys/unix"
@@ -36,14 +37,18 @@ func init() {
                        var err error
                        switch network {
                        case "udp4":
-                               c.Control(func(fd uintptr) {
-                                       err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_PKTINFO, 1)
-                               })
+                               if runtime.GOOS != "android" {
+                                       c.Control(func(fd uintptr) {
+                                               err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_PKTINFO, 1)
+                                       })
+                               }
                        case "udp6":
                                c.Control(func(fd uintptr) {
-                                       err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_RECVPKTINFO, 1)
-                                       if err != nil {
-                                               return
+                                       if runtime.GOOS != "android" {
+                                               err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_RECVPKTINFO, 1)
+                                               if err != nil {
+                                                       return
+                                               }
                                        }
                                        err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_V6ONLY, 1)
                                })
index 8c0adf59b8f9bd53a18bf11940caf1a9508f5215..05f00ea5b08f6150948ade79b207077c811c0bb4 100644 (file)
@@ -1,4 +1,4 @@
-//go:build !linux
+//go:build !linux || android
 
 /* SPDX-License-Identifier: MIT
  *
@@ -23,3 +23,5 @@ func setSrcControl(control *[]byte, ep *StdNetEndpoint) {
 // srcControlSize returns the recommended buffer size for pooling sticky control
 // data.
 const srcControlSize = 0
+
+const StdNetSupportsStickySockets = false
index 278eb195a344b95b9a54b3246d9ce802bb7398e3..274fa38a12b25fdd88ef996cb2d406c020cb4a23 100644 (file)
@@ -1,3 +1,5 @@
+//go:build linux && !android
+
 /* SPDX-License-Identifier: MIT
  *
  * Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
@@ -111,3 +113,5 @@ func setSrcControl(control *[]byte, ep *StdNetEndpoint) {
 }
 
 var srcControlSize = unix.CmsgSpace(unix.SizeofInet6Pktinfo)
+
+const StdNetSupportsStickySockets = true
index 3213e772ba2de7338dd697334fc34224d2fadca8..0219ac300811862709db5c8873c8a5f9c137ca7c 100644 (file)
@@ -1,4 +1,4 @@
-//go:build linux
+//go:build linux && !android
 
 /* SPDX-License-Identifier: MIT
  *
index 3ce07694dde6b53a32ba86cf3c5658db47e7796e..f9230f8c3c363c2d556b37cc65aa58f83bc08846 100644 (file)
@@ -25,6 +25,9 @@ import (
 )
 
 func (device *Device) startRouteListener(bind conn.Bind) (*rwcancel.RWCancel, error) {
+       if !conn.StdNetSupportsStickySockets {
+               return nil, nil
+       }
        if _, ok := bind.(*conn.StdNetBind); !ok {
                return nil, nil
        }