net/netfilter/nft_cmp.c
Source file repositories/reference/linux-study-clean/net/netfilter/nft_cmp.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nft_cmp.c- Extension
.c- Size
- 10634 bytes
- Lines
- 434
- 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.
- 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/if_arp.hlinux/netfilter/nf_tables.hnet/netfilter/nf_tables_core.hnet/netfilter/nf_tables_offload.hnet/netfilter/nf_tables.h
Detected Declarations
struct nft_cmp_exprfunction nft_cmp_evalfunction nft_cmp_initfunction nft_cmp_dumpfunction nft_payload_n2hfunction __nft_cmp_offloadfunction nft_cmp_offloadfunction nft_cmp_fast_maskfunction nft_cmp_fast_initfunction nft_cmp_fast_offloadfunction nft_cmp_fast_dumpfunction nft_cmp_maskfunction nft_cmp16_fast_maskfunction nft_cmp16_fast_initfunction nft_cmp16_fast_offloadfunction nft_cmp16_fast_dumpfunction nft_cmp_select_ops
Annotated Snippet
struct nft_cmp_expr {
struct nft_data data;
u8 sreg;
u8 len;
enum nft_cmp_ops op:8;
};
void nft_cmp_eval(const struct nft_expr *expr,
struct nft_regs *regs,
const struct nft_pktinfo *pkt)
{
const struct nft_cmp_expr *priv = nft_expr_priv(expr);
int d;
d = memcmp(®s->data[priv->sreg], &priv->data, priv->len);
switch (priv->op) {
case NFT_CMP_EQ:
if (d != 0)
goto mismatch;
break;
case NFT_CMP_NEQ:
if (d == 0)
goto mismatch;
break;
case NFT_CMP_LT:
if (d == 0)
goto mismatch;
fallthrough;
case NFT_CMP_LTE:
if (d > 0)
goto mismatch;
break;
case NFT_CMP_GT:
if (d == 0)
goto mismatch;
fallthrough;
case NFT_CMP_GTE:
if (d < 0)
goto mismatch;
break;
}
return;
mismatch:
regs->verdict.code = NFT_BREAK;
}
static const struct nla_policy nft_cmp_policy[NFTA_CMP_MAX + 1] = {
[NFTA_CMP_SREG] = NLA_POLICY_MAX(NLA_BE32, NFT_REG32_MAX),
[NFTA_CMP_OP] = { .type = NLA_U32 },
[NFTA_CMP_DATA] = { .type = NLA_NESTED },
};
static int nft_cmp_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
const struct nlattr * const tb[])
{
struct nft_cmp_expr *priv = nft_expr_priv(expr);
struct nft_data_desc desc = {
.type = NFT_DATA_VALUE,
.size = sizeof(priv->data),
};
int err;
err = nft_data_init(NULL, &priv->data, &desc, tb[NFTA_CMP_DATA]);
if (err < 0)
return err;
err = nft_parse_register_load(ctx, tb[NFTA_CMP_SREG], &priv->sreg, desc.len);
if (err < 0)
return err;
priv->op = ntohl(nla_get_be32(tb[NFTA_CMP_OP]));
priv->len = desc.len;
return 0;
}
static int nft_cmp_dump(struct sk_buff *skb,
const struct nft_expr *expr, bool reset)
{
const struct nft_cmp_expr *priv = nft_expr_priv(expr);
if (nft_dump_register(skb, NFTA_CMP_SREG, priv->sreg))
goto nla_put_failure;
if (nla_put_be32(skb, NFTA_CMP_OP, htonl(priv->op)))
goto nla_put_failure;
if (nft_data_dump(skb, NFTA_CMP_DATA, &priv->data,
NFT_DATA_VALUE, priv->len) < 0)
goto nla_put_failure;
return 0;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/netlink.h`, `linux/netfilter.h`, `linux/if_arp.h`, `linux/netfilter/nf_tables.h`, `net/netfilter/nf_tables_core.h`.
- Detected declarations: `struct nft_cmp_expr`, `function nft_cmp_eval`, `function nft_cmp_init`, `function nft_cmp_dump`, `function nft_payload_n2h`, `function __nft_cmp_offload`, `function nft_cmp_offload`, `function nft_cmp_fast_mask`, `function nft_cmp_fast_init`, `function nft_cmp_fast_offload`.
- 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.