mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
conf: add an attribute to turn on NAT for IPv6 virtual networks
Historically IPv6 did not support NAT, so when IPv6 was added to libvirt's virtual networks, when requesting <forward mode="nat"/> libvirt will NOT apply NAT to IPv6 traffic, only IPv4 traffic. This is an annoying historical design decision as it means we cannot enable IPv6 automatically. We thus need to introduce a new attribute <forward mode="nat"> <nat ipv6="yes"/> </forward> Reviewed-by: Laine Stump <laine@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
8774db431f
commit
927acaedec
@ -276,6 +276,20 @@
|
||||
</nat>
|
||||
</forward>
|
||||
...</pre>
|
||||
|
||||
<p>
|
||||
<span class="since">Since 6.5.0</span> it is possible to
|
||||
enable NAT with IPv6 networking. As noted above, IPv6
|
||||
has historically done plain forwarding and thus to avoid
|
||||
breaking historical compatibility, IPv6 NAT must be
|
||||
explicitly requested.
|
||||
</p>
|
||||
<pre>
|
||||
...
|
||||
<forward mode='nat'>
|
||||
<nat ipv6='yes'/>
|
||||
</forward>
|
||||
...</pre>
|
||||
</dd>
|
||||
|
||||
<dt><code>route</code></dt>
|
||||
|
@ -181,6 +181,11 @@
|
||||
</optional>
|
||||
<optional>
|
||||
<element name='nat'>
|
||||
<optional>
|
||||
<attribute name="ipv6">
|
||||
<ref name="virYesNo"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<interleave>
|
||||
<optional>
|
||||
<element name='address'>
|
||||
|
@ -1358,6 +1358,7 @@ virNetworkForwardNatDefParseXML(const char *networkName,
|
||||
int nNatAddrs, nNatPorts;
|
||||
char *addrStart = NULL;
|
||||
char *addrEnd = NULL;
|
||||
char *ipv6 = NULL;
|
||||
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
||||
|
||||
ctxt->node = node;
|
||||
@ -1369,6 +1370,21 @@ virNetworkForwardNatDefParseXML(const char *networkName,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ipv6 = virXMLPropString(node, "ipv6");
|
||||
if (ipv6) {
|
||||
int natIPv6;
|
||||
if ((natIPv6 = virTristateBoolTypeFromString(ipv6)) <= 0) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Invalid ipv6 setting '%s' "
|
||||
"in network '%s' NAT"),
|
||||
ipv6, networkName);
|
||||
VIR_FREE(ipv6);
|
||||
goto cleanup;
|
||||
}
|
||||
def->natIPv6 = natIPv6;
|
||||
VIR_FREE(ipv6);
|
||||
}
|
||||
|
||||
/* addresses for SNAT */
|
||||
nNatAddrs = virXPathNodeSet("./address", ctxt, &natAddrNodes);
|
||||
if (nNatAddrs < 0) {
|
||||
@ -2516,10 +2532,18 @@ virNetworkForwardNatDefFormat(virBufferPtr buf,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!addrEnd && !addrStart && !fwd->port.start && !fwd->port.end)
|
||||
if (!addrEnd && !addrStart && !fwd->port.start && !fwd->port.end && !fwd->natIPv6)
|
||||
return 0;
|
||||
|
||||
virBufferAddLit(buf, "<nat>\n");
|
||||
virBufferAddLit(buf, "<nat");
|
||||
if (fwd->natIPv6)
|
||||
virBufferAsprintf(buf, " ipv6='%s'", virTristateBoolTypeToString(fwd->natIPv6));
|
||||
|
||||
if (!addrEnd && !addrStart && !fwd->port.start && !fwd->port.end) {
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
return 0;
|
||||
}
|
||||
virBufferAddLit(buf, ">\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
if (addrStart) {
|
||||
@ -2627,7 +2651,8 @@ virNetworkDefFormatBuf(virBufferPtr buf,
|
||||
|| def->forward.port.start
|
||||
|| def->forward.port.end
|
||||
|| (def->forward.driverName
|
||||
!= VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT));
|
||||
!= VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT)
|
||||
|| def->forward.natIPv6);
|
||||
virBufferAsprintf(buf, "%s>\n", shortforward ? "/" : "");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
|
@ -244,6 +244,8 @@ struct _virNetworkForwardDef {
|
||||
/* ranges for NAT */
|
||||
virSocketAddrRange addr;
|
||||
virPortRange port;
|
||||
|
||||
virTristateBool natIPv6;
|
||||
};
|
||||
|
||||
typedef struct _virPortGroupDef virPortGroupDef;
|
||||
|
10
tests/networkxml2xmlin/nat-network-forward-nat-ipv6.xml
Normal file
10
tests/networkxml2xmlin/nat-network-forward-nat-ipv6.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<network>
|
||||
<name>default</name>
|
||||
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||
<bridge name="virbr0"/>
|
||||
<forward mode="nat">
|
||||
<nat ipv6="yes"/>
|
||||
</forward>
|
||||
<ip family="ipv6" address="2001:db8:ac10:fe01::1" prefix="64">
|
||||
</ip>
|
||||
</network>
|
10
tests/networkxml2xmlout/nat-network-forward-nat-ipv6.xml
Normal file
10
tests/networkxml2xmlout/nat-network-forward-nat-ipv6.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<network>
|
||||
<name>default</name>
|
||||
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||
<forward mode='nat'>
|
||||
<nat ipv6='yes'/>
|
||||
</forward>
|
||||
<bridge name='virbr0' stp='on' delay='0'/>
|
||||
<ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'>
|
||||
</ip>
|
||||
</network>
|
@ -140,6 +140,7 @@ mymain(void)
|
||||
DO_TEST("nat-network-dns-forward-plain");
|
||||
DO_TEST("nat-network-dns-forwarders");
|
||||
DO_TEST("nat-network-dns-forwarder-no-resolv");
|
||||
DO_TEST("nat-network-forward-nat-ipv6");
|
||||
DO_TEST("nat-network-forward-nat-address");
|
||||
DO_TEST("nat-network-forward-nat-no-address");
|
||||
DO_TEST("nat-network-mtu");
|
||||
|
Loading…
Reference in New Issue
Block a user