Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: support for fw-counters #588

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading