From 429082dd71a00e7eb67efb6c8c20d0b95c532da1 Mon Sep 17 00:00:00 2001 From: Martin Kaiser Date: Sat, 6 Jul 2019 15:27:20 +0200 Subject: [PATCH] wslua: pinfo: make p2p_dir accessible to lua dissectors Some dissectors populate pinfo->p2p_dir with a packet's direction (incoming / outgoing). Make this info available to lua dissectors. Add a simple test for Pinfo's new p2p_dir attribute to the wslua test suite. It checks that p2p_dir is unknown for dhcp packets. (The dhcp dissector does not set p2p_dir). Change-Id: I8cc39a11cff840d10ef7fa94d30cbac8bf9b533f Reviewed-on: https://code.wireshark.org/review/33935 Reviewed-by: Peter Wu Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Martin Kaiser --- epan/wslua/template-init.lua | 6 ++++++ epan/wslua/wslua_pinfo.c | 3 +++ test/lua/pinfo.lua | 2 ++ 3 files changed, 11 insertions(+) diff --git a/epan/wslua/template-init.lua b/epan/wslua/template-init.lua index 197f1645d2..9293dcc0e1 100644 --- a/epan/wslua/template-init.lua +++ b/epan/wslua/template-init.lua @@ -106,6 +106,12 @@ end %MENU_GROUPS% +-- the possible values for Pinfo's p2p_dir attribute +P2P_DIR_UNKNOWN = -1 +P2P_DIR_SENT = 0 +P2P_DIR_RECV = 1 + + -- other useful constants -- DATA_DIR and USER_DIR have a trailing directory separator. GUI_ENABLED = gui_enabled() diff --git a/epan/wslua/wslua_pinfo.c b/epan/wslua/wslua_pinfo.c index 71b895c309..9b6974eab8 100644 --- a/epan/wslua/wslua_pinfo.c +++ b/epan/wslua/wslua_pinfo.c @@ -292,6 +292,8 @@ PINFO_ADDRESS_SETTER(src); PINFO_ADDRESS_GETTER(dst); PINFO_ADDRESS_SETTER(dst); +/* WSLUA_ATTRIBUTE Pinfo_p2p_dir RO direction of this Packet. (incoming / outgoing) */ +PINFO_NUMBER_GETTER(p2p_dir); /* WSLUA_ATTRIBUTE Pinfo_match RO Port/Data we are matching. */ static int Pinfo_get_match(lua_State *L) { @@ -457,6 +459,7 @@ WSLUA_ATTRIBUTES Pinfo_attributes[] = { WSLUA_ATTRIBUTE_ROREG(Pinfo,match_uint), WSLUA_ATTRIBUTE_ROREG(Pinfo,match_string), WSLUA_ATTRIBUTE_WOREG(Pinfo,conversation), + WSLUA_ATTRIBUTE_ROREG(Pinfo,p2p_dir), { NULL, NULL, NULL } }; diff --git a/test/lua/pinfo.lua b/test/lua/pinfo.lua index 4cc9f0b95d..9b8e47d67e 100644 --- a/test/lua/pinfo.lua +++ b/test/lua/pinfo.lua @@ -210,6 +210,8 @@ again, these *should* pass, but Pinfo silently allows it! test("Pinfo.desegment_len-get-1",pinfo.desegment_len == 0) test("Pinfo.desegment_offset-get-1",pinfo.desegment_offset == 0) + test("pinfo.p2p_dir", pinfo.p2p_dir == P2P_DIR_UNKNOWN) + if pinfo.number == 1 then test("Pinfo.rel_ts-get-1",pinfo.rel_ts == 0) test("Pinfo.delta_ts-get-1",pinfo.delta_ts == 0)