net/netfilter/nf_conntrack_proto_tcp.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_conntrack_proto_tcp.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_conntrack_proto_tcp.c- Extension
.c- Size
- 50160 bytes
- Lines
- 1643
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/timer.hlinux/module.hlinux/in.hlinux/tcp.hlinux/spinlock.hlinux/skbuff.hlinux/ipv6.hnet/ip6_checksum.hlinux/unaligned.hnet/tcp.hlinux/netfilter.hlinux/netfilter_ipv4.hlinux/netfilter_ipv6.hnet/netfilter/nf_conntrack.hnet/netfilter/nf_conntrack_l4proto.hnet/netfilter/nf_conntrack_ecache.hnet/netfilter/nf_conntrack_seqadj.hnet/netfilter/nf_conntrack_synproxy.hnet/netfilter/nf_conntrack_timeout.hnet/netfilter/nf_log.hnet/netfilter/ipv4/nf_conntrack_ipv4.hnet/netfilter/ipv6/nf_conntrack_ipv6.hlinux/netfilter/nfnetlink.hlinux/netfilter/nfnetlink_conntrack.hlinux/netfilter/nfnetlink_cttimeout.h
Detected Declarations
enum nf_ct_tcp_actionenum tcp_bit_setfunction tcp_print_conntrackfunction get_conntrack_indexfunction windowfunction tcp_optionsfunction tcp_sackfunction tcp_init_senderfunction nf_tcp_log_invalidfunction tcp_in_windowfunction afterfunction nf_tcp_handle_invalidfunction tcp_error_logfunction tcp_errorfunction nf_checksumfunction tcp_newfunction tcp_can_early_dropfunction nf_conntrack_tcp_set_closingfunction nf_ct_tcp_state_resetfunction nf_conntrack_tcp_packetfunction tcp_to_nlattrfunction nlattr_to_tcpfunction tcp_nlattr_tuple_sizefunction tcp_timeout_nlattr_to_objfunction tcp_timeout_obj_to_nlattrfunction nf_conntrack_tcp_init_net
Annotated Snippet
switch (opcode) {
case TCPOPT_EOL:
return;
case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
length--;
continue;
default:
if (length < 2)
return;
opsize=*ptr++;
if (opsize < 2) /* "silly options" */
return;
if (opsize > length)
return; /* don't parse partial options */
if (opcode == TCPOPT_SACK_PERM
&& opsize == TCPOLEN_SACK_PERM)
state->flags |= IP_CT_TCP_FLAG_SACK_PERM;
else if (opcode == TCPOPT_WINDOW
&& opsize == TCPOLEN_WINDOW) {
state->td_scale = *(u_int8_t *)ptr;
if (state->td_scale > TCP_MAX_WSCALE)
state->td_scale = TCP_MAX_WSCALE;
state->flags |=
IP_CT_TCP_FLAG_WINDOW_SCALE;
}
ptr += opsize - 2;
length -= opsize;
}
}
}
static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
const struct tcphdr *tcph, __u32 *sack)
{
unsigned char buff[(15 * 4) - sizeof(struct tcphdr)];
const unsigned char *ptr;
int length = (tcph->doff*4) - sizeof(struct tcphdr);
__u32 tmp;
if (!length)
return;
ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
length, buff);
if (!ptr)
return;
/* Fast path for timestamp-only option */
if (length == TCPOLEN_TSTAMP_ALIGNED &&
get_unaligned_be32(ptr) == ((TCPOPT_NOP << 24) |
(TCPOPT_NOP << 16) |
(TCPOPT_TIMESTAMP << 8) |
TCPOLEN_TIMESTAMP))
return;
while (length > 0) {
int opcode = *ptr++;
int opsize, i;
switch (opcode) {
case TCPOPT_EOL:
return;
case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
length--;
continue;
default:
if (length < 2)
return;
opsize = *ptr++;
if (opsize < 2) /* "silly options" */
return;
if (opsize > length)
return; /* don't parse partial options */
if (opcode == TCPOPT_SACK
&& opsize >= (TCPOLEN_SACK_BASE
+ TCPOLEN_SACK_PERBLOCK)
&& !((opsize - TCPOLEN_SACK_BASE)
% TCPOLEN_SACK_PERBLOCK)) {
for (i = 0;
i < (opsize - TCPOLEN_SACK_BASE);
i += TCPOLEN_SACK_PERBLOCK) {
tmp = get_unaligned_be32((__be32 *)(ptr+i)+1);
if (after(tmp, *sack))
*sack = tmp;
}
Annotation
- Immediate include surface: `linux/types.h`, `linux/timer.h`, `linux/module.h`, `linux/in.h`, `linux/tcp.h`, `linux/spinlock.h`, `linux/skbuff.h`, `linux/ipv6.h`.
- Detected declarations: `enum nf_ct_tcp_action`, `enum tcp_bit_set`, `function tcp_print_conntrack`, `function get_conntrack_index`, `function window`, `function tcp_options`, `function tcp_sack`, `function tcp_init_sender`, `function nf_tcp_log_invalid`, `function tcp_in_window`.
- 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.