1*d493b3c6Sriastradh# $NetBSD: t_inpcb_bind.sh,v 1.2 2023/08/05 13:25:26 riastradh Exp $ 23eb71caaSozaki-r# 33eb71caaSozaki-r# Copyright (c) 2022 Internet Initiative Japan Inc. 43eb71caaSozaki-r# All rights reserved. 53eb71caaSozaki-r# 63eb71caaSozaki-r# Redistribution and use in source and binary forms, with or without 73eb71caaSozaki-r# modification, are permitted provided that the following conditions 83eb71caaSozaki-r# are met: 93eb71caaSozaki-r# 1. Redistributions of source code must retain the above copyright 103eb71caaSozaki-r# notice, this list of conditions and the following disclaimer. 113eb71caaSozaki-r# 2. Redistributions in binary form must reproduce the above copyright 123eb71caaSozaki-r# notice, this list of conditions and the following disclaimer in the 133eb71caaSozaki-r# documentation and/or other materials provided with the distribution. 143eb71caaSozaki-r# 153eb71caaSozaki-r# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 163eb71caaSozaki-r# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 173eb71caaSozaki-r# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 183eb71caaSozaki-r# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 193eb71caaSozaki-r# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 203eb71caaSozaki-r# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 213eb71caaSozaki-r# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 223eb71caaSozaki-r# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 233eb71caaSozaki-r# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 243eb71caaSozaki-r# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 253eb71caaSozaki-r# POSSIBILITY OF SUCH DAMAGE. 263eb71caaSozaki-r# 273eb71caaSozaki-r 283eb71caaSozaki-rSOCK=unix://inpcb_bind 293eb71caaSozaki-rBUS=./bus 303eb71caaSozaki-r 313eb71caaSozaki-rDEBUG=${DEBUG:-false} 323eb71caaSozaki-rNAME="inpcb_bind" 333eb71caaSozaki-r 343eb71caaSozaki-rtest_inpcb_bind_ipv4() 353eb71caaSozaki-r{ 363eb71caaSozaki-r local addr="10.0.0.10" 373eb71caaSozaki-r local port=23000 383eb71caaSozaki-r local prog="$(atf_get_srcdir)/inpcb_bind" 393eb71caaSozaki-r 403eb71caaSozaki-r rump_server_start $SOCK 413eb71caaSozaki-r rump_server_add_iface $SOCK shmif0 $BUS 423eb71caaSozaki-r 433eb71caaSozaki-r export RUMP_SERVER=$SOCK 443eb71caaSozaki-r atf_check -s exit:0 rump.ifconfig shmif0 $addr/24 453eb71caaSozaki-r atf_check -s exit:0 -o ignore $HIJACKING $prog $addr $port 463eb71caaSozaki-r atf_check -s exit:0 -o ignore $HIJACKING $prog 224.0.2.1 $port $addr 473eb71caaSozaki-r} 483eb71caaSozaki-r 493eb71caaSozaki-rtest_inpcb_bind_ipv6() 503eb71caaSozaki-r{ 513eb71caaSozaki-r local addr="fc00::10" 523eb71caaSozaki-r local port=23000 533eb71caaSozaki-r local prog="$(atf_get_srcdir)/inpcb_bind" 543eb71caaSozaki-r 553eb71caaSozaki-r rump_server_start $SOCK netinet6 563eb71caaSozaki-r rump_server_add_iface $SOCK shmif0 $BUS 573eb71caaSozaki-r 583eb71caaSozaki-r export RUMP_SERVER=$SOCK 593eb71caaSozaki-r atf_check -s exit:0 rump.ifconfig shmif0 inet6 $addr/64 603eb71caaSozaki-r atf_check -s exit:0 -o ignore $HIJACKING $prog $addr $port 613eb71caaSozaki-r atf_check -s exit:0 -o ignore $HIJACKING $prog ff1e::123 $port $addr 623eb71caaSozaki-r} 633eb71caaSozaki-r 643eb71caaSozaki-radd_test() 653eb71caaSozaki-r{ 663eb71caaSozaki-r local name="${NAME}_$1" 673eb71caaSozaki-r local desc="$2" 683eb71caaSozaki-r 693eb71caaSozaki-r atf_test_case "${name}" cleanup 703eb71caaSozaki-r eval "${name}_head() { 713eb71caaSozaki-r atf_set descr \"${desc}\" 723eb71caaSozaki-r atf_set require.progs rump_server 73*d493b3c6Sriastradh atf_set require.user root 743eb71caaSozaki-r } 753eb71caaSozaki-r ${name}_body() { 763eb71caaSozaki-r test_${name} 773eb71caaSozaki-r } 783eb71caaSozaki-r ${name}_cleanup() { 793eb71caaSozaki-r \$DEBUG && dump 803eb71caaSozaki-r cleanup 813eb71caaSozaki-r }" 823eb71caaSozaki-r atf_add_test_case "${name}" 833eb71caaSozaki-r} 843eb71caaSozaki-r 853eb71caaSozaki-ratf_init_test_cases() 863eb71caaSozaki-r{ 873eb71caaSozaki-r 883eb71caaSozaki-r add_test ipv4 "tests for inpcb_bind (ipv4)" 893eb71caaSozaki-r add_test ipv6 "tests for inpcb_bind (ipv6)" 903eb71caaSozaki-r} 91