net/unix/garbage.c
Source file repositories/reference/linux-study-clean/net/unix/garbage.c
File Facts
- System
- Linux kernel
- Corpus path
net/unix/garbage.c- Extension
.c- Size
- 16807 bytes
- Lines
- 660
- 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/fs.hlinux/list.hlinux/skbuff.hlinux/socket.hlinux/workqueue.hnet/af_unix.hnet/scm.hnet/tcp_states.haf_unix.h
Detected Declarations
struct unix_vertexstruct unix_edgeenum unix_vertex_indexfunction unix_update_graphfunction unix_add_edgefunction unix_del_edgefunction unix_free_verticesfunction list_for_each_entry_safefunction unix_add_edgesfunction unix_del_edgesfunction unix_update_edgesfunction unix_prepare_fplfunction unix_destroy_fplfunction unix_peek_fplfunction unix_vertex_deadfunction list_for_each_entryfunction unix_scc_deadfunction list_for_each_entry_reversefunction unix_collect_skbfunction list_for_each_entry_reversefunction skb_queue_walkfunction unix_scc_cyclicfunction __unix_walk_sccfunction unix_walk_sccfunction __unix_walk_sccfunction unix_walk_scc_fastfunction unix_gcfunction skb_queue_walkfunction unix_schedule_gc
Annotated Snippet
const struct proto_ops *ops;
struct sock *sk = sock->sk;
ops = READ_ONCE(sock->ops);
/* PF_UNIX ? */
if (sk && ops && ops->family == PF_UNIX)
return unix_sk(sk);
}
return NULL;
}
static struct unix_vertex *unix_edge_successor(struct unix_edge *edge)
{
/* If an embryo socket has a fd,
* the listener indirectly holds the fd's refcnt.
*/
if (edge->successor->listener)
return unix_sk(edge->successor->listener)->vertex;
return edge->successor->vertex;
}
enum {
UNIX_GRAPH_NOT_CYCLIC,
UNIX_GRAPH_MAYBE_CYCLIC,
UNIX_GRAPH_CYCLIC,
};
static unsigned char unix_graph_state;
static void unix_update_graph(struct unix_vertex *vertex)
{
/* If the receiver socket is not inflight, no cyclic
* reference could be formed.
*/
if (!vertex)
return;
WRITE_ONCE(unix_graph_state, UNIX_GRAPH_MAYBE_CYCLIC);
}
static LIST_HEAD(unix_unvisited_vertices);
enum unix_vertex_index {
UNIX_VERTEX_INDEX_MARK1,
UNIX_VERTEX_INDEX_MARK2,
UNIX_VERTEX_INDEX_START,
};
static unsigned long unix_vertex_unvisited_index = UNIX_VERTEX_INDEX_MARK1;
static unsigned long unix_vertex_max_scc_index = UNIX_VERTEX_INDEX_START;
static void unix_add_edge(struct scm_fp_list *fpl, struct unix_edge *edge)
{
struct unix_vertex *vertex = edge->predecessor->vertex;
if (!vertex) {
vertex = list_first_entry(&fpl->vertices, typeof(*vertex), entry);
vertex->index = unix_vertex_unvisited_index;
vertex->scc_index = ++unix_vertex_max_scc_index;
vertex->out_degree = 0;
INIT_LIST_HEAD(&vertex->edges);
INIT_LIST_HEAD(&vertex->scc_entry);
list_move_tail(&vertex->entry, &unix_unvisited_vertices);
edge->predecessor->vertex = vertex;
}
vertex->out_degree++;
list_add_tail(&edge->vertex_entry, &vertex->edges);
unix_update_graph(unix_edge_successor(edge));
}
static void unix_del_edge(struct scm_fp_list *fpl, struct unix_edge *edge)
{
struct unix_vertex *vertex = edge->predecessor->vertex;
if (!fpl->dead)
unix_update_graph(unix_edge_successor(edge));
list_del(&edge->vertex_entry);
vertex->out_degree--;
if (!vertex->out_degree) {
edge->predecessor->vertex = NULL;
list_move_tail(&vertex->entry, &fpl->vertices);
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/list.h`, `linux/skbuff.h`, `linux/socket.h`, `linux/workqueue.h`, `net/af_unix.h`, `net/scm.h`, `net/tcp_states.h`.
- Detected declarations: `struct unix_vertex`, `struct unix_edge`, `enum unix_vertex_index`, `function unix_update_graph`, `function unix_add_edge`, `function unix_del_edge`, `function unix_free_vertices`, `function list_for_each_entry_safe`, `function unix_add_edges`, `function unix_del_edges`.
- 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.