net/netfilter/nf_flow_table_bpf.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_flow_table_bpf.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_flow_table_bpf.c- Extension
.c- Size
- 3060 bytes
- Lines
- 122
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/init.hlinux/module.hnet/netfilter/nf_flow_table.hlinux/bpf.hlinux/btf.hnet/xdp.h
Detected Declarations
struct bpf_flowtable_optsfunction bpf_xdp_flow_tuple_lookupfunction bpf_xdp_flow_lookupfunction nf_flow_register_bpfexport nf_flow_register_bpf
Annotated Snippet
struct bpf_flowtable_opts {
s32 error;
};
enum {
NF_BPF_FLOWTABLE_OPTS_SZ = 4,
};
__diag_push();
__diag_ignore_all("-Wmissing-prototypes",
"Global functions as their definitions will be in nf_flow_table BTF");
__bpf_kfunc_start_defs();
static struct flow_offload_tuple_rhash *
bpf_xdp_flow_tuple_lookup(struct net_device *dev,
struct flow_offload_tuple *tuple, __be16 proto)
{
struct flow_offload_tuple_rhash *tuplehash;
struct nf_flowtable *nf_flow_table;
struct flow_offload *nf_flow;
nf_flow_table = nf_flowtable_by_dev(dev);
if (!nf_flow_table)
return ERR_PTR(-ENOENT);
tuplehash = flow_offload_lookup(nf_flow_table, tuple);
if (!tuplehash)
return ERR_PTR(-ENOENT);
nf_flow = container_of(tuplehash, struct flow_offload,
tuplehash[tuplehash->tuple.dir]);
flow_offload_refresh(nf_flow_table, nf_flow, false);
return tuplehash;
}
__bpf_kfunc struct flow_offload_tuple_rhash *
bpf_xdp_flow_lookup(struct xdp_md *ctx, struct bpf_fib_lookup *fib_tuple,
struct bpf_flowtable_opts *opts, u32 opts_len)
{
struct xdp_buff *xdp = (struct xdp_buff *)ctx;
struct flow_offload_tuple tuple = {
.iifidx = fib_tuple->ifindex,
.l3proto = fib_tuple->family,
.l4proto = fib_tuple->l4_protocol,
.src_port = fib_tuple->sport,
.dst_port = fib_tuple->dport,
};
struct flow_offload_tuple_rhash *tuplehash;
__be16 proto;
if (opts_len != NF_BPF_FLOWTABLE_OPTS_SZ) {
opts->error = -EINVAL;
return NULL;
}
switch (fib_tuple->family) {
case AF_INET:
tuple.src_v4.s_addr = fib_tuple->ipv4_src;
tuple.dst_v4.s_addr = fib_tuple->ipv4_dst;
proto = htons(ETH_P_IP);
break;
case AF_INET6:
tuple.src_v6 = *(struct in6_addr *)&fib_tuple->ipv6_src;
tuple.dst_v6 = *(struct in6_addr *)&fib_tuple->ipv6_dst;
proto = htons(ETH_P_IPV6);
break;
default:
opts->error = -EAFNOSUPPORT;
return NULL;
}
tuplehash = bpf_xdp_flow_tuple_lookup(xdp->rxq->dev, &tuple, proto);
if (IS_ERR(tuplehash)) {
opts->error = PTR_ERR(tuplehash);
return NULL;
}
return tuplehash;
}
__diag_pop()
__bpf_kfunc_end_defs();
BTF_KFUNCS_START(nf_ft_kfunc_set)
BTF_ID_FLAGS(func, bpf_xdp_flow_lookup, KF_RET_NULL)
BTF_KFUNCS_END(nf_ft_kfunc_set)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `net/netfilter/nf_flow_table.h`, `linux/bpf.h`, `linux/btf.h`, `net/xdp.h`.
- Detected declarations: `struct bpf_flowtable_opts`, `function bpf_xdp_flow_tuple_lookup`, `function bpf_xdp_flow_lookup`, `function nf_flow_register_bpf`, `export nf_flow_register_bpf`.
- 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.