Skip to content

Commit

Permalink
remove comment lines in iptables list
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Aug 14, 2024
1 parent 2fe2a0d commit 2ea501b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/firewall/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ func parseChain(iptablesOutput string) (c chain, err error) {
// 0 0 ACCEPT 6 -- tun0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:55405
// 0 0 DROP 0 -- tun0 * 0.0.0.0/0 0.0.0.0/0
iptablesOutput = strings.TrimSpace(iptablesOutput)
lines := strings.Split(iptablesOutput, "\n")
linesWithComments := strings.Split(iptablesOutput, "\n")

// Filter out lines starting with a '#' character
lines := make([]string, 0, len(linesWithComments))
for _, line := range linesWithComments {
if strings.HasPrefix(line, "#") {
continue
}
lines = append(lines, line)
}

const minLines = 2 // chain general information line + legend line
if len(lines) < minLines {
Expand Down

0 comments on commit 2ea501b

Please sign in to comment.