浏览代码

do not ignore user-provided "ndots:0" option

`ndots:0` is a valid DNS option; previously, `ndots:0` was
ignored, leading to the default (`ndots:0`) also being applied;

Before this change:

    docker network create foo
    docker run --rm --network foo --dns-opt ndots:0 alpine cat /etc/resolv.conf
    nameserver 127.0.0.11
    options ndots:0 ndots:0

After this change:

    docker network create foo
    docker run --rm --network foo --dns-opt ndots:0 alpine cat /etc/resolv.conf
    nameserver 127.0.0.11
    options ndots:0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 7 年之前
父节点
当前提交
6e260332e8
共有 2 个文件被更改,包括 17 次插入1 次删除
  1. 1 1
      libnetwork/sandbox_dns_unix.go
  2. 16 0
      libnetwork/service_common_test.go

+ 1 - 1
libnetwork/sandbox_dns_unix.go

@@ -370,7 +370,7 @@ dnsOpt:
 					}
 					}
 					if num, err := strconv.Atoi(parts[1]); err != nil {
 					if num, err := strconv.Atoi(parts[1]); err != nil {
 						return fmt.Errorf("invalid number for ndots option %v", option)
 						return fmt.Errorf("invalid number for ndots option %v", option)
-					} else if num > 0 {
+					} else if num >= 0 {
 						// if the user sets ndots, use the user setting
 						// if the user sets ndots, use the user setting
 						sb.ndotsSet = true
 						sb.ndotsSet = true
 						break dnsOpt
 						break dnsOpt

+ 16 - 0
libnetwork/service_common_test.go

@@ -81,4 +81,20 @@ func TestDNSOptions(t *testing.T) {
 	dnsOptionsList = resolvconf.GetOptions(currRC.Content)
 	dnsOptionsList = resolvconf.GetOptions(currRC.Content)
 	assert.Equal(t, 1, len(dnsOptionsList))
 	assert.Equal(t, 1, len(dnsOptionsList))
 	assert.Equal(t, "ndots:5", dnsOptionsList[0])
 	assert.Equal(t, "ndots:5", dnsOptionsList[0])
+
+	sb2, err := c.(*controller).NewSandbox("cnt2", nil)
+	require.NoError(t, err)
+	defer sb2.Delete()
+	sb2.(*sandbox).startResolver(false)
+
+	sb2.(*sandbox).config.dnsOptionsList = []string{"ndots:0"}
+	err = sb2.(*sandbox).setupDNS()
+	require.NoError(t, err)
+	err = sb2.(*sandbox).rebuildDNS()
+	require.NoError(t, err)
+	currRC, err = resolvconf.GetSpecific(sb2.(*sandbox).config.resolvConfPath)
+	require.NoError(t, err)
+	dnsOptionsList = resolvconf.GetOptions(currRC.Content)
+	assert.Equal(t, 1, len(dnsOptionsList))
+	assert.Equal(t, "ndots:0", dnsOptionsList[0])
 }
 }