Skip to content

Commit

Permalink
Fix refresh bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Jan 17, 2025
1 parent 18d23d4 commit 798a4af
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions client/firewall/nftables/acl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ func (m *AclManager) Flush() error {
return err
}

if err := m.refreshRuleHandles(m.chainInputRules); err != nil {
if err := m.refreshRuleHandles(m.chainInputRules, false); err != nil {
log.Errorf("failed to refresh rule handles ipv4 input chain: %v", err)
}
if err := m.refreshRuleHandles(m.chainPrerouting); err != nil {
if err := m.refreshRuleHandles(m.chainPrerouting, true); err != nil {
log.Errorf("failed to refresh rule handles prerouting chain: %v", err)
}

Expand Down Expand Up @@ -398,8 +398,7 @@ func (m *AclManager) createPreroutingRule(expressions []expr.Any, userData []byt
return nil
}

preroutingExprs := make([]expr.Any, len(expressions))
copy(preroutingExprs, expressions)
preroutingExprs := slices.Clone(expressions)

// interface
preroutingExprs = append([]expr.Any{
Expand Down Expand Up @@ -685,7 +684,7 @@ func (m *AclManager) flushWithBackoff() (err error) {
return
}

func (m *AclManager) refreshRuleHandles(chain *nftables.Chain) error {
func (m *AclManager) refreshRuleHandles(chain *nftables.Chain, mangle bool) error {
if m.workTable == nil || chain == nil {
return nil
}
Expand All @@ -702,7 +701,11 @@ func (m *AclManager) refreshRuleHandles(chain *nftables.Chain) error {
split := bytes.Split(rule.UserData, []byte(" "))
r, ok := m.rules[string(split[0])]
if ok {
*r.nftRule = *rule
if mangle {
*r.mangleRule = *rule
} else {
*r.nftRule = *rule
}
}
}

Expand Down

0 comments on commit 798a4af

Please sign in to comment.