blob: 1cfa9bf1d18713afc7191ddecb256bfb3844154e [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* net/atm/common.c - ATM sockets (common part for PVC and SVC) */
3
4/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
5
Joe Perches99824462010-01-26 11:40:00 +00006#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/module.h>
9#include <linux/kmod.h>
10#include <linux/net.h> /* struct socket, struct proto_ops */
11#include <linux/atm.h> /* ATM stuff */
12#include <linux/atmdev.h>
13#include <linux/socket.h> /* SOL_SOCKET */
14#include <linux/errno.h> /* error codes */
15#include <linux/capability.h>
Jesper Juhle49332b2005-05-01 08:59:08 -070016#include <linux/mm.h>
Ingo Molnar3f07c012017-02-08 18:51:30 +010017#include <linux/sched/signal.h>
Tina Ruchandanid750dbd2017-11-27 15:02:17 +010018#include <linux/time64.h> /* 64-bit time for seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/skbuff.h>
20#include <linux/bitops.h>
21#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <net/sock.h> /* struct sock */
Joe Perchesa8147d72010-01-26 11:40:06 +000024#include <linux/uaccess.h>
25#include <linux/poll.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Arun Sharma600634972011-07-26 16:09:06 -070027#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#include "resources.h" /* atm_find_dev */
30#include "common.h" /* prototypes */
31#include "protocols.h" /* atm_init_<transport> */
32#include "addr.h" /* address registry */
33#include "signaling.h" /* for WAITING and sigd_attach */
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
Joe Perchesa8147d72010-01-26 11:40:06 +000036EXPORT_SYMBOL(vcc_hash);
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038DEFINE_RWLOCK(vcc_sklist_lock);
Joe Perchesa8147d72010-01-26 11:40:06 +000039EXPORT_SYMBOL(vcc_sklist_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Karl Hiramoto7313bb82010-07-08 20:55:30 +000041static ATOMIC_NOTIFIER_HEAD(atm_dev_notify_chain);
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static void __vcc_insert_socket(struct sock *sk)
44{
45 struct atm_vcc *vcc = atm_sk(sk);
Joe Perchesa8147d72010-01-26 11:40:06 +000046 struct hlist_head *head = &vcc_hash[vcc->vci & (VCC_HTABLE_SIZE - 1)];
Eric Dumazet81c3d542005-10-03 14:13:38 -070047 sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 sk_add_node(sk, head);
49}
50
51void vcc_insert_socket(struct sock *sk)
52{
53 write_lock_irq(&vcc_sklist_lock);
54 __vcc_insert_socket(sk);
55 write_unlock_irq(&vcc_sklist_lock);
56}
Joe Perchesa8147d72010-01-26 11:40:06 +000057EXPORT_SYMBOL(vcc_insert_socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59static void vcc_remove_socket(struct sock *sk)
60{
61 write_lock_irq(&vcc_sklist_lock);
62 sk_del_node_init(sk);
63 write_unlock_irq(&vcc_sklist_lock);
64}
65
Francois Romieuc55fa3c2017-03-11 19:41:36 -050066static bool vcc_tx_ready(struct atm_vcc *vcc, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 struct sock *sk = sk_atm(vcc);
69
Eric Dumazet81e2a3d2009-06-17 19:06:12 -070070 if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) {
Stephen Hemminger52240062007-08-28 15:22:09 -070071 pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
Joe Perches99824462010-01-26 11:40:00 +000072 sk_wmem_alloc_get(sk), size, sk->sk_sndbuf);
Francois Romieuc55fa3c2017-03-11 19:41:36 -050073 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 }
Francois Romieuc55fa3c2017-03-11 19:41:36 -050075 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078static void vcc_sock_destruct(struct sock *sk)
79{
80 if (atomic_read(&sk->sk_rmem_alloc))
Joe Perchesa8147d72010-01-26 11:40:06 +000081 printk(KERN_DEBUG "%s: rmem leakage (%d bytes) detected.\n",
82 __func__, atomic_read(&sk->sk_rmem_alloc));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Reshetova, Elena14afee42017-06-30 13:08:00 +030084 if (refcount_read(&sk->sk_wmem_alloc))
Joe Perchesa8147d72010-01-26 11:40:06 +000085 printk(KERN_DEBUG "%s: wmem leakage (%d bytes) detected.\n",
Reshetova, Elena14afee42017-06-30 13:08:00 +030086 __func__, refcount_read(&sk->sk_wmem_alloc));
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
89static void vcc_def_wakeup(struct sock *sk)
90{
Eric Dumazet43815482010-04-29 11:01:49 +000091 struct socket_wq *wq;
92
93 rcu_read_lock();
94 wq = rcu_dereference(sk->sk_wq);
Herbert Xu1ce0bf52015-11-26 13:55:39 +080095 if (skwq_has_sleeper(wq))
Eric Dumazet43815482010-04-29 11:01:49 +000096 wake_up(&wq->wait);
97 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
100static inline int vcc_writable(struct sock *sk)
101{
102 struct atm_vcc *vcc = atm_sk(sk);
103
104 return (vcc->qos.txtp.max_sdu +
Reshetova, Elena14afee42017-06-30 13:08:00 +0300105 refcount_read(&sk->sk_wmem_alloc)) <= sk->sk_sndbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
107
108static void vcc_write_space(struct sock *sk)
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900109{
Eric Dumazet43815482010-04-29 11:01:49 +0000110 struct socket_wq *wq;
111
112 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 if (vcc_writable(sk)) {
Eric Dumazet43815482010-04-29 11:01:49 +0000115 wq = rcu_dereference(sk->sk_wq);
Herbert Xu1ce0bf52015-11-26 13:55:39 +0800116 if (skwq_has_sleeper(wq))
Eric Dumazet43815482010-04-29 11:01:49 +0000117 wake_up_interruptible(&wq->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Pavel Emelyanov8d8ad9d2007-11-26 20:10:50 +0800119 sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121
Eric Dumazet43815482010-04-29 11:01:49 +0000122 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
David Woodhousec971f082012-11-28 00:03:11 +0000125static void vcc_release_cb(struct sock *sk)
126{
127 struct atm_vcc *vcc = atm_sk(sk);
128
129 if (vcc->release_cb)
130 vcc->release_cb(vcc);
131}
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static struct proto vcc_proto = {
134 .name = "VCC",
135 .owner = THIS_MODULE,
136 .obj_size = sizeof(struct atm_vcc),
David Woodhousec971f082012-11-28 00:03:11 +0000137 .release_cb = vcc_release_cb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138};
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900139
Eric W. Biederman11aa9c22015-05-08 21:09:13 -0500140int vcc_create(struct net *net, struct socket *sock, int protocol, int family, int kern)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
142 struct sock *sk;
143 struct atm_vcc *vcc;
144
145 sock->sk = NULL;
146 if (sock->type == SOCK_STREAM)
147 return -EINVAL;
Eric W. Biederman11aa9c22015-05-08 21:09:13 -0500148 sk = sk_alloc(net, family, GFP_KERNEL, &vcc_proto, kern);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 if (!sk)
150 return -ENOMEM;
151 sock_init_data(sock, sk);
152 sk->sk_state_change = vcc_def_wakeup;
153 sk->sk_write_space = vcc_write_space;
154
155 vcc = atm_sk(sk);
156 vcc->dev = NULL;
Joe Perchesa8147d72010-01-26 11:40:06 +0000157 memset(&vcc->local, 0, sizeof(struct sockaddr_atmsvc));
158 memset(&vcc->remote, 0, sizeof(struct sockaddr_atmsvc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
Reshetova, Elena14afee42017-06-30 13:08:00 +0300160 refcount_set(&sk->sk_wmem_alloc, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 atomic_set(&sk->sk_rmem_alloc, 0);
162 vcc->push = NULL;
163 vcc->pop = NULL;
Krzysztof Mazurec809bd2012-11-06 23:16:57 +0100164 vcc->owner = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 vcc->push_oam = NULL;
David Woodhousec971f082012-11-28 00:03:11 +0000166 vcc->release_cb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 vcc->vpi = vcc->vci = 0; /* no VCI/VPI yet */
168 vcc->atm_options = vcc->aal_options = 0;
169 sk->sk_destruct = vcc_sock_destruct;
170 return 0;
171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173static void vcc_destroy_socket(struct sock *sk)
174{
175 struct atm_vcc *vcc = atm_sk(sk);
176 struct sk_buff *skb;
177
178 set_bit(ATM_VF_CLOSE, &vcc->flags);
179 clear_bit(ATM_VF_READY, &vcc->flags);
Cong Wang93a20142020-05-01 11:11:08 -0700180 if (vcc->dev && vcc->dev->ops->close)
181 vcc->dev->ops->close(vcc);
182 if (vcc->push)
183 vcc->push(vcc, NULL); /* atmarpd has no push */
184 module_put(vcc->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Cong Wang93a20142020-05-01 11:11:08 -0700186 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
187 atm_return(vcc, skb->truesize);
188 kfree_skb(skb);
189 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Cong Wang93a20142020-05-01 11:11:08 -0700191 if (vcc->dev && vcc->dev->ops->owner) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 module_put(vcc->dev->ops->owner);
193 atm_dev_put(vcc->dev);
194 }
Chas Williams9301e322005-09-28 16:35:01 -0700195
196 vcc_remove_socket(sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199int vcc_release(struct socket *sock)
200{
201 struct sock *sk = sock->sk;
202
203 if (sk) {
204 lock_sock(sk);
205 vcc_destroy_socket(sock->sk);
206 release_sock(sk);
207 sock_put(sk);
208 }
209
210 return 0;
211}
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213void vcc_release_async(struct atm_vcc *vcc, int reply)
214{
215 struct sock *sk = sk_atm(vcc);
216
217 set_bit(ATM_VF_CLOSE, &vcc->flags);
218 sk->sk_shutdown |= RCV_SHUTDOWN;
219 sk->sk_err = -reply;
220 clear_bit(ATM_VF_WAITING, &vcc->flags);
221 sk->sk_state_change(sk);
222}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223EXPORT_SYMBOL(vcc_release_async);
224
Jorge Boncompte [DTI2]4e55f572011-11-21 10:25:57 +0000225void vcc_process_recv_queue(struct atm_vcc *vcc)
226{
227 struct sk_buff_head queue, *rq;
228 struct sk_buff *skb, *tmp;
229 unsigned long flags;
230
231 __skb_queue_head_init(&queue);
232 rq = &sk_atm(vcc)->sk_receive_queue;
233
234 spin_lock_irqsave(&rq->lock, flags);
235 skb_queue_splice_init(rq, &queue);
236 spin_unlock_irqrestore(&rq->lock, flags);
237
238 skb_queue_walk_safe(&queue, skb, tmp) {
239 __skb_unlink(skb, &queue);
240 vcc->push(vcc, skb);
241 }
242}
243EXPORT_SYMBOL(vcc_process_recv_queue);
244
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000245void atm_dev_signal_change(struct atm_dev *dev, char signal)
246{
247 pr_debug("%s signal=%d dev=%p number=%d dev->signal=%d\n",
248 __func__, signal, dev, dev->number, dev->signal);
249
250 /* atm driver sending invalid signal */
251 WARN_ON(signal < ATM_PHY_SIG_LOST || signal > ATM_PHY_SIG_FOUND);
252
253 if (dev->signal == signal)
254 return; /* no change */
255
256 dev->signal = signal;
257
258 atomic_notifier_call_chain(&atm_dev_notify_chain, signal, dev);
259}
260EXPORT_SYMBOL(atm_dev_signal_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800262void atm_dev_release_vccs(struct atm_dev *dev)
263{
264 int i;
265
266 write_lock_irq(&vcc_sklist_lock);
267 for (i = 0; i < VCC_HTABLE_SIZE; i++) {
268 struct hlist_head *head = &vcc_hash[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800269 struct hlist_node *tmp;
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800270 struct sock *s;
271 struct atm_vcc *vcc;
272
Sasha Levinb67bfe02013-02-27 17:06:00 -0800273 sk_for_each_safe(s, tmp, head) {
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800274 vcc = atm_sk(s);
275 if (vcc->dev == dev) {
276 vcc_release_async(vcc, -EPIPE);
277 sk_del_node_init(s);
278 }
279 }
280 }
281 write_unlock_irq(&vcc_sklist_lock);
282}
Philip A. Prindevillec0312352011-03-30 13:17:04 +0000283EXPORT_SYMBOL(atm_dev_release_vccs);
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800284
Joe Perchesa8147d72010-01-26 11:40:06 +0000285static int adjust_tp(struct atm_trafprm *tp, unsigned char aal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 int max_sdu;
288
Joe Perchesa8147d72010-01-26 11:40:06 +0000289 if (!tp->traffic_class)
290 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 switch (aal) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000292 case ATM_AAL0:
293 max_sdu = ATM_CELL_SIZE-1;
294 break;
295 case ATM_AAL34:
296 max_sdu = ATM_MAX_AAL34_PDU;
297 break;
298 default:
Joe Perchesef423a42014-09-09 21:17:28 -0700299 pr_warn("AAL problems ... (%d)\n", aal);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500300 fallthrough;
Joe Perchesa8147d72010-01-26 11:40:06 +0000301 case ATM_AAL5:
302 max_sdu = ATM_MAX_AAL5_PDU;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000304 if (!tp->max_sdu)
305 tp->max_sdu = max_sdu;
306 else if (tp->max_sdu > max_sdu)
307 return -EINVAL;
308 if (!tp->max_cdv)
309 tp->max_cdv = ATM_MAX_CDV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return 0;
311}
312
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700313static int check_ci(const struct atm_vcc *vcc, short vpi, int vci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Joe Perchesa8147d72010-01-26 11:40:06 +0000315 struct hlist_head *head = &vcc_hash[vci & (VCC_HTABLE_SIZE - 1)];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 struct sock *s;
317 struct atm_vcc *walk;
318
Sasha Levinb67bfe02013-02-27 17:06:00 -0800319 sk_for_each(s, head) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 walk = atm_sk(s);
321 if (walk->dev != vcc->dev)
322 continue;
323 if (test_bit(ATM_VF_ADDR, &walk->flags) && walk->vpi == vpi &&
324 walk->vci == vci && ((walk->qos.txtp.traffic_class !=
325 ATM_NONE && vcc->qos.txtp.traffic_class != ATM_NONE) ||
326 (walk->qos.rxtp.traffic_class != ATM_NONE &&
327 vcc->qos.rxtp.traffic_class != ATM_NONE)))
328 return -EADDRINUSE;
329 }
330
331 /* allow VCCs with same VPI/VCI iff they don't collide on
332 TX/RX (but we may refuse such sharing for other reasons,
333 e.g. if protocol requires to have both channels) */
334
335 return 0;
336}
337
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700338static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
340 static short p; /* poor man's per-device cache */
341 static int c;
342 short old_p;
343 int old_c;
344 int err;
345
346 if (*vpi != ATM_VPI_ANY && *vci != ATM_VCI_ANY) {
347 err = check_ci(vcc, *vpi, *vci);
348 return err;
349 }
350 /* last scan may have left values out of bounds for current device */
351 if (*vpi != ATM_VPI_ANY)
352 p = *vpi;
353 else if (p >= 1 << vcc->dev->ci_range.vpi_bits)
354 p = 0;
355 if (*vci != ATM_VCI_ANY)
356 c = *vci;
357 else if (c < ATM_NOT_RSV_VCI || c >= 1 << vcc->dev->ci_range.vci_bits)
358 c = ATM_NOT_RSV_VCI;
359 old_p = p;
360 old_c = c;
361 do {
362 if (!check_ci(vcc, p, c)) {
363 *vpi = p;
364 *vci = c;
365 return 0;
366 }
367 if (*vci == ATM_VCI_ANY) {
368 c++;
369 if (c >= 1 << vcc->dev->ci_range.vci_bits)
370 c = ATM_NOT_RSV_VCI;
371 }
372 if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) &&
373 *vpi == ATM_VPI_ANY) {
374 p++;
Joe Perchesa8147d72010-01-26 11:40:06 +0000375 if (p >= 1 << vcc->dev->ci_range.vpi_bits)
376 p = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000378 } while (old_p != p || old_c != c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return -EADDRINUSE;
380}
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
383 int vci)
384{
385 struct sock *sk = sk_atm(vcc);
386 int error;
387
388 if ((vpi != ATM_VPI_UNSPEC && vpi != ATM_VPI_ANY &&
389 vpi >> dev->ci_range.vpi_bits) || (vci != ATM_VCI_UNSPEC &&
390 vci != ATM_VCI_ANY && vci >> dev->ci_range.vci_bits))
391 return -EINVAL;
392 if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
393 return -EPERM;
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800394 error = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (!try_module_get(dev->ops->owner))
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800396 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 vcc->dev = dev;
398 write_lock_irq(&vcc_sklist_lock);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900399 if (test_bit(ATM_DF_REMOVED, &dev->flags) ||
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800400 (error = find_ci(vcc, &vpi, &vci))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 write_unlock_irq(&vcc_sklist_lock);
402 goto fail_module_put;
403 }
404 vcc->vpi = vpi;
405 vcc->vci = vci;
406 __vcc_insert_socket(sk);
407 write_unlock_irq(&vcc_sklist_lock);
408 switch (vcc->qos.aal) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000409 case ATM_AAL0:
410 error = atm_init_aal0(vcc);
411 vcc->stats = &dev->stats.aal0;
412 break;
413 case ATM_AAL34:
414 error = atm_init_aal34(vcc);
415 vcc->stats = &dev->stats.aal34;
416 break;
417 case ATM_NO_AAL:
418 /* ATM_AAL5 is also used in the "0 for default" case */
419 vcc->qos.aal = ATM_AAL5;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500420 fallthrough;
Joe Perchesa8147d72010-01-26 11:40:06 +0000421 case ATM_AAL5:
422 error = atm_init_aal5(vcc);
423 vcc->stats = &dev->stats.aal5;
424 break;
425 default:
426 error = -EPROTOTYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000428 if (!error)
429 error = adjust_tp(&vcc->qos.txtp, vcc->qos.aal);
430 if (!error)
431 error = adjust_tp(&vcc->qos.rxtp, vcc->qos.aal);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 if (error)
433 goto fail;
Joe Perches99824462010-01-26 11:40:00 +0000434 pr_debug("VCC %d.%d, AAL %d\n", vpi, vci, vcc->qos.aal);
435 pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",
436 vcc->qos.txtp.traffic_class,
437 vcc->qos.txtp.min_pcr,
438 vcc->qos.txtp.max_pcr,
439 vcc->qos.txtp.max_sdu);
440 pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",
441 vcc->qos.rxtp.traffic_class,
442 vcc->qos.rxtp.min_pcr,
443 vcc->qos.rxtp.max_pcr,
444 vcc->qos.rxtp.max_sdu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 if (dev->ops->open) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000447 error = dev->ops->open(vcc);
448 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 goto fail;
450 }
451 return 0;
452
453fail:
454 vcc_remove_socket(sk);
455fail_module_put:
456 module_put(dev->ops->owner);
457 /* ensure we get dev module ref count correct */
458 vcc->dev = NULL;
459 return error;
460}
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
463{
464 struct atm_dev *dev;
465 struct atm_vcc *vcc = ATM_SD(sock);
466 int error;
467
Joe Perches99824462010-01-26 11:40:00 +0000468 pr_debug("(vpi %d, vci %d)\n", vpi, vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if (sock->state == SS_CONNECTED)
470 return -EISCONN;
471 if (sock->state != SS_UNCONNECTED)
472 return -EINVAL;
473 if (!(vpi || vci))
474 return -EINVAL;
475
476 if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC)
Joe Perchesa8147d72010-01-26 11:40:06 +0000477 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 else
Joe Perchesa8147d72010-01-26 11:40:06 +0000479 if (test_bit(ATM_VF_PARTIAL, &vcc->flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 return -EINVAL;
Joe Perches99824462010-01-26 11:40:00 +0000481 pr_debug("(TX: cl %d,bw %d-%d,sdu %d; "
482 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
483 vcc->qos.txtp.traffic_class, vcc->qos.txtp.min_pcr,
484 vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_sdu,
485 vcc->qos.rxtp.traffic_class, vcc->qos.rxtp.min_pcr,
Joe Perchesa8147d72010-01-26 11:40:06 +0000486 vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_sdu,
Joe Perches99824462010-01-26 11:40:00 +0000487 vcc->qos.aal == ATM_AAL5 ? "" :
488 vcc->qos.aal == ATM_AAL0 ? "" : " ??? code ",
489 vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
491 return -EBADFD;
492 if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
493 vcc->qos.rxtp.traffic_class == ATM_ANYCLASS)
494 return -EINVAL;
Mitchell Blank Jrc9933d02005-11-29 16:13:32 -0800495 if (likely(itf != ATM_ITF_ANY)) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000496 dev = try_then_request_module(atm_dev_lookup(itf),
497 "atm-device-%d", itf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 dev = NULL;
Ingo Molnar57b47a52006-03-20 22:35:41 -0800500 mutex_lock(&atm_dev_mutex);
Mitchell Blank Jrc9933d02005-11-29 16:13:32 -0800501 if (!list_empty(&atm_devs)) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000502 dev = list_entry(atm_devs.next,
503 struct atm_dev, dev_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 atm_dev_hold(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
Ingo Molnar57b47a52006-03-20 22:35:41 -0800506 mutex_unlock(&atm_dev_mutex);
Mitchell Blank Jrc9933d02005-11-29 16:13:32 -0800507 }
508 if (!dev)
509 return -ENODEV;
510 error = __vcc_connect(vcc, dev, vpi, vci);
511 if (error) {
512 atm_dev_put(dev);
513 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
515 if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
Joe Perchesa8147d72010-01-26 11:40:06 +0000516 set_bit(ATM_VF_PARTIAL, &vcc->flags);
517 if (test_bit(ATM_VF_READY, &ATM_SD(sock)->flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 sock->state = SS_CONNECTED;
519 return 0;
520}
521
Ying Xue1b784142015-03-02 15:37:48 +0800522int vcc_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
523 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
525 struct sock *sk = sock->sk;
526 struct atm_vcc *vcc;
527 struct sk_buff *skb;
528 int copied, error = -EINVAL;
529
530 if (sock->state != SS_CONNECTED)
531 return -ENOTCONN;
Jorge Boncompte [DTI2]40ba8492011-11-21 10:25:58 +0000532
533 /* only handle MSG_DONTWAIT and MSG_PEEK */
534 if (flags & ~(MSG_DONTWAIT | MSG_PEEK))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 return -EOPNOTSUPP;
Jorge Boncompte [DTI2]40ba8492011-11-21 10:25:58 +0000536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 vcc = ATM_SD(sock);
Joe Perchesa8147d72010-01-26 11:40:06 +0000538 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
539 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 !test_bit(ATM_VF_READY, &vcc->flags))
541 return 0;
542
543 skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &error);
544 if (!skb)
545 return error;
546
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900547 copied = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 if (copied > size) {
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900549 copied = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 msg->msg_flags |= MSG_TRUNC;
551 }
552
David S. Miller51f3d022014-11-05 16:46:40 -0500553 error = skb_copy_datagram_msg(skb, 0, msg, copied);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900554 if (error)
555 return error;
Neil Horman3b885782009-10-12 13:26:31 -0700556 sock_recv_ts_and_drops(msg, sk, skb);
Jorge Boncompte [DTI2]40ba8492011-11-21 10:25:58 +0000557
558 if (!(flags & MSG_PEEK)) {
559 pr_debug("%d -= %d\n", atomic_read(&sk->sk_rmem_alloc),
560 skb->truesize);
561 atm_return(vcc, skb->truesize);
562 }
563
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900564 skb_free_datagram(sk, skb);
565 return copied;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
567
Ying Xue1b784142015-03-02 15:37:48 +0800568int vcc_sendmsg(struct socket *sock, struct msghdr *m, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
570 struct sock *sk = sock->sk;
571 DEFINE_WAIT(wait);
572 struct atm_vcc *vcc;
573 struct sk_buff *skb;
Joe Perchesa8147d72010-01-26 11:40:06 +0000574 int eff, error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 lock_sock(sk);
577 if (sock->state != SS_CONNECTED) {
578 error = -ENOTCONN;
579 goto out;
580 }
581 if (m->msg_name) {
582 error = -EISCONN;
583 goto out;
584 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 vcc = ATM_SD(sock);
586 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
587 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
588 !test_bit(ATM_VF_READY, &vcc->flags)) {
589 error = -EPIPE;
590 send_sig(SIGPIPE, current, 0);
591 goto out;
592 }
593 if (!size) {
594 error = 0;
595 goto out;
596 }
Al Viro7424ce62014-11-20 07:01:29 -0500597 if (size > vcc->qos.txtp.max_sdu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 error = -EMSGSIZE;
599 goto out;
600 }
Jesper Juhle49332b2005-05-01 08:59:08 -0700601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 eff = (size+3) & ~3; /* align to word boundary */
Eric Dumazetaa395142010-04-20 13:03:51 +0000603 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 error = 0;
Francois Romieuc55fa3c2017-03-11 19:41:36 -0500605 while (!vcc_tx_ready(vcc, eff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 if (m->msg_flags & MSG_DONTWAIT) {
607 error = -EAGAIN;
608 break;
609 }
610 schedule();
611 if (signal_pending(current)) {
612 error = -ERESTARTSYS;
613 break;
614 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000615 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
616 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
617 !test_bit(ATM_VF_READY, &vcc->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 error = -EPIPE;
619 send_sig(SIGPIPE, current, 0);
620 break;
621 }
Eric Dumazetaa395142010-04-20 13:03:51 +0000622 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 }
Eric Dumazetaa395142010-04-20 13:03:51 +0000624 finish_wait(sk_sleep(sk), &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 if (error)
626 goto out;
Francois Romieuc55fa3c2017-03-11 19:41:36 -0500627
628 skb = alloc_skb(eff, GFP_KERNEL);
629 if (!skb) {
630 error = -ENOMEM;
631 goto out;
632 }
633 pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize);
David Woodhouse9bbe60a2018-06-16 11:55:44 +0100634 atm_account_tx(vcc, skb);
Francois Romieuc55fa3c2017-03-11 19:41:36 -0500635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 skb->dev = NULL; /* for paths shared with net_device interfaces */
Al Virocbbd26b2016-11-01 22:09:04 -0400637 if (!copy_from_iter_full(skb_put(skb, size), size, &m->msg_iter)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 kfree_skb(skb);
639 error = -EFAULT;
640 goto out;
641 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000642 if (eff != size)
643 memset(skb->data + size, 0, eff-size);
644 error = vcc->dev->ops->send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 error = error ? error : size;
646out:
647 release_sock(sk);
648 return error;
649}
650
Linus Torvaldsa11e1d42018-06-28 09:43:44 -0700651__poll_t vcc_poll(struct file *file, struct socket *sock, poll_table *wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
653 struct sock *sk = sock->sk;
Linus Torvaldsa11e1d42018-06-28 09:43:44 -0700654 struct atm_vcc *vcc;
655 __poll_t mask;
656
Karsten Graul89ab0662018-10-23 13:40:39 +0200657 sock_poll_wait(file, sock, wait);
Linus Torvaldsa11e1d42018-06-28 09:43:44 -0700658 mask = 0;
659
660 vcc = ATM_SD(sock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 /* exceptional events */
663 if (sk->sk_err)
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800664 mask = EPOLLERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
667 test_bit(ATM_VF_CLOSE, &vcc->flags))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800668 mask |= EPOLLHUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 /* readable? */
Eric Dumazet3ef7cf52019-10-23 22:44:50 -0700671 if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800672 mask |= EPOLLIN | EPOLLRDNORM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 /* writable? */
675 if (sock->state == SS_CONNECTING &&
676 test_bit(ATM_VF_WAITING, &vcc->flags))
677 return mask;
678
679 if (vcc->qos.txtp.traffic_class != ATM_NONE &&
680 vcc_writable(sk))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800681 mask |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 return mask;
684}
685
Joe Perchesa8147d72010-01-26 11:40:06 +0000686static int atm_change_qos(struct atm_vcc *vcc, struct atm_qos *qos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 int error;
689
690 /*
691 * Don't let the QoS change the already connected AAL type nor the
692 * traffic class.
693 */
694 if (qos->aal != vcc->qos.aal ||
695 qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class ||
696 qos->txtp.traffic_class != vcc->qos.txtp.traffic_class)
697 return -EINVAL;
Joe Perchesa8147d72010-01-26 11:40:06 +0000698 error = adjust_tp(&qos->txtp, qos->aal);
699 if (!error)
700 error = adjust_tp(&qos->rxtp, qos->aal);
701 if (error)
702 return error;
703 if (!vcc->dev->ops->change_qos)
704 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 if (sk_atm(vcc)->sk_family == AF_ATMPVC)
Joe Perchesa8147d72010-01-26 11:40:06 +0000706 return vcc->dev->ops->change_qos(vcc, qos, ATM_MF_SET);
707 return svc_change_qos(vcc, qos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
709
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700710static int check_tp(const struct atm_trafprm *tp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
712 /* @@@ Should be merged with adjust_tp */
Joe Perchesa8147d72010-01-26 11:40:06 +0000713 if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS)
714 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
Joe Perchesa8147d72010-01-26 11:40:06 +0000716 !tp->max_pcr)
717 return -EINVAL;
718 if (tp->min_pcr == ATM_MAX_PCR)
719 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR &&
Joe Perchesa8147d72010-01-26 11:40:06 +0000721 tp->min_pcr > tp->max_pcr)
722 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 /*
724 * We allow pcr to be outside [min_pcr,max_pcr], because later
725 * adjustment may still push it in the valid range.
726 */
727 return 0;
728}
729
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700730static int check_qos(const struct atm_qos *qos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
732 int error;
733
734 if (!qos->txtp.traffic_class && !qos->rxtp.traffic_class)
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900735 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
737 qos->txtp.traffic_class && qos->rxtp.traffic_class &&
738 qos->txtp.traffic_class != ATM_ANYCLASS &&
Joe Perchesa8147d72010-01-26 11:40:06 +0000739 qos->rxtp.traffic_class != ATM_ANYCLASS)
740 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 error = check_tp(&qos->txtp);
Joe Perchesa8147d72010-01-26 11:40:06 +0000742 if (error)
743 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 return check_tp(&qos->rxtp);
745}
746
747int vcc_setsockopt(struct socket *sock, int level, int optname,
Christoph Hellwiga7b75c52020-07-23 08:09:07 +0200748 sockptr_t optval, unsigned int optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
750 struct atm_vcc *vcc;
751 unsigned long value;
752 int error;
753
754 if (__SO_LEVEL_MATCH(optname, level) && optlen != __SO_SIZE(optname))
755 return -EINVAL;
756
757 vcc = ATM_SD(sock);
758 switch (optname) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000759 case SO_ATMQOS:
760 {
761 struct atm_qos qos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Christoph Hellwiga7b75c52020-07-23 08:09:07 +0200763 if (copy_from_sockptr(&qos, optval, sizeof(qos)))
Joe Perchesa8147d72010-01-26 11:40:06 +0000764 return -EFAULT;
765 error = check_qos(&qos);
766 if (error)
767 return error;
768 if (sock->state == SS_CONNECTED)
769 return atm_change_qos(vcc, &qos);
770 if (sock->state != SS_UNCONNECTED)
771 return -EBADFD;
772 vcc->qos = qos;
773 set_bit(ATM_VF_HASQOS, &vcc->flags);
774 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000776 case SO_SETCLP:
Christoph Hellwiga7b75c52020-07-23 08:09:07 +0200777 if (copy_from_sockptr(&value, optval, sizeof(value)))
Joe Perchesa8147d72010-01-26 11:40:06 +0000778 return -EFAULT;
779 if (value)
780 vcc->atm_options |= ATM_ATMOPT_CLP;
781 else
782 vcc->atm_options &= ~ATM_ATMOPT_CLP;
783 return 0;
784 default:
Joe Perchesa8147d72010-01-26 11:40:06 +0000785 return -EINVAL;
Christoph Hellwiga06d30a2020-07-17 08:23:10 +0200786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787}
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789int vcc_getsockopt(struct socket *sock, int level, int optname,
790 char __user *optval, int __user *optlen)
791{
792 struct atm_vcc *vcc;
793 int len;
794
795 if (get_user(len, optlen))
796 return -EFAULT;
797 if (__SO_LEVEL_MATCH(optname, level) && len != __SO_SIZE(optname))
798 return -EINVAL;
799
800 vcc = ATM_SD(sock);
801 switch (optname) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000802 case SO_ATMQOS:
803 if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
804 return -EINVAL;
805 return copy_to_user(optval, &vcc->qos, sizeof(vcc->qos))
806 ? -EFAULT : 0;
807 case SO_SETCLP:
808 return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : 0,
809 (unsigned long __user *)optval) ? -EFAULT : 0;
810 case SO_ATMPVC:
811 {
812 struct sockaddr_atmpvc pvc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Joe Perchesa8147d72010-01-26 11:40:06 +0000814 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
815 return -ENOTCONN;
Mathias Krausee862f1a2012-08-15 11:31:44 +0000816 memset(&pvc, 0, sizeof(pvc));
Joe Perchesa8147d72010-01-26 11:40:06 +0000817 pvc.sap_family = AF_ATMPVC;
818 pvc.sap_addr.itf = vcc->dev->number;
819 pvc.sap_addr.vpi = vcc->vpi;
820 pvc.sap_addr.vci = vcc->vci;
821 return copy_to_user(optval, &pvc, sizeof(pvc)) ? -EFAULT : 0;
822 }
823 default:
Joe Perchesa8147d72010-01-26 11:40:06 +0000824 return -EINVAL;
Christoph Hellwiga06d30a2020-07-17 08:23:10 +0200825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826}
827
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000828int register_atmdevice_notifier(struct notifier_block *nb)
829{
830 return atomic_notifier_chain_register(&atm_dev_notify_chain, nb);
831}
832EXPORT_SYMBOL_GPL(register_atmdevice_notifier);
833
834void unregister_atmdevice_notifier(struct notifier_block *nb)
835{
836 atomic_notifier_chain_unregister(&atm_dev_notify_chain, nb);
837}
838EXPORT_SYMBOL_GPL(unregister_atmdevice_notifier);
839
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840static int __init atm_init(void)
841{
842 int error;
843
Joe Perchesa8147d72010-01-26 11:40:06 +0000844 error = proto_register(&vcc_proto, 0);
845 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 goto out;
Joe Perchesa8147d72010-01-26 11:40:06 +0000847 error = atmpvc_init();
848 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000849 pr_err("atmpvc_init() failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 goto out_unregister_vcc_proto;
851 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000852 error = atmsvc_init();
853 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000854 pr_err("atmsvc_init() failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 goto out_atmpvc_exit;
856 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000857 error = atm_proc_init();
858 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000859 pr_err("atm_proc_init() failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 goto out_atmsvc_exit;
861 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000862 error = atm_sysfs_init();
863 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000864 pr_err("atm_sysfs_init() failed with %d\n", error);
Roman Kagan656d98b2006-06-29 12:36:34 -0700865 goto out_atmproc_exit;
866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867out:
868 return error;
Roman Kagan656d98b2006-06-29 12:36:34 -0700869out_atmproc_exit:
870 atm_proc_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871out_atmsvc_exit:
872 atmsvc_exit();
873out_atmpvc_exit:
874 atmsvc_exit();
875out_unregister_vcc_proto:
876 proto_unregister(&vcc_proto);
877 goto out;
878}
879
880static void __exit atm_exit(void)
881{
882 atm_proc_exit();
Roman Kagan656d98b2006-06-29 12:36:34 -0700883 atm_sysfs_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 atmsvc_exit();
885 atmpvc_exit();
886 proto_unregister(&vcc_proto);
887}
888
Daniel Walker84ff6022007-02-05 18:04:06 -0800889subsys_initcall(atm_init);
890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891module_exit(atm_exit);
892
893MODULE_LICENSE("GPL");
894MODULE_ALIAS_NETPROTO(PF_ATMPVC);
895MODULE_ALIAS_NETPROTO(PF_ATMSVC);