1
0
forked from rosa/hakurei

internal/netlink: optional check header as reply

Not every received message is a reply.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-25 19:33:01 +09:00
parent 372d509e5c
commit 722c3cc54f
2 changed files with 16 additions and 10 deletions

View File

@@ -232,6 +232,14 @@ func (e *InconsistentError) Error() string {
return s
}
// checkReply checks the message header of a reply from the kernel.
func (c *conn) checkReply(header *syscall.NlMsghdr) error {
if header.Seq != c.seq || header.Pid != c.port {
return &InconsistentError{*header, c.seq, c.port}
}
return nil
}
// pending returns the valid slice of buf and initialises pos.
func (c *conn) pending() []byte {
buf := c.buf[:c.pos]
@@ -275,12 +283,6 @@ func (c *conn) receive(ctx context.Context, f HandlerFunc, flags int) error {
return err
}
for i := range resp {
header := &resp[i].Header
if header.Seq != c.seq || header.Pid != c.port {
return &InconsistentError{*header, c.seq, c.port}
}
}
if err = f(resp); err != nil {
if err == (Complete{}) {
return nil