0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/string.h>
0018 #include <linux/module.h>
0019 #include <linux/kernel.h>
0020 #include <linux/compat.h>
0021 #include <linux/errno.h>
0022 #include <linux/netdevice.h>
0023 #include <linux/net.h>
0024 #include <linux/init.h>
0025 #include <linux/if_pppox.h>
0026 #include <linux/ppp_defs.h>
0027 #include <linux/ppp-ioctl.h>
0028 #include <linux/ppp_channel.h>
0029 #include <linux/kmod.h>
0030
0031 #include <net/sock.h>
0032
0033 #include <linux/uaccess.h>
0034
0035 static const struct pppox_proto *pppox_protos[PX_MAX_PROTO + 1];
0036
0037 int register_pppox_proto(int proto_num, const struct pppox_proto *pp)
0038 {
0039 if (proto_num < 0 || proto_num > PX_MAX_PROTO)
0040 return -EINVAL;
0041 if (pppox_protos[proto_num])
0042 return -EALREADY;
0043 pppox_protos[proto_num] = pp;
0044 return 0;
0045 }
0046
0047 void unregister_pppox_proto(int proto_num)
0048 {
0049 if (proto_num >= 0 && proto_num <= PX_MAX_PROTO)
0050 pppox_protos[proto_num] = NULL;
0051 }
0052
0053 void pppox_unbind_sock(struct sock *sk)
0054 {
0055
0056
0057 if (sk->sk_state & (PPPOX_BOUND | PPPOX_CONNECTED)) {
0058 ppp_unregister_channel(&pppox_sk(sk)->chan);
0059 sk->sk_state = PPPOX_DEAD;
0060 }
0061 }
0062
0063 EXPORT_SYMBOL(register_pppox_proto);
0064 EXPORT_SYMBOL(unregister_pppox_proto);
0065 EXPORT_SYMBOL(pppox_unbind_sock);
0066
0067 int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
0068 {
0069 struct sock *sk = sock->sk;
0070 struct pppox_sock *po = pppox_sk(sk);
0071 int rc;
0072
0073 lock_sock(sk);
0074
0075 switch (cmd) {
0076 case PPPIOCGCHAN: {
0077 int index;
0078 rc = -ENOTCONN;
0079 if (!(sk->sk_state & PPPOX_CONNECTED))
0080 break;
0081
0082 rc = -EINVAL;
0083 index = ppp_channel_index(&po->chan);
0084 if (put_user(index , (int __user *) arg))
0085 break;
0086
0087 rc = 0;
0088 sk->sk_state |= PPPOX_BOUND;
0089 break;
0090 }
0091 default:
0092 rc = pppox_protos[sk->sk_protocol]->ioctl ?
0093 pppox_protos[sk->sk_protocol]->ioctl(sock, cmd, arg) : -ENOTTY;
0094 }
0095
0096 release_sock(sk);
0097 return rc;
0098 }
0099
0100 EXPORT_SYMBOL(pppox_ioctl);
0101
0102 #ifdef CONFIG_COMPAT
0103 int pppox_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
0104 {
0105 if (cmd == PPPOEIOCSFWD32)
0106 cmd = PPPOEIOCSFWD;
0107
0108 return pppox_ioctl(sock, cmd, (unsigned long)compat_ptr(arg));
0109 }
0110
0111 EXPORT_SYMBOL(pppox_compat_ioctl);
0112 #endif
0113
0114 static int pppox_create(struct net *net, struct socket *sock, int protocol,
0115 int kern)
0116 {
0117 int rc = -EPROTOTYPE;
0118
0119 if (protocol < 0 || protocol > PX_MAX_PROTO)
0120 goto out;
0121
0122 rc = -EPROTONOSUPPORT;
0123 if (!pppox_protos[protocol])
0124 request_module("net-pf-%d-proto-%d", PF_PPPOX, protocol);
0125 if (!pppox_protos[protocol] ||
0126 !try_module_get(pppox_protos[protocol]->owner))
0127 goto out;
0128
0129 rc = pppox_protos[protocol]->create(net, sock, kern);
0130
0131 module_put(pppox_protos[protocol]->owner);
0132 out:
0133 return rc;
0134 }
0135
0136 static const struct net_proto_family pppox_proto_family = {
0137 .family = PF_PPPOX,
0138 .create = pppox_create,
0139 .owner = THIS_MODULE,
0140 };
0141
0142 static int __init pppox_init(void)
0143 {
0144 return sock_register(&pppox_proto_family);
0145 }
0146
0147 static void __exit pppox_exit(void)
0148 {
0149 sock_unregister(PF_PPPOX);
0150 }
0151
0152 module_init(pppox_init);
0153 module_exit(pppox_exit);
0154
0155 MODULE_AUTHOR("Michal Ostrowski <mostrows@speakeasy.net>");
0156 MODULE_DESCRIPTION("PPP over Ethernet driver (generic socket layer)");
0157 MODULE_LICENSE("GPL");
0158 MODULE_ALIAS_NETPROTO(PF_PPPOX);