This source file includes following definitions.
- loopback_xmit
- get_stats
- loopback_open
- loopback_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include <linux/config.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/interrupt.h>
30 #include <linux/fs.h>
31 #include <linux/types.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>
38 #include <linux/if_arp.h>
39
40 #include <asm/system.h>
41 #include <asm/segment.h>
42 #include <asm/io.h>
43
44 #include <linux/inet.h>
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/skbuff.h>
48 #include <net/sock.h>
49
50
51 static int loopback_xmit(struct sk_buff *skb, struct device *dev)
52 {
53 struct enet_statistics *stats = (struct enet_statistics *)dev->priv;
54 unsigned long flags;
55 int unlock=1;
56
57 if (skb == NULL || dev == NULL)
58 return(0);
59
60 save_flags(flags);
61 cli();
62 if (dev->tbusy != 0)
63 {
64 restore_flags(flags);
65 stats->tx_errors++;
66 return(1);
67 }
68 dev->tbusy = 1;
69 restore_flags(flags);
70
71
72
73
74
75
76 if(skb->free==0)
77 {
78 struct sk_buff *skb2=skb;
79 skb=skb_clone(skb, GFP_ATOMIC);
80 if(skb==NULL)
81 return 1;
82 dev_kfree_skb(skb2, FREE_READ);
83 unlock=0;
84 }
85 else if(skb->sk)
86 {
87
88
89
90
91 save_flags(flags);
92 cli();
93 skb->sk->wmem_alloc-=skb->truesize;
94 skb->sk->write_space(skb->sk);
95 restore_flags(flags);
96 }
97
98 skb->protocol=eth_type_trans(skb,dev);
99 skb->dev=dev;
100 save_flags(flags);
101 cli();
102 netif_rx(skb);
103 if(unlock)
104 skb_device_unlock(skb);
105 restore_flags(flags);
106
107 stats->tx_packets++;
108 stats->rx_packets++;
109
110 dev->tbusy = 0;
111
112 return(0);
113 }
114
115 static struct enet_statistics *get_stats(struct device *dev)
116 {
117 return (struct enet_statistics *)dev->priv;
118 }
119
120 static int loopback_open(struct device *dev)
121 {
122 dev->flags|=IFF_LOOPBACK;
123 return 0;
124 }
125
126
127 int loopback_init(struct device *dev)
128 {
129 int i;
130 #if LINUS_EVER_SOLVES_THE_LARGE_ATOMIC_BUFFER_ISSUE
131 dev->mtu = 7900;
132 #else
133
134
135
136 dev->mtu = 2000;
137 #endif
138 dev->tbusy = 0;
139 dev->hard_start_xmit = loopback_xmit;
140 dev->open = NULL;
141 dev->hard_header = eth_header;
142 dev->hard_header_len = ETH_HLEN;
143 dev->addr_len = ETH_ALEN;
144 dev->type = ARPHRD_ETHER;
145 dev->rebuild_header = eth_rebuild_header;
146 dev->open = loopback_open;
147 dev->flags = IFF_LOOPBACK|IFF_BROADCAST;
148 dev->family = AF_INET;
149 #ifdef CONFIG_INET
150 dev->pa_addr = in_aton("127.0.0.1");
151 dev->pa_brdaddr = in_aton("127.255.255.255");
152 dev->pa_mask = in_aton("255.0.0.0");
153 dev->pa_alen = 4;
154 #endif
155 dev->priv = kmalloc(sizeof(struct enet_statistics), GFP_KERNEL);
156 if (dev->priv == NULL)
157 return -ENOMEM;
158 memset(dev->priv, 0, sizeof(struct enet_statistics));
159 dev->get_stats = get_stats;
160
161
162
163
164
165 for (i = 0; i < DEV_NUMBUFFS; i++)
166 skb_queue_head_init(&dev->buffs[i]);
167
168 return(0);
169 };