-
Notifications
You must be signed in to change notification settings - Fork 257
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
base: main
Are you sure you want to change the base?
Conversation
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]>
7d07ae3
to
077e672
Compare
@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, " ")) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 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 { |
There was a problem hiding this comment.
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)
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-kubernetes/ovn-kubernetes#4241
ovn-kubernetes/ovn-kubernetes#4241 (comment)