qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Use existing tun/tap network interface
@ 2004-11-27 10:54 Lars Munch
  2004-11-28 16:07 ` Thomas Schwinge
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Munch @ 2004-11-27 10:54 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 591 bytes --]

Hello

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

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'.

Then start qemu with something like this:

# qemu -tun-if qemu0 .....

You can have MAX_NICS numbers of preconfigured network interfaces.

Please apply.

Regards
Lars Munch



[-- Attachment #2: tun-if.patch --]
[-- Type: text/plain, Size: 5623 bytes --]

Index: Changelog
===================================================================
RCS file: /cvsroot/qemu/qemu/Changelog,v
retrieving revision 1.75
diff -u -p -u -r1.75 Changelog
--- Changelog	24 Nov 2004 19:31:21 -0000	1.75
+++ Changelog	27 Nov 2004 10:32:25 -0000
@@ -3,6 +3,7 @@ version 0.6.2:
   - better BIOS translation and HDD geometry auto-detection
   - user mode networking bug fix
   - undocumented FPU ops support
+  - 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.50
diff -u -p -u -r1.50 qemu-doc.texi
--- qemu-doc.texi	16 Nov 2004 01:45:27 -0000	1.50
+++ qemu-doc.texi	27 Nov 2004 10:32:25 -0000
@@ -224,6 +224,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.107
diff -u -p -u -r1.107 vl.c
--- vl.c	16 Nov 2004 01:45:27 -0000	1.107
+++ vl.c	27 Nov 2004 10:32:26 -0000
@@ -1596,7 +1596,10 @@ 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");
+    if(strlen(ifname) == 0)
+        pstrcpy(ifr.ifr_name, IFNAMSIZ, "tun%d");
+    else
+        pstrcpy(ifr.ifr_name, IFNAMSIZ, ifname);
     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 +1667,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 */
 
 /***********************************************************/
@@ -2514,6 +2530,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"
@@ -2597,6 +2614,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,
@@ -2653,6 +2671,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 },
@@ -2757,7 +2776,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;
@@ -2798,6 +2818,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 */
@@ -2906,7 +2927,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);
@@ -2916,6 +2937,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;
@@ -3168,6 +3196,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] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Use existing tun/tap network interface
  2004-11-27 10:54 [Qemu-devel] [PATCH] Use existing tun/tap network interface Lars Munch
@ 2004-11-28 16:07 ` Thomas Schwinge
  2004-11-28 16:37   ` Lars Munch
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Schwinge @ 2004-11-28 16:07 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1356 bytes --]

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

[-- Attachment #2: qemu-net-if.patch --]
[-- Type: text/plain, Size: 2665 bytes --]

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;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Use existing tun/tap network interface
  2004-11-28 16:07 ` Thomas Schwinge
@ 2004-11-28 16:37   ` Lars Munch
  2004-11-28 18:26     ` Thomas Schwinge
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Munch @ 2004-11-28 16:37 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2330 bytes --]

On Sun, Nov 28, 2004 at 05:07:20PM +0100, Thomas Schwinge wrote:
> 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.

My patch takes care of that.

> * Disable the invocation of a tap/tun network init script when
>   specifying '-net-if ...' or '-tun-fd ...'

With my patch you can still use a tap/tun network init script for the
NICs not created by '-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.

I don't have to.

> 
> Regards,
>  Thomas
> 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");

I like this part of you patch better than my code, so I have added this
to the attached patch.

Regards
Lars Munch


[-- Attachment #2: tun-if.patch --]
[-- Type: text/plain, Size: 5596 bytes --]

? more-os.patch
? semantic.cache
? tun-if.patch
Index: Changelog
===================================================================
RCS file: /cvsroot/qemu/qemu/Changelog,v
retrieving revision 1.75
diff -u -p -u -r1.75 Changelog
--- Changelog	24 Nov 2004 19:31:21 -0000	1.75
+++ Changelog	28 Nov 2004 16:37:39 -0000
@@ -3,6 +3,7 @@ version 0.6.2:
   - better BIOS translation and HDD geometry auto-detection
   - user mode networking bug fix
   - undocumented FPU ops support
+  - 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.50
diff -u -p -u -r1.50 qemu-doc.texi
--- qemu-doc.texi	16 Nov 2004 01:45:27 -0000	1.50
+++ qemu-doc.texi	28 Nov 2004 16:37:39 -0000
@@ -224,6 +224,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.107
diff -u -p -u -r1.107 vl.c
--- vl.c	16 Nov 2004 01:45:27 -0000	1.107
+++ vl.c	28 Nov 2004 16:37:40 -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 */
 
 /***********************************************************/
@@ -2514,6 +2527,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"
@@ -2597,6 +2611,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,
@@ -2653,6 +2668,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 },
@@ -2757,7 +2773,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;
@@ -2798,6 +2815,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 */
@@ -2906,7 +2924,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);
@@ -2916,6 +2934,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;
@@ -3168,6 +3193,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] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Use existing tun/tap network interface
  2004-11-28 16:37   ` Lars Munch
@ 2004-11-28 18:26     ` Thomas Schwinge
  2004-11-28 19:37       ` Lars Munch
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Schwinge @ 2004-11-28 18:26 UTC (permalink / raw)
  To: qemu-devel

On Sun, Nov 28, 2004 at 05:36:48PM +0100, Lars Munch wrote:
> On Sun, Nov 28, 2004 at 05:07:20PM +0100, Thomas Schwinge wrote:
> > 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.
> 
> My patch takes care of that.

Good.

> > * Disable the invocation of a tap/tun network init script when
> >   specifying '-net-if ...' or '-tun-fd ...'
> 
> With my patch you can still use a tap/tun network init script for the
> NICs not created by '-net-if' or '-tun-fd.

Yes, I forgot that the same script is used for all interfaces - you
could use that with my patch, too.
If every interface had it's own specific script, it would be reasonable
to disable it by default when using a preconfigured interface.
But since it is not, I'd also just leave that alone.

> > > Then start qemu with something like this:
> > > 
> > > # qemu -tun-if qemu0 .....
> > 
> > I'm adding '-n /bin/true' here.
> 
> I don't have to.

Of course I also don't have to, but I don't want to get
'/etc/qemu-ifup: could not launch network script' every time running
qemu.
;-)

> +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;
> +}
> +

Why do you need this function?
(Sorry, I don't have the time to dig through qemu's networking code at
the moment.)
Is it because I am doing
#v+
            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;
#v-
..., whereas you are putting the devices' names into an array and copy it
to the interfaces' structure later?
What's the advantage of your approach compared to mine?

> +            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;

> +            } 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);


Regards,
 Thomas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Use existing tun/tap network interface
  2004-11-28 18:26     ` Thomas Schwinge
@ 2004-11-28 19:37       ` Lars Munch
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Munch @ 2004-11-28 19:37 UTC (permalink / raw)
  To: qemu-devel

On Sun, Nov 28, 2004 at 07:26:44PM +0100, Thomas Schwinge wrote:
> On Sun, Nov 28, 2004 at 05:36:48PM +0100, Lars Munch wrote:
> > +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;
> > +}
> > +
> 
> Why do you need this function?
> (Sorry, I don't have the time to dig through qemu's networking code at
> the moment.)

I need net_if_init functions because I do not want to call the network 
configuration script for preconfigured interfaces.

> Is it because I am doing
> #v+
>             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;
> #v-
> ..., whereas you are putting the devices' names into an array and copy it
> to the interfaces' structure later?
> What's the advantage of your approach compared to mine?

If you copy the device names into the nd_table structure immediately,
you will get into trouble later because the n'th first interfaces are
used for -tun-fd's.

Regards
Lars Munch

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-11-28 19:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-27 10:54 [Qemu-devel] [PATCH] Use existing tun/tap network interface Lars Munch
2004-11-28 16:07 ` Thomas Schwinge
2004-11-28 16:37   ` Lars Munch
2004-11-28 18:26     ` Thomas Schwinge
2004-11-28 19:37       ` Lars Munch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).