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>
25 #include <asm/uaccess.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/slab.h>
30 #include <linux/errno.h>
32 #include <linux/netdevice.h>
33 #include <linux/net.h>
34 #include <linux/init.h>
35 #include <linux/if_pppox.h>
37 #include <linux/ppp_defs.h>
38 #include <linux/if_ppp.h>
39 #include <linux/ppp_channel.h>
41 static struct pppox_proto *proto[PX_MAX_PROTO+1];
43 int register_pppox_proto(int proto_num, struct pppox_proto *pp)
45 if (proto_num < 0 || proto_num > PX_MAX_PROTO) {
54 proto[proto_num] = pp;
58 void unregister_pppox_proto(int proto_num)
60 if (proto_num >= 0 && proto_num <= PX_MAX_PROTO) {
61 proto[proto_num] = NULL;
66 void pppox_unbind_sock(struct sock *sk)
68 /* Clear connection to ppp device, if attached. */
70 if (sk->state & (PPPOX_BOUND|PPPOX_ZOMBIE)) {
71 ppp_unregister_channel(&sk->protinfo.pppox->chan);
72 sk->state = PPPOX_DEAD;
76 EXPORT_SYMBOL(register_pppox_proto);
77 EXPORT_SYMBOL(unregister_pppox_proto);
78 EXPORT_SYMBOL(pppox_unbind_sock);
80 static int pppox_ioctl(struct socket* sock, unsigned int cmd,
83 struct sock *sk = sock->sk;
87 po = sk->protinfo.pppox;
95 if (!(sk->state & PPPOX_CONNECTED))
99 index = ppp_channel_index(&po->chan);
100 if (put_user(index , (int *) arg))
104 sk->state |= PPPOX_BOUND;
108 if (proto[sk->protocol]->ioctl)
109 err = (*proto[sk->protocol]->ioctl)(sock, cmd, arg);
119 static int pppox_create(struct socket *sock, int protocol)
123 if (protocol < 0 || protocol > PX_MAX_PROTO)
126 if (proto[protocol] == NULL)
127 return -EPROTONOSUPPORT;
129 err = (*proto[protocol]->create)(sock);
132 /* We get to set the ioctl handler. */
133 /* For everything else, pppox is just a shell. */
134 sock->ops->ioctl = pppox_ioctl;
140 static struct net_proto_family pppox_proto_family = {
145 static int __init pppox_init(void)
149 err = sock_register(&pppox_proto_family);
154 static void __exit pppox_exit(void)
156 sock_unregister(PF_PPPOX);
159 module_init(pppox_init);
160 module_exit(pppox_exit);
162 MODULE_AUTHOR("Michal Ostrowski <mostrows@speakeasy.net>");
163 MODULE_DESCRIPTION("PPP over Ethernet driver (generic socket layer)");
164 MODULE_LICENSE("GPL");