?? loopback.c
字號:
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 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
18 */
19 #include <linux/config.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/fs.h>
23 #include <linux/types.h>
24 #include <linux/string.h>
25 #include <linux/socket.h>
26 #include <linux/errno.h>
27 #include <linux/fcntl.h>
28 #include <linux/in.h>
29 #include <linux/if_ether.h> /* For the statistics structure. */
30
31 #include <asm/system.h>
32 #include <asm/segment.h>
33 #include <asm/io.h>
34
35 #include "inet.h"
36 #include "dev.h"
37 #include "eth.h"
38 #include "ip.h"
39 #include "protocol.h"
40 #include "tcp.h"
41 #include "skbuff.h"
42 #include "sock.h"
43 #include "arp.h"
44
45
46 static int
47 loopback_xmit(struct sk_buff *skb, struct device *dev)
48 {
49 struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
50 int done;
51
52 DPRINTF((DBG_LOOPB, "loopback_xmit(dev=%X, skb=%X)\n", dev, skb));
53 if (skb == NULL || dev == NULL) return(0);
54
55 cli();
56 if (dev->tbusy != 0) {
57 sti();
58 stats->tx_errors++;
59 return(1);
60 }
61 dev->tbusy = 1;
62 sti();
63
64 done = dev_rint(skb->data, skb->len, 0, dev);
65 if (skb->free) kfree_skb(skb, FREE_WRITE);
66
67 while (done != 1) {
68 done = dev_rint(NULL, 0, 0, dev);
69 }
70 stats->tx_packets++;
71
72 dev->tbusy = 0;
73
74 #if 1
75 __asm__("cmpl $0,_intr_count\n\t"
76 "jne 1f\n\t"
77 "movl _bh_active,%%eax\n\t"
78 "testl _bh_mask,%%eax\n\t"
79 "je 1f\n\t"
80 "incl _intr_count\n\t"
81 "call _do_bottom_half\n\t"
82 "decl _intr_count\n"
83 "1:"
84 :
85 :
86 : "ax", "dx", "cx");
87 #endif
88
89 return(0);
90 }
91
92 static struct enet_statistics *
93 get_stats(struct device *dev)
94 {
95 return (struct enet_statistics *)dev->priv;
96 }
97
98 /* Initialize the rest of the LOOPBACK device. */
99 int
100 loopback_init(struct device *dev)
101 {
102 dev->mtu = 2000; /* MTU */
103 dev->tbusy = 0;
104 dev->hard_start_xmit = loopback_xmit;
105 dev->open = NULL;
106 #if 1
107 dev->hard_header = eth_header;
108 dev->add_arp = NULL;
109 dev->hard_header_len = ETH_HLEN; /* 14 */
110 dev->addr_len = ETH_ALEN; /* 6 */
111 dev->type = ARPHRD_ETHER; /* 0x0001 */
112 dev->type_trans = eth_type_trans;
113 dev->rebuild_header = eth_rebuild_header;
114 #else
115 dev->hard_header_length = 0;
116 dev->add_arp = NULL;
117 dev->addr_len = 0;
118 dev->type = 0; /* loopback_type (0) */
119 dev->hard_header = NULL;
120 dev->type_trans = NULL;
121 dev->rebuild_header = NULL;
122 #endif
123 dev->queue_xmit = dev_queue_xmit;
124
125 /* New-style flags. */
126 dev->flags = IFF_LOOPBACK;
127 dev->family = AF_INET;
128 dev->pa_addr = in_aton("127.0.0.1");
129 dev->pa_brdaddr = in_aton("127.255.255.255");
130 dev->pa_mask = in_aton("255.0.0.0");
131 dev->pa_alen = sizeof(unsigned long);
132 dev->priv = kmalloc(sizeof(struct enet_statistics), GFP_KERNEL);
133 memset(dev->priv, 0, sizeof(struct enet_statistics));
134 dev->get_stats = get_stats;
135
136 return(0);
137 };
138
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -