net/netfilter/nf_flow_table_ip.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_flow_table_ip.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_flow_table_ip.c- Extension
.c- Size
- 31077 bytes
- Lines
- 1239
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/init.hlinux/module.hlinux/netfilter.hlinux/rhashtable.hlinux/ip.hlinux/ipv6.hlinux/netdevice.hlinux/if_ether.hlinux/if_vlan.hnet/gre.hnet/gso.hnet/ip.hnet/ipv6.hnet/ip6_route.hnet/ip6_tunnel.hnet/neighbour.hnet/netfilter/nf_flow_table.hnet/netfilter/nf_conntrack_acct.hlinux/tcp.hlinux/udp.h
Detected Declarations
struct nf_flowtable_ctxstruct ppp_hdrstruct ipv6_tel_txoptionstruct nf_flow_xmitfunction nf_flow_state_checkfunction nf_flow_nat_ip_tcpfunction nf_flow_nat_ip_udpfunction nf_flow_nat_ip_l4protofunction nf_flow_snat_ipfunction nf_flow_dnat_ipfunction nf_flow_nat_ipfunction ip_has_optionsfunction nf_flow_tuple_encapfunction nf_flow_tuple_ipfunction nf_flow_exceeds_mtufunction nf_flow_dst_checkfunction nf_flow_xmit_xfrmfunction nf_flow_ip4_tunnel_protofunction nf_flow_ip6_tunnel_protofunction nf_flow_ip_tunnel_popfunction nf_flow_skb_encap_protocolfunction htonsfunction nf_flow_encap_popfunction nf_flow_offload_lookupfunction nf_flow_offload_forwardfunction nf_flow_vlan_pushfunction nf_flow_pppoe_pushfunction nf_flow_tunnel_ipip_pushfunction nf_flow_tunnel_v4_pushfunction nf_flow_tunnel_ip6ip6_pushfunction nf_flow_tunnel_v6_pushfunction nf_flow_encap_pushfunction __nf_flow_queue_xmitfunction nf_flow_encap_gso_xmitfunction skb_list_walk_safefunction nf_flow_queue_xmitfunction nf_flow_offload_ip_hookfunction nf_flow_nat_ipv6_tcpfunction nf_flow_nat_ipv6_udpfunction nf_flow_nat_ipv6_l4protofunction nf_flow_snat_ipv6function nf_flow_dnat_ipv6function nf_flow_nat_ipv6function nf_flow_tuple_ipv6function nf_flow_offload_ipv6_forwardfunction nf_flow_offload_ipv6_lookupfunction nf_flow_offload_ipv6_hookexport nf_flow_offload_ip_hook
Annotated Snippet
struct nf_flowtable_ctx {
const struct net_device *in;
u32 offset;
u32 hdrsize;
struct {
/* Tunnel IP header size */
u32 hdr_size;
/* IP tunnel protocol */
u8 proto;
} tun;
};
static void nf_flow_tuple_encap(struct nf_flowtable_ctx *ctx,
struct sk_buff *skb,
struct flow_offload_tuple *tuple)
{
__be16 inner_proto = skb->protocol;
struct vlan_ethhdr *veth;
struct pppoe_hdr *phdr;
struct ipv6hdr *ip6h;
struct iphdr *iph;
u16 offset = 0;
int i = 0;
if (skb_vlan_tag_present(skb)) {
tuple->encap[i].id = skb_vlan_tag_get(skb);
tuple->encap[i].proto = skb->vlan_proto;
i++;
}
switch (skb->protocol) {
case htons(ETH_P_8021Q):
veth = (struct vlan_ethhdr *)skb_mac_header(skb);
tuple->encap[i].id = ntohs(veth->h_vlan_TCI);
tuple->encap[i].proto = skb->protocol;
inner_proto = veth->h_vlan_encapsulated_proto;
offset += VLAN_HLEN;
break;
case htons(ETH_P_PPP_SES):
phdr = (struct pppoe_hdr *)skb_network_header(skb);
tuple->encap[i].id = ntohs(phdr->sid);
tuple->encap[i].proto = skb->protocol;
inner_proto = *((__be16 *)(phdr + 1));
offset += PPPOE_SES_HLEN;
break;
}
switch (inner_proto) {
case htons(ETH_P_IP):
iph = (struct iphdr *)(skb_network_header(skb) + offset);
if (ctx->tun.proto == IPPROTO_IPIP) {
tuple->tun.dst_v4.s_addr = iph->daddr;
tuple->tun.src_v4.s_addr = iph->saddr;
tuple->tun.l3_proto = IPPROTO_IPIP;
}
break;
case htons(ETH_P_IPV6):
ip6h = (struct ipv6hdr *)(skb_network_header(skb) + offset);
if (ctx->tun.proto == IPPROTO_IPV6) {
tuple->tun.dst_v6 = ip6h->daddr;
tuple->tun.src_v6 = ip6h->saddr;
tuple->tun.l3_proto = IPPROTO_IPV6;
}
break;
default:
break;
}
}
static int nf_flow_tuple_ip(struct nf_flowtable_ctx *ctx, struct sk_buff *skb,
struct flow_offload_tuple *tuple)
{
struct flow_ports *ports;
unsigned int thoff;
struct iphdr *iph;
u8 ipproto;
if (!pskb_may_pull(skb, sizeof(*iph) + ctx->offset))
return -1;
iph = (struct iphdr *)(skb_network_header(skb) + ctx->offset);
thoff = (iph->ihl * 4);
if (ip_is_fragment(iph) ||
unlikely(ip_has_options(thoff)))
return -1;
thoff += ctx->offset;
ipproto = iph->protocol;
switch (ipproto) {
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/netfilter.h`, `linux/rhashtable.h`, `linux/ip.h`, `linux/ipv6.h`, `linux/netdevice.h`.
- Detected declarations: `struct nf_flowtable_ctx`, `struct ppp_hdr`, `struct ipv6_tel_txoption`, `struct nf_flow_xmit`, `function nf_flow_state_check`, `function nf_flow_nat_ip_tcp`, `function nf_flow_nat_ip_udp`, `function nf_flow_nat_ip_l4proto`, `function nf_flow_snat_ip`, `function nf_flow_dnat_ip`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
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.