Skip to content

Template registration problem in netflow9 and ipfix packages #25

@satoukick

Description

@satoukick

Hi, there are some mistakes, like the codes below, that will end up registering the same template to a session.

for _, tr := range tfs.Records {
tr.register(s)
}

netflow/netflow9/packet.go

Lines 130 to 132 in 8c13bb0

for _, record := range ofs.Records {
record.register(s)
}

netflow/ipfix/packet.go

Lines 112 to 114 in 8c13bb0

for _, record := range ots.Records {
record.register(s)
}

netflow/ipfix/packet.go

Lines 100 to 102 in 8c13bb0

for _, tr := range ts.Records {
tr.register(s)
}

The problem is described below:

prior to Go 1.22, every freshly-declared loop variable used in a for loop is shared by all iterations during executing the loop. 

I find this blog very helpful, please check!

I think there are two ways to fix the problem:

  1. Add go.mod and declare go 1.22 or later. This will fix the problem without modifying any existing codes.
    Here is the official Go blog for the problem fix: https://go.dev/blog/loopvar-preview

  2. Make a record copy in the loop and register the copy to session. This may be a better choice for backwards compatibility.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions