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