#225 removed redundant checks on remote address, added clarity to log messages
This commit is contained in:
17
rtu/rtu.lua
17
rtu/rtu.lua
@@ -341,8 +341,9 @@ function rtu.comms(version, modem, rtu_channel, svr_channel, range, conn_watchdo
|
||||
elseif rtu_state.linked and ((self.r_seq_num + 1) ~= packet.scada_frame.seq_num()) then
|
||||
log.warning("sequence out-of-order: last = " .. self.r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
|
||||
return
|
||||
elseif rtu_state.linked and src_addr ~= self.sv_addr then
|
||||
log.debug("received packet from unknown computer " .. src_addr .. " while linked; channel in use by another system?")
|
||||
elseif rtu_state.linked and (src_addr ~= self.sv_addr) then
|
||||
log.debug("received packet from unknown computer " .. src_addr .. " while linked (expected " .. self.sv_addr ..
|
||||
"); channel in use by another system?")
|
||||
return
|
||||
else
|
||||
self.r_seq_num = packet.scada_frame.seq_num()
|
||||
@@ -354,7 +355,7 @@ function rtu.comms(version, modem, rtu_channel, svr_channel, range, conn_watchdo
|
||||
-- handle packet
|
||||
if protocol == PROTOCOL.MODBUS_TCP then
|
||||
---@cast packet modbus_frame
|
||||
if rtu_state.linked and (src_addr == self.sv_addr) then
|
||||
if rtu_state.linked then
|
||||
local return_code ---@type boolean
|
||||
local reply ---@type modbus_packet
|
||||
|
||||
@@ -394,10 +395,8 @@ function rtu.comms(version, modem, rtu_channel, svr_channel, range, conn_watchdo
|
||||
end
|
||||
|
||||
public.send_modbus(reply)
|
||||
elseif not rtu_state.linked then
|
||||
log.debug("discarding MODBUS packet before linked")
|
||||
else
|
||||
log.debug("discarding MODBUS packet from different supervisor (src_addr " .. src_addr .. " ≠ " .. self.sv_addr .. ")")
|
||||
log.debug("discarding MODBUS packet before linked")
|
||||
end
|
||||
elseif protocol == PROTOCOL.SCADA_MGMT then
|
||||
---@cast packet mgmt_frame
|
||||
@@ -436,7 +435,7 @@ function rtu.comms(version, modem, rtu_channel, svr_channel, range, conn_watchdo
|
||||
else
|
||||
log.debug("SCADA_MGMT establish packet length mismatch")
|
||||
end
|
||||
elseif rtu_state.linked and (src_addr == self.sv_addr) then
|
||||
elseif rtu_state.linked then
|
||||
if packet.type == SCADA_MGMT_TYPE.KEEP_ALIVE then
|
||||
-- keep alive request received, echo back
|
||||
if packet.length == 1 and type(packet.data[1]) == "number" then
|
||||
@@ -466,10 +465,8 @@ function rtu.comms(version, modem, rtu_channel, svr_channel, range, conn_watchdo
|
||||
-- not supported
|
||||
log.debug("received unsupported SCADA_MGMT message type " .. packet.type)
|
||||
end
|
||||
elseif not rtu_state.linked then
|
||||
log.debug("discarding non-link SCADA_MGMT packet before linked")
|
||||
else
|
||||
log.debug("discarding non-link SCADA_MGMT packet from different supervisor (src_addr " .. src_addr .. " ≠ " .. self.sv_addr .. ")")
|
||||
log.debug("discarding non-link SCADA_MGMT packet before linked")
|
||||
end
|
||||
else
|
||||
-- should be unreachable assuming packet is from parse_packet()
|
||||
|
||||
Reference in New Issue
Block a user