]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/um/drivers/vde_kern.c
uml: add VDE networking support
[linux-2.6-omap-h63xx.git] / arch / um / drivers / vde_kern.c
1 /*
2  * Copyright (C) 2007 Luca Bigliardi (shammash@artha.org).
3  * Licensed under the GPL.
4  *
5  * Transport usage:
6  *  ethN=vde,<vde_switch>,<mac addr>,<port>,<group>,<mode>,<description>
7  *
8  */
9
10 #include "linux/kernel.h"
11 #include "linux/init.h"
12 #include "linux/netdevice.h"
13 #include "linux/etherdevice.h"
14 #include "net_kern.h"
15 #include "net_user.h"
16 #include "vde.h"
17
18 static void vde_init(struct net_device *dev, void *data)
19 {
20         struct vde_init *init = data;
21         struct uml_net_private *pri;
22         struct vde_data *vpri;
23
24         pri = dev->priv;
25         vpri = (struct vde_data *) pri->user;
26
27         vpri->vde_switch = init->vde_switch;
28         vpri->descr = init->descr ? init->descr : "UML vde_transport";
29         vpri->args = NULL;
30         vpri->conn = NULL;
31         vpri->dev = dev;
32
33         printk(KERN_INFO "vde backend - %s, ", vpri->vde_switch ?
34                vpri->vde_switch : "(default socket)");
35
36         vde_init_libstuff(vpri, init);
37
38         printk(KERN_INFO "\n");
39 }
40
41 static int vde_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
42 {
43         struct vde_data *pri = (struct vde_data *) &lp->user;
44
45         if (pri->conn != NULL) {
46                 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
47                 if (*skb == NULL)
48                         return -ENOMEM;
49
50                 return vde_user_read(pri->conn, skb_mac_header(*skb),
51                                      (*skb)->dev->mtu + ETH_HEADER_OTHER);
52         }
53
54         printk(KERN_ERR "vde_read - we have no VDECONN to read from");
55         return -EBADF;
56 }
57
58 static int vde_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
59 {
60         struct vde_data *pri = (struct vde_data *) &lp->user;
61
62         if (pri->conn != NULL)
63                 return vde_user_write((void *)pri->conn, (*skb)->data,
64                                       (*skb)->len);
65
66         printk(KERN_ERR "vde_write - we have no VDECONN to write to");
67         return -EBADF;
68 }
69
70 static const struct net_kern_info vde_kern_info = {
71         .init                   = vde_init,
72         .protocol               = eth_protocol,
73         .read                   = vde_read,
74         .write                  = vde_write,
75 };
76
77 static int vde_setup(char *str, char **mac_out, void *data)
78 {
79         struct vde_init *init = data;
80         char *remain, *port_str = NULL, *mode_str = NULL, *last;
81
82         *init = ((struct vde_init)
83                 { .vde_switch           = NULL,
84                   .descr                = NULL,
85                   .port                 = 0,
86                   .group                = NULL,
87                   .mode                 = 0 });
88
89         remain = split_if_spec(str, &init->vde_switch, mac_out, &port_str,
90                                 &init->group, &mode_str, &init->descr, NULL);
91
92         if (remain != NULL)
93                 printk(KERN_WARNING "vde_setup - Ignoring extra data :"
94                        "'%s'\n", remain);
95
96         if (port_str != NULL) {
97                 init->port = simple_strtoul(port_str, &last, 10);
98                 if ((*last != '\0') || (last == port_str)) {
99                         printk(KERN_ERR "vde_setup - Bad port : '%s'\n",
100                                                 port_str);
101                         return 0;
102                 }
103         }
104
105         if (mode_str != NULL) {
106                 init->mode = simple_strtoul(mode_str, &last, 8);
107                 if ((*last != '\0') || (last == mode_str)) {
108                         printk(KERN_ERR "vde_setup - Bad mode : '%s'\n",
109                                                 mode_str);
110                         return 0;
111                 }
112         }
113
114         printk(KERN_INFO "Configured vde device: %s\n", init->vde_switch ?
115                init->vde_switch : "(default socket)");
116
117         return 1;
118 }
119
120 static struct transport vde_transport = {
121         .list           = LIST_HEAD_INIT(vde_transport.list),
122         .name           = "vde",
123         .setup          = vde_setup,
124         .user           = &vde_user_info,
125         .kern           = &vde_kern_info,
126         .private_size   = sizeof(struct vde_data),
127         .setup_size     = sizeof(struct vde_init),
128 };
129
130 static int register_vde(void)
131 {
132         register_transport(&vde_transport);
133         return 0;
134 }
135
136 late_initcall(register_vde);