Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is it possible to have a Lua Dissector in between built-in C-dissectors?

Yes. Lua dissectors can invoke built-in dissectors and vice versa.

how can I bind a built-in dissector to the output of my lua dissector?

By fetching a reference to it and calling it as any other function from your Lua code, passing it the same parameters which any dissector expects.

I plan to have Lua reverse the wire-bit/byte order to the expected litte-endian bit/byte order of all IETF described fields

And this is the part which is not obvious. No dissector can modify the contents of the frame, it is read-only. So in your Lua dissector, you have to create a new tvb structure, containing a reordered copy of the original tvb, and feed the iWARP dissector with a link to this structure instead of the original tvb. The result will be similar to how the whole http message is shown in the last one of the TCP segments carrying it - the packet bytes pane will contain only the rearranged bytes, and the packet dissection pane will show the full tree including the iWARP part of it. It would look approximately like below - not tested, just a rough idea quickly extracted from a remotely similar scenario:

...
my origDissector = dissector.get("iwarp") -- or what is the dissector/protocol name
...

function MyAuxProto.dissector(buffer,pinfo,tree)
    local MyArray = ByteArray.new("00")
    MyArray:set_size(buffer.len())
    -- now fill MyArray with a byte-reordered copy of buffer
    local MyTvb = ByteArray.tvb(MyArray,"reorderedBytes")
    return origDissector(MyTvb,pinfo,tree)
end

Is it possible to have a Lua Dissector in between built-in C-dissectors?

Yes. Lua dissectors can invoke built-in dissectors and vice versa.

how can I bind a built-in dissector to the output of my lua dissector?

By fetching a reference to it and calling it as any other function from your Lua code, passing it the same parameters which any dissector expects.

I plan to have Lua reverse the wire-bit/byte order to the expected litte-endian bit/byte order of all IETF described fields

And this is the part which is not obvious. No dissector can modify the contents of the frame, it is read-only. So in your Lua dissector, you have to create a new tvb structure, containing a reordered copy of the original tvb, and feed the iWARP dissector with a link to this structure instead of the original tvb. The result will be similar to how the whole http dissection of a complete HTTP message is shown in the dissection three of the last one of the TCP segments carrying it - the packet bytes pane will contain another tab with only the rearranged bytes, bytes in it, and the packet dissection pane will show the full tree including the iWARP part of it. It Your inserted dissector would look approximately like below - not tested, just a rough idea quickly extracted from a remotely similar scenario:

...
my origDissector = dissector.get("iwarp") -- or what is the dissector/protocol name
-- as you are going to replace the original dissector by your intermediate one
-- in the dissector table of the underlying layer's dissector, you may as well fetch
-- the link to the original dissector from that dissector table of the underlying layer
-- before replacing it with your own one - in such case you don't need to know the name
...

function MyAuxProto.dissector(buffer,pinfo,tree)
    local MyArray = ByteArray.new("00")
    MyArray:set_size(buffer.len())
    -- now fill MyArray with a byte-reordered copy of buffer
    local MyTvb = ByteArray.tvb(MyArray,"reorderedBytes")
    return origDissector(MyTvb,pinfo,tree)
end

Is it possible to have a Lua Dissector in between built-in C-dissectors?

Yes. Lua dissectors can invoke built-in dissectors and vice versa.

how can I bind a built-in dissector to the output of my lua dissector?

By fetching a reference to it and calling it as any other function from your Lua code, passing it the same parameters which any dissector expects.

I plan to have Lua reverse the wire-bit/byte order to the expected litte-endian bit/byte order of all IETF described fields

And this is the part which is not obvious. No dissector can modify the contents of the frame, it is read-only. So in your Lua dissector, you have to create a new tvb structure, containing a reordered copy of the original tvb, and feed the iWARP dissector with a link to this structure instead of the original tvb. The result will be similar to how the dissection of a complete HTTP message is shown in the dissection three of the last one of the TCP segments carrying it - the packet bytes pane will contain another tab with only the rearranged bytes in it, and the packet dissection pane will show the full tree including the iWARP part of it. Your inserted dissector would look approximately like below - not tested, just a rough idea quickly extracted from a remotely similar scenario:

...
my origDissector = dissector.get("iwarp") -- or what is the dissector/protocol name
-- as you are going to replace the original dissector by your intermediate one
-- in the dissector table of the underlying layer's dissector, you may as well fetch
-- the link to the original dissector from that dissector table of the underlying layer
-- before replacing it it
-- with your own one - in such case you don't need to know the name
...

function MyAuxProto.dissector(buffer,pinfo,tree)
    local MyArray = ByteArray.new("00")
    MyArray:set_size(buffer.len())
    -- now fill MyArray with a byte-reordered copy of buffer
    local MyTvb = ByteArray.tvb(MyArray,"reorderedBytes")
    return origDissector(MyTvb,pinfo,tree)
end

Is it possible to have a Lua Dissector in between built-in C-dissectors?

Yes. Lua dissectors can invoke built-in dissectors and vice versa.

how can I bind a built-in dissector to the output of my lua dissector?

By fetching a reference to it and calling it as any other function from your Lua code, passing it the same parameters which any dissector expects.

I plan to have Lua reverse the wire-bit/byte order to the expected litte-endian bit/byte order of all IETF described fields

And this is the part which is not obvious. No dissector can modify the contents of the frame, it is read-only. So in your Lua dissector, you have to create a new tvb structure, containing a reordered copy of the original tvb, and feed the iWARP dissector with a link to this structure instead of the original tvb. The result will be similar to how the dissection of a complete HTTP message is shown in the dissection three of the last one of the TCP segments carrying it - the packet bytes pane will contain another tab with only the rearranged bytes in it, and the packet dissection pane will show the full tree including the iWARP part of it. Your inserted dissector would look approximately like below - not tested, just a rough idea quickly extracted from a remotely similar scenario:

...
my origDissector = dissector.get("iwarp") -- or what is the dissector/protocol name
-- as you are going to replace the original dissector by your intermediate one
-- in the dissector table of the underlying layer's layer\'s dissector, you may as well fetch
-- the link to the original dissector from that dissector table before replacing it
-- with your own one - in such case you don't don\'t need to know the name
...

function MyAuxProto.dissector(buffer,pinfo,tree)
    local MyArray = ByteArray.new("00")
    MyArray:set_size(buffer.len())
    -- now fill MyArray with a byte-reordered copy of buffer
    local MyTvb = ByteArray.tvb(MyArray,"reorderedBytes")
    return origDissector(MyTvb,pinfo,tree)
end