Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Jan 2017 12:57:23 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r312988 - in head/sys: compat/cloudabi compat/linux kern sys
Message-ID:  <201701301257.v0UCvNrK065993@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Mon Jan 30 12:57:22 2017
New Revision: 312988
URL: https://svnweb.freebsd.org/changeset/base/312988

Log:
  Add kern_listen(), kern_shutdown(), and kern_socket(), and use them
  instead of their sys_*() counterparts in various compats. The svr4
  is left untouched, because there's no point.
  
  Reviewed by:	ed@, kib@
  MFC after:	2 weeks
  Sponsored by:	DARPA, AFRL
  Differential Revision:	https://reviews.freebsd.org/D9367

Modified:
  head/sys/compat/cloudabi/cloudabi_fd.c
  head/sys/compat/cloudabi/cloudabi_sock.c
  head/sys/compat/linux/linux_socket.c
  head/sys/kern/uipc_syscalls.c
  head/sys/sys/syscallsubr.h

Modified: head/sys/compat/cloudabi/cloudabi_fd.c
==============================================================================
--- head/sys/compat/cloudabi/cloudabi_fd.c	Mon Jan 30 12:24:47 2017	(r312987)
+++ head/sys/compat/cloudabi/cloudabi_fd.c	Mon Jan 30 12:57:22 2017	(r312988)
@@ -100,9 +100,6 @@ cloudabi_sys_fd_create1(struct thread *t
     struct cloudabi_sys_fd_create1_args *uap)
 {
 	struct filecaps fcaps = {};
-	struct socket_args socket_args = {
-		.domain = AF_UNIX,
-	};
 
 	switch (uap->type) {
 	case CLOUDABI_FILETYPE_POLL:
@@ -113,14 +110,11 @@ cloudabi_sys_fd_create1(struct thread *t
 		    CAP_MMAP_RWX);
 		return (kern_shm_open(td, SHM_ANON, O_RDWR, 0, &fcaps));
 	case CLOUDABI_FILETYPE_SOCKET_DGRAM:
-		socket_args.type = SOCK_DGRAM;
-		return (sys_socket(td, &socket_args));
+		return (kern_socket(td, AF_UNIX, SOCK_DGRAM, 0));
 	case CLOUDABI_FILETYPE_SOCKET_SEQPACKET:
-		socket_args.type = SOCK_SEQPACKET;
-		return (sys_socket(td, &socket_args));
+		return (kern_socket(td, AF_UNIX, SOCK_SEQPACKET, 0));
 	case CLOUDABI_FILETYPE_SOCKET_STREAM:
-		socket_args.type = SOCK_STREAM;
-		return (sys_socket(td, &socket_args));
+		return (kern_socket(td, AF_UNIX, SOCK_STREAM, 0));
 	default:
 		return (EINVAL);
 	}

Modified: head/sys/compat/cloudabi/cloudabi_sock.c
==============================================================================
--- head/sys/compat/cloudabi/cloudabi_sock.c	Mon Jan 30 12:24:47 2017	(r312987)
+++ head/sys/compat/cloudabi/cloudabi_sock.c	Mon Jan 30 12:57:22 2017	(r312988)
@@ -35,7 +35,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/syscallsubr.h>
-#include <sys/sysproto.h>
 #include <sys/systm.h>
 #include <sys/un.h>
 
@@ -165,37 +164,31 @@ int
 cloudabi_sys_sock_listen(struct thread *td,
     struct cloudabi_sys_sock_listen_args *uap)
 {
-	struct listen_args listen_args = {
-		.s = uap->sock,
-		.backlog = uap->backlog,
-	};
 
-	return (sys_listen(td, &listen_args));
+	return (kern_listen(td, uap->sock, uap->backlog));
 }
 
 int
 cloudabi_sys_sock_shutdown(struct thread *td,
     struct cloudabi_sys_sock_shutdown_args *uap)
 {
-	struct shutdown_args shutdown_args = {
-		.s = uap->sock,
-	};
+	int how;
 
 	switch (uap->how) {
 	case CLOUDABI_SHUT_RD:
-		shutdown_args.how = SHUT_RD;
+		how = SHUT_RD;
 		break;
 	case CLOUDABI_SHUT_WR:
-		shutdown_args.how = SHUT_WR;
+		how = SHUT_WR;
 		break;
 	case CLOUDABI_SHUT_RD | CLOUDABI_SHUT_WR:
-		shutdown_args.how = SHUT_RDWR;
+		how = SHUT_RDWR;
 		break;
 	default:
 		return (EINVAL);
 	}
 
-	return (sys_shutdown(td, &shutdown_args));
+	return (kern_shutdown(td, uap->sock, how));
 }
 
 int

Modified: head/sys/compat/linux/linux_socket.c
==============================================================================
--- head/sys/compat/linux/linux_socket.c	Mon Jan 30 12:24:47 2017	(r312987)
+++ head/sys/compat/linux/linux_socket.c	Mon Jan 30 12:57:22 2017	(r312988)
@@ -697,32 +697,26 @@ goout:
 int
 linux_socket(struct thread *td, struct linux_socket_args *args)
 {
-	struct socket_args /* {
-		int domain;
-		int type;
-		int protocol;
-	} */ bsd_args;
-	int retval_socket;
+	int domain, retval_socket, type;
 
-	bsd_args.protocol = args->protocol;
-	bsd_args.type = args->type & LINUX_SOCK_TYPE_MASK;
-	if (bsd_args.type < 0 || bsd_args.type > LINUX_SOCK_MAX)
+	type = args->type & LINUX_SOCK_TYPE_MASK;
+	if (type < 0 || type > LINUX_SOCK_MAX)
 		return (EINVAL);
 	retval_socket = linux_set_socket_flags(args->type & ~LINUX_SOCK_TYPE_MASK,
-		&bsd_args.type);
+		&type);
 	if (retval_socket != 0)
 		return (retval_socket);
-	bsd_args.domain = linux_to_bsd_domain(args->domain);
-	if (bsd_args.domain == -1)
+	domain = linux_to_bsd_domain(args->domain);
+	if (domain == -1)
 		return (EAFNOSUPPORT);
 
-	retval_socket = sys_socket(td, &bsd_args);
+	retval_socket = kern_socket(td, domain, type, args->protocol);
 	if (retval_socket)
 		return (retval_socket);
 
-	if (bsd_args.type == SOCK_RAW
-	    && (bsd_args.protocol == IPPROTO_RAW || bsd_args.protocol == 0)
-	    && bsd_args.domain == PF_INET) {
+	if (type == SOCK_RAW
+	    && (args->protocol == IPPROTO_RAW || args->protocol == 0)
+	    && domain == PF_INET) {
 		/* It's a raw IP socket: set the IP_HDRINCL option. */
 		int hdrincl;
 
@@ -738,7 +732,7 @@ linux_socket(struct thread *td, struct l
 	 * For simplicity we do this unconditionally of the net.inet6.ip6.v6only
 	 * sysctl value.
 	 */
-	if (bsd_args.domain == PF_INET6) {
+	if (domain == PF_INET6) {
 		int v6only;
 
 		v6only = 0;
@@ -816,14 +810,8 @@ linux_connect(struct thread *td, struct 
 int
 linux_listen(struct thread *td, struct linux_listen_args *args)
 {
-	struct listen_args /* {
-		int s;
-		int backlog;
-	} */ bsd_args;
 
-	bsd_args.s = args->s;
-	bsd_args.backlog = args->backlog;
-	return (sys_listen(td, &bsd_args));
+	return (kern_listen(td, args->s, args->backlog));
 }
 
 static int
@@ -1524,14 +1512,8 @@ linux_recvmmsg(struct thread *td, struct
 int
 linux_shutdown(struct thread *td, struct linux_shutdown_args *args)
 {
-	struct shutdown_args /* {
-		int s;
-		int how;
-	} */ bsd_args;
 
-	bsd_args.s = args->s;
-	bsd_args.how = args->how;
-	return (sys_shutdown(td, &bsd_args));
+	return (kern_shutdown(td, args->s, args->how));
 }
 
 int

Modified: head/sys/kern/uipc_syscalls.c
==============================================================================
--- head/sys/kern/uipc_syscalls.c	Mon Jan 30 12:24:47 2017	(r312987)
+++ head/sys/kern/uipc_syscalls.c	Mon Jan 30 12:57:22 2017	(r312988)
@@ -124,13 +124,19 @@ getsock_cap(struct thread *td, int fd, c
 int
 sys_socket(struct thread *td, struct socket_args *uap)
 {
+
+	return (kern_socket(td, uap->domain, uap->type, uap->protocol));
+}
+
+int
+kern_socket(struct thread *td, int domain, int type, int protocol)
+{
 	struct socket *so;
 	struct file *fp;
-	int fd, error, type, oflag, fflag;
+	int fd, error, oflag, fflag;
 
-	AUDIT_ARG_SOCKET(uap->domain, uap->type, uap->protocol);
+	AUDIT_ARG_SOCKET(domain, type, protocol);
 
-	type = uap->type;
 	oflag = 0;
 	fflag = 0;
 	if ((type & SOCK_CLOEXEC) != 0) {
@@ -143,8 +149,7 @@ sys_socket(struct thread *td, struct soc
 	}
 
 #ifdef MAC
-	error = mac_socket_check_create(td->td_ucred, uap->domain, type,
-	    uap->protocol);
+	error = mac_socket_check_create(td->td_ucred, domain, type, protocol);
 	if (error != 0)
 		return (error);
 #endif
@@ -152,8 +157,7 @@ sys_socket(struct thread *td, struct soc
 	if (error != 0)
 		return (error);
 	/* An extra reference on `fp' has been held for us by falloc(). */
-	error = socreate(uap->domain, &so, type, uap->protocol,
-	    td->td_ucred, td);
+	error = socreate(domain, &so, type, protocol, td->td_ucred, td);
 	if (error != 0) {
 		fdclose(td, fp, fd);
 	} else {
@@ -231,13 +235,20 @@ sys_bindat(struct thread *td, struct bin
 int
 sys_listen(struct thread *td, struct listen_args *uap)
 {
+
+	return (kern_listen(td, uap->s, uap->backlog));
+}
+
+int
+kern_listen(struct thread *td, int s, int backlog)
+{
 	struct socket *so;
 	struct file *fp;
 	cap_rights_t rights;
 	int error;
 
-	AUDIT_ARG_FD(uap->s);
-	error = getsock_cap(td, uap->s, cap_rights_init(&rights, CAP_LISTEN),
+	AUDIT_ARG_FD(s);
+	error = getsock_cap(td, s, cap_rights_init(&rights, CAP_LISTEN),
 	    &fp, NULL, NULL);
 	if (error == 0) {
 		so = fp->f_data;
@@ -245,10 +256,10 @@ sys_listen(struct thread *td, struct lis
 		error = mac_socket_check_listen(td->td_ucred, so);
 		if (error == 0)
 #endif
-			error = solisten(so, uap->backlog, td);
+			error = solisten(so, backlog, td);
 		fdrop(fp, td);
 	}
-	return(error);
+	return (error);
 }
 
 /*
@@ -1205,17 +1216,24 @@ sys_recvmsg(struct thread *td, struct re
 int
 sys_shutdown(struct thread *td, struct shutdown_args *uap)
 {
+
+	return (kern_shutdown(td, uap->s, uap->how));
+}
+
+int
+kern_shutdown(struct thread *td, int s, int how)
+{
 	struct socket *so;
 	struct file *fp;
 	cap_rights_t rights;
 	int error;
 
-	AUDIT_ARG_FD(uap->s);
-	error = getsock_cap(td, uap->s, cap_rights_init(&rights, CAP_SHUTDOWN),
+	AUDIT_ARG_FD(s);
+	error = getsock_cap(td, s, cap_rights_init(&rights, CAP_SHUTDOWN),
 	    &fp, NULL, NULL);
 	if (error == 0) {
 		so = fp->f_data;
-		error = soshutdown(so, uap->how);
+		error = soshutdown(so, how);
 		/*
 		 * Previous versions did not return ENOTCONN, but 0 in
 		 * case the socket was not connected. Some important

Modified: head/sys/sys/syscallsubr.h
==============================================================================
--- head/sys/sys/syscallsubr.h	Mon Jan 30 12:24:47 2017	(r312987)
+++ head/sys/sys/syscallsubr.h	Mon Jan 30 12:57:22 2017	(r312988)
@@ -135,6 +135,7 @@ int	kern_kldstat(struct thread *td, int 
 int	kern_kldunload(struct thread *td, int fileid, int flags);
 int	kern_linkat(struct thread *td, int fd1, int fd2, char *path1,
 	    char *path2, enum uio_seg segflg, int follow);
+int	kern_listen(struct thread *td, int s, int backlog);
 int	kern_lseek(struct thread *td, int fd, off_t offset, int whence);
 int	kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg,
 	    struct timeval *tptr, enum uio_seg tptrseg);
@@ -213,6 +214,7 @@ int	kern_shmat(struct thread *td, int sh
 	    int shmflg);
 int	kern_shmctl(struct thread *td, int shmid, int cmd, void *buf,
 	    size_t *bufsz);
+int	kern_shutdown(struct thread *td, int s, int how);
 int	kern_sigaction(struct thread *td, int sig, const struct sigaction *act,
 	    struct sigaction *oact, int flags);
 int	kern_sigaltstack(struct thread *td, stack_t *ss, stack_t *oss);
@@ -221,6 +223,7 @@ int	kern_sigprocmask(struct thread *td, 
 int	kern_sigsuspend(struct thread *td, sigset_t mask);
 int	kern_sigtimedwait(struct thread *td, sigset_t waitset,
 	    struct ksiginfo *ksi, struct timespec *timeout);
+int	kern_socket(struct thread *td, int domain, int type, int protocol);
 int	kern_statat(struct thread *td, int flag, int fd, char *path,
 	    enum uio_seg pathseg, struct stat *sbp,
 	    void (*hook)(struct vnode *vp, struct stat *sbp));



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701301257.v0UCvNrK065993>