blob: a7a68e5096288df11af1037297189962dc2fa548 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* net/atm/common.c - ATM sockets (common part for PVC and SVC) */
2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4
Joe Perches99824462010-01-26 11:40:00 +00005#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/module.h>
8#include <linux/kmod.h>
9#include <linux/net.h> /* struct socket, struct proto_ops */
10#include <linux/atm.h> /* ATM stuff */
11#include <linux/atmdev.h>
12#include <linux/socket.h> /* SOL_SOCKET */
13#include <linux/errno.h> /* error codes */
14#include <linux/capability.h>
Jesper Juhle49332b2005-05-01 08:59:08 -070015#include <linux/mm.h>
Ingo Molnar3f07c012017-02-08 18:51:30 +010016#include <linux/sched/signal.h>
Tina Ruchandanid750dbd2017-11-27 15:02:17 +010017#include <linux/time64.h> /* 64-bit time for seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/skbuff.h>
19#include <linux/bitops.h>
20#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <net/sock.h> /* struct sock */
Joe Perchesa8147d72010-01-26 11:40:06 +000023#include <linux/uaccess.h>
24#include <linux/poll.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Arun Sharma600634972011-07-26 16:09:06 -070026#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include "resources.h" /* atm_find_dev */
29#include "common.h" /* prototypes */
30#include "protocols.h" /* atm_init_<transport> */
31#include "addr.h" /* address registry */
32#include "signaling.h" /* for WAITING and sigd_attach */
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
Joe Perchesa8147d72010-01-26 11:40:06 +000035EXPORT_SYMBOL(vcc_hash);
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037DEFINE_RWLOCK(vcc_sklist_lock);
Joe Perchesa8147d72010-01-26 11:40:06 +000038EXPORT_SYMBOL(vcc_sklist_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Karl Hiramoto7313bb82010-07-08 20:55:30 +000040static ATOMIC_NOTIFIER_HEAD(atm_dev_notify_chain);
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static void __vcc_insert_socket(struct sock *sk)
43{
44 struct atm_vcc *vcc = atm_sk(sk);
Joe Perchesa8147d72010-01-26 11:40:06 +000045 struct hlist_head *head = &vcc_hash[vcc->vci & (VCC_HTABLE_SIZE - 1)];
Eric Dumazet81c3d542005-10-03 14:13:38 -070046 sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 sk_add_node(sk, head);
48}
49
50void vcc_insert_socket(struct sock *sk)
51{
52 write_lock_irq(&vcc_sklist_lock);
53 __vcc_insert_socket(sk);
54 write_unlock_irq(&vcc_sklist_lock);
55}
Joe Perchesa8147d72010-01-26 11:40:06 +000056EXPORT_SYMBOL(vcc_insert_socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58static void vcc_remove_socket(struct sock *sk)
59{
60 write_lock_irq(&vcc_sklist_lock);
61 sk_del_node_init(sk);
62 write_unlock_irq(&vcc_sklist_lock);
63}
64
Francois Romieuc55fa3c2017-03-11 19:41:36 -050065static bool vcc_tx_ready(struct atm_vcc *vcc, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 struct sock *sk = sk_atm(vcc);
68
Eric Dumazet81e2a3d2009-06-17 19:06:12 -070069 if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) {
Stephen Hemminger52240062007-08-28 15:22:09 -070070 pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
Joe Perches99824462010-01-26 11:40:00 +000071 sk_wmem_alloc_get(sk), size, sk->sk_sndbuf);
Francois Romieuc55fa3c2017-03-11 19:41:36 -050072 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 }
Francois Romieuc55fa3c2017-03-11 19:41:36 -050074 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static void vcc_sock_destruct(struct sock *sk)
78{
79 if (atomic_read(&sk->sk_rmem_alloc))
Joe Perchesa8147d72010-01-26 11:40:06 +000080 printk(KERN_DEBUG "%s: rmem leakage (%d bytes) detected.\n",
81 __func__, atomic_read(&sk->sk_rmem_alloc));
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Reshetova, Elena14afee42017-06-30 13:08:00 +030083 if (refcount_read(&sk->sk_wmem_alloc))
Joe Perchesa8147d72010-01-26 11:40:06 +000084 printk(KERN_DEBUG "%s: wmem leakage (%d bytes) detected.\n",
Reshetova, Elena14afee42017-06-30 13:08:00 +030085 __func__, refcount_read(&sk->sk_wmem_alloc));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
88static void vcc_def_wakeup(struct sock *sk)
89{
Eric Dumazet43815482010-04-29 11:01:49 +000090 struct socket_wq *wq;
91
92 rcu_read_lock();
93 wq = rcu_dereference(sk->sk_wq);
Herbert Xu1ce0bf52015-11-26 13:55:39 +080094 if (skwq_has_sleeper(wq))
Eric Dumazet43815482010-04-29 11:01:49 +000095 wake_up(&wq->wait);
96 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
99static inline int vcc_writable(struct sock *sk)
100{
101 struct atm_vcc *vcc = atm_sk(sk);
102
103 return (vcc->qos.txtp.max_sdu +
Reshetova, Elena14afee42017-06-30 13:08:00 +0300104 refcount_read(&sk->sk_wmem_alloc)) <= sk->sk_sndbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
107static void vcc_write_space(struct sock *sk)
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900108{
Eric Dumazet43815482010-04-29 11:01:49 +0000109 struct socket_wq *wq;
110
111 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 if (vcc_writable(sk)) {
Eric Dumazet43815482010-04-29 11:01:49 +0000114 wq = rcu_dereference(sk->sk_wq);
Herbert Xu1ce0bf52015-11-26 13:55:39 +0800115 if (skwq_has_sleeper(wq))
Eric Dumazet43815482010-04-29 11:01:49 +0000116 wake_up_interruptible(&wq->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Pavel Emelyanov8d8ad9d2007-11-26 20:10:50 +0800118 sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
120
Eric Dumazet43815482010-04-29 11:01:49 +0000121 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
David Woodhousec971f082012-11-28 00:03:11 +0000124static void vcc_release_cb(struct sock *sk)
125{
126 struct atm_vcc *vcc = atm_sk(sk);
127
128 if (vcc->release_cb)
129 vcc->release_cb(vcc);
130}
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132static struct proto vcc_proto = {
133 .name = "VCC",
134 .owner = THIS_MODULE,
135 .obj_size = sizeof(struct atm_vcc),
David Woodhousec971f082012-11-28 00:03:11 +0000136 .release_cb = vcc_release_cb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137};
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900138
Eric W. Biederman11aa9c22015-05-08 21:09:13 -0500139int vcc_create(struct net *net, struct socket *sock, int protocol, int family, int kern)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 struct sock *sk;
142 struct atm_vcc *vcc;
143
144 sock->sk = NULL;
145 if (sock->type == SOCK_STREAM)
146 return -EINVAL;
Eric W. Biederman11aa9c22015-05-08 21:09:13 -0500147 sk = sk_alloc(net, family, GFP_KERNEL, &vcc_proto, kern);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 if (!sk)
149 return -ENOMEM;
150 sock_init_data(sock, sk);
151 sk->sk_state_change = vcc_def_wakeup;
152 sk->sk_write_space = vcc_write_space;
153
154 vcc = atm_sk(sk);
155 vcc->dev = NULL;
Joe Perchesa8147d72010-01-26 11:40:06 +0000156 memset(&vcc->local, 0, sizeof(struct sockaddr_atmsvc));
157 memset(&vcc->remote, 0, sizeof(struct sockaddr_atmsvc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
Reshetova, Elena14afee42017-06-30 13:08:00 +0300159 refcount_set(&sk->sk_wmem_alloc, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 atomic_set(&sk->sk_rmem_alloc, 0);
161 vcc->push = NULL;
162 vcc->pop = NULL;
Krzysztof Mazurec809bd2012-11-06 23:16:57 +0100163 vcc->owner = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 vcc->push_oam = NULL;
David Woodhousec971f082012-11-28 00:03:11 +0000165 vcc->release_cb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 vcc->vpi = vcc->vci = 0; /* no VCI/VPI yet */
167 vcc->atm_options = vcc->aal_options = 0;
168 sk->sk_destruct = vcc_sock_destruct;
169 return 0;
170}
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172static void vcc_destroy_socket(struct sock *sk)
173{
174 struct atm_vcc *vcc = atm_sk(sk);
175 struct sk_buff *skb;
176
177 set_bit(ATM_VF_CLOSE, &vcc->flags);
178 clear_bit(ATM_VF_READY, &vcc->flags);
179 if (vcc->dev) {
180 if (vcc->dev->ops->close)
181 vcc->dev->ops->close(vcc);
182 if (vcc->push)
183 vcc->push(vcc, NULL); /* atmarpd has no push */
Krzysztof Mazurec809bd2012-11-06 23:16:57 +0100184 module_put(vcc->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000187 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 kfree_skb(skb);
189 }
190
191 module_put(vcc->dev->ops->owner);
192 atm_dev_put(vcc->dev);
193 }
Chas Williams9301e322005-09-28 16:35:01 -0700194
195 vcc_remove_socket(sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198int vcc_release(struct socket *sock)
199{
200 struct sock *sk = sock->sk;
201
202 if (sk) {
203 lock_sock(sk);
204 vcc_destroy_socket(sock->sk);
205 release_sock(sk);
206 sock_put(sk);
207 }
208
209 return 0;
210}
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212void vcc_release_async(struct atm_vcc *vcc, int reply)
213{
214 struct sock *sk = sk_atm(vcc);
215
216 set_bit(ATM_VF_CLOSE, &vcc->flags);
217 sk->sk_shutdown |= RCV_SHUTDOWN;
218 sk->sk_err = -reply;
219 clear_bit(ATM_VF_WAITING, &vcc->flags);
220 sk->sk_state_change(sk);
221}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222EXPORT_SYMBOL(vcc_release_async);
223
Jorge Boncompte [DTI2]4e55f572011-11-21 10:25:57 +0000224void vcc_process_recv_queue(struct atm_vcc *vcc)
225{
226 struct sk_buff_head queue, *rq;
227 struct sk_buff *skb, *tmp;
228 unsigned long flags;
229
230 __skb_queue_head_init(&queue);
231 rq = &sk_atm(vcc)->sk_receive_queue;
232
233 spin_lock_irqsave(&rq->lock, flags);
234 skb_queue_splice_init(rq, &queue);
235 spin_unlock_irqrestore(&rq->lock, flags);
236
237 skb_queue_walk_safe(&queue, skb, tmp) {
238 __skb_unlink(skb, &queue);
239 vcc->push(vcc, skb);
240 }
241}
242EXPORT_SYMBOL(vcc_process_recv_queue);
243
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000244void atm_dev_signal_change(struct atm_dev *dev, char signal)
245{
246 pr_debug("%s signal=%d dev=%p number=%d dev->signal=%d\n",
247 __func__, signal, dev, dev->number, dev->signal);
248
249 /* atm driver sending invalid signal */
250 WARN_ON(signal < ATM_PHY_SIG_LOST || signal > ATM_PHY_SIG_FOUND);
251
252 if (dev->signal == signal)
253 return; /* no change */
254
255 dev->signal = signal;
256
257 atomic_notifier_call_chain(&atm_dev_notify_chain, signal, dev);
258}
259EXPORT_SYMBOL(atm_dev_signal_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800261void atm_dev_release_vccs(struct atm_dev *dev)
262{
263 int i;
264
265 write_lock_irq(&vcc_sklist_lock);
266 for (i = 0; i < VCC_HTABLE_SIZE; i++) {
267 struct hlist_head *head = &vcc_hash[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800268 struct hlist_node *tmp;
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800269 struct sock *s;
270 struct atm_vcc *vcc;
271
Sasha Levinb67bfe02013-02-27 17:06:00 -0800272 sk_for_each_safe(s, tmp, head) {
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800273 vcc = atm_sk(s);
274 if (vcc->dev == dev) {
275 vcc_release_async(vcc, -EPIPE);
276 sk_del_node_init(s);
277 }
278 }
279 }
280 write_unlock_irq(&vcc_sklist_lock);
281}
Philip A. Prindevillec0312352011-03-30 13:17:04 +0000282EXPORT_SYMBOL(atm_dev_release_vccs);
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800283
Joe Perchesa8147d72010-01-26 11:40:06 +0000284static int adjust_tp(struct atm_trafprm *tp, unsigned char aal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 int max_sdu;
287
Joe Perchesa8147d72010-01-26 11:40:06 +0000288 if (!tp->traffic_class)
289 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 switch (aal) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000291 case ATM_AAL0:
292 max_sdu = ATM_CELL_SIZE-1;
293 break;
294 case ATM_AAL34:
295 max_sdu = ATM_MAX_AAL34_PDU;
296 break;
297 default:
Joe Perchesef423a42014-09-09 21:17:28 -0700298 pr_warn("AAL problems ... (%d)\n", aal);
Joe Perchesa8147d72010-01-26 11:40:06 +0000299 /* fall through */
300 case ATM_AAL5:
301 max_sdu = ATM_MAX_AAL5_PDU;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000303 if (!tp->max_sdu)
304 tp->max_sdu = max_sdu;
305 else if (tp->max_sdu > max_sdu)
306 return -EINVAL;
307 if (!tp->max_cdv)
308 tp->max_cdv = ATM_MAX_CDV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 return 0;
310}
311
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700312static int check_ci(const struct atm_vcc *vcc, short vpi, int vci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Joe Perchesa8147d72010-01-26 11:40:06 +0000314 struct hlist_head *head = &vcc_hash[vci & (VCC_HTABLE_SIZE - 1)];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 struct sock *s;
316 struct atm_vcc *walk;
317
Sasha Levinb67bfe02013-02-27 17:06:00 -0800318 sk_for_each(s, head) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 walk = atm_sk(s);
320 if (walk->dev != vcc->dev)
321 continue;
322 if (test_bit(ATM_VF_ADDR, &walk->flags) && walk->vpi == vpi &&
323 walk->vci == vci && ((walk->qos.txtp.traffic_class !=
324 ATM_NONE && vcc->qos.txtp.traffic_class != ATM_NONE) ||
325 (walk->qos.rxtp.traffic_class != ATM_NONE &&
326 vcc->qos.rxtp.traffic_class != ATM_NONE)))
327 return -EADDRINUSE;
328 }
329
330 /* allow VCCs with same VPI/VCI iff they don't collide on
331 TX/RX (but we may refuse such sharing for other reasons,
332 e.g. if protocol requires to have both channels) */
333
334 return 0;
335}
336
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700337static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
339 static short p; /* poor man's per-device cache */
340 static int c;
341 short old_p;
342 int old_c;
343 int err;
344
345 if (*vpi != ATM_VPI_ANY && *vci != ATM_VCI_ANY) {
346 err = check_ci(vcc, *vpi, *vci);
347 return err;
348 }
349 /* last scan may have left values out of bounds for current device */
350 if (*vpi != ATM_VPI_ANY)
351 p = *vpi;
352 else if (p >= 1 << vcc->dev->ci_range.vpi_bits)
353 p = 0;
354 if (*vci != ATM_VCI_ANY)
355 c = *vci;
356 else if (c < ATM_NOT_RSV_VCI || c >= 1 << vcc->dev->ci_range.vci_bits)
357 c = ATM_NOT_RSV_VCI;
358 old_p = p;
359 old_c = c;
360 do {
361 if (!check_ci(vcc, p, c)) {
362 *vpi = p;
363 *vci = c;
364 return 0;
365 }
366 if (*vci == ATM_VCI_ANY) {
367 c++;
368 if (c >= 1 << vcc->dev->ci_range.vci_bits)
369 c = ATM_NOT_RSV_VCI;
370 }
371 if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) &&
372 *vpi == ATM_VPI_ANY) {
373 p++;
Joe Perchesa8147d72010-01-26 11:40:06 +0000374 if (p >= 1 << vcc->dev->ci_range.vpi_bits)
375 p = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000377 } while (old_p != p || old_c != c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 return -EADDRINUSE;
379}
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
382 int vci)
383{
384 struct sock *sk = sk_atm(vcc);
385 int error;
386
387 if ((vpi != ATM_VPI_UNSPEC && vpi != ATM_VPI_ANY &&
388 vpi >> dev->ci_range.vpi_bits) || (vci != ATM_VCI_UNSPEC &&
389 vci != ATM_VCI_ANY && vci >> dev->ci_range.vci_bits))
390 return -EINVAL;
391 if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
392 return -EPERM;
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800393 error = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (!try_module_get(dev->ops->owner))
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800395 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 vcc->dev = dev;
397 write_lock_irq(&vcc_sklist_lock);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900398 if (test_bit(ATM_DF_REMOVED, &dev->flags) ||
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800399 (error = find_ci(vcc, &vpi, &vci))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 write_unlock_irq(&vcc_sklist_lock);
401 goto fail_module_put;
402 }
403 vcc->vpi = vpi;
404 vcc->vci = vci;
405 __vcc_insert_socket(sk);
406 write_unlock_irq(&vcc_sklist_lock);
407 switch (vcc->qos.aal) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000408 case ATM_AAL0:
409 error = atm_init_aal0(vcc);
410 vcc->stats = &dev->stats.aal0;
411 break;
412 case ATM_AAL34:
413 error = atm_init_aal34(vcc);
414 vcc->stats = &dev->stats.aal34;
415 break;
416 case ATM_NO_AAL:
417 /* ATM_AAL5 is also used in the "0 for default" case */
418 vcc->qos.aal = ATM_AAL5;
419 /* fall through */
420 case ATM_AAL5:
421 error = atm_init_aal5(vcc);
422 vcc->stats = &dev->stats.aal5;
423 break;
424 default:
425 error = -EPROTOTYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000427 if (!error)
428 error = adjust_tp(&vcc->qos.txtp, vcc->qos.aal);
429 if (!error)
430 error = adjust_tp(&vcc->qos.rxtp, vcc->qos.aal);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 if (error)
432 goto fail;
Joe Perches99824462010-01-26 11:40:00 +0000433 pr_debug("VCC %d.%d, AAL %d\n", vpi, vci, vcc->qos.aal);
434 pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",
435 vcc->qos.txtp.traffic_class,
436 vcc->qos.txtp.min_pcr,
437 vcc->qos.txtp.max_pcr,
438 vcc->qos.txtp.max_sdu);
439 pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",
440 vcc->qos.rxtp.traffic_class,
441 vcc->qos.rxtp.min_pcr,
442 vcc->qos.rxtp.max_pcr,
443 vcc->qos.rxtp.max_sdu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 if (dev->ops->open) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000446 error = dev->ops->open(vcc);
447 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 goto fail;
449 }
450 return 0;
451
452fail:
453 vcc_remove_socket(sk);
454fail_module_put:
455 module_put(dev->ops->owner);
456 /* ensure we get dev module ref count correct */
457 vcc->dev = NULL;
458 return error;
459}
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
462{
463 struct atm_dev *dev;
464 struct atm_vcc *vcc = ATM_SD(sock);
465 int error;
466
Joe Perches99824462010-01-26 11:40:00 +0000467 pr_debug("(vpi %d, vci %d)\n", vpi, vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (sock->state == SS_CONNECTED)
469 return -EISCONN;
470 if (sock->state != SS_UNCONNECTED)
471 return -EINVAL;
472 if (!(vpi || vci))
473 return -EINVAL;
474
475 if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC)
Joe Perchesa8147d72010-01-26 11:40:06 +0000476 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 else
Joe Perchesa8147d72010-01-26 11:40:06 +0000478 if (test_bit(ATM_VF_PARTIAL, &vcc->flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 return -EINVAL;
Joe Perches99824462010-01-26 11:40:00 +0000480 pr_debug("(TX: cl %d,bw %d-%d,sdu %d; "
481 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
482 vcc->qos.txtp.traffic_class, vcc->qos.txtp.min_pcr,
483 vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_sdu,
484 vcc->qos.rxtp.traffic_class, vcc->qos.rxtp.min_pcr,
Joe Perchesa8147d72010-01-26 11:40:06 +0000485 vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_sdu,
Joe Perches99824462010-01-26 11:40:00 +0000486 vcc->qos.aal == ATM_AAL5 ? "" :
487 vcc->qos.aal == ATM_AAL0 ? "" : " ??? code ",
488 vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
490 return -EBADFD;
491 if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
492 vcc->qos.rxtp.traffic_class == ATM_ANYCLASS)
493 return -EINVAL;
Mitchell Blank Jrc9933d02005-11-29 16:13:32 -0800494 if (likely(itf != ATM_ITF_ANY)) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000495 dev = try_then_request_module(atm_dev_lookup(itf),
496 "atm-device-%d", itf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 dev = NULL;
Ingo Molnar57b47a52006-03-20 22:35:41 -0800499 mutex_lock(&atm_dev_mutex);
Mitchell Blank Jrc9933d02005-11-29 16:13:32 -0800500 if (!list_empty(&atm_devs)) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000501 dev = list_entry(atm_devs.next,
502 struct atm_dev, dev_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 atm_dev_hold(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
Ingo Molnar57b47a52006-03-20 22:35:41 -0800505 mutex_unlock(&atm_dev_mutex);
Mitchell Blank Jrc9933d02005-11-29 16:13:32 -0800506 }
507 if (!dev)
508 return -ENODEV;
509 error = __vcc_connect(vcc, dev, vpi, vci);
510 if (error) {
511 atm_dev_put(dev);
512 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514 if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
Joe Perchesa8147d72010-01-26 11:40:06 +0000515 set_bit(ATM_VF_PARTIAL, &vcc->flags);
516 if (test_bit(ATM_VF_READY, &ATM_SD(sock)->flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 sock->state = SS_CONNECTED;
518 return 0;
519}
520
Ying Xue1b784142015-03-02 15:37:48 +0800521int vcc_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
522 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
524 struct sock *sk = sock->sk;
525 struct atm_vcc *vcc;
526 struct sk_buff *skb;
527 int copied, error = -EINVAL;
528
529 if (sock->state != SS_CONNECTED)
530 return -ENOTCONN;
Jorge Boncompte [DTI2]40ba8492011-11-21 10:25:58 +0000531
532 /* only handle MSG_DONTWAIT and MSG_PEEK */
533 if (flags & ~(MSG_DONTWAIT | MSG_PEEK))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 return -EOPNOTSUPP;
Jorge Boncompte [DTI2]40ba8492011-11-21 10:25:58 +0000535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 vcc = ATM_SD(sock);
Joe Perchesa8147d72010-01-26 11:40:06 +0000537 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
538 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 !test_bit(ATM_VF_READY, &vcc->flags))
540 return 0;
541
542 skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &error);
543 if (!skb)
544 return error;
545
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900546 copied = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 if (copied > size) {
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900548 copied = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 msg->msg_flags |= MSG_TRUNC;
550 }
551
David S. Miller51f3d022014-11-05 16:46:40 -0500552 error = skb_copy_datagram_msg(skb, 0, msg, copied);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900553 if (error)
554 return error;
Neil Horman3b885782009-10-12 13:26:31 -0700555 sock_recv_ts_and_drops(msg, sk, skb);
Jorge Boncompte [DTI2]40ba8492011-11-21 10:25:58 +0000556
557 if (!(flags & MSG_PEEK)) {
558 pr_debug("%d -= %d\n", atomic_read(&sk->sk_rmem_alloc),
559 skb->truesize);
560 atm_return(vcc, skb->truesize);
561 }
562
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900563 skb_free_datagram(sk, skb);
564 return copied;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
Ying Xue1b784142015-03-02 15:37:48 +0800567int vcc_sendmsg(struct socket *sock, struct msghdr *m, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
569 struct sock *sk = sock->sk;
570 DEFINE_WAIT(wait);
571 struct atm_vcc *vcc;
572 struct sk_buff *skb;
Joe Perchesa8147d72010-01-26 11:40:06 +0000573 int eff, error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
575 lock_sock(sk);
576 if (sock->state != SS_CONNECTED) {
577 error = -ENOTCONN;
578 goto out;
579 }
580 if (m->msg_name) {
581 error = -EISCONN;
582 goto out;
583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 vcc = ATM_SD(sock);
585 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
586 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
587 !test_bit(ATM_VF_READY, &vcc->flags)) {
588 error = -EPIPE;
589 send_sig(SIGPIPE, current, 0);
590 goto out;
591 }
592 if (!size) {
593 error = 0;
594 goto out;
595 }
Al Viro7424ce62014-11-20 07:01:29 -0500596 if (size > vcc->qos.txtp.max_sdu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 error = -EMSGSIZE;
598 goto out;
599 }
Jesper Juhle49332b2005-05-01 08:59:08 -0700600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 eff = (size+3) & ~3; /* align to word boundary */
Eric Dumazetaa395142010-04-20 13:03:51 +0000602 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 error = 0;
Francois Romieuc55fa3c2017-03-11 19:41:36 -0500604 while (!vcc_tx_ready(vcc, eff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 if (m->msg_flags & MSG_DONTWAIT) {
606 error = -EAGAIN;
607 break;
608 }
609 schedule();
610 if (signal_pending(current)) {
611 error = -ERESTARTSYS;
612 break;
613 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000614 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
615 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
616 !test_bit(ATM_VF_READY, &vcc->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 error = -EPIPE;
618 send_sig(SIGPIPE, current, 0);
619 break;
620 }
Eric Dumazetaa395142010-04-20 13:03:51 +0000621 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 }
Eric Dumazetaa395142010-04-20 13:03:51 +0000623 finish_wait(sk_sleep(sk), &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (error)
625 goto out;
Francois Romieuc55fa3c2017-03-11 19:41:36 -0500626
627 skb = alloc_skb(eff, GFP_KERNEL);
628 if (!skb) {
629 error = -ENOMEM;
630 goto out;
631 }
632 pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize);
David Woodhouse9bbe60a2018-06-16 11:55:44 +0100633 atm_account_tx(vcc, skb);
Francois Romieuc55fa3c2017-03-11 19:41:36 -0500634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 skb->dev = NULL; /* for paths shared with net_device interfaces */
Al Virocbbd26b2016-11-01 22:09:04 -0400636 if (!copy_from_iter_full(skb_put(skb, size), size, &m->msg_iter)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 kfree_skb(skb);
638 error = -EFAULT;
639 goto out;
640 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000641 if (eff != size)
642 memset(skb->data + size, 0, eff-size);
643 error = vcc->dev->ops->send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 error = error ? error : size;
645out:
646 release_sock(sk);
647 return error;
648}
649
Linus Torvaldsa11e1d42018-06-28 09:43:44 -0700650__poll_t vcc_poll(struct file *file, struct socket *sock, poll_table *wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
652 struct sock *sk = sock->sk;
Linus Torvaldsa11e1d42018-06-28 09:43:44 -0700653 struct atm_vcc *vcc;
654 __poll_t mask;
655
656 sock_poll_wait(file, sk_sleep(sk), wait);
657 mask = 0;
658
659 vcc = ATM_SD(sock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661 /* exceptional events */
662 if (sk->sk_err)
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800663 mask = EPOLLERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
666 test_bit(ATM_VF_CLOSE, &vcc->flags))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800667 mask |= EPOLLHUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669 /* readable? */
670 if (!skb_queue_empty(&sk->sk_receive_queue))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800671 mask |= EPOLLIN | EPOLLRDNORM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 /* writable? */
674 if (sock->state == SS_CONNECTING &&
675 test_bit(ATM_VF_WAITING, &vcc->flags))
676 return mask;
677
678 if (vcc->qos.txtp.traffic_class != ATM_NONE &&
679 vcc_writable(sk))
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800680 mask |= EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 return mask;
683}
684
Joe Perchesa8147d72010-01-26 11:40:06 +0000685static int atm_change_qos(struct atm_vcc *vcc, struct atm_qos *qos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
687 int error;
688
689 /*
690 * Don't let the QoS change the already connected AAL type nor the
691 * traffic class.
692 */
693 if (qos->aal != vcc->qos.aal ||
694 qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class ||
695 qos->txtp.traffic_class != vcc->qos.txtp.traffic_class)
696 return -EINVAL;
Joe Perchesa8147d72010-01-26 11:40:06 +0000697 error = adjust_tp(&qos->txtp, qos->aal);
698 if (!error)
699 error = adjust_tp(&qos->rxtp, qos->aal);
700 if (error)
701 return error;
702 if (!vcc->dev->ops->change_qos)
703 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (sk_atm(vcc)->sk_family == AF_ATMPVC)
Joe Perchesa8147d72010-01-26 11:40:06 +0000705 return vcc->dev->ops->change_qos(vcc, qos, ATM_MF_SET);
706 return svc_change_qos(vcc, qos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700709static int check_tp(const struct atm_trafprm *tp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
711 /* @@@ Should be merged with adjust_tp */
Joe Perchesa8147d72010-01-26 11:40:06 +0000712 if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS)
713 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
Joe Perchesa8147d72010-01-26 11:40:06 +0000715 !tp->max_pcr)
716 return -EINVAL;
717 if (tp->min_pcr == ATM_MAX_PCR)
718 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR &&
Joe Perchesa8147d72010-01-26 11:40:06 +0000720 tp->min_pcr > tp->max_pcr)
721 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 /*
723 * We allow pcr to be outside [min_pcr,max_pcr], because later
724 * adjustment may still push it in the valid range.
725 */
726 return 0;
727}
728
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700729static int check_qos(const struct atm_qos *qos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
731 int error;
732
733 if (!qos->txtp.traffic_class && !qos->rxtp.traffic_class)
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900734 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
736 qos->txtp.traffic_class && qos->rxtp.traffic_class &&
737 qos->txtp.traffic_class != ATM_ANYCLASS &&
Joe Perchesa8147d72010-01-26 11:40:06 +0000738 qos->rxtp.traffic_class != ATM_ANYCLASS)
739 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 error = check_tp(&qos->txtp);
Joe Perchesa8147d72010-01-26 11:40:06 +0000741 if (error)
742 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 return check_tp(&qos->rxtp);
744}
745
746int vcc_setsockopt(struct socket *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700747 char __user *optval, unsigned int optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
749 struct atm_vcc *vcc;
750 unsigned long value;
751 int error;
752
753 if (__SO_LEVEL_MATCH(optname, level) && optlen != __SO_SIZE(optname))
754 return -EINVAL;
755
756 vcc = ATM_SD(sock);
757 switch (optname) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000758 case SO_ATMQOS:
759 {
760 struct atm_qos qos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Joe Perchesa8147d72010-01-26 11:40:06 +0000762 if (copy_from_user(&qos, optval, sizeof(qos)))
763 return -EFAULT;
764 error = check_qos(&qos);
765 if (error)
766 return error;
767 if (sock->state == SS_CONNECTED)
768 return atm_change_qos(vcc, &qos);
769 if (sock->state != SS_UNCONNECTED)
770 return -EBADFD;
771 vcc->qos = qos;
772 set_bit(ATM_VF_HASQOS, &vcc->flags);
773 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000775 case SO_SETCLP:
776 if (get_user(value, (unsigned long __user *)optval))
777 return -EFAULT;
778 if (value)
779 vcc->atm_options |= ATM_ATMOPT_CLP;
780 else
781 vcc->atm_options &= ~ATM_ATMOPT_CLP;
782 return 0;
783 default:
784 if (level == SOL_SOCKET)
785 return -EINVAL;
786 break;
787 }
788 if (!vcc->dev || !vcc->dev->ops->setsockopt)
789 return -EINVAL;
790 return vcc->dev->ops->setsockopt(vcc, level, optname, optval, optlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791}
792
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793int vcc_getsockopt(struct socket *sock, int level, int optname,
794 char __user *optval, int __user *optlen)
795{
796 struct atm_vcc *vcc;
797 int len;
798
799 if (get_user(len, optlen))
800 return -EFAULT;
801 if (__SO_LEVEL_MATCH(optname, level) && len != __SO_SIZE(optname))
802 return -EINVAL;
803
804 vcc = ATM_SD(sock);
805 switch (optname) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000806 case SO_ATMQOS:
807 if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
808 return -EINVAL;
809 return copy_to_user(optval, &vcc->qos, sizeof(vcc->qos))
810 ? -EFAULT : 0;
811 case SO_SETCLP:
812 return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : 0,
813 (unsigned long __user *)optval) ? -EFAULT : 0;
814 case SO_ATMPVC:
815 {
816 struct sockaddr_atmpvc pvc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Joe Perchesa8147d72010-01-26 11:40:06 +0000818 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
819 return -ENOTCONN;
Mathias Krausee862f1a2012-08-15 11:31:44 +0000820 memset(&pvc, 0, sizeof(pvc));
Joe Perchesa8147d72010-01-26 11:40:06 +0000821 pvc.sap_family = AF_ATMPVC;
822 pvc.sap_addr.itf = vcc->dev->number;
823 pvc.sap_addr.vpi = vcc->vpi;
824 pvc.sap_addr.vci = vcc->vci;
825 return copy_to_user(optval, &pvc, sizeof(pvc)) ? -EFAULT : 0;
826 }
827 default:
828 if (level == SOL_SOCKET)
829 return -EINVAL;
Julia Lawall510a05e2010-08-05 10:19:00 +0000830 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000832 if (!vcc->dev || !vcc->dev->ops->getsockopt)
833 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len);
835}
836
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000837int register_atmdevice_notifier(struct notifier_block *nb)
838{
839 return atomic_notifier_chain_register(&atm_dev_notify_chain, nb);
840}
841EXPORT_SYMBOL_GPL(register_atmdevice_notifier);
842
843void unregister_atmdevice_notifier(struct notifier_block *nb)
844{
845 atomic_notifier_chain_unregister(&atm_dev_notify_chain, nb);
846}
847EXPORT_SYMBOL_GPL(unregister_atmdevice_notifier);
848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849static int __init atm_init(void)
850{
851 int error;
852
Joe Perchesa8147d72010-01-26 11:40:06 +0000853 error = proto_register(&vcc_proto, 0);
854 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 goto out;
Joe Perchesa8147d72010-01-26 11:40:06 +0000856 error = atmpvc_init();
857 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000858 pr_err("atmpvc_init() failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 goto out_unregister_vcc_proto;
860 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000861 error = atmsvc_init();
862 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000863 pr_err("atmsvc_init() failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 goto out_atmpvc_exit;
865 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000866 error = atm_proc_init();
867 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000868 pr_err("atm_proc_init() failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 goto out_atmsvc_exit;
870 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000871 error = atm_sysfs_init();
872 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000873 pr_err("atm_sysfs_init() failed with %d\n", error);
Roman Kagan656d98b2006-06-29 12:36:34 -0700874 goto out_atmproc_exit;
875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876out:
877 return error;
Roman Kagan656d98b2006-06-29 12:36:34 -0700878out_atmproc_exit:
879 atm_proc_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880out_atmsvc_exit:
881 atmsvc_exit();
882out_atmpvc_exit:
883 atmsvc_exit();
884out_unregister_vcc_proto:
885 proto_unregister(&vcc_proto);
886 goto out;
887}
888
889static void __exit atm_exit(void)
890{
891 atm_proc_exit();
Roman Kagan656d98b2006-06-29 12:36:34 -0700892 atm_sysfs_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 atmsvc_exit();
894 atmpvc_exit();
895 proto_unregister(&vcc_proto);
896}
897
Daniel Walker84ff6022007-02-05 18:04:06 -0800898subsys_initcall(atm_init);
899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900module_exit(atm_exit);
901
902MODULE_LICENSE("GPL");
903MODULE_ALIAS_NETPROTO(PF_ATMPVC);
904MODULE_ALIAS_NETPROTO(PF_ATMSVC);