Uninett / zinolib

Python library for zino
Apache License 2.0
1 stars 3 forks source link

BFD: parsing bfdaddr failes on BFD event. #54

Open runborg opened 3 months ago

runborg commented 3 months ago

There have been inciedents where a BFD case have gotten a incorrect bfdaddr set in zino1 backend. This makes zinolib fail with this error message:

----> 1 for x in sess.cases_iter():
      2     pass

File ~/zino2/zino-env/lib/python3.10/site-packages/zinolib/ritz.py:535, in ritz.cases_iter(self)
    528 """Return list with cases from zino as a iter
    529
    530 Usage:
    531     for case in ritz_session.cases_iter():
    532         print(case.id)
    533 """
    534 for k in self.get_caseids():
--> 535     yield Case(self, k)

File ~/zino2/zino-env/lib/python3.10/site-packages/zinolib/ritz.py:193, in Case.__init__(self, zino, caseid)
    191 self._zino = zino
    192 self._caseid = caseid
--> 193 self._attrs = self._zino.get_attributes(caseid)

File ~/zino2/zino-env/lib/python3.10/site-packages/zinolib/ritz.py:592, in ritz.get_attributes(self, caseid)
    590 attrlist = self.get_raw_attributes(caseid)
    591 caseinfo = self.convert_attribute_list_to_case_dict(attrlist)
--> 592 caseinfo = self.clean_attributes(caseinfo)
    593 return caseinfo

File ~/zino2/zino-env/lib/python3.10/site-packages/zinolib/ritz.py:633, in ritz.clean_attributes(self, caseinfo)
    631 if "bfdaddr" in caseinfo:
    632     print(caseinfo)
--> 633     caseinfo["bfdaddr"] = ipaddress.ip_address(caseinfo["bfdaddr"])
    635 return caseinfo

File /usr/lib/python3.10/ipaddress.py:54, in ip_address(address)
     51 except (AddressValueError, NetmaskValueError):
     52     pass
---> 54 raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address')

ValueError: 'unknown(bad type (0))' does not appear to be an IPv4 or IPv6 address

This happens because zino1 cant detect if this is a IPv4 og IPv6 BFD message. The reason for this issue happening in the backend in the first place is for now unknown.

i've hotfixed my local zinolib with the following in ritz.py: (sorry, no diff available)

631          if "bfdaddr" in caseinfo:
632             try:
633                 caseinfo["bfdaddr"] = ipaddress.ip_address(caseinfo["bfdaddr"])
634             except ValueError:
635                pass
runborg commented 2 weeks ago

it might be more correct to return a ip 0.0.0.0 or something like that when this happens?.. so the client does get its ip address but it will be a incorrect address anyways..