root/net/inet/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_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.28    20/12/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  *              This file should be in drivers/net, but our glorious leader
  15  *              has put it here, and who are we to argue with the Linus 8-)
  16  *
  17  *              This program is free software; you can redistribute it and/or
  18  *              modify it under the terms of the GNU General Public License
  19  *              as published by the Free Software Foundation; either version
  20  *              2 of the License, or (at your option) any later version.
  21  */
  22 #include <asm/system.h>
  23 #include <asm/segment.h>
  24 #include <asm/io.h>
  25 #include <linux/config.h>
  26 #include <linux/kernel.h>
  27 #include <linux/sched.h>
  28 #include <linux/fs.h>
  29 #include <linux/tty.h>
  30 #include <linux/types.h>
  31 #include <linux/ptrace.h>
  32 #include <linux/string.h>
  33 #include <linux/socket.h>
  34 #include <linux/errno.h>
  35 #include <linux/fcntl.h>
  36 #include <linux/in.h>
  37 #include <linux/if_ether.h>     /* For the statistics structure. */
  38 #include "inet.h"
  39 #include "devinet.h"
  40 #include "eth.h"
  41 #include "ip.h"
  42 #include "protocol.h"
  43 #include "tcp.h"
  44 #include "skbuff.h"
  45 #include "sockinet.h"
  46 #include "arp.h"
  47 
  48 
  49 static int loopback_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51         struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
  52         int done;
  53 
  54         DPRINTF((DBG_LOOPB, "loopback_xmit(dev=%X, skb=%X)\n", dev, skb));
  55         if (skb == NULL || dev == NULL) 
  56                 return(0);
  57 
  58         cli();
  59         if (dev->tbusy != 0) 
  60         {
  61                 sti();
  62                 stats->tx_errors++;
  63                 return(1);
  64         }
  65         dev->tbusy = 1;
  66         sti();
  67 
  68         done = dev_rint((unsigned char *)(skb+1), skb->len, 0, dev);
  69         if (skb->free) 
  70                 kfree_skb(skb, FREE_WRITE);
  71 
  72         while (done != 1) 
  73         {
  74                 done = dev_rint(NULL, 0, 0, dev);
  75         }
  76         stats->tx_packets++;
  77 
  78         dev->tbusy = 0;
  79 
  80 #if 1
  81         __asm__("cmpl $0,_intr_count\n\t"
  82                 "jne 1f\n\t"
  83                 "movl _bh_active,%%eax\n\t"
  84                 "testl _bh_mask,%%eax\n\t"
  85                 "je 1f\n\t"
  86                 "incl _intr_count\n\t"
  87                 "call _do_bottom_half\n\t"
  88                 "decl _intr_count\n"
  89                 "1:"
  90                 :
  91                 :
  92                 : "ax", "dx", "cx");
  93 #endif
  94 
  95         return(0);
  96 }
  97 
  98 static struct enet_statistics *get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  99 {
 100     return (struct enet_statistics *)dev->priv;
 101 }
 102 
 103 /* Initialize the rest of the LOOPBACK device. */
 104 int loopback_init(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 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->add_arp            = NULL;
 113         dev->hard_header_len    = ETH_HLEN;             /* 14                   */
 114         dev->addr_len           = ETH_ALEN;             /* 6                    */
 115         dev->type               = ARPHRD_ETHER;         /* 0x0001               */
 116         dev->type_trans = eth_type_trans;
 117         dev->rebuild_header     = eth_rebuild_header;
 118 #else
 119         dev->hard_header_length = 0;
 120         dev->add_arp            = NULL;
 121         dev->addr_len           = 0;
 122         dev->type               = 0;                    /* loopback_type (0)    */
 123         dev->hard_header        = NULL;
 124         dev->type_trans         = NULL;
 125         dev->rebuild_header     = NULL;
 126 #endif
 127         dev->queue_xmit         = dev_queue_xmit;
 128 
 129   /* New-style flags. */
 130         dev->flags              = IFF_LOOPBACK;
 131         dev->family             = AF_INET;
 132         dev->pa_addr            = in_aton("127.0.0.1");
 133         dev->pa_brdaddr         = in_aton("127.255.255.255");
 134         dev->pa_mask            = in_aton("255.0.0.0");
 135         dev->pa_alen            = sizeof(unsigned long);
 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         return(0);
 141 };

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