uml: network formatting
[linux-2.6] / arch / um / os-Linux / drivers / tuntap_kern.c
1 /*
2  * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3  * Licensed under the GPL
4  */
5
6 #include <linux/netdevice.h>
7 #include <linux/init.h>
8 #include <linux/skbuff.h>
9 #include <asm/errno.h>
10 #include "net_kern.h"
11 #include "tuntap.h"
12
13 struct tuntap_init {
14         char *dev_name;
15         char *gate_addr;
16 };
17
18 static void tuntap_init(struct net_device *dev, void *data)
19 {
20         struct uml_net_private *pri;
21         struct tuntap_data *tpri;
22         struct tuntap_init *init = data;
23
24         pri = dev->priv;
25         tpri = (struct tuntap_data *) pri->user;
26         tpri->dev_name = init->dev_name;
27         tpri->fixed_config = (init->dev_name != NULL);
28         tpri->gate_addr = init->gate_addr;
29         tpri->fd = -1;
30         tpri->dev = dev;
31
32         printk("TUN/TAP backend - ");
33         if (tpri->gate_addr != NULL)
34                 printk("IP = %s", tpri->gate_addr);
35         printk("\n");
36 }
37
38 static int tuntap_read(int fd, struct sk_buff **skb,
39                        struct uml_net_private *lp)
40 {
41         *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
42         if (*skb == NULL)
43                 return -ENOMEM;
44         return net_read(fd, skb_mac_header(*skb),
45                         (*skb)->dev->mtu + ETH_HEADER_OTHER);
46 }
47
48 static int tuntap_write(int fd, struct sk_buff **skb,
49                         struct uml_net_private *lp)
50 {
51         return net_write(fd, (*skb)->data, (*skb)->len);
52 }
53
54 const struct net_kern_info tuntap_kern_info = {
55         .init                   = tuntap_init,
56         .protocol               = eth_protocol,
57         .read                   = tuntap_read,
58         .write                  = tuntap_write,
59 };
60
61 int tuntap_setup(char *str, char **mac_out, void *data)
62 {
63         struct tuntap_init *init = data;
64
65         *init = ((struct tuntap_init)
66                 { .dev_name     = NULL,
67                   .gate_addr    = NULL });
68         if (tap_setup_common(str, "tuntap", &init->dev_name, mac_out,
69                             &init->gate_addr))
70                 return 0;
71
72         return 1;
73 }
74
75 static struct transport tuntap_transport = {
76         .list           = LIST_HEAD_INIT(tuntap_transport.list),
77         .name           = "tuntap",
78         .setup          = tuntap_setup,
79         .user           = &tuntap_user_info,
80         .kern           = &tuntap_kern_info,
81         .private_size   = sizeof(struct tuntap_data),
82         .setup_size     = sizeof(struct tuntap_init),
83 };
84
85 static int register_tuntap(void)
86 {
87         register_transport(&tuntap_transport);
88         return 0;
89 }
90
91 late_initcall(register_tuntap);