net/ipv4/inet_connection_sock.c
Source file repositories/reference/linux-study-clean/net/ipv4/inet_connection_sock.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/inet_connection_sock.c- Extension
.c- Size
- 43059 bytes
- Lines
- 1565
- 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/jhash.hnet/inet_connection_sock.hnet/inet_hashtables.hnet/inet_timewait_sock.hnet/ip.hnet/route.hnet/tcp_states.hnet/xfrm.hnet/tcp.hnet/tcp_ecn.hnet/sock_reuseport.hnet/addrconf.h
Detected Declarations
function ipv6_rcv_saddr_equalfunction ipv4_rcv_saddr_equalfunction inet_rcv_saddr_equalfunction inet_rcv_saddr_anyfunction rangefunction inet_bind_conflictfunction __inet_bhash2_conflictfunction inet_bhash2_conflictfunction sk_for_each_boundfunction sk_for_each_boundfunction INADDR_ANYfunction inet_bind_bucket_for_eachfunction inet_csk_find_open_portfunction inet_bind_bucket_for_eachfunction sk_reuseport_matchfunction inet_csk_update_fastreusefunction portfunction inet_csk_wait_for_connectfunction inet_csk_init_xmit_timersfunction inet_csk_clear_xmit_timersfunction inet_csk_clear_xmit_timers_syncfunction syn_ack_recalcfunction reqsk_alloc_noproffunction __reqsk_freefunction reqsk_queue_migratedfunction reqsk_migrate_resetfunction reqsk_queue_unlinkfunction __inet_csk_reqsk_queue_dropfunction inet_csk_reqsk_queue_dropfunction inet_csk_reqsk_queue_drop_and_putfunction reqsk_timer_handlerfunction reqsk_queue_hash_reqfunction inet_csk_reqsk_queue_hash_addfunction inet_clone_ulpfunction pathfunction inet_csk_destroy_sockfunction inet_csk_prepare_for_destroy_sockfunction tcp_create_openreq_childfunction inet_ulp_can_listenfunction reqsk_queue_allocfunction inet_csk_listen_startfunction inet_child_forgetfunction inet_csk_listen_stopfunction resetexport inet_sk_get_local_port_rangeexport inet_csk_get_port
Annotated Snippet
if (!sk2_ipv6only) {
if (sk1_rcv_saddr == sk2_rcv_saddr)
return true;
return (match_sk1_wildcard && !sk1_rcv_saddr) ||
(match_sk2_wildcard && !sk2_rcv_saddr);
}
return false;
}
if (addr_type == IPV6_ADDR_ANY && addr_type2 == IPV6_ADDR_ANY)
return true;
if (addr_type2 == IPV6_ADDR_ANY && match_sk2_wildcard &&
!(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
return true;
if (addr_type == IPV6_ADDR_ANY && match_sk1_wildcard &&
!(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
return true;
if (sk2_rcv_saddr6 &&
ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
return true;
return false;
}
#endif
/* match_sk*_wildcard == true: 0.0.0.0 equals to any IPv4 addresses
* match_sk*_wildcard == false: addresses must be exactly the same, i.e.
* 0.0.0.0 only equals to 0.0.0.0
*/
static bool ipv4_rcv_saddr_equal(__be32 sk1_rcv_saddr, __be32 sk2_rcv_saddr,
bool sk2_ipv6only, bool match_sk1_wildcard,
bool match_sk2_wildcard)
{
if (!sk2_ipv6only) {
if (sk1_rcv_saddr == sk2_rcv_saddr)
return true;
return (match_sk1_wildcard && !sk1_rcv_saddr) ||
(match_sk2_wildcard && !sk2_rcv_saddr);
}
return false;
}
bool inet_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2,
bool match_wildcard)
{
#if IS_ENABLED(CONFIG_IPV6)
if (sk->sk_family == AF_INET6)
return ipv6_rcv_saddr_equal(&sk->sk_v6_rcv_saddr,
inet6_rcv_saddr(sk2),
sk->sk_rcv_saddr,
sk2->sk_rcv_saddr,
ipv6_only_sock(sk),
ipv6_only_sock(sk2),
match_wildcard,
match_wildcard);
#endif
return ipv4_rcv_saddr_equal(sk->sk_rcv_saddr, sk2->sk_rcv_saddr,
ipv6_only_sock(sk2), match_wildcard,
match_wildcard);
}
bool inet_rcv_saddr_any(const struct sock *sk)
{
#if IS_ENABLED(CONFIG_IPV6)
if (sk->sk_family == AF_INET6)
return ipv6_addr_any(&sk->sk_v6_rcv_saddr);
#endif
return !sk->sk_rcv_saddr;
}
/**
* inet_sk_get_local_port_range - fetch ephemeral ports range
* @sk: socket
* @low: pointer to low port
* @high: pointer to high port
*
* Fetch netns port range (/proc/sys/net/ipv4/ip_local_port_range)
* Range can be overridden if socket got IP_LOCAL_PORT_RANGE option.
* Returns true if IP_LOCAL_PORT_RANGE was set on this socket.
*/
bool inet_sk_get_local_port_range(const struct sock *sk, int *low, int *high)
{
int lo, hi, sk_lo, sk_hi;
bool local_range = false;
u32 sk_range;
inet_get_local_port_range(sock_net(sk), &lo, &hi);
Annotation
- Immediate include surface: `linux/module.h`, `linux/jhash.h`, `net/inet_connection_sock.h`, `net/inet_hashtables.h`, `net/inet_timewait_sock.h`, `net/ip.h`, `net/route.h`, `net/tcp_states.h`.
- Detected declarations: `function ipv6_rcv_saddr_equal`, `function ipv4_rcv_saddr_equal`, `function inet_rcv_saddr_equal`, `function inet_rcv_saddr_any`, `function range`, `function inet_bind_conflict`, `function __inet_bhash2_conflict`, `function inet_bhash2_conflict`, `function sk_for_each_bound`, `function sk_for_each_bound`.
- 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.