]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Introduce -net {user, tap, none} options for virtio net
authorAsias He <asias.hejun@gmail.com>
Wed, 29 Jun 2011 08:47:31 +0000 (16:47 +0800)
committerPekka Enberg <penberg@kernel.org>
Thu, 30 Jun 2011 07:42:46 +0000 (10:42 +0300)
Use '-net user' to enable user model network, which enables plain user
without speical privileges to use network in guest.

Use '-net tap' to enable tap based network, which requres special
privileges.

Use '-net none' to disable virtio net.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/kvm-run.c

index 0dece2d03806d57e3aa08c7cb8d4e578978b10a7..0ac2ed849d93ec57b70f84827ee32ca0bdf70d56 100644 (file)
@@ -154,7 +154,7 @@ static const struct option options[] = {
                        "Kernel command line arguments"),
 
        OPT_GROUP("Networking options:"),
-       OPT_STRING('n', "network", &network, "virtio",
+       OPT_STRING('n', "network", &network, "user, tap, none",
                        "Network to use"),
        OPT_STRING('\0', "host-ip-addr", &host_ip_addr, "a.b.c.d",
                        "Assign this address to the host side networking"),
@@ -629,20 +629,24 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
        if (!network)
                network = DEFAULT_NETWORK;
 
-       if (!strncmp(network, "virtio", 6)) {
-               net_params = (struct virtio_net_parameters) {
-                       .host_ip = host_ip_addr,
-                       .kvm = kvm,
-                       .script = script
-               };
-               sscanf(guest_mac,       "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-                                                       net_params.guest_mac,
-                                                       net_params.guest_mac+1,
-                                                       net_params.guest_mac+2,
-                                                       net_params.guest_mac+3,
-                                                       net_params.guest_mac+4,
-                                                       net_params.guest_mac+5);
-
+       if (strncmp(network, "none", 4)) {
+               net_params.host_ip = host_ip_addr;
+               net_params.kvm = kvm;
+               net_params.script = script;
+               sscanf(guest_mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+                       net_params.guest_mac,
+                       net_params.guest_mac+1,
+                       net_params.guest_mac+2,
+                       net_params.guest_mac+3,
+                       net_params.guest_mac+4,
+                       net_params.guest_mac+5);
+
+               if (!strncmp(network, "user", 4))
+                       net_params.mode = NET_MODE_USER;
+               else if (!strncmp(network, "tap", 3))
+                       net_params.mode = NET_MODE_TAP;
+               else
+                       die("Unkown network mode %s, please use -network user, tap, none", network);
                virtio_net__init(&net_params);
        }