-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NETOBSERV-1890: decode TCP flags (new stage/rule) (#747)
* NETOBSERV-1890: decode TCP flags (new stage/rule) * Use flags list
- Loading branch information
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package utils | ||
|
||
type tcpFlag struct { | ||
value uint16 | ||
name string | ||
} | ||
|
||
var tcpFlags = []tcpFlag{ | ||
{value: 1, name: "FIN"}, | ||
{value: 2, name: "SYN"}, | ||
{value: 4, name: "RST"}, | ||
{value: 8, name: "PSH"}, | ||
{value: 16, name: "ACK"}, | ||
{value: 32, name: "URG"}, | ||
{value: 64, name: "ECE"}, | ||
{value: 128, name: "CWR"}, | ||
{value: 256, name: "SYN_ACK"}, | ||
{value: 512, name: "FIN_ACK"}, | ||
{value: 1024, name: "RST_ACK"}, | ||
} | ||
|
||
func DecodeTCPFlags(bitfield uint16) []string { | ||
var values []string | ||
for _, flag := range tcpFlags { | ||
if bitfield&flag.value != 0 { | ||
values = append(values, flag.name) | ||
} | ||
} | ||
return values | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDecodeFlags(t *testing.T) { | ||
flags528 := DecodeTCPFlags(528) | ||
assert.Equal(t, []string{"ACK", "FIN_ACK"}, flags528) | ||
|
||
flags256 := DecodeTCPFlags(256) | ||
assert.Equal(t, []string{"SYN_ACK"}, flags256) | ||
|
||
flags666 := DecodeTCPFlags(666) | ||
assert.Equal(t, []string{"SYN", "PSH", "ACK", "CWR", "FIN_ACK"}, flags666) | ||
} |