net/netfilter/nft_exthdr.c
Source file repositories/reference/linux-study-clean/net/netfilter/nft_exthdr.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nft_exthdr.c- Extension
.c- Size
- 19745 bytes
- Lines
- 821
- 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/unaligned.hlinux/kernel.hlinux/netlink.hlinux/netfilter.hlinux/netfilter/nf_tables.hlinux/dccp.hlinux/sctp.hnet/netfilter/nf_tables_core.hnet/netfilter/nf_tables.hnet/tcp.h
Detected Declarations
struct nft_exthdrfunction optlenfunction nft_skb_copy_to_regfunction nft_exthdr_ipv6_evalfunction ipv4_find_optionfunction nft_exthdr_ipv4_evalfunction nft_tcp_header_pointerfunction nft_exthdr_tcp_evalfunction nft_exthdr_tcp_set_evalfunction nft_exthdr_tcp_strip_evalfunction nft_exthdr_sctp_evalfunction nft_exthdr_dccp_evalfunction nft_exthdr_initfunction nft_exthdr_tcp_set_initfunction nft_exthdr_tcp_strip_initfunction nft_exthdr_ipv4_initfunction nft_exthdr_dccp_initfunction nft_exthdr_dump_commonfunction nft_exthdr_dumpfunction nft_exthdr_dump_setfunction nft_exthdr_dump_stripfunction nft_exthdr_select_ops
Annotated Snippet
struct nft_exthdr {
u8 type;
u8 offset;
u8 len;
u8 op;
u8 dreg;
u8 sreg;
u8 flags;
};
static unsigned int optlen(const u8 *opt, unsigned int offset)
{
/* Beware zero-length options: make finite progress */
if (opt[offset] <= TCPOPT_NOP || opt[offset + 1] == 0)
return 1;
else
return opt[offset + 1];
}
static int nft_skb_copy_to_reg(const struct sk_buff *skb, int offset, u32 *dest, unsigned int len)
{
if (len % NFT_REG32_SIZE)
dest[len / NFT_REG32_SIZE] = 0;
return skb_copy_bits(skb, offset, dest, len);
}
static void nft_exthdr_ipv6_eval(const struct nft_expr *expr,
struct nft_regs *regs,
const struct nft_pktinfo *pkt)
{
struct nft_exthdr *priv = nft_expr_priv(expr);
u32 *dest = ®s->data[priv->dreg];
unsigned int offset = 0;
int err;
if (pkt->skb->protocol != htons(ETH_P_IPV6))
goto err;
err = ipv6_find_hdr(pkt->skb, &offset, priv->type, NULL, NULL);
if (priv->flags & NFT_EXTHDR_F_PRESENT) {
nft_reg_store8(dest, err >= 0);
return;
} else if (err < 0) {
goto err;
}
offset += priv->offset;
if (nft_skb_copy_to_reg(pkt->skb, offset, dest, priv->len) < 0)
goto err;
return;
err:
regs->verdict.code = NFT_BREAK;
}
/* find the offset to specified option.
*
* If target header is found, its offset is set in *offset and return option
* number. Otherwise, return negative error.
*
* If the first fragment doesn't contain the End of Options it is considered
* invalid.
*/
static int ipv4_find_option(struct net *net, struct sk_buff *skb,
unsigned int *offset, int target)
{
unsigned char optbuf[sizeof(struct ip_options) + 40];
struct ip_options *opt = (struct ip_options *)optbuf;
struct iphdr *iph, _iph;
bool found = false;
__be32 info;
int optlen;
iph = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
if (!iph)
return -EBADMSG;
optlen = iph->ihl * 4 - (int)sizeof(struct iphdr);
if (optlen <= 0)
return -ENOENT;
memset(opt, 0, sizeof(struct ip_options));
/* Copy the options since __ip_options_compile() modifies
* the options.
*/
if (skb_copy_bits(skb, sizeof(struct iphdr), opt->__data, optlen))
return -EBADMSG;
opt->optlen = optlen;
if (__ip_options_compile(net, opt, NULL, &info))
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/kernel.h`, `linux/netlink.h`, `linux/netfilter.h`, `linux/netfilter/nf_tables.h`, `linux/dccp.h`, `linux/sctp.h`, `net/netfilter/nf_tables_core.h`.
- Detected declarations: `struct nft_exthdr`, `function optlen`, `function nft_skb_copy_to_reg`, `function nft_exthdr_ipv6_eval`, `function ipv4_find_option`, `function nft_exthdr_ipv4_eval`, `function nft_tcp_header_pointer`, `function nft_exthdr_tcp_eval`, `function nft_exthdr_tcp_set_eval`, `function nft_exthdr_tcp_strip_eval`.
- 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.