1 /** -*- linux-c -*- ***********************************************************
2 * Linux PPP over X/Ethernet (PPPoX/PPPoE) Sockets
4 * PPPoX --- Generic PPP encapsulation socket family
5 * PPPoE --- PPP over Ethernet (RFC 2516)
10 * Author: Michal Ostrowski <mostrows@speakeasy.net>
12 * 051000 : Initialization cleanup
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
22 #include <linux/string.h>
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/compat.h>
26 #include <linux/errno.h>
27 #include <linux/netdevice.h>
28 #include <linux/net.h>
29 #include <linux/init.h>
30 #include <linux/if_pppox.h>
31 #include <linux/ppp_defs.h>
32 #include <linux/ppp-ioctl.h>
33 #include <linux/ppp_channel.h>
34 #include <linux/kmod.h>
38 #include <linux/uaccess.h>
40 static const struct pppox_proto *pppox_protos[PX_MAX_PROTO + 1];
42 int register_pppox_proto(int proto_num, const struct pppox_proto *pp)
44 if (proto_num < 0 || proto_num > PX_MAX_PROTO)
46 if (pppox_protos[proto_num])
48 pppox_protos[proto_num] = pp;
52 void unregister_pppox_proto(int proto_num)
54 if (proto_num >= 0 && proto_num <= PX_MAX_PROTO)
55 pppox_protos[proto_num] = NULL;
58 void pppox_unbind_sock(struct sock *sk)
60 /* Clear connection to ppp device, if attached. */
62 if (sk->sk_state & (PPPOX_BOUND | PPPOX_CONNECTED)) {
63 ppp_unregister_channel(&pppox_sk(sk)->chan);
64 sk->sk_state = PPPOX_DEAD;
68 EXPORT_SYMBOL(register_pppox_proto);
69 EXPORT_SYMBOL(unregister_pppox_proto);
70 EXPORT_SYMBOL(pppox_unbind_sock);
72 int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
74 struct sock *sk = sock->sk;
75 struct pppox_sock *po = pppox_sk(sk);
84 if (!(sk->sk_state & PPPOX_CONNECTED))
88 index = ppp_channel_index(&po->chan);
89 if (put_user(index , (int __user *) arg))
93 sk->sk_state |= PPPOX_BOUND;
97 rc = pppox_protos[sk->sk_protocol]->ioctl ?
98 pppox_protos[sk->sk_protocol]->ioctl(sock, cmd, arg) : -ENOTTY;
105 EXPORT_SYMBOL(pppox_ioctl);
108 int pppox_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
110 if (cmd == PPPOEIOCSFWD32)
113 return pppox_ioctl(sock, cmd, (unsigned long)compat_ptr(arg));
116 EXPORT_SYMBOL(pppox_compat_ioctl);
119 static int pppox_create(struct net *net, struct socket *sock, int protocol,
122 int rc = -EPROTOTYPE;
124 if (protocol < 0 || protocol > PX_MAX_PROTO)
127 rc = -EPROTONOSUPPORT;
128 if (!pppox_protos[protocol])
129 request_module("net-pf-%d-proto-%d", PF_PPPOX, protocol);
130 if (!pppox_protos[protocol] ||
131 !try_module_get(pppox_protos[protocol]->owner))
134 rc = pppox_protos[protocol]->create(net, sock, kern);
136 module_put(pppox_protos[protocol]->owner);
141 static const struct net_proto_family pppox_proto_family = {
143 .create = pppox_create,
144 .owner = THIS_MODULE,
147 static int __init pppox_init(void)
149 return sock_register(&pppox_proto_family);
152 static void __exit pppox_exit(void)
154 sock_unregister(PF_PPPOX);
157 module_init(pppox_init);
158 module_exit(pppox_exit);
160 MODULE_AUTHOR("Michal Ostrowski <mostrows@speakeasy.net>");
161 MODULE_DESCRIPTION("PPP over Ethernet driver (generic socket layer)");
162 MODULE_LICENSE("GPL");
163 MODULE_ALIAS_NETPROTO(PF_PPPOX);