提交 936565c7 编写于 作者: P Paolo Bonzini 提交者: Daniel Veillard

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
上级 16c1c083
...@@ -142,11 +142,16 @@ ...@@ -142,11 +142,16 @@
name to be given that host by the DHCP server (via the name to be given that host by the DHCP server (via the
<code>name</code> attribute). <span class="since">Since 0.4.5</span> <code>name</code> attribute). <span class="since">Since 0.4.5</span>
</dd><dt><code>bootp</code></dt><dd>The optional <code>bootp</code> </dd><dt><code>bootp</code></dt><dd>The optional <code>bootp</code>
element specifies BOOTP options to be provided by the DHCP server. element specifies BOOTP options to be provided by the DHCP server.
Only one attribute is supported, <code>file</code>, giving the file Two attributes are supported: <code>file</code> is mandatory and
to be used for the boot image). The BOOTP options currently have to gives the file to be used for the boot image; <code>server</code> is
be the same for all address ranges and statically assigned addresses.<span optional and gives the address of the TFTP server from which the boot
class="since">Since 0.7.1.</span> 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> </dl>
<h2><a name="examples">Example configuration</a></h2> <h2><a name="examples">Example configuration</a></h2>
......
...@@ -109,6 +109,9 @@ ...@@ -109,6 +109,9 @@
<optional> <optional>
<element name="bootp"> <element name="bootp">
<attribute name="file"><text/></attribute> <attribute name="file"><text/></attribute>
<optional>
<attribute name="server"><text/></attribute>
</optional>
</element> </element>
</optional> </optional>
</element> </element>
......
...@@ -117,6 +117,7 @@ void virNetworkDefFree(virNetworkDefPtr def) ...@@ -117,6 +117,7 @@ void virNetworkDefFree(virNetworkDefPtr def)
VIR_FREE(def->tftproot); VIR_FREE(def->tftproot);
VIR_FREE(def->bootfile); VIR_FREE(def->bootfile);
VIR_FREE(def->bootserver);
VIR_FREE(def); VIR_FREE(def);
} }
...@@ -313,6 +314,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn, ...@@ -313,6 +314,7 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
} }
def->bootfile = (char *)file; def->bootfile = (char *)file;
def->bootserver = (char *) xmlGetProp(cur, BAD_CAST "server");
} }
cur = cur->next; cur = cur->next;
...@@ -671,8 +673,13 @@ char *virNetworkDefFormat(virConnectPtr conn, ...@@ -671,8 +673,13 @@ char *virNetworkDefFormat(virConnectPtr conn,
virBufferAddLit(&buf, "/>\n"); virBufferAddLit(&buf, "/>\n");
} }
if (def->bootfile) { if (def->bootfile) {
virBufferEscapeString(&buf, " <bootp file='%s' />\n", virBufferEscapeString(&buf, " <bootp file='%s' ",
def->bootfile); def->bootfile);
if (def->bootserver) {
virBufferEscapeString(&buf, "server='%s' ",
def->bootserver);
}
virBufferAddLit(&buf, "/>\n");
} }
virBufferAddLit(&buf, " </dhcp>\n"); virBufferAddLit(&buf, " </dhcp>\n");
......
...@@ -81,6 +81,7 @@ struct _virNetworkDef { ...@@ -81,6 +81,7 @@ struct _virNetworkDef {
char *tftproot; char *tftproot;
char *bootfile; char *bootfile;
char *bootserver;
}; };
typedef struct _virNetworkObj virNetworkObj; typedef struct _virNetworkObj virNetworkObj;
......
...@@ -402,7 +402,7 @@ networkBuildDnsmasqArgv(virConnectPtr conn, ...@@ -402,7 +402,7 @@ networkBuildDnsmasqArgv(virConnectPtr conn,
(2 * network->def->nhosts) + (2 * network->def->nhosts) +
/* --enable-tftp --tftp-root /srv/tftp */ /* --enable-tftp --tftp-root /srv/tftp */
(network->def->tftproot ? 3 : 0) + (network->def->tftproot ? 3 : 0) +
/* --dhcp-boot pxeboot.img */ /* --dhcp-boot pxeboot.img[,,12.34.56.78] */
(network->def->bootfile ? 2 : 0) + (network->def->bootfile ? 2 : 0) +
1; /* NULL */ 1; /* NULL */
...@@ -488,8 +488,13 @@ networkBuildDnsmasqArgv(virConnectPtr conn, ...@@ -488,8 +488,13 @@ networkBuildDnsmasqArgv(virConnectPtr conn,
APPEND_ARG(*argv, i++, network->def->tftproot); APPEND_ARG(*argv, i++, network->def->tftproot);
} }
if (network->def->bootfile) { 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++, "--dhcp-boot");
APPEND_ARG(*argv, i++, network->def->bootfile); APPEND_ARG(*argv, i++, buf);
} }
#undef APPEND_ARG #undef APPEND_ARG
......
<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>
<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>
...@@ -89,6 +89,7 @@ mymain(int argc, char **argv) ...@@ -89,6 +89,7 @@ mymain(int argc, char **argv)
DO_TEST("routed-network"); DO_TEST("routed-network");
DO_TEST("nat-network"); DO_TEST("nat-network");
DO_TEST("netboot-network"); DO_TEST("netboot-network");
DO_TEST("netboot-proxy-network");
return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册