1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-07-19 00:35:16 -04:00

Trap for failed parsing of packets on KISS

This adds a try block around the aprslib.parse() for packets incoming
on the KISS interface.  Often times we'll get invalid packets and
this prevents stack dumps to the log.
This commit is contained in:
Hemna 2025-01-24 17:44:58 -05:00
parent edeba7f514
commit 9501a63bd6

View File

@ -12,7 +12,7 @@ from aprsd.client.drivers import kiss
from aprsd.packets import core from aprsd.packets import core
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger("APRSD") LOG = logging.getLogger('APRSD')
LOGU = logger LOGU = logger
@ -27,15 +27,15 @@ class KISSClient(base.APRSClient):
if serializable: if serializable:
keepalive = keepalive.isoformat() keepalive = keepalive.isoformat()
stats = { stats = {
"connected": self.is_connected, 'connected': self.is_connected,
"connection_keepalive": keepalive, 'connection_keepalive': keepalive,
"transport": self.transport(), 'transport': self.transport(),
} }
if self.transport() == client.TRANSPORT_TCPKISS: if self.transport() == client.TRANSPORT_TCPKISS:
stats["host"] = CONF.kiss_tcp.host stats['host'] = CONF.kiss_tcp.host
stats["port"] = CONF.kiss_tcp.port stats['port'] = CONF.kiss_tcp.port
elif self.transport() == client.TRANSPORT_SERIALKISS: elif self.transport() == client.TRANSPORT_SERIALKISS:
stats["device"] = CONF.kiss_serial.device stats['device'] = CONF.kiss_serial.device
return stats return stats
@staticmethod @staticmethod
@ -56,15 +56,15 @@ class KISSClient(base.APRSClient):
transport = KISSClient.transport() transport = KISSClient.transport()
if transport == client.TRANSPORT_SERIALKISS: if transport == client.TRANSPORT_SERIALKISS:
if not CONF.kiss_serial.device: if not CONF.kiss_serial.device:
LOG.error("KISS serial enabled, but no device is set.") LOG.error('KISS serial enabled, but no device is set.')
raise exception.MissingConfigOptionException( raise exception.MissingConfigOptionException(
"kiss_serial.device is not set.", 'kiss_serial.device is not set.',
) )
elif transport == client.TRANSPORT_TCPKISS: elif transport == client.TRANSPORT_TCPKISS:
if not CONF.kiss_tcp.host: if not CONF.kiss_tcp.host:
LOG.error("KISS TCP enabled, but no host is set.") LOG.error('KISS TCP enabled, but no host is set.')
raise exception.MissingConfigOptionException( raise exception.MissingConfigOptionException(
"kiss_tcp.host is not set.", 'kiss_tcp.host is not set.',
) )
return True return True
@ -91,8 +91,8 @@ class KISSClient(base.APRSClient):
if ka := self._client.aprsd_keepalive: if ka := self._client.aprsd_keepalive:
keepalive = timeago.format(ka) keepalive = timeago.format(ka)
else: else:
keepalive = "N/A" keepalive = 'N/A'
LOGU.opt(colors=True).info(f"<green>Client keepalive {keepalive}</green>") LOGU.opt(colors=True).info(f'<green>Client keepalive {keepalive}</green>')
@staticmethod @staticmethod
def transport(): def transport():
@ -104,8 +104,8 @@ class KISSClient(base.APRSClient):
def decode_packet(self, *args, **kwargs): def decode_packet(self, *args, **kwargs):
"""We get a frame, which has to be decoded.""" """We get a frame, which has to be decoded."""
LOG.debug(f"kwargs {kwargs}") LOG.debug(f'kwargs {kwargs}')
frame = kwargs["frame"] frame = kwargs['frame']
LOG.debug(f"Got an APRS Frame '{frame}'") LOG.debug(f"Got an APRS Frame '{frame}'")
# try and nuke the * from the fromcall sign. # try and nuke the * from the fromcall sign.
# frame.header._source._ch = False # frame.header._source._ch = False
@ -114,20 +114,23 @@ class KISSClient(base.APRSClient):
# msg = frame.tnc2 # msg = frame.tnc2
# LOG.debug(f"Decoding {msg}") # LOG.debug(f"Decoding {msg}")
try:
raw = aprslib.parse(str(frame)) raw = aprslib.parse(str(frame))
packet = core.factory(raw) packet = core.factory(raw)
if isinstance(packet, core.ThirdPartyPacket): if isinstance(packet, core.ThirdPartyPacket):
return packet.subpacket return packet.subpacket
else: else:
return packet return packet
except Exception as ex:
LOG.error(f'Error decoding packet: {ex}')
def setup_connection(self): def setup_connection(self):
try: try:
self._client = kiss.KISS3Client() self._client = kiss.KISS3Client()
self.connected = self.login_status["success"] = True self.connected = self.login_status['success'] = True
except Exception as ex: except Exception as ex:
self.connected = self.login_status["success"] = False self.connected = self.login_status['success'] = False
self.login_status["message"] = str(ex) self.login_status['message'] = str(ex)
return self._client return self._client
def consumer(self, callback, blocking=False, immortal=False, raw=False): def consumer(self, callback, blocking=False, immortal=False, raw=False):
@ -135,5 +138,5 @@ class KISSClient(base.APRSClient):
self._client.consumer(callback) self._client.consumer(callback)
self.keepalive = datetime.datetime.now() self.keepalive = datetime.datetime.now()
except Exception as ex: except Exception as ex:
LOG.error(f"Consumer failed {ex}") LOG.error(f'Consumer failed {ex}')
LOG.error(ex) LOG.error(ex)