Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix v6 ipfix export #94

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pkg/exporter/ipfix.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,16 @@ func (ipf *IPFIX) sendDataRecord(log *logrus.Entry, record *flow.Record, v6 bool
if err != nil {
return err
}
err = dataSet.AddRecord(ipf.entitiesV4, templateID)
if err != nil {
return err
if v6 {
Copy link
Contributor

@msherif1234 msherif1234 Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its good practice to avoid if() {
} else {
}

instead

err = dataSet.AddRecord(ipf.entitiesV4, templateID)
if err != nil {
    return err
}

if v6 {
   err = dataSet.AddRecord(ipf.entitiesV6, templateID)
   if err != nil {
       return err
   }
}

Copy link
Collaborator Author

@praveingk praveingk Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msherif1234 Wouldn't that perform dataSet.AddRecord multiple times for v6?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 @praveingk
I think the good practice referred to is writing if { ...return } ... return instead of if { ...return } else { ...return}, but it doesn't apply here as not all paths return in the conditional expressions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah @praveingk I was commenting in general and yes whatu have make sense
/lgtm

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @praveingk
so we can do this

entities := ipf.entitiesV4
if v6 {
  entities = ipf.entitiesV6
}
if err := dataSet.AddRecord(entities, templateID); err != nil {
  return err
}

err = dataSet.AddRecord(ipf.entitiesV6, templateID)
if err != nil {
return err
}
} else {
err = dataSet.AddRecord(ipf.entitiesV4, templateID)
if err != nil {
return err
}
}
_, err = ipf.exporter.SendSet(dataSet)
if err != nil {
Expand Down