]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add support for an external TFTP boot server
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 28 Oct 2009 14:57:49 +0000 (15:57 +0100)
committerDaniel Veillard <veillard@redhat.com>
Wed, 28 Oct 2009 14:57:49 +0000 (15:57 +0100)
This patch adds an optional attribute to the <bootp> tag, that
allows to specify a TFTP server address other than the address of
the DHCP server itself.

This can be used to forward the BOOTP settings of the host down to the
guest.  This is something that configurations such as Xen's default
network achieve naturally, but must be done manually for NAT.

* docs/formatnetwork.html.in: Document new attribute.
* docs/schemas/network.rng: Add it to schema.
* src/conf/network_conf.h: Add it to struct.
* src/conf/network_conf.c: Add it to parser and pretty printer.
* src/network/bridge_driver.c: Put it in the dnsmasq command line.
* tests/networkxml2xmlin/netboot-proxy-network.xml
  tests/networkxml2xmlout/netboot-proxy-network.xml
  tests/networkxml2xmltest.c: add new tests

docs/formatnetwork.html.in
docs/schemas/network.rng
src/conf/network_conf.c
src/conf/network_conf.h
src/network/bridge_driver.c
tests/networkxml2xmlin/netboot-proxy-network.xml [new file with mode: 0644]
tests/networkxml2xmlout/netboot-proxy-network.xml [new file with mode: 0644]
tests/networkxml2xmltest.c

index e471385e251c770b06fec6aa829c095178b86fb1..eb61f15894e2b4ee937cbfc0b4c859636f23a040 100644 (file)
        name to be given that host by the DHCP server (via the
         <code>name</code> attribute).  <span class="since">Since 0.4.5</span>
       </dd><dt><code>bootp</code></dt><dd>The optional <code>bootp</code>
-       element specifies BOOTP options to be provided by the DHCP server.
-       Only one attribute is supported, <code>file</code>, giving the file
-       to be used for the boot image).  The BOOTP options currently have to
-       be the same for all address ranges and statically assigned addresses.<span
-       class="since">Since 0.7.1.</span>
+        element specifies BOOTP options to be provided by the DHCP server.
+        Two attributes are supported: <code>file</code> is mandatory and
+        gives the file to be used for the boot image; <code>server</code> is
+        optional and gives the address of the TFTP server from which the boot
+        image will be fetched.  <code>server</code> defaults to the same host
+        that runs the DHCP server, as is the case when the <code>tftp</code>
+        element is used.  The BOOTP options currently have to be the same
+        for all address ranges and statically assigned addresses.<span
+        class="since">Since 0.7.1 (<code>server</code> since 0.7.3).</span>
+      </dd>
     </dl>
 
     <h2><a name="examples">Example configuration</a></h2>
index 7a2d7d4f4da5ccc6dae62c039384b5a927f03628..adef792ed26f441b7d2d74581a3c6b10164a4520 100644 (file)
        <optional>
          <element name="bootp">
            <attribute name="file"><text/></attribute>
+            <optional>
+              <attribute name="server"><text/></attribute>
+            </optional>
          </element>
        </optional>
       </element>
index 40f5fdd08190803ade2f0483af3d84e99695f110..fd8efb0b92b5e968b9496d5e9360cde0f0790354 100644 (file)
@@ -117,6 +117,7 @@ void virNetworkDefFree(virNetworkDefPtr def)
 
     VIR_FREE(def->tftproot);
     VIR_FREE(def->bootfile);
+    VIR_FREE(def->bootserver);
 
     VIR_FREE(def);
 }
@@ -313,6 +314,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
             }
 
             def->bootfile = (char *)file;
+            def->bootserver = (char *) xmlGetProp(cur, BAD_CAST "server");
         }
 
         cur = cur->next;
@@ -671,8 +673,13 @@ char *virNetworkDefFormat(virConnectPtr conn,
                 virBufferAddLit(&buf, "/>\n");
             }
             if (def->bootfile) {
-                virBufferEscapeString(&buf, "      <bootp file='%s' />\n",
+                virBufferEscapeString(&buf, "      <bootp file='%s' ",
                                       def->bootfile);
+                if (def->bootserver) {
+                    virBufferEscapeString(&buf, "server='%s' ",
+                                          def->bootserver);
+                }
+                virBufferAddLit(&buf, "/>\n");
             }
 
             virBufferAddLit(&buf, "    </dhcp>\n");
index e983a015a14fde50e7df9e15336bc9ec633bed35..6175b0f65d16bb809317d0a1c04a4444b4d5b3a4 100644 (file)
@@ -81,6 +81,7 @@ struct _virNetworkDef {
 
     char *tftproot;
     char *bootfile;
+    char *bootserver;
 };
 
 typedef struct _virNetworkObj virNetworkObj;
index 95bc810416b830a58a647cbf480f41de04b066c3..bc241ef4dd666d7fa45a4b23766a50440cb87233 100644 (file)
@@ -402,7 +402,7 @@ networkBuildDnsmasqArgv(virConnectPtr conn,
         (2 * network->def->nhosts) +
         /* --enable-tftp --tftp-root /srv/tftp */
         (network->def->tftproot ? 3 : 0) +
-        /* --dhcp-boot pxeboot.img */
+        /* --dhcp-boot pxeboot.img[,,12.34.56.78] */
         (network->def->bootfile ? 2 : 0) +
         1;  /* NULL */
 
@@ -488,8 +488,13 @@ networkBuildDnsmasqArgv(virConnectPtr conn,
         APPEND_ARG(*argv, i++, network->def->tftproot);
     }
     if (network->def->bootfile) {
+        snprintf(buf, sizeof(buf), "%s%s%s",
+                 network->def->bootfile,
+                 network->def->bootserver ? ",," : "",
+                 network->def->bootserver ? network->def->bootserver : "");
+
         APPEND_ARG(*argv, i++, "--dhcp-boot");
-        APPEND_ARG(*argv, i++, network->def->bootfile);
+        APPEND_ARG(*argv, i++, buf);
     }
 
 #undef APPEND_ARG
diff --git a/tests/networkxml2xmlin/netboot-proxy-network.xml b/tests/networkxml2xmlin/netboot-proxy-network.xml
new file mode 100644 (file)
index 0000000..ecb6738
--- /dev/null
@@ -0,0 +1,13 @@
+<network>
+  <name>netboot</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <bridge name="virbr1" stp='off' delay='1'/>
+  <domain name="example.com"/>
+  <forward/>
+  <ip address="192.168.122.1" netmask="255.255.255.0">
+    <dhcp>
+      <range start="192.168.122.2" end="192.168.122.254" />
+      <bootp file="pxeboot.img" server="10.20.30.40" />
+    </dhcp>
+  </ip>
+</network>
diff --git a/tests/networkxml2xmlout/netboot-proxy-network.xml b/tests/networkxml2xmlout/netboot-proxy-network.xml
new file mode 100644 (file)
index 0000000..e11c50b
--- /dev/null
@@ -0,0 +1,13 @@
+<network>
+  <name>netboot</name>
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
+  <forward mode='nat'/>
+  <bridge name='virbr1' stp='off' delay='1' />
+  <domain name='example.com'/>
+  <ip address='192.168.122.1' netmask='255.255.255.0'>
+    <dhcp>
+      <range start='192.168.122.2' end='192.168.122.254' />
+      <bootp file='pxeboot.img' server='10.20.30.40' />
+    </dhcp>
+  </ip>
+</network>
index b02d735a476b253d432b914ad51e9ce13f171a1e..957e64b8acaa40ad7f554f00f1fbce9dde584e20 100644 (file)
@@ -89,6 +89,7 @@ mymain(int argc, char **argv)
     DO_TEST("routed-network");
     DO_TEST("nat-network");
     DO_TEST("netboot-network");
+    DO_TEST("netboot-proxy-network");
 
     return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }