This source file includes following definitions.
- dummy_open
- dummy_close
- dummy_init
- dummy_xmit
- dummy_get_stats
- dummy_probe
- init_module
- cleanup_module
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
27
28
29
30
31
32 #undef DUMMY_STATS
33
34 #ifdef MODULE
35 #include <linux/module.h>
36 #include <linux/version.h>
37 #endif
38
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/types.h>
42 #include <linux/fcntl.h>
43 #include <linux/interrupt.h>
44 #include <linux/ptrace.h>
45 #include <linux/ioport.h>
46 #include <linux/in.h>
47 #include <linux/malloc.h>
48 #include <linux/string.h>
49 #include <asm/system.h>
50 #include <asm/bitops.h>
51 #include <asm/io.h>
52 #include <asm/dma.h>
53 #include <linux/errno.h>
54
55 #include <linux/netdevice.h>
56 #include <linux/etherdevice.h>
57 #include <linux/skbuff.h>
58
59 static int dummy_xmit(struct sk_buff *skb, struct device *dev);
60 #ifdef DUMMY_STATS
61 static struct enet_statistics *dummy_get_stats(struct device *dev);
62 #endif
63
64 #ifdef MODULE
65 static int dummy_open(struct device *dev)
66 {
67 MOD_INC_USE_COUNT;
68 return 0;
69 }
70
71 static int dummy_close(struct device *dev)
72 {
73 MOD_DEC_USE_COUNT;
74 return 0;
75 }
76
77 #endif
78
79
80 int dummy_init(struct device *dev)
81 {
82
83
84
85
86
87 dev->hard_start_xmit = dummy_xmit;
88
89 #if DUMMY_STATS
90 dev->priv = kmalloc(sizeof(struct enet_statistics), GFP_KERNEL);
91 if (dev->priv == NULL)
92 return -ENOMEM;
93 memset(dev->priv, 0, sizeof(struct enet_statistics));
94 dev->get_stats = dummy_get_stats;
95 #endif
96 #ifdef MODULE
97 dev->open = &dummy_open;
98 dev->stop = &dummy_close;
99 #endif
100
101
102 ether_setup(dev);
103 dev->flags |= IFF_NOARP;
104
105 return 0;
106 }
107
108 static int
109 dummy_xmit(struct sk_buff *skb, struct device *dev)
110 {
111 #if DUMMY_STATS
112 struct enet_statistics *stats;
113 #endif
114
115 if (skb == NULL || dev == NULL)
116 return 0;
117
118 dev_kfree_skb(skb, FREE_WRITE);
119
120 #if DUMMY_STATS
121 stats = (struct enet_statistics *)dev->priv;
122 stats->tx_packets++;
123 #endif
124
125 return 0;
126 }
127
128 #if DUMMY_STATS
129 static struct enet_statistics *
130 dummy_get_stats(struct device *dev)
131 {
132 struct enet_statistics *stats = (struct enet_statistics*) dev->priv;
133 return stats;
134 }
135 #endif
136
137 #ifdef MODULE
138 char kernel_version[] = UTS_RELEASE;
139
140 static int dummy_probe(struct device *dev)
141 {
142 dummy_init(dev);
143 return 0;
144 }
145
146 static struct device dev_dummy = {
147 "dummy0\0 ",
148 0, 0, 0, 0,
149 0x0, 0,
150 0, 0, 0, NULL, dummy_probe };
151
152 int init_module(void)
153 {
154
155 int ct= 1;
156
157 while(dev_get(dev_dummy.name)!=NULL && ct<100)
158 {
159 sprintf(dev_dummy.name,"dummy%d",ct);
160 ct++;
161 }
162 if(ct==100)
163 return -ENFILE;
164
165 if (register_netdev(&dev_dummy) != 0)
166 return -EIO;
167 return 0;
168 }
169
170 void cleanup_module(void)
171 {
172 if (MOD_IN_USE)
173 printk("dummy: device busy, remove delayed\n");
174 else
175 {
176 unregister_netdev(&dev_dummy);
177 kfree(dev_dummy.priv);
178 dev_dummy.priv = NULL;
179 }
180 }
181 #endif