]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Use kernel dhcp for network autoconfiguration
authorSasha Levin <levinsasha928@gmail.com>
Wed, 14 Sep 2011 07:11:09 +0000 (10:11 +0300)
committerPekka Enberg <penberg@kernel.org>
Wed, 14 Sep 2011 15:56:47 +0000 (18:56 +0300)
This patch removes the manual/usermode dhcp client configuration and instead
uses the DHCP client built within the kernel.

Since this client is tightly integrated with NFS (if NFS config is set), we
will add a specific NFS root addr in our DHCP offer to point it to a non
existent address so that we won't hang trying to poke it for our root.

Acked-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-run.c
tools/kvm/guest/init.c
tools/kvm/guest/setnet.sh [deleted file]
tools/kvm/include/kvm/uip.h
tools/kvm/net/uip/dhcp.c

index 6234b65b16997ba2325460baa0fab31abc1741e3..741548f723924f117b4a5998b5816e68406bde86 100644 (file)
@@ -764,7 +764,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
        if (using_rootfs) {
                strcat(real_cmdline, " root=/dev/root rw rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p");
                if (custom_rootfs)
-                       strcat(real_cmdline, " init=/virt/init");
+                       strcat(real_cmdline, " init=/virt/init ip=dhcp");
        } else if (!strstr(real_cmdline, "root=")) {
                strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
        }
index 773302602534c2c435a45dd5b10d85789e37c166..837acfb18c2876a224cc079249145a302147f15e 100644 (file)
@@ -30,10 +30,6 @@ int main(int argc, char *argv[])
 
        do_mounts();
 
-       puts("Setting up network...");
-
-       system("/bin/sh virt/setnet.sh");
-
        puts("Starting '/bin/sh'...");
 
        run_process("/bin/sh");
diff --git a/tools/kvm/guest/setnet.sh b/tools/kvm/guest/setnet.sh
deleted file mode 100755 (executable)
index 3da9c22..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-for f in /sys/class/net/*; do
-       type=`cat $f/type`
-       if [ $type -eq 1 ]; then
-               f=${f#/sys/class/net/}
-
-               eval "dhcpcd -A $f 2> /dev/null"
-               if [ $? -eq 0 ]; then
-                       exit
-               fi
-
-               eval "dhclient $f 2> /dev/null"
-               if [ $? -eq 0 ]; then
-                       exit
-               fi
-
-               ifconfig $f 192.168.33.15
-               route add default 192.168.33.1
-               echo "nameserver 8.8.8.8" >> /etc/resolv.conf
-
-               exit
-       fi
-done
index 344ec0983836aaf17f6b84c9a5ff70a9e387ac25..3501d36106b5cdf900c05795ae2d5610077ae791 100644 (file)
@@ -58,6 +58,8 @@
 #define UIP_DHCP_TAG_SUBMASK_LEN       4
 #define UIP_DHCP_TAG_ROUTER            3
 #define UIP_DHCP_TAG_ROUTER_LEN                4
+#define UIP_DHCP_TAG_ROOT              17
+#define UIP_DHCP_TAG_ROOT_LEN          4
 #define UIP_DHCP_TAG_DNS_SERVER                6
 #define UIP_DHCP_TAG_DNS_SERVER_LEN    4
 #define UIP_DHCP_TAG_DOMAIN_NAME       15
index bd3c53ba1416e08b1de9cd9254028db1b3e81a15..e91a7c7a6aca4584283cebea05ab281d39434b71 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <arpa/inet.h>
 
+#define EMPTY_ADDR "0.0.0.0"
+
 static inline bool uip_dhcp_is_discovery(struct uip_dhcp *dhcp)
 {
        return (dhcp->option[2] == UIP_DHCP_DISCOVER &&
@@ -127,6 +129,12 @@ static int uip_dhcp_fill_option(struct uip_info *info, struct uip_dhcp *dhcp, in
        *addr           = htonl(info->host_ip);
        i               += UIP_DHCP_TAG_ROUTER_LEN;
 
+       opt[i++]        = UIP_DHCP_TAG_ROOT;
+       opt[i++]        = strlen(EMPTY_ADDR);
+       addr            = (u32 *)&opt[i];
+       strncpy((void *) addr, EMPTY_ADDR, strlen(EMPTY_ADDR));
+       i               += strlen(EMPTY_ADDR);
+
        i               = uip_dhcp_fill_option_name_and_server(info, opt, i);
 
        opt[i++]        = UIP_DHCP_TAG_END;