Use ip link JSON output for SocketCAN find_available_interfaces #1478
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Until now, the helper method to find locally available SocketCAN interfaces uses string manipulations to parse the
ip link
output. Additionally, it uses a regular expression to parse the interface name and determine which of these interfaces are CAN interfaces. As a result, it does not properly detect CAN interfaces with customized names (see #1475 ).python-can/can/interfaces/socketcan/utils.py
Lines 41 to 69 in 5e5b950
In #1475 , @1atabey1 proposed a more reliable approach to instead use the interface
link_type
for CAN interface detection. This pull request additionally uses theip link
(Changelog) JSON output option to make parsing the information easier.JSON output has been available in
ip link
since version 4.14.0. All Debian / Ubuntu versions with the minimum supported Python version 3.7 also ship with anip link
version > 4.14.0.