. "$BST_LIB" # BST-TIMEOUT: 600 # mstpd 0.1.0+git (meta-oe recipes-extended/networking/mstpd, SRCREV 181c453fc1) # -- the userspace IEEE 802.1Q MSTP / RSTP daemon and its mstpctl client. What # ships is /usr/sbin/mstpd, /usr/sbin/mstpctl, the /usr/sbin/bridge-stp kernel # helper meta-oe substitutes for upstream's, the /usr/sbin/mstp_restart symlink # onto it, /etc/bridge-stp.conf, and two man pages. # # THE SUBJECT IS THE WHOLE PROGRAM, ON A BRIDGE THIS SUITE MAKES. The kernel # builds the bridge device type (brintos/linux#109), AF_PACKET (brintos/linux#81) # and the veth pair (brintos/linux#210), so the suite makes a bridge, enslaves # one end of a veth pair to it over rtnetlink, starts mstpd in the background, # and drives it through mstpctl: # # * mstpctl's OPTION LAYER, asserted by value. main() parses argv with # getopt_long and handles -h/--help, -V/--version, -f/--format, -b/--batch, # -s/--stdin and every malformed spelling of them BEFORE it calls # ctl_client_init(). # * mstpctl with NO DAEMON: ctl_client_init() runs first, so every command, # valid or not, ends in the same "can't setup control connection". # * mstpd SERVING: the control socket answers, the CIST port walks to # Designated/Forwarding, showbridge / showmstconfid / showportdetail are # read by value, the bridge timers round-trip and their ranges are refused, # and batch-mode validation -- which sits behind the connect -- is reached. # * mstpd STOPPING on SIGTERM with status 0, its log carrying the banner and # sanity_check()'s verdict. # # ON AN OLDER KERNEL the same cases read the gap instead. Without a bridge the # runtime cases are reds naming brintos/linux#109; without AF_PACKET mstpd -d # returns at its first wall and is run in the foreground, as it was before; and # without veth the two cases that need a bridge port are skips naming # brintos/linux#210. mstpd/bridge-device and mstpd/packet-socket each carry their # gap as one red and are green on a kernel that has it. # # NOTHING IS LEFT RUNNING. The daemon is backgrounded directly, so $! is mstpd # itself; it is stopped by pid, and an EXIT trap removes the bridge, the veth # pair and the daemon if the suite ends early. Every mstpctl call is bounded # (bst_run). # # THE DAEMONIZING FORM (`mstpd' with no -d) IS DELIBERATELY NOT RUN. It fopen()s # /var/run/mstpd.pid and calls daemon(3), leaving a pidfile and a child this # suite did not start; the foreground form runs the identical startup sequence. # # CALIBRATED AGAINST A NATIVE x86_64 BUILD of the same upstream commit with the # same shipped configure and the same out-of-tree build directory, so every # string and exit status below was read off a real run before it ever ran here. # That build directory matters: it is why PACKAGE_VERSION is "0.1.0-" with an # EMPTY build id. configure.ac computes PACKAGE_BUILD as `git log --pretty=%h -n # 1' and autotools runs configure in ${B}, which under bitbake is NOT inside ${S} # -- the do_configure log records `fatal: not a git repository'. The trailing # hyphen is therefore upstream's format with an empty field, not a truncation, # and it is asserted as such below so that a future recipe that DOES thread the # revision through shows up here rather than passing unnoticed. require /usr/sbin/mstpd mstpd/present MSTPD=/usr/sbin/mstpd MSTPCTL=/usr/sbin/mstpctl BRIDGESTP=/usr/sbin/bridge-stp VER='0.1.0-' W=${TMPDIR:-/tmp}/bst-mstpd.$$ rm -rf "$W"; mkdir -p "$W" || { bst_notok mstpd/workdir "cannot create $W"; exit 0; } # rb -- run bounded, merging stdout+stderr; sets $out and $rc. # Both streams are read together throughout: mstpctl writes its own diagnostics # to stderr while the ERROR macro underneath them prints to stdout (log.h's # NO_DAEMON branch), so a case that read only one would see half the evidence. rb() { bst_run "$@"; } # lib/bst.sh: a bound that FIRES # (timeout(1) did not, before the # brintos/linux#77 fix) and a file capture # no wedged child can hold open. has() { case "$2" in *"$1"*) return 0 ;; *) return 1 ;; esac; } yn() { if "$@"; then echo yes; else echo no; fi; } # --- inventory: what the package put on the image ----------------------------- check_eq mstpd/inventory-mstpd "yes" "$([ -x "$MSTPD" ] && echo yes)" check_eq mstpd/inventory-mstpctl "yes" "$([ -x "$MSTPCTL" ] && echo yes)" check_eq mstpd/inventory-bridgestp "yes" "$([ -x "$BRIDGESTP" ] && echo yes)" # The bare names a user types must be these binaries; `command -v' reads root's # real PATH, so this also catches an image where /usr/sbin is not on it. check_eq mstpd/on-path-mstpd "$MSTPD" "$(command -v mstpd 2>/dev/null)" check_eq mstpd/on-path-mstpctl "$MSTPCTL" "$(command -v mstpctl 2>/dev/null)" # mstp_restart is a symlink onto bridge-stp, and the two live in DIFFERENT # binary packages -- the link is in `mstpd', its target in `mstpd-mstpd'. That # split is what makes mstpd Depends: mstpd-mstpd, so a dangling link here is the # visible form of an image that took only one of the pair. The link is RELATIVE # (`bridge-stp', a sibling in the same directory), so it is resolved rather than # read: what the packaging guarantees is the target, not the spelling. check_eq mstpd/mstp-restart-link "$BRIDGESTP" \ "$(cd /usr/sbin 2>/dev/null && readlink -f mstp_restart 2>/dev/null)" check_eq mstpd/mstp-restart-resolves "yes" "$([ -x /usr/sbin/mstp_restart ] && echo yes)" check_eq mstpd/bridge-stp-conf "yes" "$([ -f /etc/bridge-stp.conf ] && echo yes)" check_eq mstpd/man-mstpctl "yes" "$([ -f /usr/share/man/man8/mstpctl.8 ] && echo yes)" check_eq mstpd/man-interfaces "yes" "$([ -f /usr/share/man/man5/mstpctl-utils-interfaces.5 ] && echo yes)" # The recipe inherits systemd and installs mstpd.service, and this distro sets no # "systemd" in DISTRO_FEATURES -- so systemd.bbclass strips ${systemd_unitdir} at # the end of do_install and NO unit ships. Asserted as the positive fact it is: # an image that suddenly grew one would mean the distro had gained systemd, which # is a change nobody should learn about from a boot failure. check_eq mstpd/no-systemd-unit "absent" \ "$([ -e /lib/systemd/system/mstpd.service ] && echo present || echo absent)" # The libexecdir half of upstream (mstpctl-utils' ifupdown.sh, mstp_config_bridge # and the python3 ifquery) is removed by the recipe's do_install:append. Pinned # because a recipe change that stopped removing it would put a /usr/bin/python3 # shebang on an image that has no python3. check_eq mstpd/no-mstpctl-utils "absent" \ "$([ -d /usr/lib/mstpctl-utils ] && echo present || echo absent)" # --- version, asserted by value for both binaries ----------------------------- rb 20 "$MSTPCTL" -V; mv_short=$out; mv_short_rc=$rc rb 20 "$MSTPCTL" --version; mv_long=$out rb 20 "$MSTPD" -V; md_ver=$out; md_ver_rc=$rc check_eq mstpd/version-mstpctl "$VER" "$mv_short" check_eq mstpd/version-mstpctl-rc "0" "$mv_short_rc" check_eq mstpd/version-long-form "$VER" "$mv_long" check_eq mstpd/version-mstpd "$VER" "$md_ver" check_eq mstpd/version-mstpd-rc "0" "$md_ver_rc" # The two binaries are compiled from one config.h, so a divergence would mean a # mixed install rather than a version bump. check_eq mstpd/version-agrees "$mv_short" "$md_ver" # The empty build id -- see the header. `0.1.0-' with nothing after the hyphen. check_eq mstpd/version-build-id-empty "" "${md_ver#0.1.0-}" # --- usage text, asserted by value -------------------------------------------- rb 20 "$MSTPCTL" --help; help_out=$out; help_rc=$rc check_eq mstpd/help-rc "0" "$help_rc" check_eq mstpd/help-usage-line "yes" "$(yn has 'Usage: mstpctl [options] [commands]' "$help_out")" check_eq mstpd/help-format-option "yes" \ "$(yn has '-f | --format Select output format (json, plain)' "$help_out")" check_eq mstpd/help-batch-option "yes" \ "$(yn has '-b | --batch Process file with mstpctl commands' "$help_out")" # command_helpall() prints one two-line stanza per command: a `-:' # line at column 0 and the ` ' line under it. The command table # has 39 entries and the printer suppresses exactly one of them, so both counts # are 38. Counting is what makes this stronger than a substring: a help text that # lost half its commands would still contain the usage line. printf '%s\n' "$help_out" > "$W/help.txt" check_eq mstpd/help-command-stanzas "38" "$(grep -c '^-' "$W/help.txt")" check_eq mstpd/help-command-names "38" "$(grep -c '^ [a-z]' "$W/help.txt")" # The one suppressed entry, by name: `if(strcmp("setportdonttxmt", ...))' in # command_helpall(). It is still a valid command -- only undocumented. check_eq mstpd/help-hides-donttxmt "0" "$(grep -c 'setportdonttxmt' "$W/help.txt")" # Four commands sampled by name and by their argument spelling, so that a # reordered or re-worded table is visible rather than merely a shorter one. check_eq mstpd/help-lists-addbridge "yes" "$(yn has ' addbridge [ ...]' "$help_out")" check_eq mstpd/help-lists-showbridge "yes" "$(yn has ' showbridge [ ... [param]]' "$help_out")" check_eq mstpd/help-lists-setmaxage "yes" "$(yn has ' setmaxage ' "$help_out")" check_eq mstpd/help-lists-settreeport "yes" "$(yn has ' settreeportcost ' "$help_out")" # -h and --help are the same case in the getopt table, so they must produce # byte-identical output. Comparing the whole of both runs is the assertion. rb 20 "$MSTPCTL" -h; check_eq mstpd/help-short-form "$help_out" "$out" # mstpd HAS NO USAGE TEXT AT ALL. Its getopt string is "Vdsv:" with no 'h' and no # default help branch -- `-h' falls to `default: return -1'. Recorded as the # positive fact it is, because "mstpd --help printed nothing useful" is otherwise # indistinguishable from a broken binary. rb 20 "$MSTPD" -h; md_h=$out; md_h_rc=$rc check_eq mstpd/mstpd-no-usage-rc "255" "$md_h_rc" check_eq mstpd/mstpd-no-usage-text "no" "$(yn has 'Usage' "$md_h")" check_eq mstpd/mstpd-getopt-diagnostic "yes" "$(yn has "invalid option -- 'h'" "$md_h")" # --- argument validation, asserted for real ----------------------------------- # Every case here is reached BEFORE ctl_client_init(), which is what makes it # assertable on an image with no daemon. # No arguments at all: `if((argc == optind) && !batch_file) goto help' -- the # usage text goes to stdout and the status is 1, not 0. rb 20 "$MSTPCTL"; check_eq mstpd/argv-none-rc "1" "$rc" check_eq mstpd/argv-none-prints-usage "yes" "$(yn has 'Usage: mstpctl' "$out")" # An unknown short option: getopt_long prints its own line, then the `default:' # arm prints ours, then help() runs and the status is 1. rb 20 "$MSTPCTL" -Z; check_eq mstpd/argv-bad-option-rc "1" "$rc" check_eq mstpd/argv-bad-option-getopt "yes" "$(yn has "invalid option -- 'Z'" "$out")" check_eq mstpd/argv-bad-option-own "yes" "$(yn has "Unknown option '?'" "$out")" # -f takes exactly "json" or "plain"; anything else is named back to the user. rb 20 "$MSTPCTL" -f bogus; check_eq mstpd/argv-bad-format-rc "1" "$rc" check_eq mstpd/argv-bad-format-msg "yes" "$(yn has "Invalid format 'bogus'" "$out")" # ...and the two valid spellings are NOT rejected. `-f json' with no command # still falls through to the `argc == optind' help path, so what distinguishes # accept from reject is the absence of the diagnostic, not the status. rb 20 "$MSTPCTL" -f json; check_eq mstpd/argv-format-json-accepted "no" "$(yn has 'Invalid format' "$out")" rb 20 "$MSTPCTL" -f plain; check_eq mstpd/argv-format-plain-accepted "no" "$(yn has 'Invalid format' "$out")" # -b names a file that must open. The path is checked by fopen(3) inside the # getopt loop, so this is real validation and not a later failure. rb 20 "$MSTPCTL" -b "$W/there-is-no-such-file" check_eq mstpd/argv-missing-batch-rc "1" "$rc" check_eq mstpd/argv-missing-batch-msg "yes" "$(yn has "Could not open file '$W/there-is-no-such-file'" "$out")" # -s and -b are mutually exclusive, and the refusal fires from whichever arrives # second. The file exists here, so the ONLY reason to refuse is the combination. : > "$W/batch.txt" rb 20 "$MSTPCTL" -s -b "$W/batch.txt" check_eq mstpd/argv-stdin-plus-batch-rc "1" "$rc" check_eq mstpd/argv-stdin-plus-batch-msg "yes" "$(yn has 'Cannot mix stdin & batch file' "$out")" rb 20 "$MSTPCTL" -b "$W/batch.txt" -s check_eq mstpd/argv-batch-plus-stdin-msg "yes" "$(yn has 'Cannot mix stdin & batch file' "$out")" # mstpd's own -v takes an integer 0..LOG_LEVEL_MAX (100); strtoul must consume # the WHOLE argument. Both halves of that check are exercised: a non-numeric # argument and an in-range-looking number that is over the ceiling. rb 20 "$MSTPD" -v abc; check_eq mstpd/argv-loglevel-nan-rc "1" "$rc" check_eq mstpd/argv-loglevel-nan-msg "yes" "$(yn has 'Invalid loglevel abc' "$out")" rb 20 "$MSTPD" -v 999; check_eq mstpd/argv-loglevel-range-rc "1" "$rc" check_eq mstpd/argv-loglevel-range-msg "yes" "$(yn has 'Invalid loglevel 999' "$out")" # ...and a legal level is not refused. -v 1 with no -d still daemonizes, so the # accepted case is taken on -V, which returns from the same getopt loop. rb 20 "$MSTPD" -v 2 -V; check_eq mstpd/argv-loglevel-accepted "$VER" "$out" # mstpd's unknown-option arm returns -1 from main(), which is exit status 255 -- # a different contract from mstpctl's 1, and worth pinning as such. rb 20 "$MSTPD" -Z; check_eq mstpd/argv-mstpd-bad-option-rc "255" "$rc" # --- the kernel helper: /usr/sbin/bridge-stp ---------------------------------- # meta-oe replaces upstream's 200-line bridge-stp.in with an 18-line POSIX-sh # script, and that script IS the documented contract: mstpctl(8) says user-space # STP is enabled only "while ensuring that /sbin/bridge-stp kernel helper script # will return success (0) for this operation". Its argument handling therefore # runs on this image for real, with no daemon and no bridge involved. rb 20 "$BRIDGESTP"; check_eq mstpd/helper-no-args-rc "1" "$rc" check_eq mstpd/helper-no-args-msg "yes" "$(yn has 'Missing args: bridge-stp ' "$out")" rb 20 "$BRIDGESTP" br0; check_eq mstpd/helper-one-arg-rc "1" "$rc" check_eq mstpd/helper-one-arg-msg "yes" "$(yn has 'Missing args:' "$out")" rb 20 "$BRIDGESTP" br0 bogus; check_eq mstpd/helper-bad-op-rc "1" "$rc" check_eq mstpd/helper-bad-op-msg "yes" "$(yn has 'Invalid operation: bogus' "$out")" # The kernel execs the helper at the hardcoded path /sbin/bridge-stp, and this # port installs it to ${sbindir}, which is /usr/sbin here because the distro is # not usrmerged. Upstream's configure.ac forces exec_prefix='' for exactly this # reason and Yocto's --exec-prefix=/usr overrides it. Pinned as a fact: the # kernel's own stp_state=1 request therefore falls back to kernel STP, and the # suite hands the bridge to mstpd through mstpctl and the helper directly. check_eq mstpd/helper-install-path "usr-sbin-only" \ "$([ -x /sbin/bridge-stp ] && echo both || echo usr-sbin-only)" # --- probes: what the kernel offers, established at runtime ------------------- # AF_PACKET. CONFIG_PACKET is what creates /proc/net/packet (packet_net_ops), so # the file is a direct reading of the option rather than an inference. # 79-libnet.test measures the syscall itself with a compiled probe. packet_proc=$([ -e /proc/net/packet ] && echo present || echo absent) # The image ships no bridge: a bridge device advertises itself through # /sys/class/net//bridge/, and no interface the image brings up has one. # Read before this suite makes its own. brdirs=0 for _d in /sys/class/net/*; do [ -d "$_d/bridge" ] && brdirs=$((brdirs + 1)); done check_eq mstpd/probe-no-bridge-sysfs "0" "$brdirs" BR=bstbr0 PA=bstmv0 PB=bstmv1 cleanup() { [ -n "${MP:-}" ] && { kill -TERM "$MP" 2>/dev/null; kill -9 "$MP" 2>/dev/null; } ip link del "$PA" >/dev/null 2>&1 ip link del "$BR" >/dev/null 2>&1 rm -rf "$W" } trap cleanup EXIT # The bridge link type. Asking rtnetlink for one is the assertion, and the # bridge it makes is the one the daemon below runs on. Each of the three fails # on a kernel without CONFIG_BRIDGE (brintos/linux#109), where iproute2 prints # "Unknown device type". if command -v ip >/dev/null 2>&1; then rb 30 ip link add name "$BR" type bridge; br_out=$out; br_rc=$rc br_exists=$([ -d "/sys/class/net/$BR/bridge" ] && echo yes || echo no) check_eq mstpd/probe-bridge-add "0" "$br_rc" check_eq mstpd/probe-bridge-created "yes" "$br_exists" check_eq mstpd/probe-bridge-quiet "" "$br_out" # BST-EMPTY-OK: br_rc above is the producer's status else bst_skip mstpd/probe-bridge-add "iproute2 ip is not on this image" bst_skip mstpd/probe-bridge-created "iproute2 ip is not on this image" bst_skip mstpd/probe-bridge-quiet "iproute2 ip is not on this image" br_exists=no fi # A bridge port. The image's only interface is lo and the bridge refuses it # (br_add_if: IFF_LOOPBACK), so the port is one end of a veth pair, enslaved # over rtnetlink. lo is never offered to the bridge: refusing it through # brctl's SIOCBRADDIF traps in this kernel and wedges every later rtnetlink user. port=no if [ "$br_exists" = yes ]; then rb 30 ip link add "$PA" type veth peer name "$PB"; veth_rc=$rc; veth_out=$out if [ "$veth_rc" -eq 0 ]; then rb 20 ip link set "$PA" master "$BR" [ "$rc" -eq 0 ] && [ -e "/sys/class/net/$BR/brif/$PA" ] && port=yes rb 20 ip link set "$BR" up; rb 20 ip link set "$PA" up; rb 20 ip link set "$PB" up fi fi # --- mstpctl with no daemon: the exit contract, asserted for real ------------- # ctl_client_init() runs before command_lookup_and_validate(), so EVERY command # ends the same way. The three cases below are deliberately different shapes -- # a query, a mutation, and a name that is not a command at all -- and the point # is that they are indistinguishable. Run before any daemon is started. rb 20 "$MSTPCTL" showbridge; sb_out=$out check_eq mstpd/noctl-showbridge-rc "1" "$rc" check_eq mstpd/noctl-showbridge-msg "yes" "$(yn has "can't setup control connection" "$sb_out")" check_eq mstpd/noctl-connect-diagnostic "yes" "$(yn has "Couldn't connect to server" "$sb_out")" rb 20 "$MSTPCTL" addbridge br0; check_eq mstpd/noctl-addbridge-rc "1" "$rc" check_eq mstpd/noctl-addbridge-msg "yes" "$(yn has "can't setup control connection" "$out")" rb 20 "$MSTPCTL" no-such-command; nsc_out=$out check_eq mstpd/noctl-unknown-command-rc "1" "$rc" # The "Unknown command" diagnostic exists in ctl_main.c and CANNOT be produced # with no daemon, because the connect refuses first. mstpd/ctl-unknown-command # below is the same command against a live daemon, where it is. check_eq mstpd/noctl-validation-unreachable "no" "$(yn has 'Unknown command' "$nsc_out")" check_eq mstpd/noctl-unknown-same-as-valid "$sb_out" "$nsc_out" # The documented helper contract, at its own level: mstpctl(8) requires # /sbin/bridge-stp to "return success (0)" before the kernel will hand STP to # userspace. With no daemon it returns mstpctl's 1, so the kernel would refuse. rb 30 "$BRIDGESTP" br0 start check_eq mstpd/helper-start-propagates-rc "1" "$rc" check_eq mstpd/helper-start-reaches-mstpctl "yes" "$(yn has "can't setup control connection" "$out")" # --- mstpd startup ------------------------------------------------------------ RUNTIME_CASES="mstp-state-machine showbridge-fields showmstconfid set-bridge-params showportdetail batch-command-validation ctl-unknown-command addbridge helper-start-with-daemon helper-stop-with-daemon delbridge" runtime_all() { # runtime_all for _c in $RUNTIME_CASES; do if [ "$1" = skip ]; then bst_skip "mstpd/$_c" "$2"; else bst_notok "mstpd/$_c" "$2"; fi done } serving=no if [ "$packet_proc" = absent ]; then # A kernel without AF_PACKET: mstpd -d returns on its own, at its first wall, # so it is run in the foreground and the wall is pinned by name: TST() names # the failing initialiser and its line. Where epoll is wired that wall is # packet_sock_init(), main.c:184, refused EAFNOSUPPORT; on an older kernel # without epoll (brintos/linux#53) it is init_epoll(), main.c:182. rb 60 "$MSTPD" -d; start_out=$out; start_rc=$rc check_eq mstpd/start-banner "yes" "$(yn has "Version - $VER" "$start_out")" check_eq mstpd/start-sanity-checks "yes" "$(yn has 'Sanity checks succeeded' "$start_out")" if has 'verifying packet_sock_init() == 0' "$start_out"; then check_eq mstpd/start-stops-at-wall "yes" \ "$(yn has 'socket failed: Address family not supported by protocol' "$start_out")" elif has 'verifying init_epoll() == 0' "$start_out"; then check_eq mstpd/start-stops-at-wall "yes" "$(yn has 'epoll_create failed' "$start_out")" else bst_notok mstpd/start-stops-at-wall "mstpd -d stopped at neither init_epoll() nor packet_sock_init(): $(_bst_1line "$start_out")" fi check_eq mstpd/start-exit-status "255" "$start_rc" else # A kernel with AF_PACKET: mstpd -d reaches epoll_main_loop() and serves until # it is stopped. It is backgrounded directly, so $! is mstpd itself, and # stopped by pid with TERM (then KILL) -- never left behind. Its log is a # block-buffered file, so it is read only after the daemon has exited. # Readiness is the control socket answering, not a fixed sleep: mstpctl's # "can't setup control connection" goes away once ctl_socket_init() has bound. "$MSTPD" -d -v 2 "$W/mstpd.log" 2>&1 & MP=$! _i=0 while [ $_i -lt 30 ]; do _i=$((_i + 1)); sleep 1 kill -0 "$MP" 2>/dev/null || break rb 20 "$MSTPCTL" showbridge has "can't setup control connection" "$out" || { serving=yes; break; } done if [ "$serving" = yes ]; then bst_ok mstpd/start-serves else bst_notok mstpd/start-serves "mstpd did not answer on its control socket within ${_i} s (alive: $(kill -0 "$MP" 2>/dev/null && echo yes || echo no)) -- $(_bst_1line "$out")" fi fi # --- the state machine and the per-bridge commands ----------------------------- # These need a live daemon, a real bridge and a port on it. Each precondition # was established above; a case that cannot run says which one it lacks. if [ "$br_exists" != yes ]; then runtime_all notok "no bridge device type on this kernel: wasm32_defconfig sets no CONFIG_BRIDGE, so __rtnl_newlink() answers EOPNOTSUPP 'Unknown device type' -- brintos/linux#109 (https://brintos.io/brintos/linux/issues/109)" elif [ "$packet_proc" = absent ]; then runtime_all notok "mstpd cannot open its BPDU socket: /proc/net/packet is absent -- brintos/linux#81 (https://brintos.io/brintos/linux/issues/81)" elif [ "$serving" != yes ]; then runtime_all notok "mstpd is not serving (see mstpd/start-serves)" else # The kernel helper, with a daemon to reach: `bridge-stp
start' is # `mstpctl addbridge', and success is the 0 the kernel waits for. `stop' is # delbridge, after which the daemon no longer knows the bridge. rb 30 "$BRIDGESTP" "$BR" start; h_rc=$rc rb 20 "$MSTPCTL" showbridge "$BR" check_eq mstpd/helper-start-with-daemon "0 0" "$h_rc $rc" rb 30 "$BRIDGESTP" "$BR" stop; h_rc=$rc rb 20 "$MSTPCTL" showbridge "$BR" check_eq mstpd/helper-stop-with-daemon "0 yes" "$h_rc $([ "$rc" -ne 0 ] && echo yes || echo no)" rb 20 "$MSTPCTL" addbridge "$BR" check_eq mstpd/addbridge "0" "$rc" # The CIST port reaches Designated/Forwarding. One bridge alone is its own # root, and a port with no BPDU coming back is an edge port, so the RSTP # state machine walks it blocking -> learning -> forwarding in a few seconds. if [ "$port" = yes ]; then _i=0; pd= while [ $_i -lt 30 ]; do rb 20 "$MSTPCTL" showportdetail "$BR" "$PA"; pd=$out has 'state forwarding' "$pd" && break _i=$((_i + 1)); sleep 1 done check_eq mstpd/mstp-state-machine "Designated forwarding" \ "$(printf '%s\n' "$pd" | awk '$1 == "enabled" && $3 == "role" { r = $4 } $1 == "port" && $2 == "id" { s = $5 } END { print r, s }')" else bst_skip mstpd/mstp-state-machine "no bridge port: the image's only interface is lo, which the bridge refuses, and the kernel made no veth pair (rc=$veth_rc $(_bst_1line "$veth_out")) -- CONFIG_VETH, brintos/linux#210" fi # showbridge, by value. The bridge id is priority.system-id.MAC: 8.000 is the # default priority 32768 with MSTI 0, and the MAC is the bridge's own address. # Alone, the bridge is its own designated root at path cost 0. The timers are # the 802.1D defaults and the protocol RSTP. mac=$(tr 'a-f' 'A-F' < "/sys/class/net/$BR/address" 2>/dev/null) rb 20 "$MSTPCTL" showbridge "$BR"; sb=$out check_eq mstpd/showbridge-fields \ "8.000.$mac 8.000.$mac 0 20 15 2 rstp" \ "$(printf '%s\n' "$sb" | awk ' /^ bridge id / { id = $3 } /^ designated root / { dr = $3 } /^ path cost / { pc = $3 } /^ max age / { ma = $3 } /^ forward delay / { fd = $3 } /^ hello time / { ht = $3 } /^ force protocol version / { pv = $4 } END { print id, dr, pc, ma, fd, ht, pv }')" # The MST Configuration Identifier. With no VID mapped to any MSTI the digest # is the 802.1Q default for "every VID on the CIST", AC36177F...DE62, and the # default name is the bridge MAC. setmstconfid changes name and revision and # leaves the digest, which depends only on the VID map, where it was. cid() { printf '%s\n' "$1" | awk -F': *' ' /Format Selector/ { f = $2 } /Configuration Name/ { n = $2 } /Revision Level/ { r = $2 } /Configuration Digest/ { d = $2 } END { print f, n, r, d }'; } rb 20 "$MSTPCTL" showmstconfid "$BR"; c0=$(cid "$out") rb 20 "$MSTPCTL" setmstconfid "$BR" 5 bstname; s_rc=$rc rb 20 "$MSTPCTL" showmstconfid "$BR"; c1=$(cid "$out") check_eq mstpd/showmstconfid \ "0 $(printf '%s' "$mac" | tr -d ':') 0 AC36177F50283CD4B83821D8AB26DE62|0|0 bstname 5 AC36177F50283CD4B83821D8AB26DE62" \ "$c0|$s_rc|$c1" # Per-port detail for the CIST: port id 8.001 is default port priority 128 # and port number 1, and 2000 is the 802.1D-2004 path cost of a 10 Gb/s link, # the speed a veth reports. if [ "$port" = yes ]; then rb 20 "$MSTPCTL" showportdetail "$BR" "$PA" check_eq mstpd/showportdetail "8.001 Designated 2000" \ "$(printf '%s\n' "$out" | awk '$1 == "port" && $2 == "id" { p = $3 } $1 == "enabled" && $3 == "role" { r = $4 } $1 == "external" { c = $4 } END { print p, r, c }')" else bst_skip mstpd/showportdetail "no bridge port: the image's only interface is lo, which the bridge refuses, and the kernel made no veth pair -- CONFIG_VETH, brintos/linux#210" fi # setmaxage/setfdelay/sethello round-trip through showbridge, and each one's # documented range (mstpctl help: 6-40, 4-30, 1-10) is refused at both ends # with the daemon's own message and mstpctl's 255. A refused value leaves the # accepted one in place. rb 20 "$MSTPCTL" setmaxage "$BR" 10; r1=$rc rb 20 "$MSTPCTL" setfdelay "$BR" 10; r2=$rc rb 20 "$MSTPCTL" sethello "$BR" 1; r3=$rc refusals= for _a in "setmaxage 50 Max Age must be between 6 and 40 seconds" \ "setmaxage 5 Max Age must be between 6 and 40 seconds" \ "setfdelay 31 Forward Delay must be between 4 and 30 seconds" \ "setfdelay 3 Forward Delay must be between 4 and 30 seconds" \ "sethello 11 Hello Time must be between 1 and 10" \ "sethello 0 Hello Time must be between 1 and 10"; do set -- $_a; _cmd=$1; _val=$2; shift 2 rb 20 "$MSTPCTL" "$_cmd" "$BR" "$_val" if [ "$rc" -eq 255 ] && has "$BR Bridge $*" "$out"; then :; else refusals="$refusals $_cmd=$_val:rc$rc" fi done rb 20 "$MSTPCTL" showbridge "$BR" check_eq mstpd/set-bridge-params "0 0 0|10 10 10 10 1|" \ "$r1 $r2 $r3|$(printf '%s\n' "$out" | awk ' /^ max age / { ma = $3; bma = $7 } /^ forward delay / { fd = $3; bfd = $7 } /^ hello time / { ht = $3 } END { print ma, bma, fd, bfd, ht }')|$refusals" # Batch mode validates each line's argument count and names the line, and an # unknown command in a batch is named the same way. Both sit behind # ctl_client_init(), so this is the first image they could be reached on. printf 'showbridge %s\nsetmaxage %s\n' "$BR" "$BR" > "$W/b1.txt" printf 'bogus-cmd %s\n' "$BR" > "$W/b2.txt" rb 20 "$MSTPCTL" -b "$W/b1.txt"; b1=$out; b1rc=$rc rb 20 "$MSTPCTL" -b "$W/b2.txt"; b2=$out; b2rc=$rc check_eq mstpd/batch-command-validation "1 yes yes|1 yes yes" \ "$b1rc $(yn has 'Error on line 2:' "$b1") $(yn has "Incorrect number of arguments for command 'setmaxage'" "$b1")|$b2rc $(yn has 'Error on line 1:' "$b2") $(yn has 'Unknown command [bogus-cmd]' "$b2")" # The same unknown command noctl-validation-unreachable ran, now that a # daemon answers: validation is reached and names it. rb 20 "$MSTPCTL" no-such-command check_eq mstpd/ctl-unknown-command "1 yes" "$rc $(yn has 'Unknown command [no-such-command]' "$out")" rb 20 "$MSTPCTL" delbridge "$BR"; d_rc=$rc rb 20 "$MSTPCTL" showbridge "$BR" check_eq mstpd/delbridge "0 yes" "$d_rc $([ "$rc" -ne 0 ] && echo yes || echo no)" fi # --- mstpd shutdown ----------------------------------------------------------- # TERM is mstpd's orderly stop: it exits 0, and the log it then flushes carries # the banner and sanity_check()'s verdict. sanity_check() verifies eight sizeof() # invariants over the packed on-wire MSTP structures; it is what would catch # wasm32 laying out __attribute__((packed)) differently. if [ -n "${MP:-}" ]; then alive=$(kill -0 "$MP" 2>/dev/null && echo yes || echo no) check_eq mstpd/start-stays-up "yes" "$alive" kill -TERM "$MP" 2>/dev/null _i=0 while [ $_i -lt 10 ] && kill -0 "$MP" 2>/dev/null; do _i=$((_i + 1)); sleep 1; done if kill -0 "$MP" 2>/dev/null; then kill -9 "$MP" 2>/dev/null; wait "$MP" 2>/dev/null bst_notok mstpd/start-term-exit "mstpd still running ${_i} s after SIGTERM; killed" else wait "$MP"; check_eq mstpd/start-term-exit "0" "$?" fi MP= start_out=$(cat "$W/mstpd.log" 2>/dev/null) check_eq mstpd/start-banner "yes" "$(yn has "Version - $VER" "$start_out")" check_eq mstpd/start-sanity-checks "yes" "$(yn has 'Sanity checks succeeded' "$start_out")" fi # --- the two config gaps, one attributed red each ----------------------------- # Written so that OK is GREEN on a kernel that has them. if [ "$br_exists" = yes ]; then bst_ok mstpd/bridge-device else bst_notok mstpd/bridge-device \ "no bridge device type on this kernel: wasm32_defconfig sets no CONFIG_BRIDGE and '# CONFIG_MODULES is not set', so __rtnl_newlink() answers EOPNOTSUPP 'Unknown device type' -- brintos/linux#109 (https://brintos.io/brintos/linux/issues/109). mstpctl's 39 commands all take a as argv[1]" fi if [ "$packet_proc" = present ]; then bst_ok mstpd/packet-socket else bst_notok mstpd/packet-socket \ "mstpd cannot open its BPDU socket: /proc/net/packet is absent, although the kernel is built CONFIG_PACKET=y -- brintos/linux#81 (https://brintos.io/brintos/linux/issues/81); same wall as lldpd/ports-initialised" fi