Add support for an external TFTP boot server

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
This commit is contained in:
Paolo Bonzini 2009-10-28 15:57:49 +01:00 committed by Daniel Veillard
parent 16c1c0833b
commit 936565c701
8 changed files with 56 additions and 8 deletions

View File

@ -142,11 +142,16 @@
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>

View File

@ -109,6 +109,9 @@
<optional>
<element name="bootp">
<attribute name="file"><text/></attribute>
<optional>
<attribute name="server"><text/></attribute>
</optional>
</element>
</optional>
</element>

View 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");

View File

@ -81,6 +81,7 @@ struct _virNetworkDef {
char *tftproot;
char *bootfile;
char *bootserver;
};
typedef struct _virNetworkObj virNetworkObj;

View 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

View File

@ -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>

View File

@ -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>

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