Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,30 @@ func (ipt *IPTables) ChainExists(table, chain string) (bool, error) {
}
}

// ChainsPolicies returns a slice containing a struct with the name and the default policy of each chain in the specified table.
func (ipt *IPTables) ChainsPolicies(table string) (map[string]string, error) {
ret := make(map[string]string)
args := []string{"-t", table, "-S"}

result, err := ipt.executeList(args)
if err != nil {
return nil, err
}

// Iterate over rules to find all default (-P)
// Chains definition always come before rules.
// Format is the following:
// -P OUTPUT ACCEPT
for _, val := range result {
if strings.HasPrefix(val, "-P") {
ret[strings.Fields(val)[1]] = strings.Fields(val)[2]
} else {
break
}
}
return ret, nil
}

// Stats lists rules including the byte and packet counts
func (ipt *IPTables) Stats(table, chain string) ([][]string, error) {
args := []string{"-t", table, "-L", chain, "-n", "-v", "-x"}
Expand Down