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