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
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
26 Nick Holloway, 27th May 1994
27 [I tweaked this explanation a little but that's all]
28 Alan Cox, 30th May 1994
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/netdevice.h>
34 #include <linux/etherdevice.h>
35 #include <linux/init.h>
36 #include <linux/moduleparam.h>
37 #include <linux/rtnetlink.h>
40 struct net_device *dev;
41 struct list_head list;
44 static int numdummies = 1;
46 static int dummy_xmit(struct sk_buff *skb, struct net_device *dev);
48 static int dummy_set_address(struct net_device *dev, void *p)
50 struct sockaddr *sa = p;
52 if (!is_valid_ether_addr(sa->sa_data))
53 return -EADDRNOTAVAIL;
55 memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
59 /* fake multicast ability */
60 static void set_multicast_list(struct net_device *dev)
64 static void __init dummy_setup(struct net_device *dev)
66 /* Initialize the device structure. */
67 dev->hard_start_xmit = dummy_xmit;
68 dev->set_multicast_list = set_multicast_list;
69 dev->set_mac_address = dummy_set_address;
71 /* Fill in device structure with ethernet-generic values. */
73 dev->tx_queue_len = 0;
74 dev->change_mtu = NULL;
75 dev->flags |= IFF_NOARP;
76 dev->flags &= ~IFF_MULTICAST;
77 SET_MODULE_OWNER(dev);
78 random_ether_addr(dev->dev_addr);
81 static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)
83 dev->stats.tx_packets++;
84 dev->stats.tx_bytes += skb->len;
90 static LIST_HEAD(dummies);
92 /* Number of dummy devices to be set up by this module. */
93 module_param(numdummies, int, 0);
94 MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices");
96 static int __init dummy_init_one(void)
98 struct net_device *dev_dummy;
99 struct dummy_priv *priv;
102 dev_dummy = alloc_netdev(sizeof(struct dummy_priv), "dummy%d",
108 if ((err = register_netdev(dev_dummy))) {
109 free_netdev(dev_dummy);
112 priv = netdev_priv(dev_dummy);
113 priv->dev = dev_dummy;
114 list_add_tail(&priv->list, &dummies);
120 static void dummy_free_one(struct net_device *dev)
122 struct dummy_priv *priv = netdev_priv(dev);
124 list_del(&priv->list);
125 unregister_netdev(dev);
129 static int __init dummy_init_module(void)
131 struct dummy_priv *priv, *next;
134 for (i = 0; i < numdummies && !err; i++)
135 err = dummy_init_one();
137 list_for_each_entry_safe(priv, next, &dummies, list)
138 dummy_free_one(priv->dev);
143 static void __exit dummy_cleanup_module(void)
145 struct dummy_priv *priv, *next;
147 list_for_each_entry_safe(priv, next, &dummies, list)
148 dummy_free_one(priv->dev);
151 module_init(dummy_init_module);
152 module_exit(dummy_cleanup_module);
153 MODULE_LICENSE("GPL");