spi: sprd: adi: Add a reset reason for watchdog mode
[linux/fpc-iii.git] / drivers / net / ppp / pppox.c
blob5ef422a43d70b479e44991062cbdc03de9aa8951
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /** -*- linux-c -*- ***********************************************************
3 * Linux PPP over X/Ethernet (PPPoX/PPPoE) Sockets
5 * PPPoX --- Generic PPP encapsulation socket family
6 * PPPoE --- PPP over Ethernet (RFC 2516)
8 * Version: 0.5.2
10 * Author: Michal Ostrowski <mostrows@speakeasy.net>
12 * 051000 : Initialization cleanup
14 * License:
17 #include <linux/string.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/netdevice.h>
22 #include <linux/net.h>
23 #include <linux/init.h>
24 #include <linux/if_pppox.h>
25 #include <linux/ppp_defs.h>
26 #include <linux/ppp-ioctl.h>
27 #include <linux/ppp_channel.h>
28 #include <linux/kmod.h>
30 #include <net/sock.h>
32 #include <linux/uaccess.h>
34 static const struct pppox_proto *pppox_protos[PX_MAX_PROTO + 1];
36 int register_pppox_proto(int proto_num, const struct pppox_proto *pp)
38 if (proto_num < 0 || proto_num > PX_MAX_PROTO)
39 return -EINVAL;
40 if (pppox_protos[proto_num])
41 return -EALREADY;
42 pppox_protos[proto_num] = pp;
43 return 0;
46 void unregister_pppox_proto(int proto_num)
48 if (proto_num >= 0 && proto_num <= PX_MAX_PROTO)
49 pppox_protos[proto_num] = NULL;
52 void pppox_unbind_sock(struct sock *sk)
54 /* Clear connection to ppp device, if attached. */
56 if (sk->sk_state & (PPPOX_BOUND | PPPOX_CONNECTED)) {
57 ppp_unregister_channel(&pppox_sk(sk)->chan);
58 sk->sk_state = PPPOX_DEAD;
62 EXPORT_SYMBOL(register_pppox_proto);
63 EXPORT_SYMBOL(unregister_pppox_proto);
64 EXPORT_SYMBOL(pppox_unbind_sock);
66 int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
68 struct sock *sk = sock->sk;
69 struct pppox_sock *po = pppox_sk(sk);
70 int rc;
72 lock_sock(sk);
74 switch (cmd) {
75 case PPPIOCGCHAN: {
76 int index;
77 rc = -ENOTCONN;
78 if (!(sk->sk_state & PPPOX_CONNECTED))
79 break;
81 rc = -EINVAL;
82 index = ppp_channel_index(&po->chan);
83 if (put_user(index , (int __user *) arg))
84 break;
86 rc = 0;
87 sk->sk_state |= PPPOX_BOUND;
88 break;
90 default:
91 rc = pppox_protos[sk->sk_protocol]->ioctl ?
92 pppox_protos[sk->sk_protocol]->ioctl(sock, cmd, arg) : -ENOTTY;
95 release_sock(sk);
96 return rc;
99 EXPORT_SYMBOL(pppox_ioctl);
101 static int pppox_create(struct net *net, struct socket *sock, int protocol,
102 int kern)
104 int rc = -EPROTOTYPE;
106 if (protocol < 0 || protocol > PX_MAX_PROTO)
107 goto out;
109 rc = -EPROTONOSUPPORT;
110 if (!pppox_protos[protocol])
111 request_module("net-pf-%d-proto-%d", PF_PPPOX, protocol);
112 if (!pppox_protos[protocol] ||
113 !try_module_get(pppox_protos[protocol]->owner))
114 goto out;
116 rc = pppox_protos[protocol]->create(net, sock, kern);
118 module_put(pppox_protos[protocol]->owner);
119 out:
120 return rc;
123 static const struct net_proto_family pppox_proto_family = {
124 .family = PF_PPPOX,
125 .create = pppox_create,
126 .owner = THIS_MODULE,
129 static int __init pppox_init(void)
131 return sock_register(&pppox_proto_family);
134 static void __exit pppox_exit(void)
136 sock_unregister(PF_PPPOX);
139 module_init(pppox_init);
140 module_exit(pppox_exit);
142 MODULE_AUTHOR("Michal Ostrowski <mostrows@speakeasy.net>");
143 MODULE_DESCRIPTION("PPP over Ethernet driver (generic socket layer)");
144 MODULE_LICENSE("GPL");
145 MODULE_ALIAS_NETPROTO(PF_PPPOX);