drivers/net/ppp/pppoe.c
Source file repositories/reference/linux-study-clean/drivers/net/ppp/pppoe.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ppp/pppoe.c- Extension
.c- Size
- 31272 bytes
- Lines
- 1312
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/string.hlinux/module.hlinux/kernel.hlinux/slab.hlinux/errno.hlinux/netdevice.hlinux/net.hlinux/inetdevice.hlinux/etherdevice.hlinux/skbuff.hlinux/init.hlinux/if_ether.hlinux/if_pppox.hlinux/ppp_channel.hlinux/ppp_defs.hlinux/ppp-ioctl.hlinux/notifier.hlinux/file.hlinux/proc_fs.hlinux/seq_file.hlinux/nsproxy.hnet/net_namespace.hnet/netns/generic.hnet/sock.hnet/gro.hlinux/uaccess.h
Detected Declarations
struct pppoe_netfunction stage_sessionfunction cmp_2_addrfunction cmp_addrfunction hash_itemfunction __set_itemfunction __delete_itemfunction delete_itemfunction pppoe_flush_devfunction pppoe_device_eventfunction pppoe_rcv_corefunction pppoe_rcvfunction pppoe_unbind_sock_workfunction pppoe_disc_rcvfunction pppoe_destructfunction pppoe_createfunction pppoe_releasefunction pppoe_connectfunction pppoe_getnamefunction pppoe_ioctlfunction pppoe_sendmsgfunction __pppoe_xmitfunction pppoe_xmitfunction pppoe_fill_forward_pathfunction pppoe_recvmsgfunction pppoe_seq_showfunction pppoe_seq_stopfunction pppoe_init_netfunction pppoe_exit_netfunction compare_pppoe_headerfunction pppoe_hdr_protofunction list_for_each_entryfunction pppoe_gro_completefunction pppoe_initfunction pppoe_exitmodule init pppoe_init
Annotated Snippet
static const struct proto_ops pppoe_ops;
static const struct ppp_channel_ops pppoe_chan_ops;
/* per-net private data for this module */
static unsigned int pppoe_net_id __read_mostly;
struct pppoe_net {
/*
* we could use _single_ hash table for all
* nets by injecting net id into the hash but
* it would increase hash chains and add
* a few additional math comparisons messy
* as well, moreover in case of SMP less locking
* controversy here
*/
struct pppox_sock __rcu *hash_table[PPPOE_HASH_SIZE];
spinlock_t hash_lock;
};
/*
* PPPoE could be in the following stages:
* 1) Discovery stage (to obtain remote MAC and Session ID)
* 2) Session stage (MAC and SID are known)
*
* Ethernet frames have a special tag for this but
* we use simpler approach based on session id
*/
static inline bool stage_session(__be16 sid)
{
return sid != 0;
}
static inline struct pppoe_net *pppoe_pernet(struct net *net)
{
return net_generic(net, pppoe_net_id);
}
static inline int cmp_2_addr(struct pppoe_addr *a, struct pppoe_addr *b)
{
return a->sid == b->sid && ether_addr_equal(a->remote, b->remote);
}
static inline int cmp_addr(struct pppoe_addr *a, __be16 sid, char *addr)
{
return a->sid == sid && ether_addr_equal(a->remote, addr);
}
#if 8 % PPPOE_HASH_BITS
#error 8 must be a multiple of PPPOE_HASH_BITS
#endif
static u8 hash_item(__be16 sid, const u8 addr[ETH_ALEN])
{
const u16 *addr16 = (const u16 *)addr;
unsigned int i;
u16 hash16;
u8 hash;
hash16 = addr16[0] ^ addr16[1] ^ addr16[2] ^ (__force u16)sid;
hash = (hash16 >> 8) ^ hash16;
for (i = 8; (i >>= 1) >= PPPOE_HASH_BITS;)
hash ^= hash >> i;
return hash & PPPOE_HASH_MASK;
}
/**********************************************************************
*
* Set/get/delete/rehash items (internal versions)
*
**********************************************************************/
static struct pppox_sock *__get_item(struct pppoe_net *pn, __be16 sid,
unsigned char *addr, int ifindex)
{
int hash = hash_item(sid, addr);
struct pppox_sock *ret;
ret = rcu_dereference(pn->hash_table[hash]);
while (ret) {
if (cmp_addr(&ret->pppoe_pa, sid, addr) &&
ret->pppoe_ifindex == ifindex)
return ret;
ret = rcu_dereference(ret->next);
}
return NULL;
}
static int __set_item(struct pppoe_net *pn, struct pppox_sock *po)
{
Annotation
- Immediate include surface: `linux/string.h`, `linux/module.h`, `linux/kernel.h`, `linux/slab.h`, `linux/errno.h`, `linux/netdevice.h`, `linux/net.h`, `linux/inetdevice.h`.
- Detected declarations: `struct pppoe_net`, `function stage_session`, `function cmp_2_addr`, `function cmp_addr`, `function hash_item`, `function __set_item`, `function __delete_item`, `function delete_item`, `function pppoe_flush_dev`, `function pppoe_device_event`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.