[PATCH can-next v2 0/3] Introduce diag support for CAN
Filippo Storniolo <[email protected]>
| Newsgroups | org.kernel.vger.linux-can |
|---|---|
| Message-ID | <[email protected]> |
In the current state of the art, it is not possible for userspace to use
tool like ss(8) to query open AF_CAN sockets.
This patch series adds the netlink can_diag interface for AF_CAN. Userspace
is now able to send a netlink request to request information about open
AF_CAN sockets that are retrieved by the can-diag.ko module.
Patch 1 is a fix that is mandatory to the correct behaviour of the diag
module: the field sk_protocol is not assigned during `can_create()` instead
of being assigned only in case the CAN socket belong to the j1939 transport
protocol. This is needed to the correct filtering of the can diag module.
Patch 2 introduces a list per network namespace containing open CAN sockets.
The list is protected by a mutex.
CAN sockets are added in `can_create()` to the list and removed from it
in the `release()` calls defined for each transport protocol.
Patch 3 is the core patch that introduces the userspace structures to query
and receive netlink messages for CAN sockets and the actual CAN diag module.
The latter will use the userspace structures defined in <linux/can/diag.h>
to filter and retrieve open CAN sockets.
In the current implementation, every CAN sockets in the list is
returned to the userspace, however a filtering could be implemented:
Userspace could possibly request only bound CAN sockets or CAN sockets
belonging to a specific transport protocol (raw, iso-tp, j1939, bcm)
and so on.
An example of the output given by ss -cpe:
Netid Recv-Q Send-Q Local Address:Port Peer Address:Port Process
CAN_ISOTP 0 0 vcan1:1110 vcan1:291 uid:1001 ino:50324 sk:0 users:(("can2",pid=9210,fd=4))
CAN_ISOTP 0 0 vcan1:291 vcan1:1110 uid:1001 ino:50323 sk:0 users:(("can2",pid=9210,fd=3))
---
Changes in v2:
- Rebased to latest net-next
- Added a patch, suggested by sashiko-bot, that fixes an attempt
to lock an uninitialized mutex
- Link to v1: https://lore.kernel.org/r/[email protected]
Change w.r.t. RFC:
- header relocation, from linux/can_diag.h to linux/can/diag.h
(Oliver Hartkopp)
- file renaming, from net/can/can-diag.c to net/can/diag.c
(Oliver Hartkopp)
- guard renaming, from _UAPI__CAN_DIAG_H__ to _UAPI_CAN_DIAG_H_
(Oliver Hartkopp)
- handled J1939 addressing in sockaddr_can
(Oliver Hartkopp)
- Link to RFC: https://lore.kernel.org/linux-can/[email protected]/
---
Davide Caratti (1):
af_can: ensure sk_protocol is always set on socket creation
Filippo Storniolo (2):
af_can: store socket pointers in struct netns_can
can: add can diag interface
MAINTAINERS | 1 +
include/linux/can/core.h | 11 +++
include/net/netns/can.h | 6 ++
include/uapi/linux/can/diag.h | 55 +++++++++++++
net/can/Kconfig | 10 +++
net/can/Makefile | 3 +
net/can/af_can.c | 51 ++++++++++++
net/can/bcm.c | 2 +
net/can/diag.c | 185 ++++++++++++++++++++++++++++++++++++++++++
net/can/isotp.c | 2 +
net/can/j1939/socket.c | 3 +-
net/can/raw.c | 2 +
12 files changed, 330 insertions(+), 1 deletion(-)
---
base-commit: 69963a0678a347d57c4ac8b16939dba216eb95ce
change-id: 20260529-feat-can-diag-d7acbf5e22c2
Best regards,
--
Filippo Storniolo <[email protected]>