Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] links without IP addresses causes "invalid IPNetwork /0" #466

Closed
ehrenb opened this issue Jun 10, 2020 · 3 comments
Closed

[BUG] links without IP addresses causes "invalid IPNetwork /0" #466

ehrenb opened this issue Jun 10, 2020 · 3 comments
Assignees
Labels

Comments

@ehrenb
Copy link

ehrenb commented Jun 10, 2020

Describe the bug
It seems that links to nodes without IP addresses (e.g. hubs, RJ45) causes an error when re-opening the network XML. Upon initial creation and running, it works as expected, but core-pygui produces following error when re-opening due to a bug when parsing the XML:

2020-06-10 10:16:58,428 - ERROR - app:show_exception - app exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/netaddr/strategy/ipv4.py", line 125, in str_to_int
    return _struct.unpack('>I', _inet_pton(AF_INET, addr))[0]
OSError: illegal IP address string passed to inet_pton

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/netaddr/ip/__init__.py", line 311, in __init__
    self._value = self._module.str_to_int(addr, flags)
  File "/usr/local/lib/python3.6/dist-packages/netaddr/strategy/ipv4.py", line 129, in str_to_int
    raise AddrFormatError('%r is not a valid IPv4 address string!' % addr)
netaddr.core.AddrFormatError: '' is not a valid IPv4 address string!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/netaddr/ip/__init__.py", line 791, in parse_ip_network
    ip = IPAddress(val1, module.version, flags=INET_PTON)
  File "/usr/local/lib/python3.6/dist-packages/netaddr/ip/__init__.py", line 314, in __init__
    % (addr, self._module.version))
netaddr.core.AddrFormatError: base address '' is not IPv4

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/netaddr/strategy/ipv4.py", line 265, in expand_partial_address
    tokens = ['%d' % int(addr)]
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/netaddr/ip/__init__.py", line 928, in __init__
    implicit_prefix, flags)
  File "/usr/local/lib/python3.6/dist-packages/netaddr/ip/__init__.py", line 795, in parse_ip_network
    expanded_addr = _ipv4.expand_partial_address(val1)
  File "/usr/local/lib/python3.6/dist-packages/netaddr/strategy/ipv4.py", line 267, in expand_partial_address
    raise error
netaddr.core.AddrFormatError: invalid partial IPv4 address: ''!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/core/gui/task.py", line 38, in run
    values = self.task(*self.args)
  File "/usr/local/lib/python3.6/dist-packages/core/gui/coreclient.py", line 604, in open_xml
    self.join_session(response.session_id)
  File "/usr/local/lib/python3.6/dist-packages/core/gui/coreclient.py", line 272, in join_session
    self.interfaces_manager.joined(session.links)
  File "/usr/local/lib/python3.6/dist-packages/core/gui/interface.py", line 126, in joined
    index = get_index(interface)
  File "/usr/local/lib/python3.6/dist-packages/core/gui/interface.py", line 16, in get_index
    net = netaddr.IPNetwork(f"{interface.ip4}/{interface.ip4mask}")
  File "/usr/local/lib/python3.6/dist-packages/netaddr/ip/__init__.py", line 938, in __init__
    raise AddrFormatError('invalid IPNetwork %s' % addr)
netaddr.core.AddrFormatError: invalid IPNetwork /0

The culprit here seems to be core/gui/interface.py . It is trying to parse ip4 and ip4_mask from links that don't have ip addresses in the saved xml. My current local fix is to check to see if the link has an ip4 within the joined() function:

interface.py

    def joined(self, links: List["core_pb2.Link"]) -> None:
        interfaces = []
        for link in links:
            if link.HasField("interface_one"):
                interfaces.append(link.interface_one)
            if link.HasField("interface_two"):
                interfaces.append(link.interface_two)

        # add to used subnets and mark used indexes
        for interface in interfaces:
            # *Ensure an ip4 or ip6 address exists*
            if interface.ip4 or interface.ip6:
                subnets = self.get_subnets(interface) # previous commit tried to fix w/ this
                index = get_index(interface)
                subnets.used_indexes.add(index)
                if subnets.key() not in self.used_subnets:
                    self.used_subnets[subnets.key()] = subnets

I saw that this commit a36674a is trying to solve the same problem, but was still receiving the error.

To Reproduce
Steps to reproduce the behavior:

  1. Make a network that has a RJ45 or Hub linked to another node
  2. Save it as XML
  3. Reopen the XML within core-pygui
  4. See error in log about Invalid IPNetwork

Desktop (please complete the following information):

  • OS: e.g. Ubuntu 18.04
  • CORE Version - develop branch, but I believe it will occur in 6.4.0 as well
  • EMANE Version N/A
@ehrenb ehrenb added the bug label Jun 10, 2020
@bharnden
Copy link
Contributor

will take a look, thanks

@bharnden
Copy link
Contributor

bharnden commented Jun 10, 2020

Can you provide a specific XML example? Following your directions using an example for step1 with nodes connected to a Hub, I could not replicate.

I can see it occur if the node linked to the Hub does not have an address, maybe that was your case and I didn't understand that part.

More specifically when ip4 is missing as that whats used in the get_index call

@bharnden
Copy link
Contributor

I believe this is now fixed and will avoid this problem, on the develop branch.

In the future I would still like to shift to tracking the subnets used for ipv4/ipv6 individually as well as tracking user changes from the UI to avoid conflicting addresses etc, but there are possibilities of this happening at the moment when a user modifies addresses manually for now.

@bharnden bharnden self-assigned this Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants