net/netfilter/nft_last.c
Source file repositories/reference/linux-study-clean/net/netfilter/nft_last.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nft_last.c- Extension
.c- Size
- 3273 bytes
- Lines
- 138
- 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.
- 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/netlink.hlinux/netfilter.hlinux/netfilter/nf_tables.hnet/netfilter/nf_tables_core.hnet/netfilter/nf_tables.h
Detected Declarations
struct nft_laststruct nft_last_privfunction nft_last_initfunction nft_last_evalfunction nft_last_dumpfunction nft_last_destroyfunction nft_last_clone
Annotated Snippet
struct nft_last {
unsigned long jiffies;
unsigned int set;
};
struct nft_last_priv {
struct nft_last *last;
};
static const struct nla_policy nft_last_policy[NFTA_LAST_MAX + 1] = {
[NFTA_LAST_SET] = { .type = NLA_U32 },
[NFTA_LAST_MSECS] = { .type = NLA_U64 },
};
static int nft_last_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
const struct nlattr * const tb[])
{
struct nft_last_priv *priv = nft_expr_priv(expr);
struct nft_last *last;
u64 last_jiffies;
int err;
last = kzalloc_obj(*last, GFP_KERNEL_ACCOUNT);
if (!last)
return -ENOMEM;
if (tb[NFTA_LAST_SET])
last->set = ntohl(nla_get_be32(tb[NFTA_LAST_SET]));
if (last->set && tb[NFTA_LAST_MSECS]) {
err = nf_msecs_to_jiffies64(tb[NFTA_LAST_MSECS], &last_jiffies);
if (err < 0)
goto err;
last->jiffies = jiffies - (unsigned long)last_jiffies;
}
priv->last = last;
return 0;
err:
kfree(last);
return err;
}
static void nft_last_eval(const struct nft_expr *expr,
struct nft_regs *regs, const struct nft_pktinfo *pkt)
{
struct nft_last_priv *priv = nft_expr_priv(expr);
struct nft_last *last = priv->last;
if (READ_ONCE(last->jiffies) != jiffies)
WRITE_ONCE(last->jiffies, jiffies);
if (READ_ONCE(last->set) == 0)
WRITE_ONCE(last->set, 1);
}
static int nft_last_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
struct nft_last_priv *priv = nft_expr_priv(expr);
struct nft_last *last = priv->last;
unsigned long last_jiffies = READ_ONCE(last->jiffies);
u32 last_set = READ_ONCE(last->set);
__be64 msecs;
if (time_before(jiffies, last_jiffies)) {
WRITE_ONCE(last->set, 0);
last_set = 0;
}
if (last_set)
msecs = nf_jiffies64_to_msecs(jiffies - last_jiffies);
else
msecs = 0;
if (nla_put_be32(skb, NFTA_LAST_SET, htonl(last_set)) ||
nla_put_be64(skb, NFTA_LAST_MSECS, msecs, NFTA_LAST_PAD))
goto nla_put_failure;
return 0;
nla_put_failure:
return -1;
}
static void nft_last_destroy(const struct nft_ctx *ctx,
const struct nft_expr *expr)
{
struct nft_last_priv *priv = nft_expr_priv(expr);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/netlink.h`, `linux/netfilter.h`, `linux/netfilter/nf_tables.h`, `net/netfilter/nf_tables_core.h`, `net/netfilter/nf_tables.h`.
- Detected declarations: `struct nft_last`, `struct nft_last_priv`, `function nft_last_init`, `function nft_last_eval`, `function nft_last_dump`, `function nft_last_destroy`, `function nft_last_clone`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.