mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
network: add 'bootp' and 'tftp' config
Currently, libvirtd will start a dnsmasq process for the virtual network, but (aside from killing the dnsmasq process and replacing it), there's no way to define tftp boot options. This change introduces the appropriate tags to the dhcp configuration: <network> <name>default</name> <bridge name="virbr%d" /> <forward/> <ip address="192.168.122.1" netmask="255.255.255.0"> <tftp root="/var/lib/tftproot" /> <dhcp> <range start="192.168.122.2" end="192.168.122.254" /> <bootp file="pxeboot.img"/> </dhcp> </ip> </network> When the attributes are present, these are passed to the arguments to dnsmasq: dnsmasq [...] --enable-tftp --tftp-root /srv/tftp --dhcp-boot pxeboot.img ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ from <tftp /> from <bootp /> At present, only local tftp servers are supported (ie, dnsmasq runs as the tftp server), but we could improve this in future by adding a server= attribute. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> 2009-09-21 Paolo Bonzini <pbonzini@redhat.com> Jeremy Kerr <jk@ozlabs.org> * docs/formatnetwork.html.in: Document new tags. * docs/formatnetwork.html: Regenerate. * docs/schemas/network.rng: Update. * src/network_conf.c (virNetworkDefFree): Free new fields. (virNetworkDHCPRangeDefParseXML): Parse <bootp>. (virNetworkIPParseXML): New, parsing <dhcp> and <tftp>. (virNetworkDefParseXML): Use virNetworkIPParseXML instead of virNetworkDHCPRangeDefParseXML. (virNetworkDefFormat): Pretty print new fields. * src/network_conf.h (struct _virNetworkDef): Add netboot fields. * src/network_driver.c (networkBuildDnsmasqArgv): Add TFTP and BOOTP arguments. * tests/Makefile.am (EXTRA_DIST): Add networkschemadata. * tests/networkschematest: Look in networkschemadata. * tests/networkschemadata/netboot-network.xml: New.
This commit is contained in:
parent
03d777f345
commit
738ee810b4
@ -113,9 +113,13 @@
|
|||||||
address will be their default route. The <code>netmask</code>
|
address will be their default route. The <code>netmask</code>
|
||||||
attribute defines the significant bits of the network address,
|
attribute defines the significant bits of the network address,
|
||||||
again specified in dotted-decimal format. <span class="since">Since 0.3.0</span>
|
again specified in dotted-decimal format. <span class="since">Since 0.3.0</span>
|
||||||
</dd>
|
</dd><dt><code>tftp</code></dt><dd>Immediately within
|
||||||
<dt><code>dhcp</code></dt>
|
the <code>ip</code> element there is an optional <code>tftp</code>
|
||||||
<dd>Immediately within the <code>ip</code> element there is an
|
element. The presence of this element and of its attribute
|
||||||
|
<code>root</code> enables TFTP services. The attribute specifies
|
||||||
|
the path to the root directory served via TFTP.
|
||||||
|
<span class="since">Since 0.7.1</span>
|
||||||
|
</dd><dt><code>dhcp</code></dt><dd>Also within the <code>ip</code> element there is an
|
||||||
optional <code>dhcp</code> element. The presence of this element
|
optional <code>dhcp</code> element. The presence of this element
|
||||||
enables DHCP services on the virtual network. It will further
|
enables DHCP services on the virtual network. It will further
|
||||||
contain one or more <code>range</code> elements.
|
contain one or more <code>range</code> elements.
|
||||||
@ -137,7 +141,12 @@
|
|||||||
assigned to that host (via the <code>ip</code> attribute), and the
|
assigned to that host (via the <code>ip</code> attribute), and the
|
||||||
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>
|
</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>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h2><a name="examples">Example configuration</a></h2>
|
<h2><a name="examples">Example configuration</a></h2>
|
||||||
|
@ -60,6 +60,11 @@
|
|||||||
<optional>
|
<optional>
|
||||||
<attribute name="netmask"><text/></attribute>
|
<attribute name="netmask"><text/></attribute>
|
||||||
</optional>
|
</optional>
|
||||||
|
<optional>
|
||||||
|
<element name="tftp">
|
||||||
|
<attribute name="root"><text/></attribute>
|
||||||
|
</element>
|
||||||
|
</optional>
|
||||||
<!-- Define the range(s) of IP addresses that the DHCP
|
<!-- Define the range(s) of IP addresses that the DHCP
|
||||||
server should hand out -->
|
server should hand out -->
|
||||||
<element name="dhcp">
|
<element name="dhcp">
|
||||||
@ -76,6 +81,11 @@
|
|||||||
<attribute name="ip"><text/></attribute>
|
<attribute name="ip"><text/></attribute>
|
||||||
</element>
|
</element>
|
||||||
</zeroOrMore>
|
</zeroOrMore>
|
||||||
|
<optional>
|
||||||
|
<element name="bootp">
|
||||||
|
<attribute name="file"><text/></attribute>
|
||||||
|
</element>
|
||||||
|
</optional>
|
||||||
</element>
|
</element>
|
||||||
</element>
|
</element>
|
||||||
</optional>
|
</optional>
|
||||||
|
@ -115,6 +115,9 @@ void virNetworkDefFree(virNetworkDefPtr def)
|
|||||||
}
|
}
|
||||||
VIR_FREE(def->hosts);
|
VIR_FREE(def->hosts);
|
||||||
|
|
||||||
|
VIR_FREE(def->tftproot);
|
||||||
|
VIR_FREE(def->bootfile);
|
||||||
|
|
||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,6 +302,17 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
|
|||||||
def->hosts[def->nhosts].name = (char *)name;
|
def->hosts[def->nhosts].name = (char *)name;
|
||||||
def->hosts[def->nhosts].ip = (char *)ip;
|
def->hosts[def->nhosts].ip = (char *)ip;
|
||||||
def->nhosts++;
|
def->nhosts++;
|
||||||
|
|
||||||
|
} else if (cur->type == XML_ELEMENT_NODE &&
|
||||||
|
xmlStrEqual(cur->name, BAD_CAST "bootp")) {
|
||||||
|
xmlChar *file;
|
||||||
|
|
||||||
|
if (!(file = xmlGetProp(cur, BAD_CAST "file"))) {
|
||||||
|
cur = cur->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
def->bootfile = (char *)file;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
@ -307,6 +321,37 @@ virNetworkDHCPRangeDefParseXML(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
virNetworkIPParseXML(virConnectPtr conn,
|
||||||
|
virNetworkDefPtr def,
|
||||||
|
xmlNodePtr node) {
|
||||||
|
xmlNodePtr cur;
|
||||||
|
|
||||||
|
cur = node->children;
|
||||||
|
while (cur != NULL) {
|
||||||
|
if (cur->type == XML_ELEMENT_NODE &&
|
||||||
|
xmlStrEqual(cur->name, BAD_CAST "dhcp")) {
|
||||||
|
int result = virNetworkDHCPRangeDefParseXML(conn, def, cur);
|
||||||
|
if (result)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
} else if (cur->type == XML_ELEMENT_NODE &&
|
||||||
|
xmlStrEqual(cur->name, BAD_CAST "tftp")) {
|
||||||
|
xmlChar *root;
|
||||||
|
|
||||||
|
if (!(root = xmlGetProp(cur, BAD_CAST "root"))) {
|
||||||
|
cur = cur->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
def->tftproot = (char *)root;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static virNetworkDefPtr
|
static virNetworkDefPtr
|
||||||
virNetworkDefParseXML(virConnectPtr conn,
|
virNetworkDefParseXML(virConnectPtr conn,
|
||||||
xmlXPathContextPtr ctxt)
|
xmlXPathContextPtr ctxt)
|
||||||
@ -363,7 +408,7 @@ virNetworkDefParseXML(virConnectPtr conn,
|
|||||||
/* XXX someday we want IPv6 too, so inet_aton won't work there */
|
/* XXX someday we want IPv6 too, so inet_aton won't work there */
|
||||||
struct in_addr inaddress, innetmask;
|
struct in_addr inaddress, innetmask;
|
||||||
char *netaddr;
|
char *netaddr;
|
||||||
xmlNodePtr dhcp;
|
xmlNodePtr ip;
|
||||||
|
|
||||||
if (inet_pton(AF_INET, def->ipAddress, &inaddress) <= 0) {
|
if (inet_pton(AF_INET, def->ipAddress, &inaddress) <= 0) {
|
||||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -386,8 +431,8 @@ virNetworkDefParseXML(virConnectPtr conn,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dhcp = virXPathNode(conn, "./ip[1]/dhcp[1]", ctxt)) &&
|
if ((ip = virXPathNode(conn, "./ip[1]", ctxt)) &&
|
||||||
virNetworkDHCPRangeDefParseXML(conn, def, dhcp) < 0)
|
virNetworkIPParseXML(conn, def, ip) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,6 +650,10 @@ char *virNetworkDefFormat(virConnectPtr conn,
|
|||||||
|
|
||||||
virBufferAddLit(&buf, ">\n");
|
virBufferAddLit(&buf, ">\n");
|
||||||
|
|
||||||
|
if (def->tftproot) {
|
||||||
|
virBufferEscapeString(&buf, " <tftp root='%s' />\n",
|
||||||
|
def->tftproot);
|
||||||
|
}
|
||||||
if ((def->nranges || def->nhosts)) {
|
if ((def->nranges || def->nhosts)) {
|
||||||
int i;
|
int i;
|
||||||
virBufferAddLit(&buf, " <dhcp>\n");
|
virBufferAddLit(&buf, " <dhcp>\n");
|
||||||
@ -621,6 +670,11 @@ char *virNetworkDefFormat(virConnectPtr conn,
|
|||||||
virBufferVSprintf(&buf, "ip='%s' ", def->hosts[i].ip);
|
virBufferVSprintf(&buf, "ip='%s' ", def->hosts[i].ip);
|
||||||
virBufferAddLit(&buf, "/>\n");
|
virBufferAddLit(&buf, "/>\n");
|
||||||
}
|
}
|
||||||
|
if (def->bootfile) {
|
||||||
|
virBufferEscapeString(&buf, " <bootp file='%s' />\n",
|
||||||
|
def->bootfile);
|
||||||
|
}
|
||||||
|
|
||||||
virBufferAddLit(&buf, " </dhcp>\n");
|
virBufferAddLit(&buf, " </dhcp>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +78,9 @@ struct _virNetworkDef {
|
|||||||
|
|
||||||
unsigned int nhosts; /* Zero or more dhcp hosts */
|
unsigned int nhosts; /* Zero or more dhcp hosts */
|
||||||
virNetworkDHCPHostDefPtr hosts;
|
virNetworkDHCPHostDefPtr hosts;
|
||||||
|
|
||||||
|
char *tftproot;
|
||||||
|
char *bootfile;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _virNetworkObj virNetworkObj;
|
typedef struct _virNetworkObj virNetworkObj;
|
||||||
|
@ -400,6 +400,10 @@ networkBuildDnsmasqArgv(virConnectPtr conn,
|
|||||||
(2 * network->def->nranges) + /* --dhcp-range 10.0.0.2,10.0.0.254 */
|
(2 * network->def->nranges) + /* --dhcp-range 10.0.0.2,10.0.0.254 */
|
||||||
/* --dhcp-host 01:23:45:67:89:0a,hostname,10.0.0.3 */
|
/* --dhcp-host 01:23:45:67:89:0a,hostname,10.0.0.3 */
|
||||||
(2 * network->def->nhosts) +
|
(2 * network->def->nhosts) +
|
||||||
|
/* --enable-tftp --tftp-root /srv/tftp */
|
||||||
|
(network->def->tftproot ? 3 : 0) +
|
||||||
|
/* --dhcp-boot pxeboot.img */
|
||||||
|
(network->def->bootfile ? 2 : 0) +
|
||||||
1; /* NULL */
|
1; /* NULL */
|
||||||
|
|
||||||
if (VIR_ALLOC_N(*argv, len) < 0)
|
if (VIR_ALLOC_N(*argv, len) < 0)
|
||||||
@ -478,6 +482,16 @@ networkBuildDnsmasqArgv(virConnectPtr conn,
|
|||||||
APPEND_ARG(*argv, i++, buf);
|
APPEND_ARG(*argv, i++, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (network->def->tftproot) {
|
||||||
|
APPEND_ARG(*argv, i++, "--enable-tftp");
|
||||||
|
APPEND_ARG(*argv, i++, "--tftp-root");
|
||||||
|
APPEND_ARG(*argv, i++, network->def->tftproot);
|
||||||
|
}
|
||||||
|
if (network->def->bootfile) {
|
||||||
|
APPEND_ARG(*argv, i++, "--dhcp-boot");
|
||||||
|
APPEND_ARG(*argv, i++, network->def->bootfile);
|
||||||
|
}
|
||||||
|
|
||||||
#undef APPEND_ARG
|
#undef APPEND_ARG
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -53,6 +53,7 @@ EXTRA_DIST = \
|
|||||||
capabilityschematest \
|
capabilityschematest \
|
||||||
capabilityschemadata \
|
capabilityschemadata \
|
||||||
networkschematest \
|
networkschematest \
|
||||||
|
networkschemadata \
|
||||||
domainschematest \
|
domainschematest \
|
||||||
domainschemadata \
|
domainschemadata \
|
||||||
interfaceschemadata \
|
interfaceschemadata \
|
||||||
|
12
tests/networkschemadata/netboot-network.xml
Normal file
12
tests/networkschemadata/netboot-network.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<network>
|
||||||
|
<name>netboot</name>
|
||||||
|
<bridge name="virbr1" />
|
||||||
|
<forward/>
|
||||||
|
<ip address="192.168.122.1" netmask="255.255.255.0">
|
||||||
|
<tftp root="/var/lib/tftproot" />
|
||||||
|
<dhcp>
|
||||||
|
<range start="192.168.122.2" end="192.168.122.254" />
|
||||||
|
<bootp file="pxeboot.img" />
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
</network>
|
@ -3,7 +3,7 @@
|
|||||||
test -z "$srcdir" && srcdir=`pwd`
|
test -z "$srcdir" && srcdir=`pwd`
|
||||||
test -z "$abs_srcdir" && abs_srcdir=`pwd`
|
test -z "$abs_srcdir" && abs_srcdir=`pwd`
|
||||||
|
|
||||||
DIRS="../src/network"
|
DIRS="../src/network networkschemadata"
|
||||||
|
|
||||||
n=0
|
n=0
|
||||||
f=0
|
f=0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user