diff options
author | Jason King <jason.king@joyent.com> | 2021-03-21 04:02:39 +0000 |
---|---|---|
committer | Jason King <jason.king@joyent.com> | 2021-03-21 04:02:39 +0000 |
commit | c9f9deed3a7ca88d2368ac1f9c1d653662df95d1 (patch) | |
tree | ac827f35e350ed6dc66b390331405d5051fddac5 /usr/src | |
parent | 1bdd4b7b527e6552b00be56972027c83b8a68c05 (diff) | |
download | illumos-joyent-c9f9deed3a7ca88d2368ac1f9c1d653662df95d1.tar.gz |
VSOCK skeleton
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/uts/common/Makefile.files | 4 | ||||
-rw-r--r-- | usr/src/uts/common/io/vsock.c | 274 | ||||
-rw-r--r-- | usr/src/uts/common/sys/Makefile | 4 | ||||
-rw-r--r-- | usr/src/uts/common/sys/vsock.h | 46 | ||||
-rw-r--r-- | usr/src/uts/intel/Makefile.intel | 3 | ||||
-rw-r--r-- | usr/src/uts/intel/vsock/Makefile | 40 |
6 files changed, 367 insertions, 4 deletions
diff --git a/usr/src/uts/common/Makefile.files b/usr/src/uts/common/Makefile.files index 7dfbae4a68..4aa4a03310 100644 --- a/usr/src/uts/common/Makefile.files +++ b/usr/src/uts/common/Makefile.files @@ -25,7 +25,7 @@ # Copyright (c) 2013 by Saso Kiselkov. All rights reserved. # Copyright 2018 Nexenta Systems, Inc. # Copyright 2016 Garrett D'Amore <garrett@damore.org> -# Copyright 2020 Joyent, Inc. +# Copyright 2021 Joyent, Inc. # Copyright 2016 OmniTI Computer Consulting, Inc. All rights reserved. # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> # Copyright 2020 RackTop Systems, Inc. @@ -1964,6 +1964,8 @@ SKD_OBJS = skd.o NVME_OBJS = nvme.o +VSOCK_OBJS = vsock.o + # # Build up defines and paths. # diff --git a/usr/src/uts/common/io/vsock.c b/usr/src/uts/common/io/vsock.c new file mode 100644 index 0000000000..d417ea7ff2 --- /dev/null +++ b/usr/src/uts/common/io/vsock.c @@ -0,0 +1,274 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2021 Joyent, Inc. + */ + +#include <sys/strsubr.h> +#include <sys/socket.h> +#include <sys/socketvar.h> +#include <sys/modctl.h> +#include <sys/cmn_err.h> +#include <sys/strsun.h> +#include <sys/sunddi.h> + +typedef struct vsock_sock { + int foo; +} vsock_sock_t; + +static sock_lower_handle_t vsock_create(int, int, int, sock_downcalls_t **, + uint_t *, int *, int, cred_t *); +static vsock_sock_t * vsock_do_open(int flags); +static void vsock_activate(sock_lower_handle_t proto_handle, + sock_upper_handle_t sock_handle, sock_upcalls_t *sock_upcalls, int flags, + cred_t *cr); +static int vsock_accept(sock_lower_handle_t proto_handle, + sock_lower_handle_t lproto_handle, sock_upper_handle_t sock_handle, + cred_t *cr); +static int vsock_bind(sock_lower_handle_t proto_handle, struct sockaddr *sa, + socklen_t len, cred_t *cr); +static int +vsock_listen(sock_lower_handle_t proto_handle, int backlog, cred_t *cr); +static int +vsock_connect(sock_lower_handle_t proto_handle, const struct sockaddr *sa, + socklet_t len, sock_connid_t *id, cred_t *cr); +static int +vsock_getpeername(sock_lower_handle_t proto_handle, struct sockaddr *addr, + socklen_t *addrlenp, cred_t *cr); +static int +vsock_getsockname(sock_lower_handle_t proto_handle, struct sockaddr *addr, + socklen_t *addrlenp, cred_t *cr); +static int +vsock_getsockopt(sock_lower_handle_t proto_handle, int level, int option_name, + void *optvalp, socklen_t *optlen, cred_t *cr); +static int +vsock_setsockopt(sock_lower_handle_t proto_handle, int level, int option_name, + const void *optvalp, socklen_t optlen, cred_t *cr); +static int +vsock_send(sock_lower_handle_t proto_handle, mblk_t *mp, struct nmsghdr *msg, + cred_t *cr); +static int +vsock_send_uio(sock_lower_handle_t proto_handle, uio_t *uiop, + struct nmsghdr *msg, cred_t *cr); +static int +vsock_recv_uio(sock_lower_handle_t proto_handle, uio_t *uiop, + struct nmsghdr *msg, cred_t *cr); +static int +vosck_poll(sock_lower_handle_t proto_handle, short events, int anyyet, + cred_t *cr); +static int +vsock_shutdown(sock_lower_handle_t proto_handle, int how, cred_t *cr); +static int +vsock_setflowctrl(sock_lower_handle_t proto_handle); +static int +vsock_ioctl(sock_lower_handle_t proto_handle, int cmd, intptr_t arg, + int mode, int32_t *rvalp, cred_t *cr); + + +static smod_reg_t sinfo = { + SOCKMOD_VERSION, + "vsock", + SOCK_UC_VERSION, + SOCK_DC_VERSION, + sock_create, + NULL, +}; + +static struct modlsockmod sockmod = { + &mod_sockmodops, "AF_VSOCK socket module", &sinfo +}; + +static struct modlinkage ml = { + MODREV_1, + &sockmod, + NULL +}; + +static sock_downcalls_t sock_vsock_downcalls = { + vsock_activate, + vsock_accept, + vsock_bind, + vsock_listen, + vsock_connect, + vsock_getpeername, + vsock_getsockname, + vsock_getsockopt, + vsock_setsockopt, + vsock_send, + vsock_send_uio, + vsock_recv_uio, + vosck_poll, + vsock_shutdown, + vsock_setflowctrl, + vsock_ioctl, + vsock_close, +}; + +int +_init(void) +{ + int rc; + + rc = mod_install(&ml); + return (rc); +} + +int +_info(struct modinfo *modinfop) +{ + return (mod_info(&ml, modinfop)); +} + +int +_fini(void) +{ + int rc; + + rc = mod_remove(&ml); + return (rc); +} + +static sock_lower_handle_t +vsock_create(int family, int type, int proto, sock_downcalls_t **sock_downcalls, + uint_t *smodep, int *errorp, int flags, cred_t *credp) +{ + vsock_sock_t *vsock; + + if (family != AF_VSOCK || type != SOCK_STREAM || proto != 0) { + *errorp = EPROTONOSUPPORT; + return (NULL); + } + + *sock_downcalls = &sock_vsock_downcalls; + *smodep = SM_CONNREQUIRED | SM_EXDATA | SM_ACCEPTSUPP; + vsock = vsock_do_open(flags); + *errorp = (vsock != NULL) ? 0 : ENOMEM; + return ((sock_lower_handle_t)vsock); +} + +static vsock_sock_t * +vsock_do_open(int flags) +{ + return (NULL); +} + +static void +vsock_activate(sock_lower_handle_t proto_handle, + sock_upper_handle_t sock_handle, sock_upcalls_t *sock_upcalls, int flags, + cred_t *cr) +{ +} + +static int +vsock_accept(sock_lower_handle_t proto_handle, + sock_lower_handle_t lproto_handle, sock_upper_handle_t sock_handle, + cred_t *cr) + return (ECONNABORTED); +} + +static int +vsock_bind(sock_lower_handle_t proto_handle, struct sockaddr *sa, + socklen_t len, cred_t *cr) +{ + return (EOPNOTSUPP); +} + +static int +vsock_listen(sock_lower_handle_t proto_handle, int backlog, cred_t *cr) +{ + return (EOPNOTSUPP); +} + +static int +vsock_connect(sock_lower_handle_t proto_handle, const struct sockaddr *sa, + socklet_t len, sock_connid_t *id, cred_t *cr) +{ + return (EOPNOTSUPP); +} + +static int +vsock_getpeername(sock_lower_handle_t proto_handle, struct sockaddr *addr, + socklen_t *addrlenp, cred_t *cr) +{ + return (ENOTCONN); +} + +static int +vsock_getsockname(sock_lower_handle_t proto_handle, struct sockaddr *addr, + socklen_t *addrlenp, cred_t *cr) +{ + return (ENOTCONN); +} + +static int +vsock_getsockopt(sock_lower_handle_t proto_handle, int level, int option_name, + void *optvalp, socklen_t *optlen, cred_t *cr) +{ + return (EOPNOTSUPP); +} + +static int +vsock_setsockopt(sock_lower_handle_t proto_handle, int level, int option_name, + const void *optvalp, socklen_t optlen, cred_t *cr) +{ + return (EOPNOTSUPP); +} + + +static int +vsock_send(sock_lower_handle_t proto_handle, mblk_t *mp, struct nmsghdr *msg, + cred_t *cr) +{ + return (EOPNOTSUPP); +} + + +static int +vsock_send_uio(sock_lower_handle_t proto_handle, uio_t *uiop, + struct nmsghdr *msg, cred_t *cr) +{ + return (EOPNOTSUPP); +} + +static int +vsock_recv_uio(sock_lower_handle_t proto_handle, uio_t *uiop, + struct nmsghdr *msg, cred_t *cr) +{ + return (EOPNOTSUPP); +} + +static int +vosck_poll(sock_lower_handle_t proto_handle, short events, int anyyet, + cred_t *cr) +{ + return (EOPNOTSUPP); +} + + +static int +vsock_shutdown(sock_lower_handle_t proto_handle, int how, cred_t *cr) +{ + return (EOPNOTSUPP); +} + +static int +vsock_setflowctrl(sock_lower_handle_t proto_handle) +{ + return (EOPNOTSUPP); +} + +static int +vsock_ioctl(sock_lower_handle_t proto_handle, int cmd, intptr_t arg, + int mode, int32_t *rvalp, cred_t *cr) +{ + return (EOPNOTSUPP); +} diff --git a/usr/src/uts/common/sys/Makefile b/usr/src/uts/common/sys/Makefile index 24fdd94c11..53b1818fa5 100644 --- a/usr/src/uts/common/sys/Makefile +++ b/usr/src/uts/common/sys/Makefile @@ -21,14 +21,13 @@ # # Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. -# Copyright 2019 Joyent, Inc. +# Copyright 2021 Joyent, Inc. # Copyright 2013 Garrett D'Amore <garrett@damore.org> # Copyright 2013 Saso Kiselkov. All rights reserved. # Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com> # Copyright 2017 Nexenta Systems, Inc. # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> # Copyright 2019 Peter Tribble. -# Copyright 2015, Joyent, Inc. All rights reserved. # include $(SRC)/uts/Makefile.uts @@ -673,6 +672,7 @@ CHKHDRS= \ vnic_impl.h \ vnode.h \ vscan.h \ + vsock.h \ vtoc.h \ vtrace.h \ vuid_event.h \ diff --git a/usr/src/uts/common/sys/vsock.h b/usr/src/uts/common/sys/vsock.h new file mode 100644 index 0000000000..c46722d6bf --- /dev/null +++ b/usr/src/uts/common/sys/vsock.h @@ -0,0 +1,46 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2021 Joyent, Inc. + */ + +#ifndef _VSOCK_H +#define _VSOCK_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _SA_FAMILY_T +#define _SA_FAMILY_T +typedef unsigned short sa_family_t; +#endif + +#define VMADDR_CID_ANY (-1U) +#define VMADDR_CID_HYPERVISOR 0 +#define VMADDR_CID_LOCAL 2 + +#define VSIOCTL ('v' << 16 | 's' << 8) +#define IOCTL_VM_SOCKETS_GET_LOCAL_CID (VSIOCTL | 0x1) + +struct sockaddr_vm { + sa_family_t svm_family; + unsigned short svm_reserved1; + uint32_t svm_port; + uint64_t svm_cid; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _VSOCK_H */ diff --git a/usr/src/uts/intel/Makefile.intel b/usr/src/uts/intel/Makefile.intel index fdaee2f09d..9071eb6c40 100644 --- a/usr/src/uts/intel/Makefile.intel +++ b/usr/src/uts/intel/Makefile.intel @@ -22,7 +22,7 @@ # Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2013 Andrew Stormont. All rights reserved. # Copyright (c) 2014 by Delphix. All rights reserved. -# Copyright 2019 Joyent, Inc. +# Copyright 2021 Joyent, Inc. # Copyright 2016 Garrett D'Amore <garrett@damore.org> # Copyright 2018 Nexenta Systems, Inc. # Copyright 2019 RackTop Systems @@ -358,6 +358,7 @@ DRV_KMODS += vmxnet DRV_KMODS += vnd DRV_KMODS += vnic DRV_KMODS += vscan +DRV_KMODS += vsock DRV_KMODS += wc DRV_KMODS += winlock DRV_KMODS += wpi diff --git a/usr/src/uts/intel/vsock/Makefile b/usr/src/uts/intel/vsock/Makefile new file mode 100644 index 0000000000..695d6c9686 --- /dev/null +++ b/usr/src/uts/intel/vsock/Makefile @@ -0,0 +1,40 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2021 Joyent, Inc. +# + +UTSBASE = ../.. + +MODULE = vsock +OBJECTS = $(VSOCK_OBKS:%=$(OBJS_DIR)/%) +ROOTMODULE = $(ROOT_SOCK_DIR)/$(MODULE) + +ALL_TARGET = $(BINARY) +INSTALL_TARGET = $(BINARY) $(ROOTMODULE) + +CFLAGS += $(CCVERVOSE) +LDFLAGS += -dy -Nfs/sockfs + +.KEEP_STATE: + +def: $(DEF_DEPS) + +all: $(ALL_DEPS) + +clean: $(CLEAN_DEPS) + +clobber: $(CLOBBER_DEPS) + +install: $(INSTALL_DEPS) + +include $(UTSBASE)/intel/Makefile.targ |