mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#225 removed redundant checks on remote address, added clarity to log messages
This commit is contained in:
parent
5ba06dcdaf
commit
15b071378c
@ -234,8 +234,9 @@ function pocket.comms(version, modem, pkt_channel, svr_channel, crd_channel, ran
|
||||
elseif self.connected and ((self.api.r_seq_num + 1) ~= packet.scada_frame.seq_num()) then
|
||||
log.warning("sequence out-of-order (API): last = " .. self.api.r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
|
||||
return
|
||||
elseif self.api.linked and self.api.addr ~= src_addr then
|
||||
log.debug("received API packet from unknown computer " .. src_addr .. " while linked; channel in use by another system?")
|
||||
elseif self.api.linked and (self.api.addr ~= src_addr) then
|
||||
log.debug("received packet from unknown computer " .. src_addr .. " while linked (API expected " .. self.api.addr ..
|
||||
"); channel in use by another system?")
|
||||
return
|
||||
else
|
||||
self.api.r_seq_num = packet.scada_frame.seq_num()
|
||||
@ -284,7 +285,7 @@ function pocket.comms(version, modem, pkt_channel, svr_channel, crd_channel, ran
|
||||
else
|
||||
log.debug("coordinator SCADA_MGMT establish packet length mismatch")
|
||||
end
|
||||
elseif self.api.linked and src_addr == self.api.addr then
|
||||
elseif self.api.linked then
|
||||
if packet.type == SCADA_MGMT_TYPE.KEEP_ALIVE then
|
||||
-- keep alive request received, echo back
|
||||
if packet.length == 1 then
|
||||
@ -311,10 +312,8 @@ function pocket.comms(version, modem, pkt_channel, svr_channel, crd_channel, ran
|
||||
else
|
||||
log.debug("received unknown SCADA_MGMT packet type " .. packet.type .. " from coordinator")
|
||||
end
|
||||
elseif not self.api.linked then
|
||||
log.debug("discarding coordinator non-link SCADA_MGMT packet before linked")
|
||||
else
|
||||
log.debug("discarding non-link SCADA_MGMT packet from different coordinator (src_addr " .. src_addr .. " ≠ " .. self.api.addr .. ")")
|
||||
log.debug("discarding coordinator non-link SCADA_MGMT packet before linked")
|
||||
end
|
||||
else
|
||||
log.debug("illegal packet type " .. protocol .. " from coordinator", true)
|
||||
@ -326,8 +325,9 @@ function pocket.comms(version, modem, pkt_channel, svr_channel, crd_channel, ran
|
||||
elseif self.connected and ((self.sv.r_seq_num + 1) ~= packet.scada_frame.seq_num()) then
|
||||
log.warning("sequence out-of-order (SVR): last = " .. self.sv.r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
|
||||
return
|
||||
elseif self.sv.linked and self.sv.addr ~= src_addr then
|
||||
log.debug("received SVR packet from unknown computer " .. src_addr .. " while linked; channel in use by another system?")
|
||||
elseif self.sv.linked and (self.sv.addr ~= src_addr) then
|
||||
log.debug("received packet from unknown computer " .. src_addr .. " while linked (SVR expected " .. self.sv.addr ..
|
||||
"); channel in use by another system?")
|
||||
return
|
||||
else
|
||||
self.sv.r_seq_num = packet.scada_frame.seq_num()
|
||||
@ -375,7 +375,7 @@ function pocket.comms(version, modem, pkt_channel, svr_channel, crd_channel, ran
|
||||
else
|
||||
log.debug("supervisor SCADA_MGMT establish packet length mismatch")
|
||||
end
|
||||
elseif self.sv.linked and (src_addr == self.sv.addr) then
|
||||
elseif self.sv.linked then
|
||||
if packet.type == SCADA_MGMT_TYPE.KEEP_ALIVE then
|
||||
-- keep alive request received, echo back
|
||||
if packet.length == 1 then
|
||||
@ -402,10 +402,8 @@ function pocket.comms(version, modem, pkt_channel, svr_channel, crd_channel, ran
|
||||
else
|
||||
log.debug("received unknown SCADA_MGMT packet type " .. packet.type .. " from supervisor")
|
||||
end
|
||||
elseif not self.sv.linked then
|
||||
log.debug("discarding supervisor non-link SCADA_MGMT packet before linked")
|
||||
else
|
||||
log.debug("discarding non-link SCADA_MGMT from different supervisor (src_addr " .. src_addr .. " ≠ " .. self.sv.addr .. ")")
|
||||
log.debug("discarding supervisor non-link SCADA_MGMT packet before linked")
|
||||
end
|
||||
else
|
||||
log.debug("illegal packet type " .. protocol .. " from supervisor", true)
|
||||
|
@ -17,7 +17,7 @@ local coreio = require("pocket.coreio")
|
||||
local pocket = require("pocket.pocket")
|
||||
local renderer = require("pocket.renderer")
|
||||
|
||||
local POCKET_VERSION = "alpha-v0.4.3"
|
||||
local POCKET_VERSION = "alpha-v0.4.4"
|
||||
|
||||
local println = util.println
|
||||
local println_ts = util.println_ts
|
||||
|
@ -790,8 +790,9 @@ function plc.comms(id, version, modem, plc_channel, svr_channel, range, reactor,
|
||||
elseif self.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 self.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 self.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()
|
||||
@ -804,7 +805,7 @@ function plc.comms(id, version, modem, plc_channel, svr_channel, range, reactor,
|
||||
if protocol == PROTOCOL.RPLC then
|
||||
---@cast packet rplc_frame
|
||||
-- if linked, only accept packets from configured supervisor
|
||||
if self.linked and (self.sv_addr == src_addr) then
|
||||
if self.linked then
|
||||
if packet.type == RPLC_TYPE.STATUS then
|
||||
-- request of full status, clear cache first
|
||||
self.status_cache = nil
|
||||
@ -935,15 +936,13 @@ function plc.comms(id, version, modem, plc_channel, svr_channel, range, reactor,
|
||||
else
|
||||
log.debug("received unknown RPLC packet type " .. packet.type)
|
||||
end
|
||||
elseif not self.linked then
|
||||
log.debug("discarding RPLC packet before linked")
|
||||
else
|
||||
log.debug("discarding RPLC packet from different supervisor (src_addr " .. src_addr .. " ≠ " .. self.sv_addr .. ")")
|
||||
log.debug("discarding RPLC packet before linked")
|
||||
end
|
||||
elseif protocol == PROTOCOL.SCADA_MGMT then
|
||||
---@cast packet mgmt_frame
|
||||
-- if linked, only accept packets from configured supervisor
|
||||
if self.linked and (self.sv_addr == src_addr) then
|
||||
if self.linked then
|
||||
if packet.type == SCADA_MGMT_TYPE.ESTABLISH then
|
||||
-- link request confirmation
|
||||
if (packet.length == 1) and (self.sv_addr == src_addr) then
|
||||
@ -1057,10 +1056,8 @@ function plc.comms(id, version, modem, plc_channel, svr_channel, range, reactor,
|
||||
else
|
||||
log.debug("SCADA_MGMT establish packet length mismatch")
|
||||
end
|
||||
elseif not self.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()
|
||||
|
@ -18,7 +18,7 @@ local plc = require("reactor-plc.plc")
|
||||
local renderer = require("reactor-plc.renderer")
|
||||
local threads = require("reactor-plc.threads")
|
||||
|
||||
local R_PLC_VERSION = "v1.4.4"
|
||||
local R_PLC_VERSION = "v1.4.5"
|
||||
|
||||
local println = util.println
|
||||
local println_ts = util.println_ts
|
||||
|
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()
|
||||
|
@ -28,7 +28,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
|
||||
local sps_rtu = require("rtu.dev.sps_rtu")
|
||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||
|
||||
local RTU_VERSION = "v1.3.4"
|
||||
local RTU_VERSION = "v1.3.5"
|
||||
|
||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
||||
local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE
|
||||
|
Loading…
Reference in New Issue
Block a user