1#!/bin/sh
2# Copyright (c) 2016 Red Hat Inc.,  All Rights Reserved.
3# Copyright (c) International Business Machines  Corp., 2005
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License as
7# published by the Free Software Foundation; either version 2 of
8# the License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it would be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, see <http://www.gnu.org/licenses/>.
17#
18# Author: Hangbin Liu <haliu@redhat.com>
19#
20################################################################################
21TCID=${TCID:-icmp-uni-basic}
22TST_TOTAL=1
23TST_COUNT=1
24TST_CLEANUP="tst_ipsec_cleanup"
25
26. ipsec_lib.sh
27
28while getopts "hl:m:p:s:S:6" opt; do
29	case "$opt" in
30	h)
31		echo "Usage:"
32		echo "h        help"
33		echo "l n      n is the number of test link when tests run"
34		echo "m x      x is ipsec mode, could be transport / tunnel"
35		echo "p x      x is ipsec protocol, could be ah / esp / ipcomp"
36		echo "s x      x is icmp messge size array"
37		echo "S n      n is IPsec SPI value"
38		echo "6        run over IPv6"
39		exit 0
40	;;
41	l) LINK_NUM=$OPTARG ;;
42	m) IPSEC_MODE=$OPTARG ;;
43	p) IPSEC_PROTO=$OPTARG ;;
44	s) ICMP_SIZE_ARRAY=$OPTARG ;;
45	S) SPI=$OPTARG ;;
46	6) # skip, test_net library already processed it
47	;;
48	*) tst_brkm TBROK "unknown option: $opt" ;;
49	esac
50done
51
52SPI=${SPI:-1000}
53LINK_NUM=${LINK_NUM:-0}
54DO_IPSEC=${DO_IPSEC:-false}
55ICMP_SIZE_ARRAY=${ICMP_SIZE_ARRAY:-"10 100 1000 10000 65507"}
56[ -n "$IPSEC_MODE" -a -n "$IPSEC_PROTO" ] && DO_IPSEC=true || DO_IPSEC=false
57
58# Test description
59tst_resm TINFO "Sending ICMP messages with the following conditions"
60tst_resm TINFO "- Version of IP is IPv${TST_IPV6:-4}"
61tst_resm TINFO "- Size of packets are ( $ICMP_SIZE_ARRAY )"
62
63if $DO_IPSEC; then
64	case $IPSEC_PROTO in
65	ah)	tst_resm TINFO "- IPsec [ AH / $IPSEC_MODE ]" ;;
66	esp)	tst_resm TINFO "- IPsec [ ESP / $IPSEC_MODE ]" ;;
67	ipcomp)	tst_resm TINFO "- IPcomp [ $IPSEC_MODE ]" ;;
68	esac
69fi
70
71# name of interface of the local/remote host
72lhost_ifname=$(tst_iface lhost $LINK_NUM)
73rhost_ifname=$(tst_iface rhost $LINK_NUM)
74
75lhost_addr=$(tst_ipaddr)
76rhost_addr=$(tst_ipaddr rhost)
77
78# Configure SAD/SPD
79if $DO_IPSEC ; then
80	tst_ipsec lhost $IPSEC_PROTO $IPSEC_MODE $SPI $lhost_addr $rhost_addr
81	tst_ipsec rhost $IPSEC_PROTO $IPSEC_MODE $SPI $rhost_addr $lhost_addr
82fi
83
84tst_ping $lhost_ifname $rhost_addr $ICMP_SIZE_ARRAY
85if [ $? -ne 0 ]; then
86	tst_resm TFAIL "Checked IPv${TST_IPV6:-4} $IPSEC_PROTO $IPSEC_MODE"
87else
88	tst_resm TPASS "Checked IPv${TST_IPV6:-4} $IPSEC_PROTO $IPSEC_MODE"
89fi
90
91tst_exit
92