From 10da6d4e61ecbd7cb3746e0a71248569f07a9f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= <maze@google.com> Date: Fri, 6 Oct 2023 14:14:00 -0700 Subject: [PATCH] move PRIVATE/SHARED/MANDATORY/OPTIONAL/{LOAD,IGNORE}_ON_* into core headers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I7053ab46e73b763f64f36baf5e7ab64b62421045 --- bpf_progs/bpf_net_helpers.h | 16 ----------- .../bpf_headers/include/bpf/bpf_helpers.h | 27 ++++++++++--------- .../bpf_headers/include/bpf/bpf_map_def.h | 18 +++++++++++++ 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/bpf_progs/bpf_net_helpers.h b/bpf_progs/bpf_net_helpers.h index bb5e330f1b..2383d95abc 100644 --- a/bpf_progs/bpf_net_helpers.h +++ b/bpf_progs/bpf_net_helpers.h @@ -87,14 +87,6 @@ static inline __always_inline void try_make_writable(struct __sk_buff* skb, int if (skb->data_end - skb->data < len) bpf_skb_pull_data(skb, len); } -// constants for passing in to 'bool shared' (for maps) -static const bool PRIVATE = false; -static const bool SHARED = true; - -// constants for passing in to 'bool optional' (for programs) -static const bool MANDATORY = false; -static const bool OPTIONAL = true; - // constants for passing in to 'bool egress' static const bool INGRESS = false; static const bool EGRESS = true; @@ -111,12 +103,4 @@ static const bool ETHER = true; static const bool NO_UPDATETIME = false; static const bool UPDATETIME = true; -// constants for passing in to ignore_on_eng / ignore_on_user / ignore_on_userdebug -static const bool LOAD_ON_ENG = false; -static const bool LOAD_ON_USER = false; -static const bool LOAD_ON_USERDEBUG = false; -static const bool IGNORE_ON_ENG = true; -static const bool IGNORE_ON_USER = true; -static const bool IGNORE_ON_USERDEBUG = true; - #define KVER_4_14 KVER(4, 14, 0) diff --git a/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h b/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h index 67ac0e46e9..9583e805a4 100644 --- a/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h +++ b/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h @@ -312,11 +312,11 @@ static void (*bpf_ringbuf_submit_unsafe)(const void* data, __u64 flags) = (void* #error "Bpf Map UID must be left at default of AID_ROOT for BpfLoader prior to v0.28" #endif -#define DEFINE_BPF_MAP_UGM(the_map, TYPE, KeyType, ValueType, num_entries, usr, grp, md) \ - DEFINE_BPF_MAP_EXT(the_map, TYPE, KeyType, ValueType, num_entries, usr, grp, md, \ - DEFAULT_BPF_MAP_SELINUX_CONTEXT, DEFAULT_BPF_MAP_PIN_SUBDIR, false, \ - BPFLOADER_MIN_VER, BPFLOADER_MAX_VER, /*ignore_on_eng*/false, \ - /*ignore_on_user*/false, /*ignore_on_userdebug*/false) +#define DEFINE_BPF_MAP_UGM(the_map, TYPE, KeyType, ValueType, num_entries, usr, grp, md) \ + DEFINE_BPF_MAP_EXT(the_map, TYPE, KeyType, ValueType, num_entries, usr, grp, md, \ + DEFAULT_BPF_MAP_SELINUX_CONTEXT, DEFAULT_BPF_MAP_PIN_SUBDIR, PRIVATE, \ + BPFLOADER_MIN_VER, BPFLOADER_MAX_VER, LOAD_ON_ENG, \ + LOAD_ON_USER, LOAD_ON_USERDEBUG) #define DEFINE_BPF_MAP(the_map, TYPE, KeyType, ValueType, num_entries) \ DEFINE_BPF_MAP_UGM(the_map, TYPE, KeyType, ValueType, num_entries, \ @@ -389,7 +389,7 @@ static long (*bpf_get_current_comm)(void* buf, uint32_t buf_size) = (void*) BPF_ DEFINE_BPF_PROG_EXT(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, max_kv, \ BPFLOADER_MIN_VER, BPFLOADER_MAX_VER, opt, \ DEFAULT_BPF_PROG_SELINUX_CONTEXT, DEFAULT_BPF_PROG_PIN_SUBDIR, \ - false, false, false) + LOAD_ON_ENG, LOAD_ON_USER, LOAD_ON_USERDEBUG) // Programs (here used in the sense of functions/sections) marked optional are allowed to fail // to load (for example due to missing kernel patches). @@ -405,21 +405,24 @@ static long (*bpf_get_current_comm)(void* buf, uint32_t buf_size) = (void*) BPF_ // programs requiring a kernel version >= min_kv && < max_kv #define DEFINE_BPF_PROG_KVER_RANGE(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, max_kv) \ DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, max_kv, \ - false) + MANDATORY) #define DEFINE_OPTIONAL_BPF_PROG_KVER_RANGE(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, \ max_kv) \ - DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, max_kv, true) + DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, max_kv, \ + OPTIONAL) // programs requiring a kernel version >= min_kv #define DEFINE_BPF_PROG_KVER(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv) \ DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, KVER_INF, \ - false) + MANDATORY) #define DEFINE_OPTIONAL_BPF_PROG_KVER(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv) \ DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, min_kv, KVER_INF, \ - true) + OPTIONAL) // programs with no kernel version requirements #define DEFINE_BPF_PROG(SECTION_NAME, prog_uid, prog_gid, the_prog) \ - DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, 0, KVER_INF, false) + DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, 0, KVER_INF, \ + MANDATORY) #define DEFINE_OPTIONAL_BPF_PROG(SECTION_NAME, prog_uid, prog_gid, the_prog) \ - DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, 0, KVER_INF, true) + DEFINE_BPF_PROG_KVER_RANGE_OPT(SECTION_NAME, prog_uid, prog_gid, the_prog, 0, KVER_INF, \ + OPTIONAL) diff --git a/staticlibs/native/bpf_headers/include/bpf/bpf_map_def.h b/staticlibs/native/bpf_headers/include/bpf/bpf_map_def.h index e7428b6d3f..7474346c7e 100644 --- a/staticlibs/native/bpf_headers/include/bpf/bpf_map_def.h +++ b/staticlibs/native/bpf_headers/include/bpf/bpf_map_def.h @@ -114,6 +114,24 @@ _Static_assert(__alignof__(unsigned long long) == 8, "__alignof__ unsigned long // BPF wants 8, but 32-bit x86 wants 4 //_Static_assert(_Alignof(unsigned long long) == 8, "_Alignof unsigned long long != 8"); + +// constants for passing in to 'bool shared' (for maps) +static const bool PRIVATE = false; +static const bool SHARED = true; + +// constants for passing in to 'bool optional' (for programs) +static const bool MANDATORY = false; +static const bool OPTIONAL = true; + +// constants for passing in to ignore_on_eng / ignore_on_user / ignore_on_userdebug +static const bool LOAD_ON_ENG = false; +static const bool LOAD_ON_USER = false; +static const bool LOAD_ON_USERDEBUG = false; +static const bool IGNORE_ON_ENG = true; +static const bool IGNORE_ON_USER = true; +static const bool IGNORE_ON_USERDEBUG = true; + + // Length of strings (incl. selinux_context and pin_subdir) // in the bpf_map_def and bpf_prog_def structs. // -- GitLab