@@ -34,7 +34,7 @@ func CreateSamplingSystem() SamplingRateSystem {
34
34
func (s * basicSamplingRateSystem ) AddSamplingRate (version uint16 , obsDomainId uint32 , samplingRate uint32 ) {
35
35
s .samplinglock .Lock ()
36
36
_ , exists := s .sampling [version ]
37
- if exists != true {
37
+ if ! exists {
38
38
s .sampling [version ] = make (map [uint32 ]uint32 )
39
39
}
40
40
s.sampling [version ][obsDomainId ] = samplingRate
@@ -119,7 +119,7 @@ func DecodeUNumber(b []byte, out interface{}) error {
119
119
iter ++
120
120
}
121
121
} else {
122
- return errors . New ( fmt .Sprintf ( "Non -regular number of bytes for a number: %v" , l ) )
122
+ return fmt .Errorf ( "non -regular number of bytes for a number: %v" , l )
123
123
}
124
124
}
125
125
switch t := out .(type ) {
@@ -132,7 +132,7 @@ func DecodeUNumber(b []byte, out interface{}) error {
132
132
case * uint64 :
133
133
* t = o
134
134
default :
135
- return errors .New ("The parameter is not a pointer to a byte/uint16/uint32/uint64 structure" )
135
+ return errors .New ("the parameter is not a pointer to a byte/uint16/uint32/uint64 structure" )
136
136
}
137
137
return nil
138
138
}
@@ -150,13 +150,9 @@ func ConvertNetFlowDataSet(version uint16, baseTime uint32, uptime uint32, recor
150
150
for i := range record {
151
151
df := record [i ]
152
152
153
- v , ok := df .Value .([]byte )
154
- if ! ok {
155
- continue
156
- }
153
+ v := df .Value
157
154
158
155
switch df .Type {
159
-
160
156
// Statistics
161
157
case netflow .NFV9_FIELD_IN_BYTES :
162
158
DecodeUNumber (v , & (flowMessage .Bytes ))
@@ -382,43 +378,11 @@ func SearchNetFlowOptionDataSets(dataFlowSet []netflow.OptionsDataFlowSet) (uint
382
378
}
383
379
384
380
func SplitNetFlowSets (packetNFv9 netflow.NFv9Packet ) ([]netflow.DataFlowSet , []netflow.TemplateFlowSet , []netflow.NFv9OptionsTemplateFlowSet , []netflow.OptionsDataFlowSet ) {
385
- dataFlowSet := make ([]netflow.DataFlowSet , 0 )
386
- templatesFlowSet := make ([]netflow.TemplateFlowSet , 0 )
387
- optionsTemplatesFlowSet := make ([]netflow.NFv9OptionsTemplateFlowSet , 0 )
388
- optionsDataFlowSet := make ([]netflow.OptionsDataFlowSet , 0 )
389
- for _ , flowSet := range packetNFv9 .FlowSets {
390
- switch flowSet .(type ) {
391
- case netflow.TemplateFlowSet :
392
- templatesFlowSet = append (templatesFlowSet , flowSet .(netflow.TemplateFlowSet ))
393
- case netflow.NFv9OptionsTemplateFlowSet :
394
- optionsTemplatesFlowSet = append (optionsTemplatesFlowSet , flowSet .(netflow.NFv9OptionsTemplateFlowSet ))
395
- case netflow.DataFlowSet :
396
- dataFlowSet = append (dataFlowSet , flowSet .(netflow.DataFlowSet ))
397
- case netflow.OptionsDataFlowSet :
398
- optionsDataFlowSet = append (optionsDataFlowSet , flowSet .(netflow.OptionsDataFlowSet ))
399
- }
400
- }
401
- return dataFlowSet , templatesFlowSet , optionsTemplatesFlowSet , optionsDataFlowSet
381
+ return packetNFv9 .DataFS , packetNFv9 .TemplateFS , packetNFv9 .NFv9OptionsTemplateFS , packetNFv9 .OptionsDataFS
402
382
}
403
383
404
384
func SplitIPFIXSets (packetIPFIX netflow.IPFIXPacket ) ([]netflow.DataFlowSet , []netflow.TemplateFlowSet , []netflow.IPFIXOptionsTemplateFlowSet , []netflow.OptionsDataFlowSet ) {
405
- dataFlowSet := make ([]netflow.DataFlowSet , 0 )
406
- templatesFlowSet := make ([]netflow.TemplateFlowSet , 0 )
407
- optionsTemplatesFlowSet := make ([]netflow.IPFIXOptionsTemplateFlowSet , 0 )
408
- optionsDataFlowSet := make ([]netflow.OptionsDataFlowSet , 0 )
409
- for _ , flowSet := range packetIPFIX .FlowSets {
410
- switch flowSet .(type ) {
411
- case netflow.TemplateFlowSet :
412
- templatesFlowSet = append (templatesFlowSet , flowSet .(netflow.TemplateFlowSet ))
413
- case netflow.IPFIXOptionsTemplateFlowSet :
414
- optionsTemplatesFlowSet = append (optionsTemplatesFlowSet , flowSet .(netflow.IPFIXOptionsTemplateFlowSet ))
415
- case netflow.DataFlowSet :
416
- dataFlowSet = append (dataFlowSet , flowSet .(netflow.DataFlowSet ))
417
- case netflow.OptionsDataFlowSet :
418
- optionsDataFlowSet = append (optionsDataFlowSet , flowSet .(netflow.OptionsDataFlowSet ))
419
- }
420
- }
421
- return dataFlowSet , templatesFlowSet , optionsTemplatesFlowSet , optionsDataFlowSet
385
+ return packetIPFIX .DataFS , packetIPFIX .TemplateFS , packetIPFIX .IPFIXOptionsTemplateFS , packetIPFIX .OptionsDataFS
422
386
}
423
387
424
388
// Convert a NetFlow datastructure to a FlowMessage protobuf
@@ -474,7 +438,7 @@ func ProcessMessageNetFlow(msgDec interface{}, samplingRateSys SamplingRateSyste
474
438
fmsg .SamplingRate = uint64 (samplingRate )
475
439
}
476
440
default :
477
- return flowMessageSet , errors .New ("Bad NetFlow/IPFIX version" )
441
+ return flowMessageSet , errors .New ("bad NetFlow/IPFIX version" )
478
442
}
479
443
480
444
return flowMessageSet , nil
0 commit comments