2016-09-19 18:48:06 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package libnetwork
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
2016-10-12 19:55:20 -04:00
|
|
|
"time"
|
2016-09-19 18:48:06 -04:00
|
|
|
|
|
|
|
"github.com/Microsoft/hcsshim"
|
2016-11-01 00:26:14 -04:00
|
|
|
"github.com/Sirupsen/logrus"
|
2016-09-19 18:48:06 -04:00
|
|
|
"github.com/docker/libnetwork/drivers/windows"
|
2016-10-12 19:55:20 -04:00
|
|
|
"github.com/docker/libnetwork/ipamapi"
|
|
|
|
"github.com/docker/libnetwork/ipams/windowsipam"
|
2016-09-19 18:48:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func executeInCompartment(compartmentID uint32, x func()) {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
|
|
|
|
if err := hcsshim.SetCurrentThreadCompartmentId(compartmentID); err != nil {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Error(err)
|
2016-09-19 18:48:06 -04:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
hcsshim.SetCurrentThreadCompartmentId(0)
|
|
|
|
runtime.UnlockOSThread()
|
|
|
|
}()
|
|
|
|
|
|
|
|
x()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *network) startResolver() {
|
|
|
|
n.resolverOnce.Do(func() {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Debugf("Launching DNS server for network", n.Name())
|
2016-09-19 18:48:06 -04:00
|
|
|
options := n.Info().DriverOptions()
|
|
|
|
hnsid := options[windows.HNSID]
|
|
|
|
|
2016-11-01 17:51:41 -04:00
|
|
|
if hnsid == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-09-19 18:48:06 -04:00
|
|
|
hnsresponse, err := hcsshim.HNSNetworkRequest("GET", hnsid, "")
|
|
|
|
if err != nil {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Errorf("Resolver Setup/Start failed for container %s, %q", n.Name(), err)
|
2016-09-19 18:48:06 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, subnet := range hnsresponse.Subnets {
|
|
|
|
if subnet.GatewayAddress != "" {
|
2016-10-12 19:55:20 -04:00
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
resolver := NewResolver(subnet.GatewayAddress, false, "", n)
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Debugf("Binding a resolver on network %s gateway %s", n.Name(), subnet.GatewayAddress)
|
2016-10-12 19:55:20 -04:00
|
|
|
executeInCompartment(hnsresponse.DNSServerCompartment, resolver.SetupFunc(53))
|
|
|
|
|
|
|
|
if err = resolver.Start(); err != nil {
|
2016-11-01 00:26:14 -04:00
|
|
|
logrus.Errorf("Resolver Setup/Start failed for container %s, %q", n.Name(), err)
|
2016-10-12 19:55:20 -04:00
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
} else {
|
2016-11-28 13:44:45 -05:00
|
|
|
logrus.Debugf("Resolver bound successfully for network %s", n.Name())
|
2016-10-12 19:55:20 -04:00
|
|
|
n.resolver = append(n.resolver, resolver)
|
|
|
|
break
|
|
|
|
}
|
2016-09-19 18:48:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2016-10-12 19:55:20 -04:00
|
|
|
|
|
|
|
func defaultIpamForNetworkType(networkType string) string {
|
|
|
|
if windows.IsBuiltinLocalDriver(networkType) {
|
|
|
|
return windowsipam.DefaultIPAM
|
|
|
|
}
|
|
|
|
return ipamapi.DefaultIPAM
|
|
|
|
}
|