Skip to content

Commit

Permalink
Objects implementation refactor
Browse files Browse the repository at this point in the history
Refactored obj.go to a more generic approach
Added object support for already implemented expressions
Added test for limit object
Fixes #253
  • Loading branch information
turekt committed Jul 27, 2024
1 parent 912dee6 commit eab2afa
Show file tree
Hide file tree
Showing 5 changed files with 716 additions and 85 deletions.
16 changes: 15 additions & 1 deletion counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ package nftables

import (
"github.com/google/nftables/binaryutil"
"github.com/google/nftables/expr"
"github.com/mdlayher/netlink"
"golang.org/x/sys/unix"
)

// CounterObj implements Obj.
type CounterObj struct {
Table *Table
Name string // e.g. “fwded”
Expand All @@ -41,6 +41,20 @@ func (c *CounterObj) unmarshal(ad *netlink.AttributeDecoder) error {
return ad.Err()
}

func (c *CounterObj) data() expr.Any {
return &expr.Counter{
Bytes: c.Bytes,
Packets: c.Packets,
}
}

func (c *CounterObj) name() string {
return c.Name
}
func (c *CounterObj) objType() ObjType {
return ObjTypeCounter
}

func (c *CounterObj) table() *Table {
return c.Table
}
Expand Down
2 changes: 1 addition & 1 deletion monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (monitor *Monitor) monitor() {
}
monitor.eventCh <- event
case unix.NFT_MSG_NEWOBJ, unix.NFT_MSG_DELOBJ:
obj, err := objFromMsg(msg)
obj, err := objFromMsg(msg, true)
event := &MonitorEvent{
Type: MonitorEventType(msgType),
Data: obj,
Expand Down
Loading

0 comments on commit eab2afa

Please sign in to comment.