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

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