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"
|
2021-04-05 20:24:47 -04:00
|
|
|
"github.com/docker/docker/libnetwork/drivers/windows"
|
|
|
|
"github.com/docker/docker/libnetwork/ipamapi"
|
|
|
|
"github.com/docker/docker/libnetwork/ipams/windowsipam"
|
2017-07-26 17:18:31 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
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() {
|
2017-11-17 16:03:41 -05:00
|
|
|
if n.networkType == "ics" {
|
|
|
|
return
|
|
|
|
}
|
2016-09-19 18:48:06 -04:00
|
|
|
n.resolverOnce.Do(func() {
|
2017-07-17 17:35:16 -04:00
|
|
|
logrus.Debugf("Launching DNS server for network %q", 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
|
|
|
|
}
|