linux/include/linux/filter.h
<<
>>
Prefs
   1/*
   2 * Linux Socket Filter Data Structures
   3 */
   4#ifndef __LINUX_FILTER_H__
   5#define __LINUX_FILTER_H__
   6
   7#include <linux/atomic.h>
   8#include <linux/compat.h>
   9#include <uapi/linux/filter.h>
  10
  11#ifdef CONFIG_COMPAT
  12/*
  13 * A struct sock_filter is architecture independent.
  14 */
  15struct compat_sock_fprog {
  16        u16             len;
  17        compat_uptr_t   filter;         /* struct sock_filter * */
  18};
  19#endif
  20
  21struct sk_buff;
  22struct sock;
  23
  24struct sk_filter
  25{
  26        atomic_t                refcnt;
  27        unsigned int            len;    /* Number of filter blocks */
  28        unsigned int            (*bpf_func)(const struct sk_buff *skb,
  29                                            const struct sock_filter *filter);
  30        struct rcu_head         rcu;
  31        struct sock_filter      insns[0];
  32};
  33
  34static inline unsigned int sk_filter_len(const struct sk_filter *fp)
  35{
  36        return fp->len * sizeof(struct sock_filter) + sizeof(*fp);
  37}
  38
  39extern int sk_filter(struct sock *sk, struct sk_buff *skb);
  40extern unsigned int sk_run_filter(const struct sk_buff *skb,
  41                                  const struct sock_filter *filter);
  42extern int sk_unattached_filter_create(struct sk_filter **pfp,
  43                                       struct sock_fprog *fprog);
  44extern void sk_unattached_filter_destroy(struct sk_filter *fp);
  45extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
  46extern int sk_detach_filter(struct sock *sk);
  47extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
  48
  49#ifdef CONFIG_BPF_JIT
  50extern void bpf_jit_compile(struct sk_filter *fp);
  51extern void bpf_jit_free(struct sk_filter *fp);
  52#define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
  53#else
  54static inline void bpf_jit_compile(struct sk_filter *fp)
  55{
  56}
  57static inline void bpf_jit_free(struct sk_filter *fp)
  58{
  59}
  60#define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
  61#endif
  62
  63enum {
  64        BPF_S_RET_K = 1,
  65        BPF_S_RET_A,
  66        BPF_S_ALU_ADD_K,
  67        BPF_S_ALU_ADD_X,
  68        BPF_S_ALU_SUB_K,
  69        BPF_S_ALU_SUB_X,
  70        BPF_S_ALU_MUL_K,
  71        BPF_S_ALU_MUL_X,
  72        BPF_S_ALU_DIV_X,
  73        BPF_S_ALU_MOD_K,
  74        BPF_S_ALU_MOD_X,
  75        BPF_S_ALU_AND_K,
  76        BPF_S_ALU_AND_X,
  77        BPF_S_ALU_OR_K,
  78        BPF_S_ALU_OR_X,
  79        BPF_S_ALU_XOR_K,
  80        BPF_S_ALU_XOR_X,
  81        BPF_S_ALU_LSH_K,
  82        BPF_S_ALU_LSH_X,
  83        BPF_S_ALU_RSH_K,
  84        BPF_S_ALU_RSH_X,
  85        BPF_S_ALU_NEG,
  86        BPF_S_LD_W_ABS,
  87        BPF_S_LD_H_ABS,
  88        BPF_S_LD_B_ABS,
  89        BPF_S_LD_W_LEN,
  90        BPF_S_LD_W_IND,
  91        BPF_S_LD_H_IND,
  92        BPF_S_LD_B_IND,
  93        BPF_S_LD_IMM,
  94        BPF_S_LDX_W_LEN,
  95        BPF_S_LDX_B_MSH,
  96        BPF_S_LDX_IMM,
  97        BPF_S_MISC_TAX,
  98        BPF_S_MISC_TXA,
  99        BPF_S_ALU_DIV_K,
 100        BPF_S_LD_MEM,
 101        BPF_S_LDX_MEM,
 102        BPF_S_ST,
 103        BPF_S_STX,
 104        BPF_S_JMP_JA,
 105        BPF_S_JMP_JEQ_K,
 106        BPF_S_JMP_JEQ_X,
 107        BPF_S_JMP_JGE_K,
 108        BPF_S_JMP_JGE_X,
 109        BPF_S_JMP_JGT_K,
 110        BPF_S_JMP_JGT_X,
 111        BPF_S_JMP_JSET_K,
 112        BPF_S_JMP_JSET_X,
 113        /* Ancillary data */
 114        BPF_S_ANC_PROTOCOL,
 115        BPF_S_ANC_PKTTYPE,
 116        BPF_S_ANC_IFINDEX,
 117        BPF_S_ANC_NLATTR,
 118        BPF_S_ANC_NLATTR_NEST,
 119        BPF_S_ANC_MARK,
 120        BPF_S_ANC_QUEUE,
 121        BPF_S_ANC_HATYPE,
 122        BPF_S_ANC_RXHASH,
 123        BPF_S_ANC_CPU,
 124        BPF_S_ANC_ALU_XOR_X,
 125        BPF_S_ANC_SECCOMP_LD_W,
 126};
 127
 128#endif /* __LINUX_FILTER_H__ */
 129
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.