Skip to content

ndb: Error while adding default route to just added gateway IP #1465

Description

@ekkagra
# uv pip list
Package  Version
-------- -------
pyroute2 0.9.5

# uname -a
Linux xxxxx 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64 GNU/Linux

Trying to replicate following operations.

ip addr add 192.168.120.10/24 dev eth0
ip r add 192.168.120.1 dev eth0
ip r add default via 192.168.120.1 dev eth0

although ndb is able to add but some error is seen while adding default route.

>>> with NDB() as n:
...     n.interfaces["eth0"].add_ip("192.168.120.10/24").commit()
...     idx = n.interfaces["eth0"].get("index")
...     n.routes.create(dst="192.168.120.1", gateway="", oif=idx).commit()
...     n.routes.create(dst="", gateway="192.168.120.1", oif=idx).commit()
...
{'alt_ifname_list': [], 'state': 'up', 'ifname': 'eth0', 'target': 'localhost', 'tflags': 0, 'index': 3, 'family': 0, 'ifi_type': 1, 'flags': 69699, 'change': 0, 'address': '7e:6e:5b:88:f0:67', 'broadcast': 'ff:ff:ff:ff:ff:ff', 'mtu': 1480, 'link': 271, 'qdisc': 'noqueue', 'master': None, 'txqlen': 1000, 'operstate': 'UP', 'linkmode': 0, 'net_ns_pid': None, 'ifalias': None, 'num_vf': None, 'group': 0, 'ext_mask': None, 'promiscuity': 0, 'num_tx_queues': 1, 'num_rx_queues': 1, 'carrier': 1, 'carrier_changes': 2, 'link_netnsid': 0, 'phys_port_name': None, 'proto_down': 0, 'gso_max_segs': 65535, 'gso_max_size': 65536, 'event': None, 'new_netnsid': None, 'if_netnsid': None, 'carrier_up_count': 1, 'carrier_down_count': 1, 'new_ifindex': None, 'min_mtu': 68, 'max_mtu': 65535, 'alt_ifname': None, 'parent_dev_name': None, 'parent_dev_bus_name': None, 'gro_max_size': None, 'tso_max_size': None, 'tso_max_segs': None, 'kind': 'veth', 'slave_kind': None, 'xdp_attached': None, 'xdp_flags': None, 'xdp_prog_id': None, 'xdp_drv_prog_id': None, 'xdp_skb_prog_id': None, 'xdp_hw_prog_id': None}
{'multipath': [], 'metrics': {}, 'deps': 0, 'dst': '192.168.120.1', 'family': 2, 'dst_len': 32, 'oif': 3, 'target': 'localhost', 'tflags': 0, 'src_len': 0, 'tos': 0, 'table': 254, 'proto': 4, 'scope': 0, 'type': 1, 'flags': 0, 'src': None, 'iif': None, 'gateway': None, 'priority': 0, 'prefsrc': None, 'protoinfo': None, 'flow': None, 'mark': None, 'via': '', 'newdst': '', 'pref': None, 'encap_type': None, 'route_id': None, 'gc_mark': None}

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/tmp/test/.venv/lib/python3.12/site-packages/pyroute2/ndb/objects/__init__.py", line 1204, in commit
    self._main_async_call(self.asyncore.commit)
  File "/tmp/test/.venv/lib/python3.12/site-packages/pyroute2/ndb/sync_api.py", line 85, in _main_async_call
    ret = task.result()
          ^^^^^^^^^^^^^
  File "/root/.local/share/uv/python/cpython-3.12.12-linux-x86_64-gnu/lib/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/root/.local/share/uv/python/cpython-3.12.12-linux-x86_64-gnu/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/tmp/test/.venv/lib/python3.12/site-packages/pyroute2/ndb/objects/__init__.py", line 707, in commit
    raise e_i
  File "/tmp/test/.venv/lib/python3.12/site-packages/pyroute2/ndb/objects/__init__.py", line 696, in commit
    return await self.apply(mode='commit')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/test/.venv/lib/python3.12/site-packages/pyroute2/ndb/objects/__init__.py", line 948, in apply
    if not await self.use_db_resync(lambda x: x, self.check):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/test/.venv/lib/python3.12/site-packages/pyroute2/ndb/objects/__init__.py", line 1025, in use_db_resync
    for k in method(*argv, **kwarg):
             ^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'bool' object is not iterable
# ip --ts monitor
[2026-02-11T11:29:20.620180] 3: eth0    inet 192.168.120.10/24 scope global eth0
       valid_lft forever preferred_lft forever
[2026-02-11T11:29:20.620337] local 192.168.120.10 dev eth0 table local proto kernel scope host src 192.168.120.10
[2026-02-11T11:29:20.620478] 192.168.120.0/24 dev eth0 proto kernel scope link src 192.168.120.10
[2026-02-11T11:29:20.620514] broadcast 192.168.120.255 dev eth0 table local proto kernel scope link src 192.168.120.10
[2026-02-11T11:29:20.627400] 192.168.120.1 dev eth0 proto static
[2026-02-11T11:29:20.630370] default via 192.168.120.1 dev eth0 proto static
# ip r
default via 192.168.120.1 dev eth0 proto static
169.254.1.1 dev eth0 scope link
192.168.120.0/24 dev eth0 proto kernel scope link src 192.168.120.10
192.168.120.1 dev eth0 proto static

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions