mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
probe/endpoint: NATMapper missed an edge case
NATMapper can be created with a nil Conntracker if ConntrackerModulePresent is false, e.g. on Darwin. Check for that in ApplyNAT.
This commit is contained in:
committed by
Tom Wilkie
parent
15371a2bba
commit
32a57e63db
@@ -21,8 +21,8 @@ type NATMapper struct {
|
||||
Conntracker
|
||||
}
|
||||
|
||||
// NewNATMapper is exposed for testing
|
||||
func NewNATMapper(ct Conntracker) NATMapper {
|
||||
// MakeNATMapper is exposed for testing
|
||||
func MakeNATMapper(ct Conntracker) NATMapper {
|
||||
return NATMapper{ct}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,10 @@ func toMapping(f Flow) *endpointMapping {
|
||||
// ApplyNAT duplicates Nodes in the endpoint topology of a
|
||||
// report, based on the NAT table as returns by natTable.
|
||||
func (n NATMapper) ApplyNAT(rpt report.Report, scope string) {
|
||||
n.WalkFlows(func(f Flow) {
|
||||
if n.Conntracker == nil {
|
||||
return
|
||||
}
|
||||
n.Conntracker.WalkFlows(func(f Flow) {
|
||||
var (
|
||||
mapping = toMapping(f)
|
||||
realEndpointID = report.MakeEndpointNodeID(scope, mapping.originalIP, strconv.Itoa(mapping.originalPort))
|
||||
|
||||
@@ -55,7 +55,7 @@ func TestNat(t *testing.T) {
|
||||
"foo": "bar",
|
||||
}))
|
||||
|
||||
natmapper := endpoint.NewNATMapper(ct)
|
||||
natmapper := endpoint.MakeNATMapper(ct)
|
||||
natmapper.ApplyNAT(have, "host1")
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Fatal(test.Diff(want, have))
|
||||
@@ -88,7 +88,7 @@ func TestNat(t *testing.T) {
|
||||
"foo": "baz",
|
||||
}))
|
||||
|
||||
natmapper := endpoint.NewNATMapper(ct)
|
||||
natmapper := endpoint.MakeNATMapper(ct)
|
||||
natmapper.ApplyNAT(have, "host1")
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Fatal(test.Diff(want, have))
|
||||
|
||||
@@ -66,7 +66,7 @@ func NewReporter(hostID, hostName string, includeProcesses bool, useConntrack bo
|
||||
if err != nil {
|
||||
log.Printf("Failed to start conntracker for natmapper: %v", err)
|
||||
}
|
||||
natmapper = NewNATMapper(ct)
|
||||
natmapper = MakeNATMapper(ct)
|
||||
}
|
||||
return &Reporter{
|
||||
hostID: hostID,
|
||||
|
||||
Reference in New Issue
Block a user