|
@@ -6,7 +6,11 @@ import (
|
|
"net"
|
|
"net"
|
|
|
|
|
|
"github.com/Microsoft/hcsshim"
|
|
"github.com/Microsoft/hcsshim"
|
|
|
|
+ "github.com/docker/docker/pkg/system"
|
|
"github.com/docker/libnetwork/driverapi"
|
|
"github.com/docker/libnetwork/driverapi"
|
|
|
|
+ "github.com/docker/libnetwork/drivers/windows"
|
|
|
|
+ "github.com/docker/libnetwork/netlabel"
|
|
|
|
+ "github.com/docker/libnetwork/types"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -15,12 +19,14 @@ type endpointTable map[string]*endpoint
|
|
const overlayEndpointPrefix = "overlay/endpoint"
|
|
const overlayEndpointPrefix = "overlay/endpoint"
|
|
|
|
|
|
type endpoint struct {
|
|
type endpoint struct {
|
|
- id string
|
|
|
|
- nid string
|
|
|
|
- profileId string
|
|
|
|
- remote bool
|
|
|
|
- mac net.HardwareAddr
|
|
|
|
- addr *net.IPNet
|
|
|
|
|
|
+ id string
|
|
|
|
+ nid string
|
|
|
|
+ profileID string
|
|
|
|
+ remote bool
|
|
|
|
+ mac net.HardwareAddr
|
|
|
|
+ addr *net.IPNet
|
|
|
|
+ disablegateway bool
|
|
|
|
+ portMapping []types.PortBinding // Operation port bindings
|
|
}
|
|
}
|
|
|
|
|
|
func validateID(nid, eid string) error {
|
|
func validateID(nid, eid string) error {
|
|
@@ -71,7 +77,7 @@ func (n *network) removeEndpointWithAddress(addr *net.IPNet) {
|
|
|
|
|
|
if networkEndpoint != nil {
|
|
if networkEndpoint != nil {
|
|
logrus.Debugf("Removing stale endpoint from HNS")
|
|
logrus.Debugf("Removing stale endpoint from HNS")
|
|
- _, err := hcsshim.HNSEndpointRequest("DELETE", networkEndpoint.profileId, "")
|
|
|
|
|
|
+ _, err := hcsshim.HNSEndpointRequest("DELETE", networkEndpoint.profileID, "")
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
logrus.Debugf("Failed to delete stale overlay endpoint (%s) from hns", networkEndpoint.id[0:7])
|
|
logrus.Debugf("Failed to delete stale overlay endpoint (%s) from hns", networkEndpoint.id[0:7])
|
|
@@ -96,7 +102,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
|
|
logrus.Debugf("Deleting stale endpoint %s", eid)
|
|
logrus.Debugf("Deleting stale endpoint %s", eid)
|
|
n.deleteEndpoint(eid)
|
|
n.deleteEndpoint(eid)
|
|
|
|
|
|
- _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileId, "")
|
|
|
|
|
|
+ _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileID, "")
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -113,17 +119,19 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
|
|
return fmt.Errorf("create endpoint was not passed interface IP address")
|
|
return fmt.Errorf("create endpoint was not passed interface IP address")
|
|
}
|
|
}
|
|
|
|
|
|
- if s := n.getSubnetforIP(ep.addr); s == nil {
|
|
|
|
- return fmt.Errorf("no matching subnet for IP %q in network %q\n", ep.addr, nid)
|
|
|
|
|
|
+ s := n.getSubnetforIP(ep.addr)
|
|
|
|
+ if s == nil {
|
|
|
|
+ return fmt.Errorf("no matching subnet for IP %q in network %q", ep.addr, nid)
|
|
}
|
|
}
|
|
|
|
|
|
// Todo: Add port bindings and qos policies here
|
|
// Todo: Add port bindings and qos policies here
|
|
|
|
|
|
hnsEndpoint := &hcsshim.HNSEndpoint{
|
|
hnsEndpoint := &hcsshim.HNSEndpoint{
|
|
Name: eid,
|
|
Name: eid,
|
|
- VirtualNetwork: n.hnsId,
|
|
|
|
|
|
+ VirtualNetwork: n.hnsID,
|
|
IPAddress: ep.addr.IP,
|
|
IPAddress: ep.addr.IP,
|
|
EnableInternalDNS: true,
|
|
EnableInternalDNS: true,
|
|
|
|
+ GatewayAddress: s.gwIP.String(),
|
|
}
|
|
}
|
|
|
|
|
|
if ep.mac != nil {
|
|
if ep.mac != nil {
|
|
@@ -141,6 +149,31 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
|
|
|
|
|
|
hnsEndpoint.Policies = append(hnsEndpoint.Policies, paPolicy)
|
|
hnsEndpoint.Policies = append(hnsEndpoint.Policies, paPolicy)
|
|
|
|
|
|
|
|
+ if system.GetOSVersion().Build > 16236 {
|
|
|
|
+ natPolicy, err := json.Marshal(hcsshim.PaPolicy{
|
|
|
|
+ Type: "OutBoundNAT",
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ hnsEndpoint.Policies = append(hnsEndpoint.Policies, natPolicy)
|
|
|
|
+
|
|
|
|
+ epConnectivity, err := windows.ParseEndpointConnectivity(epOptions)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pbPolicy, err := windows.ConvertPortBindings(epConnectivity.PortBindings)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ hnsEndpoint.Policies = append(hnsEndpoint.Policies, pbPolicy...)
|
|
|
|
+
|
|
|
|
+ ep.disablegateway = true
|
|
|
|
+ }
|
|
|
|
+
|
|
configurationb, err := json.Marshal(hnsEndpoint)
|
|
configurationb, err := json.Marshal(hnsEndpoint)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -151,7 +184,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- ep.profileId = hnsresponse.Id
|
|
|
|
|
|
+ ep.profileID = hnsresponse.Id
|
|
|
|
|
|
if ep.mac == nil {
|
|
if ep.mac == nil {
|
|
ep.mac, err = net.ParseMAC(hnsresponse.MacAddress)
|
|
ep.mac, err = net.ParseMAC(hnsresponse.MacAddress)
|
|
@@ -164,6 +197,12 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ ep.portMapping, err = windows.ParsePortBindingPolicies(hnsresponse.Policies)
|
|
|
|
+ if err != nil {
|
|
|
|
+ hcsshim.HNSEndpointRequest("DELETE", hnsresponse.Id, "")
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
n.addEndpoint(ep)
|
|
n.addEndpoint(ep)
|
|
|
|
|
|
return nil
|
|
return nil
|
|
@@ -186,7 +225,7 @@ func (d *driver) DeleteEndpoint(nid, eid string) error {
|
|
|
|
|
|
n.deleteEndpoint(eid)
|
|
n.deleteEndpoint(eid)
|
|
|
|
|
|
- _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileId, "")
|
|
|
|
|
|
+ _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileID, "")
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -210,7 +249,17 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro
|
|
}
|
|
}
|
|
|
|
|
|
data := make(map[string]interface{}, 1)
|
|
data := make(map[string]interface{}, 1)
|
|
- data["hnsid"] = ep.profileId
|
|
|
|
|
|
+ data["hnsid"] = ep.profileID
|
|
data["AllowUnqualifiedDNSQuery"] = true
|
|
data["AllowUnqualifiedDNSQuery"] = true
|
|
|
|
+
|
|
|
|
+ if ep.portMapping != nil {
|
|
|
|
+ // Return a copy of the operational data
|
|
|
|
+ pmc := make([]types.PortBinding, 0, len(ep.portMapping))
|
|
|
|
+ for _, pm := range ep.portMapping {
|
|
|
|
+ pmc = append(pmc, pm.GetCopy())
|
|
|
|
+ }
|
|
|
|
+ data[netlabel.PortMap] = pmc
|
|
|
|
+ }
|
|
|
|
+
|
|
return data, nil
|
|
return data, nil
|
|
}
|
|
}
|