Wireshark Lua dissector reassembly - dissector not called with previous Tvb's data -
i trying write lua dissector data comes in payload of protocol. each packet contains serial data. data needs processed cr-delimited (0x0d
/\r
) packets, these don't line protocol packets.
i'm having problem dissector function not called left on data last time if report don't have enough data parse.
for example, have following protocol packets:
1: 01 02 03 0d 2: 11 12 13 3: 21 22 23 24 0d
then have 2 dissectable sequences: 01 02 03 0d
(the first packet), 11 12 13 21 22 23 24 0d
(packet 2 , packet 3).
my strategy to:
- work though each packet, looking offset of
\r
- if not found:
- set
desegment_offset = 0
- set
desegment_len = desegment_one_more_segment
(since don't know how data left) - return
nil
, try again next packet
- set
- if found in middle:
- set
desegment_offset
offset of newline, next packet can tail data - set
desegment_len = desegment_one_more_segment
(since don't know how data left) - don't return
- set
- if found @ end, leave desegmentation params alone , carry on - whole line 1 line of data
- if didn't return, buffer 0 offset whole line of data - parse this
example:
function myproto.dissector(tvbuf, pinfo, treeitem) original_dissector:call(tvbuf, pinfo, treeitem) local endoffset = 0 -- find out if have complete chunks while endoffset < tvbuf:len() if tvbuf(endoffset, 1):uint() == 0x0d break end endoffset = endoffset + 1 end -- didn't find complete line in payload -- ask more if endoffset == tvbuf:len() pinfo.desegment_len = desegment_one_more_segment pinfo.desegment_offset = 0 print(' incomplete, ask more') return end -- have more needed set offset next dissection if tvbuf:len() - 1 > endoffset pinfo.desegment_len = desegment_one_more_segment pinfo.desegment_offset = offset print(' much, leave later') end print("whole line dissector:", tvbuf:len()) end
in example above (payload lengths 4, 3, 5), dissector called tvbuf
lengths of 4, 3, 5, when expected 4, 3, 8, last call containing left-over data previous packets.
i hit "incomplete, return" branch on second packet, third packet never changes.
this isn't happening, doing wrong?
side note: aware method above won't work in cases multiple \r
per line, think it's simpler lay out this question.
the reassembly functionality via setting desegment_offset
, desegment_length
depend on parent protocol. guess serial protocol runs on usb , indeed, usb protocol not implement reassembly usb packet/message based. (protocols tcp implement reassembly since logically stream of data.)
wireshark not expose reassembly api lua dissectors (still applicable in current development version, v2.3.0rc0), if using lua unfortunately have create variable dissector track previous data yourself.
Comments
Post a Comment