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

Make Event.Unmarshal method public. #39

Merged
merged 3 commits into from
May 17, 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
6 changes: 0 additions & 6 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
linters-settings:
staticcheck:
go: "1.19"
unused:
go: "1.19"

linters:
enable:
- gofmt
Expand Down
2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (c *Conn) eventWorker(workerID uint8, evChan chan<- Event, errChan chan<- e

// Decode event and send on channel
ev = *new(Event)
err := ev.unmarshal(recv[0])
err := ev.Unmarshal(recv[0])
if err != nil {
errChan <- err
return
Expand Down
4 changes: 2 additions & 2 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (et *eventType) unmarshal(h netfilter.Header) error {
return nil
}

// unmarshal unmarshals a Netlink message into an Event structure.
func (e *Event) unmarshal(nlmsg netlink.Message) error {
// Unmarshal unmarshals a Netlink message into an Event structure.
func (e *Event) Unmarshal(nlmsg netlink.Message) error {
// Make sure we don't re-use an Event structure
if e.Expect != nil || e.Flow != nil {
return errReusedEvent
Expand Down
8 changes: 4 additions & 4 deletions event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestEventUnmarshal(t *testing.T) {
require.NoError(t, err)

var e Event
assert.NoError(t, e.unmarshal(nlm))
assert.NoError(t, e.Unmarshal(nlm))
assert.Equal(t, tt.e, e, "unexpected unmarshal")
})
}
Expand All @@ -144,17 +144,17 @@ func TestEventUnmarshal(t *testing.T) {
func TestEventUnmarshalError(t *testing.T) {
// Unmarshal into event with existing Flow
eventExistingFlow := Event{Flow: &Flow{}}
assert.ErrorIs(t, eventExistingFlow.unmarshal(netlink.Message{}), errReusedEvent)
assert.ErrorIs(t, eventExistingFlow.Unmarshal(netlink.Message{}), errReusedEvent)

// EventType unmarshal error, blank SubsystemID
var emptyEvent Event
assert.ErrorIs(t, emptyEvent.unmarshal(netlink.Message{
assert.ErrorIs(t, emptyEvent.Unmarshal(netlink.Message{
Header: netlink.Header{},
Data: []byte{1, 2, 3, 4},
}), errNotConntrack)

// Cause a random error during Flow unmarshal
assert.ErrorIs(t, emptyEvent.unmarshal(netlink.Message{
assert.ErrorIs(t, emptyEvent.Unmarshal(netlink.Message{
Header: netlink.Header{Type: netlink.HeaderType(netfilter.NFSubsysCTNetlink) << 8},
Data: []byte{
1, 2, 3, 4, // random 4-byte nfgenmsg
Expand Down
10 changes: 3 additions & 7 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ func (s Status) String() string {
}

func (e Event) String() string {

if e.Flow != nil {

// Status flag
status := ""
if !e.Flow.Status.SeenReply() {
Expand Down Expand Up @@ -117,17 +115,15 @@ func (e Event) String() string {
e.Flow.Zone,
acct, labels, mark,
seqadjo, seqadjr, secctx)
}

} else if e.Expect != nil {

if e.Expect != nil {
return fmt.Sprintf("[%s] Timeout: %d, Master: %s, Tuple: %s, Mask: %s, Zone: %d, Helper: '%s', Class: %#x",
e.Type, e.Expect.Timeout,
e.Expect.TupleMaster, e.Expect.Tuple, e.Expect.Mask,
e.Expect.Zone, e.Expect.HelpName, e.Expect.Class,
)

} else {
return fmt.Sprintf("[%s] <Empty Event>", e.Type)
}

return fmt.Sprintf("[%s] <Empty Event>", e.Type)
}
Loading