Wireshark-bugs: [Wireshark-bugs] [Bug 10695] Lua Proto:register_heuristic should accept Dissecto

Date: Mon, 29 Dec 2014 00:36:45 +0000

Comment # 6 on bug 10695 from
(In reply to Matthijs Kooijman from comment #4)
> > Because your lambda function doesn't return anything.  If your
> > foo.dissector() returns true/false, then your lambda should be:
> >
> >     function(...) return foo.dissector(...) end
> 
> Ah, that was just an oversight while minimizing my example for the bug
> report - I had already tested with the return statement in my original
> code. Just to confirm, I just tested this:
> 
> 	local foo = Proto("foo", "Foo dissector")
> 
> 	function foo.dissector(tvb, pinfo, tree)
> 		return true;
> 	end
> 
> 	foo:register_heuristic("wpan", function(...) return foo.dissector(...) end)
> 
> Which doesn't affect wpan packet parsing in any way.

Did your `foo.dissector(...)` return true?


> This is contrast
> with:
> 
> 	foo:register_heuristic("wpan", function(...) return true; end)
> 
> Which should be exactly equivalent, but leaves all wpan packets
> unparsed.

Well sure, because the lambda function didn't actually parse/tree-add anything.


> > Or, you could instead simply separately create a Lua function that
> > that does what you want, and then set both the Proto's dissector and
> > register the heuristic to that Lua function.  For example:
> 
> Yeah, that's what I ended up doing. However, I spent quite some time
> figuring out the unexpected stuff in the API before I ended up at this
> solution - it would be useful if things worked more as you'd expect to
> save others from going through the same in the future.

We're kinda constrained to following how the C-code behaves. For example the
C-code heuristic dissectors do the parsing/tree-add stuff and return true or
false, and that's what every C-code protocol expects them to do. For example
when the UDP protocol C-code calls its table of registered heuristic functions
(heuristic dissectors of upper-layer protocols that use UDP transport), it
expects that the called heuristic dissector will either return false to mean
the packet wasn't for it, or true to mean it was for it and that it parsed it.

I could let the Lua register_heuristic() function accept a Dissector object as
well, instead of only a Lua function; and then later when it's invoked, then if
the called Dissector returned 0 it would mean false, and if it's a different
number then it means true.


You are receiving this mail because:
  • You are watching all bug changes.