Skip to content

Commit

Permalink
Merge pull request loxilb-io#588 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR: support for fw-counters
  • Loading branch information
UltraInstinct14 authored Mar 14, 2024
2 parents b89b166 + 562fe27 commit 7e3e275
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions api/models/firewall_option_entry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions api/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/restapi/handler/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func ConfigGetFW(params operations.GetConfigFirewallAllParams) middleware.Respon
tmpOpts.Trap = FW.Opts.Trap
tmpOpts.Record = FW.Opts.Record
tmpOpts.FwMark = int64(FW.Opts.Mark)
tmpOpts.Counter = FW.Opts.Counter

tmpResult.RuleArguments = &tmpRule
tmpResult.Opts = &tmpOpts
Expand Down
6 changes: 5 additions & 1 deletion api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3215,6 +3215,10 @@ definitions:
fwMark:
type: integer
description: Set a fwmark for any matching rule
counter:
type: string
description: traffic counters


FirewallRuleEntry:
type: object
Expand Down Expand Up @@ -3359,4 +3363,4 @@ definitions:
retryCount:
type: integer
format: uint8
description: Retry Count to detect failure
description: Retry Count to detect failure
2 changes: 2 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ type FwOptArg struct {
Allow bool `json:"allow"`
// Mark - Mark the matching rule
Mark uint32 `json:"fwMark"`
// Counter - Traffic counter
Counter string `json:"counter"`
}

// FwRuleArg - Information related to firewall rule
Expand Down
19 changes: 19 additions & 0 deletions loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,9 @@ func (R *RuleH) GetFwRule() ([]cmn.FwRuleMod, error) {
ret.Opts.Mark = fwOpts.opt.fwMark
ret.Opts.Record = fwOpts.opt.record

data.Fw2DP(DpStatsGetImm)
ret.Opts.Counter = fmt.Sprintf("%v:%v", data.stat.packets, data.stat.bytes)

// Make FwRule
res = append(res, ret)
}
Expand Down Expand Up @@ -2417,6 +2420,22 @@ func (r *ruleEnt) Nat2DP(work DpWorkT) int {
// Fw2DP - Sync state of fw-rule entity to data-path
func (r *ruleEnt) Fw2DP(work DpWorkT) int {

if work == DpStatsGet || work == DpStatsGetImm {
nStat := new(StatDpWorkQ)
nStat.Work = work
nStat.Mark = uint32(r.ruleNum)
nStat.Name = MapNameFw4
nStat.Bytes = &r.stat.bytes
nStat.Packets = &r.stat.packets

if work != DpStatsGetImm {
mh.dp.ToDpCh <- nStat
} else {
DpWorkSingle(mh.dp, nStat)
}
return 0
}

nWork := new(FwDpWorkQ)

nWork.Work = work
Expand Down

0 comments on commit 7e3e275

Please sign in to comment.