Blame view

net/atm/pppoatm.c 15.5 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  /* net/atm/pppoatm.c - RFC2364 PPP over ATM/AAL5 */
  
  /* Copyright 1999-2000 by Mitchell Blank Jr */
  /* Based on clip.c; 1995-1999 by Werner Almesberger, EPFL LRC/ICA */
  /* And on ppp_async.c; Copyright 1999 Paul Mackerras */
  /* And help from Jens Axboe */
  
  /*
   *  This program is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU General Public License
   *  as published by the Free Software Foundation; either version
   *  2 of the License, or (at your option) any later version.
   *
   * This driver provides the encapsulation and framing for sending
   * and receiving PPP frames in ATM AAL5 PDUs.
   */
  
  /*
   * One shortcoming of this driver is that it does not comply with
   * section 8 of RFC2364 - we are supposed to detect a change
   * in encapsulation and immediately abort the connection (in order
   * to avoid a black-hole being created if our peer loses state
   * and changes encapsulation unilaterally.  However, since the
   * ppp_generic layer actually does the decapsulation, we need
   * a way of notifying it when we _think_ there might be a problem)
   * There's two cases:
   *   1.	LLC-encapsulation was missing when it was enabled.  In
   *	this case, we should tell the upper layer "tear down
   *	this session if this skb looks ok to you"
   *   2.	LLC-encapsulation was present when it was disabled.  Then
   *	we need to tell the upper layer "this packet may be
   *	ok, but if its in error tear down the session"
   * These hooks are not yet available in ppp_generic
   */
99824461e   Joe Perches   net/atm: Convert ...
35
  #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
  #include <linux/init.h>
a6b7a4078   Alexey Dobriyan   net: remove inter...
38
  #include <linux/interrupt.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
  #include <linux/skbuff.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
40
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
42
  #include <linux/atm.h>
  #include <linux/atmdev.h>
4fc268d24   Randy Dunlap   [PATCH] capable/c...
43
  #include <linux/capability.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
  #include <linux/ppp_defs.h>
4b32da2bc   Paul Mackerras   ppp: Replace uses...
45
  #include <linux/ppp-ioctl.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
  #include <linux/ppp_channel.h>
  #include <linux/atmppp.h>
  
  #include "common.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
52
53
54
55
56
57
58
59
  enum pppoatm_encaps {
  	e_autodetect = PPPOATM_ENCAPS_AUTODETECT,
  	e_vc = PPPOATM_ENCAPS_VC,
  	e_llc = PPPOATM_ENCAPS_LLC,
  };
  
  struct pppoatm_vcc {
  	struct atm_vcc	*atmvcc;	/* VCC descriptor */
  	void (*old_push)(struct atm_vcc *, struct sk_buff *);
  	void (*old_pop)(struct atm_vcc *, struct sk_buff *);
0e56d99a5   David Woodhouse   pppoatm: fix miss...
60
  	void (*old_release_cb)(struct atm_vcc *);
e41faed9c   Krzysztof Mazur   pppoatm: fix modu...
61
  	struct module *old_owner;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
  					/* keep old push/pop for detaching */
  	enum pppoatm_encaps encaps;
9d02daf75   David Woodhouse   pppoatm: Fix exce...
64
65
  	atomic_t inflight;
  	unsigned long blocked;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
71
  	int flags;			/* SC_COMP_PROT - compress protocol */
  	struct ppp_channel chan;	/* interface to generic ppp layer */
  	struct tasklet_struct wakeup_tasklet;
  };
  
  /*
9d02daf75   David Woodhouse   pppoatm: Fix exce...
72
73
74
75
76
77
78
79
80
81
82
   * We want to allow two packets in the queue. The one that's currently in
   * flight, and *one* queued up ready for the ATM device to send immediately
   * from its TX done IRQ. We want to be able to use atomic_inc_not_zero(), so
   * inflight == -2 represents an empty queue, -1 one packet, and zero means
   * there are two packets in the queue.
   */
  #define NONE_INFLIGHT -2
  
  #define BLOCKED 0
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
   * Header used for LLC Encapsulated PPP (4 bytes) followed by the LCP protocol
   * ID (0xC021) used in autodetection
   */
  static const unsigned char pppllc[6] = { 0xFE, 0xFE, 0x03, 0xCF, 0xC0, 0x21 };
  #define LLC_LEN		(4)
  
  static inline struct pppoatm_vcc *atmvcc_to_pvcc(const struct atm_vcc *atmvcc)
  {
  	return (struct pppoatm_vcc *) (atmvcc->user_back);
  }
  
  static inline struct pppoatm_vcc *chan_to_pvcc(const struct ppp_channel *chan)
  {
  	return (struct pppoatm_vcc *) (chan->private);
  }
  
  /*
   * We can't do this directly from our _pop handler, since the ppp code
   * doesn't want to be called in interrupt context, so we do it from
   * a tasklet
   */
  static void pppoatm_wakeup_sender(unsigned long arg)
  {
  	ppp_output_wakeup((struct ppp_channel *) arg);
  }
0e56d99a5   David Woodhouse   pppoatm: fix miss...
108
109
110
  static void pppoatm_release_cb(struct atm_vcc *atmvcc)
  {
  	struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc);
5b4d72080   David Woodhouse   pppoatm: optimise...
111
112
113
114
115
116
117
118
119
120
121
  	/*
  	 * As in pppoatm_pop(), it's safe to clear the BLOCKED bit here because
  	 * the wakeup *can't* race with pppoatm_send(). They both hold the PPP
  	 * channel's ->downl lock. And the potential race with *setting* it,
  	 * which leads to the double-check dance in pppoatm_may_send(), doesn't
  	 * exist here. In the sock_owned_by_user() case in pppoatm_send(), we
  	 * set the BLOCKED bit while the socket is still locked. We know that
  	 * ->release_cb() can't be called until that's done.
  	 */
  	if (test_and_clear_bit(BLOCKED, &pvcc->blocked))
  		tasklet_schedule(&pvcc->wakeup_tasklet);
0e56d99a5   David Woodhouse   pppoatm: fix miss...
122
123
124
  	if (pvcc->old_release_cb)
  		pvcc->old_release_cb(atmvcc);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
126
127
128
129
130
131
132
  /*
   * This gets called every time the ATM card has finished sending our
   * skb.  The ->old_pop will take care up normal atm flow control,
   * but we also need to wake up the device if we blocked it
   */
  static void pppoatm_pop(struct atm_vcc *atmvcc, struct sk_buff *skb)
  {
  	struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc);
9d02daf75   David Woodhouse   pppoatm: Fix exce...
133

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
  	pvcc->old_pop(atmvcc, skb);
9d02daf75   David Woodhouse   pppoatm: Fix exce...
135
  	atomic_dec(&pvcc->inflight);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
  	/*
9d02daf75   David Woodhouse   pppoatm: Fix exce...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  	 * We always used to run the wakeup tasklet unconditionally here, for
  	 * fear of race conditions where we clear the BLOCKED flag just as we
  	 * refuse another packet in pppoatm_send(). This was quite inefficient.
  	 *
  	 * In fact it's OK. The PPP core will only ever call pppoatm_send()
  	 * while holding the channel->downl lock. And ppp_output_wakeup() as
  	 * called by the tasklet will *also* grab that lock. So even if another
  	 * CPU is in pppoatm_send() right now, the tasklet isn't going to race
  	 * with it. The wakeup *will* happen after the other CPU is safely out
  	 * of pppoatm_send() again.
  	 *
  	 * So if the CPU in pppoatm_send() has already set the BLOCKED bit and
  	 * it about to return, that's fine. We trigger a wakeup which will
  	 * happen later. And if the CPU in pppoatm_send() *hasn't* set the
  	 * BLOCKED bit yet, that's fine too because of the double check in
  	 * pppoatm_may_send() which is commented there.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
  	 */
9d02daf75   David Woodhouse   pppoatm: Fix exce...
154
155
  	if (test_and_clear_bit(BLOCKED, &pvcc->blocked))
  		tasklet_schedule(&pvcc->wakeup_tasklet);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
158
159
160
161
162
163
164
165
166
167
  }
  
  /*
   * Unbind from PPP - currently we only do this when closing the socket,
   * but we could put this into an ioctl if need be
   */
  static void pppoatm_unassign_vcc(struct atm_vcc *atmvcc)
  {
  	struct pppoatm_vcc *pvcc;
  	pvcc = atmvcc_to_pvcc(atmvcc);
  	atmvcc->push = pvcc->old_push;
  	atmvcc->pop = pvcc->old_pop;
0e56d99a5   David Woodhouse   pppoatm: fix miss...
168
  	atmvcc->release_cb = pvcc->old_release_cb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
170
171
172
  	tasklet_kill(&pvcc->wakeup_tasklet);
  	ppp_unregister_channel(&pvcc->chan);
  	atmvcc->user_back = NULL;
  	kfree(pvcc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
173
174
175
176
177
178
  }
  
  /* Called when an AAL5 PDU comes in */
  static void pppoatm_push(struct atm_vcc *atmvcc, struct sk_buff *skb)
  {
  	struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc);
99824461e   Joe Perches   net/atm: Convert ...
179
180
  	pr_debug("
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
181
  	if (skb == NULL) {			/* VCC was closed */
e41faed9c   Krzysztof Mazur   pppoatm: fix modu...
182
  		struct module *module;
522400623   Stephen Hemminger   [ATM]: Replace DP...
183
184
  		pr_debug("removing ATMPPP VCC %p
  ", pvcc);
e41faed9c   Krzysztof Mazur   pppoatm: fix modu...
185
  		module = pvcc->old_owner;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
187
  		pppoatm_unassign_vcc(atmvcc);
  		atmvcc->push(atmvcc, NULL);	/* Pass along bad news */
e41faed9c   Krzysztof Mazur   pppoatm: fix modu...
188
  		module_put(module);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
  		return;
  	}
  	atm_return(atmvcc, skb->truesize);
  	switch (pvcc->encaps) {
  	case e_llc:
  		if (skb->len < LLC_LEN ||
  		    memcmp(skb->data, pppllc, LLC_LEN))
  			goto error;
  		skb_pull(skb, LLC_LEN);
  		break;
  	case e_autodetect:
  		if (pvcc->chan.ppp == NULL) {	/* Not bound yet! */
  			kfree_skb(skb);
  			return;
  		}
  		if (skb->len >= sizeof(pppllc) &&
  		    !memcmp(skb->data, pppllc, sizeof(pppllc))) {
  			pvcc->encaps = e_llc;
  			skb_pull(skb, LLC_LEN);
  			break;
  		}
  		if (skb->len >= (sizeof(pppllc) - LLC_LEN) &&
  		    !memcmp(skb->data, &pppllc[LLC_LEN],
  		    sizeof(pppllc) - LLC_LEN)) {
  			pvcc->encaps = e_vc;
  			pvcc->chan.mtu += LLC_LEN;
  			break;
  		}
99824461e   Joe Perches   net/atm: Convert ...
217
218
219
220
  		pr_debug("Couldn't autodetect yet (skb: %02X %02X %02X %02X %02X %02X)
  ",
  			 skb->data[0], skb->data[1], skb->data[2],
  			 skb->data[3], skb->data[4], skb->data[5]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221
222
223
224
225
226
  		goto error;
  	case e_vc:
  		break;
  	}
  	ppp_input(&pvcc->chan, skb);
  	return;
d81219db6   Joe Perches   net/atm/pppoatm.c...
227
228
  
  error:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
229
230
231
  	kfree_skb(skb);
  	ppp_input_error(&pvcc->chan, 0);
  }
397ff16dc   Krzysztof Mazur   pppoatm: do not i...
232
  static int pppoatm_may_send(struct pppoatm_vcc *pvcc, int size)
9d02daf75   David Woodhouse   pppoatm: Fix exce...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
  {
  	/*
  	 * It's not clear that we need to bother with using atm_may_send()
  	 * to check we don't exceed sk->sk_sndbuf. If userspace sets a
  	 * value of sk_sndbuf which is lower than the MTU, we're going to
  	 * block for ever. But the code always did that before we introduced
  	 * the packet count limit, so...
  	 */
  	if (atm_may_send(pvcc->atmvcc, size) &&
  	    atomic_inc_not_zero_hint(&pvcc->inflight, NONE_INFLIGHT))
  		return 1;
  
  	/*
  	 * We use test_and_set_bit() rather than set_bit() here because
  	 * we need to ensure there's a memory barrier after it. The bit
  	 * *must* be set before we do the atomic_inc() on pvcc->inflight.
  	 * There's no smp_mb__after_set_bit(), so it's this or abuse
4e857c58e   Peter Zijlstra   arch: Mass conver...
250
  	 * smp_mb__after_atomic().
9d02daf75   David Woodhouse   pppoatm: Fix exce...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  	 */
  	test_and_set_bit(BLOCKED, &pvcc->blocked);
  
  	/*
  	 * We may have raced with pppoatm_pop(). If it ran for the
  	 * last packet in the queue, *just* before we set the BLOCKED
  	 * bit, then it might never run again and the channel could
  	 * remain permanently blocked. Cope with that race by checking
  	 * *again*. If it did run in that window, we'll have space on
  	 * the queue now and can return success. It's harmless to leave
  	 * the BLOCKED flag set, since it's only used as a trigger to
  	 * run the wakeup tasklet. Another wakeup will never hurt.
  	 * If pppoatm_pop() is running but hasn't got as far as making
  	 * space on the queue yet, then it hasn't checked the BLOCKED
  	 * flag yet either, so we're safe in that case too. It'll issue
  	 * an "immediate" wakeup... where "immediate" actually involves
  	 * taking the PPP channel's ->downl lock, which is held by the
  	 * code path that calls pppoatm_send(), and is thus going to
  	 * wait for us to finish.
  	 */
  	if (atm_may_send(pvcc->atmvcc, size) &&
  	    atomic_inc_not_zero(&pvcc->inflight))
  		return 1;
  
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
277
278
279
280
281
282
283
284
285
286
287
288
289
  /*
   * Called by the ppp_generic.c to send a packet - returns true if packet
   * was accepted.  If we return false, then it's our job to call
   * ppp_output_wakeup(chan) when we're feeling more up to it.
   * Note that in the ENOMEM case (as opposed to the !atm_may_send case)
   * we should really drop the packet, but the generic layer doesn't
   * support this yet.  We just return 'DROP_PACKET' which we actually define
   * as success, just to be clear what we're really doing.
   */
  #define DROP_PACKET 1
  static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)
  {
  	struct pppoatm_vcc *pvcc = chan_to_pvcc(chan);
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
290
291
  	struct atm_vcc *vcc;
  	int ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
  	ATM_SKB(skb)->vcc = pvcc->atmvcc;
99824461e   Joe Perches   net/atm: Convert ...
293
294
  	pr_debug("(skb=0x%p, vcc=0x%p)
  ", skb, pvcc->atmvcc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
295
296
  	if (skb->data[0] == '\0' && (pvcc->flags & SC_COMP_PROT))
  		(void) skb_pull(skb, 1);
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
297
298
299
  
  	vcc = ATM_SKB(skb)->vcc;
  	bh_lock_sock(sk_atm(vcc));
5b4d72080   David Woodhouse   pppoatm: optimise...
300
301
302
303
304
305
306
  	if (sock_owned_by_user(sk_atm(vcc))) {
  		/*
  		 * Needs to happen (and be flushed, hence test_and_) before we unlock
  		 * the socket. It needs to be seen by the time our ->release_cb gets
  		 * called.
  		 */
  		test_and_set_bit(BLOCKED, &pvcc->blocked);
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
307
  		goto nospace;
5b4d72080   David Woodhouse   pppoatm: optimise...
308
  	}
071d93931   Krzysztof Mazur   pppoatm: drop fra...
309
310
311
312
313
314
315
  	if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
  	    test_bit(ATM_VF_CLOSE, &vcc->flags) ||
  	    !test_bit(ATM_VF_READY, &vcc->flags)) {
  		bh_unlock_sock(sk_atm(vcc));
  		kfree_skb(skb);
  		return DROP_PACKET;
  	}
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
316

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
318
319
320
321
322
  	switch (pvcc->encaps) {		/* LLC encapsulation needed */
  	case e_llc:
  		if (skb_headroom(skb) < LLC_LEN) {
  			struct sk_buff *n;
  			n = skb_realloc_headroom(skb, LLC_LEN);
  			if (n != NULL &&
9d02daf75   David Woodhouse   pppoatm: Fix exce...
323
  			    !pppoatm_may_send(pvcc, n->truesize)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
324
325
326
  				kfree_skb(n);
  				goto nospace;
  			}
5d0ba55b6   Eric Dumazet   net: use consume_...
327
  			consume_skb(skb);
d81219db6   Joe Perches   net/atm/pppoatm.c...
328
  			skb = n;
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
329
330
  			if (skb == NULL) {
  				bh_unlock_sock(sk_atm(vcc));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
331
  				return DROP_PACKET;
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
332
  			}
9d02daf75   David Woodhouse   pppoatm: Fix exce...
333
  		} else if (!pppoatm_may_send(pvcc, skb->truesize))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
334
335
336
337
  			goto nospace;
  		memcpy(skb_push(skb, LLC_LEN), pppllc, LLC_LEN);
  		break;
  	case e_vc:
9d02daf75   David Woodhouse   pppoatm: Fix exce...
338
  		if (!pppoatm_may_send(pvcc, skb->truesize))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339
340
341
  			goto nospace;
  		break;
  	case e_autodetect:
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
342
  		bh_unlock_sock(sk_atm(vcc));
522400623   Stephen Hemminger   [ATM]: Replace DP...
343
344
  		pr_debug("Trying to send without setting encaps!
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345
346
347
  		kfree_skb(skb);
  		return 1;
  	}
f93d65939   David Woodhouse   atm: Preserve val...
348
  	atm_account_tx(vcc, skb);
99824461e   Joe Perches   net/atm: Convert ...
349
350
351
  	pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)
  ",
  		 skb, ATM_SKB(skb)->vcc, ATM_SKB(skb)->vcc->dev);
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
352
  	ret = ATM_SKB(skb)->vcc->send(ATM_SKB(skb)->vcc, skb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
353
  	    ? DROP_PACKET : 1;
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
354
355
  	bh_unlock_sock(sk_atm(vcc));
  	return ret;
d81219db6   Joe Perches   net/atm/pppoatm.c...
356
  nospace:
3ac108006   Krzysztof Mazur   pppoatm: take ATM...
357
  	bh_unlock_sock(sk_atm(vcc));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
  	/*
  	 * We don't have space to send this SKB now, but we might have
  	 * already applied SC_COMP_PROT compression, so may need to undo
  	 */
  	if ((pvcc->flags & SC_COMP_PROT) && skb_headroom(skb) > 0 &&
  	    skb->data[-1] == '\0')
  		(void) skb_push(skb, 1);
  	return 0;
  }
  
  /* This handles ioctls sent to the /dev/ppp interface */
  static int pppoatm_devppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
  	unsigned long arg)
  {
  	switch (cmd) {
  	case PPPIOCGFLAGS:
  		return put_user(chan_to_pvcc(chan)->flags, (int __user *) arg)
  		    ? -EFAULT : 0;
  	case PPPIOCSFLAGS:
  		return get_user(chan_to_pvcc(chan)->flags, (int __user *) arg)
  		    ? -EFAULT : 0;
  	}
  	return -ENOTTY;
  }
d7100da02   stephen hemminger   ppp: make channel...
382
  static const struct ppp_channel_ops pppoatm_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
  	.start_xmit = pppoatm_send,
  	.ioctl = pppoatm_devppp_ioctl,
  };
  
  static int pppoatm_assign_vcc(struct atm_vcc *atmvcc, void __user *arg)
  {
  	struct atm_backend_ppp be;
  	struct pppoatm_vcc *pvcc;
  	int err;
  	/*
  	 * Each PPPoATM instance has its own tasklet - this is just a
  	 * prototypical one used to initialize them
  	 */
  	static const DECLARE_TASKLET(tasklet_proto, pppoatm_wakeup_sender, 0);
  	if (copy_from_user(&be, arg, sizeof be))
  		return -EFAULT;
  	if (be.encaps != PPPOATM_ENCAPS_AUTODETECT &&
  	    be.encaps != PPPOATM_ENCAPS_VC && be.encaps != PPPOATM_ENCAPS_LLC)
  		return -EINVAL;
0da974f4f   Panagiotis Issaris   [NET]: Conversion...
402
  	pvcc = kzalloc(sizeof(*pvcc), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
403
404
  	if (pvcc == NULL)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
405
  	pvcc->atmvcc = atmvcc;
9d02daf75   David Woodhouse   pppoatm: Fix exce...
406
407
408
  
  	/* Maximum is zero, so that we can use atomic_inc_not_zero() */
  	atomic_set(&pvcc->inflight, NONE_INFLIGHT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
  	pvcc->old_push = atmvcc->push;
  	pvcc->old_pop = atmvcc->pop;
e41faed9c   Krzysztof Mazur   pppoatm: fix modu...
411
  	pvcc->old_owner = atmvcc->owner;
0e56d99a5   David Woodhouse   pppoatm: fix miss...
412
  	pvcc->old_release_cb = atmvcc->release_cb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
413
414
415
416
417
418
419
  	pvcc->encaps = (enum pppoatm_encaps) be.encaps;
  	pvcc->chan.private = pvcc;
  	pvcc->chan.ops = &pppoatm_ops;
  	pvcc->chan.mtu = atmvcc->qos.txtp.max_sdu - PPP_HDRLEN -
  	    (be.encaps == e_vc ? 0 : LLC_LEN);
  	pvcc->wakeup_tasklet = tasklet_proto;
  	pvcc->wakeup_tasklet.data = (unsigned long) &pvcc->chan;
d81219db6   Joe Perches   net/atm/pppoatm.c...
420
421
  	err = ppp_register_channel(&pvcc->chan);
  	if (err != 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
422
423
424
425
426
427
  		kfree(pvcc);
  		return err;
  	}
  	atmvcc->user_back = pvcc;
  	atmvcc->push = pppoatm_push;
  	atmvcc->pop = pppoatm_pop;
0e56d99a5   David Woodhouse   pppoatm: fix miss...
428
  	atmvcc->release_cb = pppoatm_release_cb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
429
  	__module_get(THIS_MODULE);
e41faed9c   Krzysztof Mazur   pppoatm: fix modu...
430
  	atmvcc->owner = THIS_MODULE;
4e55f5785   Jorge Boncompte [DTI2]   atm: Introduce vc...
431
432
433
434
  
  	/* re-process everything received between connection setup and
  	   backend setup */
  	vcc_process_recv_queue(atmvcc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
  	return 0;
  }
  
  /*
   * This handles ioctls actually performed on our vcc - we must return
   * -ENOIOCTLCMD for any unrecognized ioctl
   */
  static int pppoatm_ioctl(struct socket *sock, unsigned int cmd,
  	unsigned long arg)
  {
  	struct atm_vcc *atmvcc = ATM_SD(sock);
  	void __user *argp = (void __user *)arg;
  
  	if (cmd != ATM_SETBACKEND && atmvcc->push != pppoatm_push)
  		return -ENOIOCTLCMD;
  	switch (cmd) {
  	case ATM_SETBACKEND: {
  		atm_backend_t b;
  		if (get_user(b, (atm_backend_t __user *) argp))
  			return -EFAULT;
  		if (b != ATM_BACKEND_PPP)
  			return -ENOIOCTLCMD;
  		if (!capable(CAP_NET_ADMIN))
  			return -EPERM;
3b1a91459   Krzysztof Mazur   pppoatm: allow as...
459
460
  		if (sock->state != SS_CONNECTED)
  			return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
  		return pppoatm_assign_vcc(atmvcc, argp);
  		}
  	case PPPIOCGCHAN:
  		return put_user(ppp_channel_index(&atmvcc_to_pvcc(atmvcc)->
  		    chan), (int __user *) argp) ? -EFAULT : 0;
  	case PPPIOCGUNIT:
  		return put_user(ppp_unit_number(&atmvcc_to_pvcc(atmvcc)->
  		    chan), (int __user *) argp) ? -EFAULT : 0;
  	}
  	return -ENOIOCTLCMD;
  }
  
  static struct atm_ioctl pppoatm_ioctl_ops = {
  	.owner	= THIS_MODULE,
  	.ioctl	= pppoatm_ioctl,
  };
  
  static int __init pppoatm_init(void)
  {
  	register_atm_ioctl(&pppoatm_ioctl_ops);
  	return 0;
  }
  
  static void __exit pppoatm_exit(void)
  {
  	deregister_atm_ioctl(&pppoatm_ioctl_ops);
  }
  
  module_init(pppoatm_init);
  module_exit(pppoatm_exit);
  
  MODULE_AUTHOR("Mitchell Blank Jr <mitch@sfgoth.com>");
  MODULE_DESCRIPTION("RFC2364 PPP over ATM/AAL5");
  MODULE_LICENSE("GPL");