net/ipv4/tcp_metrics.c
Source file repositories/reference/linux-study-clean/net/ipv4/tcp_metrics.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/tcp_metrics.c- Extension
.c- Size
- 28426 bytes
- Lines
- 1060
- 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.
- 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/rcupdate.hlinux/spinlock.hlinux/jiffies.hlinux/module.hlinux/cache.hlinux/slab.hlinux/init.hlinux/tcp.hlinux/hash.hlinux/tcp_metrics.hlinux/vmalloc.hnet/inet_connection_sock.hnet/net_namespace.hnet/request_sock.hnet/inetpeer.hnet/sock.hnet/ipv6.hnet/dst.hnet/tcp.hnet/genetlink.h
Detected Declarations
struct tcp_fastopen_metricsstruct tcp_metrics_blockstruct tcpm_hash_bucketfunction tcp_metric_lockedfunction tcp_metric_getfunction tcp_metric_setfunction addr_samefunction tcpm_suck_dstfunction tcpm_check_stampfunction tcp_update_metricsfunction tcp_init_metricsfunction intactfunction tcp_peer_is_provenfunction tcp_fastopen_cache_getfunction tcp_fastopen_cache_setfunction tcp_metrics_fill_infofunction tcp_metrics_dump_infofunction tcp_metrics_nl_dumpfunction __parse_nl_addrfunction parse_nl_addrfunction parse_nl_saddrfunction tcp_metrics_nl_cmd_getfunction tcp_metrics_flush_allfunction tcp_metrics_nl_cmd_delfunction set_tcpmhash_entriesfunction tcp_metrics_hash_allocfunction tcp_net_metrics_exit_batchfunction tcp_metrics_init
Annotated Snippet
struct tcp_fastopen_metrics {
u16 mss;
u16 syn_loss:10, /* Recurring Fast Open SYN losses */
try_exp:2; /* Request w/ exp. option (once) */
unsigned long last_syn_loss; /* Last Fast Open SYN loss */
struct tcp_fastopen_cookie cookie;
};
/* TCP_METRIC_MAX includes 2 extra fields for userspace compatibility
* Kernel only stores RTT and RTTVAR in usec resolution
*/
#define TCP_METRIC_MAX_KERNEL (TCP_METRIC_MAX - 2)
struct tcp_metrics_block {
struct tcp_metrics_block __rcu *tcpm_next;
struct net *tcpm_net;
struct inetpeer_addr tcpm_saddr;
struct inetpeer_addr tcpm_daddr;
unsigned long tcpm_stamp;
u32 tcpm_lock;
u32 tcpm_vals[TCP_METRIC_MAX_KERNEL + 1];
struct tcp_fastopen_metrics tcpm_fastopen;
struct rcu_head rcu_head;
};
static inline struct net *tm_net(const struct tcp_metrics_block *tm)
{
/* Paired with the WRITE_ONCE() in tcpm_new() */
return READ_ONCE(tm->tcpm_net);
}
static bool tcp_metric_locked(struct tcp_metrics_block *tm,
enum tcp_metric_index idx)
{
/* Paired with WRITE_ONCE() in tcpm_suck_dst() */
return READ_ONCE(tm->tcpm_lock) & (1 << idx);
}
static u32 tcp_metric_get(const struct tcp_metrics_block *tm,
enum tcp_metric_index idx)
{
/* Paired with WRITE_ONCE() in tcp_metric_set() */
return READ_ONCE(tm->tcpm_vals[idx]);
}
static void tcp_metric_set(struct tcp_metrics_block *tm,
enum tcp_metric_index idx,
u32 val)
{
/* Paired with READ_ONCE() in tcp_metric_get() */
WRITE_ONCE(tm->tcpm_vals[idx], val);
}
static bool addr_same(const struct inetpeer_addr *a,
const struct inetpeer_addr *b)
{
return (a->family == b->family) && !inetpeer_addr_cmp(a, b);
}
struct tcpm_hash_bucket {
struct tcp_metrics_block __rcu *chain;
};
static struct tcpm_hash_bucket *tcp_metrics_hash __read_mostly;
static unsigned int tcp_metrics_hash_log __read_mostly;
static DEFINE_SPINLOCK(tcp_metrics_lock);
static DEFINE_SEQLOCK(fastopen_seqlock);
static void tcpm_suck_dst(struct tcp_metrics_block *tm,
const struct dst_entry *dst,
bool fastopen_clear)
{
u32 msval;
u32 val;
WRITE_ONCE(tm->tcpm_stamp, jiffies);
val = 0;
if (dst_metric_locked(dst, RTAX_RTT))
val |= 1 << TCP_METRIC_RTT;
if (dst_metric_locked(dst, RTAX_RTTVAR))
val |= 1 << TCP_METRIC_RTTVAR;
if (dst_metric_locked(dst, RTAX_SSTHRESH))
val |= 1 << TCP_METRIC_SSTHRESH;
if (dst_metric_locked(dst, RTAX_CWND))
val |= 1 << TCP_METRIC_CWND;
if (dst_metric_locked(dst, RTAX_REORDERING))
val |= 1 << TCP_METRIC_REORDERING;
Annotation
- Immediate include surface: `linux/rcupdate.h`, `linux/spinlock.h`, `linux/jiffies.h`, `linux/module.h`, `linux/cache.h`, `linux/slab.h`, `linux/init.h`, `linux/tcp.h`.
- Detected declarations: `struct tcp_fastopen_metrics`, `struct tcp_metrics_block`, `struct tcpm_hash_bucket`, `function tcp_metric_locked`, `function tcp_metric_get`, `function tcp_metric_set`, `function addr_same`, `function tcpm_suck_dst`, `function tcpm_check_stamp`, `function tcp_update_metrics`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.