From patchwork Wed Sep 13 10:26:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9950921 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 1546B60360 for ; Wed, 13 Sep 2017 10:27:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05FC122299 for ; Wed, 13 Sep 2017 10:27:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF025223A5; Wed, 13 Sep 2017 10:27:21 +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 A190622299 for ; Wed, 13 Sep 2017 10:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751940AbdIMK1U (ORCPT ); Wed, 13 Sep 2017 06:27:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60726 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751678AbdIMK1U (ORCPT ); Wed, 13 Sep 2017 06:27:20 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3016CC0587E3; Wed, 13 Sep 2017 10:27:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3016CC0587E3 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=stefanha@redhat.com Received: from localhost (ovpn-116-110.ams2.redhat.com [10.36.116.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id E41F960C23; Wed, 13 Sep 2017 10:27:17 +0000 (UTC) From: Stefan Hajnoczi To: linux-nfs@vger.kernel.org Cc: NeilBrown , Matt Benjamin , Jeff Layton , "J . Bruce Fields" , Chuck Lever , Steve Dickson , Stefan Hajnoczi Subject: [PATCH nfs-utils v3 06/14] mount: generate AF_VSOCK clientaddr Date: Wed, 13 Sep 2017 11:26:42 +0100 Message-Id: <20170913102650.10377-7-stefanha@redhat.com> In-Reply-To: <20170913102650.10377-1-stefanha@redhat.com> References: <20170913102650.10377-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 13 Sep 2017 10:27:20 +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 The mount(8) command should automatically determine the NFS backchannel address details so the user does not have to specify them on the command-line. Use the AF_VSOCK ioctl for determining the local CID. Signed-off-by: Stefan Hajnoczi --- utils/mount/network.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/utils/mount/network.c b/utils/mount/network.c index 7b0bc97..1f9ad02 100644 --- a/utils/mount/network.c +++ b/utils/mount/network.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -1129,6 +1130,34 @@ static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen, int sock, result = 0; int val; + if (sap->sa_family == AF_VSOCK) { + struct sockaddr_vm *svm = (struct sockaddr_vm *)buf; + unsigned int cid; + int fd; + + if (*buflen < sizeof(struct sockaddr_vm)) { + errno = EINVAL; + return 0; + } + + fd = open("/dev/vsock", O_RDONLY); + if (fd < 0) + return 0; + + if (ioctl(fd, IOCTL_VM_SOCKETS_GET_LOCAL_CID, &cid) < 0) { + close(fd); + return 0; + } + + memset(svm, 0, sizeof(*svm)); + svm->svm_family = AF_VSOCK; + svm->svm_cid = cid; + + *buflen = sizeof(*svm); + close(fd); + return 1; + } + sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP); if (sock < 0) return 0;