ppp_generic.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:63k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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