1eb5e0755SKristof Provost# 2*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 3eb5e0755SKristof Provost# 4eb5e0755SKristof Provost# Copyright (c) 2021 Rubicon Communications, LLC (Netgate) 5eb5e0755SKristof Provost# 6eb5e0755SKristof Provost# Redistribution and use in source and binary forms, with or without 7eb5e0755SKristof Provost# modification, are permitted provided that the following conditions 8eb5e0755SKristof Provost# are met: 9eb5e0755SKristof Provost# 1. Redistributions of source code must retain the above copyright 10eb5e0755SKristof Provost# notice, this list of conditions and the following disclaimer. 11eb5e0755SKristof Provost# 2. Redistributions in binary form must reproduce the above copyright 12eb5e0755SKristof Provost# notice, this list of conditions and the following disclaimer in the 13eb5e0755SKristof Provost# documentation and/or other materials provided with the distribution. 14eb5e0755SKristof Provost# 15eb5e0755SKristof Provost# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16eb5e0755SKristof Provost# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17eb5e0755SKristof Provost# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18eb5e0755SKristof Provost# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19eb5e0755SKristof Provost# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20eb5e0755SKristof Provost# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21eb5e0755SKristof Provost# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22eb5e0755SKristof Provost# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23eb5e0755SKristof Provost# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24eb5e0755SKristof Provost# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25eb5e0755SKristof Provost# SUCH DAMAGE. 26eb5e0755SKristof Provost 27eb5e0755SKristof Provost. $(atf_get_srcdir)/../common/vnet.subr 28eb5e0755SKristof Provost 29eb5e0755SKristof Provostatf_test_case "6to4" "cleanup" 30eb5e0755SKristof Provost6to4_head() 31eb5e0755SKristof Provost{ 32eb5e0755SKristof Provost atf_set descr 'Test 6to4' 33eb5e0755SKristof Provost atf_set require.user root 34eb5e0755SKristof Provost} 35eb5e0755SKristof Provost 36eb5e0755SKristof Provost6to4_body() 37eb5e0755SKristof Provost{ 38eb5e0755SKristof Provost vnet_init 39eb5e0755SKristof Provost if ! kldstat -q -m if_stf; then 40eb5e0755SKristof Provost atf_skip "This test requires if_stf" 41eb5e0755SKristof Provost fi 42eb5e0755SKristof Provost if ! kldstat -q -m if_gif; then 4367573b7aSKristof Provost atf_skip "This test requires if_gif" 44eb5e0755SKristof Provost fi 45eb5e0755SKristof Provost 46eb5e0755SKristof Provost epair=$(vnet_mkepair) 47eb5e0755SKristof Provost 48eb5e0755SKristof Provost vnet_mkjail relay ${epair}a 49eb5e0755SKristof Provost jexec relay ifconfig lo0 inet6 2001:db8::1/64 up 50eb5e0755SKristof Provost jexec relay ifconfig ${epair}a 192.0.2.1/24 up 51eb5e0755SKristof Provost # Simple gif to terminate 6to4 52eb5e0755SKristof Provost gif=$(jexec relay ifconfig gif create) 53eb5e0755SKristof Provost jexec relay ifconfig $gif inet6 2002:c000:0201::1/64 up 54eb5e0755SKristof Provost jexec relay ifconfig $gif tunnel 192.0.2.1 192.0.2.2 55eb5e0755SKristof Provost jexec relay route -6 add default -interface $gif 56eb5e0755SKristof Provost 57eb5e0755SKristof Provost vnet_mkjail client ${epair}b 5867573b7aSKristof Provost jexec client ifconfig lo0 up 59eb5e0755SKristof Provost jexec client ifconfig ${epair}b 192.0.2.2/24 up 60eb5e0755SKristof Provost stf=$(jexec client ifconfig stf create) 61eb5e0755SKristof Provost jexec client ifconfig $stf inet6 2002:c000:0202::1/32 up 62eb5e0755SKristof Provost jexec client route -6 add default 2002:c000:0201::1 63eb5e0755SKristof Provost 64eb5e0755SKristof Provost # Sanity check 65eb5e0755SKristof Provost atf_check -s exit:0 -o ignore \ 66eb5e0755SKristof Provost jexec client ping -c 1 192.0.2.1 67eb5e0755SKristof Provost # 6to4 direct 68eb5e0755SKristof Provost atf_check -s exit:0 -o ignore \ 69eb5e0755SKristof Provost jexec client ping6 -c 1 2002:c000:0201::1 70eb5e0755SKristof Provost 71eb5e0755SKristof Provost # "Wider internet" 72eb5e0755SKristof Provost atf_check -s exit:0 -o ignore \ 73eb5e0755SKristof Provost jexec client ping6 -c 1 2001:db8::1 74eb5e0755SKristof Provost} 75eb5e0755SKristof Provost 76eb5e0755SKristof Provost6to4_cleanup() 77eb5e0755SKristof Provost{ 78eb5e0755SKristof Provost vnet_cleanup 79eb5e0755SKristof Provost} 80eb5e0755SKristof Provost 81e1b95017SKristof Provostatf_test_case "6rd" "cleanup" 82e1b95017SKristof Provost6rd_head() 83e1b95017SKristof Provost{ 84e1b95017SKristof Provost atf_set descr '6RD test' 85e1b95017SKristof Provost atf_set require.user root 86e1b95017SKristof Provost} 87e1b95017SKristof Provost 88e1b95017SKristof Provost6rd_body() 89e1b95017SKristof Provost{ 90e1b95017SKristof Provost vnet_init 91e1b95017SKristof Provost 92e1b95017SKristof Provost if ! kldstat -q -m if_stf; then 93e1b95017SKristof Provost atf_skip "This test requires if_stf" 94e1b95017SKristof Provost fi 95e1b95017SKristof Provost if ! kldstat -q -m if_gif; then 96e1b95017SKristof Provost atf_skip "This test requires if_gif" 97e1b95017SKristof Provost fi 98e1b95017SKristof Provost 99e1b95017SKristof Provost epair=$(vnet_mkepair) 100e1b95017SKristof Provost vnet_mkjail br ${epair}a 101e1b95017SKristof Provost jexec br ifconfig ${epair}a 192.0.2.1/24 up 102e1b95017SKristof Provost 103e1b95017SKristof Provost # Simple gif to terminate the 6RD tunnel 104e1b95017SKristof Provost gif=$(jexec br ifconfig gif create) 105e1b95017SKristof Provost jexec br ifconfig lo0 inet6 2001:db9::1/64 up 106e1b95017SKristof Provost jexec br ifconfig $gif inet6 2001:db8::/64 up 107e1b95017SKristof Provost jexec br ifconfig $gif tunnel 192.0.2.1 192.0.2.2 108e1b95017SKristof Provost jexec br route -6 add default -interface $gif 109e1b95017SKristof Provost 110e1b95017SKristof Provost vnet_mkjail client ${epair}b 111e1b95017SKristof Provost jexec client ifconfig lo0 up 112e1b95017SKristof Provost jexec client ifconfig ${epair}b 192.0.2.2/24 up 113e1b95017SKristof Provost 114e1b95017SKristof Provost # Sanity check 115e1b95017SKristof Provost atf_check -s exit:0 -o ignore \ 116e1b95017SKristof Provost jexec client ping -c 1 192.0.2.1 117e1b95017SKristof Provost 118e1b95017SKristof Provost stf=$(jexec client ifconfig stf create) 119e1b95017SKristof Provost 120e1b95017SKristof Provost jexec client ifconfig $stf stfv4br 192.0.2.1 121e1b95017SKristof Provost jexec client ifconfig $stf stfv4net 192.0.2.2/32 122e1b95017SKristof Provost jexec client ifconfig $stf inet6 2001:db8:c000:0202::1/32 up 123e1b95017SKristof Provost jexec client route -6 add default -interface $stf 124e1b95017SKristof Provost 125e1b95017SKristof Provost atf_check -s exit:0 -o ignore \ 126e1b95017SKristof Provost jexec client ping6 -c 1 2001:db9::1 127e1b95017SKristof Provost} 128e1b95017SKristof Provost 129e1b95017SKristof Provost6rd_cleanup() 130e1b95017SKristof Provost{ 131e1b95017SKristof Provost vnet_cleanup 132e1b95017SKristof Provost} 133e1b95017SKristof Provost 1342610dcc1SKristof Provostatf_test_case "6rd_peer" "cleanup" 1352610dcc1SKristof Provost6rd_peer_head() 1362610dcc1SKristof Provost{ 1372610dcc1SKristof Provost atf_set descr '6RD peer test' 1382610dcc1SKristof Provost atf_set require.user root 1392610dcc1SKristof Provost} 1402610dcc1SKristof Provost 1412610dcc1SKristof Provost6rd_peer_body() 1422610dcc1SKristof Provost{ 1432610dcc1SKristof Provost vnet_init 1442610dcc1SKristof Provost 1452610dcc1SKristof Provost if ! kldstat -q -m if_stf; then 1462610dcc1SKristof Provost atf_skip "This test requires if_stf" 1472610dcc1SKristof Provost fi 1482610dcc1SKristof Provost 1492610dcc1SKristof Provost epair=$(vnet_mkepair) 1502610dcc1SKristof Provost 1512610dcc1SKristof Provost vnet_mkjail one ${epair}a 1522610dcc1SKristof Provost jexec one ifconfig lo0 up 1532610dcc1SKristof Provost jexec one ifconfig ${epair}a 192.0.2.1/24 up 1542610dcc1SKristof Provost stf_one=$(jexec one ifconfig stf create) 1552610dcc1SKristof Provost jexec one ifconfig $stf_one stfv4br 192.0.2.3 1562610dcc1SKristof Provost jexec one ifconfig $stf_one stfv4net 192.0.2.1/32 1572610dcc1SKristof Provost jexec one ifconfig $stf_one inet6 2001:db8:c000:0201::1/32 up 1582610dcc1SKristof Provost jexec one route -6 add default -interface $stf_one 1592610dcc1SKristof Provost 1602610dcc1SKristof Provost vnet_mkjail two ${epair}b 1612610dcc1SKristof Provost jexec two ifconfig lo0 up 1622610dcc1SKristof Provost jexec two ifconfig ${epair}b 192.0.2.2/24 up 1632610dcc1SKristof Provost stf_two=$(jexec two ifconfig stf create) 1642610dcc1SKristof Provost jexec two ifconfig $stf_two stfv4br 192.0.2.3 1652610dcc1SKristof Provost jexec two ifconfig $stf_two stfv4net 192.0.2.2/32 1662610dcc1SKristof Provost jexec two ifconfig $stf_two inet6 2001:db8:c000:0202::1/32 up 1672610dcc1SKristof Provost jexec two route -6 add default -interface $stf_two 1682610dcc1SKristof Provost 1692610dcc1SKristof Provost # Sanity check 1702610dcc1SKristof Provost atf_check -s exit:0 -o ignore \ 1712610dcc1SKristof Provost jexec one ping -c 1 192.0.2.2 1722610dcc1SKristof Provost 1732610dcc1SKristof Provost # Test 6rd 1742610dcc1SKristof Provost atf_check -s exit:0 -o ignore \ 1752610dcc1SKristof Provost jexec one ping6 -c 1 2001:db8:c000:0202::1 1762610dcc1SKristof Provost atf_check -s exit:0 -o ignore \ 1772610dcc1SKristof Provost jexec two ping6 -c 1 2001:db8:c000:0201::1 1782610dcc1SKristof Provost 1792610dcc1SKristof Provost # Shorter prefixes, for both v4 and v6 1802610dcc1SKristof Provost jexec one ifconfig $stf_one inet6 2001:db8:c000:0201::1 delete 1812610dcc1SKristof Provost jexec one ifconfig $stf_one inet6 2001:0201::1/16 1822610dcc1SKristof Provost jexec one ifconfig $stf_one stfv4net 192.0.2.1/16 1832610dcc1SKristof Provost jexec two ifconfig $stf_two inet6 2001:db8:c000:0202::1 delete 1842610dcc1SKristof Provost jexec two ifconfig $stf_two inet6 2001:0202::1/16 1852610dcc1SKristof Provost jexec two ifconfig $stf_two stfv4net 192.0.2.2/16 1862610dcc1SKristof Provost 1872610dcc1SKristof Provost atf_check -s exit:0 -o ignore \ 1882610dcc1SKristof Provost jexec one ping6 -c 1 2001:0202::1 1892610dcc1SKristof Provost atf_check -s exit:0 -o ignore \ 1902610dcc1SKristof Provost jexec two ping6 -c 1 2001:0201::1 1912610dcc1SKristof Provost} 1922610dcc1SKristof Provost 1932610dcc1SKristof Provost6rd_peer_cleanup() 1942610dcc1SKristof Provost{ 1952610dcc1SKristof Provost vnet_cleanup 1962610dcc1SKristof Provost} 1972610dcc1SKristof Provost 198eb5e0755SKristof Provostatf_init_test_cases() 199eb5e0755SKristof Provost{ 200eb5e0755SKristof Provost atf_add_test_case "6to4" 201e1b95017SKristof Provost atf_add_test_case "6rd" 2022610dcc1SKristof Provost atf_add_test_case "6rd_peer" 203eb5e0755SKristof Provost} 204