Skip to content

Commit

Permalink
Merge branch 'NET-1784' of https://github.com/gravitl/netclient into …
Browse files Browse the repository at this point in the history
…NET-1784-nftables
  • Loading branch information
abhishek9686 committed Dec 6, 2024
2 parents a23fc02 + e5f79f4 commit f0e09b5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions firewall/iptables_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ var (
table: defaultIpTable,
chain: iptableINChain,
},
{
rule: []string{"-i", ncutils.GetInterfaceName(), "-m", "conntrack",
"--ctstate", "ESTABLISHED,RELATED", "-m", "comment",
"--comment", netmakerSignature, "-j", "ACCEPT"},
table: defaultIpTable,
chain: iptableFWDChain,
},
{
rule: []string{"-o", ncutils.GetInterfaceName(), "-m", "conntrack",
"--ctstate", "ESTABLISHED,RELATED", "-m", "comment",
"--comment", netmakerSignature, "-j", "ACCEPT"},
table: defaultIpTable,
chain: iptableFWDChain,
},
{
rule: []string{"-i", ncutils.GetInterfaceName(), "-j", aclInputRulesChain,
"-m", "comment", "--comment", netmakerSignature},
Expand Down Expand Up @@ -455,6 +469,9 @@ func (i *iptablesManager) InsertIngressRoutingRules(server string, ingressInfo m
continue
}
ruleSpec := []string{"-s", rule.SrcIP.String()}
if rule.DstIP.IP != nil {
ruleSpec = append(ruleSpec, "-d", rule.DstIP.String())
}
if rule.AllowedProtocol.String() != "" && rule.AllowedProtocol != models.ALL {
ruleSpec = append(ruleSpec, "-p", rule.AllowedProtocol.String())
}
Expand All @@ -466,6 +483,9 @@ func (i *iptablesManager) InsertIngressRoutingRules(server string, ingressInfo m

} else {
ruleSpec := []string{"-s", rule.SrcIP.String()}
if rule.DstIP.IP != nil {
ruleSpec = append(ruleSpec, "-d", rule.DstIP.String())
}
if rule.AllowedProtocol.String() != "" && rule.AllowedProtocol != models.ALL {
ruleSpec = append(ruleSpec, "-p", rule.AllowedProtocol.String())
}
Expand Down Expand Up @@ -528,6 +548,7 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
}
ruleSpec = append(ruleSpec, "--dport", port)
ruleSpec = append(ruleSpec, "-m", "addrtype", "--dst-type", "LOCAL")
ruleSpec = append(ruleSpec, "-j", "ACCEPT")
ruleSpec = appendNetmakerCommentToRule(ruleSpec)
rulesSpec = append(rulesSpec, ruleSpec)
Expand All @@ -538,6 +559,7 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
if aclRule.AllowedProtocol.String() != "" && aclRule.AllowedProtocol != models.ALL {
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
}
ruleSpec = append(ruleSpec, "-m", "addrtype", "--dst-type", "LOCAL")
ruleSpec = append(ruleSpec, "-j", "ACCEPT")
ruleSpec = appendNetmakerCommentToRule(ruleSpec)
rulesSpec = append(rulesSpec, ruleSpec)
Expand Down Expand Up @@ -576,6 +598,7 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
}
ruleSpec = append(ruleSpec, "--dport", port)
ruleSpec = append(ruleSpec, "-m", "addrtype", "--dst-type", "LOCAL")
ruleSpec = append(ruleSpec, "-j", "ACCEPT")
ruleSpec = appendNetmakerCommentToRule(ruleSpec)
rulesSpec = append(rulesSpec, ruleSpec)
Expand All @@ -586,6 +609,7 @@ func (i *iptablesManager) AddAclRules(server string, aclRules map[string]models.
if aclRule.AllowedProtocol.String() != "" && aclRule.AllowedProtocol != models.ALL {
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
}
ruleSpec = append(ruleSpec, "-m", "addrtype", "--dst-type", "LOCAL")
ruleSpec = append(ruleSpec, "-j", "ACCEPT")
ruleSpec = appendNetmakerCommentToRule(ruleSpec)
rulesSpec = append(rulesSpec, ruleSpec)
Expand Down Expand Up @@ -650,6 +674,7 @@ func (i *iptablesManager) UpsertAclRule(server string, aclRule models.AclRule) {
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
}
ruleSpec = append(ruleSpec, "--dport", port)
ruleSpec = append(ruleSpec, "-m", "addrtype", "--dst-type", "LOCAL")
ruleSpec = append(ruleSpec, "-j", "ACCEPT")
ruleSpec = appendNetmakerCommentToRule(ruleSpec)
rulesSpec = append(rulesSpec, ruleSpec)
Expand All @@ -660,6 +685,7 @@ func (i *iptablesManager) UpsertAclRule(server string, aclRule models.AclRule) {
if aclRule.AllowedProtocol.String() != "" {
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
}
ruleSpec = append(ruleSpec, "-m", "addrtype", "--dst-type", "LOCAL")
ruleSpec = append(ruleSpec, "-j", "ACCEPT")
ruleSpec = appendNetmakerCommentToRule(ruleSpec)
rulesSpec = append(rulesSpec, ruleSpec)
Expand Down Expand Up @@ -697,6 +723,7 @@ func (i *iptablesManager) UpsertAclRule(server string, aclRule models.AclRule) {
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
}
ruleSpec = append(ruleSpec, "--dport", port)
ruleSpec = append(ruleSpec, "-m", "addrtype", "--dst-type", "LOCAL")
ruleSpec = append(ruleSpec, "-j", "ACCEPT")
rulesSpec = append(rulesSpec, ruleSpec)
}
Expand All @@ -706,6 +733,7 @@ func (i *iptablesManager) UpsertAclRule(server string, aclRule models.AclRule) {
if aclRule.AllowedProtocol.String() != "" {
ruleSpec = append(ruleSpec, "-p", aclRule.AllowedProtocol.String())
}
ruleSpec = append(ruleSpec, "-m", "addrtype", "--dst-type", "LOCAL")
ruleSpec = append(ruleSpec, "-j", "ACCEPT")
rulesSpec = append(rulesSpec, ruleSpec)
}
Expand Down

0 comments on commit f0e09b5

Please sign in to comment.