Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 6 | #include <linux/netdevice.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/skbuff.h> |
| 9 | #include <asm/errno.h> |
Al Viro | 37185b3 | 2012-10-08 03:27:32 +0100 | [diff] [blame^] | 10 | #include <net_kern.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Wang Chen | 17c324f | 2008-12-04 15:07:33 -0800 | [diff] [blame] | 24 | pri = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Jeff Dike | 5134d8f | 2008-02-08 04:22:08 -0800 | [diff] [blame] | 32 | printk(KERN_INFO "TUN/TAP backend - "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | if (tpri->gate_addr != NULL) |
Jeff Dike | 5134d8f | 2008-02-08 04:22:08 -0800 | [diff] [blame] | 34 | printk(KERN_CONT "IP = %s", tpri->gate_addr); |
| 35 | printk(KERN_CONT "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 38 | static int tuntap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 40 | return net_read(fd, skb_mac_header(skb), |
| 41 | skb->dev->mtu + ETH_HEADER_OTHER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 44 | static int tuntap_write(int fd, struct sk_buff *skb, struct uml_net_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 46 | return net_write(fd, skb->data, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 49 | const struct net_kern_info tuntap_kern_info = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | .init = tuntap_init, |
| 51 | .protocol = eth_protocol, |
| 52 | .read = tuntap_read, |
| 53 | .write = tuntap_write, |
| 54 | }; |
| 55 | |
| 56 | int tuntap_setup(char *str, char **mac_out, void *data) |
| 57 | { |
| 58 | struct tuntap_init *init = data; |
| 59 | |
| 60 | *init = ((struct tuntap_init) |
| 61 | { .dev_name = NULL, |
| 62 | .gate_addr = NULL }); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 63 | if (tap_setup_common(str, "tuntap", &init->dev_name, mac_out, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | &init->gate_addr)) |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 65 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 67 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static struct transport tuntap_transport = { |
| 71 | .list = LIST_HEAD_INIT(tuntap_transport.list), |
| 72 | .name = "tuntap", |
| 73 | .setup = tuntap_setup, |
| 74 | .user = &tuntap_user_info, |
| 75 | .kern = &tuntap_kern_info, |
| 76 | .private_size = sizeof(struct tuntap_data), |
| 77 | .setup_size = sizeof(struct tuntap_init), |
| 78 | }; |
| 79 | |
| 80 | static int register_tuntap(void) |
| 81 | { |
| 82 | register_transport(&tuntap_transport); |
Jeff Dike | f4c57a7 | 2006-03-31 02:30:10 -0800 | [diff] [blame] | 83 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Jeff Dike | 8210fd2 | 2006-12-06 20:34:55 -0800 | [diff] [blame] | 86 | late_initcall(register_tuntap); |