1# 2# Copyright (c) 2025 Dag-Erling Smørgrav <des@FreeBSD.org> 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6 7. $(atf_get_srcdir)/../../sys/common/vnet.subr 8 9atf_test_case nptv6 cleanup 10nptv6_head() 11{ 12 atf_set "descr" "Test creation of NPTv6 rules" 13 atf_set "require.user" "root" 14 atf_set "require.kmods" "ipfw_nptv6" 15 atf_set "require.progs" ipfw 16} 17nptv6_body() 18{ 19 vnet_init 20 local jail=ipfw_$(atf_get ident) 21 local epair=$(vnet_mkepair) 22 vnet_mkjail ${jail} ${epair}a 23 24 local rule="xyzzy" 25 local int="2001:db8:1::" 26 local ext="2001:db8:2::" 27 28 atf_check jexec ${jail} \ 29 ifconfig "${epair}"a inet6 ${ext}1/64 up 30 31 # This is how it's supposed to be used 32 atf_check jexec ${jail} ipfw nptv6 ${rule} create \ 33 int_prefix ${int} ext_prefix ${ext} prefixlen 64 34 atf_check -o inline:\ 35"nptv6 $rule int_prefix $int ext_prefix $ext prefixlen 64\n" \ 36 jexec ${jail} ipfw nptv6 all list 37 atf_check jexec ${jail} ipfw nptv6 all destroy 38 39 # Specify external interface rather than network 40 atf_check jexec ${jail} ipfw nptv6 ${rule} create \ 41 int_prefix ${int} ext_if ${epair}a prefixlen 64 42 atf_check -o inline:\ 43"nptv6 $rule int_prefix $int ext_if ${epair}a prefixlen 64\n" \ 44 jexec ${jail} ipfw nptv6 all list 45 atf_check jexec ${jail} ipfw nptv6 all destroy 46 47 # This should also work 48 atf_check jexec ${jail} ipfw nptv6 ${rule} create \ 49 int_prefix ${int}/64 ext_prefix ${ext}/64 prefixlen 64 50 atf_check -o inline:\ 51"nptv6 $rule int_prefix $int ext_prefix $ext prefixlen 64\n" \ 52 jexec ${jail} ipfw nptv6 all list 53 atf_check jexec ${jail} ipfw nptv6 all destroy 54 55 # This should also work, although it's not encouraged 56 atf_check -e match:"use prefixlen instead" \ 57 jexec ${jail} ipfw nptv6 ${rule} create \ 58 int_prefix ${int}/64 ext_prefix ${ext}/64 59 atf_check -o inline:\ 60"nptv6 $rule int_prefix $int ext_prefix $ext prefixlen 64\n" \ 61 jexec ${jail} ipfw nptv6 all list 62 atf_check jexec ${jail} ipfw nptv6 all destroy 63 64 # These should all fail 65 atf_check -s not-exit:0 -e match:"one ext_prefix or ext_if" \ 66 jexec ${jail} ipfw nptv6 ${rule} create \ 67 int_prefix ${int} ext_prefix ${ext} ext_if ${epair}a 68 atf_check -o empty jexec ${jail} ipfw nptv6 all list 69 70 atf_check -s not-exit:0 -e match:"one ext_prefix or ext_if" \ 71 jexec ${jail} ipfw nptv6 ${rule} create \ 72 int_prefix ${int} ext_if ${epair}a ext_prefix ${ext} 73 atf_check -o empty jexec ${jail} ipfw nptv6 all list 74 75 atf_check -s not-exit:0 -e match:"prefix length mismatch" \ 76 jexec ${jail} ipfw nptv6 ${rule} create \ 77 int_prefix ${int}/48 ext_prefix ${ext}/64 78 atf_check -o empty jexec ${jail} ipfw nptv6 all list 79 80 atf_check -s not-exit:0 -e match:"prefix length mismatch" \ 81 jexec ${jail} ipfw nptv6 ${rule} create \ 82 int_prefix ${int}/64 ext_prefix ${ext}/64 prefixlen 48 83 atf_check -o empty jexec ${jail} ipfw nptv6 all list 84 85 atf_check -s not-exit:0 -e match:"prefix length mismatch" \ 86 jexec ${jail} ipfw nptv6 ${rule} create \ 87 int_prefix ${int}/64 ext_prefix ${ext} prefixlen 48 88 atf_check -o empty jexec ${jail} ipfw nptv6 all list 89 90 atf_check -s not-exit:0 -e match:"prefix length mismatch" \ 91 jexec ${jail} ipfw nptv6 ${rule} create \ 92 int_prefix ${int} ext_prefix ${ext}/64 prefixlen 48 93 atf_check -o empty jexec ${jail} ipfw nptv6 all list 94 95 atf_check -s not-exit:0 -e match:"prefix length mismatch" \ 96 jexec ${jail} ipfw nptv6 ${rule} create \ 97 int_prefix ${int}/64 ext_if ${epair}a prefixlen 48 98 atf_check -o empty jexec ${jail} ipfw nptv6 all list 99} 100nptv6_cleanup() 101{ 102 vnet_cleanup 103} 104 105atf_init_test_cases() 106{ 107 atf_add_test_case nptv6 108} 109