Skip to content

cli: keep the mask of inverted --filter arguments - #2182

Open
thomas0829 wants to merge 1 commit into
hardbyte:mainfrom
thomas0829:fix-cli-inverted-filter-mask
Open

thomas0829 wants to merge 1 commit into
hardbyte:mainfrom
thomas0829:fix-cli-inverted-filter-mask

Conversation

@thomas0829

Copy link
Copy Markdown

Summary of Changes

  • Clear only CAN_ERR_FLAG from the mask of an inverted --filter <can_id>~<can_mask> argument instead of keeping only that bit, so 123~7FF gives can_mask=0x7FF instead of 0.
  • Fix the expected masks in test/test_cli.py and test/test_viewer.py, which asserted the old value (0x7F0 & 0x20000000, that is, 0).
  • Add the news fragment doc/changelog.d/2181.fixed.rst.

Why

With can_mask=0, the Linux kernel stores the inverted filter as can_id & 0 and never delivers a frame, because (rx_id & 0) != 0 is never true. candump parses the same syntax with can_mask &= ~CAN_ERR_FLAG, and the --filter help text describes the != match.

Validation

  • python -c snippet from cli: inverted --filter <can_id>~<can_mask> drops the mask #2181 prints 0x20000123 0x0 on main (86e70bc) and 0x20000123 0x7ff with this change
  • pytest test/test_cli.py test/test_viewer.py: the updated test_add_bus_arguments, test_add_bus_arguments_no_prefix and test_parse_args fail on main (0 != 2032, 2047 != 0) and pass here
  • pytest: same results as on main (885 tests; the 35 that fail in this environment fail identically on main, and pass when run on their own)
  • black --check ., ruff check can examples doc, pylint can/cli.py can/logger.py can/viewer.py: clean
  • mypy --python-version 3.12 .: no new errors (the 7 in can/io/mf4.py also show on main)

Related Issues / Pull Requests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe):

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

Additional Notes

Tested by parsing only; no SocketCAN device was available. Software filtering in BusABC._matches_filters does not handle CAN_INV_FILTER, which this change leaves as is.

_CanFilterAction ANDed the mask of "<can_id>~<can_mask>" with
CAN_ERR_FLAG instead of ~CAN_ERR_FLAG, so the mask was always 0 and
the inverted SocketCAN filter blocked every frame. Clear only the
error flag, as candump does.

Fixes hardbyte#2181
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

Successfully merging this pull request may close these issues.

cli: inverted --filter <can_id>~<can_mask> drops the mask

1 participant