aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / scripts / ck_courier_udp_frame_test.sh
| 1 | #!/usr/bin/env bash |
| 2 | # Actual kernel-produced Ethernet frames, real relay UDP answers. All network |
| 3 | # setup and offload changes are confined to a fresh namespace; no live service, |
| 4 | # interface, firewall, model or hardware is touched. Requires Linux iproute2, |
| 5 | # ethtool, unshare and sudo -n (or root); host cc, rustc and cargo offline cache. |
| 6 | # KEEP_LOGS must name a new output directory if evidence is to be retained. |
| 7 | # COURIER_CAPTURE_SELF_LOOP=1 additionally records loopback UDP and waits for |
| 8 | # the relay's existing 10 s drop log after a failing baseline/mutant run. |
| 9 | set -euo pipefail |
| 10 | cd "$(dirname "$0")/.." |
| 11 | ROOT=$PWD |
| 12 | if [[ ${1:-} == --namespace ]]; then |
| 13 | W=$2 |
| 14 | cleanup_namespace() { |
| 15 | kill ${relay_pid:-} ${model_pid:-} ${capture_pid:-} 2>/dev/null || true |
| 16 | wait ${relay_pid:-} ${model_pid:-} ${capture_pid:-} 2>/dev/null || true |
| 17 | chown -R "${SUDO_UID:-0}:${SUDO_GID:-0}" "$W" |
| 18 | } |
| 19 | trap cleanup_namespace EXIT |
| 20 | ip link set lo up |
| 21 | ip link add imac0 type veth peer name spark0 |
| 22 | ip address add 192.168.1.108/24 broadcast 192.168.1.255 dev spark0 |
| 23 | ip link set imac0 up |
| 24 | ip link set spark0 up |
| 25 | # AF_PACKET sees final bytes, not veth CHECKSUM_PARTIAL metadata. |
| 26 | ethtool -K spark0 tx off |
| 27 | if [[ ${COURIER_CAPTURE_SELF_LOOP:-0} == 1 ]]; then |
| 28 | tcpdump -U -n -i lo -w "$W/self-loop.pcap" 'udp port 47033' >"$W/capture.log" 2>&1 & |
| 29 | capture_pid=$! |
| 30 | fi |
| 31 | "$W/model" "$W/model.port" 0 0 >"$W/model.log" 2>&1 & |
| 32 | model_pid=$! |
| 33 | for _ in {1..100}; do |
| 34 | [[ -s "$W/model.port" ]] && break |
| 35 | kill -0 "$model_pid" |
| 36 | sleep .02 |
| 37 | done |
| 38 | [[ -s "$W/model.port" ]] |
| 39 | model=$(cat "$W/model.port") |
| 40 | "$W/relay" --udp 47033 --udp-answer 192.168.1.255:47033 \ |
| 41 | --model "127.0.0.1:$model" --work "$W/work" --log-dir "$W/conversations" >"$W/relay.log" 2>&1 & |
| 42 | relay_pid=$! |
| 43 | # Wait for the socket, not an assumed server startup delay. |
| 44 | for _ in {1..100}; do |
| 45 | if ss -H -uln 'sport = :47033' | read -r _; then break; fi |
| 46 | kill -0 "$relay_pid" |
| 47 | sleep .02 |
| 48 | done |
| 49 | mkdir "$W/frames" |
| 50 | test_rc=0 |
| 51 | "$W/test" imac0 "$W/frames" || test_rc=$? |
| 52 | if [[ $test_rc != 0 ]]; then |
| 53 | if [[ ${COURIER_CAPTURE_SELF_LOOP:-0} == 1 ]]; then |
| 54 | sleep 7 # observe the existing LINE drop after its 10 s deadline |
| 55 | fi |
| 56 | exit "$test_rc" |
| 57 | fi |
| 58 | # A valid emitted GOT intentionally withheld at the frame-device seam must |
| 59 | # make the same test fail on the relay's actual LINE retransmission. |
| 60 | mkdir "$W/negative" |
| 61 | if "$W/test" imac0 "$W/negative" drop-got >"$W/drop-got.log" 2>&1; then |
| 62 | echo 'COURIER_FRAMES: FAIL dropped GOT control unexpectedly passed' |
| 63 | exit 1 |
| 64 | fi |
| 65 | if ! [[ $(cat "$W/drop-got.log") == *'relay retransmitted LINE after GOT'* ]]; then |
| 66 | cat "$W/drop-got.log" |
| 67 | echo 'COURIER_FRAMES: FAIL negative control failed for unrelated reason' |
| 68 | exit 1 |
| 69 | fi |
| 70 | echo 'COURIER_FRAME_ACK_CONTROL: PASS withholding GOT triggers real LINE retransmission' |
| 71 | exit |
| 72 | fi |
| 73 | W=$(mktemp -d "${TMPDIR:-/tmp}/ck_courier_frames.XXXXXX") |
| 74 | cleanup() { |
| 75 | if [[ -n ${KEEP_LOGS:-} ]]; then |
| 76 | cp -r "$W" "$KEEP_LOGS" |
| 77 | fi |
| 78 | rm -rf "$W" |
| 79 | } |
| 80 | trap cleanup EXIT |
| 81 | ${HOSTCC:-cc} -std=c11 -D_DEFAULT_SOURCE -O2 -Wall -Wextra -Werror -DCK_COURIER_HOST \ |
| 82 | -Inative/kernel/x86 -Inative/net -o "$W/test" \ |
| 83 | native/kernel/x86/tests/courier_udp_frame_test.c native/kernel/x86/courier_udp_x86.c native/net/aienos_net.c |
| 84 | rustc --edition=2021 -D warnings -O -o "$W/model" native/kernel/x86/tests/courier_model_fixture.rs |
| 85 | if [[ -n ${ALLEN_RELAY:-} ]]; then |
| 86 | cp "$ALLEN_RELAY" "$W/relay" |
| 87 | else |
| 88 | CARGO_TARGET_DIR="$W/target" cargo build --release --offline -p allen-courier |
| 89 | cp "$W/target/release/allen-courier" "$W/relay" |
| 90 | fi |
| 91 | if [[ $EUID == 0 ]]; then |
| 92 | COURIER_CAPTURE_SELF_LOOP=${COURIER_CAPTURE_SELF_LOOP:-0} unshare --net -- bash "$ROOT/scripts/ck_courier_udp_frame_test.sh" --namespace "$W" |
| 93 | else |
| 94 | sudo -n env COURIER_CAPTURE_SELF_LOOP="${COURIER_CAPTURE_SELF_LOOP:-0}" unshare --net -- bash "$ROOT/scripts/ck_courier_udp_frame_test.sh" --namespace "$W" |
| 95 | fi |