Merge "bpf: build tcpAccECN into netd.o" into main
This commit is contained in:
commit
b21ed8fb38
5 changed files with 26 additions and 71 deletions
|
|
@ -111,13 +111,6 @@ bpf {
|
|||
sub_dir: "mainline",
|
||||
}
|
||||
|
||||
bpf {
|
||||
name: "tcpAccECN.o",
|
||||
srcs: ["tcpAccECN.c"],
|
||||
include_dirs: ["packages/modules/Connectivity/bpf/progs/include"],
|
||||
sub_dir: "mainline",
|
||||
}
|
||||
|
||||
bpf {
|
||||
name: "test.o",
|
||||
srcs: ["test.c"],
|
||||
|
|
|
|||
|
|
@ -902,4 +902,10 @@ DEFINE_NETD_V_BPF_PROG_KVER(setsockopt, prog, , 5_4)
|
|||
return BPF_ALLOW;
|
||||
}
|
||||
|
||||
#undef BPFLOADER_MIN_VER
|
||||
#undef BPF_OBJ_NAME
|
||||
#undef DEFAULT_BPF_PIN_SUBDIR
|
||||
|
||||
#include "tcpAccECN.c"
|
||||
|
||||
LICENSE("Apache 2.0");
|
||||
|
|
|
|||
|
|
@ -236,8 +236,6 @@ STRUCT_SIZE(LocalNetAccessKey, 4 + 4 + 16 + 2 + 2); // 28
|
|||
// Entry in the data saver enabled map that stores whether data saver is enabled or not.
|
||||
#define DATA_SAVER_ENABLED_KEY 0
|
||||
|
||||
#undef STRUCT_SIZE
|
||||
|
||||
// DROP_IF_SET is set of rules that DROP if rule is globally enabled, and per-uid bit is set
|
||||
#define DROP_IF_SET (STANDBY_MATCH | OEM_DENY_1_MATCH | OEM_DENY_2_MATCH | OEM_DENY_3_MATCH)
|
||||
// DROP_IF_UNSET is set of rules that should DROP if globally enabled, and per-uid bit is NOT set
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2025 Samsung Electronics.
|
||||
* Copyright (C) 2025 Samsung Electronics.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -20,12 +20,8 @@
|
|||
* Includes separate handling for Ethernet and raw IP packets.
|
||||
*/
|
||||
|
||||
// The resulting .o needs to load on Android T+
|
||||
#define BPFLOADER_MIN_VER BPFLOADER_MAINLINE_T_VERSION
|
||||
#define BPF_OBJ_NAME "tcpAccECN"
|
||||
#define DEFAULT_BPF_PIN_SUBDIR "netd_shared"
|
||||
|
||||
#include <linux/bpf.h>
|
||||
#include <linux/filter.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/if_packet.h>
|
||||
|
|
@ -33,30 +29,21 @@
|
|||
#include <linux/in6.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/ipv6.h>
|
||||
#include <linux/pkt_cls.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <stdint.h>
|
||||
#include "bpf_helpers.h"
|
||||
#include <tcpAccECN.h>
|
||||
#include <linux/pkt_cls.h>
|
||||
#include <linux/filter.h>
|
||||
|
||||
// Offsets from beginning of L4 (TCP) header
|
||||
#define TCP_OFFSET(field) offsetof(struct tcphdr, field)
|
||||
// The resulting .o needs to load on Android 26Q2+
|
||||
#define BPFLOADER_MIN_VER BPFLOADER_MAINLINE_26Q2_VERSION
|
||||
#define BPF_OBJ_NAME "tcpAccECN"
|
||||
#define DEFAULT_BPF_PIN_SUBDIR "netd_shared"
|
||||
|
||||
// Offsets from beginning of L3 (IPv4) header
|
||||
#define IP4_OFFSET(field) offsetof(struct iphdr, field)
|
||||
#define IP6_OFFSET(field) offsetof(struct ipv6hdr, field)
|
||||
#define IP4_TCP_OFFSET(field) (sizeof(struct iphdr) + TCP_OFFSET(field))
|
||||
#define IP6_TCP_OFFSET(field) (sizeof(struct ipv6hdr) + TCP_OFFSET(field))
|
||||
#include "bpf_net_helpers.h"
|
||||
#include "tcpAccECN.h"
|
||||
|
||||
// Offsets from beginning of L2 (ie. Ethernet) header (which must be present)
|
||||
#define ETH_IP4_OFFSET(field) (ETH_HLEN + IP4_OFFSET(field))
|
||||
#define ETH_IP4_TCP_OFFSET(field) (ETH_HLEN + IP4_TCP_OFFSET(field))
|
||||
#define ETH_IP6_OFFSET(field) (ETH_HLEN + IP6_OFFSET(field))
|
||||
#define ETH_IP6_TCP_OFFSET(field) (ETH_HLEN + IP6_TCP_OFFSET(field))
|
||||
|
||||
#define IP4_TCP_FLAGS_OFF (sizeof(struct iphdr) + 12)
|
||||
#define IP6_TCP_FLAGS_OFF (sizeof(struct ipv6hdr) + 12)
|
||||
#define TCP_FLAGS_OFF 12
|
||||
#define IP4_TCP_FLAGS_OFF (sizeof(struct iphdr) + TCP_FLAGS_OFF)
|
||||
#define IP6_TCP_FLAGS_OFF (sizeof(struct ipv6hdr) + TCP_FLAGS_OFF)
|
||||
|
||||
#define ETH_IP4_TCP_FLAGS_OFF (ETH_HLEN + IP4_TCP_FLAGS_OFF)
|
||||
#define ETH_IP6_TCP_FLAGS_OFF (ETH_HLEN + IP6_TCP_FLAGS_OFF)
|
||||
|
|
@ -71,27 +58,10 @@ DEFINE_BPF_MAP(l4s_accecn_ce_map, LRU_HASH, uint32_t, uint32_t, L4S_ACCECN_MAP_S
|
|||
DEFINE_BPF_MAP(l4s_accecn_byte_map, LRU_HASH, uint32_t, EcnByteCounters, L4S_ACCECN_MAP_SIZE)
|
||||
DEFINE_BPF_MAP(l4s_accecn_mss_map, LRU_HASH, uint32_t, uint16_t, L4S_ACCECN_MAP_SIZE)
|
||||
|
||||
static int (*bpf_skb_store_bytes)(struct __sk_buff* skb, __u32 offset, const void* from, __u32 len,
|
||||
__u64 flags) = (void*)BPF_FUNC_skb_store_bytes;
|
||||
|
||||
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_l3_csum_replace)(struct __sk_buff* skb, __u32 offset, __u64 from, __u64 to,
|
||||
__u64 flags) = (void*)BPF_FUNC_l3_csum_replace;
|
||||
|
||||
static int (*bpf_skb_load_bytes)(struct __sk_buff *skb, int off, void *to, int len) = (void *) BPF_FUNC_skb_load_bytes;
|
||||
static int64_t (*bpf_csum_diff)(__be32 *from, __u32 from_size, __be32 *to, __u32 to_size, __wsum seed) = (void*) BPF_FUNC_csum_diff;
|
||||
static int (*bpf_sock_ops_cb_flags_set)(struct bpf_sock_ops *skops, int flags) = (void *) BPF_FUNC_sock_ops_cb_flags_set;
|
||||
static int (*bpf_reserve_hdr_opt)(struct bpf_sock_ops *skops, int space, int flags) = (void *) BPF_FUNC_reserve_hdr_opt;
|
||||
static int (*bpf_store_hdr_opt)(struct bpf_sock_ops *skops, void *from, int len, int flags) = (void *) BPF_FUNC_store_hdr_opt;
|
||||
|
||||
// Android only supports little endian architectures
|
||||
#define htons(x) (__builtin_constant_p(x) ? ___constant_swab16(x) : __builtin_bswap16(x))
|
||||
#define htonl(x) (__builtin_constant_p(x) ? ___constant_swab32(x) : __builtin_bswap32(x))
|
||||
#define ntohs(x) htons(x)
|
||||
#define ntohl(x) htonl(x)
|
||||
|
||||
static inline __attribute__((always_inline)) int
|
||||
find_accecn_options_offset(struct __sk_buff *skb, uint8_t offset) {
|
||||
int ret;
|
||||
|
|
@ -729,5 +699,3 @@ DEFINE_BPF_PROG_KVER(schedcls, egress_accecn_rawip, , AID_SYSTEM, 5_10)
|
|||
}
|
||||
return TC_ACT_PIPE;
|
||||
}
|
||||
|
||||
LICENSE("Apache 2.0");
|
||||
|
|
|
|||
|
|
@ -1,22 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
// This header file is shared by eBPF kernel programs (C) and netd (C++) and
|
||||
// some of the maps are also accessed directly from Java mainline module code.
|
||||
//
|
||||
// Hence: explicitly pad all relevant structures and assert that their size
|
||||
// is the sum of the sizes of their fields.
|
||||
#define STRUCT_SIZE(name, size) _Static_assert(sizeof(name) == (size), "Incorrect struct size.")
|
||||
|
||||
#define SS_BPF_PATH "/sys/fs/bpf/"
|
||||
|
||||
#define L4S_INGRESS_ETHER_PROG_PATH SS_BPF_PATH "prog_tcpAccECN_schedcls_ingress_l4s_accecn_eth"
|
||||
#define L4S_EGRESS_ETHER_PROG_PATH SS_BPF_PATH "prog_tcpAccECN_schedcls_egress_l4s_accecn_eth"
|
||||
#define L4S_INGRESS_RAWIP_PROG_PATH SS_BPF_PATH "prog_tcpAccECN_schedcls_ingress_l4s_accecn_rawip"
|
||||
#define L4S_EGRESS_RAWIP_PROG_PATH SS_BPF_PATH "prog_tcpAccECN_schedcls_egress_l4s_accecn_rawip"
|
||||
#define L4S_OPTIONS_SOCKOPS_PROG_PATH SS_BPF_PATH "prog_tcpAccECN_sockops_l4s_accecn_option"
|
||||
#define L4S_ACCECN_CE_MAP_PATH SS_BPF_PATH "map_tcpAccECN_l4s_accecn_ce_map"
|
||||
#define L4S_ACCECN_BYTE_MAP_PATH SS_BPF_PATH "map_tcpAccECN_l4s_accecn_byte_map"
|
||||
#define L4S_ACCECN_MSS_MAP_PATH SS_BPF_PATH "map_tcpAccECN_l4s_accecn_mss_map"
|
||||
#define L4S_INGRESS_ETHER_PROG_PATH BPF_NETD_PATH "prog_tcpAccECN_schedcls_ingress_accecn_eth"
|
||||
#define L4S_EGRESS_ETHER_PROG_PATH BPF_NETD_PATH "prog_tcpAccECN_schedcls_egress_accecn_eth"
|
||||
#define L4S_INGRESS_RAWIP_PROG_PATH BPF_NETD_PATH "prog_tcpAccECN_schedcls_ingress_accecn_rawip"
|
||||
#define L4S_EGRESS_RAWIP_PROG_PATH BPF_NETD_PATH "prog_tcpAccECN_schedcls_egress_accecn_rawip"
|
||||
#define L4S_OPTIONS_SOCKOPS_PROG_PATH BPF_NETD_PATH "prog_tcpAccECN_sockops_l4s_accecn_option"
|
||||
#define L4S_ACCECN_CE_MAP_PATH BPF_NETD_PATH "map_tcpAccECN_l4s_accecn_ce_map"
|
||||
#define L4S_ACCECN_BYTE_MAP_PATH BPF_NETD_PATH "map_tcpAccECN_l4s_accecn_byte_map"
|
||||
#define L4S_ACCECN_MSS_MAP_PATH BPF_NETD_PATH "map_tcpAccECN_l4s_accecn_mss_map"
|
||||
|
||||
typedef struct{
|
||||
uint64_t ceb;
|
||||
|
|
|
|||
Loading…
Reference in a new issue