Skip to content

Commit

Permalink
iptables drop invalid rst (#3484)
Browse files Browse the repository at this point in the history
* iptables drop invalid rst

Signed-off-by: changluyi <[email protected]>

* Update uninstall.sh

---------

Signed-off-by: changluyi <[email protected]>
  • Loading branch information
changluyi authored Dec 5, 2023
1 parent 7436dc4 commit 984f227
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dist/images/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ iptables -t mangle -F OVN-PREROUTING
iptables -t mangle -X OVN-PREROUTING
iptables -t mangle -F OVN-OUTPUT
iptables -t mangle -X OVN-OUTPUT
iptables -t mangle -F OVN-POSTROUTING
iptables -t mangle -X OVN-POSTROUTING

sleep 1

Expand Down Expand Up @@ -67,6 +69,8 @@ ip6tables -t mangle -F OVN-PREROUTING
ip6tables -t mangle -X OVN-PREROUTING
ip6tables -t mangle -F OVN-OUTPUT
ip6tables -t mangle -X OVN-OUTPUT
ip6tables -t mangle -F OVN-POSTROUTING
ip6tables -t mangle -X OVN-POSTROUTING

sleep 1

Expand Down
16 changes: 15 additions & 1 deletion pkg/daemon/gateway_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ func (c *Controller) setIptables() error {
{Table: "filter", Chain: "FORWARD", Rule: strings.Fields(`-m set --match-set ovn40services dst -j ACCEPT`)},
// Output unmark to bypass kernel nat checksum issue https://github.com/flannel-io/flannel/issues/1279
{Table: "filter", Chain: "OUTPUT", Rule: strings.Fields(`-p udp -m udp --dport 6081 -j MARK --set-xmark 0x0`)},
// Drop invalid rst
{Table: MANGLE, Chain: OvnPostrouting, Rule: strings.Fields(`-p tcp -m set --match-set ovn40subnets src -m tcp --tcp-flags RST RST -m state --state INVALID -j DROP`)},
}
v6Rules = []util.IPTableRule{
// mark packets from pod to service
Expand Down Expand Up @@ -588,6 +590,8 @@ func (c *Controller) setIptables() error {
{Table: "filter", Chain: "FORWARD", Rule: strings.Fields(`-m set --match-set ovn60services dst -j ACCEPT`)},
// Output unmark to bypass kernel nat checksum issue https://github.com/flannel-io/flannel/issues/1279
{Table: "filter", Chain: "OUTPUT", Rule: strings.Fields(`-p udp -m udp --dport 6081 -j MARK --set-xmark 0x0`)},
// Drop invalid rst
{Table: MANGLE, Chain: OvnPostrouting, Rule: strings.Fields(`-p tcp -m set --match-set ovn60subnets src -m tcp --tcp-flags RST RST -m state --state INVALID -j DROP`)},
}
)
protocols := make([]string, 2)
Expand Down Expand Up @@ -710,7 +714,7 @@ func (c *Controller) setIptables() error {
}
}

var natPreroutingRules, natPostroutingRules, ovnMasqueradeRules []util.IPTableRule
var natPreroutingRules, natPostroutingRules, ovnMasqueradeRules, manglePostrutingRules []util.IPTableRule
for _, rule := range iptablesRules {
if rule.Table == NAT {
if c.k8siptables[protocol].HasRandomFully() &&
Expand All @@ -729,6 +733,11 @@ func (c *Controller) setIptables() error {
ovnMasqueradeRules = append(ovnMasqueradeRules, rule)
continue
}
} else if rule.Table == MANGLE {
if rule.Chain == OvnPostrouting {
manglePostrutingRules = append(manglePostrutingRules, rule)
continue
}
}

if err = c.createIptablesRule(ipt, rule); err != nil {
Expand Down Expand Up @@ -780,6 +789,11 @@ func (c *Controller) setIptables() error {
return err
}

if err = c.updateIptablesChain(ipt, MANGLE, OvnPostrouting, Postrouting, manglePostrutingRules); err != nil {
klog.Errorf("failed to update chain %s/%s: %v", MANGLE, OvnPostrouting, err)
return err
}

if err = c.cleanObsoleteIptablesRules(protocol, obsoleteRules); err != nil {
klog.Errorf("failed to clean legacy iptables rules: %v", err)
return err
Expand Down

0 comments on commit 984f227

Please sign in to comment.