net/netfilter/nf_synproxy_core.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_synproxy_core.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_synproxy_core.c- Extension
.c- Size
- 31360 bytes
- Lines
- 1238
- 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/skbuff.hlinux/unaligned.hnet/tcp.hnet/netns/generic.hlinux/proc_fs.hlinux/netfilter_ipv4.hlinux/netfilter_ipv6.hlinux/netfilter/nf_synproxy.hnet/netfilter/nf_conntrack.hnet/netfilter/nf_conntrack_ecache.hnet/netfilter/nf_conntrack_extend.hnet/netfilter/nf_conntrack_seqadj.hnet/netfilter/nf_conntrack_synproxy.hnet/netfilter/nf_conntrack_zones.hnet/netfilter/nf_synproxy.h
Detected Declarations
function synproxy_parse_optionsfunction synproxy_options_sizefunction synproxy_build_optionsfunction synproxy_init_timestamp_cookiefunction synproxy_check_timestamp_cookiefunction synproxy_tstamp_adjustfunction synproxy_cpu_seq_stopfunction synproxy_cpu_seq_showfunction synproxy_proc_initfunction synproxy_proc_exitfunction synproxy_proc_initfunction synproxy_proc_exitfunction synproxy_net_initfunction synproxy_net_exitfunction synproxy_core_initfunction synproxy_core_exitfunction synproxy_build_ipfunction synproxy_send_tcpfunction synproxy_send_client_synackfunction synproxy_send_server_synfunction synproxy_send_server_ackfunction synproxy_send_client_ackfunction synproxy_recv_client_ackfunction ipv4_synproxy_hookfunction nf_synproxy_ipv4_initfunction nf_synproxy_ipv4_finifunction synproxy_build_ip_ipv6function synproxy_send_tcp_ipv6function synproxy_send_client_synack_ipv6function synproxy_send_server_syn_ipv6function synproxy_send_server_ack_ipv6function synproxy_send_client_ack_ipv6function synproxy_recv_client_ack_ipv6function ipv6_synproxy_hookfunction nf_synproxy_ipv6_initfunction nf_synproxy_ipv6_finimodule init synproxy_core_initexport synproxy_net_idexport synproxy_parse_optionsexport synproxy_init_timestamp_cookieexport synproxy_send_client_synackexport synproxy_recv_client_ackexport ipv4_synproxy_hookexport nf_synproxy_ipv4_initexport nf_synproxy_ipv4_finiexport synproxy_send_client_synack_ipv6export synproxy_recv_client_ack_ipv6export ipv6_synproxy_hook
Annotated Snippet
module_init(synproxy_core_init);
module_exit(synproxy_core_exit);
static struct iphdr *
synproxy_build_ip(struct net *net, struct sk_buff *skb, __be32 saddr,
__be32 daddr)
{
struct iphdr *iph;
skb_reset_network_header(skb);
iph = skb_put(skb, sizeof(*iph));
iph->version = 4;
iph->ihl = sizeof(*iph) / 4;
iph->tos = 0;
iph->id = 0;
iph->frag_off = htons(IP_DF);
iph->ttl = READ_ONCE(net->ipv4.sysctl_ip_default_ttl);
iph->protocol = IPPROTO_TCP;
iph->check = 0;
iph->saddr = saddr;
iph->daddr = daddr;
return iph;
}
static void
synproxy_send_tcp(struct net *net,
const struct sk_buff *skb, struct sk_buff *nskb,
struct nf_conntrack *nfct, enum ip_conntrack_info ctinfo,
struct iphdr *niph, struct tcphdr *nth,
unsigned int tcp_hdr_size)
{
nth->check = ~tcp_v4_check(tcp_hdr_size, niph->saddr, niph->daddr, 0);
nskb->ip_summed = CHECKSUM_PARTIAL;
nskb->csum_start = (unsigned char *)nth - nskb->head;
nskb->csum_offset = offsetof(struct tcphdr, check);
skb_dst_set_noref(nskb, skb_dst(skb));
nskb->protocol = htons(ETH_P_IP);
if (ip_route_me_harder(net, nskb->sk, nskb, RTN_UNSPEC))
goto free_nskb;
if (nfct) {
nf_ct_set(nskb, (struct nf_conn *)nfct, ctinfo);
nf_conntrack_get(nfct);
}
ip_local_out(net, nskb->sk, nskb);
return;
free_nskb:
kfree_skb(nskb);
}
void
synproxy_send_client_synack(struct net *net,
const struct sk_buff *skb, const struct tcphdr *th,
const struct synproxy_options *opts)
{
struct sk_buff *nskb;
struct iphdr *iph, *niph;
struct tcphdr *nth;
unsigned int tcp_hdr_size;
u16 mss = opts->mss_encode;
iph = ip_hdr(skb);
tcp_hdr_size = sizeof(*nth) + synproxy_options_size(opts);
nskb = alloc_skb(sizeof(*niph) + tcp_hdr_size + MAX_TCP_HEADER,
GFP_ATOMIC);
if (!nskb)
return;
skb_reserve(nskb, MAX_TCP_HEADER);
niph = synproxy_build_ip(net, nskb, iph->daddr, iph->saddr);
skb_reset_transport_header(nskb);
nth = skb_put(nskb, tcp_hdr_size);
nth->source = th->dest;
nth->dest = th->source;
nth->seq = htonl(__cookie_v4_init_sequence(iph, th, &mss));
nth->ack_seq = htonl(ntohl(th->seq) + 1);
tcp_flag_word(nth) = TCP_FLAG_SYN | TCP_FLAG_ACK;
if (opts->options & NF_SYNPROXY_OPT_ECN)
tcp_flag_word(nth) |= TCP_FLAG_ECE;
nth->doff = tcp_hdr_size / 4;
nth->window = 0;
nth->check = 0;
nth->urg_ptr = 0;
Annotation
- Immediate include surface: `linux/module.h`, `linux/skbuff.h`, `linux/unaligned.h`, `net/tcp.h`, `net/netns/generic.h`, `linux/proc_fs.h`, `linux/netfilter_ipv4.h`, `linux/netfilter_ipv6.h`.
- Detected declarations: `function synproxy_parse_options`, `function synproxy_options_size`, `function synproxy_build_options`, `function synproxy_init_timestamp_cookie`, `function synproxy_check_timestamp_cookie`, `function synproxy_tstamp_adjust`, `function synproxy_cpu_seq_stop`, `function synproxy_cpu_seq_show`, `function synproxy_proc_init`, `function synproxy_proc_exit`.
- 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.