Skip to content

Commit

Permalink
fw: fixed adding 'counter' obj to rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavo-iniguez-goya committed Jul 3, 2024
1 parent c89b490 commit f882cf4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions daemon/firewall/nftables/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,14 @@ func (n *Nft) parseExpression(table, chain, family string, expression *config.Ex
exprList = append(exprList, *exprs.NewNoTrack()...)

case exprs.NFT_COUNTER:
tbl := n.GetTable(table, family)
if tbl == nil {
log.Warning("%s Error getting table counter: %s, %s, %s", logTag, table, chain, family)
return nil
}
defaultCounterName := "opensnitch"
counterObj := &nftables.CounterObj{
Table: &nftables.Table{Name: table, Family: nftables.TableFamilyIPv4},
Table: tbl,
Name: defaultCounterName,
Bytes: 0,
Packets: 0,
Expand All @@ -187,7 +192,17 @@ func (n *Nft) parseExpression(table, chain, family string, expression *config.Ex
counterObj.Packets = 1
}
}
n.Conn.AddObj(counterObj)
cntObj := n.Conn.AddObj(counterObj)
if cntObj == nil {
log.Warning("Error adding counter %s", defaultCounterName)
return nil
}
if !n.Commit() {
log.Warning("Error creating counter %s", defaultCounterName)
return nil
}
log.Debug("%s counter %s created (%s, %s, %s)", logTag, defaultCounterName, table, chain, family)

exprList = append(exprList, *exprs.NewExprCounter(defaultCounterName)...)
}

Expand Down

0 comments on commit f882cf4

Please sign in to comment.