summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2023-03-27 19:46:26 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-03-27 19:46:26 +0000
commitdb223b53fe527c64c428da89bc479dead58998ea (patch)
treeeea250ba2072dbf1549129394ed6cbc3e2597a6f
parentd626dcce346246bb771e736bb5ba5da12df5a917 (diff)
parent8e4abd2a446a70c30bb4563a0f752df6f1801208 (diff)
downloadtests-db223b53fe527c64c428da89bc479dead58998ea.tar.gz
net-test: add test for SO_NETNS_COOKIE am: 8e4abd2a44
Original change: https://android-review.googlesource.com/c/kernel/tests/+/2506318 Change-Id: I2e88ed677b939dcee6c035b0a786bc4d483601b1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rwxr-xr-xnet/test/bpf.py10
-rwxr-xr-xnet/test/bpf_test.py38
2 files changed, 47 insertions, 1 deletions
diff --git a/net/test/bpf.py b/net/test/bpf.py
index 41f19eb..cef1a37 100755
--- a/net/test/bpf.py
+++ b/net/test/bpf.py
@@ -49,6 +49,16 @@ __NR_bpf = { # pylint: disable=invalid-name
"riscv64-64bit": 280,
}[os.uname()[4] + "-" + platform.architecture()[0]]
+# After ACK merge of 5.10.168 is when support for this was backported from
+# upstream Linux 5.14 and was merged into ACK android{12,13}-5.10 branches.
+# ACK android12-5.10 was >= 5.10.168 without this support only for ~4.5 hours
+# ACK android13-4.10 was >= 5.10.168 without this support only for ~25 hours
+# as such we can >= 5.10.168 instead of > 5.10.168
+HAVE_SO_NETNS_COOKIE = net_test.LINUX_VERSION >= (5, 10, 168)
+
+# Note: This is *not* correct for parisc & sparc architectures
+SO_NETNS_COOKIE = 71
+
LOG_LEVEL = 1
LOG_SIZE = 65536
diff --git a/net/test/bpf_test.py b/net/test/bpf_test.py
index 0678f1f..343ca97 100755
--- a/net/test/bpf_test.py
+++ b/net/test/bpf_test.py
@@ -79,7 +79,6 @@ from bpf import LookupMap
from bpf import UpdateMap
import csocket
import net_test
-from net_test import LINUX_VERSION
import sock_diag
libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True)
@@ -407,6 +406,43 @@ class BpfTest(net_test.NetworkTest):
b"Apache 2.0")
# No exceptions? Good.
+ ##############################################################################
+ #
+ # Test for presence of upstream 5.14 kernel patches:
+ #
+ # Android12-5.10:
+ # UPSTREAM: net: initialize net->net_cookie at netns setup
+ # https://android-review.git.corp.google.com/c/kernel/common/+/2503195
+ #
+ # UPSTREAM: net: retrieve netns cookie via getsocketopt
+ # https://android-review.git.corp.google.com/c/kernel/common/+/2503056
+ #
+ # (and potentially if you care about kernel ABI)
+ #
+ # ANDROID: fix ABI by undoing atomic64_t -> u64 type conversion
+ # https://android-review.git.corp.google.com/c/kernel/common/+/2504335
+ #
+ # Android13-5.10:
+ # UPSTREAM: net: initialize net->net_cookie at netns setup
+ # https://android-review.git.corp.google.com/c/kernel/common/+/2503795
+ #
+ # UPSTREAM: net: retrieve netns cookie via getsocketopt
+ # https://android-review.git.corp.google.com/c/kernel/common/+/2503796
+ #
+ # (and potentially if you care about kernel ABI)
+ #
+ # ANDROID: fix ABI by undoing atomic64_t -> u64 type conversion
+ # https://android-review.git.corp.google.com/c/kernel/common/+/2506895
+ #
+ @unittest.skipUnless(bpf.HAVE_SO_NETNS_COOKIE, "no SO_NETNS_COOKIE support")
+ def testGetNetNsCookie(self):
+ sk = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, 0)
+ cookie = sk.getsockopt(socket.SOL_SOCKET, bpf.SO_NETNS_COOKIE, 8) # sizeof(u64) == 8
+ sk.close()
+ self.assertEqual(len(cookie), 8)
+ cookie = int.from_bytes(cookie, "little")
+ self.assertGreaterEqual(cookie, 0)
+
def testGetSocketCookie(self):
self.map_fd = CreateMap(BPF_MAP_TYPE_HASH, KEY_SIZE, VALUE_SIZE,
TOTAL_ENTRIES)