From aefa0950b545bb95cbc314ccaa566cee883a7529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Sun, 14 Feb 2021 23:15:19 -0800 Subject: [PATCH] offload ebpf - do_forward4() - introduce updatetime argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will facilitate providing a tcp-only version of the programs which due to TCP's very long timeouts will not need to use the Linux 5.8+ bpf_ktime_get_boot_ns() helpers. Test: atest, TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: I1e49b6758d3754782ac6f8820e0c15aa20e4c61d --- Tethering/bpf_progs/offload.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tethering/bpf_progs/offload.c b/Tethering/bpf_progs/offload.c index 8054ef4cc5..b5a34db4c1 100644 --- a/Tethering/bpf_progs/offload.c +++ b/Tethering/bpf_progs/offload.c @@ -341,7 +341,7 @@ DEFINE_BPF_MAP_GRW(tether_downstream4_map, HASH, Tether4Key, Tether4Value, 64, A DEFINE_BPF_MAP_GRW(tether_upstream4_map, HASH, Tether4Key, Tether4Value, 64, AID_NETWORK_STACK) static inline __always_inline int do_forward4(struct __sk_buff* skb, const bool is_ethernet, - const bool downstream) { + const bool downstream, const bool updatetime) { const int l2_header_size = is_ethernet ? sizeof(struct ethhdr) : 0; void* data = (void*)(long)skb->data; const void* data_end = (void*)(long)skb->data_end; @@ -521,7 +521,7 @@ if (!is_tcp) return TC_ACT_OK; // HACK // TTL dec -// v->last_used = bpf_ktime_get_boot_ns(); + if (updatetime) v->last_used = bpf_ktime_get_boot_ns(); __sync_fetch_and_add(downstream ? &stat_v->rxPackets : &stat_v->txPackets, packets); __sync_fetch_and_add(downstream ? &stat_v->rxBytes : &stat_v->txBytes, bytes); @@ -540,25 +540,25 @@ if (!is_tcp) return TC_ACT_OK; // HACK DEFINE_BPF_PROG_KVER("schedcls/tether_downstream4_ether$5_8", AID_ROOT, AID_NETWORK_STACK, sched_cls_tether_downstream4_ether_5_8, KVER(5, 8, 0)) (struct __sk_buff* skb) { - return do_forward4(skb, /* is_ethernet */ true, /* downstream */ true); + return do_forward4(skb, /* is_ethernet */ true, /* downstream */ true, /* updatetime */ true); } DEFINE_BPF_PROG_KVER("schedcls/tether_downstream4_rawip$5_8", AID_ROOT, AID_NETWORK_STACK, sched_cls_tether_downstream4_rawip_5_8, KVER(5, 8, 0)) (struct __sk_buff* skb) { - return do_forward4(skb, /* is_ethernet */ false, /* downstream */ true); + return do_forward4(skb, /* is_ethernet */ false, /* downstream */ true, /* updatetime */ true); } DEFINE_BPF_PROG_KVER("schedcls/tether_upstream4_ether$5_8", AID_ROOT, AID_NETWORK_STACK, sched_cls_tether_upstream4_ether_5_8, KVER(5, 8, 0)) (struct __sk_buff* skb) { - return do_forward4(skb, /* is_ethernet */ true, /* downstream */ false); + return do_forward4(skb, /* is_ethernet */ true, /* downstream */ false, /* updatetime */ true); } DEFINE_BPF_PROG_KVER("schedcls/tether_upstream4_rawip$5_8", AID_ROOT, AID_NETWORK_STACK, sched_cls_tether_upstream4_rawip_5_8, KVER(5, 8, 0)) (struct __sk_buff* skb) { - return do_forward4(skb, /* is_ethernet */ false, /* downstream */ false); + return do_forward4(skb, /* is_ethernet */ false, /* downstream */ false, /* updatetime */ true); } // Placeholder implementations for older pre-5.8 kernels