Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple template set #2

Open
fedy85 opened this issue Jun 21, 2023 · 0 comments
Open

multiple template set #2

fedy85 opened this issue Jun 21, 2023 · 0 comments

Comments

@fedy85
Copy link

fedy85 commented Jun 21, 2023

The library ignores template sets with multiple templates and merges all of them into the first one it finds in byte buffer.
I've made a fix. Could you merge it into the master ?

/ipfix_node/lib/ipfix_packet_elements/template_set/record.js

--- record.js.backup    2023-06-20 22:56:54.323450660 +0200
+++ record.js   2023-06-21 11:09:49.482162620 +0200
@@ -4,20 +4,31 @@
     this.templateId = undefined;
     this.numberFields = undefined;
     this.FieldSpecifiers = []
+
+    this.isLast = false;
+    this.newBuffer = null;
+
     var _construct = function() {
-        var i = 0;
-        self.setId = buffer.readUInt16BE(i)
-        self.sizeInBytes = buffer.readUInt16BE(i += 2);
-        self.templateId = buffer.readUInt16BE(i += 2);
-        self.numberFields = buffer.readUInt16BE(i += 2);
-        buffer = buffer.slice(i += 2);
+        var byte = 0;
+        self.setId = buffer.readUInt16BE(byte)
+        self.sizeInBytes = buffer.readUInt16BE(byte += 2);
+        self.templateId = buffer.readUInt16BE(byte += 2);
+        self.numberFields = buffer.readUInt16BE(byte += 2);
+
+        var headerBuffer = buffer.slice(0, 4);
+        var setBuffer = buffer.slice(byte += 2);

-        while (i < self.sizeInBytes) {
-            var FreshSpecifier = new TemplateRecordFieldSpecifier(buffer);
+        var i = 0;
+        while (i < self.numberFields) {
+            var FreshSpecifier = new TemplateRecordFieldSpecifier(setBuffer);
             self.FieldSpecifiers.push(FreshSpecifier);
-            buffer = buffer.slice(4);
-            i += 4;
+            setBuffer = setBuffer.slice(4);
+            i++;
         }
+
+        self.isLast = (setBuffer.byteLength == 0) ? true : false;
+        self.newBuffer = Buffer.concat([headerBuffer, setBuffer]);
+
         return this;
     }

and

/ipfix_node/lib/ipfix_packet_elements/ipfix_packet.js

--- ipfix_packet.js.backup      2023-06-21 11:19:55.764359997 +0200
+++ ipfix_packet.js     2023-06-21 11:10:10.354236553 +0200
@@ -22,10 +22,16 @@
             var setType = getSetType(setId);
             var sizeInBytes = buffer.readUInt16BE(2);
             if (setType == 'DataTemplate') {
-                var TemplateSet = new TemplateRecord(buffer);
+                var isLast = false;
+                while (!isLast) {
+                    var TemplateSet = new TemplateRecord(buffer);

-                storeTemplate(TemplateSet);
-                self.TemplateSets.push(TemplateSet);
+                    buffer = TemplateSet.newBuffer;
+                    isLast = TemplateSet.isLast;
+
+                    storeTemplate(TemplateSet);
+                    self.TemplateSets.push(TemplateSet);
+                }
             } else if (setType == 'OptionTemplate') {
                 var OptionsTemplateSet = new OptionsTemplateRecord(buffer);
                 storeTemplate(OptionsTemplateSet);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant