2019-08-25 03:49:18 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2007-10-16 02:27:29 -06:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
2007-10-16 02:27:29 -06:00
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <asm/errno.h>
|
2012-10-07 20:27:32 -06:00
|
|
|
#include <net_kern.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include "tuntap.h"
|
|
|
|
|
|
|
|
struct tuntap_init {
|
|
|
|
char *dev_name;
|
|
|
|
char *gate_addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void tuntap_init(struct net_device *dev, void *data)
|
|
|
|
{
|
|
|
|
struct uml_net_private *pri;
|
|
|
|
struct tuntap_data *tpri;
|
|
|
|
struct tuntap_init *init = data;
|
|
|
|
|
2008-12-04 16:07:33 -07:00
|
|
|
pri = netdev_priv(dev);
|
2005-04-16 16:20:36 -06:00
|
|
|
tpri = (struct tuntap_data *) pri->user;
|
|
|
|
tpri->dev_name = init->dev_name;
|
|
|
|
tpri->fixed_config = (init->dev_name != NULL);
|
|
|
|
tpri->gate_addr = init->gate_addr;
|
|
|
|
tpri->fd = -1;
|
|
|
|
tpri->dev = dev;
|
|
|
|
|
2008-02-08 05:22:08 -07:00
|
|
|
printk(KERN_INFO "TUN/TAP backend - ");
|
2005-04-16 16:20:36 -06:00
|
|
|
if (tpri->gate_addr != NULL)
|
2008-02-08 05:22:08 -07:00
|
|
|
printk(KERN_CONT "IP = %s", tpri->gate_addr);
|
|
|
|
printk(KERN_CONT "\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:31 -06:00
|
|
|
static int tuntap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-10-16 02:27:31 -06:00
|
|
|
return net_read(fd, skb_mac_header(skb),
|
|
|
|
skb->dev->mtu + ETH_HEADER_OTHER);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:31 -06:00
|
|
|
static int tuntap_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-10-16 02:27:31 -06:00
|
|
|
return net_write(fd, skb->data, skb->len);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-09-27 02:50:33 -06:00
|
|
|
const struct net_kern_info tuntap_kern_info = {
|
2005-04-16 16:20:36 -06:00
|
|
|
.init = tuntap_init,
|
|
|
|
.protocol = eth_protocol,
|
|
|
|
.read = tuntap_read,
|
|
|
|
.write = tuntap_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
int tuntap_setup(char *str, char **mac_out, void *data)
|
|
|
|
{
|
|
|
|
struct tuntap_init *init = data;
|
|
|
|
|
|
|
|
*init = ((struct tuntap_init)
|
|
|
|
{ .dev_name = NULL,
|
|
|
|
.gate_addr = NULL });
|
2007-10-16 02:27:29 -06:00
|
|
|
if (tap_setup_common(str, "tuntap", &init->dev_name, mac_out,
|
2005-04-16 16:20:36 -06:00
|
|
|
&init->gate_addr))
|
2007-10-16 02:27:29 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:29 -06:00
|
|
|
return 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct transport tuntap_transport = {
|
|
|
|
.list = LIST_HEAD_INIT(tuntap_transport.list),
|
|
|
|
.name = "tuntap",
|
|
|
|
.setup = tuntap_setup,
|
|
|
|
.user = &tuntap_user_info,
|
|
|
|
.kern = &tuntap_kern_info,
|
|
|
|
.private_size = sizeof(struct tuntap_data),
|
|
|
|
.setup_size = sizeof(struct tuntap_init),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int register_tuntap(void)
|
|
|
|
{
|
|
|
|
register_transport(&tuntap_transport);
|
2006-03-31 03:30:10 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-12-06 21:34:55 -07:00
|
|
|
late_initcall(register_tuntap);
|