-
Notifications
You must be signed in to change notification settings - Fork 52
Update socket CAN to include CAN-FD #21
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
Conversation
mcr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for updating the documentation.
You intro suggested that there were other things that needed to be done in libpcap.
Is there a matching PR for libpcap?
Presumably you mean "the libpcap documentation", as tcpdump is an application. |
I mean the tcpdump.org documentation for LINKTYPE: https://www.tcpdump.org/linktypes/LINKTYPE_CAN_SOCKETCAN.html Libpcap documentation (Libpcap man pages) https://www.tcpdump.org/manpages/pcap.3pcap.html do not specify the format for any LINKTYPE |
Once the concept is approved here, I will create a matching PR in Libpcap, If you think the concept should be discussed in https://github.com/the-tcpdump-group/libpcap instead then I will open an issue there. |
|
Note that libpcap itself no longer produces DLT_CAN_SOCKETCAN packets; support for them was introduced in commit f3edbb599b8cbcc7e4560000dcba8e992dc11a31 and was removed in commit 93ca5ff7030aaf1219e1de05ec89a68384bfc50b See this comment on that commit and the two following comments. Is there any other packet source that produces |
Yes, the following tools produce PCAPNG files with Open Source Converters that convert files from automotive specific formats to PCAPNG
Commercial product that produce PCAPNG files with
|
|
So in what fashion is this format at all related to SocketCAN? Is it a format that could be used to record CAN packets in a system that doesn't use the SocketCAN API (and might not even use Linux)? If the answer is "yes", perhaps it should just be named |
The format have the same layout as Linux Socket CAN, with only difference being the endianness of the ID
Yes,
Naming it |
|
@guyharris I updated this MR to focus only on documenting the FD flags, could you review it? |
|
So has there ever been code that 1) put CAN FD packets into a pcap or pcapng file with LINKTYPE_CAN_SOCKETCAN and 2) did not set the |
Yes, I wrote such code.
Yes, since So new writers should set it, and readers should check for both MTU and FDF flag. |
|
So when it speaks of the two values of the "frame size", when determining whether a frame without
|
the full packet length from the pcap/pcapng block (including header, payload and unused padding bytes) |
|
So as I read Table 5 "Coding of the numbers of data bytes by the DLC" in ISO 11898-1:2015, "classic" frames can have up to 8 data bytes and FD frames can have up to 64 data bytes; an 8-byte SocketCAN header plus 8 data bytes is 16, and an 8-byte SocketCAN header plus 64 data bytes is 72, but does the Linux SocketCAN code always pad classic frames out to 16 bytes and FD frames out to 72 bytes, so the length and caplen are 16 for classic frames and 72 for FD frames (even if the FD frame has 8 or fewer data bytes)? (I don't have any of the other ISO 11898 standards specifying the layers below ISO 11898-1, so I don't know whether frames are padded on the wire.) |
Above statement is correct
There is no padding on the wire |
|
While testing some changes to Wireshark to use the So I don't trust that field completely, at least for older packets. I don't know whether those captures came from libpcap on Linux or, if they did, whether it was from the old In kernels at least as far back as 3.0.4, there is a routine In 2.6.31, the driver in drivers/net/can/sja1000/sja1000.c appears to zero out the frame header itself. If other drivers didn't do so, protocol analyzers - or capture file readers - will need to apply heuristics to determine whether to trust the "FD flags" field. Given that all kernels with CAN FD support have |
|
@guyharris I understand the issue, what would you recommend future writers of LINKTYPE_CAN_SOCKETCAN do? |
|
|
So the first "Reserved/Padding" appears to have been assigned a meaning for classic CAN frames, I infer from the can/length.h header and section 8.4.2.4 "DLC field" of ISO 11898-1 that, if the Is that the case? And is that only for sending classic CAN frames, so that the sender can specify what value to put into the DLC field, or is it also supplied when a frame is received? I see That field isn't needed for CAN FD and isn't part of the , so I presume that for a CAN FD field it will be zero; it's a reserved field in the |
|
@guyharris I have not used |
Not really. The right (and safe) way is to check for the data structure length (aka MTU). |
Yes. The reason for can8_dlc is that CAN controllers send that 'raw' DLC value on the wire. The API extension is used for CAN security testing to check whether a receiving node grabs this 'raw' DLC value and uses values like 0xF in the former processing to trigger overflows or write behind buffer sizes. With a 'raw' DLC value of 0xF the Classical CAN controller still transfers 8 bytes of payload. The receivers should limit the length value to 8 bytes when reading the DLC value from the CAN controllers registers. |
The code in the main branch of libpcap does exactly that. If a packet in the |
Is this the right approach? From the kernel perspective the FDF flag is unreliable. Should therefore libpcap set this bit on its own or should it show the 'reality' which has been captured? The reliable information whether we have a Classical CAN frame or a CAN FD frame is (still) only represented in the MTU, and |
Proposed as the-tcpdump-group/libpcap#1035
Because writing 64bytes of CAN-FD data when not all the bytes are used is a big waste of disk space. Example: |
The "reality that was captured" is that a frame is either classic CAN or CAN FD. One way to indicate the difference is to use a However, a user requested in the-tcpdump-group/libpcap#1052 that libpcap not add a Using the FDF flag is a way to provide the classic CAN vs. CAN FD information without having to add extra data to the frame.
To, as @kayoub5 noted, save space. Think of it as compressing the Note also that not all |
Ok, got it (hopefully). It is not mainly about storing 1:1 content provided by the Linux kernel but about storing CAN traffic (in an efficient way). Then the FDF flag is perfectly fine for this 'use-case in userspace'. The https://github.com/linux-can/can-utils ASCII HEX logfile format does not store 'empty bytes' of CAN (FD) frames either:
Right. |
Exactly. It can store CAN traffic from the Linux kernel, or from other arbitrary equipment that generates or captures CAN traffic, or converted from CAN traffic captures in other formats. |
Context
The libpcap library used the socket CAN format for both CAN and CAN-FD, however the documentation did not reflect the new flags that were added when the CAN-FD format was used.