blob: 59811cc880e0fa18066f76fba8ba8fa76798b8a6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jeff Dikecd1ae0e2007-10-16 01:27:29 -07002 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Jeff Dikef28169d2007-02-10 01:43:53 -08003 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * James Leu (jleu@mindspring.net).
5 * Copyright (C) 2001 by various other people who didn't put their name here.
6 * Licensed under the GPL.
7 */
8
Jeff Dikecd1ae0e2007-10-16 01:27:29 -07009#include <linux/bootmem.h>
10#include <linux/etherdevice.h>
11#include <linux/ethtool.h>
12#include <linux/inetdevice.h>
13#include <linux/init.h>
14#include <linux/list.h>
15#include <linux/netdevice.h>
16#include <linux/platform_device.h>
17#include <linux/rtnetlink.h>
18#include <linux/skbuff.h>
19#include <linux/spinlock.h>
20#include "init.h"
21#include "irq_kern.h"
22#include "irq_user.h"
23#include "mconsole_kern.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "net_kern.h"
25#include "net_user.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Paolo 'Blaisorblade' Giarrussobf61f502006-09-25 23:33:07 -070027static inline void set_ether_mac(struct net_device *dev, unsigned char *addr)
28{
29 memcpy(dev->dev_addr, addr, ETH_ALEN);
30}
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define DRIVER_NAME "uml-netdev"
33
34static DEFINE_SPINLOCK(opened_lock);
Jeff Dike90107722006-01-06 00:18:54 -080035static LIST_HEAD(opened);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37static int uml_net_rx(struct net_device *dev)
38{
39 struct uml_net_private *lp = dev->priv;
40 int pkt_len;
41 struct sk_buff *skb;
42
43 /* If we can't allocate memory, try again next round. */
Jeff Dikeb53f35a2007-10-16 01:27:31 -070044 skb = dev_alloc_skb(lp->max_packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 if (skb == NULL) {
46 lp->stats.rx_dropped++;
47 return 0;
48 }
49
50 skb->dev = dev;
Jeff Dikeb53f35a2007-10-16 01:27:31 -070051 skb_put(skb, lp->max_packet);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -070052 skb_reset_mac_header(skb);
Jeff Dikeb53f35a2007-10-16 01:27:31 -070053 pkt_len = (*lp->read)(lp->fd, skb, lp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 if (pkt_len > 0) {
56 skb_trim(skb, pkt_len);
57 skb->protocol = (*lp->protocol)(skb);
58 netif_rx(skb);
59
60 lp->stats.rx_bytes += skb->len;
61 lp->stats.rx_packets++;
62 return pkt_len;
63 }
64
65 kfree_skb(skb);
66 return pkt_len;
67}
68
Peter Zijlstraeff3b632006-12-13 00:33:50 -080069static void uml_dev_close(struct work_struct *work)
Paolo 'Blaisorblade' Giarrusso71c8d4c2006-01-18 17:42:56 -080070{
Peter Zijlstraeff3b632006-12-13 00:33:50 -080071 struct uml_net_private *lp =
72 container_of(work, struct uml_net_private, work);
73 dev_close(lp->dev);
Paolo 'Blaisorblade' Giarrusso71c8d4c2006-01-18 17:42:56 -080074}
75
Al Viro7bea96f2006-10-08 22:49:34 +010076irqreturn_t uml_net_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 struct net_device *dev = dev_id;
79 struct uml_net_private *lp = dev->priv;
80 int err;
81
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070082 if (!netif_running(dev))
83 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 spin_lock(&lp->lock);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070086 while ((err = uml_net_rx(dev)) > 0) ;
87 if (err < 0) {
Jeff Dikef28169d2007-02-10 01:43:53 -080088 printk(KERN_ERR
89 "Device '%s' read returned %d, shutting it down\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 dev->name, err);
Paolo 'Blaisorblade' Giarrusso71c8d4c2006-01-18 17:42:56 -080091 /* dev_close can't be called in interrupt context, and takes
92 * again lp->lock.
93 * And dev_close() can be safely called multiple times on the
94 * same device, since it tests for (dev->flags & IFF_UP). So
Peter Zijlstraeff3b632006-12-13 00:33:50 -080095 * there's no harm in delaying the device shutdown.
96 * Furthermore, the workqueue will not re-enqueue an already
97 * enqueued work item. */
98 schedule_work(&lp->work);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 goto out;
100 }
101 reactivate_fd(lp->fd, UM_ETH_IRQ);
102
Paolo 'Blaisorblade' Giarrusso71c8d4c2006-01-18 17:42:56 -0800103out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 spin_unlock(&lp->lock);
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800105 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
107
108static int uml_net_open(struct net_device *dev)
109{
110 struct uml_net_private *lp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 int err;
112
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700113 if (lp->fd >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 err = -ENXIO;
115 goto out;
116 }
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 lp->fd = (*lp->open)(&lp->user);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700119 if (lp->fd < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 err = lp->fd;
121 goto out;
122 }
123
124 err = um_request_irq(dev->irq, lp->fd, IRQ_READ, uml_net_interrupt,
Thomas Gleixnerbd6aa652006-07-01 19:29:27 -0700125 IRQF_DISABLED | IRQF_SHARED, dev->name, dev);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700126 if (err != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 printk(KERN_ERR "uml_net_open: failed to get irq(%d)\n", err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 err = -ENETUNREACH;
Jeff Dike14d9ead2006-02-07 12:58:42 -0800129 goto out_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
132 lp->tl.data = (unsigned long) &lp->user;
133 netif_start_queue(dev);
134
135 /* clear buffer - it can happen that the host side of the interface
136 * is full when we get here. In this case, new data is never queued,
137 * SIGIOs never arrive, and the net never works.
138 */
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700139 while ((err = uml_net_rx(dev)) > 0) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Jeff Dike14d9ead2006-02-07 12:58:42 -0800141 spin_lock(&opened_lock);
142 list_add(&lp->list, &opened);
143 spin_unlock(&opened_lock);
144
145 return 0;
146out_close:
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700147 if (lp->close != NULL) (*lp->close)(lp->fd, &lp->user);
Jeff Dike14d9ead2006-02-07 12:58:42 -0800148 lp->fd = -1;
149out:
Jeff Dike14d9ead2006-02-07 12:58:42 -0800150 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
153static int uml_net_close(struct net_device *dev)
154{
155 struct uml_net_private *lp = dev->priv;
Jeff Dikef28169d2007-02-10 01:43:53 -0800156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 free_irq(dev->irq, dev);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700160 if (lp->close != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 (*lp->close)(lp->fd, &lp->user);
162 lp->fd = -1;
163
Jeff Dike14d9ead2006-02-07 12:58:42 -0800164 spin_lock(&opened_lock);
165 list_del(&lp->list);
166 spin_unlock(&opened_lock);
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return 0;
169}
170
171static int uml_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
172{
173 struct uml_net_private *lp = dev->priv;
174 unsigned long flags;
175 int len;
176
177 netif_stop_queue(dev);
178
179 spin_lock_irqsave(&lp->lock, flags);
180
Jeff Dikeb53f35a2007-10-16 01:27:31 -0700181 len = (*lp->write)(lp->fd, skb, lp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700183 if (len == skb->len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 lp->stats.tx_packets++;
185 lp->stats.tx_bytes += skb->len;
186 dev->trans_start = jiffies;
187 netif_start_queue(dev);
188
189 /* this is normally done in the interrupt when tx finishes */
190 netif_wake_queue(dev);
Jeff Dikef28169d2007-02-10 01:43:53 -0800191 }
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700192 else if (len == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 netif_start_queue(dev);
194 lp->stats.tx_dropped++;
195 }
196 else {
197 netif_start_queue(dev);
198 printk(KERN_ERR "uml_net_start_xmit: failed(%d)\n", len);
199 }
200
201 spin_unlock_irqrestore(&lp->lock, flags);
202
203 dev_kfree_skb(skb);
204
205 return 0;
206}
207
208static struct net_device_stats *uml_net_get_stats(struct net_device *dev)
209{
210 struct uml_net_private *lp = dev->priv;
211 return &lp->stats;
212}
213
214static void uml_net_set_multicast_list(struct net_device *dev)
215{
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700216 if (dev->flags & IFF_PROMISC)
217 return;
218 else if (dev->mc_count)
219 dev->flags |= IFF_ALLMULTI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 else dev->flags &= ~IFF_ALLMULTI;
221}
222
223static void uml_net_tx_timeout(struct net_device *dev)
224{
225 dev->trans_start = jiffies;
226 netif_wake_queue(dev);
227}
228
229static int uml_net_set_mac(struct net_device *dev, void *addr)
230{
231 struct uml_net_private *lp = dev->priv;
232 struct sockaddr *hwaddr = addr;
233
Paolo 'Blaisorblade' Giarrusso48af05e2006-09-27 01:50:31 -0700234 spin_lock_irq(&lp->lock);
Paolo 'Blaisorblade' Giarrussobf61f502006-09-25 23:33:07 -0700235 set_ether_mac(dev, hwaddr->sa_data);
Paolo 'Blaisorblade' Giarrusso48af05e2006-09-27 01:50:31 -0700236 spin_unlock_irq(&lp->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800238 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239}
240
241static int uml_net_change_mtu(struct net_device *dev, int new_mtu)
242{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 dev->mtu = new_mtu;
244
Jeff Dikeb53f35a2007-10-16 01:27:31 -0700245 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
247
Christoph Hellwig6d387482005-11-07 06:21:21 +0100248static void uml_net_get_drvinfo(struct net_device *dev,
249 struct ethtool_drvinfo *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Christoph Hellwig6d387482005-11-07 06:21:21 +0100251 strcpy(info->driver, DRIVER_NAME);
252 strcpy(info->version, "42");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
Christoph Hellwig6d387482005-11-07 06:21:21 +0100255static struct ethtool_ops uml_net_ethtool_ops = {
256 .get_drvinfo = uml_net_get_drvinfo,
257 .get_link = ethtool_op_get_link,
258};
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260void uml_net_user_timer_expire(unsigned long _conn)
261{
262#ifdef undef
263 struct connection *conn = (struct connection *)_conn;
264
265 dprintk(KERN_INFO "uml_net_user_timer_expire [%p]\n", conn);
266 do_connect(conn);
267#endif
268}
269
Paolo 'Blaisorblade' Giarrussoe0247152007-05-06 14:51:13 -0700270static void setup_etheraddr(char *str, unsigned char *addr, char *name)
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700271{
272 char *end;
273 int i;
274
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700275 if (str == NULL)
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700276 goto random;
277
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700278 for (i = 0;i < 6; i++) {
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700279 addr[i] = simple_strtoul(str, &end, 16);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700280 if ((end == str) ||
281 ((*end != ':') && (*end != ',') && (*end != '\0'))) {
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700282 printk(KERN_ERR
283 "setup_etheraddr: failed to parse '%s' "
284 "as an ethernet address\n", str);
285 goto random;
286 }
287 str = end + 1;
288 }
Paolo 'Blaisorblade' Giarrussoe0247152007-05-06 14:51:13 -0700289 if (is_multicast_ether_addr(addr)) {
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700290 printk(KERN_ERR
Paolo 'Blaisorblade' Giarrussoe0247152007-05-06 14:51:13 -0700291 "Attempt to assign a multicast ethernet address to a "
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700292 "device disallowed\n");
293 goto random;
294 }
Paolo 'Blaisorblade' Giarrussoe0247152007-05-06 14:51:13 -0700295 if (!is_valid_ether_addr(addr)) {
296 printk(KERN_ERR
297 "Attempt to assign an invalid ethernet address to a "
298 "device disallowed\n");
299 goto random;
300 }
301 if (!is_local_ether_addr(addr)) {
302 printk(KERN_WARNING
Jeff Dike7d982302007-05-08 00:35:04 -0700303 "Warning: attempt to assign a globally valid ethernet "
304 "address to a device\n");
305 printk(KERN_WARNING "You should better enable the 2nd "
306 "rightmost bit in the first byte of the MAC,\n");
307 printk(KERN_WARNING "i.e. %02x:%02x:%02x:%02x:%02x:%02x\n",
308 addr[0] | 0x02, addr[1], addr[2], addr[3], addr[4],
309 addr[5]);
310 goto random;
Paolo 'Blaisorblade' Giarrussoe0247152007-05-06 14:51:13 -0700311 }
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700312 return;
313
314random:
Paolo 'Blaisorblade' Giarrussoe0247152007-05-06 14:51:13 -0700315 printk(KERN_INFO
316 "Choosing a random ethernet address for device %s\n", name);
Ollie Wildd6c64102006-09-29 15:50:28 -0700317 random_ether_addr(addr);
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700318}
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320static DEFINE_SPINLOCK(devices_lock);
Jeff Dike90107722006-01-06 00:18:54 -0800321static LIST_HEAD(devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Russell King3ae5eae2005-11-09 22:32:44 +0000323static struct platform_driver uml_net_driver = {
324 .driver = {
325 .name = DRIVER_NAME,
326 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327};
328static int driver_registered;
329
Jeff Dike2e3f5252007-05-06 14:51:29 -0700330static void net_device_release(struct device *dev)
331{
332 struct uml_net *device = dev->driver_data;
333 struct net_device *netdev = device->dev;
334 struct uml_net_private *lp = netdev->priv;
335
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700336 if (lp->remove != NULL)
Jeff Dike2e3f5252007-05-06 14:51:29 -0700337 (*lp->remove)(&lp->user);
338 list_del(&device->list);
339 kfree(device);
340 free_netdev(netdev);
341}
342
Jeff Dikef34d9d22007-05-06 14:51:04 -0700343static void eth_configure(int n, void *init, char *mac,
344 struct transport *transport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
346 struct uml_net *device;
347 struct net_device *dev;
348 struct uml_net_private *lp;
Paolo 'Blaisorblade' Giarrussoc74c69b2007-05-06 14:51:15 -0700349 int err, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Paolo 'Blaisorblade' Giarrussoc74c69b2007-05-06 14:51:15 -0700351 size = transport->private_size + sizeof(struct uml_net_private);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Yan Burman0268bd02006-12-12 19:54:52 +0100353 device = kzalloc(sizeof(*device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (device == NULL) {
Paolo 'Blaisorblade' Giarrusso8c840832007-05-06 14:51:14 -0700355 printk(KERN_ERR "eth_configure failed to allocate struct "
356 "uml_net\n");
Jeff Dikef34d9d22007-05-06 14:51:04 -0700357 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
359
Paolo 'Blaisorblade' Giarrusso8c840832007-05-06 14:51:14 -0700360 dev = alloc_etherdev(size);
361 if (dev == NULL) {
362 printk(KERN_ERR "eth_configure: failed to allocate struct "
363 "net_device for eth%d\n", n);
364 goto out_free_device;
365 }
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 INIT_LIST_HEAD(&device->list);
368 device->index = n;
369
Paolo 'Blaisorblade' Giarrussoe0247152007-05-06 14:51:13 -0700370 /* If this name ends up conflicting with an existing registered
371 * netdevice, that is OK, register_netdev{,ice}() will notice this
372 * and fail.
373 */
Paolo 'Blaisorblade' Giarrusso8c840832007-05-06 14:51:14 -0700374 snprintf(dev->name, sizeof(dev->name), "eth%d", n);
Paolo 'Blaisorblade' Giarrussoe0247152007-05-06 14:51:13 -0700375
Paolo 'Blaisorblade' Giarrusso8c840832007-05-06 14:51:14 -0700376 setup_etheraddr(mac, device->mac, dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 printk(KERN_INFO "Netdevice %d ", n);
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700379 printk("(%02x:%02x:%02x:%02x:%02x:%02x) ",
380 device->mac[0], device->mac[1],
381 device->mac[2], device->mac[3],
382 device->mac[4], device->mac[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 printk(": ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Paolo 'Blaisorblade' Giarrussoe56a7882006-01-18 17:42:55 -0800385 lp = dev->priv;
386 /* This points to the transport private data. It's still clear, but we
387 * must memset it to 0 *now*. Let's help the drivers. */
388 memset(lp, 0, size);
Peter Zijlstraeff3b632006-12-13 00:33:50 -0800389 INIT_WORK(&lp->work, uml_dev_close);
Paolo 'Blaisorblade' Giarrussoe56a7882006-01-18 17:42:55 -0800390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 /* sysfs register */
392 if (!driver_registered) {
Russell King3ae5eae2005-11-09 22:32:44 +0000393 platform_driver_register(&uml_net_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 driver_registered = 1;
395 }
396 device->pdev.id = n;
397 device->pdev.name = DRIVER_NAME;
Jeff Dike2e3f5252007-05-06 14:51:29 -0700398 device->pdev.dev.release = net_device_release;
399 device->pdev.dev.driver_data = device;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700400 if (platform_device_register(&device->pdev))
Jeff Dikef34d9d22007-05-06 14:51:04 -0700401 goto out_free_netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 SET_NETDEV_DEV(dev,&device->pdev.dev);
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 device->dev = dev;
405
Jeff Dikef34d9d22007-05-06 14:51:04 -0700406 /*
407 * These just fill in a data structure, so there's no failure
408 * to be worried about.
409 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 (*transport->kern->init)(dev, init);
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 *lp = ((struct uml_net_private)
413 { .list = LIST_HEAD_INIT(lp->list),
414 .dev = dev,
415 .fd = -1,
416 .mac = { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0},
Jeff Dikeb53f35a2007-10-16 01:27:31 -0700417 .max_packet = transport->user->max_packet,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .protocol = transport->kern->protocol,
419 .open = transport->user->open,
420 .close = transport->user->close,
421 .remove = transport->user->remove,
422 .read = transport->kern->read,
423 .write = transport->kern->write,
424 .add_address = transport->user->add_address,
Jeff Dikeb53f35a2007-10-16 01:27:31 -0700425 .delete_address = transport->user->delete_address });
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 init_timer(&lp->tl);
428 spin_lock_init(&lp->lock);
429 lp->tl.function = uml_net_user_timer_expire;
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700430 memcpy(lp->mac, device->mac, sizeof(lp->mac));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Jeff Dikef34d9d22007-05-06 14:51:04 -0700432 if ((transport->user->init != NULL) &&
433 ((*transport->user->init)(&lp->user, dev) != 0))
434 goto out_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Jeff Dikeb10aeee2006-09-29 01:58:50 -0700436 set_ether_mac(dev, device->mac);
Jeff Dikeb53f35a2007-10-16 01:27:31 -0700437 dev->mtu = transport->user->mtu;
Jeff Dikef34d9d22007-05-06 14:51:04 -0700438 dev->open = uml_net_open;
439 dev->hard_start_xmit = uml_net_start_xmit;
440 dev->stop = uml_net_close;
441 dev->get_stats = uml_net_get_stats;
442 dev->set_multicast_list = uml_net_set_multicast_list;
443 dev->tx_timeout = uml_net_tx_timeout;
444 dev->set_mac_address = uml_net_set_mac;
445 dev->change_mtu = uml_net_change_mtu;
446 dev->ethtool_ops = &uml_net_ethtool_ops;
447 dev->watchdog_timeo = (HZ >> 1);
448 dev->irq = UM_ETH_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Jeff Dikef34d9d22007-05-06 14:51:04 -0700450 rtnl_lock();
451 err = register_netdevice(dev);
452 rtnl_unlock();
453 if (err)
454 goto out_undo_user_init;
455
456 spin_lock(&devices_lock);
457 list_add(&device->list, &devices);
458 spin_unlock(&devices_lock);
459
460 return;
461
462out_undo_user_init:
Paolo 'Blaisorblade' Giarrusso8c840832007-05-06 14:51:14 -0700463 if (transport->user->remove != NULL)
Jeff Dikef34d9d22007-05-06 14:51:04 -0700464 (*transport->user->remove)(&lp->user);
465out_unregister:
466 platform_device_unregister(&device->pdev);
Jeff Dike7d982302007-05-08 00:35:04 -0700467 return; /* platform_device_unregister frees dev and device */
Jeff Dikef34d9d22007-05-06 14:51:04 -0700468out_free_netdev:
469 free_netdev(dev);
Paolo 'Blaisorblade' Giarrusso8c840832007-05-06 14:51:14 -0700470out_free_device:
Jeff Dikef34d9d22007-05-06 14:51:04 -0700471 kfree(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
474static struct uml_net *find_device(int n)
475{
476 struct uml_net *device;
477 struct list_head *ele;
478
479 spin_lock(&devices_lock);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700480 list_for_each(ele, &devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 device = list_entry(ele, struct uml_net, list);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700482 if (device->index == n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 goto out;
484 }
485 device = NULL;
486 out:
487 spin_unlock(&devices_lock);
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800488 return device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
490
Jeff Dikef28169d2007-02-10 01:43:53 -0800491static int eth_parse(char *str, int *index_out, char **str_out,
492 char **error_out)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
494 char *end;
Jeff Dikef28169d2007-02-10 01:43:53 -0800495 int n, err = -EINVAL;;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 n = simple_strtoul(str, &end, 0);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700498 if (end == str) {
Jeff Dikef28169d2007-02-10 01:43:53 -0800499 *error_out = "Bad device number";
500 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
Jeff Dikef28169d2007-02-10 01:43:53 -0800502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 str = end;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700504 if (*str != '=') {
Jeff Dikef28169d2007-02-10 01:43:53 -0800505 *error_out = "Expected '=' after device number";
506 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
Jeff Dikef28169d2007-02-10 01:43:53 -0800508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 str++;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700510 if (find_device(n)) {
Jeff Dikef28169d2007-02-10 01:43:53 -0800511 *error_out = "Device already configured";
512 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
Jeff Dikef28169d2007-02-10 01:43:53 -0800514
515 *index_out = n;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 *str_out = str;
Jeff Dikef28169d2007-02-10 01:43:53 -0800517 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518}
519
520struct eth_init {
521 struct list_head list;
522 char *init;
523 int index;
524};
525
Jeff Diked3b7f692007-02-10 01:43:56 -0800526static DEFINE_SPINLOCK(transports_lock);
527static LIST_HEAD(transports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529/* Filled in during early boot */
Jeff Dikec862fc32007-02-10 01:44:04 -0800530static LIST_HEAD(eth_cmd_line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532static int check_transport(struct transport *transport, char *eth, int n,
533 void **init_out, char **mac_out)
534{
535 int len;
536
537 len = strlen(transport->name);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700538 if (strncmp(eth, transport->name, len))
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800539 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541 eth += len;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700542 if (*eth == ',')
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 eth++;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700544 else if (*eth != '\0')
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800545 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 *init_out = kmalloc(transport->setup_size, GFP_KERNEL);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700548 if (*init_out == NULL)
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800549 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700551 if (!transport->setup(eth, mac_out, *init_out)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 kfree(*init_out);
553 *init_out = NULL;
554 }
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800555 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
558void register_transport(struct transport *new)
559{
560 struct list_head *ele, *next;
561 struct eth_init *eth;
562 void *init;
563 char *mac = NULL;
564 int match;
565
Jeff Diked3b7f692007-02-10 01:43:56 -0800566 spin_lock(&transports_lock);
567 BUG_ON(!list_empty(&new->list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 list_add(&new->list, &transports);
Jeff Diked3b7f692007-02-10 01:43:56 -0800569 spin_unlock(&transports_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700571 list_for_each_safe(ele, next, &eth_cmd_line) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 eth = list_entry(ele, struct eth_init, list);
573 match = check_transport(new, eth->init, eth->index, &init,
574 &mac);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700575 if (!match)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 continue;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700577 else if (init != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 eth_configure(eth->index, init, mac, new);
579 kfree(init);
580 }
581 list_del(&eth->list);
582 }
583}
584
585static int eth_setup_common(char *str, int index)
586{
587 struct list_head *ele;
588 struct transport *transport;
589 void *init;
590 char *mac = NULL;
Jeff Dikec862fc32007-02-10 01:44:04 -0800591 int found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Jeff Dikec862fc32007-02-10 01:44:04 -0800593 spin_lock(&transports_lock);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700594 list_for_each(ele, &transports) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 transport = list_entry(ele, struct transport, list);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700596 if (!check_transport(transport, str, index, &init, &mac))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 continue;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700598 if (init != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 eth_configure(index, init, mac, transport);
600 kfree(init);
601 }
Jeff Dikec862fc32007-02-10 01:44:04 -0800602 found = 1;
603 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 }
Jeff Dikec862fc32007-02-10 01:44:04 -0800605
606 spin_unlock(&transports_lock);
607 return found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
Jeff Dike97a1fcb2007-07-23 18:43:48 -0700610static int __init eth_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
612 struct eth_init *new;
Jeff Dikef28169d2007-02-10 01:43:53 -0800613 char *error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 int n, err;
615
Jeff Dikef28169d2007-02-10 01:43:53 -0800616 err = eth_parse(str, &n, &str, &error);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700617 if (err) {
Jeff Dikef28169d2007-02-10 01:43:53 -0800618 printk(KERN_ERR "eth_setup - Couldn't parse '%s' : %s\n",
619 str, error);
Jeff Dike1183dc92006-09-27 01:50:43 -0700620 return 1;
Jeff Dikef28169d2007-02-10 01:43:53 -0800621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Jeff Dike1183dc92006-09-27 01:50:43 -0700623 new = alloc_bootmem(sizeof(*new));
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700624 if (new == NULL) {
625 printk(KERN_ERR "eth_init : alloc_bootmem failed\n");
Jeff Dike1183dc92006-09-27 01:50:43 -0700626 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 }
628
629 INIT_LIST_HEAD(&new->list);
630 new->index = n;
631 new->init = str;
632
633 list_add_tail(&new->list, &eth_cmd_line);
Jeff Dike1183dc92006-09-27 01:50:43 -0700634 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635}
636
637__setup("eth", eth_setup);
638__uml_help(eth_setup,
639"eth[0-9]+=<transport>,<options>\n"
640" Configure a network device.\n\n"
641);
642
Jeff Dikef28169d2007-02-10 01:43:53 -0800643static int net_config(char *str, char **error_out)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644{
645 int n, err;
646
Jeff Dikef28169d2007-02-10 01:43:53 -0800647 err = eth_parse(str, &n, &str, error_out);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700648 if (err)
Jeff Dikef28169d2007-02-10 01:43:53 -0800649 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Jeff Dikef28169d2007-02-10 01:43:53 -0800651 /* This string is broken up and the pieces used by the underlying
652 * driver. So, it is freed only if eth_setup_common fails.
653 */
Jeff Dike970d6e32006-01-06 00:18:48 -0800654 str = kstrdup(str, GFP_KERNEL);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700655 if (str == NULL) {
Jeff Dikef28169d2007-02-10 01:43:53 -0800656 *error_out = "net_config failed to strdup string";
657 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
659 err = !eth_setup_common(str, n);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700660 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 kfree(str);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700662 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
Jeff Dike29d56cf2005-06-25 14:55:25 -0700665static int net_id(char **str, int *start_out, int *end_out)
666{
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700667 char *end;
668 int n;
Jeff Dike29d56cf2005-06-25 14:55:25 -0700669
670 n = simple_strtoul(*str, &end, 0);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700671 if ((*end != '\0') || (end == *str))
Jeff Dike29d56cf2005-06-25 14:55:25 -0700672 return -1;
673
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700674 *start_out = n;
675 *end_out = n;
676 *str = end;
677 return n;
Jeff Dike29d56cf2005-06-25 14:55:25 -0700678}
679
Jeff Dikef28169d2007-02-10 01:43:53 -0800680static int net_remove(int n, char **error_out)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
682 struct uml_net *device;
683 struct net_device *dev;
684 struct uml_net_private *lp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686 device = find_device(n);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700687 if (device == NULL)
Jeff Dike29d56cf2005-06-25 14:55:25 -0700688 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690 dev = device->dev;
691 lp = dev->priv;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700692 if (lp->fd > 0)
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800693 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 unregister_netdev(dev);
695 platform_device_unregister(&device->pdev);
696
Jeff Dike29d56cf2005-06-25 14:55:25 -0700697 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
700static struct mc_device net_mc = {
Jeff Dike84f48d42007-02-10 01:44:01 -0800701 .list = LIST_HEAD_INIT(net_mc.list),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .name = "eth",
703 .config = net_config,
704 .get_config = NULL,
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800705 .id = net_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 .remove = net_remove,
707};
708
709static int uml_inetaddr_event(struct notifier_block *this, unsigned long event,
710 void *ptr)
711{
712 struct in_ifaddr *ifa = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 struct net_device *dev = ifa->ifa_dev->dev;
714 struct uml_net_private *lp;
715 void (*proc)(unsigned char *, unsigned char *, void *);
716 unsigned char addr_buf[4], netmask_buf[4];
717
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700718 if (dev->open != uml_net_open)
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800719 return NOTIFY_DONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721 lp = dev->priv;
722
723 proc = NULL;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700724 switch (event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 case NETDEV_UP:
726 proc = lp->add_address;
727 break;
728 case NETDEV_DOWN:
729 proc = lp->delete_address;
730 break;
731 }
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700732 if (proc != NULL) {
Bodo Stroesser0e764222005-11-07 00:58:47 -0800733 memcpy(addr_buf, &ifa->ifa_address, sizeof(addr_buf));
734 memcpy(netmask_buf, &ifa->ifa_mask, sizeof(netmask_buf));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 (*proc)(addr_buf, netmask_buf, &lp->user);
736 }
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800737 return NOTIFY_DONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
Jeff Dikec862fc32007-02-10 01:44:04 -0800740/* uml_net_init shouldn't be called twice on two CPUs at the same time */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741struct notifier_block uml_inetaddr_notifier = {
742 .notifier_call = uml_inetaddr_event,
743};
744
745static int uml_net_init(void)
746{
747 struct list_head *ele;
Jeff Dikef28169d2007-02-10 01:43:53 -0800748 struct uml_net_private *lp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 struct in_device *ip;
750 struct in_ifaddr *in;
751
752 mconsole_register_dev(&net_mc);
753 register_inetaddr_notifier(&uml_inetaddr_notifier);
754
755 /* Devices may have been opened already, so the uml_inetaddr_notifier
756 * didn't get a chance to run for them. This fakes it so that
757 * addresses which have already been set up get handled properly.
758 */
Jeff Dikec862fc32007-02-10 01:44:04 -0800759 spin_lock(&opened_lock);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700760 list_for_each(ele, &opened) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 lp = list_entry(ele, struct uml_net_private, list);
762 ip = lp->dev->ip_ptr;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700763 if (ip == NULL)
Jeff Dikec862fc32007-02-10 01:44:04 -0800764 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 in = ip->ifa_list;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700766 while (in != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 uml_inetaddr_event(NULL, NETDEV_UP, in);
768 in = in->ifa_next;
769 }
Jeff Dikef28169d2007-02-10 01:43:53 -0800770 }
Jeff Dikec862fc32007-02-10 01:44:04 -0800771 spin_unlock(&opened_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Jeff Dikec862fc32007-02-10 01:44:04 -0800773 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774}
775
776__initcall(uml_net_init);
777
778static void close_devices(void)
779{
780 struct list_head *ele;
781 struct uml_net_private *lp;
782
Jeff Dikec862fc32007-02-10 01:44:04 -0800783 spin_lock(&opened_lock);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700784 list_for_each(ele, &opened) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 lp = list_entry(ele, struct uml_net_private, list);
Jeff Dike8d93c702006-01-06 00:19:06 -0800786 free_irq(lp->dev->irq, lp->dev);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700787 if ((lp->close != NULL) && (lp->fd >= 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 (*lp->close)(lp->fd, &lp->user);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700789 if (lp->remove != NULL)
Jeff Dikec862fc32007-02-10 01:44:04 -0800790 (*lp->remove)(&lp->user);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 }
Jeff Dikec862fc32007-02-10 01:44:04 -0800792 spin_unlock(&opened_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}
794
795__uml_exitcall(close_devices);
796
Jeff Dikef28169d2007-02-10 01:43:53 -0800797void iter_addresses(void *d, void (*cb)(unsigned char *, unsigned char *,
798 void *),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 void *arg)
800{
801 struct net_device *dev = d;
802 struct in_device *ip = dev->ip_ptr;
803 struct in_ifaddr *in;
804 unsigned char address[4], netmask[4];
805
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700806 if (ip == NULL) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 in = ip->ifa_list;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700808 while (in != NULL) {
Bodo Stroesser0e764222005-11-07 00:58:47 -0800809 memcpy(address, &in->ifa_address, sizeof(address));
810 memcpy(netmask, &in->ifa_mask, sizeof(netmask));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 (*cb)(address, netmask, arg);
812 in = in->ifa_next;
813 }
814}
815
816int dev_netmask(void *d, void *m)
817{
818 struct net_device *dev = d;
819 struct in_device *ip = dev->ip_ptr;
820 struct in_ifaddr *in;
Al Viroa144ea42006-09-28 18:00:55 -0700821 __be32 *mask_out = m;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700823 if (ip == NULL)
824 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 in = ip->ifa_list;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700827 if (in == NULL)
828 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 *mask_out = in->ifa_mask;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700831 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832}
833
834void *get_output_buffer(int *len_out)
835{
836 void *ret;
837
838 ret = (void *) __get_free_pages(GFP_KERNEL, 0);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700839 if (ret) *len_out = PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 else *len_out = 0;
Jeff Dike4ea21cd2007-02-10 01:43:56 -0800841 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842}
843
844void free_output_buffer(void *buffer)
845{
846 free_pages((unsigned long) buffer, 0);
847}
848
Jeff Dikef28169d2007-02-10 01:43:53 -0800849int tap_setup_common(char *str, char *type, char **dev_name, char **mac_out,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 char **gate_addr)
851{
852 char *remain;
853
854 remain = split_if_spec(str, dev_name, mac_out, gate_addr, NULL);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700855 if (remain != NULL) {
856 printk(KERN_ERR "tap_setup_common - Extra garbage on "
857 "specification : '%s'\n", remain);
858 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 }
860
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700861 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862}
863
864unsigned short eth_protocol(struct sk_buff *skb)
865{
Jeff Dikecd1ae0e2007-10-16 01:27:29 -0700866 return eth_type_trans(skb, skb->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867}