Commit Graph

23 Commits

Author SHA1 Message Date
Treehugger Robot
e182ece901 Merge "refactor common logic into abortOnKeyOrValueSizeMismatch" 2022-06-23 19:53:41 +00:00
Maciej Żenczykowski
96ffe3733c refactor common logic into abortOnKeyOrValueSizeMismatch
Per request on:
  https://googleplex-android-review.googlesource.com/c/platform/frameworks/libs/net/+/18992756

While we're at it let's temporarily remove the check in .reset(fd)
  if (bpfGetFdMapFlags(mMapFd) != 0) abort(); // TODO: fix for BpfMapRO

We'll add it back when the code is in better shape,
and read-only vs read-write state of the map is something
we actually *know*.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id8d65bdc529872685b42656e638f22048fafb7f6
2022-06-23 13:20:35 +00:00
Maciej Żenczykowski
1a542aa48d bpf_helpers - BPFLOADER_T_VERSION is v0.19
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1298757926acfe299d4646e4e3f1ead3a0dfa806
2022-06-23 13:15:14 +00:00
Maciej Żenczykowski
53a144ea2e actually enable the use of new fields added in previous commit
(split in two to facilitate manual testing)

Bug: 218408035
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifc00ed168231615819b88b232155e1fe6f9a8c71
2022-06-18 20:14:48 -07:00
Maciej Żenczykowski
d4e612b1e7 support per-map/prog selinux context and cross .o map sharing
Tested by making the map struct conditional on #define V18,
and only #defining that in the top line of netd.c,
this results in:

$ objdump -s -j size_of_bpf_map_def out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/net_shared/clatd.o
out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/net_shared/clatd.o:     file format elf64-little
Contents of section size_of_bpf_map_def:
 0000 30000000 00000000                    0.......

$ objdump -s -j size_of_bpf_prog_def out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/net_shared/clatd.o
out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/net_shared/clatd.o:     file format elf64-little
Contents of section size_of_bpf_prog_def:
 0000 1c000000 00000000                    ........

$ objdump -s -j size_of_bpf_map_def out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/netd_shared/netd.o
out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/netd_shared/netd.o:     file format elf64-little
Contents of section size_of_bpf_map_def:
 0000 74000000 00000000                    t.......

$ objdump -s -j size_of_bpf_prog_def out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/netd_shared/netd.o
out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/netd_shared/netd.o:     file format elf64-little
Contents of section size_of_bpf_prog_def:
 0000 5c000000 00000000                    \.......

$ echo $[0x00000030] $[0x00000074]
48 116

$ echo $[0x0000001c] $[0x0000005c]
28 92

and it still successfully boots.
So the struct extension infrastructure works as desired.

Bug: 218408035
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8b55769e69dbf9580e844f2a50d48651fd9a0cff
2022-06-18 14:03:50 -07:00
Maciej Żenczykowski
2efccc5a0e BpfMap.h - hide dangerous stuff behind #ifdef BPF_MAP_MAKE_VISIBLE_FOR_TESTING
while we're at it:
  - replace 'unique_fd != -1' with unique_fd.ok() which is
    a test for fd.get() >= 0 and is thus effectively equivalent
  - make use of the fact that unique_fd.reset()
    takes care to save errno.

(see impl. in //system/libbase/include/android-base/unique_fd.h )

Bug: 236285127
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6fb7bf28a2265ad84baa3c552b39c620cb3875fe
2022-06-16 19:25:30 +00:00
Maciej Żenczykowski
cf4b58f98f BpfMap - add BpfMapRO.init() support
Really we need to fix the inheritance to make
BpfMapRO the parent class of BpfMap:
but that's a far more difficult thing to do,
so in the short term we punt like this.

This makes BpfMapRO a little bit more usable,
and allows a slow transition across the codebase...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1c5112db70e9e523c113cba536fbe19422b4d3f3
2022-06-13 19:37:03 -07:00
Maciej Żenczykowski
4b1b4090de TEST_BPF_MAP -> BPF_MAP_MAKE_VISIBLE_FOR_TESTING
Per request of Lorenzo on:
  https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/libs/net/+/18694820
  https://googleplex-android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/18695355

Although he'd suggested 'BPF_MAP_TEST_ONLY',
but I think this is even clearer.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie1185a61e80abe94e19903f6aa66bb1ad29ce2f4
2022-06-13 19:37:03 -07:00
Maciej Żenczykowski
5c5fae7a8b BpfMap key/value access size verification
(beginning there of)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie7cf8cd51b4e272fc76a281df6231ed27955ed3f
2022-06-03 21:23:39 +00:00
Maciej Żenczykowski
1a31e3e68e BpfMap: simplify .init() mMapFd assignment
this way is more obviously not calling dup_with_cloexec

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4e1ce3b0a42ccea638332ae451e291e025d57895
2022-06-01 15:17:17 -07:00
Maciej Żenczykowski
ec3e848a13 Merge "BpfMap: introduce resetMap(type, entries, flags)" 2022-06-01 09:00:46 +00:00
Maciej Żenczykowski
1db4a793b1 BpfMap: introduce resetMap(type, entries, flags)
to replace less safe uses of BpfMap.reset(create(type, keysize, valuesize, entries, flags))

Meant to be used in tests only.

Bug:
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I869f1f935bcf5d00702c42bc46d6094ea552addc
2022-05-31 07:30:24 -07:00
Maciej Żenczykowski
9a276e68f8 Fix parsing of kernel version 5.18-rc1
Test: TreeHugger
Bug: 234125620
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I624927cacd2722f4fc61ef419de74254cecdd77b
2022-05-27 19:43:47 +00:00
Maciej Żenczykowski
70cd8e7de8 synchronizeKernelRCU - update comment
Test: N/A, comment only
Signed-of-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I839a457fdb8f5b95f60cb9cd41983fbcf3792768
2022-05-27 15:06:41 +00:00
Maciej Żenczykowski
0b3a990e72 Merge "define necessary bpf helper functions" 2022-05-26 10:15:19 +00:00
eric.yan
fa1baa1b4c define necessary bpf helper functions
add bpf helper functions: bpf_get_stackid; bpf_get_current_comm

Signed-off-by: eric.yan <eric.yan@oppo.com>
Change-Id: If0daccfe8504fc107ed8d07bef92ed40b101dbc5
2022-05-26 09:29:26 +08:00
Maciej Żenczykowski
eeb588721e cache kernelVersion(), make isAtLeastKernelVersion() cheaper
not perfect due to this being in a header file, so multiple copies
potentially exist, but it's really simple, and works nearly as well.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id90c6933d57bc12f4dd640c8918fd0885c7474cf
2022-05-25 12:41:25 -07:00
Maciej Żenczykowski
6f49c95686 bpf_helpers.h - add #define's for S/T bpfloader versions
(by request from Lorenzo)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I802d2aae8b103375d7cbe0ed5c35f0abf6c04ac9
2022-05-24 16:07:27 -07:00
Ken Chen
0a31b342a1 BpfUtils.h - switch to GTEST_SKIP in all 4 SKIP macros
patch the missing commit I3acb47a432378f257418f81b26516e18d6ff3780.

Test: TreeHugger, atest libbpf_android_test netd_unit_test
netd_integration_test

Change-Id: I6b7114584759c0689e0d6b852387b93a799f663f
2022-03-02 03:19:49 +00:00
Steven Moreland
b0df1895d5 bpf_headers for vendor.
For waitForProgsLoaded.

Bug: 162057235
Test: build, load bpf program from vendor
Change-Id: Ib670aada0a98249fed21beb72879326286b2f4c2
2022-02-08 22:30:07 +00:00
Connor O'Brien
56875455c2 Add BPF_ANNOTATE_KV_PAIR to BPF map definition macros
BPF_ANNOTATE_KV_PAIR is used by libbpf to associate each map with its
BTF information. This is ignored for programs compiled without BTF
information.

Bug: 203823368
Test: build & boot; confirm all bpf progs load successfully
Test: compile time_in_state.o with -g; confirm BTF is loaded
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: I45f294945d48106d39d1d105ac4f49311459a19d
2022-01-20 21:22:24 -08:00
Ken Chen
45c7b15553 [NETD-BPF#23] Move a few headers to frameworks/libs/net
BPF headers used by both platform and mainline modules should be in
frameworks/libs/net.

Bug: 202086915
Test: build and boot
Test: cd packages/modules/Connectivity/netd; atest
Change-Id: Ie6f257b022cdea6bab3389a9fa41791f893e54c3
2021-12-23 09:57:29 +08:00
Ken Chen
0f1ee4ca81 Rename bpf_map_utils to bpf_headers
Use a generic name so that it can contain more bpf related headers.

Bug: 202086915
Test: build
Change-Id: I5a76948db394d8d7bb6eaedb570a2ca5bc99a289
2021-12-21 16:16:20 +08:00