From 1daafe04f107a2e2968e933314efa59c21ef03af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Sat, 17 May 2025 02:47:31 -0700 Subject: [PATCH] bpf: remove unused tethering xdp programs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can always trivially add it back if we ever manage to make XDP work, but that will likely be on at least 6.1+ as that's the minimum kernel version on Pixel 6+ now. In the mean time, we can just delete it, and very slightly speed up boot time (less things to verify). Note: code search in android for xdp_tether -file:kernel_logs/ xdp/tether -file:kernel_logs/ doesn't find any hits outside this one file. Test: TreeHugger Flag: EXEMPT dead code removal Signed-off-by: Maciej Żenczykowski Change-Id: I39c040d79b4f175cafc141e8f0c9e631e372ebd2 --- bpf/progs/offload.c | 68 +-------------------------------------------- 1 file changed, 1 insertion(+), 67 deletions(-) diff --git a/bpf/progs/offload.c b/bpf/progs/offload.c index b34fe6fd88..16fc393b5d 100644 --- a/bpf/progs/offload.c +++ b/bpf/progs/offload.c @@ -750,74 +750,8 @@ DEFINE_BPF_PROG_KVER_RANGE("schedcls/tether_upstream4_ether$stub", AID_ROOT, AID // ----- XDP Support ----- +// java populates this map, and bpf_existence_test requires it on S+ DEFINE_BPF_MAP_GRW(tether_dev_map, DEVMAP_HASH, uint32_t, uint32_t, 64, AID_NETWORK_STACK) -static inline __always_inline int do_xdp_forward6(__unused struct xdp_md *ctx, - __unused const struct rawip_bool rawip, __unused const struct stream_bool stream) { - return XDP_PASS; -} - -static inline __always_inline int do_xdp_forward4(__unused struct xdp_md *ctx, - __unused const struct rawip_bool rawip, __unused const struct stream_bool stream) { - return XDP_PASS; -} - -static inline __always_inline int do_xdp_forward_ether(struct xdp_md *ctx, - const struct stream_bool stream) { - const void* data = (void*)(long)ctx->data; - const void* data_end = (void*)(long)ctx->data_end; - const struct ethhdr* eth = data; - - // Make sure we actually have an ethernet header - if ((void*)(eth + 1) > data_end) return XDP_PASS; - - if (eth->h_proto == htons(ETH_P_IPV6)) - return do_xdp_forward6(ctx, ETHER, stream); - if (eth->h_proto == htons(ETH_P_IP)) - return do_xdp_forward4(ctx, ETHER, stream); - - // Anything else we don't know how to handle... - return XDP_PASS; -} - -static inline __always_inline int do_xdp_forward_rawip(struct xdp_md *ctx, - const struct stream_bool stream) { - const void* data = (void*)(long)ctx->data; - const void* data_end = (void*)(long)ctx->data_end; - - // The top nibble of both IPv4 and IPv6 headers is the IP version. - if (data_end - data < 1) return XDP_PASS; - const uint8_t v = (*(uint8_t*)data) >> 4; - - if (v == 6) return do_xdp_forward6(ctx, RAWIP, stream); - if (v == 4) return do_xdp_forward4(ctx, RAWIP, stream); - - // Anything else we don't know how to handle... - return XDP_PASS; -} - -#define DEFINE_XDP_PROG(str, func) \ - DEFINE_BPF_PROG_KVER(str, AID_ROOT, AID_NETWORK_STACK, func, KVER_5_10)(struct xdp_md *ctx) - -DEFINE_XDP_PROG("xdp/tether_downstream_ether", - xdp_tether_downstream_ether) { - return do_xdp_forward_ether(ctx, DOWNSTREAM); -} - -DEFINE_XDP_PROG("xdp/tether_downstream_rawip", - xdp_tether_downstream_rawip) { - return do_xdp_forward_rawip(ctx, DOWNSTREAM); -} - -DEFINE_XDP_PROG("xdp/tether_upstream_ether", - xdp_tether_upstream_ether) { - return do_xdp_forward_ether(ctx, UPSTREAM); -} - -DEFINE_XDP_PROG("xdp/tether_upstream_rawip", - xdp_tether_upstream_rawip) { - return do_xdp_forward_rawip(ctx, UPSTREAM); -} - LICENSE("Apache 2.0"); CRITICAL("Connectivity (Tethering)");