* [Qemu-devel] [PATCH] Updated: Use existing tun/tap network interface
@ 2004-12-08 22:40 Lars Munch
2004-12-08 23:14 ` Fabrice Bellard
2004-12-09 6:35 ` Jens Arm
0 siblings, 2 replies; 4+ messages in thread
From: Lars Munch @ 2004-12-08 22:40 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 246 bytes --]
Hello
I have just updated my priviously posted "Use existing tun/tap network
interface" patch against latest cvs.
For description see here:
http://lists.gnu.org/archive/html/qemu-devel/2004-11/msg00454.html
Please apply.
Regards
Lars Munch
[-- Attachment #2: tun-if.patch --]
[-- Type: text/plain, Size: 5537 bytes --]
Index: Changelog
===================================================================
RCS file: /cvsroot/qemu/qemu/Changelog,v
retrieving revision 1.76
diff -u -p -u -r1.76 Changelog
--- Changelog 30 Nov 2004 23:41:30 -0000 1.76
+++ Changelog 8 Dec 2004 22:31:19 -0000
@@ -4,6 +4,7 @@ version 0.6.2:
- user mode networking bug fix
- undocumented FPU ops support
- Cirrus VGA: support for 1280x1024x[8,15,16] modes
+ - tun-if option (Lars Munch)
version 0.6.1:
Index: qemu-doc.texi
===================================================================
RCS file: /cvsroot/qemu/qemu/qemu-doc.texi,v
retrieving revision 1.51
diff -u -p -u -r1.51 qemu-doc.texi
--- qemu-doc.texi 8 Dec 2004 22:21:25 -0000 1.51
+++ qemu-doc.texi 8 Dec 2004 22:31:20 -0000
@@ -228,6 +228,11 @@ Assumes @var{fd} talks to a tap/tun host
it. Read @url{http://bellard.org/qemu/tetrinet.html} to have an
example of its use.
+@item -tun-if iface
+Use @var{iface} as TUN/TAP network interface. The interface
+is a preconfigured, persistent network interface and has the same
+owner as the QEMU user.
+
@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.108
diff -u -p -u -r1.108 vl.c
--- vl.c 8 Dec 2004 22:21:25 -0000 1.108
+++ vl.c 8 Dec 2004 22:31:20 -0000
@@ -1596,7 +1596,7 @@ static int tun_open(char *ifname, int if
}
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");
@@ -1664,6 +1664,19 @@ static int net_fd_init(NetDriverState *n
return 0;
}
+static int net_if_init(NetDriverState *nd, char *ifname)
+{
+ pstrcpy(nd->ifname, sizeof(nd->ifname), ifname);
+
+ nd->fd = tun_open(nd->ifname, sizeof(nd->ifname));
+ if (nd->fd < 0)
+ return -1;
+
+ nd->send_packet = tun_send_packet;
+ nd->add_read_packet = tun_add_read_packet;
+ return 0;
+}
+
#endif /* !_WIN32 */
/***********************************************************/
@@ -2554,6 +2567,7 @@ void help(void)
"-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-if iface use this iface as already created tap/tun network interface\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"
@@ -2638,6 +2652,7 @@ enum {
QEMU_OPTION_macaddr,
QEMU_OPTION_n,
QEMU_OPTION_tun_fd,
+ QEMU_OPTION_tun_if,
QEMU_OPTION_user_net,
QEMU_OPTION_tftp,
QEMU_OPTION_smb,
@@ -2695,6 +2710,7 @@ const QEMUOption qemu_options[] = {
{ "macaddr", HAS_ARG, QEMU_OPTION_macaddr},
{ "n", HAS_ARG, QEMU_OPTION_n },
{ "tun-fd", HAS_ARG, QEMU_OPTION_tun_fd },
+ { "tun-if", HAS_ARG, QEMU_OPTION_tun_if },
#ifdef CONFIG_SLIRP
{ "user-net", 0, QEMU_OPTION_user_net },
{ "tftp", HAS_ARG, QEMU_OPTION_tftp },
@@ -2800,7 +2816,8 @@ int main(int argc, char **argv)
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, nb_tun_ifs, tun_fds[MAX_NICS];
+ char tun_ifs[MAX_NICS][IFNAMSIZ];
int optind;
const char *r, *optarg;
CharDriverState *monitor_hd;
@@ -2841,6 +2858,7 @@ int main(int argc, char **argv)
serial_device_index = 0;
nb_tun_fds = 0;
+ nb_tun_ifs = 0;
net_if_type = -1;
nb_nics = 1;
/* default mac address of the first network interface */
@@ -2949,7 +2967,7 @@ int main(int argc, char **argv)
const char *p;
int fd;
net_if_type = NET_IF_TUN;
- if (nb_tun_fds < MAX_NICS) {
+ if (nb_tun_fds+nb_tun_ifs < MAX_NICS) {
fd = strtol(optarg, (char **)&p, 0);
if (*p != '\0') {
fprintf(stderr, "qemu: invalid fd for network interface %d\n", nb_tun_fds);
@@ -2959,6 +2977,13 @@ int main(int argc, char **argv)
}
}
break;
+ case QEMU_OPTION_tun_if:
+ net_if_type = NET_IF_TUN;
+ if (nb_tun_fds+nb_tun_ifs < MAX_NICS) {
+ pstrcpy(tun_ifs[nb_tun_ifs], sizeof(tun_ifs[0]), optarg);
+ nb_tun_ifs++;
+ }
+ break;
case QEMU_OPTION_hdc:
hd_filename[2] = optarg;
has_cdrom = 0;
@@ -3214,6 +3239,9 @@ int main(int argc, char **argv)
case NET_IF_TUN:
if (i < nb_tun_fds) {
net_fd_init(nd, tun_fds[i]);
+ } else if (i < nb_tun_fds+nb_tun_ifs) {
+ if (net_if_init(nd, tun_ifs[i-nb_tun_fds]) < 0)
+ net_dummy_init(nd);
} else {
if (net_tun_init(nd) < 0)
net_dummy_init(nd);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-12-09 9:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-08 22:40 [Qemu-devel] [PATCH] Updated: Use existing tun/tap network interface Lars Munch
2004-12-08 23:14 ` Fabrice Bellard
2004-12-09 6:35 ` Jens Arm
2004-12-09 9:17 ` Lars Munch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.