From 45291ce0de38c02a80bcc38aad1fce1b967ade7d Mon Sep 17 00:00:00 2001 From: Xueming Feng Date: Sun, 25 Jun 2023 15:38:59 +0800 Subject: [PATCH] Skip warning about rules in legacy iptables. After iptables support nft backend, it will emit the following warning if there are rules in the legacy iptables. "# Warning: iptables-legacy tables present, use iptables-legacy to see them". This cause the header skipping to fail in the following loop. --- iptables/iptables.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/iptables/iptables.go b/iptables/iptables.go index 1e7ad24..fa942e0 100644 --- a/iptables/iptables.go +++ b/iptables/iptables.go @@ -316,6 +316,11 @@ func (ipt *IPTables) Stats(table, chain string) ([][]string, error) { ipv6 := ipt.proto == ProtocolIPv6 + // Skip the warning if exist + if strings.HasPrefix(lines[0], "#") { + lines = lines[1:] + } + rows := [][]string{} for i, line := range lines { // Skip over chain name and field header