3 * Michael Callahan <callahan@maths.ox.ac.uk>
4 * Al Longyear <longyear@netcom.com>
5 * Extensively rewritten by Paul Mackerras <paulus@cs.anu.edu.au>
7 * ==FILEVERSION 980704==
10 * If you modify this file at all, please set the number above to the
11 * date of the modification as YYMMDD (year month day).
12 * ppp.c is shipped with a PPP distribution as well as with the kernel;
13 * if everyone increases the FILEVERSION number above, then scripts
14 * can do the right thing when deciding whether to install a new ppp.c
15 * file. Don't change the format of that line otherwise, so the
16 * installation script can recognize it.
24 RFC1331: The Point-to-Point Protocol (PPP) for the Transmission of
25 Multi-protocol Datagrams over Point-to-Point Links
31 Flags for this module (any combination is acceptable for testing.):
33 OPTIMIZE_FLAG_TIME - Number of jiffies to force sending of leading flag
34 character. This is normally set to ((HZ * 3) / 2).
35 This is 1.5 seconds. If zero then the leading
38 CHECK_CHARACTERS - Enable the checking on all received characters for
39 8 data bits, no parity. This adds a small amount of
40 processing for each received character.
43 #define OPTIMIZE_FLAG_TIME ((HZ * 3)/2)
44 #define CHECK_CHARACTERS 1
46 #define PPP_MAX_RCV_QLEN 32 /* max # frames we queue up for pppd */
48 /* $Id: ppp.c,v 1.19 1998/07/07 04:27:37 paulus Exp $ */
50 #include <linux/version.h>
51 #include <linux/config.h>
52 #include <linux/module.h>
53 #include <linux/kernel.h>
54 #include <linux/sched.h>
55 #include <linux/types.h>
56 #include <linux/fcntl.h>
57 #include <linux/interrupt.h>
58 #include <linux/ptrace.h>
60 /* a macro to generate linux version number codes */
61 #define VERSION(major,minor,patch) (((((major)<<8)+(minor))<<8)+(patch))
63 #if LINUX_VERSION_CODE < VERSION(2,1,14)
64 #include <linux/ioport.h>
67 #if LINUX_VERSION_CODE >= VERSION(2,1,23)
68 #include <linux/poll.h>
72 #include <linux/malloc.h>
73 #include <linux/tty.h>
74 #include <linux/errno.h>
75 #include <linux/sched.h> /* to get the struct task_struct */
76 #include <linux/string.h> /* used in new tty drivers */
77 #include <linux/signal.h> /* used in new tty drivers */
78 #include <asm/system.h>
79 #include <asm/bitops.h>
81 #include <linux/if_ether.h>
82 #include <linux/netdevice.h>
83 #include <linux/skbuff.h>
84 #include <linux/inet.h>
85 #include <linux/ioctl.h>
87 #include <linux/tcp.h>
88 #include <linux/if_arp.h>
89 #include <net/slhc_vj.h>
91 #define fcstab ppp_crc16_table /* Name of the table in the kernel */
92 #include <linux/ppp_defs.h>
94 #include <linux/socket.h>
95 #include <linux/if_ppp.h>
96 #include <linux/if_pppvar.h>
97 #include <linux/ppp-comp.h>
100 #include <linux/kmod.h>
102 #ifdef CONFIG_KERNELD
103 #include <linux/kerneld.h>
106 #if LINUX_VERSION_CODE >= VERSION(2,1,4)
108 #if LINUX_VERSION_CODE >= VERSION(2,1,5)
109 #include <asm/uaccess.h>
111 #include <asm/segment.h>
114 #define GET_USER get_user
115 #define PUT_USER put_user
116 #define COPY_FROM_USER copy_from_user
117 #define COPY_TO_USER copy_to_user
119 #else /* 2.0.x and 2.1.x before 2.1.4 */
121 #define GET_USER(val, src) \
122 (verify_area(VERIFY_READ, src, sizeof(*src))? -EFAULT: \
123 ((val) = get_user(src), 0))
124 #define PUT_USER(val, dst) \
125 (verify_area(VERIFY_WRITE, dst, sizeof(*dst))? -EFAULT: \
126 (put_user(val, dst), 0))
127 #define COPY_FROM_USER(dst, src, size) \
128 (verify_area(VERIFY_READ, src, size)? -EFAULT: \
129 (memcpy_fromfs(dst, src, size), 0))
130 #define COPY_TO_USER(dst, src, size) \
131 (verify_area(VERIFY_WRITE, dst, size)? -EFAULT: \
132 (memcpy_tofs(dst, src, size), 0))
136 #if LINUX_VERSION_CODE < VERSION(2,1,37)
137 #define test_and_set_bit(nr, addr) set_bit(nr, addr)
140 #if LINUX_VERSION_CODE < VERSION(2,1,25)
141 #define net_device_stats enet_statistics
144 #if LINUX_VERSION_CODE < VERSION(2,1,57)
145 #define signal_pending(tsk) ((tsk)->pending & ~(tsk)->blocked)
148 #if LINUX_VERSION_CODE < VERSION(2,1,60)
149 typedef int rw_ret_t;
150 typedef unsigned int rw_count_t;
152 typedef ssize_t rw_ret_t;
153 typedef size_t rw_count_t;
160 #ifdef CONFIG_MODULES
161 static int ppp_register_compressor (struct compressor *cp);
162 static void ppp_unregister_compressor (struct compressor *cp);
165 static void ppp_async_init(struct ppp *ppp);
166 static void ppp_async_release(struct ppp *ppp);
167 static int ppp_tty_push(struct ppp *ppp);
168 static int ppp_async_encode(struct ppp *ppp);
169 static int ppp_async_send(struct ppp *, struct sk_buff *);
171 static int ppp_ioctl(struct ppp *, unsigned int, unsigned long);
172 static int ppp_set_compression (struct ppp *ppp, struct ppp_option_data *odp);
173 static void ppp_proto_ccp(struct ppp *ppp, __u8 *dp, int len, int rcvd);
174 static void ppp_ccp_closed(struct ppp *ppp);
175 static int ppp_receive_frame(struct ppp *, struct sk_buff *);
176 static void ppp_receive_error(struct ppp *ppp);
177 static void ppp_output_wakeup(struct ppp *ppp);
178 static void ppp_send_ctrl(struct ppp *ppp, struct sk_buff *skb);
179 static void ppp_send_frame(struct ppp *ppp, struct sk_buff *skb);
180 static struct sk_buff *ppp_vj_compress(struct ppp *ppp, struct sk_buff *skb);
182 static struct ppp *ppp_find (int pid_value);
183 static struct ppp *ppp_alloc (void);
184 static void ppp_generic_init(struct ppp *ppp);
185 static void ppp_release(struct ppp *ppp);
186 static void ppp_print_buffer (const char *, const __u8 *, int);
187 static struct compressor *find_compressor (int type);
189 #ifndef OPTIMIZE_FLAG_TIME
190 #define OPTIMIZE_FLAG_TIME 0
194 * Parameters which may be changed via insmod.
197 static int flag_time = OPTIMIZE_FLAG_TIME;
198 #if LINUX_VERSION_CODE >= VERSION(2,1,19)
199 MODULE_PARM(flag_time, "i");
202 #define CHECK_PPP_MAGIC(ppp) do { \
203 if (ppp->magic != PPP_MAGIC) { \
204 printk(ppp_magic_warn, ppp, __FILE__, __LINE__); \
207 #define CHECK_PPP(a) do { \
208 CHECK_PPP_MAGIC(ppp); \
210 printk(ppp_warning, __LINE__); \
214 #define CHECK_PPP_VOID() do { \
215 CHECK_PPP_MAGIC(ppp); \
217 printk(ppp_warning, __LINE__); \
222 #define tty2ppp(tty) ((struct ppp *) ((tty)->disc_data))
223 #define dev2ppp(dev) ((struct ppp *) ((dev)->priv))
224 #define ppp2tty(ppp) ((ppp)->tty)
225 #define ppp2dev(ppp) (&(ppp)->dev)
227 static struct ppp *ppp_list = NULL;
228 static struct ppp *ppp_last = NULL;
230 /* Define these strings only once for all macro invocations */
231 static char ppp_warning[] = KERN_WARNING "PPP: ALERT! not INUSE! %d\n";
232 static char ppp_magic_warn[] = KERN_WARNING "bad magic for ppp %p at %s:%d\n";
234 static char szVersion[] = PPP_VERSION;
236 #if LINUX_VERSION_CODE < VERSION(2,1,18)
237 static struct symbol_table ppp_syms = {
238 #include <linux/symtab_begin.h>
239 X(ppp_register_compressor),
240 X(ppp_unregister_compressor),
242 #include <linux/symtab_end.h>
245 EXPORT_SYMBOL(ppp_register_compressor);
246 EXPORT_SYMBOL(ppp_unregister_compressor);
249 /*************************************************************
250 * LINE DISCIPLINE SUPPORT
251 * The following code implements the PPP line discipline
252 * and supports using PPP on an async serial line.
253 *************************************************************/
255 #define in_xmap(ppp,c) (ppp->xmit_async_map[(c) >> 5] & (1 << ((c) & 0x1f)))
256 #define in_rmap(ppp,c) ((((unsigned int) (__u8) (c)) < 0x20) && \
257 ppp->recv_async_map & (1 << (c)))
263 static rw_ret_t ppp_tty_read(struct tty_struct *, struct file *, __u8 *,
265 static rw_ret_t ppp_tty_write(struct tty_struct *, struct file *, const __u8 *,
267 static int ppp_tty_ioctl(struct tty_struct *, struct file *, unsigned int,
269 #if LINUX_VERSION_CODE < VERSION(2,1,23)
270 static int ppp_tty_select(struct tty_struct *tty, struct inode *inode,
271 struct file *filp, int sel_type, select_table * wait);
273 static unsigned int ppp_tty_poll(struct tty_struct *tty, struct file *filp,
276 static int ppp_tty_open (struct tty_struct *);
277 static void ppp_tty_close (struct tty_struct *);
278 static int ppp_tty_room (struct tty_struct *tty);
279 static void ppp_tty_receive (struct tty_struct *tty, const __u8 * cp,
280 char *fp, int count);
281 static void ppp_tty_wakeup (struct tty_struct *tty);
283 __u16 ppp_crc16_table[256] =
285 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
286 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
287 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
288 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
289 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
290 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
291 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
292 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
293 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
294 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
295 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
296 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
297 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
298 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
299 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
300 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
301 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
302 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
303 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
304 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
305 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
306 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
307 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
308 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
309 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
310 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
311 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
312 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
313 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
314 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
315 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
316 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
318 EXPORT_SYMBOL(ppp_crc16_table);
320 #ifdef CHECK_CHARACTERS
321 static __u32 paritytab[8] =
323 0x96696996, 0x69969669, 0x69969669, 0x96696996,
324 0x69969669, 0x96696996, 0x96696996, 0x69969669
329 * This procedure is called at initialization time to register
330 * the PPP line discipline.
335 static struct tty_ldisc ppp_ldisc;
339 "PPP: version %s (demand dialling)"
342 #ifndef MODULE /* slhc module logic has its own copyright announcement */
344 "TCP compression code copyright 1989 Regents of the "
345 "University of California\n");
349 * Register the tty discipline
351 (void) memset (&ppp_ldisc, 0, sizeof (ppp_ldisc));
352 ppp_ldisc.magic = TTY_LDISC_MAGIC;
353 ppp_ldisc.name = "ppp";
354 ppp_ldisc.open = ppp_tty_open;
355 ppp_ldisc.close = ppp_tty_close;
356 ppp_ldisc.read = ppp_tty_read;
357 ppp_ldisc.write = ppp_tty_write;
358 ppp_ldisc.ioctl = ppp_tty_ioctl;
359 #if LINUX_VERSION_CODE < VERSION(2,1,23)
360 ppp_ldisc.select = ppp_tty_select;
362 ppp_ldisc.poll = ppp_tty_poll;
364 ppp_ldisc.receive_room = ppp_tty_room;
365 ppp_ldisc.receive_buf = ppp_tty_receive;
366 ppp_ldisc.write_wakeup = ppp_tty_wakeup;
368 status = tty_register_ldisc (N_PPP, &ppp_ldisc);
370 printk(KERN_INFO "PPP line discipline registered.\n");
372 printk(KERN_ERR "error registering line discipline: %d\n",
380 * Called at boot time if the PPP driver is compiled into the kernel.
383 ppp_init(struct device *dev)
385 static int first_time = 1;
390 answer = ppp_first_time();
391 #if LINUX_VERSION_CODE < VERSION(2,1,18)
393 (void) register_symtab(&ppp_syms);
403 * Initialize the async-specific parts of the ppp structure.
406 ppp_async_init(struct ppp *ppp)
410 ppp->tty_pushing = 0;
412 memset (ppp->xmit_async_map, 0, sizeof (ppp->xmit_async_map));
413 ppp->xmit_async_map[0] = 0xffffffff;
414 ppp->xmit_async_map[3] = 0x60000000;
415 ppp->recv_async_map = 0xffffffff;
418 ppp->tfcs = PPP_INITFCS;
419 ppp->optr = ppp->obuf;
420 ppp->olim = ppp->obuf;
423 ppp->rfcs = PPP_INITFCS;
426 ppp->backup_tty = NULL;
433 * Clean up the async-specific parts of the ppp structure.
436 ppp_async_release(struct ppp *ppp)
440 if ((skb = ppp->rpkt) != NULL)
443 if ((skb = ppp->tpkt) != NULL)
451 * Called when the tty discipline is switched to PPP.
455 ppp_tty_open (struct tty_struct *tty)
460 * Allocate a ppp structure to use.
462 tty->disc_data = NULL;
463 ppp = ppp_find(current->pid);
466 * If we are taking over a ppp unit which is currently
467 * connected to a loopback pty, there's not much to do.
474 printk(KERN_ERR "ppp_alloc failed\n");
479 * Initialize the control block
481 ppp_generic_init(ppp);
487 tty->disc_data = ppp;
491 * Flush any pending characters in the driver
493 if (tty->driver.flush_buffer)
494 tty->driver.flush_buffer (tty);
502 * Called when the line discipline is changed to something
503 * else, the tty is closed, or the tty detects a hangup.
507 ppp_tty_close (struct tty_struct *tty)
509 struct ppp *ppp = tty2ppp(tty);
513 tty->disc_data = NULL;
514 if (ppp->magic != PPP_MAGIC) {
515 printk(KERN_WARNING "ppp_tty_close: bogus\n");
519 printk(KERN_WARNING "ppp_tty_close: not inuse\n");
520 ppp->tty = ppp->backup_tty = 0;
523 if (tty == ppp->backup_tty)
527 if (ppp->backup_tty) {
528 ppp->tty = ppp->backup_tty;
532 if (ppp->flags & SC_DEBUG)
533 printk(KERN_INFO "ppp: channel %s closing.\n",
536 ppp_async_release(ppp);
544 * Read a PPP frame from the rcv_q list,
545 * waiting if necessary
548 ppp_tty_read(struct tty_struct *tty, struct file *file, __u8 * buf,
551 struct ppp *ppp = tty2ppp (tty);
556 * Validate the pointers
563 * Before we attempt to write the frame to the user, ensure that the
564 * user has access to the pages for the total buffer length.
566 err = verify_area(VERIFY_WRITE, buf, nr);
571 * Wait for a frame to arrive if necessary.
572 * We increment the module use count so that the module
573 * can't go away while we're sleeping.
580 if (!ppp || ppp->magic != PPP_MAGIC || !ppp->inuse
584 skb = skb_dequeue(&ppp->rcv_q);
589 * If no frame is available, return -EAGAIN or wait.
592 if (file->f_flags & O_NONBLOCK)
595 current->timeout = 0;
596 interruptible_sleep_on(&ppp->read_wait);
598 if (signal_pending(current))
606 * Ensure that the frame will fit within the caller's buffer.
607 * If not, just discard the frame.
611 if (ppp->flags & SC_DEBUG)
613 "ppp: read of %lu bytes too small for %ld "
614 "frame\n", (unsigned long) nr, (long) len);
615 ppp->stats.ppp_ierrors++;
621 * Copy the received data from the buffer to the caller's area.
623 err = COPY_TO_USER(buf, skb->data, len);
633 * Writing to a tty in ppp line discipline sends a PPP frame.
634 * Used by pppd to send control packets (LCP, etc.).
637 ppp_tty_write(struct tty_struct *tty, struct file *file, const __u8 * data,
640 struct ppp *ppp = tty2ppp (tty);
645 * Verify the pointers.
650 if (ppp->magic != PPP_MAGIC)
656 * Ensure that the caller does not wish to send too much.
658 if (count > PPP_MTU + PPP_HDRLEN) {
659 if (ppp->flags & SC_DEBUG)
661 "ppp_tty_write: truncating user packet "
662 "from %lu to mtu %d\n", (unsigned long) count,
663 PPP_MTU + PPP_HDRLEN);
664 count = PPP_MTU + PPP_HDRLEN;
668 * Allocate a buffer for the data and fetch it from the user space.
670 skb = alloc_skb(count, GFP_KERNEL);
672 printk(KERN_ERR "ppp_tty_write: no memory\n");
675 new_data = skb_put(skb, count);
678 * Retrieve the user's buffer
680 if (COPY_FROM_USER(new_data, data, count)) {
688 ppp_send_ctrl(ppp, skb);
690 return (rw_ret_t) count;
694 * Process the IOCTL call for the tty device.
695 * Only the ioctls that relate to using ppp on async serial lines
696 * are processed here; the rest are handled by ppp_ioctl.
699 ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
700 unsigned int param2, unsigned long param3)
702 struct ppp *ppp = tty2ppp (tty);
703 register int temp_i = 0;
707 * Verify the status of the PPP device.
709 if (!ppp || ppp->magic != PPP_MAGIC || !ppp->inuse)
713 * The user must have an euid of root to do these requests.
715 if (!capable(CAP_NET_ADMIN))
719 case PPPIOCGASYNCMAP:
721 * Retrieve the transmit async map
723 if (PUT_USER(ppp->xmit_async_map[0], (int *) param3))
728 case PPPIOCSASYNCMAP:
730 * Set the transmit async map
732 if (GET_USER(temp_i, (int *) param3))
734 ppp->xmit_async_map[0] = temp_i;
735 if (ppp->flags & SC_DEBUG)
737 "ppp_tty_ioctl: set xmit asyncmap %x\n",
738 ppp->xmit_async_map[0]);
742 case PPPIOCSRASYNCMAP:
744 * Set the receive async map
746 if (GET_USER(temp_i, (int *) param3))
748 ppp->recv_async_map = temp_i;
749 if (ppp->flags & SC_DEBUG)
751 "ppp_tty_ioctl: set rcv asyncmap %x\n",
752 ppp->recv_async_map);
756 case PPPIOCGXASYNCMAP:
758 * Get the map of characters to be escaped on transmission.
760 if (COPY_TO_USER((void *) param3, ppp->xmit_async_map,
761 sizeof (ppp->xmit_async_map)))
766 case PPPIOCSXASYNCMAP:
768 * Set the map of characters to be escaped on transmission.
773 if (COPY_FROM_USER(temp_tbl, (void *) param3,
777 temp_tbl[1] = 0x00000000;
778 temp_tbl[2] &= ~0x40000000;
779 temp_tbl[3] |= 0x60000000;
781 memcpy(ppp->xmit_async_map, temp_tbl,
782 sizeof (ppp->xmit_async_map));
784 if (ppp->flags & SC_DEBUG)
786 "ppp_tty_ioctl: set xasyncmap\n");
793 * Set up this PPP unit to be used next time this
794 * process sets a tty to PPP line discipline.
796 ppp->backup_tty = tty;
797 ppp->sc_xfer = current->pid;
804 * Allow users to read, but not set, the serial port parameters
806 error = n_tty_ioctl (tty, file, param2, param3);
811 * Returns how many bytes are available for a read().
820 skb = skb_peek(&ppp->rcv_q);
823 restore_flags(flags);
824 if (PUT_USER(count, (int *) param3))
832 * All other ioctl() events will come here.
834 error = ppp_ioctl(ppp, param2, param3);
843 * Process the select() or poll() statement for the PPP device.
846 #if LINUX_VERSION_CODE < VERSION(2,1,23)
848 ppp_tty_select(struct tty_struct *tty, struct inode *inode,
849 struct file *filp, int sel_type, select_table * wait)
851 struct ppp *ppp = tty2ppp(tty);
855 * Verify the status of the PPP device.
857 if (!ppp || tty != ppp->tty)
864 /* The fd is readable if the receive queue isn't empty. */
865 if (skb_peek(&ppp->rcv_q) != NULL)
869 /* Check for exceptions or read errors. */
870 /* Is this a pty link and the remote disconnected? */
871 if (tty->flags & (1 << TTY_OTHER_CLOSED))
874 /* Is this a local link and the modem disconnected? */
875 if (tty_hung_up_p (filp))
878 select_wait(&ppp->read_wait, wait);
883 /* The fd is always writable. */
889 #else /* 2.1.23 or later */
892 ppp_tty_poll(struct tty_struct *tty, struct file *filp, poll_table * wait)
894 struct ppp *ppp = tty2ppp(tty);
895 unsigned int mask = 0;
897 if (ppp && ppp->magic == PPP_MAGIC && tty == ppp->tty) {
900 poll_wait(filp, &ppp->read_wait, wait);
902 if (skb_peek(&ppp->rcv_q) != NULL)
903 mask |= POLLIN | POLLRDNORM;
904 if (tty->flags & (1 << TTY_OTHER_CLOSED)
905 || tty_hung_up_p(filp))
907 mask |= POLLOUT | POLLWRNORM;
911 #endif /* >= 2.1.23 */
914 * This function is called by the tty driver when the transmit buffer has
915 * additional space. It is used by the ppp code to continue to transmit
916 * the current buffer should the buffer have been partially sent.
919 ppp_tty_wakeup (struct tty_struct *tty)
921 struct ppp *ppp = tty2ppp (tty);
923 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
930 if (ppp_tty_push(ppp))
931 ppp_output_wakeup(ppp);
935 * Send a packet to the peer over an async tty line.
936 * Returns -1 iff the packet could not be accepted at present,
937 * 0 if the packet was accepted but we can't accept another yet, or
938 * 1 if we can accept another packet immediately.
939 * If this procedure returns 0, ppp_output_wakeup will be called
943 ppp_async_send(struct ppp *ppp, struct sk_buff *skb)
949 if (ppp->tpkt != NULL)
954 return ppp_tty_push(ppp);
958 * Push as much data as possible out to the tty.
959 * Returns 1 if we finished encoding the current frame, 0 otherwise.
962 ppp_tty_push(struct ppp *ppp)
964 int avail, sent, done = 0;
965 struct tty_struct *tty = ppp2tty(ppp);
968 if (ppp->tty_pushing)
970 if (tty == NULL || tty->disc_data != (void *) ppp)
972 while (ppp->optr < ppp->olim || ppp->tpkt != 0) {
973 ppp->tty_pushing = 1;
974 avail = ppp->olim - ppp->optr;
976 tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
977 sent = tty->driver.write(tty, 0, ppp->optr, avail);
979 goto flush; /* error, e.g. loss of CD */
980 ppp->stats.ppp_obytes += sent;
983 ppp->tty_pushing = 0;
988 done = ppp_async_encode(ppp);
989 ppp->tty_pushing = 0;
994 ppp->tty_pushing = 1;
995 ppp->stats.ppp_oerrors++;
996 if (ppp->tpkt != 0) {
997 kfree_skb(ppp->tpkt);
1001 ppp->optr = ppp->olim;
1002 ppp->tty_pushing = 0;
1007 * Procedure to encode the data for async serial transmission.
1008 * Does octet stuffing (escaping) and address/control
1009 * and protocol compression.
1010 * Assumes ppp->opkt != 0 on entry.
1011 * Returns 1 if we finished the current frame, 0 otherwise.
1014 ppp_async_encode(struct ppp *ppp)
1016 int fcs, i, count, c;
1017 unsigned char *buf, *buflim;
1018 unsigned char *data;
1027 data = ppp->tpkt->data;
1028 count = ppp->tpkt->len;
1032 * LCP packets with code values between 1 (configure-reqest)
1033 * and 7 (code-reject) must be sent as though no options
1034 * had been negotiated.
1036 islcp = PPP_PROTOCOL(data) == PPP_LCP
1037 && 1 <= data[PPP_HDRLEN] && data[PPP_HDRLEN] <= 7;
1041 * Start of a new packet - insert the leading FLAG
1042 * character if necessary.
1044 if (islcp || flag_time == 0
1045 || jiffies - ppp->last_xmit >= flag_time)
1047 /* only reset idle time for data packets */
1048 if (PPP_PROTOCOL(data) < 0x8000)
1049 ppp->last_xmit = jiffies;
1051 ++ppp->stats.ppp_opackets;
1052 ppp->stats.ppp_ooctects += count;
1055 * Do address/control compression
1057 if ((ppp->flags & SC_COMP_AC) != 0 && !islcp
1058 && PPP_ADDRESS(data) == PPP_ALLSTATIONS
1059 && PPP_CONTROL(data) == PPP_UI)
1064 * Once we put in the last byte, we need to put in the FCS
1065 * and closing flag, so make sure there is at least 7 bytes
1066 * of free space in the output buffer.
1068 buflim = buf + OBUFSIZE - 6;
1069 while (i < count && buf < buflim) {
1071 if (i == 3 && c == 0 && (ppp->flags & SC_COMP_PROT))
1072 continue; /* compress protocol field */
1073 fcs = PPP_FCS(fcs, c);
1074 if (in_xmap(ppp, c) || (islcp && c < 0x20)) {
1075 *buf++ = PPP_ESCAPE;
1083 * We have finished the packet. Add the FCS and flag.
1087 if (in_xmap(ppp, c) || (islcp && c < 0x20)) {
1088 *buf++ = PPP_ESCAPE;
1092 c = (fcs >> 8) & 0xff;
1093 if (in_xmap(ppp, c) || (islcp && c < 0x20)) {
1094 *buf++ = PPP_ESCAPE;
1101 kfree_skb(ppp->tpkt);
1107 * Remember where we are up to in this packet.
1116 * Callback function from tty driver. Return the amount of space left
1117 * in the receiver's buffer to decide if remote transmitter is to be
1121 ppp_tty_room (struct tty_struct *tty)
1123 return 65536; /* We can handle an infinite amount of data. :-) */
1127 * Callback function when data is available at the tty driver.
1130 ppp_tty_receive (struct tty_struct *tty, const __u8 * data,
1131 char *flags, int count)
1133 register struct ppp *ppp = tty2ppp (tty);
1134 struct sk_buff *skb;
1141 * This can happen if stuff comes in on the backup tty.
1143 if (ppp == 0 || tty != ppp->tty)
1146 * Verify the table pointer and ensure that the line is
1147 * still in PPP discipline.
1149 if (ppp->magic != PPP_MAGIC) {
1150 if (ppp->flags & SC_DEBUG)
1152 "PPP: tty_receive called but couldn't find "
1157 * Print the buffer if desired
1159 if (ppp->flags & SC_LOG_RAWIN)
1160 ppp_print_buffer ("receive buffer", data, count);
1162 ppp->stats.ppp_ibytes += count;
1164 while (count-- > 0) {
1166 * Collect the character and error condition for the character.
1167 * Set the toss flag for the first character error.
1177 ++ppp->estats.rx_fifo_errors;
1181 ++ppp->estats.rx_frame_errors;
1189 * Set the flags for d7 being 0/1 and parity being
1190 * even/odd so that the normal processing would have
1191 * all flags set at the end of the session. A
1192 * missing flag bit indicates an error condition.
1195 #ifdef CHECK_CHARACTERS
1197 ppp->flags |= SC_RCV_B7_1;
1199 ppp->flags |= SC_RCV_B7_0;
1201 if (paritytab[chr >> 5] & (1 << (chr & 0x1F)))
1202 ppp->flags |= SC_RCV_ODDP;
1204 ppp->flags |= SC_RCV_EVNP;
1207 if (chr == PPP_FLAG) {
1209 * FLAG. This is the end of the block. If the block
1210 * ends with ESC FLAG, then the block is to be ignored.
1215 * Process the frame if it was received correctly.
1216 * If there was an error, let the VJ decompressor know.
1217 * There are 4 cases here:
1218 * skb != NULL, toss != 0: error in frame
1219 * skb != NULL, toss == 0: frame ok
1220 * skb == NULL, toss != 0: very first frame,
1221 * error on 1st char, or alloc_skb failed
1222 * skb == NULL, toss == 0: empty frame (~~)
1224 if (ppp->toss || !ppp_receive_frame(ppp, skb)) {
1225 if (ppp->toss && (ppp->flags & SC_DEBUG))
1227 "ppp: tossing frame (%x)\n",
1231 if (!(ppp->toss == 0xE0 || ppp->toss == 0x80))
1232 ++ppp->stats.ppp_ierrors;
1233 ppp_receive_error(ppp);
1236 * Reset for the next frame.
1239 ppp->rfcs = PPP_INITFCS;
1245 /* If we're tossing, look no further. */
1249 /* If this is a control char to be ignored, do so */
1250 if (in_rmap(ppp, chr))
1254 * Modify the next character if preceded by escape.
1255 * The escape character (0x7d) could be an escaped
1256 * 0x5d, if it follows an escape :-)
1261 } else if (chr == PPP_ESCAPE) {
1262 ppp->escape = PPP_TRANS;
1267 * Allocate an skbuff on the first character received.
1268 * The 128 is room for VJ header expansion and FCS.
1271 skb = dev_alloc_skb(ppp->mru + 128 + PPP_HDRLEN);
1273 if (ppp->flags & SC_DEBUG)
1274 printk(KERN_DEBUG "couldn't "
1275 "alloc skb for recv\n");
1282 * Decompress A/C and protocol compression here.
1284 if (skb->len == 0 && chr != PPP_ALLSTATIONS) {
1285 p = skb_put(skb, 2);
1286 p[0] = PPP_ALLSTATIONS;
1289 if (skb->len == 2 && (chr & 1) != 0) {
1290 p = skb_put(skb, 1);
1295 * Check if we've overflowed the MRU
1297 if (skb->len >= ppp->mru + PPP_HDRLEN + 2
1298 || skb_tailroom(skb) <= 0) {
1299 ++ppp->estats.rx_length_errors;
1301 if (ppp->flags & SC_DEBUG)
1302 printk(KERN_DEBUG "rcv frame too long: "
1303 "len=%d mru=%d hroom=%d troom=%d\n",
1304 skb->len, ppp->mru, skb_headroom(skb),
1310 * Store the character and update the FCS.
1312 p = skb_put(skb, 1);
1314 ppp->rfcs = PPP_FCS(ppp->rfcs, chr);
1319 /*************************************************************
1320 * PPP NETWORK INTERFACE SUPPORT
1321 * The following code implements the PPP network
1322 * interface device and handles those parts of
1323 * the PPP processing which are independent of the
1324 * type of hardware link being used, including
1325 * VJ and packet compression.
1326 *************************************************************/
1329 * Network device driver callback routines
1332 static int ppp_init_dev(struct device *dev);
1333 static int ppp_dev_open(struct device *);
1334 static int ppp_dev_ioctl(struct device *dev, struct ifreq *ifr, int cmd);
1335 static int ppp_dev_close(struct device *);
1336 static int ppp_dev_xmit(struct sk_buff *, struct device *);
1337 static struct net_device_stats *ppp_dev_stats (struct device *);
1339 #if LINUX_VERSION_CODE < VERSION(2,1,15)
1340 static int ppp_dev_header(struct sk_buff *, struct device *, __u16,
1341 void *, void *, unsigned int);
1342 static int ppp_dev_rebuild(void *eth, struct device *dev,
1343 unsigned long raddr, struct sk_buff *skb);
1347 * Information for the protocol decoder
1350 typedef int (*pfn_proto) (struct ppp *, struct sk_buff *);
1352 typedef struct ppp_proto_struct {
1357 static int rcv_proto_ip (struct ppp *, struct sk_buff *);
1358 static int rcv_proto_ipx (struct ppp *, struct sk_buff *);
1359 static int rcv_proto_at (struct ppp *, struct sk_buff *);
1360 static int rcv_proto_vjc_comp (struct ppp *, struct sk_buff *);
1361 static int rcv_proto_vjc_uncomp (struct ppp *, struct sk_buff *);
1362 static int rcv_proto_ccp (struct ppp *, struct sk_buff *);
1363 static int rcv_proto_unknown (struct ppp *, struct sk_buff *);
1366 ppp_proto_type proto_list[] = {
1367 { PPP_IP, rcv_proto_ip },
1368 { PPP_IPX, rcv_proto_ipx },
1369 { PPP_AT, rcv_proto_at },
1370 { PPP_VJC_COMP, rcv_proto_vjc_comp },
1371 { PPP_VJC_UNCOMP, rcv_proto_vjc_uncomp },
1372 { PPP_CCP, rcv_proto_ccp },
1373 { 0, rcv_proto_unknown } /* !!! MUST BE LAST !!! */
1377 * Called when the PPP network interface device is actually created.
1380 ppp_init_dev (struct device *dev)
1382 dev->hard_header_len = PPP_HDRLEN;
1383 #if LINUX_VERSION_CODE < VERSION(2,1,15)
1384 dev->hard_header = ppp_dev_header;
1385 dev->rebuild_header = ppp_dev_rebuild;
1390 dev->hard_start_xmit = ppp_dev_xmit;
1391 dev->open = ppp_dev_open;
1392 dev->stop = ppp_dev_close;
1393 dev->get_stats = ppp_dev_stats;
1394 dev->do_ioctl = ppp_dev_ioctl;
1396 dev->tx_queue_len = 10;
1397 dev->type = ARPHRD_PPP;
1399 #if LINUX_VERSION_CODE < VERSION(2,1,20)
1403 for (indx = 0; indx < DEV_NUMBUFFS; indx++)
1404 skb_queue_head_init (&dev->buffs[indx]);
1407 dev_init_buffers(dev);
1410 dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
1416 * Callback from the network layer when the device goes up.
1420 ppp_dev_open (struct device *dev)
1422 struct ppp *ppp = dev2ppp(dev);
1424 if (!ppp->inuse || ppp2tty(ppp) == NULL) {
1425 printk(KERN_ERR "ppp: %s not active\n", dev->name);
1435 * Callback from the network layer when the ppp device goes down.
1439 ppp_dev_close (struct device *dev)
1441 struct ppp *ppp = dev2ppp (dev);
1443 CHECK_PPP_MAGIC(ppp);
1451 get_vj_stats(struct vjstat *vj, struct slcompress *slc)
1453 vj->vjs_packets = slc->sls_o_compressed + slc->sls_o_uncompressed;
1454 vj->vjs_compressed = slc->sls_o_compressed;
1455 vj->vjs_searches = slc->sls_o_searches;
1456 vj->vjs_misses = slc->sls_o_misses;
1457 vj->vjs_errorin = slc->sls_i_error;
1458 vj->vjs_tossed = slc->sls_i_tossed;
1459 vj->vjs_uncompressedin = slc->sls_i_uncompressed;
1460 vj->vjs_compressedin = slc->sls_i_compressed;
1464 * Callback from the network layer to process the sockioctl functions.
1467 ppp_dev_ioctl (struct device *dev, struct ifreq *ifr, int cmd)
1469 struct ppp *ppp = dev2ppp(dev);
1472 struct ppp_stats stats;
1473 struct ppp_comp_stats cstats;
1477 CHECK_PPP_MAGIC(ppp);
1479 memset(&u, 0, sizeof(u));
1482 u.stats.p = ppp->stats;
1483 if (ppp->slcomp != NULL)
1484 get_vj_stats(&u.stats.vj, ppp->slcomp);
1485 nb = sizeof(u.stats);
1488 case SIOCGPPPCSTATS:
1489 if (ppp->sc_xc_state != NULL)
1490 (*ppp->sc_xcomp->comp_stat)
1491 (ppp->sc_xc_state, &u.cstats.c);
1492 if (ppp->sc_rc_state != NULL)
1493 (*ppp->sc_rcomp->decomp_stat)
1494 (ppp->sc_rc_state, &u.cstats.d);
1495 nb = sizeof(u.cstats);
1499 strcpy(u.vers, szVersion);
1500 nb = strlen(u.vers) + 1;
1507 return COPY_TO_USER((void *) ifr->ifr_ifru.ifru_data, &u, nb);
1511 * Process the generic PPP ioctls, i.e. those which are not specific
1512 * to any particular type of hardware link.
1515 ppp_ioctl(struct ppp *ppp, unsigned int param2, unsigned long param3)
1517 register int temp_i = 0, oldflags;
1518 int error = -EFAULT;
1519 unsigned long flags;
1520 struct ppp_idle cur_ddinfo;
1526 * The user must have an euid of root to do these requests.
1528 if (!capable(CAP_NET_ADMIN))
1536 if (GET_USER(temp_i, (int *) param3))
1538 if (temp_i < PPP_MRU)
1540 if (ppp->flags & SC_DEBUG)
1542 "ppp_ioctl: set mru to %x\n", temp_i);
1548 * Fetch the current flags
1550 temp_i = ppp->flags & SC_MASK;
1551 #ifndef CHECK_CHARACTERS /* Don't generate errors if we don't check chars. */
1552 temp_i |= SC_RCV_B7_1 | SC_RCV_B7_0 |
1553 SC_RCV_ODDP | SC_RCV_EVNP;
1555 if (PUT_USER(temp_i, (int *) param3))
1562 * Set the flags for the various options
1564 if (GET_USER(temp_i, (int *) param3))
1567 if (ppp->flags & ~temp_i & SC_CCP_OPEN)
1568 ppp_ccp_closed(ppp);
1572 oldflags = ppp->flags;
1573 temp_i = (temp_i & SC_MASK) | (oldflags & ~SC_MASK);
1574 ppp->flags = temp_i;
1575 restore_flags(flags);
1577 if ((oldflags | temp_i) & SC_DEBUG)
1579 "ppp_ioctl: set flags to %x\n", temp_i);
1583 case PPPIOCSCOMPRESS:
1585 * Set the compression mode
1587 error = ppp_set_compression
1588 (ppp, (struct ppp_option_data *) param3);
1593 * Obtain the unit number for this device.
1595 if (PUT_USER(ppp->line, (int *) param3))
1597 if (ppp->flags & SC_DEBUG)
1599 "ppp_ioctl: get unit: %d\n", ppp->line);
1605 * Set the debug level
1607 if (GET_USER(temp_i, (int *) param3))
1609 temp_i = (temp_i & 0x1F) << 16;
1611 if ((ppp->flags | temp_i) & SC_DEBUG)
1613 "ppp_ioctl: set dbg flags to %x\n", temp_i);
1617 ppp->flags = (ppp->flags & ~0x1F0000) | temp_i;
1618 restore_flags(flags);
1624 * Get the debug level
1626 temp_i = (ppp->flags >> 16) & 0x1F;
1627 if (PUT_USER(temp_i, (int *) param3))
1634 * Get the times since the last send/receive frame operation
1636 /* change absolute times to relative times. */
1637 cur_ddinfo.xmit_idle = (jiffies - ppp->last_xmit) / HZ;
1638 cur_ddinfo.recv_idle = (jiffies - ppp->last_recv) / HZ;
1639 if (COPY_TO_USER((void *) param3, &cur_ddinfo,
1640 sizeof (cur_ddinfo)))
1647 * Set the maximum VJ header compression slot number.
1649 if (GET_USER(temp_i, (int *) param3))
1652 if (temp_i < 2 || temp_i > 255)
1655 if (ppp->flags & SC_DEBUG)
1656 printk(KERN_INFO "ppp_ioctl: set maxcid to %d\n",
1658 if (ppp->slcomp != NULL)
1659 slhc_free(ppp->slcomp);
1660 ppp->slcomp = slhc_init(16, temp_i);
1663 if (ppp->slcomp == NULL) {
1664 printk(KERN_ERR "ppp: no memory for VJ compression\n");
1672 if (COPY_FROM_USER(&npi, (void *) param3, sizeof(npi)))
1675 switch (npi.protocol) {
1677 npi.protocol = NP_IP;
1680 npi.protocol = NP_IPX;
1683 npi.protocol = NP_AT;
1686 if (ppp->flags & SC_DEBUG)
1687 printk(KERN_DEBUG "pppioc[gs]npmode: "
1688 "invalid proto %d\n", npi.protocol);
1693 if (param2 == PPPIOCGNPMODE) {
1694 npi.mode = ppp->sc_npmode[npi.protocol];
1695 if (COPY_TO_USER((void *) param3, &npi, sizeof(npi)))
1698 ppp->sc_npmode[npi.protocol] = npi.mode;
1699 if (ppp->flags & SC_DEBUG)
1700 printk(KERN_DEBUG "ppp: set np %d to %d\n",
1701 npi.protocol, npi.mode);
1709 * All other ioctl() events will come here.
1711 if (ppp->flags & SC_DEBUG)
1713 "ppp_ioctl: invalid ioctl: %x, addr %lx\n",
1716 error = -ENOIOCTLCMD;
1724 * Process the set-compression ioctl.
1727 ppp_set_compression (struct ppp *ppp, struct ppp_option_data *odp)
1729 struct compressor *cp;
1731 unsigned long flags;
1733 __u8 ccp_option[CCP_MAX_OPTION_LENGTH];
1734 struct ppp_option_data data;
1737 * Fetch the compression parameters
1739 if (COPY_FROM_USER(&data, odp, sizeof (data)))
1744 if ((unsigned) nb >= CCP_MAX_OPTION_LENGTH)
1745 nb = CCP_MAX_OPTION_LENGTH;
1747 if (COPY_FROM_USER(ccp_option, ptr, nb))
1750 if (ccp_option[1] < 2) /* preliminary check on the length byte */
1755 ppp->flags &= ~(data.transmit? SC_COMP_RUN: SC_DECOMP_RUN);
1756 restore_flags(flags);
1758 cp = find_compressor (ccp_option[0]);
1759 #if defined(CONFIG_KMOD) || defined(CONFIG_KERNELD)
1762 sprintf(modname, "ppp-compress-%d", ccp_option[0]);
1763 request_module(modname);
1764 cp = find_compressor(ccp_option[0]);
1766 #endif /* CONFIG_KMOD */
1769 if (ppp->flags & SC_DEBUG)
1771 "%s: no compressor for [%x %x %x], %x\n",
1772 ppp->name, ccp_option[0], ccp_option[1],
1774 return -EINVAL; /* compressor not loaded */
1778 * Found a handler for the protocol - try to allocate
1779 * a compressor or decompressor.
1782 if (data.transmit) {
1783 if (ppp->sc_xc_state != NULL)
1784 (*ppp->sc_xcomp->comp_free)(ppp->sc_xc_state);
1785 ppp->sc_xc_state = NULL;
1788 ppp->sc_xc_state = cp->comp_alloc(ccp_option, nb);
1790 if (ppp->sc_xc_state == NULL) {
1791 if (ppp->flags & SC_DEBUG)
1792 printk(KERN_DEBUG "%s: comp_alloc failed\n",
1797 if (ppp->sc_rc_state != NULL)
1798 (*ppp->sc_rcomp->decomp_free)(ppp->sc_rc_state);
1799 ppp->sc_rc_state = NULL;
1802 ppp->sc_rc_state = cp->decomp_alloc(ccp_option, nb);
1803 if (ppp->sc_rc_state == NULL) {
1804 if (ppp->flags & SC_DEBUG)
1805 printk(KERN_DEBUG "%s: decomp_alloc failed\n",
1815 * Handle a CCP packet.
1817 * The CCP packet is passed along to the pppd process just like any
1818 * other PPP frame. The difference is that some processing needs to be
1819 * immediate or the compressors will become confused on the peer.
1822 static void ppp_proto_ccp(struct ppp *ppp, __u8 *dp, int len, int rcvd)
1824 int slen = CCP_LENGTH(dp);
1825 __u8 *opt = dp + CCP_HDRLEN;
1826 int opt_len = slen - CCP_HDRLEN;
1827 unsigned long flags;
1832 if (ppp->flags & SC_DEBUG)
1833 printk(KERN_DEBUG "ppp_proto_ccp rcvd=%d code=%x flags=%x\n",
1834 rcvd, CCP_CODE(dp), ppp->flags);
1836 switch (CCP_CODE(dp)) {
1841 * CCP must be going down - disable compression
1843 if (ppp->flags & SC_CCP_UP) {
1845 ppp->flags &= ~(SC_CCP_UP |
1852 if ((ppp->flags & SC_CCP_OPEN) == 0)
1854 if (ppp->flags & SC_CCP_UP)
1856 if (slen < (CCP_HDRLEN + CCP_OPT_MINLEN))
1858 if (slen < (CCP_OPT_LENGTH (opt) + CCP_HDRLEN))
1862 * we're agreeing to send compressed packets.
1864 if (ppp->sc_xc_state == NULL)
1867 if ((*ppp->sc_xcomp->comp_init)
1870 ppp->line, 0, ppp->flags & SC_DEBUG)) {
1871 if (ppp->flags & SC_DEBUG)
1872 printk(KERN_DEBUG "%s: comp running\n",
1875 ppp->flags |= SC_COMP_RUN;
1881 * peer is agreeing to send compressed packets.
1883 if (ppp->sc_rc_state == NULL)
1886 if ((*ppp->sc_rcomp->decomp_init)
1889 ppp->line, 0, ppp->mru, ppp->flags & SC_DEBUG)) {
1890 if (ppp->flags & SC_DEBUG)
1891 printk(KERN_DEBUG "%s: decomp running\n",
1894 ppp->flags |= SC_DECOMP_RUN;
1895 ppp->flags &= ~(SC_DC_ERROR | SC_DC_FERROR);
1901 * CCP Reset-ack resets compressors and decompressors
1902 * as it passes through.
1904 if ((ppp->flags & SC_CCP_UP) == 0)
1908 if (ppp->sc_xc_state && (ppp->flags & SC_COMP_RUN)) {
1909 (*ppp->sc_xcomp->comp_reset)(ppp->sc_xc_state);
1910 if (ppp->flags & SC_DEBUG)
1911 printk(KERN_DEBUG "%s: comp reset\n",
1915 if (ppp->sc_rc_state && (ppp->flags & SC_DECOMP_RUN)) {
1916 (*ppp->sc_rcomp->decomp_reset)(ppp->sc_rc_state);
1917 if (ppp->flags & SC_DEBUG)
1918 printk(KERN_DEBUG "%s: decomp reset\n",
1921 ppp->flags &= ~SC_DC_ERROR;
1926 restore_flags(flags);
1930 * CCP is down; free (de)compressor state if necessary.
1934 ppp_ccp_closed(struct ppp *ppp)
1936 unsigned long flags;
1940 ppp->flags &= ~(SC_CCP_OPEN | SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN);
1941 restore_flags(flags);
1942 if (ppp->flags & SC_DEBUG)
1943 printk(KERN_DEBUG "%s: ccp closed\n", ppp->name);
1944 if (ppp->sc_xc_state) {
1945 (*ppp->sc_xcomp->comp_free) (ppp->sc_xc_state);
1946 ppp->sc_xc_state = NULL;
1949 if (ppp->sc_rc_state) {
1950 (*ppp->sc_rcomp->decomp_free) (ppp->sc_rc_state);
1951 ppp->sc_rc_state = NULL;
1955 /*************************************************************
1956 * RECEIVE-SIDE ROUTINES
1957 *************************************************************/
1960 * On entry, a received frame is in skb.
1961 * Check it and dispose as appropriate.
1964 ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb)
1970 struct sk_buff *new_skb;
1971 ppp_proto_type *proto_ptr;
1974 * An empty frame is ignored. This occurs if the FLAG sequence
1975 * precedes and follows each frame.
1979 if (skb->len == 0) {
1987 * Generate an error if the frame is too small.
1989 if (count < PPP_HDRLEN + 2) {
1990 if (ppp->flags & SC_DEBUG)
1992 "ppp: got runt ppp frame, %d chars\n", count);
1993 ++ppp->estats.rx_length_errors;
1998 * Verify the FCS of the frame and discard the FCS characters
1999 * from the end of the buffer.
2001 if (ppp->rfcs != PPP_GOODFCS) {
2002 if (ppp->flags & SC_DEBUG) {
2004 "ppp: frame with bad fcs, length = %d\n",
2006 ppp_print_buffer("bad frame", data, count);
2008 ++ppp->estats.rx_crc_errors;
2011 count -= 2; /* ignore the fcs characters */
2012 skb_trim(skb, count);
2015 * Process the active decompressor.
2017 if (ppp->sc_rc_state != NULL &&
2018 (ppp->flags & SC_DECOMP_RUN) &&
2019 ((ppp->flags & (SC_DC_FERROR | SC_DC_ERROR)) == 0)) {
2020 if (PPP_PROTOCOL(data) == PPP_COMP) {
2022 * If the frame is compressed then decompress it.
2024 new_skb = dev_alloc_skb(ppp->mru + 128 + PPP_HDRLEN);
2025 if (new_skb == NULL) {
2026 printk(KERN_ERR "ppp_recv_frame: no memory\n");
2027 new_count = DECOMP_ERROR;
2029 new_count = (*ppp->sc_rcomp->decompress)
2030 (ppp->sc_rc_state, data, count,
2031 new_skb->data, ppp->mru + PPP_HDRLEN);
2033 if (new_count > 0) {
2034 /* Frame was decompressed OK */
2038 data = skb_put(skb, count);
2042 * On a decompression error, we pass the
2043 * compressed frame up to pppd as an
2046 if (ppp->flags & SC_DEBUG)
2047 printk(KERN_INFO "%s: decomp err %d\n",
2048 ppp->name, new_count);
2051 if (ppp->slcomp != 0)
2052 slhc_toss(ppp->slcomp);
2053 ++ppp->stats.ppp_ierrors;
2054 if (new_count == DECOMP_FATALERROR) {
2055 ppp->flags |= SC_DC_FERROR;
2057 ppp->flags |= SC_DC_ERROR;
2064 * The frame is not compressed. Pass it to the
2065 * decompression code so it can update its
2066 * dictionary if necessary.
2068 (*ppp->sc_rcomp->incomp)(ppp->sc_rc_state,
2072 else if (PPP_PROTOCOL(data) == PPP_COMP && (ppp->flags & SC_DEBUG))
2073 printk(KERN_INFO "%s: not decomp, rc_state=%p flags=%x\n",
2074 ppp->name, ppp->sc_rc_state, ppp->flags);
2077 * Count the frame and print it
2079 ++ppp->stats.ppp_ipackets;
2080 ppp->stats.ppp_ioctects += count;
2081 if (ppp->flags & SC_LOG_INPKT)
2082 ppp_print_buffer ("receive frame", data, count);
2085 * Find the procedure to handle this protocol.
2086 * The last one is marked as protocol 0 which is the 'catch-all'
2087 * to feed it to the pppd daemon.
2089 proto = PPP_PROTOCOL(data);
2090 proto_ptr = proto_list;
2091 while (proto_ptr->proto != 0 && proto_ptr->proto != proto)
2095 * Update the appropriate statistic counter.
2097 if (!(*proto_ptr->func)(ppp, skb)) {
2099 ++ppp->stats.ppp_discards;
2106 * An input error has been detected, so we need to inform
2107 * the VJ decompressor.
2110 ppp_receive_error(struct ppp *ppp)
2114 if (ppp->slcomp != 0)
2115 slhc_toss(ppp->slcomp);
2119 * Put the input frame into the networking system for the indicated protocol
2122 ppp_rcv_rx(struct ppp *ppp, __u16 proto, struct sk_buff *skb)
2126 * Fill in a few fields of the skb and give it to netif_rx().
2128 skb->dev = ppp2dev(ppp); /* We are the device */
2129 skb->protocol = htons(proto);
2130 skb->mac.raw = skb->data;
2131 skb_pull(skb, PPP_HDRLEN); /* pull off ppp header */
2132 ppp->last_recv = jiffies;
2133 #if LINUX_VERSION_CODE < VERSION(2,1,15)
2141 * Process the receipt of an IP frame
2144 rcv_proto_ip(struct ppp *ppp, struct sk_buff *skb)
2147 if ((ppp2dev(ppp)->flags & IFF_UP) && (skb->len > 0)
2148 && ppp->sc_npmode[NP_IP] == NPMODE_PASS)
2149 return ppp_rcv_rx(ppp, ETH_P_IP, skb);
2154 * Process the receipt of an IPX frame
2157 rcv_proto_ipx(struct ppp *ppp, struct sk_buff *skb)
2160 if (((ppp2dev(ppp)->flags & IFF_UP) != 0) && (skb->len > 0)
2161 && ppp->sc_npmode[NP_IPX] == NPMODE_PASS)
2162 return ppp_rcv_rx(ppp, ETH_P_IPX, skb);
2167 * Process the receipt of an Appletalk frame
2170 rcv_proto_at(struct ppp *ppp, struct sk_buff *skb)
2173 if ((ppp2dev(ppp)->flags & IFF_UP) && (skb->len > 0)
2174 && ppp->sc_npmode[NP_AT] == NPMODE_PASS)
2175 return ppp_rcv_rx(ppp, ETH_P_PPPTALK, skb);
2180 * Process the receipt of an VJ Compressed frame
2183 rcv_proto_vjc_comp(struct ppp *ppp, struct sk_buff *skb)
2188 if ((ppp->flags & SC_REJ_COMP_TCP) || ppp->slcomp == NULL)
2190 new_count = slhc_uncompress(ppp->slcomp, skb->data + PPP_HDRLEN,
2191 skb->len - PPP_HDRLEN);
2192 if (new_count < 0) {
2193 if (ppp->flags & SC_DEBUG)
2195 "ppp: error in VJ decompression\n");
2198 skb_put(skb, new_count + PPP_HDRLEN - skb->len);
2199 return rcv_proto_ip(ppp, skb);
2203 * Process the receipt of an VJ Un-compressed frame
2206 rcv_proto_vjc_uncomp(struct ppp *ppp, struct sk_buff *skb)
2209 if ((ppp->flags & SC_REJ_COMP_TCP) || ppp->slcomp == NULL)
2211 if (slhc_remember(ppp->slcomp, skb->data + PPP_HDRLEN,
2212 skb->len - PPP_HDRLEN) <= 0) {
2213 if (ppp->flags & SC_DEBUG)
2214 printk(KERN_NOTICE "ppp: error in VJ memorizing\n");
2217 return rcv_proto_ip(ppp, skb);
2221 rcv_proto_ccp(struct ppp *ppp, struct sk_buff *skb)
2224 ppp_proto_ccp (ppp, skb->data + PPP_HDRLEN, skb->len - PPP_HDRLEN, 1);
2225 return rcv_proto_unknown(ppp, skb);
2229 * Receive all unclassified protocols.
2232 rcv_proto_unknown(struct ppp *ppp, struct sk_buff *skb)
2237 * Limit queue length by dropping old frames.
2239 skb_queue_tail(&ppp->rcv_q, skb);
2240 while (ppp->rcv_q.qlen > PPP_MAX_RCV_QLEN) {
2241 struct sk_buff *skb = skb_dequeue(&ppp->rcv_q);
2246 wake_up_interruptible (&ppp->read_wait);
2247 if (ppp->tty->fasync != NULL)
2248 kill_fasync (ppp->tty->fasync, SIGIO);
2253 /*************************************************************
2254 * TRANSMIT-SIDE ROUTINES
2255 *************************************************************/
2257 /* local function to store a value into the LQR frame */
2258 extern inline __u8 * store_long (register __u8 *p, register int value) {
2259 *p++ = (__u8) (value >> 24);
2260 *p++ = (__u8) (value >> 16);
2261 *p++ = (__u8) (value >> 8);
2262 *p++ = (__u8) value;
2267 * Compress and send an frame to the peer.
2268 * Should be called with dev->tbusy == 1, having been set by the caller.
2269 * That is, we use dev->tbusy as a lock to prevent reentry of this
2273 ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
2285 /* dump the buffer */
2286 if (ppp->flags & SC_LOG_OUTPKT)
2287 ppp_print_buffer ("write frame", data, count);
2290 * Handle various types of protocol-specific compression
2291 * and other processing, including:
2292 * - VJ TCP header compression
2293 * - updating LQR packets
2294 * - updating CCP state on CCP packets
2296 proto = PPP_PROTOCOL(data);
2299 if ((ppp->flags & SC_COMP_TCP) && ppp->slcomp != NULL)
2300 skb = ppp_vj_compress(ppp, skb);
2305 * Update the LQR frame with the current MIB information.
2306 * This way the information is accurate and up-to-date.
2310 p = data + 40; /* Point to last two items. */
2311 p = store_long(p, ppp->stats.ppp_opackets + 1);
2312 p = store_long(p, ppp->stats.ppp_ooctects + count);
2313 ++ppp->stats.ppp_olqrs;
2318 * Outbound compression control frames
2320 ppp_proto_ccp(ppp, data + PPP_HDRLEN, count - PPP_HDRLEN, 0);
2327 * Compress the whole frame if possible.
2329 if (((ppp->flags & SC_COMP_RUN) != 0) &&
2330 (ppp->sc_xc_state != (void *) 0) &&
2331 (proto != PPP_LCP) &&
2332 (proto != PPP_CCP)) {
2333 struct sk_buff *new_skb;
2336 /* Allocate an skb for the compressed frame. */
2337 new_skb = alloc_skb(ppp->mtu + PPP_HDRLEN, GFP_ATOMIC);
2338 if (new_skb == NULL) {
2339 printk(KERN_ERR "ppp_send_frame: no memory\n");
2345 /* Compress the frame. */
2346 new_count = (*ppp->sc_xcomp->compress)
2347 (ppp->sc_xc_state, data, new_skb->data,
2348 count, ppp->mtu + PPP_HDRLEN);
2350 /* Did it compress? */
2351 if (new_count > 0 && (ppp->flags & SC_CCP_UP)) {
2352 skb_put(new_skb, new_count);
2357 * The frame could not be compressed, or it could not
2358 * be sent in compressed form because CCP is down.
2367 ret = ppp_async_send(ppp, skb);
2369 /* we can release the lock */
2371 } else if (ret < 0) {
2372 /* this can't happen, since the caller got the tbusy lock */
2373 printk(KERN_ERR "ppp: ppp_async_send didn't accept pkt\n");
2378 * Apply VJ TCP header compression to a packet.
2380 static struct sk_buff *
2381 ppp_vj_compress(struct ppp *ppp, struct sk_buff *skb)
2383 __u8 *orig_data, *data;
2384 struct sk_buff *new_skb;
2387 new_skb = alloc_skb(skb->len, GFP_ATOMIC);
2388 if (new_skb == NULL) {
2389 printk(KERN_ERR "ppp: no memory for vj compression\n");
2393 orig_data = data = skb->data + PPP_HDRLEN;
2394 len = slhc_compress(ppp->slcomp, data, skb->len - PPP_HDRLEN,
2395 new_skb->data + PPP_HDRLEN, &data,
2396 (ppp->flags & SC_NO_TCP_CCID) == 0);
2398 if (data == orig_data) {
2399 /* Couldn't compress the data */
2404 /* The data has been changed */
2405 if (data[0] & SL_TYPE_COMPRESSED_TCP) {
2406 proto = PPP_VJC_COMP;
2407 data[0] ^= SL_TYPE_COMPRESSED_TCP;
2409 if (data[0] >= SL_TYPE_UNCOMPRESSED_TCP)
2410 proto = PPP_VJC_UNCOMP;
2413 data[0] = orig_data[0];
2416 data = skb_put(new_skb, len + PPP_HDRLEN);
2417 data[0] = PPP_ALLSTATIONS;
2427 ppp_send_frames(struct ppp *ppp)
2429 struct sk_buff *skb;
2431 while (!test_and_set_bit(0, &ppp->dev.tbusy)) {
2432 skb = skb_dequeue(&ppp->xmt_q);
2438 ppp_send_frame(ppp, skb);
2443 * Called from the hardware (tty) layer when it can accept
2447 ppp_output_wakeup(struct ppp *ppp)
2451 if (!ppp->dev.tbusy) {
2452 printk(KERN_ERR "ppp_output_wakeup called but tbusy==0\n");
2456 ppp_send_frames(ppp);
2460 * Send a control frame (from pppd).
2463 ppp_send_ctrl(struct ppp *ppp, struct sk_buff *skb)
2468 * Put the packet on the queue, then send as many as we can.
2470 skb_queue_tail(&ppp->xmt_q, skb);
2471 ppp_send_frames(ppp);
2475 /*************************************************************
2477 * This routine accepts requests from the network layer
2478 * and attempts to deliver the packets.
2479 *************************************************************/
2481 * Send a frame to the peer.
2482 * Returns 1 iff the frame was not accepted.
2485 ppp_dev_xmit(struct sk_buff *skb, struct device *dev)
2487 struct ppp *ppp = dev2ppp(dev);
2488 struct tty_struct *tty = ppp2tty(ppp);
2493 /* just a little sanity check. */
2496 if (skb->data == NULL) {
2502 * Avoid timing problem should tty hangup while data is
2503 * queued to be sent.
2511 * Validate the tty interface
2514 if (ppp->flags & SC_DEBUG)
2516 "ppp_dev_xmit: %s not connected to a TTY!\n",
2523 * Work out the appropriate network-protocol mode for this packet.
2525 npmode = NPMODE_PASS; /* default */
2526 switch (ntohs(skb->protocol)) {
2529 npmode = ppp->sc_npmode[NP_IP];
2533 npmode = ppp->sc_npmode[NP_IPX];
2538 npmode = ppp->sc_npmode[NP_AT];
2541 if (ppp->flags & SC_DEBUG)
2542 printk(KERN_INFO "%s: packet for unknown proto %x\n",
2543 ppp->name, ntohs(skb->protocol));
2549 * Drop, accept or reject the packet depending on the mode.
2557 * We may not send the packet now, so drop it.
2558 * XXX It would be nice to be able to return it to the
2559 * network system to be queued and retransmitted later.
2561 if (ppp->flags & SC_DEBUG)
2562 printk(KERN_DEBUG "%s: returning frame\n", ppp->name);
2568 if (ppp->flags & SC_DEBUG)
2570 "ppp_dev_xmit: dropping (npmode = %d) on %s\n",
2577 * The dev->tbusy field acts as a lock to allow only
2578 * one packet to be processed at a time. If we can't
2579 * get the lock, try again later.
2581 if (test_and_set_bit(0, &dev->tbusy))
2585 * Put the 4-byte PPP header on the packet.
2586 * If there isn't room for it, we have to copy the packet.
2588 if (skb_headroom(skb) < PPP_HDRLEN) {
2589 struct sk_buff *new_skb;
2591 new_skb = alloc_skb(skb->len + PPP_HDRLEN, GFP_ATOMIC);
2592 if (new_skb == NULL) {
2593 printk(KERN_ERR "%s: skb hdr alloc failed\n",
2599 skb_reserve(new_skb, PPP_HDRLEN);
2600 memcpy(skb_put(new_skb, skb->len), skb->data, skb->len);
2605 hdr = skb_push(skb, PPP_HDRLEN);
2606 hdr[0] = PPP_ALLSTATIONS;
2608 hdr[2] = proto >> 8;
2611 ppp_send_frame(ppp, skb);
2615 #if LINUX_VERSION_CODE < VERSION(2,1,15)
2617 * Null hard_header and header_rebuild routines.
2619 static int ppp_dev_header(struct sk_buff *skb, struct device *dev,
2620 unsigned short type, void *daddr,
2621 void *saddr, unsigned int len)
2626 static int ppp_dev_rebuild(void *eth, struct device *dev,
2627 unsigned long raddr, struct sk_buff *skb)
2631 #endif /* < 2.1.15 */
2634 * Generate the statistic information for the /proc/net/dev listing.
2636 static struct net_device_stats *
2637 ppp_dev_stats (struct device *dev)
2639 struct ppp *ppp = dev2ppp (dev);
2641 ppp->estats.rx_packets = ppp->stats.ppp_ipackets;
2642 ppp->estats.rx_errors = ppp->stats.ppp_ierrors;
2643 ppp->estats.tx_packets = ppp->stats.ppp_opackets;
2644 ppp->estats.tx_errors = ppp->stats.ppp_oerrors;
2645 #if LINUX_VERSION_CODE >= VERSION(2,1,25)
2646 ppp->estats.rx_bytes = ppp->stats.ppp_ibytes;
2647 ppp->estats.tx_bytes = ppp->stats.ppp_obytes;
2650 return &ppp->estats;
2653 /*************************************************************
2655 * Miscellany called by various functions above.
2656 *************************************************************/
2658 /* Locate the previous instance of the PPP channel */
2660 ppp_find(int pid_value)
2664 /* try to find the device which this pid is already using */
2665 for (ppp = ppp_list; ppp != 0; ppp = ppp->next) {
2666 if (ppp->inuse && ppp->sc_xfer == pid_value) {
2674 /* allocate or create a PPP channel */
2683 /* try to find an free device */
2684 for (ppp = ppp_list; ppp != 0; ppp = ppp->next) {
2685 if (!test_and_set_bit(0, &ppp->inuse)) {
2687 if (dev->flags & IFF_UP) {
2688 clear_bit(0, &ppp->inuse);
2691 /* Reregister device */
2692 unregister_netdev(dev);
2693 if (register_netdev(dev) == 0)
2695 printk(KERN_DEBUG "could not reregister ppp device\n");
2696 /* leave inuse set in this case */
2701 * There are no available units, so make a new one.
2703 ppp = (struct ppp *) kmalloc(sizeof(struct ppp), GFP_KERNEL);
2705 printk(KERN_ERR "ppp: struct ppp allocation failed\n");
2708 memset(ppp, 0, sizeof(*ppp));
2710 /* initialize channel control data */
2711 ppp->magic = PPP_MAGIC;
2714 ppp->read_wait = NULL;
2717 * Make up a suitable name for this device
2720 dev->name = ppp->name;
2721 if_num = dev_alloc_name(dev, "ppp%d");
2723 printk(KERN_ERR "ppp: dev_alloc_name failed (%d)\n", if_num);
2731 dev->init = ppp_init_dev;
2732 dev->name = ppp->name;
2733 dev->priv = (void *) ppp;
2735 /* register device so that we can be ifconfig'd */
2736 /* ppp_init_dev() will be called as a side-effect */
2737 status = register_netdev (dev);
2739 printk(KERN_INFO "registered device %s\n", dev->name);
2742 "ppp_alloc - register_netdev(%s) = %d failure.\n",
2748 /* link this unit into our list */
2752 ppp_last->next = ppp;
2759 * Initialize the generic parts of the ppp structure.
2762 ppp_generic_init(struct ppp *ppp)
2770 skb_queue_head_init(&ppp->xmt_q);
2771 skb_queue_head_init(&ppp->rcv_q);
2773 ppp->last_xmit = jiffies;
2774 ppp->last_recv = jiffies;
2776 /* clear statistics */
2777 memset(&ppp->stats, 0, sizeof (struct pppstat));
2778 memset(&ppp->estats, 0, sizeof(struct net_device_stats));
2780 /* PPP compression data */
2781 ppp->sc_xc_state = NULL;
2782 ppp->sc_rc_state = NULL;
2784 for (indx = 0; indx < NUM_NP; ++indx)
2785 ppp->sc_npmode[indx] = NPMODE_PASS;
2789 * Called to clean up the generic parts of the ppp structure.
2792 ppp_release(struct ppp *ppp)
2794 struct sk_buff *skb;
2796 CHECK_PPP_MAGIC(ppp);
2798 if (ppp->flags & SC_DEBUG)
2799 printk(KERN_DEBUG "%s released\n", ppp->name);
2801 ppp_ccp_closed(ppp);
2803 /* Ensure that the pppd process is not hanging on select()/poll() */
2804 wake_up_interruptible(&ppp->read_wait);
2807 slhc_free(ppp->slcomp);
2811 while ((skb = skb_dequeue(&ppp->rcv_q)) != NULL)
2813 while ((skb = skb_dequeue(&ppp->xmt_q)) != NULL)
2818 * Utility procedures to print a buffer in hex/ascii
2821 ppp_print_hex (register __u8 * out, const __u8 * in, int count)
2823 register __u8 next_ch;
2824 static char hex[] = "0123456789ABCDEF";
2826 while (count-- > 0) {
2828 *out++ = hex[(next_ch >> 4) & 0x0F];
2829 *out++ = hex[next_ch & 0x0F];
2835 ppp_print_char (register __u8 * out, const __u8 * in, int count)
2837 register __u8 next_ch;
2839 while (count-- > 0) {
2842 if (next_ch < 0x20 || next_ch > 0x7e)
2846 if (next_ch == '%') /* printk/syslogd has a bug !! */
2854 ppp_print_buffer (const char *name, const __u8 *buf, int count)
2859 printk(KERN_DEBUG "ppp: %s, count = %d\n", name, count);
2862 memset (line, 32, 44);
2863 ppp_print_hex (line, buf, 8);
2864 ppp_print_char (&line[8 * 3], buf, 8);
2865 printk(KERN_DEBUG "%s\n", line);
2871 memset (line, 32, 44);
2872 ppp_print_hex (line, buf, count);
2873 ppp_print_char (&line[8 * 3], buf, count);
2874 printk(KERN_DEBUG "%s\n", line);
2878 /*************************************************************
2879 * Compressor module interface
2880 *************************************************************/
2882 struct compressor_link {
2883 struct compressor_link *next;
2884 struct compressor *comp;
2887 static struct compressor_link *ppp_compressors = (struct compressor_link *) 0;
2889 static struct compressor *find_compressor (int type)
2891 struct compressor_link *lnk;
2892 unsigned long flags;
2897 lnk = ppp_compressors;
2898 while (lnk != (struct compressor_link *) 0) {
2899 if ((int) (__u8) lnk->comp->compress_proto == type) {
2900 restore_flags(flags);
2906 restore_flags(flags);
2907 return (struct compressor *) 0;
2910 #ifdef CONFIG_MODULES
2911 static int ppp_register_compressor (struct compressor *cp)
2913 struct compressor_link *new;
2914 unsigned long flags;
2916 new = (struct compressor_link *)
2917 kmalloc (sizeof (struct compressor_link), GFP_KERNEL);
2919 if (new == (struct compressor_link *) 0)
2925 if (find_compressor (cp->compress_proto)) {
2926 restore_flags(flags);
2931 new->next = ppp_compressors;
2933 ppp_compressors = new;
2935 restore_flags(flags);
2939 static void ppp_unregister_compressor (struct compressor *cp)
2941 struct compressor_link *prev = (struct compressor_link *) 0;
2942 struct compressor_link *lnk;
2943 unsigned long flags;
2948 lnk = ppp_compressors;
2949 while (lnk != (struct compressor_link *) 0) {
2950 if (lnk->comp == cp) {
2952 prev->next = lnk->next;
2954 ppp_compressors = lnk->next;
2961 restore_flags(flags);
2965 /*************************************************************
2966 * Module support routines
2967 *************************************************************/
2975 /* register our line disciplines */
2976 status = ppp_first_time();
2978 printk(KERN_INFO "PPP: ppp_init() failure %d\n", status);
2979 #if LINUX_VERSION_CODE < VERSION(2,1,18)
2981 (void) register_symtab (&ppp_syms);
2988 cleanup_module(void)
2991 struct ppp *ppp, *next_ppp;
2995 * Ensure that the devices are not in operation.
2997 for (ppp = ppp_list; ppp != 0; ppp = ppp->next) {
2998 CHECK_PPP_MAGIC(ppp);
2999 if (ppp->inuse || (ppp->dev.flags & IFF_UP))
3003 printk(KERN_CRIT "PPP: removing despite %d units in use!\n",
3007 * Release the tty registration of the line discipline so that
3008 * ttys can no longer be put into PPP line discipline.
3010 status = tty_register_ldisc (N_PPP, NULL);
3013 "PPP: Unable to unregister ppp line discipline "
3014 "(err = %d)\n", status);
3017 "PPP: ppp line discipline successfully unregistered\n");
3020 * De-register the devices so that there is no problem with them
3022 for (ppp = ppp_list; ppp != 0; ppp = next_ppp) {
3023 next_ppp = ppp->next;
3024 unregister_netdev(&ppp->dev);