From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DMZZb-00032s-OU for qemu-devel@nongnu.org; Fri, 15 Apr 2005 18:46:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DMZZV-0002yk-Bv for qemu-devel@nongnu.org; Fri, 15 Apr 2005 18:45:58 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DMZZU-0002yb-HR for qemu-devel@nongnu.org; Fri, 15 Apr 2005 18:45:57 -0400 Received: from [144.85.15.72] (helo=mail.eclis.ch) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DMZVJ-0006Dz-W8 for qemu-devel@nongnu.org; Fri, 15 Apr 2005 18:41:38 -0400 Received: from [10.0.33.10] (212-98-46-129.adslpremium.ch [212.98.46.129]) by mail.eclis.ch (Postfix) with ESMTP id E30CE3F2071 for ; Sat, 16 Apr 2005 00:40:38 +0200 (CEST) Message-ID: <426042E6.4060404@eclis.ch> Date: Sat, 16 Apr 2005 00:40:38 +0200 From: Jean-Christian de Rivaz MIME-Version: 1.0 Subject: Re: [Qemu-devel] [patch] Linux TUN/TAP driver updates References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------000401030805010001000002" Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------000401030805010001000002 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Hi, This is a good idea. I haved posted a similar patch to this mailing list=20 the 13 feb 2005 but I have see no reaction at all at this time. Maybe=20 you can find something usefull in the attached patch to improve the=20 support of static TUN/TAP. The patch is outdated now, but I can update=20 it to the current CVS if there is any interrest. Just tell me. Static TUN is good in the situation where you have a superuser that=20 manage the interfaces. It set them and assign them to each users. it can=20 also setup a DHCP server to distribute IP addresses. Users just lunch=20 quemu with there static TUN in the option and magicaly get a working=20 network without any need to sudo, setuid or whatever that can have any=20 security risk. You can also imagine a virtual machine manager application that setup=20 the network interfaces and lunch the qemu instances. This is the=20 direction I like the most. Have a good day, -- Henrik Nordstrom a =E9crit : > The attached patch updates the Linux TUN/TAP interface >=20 > - Allow use of static/persistent TUN/TAP devices, eleminating the nee= d=20 > to run anything as root when starting qemu. >=20 > - A minor bugfix in filedescriptor based TUN/TAP devices to allow mor= e=20 > than one filedescriptor (was colliding on the qemu internal device name= ). >=20 > - Added the interface index as argument to the ifup script to simplif= y=20 > integration. >=20 >=20 > A small howto use persistent TUN/TAP devices: >=20 > 1. Grab the tunctl tool from UML.=20 > > >=20 > this small tools allows you to create persistent TAP devices with a=20 > fixed name on the host. A persistent tap device stays until it is=20 > manually deleted with tunctl. >=20 > 2. Configure the host side of the created TAP devices using your normal= =20 > network setup tools, or the network configuration tools provided by you= r=20 > distribution vendor if preferred. >=20 > 3. When starting qemu, specify the TAP device names with the new=20 > -tun-dev qemu command line option. >=20 > -tun-dev name use this already created tun device >=20 > -tun-dev can be specified multiple times if you want qemu to connect to= =20 > more than one device. >=20 > Regards > Henrik --=20 Jean-Christian de Rivaz --------------000401030805010001000002 Content-Type: text/x-patch; name="tun.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="tun.patch" Index: qemu-doc.texi =================================================================== RCS file: /cvsroot/qemu/qemu/qemu-doc.texi,v retrieving revision 1.55 diff -u -r1.55 qemu-doc.texi --- qemu-doc.texi 10 Feb 2005 21:46:47 -0000 1.55 +++ qemu-doc.texi 13 Feb 2005 01:59:04 -0000 @@ -212,6 +212,22 @@ aa:bb:cc:dd:ee:ff in hexa). The mac address is incremented for each new network interface. +@item -tun devname +Try to use @var{devname} while opening a tap/tun host network interface and use +it. If it work, the network init script is not executed for this +interface. If it don't work, the interface will use the name assigned +by the operating system and the network init script is executed. + +This option permit the use of preconfigured interface. For example, as +root you can assign a tun interface to a user and configure it like this: +@example +tunctl -u bob -t tun2 +ifconfig tun2 192.168.2.1 +@end example +Then bob can use this interface with the option "-tun tun2". Note that +option permit the use of a DHCP server on the host to configure the +guest interface. + @item -tun-fd fd Assumes @var{fd} talks to a tap/tun host network interface and use it. Read @url{http://bellard.org/qemu/tetrinet.html} to have an Index: vl.c =================================================================== RCS file: /cvsroot/qemu/qemu/vl.c,v retrieving revision 1.120 diff -u -r1.120 vl.c --- vl.c 10 Feb 2005 22:00:06 -0000 1.120 +++ vl.c 13 Feb 2005 01:59:05 -0000 @@ -1600,7 +1600,7 @@ } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; - pstrcpy(ifr.ifr_name, IFNAMSIZ, "tun%d"); + pstrcpy(ifr.ifr_name, IFNAMSIZ, (ifname && *ifname) ? ifname : "tun%d"); ret = ioctl(fd, TUNSETIFF, (void *) &ifr); if (ret != 0) { fprintf(stderr, "warning: could not configure /dev/net/tun: no virtual network emulation\n"); @@ -1626,7 +1626,7 @@ qemu_add_fd_read_handler(nd->fd, fd_can_read, fd_read, opaque); } -static int net_tun_init(NetDriverState *nd) +static int net_tun_init(NetDriverState *nd, int script) { int pid, status; char *args[3]; @@ -1637,7 +1637,7 @@ return -1; /* try to launch network init script */ - pid = fork(); + pid = script ? fork() : -1; if (pid >= 0) { if (pid == 0) { parg = args; @@ -2731,6 +2731,7 @@ "-nics n simulate 'n' network cards [default=1]\n" "-macaddr addr set the mac address of the first interface\n" "-n script set tap/tun network init script [default=%s]\n" + "-tun devname try to use devname while opening tap/tun interface\n" "-tun-fd fd use this fd as already opened tap/tun interface\n" #ifdef CONFIG_SLIRP "-user-net use user mode network stack [default if no tap/tun script]\n" @@ -2819,6 +2820,7 @@ QEMU_OPTION_nics, QEMU_OPTION_macaddr, QEMU_OPTION_n, + QEMU_OPTION_tun, QEMU_OPTION_tun_fd, QEMU_OPTION_user_net, QEMU_OPTION_tftp, @@ -2880,6 +2882,7 @@ { "nics", HAS_ARG, QEMU_OPTION_nics}, { "macaddr", HAS_ARG, QEMU_OPTION_macaddr}, { "n", HAS_ARG, QEMU_OPTION_n }, + { "tun", HAS_ARG, QEMU_OPTION_tun }, { "tun-fd", HAS_ARG, QEMU_OPTION_tun_fd }, #ifdef CONFIG_SLIRP { "user-net", 0, QEMU_OPTION_user_net }, @@ -2990,7 +2993,7 @@ int cyls, heads, secs, translation; int start_emulation = 1; uint8_t macaddr[6]; - int net_if_type, nb_tun_fds, tun_fds[MAX_NICS]; + int net_if_type, nb_tun, nb_tun_fds, cnt_tun_fds, tun_fds[MAX_NICS]; int optind; const char *r, *optarg; CharDriverState *monitor_hd; @@ -3037,7 +3040,12 @@ parallel_devices[i][0] = '\0'; parallel_device_index = 0; + for(i = 0; i < MAX_NICS; i++) { + nd_table[i].ifname[0] = '\0'; + } + nb_tun = 0; nb_tun_fds = 0; + cnt_tun_fds = 0; net_if_type = -1; nb_nics = 1; /* default mac address of the first network interface */ @@ -3141,18 +3149,25 @@ case QEMU_OPTION_append: kernel_cmdline = optarg; break; + case QEMU_OPTION_tun: + net_if_type = NET_IF_TUN; + if (nb_tun+nb_tun_fds < MAX_NICS) { + pstrcpy(nd_table[nb_tun++].ifname, IFNAMSIZ, optarg); + } + break; case QEMU_OPTION_tun_fd: { const char *p; int fd; net_if_type = NET_IF_TUN; - if (nb_tun_fds < MAX_NICS) { + if (nb_tun+nb_tun_fds < MAX_NICS) { fd = strtol(optarg, (char **)&p, 0); if (*p != '\0') { fprintf(stderr, "qemu: invalid fd for network interface %d\n", nb_tun_fds); exit(1); } tun_fds[nb_tun_fds++] = fd; + nb_tun++; } } break; @@ -3426,12 +3441,20 @@ #endif #if !defined(_WIN32) case NET_IF_TUN: - if (i < nb_tun_fds) { - net_fd_init(nd, tun_fds[i]); - } else { - if (net_tun_init(nd) < 0) - net_dummy_init(nd); - } + if (nd->ifname && *(nd->ifname)) { + if (net_tun_init(nd, 0) < 0) { + nd->ifname[0] = '\0'; + if (net_tun_init(nd, 1) < 0) + net_dummy_init(nd); + } + } else { + if (cnt_tun_fds < nb_tun_fds) { + net_fd_init(nd, tun_fds[cnt_tun_fds++]); + } else { + if (net_tun_init(nd, 1) < 0) + net_dummy_init(nd); + } + } break; #endif case NET_IF_DUMMY: --------------000401030805010001000002--