RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / net / ppp_generic.c
blob3c3d0478dc4e03a64d2aa12a9b206fc61a0850c1
1 /*
2 * Generic PPP layer for Linux.
4 * Copyright 1999-2002 Paul Mackerras.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * The generic PPP layer handles the PPP network interfaces, the
12 * /dev/ppp device, packet and VJ compression, and multilink.
13 * It talks to PPP `channels' via the interface defined in
14 * include/linux/ppp_channel.h. Channels provide the basic means for
15 * sending and receiving PPP frames on some kind of communications
16 * channel.
18 * Part of the code in this driver was inspired by the old async-only
19 * PPP driver, written by Michael Callahan and Al Longyear, and
20 * subsequently hacked by Paul Mackerras.
22 * ==FILEVERSION 20050110==
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/kmod.h>
28 #include <linux/init.h>
29 #include <linux/list.h>
30 #include <linux/netdevice.h>
31 #include <linux/poll.h>
32 #include <linux/ppp_defs.h>
33 #include <linux/filter.h>
34 #include <linux/if_ppp.h>
35 #include <linux/ppp_channel.h>
36 #include <linux/ppp-comp.h>
37 #include <linux/skbuff.h>
38 #include <linux/rtnetlink.h>
39 #include <linux/if_arp.h>
40 #include <linux/ip.h>
41 #include <linux/tcp.h>
42 #include <linux/spinlock.h>
43 #include <linux/smp_lock.h>
44 #include <linux/rwsem.h>
45 #include <linux/stddef.h>
46 #include <linux/device.h>
47 #include <linux/mutex.h>
48 #include <linux/ppp_async.h>
49 #include <net/slhc_vj.h>
50 #include <asm/atomic.h>
52 #ifdef HNDCTF
53 #define TYPEDEF_INT32
54 #include <ctf/hndctf.h>
55 #include <linux/if_pppox.h>
56 #endif
58 #define PPP_VERSION "2.4.2"
61 * Network protocols we support.
63 #define NP_IP 0 /* Internet Protocol V4 */
64 #define NP_IPV6 1 /* Internet Protocol V6 */
65 #define NP_IPX 2 /* IPX protocol */
66 #define NP_AT 3 /* Appletalk protocol */
67 #define NP_MPLS_UC 4 /* MPLS unicast */
68 #define NP_MPLS_MC 5 /* MPLS multicast */
69 #define NUM_NP 6 /* Number of NPs. */
71 #define MPHDRLEN 6 /* multilink protocol header length */
72 #define MPHDRLEN_SSN 4 /* ditto with short sequence numbers */
73 #define MIN_FRAG_SIZE 64
76 * An instance of /dev/ppp can be associated with either a ppp
77 * interface unit or a ppp channel. In both cases, file->private_data
78 * points to one of these.
80 struct ppp_file {
81 enum {
82 INTERFACE=1, CHANNEL
83 } kind;
84 struct sk_buff_head xq; /* pppd transmit queue */
85 struct sk_buff_head rq; /* receive queue for pppd */
86 wait_queue_head_t rwait; /* for poll on reading /dev/ppp */
87 atomic_t refcnt; /* # refs (incl /dev/ppp attached) */
88 int hdrlen; /* space to leave for headers */
89 int index; /* interface unit / channel number */
90 int dead; /* unit/channel has been shut down */
93 #define PF_TO_X(pf, X) ((X *)((char *)(pf) - offsetof(X, file)))
95 #define PF_TO_PPP(pf) PF_TO_X(pf, struct ppp)
96 #define PF_TO_CHANNEL(pf) PF_TO_X(pf, struct channel)
98 #define ROUNDUP(n, x) (((n) + (x) - 1) / (x))
101 * Data structure describing one ppp unit.
102 * A ppp unit corresponds to a ppp network interface device
103 * and represents a multilink bundle.
104 * It can have 0 or more ppp channels connected to it.
106 #ifdef HNDCTF
107 typedef struct channel channel_t;
108 #endif
110 struct ppp {
111 struct ppp_file file; /* stuff for read/write/poll 0 */
112 struct file *owner; /* file that owns this unit 48 */
113 struct list_head channels; /* list of attached channels 4c */
114 int n_channels; /* how many channels are attached 54 */
115 spinlock_t rlock; /* lock for receive side 58 */
116 spinlock_t wlock; /* lock for transmit side 5c */
117 int mru; /* max receive unit 60 */
118 int mru_alloc; /* MAX(1500,MRU) for dev_alloc_skb() */
119 unsigned int flags; /* control bits 64 */
120 unsigned int xstate; /* transmit state bits 68 */
121 unsigned int rstate; /* receive state bits 6c */
122 int debug; /* debug flags 70 */
123 struct slcompress *vj; /* state for VJ header compression */
124 enum NPmode npmode[NUM_NP]; /* what to do with each net proto 78 */
125 struct sk_buff *xmit_pending; /* a packet ready to go out 88 */
126 struct compressor *xcomp; /* transmit packet compressor 8c */
127 void *xc_state; /* its internal state 90 */
128 struct compressor *rcomp; /* receive decompressor 94 */
129 void *rc_state; /* its internal state 98 */
130 unsigned long last_xmit; /* jiffies when last pkt sent 9c */
131 unsigned long last_recv; /* jiffies when last pkt rcvd a0 */
132 struct net_device *dev; /* network interface device a4 */
133 #ifdef CONFIG_PPP_MULTILINK
134 int nxchan; /* next channel to send something on */
135 u32 nxseq; /* next sequence number to send */
136 int mrru; /* MP: max reconst. receive unit */
137 u32 nextseq; /* MP: seq no of next packet */
138 u32 minseq; /* MP: min of most recent seqnos */
139 struct sk_buff_head mrq; /* MP: receive reconstruction queue */
140 #endif /* CONFIG_PPP_MULTILINK */
141 struct net_device_stats stats; /* statistics */
142 #ifdef CONFIG_PPP_FILTER
143 struct sock_filter *pass_filter; /* filter for packets to pass */
144 struct sock_filter *active_filter;/* filter for pkts to reset idle */
145 unsigned pass_len, active_len;
146 #endif /* CONFIG_PPP_FILTER */
147 #ifdef HNDCTF
148 channel_t *ctfpch;
149 #endif
153 * Bits in flags: SC_NO_TCP_CCID, SC_CCP_OPEN, SC_CCP_UP, SC_LOOP_TRAFFIC,
154 * SC_MULTILINK, SC_MP_SHORTSEQ, SC_MP_XSHORTSEQ, SC_COMP_TCP, SC_REJ_COMP_TCP.
155 * Bits in rstate: SC_DECOMP_RUN, SC_DC_ERROR, SC_DC_FERROR.
156 * Bits in xstate: SC_COMP_RUN
158 #define SC_FLAG_BITS (SC_NO_TCP_CCID|SC_CCP_OPEN|SC_CCP_UP|SC_LOOP_TRAFFIC \
159 |SC_MULTILINK|SC_MP_SHORTSEQ|SC_MP_XSHORTSEQ \
160 |SC_COMP_TCP|SC_REJ_COMP_TCP)
163 * Private data structure for each channel.
164 * This includes the data structure used for multilink.
166 struct channel {
167 struct ppp_file file; /* stuff for read/write/poll */
168 struct list_head list; /* link in all/new_channels list */
169 struct ppp_channel *chan; /* public channel data structure */
170 struct rw_semaphore chan_sem; /* protects `chan' during chan ioctl */
171 spinlock_t downl; /* protects `chan', file.xq dequeue */
172 struct ppp *ppp; /* ppp unit we're connected to */
173 struct list_head clist; /* link in list of channels per unit */
174 rwlock_t upl; /* protects `ppp' */
175 #ifdef CONFIG_PPP_MULTILINK
176 u8 avail; /* flag used in multilink stuff */
177 u8 had_frag; /* >= 1 fragments have been sent */
178 u32 lastseq; /* MP: last sequence # received */
179 #endif /* CONFIG_PPP_MULTILINK */
183 * SMP locking issues:
184 * Both the ppp.rlock and ppp.wlock locks protect the ppp.channels
185 * list and the ppp.n_channels field, you need to take both locks
186 * before you modify them.
187 * The lock ordering is: channel.upl -> ppp.wlock -> ppp.rlock ->
188 * channel.downl.
192 * A cardmap represents a mapping from unsigned integers to pointers,
193 * and provides a fast "find lowest unused number" operation.
194 * It uses a broad (32-way) tree with a bitmap at each level.
195 * It is designed to be space-efficient for small numbers of entries
196 * and time-efficient for large numbers of entries.
198 #define CARDMAP_ORDER 5
199 #define CARDMAP_WIDTH (1U << CARDMAP_ORDER)
200 #define CARDMAP_MASK (CARDMAP_WIDTH - 1)
202 struct cardmap {
203 int shift;
204 unsigned long inuse;
205 struct cardmap *parent;
206 void *ptr[CARDMAP_WIDTH];
208 static void *cardmap_get(struct cardmap *map, unsigned int nr);
209 static int cardmap_set(struct cardmap **map, unsigned int nr, void *ptr);
210 static unsigned int cardmap_find_first_free(struct cardmap *map);
211 static void cardmap_destroy(struct cardmap **map);
214 * all_ppp_mutex protects the all_ppp_units mapping.
215 * It also ensures that finding a ppp unit in the all_ppp_units map
216 * and updating its file.refcnt field is atomic.
218 static DEFINE_MUTEX(all_ppp_mutex);
219 static struct cardmap *all_ppp_units;
220 static atomic_t ppp_unit_count = ATOMIC_INIT(0);
223 * all_channels_lock protects all_channels and last_channel_index,
224 * and the atomicity of find a channel and updating its file.refcnt
225 * field.
227 static DEFINE_SPINLOCK(all_channels_lock);
228 static LIST_HEAD(all_channels);
229 static LIST_HEAD(new_channels);
230 static int last_channel_index;
231 static atomic_t channel_count = ATOMIC_INIT(0);
233 /* Get the PPP protocol number from a skb */
234 #define PPP_PROTO(skb) (((skb)->data[0] << 8) + (skb)->data[1])
236 // zzz
237 #define IP_PROTO(skb) (skb)->data[11]
238 #define SRC_PORT(skb) (((skb)->data[22] << 8) + (skb)->data[23])
239 #define DST_PORT(skb) (((skb)->data[24] << 8) + (skb)->data[25])
241 /* We limit the length of ppp->file.rq to this (arbitrary) value */
242 #define PPP_MAX_RQLEN 32
245 * Maximum number of multilink fragments queued up.
246 * This has to be large enough to cope with the maximum latency of
247 * the slowest channel relative to the others. Strictly it should
248 * depend on the number of channels and their characteristics.
250 #define PPP_MP_MAX_QLEN 128
252 /* Multilink header bits. */
253 #define B 0x80 /* this fragment begins a packet */
254 #define E 0x40 /* this fragment ends a packet */
256 /* Compare multilink sequence numbers (assumed to be 32 bits wide) */
257 #define seq_before(a, b) ((s32)((a) - (b)) < 0)
258 #define seq_after(a, b) ((s32)((a) - (b)) > 0)
260 /* Prototypes. */
261 static int ppp_unattached_ioctl(struct ppp_file *pf, struct file *file,
262 unsigned int cmd, unsigned long arg);
263 static void ppp_xmit_process(struct ppp *ppp);
264 static void ppp_send_frame(struct ppp *ppp, struct sk_buff *skb);
265 static void ppp_push(struct ppp *ppp);
266 static void ppp_channel_push(struct channel *pch);
267 static void ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb,
268 struct channel *pch);
269 static void ppp_receive_error(struct ppp *ppp);
270 static void ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb);
271 static struct sk_buff *ppp_decompress_frame(struct ppp *ppp,
272 struct sk_buff *skb);
273 #ifdef CONFIG_PPP_MULTILINK
274 static void ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb,
275 struct channel *pch);
276 static void ppp_mp_insert(struct ppp *ppp, struct sk_buff *skb);
277 static struct sk_buff *ppp_mp_reconstruct(struct ppp *ppp);
278 static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb);
279 #endif /* CONFIG_PPP_MULTILINK */
280 static int ppp_set_compress(struct ppp *ppp, unsigned long arg);
281 static void ppp_ccp_peek(struct ppp *ppp, struct sk_buff *skb, int inbound);
282 static void ppp_ccp_closed(struct ppp *ppp);
283 static struct compressor *find_compressor(int type);
284 static void ppp_get_stats(struct ppp *ppp, struct ppp_stats *st);
285 static struct ppp *ppp_create_interface(int unit, int *retp);
286 static void init_ppp_file(struct ppp_file *pf, int kind);
287 static void ppp_shutdown_interface(struct ppp *ppp);
288 static void ppp_destroy_interface(struct ppp *ppp);
289 static struct ppp *ppp_find_unit(int unit);
290 static struct channel *ppp_find_channel(int unit);
291 static int ppp_connect_channel(struct channel *pch, int unit);
292 static int ppp_disconnect_channel(struct channel *pch);
293 static void ppp_destroy_channel(struct channel *pch);
295 static struct class *ppp_class;
297 /* Translates a PPP protocol number to a NP index (NP == network protocol) */
298 static inline int proto_to_npindex(int proto)
300 switch (proto) {
301 case PPP_IP:
302 return NP_IP;
303 case PPP_IPV6:
304 return NP_IPV6;
305 case PPP_IPX:
306 return NP_IPX;
307 case PPP_AT:
308 return NP_AT;
309 case PPP_MPLS_UC:
310 return NP_MPLS_UC;
311 case PPP_MPLS_MC:
312 return NP_MPLS_MC;
314 return -EINVAL;
317 /* Translates an NP index into a PPP protocol number */
318 static const int npindex_to_proto[NUM_NP] = {
319 PPP_IP,
320 PPP_IPV6,
321 PPP_IPX,
322 PPP_AT,
323 PPP_MPLS_UC,
324 PPP_MPLS_MC,
327 /* Translates an ethertype into an NP index */
328 static inline int ethertype_to_npindex(int ethertype)
330 switch (ethertype) {
331 case ETH_P_IP:
332 return NP_IP;
333 case ETH_P_IPV6:
334 return NP_IPV6;
335 case ETH_P_IPX:
336 return NP_IPX;
337 case ETH_P_PPPTALK:
338 case ETH_P_ATALK:
339 return NP_AT;
340 case ETH_P_MPLS_UC:
341 return NP_MPLS_UC;
342 case ETH_P_MPLS_MC:
343 return NP_MPLS_MC;
345 return -1;
348 /* Translates an NP index into an ethertype */
349 static const int npindex_to_ethertype[NUM_NP] = {
350 ETH_P_IP,
351 ETH_P_IPV6,
352 ETH_P_IPX,
353 ETH_P_PPPTALK,
354 ETH_P_MPLS_UC,
355 ETH_P_MPLS_MC,
359 * Locking shorthand.
361 #define ppp_xmit_lock(ppp) spin_lock_bh(&(ppp)->wlock)
362 #define ppp_xmit_unlock(ppp) spin_unlock_bh(&(ppp)->wlock)
363 #define ppp_recv_lock(ppp) spin_lock_bh(&(ppp)->rlock)
364 #define ppp_recv_unlock(ppp) spin_unlock_bh(&(ppp)->rlock)
365 #define ppp_lock(ppp) do { ppp_xmit_lock(ppp); \
366 ppp_recv_lock(ppp); } while (0)
367 #define ppp_unlock(ppp) do { ppp_recv_unlock(ppp); \
368 ppp_xmit_unlock(ppp); } while (0)
371 * /dev/ppp device routines.
372 * The /dev/ppp device is used by pppd to control the ppp unit.
373 * It supports the read, write, ioctl and poll functions.
374 * Open instances of /dev/ppp can be in one of three states:
375 * unattached, attached to a ppp unit, or attached to a ppp channel.
377 static int ppp_open(struct inode *inode, struct file *file)
380 * This could (should?) be enforced by the permissions on /dev/ppp.
382 if (!capable(CAP_NET_ADMIN))
383 return -EPERM;
384 return 0;
387 static int ppp_release(struct inode *inode, struct file *file)
389 struct ppp_file *pf = file->private_data;
390 struct ppp *ppp;
392 if (pf != 0) {
393 file->private_data = NULL;
394 if (pf->kind == INTERFACE) {
395 ppp = PF_TO_PPP(pf);
396 if (file == ppp->owner)
397 ppp_shutdown_interface(ppp);
399 if (atomic_dec_and_test(&pf->refcnt)) {
400 switch (pf->kind) {
401 case INTERFACE:
402 ppp_destroy_interface(PF_TO_PPP(pf));
403 break;
404 case CHANNEL:
405 ppp_destroy_channel(PF_TO_CHANNEL(pf));
406 break;
410 return 0;
413 static ssize_t ppp_read(struct file *file, char __user *buf,
414 size_t count, loff_t *ppos)
416 struct ppp_file *pf = file->private_data;
417 DECLARE_WAITQUEUE(wait, current);
418 ssize_t ret;
419 struct sk_buff *skb = NULL;
420 struct iovec iov;
422 ret = count;
424 if (pf == 0)
425 return -ENXIO;
426 add_wait_queue(&pf->rwait, &wait);
427 for (;;) {
428 set_current_state(TASK_INTERRUPTIBLE);
429 skb = skb_dequeue(&pf->rq);
430 if (skb)
431 break;
432 ret = 0;
433 if (pf->dead)
434 break;
435 if (pf->kind == INTERFACE) {
437 * Return 0 (EOF) on an interface that has no
438 * channels connected, unless it is looping
439 * network traffic (demand mode).
441 struct ppp *ppp = PF_TO_PPP(pf);
442 if (ppp->n_channels == 0
443 && (ppp->flags & SC_LOOP_TRAFFIC) == 0)
444 break;
446 ret = -EAGAIN;
447 if (file->f_flags & O_NONBLOCK)
448 break;
449 ret = -ERESTARTSYS;
450 if (signal_pending(current))
451 break;
452 schedule();
454 set_current_state(TASK_RUNNING);
455 remove_wait_queue(&pf->rwait, &wait);
457 if (skb == 0)
458 goto out;
460 ret = -EOVERFLOW;
461 if (skb->len > count)
462 goto outf;
463 ret = -EFAULT;
464 iov.iov_base = buf;
465 iov.iov_len = count;
466 if (skb_copy_datagram_iovec(skb, 0, &iov, skb->len))
467 goto outf;
468 ret = skb->len;
470 outf:
471 kfree_skb(skb);
472 out:
473 return ret;
476 static ssize_t ppp_write(struct file *file, const char __user *buf,
477 size_t count, loff_t *ppos)
479 struct ppp_file *pf = file->private_data;
480 struct sk_buff *skb;
481 ssize_t ret;
483 if (pf == 0)
484 return -ENXIO;
485 ret = -ENOMEM;
486 skb = alloc_skb(count + pf->hdrlen, GFP_KERNEL);
487 if (skb == 0)
488 goto out;
489 skb_reserve(skb, pf->hdrlen);
490 ret = -EFAULT;
491 if (copy_from_user(skb_put(skb, count), buf, count)) {
492 kfree_skb(skb);
493 goto out;
496 skb_queue_tail(&pf->xq, skb);
498 switch (pf->kind) {
499 case INTERFACE:
500 ppp_xmit_process(PF_TO_PPP(pf));
501 break;
502 case CHANNEL:
503 ppp_channel_push(PF_TO_CHANNEL(pf));
504 break;
507 ret = count;
509 out:
510 return ret;
513 /* No kernel lock - fine */
514 static unsigned int ppp_poll(struct file *file, poll_table *wait)
516 struct ppp_file *pf = file->private_data;
517 unsigned int mask;
519 if (pf == 0)
520 return 0;
521 poll_wait(file, &pf->rwait, wait);
522 mask = POLLOUT | POLLWRNORM;
523 if (skb_peek(&pf->rq) != 0)
524 mask |= POLLIN | POLLRDNORM;
525 if (pf->dead)
526 mask |= POLLHUP;
527 else if (pf->kind == INTERFACE) {
528 /* see comment in ppp_read */
529 struct ppp *ppp = PF_TO_PPP(pf);
530 if (ppp->n_channels == 0
531 && (ppp->flags & SC_LOOP_TRAFFIC) == 0)
532 mask |= POLLIN | POLLRDNORM;
535 return mask;
538 #ifdef CONFIG_PPP_FILTER
539 static int get_filter(void __user *arg, struct sock_filter **p)
541 struct sock_fprog uprog;
542 struct sock_filter *code = NULL;
543 int len, err;
545 if (copy_from_user(&uprog, arg, sizeof(uprog)))
546 return -EFAULT;
548 if (!uprog.len) {
549 *p = NULL;
550 return 0;
553 len = uprog.len * sizeof(struct sock_filter);
554 code = kmalloc(len, GFP_KERNEL);
555 if (code == NULL)
556 return -ENOMEM;
558 if (copy_from_user(code, uprog.filter, len)) {
559 kfree(code);
560 return -EFAULT;
563 err = sk_chk_filter(code, uprog.len);
564 if (err) {
565 kfree(code);
566 return err;
569 *p = code;
570 return uprog.len;
572 #endif /* CONFIG_PPP_FILTER */
574 static int ppp_ioctl(struct inode *inode, struct file *file,
575 unsigned int cmd, unsigned long arg)
577 struct ppp_file *pf = file->private_data;
578 struct ppp *ppp;
579 int err = -EFAULT, val, val2, i;
580 struct ppp_idle idle;
581 struct npioctl npi;
582 int unit, cflags;
583 struct slcompress *vj;
584 void __user *argp = (void __user *)arg;
585 int __user *p = argp;
587 if (pf == 0)
588 return ppp_unattached_ioctl(pf, file, cmd, arg);
590 if (cmd == PPPIOCDETACH) {
592 * We have to be careful here... if the file descriptor
593 * has been dup'd, we could have another process in the
594 * middle of a poll using the same file *, so we had
595 * better not free the interface data structures -
596 * instead we fail the ioctl. Even in this case, we
597 * shut down the interface if we are the owner of it.
598 * Actually, we should get rid of PPPIOCDETACH, userland
599 * (i.e. pppd) could achieve the same effect by closing
600 * this fd and reopening /dev/ppp.
602 err = -EINVAL;
603 if (pf->kind == INTERFACE) {
604 ppp = PF_TO_PPP(pf);
605 if (file == ppp->owner)
606 ppp_shutdown_interface(ppp);
608 if (atomic_read(&file->f_count) <= 2) {
609 ppp_release(inode, file);
610 err = 0;
611 } else
612 printk(KERN_DEBUG "PPPIOCDETACH file->f_count=%d\n",
613 atomic_read(&file->f_count));
614 return err;
617 if (pf->kind == CHANNEL) {
618 struct channel *pch = PF_TO_CHANNEL(pf);
619 struct ppp_channel *chan;
621 switch (cmd) {
622 case PPPIOCCONNECT:
623 if (get_user(unit, p))
624 break;
625 err = ppp_connect_channel(pch, unit);
626 break;
628 case PPPIOCDISCONN:
629 err = ppp_disconnect_channel(pch);
630 break;
632 default:
633 down_read(&pch->chan_sem);
634 chan = pch->chan;
635 err = -ENOTTY;
636 if (chan && chan->ops->ioctl)
637 err = chan->ops->ioctl(chan, cmd, arg);
638 up_read(&pch->chan_sem);
640 return err;
643 if (pf->kind != INTERFACE) {
644 /* can't happen */
645 printk(KERN_ERR "PPP: not interface or channel??\n");
646 return -EINVAL;
649 ppp = PF_TO_PPP(pf);
650 switch (cmd) {
651 case PPPIOCSMRU:
652 if (get_user(val, p))
653 break;
654 ppp->mru_alloc = ppp->mru = val;
655 if (ppp->mru_alloc < PPP_MRU)
656 ppp->mru_alloc = PPP_MRU; /* increase for broken peers */
657 err = 0;
658 break;
660 case PPPIOCSFLAGS:
661 if (get_user(val, p))
662 break;
663 ppp_lock(ppp);
664 cflags = ppp->flags & ~val;
665 ppp->flags = val & SC_FLAG_BITS;
666 ppp_unlock(ppp);
667 if (cflags & SC_CCP_OPEN)
668 ppp_ccp_closed(ppp);
669 err = 0;
670 break;
672 case PPPIOCGFLAGS:
673 val = ppp->flags | ppp->xstate | ppp->rstate;
674 if (put_user(val, p))
675 break;
676 err = 0;
677 break;
679 case PPPIOCSCOMPRESS:
680 err = ppp_set_compress(ppp, arg);
681 break;
683 case PPPIOCGUNIT:
684 if (put_user(ppp->file.index, p))
685 break;
686 err = 0;
687 break;
689 case PPPIOCSDEBUG:
690 if (get_user(val, p))
691 break;
692 ppp->debug = val;
693 err = 0;
694 break;
696 case PPPIOCGDEBUG:
697 if (put_user(ppp->debug, p))
698 break;
699 err = 0;
700 break;
702 case PPPIOCGIDLE:
703 idle.xmit_idle = (jiffies - ppp->last_xmit) / HZ;
704 idle.recv_idle = (jiffies - ppp->last_recv) / HZ;
705 if (copy_to_user(argp, &idle, sizeof(idle)))
706 break;
707 err = 0;
708 break;
710 case PPPIOCSMAXCID:
711 if (get_user(val, p))
712 break;
713 val2 = 15;
714 if ((val >> 16) != 0) {
715 val2 = val >> 16;
716 val &= 0xffff;
718 vj = slhc_init(val2+1, val+1);
719 if (vj == 0) {
720 printk(KERN_ERR "PPP: no memory (VJ compressor)\n");
721 err = -ENOMEM;
722 break;
724 ppp_lock(ppp);
725 if (ppp->vj != 0)
726 slhc_free(ppp->vj);
727 ppp->vj = vj;
728 ppp_unlock(ppp);
729 err = 0;
730 break;
732 case PPPIOCGNPMODE:
733 case PPPIOCSNPMODE:
734 if (copy_from_user(&npi, argp, sizeof(npi)))
735 break;
736 err = proto_to_npindex(npi.protocol);
737 if (err < 0)
738 break;
739 i = err;
740 if (cmd == PPPIOCGNPMODE) {
741 err = -EFAULT;
742 npi.mode = ppp->npmode[i];
743 if (copy_to_user(argp, &npi, sizeof(npi)))
744 break;
745 } else {
746 ppp->npmode[i] = npi.mode;
747 /* we may be able to transmit more packets now (??) */
748 netif_wake_queue(ppp->dev);
750 err = 0;
751 break;
753 #ifdef CONFIG_PPP_FILTER
754 case PPPIOCSPASS:
756 struct sock_filter *code;
757 err = get_filter(argp, &code);
758 if (err >= 0) {
759 ppp_lock(ppp);
760 kfree(ppp->pass_filter);
761 ppp->pass_filter = code;
762 ppp->pass_len = err;
763 ppp_unlock(ppp);
764 err = 0;
766 break;
768 case PPPIOCSACTIVE:
770 struct sock_filter *code;
771 err = get_filter(argp, &code);
772 if (err >= 0) {
773 ppp_lock(ppp);
774 kfree(ppp->active_filter);
775 ppp->active_filter = code;
776 ppp->active_len = err;
777 ppp_unlock(ppp);
778 err = 0;
780 break;
782 #endif /* CONFIG_PPP_FILTER */
784 #ifdef CONFIG_PPP_MULTILINK
785 case PPPIOCSMRRU:
786 if (get_user(val, p))
787 break;
788 ppp_recv_lock(ppp);
789 ppp->mrru = val;
790 ppp_recv_unlock(ppp);
791 err = 0;
792 break;
793 #endif /* CONFIG_PPP_MULTILINK */
795 default:
796 err = -ENOTTY;
799 return err;
802 static int ppp_unattached_ioctl(struct ppp_file *pf, struct file *file,
803 unsigned int cmd, unsigned long arg)
805 int unit, err = -EFAULT;
806 struct ppp *ppp;
807 struct channel *chan;
808 int __user *p = (int __user *)arg;
810 switch (cmd) {
811 case PPPIOCNEWUNIT:
812 /* Create a new ppp unit */
813 if (get_user(unit, p))
814 break;
815 ppp = ppp_create_interface(unit, &err);
816 if (ppp == 0)
817 break;
818 file->private_data = &ppp->file;
819 ppp->owner = file;
820 err = -EFAULT;
821 if (put_user(ppp->file.index, p))
822 break;
823 err = 0;
824 break;
826 case PPPIOCATTACH:
827 /* Attach to an existing ppp unit */
828 if (get_user(unit, p))
829 break;
830 mutex_lock(&all_ppp_mutex);
831 err = -ENXIO;
832 ppp = ppp_find_unit(unit);
833 if (ppp != 0) {
834 atomic_inc(&ppp->file.refcnt);
835 file->private_data = &ppp->file;
836 err = 0;
838 mutex_unlock(&all_ppp_mutex);
839 break;
841 case PPPIOCATTCHAN:
842 if (get_user(unit, p))
843 break;
844 spin_lock_bh(&all_channels_lock);
845 err = -ENXIO;
846 chan = ppp_find_channel(unit);
847 if (chan != 0) {
848 atomic_inc(&chan->file.refcnt);
849 file->private_data = &chan->file;
850 err = 0;
852 spin_unlock_bh(&all_channels_lock);
853 break;
855 default:
856 err = -ENOTTY;
858 return err;
861 static const struct file_operations ppp_device_fops = {
862 .owner = THIS_MODULE,
863 .read = ppp_read,
864 .write = ppp_write,
865 .poll = ppp_poll,
866 .ioctl = ppp_ioctl,
867 .open = ppp_open,
868 .release = ppp_release
871 #define PPP_MAJOR 108
873 /* Called at boot time if ppp is compiled into the kernel,
874 or at module load time (from init_module) if compiled as a module. */
875 static int __init ppp_init(void)
877 int err;
879 printk(KERN_INFO "PPP generic driver version " PPP_VERSION "\n");
880 err = register_chrdev(PPP_MAJOR, "ppp", &ppp_device_fops);
881 if (!err) {
882 ppp_class = class_create(THIS_MODULE, "ppp");
883 if (IS_ERR(ppp_class)) {
884 err = PTR_ERR(ppp_class);
885 goto out_chrdev;
887 device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), "ppp");
890 out:
891 if (err)
892 printk(KERN_ERR "failed to register PPP device (%d)\n", err);
893 return err;
895 out_chrdev:
896 unregister_chrdev(PPP_MAJOR, "ppp");
897 goto out;
901 * Network interface unit routines.
903 static int
904 ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
906 struct ppp *ppp = (struct ppp *) dev->priv;
907 int npi, proto;
908 unsigned char *pp;
910 npi = ethertype_to_npindex(ntohs(skb->protocol));
911 if (npi < 0)
912 goto outf;
914 /* Drop, accept or reject the packet */
915 switch (ppp->npmode[npi]) {
916 case NPMODE_PASS:
917 break;
918 case NPMODE_QUEUE:
919 /* it would be nice to have a way to tell the network
920 system to queue this one up for later. */
921 goto outf;
922 case NPMODE_DROP:
923 case NPMODE_ERROR:
924 goto outf;
927 /* Put the 2-byte PPP protocol number on the front,
928 making sure there is room for the address and control fields. */
929 if (skb_cow_head(skb, PPP_HDRLEN))
930 goto outf;
932 pp = skb_push(skb, 2);
933 proto = npindex_to_proto[npi];
934 pp[0] = proto >> 8;
935 pp[1] = proto;
937 skb_queue_tail(&ppp->file.xq, skb);
938 ppp_xmit_process(ppp);
939 return 0;
941 outf:
942 kfree_skb(skb);
943 ++ppp->stats.tx_dropped;
944 return 0;
947 static struct net_device_stats *
948 ppp_net_stats(struct net_device *dev)
950 struct ppp *ppp = (struct ppp *) dev->priv;
952 return &ppp->stats;
955 static int
956 ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
958 struct ppp *ppp = dev->priv;
959 int err = -EFAULT;
960 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
961 struct ppp_stats stats;
962 struct ppp_comp_stats cstats;
963 char *vers;
965 switch (cmd) {
966 case SIOCGPPPSTATS:
967 ppp_get_stats(ppp, &stats);
968 if (copy_to_user(addr, &stats, sizeof(stats)))
969 break;
970 err = 0;
971 break;
973 case SIOCGPPPCSTATS:
974 memset(&cstats, 0, sizeof(cstats));
975 if (ppp->xc_state != 0)
976 ppp->xcomp->comp_stat(ppp->xc_state, &cstats.c);
977 if (ppp->rc_state != 0)
978 ppp->rcomp->decomp_stat(ppp->rc_state, &cstats.d);
979 if (copy_to_user(addr, &cstats, sizeof(cstats)))
980 break;
981 err = 0;
982 break;
984 case SIOCGPPPVER:
985 vers = PPP_VERSION;
986 if (copy_to_user(addr, vers, strlen(vers) + 1))
987 break;
988 err = 0;
989 break;
991 default:
992 err = -EINVAL;
995 return err;
998 static void ppp_setup(struct net_device *dev)
1000 dev->hard_header_len = PPP_HDRLEN;
1001 dev->mtu = PPP_MTU;
1002 dev->addr_len = 0;
1003 dev->tx_queue_len = 3;
1004 dev->type = ARPHRD_PPP;
1005 dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
1009 * Transmit-side routines.
1013 * Called to do any work queued up on the transmit side
1014 * that can now be done.
1016 static void
1017 ppp_xmit_process(struct ppp *ppp)
1019 struct sk_buff *skb;
1021 ppp_xmit_lock(ppp);
1022 if (ppp->dev != 0) {
1023 ppp_push(ppp);
1024 while (ppp->xmit_pending == 0
1025 && (skb = skb_dequeue(&ppp->file.xq)) != 0)
1026 ppp_send_frame(ppp, skb);
1027 /* If there's no work left to do, tell the core net
1028 code that we can accept some more. */
1029 if (!ppp->xmit_pending && !skb_peek(&ppp->file.xq))
1030 netif_wake_queue(ppp->dev);
1031 else
1032 netif_stop_queue(ppp->dev);
1034 ppp_xmit_unlock(ppp);
1038 * Compress and send a frame.
1039 * The caller should have locked the xmit path,
1040 * and xmit_pending should be 0.
1042 static void
1043 ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
1045 int proto = PPP_PROTO(skb);
1046 struct sk_buff *new_skb;
1047 int len;
1048 unsigned char *cp;
1050 if (proto < 0x8000) {
1051 #ifdef CONFIG_PPP_FILTER
1052 /* check if we should pass this packet */
1053 /* the filter instructions are constructed assuming
1054 a four-byte PPP header on each packet */
1055 *skb_push(skb, 2) = 1;
1056 if (ppp->pass_filter
1057 && sk_run_filter(skb, ppp->pass_filter,
1058 ppp->pass_len) == 0) {
1059 if (ppp->debug & 1)
1060 printk(KERN_DEBUG "PPP: outbound frame not passed\n");
1061 kfree_skb(skb);
1062 return;
1064 /* if this packet passes the active filter, record the time */
1065 if (!(ppp->active_filter
1066 && sk_run_filter(skb, ppp->active_filter,
1067 ppp->active_len) == 0))
1068 ppp->last_xmit = jiffies;
1069 skb_pull(skb, 2);
1070 #else
1072 #if 1 // zzz
1073 switch (IP_PROTO(skb)) {
1074 case 6: // TCP
1075 switch (DST_PORT(skb)) {
1076 case 139: // netbios-ssn
1077 case 445: // microsoft-ds
1078 break;
1079 default:
1080 ppp->last_xmit = jiffies;
1081 break;
1083 break;
1084 case 17: // UDP
1085 switch (DST_PORT(skb)) {
1086 case 137: // netbios-ns
1087 case 138: // netbios-dgm
1088 break;
1089 default:
1090 ppp->last_xmit = jiffies;
1091 break;
1093 break;
1094 default:
1095 ppp->last_xmit = jiffies;
1096 break;
1098 #else
1099 /* for data packets, record the time */
1100 ppp->last_xmit = jiffies;
1101 #endif
1102 #endif /* CONFIG_PPP_FILTER */
1105 ++ppp->stats.tx_packets;
1106 ppp->stats.tx_bytes += skb->len - 2;
1108 switch (proto) {
1109 case PPP_IP:
1110 if (ppp->vj == 0 || (ppp->flags & SC_COMP_TCP) == 0)
1111 break;
1112 /* try to do VJ TCP header compression */
1113 new_skb = alloc_skb(skb->len + ppp->dev->hard_header_len - 2,
1114 GFP_ATOMIC);
1115 if (new_skb == 0) {
1116 printk(KERN_ERR "PPP: no memory (VJ comp pkt)\n");
1117 goto drop;
1119 skb_reserve(new_skb, ppp->dev->hard_header_len - 2);
1120 cp = skb->data + 2;
1121 len = slhc_compress(ppp->vj, cp, skb->len - 2,
1122 new_skb->data + 2, &cp,
1123 !(ppp->flags & SC_NO_TCP_CCID));
1124 if (cp == skb->data + 2) {
1125 /* didn't compress */
1126 kfree_skb(new_skb);
1127 } else {
1128 if (cp[0] & SL_TYPE_COMPRESSED_TCP) {
1129 proto = PPP_VJC_COMP;
1130 cp[0] &= ~SL_TYPE_COMPRESSED_TCP;
1131 } else {
1132 proto = PPP_VJC_UNCOMP;
1133 cp[0] = skb->data[2];
1135 kfree_skb(skb);
1136 skb = new_skb;
1137 cp = skb_put(skb, len + 2);
1138 cp[0] = 0;
1139 cp[1] = proto;
1141 break;
1143 case PPP_CCP:
1144 /* peek at outbound CCP frames */
1145 ppp_ccp_peek(ppp, skb, 0);
1147 * When LZS or MPPE/MPPC has been negotiated we don't send
1148 * CCP_RESETACK after receiving CCP_RESETREQ; in fact pppd
1149 * sends such a packet but we silently discard it here
1151 if (CCP_CODE(skb->data+2) == CCP_RESETACK
1152 && (ppp->xcomp->compress_proto == CI_MPPE
1153 || ppp->xcomp->compress_proto == CI_LZS)) {
1154 --ppp->stats.tx_packets;
1155 ppp->stats.tx_bytes -= skb->len - 2;
1156 kfree_skb(skb);
1157 return;
1159 break;
1162 /* try to do packet compression */
1163 if ((ppp->xstate & SC_COMP_RUN) && ppp->xc_state != 0
1164 && proto != PPP_LCP && proto != PPP_CCP) {
1165 int comp_ovhd = 0;
1167 * because of possible data expansion when MPPC or LZS
1168 * is used, allocate compressor's buffer 12.5% bigger
1169 * than MTU
1171 if (ppp->xcomp->compress_proto == CI_MPPE)
1172 comp_ovhd = ((ppp->dev->mtu * 9) / 8) + 1 + MPPE_OVHD;
1173 else if (ppp->xcomp->compress_proto == CI_LZS)
1174 comp_ovhd = ((ppp->dev->mtu * 9) / 8) + 1 + LZS_OVHD;
1175 new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len
1176 + comp_ovhd, GFP_ATOMIC);
1177 if (new_skb == 0) {
1178 printk(KERN_ERR "PPP: no memory (comp pkt)\n");
1179 goto drop;
1181 if (ppp->dev->hard_header_len > PPP_HDRLEN)
1182 skb_reserve(new_skb,
1183 ppp->dev->hard_header_len - PPP_HDRLEN);
1185 /* compressor still expects A/C bytes in hdr */
1186 len = ppp->xcomp->compress(ppp->xc_state, skb->data - 2,
1187 new_skb->data, skb->len + 2,
1188 ppp->dev->mtu + PPP_HDRLEN);
1189 if (len > 0 && (ppp->flags & SC_CCP_UP)) {
1190 kfree_skb(skb);
1191 skb = new_skb;
1192 skb_put(skb, len);
1193 skb_pull(skb, 2); /* pull off A/C bytes */
1194 } else if (len == 0) {
1195 /* didn't compress, or CCP not up yet */
1196 kfree_skb(new_skb);
1197 } else {
1199 * (len < 0)
1200 * MPPE requires that we do not send unencrypted
1201 * frames. The compressor will return -1 if we
1202 * should drop the frame. We cannot simply test
1203 * the compress_proto because MPPE and MPPC share
1204 * the same number.
1206 printk(KERN_ERR "ppp: compressor dropped pkt\n");
1207 kfree_skb(new_skb);
1208 goto drop;
1213 * If we are waiting for traffic (demand dialling),
1214 * queue it up for pppd to receive.
1216 if (ppp->flags & SC_LOOP_TRAFFIC) {
1217 if (ppp->file.rq.qlen > PPP_MAX_RQLEN)
1218 goto drop;
1219 skb_queue_tail(&ppp->file.rq, skb);
1220 wake_up_interruptible(&ppp->file.rwait);
1221 return;
1224 ppp->xmit_pending = skb;
1225 ppp_push(ppp);
1226 return;
1228 drop:
1229 kfree_skb(skb);
1230 ++ppp->stats.tx_errors;
1234 * Try to send the frame in xmit_pending.
1235 * The caller should have the xmit path locked.
1237 static void
1238 ppp_push(struct ppp *ppp)
1240 struct list_head *list;
1241 struct channel *pch;
1242 struct sk_buff *skb = ppp->xmit_pending;
1244 if (skb == 0)
1245 return;
1247 list = &ppp->channels;
1248 if (list_empty(list)) {
1249 /* nowhere to send the packet, just drop it */
1250 ppp->xmit_pending = NULL;
1251 kfree_skb(skb);
1252 return;
1255 if ((ppp->flags & SC_MULTILINK) == 0) {
1256 /* not doing multilink: send it down the first channel */
1257 list = list->next;
1258 pch = list_entry(list, struct channel, clist);
1260 spin_lock_bh(&pch->downl);
1261 if (pch->chan) {
1262 if (pch->chan->ops->start_xmit(pch->chan, skb))
1263 ppp->xmit_pending = NULL;
1264 } else {
1265 /* channel got unregistered */
1266 kfree_skb(skb);
1267 ppp->xmit_pending = NULL;
1269 spin_unlock_bh(&pch->downl);
1270 return;
1273 #ifdef CONFIG_PPP_MULTILINK
1274 /* Multilink: fragment the packet over as many links
1275 as can take the packet at the moment. */
1276 if (!ppp_mp_explode(ppp, skb))
1277 return;
1278 #endif /* CONFIG_PPP_MULTILINK */
1280 ppp->xmit_pending = NULL;
1281 kfree_skb(skb);
1284 #ifdef CONFIG_PPP_MULTILINK
1286 * Divide a packet to be transmitted into fragments and
1287 * send them out the individual links.
1289 static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1291 int len, fragsize;
1292 int i, bits, hdrlen, mtu;
1293 int flen;
1294 int navail, nfree;
1295 int nbigger;
1296 unsigned char *p, *q;
1297 struct list_head *list;
1298 struct channel *pch;
1299 struct sk_buff *frag;
1300 struct ppp_channel *chan;
1302 nfree = 0; /* # channels which have no packet already queued */
1303 navail = 0; /* total # of usable channels (not deregistered) */
1304 hdrlen = (ppp->flags & SC_MP_XSHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN;
1305 i = 0;
1306 list_for_each_entry(pch, &ppp->channels, clist) {
1307 navail += pch->avail = (pch->chan != NULL);
1308 if (pch->avail) {
1309 if (skb_queue_empty(&pch->file.xq) ||
1310 !pch->had_frag) {
1311 pch->avail = 2;
1312 ++nfree;
1314 if (!pch->had_frag && i < ppp->nxchan)
1315 ppp->nxchan = i;
1317 ++i;
1321 * Don't start sending this packet unless at least half of
1322 * the channels are free. This gives much better TCP
1323 * performance if we have a lot of channels.
1325 if (nfree == 0 || nfree < navail / 2)
1326 return 0; /* can't take now, leave it in xmit_pending */
1328 /* Do protocol field compression (XXX this should be optional) */
1329 p = skb->data;
1330 len = skb->len;
1331 if (*p == 0) {
1332 ++p;
1333 --len;
1337 * Decide on fragment size.
1338 * We create a fragment for each free channel regardless of
1339 * how small they are (i.e. even 0 length) in order to minimize
1340 * the time that it will take to detect when a channel drops
1341 * a fragment.
1343 fragsize = len;
1344 if (nfree > 1)
1345 fragsize = DIV_ROUND_UP(fragsize, nfree);
1346 /* nbigger channels get fragsize bytes, the rest get fragsize-1,
1347 except if nbigger==0, then they all get fragsize. */
1348 nbigger = len % nfree;
1350 /* skip to the channel after the one we last used
1351 and start at that one */
1352 list = &ppp->channels;
1353 for (i = 0; i < ppp->nxchan; ++i) {
1354 list = list->next;
1355 if (list == &ppp->channels) {
1356 i = 0;
1357 break;
1361 /* create a fragment for each channel */
1362 bits = B;
1363 while (nfree > 0 || len > 0) {
1364 list = list->next;
1365 if (list == &ppp->channels) {
1366 i = 0;
1367 continue;
1369 pch = list_entry(list, struct channel, clist);
1370 ++i;
1371 if (!pch->avail)
1372 continue;
1375 * Skip this channel if it has a fragment pending already and
1376 * we haven't given a fragment to all of the free channels.
1378 if (pch->avail == 1) {
1379 if (nfree > 0)
1380 continue;
1381 } else {
1382 --nfree;
1383 pch->avail = 1;
1386 /* check the channel's mtu and whether it is still attached. */
1387 spin_lock_bh(&pch->downl);
1388 if (pch->chan == NULL) {
1389 /* can't use this channel, it's being deregistered */
1390 spin_unlock_bh(&pch->downl);
1391 pch->avail = 0;
1392 if (--navail == 0)
1393 break;
1394 continue;
1398 * Create a fragment for this channel of
1399 * min(max(mtu+2-hdrlen, 4), fragsize, len) bytes.
1400 * If mtu+2-hdrlen < 4, that is a ridiculously small
1401 * MTU, so we use mtu = 2 + hdrlen.
1403 if (fragsize > len)
1404 fragsize = len;
1405 flen = fragsize;
1406 mtu = pch->chan->mtu + 2 - hdrlen;
1407 if (mtu < 4)
1408 mtu = 4;
1409 if (flen > mtu)
1410 flen = mtu;
1411 if (flen == len && nfree == 0)
1412 bits |= E;
1413 frag = alloc_skb(flen + hdrlen + (flen == 0), GFP_ATOMIC);
1414 if (frag == 0)
1415 goto noskb;
1416 q = skb_put(frag, flen + hdrlen);
1418 /* make the MP header */
1419 q[0] = PPP_MP >> 8;
1420 q[1] = PPP_MP;
1421 if (ppp->flags & SC_MP_XSHORTSEQ) {
1422 q[2] = bits + ((ppp->nxseq >> 8) & 0xf);
1423 q[3] = ppp->nxseq;
1424 } else {
1425 q[2] = bits;
1426 q[3] = ppp->nxseq >> 16;
1427 q[4] = ppp->nxseq >> 8;
1428 q[5] = ppp->nxseq;
1432 * Copy the data in.
1433 * Unfortunately there is a bug in older versions of
1434 * the Linux PPP multilink reconstruction code where it
1435 * drops 0-length fragments. Therefore we make sure the
1436 * fragment has at least one byte of data. Any bytes
1437 * we add in this situation will end up as padding on the
1438 * end of the reconstructed packet.
1440 if (flen == 0)
1441 *skb_put(frag, 1) = 0;
1442 else
1443 memcpy(q + hdrlen, p, flen);
1445 /* try to send it down the channel */
1446 chan = pch->chan;
1447 if (!skb_queue_empty(&pch->file.xq) ||
1448 !chan->ops->start_xmit(chan, frag))
1449 skb_queue_tail(&pch->file.xq, frag);
1450 pch->had_frag = 1;
1451 p += flen;
1452 len -= flen;
1453 ++ppp->nxseq;
1454 bits = 0;
1455 spin_unlock_bh(&pch->downl);
1457 if (--nbigger == 0 && fragsize > 0)
1458 --fragsize;
1460 ppp->nxchan = i;
1462 return 1;
1464 noskb:
1465 spin_unlock_bh(&pch->downl);
1466 if (ppp->debug & 1)
1467 printk(KERN_ERR "PPP: no memory (fragment)\n");
1468 ++ppp->stats.tx_errors;
1469 ++ppp->nxseq;
1470 return 1; /* abandon the frame */
1472 #endif /* CONFIG_PPP_MULTILINK */
1475 * Try to send data out on a channel.
1477 static void
1478 ppp_channel_push(struct channel *pch)
1480 struct sk_buff *skb;
1481 struct ppp *ppp;
1483 spin_lock_bh(&pch->downl);
1484 if (pch->chan != 0) {
1485 while (!skb_queue_empty(&pch->file.xq)) {
1486 skb = skb_dequeue(&pch->file.xq);
1487 if (!pch->chan->ops->start_xmit(pch->chan, skb)) {
1488 /* put the packet back and try again later */
1489 skb_queue_head(&pch->file.xq, skb);
1490 break;
1493 } else {
1494 /* channel got deregistered */
1495 skb_queue_purge(&pch->file.xq);
1497 spin_unlock_bh(&pch->downl);
1498 /* see if there is anything from the attached unit to be sent */
1499 if (skb_queue_empty(&pch->file.xq)) {
1500 read_lock_bh(&pch->upl);
1501 ppp = pch->ppp;
1502 if (ppp != 0)
1503 ppp_xmit_process(ppp);
1504 read_unlock_bh(&pch->upl);
1509 * Receive-side routines.
1512 /* misuse a few fields of the skb for MP reconstruction */
1513 #define sequence priority
1514 #define BEbits cb[0]
1516 static inline void
1517 ppp_do_recv(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1519 ppp_recv_lock(ppp);
1520 /* ppp->dev == 0 means interface is closing down */
1521 if (ppp->dev != 0)
1522 ppp_receive_frame(ppp, skb, pch);
1523 else
1524 kfree_skb(skb);
1525 ppp_recv_unlock(ppp);
1528 void
1529 ppp_input(struct ppp_channel *chan, struct sk_buff *skb)
1531 struct channel *pch = chan->ppp;
1532 int proto;
1534 if (!pch) {
1535 kfree_skb(skb);
1536 return;
1539 read_lock_bh(&pch->upl);
1540 if (!pskb_may_pull(skb, 2)) {
1541 kfree_skb(skb);
1542 if (pch->ppp) {
1543 ++pch->ppp->stats.rx_length_errors;
1544 ppp_receive_error(pch->ppp);
1546 goto done;
1549 proto = PPP_PROTO(skb);
1550 if (pch->ppp == 0 || proto >= 0xc000 || proto == PPP_CCPFRAG) {
1551 /* put it on the channel queue */
1552 skb_queue_tail(&pch->file.rq, skb);
1553 /* drop old frames if queue too long */
1554 while (pch->file.rq.qlen > PPP_MAX_RQLEN
1555 && (skb = skb_dequeue(&pch->file.rq)) != 0)
1556 kfree_skb(skb);
1557 wake_up_interruptible(&pch->file.rwait);
1558 } else {
1559 ppp_do_recv(pch->ppp, skb, pch);
1562 done:
1563 read_unlock_bh(&pch->upl);
1566 /* Put a 0-length skb in the receive queue as an error indication */
1567 void
1568 ppp_input_error(struct ppp_channel *chan, int code)
1570 struct channel *pch = chan->ppp;
1571 struct sk_buff *skb;
1573 if (pch == 0)
1574 return;
1576 read_lock_bh(&pch->upl);
1577 if (pch->ppp != 0) {
1578 skb = alloc_skb(0, GFP_ATOMIC);
1579 if (skb != 0) {
1580 skb->len = 0; /* probably unnecessary */
1581 skb->cb[0] = code;
1582 ppp_do_recv(pch->ppp, skb, pch);
1585 read_unlock_bh(&pch->upl);
1589 * We come in here to process a received frame.
1590 * The receive side of the ppp unit is locked.
1592 static void
1593 ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1595 /* note: a 0-length skb is used as an error indication */
1596 if (skb->len > 0) {
1597 #ifdef CONFIG_PPP_MULTILINK
1598 /* XXX do channel-level decompression here */
1599 if (PPP_PROTO(skb) == PPP_MP)
1600 ppp_receive_mp_frame(ppp, skb, pch);
1601 else
1602 #endif /* CONFIG_PPP_MULTILINK */
1603 ppp_receive_nonmp_frame(ppp, skb);
1604 } else {
1605 kfree_skb(skb);
1606 ppp_receive_error(ppp);
1610 static void
1611 ppp_receive_error(struct ppp *ppp)
1613 ++ppp->stats.rx_errors;
1614 if (ppp->vj != 0)
1615 slhc_toss(ppp->vj);
1618 static void
1619 ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
1621 struct sk_buff *ns;
1622 int proto, len, npi;
1625 * Decompress the frame, if compressed.
1626 * Note that some decompressors need to see uncompressed frames
1627 * that come in as well as compressed frames.
1629 if (ppp->rc_state != 0 && (ppp->rstate & SC_DECOMP_RUN)
1630 && (ppp->rstate & (SC_DC_FERROR | SC_DC_ERROR)) == 0)
1631 skb = ppp_decompress_frame(ppp, skb);
1633 proto = PPP_PROTO(skb);
1634 switch (proto) {
1635 case PPP_VJC_COMP:
1636 /* decompress VJ compressed packets */
1637 if (ppp->vj == 0 || (ppp->flags & SC_REJ_COMP_TCP))
1638 goto err;
1640 if (skb_tailroom(skb) < 124 || skb_cloned(skb)) {
1641 /* copy to a new sk_buff with more tailroom */
1642 ns = dev_alloc_skb(skb->len + 128);
1643 if (ns == 0) {
1644 printk(KERN_ERR"PPP: no memory (VJ decomp)\n");
1645 goto err;
1647 skb_reserve(ns, 2);
1648 skb_copy_bits(skb, 0, skb_put(ns, skb->len), skb->len);
1649 kfree_skb(skb);
1650 skb = ns;
1652 else
1653 skb->ip_summed = CHECKSUM_NONE;
1655 len = slhc_uncompress(ppp->vj, skb->data + 2, skb->len - 2);
1656 if (len <= 0) {
1657 printk(KERN_DEBUG "PPP: VJ decompression error\n");
1658 goto err;
1660 len += 2;
1661 if (len > skb->len)
1662 skb_put(skb, len - skb->len);
1663 else if (len < skb->len)
1664 skb_trim(skb, len);
1665 proto = PPP_IP;
1666 break;
1668 case PPP_VJC_UNCOMP:
1669 if (ppp->vj == 0 || (ppp->flags & SC_REJ_COMP_TCP))
1670 goto err;
1672 /* Until we fix the decompressor need to make sure
1673 * data portion is linear.
1675 if (!pskb_may_pull(skb, skb->len))
1676 goto err;
1678 if (slhc_remember(ppp->vj, skb->data + 2, skb->len - 2) <= 0) {
1679 printk(KERN_ERR "PPP: VJ uncompressed error\n");
1680 goto err;
1682 proto = PPP_IP;
1683 break;
1685 case PPP_CCP:
1686 ppp_ccp_peek(ppp, skb, 1);
1687 break;
1690 ++ppp->stats.rx_packets;
1691 ppp->stats.rx_bytes += skb->len - 2;
1693 npi = proto_to_npindex(proto);
1694 if (npi < 0) {
1695 /* control or unknown frame - pass it to pppd */
1696 skb_queue_tail(&ppp->file.rq, skb);
1697 /* limit queue length by dropping old frames */
1698 while (ppp->file.rq.qlen > PPP_MAX_RQLEN
1699 && (skb = skb_dequeue(&ppp->file.rq)) != 0)
1700 kfree_skb(skb);
1701 /* wake up any process polling or blocking on read */
1702 wake_up_interruptible(&ppp->file.rwait);
1704 } else {
1705 /* network protocol frame - give it to the kernel */
1707 #ifdef CONFIG_PPP_FILTER
1708 /* check if the packet passes the pass and active filters */
1709 /* the filter instructions are constructed assuming
1710 a four-byte PPP header on each packet */
1711 if (ppp->pass_filter || ppp->active_filter) {
1712 if (skb_cloned(skb) &&
1713 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
1714 goto err;
1716 *skb_push(skb, 2) = 0;
1717 if (ppp->pass_filter
1718 && sk_run_filter(skb, ppp->pass_filter,
1719 ppp->pass_len) == 0) {
1720 if (ppp->debug & 1)
1721 printk(KERN_DEBUG "PPP: inbound frame "
1722 "not passed\n");
1723 kfree_skb(skb);
1724 return;
1726 if (!(ppp->active_filter
1727 && sk_run_filter(skb, ppp->active_filter,
1728 ppp->active_len) == 0))
1729 ppp->last_recv = jiffies;
1730 __skb_pull(skb, 2);
1731 } else
1732 #endif /* CONFIG_PPP_FILTER */
1733 ppp->last_recv = jiffies;
1735 if ((ppp->dev->flags & IFF_UP) == 0
1736 || ppp->npmode[npi] != NPMODE_PASS) {
1737 kfree_skb(skb);
1738 } else {
1739 /* chop off protocol */
1740 skb_pull_rcsum(skb, 2);
1741 skb->dev = ppp->dev;
1742 skb->protocol = htons(npindex_to_ethertype[npi]);
1743 skb_reset_mac_header(skb);
1744 netif_rx(skb);
1745 ppp->dev->last_rx = jiffies;
1748 return;
1750 err:
1751 kfree_skb(skb);
1752 ppp_receive_error(ppp);
1755 static struct sk_buff *
1756 ppp_decompress_frame(struct ppp *ppp, struct sk_buff *skb)
1758 int proto = PPP_PROTO(skb);
1759 struct sk_buff *ns;
1760 int len;
1762 /* Until we fix all the decompressor's need to make sure
1763 * data portion is linear.
1765 if (!pskb_may_pull(skb, skb->len))
1766 goto err;
1768 if (proto == PPP_COMP) {
1769 int obuff_size;
1771 switch(ppp->rcomp->compress_proto) {
1772 case CI_MPPE:
1773 obuff_size = ppp->mru_alloc + PPP_HDRLEN + 1;
1774 break;
1775 default:
1776 obuff_size = ppp->mru_alloc + PPP_HDRLEN;
1777 break;
1780 ns = dev_alloc_skb(obuff_size);
1781 if (ns == 0) {
1782 printk(KERN_ERR "ppp_decompress_frame: no memory\n");
1783 goto err;
1785 /* the decompressor still expects the A/C bytes in the hdr */
1786 len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2,
1787 skb->len + 2, ns->data, obuff_size);
1788 if (len < 0) {
1789 /* Pass the compressed frame to pppd as an
1790 error indication. */
1791 if (len == DECOMP_FATALERROR)
1792 ppp->rstate |= SC_DC_FERROR;
1793 kfree_skb(ns);
1794 goto err;
1797 kfree_skb(skb);
1798 skb = ns;
1799 skb_put(skb, len);
1800 skb_pull(skb, 2); /* pull off the A/C bytes */
1802 } else {
1803 /* Uncompressed frame - pass to decompressor so it
1804 can update its dictionary if necessary. */
1805 if (ppp->rcomp->incomp)
1806 ppp->rcomp->incomp(ppp->rc_state, skb->data - 2,
1807 skb->len + 2);
1810 return skb;
1812 err:
1813 if (ppp->rcomp->compress_proto != CI_MPPE
1814 && ppp->rcomp->compress_proto != CI_LZS) {
1816 * If decompression protocol isn't MPPE/MPPC or LZS, we set
1817 * SC_DC_ERROR flag and wait for CCP_RESETACK
1819 ppp->rstate |= SC_DC_ERROR;
1821 ppp_receive_error(ppp);
1822 return skb;
1825 #ifdef CONFIG_PPP_MULTILINK
1827 * Receive a multilink frame.
1828 * We put it on the reconstruction queue and then pull off
1829 * as many completed frames as we can.
1831 static void
1832 ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1834 u32 mask, seq;
1835 struct channel *ch;
1836 int mphdrlen = (ppp->flags & SC_MP_SHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN;
1838 if (!pskb_may_pull(skb, mphdrlen + 1) || ppp->mrru == 0)
1839 goto err; /* no good, throw it away */
1841 /* Decode sequence number and begin/end bits */
1842 if (ppp->flags & SC_MP_SHORTSEQ) {
1843 seq = ((skb->data[2] & 0x0f) << 8) | skb->data[3];
1844 mask = 0xfff;
1845 } else {
1846 seq = (skb->data[3] << 16) | (skb->data[4] << 8)| skb->data[5];
1847 mask = 0xffffff;
1849 skb->BEbits = skb->data[2];
1850 skb_pull(skb, mphdrlen); /* pull off PPP and MP headers */
1853 * Do protocol ID decompression on the first fragment of each packet.
1855 if ((skb->BEbits & B) && (skb->data[0] & 1))
1856 *skb_push(skb, 1) = 0;
1859 * Expand sequence number to 32 bits, making it as close
1860 * as possible to ppp->minseq.
1862 seq |= ppp->minseq & ~mask;
1863 if ((int)(ppp->minseq - seq) > (int)(mask >> 1))
1864 seq += mask + 1;
1865 else if ((int)(seq - ppp->minseq) > (int)(mask >> 1))
1866 seq -= mask + 1; /* should never happen */
1867 skb->sequence = seq;
1868 pch->lastseq = seq;
1871 * If this packet comes before the next one we were expecting,
1872 * drop it.
1874 if (seq_before(seq, ppp->nextseq)) {
1875 kfree_skb(skb);
1876 ++ppp->stats.rx_dropped;
1877 ppp_receive_error(ppp);
1878 return;
1882 * Reevaluate minseq, the minimum over all channels of the
1883 * last sequence number received on each channel. Because of
1884 * the increasing sequence number rule, we know that any fragment
1885 * before `minseq' which hasn't arrived is never going to arrive.
1886 * The list of channels can't change because we have the receive
1887 * side of the ppp unit locked.
1889 list_for_each_entry(ch, &ppp->channels, clist) {
1890 if (seq_before(ch->lastseq, seq))
1891 seq = ch->lastseq;
1893 if (seq_before(ppp->minseq, seq))
1894 ppp->minseq = seq;
1896 /* Put the fragment on the reconstruction queue */
1897 ppp_mp_insert(ppp, skb);
1899 /* If the queue is getting long, don't wait any longer for packets
1900 before the start of the queue. */
1901 if (skb_queue_len(&ppp->mrq) >= PPP_MP_MAX_QLEN
1902 && seq_before(ppp->minseq, ppp->mrq.next->sequence))
1903 ppp->minseq = ppp->mrq.next->sequence;
1905 /* Pull completed packets off the queue and receive them. */
1906 while ((skb = ppp_mp_reconstruct(ppp)) != 0) {
1907 if (pskb_may_pull(skb, 2))
1908 ppp_receive_nonmp_frame(ppp, skb);
1909 else {
1910 ++ppp->dev->stats.rx_length_errors;
1911 kfree_skb(skb);
1912 ppp_receive_error(ppp);
1916 return;
1918 err:
1919 kfree_skb(skb);
1920 ppp_receive_error(ppp);
1924 * Insert a fragment on the MP reconstruction queue.
1925 * The queue is ordered by increasing sequence number.
1927 static void
1928 ppp_mp_insert(struct ppp *ppp, struct sk_buff *skb)
1930 struct sk_buff *p;
1931 struct sk_buff_head *list = &ppp->mrq;
1932 u32 seq = skb->sequence;
1934 /* N.B. we don't need to lock the list lock because we have the
1935 ppp unit receive-side lock. */
1936 for (p = list->next; p != (struct sk_buff *)list; p = p->next)
1937 if (seq_before(seq, p->sequence))
1938 break;
1939 __skb_insert(skb, p->prev, p, list);
1943 * Reconstruct a packet from the MP fragment queue.
1944 * We go through increasing sequence numbers until we find a
1945 * complete packet, or we get to the sequence number for a fragment
1946 * which hasn't arrived but might still do so.
1948 struct sk_buff *
1949 ppp_mp_reconstruct(struct ppp *ppp)
1951 u32 seq = ppp->nextseq;
1952 u32 minseq = ppp->minseq;
1953 struct sk_buff_head *list = &ppp->mrq;
1954 struct sk_buff *p, *next;
1955 struct sk_buff *head, *tail;
1956 struct sk_buff *skb = NULL;
1957 int lost = 0, len = 0;
1959 if (ppp->mrru == 0) /* do nothing until mrru is set */
1960 return NULL;
1961 head = list->next;
1962 tail = NULL;
1963 for (p = head; p != (struct sk_buff *) list; p = next) {
1964 next = p->next;
1965 if (seq_before(p->sequence, seq)) {
1966 /* this can't happen, anyway ignore the skb */
1967 printk(KERN_ERR "ppp_mp_reconstruct bad seq %u < %u\n",
1968 p->sequence, seq);
1969 head = next;
1970 continue;
1972 if (p->sequence != seq) {
1973 /* Fragment `seq' is missing. If it is after
1974 minseq, it might arrive later, so stop here. */
1975 if (seq_after(seq, minseq))
1976 break;
1977 /* Fragment `seq' is lost, keep going. */
1978 lost = 1;
1979 seq = seq_before(minseq, p->sequence)?
1980 minseq + 1: p->sequence;
1981 next = p;
1982 continue;
1986 * At this point we know that all the fragments from
1987 * ppp->nextseq to seq are either present or lost.
1988 * Also, there are no complete packets in the queue
1989 * that have no missing fragments and end before this
1990 * fragment.
1993 /* B bit set indicates this fragment starts a packet */
1994 if (p->BEbits & B) {
1995 head = p;
1996 lost = 0;
1997 len = 0;
2000 len += p->len;
2002 /* Got a complete packet yet? */
2003 if (lost == 0 && (p->BEbits & E) && (head->BEbits & B)) {
2004 if (len > ppp->mrru + 2) {
2005 ++ppp->stats.rx_length_errors;
2006 printk(KERN_DEBUG "PPP: reconstructed packet"
2007 " is too long (%d)\n", len);
2008 } else if (p == head) {
2009 /* fragment is complete packet - reuse skb */
2010 tail = p;
2011 skb = skb_get(p);
2012 break;
2013 } else if ((skb = dev_alloc_skb(len)) == NULL) {
2014 ++ppp->stats.rx_missed_errors;
2015 printk(KERN_DEBUG "PPP: no memory for "
2016 "reconstructed packet");
2017 } else {
2018 tail = p;
2019 break;
2021 ppp->nextseq = seq + 1;
2025 * If this is the ending fragment of a packet,
2026 * and we haven't found a complete valid packet yet,
2027 * we can discard up to and including this fragment.
2029 if (p->BEbits & E)
2030 head = next;
2032 ++seq;
2035 /* If we have a complete packet, copy it all into one skb. */
2036 if (tail != NULL) {
2037 /* If we have discarded any fragments,
2038 signal a receive error. */
2039 if (head->sequence != ppp->nextseq) {
2040 if (ppp->debug & 1)
2041 printk(KERN_DEBUG " missed pkts %u..%u\n",
2042 ppp->nextseq, head->sequence-1);
2043 ++ppp->stats.rx_dropped;
2044 ppp_receive_error(ppp);
2047 if (head != tail)
2048 /* copy to a single skb */
2049 for (p = head; p != tail->next; p = p->next)
2050 skb_copy_bits(p, 0, skb_put(skb, p->len), p->len);
2051 ppp->nextseq = tail->sequence + 1;
2052 head = tail->next;
2055 /* Discard all the skbuffs that we have copied the data out of
2056 or that we can't use. */
2057 while ((p = list->next) != head) {
2058 __skb_unlink(p, list);
2059 kfree_skb(p);
2062 return skb;
2064 #endif /* CONFIG_PPP_MULTILINK */
2067 * Channel interface.
2071 * Create a new, unattached ppp channel.
2074 ppp_register_channel(struct ppp_channel *chan)
2076 struct channel *pch;
2078 pch = kzalloc(sizeof(struct channel), GFP_KERNEL);
2079 if (pch == 0)
2080 return -ENOMEM;
2081 pch->ppp = NULL;
2082 pch->chan = chan;
2083 chan->ppp = pch;
2084 init_ppp_file(&pch->file, CHANNEL);
2085 pch->file.hdrlen = chan->hdrlen;
2086 #ifdef CONFIG_PPP_MULTILINK
2087 pch->lastseq = -1;
2088 #endif /* CONFIG_PPP_MULTILINK */
2089 init_rwsem(&pch->chan_sem);
2090 spin_lock_init(&pch->downl);
2091 rwlock_init(&pch->upl);
2092 spin_lock_bh(&all_channels_lock);
2093 pch->file.index = ++last_channel_index;
2094 list_add(&pch->list, &new_channels);
2095 atomic_inc(&channel_count);
2096 spin_unlock_bh(&all_channels_lock);
2097 return 0;
2101 * Return the index of a channel.
2103 int ppp_channel_index(struct ppp_channel *chan)
2105 struct channel *pch = chan->ppp;
2107 if (pch != 0)
2108 return pch->file.index;
2109 return -1;
2113 * Return the PPP unit number to which a channel is connected.
2115 int ppp_unit_number(struct ppp_channel *chan)
2117 struct channel *pch = chan->ppp;
2118 int unit = -1;
2120 if (pch != 0) {
2121 read_lock_bh(&pch->upl);
2122 if (pch->ppp != 0)
2123 unit = pch->ppp->file.index;
2124 read_unlock_bh(&pch->upl);
2126 return unit;
2130 * Disconnect a channel from the generic layer.
2131 * This must be called in process context.
2133 void
2134 ppp_unregister_channel(struct ppp_channel *chan)
2136 struct channel *pch = chan->ppp;
2138 if (pch == 0)
2139 return; /* should never happen */
2140 chan->ppp = NULL;
2143 * This ensures that we have returned from any calls into the
2144 * the channel's start_xmit or ioctl routine before we proceed.
2146 down_write(&pch->chan_sem);
2147 spin_lock_bh(&pch->downl);
2148 pch->chan = NULL;
2149 spin_unlock_bh(&pch->downl);
2150 up_write(&pch->chan_sem);
2151 ppp_disconnect_channel(pch);
2152 spin_lock_bh(&all_channels_lock);
2153 list_del(&pch->list);
2154 spin_unlock_bh(&all_channels_lock);
2155 pch->file.dead = 1;
2156 wake_up_interruptible(&pch->file.rwait);
2157 if (atomic_dec_and_test(&pch->file.refcnt))
2158 ppp_destroy_channel(pch);
2162 * Callback from a channel when it can accept more to transmit.
2163 * This should be called at BH/softirq level, not interrupt level.
2165 void
2166 ppp_output_wakeup(struct ppp_channel *chan)
2168 struct channel *pch = chan->ppp;
2170 if (pch == 0)
2171 return;
2172 ppp_channel_push(pch);
2176 * Compression control.
2179 /* Process the PPPIOCSCOMPRESS ioctl. */
2180 static int
2181 ppp_set_compress(struct ppp *ppp, unsigned long arg)
2183 int err;
2184 struct compressor *cp, *ocomp;
2185 struct ppp_option_data data;
2186 void *state, *ostate;
2187 unsigned char ccp_option[CCP_MAX_OPTION_LENGTH];
2189 err = -EFAULT;
2190 if (copy_from_user(&data, (void __user *) arg, sizeof(data))
2191 || (data.length <= CCP_MAX_OPTION_LENGTH
2192 && copy_from_user(ccp_option, (void __user *) data.ptr, data.length)))
2193 goto out;
2194 err = -EINVAL;
2195 if (data.length > CCP_MAX_OPTION_LENGTH
2196 || ccp_option[1] < 2 || ccp_option[1] > data.length)
2197 goto out;
2199 cp = find_compressor(ccp_option[0]);
2200 #ifdef CONFIG_KMOD
2201 if (cp == 0) {
2202 request_module("ppp-compress-%d", ccp_option[0]);
2203 cp = find_compressor(ccp_option[0]);
2205 #endif /* CONFIG_KMOD */
2206 if (cp == 0)
2207 goto out;
2209 err = -ENOBUFS;
2210 if (data.transmit) {
2211 state = cp->comp_alloc(ccp_option, data.length);
2212 if (state != 0) {
2213 ppp_xmit_lock(ppp);
2214 ppp->xstate &= ~SC_COMP_RUN;
2215 ocomp = ppp->xcomp;
2216 ostate = ppp->xc_state;
2217 ppp->xcomp = cp;
2218 ppp->xc_state = state;
2219 ppp_xmit_unlock(ppp);
2220 if (ostate != 0) {
2221 ocomp->comp_free(ostate);
2222 module_put(ocomp->owner);
2224 err = 0;
2225 } else
2226 module_put(cp->owner);
2228 } else {
2229 state = cp->decomp_alloc(ccp_option, data.length);
2230 if (state != 0) {
2231 ppp_recv_lock(ppp);
2232 ppp->rstate &= ~SC_DECOMP_RUN;
2233 ocomp = ppp->rcomp;
2234 ostate = ppp->rc_state;
2235 ppp->rcomp = cp;
2236 ppp->rc_state = state;
2237 ppp_recv_unlock(ppp);
2238 if (ostate != 0) {
2239 ocomp->decomp_free(ostate);
2240 module_put(ocomp->owner);
2242 err = 0;
2243 } else
2244 module_put(cp->owner);
2247 out:
2248 return err;
2252 * Look at a CCP packet and update our state accordingly.
2253 * We assume the caller has the xmit or recv path locked.
2255 static void
2256 ppp_ccp_peek(struct ppp *ppp, struct sk_buff *skb, int inbound)
2258 unsigned char *dp;
2259 int len;
2261 if (!pskb_may_pull(skb, CCP_HDRLEN + 2))
2262 return; /* no header */
2263 dp = skb->data + 2;
2265 switch (CCP_CODE(dp)) {
2266 case CCP_CONFREQ:
2268 /* A ConfReq starts negotiation of compression
2269 * in one direction of transmission,
2270 * and hence brings it down...but which way?
2272 * Remember:
2273 * A ConfReq indicates what the sender would like to receive
2275 if(inbound)
2276 /* He is proposing what I should send */
2277 ppp->xstate &= ~SC_COMP_RUN;
2278 else
2279 /* I am proposing to what he should send */
2280 ppp->rstate &= ~SC_DECOMP_RUN;
2282 break;
2284 case CCP_TERMREQ:
2285 case CCP_TERMACK:
2287 * CCP is going down, both directions of transmission
2289 ppp->rstate &= ~SC_DECOMP_RUN;
2290 ppp->xstate &= ~SC_COMP_RUN;
2291 break;
2293 case CCP_CONFACK:
2294 if ((ppp->flags & (SC_CCP_OPEN | SC_CCP_UP)) != SC_CCP_OPEN)
2295 break;
2296 len = CCP_LENGTH(dp);
2297 if (!pskb_may_pull(skb, len + 2))
2298 return; /* too short */
2299 dp += CCP_HDRLEN;
2300 len -= CCP_HDRLEN;
2301 if (len < CCP_OPT_MINLEN || len < CCP_OPT_LENGTH(dp))
2302 break;
2303 if (inbound) {
2304 /* we will start receiving compressed packets */
2305 if (ppp->rc_state == 0)
2306 break;
2307 if (ppp->rcomp->decomp_init(ppp->rc_state, dp, len,
2308 ppp->file.index, 0, ppp->mru, ppp->debug)) {
2309 ppp->rstate |= SC_DECOMP_RUN;
2310 ppp->rstate &= ~(SC_DC_ERROR | SC_DC_FERROR);
2312 } else {
2313 /* we will soon start sending compressed packets */
2314 if (ppp->xc_state == 0)
2315 break;
2316 if (ppp->xcomp->comp_init(ppp->xc_state, dp, len,
2317 ppp->file.index, 0, ppp->debug))
2318 ppp->xstate |= SC_COMP_RUN;
2320 break;
2322 case CCP_RESETACK:
2323 /* reset the [de]compressor */
2324 if ((ppp->flags & SC_CCP_UP) == 0)
2325 break;
2326 if (inbound) {
2327 if (ppp->rc_state && (ppp->rstate & SC_DECOMP_RUN)) {
2328 ppp->rcomp->decomp_reset(ppp->rc_state);
2329 ppp->rstate &= ~SC_DC_ERROR;
2331 } else {
2332 if (ppp->xc_state && (ppp->xstate & SC_COMP_RUN))
2333 ppp->xcomp->comp_reset(ppp->xc_state);
2335 break;
2339 /* Free up compression resources. */
2340 static void
2341 ppp_ccp_closed(struct ppp *ppp)
2343 void *xstate, *rstate;
2344 struct compressor *xcomp, *rcomp;
2346 ppp_lock(ppp);
2347 ppp->flags &= ~(SC_CCP_OPEN | SC_CCP_UP);
2348 ppp->xstate = 0;
2349 xcomp = ppp->xcomp;
2350 xstate = ppp->xc_state;
2351 ppp->xc_state = NULL;
2352 ppp->rstate = 0;
2353 rcomp = ppp->rcomp;
2354 rstate = ppp->rc_state;
2355 ppp->rc_state = NULL;
2356 ppp_unlock(ppp);
2358 if (xstate) {
2359 xcomp->comp_free(xstate);
2360 module_put(xcomp->owner);
2362 if (rstate) {
2363 rcomp->decomp_free(rstate);
2364 module_put(rcomp->owner);
2368 /* List of compressors. */
2369 static LIST_HEAD(compressor_list);
2370 static DEFINE_SPINLOCK(compressor_list_lock);
2372 struct compressor_entry {
2373 struct list_head list;
2374 struct compressor *comp;
2377 static struct compressor_entry *
2378 find_comp_entry(int proto)
2380 struct compressor_entry *ce;
2382 list_for_each_entry(ce, &compressor_list, list) {
2383 if (ce->comp->compress_proto == proto)
2384 return ce;
2386 return NULL;
2389 /* Register a compressor */
2391 ppp_register_compressor(struct compressor *cp)
2393 struct compressor_entry *ce;
2394 int ret;
2395 spin_lock(&compressor_list_lock);
2396 ret = -EEXIST;
2397 if (find_comp_entry(cp->compress_proto) != 0)
2398 goto out;
2399 ret = -ENOMEM;
2400 ce = kmalloc(sizeof(struct compressor_entry), GFP_ATOMIC);
2401 if (ce == 0)
2402 goto out;
2403 ret = 0;
2404 ce->comp = cp;
2405 list_add(&ce->list, &compressor_list);
2406 out:
2407 spin_unlock(&compressor_list_lock);
2408 return ret;
2411 /* Unregister a compressor */
2412 void
2413 ppp_unregister_compressor(struct compressor *cp)
2415 struct compressor_entry *ce;
2417 spin_lock(&compressor_list_lock);
2418 ce = find_comp_entry(cp->compress_proto);
2419 if (ce != 0 && ce->comp == cp) {
2420 list_del(&ce->list);
2421 kfree(ce);
2423 spin_unlock(&compressor_list_lock);
2426 /* Find a compressor. */
2427 static struct compressor *
2428 find_compressor(int type)
2430 struct compressor_entry *ce;
2431 struct compressor *cp = NULL;
2433 spin_lock(&compressor_list_lock);
2434 ce = find_comp_entry(type);
2435 if (ce != 0) {
2436 cp = ce->comp;
2437 if (!try_module_get(cp->owner))
2438 cp = NULL;
2440 spin_unlock(&compressor_list_lock);
2441 return cp;
2445 * Miscelleneous stuff.
2448 static void
2449 ppp_get_stats(struct ppp *ppp, struct ppp_stats *st)
2451 struct slcompress *vj = ppp->vj;
2453 memset(st, 0, sizeof(*st));
2454 st->p.ppp_ipackets = ppp->stats.rx_packets;
2455 st->p.ppp_ierrors = ppp->stats.rx_errors;
2456 st->p.ppp_ibytes = ppp->stats.rx_bytes;
2457 st->p.ppp_opackets = ppp->stats.tx_packets;
2458 st->p.ppp_oerrors = ppp->stats.tx_errors;
2459 st->p.ppp_obytes = ppp->stats.tx_bytes;
2460 if (vj == 0)
2461 return;
2462 st->vj.vjs_packets = vj->sls_o_compressed + vj->sls_o_uncompressed;
2463 st->vj.vjs_compressed = vj->sls_o_compressed;
2464 st->vj.vjs_searches = vj->sls_o_searches;
2465 st->vj.vjs_misses = vj->sls_o_misses;
2466 st->vj.vjs_errorin = vj->sls_i_error;
2467 st->vj.vjs_tossed = vj->sls_i_tossed;
2468 st->vj.vjs_uncompressedin = vj->sls_i_uncompressed;
2469 st->vj.vjs_compressedin = vj->sls_i_compressed;
2473 * Stuff for handling the lists of ppp units and channels
2474 * and for initialization.
2478 * Create a new ppp interface unit. Fails if it can't allocate memory
2479 * or if there is already a unit with the requested number.
2480 * unit == -1 means allocate a new number.
2482 static struct ppp *
2483 ppp_create_interface(int unit, int *retp)
2485 struct ppp *ppp;
2486 struct net_device *dev = NULL;
2487 int ret = -ENOMEM;
2488 int i;
2490 ppp = kzalloc(sizeof(struct ppp), GFP_KERNEL);
2491 if (!ppp)
2492 goto out;
2493 dev = alloc_netdev(0, "", ppp_setup);
2494 if (!dev)
2495 goto out1;
2497 ppp->mru = PPP_MRU;
2498 ppp->mru_alloc = PPP_MRU;
2499 init_ppp_file(&ppp->file, INTERFACE);
2500 ppp->file.hdrlen = PPP_HDRLEN - 2; /* don't count proto bytes */
2501 for (i = 0; i < NUM_NP; ++i)
2502 ppp->npmode[i] = NPMODE_PASS;
2503 INIT_LIST_HEAD(&ppp->channels);
2504 spin_lock_init(&ppp->rlock);
2505 spin_lock_init(&ppp->wlock);
2506 #ifdef CONFIG_PPP_MULTILINK
2507 ppp->minseq = -1;
2508 skb_queue_head_init(&ppp->mrq);
2509 #endif /* CONFIG_PPP_MULTILINK */
2510 ppp->dev = dev;
2511 dev->priv = ppp;
2513 dev->hard_start_xmit = ppp_start_xmit;
2514 dev->get_stats = ppp_net_stats;
2515 dev->do_ioctl = ppp_net_ioctl;
2517 ret = -EEXIST;
2518 mutex_lock(&all_ppp_mutex);
2519 if (unit < 0)
2520 unit = cardmap_find_first_free(all_ppp_units);
2521 else if (cardmap_get(all_ppp_units, unit) != NULL)
2522 goto out2; /* unit already exists */
2524 /* Initialize the new ppp unit */
2525 ppp->file.index = unit;
2526 sprintf(dev->name, "ppp%d", unit);
2528 ret = register_netdev(dev);
2529 if (ret != 0) {
2530 printk(KERN_ERR "PPP: couldn't register device %s (%d)\n",
2531 dev->name, ret);
2532 goto out2;
2535 #ifdef HNDCTF
2536 if ((ctf_dev_register(kcih, dev, FALSE) != BCME_OK) ||
2537 (ctf_enable(kcih, dev, TRUE, NULL) != BCME_OK))
2538 ctf_dev_unregister(kcih, dev);
2539 #endif
2541 atomic_inc(&ppp_unit_count);
2542 ret = cardmap_set(&all_ppp_units, unit, ppp);
2543 if (ret != 0)
2544 goto out3;
2546 mutex_unlock(&all_ppp_mutex);
2547 *retp = 0;
2548 return ppp;
2550 out3:
2551 atomic_dec(&ppp_unit_count);
2552 out2:
2553 mutex_unlock(&all_ppp_mutex);
2554 free_netdev(dev);
2555 out1:
2556 kfree(ppp);
2557 out:
2558 *retp = ret;
2559 return NULL;
2563 * Initialize a ppp_file structure.
2565 static void
2566 init_ppp_file(struct ppp_file *pf, int kind)
2568 pf->kind = kind;
2569 skb_queue_head_init(&pf->xq);
2570 skb_queue_head_init(&pf->rq);
2571 atomic_set(&pf->refcnt, 1);
2572 init_waitqueue_head(&pf->rwait);
2576 * Take down a ppp interface unit - called when the owning file
2577 * (the one that created the unit) is closed or detached.
2579 static void ppp_shutdown_interface(struct ppp *ppp)
2581 struct net_device *dev;
2583 mutex_lock(&all_ppp_mutex);
2584 ppp_lock(ppp);
2585 dev = ppp->dev;
2586 ppp->dev = NULL;
2587 ppp_unlock(ppp);
2588 /* This will call dev_close() for us. */
2589 if (dev) {
2590 #ifdef HNDCTF
2591 ctf_dev_unregister(kcih, dev);
2592 #endif
2593 unregister_netdev(dev);
2594 free_netdev(dev);
2596 cardmap_set(&all_ppp_units, ppp->file.index, NULL);
2597 ppp->file.dead = 1;
2598 ppp->owner = NULL;
2599 wake_up_interruptible(&ppp->file.rwait);
2600 mutex_unlock(&all_ppp_mutex);
2604 * Free the memory used by a ppp unit. This is only called once
2605 * there are no channels connected to the unit and no file structs
2606 * that reference the unit.
2608 static void ppp_destroy_interface(struct ppp *ppp)
2610 atomic_dec(&ppp_unit_count);
2612 if (!ppp->file.dead || ppp->n_channels) {
2613 /* "can't happen" */
2614 printk(KERN_ERR "ppp: destroying ppp struct %p but dead=%d "
2615 "n_channels=%d !\n", ppp, ppp->file.dead,
2616 ppp->n_channels);
2617 return;
2620 ppp_ccp_closed(ppp);
2621 if (ppp->vj) {
2622 slhc_free(ppp->vj);
2623 ppp->vj = NULL;
2625 skb_queue_purge(&ppp->file.xq);
2626 skb_queue_purge(&ppp->file.rq);
2627 #ifdef CONFIG_PPP_MULTILINK
2628 skb_queue_purge(&ppp->mrq);
2629 #endif /* CONFIG_PPP_MULTILINK */
2630 #ifdef CONFIG_PPP_FILTER
2631 kfree(ppp->pass_filter);
2632 ppp->pass_filter = NULL;
2633 kfree(ppp->active_filter);
2634 ppp->active_filter = NULL;
2635 #endif /* CONFIG_PPP_FILTER */
2637 if (ppp->xmit_pending)
2638 kfree_skb(ppp->xmit_pending);
2640 kfree(ppp);
2644 * Locate an existing ppp unit.
2645 * The caller should have locked the all_ppp_mutex.
2647 static struct ppp *
2648 ppp_find_unit(int unit)
2650 return cardmap_get(all_ppp_units, unit);
2654 * Locate an existing ppp channel.
2655 * The caller should have locked the all_channels_lock.
2656 * First we look in the new_channels list, then in the
2657 * all_channels list. If found in the new_channels list,
2658 * we move it to the all_channels list. This is for speed
2659 * when we have a lot of channels in use.
2661 static struct channel *
2662 ppp_find_channel(int unit)
2664 struct channel *pch;
2666 list_for_each_entry(pch, &new_channels, list) {
2667 if (pch->file.index == unit) {
2668 list_move(&pch->list, &all_channels);
2669 return pch;
2672 list_for_each_entry(pch, &all_channels, list) {
2673 if (pch->file.index == unit)
2674 return pch;
2676 return NULL;
2680 * Connect a PPP channel to a PPP interface unit.
2682 static int
2683 ppp_connect_channel(struct channel *pch, int unit)
2685 struct ppp *ppp;
2686 int ret = -ENXIO;
2687 int hdrlen;
2689 mutex_lock(&all_ppp_mutex);
2690 ppp = ppp_find_unit(unit);
2691 if (ppp == 0)
2692 goto out;
2693 write_lock_bh(&pch->upl);
2694 ret = -EINVAL;
2695 if (pch->ppp != 0)
2696 goto outl;
2698 ppp_lock(ppp);
2699 if (pch->file.hdrlen > ppp->file.hdrlen)
2700 ppp->file.hdrlen = pch->file.hdrlen;
2701 hdrlen = pch->file.hdrlen + 2; /* for protocol bytes */
2702 if (ppp->dev && hdrlen > ppp->dev->hard_header_len)
2703 ppp->dev->hard_header_len = hdrlen;
2704 list_add_tail(&pch->clist, &ppp->channels);
2705 ++ppp->n_channels;
2706 pch->ppp = ppp;
2707 #ifdef HNDCTF
2708 ppp->ctfpch = pch;
2709 #endif
2710 atomic_inc(&ppp->file.refcnt);
2711 ppp_unlock(ppp);
2712 ret = 0;
2714 outl:
2715 write_unlock_bh(&pch->upl);
2716 out:
2717 mutex_unlock(&all_ppp_mutex);
2718 return ret;
2722 * Disconnect a channel from its ppp unit.
2724 static int
2725 ppp_disconnect_channel(struct channel *pch)
2727 struct ppp *ppp;
2728 int err = -EINVAL;
2730 write_lock_bh(&pch->upl);
2731 ppp = pch->ppp;
2732 pch->ppp = NULL;
2733 write_unlock_bh(&pch->upl);
2734 if (ppp != 0) {
2735 /* remove it from the ppp unit's list */
2736 ppp_lock(ppp);
2737 list_del(&pch->clist);
2738 if (--ppp->n_channels == 0)
2739 wake_up_interruptible(&ppp->file.rwait);
2740 ppp_unlock(ppp);
2741 if (atomic_dec_and_test(&ppp->file.refcnt))
2742 ppp_destroy_interface(ppp);
2743 err = 0;
2745 return err;
2749 * Free up the resources used by a ppp channel.
2751 static void ppp_destroy_channel(struct channel *pch)
2753 atomic_dec(&channel_count);
2755 if (!pch->file.dead) {
2756 /* "can't happen" */
2757 printk(KERN_ERR "ppp: destroying undead channel %p !\n",
2758 pch);
2759 return;
2761 skb_queue_purge(&pch->file.xq);
2762 skb_queue_purge(&pch->file.rq);
2763 kfree(pch);
2766 static void __exit ppp_cleanup(void)
2768 /* should never happen */
2769 if (atomic_read(&ppp_unit_count) || atomic_read(&channel_count))
2770 printk(KERN_ERR "PPP: removing module but units remain!\n");
2771 cardmap_destroy(&all_ppp_units);
2772 if (unregister_chrdev(PPP_MAJOR, "ppp") != 0)
2773 printk(KERN_ERR "PPP: failed to unregister PPP device\n");
2774 device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0));
2775 class_destroy(ppp_class);
2779 * Cardmap implementation.
2781 static void *cardmap_get(struct cardmap *map, unsigned int nr)
2783 struct cardmap *p;
2784 int i;
2786 for (p = map; p != NULL; ) {
2787 if ((i = nr >> p->shift) >= CARDMAP_WIDTH)
2788 return NULL;
2789 if (p->shift == 0)
2790 return p->ptr[i];
2791 nr &= ~(CARDMAP_MASK << p->shift);
2792 p = p->ptr[i];
2794 return NULL;
2797 static int cardmap_set(struct cardmap **pmap, unsigned int nr, void *ptr)
2799 struct cardmap *p;
2800 int i;
2802 p = *pmap;
2803 if (p == NULL || (nr >> p->shift) >= CARDMAP_WIDTH) {
2804 do {
2805 /* need a new top level */
2806 struct cardmap *np = kzalloc(sizeof(*np), GFP_KERNEL);
2807 if (!np)
2808 goto enomem;
2809 np->ptr[0] = p;
2810 if (p != NULL) {
2811 np->shift = p->shift + CARDMAP_ORDER;
2812 p->parent = np;
2813 } else
2814 np->shift = 0;
2815 p = np;
2816 } while ((nr >> p->shift) >= CARDMAP_WIDTH);
2817 *pmap = p;
2819 while (p->shift > 0) {
2820 i = (nr >> p->shift) & CARDMAP_MASK;
2821 if (p->ptr[i] == NULL) {
2822 struct cardmap *np = kzalloc(sizeof(*np), GFP_KERNEL);
2823 if (!np)
2824 goto enomem;
2825 np->shift = p->shift - CARDMAP_ORDER;
2826 np->parent = p;
2827 p->ptr[i] = np;
2829 if (ptr == NULL)
2830 clear_bit(i, &p->inuse);
2831 p = p->ptr[i];
2833 i = nr & CARDMAP_MASK;
2834 p->ptr[i] = ptr;
2835 if (ptr != NULL)
2836 set_bit(i, &p->inuse);
2837 else
2838 clear_bit(i, &p->inuse);
2839 return 0;
2840 enomem:
2841 return -ENOMEM;
2844 static unsigned int cardmap_find_first_free(struct cardmap *map)
2846 struct cardmap *p;
2847 unsigned int nr = 0;
2848 int i;
2850 if ((p = map) == NULL)
2851 return 0;
2852 for (;;) {
2853 i = find_first_zero_bit(&p->inuse, CARDMAP_WIDTH);
2854 if (i >= CARDMAP_WIDTH) {
2855 if (p->parent == NULL)
2856 return CARDMAP_WIDTH << p->shift;
2857 p = p->parent;
2858 i = (nr >> p->shift) & CARDMAP_MASK;
2859 set_bit(i, &p->inuse);
2860 continue;
2862 nr = (nr & (~CARDMAP_MASK << p->shift)) | (i << p->shift);
2863 if (p->shift == 0 || p->ptr[i] == NULL)
2864 return nr;
2865 p = p->ptr[i];
2869 static void cardmap_destroy(struct cardmap **pmap)
2871 struct cardmap *p, *np;
2872 int i;
2874 for (p = *pmap; p != NULL; p = np) {
2875 if (p->shift != 0) {
2876 for (i = 0; i < CARDMAP_WIDTH; ++i)
2877 if (p->ptr[i] != NULL)
2878 break;
2879 if (i < CARDMAP_WIDTH) {
2880 np = p->ptr[i];
2881 p->ptr[i] = NULL;
2882 continue;
2885 np = p->parent;
2886 kfree(p);
2888 *pmap = NULL;
2891 #ifdef HNDCTF
2892 #if defined(CTF_PPPOE) || defined(CTF_PPTP) || defined(CTF_L2TP)
2893 void
2894 ppp_rxstats_upd(void *pppif, struct sk_buff *skb)
2896 if(pppif == NULL || skb == NULL)
2897 return;
2898 struct ppp *ppp = ((struct net_device *)pppif)->priv;
2899 if(ppp == NULL)
2900 return;
2901 ++ppp->stats.rx_packets;
2902 ppp->stats.rx_bytes += skb->len;
2903 ppp->last_recv = jiffies;
2906 void
2907 ppp_txstats_upd(void *pppif, struct sk_buff *skb)
2909 if(pppif == NULL || skb == NULL)
2910 return;
2911 struct ppp *ppp = ((struct net_device *)pppif)->priv;
2912 if(ppp == NULL)
2913 return;
2914 ++ppp->stats.tx_packets;
2915 ppp->stats.tx_bytes += skb->len;
2916 ppp->last_xmit = jiffies;
2921 ppp_get_conn_pkt_info(int unit, struct ctf_ppp *ctfppp){
2922 struct pppox_sock *po = NULL;
2923 struct asyncppp *ap = NULL;
2924 struct sock *sk = NULL;
2925 struct ppp *ppp = NULL;
2926 struct channel *pch = NULL;
2927 const char *vars = NULL;
2929 ppp = ppp_find_unit(unit);
2930 if(ppp) pch = ppp->ctfpch;
2932 if (pch == NULL){
2933 return (BCME_ERROR);
2936 po = pppox_sk((struct sock *)pch->chan->private);
2937 ap = (struct asyncppp *)pch->chan->private;
2939 if(ap && ap->tty)
2940 return (BCME_ERROR);
2942 if (po == NULL){
2943 return (BCME_ERROR);
2945 ctfppp->psk.po = po;
2947 sk = po->chan.private;
2948 if(sk /*&& sizeof(sk) > sizeof(struct sock_common)*/){
2949 ctfppp->psk.pppox_protocol = sk->sk_protocol;
2950 switch (sk->sk_protocol){
2951 case PX_PROTO_OE:
2952 ctfppp->pppox_id = po->pppoe_pa.sid;
2953 memcpy(ctfppp->psk.dhost.octet , po->pppoe_pa.remote, ETH_ALEN);
2955 #ifdef DEBUG
2956 printk("%s: Adding ppp connection: session ID =%04x, Address=%02x:%02x:%02x:%02x:%02x:%02x\n",
2957 __FUNCTION__,ntohs(ctfppp->pppox_id),
2958 ctfppp->psk.dhost.octet[0], ctfppp->psk.dhost.octet[1],
2959 ctfppp->psk.dhost.octet[2], ctfppp->psk.dhost.octet[3],
2960 ctfppp->psk.dhost.octet[4], ctfppp->psk.dhost.octet[5]);
2961 #endif /*DEBUG*/
2962 break;
2963 #if 0
2964 case PX_PROTO_PPTP:
2965 ctfppp->pppox_id = po->proto.pptp.dst_addr.call_id;
2966 #ifdef DEBUG
2968 printk("%s: Adding pptp entry: src call ID =%04x, src ip=%u.%u.%u.%u, dst call ID=%4x, dst ip=%u.%u.%u.%u\n ",
2969 __FUNCTION__,po->proto.pptp.dst_addr.call_id, NIPQUAD(po->proto.pptp.src_addr.sin_addr.s_addr),
2970 po->proto.pptp.dst_addr.call_id,NIPQUAD(po->proto.pptp.dst_addr.sin_addr.s_addr));
2971 //printk("%s\n ",sk->sk_send_head->dev->name);
2972 #endif
2973 break;
2974 #endif
2975 default:
2976 return (BCME_ERROR);
2979 else{
2980 return (BCME_ERROR);
2982 return (BCME_OK);
2986 EXPORT_SYMBOL(ppp_rxstats_upd);
2987 EXPORT_SYMBOL(ppp_txstats_upd);
2988 EXPORT_SYMBOL(ppp_get_conn_pkt_info);
2990 #endif /* CTF_PPPOE | CTF_PPTP | CTF_L2TP */
2991 #endif /* HNDCTF */
2993 /* Module/initialization stuff */
2995 module_init(ppp_init);
2996 module_exit(ppp_cleanup);
2998 EXPORT_SYMBOL(ppp_register_channel);
2999 EXPORT_SYMBOL(ppp_unregister_channel);
3000 EXPORT_SYMBOL(ppp_channel_index);
3001 EXPORT_SYMBOL(ppp_unit_number);
3002 EXPORT_SYMBOL(ppp_input);
3003 EXPORT_SYMBOL(ppp_input_error);
3004 EXPORT_SYMBOL(ppp_output_wakeup);
3005 EXPORT_SYMBOL(ppp_register_compressor);
3006 EXPORT_SYMBOL(ppp_unregister_compressor);
3007 MODULE_LICENSE("GPL");
3008 MODULE_ALIAS_CHARDEV_MAJOR(PPP_MAJOR);
3009 MODULE_ALIAS("/dev/ppp");