daemon_kern.c 2.4 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
J
Jeff Dike 已提交
2
 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
L
Linus Torvalds 已提交
3
 * James Leu (jleu@mindspring.net).
J
Jeff Dike 已提交
4
 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
L
Linus Torvalds 已提交
5 6 7 8 9
 * Copyright (C) 2001 by various other people who didn't put their name here.
 * Licensed under the GPL.
 */

#include "linux/init.h"
J
Jeff Dike 已提交
10
#include <linux/netdevice.h>
L
Linus Torvalds 已提交
11 12 13 14 15 16 17 18
#include "net_kern.h"
#include "daemon.h"

struct daemon_init {
	char *sock_type;
	char *ctl_sock;
};

19
static void daemon_init(struct net_device *dev, void *data)
L
Linus Torvalds 已提交
20 21 22 23 24 25 26 27 28 29 30 31
{
	struct uml_net_private *pri;
	struct daemon_data *dpri;
	struct daemon_init *init = data;

	pri = dev->priv;
	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;
32 33 34 35
	/* We will free this pointer. If it contains crap we're burned. */
	dpri->ctl_addr = NULL;
	dpri->data_addr = NULL;
	dpri->local_addr = NULL;
L
Linus Torvalds 已提交
36

J
Jeff Dike 已提交
37
	printk("daemon backend (uml_switch version %d) - %s:%s",
L
Linus Torvalds 已提交
38 39 40 41
	       SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
	printk("\n");
}

J
Jeff Dike 已提交
42
static int daemon_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
L
Linus Torvalds 已提交
43
{
J
Jeff Dike 已提交
44 45
	return net_recvfrom(fd, skb_mac_header(skb),
			    skb->dev->mtu + ETH_HEADER_OTHER);
L
Linus Torvalds 已提交
46 47
}

J
Jeff Dike 已提交
48
static int daemon_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
L
Linus Torvalds 已提交
49
{
J
Jeff Dike 已提交
50
	return daemon_user_write(fd, skb->data, skb->len,
J
Jeff Dike 已提交
51
				 (struct daemon_data *) &lp->user);
L
Linus Torvalds 已提交
52 53
}

J
Jeff Dike 已提交
54
static const struct net_kern_info daemon_kern_info = {
L
Linus Torvalds 已提交
55 56 57 58 59 60
	.init			= daemon_init,
	.protocol		= eth_protocol,
	.read			= daemon_read,
	.write			= daemon_write,
};

61
static int daemon_setup(char *str, char **mac_out, void *data)
L
Linus Torvalds 已提交
62 63 64 65 66 67 68
{
	struct daemon_init *init = data;
	char *remain;

	*init = ((struct daemon_init)
		{ .sock_type 		= "unix",
		  .ctl_sock 		= "/tmp/uml.ctl" });
J
Jeff Dike 已提交
69

L
Linus Torvalds 已提交
70 71
	remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
			       NULL);
J
Jeff Dike 已提交
72
	if (remain != NULL)
L
Linus Torvalds 已提交
73 74
		printk(KERN_WARNING "daemon_setup : Ignoring data socket "
		       "specification\n");
J
Jeff Dike 已提交
75 76

	return 1;
L
Linus Torvalds 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
}

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);
92
	return 0;
L
Linus Torvalds 已提交
93 94
}

95
late_initcall(register_daemon);