diff options
author | Maciej Żenczykowski <maze@google.com> | 2021-02-25 18:19:38 -0800 |
---|---|---|
committer | Maciej Żenczykowski <maze@google.com> | 2021-02-25 18:59:13 -0800 |
commit | 687786c303db5b0090abb91dbc12f1d25bff56f4 (patch) | |
tree | 769e328c42a3ea186eca6c122e654c58a19a78a3 | |
parent | 6ec4a0cdb1d4158660e588cc450df87061660071 (diff) | |
download | tests-687786c303db5b0090abb91dbc12f1d25bff56f4.tar.gz |
net-test: add test for bpf_skb_change_head() use from a TC program
Test: TreeHugger, gpylint2 bpf.py bpf_test.py
passes on ACK 4.14-P tree, fails after reverting relevant kernel patch
Bug: 181188036
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6890e51001167fbbd4e0b1e5b8290ad7ec92a9af
-rwxr-xr-x | net/test/bpf.py | 1 | ||||
-rwxr-xr-x | net/test/bpf_test.py | 44 |
2 files changed, 39 insertions, 6 deletions
diff --git a/net/test/bpf.py b/net/test/bpf.py index be4c72f..6d22423 100755 --- a/net/test/bpf.py +++ b/net/test/bpf.py @@ -163,6 +163,7 @@ BPF_FUNC_map_update_elem = 2 BPF_FUNC_map_delete_elem = 3 BPF_FUNC_ktime_get_ns = 5 BPF_FUNC_get_current_uid_gid = 15 +BPF_FUNC_skb_change_head = 43 BPF_FUNC_get_socket_cookie = 46 BPF_FUNC_get_socket_uid = 47 BPF_FUNC_ktime_get_boot_ns = 125 diff --git a/net/test/bpf_test.py b/net/test/bpf_test.py index 92bbe50..a014918 100755 --- a/net/test/bpf_test.py +++ b/net/test/bpf_test.py @@ -38,6 +38,7 @@ from bpf import BPF_FUNC_ktime_get_boot_ns from bpf import BPF_FUNC_ktime_get_ns from bpf import BPF_FUNC_map_lookup_elem from bpf import BPF_FUNC_map_update_elem +from bpf import BPF_FUNC_skb_change_head from bpf import BPF_JNE from bpf import BPF_MAP_TYPE_HASH from bpf import BPF_PROG_TYPE_CGROUP_SKB @@ -330,9 +331,40 @@ class BpfTest(net_test.NetworkTest): SocketUDPLoopBack(packet_count, 6, self.prog_fd) self.assertEqual(packet_count * 2, LookupMap(self.map_fd, key).value) + ############################################################################## + # + # Test for presence of kernel patch: + # + # ANDROID: net: bpf: Allow TC programs to call BPF_FUNC_skb_change_head + # + # 4.14: https://android-review.googlesource.com/c/kernel/common/+/1237789 + # commit fe82848d9c1c887d2a84d3738c13e644d01b6d6f + # + # 4.19: https://android-review.googlesource.com/c/kernel/common/+/1237788 + # commit 6e04d94ab72435b45c413daff63520fd724e260e + # + # 5.4: https://android-review.googlesource.com/c/kernel/common/+/1237787 + # commit d730995e7bc5b4c10cc176235b704a274e6ec16f + # + # Upstream in Linux v5.8: + # net: bpf: Allow TC programs to call BPF_FUNC_skb_change_head + # commit 6f3f65d80dac8f2bafce2213005821fccdce194c + # + @unittest.skipUnless(bpf.HAVE_EBPF_4_14, + "no bpf_skb_change_head() support for pre-4.14 kernels") + def testSkbChangeHead(self): + # long bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags) + instructions = [ + BpfMov64Imm(BPF_REG_2, 14), # u32 len + BpfMov64Imm(BPF_REG_3, 0), # u64 flags + BpfFuncCall(BPF_FUNC_skb_change_head), + ] + INS_BPF_EXIT_BLOCK + self.prog_fd = BpfProgLoad(BPF_PROG_TYPE_SCHED_CLS, instructions, + b"Apache 2.0") + # No exceptions? Good. + def testKtimeGetNsGPL(self): - instructions = [BpfFuncCall(BPF_FUNC_ktime_get_ns)] - instructions += INS_BPF_EXIT_BLOCK + instructions = [BpfFuncCall(BPF_FUNC_ktime_get_ns)] + INS_BPF_EXIT_BLOCK self.prog_fd = BpfProgLoad(BPF_PROG_TYPE_SCHED_CLS, instructions) # No exceptions? Good. @@ -354,8 +386,7 @@ class BpfTest(net_test.NetworkTest): @unittest.skipUnless(HAVE_EBPF_KTIME_GET_NS_APACHE2, "no bpf_ktime_get_ns() support for non-GPL programs") def testKtimeGetNsApache2(self): - instructions = [BpfFuncCall(BPF_FUNC_ktime_get_ns)] - instructions += INS_BPF_EXIT_BLOCK + instructions = [BpfFuncCall(BPF_FUNC_ktime_get_ns)] + INS_BPF_EXIT_BLOCK self.prog_fd = BpfProgLoad(BPF_PROG_TYPE_SCHED_CLS, instructions, b"Apache 2.0") # No exceptions? Good. @@ -378,8 +409,9 @@ class BpfTest(net_test.NetworkTest): @unittest.skipUnless(HAVE_EBPF_KTIME_GET_BOOT_NS, "no bpf_ktime_get_boot_ns() support") def testKtimeGetBootNs(self): - instructions = [BpfFuncCall(BPF_FUNC_ktime_get_boot_ns)] - instructions += INS_BPF_EXIT_BLOCK + instructions = [ + BpfFuncCall(BPF_FUNC_ktime_get_boot_ns), + ] + INS_BPF_EXIT_BLOCK self.prog_fd = BpfProgLoad(BPF_PROG_TYPE_SCHED_CLS, instructions, b"Apache 2.0") # No exceptions? Good. |