Merge pull request #269 from tomwilkie/265-docker-bridge

Treat addresses on the docker bridge as local.
This commit is contained in:
Tom Wilkie
2015-06-22 15:55:37 +02:00
7 changed files with 154 additions and 38 deletions

View File

@@ -34,7 +34,7 @@ type LeafMapFunc func(report.NodeMetadata) (RenderableNode, bool)
// The srcNode renderable node is essentially from MapFunc, representing one of
// the rendered nodes this pseudo node refers to. srcNodeID and dstNodeID are
// node IDs prior to mapping.
type PseudoFunc func(srcNodeID string, srcNode RenderableNode, dstNodeID string, local Networks) (RenderableNode, bool)
type PseudoFunc func(srcNodeID string, srcNode RenderableNode, dstNodeID string, local report.Networks) (RenderableNode, bool)
// MapFunc is anything which can take an arbitrary RenderableNode and
// return another RenderableNode.
@@ -266,7 +266,7 @@ func MapAddress2Host(n RenderableNode) (RenderableNode, bool) {
// the report's local networks. Otherwise, the returned function will
// produce a single pseudo node per (dst address, src address, src port).
func GenericPseudoNode(addresser func(id string) net.IP) PseudoFunc {
return func(src string, srcMapped RenderableNode, dst string, local Networks) (RenderableNode, bool) {
return func(src string, srcMapped RenderableNode, dst string, local report.Networks) (RenderableNode, bool) {
// Use the addresser to extract the destination IP
dstNodeAddr := addresser(dst)
@@ -287,7 +287,7 @@ func GenericPseudoNode(addresser func(id string) net.IP) PseudoFunc {
}
// PanicPseudoNode just panics; it is for Topologies without edges
func PanicPseudoNode(src string, srcMapped RenderableNode, dst string, local Networks) (RenderableNode, bool) {
func PanicPseudoNode(src string, srcMapped RenderableNode, dst string, local report.Networks) (RenderableNode, bool) {
panic(dst)
}

View File

@@ -7,16 +7,13 @@ import (
"github.com/weaveworks/scope/report"
)
// Networks represent a set of subnets local to a report.
type Networks []*net.IPNet
// LocalNetworks returns a superset of the networks (think: CIDRs) that are
// "local" from the perspective of each host represented in the report. It's
// used to determine which nodes in the report are "remote", i.e. outside of
// our infrastructure.
func LocalNetworks(r report.Report) Networks {
func LocalNetworks(r report.Report) report.Networks {
var (
result = Networks{}
result = report.Networks{}
networks = map[string]struct{}{}
)
@@ -39,13 +36,3 @@ func LocalNetworks(r report.Report) Networks {
}
return result
}
// Contains returns true if IP is in Networks.
func (n Networks) Contains(ip net.IP) bool {
for _, net := range n {
if net.Contains(ip) {
return true
}
}
return false
}

View File

@@ -16,7 +16,7 @@ func TestReportLocalNetworks(t *testing.T) {
"nonets": {},
"foo": {"local_networks": "10.0.0.1/8 192.168.1.1/24 10.0.0.1/8 badnet/33"},
}}})
want := render.Networks([]*net.IPNet{
want := report.Networks([]*net.IPNet{
mustParseCIDR("10.0.0.1/8"),
mustParseCIDR("192.168.1.1/24"),
})
@@ -26,21 +26,6 @@ func TestReportLocalNetworks(t *testing.T) {
}
}
func TestContains(t *testing.T) {
networks := render.Networks([]*net.IPNet{
mustParseCIDR("10.0.0.1/8"),
mustParseCIDR("192.168.1.1/24"),
})
if networks.Contains(net.ParseIP("52.52.52.52")) {
t.Errorf("52.52.52.52 not in %v", networks)
}
if !networks.Contains(net.ParseIP("10.0.0.1")) {
t.Errorf("10.0.0.1 in %v", networks)
}
}
func mustParseCIDR(s string) *net.IPNet {
_, ipNet, err := net.ParseCIDR(s)
if err != nil {