net/xdp/xsk.c
Source file repositories/reference/linux-study-clean/net/xdp/xsk.c
File Facts
- System
- Linux kernel
- Corpus path
net/xdp/xsk.c- Extension
.c- Size
- 47056 bytes
- Lines
- 2087
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/if_xdp.hlinux/init.hlinux/sched/mm.hlinux/sched/signal.hlinux/sched/task.hlinux/socket.hlinux/file.hlinux/uaccess.hlinux/net.hlinux/netdevice.hlinux/rculist.hlinux/uio.hlinux/vmalloc.hnet/netdev_queues.hnet/xdp_sock_drv.hnet/busy_poll.hnet/netdev_lock.hnet/netdev_rx_queue.hnet/xdp.h../core/dev.hxsk_queue.hxdp_umem.hxsk.h
Detected Declarations
struct xsk_addrsstruct xdp_umem_reg_v1struct xdp_statistics_v1function xsk_set_rx_need_wakeupfunction xsk_set_tx_need_wakeupfunction xsk_clear_rx_need_wakeupfunction xsk_clear_tx_need_wakeupfunction xsk_uses_need_wakeupfunction __xsk_clear_pool_at_qidfunction xsk_clear_pool_at_qidfunction __xsk_reg_pool_at_qidfunction xsk_reg_pool_at_qidfunction __xsk_rcv_zcfunction __xsk_rcv_zc_safefunction xsk_rcv_zcfunction xsk_copy_xdpfunction __xsk_rcvfunction xsk_tx_writeablefunction __xsk_tx_releasefunction xsk_is_boundfunction xsk_dev_queue_validfunction xsk_rcv_checkfunction xsk_flushfunction xsk_generic_rcvfunction xsk_rcvfunction __xsk_map_redirectfunction __xsk_map_flushfunction list_for_each_entry_safefunction xsk_tx_completedfunction xsk_tx_releasefunction xsk_tx_peek_descfunction xsk_tx_peek_release_fallbackfunction xsk_tx_peek_release_desc_batchfunction xsk_wakeupfunction xsk_cq_reserve_lockedfunction xsk_skb_destructor_is_addrfunction xsk_skb_destructor_get_addrfunction xsk_skb_destructor_set_addrfunction xsk_inc_num_descfunction xsk_get_num_descfunction xsk_cq_submit_addr_lockedfunction xsk_cq_cancel_lockedfunction xsk_destruct_skbfunction xsk_skb_init_miscfunction xsk_consume_skbfunction xsk_drop_skbfunction xsk_skb_metadatafunction __xsk_generic_xmit
Annotated Snippet
static const struct proto_ops xsk_proto_ops = {
.family = PF_XDP,
.owner = THIS_MODULE,
.release = xsk_release,
.bind = xsk_bind,
.connect = sock_no_connect,
.socketpair = sock_no_socketpair,
.accept = sock_no_accept,
.getname = sock_no_getname,
.poll = xsk_poll,
.ioctl = sock_no_ioctl,
.listen = sock_no_listen,
.shutdown = sock_no_shutdown,
.setsockopt = xsk_setsockopt,
.getsockopt_iter = xsk_getsockopt,
.sendmsg = xsk_sendmsg,
.recvmsg = xsk_recvmsg,
.mmap = xsk_mmap,
};
static void xsk_destruct(struct sock *sk)
{
struct xdp_sock *xs = xdp_sk(sk);
if (!sock_flag(sk, SOCK_DEAD))
return;
if (!xp_put_pool(xs->pool))
xdp_put_umem(xs->umem, !xs->pool);
}
static int xsk_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct xdp_sock *xs;
struct sock *sk;
if (!ns_capable(net->user_ns, CAP_NET_RAW))
return -EPERM;
if (sock->type != SOCK_RAW)
return -ESOCKTNOSUPPORT;
if (protocol)
return -EPROTONOSUPPORT;
sock->state = SS_UNCONNECTED;
sk = sk_alloc(net, PF_XDP, GFP_KERNEL, &xsk_proto, kern);
if (!sk)
return -ENOBUFS;
sock->ops = &xsk_proto_ops;
sock_init_data(sock, sk);
sk->sk_family = PF_XDP;
sk->sk_destruct = xsk_destruct;
sock_set_flag(sk, SOCK_RCU_FREE);
xs = xdp_sk(sk);
xs->state = XSK_READY;
xs->max_tx_budget = TX_BATCH_SIZE;
mutex_init(&xs->mutex);
INIT_LIST_HEAD(&xs->map_list);
spin_lock_init(&xs->map_list_lock);
mutex_lock(&net->xdp.lock);
sk_add_node_rcu(sk, &net->xdp.list);
mutex_unlock(&net->xdp.lock);
sock_prot_inuse_add(net, &xsk_proto, 1);
return 0;
}
static const struct net_proto_family xsk_family_ops = {
.family = PF_XDP,
.create = xsk_create,
.owner = THIS_MODULE,
};
static struct notifier_block xsk_netdev_notifier = {
.notifier_call = xsk_notifier,
};
static int __net_init xsk_net_init(struct net *net)
{
Annotation
- Immediate include surface: `linux/if_xdp.h`, `linux/init.h`, `linux/sched/mm.h`, `linux/sched/signal.h`, `linux/sched/task.h`, `linux/socket.h`, `linux/file.h`, `linux/uaccess.h`.
- Detected declarations: `struct xsk_addrs`, `struct xdp_umem_reg_v1`, `struct xdp_statistics_v1`, `function xsk_set_rx_need_wakeup`, `function xsk_set_tx_need_wakeup`, `function xsk_clear_rx_need_wakeup`, `function xsk_clear_tx_need_wakeup`, `function xsk_uses_need_wakeup`, `function __xsk_clear_pool_at_qid`, `function xsk_clear_pool_at_qid`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern 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.