Vadims06 / topolograph

Topolograph.com is an online project which can visualize OSPF/ISIS topology based on LSDB output from a single network device. Then you can not only see (and check) the shortest path from source to destination, but also see the outcome from link or node failure along the path to the destination.
https://topolograph.com
MIT License
177 stars 23 forks source link

Error parsing OSPF LSDB output: host bits set #20

Closed rbeumer closed 3 years ago

rbeumer commented 3 years ago

I was testing with the lastest docker image and uploading an OSPF LSDB. The uploading works for an IOS-XR LSDB but when I am testing the output from a Cisco IOS LSDB it trows an internal server error. The Flask logs show the following error:

[2021-08-04 08:54:41 +0000] [13] [ERROR] Error handling request /upload-ospf-lsdb
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 134, in handle
    self.handle_request(listener, req, client, addr)
  File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 175, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/usr/local/lib/python3.6/site-packages/connexion/apps/abstract.py", line 249, in __call__
    return self.app(environ, start_response)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "routes.pyx", line 2063, in routes.upload_file
  File "Helpers.pyx", line 1883, in Helpers.ParsingHelper.doParseLsdbAndBuildGraph
  File "Helpers.pyx", line 1274, in Helpers.ParsingHelper.parse_router_lsa
  File "/usr/local/lib/python3.6/ipaddress.py", line 1519, in __init__
    raise ValueError('%s has host bits set' % self)
ValueError: x.x.x.x/31 has host bits set

The IP address has obiously been obfuscated.

When I check the LSDB output the IP address mentioned in the error is part of a type 1 router LSA. It is first part of a /31 point to point link and also mentioned als a stub network.

    Link connected to: another Router (point-to-point)
     (Link ID) Neighboring Router ID: x.x.x.x
     (Link Data) Router Interface address: x.x.x.x <== IP address with the /31 mask mentioned in the error
      Number of MTID metrics: 0
       TOS 0 Metrics: 1

    Link connected to: a Stub Network
     (Link ID) Network/subnet number: x.x.x.x <== IP address with the /31 mask mentioned in the error
     (Link Data) Network Mask: 255.255.255.254
      Number of MTID metrics: 0
       TOS 0 Metrics: 1

The Python IP address library is throwing this error because the address mentioned is not the network address it seems, though with a /31 you won't have a dedicated network address. In my case it is the second address in the /31.

I can't check the code to see why and how the IP address is being checked by the ipaddress module so I can't speculate on how to solve it. Would you be willing to add the code to this repository so others might help solving this issue?

Vadims06 commented 3 years ago

Hi @rbeumer, thank you for your feedback and for such deep investigation. I met cases when OSPF use non-network addresses and probably my implemented logic doesn't cover all cases) I will try to recreate the issue, fix, release it next week.

Vadims06 commented 3 years ago

Hi @rbeumer, the fix has been released in v2.21.1. Please make a docker-compose pull and provide me an update.

rbeumer commented 3 years ago

Thanks! The fix seems to work, uploading the LSDB output is now working without any errors, also no errors from the Flask container.

Vadims06 commented 3 years ago

fixed