mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#488 fixes to sequence number changes and auth packet data
This commit is contained in:
@ -525,6 +525,7 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
|
||||
local self = {
|
||||
sv_addr = comms.BROADCAST,
|
||||
seq_num = util.time_ms() * 10, -- unique per peer, restarting will not re-use seq nums due to message rate
|
||||
r_seq_num = nil, ---@type nil|integer
|
||||
scrammed = false,
|
||||
linked = false,
|
||||
last_est_ack = ESTABLISH_ACK.ALLOW,
|
||||
@ -715,6 +716,7 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
|
||||
self.sv_addr = comms.BROADCAST
|
||||
self.linked = false
|
||||
self.status_cache = nil
|
||||
self.r_seq_num = nil
|
||||
databus.tx_link_state(types.PANEL_LINK_STATE.DISCONNECTED)
|
||||
end
|
||||
|
||||
@ -822,15 +824,17 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
|
||||
-- handle packets now that we have prints setup
|
||||
if l_chan == config.PLC_Channel then
|
||||
-- check sequence number
|
||||
if self.seq_num ~= packet.scada_frame.seq_num() then
|
||||
log.warning("sequence out-of-order: last = " .. self.seq_num .. ", new = " .. packet.scada_frame.seq_num())
|
||||
if self.r_seq_num == nil then
|
||||
self.r_seq_num = packet.scada_frame.seq_num() + 1
|
||||
elseif self.r_seq_num ~= 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 (expected " .. self.sv_addr ..
|
||||
"); channel in use by another system?")
|
||||
return
|
||||
else
|
||||
self.seq_num = packet.scada_frame.seq_num() + 1
|
||||
self.r_seq_num = packet.scada_frame.seq_num() + 1
|
||||
end
|
||||
|
||||
-- feed the watchdog first so it doesn't uhh...eat our packets :)
|
||||
|
Reference in New Issue
Block a user