Skip to content

Commit ffb643b

Browse files
authored
Support specifying "open" forward mode (#900)
"The new forward mode 'open' is just like mode='route', except that no firewall rules are added to assure that any traffic does or doesn't pass. It is assumed that either they aren't necessary, or they will be setup outside the scope of libvirt."[1] [1] libvirt/libvirt@25e8112
1 parent bdcb2aa commit ffb643b

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

libvirt/network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func getIPsFromResource(d *schema.ResourceData) ([]libvirtxml.NetworkIP, error)
5555
// check if DHCP must be enabled by default
5656
var dhcpEnabled bool
5757
netMode := getNetModeFromResource(d)
58-
if netMode == netModeIsolated || netMode == netModeNat || netMode == netModeRoute {
58+
if netMode == netModeIsolated || netMode == netModeNat || netMode == netModeRoute || netMode == netModeOpen {
5959
dhcpEnabled = true
6060
}
6161

libvirt/network_def.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// HasDHCP checks if the network has a DHCP server managed by libvirt
1414
func HasDHCP(net libvirtxml.Network) bool {
1515
if net.Forward != nil {
16-
if net.Forward.Mode == "nat" || net.Forward.Mode == "route" || net.Forward.Mode == "" {
16+
if net.Forward.Mode == "nat" || net.Forward.Mode == "route" || net.Forward.Mode == "open" || net.Forward.Mode == "" {
1717
return true
1818
}
1919
} else {

libvirt/network_def_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestHasDHCPForwardSet(t *testing.T) {
114114
}
115115
}
116116

117-
for _, mode := range []string{"nat", "route", ""} {
117+
for _, mode := range []string{"nat", "route", "open", ""} {
118118
net := createNet(mode)
119119
if !HasDHCP(net) {
120120
t.Errorf(

libvirt/resource_libvirt_network.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
netModeIsolated = "none"
1818
netModeNat = "nat"
1919
netModeRoute = "route"
20+
netModeOpen = "open"
2021
netModeBridge = "bridge"
2122
dnsPrefix = "dns.0"
2223
)
@@ -60,7 +61,7 @@ func resourceLibvirtNetwork() *schema.Resource {
6061
// libvirt cannot update it so force new
6162
ForceNew: true,
6263
},
63-
"mode": { // can be "none", "nat" (default), "route", "bridge"
64+
"mode": { // can be "none", "nat" (default), "route", "open", "bridge"
6465
Type: schema.TypeString,
6566
Optional: true,
6667
ForceNew: true,
@@ -377,13 +378,13 @@ func resourceLibvirtNetworkCreate(d *schema.ResourceData, meta interface{}) erro
377378
networkDef.Forward = &libvirtxml.NetworkForward{
378379
Mode: getNetModeFromResource(d),
379380
}
380-
if networkDef.Forward.Mode == netModeIsolated || networkDef.Forward.Mode == netModeNat || networkDef.Forward.Mode == netModeRoute {
381+
if networkDef.Forward.Mode == netModeIsolated || networkDef.Forward.Mode == netModeNat || networkDef.Forward.Mode == netModeRoute || networkDef.Forward.Mode == netModeOpen {
381382

382383
if networkDef.Forward.Mode == netModeIsolated {
383384
// there is no forwarding when using an isolated network
384385
networkDef.Forward = nil
385-
} else if networkDef.Forward.Mode == netModeRoute {
386-
// there is no NAT when using a routed network
386+
} else if networkDef.Forward.Mode == netModeRoute || networkDef.Forward.Mode == netModeOpen {
387+
// there is no NAT when using a routed or open network
387388
networkDef.Forward.NAT = nil
388389
}
389390

website/docs/r/network.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resource "libvirt_network" "kube_network" {
1818
# the name used by libvirt
1919
name = "k8snet"
2020
21-
# mode can be: "nat" (default), "none", "route", "bridge"
21+
# mode can be: "nat" (default), "none", "route", "open", "bridge"
2222
mode = "nat"
2323
2424
# the domain used by the DNS server in this network
@@ -123,14 +123,15 @@ The following arguments are supported:
123123
the virtual network to the LAN **without applying any NAT**. It requires that
124124
the IP address range be pre-configured in the routing tables of the router
125125
on the host network.
126+
- `open`: similar to `route`, but no firewall rules are added.
126127
- `bridge`: use a pre-existing host bridge. The guests will effectively be
127128
directly connected to the physical network (i.e. their IP addresses will
128129
all be on the subnet of the physical network, and there will be no
129130
restrictions on inbound or outbound connections). The `bridge` network
130131
attribute is mandatory in this case.
131132
* `bridge` - (Optional) The bridge device defines the name of a bridge
132133
device which will be used to construct the virtual network (when not provided,
133-
it will be automatically obtained by libvirt in `none`, `nat` and `route` modes).
134+
it will be automatically obtained by libvirt in `none`, `nat`, `route` and `open` modes).
134135
* `mtu` - (Optional) The MTU to set for the underlying network interfaces. When
135136
not supplied, libvirt will use the default for the interface, usually 1500.
136137
Libvirt version 5.1 and greater will advertise this value to nodes via DHCP.

0 commit comments

Comments
 (0)