diff --git a/pkg/agent/util/ipset/ipset.go b/pkg/agent/util/ipset/ipset.go index 3e7fbeea586..657c1b743b1 100644 --- a/pkg/agent/util/ipset/ipset.go +++ b/pkg/agent/util/ipset/ipset.go @@ -45,6 +45,8 @@ type Interface interface { DelEntry(name string, entry string) error ListEntries(name string) ([]string, error) + + Save() ([]byte, error) } type Client struct { @@ -121,3 +123,12 @@ func (c *Client) ListEntries(name string) ([]string, error) { } return entries, nil } + +func (c *Client) Save() ([]byte, error) { + cmd := c.exec.Command("ipset", "save") + output, err := cmd.CombinedOutput() + if err != nil { + return nil, fmt.Errorf("error saving ipset: %w, output: %s", err, string(output)) + } + return output, nil +} \ No newline at end of file diff --git a/pkg/support/dump_others.go b/pkg/support/dump_others.go index 529273f2933..99974844141 100644 --- a/pkg/support/dump_others.go +++ b/pkg/support/dump_others.go @@ -23,6 +23,7 @@ import ( "path/filepath" "strings" + "antrea.io/antrea/pkg/agent/util/ipset" "antrea.io/antrea/pkg/agent/util/iptables" "antrea.io/antrea/pkg/util/logdir" ) @@ -41,6 +42,9 @@ func (d *agentDumper) DumpHostNetworkInfo(basedir string) error { if err := d.dumpIPTables(basedir); err != nil { return err } + if err := d.dumpIPSets(basedir); err != nil { + return err + } if err := d.dumpIPToolInfo(basedir); err != nil { return err } @@ -59,6 +63,15 @@ func (d *agentDumper) dumpIPTables(basedir string) error { return writeFile(d.fs, filepath.Join(basedir, "iptables"), "iptables", data) } +func (d *agentDumper) dumpIPSets(basedir string) error { + c := ipset.NewClient() + data, err := c.Save() + if err != nil { + return err + } + return writeFile(d.fs, filepath.Join(basedir, "ipsets"), "ipsets", data) +} + func (d *agentDumper) dumpIPToolInfo(basedir string) error { dump := func(name string) error { output, err := d.executor.Command("ip", name).CombinedOutput()