Skip to content

Commit 0c2080b

Browse files
authored
Fix registration (#5)
Managing modules load order using require doesn't always work (especially when installing the plugin globally. It is better to register subprotocols in init() function which is called when every module is registered.
1 parent 867fc5f commit 0c2080b

File tree

4 files changed

+56
-48
lines changed

4 files changed

+56
-48
lines changed

.luacheckrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ stds.wireshark = {
1212
"ProtoField",
1313
"base",
1414
"ftypes",
15+
"package",
16+
"set_plugin_info",
1517
}
1618
}

rls-3-1.lua renamed to protocol/rls-3-1.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
-- CC0-1.0 2021 - Louis Royer (<https://github.com/louisroyer/RLS-wireshark-dissector>)
77
--
88
--]]
9-
require("rls")
10-
119
local rlsProtocol31 = Proto("RLS-3.1", "UERANSIM 3.1.x Radio Link Simulation (RLS) Protocol")
1210
local fields = rlsProtocol31.fields
1311

@@ -128,7 +126,9 @@ function rlsProtocol31.dissector(buffer, pinfo, tree)
128126
end
129127
end
130128

131-
local rls = DissectorTable.get("rls")
132-
rls:add(0x0301, rlsProtocol31)
133-
local udp_port = DissectorTable.get("udp.port")
134-
udp_port:add_for_decode_as(rlsProtocol31)
129+
function rlsProtocol31.init()
130+
local rls = DissectorTable.get("rls")
131+
rls:add(0x0301, rlsProtocol31)
132+
local udp_port = DissectorTable.get("udp.port")
133+
udp_port:add_for_decode_as(rlsProtocol31)
134+
end

rls-3-2.lua renamed to protocol/rls-3-2.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
-- CC0-1.0 2021 - Louis Royer (<https://github.com/louisroyer/RLS-wireshark-dissector>)
77
--
88
--]]
9-
require("rls")
10-
119
local rlsProtocol32 = Proto("RLS-3.2", "UERANSIM 3.2.x Radio Link Simulation (RLS) Protocol")
1210
local fields = rlsProtocol32.fields
1311

@@ -124,7 +122,9 @@ function rlsProtocol32.dissector(buffer, pinfo, tree)
124122
end
125123
end
126124

127-
local rls = DissectorTable.get("rls")
128-
rls:add(0x0302, rlsProtocol32)
129-
local udp_port = DissectorTable.get("udp.port")
130-
udp_port:add_for_decode_as(rlsProtocol32)
125+
function rlsProtocol32.init()
126+
local rls = DissectorTable.get("rls")
127+
rls:add(0x0302, rlsProtocol32)
128+
local udp_port = DissectorTable.get("udp.port")
129+
udp_port:add_for_decode_as(rlsProtocol32)
130+
end

rls.lua

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,59 @@
77
--
88
--]]
99

10-
-- This file must only be loaded once, but each version requires it.
11-
if package.loaded['rls'] == nil then
12-
-- Update the following when adding new versions
13-
local latestVersion = 0x0302
14-
local oldestVersion = 0x0301
10+
local pluginVersion = "1.1.1"
11+
-- Update the following when adding new versions
12+
local latestVersion = 0x0302
13+
local oldestVersion = 0x0301
1514

16-
local rlsProtocol = Proto("RLS", "UERANSIM Radio Link Simulation (RLS) Protocol")
15+
local rlsProtocol = Proto("RLS", "UERANSIM Radio Link Simulation (RLS) Protocol")
16+
set_plugin_info({
17+
version = pluginVersion,
18+
author = "Louis Royer",
19+
repository = "https://github.com/louisroyer/RLS-wireshark-dissector",
20+
description = "Dissector for Radio Link Simulation Protocol"
21+
})
1722

18-
-- Create a DissectorTable to register dissector for each version of RLS
19-
DissectorTable.new("rls", "RLS version", ftypes.UINT32, base.HEX, rlsProtocol)
23+
-- Create a DissectorTable to register dissector for each version of RLS
24+
DissectorTable.new("rls", "RLS version", ftypes.UINT32, base.HEX, rlsProtocol)
2025

21-
-- Preferences
22-
rlsProtocol.prefs.udp_port = Pref.uint("RLS UDP port", 4997, "UDP port for RLS")
26+
-- Preferences
27+
rlsProtocol.prefs.udp_port = Pref.uint("RLS UDP port", 4997, "UDP port for RLS")
2328

24-
-- Add version field
25-
local fields = rlsProtocol.fields
26-
fields.Version = ProtoField.string("rls.version", "Version")
29+
-- Add version field
30+
local fields = rlsProtocol.fields
31+
fields.Version = ProtoField.string("rls.version", "Version")
2732

28-
function rlsProtocol.dissector(buffer, pinfo, tree)
29-
-- Generic check
30-
if buffer:len() == 0 then return end
31-
if buffer(0, 1):uint() ~= 0x03 then return end
33+
function rlsProtocol.dissector(buffer, pinfo, tree)
34+
-- Generic check
35+
if buffer:len() == 0 then return end
36+
if buffer(0, 1):uint() ~= 0x03 then return end
3237

33-
pinfo.cols.protocol = rlsProtocol.name
38+
pinfo.cols.protocol = rlsProtocol.name
3439

35-
local version = buffer(1,2):uint()
36-
local subprotocol = DissectorTable.get("rls"):get_dissector(version)
40+
local version = buffer(1,2):uint()
41+
local subprotocol = DissectorTable.get("rls"):get_dissector(version)
42+
if subprotocol == nil then
43+
if version > latestVersion then
44+
-- fallback to latest version
45+
version = latestVersion
46+
elseif version < oldestVersion then
47+
-- fallback to oldest version
48+
version = oldestVersion
49+
end
50+
subprotocol = DissectorTable.get("rls"):get_dissector(version)
3751
if subprotocol == nil then
38-
if version > latestVersion then
39-
-- fallback to latest version
40-
version = latestVersion
41-
elseif version < oldestVersion then
42-
-- fallback to oldest version
43-
version = oldestVersion
44-
end
45-
subprotocol = DissectorTable.get("rls"):get_dissector(version)
46-
if subprotocol == nil then
47-
local versionNumber = buffer(1, 1):uint() .. "." .. buffer(2, 1):uint() .. "." .. buffer(3, 1):uint()
48-
local subtree = tree:add(rlsProtocol, buffer(), "UERANSIM Radio Link Simulation (RLS) protocol")
49-
pinfo.cols.info = "Unsupported version - Cannot decode"
50-
subtree:add(fields.Version, buffer(1, 3), versionNumber)
51-
return 4
52-
end
52+
local versionNumber = buffer(1, 1):uint() .. "." .. buffer(2, 1):uint() .. "." .. buffer(3, 1):uint()
53+
local subtree = tree:add(rlsProtocol, buffer(), "UERANSIM Radio Link Simulation (RLS) protocol")
54+
pinfo.cols.info = "Unsupported version - Cannot decode"
55+
subtree:add(fields.Version, buffer(1, 3), versionNumber)
56+
return 4
5357
end
54-
subprotocol:call(buffer():tvb(), pinfo, tree)
5558
end
59+
subprotocol:call(buffer():tvb(), pinfo, tree)
60+
end
5661

62+
function rlsProtocol.init()
5763
-- Export protocol
5864
local udp_port = DissectorTable.get("udp.port")
5965
udp_port:add(rlsProtocol.prefs.udp_port, rlsProtocol)

0 commit comments

Comments
 (0)