From nobody Fri Jun 17 19:41:16 2022 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 6445E85D9B7; Fri, 17 Jun 2022 19:41:18 +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 4LPqCx0SN3z3jD1; Fri, 17 Jun 2022 19:41:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494877; 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=K5wL3ygsFPFLyVIRLWPO0pRS9mkZsPjHJzDjrhy13rM=; b=H0anTT8rzwAItTa0XDZJwP4hygSXVaMbjOjpYynU7SREc+9Rq44L7eAy/CpbZszB1Nsq6N bT13f1e8Fa3e2WwpS+X/DRNe7z7VXMNmEFSN+q+7lGtKX9Iqqr0KsOIkw/hTIBSduvPbjz ZTgcSW9AbTZbYwca0SI084CmTRwFsBuWqzrrxlOWYIuzeyb9ghtVwxz+FsfxEe3w+UT/ie fSWjnBJOV2IOBO8MHrModj7Pz21WGEiyIU2rKtl+EoXpoiORlEVhvxitqlrLlD2y9GFCVG r6EQEhi5bcEBJr+IKQDHdoD8ZBksYHjmfXCzGs+J9/5paIdGBtiBQLaJUD+qIg== 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 BA515257FB; Fri, 17 Jun 2022 19:41:16 +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 25HJfG0K030263; Fri, 17 Jun 2022 19:41:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJfGLs030262; Fri, 17 Jun 2022 19:41:16 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:41:16 GMT Message-Id: <202206171941.25HJfGLs030262@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: fc9014c1954c - stable/13 - linux(4): Refactor linux_common_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: fc9014c1954cebf17c8e317c67dc5b54722edbe1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494877; 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=K5wL3ygsFPFLyVIRLWPO0pRS9mkZsPjHJzDjrhy13rM=; b=VafjRX/buCuPr05hpYN9kaZiNUDc+o0jfhfmNgt2rfbFnrDf5HwAfffV3ebo0MwoFcNduN XiPOfQfbzqpOa4Mnt6RTS2NXMJHWQCEQWNnTupEJSI5sooCQZ/txo0Gwy1vMPWKw6qmBFW eQYYcJYhX0RIXubl7JqA7mP5+Gttny9bGw9xsBd8X2KkUNrbV9sXyldHlHUR26+nlT8GfD JWHwTuft9pNzad4EeE54ud+tOoxVpW2IgYJfEhqZKCf9bqLBGSCn7rI3+dqY4WNIjzWCia x9KycWGTGl61kO0ZfdbzfIP5kwt9pYdDK6omHTa/iWMmw63uGhuNs1MEXmAsuA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494877; a=rsa-sha256; cv=none; b=LZ8SKC5+fWQyICmUhJuPC2NT64i6DThwGrEdyN5VrSQUX+xNL1yQG/IwCMotQ9rOwUcZVe ljHU8SmhmvQlamK3luHr2FaVcFNrMt7upmLpCNBaG6BKX5WG6WIS0M/KGslQ2it1348qWv GOjrjjdRIiX2iJKueubNWLg9CRl606zrRNrwYmC/Y5Yu6SlKa0ib2T2mMC981g2Z3kstuJ IK7QRWT8XQM6q5pCzwMkzCeSDwV5AGkQRIFFENm6TC02pdWyopHVK4cyPav7gH+lHg/s9r xrMx3O9gMpp0BdbzmgraX5zeBGp9uF5tSwRJ8uSWLKxmqxG1BCTClRlRL5FphA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=fc9014c1954cebf17c8e317c67dc5b54722edbe1 commit fc9014c1954cebf17c8e317c67dc5b54722edbe1 Author: Dmitry Chagin AuthorDate: 2022-05-28 20:46:22 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:35:35 +0000 linux(4): Refactor linux_common_recvmsg() To improve readability lower nesting level, better naming for variables. No functional changes. MFC after: 2 weeks (cherry picked from commit 0eda2ceab7820aeba79029b59b3fe9b28a66c766) --- sys/compat/linux/linux_socket.c | 168 +++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 88 deletions(-) diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 14f034eb8037..401e1bc5c88f 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -1691,9 +1691,9 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, { struct proc *p = td->td_proc; struct cmsghdr *cm; - struct l_cmsghdr *linux_cmsg = NULL; + struct l_cmsghdr *lcm = NULL; socklen_t datalen, maxlen, outlen; - struct l_msghdr linux_msghdr; + struct l_msghdr l_msghdr; struct iovec *iov, *uiov; struct mbuf *control = NULL; struct mbuf **controlp; @@ -1702,7 +1702,7 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, void *data, *udata; int error; - error = copyin(msghdr, &linux_msghdr, sizeof(linux_msghdr)); + error = copyin(msghdr, &l_msghdr, sizeof(l_msghdr)); if (error != 0) return (error); @@ -1710,9 +1710,9 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, * Pass user-supplied recvmsg() flags in msg_flags field, * following sys_recvmsg() convention. */ - linux_msghdr.msg_flags = flags; + l_msghdr.msg_flags = flags; - error = linux_to_bsd_msghdr(msg, &linux_msghdr); + error = linux_to_bsd_msghdr(msg, &l_msghdr); if (error != 0) return (error); @@ -1746,111 +1746,103 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, * Note that kern_recvit() updates msg->msg_namelen. */ if (msg->msg_name != NULL && msg->msg_namelen > 0) { - msg->msg_name = PTRIN(linux_msghdr.msg_name); + msg->msg_name = PTRIN(l_msghdr.msg_name); error = linux_copyout_sockaddr(sa, msg->msg_name, msg->msg_namelen); if (error != 0) goto bad; } - error = bsd_to_linux_msghdr(msg, &linux_msghdr); + error = bsd_to_linux_msghdr(msg, &l_msghdr); if (error != 0) goto bad; - maxlen = linux_msghdr.msg_controllen; - linux_msghdr.msg_controllen = 0; - if (control) { - linux_cmsg = malloc(L_CMSG_HDRSZ, M_LINUX, M_WAITOK | M_ZERO); - - msg->msg_control = mtod(control, struct cmsghdr *); - msg->msg_controllen = control->m_len; - - cm = CMSG_FIRSTHDR(msg); - outbuf = PTRIN(linux_msghdr.msg_control); - outlen = 0; - while (cm != NULL) { - linux_cmsg->cmsg_type = - bsd_to_linux_cmsg_type(p, cm->cmsg_type); - linux_cmsg->cmsg_level = - bsd_to_linux_sockopt_level(cm->cmsg_level); - if (linux_cmsg->cmsg_type == -1 || - cm->cmsg_level != SOL_SOCKET) { - linux_msg(curthread, - "unsupported recvmsg cmsg level %d type %d", - cm->cmsg_level, cm->cmsg_type); - error = EINVAL; - goto bad; - } - - data = CMSG_DATA(cm); - datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data; - udata = NULL; - - switch (cm->cmsg_type) { - case SCM_RIGHTS: - error = recvmsg_scm_rights(td, flags, - &datalen, &data, &udata); - break; + maxlen = l_msghdr.msg_controllen; + l_msghdr.msg_controllen = 0; + if (control == NULL) + goto out; - case SCM_CREDS: - error = recvmsg_scm_creds(&datalen, - &data, &udata); - break; + lcm = malloc(L_CMSG_HDRSZ, M_LINUX, M_WAITOK | M_ZERO); + msg->msg_control = mtod(control, struct cmsghdr *); + msg->msg_controllen = control->m_len; + cm = CMSG_FIRSTHDR(msg); + outbuf = PTRIN(l_msghdr.msg_control); + outlen = 0; + while (cm != NULL) { + lcm->cmsg_type = bsd_to_linux_cmsg_type(p, cm->cmsg_type); + lcm->cmsg_level = bsd_to_linux_sockopt_level(cm->cmsg_level); + if (lcm->cmsg_type == -1 || + cm->cmsg_level != SOL_SOCKET) { + linux_msg(curthread, + "unsupported recvmsg cmsg level %d type %d", + cm->cmsg_level, cm->cmsg_type); + error = EINVAL; + goto bad; + } - case SCM_CREDS2: - error = recvmsg_scm_creds2(&datalen, - &data, &udata); - break; + data = CMSG_DATA(cm); + datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data; + udata = NULL; - case SCM_TIMESTAMP: + 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(linux_cmsg->cmsg_type, - &datalen, &data, &udata); + error = recvmsg_scm_timestamp(lcm->cmsg_type, + &datalen, &data, &udata); #endif - break; - - case SCM_BINTIME: - error = recvmsg_scm_timestampns(linux_cmsg->cmsg_type, - &datalen, &data, &udata); - break; - } - if (error != 0) - goto bad; + break; + case SCM_BINTIME: + error = recvmsg_scm_timestampns(lcm->cmsg_type, + &datalen, &data, &udata); + break; + } + if (error != 0) + goto bad; - if (outlen + LINUX_CMSG_LEN(datalen) > maxlen) { - if (outlen == 0) { - error = EMSGSIZE; - goto err; - } else { - linux_msghdr.msg_flags |= LINUX_MSG_CTRUNC; - m_dispose_extcontrolm(control); - free(udata, M_LINUX); - goto out; - } + if (outlen + LINUX_CMSG_LEN(datalen) > maxlen) { + if (outlen == 0) { + error = EMSGSIZE; + goto err; + } else { + l_msghdr.msg_flags |= LINUX_MSG_CTRUNC; + m_dispose_extcontrolm(control); + free(udata, M_LINUX); + goto out; } + } - linux_cmsg->cmsg_len = LINUX_CMSG_LEN(datalen); - - error = copyout(linux_cmsg, outbuf, L_CMSG_HDRSZ); + lcm->cmsg_len = LINUX_CMSG_LEN(datalen); + error = copyout(lcm, outbuf, L_CMSG_HDRSZ); + if (error == 0) { + outbuf += L_CMSG_HDRSZ; + error = copyout(data, outbuf, datalen); if (error == 0) { - outbuf += L_CMSG_HDRSZ; - error = copyout(data, outbuf, datalen); - if (error == 0) { - outbuf += LINUX_CMSG_ALIGN(datalen); - outlen += LINUX_CMSG_LEN(datalen); - cm = CMSG_NXTHDR(msg, cm); - } + outbuf += LINUX_CMSG_ALIGN(datalen); + outlen += LINUX_CMSG_LEN(datalen); + cm = CMSG_NXTHDR(msg, cm); } -err: - free(udata, M_LINUX); - if (error != 0) - goto bad; } - linux_msghdr.msg_controllen = outlen; +err: + free(udata, M_LINUX); + if (error != 0) + goto bad; } + l_msghdr.msg_controllen = outlen; out: - error = copyout(&linux_msghdr, msghdr, sizeof(linux_msghdr)); + error = copyout(&l_msghdr, msghdr, sizeof(l_msghdr)); bad: if (control != NULL) { @@ -1859,7 +1851,7 @@ bad: m_freem(control); } free(iov, M_IOV); - free(linux_cmsg, M_LINUX); + free(lcm, M_LINUX); free(sa, M_SONAME); return (error);