-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Added a different chain for iptables rules #1650
Conversation
fe5d01f
to
e1b8075
Compare
273ccc6
to
7a9b0aa
Compare
network/iptables.go
Outdated
@@ -135,7 +173,7 @@ func ipTablesRulesExist(ipt IPTables, rules []IPTablesRule) (bool, error) { | |||
} | |||
|
|||
// ipTablesCleanAndBuild create from a list of iptables rules a transaction (as string) for iptables-restore for ordering the rules that effectively running | |||
func ipTablesCleanAndBuild(ipt IPTables, rules []IPTablesRule) (IPTablesRestoreRules, error) { | |||
func ipTablesCleanAndBuild(ipt IPTables, rules []IPTablesRule, toChain bool) (IPTablesRestoreRules, 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.
Can you explain in the function comment what "toChain" mean?
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.
If the rule is used to send the traffic to the chain and it has to be added with -I and not -A.
Maybe I can modified to a more meaningful name.
network/iptables.go
Outdated
var MasqChain = []IPTablesRule{ | ||
{"nat", "POSTROUTING", []string{"-m", "comment", "--comment", "flanneld masq", "-j", "FLANNEL-POSTRTG"}}, | ||
} | ||
|
||
var FwdChain = []IPTablesRule{ | ||
{"filter", "FORWARD", []string{"-m", "comment", "--comment", "flanneld forward", "-j", "FLANNEL-FWD"}}, | ||
} | ||
|
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.
You can have both definitions in one var ( ...) section
network/iptables_windows.go
Outdated
var MasqChain = []IPTablesRule{ | ||
{"nat", "POSTROUTING", []string{"-m", "comment", "--comment", "flanneld masq", "-j", "FLANNEL-POSTRTG"}}, | ||
} | ||
|
||
var FwdChain = []IPTablesRule{ | ||
{"filter", "FORWARD", []string{"-m", "comment", "--comment", "flanneld forward", "-j", "FLANNEL-FWD"}}, | ||
} |
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.
You can define both variables in one var section
network/iptables_test.go
Outdated
@@ -114,7 +114,7 @@ func TestDeleteRules(t *testing.T) { | |||
baseRules := MasqRules(ip.IP4Net{}, lease()) | |||
expectedRules := expectedTearDownIPTablesRestoreRules(baseRules) | |||
|
|||
err := ipTablesBootstrap(ipt, iptr, baseRules) | |||
err := ipTablesBootstrap(ipt, iptr, baseRules, false) |
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.
All use toChain=false
, is it possible to create one that uses toChain=true
?
744a437
to
e8482f3
Compare
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.
Looks good. Only one comment
network/iptables.go
Outdated
ipt, err := iptables.NewWithProtocol(iptables.ProtocolIPv6) | ||
if err != nil { | ||
// if we can't find iptables, give up and return | ||
log.Errorf("Failed to setup IPTables. iptables binary was not found: %v", err) |
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.
Could you add v6 in the logs? Just to differentiate with the ipv4 case. Imagine we get an error in a dual-stack env, we would not know where it is coming from
94d7556
to
40d4113
Compare
Signed-off-by: rbrtbnfgl <roberto.bonafiglia@gmail.com>
Signed-off-by: rbrtbnfgl <roberto.bonafiglia@gmail.com>
Signed-off-by: rbrtbnfgl <roberto.bonafiglia@gmail.com>
40d4113
to
78c6ddf
Compare
Signed-off-by: rbrtbnfgl <roberto.bonafiglia@gmail.com>
Description
Added a different chain for Flannel iptables rules to order the rules before the one already present on the node.
It should solve #1619 #1542 #1033
Todos
Release Note