net/psp/psp_sock.c
Source file repositories/reference/linux-study-clean/net/psp/psp_sock.c
File Facts
- System
- Linux kernel
- Corpus path
net/psp/psp_sock.c- Extension
.c- Size
- 6619 bytes
- Lines
- 294
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- 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/file.hlinux/net.hlinux/rcupdate.hlinux/tcp.hnet/ip.hnet/psp.hpsp.h
Detected Declarations
function psp_validate_xmitfunction psp_dev_tx_key_addfunction psp_dev_tx_key_delfunction psp_assoc_freefunction psp_assoc_free_queuefunction psp_assoc_putfunction psp_sk_assoc_freefunction psp_sock_assoc_set_rxfunction psp_sock_recv_queue_checkfunction skb_rbtree_walkfunction skb_queue_walkfunction psp_sock_assoc_set_txfunction psp_assocs_key_rotatedfunction psp_twsk_initfunction psp_twsk_assoc_freefunction psp_reply_set_decrypted
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/file.h>
#include <linux/net.h>
#include <linux/rcupdate.h>
#include <linux/tcp.h>
#include <net/ip.h>
#include <net/psp.h>
#include "psp.h"
struct psp_dev *psp_dev_get_for_sock(struct sock *sk)
{
struct psp_dev *psd = NULL;
struct dst_entry *dst;
rcu_read_lock();
dst = __sk_dst_get(sk);
if (dst) {
psd = rcu_dereference(dst_dev_rcu(dst)->psp_dev);
if (psd && !psp_dev_tryget(psd))
psd = NULL;
}
rcu_read_unlock();
return psd;
}
static struct sk_buff *
psp_validate_xmit(struct sock *sk, struct net_device *dev, struct sk_buff *skb)
{
struct psp_assoc *pas;
bool good;
rcu_read_lock();
pas = psp_skb_get_assoc_rcu(skb);
good = !pas || rcu_access_pointer(dev->psp_dev) == pas->psd;
rcu_read_unlock();
if (!good) {
sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PSP_OUTPUT);
return NULL;
}
return skb;
}
struct psp_assoc *psp_assoc_create(struct psp_dev *psd)
{
struct psp_assoc *pas;
lockdep_assert_held(&psd->lock);
pas = kzalloc_flex(*pas, drv_data, psd->caps->assoc_drv_spc,
GFP_KERNEL_ACCOUNT);
if (!pas)
return NULL;
pas->psd = psd;
pas->dev_id = psd->id;
pas->generation = psd->generation;
psp_dev_get(psd);
refcount_set(&pas->refcnt, 1);
list_add_tail(&pas->assocs_list, &psd->active_assocs);
return pas;
}
static struct psp_assoc *psp_assoc_dummy(struct psp_assoc *pas)
{
struct psp_dev *psd = pas->psd;
size_t sz;
lockdep_assert_held(&psd->lock);
sz = struct_size(pas, drv_data, psd->caps->assoc_drv_spc);
return kmemdup(pas, sz, GFP_KERNEL);
}
static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,
struct netlink_ext_ack *extack)
{
return psd->ops->tx_key_add(psd, pas, extack);
}
void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas)
{
if (pas->tx.spi)
psd->ops->tx_key_del(psd, pas);
list_del(&pas->assocs_list);
Annotation
- Immediate include surface: `linux/file.h`, `linux/net.h`, `linux/rcupdate.h`, `linux/tcp.h`, `net/ip.h`, `net/psp.h`, `psp.h`.
- Detected declarations: `function psp_validate_xmit`, `function psp_dev_tx_key_add`, `function psp_dev_tx_key_del`, `function psp_assoc_free`, `function psp_assoc_free_queue`, `function psp_assoc_put`, `function psp_sk_assoc_free`, `function psp_sock_assoc_set_rx`, `function psp_sock_recv_queue_check`, `function skb_rbtree_walk`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.