+- add patches.fixes/linux-post-2.6.3-20040220
[linux-flexiantxendom0-3.2.10.git] / drivers / net / ppp_generic.c
1 /*
2  * Generic PPP layer for Linux.
3  *
4  * Copyright 1999-2002 Paul Mackerras.
5  *
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.
10  *
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.
17  *
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.
21  *
22  * ==FILEVERSION 20020217==
23  */
24
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/kmod.h>
29 #include <linux/init.h>
30 #include <linux/list.h>
31 #include <linux/devfs_fs_kernel.h>
32 #include <linux/netdevice.h>
33 #include <linux/poll.h>
34 #include <linux/ppp_defs.h>
35 #include <linux/filter.h>
36 #include <linux/if_ppp.h>
37 #include <linux/ppp_channel.h>
38 #include <linux/ppp-comp.h>
39 #include <linux/skbuff.h>
40 #include <linux/rtnetlink.h>
41 #include <linux/if_arp.h>
42 #include <linux/ip.h>
43 #include <linux/tcp.h>
44 #include <linux/spinlock.h>
45 #include <linux/smp_lock.h>
46 #include <linux/rwsem.h>
47 #include <linux/stddef.h>
48 #include <net/slhc_vj.h>
49 #include <asm/atomic.h>
50
51 #define PPP_VERSION     "2.4.2"
52
53 /*
54  * Network protocols we support.
55  */
56 #define NP_IP   0               /* Internet Protocol V4 */
57 #define NP_IPV6 1               /* Internet Protocol V6 */
58 #define NP_IPX  2               /* IPX protocol */
59 #define NP_AT   3               /* Appletalk protocol */
60 #define NP_MPLS_UC 4            /* MPLS unicast */
61 #define NP_MPLS_MC 5            /* MPLS multicast */
62 #define NUM_NP  6               /* Number of NPs. */
63
64 #define MPHDRLEN        6       /* multilink protocol header length */
65 #define MPHDRLEN_SSN    4       /* ditto with short sequence numbers */
66 #define MIN_FRAG_SIZE   64
67
68 /*
69  * An instance of /dev/ppp can be associated with either a ppp
70  * interface unit or a ppp channel.  In both cases, file->private_data
71  * points to one of these.
72  */
73 struct ppp_file {
74         enum {
75                 INTERFACE=1, CHANNEL
76         }               kind;
77         struct sk_buff_head xq;         /* pppd transmit queue */
78         struct sk_buff_head rq;         /* receive queue for pppd */
79         wait_queue_head_t rwait;        /* for poll on reading /dev/ppp */
80         atomic_t        refcnt;         /* # refs (incl /dev/ppp attached) */
81         int             hdrlen;         /* space to leave for headers */
82         int             index;          /* interface unit / channel number */
83         int             dead;           /* unit/channel has been shut down */
84 };
85
86 #define PF_TO_X(pf, X)          ((X *)((char *)(pf) - offsetof(X, file)))
87
88 #define PF_TO_PPP(pf)           PF_TO_X(pf, struct ppp)
89 #define PF_TO_CHANNEL(pf)       PF_TO_X(pf, struct channel)
90
91 #define ROUNDUP(n, x)           (((n) + (x) - 1) / (x))
92
93 /*
94  * Data structure describing one ppp unit.
95  * A ppp unit corresponds to a ppp network interface device
96  * and represents a multilink bundle.
97  * It can have 0 or more ppp channels connected to it.
98  */
99 struct ppp {
100         struct ppp_file file;           /* stuff for read/write/poll 0 */
101         struct file     *owner;         /* file that owns this unit 48 */
102         struct list_head channels;      /* list of attached channels 4c */
103         int             n_channels;     /* how many channels are attached 54 */
104         spinlock_t      rlock;          /* lock for receive side 58 */
105         spinlock_t      wlock;          /* lock for transmit side 5c */
106         int             mru;            /* max receive unit 60 */
107         unsigned int    flags;          /* control bits 64 */
108         unsigned int    xstate;         /* transmit state bits 68 */
109         unsigned int    rstate;         /* receive state bits 6c */
110         int             debug;          /* debug flags 70 */
111         struct slcompress *vj;          /* state for VJ header compression */
112         enum NPmode     npmode[NUM_NP]; /* what to do with each net proto 78 */
113         struct sk_buff  *xmit_pending;  /* a packet ready to go out 88 */
114         struct compressor *xcomp;       /* transmit packet compressor 8c */
115         void            *xc_state;      /* its internal state 90 */
116         struct compressor *rcomp;       /* receive decompressor 94 */
117         void            *rc_state;      /* its internal state 98 */
118         unsigned long   last_xmit;      /* jiffies when last pkt sent 9c */
119         unsigned long   last_recv;      /* jiffies when last pkt rcvd a0 */
120         struct net_device *dev;         /* network interface device a4 */
121 #ifdef CONFIG_PPP_MULTILINK
122         int             nxchan;         /* next channel to send something on */
123         u32             nxseq;          /* next sequence number to send */
124         int             mrru;           /* MP: max reconst. receive unit */
125         u32             nextseq;        /* MP: seq no of next packet */
126         u32             minseq;         /* MP: min of most recent seqnos */
127         struct sk_buff_head mrq;        /* MP: receive reconstruction queue */
128 #endif /* CONFIG_PPP_MULTILINK */
129         struct net_device_stats stats;  /* statistics */
130 #ifdef CONFIG_PPP_FILTER
131         struct sock_fprog pass_filter;  /* filter for packets to pass */
132         struct sock_fprog active_filter;/* filter for pkts to reset idle */
133 #endif /* CONFIG_PPP_FILTER */
134 };
135
136 /*
137  * Bits in flags: SC_NO_TCP_CCID, SC_CCP_OPEN, SC_CCP_UP, SC_LOOP_TRAFFIC,
138  * SC_MULTILINK, SC_MP_SHORTSEQ, SC_MP_XSHORTSEQ, SC_COMP_TCP, SC_REJ_COMP_TCP.
139  * Bits in rstate: SC_DECOMP_RUN, SC_DC_ERROR, SC_DC_FERROR.
140  * Bits in xstate: SC_COMP_RUN
141  */
142 #define SC_FLAG_BITS    (SC_NO_TCP_CCID|SC_CCP_OPEN|SC_CCP_UP|SC_LOOP_TRAFFIC \
143                          |SC_MULTILINK|SC_MP_SHORTSEQ|SC_MP_XSHORTSEQ \
144                          |SC_COMP_TCP|SC_REJ_COMP_TCP)
145
146 /*
147  * Private data structure for each channel.
148  * This includes the data structure used for multilink.
149  */
150 struct channel {
151         struct ppp_file file;           /* stuff for read/write/poll */
152         struct list_head list;          /* link in all/new_channels list */
153         struct ppp_channel *chan;       /* public channel data structure */
154         struct rw_semaphore chan_sem;   /* protects `chan' during chan ioctl */
155         spinlock_t      downl;          /* protects `chan', file.xq dequeue */
156         struct ppp      *ppp;           /* ppp unit we're connected to */
157         struct list_head clist;         /* link in list of channels per unit */
158         rwlock_t        upl;            /* protects `ppp' */
159 #ifdef CONFIG_PPP_MULTILINK
160         u8              avail;          /* flag used in multilink stuff */
161         u8              had_frag;       /* >= 1 fragments have been sent */
162         u32             lastseq;        /* MP: last sequence # received */
163 #endif /* CONFIG_PPP_MULTILINK */
164 };
165
166 /*
167  * SMP locking issues:
168  * Both the ppp.rlock and ppp.wlock locks protect the ppp.channels
169  * list and the ppp.n_channels field, you need to take both locks
170  * before you modify them.
171  * The lock ordering is: channel.upl -> ppp.wlock -> ppp.rlock ->
172  * channel.downl.
173  */
174
175 /*
176  * A cardmap represents a mapping from unsigned integers to pointers,
177  * and provides a fast "find lowest unused number" operation.
178  * It uses a broad (32-way) tree with a bitmap at each level.
179  * It is designed to be space-efficient for small numbers of entries
180  * and time-efficient for large numbers of entries.
181  */
182 #define CARDMAP_ORDER   5
183 #define CARDMAP_WIDTH   (1U << CARDMAP_ORDER)
184 #define CARDMAP_MASK    (CARDMAP_WIDTH - 1)
185
186 struct cardmap {
187         int shift;
188         unsigned long inuse;
189         struct cardmap *parent;
190         void *ptr[CARDMAP_WIDTH];
191 };
192 static void *cardmap_get(struct cardmap *map, unsigned int nr);
193 static void cardmap_set(struct cardmap **map, unsigned int nr, void *ptr);
194 static unsigned int cardmap_find_first_free(struct cardmap *map);
195 static void cardmap_destroy(struct cardmap **map);
196
197 /*
198  * all_ppp_sem protects the all_ppp_units mapping.
199  * It also ensures that finding a ppp unit in the all_ppp_units map
200  * and updating its file.refcnt field is atomic.
201  */
202 static DECLARE_MUTEX(all_ppp_sem);
203 static struct cardmap *all_ppp_units;
204 static atomic_t ppp_unit_count = ATOMIC_INIT(0);
205
206 /*
207  * all_channels_lock protects all_channels and last_channel_index,
208  * and the atomicity of find a channel and updating its file.refcnt
209  * field.
210  */
211 static spinlock_t all_channels_lock = SPIN_LOCK_UNLOCKED;
212 static LIST_HEAD(all_channels);
213 static LIST_HEAD(new_channels);
214 static int last_channel_index;
215 static atomic_t channel_count = ATOMIC_INIT(0);
216
217 /* Get the PPP protocol number from a skb */
218 #define PPP_PROTO(skb)  (((skb)->data[0] << 8) + (skb)->data[1])
219
220 /* We limit the length of ppp->file.rq to this (arbitrary) value */
221 #define PPP_MAX_RQLEN   32
222
223 /*
224  * Maximum number of multilink fragments queued up.
225  * This has to be large enough to cope with the maximum latency of
226  * the slowest channel relative to the others.  Strictly it should
227  * depend on the number of channels and their characteristics.
228  */
229 #define PPP_MP_MAX_QLEN 128
230
231 /* Multilink header bits. */
232 #define B       0x80            /* this fragment begins a packet */
233 #define E       0x40            /* this fragment ends a packet */
234
235 /* Compare multilink sequence numbers (assumed to be 32 bits wide) */
236 #define seq_before(a, b)        ((s32)((a) - (b)) < 0)
237 #define seq_after(a, b)         ((s32)((a) - (b)) > 0)
238
239 /* Prototypes. */
240 static int ppp_unattached_ioctl(struct ppp_file *pf, struct file *file,
241                                 unsigned int cmd, unsigned long arg);
242 static void ppp_xmit_process(struct ppp *ppp);
243 static void ppp_send_frame(struct ppp *ppp, struct sk_buff *skb);
244 static void ppp_push(struct ppp *ppp);
245 static void ppp_channel_push(struct channel *pch);
246 static void ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb,
247                               struct channel *pch);
248 static void ppp_receive_error(struct ppp *ppp);
249 static void ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb);
250 static struct sk_buff *ppp_decompress_frame(struct ppp *ppp,
251                                             struct sk_buff *skb);
252 #ifdef CONFIG_PPP_MULTILINK
253 static void ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb,
254                                 struct channel *pch);
255 static void ppp_mp_insert(struct ppp *ppp, struct sk_buff *skb);
256 static struct sk_buff *ppp_mp_reconstruct(struct ppp *ppp);
257 static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb);
258 #endif /* CONFIG_PPP_MULTILINK */
259 static int ppp_set_compress(struct ppp *ppp, unsigned long arg);
260 static void ppp_ccp_peek(struct ppp *ppp, struct sk_buff *skb, int inbound);
261 static void ppp_ccp_closed(struct ppp *ppp);
262 static struct compressor *find_compressor(int type);
263 static void ppp_get_stats(struct ppp *ppp, struct ppp_stats *st);
264 static struct ppp *ppp_create_interface(int unit, int *retp);
265 static void init_ppp_file(struct ppp_file *pf, int kind);
266 static void ppp_shutdown_interface(struct ppp *ppp);
267 static void ppp_destroy_interface(struct ppp *ppp);
268 static struct ppp *ppp_find_unit(int unit);
269 static struct channel *ppp_find_channel(int unit);
270 static int ppp_connect_channel(struct channel *pch, int unit);
271 static int ppp_disconnect_channel(struct channel *pch);
272 static void ppp_destroy_channel(struct channel *pch);
273
274 /* Translates a PPP protocol number to a NP index (NP == network protocol) */
275 static inline int proto_to_npindex(int proto)
276 {
277         switch (proto) {
278         case PPP_IP:
279                 return NP_IP;
280         case PPP_IPV6:
281                 return NP_IPV6;
282         case PPP_IPX:
283                 return NP_IPX;
284         case PPP_AT:
285                 return NP_AT;
286         case PPP_MPLS_UC:
287                 return NP_MPLS_UC;
288         case PPP_MPLS_MC:
289                 return NP_MPLS_MC;
290         }
291         return -EINVAL;
292 }
293
294 /* Translates an NP index into a PPP protocol number */
295 static const int npindex_to_proto[NUM_NP] = {
296         PPP_IP,
297         PPP_IPV6,
298         PPP_IPX,
299         PPP_AT,
300         PPP_MPLS_UC,
301         PPP_MPLS_MC,
302 };
303         
304 /* Translates an ethertype into an NP index */
305 static inline int ethertype_to_npindex(int ethertype)
306 {
307         switch (ethertype) {
308         case ETH_P_IP:
309                 return NP_IP;
310         case ETH_P_IPV6:
311                 return NP_IPV6;
312         case ETH_P_IPX:
313                 return NP_IPX;
314         case ETH_P_PPPTALK:
315         case ETH_P_ATALK:
316                 return NP_AT;
317         case ETH_P_MPLS_UC:
318                 return NP_MPLS_UC;
319         case ETH_P_MPLS_MC:
320                 return NP_MPLS_MC;
321         }
322         return -1;
323 }
324
325 /* Translates an NP index into an ethertype */
326 static const int npindex_to_ethertype[NUM_NP] = {
327         ETH_P_IP,
328         ETH_P_IPV6,
329         ETH_P_IPX,
330         ETH_P_PPPTALK,
331         ETH_P_MPLS_UC,
332         ETH_P_MPLS_MC,
333 };
334
335 /*
336  * Locking shorthand.
337  */
338 #define ppp_xmit_lock(ppp)      spin_lock_bh(&(ppp)->wlock)
339 #define ppp_xmit_unlock(ppp)    spin_unlock_bh(&(ppp)->wlock)
340 #define ppp_recv_lock(ppp)      spin_lock_bh(&(ppp)->rlock)
341 #define ppp_recv_unlock(ppp)    spin_unlock_bh(&(ppp)->rlock)
342 #define ppp_lock(ppp)           do { ppp_xmit_lock(ppp); \
343                                      ppp_recv_lock(ppp); } while (0)
344 #define ppp_unlock(ppp)         do { ppp_recv_unlock(ppp); \
345                                      ppp_xmit_unlock(ppp); } while (0)
346
347 /*
348  * /dev/ppp device routines.
349  * The /dev/ppp device is used by pppd to control the ppp unit.
350  * It supports the read, write, ioctl and poll functions.
351  * Open instances of /dev/ppp can be in one of three states:
352  * unattached, attached to a ppp unit, or attached to a ppp channel.
353  */
354 static int ppp_open(struct inode *inode, struct file *file)
355 {
356         /*
357          * This could (should?) be enforced by the permissions on /dev/ppp.
358          */
359         if (!capable(CAP_NET_ADMIN))
360                 return -EPERM;
361         return 0;
362 }
363
364 static int ppp_release(struct inode *inode, struct file *file)
365 {
366         struct ppp_file *pf = file->private_data;
367         struct ppp *ppp;
368
369         if (pf != 0) {
370                 file->private_data = 0;
371                 if (pf->kind == INTERFACE) {
372                         ppp = PF_TO_PPP(pf);
373                         if (file == ppp->owner)
374                                 ppp_shutdown_interface(ppp);
375                 }
376                 if (atomic_dec_and_test(&pf->refcnt)) {
377                         switch (pf->kind) {
378                         case INTERFACE:
379                                 ppp_destroy_interface(PF_TO_PPP(pf));
380                                 break;
381                         case CHANNEL:
382                                 ppp_destroy_channel(PF_TO_CHANNEL(pf));
383                                 break;
384                         }
385                 }
386         }
387         return 0;
388 }
389
390 static ssize_t ppp_read(struct file *file, char __user *buf,
391                         size_t count, loff_t *ppos)
392 {
393         struct ppp_file *pf = file->private_data;
394         DECLARE_WAITQUEUE(wait, current);
395         ssize_t ret;
396         struct sk_buff *skb = 0;
397
398         ret = count;
399
400         if (pf == 0)
401                 return -ENXIO;
402         add_wait_queue(&pf->rwait, &wait);
403         for (;;) {
404                 set_current_state(TASK_INTERRUPTIBLE);
405                 skb = skb_dequeue(&pf->rq);
406                 if (skb)
407                         break;
408                 ret = 0;
409                 if (pf->dead)
410                         break;
411                 ret = -EAGAIN;
412                 if (file->f_flags & O_NONBLOCK)
413                         break;
414                 ret = -ERESTARTSYS;
415                 if (signal_pending(current))
416                         break;
417                 schedule();
418         }
419         set_current_state(TASK_RUNNING);
420         remove_wait_queue(&pf->rwait, &wait);
421
422         if (skb == 0)
423                 goto out;
424
425         ret = -EOVERFLOW;
426         if (skb->len > count)
427                 goto outf;
428         ret = -EFAULT;
429         if (copy_to_user(buf, skb->data, skb->len))
430                 goto outf;
431         ret = skb->len;
432
433  outf:
434         kfree_skb(skb);
435  out:
436         return ret;
437 }
438
439 static ssize_t ppp_write(struct file *file, const char __user *buf,
440                          size_t count, loff_t *ppos)
441 {
442         struct ppp_file *pf = file->private_data;
443         struct sk_buff *skb;
444         ssize_t ret;
445
446         if (pf == 0)
447                 return -ENXIO;
448         ret = -ENOMEM;
449         skb = alloc_skb(count + pf->hdrlen, GFP_KERNEL);
450         if (skb == 0)
451                 goto out;
452         skb_reserve(skb, pf->hdrlen);
453         ret = -EFAULT;
454         if (copy_from_user(skb_put(skb, count), buf, count)) {
455                 kfree_skb(skb);
456                 goto out;
457         }
458
459         skb_queue_tail(&pf->xq, skb);
460
461         switch (pf->kind) {
462         case INTERFACE:
463                 ppp_xmit_process(PF_TO_PPP(pf));
464                 break;
465         case CHANNEL:
466                 ppp_channel_push(PF_TO_CHANNEL(pf));
467                 break;
468         }
469
470         ret = count;
471
472  out:
473         return ret;
474 }
475
476 /* No kernel lock - fine */
477 static unsigned int ppp_poll(struct file *file, poll_table *wait)
478 {
479         struct ppp_file *pf = file->private_data;
480         unsigned int mask;
481
482         if (pf == 0)
483                 return 0;
484         poll_wait(file, &pf->rwait, wait);
485         mask = POLLOUT | POLLWRNORM;
486         if (skb_peek(&pf->rq) != 0)
487                 mask |= POLLIN | POLLRDNORM;
488         if (pf->dead)
489                 mask |= POLLHUP;
490         return mask;
491 }
492
493 static int ppp_ioctl(struct inode *inode, struct file *file,
494                      unsigned int cmd, unsigned long arg)
495 {
496         struct ppp_file *pf = file->private_data;
497         struct ppp *ppp;
498         int err = -EFAULT, val, val2, i;
499         struct ppp_idle idle;
500         struct npioctl npi;
501         int unit, cflags;
502         struct slcompress *vj;
503
504         if (pf == 0)
505                 return ppp_unattached_ioctl(pf, file, cmd, arg);
506
507         if (cmd == PPPIOCDETACH) {
508                 /*
509                  * We have to be careful here... if the file descriptor
510                  * has been dup'd, we could have another process in the
511                  * middle of a poll using the same file *, so we had
512                  * better not free the interface data structures -
513                  * instead we fail the ioctl.  Even in this case, we
514                  * shut down the interface if we are the owner of it.
515                  * Actually, we should get rid of PPPIOCDETACH, userland
516                  * (i.e. pppd) could achieve the same effect by closing
517                  * this fd and reopening /dev/ppp.
518                  */
519                 err = -EINVAL;
520                 if (pf->kind == INTERFACE) {
521                         ppp = PF_TO_PPP(pf);
522                         if (file == ppp->owner)
523                                 ppp_shutdown_interface(ppp);
524                 }
525                 if (atomic_read(&file->f_count) <= 2) {
526                         ppp_release(inode, file);
527                         err = 0;
528                 } else
529                         printk(KERN_DEBUG "PPPIOCDETACH file->f_count=%d\n",
530                                atomic_read(&file->f_count));
531                 return err;
532         }
533
534         if (pf->kind == CHANNEL) {
535                 struct channel *pch = PF_TO_CHANNEL(pf);
536                 struct ppp_channel *chan;
537
538                 switch (cmd) {
539                 case PPPIOCCONNECT:
540                         if (get_user(unit, (int *) arg))
541                                 break;
542                         err = ppp_connect_channel(pch, unit);
543                         break;
544
545                 case PPPIOCDISCONN:
546                         err = ppp_disconnect_channel(pch);
547                         break;
548
549                 default:
550                         down_read(&pch->chan_sem);
551                         chan = pch->chan;
552                         err = -ENOTTY;
553                         if (chan && chan->ops->ioctl)
554                                 err = chan->ops->ioctl(chan, cmd, arg);
555                         up_read(&pch->chan_sem);
556                 }
557                 return err;
558         }
559
560         if (pf->kind != INTERFACE) {
561                 /* can't happen */
562                 printk(KERN_ERR "PPP: not interface or channel??\n");
563                 return -EINVAL;
564         }
565
566         ppp = PF_TO_PPP(pf);
567         switch (cmd) {
568         case PPPIOCSMRU:
569                 if (get_user(val, (int *) arg))
570                         break;
571                 ppp->mru = val;
572                 err = 0;
573                 break;
574
575         case PPPIOCSFLAGS:
576                 if (get_user(val, (int *) arg))
577                         break;
578                 ppp_lock(ppp);
579                 cflags = ppp->flags & ~val;
580                 ppp->flags = val & SC_FLAG_BITS;
581                 ppp_unlock(ppp);
582                 if (cflags & SC_CCP_OPEN)
583                         ppp_ccp_closed(ppp);
584                 err = 0;
585                 break;
586
587         case PPPIOCGFLAGS:
588                 val = ppp->flags | ppp->xstate | ppp->rstate;
589                 if (put_user(val, (int *) arg))
590                         break;
591                 err = 0;
592                 break;
593
594         case PPPIOCSCOMPRESS:
595                 err = ppp_set_compress(ppp, arg);
596                 break;
597
598         case PPPIOCGUNIT:
599                 if (put_user(ppp->file.index, (int *) arg))
600                         break;
601                 err = 0;
602                 break;
603
604         case PPPIOCSDEBUG:
605                 if (get_user(val, (int *) arg))
606                         break;
607                 ppp->debug = val;
608                 err = 0;
609                 break;
610
611         case PPPIOCGDEBUG:
612                 if (put_user(ppp->debug, (int *) arg))
613                         break;
614                 err = 0;
615                 break;
616
617         case PPPIOCGIDLE:
618                 idle.xmit_idle = (jiffies - ppp->last_xmit) / HZ;
619                 idle.recv_idle = (jiffies - ppp->last_recv) / HZ;
620                 if (copy_to_user((void __user *) arg, &idle, sizeof(idle)))
621                         break;
622                 err = 0;
623                 break;
624
625         case PPPIOCSMAXCID:
626                 if (get_user(val, (int *) arg))
627                         break;
628                 val2 = 15;
629                 if ((val >> 16) != 0) {
630                         val2 = val >> 16;
631                         val &= 0xffff;
632                 }
633                 vj = slhc_init(val2+1, val+1);
634                 if (vj == 0) {
635                         printk(KERN_ERR "PPP: no memory (VJ compressor)\n");
636                         err = -ENOMEM;
637                         break;
638                 }
639                 ppp_lock(ppp);
640                 if (ppp->vj != 0)
641                         slhc_free(ppp->vj);
642                 ppp->vj = vj;
643                 ppp_unlock(ppp);
644                 err = 0;
645                 break;
646
647         case PPPIOCGNPMODE:
648         case PPPIOCSNPMODE:
649                 if (copy_from_user(&npi, (void __user *) arg, sizeof(npi)))
650                         break;
651                 err = proto_to_npindex(npi.protocol);
652                 if (err < 0)
653                         break;
654                 i = err;
655                 if (cmd == PPPIOCGNPMODE) {
656                         err = -EFAULT;
657                         npi.mode = ppp->npmode[i];
658                         if (copy_to_user((void __user *) arg, &npi, sizeof(npi)))
659                                 break;
660                 } else {
661                         ppp->npmode[i] = npi.mode;
662                         /* we may be able to transmit more packets now (??) */
663                         netif_wake_queue(ppp->dev);
664                 }
665                 err = 0;
666                 break;
667
668 #ifdef CONFIG_PPP_FILTER
669         case PPPIOCSPASS:
670         case PPPIOCSACTIVE:
671         {
672                 struct sock_fprog uprog, *filtp;
673                 struct sock_filter *code = NULL;
674                 int len;
675
676                 if (copy_from_user(&uprog, (void __user *) arg, sizeof(uprog)))
677                         break;
678                 err = -EINVAL;
679                 if (uprog.len > BPF_MAXINSNS)
680                         break;
681                 err = -ENOMEM;
682                 if (uprog.len > 0) {
683                         len = uprog.len * sizeof(struct sock_filter);
684                         code = kmalloc(len, GFP_KERNEL);
685                         if (code == NULL)
686                                 break;
687                         err = -EFAULT;
688                         if (copy_from_user(code, (void __user *) uprog.filter, len)) {
689                                 kfree(code);
690                                 break;
691                         }
692                         err = sk_chk_filter(code, uprog.len);
693                         if (err) {
694                                 kfree(code);
695                                 break;
696                         }
697                 }
698                 filtp = (cmd == PPPIOCSPASS)? &ppp->pass_filter: &ppp->active_filter;
699                 ppp_lock(ppp);
700                 if (filtp->filter)
701                         kfree(filtp->filter);
702                 filtp->filter = code;
703                 filtp->len = uprog.len;
704                 ppp_unlock(ppp);
705                 err = 0;
706                 break;
707         }
708 #endif /* CONFIG_PPP_FILTER */
709
710 #ifdef CONFIG_PPP_MULTILINK
711         case PPPIOCSMRRU:
712                 if (get_user(val, (int *) arg))
713                         break;
714                 ppp_recv_lock(ppp);
715                 ppp->mrru = val;
716                 ppp_recv_unlock(ppp);
717                 err = 0;
718                 break;
719 #endif /* CONFIG_PPP_MULTILINK */
720
721         default:
722                 err = -ENOTTY;
723         }
724
725         return err;
726 }
727
728 static int ppp_unattached_ioctl(struct ppp_file *pf, struct file *file,
729                                 unsigned int cmd, unsigned long arg)
730 {
731         int unit, err = -EFAULT;
732         struct ppp *ppp;
733         struct channel *chan;
734
735         switch (cmd) {
736         case PPPIOCNEWUNIT:
737                 /* Create a new ppp unit */
738                 if (get_user(unit, (int *) arg))
739                         break;
740                 ppp = ppp_create_interface(unit, &err);
741                 if (ppp == 0)
742                         break;
743                 file->private_data = &ppp->file;
744                 ppp->owner = file;
745                 err = -EFAULT;
746                 if (put_user(ppp->file.index, (int *) arg))
747                         break;
748                 err = 0;
749                 break;
750
751         case PPPIOCATTACH:
752                 /* Attach to an existing ppp unit */
753                 if (get_user(unit, (int *) arg))
754                         break;
755                 down(&all_ppp_sem);
756                 err = -ENXIO;
757                 ppp = ppp_find_unit(unit);
758                 if (ppp != 0) {
759                         atomic_inc(&ppp->file.refcnt);
760                         file->private_data = &ppp->file;
761                         err = 0;
762                 }
763                 up(&all_ppp_sem);
764                 break;
765
766         case PPPIOCATTCHAN:
767                 if (get_user(unit, (int *) arg))
768                         break;
769                 spin_lock_bh(&all_channels_lock);
770                 err = -ENXIO;
771                 chan = ppp_find_channel(unit);
772                 if (chan != 0) {
773                         atomic_inc(&chan->file.refcnt);
774                         file->private_data = &chan->file;
775                         err = 0;
776                 }
777                 spin_unlock_bh(&all_channels_lock);
778                 break;
779
780         default:
781                 err = -ENOTTY;
782         }
783         return err;
784 }
785
786 static struct file_operations ppp_device_fops = {
787         .owner          = THIS_MODULE,
788         .read           = ppp_read,
789         .write          = ppp_write,
790         .poll           = ppp_poll,
791         .ioctl          = ppp_ioctl,
792         .open           = ppp_open,
793         .release        = ppp_release
794 };
795
796 #define PPP_MAJOR       108
797
798 /* Called at boot time if ppp is compiled into the kernel,
799    or at module load time (from init_module) if compiled as a module. */
800 static int __init ppp_init(void)
801 {
802         int err;
803
804         printk(KERN_INFO "PPP generic driver version " PPP_VERSION "\n");
805         err = register_chrdev(PPP_MAJOR, "ppp", &ppp_device_fops);
806         if (!err) {
807                 err = devfs_mk_cdev(MKDEV(PPP_MAJOR, 0),
808                                 S_IFCHR|S_IRUSR|S_IWUSR, "ppp");
809                 if (err)
810                         unregister_chrdev(PPP_MAJOR, "ppp");
811         }
812
813         if (err)
814                 printk(KERN_ERR "failed to register PPP device (%d)\n", err);
815         return err;
816 }
817
818 /*
819  * Network interface unit routines.
820  */
821 static int
822 ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
823 {
824         struct ppp *ppp = (struct ppp *) dev->priv;
825         int npi, proto;
826         unsigned char *pp;
827
828         npi = ethertype_to_npindex(ntohs(skb->protocol));
829         if (npi < 0)
830                 goto outf;
831
832         /* Drop, accept or reject the packet */
833         switch (ppp->npmode[npi]) {
834         case NPMODE_PASS:
835                 break;
836         case NPMODE_QUEUE:
837                 /* it would be nice to have a way to tell the network
838                    system to queue this one up for later. */
839                 goto outf;
840         case NPMODE_DROP:
841         case NPMODE_ERROR:
842                 goto outf;
843         }
844
845         /* Put the 2-byte PPP protocol number on the front,
846            making sure there is room for the address and control fields. */
847         if (skb_headroom(skb) < PPP_HDRLEN) {
848                 struct sk_buff *ns;
849
850                 ns = alloc_skb(skb->len + dev->hard_header_len, GFP_ATOMIC);
851                 if (ns == 0)
852                         goto outf;
853                 skb_reserve(ns, dev->hard_header_len);
854                 skb_copy_bits(skb, 0, skb_put(ns, skb->len), skb->len);
855                 kfree_skb(skb);
856                 skb = ns;
857         }
858         pp = skb_push(skb, 2);
859         proto = npindex_to_proto[npi];
860         pp[0] = proto >> 8;
861         pp[1] = proto;
862
863         netif_stop_queue(dev);
864         skb_queue_tail(&ppp->file.xq, skb);
865         ppp_xmit_process(ppp);
866         return 0;
867
868  outf:
869         kfree_skb(skb);
870         ++ppp->stats.tx_dropped;
871         return 0;
872 }
873
874 static struct net_device_stats *
875 ppp_net_stats(struct net_device *dev)
876 {
877         struct ppp *ppp = (struct ppp *) dev->priv;
878
879         return &ppp->stats;
880 }
881
882 static int
883 ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
884 {
885         struct ppp *ppp = dev->priv;
886         int err = -EFAULT;
887         void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
888         struct ppp_stats stats;
889         struct ppp_comp_stats cstats;
890         char *vers;
891
892         switch (cmd) {
893         case SIOCGPPPSTATS:
894                 ppp_get_stats(ppp, &stats);
895                 if (copy_to_user(addr, &stats, sizeof(stats)))
896                         break;
897                 err = 0;
898                 break;
899
900         case SIOCGPPPCSTATS:
901                 memset(&cstats, 0, sizeof(cstats));
902                 if (ppp->xc_state != 0)
903                         ppp->xcomp->comp_stat(ppp->xc_state, &cstats.c);
904                 if (ppp->rc_state != 0)
905                         ppp->rcomp->decomp_stat(ppp->rc_state, &cstats.d);
906                 if (copy_to_user(addr, &cstats, sizeof(cstats)))
907                         break;
908                 err = 0;
909                 break;
910
911         case SIOCGPPPVER:
912                 vers = PPP_VERSION;
913                 if (copy_to_user(addr, vers, strlen(vers) + 1))
914                         break;
915                 err = 0;
916                 break;
917
918         default:
919                 err = -EINVAL;
920         }
921
922         return err;
923 }
924
925 static void ppp_setup(struct net_device *dev)
926 {
927         dev->hard_header_len = PPP_HDRLEN;
928         dev->mtu = PPP_MTU;
929         dev->addr_len = 0;
930         dev->tx_queue_len = 3;
931         dev->type = ARPHRD_PPP;
932         dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
933 }
934
935 /*
936  * Transmit-side routines.
937  */
938
939 /*
940  * Called to do any work queued up on the transmit side
941  * that can now be done.
942  */
943 static void
944 ppp_xmit_process(struct ppp *ppp)
945 {
946         struct sk_buff *skb;
947
948         ppp_xmit_lock(ppp);
949         if (ppp->dev != 0) {
950                 ppp_push(ppp);
951                 while (ppp->xmit_pending == 0
952                        && (skb = skb_dequeue(&ppp->file.xq)) != 0)
953                         ppp_send_frame(ppp, skb);
954                 /* If there's no work left to do, tell the core net
955                    code that we can accept some more. */
956                 if (ppp->xmit_pending == 0 && skb_peek(&ppp->file.xq) == 0)
957                         netif_wake_queue(ppp->dev);
958         }
959         ppp_xmit_unlock(ppp);
960 }
961
962 /*
963  * Compress and send a frame.
964  * The caller should have locked the xmit path,
965  * and xmit_pending should be 0.
966  */
967 static void
968 ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
969 {
970         int proto = PPP_PROTO(skb);
971         struct sk_buff *new_skb;
972         int len;
973         unsigned char *cp;
974
975         if (proto < 0x8000) {
976 #ifdef CONFIG_PPP_FILTER
977                 /* check if we should pass this packet */
978                 /* the filter instructions are constructed assuming
979                    a four-byte PPP header on each packet */
980                 *skb_push(skb, 2) = 1;
981                 if (ppp->pass_filter.filter
982                     && sk_run_filter(skb, ppp->pass_filter.filter,
983                                      ppp->pass_filter.len) == 0) {
984                         if (ppp->debug & 1)
985                                 printk(KERN_DEBUG "PPP: outbound frame not passed\n");
986                         kfree_skb(skb);
987                         return;
988                 }
989                 /* if this packet passes the active filter, record the time */
990                 if (!(ppp->active_filter.filter
991                       && sk_run_filter(skb, ppp->active_filter.filter,
992                                        ppp->active_filter.len) == 0))
993                         ppp->last_xmit = jiffies;
994                 skb_pull(skb, 2);
995 #else
996                 /* for data packets, record the time */
997                 ppp->last_xmit = jiffies;
998 #endif /* CONFIG_PPP_FILTER */
999         }
1000
1001         ++ppp->stats.tx_packets;
1002         ppp->stats.tx_bytes += skb->len - 2;
1003
1004         switch (proto) {
1005         case PPP_IP:
1006                 if (ppp->vj == 0 || (ppp->flags & SC_COMP_TCP) == 0)
1007                         break;
1008                 /* try to do VJ TCP header compression */
1009                 new_skb = alloc_skb(skb->len + ppp->dev->hard_header_len - 2,
1010                                     GFP_ATOMIC);
1011                 if (new_skb == 0) {
1012                         printk(KERN_ERR "PPP: no memory (VJ comp pkt)\n");
1013                         goto drop;
1014                 }
1015                 skb_reserve(new_skb, ppp->dev->hard_header_len - 2);
1016                 cp = skb->data + 2;
1017                 len = slhc_compress(ppp->vj, cp, skb->len - 2,
1018                                     new_skb->data + 2, &cp,
1019                                     !(ppp->flags & SC_NO_TCP_CCID));
1020                 if (cp == skb->data + 2) {
1021                         /* didn't compress */
1022                         kfree_skb(new_skb);
1023                 } else {
1024                         if (cp[0] & SL_TYPE_COMPRESSED_TCP) {
1025                                 proto = PPP_VJC_COMP;
1026                                 cp[0] &= ~SL_TYPE_COMPRESSED_TCP;
1027                         } else {
1028                                 proto = PPP_VJC_UNCOMP;
1029                                 cp[0] = skb->data[2];
1030                         }
1031                         kfree_skb(skb);
1032                         skb = new_skb;
1033                         cp = skb_put(skb, len + 2);
1034                         cp[0] = 0;
1035                         cp[1] = proto;
1036                 }
1037                 break;
1038
1039         case PPP_CCP:
1040                 /* peek at outbound CCP frames */
1041                 ppp_ccp_peek(ppp, skb, 0);
1042                 break;
1043         }
1044
1045         /* try to do packet compression */
1046         if ((ppp->xstate & SC_COMP_RUN) && ppp->xc_state != 0
1047             && proto != PPP_LCP && proto != PPP_CCP) {
1048                 new_skb = alloc_skb(ppp->dev->mtu + ppp->dev->hard_header_len,
1049                                     GFP_ATOMIC);
1050                 if (new_skb == 0) {
1051                         printk(KERN_ERR "PPP: no memory (comp pkt)\n");
1052                         goto drop;
1053                 }
1054                 if (ppp->dev->hard_header_len > PPP_HDRLEN)
1055                         skb_reserve(new_skb,
1056                                     ppp->dev->hard_header_len - PPP_HDRLEN);
1057
1058                 /* compressor still expects A/C bytes in hdr */
1059                 len = ppp->xcomp->compress(ppp->xc_state, skb->data - 2,
1060                                            new_skb->data, skb->len + 2,
1061                                            ppp->dev->mtu + PPP_HDRLEN);
1062                 if (len > 0 && (ppp->flags & SC_CCP_UP)) {
1063                         kfree_skb(skb);
1064                         skb = new_skb;
1065                         skb_put(skb, len);
1066                         skb_pull(skb, 2);       /* pull off A/C bytes */
1067                 } else {
1068                         /* didn't compress, or CCP not up yet */
1069                         kfree_skb(new_skb);
1070                 }
1071         }
1072
1073         /*
1074          * If we are waiting for traffic (demand dialling),
1075          * queue it up for pppd to receive.
1076          */
1077         if (ppp->flags & SC_LOOP_TRAFFIC) {
1078                 if (ppp->file.rq.qlen > PPP_MAX_RQLEN)
1079                         goto drop;
1080                 skb_queue_tail(&ppp->file.rq, skb);
1081                 wake_up_interruptible(&ppp->file.rwait);
1082                 return;
1083         }
1084
1085         ppp->xmit_pending = skb;
1086         ppp_push(ppp);
1087         return;
1088
1089  drop:
1090         kfree_skb(skb);
1091         ++ppp->stats.tx_errors;
1092 }
1093
1094 /*
1095  * Try to send the frame in xmit_pending.
1096  * The caller should have the xmit path locked.
1097  */
1098 static void
1099 ppp_push(struct ppp *ppp)
1100 {
1101         struct list_head *list;
1102         struct channel *pch;
1103         struct sk_buff *skb = ppp->xmit_pending;
1104
1105         if (skb == 0)
1106                 return;
1107
1108         list = &ppp->channels;
1109         if (list_empty(list)) {
1110                 /* nowhere to send the packet, just drop it */
1111                 ppp->xmit_pending = 0;
1112                 kfree_skb(skb);
1113                 return;
1114         }
1115
1116         if ((ppp->flags & SC_MULTILINK) == 0) {
1117                 /* not doing multilink: send it down the first channel */
1118                 list = list->next;
1119                 pch = list_entry(list, struct channel, clist);
1120
1121                 spin_lock_bh(&pch->downl);
1122                 if (pch->chan) {
1123                         if (pch->chan->ops->start_xmit(pch->chan, skb))
1124                                 ppp->xmit_pending = 0;
1125                 } else {
1126                         /* channel got unregistered */
1127                         kfree_skb(skb);
1128                         ppp->xmit_pending = 0;
1129                 }
1130                 spin_unlock_bh(&pch->downl);
1131                 return;
1132         }
1133
1134 #ifdef CONFIG_PPP_MULTILINK
1135         /* Multilink: fragment the packet over as many links
1136            as can take the packet at the moment. */
1137         if (!ppp_mp_explode(ppp, skb))
1138                 return;
1139 #endif /* CONFIG_PPP_MULTILINK */
1140
1141         ppp->xmit_pending = 0;
1142         kfree_skb(skb);
1143 }
1144
1145 #ifdef CONFIG_PPP_MULTILINK
1146 /*
1147  * Divide a packet to be transmitted into fragments and
1148  * send them out the individual links.
1149  */
1150 static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1151 {
1152         int nch, len, fragsize;
1153         int i, bits, hdrlen, mtu;
1154         int flen, fnb;
1155         unsigned char *p, *q;
1156         struct list_head *list;
1157         struct channel *pch;
1158         struct sk_buff *frag;
1159         struct ppp_channel *chan;
1160
1161         nch = 0;
1162         hdrlen = (ppp->flags & SC_MP_XSHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN;
1163         list = &ppp->channels;
1164         while ((list = list->next) != &ppp->channels) {
1165                 pch = list_entry(list, struct channel, clist);
1166                 nch += pch->avail = (skb_queue_len(&pch->file.xq) == 0);
1167                 /*
1168                  * If a channel hasn't had a fragment yet, it has to get
1169                  * one before we send any fragments on later channels.
1170                  * If it can't take a fragment now, don't give any
1171                  * to subsequent channels.
1172                  */
1173                 if (!pch->had_frag && !pch->avail) {
1174                         while ((list = list->next) != &ppp->channels) {
1175                                 pch = list_entry(list, struct channel, clist);
1176                                 pch->avail = 0;
1177                         }
1178                         break;
1179                 }
1180         }
1181         if (nch == 0)
1182                 return 0;       /* can't take now, leave it in xmit_pending */
1183
1184         /* Do protocol field compression (XXX this should be optional) */
1185         p = skb->data;
1186         len = skb->len;
1187         if (*p == 0) {
1188                 ++p;
1189                 --len;
1190         }
1191
1192         /* decide on fragment size */
1193         fragsize = len;
1194         if (nch > 1) {
1195                 int maxch = ROUNDUP(len, MIN_FRAG_SIZE);
1196                 if (nch > maxch)
1197                         nch = maxch;
1198                 fragsize = ROUNDUP(fragsize, nch);
1199         }
1200
1201         /* skip to the channel after the one we last used
1202            and start at that one */
1203         for (i = 0; i < ppp->nxchan; ++i) {
1204                 list = list->next;
1205                 if (list == &ppp->channels) {
1206                         i = 0;
1207                         break;
1208                 }
1209         }
1210
1211         /* create a fragment for each channel */
1212         bits = B;
1213         do {
1214                 list = list->next;
1215                 if (list == &ppp->channels) {
1216                         i = 0;
1217                         continue;
1218                 }
1219                 pch = list_entry(list, struct channel, clist);
1220                 ++i;
1221                 if (!pch->avail)
1222                         continue;
1223
1224                 /* check the channel's mtu and whether it is still attached. */
1225                 spin_lock_bh(&pch->downl);
1226                 if (pch->chan == 0 || (mtu = pch->chan->mtu) < hdrlen) {
1227                         /* can't use this channel */
1228                         spin_unlock_bh(&pch->downl);
1229                         pch->avail = 0;
1230                         if (--nch == 0)
1231                                 break;
1232                         continue;
1233                 }
1234
1235                 /*
1236                  * We have to create multiple fragments for this channel
1237                  * if fragsize is greater than the channel's mtu.
1238                  */
1239                 if (fragsize > len)
1240                         fragsize = len;
1241                 for (flen = fragsize; flen > 0; flen -= fnb) {
1242                         fnb = flen;
1243                         if (fnb > mtu + 2 - hdrlen)
1244                                 fnb = mtu + 2 - hdrlen;
1245                         if (fnb >= len)
1246                                 bits |= E;
1247                         frag = alloc_skb(fnb + hdrlen, GFP_ATOMIC);
1248                         if (frag == 0)
1249                                 goto noskb;
1250                         q = skb_put(frag, fnb + hdrlen);
1251                         /* make the MP header */
1252                         q[0] = PPP_MP >> 8;
1253                         q[1] = PPP_MP;
1254                         if (ppp->flags & SC_MP_XSHORTSEQ) {
1255                                 q[2] = bits + ((ppp->nxseq >> 8) & 0xf);
1256                                 q[3] = ppp->nxseq;
1257                         } else {
1258                                 q[2] = bits;
1259                                 q[3] = ppp->nxseq >> 16;
1260                                 q[4] = ppp->nxseq >> 8;
1261                                 q[5] = ppp->nxseq;
1262                         }
1263
1264                         /* copy the data in */
1265                         memcpy(q + hdrlen, p, fnb);
1266
1267                         /* try to send it down the channel */
1268                         chan = pch->chan;
1269                         if (!chan->ops->start_xmit(chan, frag))
1270                                 skb_queue_tail(&pch->file.xq, frag);
1271                         pch->had_frag = 1;
1272                         p += fnb;
1273                         len -= fnb;
1274                         ++ppp->nxseq;
1275                         bits = 0;
1276                 }
1277                 spin_unlock_bh(&pch->downl);
1278         } while (len > 0);
1279         ppp->nxchan = i;
1280
1281         return 1;
1282
1283  noskb:
1284         spin_unlock_bh(&pch->downl);
1285         if (ppp->debug & 1)
1286                 printk(KERN_ERR "PPP: no memory (fragment)\n");
1287         ++ppp->stats.tx_errors;
1288         ++ppp->nxseq;
1289         return 1;       /* abandon the frame */
1290 }
1291 #endif /* CONFIG_PPP_MULTILINK */
1292
1293 /*
1294  * Try to send data out on a channel.
1295  */
1296 static void
1297 ppp_channel_push(struct channel *pch)
1298 {
1299         struct sk_buff *skb;
1300         struct ppp *ppp;
1301
1302         spin_lock_bh(&pch->downl);
1303         if (pch->chan != 0) {
1304                 while (skb_queue_len(&pch->file.xq) > 0) {
1305                         skb = skb_dequeue(&pch->file.xq);
1306                         if (!pch->chan->ops->start_xmit(pch->chan, skb)) {
1307                                 /* put the packet back and try again later */
1308                                 skb_queue_head(&pch->file.xq, skb);
1309                                 break;
1310                         }
1311                 }
1312         } else {
1313                 /* channel got deregistered */
1314                 skb_queue_purge(&pch->file.xq);
1315         }
1316         spin_unlock_bh(&pch->downl);
1317         /* see if there is anything from the attached unit to be sent */
1318         if (skb_queue_len(&pch->file.xq) == 0) {
1319                 read_lock_bh(&pch->upl);
1320                 ppp = pch->ppp;
1321                 if (ppp != 0)
1322                         ppp_xmit_process(ppp);
1323                 read_unlock_bh(&pch->upl);
1324         }
1325 }
1326
1327 /*
1328  * Receive-side routines.
1329  */
1330
1331 /* misuse a few fields of the skb for MP reconstruction */
1332 #define sequence        priority
1333 #define BEbits          cb[0]
1334
1335 static inline void
1336 ppp_do_recv(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1337 {
1338         ppp_recv_lock(ppp);
1339         /* ppp->dev == 0 means interface is closing down */
1340         if (ppp->dev != 0)
1341                 ppp_receive_frame(ppp, skb, pch);
1342         else
1343                 kfree_skb(skb);
1344         ppp_recv_unlock(ppp);
1345 }
1346
1347 void
1348 ppp_input(struct ppp_channel *chan, struct sk_buff *skb)
1349 {
1350         struct channel *pch = chan->ppp;
1351         int proto;
1352
1353         if (pch == 0 || skb->len == 0) {
1354                 kfree_skb(skb);
1355                 return;
1356         }
1357         
1358         proto = PPP_PROTO(skb);
1359         read_lock_bh(&pch->upl);
1360         if (pch->ppp == 0 || proto >= 0xc000 || proto == PPP_CCPFRAG) {
1361                 /* put it on the channel queue */
1362                 skb_queue_tail(&pch->file.rq, skb);
1363                 /* drop old frames if queue too long */
1364                 while (pch->file.rq.qlen > PPP_MAX_RQLEN
1365                        && (skb = skb_dequeue(&pch->file.rq)) != 0)
1366                         kfree_skb(skb);
1367                 wake_up_interruptible(&pch->file.rwait);
1368         } else {
1369                 ppp_do_recv(pch->ppp, skb, pch);
1370         }
1371         read_unlock_bh(&pch->upl);
1372 }
1373
1374 /* Put a 0-length skb in the receive queue as an error indication */
1375 void
1376 ppp_input_error(struct ppp_channel *chan, int code)
1377 {
1378         struct channel *pch = chan->ppp;
1379         struct sk_buff *skb;
1380
1381         if (pch == 0)
1382                 return;
1383
1384         read_lock_bh(&pch->upl);
1385         if (pch->ppp != 0) {
1386                 skb = alloc_skb(0, GFP_ATOMIC);
1387                 if (skb != 0) {
1388                         skb->len = 0;           /* probably unnecessary */
1389                         skb->cb[0] = code;
1390                         ppp_do_recv(pch->ppp, skb, pch);
1391                 }
1392         }
1393         read_unlock_bh(&pch->upl);
1394 }
1395
1396 /*
1397  * We come in here to process a received frame.
1398  * The receive side of the ppp unit is locked.
1399  */
1400 static void
1401 ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1402 {
1403         if (skb->len >= 2) {
1404 #ifdef CONFIG_PPP_MULTILINK
1405                 /* XXX do channel-level decompression here */
1406                 if (PPP_PROTO(skb) == PPP_MP)
1407                         ppp_receive_mp_frame(ppp, skb, pch);
1408                 else
1409 #endif /* CONFIG_PPP_MULTILINK */
1410                         ppp_receive_nonmp_frame(ppp, skb);
1411                 return;
1412         }
1413
1414         if (skb->len > 0)
1415                 /* note: a 0-length skb is used as an error indication */
1416                 ++ppp->stats.rx_length_errors;
1417
1418         kfree_skb(skb);
1419         ppp_receive_error(ppp);
1420 }
1421
1422 static void
1423 ppp_receive_error(struct ppp *ppp)
1424 {
1425         ++ppp->stats.rx_errors;
1426         if (ppp->vj != 0)
1427                 slhc_toss(ppp->vj);
1428 }
1429
1430 static void
1431 ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
1432 {
1433         struct sk_buff *ns;
1434         int proto, len, npi;
1435
1436         /*
1437          * Decompress the frame, if compressed.
1438          * Note that some decompressors need to see uncompressed frames
1439          * that come in as well as compressed frames.
1440          */
1441         if (ppp->rc_state != 0 && (ppp->rstate & SC_DECOMP_RUN)
1442             && (ppp->rstate & (SC_DC_FERROR | SC_DC_ERROR)) == 0)
1443                 skb = ppp_decompress_frame(ppp, skb);
1444
1445         proto = PPP_PROTO(skb);
1446         switch (proto) {
1447         case PPP_VJC_COMP:
1448                 /* decompress VJ compressed packets */
1449                 if (ppp->vj == 0 || (ppp->flags & SC_REJ_COMP_TCP))
1450                         goto err;
1451
1452                 if (skb_tailroom(skb) < 124) {
1453                         /* copy to a new sk_buff with more tailroom */
1454                         ns = dev_alloc_skb(skb->len + 128);
1455                         if (ns == 0) {
1456                                 printk(KERN_ERR"PPP: no memory (VJ decomp)\n");
1457                                 goto err;
1458                         }
1459                         skb_reserve(ns, 2);
1460                         skb_copy_bits(skb, 0, skb_put(ns, skb->len), skb->len);
1461                         kfree_skb(skb);
1462                         skb = ns;
1463                 }
1464                 else if (!pskb_may_pull(skb, skb->len))
1465                         goto err;
1466
1467                 len = slhc_uncompress(ppp->vj, skb->data + 2, skb->len - 2);
1468                 if (len <= 0) {
1469                         printk(KERN_DEBUG "PPP: VJ decompression error\n");
1470                         goto err;
1471                 }
1472                 len += 2;
1473                 if (len > skb->len)
1474                         skb_put(skb, len - skb->len);
1475                 else if (len < skb->len)
1476                         skb_trim(skb, len);
1477                 proto = PPP_IP;
1478                 break;
1479
1480         case PPP_VJC_UNCOMP:
1481                 if (ppp->vj == 0 || (ppp->flags & SC_REJ_COMP_TCP))
1482                         goto err;
1483                 
1484                 /* Until we fix the decompressor need to make sure
1485                  * data portion is linear.
1486                  */
1487                 if (!pskb_may_pull(skb, skb->len)) 
1488                         goto err;
1489
1490                 if (slhc_remember(ppp->vj, skb->data + 2, skb->len - 2) <= 0) {
1491                         printk(KERN_ERR "PPP: VJ uncompressed error\n");
1492                         goto err;
1493                 }
1494                 proto = PPP_IP;
1495                 break;
1496
1497         case PPP_CCP:
1498                 ppp_ccp_peek(ppp, skb, 1);
1499                 break;
1500         }
1501
1502         ++ppp->stats.rx_packets;
1503         ppp->stats.rx_bytes += skb->len - 2;
1504
1505         npi = proto_to_npindex(proto);
1506         if (npi < 0) {
1507                 /* control or unknown frame - pass it to pppd */
1508                 skb_queue_tail(&ppp->file.rq, skb);
1509                 /* limit queue length by dropping old frames */
1510                 while (ppp->file.rq.qlen > PPP_MAX_RQLEN
1511                        && (skb = skb_dequeue(&ppp->file.rq)) != 0)
1512                         kfree_skb(skb);
1513                 /* wake up any process polling or blocking on read */
1514                 wake_up_interruptible(&ppp->file.rwait);
1515
1516         } else {
1517                 /* network protocol frame - give it to the kernel */
1518
1519 #ifdef CONFIG_PPP_FILTER
1520                 /* check if the packet passes the pass and active filters */
1521                 /* the filter instructions are constructed assuming
1522                    a four-byte PPP header on each packet */
1523                 *skb_push(skb, 2) = 0;
1524                 if (ppp->pass_filter.filter
1525                     && sk_run_filter(skb, ppp->pass_filter.filter,
1526                                      ppp->pass_filter.len) == 0) {
1527                         if (ppp->debug & 1)
1528                                 printk(KERN_DEBUG "PPP: inbound frame not passed\n");
1529                         kfree_skb(skb);
1530                         return;
1531                 }
1532                 if (!(ppp->active_filter.filter
1533                       && sk_run_filter(skb, ppp->active_filter.filter,
1534                                        ppp->active_filter.len) == 0))
1535                         ppp->last_recv = jiffies;
1536                 skb_pull(skb, 2);
1537 #else
1538                 ppp->last_recv = jiffies;
1539 #endif /* CONFIG_PPP_FILTER */
1540
1541                 if ((ppp->dev->flags & IFF_UP) == 0
1542                     || ppp->npmode[npi] != NPMODE_PASS) {
1543                         kfree_skb(skb);
1544                 } else {
1545                         skb_pull(skb, 2);       /* chop off protocol */
1546                         skb->dev = ppp->dev;
1547                         skb->protocol = htons(npindex_to_ethertype[npi]);
1548                         skb->mac.raw = skb->data;
1549                         netif_rx(skb);
1550                         ppp->dev->last_rx = jiffies;
1551                 }
1552         }
1553         return;
1554
1555  err:
1556         kfree_skb(skb);
1557         ppp_receive_error(ppp);
1558 }
1559
1560 static struct sk_buff *
1561 ppp_decompress_frame(struct ppp *ppp, struct sk_buff *skb)
1562 {
1563         int proto = PPP_PROTO(skb);
1564         struct sk_buff *ns;
1565         int len;
1566
1567         /* Until we fix all the decompressor's need to make sure
1568          * data portion is linear.
1569          */
1570         if (!pskb_may_pull(skb, skb->len))
1571                 goto err;
1572
1573         if (proto == PPP_COMP) {
1574                 ns = dev_alloc_skb(ppp->mru + PPP_HDRLEN);
1575                 if (ns == 0) {
1576                         printk(KERN_ERR "ppp_decompress_frame: no memory\n");
1577                         goto err;
1578                 }
1579                 /* the decompressor still expects the A/C bytes in the hdr */
1580                 len = ppp->rcomp->decompress(ppp->rc_state, skb->data - 2,
1581                                 skb->len + 2, ns->data, ppp->mru + PPP_HDRLEN);
1582                 if (len < 0) {
1583                         /* Pass the compressed frame to pppd as an
1584                            error indication. */
1585                         if (len == DECOMP_FATALERROR)
1586                                 ppp->rstate |= SC_DC_FERROR;
1587                         kfree_skb(ns);
1588                         goto err;
1589                 }
1590
1591                 kfree_skb(skb);
1592                 skb = ns;
1593                 skb_put(skb, len);
1594                 skb_pull(skb, 2);       /* pull off the A/C bytes */
1595
1596         } else {
1597                 /* Uncompressed frame - pass to decompressor so it
1598                    can update its dictionary if necessary. */
1599                 if (ppp->rcomp->incomp)
1600                         ppp->rcomp->incomp(ppp->rc_state, skb->data - 2,
1601                                            skb->len + 2);
1602         }
1603
1604         return skb;
1605
1606  err:
1607         ppp->rstate |= SC_DC_ERROR;
1608         ppp_receive_error(ppp);
1609         return skb;
1610 }
1611
1612 #ifdef CONFIG_PPP_MULTILINK
1613 /*
1614  * Receive a multilink frame.
1615  * We put it on the reconstruction queue and then pull off
1616  * as many completed frames as we can.
1617  */
1618 static void
1619 ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1620 {
1621         u32 mask, seq;
1622         struct list_head *l;
1623         int mphdrlen = (ppp->flags & SC_MP_SHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN;
1624
1625         if (!pskb_may_pull(skb, mphdrlen + 1) || ppp->mrru == 0)
1626                 goto err;               /* no good, throw it away */
1627
1628         /* Decode sequence number and begin/end bits */
1629         if (ppp->flags & SC_MP_SHORTSEQ) {
1630                 seq = ((skb->data[2] & 0x0f) << 8) | skb->data[3];
1631                 mask = 0xfff;
1632         } else {
1633                 seq = (skb->data[3] << 16) | (skb->data[4] << 8)| skb->data[5];
1634                 mask = 0xffffff;
1635         }
1636         skb->BEbits = skb->data[2];
1637         skb_pull(skb, mphdrlen);        /* pull off PPP and MP headers */
1638
1639         /*
1640          * Do protocol ID decompression on the first fragment of each packet.
1641          */
1642         if ((skb->BEbits & B) && (skb->data[0] & 1))
1643                 *skb_push(skb, 1) = 0;
1644
1645         /*
1646          * Expand sequence number to 32 bits, making it as close
1647          * as possible to ppp->minseq.
1648          */
1649         seq |= ppp->minseq & ~mask;
1650         if ((int)(ppp->minseq - seq) > (int)(mask >> 1))
1651                 seq += mask + 1;
1652         else if ((int)(seq - ppp->minseq) > (int)(mask >> 1))
1653                 seq -= mask + 1;        /* should never happen */
1654         skb->sequence = seq;
1655         pch->lastseq = seq;
1656
1657         /*
1658          * If this packet comes before the next one we were expecting,
1659          * drop it.
1660          */
1661         if (seq_before(seq, ppp->nextseq)) {
1662                 kfree_skb(skb);
1663                 ++ppp->stats.rx_dropped;
1664                 ppp_receive_error(ppp);
1665                 return;
1666         }
1667
1668         /*
1669          * Reevaluate minseq, the minimum over all channels of the
1670          * last sequence number received on each channel.  Because of
1671          * the increasing sequence number rule, we know that any fragment
1672          * before `minseq' which hasn't arrived is never going to arrive.
1673          * The list of channels can't change because we have the receive
1674          * side of the ppp unit locked.
1675          */
1676         for (l = ppp->channels.next; l != &ppp->channels; l = l->next) {
1677                 struct channel *ch = list_entry(l, struct channel, clist);
1678                 if (seq_before(ch->lastseq, seq))
1679                         seq = ch->lastseq;
1680         }
1681         if (seq_before(ppp->minseq, seq))
1682                 ppp->minseq = seq;
1683
1684         /* Put the fragment on the reconstruction queue */
1685         ppp_mp_insert(ppp, skb);
1686
1687         /* If the queue is getting long, don't wait any longer for packets
1688            before the start of the queue. */
1689         if (skb_queue_len(&ppp->mrq) >= PPP_MP_MAX_QLEN
1690             && seq_before(ppp->minseq, ppp->mrq.next->sequence))
1691                 ppp->minseq = ppp->mrq.next->sequence;
1692
1693         /* Pull completed packets off the queue and receive them. */
1694         while ((skb = ppp_mp_reconstruct(ppp)) != 0)
1695                 ppp_receive_nonmp_frame(ppp, skb);
1696
1697         return;
1698
1699  err:
1700         kfree_skb(skb);
1701         ppp_receive_error(ppp);
1702 }
1703
1704 /*
1705  * Insert a fragment on the MP reconstruction queue.
1706  * The queue is ordered by increasing sequence number.
1707  */
1708 static void
1709 ppp_mp_insert(struct ppp *ppp, struct sk_buff *skb)
1710 {
1711         struct sk_buff *p;
1712         struct sk_buff_head *list = &ppp->mrq;
1713         u32 seq = skb->sequence;
1714
1715         /* N.B. we don't need to lock the list lock because we have the
1716            ppp unit receive-side lock. */
1717         for (p = list->next; p != (struct sk_buff *)list; p = p->next)
1718                 if (seq_before(seq, p->sequence))
1719                         break;
1720         __skb_insert(skb, p->prev, p, list);
1721 }
1722
1723 /*
1724  * Reconstruct a packet from the MP fragment queue.
1725  * We go through increasing sequence numbers until we find a
1726  * complete packet, or we get to the sequence number for a fragment
1727  * which hasn't arrived but might still do so.
1728  */
1729 struct sk_buff *
1730 ppp_mp_reconstruct(struct ppp *ppp)
1731 {
1732         u32 seq = ppp->nextseq;
1733         u32 minseq = ppp->minseq;
1734         struct sk_buff_head *list = &ppp->mrq;
1735         struct sk_buff *p, *next;
1736         struct sk_buff *head, *tail;
1737         struct sk_buff *skb = NULL;
1738         int lost = 0, len = 0;
1739
1740         if (ppp->mrru == 0)     /* do nothing until mrru is set */
1741                 return NULL;
1742         head = list->next;
1743         tail = NULL;
1744         for (p = head; p != (struct sk_buff *) list; p = next) {
1745                 next = p->next;
1746                 if (seq_before(p->sequence, seq)) {
1747                         /* this can't happen, anyway ignore the skb */
1748                         printk(KERN_ERR "ppp_mp_reconstruct bad seq %u < %u\n",
1749                                p->sequence, seq);
1750                         head = next;
1751                         continue;
1752                 }
1753                 if (p->sequence != seq) {
1754                         /* Fragment `seq' is missing.  If it is after
1755                            minseq, it might arrive later, so stop here. */
1756                         if (seq_after(seq, minseq))
1757                                 break;
1758                         /* Fragment `seq' is lost, keep going. */
1759                         lost = 1;
1760                         seq = seq_before(minseq, p->sequence)?
1761                                 minseq + 1: p->sequence;
1762                         next = p;
1763                         continue;
1764                 }
1765
1766                 /*
1767                  * At this point we know that all the fragments from
1768                  * ppp->nextseq to seq are either present or lost.
1769                  * Also, there are no complete packets in the queue
1770                  * that have no missing fragments and end before this
1771                  * fragment.
1772                  */
1773
1774                 /* B bit set indicates this fragment starts a packet */
1775                 if (p->BEbits & B) {
1776                         head = p;
1777                         lost = 0;
1778                         len = 0;
1779                 }
1780
1781                 len += p->len;
1782
1783                 /* Got a complete packet yet? */
1784                 if (lost == 0 && (p->BEbits & E) && (head->BEbits & B)) {
1785                         if (len > ppp->mrru + 2) {
1786                                 ++ppp->stats.rx_length_errors;
1787                                 printk(KERN_DEBUG "PPP: reconstructed packet"
1788                                        " is too long (%d)\n", len);
1789                         } else if (p == head) {
1790                                 /* fragment is complete packet - reuse skb */
1791                                 tail = p;
1792                                 skb = skb_get(p);
1793                                 break;
1794                         } else if ((skb = dev_alloc_skb(len)) == NULL) {
1795                                 ++ppp->stats.rx_missed_errors;
1796                                 printk(KERN_DEBUG "PPP: no memory for "
1797                                        "reconstructed packet");
1798                         } else {
1799                                 tail = p;
1800                                 break;
1801                         }
1802                         ppp->nextseq = seq + 1;
1803                 }
1804
1805                 /*
1806                  * If this is the ending fragment of a packet,
1807                  * and we haven't found a complete valid packet yet,
1808                  * we can discard up to and including this fragment.
1809                  */
1810                 if (p->BEbits & E)
1811                         head = next;
1812
1813                 ++seq;
1814         }
1815
1816         /* If we have a complete packet, copy it all into one skb. */
1817         if (tail != NULL) {
1818                 /* If we have discarded any fragments,
1819                    signal a receive error. */
1820                 if (head->sequence != ppp->nextseq) {
1821                         if (ppp->debug & 1)
1822                                 printk(KERN_DEBUG "  missed pkts %u..%u\n",
1823                                        ppp->nextseq, head->sequence-1);
1824                         ++ppp->stats.rx_dropped;
1825                         ppp_receive_error(ppp);
1826                 }
1827
1828                 if (head != tail)
1829                         /* copy to a single skb */
1830                         for (p = head; p != tail->next; p = p->next)
1831                                 skb_copy_bits(p, 0, skb_put(skb, p->len), p->len);
1832                 ppp->nextseq = tail->sequence + 1;
1833                 head = tail->next;
1834         }
1835
1836         /* Discard all the skbuffs that we have copied the data out of
1837            or that we can't use. */
1838         while ((p = list->next) != head) {
1839                 __skb_unlink(p, list);
1840                 kfree_skb(p);
1841         }
1842
1843         return skb;
1844 }
1845 #endif /* CONFIG_PPP_MULTILINK */
1846
1847 /*
1848  * Channel interface.
1849  */
1850
1851 /*
1852  * Create a new, unattached ppp channel.
1853  */
1854 int
1855 ppp_register_channel(struct ppp_channel *chan)
1856 {
1857         struct channel *pch;
1858
1859         pch = kmalloc(sizeof(struct channel), GFP_KERNEL);
1860         if (pch == 0)
1861                 return -ENOMEM;
1862         memset(pch, 0, sizeof(struct channel));
1863         pch->ppp = NULL;
1864         pch->chan = chan;
1865         chan->ppp = pch;
1866         init_ppp_file(&pch->file, CHANNEL);
1867         pch->file.hdrlen = chan->hdrlen;
1868 #ifdef CONFIG_PPP_MULTILINK
1869         pch->lastseq = -1;
1870 #endif /* CONFIG_PPP_MULTILINK */
1871         init_rwsem(&pch->chan_sem);
1872         spin_lock_init(&pch->downl);
1873         pch->upl = RW_LOCK_UNLOCKED;
1874         spin_lock_bh(&all_channels_lock);
1875         pch->file.index = ++last_channel_index;
1876         list_add(&pch->list, &new_channels);
1877         atomic_inc(&channel_count);
1878         spin_unlock_bh(&all_channels_lock);
1879         return 0;
1880 }
1881
1882 /*
1883  * Return the index of a channel.
1884  */
1885 int ppp_channel_index(struct ppp_channel *chan)
1886 {
1887         struct channel *pch = chan->ppp;
1888
1889         if (pch != 0)
1890                 return pch->file.index;
1891         return -1;
1892 }
1893
1894 /*
1895  * Return the PPP unit number to which a channel is connected.
1896  */
1897 int ppp_unit_number(struct ppp_channel *chan)
1898 {
1899         struct channel *pch = chan->ppp;
1900         int unit = -1;
1901
1902         if (pch != 0) {
1903                 read_lock_bh(&pch->upl);
1904                 if (pch->ppp != 0)
1905                         unit = pch->ppp->file.index;
1906                 read_unlock_bh(&pch->upl);
1907         }
1908         return unit;
1909 }
1910
1911 /*
1912  * Disconnect a channel from the generic layer.
1913  * This must be called in process context.
1914  */
1915 void
1916 ppp_unregister_channel(struct ppp_channel *chan)
1917 {
1918         struct channel *pch = chan->ppp;
1919
1920         if (pch == 0)
1921                 return;         /* should never happen */
1922         chan->ppp = 0;
1923
1924         /*
1925          * This ensures that we have returned from any calls into the
1926          * the channel's start_xmit or ioctl routine before we proceed.
1927          */
1928         down_write(&pch->chan_sem);
1929         spin_lock_bh(&pch->downl);
1930         pch->chan = 0;
1931         spin_unlock_bh(&pch->downl);
1932         up_write(&pch->chan_sem);
1933         ppp_disconnect_channel(pch);
1934         spin_lock_bh(&all_channels_lock);
1935         list_del(&pch->list);
1936         spin_unlock_bh(&all_channels_lock);
1937         pch->file.dead = 1;
1938         wake_up_interruptible(&pch->file.rwait);
1939         if (atomic_dec_and_test(&pch->file.refcnt))
1940                 ppp_destroy_channel(pch);
1941 }
1942
1943 /*
1944  * Callback from a channel when it can accept more to transmit.
1945  * This should be called at BH/softirq level, not interrupt level.
1946  */
1947 void
1948 ppp_output_wakeup(struct ppp_channel *chan)
1949 {
1950         struct channel *pch = chan->ppp;
1951
1952         if (pch == 0)
1953                 return;
1954         ppp_channel_push(pch);
1955 }
1956
1957 /*
1958  * Compression control.
1959  */
1960
1961 /* Process the PPPIOCSCOMPRESS ioctl. */
1962 static int
1963 ppp_set_compress(struct ppp *ppp, unsigned long arg)
1964 {
1965         int err;
1966         struct compressor *cp, *ocomp;
1967         struct ppp_option_data data;
1968         void *state, *ostate;
1969         unsigned char ccp_option[CCP_MAX_OPTION_LENGTH];
1970
1971         err = -EFAULT;
1972         if (copy_from_user(&data, (void __user *) arg, sizeof(data))
1973             || (data.length <= CCP_MAX_OPTION_LENGTH
1974                 && copy_from_user(ccp_option, (void __user *) data.ptr, data.length)))
1975                 goto out;
1976         err = -EINVAL;
1977         if (data.length > CCP_MAX_OPTION_LENGTH
1978             || ccp_option[1] < 2 || ccp_option[1] > data.length)
1979                 goto out;
1980
1981         cp = find_compressor(ccp_option[0]);
1982 #ifdef CONFIG_KMOD
1983         if (cp == 0) {
1984                 request_module("ppp-compress-%d", ccp_option[0]);
1985                 cp = find_compressor(ccp_option[0]);
1986         }
1987 #endif /* CONFIG_KMOD */
1988         if (cp == 0)
1989                 goto out;
1990
1991         err = -ENOBUFS;
1992         if (data.transmit) {
1993                 state = cp->comp_alloc(ccp_option, data.length);
1994                 if (state != 0) {
1995                         ppp_xmit_lock(ppp);
1996                         ppp->xstate &= ~SC_COMP_RUN;
1997                         ocomp = ppp->xcomp;
1998                         ostate = ppp->xc_state;
1999                         ppp->xcomp = cp;
2000                         ppp->xc_state = state;
2001                         ppp_xmit_unlock(ppp);
2002                         if (ostate != 0) {
2003                                 ocomp->comp_free(ostate);
2004                                 module_put(ocomp->owner);
2005                         }
2006                         err = 0;
2007                 } else
2008                         module_put(cp->owner);
2009
2010         } else {
2011                 state = cp->decomp_alloc(ccp_option, data.length);
2012                 if (state != 0) {
2013                         ppp_recv_lock(ppp);
2014                         ppp->rstate &= ~SC_DECOMP_RUN;
2015                         ocomp = ppp->rcomp;
2016                         ostate = ppp->rc_state;
2017                         ppp->rcomp = cp;
2018                         ppp->rc_state = state;
2019                         ppp_recv_unlock(ppp);
2020                         if (ostate != 0) {
2021                                 ocomp->decomp_free(ostate);
2022                                 module_put(ocomp->owner);
2023                         }
2024                         err = 0;
2025                 } else
2026                         module_put(cp->owner);
2027         }
2028
2029  out:
2030         return err;
2031 }
2032
2033 /*
2034  * Look at a CCP packet and update our state accordingly.
2035  * We assume the caller has the xmit or recv path locked.
2036  */
2037 static void
2038 ppp_ccp_peek(struct ppp *ppp, struct sk_buff *skb, int inbound)
2039 {
2040         unsigned char *dp;
2041         int len;
2042
2043         if (!pskb_may_pull(skb, CCP_HDRLEN + 2))
2044                 return; /* no header */
2045         dp = skb->data + 2;
2046
2047         switch (CCP_CODE(dp)) {
2048         case CCP_CONFREQ:
2049
2050                 /* A ConfReq starts negotiation of compression 
2051                  * in one direction of transmission,
2052                  * and hence brings it down...but which way?
2053                  *
2054                  * Remember:
2055                  * A ConfReq indicates what the sender would like to receive
2056                  */
2057                 if(inbound)
2058                         /* He is proposing what I should send */
2059                         ppp->xstate &= ~SC_COMP_RUN;
2060                 else    
2061                         /* I am proposing to what he should send */
2062                         ppp->rstate &= ~SC_DECOMP_RUN;
2063                 
2064                 break;
2065                 
2066         case CCP_TERMREQ:
2067         case CCP_TERMACK:
2068                 /*
2069                  * CCP is going down, both directions of transmission 
2070                  */
2071                 ppp->rstate &= ~SC_DECOMP_RUN;
2072                 ppp->xstate &= ~SC_COMP_RUN;
2073                 break;
2074
2075         case CCP_CONFACK:
2076                 if ((ppp->flags & (SC_CCP_OPEN | SC_CCP_UP)) != SC_CCP_OPEN)
2077                         break;
2078                 len = CCP_LENGTH(dp);
2079                 if (!pskb_may_pull(skb, len + 2))
2080                         return;         /* too short */
2081                 dp += CCP_HDRLEN;
2082                 len -= CCP_HDRLEN;
2083                 if (len < CCP_OPT_MINLEN || len < CCP_OPT_LENGTH(dp))
2084                         break;
2085                 if (inbound) {
2086                         /* we will start receiving compressed packets */
2087                         if (ppp->rc_state == 0)
2088                                 break;
2089                         if (ppp->rcomp->decomp_init(ppp->rc_state, dp, len,
2090                                         ppp->file.index, 0, ppp->mru, ppp->debug)) {
2091                                 ppp->rstate |= SC_DECOMP_RUN;
2092                                 ppp->rstate &= ~(SC_DC_ERROR | SC_DC_FERROR);
2093                         }
2094                 } else {
2095                         /* we will soon start sending compressed packets */
2096                         if (ppp->xc_state == 0)
2097                                 break;
2098                         if (ppp->xcomp->comp_init(ppp->xc_state, dp, len,
2099                                         ppp->file.index, 0, ppp->debug))
2100                                 ppp->xstate |= SC_COMP_RUN;
2101                 }
2102                 break;
2103
2104         case CCP_RESETACK:
2105                 /* reset the [de]compressor */
2106                 if ((ppp->flags & SC_CCP_UP) == 0)
2107                         break;
2108                 if (inbound) {
2109                         if (ppp->rc_state && (ppp->rstate & SC_DECOMP_RUN)) {
2110                                 ppp->rcomp->decomp_reset(ppp->rc_state);
2111                                 ppp->rstate &= ~SC_DC_ERROR;
2112                         }
2113                 } else {
2114                         if (ppp->xc_state && (ppp->xstate & SC_COMP_RUN))
2115                                 ppp->xcomp->comp_reset(ppp->xc_state);
2116                 }
2117                 break;
2118         }
2119 }
2120
2121 /* Free up compression resources. */
2122 static void
2123 ppp_ccp_closed(struct ppp *ppp)
2124 {
2125         void *xstate, *rstate;
2126         struct compressor *xcomp, *rcomp;
2127
2128         ppp_lock(ppp);
2129         ppp->flags &= ~(SC_CCP_OPEN | SC_CCP_UP);
2130         ppp->xstate = 0;
2131         xcomp = ppp->xcomp;
2132         xstate = ppp->xc_state;
2133         ppp->xc_state = 0;
2134         ppp->rstate = 0;
2135         rcomp = ppp->rcomp;
2136         rstate = ppp->rc_state;
2137         ppp->rc_state = 0;
2138         ppp_unlock(ppp);
2139
2140         if (xstate) {
2141                 xcomp->comp_free(xstate);
2142                 module_put(xcomp->owner);
2143         }
2144         if (rstate) {
2145                 rcomp->decomp_free(rstate);
2146                 module_put(rcomp->owner);
2147         }
2148 }
2149
2150 /* List of compressors. */
2151 static LIST_HEAD(compressor_list);
2152 static spinlock_t compressor_list_lock = SPIN_LOCK_UNLOCKED;
2153
2154 struct compressor_entry {
2155         struct list_head list;
2156         struct compressor *comp;
2157 };
2158
2159 static struct compressor_entry *
2160 find_comp_entry(int proto)
2161 {
2162         struct compressor_entry *ce;
2163         struct list_head *list = &compressor_list;
2164
2165         while ((list = list->next) != &compressor_list) {
2166                 ce = list_entry(list, struct compressor_entry, list);
2167                 if (ce->comp->compress_proto == proto)
2168                         return ce;
2169         }
2170         return 0;
2171 }
2172
2173 /* Register a compressor */
2174 int
2175 ppp_register_compressor(struct compressor *cp)
2176 {
2177         struct compressor_entry *ce;
2178         int ret;
2179         spin_lock(&compressor_list_lock);
2180         ret = -EEXIST;
2181         if (find_comp_entry(cp->compress_proto) != 0)
2182                 goto out;
2183         ret = -ENOMEM;
2184         ce = kmalloc(sizeof(struct compressor_entry), GFP_ATOMIC);
2185         if (ce == 0)
2186                 goto out;
2187         ret = 0;
2188         ce->comp = cp;
2189         list_add(&ce->list, &compressor_list);
2190  out:
2191         spin_unlock(&compressor_list_lock);
2192         return ret;
2193 }
2194
2195 /* Unregister a compressor */
2196 void
2197 ppp_unregister_compressor(struct compressor *cp)
2198 {
2199         struct compressor_entry *ce;
2200
2201         spin_lock(&compressor_list_lock);
2202         ce = find_comp_entry(cp->compress_proto);
2203         if (ce != 0 && ce->comp == cp) {
2204                 list_del(&ce->list);
2205                 kfree(ce);
2206         }
2207         spin_unlock(&compressor_list_lock);
2208 }
2209
2210 /* Find a compressor. */
2211 static struct compressor *
2212 find_compressor(int type)
2213 {
2214         struct compressor_entry *ce;
2215         struct compressor *cp = 0;
2216
2217         spin_lock(&compressor_list_lock);
2218         ce = find_comp_entry(type);
2219         if (ce != 0) {
2220                 cp = ce->comp;
2221                 if (!try_module_get(cp->owner))
2222                         cp = NULL;
2223         }
2224         spin_unlock(&compressor_list_lock);
2225         return cp;
2226 }
2227
2228 /*
2229  * Miscelleneous stuff.
2230  */
2231
2232 static void
2233 ppp_get_stats(struct ppp *ppp, struct ppp_stats *st)
2234 {
2235         struct slcompress *vj = ppp->vj;
2236
2237         memset(st, 0, sizeof(*st));
2238         st->p.ppp_ipackets = ppp->stats.rx_packets;
2239         st->p.ppp_ierrors = ppp->stats.rx_errors;
2240         st->p.ppp_ibytes = ppp->stats.rx_bytes;
2241         st->p.ppp_opackets = ppp->stats.tx_packets;
2242         st->p.ppp_oerrors = ppp->stats.tx_errors;
2243         st->p.ppp_obytes = ppp->stats.tx_bytes;
2244         if (vj == 0)
2245                 return;
2246         st->vj.vjs_packets = vj->sls_o_compressed + vj->sls_o_uncompressed;
2247         st->vj.vjs_compressed = vj->sls_o_compressed;
2248         st->vj.vjs_searches = vj->sls_o_searches;
2249         st->vj.vjs_misses = vj->sls_o_misses;
2250         st->vj.vjs_errorin = vj->sls_i_error;
2251         st->vj.vjs_tossed = vj->sls_i_tossed;
2252         st->vj.vjs_uncompressedin = vj->sls_i_uncompressed;
2253         st->vj.vjs_compressedin = vj->sls_i_compressed;
2254 }
2255
2256 /*
2257  * Stuff for handling the lists of ppp units and channels
2258  * and for initialization.
2259  */
2260
2261 /*
2262  * Create a new ppp interface unit.  Fails if it can't allocate memory
2263  * or if there is already a unit with the requested number.
2264  * unit == -1 means allocate a new number.
2265  */
2266 static struct ppp *
2267 ppp_create_interface(int unit, int *retp)
2268 {
2269         struct ppp *ppp;
2270         struct net_device *dev = NULL;
2271         int ret = -ENOMEM;
2272         int i;
2273
2274         ppp = kmalloc(sizeof(struct ppp), GFP_KERNEL);
2275         if (!ppp)
2276                 goto out;
2277         dev = alloc_netdev(0, "", ppp_setup);
2278         if (!dev)
2279                 goto out1;
2280         memset(ppp, 0, sizeof(struct ppp));
2281
2282         ppp->mru = PPP_MRU;
2283         init_ppp_file(&ppp->file, INTERFACE);
2284         ppp->file.hdrlen = PPP_HDRLEN - 2;      /* don't count proto bytes */
2285         for (i = 0; i < NUM_NP; ++i)
2286                 ppp->npmode[i] = NPMODE_PASS;
2287         INIT_LIST_HEAD(&ppp->channels);
2288         spin_lock_init(&ppp->rlock);
2289         spin_lock_init(&ppp->wlock);
2290 #ifdef CONFIG_PPP_MULTILINK
2291         ppp->minseq = -1;
2292         skb_queue_head_init(&ppp->mrq);
2293 #endif /* CONFIG_PPP_MULTILINK */
2294         ppp->dev = dev;
2295         dev->priv = ppp;
2296
2297         dev->hard_start_xmit = ppp_start_xmit;
2298         dev->get_stats = ppp_net_stats;
2299         dev->do_ioctl = ppp_net_ioctl;
2300
2301         ret = -EEXIST;
2302         down(&all_ppp_sem);
2303         if (unit < 0)
2304                 unit = cardmap_find_first_free(all_ppp_units);
2305         else if (cardmap_get(all_ppp_units, unit) != NULL)
2306                 goto out2;      /* unit already exists */
2307
2308         /* Initialize the new ppp unit */
2309         ppp->file.index = unit;
2310         sprintf(dev->name, "ppp%d", unit);
2311
2312         ret = register_netdev(dev);
2313         if (ret != 0) {
2314                 printk(KERN_ERR "PPP: couldn't register device %s (%d)\n",
2315                        dev->name, ret);
2316                 goto out2;
2317         }
2318
2319         atomic_inc(&ppp_unit_count);
2320         cardmap_set(&all_ppp_units, unit, ppp);
2321         up(&all_ppp_sem);
2322         *retp = 0;
2323         return ppp;
2324
2325 out2:
2326         up(&all_ppp_sem);
2327         free_netdev(dev);
2328 out1:
2329         kfree(ppp);
2330 out:
2331         *retp = ret;
2332         return NULL;
2333 }
2334
2335 /*
2336  * Initialize a ppp_file structure.
2337  */
2338 static void
2339 init_ppp_file(struct ppp_file *pf, int kind)
2340 {
2341         pf->kind = kind;
2342         skb_queue_head_init(&pf->xq);
2343         skb_queue_head_init(&pf->rq);
2344         atomic_set(&pf->refcnt, 1);
2345         init_waitqueue_head(&pf->rwait);
2346 }
2347
2348 /*
2349  * Take down a ppp interface unit - called when the owning file
2350  * (the one that created the unit) is closed or detached.
2351  */
2352 static void ppp_shutdown_interface(struct ppp *ppp)
2353 {
2354         struct net_device *dev;
2355
2356         down(&all_ppp_sem);
2357         ppp_lock(ppp);
2358         dev = ppp->dev;
2359         ppp->dev = 0;
2360         ppp_unlock(ppp);
2361         /* This will call dev_close() for us. */
2362         if (dev) {
2363                 unregister_netdev(dev);
2364                 free_netdev(dev);
2365         }
2366         cardmap_set(&all_ppp_units, ppp->file.index, NULL);
2367         ppp->file.dead = 1;
2368         ppp->owner = NULL;
2369         wake_up_interruptible(&ppp->file.rwait);
2370         up(&all_ppp_sem);
2371 }
2372
2373 /*
2374  * Free the memory used by a ppp unit.  This is only called once
2375  * there are no channels connected to the unit and no file structs
2376  * that reference the unit.
2377  */
2378 static void ppp_destroy_interface(struct ppp *ppp)
2379 {
2380         atomic_dec(&ppp_unit_count);
2381
2382         if (!ppp->file.dead || ppp->n_channels) {
2383                 /* "can't happen" */
2384                 printk(KERN_ERR "ppp: destroying ppp struct %p but dead=%d "
2385                        "n_channels=%d !\n", ppp, ppp->file.dead,
2386                        ppp->n_channels);
2387                 return;
2388         }
2389
2390         ppp_ccp_closed(ppp);
2391         if (ppp->vj) {
2392                 slhc_free(ppp->vj);
2393                 ppp->vj = 0;
2394         }
2395         skb_queue_purge(&ppp->file.xq);
2396         skb_queue_purge(&ppp->file.rq);
2397 #ifdef CONFIG_PPP_MULTILINK
2398         skb_queue_purge(&ppp->mrq);
2399 #endif /* CONFIG_PPP_MULTILINK */
2400 #ifdef CONFIG_PPP_FILTER
2401         if (ppp->pass_filter.filter) {
2402                 kfree(ppp->pass_filter.filter);
2403                 ppp->pass_filter.filter = NULL;
2404         }
2405         if (ppp->active_filter.filter) {
2406                 kfree(ppp->active_filter.filter);
2407                 ppp->active_filter.filter = 0;
2408         }
2409 #endif /* CONFIG_PPP_FILTER */
2410
2411         kfree(ppp);
2412 }
2413
2414 /*
2415  * Locate an existing ppp unit.
2416  * The caller should have locked the all_ppp_sem.
2417  */
2418 static struct ppp *
2419 ppp_find_unit(int unit)
2420 {
2421         return cardmap_get(all_ppp_units, unit);
2422 }
2423
2424 /*
2425  * Locate an existing ppp channel.
2426  * The caller should have locked the all_channels_lock.
2427  * First we look in the new_channels list, then in the
2428  * all_channels list.  If found in the new_channels list,
2429  * we move it to the all_channels list.  This is for speed
2430  * when we have a lot of channels in use.
2431  */
2432 static struct channel *
2433 ppp_find_channel(int unit)
2434 {
2435         struct channel *pch;
2436         struct list_head *list;
2437
2438         list = &new_channels;
2439         while ((list = list->next) != &new_channels) {
2440                 pch = list_entry(list, struct channel, list);
2441                 if (pch->file.index == unit) {
2442                         list_del(&pch->list);
2443                         list_add(&pch->list, &all_channels);
2444                         return pch;
2445                 }
2446         }
2447         list = &all_channels;
2448         while ((list = list->next) != &all_channels) {
2449                 pch = list_entry(list, struct channel, list);
2450                 if (pch->file.index == unit)
2451                         return pch;
2452         }
2453         return 0;
2454 }
2455
2456 /*
2457  * Connect a PPP channel to a PPP interface unit.
2458  */
2459 static int
2460 ppp_connect_channel(struct channel *pch, int unit)
2461 {
2462         struct ppp *ppp;
2463         int ret = -ENXIO;
2464         int hdrlen;
2465
2466         down(&all_ppp_sem);
2467         ppp = ppp_find_unit(unit);
2468         if (ppp == 0)
2469                 goto out;
2470         write_lock_bh(&pch->upl);
2471         ret = -EINVAL;
2472         if (pch->ppp != 0)
2473                 goto outl;
2474
2475         ppp_lock(ppp);
2476         if (pch->file.hdrlen > ppp->file.hdrlen)
2477                 ppp->file.hdrlen = pch->file.hdrlen;
2478         hdrlen = pch->file.hdrlen + 2;  /* for protocol bytes */
2479         if (ppp->dev && hdrlen > ppp->dev->hard_header_len)
2480                 ppp->dev->hard_header_len = hdrlen;
2481         list_add_tail(&pch->clist, &ppp->channels);
2482         ++ppp->n_channels;
2483         pch->ppp = ppp;
2484         atomic_inc(&ppp->file.refcnt);
2485         ppp_unlock(ppp);
2486         ret = 0;
2487
2488  outl:
2489         write_unlock_bh(&pch->upl);
2490  out:
2491         up(&all_ppp_sem);
2492         return ret;
2493 }
2494
2495 /*
2496  * Disconnect a channel from its ppp unit.
2497  */
2498 static int
2499 ppp_disconnect_channel(struct channel *pch)
2500 {
2501         struct ppp *ppp;
2502         int err = -EINVAL;
2503
2504         write_lock_bh(&pch->upl);
2505         ppp = pch->ppp;
2506         pch->ppp = NULL;
2507         write_unlock_bh(&pch->upl);
2508         if (ppp != 0) {
2509                 /* remove it from the ppp unit's list */
2510                 ppp_lock(ppp);
2511                 list_del(&pch->clist);
2512                 --ppp->n_channels;
2513                 ppp_unlock(ppp);
2514                 if (atomic_dec_and_test(&ppp->file.refcnt))
2515                         ppp_destroy_interface(ppp);
2516                 err = 0;
2517         }
2518         return err;
2519 }
2520
2521 /*
2522  * Free up the resources used by a ppp channel.
2523  */
2524 static void ppp_destroy_channel(struct channel *pch)
2525 {
2526         atomic_dec(&channel_count);
2527
2528         if (!pch->file.dead) {
2529                 /* "can't happen" */
2530                 printk(KERN_ERR "ppp: destroying undead channel %p !\n",
2531                        pch);
2532                 return;
2533         }
2534         skb_queue_purge(&pch->file.xq);
2535         skb_queue_purge(&pch->file.rq);
2536         kfree(pch);
2537 }
2538
2539 static void __exit ppp_cleanup(void)
2540 {
2541         /* should never happen */
2542         if (atomic_read(&ppp_unit_count) || atomic_read(&channel_count))
2543                 printk(KERN_ERR "PPP: removing module but units remain!\n");
2544         cardmap_destroy(&all_ppp_units);
2545         if (unregister_chrdev(PPP_MAJOR, "ppp") != 0)
2546                 printk(KERN_ERR "PPP: failed to unregister PPP device\n");
2547         devfs_remove("ppp");
2548 }
2549
2550 /*
2551  * Cardmap implementation.
2552  */
2553 static void *cardmap_get(struct cardmap *map, unsigned int nr)
2554 {
2555         struct cardmap *p;
2556         int i;
2557
2558         for (p = map; p != NULL; ) {
2559                 if ((i = nr >> p->shift) >= CARDMAP_WIDTH)
2560                         return NULL;
2561                 if (p->shift == 0)
2562                         return p->ptr[i];
2563                 nr &= ~(CARDMAP_MASK << p->shift);
2564                 p = p->ptr[i];
2565         }
2566         return NULL;
2567 }
2568
2569 static void cardmap_set(struct cardmap **pmap, unsigned int nr, void *ptr)
2570 {
2571         struct cardmap *p;
2572         int i;
2573
2574         p = *pmap;
2575         if (p == NULL || (nr >> p->shift) >= CARDMAP_WIDTH) {
2576                 do {
2577                         /* need a new top level */
2578                         struct cardmap *np = kmalloc(sizeof(*np), GFP_KERNEL);
2579                         memset(np, 0, sizeof(*np));
2580                         np->ptr[0] = p;
2581                         if (p != NULL) {
2582                                 np->shift = p->shift + CARDMAP_ORDER;
2583                                 p->parent = np;
2584                         } else
2585                                 np->shift = 0;
2586                         p = np;
2587                 } while ((nr >> p->shift) >= CARDMAP_WIDTH);
2588                 *pmap = p;
2589         }
2590         while (p->shift > 0) {
2591                 i = (nr >> p->shift) & CARDMAP_MASK;
2592                 if (p->ptr[i] == NULL) {
2593                         struct cardmap *np = kmalloc(sizeof(*np), GFP_KERNEL);
2594                         memset(np, 0, sizeof(*np));
2595                         np->shift = p->shift - CARDMAP_ORDER;
2596                         np->parent = p;
2597                         p->ptr[i] = np;
2598                 }
2599                 if (ptr == NULL)
2600                         clear_bit(i, &p->inuse);
2601                 p = p->ptr[i];
2602         }
2603         i = nr & CARDMAP_MASK;
2604         p->ptr[i] = ptr;
2605         if (ptr != NULL)
2606                 set_bit(i, &p->inuse);
2607         else
2608                 clear_bit(i, &p->inuse);
2609 }
2610
2611 static unsigned int cardmap_find_first_free(struct cardmap *map)
2612 {
2613         struct cardmap *p;
2614         unsigned int nr = 0;
2615         int i;
2616
2617         if ((p = map) == NULL)
2618                 return 0;
2619         for (;;) {
2620                 i = find_first_zero_bit(&p->inuse, CARDMAP_WIDTH);
2621                 if (i >= CARDMAP_WIDTH) {
2622                         if (p->parent == NULL)
2623                                 return CARDMAP_WIDTH << p->shift;
2624                         p = p->parent;
2625                         i = (nr >> p->shift) & CARDMAP_MASK;
2626                         set_bit(i, &p->inuse);
2627                         continue;
2628                 }
2629                 nr = (nr & (~CARDMAP_MASK << p->shift)) | (i << p->shift);
2630                 if (p->shift == 0 || p->ptr[i] == NULL)
2631                         return nr;
2632                 p = p->ptr[i];
2633         }
2634 }
2635
2636 static void cardmap_destroy(struct cardmap **pmap)
2637 {
2638         struct cardmap *p, *np;
2639         int i;
2640
2641         for (p = *pmap; p != NULL; p = np) {
2642                 if (p->shift != 0) {
2643                         for (i = 0; i < CARDMAP_WIDTH; ++i)
2644                                 if (p->ptr[i] != NULL)
2645                                         break;
2646                         if (i < CARDMAP_WIDTH) {
2647                                 np = p->ptr[i];
2648                                 p->ptr[i] = NULL;
2649                                 continue;
2650                         }
2651                 }
2652                 np = p->parent;
2653                 kfree(p);
2654         }
2655         *pmap = NULL;
2656 }
2657
2658 /* Module/initialization stuff */
2659
2660 module_init(ppp_init);
2661 module_exit(ppp_cleanup);
2662
2663 EXPORT_SYMBOL(ppp_register_channel);
2664 EXPORT_SYMBOL(ppp_unregister_channel);
2665 EXPORT_SYMBOL(ppp_channel_index);
2666 EXPORT_SYMBOL(ppp_unit_number);
2667 EXPORT_SYMBOL(ppp_input);
2668 EXPORT_SYMBOL(ppp_input_error);
2669 EXPORT_SYMBOL(ppp_output_wakeup);
2670 EXPORT_SYMBOL(ppp_register_compressor);
2671 EXPORT_SYMBOL(ppp_unregister_compressor);
2672 EXPORT_SYMBOL(all_ppp_units); /* for debugging */
2673 EXPORT_SYMBOL(all_channels); /* for debugging */
2674 MODULE_LICENSE("GPL");
2675 MODULE_ALIAS_CHARDEV_MAJOR(PPP_MAJOR);
2676 MODULE_ALIAS("/dev/ppp");