1 #!/bin/sh 2 3 # Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4 # 5 # SPDX-License-Identifier: MPL-2.0 6 # 7 # This Source Code Form is subject to the terms of the Mozilla Public 8 # License, v. 2.0. If a copy of the MPL was not distributed with this 9 # file, you can obtain one at https://mozilla.org/MPL/2.0/. 10 # 11 # See the COPYRIGHT file distributed with this work for additional 12 # information regarding copyright ownership. 13 14 set -e 15 16 . ../conf.sh 17 18 DIGOPTS="+nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short +nocookie" 19 20 dig_cmd() { 21 # shellcheck disable=SC2086 22 "$DIG" $DIGOPTS -p "${PORT}" "$@" | grep -v '^;' 23 } 24 25 status=0 26 27 GOOD_RANDOM="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24" 28 GOOD_RANDOM_NO=24 29 30 if grep "^#define DNS_RDATASET_FIXED" "$TOP_BUILDDIR/config.h" >/dev/null 2>&1; then 31 test_fixed=true 32 else 33 echo_i "Order 'fixed' disabled at compile time" 34 test_fixed=false 35 fi 36 37 # 38 # 39 # 40 if $test_fixed; then 41 echo_i "Checking order fixed (primary)" 42 ret=0 43 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do 44 dig_cmd @10.53.0.1 fixed.example >dig.out.fixed || ret=1 45 diff dig.out.fixed reference.dig.out.fixed.good >/dev/null || ret=1 46 done 47 if [ $ret != 0 ]; then echo_i "failed"; fi 48 status=$((status + ret)) 49 else 50 echo_i "Checking order fixed behaves as cyclic when disabled (primary)" 51 ret=0 52 matches=0 53 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 54 j=$((i % 4)) 55 dig_cmd @10.53.0.1 fixed.example >dig.out.fixed || ret=1 56 if [ $i -le 4 ]; then 57 cp dig.out.fixed dig.out.$j 58 else 59 diff dig.out.fixed dig.out.$j >/dev/null && matches=$((matches + 1)) 60 fi 61 done 62 diff dig.out.0 dig.out.1 >/dev/null && ret=1 63 diff dig.out.0 dig.out.2 >/dev/null && ret=1 64 diff dig.out.0 dig.out.3 >/dev/null && ret=1 65 diff dig.out.1 dig.out.2 >/dev/null && ret=1 66 diff dig.out.1 dig.out.3 >/dev/null && ret=1 67 diff dig.out.2 dig.out.3 >/dev/null && ret=1 68 if [ $matches -ne 16 ]; then ret=1; fi 69 if [ $ret != 0 ]; then echo_i "failed"; fi 70 status=$((status + ret)) 71 fi 72 73 # 74 # 75 # 76 echo_i "Checking order cyclic (primary + additional)" 77 ret=0 78 matches=0 79 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 80 j=$((i % 4)) 81 dig_cmd @10.53.0.1 cyclic.example >dig.out.cyclic || ret=1 82 if [ $i -le 4 ]; then 83 cp dig.out.cyclic dig.out.$j 84 else 85 diff dig.out.cyclic dig.out.$j >/dev/null && matches=$((matches + 1)) 86 fi 87 done 88 diff dig.out.0 dig.out.1 >/dev/null && ret=1 89 diff dig.out.0 dig.out.2 >/dev/null && ret=1 90 diff dig.out.0 dig.out.3 >/dev/null && ret=1 91 diff dig.out.1 dig.out.2 >/dev/null && ret=1 92 diff dig.out.1 dig.out.3 >/dev/null && ret=1 93 diff dig.out.2 dig.out.3 >/dev/null && ret=1 94 if [ $matches -ne 16 ]; then ret=1; fi 95 if [ $ret != 0 ]; then echo_i "failed"; fi 96 status=$((status + ret)) 97 98 # 99 # 100 # 101 echo_i "Checking order cyclic (primary)" 102 ret=0 103 matches=0 104 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 105 j=$((i % 4)) 106 dig_cmd @10.53.0.1 cyclic2.example >dig.out.cyclic2 || ret=1 107 if [ $i -le 4 ]; then 108 cp dig.out.cyclic2 dig.out.$j 109 else 110 diff dig.out.cyclic2 dig.out.$j >/dev/null && matches=$((matches + 1)) 111 fi 112 done 113 diff dig.out.0 dig.out.1 >/dev/null && ret=1 114 diff dig.out.0 dig.out.2 >/dev/null && ret=1 115 diff dig.out.0 dig.out.3 >/dev/null && ret=1 116 diff dig.out.1 dig.out.2 >/dev/null && ret=1 117 diff dig.out.1 dig.out.3 >/dev/null && ret=1 118 diff dig.out.2 dig.out.3 >/dev/null && ret=1 119 if [ $matches -ne 16 ]; then ret=1; fi 120 if [ $ret != 0 ]; then echo_i "failed"; fi 121 status=$((status + ret)) 122 echo_i "Checking order random (primary)" 123 ret=0 124 for i in $GOOD_RANDOM; do 125 eval match$i=0 126 done 127 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 9; do 128 dig_cmd @10.53.0.1 random.example >dig.out.random || ret=1 129 match=0 130 for j in $GOOD_RANDOM; do 131 eval "diff dig.out.random reference.dig.out.random.good$j >/dev/null && match$j=1 match=1 || true" 132 if [ $match -eq 1 ]; then break; fi 133 done 134 if [ $match -eq 0 ]; then ret=1; fi 135 done 136 match=0 137 for i in $GOOD_RANDOM; do 138 eval "match=\$((match + match$i))" 139 done 140 echo_i "Random selection return $match of ${GOOD_RANDOM_NO} possible orders in 36 samples" 141 if [ $match -lt $((GOOD_RANDOM_NO / 3)) ]; then ret=1; fi 142 if [ $ret != 0 ]; then echo_i "failed"; fi 143 status=$((status + ret)) 144 145 echo_i "Checking order none (primary)" 146 ret=0 147 # Fetch the "reference" response and ensure it contains the expected records. 148 dig_cmd @10.53.0.1 none.example >dig.out.none || ret=1 149 for i in 1 2 3 4; do 150 grep -F -q 1.2.3.$i dig.out.none || ret=1 151 done 152 # Ensure 20 further queries result in the same response as the "reference" one. 153 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 154 dig_cmd @10.53.0.1 none.example >dig.out.test$i || ret=1 155 diff dig.out.none dig.out.test$i >/dev/null || ret=1 156 done 157 if [ $ret != 0 ]; then echo_i "failed"; fi 158 status=$((status + ret)) 159 160 # 161 # 162 # 163 if $test_fixed; then 164 echo_i "Checking order fixed (secondary)" 165 ret=0 166 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do 167 dig_cmd @10.53.0.2 fixed.example >dig.out.fixed || ret=1 168 diff dig.out.fixed reference.dig.out.fixed.good || ret=1 169 done 170 if [ $ret != 0 ]; then echo_i "failed"; fi 171 status=$((status + ret)) 172 fi 173 174 # 175 # 176 # 177 echo_i "Checking order cyclic (secondary + additional)" 178 ret=0 179 matches=0 180 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 181 j=$((i % 4)) 182 dig_cmd @10.53.0.2 cyclic.example >dig.out.cyclic || ret=1 183 if [ $i -le 4 ]; then 184 cp dig.out.cyclic dig.out.$j 185 else 186 diff dig.out.cyclic dig.out.$j >/dev/null && matches=$((matches + 1)) 187 fi 188 done 189 diff dig.out.0 dig.out.1 >/dev/null && ret=1 190 diff dig.out.0 dig.out.2 >/dev/null && ret=1 191 diff dig.out.0 dig.out.3 >/dev/null && ret=1 192 diff dig.out.1 dig.out.2 >/dev/null && ret=1 193 diff dig.out.1 dig.out.3 >/dev/null && ret=1 194 diff dig.out.2 dig.out.3 >/dev/null && ret=1 195 if [ $matches -ne 16 ]; then ret=1; fi 196 if [ $ret != 0 ]; then echo_i "failed"; fi 197 status=$((status + ret)) 198 199 # 200 # 201 # 202 echo_i "Checking order cyclic (secondary)" 203 ret=0 204 matches=0 205 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 206 j=$((i % 4)) 207 dig_cmd @10.53.0.2 cyclic2.example >dig.out.cyclic2 || ret=1 208 if [ $i -le 4 ]; then 209 cp dig.out.cyclic2 dig.out.$j 210 else 211 diff dig.out.cyclic2 dig.out.$j >/dev/null && matches=$((matches + 1)) 212 fi 213 done 214 diff dig.out.0 dig.out.1 >/dev/null && ret=1 215 diff dig.out.0 dig.out.2 >/dev/null && ret=1 216 diff dig.out.0 dig.out.3 >/dev/null && ret=1 217 diff dig.out.1 dig.out.2 >/dev/null && ret=1 218 diff dig.out.1 dig.out.3 >/dev/null && ret=1 219 diff dig.out.2 dig.out.3 >/dev/null && ret=1 220 if [ $matches -ne 16 ]; then ret=1; fi 221 if [ $ret != 0 ]; then echo_i "failed"; fi 222 status=$((status + ret)) 223 224 echo_i "Checking order random (secondary)" 225 ret=0 226 for i in $GOOD_RANDOM; do 227 eval match$i=0 228 done 229 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 9; do 230 dig_cmd @10.53.0.2 random.example >dig.out.random || ret=1 231 match=0 232 for j in $GOOD_RANDOM; do 233 eval "diff dig.out.random reference.dig.out.random.good$j >/dev/null && match$j=1 match=1 || true" 234 if [ $match -eq 1 ]; then break; fi 235 done 236 if [ $match -eq 0 ]; then ret=1; fi 237 done 238 match=0 239 for i in $GOOD_RANDOM; do 240 eval "match=\$((match + match$i))" 241 done 242 echo_i "Random selection return $match of ${GOOD_RANDOM_NO} possible orders in 36 samples" 243 if [ $match -lt $((GOOD_RANDOM_NO / 3)) ]; then ret=1; fi 244 if [ $ret != 0 ]; then echo_i "failed"; fi 245 status=$((status + ret)) 246 247 echo_i "Checking order none (secondary)" 248 ret=0 249 # Fetch the "reference" response and ensure it contains the expected records. 250 dig_cmd @10.53.0.2 none.example >dig.out.none || ret=1 251 for i in 1 2 3 4; do 252 grep -F -q 1.2.3.$i dig.out.none || ret=1 253 done 254 # Ensure 20 further queries result in the same response as the "reference" one. 255 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 256 dig_cmd @10.53.0.2 none.example >dig.out.test$i || ret=1 257 diff dig.out.none dig.out.test$i >/dev/null || ret=1 258 done 259 if [ $ret != 0 ]; then echo_i "failed"; fi 260 status=$((status + ret)) 261 262 echo_i "Shutting down secondary" 263 264 stop_server ns2 265 266 echo_i "Checking for secondary's on disk copy of zone" 267 268 if [ ! -f ns2/root.bk ]; then 269 echo_i "failed" 270 status=$((status + 1)) 271 fi 272 273 echo_i "Re-starting secondary" 274 275 start_server --noclean --restart --port ${PORT} ns2 276 277 # 278 # 279 # 280 if $test_fixed; then 281 echo_i "Checking order fixed (secondary loaded from disk)" 282 ret=0 283 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do 284 dig_cmd @10.53.0.2 fixed.example >dig.out.fixed || ret=1 285 diff dig.out.fixed reference.dig.out.fixed.good || ret=1 286 done 287 if [ $ret != 0 ]; then echo_i "failed"; fi 288 status=$((status + ret)) 289 fi 290 291 # 292 # 293 # 294 echo_i "Checking order cyclic (secondary + additional, loaded from disk)" 295 ret=0 296 matches=0 297 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 298 j=$((i % 4)) 299 dig_cmd @10.53.0.2 cyclic.example >dig.out.cyclic || ret=1 300 if [ $i -le 4 ]; then 301 cp dig.out.cyclic dig.out.$j 302 else 303 diff dig.out.cyclic dig.out.$j >/dev/null && matches=$((matches + 1)) 304 fi 305 done 306 diff dig.out.0 dig.out.1 >/dev/null && ret=1 307 diff dig.out.0 dig.out.2 >/dev/null && ret=1 308 diff dig.out.0 dig.out.3 >/dev/null && ret=1 309 diff dig.out.1 dig.out.2 >/dev/null && ret=1 310 diff dig.out.1 dig.out.3 >/dev/null && ret=1 311 diff dig.out.2 dig.out.3 >/dev/null && ret=1 312 if [ $matches -ne 16 ]; then ret=1; fi 313 if [ $ret != 0 ]; then echo_i "failed"; fi 314 status=$((status + ret)) 315 316 # 317 # 318 # 319 echo_i "Checking order cyclic (secondary loaded from disk)" 320 ret=0 321 matches=0 322 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 323 j=$((i % 4)) 324 dig_cmd @10.53.0.2 cyclic2.example >dig.out.cyclic2 || ret=1 325 if [ $i -le 4 ]; then 326 cp dig.out.cyclic2 dig.out.$j 327 else 328 diff dig.out.cyclic2 dig.out.$j >/dev/null && matches=$((matches + 1)) 329 fi 330 done 331 diff dig.out.0 dig.out.1 >/dev/null && ret=1 332 diff dig.out.0 dig.out.2 >/dev/null && ret=1 333 diff dig.out.0 dig.out.3 >/dev/null && ret=1 334 diff dig.out.1 dig.out.2 >/dev/null && ret=1 335 diff dig.out.1 dig.out.3 >/dev/null && ret=1 336 diff dig.out.2 dig.out.3 >/dev/null && ret=1 337 if [ $matches -ne 16 ]; then ret=1; fi 338 if [ $ret != 0 ]; then echo_i "failed"; fi 339 status=$((status + ret)) 340 341 echo_i "Checking order random (secondary loaded from disk)" 342 ret=0 343 for i in $GOOD_RANDOM; do 344 eval match$i=0 345 done 346 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 9; do 347 dig_cmd @10.53.0.2 random.example >dig.out.random || ret=1 348 match=0 349 for j in $GOOD_RANDOM; do 350 eval "diff dig.out.random reference.dig.out.random.good$j >/dev/null && match$j=1 match=1 || true" 351 if [ $match -eq 1 ]; then break; fi 352 done 353 if [ $match -eq 0 ]; then ret=1; fi 354 done 355 match=0 356 for i in $GOOD_RANDOM; do 357 eval "match=\$((match + match$i))" 358 done 359 echo_i "Random selection return $match of ${GOOD_RANDOM_NO} possible orders in 36 samples" 360 if [ $match -lt $((GOOD_RANDOM_NO / 3)) ]; then ret=1; fi 361 if [ $ret != 0 ]; then echo_i "failed"; fi 362 status=$((status + ret)) 363 364 echo_i "Checking order none (secondary loaded from disk)" 365 ret=0 366 # Fetch the "reference" response and ensure it contains the expected records. 367 dig_cmd @10.53.0.2 none.example >dig.out.none || ret=1 368 for i in 1 2 3 4; do 369 grep -F -q 1.2.3.$i dig.out.none || ret=1 370 done 371 # Ensure 20 further queries result in the same response as the "reference" one. 372 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 373 dig_cmd @10.53.0.2 none.example >dig.out.test$i || ret=1 374 diff dig.out.none dig.out.test$i >/dev/null || ret=1 375 done 376 if [ $ret != 0 ]; then echo_i "failed"; fi 377 status=$((status + ret)) 378 379 # 380 # 381 # 382 if $test_fixed; then 383 echo_i "Checking order fixed (cache)" 384 ret=0 385 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do 386 dig_cmd @10.53.0.3 fixed.example >dig.out.fixed || ret=1 387 diff dig.out.fixed reference.dig.out.fixed.good || ret=1 388 done 389 if [ $ret != 0 ]; then echo_i "failed"; fi 390 status=$((status + ret)) 391 fi 392 393 # 394 # 395 # 396 echo_i "Checking order cyclic (cache + additional)" 397 ret=0 398 # prime acache 399 dig_cmd @10.53.0.3 cyclic.example >dig.out.cyclic || ret=1 400 matches=0 401 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 402 j=$((i % 4)) 403 dig_cmd @10.53.0.3 cyclic.example >dig.out.cyclic || ret=1 404 if [ $i -le 4 ]; then 405 cp dig.out.cyclic dig.out.$j 406 else 407 diff dig.out.cyclic dig.out.$j >/dev/null && matches=$((matches + 1)) 408 fi 409 done 410 diff dig.out.0 dig.out.1 >/dev/null && ret=1 411 diff dig.out.0 dig.out.2 >/dev/null && ret=1 412 diff dig.out.0 dig.out.3 >/dev/null && ret=1 413 diff dig.out.1 dig.out.2 >/dev/null && ret=1 414 diff dig.out.1 dig.out.3 >/dev/null && ret=1 415 diff dig.out.2 dig.out.3 >/dev/null && ret=1 416 if [ $matches -ne 16 ]; then ret=1; fi 417 if [ $ret != 0 ]; then echo_i "failed"; fi 418 status=$((status + ret)) 419 420 # 421 # 422 # 423 echo_i "Checking order cyclic (cache)" 424 ret=0 425 # prime acache 426 dig_cmd @10.53.0.3 cyclic2.example >dig.out.cyclic2 || ret=1 427 matches=0 428 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 429 j=$((i % 4)) 430 dig_cmd @10.53.0.3 cyclic2.example >dig.out.cyclic2 || ret=1 431 if [ $i -le 4 ]; then 432 cp dig.out.cyclic2 dig.out.$j 433 else 434 diff dig.out.cyclic2 dig.out.$j >/dev/null && matches=$((matches + 1)) 435 fi 436 done 437 diff dig.out.0 dig.out.1 >/dev/null && ret=1 438 diff dig.out.0 dig.out.2 >/dev/null && ret=1 439 diff dig.out.0 dig.out.3 >/dev/null && ret=1 440 diff dig.out.1 dig.out.2 >/dev/null && ret=1 441 diff dig.out.1 dig.out.3 >/dev/null && ret=1 442 diff dig.out.2 dig.out.3 >/dev/null && ret=1 443 if [ $matches -ne 16 ]; then ret=1; fi 444 if [ $ret != 0 ]; then echo_i "failed"; fi 445 status=$((status + ret)) 446 447 echo_i "Checking order random (cache)" 448 ret=0 449 for i in $GOOD_RANDOM; do 450 eval match$i=0 451 done 452 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 9; do 453 dig_cmd @10.53.0.3 random.example >dig.out.random || ret=1 454 match=0 455 for j in $GOOD_RANDOM; do 456 eval "diff dig.out.random reference.dig.out.random.good$j >/dev/null && match$j=1 match=1 || true" 457 if [ $match -eq 1 ]; then break; fi 458 done 459 if [ $match -eq 0 ]; then ret=1; fi 460 done 461 match=0 462 for i in $GOOD_RANDOM; do 463 eval "match=\$((match + match$i))" 464 done 465 echo_i "Random selection return $match of ${GOOD_RANDOM_NO} possible orders in 36 samples" 466 if [ $match -lt $((GOOD_RANDOM_NO / 3)) ]; then ret=1; fi 467 if [ $ret != 0 ]; then echo_i "failed"; fi 468 status=$((status + ret)) 469 470 echo_i "Checking order none (cache)" 471 ret=0 472 # Fetch the "reference" response and ensure it contains the expected records. 473 dig_cmd @10.53.0.3 none.example >dig.out.none || ret=1 474 for i in 1 2 3 4; do 475 grep -F -q 1.2.3.$i dig.out.none || ret=1 476 done 477 # Ensure 20 further queries result in the same response as the "reference" one. 478 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 479 dig_cmd @10.53.0.3 none.example >dig.out.test$i || ret=1 480 diff dig.out.none dig.out.test$i >/dev/null || ret=1 481 done 482 if [ $ret != 0 ]; then echo_i "failed"; fi 483 status=$((status + ret)) 484 485 echo_i "Checking default order (cache)" 486 ret=0 487 for i in $GOOD_RANDOM; do 488 eval match$i=0 489 done 490 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 9; do 491 dig_cmd @10.53.0.5 random.example >dig.out.random || ret=1 492 match=0 493 for j in $GOOD_RANDOM; do 494 eval "diff dig.out.random reference.dig.out.random.good$j >/dev/null && match$j=1 match=1 || true" 495 if [ $match -eq 1 ]; then break; fi 496 done 497 if [ $match -eq 0 ]; then ret=1; fi 498 done 499 match=0 500 for i in $GOOD_RANDOM; do 501 eval "match=\$((match + match$i))" 502 done 503 echo_i "Default selection return $match of ${GOOD_RANDOM_NO} possible orders in 36 samples" 504 if [ $match -lt $((GOOD_RANDOM_NO / 3)) ]; then ret=1; fi 505 if [ $ret != 0 ]; then echo_i "failed"; fi 506 status=$((status + ret)) 507 508 echo_i "Checking default order no match in rrset-order (cache)" 509 ret=0 510 # Fetch the "reference" response and ensure it contains the expected records. 511 dig_cmd @10.53.0.4 nomatch.example >dig.out.nomatch || ret=1 512 for i in 1 2 3 4; do 513 grep -F -q 1.2.3.$i dig.out.nomatch || ret=1 514 done 515 # Ensure 20 further queries result in the same response as the "reference" one. 516 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do 517 dig_cmd @10.53.0.4 nomatch.example >dig.out.test$i || ret=1 518 diff dig.out.nomatch dig.out.test$i >/dev/null || ret=1 519 done 520 if [ $ret != 0 ]; then echo_i "failed"; fi 521 status=$((status + ret)) 522 523 echo_i "exit status: $status" 524 [ $status -eq 0 ] || exit 1 525