Import 2.3.10pre5
[davej-history.git] / drivers / net / dummy.c
blobc27d4628c126dcd13330aa8aa90547aa3999a8e9
1 /* dummy.c: a dummy net driver
3 The purpose of this driver is to provide a device to point a
4 route through, but not to actually transmit packets.
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.
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
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
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.
26 Nick Holloway, 27th May 1994
27 [I tweaked this explanation a little but that's all]
28 Alan Cox, 30th May 1994
31 /* To have statistics (just packets sent) define this */
33 #include <linux/config.h>
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/sched.h>
37 #include <linux/types.h>
38 #include <linux/fcntl.h>
39 #include <linux/interrupt.h>
40 #include <linux/ptrace.h>
41 #include <linux/ioport.h>
42 #include <linux/in.h>
43 #include <linux/malloc.h>
44 #include <linux/string.h>
45 #include <linux/init.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>
52 #include <linux/netdevice.h>
53 #include <linux/etherdevice.h>
54 #include <linux/skbuff.h>
56 static int dummy_xmit(struct sk_buff *skb, struct device *dev);
57 static struct net_device_stats *dummy_get_stats(struct device *dev);
59 static int dummy_open(struct device *dev)
61 MOD_INC_USE_COUNT;
62 return 0;
65 static int dummy_close(struct device *dev)
67 MOD_DEC_USE_COUNT;
68 return 0;
71 /* fake multicast ability */
72 static void set_multicast_list(struct device *dev)
76 #ifdef CONFIG_NET_FASTROUTE
77 static int dummy_accept_fastpath(struct device *dev, struct dst_entry *dst)
79 return -1;
81 #endif
83 int __init dummy_init(struct device *dev)
85 /* Initialize the device structure. */
86 dev->hard_start_xmit = dummy_xmit;
88 dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
89 if (dev->priv == NULL)
90 return -ENOMEM;
91 memset(dev->priv, 0, sizeof(struct net_device_stats));
92 dev->get_stats = dummy_get_stats;
94 dev->open = dummy_open;
95 dev->stop = dummy_close;
96 dev->set_multicast_list = set_multicast_list;
98 /* Fill in the fields of the device structure with ethernet-generic values. */
99 ether_setup(dev);
100 dev->tx_queue_len = 0;
101 dev->flags |= IFF_NOARP;
102 dev->flags &= ~IFF_MULTICAST;
103 #ifdef CONFIG_NET_FASTROUTE
104 dev->accept_fastpath = dummy_accept_fastpath;
105 #endif
107 return 0;
110 static int dummy_xmit(struct sk_buff *skb, struct device *dev)
112 struct net_device_stats *stats;
113 dev_kfree_skb(skb);
115 stats = (struct net_device_stats *)dev->priv;
116 stats->tx_packets++;
117 stats->tx_bytes+=skb->len;
119 return 0;
122 static struct net_device_stats *dummy_get_stats(struct device *dev)
124 struct net_device_stats *stats = (struct net_device_stats *) dev->priv;
125 return stats;
128 #ifdef MODULE
130 static int __init dummy_probe(struct device *dev)
132 dummy_init(dev);
133 return 0;
136 static char dummy_name[16];
138 static struct device dev_dummy = {
139 dummy_name, /* Needs to be writeable */
140 0, 0, 0, 0,
141 0x0, 0,
142 0, 0, 0, NULL, dummy_probe };
144 int init_module(void)
146 /* Find a name for this unit */
147 int err=dev_alloc_name(&dev_dummy,"dummy%d");
148 if(err<0)
149 return err;
150 if (register_netdev(&dev_dummy) != 0)
151 return -EIO;
152 return 0;
155 void cleanup_module(void)
157 unregister_netdev(&dev_dummy);
158 kfree(dev_dummy.priv);
159 dev_dummy.priv = NULL;
161 #endif /* MODULE */