can: bcm: add recvmsg flags for own, local and remote traffic
Subsystems (4)
Oliver Hartkopp
maintainerPATCH v3 1/1 can: bcm: add recvmsg flags for own, local and remote traffic
From: Nicolas Maier <[email protected]>
CAN RAW sockets allow userspace to tell if a received CAN frame comes from the same socket, another socket on the same host, or another host. See commit 1e55659ce6dd ("can-raw: add msg_flags to distinguish local traffic"). However, this feature is missing in CAN BCM sockets.
Add the same feature to CAN BCM sockets. When reading a received frame (opcode RX_CHANGED) using recvmsg, two flags in msg->msg_flags may be set following the previous convention (from CAN RAW), to distinguish between 'own', 'local' and 'remote' CAN traffic.
Update the documentation to reflect this change.
---
v2:
* add 'traffic_flags' parameter to bcm_rx_update_and_send and bcm_rx_cmp_to_index, to put the flags in the can frame after its data has been copied
v3:
* add missing initialization of msg flags and check for the needed cb space for sockaddr_can and the msg flags only once
Documentation/networking/can.rst | 34 ++++++++-------- net/can/bcm.c | 69 ++++++++++++++++++++++++++------ 2 files changed, 75 insertions(+), 28 deletions(-)
Documentation/networking/can.rst +18 -16
@@ -442,10 +442,28 @@ definitions are specified for CAN specific MTUs in include/linux/can.h: #define CAN_MTU (sizeof(struct can_frame)) == 16 => Classical CAN frame #define CANFD_MTU (sizeof(struct canfd_frame)) == 72 => CAN FD frame +Returned Message Flags +---------------------- + +When using the system call recvmsg(2) on a RAW or a BCM socket, the +msg->msg_flags field may contain the following flags: + +MSG_DONTROUTE: + set when the received frame was created on the local host. + +MSG_CONFIRM: + set when the frame was sent via the socket it is received on. + This flag can be interpreted as a 'transmission confirmation' when the + CAN driver supports the echo of frames on driver level, see + :ref:`socketcan-local-loopback1` and :ref:`socketcan-local-loopback2`. + (Note: In order to receive such messages on a RAW socket, + CAN_RAW_RECV_OWN_MSGS must be set.) + + .. _socketcan-raw-sockets: RAW Protocol Sockets with can_filters (SOCK_RAW) ------------------------------------------------
@@ -691,26 +709,10 @@ semantic for the applied filters is therefore changed to a logical AND. This is useful especially when the filterset is a combination of filters where the CAN_INV_FILTER flag is set in order to notch single CAN IDs or CAN ID ranges from the incoming traffic. -RAW Socket Returned Message Flags -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When using recvmsg() call, the msg->msg_flags may contain following flags: - -MSG_DONTROUTE: - set when the received frame was created on the local host. - -MSG_CONFIRM: - set when the frame was sent via the socket it is received on. - This flag can be interpreted as a 'transmission confirmation' when the - CAN driver supports the echo of frames on driver level, see - :ref:`socketcan-local-loopback1` and :ref:`socketcan-local-loopback2`. - In order to receive such messages, CAN_RAW_RECV_OWN_MSGS must be set. - - Broadcast Manager Protocol Sockets (SOCK_DGRAM) ----------------------------------------------- The Broadcast Manager protocol provides a command based configuration interface to filter and send (e.g. cyclic) CAN messages in kernel space.
net/can/bcm.c +57 -12
236 lines not on this page · raw message
Signature · 1 line
2.39.2
Hi,
Quoted 3 lines · Oliver Hartkopp
v3:
* add missing initialization of msg flags and check for the needed cb space forsockaddr_canand the msg flags only once
Thanks!
Best regards,
Nicolas