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

Added a different chain for iptables rules #1650

Merged
merged 4 commits into from
Oct 5, 2022

Conversation

rbrtbnfgl
Copy link
Contributor

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

  • Tests
  • Documentation
  • Release note

Release Note

None required

@@ -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) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Comment on lines 46 to 53
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"}},
}

Copy link
Collaborator

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

Comment on lines 34 to 40
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"}},
}
Copy link
Collaborator

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

@@ -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)
Copy link
Collaborator

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?

@rbrtbnfgl rbrtbnfgl force-pushed the iptables-rule branch 2 times, most recently from 744a437 to e8482f3 Compare September 28, 2022 10:23
Copy link
Collaborator

@manuelbuil manuelbuil left a 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

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)
Copy link
Collaborator

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

@rbrtbnfgl rbrtbnfgl force-pushed the iptables-rule branch 2 times, most recently from 94d7556 to 40d4113 Compare September 28, 2022 10:37
Signed-off-by: rbrtbnfgl <roberto.bonafiglia@gmail.com>
Signed-off-by: rbrtbnfgl <roberto.bonafiglia@gmail.com>
Signed-off-by: rbrtbnfgl <roberto.bonafiglia@gmail.com>
Signed-off-by: rbrtbnfgl <roberto.bonafiglia@gmail.com>
@rbrtbnfgl rbrtbnfgl merged commit 3eebfb5 into flannel-io:master Oct 5, 2022
@rbrtbnfgl rbrtbnfgl deleted the iptables-rule branch October 5, 2022 14:34
@rbrtbnfgl rbrtbnfgl mentioned this pull request Feb 16, 2023
3 tasks
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.

None yet

3 participants