root/drivers/net/loopback.c

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

DEFINITIONS

This source file includes following definitions.
  1. loopback_xmit
  2. get_stats
  3. loopback_open
  4. loopback_init

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              Pseudo-driver for the loopback interface.
   7  *
   8  * Version:     @(#)loopback.c  1.0.4b  08/16/93
   9  *
  10  * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
  11  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12  *              Donald Becker, <becker@super.org>
  13  *
  14  *              Alan Cox        :       Fixed oddments for NET3.014
  15  *
  16  *              This program is free software; you can redistribute it and/or
  17  *              modify it under the terms of the GNU General Public License
  18  *              as published by the Free Software Foundation; either version
  19  *              2 of the License, or (at your option) any later version.
  20  */
  21 #include <linux/config.h>
  22 #include <linux/kernel.h>
  23 #include <linux/sched.h>
  24 #include <linux/fs.h>
  25 #include <linux/types.h>
  26 #include <linux/string.h>
  27 #include <linux/socket.h>
  28 #include <linux/errno.h>
  29 #include <linux/fcntl.h>
  30 #include <linux/in.h>
  31 #include <linux/if_ether.h>     /* For the statistics structure. */
  32 
  33 #include <asm/system.h>
  34 #include <asm/segment.h>
  35 #include <asm/io.h>
  36 
  37 #include <linux/inet.h>
  38 #include <linux/netdevice.h>
  39 #include <linux/etherdevice.h>
  40 #include <linux/skbuff.h>
  41 
  42 
  43 static int
  44 loopback_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46   struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
  47   int done;
  48 
  49   if (skb == NULL || dev == NULL) return(0);
  50 
  51   cli();
  52   if (dev->tbusy != 0) {
  53         sti();
  54         stats->tx_errors++;
  55         return(1);
  56   }
  57   dev->tbusy = 1;
  58   sti();
  59 
  60   done = dev_rint(skb->data, skb->len, 0, dev);
  61   if (skb->free) kfree_skb(skb, FREE_WRITE);
  62 
  63   while (done != 1) {
  64         done = dev_rint(NULL, 0, 0, dev);
  65   }
  66   stats->tx_packets++;
  67 
  68   dev->tbusy = 0;
  69 
  70 #if 1
  71         __asm__("cmpl $0,_intr_count\n\t"
  72                 "jne 1f\n\t"
  73                 "movl _bh_active,%%eax\n\t"
  74                 "testl _bh_mask,%%eax\n\t"
  75                 "je 1f\n\t"
  76                 "incl _intr_count\n\t"
  77                 "call _do_bottom_half\n\t"
  78                 "decl _intr_count\n"
  79                 "1:"
  80                 :
  81                 :
  82                 : "ax", "dx", "cx");
  83 #endif
  84 
  85   return(0);
  86 }
  87 
  88 static struct enet_statistics *
  89 get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  90 {
  91     return (struct enet_statistics *)dev->priv;
  92 }
  93 
  94 static int loopback_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96         dev->flags|=IFF_LOOPBACK;
  97         return 0;
  98 }
  99 
 100 /* Initialize the rest of the LOOPBACK device. */
 101 int
 102 loopback_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 103 {
 104   int i;
 105 
 106   dev->mtu              = 2000;                 /* MTU                  */
 107   dev->tbusy            = 0;
 108   dev->hard_start_xmit  = loopback_xmit;
 109   dev->open             = NULL;
 110 #if 1
 111   dev->hard_header      = eth_header;
 112   dev->hard_header_len  = ETH_HLEN;             /* 14                   */
 113   dev->addr_len         = ETH_ALEN;             /* 6                    */
 114   dev->type             = ARPHRD_ETHER;         /* 0x0001               */
 115   dev->type_trans       = eth_type_trans;
 116   dev->rebuild_header   = eth_rebuild_header;
 117   dev->open             = loopback_open;
 118 #else
 119   dev->hard_header_length = 0;
 120   dev->addr_len         = 0;
 121   dev->type             = 0;                    /* loopback_type (0)    */
 122   dev->hard_header      = NULL;
 123   dev->type_trans       = NULL;
 124   dev->rebuild_header   = NULL;
 125 #endif
 126 
 127   /* New-style flags. */
 128   dev->flags            = IFF_LOOPBACK;
 129   dev->family           = AF_INET;
 130 #ifdef CONFIG_INET    
 131   dev->pa_addr          = in_aton("127.0.0.1");
 132   dev->pa_brdaddr       = in_aton("127.255.255.255");
 133   dev->pa_mask          = in_aton("255.0.0.0");
 134   dev->pa_alen          = sizeof(unsigned long);
 135 #endif  
 136   dev->priv = kmalloc(sizeof(struct enet_statistics), GFP_KERNEL);
 137   memset(dev->priv, 0, sizeof(struct enet_statistics));
 138   dev->get_stats = get_stats;
 139 
 140   /* Fill in the generic fields of the device structure. */
 141   for (i = 0; i < DEV_NUMBUFFS; i++)
 142         skb_queue_head_init(&dev->buffs[i]);
 143   
 144   return(0);
 145 };

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