Skip to content

Commit

Permalink
fix(inputs.netflow): change TCP and IP flags processing from using sw…
Browse files Browse the repository at this point in the history
…itch statements to if statements

fallthrough usage is not valid because next condition is not evaluated
  • Loading branch information
jlgonzalez committed Nov 29, 2024
1 parent 3fa0430 commit 702957c
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions plugins/inputs/netflow/sflow_v5.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,13 @@ func (d *sflowv5Decoder) decodeRawHeaderSample(record *sflow.SampledHeader) (map
fields["dst"] = l.DstIP.String()

flags := []byte("........")
switch {
case l.Flags&layers.IPv4EvilBit > 0:
if l.Flags&layers.IPv4EvilBit > 0 {
flags[7] = byte('E')
fallthrough
case l.Flags&layers.IPv4DontFragment > 0:
}
if l.Flags&layers.IPv4DontFragment > 0 {
flags[6] = byte('D')
fallthrough
case l.Flags&layers.IPv4MoreFragments > 0:
}
if l.Flags&layers.IPv4MoreFragments > 0 {
flags[5] = byte('M')
}
fields["fragment_flags"] = string(flags)
Expand All @@ -420,29 +419,28 @@ func (d *sflowv5Decoder) decodeRawHeaderSample(record *sflow.SampledHeader) (map
fields["tcp_window_size"] = l.Window
fields["tcp_urgent_ptr"] = l.Urgent
flags := []byte("........")
switch {
case l.FIN:
if l.FIN {
flags[7] = byte('F')
fallthrough
case l.SYN:
}
if l.SYN {
flags[6] = byte('S')
fallthrough
case l.RST:
}
if l.RST {
flags[5] = byte('R')
fallthrough
case l.PSH:
}
if l.PSH {
flags[4] = byte('P')
fallthrough
case l.ACK:
}
if l.ACK {
flags[3] = byte('A')
fallthrough
case l.URG:
}
if l.URG {
flags[2] = byte('U')
fallthrough
case l.ECE:
}
if l.ECE {
flags[1] = byte('E')
fallthrough
case l.CWR:
}
if l.CWR {
flags[0] = byte('C')
}
fields["tcp_flags"] = string(flags)
Expand Down

0 comments on commit 702957c

Please sign in to comment.