Index: qemu-doc.texi =================================================================== RCS file: /cvsroot/qemu/qemu/qemu-doc.texi,v retrieving revision 1.65 diff -u -r1.65 qemu-doc.texi --- qemu-doc.texi 28 Jul 2005 22:27:28 -0000 1.65 +++ qemu-doc.texi 18 Sep 2005 20:46:24 -0000 @@ -227,6 +227,11 @@ it. Read @url{http://bellard.org/qemu/tetrinet.html} to have an example of its use. address@hidden -tun-dev ifname + +Set the host TUN/TAP device name. Useful if you use persistent TUN/TAP +interfaces or host firewalling based on the device name. + @item -user-net Use the user mode network stack. This is the default if no tun/tap network init script is found. Index: vl.c =================================================================== RCS file: /cvsroot/qemu/qemu/vl.c,v retrieving revision 1.136 diff -u -r1.136 vl.c --- vl.c 3 Sep 2005 21:33:43 -0000 1.136 +++ vl.c 18 Sep 2005 20:46:24 -0000 @@ -1663,14 +1663,16 @@ } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; - pstrcpy(ifr.ifr_name, IFNAMSIZ, "tun%d"); + if (*ifname) + pstrcpy(ifr.ifr_name, IFNAMSIZ, ifname); + else + pstrcpy(ifr.ifr_name, IFNAMSIZ, "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"); close(fd); return -1; } - printf("Connected to host network interface: %s\n", ifr.ifr_name); pstrcpy(ifname, ifname_size, ifr.ifr_name); fcntl(fd, F_SETFL, O_NONBLOCK); return fd; @@ -1692,20 +1694,24 @@ static int net_tun_init(NetDriverState *nd) { int pid, status; - char *args[3]; - char **parg; nd->fd = tun_open(nd->ifname, sizeof(nd->ifname)); if (nd->fd < 0) return -1; + printf("Network %d connected to host network interface: %s\n", nd->index, nd->ifname); /* try to launch network init script */ pid = fork(); if (pid >= 0) { if (pid == 0) { + char ifnum[4]; + char *args[4]; + char **parg; + snprintf(ifnum, sizeof(ifnum), "%d", nd->index); parg = args; *parg++ = network_script; *parg++ = nd->ifname; + *parg++ = ifnum; *parg++ = NULL; execv(network_script, args); exit(1); @@ -1727,7 +1733,7 @@ nd->fd = fd; nd->send_packet = tun_send_packet; nd->add_read_packet = tun_add_read_packet; - pstrcpy(nd->ifname, sizeof(nd->ifname), "tunfd"); + snprintf(nd->ifname, sizeof(nd->ifname), "tunfd%d", fd); return 0; } @@ -2852,6 +2858,7 @@ "-macaddr addr set the mac address of the first interface\n" "-n script set tap/tun network init script [default=%s]\n" "-tun-fd fd use this fd as already opened tap/tun interface\n" + "-tun-dev name use this already created tun device\n" #ifdef CONFIG_SLIRP "-user-net use user mode network stack [default if no tap/tun script]\n" "-tftp prefix allow tftp access to files starting with prefix [-user-net]\n" @@ -2941,6 +2948,7 @@ QEMU_OPTION_macaddr, QEMU_OPTION_n, QEMU_OPTION_tun_fd, + QEMU_OPTION_tun_dev, QEMU_OPTION_user_net, QEMU_OPTION_tftp, QEMU_OPTION_smb, @@ -3004,6 +3012,7 @@ { "macaddr", HAS_ARG, QEMU_OPTION_macaddr}, { "n", HAS_ARG, QEMU_OPTION_n }, { "tun-fd", HAS_ARG, QEMU_OPTION_tun_fd }, + { "tun-dev", HAS_ARG, QEMU_OPTION_tun_dev }, #ifdef CONFIG_SLIRP { "user-net", 0, QEMU_OPTION_user_net }, { "tftp", HAS_ARG, QEMU_OPTION_tftp }, @@ -3136,7 +3145,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_fds, tun_fds[MAX_NICS], nb_tun_devices; int optind; const char *r, *optarg; CharDriverState *monitor_hd; @@ -3191,6 +3200,7 @@ parallel_device_index = 0; nb_tun_fds = 0; + nb_tun_devices = 0; net_if_type = -1; nb_nics = 1; /* default mac address of the first network interface */ @@ -3326,6 +3336,15 @@ } tun_fds[nb_tun_fds++] = fd; } + } + break; + case QEMU_OPTION_tun_dev: + { + net_if_type = NET_IF_TUN; + if (nb_tun_devices < MAX_NICS) { + pstrcpy(nd_table[nb_tun_devices].ifname, sizeof(nd_table[nb_tun_devices].ifname), optarg); + nb_tun_devices++; + } } break; case QEMU_OPTION_cdrom: