net/core/neighbour.c
Source file repositories/reference/linux-study-clean/net/core/neighbour.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/neighbour.c- Extension
.c- Size
- 100894 bytes
- Lines
- 3962
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/slab.hlinux/types.hlinux/kernel.hlinux/module.hlinux/socket.hlinux/netdevice.hlinux/proc_fs.hlinux/sysctl.hlinux/times.hnet/net_namespace.hnet/neighbour.hnet/arp.hnet/dst.hnet/ip.hnet/sock.hnet/netevent.hnet/netlink.hlinux/rtnetlink.hlinux/random.hlinux/string.hlinux/log2.hlinux/inetdevice.hnet/addrconf.htrace/events/neigh.h
Detected Declarations
struct neigh_dump_filterfunction neigh_blackholefunction neigh_cleanup_and_releasefunction intervalfunction neigh_mark_deadfunction neigh_update_gc_listfunction neigh_update_managed_listfunction neigh_update_flagsfunction neigh_remove_onefunction neigh_forced_gcfunction list_for_each_entry_safefunction neigh_add_timerfunction neigh_del_timerfunction neigh_parms_qlen_decfunction pneigh_queue_purgefunction neigh_flush_onefunction neigh_flush_devfunction hlist_for_each_entry_safefunction neigh_flush_tablefunction neigh_changeaddrfunction __neigh_ifdownfunction neigh_carrier_downfunction neigh_ifdownfunction time_afterfunction neigh_get_hash_rndfunction neigh_hash_free_rcufunction neigh_for_each_in_bucket_safefunction ___neigh_createfunction neigh_for_each_in_bucketfunction pneigh_hashfunction pneigh_createfunction pneigh_destroyfunction pneigh_deletefunction pneigh_ifdownfunction neigh_parms_putfunction neigh_destroyfunction neigh_suspectfunction neigh_connectfunction neigh_periodic_workfunction neigh_for_each_in_bucket_safefunction neigh_max_probesfunction neigh_invalidatefunction neigh_probefunction neigh_timer_handlerfunction NEIGH_VARfunction __neigh_event_sendfunction neigh_update_hhsfunction neigh_update_process_arp_queue
Annotated Snippet
const struct net_device_ops *ops = dev->netdev_ops;
p = kmemdup(&tbl->parms, sizeof(*p), GFP_KERNEL);
if (p) {
p->tbl = tbl;
refcount_set(&p->refcnt, 1);
neigh_set_reach_time(p);
p->qlen = 0;
netdev_hold(dev, &p->dev_tracker, GFP_KERNEL);
p->dev = dev;
write_pnet(&p->net, net);
p->sysctl_table = NULL;
if (ops->ndo_neigh_setup && ops->ndo_neigh_setup(dev, p)) {
netdev_put(dev, &p->dev_tracker);
kfree(p);
return NULL;
}
spin_lock_bh(&tbl->lock);
list_add_rcu(&p->list, &tbl->parms.list);
spin_unlock_bh(&tbl->lock);
neigh_parms_data_state_cleanall(p);
}
return p;
}
EXPORT_SYMBOL(neigh_parms_alloc);
static void neigh_rcu_free_parms(struct rcu_head *head)
{
struct neigh_parms *parms =
container_of(head, struct neigh_parms, rcu_head);
neigh_parms_put(parms);
}
void neigh_parms_release(struct neigh_table *tbl, struct neigh_parms *parms)
{
if (!parms || parms == &tbl->parms)
return;
spin_lock_bh(&tbl->lock);
list_del_rcu(&parms->list);
parms->dead = 1;
spin_unlock_bh(&tbl->lock);
netdev_put(parms->dev, &parms->dev_tracker);
call_rcu(&parms->rcu_head, neigh_rcu_free_parms);
}
EXPORT_SYMBOL(neigh_parms_release);
static struct lock_class_key neigh_table_proxy_queue_class;
static struct neigh_table __rcu *neigh_tables[NEIGH_NR_TABLES] __read_mostly;
void neigh_table_init(int index, struct neigh_table *tbl)
{
unsigned long now = jiffies;
unsigned long phsize;
INIT_LIST_HEAD(&tbl->parms_list);
INIT_LIST_HEAD(&tbl->gc_list);
INIT_LIST_HEAD(&tbl->managed_list);
list_add(&tbl->parms.list, &tbl->parms_list);
write_pnet(&tbl->parms.net, &init_net);
refcount_set(&tbl->parms.refcnt, 1);
neigh_set_reach_time(&tbl->parms);
tbl->parms.qlen = 0;
tbl->stats = alloc_percpu(struct neigh_statistics);
if (!tbl->stats)
panic("cannot create neighbour cache statistics");
#ifdef CONFIG_PROC_FS
if (!proc_create_seq_data(tbl->id, 0, init_net.proc_net_stat,
&neigh_stat_seq_ops, tbl))
panic("cannot create neighbour proc dir entry");
#endif
RCU_INIT_POINTER(tbl->nht, neigh_hash_alloc(3));
phsize = (PNEIGH_HASHMASK + 1) * sizeof(struct pneigh_entry *);
tbl->phash_buckets = kzalloc(phsize, GFP_KERNEL);
if (!tbl->nht || !tbl->phash_buckets)
panic("cannot allocate neighbour cache hashes");
if (!tbl->entry_size)
Annotation
- Immediate include surface: `linux/slab.h`, `linux/types.h`, `linux/kernel.h`, `linux/module.h`, `linux/socket.h`, `linux/netdevice.h`, `linux/proc_fs.h`, `linux/sysctl.h`.
- Detected declarations: `struct neigh_dump_filter`, `function neigh_blackhole`, `function neigh_cleanup_and_release`, `function interval`, `function neigh_mark_dead`, `function neigh_update_gc_list`, `function neigh_update_managed_list`, `function neigh_update_flags`, `function neigh_remove_one`, `function neigh_forced_gc`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.