Skip to content

Commit c592ee4

Browse files
author
Flavio Crisciani
authored
Merge pull request #2070 from nwoodmsft/master
Added OutboundNAT policy support for Windows
2 parents 20dd462 + 6681c02 commit c592ee4

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

drivers/windows/labels.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@ const (
4242

4343
// DisableGatewayDNS label
4444
DisableGatewayDNS = "com.docker.network.windowsshim.disable_gatewaydns"
45+
46+
// EnableOutboundNat label
47+
EnableOutboundNat = "com.docker.network.windowsshim.enable_outboundnat"
48+
49+
// OutboundNatExceptions label
50+
OutboundNatExceptions = "com.docker.network.windowsshim.outboundnat_exceptions"
4551
)

drivers/windows/windows.go

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"sync"
2121

2222
"github.com/Microsoft/hcsshim"
23+
"github.com/docker/docker/pkg/system"
2324
"github.com/docker/libnetwork/datastore"
2425
"github.com/docker/libnetwork/discoverapi"
2526
"github.com/docker/libnetwork/driverapi"
@@ -30,21 +31,23 @@ import (
3031

3132
// networkConfiguration for network specific configuration
3233
type networkConfiguration struct {
33-
ID string
34-
Type string
35-
Name string
36-
HnsID string
37-
RDID string
38-
VLAN uint
39-
VSID uint
40-
DNSServers string
41-
MacPools []hcsshim.MacPool
42-
DNSSuffix string
43-
SourceMac string
44-
NetworkAdapterName string
45-
dbIndex uint64
46-
dbExists bool
47-
DisableGatewayDNS bool
34+
ID string
35+
Type string
36+
Name string
37+
HnsID string
38+
RDID string
39+
VLAN uint
40+
VSID uint
41+
DNSServers string
42+
MacPools []hcsshim.MacPool
43+
DNSSuffix string
44+
SourceMac string
45+
NetworkAdapterName string
46+
dbIndex uint64
47+
dbExists bool
48+
DisableGatewayDNS bool
49+
EnableOutboundNat bool
50+
OutboundNatExceptions []string
4851
}
4952

5053
// endpointConfiguration represents the user specified configuration for the sandbox endpoint
@@ -208,6 +211,18 @@ func (d *driver) parseNetworkOptions(id string, genericOptions map[string]string
208211
return nil, err
209212
}
210213
config.VSID = uint(vsid)
214+
case EnableOutboundNat:
215+
if system.GetOSVersion().Build <= 16236 {
216+
return nil, fmt.Errorf("Invalid network option. OutboundNat is not supported on this OS version")
217+
}
218+
b, err := strconv.ParseBool(value)
219+
if err != nil {
220+
return nil, err
221+
}
222+
config.EnableOutboundNat = b
223+
case OutboundNatExceptions:
224+
s := strings.Split(value, ",")
225+
config.OutboundNatExceptions = s
211226
}
212227
}
213228

@@ -609,6 +624,19 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
609624

610625
endpointStruct.DisableICC = epOption.DisableICC
611626

627+
// Inherit OutboundNat policy from the network
628+
if n.config.EnableOutboundNat {
629+
outboundNatPolicy, err := json.Marshal(hcsshim.OutboundNatPolicy{
630+
Policy: hcsshim.Policy{Type: hcsshim.OutboundNat},
631+
Exceptions: n.config.OutboundNatExceptions,
632+
})
633+
634+
if err != nil {
635+
return err
636+
}
637+
endpointStruct.Policies = append(endpointStruct.Policies, outboundNatPolicy)
638+
}
639+
612640
configurationb, err := json.Marshal(endpointStruct)
613641
if err != nil {
614642
return err

0 commit comments

Comments
 (0)