diff --git a/go.mod b/go.mod index e55af1af5..21f4548b8 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/spf13/viper v1.18.1 github.com/stretchr/testify v1.8.4 github.com/vladimirvivien/gexe v0.2.0 - github.com/vmware/go-ipfix v0.8.0 + github.com/vmware/go-ipfix v0.8.1 golang.org/x/net v0.19.0 google.golang.org/grpc v1.59.0 google.golang.org/protobuf v1.31.0 diff --git a/go.sum b/go.sum index 9e2b4f9c2..3a498908a 100644 --- a/go.sum +++ b/go.sum @@ -831,8 +831,8 @@ github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= github.com/vladimirvivien/gexe v0.2.0 h1:nbdAQ6vbZ+ZNsolCgSVb9Fno60kzSuvtzVh6Ytqi/xY= github.com/vladimirvivien/gexe v0.2.0/go.mod h1:LHQL00w/7gDUKIak24n801ABp8C+ni6eBht9vGVst8w= -github.com/vmware/go-ipfix v0.8.0 h1:9jeeMppLHU6KxCz6BHtDw0YW7Von5MKyz03p9fNT5JI= -github.com/vmware/go-ipfix v0.8.0/go.mod h1:Y3YKMFN/Nec6QwmXcDae+uy6xuDgbejwRAZv9RTzS9c= +github.com/vmware/go-ipfix v0.8.1 h1:xoX4Tw9Rsc81+sMkgVoceOon2oP8K9GxYCz/2b6rIhs= +github.com/vmware/go-ipfix v0.8.1/go.mod h1:NvEehcpptPOTBaLSkMA+88l2Oe8YNelVBdvj8PA/1d0= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= diff --git a/vendor/github.com/vmware/go-ipfix/pkg/collector/process.go b/vendor/github.com/vmware/go-ipfix/pkg/collector/process.go index cb59ffcab..bad763778 100644 --- a/vendor/github.com/vmware/go-ipfix/pkg/collector/process.go +++ b/vendor/github.com/vmware/go-ipfix/pkg/collector/process.go @@ -280,7 +280,7 @@ func (cp *CollectingProcess) decodeTemplateSet(templateBuffer *bytes.Buffer, obs return nil, err } } - err := templateSet.AddRecord(elementsWithValue, templateID) + err := templateSet.AddRecordV2(elementsWithValue, templateID) if err != nil { return nil, err } @@ -300,7 +300,7 @@ func (cp *CollectingProcess) decodeDataSet(dataBuffer *bytes.Buffer, obsDomainID } for dataBuffer.Len() > 0 { - elements := make([]entities.InfoElementWithValue, len(template)) + elements := make([]entities.InfoElementWithValue, len(template), len(template)+cp.numExtraElements) for i, element := range template { var length int if element.Len == entities.VariableLength { // string @@ -312,7 +312,7 @@ func (cp *CollectingProcess) decodeDataSet(dataBuffer *bytes.Buffer, obsDomainID return nil, err } } - err = dataSet.AddRecordWithExtraElements(elements, cp.numExtraElements, templateID) + err = dataSet.AddRecordV2(elements, templateID) if err != nil { return nil, err } diff --git a/vendor/github.com/vmware/go-ipfix/pkg/entities/ie.go b/vendor/github.com/vmware/go-ipfix/pkg/entities/ie.go index 871ee449b..e18428fbc 100644 --- a/vendor/github.com/vmware/go-ipfix/pkg/entities/ie.go +++ b/vendor/github.com/vmware/go-ipfix/pkg/entities/ie.go @@ -318,9 +318,25 @@ func DecodeAndCreateInfoElementWithValue(element *InfoElement, value []byte) (In case DateTimeMicroseconds, DateTimeNanoseconds: return nil, fmt.Errorf("API does not support micro and nano seconds types yet") case MacAddress: - return NewMacAddressInfoElement(element, value), nil + if value == nil { + return NewMacAddressInfoElement(element, nil), nil + } else { + // make sure that we make a copy of the slice, instead of using it as is + // otherwise the underlying array for value may not be GC'd until the IE is GC'd + // the underlying array may be much larger than the value slice itself + addr := append([]byte{}, value...) + return NewMacAddressInfoElement(element, addr), nil + } case Ipv4Address, Ipv6Address: - return NewIPAddressInfoElement(element, value), nil + if value == nil { + return NewIPAddressInfoElement(element, nil), nil + } else { + // make sure that we make a copy of the slice, instead of using it as is + // otherwise the underlying array for value may not be GC'd until the IE is GC'd + // the underlying array may be much larger than the value slice itself + addr := append([]byte{}, value...) + return NewIPAddressInfoElement(element, addr), nil + } case String: var val string if value == nil { diff --git a/vendor/github.com/vmware/go-ipfix/pkg/entities/record.go b/vendor/github.com/vmware/go-ipfix/pkg/entities/record.go index 43544becf..8c2524de0 100644 --- a/vendor/github.com/vmware/go-ipfix/pkg/entities/record.go +++ b/vendor/github.com/vmware/go-ipfix/pkg/entities/record.go @@ -68,6 +68,24 @@ func NewDataRecord(id uint16, numElements, numExtraElements int, isDecoding bool } } +func NewDataRecordFromElements(id uint16, elements []InfoElementWithValue, isDecoding bool) *dataRecord { + length := 0 + if !isDecoding { + for idx := range elements { + length += elements[idx].GetLength() + } + } + return &dataRecord{ + baseRecord{ + fieldCount: uint16(len(elements)), + templateID: id, + isDecoding: isDecoding, + len: length, + orderedElementList: elements, + }, + } +} + type templateRecord struct { baseRecord // Minimum data record length required to be sent for this template. @@ -91,6 +109,25 @@ func NewTemplateRecord(id uint16, numElements int, isDecoding bool) *templateRec } } +func NewTemplateRecordFromElements(id uint16, elements []InfoElementWithValue, isDecoding bool) *templateRecord { + r := &templateRecord{ + baseRecord{ + buffer: make([]byte, 4), + fieldCount: uint16(len(elements)), + templateID: id, + isDecoding: isDecoding, + orderedElementList: elements, + }, + 0, + len(elements), + } + for idx := range elements { + infoElement := elements[idx].GetInfoElement() + r.addInfoElement(infoElement) + } + return r +} + func (b *baseRecord) GetTemplateID() uint16 { return b.templateID } @@ -205,12 +242,7 @@ func (t *templateRecord) PrepareRecord() error { return nil } -func (t *templateRecord) AddInfoElement(element InfoElementWithValue) error { - infoElement := element.GetInfoElement() - // val could be used to specify smaller length than default? For now assert it to be nil - if !element.IsValueEmpty() { - return fmt.Errorf("template record cannot take element %v with non-empty value", infoElement.Name) - } +func (t *templateRecord) addInfoElement(infoElement *InfoElement) { initialLength := len(t.buffer) // Add field specifier {elementID: uint16, elementLen: uint16} addBytes := make([]byte, 4) @@ -224,14 +256,23 @@ func (t *templateRecord) AddInfoElement(element InfoElementWithValue) error { binary.BigEndian.PutUint32(addBytes, infoElement.EnterpriseId) t.buffer = append(t.buffer, addBytes...) } - t.orderedElementList[t.index] = element - t.index++ // Keep track of minimum data record length required for sanity check if infoElement.Len == VariableLength { t.minDataRecLength = t.minDataRecLength + 1 } else { t.minDataRecLength = t.minDataRecLength + infoElement.Len } +} + +func (t *templateRecord) AddInfoElement(element InfoElementWithValue) error { + infoElement := element.GetInfoElement() + // val could be used to specify smaller length than default? For now assert it to be nil + if !element.IsValueEmpty() { + return fmt.Errorf("template record cannot take element %v with non-empty value", infoElement.Name) + } + t.addInfoElement(infoElement) + t.orderedElementList[t.index] = element + t.index++ return nil } diff --git a/vendor/github.com/vmware/go-ipfix/pkg/entities/set.go b/vendor/github.com/vmware/go-ipfix/pkg/entities/set.go index ac62477b0..972378c75 100644 --- a/vendor/github.com/vmware/go-ipfix/pkg/entities/set.go +++ b/vendor/github.com/vmware/go-ipfix/pkg/entities/set.go @@ -49,6 +49,10 @@ type Set interface { UpdateLenInHeader() AddRecord(elements []InfoElementWithValue, templateID uint16) error AddRecordWithExtraElements(elements []InfoElementWithValue, numExtraElements int, templateID uint16) error + // Unlike AddRecord, AddRecordV2 uses the elements slice directly, instead of creating a new + // one. This can result in fewer memory allocations. The caller should not modify the + // contents of the slice after calling AddRecordV2. + AddRecordV2(elements []InfoElementWithValue, templateID uint16) error GetRecords() []Record GetNumberOfRecords() uint32 } @@ -122,9 +126,13 @@ func (s *set) UpdateLenInHeader() { } func (s *set) AddRecord(elements []InfoElementWithValue, templateID uint16) error { + return s.AddRecordWithExtraElements(elements, 0, templateID) +} + +func (s *set) AddRecordWithExtraElements(elements []InfoElementWithValue, numExtraElements int, templateID uint16) error { var record Record if s.setType == Data { - record = NewDataRecord(templateID, len(elements), 0, s.isDecoding) + record = NewDataRecord(templateID, len(elements), numExtraElements, s.isDecoding) } else if s.setType == Template { record = NewTemplateRecord(templateID, len(elements), s.isDecoding) err := record.PrepareRecord() @@ -134,8 +142,8 @@ func (s *set) AddRecord(elements []InfoElementWithValue, templateID uint16) erro } else { return fmt.Errorf("set type is not supported") } - for _, element := range elements { - err := record.AddInfoElement(element) + for i := range elements { + err := record.AddInfoElement(elements[i]) if err != nil { return err } @@ -145,12 +153,12 @@ func (s *set) AddRecord(elements []InfoElementWithValue, templateID uint16) erro return nil } -func (s *set) AddRecordWithExtraElements(elements []InfoElementWithValue, numExtraElements int, templateID uint16) error { +func (s *set) AddRecordV2(elements []InfoElementWithValue, templateID uint16) error { var record Record if s.setType == Data { - record = NewDataRecord(templateID, len(elements), numExtraElements, s.isDecoding) + record = NewDataRecordFromElements(templateID, elements, s.isDecoding) } else if s.setType == Template { - record = NewTemplateRecord(templateID, len(elements), s.isDecoding) + record = NewTemplateRecordFromElements(templateID, elements, s.isDecoding) err := record.PrepareRecord() if err != nil { return err @@ -158,12 +166,6 @@ func (s *set) AddRecordWithExtraElements(elements []InfoElementWithValue, numExt } else { return fmt.Errorf("set type is not supported") } - for i := range elements { - err := record.AddInfoElement(elements[i]) - if err != nil { - return err - } - } s.records = append(s.records, record) s.length += record.GetRecordLength() return nil diff --git a/vendor/github.com/vmware/go-ipfix/pkg/registry/registry_antrea.csv b/vendor/github.com/vmware/go-ipfix/pkg/registry/registry_antrea.csv index 20c9cd81d..68084cb70 100644 --- a/vendor/github.com/vmware/go-ipfix/pkg/registry/registry_antrea.csv +++ b/vendor/github.com/vmware/go-ipfix/pkg/registry/registry_antrea.csv @@ -54,5 +54,5 @@ ElementID,Name,Abstract Data Type,Data Type Semantics,Status,Description,Units,R 152,flowEndSecondsFromDestinationNode,dateTimeSeconds,,current,,,,,,,,56506, 153,egressName,string,,current,,,,,,,,56506, 154,egressIP,string,,current,,,,,,,,56506, -155,l7ProtocolName,string,,current,,,,,,,,56506, +155,appProtocolName,string,,current,,,,,,,,56506, 156,httpVals,string,,current,,,,,,,,56506, diff --git a/vendor/github.com/vmware/go-ipfix/pkg/registry/registry_antrea.go b/vendor/github.com/vmware/go-ipfix/pkg/registry/registry_antrea.go index 6587d8df9..5aaf7d597 100644 --- a/vendor/github.com/vmware/go-ipfix/pkg/registry/registry_antrea.go +++ b/vendor/github.com/vmware/go-ipfix/pkg/registry/registry_antrea.go @@ -76,6 +76,6 @@ func loadAntreaRegistry() { registerInfoElement(*entities.NewInfoElement("flowEndSecondsFromDestinationNode", 152, 14, 56506, 4), 56506) registerInfoElement(*entities.NewInfoElement("egressName", 153, 13, 56506, 65535), 56506) registerInfoElement(*entities.NewInfoElement("egressIP", 154, 13, 56506, 65535), 56506) - registerInfoElement(*entities.NewInfoElement("l7ProtocolName", 155, 13, 56506, 65535), 56506) + registerInfoElement(*entities.NewInfoElement("appProtocolName", 155, 13, 56506, 65535), 56506) registerInfoElement(*entities.NewInfoElement("httpVals", 156, 13, 56506, 65535), 56506) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 1dd22cbed..90caa758d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -446,7 +446,7 @@ github.com/vladimirvivien/gexe/fs github.com/vladimirvivien/gexe/http github.com/vladimirvivien/gexe/prog github.com/vladimirvivien/gexe/vars -# github.com/vmware/go-ipfix v0.8.0 +# github.com/vmware/go-ipfix v0.8.1 ## explicit; go 1.21 github.com/vmware/go-ipfix/pkg/collector github.com/vmware/go-ipfix/pkg/entities