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

get_nested() crashes on link kind = "erspan" (element of GRE) #1145

Open
crosser opened this issue Nov 17, 2023 · 0 comments
Open

get_nested() crashes on link kind = "erspan" (element of GRE) #1145

crosser opened this issue Nov 17, 2023 · 0 comments

Comments

@crosser
Copy link
Contributor

crosser commented Nov 17, 2023

$ sudo ip tunnel add greif mode gre remote 189.254.111.111 local 189.254.222.222 ttl 255

This operation creates interface kind="gre" plus an interface kind="erspan". When we get attributes for the latter, result contains IFLA_LINKINFO -> IFLA_INFO_DATA which is a string:

>>> [(el.get_attr("IFLA_IFNAME"), el.get_nested("IFLA_LINKINFO", "IFLA_INFO_KIND"), el.get_nested("IFLA_LINKINFO", "IFLA_INFO_DATA")) for el in IPRoute().get_links() if el.get_nested("IFLA_LINKINFO", "IFLA_INFO_KIND") == "erspan"]
[('erspan0', 'erspan', '05:00:16:00:01:00:00:00:08:00:15:00:00:00:00:00:08:00:01:00:00:00:00:00:06:00:02:00:00:00:00:00:06:00:03:00:20:00:00:00:08:00:04:00:00:00:00:00:08:00:05:00:00:00:00:00:08:00:06:00:00:00:00:00:08:00:07:00:00:00:00:00:05:00:08:00:00:00:00:00:05:00:09:00:00:00:00:00:05:00:0a:00:00:00:00:00:08:00:14:00:00:00:00:00:06:00:0e:00:00:00:00:00:06:00:10:00:00:00:00:00:06:00:11:00:00:00:00:00:06:00:0f:00:00:00:00:00:05:00:13:00:00:00:00:00')]
>>> 

For other types of interfaces, IFLA_INFO_DATA contains other useful nested attributes, so I want to be able to use, for instance,

get_nested("IFLA_LINKINFO", "IFLA_INFO_DATA", "IFLA_VRF_TABLE")

but when there is an erspan interface in the list, get_nested crashes:

>>> [(el.get_attr("IFLA_IFNAME"), el.get_nested("IFLA_LINKINFO", "IFLA_INFO_KIND"), el.get_nested("IFLA_LINKINFO", "IFLA_INFO_DATA", "IFLA_SOME_ATTRIBUTE")) for el in IPRoute().get_links() if el.get_nested("IFLA_LINKINFO", "IFLA_INFO_KIND") == "erspan"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
  File "/usr/lib/python3/dist-packages/pr2modules/netlink/__init__.py", line 1130, in get_nested
    pointer = pointer.get_attr(attr)
AttributeError: 'str' object has no attribute 'get_attr'
>>>
I understand that `get_nested()` is supposed to be "safe": never crash, and just return `None` if it cannot access an attribute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant