add MIRROR_TRAFFIC, prevent packet duplicating in data_gateway

This commit is contained in:
KF7EEL 2021-09-08 11:27:30 -07:00
parent 6541aa61b6
commit 19db51b1f6
3 changed files with 33 additions and 13 deletions

View File

@ -348,14 +348,14 @@ def svrd_send_all(_svrd_data):
systems[system].send_system(_svrd_packet + _svrd_data)
# Send any data packets to connections with ALL_DATA specified in other options
def all_data(_data):
def mirror_traffic(_data):
for system in CONFIG['SYSTEMS']:
if CONFIG['SYSTEMS'][system]['ENABLED']:
if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE':
print(CONFIG['SYSTEMS'][system]['OTHER_OPTIONS'])
if 'ALL_DATA' in CONFIG['SYSTEMS'][system]['OTHER_OPTIONS']:
if 'MIRROR_TRAFFIC' in CONFIG['SYSTEMS'][system]['OTHER_OPTIONS']:
print('mirrored to ' + system)
print(SVRD + b'DATA' + _data)
print(_data)
systems[system].send_system(SVRD + b'DATA' + _data)
@ -1372,19 +1372,20 @@ class routerHBP(HBSYSTEM):
def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data):
if _call_type == 'group':
self.group_received(_peer_id, _rf_src, _dst_id, _seq, _slot, _frame_type, _dtype_vseq, _stream_id, _data)
## all_data(_data)
mirror_traffic(_data)
elif _call_type == 'unit':
if self._system not in UNIT:
logger.error('(%s) *UNIT CALL NOT FORWARDED* UNIT calling is disabled for this system (INGRESS)', self._system)
else:
self.unit_received(_peer_id, _rf_src, _dst_id, _seq, _slot, _frame_type, _dtype_vseq, _stream_id, _data)
## all_data(_data)
mirror_traffic(_data)
elif _call_type == 'vcsbk':
self.group_received(_peer_id, _rf_src, _dst_id, _seq, _slot, _frame_type, _dtype_vseq, _stream_id, _data)
logger.debug('CSBK recieved, forwarded to destination TG.')
## all_data(_data)
mirror_traffic(_data)
else:
logger.error('Unknown call type recieved -- not processed')
mirror_traffic(_data)
#
# Socket-based reporting section

View File

@ -112,6 +112,7 @@ hdr_type = ''
btf = -1
ssid = ''
UNIT_MAP = {}
PACKET_MATCH = {}
# From dmr_utils3, modified to decode entire packet. Works for 1/2 rate coded data.
def decode_full(_data):
@ -1201,8 +1202,19 @@ class OBP(OPENBRIDGE):
def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data):
UNIT_MAP[_rf_src] = (self._system, time())
print('OBP RCVD')
data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data)
# Check to see if we have already received this packet
if _data == PACKET_MATCH[_rf_src][0] and time() - PACKET_MATCH[_rf_src][1] < 1:
print('matched, dropping')
pass
print(PACKET_MATCH)
else:
PACKET_MATCH[_rf_src] = [_data, time()]
print('OBP RCVD')
if _dtype_vseq in [3,6,7] and _call_type == 'unit' or _call_type == 'group' and _dtype_vseq == 6 or _call_type == 'vcsbk':
data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data)
else:
pass
def svrd_received(self, _mode, _data):
print('SVRD RCV')
@ -1210,7 +1222,7 @@ class OBP(OPENBRIDGE):
UNIT_MAP[_data] = (self._system, time())
print(UNIT_MAP)
if _mode == b'DATA':
# DMR Data packet, sent via SVRD
# DMR Data packet, sent via SVRD
_peer_id = _data[11:15]
_seq = _data[4]
_rf_src = _data[5:8]
@ -1228,8 +1240,11 @@ class OBP(OPENBRIDGE):
_dtype_vseq = (_bits & 0xF) # data, 1=voice header, 2=voice terminator; voice, 0=burst A ... 5=burst F
_stream_id = _data[16:20]
# Record last packet to prevent duplicates, think finger printing.
PACKET_MATCH[_rf_src] = [_data, time()]
self.dmrd_received(_peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data)
pass
@ -1241,7 +1256,10 @@ class HBP(HBSYSTEM):
def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data):
UNIT_MAP[_rf_src] = (self._system, time())
print('MMDVM RCVD')
data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data)
if _dtype_vseq in [3,6,7] and _call_type == 'unit' or _call_type == 'group' and _dytpe_vseq == 6 or _call_type == 'vcsbk':
data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data)
else:
pass
## pass

View File

@ -159,7 +159,7 @@ class OPENBRIDGE(DatagramProtocol):
logger.info('(%s) is mode OPENBRIDGE. No De-Registration required, continuing shutdown', self._system)
def send_system(self, _packet):
if _packet[:4] == DMRD or _packet[:4] == EOBP:
if _packet[:4] == DMRD or _packet[:4] == EOBP or _packet[:4] == b'NOCK':
#_packet = _packet[:11] + self._config['NETWORK_ID'] + _packet[15:]
_packet = b''.join([_packet[:11], self._config['NETWORK_ID'], _packet[15:]])
#_packet += hmac_new(self._config['PASSPHRASE'],_packet,sha1).digest()
@ -257,7 +257,8 @@ class OPENBRIDGE(DatagramProtocol):
if not _sockaddr == self._config['TARGET_SOCK']:
logger.info('(%s) OpenBridge socket mismatch, packet discarded - OPCODE: %s DATA: %s ', self._system, _packet[:4], repr(_packet[:53]))
# Server Data packet, decrypt and process it.
elif _packet[:4] == SVRD:
_d_pkt = decrypt_packet(self._config['ENCRYPTION_KEY'], _packet[4:])