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. sl_get_ax25_mode
  26. slip_ioctl
  27. sl_open_dev
  28. slip_init_ctrl_dev
  29. slip_init
  30. init_module
  31. 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|SL_MODE_AX25VC))
 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) || (sl->mode & SL_MODE_AX25VC)) && 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) || (sl->mode & SL_MODE_AX25VC)) {
 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 || sl->dev->type == 272) {     /* 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 
1012 int sl_get_ax25_mode(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1013 {
1014         struct slip *sl = (struct slip*)(dev->priv);
1015 
1016         return sl->mode & SL_MODE_AX25VC;
1017 }
1018 
1019 #endif /* CONFIG_AX25 */
1020 
1021 
1022 /* Perform I/O control on an active SLIP channel. */
1023 static int
1024 slip_ioctl(struct tty_struct *tty, void *file, int cmd, void *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1025 {
1026         struct slip *sl = (struct slip *) tty->disc_data;
1027         int err;
1028         unsigned int tmp;
1029 
1030         /* First make sure we're connected. */
1031         if (!sl || sl->magic != SLIP_MAGIC) {
1032                 return -EINVAL;
1033         }
1034 
1035         switch(cmd) {
1036          case SIOCGIFNAME:
1037                 err = verify_area(VERIFY_WRITE, arg, strlen(sl->dev->name) + 1);
1038                 if (err)  {
1039                         return -err;
1040                 }
1041                 memcpy_tofs(arg, sl->dev->name, strlen(sl->dev->name) + 1);
1042                 return 0;
1043 
1044         case SIOCGIFENCAP:
1045                 err = verify_area(VERIFY_WRITE, arg, sizeof(int));
1046                 if (err)  {
1047                         return -err;
1048                 }
1049                 put_user(sl->mode, (int *)arg);
1050                 return 0;
1051 
1052         case SIOCSIFENCAP:
1053                 err = verify_area(VERIFY_READ, arg, sizeof(int));
1054                 if (err)  {
1055                         return -err;
1056                 }
1057                 tmp = get_user((int *)arg);
1058 #ifndef SL_INCLUDE_CSLIP
1059                 if (tmp & (SL_MODE_CSLIP|SL_MODE_ADAPTIVE))  {
1060                         return -EINVAL;
1061                 }
1062 #else
1063                 if ((tmp & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) ==
1064                     (SL_MODE_ADAPTIVE | SL_MODE_CSLIP))  {
1065                         /* return -EINVAL; */
1066                         tmp &= ~SL_MODE_ADAPTIVE;
1067                 }
1068 #endif
1069 #ifndef CONFIG_SLIP_MODE_SLIP6
1070                 if (tmp & SL_MODE_SLIP6)  {
1071                         return -EINVAL;
1072                 }
1073 #endif
1074 #ifndef CONFIG_AX25
1075                 if ((tmp & SL_MODE_AX25) || (tmp & SL_MODE_AX25VC)) {
1076                         return -EINVAL;
1077                 }
1078 #else
1079                 if ((tmp & SL_MODE_AX25) || (tmp & SL_MODE_AX25VC)) {
1080                         sl->dev->addr_len=AX25_ADDR_LEN;          /* sizeof an AX.25 addr */
1081                         sl->dev->hard_header_len=73; /* We don't do digipeaters */
1082                 } else  {
1083                         sl->dev->addr_len=0;    /* No mac addr in slip mode */
1084                         sl->dev->hard_header_len=0;
1085                 }
1086 #endif
1087                 sl->mode = tmp;
1088                 sl->dev->type = ARPHRD_SLIP+sl->mode;
1089 #ifdef CONFIG_AX25              
1090                 if (sl->dev->type == 260 || sl->dev->type == 272)  {
1091                         sl->dev->type = ARPHRD_AX25;
1092                 }
1093 #endif          
1094                 return 0;
1095 
1096          case SIOCSIFHWADDR:
1097 #ifdef CONFIG_AX25
1098                 return sl_set_mac_address(sl->dev, arg);
1099 #else
1100                 return -EINVAL;
1101 #endif
1102 
1103         /* Allow stty to read, but not set, the serial port */
1104         case TCGETS:
1105         case TCGETA:
1106                 return n_tty_ioctl(tty, (struct file *) file, cmd, (unsigned long) arg);
1107 
1108         default:
1109                 return -ENOIOCTLCMD;
1110         }
1111 }
1112 
1113 static int sl_open_dev(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1114 {
1115         struct slip *sl = (struct slip*)(dev->priv);
1116         if(sl->tty==NULL)
1117                 return -ENODEV;
1118         return 0;
1119 }
1120 
1121 /* Initialize SLIP control device -- register SLIP line discipline */
1122 #ifdef MODULE
1123 static int slip_init_ctrl_dev(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1124 #else   /* !MODULE */
1125 int
1126 slip_init_ctrl_dev(struct device *dummy)
1127 #endif  /* !MODULE */
1128 {
1129         int status;
1130 
1131         if (slip_maxdev < 4) slip_maxdev = 4; /* Sanity */
1132 
1133         printk("SLIP: version %s (dynamic channels, max=%d)"
1134 #ifdef CONFIG_SLIP_MODE_SLIP6
1135                " (6 bit encapsulation enabled)"
1136 #endif
1137                "\n",
1138                SLIP_VERSION, slip_maxdev );
1139 #if defined(SL_INCLUDE_CSLIP) && !defined(MODULE)
1140         printk("CSLIP: code copyright 1989 Regents of the University of California\n");
1141 #endif
1142 #ifdef CONFIG_AX25
1143         printk("AX25: KISS encapsulation enabled\n");
1144 #endif
1145 
1146         slip_ctrls = (slip_ctrl_t **) kmalloc(sizeof(void*)*slip_maxdev, GFP_KERNEL);
1147         if (slip_ctrls == NULL) {
1148           printk("SLIP: Can't allocate slip_ctrls[] array!  Uaargh! (-> No SLIP available)\n");
1149           return -ENOMEM;
1150         }
1151         
1152         /* Clear the pointer array, we allocate devices when we need them */
1153         memset(slip_ctrls, 0, sizeof(void*)*slip_maxdev); /* Pointers */
1154 
1155         /* Fill in our line protocol discipline, and register it */
1156         memset(&sl_ldisc, 0, sizeof(sl_ldisc));
1157         sl_ldisc.magic  = TTY_LDISC_MAGIC;
1158         sl_ldisc.flags  = 0;
1159         sl_ldisc.open   = slip_open;
1160         sl_ldisc.close  = slip_close;
1161         sl_ldisc.read   = NULL;
1162         sl_ldisc.write  = NULL;
1163         sl_ldisc.ioctl  = (int (*)(struct tty_struct *, struct file *,
1164                                    unsigned int, unsigned long)) slip_ioctl;
1165         sl_ldisc.select = NULL;
1166         sl_ldisc.receive_buf = slip_receive_buf;
1167         sl_ldisc.receive_room = slip_receive_room;
1168         sl_ldisc.write_wakeup = slip_write_wakeup;
1169         if ((status = tty_register_ldisc(N_SLIP, &sl_ldisc)) != 0)  {
1170           printk("SLIP: can't register line discipline (err = %d)\n", status);
1171         }
1172 
1173 
1174         /* If not loadable module, a bootstrap Space.c slip_proto dev
1175          *  now needs to be unregistered.
1176          */
1177 #ifndef MODULE
1178         printk("SLIP: Unregistering bootstrap device "
1179                "'slip_proto' - slip OK\n");
1180         unregister_netdev(dummy);
1181 #endif
1182         return status;
1183       }
1184 
1185 
1186 /* Initialize the SLIP driver.  Called by DDI. */
1187 int
1188 slip_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1189 {
1190         struct slip *sl = (struct slip*)(dev->priv);
1191         int i;
1192 #ifdef CONFIG_AX25
1193         static char ax25_bcast[AX25_ADDR_LEN] =
1194                 {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
1195         static char ax25_test[AX25_ADDR_LEN] =
1196                 {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
1197 #endif
1198 
1199         if (sl == NULL)         /* Allocation failed ?? */
1200           return -ENODEV;
1201 
1202         /* Set up the "SLIP Control Block". (And clear statistics) */
1203         
1204         memset(sl, 0, sizeof (struct slip));
1205         sl->magic  = SLIP_MAGIC;
1206         sl->dev    = dev;
1207         
1208         /* Finish setting up the DEVICE info. */
1209         dev->mtu                = SL_MTU;
1210         dev->hard_start_xmit    = sl_xmit;
1211         dev->open               = sl_open_dev;
1212         dev->stop               = sl_close;
1213         dev->hard_header        = sl_header;
1214         dev->get_stats          = sl_get_stats;
1215 #ifdef HAVE_SET_MAC_ADDR
1216 #ifdef CONFIG_AX25
1217         dev->set_mac_address    = sl_set_dev_mac_address;
1218 #endif
1219 #endif
1220         dev->hard_header_len    = 0;
1221         dev->addr_len           = 0;
1222         dev->type               = ARPHRD_SLIP + SL_MODE_DEFAULT;
1223 #ifdef CONFIG_AX25
1224         if (sl->dev->type == 260 || sl->dev->type == 272)  {
1225                 sl->dev->type = ARPHRD_AX25;
1226         }
1227         memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN);      /* Only activated in AX.25 mode */
1228         memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN);        /*    ""      ""       ""    "" */
1229 #endif
1230         dev->rebuild_header     = sl_rebuild_header;
1231 
1232         for (i = 0; i < DEV_NUMBUFFS; i++)  {
1233                 skb_queue_head_init(&dev->buffs[i]);
1234         }
1235 
1236         /* New-style flags. */
1237         dev->flags              = 0;
1238         dev->family             = AF_INET;
1239         dev->pa_addr            = 0;
1240         dev->pa_brdaddr         = 0;
1241         dev->pa_mask            = 0;
1242         dev->pa_alen            = 4;
1243 
1244         return 0;
1245 }
1246 #ifdef MODULE
1247 char kernel_version[] = UTS_RELEASE;
1248 
1249 int
1250 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1251 {
1252         return slip_init_ctrl_dev();
1253 }
1254 
1255 void
1256 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1257 {
1258         int i;
1259 
1260         if (MOD_IN_USE)  {
1261                 printk("SLIP: device busy, remove delayed\n");
1262                 return;
1263         }
1264         if (slip_ctrls != NULL) {
1265           for (i = 0; i < slip_maxdev; i++)  {
1266             if (slip_ctrls[i] != NULL) {
1267               unregister_netdev(&(slip_ctrls[i]->dev));
1268               kfree(slip_ctrls[i]);
1269             }
1270           }
1271           kfree(slip_ctrls);
1272           slip_ctrls = NULL;
1273         }
1274         if ((i = tty_register_ldisc(N_SLIP, NULL)))  {
1275           printk("SLIP: can't unregister line discipline (err = %d)\n", i);
1276         }
1277 }
1278 #endif /* MODULE */

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