android_packages_modules_Co.../staticlibs/native
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Maciej Żenczykowski 2cd8b69005 BpfClassic - add three more macros
Example use case:
  BPF_LOAD_SKB_PROTOCOL,
  BPF2_ACCEPT_IF_EQUAL(ETH_P_ARP),
  BPF2_REJECT_IF_NOT_EQUAL(ETH_P_IP),
  BPF_LOAD_IPV4_BE16(frag_off),
  BPF2_REJECT_IF_ANY_BITS_SET(IP_MF | IP_OFFMASK),
  BPF_ACCEPT,
which is a sample program which accepts ARP plus non-fragmented IPv4.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibe6f9f7941f11bc7b767a092d3d108fa0291f360
2023-07-22 14:32:47 +00:00
..
bpf_headers BpfClassic - add three more macros 2023-07-22 14:32:47 +00:00
bpf_syscall_wrappers add createOuterMap() 2023-06-14 09:14:19 +00:00
bpfmapjni bpf_headers: rename KernelVersion.h to KernelUtils.h 2023-05-17 11:43:02 -07:00
bpfutiljni Bpf Util Lib in Common Location 2022-03-01 09:09:36 -08:00
ip_checksum minor checksum changes 2023-03-15 02:58:28 +00:00
netjniutils Use IsAtLeastS SdkLevel utility implementation 2022-06-27 12:53:49 +00:00
nettestutils Add a dumpService variant that uses libbinder_ndk. 2023-06-22 19:14:10 +09:00
tcutils bpf_headers: rename KernelVersion.h to KernelUtils.h 2023-05-17 11:43:02 -07:00
README.md Clarify that JNI libraries used for jarjar'd classes must be statically linked. 2021-12-15 02:28:17 +00:00

JNI

As a general rule, jarjar every static library dependency used in a mainline module into the modules's namespace (especially if it is also used by other modules)

Fully-qualified name of java class needs to be hard-coded into the JNI .so, because JNI_OnLoad does not take any parameters. This means that there needs to be a different .so target for each post-jarjared package, so for each module.

This is the guideline to provide JNI library shared with modules:

  • provide a common java library in frameworks/libs/net with the Java class (e.g. BpfMap.java).

  • provide a common native library in frameworks/libs/net with the JNI and provide the native register function with class_name parameter. See register_com_android_net_module_util_BpfMap function in frameworks/libs/net/common/native/bpfmapjni/com_android_net_module_util_BpfMap.cpp as an example.

When you want to use JNI library from frameworks/lib/net:

  • Each module includes the java library (e.g. net-utils-device-common-bpf) and applies its jarjar rules after build.

  • Each module creates a native library in their directory, which statically links against the common native library (e.g. libnet_utils_device_common_bpf), and calls the native registered function by hardcoding the post-jarjar class_name. Linkage MUST be static because common functions in the file (e.g., register_com_android_net_module_util_BpfMap) will appear in the library (.so) file, and different versions of the library loaded in the same process by different modules will in general have different versions. It's important that each of these libraries loads the common function from its own library. Static linkage should guarantee this because static linkage resolves symbols at build time, not runtime.