@@ -34,7 +34,7 @@ func CreateSamplingSystem() SamplingRateSystem {
3434func (s * basicSamplingRateSystem ) AddSamplingRate (version uint16 , obsDomainId uint32 , samplingRate uint32 ) {
3535 s .samplinglock .Lock ()
3636 _ , exists := s .sampling [version ]
37- if exists != true {
37+ if ! exists {
3838 s .sampling [version ] = make (map [uint32 ]uint32 )
3939 }
4040 s.sampling [version ][obsDomainId ] = samplingRate
@@ -119,7 +119,7 @@ func DecodeUNumber(b []byte, out interface{}) error {
119119 iter ++
120120 }
121121 } 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 )
123123 }
124124 }
125125 switch t := out .(type ) {
@@ -132,7 +132,7 @@ func DecodeUNumber(b []byte, out interface{}) error {
132132 case * uint64 :
133133 * t = o
134134 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" )
136136 }
137137 return nil
138138}
@@ -150,13 +150,9 @@ func ConvertNetFlowDataSet(version uint16, baseTime uint32, uptime uint32, recor
150150 for i := range record {
151151 df := record [i ]
152152
153- v , ok := df .Value .([]byte )
154- if ! ok {
155- continue
156- }
153+ v := df .Value
157154
158155 switch df .Type {
159-
160156 // Statistics
161157 case netflow .NFV9_FIELD_IN_BYTES :
162158 DecodeUNumber (v , & (flowMessage .Bytes ))
@@ -382,43 +378,11 @@ func SearchNetFlowOptionDataSets(dataFlowSet []netflow.OptionsDataFlowSet) (uint
382378}
383379
384380func 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
402382}
403383
404384func 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
422386}
423387
424388// Convert a NetFlow datastructure to a FlowMessage protobuf
@@ -474,7 +438,7 @@ func ProcessMessageNetFlow(msgDec interface{}, samplingRateSys SamplingRateSyste
474438 fmsg .SamplingRate = uint64 (samplingRate )
475439 }
476440 default :
477- return flowMessageSet , errors .New ("Bad NetFlow/IPFIX version" )
441+ return flowMessageSet , errors .New ("bad NetFlow/IPFIX version" )
478442 }
479443
480444 return flowMessageSet , nil
0 commit comments