net/netfilter/nft_meta.c
Source file repositories/reference/linux-study-clean/net/netfilter/nft_meta.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nft_meta.c- Extension
.c- Size
- 23153 bytes
- Lines
- 1023
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/netlink.hlinux/netfilter.hlinux/netfilter/nf_tables.hlinux/in.hlinux/ip.hlinux/ipv6.hlinux/random.hlinux/smp.hlinux/static_key.hnet/dst.hnet/ip.hnet/sock.hnet/tcp_states.hnet/netfilter/nf_tables.hnet/netfilter/nf_tables_core.hnet/netfilter/nf_tables_ipv4.hnet/netfilter/nf_tables_ipv6.hnet/netfilter/nft_meta.hnet/netfilter/nf_tables_offload.huapi/linux/netfilter_bridge.h
Detected Declarations
struct nft_secmarkfunction Copyrightfunction nft_meta_hourfunction nft_meta_get_eval_timefunction nft_meta_get_eval_pkttype_lofunction nft_meta_get_eval_skugidfunction nft_meta_get_eval_cgroupfunction nft_meta_get_eval_kindfunction nft_meta_store_ifindexfunction nft_meta_store_ifnamefunction nft_meta_store_iftypefunction nft_meta_store_ifgroupfunction nft_meta_get_eval_ifnamefunction nft_meta_get_eval_rtclassidfunction nft_meta_get_eval_sdiffunction nft_meta_get_eval_sdifnamefunction nft_meta_pktinfo_may_updatefunction nft_meta_get_evalfunction nft_meta_set_evalfunction nft_meta_get_initfunction nft_meta_get_validate_sdiffunction nft_meta_get_validate_xfrmfunction nft_meta_get_validatefunction nft_meta_set_validatefunction nft_meta_set_initfunction nft_meta_get_dumpfunction nft_meta_set_dumpfunction nft_meta_set_destroyfunction nft_meta_get_offloadfunction nft_meta_select_opsfunction nft_meta_inner_initfunction nft_meta_inner_evalfunction nft_secmark_compute_secidfunction nft_secmark_obj_evalfunction nft_secmark_obj_initfunction nft_secmark_obj_dumpfunction nft_secmark_obj_destroyexport nft_meta_get_evalexport nft_meta_set_evalexport nft_meta_policyexport nft_meta_get_initexport nft_meta_set_validateexport nft_meta_set_initexport nft_meta_get_dumpexport nft_meta_set_dumpexport nft_meta_set_destroyexport nft_meta_inner_eval
Annotated Snippet
struct nft_secmark {
u32 secid;
char *ctx;
};
static const struct nla_policy nft_secmark_policy[NFTA_SECMARK_MAX + 1] = {
[NFTA_SECMARK_CTX] = { .type = NLA_STRING, .len = NFT_SECMARK_CTX_MAXLEN },
};
static int nft_secmark_compute_secid(struct nft_secmark *priv)
{
u32 tmp_secid = 0;
int err;
err = security_secctx_to_secid(priv->ctx, strlen(priv->ctx), &tmp_secid);
if (err)
return err;
if (!tmp_secid)
return -ENOENT;
err = security_secmark_relabel_packet(tmp_secid);
if (err)
return err;
priv->secid = tmp_secid;
return 0;
}
static void nft_secmark_obj_eval(struct nft_object *obj, struct nft_regs *regs,
const struct nft_pktinfo *pkt)
{
const struct nft_secmark *priv = nft_obj_data(obj);
struct sk_buff *skb = pkt->skb;
skb->secmark = priv->secid;
}
static int nft_secmark_obj_init(const struct nft_ctx *ctx,
const struct nlattr * const tb[],
struct nft_object *obj)
{
struct nft_secmark *priv = nft_obj_data(obj);
int err;
if (tb[NFTA_SECMARK_CTX] == NULL)
return -EINVAL;
priv->ctx = nla_strdup(tb[NFTA_SECMARK_CTX], GFP_KERNEL_ACCOUNT);
if (!priv->ctx)
return -ENOMEM;
err = nft_secmark_compute_secid(priv);
if (err) {
kfree(priv->ctx);
return err;
}
security_secmark_refcount_inc();
return 0;
}
static int nft_secmark_obj_dump(struct sk_buff *skb, struct nft_object *obj,
bool reset)
{
struct nft_secmark *priv = nft_obj_data(obj);
int err;
if (nla_put_string(skb, NFTA_SECMARK_CTX, priv->ctx))
return -1;
if (reset) {
err = nft_secmark_compute_secid(priv);
if (err)
return err;
}
return 0;
}
static void nft_secmark_obj_destroy(const struct nft_ctx *ctx, struct nft_object *obj)
{
struct nft_secmark *priv = nft_obj_data(obj);
security_secmark_refcount_dec();
kfree(priv->ctx);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/netlink.h`, `linux/netfilter.h`, `linux/netfilter/nf_tables.h`, `linux/in.h`, `linux/ip.h`, `linux/ipv6.h`, `linux/random.h`.
- Detected declarations: `struct nft_secmark`, `function Copyright`, `function nft_meta_hour`, `function nft_meta_get_eval_time`, `function nft_meta_get_eval_pkttype_lo`, `function nft_meta_get_eval_skugid`, `function nft_meta_get_eval_cgroup`, `function nft_meta_get_eval_kind`, `function nft_meta_store_ifindex`, `function nft_meta_store_ifname`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.