From: George Zhang <georgezhang@vmware.com>
To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
georgezhang@vmware.com,
virtualization@lists.linux-foundation.org
Cc: pv-drivers@vmware.com, gregkh@linuxfoundation.org, davem@davemloft.net
Subject: [PATCH 2/6] VSOCK: vsock address implementaion.
Date: Tue, 08 Jan 2013 15:59:43 -0800 [thread overview]
Message-ID: <20130108235931.3719.14605.stgit@promb-2n-dhcp175.eng.vmware.com> (raw)
In-Reply-To: <20130108235633.3719.6085.stgit@promb-2n-dhcp175.eng.vmware.com>
VSOCK linux address code implementation.
Signed-off-by: George Zhang <georgezhang@vmware.com>
Acked-by: Andy king <acking@vmware.com>
Acked-by: Dmitry Torokhov <dtor@vmware.com>
---
net/vmw_vsock/vsock_addr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++
net/vmw_vsock/vsock_addr.h | 34 +++++++++++++
2 files changed, 150 insertions(+), 0 deletions(-)
create mode 100644 net/vmw_vsock/vsock_addr.c
create mode 100644 net/vmw_vsock/vsock_addr.h
diff --git a/net/vmw_vsock/vsock_addr.c b/net/vmw_vsock/vsock_addr.c
new file mode 100644
index 0000000..9564576
--- /dev/null
+++ b/net/vmw_vsock/vsock_addr.c
@@ -0,0 +1,116 @@
+/*
+ * VMware vSockets Driver
+ *
+ * Copyright (C) 2007-2012 VMware, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation version 2 and no later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ */
+
+#include <linux/types.h>
+#include <linux/socket.h>
+#include <linux/stddef.h>
+#include <net/sock.h>
+
+#include "vsock_common.h"
+
+void vsock_addr_init(struct sockaddr_vm *addr, u32 cid, u32 port)
+{
+ memset(addr, 0, sizeof(*addr));
+ addr->svm_family = AF_VSOCK;
+ addr->svm_cid = cid;
+ addr->svm_port = port;
+}
+
+int vsock_addr_validate(const struct sockaddr_vm *addr)
+{
+ if (!addr)
+ return -EFAULT;
+
+ if (addr->svm_family != AF_VSOCK)
+ return -EAFNOSUPPORT;
+
+ if (addr->svm_zero[0] != 0)
+ return -EINVAL;
+
+ return 0;
+}
+
+bool vsock_addr_bound(const struct sockaddr_vm *addr)
+{
+ return addr->svm_port != VMADDR_PORT_ANY;
+}
+
+void vsock_addr_unbind(struct sockaddr_vm *addr)
+{
+ vsock_addr_init(addr, VMADDR_CID_ANY, VMADDR_PORT_ANY);
+}
+
+bool vsock_addr_equals_addr(const struct sockaddr_vm *addr,
+ const struct sockaddr_vm *other)
+{
+ return addr->svm_cid == other->svm_cid &&
+ addr->svm_port == other->svm_port;
+}
+
+bool vsock_addr_equals_addr_any(const struct sockaddr_vm *addr,
+ const struct sockaddr_vm *other)
+{
+ return (addr->svm_cid == VMADDR_CID_ANY ||
+ other->svm_cid == VMADDR_CID_ANY ||
+ addr->svm_cid == other->svm_cid) &&
+ addr->svm_port == other->svm_port;
+}
+
+bool vsock_addr_equals_handle_port(const struct sockaddr_vm *addr,
+ struct vmci_handle handle, u32 port)
+{
+ return addr->svm_cid == handle.context && addr->svm_port == port;
+}
+
+int vsock_addr_cast(const struct sockaddr *addr,
+ size_t len, struct sockaddr_vm **out_addr)
+{
+ if (len < sizeof(**out_addr))
+ return -EFAULT;
+
+ *out_addr = (struct sockaddr_vm *)addr;
+ return vsock_addr_validate(*out_addr);
+}
+
+bool vsock_addr_socket_context_stream(u32 cid)
+{
+ static const u32 non_socket_contexts[] = {
+ VMCI_HYPERVISOR_CONTEXT_ID,
+ VMCI_WELL_KNOWN_CONTEXT_ID,
+ };
+ int i;
+
+ BUILD_BUG_ON(sizeof(cid) != sizeof(*non_socket_contexts));
+
+ for (i = 0; i < ARRAY_SIZE(non_socket_contexts); i++) {
+ if (cid == non_socket_contexts[i])
+ return false;
+
+ }
+
+ return true;
+}
+
+bool vsock_addr_socket_context_dgram(u32 cid, u32 rid)
+{
+ if (cid == VMCI_HYPERVISOR_CONTEXT_ID) {
+ /* Registrations of PBRPC Servers do not modify VMX/Hypervisor
+ * state and are allowed.
+ */
+ return rid == VMCI_UNITY_PBRPC_REGISTER;
+ }
+
+ return true;
+}
diff --git a/net/vmw_vsock/vsock_addr.h b/net/vmw_vsock/vsock_addr.h
new file mode 100644
index 0000000..65c4bcf
--- /dev/null
+++ b/net/vmw_vsock/vsock_addr.h
@@ -0,0 +1,34 @@
+/*
+ * VMware vSockets Driver
+ *
+ * Copyright (C) 2007-2012 VMware, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation version 2 and no later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ */
+
+#ifndef _VSOCK_ADDR_H_
+#define _VSOCK_ADDR_H_
+
+void vsock_addr_init(struct sockaddr_vm *addr, u32 cid, u32 port);
+int vsock_addr_validate(const struct sockaddr_vm *addr);
+bool vsock_addr_bound(const struct sockaddr_vm *addr);
+void vsock_addr_unbind(struct sockaddr_vm *addr);
+bool vsock_addr_equals_addr(const struct sockaddr_vm *addr,
+ const struct sockaddr_vm *other);
+bool vsock_addr_equals_addr_any(const struct sockaddr_vm *addr,
+ const struct sockaddr_vm *other);
+bool vsock_addr_equals_handle_port(const struct sockaddr_vm *addr,
+ struct vmci_handle handle, u32 port);
+int vsock_addr_cast(const struct sockaddr *addr, size_t len,
+ struct sockaddr_vm **out_addr);
+bool vsock_addr_socket_context_stream(u32 cid);
+bool vsock_addr_socket_context_dgram(u32 cid, u32 rid);
+
+#endif
next prev parent reply other threads:[~2013-01-08 23:59 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-08 23:59 [PATCH 0/6] VSOCK for Linux upstreaming George Zhang
2013-01-08 23:59 ` [PATCH 1/6] VSOCK: vsock protocol implementation George Zhang
2013-01-08 23:59 ` George Zhang [this message]
2013-01-08 23:59 ` [PATCH 3/6] VSOCK: notification implementation George Zhang
2013-01-09 0:00 ` [PATCH 4/6] VSOCK: statistics implementation George Zhang
2013-01-09 0:00 ` [PATCH 5/6] VSOCK: utility functions George Zhang
2013-01-09 0:00 ` [PATCH 6/6] VSOCK: header and config files George Zhang
2013-01-09 0:21 ` [PATCH 0/6] VSOCK for Linux upstreaming Greg KH
2013-01-09 1:30 ` David Miller
2013-01-09 1:41 ` [Pv-drivers] " Dmitry Torokhov
2013-01-09 1:46 ` David Miller
2013-01-09 2:22 ` Dmitry Torokhov
2013-01-09 8:10 ` Gerd Hoffmann
2013-01-10 2:42 ` Andy King
2013-01-25 21:33 ` Andy King
2013-02-05 4:42 ` Andy King
-- strict thread matches above, loose matches on Subject: below --
2012-11-21 20:39 George Zhang
2012-11-21 20:39 ` [PATCH 2/6] VSOCK: vsock address implementaion George Zhang
2012-11-07 18:45 [PATCH 0/6] VSOCK for Linux upstreaming George Zhang
2012-11-07 18:45 ` [PATCH 2/6] VSOCK: vsock address implementaion George Zhang
2012-11-05 18:00 [PATCH 0/6] VSOCK for Linux upstreaming George Zhang
2012-11-05 18:01 ` [PATCH 2/6] VSOCK: vsock address implementaion George Zhang
2012-10-16 0:31 [PATCH 0/6] VSOCK for Linux upstreaming George Zhang
2012-10-16 0:32 ` [PATCH 2/6] VSOCK: vsock address implementaion George Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130108235931.3719.14605.stgit@promb-2n-dhcp175.eng.vmware.com \
--to=georgezhang@vmware.com \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pv-drivers@vmware.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).