Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Merge pull request #53 from cloudflare/fix/gre-decoding
Browse files Browse the repository at this point in the history
Fix GRE decoding
  • Loading branch information
lspgn authored Jan 30, 2020
2 parents 1e91bdf + ac41d32 commit ecf0e5a
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions producer/producer_sf.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,25 +186,30 @@ func ParseSampledHeaderConfig(flowMessage *flowmessage.FlowMessage, sampledHeade

// GRE
if len(data) >= offset+4 && nextHeader == 47 {
hasEncap = true
copy(etherTypeEncap, etherType)
etherType = data[offset+2 : offset+4]

nextHeaderEncap = nextHeader
tosEncap = tos
ttlEncap = ttl
identificationEncap = identification
fragOffsetEncap = fragOffset
flowLabelEncap = flowLabel

if (etherType[0] == 0x8 && etherType[1] == 0x0) ||
(etherType[0] == 0x86 && etherType[1] == 0xdd) {
srcIPEncap = srcIP
dstIPEncap = dstIP
etherTypeEncap = data[offset+2 : offset+4]
if (etherTypeEncap[0] == 0x8 && etherTypeEncap[1] == 0x0) ||
(etherTypeEncap[0] == 0x86 && etherTypeEncap[1] == 0xdd) {
encap = true
hasEncap = true
}
offset += 4

if hasEncap {
srcIPEncap = srcIP
dstIPEncap = dstIP

nextHeaderEncap = nextHeader
tosEncap = tos
ttlEncap = ttl
identificationEncap = identification
fragOffsetEncap = fragOffset
flowLabelEncap = flowLabel

etherTypeEncapTmp := etherTypeEncap
etherTypeEncap = etherType
etherType = etherTypeEncapTmp
}

}
iterations++
}
Expand All @@ -218,18 +223,10 @@ func ParseSampledHeaderConfig(flowMessage *flowmessage.FlowMessage, sampledHeade
srcIP = tmpSrc
dstIP = tmpDst

tmpEtype := etherTypeEncap
etherTypeEncap = etherType
etherType = tmpEtype

tmpNextHeader := nextHeaderEncap
nextHeaderEncap = nextHeader
nextHeader = tmpNextHeader

nextHeaderTmp := nextHeaderEncap
nextHeaderEncap = nextHeader
nextHeader = nextHeaderTmp

tosTmp := tosEncap
tosEncap = tos
tos = tosTmp
Expand Down

0 comments on commit ecf0e5a

Please sign in to comment.