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 #include <linux/kernel.h>
35 #include <linux/sched.h>
36 #include <linux/types.h>
37 #include <linux/fcntl.h>
38 #include <linux/interrupt.h>
39 #include <linux/ptrace.h>
40 #include <linux/ioport.h>
41 #include <linux/in.h>
42 #include <linux/malloc.h>
43 #include <linux/string.h>
44 #include <asm/system.h>
45 #include <asm/bitops.h>
46 #include <asm/io.h>
47 #include <asm/dma.h>
48 #include <linux/errno.h>
49
50 #include <linux/netdevice.h>
51 #include <linux/etherdevice.h>
52 #include <linux/skbuff.h>
53
54 #ifdef MODULE
55 #include <linux/module.h>
56 #include <linux/version.h>
57 #endif
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 memset(dev->priv, 0, sizeof(struct enet_statistics));
92 dev->get_stats = dummy_get_stats;
93 #endif
94 #ifdef MODULE
95 dev->open = &dummy_open;
96 dev->stop = &dummy_close;
97 #endif
98
99
100 ether_setup(dev);
101 dev->flags |= IFF_NOARP;
102
103 return 0;
104 }
105
106 static int
107 dummy_xmit(struct sk_buff *skb, struct device *dev)
108 {
109 #if DUMMY_STATS
110 struct enet_statistics *stats;
111 #endif
112
113 if (skb == NULL || dev == NULL)
114 return 0;
115
116 dev_kfree_skb(skb, FREE_WRITE);
117
118 #if DUMMY_STATS
119 stats = (struct enet_statistics *)dev->priv;
120 stats->tx_packets++;
121 #endif
122
123 return 0;
124 }
125
126 #if DUMMY_STATS
127 static struct enet_statistics *
128 dummy_get_stats(struct device *dev)
129 {
130 struct enet_statistics *stats = (struct enet_statistics*) dev->priv;
131 return stats;
132 }
133 #endif
134
135 #ifdef MODULE
136 char kernel_version[] = UTS_RELEASE;
137
138 static int dummy_probe(struct device *dev)
139 {
140 dummy_init(dev);
141 return 0;
142 }
143
144 static struct device dev_dummy = {
145 "dummy0\0 ",
146 0, 0, 0, 0,
147 0x0, 0,
148 0, 0, 0, NULL, dummy_probe };
149
150 int init_module(void)
151 {
152
153 int ct= 1;
154
155 while(dev_get(dev_dummy.name)!=NULL && ct<100)
156 {
157 sprintf(dev_dummy.name,"dummy%d",ct);
158 ct++;
159 }
160
161 if (register_netdev(&dev_dummy) != 0)
162 return -EIO;
163 return 0;
164 }
165
166 void cleanup_module(void)
167 {
168 if (MOD_IN_USE)
169 printk("dummy: device busy, remove delayed\n");
170 else
171 {
172 unregister_netdev(&dev_dummy);
173 }
174 }
175 #endif