Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to use iptables-restore #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

trozet
Copy link

@trozet trozet commented Mar 28, 2024

This improves efficiency when adding a lot of rules to a table. Rather than calling insert or append for each rule, we can execute one iptables operation to replace them all.

This was identified to greatly improve the performance in ovn-kubernetes. The overall time of installing 1000 rules was taking 4.8 seconds by insert operations. By moving to this commit it only takes .058 seconds.

ovn-org/ovn-kubernetes#4241

ovn-org/ovn-kubernetes#4241 (comment)

This improves efficiency when adding a lot of rules to a table. Rather
than calling insert or append for each rule, we can execute one iptables
operation to replace them all.

Signed-off-by: Tim Rozet <[email protected]>
@trozet
Copy link
Author

trozet commented Apr 2, 2024

@squeed can you PTAL?

for chain, rules := range rulesMap {
restoreRules += "\n" + fmt.Sprintf(":%s - [0:0]", strings.ToUpper(chain))
for _, rule := range rules {
restoreRules += "\n" + fmt.Sprintf("-I %s %s", chain, strings.Join(rule, " "))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I assumed Insert for the rules...but maybe it would be more appropriate to use Append. Another option is make it part of the rule, or make it a parameter to the function. I dont have any preference.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally expect Append but perhaps it could be documented that this is the behavior

@jcaamano
Copy link

jcaamano commented May 6, 2024

@jcaamano tagging me here

@@ -554,6 +578,57 @@ func (ipt *IPTables) run(args ...string) error {
return ipt.runWithOutput(args, nil)
}

// runWithOutput runs an iptables command with the given arguments,
// writing any stdout output to the given writer
func (ipt *IPTables) runRestore(args []string, input string) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if the maintainers are planning to merge this PR but it'd be nice to make this function public or maybe create a wrapper RestoreRaw(args []string, input string)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants