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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * PPP synchronous tty channel driver for Linux.
  3.  *
  4.  * This is a ppp channel driver that can be used with tty device drivers
  5.  * that are frame oriented, such as synchronous HDLC devices.
  6.  *
  7.  * Complete PPP frames without encoding/decoding are exchanged between
  8.  * the channel driver and the device driver.
  9.  * 
  10.  * The async map IOCTL codes are implemented to keep the user mode
  11.  * applications happy if they call them. Synchronous PPP does not use
  12.  * the async maps.
  13.  *
  14.  * Copyright 1999 Paul Mackerras.
  15.  *
  16.  * Also touched by the grubby hands of Paul Fulghum paulkf@microgate.com
  17.  *
  18.  *  This program is free software; you can redistribute it and/or
  19.  *  modify it under the terms of the GNU General Public License
  20.  *  as published by the Free Software Foundation; either version
  21.  *  2 of the License, or (at your option) any later version.
  22.  *
  23.  * This driver provides the encapsulation and framing for sending
  24.  * and receiving PPP frames over sync serial lines.  It relies on
  25.  * the generic PPP layer to give it frames to send and to process
  26.  * received frames.  It implements the PPP line discipline.
  27.  *
  28.  * Part of the code in this driver was inspired by the old async-only
  29.  * PPP driver, written by Michael Callahan and Al Longyear, and
  30.  * subsequently hacked by Paul Mackerras.
  31.  *
  32.  * ==FILEVERSION 20020125==
  33.  */
  34. #include <linux/module.h>
  35. #include <linux/kernel.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/tty.h>
  38. #include <linux/netdevice.h>
  39. #include <linux/poll.h>
  40. #include <linux/ppp_defs.h>
  41. #include <linux/if_ppp.h>
  42. #include <linux/ppp_channel.h>
  43. #include <linux/spinlock.h>
  44. #include <linux/init.h>
  45. #include <asm/uaccess.h>
  46. #include <asm/semaphore.h>
  47. #define PPP_VERSION "2.4.2"
  48. /* Structure for storing local state. */
  49. struct syncppp {
  50. struct tty_struct *tty;
  51. unsigned int flags;
  52. unsigned int rbits;
  53. int mru;
  54. spinlock_t xmit_lock;
  55. spinlock_t recv_lock;
  56. unsigned long xmit_flags;
  57. u32 xaccm[8];
  58. u32 raccm;
  59. unsigned int bytes_sent;
  60. unsigned int bytes_rcvd;
  61. struct sk_buff *tpkt;
  62. unsigned long last_xmit;
  63. struct sk_buff *rpkt;
  64. atomic_t refcnt;
  65. struct semaphore dead_sem;
  66. struct ppp_channel chan; /* interface to generic ppp layer */
  67. };
  68. /* Bit numbers in xmit_flags */
  69. #define XMIT_WAKEUP 0
  70. #define XMIT_FULL 1
  71. /* Bits in rbits */
  72. #define SC_RCV_BITS (SC_RCV_B7_1|SC_RCV_B7_0|SC_RCV_ODDP|SC_RCV_EVNP)
  73. #define PPPSYNC_MAX_RQLEN 32 /* arbitrary */
  74. /*
  75.  * Prototypes.
  76.  */
  77. static struct sk_buff* ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *);
  78. static int ppp_sync_send(struct ppp_channel *chan, struct sk_buff *skb);
  79. static int ppp_sync_ioctl(struct ppp_channel *chan, unsigned int cmd,
  80.   unsigned long arg);
  81. static int ppp_sync_push(struct syncppp *ap);
  82. static void ppp_sync_flush_output(struct syncppp *ap);
  83. static void ppp_sync_input(struct syncppp *ap, const unsigned char *buf,
  84.    char *flags, int count);
  85. static struct ppp_channel_ops sync_ops = {
  86. ppp_sync_send,
  87. ppp_sync_ioctl
  88. };
  89. /*
  90.  * Utility procedures to print a buffer in hex/ascii
  91.  */
  92. static void
  93. ppp_print_hex (register __u8 * out, const __u8 * in, int count)
  94. {
  95. register __u8 next_ch;
  96. static char hex[] = "0123456789ABCDEF";
  97. while (count-- > 0) {
  98. next_ch = *in++;
  99. *out++ = hex[(next_ch >> 4) & 0x0F];
  100. *out++ = hex[next_ch & 0x0F];
  101. ++out;
  102. }
  103. }
  104. static void
  105. ppp_print_char (register __u8 * out, const __u8 * in, int count)
  106. {
  107. register __u8 next_ch;
  108. while (count-- > 0) {
  109. next_ch = *in++;
  110. if (next_ch < 0x20 || next_ch > 0x7e)
  111. *out++ = '.';
  112. else {
  113. *out++ = next_ch;
  114. if (next_ch == '%')   /* printk/syslogd has a bug !! */
  115. *out++ = '%';
  116. }
  117. }
  118. *out = '';
  119. }
  120. static void
  121. ppp_print_buffer (const char *name, const __u8 *buf, int count)
  122. {
  123. __u8 line[44];
  124. if (name != NULL)
  125. printk(KERN_DEBUG "ppp_synctty: %s, count = %dn", name, count);
  126. while (count > 8) {
  127. memset (line, 32, 44);
  128. ppp_print_hex (line, buf, 8);
  129. ppp_print_char (&line[8 * 3], buf, 8);
  130. printk(KERN_DEBUG "%sn", line);
  131. count -= 8;
  132. buf += 8;
  133. }
  134. if (count > 0) {
  135. memset (line, 32, 44);
  136. ppp_print_hex (line, buf, count);
  137. ppp_print_char (&line[8 * 3], buf, count);
  138. printk(KERN_DEBUG "%sn", line);
  139. }
  140. }
  141. /*
  142.  * Routines implementing the synchronous PPP line discipline.
  143.  */
  144. /*
  145.  * We have a potential race on dereferencing tty->disc_data,
  146.  * because the tty layer provides no locking at all - thus one
  147.  * cpu could be running ppp_synctty_receive while another
  148.  * calls ppp_synctty_close, which zeroes tty->disc_data and
  149.  * frees the memory that ppp_synctty_receive is using.  The best
  150.  * way to fix this is to use a rwlock in the tty struct, but for now
  151.  * we use a single global rwlock for all ttys in ppp line discipline.
  152.  */
  153. static rwlock_t disc_data_lock = RW_LOCK_UNLOCKED;
  154. static struct syncppp *sp_get(struct tty_struct *tty)
  155. {
  156. struct syncppp *ap;
  157. read_lock(&disc_data_lock);
  158. ap = tty->disc_data;
  159. if (ap != NULL)
  160. atomic_inc(&ap->refcnt);
  161. read_unlock(&disc_data_lock);
  162. return ap;
  163. }
  164. static void sp_put(struct syncppp *ap)
  165. {
  166. if (atomic_dec_and_test(&ap->refcnt))
  167. up(&ap->dead_sem);
  168. }
  169. /*
  170.  * Called when a tty is put into sync-PPP line discipline.
  171.  */
  172. static int
  173. ppp_sync_open(struct tty_struct *tty)
  174. {
  175. struct syncppp *ap;
  176. int err;
  177. MOD_INC_USE_COUNT;
  178. ap = kmalloc(sizeof(*ap), GFP_KERNEL);
  179. err = -ENOMEM;
  180. if (ap == 0)
  181. goto out;
  182. /* initialize the syncppp structure */
  183. memset(ap, 0, sizeof(*ap));
  184. ap->tty = tty;
  185. ap->mru = PPP_MRU;
  186. spin_lock_init(&ap->xmit_lock);
  187. spin_lock_init(&ap->recv_lock);
  188. ap->xaccm[0] = ~0U;
  189. ap->xaccm[3] = 0x60000000U;
  190. ap->raccm = ~0U;
  191. atomic_set(&ap->refcnt, 1);
  192. init_MUTEX_LOCKED(&ap->dead_sem);
  193. ap->chan.private = ap;
  194. ap->chan.ops = &sync_ops;
  195. ap->chan.mtu = PPP_MRU;
  196. ap->chan.hdrlen = 2; /* for A/C bytes */
  197. err = ppp_register_channel(&ap->chan);
  198. if (err)
  199. goto out_free;
  200. tty->disc_data = ap;
  201. return 0;
  202.  out_free:
  203. kfree(ap);
  204.  out:
  205. MOD_DEC_USE_COUNT;
  206. return err;
  207. }
  208. /*
  209.  * Called when the tty is put into another line discipline
  210.  * or it hangs up.  We have to wait for any cpu currently
  211.  * executing in any of the other ppp_synctty_* routines to
  212.  * finish before we can call ppp_unregister_channel and free
  213.  * the syncppp struct.  This routine must be called from
  214.  * process context, not interrupt or softirq context.
  215.  */
  216. static void
  217. ppp_sync_close(struct tty_struct *tty)
  218. {
  219. struct syncppp *ap;
  220. write_lock(&disc_data_lock);
  221. ap = tty->disc_data;
  222. tty->disc_data = 0;
  223. write_unlock(&disc_data_lock);
  224. if (ap == 0)
  225. return;
  226. /*
  227.  * We have now ensured that nobody can start using ap from now
  228.  * on, but we have to wait for all existing users to finish.
  229.  * Note that ppp_unregister_channel ensures that no calls to
  230.  * our channel ops (i.e. ppp_sync_send/ioctl) are in progress
  231.  * by the time it returns.
  232.  */
  233. if (!atomic_dec_and_test(&ap->refcnt))
  234. down(&ap->dead_sem);
  235. ppp_unregister_channel(&ap->chan);
  236. if (ap->rpkt != 0)
  237. kfree_skb(ap->rpkt);
  238. if (ap->tpkt != 0)
  239. kfree_skb(ap->tpkt);
  240. kfree(ap);
  241. MOD_DEC_USE_COUNT;
  242. }
  243. /*
  244.  * Read does nothing - no data is ever available this way.
  245.  * Pppd reads and writes packets via /dev/ppp instead.
  246.  */
  247. static ssize_t
  248. ppp_sync_read(struct tty_struct *tty, struct file *file,
  249.        unsigned char *buf, size_t count)
  250. {
  251. return -EAGAIN;
  252. }
  253. /*
  254.  * Write on the tty does nothing, the packets all come in
  255.  * from the ppp generic stuff.
  256.  */
  257. static ssize_t
  258. ppp_sync_write(struct tty_struct *tty, struct file *file,
  259. const unsigned char *buf, size_t count)
  260. {
  261. return -EAGAIN;
  262. }
  263. static int
  264. ppp_synctty_ioctl(struct tty_struct *tty, struct file *file,
  265.   unsigned int cmd, unsigned long arg)
  266. {
  267. struct syncppp *ap = sp_get(tty);
  268. int err, val;
  269. if (ap == 0)
  270. return -ENXIO;
  271. err = -EFAULT;
  272. switch (cmd) {
  273. case PPPIOCGCHAN:
  274. err = -ENXIO;
  275. if (ap == 0)
  276. break;
  277. err = -EFAULT;
  278. if (put_user(ppp_channel_index(&ap->chan), (int *) arg))
  279. break;
  280. err = 0;
  281. break;
  282. case PPPIOCGUNIT:
  283. err = -ENXIO;
  284. if (ap == 0)
  285. break;
  286. err = -EFAULT;
  287. if (put_user(ppp_unit_number(&ap->chan), (int *) arg))
  288. break;
  289. err = 0;
  290. break;
  291. case TCGETS:
  292. case TCGETA:
  293. err = n_tty_ioctl(tty, file, cmd, arg);
  294. break;
  295. case TCFLSH:
  296. /* flush our buffers and the serial port's buffer */
  297. if (arg == TCIOFLUSH || arg == TCOFLUSH)
  298. ppp_sync_flush_output(ap);
  299. err = n_tty_ioctl(tty, file, cmd, arg);
  300. break;
  301. case FIONREAD:
  302. val = 0;
  303. if (put_user(val, (int *) arg))
  304. break;
  305. err = 0;
  306. break;
  307. default:
  308. err = -ENOIOCTLCMD;
  309. }
  310. sp_put(ap);
  311. return err;
  312. }
  313. /* No kernel lock - fine */
  314. static unsigned int
  315. ppp_sync_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
  316. {
  317. return 0;
  318. }
  319. static int
  320. ppp_sync_room(struct tty_struct *tty)
  321. {
  322. return 65535;
  323. }
  324. static void
  325. ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf,
  326.   char *flags, int count)
  327. {
  328. struct syncppp *ap = sp_get(tty);
  329. if (ap == 0)
  330. return;
  331. spin_lock_bh(&ap->recv_lock);
  332. ppp_sync_input(ap, buf, flags, count);
  333. spin_unlock_bh(&ap->recv_lock);
  334. sp_put(ap);
  335. if (test_and_clear_bit(TTY_THROTTLED, &tty->flags)
  336.     && tty->driver.unthrottle)
  337. tty->driver.unthrottle(tty);
  338. }
  339. static void
  340. ppp_sync_wakeup(struct tty_struct *tty)
  341. {
  342. struct syncppp *ap = sp_get(tty);
  343. clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
  344. if (ap == 0)
  345. return;
  346. if (ppp_sync_push(ap))
  347. ppp_output_wakeup(&ap->chan);
  348. sp_put(ap);
  349. }
  350. static struct tty_ldisc ppp_sync_ldisc = {
  351. magic: TTY_LDISC_MAGIC,
  352. name: "pppsync",
  353. open: ppp_sync_open,
  354. close: ppp_sync_close,
  355. read: ppp_sync_read,
  356. write: ppp_sync_write,
  357. ioctl: ppp_synctty_ioctl,
  358. poll: ppp_sync_poll,
  359. receive_room: ppp_sync_room,
  360. receive_buf: ppp_sync_receive,
  361. write_wakeup: ppp_sync_wakeup,
  362. };
  363. static int __init
  364. ppp_sync_init(void)
  365. {
  366. int err;
  367. err = tty_register_ldisc(N_SYNC_PPP, &ppp_sync_ldisc);
  368. if (err != 0)
  369. printk(KERN_ERR "PPP_sync: error %d registering line disc.n",
  370.        err);
  371. return err;
  372. }
  373. /*
  374.  * The following routines provide the PPP channel interface.
  375.  */
  376. static int
  377. ppp_sync_ioctl(struct ppp_channel *chan, unsigned int cmd, unsigned long arg)
  378. {
  379. struct syncppp *ap = chan->private;
  380. int err, val;
  381. u32 accm[8];
  382. err = -EFAULT;
  383. switch (cmd) {
  384. case PPPIOCGFLAGS:
  385. val = ap->flags | ap->rbits;
  386. if (put_user(val, (int *) arg))
  387. break;
  388. err = 0;
  389. break;
  390. case PPPIOCSFLAGS:
  391. if (get_user(val, (int *) arg))
  392. break;
  393. ap->flags = val & ~SC_RCV_BITS;
  394. spin_lock_bh(&ap->recv_lock);
  395. ap->rbits = val & SC_RCV_BITS;
  396. spin_unlock_bh(&ap->recv_lock);
  397. err = 0;
  398. break;
  399. case PPPIOCGASYNCMAP:
  400. if (put_user(ap->xaccm[0], (u32 *) arg))
  401. break;
  402. err = 0;
  403. break;
  404. case PPPIOCSASYNCMAP:
  405. if (get_user(ap->xaccm[0], (u32 *) arg))
  406. break;
  407. err = 0;
  408. break;
  409. case PPPIOCGRASYNCMAP:
  410. if (put_user(ap->raccm, (u32 *) arg))
  411. break;
  412. err = 0;
  413. break;
  414. case PPPIOCSRASYNCMAP:
  415. if (get_user(ap->raccm, (u32 *) arg))
  416. break;
  417. err = 0;
  418. break;
  419. case PPPIOCGXASYNCMAP:
  420. if (copy_to_user((void *) arg, ap->xaccm, sizeof(ap->xaccm)))
  421. break;
  422. err = 0;
  423. break;
  424. case PPPIOCSXASYNCMAP:
  425. if (copy_from_user(accm, (void *) arg, sizeof(accm)))
  426. break;
  427. accm[2] &= ~0x40000000U; /* can't escape 0x5e */
  428. accm[3] |= 0x60000000U; /* must escape 0x7d, 0x7e */
  429. memcpy(ap->xaccm, accm, sizeof(ap->xaccm));
  430. err = 0;
  431. break;
  432. case PPPIOCGMRU:
  433. if (put_user(ap->mru, (int *) arg))
  434. break;
  435. err = 0;
  436. break;
  437. case PPPIOCSMRU:
  438. if (get_user(val, (int *) arg))
  439. break;
  440. if (val < PPP_MRU)
  441. val = PPP_MRU;
  442. ap->mru = val;
  443. err = 0;
  444. break;
  445. default:
  446. err = -ENOTTY;
  447. }
  448. return err;
  449. }
  450. /*
  451.  * Procedures for encapsulation and framing.
  452.  */
  453. struct sk_buff*
  454. ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb)
  455. {
  456. int proto;
  457. unsigned char *data;
  458. int islcp;
  459. data  = skb->data;
  460. proto = (data[0] << 8) + data[1];
  461. /* LCP packets with codes between 1 (configure-request)
  462.  * and 7 (code-reject) must be sent as though no options
  463.  * have been negotiated.
  464.  */
  465. islcp = proto == PPP_LCP && 1 <= data[2] && data[2] <= 7;
  466. /* compress protocol field if option enabled */
  467. if (data[0] == 0 && (ap->flags & SC_COMP_PROT) && !islcp)
  468. skb_pull(skb,1);
  469. /* prepend address/control fields if necessary */
  470. if ((ap->flags & SC_COMP_AC) == 0 || islcp) {
  471. if (skb_headroom(skb) < 2) {
  472. struct sk_buff *npkt = dev_alloc_skb(skb->len + 2);
  473. if (npkt == NULL) {
  474. kfree_skb(skb);
  475. return NULL;
  476. }
  477. skb_reserve(npkt,2);
  478. memcpy(skb_put(npkt,skb->len), skb->data, skb->len);
  479. kfree_skb(skb);
  480. skb = npkt;
  481. }
  482. skb_push(skb,2);
  483. skb->data[0] = PPP_ALLSTATIONS;
  484. skb->data[1] = PPP_UI;
  485. }
  486. ap->last_xmit = jiffies;
  487. if (skb && ap->flags & SC_LOG_OUTPKT)
  488. ppp_print_buffer ("send buffer", skb->data, skb->len);
  489. return skb;
  490. }
  491. /*
  492.  * Transmit-side routines.
  493.  */
  494. /*
  495.  * Send a packet to the peer over an sync tty line.
  496.  * Returns 1 iff the packet was accepted.
  497.  * If the packet was not accepted, we will call ppp_output_wakeup
  498.  * at some later time.
  499.  */
  500. static int
  501. ppp_sync_send(struct ppp_channel *chan, struct sk_buff *skb)
  502. {
  503. struct syncppp *ap = chan->private;
  504. ppp_sync_push(ap);
  505. if (test_and_set_bit(XMIT_FULL, &ap->xmit_flags))
  506. return 0; /* already full */
  507. skb = ppp_sync_txmunge(ap, skb);
  508. if (skb != NULL)
  509. ap->tpkt = skb;
  510. else
  511. clear_bit(XMIT_FULL, &ap->xmit_flags);
  512. ppp_sync_push(ap);
  513. return 1;
  514. }
  515. /*
  516.  * Push as much data as possible out to the tty.
  517.  */
  518. static int
  519. ppp_sync_push(struct syncppp *ap)
  520. {
  521. int sent, done = 0;
  522. struct tty_struct *tty = ap->tty;
  523. int tty_stuffed = 0;
  524. set_bit(XMIT_WAKEUP, &ap->xmit_flags);
  525. if (!spin_trylock_bh(&ap->xmit_lock))
  526. return 0;
  527. for (;;) {
  528. if (test_and_clear_bit(XMIT_WAKEUP, &ap->xmit_flags))
  529. tty_stuffed = 0;
  530. if (!tty_stuffed && ap->tpkt != 0) {
  531. set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
  532. sent = tty->driver.write(tty, 0, ap->tpkt->data, ap->tpkt->len);
  533. if (sent < 0)
  534. goto flush; /* error, e.g. loss of CD */
  535. if (sent < ap->tpkt->len) {
  536. tty_stuffed = 1;
  537. } else {
  538. kfree_skb(ap->tpkt);
  539. ap->tpkt = 0;
  540. clear_bit(XMIT_FULL, &ap->xmit_flags);
  541. done = 1;
  542. }
  543. continue;
  544. }
  545. /* haven't made any progress */
  546. spin_unlock_bh(&ap->xmit_lock);
  547. if (!(test_bit(XMIT_WAKEUP, &ap->xmit_flags)
  548.       || (!tty_stuffed && ap->tpkt != 0)))
  549. break;
  550. if (!spin_trylock_bh(&ap->xmit_lock))
  551. break;
  552. }
  553. return done;
  554. flush:
  555. if (ap->tpkt != 0) {
  556. kfree_skb(ap->tpkt);
  557. ap->tpkt = 0;
  558. clear_bit(XMIT_FULL, &ap->xmit_flags);
  559. done = 1;
  560. }
  561. spin_unlock_bh(&ap->xmit_lock);
  562. return done;
  563. }
  564. /*
  565.  * Flush output from our internal buffers.
  566.  * Called for the TCFLSH ioctl.
  567.  */
  568. static void
  569. ppp_sync_flush_output(struct syncppp *ap)
  570. {
  571. int done = 0;
  572. spin_lock_bh(&ap->xmit_lock);
  573. if (ap->tpkt != NULL) {
  574. kfree_skb(ap->tpkt);
  575. ap->tpkt = 0;
  576. clear_bit(XMIT_FULL, &ap->xmit_flags);
  577. done = 1;
  578. }
  579. spin_unlock_bh(&ap->xmit_lock);
  580. if (done)
  581. ppp_output_wakeup(&ap->chan);
  582. }
  583. /*
  584.  * Receive-side routines.
  585.  */
  586. static inline void
  587. process_input_packet(struct syncppp *ap)
  588. {
  589. struct sk_buff *skb;
  590. unsigned char *p;
  591. int code = 0;
  592. skb = ap->rpkt;
  593. ap->rpkt = 0;
  594. /* strip address/control field if present */
  595. p = skb->data;
  596. if (p[0] == PPP_ALLSTATIONS && p[1] == PPP_UI) {
  597. /* chop off address/control */
  598. if (skb->len < 3)
  599. goto err;
  600. p = skb_pull(skb, 2);
  601. }
  602. /* decompress protocol field if compressed */
  603. if (p[0] & 1) {
  604. /* protocol is compressed */
  605. skb_push(skb, 1)[0] = 0;
  606. } else if (skb->len < 2)
  607. goto err;
  608. /* pass to generic layer */
  609. ppp_input(&ap->chan, skb);
  610. return;
  611.  err:
  612. kfree_skb(skb);
  613. ppp_input_error(&ap->chan, code);
  614. }
  615. /* called when the tty driver has data for us. 
  616.  *
  617.  * Data is frame oriented: each call to ppp_sync_input is considered
  618.  * a whole frame. If the 1st flag byte is non-zero then the whole
  619.  * frame is considered to be in error and is tossed.
  620.  */
  621. static void
  622. ppp_sync_input(struct syncppp *ap, const unsigned char *buf,
  623. char *flags, int count)
  624. {
  625. struct sk_buff *skb;
  626. unsigned char *sp;
  627. if (count == 0)
  628. return;
  629. /* if flag set, then error, ignore frame */
  630. if (flags != 0 && *flags) {
  631. ppp_input_error(&ap->chan, *flags);
  632. return;
  633. }
  634. if (ap->flags & SC_LOG_INPKT)
  635. ppp_print_buffer ("receive buffer", buf, count);
  636. /* stuff the chars in the skb */
  637. if ((skb = ap->rpkt) == 0) {
  638. if ((skb = dev_alloc_skb(ap->mru + PPP_HDRLEN + 2)) == 0) {
  639. printk(KERN_ERR "PPPsync: no memory (input pkt)n");
  640. ppp_input_error(&ap->chan, 0);
  641. return;
  642. }
  643. /* Try to get the payload 4-byte aligned */
  644. if (buf[0] != PPP_ALLSTATIONS)
  645. skb_reserve(skb, 2 + (buf[0] & 1));
  646. ap->rpkt = skb;
  647. }
  648. if (count > skb_tailroom(skb)) {
  649. /* packet overflowed MRU */
  650. ppp_input_error(&ap->chan, 1);
  651. } else {
  652. sp = skb_put(skb, count);
  653. memcpy(sp, buf, count);
  654. process_input_packet(ap);
  655. }
  656. }
  657. static void __exit
  658. ppp_sync_cleanup(void)
  659. {
  660. if (tty_register_ldisc(N_SYNC_PPP, NULL) != 0)
  661. printk(KERN_ERR "failed to unregister Sync PPP line disciplinen");
  662. }
  663. module_init(ppp_sync_init);
  664. module_exit(ppp_sync_cleanup);
  665. MODULE_LICENSE("GPL");