Linux SocketCAN nano-howto

How to get it to work:

In the kernel, enable
CAN networking and your appropriate CAN hardware device driver.
E.g., I have the dual-port Advantech PCI-1680, with a loopback (point-to-point
interconnect, really) between the two ports.
I had to patch Linux 3.16.7
to get hardware support for this particular board.
The patch still applies (almost cleanly) in 4.13.9, but there's a pitfall:
the currently shipping Advantech PCI-1680 rev.B don't contain a slave bridge
by PLX any longer. RIP, PLX. Instead, the PCI interface is implemented
in some FPGA (and the PCI device ID has changed).
Thus, the vanilla plx_pci driver no longer works.
Fortunately, Advantech now provide their own open-source
driver with a SocketCAN front end (two modules).
Note that their driver conflicts with the vanilla
sja1000 module.

modprobe plx_pci
ip link set can0 type can bitrate 125000
ip link set can1 type can bitrate 125000
#ifconfig can0 up
#ifconfig can1 up
ip link set can0 up
ip link set can1 up
# the socketcan user-space tools have moved from SVN at Berlios to GIT at Github
aptitude install git
git clone https://github.com/linux-can/can-utils/
cd can-utils
make
make install
candump can1
# switch to another console
cansend can0 5A1#1122334455667788

All of this works "out of the box" in Debian 8.1 Jessie.
Yes, the netfilter's "ip" tool already knows about CAN.
And yes, the libc / kernheaders already contain the CAN #defines and structs.
It really all worked in Debian 6 Squeeze already.

For more information on how to use the "socket CAN" from your programs,
check out Documentation/networking/can.txt in your kernel source tree.
And, the can-utils directory is a great source of code examples.