From 9b3ab1109ff64abdc565a0e675a332500398ab00 Mon Sep 17 00:00:00 2001 From: Nadia Pinaeva Date: Thu, 2 May 2024 16:04:07 +0200 Subject: [PATCH] event: export Unmarshal method This is useful for callers that bring their own netlink receiver (e.g. rcvmmsg) but still want to use the unmarshaling infrastructure. Signed-off-by: Nadia Pinaeva --- conn.go | 2 +- event.go | 4 ++-- event_test.go | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/conn.go b/conn.go index ac7fae6..bb88ee4 100644 --- a/conn.go +++ b/conn.go @@ -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 diff --git a/event.go b/event.go index 6ac41f5..76bd806 100644 --- a/event.go +++ b/event.go @@ -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 diff --git a/event_test.go b/event_test.go index d3155ee..38df870 100644 --- a/event_test.go +++ b/event_test.go @@ -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") }) } @@ -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