1 #ifndef _NET_NF_TABLES_OFFLOAD_H
2 #define _NET_NF_TABLES_OFFLOAD_H
4 #include <net/flow_offload.h>
5 #include <net/netfilter/nf_tables.h>
7 enum nft_offload_reg_flags {
8 NFT_OFFLOAD_F_NETWORK2HOST = (1 << 0),
11 struct nft_offload_reg {
21 enum nft_offload_dep_type {
22 NFT_OFFLOAD_DEP_UNSPEC = 0,
23 NFT_OFFLOAD_DEP_NETWORK,
24 NFT_OFFLOAD_DEP_TRANSPORT,
27 struct nft_offload_ctx {
29 enum nft_offload_dep_type type;
33 unsigned int num_actions;
35 struct nft_offload_reg regs[NFT_REG32_15 + 1];
38 void nft_offload_set_dependency(struct nft_offload_ctx *ctx,
39 enum nft_offload_dep_type type);
40 void nft_offload_update_dependency(struct nft_offload_ctx *ctx,
41 const void *data, u32 len);
44 struct flow_dissector_key_basic basic;
45 struct flow_dissector_key_control control;
47 struct flow_dissector_key_ipv4_addrs ipv4;
48 struct flow_dissector_key_ipv6_addrs ipv6;
50 struct flow_dissector_key_ports tp;
51 struct flow_dissector_key_ip ip;
52 struct flow_dissector_key_vlan vlan;
53 struct flow_dissector_key_vlan cvlan;
54 struct flow_dissector_key_eth_addrs eth_addrs;
55 struct flow_dissector_key_meta meta;
56 } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
58 struct nft_flow_match {
59 struct flow_dissector dissector;
60 struct nft_flow_key key;
61 struct nft_flow_key mask;
64 struct nft_flow_rule {
66 struct nft_flow_match match;
67 struct flow_rule *rule;
70 void nft_flow_rule_set_addr_type(struct nft_flow_rule *flow,
71 enum flow_dissector_key_id addr_type);
74 struct nft_flow_rule *nft_flow_rule_create(struct net *net, const struct nft_rule *rule);
75 void nft_flow_rule_destroy(struct nft_flow_rule *flow);
76 int nft_flow_rule_offload_commit(struct net *net);
78 #define NFT_OFFLOAD_MATCH_FLAGS(__key, __base, __field, __len, __reg, __flags) \
79 (__reg)->base_offset = \
80 offsetof(struct nft_flow_key, __base); \
82 offsetof(struct nft_flow_key, __base.__field); \
83 (__reg)->len = __len; \
84 (__reg)->key = __key; \
85 (__reg)->flags = __flags;
87 #define NFT_OFFLOAD_MATCH(__key, __base, __field, __len, __reg) \
88 NFT_OFFLOAD_MATCH_FLAGS(__key, __base, __field, __len, __reg, 0)
90 #define NFT_OFFLOAD_MATCH_EXACT(__key, __base, __field, __len, __reg) \
91 NFT_OFFLOAD_MATCH(__key, __base, __field, __len, __reg) \
92 memset(&(__reg)->mask, 0xff, (__reg)->len);
94 bool nft_chain_offload_support(const struct nft_base_chain *basechain);
96 int nft_offload_init(void);
97 void nft_offload_exit(void);