Skip to content

Commit

Permalink
Parse ICMP code and type (#7)
Browse files Browse the repository at this point in the history
* sflow: from packet sample
* netflow/ipfix:
  * field 32 on NetFlow
  * fields 139, 176, 177, 178,179 on IPFIX
* updated protobuf
  • Loading branch information
lspgn committed May 23, 2018
1 parent b8cc786 commit 0e715d6
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 88 deletions.
2 changes: 1 addition & 1 deletion goflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"bytes"
)

const AppVersion = "GoFlow v2.0.3"
const AppVersion = "GoFlow v2.0.4"

var (
FEnable = flag.Bool("netflow", true, "Enable NetFlow")
Expand Down
206 changes: 119 additions & 87 deletions pb/flow.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pb/flow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ message FlowMessage {

// Layer 3 protocol (IPv4/IPv6/ARP/...)
uint32 Etype = 30;

uint32 IcmpType = 31;
uint32 IcmpCode = 32;
}
20 changes: 20 additions & 0 deletions producer/producer_nf.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,26 @@ func ConvertNetFlowDataSet(version uint16, baseTime uint32, uptime uint32, recor
flowMessage.IPversion = flowmessage.FlowMessage_IPv6
flowMessage.NextHop = v

// ICMP
case netflow.NFV9_FIELD_ICMP_TYPE:
var icmpTypeCode uint16
DecodeUNumber(v, &icmpTypeCode)
flowMessage.IcmpType = uint32(icmpTypeCode>>8)
flowMessage.IcmpCode = uint32(icmpTypeCode&0xff)
case netflow.IPFIX_FIELD_icmpTypeCodeIPv6:
var icmpTypeCode uint16
DecodeUNumber(v, &icmpTypeCode)
flowMessage.IcmpType = uint32(icmpTypeCode>>8)
flowMessage.IcmpCode = uint32(icmpTypeCode&0xff)
case netflow.IPFIX_FIELD_icmpTypeIPv4:
DecodeUNumber(v, &(flowMessage.IcmpType))
case netflow.IPFIX_FIELD_icmpTypeIPv6:
DecodeUNumber(v, &(flowMessage.IcmpType))
case netflow.IPFIX_FIELD_icmpCodeIPv4:
DecodeUNumber(v, &(flowMessage.IcmpCode))
case netflow.IPFIX_FIELD_icmpCodeIPv6:
DecodeUNumber(v, &(flowMessage.IcmpCode))

// Mac
case netflow.NFV9_FIELD_IN_SRC_MAC:
DecodeUNumber(v, &(flowMessage.SrcMac))
Expand Down
6 changes: 6 additions & 0 deletions producer/producer_sf.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func ParseSampledHeader(flowMessage *flowmessage.FlowMessage, sampledHeader *sfl
tcpflags = dataTransport[13]
}

// ICMP and ICMPv6
if len(dataTransport) >= 2 && (nextHeader == 1 || nextHeader == 58) {
(*flowMessage).IcmpType = uint32(dataTransport[0])
(*flowMessage).IcmpCode = uint32(dataTransport[1])
}

(*flowMessage).SrcIP = srcIP
(*flowMessage).DstIP = dstIP
(*flowMessage).Proto = uint32(nextHeader)
Expand Down

0 comments on commit 0e715d6

Please sign in to comment.