nftest: generate message acknowledgements

Previously, the code just returned the input requests, which happened to work
This commit is contained in:
Michael Stapelberg 2022-06-11 23:25:19 +02:00
parent 2719b9add1
commit 2025aec0d2
1 changed files with 13 additions and 4 deletions

View File

@ -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
}))
}