blob: aa3fdbcfe5a9dbd71c6a23a6c6351bb4cd3ba8db [file] [log] [blame]
Austin Schuh0a0a8272021-12-08 13:19:32 -08001#!/bin/bash
2
3set -euo pipefail
4
5result=0
6verify() {
7 local thisresult=0
8 local family
9 local address
10 family=$(echo "$output" | grep -Po '\] Family [^ ]+' | cut -f3 -d' ')
11 address=$(echo "$output" | grep -Po '\] Address [^ ]+' | cut -f3 -d' ')
12 if [[ "${family}" != "${1}" ]]; then
13 echo "Expected family ${1}, got ${family}" >&2
14 thisresult=1
15 result=1
16 fi
17 if [[ ! "${address}" =~ ${2} ]]; then
18 echo "Expected address ${2}, got ${address}" >&2
19 thisresult=1
20 result=1
21 fi
22 return $thisresult
23}
24
25run_test() {
26 local has_ipv6
27 has_ipv6="${1}"
28 export has_ipv6
29 shift
30 LD_PRELOAD="${SHIM}" "${BINARY}" --host=localhost "$@" 2>&1
31}
32
33BINARY="$1"
34SHIM="$2"
35
36output=$(run_test y)
37verify AF_INET6 "(::ffff:127.0.0.1|::)" || echo "IPv6 allowed with no arguments failed" >&2
38
39output=$(run_test n)
40verify AF_INET "127\\.0\\.0\\.1" || echo "IPv6 disallowed with no arguments failed" >&2
41
42output=$(run_test y --disable_ipv6)
43verify AF_INET "127\\.0\\.0\\.1" || echo "IPv6 allowed with --disable_ipv6 failed" >&2
44
45exit $result