/* * TUN - Universal TUN/TAP device driver. * Copyright (C) 1999-2002 Maxim Krasnyansky <maxk@qualcomm.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * $Id: tun.c,v 1.15 2002/03/01 02:44:24 maxk Exp $ *//* * Changes: * * Mike Kershaw <dragorn@kismetwireless.net> 2005/08/14 * Add TUNSETLINK ioctl to set the link encapsulation * * Mark Smith <markzzzsmith@yahoo.com.au> * Use random_ether_addr() for tap MAC address. * * Harald Roelle <harald.roelle@ifi.lmu.de> 2004/04/20 * Fixes in packet dropping, queue length setting and queue wakeup. * Increased default tx queue length. * Added ethtool API. * Minor cleanups * * Daniel Podlejski <underley@underley.eu.org> * Modifications for 2.3.99-pre5 kernel. */#define DRV_NAME "tun"#define DRV_VERSION "1.6"#define DRV_DESCRIPTION "Universal TUN/TAP device driver"#define DRV_COPYRIGHT "(C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com>"#include<linux/module.h>#include<linux/errno.h>#include<linux/kernel.h>#include<linux/major.h>#include<linux/slab.h>#include<linux/smp_lock.h>#include<linux/poll.h>#include<linux/fcntl.h>#include<linux/init.h>#include<linux/skbuff.h>#include<linux/netdevice.h>#include<linux/etherdevice.h>#include<linux/miscdevice.h>#include<linux/ethtool.h>#include<linux/rtnetlink.h>#include<linux/if.h>#include<linux/if_arp.h>#include<linux/if_ether.h>#include<linux/if_tun.h>#include<linux/crc32.h>#include<linux/nsproxy.h>#include<linux/virtio_net.h>#include<net/net_namespace.h>#include<net/netns/generic.h>#include<asm/system.h>#include<asm/uaccess.h>/* Uncomment to enable debugging *//* #define TUN_DEBUG 1 */#ifdef TUN_DEBUGstaticintdebug;#define DBG if(tun->debug)printk#define DBG1 if(debug==2)printk#else#define DBG( a... )#define DBG1( a... )#endif#define FLT_EXACT_COUNT 8structtap_filter{unsignedintcount;/* Number of addrs. Zero means disabled */u32mask[2];/* Mask of the hashed addrs */unsignedcharaddr[FLT_EXACT_COUNT][ETH_ALEN];};structtun_file{atomic_tcount;structtun_struct*tun;structnet*net;wait_queue_head_tread_wait;};structtun_struct{structtun_file*tfile;unsignedintflags;uid_towner;gid_tgroup;structsk_buff_headreadq;structnet_device*dev;structfasync_struct*fasync;structtap_filter