1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later
3f08c3bdfSopenharmony_ci# Copyright (c) 2019 Oracle and/or its affiliates. All Rights Reserved.
4f08c3bdfSopenharmony_ci
5f08c3bdfSopenharmony_ciTST_SETUP="do_setup"
6f08c3bdfSopenharmony_ciTST_CLEANUP="do_cleanup"
7f08c3bdfSopenharmony_ciTST_NEEDS_DRIVERS="nf_tables"
8f08c3bdfSopenharmony_ciuse_iptables=0
9f08c3bdfSopenharmony_cicleanup_table=0
10f08c3bdfSopenharmony_cicleanup_chain=0
11f08c3bdfSopenharmony_ci
12f08c3bdfSopenharmony_cido_setup()
13f08c3bdfSopenharmony_ci{
14f08c3bdfSopenharmony_ci	init
15f08c3bdfSopenharmony_ci	local ip_table="ip${TST_IPV6}"
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ci	if ! nft list table $ip_table filter > /dev/null 2>&1; then
18f08c3bdfSopenharmony_ci		ROD nft add table $ip_table filter
19f08c3bdfSopenharmony_ci		cleanup_table=1
20f08c3bdfSopenharmony_ci	fi
21f08c3bdfSopenharmony_ci	if ! nft list chain $ip_table filter INPUT > /dev/null 2>&1; then
22f08c3bdfSopenharmony_ci		ROD nft add chain $ip_table filter INPUT '{ type filter hook input priority 0; }'
23f08c3bdfSopenharmony_ci		cleanup_chain=1
24f08c3bdfSopenharmony_ci	fi
25f08c3bdfSopenharmony_ci}
26f08c3bdfSopenharmony_ci
27f08c3bdfSopenharmony_cido_cleanup()
28f08c3bdfSopenharmony_ci{
29f08c3bdfSopenharmony_ci	local ip_table="ip${TST_IPV6}"
30f08c3bdfSopenharmony_ci
31f08c3bdfSopenharmony_ci	[ "$cleanup_chain" = 1 ] && nft delete chain $ip_table filter INPUT >/dev/null 2>&1
32f08c3bdfSopenharmony_ci	[ "$cleanup_table" = 1 ] && nft delete table $ip_table filter >/dev/null 2>&1
33f08c3bdfSopenharmony_ci	cleanup
34f08c3bdfSopenharmony_ci}
35f08c3bdfSopenharmony_ci
36f08c3bdfSopenharmony_ci. iptables_lib.sh
37f08c3bdfSopenharmony_citst_run
38