linux/include/net/netfilter/nf_tables_core.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef _NET_NF_TABLES_CORE_H
   3#define _NET_NF_TABLES_CORE_H
   4
   5#include <net/netfilter/nf_tables.h>
   6#include <linux/indirect_call_wrapper.h>
   7
   8extern struct nft_expr_type nft_imm_type;
   9extern struct nft_expr_type nft_cmp_type;
  10extern struct nft_expr_type nft_lookup_type;
  11extern struct nft_expr_type nft_bitwise_type;
  12extern struct nft_expr_type nft_byteorder_type;
  13extern struct nft_expr_type nft_payload_type;
  14extern struct nft_expr_type nft_dynset_type;
  15extern struct nft_expr_type nft_range_type;
  16extern struct nft_expr_type nft_meta_type;
  17extern struct nft_expr_type nft_rt_type;
  18extern struct nft_expr_type nft_exthdr_type;
  19extern struct nft_expr_type nft_last_type;
  20
  21#ifdef CONFIG_NETWORK_SECMARK
  22extern struct nft_object_type nft_secmark_obj_type;
  23#endif
  24
  25int nf_tables_core_module_init(void);
  26void nf_tables_core_module_exit(void);
  27
  28struct nft_bitwise_fast_expr {
  29        u32                     mask;
  30        u32                     xor;
  31        u8                      sreg;
  32        u8                      dreg;
  33};
  34
  35struct nft_cmp_fast_expr {
  36        u32                     data;
  37        u32                     mask;
  38        u8                      sreg;
  39        u8                      len;
  40        bool                    inv;
  41};
  42
  43struct nft_immediate_expr {
  44        struct nft_data         data;
  45        u8                      dreg;
  46        u8                      dlen;
  47};
  48
  49/* Calculate the mask for the nft_cmp_fast expression. On big endian the
  50 * mask needs to include the *upper* bytes when interpreting that data as
  51 * something smaller than the full u32, therefore a cpu_to_le32 is done.
  52 */
  53static inline u32 nft_cmp_fast_mask(unsigned int len)
  54{
  55        return cpu_to_le32(~0U >> (sizeof_field(struct nft_cmp_fast_expr,
  56                                                data) * BITS_PER_BYTE - len));
  57}
  58
  59extern const struct nft_expr_ops nft_cmp_fast_ops;
  60
  61struct nft_payload {
  62        enum nft_payload_bases  base:8;
  63        u8                      offset;
  64        u8                      len;
  65        u8                      dreg;
  66};
  67
  68struct nft_payload_set {
  69        enum nft_payload_bases  base:8;
  70        u8                      offset;
  71        u8                      len;
  72        u8                      sreg;
  73        u8                      csum_type;
  74        u8                      csum_offset;
  75        u8                      csum_flags;
  76};
  77
  78extern const struct nft_expr_ops nft_payload_fast_ops;
  79
  80extern const struct nft_expr_ops nft_bitwise_fast_ops;
  81
  82extern struct static_key_false nft_counters_enabled;
  83extern struct static_key_false nft_trace_enabled;
  84
  85extern const struct nft_set_type nft_set_rhash_type;
  86extern const struct nft_set_type nft_set_hash_type;
  87extern const struct nft_set_type nft_set_hash_fast_type;
  88extern const struct nft_set_type nft_set_rbtree_type;
  89extern const struct nft_set_type nft_set_bitmap_type;
  90extern const struct nft_set_type nft_set_pipapo_type;
  91extern const struct nft_set_type nft_set_pipapo_avx2_type;
  92
  93#ifdef CONFIG_RETPOLINE
  94bool nft_rhash_lookup(const struct net *net, const struct nft_set *set,
  95                      const u32 *key, const struct nft_set_ext **ext);
  96bool nft_rbtree_lookup(const struct net *net, const struct nft_set *set,
  97                       const u32 *key, const struct nft_set_ext **ext);
  98bool nft_bitmap_lookup(const struct net *net, const struct nft_set *set,
  99                       const u32 *key, const struct nft_set_ext **ext);
 100bool nft_hash_lookup_fast(const struct net *net,
 101                          const struct nft_set *set,
 102                          const u32 *key, const struct nft_set_ext **ext);
 103bool nft_hash_lookup(const struct net *net, const struct nft_set *set,
 104                     const u32 *key, const struct nft_set_ext **ext);
 105bool nft_set_do_lookup(const struct net *net, const struct nft_set *set,
 106                       const u32 *key, const struct nft_set_ext **ext);
 107#else
 108static inline bool
 109nft_set_do_lookup(const struct net *net, const struct nft_set *set,
 110                  const u32 *key, const struct nft_set_ext **ext)
 111{
 112        return set->ops->lookup(net, set, key, ext);
 113}
 114#endif
 115
 116/* called from nft_pipapo_avx2.c */
 117bool nft_pipapo_lookup(const struct net *net, const struct nft_set *set,
 118                       const u32 *key, const struct nft_set_ext **ext);
 119/* called from nft_set_pipapo.c */
 120bool nft_pipapo_avx2_lookup(const struct net *net, const struct nft_set *set,
 121                            const u32 *key, const struct nft_set_ext **ext);
 122
 123struct nft_expr;
 124struct nft_regs;
 125struct nft_pktinfo;
 126void nft_meta_get_eval(const struct nft_expr *expr,
 127                       struct nft_regs *regs, const struct nft_pktinfo *pkt);
 128void nft_cmp_eval(const struct nft_expr *expr,
 129                  struct nft_regs *regs, const struct nft_pktinfo *pkt);
 130void nft_lookup_eval(const struct nft_expr *expr,
 131                     struct nft_regs *regs, const struct nft_pktinfo *pkt);
 132void nft_payload_eval(const struct nft_expr *expr,
 133                      struct nft_regs *regs, const struct nft_pktinfo *pkt);
 134void nft_immediate_eval(const struct nft_expr *expr,
 135                        struct nft_regs *regs, const struct nft_pktinfo *pkt);
 136void nft_bitwise_eval(const struct nft_expr *expr,
 137                      struct nft_regs *regs, const struct nft_pktinfo *pkt);
 138void nft_range_eval(const struct nft_expr *expr,
 139                    struct nft_regs *regs, const struct nft_pktinfo *pkt);
 140void nft_byteorder_eval(const struct nft_expr *expr,
 141                        struct nft_regs *regs, const struct nft_pktinfo *pkt);
 142void nft_dynset_eval(const struct nft_expr *expr,
 143                     struct nft_regs *regs, const struct nft_pktinfo *pkt);
 144void nft_rt_get_eval(const struct nft_expr *expr,
 145                     struct nft_regs *regs, const struct nft_pktinfo *pkt);
 146#endif /* _NET_NF_TABLES_CORE_H */
 147