britram / python-ipfix

IPFIX implementation for Python 3.x
GNU Lesser General Public License v3.0
40 stars 20 forks source link

Encoding and decoding fails for template with first ie element being varlen #24

Open shravan86 opened 6 years ago

shravan86 commented 6 years ago

Hello,

PROBLEM:

If we define a template with the first ie element being a varlen, then the decoding does not seem to work. Please see the below to reproduce the issue -

import ipfix.template import ipfix.ie import hexdump from datetime import datetime from ipaddress import ip_address

msg = ipfix.message.MessageBuffer()

msg.begin_export(8304)

ipfix.ie.use_iana_default()

tmpl = ipfix.template.from_ielist(256, ipfix.ie.spec_list(("applicationName", "flowStartMilliseconds", "sourceIPv4Address", "destinationIPv4Address", "packetDeltaCount")))

msg.add_template(tmpl)

msg.export_ensure_set(256)

rec = { "applicationName" : "testing123", "flowStartMilliseconds" : datetime.strptime("2013-06-21 14:00:00", "%Y-%m-%d %H:%M:%S"), "sourceIPv4Address" : ip_address("10.1.2.3"), "destinationIPv4Address" : ip_address("10.5.6.7"), "packetDeltaCount" : 27}

msg.export_namedict(rec)

print(msg) print(hexdump.dump(msg.to_bytes()))

###################################################

READER

###################################################

msg1 = ipfix.message.MessageBuffer() msg1.from_bytes(msg.to_bytes())

for rec in msg1.namedict_iterator(): print(sorted(rec.items()))

FIX:

The root cause of the issue is in template.py - encode_to() and decode_from() methods.

diff --git a/ipfix/template.py b/ipfix/template.py index 1203e55..87a7f5b 100644 --- a/ipfix/template.py +++ b/ipfix/template.py @@ -187,7 +187,7 @@ class Template(object): offset += packplan.st.size

     # short circuit on no varlen

If you are ok with this fix. Please let me know how to commit this change to master. I have also attached the diff file.

Thanks Shravan

diff.txt