From nobody Sat May 28 20:53:29 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 25F451B50A42; Sat, 28 May 2022 20:53:31 +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 4L9YmV3SR5z4lLj; Sat, 28 May 2022 20:53:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653771210; 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=Bqey3e1iPqp9ys8PW0VEmvGXzVHd9G1tQQSqX2P4KNM=; b=FJmM5s0TmlyitZiiAMATmTaOHgEZsgEyCag69AvLjLCc2ZRhNpPyp/aoifwWI4ExfBq1gE T8c6xgFH2mTbvqFDpxMdxmAxDlWmtYbAIGJ2a+P8ONvNS+tudrCNoq5NeWzN9Ix6PwxRya Jik1BZRjnzi9G9tNNcTp26JeN7gooXetFC73f6ky+xAVpd57zvh99OmqCEa7PBERPTPv7U tCwq4zhweJ9tTtU7uN9bDQgF95CcyZEZCSydahkQInFnO96CiMdWMkqvUCvLq+DfLLLLJQ bkDWDyvejws8X5+2uLg28BGu1yFxaAV06AxvuFdJNPiRWGZUeT4PlrEW3ishXg== 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 CC86316041; Sat, 28 May 2022 20:53:29 +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 24SKrT8F099535; Sat, 28 May 2022 20:53:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24SKrTQ8099534; Sat, 28 May 2022 20:53:29 GMT (envelope-from git) Date: Sat, 28 May 2022 20:53:29 GMT Message-Id: <202205282053.24SKrTQ8099534@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: f8a6615064ba - main - linux(4): Handle IP_ORIGDSTADDR socket option for IPPROTO_IP protocol level 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/main X-Git-Reftype: branch X-Git-Commit: f8a6615064badb76b6cb301163697cf99ac4f180 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653771210; 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=Bqey3e1iPqp9ys8PW0VEmvGXzVHd9G1tQQSqX2P4KNM=; b=JcobF7Pz9/r7SG1+J8mIOnvrjAZKQYZYpr9srz96ensWTcZw7WJVYI407yIevNXS8/JSbs F6d1l/z1/Rw6xi7SxhmISlK9c8c966WS7COQSOhHDD+EC739IZJgOpb7Yb4Sd3wKivYIeX NK0fDkLQswfz1LcAJO5j6Lqd660pQ1QLLwNj1HXcTqlcoaJXMyKGdIzimjW0pT8cAmThTP 1YY0xrI+fzhFyRqGskllfgzqSHCq6YEMEz8kI/DkhQPQ/lpDEOo2ml0GBfdwGDtD+Yckrr 9Tdj66dJAMmoQ47OVMlxgPTxL+UkcgBekyPjD92T5W2zPznMWaxXXgtgrVnjQQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653771210; a=rsa-sha256; cv=none; b=nryvhkdn12pkMS0/w+8hkS8tOOOTPYziaWGwKUWlbw89kaXAfkoFothgnSqJ1QUiskBnPU eMA09nOxi84avlksIKb3mIaGT69Qp9gX4lLjWJVpgperVM+qYnBr8cVn+uJctU8JBTIZnR XyAnK2UoQmtGA2AZs9s6KVSEGKPu4E/0FtOjabaCj+MrpnCqqfGpEOIq03fSYjx2zE5Ut3 3FShVtPRpvIUH7BtzsNw4viR8qDREtj4wzDK4MmjamtgqL1qKDScraCs+PqsOjN9TyM3AK Oh8kXX+oEjGGPJJZ0Dnk8cw3Vyvw2b7x1AyECzjAzo/bwhHXtz/ZzPy1MXAprA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=f8a6615064badb76b6cb301163697cf99ac4f180 commit f8a6615064badb76b6cb301163697cf99ac4f180 Author: Dmitry Chagin AuthorDate: 2022-05-28 20:47:40 +0000 Commit: Dmitry Chagin CommitDate: 2022-05-28 20:47:40 +0000 linux(4): Handle IP_ORIGDSTADDR socket option for IPPROTO_IP protocol level MFC after: 2 weeks --- sys/compat/linux/linux_socket.c | 55 +++++++++++++++++++++++++++++++++++++---- sys/compat/linux/linux_socket.h | 2 ++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 3fea532d676d..b71dee847cf8 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -180,6 +180,8 @@ linux_to_bsd_ip_sockopt(int opt) case LINUX_MCAST_LEAVE_SOURCE_GROUP: LINUX_RATELIMIT_MSG_NOTTESTED("IPv4 socket option IP_MCAST_LEAVE_SOURCE_GROUP"); return (MCAST_LEAVE_SOURCE_GROUP); + case LINUX_IP_RECVORIGDSTADDR: + return (IP_RECVORIGDSTADDR); /* known but not implemented sockopts */ case LINUX_IP_ROUTER_ALERT: @@ -649,10 +651,26 @@ linux_to_bsd_cmsg_type(int cmsg_type) } static int -bsd_to_linux_cmsg_type(struct proc *p, int cmsg_type) +bsd_to_linux_ip_cmsg_type(int cmsg_type) +{ + + switch (cmsg_type) { + case IP_RECVORIGDSTADDR: + return (LINUX_IP_RECVORIGDSTADDR); + } + return (-1); +} + +static int +bsd_to_linux_cmsg_type(struct proc *p, int cmsg_type, int cmsg_level) { struct linux_pemuldata *pem; + if (cmsg_level == IPPROTO_IP) + return (bsd_to_linux_ip_cmsg_type(cmsg_type)); + if (cmsg_level != SOL_SOCKET) + return (-1); + pem = pem_find(p); switch (cmsg_type) { @@ -1685,6 +1703,20 @@ _Static_assert(sizeof(struct bintime) >= sizeof(struct timespec), "scm_timestampns sizeof timespec"); #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ +static int +recvmsg_scm_ip_origdstaddr(socklen_t *datalen, void **data, void **udata) +{ + struct l_sockaddr *lsa; + int error; + + error = bsd_to_linux_sockaddr(*data, &lsa, *datalen); + if (error == 0) { + *data = *udata = lsa; + *datalen = sizeof(*lsa); + } + return (error); +} + static int linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, l_uint flags, struct msghdr *msg) @@ -1769,8 +1801,22 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, 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_type = bsd_to_linux_cmsg_type(p, cm->cmsg_type, + 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 != SOL_SOCKET) { linux_msg(curthread, @@ -1780,9 +1826,6 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, 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: @@ -1808,6 +1851,8 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr, &datalen, &data, &udata); break; } + +cont: if (error != 0) goto bad; diff --git a/sys/compat/linux/linux_socket.h b/sys/compat/linux/linux_socket.h index ef0c1f24f10a..74b96fbb9c11 100644 --- a/sys/compat/linux/linux_socket.h +++ b/sys/compat/linux/linux_socket.h @@ -229,6 +229,8 @@ int linux_accept(struct thread *td, struct linux_accept_args *args); #define LINUX_IP_PASSSEC 18 #define LINUX_IP_TRANSPARENT 19 +#define LINUX_IP_ORIGDSTADDR 20 +#define LINUX_IP_RECVORIGDSTADDR LINUX_IP_ORIGDSTADDR #define LINUX_IP_MINTTL 21 #define LINUX_IP_NODEFRAG 22 #define LINUX_IP_CHECKSUM 23