Skip to content

Unable to create ip6tnl interface with ip6tnl_flags using NDB #1393

@spike77453

Description

@spike77453

This is a follow-up to #1184. pyroute2 version used: 0.9.4

As stated in #1184 creating an ip6tnl interface with ip6tnl_flags set works well when using IPRoute. However, it fails when using NDB.

Here's a minimal, viable, complete example:

import sys
import logging
from pyroute2 import NDB, IPRoute


def create_tunnel_ipr(i, l, r, set_flags):
    ipr = IPRoute()
    if set_flags:
        ipr.link("add", ifname=i, kind="ip6tnl", ip6tnl_local=l, ip6tnl_remote=r, ip6tnl_proto=4, ip6tnl_flags=0x1)
    else:
        ipr.link("add", ifname=i, kind="ip6tnl", ip6tnl_local=l, ip6tnl_remote=r, ip6tnl_proto=4)


def create_tunnel_ndb(i, l, r, set_flags):
    with NDB() as ndb:
        if set_flags:
            ndb.interfaces.create(
                ifname=i, kind="ip6tnl", ip6tnl_local=l, ip6tnl_remote=r, ip6tnl_proto=4, ip6tnl_flags=0x1
            ).commit()
        else:
            ndb.interfaces.create(
                ifname=i, kind="ip6tnl", ip6tnl_local=l, ip6tnl_remote=r, ip6tnl_proto=4
            ).commit()


if __name__ == "__main__":
    tunnel_interface_name = sys.argv[2]
    rfc6333_b4 = sys.argv[3]
    rfc6333_aftr = sys.argv[4]
    set_flags = len(sys.argv) > 5
    if sys.argv[1] == "ndb":
        create_tunnel_ndb(tunnel_interface_name, rfc6333_b4, rfc6333_aftr, set_flags)
    elif sys.argv[1] == "ipr":
        create_tunnel_ipr(tunnel_interface_name, rfc6333_b4, rfc6333_aftr, set_flags)

For reference:

Creating the tunnel interface with IPRoute works well, with or without ip6tnl_flags:

# ip -6 tunnel del mytunnel; python mvce.py ipr mytunnel 2606:f4c0:5000::dead:beef 2606:f4c0:5001::ffff; ip -6 tunnel show mytunnel
mytunnel: ip/ipv6 remote 2606:f4c0:5001::ffff local 2606:f4c0:5000::dead:beef encaplimit 0 hoplimit inherit tclass 0x00 flowlabel 0x00000 (flowinfo 0x00000000)

# ip -6 tunnel del mytunnel; python mvce.py ipr mytunnel 2606:f4c0:5000::dead:beef 2606:f4c0:5001::ffff flag; ip -6 tunnel show mytunnel
mytunnel: ip/ipv6 remote 2606:f4c0:5001::ffff local 2606:f4c0:5000::dead:beef encaplimit none hoplimit inherit tclass 0x00 flowlabel 0x00000 (flowinfo 0x00000000)

However, when using NDB this fails when ip6tnl_flags is given (note that the interface is created correctly, with IP6_TNL_F_IGN_ENCAP_LIMIT set, i.e. encaplimit none):

# ip -6 tunnel del mytunnel; python mvce.py ndb mytunnel 2606:f4c0:5000::dead:beef 2606:f4c0:5001::ffff; ip -6 tunnel show mytunnel
mytunnel: ip/ipv6 remote 2606:f4c0:5001::ffff local 2606:f4c0:5000::dead:beef encaplimit 0 hoplimit inherit tclass 0x00 flowlabel 0x00000 (flowinfo 0x00000000)

# ip -6 tunnel del mytunnel; python mvce.py ndb mytunnel 2606:f4c0:5000::dead:beef 2606:f4c0:5001::ffff flag; ip -6 tunnel show mytunnel
Traceback (most recent call last):
  File "/root/mvce.py", line 42, in <module>
    create_tunnel_ndb(tunnel_interface_name, rfc6333_b4, rfc6333_aftr, set_flags)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mvce.py", line 28, in create_tunnel_ndb
    ).commit()
      ~~~~~~^^
  File "/var/tmp/mvce-venv/lib/python3.13/site-packages/pyroute2/ndb/objects/__init__.py", line 1211, in commit
    self._main_async_call(self.asyncore.commit)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/mvce-venv/lib/python3.13/site-packages/pyroute2/ndb/sync_api.py", line 85, in _main_async_call
    ret = task.result()
  File "/usr/lib64/python3.13/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ~~~~~~~~~~~~~~~~~^^
  File "/usr/lib64/python3.13/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/var/tmp/mvce-venv/lib/python3.13/site-packages/pyroute2/ndb/objects/__init__.py", line 710, in commit
    raise e_i
  File "/var/tmp/mvce-venv/lib/python3.13/site-packages/pyroute2/ndb/objects/__init__.py", line 699, in commit
    return await self.apply(mode='commit')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/mvce-venv/lib/python3.13/site-packages/pyroute2/ndb/objects/interface.py", line 999, in apply
    await super().apply(rollback, req_filter, mode)
  File "/var/tmp/mvce-venv/lib/python3.13/site-packages/pyroute2/ndb/objects/__init__.py", line 955, in apply
    if not await self.use_db_resync(lambda x: x, self.check):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/mvce-venv/lib/python3.13/site-packages/pyroute2/ndb/objects/__init__.py", line 1032, in use_db_resync
    for k in method(*argv, **kwarg):
             ~~~~~~^^^^^^^^^^^^^^^^
TypeError: 'bool' object is not iterable
mytunnel: ip/ipv6 remote 2606:f4c0:5001::ffff local 2606:f4c0:5000::dead:beef encaplimit none hoplimit inherit tclass 0x00 flowlabel 0x00000 (flowinfo 0x00000000)

This also fails when other IP6_TNL_F_* flags are set and even if they are all unset i.e. ip6tnl_flags=0.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions