From 6f58da1791a49ad7cb021a06f512ae7ced7ae0aa Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 7 Sep 2026 15:05:32 +0900 Subject: [PATCH] test-firewall-util: clear test tables in intro() and outro() Otherwise, the test may fail when there is a garbage in the nftables. --- src/test/test-firewall-util.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/test-firewall-util.c b/src/test/test-firewall-util.c index 7b41d98e66..cdf1864b21 100644 --- a/src/test/test-firewall-util.c +++ b/src/test/test-firewall-util.c @@ -79,14 +79,28 @@ static int intro(void) { ASSERT_OK_ERRNO(setenv("SYSTEMD_FIREWALL_UTIL_NFT_TABLE_NAME", "io.systemd-test.nat", /* overwrite= */ true)); ASSERT_OK_ERRNO(setenv("SYSTEMD_FIREWALL_UTIL_DNAT_MAP_NAME", "test_map_port_ipport", /* overwrite= */ true)); - r = sd_nfnl_socket_open(&nfnl); + _cleanup_(sd_netlink_unrefp) sd_netlink *nl = NULL; + r = sd_nfnl_socket_open(&nl); if (r < 0) return log_tests_skipped_errno(r, "Failed to initialize nftables"); + r = fw_nftables_del_table(nl, AF_INET); + if (r < 0) + return log_tests_skipped_errno(r, "Failed to clear nftables test table"); + + ASSERT_OK(fw_nftables_del_table(nl, AF_INET6)); + + nfnl = TAKE_PTR(nl); return 0; } static int outro(void) { + if (!nfnl) + return 0; + + ASSERT_OK(fw_nftables_del_table(nfnl, AF_INET)); + ASSERT_OK(fw_nftables_del_table(nfnl, AF_INET6)); + sd_netlink_unref(nfnl); return 0; }