From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CYRlO-0005ln-1g for qemu-devel@nongnu.org; Sun, 28 Nov 2004 11:19:02 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CYRlN-0005lY-Je for qemu-devel@nongnu.org; Sun, 28 Nov 2004 11:19:01 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CYRlN-0005lR-HV for qemu-devel@nongnu.org; Sun, 28 Nov 2004 11:19:01 -0500 Received: from [151.189.20.157] (helo=postman.arcor.de) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1CYRbk-0000u2-Mm for qemu-devel@nongnu.org; Sun, 28 Nov 2004 11:09:05 -0500 Received: from server.schwinge.homeip.net (c-180-200-94.n.dial.de.ignite.net [62.180.200.94]) (authenticated bits=0) by postman.arcor.de (8.13.0.PreAlpha4/8.13.0.PreAlpha4) with ESMTP id iASG90Th001773 for ; Sun, 28 Nov 2004 17:09:01 +0100 (MET) Date: Sun, 28 Nov 2004 17:07:20 +0100 From: Thomas Schwinge Subject: Re: [Qemu-devel] [PATCH] Use existing tun/tap network interface Message-ID: <20041128160719.GA3263@bobby.schwinge.homeip.net> References: <20041127105452.GA8263@tuxedo.skovlyporten.dk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="LZvS9be/3tNcYl/X" Content-Disposition: inline In-Reply-To: <20041127105452.GA8263@tuxedo.skovlyporten.dk> 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 --LZvS9be/3tNcYl/X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Nov 27, 2004 at 11:54:30AM +0100, Lars Munch wrote: > The attached patch adds a new option '-tun-if' which will enable you to > use preconfigured tun/tap network interfaces as described here: > http://user-mode-linux.sourceforge.net/UserModeLinux-HOWTO-6.html#ss6.7 I've been preparing a patch to achieve the same functionality some days ago, but didn't have the time to finish it, yet. It is, however, working: 'qemu-net-if.patch' is attached. Things to be done: * Make it possible to use '-net-if ...' and '-tun-fd ...' at the same time without interfering with each other - albeit I don't know if anybody will use both of them at the same time, ever. * Disable the invocation of a tap/tun network init script when specifying '-net-if ...' or '-tun-fd ...' > To use it, first configure your interface by using for example tunctl > from UML: > > # tunctl -t qemu0 -u OWNER > # ifconfig qemu0 xxx.xxx.xxx.xxx up > > Now you will have a network interface called 'qemu0'. Wrapping that in other words: You configure the network interfaces to be used by qemu in your system's network configuration script (or anywhere else) and can use that interface later without starting qemu (or a wrapper script) as root. > Then start qemu with something like this: > > # qemu -tun-if qemu0 ..... I'm adding '-n /bin/true' here. Regards, Thomas --LZvS9be/3tNcYl/X Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="qemu-net-if.patch" diff -Nru qemu-0.o/vl.c qemu-0/vl.c --- qemu-0.o/vl.c 2004-11-16 14:16:22.000000000 +0100 +++ qemu-0/vl.c 2004-11-19 18:42:49.811154272 +0100 @@ -1596,7 +1596,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 : "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"); @@ -2513,6 +2513,8 @@ "-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" + "-net-if interface\n" + " set the network interface to use [default=tun%%d]\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" @@ -2596,6 +2598,7 @@ QEMU_OPTION_nics, QEMU_OPTION_macaddr, QEMU_OPTION_n, + QEMU_OPTION_net_if, QEMU_OPTION_tun_fd, QEMU_OPTION_user_net, QEMU_OPTION_tftp, @@ -2652,6 +2655,7 @@ { "nics", HAS_ARG, QEMU_OPTION_nics}, { "macaddr", HAS_ARG, QEMU_OPTION_macaddr}, { "n", HAS_ARG, QEMU_OPTION_n }, + { "net-if", HAS_ARG, QEMU_OPTION_net_if }, { "tun-fd", HAS_ARG, QEMU_OPTION_tun_fd }, #ifdef CONFIG_SLIRP { "user-net", 0, QEMU_OPTION_user_net }, @@ -2757,7 +2761,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_net_ifs, nb_tun_fds, tun_fds[MAX_NICS]; int optind; const char *r, *optarg; CharDriverState *monitor_hd; @@ -2798,6 +2802,7 @@ serial_device_index = 0; nb_tun_fds = 0; + nb_net_ifs = 0; net_if_type = -1; nb_nics = 1; /* default mac address of the first network interface */ @@ -3026,6 +3031,13 @@ case QEMU_OPTION_n: pstrcpy(network_script, sizeof(network_script), optarg); break; + case QEMU_OPTION_net_if: + net_if_type = NET_IF_TUN; + if (nb_net_ifs < MAX_NICS) { + pstrcpy (nd_table[nb_net_ifs].ifname, sizeof(nd_table[nb_net_ifs].ifname), optarg); + nb_net_ifs++; + } + break; #ifdef CONFIG_GDBSTUB case QEMU_OPTION_s: use_gdbstub = 1; --LZvS9be/3tNcYl/X--