[libsocketcan] Start / stop CAN boards from userspace
This post has NOT been accepted by the mailing list yet.
I am trying to start / stop CAN boards or to update their baudrate using SocketCAN from userspace. My tests are performed on PeakSystem and IXXAT USB-to-CAN V1/V2 boards.
My first attempt was to use visudo and to enable NOPASSWD to "ip link set ...", and then to call "sudo ip link set ..." in my C++ code.
(complete visudo line is "%sudo ALL=(ALL:ALL) NOPASSWD: /bin/ip link set can* type can bitrate *, /bin/ip link set can* up, /bin/ip link set can* down")
Then, I tried with Linux capabilities by adding capabilities to /bin/ip: "sudo setcap cap_net_raw,cap_net_admin+ep /bin/ip". That allows me to call "ip link set ..." from my C++ code which was even better.
But then I discovered "libsocketcan" which is a far better approach than calling command lines from C++. However when calling "can_set_bitrate" or "can_do_start", I have an error "RTNETLINK: Operation not permitted". But things are working fine when my program is launched as root. Other functions like can_get_state are working fine in userspace (actually, they are returning : 4 -> CAN_STATE_STOPPED).
I tried to adding capabilities to my program without any success ""sudo setcap cap_net_raw,cap_net_admin+ep ./myprogram".
How can I allow my program to use libsocketcan in userspace?