Skip to content

Commit

Permalink
Fix not mangle policy insertion priority
Browse files Browse the repository at this point in the history
Signed-off-by: lou-lan <[email protected]>
  • Loading branch information
lou-lan committed Mar 29, 2024
1 parent a900eaa commit d3f2474
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions pkg/agent/police.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func (r *policeReconciler) getPolicySrcIPs(policyNs, policyName string, filter f
}

func buildEipRule(policyName string, eip IP, version uint8, isIgnoreInternalCIDR bool) *iptables.Rule {
if eip.V4 == "" && eip.V6 == "" {
if (version == 4 && eip.V4 == "") || (version == 6 && eip.V6 == "") {
return nil
}

Expand Down Expand Up @@ -775,24 +775,22 @@ func buildMangleStaticRule(base uint32,
}}

prerouting := make([]iptables.Rule, 0)
prerouting = append(prerouting, iptables.Rule{
Match: iptables.MatchCriteria{},
Action: iptables.JumpAction{Target: "EGRESSGATEWAY-MARK-REQUEST"},
Comment: []string{
"Checking for EgressPolicy matched traffic",
},
})

if isEgressNode && enableGatewayReplyRoute {
prerouting = []iptables.Rule{
{
Match: iptables.MatchCriteria{},
Action: iptables.JumpAction{Target: "EGRESSGATEWAY-REPLY-ROUTING"},
Comment: []string{
"egressGateway Reply datapath rule, rule is from the EgressGateway",
},
},
{
Match: iptables.MatchCriteria{},
Action: iptables.JumpAction{Target: "EGRESSGATEWAY-MARK-REQUEST"},
Comment: []string{
"Checking for EgressPolicy matched traffic",
},
prerouting = append(prerouting, iptables.Rule{
Match: iptables.MatchCriteria{},
Action: iptables.JumpAction{Target: "EGRESSGATEWAY-REPLY-ROUTING"},
Comment: []string{
"egressGateway Reply datapath rule, rule is from the EgressGateway",
},
}
})
postrouting = append(postrouting, iptables.Rule{
Match: iptables.MatchCriteria{}.MarkMatchesWithMask(replyMark, 0xffffffff),
Action: iptables.SetMaskedMarkAction{Mark: 0x00000000, Mask: 0xffffffff},
Expand Down Expand Up @@ -1113,7 +1111,7 @@ func newPolicyController(mgr manager.Manager, log logr.Logger, cfg *config.Confi
filterTables = append(filterTables, filterTable)
}
if cfg.FileConfig.EnableIPv6 {
mangle, err := iptables.NewTable("mangle", 6, "egw:-", opt, log)
mangle, err := iptables.NewTable("mangle", 6, "egw:", opt, log)
if err != nil {
return err
}
Expand Down

0 comments on commit d3f2474

Please sign in to comment.