From nobody Mon Jan 23 22:12:01 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P148K64JHz2t0Wg; Mon, 23 Jan 2023 22:12:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P148K4sLfz3LGg; Mon, 23 Jan 2023 22:12:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674511921; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=56esKWXgQoK9qZw4K5mqe1qLEbH/lYSjFCOto+3bqiE=; b=xAChHPldWgKOn6lGyRBiaP6oc0rtJVn7uJBJY3e+ayirtolIWALxu/P2+Uw8BwyhyEZumT gCOsTIR6HYBHEWDxX4d2H50xIdL9XdmtDayGfIcoIXuNl9zxZCao7KRbEJt6JDSHiOt3Rx YrvMOzUhHvD1LMskioTMqJLBZV6gohjTy0I37kvR0a8ZFGmcCh8ma4y6qYXsqRkZpoxCeK mRKVshBgI63HCsoPxMRkaC4Ohzo3o57/LM8BOne/hopYNd4odZQTj4FYIjZBcsp40ohKEL fCHd/4GQCV279SKceLX82AtBKKFuKNqEaahUSfx1XEz9T9zrMRbDDCZLMxvFnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674511921; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=56esKWXgQoK9qZw4K5mqe1qLEbH/lYSjFCOto+3bqiE=; b=pgkG/buMGIBR4wsMpB52C++Bj2b5veIV9JM1NzV5DAcMOFOKGtlFcabWuw/rHWbSiWyusV ngfoTdgU+3g7kscuM7Uf/A8omjeQ5lMeqL8jCJmxqI19qFdaglsHuJvksTw5Iz4gUJM0lY fMLnhDGZ43kdg8tIAC38yNeEwA+7c1BPRH8sYrNHarh+Ox+yeTWlT4bJ2ENZGjPOfWHxu3 EeIeHtDsaK3T2uVFb3n9cAhlwtOCG2/vic7iM61sDSoTcB9EOdKUvf5XilI5R9iAbqNq+n 965iQCJblFjbzyeMDDq4deRYu/NPXedZfxzLxRSviW5k/ICtcDRvd3qCj6/6zQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674511921; a=rsa-sha256; cv=none; b=svzKzWitWgAMFI4w5I/slCzmk3o0jNXHhcmIJOCVkhZBsJGkvNBsBdU7Fl0lLrNH8DAK1C iUk8725lhF0SbU5xlPzjNMzZ7TKAtzQcSUQbBtU+3RvCdqwtRgoMateq6X1ITBKv0t03+I 8x5ZZ/6P7Gulq+LgiuV1I8YmKsZpnX4LLXuhlXe9UBJbFhcTE/E3qiTbkkpla17ahc/tPQ yHwWg6cuRNiR+paSJXXoOM+cA5as3dedQXP6Ulrw9uJ+rk82DyvUJJ+3Ipk+ENAQfqcMNE Wy2VjIOPNCiY0M57SdlDKL+gOw2gWn/Gt4PfrBjzPNtLQ7xN2OCGq6A8yALuIQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P148K3xqXzm2R; Mon, 23 Jan 2023 22:12:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30NMC1XQ012879; Mon, 23 Jan 2023 22:12:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30NMC1NJ012878; Mon, 23 Jan 2023 22:12:01 GMT (envelope-from git) Date: Mon, 23 Jan 2023 22:12:01 GMT Message-Id: <202301232212.30NMC1NJ012878@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: a6b537f6b945 - stable/13 - netlink: suppress sending NLMSG_ERROR if NLMSG_DONE is already sent List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a6b537f6b9459dbc0f5f2f60d973f025c6e63782 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=a6b537f6b9459dbc0f5f2f60d973f025c6e63782 commit a6b537f6b9459dbc0f5f2f60d973f025c6e63782 Author: Alexander V. Chernikov AuthorDate: 2022-11-30 12:15:23 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-23 22:04:03 +0000 netlink: suppress sending NLMSG_ERROR if NLMSG_DONE is already sent Netlink has a confirmation/error reporting mechanism for the sent messages. Kernel explicitly acks each messages if requested (NLM_F_ACK) or if message processing results in an error. Similarly, for multipart messages - typically dumps, where each message represents a single object like an interface or a route - another message, NLMSG_DONE is used to indicate the end of dump and the resulting status. As a result, successfull dump ends with both NLMSG_DONE and NLMSG_ERROR messages. RFC 3549 does not say anything specific about such case. Linux adopted an optimisation which suppresses NLMSG_ERROR message when NLMSG_DONE is already sent. Certain libraries/applications like libnl depends on such behavior. Suppress sending NLMSG_ERROR if NLMSG_DONE is already sent, by setting newly-added 'suppress_ack' flag in the writer and checking this flag when generating ack. This change restores libnl compatibility. Before: ``` ~ nl-link-list Error: Unable to allocate link cache: Message sequence number mismatch ```` After: ``` ~ nl-link-list vtnet0 ether 52:54:00:14:e3:19 lo0 ieee1394 ``` Reviewed by: bapt,pauamma Tested by: bapt Differential Revision: https://reviews.freebsd.org/D37565 (cherry picked from commit f4d3aa74908496f1f5815caca94ebd86944b17cb) --- share/man/man4/netlink.4 | 9 +++++++-- sys/netlink/netlink_io.c | 13 ++++++++----- sys/netlink/netlink_message_writer.c | 4 ++++ sys/netlink/netlink_message_writer.h | 1 + 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/share/man/man4/netlink.4 b/share/man/man4/netlink.4 index c75366f560f0..bbfa55049e2e 100644 --- a/share/man/man4/netlink.4 +++ b/share/man/man4/netlink.4 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 1, 2022 +.Dd November 30, 2022 .Dt NETLINK 4 .Os .Sh NAME @@ -212,11 +212,16 @@ If the socket option is not set, the remainder of the original message will follow. If the .Dv NETLINK_EXT_ACK -socket option is set, kernel may add a +socket option is set, the kernel may add a .Dv NLMSGERR_ATTR_MSG string TLV with the textual error description, optionally followed by the .Dv NLMSGERR_ATTR_OFFS TLV, indicating the offset from the message start that triggered an error. +If the operation reply is a multipart message, then no +.Dv NLMSG_ERROR +reply is generated, only a +.Dv NLMSG_DONE +message, closing multipart sequence. .Pp .Dv NLMSG_DONE indicates the end of the message group: typically, the end of the dump. diff --git a/sys/netlink/netlink_io.c b/sys/netlink/netlink_io.c index b2a0023a143b..fb8006f689e4 100644 --- a/sys/netlink/netlink_io.c +++ b/sys/netlink/netlink_io.c @@ -405,8 +405,9 @@ nl_receive_message(struct nlmsghdr *hdr, int remaining_length, nl_handler_f handler = nl_handlers[nlp->nl_proto].cb; int error = 0; - NL_LOG(LOG_DEBUG2, "msg len: %d type: %d", hdr->nlmsg_len, - hdr->nlmsg_type); + NLP_LOG(LOG_DEBUG2, nlp, "msg len: %u type: %d: flags: 0x%X seq: %u pid: %u", + hdr->nlmsg_len, hdr->nlmsg_type, hdr->nlmsg_flags, hdr->nlmsg_seq, + hdr->nlmsg_pid); if (__predict_false(hdr->nlmsg_len > remaining_length)) { NLP_LOG(LOG_DEBUG, nlp, "message is not entirely present: want %d got %d", @@ -439,9 +440,10 @@ nl_receive_message(struct nlmsghdr *hdr, int remaining_length, NL_LOG(LOG_DEBUG2, "retcode: %d", error); } if ((hdr->nlmsg_flags & NLM_F_ACK) || (error != 0 && error != EINTR)) { - NL_LOG(LOG_DEBUG3, "ack"); - nlmsg_ack(nlp, error, hdr, npt); - NL_LOG(LOG_DEBUG3, "done"); + if (!npt->nw->suppress_ack) { + NL_LOG(LOG_DEBUG3, "ack"); + nlmsg_ack(nlp, error, hdr, npt); + } } return (0); @@ -455,6 +457,7 @@ npt_clear(struct nl_pstate *npt) npt->err_msg = NULL; npt->err_off = 0; npt->hdr = NULL; + npt->nw->suppress_ack = false; } /* diff --git a/sys/netlink/netlink_message_writer.c b/sys/netlink/netlink_message_writer.c index 1856f2859b01..37414703c6f6 100644 --- a/sys/netlink/netlink_message_writer.c +++ b/sys/netlink/netlink_message_writer.c @@ -600,6 +600,9 @@ nlmsg_end(struct nl_writer *nw) } nw->hdr->nlmsg_len = (uint32_t)(nw->data + nw->offset - (char *)nw->hdr); + NL_LOG(LOG_DEBUG2, "wrote msg len: %u type: %d: flags: 0x%X seq: %u pid: %u", + nw->hdr->nlmsg_len, nw->hdr->nlmsg_type, nw->hdr->nlmsg_flags, + nw->hdr->nlmsg_seq, nw->hdr->nlmsg_pid); nw->hdr = NULL; nw->num_messages++; return (true); @@ -681,6 +684,7 @@ nlmsg_end_dump(struct nl_writer *nw, int error, struct nlmsghdr *hdr) nw->offset, perror); *perror = error; nlmsg_end(nw); + nw->suppress_ack = true; return (true); } diff --git a/sys/netlink/netlink_message_writer.h b/sys/netlink/netlink_message_writer.h index 424983282e59..99f50fb94213 100644 --- a/sys/netlink/netlink_message_writer.h +++ b/sys/netlink/netlink_message_writer.h @@ -55,6 +55,7 @@ struct nl_writer { uint8_t writer_target; /* NS_WRITER_TARGET_* */ bool ignore_limit; /* If true, ignores RCVBUF limit */ bool enomem; /* True if ENOMEM occured */ + bool suppress_ack; /* If true, don't send NLMSG_ERR */ }; #define NS_WRITER_TARGET_SOCKET 0 #define NS_WRITER_TARGET_GROUP 1