2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2007-10-16 02:27:29 -06:00
|
|
|
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
|
2005-04-16 16:20:36 -06:00
|
|
|
* James Leu (jleu@mindspring.net).
|
2007-10-16 02:27:29 -06:00
|
|
|
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-16 16:20:36 -06:00
|
|
|
* Copyright (C) 2001 by various other people who didn't put their name here.
|
|
|
|
* Licensed under the GPL.
|
|
|
|
*/
|
|
|
|
|
2012-10-07 20:27:32 -06:00
|
|
|
#include <linux/init.h>
|
2007-10-16 02:27:29 -06:00
|
|
|
#include <linux/netdevice.h>
|
2012-10-07 20:27:32 -06:00
|
|
|
#include <net_kern.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include "daemon.h"
|
|
|
|
|
|
|
|
struct daemon_init {
|
|
|
|
char *sock_type;
|
|
|
|
char *ctl_sock;
|
|
|
|
};
|
|
|
|
|
2006-02-01 04:06:29 -07:00
|
|
|
static void daemon_init(struct net_device *dev, void *data)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct uml_net_private *pri;
|
|
|
|
struct daemon_data *dpri;
|
|
|
|
struct daemon_init *init = data;
|
|
|
|
|
2008-12-04 16:07:33 -07:00
|
|
|
pri = netdev_priv(dev);
|
2005-04-16 16:20:36 -06:00
|
|
|
dpri = (struct daemon_data *) pri->user;
|
|
|
|
dpri->sock_type = init->sock_type;
|
|
|
|
dpri->ctl_sock = init->ctl_sock;
|
|
|
|
dpri->fd = -1;
|
|
|
|
dpri->control = -1;
|
|
|
|
dpri->dev = dev;
|
2006-01-18 18:42:53 -07:00
|
|
|
/* We will free this pointer. If it contains crap we're burned. */
|
|
|
|
dpri->ctl_addr = NULL;
|
|
|
|
dpri->data_addr = NULL;
|
|
|
|
dpri->local_addr = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:29 -06:00
|
|
|
printk("daemon backend (uml_switch version %d) - %s:%s",
|
2005-04-16 16:20:36 -06:00
|
|
|
SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:31 -06:00
|
|
|
static int daemon_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-10-16 02:27:31 -06:00
|
|
|
return net_recvfrom(fd, skb_mac_header(skb),
|
|
|
|
skb->dev->mtu + ETH_HEADER_OTHER);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:31 -06:00
|
|
|
static int daemon_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-10-16 02:27:31 -06:00
|
|
|
return daemon_user_write(fd, skb->data, skb->len,
|
2007-10-16 02:27:29 -06:00
|
|
|
(struct daemon_data *) &lp->user);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-09-27 02:50:33 -06:00
|
|
|
static const struct net_kern_info daemon_kern_info = {
|
2005-04-16 16:20:36 -06:00
|
|
|
.init = daemon_init,
|
|
|
|
.protocol = eth_protocol,
|
|
|
|
.read = daemon_read,
|
|
|
|
.write = daemon_write,
|
|
|
|
};
|
|
|
|
|
2006-02-01 04:06:29 -07:00
|
|
|
static int daemon_setup(char *str, char **mac_out, void *data)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct daemon_init *init = data;
|
|
|
|
char *remain;
|
|
|
|
|
|
|
|
*init = ((struct daemon_init)
|
|
|
|
{ .sock_type = "unix",
|
|
|
|
.ctl_sock = "/tmp/uml.ctl" });
|
2007-10-16 02:27:29 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
|
|
|
|
NULL);
|
2007-10-16 02:27:29 -06:00
|
|
|
if (remain != NULL)
|
2005-04-16 16:20:36 -06:00
|
|
|
printk(KERN_WARNING "daemon_setup : Ignoring data socket "
|
|
|
|
"specification\n");
|
2007-10-16 02:27:29 -06:00
|
|
|
|
|
|
|
return 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct transport daemon_transport = {
|
|
|
|
.list = LIST_HEAD_INIT(daemon_transport.list),
|
|
|
|
.name = "daemon",
|
|
|
|
.setup = daemon_setup,
|
|
|
|
.user = &daemon_user_info,
|
|
|
|
.kern = &daemon_kern_info,
|
|
|
|
.private_size = sizeof(struct daemon_data),
|
|
|
|
.setup_size = sizeof(struct daemon_init),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int register_daemon(void)
|
|
|
|
{
|
|
|
|
register_transport(&daemon_transport);
|
2006-03-31 03:30:10 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-12-06 21:34:55 -07:00
|
|
|
late_initcall(register_daemon);
|