Skip to content

Unable to delete filter of clsact/ingress #928

@jschwinger233

Description

@jschwinger233

Reproduce steps:

First let's create the clsact qdisc and a bpf filter.

ipr.tc("add", "clsact", 1) # dev lo
ipr.tc(
    "add-filter",
    "bpf",
    1, # dev lo
    ":1",
    fd=func.fd,
    name=func.name,
    parent='ffff:fff2',
    classid=1,
    direct_action=True,
)

Then we can check the status:

$ tc filter show dev lo parent ffff:fff2
filter protocol all pref 49152 bpf chain 0 
filter protocol all pref 49152 bpf chain 0 handle 0x1 flowid :1 tc_pass direct-action not_in_hw id 329 tag 15858a412926acbb

However the consequent del-filter won't work:

ipr.tc("del-filter", "bpf", iface_idx, ':1', parent='ffff:fff2')

will raise error

Traceback (most recent call last):
  File "basic01-xdp-pass/tc_loader.bcc.py", line 45, in <module>
    ipr.tc("del-filter", "bpf", iface_idx, ':0', parent=parent)
  File "/usr/lib/python3/dist-packages/pyroute2/iproute/linux.py", line 1614, in tc
    return tuple(self.nlm_request(msg, msg_type=command, msg_flags=flags))
  File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 376, in nlm_request
    return tuple(self._genlm_request(*argv, **kwarg))
  File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 867, in nlm_request
    for msg in self.get(msg_seq=msg_seq,
  File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 379, in get
    return tuple(self._genlm_get(*argv, **kwarg))
  File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 704, in get
    raise msg['header']['error']
pyroute2.netlink.exceptions.NetlinkError: (2, 'No such file or directory')

I guess it's caused by tcm_info in the request of RTM_DELTFILTER, somehow the parameter is set to 0x300 instead of 0, but I don't know how to make the correction.

Activity

jschwinger233

jschwinger233 commented on Jun 10, 2022

@jschwinger233
Author

Maybe this issue is interrelated?

svinota

svinota commented on Jun 10, 2022

@svinota
Owner

Thanks, working on it!

svinota

svinota commented on Jun 10, 2022

@svinota
Owner

The issue caused by incorrect tcm_info encoding.

To mitigate the error, you can use right now:

ipr.tc("del-filter", "bpf", iface_idx, ':1', protocol=0, prio=0xc000, parent='ffff:fff2')

Corresponding code:

def fix_msg(msg, kwarg):
msg['info'] = htons(kwarg.pop('protocol', ETH_P_ALL) & 0xFFFF) | (
(kwarg.pop('prio', 0) << 16) & 0xFFFF0000
)

Tomorrow I'm to fix this. And #745 as well.

added a commit that references this issue on Jun 11, 2022
svinota

svinota commented on Jun 11, 2022

@svinota
Owner

Looks like fixed:

def test_filter_delete(context, bpf):
context.ipr.tc('add', kind='clsact', index=context.default_interface.index)
context.ipr.tc(
'add-filter',
kind='bpf',
index=context.default_interface.index,
fd=bpf,
name='my_func',
parent='ffff:fff2',
classid=1,
direct_action=True,
)
filters = context.ipr.get_filters(
index=context.default_interface.index, parent='ffff:fff2'
)
# len == 2: handles 0 and 1
assert len(filters) == 2
context.ipr.tc(
'del-filter',
kind='bpf',
index=context.default_interface.index,
parent='ffff:fff2',
info=filters[0]['info'],
)
filters = context.ipr.get_filters(
index=context.default_interface.index, parent='ffff:fff2'
)
assert len(filters) == 0

The next release which will include this fix is to be tagged tomorrow

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @svinota@jschwinger233

        Issue actions

          Unable to delete filter of clsact/ingress · Issue #928 · svinota/pyroute2