Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------------------
- -- Checkpoint Orchestrator Post-Dissector --
- ------------------------------------------------------------------------------
- -- --
- -- Copyright: Allan Que, 2023 --
- -- License : GPL-3.0-or-later --
- -- see http://www.gnu.org/licenses/gpl.html --
- -- --
- ------------------------------------------------------------------------------
- -- --
- -- Copy file to your Personal Plugins directory --
- -- See Help > About > Folders for paths --
- -- --
- ------------------------------------------------------------------------------
- local mho_info = {
- version = "1.1",
- author = "Allan Que",
- description = "Calculates which Check Point Orchestrator handled each"..
- " frame. Capture file must come from $SMODIR/bin/g_tcpdump (Expert"..
- " mode) to have correct values.",
- }
- set_plugin_info(mho_info)
- -- Access frame.time field (NSTime type)
- local frame_t_f = Field.new("frame.time")
- -- Define new MHO protocol
- local mho_p = Proto("mho", "Check Point Orchestrator")
- local name_s = mho_p.name:lower()
- -- Fields under protocol. These appear in the tree.
- local mho_ch_field = ProtoField.uint8(name_s..".chassis", "Chassis", base.DEC)
- local mho_bl_field = ProtoField.uint8(name_s..".blade", "Blade", base.DEC)
- local mho_id_field = ProtoField.string(name_s..".id", "Id", base.ASCII)
- -- Calculate items and add them to protocol tree
- function mho_p.dissector(buffer, pinfo, tree)
- -- Retrieve timestamp from frame
- local frame_time_fld = frame_t_f()
- if not mho_p.prefs.enabled or frame_time_fld == nil then
- return
- end
- -- Extract frame sub-second timestamp
- local subsec_f = frame_time_fld.value:tonumber() % 1 * 1000000
- -- Calculate integer value. Handle rounding if necessary
- local subsec_i = math.floor(subsec_f + 0.5)
- -- Chassis and Blade calculations are from
- -- $SMODIR/bin/gtcpdump-helper.sh
- local mho_ch = bit.rshift(bit.band(subsec_i, 16), 4) + 1
- local mho_bl = bit.band(subsec_i, 15)
- -- Add items to the tree
- local mho_id = mho_ch..'_'..mho_bl
- local mho_tree = tree:add(mho_p, mho_p.description..", Id: "..mho_id)
- mho_tree:set_generated()
- mho_tree:add(mho_ch_field, mho_ch):set_generated()
- mho_tree:add(mho_bl_field, mho_bl):set_generated()
- mho_tree:add(mho_id_field, mho_id):set_generated()
- -- Append extracted blade id to the Info column, if enabled
- if mho_p.prefs.append_info then
- pinfo.cols.info:append(" "..mho_p.name.."="..mho_id)
- end
- end
- -- Link fields to protocol
- mho_p.fields = { mho_ch_field, mho_bl_field, mho_id_field }
- -- Set default states to DISABLED - only enable when user requested
- mho_p.prefs.enabled = Pref.bool("Extract blade id from g_tcpdump", false,
- "Extract blade id information from g_tcpdump packet captures")
- mho_p.prefs.append_info = Pref.bool("Append blade id to Info column", false,
- "Append extracted blade id to the Info output column")
- mho_p.prefs.save_prefs = Pref.bool("Save preferences on menu bar click (GUI only)", false,
- "Save preferences when using menu bar to enable/disable")
- -- Register protocol as a new post-dissector
- register_postdissector(mho_p)
- -- Add menu item if running on 3.5 and later GUI
- -- set_preference() is only available on 3.5 and later versions
- -- Use Preferences > Protocol for older versions
- -- tshark uses "-o mho.enabled:true -o mho.append_info:true" parameters
- if not (gui_enabled() and set_preference) then return end
- local function invert_enabled()
- -- Read current enabled preference and store inverted value
- local enabled_b = mho_p.prefs.enabled
- set_preference(name_s..".enabled", not enabled_b)
- -- User decides if menu bar triggers a save of preferences to file
- if mho_p.prefs.save_prefs then
- apply_preferences()
- end
- -- Rerun post dissection tasks
- --
- -- Note 1: Wireshark has a bug where the displayed protocol tree is not
- -- updated. Briefly select another packet and switch back
- -- to redraw tree.
- --
- -- Note 2: retap_packets() is faster than reload() but does not dissect
- -- packets again. Info column is not updated and could still
- -- contain "MHO=" data. Press Ctrl-R to perform a reload().
- retap_packets()
- end
- register_menu("MHO Blade Id", invert_enabled, MENU_TOOLS_UNSORTED)
Advertisement