From patchwork Fri Jun 30 13:23:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9819625 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 309D8603F2 for ; Fri, 30 Jun 2017 13:24:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21E111FF21 for ; Fri, 30 Jun 2017 13:24:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 169D728657; Fri, 30 Jun 2017 13:24:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AED581FF21 for ; Fri, 30 Jun 2017 13:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751905AbdF3NY1 (ORCPT ); Fri, 30 Jun 2017 09:24:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61654 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751936AbdF3NY1 (ORCPT ); Fri, 30 Jun 2017 09:24:27 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 117B083F3D; Fri, 30 Jun 2017 13:24:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 117B083F3D Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=stefanha@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 117B083F3D Received: from localhost (ovpn-116-222.ams2.redhat.com [10.36.116.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93622177DA; Fri, 30 Jun 2017 13:24:26 +0000 (UTC) From: Stefan Hajnoczi To: linux-nfs@vger.kernel.org Cc: Abbas Naderi , Anna Schumaker , Trond Myklebust , "J. Bruce Fields" , Jeff Layton , Chuck Lever , Stefan Hajnoczi Subject: [PATCH v3 08/14] SUNRPC: add AF_VSOCK support to svc_xprt.c Date: Fri, 30 Jun 2017 14:23:46 +0100 Message-Id: <20170630132352.32133-9-stefanha@redhat.com> In-Reply-To: <20170630132352.32133-1-stefanha@redhat.com> References: <20170630132352.32133-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 30 Jun 2017 13:24:27 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow creation of AF_VSOCK service xprts. This is needed for the "vsock-bc" backchannel. Signed-off-by: Stefan Hajnoczi --- include/linux/sunrpc/svc_xprt.h | 12 ++++++++++++ net/sunrpc/svc_xprt.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/svc_xprt.h index ddb7f94..938f9ee 100644 --- a/include/linux/sunrpc/svc_xprt.h +++ b/include/linux/sunrpc/svc_xprt.h @@ -8,6 +8,7 @@ #define SUNRPC_SVC_XPRT_H #include +#include struct module; @@ -156,12 +157,15 @@ static inline unsigned short svc_addr_port(const struct sockaddr *sa) { const struct sockaddr_in *sin = (const struct sockaddr_in *)sa; const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa; + const struct sockaddr_vm *svm = (const struct sockaddr_vm *)sa; switch (sa->sa_family) { case AF_INET: return ntohs(sin->sin_port); case AF_INET6: return ntohs(sin6->sin6_port); + case AF_VSOCK: + return svm->svm_port; } return 0; @@ -174,6 +178,8 @@ static inline size_t svc_addr_len(const struct sockaddr *sa) return sizeof(struct sockaddr_in); case AF_INET6: return sizeof(struct sockaddr_in6); + case AF_VSOCK: + return sizeof(struct sockaddr_vm); } BUG(); } @@ -193,6 +199,7 @@ static inline char *__svc_print_addr(const struct sockaddr *addr, { const struct sockaddr_in *sin = (const struct sockaddr_in *)addr; const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)addr; + const struct sockaddr_vm *svm = (const struct sockaddr_vm *)addr; switch (addr->sa_family) { case AF_INET: @@ -206,6 +213,11 @@ static inline char *__svc_print_addr(const struct sockaddr *addr, ntohs(sin6->sin6_port)); break; + case AF_VSOCK: + snprintf(buf, len, "%u, port=%u", + svm->svm_cid, svm->svm_port); + break; + default: snprintf(buf, len, "unknown address type: %d", addr->sa_family); break; diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c index 7bfe1fb..2a8ccc1 100644 --- a/net/sunrpc/svc_xprt.c +++ b/net/sunrpc/svc_xprt.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -195,6 +196,13 @@ static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl, .sin6_port = htons(port), }; #endif +#ifdef CONFIG_SUNRPC_XPRT_VSOCK + struct sockaddr_vm svm = { + .svm_family = AF_VSOCK, + .svm_cid = VMADDR_CID_ANY, + .svm_port = port, + }; +#endif struct sockaddr *sap; size_t len; @@ -209,6 +217,12 @@ static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl, len = sizeof(sin6); break; #endif +#ifdef CONFIG_SUNRPC_XPRT_VSOCK + case AF_VSOCK: + sap = (struct sockaddr *)&svm; + len = sizeof(svm); + break; +#endif default: return ERR_PTR(-EAFNOSUPPORT); } @@ -595,6 +609,10 @@ int svc_port_is_privileged(struct sockaddr *sin) case AF_INET6: return ntohs(((struct sockaddr_in6 *)sin)->sin6_port) < PROT_SOCK; + case AF_VSOCK: + return ((struct sockaddr_vm *)sin)->svm_port <= + LAST_RESERVED_PORT; + default: return 0; }