root/drivers/net/slip.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sl_alloc
  2. sl_free
  3. sl_changedmtu
  4. sl_lock
  5. sl_unlock
  6. sl_bump
  7. sl_encaps
  8. slip_write_wakeup
  9. sl_xmit
  10. sl_header
  11. sl_rebuild_header
  12. sl_open
  13. sl_close
  14. slip_receive_room
  15. slip_receive_buf
  16. slip_open
  17. slip_close
  18. sl_get_stats
  19. slip_esc
  20. slip_unesc
  21. slip_esc6
  22. slip_unesc6
  23. sl_set_mac_address
  24. sl_set_dev_mac_address
  25. slip_ioctl
  26. sl_open_dev
  27. slip_init_ctrl_dev
  28. slip_init
  29. init_module
  30. cleanup_module

   1 /*
   2  * slip.c       This module implements the SLIP protocol for kernel-based
   3  *              devices like TTY.  It interfaces between a raw TTY, and the
   4  *              kernel's INET protocol layers.
   5  *
   6  * Version:     @(#)slip.c      0.8.3   12/24/94
   7  *
   8  * Authors:     Laurence Culhane, <loz@holmes.demon.co.uk>
   9  *              Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  10  *
  11  * Fixes:
  12  *              Alan Cox        :       Sanity checks and avoid tx overruns.
  13  *                                      Has a new sl->mtu field.
  14  *              Alan Cox        :       Found cause of overrun. ifconfig sl0 mtu upwards.
  15  *                                      Driver now spots this and grows/shrinks its buffers(hack!).
  16  *                                      Memory leak if you run out of memory setting up a slip driver fixed.
  17  *              Matt Dillon     :       Printable slip (borrowed from NET2E)
  18  *      Pauline Middelink       :       Slip driver fixes.
  19  *              Alan Cox        :       Honours the old SL_COMPRESSED flag
  20  *              Alan Cox        :       KISS AX.25 and AXUI IP support
  21  *              Michael Riepe   :       Automatic CSLIP recognition added
  22  *              Charles Hedrick :       CSLIP header length problem fix.
  23  *              Alan Cox        :       Corrected non-IP cases of the above.
  24  *              Alan Cox        :       Now uses hardware type as per FvK.
  25  *              Alan Cox        :       Default to 192.168.0.0 (RFC 1597)
  26  *              A.N.Kuznetsov   :       dev_tint() recursion fix.
  27  *      Dmitry Gorodchanin      :       SLIP memory leaks
  28  *      Dmitry Gorodchanin      :       Code cleanup. Reduce tty driver
  29  *                                      buffering from 4096 to 256 bytes.
  30  *                                      Improving SLIP response time.
  31  *                                      CONFIG_SLIP_MODE_SLIP6.
  32  *                                      ifconfig sl? up & down now works correctly.
  33  *                                      Modularization.
  34  *              Alan Cox        :       Oops - fix AX.25 buffer lengths
  35  *      Dmitry Gorodchanin      :       Even more cleanups. Preserve CSLIP
  36  *                                      statistics. Include CSLIP code only
  37  *                                      if it really needed.
  38  *              Alan Cox        :       Free slhc buffers in the right place.
  39  *              Alan Cox        :       Allow for digipeated IP over AX.25
  40  *              Matti Aarnio    :       Dynamic SLIP devices, with ideas taken
  41  *                                      from Jim Freeman's <jfree@caldera.com>
  42  *                                      dynamic PPP devices.  We do NOT kfree()
  43  *                                      device entries, just reg./unreg. them
  44  *                                      as they are needed.  We kfree() them
  45  *                                      at module cleanup.
  46  *                                      With MODULE-loading ``insmod'', user can
  47  *                                      issue parameter:   slip_maxdev=1024
  48  *                                      (Or how much he/she wants.. Default is 256)
  49  *
  50  */
  51 
  52 #define SL_CHECK_TRANSMIT
  53 #include <linux/config.h>
  54 #ifdef MODULE
  55 #include <linux/module.h>
  56 #include <linux/version.h>
  57 #endif
  58 
  59 /* Undef this, if you don't need 6bit encapsulation code in the driver */
  60 #define CONFIG_SLIP_MODE_SLIP6
  61 
  62 #include <asm/system.h>
  63 #include <asm/segment.h>
  64 #include <asm/bitops.h>
  65 #include <linux/string.h>
  66 #include <linux/mm.h>
  67 #include <linux/interrupt.h>
  68 #include <linux/in.h>
  69 #include <linux/tty.h>
  70 #include <linux/errno.h>
  71 #include <linux/netdevice.h>
  72 #ifdef CONFIG_AX25
  73 #include <linux/timer.h>
  74 #include <net/ax25.h>
  75 #endif
  76 #include <linux/etherdevice.h>
  77 #include <linux/skbuff.h>
  78 #include <linux/if_arp.h>
  79 #include "slip.h"
  80 #ifdef CONFIG_INET
  81 #include <linux/ip.h>
  82 #include <linux/tcp.h>
  83 #include "slhc.h"
  84 #endif
  85 
  86 #ifdef MODULE
  87 #define SLIP_VERSION    "0.8.3-NET3.019-NEWTTY-MODULAR"
  88 #else
  89 #define SLIP_VERSION    "0.8.3-NET3.019-NEWTTY"
  90 #endif
  91 
  92 
  93 typedef struct slip_ctrl {
  94         char            if_name[8];     /* "sl0\0" .. "sl99999\0"       */
  95         struct slip     ctrl;           /* SLIP things                  */
  96         struct device   dev;            /* the device                   */
  97 } slip_ctrl_t;
  98 static slip_ctrl_t      **slip_ctrls = NULL;
  99 int slip_maxdev = SL_NRUNIT;            /* Can be overridden with insmod! */
 100 
 101 static struct tty_ldisc sl_ldisc;
 102 
 103 static int slip_esc(unsigned char *p, unsigned char *d, int len);
 104 static void slip_unesc(struct slip *sl, unsigned char c);
 105 #ifdef CONFIG_SLIP_MODE_SLIP6
 106 static int slip_esc6(unsigned char *p, unsigned char *d, int len);
 107 static void slip_unesc6(struct slip *sl, unsigned char c);
 108 #endif
 109 
 110 
 111 /* Find a free SLIP channel, and link in this `tty' line. */
 112 static inline struct slip *
 113 sl_alloc(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 114 {
 115         slip_ctrl_t *slp;
 116         int i;
 117 
 118         if (slip_ctrls == NULL) return NULL;    /* Master array missing ! */
 119 
 120         for (i = 0; i < slip_maxdev; i++) {
 121           slp = slip_ctrls[i];
 122           /* Not allocated ? */
 123           if (slp == NULL)
 124             break;
 125           /* Not in use ? */
 126           if (!set_bit(SLF_INUSE, &slp->ctrl.flags))
 127             break;
 128         }
 129         /* SLP is set.. */
 130 
 131         /* Sorry, too many, all slots in use */
 132         if (i >= slip_maxdev) return NULL;
 133 
 134         /* If no channels are available, allocate one */
 135         if (!slp &&
 136             (slip_ctrls[i] = (slip_ctrl_t *)kmalloc(sizeof(slip_ctrl_t),
 137                                                     GFP_KERNEL)) != NULL) {
 138           slp = slip_ctrls[i];
 139           memset(slp, 0, sizeof(slip_ctrl_t));
 140 
 141           /* Initialize channel control data */
 142           set_bit(SLF_INUSE, &slp->ctrl.flags);
 143           slp->ctrl.tty         = NULL;
 144           sprintf(slp->if_name, "sl%d", i);
 145           slp->dev.name         = slp->if_name;
 146           slp->dev.base_addr    = i;
 147           slp->dev.priv         = (void*)&(slp->ctrl);
 148           slp->dev.next         = NULL;
 149           slp->dev.init         = slip_init;
 150 /* printk(KERN_INFO "slip: kmalloc()ed SLIP control node for line %s\n",
 151    slp->if_name); */
 152         }
 153         if (slp != NULL) {
 154 
 155           /* register device so that it can be ifconfig'ed       */
 156           /* slip_init() will be called as a side-effect         */
 157           /* SIDE-EFFECT WARNING: slip_init() CLEARS slp->ctrl ! */
 158 
 159           if (register_netdev(&(slp->dev)) == 0) {
 160             /* (Re-)Set the INUSE bit.   Very Important! */
 161             set_bit(SLF_INUSE, &slp->ctrl.flags);
 162             slp->ctrl.dev = &(slp->dev);
 163             slp->dev.priv = (void*)&(slp->ctrl);
 164 
 165 /* printk(KERN_INFO "slip: linked in netdev %s for active use\n",
 166    slp->if_name); */
 167 
 168             return (&(slp->ctrl));
 169 
 170           } else {
 171             clear_bit(SLF_INUSE,&(slp->ctrl.flags));
 172             printk("sl_alloc() - register_netdev() failure.\n");
 173           }
 174         }
 175 
 176         return NULL;
 177 }
 178 
 179 
 180 /* Free a SLIP channel. */
 181 static inline void
 182 sl_free(struct slip *sl)
     /* [previous][next][first][last][top][bottom][index][help] */
 183 {
 184         /* Free all SLIP frame buffers. */
 185         if (sl->rbuff)  {
 186                 kfree(sl->rbuff);
 187         }
 188         sl->rbuff = NULL;
 189         if (sl->xbuff)  {
 190                 kfree(sl->xbuff);
 191         }
 192         sl->xbuff = NULL;
 193 #ifdef SL_INCLUDE_CSLIP
 194         /* Save CSLIP statistics */
 195         if (sl->slcomp)  {
 196                 sl->rx_compressed += sl->slcomp->sls_i_compressed;
 197                 sl->rx_dropped    += sl->slcomp->sls_i_tossed;
 198                 sl->tx_compressed += sl->slcomp->sls_o_compressed;
 199                 sl->tx_misses     += sl->slcomp->sls_o_misses;
 200         }
 201         if (sl->cbuff)  {
 202                 kfree(sl->cbuff);
 203         }
 204         sl->cbuff = NULL;
 205         if(sl->slcomp)
 206                 slhc_free(sl->slcomp);
 207         sl->slcomp = NULL;
 208 #endif
 209 
 210         if (!clear_bit(SLF_INUSE, &sl->flags)) {
 211                 printk("%s: sl_free for already free unit.\n", sl->dev->name);
 212         }
 213 }
 214 
 215 /* MTU has been changed by the IP layer. Unfortunately we are not told
 216    about this, but we spot it ourselves and fix things up. We could be
 217    in an upcall from the tty driver, or in an ip packet queue. */
 218 
 219 static void sl_changedmtu(struct slip *sl)
     /* [previous][next][first][last][top][bottom][index][help] */
 220 {
 221         struct device *dev = sl->dev;
 222         unsigned char *xbuff, *rbuff, *oxbuff, *orbuff;
 223 #ifdef SL_INCLUDE_CSLIP
 224         unsigned char *cbuff, *ocbuff;
 225 #endif
 226         int len;
 227         unsigned long flags;
 228 
 229         len = dev->mtu * 2;
 230 /*
 231  * allow for arrival of larger UDP packets, even if we say not to
 232  * also fixes a bug in which SunOS sends 512-byte packets even with
 233  * an MSS of 128
 234  */
 235         if (len < 576 * 2)  {
 236                 len = 576 * 2;
 237         }
 238 
 239         xbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC);
 240         rbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC);
 241 #ifdef SL_INCLUDE_CSLIP
 242         cbuff = (unsigned char *) kmalloc (len + 4, GFP_ATOMIC);
 243 #endif
 244 
 245 #ifdef SL_INCLUDE_CSLIP
 246         if (xbuff == NULL || rbuff == NULL || cbuff == NULL)  {
 247 #else
 248         if (xbuff == NULL || rbuff == NULL)  {
 249 #endif
 250                 printk("%s: unable to grow slip buffers, MTU change cancelled.\n",
 251                        sl->dev->name);
 252                 dev->mtu = sl->mtu;
 253                 if (xbuff != NULL)  {
 254                         kfree(xbuff);
 255                 }
 256                 if (rbuff != NULL)  {
 257                         kfree(rbuff);
 258                 }
 259 #ifdef SL_INCLUDE_CSLIP
 260                 if (cbuff != NULL)  {
 261                         kfree(cbuff);
 262                 }
 263 #endif
 264                 return;
 265         }
 266 
 267         save_flags(flags); cli();
 268 
 269         oxbuff    = sl->xbuff;
 270         sl->xbuff = xbuff;
 271         orbuff    = sl->rbuff;
 272         sl->rbuff = rbuff;
 273 #ifdef SL_INCLUDE_CSLIP
 274         ocbuff    = sl->cbuff;
 275         sl->cbuff = cbuff;
 276 #endif
 277         if (sl->xleft)  {
 278                 if (sl->xleft <= len)  {
 279                         memcpy(sl->xbuff, sl->xhead, sl->xleft);
 280                 } else  {
 281                         sl->xleft = 0;
 282                         sl->tx_dropped++;
 283                 }
 284         }
 285         sl->xhead = sl->xbuff;
 286 
 287         if (sl->rcount)  {
 288                 if (sl->rcount <= len) {
 289                         memcpy(sl->rbuff, orbuff, sl->rcount);
 290                 } else  {
 291                         sl->rcount = 0;
 292                         sl->rx_over_errors++;
 293                         set_bit(SLF_ERROR, &sl->flags);
 294                 }
 295         }
 296 #ifdef CONFIG_AX25
 297         sl->mtu      = dev->mtu + 73;
 298 #else
 299         sl->mtu      = dev->mtu;
 300 #endif
 301         sl->buffsize = len;
 302 
 303         restore_flags(flags);
 304 
 305         if (oxbuff != NULL)   {
 306                 kfree(oxbuff);
 307         }
 308         if (orbuff != NULL)    {
 309                 kfree(orbuff);
 310         }
 311 #ifdef SL_INCLUDE_CSLIP
 312         if (ocbuff != NULL)  {
 313                 kfree(ocbuff);
 314         }
 315 #endif
 316 }
 317 
 318 
 319 /* Set the "sending" flag.  This must be atomic, hence the ASM. */
 320 static inline void
 321 sl_lock(struct slip *sl)
     /* [previous][next][first][last][top][bottom][index][help] */
 322 {
 323         if (set_bit(0, (void *) &sl->dev->tbusy))  {
 324                 printk("%s: trying to lock already locked device!\n", sl->dev->name);
 325         }
 326 }
 327 
 328 
 329 /* Clear the "sending" flag.  This must be atomic, hence the ASM. */
 330 static inline void
 331 sl_unlock(struct slip *sl)
     /* [previous][next][first][last][top][bottom][index][help] */
 332 {
 333         if (!clear_bit(0, (void *)&sl->dev->tbusy))  {
 334                 printk("%s: trying to unlock already unlocked device!\n", sl->dev->name);
 335         }
 336 }
 337 
 338 /* Send one completely decapsulated IP datagram to the IP layer. */
 339 static void
 340 sl_bump(struct slip *sl)
     /* [previous][next][first][last][top][bottom][index][help] */
 341 {
 342         struct sk_buff *skb;
 343         int count;
 344 
 345         count = sl->rcount;
 346 #ifdef SL_INCLUDE_CSLIP
 347         if (sl->mode & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) {
 348                 unsigned char c;
 349                 if ((c = sl->rbuff[0]) & SL_TYPE_COMPRESSED_TCP) {
 350                         /* ignore compressed packets when CSLIP is off */
 351                         if (!(sl->mode & SL_MODE_CSLIP)) {
 352                                 printk("%s: compressed packet ignored\n", sl->dev->name);
 353                                 return;
 354                         }
 355                         /* make sure we've reserved enough space for uncompress to use */
 356                         if (count + 80 > sl->buffsize) {
 357                                 sl->rx_over_errors++;
 358                                 return;
 359                         }
 360                         count = slhc_uncompress(sl->slcomp, sl->rbuff, count);
 361                         if (count <= 0) {
 362                                 return;
 363                         }
 364                 } else if (c >= SL_TYPE_UNCOMPRESSED_TCP) {
 365                         if (!(sl->mode & SL_MODE_CSLIP)) {
 366                                 /* turn on header compression */
 367                                 sl->mode |= SL_MODE_CSLIP;
 368                                 sl->mode &= ~SL_MODE_ADAPTIVE;
 369                                 printk("%s: header compression turned on\n", sl->dev->name);
 370                         }
 371                         sl->rbuff[0] &= 0x4f;
 372                         if (slhc_remember(sl->slcomp, sl->rbuff, count) <= 0) {
 373                                 return;
 374                         }
 375                 }
 376         }
 377 #endif  /* SL_INCLUDE_CSLIP */
 378 
 379         skb = dev_alloc_skb(count);
 380         if (skb == NULL)  {
 381                 printk("%s: memory squeeze, dropping packet.\n", sl->dev->name);
 382                 sl->rx_dropped++;
 383                 return;
 384         }
 385         skb->dev = sl->dev;
 386         memcpy(skb_put(skb,count), sl->rbuff, count);
 387         skb->mac.raw=skb->data;
 388         if(sl->mode & SL_MODE_AX25)
 389                 skb->protocol=htons(ETH_P_AX25);
 390         else
 391                 skb->protocol=htons(ETH_P_IP);
 392         netif_rx(skb);
 393         sl->rx_packets++;
 394 }
 395 
 396 /* Encapsulate one IP datagram and stuff into a TTY queue. */
 397 static void
 398 sl_encaps(struct slip *sl, unsigned char *icp, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 399 {
 400         unsigned char *p;
 401         int actual, count;
 402 
 403 
 404 #ifdef CONFIG_AX25
 405         if (sl->mtu != sl->dev->mtu + 73) {     /* Someone has been ifconfigging */
 406 #else
 407         if (sl->mtu != sl->dev->mtu) {  /* Someone has been ifconfigging */
 408 #endif
 409                 sl_changedmtu(sl);
 410         }
 411 
 412         if (len > sl->mtu) {            /* Sigh, shouldn't occur BUT ... */
 413                 len = sl->mtu;
 414                 printk ("%s: truncating oversized transmit packet!\n", sl->dev->name);
 415                 sl->tx_dropped++;
 416                 sl_unlock(sl);
 417                 return;
 418         }
 419 
 420         p = icp;
 421 #ifdef SL_INCLUDE_CSLIP
 422         if (sl->mode & SL_MODE_CSLIP)  {
 423                 len = slhc_compress(sl->slcomp, p, len, sl->cbuff, &p, 1);
 424         }
 425 #endif
 426 #ifdef CONFIG_SLIP_MODE_SLIP6
 427         if(sl->mode & SL_MODE_SLIP6)
 428                 count = slip_esc6(p, (unsigned char *) sl->xbuff, len);
 429         else
 430 #endif
 431                 count = slip_esc(p, (unsigned char *) sl->xbuff, len);
 432 
 433         /* Order of next two lines is *very* important.
 434          * When we are sending a little amount of data,
 435          * the transfer may be completed inside driver.write()
 436          * routine, because it's running with interrupts enabled.
 437          * In this case we *never* got WRITE_WAKEUP event,
 438          * if we did not request it before write operation.
 439          *       14 Oct 1994  Dmitry Gorodchanin.
 440          */
 441         sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
 442         actual = sl->tty->driver.write(sl->tty, 0, sl->xbuff, count);
 443 #ifdef SL_CHECK_TRANSMIT
 444         sl->dev->trans_start = jiffies;
 445 #endif
 446         sl->xleft = count - actual;
 447         sl->xhead = sl->xbuff + actual;
 448 }
 449 
 450 /*
 451  * Called by the driver when there's room for more data.  If we have
 452  * more packets to send, we send them here.
 453  */
 454 static void slip_write_wakeup(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
 455 {
 456         int actual;
 457         struct slip *sl = (struct slip *) tty->disc_data;
 458 
 459         /* First make sure we're connected. */
 460         if (!sl || sl->magic != SLIP_MAGIC || !sl->dev->start) {
 461                 return;
 462         }
 463 
 464         if (sl->xleft <= 0)  {
 465                 /* Now serial buffer is almost free & we can start
 466                  * transmission of another packet */
 467                 sl->tx_packets++;
 468                 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
 469                 sl_unlock(sl);
 470                 mark_bh(NET_BH);
 471                 return;
 472         }
 473 
 474         actual = tty->driver.write(tty, 0, sl->xhead, sl->xleft);
 475         sl->xleft -= actual;
 476         sl->xhead += actual;
 477 }
 478 
 479 /* Encapsulate an IP datagram and kick it into a TTY queue. */
 480 static int
 481 sl_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 482 {
 483         struct slip *sl = (struct slip*)(dev->priv);
 484 
 485         if (!dev->start)  {
 486                 printk("%s: xmit call when iface is down\n", dev->name);
 487                 return 1;
 488         }
 489         /*
 490          * If we are busy already- too bad.  We ought to be able
 491          * to queue things at this point, to allow for a little
 492          * frame buffer.  Oh well...
 493          * -----------------------------------------------------
 494          * I hate queues in SLIP driver. May be it's efficient,
 495          * but for me latency is more important. ;)
 496          * So, no queues !
 497          *        14 Oct 1994  Dmitry Gorodchanin.
 498          */
 499         if (dev->tbusy) {
 500                 /* May be we must check transmitter timeout here ?
 501                  *      14 Oct 1994 Dmitry Gorodchanin.
 502                  */
 503 #ifdef SL_CHECK_TRANSMIT
 504                 if (jiffies - dev->trans_start  < 20 * HZ)  {
 505                         /* 20 sec timeout not reached */
 506                         return 1;
 507                 }
 508                 printk("%s: transmit timed out, %s?\n", dev->name,
 509                        (sl->tty->driver.chars_in_buffer(sl->tty) || sl->xleft) ?
 510                        "bad line quality" : "driver error");
 511                 sl->xleft = 0;
 512                 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
 513                 sl_unlock(sl);
 514 #else
 515                 return 1;
 516 #endif
 517         }
 518 
 519         /* We were not busy, so we are now... :-) */
 520         if (skb != NULL) {
 521                 sl_lock(sl);
 522                 sl_encaps(sl, skb->data, skb->len);
 523                 dev_kfree_skb(skb, FREE_WRITE);
 524         }
 525         return 0;
 526 }
 527 
 528 
 529 /* Return the frame type ID.  This is normally IP but maybe be AX.25. */
 530 
 531 /* Fill in the MAC-level header. Not used by SLIP. */
 532 static int
 533 sl_header(struct sk_buff *skb, struct device *dev, unsigned short type,
     /* [previous][next][first][last][top][bottom][index][help] */
 534           void *daddr, void *saddr, unsigned len)
 535 {
 536 #ifdef CONFIG_AX25
 537 #ifdef CONFIG_INET
 538         struct slip *sl = (struct slip*)(dev->priv);
 539 
 540         if (sl->mode & SL_MODE_AX25 && type != htons(ETH_P_AX25))  {
 541                 return ax25_encapsulate(skb, dev, type, daddr, saddr, len);
 542         }
 543 #endif
 544 #endif
 545         return 0;
 546 }
 547 
 548 
 549 /* Rebuild the MAC-level header.  Not used by SLIP. */
 550 static int
 551 sl_rebuild_header(void *buff, struct device *dev, unsigned long raddr,
     /* [previous][next][first][last][top][bottom][index][help] */
 552                   struct sk_buff *skb)
 553 {
 554 #ifdef CONFIG_AX25
 555 #ifdef CONFIG_INET
 556         struct slip *sl = (struct slip*)(dev->priv);
 557 
 558         if (sl->mode & SL_MODE_AX25) {
 559                 return ax25_rebuild_header(buff, dev, raddr, skb);
 560         }
 561 #endif
 562 #endif
 563         return 0;
 564 }
 565 
 566 
 567 /* Open the low-level part of the SLIP channel. Easy! */
 568 static int
 569 sl_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 570 {
 571         struct slip *sl = (struct slip*)(dev->priv);
 572         unsigned long len;
 573 
 574         if (sl->tty == NULL) {
 575                 return -ENODEV;
 576         }
 577 
 578         /*
 579          * Allocate the SLIP frame buffers:
 580          *
 581          * rbuff        Receive buffer.
 582          * xbuff        Transmit buffer.
 583          * cbuff        Temporary compression buffer.
 584          */
 585         len = dev->mtu * 2;
 586         /*
 587          * allow for arrival of larger UDP packets, even if we say not to
 588          * also fixes a bug in which SunOS sends 512-byte packets even with
 589          * an MSS of 128
 590          */
 591         if (len < 576 * 2)  {
 592                 len = 576 * 2;
 593         }
 594         sl->rbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL);
 595         if (sl->rbuff == NULL)   {
 596                 goto norbuff;
 597         }
 598         sl->xbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL);
 599         if (sl->xbuff == NULL)   {
 600                 goto noxbuff;
 601         }
 602 #ifdef SL_INCLUDE_CSLIP
 603         sl->cbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL);
 604         if (sl->cbuff == NULL)   {
 605                 goto nocbuff;
 606         }
 607         sl->slcomp = slhc_init(16, 16);
 608         if (sl->slcomp == NULL)  {
 609                 goto noslcomp;
 610         }
 611 #endif
 612 
 613 #ifdef CONFIG_AX25
 614         sl->mtu      = dev->mtu + 73;
 615 #else
 616         sl->mtu      = dev->mtu;
 617 #endif
 618         sl->buffsize = len;
 619         sl->rcount   = 0;
 620         sl->xleft    = 0;
 621 #ifdef CONFIG_SLIP_MODE_SLIP6
 622         sl->xdata    = 0;
 623         sl->xbits    = 0;
 624 #endif
 625         sl->flags   &= (1 << SLF_INUSE);      /* Clear ESCAPE & ERROR flags */
 626 
 627         /* Needed because address '0' is special */
 628         if (dev->pa_addr == 0)  {
 629                 dev->pa_addr=ntohl(0xC0A80001);
 630         }
 631         dev->tbusy  = 0;
 632 /*      dev->flags |= IFF_UP; */
 633         dev->start  = 1;
 634 
 635         return 0;
 636 
 637         /* Cleanup */
 638 #ifdef SL_INCLUDE_CSLIP
 639 noslcomp:
 640         kfree(sl->cbuff);
 641 nocbuff:
 642 #endif
 643         kfree(sl->xbuff);
 644 noxbuff:
 645         kfree(sl->rbuff);
 646 norbuff:
 647         return -ENOMEM;
 648 }
 649 
 650 
 651 /* Close the low-level part of the SLIP channel. Easy! */
 652 static int
 653 sl_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 654 {
 655         struct slip *sl = (struct slip*)(dev->priv);
 656 
 657         if (sl->tty == NULL) {
 658                 return -EBUSY;
 659         }
 660         sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
 661         dev->tbusy = 1;
 662         dev->start = 0;
 663         
 664 /*      dev->flags &= ~IFF_UP; */
 665 
 666         return 0;
 667 }
 668 
 669 static int
 670 slip_receive_room(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
 671 {
 672         return 65536;  /* We can handle an infinite amount of data. :-) */
 673 }
 674 
 675 /*
 676  * Handle the 'receiver data ready' interrupt.
 677  * This function is called by the 'tty_io' module in the kernel when
 678  * a block of SLIP data has been received, which can now be decapsulated
 679  * and sent on to some IP layer for further processing.
 680  */
 681 static void
 682 slip_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 683 {
 684         struct slip *sl = (struct slip *) tty->disc_data;
 685 
 686         if (!sl || sl->magic != SLIP_MAGIC || !sl->dev->start)
 687                 return;
 688 
 689         /*
 690          * Argh! mtu change time! - costs us the packet part received
 691          * at the change
 692          */
 693 #ifdef CONFIG_AX25
 694         if (sl->mtu != sl->dev->mtu + 73)  {
 695 #else
 696         if (sl->mtu != sl->dev->mtu)  {
 697 #endif
 698                 sl_changedmtu(sl);
 699         }
 700 
 701         /* Read the characters out of the buffer */
 702         while (count--) {
 703                 if (fp && *fp++) {
 704                         if (!set_bit(SLF_ERROR, &sl->flags))  {
 705                                 sl->rx_errors++;
 706                         }
 707                         cp++;
 708                         continue;
 709                 }
 710 #ifdef CONFIG_SLIP_MODE_SLIP6
 711                 if (sl->mode & SL_MODE_SLIP6)
 712                         slip_unesc6(sl, *cp++);
 713                 else
 714 #endif
 715                         slip_unesc(sl, *cp++);
 716         }
 717 }
 718 
 719 /*
 720  * Open the high-level part of the SLIP channel.
 721  * This function is called by the TTY module when the
 722  * SLIP line discipline is called for.  Because we are
 723  * sure the tty line exists, we only have to link it to
 724  * a free SLIP channel...
 725  */
 726 static int
 727 slip_open(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
 728 {
 729         struct slip *sl = (struct slip *) tty->disc_data;
 730         int err;
 731 
 732         /* First make sure we're not already connected. */
 733         if (sl && sl->magic == SLIP_MAGIC) {
 734                 return -EEXIST;
 735         }
 736 
 737         /* OK.  Find a free SLIP channel to use. */
 738         if ((sl = sl_alloc()) == NULL) {
 739                 return -ENFILE;
 740         }
 741 
 742         sl->tty = tty;
 743         tty->disc_data = sl;
 744         if (tty->driver.flush_buffer)  {
 745                 tty->driver.flush_buffer(tty);
 746         }
 747         if (tty->ldisc.flush_buffer)  {
 748                 tty->ldisc.flush_buffer(tty);
 749         }
 750 
 751         /* Restore default settings */
 752         sl->mode      = SL_MODE_DEFAULT;
 753         sl->dev->type = ARPHRD_SLIP + sl->mode;
 754 #ifdef CONFIG_AX25      
 755         if (sl->dev->type == 260) {             /* KISS */
 756                 sl->dev->type = ARPHRD_AX25;
 757         }
 758 #endif  
 759         /* Perform the low-level SLIP initialization. */
 760         if ((err = sl_open(sl->dev)))  {
 761                 return err;
 762         }
 763         
 764 #ifdef MODULE
 765         MOD_INC_USE_COUNT;
 766 #endif
 767 
 768         /* Done.  We have linked the TTY line to a channel. */
 769         return sl->dev->base_addr;
 770 }
 771 
 772 
 773 /*
 774  * Close down a SLIP channel.
 775  * This means flushing out any pending queues, and then restoring the
 776  * TTY line discipline to what it was before it got hooked to SLIP
 777  * (which usually is TTY again).
 778  */
 779 static void
 780 slip_close(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
 781 {
 782         struct slip *sl = (struct slip *) tty->disc_data;
 783 
 784         /* First make sure we're connected. */
 785         if (!sl || sl->magic != SLIP_MAGIC) {
 786                 return;
 787         }
 788 
 789         (void) dev_close(sl->dev);
 790         
 791         tty->disc_data = 0;
 792         sl->tty = NULL;
 793         sl_free(sl);
 794         unregister_netdev(sl->dev);
 795 #ifdef MODULE
 796         MOD_DEC_USE_COUNT;
 797 #endif
 798 }
 799 
 800 
 801 static struct enet_statistics *
 802 sl_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 803 {
 804         static struct enet_statistics stats;
 805         struct slip *sl = (struct slip*)(dev->priv);
 806 #ifdef SL_INCLUDE_CSLIP
 807         struct slcompress *comp;
 808 #endif
 809 
 810         memset(&stats, 0, sizeof(struct enet_statistics));
 811 
 812         stats.rx_packets     = sl->rx_packets;
 813         stats.tx_packets     = sl->tx_packets;
 814         stats.rx_dropped     = sl->rx_dropped;
 815         stats.tx_dropped     = sl->tx_dropped;
 816         stats.tx_errors      = sl->tx_errors;
 817         stats.rx_errors      = sl->rx_errors;
 818         stats.rx_over_errors = sl->rx_over_errors;
 819 #ifdef SL_INCLUDE_CSLIP
 820         stats.rx_fifo_errors = sl->rx_compressed;
 821         stats.tx_fifo_errors = sl->tx_compressed;
 822         stats.collisions     = sl->tx_misses;
 823         comp = sl->slcomp;
 824         if (comp) {
 825                 stats.rx_fifo_errors += comp->sls_i_compressed;
 826                 stats.rx_dropped     += comp->sls_i_tossed;
 827                 stats.tx_fifo_errors += comp->sls_o_compressed;
 828                 stats.collisions     += comp->sls_o_misses;
 829         }
 830 #endif /* CONFIG_INET */
 831         return (&stats);
 832 }
 833 
 834 
 835  /************************************************************************
 836   *                     STANDARD SLIP ENCAPSULATION                      *
 837   ************************************************************************/
 838 
 839 int
 840 slip_esc(unsigned char *s, unsigned char *d, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 841 {
 842         unsigned char *ptr = d;
 843         unsigned char c;
 844 
 845         /*
 846          * Send an initial END character to flush out any
 847          * data that may have accumulated in the receiver
 848          * due to line noise.
 849          */
 850 
 851         *ptr++ = END;
 852 
 853         /*
 854          * For each byte in the packet, send the appropriate
 855          * character sequence, according to the SLIP protocol.
 856          */
 857 
 858         while (len-- > 0) {
 859                 switch(c = *s++) {
 860                  case END:
 861                         *ptr++ = ESC;
 862                         *ptr++ = ESC_END;
 863                         break;
 864                  case ESC:
 865                         *ptr++ = ESC;
 866                         *ptr++ = ESC_ESC;
 867                         break;
 868                  default:
 869                         *ptr++ = c;
 870                         break;
 871                 }
 872         }
 873         *ptr++ = END;
 874         return (ptr - d);
 875 }
 876 
 877 static void
 878 slip_unesc(struct slip *sl, unsigned char s)
     /* [previous][next][first][last][top][bottom][index][help] */
 879 {
 880 
 881         switch(s) {
 882          case END:
 883                 if (!clear_bit(SLF_ERROR, &sl->flags) && (sl->rcount > 2))  {
 884                         sl_bump(sl);
 885                 }
 886                 clear_bit(SLF_ESCAPE, &sl->flags);
 887                 sl->rcount = 0;
 888                 return;
 889 
 890          case ESC:
 891                 set_bit(SLF_ESCAPE, &sl->flags);
 892                 return;
 893          case ESC_ESC:
 894                 if (clear_bit(SLF_ESCAPE, &sl->flags))  {
 895                         s = ESC;
 896                 }
 897                 break;
 898          case ESC_END:
 899                 if (clear_bit(SLF_ESCAPE, &sl->flags))  {
 900                         s = END;
 901                 }
 902                 break;
 903         }
 904         if (!test_bit(SLF_ERROR, &sl->flags))  {
 905                 if (sl->rcount < sl->buffsize)  {
 906                         sl->rbuff[sl->rcount++] = s;
 907                         return;
 908                 }
 909                 sl->rx_over_errors++;
 910                 set_bit(SLF_ERROR, &sl->flags);
 911         }
 912 }
 913 
 914 
 915 #ifdef CONFIG_SLIP_MODE_SLIP6
 916 /************************************************************************
 917  *                       6 BIT SLIP ENCAPSULATION                       *
 918  ************************************************************************/
 919 
 920 int
 921 slip_esc6(unsigned char *s, unsigned char *d, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 922 {
 923         unsigned char *ptr = d;
 924         unsigned char c;
 925         int i;
 926         unsigned short v = 0;
 927         short bits = 0;
 928 
 929         /*
 930          * Send an initial END character to flush out any
 931          * data that may have accumulated in the receiver
 932          * due to line noise.
 933          */
 934 
 935         *ptr++ = 0x70;
 936 
 937         /*
 938          * Encode the packet into printable ascii characters
 939          */
 940 
 941         for (i = 0; i < len; ++i) {
 942                 v = (v << 8) | s[i];
 943                 bits += 8;
 944                 while (bits >= 6) {
 945                         bits -= 6;
 946                         c = 0x30 + ((v >> bits) & 0x3F);
 947                         *ptr++ = c;
 948                 }
 949         }
 950         if (bits) {
 951                 c = 0x30 + ((v << (6 - bits)) & 0x3F);
 952                 *ptr++ = c;
 953         }
 954         *ptr++ = 0x70;
 955         return ptr - d;
 956 }
 957 
 958 void
 959 slip_unesc6(struct slip *sl, unsigned char s)
     /* [previous][next][first][last][top][bottom][index][help] */
 960 {
 961         unsigned char c;
 962 
 963         if (s == 0x70) {
 964                 if (!clear_bit(SLF_ERROR, &sl->flags) && (sl->rcount > 2))  {
 965                         sl_bump(sl);
 966                 }
 967                 sl->rcount = 0;
 968                 sl->xbits = 0;
 969                 sl->xdata = 0;
 970         } else if (s >= 0x30 && s < 0x70) {
 971                 sl->xdata = (sl->xdata << 6) | ((s - 0x30) & 0x3F);
 972                 sl->xbits += 6;
 973                 if (sl->xbits >= 8) {
 974                         sl->xbits -= 8;
 975                         c = (unsigned char)(sl->xdata >> sl->xbits);
 976                         if (!test_bit(SLF_ERROR, &sl->flags))  {
 977                                 if (sl->rcount < sl->buffsize)  {
 978                                         sl->rbuff[sl->rcount++] = c;
 979                                         return;
 980                                 }
 981                                 sl->rx_over_errors++;
 982                                 set_bit(SLF_ERROR, &sl->flags);
 983                         }
 984                 }
 985         }
 986 }
 987 #endif /* CONFIG_SLIP_MODE_SLIP6 */
 988 
 989 #ifdef CONFIG_AX25
 990 int
 991 sl_set_mac_address(struct device *dev, void *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 992 {
 993         int err;
 994 
 995         err = verify_area(VERIFY_READ, addr, AX25_ADDR_LEN);
 996         if (err)  {
 997                 return err;
 998         }
 999 
1000         memcpy_fromfs(dev->dev_addr, addr, AX25_ADDR_LEN);      /* addr is an AX.25 shifted ASCII mac address */
1001 
1002         return 0;
1003 }
1004 
1005 static int
1006 sl_set_dev_mac_address(struct device *dev, void *addr)
     /* [previous][next][first][last][top][bottom][index][help] */
1007 {
1008         memcpy(dev->dev_addr, addr, AX25_ADDR_LEN);
1009         return 0;
1010 }
1011 #endif /* CONFIG_AX25 */
1012 
1013 
1014 /* Perform I/O control on an active SLIP channel. */
1015 static int
1016 slip_ioctl(struct tty_struct *tty, void *file, int cmd, void *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1017 {
1018         struct slip *sl = (struct slip *) tty->disc_data;
1019         int err;
1020         unsigned int tmp;
1021 
1022         /* First make sure we're connected. */
1023         if (!sl || sl->magic != SLIP_MAGIC) {
1024                 return -EINVAL;
1025         }
1026 
1027         switch(cmd) {
1028          case SIOCGIFNAME:
1029                 err = verify_area(VERIFY_WRITE, arg, strlen(sl->dev->name) + 1);
1030                 if (err)  {
1031                         return -err;
1032                 }
1033                 memcpy_tofs(arg, sl->dev->name, strlen(sl->dev->name) + 1);
1034                 return 0;
1035 
1036         case SIOCGIFENCAP:
1037                 err = verify_area(VERIFY_WRITE, arg, sizeof(int));
1038                 if (err)  {
1039                         return -err;
1040                 }
1041                 put_user(sl->mode, (int *)arg);
1042                 return 0;
1043 
1044         case SIOCSIFENCAP:
1045                 err = verify_area(VERIFY_READ, arg, sizeof(int));
1046                 if (err)  {
1047                         return -err;
1048                 }
1049                 tmp = get_user((int *)arg);
1050 #ifndef SL_INCLUDE_CSLIP
1051                 if (tmp & (SL_MODE_CSLIP|SL_MODE_ADAPTIVE))  {
1052                         return -EINVAL;
1053                 }
1054 #else
1055                 if ((tmp & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) ==
1056                     (SL_MODE_ADAPTIVE | SL_MODE_CSLIP))  {
1057                         /* return -EINVAL; */
1058                         tmp &= ~SL_MODE_ADAPTIVE;
1059                 }
1060 #endif
1061 #ifndef CONFIG_SLIP_MODE_SLIP6
1062                 if (tmp & SL_MODE_SLIP6)  {
1063                         return -EINVAL;
1064                 }
1065 #endif
1066 #ifndef CONFIG_AX25
1067                 if (tmp & SL_MODE_AX25) {
1068                         return -EINVAL;
1069                 }
1070 #else
1071                 if (tmp & SL_MODE_AX25) {
1072                         sl->dev->addr_len=AX25_ADDR_LEN;          /* sizeof an AX.25 addr */
1073                         sl->dev->hard_header_len=AX25_KISS_HEADER_LEN + AX25_MAX_HEADER_LEN + 3;
1074                 } else  {
1075                         sl->dev->addr_len=0;    /* No mac addr in slip mode */
1076                         sl->dev->hard_header_len=0;
1077                 }
1078 #endif
1079                 sl->mode = tmp;
1080                 sl->dev->type = ARPHRD_SLIP+sl->mode;
1081 #ifdef CONFIG_AX25              
1082                 if (sl->dev->type == 260)  {
1083                         sl->dev->type = ARPHRD_AX25;
1084                 }
1085 #endif          
1086                 return 0;
1087 
1088          case SIOCSIFHWADDR:
1089 #ifdef CONFIG_AX25
1090                 return sl_set_mac_address(sl->dev, arg);
1091 #else
1092                 return -EINVAL;
1093 #endif
1094 
1095         /* Allow stty to read, but not set, the serial port */
1096         case TCGETS:
1097         case TCGETA:
1098                 return n_tty_ioctl(tty, (struct file *) file, cmd, (unsigned long) arg);
1099 
1100         default:
1101                 return -ENOIOCTLCMD;
1102         }
1103 }
1104 
1105 static int sl_open_dev(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1106 {
1107         struct slip *sl = (struct slip*)(dev->priv);
1108         if(sl->tty==NULL)
1109                 return -ENODEV;
1110         return 0;
1111 }
1112 
1113 /* Initialize SLIP control device -- register SLIP line discipline */
1114 #ifdef MODULE
1115 static int slip_init_ctrl_dev(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1116 #else   /* !MODULE */
1117 int
1118 slip_init_ctrl_dev(struct device *dummy)
1119 #endif  /* !MODULE */
1120 {
1121         int status;
1122 
1123         if (slip_maxdev < 4) slip_maxdev = 4; /* Sanity */
1124 
1125         printk("SLIP: version %s (dynamic channels, max=%d)"
1126 #ifdef CONFIG_SLIP_MODE_SLIP6
1127                " (6 bit encapsulation enabled)"
1128 #endif
1129                "\n",
1130                SLIP_VERSION, slip_maxdev );
1131 #if defined(SL_INCLUDE_CSLIP) && !defined(MODULE)
1132         printk("CSLIP: code copyright 1989 Regents of the University of California\n");
1133 #endif
1134 #ifdef CONFIG_AX25
1135         printk("AX25: KISS encapsulation enabled\n");
1136 #endif
1137 
1138         slip_ctrls = (slip_ctrl_t **) kmalloc(sizeof(void*)*slip_maxdev, GFP_KERNEL);
1139         if (slip_ctrls == NULL) {
1140           printk("SLIP: Can't allocate slip_ctrls[] array!  Uaargh! (-> No SLIP available)\n");
1141           return -ENOMEM;
1142         }
1143         
1144         /* Clear the pointer array, we allocate devices when we need them */
1145         memset(slip_ctrls, 0, sizeof(void*)*slip_maxdev); /* Pointers */
1146 
1147         /* Fill in our line protocol discipline, and register it */
1148         memset(&sl_ldisc, 0, sizeof(sl_ldisc));
1149         sl_ldisc.magic  = TTY_LDISC_MAGIC;
1150         sl_ldisc.flags  = 0;
1151         sl_ldisc.open   = slip_open;
1152         sl_ldisc.close  = slip_close;
1153         sl_ldisc.read   = NULL;
1154         sl_ldisc.write  = NULL;
1155         sl_ldisc.ioctl  = (int (*)(struct tty_struct *, struct file *,
1156                                    unsigned int, unsigned long)) slip_ioctl;
1157         sl_ldisc.select = NULL;
1158         sl_ldisc.receive_buf = slip_receive_buf;
1159         sl_ldisc.receive_room = slip_receive_room;
1160         sl_ldisc.write_wakeup = slip_write_wakeup;
1161         if ((status = tty_register_ldisc(N_SLIP, &sl_ldisc)) != 0)  {
1162           printk("SLIP: can't register line discipline (err = %d)\n", status);
1163         }
1164 
1165 
1166 #ifdef MODULE
1167         return status;
1168 #else
1169         /* Return "not found", so that dev_init() will unlink
1170          * the placeholder device entry for us.
1171          */
1172         return ENODEV;
1173 #endif
1174       }
1175 
1176 
1177 /* Initialize the SLIP driver.  Called by DDI. */
1178 int
1179 slip_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1180 {
1181         struct slip *sl = (struct slip*)(dev->priv);
1182         int i;
1183 #ifdef CONFIG_AX25
1184         static char ax25_bcast[AX25_ADDR_LEN] =
1185                 {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
1186         static char ax25_test[AX25_ADDR_LEN] =
1187                 {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
1188 #endif
1189 
1190         if (sl == NULL)         /* Allocation failed ?? */
1191           return -ENODEV;
1192 
1193         /* Set up the "SLIP Control Block". (And clear statistics) */
1194         
1195         memset(sl, 0, sizeof (struct slip));
1196         sl->magic  = SLIP_MAGIC;
1197         sl->dev    = dev;
1198         
1199         /* Finish setting up the DEVICE info. */
1200         dev->mtu                = SL_MTU;
1201         dev->hard_start_xmit    = sl_xmit;
1202         dev->open               = sl_open_dev;
1203         dev->stop               = sl_close;
1204         dev->hard_header        = sl_header;
1205         dev->get_stats          = sl_get_stats;
1206 #ifdef HAVE_SET_MAC_ADDR
1207 #ifdef CONFIG_AX25
1208         dev->set_mac_address    = sl_set_dev_mac_address;
1209 #endif
1210 #endif
1211         dev->hard_header_len    = 0;
1212         dev->addr_len           = 0;
1213         dev->type               = ARPHRD_SLIP + SL_MODE_DEFAULT;
1214 #ifdef CONFIG_AX25
1215         if (sl->dev->type == 260) {
1216                 sl->dev->type = ARPHRD_AX25;
1217         }
1218         memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN);      /* Only activated in AX.25 mode */
1219         memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN);        /*    ""      ""       ""    "" */
1220 #endif
1221         dev->rebuild_header     = sl_rebuild_header;
1222 
1223         for (i = 0; i < DEV_NUMBUFFS; i++)  {
1224                 skb_queue_head_init(&dev->buffs[i]);
1225         }
1226 
1227         /* New-style flags. */
1228         dev->flags              = 0;
1229         dev->family             = AF_INET;
1230         dev->pa_addr            = 0;
1231         dev->pa_brdaddr         = 0;
1232         dev->pa_mask            = 0;
1233         dev->pa_alen            = 4;
1234 
1235         return 0;
1236 }
1237 #ifdef MODULE
1238 char kernel_version[] = UTS_RELEASE;
1239 
1240 int
1241 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1242 {
1243         return slip_init_ctrl_dev();
1244 }
1245 
1246 void
1247 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1248 {
1249         int i;
1250 
1251         if (MOD_IN_USE)  {
1252                 printk("SLIP: device busy, remove delayed\n");
1253                 return;
1254         }
1255         if (slip_ctrls != NULL) {
1256           for (i = 0; i < slip_maxdev; i++)  {
1257             if (slip_ctrls[i] != NULL) {
1258               unregister_netdev(&(slip_ctrls[i]->dev));
1259               kfree(slip_ctrls[i]);
1260             }
1261           }
1262           kfree(slip_ctrls);
1263           slip_ctrls = NULL;
1264         }
1265         if ((i = tty_register_ldisc(N_SLIP, NULL)))  {
1266           printk("SLIP: can't unregister line discipline (err = %d)\n", i);
1267         }
1268 }
1269 #endif /* MODULE */

/* [previous][next][first][last][top][bottom][index][help] */