can-hub-client — the consumer

Reference consumer: browse the catalogue, dump and inject frames, and bridge remote buses into the tools you already use (socketcand clients, the whole SocketCAN ecosystem via attach).

can-hub-client [--connect <url>] [--state-dir <path>] [--hub-fingerprint <hex>] [--name <label>] <command>
can-hub-client --show-identity [--state-dir <path>]

--connect takes quic://host:port, tls://host:port, tcp://host:port or unix://path; omitted, it uses the hub's local unix socket (/run/can-hub/hub.sock). On tls/quic the client has its own TLS identity (generated on first use, --show-identity prints its fingerprint for ACLs) and pins the hub on first contact. A hub reached under another address keeps its pin; --hub-fingerprint accepts that hub only, with no first contact (security).

--name <label> labels the connection in the hub's admin views (can-hub-cli peers, pending); it is not an identity and grants nothing.

Interfaces are addressed by the numeric id from list or by namespaced name agent/iface. Hub-side denials print as hub error <code>: <detail>. SIGINT and SIGTERM close the hub connection cleanly, so the hub releases the client at once (systemctl stop of the socketcand service included).

list

$ can-hub-client --connect tls://hub.example.com:7227 list
id         agent                            interface
1          truck42                          can0
2          truck42                          can1

dump

can-hub-client dump truck42/can0
can-hub-client dump --no-echo truck42/can0
can-hub-client --connect quic://hub.example.com:7227 dump --reliable truck42/can0
can-hub-client dump truck42/can0 123 700:7F0
  • Optional trailing filters <id>[:<mask>] (hex) are applied hub-side (SocketCAN mask semantics: deliver when id & mask == filter & mask); a bare id matches exactly. Up to 16 filters; only matching frames cross the network.
  • --no-echo suppresses the bus echo of this client's own injections; by default you see your own frames come back once they hit the wire.
  • --reliable carries the channel on its own reliable QUIC stream (lossless, ordered) instead of the lossy datagram plane; quic:// only, and the open fails on a hub without the capability. The stream transports are already lossless.
  • --error-frames also shows the bus error frames, like candump -e. They print with the full SocketCAN id, 20000004 [8] ... for a controller problem, the error class in the low bits and the detail in the data bytes (linux/can/error.h). Id filters do not apply to them.
  • A frame the hub injected into this bus along a bridge ends with (bridged), so it can be told from what the nodes on the bus send.

send

can-hub-client send truck42/can0 123#DEADBEEF

cansend syntax, hex throughout:

FormFrame
123#DEADBEEFclassic; more than 8 data bytes selects CAN FD
123##1DEADBEEFCAN FD; the digit after ## is the flags, bit 0 = bit rate switch
123#R, 123#R3remote request, optional length 0-8

More than 3 id digits or an id above 0x7FF selects an extended (EFF) frame. Data bytes may be separated by . (123#11.22.33). Requires a write grant when connected on tls/quic — see security.

show and configure

can-hub-client show truck42/can0
can-hub-client configure truck42/can0 bitrate 500000 sample-point 0.875 fd on dbitrate 2000000

configure takes the same settings as can-hub-cli interface set and applies them in one step; both print the settings the bus holds afterwards. On tls/quic it needs an rwa grant on the interface (security).

txn — run a transaction script

can-hub-client --connect quic://hub.example.com:7227 txn truck42/can0 flash.txn

Runs a transaction script at the agent: the script is checked before anything is sent, files it reads resolve against its directory, and its steps stream as the agent's window allows. On a terminal it shows steps done, rate and time left; Ctrl-C cancels the transaction at the agent. It prints the outcome and exits with:

ExitOutput
0done steps=272 ms=1840
1flash.txn:5: no response has this name, or why it could not connect or open
2aborted reason=timeout step=16 completed=16 missing=[5]

Before the outcome, every step waiting for a response for that moved on without all its nodes (then continue, or for N of) prints a line of its own, roster step=16 missing=[5]; missing on the outcome line names who had not answered the step that failed. Needs a write grant, and a reliable channel (quic, or the stream transports).

attach — mirror into a local vcan

can-hub-client --connect tls://hub.example.com:7227 attach truck42/can0 vcan0

Bidirectional mirror between a remote bus and a local vcan: candump, cansend, SavvyCAN, Wireshark and python-can now work against the remote bus with zero changes. When the vcan does not exist, attach creates it, up and with the CAN FD MTU; that needs CAP_NET_ADMIN (root, or sudo setcap cap_net_admin+ep $(command -v can-hub-client)). The vcan stays after the client exits and is reused next time. With a vcan created beforehand no privilege is needed:

sudo ip link add dev vcan0 type vcan && sudo ip link set up vcan0

Bus error frames reach the vcan too: a local socket sees them once it asks for them, candump -e vcan0 or python-can's socketcan interface.

Without a write grant it downgrades to read-only — frames still flow remote→local, local writes are refused at the hub.

attach keeps running when it loses the hub: it reconnects with the agent's backoff (1 s doubling to 60 s), waits for an interface the hub does not list yet, and mirrors again once it is back; frames written to the vcan meanwhile are dropped. Name the interface as <agent>/<interface> for that: interface ids change when the hub restarts, so a mirror opened by id stops on a lost hub rather than reopen another bus. Only a refusal that waiting cannot change (no read grant) ends it.

socketcand — bridge server

can-hub-client --connect tls://hub.example.com:7227 socketcand
socketcand server on 127.0.0.1:29536, hub hub.example.com, beacon on

Runs a local socketcand TCP server bridging every interface the client may read, plus the UDP discovery beacon (port 42000). For socketcand-speaking tools, e.g. python-can:

can.Bus(interface="socketcand", host="127.0.0.1", port=29536,
        channel="truck42/can0")
  • --listen [<bind-ip>:]<port> moves it off loopback (socketcand clients are unauthenticated — expose deliberately); --no-beacon silences discovery.
  • Rawmode only: BCM and ISO-TP are parsed and rejected.
  • Bus configuration before < open >: < truck42/can0 B <bitrate> <sample-point> <tq> <prop-seg> <phase-seg1> <phase-seg2> <sjw> <brp> > (sample point in tenths of a percent, 0 = not given) and < truck42/can0 C <listen-only> <loopback> <three-samples> > (0/1) become a hub CONFIGURE, so they need an rwa grant (access control). The reply is < ok > or < error <reason>: <detail> >, e.g. < error apply failed: Operation not supported > on a vcan.
  • A bus without a write grant opens read-only; < send > on it is refused.
  • The client Debian package ships this as can-hub-socketcand.service (installation).

Access control

What a client may read or inject is decided by the hub's ACLs, keyed by the client's TLS fingerprint. Defaults: read everything, write nothing. Clients on plaintext transports (unix, plain tcp) carry no fingerprint and are network-trusted with full access. Full model in security.

Programmatic access

  • Python: pip install python-can-hub, a native python-can backend — python/README.md.
  • C: libcanhub, the embeddable client library (Linux and Windows).

Logging

Frames and query results print to stdout; diagnostics go to stderr, so piping dump output is unaffected. Tune the stderr verbosity with --log-level error|warn|info|debug (default info) or the CAN_HUB_LOG environment variable.