net/phonet/pn_dev.c
Source file repositories/reference/linux-study-clean/net/phonet/pn_dev.c
File Facts
- System
- Linux kernel
- Corpus path
net/phonet/pn_dev.c- Extension
.c- Size
- 9942 bytes
- Lines
- 442
- 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/kernel.hlinux/net.hlinux/slab.hlinux/netdevice.hlinux/phonet.hlinux/proc_fs.hlinux/if_arp.hnet/sock.hnet/netns/generic.hnet/phonet/pn_dev.h
Detected Declarations
struct phonet_routesstruct phonet_netfunction list_for_each_entryfunction list_for_each_entry_rcufunction phonet_device_destroyfunction phonet_address_addfunction phonet_address_delfunction phonet_address_getfunction phonet_address_lookupfunction phonet_device_autoconffunction phonet_route_autodelfunction phonet_device_notifyfunction phonet_init_netfunction phonet_exit_netfunction phonet_device_initfunction phonet_device_exitfunction phonet_route_addfunction phonet_route_del
Annotated Snippet
struct phonet_routes {
spinlock_t lock;
struct net_device __rcu *table[64];
};
struct phonet_net {
struct phonet_device_list pndevs;
struct phonet_routes routes;
};
static unsigned int phonet_net_id __read_mostly;
static struct phonet_net *phonet_pernet(struct net *net)
{
return net_generic(net, phonet_net_id);
}
struct phonet_device_list *phonet_device_list(struct net *net)
{
struct phonet_net *pnn = phonet_pernet(net);
return &pnn->pndevs;
}
/* Allocate new Phonet device. */
static struct phonet_device *__phonet_device_alloc(struct net_device *dev)
{
struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
struct phonet_device *pnd = kmalloc_obj(*pnd, GFP_ATOMIC);
if (pnd == NULL)
return NULL;
pnd->netdev = dev;
bitmap_zero(pnd->addrs, 64);
lockdep_assert_held(&pndevs->lock);
list_add_rcu(&pnd->list, &pndevs->list);
return pnd;
}
static struct phonet_device *__phonet_get(struct net_device *dev)
{
struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
struct phonet_device *pnd;
lockdep_assert_held(&pndevs->lock);
list_for_each_entry(pnd, &pndevs->list, list) {
if (pnd->netdev == dev)
return pnd;
}
return NULL;
}
static struct phonet_device *__phonet_get_rcu(struct net_device *dev)
{
struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
struct phonet_device *pnd;
list_for_each_entry_rcu(pnd, &pndevs->list, list) {
if (pnd->netdev == dev)
return pnd;
}
return NULL;
}
static void phonet_device_destroy(struct net_device *dev)
{
struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
struct phonet_device *pnd;
ASSERT_RTNL();
spin_lock(&pndevs->lock);
pnd = __phonet_get(dev);
if (pnd)
list_del_rcu(&pnd->list);
spin_unlock(&pndevs->lock);
if (pnd) {
struct net *net = dev_net(dev);
u32 ifindex = dev->ifindex;
u8 addr;
for_each_set_bit(addr, pnd->addrs, 64)
phonet_address_notify(net, RTM_DELADDR, ifindex, addr);
kfree_rcu(pnd, rcu);
}
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/net.h`, `linux/slab.h`, `linux/netdevice.h`, `linux/phonet.h`, `linux/proc_fs.h`, `linux/if_arp.h`, `net/sock.h`.
- Detected declarations: `struct phonet_routes`, `struct phonet_net`, `function list_for_each_entry`, `function list_for_each_entry_rcu`, `function phonet_device_destroy`, `function phonet_address_add`, `function phonet_address_del`, `function phonet_address_get`, `function phonet_address_lookup`, `function phonet_device_autoconf`.
- 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.