[PATCH go-xml] Add support for NAT in network forward

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add support for NAT in network forward, and add test code.

Signed-off-by: Thomas Hipp <thipp@xxxxxxx>
---
 network.go      | 20 ++++++++++++++++++--
 network_test.go | 31 +++++++++++++++++++++++++------
 2 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/network.go b/network.go
index cc850a1..3635ad2 100644
--- a/network.go
+++ b/network.go
@@ -41,9 +41,25 @@ type NetworkDomain struct {
 	LocalOnly string `xml:"localOnly,attr,omitempty"`
 }
 
+type NetworkForwardNATAddress struct {
+	Start string `xml:"start,attr"`
+	End   string `xml:"end,attr"`
+}
+
+type NetworkForwardNATPort struct {
+	Start uint `xml:"start,attr"`
+	End   uint `xml:"end,attr"`
+}
+
+type NetworkForwardNAT struct {
+	Addresses []NetworkForwardNATAddress `xml:"address"`
+	Ports     []NetworkForwardNATPort    `xml:"port"`
+}
+
 type NetworkForward struct {
-	Mode string `xml:"mode,attr,omitempty"`
-	Dev  string `xml:"dev,attr,omitempty"`
+	Mode string             `xml:"mode,attr,omitempty"`
+	Dev  string             `xml:"dev,attr,omitempty"`
+	NAT  *NetworkForwardNAT `xml:"nat"`
 }
 
 type NetworkMAC struct {
diff --git a/network_test.go b/network_test.go
index 5269398..65f4d53 100644
--- a/network_test.go
+++ b/network_test.go
@@ -67,6 +67,20 @@ var networkTestData = []struct {
 			},
 			Forward: &NetworkForward{
 				Mode: "nat",
+				NAT: &NetworkForwardNAT{
+					Addresses: []NetworkForwardNATAddress{
+						NetworkForwardNATAddress{
+							Start: "1.2.3.4",
+							End:   "1.2.3.10",
+						},
+					},
+					Ports: []NetworkForwardNATPort{
+						NetworkForwardNATPort{
+							Start: 500,
+							End:   1000,
+						},
+					},
+				},
 			},
 			IPs: []NetworkIP{
 				NetworkIP{
@@ -89,9 +103,9 @@ var networkTestData = []struct {
 					},
 				},
 				NetworkIP{
-					Family: "ipv6",
-					Address:"2001:db8:ca2:2::1",
-					Prefix: "64",
+					Family:  "ipv6",
+					Address: "2001:db8:ca2:2::1",
+					Prefix:  "64",
 					DHCP: &NetworkDHCP{
 						Hosts: []NetworkDHCPHost{
 							NetworkDHCPHost{
@@ -99,8 +113,8 @@ var networkTestData = []struct {
 								Name: "paul",
 							},
 							NetworkDHCPHost{
-								ID:  "0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66",
-								IP:  "2001:db8:ca2:2:3::2",
+								ID: "0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66",
+								IP: "2001:db8:ca2:2:3::2",
 							},
 						},
 					},
@@ -111,7 +125,12 @@ var networkTestData = []struct {
 			`<network>`,
 			`  <name>test</name>`,
 			`  <bridge name="virbr0"></bridge>`,
-			`  <forward mode="nat"></forward>`,
+			`  <forward mode="nat">`,
+			`    <nat>`,
+			`      <address start="1.2.3.4" end="1.2.3.10"></address>`,
+			`      <port start="500" end="1000"></port>`,
+			`    </nat>`,
+			`  </forward>`,
 			`  <ip address="192.168.122.1" netmask="255.255.255.0">`,
 			`    <dhcp>`,
 			`      <range start="192.168.122.2" end="192.168.122.254"></range>`,
-- 
2.13.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux