From 2025aec0d28d9474c65b416b599ef1328bb34210 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 11 Jun 2022 23:25:19 +0200 Subject: [PATCH] nftest: generate message acknowledgements Previously, the code just returned the input requests, which happened to work --- internal/nftest/nftest.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/nftest/nftest.go b/internal/nftest/nftest.go index 7651b4f..2709fa7 100644 --- a/internal/nftest/nftest.go +++ b/internal/nftest/nftest.go @@ -4,7 +4,6 @@ package nftest import ( "bytes" "fmt" - "log" "strings" "testing" @@ -26,11 +25,21 @@ func (r *Recorder) Conn() (*nftables.Conn, error) { func(req []netlink.Message) ([]netlink.Message, error) { r.requests = append(r.requests, req...) - // TODO: generate and return acknowledgements + acks := make([]netlink.Message, 0, len(req)) for _, msg := range req { - log.Printf("msg: %+v", msg) + if msg.Header.Flags&netlink.Acknowledge != 0 { + acks = append(acks, netlink.Message{ + Header: netlink.Header{ + Length: 4, + Type: netlink.Error, + Sequence: msg.Header.Sequence, + PID: msg.Header.PID, + }, + Data: []byte{0, 0, 0, 0}, + }) + } } - return req, nil + return acks, nil })) }