From 088fe1983b83b6d358bb59d159c20dfaf5dd8622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Wed, 20 Jan 2021 13:34:17 -0800 Subject: [PATCH] add placeholder ipv4 ebpf tethering offload programs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Additionally better document tether stats/limit keys/value. Test: atest, TreeHugger, the programs load Signed-off-by: Maciej Żenczykowski Change-Id: I1e1832fc4f5a6704e00ea99ca377988c52a82eb1 --- Tethering/bpf_progs/offload.c | 53 +++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/Tethering/bpf_progs/offload.c b/Tethering/bpf_progs/offload.c index 5fdaa49130..9d2aec45f4 100644 --- a/Tethering/bpf_progs/offload.c +++ b/Tethering/bpf_progs/offload.c @@ -24,18 +24,23 @@ #include "bpf_net_helpers.h" #include "netdbpf/bpf_shared.h" -DEFINE_BPF_MAP_GRW(tether_downstream6_map, HASH, TetherDownstream6Key, TetherDownstream6Value, 64, - AID_NETWORK_STACK) - -DEFINE_BPF_MAP_GRW(tether_upstream6_map, HASH, TetherUpstream6Key, TetherUpstream6Value, 64, - AID_NETWORK_STACK) - // Tethering stats, indexed by upstream interface. -DEFINE_BPF_MAP_GRW(tether_stats_map, HASH, uint32_t, TetherStatsValue, 16, AID_NETWORK_STACK) +DEFINE_BPF_MAP_GRW(tether_stats_map, HASH, TetherStatsKey, TetherStatsValue, 16, AID_NETWORK_STACK) // Tethering data limit, indexed by upstream interface. // (tethering allowed when stats[iif].rxBytes + stats[iif].txBytes < limit[iif]) -DEFINE_BPF_MAP_GRW(tether_limit_map, HASH, uint32_t, uint64_t, 16, AID_NETWORK_STACK) +DEFINE_BPF_MAP_GRW(tether_limit_map, HASH, TetherLimitKey, TetherLimitValue, 16, AID_NETWORK_STACK) + +// ----- IPv6 Support ----- + +DEFINE_BPF_MAP_GRW(tether_downstream6_map, HASH, TetherDownstream6Key, TetherDownstream6Value, 64, + AID_NETWORK_STACK) + +DEFINE_BPF_MAP_GRW(tether_downstream64_map, HASH, TetherDownstream64Key, TetherDownstream64Value, + 64, AID_NETWORK_STACK) + +DEFINE_BPF_MAP_GRW(tether_upstream6_map, HASH, TetherUpstream6Key, TetherUpstream6Value, 64, + AID_NETWORK_STACK) static inline __always_inline int do_forward(struct __sk_buff* skb, const bool is_ethernet, const bool downstream) { @@ -256,5 +261,37 @@ DEFINE_BPF_PROG_KVER_RANGE("schedcls/tether_upstream6_rawip$stub", AID_ROOT, AID return TC_ACT_OK; } +// ----- IPv4 Support ----- + +DEFINE_BPF_MAP_GRW(tether_downstream4_map, HASH, TetherDownstream4Key, TetherDownstream4Value, 64, + AID_NETWORK_STACK) + +DEFINE_BPF_MAP_GRW(tether_upstream4_map, HASH, TetherUpstream4Key, TetherUpstream4Value, 64, + AID_NETWORK_STACK) + +DEFINE_BPF_PROG("schedcls/tether_downstream4_ether", AID_ROOT, AID_NETWORK_STACK, + sched_cls_tether_downstream4_ether) +(struct __sk_buff* skb) { + return TC_ACT_OK; +} + +DEFINE_BPF_PROG("schedcls/tether_downstream4_rawip", AID_ROOT, AID_NETWORK_STACK, + sched_cls_tether_downstream4_rawip) +(struct __sk_buff* skb) { + return TC_ACT_OK; +} + +DEFINE_BPF_PROG("schedcls/tether_upstream4_ether", AID_ROOT, AID_NETWORK_STACK, + sched_cls_tether_upstream4_ether) +(struct __sk_buff* skb) { + return TC_ACT_OK; +} + +DEFINE_BPF_PROG("schedcls/tether_upstream4_rawip", AID_ROOT, AID_NETWORK_STACK, + sched_cls_tether_upstream4_rawip) +(struct __sk_buff* skb) { + return TC_ACT_OK; +} + LICENSE("Apache 2.0"); CRITICAL("netd");