cleanup
[linux-2.4.21-pre4.git] / drivers / net / dummy.c
1 /* dummy.c: a dummy net driver
2
3         The purpose of this driver is to provide a device to point a
4         route through, but not to actually transmit packets.
5
6         Why?  If you have a machine whose only connection is an occasional
7         PPP/SLIP/PLIP link, you can only connect to your own hostname
8         when the link is up.  Otherwise you have to use localhost.
9         This isn't very consistent.
10
11         One solution is to set up a dummy link using PPP/SLIP/PLIP,
12         but this seems (to me) too much overhead for too little gain.
13         This driver provides a small alternative. Thus you can do
14         
15         [when not running slip]
16                 ifconfig dummy slip.addr.ess.here up
17         [to go to slip]
18                 ifconfig dummy down
19                 dip whatever
20
21         This was written by looking at Donald Becker's skeleton driver
22         and the loopback driver.  I then threw away anything that didn't
23         apply!  Thanks to Alan Cox for the key clue on what to do with
24         misguided packets.
25
26                         Nick Holloway, 27th May 1994
27         [I tweaked this explanation a little but that's all]
28                         Alan Cox, 30th May 1994
29 */
30
31 /* To have statistics (just packets sent) define this */
32
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/netdevice.h>
37 #include <linux/init.h>
38
39 static int dummy_xmit(struct sk_buff *skb, struct net_device *dev);
40 static struct net_device_stats *dummy_get_stats(struct net_device *dev);
41
42 /* fake multicast ability */
43 static void set_multicast_list(struct net_device *dev)
44 {
45 }
46
47 #ifdef CONFIG_NET_FASTROUTE
48 static int dummy_accept_fastpath(struct net_device *dev, struct dst_entry *dst)
49 {
50         return -1;
51 }
52 #endif
53
54 static int __init dummy_init(struct net_device *dev)
55 {
56         /* Initialize the device structure. */
57
58         dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
59         if (dev->priv == NULL)
60                 return -ENOMEM;
61         memset(dev->priv, 0, sizeof(struct net_device_stats));
62
63         dev->get_stats = dummy_get_stats;
64         dev->hard_start_xmit = dummy_xmit;
65         dev->set_multicast_list = set_multicast_list;
66 #ifdef CONFIG_NET_FASTROUTE
67         dev->accept_fastpath = dummy_accept_fastpath;
68 #endif
69
70         /* Fill in device structure with ethernet-generic values. */
71         ether_setup(dev);
72         dev->tx_queue_len = 0;
73         dev->flags |= IFF_NOARP;
74         dev->flags &= ~IFF_MULTICAST;
75
76         return 0;
77 }
78
79 static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)
80 {
81         struct net_device_stats *stats = dev->priv;
82
83         stats->tx_packets++;
84         stats->tx_bytes+=skb->len;
85
86         dev_kfree_skb(skb);
87         return 0;
88 }
89
90 static struct net_device_stats *dummy_get_stats(struct net_device *dev)
91 {
92         return dev->priv;
93 }
94
95 static struct net_device dev_dummy;
96
97 static int __init dummy_init_module(void)
98 {
99         int err;
100
101         dev_dummy.init = dummy_init;
102         SET_MODULE_OWNER(&dev_dummy);
103
104         /* Find a name for this unit */
105         err=dev_alloc_name(&dev_dummy,"dummy%d");
106         if(err<0)
107                 return err;
108         err = register_netdev(&dev_dummy);
109         if (err<0)
110                 return err;
111         return 0;
112 }
113
114 static void __exit dummy_cleanup_module(void)
115 {
116         unregister_netdev(&dev_dummy);
117         kfree(dev_dummy.priv);
118
119         memset(&dev_dummy, 0, sizeof(dev_dummy));
120         dev_dummy.init = dummy_init;
121 }
122
123 module_init(dummy_init_module);
124 module_exit(dummy_cleanup_module);
125 MODULE_LICENSE("GPL");