Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/scripts/ck_imac_bsdp_test.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / scripts / ck_imac_bsdp_test.sh` 324 lines ยท 19587 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # ck_imac_bsdp_test.sh -- host test for tools/ck_imac_bsdp.c (Apple NetBoot answerer). 3 # Runs the answerer on loopback high ports and plays the iMac with a small C client that 4 # sends the INFORM[LIST] the real iMac18,3 sent on 2026-10-17 (vendor class 5 # "AAPLBSDPC/i386/iMac18,3", option 43 = 01 01 01 02 02 01 01) plus a reply port, then an 6 # INFORM[SELECT] for the offered image; checks every answer field; then fetches the booter 7 # with curl over TFTP (blksize + tsize) and compares bytes; checks a wrong file name and a 8 # DHCP DISCOVER get nothing. A second and third answerer run with --reply-source-port: the answers 9 # must leave from that source port (the default run: from the listening port), with the same 10 # fields, client identifier echo, MAC restriction and TFTP. Loopback says nothing about the iMac 11 # firmware. 12 # read request that repeats blksize until a chained option answer would pass the end of its 13 # 128-byte buffer, and a clock gmtime cannot convert (LD_PRELOAD time shim). The server is 14 # built with ASan + UBSan, so any write past a buffer ends the test. Loopback says nothing 15 # about the iMac firmware. 16 # Final line: AIENOS_IMAC_BSDP: PASS|FAIL exit 0 / 1 17 set -euo pipefail 18 repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 19 tag="AIENOS_IMAC_BSDP" 20 W="$(mktemp -d)" 21 spid="" 22 spids=() 23 trap '[[ -z "${spid}" ]] || kill "${spid}" 2>/dev/null || true; for p in "${spids[@]}"; do kill "${p}" 2>/dev/null || true; done; rm -rf "${W}"' EXIT 24 fail() { echo "FAIL $1"; echo "${tag}: FAIL"; exit 1; } 25 pass() { echo "PASS $1"; } 26 command -v curl >/dev/null || { echo "${tag}: NOT_RUN (curl missing)"; exit 2; } 27 san=(-fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) 28 cc -std=gnu11 -O2 -Wall -Wextra -Werror "${san[@]}" -o "${W}/bsdp" "${repo_root}/native/kernel/tools/ck_imac_bsdp.c" 29 cc -std=gnu11 -O2 -Wall -Wextra -Werror -o "${W}/bsdp_plain" "${repo_root}/native/kernel/tools/ck_imac_bsdp.c" 30 cat >"${W}/client.c" <<'EOF' 31 #include 32 #include 33 #include 34 #include 35 #include 36 #include 37 #include 38 /* client SERVER_PORT REPLY_PORT list|select|discover -> prints the answer's fields 39 * client TFTP_PORT REPLY_PORT flood -> a read request with blksize repeated 12 times; 40 * prints the option answer (oack_len=N, then name=value lines) or "no answer" */ 41 static int flood(struct sockaddr_in to, int s) 42 { 43 uint8_t q[512]; 44 size_t n = 0; 45 memcpy(q, "\0\1aienos/netldr.efi\0octet", 26), n = 26; /* includes the NUL after "octet" */ 46 for (int i = 0; i < 12; i++) 47 memcpy(q + n, "blksize\0" "1428", 13), n += 13; 48 memcpy(q + n, "tsize\0" "0", 8), n += 8; 49 sendto(s, q, n, 0, (struct sockaddr *)&to, sizeof to); 50 struct pollfd pf = {s, POLLIN, 0}; 51 if (poll(&pf, 1, 3000) <= 0) { 52 printf("no answer\n"); 53 return 0; 54 } 55 uint8_t r[1600]; 56 struct sockaddr_in from; 57 socklen_t fl = sizeof from; 58 ssize_t k = recvfrom(s, r, sizeof r, 0, (struct sockaddr *)&from, &fl); 59 if (k < 2 || r[1] != 6) { 60 printf("not an option answer (opcode %d)\n", k >= 2 ? r[1] : -1); 61 return 0; 62 } 63 printf("oack_len=%zd\n", k); 64 for (ssize_t i = 2; i < k;) { 65 const char *name = (const char *)r + i; 66 size_t a = strnlen(name, (size_t)(k - i)); 67 if (i + (ssize_t)a + 1 >= k) 68 break; 69 const char *val = name + a + 1; 70 size_t b = strnlen(val, (size_t)(k - i - (ssize_t)a - 1)); 71 printf("%.*s=%.*s\n", (int)a, name, (int)b, val); 72 i += (ssize_t)(a + b + 2); 73 } 74 uint8_t err[] = {0, 5, 0, 0, 's', 't', 'o', 'p', 0}; /* end the transfer */ 75 sendto(s, err, sizeof err, 0, (struct sockaddr *)&from, sizeof from); 76 return 0; 77 } 78 /* client SERVER_PORT REPLY_PORT list|select|discover [none|short|max] [mac|other] -> prints the answer's fields 79 * and, last, src_port=N (the UDP source port the answer came from). 80 * The fourth argument picks the request's DHCP client identifier (option 61): none = absent, 81 * short = the iMac's 7 bytes (01 + MAC), max = 255 binary bytes (including 00 and ff). 82 * The fifth: other = a different client MAC (the server's --mac restriction must ignore it). */ 83 int main(int argc, char **argv) 84 { 85 int sp = atoi(argv[1]), rp = atoi(argv[2]); 86 int s = socket(AF_INET, SOCK_DGRAM, 0); 87 struct sockaddr_in me = {.sin_family = AF_INET, .sin_port = htons(rp), .sin_addr.s_addr = htonl(INADDR_LOOPBACK)}; 88 struct sockaddr_in to = {.sin_family = AF_INET, .sin_port = htons(sp), .sin_addr.s_addr = htonl(INADDR_LOOPBACK)}; 89 if (bind(s, (struct sockaddr *)&me, sizeof me) != 0) 90 return 3; 91 if (strcmp(argv[3], "flood") == 0) 92 return flood(to, s); 93 uint8_t p[800] = {0}; 94 size_t n = 240; 95 p[0] = 1, p[1] = 1, p[2] = 6; 96 p[4] = 0xd7, p[5] = 0xfe, p[6] = 0xa7, p[7] = 0x48; 97 p[12] = 127, p[15] = 1; /* ciaddr 127.0.0.1 (the iMac sent its leased address) */ 98 uint8_t mac[6] = {0x78, 0x7b, 0x8a, 0xbd, 0xd0, 0x51}; 99 if (argc > 5 && strcmp(argv[5], "other") == 0) 100 mac[5] = 0x52; 101 memcpy(p + 28, mac, 6); 102 p[236] = 0x63, p[237] = 0x82, p[238] = 0x53, p[239] = 0x63; 103 int disc = strcmp(argv[3], "discover") == 0, sel = strcmp(argv[3], "select") == 0; 104 p[n++] = 53, p[n++] = 1, p[n++] = disc ? 1 : 8; 105 p[n++] = 55, p[n++] = 2, p[n++] = 43, p[n++] = 60; 106 p[n++] = 57, p[n++] = 2, p[n++] = 0x05, p[n++] = 0xdc; 107 const char *cid = argc > 4 ? argv[4] : "none"; 108 if (strcmp(cid, "short") == 0) { 109 p[n++] = 61, p[n++] = 7, p[n++] = 1, memcpy(p + n, mac, 6), n += 6; 110 } else if (strcmp(cid, "max") == 0) { 111 p[n++] = 61, p[n++] = 255; 112 for (int i = 0; i < 255; i++) 113 p[n++] = (uint8_t)(i * 7 + 255); /* i=0 gives ff, i=1 gives 06, ... 00 appears too */ 114 } 115 p[n++] = 60, p[n++] = 23; 116 memcpy(p + n, "AAPLBSDPC/i386/iMac18,3", 23), n += 23; 117 if (sel) { 118 uint8_t v[] = {1, 1, 2, 2, 2, 1, 1, 5, 2, (uint8_t)(rp >> 8), (uint8_t)rp, 8, 4, 0x81, 0, 0, 1, 3, 4, 127, 0, 0, 1}; 119 p[n++] = 43, p[n++] = sizeof v, memcpy(p + n, v, sizeof v), n += sizeof v; 120 } else { 121 uint8_t v[] = {1, 1, 1, 2, 2, 1, 1, 5, 2, (uint8_t)(rp >> 8), (uint8_t)rp}; 122 p[n++] = 43, p[n++] = sizeof v, memcpy(p + n, v, sizeof v), n += sizeof v; 123 } 124 p[n++] = 255; 125 sendto(s, p, n, 0, (struct sockaddr *)&to, sizeof to); 126 struct pollfd pf = {s, POLLIN, 0}; 127 if (poll(&pf, 1, 2000) <= 0) { 128 printf("no answer\n"); 129 return 0; 130 } 131 uint8_t r[1600]; 132 struct sockaddr_in from; 133 socklen_t fl = sizeof from; 134 ssize_t k = recvfrom(s, r, sizeof r, 0, (struct sockaddr *)&from, &fl); 135 printf("op=%u xid=%02x%02x%02x%02x siaddr=%u.%u.%u.%u chaddr_ok=%d file=%s sname=%s\n", r[0], r[4], r[5], r[6], 136 r[7], r[20], r[21], r[22], r[23], memcmp(r + 28, mac, 6) == 0, (char *)r + 108, (char *)r + 44); 137 ssize_t i = 240; 138 for (; i + 1 < k && r[i] != 255;) { 139 uint8_t c = r[i], l = r[i + 1]; 140 if (i + 2 + l > k) 141 break; 142 printf("opt %u:", c); 143 for (int j = 0; j < l; j++) 144 printf(c == 60 || c == 17 ? "%c" : " %02x", r[i + 2 + j]); 145 printf("\n"); 146 i += 2 + l; 147 } 148 printf("end=%d len=%zd\n", i < k && r[i] == 255, k); 149 printf("src_port=%u\n", ntohs(from.sin_port)); 150 return 0; 151 } 152 EOF 153 cc -std=gnu11 -O2 -Wall -o "${W}/client" "${W}/client.c" 154 head -c 45056 /dev/urandom >"${W}/booter.efi" 155 printf 'MZ' | dd of="${W}/booter.efi" conv=notrunc status=none 156 bp=$((41000 + RANDOM % 4000)); tp=$((bp + 1)); rp=$((bp + 2)) 157 "${W}/bsdp" serve --booter "${W}/booter.efi" --server-ip 127.0.0.1 --mac 78:7b:8a:bd:d0:51 \ 158 --router 127.0.0.2 --bsdp-port "${bp}" --tftp-port "${tp}" --seconds 60 >"${W}/log" 2>&1 & 159 spid=$! 160 for _ in $(seq 1 50); do grep -q '^.* serving BSDP' "${W}/log" && break; sleep 0.1; done 161 grep -q 'serving BSDP' "${W}/log" || fail "server did not start: $(cat "${W}/log")" 162 163 "${W}/client" "${bp}" "${rp}" list >"${W}/list" 164 grep -q '^op=2 xid=`d7fea748` siaddr=127.0.0.1 chaddr_ok=1 ' "${W}/list" || fail "LIST answer header: $(cat "${W}/list")" 165 grep -q '^opt 53: 05$' "${W}/list" || fail "LIST answer is not a DHCP ACK" 166 grep -q '^opt 54: 7f 00 00 01$' "${W}/list" || fail "LIST answer server id" 167 grep -q '^opt 60:AAPLBSDPC$' "${W}/list" || fail "LIST answer vendor class" 168 grep -q "^opt 1: ff ff ff 00$" "${W}/list" || fail "LIST answer subnet mask" 169 grep -q '^opt 43: 01 01 01 04 02 80 00 07 04 81 00 00 01 09 0b 81 00 00 01 06 41 49 45 4e 4f 53$' "${W}/list" || 170 fail "LIST answer BSDP options: $(grep 'opt 43' "${W}/list")" 171 pass "INFORM[LIST] from iMac18,3 answered: ACK, one default image AIENOS (id 0x81000001, install image)" 172 173 "${W}/client" "${bp}" "${rp}" select >"${W}/sel" 174 grep -q '^op=2 xid=`d7fea748` siaddr=127.0.0.1 chaddr_ok=1 file=aienos/netldr.efi sname=spark$' "${W}/sel" || 175 fail "SELECT answer header: $(head -1 "${W}/sel")" 176 grep -q '^opt 43: 01 01 02 08 04 81 00 00 01 82 06 41 49 45 4e 4f 53$' "${W}/sel" || fail "SELECT answer BSDP options: $(grep 'opt 43' "${W}/sel")" 177 grep -q '^opt 17:tftp:127.0.0.1:/aienos/none$' "${W}/sel" || fail "SELECT answer root path" 178 pass "INFORM[SELECT] answered: boot file aienos/netldr.efi from this server" 179 180 # DHCP client identifier (option 61): RFC 6842 section 3 says a server that gets one must echo it 181 # byte for byte; no identifier in, none out. Short = the iMac's own 7 bytes, max = 255 binary bytes. 182 cid_short=" 01 78 7b 8a bd d0 51" 183 cid_max="" 184 for i in $(seq 0 254); do cid_max+="$(printf ' %02x' $(((i * 7 + 255) & 255)))"; done 185 for kind in list select; do 186 for cid in none short max; do 187 "${W}/client" "${bp}" "${rp}" "${kind}" "${cid}" >"${W}/${kind}.${cid}" 188 f="${W}/${kind}.${cid}" 189 grep -q '^op=2 xid=`d7fea748` siaddr=127.0.0.1 chaddr_ok=1 ' "${f}" || fail "${kind}/${cid}: no answer: $(head -1 "${f}")" 190 grep -q '^end=1 ' "${f}" || fail "${kind}/${cid}: answer options cut off or overran: $(tail -1 "${f}")" 191 grep -q '^opt 43: ' "${f}" || fail "${kind}/${cid}: answer lost its BSDP options" 192 [[ "${kind}" == list ]] || grep -q '^opt 17:tftp:127.0.0.1:/aienos/none$' "${f}" || fail "${kind}/${cid}: answer lost its root path" 193 n61="$(grep -c '^opt 61:' "${f}" || true)" 194 case "${cid}" in 195 none) [[ "${n61}" == 0 ]] || fail "${kind}/none: answer invented a client identifier: $(grep '^opt 61' "${f}")" ;; 196 short) [[ "$(grep '^opt 61:' "${f}")" == "opt 61:${cid_short}" && "${n61}" == 1 ]] || fail "${kind}/short: client identifier not echoed exactly: $(grep '^opt 61' "${f}")" ;; 197 max) [[ "$(grep '^opt 61:' "${f}")" == "opt 61:${cid_max}" && "${n61}" == 1 ]] || fail "${kind}/max: 255-byte client identifier not echoed exactly (${n61} copies): $(grep '^opt 61' "${f}" | cut -c1-80)" ;; 198 esac 199 done 200 done 201 pass "client identifier (option 61) echoed byte for byte on LIST and SELECT: absent stays absent, 7 bytes, 255 bytes, answer complete" 202 203 "${W}/client" "${bp}" "${rp}" discover >"${W}/disc" 204 grep -q '^no answer$' "${W}/disc" || fail "a DHCP DISCOVER got an answer (the router must stay the DHCP server)" 205 pass "DHCP DISCOVER ignored" 206 207 curl -s --tftp-blksize 1428 -o "${W}/got" "tftp://127.0.0.1:${tp}/aienos/netldr.efi" || fail "TFTP fetch failed: $(tail -3 "${W}/log")" 208 cmp -s "${W}/got" "${W}/booter.efi" || fail "TFTP bytes differ" 209 pass "TFTP delivered the booter byte for byte (blksize 1428)" 210 curl -s -o "${W}/got512" "tftp://127.0.0.1:${tp}/aienos/netldr.efi" && cmp -s "${W}/got512" "${W}/booter.efi" || 211 fail "TFTP default block size" 212 pass "TFTP delivered the booter with the default 512-byte blocks" 213 if curl -s -o "${W}/nope" "tftp://127.0.0.1:${tp}/etc/passwd"; then fail "TFTP served a file it should refuse"; fi 214 grep -q 'asked for "etc/passwd" (octet): refused' "${W}/log" || fail "refusal not logged" 215 pass "TFTP refused any other file" 216 217 "${W}/client" "${tp}" "${rp}" flood >"${W}/flood" 218 grep -q '^oack_len=' "${W}/flood" || fail "no option answer to a repeated-blksize request: $(cat "${W}/flood"); $(tail -5 "${W}/log")" 219 olen="$(sed -n 's/^oack_len=//p' "${W}/flood")" 220 ((olen <= 128)) || fail "option answer of ${olen} bytes exceeds its 128-byte buffer" 221 [[ "$(grep -c '^blksize=' "${W}/flood")" == 1 ]] || fail "blksize not acknowledged exactly once: $(cat "${W}/flood")" 222 grep -q '^blksize=1428$' "${W}/flood" || fail "blksize answer: $(cat "${W}/flood")" 223 grep -q '^tsize=45056$' "${W}/flood" || fail "tsize answer: $(cat "${W}/flood")" 224 sleep 0.5 225 kill -0 "${spid}" 2>/dev/null || fail "server died on a repeated-blksize request: $(tail -20 "${W}/log")" 226 if grep -qE 'AddressSanitizer|runtime error' "${W}/log"; then fail "sanitizer report: $(grep -E -A5 'AddressSanitizer|runtime error' "${W}/log")"; fi 227 pass "TFTP request with blksize repeated 12 times: one bounded option answer (${olen} bytes), server still serving" 228 229 cat >"${W}/timeshim.c" <<'EOF' 230 #include 231 /* A clock gmtime cannot convert (year beyond int); advances so --seconds still ends. */ 232 static time_t now = (time_t)1 << 62; 233 time_t time(time_t *t) 234 { 235 time_t v = now++; 236 if (t) 237 *t = v; 238 return v; 239 } 240 EOF 241 cc -std=gnu11 -O2 -Wall -shared -fPIC -o "${W}/timeshim.so" "${W}/timeshim.c" 242 rc=0 243 LD_PRELOAD="${W}/timeshim.so" "${W}/bsdp_plain" serve --booter "${W}/booter.efi" --server-ip 127.0.0.1 \ 244 --mac 78:7b:8a:bd:d0:51 --bsdp-port "$((bp + 10))" --tftp-port "$((bp + 11))" --seconds 3 >"${W}/log_clock" 2>&1 || rc=$? 245 [[ "${rc}" == 0 ]] || fail "server exited ${rc} on a clock gmtime cannot convert: $(cat "${W}/log_clock")" 246 grep -q 'serving BSDP' "${W}/log_clock" && grep -q 'deadline reached' "${W}/log_clock" || 247 fail "log lines missing under an unconvertible clock: $(cat "${W}/log_clock")" 248 pass "unconvertible clock: log lines still written, clean exit" 249 echo "---- server log ----"; cat "${W}/log" 250 251 # Default source port: the answers leave from the listening socket, so the source port is --bsdp-port. 252 for f in list sel; do 253 grep -q "^src_port=${bp}\$" "${W}/${f}" || fail "default: ${f} answer did not leave from the listening port ${bp}: $(grep '^src_port' "${W}/${f}")" 254 done 255 pass "default run: BSDP answers leave from the listening port (source port ${bp}), unchanged" 256 "${W}/client" "${bp}" "${rp}" list none other >"${W}/other" 257 grep -q '^no answer$' "${W}/other" || fail "a client with another MAC got an answer from the --mac restricted server" 258 pass "--mac restriction: a client with another MAC is ignored" 259 260 # --reply-source-port: same answers, from another UDP source port; requests still arrive on 261 # --bsdp-port, TFTP is untouched. Run 2 uses a distinct port, run 3 names the listening port itself 262 # (same as the default), then the unusable values must be refused. 263 start_server() { # name bsdp-port tftp-port extra-args... 264 local name="$1" b="$2" t="$3"; shift 3 265 "${W}/bsdp" serve --booter "${W}/booter.efi" --server-ip 127.0.0.1 --mac 78:7b:8a:bd:d0:51 \ 266 --router 127.0.0.2 --bsdp-port "${b}" --tftp-port "${t}" --seconds 60 "$@" >"${W}/${name}.log" 2>&1 & 267 spids+=($!) 268 for _ in $(seq 1 50); do grep -q 'serving BSDP' "${W}/${name}.log" && return 0; sleep 0.1; done 269 fail "${name}: server did not start: $(cat "${W}/${name}.log")" 270 } 271 check_reply_port() { # name bsdp-port tftp-port expected-source-port 272 local name="$1" b="$2" t="$3" want="$4" kind cid f 273 for kind in list select; do 274 for cid in none short max; do 275 f="${W}/${name}.${kind}.${cid}" 276 "${W}/client" "${b}" "${rp}" "${kind}" "${cid}" >"${f}" 277 grep -q '^op=2 xid=`d7fea748` siaddr=127.0.0.1 chaddr_ok=1 ' "${f}" || fail "${name} ${kind}/${cid}: no answer: $(head -1 "${f}")" 278 grep -q "^src_port=${want}\$" "${f}" || fail "${name} ${kind}/${cid}: answer source port is not ${want}: $(grep '^src_port' "${f}")" 279 grep -q '^end=1 ' "${f}" || fail "${name} ${kind}/${cid}: answer options cut off or overran" 280 grep -q '^opt 53: 05$' "${f}" && grep -q '^opt 54: 7f 00 00 01$' "${f}" && grep -q '^opt 60:AAPLBSDPC$' "${f}" && 281 grep -q '^opt 1: ff ff ff 00$' "${f}" || fail "${name} ${kind}/${cid}: ACK, server id, vendor class or mask changed" 282 if [[ "${kind}" == list ]]; then 283 grep -q '^opt 43: 01 01 01 04 02 80 00 07 04 81 00 00 01 09 0b 81 00 00 01 06 41 49 45 4e 4f 53$' "${f}" || 284 fail "${name} list/${cid}: BSDP options changed: $(grep 'opt 43' "${f}")" 285 else 286 grep -q '^op=2 xid=`d7fea748` siaddr=127.0.0.1 chaddr_ok=1 file=aienos/netldr.efi sname=spark$' "${f}" || fail "${name} select/${cid}: boot file changed" 287 grep -q '^opt 43: 01 01 02 08 04 81 00 00 01 82 06 41 49 45 4e 4f 53$' "${f}" || fail "${name} select/${cid}: BSDP options changed" 288 grep -q '^opt 17:tftp:127.0.0.1:/aienos/none$' "${f}" || fail "${name} select/${cid}: root path changed" 289 fi 290 case "${cid}" in 291 none) [[ "$(grep -c '^opt 61:' "${f}" || true)" == 0 ]] || fail "${name} ${kind}/none: invented a client identifier" ;; 292 short) [[ "$(grep '^opt 61:' "${f}")" == "opt 61:${cid_short}" ]] || fail "${name} ${kind}/short: client identifier not echoed exactly" ;; 293 max) [[ "$(grep '^opt 61:' "${f}")" == "opt 61:${cid_max}" ]] || fail "${name} ${kind}/max: 255-byte client identifier not echoed exactly" ;; 294 esac 295 done 296 done 297 "${W}/client" "${b}" "${rp}" discover >"${W}/${name}.disc" 298 grep -q '^no answer$' "${W}/${name}.disc" || fail "${name}: a DHCP DISCOVER got an answer" 299 "${W}/client" "${b}" "${rp}" list none other >"${W}/${name}.other" 300 grep -q '^no answer$' "${W}/${name}.other" || fail "${name}: a client with another MAC got an answer" 301 curl -s --tftp-blksize 1428 -o "${W}/${name}.got" "tftp://127.0.0.1:${t}/aienos/netldr.efi" || fail "${name}: TFTP fetch failed" 302 cmp -s "${W}/${name}.got" "${W}/booter.efi" || fail "${name}: TFTP bytes differ" 303 if curl -s -o "${W}/${name}.nope" "tftp://127.0.0.1:${t}/etc/passwd"; then fail "${name}: TFTP served a file it should refuse"; fi 304 } 305 sp=$((bp + 3)); bp2=$((bp + 4)); tp2=$((bp + 5)); bp3=$((bp + 6)); tp3=$((bp + 7)) 306 start_server rport "${bp2}" "${tp2}" --reply-source-port "${sp}" 307 grep -q "BSDP answers are sent from UDP source port ${sp}" "${W}/rport.log" || fail "reply source port not logged: $(cat "${W}/rport.log")" 308 check_reply_port rport "${bp2}" "${tp2}" "${sp}" 309 pass "--reply-source-port ${sp}: LIST and SELECT answers leave from source port ${sp} (requests read on ${bp2}), same fields and client identifier echo; DISCOVER and other MACs ignored; TFTP byte for byte" 310 start_server same "${bp3}" "${tp3}" --reply-source-port "${bp3}" 311 check_reply_port same "${bp3}" "${tp3}" "${bp3}" 312 grep -q 'BSDP answers are sent from UDP source port' "${W}/same.log" && fail "naming the listening port opened a second socket" 313 pass "--reply-source-port equal to --bsdp-port: same listening socket, source port ${bp3}" 314 for bad in 0 65536 -1 abc "" "${tp2}"; do 315 set +e 316 "${W}/bsdp" serve --booter "${W}/booter.efi" --server-ip 127.0.0.1 --bsdp-port "$((bp + 8))" --tftp-port "${tp2}" \ 317 --reply-source-port "${bad}" --seconds 1 >"${W}/bad.log" 2>&1 318 rc=$? 319 set -e 320 [[ "${rc}" == 2 ]] || fail "--reply-source-port '${bad}' was not refused with usage (exit ${rc})" 321 done 322 pass "--reply-source-port refuses 0, 65536, -1, text, empty and the TFTP port (exit 2)" 323 echo "---- server log ----"; cat "${W}/log"; echo "---- reply-source-port server log ----"; cat "${W}/rport.log" 324 echo "${tag}: PASS"