提交 93135abf 编写于 作者: V Vasiliy Tolstov 提交者: Laine Stump

conf: allow setting peer address in <ip> element of <interface>

The peer attribute is used to set the property of the same name in the
interface IP info:

  <interface type='ethernet'>
    ...
    <ip family='ipv4' address='192.168.122.5'
        prefix='32' peer='192.168.122.6'/>
    ...
  </interface>

Note that this element is used to set the IP information on the
*guest* side interface, not the host side interface - that will be
supported in an upcoming patch.

(This is an updated *re*-commit of commit 690969af, which was
subsequently reverted in commit 1d14b13f).
Signed-off-by: NVasiliy Tolstov <v.tolstov@selfip.ru>
Signed-off-by: NLaine Stump <laine@laine.org>
上级 f1e0d0da
...@@ -4967,6 +4967,7 @@ qemu-kvm -net nic,model=? /dev/null ...@@ -4967,6 +4967,7 @@ qemu-kvm -net nic,model=? /dev/null
&lt;source network='default'/&gt; &lt;source network='default'/&gt;
&lt;target dev='vnet0'/&gt; &lt;target dev='vnet0'/&gt;
<b>&lt;ip address='192.168.122.5' prefix='24'/&gt;</b> <b>&lt;ip address='192.168.122.5' prefix='24'/&gt;</b>
<b>&lt;ip address='192.168.122.5' prefix='24' peer='10.0.0.10'/&gt;</b>
<b>&lt;route family='ipv4' address='192.168.122.0' prefix='24' gateway='192.168.122.1'/&gt;</b> <b>&lt;route family='ipv4' address='192.168.122.0' prefix='24' gateway='192.168.122.1'/&gt;</b>
<b>&lt;route family='ipv4' address='192.168.122.8' gateway='192.168.122.1'/&gt;</b> <b>&lt;route family='ipv4' address='192.168.122.8' gateway='192.168.122.1'/&gt;</b>
&lt;/interface&gt; &lt;/interface&gt;
...@@ -4985,21 +4986,30 @@ qemu-kvm -net nic,model=? /dev/null ...@@ -4985,21 +4986,30 @@ qemu-kvm -net nic,model=? /dev/null
</pre> </pre>
<p> <p>
<span class="since">Since 1.2.12</span> the network devices and host devices <span class="since">Since 1.2.12</span> network devices and
with network capabilities can be provided zero or more IP addresses to set hostdev devices with network capabilities can optionally be provided
on the target device. Note that some hypervisors or network device types one or more IP addresses to set on the network device in the
will simply ignore them or only use the first one. The <code>family</code> guest. Note that some hypervisors or network device types will
attribute can be set to either <code>ipv4</code> or <code>ipv6</code>, the simply ignore them or only use the first one.
<code>address</code> attribute holds the IP address. The <code>prefix</code> The <code>family</code> attribute can be set to
is not mandatory since some hypervisors do not handle it. either <code>ipv4</code> or <code>ipv6</code>, and the
</p> <code>address</code> attribute contains the IP address. The
optional <code>prefix</code> is the number of 1 bits in the
<p> netmask, and will be automatically set if not specified - for
<span class="since">Since 1.2.12</span> route elements can also be added IPv4 the default prefix is determined according to the network
to define the network routes to use for the network device. The attributes "class" (A, B, or C - see RFC870), and for IPv6 the default
of this element are described in the documentation for the <code>route</code> prefix is 64. The optional <code>peer</code> attribute holds the
element in <a href="formatnetwork.html#elementsStaticroute">network definitions</a>. IP address of the other end of a point-to-point network
This is only used by the LXC driver. device <span class="since">(since 2.0.0)</span>.
</p>
<p>
<span class="since">Since 1.2.12</span> route elements can also be
added to define IP routes to add in the guest. The attributes of
this element are described in the documentation for
the <code>route</code> element
in <a href="formatnetwork.html#elementsStaticroute">network
definitions</a>. This is used by the LXC driver.
</p> </p>
<h5><a name="elementVhostuser">vhost-user interface</a></h5> <h5><a name="elementVhostuser">vhost-user interface</a></h5>
......
...@@ -2629,6 +2629,11 @@ ...@@ -2629,6 +2629,11 @@
<ref name="ipPrefix"/> <ref name="ipPrefix"/>
</attribute> </attribute>
</optional> </optional>
<optional>
<attribute name="peer">
<ref name="ipAddr"/>
</attribute>
</optional>
<empty/> <empty/>
</element> </element>
</zeroOrMore> </zeroOrMore>
......
...@@ -6121,7 +6121,7 @@ virDomainNetIPParseXML(xmlNodePtr node) ...@@ -6121,7 +6121,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
unsigned int prefixValue = 0; unsigned int prefixValue = 0;
char *familyStr = NULL; char *familyStr = NULL;
int family = AF_UNSPEC; int family = AF_UNSPEC;
char *address = NULL; char *address = NULL, *peer = NULL;
if (!(address = virXMLPropString(node, "address"))) { if (!(address = virXMLPropString(node, "address"))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
...@@ -6159,6 +6159,13 @@ virDomainNetIPParseXML(xmlNodePtr node) ...@@ -6159,6 +6159,13 @@ virDomainNetIPParseXML(xmlNodePtr node)
} }
ip->prefix = prefixValue; ip->prefix = prefixValue;
if ((peer = virXMLPropString(node, "peer")) != NULL &&
virSocketAddrParse(&ip->peer, peer, family) < 0) {
virReportError(VIR_ERR_INVALID_ARG,
_("Invalid peer '%s' in <ip>"), peer);
goto cleanup;
}
ret = ip; ret = ip;
ip = NULL; ip = NULL;
...@@ -6166,6 +6173,7 @@ virDomainNetIPParseXML(xmlNodePtr node) ...@@ -6166,6 +6173,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
VIR_FREE(prefixStr); VIR_FREE(prefixStr);
VIR_FREE(familyStr); VIR_FREE(familyStr);
VIR_FREE(address); VIR_FREE(address);
VIR_FREE(peer);
VIR_FREE(ip); VIR_FREE(ip);
return ret; return ret;
} }
...@@ -20264,6 +20272,12 @@ virDomainNetIPInfoFormat(virBufferPtr buf, ...@@ -20264,6 +20272,12 @@ virDomainNetIPInfoFormat(virBufferPtr buf,
virBufferAsprintf(buf, " family='%s'", familyStr); virBufferAsprintf(buf, " family='%s'", familyStr);
if (def->ips[i]->prefix) if (def->ips[i]->prefix)
virBufferAsprintf(buf, " prefix='%u'", def->ips[i]->prefix); virBufferAsprintf(buf, " prefix='%u'", def->ips[i]->prefix);
if (VIR_SOCKET_ADDR_VALID(&def->ips[i]->peer)) {
if (!(ipStr = virSocketAddrFormat(&def->ips[i]->peer)))
return -1;
virBufferAsprintf(buf, " peer='%s'", ipStr);
VIR_FREE(ipStr);
}
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
typedef struct { typedef struct {
virSocketAddr address; /* ipv4 or ipv6 address */ virSocketAddr address; /* ipv4 or ipv6 address */
unsigned int prefix; /* number of 1 bits in the net mask */ virSocketAddr peer; /* ipv4 or ipv6 address of peer */
unsigned int prefix; /* number of 1 bits in the netmask */
} virNetDevIPAddr, *virNetDevIPAddrPtr; } virNetDevIPAddr, *virNetDevIPAddrPtr;
typedef struct { typedef struct {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册