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