drivers/net/ppp/pptp.c
Source file repositories/reference/linux-study-clean/drivers/net/ppp/pptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ppp/pptp.c- Extension
.c- Size
- 16220 bytes
- Lines
- 705
- 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.
- 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/string.hlinux/module.hlinux/kernel.hlinux/slab.hlinux/errno.hlinux/netdevice.hlinux/net.hlinux/skbuff.hlinux/vmalloc.hlinux/init.hlinux/ppp_channel.hlinux/ppp_defs.hlinux/if_pppox.hlinux/ppp-ioctl.hlinux/notifier.hlinux/file.hlinux/in.hlinux/ip.hlinux/rcupdate.hlinux/security.hlinux/spinlock.hnet/sock.hnet/protocol.hnet/ip.hnet/icmp.hnet/route.hnet/gre.hnet/pptp.hlinux/uaccess.h
Detected Declarations
function lookup_chan_dstfunction add_chanfunction del_chanfunction pptp_xmitfunction pptp_rcv_corefunction pptp_rcvfunction pptp_bindfunction pptp_connectfunction pptp_getnamefunction pptp_releasefunction pptp_sock_destructfunction pptp_createfunction pptp_ppp_ioctlfunction pptp_init_modulefunction pptp_exit_modulemodule init pptp_init_module
Annotated Snippet
static const struct proto_ops pptp_ops;
static struct pppox_sock *lookup_chan(u16 call_id, __be32 s_addr)
{
struct pppox_sock *sock;
struct pptp_opt *opt;
rcu_read_lock();
sock = rcu_dereference(callid_sock[call_id]);
if (sock) {
opt = &sock->proto.pptp;
if (opt->dst_addr.sin_addr.s_addr != s_addr)
sock = NULL;
else
sock_hold(&sock->sk);
}
rcu_read_unlock();
return sock;
}
static int lookup_chan_dst(u16 call_id, __be32 d_addr)
{
struct pppox_sock *sock;
struct pptp_opt *opt;
int i;
rcu_read_lock();
i = 1;
for_each_set_bit_from(i, callid_bitmap, MAX_CALLID) {
sock = rcu_dereference(callid_sock[i]);
if (!sock)
continue;
opt = &sock->proto.pptp;
if (opt->dst_addr.call_id == call_id &&
opt->dst_addr.sin_addr.s_addr == d_addr)
break;
}
rcu_read_unlock();
return i < MAX_CALLID;
}
static int add_chan(struct pppox_sock *sock,
struct pptp_addr *sa)
{
static int call_id;
spin_lock(&chan_lock);
if (!sa->call_id) {
call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, call_id + 1);
if (call_id == MAX_CALLID) {
call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, 1);
if (call_id == MAX_CALLID)
goto out_err;
}
sa->call_id = call_id;
} else if (test_bit(sa->call_id, callid_bitmap)) {
goto out_err;
}
sock->proto.pptp.src_addr = *sa;
set_bit(sa->call_id, callid_bitmap);
rcu_assign_pointer(callid_sock[sa->call_id], sock);
spin_unlock(&chan_lock);
return 0;
out_err:
spin_unlock(&chan_lock);
return -1;
}
static void del_chan(struct pppox_sock *sock)
{
spin_lock(&chan_lock);
clear_bit(sock->proto.pptp.src_addr.call_id, callid_bitmap);
RCU_INIT_POINTER(callid_sock[sock->proto.pptp.src_addr.call_id], NULL);
spin_unlock(&chan_lock);
}
static struct rtable *pptp_route_output(const struct pppox_sock *po,
struct flowi4 *fl4)
{
const struct sock *sk = &po->sk;
struct net *net;
net = sock_net(sk);
flowi4_init_output(fl4, sk->sk_bound_dev_if, sk->sk_mark, 0,
RT_SCOPE_UNIVERSE, IPPROTO_GRE, 0,
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/skbuff.h`.
- Detected declarations: `function lookup_chan_dst`, `function add_chan`, `function del_chan`, `function pptp_xmit`, `function pptp_rcv_core`, `function pptp_rcv`, `function pptp_bind`, `function pptp_connect`, `function pptp_getname`, `function pptp_release`.
- 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.