@@ -953,6 +953,50 @@ dummynet_mask_cleanup()
953953 pft_cleanup
954954}
955955
956+ atf_test_case " first_match" " cleanup"
957+ first_match_head ()
958+ {
959+ atf_set descr ' Test that NAT rules are first match'
960+ atf_set require.user root
961+ }
962+
963+ first_match_body ()
964+ {
965+ pft_init
966+
967+ epair_nat=$( vnet_mkepair)
968+ epair_echo=$( vnet_mkepair)
969+
970+ vnet_mkjail nat ${epair_nat} b ${epair_echo} a
971+ vnet_mkjail echo ${epair_echo} b
972+
973+ ifconfig ${epair_nat} a 192.0.2.2/24 up
974+ route add -net 198.51.100.0/24 192.0.2.1
975+
976+ jexec nat ifconfig ${epair_nat} b 192.0.2.1/24 up
977+ jexec nat ifconfig ${epair_echo} a 198.51.100.1/24 up
978+ jexec nat sysctl net.inet.ip.forwarding=1
979+
980+ jexec echo ifconfig ${epair_echo} b 198.51.100.2/24 up
981+
982+ # Enable pf!
983+ jexec nat pfctl -e
984+ pft_set_rules nat \
985+ " table <foo> { 192.0.2.0/24 }" \
986+ " nat on ${epair_echo} a inet from <foo> to any -> 198.51.100.1" \
987+ " nat on ${epair_echo} a inet from 192.0.2.0/24 to any -> 198.51.100.3"
988+
989+ atf_check -s exit:0 -o ignore ping -c 3 198.51.100.2
990+ atf_check -s exit:0 -e ignore \
991+ -o match:" all icmp 198.51.100.1:.*(192.0.2.2:.*) -> 198.51.100.2:8.*" \
992+ jexec nat pfctl -ss
993+ }
994+
995+ first_match_cleanup ()
996+ {
997+ pft_cleanup
998+ }
999+
9561000atf_init_test_cases ()
9571001{
9581002 atf_add_test_case " exhaust"
@@ -975,4 +1019,5 @@ atf_init_test_cases()
9751019 atf_add_test_case " binat_match"
9761020 atf_add_test_case " empty_pool"
9771021 atf_add_test_case " dummynet_mask"
1022+ atf_add_test_case " first_match"
9781023}
0 commit comments