Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fbdb3c3

Browse files
committed
Vendoring libnetwork v0.7.0-dev.10
Signed-off-by: Alessandro Boch <[email protected]>
1 parent 53d2e5e commit fbdb3c3

6 files changed

Lines changed: 155 additions & 66 deletions

File tree

hack/vendor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
2929
clone git github.com/imdario/mergo 0.2.1
3030

3131
#get libnetwork packages
32-
clone git github.com/docker/libnetwork v0.7.0-dev.9
32+
clone git github.com/docker/libnetwork v0.7.0-dev.10
3333
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
3434
clone git github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b
3535
clone git github.com/hashicorp/memberlist 9a1e242e454d2443df330bdd51a436d5a9058fc4

integration-cli/docker_cli_network_unix_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,10 +1144,10 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectToStoppedContaine
11441144

11451145
func (s *DockerNetworkSuite) TestDockerNetworkConnectPreferredIP(c *check.C) {
11461146
// create two networks
1147-
dockerCmd(c, "network", "create", "--subnet=172.28.0.0/16", "--subnet=2001:db8:1234::/64", "n0")
1147+
dockerCmd(c, "network", "create", "--ipv6", "--subnet=172.28.0.0/16", "--subnet=2001:db8:1234::/64", "n0")
11481148
assertNwIsAvailable(c, "n0")
11491149

1150-
dockerCmd(c, "network", "create", "--subnet=172.30.0.0/16", "--ip-range=172.30.5.0/24", "--subnet=2001:db8:abcd::/64", "--ip-range=2001:db8:abcd::/80", "n1")
1150+
dockerCmd(c, "network", "create", "--ipv6", "--subnet=172.30.0.0/16", "--ip-range=172.30.5.0/24", "--subnet=2001:db8:abcd::/64", "--ip-range=2001:db8:abcd::/80", "n1")
11511151
assertNwIsAvailable(c, "n1")
11521152

11531153
// run a container on first network specifying the ip addresses
@@ -1183,7 +1183,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectPreferredIPStoppedContainer
11831183
dockerCmd(c, "create", "--name", "c0", "busybox", "top")
11841184

11851185
// create a network
1186-
dockerCmd(c, "network", "create", "--subnet=172.30.0.0/16", "--subnet=2001:db8:abcd::/64", "n0")
1186+
dockerCmd(c, "network", "create", "--ipv6", "--subnet=172.30.0.0/16", "--subnet=2001:db8:abcd::/64", "n0")
11871187
assertNwIsAvailable(c, "n0")
11881188

11891189
// connect the container to the network specifying an ip addresses

vendor/src/github.com/docker/libnetwork/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.7.0-dev.10 (2016-03-21)
4+
- Add IPv6 service discovery (AAAA records) in embedded DNS server
5+
- Honor enableIPv6 flag in network create for the IP allocation
6+
- Avoid V6 queries in docker domain going to external nameservers
7+
38
## 0.7.0-dev.9 (2016-03-18)
49
- Support labels on networks
510

vendor/src/github.com/docker/libnetwork/network.go

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ type NetworkInfo interface {
7171
type EndpointWalker func(ep Endpoint) bool
7272

7373
type svcInfo struct {
74-
svcMap map[string][]net.IP
75-
ipMap map[string]string
74+
svcMap map[string][]net.IP
75+
svcIPv6Map map[string][]net.IP
76+
ipMap map[string]string
7677
}
7778

7879
// IpamConf contains all the ipam related configurations for a network
@@ -489,6 +490,10 @@ func (n *network) UnmarshalJSON(b []byte) (err error) {
489490
if v, ok := netMap["inDelete"]; ok {
490491
n.inDelete = v.(bool)
491492
}
493+
// Reconcile old networks with the recently added `--ipv6` flag
494+
if !n.enableIPv6 {
495+
n.enableIPv6 = len(n.ipamV6Info) > 0
496+
}
492497
return nil
493498
}
494499

@@ -779,7 +784,7 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
779784
ep.ipamOptions[netlabel.MacAddress] = ep.iface.mac.String()
780785
}
781786

782-
if err = ep.assignAddress(ipam.driver, true, !n.postIPv6); err != nil {
787+
if err = ep.assignAddress(ipam.driver, true, n.enableIPv6 && !n.postIPv6); err != nil {
783788
return nil, err
784789
}
785790
defer func() {
@@ -799,7 +804,7 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
799804
}
800805
}()
801806

802-
if err = ep.assignAddress(ipam.driver, false, n.postIPv6); err != nil {
807+
if err = ep.assignAddress(ipam.driver, false, n.enableIPv6 && n.postIPv6); err != nil {
803808
return nil, err
804809
}
805810

@@ -890,68 +895,103 @@ func (n *network) EndpointByID(id string) (Endpoint, error) {
890895
}
891896

892897
func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool) {
898+
var ipv6 net.IP
893899
epName := ep.Name()
894900
if iface := ep.Iface(); iface.Address() != nil {
895901
myAliases := ep.MyAliases()
902+
if iface.AddressIPv6() != nil {
903+
ipv6 = iface.AddressIPv6().IP
904+
}
905+
896906
if isAdd {
897907
// If anonymous endpoint has an alias use the first alias
898908
// for ip->name mapping. Not having the reverse mapping
899909
// breaks some apps
900910
if ep.isAnonymous() {
901911
if len(myAliases) > 0 {
902-
n.addSvcRecords(myAliases[0], iface.Address().IP, true)
912+
n.addSvcRecords(myAliases[0], iface.Address().IP, ipv6, true)
903913
}
904914
} else {
905-
n.addSvcRecords(epName, iface.Address().IP, true)
915+
n.addSvcRecords(epName, iface.Address().IP, ipv6, true)
906916
}
907917
for _, alias := range myAliases {
908-
n.addSvcRecords(alias, iface.Address().IP, false)
918+
n.addSvcRecords(alias, iface.Address().IP, ipv6, false)
909919
}
910920
} else {
911921
if ep.isAnonymous() {
912922
if len(myAliases) > 0 {
913-
n.deleteSvcRecords(myAliases[0], iface.Address().IP, true)
923+
n.deleteSvcRecords(myAliases[0], iface.Address().IP, ipv6, true)
914924
}
915925
} else {
916-
n.deleteSvcRecords(epName, iface.Address().IP, true)
926+
n.deleteSvcRecords(epName, iface.Address().IP, ipv6, true)
917927
}
918928
for _, alias := range myAliases {
919-
n.deleteSvcRecords(alias, iface.Address().IP, false)
929+
n.deleteSvcRecords(alias, iface.Address().IP, ipv6, false)
920930
}
921931
}
922932
}
923933
}
924934

925-
func (n *network) addSvcRecords(name string, epIP net.IP, ipMapUpdate bool) {
935+
func addIPToName(ipMap map[string]string, name string, ip net.IP) {
936+
reverseIP := netutils.ReverseIP(ip.String())
937+
if _, ok := ipMap[reverseIP]; !ok {
938+
ipMap[reverseIP] = name
939+
}
940+
}
941+
942+
func addNameToIP(svcMap map[string][]net.IP, name string, epIP net.IP) {
943+
ipList := svcMap[name]
944+
for _, ip := range ipList {
945+
if ip.Equal(epIP) {
946+
return
947+
}
948+
}
949+
svcMap[name] = append(svcMap[name], epIP)
950+
}
951+
952+
func delNameToIP(svcMap map[string][]net.IP, name string, epIP net.IP) {
953+
ipList := svcMap[name]
954+
for i, ip := range ipList {
955+
if ip.Equal(epIP) {
956+
ipList = append(ipList[:i], ipList[i+1:]...)
957+
break
958+
}
959+
}
960+
svcMap[name] = ipList
961+
962+
if len(ipList) == 0 {
963+
delete(svcMap, name)
964+
}
965+
}
966+
967+
func (n *network) addSvcRecords(name string, epIP net.IP, epIPv6 net.IP, ipMapUpdate bool) {
926968
c := n.getController()
927969
c.Lock()
928970
defer c.Unlock()
929971
sr, ok := c.svcDb[n.ID()]
930972
if !ok {
931973
sr = svcInfo{
932-
svcMap: make(map[string][]net.IP),
933-
ipMap: make(map[string]string),
974+
svcMap: make(map[string][]net.IP),
975+
svcIPv6Map: make(map[string][]net.IP),
976+
ipMap: make(map[string]string),
934977
}
935978
c.svcDb[n.ID()] = sr
936979
}
937980

938981
if ipMapUpdate {
939-
reverseIP := netutils.ReverseIP(epIP.String())
940-
if _, ok := sr.ipMap[reverseIP]; !ok {
941-
sr.ipMap[reverseIP] = name
982+
addIPToName(sr.ipMap, name, epIP)
983+
if epIPv6 != nil {
984+
addIPToName(sr.ipMap, name, epIPv6)
942985
}
943986
}
944987

945-
ipList := sr.svcMap[name]
946-
for _, ip := range ipList {
947-
if ip.Equal(epIP) {
948-
return
949-
}
988+
addNameToIP(sr.svcMap, name, epIP)
989+
if epIPv6 != nil {
990+
addNameToIP(sr.svcIPv6Map, name, epIPv6)
950991
}
951-
sr.svcMap[name] = append(sr.svcMap[name], epIP)
952992
}
953993

954-
func (n *network) deleteSvcRecords(name string, epIP net.IP, ipMapUpdate bool) {
994+
func (n *network) deleteSvcRecords(name string, epIP net.IP, epIPv6 net.IP, ipMapUpdate bool) {
955995
c := n.getController()
956996
c.Lock()
957997
defer c.Unlock()
@@ -962,19 +1002,16 @@ func (n *network) deleteSvcRecords(name string, epIP net.IP, ipMapUpdate bool) {
9621002

9631003
if ipMapUpdate {
9641004
delete(sr.ipMap, netutils.ReverseIP(epIP.String()))
965-
}
9661005

967-
ipList := sr.svcMap[name]
968-
for i, ip := range ipList {
969-
if ip.Equal(epIP) {
970-
ipList = append(ipList[:i], ipList[i+1:]...)
971-
break
1006+
if epIPv6 != nil {
1007+
delete(sr.ipMap, netutils.ReverseIP(epIPv6.String()))
9721008
}
9731009
}
974-
sr.svcMap[name] = ipList
9751010

976-
if len(ipList) == 0 {
977-
delete(sr.svcMap, name)
1011+
delNameToIP(sr.svcMap, name, epIP)
1012+
1013+
if epIPv6 != nil {
1014+
delNameToIP(sr.svcIPv6Map, name, epIPv6)
9781015
}
9791016
}
9801017

@@ -1033,6 +1070,10 @@ func (n *network) ipamAllocate() error {
10331070
}
10341071
}()
10351072

1073+
if !n.enableIPv6 {
1074+
return nil
1075+
}
1076+
10361077
return n.ipamAllocateVersion(6, ipam)
10371078
}
10381079

@@ -1153,7 +1194,7 @@ func (n *network) ipamReleaseVersion(ipVer int, ipam ipamapi.Ipam) {
11531194
return
11541195
}
11551196

1156-
if *infoList == nil {
1197+
if len(*infoList) == 0 {
11571198
return
11581199
}
11591200

vendor/src/github.com/docker/libnetwork/resolver.go

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
log "github.com/Sirupsen/logrus"
1212
"github.com/docker/libnetwork/iptables"
13+
"github.com/docker/libnetwork/netutils"
1314
"github.com/miekg/dns"
1415
)
1516

@@ -185,27 +186,46 @@ func shuffleAddr(addr []net.IP) []net.IP {
185186
return addr
186187
}
187188

188-
func (r *resolver) handleIPv4Query(name string, query *dns.Msg) (*dns.Msg, error) {
189-
addr := r.sb.ResolveName(name)
189+
func createRespMsg(query *dns.Msg) *dns.Msg {
190+
resp := new(dns.Msg)
191+
resp.SetReply(query)
192+
setCommonFlags(resp)
193+
194+
return resp
195+
}
196+
197+
func (r *resolver) handleIPQuery(name string, query *dns.Msg, ipType int) (*dns.Msg, error) {
198+
addr, ipv6Miss := r.sb.ResolveName(name, ipType)
199+
if addr == nil && ipv6Miss {
200+
// Send a reply without any Answer sections
201+
log.Debugf("Lookup name %s present without IPv6 address", name)
202+
resp := createRespMsg(query)
203+
return resp, nil
204+
}
190205
if addr == nil {
191206
return nil, nil
192207
}
193208

194209
log.Debugf("Lookup for %s: IP %v", name, addr)
195210

196-
resp := new(dns.Msg)
197-
resp.SetReply(query)
198-
setCommonFlags(resp)
199-
211+
resp := createRespMsg(query)
200212
if len(addr) > 1 {
201213
addr = shuffleAddr(addr)
202214
}
203-
204-
for _, ip := range addr {
205-
rr := new(dns.A)
206-
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
207-
rr.A = ip
208-
resp.Answer = append(resp.Answer, rr)
215+
if ipType == netutils.IPv4 {
216+
for _, ip := range addr {
217+
rr := new(dns.A)
218+
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
219+
rr.A = ip
220+
resp.Answer = append(resp.Answer, rr)
221+
}
222+
} else {
223+
for _, ip := range addr {
224+
rr := new(dns.AAAA)
225+
rr.Hdr = dns.RR_Header{Name: name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: respTTL}
226+
rr.AAAA = ip
227+
resp.Answer = append(resp.Answer, rr)
228+
}
209229
}
210230
return resp, nil
211231
}
@@ -264,7 +284,9 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
264284
}
265285
name := query.Question[0].Name
266286
if query.Question[0].Qtype == dns.TypeA {
267-
resp, err = r.handleIPv4Query(name, query)
287+
resp, err = r.handleIPQuery(name, query, netutils.IPv4)
288+
} else if query.Question[0].Qtype == dns.TypeAAAA {
289+
resp, err = r.handleIPQuery(name, query, netutils.IPv6)
268290
} else if query.Question[0].Qtype == dns.TypePTR {
269291
resp, err = r.handlePTRQuery(name, query)
270292
}

0 commit comments

Comments
 (0)