forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
netfilter: nf_tables: add hardware offload support
This patch adds hardware offload support for nftables through the existing netdev_ops->ndo_setup_tc() interface, the TC_SETUP_CLSFLOWER classifier and the flow rule API. This hardware offload support is available for the NFPROTO_NETDEV family and the ingress hook. Each nftables expression has a new ->offload interface, that is used to populate the flow rule object that is attached to the transaction object. There is a new per-table NFT_TABLE_F_HW flag, that is set on to offload an entire table, including all of its chains. This patch supports for basic metadata (layer 3 and 4 protocol numbers), 5-tuple payload matching and the accept/drop actions; this also includes basechain hardware offload only. Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: David S. Miller <[email protected]>
- Loading branch information
Showing
10 changed files
with
691 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef _NET_NF_TABLES_OFFLOAD_H | ||
#define _NET_NF_TABLES_OFFLOAD_H | ||
|
||
#include <net/flow_offload.h> | ||
#include <net/netfilter/nf_tables.h> | ||
|
||
struct nft_offload_reg { | ||
u32 key; | ||
u32 len; | ||
u32 base_offset; | ||
u32 offset; | ||
struct nft_data mask; | ||
}; | ||
|
||
enum nft_offload_dep_type { | ||
NFT_OFFLOAD_DEP_UNSPEC = 0, | ||
NFT_OFFLOAD_DEP_NETWORK, | ||
NFT_OFFLOAD_DEP_TRANSPORT, | ||
}; | ||
|
||
struct nft_offload_ctx { | ||
struct { | ||
enum nft_offload_dep_type type; | ||
__be16 l3num; | ||
u8 protonum; | ||
} dep; | ||
unsigned int num_actions; | ||
struct nft_offload_reg regs[NFT_REG32_15 + 1]; | ||
}; | ||
|
||
void nft_offload_set_dependency(struct nft_offload_ctx *ctx, | ||
enum nft_offload_dep_type type); | ||
void nft_offload_update_dependency(struct nft_offload_ctx *ctx, | ||
const void *data, u32 len); | ||
|
||
struct nft_flow_key { | ||
struct flow_dissector_key_basic basic; | ||
union { | ||
struct flow_dissector_key_ipv4_addrs ipv4; | ||
struct flow_dissector_key_ipv6_addrs ipv6; | ||
}; | ||
struct flow_dissector_key_ports tp; | ||
struct flow_dissector_key_ip ip; | ||
struct flow_dissector_key_vlan vlan; | ||
struct flow_dissector_key_eth_addrs eth_addrs; | ||
} __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */ | ||
|
||
struct nft_flow_match { | ||
struct flow_dissector dissector; | ||
struct nft_flow_key key; | ||
struct nft_flow_key mask; | ||
}; | ||
|
||
struct nft_flow_rule { | ||
__be16 proto; | ||
struct nft_flow_match match; | ||
struct flow_rule *rule; | ||
}; | ||
|
||
#define NFT_OFFLOAD_F_ACTION (1 << 0) | ||
|
||
struct nft_rule; | ||
struct nft_flow_rule *nft_flow_rule_create(const struct nft_rule *rule); | ||
void nft_flow_rule_destroy(struct nft_flow_rule *flow); | ||
int nft_flow_rule_offload_commit(struct net *net); | ||
|
||
#define NFT_OFFLOAD_MATCH(__key, __base, __field, __len, __reg) \ | ||
(__reg)->base_offset = \ | ||
offsetof(struct nft_flow_key, __base); \ | ||
(__reg)->offset = \ | ||
offsetof(struct nft_flow_key, __base.__field); \ | ||
(__reg)->len = __len; \ | ||
(__reg)->key = __key; \ | ||
memset(&(__reg)->mask, 0xff, (__reg)->len); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.