Ask Your Question
0

How to call the original dissector in chained dissectors?

asked 2019-02-19 15:33:22 +0000

L. Qin gravatar image

I'm working on a Lua Dissector for my own arp protocol.

do
    local arp_wrap_proto = Proto("arp_extra", "Extra ARP Protocol");


    local original_arp_dis 
    function arp_wrap_proto.dissector(buf, pinfo, tree)
        if 10 == buf(0, 1):uint() then
            pinfo.cols.protocol = "Extra ARP"
            -- do smt
        else
            -- Original ARP 
            original_arp_dis:call(buf, pinfo, tree)
        end
    end

    local arp_dis_table = DissectorTable.get("ethertype")
    original_arp_dis = arp_dis_table:get_dissector(2054)
    arp_dis_table:add(2054, arp_wrap_proto)
end

I want to use my own dissector for buf(0,1) == 10,

other conditions, try to call the original dissector for ARP.

But I got this ERROR: lua:12: attempt to index upvalue 'original_arp_dis' (a nil value)

How can I get it work?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-02-19 16:49:26 +0000

cmaynard gravatar image

You need to set the handle before the function. Try:

do
    local arp_wrap_proto = Proto("arp_extra", "Extra ARP Protocol");

    local original_arp_dis = Dissector.get("arp")
    function arp_wrap_proto.dissector(buf, pinfo, tree)
        if 10 == buf(0, 1):uint() then
            pinfo.cols.protocol = "Extra ARP"
            -- do smt
        else
            -- Original ARP 
            original_arp_dis:call(buf, pinfo, tree)
        end
    end

    local arp_dis_table = DissectorTable.get("ethertype")
    arp_dis_table:add(2054, arp_wrap_proto)
end

Or you can use your original method for obtaining the original_arp_dis handle, but you need to move the following 2 lines before the function:

local arp_dis_table = DissectorTable.get("ethertype")
local original_arp_dis = arp_dis_table:get_dissector(2054)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-02-19 15:33:22 +0000

Seen: 1,651 times

Last updated: Feb 19 '19