net/netfilter/nf_conntrack_proto_icmp.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_conntrack_proto_icmp.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_conntrack_proto_icmp.c- Extension
.c- Size
- 11015 bytes
- Lines
- 385
- 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/types.hlinux/timer.hlinux/netfilter.hlinux/in.hlinux/icmp.hlinux/seq_file.hnet/ip.hnet/checksum.hlinux/netfilter_ipv4.hnet/netfilter/nf_conntrack_tuple.hnet/netfilter/nf_conntrack_l4proto.hnet/netfilter/nf_conntrack_core.hnet/netfilter/nf_conntrack_timeout.hnet/netfilter/nf_conntrack_zones.hnet/netfilter/nf_log.hnf_internals.hlinux/netfilter/nfnetlink.hlinux/netfilter/nfnetlink_conntrack.hlinux/netfilter/nfnetlink_cttimeout.h
Detected Declarations
function icmp_pkt_to_tuplefunction nf_conntrack_invert_icmp_tuplefunction nf_conntrack_icmp_packetfunction nf_conntrack_inet_errorfunction icmp_error_logfunction nf_conntrack_icmpv4_errorfunction nf_ip_checksumfunction icmp_tuple_to_nlattrfunction icmp_nlattr_to_tuplefunction icmp_nlattr_tuple_sizefunction icmp_timeout_nlattr_to_objfunction icmp_timeout_obj_to_nlattrfunction nf_conntrack_icmp_init_net
Annotated Snippet
if (state->pf == AF_INET) {
nf_l4proto_log_invalid(skb, state,
l4proto,
"outer daddr %pI4 != inner %pI4",
&outer_daddr->ip, &ct_daddr->ip);
} else if (state->pf == AF_INET6) {
nf_l4proto_log_invalid(skb, state,
l4proto,
"outer daddr %pI6 != inner %pI6",
&outer_daddr->ip6, &ct_daddr->ip6);
}
nf_ct_put(ct);
return -NF_ACCEPT;
}
ctinfo = IP_CT_RELATED;
if (dir == IP_CT_DIR_REPLY)
ctinfo += IP_CT_IS_REPLY;
/* Update skb to refer to this connection */
nf_ct_set(skb, ct, ctinfo);
return NF_ACCEPT;
}
static void icmp_error_log(const struct sk_buff *skb,
const struct nf_hook_state *state,
const char *msg)
{
nf_l4proto_log_invalid(skb, state, IPPROTO_ICMP, "%s", msg);
}
/* Small and modified version of icmp_rcv */
int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
struct sk_buff *skb, unsigned int dataoff,
const struct nf_hook_state *state)
{
union nf_inet_addr outer_daddr;
const struct icmphdr *icmph;
struct icmphdr _ih;
/* Not enough header? */
icmph = skb_header_pointer(skb, dataoff, sizeof(_ih), &_ih);
if (icmph == NULL) {
icmp_error_log(skb, state, "short packet");
return -NF_ACCEPT;
}
/* See nf_conntrack_proto_tcp.c */
if (state->net->ct.sysctl_checksum &&
state->hook == NF_INET_PRE_ROUTING &&
nf_ip_checksum(skb, state->hook, dataoff, IPPROTO_ICMP)) {
icmp_error_log(skb, state, "bad hw icmp checksum");
return -NF_ACCEPT;
}
/*
* 18 is the highest 'known' ICMP type. Anything else is a mystery
*
* RFC 1122: 3.2.2 Unknown ICMP messages types MUST be silently
* discarded.
*/
if (icmph->type > NR_ICMP_TYPES) {
icmp_error_log(skb, state, "invalid icmp type");
return -NF_ACCEPT;
}
/* Need to track icmp error message? */
if (!icmp_is_err(icmph->type))
return NF_ACCEPT;
memset(&outer_daddr, 0, sizeof(outer_daddr));
outer_daddr.ip = ip_hdr(skb)->daddr;
dataoff += sizeof(*icmph);
return nf_conntrack_inet_error(tmpl, skb, dataoff, state,
IPPROTO_ICMP, &outer_daddr);
}
#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/nfnetlink_conntrack.h>
static int icmp_tuple_to_nlattr(struct sk_buff *skb,
const struct nf_conntrack_tuple *t)
{
if (nla_put_be16(skb, CTA_PROTO_ICMP_ID, t->src.u.icmp.id) ||
nla_put_u8(skb, CTA_PROTO_ICMP_TYPE, t->dst.u.icmp.type) ||
nla_put_u8(skb, CTA_PROTO_ICMP_CODE, t->dst.u.icmp.code))
goto nla_put_failure;
Annotation
- Immediate include surface: `linux/types.h`, `linux/timer.h`, `linux/netfilter.h`, `linux/in.h`, `linux/icmp.h`, `linux/seq_file.h`, `net/ip.h`, `net/checksum.h`.
- Detected declarations: `function icmp_pkt_to_tuple`, `function nf_conntrack_invert_icmp_tuple`, `function nf_conntrack_icmp_packet`, `function nf_conntrack_inet_error`, `function icmp_error_log`, `function nf_conntrack_icmpv4_error`, `function nf_ip_checksum`, `function icmp_tuple_to_nlattr`, `function icmp_nlattr_to_tuple`, `function icmp_nlattr_tuple_size`.
- 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.