Skip to content

Commit 0020934

Browse files
lspgnamorenoz
andauthored
Observation domain (cloudflare#98)
* netflow: Add observation domain and point to message The ObservationDomainID and ObservationPointID are two IPFIX fields that identify the entity that is capturing flows and can be used to enrich the context around a specific sample. Parse these fields from the sample and add them to the FlowMessage. Signed-off-by: Adrian Moreno <[email protected]> Co-authored-by: Adrian Moreno <[email protected]>
1 parent 838505b commit 0020934

File tree

7 files changed

+89
-50
lines changed

7 files changed

+89
-50
lines changed

cmd/enricher/pb/flowext.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

format/common/text.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package common
33
import (
44
"encoding/binary"
55
"fmt"
6-
"github.com/golang/protobuf/proto"
76
"net"
87
"reflect"
98
"strings"
9+
10+
"github.com/golang/protobuf/proto"
1011
)
1112

1213
const (
@@ -52,6 +53,8 @@ var (
5253

5354
TextFields = []string{
5455
"Type",
56+
"ObservationPointID",
57+
"ObservationDomainID",
5558
"TimeReceived",
5659
"SequenceNum",
5760
"SamplingRate",
@@ -99,6 +102,8 @@ var (
99102
FORMAT_TYPE_INTEGER,
100103
FORMAT_TYPE_INTEGER,
101104
FORMAT_TYPE_INTEGER,
105+
FORMAT_TYPE_INTEGER,
106+
FORMAT_TYPE_INTEGER,
102107
FORMAT_TYPE_IP,
103108
FORMAT_TYPE_INTEGER,
104109
FORMAT_TYPE_INTEGER,

pb/flow.pb.go

+67-45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pb/flow.proto

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ message FlowMessage {
100100
uint32 MPLSLastTTL = 61; // Last TTL
101101
uint32 MPLSLastLabel = 62; // Last Label
102102

103+
uint32 ObservationDomainID = 70;
104+
uint32 ObservationPointID = 71;
105+
103106
// Custom fields: start after ID 1000:
104107
// uint32 MyCustomField = 1000;
105108

producer/producer_nf.go

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ func ConvertNetFlowDataSet(version uint16, baseTime uint32, uptime uint32, recor
199199

200200
switch df.Type {
201201

202+
case netflow.IPFIX_FIELD_observationPointId:
203+
DecodeUNumber(v, &(flowMessage.ObservationPointID))
204+
202205
// Statistics
203206
case netflow.NFV9_FIELD_IN_BYTES:
204207
DecodeUNumber(v, &(flowMessage.Bytes))
@@ -560,6 +563,7 @@ func ProcessMessageNetFlowConfig(msgDec interface{}, samplingRateSys SamplingRat
560563
for _, fmsg := range flowMessageSet {
561564
fmsg.SequenceNum = seqnum
562565
fmsg.SamplingRate = uint64(samplingRate)
566+
fmsg.ObservationDomainID = obsDomainId
563567
}
564568
default:
565569
return flowMessageSet, errors.New("Bad NetFlow/IPFIX version")

producer/producer_nflegacy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ func ConvertNetFlowLegacyRecord(baseTime uint32, uptime uint32, record netflowle
1616

1717
timeDiffFirst := (uptime - record.First)
1818
timeDiffLast := (uptime - record.Last)
19-
flowMessage.TimeFlowStart = uint64(baseTime - timeDiffFirst / 1000)
19+
flowMessage.TimeFlowStart = uint64(baseTime - timeDiffFirst/1000)
2020
flowMessage.TimeFlowStartMs = uint64(baseTime)*1000 - uint64(timeDiffFirst)
21-
flowMessage.TimeFlowEnd = uint64(baseTime - timeDiffLast / 1000)
21+
flowMessage.TimeFlowEnd = uint64(baseTime - timeDiffLast/1000)
2222
flowMessage.TimeFlowEndMs = uint64(baseTime)*1000 - uint64(timeDiffLast)
2323

2424
v := make(net.IP, 4)

utils/stopper.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ func (s *stopper) start() error {
2222

2323
func (s *stopper) Shutdown() {
2424
if s.stopCh != nil {
25-
close(s.stopCh)
25+
select {
26+
case <-s.stopCh:
27+
default:
28+
close(s.stopCh)
29+
}
30+
2631
s.stopCh = nil
2732
}
2833
}

0 commit comments

Comments
 (0)