Merge pull request #915 from michael-berlin/fix_normalize_ip_parsing_for_ipv6_localhost

Fix normalize ip parsing for ipv6 localhost
This commit is contained in:
Michael Berlin 2015-07-23 19:50:48 -07:00
Родитель 5b275832d0 f15649666e
Коммит 189e65c5dc
2 изменённых файлов: 13 добавлений и 7 удалений

Просмотреть файл

@ -5,11 +5,11 @@
package wrangler
import (
"errors"
"fmt"
"strings"
"net"
"sync"
log "github.com/golang/glog"
"github.com/youtube/vitess/go/vt/topo"
"golang.org/x/net/context"
)
@ -33,8 +33,8 @@ func (wr *Wrangler) waitForResults(wg *sync.WaitGroup, results chan error) error
var finalErr error
for err := range results {
finalErr = fmt.Errorf("some validation errors - see log")
log.Errorf("%v", err)
finalErr = errors.New("some validation errors - see log")
wr.Logger().Errorf("%v", err)
}
return finalErr
}
@ -166,7 +166,9 @@ func (wr *Wrangler) validateShard(ctx context.Context, keyspace, shard string, p
func normalizeIP(ip string) string {
// Normalize loopback to avoid spurious validation errors.
if strings.HasPrefix(ip, "127.") {
if parsedIP := net.ParseIP(ip); parsedIP != nil && parsedIP.IsLoopback() {
// Note that this also maps IPv6 localhost to IPv4 localhost
// as GetSlaves() will return only IPv4 addresses.
return "127.0.0.1"
}
return ip
@ -210,7 +212,7 @@ func (wr *Wrangler) validateReplication(ctx context.Context, shardInfo *topo.Sha
}
if !slaveIPMap[normalizeIP(tablet.IPAddr)] {
results <- fmt.Errorf("slave %v not replicating: %v %q", tablet.Alias, tablet.IPAddr, slaveList)
results <- fmt.Errorf("slave %v not replicating: %v slave list: %q", tablet.Alias, tablet.IPAddr, slaveList)
}
}
}
@ -222,7 +224,7 @@ func (wr *Wrangler) pingTablets(ctx context.Context, tabletMap map[topo.TabletAl
defer wg.Done()
if err := wr.tmc.Ping(ctx, tabletInfo); err != nil {
results <- fmt.Errorf("Ping(%v) failed: %v %v", tabletAlias, err, tabletInfo.Hostname)
results <- fmt.Errorf("Ping(%v) failed: %v tablet hostname: %v", tabletAlias, err, tabletInfo.Hostname)
}
}(tabletAlias, tabletInfo)
}

Просмотреть файл

@ -13,6 +13,10 @@ func TestNormalizeIP(t *testing.T) {
"1.2.3.4": "1.2.3.4",
"127.0.0.1": "127.0.0.1",
"127.0.1.1": "127.0.0.1",
// IPv6 must be mapped to IPv4.
"::1": "127.0.0.1",
// An unparseable IP should be returned as is.
"127.": "127.",
}
for input, want := range table {
if got := normalizeIP(input); got != want {