Skip to content

Commit

Permalink
Merge pull request #1280 from spidernet-io/fix/policy
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhoublue authored Mar 29, 2024
2 parents 73e53d4 + d3f2474 commit bee914e
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

1 comment on commit bee914e

@weizhoublue
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.