ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/netback/loopback.c @ 7706:37ad91483bd3

Increase the static constant default number of loopback interfaces, nloopbacks,
to 8. These interfaces are very cheap, so there's no problem having a few
spare. Anyone with more than 8 NICs can still use the kernel command line or
the module parameter line to pass a larger limit to this module.

Detail the kernel command line parameter for nloopbacks in the diagnostic in
network-bridge.

Closes bug #381.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Tue Nov 08 15:15:02 2005 +0100 (2005-11-08)
parents 06d84bf87159
children fcb7e5616102
line source
1 /******************************************************************************
2 * netback/loopback.c
3 *
4 * A two-interface loopback device to emulate a local netfront-netback
5 * connection. This ensures that local packet delivery looks identical
6 * to inter-domain delivery. Most importantly, packets delivered locally
7 * originating from other domains will get *copied* when they traverse this
8 * driver. This prevents unbounded delays in socket-buffer queues from
9 * causing the netback driver to "seize up".
10 *
11 * This driver creates a symmetric pair of loopback interfaces with names
12 * vif0.0 and veth0. The intention is that 'vif0.0' is bound to an Ethernet
13 * bridge, just like a proper netback interface, while a local IP interface
14 * is configured on 'veth0'.
15 *
16 * As with a real netback interface, vif0.0 is configured with a suitable
17 * dummy MAC address. No default is provided for veth0: a reasonable strategy
18 * is to transfer eth0's MAC address to veth0, and give eth0 a dummy address
19 * (to avoid confusing the Etherbridge).
20 *
21 * Copyright (c) 2005 K A Fraser
22 */
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/netdevice.h>
27 #include <linux/inetdevice.h>
28 #include <linux/etherdevice.h>
29 #include <linux/skbuff.h>
30 #include <net/dst.h>
32 static int nloopbacks = 8;
33 module_param(nloopbacks, int, 0);
34 MODULE_PARM_DESC(nloopbacks, "Number of netback-loopback devices to create");
36 struct net_private {
37 struct net_device *loopback_dev;
38 struct net_device_stats stats;
39 };
41 static int loopback_open(struct net_device *dev)
42 {
43 struct net_private *np = netdev_priv(dev);
44 memset(&np->stats, 0, sizeof(np->stats));
45 netif_start_queue(dev);
46 return 0;
47 }
49 static int loopback_close(struct net_device *dev)
50 {
51 netif_stop_queue(dev);
52 return 0;
53 }
55 static int loopback_start_xmit(struct sk_buff *skb, struct net_device *dev)
56 {
57 struct net_private *np = netdev_priv(dev);
59 dst_release(skb->dst);
60 skb->dst = NULL;
62 skb_orphan(skb);
64 np->stats.tx_bytes += skb->len;
65 np->stats.tx_packets++;
67 /* Switch to loopback context. */
68 dev = np->loopback_dev;
69 np = netdev_priv(dev);
71 np->stats.rx_bytes += skb->len;
72 np->stats.rx_packets++;
74 if (skb->ip_summed == CHECKSUM_HW) {
75 /* Defer checksum calculation. */
76 skb->proto_csum_blank = 1;
77 /* Must be a local packet: assert its integrity. */
78 skb->proto_csum_valid = 1;
79 }
81 skb->ip_summed = skb->proto_csum_valid ?
82 CHECKSUM_UNNECESSARY : CHECKSUM_NONE;
84 skb->pkt_type = PACKET_HOST; /* overridden by eth_type_trans() */
85 skb->protocol = eth_type_trans(skb, dev);
86 skb->dev = dev;
87 dev->last_rx = jiffies;
88 netif_rx(skb);
90 return 0;
91 }
93 static struct net_device_stats *loopback_get_stats(struct net_device *dev)
94 {
95 struct net_private *np = netdev_priv(dev);
96 return &np->stats;
97 }
99 static void loopback_construct(struct net_device *dev, struct net_device *lo)
100 {
101 struct net_private *np = netdev_priv(dev);
103 np->loopback_dev = lo;
105 dev->open = loopback_open;
106 dev->stop = loopback_close;
107 dev->hard_start_xmit = loopback_start_xmit;
108 dev->get_stats = loopback_get_stats;
110 dev->tx_queue_len = 0;
112 dev->features = NETIF_F_HIGHDMA | NETIF_F_LLTX;
114 /*
115 * We do not set a jumbo MTU on the interface. Otherwise the network
116 * stack will try to send large packets that will get dropped by the
117 * Ethernet bridge (unless the physical Ethernet interface is
118 * configured to transfer jumbo packets). If a larger MTU is desired
119 * then the system administrator can specify it using the 'ifconfig'
120 * command.
121 */
122 /*dev->mtu = 16*1024;*/
123 }
125 static int __init make_loopback(int i)
126 {
127 struct net_device *dev1, *dev2;
128 char dev_name[IFNAMSIZ];
129 int err = -ENOMEM;
131 sprintf(dev_name, "vif0.%d", i);
132 dev1 = alloc_netdev(sizeof(struct net_private), dev_name, ether_setup);
133 sprintf(dev_name, "veth%d", i);
134 dev2 = alloc_netdev(sizeof(struct net_private), dev_name, ether_setup);
135 if ((dev1 == NULL) || (dev2 == NULL))
136 goto fail;
138 loopback_construct(dev1, dev2);
139 loopback_construct(dev2, dev1);
141 dev1->features |= NETIF_F_NO_CSUM;
142 dev2->features |= NETIF_F_IP_CSUM;
144 /*
145 * Initialise a dummy MAC address for the 'dummy backend' interface. We
146 * choose the numerically largest non-broadcast address to prevent the
147 * address getting stolen by an Ethernet bridge for STP purposes.
148 */
149 memset(dev1->dev_addr, 0xFF, ETH_ALEN);
150 dev1->dev_addr[0] &= ~0x01;
152 if ((err = register_netdev(dev1)) != 0)
153 goto fail;
155 if ((err = register_netdev(dev2)) != 0) {
156 unregister_netdev(dev1);
157 goto fail;
158 }
160 return 0;
162 fail:
163 if (dev1 != NULL)
164 kfree(dev1);
165 if (dev2 != NULL)
166 kfree(dev2);
167 return err;
168 }
170 static int __init loopback_init(void)
171 {
172 int i, err = 0;
174 for (i = 0; i < nloopbacks; i++)
175 if ((err = make_loopback(i)) != 0)
176 break;
178 return err;
179 }
181 module_init(loopback_init);
183 /*
184 * Local variables:
185 * c-file-style: "linux"
186 * indent-tabs-mode: t
187 * c-indent-level: 8
188 * c-basic-offset: 8
189 * tab-width: 8
190 * End:
191 */