net/netfilter/nf_dup_netdev.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_dup_netdev.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_dup_netdev.c- Extension
.c- Size
- 2241 bytes
- Lines
- 99
- 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/netlink.hlinux/netfilter.hlinux/netfilter/nf_tables.hnet/netfilter/nf_tables.hnet/netfilter/nf_tables_offload.hnet/netfilter/nf_dup_netdev.h
Detected Declarations
function Copyrightfunction nf_fwd_netdev_egressfunction nf_dup_netdev_egressfunction nft_fwd_dup_netdev_offloadexport nf_fwd_netdev_egressexport nf_dup_netdev_egressexport nft_fwd_dup_netdev_offload
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2015 Pablo Neira Ayuso <pablo@netfilter.org>
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/netlink.h>
#include <linux/netfilter.h>
#include <linux/netfilter/nf_tables.h>
#include <net/netfilter/nf_tables.h>
#include <net/netfilter/nf_tables_offload.h>
#include <net/netfilter/nf_dup_netdev.h>
static void nf_do_netdev_egress(struct sk_buff *skb, struct net_device *dev,
enum nf_dev_hooks hook)
{
if (hook == NF_NETDEV_INGRESS && skb_mac_header_was_set(skb)) {
if (skb_cow_head(skb, skb->mac_len))
goto err;
skb_push(skb, skb->mac_len);
}
skb->dev = dev;
skb_clear_tstamp(skb);
local_bh_disable();
if (nf_dev_xmit_recursion()) {
local_bh_enable();
goto err;
}
nf_dev_xmit_recursion_inc();
dev_queue_xmit(skb);
nf_dev_xmit_recursion_dec();
local_bh_enable();
return;
err:
kfree_skb(skb);
}
void nf_fwd_netdev_egress(const struct nft_pktinfo *pkt, int oif)
{
struct net_device *dev;
dev = dev_get_by_index_rcu(nft_net(pkt), oif);
if (!dev) {
kfree_skb(pkt->skb);
return;
}
nf_do_netdev_egress(pkt->skb, dev, nft_hook(pkt));
}
EXPORT_SYMBOL_GPL(nf_fwd_netdev_egress);
void nf_dup_netdev_egress(const struct nft_pktinfo *pkt, int oif)
{
struct net_device *dev;
struct sk_buff *skb;
dev = dev_get_by_index_rcu(nft_net(pkt), oif);
if (dev == NULL)
return;
skb = skb_clone(pkt->skb, GFP_ATOMIC);
if (skb)
nf_do_netdev_egress(skb, dev, nft_hook(pkt));
}
EXPORT_SYMBOL_GPL(nf_dup_netdev_egress);
int nft_fwd_dup_netdev_offload(struct nft_offload_ctx *ctx,
struct nft_flow_rule *flow,
enum flow_action_id id, int oif)
{
struct flow_action_entry *entry;
struct net_device *dev;
dev = dev_get_by_index(ctx->net, oif);
if (!dev)
return -EOPNOTSUPP;
entry = nft_flow_action_entry_next(ctx, flow);
if (!entry) {
dev_put(dev);
return -E2BIG;
}
entry->id = id;
/* nft_flow_rule_destroy() releases the reference on this device. */
entry->dev = dev;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/netlink.h`, `linux/netfilter.h`, `linux/netfilter/nf_tables.h`, `net/netfilter/nf_tables.h`, `net/netfilter/nf_tables_offload.h`.
- Detected declarations: `function Copyright`, `function nf_fwd_netdev_egress`, `function nf_dup_netdev_egress`, `function nft_fwd_dup_netdev_offload`, `export nf_fwd_netdev_egress`, `export nf_dup_netdev_egress`, `export nft_fwd_dup_netdev_offload`.
- 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.