Skip to content

Commit

Permalink
Merge pull request #16 from cloudflare/flowlabel
Browse files Browse the repository at this point in the history
Added flow label parsing (IPv6)
  • Loading branch information
lspgn authored Nov 19, 2018
2 parents 3988fe0 + 57d204a commit 6e86c7a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 50 deletions.
4 changes: 2 additions & 2 deletions goflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,13 @@ func FlowMessageToString(fmsg *flowmessage.FlowMessage) string {
"SrcAS:%v DstAS:%v SrcNet:%v DstNet:%v SrcIf:%v DstIf:%v Proto:%v " +
"SrcPort:%v DstPort:%v IPTos:%v ForwardingStatus:%v IPTTL:%v TCPFlags:%v " +
"SrcMac:%v DstMac:%v VlanId:%v Etype:%v IcmpType:%v IcmpCode:%v " +
"SrcVlan:%v DstVlan:%v ",
"SrcVlan:%v DstVlan:%v IPv6FlowLabel:%v",
fmsg.Type, fmsg.TimeRecvd, fmsg.SamplingRate, fmsg.SequenceNum, fmsg.TimeFlow,
net.IP(fmsg.SrcIP), net.IP(fmsg.DstIP), fmsg.IPversion, fmsg.Bytes, fmsg.Packets, net.IP(fmsg.RouterAddr), net.IP(fmsg.NextHop), fmsg.NextHopAS,
fmsg.SrcAS, fmsg.DstAS, fmsg.SrcNet, fmsg.DstNet, fmsg.SrcIf, fmsg.DstIf, fmsg.Proto,
fmsg.SrcPort, fmsg.DstPort, fmsg.IPTos, fmsg.ForwardingStatus, fmsg.IPTTL, fmsg.TCPFlags,
fmsg.SrcMac, fmsg.DstMac, fmsg.VlanId, fmsg.Etype, fmsg.IcmpType, fmsg.IcmpCode,
fmsg.SrcVlan, fmsg.DstVlan)
fmsg.SrcVlan, fmsg.DstVlan, fmsg.IPv6FlowLabel)
return s
}

Expand Down
105 changes: 57 additions & 48 deletions pb/flow.pb.go

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

2 changes: 2 additions & 0 deletions pb/flow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ message FlowMessage {
// Fragments (IPv4/IPv6)
uint32 FragmentId = 35;
uint32 FragmentOffset = 36;

uint32 IPv6FlowLabel = 37;
}
3 changes: 3 additions & 0 deletions producer/producer_nf.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ func ConvertNetFlowDataSet(version uint16, baseTime uint32, uptime uint32, recor
case netflow.NFV9_FIELD_FRAGMENT_OFFSET:
DecodeUNumber(v, &(flowMessage.FragmentOffset))

case netflow.NFV9_FIELD_IPV6_FLOW_LABEL:
DecodeUNumber(v, &(flowMessage.IPv6FlowLabel))

default:
if version == 9 {
// NetFlow v9 time works with a differential based on router's uptime
Expand Down
3 changes: 3 additions & 0 deletions producer/producer_sf.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func ParseSampledHeader(flowMessage *flowmessage.FlowMessage, sampledHeader *sfl
tostmp := uint32(binary.BigEndian.Uint16(data[offset : offset+2]))
tos = uint8(tostmp & 0x0ff0 >> 4)
ttl = data[offset+7]

flowLabeltmp := binary.BigEndian.Uint32(data[offset : offset+4])
(*flowMessage).IPv6FlowLabel = flowLabeltmp & 0xFFFFF
}
} else if etherType[0] == 0x8 && etherType[1] == 0x6 { // ARP
} else {
Expand Down

0 comments on commit 6e86c7a

Please sign in to comment.