@@ -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
3233type 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