xref: /linux/arch/um/drivers/daemon_kern.c (revision 76467874b83835129dc454e3a7a8e5d1186101b0)
1 /*
2  * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
3  * James Leu (jleu@mindspring.net).
4  * Copyright (C) 2001 by various other people who didn't put their name here.
5  * Licensed under the GPL.
6  */
7 
8 #include "linux/kernel.h"
9 #include "linux/init.h"
10 #include "linux/netdevice.h"
11 #include "linux/etherdevice.h"
12 #include "net_kern.h"
13 #include "net_user.h"
14 #include "daemon.h"
15 
16 struct daemon_init {
17 	char *sock_type;
18 	char *ctl_sock;
19 };
20 
21 static void daemon_init(struct net_device *dev, void *data)
22 {
23 	struct uml_net_private *pri;
24 	struct daemon_data *dpri;
25 	struct daemon_init *init = data;
26 
27 	pri = dev->priv;
28 	dpri = (struct daemon_data *) pri->user;
29 	dpri->sock_type = init->sock_type;
30 	dpri->ctl_sock = init->ctl_sock;
31 	dpri->fd = -1;
32 	dpri->control = -1;
33 	dpri->dev = dev;
34 	/* We will free this pointer. If it contains crap we're burned. */
35 	dpri->ctl_addr = NULL;
36 	dpri->data_addr = NULL;
37 	dpri->local_addr = NULL;
38 
39 	printk("daemon backend (uml_switch version %d) - %s:%s",
40 	       SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
41 	printk("\n");
42 }
43 
44 static int daemon_read(int fd, struct sk_buff **skb,
45 		       struct uml_net_private *lp)
46 {
47 	*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
48 	if(*skb == NULL) return(-ENOMEM);
49 	return(net_recvfrom(fd, (*skb)->mac.raw,
50 			    (*skb)->dev->mtu + ETH_HEADER_OTHER));
51 }
52 
53 static int daemon_write(int fd, struct sk_buff **skb,
54 			struct uml_net_private *lp)
55 {
56 	return(daemon_user_write(fd, (*skb)->data, (*skb)->len,
57 				 (struct daemon_data *) &lp->user));
58 }
59 
60 static struct net_kern_info daemon_kern_info = {
61 	.init			= daemon_init,
62 	.protocol		= eth_protocol,
63 	.read			= daemon_read,
64 	.write			= daemon_write,
65 };
66 
67 static int daemon_setup(char *str, char **mac_out, void *data)
68 {
69 	struct daemon_init *init = data;
70 	char *remain;
71 
72 	*init = ((struct daemon_init)
73 		{ .sock_type 		= "unix",
74 		  .ctl_sock 		= "/tmp/uml.ctl" });
75 
76 	remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
77 			       NULL);
78 	if(remain != NULL)
79 		printk(KERN_WARNING "daemon_setup : Ignoring data socket "
80 		       "specification\n");
81 
82 	return(1);
83 }
84 
85 static struct transport daemon_transport = {
86 	.list 		= LIST_HEAD_INIT(daemon_transport.list),
87 	.name 		= "daemon",
88 	.setup  	= daemon_setup,
89 	.user 		= &daemon_user_info,
90 	.kern 		= &daemon_kern_info,
91 	.private_size 	= sizeof(struct daemon_data),
92 	.setup_size 	= sizeof(struct daemon_init),
93 };
94 
95 static int register_daemon(void)
96 {
97 	register_transport(&daemon_transport);
98 	return 0;
99 }
100 
101 __initcall(register_daemon);
102