#!/bin/sh

#
# iptable  application test cases
#
. ../lib/sh-test-lib
OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
export RESULT_FILE

# Test run
! check_root && error_msg "This script must be run as root"
create_out_dir "${OUTPUT}"

info_msg "About to run iptable application test..."
info_msg "Output directory: ${OUTPUT}"

TARGET_IP=$( ip route get 8.8.8.8 |  cut -f7 -d" " | grep '^[0-9]' )
echo "${TARGET_IP}"

#Test check iptable packages on target
iptable_packageCheck_test()
{
	skip_list="iptable_kernel_config_test" 
	dpkg -l | grep -i  "iptables" && apt-cache pkgnames | grep -i  "iptables"
	exit_on_fail "iptable_package_check" "${skip_list}"
}

#Checking iptables configuration option in kernel 
iptable_kernel_config_test()
{
	cat /boot/config-$(uname -r) | egrep "CONFIG_IP_NF_IPTABLES=y|CONFIG_IP_NF_IPTABLES=m"
	exit_on_fail "iptable_kernel_config_test" "${skip_list}"
}

iptable_packageCheck_test

iptable_kernel_config_test

