libnet/d/bridge: move iptRule to iptables pkg#49125
Conversation
|
Looks like the linter is unhappy (because use of unkeyed literals); not sure if you're using GoLand, but that one can "fill in all keys" for you; |
This moves the iptRule struct from the bridge package to the iptables pkg. Signed-off-by: Albin Kerouanton <[email protected]>
89de986 to
ec8a5b0
Compare
|
|
||
| // Exists returns true if the rule exists in the kernel. | ||
| func (r iptRule) Exists() bool { | ||
| return iptables.GetIptable(r.ipv).Exists(r.table, r.chain, r.args...) |
There was a problem hiding this comment.
I was slightly trying to grasp the reason behind this change; because previously this was non-exported and internal to the bridge driver. Is the intent to make this type more widely used, and used as an abstraction for iptables + nftables?
In that case, I'm wondering if it's currently the right abstraction, or at least, I'm wondering if all fields it defines are "portable";
- Should there be an interface defined instead (providing
Exists(),Append(),Insert(),Delete()) - The fields to be unexported, and instead having a constructor (
iptables.NewRule(...)) - Alternatively, the
iptablespackage to haveDelete(rule),Insert(rule)functions (which could potentially become an abstraction?)
Do you have more context to this change?
There was a problem hiding this comment.
The end goal is to decouple the bridge driver from iptables.
I have a wip branch where I'm moving iptables rules into a new internal package. There will be transitional commits where both the bridge package and the new fwipt pacakge will need this struct.
iptRule is currently the best iptables abstraction we have. It'd be great to converge on that and drop some of the alternative functions we've (eg. ProgramRule).
and used as an abstraction for iptables + nftables?
No, we won't use the same abstraction for both, they're too different. So, no need to worry about 'portability'.
There was a problem hiding this comment.
iptRule is currently the best iptables abstraction we have
Yeah, the args feels like a leaky abstraction; the combination of args (doing the actual work) with some defined fields, is a bit odd 😂
| } | ||
| rule := iptRule{ipv: ipv, table: iptables.Mangle, chain: "POSTROUTING", args: args} | ||
| }} | ||
| if err := appendOrDelChainRule(rule, "SCTP CHECKSUM", enable); err != nil { |
There was a problem hiding this comment.
If we're moving, would it make sense to put the comment as a field in the Rule? Possibly the error-message generating could then be fully delegated to the rule.Append and rule.Delete functions, because they both know whether something was added or deleted that failed, and they would have the comment related to it;
moby/libnetwork/drivers/bridge/setup_ip_tables_linux.go
Lines 544 to 555 in 40f58b3
There was a problem hiding this comment.
Good idea!
I originally thought about adding a Comment field to automatically add -m comment --comment <COMMENT> to iptables rules, but that's quite involved because we need to handle 'migration' (eg. we should not create duplicate rules, one with and one without a comment). But what you're proposing sounds good too.
However, that will need a bit more work as not all rules are currently inserted by an helper that takes a comment, and some comments might be too unspecific to be really helpful when debugging.
Since this PR doesn't deal with comments, I'd prefer to address that in a follow-up.
| // Exists returns true if the rule exists in the kernel. | ||
| func (r Rule) Exists() bool { |
There was a problem hiding this comment.
Note; I went looking where Exists() was used outside of this type itself (i.e., as part of functions like Append()), and it looks like it's only used in tests to assert that some actions happened.
If we're gonna work on follow-ups, we could look if we need Exists() to be part of this interface, or if it would be a dedicated test-utility. We could still split it between a non-exported one (for the internal use) and an exported one, to make it easier to discover where the exported one is used.
- What I did
This moves the iptRule struct from the bridge package to the iptables pkg.
- How to verify it
Existing tests, plus a new unit test.