net/netfilter/nf_flow_table_offload.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_flow_table_offload.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_flow_table_offload.c- Extension
.c- Size
- 35332 bytes
- Lines
- 1308
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/kernel.hlinux/init.hlinux/module.hlinux/netfilter.hlinux/rhashtable.hlinux/netdevice.hlinux/tc_act/tc_csum.hnet/flow_offload.hnet/ip_tunnels.hnet/netfilter/nf_flow_table.hnet/netfilter/nf_tables.hnet/netfilter/nf_conntrack.hnet/netfilter/nf_conntrack_acct.hnet/netfilter/nf_conntrack_core.hnet/netfilter/nf_conntrack_tuple.h
Detected Declarations
struct flow_offload_workfunction offsetoffunction nf_flow_rule_vlan_matchfunction nf_flow_rule_matchfunction flow_offload_manglefunction flow_action_entry_nextfunction flow_offload_eth_srcfunction flow_offload_eth_dstfunction flow_offload_ipv4_snatfunction flow_offload_ipv4_dnatfunction flow_offload_ipv6_manglefunction flow_offload_ipv6_snatfunction flow_offload_ipv6_dnatfunction flow_offload_l4protofunction flow_offload_port_snatfunction flow_offload_port_dnatfunction flow_offload_ipv4_checksumfunction flow_offload_redirectfunction flow_offload_encap_tunnelfunction flow_offload_decap_tunnelfunction nf_flow_rule_route_commonfunction nf_flow_rule_route_ipv4function nf_flow_rule_route_ipv6function nf_flow_offload_rule_allocfunction __nf_flow_offload_destroyfunction nf_flow_offload_destroyfunction nf_flow_offload_allocfunction nf_flow_offload_initfunction nf_flow_offload_tuplefunction flow_offload_tuple_addfunction flow_offload_tuple_delfunction flow_offload_rule_addfunction flow_offload_work_addfunction flow_offload_work_delfunction flow_offload_tuple_statsfunction flow_offload_work_statsfunction flow_offload_work_handlerfunction flow_offload_queue_workfunction nf_flow_offload_work_allocfunction nf_flow_offload_addfunction nf_flow_offload_delfunction nf_flow_offload_statsfunction nf_flow_table_offload_flush_cleanupfunction nf_flow_table_offload_flushfunction nf_flow_table_block_setupfunction list_for_each_entry_safefunction nf_flow_table_block_offload_initfunction nf_flow_table_indr_cleanup
Annotated Snippet
struct flow_offload_work {
struct list_head list;
enum flow_cls_command cmd;
struct nf_flowtable *flowtable;
struct flow_offload *flow;
struct work_struct work;
};
#define NF_FLOW_DISSECTOR(__match, __type, __field) \
(__match)->dissector.offset[__type] = \
offsetof(struct nf_flow_key, __field)
static void nf_flow_rule_lwt_match(struct nf_flow_match *match,
struct ip_tunnel_info *tun_info)
{
struct nf_flow_key *mask = &match->mask;
struct nf_flow_key *key = &match->key;
unsigned long long enc_keys;
if (!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX))
return;
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_ENC_CONTROL, enc_control);
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_ENC_KEYID, enc_key_id);
key->enc_key_id.keyid = tunnel_id_to_key32(tun_info->key.tun_id);
mask->enc_key_id.keyid = 0xffffffff;
enc_keys = BIT_ULL(FLOW_DISSECTOR_KEY_ENC_KEYID) |
BIT_ULL(FLOW_DISSECTOR_KEY_ENC_CONTROL);
if (ip_tunnel_info_af(tun_info) == AF_INET) {
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS,
enc_ipv4);
key->enc_ipv4.src = tun_info->key.u.ipv4.dst;
key->enc_ipv4.dst = tun_info->key.u.ipv4.src;
if (key->enc_ipv4.src)
mask->enc_ipv4.src = 0xffffffff;
if (key->enc_ipv4.dst)
mask->enc_ipv4.dst = 0xffffffff;
enc_keys |= BIT_ULL(FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS);
key->enc_control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
} else {
memcpy(&key->enc_ipv6.src, &tun_info->key.u.ipv6.dst,
sizeof(struct in6_addr));
memcpy(&key->enc_ipv6.dst, &tun_info->key.u.ipv6.src,
sizeof(struct in6_addr));
if (memcmp(&key->enc_ipv6.src, &in6addr_any,
sizeof(struct in6_addr)))
memset(&mask->enc_ipv6.src, 0xff,
sizeof(struct in6_addr));
if (memcmp(&key->enc_ipv6.dst, &in6addr_any,
sizeof(struct in6_addr)))
memset(&mask->enc_ipv6.dst, 0xff,
sizeof(struct in6_addr));
enc_keys |= BIT_ULL(FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS);
key->enc_control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
}
match->dissector.used_keys |= enc_keys;
}
static void nf_flow_rule_vlan_match(struct flow_dissector_key_vlan *key,
struct flow_dissector_key_vlan *mask,
u16 vlan_id, __be16 proto)
{
key->vlan_id = vlan_id;
mask->vlan_id = VLAN_VID_MASK;
key->vlan_tpid = proto;
mask->vlan_tpid = 0xffff;
}
static int nf_flow_rule_match(struct nf_flow_match *match,
const struct flow_offload_tuple *tuple,
struct dst_entry *other_dst)
{
struct nf_flow_key *mask = &match->mask;
struct nf_flow_key *key = &match->key;
struct ip_tunnel_info *tun_info;
bool vlan_encap = false;
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_META, meta);
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_CONTROL, control);
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_BASIC, basic);
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_IPV4_ADDRS, ipv4);
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_IPV6_ADDRS, ipv6);
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_TCP, tcp);
NF_FLOW_DISSECTOR(match, FLOW_DISSECTOR_KEY_PORTS, tp);
if (other_dst && other_dst->lwtstate) {
tun_info = lwt_tun_info(other_dst->lwtstate);
nf_flow_rule_lwt_match(match, tun_info);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/netfilter.h`, `linux/rhashtable.h`, `linux/netdevice.h`, `linux/tc_act/tc_csum.h`, `net/flow_offload.h`.
- Detected declarations: `struct flow_offload_work`, `function offsetof`, `function nf_flow_rule_vlan_match`, `function nf_flow_rule_match`, `function flow_offload_mangle`, `function flow_action_entry_next`, `function flow_offload_eth_src`, `function flow_offload_eth_dst`, `function flow_offload_ipv4_snat`, `function flow_offload_ipv4_dnat`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
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.