tuntap_kern.c 2.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* 
 * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
 * Licensed under the GPL
 */

#include "linux/stddef.h"
#include "linux/netdevice.h"
#include "linux/etherdevice.h"
#include "linux/skbuff.h"
#include "linux/init.h"
#include "asm/errno.h"
#include "net_kern.h"
#include "net_user.h"
#include "tuntap.h"

16
struct tuntap_init {
17 18 19 20
	char *dev_name;
	char *gate_addr;
};

21
static void tuntap_init(struct net_device *dev, void *data)
22 23 24
{
	struct uml_net_private *pri;
	struct tuntap_data *tpri;
25
	struct tuntap_init *init = data;
26 27 28 29

	init_etherdev(dev, 0);
	pri = dev->priv;
	tpri = (struct tuntap_data *) pri->user;
30
	*tpri = ((struct tuntap_data)
31 32 33 34 35
		{ .dev_name 		= init->dev_name,
		  .fixed_config 	= (init->dev_name != NULL),
		  .gate_addr 		= init->gate_addr,
		  .fd 			= -1,
		  .dev 			= dev });
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
	printk("TUN/TAP backend - ");
	if(tpri->gate_addr != NULL) 
		printk("IP = %s", tpri->gate_addr);
	printk("\n");
}

static int tuntap_read(int fd, struct sk_buff **skb, 
		       struct uml_net_private *lp)
{
	*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
	if(*skb == NULL) return(-ENOMEM);
	return(net_read(fd, (*skb)->mac.raw, 
			(*skb)->dev->mtu + ETH_HEADER_OTHER));
}

static int tuntap_write(int fd, struct sk_buff **skb, 
			struct uml_net_private *lp)
{
	return(net_write(fd, (*skb)->data, (*skb)->len));
}

struct net_kern_info tuntap_kern_info = {
58 59 60 61
	.init			= tuntap_init,
	.protocol		= eth_protocol,
	.read			= tuntap_read,
	.write 			= tuntap_write,
62 63
};

64
int tuntap_setup(char *str, char **mac_out, void *data)
65
{
66
	struct tuntap_init *init = data;
67

68
	*init = ((struct tuntap_init)
69 70
		{ .dev_name 	= NULL,
		  .gate_addr 	= NULL });
71 72 73
	if(tap_setup_common(str, "tuntap", &init->dev_name, mac_out,
			    &init->gate_addr))
		return(0);
74

75
	return(1);
76 77 78
}

static struct transport tuntap_transport = {
79 80 81 82 83 84 85
	.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),
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
};

static int register_tuntap(void)
{
	register_transport(&tuntap_transport);
	return(1);
}

__initcall(register_tuntap);

/*
 * Overrides for Emacs so that we follow Linus's tabbing style.
 * Emacs will notice this stuff at the end of the file and automatically
 * adjust the settings for this buffer only.  This must remain at the end
 * of the file.
 * ---------------------------------------------------------------------------
 * Local variables:
 * c-file-style: "linux"
 * End:
 */