blob: 1b852bffdebcf019d61c66dda7f4da77e4e1ff1f [file] [log] [blame]
Jeff Dikead43c352007-10-16 01:26:48 -07001/*
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
Jeff Dikead43c352007-10-16 01:26:48 -070010#include "linux/init.h"
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070011#include <linux/netdevice.h>
Jeff Dikead43c352007-10-16 01:26:48 -070012#include "net_kern.h"
13#include "net_user.h"
14#include "vde.h"
15
16static void vde_init(struct net_device *dev, void *data)
17{
18 struct vde_init *init = data;
19 struct uml_net_private *pri;
20 struct vde_data *vpri;
21
Wang Chen17c324f2008-12-04 15:07:33 -080022 pri = netdev_priv(dev);
Jeff Dikead43c352007-10-16 01:26:48 -070023 vpri = (struct vde_data *) pri->user;
24
25 vpri->vde_switch = init->vde_switch;
26 vpri->descr = init->descr ? init->descr : "UML vde_transport";
27 vpri->args = NULL;
28 vpri->conn = NULL;
29 vpri->dev = dev;
30
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070031 printk("vde backend - %s, ", vpri->vde_switch ?
Jeff Dikead43c352007-10-16 01:26:48 -070032 vpri->vde_switch : "(default socket)");
33
34 vde_init_libstuff(vpri, init);
35
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070036 printk("\n");
Jeff Dikead43c352007-10-16 01:26:48 -070037}
38
Jeff Dikeb53f35a2007-10-16 01:27:31 -070039static int vde_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
Jeff Dikead43c352007-10-16 01:26:48 -070040{
41 struct vde_data *pri = (struct vde_data *) &lp->user;
42
Jeff Dikeb53f35a2007-10-16 01:27:31 -070043 if (pri->conn != NULL)
44 return vde_user_read(pri->conn, skb_mac_header(skb),
45 skb->dev->mtu + ETH_HEADER_OTHER);
Jeff Dikead43c352007-10-16 01:26:48 -070046
47 printk(KERN_ERR "vde_read - we have no VDECONN to read from");
48 return -EBADF;
49}
50
Jeff Dikeb53f35a2007-10-16 01:27:31 -070051static int vde_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
Jeff Dikead43c352007-10-16 01:26:48 -070052{
53 struct vde_data *pri = (struct vde_data *) &lp->user;
54
55 if (pri->conn != NULL)
Jeff Dikeb53f35a2007-10-16 01:27:31 -070056 return vde_user_write((void *)pri->conn, skb->data,
57 skb->len);
Jeff Dikead43c352007-10-16 01:26:48 -070058
59 printk(KERN_ERR "vde_write - we have no VDECONN to write to");
60 return -EBADF;
61}
62
63static const struct net_kern_info vde_kern_info = {
64 .init = vde_init,
65 .protocol = eth_protocol,
66 .read = vde_read,
67 .write = vde_write,
68};
69
70static int vde_setup(char *str, char **mac_out, void *data)
71{
72 struct vde_init *init = data;
73 char *remain, *port_str = NULL, *mode_str = NULL, *last;
74
75 *init = ((struct vde_init)
76 { .vde_switch = NULL,
77 .descr = NULL,
78 .port = 0,
79 .group = NULL,
80 .mode = 0 });
81
82 remain = split_if_spec(str, &init->vde_switch, mac_out, &port_str,
83 &init->group, &mode_str, &init->descr, NULL);
84
85 if (remain != NULL)
86 printk(KERN_WARNING "vde_setup - Ignoring extra data :"
87 "'%s'\n", remain);
88
89 if (port_str != NULL) {
90 init->port = simple_strtoul(port_str, &last, 10);
91 if ((*last != '\0') || (last == port_str)) {
92 printk(KERN_ERR "vde_setup - Bad port : '%s'\n",
93 port_str);
94 return 0;
95 }
96 }
97
98 if (mode_str != NULL) {
99 init->mode = simple_strtoul(mode_str, &last, 8);
100 if ((*last != '\0') || (last == mode_str)) {
101 printk(KERN_ERR "vde_setup - Bad mode : '%s'\n",
102 mode_str);
103 return 0;
104 }
105 }
106
107 printk(KERN_INFO "Configured vde device: %s\n", init->vde_switch ?
108 init->vde_switch : "(default socket)");
109
110 return 1;
111}
112
113static struct transport vde_transport = {
114 .list = LIST_HEAD_INIT(vde_transport.list),
115 .name = "vde",
116 .setup = vde_setup,
117 .user = &vde_user_info,
118 .kern = &vde_kern_info,
119 .private_size = sizeof(struct vde_data),
120 .setup_size = sizeof(struct vde_init),
121};
122
123static int register_vde(void)
124{
125 register_transport(&vde_transport);
126 return 0;
127}
128
129late_initcall(register_vde);