From fca91c93ea719d6d223326583fed98485a9eb1b4 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 11 Dec 2023 19:04:59 +0000
Subject: [PATCH] Bump github.com/vmware/go-ipfix from 0.8.0 to 0.8.1 (#235)

Bumps [github.com/vmware/go-ipfix](https://github.com/vmware/go-ipfix) from 0.8.0 to 0.8.1.
- [Release notes](https://github.com/vmware/go-ipfix/releases)
- [Changelog](https://github.com/vmware/go-ipfix/blob/main/CHANGELOG.md)
- [Commits](https://github.com/vmware/go-ipfix/compare/v0.8.0...v0.8.1)

---
updated-dependencies:
- dependency-name: github.com/vmware/go-ipfix
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
 go.mod                                        |  2 +-
 go.sum                                        |  4 +-
 .../vmware/go-ipfix/pkg/collector/process.go  |  6 +-
 .../vmware/go-ipfix/pkg/entities/ie.go        | 20 ++++++-
 .../vmware/go-ipfix/pkg/entities/record.go    | 57 ++++++++++++++++---
 .../vmware/go-ipfix/pkg/entities/set.go       | 26 +++++----
 .../go-ipfix/pkg/registry/registry_antrea.csv |  2 +-
 .../go-ipfix/pkg/registry/registry_antrea.go  |  2 +-
 vendor/modules.txt                            |  2 +-
 9 files changed, 90 insertions(+), 31 deletions(-)

diff --git a/go.mod b/go.mod
index 41f0a1e1..e008fbc7 100644
--- a/go.mod
+++ b/go.mod
@@ -19,7 +19,7 @@ require (
 	github.com/vishvananda/netlink v1.1.0
 	github.com/vishvananda/netns v0.0.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/sys v0.15.0
 	google.golang.org/grpc v1.59.0
 	google.golang.org/protobuf v1.31.0
diff --git a/go.sum b/go.sum
index 97a3694c..6534c86c 100644
--- a/go.sum
+++ b/go.sum
@@ -824,8 +824,8 @@ github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1Y
 github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
 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 cb59ffca..bad76377 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 871ee449..e18428fb 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 43544bec..8c2524de 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 ac62477b..972378c7 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 20c9cd81..68084cb7 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 6587d8df..5aaf7d59 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 b4e2e532..31d1aef6 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -421,7 +421,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
-- 
GitLab