Skip to content

Commit

Permalink
Add MPLS decoding for IPFIX (cloudflare#95)
Browse files Browse the repository at this point in the history
* Add MPLS decoding for IPFIX
Co-authored-by: David Roy <[email protected]>
  • Loading branch information
lspgn authored Jul 21, 2022
1 parent 0020934 commit e0abb7b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 39 deletions.
88 changes: 49 additions & 39 deletions pb/flow.pb.go

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

1 change: 1 addition & 0 deletions pb/flow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ message FlowMessage {
uint32 MPLS3Label = 60; // Third Label
uint32 MPLSLastTTL = 61; // Last TTL
uint32 MPLSLastLabel = 62; // Last Label
bytes MPLSLabelIP = 65; // MPLS TOP Label IP

uint32 ObservationDomainID = 70;
uint32 ObservationPointID = 71;
Expand Down
19 changes: 19 additions & 0 deletions producer/producer_nf.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,25 @@ func ConvertNetFlowDataSet(version uint16, baseTime uint32, uptime uint32, recor
case netflow.NFV9_FIELD_DIRECTION:
DecodeUNumber(v, &(flowMessage.FlowDirection))

//MPLS
case netflow.IPFIX_FIELD_mplsTopLabelStackSection:
var mplsLabel uint32
DecodeUNumber(v, &mplsLabel)
flowMessage.MPLS1Label = uint32(mplsLabel >> 4)
flowMessage.HasMPLS = true
case netflow.IPFIX_FIELD_mplsLabelStackSection2:
var mplsLabel uint32
DecodeUNumber(v, &mplsLabel)
flowMessage.MPLS2Label = uint32(mplsLabel >> 4)
case netflow.IPFIX_FIELD_mplsLabelStackSection3:
var mplsLabel uint32
DecodeUNumber(v, &mplsLabel)
flowMessage.MPLS3Label = uint32(mplsLabel >> 4)
case netflow.IPFIX_FIELD_mplsTopLabelIPv4Address:
flowMessage.MPLSLabelIP = v
case netflow.IPFIX_FIELD_mplsTopLabelIPv6Address:
flowMessage.MPLSLabelIP = v

default:
if version == 9 {
// NetFlow v9 time works with a differential based on router's uptime
Expand Down

0 comments on commit e0abb7b

Please sign in to comment.