go-linux

Netlink decisions

Part of the accepted-design index.

Transport and caller boundary

Netlink is a record protocol with variable-length headers, protocol-specific payloads, and lossy multicast delivery. io.Reader, net.Conn, and a syscall callback would conceal required boundaries or move descriptor management back to callers. The package owns typed framing and exchanges over the existing socket transport, keeping descriptor lifetime and Go polling in one place. Message headers preserve Linux names and identifiers, while encoding derives lengths from the actual payload. The maintained x/sys/unix constants and Linux 7.0 Netlink UAPI and Generic Netlink UAPI define the layout; no unsafe casts or architecture-specific syscall tables are needed.

Protocol payloads remain byte slices because fixed headers and attribute policies belong to their facility. This is a concrete kernel messaging operation, not descriptor access. netlink/route owns routing semantics without adding route-specific knowledge here. Unknown attribute IDs, output flags, and extended ACK TLVs survive decoding so new kernel information remains inspectable. Generic family discovery validates the bounded controller schema, tolerates historical unflagged nests, and retains operations/policy data without pretending it is a complete schema compiler. Scalar helpers enforce width and byte order; ordinary attribute framing intentionally does not enforce arbitrary family policy.

Exchange ownership and concurrency

A request connection serializes complete exchanges under one mutex. A separate listener owns subscriptions and reception. The alternative, multiplexing outstanding requests and multicast on one socket, requires a persistent receive loop, pending-request registry, buffering limits, cancellation policy, and fan-out ownership. No current consumer needs that machinery. Explicit connection separation prevents notifications from being mistaken for replies and leaves parallelism and scheduling with the application. Deadlines and Close can interrupt I/O through the established transport, but a deadline is not a timed mutex acquisition.

Every request carries a nonzero sequence and requests acknowledgement. Ordinary requests complete at ACK; multipart requests drain to DONE. Separate Execute and Dump operations resolve the Linux flag-bit overlap between GET dumps and NEW modifiers. Echo/custom-completion exchanges are omitted rather than accepting modes whose completion cannot be established. Sender sockaddr identity is checked independently of header fields; received nlmsg_pid can name the recipient and is not authentication. The kernel introduction and Linux 7.0 ACK/dump implementation establish these distinctions.

Linux mutates the original request header during IPv6 multipath insertion. After the first sibling is inserted, it clears exclusive and replace and sets create so it can add the remaining siblings. The original sender and echoed message identity still have to match. For an ordinary exchange, the ACK matcher allows transitions from Create|Exclusive, Replace, or Create|Replace to Create and verifies the remaining bits and fields exactly. The returned ACK retains the header as sent by Linux. Linux 7.0 IPv6 route implementation.

Bounded reception and failure recovery

Each datagram has an explicit receive bound, and a request has an aggregate wire-byte bound. Growing indefinitely would make kernel-controlled dumps an unbounded allocation source; peeking/retrying a datagram would add transport synchronization and still require a maximum. Truncated datagrams are consumed and reported, with no partial decode presented as valid records. Pure parsers borrow the input, reject malformed batches, and accept a final record without any alignment padding, matching Linux’s record-length convention. Nested parsing is explicit and does not introduce recursive stack growth.

An incomplete exchange closes its connection. Merely incrementing the next sequence would leave an active kernel dump or unread messages, and silently discarding those messages could hide data loss or spin forever. Reopening gives the next request a fresh receive queue. A terminal kernel rejection is complete and permits reuse; a dump carrying DUMP_INTR drains to terminal status when possible and returns an explicit error. Partial earlier replies remain available for diagnostics but are never an implied snapshot. Mutation rollback and automatic retries would be dishonest after an ambiguous transport failure, so both stay with the caller.

Extended and capped ACKs are always enabled, including success warnings. Error identity remains the original errno; structured diagnostics supplement it. Unknown TLVs remain available instead of expanding the public API for each kernel policy extension. Multicast loss remains visible through ENOBUFS, overrun messages, and truncation; the package never enables loss suppression or invents an atomic subscription-and-dump operation. Destination-group ancillary reporting and automatic resynchronization remain omitted until a concrete consumer needs their additional transport and policy contracts.