#ifndef __LINUX_FILTER_H__
#define __LINUX_FILTER_H__
#include <linux/atomic.h>
#include <linux/bpf.h>
#include <linux/refcount.h>
#include <linux/compat.h>
#include <linux/skbuff.h>
#include <linux/linkage.h>
#include <linux/printk.h>
#include <linux/workqueue.h>
#include <linux/sched.h>
#include <linux/sched/clock.h>
#include <linux/capability.h>
#include <linux/set_memory.h>
#include <linux/kallsyms.h>
#include <linux/if_vlan.h>
#include <linux/vmalloc.h>
#include <linux/sockptr.h>
#include <crypto/sha1.h>
#include <linux/u64_stats_sync.h>
#include <net/sch_generic.h>
#include <asm/byteorder.h>
#include <uapi/linux/filter.h>
struct sk_buff;
struct sock;
struct seccomp_data;
struct bpf_prog_aux;
struct xdp_rxq_info;
struct xdp_buff;
struct sock_reuseport;
struct ctl_table;
struct ctl_table_header;
#define BPF_REG_ARG1 …
#define BPF_REG_ARG2 …
#define BPF_REG_ARG3 …
#define BPF_REG_ARG4 …
#define BPF_REG_ARG5 …
#define BPF_REG_CTX …
#define BPF_REG_FP …
#define BPF_REG_A …
#define BPF_REG_X …
#define BPF_REG_TMP …
#define BPF_REG_D …
#define BPF_REG_H …
#define BPF_REG_AX …
#define MAX_BPF_EXT_REG …
#define MAX_BPF_JIT_REG …
#define BPF_TAIL_CALL …
#define BPF_PROBE_MEM …
#define BPF_PROBE_MEMSX …
#define BPF_PROBE_MEM32 …
#define BPF_PROBE_ATOMIC …
#define BPF_CALL_ARGS …
#define BPF_NOSPEC …
#define BPF_SYM_ELF_TYPE …
#define MAX_BPF_STACK …
#define BPF_ALU64_REG_OFF(OP, DST, SRC, OFF) …
#define BPF_ALU64_REG(OP, DST, SRC) …
#define BPF_ALU32_REG_OFF(OP, DST, SRC, OFF) …
#define BPF_ALU32_REG(OP, DST, SRC) …
#define BPF_ALU64_IMM_OFF(OP, DST, IMM, OFF) …
#define BPF_ALU64_IMM(OP, DST, IMM) …
#define BPF_ALU32_IMM_OFF(OP, DST, IMM, OFF) …
#define BPF_ALU32_IMM(OP, DST, IMM) …
#define BPF_ENDIAN(TYPE, DST, LEN) …
#define BPF_BSWAP(DST, LEN) …
#define BPF_MOV64_REG(DST, SRC) …
#define BPF_MOV32_REG(DST, SRC) …
#define BPF_ADDR_PERCPU …
#define BPF_MOV64_PERCPU_REG(DST, SRC) …
static inline bool insn_is_mov_percpu_addr(const struct bpf_insn *insn)
{ … }
#define BPF_MOV64_IMM(DST, IMM) …
#define BPF_MOV32_IMM(DST, IMM) …
#define BPF_MOVSX64_REG(DST, SRC, OFF) …
#define BPF_MOVSX32_REG(DST, SRC, OFF) …
#define BPF_ZEXT_REG(DST) …
static inline bool insn_is_zext(const struct bpf_insn *insn)
{ … }
static inline bool insn_is_cast_user(const struct bpf_insn *insn)
{ … }
#define BPF_LD_IMM64(DST, IMM) …
#define BPF_LD_IMM64_RAW(DST, SRC, IMM) …
#define BPF_LD_MAP_FD(DST, MAP_FD) …
#define BPF_MOV64_RAW(TYPE, DST, SRC, IMM) …
#define BPF_MOV32_RAW(TYPE, DST, SRC, IMM) …
#define BPF_LD_ABS(SIZE, IMM) …
#define BPF_LD_IND(SIZE, SRC, IMM) …
#define BPF_LDX_MEM(SIZE, DST, SRC, OFF) …
#define BPF_LDX_MEMSX(SIZE, DST, SRC, OFF) …
#define BPF_STX_MEM(SIZE, DST, SRC, OFF) …
#define BPF_ATOMIC_OP(SIZE, OP, DST, SRC, OFF) …
#define BPF_STX_XADD(SIZE, DST, SRC, OFF) …
#define BPF_ST_MEM(SIZE, DST, OFF, IMM) …
#define BPF_JMP_REG(OP, DST, SRC, OFF) …
#define BPF_JMP_IMM(OP, DST, IMM, OFF) …
#define BPF_JMP32_REG(OP, DST, SRC, OFF) …
#define BPF_JMP32_IMM(OP, DST, IMM, OFF) …
#define BPF_JMP_A(OFF) …
#define BPF_JMP32_A(IMM) …
#define BPF_CALL_REL(TGT) …
#define BPF_CALL_IMM(x) …
#define BPF_EMIT_CALL(FUNC) …
#define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) …
#define BPF_EXIT_INSN() …
#define BPF_ST_NOSPEC() …
#define __BPF_STMT(CODE, K) …
#define __BPF_JUMP(CODE, K, JT, JF) …
#define bytes_to_bpf_size(bytes) …
#define bpf_size_to_bytes(bpf_size) …
#define BPF_SIZEOF(type) …
#define BPF_FIELD_SIZEOF(type, field) …
#define BPF_LDST_BYTES(insn) …
#define __BPF_MAP_0(m, v, ...) …
#define __BPF_MAP_1(m, v, t, a, ...) …
#define __BPF_MAP_2(m, v, t, a, ...) …
#define __BPF_MAP_3(m, v, t, a, ...) …
#define __BPF_MAP_4(m, v, t, a, ...) …
#define __BPF_MAP_5(m, v, t, a, ...) …
#define __BPF_REG_0(...) …
#define __BPF_REG_1(...) …
#define __BPF_REG_2(...) …
#define __BPF_REG_3(...) …
#define __BPF_REG_4(...) …
#define __BPF_REG_5(...) …
#define __BPF_MAP(n, ...) …
#define __BPF_REG(n, ...) …
#define __BPF_CAST(t, a) …
#define __BPF_V …
#define __BPF_N
#define __BPF_DECL_ARGS(t, a) …
#define __BPF_DECL_REGS(t, a) …
#define __BPF_PAD(n) …
#define BPF_CALL_x(x, attr, name, ...) …
#define __NOATTR
#define BPF_CALL_0(name, ...) …
#define BPF_CALL_1(name, ...) …
#define BPF_CALL_2(name, ...) …
#define BPF_CALL_3(name, ...) …
#define BPF_CALL_4(name, ...) …
#define BPF_CALL_5(name, ...) …
#define NOTRACE_BPF_CALL_1(name, ...) …
#define bpf_ctx_range(TYPE, MEMBER) …
#define bpf_ctx_range_till(TYPE, MEMBER1, MEMBER2) …
#if BITS_PER_LONG == 64
#define bpf_ctx_range_ptr(TYPE, MEMBER) …
#else
#define bpf_ctx_range_ptr …
#endif
#define bpf_target_off(TYPE, MEMBER, SIZE, PTR_SIZE) …
struct compat_sock_fprog { … };
struct sock_fprog_kern { … };
#define BPF_IMAGE_ALIGNMENT …
struct bpf_binary_header { … };
struct bpf_prog_stats { … } __aligned(…);
struct sk_filter { … };
DECLARE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
extern struct mutex nf_conn_btf_access_lock;
extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log,
const struct bpf_reg_state *reg,
int off, int size);
bpf_dispatcher_fn;
static __always_inline u32 __bpf_prog_run(const struct bpf_prog *prog,
const void *ctx,
bpf_dispatcher_fn dfunc)
{ … }
static __always_inline u32 bpf_prog_run(const struct bpf_prog *prog, const void *ctx)
{ … }
static inline u32 bpf_prog_run_pin_on_cpu(const struct bpf_prog *prog,
const void *ctx)
{ … }
#define BPF_SKB_CB_LEN …
struct bpf_skb_data_end { … };
struct bpf_nh_params { … };
#define BPF_RI_F_RF_NO_DIRECT …
#define BPF_RI_F_RI_INIT …
#define BPF_RI_F_CPU_MAP_INIT …
#define BPF_RI_F_DEV_MAP_INIT …
#define BPF_RI_F_XSK_MAP_INIT …
struct bpf_redirect_info { … };
struct bpf_net_context { … };
static inline struct bpf_net_context *bpf_net_ctx_set(struct bpf_net_context *bpf_net_ctx)
{ … }
static inline void bpf_net_ctx_clear(struct bpf_net_context *bpf_net_ctx)
{ … }
static inline struct bpf_net_context *bpf_net_ctx_get(void)
{ … }
static inline struct bpf_redirect_info *bpf_net_ctx_get_ri(void)
{ … }
static inline struct list_head *bpf_net_ctx_get_cpu_map_flush_list(void)
{ … }
static inline struct list_head *bpf_net_ctx_get_dev_flush_list(void)
{ … }
static inline struct list_head *bpf_net_ctx_get_xskmap_flush_list(void)
{ … }
static inline void bpf_net_ctx_get_all_used_flush_lists(struct list_head **lh_map,
struct list_head **lh_dev,
struct list_head **lh_xsk)
{ … }
static inline void bpf_compute_data_pointers(struct sk_buff *skb)
{ … }
static inline void bpf_compute_and_save_data_end(
struct sk_buff *skb, void **saved_data_end)
{ … }
static inline void bpf_restore_data_end(
struct sk_buff *skb, void *saved_data_end)
{ … }
static inline u8 *bpf_skb_cb(const struct sk_buff *skb)
{ … }
static inline u32 __bpf_prog_run_save_cb(const struct bpf_prog *prog,
const void *ctx)
{ … }
static inline u32 bpf_prog_run_save_cb(const struct bpf_prog *prog,
struct sk_buff *skb)
{ … }
static inline u32 bpf_prog_run_clear_cb(const struct bpf_prog *prog,
struct sk_buff *skb)
{ … }
DECLARE_BPF_DISPATCHER(…)
DECLARE_STATIC_KEY_FALSE(bpf_master_redirect_enabled_key);
u32 xdp_master_redirect(struct xdp_buff *xdp);
void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog);
static inline u32 bpf_prog_insn_size(const struct bpf_prog *prog)
{ … }
static inline u32 bpf_prog_tag_scratch_size(const struct bpf_prog *prog)
{ … }
static inline unsigned int bpf_prog_size(unsigned int proglen)
{ … }
static inline bool bpf_prog_was_classic(const struct bpf_prog *prog)
{ … }
static inline u32 bpf_ctx_off_adjust_machine(u32 size)
{ … }
static inline bool
bpf_ctx_narrow_access_ok(u32 off, u32 size, u32 size_default)
{ … }
static inline u8
bpf_ctx_narrow_access_offset(u32 off, u32 size, u32 size_default)
{ … }
#define bpf_ctx_wide_access_ok(off, size, type, field) …
#define bpf_classic_proglen(fprog) …
static inline int __must_check bpf_prog_lock_ro(struct bpf_prog *fp)
{ … }
static inline int __must_check
bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr)
{ … }
int sk_filter_trim_cap(struct sock *sk, struct sk_buff *skb, unsigned int cap);
static inline int sk_filter(struct sock *sk, struct sk_buff *skb)
{ … }
struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err);
void bpf_prog_free(struct bpf_prog *fp);
bool bpf_opcode_in_insntable(u8 code);
void bpf_prog_fill_jited_linfo(struct bpf_prog *prog,
const u32 *insn_to_jit_off);
int bpf_prog_alloc_jited_linfo(struct bpf_prog *prog);
void bpf_prog_jit_attempt_done(struct bpf_prog *prog);
struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags);
struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flags);
struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
gfp_t gfp_extra_flags);
void __bpf_prog_free(struct bpf_prog *fp);
static inline void bpf_prog_unlock_free(struct bpf_prog *fp)
{ … }
bpf_aux_classic_check_t;
int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);
int bpf_prog_create_from_user(struct bpf_prog **pfp, struct sock_fprog *fprog,
bpf_aux_classic_check_t trans, bool save_orig);
void bpf_prog_destroy(struct bpf_prog *fp);
int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
int sk_attach_bpf(u32 ufd, struct sock *sk);
int sk_reuseport_attach_filter(struct sock_fprog *fprog, struct sock *sk);
int sk_reuseport_attach_bpf(u32 ufd, struct sock *sk);
void sk_reuseport_prog_free(struct bpf_prog *prog);
int sk_detach_filter(struct sock *sk);
int sk_get_filter(struct sock *sk, sockptr_t optval, unsigned int len);
bool sk_filter_charge(struct sock *sk, struct sk_filter *fp);
void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);
u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
#define __bpf_call_base_args …
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog);
void bpf_jit_compile(struct bpf_prog *prog);
bool bpf_jit_needs_zext(void);
bool bpf_jit_inlines_helper_call(s32 imm);
bool bpf_jit_supports_subprog_tailcalls(void);
bool bpf_jit_supports_percpu_insn(void);
bool bpf_jit_supports_kfunc_call(void);
bool bpf_jit_supports_far_kfunc_call(void);
bool bpf_jit_supports_exceptions(void);
bool bpf_jit_supports_ptr_xchg(void);
bool bpf_jit_supports_arena(void);
bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena);
u64 bpf_arch_uaddress_limit(void);
void arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bp), void *cookie);
bool bpf_helper_changes_pkt_data(void *func);
static inline bool bpf_dump_raw_ok(const struct cred *cred)
{ … }
struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
const struct bpf_insn *patch, u32 len);
int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt);
static inline bool xdp_return_frame_no_direct(void)
{ … }
static inline void xdp_set_return_frame_no_direct(void)
{ … }
static inline void xdp_clear_return_frame_no_direct(void)
{ … }
static inline int xdp_ok_fwd_dev(const struct net_device *fwd,
unsigned int pktlen)
{ … }
int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,
struct xdp_buff *xdp, struct bpf_prog *prog);
int xdp_do_redirect(struct net_device *dev,
struct xdp_buff *xdp,
struct bpf_prog *prog);
int xdp_do_redirect_frame(struct net_device *dev,
struct xdp_buff *xdp,
struct xdp_frame *xdpf,
struct bpf_prog *prog);
void xdp_do_flush(void);
void bpf_warn_invalid_xdp_action(struct net_device *dev, struct bpf_prog *prog, u32 act);
#ifdef CONFIG_INET
struct sock *bpf_run_sk_reuseport(struct sock_reuseport *reuse, struct sock *sk,
struct bpf_prog *prog, struct sk_buff *skb,
struct sock *migrating_sk,
u32 hash);
#else
static inline struct sock *
bpf_run_sk_reuseport(struct sock_reuseport *reuse, struct sock *sk,
struct bpf_prog *prog, struct sk_buff *skb,
struct sock *migrating_sk,
u32 hash)
{
return NULL;
}
#endif
#ifdef CONFIG_BPF_JIT
extern int bpf_jit_enable;
extern int bpf_jit_harden;
extern int bpf_jit_kallsyms;
extern long bpf_jit_limit;
extern long bpf_jit_limit_max;
bpf_jit_fill_hole_t;
void bpf_jit_fill_hole_with_zero(void *area, unsigned int size);
struct bpf_binary_header *
bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
unsigned int alignment,
bpf_jit_fill_hole_t bpf_fill_ill_insns);
void bpf_jit_binary_free(struct bpf_binary_header *hdr);
u64 bpf_jit_alloc_exec_limit(void);
void *bpf_jit_alloc_exec(unsigned long size);
void bpf_jit_free_exec(void *addr);
void bpf_jit_free(struct bpf_prog *fp);
struct bpf_binary_header *
bpf_jit_binary_pack_hdr(const struct bpf_prog *fp);
void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t bpf_fill_ill_insns);
void bpf_prog_pack_free(void *ptr, u32 size);
static inline bool bpf_prog_kallsyms_verify_off(const struct bpf_prog *fp)
{ … }
struct bpf_binary_header *
bpf_jit_binary_pack_alloc(unsigned int proglen, u8 **ro_image,
unsigned int alignment,
struct bpf_binary_header **rw_hdr,
u8 **rw_image,
bpf_jit_fill_hole_t bpf_fill_ill_insns);
int bpf_jit_binary_pack_finalize(struct bpf_binary_header *ro_header,
struct bpf_binary_header *rw_header);
void bpf_jit_binary_pack_free(struct bpf_binary_header *ro_header,
struct bpf_binary_header *rw_header);
int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
struct bpf_jit_poke_descriptor *poke);
int bpf_jit_get_func_addr(const struct bpf_prog *prog,
const struct bpf_insn *insn, bool extra_pass,
u64 *func_addr, bool *func_addr_fixed);
struct bpf_prog *bpf_jit_blind_constants(struct bpf_prog *fp);
void bpf_jit_prog_release_other(struct bpf_prog *fp, struct bpf_prog *fp_other);
static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
u32 pass, void *image)
{ … }
static inline bool bpf_jit_is_ebpf(void)
{ … }
static inline bool ebpf_jit_enabled(void)
{ … }
static inline bool bpf_prog_ebpf_jited(const struct bpf_prog *fp)
{ … }
static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog)
{ … }
static inline bool bpf_jit_kallsyms_enabled(void)
{ … }
int __bpf_address_lookup(unsigned long addr, unsigned long *size,
unsigned long *off, char *sym);
bool is_bpf_text_address(unsigned long addr);
int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
char *sym);
struct bpf_prog *bpf_prog_ksym_find(unsigned long addr);
static inline int
bpf_address_lookup(unsigned long addr, unsigned long *size,
unsigned long *off, char **modname, char *sym)
{ … }
void bpf_prog_kallsyms_add(struct bpf_prog *fp);
void bpf_prog_kallsyms_del(struct bpf_prog *fp);
#else
static inline bool ebpf_jit_enabled(void)
{
return false;
}
static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog)
{
return false;
}
static inline bool bpf_prog_ebpf_jited(const struct bpf_prog *fp)
{
return false;
}
static inline int
bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
struct bpf_jit_poke_descriptor *poke)
{
return -ENOTSUPP;
}
static inline void bpf_jit_free(struct bpf_prog *fp)
{
bpf_prog_unlock_free(fp);
}
static inline bool bpf_jit_kallsyms_enabled(void)
{
return false;
}
static inline int
__bpf_address_lookup(unsigned long addr, unsigned long *size,
unsigned long *off, char *sym)
{
return 0;
}
static inline bool is_bpf_text_address(unsigned long addr)
{
return false;
}
static inline int bpf_get_kallsym(unsigned int symnum, unsigned long *value,
char *type, char *sym)
{
return -ERANGE;
}
static inline struct bpf_prog *bpf_prog_ksym_find(unsigned long addr)
{
return NULL;
}
static inline int
bpf_address_lookup(unsigned long addr, unsigned long *size,
unsigned long *off, char **modname, char *sym)
{
return 0;
}
static inline void bpf_prog_kallsyms_add(struct bpf_prog *fp)
{
}
static inline void bpf_prog_kallsyms_del(struct bpf_prog *fp)
{
}
#endif
void bpf_prog_kallsyms_del_all(struct bpf_prog *fp);
#define BPF_ANC …
static inline bool bpf_needs_clear_a(const struct sock_filter *first)
{ … }
static inline u16 bpf_anc_helper(const struct sock_filter *ftest)
{ … }
void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb,
int k, unsigned int size);
static inline int bpf_tell_extensions(void)
{ … }
struct bpf_sock_addr_kern { … };
struct bpf_sock_ops_kern { … };
struct bpf_sysctl_kern { … };
#define BPF_SOCKOPT_KERN_BUF_SIZE …
struct bpf_sockopt_buf { … };
struct bpf_sockopt_kern { … };
int copy_bpf_fprog_from_user(struct sock_fprog *dst, sockptr_t src, int len);
struct bpf_sk_lookup_kern { … };
extern struct static_key_false bpf_sk_lookup_enabled;
#define BPF_PROG_SK_LOOKUP_RUN_ARRAY(array, ctx, func) …
static inline bool bpf_sk_lookup_run_v4(const struct net *net, int protocol,
const __be32 saddr, const __be16 sport,
const __be32 daddr, const u16 dport,
const int ifindex, struct sock **psk)
{ … }
#if IS_ENABLED(CONFIG_IPV6)
static inline bool bpf_sk_lookup_run_v6(const struct net *net, int protocol,
const struct in6_addr *saddr,
const __be16 sport,
const struct in6_addr *daddr,
const u16 dport,
const int ifindex, struct sock **psk)
{ … }
#endif
static __always_inline long __bpf_xdp_redirect_map(struct bpf_map *map, u64 index,
u64 flags, const u64 flag_mask,
void *lookup_elem(struct bpf_map *map, u32 key))
{ … }
#ifdef CONFIG_NET
int __bpf_skb_load_bytes(const struct sk_buff *skb, u32 offset, void *to, u32 len);
int __bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from,
u32 len, u64 flags);
int __bpf_xdp_load_bytes(struct xdp_buff *xdp, u32 offset, void *buf, u32 len);
int __bpf_xdp_store_bytes(struct xdp_buff *xdp, u32 offset, void *buf, u32 len);
void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len);
void bpf_xdp_copy_buf(struct xdp_buff *xdp, unsigned long off,
void *buf, unsigned long len, bool flush);
#else
static inline int __bpf_skb_load_bytes(const struct sk_buff *skb, u32 offset,
void *to, u32 len)
{
return -EOPNOTSUPP;
}
static inline int __bpf_skb_store_bytes(struct sk_buff *skb, u32 offset,
const void *from, u32 len, u64 flags)
{
return -EOPNOTSUPP;
}
static inline int __bpf_xdp_load_bytes(struct xdp_buff *xdp, u32 offset,
void *buf, u32 len)
{
return -EOPNOTSUPP;
}
static inline int __bpf_xdp_store_bytes(struct xdp_buff *xdp, u32 offset,
void *buf, u32 len)
{
return -EOPNOTSUPP;
}
static inline void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len)
{
return NULL;
}
static inline void bpf_xdp_copy_buf(struct xdp_buff *xdp, unsigned long off, void *buf,
unsigned long len, bool flush)
{
}
#endif
#endif