Changeset View
Changeset View
Standalone View
Standalone View
sbin/ping/tests/ping_test.sh
Show All 21 Lines | |||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
# SUCH DAMAGE. | # SUCH DAMAGE. | ||||
# | # | ||||
# $FreeBSD$ | # $FreeBSD$ | ||||
. $(atf_get_srcdir)/../../../tests/sys/common/vnet.subr | |||||
require_ipv4() | require_ipv4() | ||||
{ | { | ||||
if ! getaddrinfo -f inet localhost 1>/dev/null 2>&1; then | if ! getaddrinfo -f inet localhost 1>/dev/null 2>&1; then | ||||
atf_skip "IPv4 is not configured" | atf_skip "IPv4 is not configured" | ||||
fi | fi | ||||
} | } | ||||
require_ipv6() | require_ipv6() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | |||||
inject_opts_head() | inject_opts_head() | ||||
{ | { | ||||
atf_set "descr" "Inject an ECHO REPLY with IP options" | atf_set "descr" "Inject an ECHO REPLY with IP options" | ||||
atf_set "require.user" "root" | atf_set "require.user" "root" | ||||
atf_set "require.progs" "python3" "scapy" | atf_set "require.progs" "python3" "scapy" | ||||
} | } | ||||
inject_opts_body() | inject_opts_body() | ||||
{ | { | ||||
atf_check -s exit:0 -o match:"wrong total length" -o match:"NOP" python3 $(atf_get_srcdir)/injection.py opts | vnet_init | ||||
tun=$(vnet_mktun) | |||||
asomers: Since you're using vnet, you really could go back to hardcoding tun0, if that would make things… | |||||
vnet_mkjail BRL $tun | |||||
atf_check -s exit:0 -o match:"wrong total length" -o match:"NOP" \ | |||||
jexec BRL $(atf_get_srcdir)/pinger.py \ | |||||
--iface $tun \ | |||||
--src 192.0.2.1 \ | |||||
--dst 192.0.2.2 \ | |||||
--icmp_type 0 \ | |||||
--icmp_code 0 \ | |||||
--opts NOP-40 | |||||
} | } | ||||
inject_opts_cleanup() | inject_opts_cleanup() | ||||
{ | { | ||||
ifconfig `cat tun.txt` destroy | vnet_cleanup | ||||
} | } | ||||
atf_test_case "inject_pip" "cleanup" | atf_test_case "inject_pip" "cleanup" | ||||
inject_pip_head() | inject_pip_head() | ||||
{ | { | ||||
atf_set "descr" "Inject an ICMP error with a quoted packet with IP options" | atf_set "descr" "Inject an ICMP error with a quoted packet with IP options" | ||||
atf_set "require.user" "root" | atf_set "require.user" "root" | ||||
atf_set "require.progs" "python3" "scapy" | atf_set "require.progs" "python3" "scapy" | ||||
} | } | ||||
inject_pip_body() | inject_pip_body() | ||||
{ | { | ||||
atf_check -s exit:2 -o match:"Destination Host Unreachable" -o not-match:"01010101" python3 $(atf_get_srcdir)/injection.py pip | vnet_init | ||||
tun=$(vnet_mktun) | |||||
vnet_mkjail BRL $tun | |||||
# XXX This test is wrong. It should match 40 NOPs (not not-match 4 NOPs). | |||||
atf_check -s exit:2 -o match:"Destination Host Unreachable" -o not-match:"01010101" \ | |||||
jexec BRL $(atf_get_srcdir)/pinger.py \ | |||||
--iface $tun \ | |||||
--src 192.0.2.1 \ | |||||
--dst 192.0.2.2 \ | |||||
--icmp_type 3 \ | |||||
--icmp_code 1 \ | |||||
--opts NOP-40 | |||||
} | } | ||||
inject_pip_cleanup() | inject_pip_cleanup() | ||||
{ | { | ||||
ifconfig `cat tun.txt` destroy | vnet_cleanup | ||||
} | } | ||||
# This is redundant with the ping_ tests, but it serves to ensure that scapy.py | # This is redundant with the ping_ tests, but it serves to ensure that scapy.py | ||||
# is working correctly. | # is working correctly. | ||||
atf_test_case "inject_reply" "cleanup" | atf_test_case "inject_reply" "cleanup" | ||||
inject_reply_head() | inject_reply_head() | ||||
{ | { | ||||
atf_set "descr" "Basic ping test with packet injection" | atf_set "descr" "Basic ping test with packet injection" | ||||
atf_set "require.user" "root" | atf_set "require.user" "root" | ||||
atf_set "require.progs" "python3" "scapy" | atf_set "require.progs" "python3" "scapy" | ||||
} | } | ||||
inject_reply_body() | inject_reply_body() | ||||
{ | { | ||||
atf_check -s exit:0 -o match:"1 packets transmitted, 1 packets received" python3 $(atf_get_srcdir)/injection.py reply | vnet_init | ||||
tun=$(vnet_mktun) | |||||
vnet_mkjail BRL $tun | |||||
atf_check -s exit:0 -o match:"1 packets transmitted, 1 packets received" \ | |||||
jexec BRL $(atf_get_srcdir)/pinger.py \ | |||||
--iface $tun \ | |||||
--src 192.0.2.1 \ | |||||
--dst 192.0.2.2 \ | |||||
--icmp_type 0 \ | |||||
--icmp_code 0 | |||||
} | } | ||||
inject_reply_cleanup() | inject_reply_cleanup() | ||||
{ | { | ||||
ifconfig `cat tun.txt` destroy | vnet_cleanup | ||||
} | } | ||||
atf_init_test_cases() | atf_init_test_cases() | ||||
{ | { | ||||
atf_add_test_case ping_c1_s56_t1 | atf_add_test_case ping_c1_s56_t1 | ||||
atf_add_test_case ping_c1_s56_t1_S127 | atf_add_test_case ping_c1_s56_t1_S127 | ||||
atf_add_test_case ping_6_c1_s8_t1 | atf_add_test_case ping_6_c1_s8_t1 | ||||
atf_add_test_case ping_c1_s8_t1_S1 | atf_add_test_case ping_c1_s8_t1_S1 | ||||
Show All 12 Lines | check_ping_statistics() | ||||
sed -e 's/0.[0-9]\{3\}//g' \ | sed -e 's/0.[0-9]\{3\}//g' \ | ||||
-e 's/[1-9][0-9]*.[0-9]\{3\}//g' \ | -e 's/[1-9][0-9]*.[0-9]\{3\}//g' \ | ||||
-e 's/localhost ([0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{1,3\})/localhost/' \ | -e 's/localhost ([0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{1,3\})/localhost/' \ | ||||
-e 's/from [0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{1,3\}/from/' \ | -e 's/from [0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{1,3\}/from/' \ | ||||
-e 's/ttl=[0-9][0-9]*/ttl=/' \ | -e 's/ttl=[0-9][0-9]*/ttl=/' \ | ||||
-e 's/hlim=[0-9][0-9]*/hlim=/' \ | -e 's/hlim=[0-9][0-9]*/hlim=/' \ | ||||
"$1" >"$1".filtered | "$1" >"$1".filtered | ||||
atf_check -s exit:0 diff -u "$1".filtered "$2" | atf_check -s exit:0 diff -u "$1".filtered "$2" | ||||
} | } | ||||
Done Inline ActionsExplicitly deleting files is unnecessary, because Kyua uses a per-testcase tempdir. asomers: Explicitly deleting files is unnecessary, because Kyua uses a per-testcase tempdir. | |||||
Done Inline ActionsOK, I'll remove it, if a test fails, it complains about it having "Files left in work directory after failure". I thought it was a common courtesy to remove them anyways. jlduran_gmail.com: OK, I'll remove it, if a test fails, it complains about it having "Files left in work directory… | |||||
Done Inline ActionsI can't edit comments. For self reference: 96b90524d155bdd2d3f78a0a50cf250164bfbf6c jlduran_gmail.com: I can't edit comments. For self reference: 96b90524d155bdd2d3f78a0a50cf250164bfbf6c |
Since you're using vnet, you really could go back to hardcoding tun0, if that would make things easier. But it's probably best not to, in case future developers want to disable the vnet part for some reason. It's more robust this way.