net/ipv4/ip_input.c
Source file repositories/reference/linux-study-clean/net/ipv4/ip_input.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/ip_input.c- Extension
.c- Size
- 20633 bytes
- Lines
- 719
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/types.hlinux/kernel.hlinux/string.hlinux/errno.hlinux/slab.hlinux/net.hlinux/socket.hlinux/sockios.hlinux/in.hlinux/inet.hlinux/inetdevice.hlinux/netdevice.hlinux/etherdevice.hlinux/indirect_call_wrapper.hnet/snmp.hnet/ip.hnet/protocol.hnet/route.hlinux/skbuff.hnet/sock.hnet/arp.hnet/icmp.hnet/raw.hnet/checksum.hnet/inet_ecn.hlinux/netfilter_ipv4.hnet/xfrm.hlinux/mroute.hlinux/netlink.hnet/dst_metadata.hnet/udp.h
Detected Declarations
function Protocolfunction ip_protocol_deliver_rcufunction ip_local_deliver_finishfunction ip_local_deliverfunction ip_rcv_optionsfunction ip_can_use_hintfunction tcp_v4_early_demuxfunction ip_rcv_finish_corefunction ip_rcv_finishfunction ip_rcvfunction ip_sublist_rcv_finishfunction list_for_each_entry_safefunction ip_list_rcv_finishfunction list_for_each_entry_safefunction ip_sublist_rcvfunction ip_list_rcvfunction list_for_each_entry_safeexport ip_local_deliver
Annotated Snippet
if (ip_is_fragment(ip_hdr(skb))) {
if (ip_defrag(net, skb, IP_DEFRAG_CALL_RA_CHAIN))
return true;
}
if (last) {
struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
if (skb2)
raw_rcv(last, skb2);
}
last = sk;
}
}
if (last) {
raw_rcv(last, skb);
return true;
}
return false;
}
INDIRECT_CALLABLE_DECLARE(int udp_rcv(struct sk_buff *));
INDIRECT_CALLABLE_DECLARE(int tcp_v4_rcv(struct sk_buff *));
void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol)
{
const struct net_protocol *ipprot;
int raw, ret;
resubmit:
raw = raw_local_deliver(skb, protocol);
ipprot = rcu_dereference(inet_protos[protocol]);
if (ipprot) {
if (!ipprot->no_policy) {
if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
kfree_skb_reason(skb,
SKB_DROP_REASON_XFRM_POLICY);
return;
}
nf_reset_ct(skb);
}
ret = INDIRECT_CALL_2(ipprot->handler, tcp_v4_rcv, udp_rcv,
skb);
if (ret < 0) {
protocol = -ret;
goto resubmit;
}
__IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS);
} else {
if (!raw) {
if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
__IP_INC_STATS(net, IPSTATS_MIB_INUNKNOWNPROTOS);
icmp_send(skb, ICMP_DEST_UNREACH,
ICMP_PROT_UNREACH, 0);
}
kfree_skb_reason(skb, SKB_DROP_REASON_IP_NOPROTO);
} else {
__IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS);
consume_skb(skb);
}
}
}
static int ip_local_deliver_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
{
if (unlikely(skb_orphan_frags_rx(skb, GFP_ATOMIC))) {
__IP_INC_STATS(net, IPSTATS_MIB_INDISCARDS);
kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM);
return 0;
}
skb_clear_delivery_time(skb);
__skb_pull(skb, skb_network_header_len(skb));
rcu_read_lock();
ip_protocol_deliver_rcu(net, skb, ip_hdr(skb)->protocol);
rcu_read_unlock();
return 0;
}
/*
* Deliver IP Packets to the higher protocol layers.
*/
int ip_local_deliver(struct sk_buff *skb)
{
/*
* Reassemble IP fragments.
*/
struct net *net = dev_net(skb->dev);
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/string.h`, `linux/errno.h`, `linux/slab.h`, `linux/net.h`, `linux/socket.h`.
- Detected declarations: `function Protocol`, `function ip_protocol_deliver_rcu`, `function ip_local_deliver_finish`, `function ip_local_deliver`, `function ip_rcv_options`, `function ip_can_use_hint`, `function tcp_v4_early_demux`, `function ip_rcv_finish_core`, `function ip_rcv_finish`, `function ip_rcv`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.