root/net/tcp/loopback.c

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

DEFINITIONS

This source file includes following definitions.
  1. loopback_xmit
  2. loopback_init

   1 /* loopback.c contains the loopback device functions. */
   2 /*
   3     Copyright (C) 1992  Ross Biro
   4 
   5     This program is free software; you can redistribute it and/or modify
   6     it under the terms of the GNU General Public License as published by
   7     the Free Software Foundation; either version 2, or (at your option)
   8     any later version.
   9 
  10     This program is distributed in the hope that it will be useful,
  11     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13     GNU General Public License for more details.
  14 
  15     You should have received a copy of the GNU General Public License
  16     along with this program; if not, write to the Free Software
  17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
  18 
  19     The Author may be reached as bir7@leland.stanford.edu or
  20     C/O Department of Mathematics; Stanford University; Stanford, CA 94305
  21 */
  22 /* $Id: loopback.c,v 0.8.4.3 1992/11/18 15:38:03 bir7 Exp $ */
  23 /* $Log: loopback.c,v $
  24  * Revision 0.8.4.3  1992/11/18  15:38:03  bir7
  25  * Fixed bug in start_xmit.
  26  *
  27  * Revision 0.8.4.2  1992/11/10  10:38:48  bir7
  28  * Change free_s to kfree_s and accidently changed free_skb to kfree_skb.
  29  *
  30  * Revision 0.8.4.1  1992/11/10  00:17:18  bir7
  31  * version change only.
  32  *
  33  * Revision 0.8.3.2  1992/11/10  00:14:47  bir7
  34  * Changed malloc to kmalloc and added $iId$ and 
  35  * */
  36 
  37 #include <linux/config.h>
  38 #include <linux/kernel.h>
  39 #include <linux/sched.h>
  40 #include <linux/fs.h>
  41 #include <linux/tty.h>
  42 #include <linux/types.h>
  43 #include <linux/ptrace.h>
  44 #include <linux/string.h>
  45 #include <asm/system.h>
  46 #include <asm/segment.h>
  47 #include <asm/io.h>
  48 #include <errno.h>
  49 #include <linux/fcntl.h>
  50 #include <netinet/in.h>
  51 
  52 #include "dev.h"
  53 #include "eth.h"
  54 #include "timer.h"
  55 #include "ip.h"
  56 #include "tcp.h"
  57 #include "sock.h"
  58 #include "arp.h"
  59 
  60 #ifdef PRINTK
  61 #undef PRINTK
  62 #endif
  63 
  64 #ifdef LOOPBACK_DEBUG
  65 #define PRINTK printk
  66 #else
  67 #define PRINTK dummy_routine
  68 #endif
  69 
  70 static int
  71 loopback_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 {
  73   static int inuse=0;
  74   struct enet_header *eth;
  75   int i;
  76   int done;
  77   static unsigned char buff[2048];
  78   unsigned char *tmp;
  79 
  80   PRINTK ("loopback_xmit (dev = %X)\n", dev);
  81   cli();
  82   if (inuse)
  83     {
  84        sti();
  85        return (1);
  86     }
  87   inuse = 1;
  88   sti();
  89 
  90   done = -1;
  91   while (done == -1)
  92     done = dev_rint ((unsigned char *)(skb+1), skb->len, 0, dev);
  93 
  94   if (skb->free)
  95     kfree_skb (skb, FREE_WRITE);
  96 
  97   tmp = NULL;
  98   i = 0;
  99   while (done != 1)
 100          {
 101             if (done != -1 && (i = dev_tint (buff,dev)) != 0)
 102               {
 103                  /* print out the buffer. */
 104                  PRINTK ("loopback xmit: \n");
 105                  eth = (struct enet_header *)buff;
 106                  print_eth (eth);
 107                  tmp = buff;
 108                  done = dev_rint (buff, i, 0, dev);
 109                  if (done != -1)
 110                    {
 111                      tmp = NULL;
 112                      i = 0;
 113                    }
 114               }
 115             else
 116               {
 117                 if (i == 0) tmp = NULL;
 118                  done = dev_rint (tmp, i, 0, dev);
 119               }
 120             
 121          }
 122   inuse = 0;
 123   return (0);
 124 }
 125 
 126 void
 127 loopback_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 {
 129    printk ("Loopback device init\n");
 130   /* initialize the rest of the device structure. */
 131   dev->mtu = 2000; /* mtu */
 132   dev->hard_start_xmit = loopback_xmit;
 133   dev->open = NULL;
 134   dev->hard_header = eth_hard_header;
 135   dev->add_arp = NULL;
 136   dev->hard_header_len = sizeof (struct enet_header);
 137   dev->addr_len = ETHER_ADDR_LEN;
 138   dev->type = ETHER_TYPE;
 139   dev->queue_xmit = dev_queue_xmit;
 140   dev->rebuild_header = eth_rebuild_header;
 141   dev->type_trans = eth_type_trans;
 142   dev->loopback = 1;
 143 }

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