|
|
1.1 ! root 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 [email protected] or ! 20: C/O Department of Mathematics; Stanford University; Stanford, CA 94305 ! 21: */ ! 22: #include <linux/config.h> ! 23: #include <linux/kernel.h> ! 24: #include <linux/sched.h> ! 25: #include <linux/fs.h> ! 26: #include <linux/tty.h> ! 27: #include <linux/types.h> ! 28: #include <linux/ptrace.h> ! 29: #include <asm/system.h> ! 30: #include <asm/segment.h> ! 31: #include <asm/io.h> ! 32: #include <asm/memory.h> ! 33: #include <errno.h> ! 34: #include <linux/fcntl.h> ! 35: #include <netinet/in.h> ! 36: ! 37: #include "dev.h" ! 38: #include "eth.h" ! 39: #include "timer.h" ! 40: #include "ip.h" ! 41: #include "tcp.h" ! 42: #include "sock.h" ! 43: #include "arp.h" ! 44: ! 45: #include "../kern_sock.h" /* for PRINTK */ ! 46: ! 47: ! 48: ! 49: static int ! 50: loopback_xmit(struct sk_buff *skb, struct device *dev) ! 51: { ! 52: static int inuse=0; ! 53: struct enet_header *eth; ! 54: int i; ! 55: int done; ! 56: static unsigned char buff[2048]; ! 57: unsigned char *tmp; ! 58: ! 59: PRINTK ("loopback_xmit (dev = %X)\n", dev); ! 60: cli(); ! 61: if (inuse) ! 62: { ! 63: sti(); ! 64: return (1); ! 65: } ! 66: inuse = 1; ! 67: sti(); ! 68: tmp = NULL; ! 69: done = dev_rint ((unsigned char *)(skb+1), skb->len, 0, dev); ! 70: ! 71: if (skb->free) ! 72: free_skb (skb, FREE_WRITE); ! 73: ! 74: while (done != 1) ! 75: { ! 76: if (done != -1 && (i = dev_tint (buff,dev)) != 0) ! 77: { ! 78: /* print out the buffer. */ ! 79: PRINTK ("ethernet xmit: \n"); ! 80: eth = (struct enet_header *)buff; ! 81: print_eth (eth); ! 82: tmp = buff; ! 83: done = dev_rint (buff, i, 0, dev); ! 84: if (done != -1) tmp = NULL; ! 85: } ! 86: else ! 87: { ! 88: done = dev_rint (tmp, 0, 0, dev); ! 89: } ! 90: ! 91: } ! 92: inuse = 0; ! 93: return (0); ! 94: } ! 95: ! 96: void ! 97: loopback_init(struct device *dev) ! 98: { ! 99: printk ("Loopback device init\n"); ! 100: /* initialize the rest of the device structure. */ ! 101: dev->mtu = 2000; /* mtu */ ! 102: dev->hard_start_xmit = loopback_xmit; ! 103: dev->open = NULL; ! 104: dev->hard_header = eth_hard_header; ! 105: dev->add_arp = NULL; ! 106: dev->hard_header_len = sizeof (struct enet_header); ! 107: dev->addr_len = ETHER_ADDR_LEN; ! 108: dev->type = ETHER_TYPE; ! 109: dev->queue_xmit = dev_queue_xmit; ! 110: dev->rebuild_header = eth_rebuild_header; ! 111: dev->type_trans = eth_type_trans; ! 112: dev->loopback = 1; ! 113: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.