can: raw: instantly reject unsupported CAN frames
Subsystems (2)
Oliver Hartkopp
maintainerPATCH 1/1 can: raw: instantly reject unsupported CAN frames
For real CAN interfaces the CAN_CTRLMODE_FD and CAN_CTRLMODE_XL control modes indicate whether an interface can handle those CAN FD/XL frames.
In the case a CAN XL interface is configured in CANXL-only mode with disabled error-signalling neither CAN CC nor CAN FD frames can be sent.
The checks are performed on CAN_RAW sockets to give an instant feedback to the user when writing unsupported CAN frames to the interface.
Signed-off-by Oliver Hartkopp <[email protected]>
--- include/linux/can/dev.h | 12 +++++++++ net/can/raw.c | 54 +++++++++++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 8 deletions(-)
include/linux/can/dev.h +12 -0
@@ -129,10 +129,22 @@ int can_restart_now(struct net_device *dev);void can_bus_off (struct net_device *dev);const char *can_get_state_str (const enum can_state state);const char *can_get_ctrlmode_str (u32 ctrlmode); +static inline bool can_dev_err_signal_is_disabled (struct can_priv *priv) +{ +const u32 mixed_mode =CAN_CTRLMODE_FD |CAN_CTRLMODE_XL ; + +/* When CAN XL is enabled but FD is disabled we are running in +* the so-called 'XL-only mode' where the error signalling is +* disabled. +* The so-called CC/FD/XL 'mixed mode' requires error signalling. +*/ +return ((priv->ctrlmode & mixed_mode) ==CAN_CTRLMODE_XL ); +} +/* drop skb if it does not contain a valid CAN frame for sending */ static inline bool can_dev_dropped_skb (struct net_device *dev,struct sk_buff *skb) {struct can_priv *priv =netdev_priv (dev); u32 silent_mode = priv->ctrlmode & (CAN_CTRLMODE_LISTENONLY |
net/can/raw.c +46 -8
81 lines not on this page · raw message
Signature · 1 line
2.47.3