net/netfilter/nf_nat_redirect.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_nat_redirect.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_nat_redirect.c- Extension
.c- Size
- 3354 bytes
- Lines
- 139
- 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/if.hlinux/inetdevice.hlinux/in.hlinux/ip.hlinux/kernel.hlinux/netdevice.hlinux/netfilter.hlinux/types.hlinux/netfilter_ipv4.hlinux/netfilter_ipv6.hlinux/netfilter/x_tables.hnet/addrconf.hnet/checksum.hnet/protocol.hnet/netfilter/nf_nat.hnet/netfilter/nf_nat_redirect.h
Detected Declarations
function Copyrightfunction nf_nat_redirect_ipv4function nf_nat_redirect_ipv6_usablefunction nf_nat_redirect_ipv6function list_for_each_entryexport nf_nat_redirect_ipv4export nf_nat_redirect_ipv6
Annotated Snippet
if (indev) {
const struct in_ifaddr *ifa;
ifa = rcu_dereference(indev->ifa_list);
if (ifa)
newdst.ip = ifa->ifa_local;
}
if (!newdst.ip)
return NF_DROP;
}
return nf_nat_redirect(skb, range, &newdst);
}
EXPORT_SYMBOL_GPL(nf_nat_redirect_ipv4);
static const struct in6_addr loopback_addr = IN6ADDR_LOOPBACK_INIT;
static bool nf_nat_redirect_ipv6_usable(const struct inet6_ifaddr *ifa, unsigned int scope)
{
unsigned int ifa_addr_type = ipv6_addr_type(&ifa->addr);
if (ifa_addr_type & IPV6_ADDR_MAPPED)
return false;
if ((ifa->flags & IFA_F_TENTATIVE) && (!(ifa->flags & IFA_F_OPTIMISTIC)))
return false;
if (scope) {
unsigned int ifa_scope = ifa_addr_type & IPV6_ADDR_SCOPE_MASK;
if (!(scope & ifa_scope))
return false;
}
return true;
}
unsigned int
nf_nat_redirect_ipv6(struct sk_buff *skb, const struct nf_nat_range2 *range,
unsigned int hooknum)
{
union nf_inet_addr newdst = {};
if (hooknum == NF_INET_LOCAL_OUT) {
newdst.in6 = loopback_addr;
} else {
unsigned int scope = ipv6_addr_scope(&ipv6_hdr(skb)->daddr);
struct inet6_dev *idev;
bool addr = false;
idev = __in6_dev_get(skb->dev);
if (idev != NULL) {
const struct inet6_ifaddr *ifa;
read_lock_bh(&idev->lock);
list_for_each_entry(ifa, &idev->addr_list, if_list) {
if (!nf_nat_redirect_ipv6_usable(ifa, scope))
continue;
newdst.in6 = ifa->addr;
addr = true;
break;
}
read_unlock_bh(&idev->lock);
}
if (!addr)
return NF_DROP;
}
return nf_nat_redirect(skb, range, &newdst);
}
EXPORT_SYMBOL_GPL(nf_nat_redirect_ipv6);
Annotation
- Immediate include surface: `linux/if.h`, `linux/inetdevice.h`, `linux/in.h`, `linux/ip.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/netfilter.h`, `linux/types.h`.
- Detected declarations: `function Copyright`, `function nf_nat_redirect_ipv4`, `function nf_nat_redirect_ipv6_usable`, `function nf_nat_redirect_ipv6`, `function list_for_each_entry`, `export nf_nat_redirect_ipv4`, `export nf_nat_redirect_ipv6`.
- 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.