Skip to content

Commit 8a2257e

Browse files
committed
remove checking interface's name in check_rx_frame
The CAN-FD flag inference logic in check_rx_frame was gated on can_name == "vcan0". This was added as a workaround for virtual CAN interfaces (vcan), which do not distinguish between CAN and CAN-FD frames at the socket level, i.e., all frames arrive as CanAnyFrame::Normal regardless of their actual type. However, the interface name check is unnecessary. Classic CAN frames can never exceed 8 bytes, so the condition `res_len > 8` is already sufficient to infer a CAN-FD frame when the feature has been negotiated. This holds for all interface types: - vcan: frames arrive without the FD flag, but res_len > 8 detects them - Real CAN-FD hardware: the FD flag is already set by process_frame, so the additional |= is redundant but harmless - Real classic CAN hardware: frames never exceed 8 bytes, so the condition is never triggered Removing the name check also fixes the limitation of only supporting an interface named exactly "vcan0", which excluded vcan1, vcan2, etc. Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
1 parent bd317e3 commit 8a2257e

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

‎vhost-device-can/src/vhu_can.rs‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,12 @@ impl VhostUserCanBackend {
272272
can_rx.flags = (can_rx.flags.to_native() | VIRTIO_CAN_FLAGS_RTR).into();
273273
}
274274

275-
// Treat Vcan interface as CANFD if MTU is set to 64 bytes.
276-
//
277-
// Vcan can not be configured as CANFD interface, but it is
278-
// possible to configure its MTU to 64 bytes. So if a messages
279-
// bigger than 8 bytes is being received we consider it as
280-
// CANFD message.
281-
let can_name = self.controller.read().unwrap().can_name.clone();
282-
if self.check_features(VIRTIO_CAN_F_CAN_FD) && res_len > 8 && can_name == "vcan0" {
275+
// Classic CAN frames cannot exceed 8 bytes. If CAN-FD has been
276+
// negotiated and the frame length is > 8, treat it as a CAN-FD
277+
// frame. This also covers virtual interfaces (vcan) which do not
278+
// distinguish between CAN and CAN-FD at the socket level.
279+
if self.check_features(VIRTIO_CAN_F_CAN_FD) && res_len > 8 {
283280
res_flags |= CAN_FRMF_TYPE_FD;
284-
warn!("\n\n\nCANFD VCAN0\n\n");
285281
}
286282

287283
// Check if CAN/FD length is out-of-range (based on negotiated features)

0 commit comments

Comments
 (0)