Browse code

Vendoring libnetwork @e8431956

Signed-off-by: Santhosh Manohar <santhosh@docker.com>

Santhosh Manohar authored on 2017/01/27 11:08:18
Showing 6 changed files
... ...
@@ -22,7 +22,7 @@ github.com/RackSec/srslog 456df3a81436d29ba874f3590eeeee25d666f8a5
22 22
 github.com/imdario/mergo 0.2.1
23 23
 
24 24
 #get libnetwork packages
25
-github.com/docker/libnetwork e8431956af5df6816e232d68376c012c2617edbd
25
+github.com/docker/libnetwork ca62711acec77034e0a670188628e26025e1482d
26 26
 github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894
27 27
 github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
28 28
 github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
... ...
@@ -178,7 +178,14 @@ func GetNameservers(resolvConf []byte, kind int) []string {
178 178
 func GetNameserversAsCIDR(resolvConf []byte) []string {
179 179
 	nameservers := []string{}
180 180
 	for _, nameserver := range GetNameservers(resolvConf, types.IP) {
181
-		nameservers = append(nameservers, nameserver+"/32")
181
+		var address string
182
+		// If IPv6, strip zone if present
183
+		if strings.Contains(nameserver, ":") {
184
+			address = strings.Split(nameserver, "%")[0] + "/128"
185
+		} else {
186
+			address = nameserver + "/32"
187
+		}
188
+		nameservers = append(nameservers, address)
182 189
 	}
183 190
 	return nameservers
184 191
 }
... ...
@@ -72,8 +72,8 @@ const (
72 72
 )
73 73
 
74 74
 type extDNSEntry struct {
75
-	ipStr        string
76
-	hostLoopback bool
75
+	IPStr        string
76
+	HostLoopback bool
77 77
 }
78 78
 
79 79
 // resolver implements the Resolver interface
... ...
@@ -413,15 +413,15 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
413 413
 	} else {
414 414
 		for i := 0; i < maxExtDNS; i++ {
415 415
 			extDNS := &r.extDNSList[i]
416
-			if extDNS.ipStr == "" {
416
+			if extDNS.IPStr == "" {
417 417
 				break
418 418
 			}
419 419
 			extConnect := func() {
420
-				addr := fmt.Sprintf("%s:%d", extDNS.ipStr, 53)
420
+				addr := fmt.Sprintf("%s:%d", extDNS.IPStr, 53)
421 421
 				extConn, err = net.DialTimeout(proto, addr, extIOTimeout)
422 422
 			}
423 423
 
424
-			if extDNS.hostLoopback {
424
+			if extDNS.HostLoopback {
425 425
 				extConnect()
426 426
 			} else {
427 427
 				execErr := r.backend.ExecFunc(extConnect)
... ...
@@ -435,7 +435,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
435 435
 				continue
436 436
 			}
437 437
 			logrus.Debugf("Query %s[%d] from %s, forwarding to %s:%s", name, query.Question[0].Qtype,
438
-				extConn.LocalAddr().String(), proto, extDNS.ipStr)
438
+				extConn.LocalAddr().String(), proto, extDNS.IPStr)
439 439
 
440 440
 			// Timeout has to be set for every IO operation.
441 441
 			extConn.SetDeadline(time.Now().Add(extIOTimeout))
... ...
@@ -174,8 +174,8 @@ func (sb *sandbox) setExternalResolvers(content []byte, addrType int, checkLoopb
174 174
 			hostLoopback = dns.IsIPv4Localhost(ip)
175 175
 		}
176 176
 		sb.extDNS = append(sb.extDNS, extDNSEntry{
177
-			ipStr:        ip,
178
-			hostLoopback: hostLoopback,
177
+			IPStr:        ip,
178
+			HostLoopback: hostLoopback,
179 179
 		})
180 180
 	}
181 181
 }
... ...
@@ -27,7 +27,12 @@ type sbState struct {
27 27
 	dbExists   bool
28 28
 	Eps        []epState
29 29
 	EpPriority map[string]int
30
-	ExtDNS     []extDNSEntry
30
+	// external servers have to be persisted so that on restart of a live-restore
31
+	// enabled daemon we get the external servers for the running containers.
32
+	// We have two versions of ExtDNS to support upgrade & downgrade of the daemon
33
+	// between >=1.14 and <1.14 versions.
34
+	ExtDNS  []string
35
+	ExtDNS2 []extDNSEntry
31 36
 }
32 37
 
33 38
 func (sbs *sbState) Key() []string {
... ...
@@ -114,8 +119,16 @@ func (sbs *sbState) CopyTo(o datastore.KVObject) error {
114 114
 		dstSbs.Eps = append(dstSbs.Eps, eps)
115 115
 	}
116 116
 
117
+	if len(sbs.ExtDNS2) > 0 {
118
+		for _, dns := range sbs.ExtDNS2 {
119
+			dstSbs.ExtDNS2 = append(dstSbs.ExtDNS2, dns)
120
+			dstSbs.ExtDNS = append(dstSbs.ExtDNS, dns.IPStr)
121
+		}
122
+		return nil
123
+	}
117 124
 	for _, dns := range sbs.ExtDNS {
118 125
 		dstSbs.ExtDNS = append(dstSbs.ExtDNS, dns)
126
+		dstSbs.ExtDNS2 = append(dstSbs.ExtDNS2, extDNSEntry{IPStr: dns})
119 127
 	}
120 128
 
121 129
 	return nil
... ...
@@ -131,7 +144,11 @@ func (sb *sandbox) storeUpdate() error {
131 131
 		ID:         sb.id,
132 132
 		Cid:        sb.containerID,
133 133
 		EpPriority: sb.epPriority,
134
-		ExtDNS:     sb.extDNS,
134
+		ExtDNS2:    sb.extDNS,
135
+	}
136
+
137
+	for _, ext := range sb.extDNS {
138
+		sbs.ExtDNS = append(sbs.ExtDNS, ext.IPStr)
135 139
 	}
136 140
 
137 141
 retry:
... ...
@@ -205,7 +222,15 @@ func (c *controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
205 205
 			dbIndex:            sbs.dbIndex,
206 206
 			isStub:             true,
207 207
 			dbExists:           true,
208
-			extDNS:             sbs.ExtDNS,
208
+		}
209
+		// If we are restoring from a older version extDNSEntry won't have the
210
+		// HostLoopback field
211
+		if len(sbs.ExtDNS2) > 0 {
212
+			sb.extDNS = sbs.ExtDNS2
213
+		} else {
214
+			for _, dns := range sbs.ExtDNS {
215
+				sb.extDNS = append(sb.extDNS, extDNSEntry{IPStr: dns})
216
+			}
209 217
 		}
210 218
 
211 219
 		msg := " for cleanup"
... ...
@@ -247,7 +247,7 @@ func (sb *sandbox) rmLBBackend(ip, vip net.IP, fwMark uint32, ingressPorts []*Po
247 247
 	if rmService {
248 248
 		s.SchedName = ipvs.RoundRobin
249 249
 		if err := i.DelService(s); err != nil {
250
-			logrus.Errorf("Failed to delete a new service for vip %s fwmark %d: %v", vip, fwMark, err)
250
+			logrus.Errorf("Failed to delete service for vip %s fwmark %d: %v", vip, fwMark, err)
251 251
 		}
252 252
 
253 253
 		var filteredPorts []*PortConfig
... ...
@@ -259,7 +259,7 @@ func (sb *sandbox) rmLBBackend(ip, vip net.IP, fwMark uint32, ingressPorts []*Po
259 259
 		}
260 260
 
261 261
 		if err := invokeFWMarker(sb.Key(), vip, fwMark, ingressPorts, eIP, true); err != nil {
262
-			logrus.Errorf("Failed to add firewall mark rule in sbox %s: %v", sb.Key(), err)
262
+			logrus.Errorf("Failed to delete firewall mark rule in sbox %s: %v", sb.Key(), err)
263 263
 		}
264 264
 	}
265 265
 }