From nobody Fri Jun 17 19:41:15 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 E468F85DB03; Fri, 17 Jun 2022 19:41:16 +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 4LPqCw2TCxz3jFS; 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=1655494876; 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=84dbrhuVZQxzcKATFIZAu8w8C4Lnogwuj7AGF4Sa45U=; b=B/dkPJxc2iSE97HzT4H3LmYtsfmFHQsD1Dx2Nga+y83rAmyYPPefoBOhqPFQgzA3WUgeYF Q1S36cO4YfzaEGiJlx8dSf2OivjzN0y0J1PgRtnBJWeVj9MDPTn6Z8Bb1Np497OjK9S/Z2 ipwU3XCgEiF/2XqpN87wKrviVc/OlymGuyP233tJ5jyLqLwsySMz6b6wSJl8KhyWXxkOl+ cdWftQMpvfQFz2n2HllfyTYGXX9NqS2YSi+c8ZWyW52cEivMIvIYoapoWpODjtaob8X/io i3M0S5BuaiRQMQOTcP4ace9pvLqYfs6vipbZQpvNUKoAxMh5OpanVpE6EFK0xg== 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 A61B525AFC; Fri, 17 Jun 2022 19:41:15 +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 25HJfFd7030233; Fri, 17 Jun 2022 19:41:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJfFD6030232; Fri, 17 Jun 2022 19:41:15 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:41:15 GMT Message-Id: <202206171941.25HJfFD6030232@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: 01a6eb8a64ec - stable/13 - linux(4): Handle SO_TIMESTAMPNS socket option 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: 01a6eb8a64eccd07f26182486f187977c632ed24 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494876; 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=84dbrhuVZQxzcKATFIZAu8w8C4Lnogwuj7AGF4Sa45U=; b=g3++VzcxyeGb+l9mm6/RkJC5OsHNdynPo3s6f182uxMHM912ZQ30W89UWUMLKeVixFl6rI tD37WuNXeA1NRdK5+iwEjKIuQI+F+O1gThwMnGgA9cBgkhs8gG+1lkumtY8x5G7OH3h57W xPOLBcgmenbUo/hJ4IsI4UrUZzx5b2qzIUanI3Y/CnfVFKcvldkTGOm60er/07nQzJ/6kU w+bkewYEdaYNnhJADNIRI9g+fASns+EopcjlTpsIzniCw/pahFXJDhK8ZT8BlAhBR+bE+5 tO6PnhbdJ8ouNOfutQOyrLQPREQ7Wn8S5I2/0V/ZZ5WskwbQfErOz4lDpJV4+A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494876; a=rsa-sha256; cv=none; b=HFkZut8KUlYZQOp0rWdQXJVrU+XB3tUIP2n/o9B7H+ne9jeE5guVLfx1QEqOGNqEd76Yro +OEUkoi7lZYOVqYze+uPc1MORcHTsQoWLjJNkxJpfibtw6hHPEPtw5dlJZlnTMibfHxDCw XVT4rlCes1WNKxsVx4Kj5Y/zwYJjbATTP9bwqTrbfZFluZ4b2q++HVU0a8+duXJ5yAAEi4 4iH7LsQSn53IraLvSgR041FNog7FOEuH+1IU+J9Lw9BFs1Te7QMEew4kwGLNE4QLwEa6bY lxnO6JVXbRk2DAeySyoZu2u29sNmXwyKwxgKWpuMH86+Iw8zRpKasJXGO0Jp8Q== 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=01a6eb8a64eccd07f26182486f187977c632ed24 commit 01a6eb8a64eccd07f26182486f187977c632ed24 Author: Dmitry Chagin AuthorDate: 2022-05-28 20:46:05 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:35:35 +0000 linux(4): Handle SO_TIMESTAMPNS socket option The SO_TIMESTAMPNS enables or disables the receiving of the SCM_TIMESTAMPNS control message. The cmsg_data field is a struct timespec. To distinguish between SO_TIMESTAMP and SO_TIMESTAMPNS in the recvmsg() map the last one to the SO_BINTIME and convert bintime to the timespec. In the rest, implementation is identical to the SO_TIMESTAMP. MFC after: 2 weeks (cherry picked from commit 71bc8bcf660b437b99af1e3d382f7bfdaea5fa9c) --- sys/compat/linux/linux_emul.h | 1 + sys/compat/linux/linux_socket.c | 62 +++++++++++++++++++++++++++++++++++++++++ sys/compat/linux/linux_socket.h | 4 +++ 3 files changed, 67 insertions(+) diff --git a/sys/compat/linux/linux_emul.h b/sys/compat/linux/linux_emul.h index e801bf09ba72..9b552ab9c720 100644 --- a/sys/compat/linux/linux_emul.h +++ b/sys/compat/linux/linux_emul.h @@ -77,6 +77,7 @@ struct linux_pemuldata { uint32_t ptrace_flags; /* used by ptrace(2) */ uint32_t oom_score_adj; /* /proc/self/oom_score_adj */ uint32_t so_timestamp; /* requested timeval */ + uint32_t so_timestampns; /* requested timespec */ }; #define LINUX_PEM_XLOCK(p) sx_xlock(&(p)->pem_sx) diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 3360cf48cb16..14f034eb8037 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -551,6 +551,9 @@ linux_to_bsd_so_sockopt(int opt) case LINUX_SO_TIMESTAMPO: case LINUX_SO_TIMESTAMPN: return (SO_TIMESTAMP); + case LINUX_SO_TIMESTAMPNSO: + case LINUX_SO_TIMESTAMPNSN: + return (SO_BINTIME); case LINUX_SO_ACCEPTCONN: return (SO_ACCEPTCONN); case LINUX_SO_PROTOCOL: @@ -661,6 +664,8 @@ bsd_to_linux_cmsg_type(struct proc *p, int cmsg_type) return (LINUX_SCM_CREDENTIALS); case SCM_TIMESTAMP: return (pem->so_timestamp); + case SCM_BINTIME: + return (pem->so_timestampns); } return (-1); } @@ -1554,6 +1559,7 @@ recvmsg_scm_rights(struct thread *td, l_uint flags, socklen_t *datalen, return (0); } + static int recvmsg_scm_creds(socklen_t *datalen, void **data, void **udata) { @@ -1632,6 +1638,53 @@ _Static_assert(sizeof(struct timeval) == sizeof(l_timeval), "scm_timestamp sizeof l_timeval"); #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ +#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) +static int +recvmsg_scm_timestampns(l_int msg_type, socklen_t *datalen, void **data, + void **udata) +{ + struct l_timespec64 ts64; + struct l_timespec ts32; + struct timespec ts; + socklen_t len; + void *buf; + + if (msg_type == LINUX_SCM_TIMESTAMPNSO) + len = sizeof(ts32); + else + len = sizeof(ts64); + + buf = malloc(len, M_LINUX, M_WAITOK); + bintime2timespec(*data, &ts); + if (msg_type == LINUX_SCM_TIMESTAMPNSO) { + ts32.tv_sec = ts.tv_sec; + ts32.tv_nsec = ts.tv_nsec; + memmove(buf, &ts32, len); + } else { + ts64.tv_sec = ts.tv_sec; + ts64.tv_nsec = ts.tv_nsec; + memmove(buf, &ts64, len); + } + *data = *udata = buf; + *datalen = len; + return (0); +} +#else +static int +recvmsg_scm_timestampns(l_int msg_type, socklen_t *datalen, void **data, + void **udata) +{ + struct timespec ts; + + bintime2timespec(*data, &ts); + memmove(*data, &ts, sizeof(struct timespec)); + *datalen = sizeof(struct timespec); + return (0); +} +_Static_assert(sizeof(struct bintime) >= sizeof(struct timespec), + "scm_timestampns sizeof timespec"); +#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ + static int linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, l_uint flags, struct msghdr *msg) @@ -1755,6 +1808,11 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, &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; @@ -1960,6 +2018,10 @@ linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args) pem = pem_find(p); pem->so_timestamp = args->optname; break; + case SO_BINTIME: + pem = pem_find(p); + pem->so_timestampns = args->optname; + break; default: break; } diff --git a/sys/compat/linux/linux_socket.h b/sys/compat/linux/linux_socket.h index 77537afad6ee..ef0c1f24f10a 100644 --- a/sys/compat/linux/linux_socket.h +++ b/sys/compat/linux/linux_socket.h @@ -189,6 +189,8 @@ int linux_accept(struct thread *td, struct linux_accept_args *args); #endif #define LINUX_SO_TIMESTAMPO 29 #define LINUX_SO_TIMESTAMPN 63 +#define LINUX_SO_TIMESTAMPNSO 35 +#define LINUX_SO_TIMESTAMPNSN 64 #define LINUX_SO_ACCEPTCONN 30 #define LINUX_SO_PEERSEC 31 #define LINUX_SO_SNDBUFFORCE 32 @@ -203,6 +205,8 @@ int linux_accept(struct thread *td, struct linux_accept_args *args); #define LINUX_SCM_CREDENTIALS 0x02 #define LINUX_SCM_TIMESTAMPO LINUX_SO_TIMESTAMPO #define LINUX_SCM_TIMESTAMPN LINUX_SO_TIMESTAMPN +#define LINUX_SCM_TIMESTAMPNSO LINUX_SO_TIMESTAMPNSO +#define LINUX_SCM_TIMESTAMPNSN LINUX_SO_TIMESTAMPNSN /* Socket options */ #define LINUX_IP_TOS 1