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.5 1992/12/12 19:25:04 bir7 Exp $ */
  23 /* $Log: loopback.c,v $
  24  * Revision 0.8.4.5  1992/12/12  19:25:04  bir7
  25  * Cleaned up Log messages.
  26  *
  27  * Revision 0.8.4.4  1992/12/05  21:35:53  bir7
  28  * changed dev->init to return an int.
  29  *
  30  * Revision 0.8.4.3  1992/11/18  15:38:03  bir7
  31  * Fixed bug in start_xmit.
  32  *
  33  * Revision 0.8.4.2  1992/11/10  10:38:48  bir7
  34  * Change free_s to kfree_s and accidently changed free_skb to kfree_skb.
  35  *
  36  * Revision 0.8.4.1  1992/11/10  00:17:18  bir7
  37  * version change only.
  38  *
  39  * Revision 0.8.3.2  1992/11/10  00:14:47  bir7
  40  * Changed malloc to kmalloc and added Id and Log
  41  * */
  42 
  43 #include <linux/config.h>
  44 #include <linux/kernel.h>
  45 #include <linux/sched.h>
  46 #include <linux/fs.h>
  47 #include <linux/tty.h>
  48 #include <linux/types.h>
  49 #include <linux/ptrace.h>
  50 #include <linux/string.h>
  51 #include <asm/system.h>
  52 #include <asm/segment.h>
  53 #include <asm/io.h>
  54 #include <errno.h>
  55 #include <linux/fcntl.h>
  56 #include <netinet/in.h>
  57 
  58 #include "dev.h"
  59 #include "eth.h"
  60 #include "timer.h"
  61 #include "ip.h"
  62 #include "tcp.h"
  63 #include "sock.h"
  64 #include "arp.h"
  65 
  66 #ifdef PRINTK
  67 #undef PRINTK
  68 #endif
  69 
  70 #ifdef LOOPBACK_DEBUG
  71 #define PRINTK printk
  72 #else
  73 #define PRINTK dummy_routine
  74 #endif
  75 
  76 static int
  77 loopback_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  78 {
  79   static int inuse=0;
  80   struct enet_header *eth;
  81   int i;
  82   int done;
  83   static unsigned char buff[2048];
  84   unsigned char *tmp;
  85 
  86   PRINTK ("loopback_xmit (dev = %X)\n", dev);
  87   cli();
  88   if (inuse)
  89     {
  90        sti();
  91        return (1);
  92     }
  93   inuse = 1;
  94   sti();
  95 
  96   done = -1;
  97   while (done == -1)
  98     done = dev_rint ((unsigned char *)(skb+1), skb->len, 0, dev);
  99 
 100   if (skb->free)
 101     kfree_skb (skb, FREE_WRITE);
 102 
 103   tmp = NULL;
 104   i = 0;
 105   while (done != 1)
 106          {
 107             if (done != -1 && (i = dev_tint (buff,dev)) != 0)
 108               {
 109                  /* print out the buffer. */
 110                  PRINTK ("loopback xmit: \n");
 111                  eth = (struct enet_header *)buff;
 112                  print_eth (eth);
 113                  tmp = buff;
 114                  done = dev_rint (buff, i, 0, dev);
 115                  if (done != -1)
 116                    {
 117                      tmp = NULL;
 118                      i = 0;
 119                    }
 120               }
 121             else
 122               {
 123                 if (i == 0) tmp = NULL;
 124                  done = dev_rint (tmp, i, 0, dev);
 125               }
 126             
 127          }
 128   inuse = 0;
 129   return (0);
 130 }
 131 
 132 int
 133 loopback_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 134 {
 135    printk ("Loopback device init\n");
 136   /* initialize the rest of the device structure. */
 137   dev->mtu = 2000; /* mtu */
 138   dev->hard_start_xmit = loopback_xmit;
 139   dev->open = NULL;
 140   dev->hard_header = eth_hard_header;
 141   dev->add_arp = NULL;
 142   dev->hard_header_len = sizeof (struct enet_header);
 143   dev->addr_len = ETHER_ADDR_LEN;
 144   dev->type = ETHER_TYPE;
 145   dev->queue_xmit = dev_queue_xmit;
 146   dev->rebuild_header = eth_rebuild_header;
 147   dev->type_trans = eth_type_trans;
 148   dev->loopback = 1;
 149   return (0);
 150 }

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