1

Is it possible to bridge to can interfaces via socat?

My setup looks something like this:

HOST A Host B vcan0 <-> vcan0 

Where i have 2 hosts with a can interface and i want to bridge them ideally via socat.

I got as far as sending can messages which the following config. But CanFD messages are just silently dropped and are not forwarded to the remote vcan interface. (I would like to avoid using something like cannelloni.)

Server

sudo socat INTERFACE:vcan0,pf=29,type=3,prototype=1 TCP-LISTEN:2000,fork,reuseaddr,nodelay 

Client

sudo socat INTERFACE:vcan0,pf=29,type=3,prototype=1 TCP:SERVERIP:2000,nodelay 

Is forwarding CanFD even possible with socat?

More debugging

Running socat with -d -d -d shows that the socat process doesn't even register CanFD frames.

For a can frame these 2 messages are produced:

2024/12/13 09:26:12 socat[8514] N local address: AF=29 AF=29 0x0000060000000400000000000000 2024/12/13 09:26:12 socat[8514] I transferred 16 bytes from 7 to 5 

And nothing for CanFD.

9
  • I'm not familiar with canfd, but if it's frame/packet based, by encapsulating it in a TCP stream, you're losing the framing. UDP might be preferable. Commented Dec 12, 2024 at 17:19
  • "Is it possible to bridge to can interfaces via socat?" Bridge TO a CAN interface FROM ... what? Commented Dec 13, 2024 at 6:55
  • @Seamus i thought it was clear for the socat i shared but i tried to update the question with a bit more details its basically from CAN to CAN Commented Dec 13, 2024 at 8:45
  • @StéphaneChazelas Im not sure im fully understand what you are saying but i tried UDP-RECV and UDP-DATAGRAM and it suffers from the same issue Commented Dec 13, 2024 at 8:49
  • 1
    Did you set the mtu to 72 to enable canfd? Commented Dec 13, 2024 at 11:14

1 Answer 1

2

It is possible, but by default a CAN socket will only process non-FD frames, and needs a call to setsockopt(SOL_CAN_RAW, CAN_RAW_FD_FRAMES, 1) to enable FD frames. Luckily, socat is flexible enough to do that:

socat INTERFACE:vcan0,pf=29,type=3,prototype=1,setsockopt=101:5:1 … 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.