Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(transparent-proxy): adjust tproxy iptables API (#10185)
- Rename "commands" to "rules" Rules are more flexible if we want to introduce some additional logic for example to remove particular iptables rule or check if it exists. Before we would end up with a list of commands inside chains, which would make it harder if we in example would like to check if the rules we want to add/remove already exists, because we would have to iterate over all "commands" inside chains and create new `Command`s for check (-C|--check) or delete. We also won't need short/long parameters in rules anymore - Get rid of rules.Append/Insert and add rules.NewRule - Change rule position param type from `int` to `uint` iptables -I|--insert doesen't allow to pass negative numbers as rule positions - Rename chain.Insert/Append/AppendIf methods Chains don't contain commands anymore. They contain rules. By changing names of these methods we give ourselves more flexibility about what we want to do with the rules inside chains. - Put flag string literals in consts package for rules (-I|--insert etc.) - Move regular chain and table names to consts package - Pass table name to rules Table name might be used to generate command arguments for checking or removing rules. - Change receiver name from "b" to "c" in Chain (b was incorrect) - Make `Rule` parameter names concistent In other places we are using `chain` and `table` instead of `chainName` and `tableName` - Rename Build methods to BuildForRestore `Build` is vague and `BuildForRestore` is more correct as returned strings are intended for `iptables-restore` usage only. - Rename variable "cmds" to "lines" in Chain.BuildForRestore - Change parameter builder's Build method to return []string instead of string We can use it then as a list of parameters for iptables execution - Allow chain constructors to return and pass through errors You shouldn't be able to create a Chain without a name or without providing a table to which the chain belongs to. - Rename "table" package/directory to "tables" for consistency - Rename "chain" package/directory to "chains" for consistency - Replace TableBuilder with Table interface Having this intermediate structure was cumbersome and unnecessary. I removed BuildForRestore method from TableBuilder and replaced it with the function BuildRulesForRestore which accepts Table interface. It makes it simpler in the future to introduce logic for cleanup and/or check of existing iptables rules. Signed-off-by: Bart Smykla <bartek@smykla.com>
- Loading branch information