. "$BST_LIB" # BST-TIMEOUT: 300 # ~95 cases, ~110 execs, one daemon start whose readiness # # is its IPC socket (about 1 s measured). No loops and no # # corpus. Declared at roughly 5x the aoetools measurement # # next door (55 cases / 46 s on the same guest), which is the # # ratio 99-sg3-utils.test uses. Nothing here waits on a # # network: the routes and memberships are kernel table # # writes on a local veth pair. # smcroute -- a static multicast routing daemon, driven against the kernel's # IPv4 multicast routing table. # # WHAT IS ASSERTED. SMCRoute exists to drive the mrouted API: smcrouted opens a # raw IGMP socket, claims the API with setsockopt(MRT_INIT), makes one VIF per # multicast-capable interface, and installs (S,G) entries in the kernel's # multicast forwarding cache on smcroutectl's request. The kernel builds that # table (CONFIG_IP_MROUTE, brintos/linux#111), so the suite makes a veth pair -- # the image's only interface is lo, which carries no IFF_MULTICAST and so gets no # VIF -- starts the daemon on it, and reads every route and membership back # twice: through smcroutectl, and through /proc/net/ip_mr_vif, ip_mr_cache and # igmp, which are what the request actually changed. # # Around that: the .conf parser (every directive, every diagnostic, run under # `smcrouted -F`, which parses and returns without touching the kernel), the # client/daemon argument split, the usage and version text, and the client with # no daemon. Those are arithmetic on argv and strings, the same on every # architecture. # # WHAT IS PROBED RATHER THAN ASSUMED. Whether the kernel has the table, read at # runtime from ${LIBEXEC}/smcroute-tests/smcroute-probe. On a kernel that refuses # MRT_INIT the daemon cases are skips naming the gap, and the refusal cases run # instead: smcrouted must exit 76 (EX_PROTOCOL, smcrouted.8) with "Kernel does not # support multicast routing." -- the status this port carries a source patch for, # 0001-smcrouted-count-both-routing-APIs.patch, because stock 2.5.6 counts one # routing API per address family and so never returns it. # # AND THE CONTROLS ARE THE POINT OF THE PROBE. "MRT_INIT was refused" is a # statement about the kernel only while this process can still open ordinary # sockets. The probe therefore opens AF_INET stream, AF_INET datagram and AF_UNIX # stream in the same run, and every multicast-routing verdict below is gated on # all three succeeding. If they stop succeeding this suite REDS rather than # quietly skipping. # # NOT ASSERTED: a datagram forwarded between the two VIFs (no sender on the image # can set the route's source address), and IPv6 multicast routing (MRT6_INIT is # refused with ENOPROTOOPT: the kernel sets no CONFIG_IPV6_MROUTE). require smcrouted smcroute/present work=${TMPDIR:-/tmp}/bst-smcroute.$$ if ! mkdir -p "$work" 2>/dev/null; then bst_notok smcroute/workdir "cannot create $work -- the .conf fixtures below have nowhere to live" exit 0 fi bst_ok smcroute/workdir # --- the three programs upstream installs into ${sbindir} --------------------- # # smcrouted and smcroutectl are automake sbin_PROGRAMS; `smcroute` is a # dist_sbin_SCRIPTS shell wrapper installed by a different rule, so it can go # missing on its own without either binary noticing. for t in smcrouted smcroutectl smcroute; do if command -v "$t" >/dev/null 2>&1; then bst_ok "smcroute/present/$t" else bst_notok "smcroute/present/$t" "not installed" fi done # --- smcrouted: usage and version -------------------------------------------- check_rc smcroute/daemon/help-rc 0 smcrouted -h check_out smcroute/daemon/help-usage "[-hnNsv]" smcrouted -h check_out smcroute/daemon/help-verify-opt "Check configuration file syntax" smcrouted -h check_out smcroute/daemon/help-foreground "Run daemon in foreground" smcrouted -h check_rc smcroute/daemon/version-rc 0 smcrouted -v check_out smcroute/daemon/version-string "SMCRoute v2.5.6" smcrouted -v check_out smcroute/daemon/version-bugaddr "Bug report address: https://github.com/troglobit/smcroute/issues" smcrouted -v check_out smcroute/daemon/version-homepage "Project homepage: https://troglobit.com/smcroute.html" smcrouted -v # EX_USAGE. `-Z` is in neither getopt string, so getopt's default arm is what # answers -- the same arm every malformed invocation lands in. check_rc smcroute/daemon/unknown-option 64 smcrouted -Z # atoi("-1") < 0 is the daemon's only numeric argument rejection that does not # need the kernel: it is a range check on argv, decided before anything opens. check_rc smcroute/daemon/bad-table-id 64 smcrouted -t -1 # --- the client/daemon argument split ---------------------------------------- # # Two front-ends over one source tree, with DISJOINT option sets, and this is # where that is asserted rather than assumed. The daemon has no -a/-r/-j/-l: # adding and removing routes is the client's job, spoken over the IPC socket, and # a daemon that quietly accepted them would be a daemon that had grown a second # way to mutate the kernel. Symmetrically the client has no -f/-F/-l: it never # reads a .conf file and never opens a routing socket. # # Each of these is the getopt default arm, so the assertion is "this option is # not in this program's string" -- which is the split, stated in the only place # the programs actually enforce it. check_rc smcroute/split/daemon-has-no-add 64 smcrouted -a check_rc smcroute/split/daemon-has-no-remove 64 smcrouted -r check_rc smcroute/split/daemon-has-no-join 64 smcrouted -j check_rc smcroute/split/daemon-has-no-batch 64 smcrouted -b check_rc smcroute/split/client-has-no-conf 1 smcroutectl -f /dev/null check_rc smcroute/split/client-has-no-verify 1 smcroutectl -F /dev/null check_rc smcroute/split/client-has-no-loglvl 1 smcroutectl -l info # --- smcroutectl: usage and version ------------------------------------------ check_rc smcroute/client/help-rc 0 smcroutectl -h check_out smcroute/client/help-commands "Commands:" smcroutectl -h check_out smcroute/client/help-arguments "INBOUND" smcroutectl -h check_out smcroute/client/help-show "show routes" smcroutectl -h check_rc smcroute/client/version-rc 0 smcroutectl -v check_out smcroute/client/version-string "SMCRoute v2.5.6" smcroutectl -v check_rc smcroute/client/unknown-option 1 smcroutectl -Z # --- the client validates its own arguments BEFORE it opens the socket -------- # # `add` needs three, `remove`/`join`/`leave` two. parse() counts them against # args[].min_args and returns 1 with "Not enough arguments" without constructing # an IPC message, so these cases are true whether or not a daemon is running -- # which is what makes them assertions rather than observations of this image. for c in add remove join leave; do out=$(smcroutectl "$c" eth0 2>&1); rc=$? if bst_execfail "$out"; then bst_unrun "smcroute/client/short-args-$c" "$out" elif [ "$rc" -eq 1 ]; then case "$out" in *"Not enough arguments to command $c"*) bst_ok "smcroute/client/short-args-$c" ;; *) bst_notok "smcroute/client/short-args-$c" \ "rc=1 but not the argument-count diagnostic: $(_bst_1line "$out")" ;; esac else bst_notok "smcroute/client/short-args-$c" "rc=$rc want=1 -- $(_bst_1line "$out")" fi done # `help ` is the other half of the same parser: it resolves the command, # sees help was asked for, and prints that command's own example instead of # reaching the socket. check_rc smcroute/client/help-topic-rc 0 smcroutectl help add check_out smcroute/client/help-topic-eg "smcroutectl add eth0 192.168.2.42 225.1.2.3 eth1 eth2" smcroutectl help add # --- the client with no daemon ----------------------------------------------- # # Nothing is listening at the default socket: the one daemon this suite starts # runs later and on a socket in the suite's own directory, so ipc_connect() fails ENOENT # and every command reports it the same way. rc is 1 -- NOT a sysexits code: # smcroutectl's failures are plain 1, which is itself part of the split. The # diagnostic is ipc_connect()'s "Cannot find IPC socket " followed by # ipc_command()'s ENOENT arm; both were read off a native build of this same # source during the port, and either one satisfies the case. for c in "show" "kill" "flush"; do out=$(bst_bound 20 smcroutectl $c 2>&1); rc=$? if bst_execfail "$out"; then bst_unrun "smcroute/client/no-daemon-$c" "$out" elif [ "$rc" -eq 1 ]; then case "$out" in *"Cannot find IPC socket"*|*"Daemon may be running with another"*|*"Failed connecting to daemon"*|*"Daemon not running"*) bst_ok "smcroute/client/no-daemon-$c" ;; *) bst_notok "smcroute/client/no-daemon-$c" \ "rc=1 but no connect diagnostic: $(_bst_1line "$out")" ;; esac else bst_notok "smcroute/client/no-daemon-$c" "rc=$rc want=1 -- $(_bst_1line "$out")" fi done # --- the compatibility wrapper ----------------------------------------------- # # /usr/sbin/smcroute is a #!/bin/sh script, so its exit status is the shell's # rather than the package's -- its -h arm ends in a top-level `return`, which # busybox ash accepts and bash diagnoses. The TEXT is the package's either way, # so that is what is asserted; the dispatch arm below is what proves the wrapper # actually reaches smcroutectl rather than merely echoing. out=$(smcroute -h 2>/dev/null) case "$out" in *"compatibility wrapper script for SMCRoute"*) bst_ok smcroute/wrapper/help-text ;; *) bst_notok smcroute/wrapper/help-text "no wrapper help text: $(_bst_1line "$out")" ;; esac out=$(smcroute -Q 2>/dev/null) case "$out" in *"Unknown command or option to the SMCRoute compatiblity wrapper"*) bst_ok smcroute/wrapper/unknown-text ;; *) bst_notok smcroute/wrapper/unknown-text "no unknown-command text: $(_bst_1line "$out")" ;; esac check_out smcroute/wrapper/version-dispatch "SMCRoute v2.5.6" smcroute -v # --- the probe --------------------------------------------------------------- P=/usr/libexec/smcroute-tests/smcroute-probe if [ ! -x "$P" ]; then bst_notok smcroute/probe/present "no probe at $P -- smcroute-tests is not installed, so nothing below can be attributed" exit 0 fi bst_ok smcroute/probe/present PO=$("$P" 2>&1); prc=$? if bst_execfail "$PO"; then bst_unrun smcroute/probe/runs "$PO" exit 0 fi case "$PO" in *"probe end"*) bst_ok smcroute/probe/runs ;; *) bst_notok smcroute/probe/runs "rc=$prc, no 'probe end' -- the probe did not finish, so its values below are partial: $(_bst_1line "$PO")" exit 0 ;; esac # field -- the value of on the probe's # line. field() { printf '%s\n' "$PO" | sed -n "s/^$1 / /p" \ | sed -n "s/.*[ ]$2=\\([^ ]*\\).*/\\1/p" | sed -n 1p } # state -- the third word of a ` present|absent` line. state() { printf '%s\n' "$PO" | sed -n "s/^$1 [^ ]* \\([a-z]*\\)$/\\1/p" | sed -n 1p } inet_s=$(field inet-stream rc) inet_d=$(field inet-dgram rc) unix_s=$(field unix-stream rc) raw4=$(field raw-igmp rc) mrt4=$(field mrt-init rc) mrt4_err=$(printf '%s\n' "$PO" | sed -n 's/^mrt-init .*strerror=//p' | sed -n 1p) raw6=$(field raw-icmpv6 rc) inet6=$(field inet6-dgram rc) gifa=$(field getifaddrs rc) ifall=$(field ifcensus all) IF=$(field iface-first name) MIF=$(field iface-mcast name) ifmcast=$(field ifcensus mcast) mrvif=$(state proc-ip-mr-vif) mrcache=$(state proc-ip-mr-cache) # The controls, asserted as cases of their own. Every skip further down cites # them, so they must be visible rather than implied. check_eq smcroute/probe/control-inet-stream 0 "$inet_s" check_eq smcroute/probe/control-inet-dgram 0 "$inet_d" check_eq smcroute/probe/control-unix-stream 0 "$unix_s" controls_ok=0 [ "$inet_s" = 0 ] && [ "$inet_d" = 0 ] && [ "$unix_s" = 0 ] && controls_ok=1 # --- what the kernel actually answers ---------------------------------------- # # Reported as cases rather than as a comment, because the day one of them flips # is the day the skips below have to stop being skips. mrt-init is the whole # question: rc=0 means this kernel has a multicast routing table. if [ "$controls_ok" != 1 ]; then bst_notok smcroute/kernel/mroute-reading \ "the probe could not open ordinary sockets (inet-stream=$inet_s inet-dgram=$inet_d unix-stream=$unix_s), so nothing it says about multicast routing can be attributed to the kernel" elif [ "$mrt4" = 0 ]; then bst_ok smcroute/kernel/mroute-reading bst_ok smcroute/kernel/mroute-present elif [ "$raw4" != 0 ]; then bst_ok smcroute/kernel/mroute-reading bst_ok smcroute/kernel/mroute-absent # refused one step earlier, at socket(2) else bst_ok smcroute/kernel/mroute-reading bst_ok smcroute/kernel/mroute-absent fi # /proc/net/ip_mr_vif and ip_mr_cache are created by the kernel's own # CONFIG_IP_MROUTE code, so they are a second, independent reading of the same # fact -- and they must AGREE with MRT_INIT. A kernel that answered MRT_INIT # while publishing neither file, or the reverse, is doing something nobody has # modelled, and that is a red rather than a skip. # # The agreement is only assertable when MRT_INIT was actually ASKED. If the raw # IGMP socket never opened, mrt-init carries the not-attempted sentinel and there # is nothing for /proc to agree with -- so the two files are then held to # agreeing with EACH OTHER instead, which is still a real assertion (the same # kernel code creates both) and is not a claim the suite cannot support. if [ "$raw4" = 0 ]; then if [ "$mrt4" = 0 ]; then want_proc=present; else want_proc=absent; fi check_eq smcroute/kernel/proc-ip-mr-vif-agrees "$want_proc" "$mrvif" check_eq smcroute/kernel/proc-ip-mr-cache-agrees "$want_proc" "$mrcache" else check_eq smcroute/kernel/proc-ip-mr-files-agree "$mrvif" "$mrcache" fi # --- .conf parsing, the environment-independent half ------------------------- # # `smcrouted -F FILE` is a parse-and-return mode: main() runs iface_init(), # conf_read(), iface_exit() and returns, touching no socket and no kernel table. # It answers EX_OK (0) for a clean file and EX_CONFIG (78) for one with any # diagnostic in it, and under -F smclog() prints to stdout, so the diagnostic # text is assertable too. # # These eight need no interface to exist: every one of them is decided either # before the interface list is consulted or by the absence of a name from it. vrfy() { # vrfy -- conf text on stdin via $vrfy_text _vid=$1; _vwant=$2; _vneedle=$3 printf '%s\n' "$vrfy_text" > "$work/t.conf" _vout=$(bst_bound 20 smcrouted -F "$work/t.conf" 2>&1); _vrc=$? if bst_execfail "$_vout"; then bst_unrun "$_vid" "$_vout" return fi case "$_vout" in *"$_vneedle"*) _vhit=1 ;; *) _vhit=0 ;; esac if [ "$_vrc" -eq "$_vwant" ] && [ "$_vhit" -eq 1 ]; then bst_ok "$_vid" else bst_notok "$_vid" "rc=$_vrc want=$_vwant want:'$_vneedle' got:'$(_bst_1line "$_vout")'" fi } if [ "$gifa" != 0 ]; then bst_notok smcroute/conf/iface-list \ "getifaddrs(3) failed in the probe (rc=$gifa), and smcrouted -F calls it too -- the parser cases below would be measuring that failure, not the parser" else bst_ok smcroute/conf/iface-list : > "$work/empty.conf" check_rc smcroute/conf/empty-file 0 bst_bound 20 smcrouted -F "$work/empty.conf" vrfy_text='# a comment # an indented comment ' vrfy smcroute/conf/comments-only 0 "Verifying configuration file" # A file that is not there is EX_CONFIG under -F and merely a NOTICE without # it -- the daemon starts anyway and waits for a client. -F is the strict # reading, and this is the case that pins the difference. check_rc smcroute/conf/missing-file 78 bst_bound 20 smcrouted -F "$work/no-such-file.conf" vrfy_text='frobnicate from lo group 225.1.2.3' vrfy smcroute/conf/unknown-command 78 "Unknown command frobnicate" vrfy_text='phyint' vrfy smcroute/conf/phyint-missing-name 78 "phyint missing interface pattern" vrfy_text='phyint bstnosuchif0 enable' vrfy smcroute/conf/phyint-unknown-iface 78 "does not exist" vrfy_text='mroute from bstnosuchif0 source 192.168.1.42 group 225.1.2.3 to bstnosuchif1' vrfy smcroute/conf/mroute-unknown-iif 78 "matches no valid phyint" vrfy_text='mgroup from bstnosuchif0 group 225.1.2.3' vrfy smcroute/conf/mgroup-unknown-iif 78 "matches no valid phyint" fi # --- .conf parsing, the half that needs one interface to exist --------------- # # conf_parse() rejects any directive naming an interface that is not in the # getifaddrs(3) list BEFORE it parses that directive's addresses, so the address # and prefix-length parser -- the arithmetic this package's correctness actually # turns on -- is only reachable through a name that IS in the list. The probe # supplies one, or says there is none; it is not typed here, because which # interfaces a brintOS guest brings up is not this suite's to assert. if [ "$gifa" != 0 ]; then bst_skip smcroute/conf/address-parser \ "getifaddrs(3) failed in the probe (rc=$gifa), so there is no interface name to reach the address parser through" elif [ -z "$IF" ] || [ "$IF" = "-" ]; then bst_skip smcroute/conf/address-parser \ "the probe found no interfaces at all (ifcensus all=$ifall), so every directive is rejected on its interface name before its addresses are read" else bst_ok smcroute/conf/address-parser vrfy_text="phyint $IF enable mroute from $IF source 192.168.1.42 group 225.1.2.3 to $IF" vrfy smcroute/conf/valid-mroute 0 "Verifying configuration file" vrfy_text="phyint $IF enable mgroup from $IF group 225.1.2.3" vrfy smcroute/conf/valid-mgroup 0 "Verifying configuration file" # 10.1.2.3 is a perfectly good address and not a multicast one. This is the # is_multicast() arm, and it is the single assertion that most directly says # "the address parser was compiled correctly for this arm". vrfy_text="phyint $IF enable mroute from $IF source 192.168.1.42 group 10.1.2.3 to $IF" vrfy smcroute/conf/bad-group 78 "Invalid multicast group: 10.1.2.3" vrfy_text="phyint $IF enable mroute from $IF group 225.1.2.3/40 to $IF" vrfy smcroute/conf/bad-group-preflen 78 "Invalid multicast group prefix length" vrfy_text="phyint $IF enable mroute from $IF source 999.1.2.3 group 225.1.2.3 to $IF" vrfy smcroute/conf/bad-source 78 "Invalid source address: 999.1.2.3" vrfy_text="phyint $IF enable mgroup from $IF group 10.1.2.3" vrfy smcroute/conf/mgroup-bad-group 78 "Invalid multicast group" vrfy_text="phyint $IF enable ttl-threshold 300" vrfy smcroute/conf/ttl-out-of-range 78 "out of range (1-255)" vrfy_text="phyint $IF enable mroute from $IF group 225.1.2.3 to bstnosuchif1" vrfy smcroute/conf/unknown-oif 78 "outbound bstnosuchif1 is not a known phyint" # include is a glob(3) expansion, and an included file's own diagnostics are # logged rather than counted -- conf_parse() recurses and only warns. So the # assertion is that the include is FOLLOWED and the outer file still parses, # which is what the directive promises. printf '%s\n' "phyint $IF enable" > "$work/inc-a.conf" vrfy_text="include $work/inc-*.conf" vrfy smcroute/conf/include-glob 0 "Verifying configuration file" fi # --- the documented exit status, on a kernel WITHOUT multicast routing -------- # # THE case this port carries a source patch for. smcrouted.8 documents 76 # EX_PROTOCOL for "Kernel does not seem to support multicast routing", and stock # 2.5.6 cannot return it: `api = 2` counts one slot per address family while # mroute_init() collapses both into one boolean and the caller decrements once, # so the `!api` arm is dead code and the daemon instead enters its server loop # with no routing API at all -- indistinguishable, to anything supervising it, # from a daemon that is working. The patch makes mroute_init() attempt both # families and return how many failed. # # Reachable only where MRT_INIT is refused, so it is run only there and says # nothing on a kernel that has the table: there is no refusal to assert, and the # daemon block below is what runs instead. # # Run in the foreground (-n, which also routes the log to stderr via LOG_PERROR) # with -N so no VIFs are attempted, and with every path -- .conf, PID, IPC socket # -- pointed into this suite's own directory, so a failure to exit cannot leave a # listener behind for the client cases above to find on a later run. if [ "$controls_ok" != 1 ]; then bst_notok smcroute/daemon/no-mroute-exit \ "the probe could not open ordinary sockets (inet-stream=$inet_s inet-dgram=$inet_d unix-stream=$unix_s), so the daemon's refusal below could not be attributed to the kernel" elif [ "$mrt4" != 0 ]; then : > "$work/d.conf" out=$(bst_bound 20 smcrouted -n -N -f "$work/d.conf" -P "$work/d.pid" \ -u "$work/d.sock" -i bstsmcroute 2>&1); rc=$? if bst_execfail "$out"; then bst_unrun smcroute/daemon/no-mroute-exit "$out" bst_unrun smcroute/daemon/no-mroute-message "$out" else if [ "$rc" -eq 76 ]; then bst_ok smcroute/daemon/no-mroute-exit elif [ "$rc" -eq 124 ]; then bst_notok smcroute/daemon/no-mroute-exit \ "the daemon did not exit within 20 s -- it entered its server loop with no routing API, which is the stock 2.5.6 behaviour the api-accounting patch removes" else bst_notok smcroute/daemon/no-mroute-exit \ "rc=$rc want=76 (EX_PROTOCOL, smcrouted.8) with MRT_INIT refused ($mrt4_err) -- $(_bst_1line "$out")" fi case "$out" in *"Kernel does not support multicast routing."*) bst_ok smcroute/daemon/no-mroute-message ;; *) bst_notok smcroute/daemon/no-mroute-message \ "no 'Kernel does not support multicast routing.' on stderr -- $(_bst_1line "$out")" ;; esac fi # It must not have got far enough to publish an IPC socket: ipc_init() runs # after the abort point, and a socket here would mean the daemon served. if [ -e "$work/d.sock" ]; then bst_notok smcroute/daemon/no-ipc-socket "the daemon created $work/d.sock, so it reached ipc_init() -- it did not abort where it reports it did" else bst_ok smcroute/daemon/no-ipc-socket fi fi # --- the daemon on a kernel WITH multicast routing --------------------------- # # The package's actual purpose. Everything below is read twice: once through # smcroutectl, which reports the daemon's own tables, and once through the # kernel's /proc/net/ip_mr_vif, ip_mr_cache and igmp, which are what a route or # a membership actually changed. A daemon that answered "ok" to a route the # kernel never got would pass the first half and fail the second. # # THE INTERFACES ARE A VETH PAIR THE SUITE MAKES. The image boots with lo only, # and lo carries no IFF_MULTICAST, so mroute4_enable() would give it no VIF and # there would be nothing to route through. A veth pair is two multicast-capable # interfaces joined back to back, which is the smallest topology an (S,G) route # from one interface to another can name. Where the kernel cannot make one # (no CONFIG_VETH before brintos/linux#210) the route cases say so. # # The daemon is backgrounded directly, so $! is smcrouted itself, and stopped # through its own `kill' command with a TERM/KILL fallback by pid. Readiness is # the IPC socket appearing, not a fixed sleep. # has_word -- appears in as a whitespace-separated word. has_word() { printf '%s\n' "$1" | tr -s ' \t' '\n\n' | grep -qx "$2"; } smc() { bst_run 20 smcroutectl -u "$work/r.sock" "$@" -- the address as /proc/net/ip_mr_cache and igmp print it: # the raw __be32 through %08X, which on this little-endian arch is byte-reversed. hexaddr() { _IFS0=$IFS; IFS=.; set -- $1; IFS=$_IFS0 printf '%02X%02X%02X%02X' "$4" "$3" "$2" "$1" } # vifof -- the VIF number the kernel gave , or empty. vifof() { awk -v n="$1" '$2 == n { print $1 }' /proc/net/ip_mr_vif 2>/dev/null; } # mfc -- that (S,G) line of /proc/net/ip_mr_cache, columns # squeezed: " ...". mfc() { awk -v g="$(hexaddr "$1")" -v o="$(hexaddr "$2")" \ '$1 == g && $2 == o { $1 = $1; print }' /proc/net/ip_mr_cache 2>/dev/null } # igmp_has -- yes if /proc/net/igmp lists under . igmp_has() { awk -v n="$1" -v g="$(hexaddr "$2")" ' /^[0-9]/ { cur = $2 } /^\t/ && cur == n && $1 == g { f = 1 } END { print (f ? "yes" : "no") }' /proc/net/igmp 2>/dev/null } DAEMON_CASES="daemon/starts daemon/pidfile daemon/answers daemon/vifs daemon/show-interfaces route/install route/kernel-mfc route/show-routes route/ip-mroute route/template group/join-veth group/leave-veth group/join-lo group/leave-lo route/remove route/flush-keeps-static daemon/kill daemon/vifs-released" daemon_all() { # daemon_all for _c in $DAEMON_CASES; do if [ "$1" = skip ]; then bst_skip "smcroute/$_c" "$2"; else bst_notok "smcroute/$_c" "$2"; fi done } VA=bstsm0 VB=bstsm1 if [ "$controls_ok" != 1 ]; then daemon_all notok "the probe could not open ordinary sockets, so a daemon failure here would say nothing about multicast routing" elif [ "$mrt4" != 0 ]; then daemon_all skip "no multicast routing table on this kernel: raw-igmp rc=$raw4, MRT_INIT rc=$mrt4 ($mrt4_err), /proc/net/ip_mr_vif $mrvif, with all three control sockets open (CONFIG_IP_MROUTE: brintos/linux#111)" elif ! command -v ip >/dev/null 2>&1; then daemon_all notok "iproute2 ip is not on this image, so no multicast-capable interface can be made for the daemon to route through" else bst_run 30 ip link add "$VA" type veth peer name "$VB" if [ "$rc" -ne 0 ]; then daemon_all skip "no veth pair: the image's only interface is lo, which has no IFF_MULTICAST and so gets no VIF, and the kernel made no second one (rc=$rc $(_bst_1line "$out")) -- CONFIG_VETH, brintos/linux#210" else bst_run 20 ip link set "$VA" up; bst_run 20 ip link set "$VB" up trap 'kill -9 $_dpid 2>/dev/null; ip link del '"$VA"' 2>/dev/null' EXIT : > "$work/r.conf" smcrouted -n -f "$work/r.conf" -P "$work/r.pid" -u "$work/r.sock" \ -i bstsmcroute "$work/r.log" 2>&1 & _dpid=$! _i=0 while [ $_i -lt 30 ] && [ ! -S "$work/r.sock" ]; do kill -0 "$_dpid" 2>/dev/null || break _i=$((_i + 1)); sleep 1 done if [ ! -S "$work/r.sock" ]; then daemon_all notok "smcrouted published no IPC socket within ${_i} s on a kernel whose MRT_INIT succeeded -- $(_bst_1line "$(cat "$work/r.log" 2>/dev/null)")" else bst_ok smcroute/daemon/starts check_eq smcroute/daemon/pidfile "$_dpid" "$(cat "$work/r.pid" 2>/dev/null)" # It answers: `show interfaces' is served from the daemon's own # interface table, so a reply naming the pair is the IPC round trip. smc show interfaces; si=$out if [ "$rc" -eq 0 ] && has_word "$si" "$VA" && has_word "$si" "$VB"; then bst_ok smcroute/daemon/answers else bst_notok smcroute/daemon/answers "rc=$rc, no $VA/$VB in show interfaces: $(_bst_1line "$si")" fi # One VIF per IFF_MULTICAST interface, in the kernel's own table. via=$(vifof "$VA"); vib=$(vifof "$VB") if [ -n "$via" ] && [ -n "$vib" ]; then bst_ok smcroute/daemon/vifs else bst_notok smcroute/daemon/vifs "no VIF for $VA ('$via') or $VB ('$vib') in /proc/net/ip_mr_vif: $(_bst_1line "$(cat /proc/net/ip_mr_vif 2>/dev/null)")" fi # ...and the daemon's view of them is the kernel's: the VIF column of # `show interfaces' for the pair is the number /proc gave it. check_eq smcroute/daemon/show-interfaces "$VA $via|$VB $vib" \ "$(printf '%s\n' "$si" | awk -v a="$VA" -v b="$VB" '$2 == a { x = a " " $3 } $2 == b { y = b " " $3 } END { print x "|" y }')" # An (S,G) route from one veth to the other. smc add "$VA" 192.168.1.42 225.1.2.3 "$VB" check_eq smcroute/route/install 0 "$rc" check_eq smcroute/route/kernel-mfc \ "$(hexaddr 225.1.2.3) $(hexaddr 192.168.1.42) $via 0 0 0 $vib:1" \ "$(mfc 225.1.2.3 192.168.1.42)" smc show routes check_eq smcroute/route/show-routes yes \ "$(printf '%s\n' "$out" | grep -q "^(192\.168\.1\.42, 225\.1\.2\.3) *$VA *$VB *\$" && echo yes || echo no)" bst_run 20 ip mroute show check_eq smcroute/route/ip-mroute yes \ "$(printf '%s\n' "$out" | grep -q "^(192\.168\.1\.42,225\.1\.2\.3) *Iif: $VA *Oifs: $VB .*State: resolved" && echo yes || echo no)" # A (*,G) rule is a template: it waits for traffic to instantiate it, # so it is in the daemon's table and NOT in the kernel's. smc add "$VA" 225.1.2.6 "$VB"; trc=$rc smc show routes if [ "$trc" -eq 0 ] && printf '%s\n' "$out" | grep -q "^(\*, 225\.1\.2\.6) *$VA *$VB" \ && ! grep -q "^$(hexaddr 225.1.2.6) " /proc/net/ip_mr_cache; then bst_ok smcroute/route/template else bst_notok smcroute/route/template "rc=$trc; want (*, 225.1.2.6) in show routes and no kernel MFC entry: $(_bst_1line "$out")" fi # Group membership: IP_ADD_MEMBERSHIP through the daemon, read back in # /proc/net/igmp under the right device, then dropped again. smc join "$VA" 225.1.2.7 check_eq smcroute/group/join-veth "0 yes" "$rc $(igmp_has "$VA" 225.1.2.7)" smc leave "$VA" 225.1.2.7 check_eq smcroute/group/leave-veth "0 no" "$rc $(igmp_has "$VA" 225.1.2.7)" smc join lo 225.1.2.5 check_eq smcroute/group/join-lo "0 yes" "$rc $(igmp_has lo 225.1.2.5)" smc leave lo 225.1.2.5 check_eq smcroute/group/leave-lo "0 no" "$rc $(igmp_has lo 225.1.2.5)" # Remove the (S,G) route: gone from the kernel and from the daemon. smc remove "$VA" 192.168.1.42 225.1.2.3; rrc=$rc smc show routes check_eq smcroute/route/remove "0||no" \ "$rrc|$(mfc 225.1.2.3 192.168.1.42)|$(printf '%s\n' "$out" | grep -q '^(192\.168\.1\.42, 225\.1\.2\.3)' && echo yes || echo no)" # `flush' drops only the dynamic (*,G)-instantiated entries # (smcroutectl.8); a static (S,G) route stays in the kernel. smc add "$VA" 192.168.1.43 225.1.2.4 "$VB" smc flush; frc=$rc check_eq smcroute/route/flush-keeps-static "0 yes" \ "$frc $([ -n "$(mfc 225.1.2.4 192.168.1.43)" ] && echo yes || echo no)" # Stop it through its own command. MRT_DONE on exit releases every # VIF, so the kernel table is empty again afterwards. smc kill _i=0 while [ $_i -lt 10 ] && kill -0 "$_dpid" 2>/dev/null; do _i=$((_i + 1)); sleep 1; done if kill -0 "$_dpid" 2>/dev/null; then bst_notok smcroute/daemon/kill "smcrouted still running ${_i} s after smcroutectl kill" else wait "$_dpid"; check_eq smcroute/daemon/kill 0 "$?" fi check_eq smcroute/daemon/vifs-released 0 \ "$(awk 'NR > 1' /proc/net/ip_mr_vif 2>/dev/null | wc -l | tr -d ' ')" fi kill -TERM "$_dpid" 2>/dev/null; sleep 1; kill -9 "$_dpid" 2>/dev/null; wait "$_dpid" 2>/dev/null bst_run 20 ip link del "$VA" trap - EXIT fi fi # Forwarding a datagram between the two VIFs -- the Pkts column of the MFC entry # counting up -- needs a sender that can put a multicast datagram with the # route's source address onto one end of the pair, and this image carries no # traffic generator that can set the source address. The route, the VIFs and the # kernel entry are asserted above; the packet path is not. bst_skip smcroute/route/forwarding \ "no sender on this image can emit a multicast datagram with the route's source address into one end of the veth pair, so the MFC Pkts counter is not driven" rm -rf "$work" 2>/dev/null