From 032e33f5776a569168a0bd02b92f2d34fb0345f4 Mon Sep 17 00:00:00 2001
From: albexk <albexk@proton.me>
Date: Sat, 10 Feb 2024 17:14:51 +0300
Subject: [PATCH] Fix Android UDP GRO check

---
 conn/controlfns_linux.go | 8 --------
 conn/features_linux.go   | 6 ++++--
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/conn/controlfns_linux.go b/conn/controlfns_linux.go
index f6ab1d2..a2396fe 100644
--- a/conn/controlfns_linux.go
+++ b/conn/controlfns_linux.go
@@ -57,13 +57,5 @@ func init() {
 			}
 			return err
 		},
-
-		// Attempt to enable UDP_GRO
-		func(network, address string, c syscall.RawConn) error {
-			c.Control(func(fd uintptr) {
-				_ = unix.SetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_GRO, 1)
-			})
-			return nil
-		},
 	)
 }
diff --git a/conn/features_linux.go b/conn/features_linux.go
index 8959d93..a6de8c1 100644
--- a/conn/features_linux.go
+++ b/conn/features_linux.go
@@ -19,8 +19,10 @@ func supportsUDPOffload(conn *net.UDPConn) (txOffload, rxOffload bool) {
 	err = rc.Control(func(fd uintptr) {
 		_, errSyscall := unix.GetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_SEGMENT)
 		txOffload = errSyscall == nil
-		opt, errSyscall := unix.GetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_GRO)
-		rxOffload = errSyscall == nil && opt == 1
+		// getsockopt(IPPROTO_UDP, UDP_GRO) is not supported in android
+		// use setsockopt workaround
+		errSyscall = unix.SetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_GRO, 1)
+		rxOffload = errSyscall == nil
 	})
 	if err != nil {
 		return false, false