[libvirt] [PATCH] add <bootp 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. 2009-10-22 Paolo Bonzini <pbonzini@redhat.com> * 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: New. * tests/networkxml2xmlout/netboot-proxy-network.xml: New. * tests/networkxml2xmltest.c: Add the new test. --- docs/formatnetwork.html.in | 15 ++++++++++----- docs/schemas/network.rng | 3 +++ src/conf/network_conf.c | 9 ++++++++- src/conf/network_conf.h | 1 + src/network/bridge_driver.c | 9 +++++++-- tests/networkxml2xmlin/netboot-proxy-network.xml | 13 +++++++++++++ tests/networkxml2xmlout/netboot-proxy-network.xml | 13 +++++++++++++ tests/networkxml2xmltest.c | 1 + 8 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 tests/networkxml2xmlin/netboot-proxy-network.xml create mode 100644 tests/networkxml2xmlout/netboot-proxy-network.xml diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in index e471385..eb61f15 100644 --- a/docs/formatnetwork.html.in +++ b/docs/formatnetwork.html.in @@ -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> diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng index 7a2d7d4..adef792 100644 --- a/docs/schemas/network.rng +++ b/docs/schemas/network.rng @@ -109,6 +109,9 @@ <optional> <element name="bootp"> <attribute name="file"><text/></attribute> + <optional> + <attribute name="server"><text/></attribute> + </optional> </element> </optional> </element> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 40f5fdd..fd8efb0 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -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"); diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index e983a01..6175b0f 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -81,6 +81,7 @@ struct _virNetworkDef { char *tftproot; char *bootfile; + char *bootserver; }; typedef struct _virNetworkObj virNetworkObj; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 95bc810..bc241ef 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -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 index 0000000..ecb6738 --- /dev/null +++ b/tests/networkxml2xmlin/netboot-proxy-network.xml @@ -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 index 0000000..e11c50b --- /dev/null +++ b/tests/networkxml2xmlout/netboot-proxy-network.xml @@ -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> diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index b02d735..957e64b 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -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); } -- 1.6.2.5

On 10/22/2009 12:20 PM, Paolo Bonzini wrote:
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.
2009-10-22 Paolo Bonzini <pbonzini@redhat.com>
* 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: New. * tests/networkxml2xmlout/netboot-proxy-network.xml: New. * tests/networkxml2xmltest.c: Add the new test. --- docs/formatnetwork.html.in | 15 ++++++++++----- docs/schemas/network.rng | 3 +++ src/conf/network_conf.c | 9 ++++++++- src/conf/network_conf.h | 1 + src/network/bridge_driver.c | 9 +++++++-- tests/networkxml2xmlin/netboot-proxy-network.xml | 13 +++++++++++++ tests/networkxml2xmlout/netboot-proxy-network.xml | 13 +++++++++++++ tests/networkxml2xmltest.c | 1 + 8 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 tests/networkxml2xmlin/netboot-proxy-network.xml create mode 100644 tests/networkxml2xmlout/netboot-proxy-network.xml
diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in index e471385..eb61f15 100644 --- a/docs/formatnetwork.html.in +++ b/docs/formatnetwork.html.in @@ -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> diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng index 7a2d7d4..adef792 100644 --- a/docs/schemas/network.rng +++ b/docs/schemas/network.rng @@ -109,6 +109,9 @@ <optional> <element name="bootp"> <attribute name="file"><text/></attribute> + <optional> + <attribute name="server"><text/></attribute> + </optional> </element> </optional> </element> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 40f5fdd..fd8efb0 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -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"); diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index e983a01..6175b0f 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -81,6 +81,7 @@ struct _virNetworkDef {
char *tftproot; char *bootfile; + char *bootserver; };
typedef struct _virNetworkObj virNetworkObj; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 95bc810..bc241ef 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -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 index 0000000..ecb6738 --- /dev/null +++ b/tests/networkxml2xmlin/netboot-proxy-network.xml @@ -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 index 0000000..e11c50b --- /dev/null +++ b/tests/networkxml2xmlout/netboot-proxy-network.xml @@ -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> diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index b02d735..957e64b 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -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); }
ACK, looks good to me. - Cole

On 10/26/2009 08:14 AM, Paolo Bonzini wrote:
On 10/22/2009 07:55 PM, Cole Robinson wrote:
ACK, looks good to me.
- Cole
Could you push it for me?
Thanks in advance,
I'd prefer if either DV or danpb pushed this, since it's an API addition. Unfortunately they are both offline today. - Cole

On Mon, Oct 26, 2009 at 08:53:58AM -0400, Cole Robinson wrote:
On 10/26/2009 08:14 AM, Paolo Bonzini wrote:
On 10/22/2009 07:55 PM, Cole Robinson wrote:
ACK, looks good to me.
- Cole
Could you push it for me?
Thanks in advance,
I'd prefer if either DV or danpb pushed this, since it's an API addition. Unfortunately they are both offline today.
ACK, looks good to me. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Thu, Oct 22, 2009 at 06:20:32PM +0200, Paolo Bonzini wrote:
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.
Makes sense, nice complete patch, pushed :-) Thanks a lot ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (4)
-
Cole Robinson
-
Daniel P. Berrange
-
Daniel Veillard
-
Paolo Bonzini