STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
DaqInterface.hpp
Go to the documentation of this file.
1#ifndef FSW_DAQ_INTERFACE_HPP
2#define FSW_DAQ_INTERFACE_HPP
3
4#include <string>
5
6#include "config/Config.hpp"
7
8namespace fsw {
9namespace net {
10
11/**
12 * Which local NIC board traffic leaves from.
13 *
14 * The DAQ used to own its machine, so "the route the kernel picks" and "the board LAN" were the
15 * same sentence. It now shares the apps box with the Docker stack and the site LAN, and they are
16 * not: an unbound UDP socket sending to a broadcast address, or to a board whose subnet is
17 * reachable two ways, can leave on the wrong wire with no error anywhere.
18 *
19 * The fix every board-facing socket uses is to bind its *local address* to the NIC holding the
20 * board subnet. That is deliberately not SO_BINDTODEVICE: the services run as unprivileged
21 * `systemd --user` units and SO_BINDTODEVICE needs CAP_NET_RAW, which none of them has.
22 *
23 * The selection rule mirrors deploy/bootstrap_daq.sh, which already picks the board NIC by
24 * address rather than by name (the name varies — eth0, enxXXXXXXXX — the address does not,
25 * because the firmware hardcodes the server at 192.168.2.20).
26 */
28 /** False means the caller must abort startup: the operator asked for something impossible. */
29 bool ok = true;
30 /** Address to bind. "0.0.0.0" means unpinned — see `pinned`. */
31 std::string address = "0.0.0.0";
32 /** True when `address` names a real NIC. False on the dev/CI path, where nothing matched. */
33 bool pinned = false;
34 /** Human-readable account of the decision. Already logged by resolveDaqBindAddress(). */
35 std::string detail;
36};
37
38/**
39 * Decide which local address board traffic should leave from, and log the decision.
40 *
41 * 1. `[network].bind_ip` set to something other than 0.0.0.0 — use it verbatim. If it cannot be
42 * bound, return ok=false. An explicit pin that silently degrades to 0.0.0.0 is this bug
43 * wearing a config key.
44 * 2. Otherwise auto-detect: the local IPv4 interface whose subnet contains the configured board
45 * addresses. Exactly one match is the normal case, on the rig and under the sim (whose boards
46 * are 127.0.0.x, matched by loopback's /8).
47 * 3. More than one match — return ok=false, naming the candidates. Ambiguity is the defect;
48 * picking one is how we got here.
49 * 4. No match — 0.0.0.0 with a warning. This is a dev laptop or CI, where the board subnet does
50 * not exist and hard-failing would break `./dev.sh`.
51 *
52 * @param who Service name for log lines, e.g. "Sequencer".
53 */
54// NOTE the leading "::". FSWConfigManager declares a nested `fsw::fsw` namespace, so inside
55// `namespace fsw` the name `fsw` resolves to it and a plain `fsw::config::Config` becomes
56// `fsw::fsw::config::Config` — which compiles or not depending on include order alone.
57DaqBindResult resolveDaqBindAddress(const ::fsw::config::Config& cfg, const char* who);
58
59/**
60 * bind() an already-created socket to `address` on an ephemeral port.
61 * A no-op returning true for "0.0.0.0" or "", so callers need no special case for the dev path.
62 * Logs and returns false on failure.
63 */
64bool bindToDaqInterface(int sock, const std::string& address, const char* who);
65
66} // namespace net
67} // namespace fsw
68
69#endif
detail namespace with internal helper functions
Definition json.hpp:249
bool bindToDaqInterface(int sock, const std::string &address, const char *who)
bind() an already-created socket to address on an ephemeral port.
DaqBindResult resolveDaqBindAddress(const ::fsw::config::Config &cfg, const char *who)
Decide which local address board traffic should leave from, and log the decision.
Motorized ball valve position: raw ADC counts -> % open.
Which local NIC board traffic leaves from.
bool ok
False means the caller must abort startup: the operator asked for something impossible.
bool pinned
True when address names a real NIC.
std::string address
Address to bind.