Skip to content

Commit

Permalink
Merge pull request #58 from cloudflare/feature/ppp
Browse files Browse the repository at this point in the history
Add PPP decoding
  • Loading branch information
lspgn authored Mar 2, 2020
2 parents cf99955 + f27eadb commit f9ff988
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 75 deletions.
158 changes: 88 additions & 70 deletions pb/flow.pb.go

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

4 changes: 4 additions & 0 deletions pb/flow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ message FlowMessage {
uint32 MPLSLastTTL = 61; // Last TTL
uint32 MPLSLastLabel = 62; // Last Label

// PPP information
bool HasPPP = 63;
uint32 PPPAddressControl = 64;

// Custom fields: start after ID 1000:
// uint32 MyCustomField = 1000;

Expand Down
23 changes: 22 additions & 1 deletion producer/producer_sf.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func ParseSampledHeaderConfig(flowMessage *flowmessage.FlowMessage, sampledHeade
data := (*sampledHeader).HeaderData
switch (*sampledHeader).Protocol {
case 1: // Ethernet
var hasPPP bool
var pppAddressControl uint16
var hasMPLS bool
var countMpls uint32
var firstLabelMpls uint32
Expand Down Expand Up @@ -188,12 +190,28 @@ func ParseSampledHeaderConfig(flowMessage *flowmessage.FlowMessage, sampledHeade
// GRE
if len(data) >= offset+4 && nextHeader == 47 {
etherTypeEncap = data[offset+2 : offset+4]
offset += 4
if (etherTypeEncap[0] == 0x8 && etherTypeEncap[1] == 0x0) ||
(etherTypeEncap[0] == 0x86 && etherTypeEncap[1] == 0xdd) {
encap = true
hasEncap = true
}
offset += 4
if etherTypeEncap[0] == 0x88 && etherTypeEncap[1] == 0x0b && len(data) >= offset+12 {
offset += 8
encap = true
hasPPP = true
pppAddressControl = binary.BigEndian.Uint16(data[offset : offset+2])
pppEtherType := data[offset+2 : offset+4]
if pppEtherType[0] == 0x0 && pppEtherType[1] == 0x21 {
etherTypeEncap = []byte{0x8, 0x00}
hasEncap = true
} else if pppEtherType[0] == 0x0 && pppEtherType[1] == 0x57 {
etherTypeEncap = []byte{0x86, 0xdd}
hasEncap = true
}
offset += 4

}

if hasEncap {
srcIPEncap = srcIP
Expand Down Expand Up @@ -249,6 +267,9 @@ func ParseSampledHeaderConfig(flowMessage *flowmessage.FlowMessage, sampledHeade
flowLabel = flowLabelTmp
}

(*flowMessage).HasPPP = hasPPP
(*flowMessage).PPPAddressControl = uint32(pppAddressControl)

(*flowMessage).HasMPLS = hasMPLS
(*flowMessage).MPLSCount = countMpls
(*flowMessage).MPLS1Label = firstLabelMpls
Expand Down
Loading

0 comments on commit f9ff988

Please sign in to comment.