Path: blob/master/arch/um/os-Linux/drivers/ethertap_kern.c
10819 views
/*1* Copyright (C) 2001 Lennert Buytenhek ([email protected]) and2* James Leu ([email protected]).3* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)4* Copyright (C) 2001 by various other people who didn't put their name here.5* Licensed under the GPL.6*/78#include <linux/init.h>9#include <linux/netdevice.h>10#include "etap.h"11#include "net_kern.h"1213struct ethertap_init {14char *dev_name;15char *gate_addr;16};1718static void etap_init(struct net_device *dev, void *data)19{20struct uml_net_private *pri;21struct ethertap_data *epri;22struct ethertap_init *init = data;2324pri = netdev_priv(dev);25epri = (struct ethertap_data *) pri->user;26epri->dev_name = init->dev_name;27epri->gate_addr = init->gate_addr;28epri->data_fd = -1;29epri->control_fd = -1;30epri->dev = dev;3132printk(KERN_INFO "ethertap backend - %s", epri->dev_name);33if (epri->gate_addr != NULL)34printk(KERN_CONT ", IP = %s", epri->gate_addr);35printk(KERN_CONT "\n");36}3738static int etap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)39{40int len;4142len = net_recvfrom(fd, skb_mac_header(skb),43skb->dev->mtu + 2 + ETH_HEADER_ETHERTAP);44if (len <= 0)45return(len);4647skb_pull(skb, 2);48len -= 2;49return len;50}5152static int etap_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)53{54skb_push(skb, 2);55return net_send(fd, skb->data, skb->len);56}5758const struct net_kern_info ethertap_kern_info = {59.init = etap_init,60.protocol = eth_protocol,61.read = etap_read,62.write = etap_write,63};6465int ethertap_setup(char *str, char **mac_out, void *data)66{67struct ethertap_init *init = data;6869*init = ((struct ethertap_init)70{ .dev_name = NULL,71.gate_addr = NULL });72if (tap_setup_common(str, "ethertap", &init->dev_name, mac_out,73&init->gate_addr))74return 0;75if (init->dev_name == NULL) {76printk(KERN_ERR "ethertap_setup : Missing tap device name\n");77return 0;78}7980return 1;81}8283static struct transport ethertap_transport = {84.list = LIST_HEAD_INIT(ethertap_transport.list),85.name = "ethertap",86.setup = ethertap_setup,87.user = ðertap_user_info,88.kern = ðertap_kern_info,89.private_size = sizeof(struct ethertap_data),90.setup_size = sizeof(struct ethertap_init),91};9293static int register_ethertap(void)94{95register_transport(ðertap_transport);96return 0;97}9899late_initcall(register_ethertap);100101102