From 023c23fb1f361a91d5541c96ac050da063e96281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Tue, 9 Mar 2021 00:57:14 +0000 Subject: bpf_net_helpers.h - add bpf_skb_pull_data() and bpf_redirect_map() helper declarations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original change: https://android-review.googlesource.com/c/platform/system/netd/+/1620932 Change-Id: I3fe3c2f30da7d2b490549c0eaa2c4adb15fdad87 Test: TreeHugger Signed-off-by: Maciej Żenczykowski Merged-In: I2e332be37ad1e048b441df491e4bff0ef1e42661 --- bpf_progs/bpf_net_helpers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bpf_progs/bpf_net_helpers.h b/bpf_progs/bpf_net_helpers.h index 179aca4c..09549a35 100644 --- a/bpf_progs/bpf_net_helpers.h +++ b/bpf_progs/bpf_net_helpers.h @@ -26,6 +26,9 @@ static uint64_t (*bpf_get_socket_cookie)(struct __sk_buff* skb) = (void*)BPF_FUNC_get_socket_cookie; static uint32_t (*bpf_get_socket_uid)(struct __sk_buff* skb) = (void*)BPF_FUNC_get_socket_uid; + +static int (*bpf_skb_pull_data)(struct __sk_buff* skb, __u32 len) = (void*)BPF_FUNC_skb_pull_data; + static int (*bpf_skb_load_bytes)(struct __sk_buff* skb, int off, void* to, int len) = (void*)BPF_FUNC_skb_load_bytes; @@ -44,6 +47,8 @@ static int (*bpf_l3_csum_replace)(struct __sk_buff* skb, __u32 offset, __u64 fro static int (*bpf_l4_csum_replace)(struct __sk_buff* skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void*)BPF_FUNC_l4_csum_replace; static int (*bpf_redirect)(__u32 ifindex, __u64 flags) = (void*)BPF_FUNC_redirect; +static int (*bpf_redirect_map)(const struct bpf_map_def* map, __u32 key, + __u64 flags) = (void*)BPF_FUNC_redirect_map; static int (*bpf_skb_change_head)(struct __sk_buff* skb, __u32 head_room, __u64 flags) = (void*)BPF_FUNC_skb_change_head; -- cgit v1.2.3 From e4b5a883015cd7dd8da5d9603498cde4c6db018d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Tue, 9 Mar 2021 11:29:20 +0000 Subject: bpf_net_helpers.h - introduce try_make_readable() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original change: https://android-review.googlesource.com/c/platform/system/netd/+/1620933 Change-Id: If845e14ea699bdc4ea46b5b5aa93513d8a3f55d1 Test: TreeHugger Signed-off-by: Maciej Żenczykowski Merged-In: Ic371816904364eda69debdb7dfb4816c4eb5e14d --- bpf_progs/bpf_net_helpers.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bpf_progs/bpf_net_helpers.h b/bpf_progs/bpf_net_helpers.h index 09549a35..d978f3a2 100644 --- a/bpf_progs/bpf_net_helpers.h +++ b/bpf_progs/bpf_net_helpers.h @@ -66,4 +66,10 @@ static inline __always_inline __unused bool is_received_skb(struct __sk_buff* sk skb->pkt_type == PACKET_MULTICAST; } +// try to make the first 'len' header bytes readable via direct packet access +static inline __always_inline void try_make_readable(struct __sk_buff* skb, int len) { + if (len > skb->len) len = skb->len; + if (skb->data_end - skb->data < len) bpf_skb_pull_data(skb, len); +} + #endif // NETDBPF_BPF_NET_HELPERS_H -- cgit v1.2.3