diff options
author | Maciej Żenczykowski <maze@google.com> | 2023-03-27 21:32:03 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-03-27 21:32:03 +0000 |
commit | 5f7b7bb9bac5115d6522a855527e8d25606122ae (patch) | |
tree | eea250ba2072dbf1549129394ed6cbc3e2597a6f | |
parent | 343d9d3b928ed37f711d244420651d4eec5f2e1c (diff) | |
parent | 0fbebee96b73f9a51cb202c5180c0edd3fe1edc2 (diff) | |
download | tests-5f7b7bb9bac5115d6522a855527e8d25606122ae.tar.gz |
net-test: add test for SO_NETNS_COOKIE am: 8e4abd2a44 am: db223b53fe am: 35ed9b509a am: 0fbebee96b
Original change: https://android-review.googlesource.com/c/kernel/tests/+/2506318
Change-Id: I5ad374ae5afc615c218fff5696a511025d4227e3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rwxr-xr-x | net/test/bpf.py | 10 | ||||
-rwxr-xr-x | net/test/bpf_test.py | 38 |
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) |