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