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:
Peter Bourgon
2015-09-29 15:11:02 +02:00
committed by Tom Wilkie
parent 15371a2bba
commit 32a57e63db
3 changed files with 9 additions and 6 deletions

View File

@@ -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))

View File

@@ -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))

View File

@@ -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,