Skip to content

Commit

Permalink
do not support hopopt in favor of skipping proto field when it is not…
Browse files Browse the repository at this point in the history
… set (#362)
  • Loading branch information
Joseph Sirianni authored Jul 15, 2021
1 parent 0fe36d0 commit 0019926
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
9 changes: 6 additions & 3 deletions operator/builtin/input/goflow/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ func Parse(message *flowmessage.FlowMessage) (map[string]interface{}, time.Time,
m["etype"] = int(message.Etype)
}

// always set proto
m["proto"] = int(message.Proto)
m["proto_name"] = protoName(int(message.Proto))
// Goflow input does not support HOPOPT as it maps to 0, meaning HOPOPT would
// be set anytime the proto field is not present.
if message.Proto > 0 {
m["proto"] = int(message.Proto)
m["proto_name"] = protoName(int(message.Proto))
}

if message.SrcPort > 0 {
m["srcport"] = int(message.SrcPort)
Expand Down
4 changes: 2 additions & 2 deletions operator/builtin/input/goflow/parse_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ func TestParseProtoName(t *testing.T) {
name string
input int
}{
{
/*{ ommitting hopopt, see parse.go
"hopopt",
0,
},
},*/
{
"icmp",
1,
Expand Down
36 changes: 7 additions & 29 deletions operator/builtin/input/goflow/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ func TestParse(t *testing.T) {
"minimal",
&flowmessage.FlowMessage{},
map[string]interface{}{
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
"inif": 0,
"outif": 0,
},
time.Time{},
false,
Expand All @@ -45,10 +43,8 @@ func TestParse(t *testing.T) {
Type: flowmessage.FlowMessage_FLOWUNKNOWN,
},
map[string]interface{}{
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
"inif": 0,
"outif": 0,
},
time.Time{},
false,
Expand All @@ -59,11 +55,9 @@ func TestParse(t *testing.T) {
Type: flowmessage.FlowMessage_IPFIX,
},
map[string]interface{}{
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
"type": "IPFIX",
"inif": 0,
"outif": 0,
"type": "IPFIX",
},
time.Time{},
false,
Expand All @@ -81,8 +75,6 @@ func TestParse(t *testing.T) {
"srcaddr": SrcAddr.String(),
"dstaddr": DstAddr.String(),
"nexthop": NextHop.String(),
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
},
Expand All @@ -101,8 +93,6 @@ func TestParse(t *testing.T) {
"sampleraddress": SamplerAddress.String(),
"dstaddr": DstAddr.String(),
"nexthop": NextHop.String(),
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
},
Expand All @@ -121,8 +111,6 @@ func TestParse(t *testing.T) {
"sampleraddress": SamplerAddress.String(),
"srcaddr": SrcAddr.String(),
"nexthop": NextHop.String(),
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
},
Expand All @@ -141,8 +129,6 @@ func TestParse(t *testing.T) {
"sampleraddress": SamplerAddress.String(),
"srcaddr": SrcAddr.String(),
"dstaddr": DstAddr.String(),
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
},
Expand All @@ -162,8 +148,6 @@ func TestParse(t *testing.T) {
"srcaddr": SrcAddr.String(),
"dstaddr": DstAddr.String(),
"nexthop": NextHop.String(),
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
},
Expand All @@ -183,8 +167,6 @@ func TestParse(t *testing.T) {
"srcaddr": SrcAddr.String(),
"dstaddr": DstAddr.String(),
"nexthop": NextHop.String(),
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
},
Expand All @@ -204,8 +186,6 @@ func TestParse(t *testing.T) {
"srcaddr": "ip:10.1.1.1",
"dstaddr": DstAddr.String(),
"nexthop": NextHop.String(),
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
},
Expand All @@ -226,8 +206,6 @@ func TestParse(t *testing.T) {
"srcaddr": SrcAddr.String(),
"dstaddr": DstAddr.String(),
"nexthop": NextHop.String(),
"proto": 0,
"proto_name": "HOPOPT",
"inif": 0,
"outif": 0,
},
Expand Down

0 comments on commit 0019926

Please sign in to comment.