mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Embedded DNS server should resolve only in docker network domain
Signed-off-by: Santhosh Manohar <santhosh@docker.com>
This commit is contained in:
parent
4e25ffc8d9
commit
411bc69949
1 changed files with 41 additions and 13 deletions
|
@ -431,23 +431,51 @@ func (sb *sandbox) ResolveIP(ip string) string {
|
||||||
|
|
||||||
func (sb *sandbox) ResolveName(name string) net.IP {
|
func (sb *sandbox) ResolveName(name string) net.IP {
|
||||||
var ip net.IP
|
var ip net.IP
|
||||||
parts := strings.Split(name, ".")
|
|
||||||
log.Debugf("To resolve %v", parts)
|
|
||||||
|
|
||||||
reqName := parts[0]
|
// Embedded server owns the docker network domain. Resolution should work
|
||||||
networkName := ""
|
// for both container_name and container_name.network_name
|
||||||
if len(parts) > 1 {
|
// We allow '.' in service name and network name. For a name a.b.c.d the
|
||||||
networkName = parts[1]
|
// following have to tried;
|
||||||
|
// {a.b.c.d in the networks container is connected to}
|
||||||
|
// {a.b.c in network d},
|
||||||
|
// {a.b in network c.d},
|
||||||
|
// {a in network b.c.d},
|
||||||
|
|
||||||
|
name = strings.TrimSuffix(name, ".")
|
||||||
|
reqName := []string{name}
|
||||||
|
networkName := []string{""}
|
||||||
|
|
||||||
|
if strings.Contains(name, ".") {
|
||||||
|
var i int
|
||||||
|
dup := name
|
||||||
|
for {
|
||||||
|
if i = strings.LastIndex(dup, "."); i == -1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
networkName = append(networkName, name[i+1:])
|
||||||
|
reqName = append(reqName, name[:i])
|
||||||
|
|
||||||
|
dup = dup[:i]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
epList := sb.getConnectedEndpoints()
|
epList := sb.getConnectedEndpoints()
|
||||||
// First check for local container alias
|
for i := 0; i < len(reqName); i++ {
|
||||||
ip = sb.resolveName(reqName, networkName, epList, true)
|
log.Debugf("To resolve: %v in %v", reqName[i], networkName[i])
|
||||||
if ip != nil {
|
|
||||||
return ip
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve the actual container name
|
// First check for local container alias
|
||||||
return sb.resolveName(reqName, networkName, epList, false)
|
ip = sb.resolveName(reqName[i], networkName[i], epList, true)
|
||||||
|
if ip != nil {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve the actual container name
|
||||||
|
ip = sb.resolveName(reqName[i], networkName[i], epList, false)
|
||||||
|
if ip != nil {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sb *sandbox) resolveName(req string, networkName string, epList []*endpoint, alias bool) net.IP {
|
func (sb *sandbox) resolveName(req string, networkName string, epList []*endpoint, alias bool) net.IP {
|
||||||
|
|
Loading…
Add table
Reference in a new issue