xref: /freebsd/tests/sys/netpfil/pf/modulate.sh (revision d0b2dbfa)
138e2d5dbSKristof Provost#
24d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause
338e2d5dbSKristof Provost#
438e2d5dbSKristof Provost# Copyright (c) 2023 Kajetan Staszkiewicz <vegetga@tuxpowered.net>
538e2d5dbSKristof Provost#
638e2d5dbSKristof Provost# Redistribution and use in source and binary forms, with or without
738e2d5dbSKristof Provost# modification, are permitted provided that the following conditions
838e2d5dbSKristof Provost# are met:
938e2d5dbSKristof Provost# 1. Redistributions of source code must retain the above copyright
1038e2d5dbSKristof Provost#    notice, this list of conditions and the following disclaimer.
1138e2d5dbSKristof Provost# 2. Redistributions in binary form must reproduce the above copyright
1238e2d5dbSKristof Provost#    notice, this list of conditions and the following disclaimer in the
1338e2d5dbSKristof Provost#    documentation and/or other materials provided with the distribution.
1438e2d5dbSKristof Provost#
1538e2d5dbSKristof Provost# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1638e2d5dbSKristof Provost# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1738e2d5dbSKristof Provost# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1838e2d5dbSKristof Provost# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1938e2d5dbSKristof Provost# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2038e2d5dbSKristof Provost# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2138e2d5dbSKristof Provost# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2238e2d5dbSKristof Provost# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2338e2d5dbSKristof Provost# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2438e2d5dbSKristof Provost# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2538e2d5dbSKristof Provost# SUCH DAMAGE.
2638e2d5dbSKristof Provost
2738e2d5dbSKristof Provost. $(atf_get_srcdir)/utils.subr
2838e2d5dbSKristof Provost
2938e2d5dbSKristof Provostatf_test_case "modulate_v4" "cleanup"
3038e2d5dbSKristof Provostmodulate_v4_head()
3138e2d5dbSKristof Provost{
3238e2d5dbSKristof Provost	atf_set descr 'IPv4 TCP sequence number modulation'
3338e2d5dbSKristof Provost	atf_set require.user root
3438e2d5dbSKristof Provost	atf_set require.progs scapy
3538e2d5dbSKristof Provost}
3638e2d5dbSKristof Provost
3738e2d5dbSKristof Provostmodulate_v4_body()
3838e2d5dbSKristof Provost{
3938e2d5dbSKristof Provost	setup_router_dummy_ipv4
4038e2d5dbSKristof Provost
4138e2d5dbSKristof Provost	pft_set_rules router \
4238e2d5dbSKristof Provost		"pass in on ${epair_tester}b modulate state"
4338e2d5dbSKristof Provost	ping_dummy_check_request exit:0 --ping-type=tcpsyn --send-seq 42 # Sanity check
4438e2d5dbSKristof Provost	ping_dummy_check_request exit:1 --ping-type=tcpsyn --send-seq 42 --expect-seq 42
4538e2d5dbSKristof Provost}
4638e2d5dbSKristof Provost
4738e2d5dbSKristof Provostmodulate_v4_cleanup()
4838e2d5dbSKristof Provost{
4938e2d5dbSKristof Provost	pft_cleanup
5038e2d5dbSKristof Provost}
5138e2d5dbSKristof Provost
5238e2d5dbSKristof Provostatf_test_case "modulate_v6" "cleanup"
5338e2d5dbSKristof Provostmodulate_v6_head()
5438e2d5dbSKristof Provost{
5538e2d5dbSKristof Provost	atf_set descr 'IPv6 TCP sequence number modulation'
5638e2d5dbSKristof Provost	atf_set require.user root
5738e2d5dbSKristof Provost	atf_set require.progs scapy
5838e2d5dbSKristof Provost}
5938e2d5dbSKristof Provost
6038e2d5dbSKristof Provostmodulate_v6_body()
6138e2d5dbSKristof Provost{
6238e2d5dbSKristof Provost	setup_router_dummy_ipv6
6338e2d5dbSKristof Provost
6438e2d5dbSKristof Provost	pft_set_rules router \
6538e2d5dbSKristof Provost		"pass in on ${epair_tester}b modulate state"
6638e2d5dbSKristof Provost	ping_dummy_check_request exit:0 --ping-type=tcpsyn --send-seq 42 # Sanity check
6738e2d5dbSKristof Provost	ping_dummy_check_request exit:1 --ping-type=tcpsyn --send-seq 42 --expect-seq 42
6838e2d5dbSKristof Provost}
6938e2d5dbSKristof Provost
7038e2d5dbSKristof Provostmodulate_v6_cleanup()
7138e2d5dbSKristof Provost{
7238e2d5dbSKristof Provost	pft_cleanup
7338e2d5dbSKristof Provost}
7438e2d5dbSKristof Provost
7538e2d5dbSKristof Provostatf_init_test_cases()
7638e2d5dbSKristof Provost{
7738e2d5dbSKristof Provost	atf_add_test_case "modulate_v4"
7838e2d5dbSKristof Provost	atf_add_test_case "modulate_v6"
7938e2d5dbSKristof Provost}
80