net/ipv4/ip_output.c
Source file repositories/reference/linux-study-clean/net/ipv4/ip_output.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/ip_output.c- Extension
.c- Size
- 43899 bytes
- Lines
- 1694
- 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.
- 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/uaccess.hlinux/module.hlinux/types.hlinux/kernel.hlinux/mm.hlinux/string.hlinux/errno.hlinux/highmem.hlinux/slab.hlinux/socket.hlinux/sockios.hlinux/in.hlinux/inet.hlinux/netdevice.hlinux/etherdevice.hlinux/proc_fs.hlinux/stat.hlinux/init.hnet/flow.hnet/snmp.hnet/ip.hnet/protocol.hnet/route.hnet/xfrm.hlinux/skbuff.hnet/sock.hnet/arp.hnet/icmp.hnet/checksum.hnet/gso.hnet/inetpeer.hnet/lwtunnel.h
Detected Declarations
function ip_send_checkfunction __ip_local_outfunction ip_local_outfunction ip_select_ttlfunction ip_build_and_send_pktfunction ip_finish_output2function ip_finish_output_gsofunction skb_list_walk_safefunction __ip_finish_outputfunction ip_finish_outputfunction ip_mc_finish_outputfunction ip_mc_outputfunction ip_outputfunction ip_copy_addrsfunction __ip_queue_xmitfunction ip_queue_xmitfunction ip_copy_metadatafunction ip_fragmentfunction ip_fraglist_initfunction ip_fraglist_preparefunction ip_frag_initfunction ip_frag_ipcbfunction piecesfunction skb_walk_fragsfunction skb_walk_fragsfunction ip_generic_getfragfunction __ip_append_datafunction ip_setup_corkfunction ip_append_datafunction ip_cork_releasefunction ip_send_skbfunction ip_push_pending_framesfunction __ip_flush_pending_framesfunction ip_flush_pending_framesfunction getfragfunction ip_reply_glue_bitsfunction ip_send_unicast_replyfunction ip_initexport ip_send_checkexport ip_local_outexport ip_outputexport __ip_queue_xmitexport ip_queue_xmitexport ip_fraglist_initexport ip_fraglist_prepareexport ip_frag_initexport ip_frag_nextexport ip_do_fragment
Annotated Snippet
if (ip_hdr(skb)->ttl == 0) {
kfree_skb(skb);
return 0;
}
}
if (rt->rt_flags&RTCF_BROADCAST) {
struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
if (newskb)
NF_HOOK(NFPROTO_IPV4, NF_INET_POST_ROUTING,
net, sk, newskb, NULL, newskb->dev,
ip_mc_finish_output);
}
return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING,
net, sk, skb, NULL, skb->dev,
ip_finish_output,
!(IPCB(skb)->flags & IPSKB_REROUTED));
}
int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb)
{
struct net_device *dev, *indev = skb->dev;
int ret_val;
rcu_read_lock();
dev = skb_dst_dev_rcu(skb);
skb->dev = dev;
skb->protocol = htons(ETH_P_IP);
ret_val = NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING,
net, sk, skb, indev, dev,
ip_finish_output,
!(IPCB(skb)->flags & IPSKB_REROUTED));
rcu_read_unlock();
return ret_val;
}
EXPORT_SYMBOL(ip_output);
/*
* copy saddr and daddr, possibly using 64bit load/stores
* Equivalent to :
* iph->saddr = fl4->saddr;
* iph->daddr = fl4->daddr;
*/
static void ip_copy_addrs(struct iphdr *iph, const struct flowi4 *fl4)
{
BUILD_BUG_ON(offsetof(typeof(*fl4), daddr) !=
offsetof(typeof(*fl4), saddr) + sizeof(fl4->saddr));
iph->saddr = fl4->saddr;
iph->daddr = fl4->daddr;
}
/* Note: skb->sk can be different from sk, in case of tunnels */
int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
__u8 tos)
{
struct inet_sock *inet = inet_sk(sk);
struct net *net = sock_net(sk);
struct ip_options_rcu *inet_opt;
struct flowi4 *fl4;
struct rtable *rt;
struct iphdr *iph;
int res;
/* Skip all of this if the packet is already routed,
* f.e. by something like SCTP.
*/
rcu_read_lock();
inet_opt = rcu_dereference(inet->inet_opt);
fl4 = &fl->u.ip4;
rt = skb_rtable(skb);
if (rt)
goto packet_routed;
/* Make sure we can route this packet. */
rt = dst_rtable(__sk_dst_check(sk, 0));
if (!rt) {
inet_sk_init_flowi4(inet, fl4);
/* sctp_v4_xmit() uses its own DSCP value */
fl4->flowi4_dscp = inet_dsfield_to_dscp(tos);
/* If this fails, retransmit mechanism of transport layer will
* keep trying until route appears or the connection times
* itself out.
*/
rt = ip_route_output_flow(net, fl4, sk);
if (IS_ERR(rt))
Annotation
- Immediate include surface: `linux/uaccess.h`, `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/mm.h`, `linux/string.h`, `linux/errno.h`, `linux/highmem.h`.
- Detected declarations: `function ip_send_check`, `function __ip_local_out`, `function ip_local_out`, `function ip_select_ttl`, `function ip_build_and_send_pkt`, `function ip_finish_output2`, `function ip_finish_output_gso`, `function skb_list_walk_safe`, `function __ip_finish_output`, `function ip_finish_output`.
- 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.