net/netfilter/nf_tables_offload.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_tables_offload.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_tables_offload.c- Extension
.c- Size
- 17563 bytes
- Lines
- 700
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/module.hlinux/netfilter.hnet/flow_offload.hnet/netfilter/nf_tables.hnet/netfilter/nf_tables_offload.hnet/pkt_cls.h
Detected Declarations
struct nft_offload_ethertypefunction nft_flow_rule_set_addr_typefunction nft_flow_rule_transfer_vlanfunction BIT_ULLfunction nft_flow_rule_destroyfunction flow_action_for_eachfunction nft_offload_set_dependencyfunction nft_offload_update_dependencyfunction nft_flow_offload_common_initfunction nft_setup_cb_callfunction list_for_each_entryfunction nft_chain_offload_priorityfunction nft_chain_offload_supportfunction list_for_each_entryfunction nft_flow_cls_offload_setupfunction nft_flow_offload_cmdfunction nft_flow_offload_rulefunction nft_flow_rule_statsfunction nft_rule_for_each_exprfunction nft_flow_offload_bindfunction nft_flow_offload_unbindfunction list_for_each_entry_safefunction nft_block_setupfunction nft_flow_block_offload_initfunction nft_block_offload_cmdfunction nft_indr_block_cleanupfunction nft_indr_block_offload_cmdfunction nft_chain_offload_cmdfunction nft_flow_block_chainfunction list_for_each_entryfunction list_for_each_entryfunction nft_flow_offload_chainfunction nft_flow_rule_offload_abortfunction list_for_each_entry_continue_reversefunction nft_flow_rule_offload_commitfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction nft_offload_netdev_eventfunction nft_offload_initfunction nft_offload_exit
Annotated Snippet
struct nft_offload_ethertype {
__be16 value;
__be16 mask;
};
static void nft_flow_rule_transfer_vlan(struct nft_offload_ctx *ctx,
struct nft_flow_rule *flow)
{
struct nft_flow_match *match = &flow->match;
struct nft_offload_ethertype ethertype = {
.value = match->key.basic.n_proto,
.mask = match->mask.basic.n_proto,
};
if (match->dissector.used_keys & BIT_ULL(FLOW_DISSECTOR_KEY_VLAN) &&
(match->key.vlan.vlan_tpid == htons(ETH_P_8021Q) ||
match->key.vlan.vlan_tpid == htons(ETH_P_8021AD))) {
match->key.basic.n_proto = match->key.cvlan.vlan_tpid;
match->mask.basic.n_proto = match->mask.cvlan.vlan_tpid;
match->key.cvlan.vlan_tpid = match->key.vlan.vlan_tpid;
match->mask.cvlan.vlan_tpid = match->mask.vlan.vlan_tpid;
match->key.vlan.vlan_tpid = ethertype.value;
match->mask.vlan.vlan_tpid = ethertype.mask;
match->dissector.offset[FLOW_DISSECTOR_KEY_CVLAN] =
offsetof(struct nft_flow_key, cvlan);
match->dissector.used_keys |= BIT_ULL(FLOW_DISSECTOR_KEY_CVLAN);
} else if (match->dissector.used_keys &
BIT_ULL(FLOW_DISSECTOR_KEY_BASIC) &&
(match->key.basic.n_proto == htons(ETH_P_8021Q) ||
match->key.basic.n_proto == htons(ETH_P_8021AD))) {
match->key.basic.n_proto = match->key.vlan.vlan_tpid;
match->mask.basic.n_proto = match->mask.vlan.vlan_tpid;
match->key.vlan.vlan_tpid = ethertype.value;
match->mask.vlan.vlan_tpid = ethertype.mask;
match->dissector.offset[FLOW_DISSECTOR_KEY_VLAN] =
offsetof(struct nft_flow_key, vlan);
match->dissector.used_keys |= BIT_ULL(FLOW_DISSECTOR_KEY_VLAN);
}
}
struct nft_flow_rule *nft_flow_rule_create(struct net *net,
const struct nft_rule *rule)
{
struct nft_offload_ctx *ctx;
struct nft_flow_rule *flow;
int num_actions = 0, err;
struct nft_expr *expr;
expr = nft_expr_first(rule);
while (nft_expr_more(rule, expr)) {
if (expr->ops->offload_action &&
expr->ops->offload_action(expr))
num_actions++;
expr = nft_expr_next(expr);
}
if (num_actions == 0)
return ERR_PTR(-EOPNOTSUPP);
flow = nft_flow_rule_alloc(num_actions);
if (!flow)
return ERR_PTR(-ENOMEM);
expr = nft_expr_first(rule);
ctx = kzalloc_obj(struct nft_offload_ctx);
if (!ctx) {
err = -ENOMEM;
goto err_out;
}
ctx->net = net;
ctx->dep.type = NFT_OFFLOAD_DEP_UNSPEC;
while (nft_expr_more(rule, expr)) {
if (!expr->ops->offload) {
err = -EOPNOTSUPP;
goto err_out;
}
err = expr->ops->offload(ctx, flow, expr);
if (err < 0)
goto err_out;
expr = nft_expr_next(expr);
}
nft_flow_rule_transfer_vlan(ctx, flow);
flow->proto = ctx->dep.l3num;
kfree(ctx);
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/netfilter.h`, `net/flow_offload.h`, `net/netfilter/nf_tables.h`, `net/netfilter/nf_tables_offload.h`, `net/pkt_cls.h`.
- Detected declarations: `struct nft_offload_ethertype`, `function nft_flow_rule_set_addr_type`, `function nft_flow_rule_transfer_vlan`, `function BIT_ULL`, `function nft_flow_rule_destroy`, `function flow_action_for_each`, `function nft_offload_set_dependency`, `function nft_offload_update_dependency`, `function nft_flow_offload_common_init`, `function nft_setup_cb_call`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.