소스 검색

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.
Xueming Feng 1 년 전
부모
커밋
45291ce0de
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      iptables/iptables.go

+ 5 - 0
iptables/iptables.go

@@ -316,6 +316,11 @@ func (ipt *IPTables) Stats(table, chain string) ([][]string, error) {
 
 
 	ipv6 := ipt.proto == ProtocolIPv6
 	ipv6 := ipt.proto == ProtocolIPv6
 
 
+	// Skip the warning if exist
+	if strings.HasPrefix(lines[0], "#") {
+		lines = lines[1:]
+	}
+
 	rows := [][]string{}
 	rows := [][]string{}
 	for i, line := range lines {
 	for i, line := range lines {
 		// Skip over chain name and field header
 		// Skip over chain name and field header