From nobody Mon Aug 21 11:41:18 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 4RTrCg0Lh3z4qfj5; Mon, 21 Aug 2023 11:41:19 +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 4RTrCf6TjXz4VtV; Mon, 21 Aug 2023 11:41:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692618078; 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=V9UcwggBAicFRTqTSholvwz9W8IfzJD2MIhPD8+D5wM=; b=W6WR5yl7HLs7/ZaaM0XZn0Yhien3gR1cq3F0XnNGIxfDkUQiNYTKlzt1NEXVKjcyhQLgzA DwgzYu8hfJJvpTVNd7LIIlhE8vGE96upHQgaMMCb6MuXdgeEwb8dxZxi9DEk7acUVSSLed PmtOavBAWxS8D8sScFKzmxg3kDg1XU5El+0bfvuRGXfVjcBMMlmQdKlR0qfDBmfgI6P67w o8futDBvaRYL7MeJMAk2ZPjxlkNX/aTexncdCB1h8BNAP62CEm+M7wphAtRMzqiJzagtU/ MWal+/tTs1YPkkkOzGBcbWHVpbcLSby83Kgng0fTikXU4CKL2hdO2P+RNtE3aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692618078; 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=V9UcwggBAicFRTqTSholvwz9W8IfzJD2MIhPD8+D5wM=; b=cYSy2pWMdBlbjbEpB5wBpF6pP1Plj7r8w4xzkNUFy7PAgmecq6hKnVkfYQk8YjprVVo0ta j7EXw6bSKDTi0pvaZt5pUnpdMi+D3XfqHXY77bfYJmzTHAdjsWcSxJ1vaaQaYly+hd8Ij6 fNWh0ahM3iU7ss1p1J28B8NnG03hmoFqN7cQMiekVBs3rgGAz4O5PJmOeQDROKH5urA9eN vHbiBrZoi6o2qr+rg/vZIfq7CemNknGwZF6gQuhubShr5dA41PRDfDkybzU0KCy8uqVEav BSzEFlmpsKOHN8YWvObhIiH8gf0Fb5lzRx6BB6mMgpajDJij0GYiTSJKGvz+0Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692618078; a=rsa-sha256; cv=none; b=AAn4uiEBGKCNFWQKT080B+ZFwcp4wPPB83wzg/nAG3WGHiWkCuDnrsdO7l3zngUEaSRma3 F2s7BqunnBEIbclgmv9VRsIzxVx+9yv6l5tA19GQPprDWZrbfQWwQR+k0YvzE0XlmIg0kU KA5fp6xavVtaF2wymyGH1Wn9FG/JzbF13pXwvg9DJt95xzuR8diVjDBcg6ao/aQTp7Ejf1 PJUIPM7yGfspX0HC4pngAe9F2gTi5rHh/p9QLPQ8d0qlFLLob0ffQ1gBqwiRGjBCK08VPF rU7KtqYdnzQUBTWOqbRQVQD5dDkbK5SzKKLZcyQrt051maT9HFSWXNv7nRzzOQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RTrCf5bB1z3rp; Mon, 21 Aug 2023 11:41:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37LBfIAG045815; Mon, 21 Aug 2023 11:41:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37LBfI6S045813; Mon, 21 Aug 2023 11:41:18 GMT (envelope-from git) Date: Mon, 21 Aug 2023 11:41:18 GMT Message-Id: <202308211141.37LBfI6S045813@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: b67a012e7ca3 - stable/13 - linux(4): Refactor recvmsg 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b67a012e7ca3a88716cac0182bfe2ab556835773 Auto-Submitted: auto-generated The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=b67a012e7ca3a88716cac0182bfe2ab556835773 commit b67a012e7ca3a88716cac0182bfe2ab556835773 Author: Dmitry Chagin AuthorDate: 2023-08-14 12:46:12 +0000 Commit: Dmitry Chagin CommitDate: 2023-08-21 10:39:04 +0000 linux(4): Refactor recvmsg As the amount of handled anxiliary messages grows move they handlers into a separate functions. MFC after: 1 week (cherry picked from commit de20eb26d014f7d9ba81fd1f84636609c8efa8e1) --- sys/compat/linux/linux_socket.c | 101 +++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 37 deletions(-) diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 7bcefcd2d81b..5db366b58401 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -1694,6 +1694,39 @@ _Static_assert(sizeof(struct bintime) >= sizeof(struct timespec), "scm_timestampns sizeof timespec"); #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ +static int +recvmsg_scm_sol_socket(struct thread *td, l_int msg_type, l_int lmsg_type, + l_uint flags, socklen_t *datalen, void **data, void **udata) +{ + int error; + + error = 0; + switch (msg_type) { + case SCM_RIGHTS: + error = recvmsg_scm_rights(td, flags, datalen, + data, udata); + break; + case SCM_CREDS: + error = recvmsg_scm_creds(datalen, data, udata); + break; + case SCM_CREDS2: + error = recvmsg_scm_creds2(datalen, data, udata); + break; + case SCM_TIMESTAMP: +#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) + error = recvmsg_scm_timestamp(lmsg_type, datalen, + data, udata); +#endif + break; + case SCM_BINTIME: + error = recvmsg_scm_timestampns(lmsg_type, datalen, + data, udata); + break; + } + + return (error); +} + static int recvmsg_scm_ip_origdstaddr(socklen_t *datalen, void **data, void **udata) { @@ -1708,6 +1741,23 @@ recvmsg_scm_ip_origdstaddr(socklen_t *datalen, void **data, void **udata) return (error); } +static int +recvmsg_scm_ipproto_ip(l_int msg_type, l_int lmsg_type, socklen_t *datalen, + void **data, void **udata) +{ + int error; + + error = 0; + switch (msg_type) { + case IP_ORIGDSTADDR: + error = recvmsg_scm_ip_origdstaddr(datalen, data, + udata); + break; + } + + return (error); +} + static int linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, l_uint flags, struct msghdr *msg) @@ -1796,18 +1846,6 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, cm->cmsg_level); lcm->cmsg_level = bsd_to_linux_sockopt_level(cm->cmsg_level); - data = CMSG_DATA(cm); - datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data; - udata = NULL; - error = 0; - - /* Process non SOL_SOCKET types. */ - if (cm->cmsg_level == IPPROTO_IP && - lcm->cmsg_type == LINUX_IP_ORIGDSTADDR) { - error = recvmsg_scm_ip_origdstaddr(&datalen, &data, &udata); - goto cont; - } - if (lcm->cmsg_type == -1 || cm->cmsg_level == -1) { LINUX_RATELIMIT_MSG_OPT2( @@ -1817,33 +1855,22 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, skiped++; continue; } + data = CMSG_DATA(cm); + datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data; + udata = NULL; + error = 0; - switch (cm->cmsg_type) { - case SCM_RIGHTS: - error = recvmsg_scm_rights(td, flags, - &datalen, &data, &udata); - break; - case SCM_CREDS: - error = recvmsg_scm_creds(&datalen, - &data, &udata); - break; - case SCM_CREDS2: - error = recvmsg_scm_creds2(&datalen, - &data, &udata); - break; - case SCM_TIMESTAMP: -#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) - error = recvmsg_scm_timestamp(lcm->cmsg_type, - &datalen, &data, &udata); -#endif - break; - case SCM_BINTIME: - error = recvmsg_scm_timestampns(lcm->cmsg_type, - &datalen, &data, &udata); - break; - } + switch (cm->cmsg_level) { + case IPPROTO_IP: + error = recvmsg_scm_ipproto_ip(cm->cmsg_type, + lcm->cmsg_type, &datalen, &data, &udata); + break; + case SOL_SOCKET: + error = recvmsg_scm_sol_socket(td, cm->cmsg_type, + lcm->cmsg_type, flags, &datalen, &data, &udata); + break; + } -cont: if (error != 0) goto bad;